@hydrateless/svelte 0.8.0 → 0.10.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.
Files changed (157) hide show
  1. package/README.md +173 -38
  2. package/dist/components/Accordion.svelte +29 -17
  3. package/dist/components/Accordion.svelte.d.ts +3 -0
  4. package/dist/components/AccordionItem.svelte +21 -12
  5. package/dist/components/AccordionItem.svelte.d.ts +6 -4
  6. package/dist/components/Alert.svelte +4 -0
  7. package/dist/components/Alert.svelte.d.ts +4 -0
  8. package/dist/components/Avatar.svelte +5 -0
  9. package/dist/components/Avatar.svelte.d.ts +5 -0
  10. package/dist/components/AvatarGroup.svelte +1 -0
  11. package/dist/components/AvatarGroup.svelte.d.ts +1 -0
  12. package/dist/components/Badge.svelte +4 -0
  13. package/dist/components/Badge.svelte.d.ts +4 -0
  14. package/dist/components/Breadcrumb.svelte +1 -0
  15. package/dist/components/Breadcrumb.svelte.d.ts +1 -0
  16. package/dist/components/BreadcrumbItem.svelte +3 -0
  17. package/dist/components/BreadcrumbItem.svelte.d.ts +3 -0
  18. package/dist/components/Button.svelte +7 -0
  19. package/dist/components/Button.svelte.d.ts +7 -0
  20. package/dist/components/Card.svelte +2 -0
  21. package/dist/components/Card.svelte.d.ts +2 -0
  22. package/dist/components/CardBody.svelte +1 -0
  23. package/dist/components/CardBody.svelte.d.ts +1 -0
  24. package/dist/components/CardDescription.svelte +1 -0
  25. package/dist/components/CardDescription.svelte.d.ts +1 -0
  26. package/dist/components/CardFooter.svelte +1 -0
  27. package/dist/components/CardFooter.svelte.d.ts +1 -0
  28. package/dist/components/CardHeader.svelte +1 -0
  29. package/dist/components/CardHeader.svelte.d.ts +1 -0
  30. package/dist/components/CardTitle.svelte +1 -0
  31. package/dist/components/CardTitle.svelte.d.ts +1 -0
  32. package/dist/components/Checkbox.svelte +24 -2
  33. package/dist/components/Checkbox.svelte.d.ts +2 -0
  34. package/dist/components/Combobox.svelte +37 -26
  35. package/dist/components/Combobox.svelte.d.ts +12 -3
  36. package/dist/components/ComboboxInput.svelte +21 -2
  37. package/dist/components/ComboboxInput.svelte.d.ts +1 -0
  38. package/dist/components/ComboboxList.svelte +4 -1
  39. package/dist/components/ComboboxList.svelte.d.ts +1 -0
  40. package/dist/components/ComboboxOption.svelte +6 -2
  41. package/dist/components/ComboboxOption.svelte.d.ts +4 -0
  42. package/dist/components/Command.svelte +36 -9
  43. package/dist/components/Command.svelte.d.ts +12 -5
  44. package/dist/components/CommandEmpty.svelte +1 -0
  45. package/dist/components/CommandEmpty.svelte.d.ts +1 -0
  46. package/dist/components/CommandGroup.svelte +1 -0
  47. package/dist/components/CommandGroup.svelte.d.ts +1 -0
  48. package/dist/components/CommandItem.svelte +2 -0
  49. package/dist/components/CommandItem.svelte.d.ts +2 -0
  50. package/dist/components/CommandList.svelte +1 -0
  51. package/dist/components/CommandList.svelte.d.ts +1 -0
  52. package/dist/components/Disclosure.svelte +29 -19
  53. package/dist/components/Disclosure.svelte.d.ts +6 -1
  54. package/dist/components/Drawer.svelte +26 -20
  55. package/dist/components/Drawer.svelte.d.ts +6 -1
  56. package/dist/components/DrawerBody.svelte +1 -0
  57. package/dist/components/DrawerBody.svelte.d.ts +1 -0
  58. package/dist/components/DrawerFooter.svelte +1 -0
  59. package/dist/components/DrawerFooter.svelte.d.ts +1 -0
  60. package/dist/components/DrawerHeader.svelte +1 -0
  61. package/dist/components/DrawerHeader.svelte.d.ts +1 -0
  62. package/dist/components/Dropdown.svelte +48 -24
  63. package/dist/components/Dropdown.svelte.d.ts +13 -2
  64. package/dist/components/DropdownGroup.svelte +19 -0
  65. package/dist/components/DropdownGroup.svelte.d.ts +11 -0
  66. package/dist/components/DropdownItem.svelte +28 -4
  67. package/dist/components/DropdownItem.svelte.d.ts +11 -2
  68. package/dist/components/DropdownMenu.svelte +14 -2
  69. package/dist/components/DropdownMenu.svelte.d.ts +1 -0
  70. package/dist/components/DropdownSeparator.svelte +3 -2
  71. package/dist/components/DropdownTrigger.svelte +14 -2
  72. package/dist/components/DropdownTrigger.svelte.d.ts +1 -0
  73. package/dist/components/Field.svelte +42 -3
  74. package/dist/components/Field.svelte.d.ts +16 -0
  75. package/dist/components/FieldError.svelte +4 -3
  76. package/dist/components/FieldError.svelte.d.ts +1 -0
  77. package/dist/components/FieldHelp.svelte +4 -3
  78. package/dist/components/FieldHelp.svelte.d.ts +1 -0
  79. package/dist/components/FieldLabel.svelte +4 -3
  80. package/dist/components/FieldLabel.svelte.d.ts +1 -0
  81. package/dist/components/Fieldset.svelte +2 -0
  82. package/dist/components/Fieldset.svelte.d.ts +2 -0
  83. package/dist/components/Input.svelte +22 -6
  84. package/dist/components/Input.svelte.d.ts +3 -0
  85. package/dist/components/Kbd.svelte +1 -0
  86. package/dist/components/Kbd.svelte.d.ts +1 -0
  87. package/dist/components/Menu.svelte +36 -23
  88. package/dist/components/Menu.svelte.d.ts +18 -5
  89. package/dist/components/MenuItem.svelte +46 -18
  90. package/dist/components/MenuItem.svelte.d.ts +10 -7
  91. package/dist/components/MenuSubmenu.svelte +30 -0
  92. package/dist/components/MenuSubmenu.svelte.d.ts +17 -0
  93. package/dist/components/Modal.svelte +17 -18
  94. package/dist/components/Modal.svelte.d.ts +4 -0
  95. package/dist/components/ModalBody.svelte +1 -0
  96. package/dist/components/ModalBody.svelte.d.ts +1 -0
  97. package/dist/components/ModalFooter.svelte +1 -0
  98. package/dist/components/ModalFooter.svelte.d.ts +1 -0
  99. package/dist/components/ModalHeader.svelte +1 -0
  100. package/dist/components/ModalHeader.svelte.d.ts +1 -0
  101. package/dist/components/Pagination.svelte +5 -0
  102. package/dist/components/Pagination.svelte.d.ts +5 -0
  103. package/dist/components/Popover.svelte +37 -20
  104. package/dist/components/Popover.svelte.d.ts +12 -2
  105. package/dist/components/Progress.svelte +4 -0
  106. package/dist/components/Progress.svelte.d.ts +4 -0
  107. package/dist/components/Radio.svelte +2 -0
  108. package/dist/components/Radio.svelte.d.ts +2 -0
  109. package/dist/components/RadioGroup.svelte +34 -4
  110. package/dist/components/RadioGroup.svelte.d.ts +10 -1
  111. package/dist/components/SegmentedControl.svelte +25 -10
  112. package/dist/components/SegmentedControl.svelte.d.ts +11 -3
  113. package/dist/components/Select.svelte +16 -5
  114. package/dist/components/Select.svelte.d.ts +4 -0
  115. package/dist/components/Separator.svelte +2 -0
  116. package/dist/components/Separator.svelte.d.ts +2 -0
  117. package/dist/components/Skeleton.svelte +6 -3
  118. package/dist/components/Skeleton.svelte.d.ts +4 -1
  119. package/dist/components/SkipLink.svelte +1 -0
  120. package/dist/components/SkipLink.svelte.d.ts +1 -0
  121. package/dist/components/Slider.svelte +23 -2
  122. package/dist/components/Slider.svelte.d.ts +1 -0
  123. package/dist/components/Spinner.svelte +2 -0
  124. package/dist/components/Spinner.svelte.d.ts +2 -0
  125. package/dist/components/Switch.svelte +25 -2
  126. package/dist/components/Switch.svelte.d.ts +2 -0
  127. package/dist/components/Tab.svelte +20 -3
  128. package/dist/components/Tab.svelte.d.ts +2 -1
  129. package/dist/components/TabList.svelte +1 -0
  130. package/dist/components/TabList.svelte.d.ts +1 -0
  131. package/dist/components/TabPanel.svelte +12 -2
  132. package/dist/components/TabPanel.svelte.d.ts +2 -1
  133. package/dist/components/Table.svelte +30 -0
  134. package/dist/components/Table.svelte.d.ts +17 -0
  135. package/dist/components/Tabs.svelte +38 -19
  136. package/dist/components/Tabs.svelte.d.ts +6 -1
  137. package/dist/components/Textarea.svelte +26 -6
  138. package/dist/components/Textarea.svelte.d.ts +5 -0
  139. package/dist/components/ToastRegion.svelte +18 -2
  140. package/dist/components/ToastRegion.svelte.d.ts +8 -1
  141. package/dist/components/Toc.svelte +19 -8
  142. package/dist/components/Toc.svelte.d.ts +6 -0
  143. package/dist/components/Tooltip.svelte +79 -22
  144. package/dist/components/Tooltip.svelte.d.ts +31 -9
  145. package/dist/context.d.ts +99 -8
  146. package/dist/context.js +60 -11
  147. package/dist/index.d.ts +8 -4
  148. package/dist/index.js +6 -4
  149. package/dist/registry.svelte.d.ts +29 -0
  150. package/dist/registry.svelte.js +44 -0
  151. package/dist/toast.d.ts +12 -7
  152. package/dist/toast.js +23 -11
  153. package/dist/useEnhancer.svelte.d.ts +40 -0
  154. package/dist/useEnhancer.svelte.js +58 -0
  155. package/package.json +4 -4
  156. package/dist/actions.d.ts +0 -25
  157. package/dist/actions.js +0 -31
