@fiscozen/composables 0.1.36 → 0.1.37
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.
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { ref as h, reactive as ie, onUnmounted as te, nextTick as oe, onMounted as O, watch as k, onBeforeUnmount as B, getCurrentInstance as ae, computed as ne, defineComponent as re, useSlots as se, toRef as Y, toRefs as le, createElementBlock as J, openBlock as $, renderSlot as R, createElementVNode as Z, withDirectives as _, createCommentVNode as j, createBlock as ue, unref as C, normalizeClass as V, vShow as ee, Teleport as ve } from "vue";
|
|
2
|
+
const pe = (e) => (o) => {
|
|
3
|
+
if (o === null)
|
|
4
|
+
return "";
|
|
5
|
+
const t = {
|
|
6
|
+
maximumFractionDigits: e.maximumFractionDigits || 2,
|
|
7
|
+
minimumFractionDigits: e.minimumFractionDigits,
|
|
8
|
+
useGrouping: e.useGrouping || !1
|
|
9
|
+
};
|
|
10
|
+
return o.toLocaleString("it-IT", t);
|
|
11
|
+
}, L = (e) => parseFloat(e.replace(/,/g, ".")), ce = (e, o) => {
|
|
12
|
+
let t = o;
|
|
13
|
+
const r = o % e, i = o >= 0 ? e : -e;
|
|
14
|
+
return r !== 0 && (t = Math.abs(r) >= e / 2 ? o + i - r : o - r), t;
|
|
15
|
+
}, E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (e, o, t, r, i) => {
|
|
16
|
+
let a = i ? "bottom" : "right", g = i ? "bottom-start" : "right-start";
|
|
17
|
+
E.width = window.innerWidth, E.height = window.innerHeight, E.x = 0, E.y = 0;
|
|
18
|
+
const s = e ? e.getBoundingClientRect() : E, n = o.getBoundingClientRect(), d = t.getBoundingClientRect(), u = (d.left - s.left - n.width) / s.width, p = (s.right - d.right - n.width) / s.width, l = (d.top - s.top - n.height) / s.height, v = (s.bottom - d.bottom - n.height) / s.height;
|
|
19
|
+
let m = [
|
|
20
|
+
{
|
|
21
|
+
key: "right",
|
|
22
|
+
space: p
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "top",
|
|
26
|
+
space: l
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "bottom",
|
|
30
|
+
space: v
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "left",
|
|
34
|
+
space: u
|
|
35
|
+
}
|
|
36
|
+
].sort((c, f) => f.space - c.space);
|
|
37
|
+
if (i && (m = m.filter((c) => c.key === "top" || c.key === "bottom")), a = m[0].key, !r) {
|
|
38
|
+
const c = (n.height - d.height) / 2;
|
|
39
|
+
switch (a) {
|
|
40
|
+
case "right":
|
|
41
|
+
case "left":
|
|
42
|
+
s.top > d.top - c && (r = "end"), s.bottom < d.top - c && (r = "start");
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return g = r ? `${a}-${r}` : a, g;
|
|
47
|
+
}, fe = (e, o, t, r) => ({
|
|
48
|
+
x: o.x + e.width * t / 100,
|
|
49
|
+
y: o.y + e.height * r / 100
|
|
50
|
+
}), de = (e) => {
|
|
51
|
+
const o = h(null), t = h(null), r = h(null), i = h(), a = h(), g = h("auto"), s = h(), n = ie({
|
|
52
|
+
position: { x: 0, y: 0 }
|
|
53
|
+
}), d = {
|
|
54
|
+
root: null,
|
|
55
|
+
rootMargin: "0px",
|
|
56
|
+
threshold: 1,
|
|
57
|
+
...e.element.value.intersectionOptions
|
|
58
|
+
}, u = (m, c) => {
|
|
59
|
+
}, p = h(new IntersectionObserver(u, d)), l = h(), v = () => oe(() => {
|
|
60
|
+
var N, S, M, P, z, D, A, W, I, T, q, G, H, U, K;
|
|
61
|
+
if (l.value = e.position ? e.position.value : "auto", o.value = typeof e.element.value.domRef.value == "string" ? document.querySelector(e.element.value.domRef.value) : e.element.value.domRef.value, (N = e.container) != null && N.value ? (t.value = typeof ((S = e.container.value) == null ? void 0 : S.domRef.value) == "string" ? document.querySelector(e.container.value.domRef.value) : (M = e.container.value) == null ? void 0 : M.domRef.value, t.value ?? (t.value = document.body)) : t.value = document.body, !o.value)
|
|
62
|
+
throw new Error("missing reference element for floating behavior");
|
|
63
|
+
(P = e.opener) != null && P.value && (r.value = typeof ((z = e.opener.value) == null ? void 0 : z.domRef.value) == "string" ? document.querySelector(e.opener.value.domRef.value) : (D = e.opener.value) == null ? void 0 : D.domRef.value), s.value = o.value.getBoundingClientRect(), i.value = (A = r.value) == null ? void 0 : A.getBoundingClientRect(), a.value = t.value.getBoundingClientRect();
|
|
64
|
+
const m = window.getComputedStyle(o.value);
|
|
65
|
+
p.value.observe(o.value), p.value.observe(t.value);
|
|
66
|
+
let c = 0, f = 0;
|
|
67
|
+
if ((W = e.opener) != null && W.value && r.value && (i != null && i.value)) {
|
|
68
|
+
const y = i.value.left - parseFloat(m.marginLeft) - parseFloat(m.marginRight), Q = i.value.left - parseFloat(m.marginLeft), x = i.value.top - parseFloat(m.marginTop) - parseFloat(m.marginBottom), X = i.value.top - parseFloat(m.marginTop);
|
|
69
|
+
switch (l.value) {
|
|
70
|
+
case "auto":
|
|
71
|
+
l.value = w(
|
|
72
|
+
(I = e.useViewport) != null && I.value ? null : t.value,
|
|
73
|
+
o.value,
|
|
74
|
+
r.value
|
|
75
|
+
);
|
|
76
|
+
break;
|
|
77
|
+
case "auto-vertical":
|
|
78
|
+
l.value = w(
|
|
79
|
+
(T = e.useViewport) != null && T.value ? null : t.value,
|
|
80
|
+
o.value,
|
|
81
|
+
r.value,
|
|
82
|
+
void 0,
|
|
83
|
+
!0
|
|
84
|
+
);
|
|
85
|
+
break;
|
|
86
|
+
case "auto-start":
|
|
87
|
+
l.value = w(
|
|
88
|
+
(q = e.useViewport) != null && q.value ? null : t.value,
|
|
89
|
+
o.value,
|
|
90
|
+
r.value,
|
|
91
|
+
"start"
|
|
92
|
+
);
|
|
93
|
+
break;
|
|
94
|
+
case "auto-vertical-start":
|
|
95
|
+
l.value = w(
|
|
96
|
+
(G = e.useViewport) != null && G.value ? null : t.value,
|
|
97
|
+
o.value,
|
|
98
|
+
r.value,
|
|
99
|
+
"start",
|
|
100
|
+
!0
|
|
101
|
+
);
|
|
102
|
+
break;
|
|
103
|
+
case "auto-end":
|
|
104
|
+
l.value = w(
|
|
105
|
+
(H = e.useViewport) != null && H.value ? null : t.value,
|
|
106
|
+
o.value,
|
|
107
|
+
r.value,
|
|
108
|
+
"end"
|
|
109
|
+
);
|
|
110
|
+
break;
|
|
111
|
+
case "auto-vertical-end":
|
|
112
|
+
l.value = w(
|
|
113
|
+
(U = e.useViewport) != null && U.value ? null : t.value,
|
|
114
|
+
o.value,
|
|
115
|
+
r.value,
|
|
116
|
+
"end",
|
|
117
|
+
!0
|
|
118
|
+
);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
switch (l.value) {
|
|
122
|
+
case "bottom":
|
|
123
|
+
n.position.y = i.value.bottom, n.position.x = Q + i.value.width / 2, f = -50, c = 0;
|
|
124
|
+
break;
|
|
125
|
+
case "bottom-start":
|
|
126
|
+
n.position.y = i.value.bottom, n.position.x = y, f = 0, c = 0;
|
|
127
|
+
break;
|
|
128
|
+
case "bottom-end":
|
|
129
|
+
n.position.y = i.value.bottom, n.position.x = i.value.right, f = -100, c = 0;
|
|
130
|
+
break;
|
|
131
|
+
case "left-start":
|
|
132
|
+
n.position.y = x, n.position.x = y, f = -100, c = 0;
|
|
133
|
+
break;
|
|
134
|
+
case "left":
|
|
135
|
+
n.position.y = X + i.value.height / 2, n.position.x = y, c = -50, f = -100;
|
|
136
|
+
break;
|
|
137
|
+
case "left-end":
|
|
138
|
+
n.position.y = i.value.bottom, n.position.x = y, c = -100, f = -100;
|
|
139
|
+
break;
|
|
140
|
+
case "top-start":
|
|
141
|
+
n.position.y = x, n.position.x = y, c = -100, f = 0;
|
|
142
|
+
break;
|
|
143
|
+
case "top":
|
|
144
|
+
n.position.y = x, n.position.x = Q + i.value.width / 2, f = -50, c = -100;
|
|
145
|
+
break;
|
|
146
|
+
case "top-end":
|
|
147
|
+
n.position.y = x, n.position.x = i.value.right, f = -100, c = -100;
|
|
148
|
+
break;
|
|
149
|
+
case "right-start":
|
|
150
|
+
n.position.y = x, n.position.x = i.value.right, f = 0, c = 0;
|
|
151
|
+
break;
|
|
152
|
+
case "right":
|
|
153
|
+
n.position.y = X + i.value.height / 2, n.position.x = i.value.right, c = -50, f = 0;
|
|
154
|
+
break;
|
|
155
|
+
case "right-end":
|
|
156
|
+
n.position.y = i.value.bottom, n.position.x = i.value.right, c = -100, f = 0;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
} else
|
|
160
|
+
switch (l.value) {
|
|
161
|
+
case "bottom":
|
|
162
|
+
n.position.y = a.value.bottom - s.value.height, n.position.x = a.value.left + a.value.width / 2, f = -50;
|
|
163
|
+
break;
|
|
164
|
+
case "left-end":
|
|
165
|
+
case "bottom-start":
|
|
166
|
+
n.position.y = a.value.bottom - s.value.height, n.position.x = a.value.left;
|
|
167
|
+
break;
|
|
168
|
+
case "right-end":
|
|
169
|
+
case "bottom-end":
|
|
170
|
+
n.position.y = a.value.bottom - s.value.height, n.position.x = a.value.right - s.value.width;
|
|
171
|
+
break;
|
|
172
|
+
case "left":
|
|
173
|
+
n.position.y = a.value.top + (a.value.height - s.value.height) / 2, n.position.x = a.value.left;
|
|
174
|
+
break;
|
|
175
|
+
case "top-start":
|
|
176
|
+
case "left-start":
|
|
177
|
+
n.position.y = a.value.top, n.position.x = a.value.left;
|
|
178
|
+
break;
|
|
179
|
+
case "top":
|
|
180
|
+
n.position.y = a.value.top, n.position.x = a.value.left + (a.value.width - s.value.width) / 2;
|
|
181
|
+
break;
|
|
182
|
+
case "top-end":
|
|
183
|
+
case "right-start":
|
|
184
|
+
n.position.y = a.value.top, n.position.x = a.value.right - s.value.width;
|
|
185
|
+
case "right":
|
|
186
|
+
n.position.y = a.value.top + (a.value.height - s.value.height) / 2, n.position.x = a.value.right - s.value.width;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
const b = fe(s.value, n.position, f, c);
|
|
190
|
+
if (n.position.x = b.x, n.position.y = b.y, b.x < a.value.left && (n.position.x = a.value.left, f = 0), b.x + s.value.width > a.value.right) {
|
|
191
|
+
const y = a.value.right - s.value.width;
|
|
192
|
+
y > 0 && (n.position.x = y), f = 0;
|
|
193
|
+
}
|
|
194
|
+
if (b.y < a.value.top && (n.position.y = a.value.top, c = 0), b.y + s.value.height > a.value.bottom) {
|
|
195
|
+
const y = a.value.bottom - s.value.height;
|
|
196
|
+
y > 0 && (n.position.y = y), c = 0;
|
|
197
|
+
}
|
|
198
|
+
o.value.style.top = `${n.position.y}px`, o.value.style.left = `${n.position.x}px`, o.value.style.position = "fixed", o.value.style.display = "flex", s.value = o.value.getBoundingClientRect(), (K = e.callback) != null && K.value && e.callback.value(s, i, a, g, l);
|
|
199
|
+
});
|
|
200
|
+
return te(() => {
|
|
201
|
+
p.value.disconnect();
|
|
202
|
+
}), {
|
|
203
|
+
float: n,
|
|
204
|
+
rect: s,
|
|
205
|
+
setPosition: v,
|
|
206
|
+
position: g,
|
|
207
|
+
actualPosition: l,
|
|
208
|
+
openerRect: i,
|
|
209
|
+
containerRect: a
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
function F(e) {
|
|
213
|
+
const o = window.matchMedia(e), t = h(o.matches);
|
|
214
|
+
function r(i) {
|
|
215
|
+
t.value = i.matches;
|
|
216
|
+
}
|
|
217
|
+
return O(() => {
|
|
218
|
+
o.addEventListener("change", r);
|
|
219
|
+
}), te(() => {
|
|
220
|
+
o.removeEventListener("change", r);
|
|
221
|
+
}), t;
|
|
222
|
+
}
|
|
223
|
+
function he(e) {
|
|
224
|
+
return {
|
|
225
|
+
isGreater(o) {
|
|
226
|
+
return F(`(min-width: ${e[o]})`);
|
|
227
|
+
},
|
|
228
|
+
isSmaller(o) {
|
|
229
|
+
return F(`(max-width: ${e[o]})`);
|
|
230
|
+
},
|
|
231
|
+
isInBetween(o, t) {
|
|
232
|
+
return F(`(min-width: ${e[o]}) and (max-width: ${e[t]})`);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function ge(e, o, t) {
|
|
237
|
+
if (!e)
|
|
238
|
+
throw new Error("A target component has to be provided.");
|
|
239
|
+
if (!o)
|
|
240
|
+
throw new Error("A callback has to be provided.");
|
|
241
|
+
const r = (i) => {
|
|
242
|
+
!e.value || i.target === e.value || i.composedPath().includes(e.value) || typeof o == "function" && o();
|
|
243
|
+
};
|
|
244
|
+
t && k(t, (i, a) => {
|
|
245
|
+
a && a.removeEventListener("click", r), i == null || i.addEventListener("click", r);
|
|
246
|
+
}), O(() => {
|
|
247
|
+
t || document.addEventListener("click", r);
|
|
248
|
+
}), B(() => {
|
|
249
|
+
var i;
|
|
250
|
+
if (t) {
|
|
251
|
+
(i = t.value) == null || i.removeEventListener("click", r);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
document.removeEventListener("click", r);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function ye(e, o) {
|
|
258
|
+
if (!e)
|
|
259
|
+
throw new Error("A target component has to be provided.");
|
|
260
|
+
if (!o || typeof o != "function")
|
|
261
|
+
throw new Error("A callback has to be provided.");
|
|
262
|
+
const t = (r) => {
|
|
263
|
+
o(r);
|
|
264
|
+
};
|
|
265
|
+
O(() => {
|
|
266
|
+
e.value.addEventListener("keydown", t);
|
|
267
|
+
}), B(() => {
|
|
268
|
+
e.value.removeEventListener("keydown", t);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
function be(e, o) {
|
|
272
|
+
if (!e || typeof e != "function")
|
|
273
|
+
throw new Error("A callback has to be provided.");
|
|
274
|
+
const t = (r) => {
|
|
275
|
+
e(r);
|
|
276
|
+
};
|
|
277
|
+
O(() => {
|
|
278
|
+
if (!o) {
|
|
279
|
+
document.addEventListener("keyup", t);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
o.value.addEventListener("keyup", t);
|
|
283
|
+
}), B(() => {
|
|
284
|
+
if (!o) {
|
|
285
|
+
document.removeEventListener("keyup", t);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
o.value.removeEventListener("keyup", t);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
const we = (e) => {
|
|
292
|
+
const o = h(null), t = ae(), r = ne(() => t == null ? void 0 : t.props.amount), i = h(), a = pe(e), g = (u) => {
|
|
293
|
+
if (!Number.isNaN(u) && t) {
|
|
294
|
+
if (i.value = u, t.props.nullOnEmpty && !u) {
|
|
295
|
+
t.emit("update:amount", null);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
t.emit("update:amount", u);
|
|
299
|
+
}
|
|
300
|
+
}, s = (u) => {
|
|
301
|
+
setTimeout(() => {
|
|
302
|
+
o.value && (o.value.value = u);
|
|
303
|
+
}, 0);
|
|
304
|
+
}, n = (u) => (p) => {
|
|
305
|
+
if (!o.value || !p.target)
|
|
306
|
+
return;
|
|
307
|
+
let { value: l } = u;
|
|
308
|
+
l = l.replace(/[^0-9,.-]/g, "");
|
|
309
|
+
const v = L(l);
|
|
310
|
+
s(l);
|
|
311
|
+
const m = t != null && t.props.nullOnEmpty && l === "" ? null : v;
|
|
312
|
+
g(Number.isNaN(m) ? 0 : m);
|
|
313
|
+
}, d = (u) => {
|
|
314
|
+
if (!o.value || !u.target)
|
|
315
|
+
return;
|
|
316
|
+
const p = u.target.value.replace(/,/g, ".");
|
|
317
|
+
let l;
|
|
318
|
+
p === "" && (t != null && t.props.nullOnEmpty) ? l = null : (l = L(p), Number.isNaN(l) && (l = 0), e.step && (t != null && t.props.forceStep) && (l = ce(e.step, l)), e.min && e.min > l && (l = e.min), e.max && e.max < l && (l = e.max));
|
|
319
|
+
const v = a(l);
|
|
320
|
+
s(v), g(L(v));
|
|
321
|
+
};
|
|
322
|
+
return k(o, (u, p) => {
|
|
323
|
+
u && (p && (p == null || p.removeEventListener("input", n(u)), p == null || p.removeEventListener("blur", d)), u.addEventListener("input", n(u)), u.addEventListener("blur", d), t != null && t.props.amount && (u.value = a(r.value)));
|
|
324
|
+
}), k(r, (u) => {
|
|
325
|
+
oe(() => {
|
|
326
|
+
if (!(!o.value || u === null || u === void 0) && i.value !== u) {
|
|
327
|
+
const p = a(u);
|
|
328
|
+
o.value.value = p, i.value = u;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}), {
|
|
332
|
+
inputRef: o,
|
|
333
|
+
parse: L,
|
|
334
|
+
format: a,
|
|
335
|
+
emitAmount: g,
|
|
336
|
+
setValue: s
|
|
337
|
+
};
|
|
338
|
+
}, ke = /* @__PURE__ */ re({
|
|
339
|
+
__name: "FzFloating",
|
|
340
|
+
props: {
|
|
341
|
+
isOpen: { type: Boolean, default: !1 },
|
|
342
|
+
position: { default: "auto" },
|
|
343
|
+
container: {},
|
|
344
|
+
contentClass: {},
|
|
345
|
+
openerClass: {},
|
|
346
|
+
overrideContentClass: { type: Boolean },
|
|
347
|
+
overrideOpener: {},
|
|
348
|
+
teleport: { type: Boolean, default: !1 },
|
|
349
|
+
useViewport: { type: Boolean }
|
|
350
|
+
},
|
|
351
|
+
emits: ["fzfloating:setPosition"],
|
|
352
|
+
setup(e, { emit: o }) {
|
|
353
|
+
const t = e, r = o, i = h(null), a = h(null), g = se();
|
|
354
|
+
let s = !1;
|
|
355
|
+
const n = {
|
|
356
|
+
position: t.position,
|
|
357
|
+
element: {
|
|
358
|
+
// @ts-ignore
|
|
359
|
+
domRef: i
|
|
360
|
+
},
|
|
361
|
+
container: {
|
|
362
|
+
// @ts-ignore
|
|
363
|
+
domRef: Y(t.container || document.body)
|
|
364
|
+
},
|
|
365
|
+
opener: {
|
|
366
|
+
domRef: Y(null)
|
|
367
|
+
},
|
|
368
|
+
useViewport: t.useViewport,
|
|
369
|
+
callback(...v) {
|
|
370
|
+
r("fzfloating:setPosition", ...v);
|
|
371
|
+
}
|
|
372
|
+
}, d = le(n);
|
|
373
|
+
g.opener && (n.opener = {
|
|
374
|
+
// @ts-ignore
|
|
375
|
+
domRef: a
|
|
376
|
+
});
|
|
377
|
+
const u = de(d), p = () => {
|
|
378
|
+
s || (s = !0, requestAnimationFrame(() => {
|
|
379
|
+
t.isOpen && u.setPosition(), s = !1;
|
|
380
|
+
}));
|
|
381
|
+
};
|
|
382
|
+
k(
|
|
383
|
+
() => t.position,
|
|
384
|
+
() => p()
|
|
385
|
+
), k(
|
|
386
|
+
() => t.isOpen,
|
|
387
|
+
(v) => {
|
|
388
|
+
if (!v || !i.value) {
|
|
389
|
+
window.removeEventListener("scroll", p);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
window.addEventListener("scroll", p), i.value.style.top = "0px", i.value.style.left = "0px", i.value.style.transform = "none", u.setPosition();
|
|
393
|
+
}
|
|
394
|
+
), k(
|
|
395
|
+
() => t.overrideOpener,
|
|
396
|
+
(v) => {
|
|
397
|
+
v && d.opener && d.opener.value && (d.opener.value = {
|
|
398
|
+
domRef: v
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
), B(() => {
|
|
402
|
+
window.removeEventListener("scroll", p);
|
|
403
|
+
});
|
|
404
|
+
const l = ne(() => t.overrideContentClass ? t.contentClass : ["bg-core-white fixed p-4", t.contentClass]);
|
|
405
|
+
return (v, m) => ($(), J("div", null, [
|
|
406
|
+
R(v.$slots, "opener-start"),
|
|
407
|
+
Z("div", {
|
|
408
|
+
ref_key: "opener",
|
|
409
|
+
ref: a,
|
|
410
|
+
class: "inline-flex"
|
|
411
|
+
}, [
|
|
412
|
+
R(v.$slots, "opener", {
|
|
413
|
+
isOpen: v.isOpen,
|
|
414
|
+
floating: C(u)
|
|
415
|
+
})
|
|
416
|
+
], 512),
|
|
417
|
+
R(v.$slots, "opener-end"),
|
|
418
|
+
v.teleport ? j("", !0) : _(($(), J("div", {
|
|
419
|
+
key: 0,
|
|
420
|
+
ref_key: "content",
|
|
421
|
+
ref: i,
|
|
422
|
+
class: V(["fz__floating__content", l.value])
|
|
423
|
+
}, [
|
|
424
|
+
R(v.$slots, "default", {
|
|
425
|
+
isOpen: v.isOpen,
|
|
426
|
+
floating: C(u)
|
|
427
|
+
})
|
|
428
|
+
], 2)), [
|
|
429
|
+
[ee, v.$slots.default && (!v.$slots.opener || v.$slots.opener && v.isOpen)]
|
|
430
|
+
]),
|
|
431
|
+
v.teleport ? ($(), ue(ve, {
|
|
432
|
+
key: 1,
|
|
433
|
+
to: "body"
|
|
434
|
+
}, [
|
|
435
|
+
_(Z("div", {
|
|
436
|
+
ref_key: "content",
|
|
437
|
+
ref: i,
|
|
438
|
+
class: V(["fz__floating__content", l.value])
|
|
439
|
+
}, [
|
|
440
|
+
R(v.$slots, "default", {
|
|
441
|
+
isOpen: v.isOpen,
|
|
442
|
+
floating: C(u)
|
|
443
|
+
})
|
|
444
|
+
], 2), [
|
|
445
|
+
[ee, v.$slots.default && (!v.$slots.opener || v.$slots.opener && v.isOpen)]
|
|
446
|
+
])
|
|
447
|
+
])) : j("", !0)
|
|
448
|
+
]));
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
export {
|
|
452
|
+
ke as FzFloating,
|
|
453
|
+
fe as calcRealPos,
|
|
454
|
+
pe as format,
|
|
455
|
+
w as getHighestAvailableSpacePos,
|
|
456
|
+
L as parse,
|
|
457
|
+
ce as roundTo,
|
|
458
|
+
he as useBreakpoints,
|
|
459
|
+
ge as useClickOutside,
|
|
460
|
+
we as useCurrency,
|
|
461
|
+
de as useFloating,
|
|
462
|
+
ye as useKeyDown,
|
|
463
|
+
be as useKeyUp,
|
|
464
|
+
F as useMediaQuery
|
|
465
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(v,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],o):(v=typeof globalThis<"u"?globalThis:v||self,o(v.FzComposables={},v.Vue))})(this,function(v,o){"use strict";const C=e=>n=>{if(n===null)return"";const t={maximumFractionDigits:e.maximumFractionDigits||2,minimumFractionDigits:e.minimumFractionDigits,useGrouping:e.useGrouping||!1};return n.toLocaleString("it-IT",t)},R=e=>parseFloat(e.replace(/,/g,".")),L=(e,n)=>{let t=n;const l=n%e,a=n>=0?e:-e;return l!==0&&(t=Math.abs(l)>=e/2?n+a-l:n-l),t},E=new DOMRect(0,0,window.innerWidth,window.innerHeight),w=(e,n,t,l,a)=>{let r=a?"bottom":"right",y=a?"bottom-start":"right-start";E.width=window.innerWidth,E.height=window.innerHeight,E.x=0,E.y=0;const s=e?e.getBoundingClientRect():E,i=n.getBoundingClientRect(),h=t.getBoundingClientRect(),c=(h.left-s.left-i.width)/s.width,f=(s.right-h.right-i.width)/s.width,u=(h.top-s.top-i.height)/s.height,p=(s.bottom-h.bottom-i.height)/s.height;let g=[{key:"right",space:f},{key:"top",space:u},{key:"bottom",space:p},{key:"left",space:c}].sort((d,m)=>m.space-d.space);if(a&&(g=g.filter(d=>d.key==="top"||d.key==="bottom")),r=g[0].key,!l){const d=(i.height-h.height)/2;switch(r){case"right":case"left":s.top>h.top-d&&(l="end"),s.bottom<h.top-d&&(l="start");break}}return y=l?`${r}-${l}`:r,y},O=(e,n,t,l)=>({x:n.x+e.width*t/100,y:n.y+e.height*l/100}),F=e=>{const n=o.ref(null),t=o.ref(null),l=o.ref(null),a=o.ref(),r=o.ref(),y=o.ref("auto"),s=o.ref(),i=o.reactive({position:{x:0,y:0}}),h={root:null,rootMargin:"0px",threshold:1,...e.element.value.intersectionOptions},c=(g,d)=>{},f=o.ref(new IntersectionObserver(c,h)),u=o.ref(),p=()=>o.nextTick(()=>{var S,$,M,N,P,z,D,A,T,U,W,I,q,H,K;if(u.value=e.position?e.position.value:"auto",n.value=typeof e.element.value.domRef.value=="string"?document.querySelector(e.element.value.domRef.value):e.element.value.domRef.value,(S=e.container)!=null&&S.value?(t.value=typeof(($=e.container.value)==null?void 0:$.domRef.value)=="string"?document.querySelector(e.container.value.domRef.value):(M=e.container.value)==null?void 0:M.domRef.value,t.value??(t.value=document.body)):t.value=document.body,!n.value)throw new Error("missing reference element for floating behavior");(N=e.opener)!=null&&N.value&&(l.value=typeof((P=e.opener.value)==null?void 0:P.domRef.value)=="string"?document.querySelector(e.opener.value.domRef.value):(z=e.opener.value)==null?void 0:z.domRef.value),s.value=n.value.getBoundingClientRect(),a.value=(D=l.value)==null?void 0:D.getBoundingClientRect(),r.value=t.value.getBoundingClientRect();const g=window.getComputedStyle(n.value);f.value.observe(n.value),f.value.observe(t.value);let d=0,m=0;if((A=e.opener)!=null&&A.value&&l.value&&(a!=null&&a.value)){const b=a.value.left-parseFloat(g.marginLeft)-parseFloat(g.marginRight),G=a.value.left-parseFloat(g.marginLeft),B=a.value.top-parseFloat(g.marginTop)-parseFloat(g.marginBottom),Q=a.value.top-parseFloat(g.marginTop);switch(u.value){case"auto":u.value=w((T=e.useViewport)!=null&&T.value?null:t.value,n.value,l.value);break;case"auto-vertical":u.value=w((U=e.useViewport)!=null&&U.value?null:t.value,n.value,l.value,void 0,!0);break;case"auto-start":u.value=w((W=e.useViewport)!=null&&W.value?null:t.value,n.value,l.value,"start");break;case"auto-vertical-start":u.value=w((I=e.useViewport)!=null&&I.value?null:t.value,n.value,l.value,"start",!0);break;case"auto-end":u.value=w((q=e.useViewport)!=null&&q.value?null:t.value,n.value,l.value,"end");break;case"auto-vertical-end":u.value=w((H=e.useViewport)!=null&&H.value?null:t.value,n.value,l.value,"end",!0);break}switch(u.value){case"bottom":i.position.y=a.value.bottom,i.position.x=G+a.value.width/2,m=-50,d=0;break;case"bottom-start":i.position.y=a.value.bottom,i.position.x=b,m=0,d=0;break;case"bottom-end":i.position.y=a.value.bottom,i.position.x=a.value.right,m=-100,d=0;break;case"left-start":i.position.y=B,i.position.x=b,m=-100,d=0;break;case"left":i.position.y=Q+a.value.height/2,i.position.x=b,d=-50,m=-100;break;case"left-end":i.position.y=a.value.bottom,i.position.x=b,d=-100,m=-100;break;case"top-start":i.position.y=B,i.position.x=b,d=-100,m=0;break;case"top":i.position.y=B,i.position.x=G+a.value.width/2,m=-50,d=-100;break;case"top-end":i.position.y=B,i.position.x=a.value.right,m=-100,d=-100;break;case"right-start":i.position.y=B,i.position.x=a.value.right,m=0,d=0;break;case"right":i.position.y=Q+a.value.height/2,i.position.x=a.value.right,d=-50,m=0;break;case"right-end":i.position.y=a.value.bottom,i.position.x=a.value.right,d=-100,m=0;break}}else switch(u.value){case"bottom":i.position.y=r.value.bottom-s.value.height,i.position.x=r.value.left+r.value.width/2,m=-50;break;case"left-end":case"bottom-start":i.position.y=r.value.bottom-s.value.height,i.position.x=r.value.left;break;case"right-end":case"bottom-end":i.position.y=r.value.bottom-s.value.height,i.position.x=r.value.right-s.value.width;break;case"left":i.position.y=r.value.top+(r.value.height-s.value.height)/2,i.position.x=r.value.left;break;case"top-start":case"left-start":i.position.y=r.value.top,i.position.x=r.value.left;break;case"top":i.position.y=r.value.top,i.position.x=r.value.left+(r.value.width-s.value.width)/2;break;case"top-end":case"right-start":i.position.y=r.value.top,i.position.x=r.value.right-s.value.width;case"right":i.position.y=r.value.top+(r.value.height-s.value.height)/2,i.position.x=r.value.right-s.value.width;break}const k=O(s.value,i.position,m,d);if(i.position.x=k.x,i.position.y=k.y,k.x<r.value.left&&(i.position.x=r.value.left,m=0),k.x+s.value.width>r.value.right){const b=r.value.right-s.value.width;b>0&&(i.position.x=b),m=0}if(k.y<r.value.top&&(i.position.y=r.value.top,d=0),k.y+s.value.height>r.value.bottom){const b=r.value.bottom-s.value.height;b>0&&(i.position.y=b),d=0}n.value.style.top=`${i.position.y}px`,n.value.style.left=`${i.position.x}px`,n.value.style.position="fixed",n.value.style.display="flex",s.value=n.value.getBoundingClientRect(),(K=e.callback)!=null&&K.value&&e.callback.value(s,a,r,y,u)});return o.onUnmounted(()=>{f.value.disconnect()}),{float:i,rect:s,setPosition:p,position:y,actualPosition:u,openerRect:a,containerRect:r}};function x(e){const n=window.matchMedia(e),t=o.ref(n.matches);function l(a){t.value=a.matches}return o.onMounted(()=>{n.addEventListener("change",l)}),o.onUnmounted(()=>{n.removeEventListener("change",l)}),t}function X(e){return{isGreater(n){return x(`(min-width: ${e[n]})`)},isSmaller(n){return x(`(max-width: ${e[n]})`)},isInBetween(n,t){return x(`(min-width: ${e[n]}) and (max-width: ${e[t]})`)}}}function Y(e,n,t){if(!e)throw new Error("A target component has to be provided.");if(!n)throw new Error("A callback has to be provided.");const l=a=>{!e.value||a.target===e.value||a.composedPath().includes(e.value)||typeof n=="function"&&n()};t&&o.watch(t,(a,r)=>{r&&r.removeEventListener("click",l),a==null||a.addEventListener("click",l)}),o.onMounted(()=>{t||document.addEventListener("click",l)}),o.onBeforeUnmount(()=>{var a;if(t){(a=t.value)==null||a.removeEventListener("click",l);return}document.removeEventListener("click",l)})}function J(e,n){if(!e)throw new Error("A target component has to be provided.");if(!n||typeof n!="function")throw new Error("A callback has to be provided.");const t=l=>{n(l)};o.onMounted(()=>{e.value.addEventListener("keydown",t)}),o.onBeforeUnmount(()=>{e.value.removeEventListener("keydown",t)})}function Z(e,n){if(!e||typeof e!="function")throw new Error("A callback has to be provided.");const t=l=>{e(l)};o.onMounted(()=>{if(!n){document.addEventListener("keyup",t);return}n.value.addEventListener("keyup",t)}),o.onBeforeUnmount(()=>{if(!n){document.removeEventListener("keyup",t);return}n.value.removeEventListener("keyup",t)})}const _=e=>{const n=o.ref(null),t=o.getCurrentInstance(),l=o.computed(()=>t==null?void 0:t.props.amount),a=o.ref(),r=C(e),y=c=>{if(!Number.isNaN(c)&&t){if(a.value=c,t.props.nullOnEmpty&&!c){t.emit("update:amount",null);return}t.emit("update:amount",c)}},s=c=>{setTimeout(()=>{n.value&&(n.value.value=c)},0)},i=c=>f=>{if(!n.value||!f.target)return;let{value:u}=c;u=u.replace(/[^0-9,.-]/g,"");const p=R(u);s(u);const g=t!=null&&t.props.nullOnEmpty&&u===""?null:p;y(Number.isNaN(g)?0:g)},h=c=>{if(!n.value||!c.target)return;const f=c.target.value.replace(/,/g,".");let u;f===""&&(t!=null&&t.props.nullOnEmpty)?u=null:(u=R(f),Number.isNaN(u)&&(u=0),e.step&&(t!=null&&t.props.forceStep)&&(u=L(e.step,u)),e.min&&e.min>u&&(u=e.min),e.max&&e.max<u&&(u=e.max));const p=r(u);s(p),y(R(p))};return o.watch(n,(c,f)=>{c&&(f&&(f==null||f.removeEventListener("input",i(c)),f==null||f.removeEventListener("blur",h)),c.addEventListener("input",i(c)),c.addEventListener("blur",h),t!=null&&t.props.amount&&(c.value=r(l.value)))}),o.watch(l,c=>{o.nextTick(()=>{if(!(!n.value||c===null||c===void 0)&&a.value!==c){const f=r(c);n.value.value=f,a.value=c}})}),{inputRef:n,parse:R,format:r,emitAmount:y,setValue:s}},j=o.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(e,{emit:n}){const t=e,l=n,a=o.ref(null),r=o.ref(null),y=o.useSlots();let s=!1;const i={position:t.position,element:{domRef:a},container:{domRef:o.toRef(t.container||document.body)},opener:{domRef:o.toRef(null)},useViewport:t.useViewport,callback(...p){l("fzfloating:setPosition",...p)}},h=o.toRefs(i);y.opener&&(i.opener={domRef:r});const c=F(h),f=()=>{s||(s=!0,requestAnimationFrame(()=>{t.isOpen&&c.setPosition(),s=!1}))};o.watch(()=>t.position,()=>f()),o.watch(()=>t.isOpen,p=>{if(!p||!a.value){window.removeEventListener("scroll",f);return}window.addEventListener("scroll",f),a.value.style.top="0px",a.value.style.left="0px",a.value.style.transform="none",c.setPosition()}),o.watch(()=>t.overrideOpener,p=>{p&&h.opener&&h.opener.value&&(h.opener.value={domRef:p})}),o.onBeforeUnmount(()=>{window.removeEventListener("scroll",f)});const u=o.computed(()=>t.overrideContentClass?t.contentClass:["bg-core-white fixed p-4",t.contentClass]);return(p,g)=>(o.openBlock(),o.createElementBlock("div",null,[o.renderSlot(p.$slots,"opener-start"),o.createElementVNode("div",{ref_key:"opener",ref:r,class:"inline-flex"},[o.renderSlot(p.$slots,"opener",{isOpen:p.isOpen,floating:o.unref(c)})],512),o.renderSlot(p.$slots,"opener-end"),p.teleport?o.createCommentVNode("",!0):o.withDirectives((o.openBlock(),o.createElementBlock("div",{key:0,ref_key:"content",ref:a,class:o.normalizeClass(["fz__floating__content",u.value])},[o.renderSlot(p.$slots,"default",{isOpen:p.isOpen,floating:o.unref(c)})],2)),[[o.vShow,p.$slots.default&&(!p.$slots.opener||p.$slots.opener&&p.isOpen)]]),p.teleport?(o.openBlock(),o.createBlock(o.Teleport,{key:1,to:"body"},[o.withDirectives(o.createElementVNode("div",{ref_key:"content",ref:a,class:o.normalizeClass(["fz__floating__content",u.value])},[o.renderSlot(p.$slots,"default",{isOpen:p.isOpen,floating:o.unref(c)})],2),[[o.vShow,p.$slots.default&&(!p.$slots.opener||p.$slots.opener&&p.isOpen)]])])):o.createCommentVNode("",!0)]))}});v.FzFloating=j,v.calcRealPos=O,v.format=C,v.getHighestAvailableSpacePos=w,v.parse=R,v.roundTo=L,v.useBreakpoints=X,v.useClickOutside=Y,v.useCurrency=_,v.useFloating=F,v.useKeyDown=J,v.useKeyUp=Z,v.useMediaQuery=x,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiscozen/composables",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
4
4
|
"description": "Design System utility composables",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"author": "Riccardo Agnoletto",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@fiscozen/style": "^0.1.7"
|
|
11
|
+
},
|
|
9
12
|
"peerDependencies": {
|
|
10
13
|
"tailwindcss": "^3.4.1",
|
|
11
14
|
"vue": "^3.4.13"
|
|
@@ -25,9 +28,9 @@
|
|
|
25
28
|
"vite": "^5.0.10",
|
|
26
29
|
"vitest": "^1.2.0",
|
|
27
30
|
"vue-tsc": "^1.8.25",
|
|
28
|
-
"@fiscozen/eslint-config": "^0.1.0",
|
|
29
31
|
"@fiscozen/tsconfig": "^0.1.0",
|
|
30
|
-
"@fiscozen/prettier-config": "^0.1.0"
|
|
32
|
+
"@fiscozen/prettier-config": "^0.1.0",
|
|
33
|
+
"@fiscozen/eslint-config": "^0.1.0"
|
|
31
34
|
},
|
|
32
35
|
"license": "ISC",
|
|
33
36
|
"scripts": {
|
package/src/FzFloating.vue
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { ref, useSlots, watch, toRef, computed, onBeforeUnmount, toRefs, defineExpose } from 'vue'
|
|
3
3
|
import { useFloating } from './composables'
|
|
4
4
|
import { FzFloatingProps, FzUseFloatingArgs } from './types'
|
|
5
|
+
import { useMediaQuery } from './composables'
|
|
6
|
+
import { breakpoints } from '@fiscozen/style'
|
|
5
7
|
|
|
6
8
|
const props = withDefaults(defineProps<FzFloatingProps>(), {
|
|
7
9
|
position: 'auto',
|
|
@@ -16,6 +18,8 @@ const opener = ref<HTMLElement | null>(null)
|
|
|
16
18
|
|
|
17
19
|
const slots = useSlots()
|
|
18
20
|
|
|
21
|
+
const xs = useMediaQuery(`(max-width: ${breakpoints.xs})`)
|
|
22
|
+
|
|
19
23
|
let scheduledAnimationFrame = false
|
|
20
24
|
|
|
21
25
|
const useFloatingOpts: FzUseFloatingArgs = {
|
|
@@ -71,9 +75,11 @@ watch(
|
|
|
71
75
|
return
|
|
72
76
|
}
|
|
73
77
|
window.addEventListener('scroll', setPositionWhenOpen)
|
|
78
|
+
const openerRect = opener.value?.getBoundingClientRect()
|
|
74
79
|
content.value.style.top = '0px'
|
|
75
80
|
content.value.style.left = '0px'
|
|
76
81
|
content.value.style.transform = 'none'
|
|
82
|
+
content.value.style.width = xs.value ? openerRect?.width + 'px' : 'auto'
|
|
77
83
|
floating.setPosition()
|
|
78
84
|
}
|
|
79
85
|
)
|
|
@@ -110,7 +116,7 @@ defineExpose({
|
|
|
110
116
|
<template>
|
|
111
117
|
<div>
|
|
112
118
|
<slot name="opener-start"></slot>
|
|
113
|
-
<div ref="opener" class="inline-flex">
|
|
119
|
+
<div ref="opener" class="inline-flex w-full sm:w-auto">
|
|
114
120
|
<slot name="opener" :isOpen :floating></slot>
|
|
115
121
|
</div>
|
|
116
122
|
<slot name="opener-end"></slot>
|
|
@@ -118,7 +124,7 @@ defineExpose({
|
|
|
118
124
|
v-if="!teleport"
|
|
119
125
|
ref="content"
|
|
120
126
|
v-show="$slots.default && (!$slots.opener || ($slots.opener && isOpen))"
|
|
121
|
-
class="fz__floating__content"
|
|
127
|
+
class="fz__floating__content w-full sm:w-auto"
|
|
122
128
|
:class="contentClass"
|
|
123
129
|
>
|
|
124
130
|
<slot :isOpen :floating></slot>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ref, onMounted, onUnmounted, ref } from 'vue'
|
|
1
|
+
import { Ref, onMounted, onUnmounted, ref, computed } from 'vue'
|
|
2
2
|
|
|
3
3
|
function useMediaQuery(mediaQuery: string): Ref<boolean> {
|
|
4
4
|
const mediaQueryList = window.matchMedia(mediaQuery)
|
|
@@ -16,7 +16,7 @@ function useMediaQuery(mediaQuery: string): Ref<boolean> {
|
|
|
16
16
|
mediaQueryList.removeEventListener('change', handleChange)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
return matches
|
|
19
|
+
return computed(() => matches.value)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export { useMediaQuery }
|