@fiscozen/composables 0.1.27 → 0.1.29
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/LICENSE +21 -0
- package/dist/composables.js +451 -0
- package/dist/composables.umd.cjs +1 -0
- package/package.json +14 -14
- package/src/FzFloating.vue +23 -5
- package/src/__tests__/__snapshots__/FzFloating.spec.ts.snap +12 -12
- package/src/composables/useClickOutside.ts +1 -1
- package/src/composables/useCurrency.ts +1 -1
- package/src/composables/useFloating.ts +28 -22
- package/src/types.ts +7 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Fiscozen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { ref as m, reactive as te, onUnmounted as j, nextTick as V, onMounted as L, watch as k, onBeforeUnmount as O, getCurrentInstance as oe, computed as ee, defineComponent as ne, useSlots as ie, toRef as K, toRefs as ae, openBlock as B, createElementBlock as Q, renderSlot as x, createElementVNode as X, unref as F, withDirectives as Y, normalizeClass as J, vShow as Z, createCommentVNode as _, createBlock as le, Teleport as se } from "vue";
|
|
2
|
+
const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e, u, i) => {
|
|
3
|
+
let a = i ? "bottom" : "right", h = i ? "bottom-start" : "right-start";
|
|
4
|
+
E.width = window.innerWidth, E.height = window.innerHeight, E.x = 0, E.y = 0;
|
|
5
|
+
const r = o ? o.getBoundingClientRect() : E, t = n.getBoundingClientRect(), d = e.getBoundingClientRect(), g = (d.left - r.left - t.width) / r.width, l = (r.right - d.right - t.width) / r.width, v = (d.top - r.top - t.height) / r.height, s = (r.bottom - d.bottom - t.height) / r.height;
|
|
6
|
+
let c = [
|
|
7
|
+
{
|
|
8
|
+
key: "right",
|
|
9
|
+
space: l
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
key: "top",
|
|
13
|
+
space: v
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
key: "bottom",
|
|
17
|
+
space: s
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key: "left",
|
|
21
|
+
space: g
|
|
22
|
+
}
|
|
23
|
+
].sort((p, f) => f.space - p.space);
|
|
24
|
+
if (i && (c = c.filter((p) => p.key === "top" || p.key === "bottom")), a = c[0].key, !u)
|
|
25
|
+
switch (a) {
|
|
26
|
+
case "right":
|
|
27
|
+
case "left":
|
|
28
|
+
const p = (t.height - d.height) / 2;
|
|
29
|
+
r.top > d.top - p && (u = "end"), r.bottom < d.top - p && (u = "start");
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return h = u ? `${a}-${u}` : a, h;
|
|
33
|
+
}, re = (o, n, e, u) => ({
|
|
34
|
+
x: n.x + o.width * e / 100,
|
|
35
|
+
y: n.y + o.height * u / 100
|
|
36
|
+
}), ue = (o) => {
|
|
37
|
+
const n = m(null), e = m(null), u = m(null), i = m(), a = m(), h = m("auto"), r = m(), t = te({
|
|
38
|
+
position: { x: 0, y: 0 }
|
|
39
|
+
}), d = {
|
|
40
|
+
root: null,
|
|
41
|
+
rootMargin: "0px",
|
|
42
|
+
threshold: 1,
|
|
43
|
+
...o.element.value.intersectionOptions
|
|
44
|
+
}, g = (c, p) => {
|
|
45
|
+
}, l = m(new IntersectionObserver(g, d)), v = m(), s = () => V(() => {
|
|
46
|
+
var $, N, z, P, S, D, M, A, W, I, q, T, H;
|
|
47
|
+
if (v.value = o.position ? o.position.value : "auto", n.value = typeof o.element.value.domRef.value == "string" ? document.querySelector(o.element.value.domRef.value) : o.element.value.domRef.value, ($ = o.container) != null && $.value ? (e.value = typeof ((N = o.container.value) == null ? void 0 : N.domRef.value) == "string" ? document.querySelector(o.container.value.domRef.value) : (z = o.container.value) == null ? void 0 : z.domRef.value, e.value ?? (e.value = document.body)) : e.value = document.body, !n.value)
|
|
48
|
+
throw new Error("missing reference element for floating behavior");
|
|
49
|
+
(P = o.opener) != null && P.value && (u.value = typeof ((S = o.opener.value) == null ? void 0 : S.domRef.value) == "string" ? document.querySelector(o.opener.value.domRef.value) : (D = o.opener.value) == null ? void 0 : D.domRef.value), r.value = n.value.getBoundingClientRect(), i.value = (M = u.value) == null ? void 0 : M.getBoundingClientRect(), a.value = e.value.getBoundingClientRect();
|
|
50
|
+
const c = window.getComputedStyle(n.value);
|
|
51
|
+
l.value.observe(n.value), l.value.observe(e.value);
|
|
52
|
+
let p = 0, f = 0;
|
|
53
|
+
if (o.opener && o.opener.value && u.value && i && i.value) {
|
|
54
|
+
const y = i.value.left - parseFloat(c.marginLeft) - parseFloat(c.marginRight), U = i.value.left - parseFloat(c.marginLeft), R = i.value.top - parseFloat(c.marginTop) - parseFloat(c.marginBottom), G = i.value.top - parseFloat(c.marginTop);
|
|
55
|
+
switch (v.value) {
|
|
56
|
+
case "auto":
|
|
57
|
+
v.value = w(
|
|
58
|
+
(A = o.useViewport) != null && A.value ? null : e.value,
|
|
59
|
+
n.value,
|
|
60
|
+
u.value
|
|
61
|
+
);
|
|
62
|
+
break;
|
|
63
|
+
case "auto-vertical":
|
|
64
|
+
v.value = w(
|
|
65
|
+
(W = o.useViewport) != null && W.value ? null : e.value,
|
|
66
|
+
n.value,
|
|
67
|
+
u.value,
|
|
68
|
+
void 0,
|
|
69
|
+
!0
|
|
70
|
+
);
|
|
71
|
+
break;
|
|
72
|
+
case "auto-start":
|
|
73
|
+
v.value = w(
|
|
74
|
+
(I = o.useViewport) != null && I.value ? null : e.value,
|
|
75
|
+
n.value,
|
|
76
|
+
u.value,
|
|
77
|
+
"start"
|
|
78
|
+
);
|
|
79
|
+
break;
|
|
80
|
+
case "auto-vertical-start":
|
|
81
|
+
v.value = w(
|
|
82
|
+
(q = o.useViewport) != null && q.value ? null : e.value,
|
|
83
|
+
n.value,
|
|
84
|
+
u.value,
|
|
85
|
+
"start",
|
|
86
|
+
!0
|
|
87
|
+
);
|
|
88
|
+
break;
|
|
89
|
+
case "auto-end":
|
|
90
|
+
v.value = w(
|
|
91
|
+
(T = o.useViewport) != null && T.value ? null : e.value,
|
|
92
|
+
n.value,
|
|
93
|
+
u.value,
|
|
94
|
+
"end"
|
|
95
|
+
);
|
|
96
|
+
break;
|
|
97
|
+
case "auto-vertical-end":
|
|
98
|
+
v.value = w(
|
|
99
|
+
(H = o.useViewport) != null && H.value ? null : e.value,
|
|
100
|
+
n.value,
|
|
101
|
+
u.value,
|
|
102
|
+
"end",
|
|
103
|
+
!0
|
|
104
|
+
);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
switch (v.value) {
|
|
108
|
+
case "bottom":
|
|
109
|
+
t.position.y = i.value.bottom, t.position.x = U + i.value.width / 2, f = -50, p = 0;
|
|
110
|
+
break;
|
|
111
|
+
case "bottom-start":
|
|
112
|
+
t.position.y = i.value.bottom, t.position.x = y, f = 0, p = 0;
|
|
113
|
+
break;
|
|
114
|
+
case "bottom-end":
|
|
115
|
+
t.position.y = i.value.bottom, t.position.x = i.value.right, f = -100, p = 0;
|
|
116
|
+
break;
|
|
117
|
+
case "left-start":
|
|
118
|
+
t.position.y = R, t.position.x = y, f = -100, p = 0;
|
|
119
|
+
break;
|
|
120
|
+
case "left":
|
|
121
|
+
t.position.y = G + i.value.height / 2, t.position.x = y, p = -50, f = -100;
|
|
122
|
+
break;
|
|
123
|
+
case "left-end":
|
|
124
|
+
t.position.y = i.value.bottom, t.position.x = y, p = -100, f = -100;
|
|
125
|
+
break;
|
|
126
|
+
case "top-start":
|
|
127
|
+
t.position.y = R, t.position.x = y, p = -100, f = 0;
|
|
128
|
+
break;
|
|
129
|
+
case "top":
|
|
130
|
+
t.position.y = R, t.position.x = U + i.value.width / 2, f = -50, p = -100;
|
|
131
|
+
break;
|
|
132
|
+
case "top-end":
|
|
133
|
+
t.position.y = R, t.position.x = i.value.right, f = -100, p = -100;
|
|
134
|
+
break;
|
|
135
|
+
case "right-start":
|
|
136
|
+
t.position.y = R, t.position.x = i.value.right, f = 0, p = 0;
|
|
137
|
+
break;
|
|
138
|
+
case "right":
|
|
139
|
+
t.position.y = G + i.value.height / 2, t.position.x = i.value.right, p = -50, f = 0;
|
|
140
|
+
break;
|
|
141
|
+
case "right-end":
|
|
142
|
+
t.position.y = i.value.bottom, t.position.x = i.value.right, p = -100, f = 0;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
} else
|
|
146
|
+
switch (v.value) {
|
|
147
|
+
case "bottom":
|
|
148
|
+
t.position.y = a.value.bottom - r.value.height, t.position.x = a.value.left + a.value.width / 2, f = -50;
|
|
149
|
+
break;
|
|
150
|
+
case "left-end":
|
|
151
|
+
case "bottom-start":
|
|
152
|
+
t.position.y = a.value.bottom - r.value.height, t.position.x = a.value.left;
|
|
153
|
+
break;
|
|
154
|
+
case "right-end":
|
|
155
|
+
case "bottom-end":
|
|
156
|
+
t.position.y = a.value.bottom - r.value.height, t.position.x = a.value.right - r.value.width;
|
|
157
|
+
break;
|
|
158
|
+
case "left":
|
|
159
|
+
t.position.y = a.value.top + (a.value.height - r.value.height) / 2, t.position.x = a.value.left;
|
|
160
|
+
break;
|
|
161
|
+
case "top-start":
|
|
162
|
+
case "left-start":
|
|
163
|
+
t.position.y = a.value.top, t.position.x = a.value.left;
|
|
164
|
+
break;
|
|
165
|
+
case "top":
|
|
166
|
+
t.position.y = a.value.top, t.position.x = a.value.left + (a.value.width - r.value.width) / 2;
|
|
167
|
+
break;
|
|
168
|
+
case "top-end":
|
|
169
|
+
case "right-start":
|
|
170
|
+
t.position.y = a.value.top, t.position.x = a.value.right - r.value.width;
|
|
171
|
+
case "right":
|
|
172
|
+
t.position.y = a.value.top + (a.value.height - r.value.height) / 2, t.position.x = a.value.right - r.value.width;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
const b = re(r.value, t.position, f, p);
|
|
176
|
+
if (t.position.x = b.x, t.position.y = b.y, b.x < a.value.left && (t.position.x = a.value.left, f = 0), b.x + r.value.width > a.value.right) {
|
|
177
|
+
const y = a.value.right - r.value.width;
|
|
178
|
+
y > 0 && (t.position.x = y), f = 0;
|
|
179
|
+
}
|
|
180
|
+
if (b.y < a.value.top && (t.position.y = a.value.top, p = 0), b.y + r.value.height > a.value.bottom) {
|
|
181
|
+
const y = a.value.bottom - r.value.height;
|
|
182
|
+
y > 0 && (t.position.y = y), p = 0;
|
|
183
|
+
}
|
|
184
|
+
n.value.style.top = `${t.position.y}px`, n.value.style.left = `${t.position.x}px`, n.value.style.position = "fixed", n.value.style.display = "flex", r.value = n.value.getBoundingClientRect(), o.callback && o.callback.value && o.callback.value(r, i, a, h, v);
|
|
185
|
+
});
|
|
186
|
+
return j(() => {
|
|
187
|
+
l.value.disconnect();
|
|
188
|
+
}), {
|
|
189
|
+
float: t,
|
|
190
|
+
rect: r,
|
|
191
|
+
setPosition: s,
|
|
192
|
+
position: h,
|
|
193
|
+
actualPosition: v,
|
|
194
|
+
openerRect: i,
|
|
195
|
+
containerRect: a
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
function C(o) {
|
|
199
|
+
const n = window.matchMedia(o), e = m(n.matches);
|
|
200
|
+
function u(i) {
|
|
201
|
+
e.value = i.matches;
|
|
202
|
+
}
|
|
203
|
+
return L(() => {
|
|
204
|
+
n.addEventListener("change", u);
|
|
205
|
+
}), j(() => {
|
|
206
|
+
n.removeEventListener("change", u);
|
|
207
|
+
}), e;
|
|
208
|
+
}
|
|
209
|
+
function pe(o) {
|
|
210
|
+
return {
|
|
211
|
+
isGreater(n) {
|
|
212
|
+
return C(`(min-width: ${o[n]})`);
|
|
213
|
+
},
|
|
214
|
+
isSmaller(n) {
|
|
215
|
+
return C(`(max-width: ${o[n]})`);
|
|
216
|
+
},
|
|
217
|
+
isInBetween(n, e) {
|
|
218
|
+
return C(`(min-width: ${o[n]}) and (max-width: ${o[e]})`);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function ce(o, n, e) {
|
|
223
|
+
if (!o)
|
|
224
|
+
throw new Error("A target component has to be provided.");
|
|
225
|
+
if (!n)
|
|
226
|
+
throw new Error("A callback has to be provided.");
|
|
227
|
+
const u = (i) => {
|
|
228
|
+
!o.value || i.target === o.value || i.composedPath().includes(o.value) || typeof n == "function" && n();
|
|
229
|
+
};
|
|
230
|
+
e && k(e, (i, a) => {
|
|
231
|
+
a && a.removeEventListener("click", u), i == null || i.addEventListener("click", u);
|
|
232
|
+
}), L(() => {
|
|
233
|
+
e || document.addEventListener("click", u);
|
|
234
|
+
}), O(() => {
|
|
235
|
+
var i;
|
|
236
|
+
if (e) {
|
|
237
|
+
(i = e.value) == null || i.removeEventListener("click", u);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
document.removeEventListener("click", u);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function fe(o, n) {
|
|
244
|
+
if (!o)
|
|
245
|
+
throw new Error("A target component has to be provided.");
|
|
246
|
+
if (!n || typeof n != "function")
|
|
247
|
+
throw new Error("A callback has to be provided.");
|
|
248
|
+
const e = (u) => {
|
|
249
|
+
n(u);
|
|
250
|
+
};
|
|
251
|
+
L(() => {
|
|
252
|
+
o.value.addEventListener("keydown", e);
|
|
253
|
+
}), O(() => {
|
|
254
|
+
o.value.removeEventListener("keydown", e);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function de(o, n) {
|
|
258
|
+
if (!o || typeof o != "function")
|
|
259
|
+
throw new Error("A callback has to be provided.");
|
|
260
|
+
const e = (u) => {
|
|
261
|
+
o(u);
|
|
262
|
+
};
|
|
263
|
+
L(() => {
|
|
264
|
+
if (!n) {
|
|
265
|
+
document.addEventListener("keyup", e);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
n.value.addEventListener("keyup", e);
|
|
269
|
+
}), O(() => {
|
|
270
|
+
if (!n) {
|
|
271
|
+
document.removeEventListener("keyup", e);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
n.value.removeEventListener("keyup", e);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const me = (o) => {
|
|
278
|
+
const n = m(null), e = oe(), u = ee(() => e == null ? void 0 : e.props.amount), i = m(), a = (l) => {
|
|
279
|
+
if (l === null)
|
|
280
|
+
return "";
|
|
281
|
+
const v = {
|
|
282
|
+
minimumFractionDigits: o.minimumFractionDigits,
|
|
283
|
+
useGrouping: !1
|
|
284
|
+
};
|
|
285
|
+
return o.maximumFractionDigits !== null && (v.maximumFractionDigits = o.maximumFractionDigits), l.toLocaleString("it-IT", v);
|
|
286
|
+
}, h = (l) => parseFloat(l.replace(/,/g, ".")), r = (l) => {
|
|
287
|
+
if (!Number.isNaN(l) && e) {
|
|
288
|
+
if (i.value = l, e.props.nullOnEmpty && !l) {
|
|
289
|
+
e.emit("update:amount", null);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
e.emit("update:amount", typeof u.value == "number" ? l : l == null ? void 0 : l.toString());
|
|
293
|
+
}
|
|
294
|
+
}, t = (l) => {
|
|
295
|
+
setTimeout(() => {
|
|
296
|
+
n.value && (n.value.value = l);
|
|
297
|
+
}, 0);
|
|
298
|
+
}, d = (l) => (v) => {
|
|
299
|
+
if (!n.value || !v.target)
|
|
300
|
+
return;
|
|
301
|
+
let { value: s } = l;
|
|
302
|
+
s = s.replace(/[^0-9,.-]/g, ""), t(s);
|
|
303
|
+
const c = e != null && e.props.nullOnEmpty && s === "" ? null : h(s);
|
|
304
|
+
r(Number.isNaN(c) ? 0 : c);
|
|
305
|
+
}, g = (l) => {
|
|
306
|
+
if (!n.value || !l.target)
|
|
307
|
+
return;
|
|
308
|
+
const v = l.target.value.replace(/,/g, ".");
|
|
309
|
+
let s;
|
|
310
|
+
v === "" && (e != null && e.props.nullOnEmpty) ? s = null : (s = h(v), Number.isNaN(s) && (s = 0));
|
|
311
|
+
const c = a(s);
|
|
312
|
+
t(c), r(h(c));
|
|
313
|
+
};
|
|
314
|
+
return k(n, (l, v) => {
|
|
315
|
+
l && (v && (v == null || v.removeEventListener("input", d(l)), v == null || v.removeEventListener("blur", g)), l.addEventListener("input", d(l)), l.addEventListener("blur", g), e != null && e.props.amount && (l.value = a(u.value)));
|
|
316
|
+
}), k(u, (l) => {
|
|
317
|
+
V(() => {
|
|
318
|
+
if (!(!n.value || l === null || l === void 0) && i.value !== l) {
|
|
319
|
+
const v = a(l);
|
|
320
|
+
n.value.value = v, i.value = l;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}), {
|
|
324
|
+
inputRef: n,
|
|
325
|
+
parse: h,
|
|
326
|
+
format: a,
|
|
327
|
+
emitAmount: r,
|
|
328
|
+
setValue: t
|
|
329
|
+
};
|
|
330
|
+
}, he = /* @__PURE__ */ ne({
|
|
331
|
+
__name: "FzFloating",
|
|
332
|
+
props: {
|
|
333
|
+
isOpen: { type: Boolean, default: !1 },
|
|
334
|
+
position: { default: "auto" },
|
|
335
|
+
container: {},
|
|
336
|
+
contentClass: {},
|
|
337
|
+
openerClass: {},
|
|
338
|
+
overrideContentClass: { type: Boolean },
|
|
339
|
+
overrideOpener: {},
|
|
340
|
+
teleport: { type: Boolean, default: !1 },
|
|
341
|
+
useViewport: { type: Boolean }
|
|
342
|
+
},
|
|
343
|
+
emits: ["fzfloating:setPosition"],
|
|
344
|
+
setup(o, { emit: n }) {
|
|
345
|
+
const e = o, u = n, i = m(null), a = m(null), h = ie();
|
|
346
|
+
let r = !1;
|
|
347
|
+
const t = {
|
|
348
|
+
position: e.position,
|
|
349
|
+
element: {
|
|
350
|
+
// @ts-ignore
|
|
351
|
+
domRef: i
|
|
352
|
+
},
|
|
353
|
+
container: {
|
|
354
|
+
// @ts-ignore
|
|
355
|
+
domRef: K(e.container || document.body)
|
|
356
|
+
},
|
|
357
|
+
opener: {
|
|
358
|
+
domRef: K(null)
|
|
359
|
+
},
|
|
360
|
+
useViewport: e.useViewport,
|
|
361
|
+
callback(...s) {
|
|
362
|
+
u("fzfloating:setPosition", ...s);
|
|
363
|
+
}
|
|
364
|
+
}, d = ae(t);
|
|
365
|
+
h.opener && (t.opener = {
|
|
366
|
+
domRef: a
|
|
367
|
+
});
|
|
368
|
+
const g = ue(d), l = () => {
|
|
369
|
+
r || (r = !0, requestAnimationFrame(() => {
|
|
370
|
+
e.isOpen && g.setPosition(), r = !1;
|
|
371
|
+
}));
|
|
372
|
+
};
|
|
373
|
+
k(
|
|
374
|
+
() => e.position,
|
|
375
|
+
() => l()
|
|
376
|
+
), k(
|
|
377
|
+
() => e.isOpen,
|
|
378
|
+
(s) => {
|
|
379
|
+
if (!s || !i.value) {
|
|
380
|
+
window.removeEventListener("scroll", l);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
window.addEventListener("scroll", l), i.value.style.top = "0px", i.value.style.left = "0px", i.value.style.transform = "none", g.setPosition();
|
|
384
|
+
}
|
|
385
|
+
), k(
|
|
386
|
+
() => e.overrideOpener,
|
|
387
|
+
(s) => {
|
|
388
|
+
s && d.opener && d.opener.value && (d.opener.value = {
|
|
389
|
+
domRef: s
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
), O(() => {
|
|
393
|
+
window.removeEventListener("scroll", l);
|
|
394
|
+
});
|
|
395
|
+
const v = ee(() => e.overrideContentClass ? e.contentClass : ["bg-core-white fixed p-4 z-10", e.contentClass]);
|
|
396
|
+
return (s, c) => (B(), Q("div", null, [
|
|
397
|
+
x(s.$slots, "opener-start"),
|
|
398
|
+
X("div", {
|
|
399
|
+
ref_key: "opener",
|
|
400
|
+
ref: a,
|
|
401
|
+
class: "inline-flex"
|
|
402
|
+
}, [
|
|
403
|
+
x(s.$slots, "opener", {
|
|
404
|
+
isOpen: s.isOpen,
|
|
405
|
+
floating: F(g)
|
|
406
|
+
})
|
|
407
|
+
], 512),
|
|
408
|
+
x(s.$slots, "opener-end"),
|
|
409
|
+
s.teleport ? _("", !0) : Y((B(), Q("div", {
|
|
410
|
+
key: 0,
|
|
411
|
+
ref_key: "content",
|
|
412
|
+
ref: i,
|
|
413
|
+
class: J(["fz__floating__content", v.value])
|
|
414
|
+
}, [
|
|
415
|
+
x(s.$slots, "default", {
|
|
416
|
+
isOpen: s.isOpen,
|
|
417
|
+
floating: F(g)
|
|
418
|
+
})
|
|
419
|
+
], 2)), [
|
|
420
|
+
[Z, s.$slots.default && (!s.$slots.opener || s.$slots.opener && s.isOpen)]
|
|
421
|
+
]),
|
|
422
|
+
s.teleport ? (B(), le(se, {
|
|
423
|
+
key: 1,
|
|
424
|
+
to: "body"
|
|
425
|
+
}, [
|
|
426
|
+
Y(X("div", {
|
|
427
|
+
ref_key: "content",
|
|
428
|
+
ref: i,
|
|
429
|
+
class: J(["fz__floating__content", v.value])
|
|
430
|
+
}, [
|
|
431
|
+
x(s.$slots, "default", {
|
|
432
|
+
isOpen: s.isOpen,
|
|
433
|
+
floating: F(g)
|
|
434
|
+
})
|
|
435
|
+
], 2), [
|
|
436
|
+
[Z, s.$slots.default && (!s.$slots.opener || s.$slots.opener && s.isOpen)]
|
|
437
|
+
])
|
|
438
|
+
])) : _("", !0)
|
|
439
|
+
]));
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
export {
|
|
443
|
+
he as FzFloating,
|
|
444
|
+
pe as useBreakpoints,
|
|
445
|
+
ce as useClickOutside,
|
|
446
|
+
me as useCurrency,
|
|
447
|
+
ue as useFloating,
|
|
448
|
+
fe as useKeyDown,
|
|
449
|
+
de as useKeyUp,
|
|
450
|
+
C as useMediaQuery
|
|
451
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(h,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(h=typeof globalThis<"u"?globalThis:h||self,e(h.FzComposables={},h.Vue))})(this,function(h,e){"use strict";const R=new DOMRect(0,0,window.innerWidth,window.innerHeight),w=(n,i,t,c,a)=>{let r=a?"bottom":"right",g=a?"bottom-start":"right-start";R.width=window.innerWidth,R.height=window.innerHeight,R.x=0,R.y=0;const u=n?n.getBoundingClientRect():R,o=i.getBoundingClientRect(),m=t.getBoundingClientRect(),y=(m.left-u.left-o.width)/u.width,l=(u.right-m.right-o.width)/u.width,p=(m.top-u.top-o.height)/u.height,s=(u.bottom-m.bottom-o.height)/u.height;let d=[{key:"right",space:l},{key:"top",space:p},{key:"bottom",space:s},{key:"left",space:y}].sort((f,v)=>v.space-f.space);if(a&&(d=d.filter(f=>f.key==="top"||f.key==="bottom")),r=d[0].key,!c)switch(r){case"right":case"left":const f=(o.height-m.height)/2;u.top>m.top-f&&(c="end"),u.bottom<m.top-f&&(c="start");break}return g=c?`${r}-${c}`:r,g},I=(n,i,t,c)=>({x:i.x+n.width*t/100,y:i.y+n.height*c/100}),B=n=>{const i=e.ref(null),t=e.ref(null),c=e.ref(null),a=e.ref(),r=e.ref(),g=e.ref("auto"),u=e.ref(),o=e.reactive({position:{x:0,y:0}}),m={root:null,rootMargin:"0px",threshold:1,...n.element.value.intersectionOptions},y=(d,f)=>{},l=e.ref(new IntersectionObserver(y,m)),p=e.ref(),s=()=>e.nextTick(()=>{var C,L,O,F,S,$,N,M,z,D,P,A,T;if(p.value=n.position?n.position.value:"auto",i.value=typeof n.element.value.domRef.value=="string"?document.querySelector(n.element.value.domRef.value):n.element.value.domRef.value,(C=n.container)!=null&&C.value?(t.value=typeof((L=n.container.value)==null?void 0:L.domRef.value)=="string"?document.querySelector(n.container.value.domRef.value):(O=n.container.value)==null?void 0:O.domRef.value,t.value??(t.value=document.body)):t.value=document.body,!i.value)throw new Error("missing reference element for floating behavior");(F=n.opener)!=null&&F.value&&(c.value=typeof((S=n.opener.value)==null?void 0:S.domRef.value)=="string"?document.querySelector(n.opener.value.domRef.value):($=n.opener.value)==null?void 0:$.domRef.value),u.value=i.value.getBoundingClientRect(),a.value=(N=c.value)==null?void 0:N.getBoundingClientRect(),r.value=t.value.getBoundingClientRect();const d=window.getComputedStyle(i.value);l.value.observe(i.value),l.value.observe(t.value);let f=0,v=0;if(n.opener&&n.opener.value&&c.value&&a&&a.value){const b=a.value.left-parseFloat(d.marginLeft)-parseFloat(d.marginRight),U=a.value.left-parseFloat(d.marginLeft),E=a.value.top-parseFloat(d.marginTop)-parseFloat(d.marginBottom),W=a.value.top-parseFloat(d.marginTop);switch(p.value){case"auto":p.value=w((M=n.useViewport)!=null&&M.value?null:t.value,i.value,c.value);break;case"auto-vertical":p.value=w((z=n.useViewport)!=null&&z.value?null:t.value,i.value,c.value,void 0,!0);break;case"auto-start":p.value=w((D=n.useViewport)!=null&&D.value?null:t.value,i.value,c.value,"start");break;case"auto-vertical-start":p.value=w((P=n.useViewport)!=null&&P.value?null:t.value,i.value,c.value,"start",!0);break;case"auto-end":p.value=w((A=n.useViewport)!=null&&A.value?null:t.value,i.value,c.value,"end");break;case"auto-vertical-end":p.value=w((T=n.useViewport)!=null&&T.value?null:t.value,i.value,c.value,"end",!0);break}switch(p.value){case"bottom":o.position.y=a.value.bottom,o.position.x=U+a.value.width/2,v=-50,f=0;break;case"bottom-start":o.position.y=a.value.bottom,o.position.x=b,v=0,f=0;break;case"bottom-end":o.position.y=a.value.bottom,o.position.x=a.value.right,v=-100,f=0;break;case"left-start":o.position.y=E,o.position.x=b,v=-100,f=0;break;case"left":o.position.y=W+a.value.height/2,o.position.x=b,f=-50,v=-100;break;case"left-end":o.position.y=a.value.bottom,o.position.x=b,f=-100,v=-100;break;case"top-start":o.position.y=E,o.position.x=b,f=-100,v=0;break;case"top":o.position.y=E,o.position.x=U+a.value.width/2,v=-50,f=-100;break;case"top-end":o.position.y=E,o.position.x=a.value.right,v=-100,f=-100;break;case"right-start":o.position.y=E,o.position.x=a.value.right,v=0,f=0;break;case"right":o.position.y=W+a.value.height/2,o.position.x=a.value.right,f=-50,v=0;break;case"right-end":o.position.y=a.value.bottom,o.position.x=a.value.right,f=-100,v=0;break}}else switch(p.value){case"bottom":o.position.y=r.value.bottom-u.value.height,o.position.x=r.value.left+r.value.width/2,v=-50;break;case"left-end":case"bottom-start":o.position.y=r.value.bottom-u.value.height,o.position.x=r.value.left;break;case"right-end":case"bottom-end":o.position.y=r.value.bottom-u.value.height,o.position.x=r.value.right-u.value.width;break;case"left":o.position.y=r.value.top+(r.value.height-u.value.height)/2,o.position.x=r.value.left;break;case"top-start":case"left-start":o.position.y=r.value.top,o.position.x=r.value.left;break;case"top":o.position.y=r.value.top,o.position.x=r.value.left+(r.value.width-u.value.width)/2;break;case"top-end":case"right-start":o.position.y=r.value.top,o.position.x=r.value.right-u.value.width;case"right":o.position.y=r.value.top+(r.value.height-u.value.height)/2,o.position.x=r.value.right-u.value.width;break}const k=I(u.value,o.position,v,f);if(o.position.x=k.x,o.position.y=k.y,k.x<r.value.left&&(o.position.x=r.value.left,v=0),k.x+u.value.width>r.value.right){const b=r.value.right-u.value.width;b>0&&(o.position.x=b),v=0}if(k.y<r.value.top&&(o.position.y=r.value.top,f=0),k.y+u.value.height>r.value.bottom){const b=r.value.bottom-u.value.height;b>0&&(o.position.y=b),f=0}i.value.style.top=`${o.position.y}px`,i.value.style.left=`${o.position.x}px`,i.value.style.position="fixed",i.value.style.display="flex",u.value=i.value.getBoundingClientRect(),n.callback&&n.callback.value&&n.callback.value(u,a,r,g,p)});return e.onUnmounted(()=>{l.value.disconnect()}),{float:o,rect:u,setPosition:s,position:g,actualPosition:p,openerRect:a,containerRect:r}};function x(n){const i=window.matchMedia(n),t=e.ref(i.matches);function c(a){t.value=a.matches}return e.onMounted(()=>{i.addEventListener("change",c)}),e.onUnmounted(()=>{i.removeEventListener("change",c)}),t}function q(n){return{isGreater(i){return x(`(min-width: ${n[i]})`)},isSmaller(i){return x(`(max-width: ${n[i]})`)},isInBetween(i,t){return x(`(min-width: ${n[i]}) and (max-width: ${n[t]})`)}}}function K(n,i,t){if(!n)throw new Error("A target component has to be provided.");if(!i)throw new Error("A callback has to be provided.");const c=a=>{!n.value||a.target===n.value||a.composedPath().includes(n.value)||typeof i=="function"&&i()};t&&e.watch(t,(a,r)=>{r&&r.removeEventListener("click",c),a==null||a.addEventListener("click",c)}),e.onMounted(()=>{t||document.addEventListener("click",c)}),e.onBeforeUnmount(()=>{var a;if(t){(a=t.value)==null||a.removeEventListener("click",c);return}document.removeEventListener("click",c)})}function H(n,i){if(!n)throw new Error("A target component has to be provided.");if(!i||typeof i!="function")throw new Error("A callback has to be provided.");const t=c=>{i(c)};e.onMounted(()=>{n.value.addEventListener("keydown",t)}),e.onBeforeUnmount(()=>{n.value.removeEventListener("keydown",t)})}function Q(n,i){if(!n||typeof n!="function")throw new Error("A callback has to be provided.");const t=c=>{n(c)};e.onMounted(()=>{if(!i){document.addEventListener("keyup",t);return}i.value.addEventListener("keyup",t)}),e.onBeforeUnmount(()=>{if(!i){document.removeEventListener("keyup",t);return}i.value.removeEventListener("keyup",t)})}const G=n=>{const i=e.ref(null),t=e.getCurrentInstance(),c=e.computed(()=>t==null?void 0:t.props.amount),a=e.ref(),r=l=>{if(l===null)return"";const p={minimumFractionDigits:n.minimumFractionDigits,useGrouping:!1};return n.maximumFractionDigits!==null&&(p.maximumFractionDigits=n.maximumFractionDigits),l.toLocaleString("it-IT",p)},g=l=>parseFloat(l.replace(/,/g,".")),u=l=>{if(!Number.isNaN(l)&&t){if(a.value=l,t.props.nullOnEmpty&&!l){t.emit("update:amount",null);return}t.emit("update:amount",typeof c.value=="number"?l:l==null?void 0:l.toString())}},o=l=>{setTimeout(()=>{i.value&&(i.value.value=l)},0)},m=l=>p=>{if(!i.value||!p.target)return;let{value:s}=l;s=s.replace(/[^0-9,.-]/g,""),o(s);const d=t!=null&&t.props.nullOnEmpty&&s===""?null:g(s);u(Number.isNaN(d)?0:d)},y=l=>{if(!i.value||!l.target)return;const p=l.target.value.replace(/,/g,".");let s;p===""&&(t!=null&&t.props.nullOnEmpty)?s=null:(s=g(p),Number.isNaN(s)&&(s=0));const d=r(s);o(d),u(g(d))};return e.watch(i,(l,p)=>{l&&(p&&(p==null||p.removeEventListener("input",m(l)),p==null||p.removeEventListener("blur",y)),l.addEventListener("input",m(l)),l.addEventListener("blur",y),t!=null&&t.props.amount&&(l.value=r(c.value)))}),e.watch(c,l=>{e.nextTick(()=>{if(!(!i.value||l===null||l===void 0)&&a.value!==l){const p=r(l);i.value.value=p,a.value=l}})}),{inputRef:i,parse:g,format:r,emitAmount:u,setValue:o}},X=e.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{},contentClass:{},openerClass:{},overrideContentClass:{type:Boolean},overrideOpener:{},teleport:{type:Boolean,default:!1},useViewport:{type:Boolean}},emits:["fzfloating:setPosition"],setup(n,{emit:i}){const t=n,c=i,a=e.ref(null),r=e.ref(null),g=e.useSlots();let u=!1;const o={position:t.position,element:{domRef:a},container:{domRef:e.toRef(t.container||document.body)},opener:{domRef:e.toRef(null)},useViewport:t.useViewport,callback(...s){c("fzfloating:setPosition",...s)}},m=e.toRefs(o);g.opener&&(o.opener={domRef:r});const y=B(m),l=()=>{u||(u=!0,requestAnimationFrame(()=>{t.isOpen&&y.setPosition(),u=!1}))};e.watch(()=>t.position,()=>l()),e.watch(()=>t.isOpen,s=>{if(!s||!a.value){window.removeEventListener("scroll",l);return}window.addEventListener("scroll",l),a.value.style.top="0px",a.value.style.left="0px",a.value.style.transform="none",y.setPosition()}),e.watch(()=>t.overrideOpener,s=>{s&&m.opener&&m.opener.value&&(m.opener.value={domRef:s})}),e.onBeforeUnmount(()=>{window.removeEventListener("scroll",l)});const p=e.computed(()=>t.overrideContentClass?t.contentClass:["bg-core-white fixed p-4 z-10",t.contentClass]);return(s,d)=>(e.openBlock(),e.createElementBlock("div",null,[e.renderSlot(s.$slots,"opener-start"),e.createElementVNode("div",{ref_key:"opener",ref:r,class:"inline-flex"},[e.renderSlot(s.$slots,"opener",{isOpen:s.isOpen,floating:e.unref(y)})],512),e.renderSlot(s.$slots,"opener-end"),s.teleport?e.createCommentVNode("",!0):e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"content",ref:a,class:e.normalizeClass(["fz__floating__content",p.value])},[e.renderSlot(s.$slots,"default",{isOpen:s.isOpen,floating:e.unref(y)})],2)),[[e.vShow,s.$slots.default&&(!s.$slots.opener||s.$slots.opener&&s.isOpen)]]),s.teleport?(e.openBlock(),e.createBlock(e.Teleport,{key:1,to:"body"},[e.withDirectives(e.createElementVNode("div",{ref_key:"content",ref:a,class:e.normalizeClass(["fz__floating__content",p.value])},[e.renderSlot(s.$slots,"default",{isOpen:s.isOpen,floating:e.unref(y)})],2),[[e.vShow,s.$slots.default&&(!s.$slots.opener||s.$slots.opener&&s.isOpen)]])])):e.createCommentVNode("",!0)]))}});h.FzFloating=X,h.useBreakpoints=q,h.useClickOutside=K,h.useCurrency=G,h.useFloating=B,h.useKeyDown=H,h.useKeyUp=Q,h.useMediaQuery=x,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiscozen/composables",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Design System utility composables",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"coverage": "vitest run --coverage",
|
|
7
|
-
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
|
|
8
|
-
"format": "prettier --write src/",
|
|
9
|
-
"test:unit": "vitest run",
|
|
10
|
-
"build": "vite build"
|
|
11
|
-
},
|
|
12
5
|
"main": "src/index.ts",
|
|
13
6
|
"type": "module",
|
|
14
7
|
"keywords": [],
|
|
@@ -18,9 +11,6 @@
|
|
|
18
11
|
"vue": "^3.4.13"
|
|
19
12
|
},
|
|
20
13
|
"devDependencies": {
|
|
21
|
-
"@fiscozen/eslint-config": "workspace:^",
|
|
22
|
-
"@fiscozen/prettier-config": "workspace:^",
|
|
23
|
-
"@fiscozen/tsconfig": "workspace:^",
|
|
24
14
|
"@rushstack/eslint-patch": "^1.3.3",
|
|
25
15
|
"@types/jsdom": "^21.1.6",
|
|
26
16
|
"@types/node": "^18.19.3",
|
|
@@ -34,7 +24,17 @@
|
|
|
34
24
|
"typescript": "~5.3.0",
|
|
35
25
|
"vite": "^5.0.10",
|
|
36
26
|
"vitest": "^1.2.0",
|
|
37
|
-
"vue-tsc": "^1.8.25"
|
|
27
|
+
"vue-tsc": "^1.8.25",
|
|
28
|
+
"@fiscozen/eslint-config": "^0.1.0",
|
|
29
|
+
"@fiscozen/prettier-config": "^0.1.0",
|
|
30
|
+
"@fiscozen/tsconfig": "^0.1.0"
|
|
38
31
|
},
|
|
39
|
-
"license": "ISC"
|
|
40
|
-
|
|
32
|
+
"license": "ISC",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"coverage": "vitest run --coverage",
|
|
35
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
|
|
36
|
+
"format": "prettier --write src/",
|
|
37
|
+
"test:unit": "vitest run",
|
|
38
|
+
"build": "vite build"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/FzFloating.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { ref, useSlots, watch, toRef, computed,
|
|
2
|
+
import { ref, useSlots, watch, toRef, computed, onBeforeUnmount, toRefs } from 'vue'
|
|
3
3
|
import { useFloating } from './composables'
|
|
4
4
|
import { FzFloatingProps, FzUseFloatingArgs } from './types'
|
|
5
5
|
|
|
@@ -11,15 +11,15 @@ const props = withDefaults(defineProps<FzFloatingProps>(), {
|
|
|
11
11
|
|
|
12
12
|
const emits = defineEmits(['fzfloating:setPosition'])
|
|
13
13
|
|
|
14
|
-
const opener = ref(null)
|
|
15
14
|
const content = ref<HTMLElement | null>(null)
|
|
15
|
+
const opener = ref<HTMLElement | null>(null)
|
|
16
16
|
|
|
17
17
|
const slots = useSlots()
|
|
18
18
|
|
|
19
19
|
let scheduledAnimationFrame = false
|
|
20
20
|
|
|
21
21
|
const useFloatingOpts: FzUseFloatingArgs = {
|
|
22
|
-
position:
|
|
22
|
+
position: props.position,
|
|
23
23
|
element: {
|
|
24
24
|
// @ts-ignore
|
|
25
25
|
domRef: content
|
|
@@ -28,18 +28,23 @@ const useFloatingOpts: FzUseFloatingArgs = {
|
|
|
28
28
|
// @ts-ignore
|
|
29
29
|
domRef: toRef(props.container || document.body)
|
|
30
30
|
},
|
|
31
|
-
|
|
31
|
+
opener: {
|
|
32
|
+
domRef: toRef(null)
|
|
33
|
+
},
|
|
34
|
+
useViewport: props.useViewport,
|
|
32
35
|
callback(...args) {
|
|
33
36
|
emits('fzfloating:setPosition', ...args)
|
|
34
37
|
}
|
|
35
38
|
}
|
|
39
|
+
|
|
40
|
+
const dynamicOpts = toRefs(useFloatingOpts)
|
|
36
41
|
if (slots.opener) {
|
|
37
42
|
useFloatingOpts.opener = {
|
|
38
43
|
domRef: opener
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
const floating = useFloating(
|
|
47
|
+
const floating = useFloating(dynamicOpts)
|
|
43
48
|
|
|
44
49
|
const setPositionWhenOpen = () => {
|
|
45
50
|
if (scheduledAnimationFrame) {
|
|
@@ -71,6 +76,19 @@ watch(
|
|
|
71
76
|
floating.setPosition()
|
|
72
77
|
}
|
|
73
78
|
)
|
|
79
|
+
watch(
|
|
80
|
+
() => props.overrideOpener,
|
|
81
|
+
(newVal) => {
|
|
82
|
+
if (!newVal) {
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
if (dynamicOpts.opener && dynamicOpts.opener.value) {
|
|
86
|
+
dynamicOpts.opener.value = {
|
|
87
|
+
domRef: newVal
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
)
|
|
74
92
|
onBeforeUnmount(() => {
|
|
75
93
|
window.removeEventListener('scroll', setPositionWhenOpen)
|
|
76
94
|
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
exports[`FzFloating > should match snapshot 1`] = `
|
|
4
4
|
"<div>
|
|
5
5
|
<div class="inline-flex"><button>opener</button></div>
|
|
6
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
6
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
7
7
|
<div>content</div>
|
|
8
8
|
</div>
|
|
9
9
|
<!--v-if-->
|
|
@@ -13,7 +13,7 @@ exports[`FzFloating > should match snapshot 1`] = `
|
|
|
13
13
|
exports[`FzFloating > should match snapshot 2`] = `
|
|
14
14
|
"<div>
|
|
15
15
|
<div class="inline-flex"><button>opener</button></div>
|
|
16
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
16
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
17
17
|
<div>content</div>
|
|
18
18
|
</div>
|
|
19
19
|
<!--v-if-->
|
|
@@ -23,7 +23,7 @@ exports[`FzFloating > should match snapshot 2`] = `
|
|
|
23
23
|
exports[`FzFloating > should match snapshot 3`] = `
|
|
24
24
|
"<div>
|
|
25
25
|
<div class="inline-flex"><button>opener</button></div>
|
|
26
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
26
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
27
27
|
<div>content</div>
|
|
28
28
|
</div>
|
|
29
29
|
<!--v-if-->
|
|
@@ -33,7 +33,7 @@ exports[`FzFloating > should match snapshot 3`] = `
|
|
|
33
33
|
exports[`FzFloating > should match snapshot 4`] = `
|
|
34
34
|
"<div>
|
|
35
35
|
<div class="inline-flex"><button>opener</button></div>
|
|
36
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
36
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
37
37
|
<div>content</div>
|
|
38
38
|
</div>
|
|
39
39
|
<!--v-if-->
|
|
@@ -43,7 +43,7 @@ exports[`FzFloating > should match snapshot 4`] = `
|
|
|
43
43
|
exports[`FzFloating > should match snapshot 5`] = `
|
|
44
44
|
"<div>
|
|
45
45
|
<div class="inline-flex"><button>opener</button></div>
|
|
46
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
46
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
47
47
|
<div>content</div>
|
|
48
48
|
</div>
|
|
49
49
|
<!--v-if-->
|
|
@@ -53,7 +53,7 @@ exports[`FzFloating > should match snapshot 5`] = `
|
|
|
53
53
|
exports[`FzFloating > should match snapshot 6`] = `
|
|
54
54
|
"<div>
|
|
55
55
|
<div class="inline-flex"><button>opener</button></div>
|
|
56
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
56
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
57
57
|
<div>content</div>
|
|
58
58
|
</div>
|
|
59
59
|
<!--v-if-->
|
|
@@ -63,7 +63,7 @@ exports[`FzFloating > should match snapshot 6`] = `
|
|
|
63
63
|
exports[`FzFloating > should match snapshot 7`] = `
|
|
64
64
|
"<div>
|
|
65
65
|
<div class="inline-flex"><button>opener</button></div>
|
|
66
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
66
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
67
67
|
<div>content</div>
|
|
68
68
|
</div>
|
|
69
69
|
<!--v-if-->
|
|
@@ -73,7 +73,7 @@ exports[`FzFloating > should match snapshot 7`] = `
|
|
|
73
73
|
exports[`FzFloating > should match snapshot 8`] = `
|
|
74
74
|
"<div>
|
|
75
75
|
<div class="inline-flex"><button>opener</button></div>
|
|
76
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
76
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
77
77
|
<div>content</div>
|
|
78
78
|
</div>
|
|
79
79
|
<!--v-if-->
|
|
@@ -83,7 +83,7 @@ exports[`FzFloating > should match snapshot 8`] = `
|
|
|
83
83
|
exports[`FzFloating > should match snapshot 9`] = `
|
|
84
84
|
"<div>
|
|
85
85
|
<div class="inline-flex"><button>opener</button></div>
|
|
86
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
86
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
87
87
|
<div>content</div>
|
|
88
88
|
</div>
|
|
89
89
|
<!--v-if-->
|
|
@@ -93,7 +93,7 @@ exports[`FzFloating > should match snapshot 9`] = `
|
|
|
93
93
|
exports[`FzFloating > should match snapshot 10`] = `
|
|
94
94
|
"<div>
|
|
95
95
|
<div class="inline-flex"><button>opener</button></div>
|
|
96
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
96
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
97
97
|
<div>content</div>
|
|
98
98
|
</div>
|
|
99
99
|
<!--v-if-->
|
|
@@ -103,7 +103,7 @@ exports[`FzFloating > should match snapshot 10`] = `
|
|
|
103
103
|
exports[`FzFloating > should match snapshot 11`] = `
|
|
104
104
|
"<div>
|
|
105
105
|
<div class="inline-flex"><button>opener</button></div>
|
|
106
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
106
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
107
107
|
<div>content</div>
|
|
108
108
|
</div>
|
|
109
109
|
<!--v-if-->
|
|
@@ -113,7 +113,7 @@ exports[`FzFloating > should match snapshot 11`] = `
|
|
|
113
113
|
exports[`FzFloating > should match snapshot 12`] = `
|
|
114
114
|
"<div>
|
|
115
115
|
<div class="inline-flex"><button>opener</button></div>
|
|
116
|
-
<div class="fz__floating__content bg-core-white fixed
|
|
116
|
+
<div class="fz__floating__content bg-core-white fixed p-4 z-10">
|
|
117
117
|
<div>content</div>
|
|
118
118
|
</div>
|
|
119
119
|
<!--v-if-->
|
|
@@ -44,7 +44,7 @@ function useClickOutside(
|
|
|
44
44
|
|
|
45
45
|
onBeforeUnmount(() => {
|
|
46
46
|
if (elementToListenClicksOn) {
|
|
47
|
-
elementToListenClicksOn.value
|
|
47
|
+
elementToListenClicksOn.value?.removeEventListener('click', listener)
|
|
48
48
|
return
|
|
49
49
|
}
|
|
50
50
|
document.removeEventListener('click', listener)
|
|
@@ -15,7 +15,7 @@ export const useCurrency = (options: FzUseCurrencyOptions) => {
|
|
|
15
15
|
const safeOptions: Intl.NumberFormatOptions = {
|
|
16
16
|
minimumFractionDigits: options.minimumFractionDigits,
|
|
17
17
|
useGrouping: false
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
if (options.maximumFractionDigits !== null) {
|
|
20
20
|
safeOptions.maximumFractionDigits = options.maximumFractionDigits
|
|
21
21
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FzFloatingPosition, FzRect, FzUseFloatingArgs } from '../types'
|
|
2
|
-
import { ref, reactive, onUnmounted, Ref, nextTick } from 'vue'
|
|
2
|
+
import { ref, reactive, onUnmounted, Ref, nextTick, ToRefs } from 'vue'
|
|
3
3
|
import { calcRealPos, getHighestAvailableSpacePos } from '../utils'
|
|
4
4
|
|
|
5
5
|
export const useFloating = (
|
|
6
|
-
args: FzUseFloatingArgs
|
|
6
|
+
args: ToRefs<FzUseFloatingArgs>
|
|
7
7
|
): {
|
|
8
8
|
float: FzRect
|
|
9
9
|
rect: Ref<DOMRect | undefined>
|
|
@@ -27,7 +27,7 @@ export const useFloating = (
|
|
|
27
27
|
root: null,
|
|
28
28
|
rootMargin: '0px',
|
|
29
29
|
threshold: 1.0,
|
|
30
|
-
...args.element.intersectionOptions
|
|
30
|
+
...args.element.value.intersectionOptions
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const handleIntersect = (
|
|
@@ -42,17 +42,17 @@ export const useFloating = (
|
|
|
42
42
|
nextTick(() => {
|
|
43
43
|
actualPosition.value = args.position ? args.position.value : 'auto'
|
|
44
44
|
safeElementDomRef.value = (
|
|
45
|
-
typeof args.element.domRef.value === 'string'
|
|
46
|
-
? document.querySelector(args.element.domRef.value)
|
|
47
|
-
: args.element.domRef.value
|
|
45
|
+
typeof args.element.value.domRef.value === 'string'
|
|
46
|
+
? document.querySelector(args.element.value.domRef.value)
|
|
47
|
+
: args.element.value.domRef.value
|
|
48
48
|
) as HTMLElement
|
|
49
|
-
if (!args.container) {
|
|
49
|
+
if (!args.container?.value) {
|
|
50
50
|
safeContainerDomRef.value = document.body
|
|
51
51
|
} else {
|
|
52
52
|
safeContainerDomRef.value = (
|
|
53
|
-
typeof args.container.domRef.value === 'string'
|
|
54
|
-
? document.querySelector(args.container.domRef.value)
|
|
55
|
-
: args.container.domRef.value
|
|
53
|
+
typeof args.container.value?.domRef.value === 'string'
|
|
54
|
+
? document.querySelector(args.container.value.domRef.value)
|
|
55
|
+
: args.container.value?.domRef.value
|
|
56
56
|
) as HTMLElement
|
|
57
57
|
safeContainerDomRef.value ??= document.body
|
|
58
58
|
}
|
|
@@ -61,11 +61,11 @@ export const useFloating = (
|
|
|
61
61
|
throw new Error('missing reference element for floating behavior')
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
if (args.opener) {
|
|
64
|
+
if (args.opener?.value) {
|
|
65
65
|
safeOpenerDomRef.value = (
|
|
66
|
-
typeof args.opener.domRef.value === 'string'
|
|
67
|
-
? document.querySelector(args.opener.domRef.value)
|
|
68
|
-
: args.opener.domRef.value
|
|
66
|
+
typeof args.opener.value?.domRef.value === 'string'
|
|
67
|
+
? document.querySelector(args.opener.value.domRef.value)
|
|
68
|
+
: args.opener.value?.domRef.value
|
|
69
69
|
) as HTMLElement
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -82,7 +82,11 @@ export const useFloating = (
|
|
|
82
82
|
let translateY = 0
|
|
83
83
|
let translateX = 0
|
|
84
84
|
|
|
85
|
-
if (
|
|
85
|
+
if (
|
|
86
|
+
args.opener?.value &&
|
|
87
|
+
safeOpenerDomRef.value &&
|
|
88
|
+
openerRect?.value
|
|
89
|
+
) {
|
|
86
90
|
const leftWithoutXMargin =
|
|
87
91
|
openerRect.value.left - parseFloat(elStyle.marginLeft) - parseFloat(elStyle.marginRight)
|
|
88
92
|
const leftWithoutLeftMargin = openerRect.value.left - parseFloat(elStyle.marginLeft)
|
|
@@ -93,14 +97,14 @@ export const useFloating = (
|
|
|
93
97
|
switch (actualPosition.value) {
|
|
94
98
|
case 'auto':
|
|
95
99
|
actualPosition.value = getHighestAvailableSpacePos(
|
|
96
|
-
args.useViewport ? null : (safeContainerDomRef.value as HTMLElement),
|
|
100
|
+
args.useViewport?.value ? null : (safeContainerDomRef.value as HTMLElement),
|
|
97
101
|
safeElementDomRef.value as HTMLElement,
|
|
98
102
|
safeOpenerDomRef.value as HTMLElement
|
|
99
103
|
)
|
|
100
104
|
break
|
|
101
105
|
case 'auto-vertical':
|
|
102
106
|
actualPosition.value = getHighestAvailableSpacePos(
|
|
103
|
-
args.useViewport ? null : (safeContainerDomRef.value as HTMLElement),
|
|
107
|
+
args.useViewport?.value ? null : (safeContainerDomRef.value as HTMLElement),
|
|
104
108
|
safeElementDomRef.value as HTMLElement,
|
|
105
109
|
safeOpenerDomRef.value as HTMLElement,
|
|
106
110
|
undefined,
|
|
@@ -109,7 +113,7 @@ export const useFloating = (
|
|
|
109
113
|
break
|
|
110
114
|
case 'auto-start':
|
|
111
115
|
actualPosition.value = getHighestAvailableSpacePos(
|
|
112
|
-
args.useViewport ? null : (safeContainerDomRef.value as HTMLElement),
|
|
116
|
+
args.useViewport?.value ? null : (safeContainerDomRef.value as HTMLElement),
|
|
113
117
|
safeElementDomRef.value as HTMLElement,
|
|
114
118
|
safeOpenerDomRef.value as HTMLElement,
|
|
115
119
|
'start'
|
|
@@ -117,7 +121,7 @@ export const useFloating = (
|
|
|
117
121
|
break
|
|
118
122
|
case 'auto-vertical-start':
|
|
119
123
|
actualPosition.value = getHighestAvailableSpacePos(
|
|
120
|
-
args.useViewport ? null : (safeContainerDomRef.value as HTMLElement),
|
|
124
|
+
args.useViewport?.value ? null : (safeContainerDomRef.value as HTMLElement),
|
|
121
125
|
safeElementDomRef.value as HTMLElement,
|
|
122
126
|
safeOpenerDomRef.value as HTMLElement,
|
|
123
127
|
'start',
|
|
@@ -126,7 +130,7 @@ export const useFloating = (
|
|
|
126
130
|
break
|
|
127
131
|
case 'auto-end':
|
|
128
132
|
actualPosition.value = getHighestAvailableSpacePos(
|
|
129
|
-
args.useViewport ? null : (safeContainerDomRef.value as HTMLElement),
|
|
133
|
+
args.useViewport?.value ? null : (safeContainerDomRef.value as HTMLElement),
|
|
130
134
|
safeElementDomRef.value as HTMLElement,
|
|
131
135
|
safeOpenerDomRef.value as HTMLElement,
|
|
132
136
|
'end'
|
|
@@ -134,7 +138,7 @@ export const useFloating = (
|
|
|
134
138
|
break
|
|
135
139
|
case 'auto-vertical-end':
|
|
136
140
|
actualPosition.value = getHighestAvailableSpacePos(
|
|
137
|
-
args.useViewport ? null : (safeContainerDomRef.value as HTMLElement),
|
|
141
|
+
args.useViewport?.value ? null : (safeContainerDomRef.value as HTMLElement),
|
|
138
142
|
safeElementDomRef.value as HTMLElement,
|
|
139
143
|
safeOpenerDomRef.value as HTMLElement,
|
|
140
144
|
'end',
|
|
@@ -304,7 +308,9 @@ export const useFloating = (
|
|
|
304
308
|
|
|
305
309
|
rect.value = safeElementDomRef.value.getBoundingClientRect()
|
|
306
310
|
|
|
307
|
-
|
|
311
|
+
if (args.callback?.value) {
|
|
312
|
+
args.callback.value(rect, openerRect, containerRect, position, actualPosition)
|
|
313
|
+
}
|
|
308
314
|
})
|
|
309
315
|
|
|
310
316
|
onUnmounted(() => {
|
package/src/types.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface FzFloatingProps {
|
|
|
19
19
|
| Record<string, boolean | undefined>
|
|
20
20
|
| Array<string | Record<string, boolean | undefined>>
|
|
21
21
|
overrideContentClass?: boolean
|
|
22
|
+
overrideOpener?: Ref<HTMLElement>
|
|
22
23
|
teleport?: boolean
|
|
23
24
|
useViewport?: boolean
|
|
24
25
|
}
|
|
@@ -39,9 +40,9 @@ export interface FzFloatElement {
|
|
|
39
40
|
export interface FzUseFloatingArgs {
|
|
40
41
|
element: FzFloatElement
|
|
41
42
|
container?: FzFloatElement
|
|
42
|
-
opener
|
|
43
|
-
position?:
|
|
44
|
-
useViewport?:
|
|
43
|
+
opener: FzFloatElement
|
|
44
|
+
position?: FzFloatingPosition
|
|
45
|
+
useViewport?: boolean
|
|
45
46
|
callback?: (
|
|
46
47
|
rect: Ref<DOMRect | undefined>,
|
|
47
48
|
openerRect: Ref<DOMRect | undefined>,
|
|
@@ -52,6 +53,6 @@ export interface FzUseFloatingArgs {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export interface FzUseCurrencyOptions {
|
|
55
|
-
minimumFractionDigits: number
|
|
56
|
-
maximumFractionDigits: number|null
|
|
57
|
-
}
|
|
56
|
+
minimumFractionDigits: number
|
|
57
|
+
maximumFractionDigits: number | null
|
|
58
|
+
}
|