@hydrateless/svelte 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -38
- package/dist/components/Accordion.svelte +28 -17
- package/dist/components/Accordion.svelte.d.ts +3 -0
- package/dist/components/AccordionItem.svelte +17 -11
- package/dist/components/AccordionItem.svelte.d.ts +5 -3
- package/dist/components/Alert.svelte +4 -0
- package/dist/components/Alert.svelte.d.ts +4 -0
- package/dist/components/Avatar.svelte +5 -0
- package/dist/components/Avatar.svelte.d.ts +5 -0
- package/dist/components/AvatarGroup.svelte +1 -0
- package/dist/components/AvatarGroup.svelte.d.ts +1 -0
- package/dist/components/Badge.svelte +4 -0
- package/dist/components/Badge.svelte.d.ts +4 -0
- package/dist/components/Breadcrumb.svelte +1 -0
- package/dist/components/Breadcrumb.svelte.d.ts +1 -0
- package/dist/components/BreadcrumbItem.svelte +3 -0
- package/dist/components/BreadcrumbItem.svelte.d.ts +3 -0
- package/dist/components/Button.svelte +7 -0
- package/dist/components/Button.svelte.d.ts +7 -0
- package/dist/components/Card.svelte +2 -0
- package/dist/components/Card.svelte.d.ts +2 -0
- package/dist/components/CardBody.svelte +1 -0
- package/dist/components/CardBody.svelte.d.ts +1 -0
- package/dist/components/CardDescription.svelte +1 -0
- package/dist/components/CardDescription.svelte.d.ts +1 -0
- package/dist/components/CardFooter.svelte +1 -0
- package/dist/components/CardFooter.svelte.d.ts +1 -0
- package/dist/components/CardHeader.svelte +1 -0
- package/dist/components/CardHeader.svelte.d.ts +1 -0
- package/dist/components/CardTitle.svelte +1 -0
- package/dist/components/CardTitle.svelte.d.ts +1 -0
- package/dist/components/Checkbox.svelte +24 -2
- package/dist/components/Checkbox.svelte.d.ts +2 -0
- package/dist/components/Combobox.svelte +37 -26
- package/dist/components/Combobox.svelte.d.ts +12 -3
- package/dist/components/ComboboxInput.svelte +21 -2
- package/dist/components/ComboboxInput.svelte.d.ts +1 -0
- package/dist/components/ComboboxList.svelte +4 -1
- package/dist/components/ComboboxList.svelte.d.ts +1 -0
- package/dist/components/ComboboxOption.svelte +6 -2
- package/dist/components/ComboboxOption.svelte.d.ts +4 -0
- package/dist/components/Command.svelte +36 -9
- package/dist/components/Command.svelte.d.ts +12 -5
- package/dist/components/CommandEmpty.svelte +1 -0
- package/dist/components/CommandEmpty.svelte.d.ts +1 -0
- package/dist/components/CommandGroup.svelte +1 -0
- package/dist/components/CommandGroup.svelte.d.ts +1 -0
- package/dist/components/CommandItem.svelte +2 -0
- package/dist/components/CommandItem.svelte.d.ts +2 -0
- package/dist/components/CommandList.svelte +1 -0
- package/dist/components/CommandList.svelte.d.ts +1 -0
- package/dist/components/Disclosure.svelte +29 -19
- package/dist/components/Disclosure.svelte.d.ts +6 -1
- package/dist/components/Drawer.svelte +26 -20
- package/dist/components/Drawer.svelte.d.ts +6 -1
- package/dist/components/DrawerBody.svelte +1 -0
- package/dist/components/DrawerBody.svelte.d.ts +1 -0
- package/dist/components/DrawerFooter.svelte +1 -0
- package/dist/components/DrawerFooter.svelte.d.ts +1 -0
- package/dist/components/DrawerHeader.svelte +1 -0
- package/dist/components/DrawerHeader.svelte.d.ts +1 -0
- package/dist/components/Dropdown.svelte +45 -24
- package/dist/components/Dropdown.svelte.d.ts +13 -2
- package/dist/components/DropdownGroup.svelte +19 -0
- package/dist/components/DropdownGroup.svelte.d.ts +11 -0
- package/dist/components/DropdownItem.svelte +28 -4
- package/dist/components/DropdownItem.svelte.d.ts +11 -2
- package/dist/components/DropdownMenu.svelte +14 -2
- package/dist/components/DropdownMenu.svelte.d.ts +1 -0
- package/dist/components/DropdownSeparator.svelte +3 -2
- package/dist/components/DropdownTrigger.svelte +14 -2
- package/dist/components/DropdownTrigger.svelte.d.ts +1 -0
- package/dist/components/Field.svelte +42 -3
- package/dist/components/Field.svelte.d.ts +16 -0
- package/dist/components/FieldError.svelte +4 -3
- package/dist/components/FieldError.svelte.d.ts +1 -0
- package/dist/components/FieldHelp.svelte +4 -3
- package/dist/components/FieldHelp.svelte.d.ts +1 -0
- package/dist/components/FieldLabel.svelte +4 -3
- package/dist/components/FieldLabel.svelte.d.ts +1 -0
- package/dist/components/Fieldset.svelte +2 -0
- package/dist/components/Fieldset.svelte.d.ts +2 -0
- package/dist/components/Input.svelte +22 -6
- package/dist/components/Input.svelte.d.ts +3 -0
- package/dist/components/Kbd.svelte +1 -0
- package/dist/components/Kbd.svelte.d.ts +1 -0
- package/dist/components/Menu.svelte +36 -23
- package/dist/components/Menu.svelte.d.ts +18 -5
- package/dist/components/MenuItem.svelte +46 -18
- package/dist/components/MenuItem.svelte.d.ts +10 -7
- package/dist/components/MenuSubmenu.svelte +30 -0
- package/dist/components/MenuSubmenu.svelte.d.ts +17 -0
- package/dist/components/Modal.svelte +17 -18
- package/dist/components/Modal.svelte.d.ts +4 -0
- package/dist/components/ModalBody.svelte +1 -0
- package/dist/components/ModalBody.svelte.d.ts +1 -0
- package/dist/components/ModalFooter.svelte +1 -0
- package/dist/components/ModalFooter.svelte.d.ts +1 -0
- package/dist/components/ModalHeader.svelte +1 -0
- package/dist/components/ModalHeader.svelte.d.ts +1 -0
- package/dist/components/Pagination.svelte +5 -0
- package/dist/components/Pagination.svelte.d.ts +5 -0
- package/dist/components/Popover.svelte +37 -20
- package/dist/components/Popover.svelte.d.ts +12 -2
- package/dist/components/Progress.svelte +4 -0
- package/dist/components/Progress.svelte.d.ts +4 -0
- package/dist/components/Radio.svelte +2 -0
- package/dist/components/Radio.svelte.d.ts +2 -0
- package/dist/components/RadioGroup.svelte +34 -4
- package/dist/components/RadioGroup.svelte.d.ts +10 -1
- package/dist/components/SegmentedControl.svelte +25 -10
- package/dist/components/SegmentedControl.svelte.d.ts +11 -3
- package/dist/components/Select.svelte +16 -5
- package/dist/components/Select.svelte.d.ts +4 -0
- package/dist/components/Separator.svelte +2 -0
- package/dist/components/Separator.svelte.d.ts +2 -0
- package/dist/components/Skeleton.svelte +6 -3
- package/dist/components/Skeleton.svelte.d.ts +4 -1
- package/dist/components/SkipLink.svelte +1 -0
- package/dist/components/SkipLink.svelte.d.ts +1 -0
- package/dist/components/Slider.svelte +23 -2
- package/dist/components/Slider.svelte.d.ts +1 -0
- package/dist/components/Spinner.svelte +2 -0
- package/dist/components/Spinner.svelte.d.ts +2 -0
- package/dist/components/Switch.svelte +25 -2
- package/dist/components/Switch.svelte.d.ts +2 -0
- package/dist/components/Tab.svelte +16 -2
- package/dist/components/Tab.svelte.d.ts +1 -0
- package/dist/components/TabList.svelte +1 -0
- package/dist/components/TabList.svelte.d.ts +1 -0
- package/dist/components/TabPanel.svelte +8 -1
- package/dist/components/TabPanel.svelte.d.ts +1 -0
- package/dist/components/Table.svelte +30 -0
- package/dist/components/Table.svelte.d.ts +17 -0
- package/dist/components/Tabs.svelte +41 -19
- package/dist/components/Tabs.svelte.d.ts +6 -1
- package/dist/components/Textarea.svelte +26 -6
- package/dist/components/Textarea.svelte.d.ts +5 -0
- package/dist/components/ToastRegion.svelte +18 -2
- package/dist/components/ToastRegion.svelte.d.ts +8 -1
- package/dist/components/Toc.svelte +19 -8
- package/dist/components/Toc.svelte.d.ts +6 -0
- package/dist/components/Tooltip.svelte +57 -19
- package/dist/components/Tooltip.svelte.d.ts +16 -7
- package/dist/context.d.ts +84 -8
- package/dist/context.js +60 -11
- package/dist/index.d.ts +8 -4
- package/dist/index.js +6 -4
- package/dist/toast.d.ts +12 -7
- package/dist/toast.js +20 -11
- package/dist/useEnhancer.svelte.d.ts +40 -0
- package/dist/useEnhancer.svelte.js +58 -0
- package/package.json +4 -4
- package/dist/actions.d.ts +0 -25
- package/dist/actions.js +0 -31
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Footer content, typically actions. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const CardFooter: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Header content, typically a `<CardTitle>` and `<CardDescription>`. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const CardHeader: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLHeadingElement> {
|
|
4
|
+
/** Title text. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const CardTitle: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
4
|
+
import { useField } from '../context.js';
|
|
4
5
|
|
|
5
6
|
interface Props extends Omit<HTMLInputAttributes, 'type' | 'checked'> {
|
|
7
|
+
/** Checked state; two-way bindable (`bind:checked`). */
|
|
6
8
|
checked?: boolean;
|
|
9
|
+
/** Label text rendered next to the box. */
|
|
7
10
|
children?: Snippet;
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
let {
|
|
13
|
+
let {
|
|
14
|
+
checked = $bindable(),
|
|
15
|
+
id,
|
|
16
|
+
required,
|
|
17
|
+
'aria-describedby': describedBy,
|
|
18
|
+
'aria-invalid': ariaInvalid,
|
|
19
|
+
class: klass,
|
|
20
|
+
children,
|
|
21
|
+
...rest
|
|
22
|
+
}: Props = $props();
|
|
23
|
+
// Optional: wires id/aria-describedby/aria-invalid/required when inside a <Field>.
|
|
24
|
+
const field = useField();
|
|
11
25
|
</script>
|
|
12
26
|
|
|
13
27
|
<label class={['hl-checkbox', klass]}>
|
|
14
|
-
<input
|
|
28
|
+
<input
|
|
29
|
+
{...rest}
|
|
30
|
+
id={id ?? field?.id}
|
|
31
|
+
required={required ?? (field?.required || undefined)}
|
|
32
|
+
aria-describedby={describedBy ?? field?.describedBy}
|
|
33
|
+
aria-invalid={ariaInvalid ?? (field?.invalid || undefined)}
|
|
34
|
+
type="checkbox"
|
|
35
|
+
bind:checked
|
|
36
|
+
/>
|
|
15
37
|
{#if children}<span>{@render children()}</span>{/if}
|
|
16
38
|
</label>
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends Omit<HTMLInputAttributes, 'type' | 'checked'> {
|
|
4
|
+
/** Checked state; two-way bindable (`bind:checked`). */
|
|
4
5
|
checked?: boolean;
|
|
6
|
+
/** Label text rendered next to the box. */
|
|
5
7
|
children?: Snippet;
|
|
6
8
|
}
|
|
7
9
|
declare const Checkbox: import("svelte").Component<Props, {}, "checked">;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
enhanceCombobox,
|
|
4
|
-
type ComboboxApi,
|
|
5
|
-
type EnhanceComboboxOptions,
|
|
6
|
-
} from '@hydrateless/enhancers';
|
|
2
|
+
import { enhanceCombobox, type EnhanceComboboxOptions } from '@hydrateless/enhancers';
|
|
7
3
|
import { untrack } from 'svelte';
|
|
8
4
|
import type { Snippet } from 'svelte';
|
|
9
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
10
7
|
|
|
11
|
-
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange'> {
|
|
8
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange' | 'onselect'> {
|
|
9
|
+
/** Hide options that don't match the typed query. Defaults to `true`. */
|
|
12
10
|
filter?: EnhanceComboboxOptions['filter'];
|
|
11
|
+
/** Highlight the first match automatically while typing. Defaults to `true`. */
|
|
13
12
|
autoHighlight?: EnhanceComboboxOptions['autoHighlight'];
|
|
14
13
|
/** Committed value; two-way bindable (`bind:value`). */
|
|
15
14
|
value?: string;
|
|
16
15
|
/** Initial committed value for uncontrolled usage. */
|
|
17
16
|
defaultValue?: string;
|
|
18
|
-
/** Called with the committed value
|
|
17
|
+
/** Called with the committed value after a selection or `value` change. */
|
|
19
18
|
onValueChange?: (value: string) => void;
|
|
19
|
+
/** Whether the listbox is expanded; two-way bindable (`bind:open`). */
|
|
20
|
+
open?: boolean;
|
|
21
|
+
/** Expand the listbox initially for uncontrolled usage. */
|
|
22
|
+
defaultOpen?: boolean;
|
|
23
|
+
/** Called after the listbox expands or collapses. */
|
|
24
|
+
onOpenChange?: (open: boolean) => void;
|
|
25
|
+
/** A `<ComboboxInput>` followed by a `<ComboboxList>` of `<ComboboxOption>`s. */
|
|
20
26
|
children?: Snippet;
|
|
21
27
|
}
|
|
22
28
|
|
|
@@ -26,35 +32,40 @@
|
|
|
26
32
|
value = $bindable(),
|
|
27
33
|
defaultValue,
|
|
28
34
|
onValueChange,
|
|
35
|
+
open = $bindable(),
|
|
36
|
+
defaultOpen = false,
|
|
37
|
+
onOpenChange,
|
|
29
38
|
children,
|
|
30
39
|
...rest
|
|
31
40
|
}: Props = $props();
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial values once
|
|
42
|
+
if (value === undefined) value = defaultValue;
|
|
43
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial values once
|
|
44
|
+
if (open === undefined) open = defaultOpen;
|
|
45
|
+
|
|
46
|
+
const combobox = useEnhancer(enhanceCombobox, () => ({
|
|
47
|
+
filter,
|
|
48
|
+
autoHighlight,
|
|
49
|
+
defaultValue: untrack(() => value),
|
|
50
|
+
onValueChange: (next) => {
|
|
51
|
+
value = next;
|
|
52
|
+
onValueChange?.(next);
|
|
53
|
+
},
|
|
54
|
+
onOpenChange: (next) => {
|
|
55
|
+
open = next;
|
|
56
|
+
onOpenChange?.(next);
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
34
59
|
|
|
35
60
|
$effect(() => {
|
|
36
|
-
if (
|
|
37
|
-
const handle = enhanceCombobox(host, {
|
|
38
|
-
filter,
|
|
39
|
-
autoHighlight,
|
|
40
|
-
defaultValue: untrack(() => value ?? defaultValue),
|
|
41
|
-
onValueChange: (next) => {
|
|
42
|
-
value = next;
|
|
43
|
-
onValueChange?.(next);
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
api = handle.api;
|
|
47
|
-
return () => {
|
|
48
|
-
handle.destroy();
|
|
49
|
-
api = null;
|
|
50
|
-
};
|
|
61
|
+
if (value != null) combobox.api?.setValue(value);
|
|
51
62
|
});
|
|
52
63
|
|
|
53
64
|
$effect(() => {
|
|
54
|
-
if (
|
|
65
|
+
if (open != null) combobox.api?.setOpen(open);
|
|
55
66
|
});
|
|
56
67
|
</script>
|
|
57
68
|
|
|
58
|
-
<div {...rest} data-hl-combobox
|
|
69
|
+
<div {...rest} data-hl-combobox {@attach combobox.attach}>
|
|
59
70
|
{@render children?.()}
|
|
60
71
|
</div>
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { type EnhanceComboboxOptions } from '@hydrateless/enhancers';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
-
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange'> {
|
|
4
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange' | 'onselect'> {
|
|
5
|
+
/** Hide options that don't match the typed query. Defaults to `true`. */
|
|
5
6
|
filter?: EnhanceComboboxOptions['filter'];
|
|
7
|
+
/** Highlight the first match automatically while typing. Defaults to `true`. */
|
|
6
8
|
autoHighlight?: EnhanceComboboxOptions['autoHighlight'];
|
|
7
9
|
/** Committed value; two-way bindable (`bind:value`). */
|
|
8
10
|
value?: string;
|
|
9
11
|
/** Initial committed value for uncontrolled usage. */
|
|
10
12
|
defaultValue?: string;
|
|
11
|
-
/** Called with the committed value
|
|
13
|
+
/** Called with the committed value after a selection or `value` change. */
|
|
12
14
|
onValueChange?: (value: string) => void;
|
|
15
|
+
/** Whether the listbox is expanded; two-way bindable (`bind:open`). */
|
|
16
|
+
open?: boolean;
|
|
17
|
+
/** Expand the listbox initially for uncontrolled usage. */
|
|
18
|
+
defaultOpen?: boolean;
|
|
19
|
+
/** Called after the listbox expands or collapses. */
|
|
20
|
+
onOpenChange?: (open: boolean) => void;
|
|
21
|
+
/** A `<ComboboxInput>` followed by a `<ComboboxList>` of `<ComboboxOption>`s. */
|
|
13
22
|
children?: Snippet;
|
|
14
23
|
}
|
|
15
|
-
declare const Combobox: import("svelte").Component<Props, {}, "value">;
|
|
24
|
+
declare const Combobox: import("svelte").Component<Props, {}, "value" | "open">;
|
|
16
25
|
type Combobox = ReturnType<typeof Combobox>;
|
|
17
26
|
export default Combobox;
|
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
|
+
import { useField } from '../context.js';
|
|
3
4
|
|
|
4
5
|
interface Props extends HTMLInputAttributes {
|
|
6
|
+
/** Apply the `hl-input` style. Defaults to `true`. */
|
|
5
7
|
styled?: boolean;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
let {
|
|
10
|
+
let {
|
|
11
|
+
styled = true,
|
|
12
|
+
id,
|
|
13
|
+
required,
|
|
14
|
+
'aria-describedby': describedBy,
|
|
15
|
+
'aria-invalid': ariaInvalid,
|
|
16
|
+
class: klass,
|
|
17
|
+
...rest
|
|
18
|
+
}: Props = $props();
|
|
19
|
+
// Optional: wires id/aria-describedby/aria-invalid/required when inside a <Field>.
|
|
20
|
+
const field = useField();
|
|
9
21
|
</script>
|
|
10
22
|
|
|
11
|
-
<input
|
|
23
|
+
<input
|
|
24
|
+
{...rest}
|
|
25
|
+
id={id ?? field?.id}
|
|
26
|
+
required={required ?? (field?.required || undefined)}
|
|
27
|
+
aria-describedby={describedBy ?? field?.describedBy}
|
|
28
|
+
aria-invalid={ariaInvalid ?? (field?.invalid || undefined)}
|
|
29
|
+
class={[styled && 'hl-input', klass]}
|
|
30
|
+
/>
|
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLAttributes<HTMLUListElement> {
|
|
6
|
+
/** `<ComboboxOption>`s. */
|
|
6
7
|
children?: Snippet;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
let { children, ...rest }: Props = $props();
|
|
10
11
|
</script>
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
<!-- No `hidden` in the markup: before the enhancer runs, the stylesheet keeps
|
|
14
|
+
the listbox reachable on focus-within as a no-JS baseline. -->
|
|
15
|
+
<ul {...rest} role="listbox">
|
|
13
16
|
{@render children?.()}
|
|
14
17
|
</ul>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLUListElement> {
|
|
4
|
+
/** `<ComboboxOption>`s. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const ComboboxList: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
import type { HTMLLiAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLLiAttributes {
|
|
6
|
+
/** Value committed when the option is chosen. */
|
|
6
7
|
value: string;
|
|
8
|
+
/** Skip the option in keyboard navigation and refuse selection. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Option label; defaults to `value`. */
|
|
7
11
|
children?: Snippet;
|
|
8
12
|
}
|
|
9
13
|
|
|
10
|
-
let { value, children, ...rest }: Props = $props();
|
|
14
|
+
let { value, disabled, children, ...rest }: Props = $props();
|
|
11
15
|
</script>
|
|
12
16
|
|
|
13
|
-
<li {...rest} role="option" data-hl-value={value}>
|
|
17
|
+
<li {...rest} role="option" data-hl-value={value} aria-disabled={disabled ? 'true' : undefined}>
|
|
14
18
|
{#if children}{@render children()}{:else}{value}{/if}
|
|
15
19
|
</li>
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLLiAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLLiAttributes {
|
|
4
|
+
/** Value committed when the option is chosen. */
|
|
4
5
|
value: string;
|
|
6
|
+
/** Skip the option in keyboard navigation and refuse selection. */
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** Option label; defaults to `value`. */
|
|
5
9
|
children?: Snippet;
|
|
6
10
|
}
|
|
7
11
|
declare const ComboboxOption: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,25 +1,52 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { enhanceCommand } from '@hydrateless/enhancers';
|
|
3
|
+
import { untrack } from 'svelte';
|
|
3
4
|
import type { Snippet } from 'svelte';
|
|
4
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
5
7
|
|
|
6
|
-
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
-
/**
|
|
8
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange'> {
|
|
9
|
+
/** Filter query; two-way bindable (`bind:query`). */
|
|
10
|
+
query?: string;
|
|
11
|
+
/** Initial filter query for uncontrolled usage. */
|
|
12
|
+
defaultQuery?: string;
|
|
13
|
+
/** Called with the filter query after every change. */
|
|
14
|
+
onQueryChange?: (query: string) => void;
|
|
15
|
+
/** Called with the chosen item's value when a command runs. */
|
|
16
|
+
onCommand?: (value: string, item: HTMLElement) => void;
|
|
17
|
+
/** Lowercased key that opens the hosting `<dialog>` with Cmd/Ctrl. */
|
|
8
18
|
hotkey?: string;
|
|
9
|
-
/**
|
|
10
|
-
onSelect?: (value: string) => void;
|
|
19
|
+
/** A `<CommandInput>`, a `<CommandList>`, and optionally a `<CommandEmpty>`. */
|
|
11
20
|
children?: Snippet;
|
|
12
21
|
}
|
|
13
22
|
|
|
14
|
-
let {
|
|
15
|
-
|
|
23
|
+
let {
|
|
24
|
+
query = $bindable(),
|
|
25
|
+
defaultQuery,
|
|
26
|
+
onQueryChange,
|
|
27
|
+
onCommand,
|
|
28
|
+
hotkey,
|
|
29
|
+
children,
|
|
30
|
+
...rest
|
|
31
|
+
}: Props = $props();
|
|
32
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
33
|
+
if (query === undefined) query = defaultQuery;
|
|
34
|
+
|
|
35
|
+
const command = useEnhancer(enhanceCommand, () => ({
|
|
36
|
+
hotkey,
|
|
37
|
+
defaultValue: untrack(() => query),
|
|
38
|
+
onValueChange: (next) => {
|
|
39
|
+
query = next;
|
|
40
|
+
onQueryChange?.(next);
|
|
41
|
+
},
|
|
42
|
+
onCommand: (value, item) => onCommand?.(value, item),
|
|
43
|
+
}));
|
|
16
44
|
|
|
17
45
|
$effect(() => {
|
|
18
|
-
if (
|
|
19
|
-
return enhanceCommand(host, { hotkey, onCommand: (value) => onSelect?.(value) }).destroy;
|
|
46
|
+
if (query != null) command.api?.setValue(query);
|
|
20
47
|
});
|
|
21
48
|
</script>
|
|
22
49
|
|
|
23
|
-
<div {...rest} data-hl-command data-hl-command-hotkey={hotkey}
|
|
50
|
+
<div {...rest} data-hl-command data-hl-command-hotkey={hotkey} {@attach command.attach}>
|
|
24
51
|
{@render children?.()}
|
|
25
52
|
</div>
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
-
/**
|
|
3
|
+
interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange'> {
|
|
4
|
+
/** Filter query; two-way bindable (`bind:query`). */
|
|
5
|
+
query?: string;
|
|
6
|
+
/** Initial filter query for uncontrolled usage. */
|
|
7
|
+
defaultQuery?: string;
|
|
8
|
+
/** Called with the filter query after every change. */
|
|
9
|
+
onQueryChange?: (query: string) => void;
|
|
10
|
+
/** Called with the chosen item's value when a command runs. */
|
|
11
|
+
onCommand?: (value: string, item: HTMLElement) => void;
|
|
12
|
+
/** Lowercased key that opens the hosting `<dialog>` with Cmd/Ctrl. */
|
|
5
13
|
hotkey?: string;
|
|
6
|
-
/**
|
|
7
|
-
onSelect?: (value: string) => void;
|
|
14
|
+
/** A `<CommandInput>`, a `<CommandList>`, and optionally a `<CommandEmpty>`. */
|
|
8
15
|
children?: Snippet;
|
|
9
16
|
}
|
|
10
|
-
declare const Command: import("svelte").Component<Props, {}, "">;
|
|
17
|
+
declare const Command: import("svelte").Component<Props, {}, "query">;
|
|
11
18
|
type Command = ReturnType<typeof Command>;
|
|
12
19
|
export default Command;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Message shown when no command matches the query. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const CommandEmpty: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,6 +3,7 @@ import type { HTMLAttributes } from 'svelte/elements';
|
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
4
|
/** Optional heading shown above the grouped items. */
|
|
5
5
|
label?: Snippet;
|
|
6
|
+
/** `<CommandItem>`s in this group. */
|
|
6
7
|
children?: Snippet;
|
|
7
8
|
}
|
|
8
9
|
declare const CommandGroup: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
/** Value passed to the Command's `onCommand` when this item runs. */
|
|
6
7
|
value: string;
|
|
7
8
|
/** Extra search terms for filtering. */
|
|
8
9
|
keywords?: string;
|
|
9
10
|
/** Leading icon snippet. */
|
|
10
11
|
icon?: Snippet;
|
|
12
|
+
/** Item label. */
|
|
11
13
|
children?: Snippet;
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Value passed to the Command's `onCommand` when this item runs. */
|
|
4
5
|
value: string;
|
|
5
6
|
/** Extra search terms for filtering. */
|
|
6
7
|
keywords?: string;
|
|
7
8
|
/** Leading icon snippet. */
|
|
8
9
|
icon?: Snippet;
|
|
10
|
+
/** Item label. */
|
|
9
11
|
children?: Snippet;
|
|
10
12
|
}
|
|
11
13
|
declare const CommandItem: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** `<CommandItem>`s, optionally wrapped in `<CommandGroup>`s. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const CommandList: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceDisclosure
|
|
2
|
+
import { enhanceDisclosure } from '@hydrateless/enhancers';
|
|
3
3
|
import { untrack } from 'svelte';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
6
7
|
|
|
7
8
|
interface Props extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
|
|
8
|
-
/**
|
|
9
|
+
/** Plain-text header. Use the `summary` snippet for rich content. */
|
|
10
|
+
title?: string;
|
|
11
|
+
/** The clickable summary/trigger row; overrides `title`. */
|
|
9
12
|
summary?: Snippet;
|
|
10
13
|
/** Open state; two-way bindable (`bind:open`). */
|
|
11
14
|
open?: boolean;
|
|
12
15
|
/** Open the disclosure initially for uncontrolled usage. */
|
|
13
16
|
defaultOpen?: boolean;
|
|
17
|
+
/** Called after the disclosure opens or closes. */
|
|
18
|
+
onOpenChange?: (open: boolean) => void;
|
|
14
19
|
/**
|
|
15
20
|
* Group name. Disclosures sharing a `name` are exclusive: the browser
|
|
16
21
|
* closes the others when one opens, with no JavaScript.
|
|
17
22
|
*/
|
|
18
23
|
name?: string;
|
|
24
|
+
/** Panel content. */
|
|
19
25
|
children?: Snippet;
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
let {
|
|
29
|
+
title,
|
|
23
30
|
summary,
|
|
24
31
|
defaultOpen = false,
|
|
25
32
|
open = $bindable(),
|
|
33
|
+
onOpenChange,
|
|
26
34
|
name,
|
|
27
35
|
class: klass,
|
|
28
36
|
children,
|
|
@@ -30,28 +38,30 @@
|
|
|
30
38
|
}: Props = $props();
|
|
31
39
|
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
32
40
|
if (open === undefined) open = defaultOpen;
|
|
33
|
-
let el = $state<HTMLDetailsElement>();
|
|
34
|
-
let api = $state<DisclosureApi | null>(null);
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
onOpenChange
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return () => {
|
|
44
|
-
handle.destroy();
|
|
45
|
-
api = null;
|
|
46
|
-
};
|
|
47
|
-
});
|
|
42
|
+
const disclosure = useEnhancer(enhanceDisclosure, () => ({
|
|
43
|
+
defaultOpen: untrack(() => open),
|
|
44
|
+
onOpenChange: (next) => {
|
|
45
|
+
open = next;
|
|
46
|
+
onOpenChange?.(next);
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
48
49
|
|
|
49
50
|
$effect(() => {
|
|
50
|
-
if (open != null) api?.setOpen(open);
|
|
51
|
+
if (open != null) disclosure.api?.setOpen(open);
|
|
51
52
|
});
|
|
52
53
|
</script>
|
|
53
54
|
|
|
54
|
-
<details
|
|
55
|
-
|
|
55
|
+
<details
|
|
56
|
+
{...rest}
|
|
57
|
+
{name}
|
|
58
|
+
{open}
|
|
59
|
+
class={['hl-disclosure', klass]}
|
|
60
|
+
data-hl-disclosure
|
|
61
|
+
{@attach disclosure.attach}
|
|
62
|
+
>
|
|
63
|
+
<summary
|
|
64
|
+
>{#if summary}{@render summary()}{:else}{title}{/if}</summary
|
|
65
|
+
>
|
|
56
66
|
<div class="hl-disclosure-panel">{@render children?.()}</div>
|
|
57
67
|
</details>
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
|
|
4
|
-
/**
|
|
4
|
+
/** Plain-text header. Use the `summary` snippet for rich content. */
|
|
5
|
+
title?: string;
|
|
6
|
+
/** The clickable summary/trigger row; overrides `title`. */
|
|
5
7
|
summary?: Snippet;
|
|
6
8
|
/** Open state; two-way bindable (`bind:open`). */
|
|
7
9
|
open?: boolean;
|
|
8
10
|
/** Open the disclosure initially for uncontrolled usage. */
|
|
9
11
|
defaultOpen?: boolean;
|
|
12
|
+
/** Called after the disclosure opens or closes. */
|
|
13
|
+
onOpenChange?: (open: boolean) => void;
|
|
10
14
|
/**
|
|
11
15
|
* Group name. Disclosures sharing a `name` are exclusive: the browser
|
|
12
16
|
* closes the others when one opens, with no JavaScript.
|
|
13
17
|
*/
|
|
14
18
|
name?: string;
|
|
19
|
+
/** Panel content. */
|
|
15
20
|
children?: Snippet;
|
|
16
21
|
}
|
|
17
22
|
declare const Disclosure: import("svelte").Component<Props, {}, "open">;
|