mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-08 00:03:07 +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>
128 lines
3.1 KiB
Svelte
128 lines
3.1 KiB
Svelte
<script lang="ts">
|
|
import { isMac } from '$lib/utils'
|
|
import { onDestroy, onMount, untrack } from 'svelte'
|
|
import { twMerge } from 'tailwind-merge'
|
|
|
|
// const dispatch = createEventDispatcher()
|
|
|
|
onMount(() => {
|
|
window.addEventListener('keydown', handleKeydown)
|
|
})
|
|
|
|
onDestroy(() => {
|
|
window.removeEventListener('keydown', handleKeydown)
|
|
})
|
|
|
|
async function handleKeydown(event: KeyboardEvent) {
|
|
if (hovered && event.key === 'Enter') {
|
|
event.preventDefault()
|
|
if (onkeyboardSpecificSelect) {
|
|
onkeyboardSpecificSelect(event.shiftKey || event.ctrlKey)
|
|
} else {
|
|
onselect(event.shiftKey || event.ctrlKey)
|
|
}
|
|
}
|
|
}
|
|
|
|
interface Props {
|
|
hovered?: boolean
|
|
id: string
|
|
label?: string
|
|
icon?: any
|
|
shortcutKey?: string | undefined
|
|
containerClass?: string | undefined
|
|
mouseMoved?: boolean
|
|
kbdClass?: string
|
|
small?: boolean
|
|
itemReplacement?: import('svelte').Snippet
|
|
onselect?: (shift: boolean) => void
|
|
onkeyboardSpecificSelect?: (shift: boolean) => void
|
|
onhover?: () => void
|
|
}
|
|
|
|
let {
|
|
hovered = false,
|
|
id,
|
|
label = '',
|
|
icon = undefined,
|
|
shortcutKey = undefined,
|
|
containerClass = undefined,
|
|
mouseMoved = $bindable(false),
|
|
kbdClass = $bindable(''),
|
|
small = true,
|
|
itemReplacement,
|
|
onselect = () => {},
|
|
onhover = () => {},
|
|
onkeyboardSpecificSelect
|
|
}: Props = $props()
|
|
|
|
if (untrack(() => small)) {
|
|
kbdClass = twMerge(
|
|
kbdClass,
|
|
'!text-[10px] px-1',
|
|
false && isMac() ? '!text-lg ' : 'text-xs',
|
|
'leading-none'
|
|
)
|
|
} else {
|
|
kbdClass += ' !text-xs px-1.5'
|
|
}
|
|
|
|
</script>
|
|
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
<div
|
|
{id}
|
|
onclick={(e) => {
|
|
e.stopImmediatePropagation()
|
|
onselect(e.shiftKey || e.ctrlKey)
|
|
}}
|
|
onmouseenter={() => {
|
|
if (mouseMoved) {
|
|
onhover()
|
|
}
|
|
mouseMoved = false
|
|
}}
|
|
class={twMerge(
|
|
`rounded-md w-full transition-all cursor-pointer ${hovered ? 'bg-surface-hover' : ''}`,
|
|
containerClass
|
|
)}
|
|
>
|
|
{#if itemReplacement}
|
|
{@render itemReplacement?.()}
|
|
{:else}
|
|
<div class="flex flex-row gap-2 items-center px-2 py-1.5 rounded-md pr-6 text-sm">
|
|
<div class="w-4">
|
|
{#if icon}
|
|
{@const SvelteComponent = icon}
|
|
<SvelteComponent size={16} />
|
|
{:else if shortcutKey != undefined}
|
|
<div class="font-bold flex items-center justify-center w-full">
|
|
<span
|
|
class="h-4 center-center ml-0.5 rounded border bg-surface-secondary text-primary shadow-sm font-light transition-all group-hover:border-primary-500 group-hover:text-primary-inverse"
|
|
>
|
|
<kbd class={kbdClass}>
|
|
{shortcutKey}
|
|
</kbd>
|
|
</span>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
{label}
|
|
{#if shortcutKey != undefined}
|
|
<div class="ml-auto">
|
|
<div class="font-bold flex items-center justify-center w-full">
|
|
<span
|
|
class="flex h-4 center-center ml-0.5 rounded border bg-surface-secondary text-primary shadow-sm font-light transition-all group-hover:border-primary-500 group-hover:text-primary-inverse"
|
|
>
|
|
<kbd class={kbdClass}>
|
|
{shortcutKey}
|
|
</kbd>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
{/if}
|
|
</div>
|