@hydrateless/svelte 0.10.1 → 0.11.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 CHANGED
@@ -177,9 +177,10 @@ appends one to `<body>`.
177
177
 
178
178
  Every component is built on one attachment factory, and it's exported so a
179
179
  custom wrapper behaves exactly like the shipped ones. Pass an enhancer and a
180
- function returning its options; the returned `attach` runs the enhancer when the
181
- element mounts and destroys it when the element leaves or the options change.
182
- `api` is the enhancer's imperative handle (or `null` while detached).
180
+ function returning its options; the returned `attach` attaches the enhancer
181
+ once on mount, updates options in place via `handle.update()` when reactive
182
+ options change, and destroys it when the element leaves. `api` is the
183
+ enhancer's imperative handle (or `null` while detached).
183
184
 
184
185
  ```svelte
185
186
  <script lang="ts">
@@ -191,12 +192,12 @@ element mounts and destroys it when the element leaves or the options change.
191
192
  </script>
192
193
 
193
194
  <button onclick={() => tabs.api?.setValue('install')}>Jump to Install</button>
194
- <div data-hl-tabs {@attach tabs.attach}>...</div>
195
+ <div class="hl-tabs" data-hl-tabs {@attach tabs.attach}>...</div>
195
196
  ```
196
197
 
197
- Reactive state read inside the options function re-runs the enhancer; wrap
198
- seed values (like a bound `value` passed as `defaultValue`) in `untrack` to
199
- keep them from doing so.
198
+ Reactive state read inside the options function triggers an in-place
199
+ `handle.update()` without closing open overlays or resetting state; wrap seed
200
+ values (like a bound `value` passed as `defaultValue`) in `untrack`.
200
201
 
201
202
  ## Changes from 0.x actions
202
203
 
@@ -25,11 +25,13 @@
25
25
  value = $bindable(),
26
26
  defaultValue,
27
27
  onValueChange,
28
+ class: klass,
28
29
  children,
29
30
  ...rest
30
31
  }: Props = $props();
31
32
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
32
33
  if (value === undefined) value = defaultValue ?? [];
34
+ let syncTick = $state(0);
33
35
 
34
36
  // Items register in document order so each `<details>` can render `open`
35
37
  // on the server from the shared value; indexes stay live for `{#each}`.
@@ -47,14 +49,16 @@
47
49
  onValueChange: (next) => {
48
50
  value = next;
49
51
  onValueChange?.(next);
52
+ syncTick += 1;
50
53
  },
51
54
  }));
52
55
 
53
56
  $effect(() => {
54
- if (value != null) accordion.api?.setValue(value);
57
+ void syncTick;
58
+ if (value != null) accordion.api?.setValue(value, { silent: true });
55
59
  });
56
60
  </script>
57
61
 
58
- <div {...rest} data-hl-accordion {@attach accordion.attach}>
62
+ <div {...rest} class={['hl-accordion', klass]} data-hl-accordion {@attach accordion.attach}>
59
63
  {@render children?.()}
60
64
  </div>
@@ -7,9 +7,9 @@
7
7
  children?: Snippet;
8
8
  }
9
9
 
10
- let { 'aria-label': ariaLabel = 'Breadcrumb', children, ...rest }: Props = $props();
10
+ let { 'aria-label': ariaLabel = 'Breadcrumb', class: klass, children, ...rest }: Props = $props();
11
11
  </script>
12
12
 
13
- <nav {...rest} data-hl-breadcrumb aria-label={ariaLabel}>
13
+ <nav {...rest} class={['hl-breadcrumb', klass]} aria-label={ariaLabel}>
14
14
  <ol>{@render children?.()}</ol>
15
15
  </nav>
@@ -35,6 +35,7 @@
35
35
  open = $bindable(),
36
36
  defaultOpen = false,
37
37
  onOpenChange,
38
+ class: klass,
38
39
  children,
39
40
  ...rest
40
41
  }: Props = $props();
@@ -42,30 +43,41 @@
42
43
  if (value === undefined) value = defaultValue;
43
44
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial values once
44
45
  if (open === undefined) open = defaultOpen;
46
+ let valueTick = $state(0);
47
+ let openTick = $state(0);
45
48
 