@@ -0,0 +1,30 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLTableAttributes } from 'svelte/elements';
4
+
5
+ interface Props extends Omit<HTMLTableAttributes, 'align'> {
6
+ /** Zebra-stripe the body rows. */
7
+ striped?: boolean;
8
+ /** Highlight a body row under the pointer. */
9
+ hover?: boolean;
10
+ /** Default text alignment of cells (logical, RTL-aware). */
11
+ align?: 'start' | 'center' | 'end';
12
+ /** Cell padding scale. */
13
+ size?: 'sm' | 'md' | 'lg';
14
+ /** `<thead>`, `<tbody>`, `<tfoot>`, and `<caption>` as usual. */
15
+ children?: Snippet;
16
+ }
17
+
18
+ let { striped, hover, align, size, class: klass, children, ...rest }: Props = $props();
19
+ </script>
20
+
21
+ <table
22
+ {...rest}
23
+ class={['hl-table', klass]}
24
+ data-hl-striped={striped || undefined}
25
+ data-hl-hover={hover || undefined}
26
+ data-hl-align={align}
27
+ data-hl-size={size}
28
+ >
29
+ {@render children?.()}
30
+ </table>
@@ -0,0 +1,17 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLTableAttributes } from 'svelte/elements';
3
+ interface Props extends Omit<HTMLTableAttributes, 'align'> {
4
+ /** Zebra-stripe the body rows. */
5
+ striped?: boolean;
6
+ /** Highlight a body row under the pointer. */
7
+ hover?: boolean;
8
+ /** Default text alignment of cells (logical, RTL-aware). */
9
+ align?: 'start' | 'center' | 'end';
10
+ /** Cell padding scale. */
11
+ size?: 'sm' | 'md' | 'lg';
12
+ /** `<thead>`, `<tbody>`, `<tfoot>`, and `<caption>` as usual. */
13
+ children?: Snippet;
14
+ }
15
+ declare const Table: import("svelte").Component<Props, {}, "">;
16
+ type Table = ReturnType<typeof Table>;
17
+ export default Table;
@@ -1,16 +1,24 @@
1
1
  <script lang="ts">
