@hydrateless/svelte 0.6.0 → 0.8.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 +2 -2
- package/dist/actions.d.ts +12 -12
- package/dist/actions.js +12 -12
- package/dist/components/Disclosure.svelte +37 -3
- package/dist/components/Disclosure.svelte.d.ts +9 -1
- package/dist/components/Drawer.svelte +8 -3
- package/dist/components/Drawer.svelte.d.ts +2 -0
- package/dist/components/Dropdown.svelte +6 -2
- package/dist/components/Dropdown.svelte.d.ts +2 -0
- package/dist/components/Field.svelte +3 -2
- package/dist/components/Menu.svelte +28 -4
- package/dist/components/Menu.svelte.d.ts +6 -2
- package/dist/components/MenuItem.svelte +6 -3
- package/dist/components/MenuItem.svelte.d.ts +3 -1
- package/dist/components/Modal.svelte +8 -3
- package/dist/components/Modal.svelte.d.ts +2 -0
- package/dist/components/Popover.svelte +25 -8
- package/dist/components/Popover.svelte.d.ts +4 -1
- package/dist/components/SegmentedControl.svelte +17 -4
- package/dist/components/SegmentedControl.svelte.d.ts +3 -0
- package/dist/components/Tooltip.svelte +3 -2
- package/dist/context.d.ts +6 -0
- package/dist/context.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/toast.d.ts +1 -1
- package/dist/toast.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ automatically when the element is destroyed.
|
|
|
10
10
|
npm install hydrateless @hydrateless/svelte
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Import the CSS once (e.g
|
|
13
|
+
Import the CSS once (e.g., in your root layout):
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
import 'hydrateless/hydrateless.css';
|
|
@@ -75,7 +75,7 @@ Interactive components support two-way binding on their state:
|
|
|
75
75
|
|
|
76
76
|
## Toasts
|
|
77
77
|
|
|
78
|
-
`useToast()` works anywhere
|
|
78
|
+
`useToast()` works anywhere, no setup required:
|
|
79
79
|
|
|
80
80
|
```svelte
|
|
81
81
|
<script lang="ts">
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import type { Action } from 'svelte/action';
|
|
2
|
-
/** `use:accordion
|
|
2
|
+
/** `use:accordion`: single-open behavior on a `[data-hl-accordion]` element. */
|
|
3
3
|
export declare const accordion: Action<HTMLElement, undefined, Record<never, any>>;
|
|
4
|
-
/** `use:disclosure
|
|
4
|
+
/** `use:disclosure`: groups `[data-hl-disclosure]` elements within the node. */
|
|
5
5
|
export declare const disclosure: Action<HTMLElement, undefined, Record<never, any>>;
|
|
6
|
-
/** `use:tabs
|
|
6
|
+
/** `use:tabs`: ARIA + keyboard navigation on a `[data-hl-tabs]` element. */
|
|
7
7
|
export declare const tabs: Action<HTMLElement, undefined, Record<never, any>>;
|
|
8
|
-
/** `use:dropdown
|
|
8
|
+
/** `use:dropdown`: menu pattern on a `[data-hl-dropdown]` element. */
|
|
9
9
|
export declare const dropdown: Action<HTMLElement, undefined, Record<never, any>>;
|
|
10
|
-
/** `use:modal
|
|
10
|
+
/** `use:modal`: wires modal openers/closers + focus trap within the node. */
|
|
11
11
|
export declare const modal: Action<HTMLElement, undefined, Record<never, any>>;
|
|
12
|
-
/** `use:drawer
|
|
12
|
+
/** `use:drawer`: wires drawer openers/closers within the node. */
|
|
13
13
|
export declare const drawer: Action<HTMLElement, undefined, Record<never, any>>;
|
|
14
|
-
/** `use:popover
|
|
14
|
+
/** `use:popover`: wires popover openers/closers within the node. */
|
|
15
15
|
export declare const popover: Action<HTMLElement, undefined, Record<never, any>>;
|
|
16
|
-
/** `use:tooltip
|
|
16
|
+
/** `use:tooltip`: wires `[data-hl-tooltip]` triggers within the node. */
|
|
17
17
|
export declare const tooltip: Action<HTMLElement, undefined, Record<never, any>>;
|
|
18
|
-
/** `use:toc
|
|
18
|
+
/** `use:toc`: builds a table of contents from the surrounding document. */
|
|
19
19
|
export declare const toc: Action<HTMLElement, undefined, Record<never, any>>;
|
|
20
|
-
/** `use:menu
|
|
20
|
+
/** `use:menu`: menubar/navigation pattern on a `[data-hl-menu]` element. */
|
|
21
21
|
export declare const menu: Action<HTMLElement, undefined, Record<never, any>>;
|
|
22
|
-
/** `use:combobox
|
|
22
|
+
/** `use:combobox`: editable combobox on a `[data-hl-combobox]` element. */
|
|
23
23
|
export declare const combobox: Action<HTMLElement, undefined, Record<never, any>>;
|
|
24
|
-
/** `use:command
|
|
24
|
+
/** `use:command`: command palette on a `[data-hl-command]` element. */
|
|
25
25
|
export declare const command: Action<HTMLElement, undefined, Record<never, any>>;
|
package/dist/actions.js
CHANGED
|
@@ -5,27 +5,27 @@ function actionFor(enhance) {
|
|
|
5
5
|
return { destroy };
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
|
-
/** `use:accordion
|
|
8
|
+
/** `use:accordion`: single-open behavior on a `[data-hl-accordion]` element. */
|
|
9
9
|
export const accordion = actionFor((node) => enhanceAccordion(node));
|
|
10
|
-
/** `use:disclosure
|
|
10
|
+
/** `use:disclosure`: groups `[data-hl-disclosure]` elements within the node. */
|
|
11
11
|
export const disclosure = actionFor((node) => enhanceDisclosure(node));
|
|
12
|
-
/** `use:tabs
|
|
12
|
+
/** `use:tabs`: ARIA + keyboard navigation on a `[data-hl-tabs]` element. */
|
|
13
13
|
export const tabs = actionFor((node) => enhanceTabs(node));
|
|
14
|
-
/** `use:dropdown
|
|
14
|
+
/** `use:dropdown`: menu pattern on a `[data-hl-dropdown]` element. */
|
|
15
15
|
export const dropdown = actionFor((node) => enhanceDropdown(node));
|
|
16
|
-
/** `use:modal
|
|
16
|
+
/** `use:modal`: wires modal openers/closers + focus trap within the node. */
|
|
17
17
|
export const modal = actionFor((node) => enhanceModal(node));
|
|
18
|
-
/** `use:drawer
|
|
18
|
+
/** `use:drawer`: wires drawer openers/closers within the node. */
|
|
19
19
|
export const drawer = actionFor((node) => enhanceDrawer(node));
|
|
20
|
-
/** `use:popover
|
|
20
|
+
/** `use:popover`: wires popover openers/closers within the node. */
|
|
21
21
|
export const popover = actionFor((node) => enhancePopover(node));
|
|
22
|
-
/** `use:tooltip
|
|
22
|
+
/** `use:tooltip`: wires `[data-hl-tooltip]` triggers within the node. */
|
|
23
23
|
export const tooltip = actionFor((node) => enhanceTooltip(node));
|
|
24
|
-
/** `use:toc
|
|
24
|
+
/** `use:toc`: builds a table of contents from the surrounding document. */
|
|
25
25
|
export const toc = actionFor((node) => enhanceToc(node.ownerDocument));
|
|
26
|
-
/** `use:menu
|
|
26
|
+
/** `use:menu`: menubar/navigation pattern on a `[data-hl-menu]` element. */
|
|
27
27
|
export const menu = actionFor((node) => enhanceMenu(node));
|
|
28
|
-
/** `use:combobox
|
|
28
|
+
/** `use:combobox`: editable combobox on a `[data-hl-combobox]` element. */
|
|
29
29
|
export const combobox = actionFor((node) => enhanceCombobox(node));
|
|
30
|
-
/** `use:command
|
|
30
|
+
/** `use:command`: command palette on a `[data-hl-command]` element. */
|
|
31
31
|
export const command = actionFor((node) => enhanceCommand(node));
|
|
@@ -1,23 +1,57 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { enhanceDisclosure, type DisclosureApi } from '@hydrateless/enhancers';
|
|
3
|
+
import { untrack } from 'svelte';
|
|
2
4
|
import type { Snippet } from 'svelte';
|
|
3
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
6
|
|
|
5
7
|
interface Props extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
|
|
6
8
|
/** The clickable summary/trigger row. */
|
|
7
9
|
summary?: Snippet;
|
|
10
|
+
/** Open state; two-way bindable (`bind:open`). */
|
|
11
|
+
open?: boolean;
|
|
12
|
+
/** Open the disclosure initially for uncontrolled usage. */
|
|
8
13
|
defaultOpen?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Group name. Disclosures sharing a `name` are exclusive: the browser
|
|
16
|
+
* closes the others when one opens, with no JavaScript.
|
|
17
|
+
*/
|
|
18
|
+
name?: string;
|
|
9
19
|
children?: Snippet;
|
|
10
20
|
}
|
|
11
21
|
|
|
12
|
-
let {
|
|
22
|
+
let {
|
|
23
|
+
summary,
|
|
24
|
+
defaultOpen = false,
|
|
25
|
+
open = $bindable(),
|
|
26
|
+
name,
|
|
27
|
+
class: klass,
|
|
28
|
+
children,
|
|
29
|
+
...rest
|
|
30
|
+
}: Props = $props();
|
|
31
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
32
|
+
if (open === undefined) open = defaultOpen;
|
|
13
33
|
let el = $state<HTMLDetailsElement>();
|
|
34
|
+
let api = $state<DisclosureApi | null>(null);
|
|
14
35
|
|
|
15
36
|
$effect(() => {
|
|
16
|
-
if (el
|
|
37
|
+
if (!el) return;
|
|
38
|
+
const handle = enhanceDisclosure(el, {
|
|
39
|
+
defaultOpen: untrack(() => open),
|
|
40
|
+
onOpenChange: (next) => (open = next),
|
|
41
|
+
});
|
|
42
|
+
api = handle.api;
|
|
43
|
+
return () => {
|
|
44
|
+
handle.destroy();
|
|
45
|
+
api = null;
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
$effect(() => {
|
|
50
|
+
if (open != null) api?.setOpen(open);
|
|
17
51
|
});
|
|
18
52
|
</script>
|
|
19
53
|
|
|
20
|
-
<details {...rest} bind:this={el} class={['hl-disclosure', klass]} data-hl-disclosure>
|
|
54
|
+
<details {...rest} bind:this={el} {name} class={['hl-disclosure', klass]} data-hl-disclosure>
|
|
21
55
|
<summary>{@render summary?.()}</summary>
|
|
22
56
|
<div class="hl-disclosure-panel">{@render children?.()}</div>
|
|
23
57
|
</details>
|
|
@@ -3,9 +3,17 @@ import type { HTMLAttributes } from 'svelte/elements';
|
|
|
3
3
|
interface Props extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
|
|
4
4
|
/** The clickable summary/trigger row. */
|
|
5
5
|
summary?: Snippet;
|
|
6
|
+
/** Open state; two-way bindable (`bind:open`). */
|
|
7
|
+
open?: boolean;
|
|
8
|
+
/** Open the disclosure initially for uncontrolled usage. */
|
|
6
9
|
defaultOpen?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Group name. Disclosures sharing a `name` are exclusive: the browser
|
|
12
|
+
* closes the others when one opens, with no JavaScript.
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
7
15
|
children?: Snippet;
|
|
8
16
|
}
|
|
9
|
-
declare const Disclosure: import("svelte").Component<Props, {}, "">;
|
|
17
|
+
declare const Disclosure: import("svelte").Component<Props, {}, "open">;
|
|
10
18
|
type Disclosure = ReturnType<typeof Disclosure>;
|
|
11
19
|
export default Disclosure;
|
|
@@ -7,19 +7,24 @@
|
|
|
7
7
|
interface Props extends HTMLDialogAttributes {
|
|
8
8
|
/** Open state; two-way bindable (`bind:open`). */
|
|
9
9
|
open?: boolean;
|
|
10
|
+
/** Open the drawer initially for uncontrolled usage. */
|
|
11
|
+
defaultOpen?: boolean;
|
|
10
12
|
side?: 'left' | 'right';
|
|
11
13
|
closeOnBackdrop?: boolean;
|
|
12
14
|
children?: Snippet;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
let {
|
|
16
|
-
|
|
18
|
+
defaultOpen = false,
|
|
19
|
+
open = $bindable(),
|
|
17
20
|
side = 'right',
|
|
18
21
|
closeOnBackdrop = true,
|
|
19
22
|
class: klass,
|
|
20
23
|
children,
|
|
21
24
|
...rest
|
|
22
25
|
}: Props = $props();
|
|
26
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
27
|
+
if (open === undefined) open = defaultOpen;
|
|
23
28
|
let dialog = $state<HTMLDialogElement>();
|
|
24
29
|
let api = $state<DrawerApi | null>(null);
|
|
25
30
|
|
|
@@ -27,10 +32,10 @@
|
|
|
27
32
|
if (!dialog) return;
|
|
28
33
|
const handle = enhanceDrawer(dialog, {
|
|
29
34
|
closeOnBackdrop,
|
|
35
|
+
defaultOpen: untrack(() => open),
|
|
30
36
|
onOpenChange: (next) => (open = next),
|
|
31
37
|
});
|
|
32
38
|
api = handle.api;
|
|
33
|
-
if (untrack(() => open)) handle.api?.setOpen(true);
|
|
34
39
|
return () => {
|
|
35
40
|
handle.destroy();
|
|
36
41
|
api = null;
|
|
@@ -38,7 +43,7 @@
|
|
|
38
43
|
});
|
|
39
44
|
|
|
40
45
|
$effect(() => {
|
|
41
|
-
api?.setOpen(open);
|
|
46
|
+
if (open != null) api?.setOpen(open);
|
|
42
47
|
});
|
|
43
48
|
</script>
|
|
44
49
|
|
|
@@ -3,6 +3,8 @@ import type { HTMLDialogAttributes } from 'svelte/elements';
|
|
|
3
3
|
interface Props extends HTMLDialogAttributes {
|
|
4
4
|
/** Open state; two-way bindable (`bind:open`). */
|
|
5
5
|
open?: boolean;
|
|
6
|
+
/** Open the drawer initially for uncontrolled usage. */
|
|
7
|
+
defaultOpen?: boolean;
|
|
6
8
|
side?: 'left' | 'right';
|
|
7
9
|
closeOnBackdrop?: boolean;
|
|
8
10
|
children?: Snippet;
|
|
@@ -12,10 +12,14 @@
|
|
|
12
12
|
placement?: EnhanceDropdownOptions['placement'];
|
|
13
13
|
/** Open state; two-way bindable (`bind:open`). */
|
|
14
14
|
open?: boolean;
|
|
15
|
+
/** Open the menu initially for uncontrolled usage. */
|
|
16
|
+
defaultOpen?: boolean;
|
|
15
17
|
children?: Snippet;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
let { placement, open = $bindable(
|
|
20
|
+
let { placement, defaultOpen = false, open = $bindable(), children, ...rest }: Props = $props();
|
|
21
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
22
|
+
if (open === undefined) open = defaultOpen;
|
|
19
23
|
let host = $state<HTMLDivElement>();
|
|
20
24
|
let api = $state<DropdownApi | null>(null);
|
|
21
25
|
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
});
|
|
35
39
|
|
|
36
40
|
$effect(() => {
|
|
37
|
-
api?.setOpen(open);
|
|
41
|
+
if (open != null) api?.setOpen(open);
|
|
38
42
|
});
|
|
39
43
|
</script>
|
|
40
44
|
|
|
@@ -5,6 +5,8 @@ interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
|
5
5
|
placement?: EnhanceDropdownOptions['placement'];
|
|
6
6
|
/** Open state; two-way bindable (`bind:open`). */
|
|
7
7
|
open?: boolean;
|
|
8
|
+
/** Open the menu initially for uncontrolled usage. */
|
|
9
|
+
defaultOpen?: boolean;
|
|
8
10
|
children?: Snippet;
|
|
9
11
|
}
|
|
10
12
|
declare const Dropdown: import("svelte").Component<Props, {}, "open">;
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
let { id, invalid = false, required = false, class: klass, children, ...rest }: Props = $props();
|
|
14
|
-
|
|
15
|
-
const
|
|
14
|
+
// SSR-safe: $props.id() is stable across server and client renders.
|
|
15
|
+
const generatedId = $props.id();
|
|
16
|
+
const baseId = $derived(id ?? `hl-field-${generatedId}`);
|
|
16
17
|
|
|
17
18
|
setFieldContext({
|
|
18
19
|
get id() {
|
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceMenu, type EnhanceMenuOptions } from '@hydrateless/enhancers';
|
|
2
|
+
import { enhanceMenu, type EnhanceMenuOptions, type MenuApi } from '@hydrateless/enhancers';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
5
|
|
|
6
|
-
interface Props extends HTMLAttributes<HTMLUListElement> {
|
|
6
|
+
interface Props extends Omit<HTMLAttributes<HTMLUListElement>, 'onselect'> {
|
|
7
7
|
orientation?: EnhanceMenuOptions['orientation'];
|
|
8
|
+
/** Open submenu value (or `null`); two-way bindable (`bind:open`). */
|
|
9
|
+
open?: string | null;
|
|
10
|
+
/** Fires with the item's value when a leaf menu item is activated. */
|
|
11
|
+
onSelect?: (value: string) => void;
|
|
8
12
|
children?: Snippet;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
let {
|
|
15
|
+
let {
|
|
16
|
+
orientation = 'horizontal',
|
|
17
|
+
open = $bindable(),
|
|
18
|
+
onSelect,
|
|
19
|
+
children,
|
|
20
|
+
...rest
|
|
21
|
+
}: Props = $props();
|
|
12
22
|
let host = $state<HTMLUListElement>();
|
|
23
|
+
let api = $state<MenuApi | null>(null);
|
|
13
24
|
|
|
14
25
|
$effect(() => {
|
|
15
26
|
if (!host) return;
|
|
16
|
-
|
|
27
|
+
const handle = enhanceMenu(host, {
|
|
28
|
+
orientation,
|
|
29
|
+
onOpenChange: (value) => (open = value),
|
|
30
|
+
onSelect: (value) => onSelect?.(value),
|
|
31
|
+
});
|
|
32
|
+
api = handle.api;
|
|
33
|
+
return () => {
|
|
34
|
+
handle.destroy();
|
|
35
|
+
api = null;
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
$effect(() => {
|
|
40
|
+
if (open !== undefined) api?.setOpen(open);
|
|
17
41
|
});
|
|
18
42
|
</script>
|
|
19
43
|
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { type EnhanceMenuOptions } from '@hydrateless/enhancers';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
-
interface Props extends HTMLAttributes<HTMLUListElement> {
|
|
4
|
+
interface Props extends Omit<HTMLAttributes<HTMLUListElement>, 'onselect'> {
|
|
5
5
|
orientation?: EnhanceMenuOptions['orientation'];
|
|
6
|
+
/** Open submenu value (or `null`); two-way bindable (`bind:open`). */
|
|
7
|
+
open?: string | null;
|
|
8
|
+
/** Fires with the item's value when a leaf menu item is activated. */
|
|
9
|
+
onSelect?: (value: string) => void;
|
|
6
10
|
children?: Snippet;
|
|
7
11
|
}
|
|
8
|
-
declare const Menu: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
declare const Menu: import("svelte").Component<Props, {}, "open">;
|
|
9
13
|
type Menu = ReturnType<typeof Menu>;
|
|
10
14
|
export default Menu;
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
|
-
interface Props extends Omit<HTMLButtonAttributes, 'type'> {
|
|
5
|
+
interface Props extends Omit<HTMLButtonAttributes, 'type' | 'value'> {
|
|
6
6
|
/** Render as a link instead of a button. */
|
|
7
7
|
href?: string;
|
|
8
|
+
/** Stable value identifying this item; defaults to its label text. */
|
|
9
|
+
value?: string;
|
|
8
10
|
/** Convenience handler fired on activation. */
|
|
9
11
|
onSelect?: () => void;
|
|
10
12
|
/** Nested `<MenuItem>`s; renders a single-level submenu. */
|
|
@@ -14,17 +16,18 @@
|
|
|
14
16
|
children?: Snippet;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
let { href, onSelect, onclick, submenu, anchorProps, children, ...rest }: Props = $props();
|
|
19
|
+
let { href, value, onSelect, onclick, submenu, anchorProps, children, ...rest }: Props = $props();
|
|
18
20
|
</script>
|
|
19
21
|
|
|
20
22
|
<li role="none">
|
|
21
23
|
{#if href && !submenu}
|
|
22
|
-
<a {...anchorProps} role="menuitem" {href}>{@render children?.()}</a>
|
|
24
|
+
<a {...anchorProps} role="menuitem" {href} data-hl-value={value}>{@render children?.()}</a>
|
|
23
25
|
{:else}
|
|
24
26
|
<button
|
|
25
27
|
{...rest}
|
|
26
28
|
type="button"
|
|
27
29
|
role="menuitem"
|
|
30
|
+
data-hl-value={value}
|
|
28
31
|
onclick={(e) => {
|
|
29
32
|
onSelect?.();
|
|
30
33
|
onclick?.(e);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
3
|
-
interface Props extends Omit<HTMLButtonAttributes, 'type'> {
|
|
3
|
+
interface Props extends Omit<HTMLButtonAttributes, 'type' | 'value'> {
|
|
4
4
|
/** Render as a link instead of a button. */
|
|
5
5
|
href?: string;
|
|
6
|
+
/** Stable value identifying this item; defaults to its label text. */
|
|
7
|
+
value?: string;
|
|
6
8
|
/** Convenience handler fired on activation. */
|
|
7
9
|
onSelect?: () => void;
|
|
8
10
|
/** Nested `<MenuItem>`s; renders a single-level submenu. */
|
|
@@ -7,17 +7,22 @@
|
|
|
7
7
|
interface Props extends HTMLDialogAttributes {
|
|
8
8
|
/** Open state; two-way bindable (`bind:open`). */
|
|
9
9
|
open?: boolean;
|
|
10
|
+
/** Open the dialog initially for uncontrolled usage. */
|
|
11
|
+
defaultOpen?: boolean;
|
|
10
12
|
closeOnBackdrop?: boolean;
|
|
11
13
|
children?: Snippet;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
let {
|
|
15
|
-
|
|
17
|
+
defaultOpen = false,
|
|
18
|
+
open = $bindable(),
|
|
16
19
|
closeOnBackdrop = true,
|
|
17
20
|
class: klass,
|
|
18
21
|
children,
|
|
19
22
|
...rest
|
|
20
23
|
}: Props = $props();
|
|
24
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
25
|
+
if (open === undefined) open = defaultOpen;
|
|
21
26
|
let dialog = $state<HTMLDialogElement>();
|
|
22
27
|
let api = $state<ModalApi | null>(null);
|
|
23
28
|
|
|
@@ -25,10 +30,10 @@
|
|
|
25
30
|
if (!dialog) return;
|
|
26
31
|
const handle = enhanceModal(dialog, {
|
|
27
32
|
closeOnBackdrop,
|
|
33
|
+
defaultOpen: untrack(() => open),
|
|
28
34
|
onOpenChange: (next) => (open = next),
|
|
29
35
|
});
|
|
30
36
|
api = handle.api;
|
|
31
|
-
if (untrack(() => open)) handle.api?.setOpen(true);
|
|
32
37
|
return () => {
|
|
33
38
|
handle.destroy();
|
|
34
39
|
api = null;
|
|
@@ -36,7 +41,7 @@
|
|
|
36
41
|
});
|
|
37
42
|
|
|
38
43
|
$effect(() => {
|
|
39
|
-
api?.setOpen(open);
|
|
44
|
+
if (open != null) api?.setOpen(open);
|
|
40
45
|
});
|
|
41
46
|
</script>
|
|
42
47
|
|
|
@@ -3,6 +3,8 @@ import type { HTMLDialogAttributes } from 'svelte/elements';
|
|
|
3
3
|
interface Props extends HTMLDialogAttributes {
|
|
4
4
|
/** Open state; two-way bindable (`bind:open`). */
|
|
5
5
|
open?: boolean;
|
|
6
|
+
/** Open the dialog initially for uncontrolled usage. */
|
|
7
|
+
defaultOpen?: boolean;
|
|
6
8
|
closeOnBackdrop?: boolean;
|
|
7
9
|
children?: Snippet;
|
|
8
10
|
}
|
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { enhancePopover, type PopoverApi } from '@hydrateless/enhancers';
|
|
3
|
+
import { untrack } from 'svelte';
|
|
3
4
|
import type { Snippet } from 'svelte';
|
|
4
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
6
|
|
|
6
7
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
-
/** Open state; two-way bindable (`bind:open`).
|
|
8
|
+
/** Open state; two-way bindable (`bind:open`). The browser's light-dismiss
|
|
9
|
+
* (Escape/outside click) closes it and updates the binding. */
|
|
8
10
|
open?: boolean;
|
|
11
|
+
/** Show the popover initially for uncontrolled usage. */
|
|
12
|
+
defaultOpen?: boolean;
|
|
9
13
|
children?: Snippet;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
let { open = $bindable(
|
|
16
|
+
let { defaultOpen = false, open = $bindable(), children, ...rest }: Props = $props();
|
|
17
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
18
|
+
if (open === undefined) open = defaultOpen;
|
|
13
19
|
let host = $state<HTMLDivElement>();
|
|
20
|
+
let api = $state<PopoverApi | null>(null);
|
|
14
21
|
|
|
15
22
|
$effect(() => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
if (!host) return;
|
|
24
|
+
const handle = enhancePopover(host, {
|
|
25
|
+
defaultOpen: untrack(() => open),
|
|
26
|
+
onOpenChange: (next) => (open = next),
|
|
27
|
+
});
|
|
28
|
+
api = handle.api;
|
|
29
|
+
return () => {
|
|
30
|
+
handle.destroy();
|
|
31
|
+
api = null;
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
$effect(() => {
|
|
36
|
+
if (open != null) api?.setOpen(open);
|
|
20
37
|
});
|
|
21
38
|
</script>
|
|
22
39
|
|
|
23
|
-
<div {...rest} data-hl-popover role="dialog"
|
|
40
|
+
<div {...rest} data-hl-popover popover="auto" role="dialog" bind:this={host}>
|
|
24
41
|
{@render children?.()}
|
|
25
42
|
</div>
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
-
/** Open state; two-way bindable (`bind:open`).
|
|
4
|
+
/** Open state; two-way bindable (`bind:open`). The browser's light-dismiss
|
|
5
|
+
* (Escape/outside click) closes it and updates the binding. */
|
|
5
6
|
open?: boolean;
|
|
7
|
+
/** Show the popover initially for uncontrolled usage. */
|
|
8
|
+
defaultOpen?: boolean;
|
|
6
9
|
children?: Snippet;
|
|
7
10
|
}
|
|
8
11
|
declare const Popover: import("svelte").Component<Props, {}, "open">;
|
|
@@ -8,15 +8,28 @@
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
11
|
+
/** Selected value; two-way bindable (`bind:value`). */
|
|
11
12
|
value?: string;
|
|
13
|
+
/** Initially selected value for uncontrolled usage. */
|
|
14
|
+
defaultValue?: string;
|
|
12
15
|
options?: SegmentedOption[];
|
|
13
16
|
name?: string;
|
|
14
17
|
size?: 'sm' | 'md' | 'lg';
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
let {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
let {
|
|
21
|
+
value = $bindable(),
|
|
22
|
+
defaultValue,
|
|
23
|
+
options = [],
|
|
24
|
+
name,
|
|
25
|
+
size,
|
|
26
|
+
class: klass,
|
|
27
|
+
...rest
|
|
28
|
+
}: Props = $props();
|
|
29
|
+
// SSR-safe: $props.id() is stable across server and client renders.
|
|
30
|
+
const generatedName = $props.id();
|
|
31
|
+
const groupName = $derived(name ?? `hl-seg-${generatedName}`);
|
|
32
|
+
const current = $derived(value ?? defaultValue);
|
|
20
33
|
</script>
|
|
21
34
|
|
|
22
35
|
<div {...rest} role="radiogroup" class={['hl-segmented', klass]} data-hl-size={size}>
|
|
@@ -26,7 +39,7 @@
|
|
|
26
39
|
type="radio"
|
|
27
40
|
name={groupName}
|
|
28
41
|
value={option.value}
|
|
29
|
-
checked={
|
|
42
|
+
checked={current === option.value}
|
|
30
43
|
disabled={option.disabled}
|
|
31
44
|
onchange={() => (value = option.value)}
|
|
32
45
|
/>
|
|
@@ -5,7 +5,10 @@ interface SegmentedOption {
|
|
|
5
5
|
disabled?: boolean;
|
|
6
6
|
}
|
|
7
7
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
/** Selected value; two-way bindable (`bind:value`). */
|
|
8
9
|
value?: string;
|
|
10
|
+
/** Initially selected value for uncontrolled usage. */
|
|
11
|
+
defaultValue?: string;
|
|
9
12
|
options?: SegmentedOption[];
|
|
10
13
|
name?: string;
|
|
11
14
|
size?: 'sm' | 'md' | 'lg';
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
let { label, tip, id, children }: Props = $props();
|
|
16
|
-
|
|
17
|
-
const
|
|
16
|
+
// SSR-safe: $props.id() is stable across server and client renders.
|
|
17
|
+
const generatedId = $props.id();
|
|
18
|
+
const tipId = $derived(id ?? `hl-tip-${generatedId}`);
|
|
18
19
|
let host = $state<HTMLSpanElement>();
|
|
19
20
|
|
|
20
21
|
$effect(() => {
|
package/dist/context.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Shared field state a Field provides to its controls (ids and validity flags). */
|
|
1
2
|
export interface FieldContext {
|
|
2
3
|
readonly id: string;
|
|
3
4
|
readonly helpId: string;
|
|
@@ -5,14 +6,19 @@ export interface FieldContext {
|
|
|
5
6
|
readonly invalid: boolean;
|
|
6
7
|
readonly required: boolean;
|
|
7
8
|
}
|
|
9
|
+
/** Publish {@link FieldContext} to the descendant controls of a Field. */
|
|
8
10
|
export declare function setFieldContext(ctx: FieldContext): void;
|
|
11
|
+
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. */
|
|
9
12
|
export declare function getFieldContext(): FieldContext | undefined;
|
|
10
13
|
/** Returns attributes (`id`, `aria-describedby`, `aria-invalid`) for a field control. */
|
|
11
14
|
export declare function fieldBindings(): Record<string, string | boolean | undefined>;
|
|
15
|
+
/** Shared state a RadioGroup provides to its radios (name, selected value, and a setter). */
|
|
12
16
|
export interface RadioGroupContext {
|
|
13
17
|
readonly name: string | undefined;
|
|
14
18
|
readonly value: string | undefined;
|
|
15
19
|
select: (value: string) => void;
|
|
16
20
|
}
|
|
21
|
+
/** Publish {@link RadioGroupContext} to the descendant radios of a group. */
|
|
17
22
|
export declare function setRadioGroupContext(ctx: RadioGroupContext): void;
|
|
23
|
+
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. */
|
|
18
24
|
export declare function getRadioGroupContext(): RadioGroupContext | undefined;
|
package/dist/context.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte';
|
|
2
2
|
const FIELD_KEY = Symbol('hl-field');
|
|
3
|
+
/** Publish {@link FieldContext} to the descendant controls of a Field. */
|
|
3
4
|
export function setFieldContext(ctx) {
|
|
4
5
|
setContext(FIELD_KEY, ctx);
|
|
5
6
|
}
|
|
7
|
+
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. */
|
|
6
8
|
export function getFieldContext() {
|
|
7
9
|
return getContext(FIELD_KEY);
|
|
8
10
|
}
|
|
@@ -19,9 +21,11 @@ export function fieldBindings() {
|
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
const RADIO_GROUP_KEY = Symbol('hl-radio-group');
|
|
24
|
+
/** Publish {@link RadioGroupContext} to the descendant radios of a group. */
|
|
22
25
|
export function setRadioGroupContext(ctx) {
|
|
23
26
|
setContext(RADIO_GROUP_KEY, ctx);
|
|
24
27
|
}
|
|
28
|
+
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. */
|
|
25
29
|
export function getRadioGroupContext() {
|
|
26
30
|
return getContext(RADIO_GROUP_KEY);
|
|
27
31
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -72,4 +72,4 @@ export { default as Separator } from './components/Separator.svelte';
|
|
|
72
72
|
export { default as Pagination } from './components/Pagination.svelte';
|
|
73
73
|
export { default as Toc } from './components/Toc.svelte';
|
|
74
74
|
export { default as SkipLink } from './components/SkipLink.svelte';
|
|
75
|
-
export type { AccordionApi, ComboboxApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, ModalApi, PopoverApi, TabsApi, ToastApi, TooltipApi, } from '@hydrateless/enhancers';
|
|
75
|
+
export type { AccordionApi, CommandApi, ComboboxApi, DisclosureApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, MenuApi, ModalApi, PopoverApi, TabsApi, ToastApi, TocApi, TooltipApi, } from '@hydrateless/enhancers';
|
package/dist/toast.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type EnhanceToastOptions, type ToastApi } from '@hydrateless/enhancers'
|
|
|
2
2
|
/**
|
|
3
3
|
* Imperative toast API backed by a lazily-created document-level region (or a
|
|
4
4
|
* `[data-hl-toast-region]` you render yourself, e.g. via `<ToastRegion>`).
|
|
5
|
-
* Safe to call from anywhere
|
|
5
|
+
* Safe to call from anywhere, no setup required:
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* import { useToast } from '@hydrateless/svelte';
|
package/dist/toast.js
CHANGED
|
@@ -3,7 +3,7 @@ let shared = null;
|
|
|
3
3
|
/**
|
|
4
4
|
* Imperative toast API backed by a lazily-created document-level region (or a
|
|
5
5
|
* `[data-hl-toast-region]` you render yourself, e.g. via `<ToastRegion>`).
|
|
6
|
-
* Safe to call from anywhere
|
|
6
|
+
* Safe to call from anywhere, no setup required:
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* import { useToast } from '@hydrateless/svelte';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydrateless/svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Svelte 5 bindings for Hydrateless
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Svelte 5 bindings for Hydrateless: first-class components, actions, and a toast store.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test": "vitest run"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@hydrateless/enhancers": "^0.
|
|
35
|
+
"@hydrateless/enhancers": "^0.8.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"svelte": ">=5"
|