46
49
  const combobox = useEnhancer(enhanceCombobox, () => ({
47
50
  filter,
48
51
  autoHighlight,
49
52
  defaultValue: untrack(() => value),
53
+ defaultOpen: untrack(() => open),
50
54
  onValueChange: (next) => {
51
55
  value = next;
52
56
  onValueChange?.(next);
57
+ valueTick += 1;
53
58
  },
54
59
  onOpenChange: (next) => {
55
60
  open = next;
56
61
  onOpenChange?.(next);
62
+ openTick += 1;
57
63
  },
58
64
  }));
59
65
 
60
66
  $effect(() => {
61
- if (value != null) combobox.api?.setValue(value);
67
+ void valueTick;
68
+ if (value != null && combobox.api && combobox.api.value !== value) {
69
+ combobox.api.setValue(value, { silent: true });
70
+ }
62
71
  });
63
72
 
64
73
  $effect(() => {
65
- if (open != null) combobox.api?.setOpen(open);
74
+ void openTick;
75
+ if (open != null && combobox.api && combobox.api.open !== open) {
76
+ combobox.api.setOpen(open, { silent: true });
77
+ }
66
78
  });
67
79
  </script>
68
80
 
69
- <div {...rest} data-hl-combobox {@attach combobox.attach}>
81
+ <div {...rest} class={['hl-combobox', klass]} data-hl-combobox {@attach combobox.attach}>
70
82
  {@render children?.()}
71
83
  </div>
@@ -26,11 +26,13 @@
26
26
  onQueryChange,
27
27
  onCommand,
28
28
  hotkey,
29
+ class: klass,
29
30
  children,
30
31
  ...rest
31
32
  }: Props = $props();
32
33
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
33
34
  if (query === undefined) query = defaultQuery;
35
+ let syncTick = $state(0);
34
36
 
35
37
  const command = useEnhancer(enhanceCommand, () => ({
36
38
  hotkey,
@@ -38,15 +40,25 @@
38
40
  onValueChange: (next) => {
39
41
  query = next;
40
42
  onQueryChange?.(next);
43
+ syncTick += 1;
41
44
  },
42
45
  onCommand: (value, item) => onCommand?.(value, item),
43
46
  }));
44
47
 
45
48
  $effect(() => {
46
- if (query != null) command.api?.setValue(query);
49
+ void syncTick;
50
+ if (query != null && command.api && command.api.value !== query) {
51
+ command.api.setValue(query, { silent: true });
52
+ }
47
53
  });
48
54
  </script>
49
55
 
50
- <div {...rest} data-hl-command data-hl-hotkey={hotkey} {@attach command.attach}>
56
+ <div
57
+ {...rest}
58
+ class={['hl-command', klass]}
59
+ data-hl-command
60
+ data-hl-hotkey={hotkey}
61
+ {@attach command.attach}
62
+ >
51
63
  {@render children?.()}
52
64
  </div>
@@ -7,9 +7,9 @@
7
7
  children?: Snippet;
8
8
  }
9
9
 
10
- let { children, ...rest }: Props = $props();
10
+ let { class: klass, children, ...rest }: Props = $props();
11
11
  </script>
12
12
 
13
- <div {...rest} data-hl-command-empty hidden>
13
+ <div {...rest} class={['hl-command-empty', klass]} data-hl-command-empty hidden>
14
14
  {#if children}{@render children()}{:else}No results found.{/if}
15
15
  </div>
@@ -9,10 +9,10 @@
9
9
  children?: Snippet;
10
10
  }
11
11
 
12
- let { label, children, ...rest }: Props = $props();
12
+ let { label, class: klass, children, ...rest }: Props = $props();
13
13
  </script>
14
14
 
15
- <div {...rest} data-hl-command-group>
15
+ <div {...rest} class={['hl-command-group', klass]} data-hl-command-group>
16
16
  {#if label}<div class="hl-command-group-label" role="presentation">{@render label()}</div>{/if}
17
17
  {@render children?.()}
18
18
  </div>
@@ -9,4 +9,4 @@
9
9
  let { styled = true, class: klass, ...rest }: Props = $props();
10
10
  </script>
11
11
 
12
- <input {...rest} class={[styled && 'hl-input', klass]} data-hl-command-input />
12
+ <input {...rest} class={['hl-command-input', styled && 'hl-input', klass]} data-hl-command-input />
@@ -7,9 +7,9 @@
7
7
  children?: Snippet;
8
8
  }
9
9
 
10
- let { children, ...rest }: Props = $props();
10
+ let { class: klass, children, ...rest }: Props = $props();
11
11
  </script>
