migrate: switch to svelte 5 events system for everything

This commit is contained in:
James Xylight committed 2025-02-05 19:29:54 -08:00
1 parent 43a857ed66
commit 53cb0e4f20
27 files changed
+248 -303

No files matched your search

+16 -13
View File
@@ -12,20 +12,7 @@
sm: 'shadow-sm',
none: 'shadow-none',
}
</script>
<script lang="ts">
import type {
HTMLInputAttributes,
HTMLInputTypeAttribute,
} from 'svelte/elements'
import Label from '../forms/Label.svelte'
import { generateID } from '../forms/helper.js'
const borderClass = `
border border-slate-200 border-b-slate-300 dark:border-zinc-900 dark:border-t-zinc-800
`
interface Props extends Omit<HTMLInputAttributes, 'size' | 'prefix'> {
label?: string | undefined
value?: string
@@ -44,6 +31,22 @@
children?: import('svelte').Snippet
}
export type { Props as TextInputProps }
</script>
<script lang="ts">
import type {
HTMLInputAttributes,
HTMLInputTypeAttribute,
} from 'svelte/elements'
import Label from '../forms/Label.svelte'
import { generateID } from '../forms/helper.js'
const borderClass = `
border border-slate-200 border-b-slate-300 dark:border-zinc-900 dark:border-t-zinc-800
`
let {
label = undefined,
value = $bindable(''),
+7 -5
View File
@@ -15,6 +15,8 @@
customTitle?: import('svelte').Snippet
children?: import('svelte').Snippet
actions?: import('svelte').Snippet<[any]>
ondismissed?: () => void
onaction?: () => void
}
let {
@@ -25,11 +27,11 @@
customTitle,
children,
actions,
ondismissed,
onaction,
}: Props = $props()
let el: any = $state()
const dispatcher = createEventDispatcher<{ action: any; dismissed: any }>()
</script>
<Portal>
@@ -46,7 +48,7 @@ bg-white/50 dark:bg-black/50 box-border p-4"
if (!el.contains(e.target)) {
open = false
dispatcher('dismissed')
ondismissed?.()
}
}}
>
@@ -94,9 +96,9 @@ bg-white/50 dark:bg-black/50 box-border p-4"
<Button
class="w-full"
onclick={(e) => {
dispatcher('action', e)
onaction?.()
open = false
dispatcher('dismissed')
ondismissed?.()
}}
color="primary"
size="lg"
+1 -1
View File
@@ -18,7 +18,7 @@
<Modal
title={$shownModal.title}
dismissable={$shownModal.dismissable}
on:dismissed={() => shownModal.set(undefined)}
ondismissed={() => shownModal.set(undefined)}
bind:open
>
<p>{$shownModal.body}</p>
+28 -27
View File
@@ -1,24 +1,5 @@
<script lang="ts">
import { Menu, TextInput, Spinner, MenuButton } from '../index.js'
import { debounce } from '../util/time.js'
import { createEventDispatcher } from 'svelte'
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
type T = $$Generic
let items: T[] = $state([])
/**
* This is here so that the menu doesn't open as soon as it's mounted.
*/
let openMenu = $state(false)
let searching = $state(false)
const dispatcher = createEventDispatcher<{
input: Event
select: T | undefined
}>()
interface Props {
<script lang="ts" module>
interface Props<T> extends Omit<TextInputProps, 'onselect' | 'children'> {
query?: string
selected?: T | undefined
search: (query: string) => Promise<T[]>
@@ -27,9 +8,28 @@
input?: import('svelte').Snippet
noresults?: import('svelte').Snippet
children?: import('svelte').Snippet<[any]>
[key: string]: any
onselect?: (value: T | undefined) => void
oninput?: TextInputProps['oninput']
}
export type { Props as SearchProps }
</script>
<script lang="ts" generics="T">
import type { TextInputProps } from 'mono-svelte/forms/TextInput.svelte'
import { Menu, TextInput, Spinner, MenuButton } from '../index.js'
import { debounce } from '../util/time.js'
import { createEventDispatcher } from 'svelte'
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
let items: T[] = $state([])
/**
* This is here so that the menu doesn't open as soon as it's mounted.
*/
let openMenu = $state(false)
let searching = $state(false)
let {
query = $bindable(''),
selected = $bindable(undefined),
@@ -38,13 +38,15 @@
select = (item: T) => {
selected = item
query = extractName(item)
dispatcher('select', item)
onselect?.(item)
},
input,
noresults,
children,
onselect,
oninput,
...rest
}: Props = $props()
}: Props<T> = $props()
const debounceFunc = debounce(async () => {
searching = true
@@ -63,13 +65,13 @@
oninput={(e) => {
searching = true
openMenu = true
dispatcher('input', e)
oninput?.(e)
debounceFunc()
}}
onfocus={(e) => {
searching = true
openMenu = true
dispatcher('input', e)
oninput?.(e)
debounceFunc()
}}
{...rest}
@@ -96,7 +98,6 @@
{#if children}{@render children({
extractName,
item,
dispatcher,
select,
})}{:else}
<MenuButton onclick={() => select(item)}>