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