12
12
 
13
- <div {...rest} data-hl-command-list role="listbox">
13
+ <div {...rest} class={['hl-command-list', klass]} data-hl-command-list role="listbox">
14
14
  {@render children?.()}
15
15
  </div>
@@ -38,17 +38,20 @@
38
38
  }: Props = $props();
39
39
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
40
40
  if (open === undefined) open = defaultOpen;
41
+ let syncTick = $state(0);
41
42
 
42
43
  const disclosure = useEnhancer(enhanceDisclosure, () => ({
43
44
  defaultOpen: untrack(() => open),
44
45
  onOpenChange: (next) => {
45
46
  open = next;
46
47
  onOpenChange?.(next);
48
+ syncTick += 1;
47
49
  },
48
50
  }));
49
51
 
50
52
  $effect(() => {
51
- if (open != null) disclosure.api?.setOpen(open);
53
+ void syncTick;
54
+ if (open != null) disclosure.api?.setOpen(open, { silent: true });
52
55
  });
53
56
  </script>
54
57
 
@@ -32,6 +32,7 @@
32
32
  }: Props = $props();
33
33
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
34
34
  if (open === undefined) open = defaultOpen;
35
+ let syncTick = $state(0);
35
36
 
36
37
  const drawer = useEnhancer(enhanceDrawer, () => ({
37
38
  closeOnBackdrop,
@@ -39,11 +40,15 @@
39
40
  onOpenChange: (next) => {
40
41
  open = next;
41
42
  onOpenChange?.(next);
43
+ syncTick += 1;
42
44
  },
43
45
  }));
44
46
 
45
47
  $effect(() => {
46
- if (open != null) drawer.api?.setOpen(open);
48
+ void syncTick;
49
+ if (open != null && drawer.api && drawer.api.open !== open) {
50
+ drawer.api.setOpen(open, { silent: true });
51
+ }
47
52
  });
48
53
  </script>
49
54
 
@@ -0,0 +1,19 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLButtonAttributes } from 'svelte/elements';
4
+
5
+ interface Props extends Omit<HTMLButtonAttributes, 'command' | 'commandfor'> {
6
+ /** Id of the `<Drawer>` dialog this button invokes (`commandfor`). */
7
+ target: string;
8
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
9
+ command?: 'show-modal' | 'close';
10
+ /** Button label. */
11
+ children?: Snippet;
12
+ }
13
+
14
+ let { target, command = 'show-modal', type = 'button', children, ...rest }: Props = $props();
15
+ </script>
16
+
17
+ <button {...rest} {type} {...{ command, commandfor: target }}>
18
+ {@render children?.()}
19
+ </button>
@@ -0,0 +1,13 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLButtonAttributes } from 'svelte/elements';
3
+ interface Props extends Omit<HTMLButtonAttributes, 'command' | 'commandfor'> {
4
+ /** Id of the `<Drawer>` dialog this button invokes (`commandfor`). */
5
+ target: string;
6
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
7
+ command?: 'show-modal' | 'close';
8
+ /** Button label. */
9
+ children?: Snippet;
10
+ }
11
+ declare const DrawerTrigger: import("svelte").Component<Props, {}, "">;
12
+ type DrawerTrigger = ReturnType<typeof DrawerTrigger>;
13
+ export default DrawerTrigger;
@@ -33,11 +33,13 @@
33
33
  onSelect,
34
34
  closeOnSelect = true,
35
35
  placement,
36
+ class: klass,
36
37
  children,
37
38
  ...rest
38
39
  }: Props = $props();
39
40
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
40
41
  if (open === undefined) open = defaultOpen;
42
+ let syncTick = $state(0);
41
43
 
42
44
  // The trigger's `popovertarget` must name the menu in server-rendered
43
45
  // markup so the menu opens before (or without) JavaScript.
@@ -57,15 +59,19 @@
57
59
  onOpenChange: (next) => {
58
60
  open = next;
59
61
  onOpenChange?.(next);
62
+ syncTick += 1;
60
63
  },
61
64
  onSelect: (value, item, checked) => onSelect?.(value, item, checked),
62
65
  }));
63
66
 
64
67
  $effect(() => {
65
- if (open != null) dropdown.api?.setOpen(open);
68
+ void syncTick;
69
+ if (open != null && dropdown.api && dropdown.api.open !== open) {
70
+ dropdown.api.setOpen(open, { silent: true });
71
+ }
66
72
  });
