@hydrateless/vue 0.7.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 CHANGED
@@ -80,19 +80,17 @@ const open = ref(false);
80
80
 
81
81
  ```vue
82
82
  <script setup lang="ts">
83
- import { ref } from 'vue';
84
83
  import { useEnhancer, useToast } from '@hydrateless/vue';
85
84
  import { enhanceDropdown } from '@hydrateless/enhancers';
86
85
 
87
- const menu = ref<HTMLElement | null>(null);
88
- const dropdown = useEnhancer(menu, enhanceDropdown);
89
- // dropdown.value?.setOpen(true)
86
+ const { host, api } = useEnhancer((el) => enhanceDropdown(el));
87
+ // api.value?.setOpen(true)
90
88
 
91
89
  const toast = useToast(); // no provider required
92
90
  </script>
93
91
 
94
92
  <template>
95
- <div ref="menu" data-hl-dropdown>…</div>
93
+ <div ref="host" data-hl-dropdown>…</div>
96
94
  <button @click="toast.show('Saved')">Save</button>
97
95
  </template>
98
96
  ```
package/dist/index.d.ts CHANGED
@@ -1,21 +1,29 @@
1
1
  import * as vue from 'vue';
2
- import { Ref, ShallowRef, Plugin, Directive, PropType } from 'vue';
2
+ import { WatchSource, Ref, ShallowRef, Plugin, Directive, PropType } from 'vue';
3
3
  import * as _hydrateless_enhancers from '@hydrateless/enhancers';
4
4
  import { EnhancerHandle, EnhanceToastOptions, ToastApi, EnhanceTabsOptions, EnhanceDropdownOptions, EnhanceMenuOptions, EnhanceComboboxOptions } from '@hydrateless/enhancers';
5
- export { AccordionApi, ComboboxApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, ModalApi, PopoverApi, TabsApi, ToastApi, TooltipApi } from '@hydrateless/enhancers';
5
+ export { AccordionApi, ComboboxApi, CommandApi, DisclosureApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, MenuApi, ModalApi, PopoverApi, TabsApi, ToastApi, TocApi, TooltipApi } from '@hydrateless/enhancers';
6
6
 
7
7
  /**
8
- * Attach any Hydrateless enhancer to a template ref for the lifetime of a
9
- * component. Returns a shallow ref to the enhancer's imperative API; the
10
- * instance is destroyed automatically on unmount.
8
+ * Attach any Hydrateless enhancer to a host element for the lifetime of a
9
+ * component. Returns a template ref to bind onto the element you want
10
+ * enhanced plus a shallow ref to the enhancer's imperative API (e.g.
11
+ * `setValue`/`setOpen`). The enhancer runs client-side only (so components
12
+ * stay SSR-safe) and is destroyed automatically on unmount. Pass a reactive
13
+ * `source` to destroy and re-attach whenever an enhancer option changes.
11
14
  *
12
- * ```ts
13
- * const el = ref<HTMLElement | null>(null);
14
- * const tabs = useEnhancer(el, enhanceTabs);
15
- * tabs.value?.setValue('install');
15
+ * ```vue
16
+ * <script setup>
17
+ * const { host, api } = useEnhancer((el) => enhanceTabs(el));
18
+ * // api.value?.setValue('two');
19
+ * </script>
20
+ * <template><div data-hl-tabs ref="host">…</div></template>
16
21
  * ```
17
22
  */
18
- declare function useEnhancer<Api = null>(target: Ref<HTMLElement | null | undefined>, enhance: (container: HTMLElement) => EnhancerHandle<Api>): ShallowRef<Api | null>;
23
+ declare function useEnhancer<Api = null>(enhance: (el: HTMLElement) => EnhancerHandle<Api>, source?: WatchSource<unknown>): {
24
+ host: Ref<HTMLElement | null>;
25
+ api: ShallowRef<Api | null>;
26
+ };
19
27
 
20
28
  /**
21
29
  * Imperative toast API backed by a lazily-created document-level region (or a
@@ -136,23 +144,39 @@ declare const AccordionItem: vue.DefineComponent<vue.ExtractPropTypes<{
136
144
  defaultOpen: boolean;
137
145
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
138
146
  /**
139
- * A single expandable section. Native `<details>` handles open/close; the
140
- * enhancer only matters for a mutually-exclusive group.
147
+ * A single expandable section built on native `<details>`, which handles
148
+ * open/close (and exclusive groups, via the `name` attribute) on its own.
149
+ * Open state works uncontrolled (`defaultOpen`) or with `v-model:open`.
141
150
  */