2
- import { enhanceTabs, type EnhanceTabsOptions, type TabsApi } from '@hydrateless/enhancers';
2
+ import { enhanceTabs, type EnhanceTabsOptions } 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 { setTabsContext } from '../context.js';
7
+ import { createRegistry } from '../registry.svelte.js';
8
+ import { useEnhancer } from '../useEnhancer.svelte.js';
6
9
 
7
10
  interface Props extends HTMLAttributes<HTMLDivElement> {
11
+ /** `manual` (default): arrows move focus, Enter/Space selects. `automatic`: arrows select. */
8
12
  activation?: EnhanceTabsOptions['activation'];
13
+ /** Layout of the tab list; also picks the arrow keys used. */
9
14
  orientation?: EnhanceTabsOptions['orientation'];
10
15
  /** Selected tab value; two-way bindable (`bind:value`). */
11
16
  value?: string;
12
- /** Initial value for uncontrolled usage. */
17
+ /** Initially selected tab for uncontrolled usage. Defaults to the first tab. */
13
18
  defaultValue?: string;
19
+ /** Called with the new tab value after every selection change. */
20
+ onValueChange?: (value: string) => void;
21
+ /** A `<TabList>` followed by one `<TabPanel>` per tab. */
14
22
  children?: Snippet;
15
23
  }
16
24
 
@@ -19,32 +27,43 @@
19
27
  orientation,
20
28
  value = $bindable(),
21
29
  defaultValue,
30
+ onValueChange,
22
31
  children,
23
32
  ...rest
24
33
  }: Props = $props();
25
- let host = $state<HTMLDivElement>();
26
- let api = $state<TabsApi | null>(null);
34
+ // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
35
+ if (value === undefined) value = defaultValue;
27
36
 