67
73
  </script>
68
74
 
69
- <div {...rest} data-hl-dropdown {@attach dropdown.attach}>
75
+ <div {...rest} class={['hl-dropdown', klass]} data-hl-dropdown {@attach dropdown.attach}>
70
76
  {@render children?.()}
71
77
  </div>
@@ -8,7 +8,7 @@
8
8
  children?: Snippet;
9
9
  }
10
10
 
11
- let { id, children, ...rest }: Props = $props();
11
+ let { id, class: klass, children, ...rest }: Props = $props();
12
12
  const dropdown = getDropdownContext();
13
13
  </script>
14
14
 
@@ -17,6 +17,7 @@
17
17
  <ul
18
18
  {...rest}
19
19
  id={id ?? dropdown?.menuId}
20
+ class={['hl-dropdown-menu', klass]}
20
21
  data-hl-dropdown-menu
21
22
  popover="auto"
22
23
  role="menu"
@@ -33,11 +33,13 @@
33
33
  defaultValue = null,
34
34
  onValueChange,
35
35
  onSelect,
36
+ class: klass,
36
37
  children,
37
38
  ...rest
38
39
  }: Props = $props();
39
40
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
40
41
  if (value === undefined) value = defaultValue;
42
+ let syncTick = $state(0);
41
43
 
42
44
  const menu = useEnhancer(enhanceMenu, () => ({
43
45
  orientation,
@@ -45,17 +47,22 @@
45
47
  onValueChange: (next) => {
46
48
  value = next;
47
49
  onValueChange?.(next);
50
+ syncTick += 1;
48
51
  },
49
52
  onSelect: (itemValue, item, checked) => onSelect?.(itemValue, item, checked),
50
53
  }));
51
54
 
52
55
  $effect(() => {
53
- if (value !== undefined) menu.api?.setValue(value);
56
+ void syncTick;
57
+ if (value !== undefined && menu.api && menu.api.value !== value) {
58
+ menu.api.setValue(value, { silent: true });
59
+ }
54
60
  });
55
61
  </script>
56
62
 
57
63
  <ul
58
64
  {...rest}
65
+ class={['hl-menu', klass]}
59
66
  data-hl-menu
60
67
  role={orientation === 'vertical' ? 'menu' : 'menubar'}
61
68
  aria-orientation={orientation}
@@ -29,6 +29,7 @@
29
29
  }: Props = $props();
30
30
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
31
31
  if (open === undefined) open = defaultOpen;
32
+ let syncTick = $state(0);
32
33
 
33
34
  const modal = useEnhancer(enhanceModal, () => ({
34
35
  closeOnBackdrop,
@@ -36,11 +37,15 @@
36
37
  onOpenChange: (next) => {
37
38
  open = next;
38
39
  onOpenChange?.(next);
40
+ syncTick += 1;
39
41
  },
40
42
  }));
41
43
 
42
44
  $effect(() => {
43
- if (open != null) modal.api?.setOpen(open);
45
+ void syncTick;
46
+ if (open != null && modal.api && modal.api.open !== open) {
47
+ modal.api.setOpen(open, { silent: true });
48
+ }
44
49
  });
45
50
  </script>
46
51
 
@@ -0,0 +1,19 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLButtonAttributes } from 'svelte/elements';
4
+
5
+ interface Props extends Omit<HTMLButtonAttributes, 'command' | 'commandfor'> {
6
+ /** Id of the `<Modal>` dialog this button invokes (`commandfor`). */
7
+ target: string;
8
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
9
+ command?: 'show-modal' | 'close';
10
+ /** Button label. */
11
+ children?: Snippet;
12
+ }
13
+
14
+ let { target, command = 'show-modal', type = 'button', children, ...rest }: Props = $props();
15
+ </script>
16
+
17
+ <button {...rest} {type} {...{ command, commandfor: target }}>
18
+ {@render children?.()}
19
+ </button>
@@ -0,0 +1,13 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLButtonAttributes } from 'svelte/elements';
3
+ interface Props extends Omit<HTMLButtonAttributes, 'command' | 'commandfor'> {
4
+ /** Id of the `<Modal>` dialog this button invokes (`commandfor`). */
5
+ target: string;
6
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
7
+ command?: 'show-modal' | 'close';
8
+ /** Button label. */
9
+ children?: Snippet;
10
+ }
11
+ declare const ModalTrigger: import("svelte").Component<Props, {}, "">;
12
+ type ModalTrigger = ReturnType<typeof ModalTrigger>;
13
+ export default ModalTrigger;
@@ -30,11 +30,13 @@
30
30
  placement,
