vue-composable-ui 1.1.4 → 1.2.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.
@@ -1,23 +1,23 @@
1
- import { defineComponent as r, inject as a, useModel as m, watch as p, withDirectives as d, openBlock as s, createElementBlock as f, mergeProps as v, unref as n, vModelDynamic as c } from "vue";
1
+ import { defineComponent as i, inject as r, useModel as m, watch as p, withDirectives as d, openBlock as s, createElementBlock as f, mergeProps as v, unref as n, vModelDynamic as c } from "vue";
2
2
  import { injectCombobox as b } from "./composable-ui19.js";
3
- const y = /* @__PURE__ */ r({
3
+ const y = /* @__PURE__ */ i({
4
4
  __name: "comboboxInput",
5
5
  props: {
6
6
  modelValue: {},
7
7
  modelModifiers: {}
8
8
  },
9
9
  emits: ["update:modelValue"],
10
- setup(i) {
11
- const e = a(b);
10
+ setup(a) {
11
+ const e = r(b);
12
12
  if (!e)
13
13
  throw new Error("Combobox injectable context is not provided");
14
- const l = m(i, "modelValue");
14
+ const l = m(a, "modelValue");
15
15
  function u() {
16
16
  l.value = e.displayValue.value;
17
17
  }
18
18
  return p(e.displayValue, u, { immediate: !0 }), (w, o) => d((s(), f("input", v({
19
19
  "onUpdate:modelValue": o[0] || (o[0] = (t) => l.value = t)
20
- }, n(e).activatorAttrs, {
20
+ }, n(e).activatorAttrs.value, {
21
21
  onClick: o[1] || (o[1] = (t) => n(e).open({ focus: !1 })),
22
22
  onKeydown: o[2] || (o[2] = //@ts-ignore
23
23
  (...t) => n(e).activatorOnKeyDown && n(e).activatorOnKeyDown(...t)),
@@ -11,14 +11,14 @@ import { _ as v } from "./tabContainer.vue_vue_type_script_setup_true_lang-yqy32
11
11
  import { _ as I } from "./tabList.vue_vue_type_script_setup_true_lang-BjKRcoyi.js";
12
12
  import { _ as g } from "./tab.vue_vue_type_script_setup_true_lang-C12uJKqo.js";
13
13
  import { _ as E } from "./tabPanel.vue_vue_type_script_setup_true_lang-DwEwu3p7.js";
14
- import { _ as H } from "./popover.vue_vue_type_script_setup_true_lang-D1gc6B-4.js";
15
- import { _ as h } from "./popoverDialog.vue_vue_type_script_setup_true_lang-ApsJsSDN.js";
16
- import { _ as q } from "./tooltip.vue_vue_type_script_setup_true_lang-kslDnoRH.js";
14
+ import { _ as H } from "./popover.vue_vue_type_script_setup_true_lang-BEMQwnTq.js";
15
+ import { _ as h } from "./popoverDialog.vue_vue_type_script_setup_true_lang-BbR_2G3W.js";
16
+ import { _ as q } from "./tooltip.vue_vue_type_script_setup_true_lang-BSjMpNzD.js";
17
17
  import { _ as y } from "./menu.vue_vue_type_script_setup_true_lang-B0Jm9v_v.js";
18
18
  import { _ as A } from "./menuItems.vue_vue_type_script_setup_true_lang-DQV-lU_A.js";
19
19
  import { _ as G } from "./menuItem.vue_vue_type_script_setup_true_lang-IZgj64N4.js";
20
20
  import { _ as K } from "./combobox.vue_vue_type_script_setup_true_lang-sMngTuXu.js";
21
- import { _ as Q } from "./comboboxInput.vue_vue_type_script_setup_true_lang-Be5FBBbM.js";
21
+ import { _ as Q } from "./comboboxInput.vue_vue_type_script_setup_true_lang-BTDqx7mj.js";
22
22
  import { _ as S } from "./comboboxOptions.vue_vue_type_script_setup_true_lang-DN0tz5dv.js";
23
23
  import { _ as W } from "./comboboxOption.vue_vue_type_script_setup_true_lang-DmF_EaqI.js";
24
24
  export {
@@ -1,4 +1,4 @@
1
- import { _ as f } from "./popover.vue_vue_type_script_setup_true_lang-D1gc6B-4.js";
1
+ import { _ as f } from "./popover.vue_vue_type_script_setup_true_lang-BEMQwnTq.js";
2
2
  export {
3
3
  f as default
4
4
  };
@@ -1,4 +1,4 @@
1
- import { _ as f } from "./popoverDialog.vue_vue_type_script_setup_true_lang-ApsJsSDN.js";
1
+ import { _ as f } from "./popoverDialog.vue_vue_type_script_setup_true_lang-BbR_2G3W.js";
2
2
  export {
3
3
  f as default
4
4
  };
@@ -1,4 +1,4 @@
1
- import { _ as f } from "./tooltip.vue_vue_type_script_setup_true_lang-kslDnoRH.js";
1
+ import { _ as f } from "./tooltip.vue_vue_type_script_setup_true_lang-BSjMpNzD.js";
2
2
  export {
3
3
  f as default
4
4
  };
@@ -1,107 +1,120 @@
1
- import { ref as _, watch as F, nextTick as y, onBeforeMount as U, onMounted as V, onBeforeUnmount as j, toValue as z } from "vue";
1
+ import { ref as D, watch as K, nextTick as P, onBeforeMount as U, onMounted as V, onBeforeUnmount as j, toValue as z } from "vue";
2
2
  import { useHTMLElement as A } from "./composable-ui24.js";
3
- function G(L, B, {
3
+ function I(H, L, {
4
4
  direction: c = "down",
5
5
  align: u = "left",
6
- position: C = "fixed",
7
- closeOnOutsideClick: M = !0,
8
- closeOnInsideClick: O = !1
6
+ position: k = "fixed",
7
+ closeOnOutsideClick: F = !0,
8
+ closeOnInsideClick: M = !1
9
9
  } = {}) {
10
- const s = _(!1);
11
- function v() {
12
- const e = A(L);
10
+ const s = D(!1);
11
+ function h() {
12
+ const e = A(H);
13
13
  if (!e.value)
14
14
  throw new Error(
15
- "Activator element is undefined: " + z(L)
15
+ "Activator element is undefined: " + z(H)
16
16
  );
17
17
  return e.value;
18
18
  }
19
- function $() {
20
- const e = A(B);
19
+ function g() {
20
+ const e = A(L);
21
21
  if (!e.value)
22
- throw new Error("Popover element is undefined: " + z(B));
22
+ throw new Error("Popover element is undefined: " + z(L));
23
23
  return e.value;
24
24
  }
25
- function P({ focus: e = !0 } = {}) {
26
- s.value = !0, e && y(() => {
27
- $().focus();
25
+ function B({ focus: e = !0 } = {}) {
26
+ s.value = !0, e && P(() => {
27
+ g().focus();
28
28
  });
29
29
  }
30
- function E({ focus: e = !0 } = {}) {
31
- s.value = !1, e && v().focus();
30
+ function O() {
31
+ try {
32
+ return g().contains(document.activeElement);
33
+ } catch {
34
+ return !1;
35
+ }
36
+ }
37
+ function w({ focus: e } = {}) {
38
+ const i = e ?? O();
39
+ s.value = !1, i && h().focus();
32
40
  }
33
41
  function R(e) {
34
- s.value ? E(e) : P(e);
42
+ s.value ? w(e) : B(e);
35
43
  }
36
- function h() {
44
+ function m() {
37
45
  if (!s.value) return;
38
- const e = v(), r = $();
39
- r.style.position = C;
46
+ const e = h(), i = g();
47
+ i.style.position = k;
40
48
  const {
41
49
  top: f,
42
50
  right: l,
43
- bottom: w,
44
- left: a,
45
- width: m,
46
- height: W
47
- } = e.getBoundingClientRect(), p = r.offsetHeight, d = r.offsetWidth, x = document.documentElement.clientHeight, b = document.documentElement.clientWidth;
48
- let i = c;
49
- c == "up" ? f - p < 0 && (i = "down") : c == "down" ? w + p > x && (i = "up") : c == "right" ? l + d > b && (i = "left") : c == "left" && a - d < 0 && (i = "right");
51
+ bottom: x,
52
+ left: p,
53
+ width: b,
54
+ height: y
55
+ } = e.getBoundingClientRect(), d = i.offsetHeight, v = i.offsetWidth, $ = document.documentElement.clientHeight, E = document.documentElement.clientWidth;
56
+ let n = c;
57
+ c == "up" ? f - d < 0 && (n = "down") : c == "down" ? x + d > $ && (n = "up") : c == "right" ? l + v > E && (n = "left") : c == "left" && p - v < 0 && (n = "right");
50
58
  let o = u;
51
- u == "left" ? a + d > b && (o = "right") : u == "right" ? l - d < 0 && (o = "left") : u == "top" ? f + p > x && (o = "bottom") : u == "bottom" && w - p < 0 && (o = "top");
59
+ u == "left" ? p + v > E && (o = "right") : u == "right" ? l - v < 0 && (o = "left") : u == "top" ? f + d > $ && (o = "bottom") : u == "bottom" && x - d < 0 && (o = "top");
52
60
  const t = {
53
61
  top: "auto",
54
62
  bottom: "auto",
55
63
  left: "auto",
56
64
  right: "auto",
57
65
  width: "auto"
58
- }, n = C === "fixed";
59
- i == "up" ? t.bottom = `${W + (n ? x - w : 0)}px` : i == "down" ? t.top = `${W + (n ? f : 0)}px` : i == "right" ? t.left = `${m + (n ? a : 0)}px` : i == "left" && (t.right = `${m + (n ? b - l : 0)}px`), ["up", "down"].includes(i) ? o == "right" ? t.right = `${n ? b - l : 0}px` : o == "left" || o == "stretch" ? t.left = `${n ? a : 0}px` : o == "center" && (t.left = `${(n ? a : 0) - (d - m) / 2}px`) : o == "bottom" ? t.bottom = `${n ? x - w : 0}px` : o == "top" ? t.top = `${n ? f : 0}px` : o == "center" && (t.top = `${(n ? f : 0) - (p - W) / 2}px`), ["up", "down"].includes(i) && o === "stretch" && (t.width = m + "px");
60
- for (const k in t)
61
- r.style[k] = t[k];
66
+ }, r = k === "fixed";
67
+ n == "up" ? t.bottom = `${y + (r ? $ - x : 0)}px` : n == "down" ? t.top = `${y + (r ? f : 0)}px` : n == "right" ? t.left = `${b + (r ? p : 0)}px` : n == "left" && (t.right = `${b + (r ? E - l : 0)}px`), ["up", "down"].includes(n) ? o == "right" ? t.right = `${r ? E - l : 0}px` : o == "left" || o == "stretch" ? t.left = `${r ? p : 0}px` : o == "center" && (t.left = `${(r ? p : 0) - (v - b) / 2}px`) : o == "bottom" ? t.bottom = `${r ? $ - x : 0}px` : o == "top" ? t.top = `${r ? f : 0}px` : o == "center" && (t.top = `${(r ? f : 0) - (d - y) / 2}px`), ["up", "down"].includes(n) && o === "stretch" && (t.width = b + "px");
68
+ for (const C in t)
69
+ i.style[C] = t[C];
62
70
  }
63
- F(
71
+ K(
64
72
  s,
65
73
  (e) => {
66
- e && y(() => {
67
- h();
74
+ e && P(() => {
75
+ m();
68
76
  });
69
77
  },
70
78
  { flush: "pre" }
71
79
  );
72
80
  function T(e) {
73
- const r = e.target;
74
- if (!v().contains(r))
81
+ const i = e.target;
82
+ if (!h().contains(i))
75
83
  try {
76
- $().contains(r) ? O && E() : M && (s.value = !1);
84
+ g().contains(i) ? M && w() : F && (s.value = !1);
77
85
  } catch {
78
86
  }
79
87
  }
80
- let H;
81
- const g = new AbortController();
88
+ function _(e) {
89
+ !s.value || e.code !== "Escape" || (w(), e.preventDefault());
90
+ }
91
+ let W;
92
+ const a = new AbortController();
82
93
  return U(() => {
83
- H = new ResizeObserver(h);
94
+ W = new ResizeObserver(m);
84
95
  }), V(() => {
85
- window.addEventListener("resize", h, {
96
+ window.addEventListener("resize", m, {
86
97
  passive: !0,
87
- signal: g.signal
88
- }), window.addEventListener("scroll", h, {
98
+ signal: a.signal
99
+ }), window.addEventListener("scroll", m, {
89
100
  passive: !0,
90
101
  //capture: true,
91
- signal: g.signal
102
+ signal: a.signal
92
103
  }), window.addEventListener("click", T, {
93
104
  passive: !0,
94
- signal: g.signal
95
- }), H.observe(v());
105
+ signal: a.signal
106
+ }), window.addEventListener("keydown", _, {
107
+ signal: a.signal
108
+ }), W.observe(h());
96
109
  }), j(() => {
97
- g.abort(), H.disconnect();
110
+ a.abort(), W.disconnect();
98
111
  }), {
99
112
  isOpen: s,
100
- open: P,
101
- close: E,
113
+ open: B,
114
+ close: w,
102
115
  toggle: R
103
116
  };
104
117
  }
105
118
  export {
106
- G as usePopover
119
+ I as usePopover
107
120
  };
@@ -1,4 +1,4 @@
1
- import { _ as f } from "./comboboxInput.vue_vue_type_script_setup_true_lang-Be5FBBbM.js";
1
+ import { _ as f } from "./comboboxInput.vue_vue_type_script_setup_true_lang-BTDqx7mj.js";
2
2
  export {
3
3
  f as default
4
4
  };
@@ -0,0 +1,64 @@
1
+ import { defineComponent as v, useModel as m, useId as c, watch as p, onMounted as O, computed as g, provide as I, renderSlot as C, unref as n, mergeModels as k } from "vue";
2
+ import { usePopover as M } from "./composable-ui23.js";
3
+ import { injectPopover as _ } from "./composable-ui19.js";
4
+ const $ = /* @__PURE__ */ v({
5
+ __name: "popover",
6
+ props: /* @__PURE__ */ k({
7
+ id: {},
8
+ activatorId: {},
9
+ direction: { default: "down" },
10
+ align: { default: "left" },
11
+ position: { default: "fixed" },
12
+ closeOnOutsideClick: { type: Boolean, default: !0 },
13
+ closeOnInsideClick: { type: Boolean, default: !1 },
14
+ role: { default: "dialog" }
15
+ }, {
16
+ open: { type: Boolean },
17
+ openModifiers: {}
18
+ }),
19
+ emits: ["update:open"],
20
+ setup(d) {
21
+ const e = d, i = m(d, "open"), l = e.id ?? c(), s = e.activatorId ?? c(), { isOpen: t, toggle: u, open: a, close: r } = M(
22
+ `#${s}`,
23
+ `#${l}`,
24
+ {
25
+ direction: e.direction,
26
+ align: e.align,
27
+ position: e.position,
28
+ closeOnOutsideClick: e.closeOnOutsideClick,
29
+ closeOnInsideClick: e.closeOnInsideClick
30
+ }
31
+ );
32
+ p(t, (o) => {
33
+ i.value !== o && (i.value = o);
34
+ }), p(i, (o) => {
35
+ o === void 0 || o === t.value || (o ? a({ focus: !1 }) : r());
36
+ }), O(() => {
37
+ i.value && !t.value && a({ focus: !1 });
38
+ });
39
+ const f = g(() => ({
40
+ id: s,
41
+ "aria-controls": t.value ? l : void 0,
42
+ // A disclosure is a plain expandable region: aria-haspopup would promise
43
+ // assistive technology a widget that is not there.
44
+ "aria-haspopup": e.role === "none" ? void 0 : e.role,
45
+ "aria-expanded": t.value
46
+ }));
47
+ return I(_, {
48
+ popoverId: l,
49
+ activatorId: s,
50
+ role: e.role,
51
+ isOpen: t,
52
+ close: r
53
+ }), (o, h) => C(o.$slots, "default", {
54
+ attrs: f.value,
55
+ isOpen: n(t),
56
+ toggle: n(u),
57
+ open: n(a),
58
+ close: n(r)
59
+ });
60
+ }
61
+ });
62
+ export {
63
+ $ as _
64
+ };
@@ -0,0 +1,22 @@
1
+ import { defineComponent as t, inject as n, unref as o, openBlock as i, createElementBlock as a, renderSlot as l, createCommentVNode as p } from "vue";
2
+ import { injectPopover as d } from "./composable-ui19.js";
3
+ const c = ["id", "role", "aria-labelledby"], f = /* @__PURE__ */ t({
4
+ __name: "popoverDialog",
5
+ setup(s) {
6
+ const e = n(d);
7
+ if (!e)
8
+ throw new Error("Popover injectable context is not provided");
9
+ return (r, m) => o(e).isOpen.value ? (i(), a("div", {
10
+ key: 0,
11
+ id: o(e).popoverId,
12
+ role: o(e).role === "none" ? void 0 : o(e).role,
13
+ "aria-labelledby": o(e).activatorId,
14
+ tabindex: "-1"
15
+ }, [
16
+ l(r.$slots, "default")
17
+ ], 8, c)) : p("", !0);
18
+ }
19
+ });
20
+ export {
21
+ f as _
22
+ };
@@ -0,0 +1,78 @@
1
+ import { defineComponent as g, useSlots as y, ref as b, useId as E, onMounted as $, onBeforeUnmount as k, openBlock as a, createElementBlock as c, Fragment as T, renderSlot as p, createBlock as _, Teleport as h, unref as f, mergeProps as B, createTextVNode as L, toDisplayString as S, createCommentVNode as w } from "vue";
2
+ import { usePopover as A } from "./composable-ui23.js";
3
+ const C = ["id"], P = /* @__PURE__ */ g({
4
+ inheritAttrs: !1,
5
+ __name: "tooltip",
6
+ props: {
7
+ id: {},
8
+ text: {},
9
+ delay: {},
10
+ direction: { default: "up" }
11
+ },
12
+ setup(l) {
13
+ const t = l, m = y(), d = b();
14
+ let u;
15
+ const o = t.id ?? E(), { isOpen: i } = A(`[aria-describedby=${o}]`, d, {
16
+ direction: t.direction,
17
+ align: "center"
18
+ });
19
+ function n() {
20
+ u = setTimeout(
21
+ () => {
22
+ i.value = !0;
23
+ },
24
+ typeof t.delay == "string" ? parseInt(t.delay) : t.delay
25
+ );
26
+ }
27
+ function s() {
28
+ i.value = !1, clearTimeout(u);
29
+ }
30
+ const v = {
31
+ "aria-describedby": o,
32
+ onmouseenter: n,
33
+ onmouseleave: s,
34
+ onfocus: n,
35
+ onblur: s
36
+ }, r = new AbortController();
37
+ return $(() => {
38
+ if (m.default) return;
39
+ const e = document.querySelector(
40
+ `[aria-describedby=${o}]`
41
+ );
42
+ if (!e)
43
+ throw new Error(`Tooltip activator not found: ${o}`);
44
+ e.addEventListener("mouseenter", n, {
45
+ signal: r.signal,
46
+ passive: !0
47
+ }), e.addEventListener("mouseleave", s, {
48
+ signal: r.signal,
49
+ passive: !0
50
+ }), e.addEventListener("focus", n, {
51
+ signal: r.signal,
52
+ passive: !0
53
+ }), e.addEventListener("blur", s, {
54
+ signal: r.signal,
55
+ passive: !0
56
+ });
57
+ }), k(() => {
58
+ r.abort();
59
+ }), (e, I) => (a(), c(T, null, [
60
+ p(e.$slots, "default", { attrs: v }),
61
+ (a(), _(h, { to: "body" }, [
62
+ f(i) ? (a(), c("div", B({
63
+ key: 0,
64
+ ref_key: "popupEl",
65
+ ref: d,
66
+ id: f(o)
67
+ }, e.$attrs, { role: "tooltip" }), [
68
+ p(e.$slots, "content", {}, () => [
69
+ L(S(l.text), 1)
70
+ ])
71
+ ], 16, C)) : w("", !0)
72
+ ]))
73
+ ], 64));
74
+ }
75
+ });
76
+ export {
77
+ P as _
78
+ };
@@ -15,7 +15,7 @@ export declare const injectTabs: InjectionKey<{
15
15
  export declare const injectPopover: InjectionKey<{
16
16
  popoverId: string;
17
17
  activatorId: string;
18
- role: "dialog" | "listbox" | "menu" | "tree" | "grid";
18
+ role: "dialog" | "listbox" | "menu" | "tree" | "grid" | "none";
19
19
  isOpen: UsePopoverReturn["isOpen"];
20
20
  close: UsePopoverReturn["close"];
21
21
  }>;
@@ -6,25 +6,37 @@ type __VLS_Props = {
6
6
  position?: "fixed" | "absolute";
7
7
  closeOnOutsideClick?: boolean;
8
8
  closeOnInsideClick?: boolean;
9
- role?: "dialog" | "listbox" | "menu" | "tree" | "grid";
9
+ role?: "dialog" | "listbox" | "menu" | "tree" | "grid" | "none";
10
10
  };
11
+ type __VLS_ModelProps = {
12
+ /**
13
+ * Optional two-way binding on the open state, for closing the popover from
14
+ * outside the slot scope - on a route change, say.
15
+ */
16
+ "open"?: boolean;
17
+ };
18
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
11
19
  declare var __VLS_1: {
12
20
  attrs: {
13
21
  id: string;
14
22
  "aria-controls": string | undefined;
15
- "aria-haspopup": "dialog" | "menu" | "listbox" | "tree" | "grid";
23
+ "aria-haspopup": "dialog" | "menu" | "listbox" | "tree" | "grid" | undefined;
16
24
  "aria-expanded": boolean;
17
25
  };
18
26
  isOpen: boolean;
19
- toggle: () => void;
20
- open: () => void;
21
- close: () => void;
27
+ toggle: (options?: import("../../main").PopoverFocusOptions) => void;
28
+ open: (options?: import("../../main").PopoverFocusOptions) => void;
29
+ close: (options?: import("../../main").PopoverFocusOptions) => void;
22
30
  };
23
31
  type __VLS_Slots = {} & {
24
32
  default?: (props: typeof __VLS_1) => any;
25
33
  };
26
- declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
27
- role: "dialog" | "listbox" | "menu" | "tree" | "grid";
34
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
35
+ "update:open": (value: boolean | undefined) => any;
36
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
37
+ "onUpdate:open"?: ((value: boolean | undefined) => any) | undefined;
38
+ }>, {
39
+ role: "dialog" | "listbox" | "menu" | "tree" | "grid" | "none";
28
40
  direction: "up" | "down" | "left" | "right";
29
41
  align: "top" | "bottom" | "left" | "right" | "center" | "stretch";
30
42
  position: "fixed" | "absolute";
@@ -6,7 +6,6 @@ type __VLS_Props = {
6
6
  };
7
7
  declare function open(): void;
8
8
  declare function close(): void;
9
- declare function onKeyDown(evt: KeyboardEvent): void;
10
9
  declare var __VLS_1: {
11
10
  attrs: {
12
11
  "aria-describedby": string;
@@ -14,7 +13,6 @@ declare var __VLS_1: {
14
13
  onmouseleave: typeof close;
15
14
  onfocus: typeof open;
16
15
  onblur: typeof close;
17
- onkeydown: typeof onKeyDown;
18
16
  };
19
17
  }, __VLS_9: {};
20
18
  type __VLS_Slots = {} & {
@@ -32,11 +32,20 @@ interface UsePopoverOptions {
32
32
  */
33
33
  closeOnInsideClick?: boolean;
34
34
  }
35
- interface FocusOptions {
35
+ /**
36
+ * Focus behaviour of an individual open/close/toggle call.
37
+ *
38
+ * Named to avoid shadowing the DOM's global `FocusOptions`.
39
+ */
40
+ export interface PopoverFocusOptions {
36
41
  /**
37
- * Focus the popover/activator
42
+ * Focus the popover on open, or return focus to the activator on close.
38
43
  *
39
- * @defaultValue `true`
44
+ * Closing defaults to returning focus only when the popover currently holds
45
+ * it: a popover dismissed by Escape must hand focus back, but one dismissed
46
+ * by the pointer leaving it must not pull focus across the page.
47
+ *
48
+ * @defaultValue `true` on open, focus containment on close
40
49
  */
41
50
  focus?: boolean;
42
51
  }
@@ -48,15 +57,15 @@ export interface UsePopoverReturn {
48
57
  /**
49
58
  * Open the popover
50
59
  */
51
- open: (options?: FocusOptions) => void;
60
+ open: (options?: PopoverFocusOptions) => void;
52
61
  /**
53
62
  * Close the popover
54
63
  */
55
- close: (options?: FocusOptions) => void;
64
+ close: (options?: PopoverFocusOptions) => void;
56
65
  /**
57
66
  * Toggle the popover
58
67
  */
59
- toggle: (options?: FocusOptions) => void;
68
+ toggle: (options?: PopoverFocusOptions) => void;
60
69
  }
61
70
  /**
62
71
  *
@@ -1,4 +1,4 @@
1
- export { usePopover } from "./composables/popover";
1
+ export { usePopover, type PopoverFocusOptions } from "./composables/popover";
2
2
  export { useList } from "./composables/list";
3
3
  export { useListOption } from "./composables/listOption";
4
4
  export { useFormControl } from "./composables/formControl";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-composable-ui",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,50 +0,0 @@
1
- import { defineComponent as u, useId as r, computed as f, provide as v, renderSlot as O, unref as t } from "vue";
2
- import { usePopover as m } from "./composable-ui23.js";
3
- import { injectPopover as g } from "./composable-ui19.js";
4
- const x = /* @__PURE__ */ u({
5
- __name: "popover",
6
- props: {
7
- id: {},
8
- activatorId: {},
9
- direction: { default: "down" },
10
- align: { default: "left" },
11
- position: { default: "fixed" },
12
- closeOnOutsideClick: { type: Boolean, default: !0 },
13
- closeOnInsideClick: { type: Boolean, default: !1 },
14
- role: { default: "dialog" }
15
- },
16
- setup(s) {
17
- const e = s, n = e.id ?? r(), i = e.activatorId ?? r(), { isOpen: o, toggle: a, open: d, close: l } = m(
18
- `#${i}`,
19
- `#${n}`,
20
- {
21
- direction: e.direction,
22
- align: e.align,
23
- position: e.position,
24
- closeOnOutsideClick: e.closeOnOutsideClick,
25
- closeOnInsideClick: e.closeOnInsideClick
26
- }
27
- ), c = f(() => ({
28
- id: i,
29
- "aria-controls": o.value ? e.id : void 0,
30
- "aria-haspopup": e.role,
31
- "aria-expanded": o.value
32
- }));
33
- return v(g, {
34
- popoverId: n,
35
- activatorId: i,
36
- role: e.role,
37
- isOpen: o,
38
- close: l
39
- }), (p, I) => O(p.$slots, "default", {
40
- attrs: c.value,
41
- isOpen: t(o),
42
- toggle: () => t(a)(),
43
- open: () => t(d)(),
44
- close: () => t(l)()
45
- });
46
- }
47
- });
48
- export {
49
- x as _
50
- };
@@ -1,30 +0,0 @@
1
- import { defineComponent as n, inject as a, unref as r, openBlock as i, createElementBlock as c, renderSlot as l, createCommentVNode as p } from "vue";
2
- import { injectPopover as d } from "./composable-ui19.js";
3
- const s = ["id", "role", "aria-labelledby"], v = /* @__PURE__ */ n({
4
- __name: "popoverDialog",
5
- setup(u) {
6
- const e = a(d);
7
- if (!e)
8
- throw new Error("Popover injectable context is not provided");
9
- function t(o) {
10
- if (o.code === "Escape")
11
- e.close();
12
- else
13
- return;
14
- o.preventDefault();
15
- }
16
- return (o, f) => r(e).isOpen.value ? (i(), c("div", {
17
- key: 0,
18
- onKeydown: t,
19
- id: r(e).popoverId,
20
- role: r(e).role,
21
- "aria-labelledby": r(e).activatorId,
22
- tabindex: "-1"
23
- }, [
24
- l(o.$slots, "default")
25
- ], 40, s)) : p("", !0);
26
- }
27
- });
28
- export {
29
- v as _
30
- };
@@ -1,85 +0,0 @@
1
- import { defineComponent as g, useSlots as b, ref as E, useId as k, onMounted as w, onBeforeUnmount as $, openBlock as a, createElementBlock as p, Fragment as L, renderSlot as f, createBlock as T, Teleport as _, unref as m, mergeProps as h, createTextVNode as B, toDisplayString as S, createCommentVNode as A } from "vue";
2
- import { usePopover as C } from "./composable-ui23.js";
3
- const I = ["id"], P = /* @__PURE__ */ g({
4
- inheritAttrs: !1,
5
- __name: "tooltip",
6
- props: {
7
- id: {},
8
- text: {},
9
- delay: {},
10
- direction: { default: "up" }
11
- },
12
- setup(l) {
13
- const o = l, v = b(), d = E();
14
- let u;
15
- const n = o.id ?? k(), { isOpen: i } = C(`[aria-describedby=${n}]`, d, {
16
- direction: o.direction,
17
- align: "center"
18
- });
19
- function s() {
20
- u = setTimeout(
21
- () => {
22
- i.value = !0;
23
- },
24
- typeof o.delay == "string" ? parseInt(o.delay) : o.delay
25
- );
26
- }
27
- function r() {
28
- i.value = !1, clearTimeout(u);
29
- }
30
- function c(e) {
31
- e.key === "Escape" && r();
32
- }
33
- const y = {
34
- "aria-describedby": n,
35
- onmouseenter: s,
36
- onmouseleave: r,
37
- onfocus: s,
38
- onblur: r,
39
- onkeydown: c
40
- }, t = new AbortController();
41
- return w(() => {
42
- if (v.default) return;
43
- const e = document.querySelector(
44
- `[aria-describedby=${n}]`
45
- );
46
- if (!e)
47
- throw new Error(`Tooltip activator not found: ${n}`);
48
- e.addEventListener("mouseenter", s, {
49
- signal: t.signal,
50
- passive: !0
51
- }), e.addEventListener("mouseleave", r, {
52
- signal: t.signal,
53
- passive: !0
54
- }), e.addEventListener("focus", s, {
55
- signal: t.signal,
56
- passive: !0
57
- }), e.addEventListener("blur", r, {
58
- signal: t.signal,
59
- passive: !0
60
- }), e.addEventListener("keydown", c, {
61
- signal: t.signal,
62
- passive: !0
63
- });
64
- }), $(() => {
65
- t.abort();
66
- }), (e, x) => (a(), p(L, null, [
67
- f(e.$slots, "default", { attrs: y }),
68
- (a(), T(_, { to: "body" }, [
69
- m(i) ? (a(), p("div", h({
70
- key: 0,
71
- ref_key: "popupEl",
72
- ref: d,
73
- id: m(n)
74
- }, e.$attrs, { role: "tooltip" }), [
75
- f(e.$slots, "content", {}, () => [
76
- B(S(l.text), 1)
77
- ])
78
- ], 16, I)) : A("", !0)
79
- ]))
80
- ], 64));
81
- }
82
- });
83
- export {
84
- P as _
85
- };