@fiscozen/composables 0.1.24 → 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
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ref as d, reactive as H, onUnmounted as q, nextTick as T, onMounted as B, watch as
|
|
2
|
-
const
|
|
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
3
|
let n = s ? "bottom" : "right", h = s ? "bottom-start" : "right-start";
|
|
4
|
-
|
|
5
|
-
const l = o ? o.getBoundingClientRect() :
|
|
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
6
|
let m = [
|
|
7
7
|
{
|
|
8
8
|
key: "right",
|
|
9
|
-
space:
|
|
9
|
+
space: v
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
key: "top",
|
|
@@ -25,8 +25,8 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, e, i
|
|
|
25
25
|
switch (n) {
|
|
26
26
|
case "right":
|
|
27
27
|
case "left":
|
|
28
|
-
const p = (t.height -
|
|
29
|
-
l.top >
|
|
28
|
+
const p = (t.height - c.height) / 2;
|
|
29
|
+
l.top > c.top - p && (u = "end"), l.bottom < c.top - p && (u = "start");
|
|
30
30
|
break;
|
|
31
31
|
}
|
|
32
32
|
return h = u ? `${n}-${u}` : n, h;
|
|
@@ -36,19 +36,19 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, e, i
|
|
|
36
36
|
}), Z = (o) => {
|
|
37
37
|
const e = d(null), i = d(null), u = d(null), s = d(), n = d(), h = d("auto"), l = d(), t = H({
|
|
38
38
|
position: { x: 0, y: 0 }
|
|
39
|
-
}),
|
|
39
|
+
}), c = {
|
|
40
40
|
root: null,
|
|
41
41
|
rootMargin: "0px",
|
|
42
42
|
threshold: 1,
|
|
43
43
|
...o.element.intersectionOptions
|
|
44
44
|
}, r = (m, p) => {
|
|
45
|
-
},
|
|
45
|
+
}, v = d(new IntersectionObserver(r, c)), a = d(), y = () => T(() => {
|
|
46
46
|
var N;
|
|
47
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
48
|
throw new Error("missing reference element for floating behavior");
|
|
49
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
50
|
const m = window.getComputedStyle(e.value);
|
|
51
|
-
|
|
51
|
+
v.value.observe(e.value), v.value.observe(i.value);
|
|
52
52
|
let p = 0, f = 0;
|
|
53
53
|
if (o.opener && u.value && s && s.value) {
|
|
54
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);
|
|
@@ -184,7 +184,7 @@ const E = new DOMRect(0, 0, window.innerWidth, window.innerHeight), w = (o, e, i
|
|
|
184
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
185
|
});
|
|
186
186
|
return q(() => {
|
|
187
|
-
|
|
187
|
+
v.value.disconnect();
|
|
188
188
|
}), {
|
|
189
189
|
float: t,
|
|
190
190
|
rect: l,
|
|
@@ -227,7 +227,7 @@ function V(o, e, i) {
|
|
|
227
227
|
const u = (s) => {
|
|
228
228
|
!o.value || s.target === o.value || s.composedPath().includes(o.value) || typeof e == "function" && e();
|
|
229
229
|
};
|
|
230
|
-
i &&
|
|
230
|
+
i && x(i, (s, n) => {
|
|
231
231
|
n && n.removeEventListener("click", u), s == null || s.addEventListener("click", u);
|
|
232
232
|
}), B(() => {
|
|
233
233
|
i || document.addEventListener("click", u);
|
|
@@ -290,28 +290,28 @@ const oe = () => {
|
|
|
290
290
|
setTimeout(() => {
|
|
291
291
|
o.value && (o.value.value = r);
|
|
292
292
|
}, 0);
|
|
293
|
-
}, t = (r) => (
|
|
294
|
-
if (!o.value || !
|
|
293
|
+
}, t = (r) => (v) => {
|
|
294
|
+
if (!o.value || !v.target)
|
|
295
295
|
return;
|
|
296
296
|
let { value: a } = r;
|
|
297
297
|
a = a.replace(/[^0-9,.]/g, ""), l(a);
|
|
298
298
|
const y = e != null && e.props.nullOnEmpty && a === "" ? null : n(a);
|
|
299
299
|
h(Number.isNaN(y) ? 0 : y);
|
|
300
|
-
},
|
|
300
|
+
}, c = (r) => {
|
|
301
301
|
if (!o.value || !r.target)
|
|
302
302
|
return;
|
|
303
|
-
let
|
|
304
|
-
|
|
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
305
|
const y = s(a);
|
|
306
306
|
l(y), h(n(y));
|
|
307
307
|
};
|
|
308
|
-
return
|
|
309
|
-
r && (
|
|
310
|
-
}),
|
|
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
311
|
T(() => {
|
|
312
|
-
if (!(!o.value ||
|
|
313
|
-
const
|
|
314
|
-
o.value.value =
|
|
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
315
|
}
|
|
316
316
|
});
|
|
317
317
|
}), {
|
|
@@ -355,49 +355,49 @@ const oe = () => {
|
|
|
355
355
|
h.opener && (t.opener = {
|
|
356
356
|
domRef: s
|
|
357
357
|
});
|
|
358
|
-
const
|
|
358
|
+
const c = Z(t), r = () => {
|
|
359
359
|
l || (l = !0, requestAnimationFrame(() => {
|
|
360
|
-
i.isOpen &&
|
|
360
|
+
i.isOpen && c.setPosition(), l = !1;
|
|
361
361
|
}));
|
|
362
362
|
};
|
|
363
|
-
|
|
363
|
+
x(
|
|
364
364
|
() => i.position,
|
|
365
365
|
() => r()
|
|
366
|
-
),
|
|
366
|
+
), x(
|
|
367
367
|
() => i.isOpen,
|
|
368
368
|
(a) => {
|
|
369
369
|
if (!a || !n.value) {
|
|
370
370
|
window.removeEventListener("scroll", r);
|
|
371
371
|
return;
|
|
372
372
|
}
|
|
373
|
-
window.addEventListener("scroll", r), n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none",
|
|
373
|
+
window.addEventListener("scroll", r), n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none", c.setPosition();
|
|
374
374
|
}
|
|
375
375
|
), C(() => {
|
|
376
376
|
window.removeEventListener("scroll", r);
|
|
377
377
|
});
|
|
378
|
-
const
|
|
378
|
+
const v = L(() => i.overrideContentClass ? i.contentClass : ["bg-core-white fixed p-4 z-10", i.contentClass]);
|
|
379
379
|
return (a, y) => ($(), S("div", null, [
|
|
380
|
-
|
|
380
|
+
E(a.$slots, "opener-start"),
|
|
381
381
|
M("div", {
|
|
382
382
|
ref_key: "opener",
|
|
383
383
|
ref: s,
|
|
384
384
|
class: "inline-flex"
|
|
385
385
|
}, [
|
|
386
|
-
|
|
386
|
+
E(a.$slots, "opener", {
|
|
387
387
|
isOpen: a.isOpen,
|
|
388
|
-
floating: F(
|
|
388
|
+
floating: F(c)
|
|
389
389
|
})
|
|
390
390
|
], 512),
|
|
391
|
-
|
|
391
|
+
E(a.$slots, "opener-end"),
|
|
392
392
|
a.teleport ? I("", !0) : A(($(), S("div", {
|
|
393
393
|
key: 0,
|
|
394
394
|
ref_key: "content",
|
|
395
395
|
ref: n,
|
|
396
|
-
class: D(["fz__floating__content
|
|
396
|
+
class: D(["fz__floating__content", v.value])
|
|
397
397
|
}, [
|
|
398
|
-
|
|
398
|
+
E(a.$slots, "default", {
|
|
399
399
|
isOpen: a.isOpen,
|
|
400
|
-
floating: F(
|
|
400
|
+
floating: F(c)
|
|
401
401
|
})
|
|
402
402
|
], 2)), [
|
|
403
403
|
[W, a.$slots.default && (!a.$slots.opener || a.$slots.opener && a.isOpen)]
|
|
@@ -409,11 +409,11 @@ const oe = () => {
|
|
|
409
409
|
A(M("div", {
|
|
410
410
|
ref_key: "content",
|
|
411
411
|
ref: n,
|
|
412
|
-
class: D(["fz__floating__content
|
|
412
|
+
class: D(["fz__floating__content", v.value])
|
|
413
413
|
}, [
|
|
414
|
-
|
|
414
|
+
E(a.$slots, "default", {
|
|
415
415
|
isOpen: a.isOpen,
|
|
416
|
-
floating: F(
|
|
416
|
+
floating: F(c)
|
|
417
417
|
})
|
|
418
418
|
], 2), [
|
|
419
419
|
[W, a.$slots.default && (!a.$slots.opener || a.$slots.opener && a.isOpen)]
|
package/dist/composables.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(h=typeof globalThis<"u"?globalThis:h||self,e(h.FzComposables={},h.Vue))})(this,function(h,e){"use strict";const 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}),B=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 x(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 x(`(min-width: ${n[t]})`)},isSmaller(t){return x(`(max-width: ${n[t]})`)},isInBetween(t,a){return x(`(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 z(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 M=()=>{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)&&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=B(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 bg-core-white fixed z-10 p-4",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 bg-core-white fixed z-10 p-4",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=M,h.useFloating=B,h.useKeyDown=N,h.useKeyUp=z,h.useMediaQuery=x,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(h=typeof globalThis<"u"?globalThis:h||self,e(h.FzComposables={},h.Vue))})(this,function(h,e){"use strict";const E=new DOMRect(0,0,window.innerWidth,window.innerHeight),w=(n,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
|
@@ -97,7 +97,7 @@ export const useCurrency = () => {
|
|
|
97
97
|
|
|
98
98
|
watch(computedModel, (newVal) => {
|
|
99
99
|
nextTick(() => {
|
|
100
|
-
if (!inputRef.value ||
|
|
100
|
+
if (!inputRef.value || newVal === null || newVal === undefined) {
|
|
101
101
|
return
|
|
102
102
|
}
|
|
103
103
|
// we need to format here only if someone externally set the
|