31
31
  hover = false,
32
32
  id,
33
+ class: klass,
33
34
  children,
34
35
  ...rest
35
36
  }: Props = $props();
36
37
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
37
38
  if (open === undefined) open = defaultOpen;
39
+ let syncTick = $state(0);
38
40
  // An id is required so invokers can target the popover before hydration.
39
41
  const generatedId = $props.id();
40
42
  const popoverId = $derived(id ?? `hl-popover-${generatedId}`);
@@ -46,14 +48,26 @@
46
48
  onOpenChange: (next) => {
47
49
  open = next;
48
50
  onOpenChange?.(next);
51
+ syncTick += 1;
49
52
  },
50
53
  }));
51
54
 
52
55
  $effect(() => {
53
- if (open != null) popover.api?.setOpen(open);
56
+ void syncTick;
57
+ if (open != null && popover.api && popover.api.open !== open) {
58
+ popover.api.setOpen(open, { silent: true });
59
+ }
54
60
  });
55
61
  </script>
56
62
 
57
- <div {...rest} id={popoverId} data-hl-popover popover="auto" role="dialog" {@attach popover.attach}>
63
+ <div
64
+ {...rest}
65
+ id={popoverId}
66
+ class={['hl-popover', klass]}
67
+ data-hl-popover
68
+ popover="auto"
69
+ role="dialog"
70
+ {@attach popover.attach}
71
+ >
58
72
  {@render children?.()}
59
73
  </div>
@@ -0,0 +1,24 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLButtonAttributes } from 'svelte/elements';
4
+
5
+ interface Props extends Omit<HTMLButtonAttributes, 'popovertarget' | 'popovertargetaction'> {
6
+ /** Id of the `<Popover>` surface this button invokes (`popovertarget`). */
7
+ target: string;
8
+ /** Popover action to perform. Defaults to `'toggle'`. */
9
+ action?: 'toggle' | 'show' | 'hide';
10
+ /** Button label. */
11
+ children?: Snippet;
12
+ }
13
+
14
+ let { target, action = 'toggle', type = 'button', children, ...rest }: Props = $props();
15
+ </script>
16
+
17
+ <button
18
+ {...rest}
19
+ {type}
20
+ popovertarget={target}
21
+ popovertargetaction={action === 'toggle' ? undefined : action}
22
+ >
23
+ {@render children?.()}
24
+ </button>
@@ -0,0 +1,13 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLButtonAttributes } from 'svelte/elements';
3
+ interface Props extends Omit<HTMLButtonAttributes, 'popovertarget' | 'popovertargetaction'> {
4
+ /** Id of the `<Popover>` surface this button invokes (`popovertarget`). */
5
+ target: string;
6
+ /** Popover action to perform. Defaults to `'toggle'`. */
7
+ action?: 'toggle' | 'show' | 'hide';
8
+ /** Button label. */
9
+ children?: Snippet;
10
+ }
11
+ declare const PopoverTrigger: import("svelte").Component<Props, {}, "">;
12
+ type PopoverTrigger = ReturnType<typeof PopoverTrigger>;
13
+ export default PopoverTrigger;
@@ -24,7 +24,7 @@
24
24
  const field = useField();
25
25
  </script>
26
26
 
27
- <label data-hl-switch class={klass}>
27
+ <label class={['hl-switch', klass]}>
28
28
  <input
29
29
  {...rest}
30
30
  id={id ?? field?.id}
@@ -28,11 +28,13 @@
28
28
  value = $bindable(),
29
29
  defaultValue,
30
30
  onValueChange,
31
+ class: klass,
31
32
  children,
32
33
  ...rest
33
34
  }: Props = $props();
34
35
  // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
35
36
  if (value === undefined) value = defaultValue;
37
+ let syncTick = $state(0);
36
38
 
37
39
  // Tabs and panels register in document order so `aria-selected`/`hidden`
38
40
  // render on the server and the enhancer finds them already in agreement.
@@ -56,14 +58,24 @@
56
58
  onValueChange: (next) => {
57
59
  value = next;
58
60
  onValueChange?.(next);
61
+ syncTick += 1;
59
62
  },
