@fiscozen/composables 0.1.9 → 0.1.11
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 +146 -107
- package/dist/composables.umd.cjs +1 -1
- package/package.json +1 -1
- package/src/composables/index.ts +2 -0
- package/src/composables/useKeyDown.ts +26 -0
- package/src/composables/useKeyUp.ts +30 -0
package/dist/composables.js
CHANGED
|
@@ -1,260 +1,299 @@
|
|
|
1
|
-
import { ref as f, reactive as
|
|
2
|
-
const x = (o, t,
|
|
3
|
-
let
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
1
|
+
import { ref as f, reactive as M, onUnmounted as z, nextTick as P, onMounted as w, onBeforeUnmount as C, defineComponent as A, useSlots as N, computed as O, toRef as T, watch as $, openBlock as D, createElementBlock as W, createElementVNode as F, renderSlot as k, unref as S, withDirectives as q, normalizeClass as I, vShow as U } from "vue";
|
|
2
|
+
const x = (o, t, i, n) => {
|
|
3
|
+
let a = "right", e = "right-start";
|
|
4
|
+
const c = o.getBoundingClientRect(), d = t.getBoundingClientRect(), r = i.getBoundingClientRect(), b = (r.left - c.left - d.width) / c.width, l = (c.right - r.right - d.width) / c.width, s = (r.top - c.top - d.height) / c.height, h = (c.bottom - r.bottom - d.height) / c.height;
|
|
5
|
+
if (a = [
|
|
6
6
|
{
|
|
7
7
|
key: "right",
|
|
8
8
|
space: l
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
key: "top",
|
|
12
|
-
space:
|
|
12
|
+
space: s
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
key: "bottom",
|
|
16
|
-
space:
|
|
16
|
+
space: h
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
key: "left",
|
|
20
20
|
space: b
|
|
21
21
|
}
|
|
22
|
-
].sort((p,
|
|
23
|
-
switch (
|
|
22
|
+
].sort((p, u) => u.space - p.space)[0].key, !n)
|
|
23
|
+
switch (a) {
|
|
24
24
|
case "right":
|
|
25
25
|
case "left":
|
|
26
|
-
const p = (
|
|
27
|
-
|
|
26
|
+
const p = (d.height - r.height) / 2;
|
|
27
|
+
c.top > r.top - p && (n = "end"), c.bottom < r.top - p && (n = "start");
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
|
-
return e = n ? `${
|
|
31
|
-
},
|
|
32
|
-
x: t.x + o.width *
|
|
30
|
+
return e = n ? `${a}-${n}` : a, e;
|
|
31
|
+
}, K = (o, t, i, n) => ({
|
|
32
|
+
x: t.x + o.width * i / 100,
|
|
33
33
|
y: t.y + o.height * n / 100
|
|
34
|
-
}),
|
|
35
|
-
const t = f(null),
|
|
34
|
+
}), Q = (o) => {
|
|
35
|
+
const t = f(null), i = f(null), n = f(null), a = f(null), e = M({
|
|
36
36
|
position: { x: 0, y: 0 }
|
|
37
|
-
}),
|
|
37
|
+
}), c = {
|
|
38
38
|
root: null,
|
|
39
39
|
rootMargin: "0px",
|
|
40
40
|
threshold: 1,
|
|
41
41
|
...o.element.intersectionOptions
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
var
|
|
45
|
-
if (t.value = typeof o.element.domRef.value == "string" ? document.querySelector(o.element.domRef.value) : o.element.domRef.value, o.container ? (
|
|
42
|
+
}, d = (l, s) => {
|
|
43
|
+
}, r = f(new IntersectionObserver(d, c)), b = () => P(() => {
|
|
44
|
+
var E;
|
|
45
|
+
if (t.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, !t.value)
|
|
46
46
|
throw new Error("missing reference element for floating behavior");
|
|
47
|
-
o.opener && (n.value = typeof o.opener.domRef.value == "string" ? document.querySelector(o.opener.domRef.value) : o.opener.domRef.value),
|
|
48
|
-
const l = (
|
|
49
|
-
|
|
50
|
-
let
|
|
47
|
+
o.opener && (n.value = typeof o.opener.domRef.value == "string" ? document.querySelector(o.opener.domRef.value) : o.opener.domRef.value), a.value = t.value.getBoundingClientRect();
|
|
48
|
+
const l = (E = n.value) == null ? void 0 : E.getBoundingClientRect(), s = i.value.getBoundingClientRect(), h = window.getComputedStyle(t.value);
|
|
49
|
+
r.value.observe(t.value), r.value.observe(i.value);
|
|
50
|
+
let v = o.position ? o.position.value : "auto", p = 0, u = 0;
|
|
51
51
|
if (o.opener && n.value && l) {
|
|
52
|
-
const g = l.left - parseFloat(
|
|
53
|
-
switch (
|
|
52
|
+
const g = l.left - parseFloat(h.marginLeft) - parseFloat(h.marginRight), L = l.left - parseFloat(h.marginLeft), y = l.top - parseFloat(h.marginTop) - parseFloat(h.marginBottom), B = l.top - parseFloat(h.marginTop);
|
|
53
|
+
switch (v) {
|
|
54
54
|
case "auto":
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
v = x(
|
|
56
|
+
i.value,
|
|
57
57
|
t.value,
|
|
58
58
|
n.value
|
|
59
59
|
);
|
|
60
60
|
break;
|
|
61
61
|
case "auto-start":
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
v = x(
|
|
63
|
+
i.value,
|
|
64
64
|
t.value,
|
|
65
65
|
n.value,
|
|
66
66
|
"start"
|
|
67
67
|
);
|
|
68
68
|
break;
|
|
69
69
|
case "auto-end":
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
v = x(
|
|
71
|
+
i.value,
|
|
72
72
|
t.value,
|
|
73
73
|
n.value,
|
|
74
74
|
"end"
|
|
75
75
|
);
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
|
-
switch (
|
|
78
|
+
switch (v) {
|
|
79
79
|
case "bottom":
|
|
80
|
-
e.position.y = l.bottom, e.position.x =
|
|
80
|
+
e.position.y = l.bottom, e.position.x = L + l.width / 2, u = -50, p = 0;
|
|
81
81
|
break;
|
|
82
82
|
case "bottom-start":
|
|
83
|
-
e.position.y = l.bottom, e.position.x = g,
|
|
83
|
+
e.position.y = l.bottom, e.position.x = g, u = 0, p = 0;
|
|
84
84
|
break;
|
|
85
85
|
case "bottom-end":
|
|
86
|
-
e.position.y = l.bottom, e.position.x = l.right,
|
|
86
|
+
e.position.y = l.bottom, e.position.x = l.right, u = -100, p = 0;
|
|
87
87
|
break;
|
|
88
88
|
case "left-start":
|
|
89
|
-
e.position.y = y, e.position.x = g,
|
|
89
|
+
e.position.y = y, e.position.x = g, u = -100, p = 0;
|
|
90
90
|
break;
|
|
91
91
|
case "left":
|
|
92
|
-
e.position.y =
|
|
92
|
+
e.position.y = B + l.height / 2, e.position.x = g, p = -50, u = -100;
|
|
93
93
|
break;
|
|
94
94
|
case "left-end":
|
|
95
|
-
e.position.y = l.bottom, e.position.x = g, p = -100,
|
|
95
|
+
e.position.y = l.bottom, e.position.x = g, p = -100, u = -100;
|
|
96
96
|
break;
|
|
97
97
|
case "top-start":
|
|
98
|
-
e.position.y = y, e.position.x = g, p = -100,
|
|
98
|
+
e.position.y = y, e.position.x = g, p = -100, u = 0;
|
|
99
99
|
break;
|
|
100
100
|
case "top":
|
|
101
|
-
e.position.y = y, e.position.x =
|
|
101
|
+
e.position.y = y, e.position.x = L + l.width / 2, u = -50, p = -100;
|
|
102
102
|
break;
|
|
103
103
|
case "top-end":
|
|
104
|
-
e.position.y = y, e.position.x = l.right,
|
|
104
|
+
e.position.y = y, e.position.x = l.right, u = -100, p = -100;
|
|
105
105
|
break;
|
|
106
106
|
case "right-start":
|
|
107
|
-
e.position.y = y, e.position.x = l.right,
|
|
107
|
+
e.position.y = y, e.position.x = l.right, u = 0, p = 0;
|
|
108
108
|
break;
|
|
109
109
|
case "right":
|
|
110
|
-
e.position.y =
|
|
110
|
+
e.position.y = B + l.height / 2, e.position.x = l.right, p = -50, u = 0;
|
|
111
111
|
break;
|
|
112
112
|
case "right-end":
|
|
113
|
-
e.position.y = l.bottom, e.position.x = l.right, p = -100,
|
|
113
|
+
e.position.y = l.bottom, e.position.x = l.right, p = -100, u = 0;
|
|
114
114
|
break;
|
|
115
115
|
}
|
|
116
116
|
} else
|
|
117
|
-
switch (
|
|
117
|
+
switch (v) {
|
|
118
118
|
case "bottom":
|
|
119
|
-
e.position.y =
|
|
119
|
+
e.position.y = s.bottom - a.value.height, e.position.x = s.left + s.width / 2, u = -50;
|
|
120
120
|
break;
|
|
121
121
|
case "left-end":
|
|
122
122
|
case "bottom-start":
|
|
123
|
-
e.position.y =
|
|
123
|
+
e.position.y = s.bottom - a.value.height, e.position.x = s.left;
|
|
124
124
|
break;
|
|
125
125
|
case "right-end":
|
|
126
126
|
case "bottom-end":
|
|
127
|
-
e.position.y =
|
|
127
|
+
e.position.y = s.bottom - a.value.height, e.position.x = s.right - a.value.width;
|
|
128
128
|
break;
|
|
129
129
|
case "left":
|
|
130
|
-
e.position.y =
|
|
130
|
+
e.position.y = s.top + (s.height - a.value.height) / 2, e.position.x = s.left;
|
|
131
131
|
break;
|
|
132
132
|
case "top-start":
|
|
133
133
|
case "left-start":
|
|
134
|
-
e.position.y =
|
|
134
|
+
e.position.y = s.top, e.position.x = s.left;
|
|
135
135
|
break;
|
|
136
136
|
case "top":
|
|
137
|
-
e.position.y =
|
|
137
|
+
e.position.y = s.top, e.position.x = s.left + (s.width - a.value.width) / 2;
|
|
138
138
|
break;
|
|
139
139
|
case "top-end":
|
|
140
140
|
case "right-start":
|
|
141
|
-
e.position.y =
|
|
141
|
+
e.position.y = s.top, e.position.x = s.right - a.value.width;
|
|
142
142
|
case "right":
|
|
143
|
-
e.position.y =
|
|
143
|
+
e.position.y = s.top + (s.height - a.value.height) / 2, e.position.x = s.right - a.value.width;
|
|
144
144
|
break;
|
|
145
145
|
}
|
|
146
|
-
const
|
|
147
|
-
e.position.x =
|
|
146
|
+
const m = K(a.value, e.position, u, p);
|
|
147
|
+
e.position.x = m.x, e.position.y = m.y, m.x < s.left && (e.position.x = s.left, u = 0), m.x + a.value.width > s.right && (e.position.x = s.right - a.value.width, u = 0), m.y < s.top && (e.position.y = s.top, p = 0), m.y + a.value.height > s.bottom && (e.position.y = s.bottom - a.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", a.value = t.value.getBoundingClientRect();
|
|
148
148
|
});
|
|
149
|
-
return
|
|
150
|
-
|
|
149
|
+
return z(() => {
|
|
150
|
+
r.value.disconnect();
|
|
151
151
|
}), {
|
|
152
152
|
float: e,
|
|
153
|
-
rect:
|
|
154
|
-
floatObserver:
|
|
153
|
+
rect: a,
|
|
154
|
+
floatObserver: r,
|
|
155
155
|
setPosition: b
|
|
156
156
|
};
|
|
157
157
|
};
|
|
158
|
-
function
|
|
159
|
-
const t = window.matchMedia(o),
|
|
160
|
-
function n(
|
|
161
|
-
|
|
158
|
+
function R(o) {
|
|
159
|
+
const t = window.matchMedia(o), i = f(t.matches);
|
|
160
|
+
function n(a) {
|
|
161
|
+
i.value = a.matches;
|
|
162
162
|
}
|
|
163
|
-
return
|
|
163
|
+
return w(() => {
|
|
164
164
|
t.addEventListener("change", n);
|
|
165
|
-
}),
|
|
165
|
+
}), z(() => {
|
|
166
166
|
t.removeEventListener("change", n);
|
|
167
|
-
}),
|
|
167
|
+
}), i;
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function Y(o) {
|
|
170
170
|
return {
|
|
171
171
|
isGreater(t) {
|
|
172
|
-
return
|
|
172
|
+
return R(`(min-width: ${o[t]})`);
|
|
173
173
|
},
|
|
174
174
|
isSmaller(t) {
|
|
175
|
-
return
|
|
175
|
+
return R(`(max-width: ${o[t]})`);
|
|
176
176
|
},
|
|
177
|
-
isInBetween(t,
|
|
178
|
-
return
|
|
177
|
+
isInBetween(t, i) {
|
|
178
|
+
return R(`(min-width: ${o[t]}) and (max-width: ${o[i]})`);
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function G(o, t) {
|
|
183
183
|
if (!o)
|
|
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
|
|
187
|
+
const i = (n) => {
|
|
188
188
|
!o.value || n.target === o.value || n.composedPath().includes(o.value) || typeof t == "function" && t();
|
|
189
189
|
};
|
|
190
|
-
|
|
191
|
-
window.addEventListener("click",
|
|
192
|
-
}),
|
|
193
|
-
window.removeEventListener("click",
|
|
190
|
+
w(() => {
|
|
191
|
+
window.addEventListener("click", i);
|
|
192
|
+
}), C(() => {
|
|
193
|
+
window.removeEventListener("click", i);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function H(o, t) {
|
|
197
|
+
if (!o)
|
|
198
|
+
throw new Error("A target component has to be provided.");
|
|
199
|
+
if (!t || typeof t != "function")
|
|
200
|
+
throw new Error("A callback has to be provided.");
|
|
201
|
+
const i = (n) => {
|
|
202
|
+
t(n);
|
|
203
|
+
};
|
|
204
|
+
w(() => {
|
|
205
|
+
o.value.addEventListener("keydown", i);
|
|
206
|
+
}), C(() => {
|
|
207
|
+
o.value.removeEventListener("keydown", i);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function V(o, t) {
|
|
211
|
+
if (!o || typeof o != "function")
|
|
212
|
+
throw new Error("A callback has to be provided.");
|
|
213
|
+
const i = (n) => {
|
|
214
|
+
o(n);
|
|
215
|
+
};
|
|
216
|
+
w(() => {
|
|
217
|
+
if (!t) {
|
|
218
|
+
document.addEventListener("keyup", i);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
t.value.addEventListener("keyup", i);
|
|
222
|
+
}), C(() => {
|
|
223
|
+
if (!t) {
|
|
224
|
+
document.removeEventListener("keyup", i);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
t.value.removeEventListener("keyup", i);
|
|
194
228
|
});
|
|
195
229
|
}
|
|
196
|
-
const
|
|
230
|
+
const J = /* @__PURE__ */ A({
|
|
197
231
|
__name: "FzFloating",
|
|
198
232
|
props: {
|
|
199
233
|
isOpen: { type: Boolean, default: !1 },
|
|
200
234
|
position: { default: "auto" },
|
|
201
235
|
container: {},
|
|
202
236
|
contentClass: {},
|
|
203
|
-
openerClass: {}
|
|
237
|
+
openerClass: {},
|
|
238
|
+
overrideContentClass: { type: Boolean }
|
|
204
239
|
},
|
|
205
240
|
setup(o) {
|
|
206
|
-
const t = o,
|
|
207
|
-
position:
|
|
241
|
+
const t = o, i = f(null), n = f(null), a = N(), e = {
|
|
242
|
+
position: O(() => t.position),
|
|
208
243
|
element: {
|
|
209
244
|
domRef: n
|
|
210
245
|
},
|
|
211
246
|
container: {
|
|
212
|
-
domRef:
|
|
247
|
+
domRef: T(t.container || document.body)
|
|
213
248
|
}
|
|
214
249
|
};
|
|
215
|
-
|
|
216
|
-
domRef:
|
|
250
|
+
a.opener && (e.opener = {
|
|
251
|
+
domRef: i
|
|
217
252
|
});
|
|
218
|
-
const
|
|
219
|
-
|
|
253
|
+
const c = Q(e);
|
|
254
|
+
$(
|
|
220
255
|
() => t.position,
|
|
221
|
-
() => t.isOpen &&
|
|
222
|
-
),
|
|
256
|
+
() => t.isOpen && c.setPosition()
|
|
257
|
+
), $(
|
|
223
258
|
() => t.isOpen,
|
|
224
259
|
(r) => {
|
|
225
|
-
!r || !n.value || (n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none",
|
|
260
|
+
!r || !n.value || (n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none", c.setPosition());
|
|
226
261
|
}
|
|
227
|
-
)
|
|
228
|
-
|
|
262
|
+
);
|
|
263
|
+
const d = O(() => t.overrideContentClass ? t.contentClass : ["bg-core-white fixed p-4 z-10", t.contentClass]);
|
|
264
|
+
return (r, b) => (D(), W("div", null, [
|
|
265
|
+
F("div", {
|
|
229
266
|
ref_key: "opener",
|
|
230
|
-
ref:
|
|
267
|
+
ref: i,
|
|
231
268
|
class: "inline-flex"
|
|
232
269
|
}, [
|
|
233
|
-
|
|
270
|
+
k(r.$slots, "opener", {
|
|
234
271
|
isOpen: r.isOpen,
|
|
235
|
-
floating:
|
|
272
|
+
floating: S(c)
|
|
236
273
|
})
|
|
237
274
|
], 512),
|
|
238
|
-
|
|
239
|
-
|
|
275
|
+
k(r.$slots, "opener-end"),
|
|
276
|
+
q(F("div", {
|
|
240
277
|
ref_key: "content",
|
|
241
278
|
ref: n,
|
|
242
|
-
class: I(
|
|
279
|
+
class: I(d.value)
|
|
243
280
|
}, [
|
|
244
|
-
|
|
281
|
+
k(r.$slots, "default", {
|
|
245
282
|
isOpen: r.isOpen,
|
|
246
|
-
floating:
|
|
283
|
+
floating: S(c)
|
|
247
284
|
})
|
|
248
285
|
], 2), [
|
|
249
|
-
[
|
|
286
|
+
[U, r.$slots.default && (!r.$slots.opener || r.$slots.opener && r.isOpen)]
|
|
250
287
|
])
|
|
251
288
|
]));
|
|
252
289
|
}
|
|
253
290
|
});
|
|
254
291
|
export {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
292
|
+
J as FzFloating,
|
|
293
|
+
Y as useBreakpoints,
|
|
294
|
+
G as useClickOutside,
|
|
295
|
+
Q as useFloating,
|
|
296
|
+
H as useKeyDown,
|
|
297
|
+
V as useKeyUp,
|
|
298
|
+
R as useMediaQuery
|
|
260
299
|
};
|
package/dist/composables.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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 x=(n,t,i,s)=>{let r="right",e="right-start";const d=n.getBoundingClientRect(),h=t.getBoundingClientRect(),l=i.getBoundingClientRect(),k=(l.left-d.left-h.width)/d.width,p=(d.right-l.right-h.width)/d.width,a=(l.top-d.top-h.height)/d.height,m=(d.bottom-l.bottom-h.height)/d.height;if(r=[{key:"right",space:p},{key:"top",space:a},{key:"bottom",space:m},{key:"left",space:k}].sort((c,u)=>u.space-c.space)[0].key,!s)switch(r){case"right":case"left":const c=(h.height-l.height)/2;d.top>l.top-c&&(s="end"),d.bottom<l.top-c&&(s="start");break}return e=s?`${r}-${s}`:r,e},L=(n,t,i,s)=>({x:t.x+n.width*i/100,y:t.y+n.height*s/100}),R=n=>{const t=o.ref(null),i=o.ref(null),s=o.ref(null),r=o.ref(null),e=o.reactive({position:{x:0,y:0}}),d={root:null,rootMargin:"0px",threshold:1,...n.element.intersectionOptions},h=(p,a)=>{},l=o.ref(new IntersectionObserver(h,d)),k=()=>o.nextTick(()=>{var C;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)throw new Error("missing reference element for floating behavior");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();const p=(C=s.value)==null?void 0:C.getBoundingClientRect(),a=i.value.getBoundingClientRect(),m=window.getComputedStyle(t.value);l.value.observe(t.value),l.value.observe(i.value);let g=n.position?n.position.value:"auto",c=0,u=0;if(n.opener&&s.value&&p){const v=p.left-parseFloat(m.marginLeft)-parseFloat(m.marginRight),E=p.left-parseFloat(m.marginLeft),b=p.top-parseFloat(m.marginTop)-parseFloat(m.marginBottom),B=p.top-parseFloat(m.marginTop);switch(g){case"auto":g=x(i.value,t.value,s.value);break;case"auto-start":g=x(i.value,t.value,s.value,"start");break;case"auto-end":g=x(i.value,t.value,s.value,"end");break}switch(g){case"bottom":e.position.y=p.bottom,e.position.x=E+p.width/2,u=-50,c=0;break;case"bottom-start":e.position.y=p.bottom,e.position.x=v,u=0,c=0;break;case"bottom-end":e.position.y=p.bottom,e.position.x=p.right,u=-100,c=0;break;case"left-start":e.position.y=b,e.position.x=v,u=-100,c=0;break;case"left":e.position.y=B+p.height/2,e.position.x=v,c=-50,u=-100;break;case"left-end":e.position.y=p.bottom,e.position.x=v,c=-100,u=-100;break;case"top-start":e.position.y=b,e.position.x=v,c=-100,u=0;break;case"top":e.position.y=b,e.position.x=E+p.width/2,u=-50,c=-100;break;case"top-end":e.position.y=b,e.position.x=p.right,u=-100,c=-100;break;case"right-start":e.position.y=b,e.position.x=p.right,u=0,c=0;break;case"right":e.position.y=B+p.height/2,e.position.x=p.right,c=-50,u=0;break;case"right-end":e.position.y=p.bottom,e.position.x=p.right,c=-100,u=0;break}}else switch(g){case"bottom":e.position.y=a.bottom-r.value.height,e.position.x=a.left+a.width/2,u=-50;break;case"left-end":case"bottom-start":e.position.y=a.bottom-r.value.height,e.position.x=a.left;break;case"right-end":case"bottom-end":e.position.y=a.bottom-r.value.height,e.position.x=a.right-r.value.width;break;case"left":e.position.y=a.top+(a.height-r.value.height)/2,e.position.x=a.left;break;case"top-start":case"left-start":e.position.y=a.top,e.position.x=a.left;break;case"top":e.position.y=a.top,e.position.x=a.left+(a.width-r.value.width)/2;break;case"top-end":case"right-start":e.position.y=a.top,e.position.x=a.right-r.value.width;case"right":e.position.y=a.top+(a.height-r.value.height)/2,e.position.x=a.right-r.value.width;break}const y=L(r.value,e.position,u,c);e.position.x=y.x,e.position.y=y.y,y.x<a.left&&(e.position.x=a.left,u=0),y.x+r.value.width>a.right&&(e.position.x=a.right-r.value.width,u=0),y.y<a.top&&(e.position.y=a.top,c=0),y.y+r.value.height>a.bottom&&(e.position.y=a.bottom-r.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",r.value=t.value.getBoundingClientRect()});return o.onUnmounted(()=>{l.value.disconnect()}),{float:e,rect:r,floatObserver:l,setPosition:k}};function w(n){const t=window.matchMedia(n),i=o.ref(t.matches);function s(r){i.value=r.matches}return o.onMounted(()=>{t.addEventListener("change",s)}),o.onUnmounted(()=>{t.removeEventListener("change",s)}),i}function O(n){return{isGreater(t){return w(`(min-width: ${n[t]})`)},isSmaller(t){return w(`(max-width: ${n[t]})`)},isInBetween(t,i){return w(`(min-width: ${n[t]}) and (max-width: ${n[i]})`)}}}function F(n,t){if(!n)throw new Error("A target component has to be provided.");if(!t)throw new Error("A callback has to be provided.");const i=s=>{!n.value||s.target===n.value||s.composedPath().includes(n.value)||typeof t=="function"&&t()};o.onMounted(()=>{window.addEventListener("click",i)}),o.onBeforeUnmount(()=>{window.removeEventListener("click",i)})}function S(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 i=s=>{t(s)};o.onMounted(()=>{n.value.addEventListener("keydown",i)}),o.onBeforeUnmount(()=>{n.value.removeEventListener("keydown",i)})}function $(n,t){if(!n||typeof n!="function")throw new Error("A callback has to be provided.");const i=s=>{n(s)};o.onMounted(()=>{if(!t){document.addEventListener("keyup",i);return}t.value.addEventListener("keyup",i)}),o.onBeforeUnmount(()=>{if(!t){document.removeEventListener("keyup",i);return}t.value.removeEventListener("keyup",i)})}const M=o.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{},contentClass:{},openerClass:{},overrideContentClass:{type:Boolean}},setup(n){const t=n,i=o.ref(null),s=o.ref(null),r=o.useSlots(),e={position:o.computed(()=>t.position),element:{domRef:s},container:{domRef:o.toRef(t.container||document.body)}};r.opener&&(e.opener={domRef:i});const d=R(e);o.watch(()=>t.position,()=>t.isOpen&&d.setPosition()),o.watch(()=>t.isOpen,l=>{!l||!s.value||(s.value.style.top="0px",s.value.style.left="0px",s.value.style.transform="none",d.setPosition())});const h=o.computed(()=>t.overrideContentClass?t.contentClass:["bg-core-white fixed p-4 z-10",t.contentClass]);return(l,k)=>(o.openBlock(),o.createElementBlock("div",null,[o.createElementVNode("div",{ref_key:"opener",ref:i,class:"inline-flex"},[o.renderSlot(l.$slots,"opener",{isOpen:l.isOpen,floating:o.unref(d)})],512),o.renderSlot(l.$slots,"opener-end"),o.withDirectives(o.createElementVNode("div",{ref_key:"content",ref:s,class:o.normalizeClass(h.value)},[o.renderSlot(l.$slots,"default",{isOpen:l.isOpen,floating:o.unref(d)})],2),[[o.vShow,l.$slots.default&&(!l.$slots.opener||l.$slots.opener&&l.isOpen)]])]))}});f.FzFloating=M,f.useBreakpoints=O,f.useClickOutside=F,f.useFloating=R,f.useKeyDown=S,f.useKeyUp=$,f.useMediaQuery=w,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/composables/index.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted, Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
function useKeyDown(component: Ref<HTMLElement | undefined>, callback: (event: KeyboardEvent) => void) {
|
|
4
|
+
// fail early if any of the required params is missing
|
|
5
|
+
if (!component) {
|
|
6
|
+
throw new Error('A target component has to be provided.')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (!callback || typeof callback !== 'function') {
|
|
10
|
+
throw new Error('A callback has to be provided.')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const listener = (event: KeyboardEvent) => {
|
|
14
|
+
callback(event)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
onMounted(() => {
|
|
18
|
+
component.value!.addEventListener('keydown', listener)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
onBeforeUnmount(() => {
|
|
22
|
+
component.value!.removeEventListener('keydown', listener)
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { useKeyDown }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted, Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
function useKeyUp(callback: (event: KeyboardEvent) => void, component?: Ref<HTMLElement | undefined>) {
|
|
4
|
+
|
|
5
|
+
if (!callback || typeof callback !== 'function') {
|
|
6
|
+
throw new Error('A callback has to be provided.')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const listener = (event: KeyboardEvent) => {
|
|
10
|
+
callback(event)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
onMounted(() => {
|
|
14
|
+
if (!component) {
|
|
15
|
+
document.addEventListener('keyup', listener)
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
component.value!.addEventListener('keyup', listener)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
onBeforeUnmount(() => {
|
|
22
|
+
if (!component) {
|
|
23
|
+
document.removeEventListener('keyup', listener)
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
component.value!.removeEventListener('keyup', listener)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { useKeyUp }
|