sb-floating-panel-vue 1.0.0 → 3.0.0
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/README.md +255 -128
- package/dist/components/SbContainer.vue.d.ts +30 -61
- package/dist/components/SbFloating.vue.d.ts +21 -69
- package/dist/components/SbReference.vue.d.ts +10 -34
- package/dist/composables/useSbFloatingPanel.d.ts +26 -76
- package/dist/context.d.ts +23 -0
- package/dist/index.d.ts +1 -1
- package/dist/sb-floating-panel.es.js +269 -218
- package/dist/sb-floating-panel.umd.js +1 -1
- package/dist/types.d.ts +169 -0
- package/package.json +32 -34
- package/dist/sb-floating-panel-vue.css +0 -1
|
@@ -1,219 +1,270 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
n && a.hasResize && t && (await N(), g());
|
|
47
|
-
}), S(e, (n) => {
|
|
48
|
-
n && a.hasResize && !t && (t = !0, s.value = new ResizeObserver(g), s.value.observe(n));
|
|
49
|
-
}), E(() => {
|
|
50
|
-
a.hasResize && e.value && (t = !0, s.value = new ResizeObserver(g), s.value.observe(e.value));
|
|
51
|
-
}), K(() => {
|
|
52
|
-
var n;
|
|
53
|
-
a.hasResize && ((n = s.value) == null || n.disconnect());
|
|
54
|
-
}), {
|
|
55
|
-
reference: e,
|
|
56
|
-
floating: l,
|
|
57
|
-
floatingArrow: r,
|
|
58
|
-
floatingPlacement: i,
|
|
59
|
-
floatingStyle: O,
|
|
60
|
-
floatingArrowStyle: P,
|
|
61
|
-
isOpen: o,
|
|
62
|
-
toggle: h,
|
|
63
|
-
open: b,
|
|
64
|
-
close: y
|
|
65
|
-
};
|
|
1
|
+
import { Teleport as e, Transition as t, computed as n, createBlock as r, createCommentVNode as i, createElementBlock as a, createVNode as o, defineComponent as s, inject as c, mergeModels as l, mergeProps as u, nextTick as d, normalizeStyle as f, onScopeDispose as p, openBlock as m, provide as h, ref as g, renderSlot as _, resolveDynamicComponent as v, toRef as y, toValue as b, unref as x, useId as S, useModel as C, watch as w, withCtx as T } from "vue";
|
|
2
|
+
import { autoUpdate as E, flip as D, hide as O, limitShift as k, offset as A, shift as j, size as M, useFloating as N } from "@floating-ui/vue";
|
|
3
|
+
//#region src/composables/useSbFloatingPanel.ts
|
|
4
|
+
var P = (e) => `${Math.max(0, e)}px`;
|
|
5
|
+
function F(e) {
|
|
6
|
+
let t = g(null), r = g(null), i = n(() => {
|
|
7
|
+
let t = b(e.padding), n = b(e.matchWidth), r = b(e.placement).includes("-"), i = D({
|
|
8
|
+
padding: t,
|
|
9
|
+
crossAxis: "alignment",
|
|
10
|
+
fallbackAxisSideDirection: "end"
|
|
11
|
+
}), a = j({
|
|
12
|
+
padding: t,
|
|
13
|
+
limiter: k()
|
|
14
|
+
}), o = [
|
|
15
|
+
A(b(e.offset)),
|
|
16
|
+
...r ? [i, a] : [a, i],
|
|
17
|
+
M({
|
|
18
|
+
padding: t,
|
|
19
|
+
apply({ rects: e, elements: t, availableWidth: r, availableHeight: i }) {
|
|
20
|
+
let { style: a } = t.floating, o = P(e.reference.width);
|
|
21
|
+
a.setProperty("--sbf-reference-width", o), a.setProperty("--sbf-available-width", P(r)), a.setProperty("--sbf-available-height", P(i)), a.width = n === !0 ? o : "", a.minWidth = n === "min" ? o : "";
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
];
|
|
25
|
+
return b(e.hideWhenDetached) && o.push(O({ padding: t })), o;
|
|
26
|
+
}), { floatingStyles: a, middlewareData: o, placement: s, isPositioned: c, update: l } = N(t, r, {
|
|
27
|
+
open: () => b(e.isOpen),
|
|
28
|
+
placement: () => b(e.placement),
|
|
29
|
+
strategy: () => b(e.strategy),
|
|
30
|
+
middleware: i,
|
|
31
|
+
whileElementsMounted: E
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
reference: t,
|
|
35
|
+
floating: r,
|
|
36
|
+
floatingStyles: n(() => ({
|
|
37
|
+
...a.value,
|
|
38
|
+
...o.value.hide?.referenceHidden ? { visibility: "hidden" } : {}
|
|
39
|
+
})),
|
|
40
|
+
placement: s,
|
|
41
|
+
side: n(() => s.value.split("-")[0]),
|
|
42
|
+
align: n(() => s.value.split("-")[1]),
|
|
43
|
+
isPositioned: c,
|
|
44
|
+
update: l
|
|
45
|
+
};
|
|
66
46
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/context.ts
|
|
49
|
+
var I = Symbol("SbFloatingContext");
|
|
50
|
+
function L(e) {
|
|
51
|
+
let t = c(I, null);
|
|
52
|
+
if (!t) throw Error(`[sb-floating-panel-vue] <${e}> must be used inside <SbContainer>.`);
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/components/SbContainer.vue?vue&type=script&setup=true&lang.ts
|
|
57
|
+
var R = /* @__PURE__ */ new WeakSet(), z = /* @__PURE__ */ s({
|
|
58
|
+
inheritAttrs: !1,
|
|
59
|
+
__name: "SbContainer",
|
|
60
|
+
props: /*@__PURE__*/ l({
|
|
61
|
+
placement: { default: "bottom-start" },
|
|
62
|
+
strategy: { default: "absolute" },
|
|
63
|
+
offset: { default: 8 },
|
|
64
|
+
padding: { default: 8 },
|
|
65
|
+
matchWidth: {
|
|
66
|
+
type: [Boolean, String],
|
|
67
|
+
default: !1
|
|
68
|
+
},
|
|
69
|
+
hideWhenDetached: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
default: !1
|
|
72
|
+
},
|
|
73
|
+
defaultOpen: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: !1
|
|
76
|
+
},
|
|
77
|
+
disabled: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: !1
|
|
80
|
+
},
|
|
81
|
+
trigger: { default: "click" },
|
|
82
|
+
closeOnEscape: {
|
|
83
|
+
type: Boolean,
|
|
84
|
+
default: !0
|
|
85
|
+
},
|
|
86
|
+
closeOnClickOutside: {
|
|
87
|
+
type: Boolean,
|
|
88
|
+
default: !0
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
open: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: void 0
|
|
94
|
+
},
|
|
95
|
+
openModifiers: {}
|
|
96
|
+
}),
|
|
97
|
+
emits: /*@__PURE__*/ l(["open", "close"], ["update:open"]),
|
|
98
|
+
setup(e, { expose: t, emit: r }) {
|
|
99
|
+
let i = e, a = C(e, "open"), o = r, s = n(() => !i.disabled && (a.value ?? i.defaultOpen)), l = (e) => {
|
|
100
|
+
e && i.disabled || e !== s.value && (a.value = e);
|
|
101
|
+
}, u = () => l(!0), d = () => l(!1), f = () => l(!s.value), m = F({
|
|
102
|
+
isOpen: s,
|
|
103
|
+
placement: () => i.placement,
|
|
104
|
+
strategy: () => i.strategy,
|
|
105
|
+
offset: () => i.offset,
|
|
106
|
+
padding: () => i.padding,
|
|
107
|
+
matchWidth: () => i.matchWidth,
|
|
108
|
+
hideWhenDetached: () => i.hideWhenDetached
|
|
109
|
+
}), g = /* @__PURE__ */ new Set(), v = {
|
|
110
|
+
...m,
|
|
111
|
+
isOpen: s,
|
|
112
|
+
disabled: y(i, "disabled"),
|
|
113
|
+
trigger: y(i, "trigger"),
|
|
114
|
+
floatingId: `${S()}-floating`,
|
|
115
|
+
open: u,
|
|
116
|
+
close: d,
|
|
117
|
+
toggle: f,
|
|
118
|
+
contains: (e) => e instanceof Node ? m.reference.value?.contains(e) || m.floating.value?.contains(e) ? !0 : [...g].some((t) => t.contains(e)) : !1,
|
|
119
|
+
hasOpenChild: () => [...g].some((e) => e.isOpen.value || e.hasOpenChild()),
|
|
120
|
+
registerChild: (e) => (g.add(e), () => g.delete(e))
|
|
121
|
+
}, b = c(I, null);
|
|
122
|
+
b && p(b.registerChild(v)), h(I, v);
|
|
123
|
+
let T = (e) => {
|
|
124
|
+
e.key === "Escape" && i.closeOnEscape && !v.hasOpenChild() && (R.has(e) || (R.add(e), d()));
|
|
125
|
+
}, E = (e) => {
|
|
126
|
+
i.closeOnClickOutside && (v.contains(e.composedPath()[0] ?? e.target) || d());
|
|
127
|
+
};
|
|
128
|
+
return w(s, (e, t, n) => {
|
|
129
|
+
e && typeof document < "u" && (document.addEventListener("keydown", T), document.addEventListener("pointerdown", E, !0), n(() => {
|
|
130
|
+
document.removeEventListener("keydown", T), document.removeEventListener("pointerdown", E, !0);
|
|
131
|
+
}));
|
|
132
|
+
}, { immediate: !0 }), w(s, (e) => o(e ? "open" : "close")), w(() => i.disabled, (e) => {
|
|
133
|
+
e && a.value && (a.value = !1);
|
|
134
|
+
}), t({
|
|
135
|
+
open: u,
|
|
136
|
+
close: d,
|
|
137
|
+
toggle: f,
|
|
138
|
+
update: m.update
|
|
139
|
+
}), (e, t) => _(e.$slots, "default", {
|
|
140
|
+
isOpen: s.value,
|
|
141
|
+
open: u,
|
|
142
|
+
close: d,
|
|
143
|
+
toggle: f,
|
|
144
|
+
placement: x(m).placement.value,
|
|
145
|
+
side: x(m).side.value
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}), B = /* @__PURE__ */ s({
|
|
149
|
+
__name: "SbReference",
|
|
150
|
+
props: {
|
|
151
|
+
as: { default: "button" },
|
|
152
|
+
ariaHaspopup: { default: "dialog" }
|
|
153
|
+
},
|
|
154
|
+
setup(e) {
|
|
155
|
+
let t = e, i = L("SbReference"), { isOpen: a, disabled: o, floatingId: s } = i, c = n(() => t.as === "button" || t.as === "a"), l = (e) => {
|
|
156
|
+
i.reference.value = e instanceof HTMLElement ? e : null;
|
|
157
|
+
}, u = () => {
|
|
158
|
+
i.trigger.value === "click" && i.toggle();
|
|
159
|
+
}, d = (e) => {
|
|
160
|
+
c.value || e.key !== "Enter" && e.key !== " " || (e.preventDefault(), u());
|
|
161
|
+
};
|
|
162
|
+
return (e, n) => (m(), r(v(t.as), {
|
|
163
|
+
ref: l,
|
|
164
|
+
type: t.as === "button" ? "button" : void 0,
|
|
165
|
+
role: c.value ? void 0 : "button",
|
|
166
|
+
tabindex: c.value ? void 0 : x(o) ? -1 : 0,
|
|
167
|
+
disabled: t.as === "button" && x(o) ? !0 : void 0,
|
|
168
|
+
"aria-disabled": !c.value && x(o) ? "true" : void 0,
|
|
169
|
+
"aria-haspopup": t.ariaHaspopup,
|
|
170
|
+
"aria-expanded": x(a) ? "true" : "false",
|
|
171
|
+
"aria-controls": x(a) ? x(s) : void 0,
|
|
172
|
+
"data-sbf-state": x(a) ? "open" : "closed",
|
|
173
|
+
onClick: u,
|
|
174
|
+
onKeydown: d
|
|
175
|
+
}, {
|
|
176
|
+
default: T(() => [_(e.$slots, "default")]),
|
|
177
|
+
_: 3
|
|
178
|
+
}, 40, [
|
|
179
|
+
"type",
|
|
180
|
+
"role",
|
|
181
|
+
"tabindex",
|
|
182
|
+
"disabled",
|
|
183
|
+
"aria-disabled",
|
|
184
|
+
"aria-haspopup",
|
|
185
|
+
"aria-expanded",
|
|
186
|
+
"aria-controls",
|
|
187
|
+
"data-sbf-state"
|
|
188
|
+
]));
|
|
189
|
+
}
|
|
190
|
+
}), V = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"]", H = /* @__PURE__ */ s({
|
|
191
|
+
inheritAttrs: !1,
|
|
192
|
+
__name: "SbFloating",
|
|
193
|
+
props: {
|
|
194
|
+
as: { default: "div" },
|
|
195
|
+
role: { default: "dialog" },
|
|
196
|
+
transition: { default: void 0 },
|
|
197
|
+
teleportTo: { default: "body" },
|
|
198
|
+
teleportDisabled: {
|
|
199
|
+
type: Boolean,
|
|
200
|
+
default: !1
|
|
201
|
+
},
|
|
202
|
+
zIndex: { default: void 0 },
|
|
203
|
+
autoFocus: {
|
|
204
|
+
type: Boolean,
|
|
205
|
+
default: !1
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
emits: ["after-enter", "after-leave"],
|
|
209
|
+
setup(s, { emit: c }) {
|
|
210
|
+
let l = s, p = c, h = L("SbFloating"), { isOpen: y, floatingId: b, side: S, align: C } = h, E = g(y.value), D = g(null), O = (e) => {
|
|
211
|
+
h.floating.value = e instanceof HTMLElement ? e : null;
|
|
212
|
+
}, k = (e) => {
|
|
213
|
+
D.value = e instanceof HTMLElement ? e : null;
|
|
214
|
+
}, A = n(() => ({
|
|
215
|
+
...h.floatingStyles.value,
|
|
216
|
+
...l.zIndex === void 0 ? {} : { zIndex: l.zIndex }
|
|
217
|
+
})), j = () => p("after-enter"), M = () => {
|
|
218
|
+
y.value || (E.value = !1), p("after-leave");
|
|
219
|
+
}, N = () => {
|
|
220
|
+
let e = D.value;
|
|
221
|
+
e && (e.querySelector("[autofocus]") ?? e.querySelector(V) ?? e).focus({ preventScroll: !0 });
|
|
222
|
+
};
|
|
223
|
+
return w(y, (e) => {
|
|
224
|
+
if (e) {
|
|
225
|
+
E.value = !0;
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
let t = document.activeElement;
|
|
229
|
+
t && h.floating.value?.contains(t) && h.reference.value?.focus();
|
|
230
|
+
}), w(() => y.value && h.isPositioned.value, async (e) => {
|
|
231
|
+
e && l.autoFocus && (await d(), N());
|
|
232
|
+
}), (n, s) => (m(), r(e, {
|
|
233
|
+
to: l.teleportTo,
|
|
234
|
+
disabled: l.teleportDisabled
|
|
235
|
+
}, [E.value ? (m(), a("div", {
|
|
236
|
+
key: 0,
|
|
237
|
+
ref: O,
|
|
238
|
+
style: f(A.value)
|
|
239
|
+
}, [o(t, {
|
|
240
|
+
name: l.transition,
|
|
241
|
+
css: !!l.transition,
|
|
242
|
+
appear: "",
|
|
243
|
+
onAfterEnter: j,
|
|
244
|
+
onAfterLeave: M
|
|
245
|
+
}, {
|
|
246
|
+
default: T(() => [x(y) ? (m(), r(v(l.as), u({ key: 0 }, n.$attrs, {
|
|
247
|
+
id: x(b),
|
|
248
|
+
ref: k,
|
|
249
|
+
role: l.role,
|
|
250
|
+
tabindex: l.autoFocus ? -1 : void 0,
|
|
251
|
+
"data-sbf-state": x(y) ? "open" : "closed",
|
|
252
|
+
"data-sbf-side": x(S),
|
|
253
|
+
"data-sbf-align": x(C)
|
|
254
|
+
}), {
|
|
255
|
+
default: T(() => [_(n.$slots, "default")]),
|
|
256
|
+
_: 3
|
|
257
|
+
}, 16, [
|
|
258
|
+
"id",
|
|
259
|
+
"role",
|
|
260
|
+
"tabindex",
|
|
261
|
+
"data-sbf-state",
|
|
262
|
+
"data-sbf-side",
|
|
263
|
+
"data-sbf-align"
|
|
264
|
+
])) : i("", !0)]),
|
|
265
|
+
_: 3
|
|
266
|
+
}, 8, ["name", "css"])], 4)) : i("", !0)], 8, ["to", "disabled"]));
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
//#endregion
|
|
270
|
+
export { z as SbContainer, H as SbFloating, B as SbReference };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue"),require("@floating-ui/vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`,`@floating-ui/vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SbFloatingPanelVue={},e.Vue,e.FloatingUIVue))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=e=>`${Math.max(0,e)}px`;function i(e){let i=(0,t.ref)(null),a=(0,t.ref)(null),o=(0,t.computed)(()=>{let i=(0,t.toValue)(e.padding),a=(0,t.toValue)(e.matchWidth),o=(0,t.toValue)(e.placement).includes(`-`),s=(0,n.flip)({padding:i,crossAxis:`alignment`,fallbackAxisSideDirection:`end`}),c=(0,n.shift)({padding:i,limiter:(0,n.limitShift)()}),l=[(0,n.offset)((0,t.toValue)(e.offset)),...o?[s,c]:[c,s],(0,n.size)({padding:i,apply({rects:e,elements:t,availableWidth:n,availableHeight:i}){let{style:o}=t.floating,s=r(e.reference.width);o.setProperty(`--sbf-reference-width`,s),o.setProperty(`--sbf-available-width`,r(n)),o.setProperty(`--sbf-available-height`,r(i)),o.width=a===!0?s:``,o.minWidth=a===`min`?s:``}})];return(0,t.toValue)(e.hideWhenDetached)&&l.push((0,n.hide)({padding:i})),l}),{floatingStyles:s,middlewareData:c,placement:l,isPositioned:u,update:d}=(0,n.useFloating)(i,a,{open:()=>(0,t.toValue)(e.isOpen),placement:()=>(0,t.toValue)(e.placement),strategy:()=>(0,t.toValue)(e.strategy),middleware:o,whileElementsMounted:n.autoUpdate});return{reference:i,floating:a,floatingStyles:(0,t.computed)(()=>({...s.value,...c.value.hide?.referenceHidden?{visibility:`hidden`}:{}})),placement:l,side:(0,t.computed)(()=>l.value.split(`-`)[0]),align:(0,t.computed)(()=>l.value.split(`-`)[1]),isPositioned:u,update:d}}var a=Symbol(`SbFloatingContext`);function o(e){let n=(0,t.inject)(a,null);if(!n)throw Error(`[sb-floating-panel-vue] <${e}> must be used inside <SbContainer>.`);return n}var s=new WeakSet,c=(0,t.defineComponent)({inheritAttrs:!1,__name:`SbContainer`,props:(0,t.mergeModels)({placement:{default:`bottom-start`},strategy:{default:`absolute`},offset:{default:8},padding:{default:8},matchWidth:{type:[Boolean,String],default:!1},hideWhenDetached:{type:Boolean,default:!1},defaultOpen:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},trigger:{default:`click`},closeOnEscape:{type:Boolean,default:!0},closeOnClickOutside:{type:Boolean,default:!0}},{open:{type:Boolean,default:void 0},openModifiers:{}}),emits:(0,t.mergeModels)([`open`,`close`],[`update:open`]),setup(e,{expose:n,emit:r}){let o=e,c=(0,t.useModel)(e,`open`),l=r,u=(0,t.computed)(()=>!o.disabled&&(c.value??o.defaultOpen)),d=e=>{e&&o.disabled||e!==u.value&&(c.value=e)},f=()=>d(!0),p=()=>d(!1),m=()=>d(!u.value),h=i({isOpen:u,placement:()=>o.placement,strategy:()=>o.strategy,offset:()=>o.offset,padding:()=>o.padding,matchWidth:()=>o.matchWidth,hideWhenDetached:()=>o.hideWhenDetached}),g=new Set,_={...h,isOpen:u,disabled:(0,t.toRef)(o,`disabled`),trigger:(0,t.toRef)(o,`trigger`),floatingId:`${(0,t.useId)()}-floating`,open:f,close:p,toggle:m,contains:e=>e instanceof Node?h.reference.value?.contains(e)||h.floating.value?.contains(e)?!0:[...g].some(t=>t.contains(e)):!1,hasOpenChild:()=>[...g].some(e=>e.isOpen.value||e.hasOpenChild()),registerChild:e=>(g.add(e),()=>g.delete(e))},v=(0,t.inject)(a,null);v&&(0,t.onScopeDispose)(v.registerChild(_)),(0,t.provide)(a,_);let y=e=>{e.key===`Escape`&&o.closeOnEscape&&!_.hasOpenChild()&&(s.has(e)||(s.add(e),p()))},b=e=>{o.closeOnClickOutside&&(_.contains(e.composedPath()[0]??e.target)||p())};return(0,t.watch)(u,(e,t,n)=>{e&&typeof document<`u`&&(document.addEventListener(`keydown`,y),document.addEventListener(`pointerdown`,b,!0),n(()=>{document.removeEventListener(`keydown`,y),document.removeEventListener(`pointerdown`,b,!0)}))},{immediate:!0}),(0,t.watch)(u,e=>l(e?`open`:`close`)),(0,t.watch)(()=>o.disabled,e=>{e&&c.value&&(c.value=!1)}),n({open:f,close:p,toggle:m,update:h.update}),(e,n)=>(0,t.renderSlot)(e.$slots,`default`,{isOpen:u.value,open:f,close:p,toggle:m,placement:(0,t.unref)(h).placement.value,side:(0,t.unref)(h).side.value})}}),l=(0,t.defineComponent)({__name:`SbReference`,props:{as:{default:`button`},ariaHaspopup:{default:`dialog`}},setup(e){let n=e,r=o(`SbReference`),{isOpen:i,disabled:a,floatingId:s}=r,c=(0,t.computed)(()=>n.as===`button`||n.as===`a`),l=e=>{r.reference.value=e instanceof HTMLElement?e:null},u=()=>{r.trigger.value===`click`&&r.toggle()},d=e=>{c.value||e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),u())};return(e,r)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(n.as),{ref:l,type:n.as===`button`?`button`:void 0,role:c.value?void 0:`button`,tabindex:c.value?void 0:(0,t.unref)(a)?-1:0,disabled:n.as===`button`&&(0,t.unref)(a)?!0:void 0,"aria-disabled":!c.value&&(0,t.unref)(a)?`true`:void 0,"aria-haspopup":n.ariaHaspopup,"aria-expanded":(0,t.unref)(i)?`true`:`false`,"aria-controls":(0,t.unref)(i)?(0,t.unref)(s):void 0,"data-sbf-state":(0,t.unref)(i)?`open`:`closed`,onClick:u,onKeydown:d},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},40,[`type`,`role`,`tabindex`,`disabled`,`aria-disabled`,`aria-haspopup`,`aria-expanded`,`aria-controls`,`data-sbf-state`]))}}),u=`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]`,d=(0,t.defineComponent)({inheritAttrs:!1,__name:`SbFloating`,props:{as:{default:`div`},role:{default:`dialog`},transition:{default:void 0},teleportTo:{default:`body`},teleportDisabled:{type:Boolean,default:!1},zIndex:{default:void 0},autoFocus:{type:Boolean,default:!1}},emits:[`after-enter`,`after-leave`],setup(e,{emit:n}){let r=e,i=n,a=o(`SbFloating`),{isOpen:s,floatingId:c,side:l,align:d}=a,f=(0,t.ref)(s.value),p=(0,t.ref)(null),m=e=>{a.floating.value=e instanceof HTMLElement?e:null},h=e=>{p.value=e instanceof HTMLElement?e:null},g=(0,t.computed)(()=>({...a.floatingStyles.value,...r.zIndex===void 0?{}:{zIndex:r.zIndex}})),_=()=>i(`after-enter`),v=()=>{s.value||(f.value=!1),i(`after-leave`)},y=()=>{let e=p.value;e&&(e.querySelector(`[autofocus]`)??e.querySelector(u)??e).focus({preventScroll:!0})};return(0,t.watch)(s,e=>{if(e){f.value=!0;return}let t=document.activeElement;t&&a.floating.value?.contains(t)&&a.reference.value?.focus()}),(0,t.watch)(()=>s.value&&a.isPositioned.value,async e=>{e&&r.autoFocus&&(await(0,t.nextTick)(),y())}),(e,n)=>((0,t.openBlock)(),(0,t.createBlock)(t.Teleport,{to:r.teleportTo,disabled:r.teleportDisabled},[f.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:0,ref:m,style:(0,t.normalizeStyle)(g.value)},[(0,t.createVNode)(t.Transition,{name:r.transition,css:!!r.transition,appear:``,onAfterEnter:_,onAfterLeave:v},{default:(0,t.withCtx)(()=>[(0,t.unref)(s)?((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(r.as),(0,t.mergeProps)({key:0},e.$attrs,{id:(0,t.unref)(c),ref:h,role:r.role,tabindex:r.autoFocus?-1:void 0,"data-sbf-state":(0,t.unref)(s)?`open`:`closed`,"data-sbf-side":(0,t.unref)(l),"data-sbf-align":(0,t.unref)(d)}),{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},16,[`id`,`role`,`tabindex`,`data-sbf-state`,`data-sbf-side`,`data-sbf-align`])):(0,t.createCommentVNode)(``,!0)]),_:3},8,[`name`,`css`])],4)):(0,t.createCommentVNode)(``,!0)],8,[`to`,`disabled`]))}});e.SbContainer=c,e.SbFloating=d,e.SbReference=l});
|