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