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