@hydrateless/svelte 0.6.0 → 0.7.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
@@ -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. in your root layout):
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 — no setup required:
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` — single-open behavior on a `[data-hl-accordion]` element. */
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` — groups `[data-hl-disclosure]` elements within the node. */
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` — ARIA + keyboard navigation on a `[data-hl-tabs]` element. */
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` — menu pattern on a `[data-hl-dropdown]` element. */
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` — wires modal openers/closers + focus trap within the node. */
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` — wires drawer openers/closers within the node. */
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` — wires popover openers/closers within the node. */
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` — wires `[data-hl-tooltip]` triggers within the node. */
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` — builds a table of contents from the surrounding document. */
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` — menubar/navigation pattern on a `[data-hl-menu]` element. */
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` — editable combobox on a `[data-hl-combobox]` element. */
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` — command palette on a `[data-hl-command]` element. */
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` — single-open behavior on a `[data-hl-accordion]` element. */
8
+ /** `use:accordion`: single-open behavior on a `[data-hl-accordion]` element. */
9
9
  export const accordion = actionFor((node) => enhanceAccordion(node));
10
- /** `use:disclosure` — groups `[data-hl-disclosure]` elements within the node. */
10
+ /** `use:disclosure`: groups `[data-hl-disclosure]` elements within the node. */
11
11
  export const disclosure = actionFor((node) => enhanceDisclosure(node));
12
- /** `use:tabs` — ARIA + keyboard navigation on a `[data-hl-tabs]` element. */
12
+ /** `use:tabs`: ARIA + keyboard navigation on a `[data-hl-tabs]` element. */
13
13
  export const tabs = actionFor((node) => enhanceTabs(node));
14
- /** `use:dropdown` — menu pattern on a `[data-hl-dropdown]` element. */
14
+ /** `use:dropdown`: menu pattern on a `[data-hl-dropdown]` element. */
15
15
  export const dropdown = actionFor((node) => enhanceDropdown(node));
16
- /** `use:modal` — wires modal openers/closers + focus trap within the node. */
16
+ /** `use:modal`: wires modal openers/closers + focus trap within the node. */
17
17
  export const modal = actionFor((node) => enhanceModal(node));
18
- /** `use:drawer` — wires drawer openers/closers within the node. */
18
+ /** `use:drawer`: wires drawer openers/closers within the node. */
19
19
  export const drawer = actionFor((node) => enhanceDrawer(node));
20
- /** `use:popover` — wires popover openers/closers within the node. */
20
+ /** `use:popover`: wires popover openers/closers within the node. */
21
21
  export const popover = actionFor((node) => enhancePopover(node));
22
- /** `use:tooltip` — wires `[data-hl-tooltip]` triggers within the node. */
22
+ /** `use:tooltip`: wires `[data-hl-tooltip]` triggers within the node. */
23
23
  export const tooltip = actionFor((node) => enhanceTooltip(node));
24
- /** `use:toc` — builds a table of contents from the surrounding document. */
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` — menubar/navigation pattern on a `[data-hl-menu]` element. */
26
+ /** `use:menu`: menubar/navigation pattern on a `[data-hl-menu]` element. */
27
27
  export const menu = actionFor((node) => enhanceMenu(node));
28
- /** `use:combobox` — editable combobox on a `[data-hl-combobox]` element. */
28
+ /** `use:combobox`: editable combobox on a `[data-hl-combobox]` element. */
29
29
  export const combobox = actionFor((node) => enhanceCombobox(node));
30
- /** `use:command` — command palette on a `[data-hl-command]` element. */
30
+ /** `use:command`: command palette on a `[data-hl-command]` element. */
31
31
  export const command = actionFor((node) => enhanceCommand(node));
@@ -1,25 +1,36 @@
1
1
  <script lang="ts">
2
- import { combine, onClickOutside, onEscape } from '@hydrateless/enhancers';
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`). Escape/outside clicks close it. */
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;
9
11
  children?: Snippet;
10
12
  }
11
13
 
12
14
  let { open = $bindable(false), children, ...rest }: Props = $props();
13
15
  let host = $state<HTMLDivElement>();
16
+ let api = $state<PopoverApi | null>(null);
14
17
 
15
18
  $effect(() => {
16
- const el = host;
17
- if (!el || !open) return;
18
- const dismiss = () => (open = false);
19
- return combine([onClickOutside(el, dismiss), onEscape(dismiss, el.ownerDocument)]);
19
+ if (!host) return;
20
+ const handle = enhancePopover(host, { onOpenChange: (next) => (open = next) });
21
+ api = handle.api;
22
+ if (untrack(() => open)) handle.api?.setOpen(true);
23
+ return () => {
24
+ handle.destroy();
25
+ api = null;
26
+ };
27
+ });
28
+
29
+ $effect(() => {
30
+ api?.setOpen(open);
20
31
  });
21
32
  </script>
22
33
 
23
- <div {...rest} data-hl-popover role="dialog" hidden={!open} bind:this={host}>
34
+ <div {...rest} data-hl-popover popover="auto" role="dialog" bind:this={host}>
24
35
  {@render children?.()}
25
36
  </div>
@@ -1,7 +1,8 @@
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`). Escape/outside clicks close it. */
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;
6
7
  children?: Snippet;
7
8
  }
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/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 — no setup required:
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 — no setup required:
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.6.0",
4
- "description": "Svelte 5 bindings for Hydrateless — first-class components, actions, and a toast store.",
3
+ "version": "0.7.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.6.0"
35
+ "@hydrateless/enhancers": "^0.7.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "svelte": ">=5"