@fiscozen/composables 0.1.10 → 0.1.12
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/composables.js
CHANGED
|
@@ -1,260 +1,299 @@
|
|
|
1
|
-
import { ref as f, reactive as
|
|
2
|
-
const x = (o, t,
|
|
3
|
-
let
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
1
|
+
import { ref as f, reactive as M, onUnmounted as z, nextTick as P, onMounted as w, onBeforeUnmount as C, defineComponent as A, useSlots as N, computed as $, toRef as D, watch as O, openBlock as T, createElementBlock as W, createElementVNode as F, renderSlot as k, unref as S, withDirectives as q, normalizeClass as I, vShow as U } from "vue";
|
|
2
|
+
const x = (o, t, i, n) => {
|
|
3
|
+
let a = "right", e = "right-start";
|
|
4
|
+
const c = o.getBoundingClientRect(), d = t.getBoundingClientRect(), r = i.getBoundingClientRect(), b = (r.left - c.left - d.width) / c.width, l = (c.right - r.right - d.width) / c.width, s = (r.top - c.top - d.height) / c.height, h = (c.bottom - r.bottom - d.height) / c.height;
|
|
5
|
+
if (a = [
|
|
6
6
|
{
|
|
7
7
|
key: "right",
|
|
8
8
|
space: l
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
key: "top",
|
|
12
|
-
space:
|
|
12
|
+
space: s
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
key: "bottom",
|
|
16
|
-
space:
|
|
16
|
+
space: h
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
key: "left",
|
|
20
20
|
space: b
|
|
21
21
|
}
|
|
22
|
-
].sort((p,
|
|
23
|
-
switch (
|
|
22
|
+
].sort((p, u) => u.space - p.space)[0].key, !n)
|
|
23
|
+
switch (a) {
|
|
24
24
|
case "right":
|
|
25
25
|
case "left":
|
|
26
|
-
const p = (
|
|
27
|
-
|
|
26
|
+
const p = (d.height - r.height) / 2;
|
|
27
|
+
c.top > r.top - p && (n = "end"), c.bottom < r.top - p && (n = "start");
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
|
-
return e = n ? `${
|
|
31
|
-
},
|
|
32
|
-
x: t.x + o.width *
|
|
30
|
+
return e = n ? `${a}-${n}` : a, e;
|
|
31
|
+
}, K = (o, t, i, n) => ({
|
|
32
|
+
x: t.x + o.width * i / 100,
|
|
33
33
|
y: t.y + o.height * n / 100
|
|
34
|
-
}),
|
|
35
|
-
const t = f(null),
|
|
34
|
+
}), Q = (o) => {
|
|
35
|
+
const t = f(null), i = f(null), n = f(null), a = f(null), e = M({
|
|
36
36
|
position: { x: 0, y: 0 }
|
|
37
|
-
}),
|
|
37
|
+
}), c = {
|
|
38
38
|
root: null,
|
|
39
39
|
rootMargin: "0px",
|
|
40
40
|
threshold: 1,
|
|
41
41
|
...o.element.intersectionOptions
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
var
|
|
45
|
-
if (t.value = typeof o.element.domRef.value == "string" ? document.querySelector(o.element.domRef.value) : o.element.domRef.value, o.container ? (
|
|
42
|
+
}, d = (l, s) => {
|
|
43
|
+
}, r = f(new IntersectionObserver(d, c)), b = () => P(() => {
|
|
44
|
+
var E;
|
|
45
|
+
if (t.value = typeof o.element.domRef.value == "string" ? document.querySelector(o.element.domRef.value) : o.element.domRef.value, o.container ? (i.value = typeof o.container.domRef.value == "string" ? document.querySelector(o.container.domRef.value) : o.container.domRef.value, i.value ?? (i.value = document.body)) : i.value = document.body, !t.value)
|
|
46
46
|
throw new Error("missing reference element for floating behavior");
|
|
47
|
-
o.opener && (n.value = typeof o.opener.domRef.value == "string" ? document.querySelector(o.opener.domRef.value) : o.opener.domRef.value),
|
|
48
|
-
const l = (
|
|
49
|
-
|
|
50
|
-
let
|
|
47
|
+
o.opener && (n.value = typeof o.opener.domRef.value == "string" ? document.querySelector(o.opener.domRef.value) : o.opener.domRef.value), a.value = t.value.getBoundingClientRect();
|
|
48
|
+
const l = (E = n.value) == null ? void 0 : E.getBoundingClientRect(), s = i.value.getBoundingClientRect(), h = window.getComputedStyle(t.value);
|
|
49
|
+
r.value.observe(t.value), r.value.observe(i.value);
|
|
50
|
+
let v = o.position ? o.position.value : "auto", p = 0, u = 0;
|
|
51
51
|
if (o.opener && n.value && l) {
|
|
52
|
-
const g = l.left - parseFloat(
|
|
53
|
-
switch (
|
|
52
|
+
const g = l.left - parseFloat(h.marginLeft) - parseFloat(h.marginRight), B = l.left - parseFloat(h.marginLeft), y = l.top - parseFloat(h.marginTop) - parseFloat(h.marginBottom), L = l.top - parseFloat(h.marginTop);
|
|
53
|
+
switch (v) {
|
|
54
54
|
case "auto":
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
v = x(
|
|
56
|
+
i.value,
|
|
57
57
|
t.value,
|
|
58
58
|
n.value
|
|
59
59
|
);
|
|
60
60
|
break;
|
|
61
61
|
case "auto-start":
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
v = x(
|
|
63
|
+
i.value,
|
|
64
64
|
t.value,
|
|
65
65
|
n.value,
|
|
66
66
|
"start"
|
|
67
67
|
);
|
|
68
68
|
break;
|
|
69
69
|
case "auto-end":
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
v = x(
|
|
71
|
+
i.value,
|
|
72
72
|
t.value,
|
|
73
73
|
n.value,
|
|
74
74
|
"end"
|
|
75
75
|
);
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
|
-
switch (
|
|
78
|
+
switch (v) {
|
|
79
79
|
case "bottom":
|
|
80
|
-
e.position.y = l.bottom, e.position.x = B + l.width / 2,
|
|
80
|
+
e.position.y = l.bottom, e.position.x = B + l.width / 2, u = -50, p = 0;
|
|
81
81
|
break;
|
|
82
82
|
case "bottom-start":
|
|
83
|
-
e.position.y = l.bottom, e.position.x = g,
|
|
83
|
+
e.position.y = l.bottom, e.position.x = g, u = 0, p = 0;
|
|
84
84
|
break;
|
|
85
85
|
case "bottom-end":
|
|
86
|
-
e.position.y = l.bottom, e.position.x = l.right,
|
|
86
|
+
e.position.y = l.bottom, e.position.x = l.right, u = -100, p = 0;
|
|
87
87
|
break;
|
|
88
88
|
case "left-start":
|
|
89
|
-
e.position.y = y, e.position.x = g,
|
|
89
|
+
e.position.y = y, e.position.x = g, u = -100, p = 0;
|
|
90
90
|
break;
|
|
91
91
|
case "left":
|
|
92
|
-
e.position.y =
|
|
92
|
+
e.position.y = L + l.height / 2, e.position.x = g, p = -50, u = -100;
|
|
93
93
|
break;
|
|
94
94
|
case "left-end":
|
|
95
|
-
e.position.y = l.bottom, e.position.x = g, p = -100,
|
|
95
|
+
e.position.y = l.bottom, e.position.x = g, p = -100, u = -100;
|
|
96
96
|
break;
|
|
97
97
|
case "top-start":
|
|
98
|
-
e.position.y = y, e.position.x = g, p = -100,
|
|
98
|
+
e.position.y = y, e.position.x = g, p = -100, u = 0;
|
|
99
99
|
break;
|
|
100
100
|
case "top":
|
|
101
|
-
e.position.y = y, e.position.x = B + l.width / 2,
|
|
101
|
+
e.position.y = y, e.position.x = B + l.width / 2, u = -50, p = -100;
|
|
102
102
|
break;
|
|
103
103
|
case "top-end":
|
|
104
|
-
e.position.y = y, e.position.x = l.right,
|
|
104
|
+
e.position.y = y, e.position.x = l.right, u = -100, p = -100;
|
|
105
105
|
break;
|
|
106
106
|
case "right-start":
|
|
107
|
-
e.position.y = y, e.position.x = l.right,
|
|
107
|
+
e.position.y = y, e.position.x = l.right, u = 0, p = 0;
|
|
108
108
|
break;
|
|
109
109
|
case "right":
|
|
110
|
-
e.position.y =
|
|
110
|
+
e.position.y = L + l.height / 2, e.position.x = l.right, p = -50, u = 0;
|
|
111
111
|
break;
|
|
112
112
|
case "right-end":
|
|
113
|
-
e.position.y = l.bottom, e.position.x = l.right, p = -100,
|
|
113
|
+
e.position.y = l.bottom, e.position.x = l.right, p = -100, u = 0;
|
|
114
114
|
break;
|
|
115
115
|
}
|
|
116
116
|
} else
|
|
117
|
-
switch (
|
|
117
|
+
switch (v) {
|
|
118
118
|
case "bottom":
|
|
119
|
-
e.position.y =
|
|
119
|
+
e.position.y = s.bottom - a.value.height, e.position.x = s.left + s.width / 2, u = -50;
|
|
120
120
|
break;
|
|
121
121
|
case "left-end":
|
|
122
122
|
case "bottom-start":
|
|
123
|
-
e.position.y =
|
|
123
|
+
e.position.y = s.bottom - a.value.height, e.position.x = s.left;
|
|
124
124
|
break;
|
|
125
125
|
case "right-end":
|
|
126
126
|
case "bottom-end":
|
|
127
|
-
e.position.y =
|
|
127
|
+
e.position.y = s.bottom - a.value.height, e.position.x = s.right - a.value.width;
|
|
128
128
|
break;
|
|
129
129
|
case "left":
|
|
130
|
-
e.position.y =
|
|
130
|
+
e.position.y = s.top + (s.height - a.value.height) / 2, e.position.x = s.left;
|
|
131
131
|
break;
|
|
132
132
|
case "top-start":
|
|
133
133
|
case "left-start":
|
|
134
|
-
e.position.y =
|
|
134
|
+
e.position.y = s.top, e.position.x = s.left;
|
|
135
135
|
break;
|
|
136
136
|
case "top":
|
|
137
|
-
e.position.y =
|
|
137
|
+
e.position.y = s.top, e.position.x = s.left + (s.width - a.value.width) / 2;
|
|
138
138
|
break;
|
|
139
139
|
case "top-end":
|
|
140
140
|
case "right-start":
|
|
141
|
-
e.position.y =
|
|
141
|
+
e.position.y = s.top, e.position.x = s.right - a.value.width;
|
|
142
142
|
case "right":
|
|
143
|
-
e.position.y =
|
|
143
|
+
e.position.y = s.top + (s.height - a.value.height) / 2, e.position.x = s.right - a.value.width;
|
|
144
144
|
break;
|
|
145
145
|
}
|
|
146
|
-
const
|
|
147
|
-
e.position.x =
|
|
146
|
+
const m = K(a.value, e.position, u, p);
|
|
147
|
+
e.position.x = m.x, e.position.y = m.y, m.x < s.left && (e.position.x = s.left, u = 0), m.x + a.value.width > s.right && (e.position.x = s.right - a.value.width, u = 0), m.y < s.top && (e.position.y = s.top, p = 0), m.y + a.value.height > s.bottom && (e.position.y = s.bottom - a.value.height, p = 0), t.value.style.top = `${e.position.y}px`, t.value.style.left = `${e.position.x}px`, t.value.style.position = "fixed", t.value.style.display = "flex", a.value = t.value.getBoundingClientRect();
|
|
148
148
|
});
|
|
149
|
-
return
|
|
150
|
-
|
|
149
|
+
return z(() => {
|
|
150
|
+
r.value.disconnect();
|
|
151
151
|
}), {
|
|
152
152
|
float: e,
|
|
153
|
-
rect:
|
|
154
|
-
floatObserver:
|
|
153
|
+
rect: a,
|
|
154
|
+
floatObserver: r,
|
|
155
155
|
setPosition: b
|
|
156
156
|
};
|
|
157
157
|
};
|
|
158
|
-
function
|
|
159
|
-
const t = window.matchMedia(o),
|
|
160
|
-
function n(
|
|
161
|
-
|
|
158
|
+
function R(o) {
|
|
159
|
+
const t = window.matchMedia(o), i = f(t.matches);
|
|
160
|
+
function n(a) {
|
|
161
|
+
i.value = a.matches;
|
|
162
162
|
}
|
|
163
|
-
return
|
|
163
|
+
return w(() => {
|
|
164
164
|
t.addEventListener("change", n);
|
|
165
|
-
}),
|
|
165
|
+
}), z(() => {
|
|
166
166
|
t.removeEventListener("change", n);
|
|
167
|
-
}),
|
|
167
|
+
}), i;
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function Y(o) {
|
|
170
170
|
return {
|
|
171
171
|
isGreater(t) {
|
|
172
|
-
return
|
|
172
|
+
return R(`(min-width: ${o[t]})`);
|
|
173
173
|
},
|
|
174
174
|
isSmaller(t) {
|
|
175
|
-
return
|
|
175
|
+
return R(`(max-width: ${o[t]})`);
|
|
176
176
|
},
|
|
177
|
-
isInBetween(t,
|
|
178
|
-
return
|
|
177
|
+
isInBetween(t, i) {
|
|
178
|
+
return R(`(min-width: ${o[t]}) and (max-width: ${o[i]})`);
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function G(o, t, i) {
|
|
183
183
|
if (!o)
|
|
184
184
|
throw new Error("A target component has to be provided.");
|
|
185
185
|
if (!t)
|
|
186
186
|
throw new Error("A callback has to be provided.");
|
|
187
|
-
const
|
|
188
|
-
!o.value ||
|
|
187
|
+
const n = (a) => {
|
|
188
|
+
!o.value || a.target === o.value || a.composedPath().includes(o.value) || typeof t == "function" && t();
|
|
189
|
+
};
|
|
190
|
+
w(() => {
|
|
191
|
+
(i ?? o).value.addEventListener("click", n);
|
|
192
|
+
}), C(() => {
|
|
193
|
+
(i ?? o).value.removeEventListener("click", n);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function H(o, t) {
|
|
197
|
+
if (!o)
|
|
198
|
+
throw new Error("A target component has to be provided.");
|
|
199
|
+
if (!t || typeof t != "function")
|
|
200
|
+
throw new Error("A callback has to be provided.");
|
|
201
|
+
const i = (n) => {
|
|
202
|
+
t(n);
|
|
189
203
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}),
|
|
193
|
-
|
|
204
|
+
w(() => {
|
|
205
|
+
o.value.addEventListener("keydown", i);
|
|
206
|
+
}), C(() => {
|
|
207
|
+
o.value.removeEventListener("keydown", i);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function V(o, t) {
|
|
211
|
+
if (!o || typeof o != "function")
|
|
212
|
+
throw new Error("A callback has to be provided.");
|
|
213
|
+
const i = (n) => {
|
|
214
|
+
o(n);
|
|
215
|
+
};
|
|
216
|
+
w(() => {
|
|
217
|
+
if (!t) {
|
|
218
|
+
document.addEventListener("keyup", i);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
t.value.addEventListener("keyup", i);
|
|
222
|
+
}), C(() => {
|
|
223
|
+
if (!t) {
|
|
224
|
+
document.removeEventListener("keyup", i);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
t.value.removeEventListener("keyup", i);
|
|
194
228
|
});
|
|
195
229
|
}
|
|
196
|
-
const
|
|
230
|
+
const J = /* @__PURE__ */ A({
|
|
197
231
|
__name: "FzFloating",
|
|
198
232
|
props: {
|
|
199
233
|
isOpen: { type: Boolean, default: !1 },
|
|
200
234
|
position: { default: "auto" },
|
|
201
235
|
container: {},
|
|
202
236
|
contentClass: {},
|
|
203
|
-
openerClass: {}
|
|
237
|
+
openerClass: {},
|
|
238
|
+
overrideContentClass: { type: Boolean }
|
|
204
239
|
},
|
|
205
240
|
setup(o) {
|
|
206
|
-
const t = o,
|
|
207
|
-
position:
|
|
241
|
+
const t = o, i = f(null), n = f(null), a = N(), e = {
|
|
242
|
+
position: $(() => t.position),
|
|
208
243
|
element: {
|
|
209
244
|
domRef: n
|
|
210
245
|
},
|
|
211
246
|
container: {
|
|
212
|
-
domRef:
|
|
247
|
+
domRef: D(t.container || document.body)
|
|
213
248
|
}
|
|
214
249
|
};
|
|
215
|
-
|
|
216
|
-
domRef:
|
|
250
|
+
a.opener && (e.opener = {
|
|
251
|
+
domRef: i
|
|
217
252
|
});
|
|
218
|
-
const
|
|
219
|
-
|
|
253
|
+
const c = Q(e);
|
|
254
|
+
O(
|
|
220
255
|
() => t.position,
|
|
221
|
-
() => t.isOpen &&
|
|
256
|
+
() => t.isOpen && c.setPosition()
|
|
222
257
|
), O(
|
|
223
258
|
() => t.isOpen,
|
|
224
259
|
(r) => {
|
|
225
|
-
!r || !n.value || (n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none",
|
|
260
|
+
!r || !n.value || (n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none", c.setPosition());
|
|
226
261
|
}
|
|
227
|
-
)
|
|
228
|
-
|
|
262
|
+
);
|
|
263
|
+
const d = $(() => t.overrideContentClass ? t.contentClass : ["bg-core-white fixed p-4 z-10", t.contentClass]);
|
|
264
|
+
return (r, b) => (T(), W("div", null, [
|
|
265
|
+
F("div", {
|
|
229
266
|
ref_key: "opener",
|
|
230
|
-
ref:
|
|
267
|
+
ref: i,
|
|
231
268
|
class: "inline-flex"
|
|
232
269
|
}, [
|
|
233
|
-
|
|
270
|
+
k(r.$slots, "opener", {
|
|
234
271
|
isOpen: r.isOpen,
|
|
235
|
-
floating:
|
|
272
|
+
floating: S(c)
|
|
236
273
|
})
|
|
237
274
|
], 512),
|
|
238
|
-
|
|
239
|
-
|
|
275
|
+
k(r.$slots, "opener-end"),
|
|
276
|
+
q(F("div", {
|
|
240
277
|
ref_key: "content",
|
|
241
278
|
ref: n,
|
|
242
|
-
class: I(
|
|
279
|
+
class: I(d.value)
|
|
243
280
|
}, [
|
|
244
|
-
|
|
281
|
+
k(r.$slots, "default", {
|
|
245
282
|
isOpen: r.isOpen,
|
|
246
|
-
floating:
|
|
283
|
+
floating: S(c)
|
|
247
284
|
})
|
|
248
285
|
], 2), [
|
|
249
|
-
[
|
|
286
|
+
[U, r.$slots.default && (!r.$slots.opener || r.$slots.opener && r.isOpen)]
|
|
250
287
|
])
|
|
251
288
|
]));
|
|
252
289
|
}
|
|
253
290
|
});
|
|
254
291
|
export {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
292
|
+
J as FzFloating,
|
|
293
|
+
Y as useBreakpoints,
|
|
294
|
+
G as useClickOutside,
|
|
295
|
+
Q as useFloating,
|
|
296
|
+
H as useKeyDown,
|
|
297
|
+
V as useKeyUp,
|
|
298
|
+
R as useMediaQuery
|
|
260
299
|
};
|
package/dist/composables.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,
|
|
1
|
+
(function(f,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(f=typeof globalThis<"u"?globalThis:f||self,n(f.FzComposables={},f.Vue))})(this,function(f,n){"use strict";const x=(o,t,i,s)=>{let r="right",e="right-start";const d=o.getBoundingClientRect(),h=t.getBoundingClientRect(),l=i.getBoundingClientRect(),k=(l.left-d.left-h.width)/d.width,p=(d.right-l.right-h.width)/d.width,a=(l.top-d.top-h.height)/d.height,m=(d.bottom-l.bottom-h.height)/d.height;if(r=[{key:"right",space:p},{key:"top",space:a},{key:"bottom",space:m},{key:"left",space:k}].sort((c,u)=>u.space-c.space)[0].key,!s)switch(r){case"right":case"left":const c=(h.height-l.height)/2;d.top>l.top-c&&(s="end"),d.bottom<l.top-c&&(s="start");break}return e=s?`${r}-${s}`:r,e},L=(o,t,i,s)=>({x:t.x+o.width*i/100,y:t.y+o.height*s/100}),R=o=>{const t=n.ref(null),i=n.ref(null),s=n.ref(null),r=n.ref(null),e=n.reactive({position:{x:0,y:0}}),d={root:null,rootMargin:"0px",threshold:1,...o.element.intersectionOptions},h=(p,a)=>{},l=n.ref(new IntersectionObserver(h,d)),k=()=>n.nextTick(()=>{var C;if(t.value=typeof o.element.domRef.value=="string"?document.querySelector(o.element.domRef.value):o.element.domRef.value,o.container?(i.value=typeof o.container.domRef.value=="string"?document.querySelector(o.container.domRef.value):o.container.domRef.value,i.value??(i.value=document.body)):i.value=document.body,!t.value)throw new Error("missing reference element for floating behavior");o.opener&&(s.value=typeof o.opener.domRef.value=="string"?document.querySelector(o.opener.domRef.value):o.opener.domRef.value),r.value=t.value.getBoundingClientRect();const p=(C=s.value)==null?void 0:C.getBoundingClientRect(),a=i.value.getBoundingClientRect(),m=window.getComputedStyle(t.value);l.value.observe(t.value),l.value.observe(i.value);let g=o.position?o.position.value:"auto",c=0,u=0;if(o.opener&&s.value&&p){const v=p.left-parseFloat(m.marginLeft)-parseFloat(m.marginRight),E=p.left-parseFloat(m.marginLeft),b=p.top-parseFloat(m.marginTop)-parseFloat(m.marginBottom),B=p.top-parseFloat(m.marginTop);switch(g){case"auto":g=x(i.value,t.value,s.value);break;case"auto-start":g=x(i.value,t.value,s.value,"start");break;case"auto-end":g=x(i.value,t.value,s.value,"end");break}switch(g){case"bottom":e.position.y=p.bottom,e.position.x=E+p.width/2,u=-50,c=0;break;case"bottom-start":e.position.y=p.bottom,e.position.x=v,u=0,c=0;break;case"bottom-end":e.position.y=p.bottom,e.position.x=p.right,u=-100,c=0;break;case"left-start":e.position.y=b,e.position.x=v,u=-100,c=0;break;case"left":e.position.y=B+p.height/2,e.position.x=v,c=-50,u=-100;break;case"left-end":e.position.y=p.bottom,e.position.x=v,c=-100,u=-100;break;case"top-start":e.position.y=b,e.position.x=v,c=-100,u=0;break;case"top":e.position.y=b,e.position.x=E+p.width/2,u=-50,c=-100;break;case"top-end":e.position.y=b,e.position.x=p.right,u=-100,c=-100;break;case"right-start":e.position.y=b,e.position.x=p.right,u=0,c=0;break;case"right":e.position.y=B+p.height/2,e.position.x=p.right,c=-50,u=0;break;case"right-end":e.position.y=p.bottom,e.position.x=p.right,c=-100,u=0;break}}else switch(g){case"bottom":e.position.y=a.bottom-r.value.height,e.position.x=a.left+a.width/2,u=-50;break;case"left-end":case"bottom-start":e.position.y=a.bottom-r.value.height,e.position.x=a.left;break;case"right-end":case"bottom-end":e.position.y=a.bottom-r.value.height,e.position.x=a.right-r.value.width;break;case"left":e.position.y=a.top+(a.height-r.value.height)/2,e.position.x=a.left;break;case"top-start":case"left-start":e.position.y=a.top,e.position.x=a.left;break;case"top":e.position.y=a.top,e.position.x=a.left+(a.width-r.value.width)/2;break;case"top-end":case"right-start":e.position.y=a.top,e.position.x=a.right-r.value.width;case"right":e.position.y=a.top+(a.height-r.value.height)/2,e.position.x=a.right-r.value.width;break}const y=L(r.value,e.position,u,c);e.position.x=y.x,e.position.y=y.y,y.x<a.left&&(e.position.x=a.left,u=0),y.x+r.value.width>a.right&&(e.position.x=a.right-r.value.width,u=0),y.y<a.top&&(e.position.y=a.top,c=0),y.y+r.value.height>a.bottom&&(e.position.y=a.bottom-r.value.height,c=0),t.value.style.top=`${e.position.y}px`,t.value.style.left=`${e.position.x}px`,t.value.style.position="fixed",t.value.style.display="flex",r.value=t.value.getBoundingClientRect()});return n.onUnmounted(()=>{l.value.disconnect()}),{float:e,rect:r,floatObserver:l,setPosition:k}};function w(o){const t=window.matchMedia(o),i=n.ref(t.matches);function s(r){i.value=r.matches}return n.onMounted(()=>{t.addEventListener("change",s)}),n.onUnmounted(()=>{t.removeEventListener("change",s)}),i}function O(o){return{isGreater(t){return w(`(min-width: ${o[t]})`)},isSmaller(t){return w(`(max-width: ${o[t]})`)},isInBetween(t,i){return w(`(min-width: ${o[t]}) and (max-width: ${o[i]})`)}}}function F(o,t,i){if(!o)throw new Error("A target component has to be provided.");if(!t)throw new Error("A callback has to be provided.");const s=r=>{!o.value||r.target===o.value||r.composedPath().includes(o.value)||typeof t=="function"&&t()};n.onMounted(()=>{(i??o).value.addEventListener("click",s)}),n.onBeforeUnmount(()=>{(i??o).value.removeEventListener("click",s)})}function S(o,t){if(!o)throw new Error("A target component has to be provided.");if(!t||typeof t!="function")throw new Error("A callback has to be provided.");const i=s=>{t(s)};n.onMounted(()=>{o.value.addEventListener("keydown",i)}),n.onBeforeUnmount(()=>{o.value.removeEventListener("keydown",i)})}function $(o,t){if(!o||typeof o!="function")throw new Error("A callback has to be provided.");const i=s=>{o(s)};n.onMounted(()=>{if(!t){document.addEventListener("keyup",i);return}t.value.addEventListener("keyup",i)}),n.onBeforeUnmount(()=>{if(!t){document.removeEventListener("keyup",i);return}t.value.removeEventListener("keyup",i)})}const M=n.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{},contentClass:{},openerClass:{},overrideContentClass:{type:Boolean}},setup(o){const t=o,i=n.ref(null),s=n.ref(null),r=n.useSlots(),e={position:n.computed(()=>t.position),element:{domRef:s},container:{domRef:n.toRef(t.container||document.body)}};r.opener&&(e.opener={domRef:i});const d=R(e);n.watch(()=>t.position,()=>t.isOpen&&d.setPosition()),n.watch(()=>t.isOpen,l=>{!l||!s.value||(s.value.style.top="0px",s.value.style.left="0px",s.value.style.transform="none",d.setPosition())});const h=n.computed(()=>t.overrideContentClass?t.contentClass:["bg-core-white fixed p-4 z-10",t.contentClass]);return(l,k)=>(n.openBlock(),n.createElementBlock("div",null,[n.createElementVNode("div",{ref_key:"opener",ref:i,class:"inline-flex"},[n.renderSlot(l.$slots,"opener",{isOpen:l.isOpen,floating:n.unref(d)})],512),n.renderSlot(l.$slots,"opener-end"),n.withDirectives(n.createElementVNode("div",{ref_key:"content",ref:s,class:n.normalizeClass(h.value)},[n.renderSlot(l.$slots,"default",{isOpen:l.isOpen,floating:n.unref(d)})],2),[[n.vShow,l.$slots.default&&(!l.$slots.opener||l.$slots.opener&&l.isOpen)]])]))}});f.FzFloating=M,f.useBreakpoints=O,f.useClickOutside=F,f.useFloating=R,f.useKeyDown=S,f.useKeyUp=$,f.useMediaQuery=w,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiscozen/composables",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Design System utility composables",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"vitest": "^1.2.0",
|
|
27
27
|
"vue-tsc": "^1.8.25",
|
|
28
28
|
"@fiscozen/tsconfig": "^0.1.0",
|
|
29
|
-
"@fiscozen/
|
|
30
|
-
"@fiscozen/
|
|
29
|
+
"@fiscozen/eslint-config": "^0.1.0",
|
|
30
|
+
"@fiscozen/prettier-config": "^0.1.0"
|
|
31
31
|
},
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"scripts": {
|
package/src/composables/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { onBeforeUnmount, onMounted, Ref } from 'vue'
|
|
2
2
|
|
|
3
|
-
function useClickOutside(
|
|
3
|
+
function useClickOutside(
|
|
4
|
+
component: Ref<HTMLElement | undefined>,
|
|
5
|
+
callback: () => void,
|
|
6
|
+
elementToListenClicksOn?: Ref<HTMLElement | undefined>,
|
|
7
|
+
) {
|
|
4
8
|
// fail early if any of the required params is missing
|
|
5
9
|
if (!component) {
|
|
6
10
|
throw new Error('A target component has to be provided.')
|
|
@@ -24,11 +28,11 @@ function useClickOutside(component: Ref<HTMLElement | undefined>, callback: () =
|
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
onMounted(() => {
|
|
27
|
-
|
|
31
|
+
(elementToListenClicksOn ?? component).value!.addEventListener('click', listener)
|
|
28
32
|
})
|
|
29
33
|
|
|
30
34
|
onBeforeUnmount(() => {
|
|
31
|
-
|
|
35
|
+
(elementToListenClicksOn ?? component).value!.removeEventListener('click', listener)
|
|
32
36
|
})
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted, Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
function useKeyUp(callback: (event: KeyboardEvent) => void, component?: Ref<HTMLElement | undefined>) {
|
|
4
|
+
|
|
5
|
+
if (!callback || typeof callback !== 'function') {
|
|
6
|
+
throw new Error('A callback has to be provided.')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const listener = (event: KeyboardEvent) => {
|
|
10
|
+
callback(event)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
onMounted(() => {
|
|
14
|
+
if (!component) {
|
|
15
|
+
document.addEventListener('keyup', listener)
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
component.value!.addEventListener('keyup', listener)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
onBeforeUnmount(() => {
|
|
22
|
+
if (!component) {
|
|
23
|
+
document.removeEventListener('keyup', listener)
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
component.value!.removeEventListener('keyup', listener)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { useKeyUp }
|