@fiscozen/composables 0.1.8-beta.1 → 0.1.9
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 +148 -100
- package/dist/composables.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/FzFloating.vue +15 -10
- package/src/composables/useFloating.ts +9 -8
- package/src/types.ts +11 -2
package/dist/composables.js
CHANGED
|
@@ -1,212 +1,260 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
const
|
|
3
|
-
let
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
1
|
+
import { ref as f, reactive as S, onUnmounted as L, nextTick as z, onMounted as E, onBeforeUnmount as M, defineComponent as P, useSlots as N, computed as T, toRef as W, watch as O, openBlock as q, createElementBlock as A, createElementVNode as $, renderSlot as w, unref as F, withDirectives as D, normalizeClass as I, vShow as Q } from "vue";
|
|
2
|
+
const x = (o, t, a, n) => {
|
|
3
|
+
let s = "right", e = "right-start";
|
|
4
|
+
const u = o.getBoundingClientRect(), r = t.getBoundingClientRect(), h = a.getBoundingClientRect(), b = (h.left - u.left - r.width) / u.width, l = (u.right - h.right - r.width) / u.width, i = (h.top - u.top - r.height) / u.height, d = (u.bottom - h.bottom - r.height) / u.height;
|
|
5
|
+
if (s = [
|
|
6
6
|
{
|
|
7
7
|
key: "right",
|
|
8
|
-
space:
|
|
8
|
+
space: l
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
key: "top",
|
|
12
|
-
space:
|
|
12
|
+
space: i
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
key: "bottom",
|
|
16
|
-
space:
|
|
16
|
+
space: d
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
key: "left",
|
|
20
|
-
space:
|
|
20
|
+
space: b
|
|
21
21
|
}
|
|
22
|
-
].sort((
|
|
23
|
-
switch (
|
|
22
|
+
].sort((p, c) => c.space - p.space)[0].key, !n)
|
|
23
|
+
switch (s) {
|
|
24
24
|
case "right":
|
|
25
25
|
case "left":
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const p = (r.height - h.height) / 2;
|
|
27
|
+
u.top > h.top - p && (n = "end"), u.bottom < h.top - p && (n = "start");
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
|
-
return e =
|
|
31
|
-
},
|
|
32
|
-
x:
|
|
33
|
-
y:
|
|
34
|
-
}),
|
|
35
|
-
const
|
|
30
|
+
return e = n ? `${s}-${n}` : s, e;
|
|
31
|
+
}, U = (o, t, a, n) => ({
|
|
32
|
+
x: t.x + o.width * a / 100,
|
|
33
|
+
y: t.y + o.height * n / 100
|
|
34
|
+
}), X = (o) => {
|
|
35
|
+
const t = f(null), a = f(null), n = f(null), s = f(null), e = S({
|
|
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
|
-
}, h =
|
|
44
|
-
var
|
|
45
|
-
if (
|
|
41
|
+
...o.element.intersectionOptions
|
|
42
|
+
}, r = (l, i) => {
|
|
43
|
+
}, h = f(new IntersectionObserver(r, u)), b = () => z(() => {
|
|
44
|
+
var R;
|
|
45
|
+
if (t.value = typeof o.element.domRef.value == "string" ? document.querySelector(o.element.domRef.value) : o.element.domRef.value, o.container ? (a.value = typeof o.container.domRef.value == "string" ? document.querySelector(o.container.domRef.value) : o.container.domRef.value, a.value ?? (a.value = document.body)) : a.value = document.body, !t.value)
|
|
46
46
|
throw new Error("missing reference element for floating behavior");
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
h.value.observe(
|
|
50
|
-
let
|
|
51
|
-
if (
|
|
52
|
-
|
|
47
|
+
o.opener && (n.value = typeof o.opener.domRef.value == "string" ? document.querySelector(o.opener.domRef.value) : o.opener.domRef.value), s.value = t.value.getBoundingClientRect();
|
|
48
|
+
const l = (R = n.value) == null ? void 0 : R.getBoundingClientRect(), i = a.value.getBoundingClientRect(), d = window.getComputedStyle(t.value);
|
|
49
|
+
h.value.observe(t.value), h.value.observe(a.value);
|
|
50
|
+
let m = o.position ? o.position.value : "auto", p = 0, c = 0;
|
|
51
|
+
if (o.opener && n.value && l) {
|
|
52
|
+
const g = l.left - parseFloat(d.marginLeft) - parseFloat(d.marginRight), B = l.left - parseFloat(d.marginLeft), y = l.top - parseFloat(d.marginTop) - parseFloat(d.marginBottom), C = l.top - parseFloat(d.marginTop);
|
|
53
|
+
switch (m) {
|
|
53
54
|
case "auto":
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
m = x(
|
|
56
|
+
a.value,
|
|
57
|
+
t.value,
|
|
58
|
+
n.value
|
|
58
59
|
);
|
|
59
60
|
break;
|
|
60
61
|
case "auto-start":
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
m = x(
|
|
63
|
+
a.value,
|
|
64
|
+
t.value,
|
|
63
65
|
n.value,
|
|
64
|
-
p.value,
|
|
65
66
|
"start"
|
|
66
67
|
);
|
|
67
68
|
break;
|
|
68
69
|
case "auto-end":
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
m = x(
|
|
71
|
+
a.value,
|
|
72
|
+
t.value,
|
|
71
73
|
n.value,
|
|
72
|
-
p.value,
|
|
73
74
|
"end"
|
|
74
75
|
);
|
|
75
76
|
break;
|
|
76
77
|
}
|
|
77
|
-
switch (
|
|
78
|
+
switch (m) {
|
|
78
79
|
case "bottom":
|
|
79
|
-
e.position.y =
|
|
80
|
+
e.position.y = l.bottom, e.position.x = B + l.width / 2, c = -50, p = 0;
|
|
80
81
|
break;
|
|
81
82
|
case "bottom-start":
|
|
82
|
-
e.position.y =
|
|
83
|
+
e.position.y = l.bottom, e.position.x = g, c = 0, p = 0;
|
|
83
84
|
break;
|
|
84
85
|
case "bottom-end":
|
|
85
|
-
e.position.y =
|
|
86
|
+
e.position.y = l.bottom, e.position.x = l.right, c = -100, p = 0;
|
|
86
87
|
break;
|
|
87
88
|
case "left-start":
|
|
88
|
-
e.position.y =
|
|
89
|
+
e.position.y = y, e.position.x = g, c = -100, p = 0;
|
|
89
90
|
break;
|
|
90
91
|
case "left":
|
|
91
|
-
e.position.y =
|
|
92
|
+
e.position.y = C + l.height / 2, e.position.x = g, p = -50, c = -100;
|
|
92
93
|
break;
|
|
93
94
|
case "left-end":
|
|
94
|
-
e.position.y =
|
|
95
|
+
e.position.y = l.bottom, e.position.x = g, p = -100, c = -100;
|
|
95
96
|
break;
|
|
96
97
|
case "top-start":
|
|
97
|
-
e.position.y =
|
|
98
|
+
e.position.y = y, e.position.x = g, p = -100, c = 0;
|
|
98
99
|
break;
|
|
99
100
|
case "top":
|
|
100
|
-
e.position.y =
|
|
101
|
+
e.position.y = y, e.position.x = B + l.width / 2, c = -50, p = -100;
|
|
101
102
|
break;
|
|
102
103
|
case "top-end":
|
|
103
|
-
e.position.y =
|
|
104
|
+
e.position.y = y, e.position.x = l.right, c = -100, p = -100;
|
|
104
105
|
break;
|
|
105
106
|
case "right-start":
|
|
106
|
-
e.position.y =
|
|
107
|
+
e.position.y = y, e.position.x = l.right, c = 0, p = 0;
|
|
107
108
|
break;
|
|
108
109
|
case "right":
|
|
109
|
-
e.position.y =
|
|
110
|
+
e.position.y = C + l.height / 2, e.position.x = l.right, p = -50, c = 0;
|
|
110
111
|
break;
|
|
111
112
|
case "right-end":
|
|
112
|
-
e.position.y =
|
|
113
|
+
e.position.y = l.bottom, e.position.x = l.right, p = -100, c = 0;
|
|
113
114
|
break;
|
|
114
115
|
}
|
|
115
116
|
} else
|
|
116
|
-
switch (
|
|
117
|
+
switch (m) {
|
|
117
118
|
case "bottom":
|
|
118
|
-
e.position.y =
|
|
119
|
+
e.position.y = i.bottom - s.value.height, e.position.x = i.left + i.width / 2, c = -50;
|
|
119
120
|
break;
|
|
120
121
|
case "left-end":
|
|
121
122
|
case "bottom-start":
|
|
122
|
-
e.position.y =
|
|
123
|
+
e.position.y = i.bottom - s.value.height, e.position.x = i.left;
|
|
123
124
|
break;
|
|
124
125
|
case "right-end":
|
|
125
126
|
case "bottom-end":
|
|
126
|
-
e.position.y =
|
|
127
|
+
e.position.y = i.bottom - s.value.height, e.position.x = i.right - s.value.width;
|
|
127
128
|
break;
|
|
128
129
|
case "left":
|
|
129
|
-
e.position.y =
|
|
130
|
+
e.position.y = i.top + (i.height - s.value.height) / 2, e.position.x = i.left;
|
|
130
131
|
break;
|
|
131
132
|
case "top-start":
|
|
132
133
|
case "left-start":
|
|
133
|
-
e.position.y =
|
|
134
|
+
e.position.y = i.top, e.position.x = i.left;
|
|
134
135
|
break;
|
|
135
136
|
case "top":
|
|
136
|
-
e.position.y =
|
|
137
|
+
e.position.y = i.top, e.position.x = i.left + (i.width - s.value.width) / 2;
|
|
137
138
|
break;
|
|
138
139
|
case "top-end":
|
|
139
140
|
case "right-start":
|
|
140
|
-
e.position.y =
|
|
141
|
+
e.position.y = i.top, e.position.x = i.right - s.value.width;
|
|
141
142
|
case "right":
|
|
142
|
-
e.position.y =
|
|
143
|
+
e.position.y = i.top + (i.height - s.value.height) / 2, e.position.x = i.right - s.value.width;
|
|
143
144
|
break;
|
|
144
145
|
}
|
|
145
|
-
const v =
|
|
146
|
-
v.x <
|
|
146
|
+
const v = U(s.value, e.position, c, p);
|
|
147
|
+
e.position.x = v.x, e.position.y = v.y, v.x < i.left && (e.position.x = i.left, c = 0), v.x + s.value.width > i.right && (e.position.x = i.right - s.value.width, c = 0), v.y < i.top && (e.position.y = i.top, p = 0), v.y + s.value.height > i.bottom && (e.position.y = i.bottom - s.value.height, p = 0), t.value.style.top = `${e.position.y}px`, t.value.style.left = `${e.position.x}px`, t.value.style.position = "fixed", t.value.style.display = "flex", s.value = t.value.getBoundingClientRect();
|
|
147
148
|
});
|
|
148
|
-
return
|
|
149
|
+
return L(() => {
|
|
149
150
|
h.value.disconnect();
|
|
150
151
|
}), {
|
|
151
152
|
float: e,
|
|
152
|
-
rect:
|
|
153
|
+
rect: s,
|
|
153
154
|
floatObserver: h,
|
|
154
|
-
setPosition:
|
|
155
|
+
setPosition: b
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
function k(o) {
|
|
159
|
+
const t = window.matchMedia(o), a = f(t.matches);
|
|
160
|
+
function n(s) {
|
|
161
|
+
a.value = s.matches;
|
|
162
|
+
}
|
|
163
|
+
return E(() => {
|
|
164
|
+
t.addEventListener("change", n);
|
|
165
|
+
}), L(() => {
|
|
166
|
+
t.removeEventListener("change", n);
|
|
167
|
+
}), a;
|
|
168
|
+
}
|
|
169
|
+
function G(o) {
|
|
170
|
+
return {
|
|
171
|
+
isGreater(t) {
|
|
172
|
+
return k(`(min-width: ${o[t]})`);
|
|
173
|
+
},
|
|
174
|
+
isSmaller(t) {
|
|
175
|
+
return k(`(max-width: ${o[t]})`);
|
|
176
|
+
},
|
|
177
|
+
isInBetween(t, a) {
|
|
178
|
+
return k(`(min-width: ${o[t]}) and (max-width: ${o[a]})`);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function H(o, t) {
|
|
183
|
+
if (!o)
|
|
184
|
+
throw new Error("A target component has to be provided.");
|
|
185
|
+
if (!t)
|
|
186
|
+
throw new Error("A callback has to be provided.");
|
|
187
|
+
const a = (n) => {
|
|
188
|
+
!o.value || n.target === o.value || n.composedPath().includes(o.value) || typeof t == "function" && t();
|
|
155
189
|
};
|
|
156
|
-
|
|
190
|
+
E(() => {
|
|
191
|
+
window.addEventListener("click", a);
|
|
192
|
+
}), M(() => {
|
|
193
|
+
window.removeEventListener("click", a);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const V = /* @__PURE__ */ P({
|
|
157
197
|
__name: "FzFloating",
|
|
158
198
|
props: {
|
|
159
199
|
isOpen: { type: Boolean, default: !1 },
|
|
160
200
|
position: { default: "auto" },
|
|
161
|
-
container: {}
|
|
201
|
+
container: {},
|
|
202
|
+
contentClass: {},
|
|
203
|
+
openerClass: {}
|
|
162
204
|
},
|
|
163
|
-
setup(
|
|
164
|
-
const
|
|
165
|
-
position:
|
|
205
|
+
setup(o) {
|
|
206
|
+
const t = o, a = f(null), n = f(null), s = N(), e = {
|
|
207
|
+
position: T(() => t.position),
|
|
166
208
|
element: {
|
|
167
|
-
domRef:
|
|
209
|
+
domRef: n
|
|
168
210
|
},
|
|
169
211
|
container: {
|
|
170
|
-
domRef:
|
|
212
|
+
domRef: W(t.container || document.body)
|
|
171
213
|
}
|
|
172
214
|
};
|
|
173
|
-
|
|
174
|
-
domRef:
|
|
215
|
+
s.opener && (e.opener = {
|
|
216
|
+
domRef: a
|
|
175
217
|
});
|
|
176
|
-
const
|
|
177
|
-
return
|
|
178
|
-
() =>
|
|
179
|
-
() =>
|
|
180
|
-
),
|
|
181
|
-
() =>
|
|
182
|
-
(
|
|
183
|
-
|
|
184
|
-
|
|
218
|
+
const u = X(e);
|
|
219
|
+
return O(
|
|
220
|
+
() => t.position,
|
|
221
|
+
() => t.isOpen && u.setPosition()
|
|
222
|
+
), O(
|
|
223
|
+
() => t.isOpen,
|
|
224
|
+
(r) => {
|
|
225
|
+
!r || !n.value || (n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none", u.setPosition());
|
|
226
|
+
}
|
|
227
|
+
), (r, h) => (q(), A("div", null, [
|
|
228
|
+
$("div", {
|
|
185
229
|
ref_key: "opener",
|
|
186
|
-
ref:
|
|
230
|
+
ref: a,
|
|
187
231
|
class: "inline-flex"
|
|
188
232
|
}, [
|
|
189
|
-
|
|
190
|
-
isOpen:
|
|
191
|
-
floating:
|
|
233
|
+
w(r.$slots, "opener", {
|
|
234
|
+
isOpen: r.isOpen,
|
|
235
|
+
floating: F(u)
|
|
192
236
|
})
|
|
193
237
|
], 512),
|
|
194
|
-
|
|
238
|
+
w(r.$slots, "opener-end"),
|
|
239
|
+
D($("div", {
|
|
195
240
|
ref_key: "content",
|
|
196
|
-
ref:
|
|
197
|
-
class: "bg-core-white
|
|
241
|
+
ref: n,
|
|
242
|
+
class: I(["bg-core-white fixed p-4 z-10", r.contentClass])
|
|
198
243
|
}, [
|
|
199
|
-
|
|
200
|
-
isOpen:
|
|
201
|
-
floating:
|
|
244
|
+
w(r.$slots, "default", {
|
|
245
|
+
isOpen: r.isOpen,
|
|
246
|
+
floating: F(u)
|
|
202
247
|
})
|
|
203
|
-
],
|
|
204
|
-
[
|
|
248
|
+
], 2), [
|
|
249
|
+
[Q, r.$slots.default && (!r.$slots.opener || r.$slots.opener && r.isOpen)]
|
|
205
250
|
])
|
|
206
251
|
]));
|
|
207
252
|
}
|
|
208
253
|
});
|
|
209
254
|
export {
|
|
210
|
-
|
|
211
|
-
|
|
255
|
+
V as FzFloating,
|
|
256
|
+
G as useBreakpoints,
|
|
257
|
+
H as useClickOutside,
|
|
258
|
+
X as useFloating,
|
|
259
|
+
k as useMediaQuery
|
|
212
260
|
};
|
package/dist/composables.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(f,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],o):(f=typeof globalThis<"u"?globalThis:f||self,o(f.FzComposables={},f.Vue))})(this,function(f,o){"use strict";const k=(i,t,l,s)=>{let a="right",e="right-start";const u=i.getBoundingClientRect(),p=t.getBoundingClientRect(),h=l.getBoundingClientRect(),x=(h.left-u.left-p.width)/u.width,r=(u.right-h.right-p.width)/u.width,n=(h.top-u.top-p.height)/u.height,m=(u.bottom-h.bottom-p.height)/u.height;if(a=[{key:"right",space:r},{key:"top",space:n},{key:"bottom",space:m},{key:"left",space:x}].sort((c,d)=>d.space-c.space)[0].key,!s)switch(a){case"right":case"left":const c=(p.height-h.height)/2;u.top>h.top-c&&(s="end"),u.bottom<h.top-c&&(s="start");break}return e=s?`${a}-${s}`:a,e},F=(i,t,l,s)=>({x:t.x+i.width*l/100,y:t.y+i.height*s/100}),R=i=>{const t=o.ref(null),l=o.ref(null),s=o.ref(null),a=o.ref(null),e=o.reactive({position:{x:0,y:0}}),u={root:null,rootMargin:"0px",threshold:1,...i.element.intersectionOptions},p=(r,n)=>{},h=o.ref(new IntersectionObserver(p,u)),x=()=>o.nextTick(()=>{var B;if(t.value=typeof i.element.domRef.value=="string"?document.querySelector(i.element.domRef.value):i.element.domRef.value,i.container?(l.value=typeof i.container.domRef.value=="string"?document.querySelector(i.container.domRef.value):i.container.domRef.value,l.value??(l.value=document.body)):l.value=document.body,!t.value)throw new Error("missing reference element for floating behavior");i.opener&&(s.value=typeof i.opener.domRef.value=="string"?document.querySelector(i.opener.domRef.value):i.opener.domRef.value),a.value=t.value.getBoundingClientRect();const r=(B=s.value)==null?void 0:B.getBoundingClientRect(),n=l.value.getBoundingClientRect(),m=window.getComputedStyle(t.value);h.value.observe(t.value),h.value.observe(l.value);let g=i.position?i.position.value:"auto",c=0,d=0;if(i.opener&&s.value&&r){const b=r.left-parseFloat(m.marginLeft)-parseFloat(m.marginRight),C=r.left-parseFloat(m.marginLeft),v=r.top-parseFloat(m.marginTop)-parseFloat(m.marginBottom),O=r.top-parseFloat(m.marginTop);switch(g){case"auto":g=k(l.value,t.value,s.value);break;case"auto-start":g=k(l.value,t.value,s.value,"start");break;case"auto-end":g=k(l.value,t.value,s.value,"end");break}switch(g){case"bottom":e.position.y=r.bottom,e.position.x=C+r.width/2,d=-50,c=0;break;case"bottom-start":e.position.y=r.bottom,e.position.x=b,d=0,c=0;break;case"bottom-end":e.position.y=r.bottom,e.position.x=r.right,d=-100,c=0;break;case"left-start":e.position.y=v,e.position.x=b,d=-100,c=0;break;case"left":e.position.y=O+r.height/2,e.position.x=b,c=-50,d=-100;break;case"left-end":e.position.y=r.bottom,e.position.x=b,c=-100,d=-100;break;case"top-start":e.position.y=v,e.position.x=b,c=-100,d=0;break;case"top":e.position.y=v,e.position.x=C+r.width/2,d=-50,c=-100;break;case"top-end":e.position.y=v,e.position.x=r.right,d=-100,c=-100;break;case"right-start":e.position.y=v,e.position.x=r.right,d=0,c=0;break;case"right":e.position.y=O+r.height/2,e.position.x=r.right,c=-50,d=0;break;case"right-end":e.position.y=r.bottom,e.position.x=r.right,c=-100,d=0;break}}else switch(g){case"bottom":e.position.y=n.bottom-a.value.height,e.position.x=n.left+n.width/2,d=-50;break;case"left-end":case"bottom-start":e.position.y=n.bottom-a.value.height,e.position.x=n.left;break;case"right-end":case"bottom-end":e.position.y=n.bottom-a.value.height,e.position.x=n.right-a.value.width;break;case"left":e.position.y=n.top+(n.height-a.value.height)/2,e.position.x=n.left;break;case"top-start":case"left-start":e.position.y=n.top,e.position.x=n.left;break;case"top":e.position.y=n.top,e.position.x=n.left+(n.width-a.value.width)/2;break;case"top-end":case"right-start":e.position.y=n.top,e.position.x=n.right-a.value.width;case"right":e.position.y=n.top+(n.height-a.value.height)/2,e.position.x=n.right-a.value.width;break}const y=F(a.value,e.position,d,c);e.position.x=y.x,e.position.y=y.y,y.x<n.left&&(e.position.x=n.left,d=0),y.x+a.value.width>n.right&&(e.position.x=n.right-a.value.width,d=0),y.y<n.top&&(e.position.y=n.top,c=0),y.y+a.value.height>n.bottom&&(e.position.y=n.bottom-a.value.height,c=0),t.value.style.top=`${e.position.y}px`,t.value.style.left=`${e.position.x}px`,t.value.style.position="fixed",t.value.style.display="flex",a.value=t.value.getBoundingClientRect()});return o.onUnmounted(()=>{h.value.disconnect()}),{float:e,rect:a,floatObserver:h,setPosition:x}};function w(i){const t=window.matchMedia(i),l=o.ref(t.matches);function s(a){l.value=a.matches}return o.onMounted(()=>{t.addEventListener("change",s)}),o.onUnmounted(()=>{t.removeEventListener("change",s)}),l}function S(i){return{isGreater(t){return w(`(min-width: ${i[t]})`)},isSmaller(t){return w(`(max-width: ${i[t]})`)},isInBetween(t,l){return w(`(min-width: ${i[t]}) and (max-width: ${i[l]})`)}}}function $(i,t){if(!i)throw new Error("A target component has to be provided.");if(!t)throw new Error("A callback has to be provided.");const l=s=>{!i.value||s.target===i.value||s.composedPath().includes(i.value)||typeof t=="function"&&t()};o.onMounted(()=>{window.addEventListener("click",l)}),o.onBeforeUnmount(()=>{window.removeEventListener("click",l)})}const E=o.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{},contentClass:{},openerClass:{}},setup(i){const t=i,l=o.ref(null),s=o.ref(null),a=o.useSlots(),e={position:o.computed(()=>t.position),element:{domRef:s},container:{domRef:o.toRef(t.container||document.body)}};a.opener&&(e.opener={domRef:l});const u=R(e);return o.watch(()=>t.position,()=>t.isOpen&&u.setPosition()),o.watch(()=>t.isOpen,p=>{!p||!s.value||(s.value.style.top="0px",s.value.style.left="0px",s.value.style.transform="none",u.setPosition())}),(p,h)=>(o.openBlock(),o.createElementBlock("div",null,[o.createElementVNode("div",{ref_key:"opener",ref:l,class:"inline-flex"},[o.renderSlot(p.$slots,"opener",{isOpen:p.isOpen,floating:o.unref(u)})],512),o.renderSlot(p.$slots,"opener-end"),o.withDirectives(o.createElementVNode("div",{ref_key:"content",ref:s,class:o.normalizeClass(["bg-core-white fixed p-4 z-10",p.contentClass])},[o.renderSlot(p.$slots,"default",{isOpen:p.isOpen,floating:o.unref(u)})],2),[[o.vShow,p.$slots.default&&(!p.$slots.opener||p.$slots.opener&&p.isOpen)]])]))}});f.FzFloating=E,f.useBreakpoints=S,f.useClickOutside=$,f.useFloating=R,f.useMediaQuery=w,Object.defineProperty(f,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.9",
|
|
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/tsconfig": "^0.1.0",
|
|
29
|
-
"@fiscozen/
|
|
30
|
-
"@fiscozen/
|
|
29
|
+
"@fiscozen/eslint-config": "^0.1.0",
|
|
30
|
+
"@fiscozen/prettier-config": "^0.1.0"
|
|
31
31
|
},
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"scripts": {
|
package/src/FzFloating.vue
CHANGED
|
@@ -46,6 +46,14 @@ watch(
|
|
|
46
46
|
floating.setPosition()
|
|
47
47
|
}
|
|
48
48
|
)
|
|
49
|
+
|
|
50
|
+
const contentClass = computed(() => {
|
|
51
|
+
if (props.overrideContentClass) {
|
|
52
|
+
return props.contentClass
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return ['bg-core-white fixed p-4 z-10', props.contentClass]
|
|
56
|
+
})
|
|
49
57
|
</script>
|
|
50
58
|
|
|
51
59
|
<template>
|
|
@@ -54,16 +62,13 @@ watch(
|
|
|
54
62
|
<slot name="opener" :isOpen :floating></slot>
|
|
55
63
|
</div>
|
|
56
64
|
<slot name="opener-end"></slot>
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<slot :isOpen :floating></slot>
|
|
65
|
-
</div>
|
|
66
|
-
</Teleport>
|
|
65
|
+
<div
|
|
66
|
+
ref="content"
|
|
67
|
+
v-show="$slots.default && (!$slots.opener || ($slots.opener && isOpen))"
|
|
68
|
+
:class="contentClass"
|
|
69
|
+
>
|
|
70
|
+
<slot :isOpen :floating></slot>
|
|
71
|
+
</div>
|
|
67
72
|
</div>
|
|
68
73
|
</template>
|
|
69
74
|
|
|
@@ -61,8 +61,8 @@ export const useFloating = (
|
|
|
61
61
|
rect.value = safeElementDomRef.value.getBoundingClientRect()
|
|
62
62
|
const openerRect = safeOpenerDomRef.value?.getBoundingClientRect()
|
|
63
63
|
const containerRect = safeContainerDomRef.value.getBoundingClientRect()
|
|
64
|
-
|
|
65
|
-
const elStyle = window.getComputedStyle(safeElementDomRef.value)
|
|
64
|
+
|
|
65
|
+
const elStyle = window.getComputedStyle(safeElementDomRef.value)
|
|
66
66
|
|
|
67
67
|
// multiple observer calls on same target do not cause multiple registrations
|
|
68
68
|
floatObserver.value.observe(safeElementDomRef.value)
|
|
@@ -74,11 +74,12 @@ export const useFloating = (
|
|
|
74
74
|
let translateX = 0
|
|
75
75
|
|
|
76
76
|
if (args.opener && safeOpenerDomRef.value && openerRect) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const leftWithoutLeftMargin = openerRect.left - parseFloat(elStyle.marginLeft)
|
|
80
|
-
const topWithoutYMargin =
|
|
81
|
-
|
|
77
|
+
const leftWithoutXMargin =
|
|
78
|
+
openerRect.left - parseFloat(elStyle.marginLeft) - parseFloat(elStyle.marginRight)
|
|
79
|
+
const leftWithoutLeftMargin = openerRect.left - parseFloat(elStyle.marginLeft)
|
|
80
|
+
const topWithoutYMargin =
|
|
81
|
+
openerRect.top - parseFloat(elStyle.marginTop) - parseFloat(elStyle.marginBottom)
|
|
82
|
+
const topWithoutTopMargin = openerRect.top - parseFloat(elStyle.marginTop)
|
|
82
83
|
|
|
83
84
|
switch (position) {
|
|
84
85
|
case 'auto':
|
|
@@ -228,7 +229,7 @@ export const useFloating = (
|
|
|
228
229
|
|
|
229
230
|
const realPos = calcRealPos(rect.value, float.position, translateX, translateY)
|
|
230
231
|
|
|
231
|
-
float.position.x = realPos.x
|
|
232
|
+
float.position.x = realPos.x
|
|
232
233
|
float.position.y = realPos.y
|
|
233
234
|
|
|
234
235
|
if (realPos.x < containerRect.left) {
|
package/src/types.ts
CHANGED
|
@@ -8,8 +8,17 @@ export interface FzFloatingProps {
|
|
|
8
8
|
isOpen: boolean
|
|
9
9
|
position?: FzFloatingPosition
|
|
10
10
|
container?: string | null
|
|
11
|
-
contentClass?:
|
|
12
|
-
|
|
11
|
+
contentClass?:
|
|
12
|
+
| string
|
|
13
|
+
| string[]
|
|
14
|
+
| Record<string, boolean | undefined>
|
|
15
|
+
| Array<string | Record<string, boolean | undefined>>
|
|
16
|
+
openerClass?:
|
|
17
|
+
| string
|
|
18
|
+
| string[]
|
|
19
|
+
| Record<string, boolean | undefined>
|
|
20
|
+
| Array<string | Record<string, boolean | undefined>>
|
|
21
|
+
overrideContentClass?: boolean
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
export interface FzAbsolutePosition {
|