60
63
  }));
61
64
 
62
65
  $effect(() => {
63
- if (value != null) enhanced.api?.setValue(value);
66
+ void syncTick;
67
+ if (value != null && enhanced.api && enhanced.api.value !== value) {
68
+ enhanced.api.setValue(value, { silent: true });
69
+ }
64
70
  });
65
71
  </script>
66
72
 
67
- <div {...rest} data-hl-tabs data-hl-orientation={orientation} {@attach enhanced.attach}>
73
+ <div
74
+ {...rest}
75
+ class={['hl-tabs', klass]}
76
+ data-hl-tabs
77
+ data-hl-orientation={orientation}
78
+ {@attach enhanced.attach}
79
+ >
68
80
  {@render children?.()}
69
81
  </div>
@@ -10,7 +10,7 @@
10
10
  onOpenChange?: EnhanceToastOptions['onOpenChange'];
11
11
  }
12
12
 
13
- let { duration, onOpenChange, ...rest }: Props = $props();
13
+ let { duration, onOpenChange, class: klass, ...rest }: Props = $props();
14
14
 
15
15
  // Enhanced on mount so `useToast()` adopts this region (and its defaults)
16
16
  // instead of appending its own to <body>.
@@ -20,4 +20,4 @@
20
20
  }));
21
21
  </script>
22
22
 
23
- <div {...rest} data-hl-toast-region {@attach toast.attach}></div>
23
+ <div {...rest} class={['hl-toast-region', klass]} data-hl-toast-region {@attach toast.attach}></div>
@@ -15,7 +15,7 @@
15
15
  children?: Snippet;
16
16
  }
17
17
 
18
- let { contentSelector, headings, scrollSpy, children, ...rest }: Props = $props();
18
+ let { contentSelector, headings, scrollSpy, class: klass, children, ...rest }: Props = $props();
19
19
 
20
20
  // The headings live outside the nav, so the enhancer scans the document and
21
21
  // finds this nav as the `[data-hl-toc]` root within it.
@@ -26,6 +26,6 @@
26
26
  );
27
27
  </script>
28
28
 
29
- <nav {...rest} data-hl-toc {@attach toc.attach}>
29
+ <nav {...rest} class={['hl-toc', klass]} data-hl-toc {@attach toc.attach}>
30
30
  {@render children?.()}
31
31
  </nav>
@@ -54,6 +54,8 @@
54
54
  'aria-describedby': tipId,
55
55
  };
56
56
 
57
+ let syncTick = $state(0);
58
+
57
59
  // Consumers that don't spread the snippet's trigger props still get linked
58
60
  // on the client: whatever they rendered first is the trigger.
59
61
  const tooltip = useEnhancer(
@@ -72,12 +74,16 @@
72
74
  onOpenChange: (next) => {
73
75
  open = next;
74
76
  onOpenChange?.(next);
77
+ syncTick += 1;
75
78
  },
76
79
  }),
77
80
  );
78
81
 
79
82
  $effect(() => {
80
- if (open != null) tooltip.api?.setOpen(open);
83
+ void syncTick;
84
+ if (open != null && tooltip.api && tooltip.api.open !== open) {
85
+ tooltip.api.setOpen(open, { silent: true });
86
+ }
81
87
  });
82
88
  </script>
83
89
 
@@ -88,7 +94,7 @@
88
94
  {@attach tooltip.attach}
89
95
  >
90
96
  {@render children?.(triggerProps)}
