vue-composable-ui 1.0.3 → 1.0.4

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,80 +1,83 @@
1
- import { ref as _, watch as M, nextTick as k, onMounted as F, onBeforeUnmount as U } from "vue";
2
- import { useHTMLElement as y } from "./composable-ui23.js";
3
- function D(z, A, {
1
+ import { ref as T, watch as _, nextTick as P, onBeforeMount as F, onMounted as U, onBeforeUnmount as j } from "vue";
2
+ import { useHTMLElement as k } from "./composable-ui23.js";
3
+ function G(y, z, {
4
4
  direction: c = "down",
5
- align: p = "left",
6
- position: W = "fixed",
7
- closeOnOutsideClick: B = !0,
8
- closeOnInsideClick: O = !1
5
+ align: u = "left",
6
+ position: L = "fixed",
7
+ closeOnOutsideClick: A = !0,
8
+ closeOnInsideClick: M = !1
9
9
  } = {}) {
10
- const s = _(!1);
10
+ const s = T(!1);
11
11
  function v() {
12
- const t = y(z);
13
- if (!t.value) throw new Error("Activator element is undefined");
14
- return t.value;
12
+ const e = k(y);
13
+ if (!e.value) throw new Error("Activator element is undefined");
14
+ return e.value;
15
15
  }
16
16
  function $() {
17
- const t = y(A);
18
- if (!t.value) throw new Error("Popover element is undefined");
19
- return t.value;
17
+ const e = k(z);
18
+ if (!e.value) throw new Error("Popover element is undefined");
19
+ return e.value;
20
20
  }
21
- function L({ focus: t = !0 } = {}) {
22
- s.value = !0, t && k(() => {
21
+ function B({ focus: e = !0 } = {}) {
22
+ s.value = !0, e && P(() => {
23
23
  $().focus();
24
24
  });
25
25
  }
26
- function E({ focus: t = !0 } = {}) {
27
- s.value = !1, t && v().focus();
26
+ function E({ focus: e = !0 } = {}) {
27
+ s.value = !1, e && v().focus();
28
28
  }
29
- function R(t) {
30
- s.value ? E(t) : L(t);
29
+ function O(e) {
30
+ s.value ? E(e) : B(e);
31
31
  }
32
32
  function h() {
33
33
  if (!s.value) return;
34
- const t = v(), r = $();
35
- r.style.position = W;
34
+ const e = v(), r = $();
35
+ r.style.position = L;
36
36
  const {
37
37
  top: f,
38
38
  right: l,
39
39
  bottom: w,
40
- left: u,
40
+ left: p,
41
41
  width: m,
42
- height: H
43
- } = t.getBoundingClientRect(), a = r.offsetHeight, d = r.offsetWidth, x = document.documentElement.clientHeight, b = document.documentElement.clientWidth;
42
+ height: W
43
+ } = e.getBoundingClientRect(), a = r.offsetHeight, d = r.offsetWidth, x = document.documentElement.clientHeight, b = document.documentElement.clientWidth;
44
44
  let i = c;
45
- c == "up" ? f - a < 0 && (i = "down") : c == "down" ? w + a > x && (i = "up") : c == "right" ? l + d > b && (i = "left") : c == "left" && u - d < 0 && (i = "right");
46
- let o = p;
47
- p == "left" ? u + d > b && (o = "right") : p == "right" ? l - d < 0 && (o = "left") : p == "top" ? f + a > x && (o = "bottom") : p == "bottom" && w - a < 0 && (o = "top");
48
- const e = {
45
+ c == "up" ? f - a < 0 && (i = "down") : c == "down" ? w + a > x && (i = "up") : c == "right" ? l + d > b && (i = "left") : c == "left" && p - d < 0 && (i = "right");
46
+ let o = u;
47
+ u == "left" ? p + d > b && (o = "right") : u == "right" ? l - d < 0 && (o = "left") : u == "top" ? f + a > x && (o = "bottom") : u == "bottom" && w - a < 0 && (o = "top");
48
+ const t = {
49
49
  top: "auto",
50
50
  bottom: "auto",
51
51
  left: "auto",
52
52
  right: "auto",
53
53
  width: "auto"
54
- }, n = W === "fixed";
55
- i == "up" ? e.bottom = `${H + (n ? x - w : 0)}px` : i == "down" ? e.top = `${H + (n ? f : 0)}px` : i == "right" ? e.left = `${m + (n ? u : 0)}px` : i == "left" && (e.right = `${m + (n ? b - l : 0)}px`), ["up", "down"].includes(i) ? o == "right" ? e.right = `${n ? b - l : 0}px` : o == "left" || o == "stretch" ? e.left = `${n ? u : 0}px` : o == "center" && (e.left = `${(n ? u : 0) - (d - m) / 2}px`) : o == "bottom" ? e.bottom = `${n ? x - w : 0}px` : o == "top" ? e.top = `${n ? f : 0}px` : o == "center" && (e.top = `${(n ? f : 0) - (a - H) / 2}px`), ["up", "down"].includes(i) && o === "stretch" && (e.width = m + "px");
56
- for (const P in e)
57
- r.style[P] = e[P];
54
+ }, n = L === "fixed";
55
+ 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 ? p : 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 ? p : 0}px` : o == "center" && (t.left = `${(n ? p : 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) - (a - W) / 2}px`), ["up", "down"].includes(i) && o === "stretch" && (t.width = m + "px");
56
+ for (const C in t)
57
+ r.style[C] = t[C];
58
58
  }
59
- M(
59
+ _(
60
60
  s,
61
- (t) => {
62
- t && k(() => {
61
+ (e) => {
62
+ e && P(() => {
63
63
  h();
64
64
  });
65
65
  },
66
66
  { flush: "pre" }
67
67
  );
68
- function T(t) {
69
- const r = t.target;
68
+ function R(e) {
69
+ const r = e.target;
70
70
  if (!v().contains(r))
71
71
  try {
72
- $().contains(r) ? O && E() : B && (s.value = !1);
72
+ $().contains(r) ? M && E() : A && (s.value = !1);
73
73
  } catch {
74
74
  }
75
75
  }
76
- const C = new ResizeObserver(h), g = new AbortController();
76
+ let H;
77
+ const g = new AbortController();
77
78
  return F(() => {
79
+ H = new ResizeObserver(h);
80
+ }), U(() => {
78
81
  window.addEventListener("resize", h, {
79
82
  passive: !0,
80
83
  signal: g.signal
@@ -82,19 +85,19 @@ function D(z, A, {
82
85
  passive: !0,
83
86
  //capture: true,
84
87
  signal: g.signal
85
- }), window.addEventListener("click", T, {
88
+ }), window.addEventListener("click", R, {
86
89
  passive: !0,
87
90
  signal: g.signal
88
- }), C.observe(v());
89
- }), U(() => {
90
- g.abort(), C.disconnect();
91
+ }), H.observe(v());
92
+ }), j(() => {
93
+ g.abort(), H.disconnect();
91
94
  }), {
92
95
  isOpen: s,
93
- open: L,
96
+ open: B,
94
97
  close: E,
95
- toggle: R
98
+ toggle: O
96
99
  };
97
100
  }
98
101
  export {
99
- D as usePopover
102
+ G as usePopover
100
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-composable-ui",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",