28
- $effect(() => {
29
- if (!host) return;
30
- const handle = enhanceTabs(host, {
31
- activation,
32
- orientation,
33
- defaultValue: untrack(() => value ?? defaultValue),
34
- onValueChange: (next) => (value = next),
35
- });
36
- api = handle.api;
37
- return () => {
38
- handle.destroy();
39
- api = null;
40
- };
37
+ // Tabs and panels register in document order so `aria-selected`/`hidden`
38
+ // render on the server and the enhancer finds them already in agreement.
39
+ // Registries keep indexes live when an `{#each}` adds or removes tabs.
40
+ const tabs = createRegistry<() => string | undefined>();
41
+ const panels = createRegistry();
42
+ const tabValues = $derived(tabs.entries.map((get, index) => get() ?? String(index)));
43
+ setTabsContext({
44
+ get value() {
45
+ return value ?? tabValues[0];
46
+ },
47
+ registerTab: (getValue) => tabs.register(getValue),
48
+ registerPanel: () => panels.register(),
49
+ tabValueAt: (index) => tabValues[index],
41
50
  });
42
51
 
52
+ const enhanced = useEnhancer(enhanceTabs, () => ({
53
+ activation,
54
+ orientation,
55
+ defaultValue: untrack(() => value),
56
+ onValueChange: (next) => {
57
+ value = next;
58
+ onValueChange?.(next);
59
+ },
60
+ }));
61
+
43
62
  $effect(() => {
44
- if (value != null) api?.setValue(value);
63
+ if (value != null) enhanced.api?.setValue(value);
45
64
  });
46
65
  </script>
47
66
 
48
- <div {...rest} data-hl-tabs bind:this={host}>
67
+ <div {...rest} data-hl-tabs data-hl-orientation={orientation} {@attach enhanced.attach}>
49
68
  {@render children?.()}
50
69
  </div>
@@ -2,12 +2,17 @@ import { type EnhanceTabsOptions } from '@hydrateless/enhancers';
2
2
  import type { Snippet } from 'svelte';
3
3
  import type { HTMLAttributes } from 'svelte/elements';
4
4
  interface Props extends HTMLAttributes<HTMLDivElement> {
5
+ /** `manual` (default): arrows move focus, Enter/Space selects. `automatic`: arrows select. */
5
6
  activation?: EnhanceTabsOptions['activation'];
7
+ /** Layout of the tab list; also picks the arrow keys used. */
6
8
  orientation?: EnhanceTabsOptions['orientation'];
7
9
  /** Selected tab value; two-way bindable (`bind:value`). */
8
10
  value?: string;
9
- /** Initial value for uncontrolled usage. */
11
+ /** Initially selected tab for uncontrolled usage. Defaults to the first tab. */
10
12
  defaultValue?: string;
13
+ /** Called with the new tab value after every selection change. */
14
+ onValueChange?: (value: string) => void;
15
+ /** A `<TabList>` followed by one `<TabPanel>` per tab. */
11
16
  children?: Snippet;
12
17
  }
13
18
  declare const Tabs: import("svelte").Component<Props, {}, "value">;
@@ -1,23 +1,43 @@
1
1
  <script lang="ts">
2
2
  import type { HTMLTextareaAttributes } from 'svelte/elements';
3
- import { fieldBindings } from '../context.js';
3
+ import { useField } from '../context.js';
4
4
 
5
5
  interface Props extends HTMLTextareaAttributes {
6
+ /** Current value; two-way bindable (`bind:value`). */
6
7
  value?: string;
8
+ /** Control size. */
7
9
  size?: 'sm' | 'md' | 'lg';
10
+ /** Mark the control invalid; also inherited from an enclosing `<Field invalid>`. */
8
11
  invalid?: boolean;
12
+ /** Grow with the content (`field-sizing: content`). */
13
+ autosize?: boolean;
9
14
  }
10
15
 
11
- let { value = $bindable(), size, invalid = false, class: klass, ...rest }: Props = $props();
12
- const field = fieldBindings();
16
+ let {
17
+ value = $bindable(),
18
+ size,
19
+ invalid = false,
20
+ autosize = false,
21
+ id,
22
+ required,
23
+ 'aria-describedby': describedBy,
24
+ class: klass,
25
+ ...rest
26
+ }: Props = $props();
27
+ // Optional: wires id/aria-describedby/aria-invalid/required when inside a <Field>.
28
+ const field = useField();
29
+ const isInvalid = $derived(invalid || Boolean(field?.invalid));
13
30
  </script>
14
31
 
15
32
  <textarea
16
- {...field}
17
33
  {...rest}
34
+ id={id ?? field?.id}
35
+ required={required ?? (field?.required || undefined)}
36
+ aria-describedby={describedBy ?? field?.describedBy}
18
37
  bind:value
19
38
  class={['hl-textarea', klass]}
20
39
  data-hl-size={size}
21
- data-hl-invalid={invalid || undefined}
22
- aria-invalid={invalid || undefined}
40
+ data-hl-autosize={autosize || undefined}
41
+ data-hl-invalid={isInvalid || undefined}
42
+ aria-invalid={isInvalid || undefined}
23
43
  ></textarea>
@@ -1,8 +1,13 @@
1
1
  import type { HTMLTextareaAttributes } from 'svelte/elements';
2
2
  interface Props extends HTMLTextareaAttributes {
3
+ /** Current value; two-way bindable (`bind:value`). */
3
4
  value?: string;
5
+ /** Control size. */
4
6
  size?: 'sm' | 'md' | 'lg';
7
+ /** Mark the control invalid; also inherited from an enclosing `<Field invalid>`. */
5
8
  invalid?: boolean;
9
+ /** Grow with the content (`field-sizing: content`). */
10
+ autosize?: boolean;
6
11
  }
7
12
  declare const Textarea: import("svelte").Component<Props, {}, "value">;
8
13
  type Textarea = ReturnType<typeof Textarea>;
@@ -1,7 +1,23 @@
1
1
  <script lang="ts">
2
+ import { enhanceToast, type EnhanceToastOptions } from '@hydrateless/enhancers';
2
3
  import type { HTMLAttributes } from 'svelte/elements';
4
+ import { useEnhancer } from '../useEnhancer.svelte.js';
3
5
 
4
- let { ...rest }: HTMLAttributes<HTMLDivElement> = $props();
6
+ interface Props extends HTMLAttributes<HTMLDivElement> {
7
+ /** Default auto-dismiss duration in ms for toasts shown without one. */
8
+ duration?: number;
9
+ /** Called after a toast appears (`open: true`) or is dismissed (`open: false`). */
10
+ onOpenChange?: EnhanceToastOptions['onOpenChange'];
11
+ }
12
+
13
+ let { duration, onOpenChange, ...rest }: Props = $props();
14
+
15
+ // Enhanced on mount so `useToast()` adopts this region (and its defaults)
16
+ // instead of appending its own to <body>.
17
+ const toast = useEnhancer(enhanceToast, () => ({
18
+ duration,
19
+ onOpenChange: (open, el) => onOpenChange?.(open, el),
20
+ }));
5
21
  </script>
6
22
 
7
- <div {...rest} data-hl-toast-region></div>
23
+ <div {...rest} data-hl-toast-region {@attach toast.attach}></div>
@@ -1,4 +1,11 @@
1
+ import { type EnhanceToastOptions } from '@hydrateless/enhancers';
1
2
  import type { HTMLAttributes } from 'svelte/elements';
2
- declare const ToastRegion: import("svelte").Component<HTMLAttributes<HTMLDivElement>, {}, "">;
3
+ interface Props extends HTMLAttributes<HTMLDivElement> {
4
+ /** Default auto-dismiss duration in ms for toasts shown without one. */
5
+ duration?: number;
6
+ /** Called after a toast appears (`open: true`) or is dismissed (`open: false`). */
7
+ onOpenChange?: EnhanceToastOptions['onOpenChange'];
8
+ }
9
+ declare const ToastRegion: import("svelte").Component<Props, {}, "">;
3
10
  type ToastRegion = ReturnType<typeof ToastRegion>;
4
11
  export default ToastRegion;
@@ -1,20 +1,31 @@
1
1
  <script lang="ts">
2
- import { enhanceToc } from '@hydrateless/enhancers';
2
+ import { enhanceToc, type EnhanceTocOptions } from '@hydrateless/enhancers';
3
+ import type { Snippet } from 'svelte';
3
4
  import type { HTMLAttributes } from 'svelte/elements';
5
+ import { useEnhancer } from '../useEnhancer.svelte.js';
4
6
 
5
7
  interface Props extends HTMLAttributes<HTMLElement> {
8
+ /** Selector for the region whose headings populate the list. Defaults to `main, article`. */
6
9
  contentSelector?: string;
10
+ /** Selector for which headings to include. Defaults to `h2,h3`. */
7
11
  headings?: string;
12
+ /** Highlight the entry for the heading currently in view. Defaults to `true`. */
8
13
  scrollSpy?: boolean;
14
+ /** Placeholder shown until the list is built (and restored if the Toc is destroyed). */
15
+ children?: Snippet;
9
16
  }
10
17
 
11
- let { contentSelector, headings, scrollSpy, ...rest }: Props = $props();
12
- let host = $state<HTMLElement>();
18
+ let { contentSelector, headings, scrollSpy, children, ...rest }: Props = $props();
13
19
 
14
- $effect(() => {
15
- if (!host) return;
16
- return enhanceToc(host.ownerDocument, { contentSelector, headings, scrollSpy }).destroy;
17
- });
20
+ // The headings live outside the nav, so the enhancer scans the document and
21
+ // finds this nav as the `[data-hl-toc]` root within it.
22
+ const toc = useEnhancer(
23
+ (node: HTMLElement, options?: Partial<EnhanceTocOptions>) =>
24
+ enhanceToc(node.ownerDocument, options),
25
+ () => ({ contentSelector, headings, scrollSpy }),
26
+ );
18
27
  </script>
19
28
 
20
- <nav {...rest} data-hl-toc bind:this={host}></nav>
29
+ <nav {...rest} data-hl-toc {@attach toc.attach}>
30
+ {@render children?.()}
31
+ </nav>
@@ -1,8 +1,14 @@
1
+ import type { Snippet } from 'svelte';
1
2
  import type { HTMLAttributes } from 'svelte/elements';
2
3
  interface Props extends HTMLAttributes<HTMLElement> {
4
+ /** Selector for the region whose headings populate the list. Defaults to `main, article`. */
3
5
  contentSelector?: string;
6
+ /** Selector for which headings to include. Defaults to `h2,h3`. */
4
7
  headings?: string;
8
+ /** Highlight the entry for the heading currently in view. Defaults to `true`. */
5
9
  scrollSpy?: boolean;
10
+ /** Placeholder shown until the list is built (and restored if the Toc is destroyed). */
11
+ children?: Snippet;
6
12
  }
7
13
  declare const Toc: import("svelte").Component<Props, {}, "">;
8
14
  type Toc = ReturnType<typeof Toc>;
@@ -1,37 +1,94 @@
1
1
  <script lang="ts">
2
- import { enhanceTooltip } from '@hydrateless/enhancers';
2
+ import { enhanceTooltip, type EnhanceTooltipOptions } from '@hydrateless/enhancers';
3
3
  import type { Snippet } from 'svelte';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+ import type { TooltipTriggerProps } from '../context.js';
6
+ import { useEnhancer } from '../useEnhancer.svelte.js';
4
7
 
5
- interface Props {
6
- /** The hint text shown on hover/focus. */
7
- label?: string;
8
- /** Richer hint content; overrides `label` when provided. */
9
- tip?: Snippet;
10
- id?: string;
11
- /** A single focusable element that triggers the tooltip. */
12
- children?: Snippet;
8
+ interface Props extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
9
+ /** The hint shown on hover/focus: plain text or a snippet for rich content. */
10
+ content?: string | Snippet;
11
+ /** Preferred placement relative to the trigger. Defaults to `top`. */
12
+ placement?: EnhanceTooltipOptions['placement'];
13
+ /** Delay in ms before showing on hover. Focus shows immediately. */
14
+ showDelay?: number;
15
+ /** Grace period in ms before hiding, so the pointer can reach the tip. */
16
+ hideDelay?: number;
17
+ /** Whether the tip is shown; two-way bindable (`bind:open`). */
18
+ open?: boolean;
19
+ /** Called after the tip shows or hides. */
20
+ onOpenChange?: (open: boolean) => void;
21
+ /**
22
+ * A single focusable element that triggers the tooltip. The snippet
23
+ * receives the trigger attributes; spread them so server-rendered markup
24
+ * links the trigger to the tip before any script runs:
25
+ *
26
+ * ```svelte
27
+ * <Tooltip content="Save">
28
+ * {#snippet children(trigger)}<Button {...trigger}>Save</Button>{/snippet}
29
+ * </Tooltip>
30
+ * ```
31
+ *
32
+ * Without the spread, the first child is linked on the client instead.
33
+ */
34
+ children?: Snippet<[TooltipTriggerProps]>;
13
35
  }
14
36
 
15
- let { label, tip, id, children }: Props = $props();
37
+ let {
38
+ content,
39
+ placement,
40
+ showDelay,
41
+ hideDelay,
42
+ open = $bindable(),
43
+ onOpenChange,
44
+ class: klass,
45
+ style,
46
+ children,
47
+ ...rest
48
+ }: Props = $props();
16
49
  // SSR-safe: $props.id() is stable across server and client renders.
17
50
  const generatedId = $props.id();
18
- const tipId = $derived(id ?? `hl-tip-${generatedId}`);
19
- let host = $state<HTMLSpanElement>();
51
+ const tipId = `hl-tip-${generatedId}`;
52
+ const triggerProps: TooltipTriggerProps = {
53
+ 'data-hl-tooltip': tipId,
54
+ 'aria-describedby': tipId,
55
+ };
56
+
57
+ // Consumers that don't spread the snippet's trigger props still get linked
58
+ // on the client: whatever they rendered first is the trigger.
59
+ const tooltip = useEnhancer(
60
+ (node: HTMLElement, options?: Partial<EnhanceTooltipOptions>) => {
61
+ const trigger = node.querySelector<HTMLElement>(':scope > :first-child');
62
+ if (trigger && !trigger.hasAttribute('data-hl-tooltip')) {
63
+ trigger.setAttribute('data-hl-tooltip', tipId);
64
+ trigger.setAttribute('aria-describedby', tipId);
65
+ }
66
+ return enhanceTooltip(node, options);
67
+ },
68
+ () => ({
69
+ placement,
70
+ showDelay,
71
+ hideDelay,
72
+ onOpenChange: (next) => {
73
+ open = next;
74
+ onOpenChange?.(next);
75
+ },
76
+ }),
77
+ );
20
78
 
21
79
  $effect(() => {
22
- if (!host) return;
23
- const trigger = host.querySelector<HTMLElement>(':scope > :first-child');
24
- if (trigger) {
25
- trigger.setAttribute('data-hl-tooltip', tipId);
26
- trigger.setAttribute('aria-describedby', tipId);
27
- }
28
- return enhanceTooltip(host).destroy;
80
+ if (open != null) tooltip.api?.setOpen(open);
29
81
  });
30
82
  </script>
31
83
 
32
- <span bind:this={host} style="position:relative;display:inline-block">
33
- {@render children?.()}
84
+ <span
85
+ {...rest}
86
+ class={['hl-tooltip-anchor', klass]}
87
+ style={['position:relative;display:inline-block', style].filter(Boolean).join(';')}
88
+ {@attach tooltip.attach}
89
+ >
90
+ {@render children?.(triggerProps)}
34
91
  <span id={tipId} role="tooltip" hidden
35
- >{#if tip}{@render tip()}{:else}{label}{/if}</span
92
+ >{#if typeof content === 'function'}{@render content()}{:else}{content}{/if}</span
36
93
  >
37
94
  </span>
@@ -1,13 +1,35 @@
1
+ import { type EnhanceTooltipOptions } from '@hydrateless/enhancers';
1
2
  import type { Snippet } from 'svelte';
2
- interface Props {
3
- /** The hint text shown on hover/focus. */
4
- label?: string;
5
- /** Richer hint content; overrides `label` when provided. */
6
- tip?: Snippet;
7
- id?: string;
8
- /** A single focusable element that triggers the tooltip. */
9
- children?: Snippet;
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import type { TooltipTriggerProps } from '../context.js';
5
+ interface Props extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
6
+ /** The hint shown on hover/focus: plain text or a snippet for rich content. */
7
+ content?: string | Snippet;
8
+ /** Preferred placement relative to the trigger. Defaults to `top`. */
9
+ placement?: EnhanceTooltipOptions['placement'];
10
+ /** Delay in ms before showing on hover. Focus shows immediately. */
11
+ showDelay?: number;
12
+ /** Grace period in ms before hiding, so the pointer can reach the tip. */
13
+ hideDelay?: number;
14
+ /** Whether the tip is shown; two-way bindable (`bind:open`). */
15
+ open?: boolean;
16
+ /** Called after the tip shows or hides. */
17
+ onOpenChange?: (open: boolean) => void;
18
+ /**
19
+ * A single focusable element that triggers the tooltip. The snippet
20
+ * receives the trigger attributes; spread them so server-rendered markup
21
+ * links the trigger to the tip before any script runs:
22
+ *
23
+ * ```svelte
24
+ * <Tooltip content="Save">
25
+ * {#snippet children(trigger)}<Button {...trigger}>Save</Button>{/snippet}
26
+ * </Tooltip>
27
+ * ```
28
+ *
29
+ * Without the spread, the first child is linked on the client instead.
30
+ */
31
+ children?: Snippet<[TooltipTriggerProps]>;
10
32
  }
11
- declare const Tooltip: import("svelte").Component<Props, {}, "">;
33
+ declare const Tooltip: import("svelte").Component<Props, {}, "open">;
12
34
  type Tooltip = ReturnType<typeof Tooltip>;
13
35
  export default Tooltip;
package/dist/context.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- /** Shared field state a Field provides to its controls (ids and validity flags). */
1
+ import type { Registration } from './registry.svelte.js';
2
+ /**
3
+ * What a Field shares with its descendants. The getters stay live, so controls
4
+ * re-render when `invalid`/`required` change.
5
+ * @internal
6
+ */
2
7
  export interface FieldContext {
3
8
  readonly id: string;
4
9
  readonly helpId: string;
@@ -6,19 +11,105 @@ export interface FieldContext {
6
11
  readonly invalid: boolean;
7
12
  readonly required: boolean;
8
13
  }
9
- /** Publish {@link FieldContext} to the descendant controls of a Field. */
14
+ /** Publish a {@link FieldContext}; called by `<Field>` only. @internal */
10
15
  export declare function setFieldContext(ctx: FieldContext): void;
11
- /** Read the nearest {@link FieldContext}, or `undefined` outside a Field. */
16
+ /** Read the nearest {@link FieldContext}, or `undefined` outside a Field. @internal */
12
17
  export declare function getFieldContext(): FieldContext | undefined;
13
- /** Returns attributes (`id`, `aria-describedby`, `aria-invalid`) for a field control. */
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). */
18
+ /** Attributes a custom control should render to join the enclosing Field. */
19
+ export interface FieldBindings {
20
+ /** The control's `id`; the Field's label points at it. */
21
+ readonly id: string;
22
+ /** Space-separated ids for `aria-describedby` (help text, plus the error when invalid). */
23
+ readonly describedBy: string | undefined;
24
+ /** Whether the Field is currently invalid; render as `aria-invalid`. */
25
+ readonly invalid: boolean;
26
+ /** Whether the Field is required; render as `required`. */
27
+ readonly required: boolean;
28
+ }
29
+ /**
30
+ * Wire a custom control into the enclosing `<Field>`. Returns `null` outside a
31
+ * Field, so controls can call it unconditionally. Must be called during
32
+ * component initialization, like any context read. The returned object's
33
+ * properties are getters, so they stay reactive in the template:
34
+ *
35
+ * ```svelte
36
+ * <script lang="ts">
37
+ * const field = useField();
38
+ * </script>
39
+ *
40
+ * <input id={field?.id} aria-describedby={field?.describedBy} aria-invalid={field?.invalid || undefined} />
41
+ * ```
42
+ */
43
+ export declare function useField(): FieldBindings | null;
44
+ /**
45
+ * Attributes a `<Tooltip>` hands to its `children` snippet. Spread them onto
46
+ * the trigger element so server-rendered markup already links it to the tip.
47
+ */
48
+ export interface TooltipTriggerProps {
49
+ /** Marks the trigger and names the tip it describes. */
50
+ 'data-hl-tooltip': string;
51
+ /** Points at the tip so assistive tech announces it. */
52
+ 'aria-describedby': string;
53
+ }
54
+ /** Shared state a RadioGroup provides to its radios (name, selected value, and a setter). @internal */
16
55
  export interface RadioGroupContext {
17
56
  readonly name: string | undefined;
18
57
  readonly value: string | undefined;
19
58
  select: (value: string) => void;
20
59
  }
21
- /** Publish {@link RadioGroupContext} to the descendant radios of a group. */
60
+ /** Publish a {@link RadioGroupContext}; called by `<RadioGroup>` only. @internal */
22
61
  export declare function setRadioGroupContext(ctx: RadioGroupContext): void;
23
- /** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. */
62
+ /** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. @internal */
24
63
  export declare function getRadioGroupContext(): RadioGroupContext | undefined;
64
+ /**
65
+ * Ids a Dropdown generates so the trigger's `popovertarget` and the menu's
66
+ * `id` agree in server-rendered markup, before any script runs, plus the live
67
+ * open state so the trigger's `aria-expanded` renders correctly too.
68
+ * @internal
69
+ */
70
+ export interface DropdownContext {
71
+ readonly menuId: string;
72
+ readonly triggerId: string;
73
+ readonly open: boolean;
74
+ }
75
+ /** Publish a {@link DropdownContext}; called by `<Dropdown>` only. @internal */
76
+ export declare function setDropdownContext(ctx: DropdownContext): void;
77
+ /** Read the nearest {@link DropdownContext}, or `undefined` outside a Dropdown. @internal */
78
+ export declare function getDropdownContext(): DropdownContext | undefined;
79
+ /**
80
+ * Selection state a Tabs root shares with its tabs and panels so `aria-selected`,
81
+ * `tabindex`, and `hidden` can be rendered on the server. Tabs and panels
82
+ * register in document order; a panel pairs with the tab at the same index.
83
+ * Indexes are live, so an `{#each}` that adds or removes tabs renumbers the
84
+ * rest; children unregister on destroy.
85
+ * @internal
86
+ */
87
+ export interface TabsContext {
88
+ /** The selected tab's value (falls back to the first registered tab). */
89
+ readonly value: string | undefined;
90
+ /** Register a tab by a getter for its value, which defaults to its index. */
91
+ registerTab: (value: () => string | undefined) => Registration;
92
+ /** Register a panel. */
93
+ registerPanel: () => Registration;
94
+ /** Value of the tab registered at `index`. */
95
+ tabValueAt: (index: number) => string | undefined;
96
+ }
97
+ /** Publish a {@link TabsContext}; called by `<Tabs>` only. @internal */
98
+ export declare function setTabsContext(ctx: TabsContext): void;
99
+ /** Read the nearest {@link TabsContext}, or `undefined` outside Tabs. @internal */
100
+ export declare function getTabsContext(): TabsContext | undefined;
101
+ /**
102
+ * Open-item state an Accordion shares with its items so each `<details>` can
103
+ * render its `open` attribute on the server.
104
+ * @internal
105
+ */
106
+ export interface AccordionContext {
107
+ /** Values of the open items. */
108
+ readonly value: readonly string[];
109
+ /** Register an item; its live index is its default value. */
110
+ registerItem: () => Registration;
111
+ }
112
+ /** Publish an {@link AccordionContext}; called by `<Accordion>` only. @internal */
113
+ export declare function setAccordionContext(ctx: AccordionContext): void;
114
+ /** Read the nearest {@link AccordionContext}, or `undefined` outside an Accordion. @internal */
115
+ export declare function getAccordionContext(): AccordionContext | undefined;