91
- <span id={tipId} role="tooltip" hidden
97
+ <span id={tipId} class="hl-tooltip" role="tooltip" hidden
92
98
  >{#if typeof content === 'function'}{@render content()}{:else}{content}{/if}</span
93
99
  >
94
100
  </span>
package/dist/index.d.ts CHANGED
@@ -20,14 +20,17 @@ export { default as Menu } from './components/Menu.svelte';
20
20
  export { default as MenuItem } from './components/MenuItem.svelte';
21
21
  export { default as MenuSubmenu } from './components/MenuSubmenu.svelte';
22
22
  export { default as Modal } from './components/Modal.svelte';
23
+ export { default as ModalTrigger } from './components/ModalTrigger.svelte';
23
24
  export { default as ModalHeader } from './components/ModalHeader.svelte';
24
25
  export { default as ModalBody } from './components/ModalBody.svelte';
25
26
  export { default as ModalFooter } from './components/ModalFooter.svelte';
26
27
  export { default as Drawer } from './components/Drawer.svelte';
28
+ export { default as DrawerTrigger } from './components/DrawerTrigger.svelte';
27
29
  export { default as DrawerHeader } from './components/DrawerHeader.svelte';
28
30
  export { default as DrawerBody } from './components/DrawerBody.svelte';
29
31
  export { default as DrawerFooter } from './components/DrawerFooter.svelte';
30
32
  export { default as Popover } from './components/Popover.svelte';
33
+ export { default as PopoverTrigger } from './components/PopoverTrigger.svelte';
31
34
  export { default as Tooltip } from './components/Tooltip.svelte';
32
35
  export { default as Breadcrumb } from './components/Breadcrumb.svelte';
33
36
  export { default as BreadcrumbItem } from './components/BreadcrumbItem.svelte';
package/dist/index.js CHANGED
@@ -24,14 +24,17 @@ export { default as MenuItem } from './components/MenuItem.svelte';
24
24
  export { default as MenuSubmenu } from './components/MenuSubmenu.svelte';
25
25
  // Overlays
26
26
  export { default as Modal } from './components/Modal.svelte';
27
+ export { default as ModalTrigger } from './components/ModalTrigger.svelte';
27
28
  export { default as ModalHeader } from './components/ModalHeader.svelte';
28
29
  export { default as ModalBody } from './components/ModalBody.svelte';
29
30
  export { default as ModalFooter } from './components/ModalFooter.svelte';
30
31
  export { default as Drawer } from './components/Drawer.svelte';
32
+ export { default as DrawerTrigger } from './components/DrawerTrigger.svelte';
31
33
  export { default as DrawerHeader } from './components/DrawerHeader.svelte';
32
34
  export { default as DrawerBody } from './components/DrawerBody.svelte';
33
35
  export { default as DrawerFooter } from './components/DrawerFooter.svelte';
34
36
  export { default as Popover } from './components/Popover.svelte';
37
+ export { default as PopoverTrigger } from './components/PopoverTrigger.svelte';
35
38
  export { default as Tooltip } from './components/Tooltip.svelte';
36
39
  // Breadcrumb
37
40
  export { default as Breadcrumb } from './components/Breadcrumb.svelte';
@@ -4,8 +4,9 @@ import type { EnhancerHandle } from '@hydrateless/enhancers';
4
4
  export interface UseEnhancer<Api> {
5
5
  /**
6
6
  * Attach to the element the enhancer should treat as its container:
7
- * `<div {@attach enhancer.attach}>`. Runs the enhancer when the element
8
- * mounts and destroys it when the element is removed or the options change.
7
+ * `<div {@attach enhancer.attach}>`. Runs the enhancer once when the element
8
+ * mounts, updates options in place via `handle.update()` when reactive
9
+ * options change, and destroys it when the element is removed.
9
10
  */
10
11
  readonly attach: Attachment<HTMLElement>;
11
12
  /** The enhanced root's imperative API, or `null` while nothing is attached. */
@@ -17,13 +18,13 @@ export interface UseEnhancer<Api> {
17
18
  * it is built on the same call, so custom wrappers behave exactly like the
18
19
  * shipped ones.
19
20
  *
20
- * `getOptions` is read inside the attachment, so any reactive state it touches
21
- * re-runs the enhancer (destroy, then enhance again with the fresh options).
22
- * Wrap values that should only seed the initial state, such as a bound
23
- * `value` passed as `defaultValue`, in `untrack` to keep them from retriggering
24
- * it. Callbacks are invoked later, outside the attachment, so reading props
25
- * inside them doesn't track. Options left `undefined` are dropped so the
26
- * enhancer's own defaults apply.
21
+ * The enhancer attaches once on mount and destroys on unmount. Reactive state
22
+ * read by `getOptions` triggers an in-place `handle.update()` instead of
23
+ * tearing down and recreating the enhancer, so open overlays and active state
24
+ * stay intact. Wrap values that should only seed initial state, such as a
25
+ * bound `value` passed as `defaultValue`, in `untrack`. Callbacks are invoked
26
+ * later, outside the effect, so reading props inside them doesn't track.
27
+ * Options left `undefined` are dropped so the enhancer's own defaults apply.
27
28
  *
28
29
  * ```svelte
29
30
  * <script lang="ts">
@@ -34,7 +35,7 @@ export interface UseEnhancer<Api> {
34
35
  * // tabs.api?.setValue('two');
35
36
  * </script>
36
37
  *
37
- * <div data-hl-tabs {@attach tabs.attach}>...</div>
38
+ * <div class="hl-tabs" data-hl-tabs {@attach tabs.attach}>...</div>
38
39
  * ```
39
40
  */
40
- export declare function useEnhancer<Options extends object, Api>(enhancer: (container: HTMLElement, options?: Partial<Options>) => EnhancerHandle<Api>, getOptions?: () => Partial<Options>): UseEnhancer<Api>;
41
+ export declare function useEnhancer<Options extends object, Api>(enhancer: (container: HTMLElement, options?: Partial<Options>) => EnhancerHandle<Api, Options>, getOptions?: () => Partial<Options>): UseEnhancer<Api>;
@@ -1,3 +1,4 @@
1
+ import { untrack } from 'svelte';
1
2
  /**
2
3
  * Drop `undefined` entries so an omitted component prop falls through to the
3
4
  * enhancer's default instead of overriding it with `undefined` when the two
@@ -17,13 +18,13 @@ function defined(options) {
17
18
  * it is built on the same call, so custom wrappers behave exactly like the
18
19
  * shipped ones.
19
20
  *
20
- * `getOptions` is read inside the attachment, so any reactive state it touches
21
- * re-runs the enhancer (destroy, then enhance again with the fresh options).
22
- * Wrap values that should only seed the initial state, such as a bound
23
- * `value` passed as `defaultValue`, in `untrack` to keep them from retriggering
24
- * it. Callbacks are invoked later, outside the attachment, so reading props
25
- * inside them doesn't track. Options left `undefined` are dropped so the
26
- * enhancer's own defaults apply.
21
+ * The enhancer attaches once on mount and destroys on unmount. Reactive state
22
+ * read by `getOptions` triggers an in-place `handle.update()` instead of
23
+ * tearing down and recreating the enhancer, so open overlays and active state
24
+ * stay intact. Wrap values that should only seed initial state, such as a
25
+ * bound `value` passed as `defaultValue`, in `untrack`. Callbacks are invoked
26
+ * later, outside the effect, so reading props inside them doesn't track.
27
+ * Options left `undefined` are dropped so the enhancer's own defaults apply.
27
28
  *
28
29
  * ```svelte
29
30
  * <script lang="ts">
@@ -34,21 +35,36 @@ function defined(options) {
34
35
  * // tabs.api?.setValue('two');
35
36
  * </script>
36
37
  *
37
- * <div data-hl-tabs {@attach tabs.attach}>...</div>
38
+ * <div class="hl-tabs" data-hl-tabs {@attach tabs.attach}>...</div>
38
39
  * ```
39
40
  */
40
41
  export function useEnhancer(enhancer, getOptions = () => ({})) {
41
42
  // `$state.raw` because the API object is opaque; proxying it would break
42
43
  // getters that close over the enhancer's private state.
43
44
  let api = $state.raw(null);
45
+ let handle = null;
46
+ let initialized = false;
44
47
  const attach = (node) => {
45
- const handle = enhancer(node, defined(getOptions()));
46
- api = handle.api;
48
+ const next = untrack(() => enhancer(node, defined(getOptions())));
49
+ handle = next;
50
+ api = next.api;
47
51
  return () => {
48
- handle.destroy();
49
- api = null;
52
+ next.destroy();
53
+ if (handle === next) {
54
+ handle = null;
55
+ api = null;
56
+ }
50
57
  };
51
58
  };
59
+ $effect(() => {
60
+ // Keep `undefined` entries: on update they revert an option to its default.
61
+ const next = getOptions();
62
+ if (!initialized) {
63
+ initialized = true;
64
+ return;
65
+ }
66
+ handle?.update(next);
67
+ });
52
68
  return {
53
69
  attach,
54
70
  get api() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydrateless/svelte",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Svelte 5 bindings for Hydrateless: rune-based components, a useEnhancer attachment, field wiring, and toasts.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "test": "vitest run"
33
33
  },
34
34
  "dependencies": {
35
- "@hydrateless/enhancers": "^0.10.1"
35
+ "@hydrateless/enhancers": "^0.11.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "svelte": ">=5.29"