@hydrateless/vue 0.9.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.
package/dist/index.d.ts CHANGED
@@ -28,8 +28,8 @@ export { AccordionApi, ComboboxApi, CommandApi, DisclosureApi, Disposer, DrawerA
28
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>;
29
29
 
30
30
  /**
31
- * Imperative toast API: `show(message, { duration, intent })` and
32
- * `dismiss(toast)`. Toasts render into the page's `[data-hl-toast-region]`
31
+ * Imperative toast API: `show(message, { duration, intent })`,
32
+ * `dismiss(toast)`, and `dismissAll()`. Toasts render into the page's `[data-hl-toast-region]`
33
33
  * (mount a `<ToastRegion>` once near the app root) or into a region created
34
34
  * on demand, so no provider is required and it's safe to call from any
35
35
  * component.
@@ -736,6 +736,14 @@ declare const disclosureProps: {
736
736
  readonly type: BooleanConstructor;
737
737
  readonly default: false;
738
738
  };
739
+ /**
740
+ * Native `<details name>`: disclosures sharing a name form an exclusive
741
+ * group, so opening one closes the rest with no JavaScript involved.
742
+ */
743
+ readonly name: {
744
+ readonly type: StringConstructor;
745
+ readonly default: undefined;
746
+ };
739
747
  /** Header text; the `summary` slot takes precedence. */
740
748
  readonly title: {
741
749
  readonly type: StringConstructor;
@@ -760,6 +768,14 @@ declare const Disclosure: vue.DefineComponent<vue.ExtractPropTypes<{
760
768
  readonly type: BooleanConstructor;
761
769
  readonly default: false;
762
770
  };
771
+ /**
772
+ * Native `<details name>`: disclosures sharing a name form an exclusive
773
+ * group, so opening one closes the rest with no JavaScript involved.
774
+ */
775
+ readonly name: {
776
+ readonly type: StringConstructor;
777
+ readonly default: undefined;
778
+ };
763
779
  /** Header text; the `summary` slot takes precedence. */
764
780
  readonly title: {
765
781
  readonly type: StringConstructor;
@@ -778,6 +794,14 @@ declare const Disclosure: vue.DefineComponent<vue.ExtractPropTypes<{
778
794
  readonly type: BooleanConstructor;
779
795
  readonly default: false;
780
796
  };
797
+ /**
798
+ * Native `<details name>`: disclosures sharing a name form an exclusive
799
+ * group, so opening one closes the rest with no JavaScript involved.
800
+ */
801
+ readonly name: {
802
+ readonly type: StringConstructor;
803
+ readonly default: undefined;
804
+ };
781
805
  /** Header text; the `summary` slot takes precedence. */
782
806
  readonly title: {
783
807
  readonly type: StringConstructor;
@@ -786,6 +810,7 @@ declare const Disclosure: vue.DefineComponent<vue.ExtractPropTypes<{
786
810
  }>> & Readonly<{
787
811
  "onUpdate:open"?: ((...args: any[]) => any) | undefined;
788
812
  }>, {
813
+ readonly name: string;
789
814
  readonly title: string;
790
815
  readonly open: boolean | undefined;
791
816
  readonly defaultOpen: boolean;
@@ -2743,7 +2768,7 @@ declare const Table: vue.DefineComponent<vue.ExtractPropTypes<{
2743
2768
  readonly size: "sm" | "md" | "lg";
2744
2769
  readonly hover: boolean;
2745
2770
  readonly striped: boolean;
2746
- readonly align: "start" | "center" | "end";
2771
+ readonly align: "start" | "end" | "center";
2747
2772
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
2748
2773
 
2749
2774
  declare const paginationProps: {
package/dist/index.js CHANGED
@@ -27,7 +27,8 @@ function useToast(options) {
27
27
  const api = () => enhanceToast(document, options).api;
28
28
  return {
29
29
  show: (message, opts) => api().show(message, opts),
30
- dismiss: (toast) => api()?.dismiss(toast)
30
+ dismiss: (toast) => api()?.dismiss(toast),
31
+ dismissAll: () => api()?.dismissAll()
31
32
  };
32
33
  }
33
34
  function cx(...classes) {
@@ -55,6 +56,42 @@ function useControlled(props, emit, { prop, event, default: fallback }) {
55
56
  };
56
57
  return { value, set };
57
58
  }
59
+ var DOCUMENT_POSITION_FOLLOWING = 4;
60
+ function byDocumentOrder(a, b) {
61
+ if (!a.node || !b.node || a.node === b.node)
62
+ return 0;
63
+ return a.node.compareDocumentPosition(b.node) & DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
64
+ }
65
+ function createRegistry() {
66
+ const items = shallowRef([]);
67
+ return {
68
+ entries: computed(() => items.value.map((item) => item.value)),
69
+ register(value) {
70
+ const entry = { value, node: null };
71
+ items.value = [...items.value, entry];
72
+ return {
73
+ get index() {
74
+ return items.value.indexOf(entry);
75
+ },
76
+ attach(node) {
77
+ if (entry.node === node)
78
+ return;
79
+ entry.node = node;
80
+ items.value = [...items.value].sort(byDocumentOrder);
81
+ },
82
+ unregister() {
83
+ items.value = items.value.filter((item) => item !== entry);
84
+ }
85
+ };
86
+ }
87
+ };
88
+ }
89
+ function useRegistration(registration) {
90
+ const node = ref(null);
91
+ onMounted(() => registration?.attach(node.value));
92
+ onBeforeUnmount(() => registration?.unregister());
93
+ return { node, index: computed(() => registration?.index ?? 0) };
94
+ }
58
95
  function same(a, b) {
59
96
  if (Array.isArray(a) && Array.isArray(b)) {
60
97
  return a.length === b.length && a.every((item, i) => item === b[i]);
@@ -418,8 +455,8 @@ var Accordion = defineComponent({
418
455
  onValueChange: set
419
456
  }), () => props.allowMultiple);
420
457
  useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v));
421
- let count = 0;
422
- provide(AccordionKey, { value, register: () => count++ });
458
+ const items = createRegistry();
459
+ provide(AccordionKey, { value, register: () => items.register() });
423
460
  return () => h("div", { ...attrs, "data-hl-accordion": "", ref: host }, slots.default?.());
424
461
  }
425
462
  });
@@ -433,9 +470,10 @@ var AccordionItem = defineComponent({
433
470
  props: accordionItemProps,
434
471
  setup(props, { slots, attrs }) {
435
472
  const ctx = inject(AccordionKey, null);
436
- const index = ctx?.register();
437
- const open = computed(() => ctx?.value.value?.includes(props.value ?? String(index)));
438
- return () => h("details", { ...attrs, "data-hl-value": props.value, open: open.value || void 0 }, [
473
+ const { node, index } = useRegistration(ctx?.register());
474
+ const value = computed(() => props.value ?? String(index.value));
475
+ const open = computed(() => ctx?.value.value?.includes(value.value));
476
+ return () => h("details", { ...attrs, ref: node, "data-hl-value": props.value, open: open.value || void 0 }, [
439
477
  h("summary", slots.summary?.() ?? props.title),
440
478
  h("div", { class: "hl-accordion-panel" }, slots.default?.())
441
479
  ]);
@@ -444,6 +482,7 @@ var AccordionItem = defineComponent({
444
482
  var disclosureProps = {
445
483
  open: { type: Boolean, default: void 0 },
446
484
  defaultOpen: { type: Boolean, default: false },
485
+ name: { type: String, default: void 0 },
447
486
  title: { type: String, default: void 0 }
448
487
  };
449
488
  var Disclosure = defineComponent({
@@ -467,6 +506,7 @@ var Disclosure = defineComponent({
467
506
  ...attrs,
468
507
  class: cx("hl-disclosure", attrs.class),
469
508
  "data-hl-disclosure": "",
509
+ name: props.name,
470
510
  open: open.value || void 0,
471
511
  ref: host
472
512
  }, [
@@ -501,14 +541,15 @@ var Tabs = defineComponent({
501
541
  onValueChange: set
502
542
  }), () => [props.activation, props.orientation]);
503
543
  useApiSync(api, value, (a) => a.value, (a, v) => a.setValue(v));
504
- const values = [];
505
- let panels = 0;
544
+ const tabs = createRegistry();
545
+ const panels = createRegistry();
546
+ const values = computed(() => tabs.entries.value.map((get, i) => get() ?? String(i)));
506
547
  provide(TabsKey, {
507
548
  id: useId(),
508
549
  value,
509
550
  values,
510
- tab: (v) => values.push(v ?? String(values.length)) - 1,
511
- panel: () => panels++
551
+ tab: (getValue) => tabs.register(getValue),
552
+ panel: () => panels.register()
512
553
  });
513
554
  return () => h("div", { ...attrs, "data-hl-tabs": "", ref: host }, slots.default?.());
514
555
  }
@@ -526,7 +567,7 @@ var tabProps = {
526
567
  };
527
568
  function isSelected(ctx, index) {
528
569
  const selected = ctx?.value.value;
529
- return selected === void 0 ? index === 0 : ctx.values.indexOf(selected) === index;
570
+ return selected === void 0 ? index === 0 : ctx.values.value.indexOf(selected) === index;
530
571
  }
531
572
  var Tab = defineComponent({
532
573
  name: "HlTab",
@@ -534,16 +575,17 @@ var Tab = defineComponent({
534
575
  props: tabProps,
535
576
  setup(props, { slots, attrs }) {
536
577
  const ctx = inject(TabsKey, null);
537
- const index = ctx?.tab(props.value) ?? 0;
538
- const selected = computed(() => isSelected(ctx, index));
578
+ const { node, index } = useRegistration(ctx?.tab(() => props.value));
579
+ const selected = computed(() => isSelected(ctx, index.value));
539
580
  return () => h("button", {
540
581
  type: "button",
541
582
  ...attrs,
542
- id: ctx && `${ctx.id}-t${index}`,
583
+ ref: node,
584
+ id: ctx && `${ctx.id}-t${index.value}`,
543
585
  role: "tab",
544
586
  "data-hl-value": props.value,
545
587
  "aria-selected": String(selected.value),
546
- "aria-controls": ctx && `${ctx.id}-p${index}`,
588
+ "aria-controls": ctx && `${ctx.id}-p${index.value}`,
547
589
  "aria-disabled": props.disabled || void 0,
548
590
  tabindex: selected.value ? 0 : -1
549
591
  }, slots.default?.());
@@ -554,13 +596,14 @@ var TabPanel = defineComponent({
554
596
  inheritAttrs: false,
555
597
  setup(_, { slots, attrs }) {
556
598
  const ctx = inject(TabsKey, null);
557
- const index = ctx?.panel() ?? 0;
558
- const selected = computed(() => isSelected(ctx, index));
599
+ const { node, index } = useRegistration(ctx?.panel());
600
+ const selected = computed(() => isSelected(ctx, index.value));
559
601
  return () => h("div", {
560
602
  ...attrs,
561
- id: ctx && `${ctx.id}-p${index}`,
603
+ ref: node,
604
+ id: ctx && `${ctx.id}-p${index.value}`,
562
605
  role: "tabpanel",
563
- "aria-labelledby": ctx && `${ctx.id}-t${index}`,
606
+ "aria-labelledby": ctx && `${ctx.id}-t${index.value}`,
564
607
  tabindex: 0,
565
608
  hidden: !selected.value
566
609
  }, slots.default?.());
@@ -650,7 +693,7 @@ var DropdownItem = defineComponent({
650
693
  const el = e.currentTarget;
651
694
  const value = props.value ?? el.textContent?.trim() ?? "";
652
695
  const checked = props.role === "menuitemcheckbox" ? el.getAttribute("aria-checked") !== "true" : props.role === "menuitemradio" || void 0;
653
- emit("select", value, checked);
696
+ emit("select", value, el, checked);
654
697
  }
655
698
  }, slots.default?.())
656
699
  ]);
@@ -767,7 +810,7 @@ var MenuSubmenu = defineComponent({
767
810
  "aria-disabled": props.disabled || void 0,
768
811
  disabled: props.disabled || void 0
769
812
  }, slots.trigger ? slots.trigger() : props.label),
770
- h("ul", { ...attrs, role: "menu", "data-hl-menu-submenu": "" }, slots.default?.())
813
+ h("ul", { ...attrs, role: "menu", "data-hl-submenu": "" }, slots.default?.())
771
814
  ]);
772
815
  }
773
816
  });
@@ -1017,7 +1060,7 @@ var Command = defineComponent({
1017
1060
  onCommand: (value, item) => emit("command", value, item)
1018
1061
  }), () => props.hotkey);
1019
1062
  useApiSync(api, query, (a) => a.value, (a, v) => a.setValue(v));
1020
- return () => h("div", { ...attrs, "data-hl-command": "", "data-hl-command-hotkey": props.hotkey, ref: host }, slots.default?.());
1063
+ return () => h("div", { ...attrs, "data-hl-command": "", "data-hl-hotkey": props.hotkey, ref: host }, slots.default?.());
1021
1064
  }
1022
1065
  });
1023
1066
  var commandInputProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydrateless/vue",
3
- "version": "0.9.0",
3
+ "version": "0.10.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.9.0"
31
+ "@hydrateless/enhancers": "^0.10.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "vue": ">=3.5"