mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-09 16:05:42 +00:00
* Remove $$props.field usage * Rename slots to ensure no hyphen * _props * _trigger * OnSelectedIteration type correct capitalization * rename _content * Remove afterUpdate * Migrate everything to svelte 5 * array bind * Fix popover * type never * nit fixes * Fixed many trivial errors * onClick * Fix errors * use let: * nit typing * fix: wrap state_referenced_locally vars with untrack() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add untrack import * Fix all syntax errors due to untrack migration * Fix undefined errors * Fix more undefined errors * untrack(() => initialOpen) * svelte-ignore * Fix state_descriptors_fixed error in Chart.svelte Use $state.snapshot() to pass plain copies of data/options to Chart.js instead of $state proxies. Chart.js's listenArrayEvents tries to define property descriptors on data arrays, which Svelte 5 proxies reject. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * nit typing * Merge issue * Fix "path is not set" error in resource picker / editor * Fix InputTransformForm error when rerunning some flows * fix npm run check --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
106 lines
2.5 KiB
Svelte
106 lines
2.5 KiB
Svelte
<script lang="ts">
|
|
import { run, createBubbler } from 'svelte/legacy'
|
|
|
|
const bubble = createBubbler()
|
|
import { createPopperActions, type PopperOptions } from 'svelte-popperjs'
|
|
import type { PopoverPlacement } from './Popover.model'
|
|
import Portal from '$lib/components/Portal.svelte'
|
|
import { untrack } from 'svelte'
|
|
|
|
interface Props {
|
|
placement?: PopoverPlacement
|
|
notClickable?: boolean
|
|
disablePopup?: boolean
|
|
disappearTimeout?: number
|
|
appearTimeout?: number
|
|
style?: string | undefined
|
|
noPadding?: boolean
|
|
focusEl?: HTMLElement | undefined
|
|
class?: string
|
|
children?: import('svelte').Snippet
|
|
overlay?: import('svelte').Snippet
|
|
}
|
|
|
|
let {
|
|
placement = 'bottom-end',
|
|
notClickable = false,
|
|
disablePopup = false,
|
|
disappearTimeout = 100,
|
|
appearTimeout = 300,
|
|
style = undefined,
|
|
noPadding = false,
|
|
focusEl = undefined,
|
|
class: clazz = '',
|
|
children,
|
|
overlay
|
|
}: Props = $props()
|
|
const [popperRef, popperContent] = createPopperActions({ placement: untrack(() => placement) })
|
|
|
|
const popperOptions: PopperOptions<{}> = {
|
|
placement: untrack(() => placement),
|
|
strategy: 'fixed',
|
|
modifiers: [
|
|
{ name: 'offset', options: { offset: [8, 8] } },
|
|
{
|
|
name: 'arrow',
|
|
options: {
|
|
padding: 10
|
|
}
|
|
}
|
|
]
|
|
}
|
|
|
|
let showTooltip = $state(false)
|
|
let timeout: number | undefined = undefined
|
|
let inTimeout: number | undefined = undefined
|
|
|
|
function open() {
|
|
clearTimeout(timeout)
|
|
if (appearTimeout == 0) {
|
|
showTooltip = true
|
|
} else {
|
|
inTimeout = setTimeout(() => (showTooltip = true), appearTimeout)
|
|
}
|
|
}
|
|
function close() {
|
|
inTimeout && clearTimeout(inTimeout)
|
|
inTimeout = undefined
|
|
timeout = setTimeout(() => (showTooltip = false), disappearTimeout)
|
|
}
|
|
|
|
run(() => {
|
|
focusEl && focusEl?.focus()
|
|
})
|
|
</script>
|
|
|
|
{#if notClickable}
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
<span {style} use:popperRef onmouseenter={open} onmouseleave={close} class={clazz}>
|
|
{@render children?.()}
|
|
</span>
|
|
{:else}
|
|
<button
|
|
{style}
|
|
use:popperRef
|
|
onmouseenter={open}
|
|
onmouseleave={close}
|
|
onclick={bubble('click')}
|
|
class={clazz}
|
|
>
|
|
{@render children?.()}
|
|
</button>
|
|
{/if}
|
|
{#if showTooltip && !disablePopup}
|
|
<Portal name="custom-popover">
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
<div
|
|
use:popperContent={popperOptions}
|
|
onmouseenter={open}
|
|
onmouseleave={close}
|
|
class="z-[5001] border rounded-lg shadow-lg {noPadding ? '' : 'p-4'} bg-surface"
|
|
>
|
|
{@render overlay?.()}
|
|
</div>
|
|
</Portal>
|
|
{/if}
|