142
151
  declare const Disclosure: vue.DefineComponent<vue.ExtractPropTypes<{
152
+ /** Controlled open state (`v-model:open`). */
153
+ open: {
154
+ type: PropType<boolean | undefined>;
155
+ default: undefined;
156
+ };
157
+ /** Open the disclosure initially for uncontrolled usage. */
143
158
  defaultOpen: {
144
159
  type: BooleanConstructor;
145
160
  default: boolean;
146
161
  };
147
162
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
148
163
  [key: string]: any;
149
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
164
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:open"[], "update:open", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
165
+ /** Controlled open state (`v-model:open`). */
166
+ open: {
167
+ type: PropType<boolean | undefined>;
168
+ default: undefined;
169
+ };
170
+ /** Open the disclosure initially for uncontrolled usage. */
150
171
  defaultOpen: {
151
172
  type: BooleanConstructor;
152
173
  default: boolean;
153
174
  };
154
- }>> & Readonly<{}>, {
175
+ }>> & Readonly<{
176
+ "onUpdate:open"?: ((...args: any[]) => any) | undefined;
177
+ }>, {
155
178
  defaultOpen: boolean;
179
+ open: boolean | undefined;
156
180
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
157
181
 
158
182
  /**
@@ -288,8 +312,8 @@ declare const Dropdown: vue.DefineComponent<vue.ExtractPropTypes<{
288
312
  "onUpdate:open"?: ((...args: any[]) => any) | undefined;
289
313
  }>, {
290
314
  defaultOpen: boolean;
291
- placement: _hydrateless_enhancers.Placement | undefined;
292
315
  open: boolean | undefined;
316
+ placement: _hydrateless_enhancers.Placement | undefined;
293
317
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
294
318
  /** The button that opens the menu. */
295
319
  declare const DropdownTrigger: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
@@ -311,22 +335,38 @@ declare const DropdownSeparator: vue.DefineComponent<{}, () => vue.VNode<vue.Ren
311
335
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
312
336
 
313
337
  /**
314
- * Menubar / navigation menu with single-level submenus. Compose with
315
- * `<MenuItem>`; nest a flyout via the `submenu` slot.
338
+ * Menubar / navigation menu with single-level submenus rendered in the top
339
+ * layer. Compose with `<MenuItem>`; nest a flyout via the `submenu` slot. The
340
+ * open submenu works uncontrolled or with `v-model:open` (a submenu value or
341
+ * `null`), and activating a leaf item emits `select` with its value.
316
342
  */
317
343
  declare const Menu: vue.DefineComponent<vue.ExtractPropTypes<{
318
344
  orientation: {
319
345
  type: PropType<EnhanceMenuOptions["orientation"]>;
320
346
  default: string;
321
347
  };
348
+ /** Controlled open submenu value (`v-model:open`), or `null` for none. */
349
+ open: {
350
+ type: PropType<string | null | undefined>;
351
+ default: undefined;
352
+ };
322
353
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
323
354
  [key: string]: any;
324
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
355
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("select" | "update:open")[], "select" | "update:open", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
325
356
  orientation: {
326
357
  type: PropType<EnhanceMenuOptions["orientation"]>;
327
358
  default: string;
328
359
  };
329
- }>> & Readonly<{}>, {
360
+ /** Controlled open submenu value (`v-model:open`), or `null` for none. */
361
+ open: {
362
+ type: PropType<string | null | undefined>;
363
+ default: undefined;
364
+ };
365
+ }>> & Readonly<{
366
+ onSelect?: ((...args: any[]) => any) | undefined;
367
+ "onUpdate:open"?: ((...args: any[]) => any) | undefined;
368
+ }>, {
369
+ open: string | null | undefined;
330
370
  orientation: "horizontal" | "vertical" | undefined;
331
371
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
332
372
  /**
@@ -338,6 +378,11 @@ declare const MenuItem: vue.DefineComponent<vue.ExtractPropTypes<{
338
378
  type: StringConstructor;
339
379
  default: undefined;
340
380
  };
381
+ /** Stable value identifying this item; defaults to its label text. */
382
+ value: {
383
+ type: StringConstructor;
384
+ default: undefined;
385
+ };
341
386
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
342
387
  [key: string]: any;
343
388
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "select"[], "select", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
@@ -345,22 +390,35 @@ declare const MenuItem: vue.DefineComponent<vue.ExtractPropTypes<{
345
390
  type: StringConstructor;
346
391
  default: undefined;
347
392
  };
393
+ /** Stable value identifying this item; defaults to its label text. */
394
+ value: {
395
+ type: StringConstructor;
396
+ default: undefined;
397
+ };
348
398
  }>> & Readonly<{
349
399
  onSelect?: ((...args: any[]) => any) | undefined;
350
400
  }>, {
401
+ value: string;
351
402
  href: string;
352
403
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
353
404
 
354
405
  /**
355
- * Controlled dialog overlay on the native `<dialog>` plus the modal enhancer
356
- * (focus trap, scroll-lock, background `inert`). Drive with `v-model:open`;
357
- * Escape and backdrop clicks emit `update:open`. Compose with `<ModalHeader>`,
358
- * `<ModalBody>`, `<ModalFooter>`.
406
+ * Dialog overlay on the native `<dialog>` plus the modal enhancer (focus
407
+ * trap, scroll-lock, background `inert`). Open state works uncontrolled
408
+ * (`defaultOpen`, or a `command="show-modal"` invoker button) or with
409
+ * `v-model:open`; Escape and backdrop clicks emit `update:open`. Compose
410
+ * with `<ModalHeader>`, `<ModalBody>`, `<ModalFooter>`.
359
411
  */
360
412
  declare const Modal: vue.DefineComponent<vue.ExtractPropTypes<{
413
+ /** Controlled open state (`v-model:open`). */
361
414
  open: {
415
+ type: PropType<boolean | undefined>;
416
+ default: undefined;
417
+ };
418
+ /** Open the dialog initially for uncontrolled usage. */
419
+ defaultOpen: {
362
420
  type: BooleanConstructor;
363
- required: true;
421
+ default: boolean;
364
422
  };
365
423
  closeOnBackdrop: {
366
424
  type: BooleanConstructor;
@@ -369,9 +427,15 @@ declare const Modal: vue.DefineComponent<vue.ExtractPropTypes<{
369
427
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
370
428
  [key: string]: any;
371
429
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:open"[], "update:open", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
430
+ /** Controlled open state (`v-model:open`). */
372
431
  open: {
432
+ type: PropType<boolean | undefined>;
433
+ default: undefined;
434
+ };
435
+ /** Open the dialog initially for uncontrolled usage. */
436
+ defaultOpen: {
373
437
  type: BooleanConstructor;
374
- required: true;
438
+ default: boolean;
375
439
  };
376
440
  closeOnBackdrop: {
377
441
  type: BooleanConstructor;
@@ -380,17 +444,26 @@ declare const Modal: vue.DefineComponent<vue.ExtractPropTypes<{
380
444
  }>> & Readonly<{
381
445
  "onUpdate:open"?: ((...args: any[]) => any) | undefined;
382
446
  }>, {
447
+ defaultOpen: boolean;
448
+ open: boolean | undefined;
383
449
  closeOnBackdrop: boolean;
384
450
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
385
451
  /**
386
- * Controlled off-canvas panel on the native `<dialog>` plus the drawer
387
- * enhancer. Drive with `v-model:open`; choose a `side`. Compose with
388
- * `<DrawerHeader>`, `<DrawerBody>`, `<DrawerFooter>`.
452
+ * Off-canvas panel on the native `<dialog>` plus the drawer enhancer. Open
453
+ * state works uncontrolled (`defaultOpen`, or an invoker button) or with
454
+ * `v-model:open`; choose a `side`. Compose with `<DrawerHeader>`,
455
+ * `<DrawerBody>`, `<DrawerFooter>`.
389
456
  */
390
457
  declare const Drawer: vue.DefineComponent<vue.ExtractPropTypes<{
458
+ /** Controlled open state (`v-model:open`). */
391
459
  open: {
460
+ type: PropType<boolean | undefined>;
461
+ default: undefined;
462
+ };
463
+ /** Open the drawer initially for uncontrolled usage. */
464
+ defaultOpen: {
392
465
  type: BooleanConstructor;
393
- required: true;
466
+ default: boolean;
394
467
  };
395
468
  side: {
396
469
  type: PropType<"left" | "right">;
@@ -403,9 +476,15 @@ declare const Drawer: vue.DefineComponent<vue.ExtractPropTypes<{
403
476
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
404
477
  [key: string]: any;
405
478
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:open"[], "update:open", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
479
+ /** Controlled open state (`v-model:open`). */
406
480
  open: {
481
+ type: PropType<boolean | undefined>;
482
+ default: undefined;
483
+ };
484
+ /** Open the drawer initially for uncontrolled usage. */
485
+ defaultOpen: {
407
486
  type: BooleanConstructor;
408
- required: true;
487
+ default: boolean;
409
488
  };
410
489
  side: {
411
490
  type: PropType<"left" | "right">;
@@ -418,6 +497,8 @@ declare const Drawer: vue.DefineComponent<vue.ExtractPropTypes<{
418
497
  }>> & Readonly<{
419
498
  "onUpdate:open"?: ((...args: any[]) => any) | undefined;
420
499
  }>, {
500
+ defaultOpen: boolean;
501
+ open: boolean | undefined;
421
502
  closeOnBackdrop: boolean;
422
503
  side: "left" | "right";
423
504
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
@@ -446,27 +527,41 @@ declare const DrawerFooter: vue.DefineComponent<{}, () => vue.VNode<vue.Renderer
446
527
  [key: string]: any;
447
528
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
448
529
  /**
449
- * Controlled floating content built on the native Popover API. The surface
450
- * lives in the top layer with light-dismiss and Escape handled by the browser;
451
- * visibility follows `open` and `update:open` is emitted when the browser
452
- * dismisses it, so `v-model:open` stays in sync. Pair with your own trigger.
530
+ * Floating content built on the native Popover API. The surface lives in the
531
+ * top layer with light-dismiss and Escape handled by the browser; visibility
532
+ * works uncontrolled (`defaultOpen`, or a `popovertarget` trigger button) or
533
+ * with `v-model:open` (`update:open` is emitted when the browser dismisses
534
+ * it).
453
535
  */
454
536
  declare const Popover: vue.DefineComponent<vue.ExtractPropTypes<{
537
+ /** Controlled open state (`v-model:open`). */
455
538
  open: {
539
+ type: PropType<boolean | undefined>;
540
+ default: undefined;
541
+ };
542
+ /** Show the popover initially for uncontrolled usage. */
543
+ defaultOpen: {
456
544
  type: BooleanConstructor;
457
545
  default: boolean;
458
546
  };
459
547
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
460
548
  [key: string]: any;
461
549
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:open"[], "update:open", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
550
+ /** Controlled open state (`v-model:open`). */
462
551
  open: {
552
+ type: PropType<boolean | undefined>;
553
+ default: undefined;
554
+ };
555
+ /** Show the popover initially for uncontrolled usage. */
556
+ defaultOpen: {
463
557
  type: BooleanConstructor;
464
558
  default: boolean;
465
559
  };
466
560
  }>> & Readonly<{
467
561
  "onUpdate:open"?: ((...args: any[]) => any) | undefined;
468
562
  }>, {
469
- open: boolean;
563
+ defaultOpen: boolean;
564
+ open: boolean | undefined;
470
565
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
471
566
  /**
472
567
  * Accessible tooltip wrapping a single focusable trigger (the default slot).
@@ -623,7 +718,8 @@ declare const ComboboxOption: vue.DefineComponent<vue.ExtractPropTypes<{
623
718
  /**
624
719
  * Command palette. Compose with `<CommandInput>`, `<CommandList>`,
625
720
  * `<CommandGroup>`, `<CommandItem>`, `<CommandEmpty>`. Emits `select` with the
626
- * chosen value. Place inside a `<dialog>` to use `hotkey`.
721
+ * chosen value and `update:query` as the filter changes. Place inside a
722
+ * `<dialog>` to use `hotkey`.
627
723
  */
628
724
  declare const Command: vue.DefineComponent<vue.ExtractPropTypes<{
629
725
  hotkey: {
@@ -632,13 +728,14 @@ declare const Command: vue.DefineComponent<vue.ExtractPropTypes<{
632
728
  };
633
729
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
634
730
  [key: string]: any;
635
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "select"[], "select", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
731
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("select" | "update:query")[], "select" | "update:query", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
636
732
  hotkey: {
637
733
  type: StringConstructor;
638
734
  default: undefined;
639
735
  };
640
736
  }>> & Readonly<{
641
737
  onSelect?: ((...args: any[]) => any) | undefined;
738
+ "onUpdate:query"?: ((...args: any[]) => any) | undefined;
642
739
  }>, {
643
740
  hotkey: string;
644
741
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
@@ -731,8 +828,8 @@ declare const Field: vue.DefineComponent<vue.ExtractPropTypes<{
731
828
  };
732
829
  }>> & Readonly<{}>, {
733
830
  invalid: boolean;
734
- required: boolean;
735
831
  id: string;
832
+ required: boolean;
736
833
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
737
834
  /** Returns props (`id`, `aria-describedby`, `aria-invalid`) to bind onto a control. */
738
835
  declare function useFieldBindings(): {
@@ -963,12 +1060,20 @@ declare const Radio: vue.DefineComponent<vue.ExtractPropTypes<{
963
1060
  required: true;
964
1061
  };
965
1062
  }>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
966
- /** Segmented control: a styled radiogroup. Supports `v-model`. */
1063
+ /**
1064
+ * Segmented control: a styled radiogroup. The selected value works
1065
+ * uncontrolled (`defaultValue`) or with `v-model`.
1066
+ */
967
1067
  declare const SegmentedControl: vue.DefineComponent<vue.ExtractPropTypes<{
968
1068
  modelValue: {
969
1069
  type: StringConstructor;
970
1070
  default: undefined;
971
1071
  };
1072
+ /** Initially selected value for uncontrolled usage. */
1073
+ defaultValue: {
1074
+ type: StringConstructor;
1075
+ default: undefined;
1076
+ };
972
1077
  options: {
973
1078
  type: PropType<Array<{
974
1079
  label: string;
@@ -992,6 +1097,11 @@ declare const SegmentedControl: vue.DefineComponent<vue.ExtractPropTypes<{
992
1097
  type: StringConstructor;
993
1098
  default: undefined;
994
1099
  };
1100
+ /** Initially selected value for uncontrolled usage. */
1101
+ defaultValue: {
1102
+ type: StringConstructor;
1103
+ default: undefined;
1104
+ };
995
1105
  options: {
996
1106
  type: PropType<Array<{
997
1107
  label: string;
@@ -1013,6 +1123,7 @@ declare const SegmentedControl: vue.DefineComponent<vue.ExtractPropTypes<{
1013
1123
  }>, {
1014
1124
  name: string;
1015
1125
  modelValue: string;
1126
+ defaultValue: string;
1016
1127
  size: Size;
1017
1128
  options: {
1018
1129
  label: string;
package/dist/index.js CHANGED
@@ -1,20 +1,31 @@
1
1
  // src/useEnhancer.ts
2
- import { onMounted, onUnmounted, shallowRef } from "vue";
3
- function useEnhancer(target, enhance) {
2
+ import {
3
+ onBeforeUnmount,
4
+ onMounted,
5
+ ref,
6
+ shallowRef,
7
+ watch
8
+ } from "vue";
9
+ function useEnhancer(enhance, source) {
10
+ const host = ref(null);
4
11
  const api = shallowRef(null);
5
12
  let destroy = null;
6
- onMounted(() => {
7
- if (!target.value) return;
8
- const handle = enhance(target.value);
9
- api.value = handle.api;
10
- destroy = handle.destroy;
11
- });
12
- onUnmounted(() => {
13
+ const detach = () => {
13
14
  destroy?.();
14
15
  destroy = null;
15
16
  api.value = null;
16
- });
17
- return api;
17
+ };
18
+ const attach = () => {
19
+ detach();
20
+ if (!host.value) return;
21
+ const handle = enhance(host.value);
22
+ api.value = handle.api;
23
+ destroy = handle.destroy;
24
+ };
25
+ onMounted(attach);
26
+ if (source) watch(source, attach);
27
+ onBeforeUnmount(detach);
28
+ return { host, api };
18
29
  }
19
30
 
20
31
  // src/useToast.ts
@@ -96,31 +107,16 @@ var HydratelessPlugin = {
96
107
  };
97
108
 
98
109
  // src/components/disclosure.ts
99
- import { defineComponent, h, onMounted as onMounted3, ref as ref2, watch } from "vue";
100
- import { enhanceAccordion as enhanceAccordion2 } from "@hydrateless/enhancers";
110
+ import { defineComponent, h, onMounted as onMounted2, ref as ref2, watch as watch2 } from "vue";
111
+ import {
112
+ enhanceAccordion as enhanceAccordion2,
113
+ enhanceDisclosure as enhanceDisclosure2
114
+ } from "@hydrateless/enhancers";
101
115
 
102
116
  // src/internal.ts
103
- import { onBeforeUnmount, onMounted as onMounted2, ref, shallowRef as shallowRef2 } from "vue";
104
117
  function cx(...classes) {
105
118
  return classes.filter(Boolean).join(" ");
106
119
  }
107
- function useHostEnhancer(enhance) {
108
- const host = ref(null);
109
- const api = shallowRef2(null);
110
- let destroy = null;
111
- onMounted2(() => {
112
- if (!host.value) return;
113
- const handle = enhance(host.value);
114
- api.value = handle.api;
115
- destroy = handle.destroy;
116
- });
117
- onBeforeUnmount(() => {
118
- destroy?.();
119
- destroy = null;
120
- api.value = null;
121
- });
122
- return { host, api };
123
- }
124
120
 
125
121
  // src/components/disclosure.ts
126
122
  var Accordion = defineComponent({
@@ -135,14 +131,15 @@ var Accordion = defineComponent({
135
131
  },
136
132
  emits: ["update:modelValue"],
137
133
  setup(props, { slots, attrs, emit }) {
138
- const { host, api } = useHostEnhancer(
134
+ const { host, api } = useEnhancer(
139
135
  (el) => enhanceAccordion2(el, {
140
136
  allowMultiple: props.allowMultiple,
141
137
  defaultValue: props.modelValue ?? props.defaultValue,
142
138
  onValueChange: (value) => emit("update:modelValue", value)
143
- })
139
+ }),
140
+ () => props.allowMultiple
144
141
  );
145
- watch(
142
+ watch2(
146
143
  () => props.modelValue,
147
144
  (value) => {
148
145
  if (value != null) api.value?.setValue(value);
@@ -161,7 +158,7 @@ var AccordionItem = defineComponent({
161
158
  },
162
159
  setup(props, { slots, attrs }) {
163
160
  const el = ref2(null);
164
- onMounted3(() => {
161
+ onMounted2(() => {
165
162
  if (el.value && props.defaultOpen) el.value.open = true;
166
163
  });
167
164
  return () => h("details", { ...attrs, "data-hl-value": props.value, ref: el }, [
@@ -174,20 +171,32 @@ var Disclosure = defineComponent({
174
171
  name: "HlDisclosure",
175
172
  inheritAttrs: false,
176
173
  props: {
174
+ /** Controlled open state (`v-model:open`). */
175
+ open: { type: Boolean, default: void 0 },
176
+ /** Open the disclosure initially for uncontrolled usage. */
177
177
  defaultOpen: { type: Boolean, default: false }
178
178
  },
179
- setup(props, { slots, attrs }) {
180
- const el = ref2(null);
181
- onMounted3(() => {
182
- if (el.value && props.defaultOpen) el.value.open = true;
183
- });
179
+ emits: ["update:open"],
180
+ setup(props, { slots, attrs, emit }) {
181
+ const { host, api } = useEnhancer(
182
+ (el) => enhanceDisclosure2(el, {
183
+ defaultOpen: props.open ?? props.defaultOpen,
184
+ onOpenChange: (open) => emit("update:open", open)
185
+ })
186
+ );
187
+ watch2(
188
+ () => props.open,
189
+ (open) => {
190
+ if (open != null) api.value?.setOpen(open);
191
+ }
192
+ );
184
193
  return () => h(
185
194
  "details",
186
195
  {
187
196
  ...attrs,
188
197
  class: cx("hl-disclosure", attrs.class),
189
198
  "data-hl-disclosure": "",
190
- ref: el
199
+ ref: host
191
200
  },
192
201
  [
193
202
  h("summary", slots.summary?.()),
@@ -198,7 +207,7 @@ var Disclosure = defineComponent({
198
207
  });
199
208
 
200
209
  // src/components/tabs.ts
201
- import { defineComponent as defineComponent2, h as h2, watch as watch2 } from "vue";
210
+ import { defineComponent as defineComponent2, h as h2, watch as watch3 } from "vue";
202
211
  import { enhanceTabs as enhanceTabs2 } from "@hydrateless/enhancers";
203
212
  var Tabs = defineComponent2({
204
213
  name: "HlTabs",
@@ -216,15 +225,16 @@ var Tabs = defineComponent2({
216
225
  },
217
226
  emits: ["update:modelValue"],
218
227
  setup(props, { slots, attrs, emit }) {
219
- const { host, api } = useHostEnhancer(
228
+ const { host, api } = useEnhancer(
220
229
  (el) => enhanceTabs2(el, {
221
230
  activation: props.activation,
222
231
  orientation: props.orientation,
223
232
  defaultValue: props.modelValue ?? props.defaultValue,
224
233
  onValueChange: (value) => emit("update:modelValue", value)
225
- })
234
+ }),
235
+ () => [props.activation, props.orientation]
226
236
  );
227
- watch2(
237
+ watch3(
228
238
  () => props.modelValue,
229
239
  (value) => {
230
240
  if (value != null) api.value?.setValue(value);
@@ -264,7 +274,7 @@ var TabPanel = defineComponent2({
264
274
  });
265
275
 
266
276
  // src/components/dropdown.ts
267
- import { defineComponent as defineComponent3, h as h3, watch as watch3 } from "vue";
277
+ import { defineComponent as defineComponent3, h as h3, watch as watch4 } from "vue";
268
278
  import {
269
279
  enhanceDropdown as enhanceDropdown2
270
280
  } from "@hydrateless/enhancers";
@@ -283,14 +293,15 @@ var Dropdown = defineComponent3({
283
293
  },
284
294
  emits: ["update:open"],
285
295
  setup(props, { slots, attrs, emit }) {
286
- const { host, api } = useHostEnhancer(
296
+ const { host, api } = useEnhancer(
287
297
  (el) => enhanceDropdown2(el, {
288
298
  placement: props.placement,
289
299
  defaultOpen: props.open ?? props.defaultOpen,
290
300
  onOpenChange: (open) => emit("update:open", open)
291
- })
301
+ }),
302
+ () => props.placement
292
303
  );
293
- watch3(
304
+ watch4(
294
305
  () => props.open,
295
306
  (open) => {
296
307
  if (open != null) api.value?.setOpen(open);
@@ -341,7 +352,7 @@ var DropdownSeparator = defineComponent3({
341
352
  });
342
353
 
343
354
  // src/components/menu.ts
344
- import { defineComponent as defineComponent4, h as h4 } from "vue";
355
+ import { defineComponent as defineComponent4, h as h4, watch as watch5 } from "vue";
345
356
  import { enhanceMenu as enhanceMenu2 } from "@hydrateless/enhancers";
346
357
  var Menu = defineComponent4({
347
358
  name: "HlMenu",
@@ -350,10 +361,26 @@ var Menu = defineComponent4({
350
361
  orientation: {
351
362
  type: String,
352
363
  default: "horizontal"
353
- }
364
+ },
365
+ /** Controlled open submenu value (`v-model:open`), or `null` for none. */
366
+ open: { type: String, default: void 0 }
354
367
  },
355
- setup(props, { slots, attrs }) {
356
- const { host } = useHostEnhancer((el) => enhanceMenu2(el, { orientation: props.orientation }));
368
+ emits: ["update:open", "select"],
369
+ setup(props, { slots, attrs, emit }) {
370
+ const { host, api } = useEnhancer(
371
+ (el) => enhanceMenu2(el, {
372
+ orientation: props.orientation,
373
+ onOpenChange: (value) => emit("update:open", value),
374
+ onSelect: (value) => emit("select", value)
375
+ }),
376
+ () => props.orientation
377
+ );
378
+ watch5(
379
+ () => props.open,
380
+ (open) => {
381
+ if (open !== void 0) api.value?.setOpen(open);
382
+ }
383
+ );
357
384
  return () => h4(
358
385
  "ul",
359
386
  {
@@ -371,15 +398,27 @@ var MenuItem = defineComponent4({
371
398
  name: "HlMenuItem",
372
399
  inheritAttrs: false,
373
400
  props: {
374
- href: { type: String, default: void 0 }
401
+ href: { type: String, default: void 0 },
402
+ /** Stable value identifying this item; defaults to its label text. */
403
+ value: { type: String, default: void 0 }
375
404
  },
376
405
  emits: ["select"],
377
406
  setup(props, { slots, attrs, emit }) {
378
407
  return () => {
379
408
  const hasSubmenu = !!slots.submenu;
380
- const label = props.href && !hasSubmenu ? h4("a", { ...attrs, role: "menuitem", href: props.href }, slots.default?.()) : h4(
409
+ const label = props.href && !hasSubmenu ? h4(
410
+ "a",
411
+ { ...attrs, role: "menuitem", href: props.href, "data-hl-value": props.value },
412
+ slots.default?.()
413
+ ) : h4(
381
414
  "button",
382
- { type: "button", ...attrs, role: "menuitem", onClick: () => emit("select") },
415
+ {
416
+ type: "button",
417
+ ...attrs,
418
+ role: "menuitem",
419
+ "data-hl-value": props.value,
420
+ onClick: () => emit("select")
421
+ },
383
422
  slots.default?.()
384
423
  );
385
424
  const children = [label];
@@ -394,7 +433,7 @@ var MenuItem = defineComponent4({
394
433
  });
395
434
 
396
435
  // src/components/overlay.ts
397
- import { defineComponent as defineComponent5, h as h5, onBeforeUnmount as onBeforeUnmount2, onMounted as onMounted4, ref as ref3, watch as watch4 } from "vue";
436
+ import { defineComponent as defineComponent5, h as h5, onBeforeUnmount as onBeforeUnmount2, onMounted as onMounted3, ref as ref3, watch as watch6 } from "vue";
398
437
  import {
399
438
  enhanceDrawer as enhanceDrawer2,
400
439
  enhanceModal as enhanceModal2,
@@ -402,18 +441,19 @@ import {
402
441
  enhanceTooltip as enhanceTooltip2
403
442
  } from "@hydrateless/enhancers";
404
443
  function useDialogEnhancer(props, emit, enhance) {
405
- const { host, api } = useHostEnhancer(
444
+ const { host, api } = useEnhancer(
406
445
  (el) => enhance(el, {
407
446
  closeOnBackdrop: props.closeOnBackdrop,
447
+ defaultOpen: props.open ?? props.defaultOpen,
408
448
  onOpenChange: (open) => emit("update:open", open)
409
- })
449
+ }),
450
+ () => props.closeOnBackdrop
410
451
  );
411
- onMounted4(() => {
412
- if (props.open) api.value?.setOpen(true);
413
- });
414
- watch4(
452
+ watch6(
415
453
  () => props.open,
416
- (open) => api.value?.setOpen(open)
454
+ (open) => {
455
+ if (open != null) api.value?.setOpen(open);
456
+ }
417
457
  );
418
458
  return host;
419
459
  }
@@ -421,7 +461,10 @@ var Modal = defineComponent5({
421
461
  name: "HlModal",
422
462
  inheritAttrs: false,
423
463
  props: {
424
- open: { type: Boolean, required: true },
464
+ /** Controlled open state (`v-model:open`). */
465
+ open: { type: Boolean, default: void 0 },
466
+ /** Open the dialog initially for uncontrolled usage. */
467
+ defaultOpen: { type: Boolean, default: false },
425
468
  closeOnBackdrop: { type: Boolean, default: true }
426
469
  },
427
470
  emits: ["update:open"],
@@ -443,7 +486,10 @@ var Drawer = defineComponent5({
443
486
  name: "HlDrawer",
444
487
  inheritAttrs: false,
445
488
  props: {
446
- open: { type: Boolean, required: true },
489
+ /** Controlled open state (`v-model:open`). */
490
+ open: { type: Boolean, default: void 0 },
491
+ /** Open the drawer initially for uncontrolled usage. */
492
+ defaultOpen: { type: Boolean, default: false },
447
493
  side: { type: String, default: "right" },
448
494
  closeOnBackdrop: { type: Boolean, default: true }
449
495
  },
@@ -482,19 +528,24 @@ var Popover = defineComponent5({
482
528
  name: "HlPopover",
483
529
  inheritAttrs: false,
484
530
  props: {
485
- open: { type: Boolean, default: false }
531
+ /** Controlled open state (`v-model:open`). */
532
+ open: { type: Boolean, default: void 0 },
533
+ /** Show the popover initially for uncontrolled usage. */
534
+ defaultOpen: { type: Boolean, default: false }
486
535
  },
487
536
  emits: ["update:open"],
488
537
  setup(props, { slots, attrs, emit }) {
489
- const { host, api } = useHostEnhancer(
490
- (el) => enhancePopover2(el, { onOpenChange: (open) => emit("update:open", open) })
538
+ const { host, api } = useEnhancer(
539
+ (el) => enhancePopover2(el, {
540
+ defaultOpen: props.open ?? props.defaultOpen,
541
+ onOpenChange: (open) => emit("update:open", open)
542
+ })
491
543
  );
492
- onMounted4(() => {
493
- if (props.open) api.value?.setOpen(true);
494
- });
495
- watch4(
544
+ watch6(
496
545
  () => props.open,
497
- (open) => api.value?.setOpen(open)
546
+ (open) => {
547
+ if (open != null) api.value?.setOpen(open);
548
+ }
498
549
  );
499
550
  return () => h5(
500
551
  "div",
@@ -515,7 +566,7 @@ var Tooltip = defineComponent5({
515
566
  const tipId = props.id ?? `hl-tip-${tipCounter += 1}`;
516
567
  const host = ref3(null);
517
568
  let destroy = null;
518
- onMounted4(() => {
569
+ onMounted3(() => {
519
570
  const trigger = host.value?.querySelector(":scope > :first-child");
520
571
  if (trigger) {
521
572
  trigger.setAttribute("data-hl-tooltip", tipId);
@@ -566,7 +617,7 @@ var BreadcrumbItem = defineComponent6({
566
617
  });
567
618
 
568
619
  // src/components/combobox.ts
569
- import { defineComponent as defineComponent7, h as h7, watch as watch5 } from "vue";
620
+ import { defineComponent as defineComponent7, h as h7, watch as watch7 } from "vue";
570
621
  import {
571
622
  enhanceCombobox as enhanceCombobox2
572
623
  } from "@hydrateless/enhancers";
@@ -586,7 +637,7 @@ var Combobox = defineComponent7({
586
637
  },
587
638
  emits: ["select", "update:modelValue"],
588
639
  setup(props, { slots, attrs, emit }) {
589
- const { host, api } = useHostEnhancer(
640
+ const { host, api } = useEnhancer(
590
641
  (el) => enhanceCombobox2(el, {
591
642
  filter: props.filter,
592
643
  autoHighlight: props.autoHighlight,
@@ -595,9 +646,10 @@ var Combobox = defineComponent7({
595
646
  emit("select", value);
596
647
  emit("update:modelValue", value);
597
648
  }
598
- })
649
+ }),
650
+ () => [props.filter, props.autoHighlight]
599
651
  );
600
- watch5(
652
+ watch7(
601
653
  () => props.modelValue,
602
654
  (value) => {
603
655
  if (value != null) api.value?.setValue(value);
@@ -647,13 +699,15 @@ var Command = defineComponent8({
647
699
  props: {
648
700
  hotkey: { type: String, default: void 0 }
649
701
  },
650
- emits: ["select"],
702
+ emits: ["select", "update:query"],
651
703
  setup(props, { slots, attrs, emit }) {
652
- const { host } = useHostEnhancer(
704
+ const { host } = useEnhancer(
653
705
  (el) => enhanceCommand2(el, {
654
706
  hotkey: props.hotkey,
707
+ onValueChange: (value) => emit("update:query", value),
655
708
  onCommand: (value) => emit("select", value)
656
- })
709
+ }),
710
+ () => props.hotkey
657
711
  );
658
712
  return () => h8(
659
713
  "div",
@@ -737,7 +791,8 @@ import {
737
791
  defineComponent as defineComponent9,
738
792
  h as h9,
739
793
  inject,
740
- provide
794
+ provide,
795
+ ref as ref4
741
796
  } from "vue";
742
797
  var FieldKey = /* @__PURE__ */ Symbol("hl-field");
743
798
  var fieldCounter = 0;
@@ -1023,6 +1078,8 @@ var SegmentedControl = defineComponent9({
1023
1078
  inheritAttrs: false,
1024
1079
  props: {
1025
1080
  modelValue: { type: String, default: void 0 },
1081
+ /** Initially selected value for uncontrolled usage. */
1082
+ defaultValue: { type: String, default: void 0 },
1026
1083
  options: {
1027
1084
  type: Array,
1028
1085
  default: () => []
@@ -1033,6 +1090,8 @@ var SegmentedControl = defineComponent9({
1033
1090
  emits: ["update:modelValue"],
1034
1091
  setup(props, { attrs, emit }) {
1035
1092
  const groupName = props.name ?? `hl-seg-${fieldCounter += 1}`;
1093
+ const internal = ref4(props.defaultValue);
1094
+ const current = computed(() => props.modelValue ?? internal.value);
1036
1095
  return () => h9(
1037
1096
  "div",
1038
1097
  {
@@ -1047,9 +1106,12 @@ var SegmentedControl = defineComponent9({
1047
1106
  type: "radio",
1048
1107
  name: groupName,
1049
1108
  value: option.value,
1050
- checked: props.modelValue === option.value,
1109
+ checked: current.value === option.value,
1051
1110
  disabled: option.disabled,
1052
- onChange: () => emit("update:modelValue", option.value)
1111
+ onChange: () => {
1112
+ internal.value = option.value;
1113
+ emit("update:modelValue", option.value);
1114
+ }
1053
1115
  }),
1054
1116
  h9("span", option.label)
1055
1117
  ])
@@ -1219,7 +1281,7 @@ var ToastRegion = defineComponent11({
1219
1281
  });
1220
1282
 
1221
1283
  // src/components/data.ts
1222
- import { defineComponent as defineComponent12, h as h12, ref as ref4 } from "vue";
1284
+ import { defineComponent as defineComponent12, h as h12, ref as ref5 } from "vue";
1223
1285
  var Card = defineComponent12({
1224
1286
  name: "HlCard",
1225
1287
  inheritAttrs: false,
@@ -1262,7 +1324,7 @@ var Avatar = defineComponent12({
1262
1324
  shape: { type: String, default: void 0 }
1263
1325
  },
1264
1326
  setup(props, { slots, attrs }) {
1265
- const failed = ref4(false);
1327
+ const failed = ref5(false);
1266
1328
  return () => h12(
1267
1329
  "span",
1268
1330
  {
@@ -1414,12 +1476,13 @@ var Toc = defineComponent13({
1414
1476
  scrollSpy: { type: Boolean, default: void 0 }
1415
1477
  },
1416
1478
  setup(props, { attrs }) {
1417
- const { host } = useHostEnhancer(
1479
+ const { host } = useEnhancer(
1418
1480
  (el) => enhanceToc2(el.ownerDocument, {
1419
1481
  contentSelector: props.contentSelector,
1420
1482
  headings: props.headings,
1421
1483
  scrollSpy: props.scrollSpy
1422
- })
1484
+ }),
1485
+ () => [props.contentSelector, props.headings, props.scrollSpy]
1423
1486
  );
1424
1487
  return () => h13("nav", { ...attrs, "data-hl-toc": "", ref: host });
1425
1488
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydrateless/vue",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Vue 3 bindings for Hydrateless: first-class components, directives, composables, and a plugin.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "test": "vitest run"
29
29
  },
30
30
  "dependencies": {
31
- "@hydrateless/enhancers": "^0.7.0"
31
+ "@hydrateless/enhancers": "^0.8.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "vue": ">=3.3"