@fiscozen/composables 0.1.29 → 0.1.31
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 +107 -106
- package/dist/composables.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/FzFloating.vue +1 -0
- package/src/composables/useCurrency.ts +2 -18
- package/src/composables/useFloating.ts +2 -6
- package/src/types.ts +2 -1
- package/src/utils/index.ts +2 -93
- package/src/utils/number/index.ts +19 -0
- package/src/utils/position/index.ts +94 -0
package/dist/composables.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ref as m, reactive as
|
|
1
|
+
import { ref as m, reactive as ne, onUnmounted as ee, nextTick as te, onMounted as L, watch as k, onBeforeUnmount as O, getCurrentInstance as ie, computed as oe, defineComponent as ae, useSlots as se, toRef as X, toRefs as le, openBlock as B, createElementBlock as Y, renderSlot as R, createElementVNode as J, unref as F, withDirectives as Z, normalizeClass as _, vShow as j, createCommentVNode as V, createBlock as re, Teleport as ue } from "vue";
|
|
2
2
|
const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e, u, i) => {
|
|
3
3
|
let a = i ? "bottom" : "right", h = i ? "bottom-start" : "right-start";
|
|
4
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,
|
|
5
|
+
const r = o ? o.getBoundingClientRect() : E, t = n.getBoundingClientRect(), d = e.getBoundingClientRect(), g = (d.left - r.left - t.width) / r.width, s = (r.right - d.right - t.width) / r.width, v = (d.top - r.top - t.height) / r.height, l = (r.bottom - d.bottom - t.height) / r.height;
|
|
6
6
|
let c = [
|
|
7
7
|
{
|
|
8
8
|
key: "right",
|
|
9
|
-
space:
|
|
9
|
+
space: s
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
key: "top",
|
|
@@ -14,7 +14,7 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
key: "bottom",
|
|
17
|
-
space:
|
|
17
|
+
space: l
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
key: "left",
|
|
@@ -30,11 +30,11 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
30
30
|
break;
|
|
31
31
|
}
|
|
32
32
|
return h = u ? `${a}-${u}` : a, h;
|
|
33
|
-
},
|
|
33
|
+
}, ve = (o, n, e, u) => ({
|
|
34
34
|
x: n.x + o.width * e / 100,
|
|
35
35
|
y: n.y + o.height * u / 100
|
|
36
|
-
}),
|
|
37
|
-
const n = m(null), e = m(null), u = m(null), i = m(), a = m(), h = m("auto"), r = m(), t =
|
|
36
|
+
}), pe = (o) => {
|
|
37
|
+
const n = m(null), e = m(null), u = m(null), i = m(), a = m(), h = m("auto"), r = m(), t = ne({
|
|
38
38
|
position: { x: 0, y: 0 }
|
|
39
39
|
}), d = {
|
|
40
40
|
root: null,
|
|
@@ -42,27 +42,27 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
42
42
|
threshold: 1,
|
|
43
43
|
...o.element.value.intersectionOptions
|
|
44
44
|
}, g = (c, p) => {
|
|
45
|
-
},
|
|
46
|
-
var $, N, z, P, S, D, M, A, W, I, q, T, H;
|
|
45
|
+
}, s = m(new IntersectionObserver(g, d)), v = m(), l = () => te(() => {
|
|
46
|
+
var $, N, z, P, S, D, M, A, W, I, q, T, G, H, U;
|
|
47
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
48
|
throw new Error("missing reference element for floating behavior");
|
|
49
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
50
|
const c = window.getComputedStyle(n.value);
|
|
51
|
-
|
|
51
|
+
s.value.observe(n.value), s.value.observe(e.value);
|
|
52
52
|
let p = 0, f = 0;
|
|
53
|
-
if (o.opener &&
|
|
54
|
-
const y = i.value.left - parseFloat(c.marginLeft) - parseFloat(c.marginRight),
|
|
53
|
+
if ((A = o.opener) != null && A.value && u.value && (i != null && i.value)) {
|
|
54
|
+
const y = i.value.left - parseFloat(c.marginLeft) - parseFloat(c.marginRight), K = i.value.left - parseFloat(c.marginLeft), x = i.value.top - parseFloat(c.marginTop) - parseFloat(c.marginBottom), Q = i.value.top - parseFloat(c.marginTop);
|
|
55
55
|
switch (v.value) {
|
|
56
56
|
case "auto":
|
|
57
57
|
v.value = w(
|
|
58
|
-
(
|
|
58
|
+
(W = o.useViewport) != null && W.value ? null : e.value,
|
|
59
59
|
n.value,
|
|
60
60
|
u.value
|
|
61
61
|
);
|
|
62
62
|
break;
|
|
63
63
|
case "auto-vertical":
|
|
64
64
|
v.value = w(
|
|
65
|
-
(
|
|
65
|
+
(I = o.useViewport) != null && I.value ? null : e.value,
|
|
66
66
|
n.value,
|
|
67
67
|
u.value,
|
|
68
68
|
void 0,
|
|
@@ -71,7 +71,7 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
71
71
|
break;
|
|
72
72
|
case "auto-start":
|
|
73
73
|
v.value = w(
|
|
74
|
-
(
|
|
74
|
+
(q = o.useViewport) != null && q.value ? null : e.value,
|
|
75
75
|
n.value,
|
|
76
76
|
u.value,
|
|
77
77
|
"start"
|
|
@@ -79,7 +79,7 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
79
79
|
break;
|
|
80
80
|
case "auto-vertical-start":
|
|
81
81
|
v.value = w(
|
|
82
|
-
(
|
|
82
|
+
(T = o.useViewport) != null && T.value ? null : e.value,
|
|
83
83
|
n.value,
|
|
84
84
|
u.value,
|
|
85
85
|
"start",
|
|
@@ -88,7 +88,7 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
88
88
|
break;
|
|
89
89
|
case "auto-end":
|
|
90
90
|
v.value = w(
|
|
91
|
-
(
|
|
91
|
+
(G = o.useViewport) != null && G.value ? null : e.value,
|
|
92
92
|
n.value,
|
|
93
93
|
u.value,
|
|
94
94
|
"end"
|
|
@@ -106,7 +106,7 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
106
106
|
}
|
|
107
107
|
switch (v.value) {
|
|
108
108
|
case "bottom":
|
|
109
|
-
t.position.y = i.value.bottom, t.position.x =
|
|
109
|
+
t.position.y = i.value.bottom, t.position.x = K + i.value.width / 2, f = -50, p = 0;
|
|
110
110
|
break;
|
|
111
111
|
case "bottom-start":
|
|
112
112
|
t.position.y = i.value.bottom, t.position.x = y, f = 0, p = 0;
|
|
@@ -115,28 +115,28 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
115
115
|
t.position.y = i.value.bottom, t.position.x = i.value.right, f = -100, p = 0;
|
|
116
116
|
break;
|
|
117
117
|
case "left-start":
|
|
118
|
-
t.position.y =
|
|
118
|
+
t.position.y = x, t.position.x = y, f = -100, p = 0;
|
|
119
119
|
break;
|
|
120
120
|
case "left":
|
|
121
|
-
t.position.y =
|
|
121
|
+
t.position.y = Q + i.value.height / 2, t.position.x = y, p = -50, f = -100;
|
|
122
122
|
break;
|
|
123
123
|
case "left-end":
|
|
124
124
|
t.position.y = i.value.bottom, t.position.x = y, p = -100, f = -100;
|
|
125
125
|
break;
|
|
126
126
|
case "top-start":
|
|
127
|
-
t.position.y =
|
|
127
|
+
t.position.y = x, t.position.x = y, p = -100, f = 0;
|
|
128
128
|
break;
|
|
129
129
|
case "top":
|
|
130
|
-
t.position.y =
|
|
130
|
+
t.position.y = x, t.position.x = K + i.value.width / 2, f = -50, p = -100;
|
|
131
131
|
break;
|
|
132
132
|
case "top-end":
|
|
133
|
-
t.position.y =
|
|
133
|
+
t.position.y = x, t.position.x = i.value.right, f = -100, p = -100;
|
|
134
134
|
break;
|
|
135
135
|
case "right-start":
|
|
136
|
-
t.position.y =
|
|
136
|
+
t.position.y = x, t.position.x = i.value.right, f = 0, p = 0;
|
|
137
137
|
break;
|
|
138
138
|
case "right":
|
|
139
|
-
t.position.y =
|
|
139
|
+
t.position.y = Q + i.value.height / 2, t.position.x = i.value.right, p = -50, f = 0;
|
|
140
140
|
break;
|
|
141
141
|
case "right-end":
|
|
142
142
|
t.position.y = i.value.bottom, t.position.x = i.value.right, p = -100, f = 0;
|
|
@@ -172,7 +172,7 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
172
172
|
t.position.y = a.value.top + (a.value.height - r.value.height) / 2, t.position.x = a.value.right - r.value.width;
|
|
173
173
|
break;
|
|
174
174
|
}
|
|
175
|
-
const b =
|
|
175
|
+
const b = ve(r.value, t.position, f, p);
|
|
176
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
177
|
const y = a.value.right - r.value.width;
|
|
178
178
|
y > 0 && (t.position.x = y), f = 0;
|
|
@@ -181,14 +181,14 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, n, e
|
|
|
181
181
|
const y = a.value.bottom - r.value.height;
|
|
182
182
|
y > 0 && (t.position.y = y), p = 0;
|
|
183
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 &&
|
|
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(), (U = o.callback) != null && U.value && o.callback.value(r, i, a, h, v);
|
|
185
185
|
});
|
|
186
|
-
return
|
|
187
|
-
|
|
186
|
+
return ee(() => {
|
|
187
|
+
s.value.disconnect();
|
|
188
188
|
}), {
|
|
189
189
|
float: t,
|
|
190
190
|
rect: r,
|
|
191
|
-
setPosition:
|
|
191
|
+
setPosition: l,
|
|
192
192
|
position: h,
|
|
193
193
|
actualPosition: v,
|
|
194
194
|
openerRect: i,
|
|
@@ -202,11 +202,11 @@ function C(o) {
|
|
|
202
202
|
}
|
|
203
203
|
return L(() => {
|
|
204
204
|
n.addEventListener("change", u);
|
|
205
|
-
}),
|
|
205
|
+
}), ee(() => {
|
|
206
206
|
n.removeEventListener("change", u);
|
|
207
207
|
}), e;
|
|
208
208
|
}
|
|
209
|
-
function
|
|
209
|
+
function fe(o) {
|
|
210
210
|
return {
|
|
211
211
|
isGreater(n) {
|
|
212
212
|
return C(`(min-width: ${o[n]})`);
|
|
@@ -219,7 +219,7 @@ function pe(o) {
|
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
-
function
|
|
222
|
+
function de(o, n, e) {
|
|
223
223
|
if (!o)
|
|
224
224
|
throw new Error("A target component has to be provided.");
|
|
225
225
|
if (!n)
|
|
@@ -240,7 +240,7 @@ function ce(o, n, e) {
|
|
|
240
240
|
document.removeEventListener("click", u);
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
|
-
function
|
|
243
|
+
function me(o, n) {
|
|
244
244
|
if (!o)
|
|
245
245
|
throw new Error("A target component has to be provided.");
|
|
246
246
|
if (!n || typeof n != "function")
|
|
@@ -254,7 +254,7 @@ function fe(o, n) {
|
|
|
254
254
|
o.value.removeEventListener("keydown", e);
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
|
-
function
|
|
257
|
+
function he(o, n) {
|
|
258
258
|
if (!o || typeof o != "function")
|
|
259
259
|
throw new Error("A callback has to be provided.");
|
|
260
260
|
const e = (u) => {
|
|
@@ -274,50 +274,50 @@ function de(o, n) {
|
|
|
274
274
|
n.value.removeEventListener("keyup", e);
|
|
275
275
|
});
|
|
276
276
|
}
|
|
277
|
-
const
|
|
278
|
-
const n = m(null), e =
|
|
279
|
-
if (
|
|
277
|
+
const ge = (o) => {
|
|
278
|
+
const n = m(null), e = ie(), u = oe(() => e == null ? void 0 : e.props.amount), i = m(), a = (s) => {
|
|
279
|
+
if (s === null)
|
|
280
280
|
return "";
|
|
281
281
|
const v = {
|
|
282
282
|
minimumFractionDigits: o.minimumFractionDigits,
|
|
283
|
-
useGrouping: !1
|
|
283
|
+
useGrouping: o.useGrouping || !1
|
|
284
284
|
};
|
|
285
|
-
return o.maximumFractionDigits !== null && (v.maximumFractionDigits = o.maximumFractionDigits),
|
|
286
|
-
}, h = (
|
|
287
|
-
if (!Number.isNaN(
|
|
288
|
-
if (i.value =
|
|
285
|
+
return o.maximumFractionDigits !== null && (v.maximumFractionDigits = o.maximumFractionDigits), s.toLocaleString("it-IT", v);
|
|
286
|
+
}, h = (s) => parseFloat(s.replace(/,/g, ".")), r = (s) => {
|
|
287
|
+
if (!Number.isNaN(s) && e) {
|
|
288
|
+
if (i.value = s, e.props.nullOnEmpty && !s) {
|
|
289
289
|
e.emit("update:amount", null);
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
|
-
e.emit("update:amount", typeof u.value == "number" ?
|
|
292
|
+
e.emit("update:amount", typeof u.value == "number" ? s : s == null ? void 0 : s.toString());
|
|
293
293
|
}
|
|
294
|
-
}, t = (
|
|
294
|
+
}, t = (s) => {
|
|
295
295
|
setTimeout(() => {
|
|
296
|
-
n.value && (n.value.value =
|
|
296
|
+
n.value && (n.value.value = s);
|
|
297
297
|
}, 0);
|
|
298
|
-
}, d = (
|
|
298
|
+
}, d = (s) => (v) => {
|
|
299
299
|
if (!n.value || !v.target)
|
|
300
300
|
return;
|
|
301
|
-
let { value:
|
|
302
|
-
|
|
303
|
-
const c = e != null && e.props.nullOnEmpty &&
|
|
301
|
+
let { value: l } = s;
|
|
302
|
+
l = l.replace(/[^0-9,.-]/g, ""), t(l);
|
|
303
|
+
const c = e != null && e.props.nullOnEmpty && l === "" ? null : h(l);
|
|
304
304
|
r(Number.isNaN(c) ? 0 : c);
|
|
305
|
-
}, g = (
|
|
306
|
-
if (!n.value || !
|
|
305
|
+
}, g = (s) => {
|
|
306
|
+
if (!n.value || !s.target)
|
|
307
307
|
return;
|
|
308
|
-
const v =
|
|
309
|
-
let
|
|
310
|
-
v === "" && (e != null && e.props.nullOnEmpty) ?
|
|
311
|
-
const c = a(
|
|
308
|
+
const v = s.target.value.replace(/,/g, ".");
|
|
309
|
+
let l;
|
|
310
|
+
v === "" && (e != null && e.props.nullOnEmpty) ? l = null : (l = h(v), Number.isNaN(l) && (l = 0));
|
|
311
|
+
const c = a(l);
|
|
312
312
|
t(c), r(h(c));
|
|
313
313
|
};
|
|
314
|
-
return k(n, (
|
|
315
|
-
|
|
316
|
-
}), k(u, (
|
|
317
|
-
|
|
318
|
-
if (!(!n.value ||
|
|
319
|
-
const v = a(
|
|
320
|
-
n.value.value = v, i.value =
|
|
314
|
+
return k(n, (s, v) => {
|
|
315
|
+
s && (v && (v == null || v.removeEventListener("input", d(s)), v == null || v.removeEventListener("blur", g)), s.addEventListener("input", d(s)), s.addEventListener("blur", g), e != null && e.props.amount && (s.value = a(u.value)));
|
|
316
|
+
}), k(u, (s) => {
|
|
317
|
+
te(() => {
|
|
318
|
+
if (!(!n.value || s === null || s === void 0) && i.value !== s) {
|
|
319
|
+
const v = a(s);
|
|
320
|
+
n.value.value = v, i.value = s;
|
|
321
321
|
}
|
|
322
322
|
});
|
|
323
323
|
}), {
|
|
@@ -327,7 +327,7 @@ const me = (o) => {
|
|
|
327
327
|
emitAmount: r,
|
|
328
328
|
setValue: t
|
|
329
329
|
};
|
|
330
|
-
},
|
|
330
|
+
}, ye = /* @__PURE__ */ ae({
|
|
331
331
|
__name: "FzFloating",
|
|
332
332
|
props: {
|
|
333
333
|
isOpen: { type: Boolean, default: !1 },
|
|
@@ -342,7 +342,7 @@ const me = (o) => {
|
|
|
342
342
|
},
|
|
343
343
|
emits: ["fzfloating:setPosition"],
|
|
344
344
|
setup(o, { emit: n }) {
|
|
345
|
-
const e = o, u = n, i = m(null), a = m(null), h =
|
|
345
|
+
const e = o, u = n, i = m(null), a = m(null), h = se();
|
|
346
346
|
let r = !1;
|
|
347
347
|
const t = {
|
|
348
348
|
position: e.position,
|
|
@@ -352,100 +352,101 @@ const me = (o) => {
|
|
|
352
352
|
},
|
|
353
353
|
container: {
|
|
354
354
|
// @ts-ignore
|
|
355
|
-
domRef:
|
|
355
|
+
domRef: X(e.container || document.body)
|
|
356
356
|
},
|
|
357
357
|
opener: {
|
|
358
|
-
domRef:
|
|
358
|
+
domRef: X(null)
|
|
359
359
|
},
|
|
360
360
|
useViewport: e.useViewport,
|
|
361
|
-
callback(...
|
|
362
|
-
u("fzfloating:setPosition", ...
|
|
361
|
+
callback(...l) {
|
|
362
|
+
u("fzfloating:setPosition", ...l);
|
|
363
363
|
}
|
|
364
|
-
}, d =
|
|
364
|
+
}, d = le(t);
|
|
365
365
|
h.opener && (t.opener = {
|
|
366
|
+
// @ts-ignore
|
|
366
367
|
domRef: a
|
|
367
368
|
});
|
|
368
|
-
const g =
|
|
369
|
+
const g = pe(d), s = () => {
|
|
369
370
|
r || (r = !0, requestAnimationFrame(() => {
|
|
370
371
|
e.isOpen && g.setPosition(), r = !1;
|
|
371
372
|
}));
|
|
372
373
|
};
|
|
373
374
|
k(
|
|
374
375
|
() => e.position,
|
|
375
|
-
() =>
|
|
376
|
+
() => s()
|
|
376
377
|
), k(
|
|
377
378
|
() => e.isOpen,
|
|
378
|
-
(
|
|
379
|
-
if (!
|
|
380
|
-
window.removeEventListener("scroll",
|
|
379
|
+
(l) => {
|
|
380
|
+
if (!l || !i.value) {
|
|
381
|
+
window.removeEventListener("scroll", s);
|
|
381
382
|
return;
|
|
382
383
|
}
|
|
383
|
-
window.addEventListener("scroll",
|
|
384
|
+
window.addEventListener("scroll", s), i.value.style.top = "0px", i.value.style.left = "0px", i.value.style.transform = "none", g.setPosition();
|
|
384
385
|
}
|
|
385
386
|
), k(
|
|
386
387
|
() => e.overrideOpener,
|
|
387
|
-
(
|
|
388
|
-
|
|
389
|
-
domRef:
|
|
388
|
+
(l) => {
|
|
389
|
+
l && d.opener && d.opener.value && (d.opener.value = {
|
|
390
|
+
domRef: l
|
|
390
391
|
});
|
|
391
392
|
}
|
|
392
393
|
), O(() => {
|
|
393
|
-
window.removeEventListener("scroll",
|
|
394
|
+
window.removeEventListener("scroll", s);
|
|
394
395
|
});
|
|
395
|
-
const v =
|
|
396
|
-
return (
|
|
397
|
-
|
|
398
|
-
|
|
396
|
+
const v = oe(() => e.overrideContentClass ? e.contentClass : ["bg-core-white fixed p-4 z-10", e.contentClass]);
|
|
397
|
+
return (l, c) => (B(), Y("div", null, [
|
|
398
|
+
R(l.$slots, "opener-start"),
|
|
399
|
+
J("div", {
|
|
399
400
|
ref_key: "opener",
|
|
400
401
|
ref: a,
|
|
401
402
|
class: "inline-flex"
|
|
402
403
|
}, [
|
|
403
|
-
|
|
404
|
-
isOpen:
|
|
404
|
+
R(l.$slots, "opener", {
|
|
405
|
+
isOpen: l.isOpen,
|
|
405
406
|
floating: F(g)
|
|
406
407
|
})
|
|
407
408
|
], 512),
|
|
408
|
-
|
|
409
|
-
|
|
409
|
+
R(l.$slots, "opener-end"),
|
|
410
|
+
l.teleport ? V("", !0) : Z((B(), Y("div", {
|
|
410
411
|
key: 0,
|
|
411
412
|
ref_key: "content",
|
|
412
413
|
ref: i,
|
|
413
|
-
class:
|
|
414
|
+
class: _(["fz__floating__content", v.value])
|
|
414
415
|
}, [
|
|
415
|
-
|
|
416
|
-
isOpen:
|
|
416
|
+
R(l.$slots, "default", {
|
|
417
|
+
isOpen: l.isOpen,
|
|
417
418
|
floating: F(g)
|
|
418
419
|
})
|
|
419
420
|
], 2)), [
|
|
420
|
-
[
|
|
421
|
+
[j, l.$slots.default && (!l.$slots.opener || l.$slots.opener && l.isOpen)]
|
|
421
422
|
]),
|
|
422
|
-
|
|
423
|
+
l.teleport ? (B(), re(ue, {
|
|
423
424
|
key: 1,
|
|
424
425
|
to: "body"
|
|
425
426
|
}, [
|
|
426
|
-
|
|
427
|
+
Z(J("div", {
|
|
427
428
|
ref_key: "content",
|
|
428
429
|
ref: i,
|
|
429
|
-
class:
|
|
430
|
+
class: _(["fz__floating__content", v.value])
|
|
430
431
|
}, [
|
|
431
|
-
|
|
432
|
-
isOpen:
|
|
432
|
+
R(l.$slots, "default", {
|
|
433
|
+
isOpen: l.isOpen,
|
|
433
434
|
floating: F(g)
|
|
434
435
|
})
|
|
435
436
|
], 2), [
|
|
436
|
-
[
|
|
437
|
+
[j, l.$slots.default && (!l.$slots.opener || l.$slots.opener && l.isOpen)]
|
|
437
438
|
])
|
|
438
|
-
])) :
|
|
439
|
+
])) : V("", !0)
|
|
439
440
|
]));
|
|
440
441
|
}
|
|
441
442
|
});
|
|
442
443
|
export {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
444
|
+
ye as FzFloating,
|
|
445
|
+
fe as useBreakpoints,
|
|
446
|
+
de as useClickOutside,
|
|
447
|
+
ge as useCurrency,
|
|
448
|
+
pe as useFloating,
|
|
449
|
+
me as useKeyDown,
|
|
450
|
+
he as useKeyUp,
|
|
450
451
|
C as useMediaQuery
|
|
451
452
|
};
|
package/dist/composables.umd.cjs
CHANGED
|
@@ -1 +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"})});
|
|
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 E=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";E.width=window.innerWidth,E.height=window.innerHeight,E.x=0,E.y=0;const u=n?n.getBoundingClientRect():E,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},K=(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,U,W;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((M=n.opener)!=null&&M.value&&c.value&&(a!=null&&a.value)){const b=a.value.left-parseFloat(d.marginLeft)-parseFloat(d.marginRight),I=a.value.left-parseFloat(d.marginLeft),R=a.value.top-parseFloat(d.marginTop)-parseFloat(d.marginBottom),q=a.value.top-parseFloat(d.marginTop);switch(p.value){case"auto":p.value=w((z=n.useViewport)!=null&&z.value?null:t.value,i.value,c.value);break;case"auto-vertical":p.value=w((D=n.useViewport)!=null&&D.value?null:t.value,i.value,c.value,void 0,!0);break;case"auto-start":p.value=w((P=n.useViewport)!=null&&P.value?null:t.value,i.value,c.value,"start");break;case"auto-vertical-start":p.value=w((A=n.useViewport)!=null&&A.value?null:t.value,i.value,c.value,"start",!0);break;case"auto-end":p.value=w((T=n.useViewport)!=null&&T.value?null:t.value,i.value,c.value,"end");break;case"auto-vertical-end":p.value=w((U=n.useViewport)!=null&&U.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=I+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=R,o.position.x=b,v=-100,f=0;break;case"left":o.position.y=q+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=R,o.position.x=b,f=-100,v=0;break;case"top":o.position.y=R,o.position.x=I+a.value.width/2,v=-50,f=-100;break;case"top-end":o.position.y=R,o.position.x=a.value.right,v=-100,f=-100;break;case"right-start":o.position.y=R,o.position.x=a.value.right,v=0,f=0;break;case"right":o.position.y=q+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=K(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(),(W=n.callback)!=null&&W.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 G(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 H(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 Q(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 X(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 Y=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:n.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}},J=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=J,h.useBreakpoints=G,h.useClickOutside=H,h.useCurrency=Y,h.useFloating=B,h.useKeyDown=Q,h.useKeyUp=X,h.useMediaQuery=x,Object.defineProperty(h,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.31",
|
|
4
4
|
"description": "Design System utility composables",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"vite": "^5.0.10",
|
|
26
26
|
"vitest": "^1.2.0",
|
|
27
27
|
"vue-tsc": "^1.8.25",
|
|
28
|
+
"@fiscozen/tsconfig": "^0.1.0",
|
|
28
29
|
"@fiscozen/eslint-config": "^0.1.0",
|
|
29
|
-
"@fiscozen/prettier-config": "^0.1.0"
|
|
30
|
-
"@fiscozen/tsconfig": "^0.1.0"
|
|
30
|
+
"@fiscozen/prettier-config": "^0.1.0"
|
|
31
31
|
},
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"scripts": {
|
package/src/FzFloating.vue
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Ref, watch, getCurrentInstance, computed, ref, nextTick } from 'vue'
|
|
2
2
|
import { FzUseCurrencyOptions } from '../types'
|
|
3
|
+
import { format as formatNumber, parse } from '../utils'
|
|
3
4
|
|
|
4
5
|
export const useCurrency = (options: FzUseCurrencyOptions) => {
|
|
5
6
|
const inputRef: Ref<HTMLInputElement | null | undefined> = ref(null)
|
|
@@ -8,24 +9,7 @@ export const useCurrency = (options: FzUseCurrencyOptions) => {
|
|
|
8
9
|
const computedModel = computed<number | null>(() => vm?.props.amount as unknown as number | null)
|
|
9
10
|
const internalVal = ref<number | null>()
|
|
10
11
|
|
|
11
|
-
const format = (
|
|
12
|
-
if (input === null) {
|
|
13
|
-
return ''
|
|
14
|
-
}
|
|
15
|
-
const safeOptions: Intl.NumberFormatOptions = {
|
|
16
|
-
minimumFractionDigits: options.minimumFractionDigits,
|
|
17
|
-
useGrouping: false
|
|
18
|
-
}
|
|
19
|
-
if (options.maximumFractionDigits !== null) {
|
|
20
|
-
safeOptions.maximumFractionDigits = options.maximumFractionDigits
|
|
21
|
-
}
|
|
22
|
-
return input.toLocaleString('it-IT', safeOptions)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const parse = (text: string) => {
|
|
26
|
-
// strip currency, handle edge cases...
|
|
27
|
-
return parseFloat(text.replace(/,/g, '.'))
|
|
28
|
-
}
|
|
12
|
+
const format = formatNumber(options)
|
|
29
13
|
|
|
30
14
|
const emitAmount = (val: number | null) => {
|
|
31
15
|
if (Number.isNaN(val)) {
|
|
@@ -82,11 +82,7 @@ export const useFloating = (
|
|
|
82
82
|
let translateY = 0
|
|
83
83
|
let translateX = 0
|
|
84
84
|
|
|
85
|
-
if (
|
|
86
|
-
args.opener?.value &&
|
|
87
|
-
safeOpenerDomRef.value &&
|
|
88
|
-
openerRect?.value
|
|
89
|
-
) {
|
|
85
|
+
if (args.opener?.value && safeOpenerDomRef.value && openerRect?.value) {
|
|
90
86
|
const leftWithoutXMargin =
|
|
91
87
|
openerRect.value.left - parseFloat(elStyle.marginLeft) - parseFloat(elStyle.marginRight)
|
|
92
88
|
const leftWithoutLeftMargin = openerRect.value.left - parseFloat(elStyle.marginLeft)
|
|
@@ -310,7 +306,7 @@ export const useFloating = (
|
|
|
310
306
|
|
|
311
307
|
if (args.callback?.value) {
|
|
312
308
|
args.callback.value(rect, openerRect, containerRect, position, actualPosition)
|
|
313
|
-
}
|
|
309
|
+
}
|
|
314
310
|
})
|
|
315
311
|
|
|
316
312
|
onUnmounted(() => {
|
package/src/types.ts
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -1,93 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type MainPosition = 'right' | 'left' | 'top' | 'bottom'
|
|
4
|
-
interface PositionListItem {
|
|
5
|
-
key: MainPosition
|
|
6
|
-
space: number
|
|
7
|
-
}
|
|
8
|
-
const windowDOMrect = new DOMRect(0, 0, window.innerWidth, window.innerHeight)
|
|
9
|
-
export const getHighestAvailableSpacePos = (
|
|
10
|
-
container: HTMLElement | null,
|
|
11
|
-
el: HTMLElement,
|
|
12
|
-
opener: HTMLElement,
|
|
13
|
-
justify?: 'start' | 'end',
|
|
14
|
-
verticalOnly?: boolean
|
|
15
|
-
): FzFloatingPosition => {
|
|
16
|
-
let mainPosition: MainPosition = verticalOnly ? 'bottom' : 'right'
|
|
17
|
-
|
|
18
|
-
let positionRes: FzFloatingPosition = verticalOnly ? 'bottom-start' : 'right-start'
|
|
19
|
-
|
|
20
|
-
windowDOMrect.width = window.innerWidth
|
|
21
|
-
windowDOMrect.height = window.innerHeight
|
|
22
|
-
windowDOMrect.x = 0
|
|
23
|
-
windowDOMrect.y = 0
|
|
24
|
-
const containerRect = container ? container.getBoundingClientRect() : windowDOMrect
|
|
25
|
-
const elRect = el.getBoundingClientRect()
|
|
26
|
-
const openerRect = opener.getBoundingClientRect()
|
|
27
|
-
|
|
28
|
-
const spaceLeftNormalized =
|
|
29
|
-
(openerRect.left - containerRect.left - elRect.width) / containerRect.width
|
|
30
|
-
const spaceRightNormalized =
|
|
31
|
-
(containerRect.right - openerRect.right - elRect.width) / containerRect.width
|
|
32
|
-
const spaceTopNormalized =
|
|
33
|
-
(openerRect.top - containerRect.top - elRect.height) / containerRect.height
|
|
34
|
-
const spaceBottomNormalized =
|
|
35
|
-
(containerRect.bottom - openerRect.bottom - elRect.height) / containerRect.height
|
|
36
|
-
|
|
37
|
-
let positionList = [
|
|
38
|
-
{
|
|
39
|
-
key: 'right',
|
|
40
|
-
space: spaceRightNormalized
|
|
41
|
-
} as PositionListItem,
|
|
42
|
-
{
|
|
43
|
-
key: 'top',
|
|
44
|
-
space: spaceTopNormalized
|
|
45
|
-
} as PositionListItem,
|
|
46
|
-
{
|
|
47
|
-
key: 'bottom',
|
|
48
|
-
space: spaceBottomNormalized
|
|
49
|
-
} as PositionListItem,
|
|
50
|
-
{
|
|
51
|
-
key: 'left',
|
|
52
|
-
space: spaceLeftNormalized
|
|
53
|
-
} as PositionListItem
|
|
54
|
-
].sort((a, b) => b.space - a.space)
|
|
55
|
-
|
|
56
|
-
if (verticalOnly) {
|
|
57
|
-
positionList = positionList.filter((pos) => pos.key === 'top' || pos.key === 'bottom')
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
mainPosition = positionList[0].key
|
|
61
|
-
|
|
62
|
-
if (!justify) {
|
|
63
|
-
switch (mainPosition) {
|
|
64
|
-
case 'right':
|
|
65
|
-
case 'left':
|
|
66
|
-
const centerDiff = (elRect.height - openerRect.height) / 2
|
|
67
|
-
if (containerRect.top > openerRect.top - centerDiff) {
|
|
68
|
-
justify = 'end'
|
|
69
|
-
}
|
|
70
|
-
if (containerRect.bottom < openerRect.top - centerDiff) {
|
|
71
|
-
justify = 'start'
|
|
72
|
-
}
|
|
73
|
-
break
|
|
74
|
-
default:
|
|
75
|
-
break
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
positionRes = justify ? `${mainPosition}-${justify}` : mainPosition
|
|
80
|
-
return positionRes
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const calcRealPos = (
|
|
84
|
-
rect: DOMRect,
|
|
85
|
-
pos: FzAbsolutePosition,
|
|
86
|
-
translateX: number,
|
|
87
|
-
translateY: number
|
|
88
|
-
): FzAbsolutePosition => {
|
|
89
|
-
return {
|
|
90
|
-
x: pos.x + (rect.width * translateX) / 100,
|
|
91
|
-
y: pos.y + (rect.height * translateY) / 100
|
|
92
|
-
}
|
|
93
|
-
}
|
|
1
|
+
export * from './number'
|
|
2
|
+
export * from './position'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FzUseCurrencyOptions } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const format = (options: FzUseCurrencyOptions) => (input: number | null) => {
|
|
4
|
+
if (input === null) {
|
|
5
|
+
return ''
|
|
6
|
+
}
|
|
7
|
+
const safeOptions: FzUseCurrencyOptions = {
|
|
8
|
+
maximumFractionDigits: options.maximumFractionDigits || 2,
|
|
9
|
+
minimumFractionDigits: options.minimumFractionDigits,
|
|
10
|
+
useGrouping: options.useGrouping || false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return input.toLocaleString('it-IT', safeOptions)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const parse = (text: string) => {
|
|
17
|
+
// strip currency, handle edge cases...
|
|
18
|
+
return parseFloat(text.replace(/,/g, '.'))
|
|
19
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { FzAbsolutePosition, FzFloatingPosition } from '../../types'
|
|
2
|
+
|
|
3
|
+
type MainPosition = 'right' | 'left' | 'top' | 'bottom'
|
|
4
|
+
interface PositionListItem {
|
|
5
|
+
key: MainPosition
|
|
6
|
+
space: number
|
|
7
|
+
}
|
|
8
|
+
const windowDOMrect = new DOMRect(0, 0, window.innerWidth, window.innerHeight)
|
|
9
|
+
export const getHighestAvailableSpacePos = (
|
|
10
|
+
container: HTMLElement | null,
|
|
11
|
+
el: HTMLElement,
|
|
12
|
+
opener: HTMLElement,
|
|
13
|
+
justify?: 'start' | 'end',
|
|
14
|
+
verticalOnly?: boolean
|
|
15
|
+
): FzFloatingPosition => {
|
|
16
|
+
let mainPosition: MainPosition = verticalOnly ? 'bottom' : 'right'
|
|
17
|
+
|
|
18
|
+
let positionRes: FzFloatingPosition = verticalOnly ? 'bottom-start' : 'right-start'
|
|
19
|
+
|
|
20
|
+
windowDOMrect.width = window.innerWidth
|
|
21
|
+
windowDOMrect.height = window.innerHeight
|
|
22
|
+
windowDOMrect.x = 0
|
|
23
|
+
windowDOMrect.y = 0
|
|
24
|
+
const containerRect = container ? container.getBoundingClientRect() : windowDOMrect
|
|
25
|
+
const elRect = el.getBoundingClientRect()
|
|
26
|
+
const openerRect = opener.getBoundingClientRect()
|
|
27
|
+
|
|
28
|
+
const spaceLeftNormalized =
|
|
29
|
+
(openerRect.left - containerRect.left - elRect.width) / containerRect.width
|
|
30
|
+
const spaceRightNormalized =
|
|
31
|
+
(containerRect.right - openerRect.right - elRect.width) / containerRect.width
|
|
32
|
+
const spaceTopNormalized =
|
|
33
|
+
(openerRect.top - containerRect.top - elRect.height) / containerRect.height
|
|
34
|
+
const spaceBottomNormalized =
|
|
35
|
+
(containerRect.bottom - openerRect.bottom - elRect.height) / containerRect.height
|
|
36
|
+
|
|
37
|
+
let positionList = [
|
|
38
|
+
{
|
|
39
|
+
key: 'right',
|
|
40
|
+
space: spaceRightNormalized
|
|
41
|
+
} as PositionListItem,
|
|
42
|
+
{
|
|
43
|
+
key: 'top',
|
|
44
|
+
space: spaceTopNormalized
|
|
45
|
+
} as PositionListItem,
|
|
46
|
+
{
|
|
47
|
+
key: 'bottom',
|
|
48
|
+
space: spaceBottomNormalized
|
|
49
|
+
} as PositionListItem,
|
|
50
|
+
{
|
|
51
|
+
key: 'left',
|
|
52
|
+
space: spaceLeftNormalized
|
|
53
|
+
} as PositionListItem
|
|
54
|
+
].sort((a, b) => b.space - a.space)
|
|
55
|
+
|
|
56
|
+
if (verticalOnly) {
|
|
57
|
+
positionList = positionList.filter((pos) => pos.key === 'top' || pos.key === 'bottom')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
mainPosition = positionList[0].key
|
|
61
|
+
|
|
62
|
+
if (!justify) {
|
|
63
|
+
const centerDiff = (elRect.height - openerRect.height) / 2
|
|
64
|
+
switch (mainPosition) {
|
|
65
|
+
case 'right':
|
|
66
|
+
case 'left':
|
|
67
|
+
if (containerRect.top > openerRect.top - centerDiff) {
|
|
68
|
+
justify = 'end'
|
|
69
|
+
}
|
|
70
|
+
if (containerRect.bottom < openerRect.top - centerDiff) {
|
|
71
|
+
justify = 'start'
|
|
72
|
+
}
|
|
73
|
+
break
|
|
74
|
+
default:
|
|
75
|
+
break
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
positionRes = justify ? `${mainPosition}-${justify}` : mainPosition
|
|
80
|
+
return positionRes
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const calcRealPos = (
|
|
84
|
+
rect: DOMRect,
|
|
85
|
+
pos: FzAbsolutePosition,
|
|
86
|
+
translateX: number,
|
|
87
|
+
translateY: number
|
|
88
|
+
): FzAbsolutePosition => {
|
|
89
|
+
return {
|
|
90
|
+
x: pos.x + (rect.width * translateX) / 100,
|
|
91
|
+
y: pos.y + (rect.height * translateY) / 100
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|