@hydrateless/vue 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
@@ -161,12 +161,12 @@ const api = useEnhancer(host, enhanceDropdown, { placement: 'bottom-end' });
161
161
  </script>
162
162
 
163
163
  <template>
164
- <div ref="host" data-hl-dropdown>...</div>
164
+ <div ref="host" class="hl-dropdown" data-hl-dropdown>...</div>
165
165
  </template>
166
166
  ```
167
167
 
168
- Pass a getter for `options` and a fourth `deps` watch source to re-attach when
169
- an option changes.
168
+ Pass a getter for `options` and a fourth `deps` watch source to update options
169
+ in place via `handle.update()` when an option changes.
170
170
 
171
171
  ## Breaking changes in this release
172
172
 
package/dist/index.d.ts CHANGED
@@ -11,21 +11,11 @@ export { AccordionApi, ComboboxApi, CommandApi, DisclosureApi, Disposer, DrawerA
11
11
  * for markup the components don't cover. Returns a shallow ref to the
12
12
  * enhancer's imperative API (`setValue`, `setOpen`, and so on), `null` until
13
13
  * mounted. The enhancer runs client-side only, so components stay SSR-safe,
14
- * and is destroyed on unmount. `options` may be a getter; it's re-read, and
15
- * the enhancer re-attached, whenever `deps` changes.
16
- *
17
- * ```vue
18
- * <script setup>
19
- * import { useTemplateRef } from 'vue';
20
- * import { enhanceTabs } from '@hydrateless/enhancers';
21
- * const host = useTemplateRef('host');
22
- * const api = useEnhancer(host, enhanceTabs, { activation: 'automatic' });
23
- * // api.value?.setValue('two');
24
- * </script>
25
- * <template><div data-hl-tabs ref="host">...</div></template>
26
- * ```
14
+ * and is destroyed on unmount. When `deps` changes, `options` is re-read and
15
+ * applied in place via `handle.update()`, preserving open overlays and state.
16
+ * If the element wasn't rendered on mount, a `deps` change attaches it.
27
17
  */
28
- declare function useEnhancer<Options extends object, Api>(el: Ref<HTMLElement | null>, enhancer: (container: HTMLElement, options?: Partial<Options>) => EnhancerHandle<Api>, options?: MaybeRefOrGetter<Partial<Options>>, deps?: WatchSource<unknown>): ShallowRef<Api | null>;
18
+ declare function useEnhancer<Options extends object, Api>(el: Ref<HTMLElement | null>, enhancer: (container: HTMLElement, options?: Partial<Options>) => EnhancerHandle<Api, Options>, options?: MaybeRefOrGetter<Partial<Options>>, deps?: WatchSource<unknown>): ShallowRef<Api | null>;
29
19
 
30
20
  /**
31
21
  * Imperative toast API: `show(message, { duration, intent })`,
@@ -1539,6 +1529,78 @@ declare const Drawer: vue.DefineComponent<vue.ExtractPropTypes<{
1539
1529
  readonly closeOnBackdrop: boolean;
1540
1530
  readonly side: "start" | "end";
1541
1531
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1532
+ declare const dialogTriggerProps: {
1533
+ /** Id of the `<dialog>` this button invokes (`commandfor`). */
1534
+ readonly target: {
1535
+ readonly type: StringConstructor;
1536
+ readonly required: true;
1537
+ };
1538
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
1539
+ readonly command: {
1540
+ readonly type: PropType<"show-modal" | "close">;
1541
+ readonly default: "show-modal";
1542
+ };
1543
+ };
1544
+ /** Props for {@link ModalTrigger}. */
1545
+ type ModalTriggerProps = ExtractPublicPropTypes<typeof dialogTriggerProps>;
1546
+ /** Props for {@link DrawerTrigger}. */
1547
+ type DrawerTriggerProps = ExtractPublicPropTypes<typeof dialogTriggerProps>;
1548
+ /** Declarative invoker button for a {@link Modal} (`command` + `commandfor`). */
1549
+ declare const ModalTrigger: vue.DefineComponent<vue.ExtractPropTypes<{
1550
+ /** Id of the `<dialog>` this button invokes (`commandfor`). */
1551
+ readonly target: {
1552
+ readonly type: StringConstructor;
1553
+ readonly required: true;
1554
+ };
1555
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
1556
+ readonly command: {
1557
+ readonly type: PropType<"show-modal" | "close">;
1558
+ readonly default: "show-modal";
1559
+ };
1560
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
1561
+ [key: string]: any;
1562
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1563
+ /** Id of the `<dialog>` this button invokes (`commandfor`). */
1564
+ readonly target: {
1565
+ readonly type: StringConstructor;
1566
+ readonly required: true;
1567
+ };
1568
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
1569
+ readonly command: {
1570
+ readonly type: PropType<"show-modal" | "close">;
1571
+ readonly default: "show-modal";
1572
+ };
1573
+ }>> & Readonly<{}>, {
1574
+ readonly command: "close" | "show-modal";
1575
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1576
+ /** Declarative invoker button for a {@link Drawer} (`command` + `commandfor`). */
1577
+ declare const DrawerTrigger: vue.DefineComponent<vue.ExtractPropTypes<{
1578
+ /** Id of the `<dialog>` this button invokes (`commandfor`). */
1579
+ readonly target: {
1580
+ readonly type: StringConstructor;
1581
+ readonly required: true;
1582
+ };
1583
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
1584
+ readonly command: {
1585
+ readonly type: PropType<"show-modal" | "close">;
1586
+ readonly default: "show-modal";
1587
+ };
1588
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
1589
+ [key: string]: any;
1590
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1591
+ /** Id of the `<dialog>` this button invokes (`commandfor`). */
1592
+ readonly target: {
1593
+ readonly type: StringConstructor;
1594
+ readonly required: true;
1595
+ };
1596
+ /** Invoker command to dispatch. Defaults to `'show-modal'`. */
1597
+ readonly command: {
1598
+ readonly type: PropType<"show-modal" | "close">;
1599
+ readonly default: "show-modal";
1600
+ };
1601
+ }>> & Readonly<{}>, {
1602
+ readonly command: "close" | "show-modal";
1603
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1542
1604
  /** Props for {@link ModalHeader}. */
1543
1605
  type ModalHeaderProps = Record<never, never>;
1544
1606
  /** Props for {@link ModalBody}. */
@@ -1655,6 +1717,48 @@ declare const Popover: vue.DefineComponent<vue.ExtractPropTypes<{
1655
1717
  readonly placement: _hydrateless_enhancers.Placement | undefined;
1656
1718
  readonly hover: boolean;
1657
1719
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1720
+ declare const popoverTriggerProps: {
1721
+ /** Id of the `<Popover>` surface this button invokes (`popovertarget`). */
1722
+ readonly target: {
1723
+ readonly type: StringConstructor;
1724
+ readonly required: true;
1725
+ };
1726
+ /** Popover action to perform. Defaults to `'toggle'`. */
1727
+ readonly action: {
1728
+ readonly type: PropType<"toggle" | "show" | "hide">;
1729
+ readonly default: "toggle";
1730
+ };
1731
+ };
1732
+ /** Props for {@link PopoverTrigger}. */
1733
+ type PopoverTriggerProps = ExtractPublicPropTypes<typeof popoverTriggerProps>;
1734
+ /** Declarative invoker button for a {@link Popover} (`popovertarget`). */
1735
+ declare const PopoverTrigger: vue.DefineComponent<vue.ExtractPropTypes<{
1736
+ /** Id of the `<Popover>` surface this button invokes (`popovertarget`). */
1737
+ readonly target: {
1738
+ readonly type: StringConstructor;
1739
+ readonly required: true;
1740
+ };
1741
+ /** Popover action to perform. Defaults to `'toggle'`. */
1742
+ readonly action: {
1743
+ readonly type: PropType<"toggle" | "show" | "hide">;
1744
+ readonly default: "toggle";
1745
+ };
1746
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
1747
+ [key: string]: any;
1748
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1749
+ /** Id of the `<Popover>` surface this button invokes (`popovertarget`). */
1750
+ readonly target: {
1751
+ readonly type: StringConstructor;
1752
+ readonly required: true;
1753
+ };
1754
+ /** Popover action to perform. Defaults to `'toggle'`. */
1755
+ readonly action: {
1756
+ readonly type: PropType<"toggle" | "show" | "hide">;
1757
+ readonly default: "toggle";
1758
+ };
1759
+ }>> & Readonly<{}>, {
1760
+ readonly action: "toggle" | "show" | "hide";
1761
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1658
1762
  declare const tooltipProps: {
1659
1763
  /** Hint text; the `content` slot takes precedence. */
1660
1764
  readonly content: {
@@ -2021,7 +2125,7 @@ declare const Command: vue.DefineComponent<vue.ExtractPropTypes<{
2021
2125
  };
2022
2126
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
2023
2127
  [key: string]: any;
2024
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("update:query" | "command")[], "update:query" | "command", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
2128
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("command" | "update:query")[], "command" | "update:query", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
2025
2129
  /** Lowercased key that, with Cmd/Ctrl, opens the hosting `<dialog>`. */
2026
2130
  readonly hotkey: {
2027
2131
  readonly type: StringConstructor;
@@ -2038,8 +2142,8 @@ declare const Command: vue.DefineComponent<vue.ExtractPropTypes<{
2038
2142
  readonly default: undefined;
2039
2143
  };
2040
2144
  }>> & Readonly<{
2041
- "onUpdate:query"?: ((...args: any[]) => any) | undefined;
2042
2145
  onCommand?: ((...args: any[]) => any) | undefined;
2146
+ "onUpdate:query"?: ((...args: any[]) => any) | undefined;
2043
2147
  }>, {
2044
2148
  readonly hotkey: string;
2045
2149
  readonly query: string;
@@ -2932,4 +3036,4 @@ declare const SkipLink: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode
2932
3036
  [key: string]: any;
2933
3037
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
2934
3038
 
2935
- export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, Alert, type AlertProps, Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, Breadcrumb, BreadcrumbItem, type BreadcrumbItemProps, type BreadcrumbProps, Button, type ButtonProps, Card, CardBody, type CardBodyProps, CardDescription, type CardDescriptionProps, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, type CardTitleProps, Checkbox, type CheckboxProps, Combobox, ComboboxInput, type ComboboxInputProps, ComboboxList, type ComboboxListProps, ComboboxOption, type ComboboxOptionProps, type ComboboxProps, Command, CommandEmpty, type CommandEmptyProps, CommandGroup, type CommandGroupProps, CommandInput, type CommandInputProps, CommandItem, type CommandItemProps, CommandList, type CommandListProps, type CommandProps, Disclosure, type DisclosureProps, Drawer, DrawerBody, type DrawerBodyProps, DrawerFooter, type DrawerFooterProps, DrawerHeader, type DrawerHeaderProps, type DrawerProps, Dropdown, DropdownGroup, type DropdownGroupProps, DropdownItem, type DropdownItemProps, DropdownMenu, type DropdownMenuProps, type DropdownProps, DropdownSeparator, type DropdownSeparatorProps, DropdownTrigger, type DropdownTriggerProps, Field, type FieldBindings, FieldError, type FieldErrorProps, FieldHelp, type FieldHelpProps, FieldLabel, type FieldLabelProps, type FieldProps, Fieldset, type FieldsetProps, Input, type InputProps, Kbd, type KbdProps, Menu, MenuItem, type MenuItemProps, type MenuProps, MenuSubmenu, type MenuSubmenuProps, Modal, ModalBody, type ModalBodyProps, ModalFooter, type ModalFooterProps, ModalHeader, type ModalHeaderProps, type ModalProps, Pagination, type PaginationProps, Popover, type PopoverProps, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, Select, type SelectProps, Separator, type SeparatorProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, Slider, type SliderProps, Spinner, type SpinnerProps, Switch, type SwitchProps, Tab, TabList, type TabListProps, TabPanel, type TabPanelProps, type TabProps, Table, type TableProps, Tabs, type TabsProps, Textarea, type TextareaProps, ToastRegion, type ToastRegionProps, Toc, type TocProps, Tooltip, type TooltipProps, useEnhancer, useField, useToast };
3039
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, Alert, type AlertProps, Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, Breadcrumb, BreadcrumbItem, type BreadcrumbItemProps, type BreadcrumbProps, Button, type ButtonProps, Card, CardBody, type CardBodyProps, CardDescription, type CardDescriptionProps, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, type CardTitleProps, Checkbox, type CheckboxProps, Combobox, ComboboxInput, type ComboboxInputProps, ComboboxList, type ComboboxListProps, ComboboxOption, type ComboboxOptionProps, type ComboboxProps, Command, CommandEmpty, type CommandEmptyProps, CommandGroup, type CommandGroupProps, CommandInput, type CommandInputProps, CommandItem, type CommandItemProps, CommandList, type CommandListProps, type CommandProps, Disclosure, type DisclosureProps, Drawer, DrawerBody, type DrawerBodyProps, DrawerFooter, type DrawerFooterProps, DrawerHeader, type DrawerHeaderProps, type DrawerProps, DrawerTrigger, type DrawerTriggerProps, Dropdown, DropdownGroup, type DropdownGroupProps, DropdownItem, type DropdownItemProps, DropdownMenu, type DropdownMenuProps, type DropdownProps, DropdownSeparator, type DropdownSeparatorProps, DropdownTrigger, type DropdownTriggerProps, Field, type FieldBindings, FieldError, type FieldErrorProps, FieldHelp, type FieldHelpProps, FieldLabel, type FieldLabelProps, type FieldProps, Fieldset, type FieldsetProps, Input, type InputProps, Kbd, type KbdProps, Menu, MenuItem, type MenuItemProps, type MenuProps, MenuSubmenu, type MenuSubmenuProps, Modal, ModalBody, type ModalBodyProps, ModalFooter, type ModalFooterProps, ModalHeader, type ModalHeaderProps, type ModalProps, ModalTrigger, type ModalTriggerProps, Pagination, type PaginationProps, Popover, type PopoverProps, PopoverTrigger, type PopoverTriggerProps, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, Select, type SelectProps, Separator, type SeparatorProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, Slider, type SliderProps, Spinner, type SpinnerProps, Switch, type SwitchProps, Tab, TabList, type TabListProps, TabPanel, type TabPanelProps, type TabProps, Table, type TableProps, Tabs, type TabsProps, Textarea, type TextareaProps, ToastRegion, type ToastRegionProps, Toc, type TocProps, Tooltip, type TooltipProps, useEnhancer, useField, useToast };
package/dist/index.js CHANGED
@@ -3,23 +3,23 @@ import { enhanceAccordion, enhanceDisclosure, enhanceTabs, enhanceDropdown, enha
3
3
 
4
4
  function useEnhancer(el, enhancer, options, deps) {
5
5
  const api = shallowRef(null);
6
- let destroy = null;
6
+ let handle = null;
7
7
  const detach = () => {
8
- destroy?.();
9
- destroy = null;
8
+ handle?.destroy();
9
+ handle = null;
10
10
  api.value = null;
11
11
  };
12
12
  const attach = () => {
13
13
  detach();
14
14
  if (!el.value)
15
15
  return;
16
- const handle = enhancer(el.value, toValue(options));
16
+ handle = enhancer(el.value, toValue(options));
17
17
  api.value = handle.api;
18
- destroy = handle.destroy;
19
18
  };
20
19
  onMounted(attach);
21
- if (deps)
22
- watch(deps, attach);
20
+ if (deps) {
21
+ watch(deps, () => handle ? handle.update(toValue(options)) : attach(), { flush: "post" });
22
+ }
23
23
  onBeforeUnmount(detach);
24
24
  return api;
25
25
  }
@@ -46,15 +46,19 @@ function part(name, tag, klass) {
46
46
  function useControlled(props, emit, { prop, event, default: fallback }) {
47
47
  const controlled = () => props[prop];
48
48
  const internal = shallowRef(controlled() ?? fallback);
49
+ const tick = ref(0);
49
50
  const value = computed(() => {
50
51
  const outer = controlled();
51
52
  return outer === void 0 ? internal.value : outer;
52
53
  });
53
54
  const set = (next) => {
54
- internal.value = next;
55
+ if (controlled() !== void 0)
56
+ tick.value += 1;
57
+ else
58
+ internal.value = next;
55
59
  emit(event, next);
56
60
  };
57
- return { value, set };
61
+ return { value, set, tick };
58
62
  }
59
63
  var DOCUMENT_POSITION_FOLLOWING = 4;
60
64
  function byDocumentOrder(a, b) {
@@ -98,13 +102,15 @@ function same(a, b) {
98
102
  }
99
103
  return a === b;
100
104
  }
101
- function useApiSync(api, source, read, write) {
102
- watch(source, (value) => {
105
+ function useApiSync(api, source, read, write, tick) {
106
+ const sync = () => {
103
107
  const current = api.value;
104
- if (current && value !== void 0 && !same(read(current), value)) {
108
+ const value = source.value;
109
+ if (current && value !== void 0 && (!read || !same(read(current), value))) {
105
110
  write(current, value);
106
111
  }
107
- });
112
+ };
113
+ watch(tick ? [source, tick] : source, sync);
108
114
  }
109
115
  var FieldKey = Symbol("hl-field");
110
116
  var fieldProps = {
@@ -310,7 +316,7 @@ function checkable(name, wrapper, role) {
310
316
  });
311
317
  }
312
318
  var Checkbox = checkable("HlCheckbox", { class: "hl-checkbox" });
313
- var Switch = checkable("HlSwitch", { "data-hl-switch": "" }, "switch");
319
+ var Switch = checkable("HlSwitch", { class: "hl-switch" }, "switch");
314
320
  var sliderProps = {
315
321
  modelValue: { type: [String, Number], default: void 0 }
316
322
  };
@@ -444,7 +450,7 @@ var Accordion = defineComponent({
444
450
  emits: ["update:modelValue"],
445
451
  setup(props, { slots, attrs, emit }) {
446
452
  const host = ref(null);
447
- const { value, set } = useControlled(props, emit, {
453
+ const { value, set, tick } = useControlled(props, emit, {
448
454
  prop: "modelValue",
449
455
  event: "update:modelValue",
450
456
  default: props.defaultValue
@@ -454,10 +460,15 @@ var Accordion = defineComponent({
454
460
  defaultValue: value.value,
455
461
  onValueChange: set
456
462
  }), () => props.allowMultiple);
457
- useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v));
463
+ useApiSync(api, value, null, (a, v) => a.setValue(v, { silent: true }), tick);
458
464
  const items = createRegistry();
459
465
  provide(AccordionKey, { value, register: () => items.register() });
460
- return () => h("div", { ...attrs, "data-hl-accordion": "", ref: host }, slots.default?.());
466
+ return () => h("div", {
467
+ ...attrs,
468
+ class: cx("hl-accordion", attrs.class),
469
+ "data-hl-accordion": "",
470
+ ref: host
471
+ }, slots.default?.());
461
472
  }
462
473
  });
463
474
  var accordionItemProps = {
@@ -492,7 +503,7 @@ var Disclosure = defineComponent({
492
503
  emits: ["update:open"],
493
504
  setup(props, { slots, attrs, emit }) {
494
505
  const host = ref(null);
495
- const { value: open, set } = useControlled(props, emit, {
506
+ const { value: open, set, tick } = useControlled(props, emit, {
496
507
  prop: "open",
497
508
  event: "update:open",
498
509
  default: props.defaultOpen
@@ -501,7 +512,7 @@ var Disclosure = defineComponent({
501
512
  defaultOpen: open.value,
502
513
  onOpenChange: set
503
514
  }));
504
- useApiSync(api, open, (a) => a.open, (a, v) => a.setOpen(v));
515
+ useApiSync(api, open, null, (a, v) => a.setOpen(v, { silent: true }), tick);
505
516
  return () => h("details", {
506
517
  ...attrs,
507
518
  class: cx("hl-disclosure", attrs.class),
@@ -529,7 +540,7 @@ var Tabs = defineComponent({
529
540
  emits: ["update:modelValue"],
530
541
  setup(props, { slots, attrs, emit }) {
531
542
  const host = ref(null);
532
- const { value, set } = useControlled(props, emit, {
543
+ const { value, set, tick } = useControlled(props, emit, {
533
544
  prop: "modelValue",
534
545
  event: "update:modelValue",
535
546
  default: props.defaultValue
@@ -540,7 +551,7 @@ var Tabs = defineComponent({
540
551
  defaultValue: value.value,
541
552
  onValueChange: set
542
553
  }), () => [props.activation, props.orientation]);
543
- useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v));
554
+ useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v, { silent: true }), tick);
544
555
  const tabs = createRegistry();
545
556
  const panels = createRegistry();
546
557
  const values = computed(() => tabs.entries.value.map((get, i) => get() ?? String(i)));
@@ -551,7 +562,7 @@ var Tabs = defineComponent({
551
562
  tab: (getValue) => tabs.register(getValue),
552
563
  panel: () => panels.register()
553
564
  });
554
- return () => h("div", { ...attrs, "data-hl-tabs": "", ref: host }, slots.default?.());
565
+ return () => h("div", { ...attrs, class: cx("hl-tabs", attrs.class), "data-hl-tabs": "", ref: host }, slots.default?.());
555
566
  }
556
567
  });
557
568
  var TabList = defineComponent({
@@ -623,7 +634,7 @@ var Dropdown = defineComponent({
623
634
  emits: ["update:open", "select"],
624
635
  setup(props, { slots, attrs, emit }) {
625
636
  const host = ref(null);
626
- const { value: open, set } = useControlled(props, emit, {
637
+ const { value: open, set, tick } = useControlled(props, emit, {
627
638
  prop: "open",
628
639
  event: "update:open",
629
640
  default: props.defaultOpen
@@ -635,9 +646,14 @@ var Dropdown = defineComponent({
635
646
  onOpenChange: set,
636
647
  onSelect: (value, item, checked) => emit("select", value, item, checked)
637
648
  }), () => [props.placement, props.closeOnSelect]);
638
- useApiSync(api, open, (a) => a.open, (a, v) => a.setOpen(v));
649
+ useApiSync(api, open, (a) => a.open, (a, v) => a.setOpen(v, { silent: true }), tick);
639
650
  provide(DropdownKey, { menuId: useId(), open });
640
- return () => h("div", { ...attrs, "data-hl-dropdown": "", ref: host }, slots.default?.());
651
+ return () => h("div", {
652
+ ...attrs,
653
+ class: cx("hl-dropdown", attrs.class),
654
+ "data-hl-dropdown": "",
655
+ ref: host
656
+ }, slots.default?.());
641
657
  }
642
658
  });
643
659
  var DropdownTrigger = defineComponent({
@@ -660,7 +676,14 @@ var DropdownMenu = defineComponent({
660
676
  inheritAttrs: false,
661
677
  setup(_, { slots, attrs }) {
662
678
  const ctx = inject(DropdownKey, null);
663
- return () => h("ul", { ...attrs, id: ctx?.menuId, popover: "auto", role: "menu", "data-hl-dropdown-menu": "" }, slots.default?.());
679
+ return () => h("ul", {
680
+ ...attrs,
681
+ id: ctx?.menuId,
682
+ class: cx("hl-dropdown-menu", attrs.class),
683
+ popover: "auto",
684
+ role: "menu",
685
+ "data-hl-dropdown-menu": ""
686
+ }, slots.default?.());
664
687
  }
665
688
  });
666
689
  var dropdownItemProps = {
@@ -738,18 +761,19 @@ var Menu = defineComponent({
738
761
  emits: ["update:modelValue", "select"],
739
762
  setup(props, { slots, attrs, emit }) {
740
763
  const host = ref(null);
741
- const { value, set } = useControlled(props, emit, { prop: "modelValue", event: "update:modelValue", default: props.defaultValue });
764
+ const { value, set, tick } = useControlled(props, emit, { prop: "modelValue", event: "update:modelValue", default: props.defaultValue });
742
765
  const api = useEnhancer(host, enhanceMenu, () => ({
743
766
  orientation: props.orientation,
744
767
  defaultValue: value.value,
745
768
  onValueChange: set,
746
769
  onSelect: (v, item, checked) => emit("select", v, item, checked)
747
770
  }), () => props.orientation);
748
- useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v));
771
+ useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v, { silent: true }), tick);
749
772
  let count = 0;
750
773
  provide(MenuKey, { register: () => count++ });
751
774
  return () => h("ul", {
752
775
  ...attrs,
776
+ class: cx("hl-menu", attrs.class),
753
777
  "data-hl-menu": "",
754
778
  role: props.orientation === "vertical" ? "menu" : "menubar",
755
779
  "aria-orientation": props.orientation,
@@ -825,7 +849,7 @@ function useOpen(props, emit, attach) {
825
849
  default: props.defaultOpen ?? false
826
850
  });
827
851
  const api = attach(open);
828
- useApiSync(api, open.value, (a) => a.open, (a, v) => a.setOpen(v));
852
+ useApiSync(api, open.value, (a) => a.open, (a, v) => a.setOpen(v, { silent: true }), open.tick);
829
853
  return open.value;
830
854
  }
831
855
  function useDialog(host, enhance, props, emit) {
@@ -876,6 +900,22 @@ var Drawer = defineComponent({
876
900
  }, slots.default?.());
877
901
  }
878
902
  });
903
+ var dialogTriggerProps = {
904
+ target: { type: String, required: true },
905
+ command: { type: String, default: "show-modal" }
906
+ };
907
+ function dialogTrigger(name) {
908
+ return defineComponent({
909
+ name,
910
+ inheritAttrs: false,
911
+ props: dialogTriggerProps,
912
+ setup(props, { slots, attrs }) {
913
+ return () => h("button", { type: "button", ...attrs, command: props.command, commandfor: props.target }, slots.default?.());
914
+ }
915
+ });
916
+ }
917
+ var ModalTrigger = dialogTrigger("HlModalTrigger");
918
+ var DrawerTrigger = dialogTrigger("HlDrawerTrigger");
879
919
  var section = (name, klass) => part(name, "div", klass);
880
920
  var ModalHeader = section("HlModalHeader", "hl-modal-header");
881
921
  var ModalBody = section("HlModalBody", "hl-modal-body");
@@ -901,7 +941,31 @@ var Popover = defineComponent({
901
941
  defaultOpen: open.value.value,
902
942
  onOpenChange: open.set
903
943
  }), () => [props.placement, props.hover]));
904
- return () => h("div", { ...attrs, "data-hl-popover": "", popover: "auto", role: "dialog", ref: host }, slots.default?.());
944
+ return () => h("div", {
945
+ ...attrs,
946
+ class: cx("hl-popover", attrs.class),
947
+ "data-hl-popover": "",
948
+ popover: "auto",
949
+ role: "dialog",
950
+ ref: host
951
+ }, slots.default?.());
952
+ }
953
+ });
954
+ var popoverTriggerProps = {
955
+ target: { type: String, required: true },
956
+ action: { type: String, default: "toggle" }
957
+ };
958
+ var PopoverTrigger = defineComponent({
959
+ name: "HlPopoverTrigger",
960
+ inheritAttrs: false,
961
+ props: popoverTriggerProps,
962
+ setup(props, { slots, attrs }) {
963
+ return () => h("button", {
964
+ type: "button",
965
+ ...attrs,
966
+ popovertarget: props.target,
967
+ popovertargetaction: props.action === "toggle" ? void 0 : props.action
968
+ }, slots.default?.());
905
969
  }
906
970
  });
907
971
  var tooltipProps = {
@@ -929,7 +993,7 @@ var Tooltip = defineComponent({
929
993
  const [trigger] = slots.default?.() ?? [];
930
994
  return h("span", { ...attrs, ref: host }, [
931
995
  trigger && cloneVNode(trigger, { "data-hl-tooltip": tipId, "aria-describedby": tipId }),
932
- h("span", { id: tipId, role: "tooltip" }, slots.content?.() ?? props.content)
996
+ h("span", { id: tipId, class: "hl-tooltip", role: "tooltip" }, slots.content?.() ?? props.content)
933
997
  ]);
934
998
  };
935
999
  }
@@ -938,9 +1002,11 @@ var Breadcrumb = defineComponent({
938
1002
  name: "HlBreadcrumb",
939
1003
  inheritAttrs: false,
940
1004
  setup(_, { slots, attrs }) {
941
- return () => h("nav", { "aria-label": "Breadcrumb", ...attrs, "data-hl-breadcrumb": "" }, [
942
- h("ol", slots.default?.())
943
- ]);
1005
+ return () => h("nav", {
1006
+ "aria-label": "Breadcrumb",
1007
+ ...attrs,
1008
+ class: cx("hl-breadcrumb", attrs.class)
1009
+ }, [h("ol", slots.default?.())]);
944
1010
  }
945
1011
  });
946
1012
  var breadcrumbItemProps = {
@@ -975,22 +1041,32 @@ var Combobox = defineComponent({
975
1041
  emits: ["update:modelValue", "update:open"],
976
1042
  setup(props, { slots, attrs, emit }) {
977
1043
  const host = ref(null);
978
- const { value, set } = useControlled(props, emit, {
1044
+ const { value, set, tick } = useControlled(props, emit, {
979
1045
  prop: "modelValue",
980
1046
  event: "update:modelValue",
981
1047
  default: props.defaultValue
982
1048
  });
983
- const { value: open, set: setOpen } = useControlled(props, emit, { prop: "open", event: "update:open", default: props.defaultOpen });
1049
+ const { value: open, set: setOpen, tick: openTick } = useControlled(props, emit, {
1050
+ prop: "open",
1051
+ event: "update:open",
1052
+ default: props.defaultOpen
1053
+ });
984
1054
  const api = useEnhancer(host, enhanceCombobox, () => ({
985
1055
  filter: props.filter,
986
1056
  autoHighlight: props.autoHighlight,
987
1057
  defaultValue: value.value,
1058
+ defaultOpen: open.value,
988
1059
  onValueChange: set,
989
1060
  onOpenChange: setOpen
990
1061
  }), () => [props.filter, props.autoHighlight]);
991
- useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v));
992
- useApiSync(api, open, (a) => a.open, (a, v) => a.setOpen(v));
993
- return () => h("div", { ...attrs, "data-hl-combobox": "", ref: host }, slots.default?.());
1062
+ useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v, { silent: true }), tick);
1063
+ useApiSync(api, open, (a) => a.open, (a, v) => a.setOpen(v, { silent: true }), openTick);
1064
+ return () => h("div", {
1065
+ ...attrs,
1066
+ class: cx("hl-combobox", attrs.class),
1067
+ "data-hl-combobox": "",
1068
+ ref: host
1069
+ }, slots.default?.());
994
1070
  }
995
1071
  });
996
1072
  var comboboxInputProps = {
@@ -1048,7 +1124,7 @@ var Command = defineComponent({
1048
1124
  emits: ["update:query", "command"],
1049
1125
  setup(props, { slots, attrs, emit }) {
1050
1126
  const host = ref(null);
1051
- const { value: query, set } = useControlled(props, emit, {
1127
+ const { value: query, set, tick } = useControlled(props, emit, {
1052
1128
  prop: "query",
1053
1129
  event: "update:query",
1054
1130
  default: props.defaultQuery
@@ -1059,8 +1135,14 @@ var Command = defineComponent({
1059
1135
  onValueChange: set,
1060
1136
  onCommand: (value, item) => emit("command", value, item)
1061
1137
  }), () => props.hotkey);
1062
- useApiSync(api, query, (a) => a.value, (a, v) => a.setValue(v));
1063
- return () => h("div", { ...attrs, "data-hl-command": "", "data-hl-hotkey": props.hotkey, ref: host }, slots.default?.());
1138
+ useApiSync(api, query, (a) => a.value, (a, v) => a.setValue(v, { silent: true }), tick);
1139
+ return () => h("div", {
1140
+ ...attrs,
1141
+ class: cx("hl-command", attrs.class),
1142
+ "data-hl-command": "",
1143
+ "data-hl-hotkey": props.hotkey,
1144
+ ref: host
1145
+ }, slots.default?.());
1064
1146
  }
1065
1147
  });
1066
1148
  var commandInputProps = {
@@ -1073,7 +1155,7 @@ var CommandInput = defineComponent({
1073
1155
  setup(props, { attrs }) {
1074
1156
  return () => h("input", {
1075
1157
  ...attrs,
1076
- class: cx(props.styled && "hl-input", attrs.class),
1158
+ class: cx(props.styled && "hl-command-input", attrs.class),
1077
1159
  "data-hl-command-input": ""
1078
1160
  });
1079
1161
  }
@@ -1082,7 +1164,12 @@ var CommandList = defineComponent({
1082
1164
  name: "HlCommandList",
1083
1165
  inheritAttrs: false,
1084
1166
  setup(_, { slots, attrs }) {
1085
- return () => h("div", { ...attrs, "data-hl-command-list": "", role: "listbox" }, slots.default?.());
1167
+ return () => h("div", {
1168
+ ...attrs,
1169
+ class: cx("hl-command-list", attrs.class),
1170
+ "data-hl-command-list": "",
1171
+ role: "listbox"
1172
+ }, slots.default?.());
1086
1173
  }
1087
1174
  });
1088
1175
  var commandGroupProps = {
@@ -1095,7 +1182,11 @@ var CommandGroup = defineComponent({
1095
1182
  setup(props, { slots, attrs }) {
1096
1183
  return () => {
1097
1184
  const label = slots.label?.() ?? props.label;
1098
- return h("div", { ...attrs, "data-hl-command-group": "" }, [
1185
+ return h("div", {
1186
+ ...attrs,
1187
+ class: cx("hl-command-group", attrs.class),
1188
+ "data-hl-command-group": ""
1189
+ }, [
1099
1190
  label ? h("div", { class: "hl-command-group-label", role: "presentation" }, label) : null,
1100
1191
  slots.default?.()
1101
1192
  ]);
@@ -1123,7 +1214,12 @@ var CommandEmpty = defineComponent({
1123
1214
  name: "HlCommandEmpty",
1124
1215
  inheritAttrs: false,
1125
1216
  setup(_, { slots, attrs }) {
1126
- return () => h("div", { ...attrs, "data-hl-command-empty": "", hidden: true }, slots.default?.() ?? "No results found.");
1217
+ return () => h("div", {
1218
+ ...attrs,
1219
+ class: cx("hl-command-empty", attrs.class),
1220
+ "data-hl-command-empty": "",
1221
+ hidden: true
1222
+ }, slots.default?.() ?? "No results found.");
1127
1223
  }
1128
1224
  });
1129
1225
  var buttonProps = {
@@ -1279,6 +1375,7 @@ var ToastRegion = defineComponent({
1279
1375
  "aria-live": "polite",
1280
1376
  "aria-relevant": "additions",
1281
1377
  ...attrs,
1378
+ class: cx("hl-toast-region", attrs.class),
1282
1379
  "data-hl-toast-region": "",
1283
1380
  ref: host
1284
1381
  });
@@ -1464,7 +1561,13 @@ var Toc = defineComponent({
1464
1561
  headings: props.headings,
1465
1562
  scrollSpy: props.scrollSpy
1466
1563
  }), () => [props.contentSelector, props.headings, props.scrollSpy]);
1467
- return () => h("nav", { "aria-label": "Table of contents", ...attrs, "data-hl-toc": "", ref: host }, slots.default?.());
1564
+ return () => h("nav", {
1565
+ "aria-label": "Table of contents",
1566
+ ...attrs,
1567
+ class: cx("hl-toc", attrs.class),
1568
+ "data-hl-toc": "",
1569
+ ref: host
1570
+ }, slots.default?.());
1468
1571
  }
1469
1572
  });
1470
1573
  var SkipLink = defineComponent({
@@ -1475,4 +1578,4 @@ var SkipLink = defineComponent({
1475
1578
  }
1476
1579
  });
1477
1580
 
1478
- export { Accordion, AccordionItem, Alert, Avatar, AvatarGroup, Badge, Breadcrumb, BreadcrumbItem, Button, Card, CardBody, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Combobox, ComboboxInput, ComboboxList, ComboboxOption, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Disclosure, Drawer, DrawerBody, DrawerFooter, DrawerHeader, Dropdown, DropdownGroup, DropdownItem, DropdownMenu, DropdownSeparator, DropdownTrigger, Field, FieldError, FieldHelp, FieldLabel, Fieldset, Input, Kbd, Menu, MenuItem, MenuSubmenu, Modal, ModalBody, ModalFooter, ModalHeader, Pagination, Popover, Progress, Radio, RadioGroup, SegmentedControl, Select, Separator, Skeleton, SkipLink, Slider, Spinner, Switch, Tab, TabList, TabPanel, Table, Tabs, Textarea, ToastRegion, Toc, Tooltip, useEnhancer, useField, useToast };
1581
+ export { Accordion, AccordionItem, Alert, Avatar, AvatarGroup, Badge, Breadcrumb, BreadcrumbItem, Button, Card, CardBody, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Combobox, ComboboxInput, ComboboxList, ComboboxOption, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Disclosure, Drawer, DrawerBody, DrawerFooter, DrawerHeader, DrawerTrigger, Dropdown, DropdownGroup, DropdownItem, DropdownMenu, DropdownSeparator, DropdownTrigger, Field, FieldError, FieldHelp, FieldLabel, Fieldset, Input, Kbd, Menu, MenuItem, MenuSubmenu, Modal, ModalBody, ModalFooter, ModalHeader, ModalTrigger, Pagination, Popover, PopoverTrigger, Progress, Radio, RadioGroup, SegmentedControl, Select, Separator, Skeleton, SkipLink, Slider, Spinner, Switch, Tab, TabList, TabPanel, Table, Tabs, Textarea, ToastRegion, Toc, Tooltip, useEnhancer, useField, useToast };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydrateless/vue",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Vue 3 bindings for Hydrateless: first-class components plus the useEnhancer, useField, and useToast composables.",
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.10.1"
31
+ "@hydrateless/enhancers": "^0.11.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "vue": ">=3.5"