sb-floating-panel-vue 1.0.0 → 4.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 +305 -128
- package/dist/components/SbContainer.vue.d.ts +31 -61
- package/dist/components/SbFloating.vue.d.ts +22 -69
- package/dist/components/SbReference.vue.d.ts +11 -34
- package/dist/composables/useSbFloatingPanel.d.ts +26 -76
- package/dist/context.d.ts +32 -0
- package/dist/focus.d.ts +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/sb-floating-panel.es.js +375 -218
- package/dist/sb-floating-panel.umd.js +1 -1
- package/dist/types.d.ts +200 -0
- package/package.json +32 -34
- package/dist/sb-floating-panel-vue.css +0 -1
|
@@ -1,219 +1,376 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
open: o,
|
|
8
|
-
placement: a.placement,
|
|
9
|
-
strategy: a.strategy,
|
|
10
|
-
transform: !1,
|
|
11
|
-
middleware: [M(a.offsetValue), T(), W(), D({ element: r })],
|
|
12
|
-
whileElementsMounted: B
|
|
13
|
-
}), d = (n) => {
|
|
14
|
-
o.value = n;
|
|
15
|
-
}, b = () => d(!0), y = () => d(!1), h = () => d(!o.value), g = () => {
|
|
16
|
-
l.value && e.value && (l.value.style.width = `${e.value.offsetWidth}px`);
|
|
17
|
-
}, O = u(() => ({
|
|
18
|
-
...f.value
|
|
19
|
-
})), P = u(() => {
|
|
20
|
-
const n = m.value.arrow, F = i.value.split("-")[0], p = {
|
|
21
|
-
position: "absolute",
|
|
22
|
-
transform: "rotate(45deg)",
|
|
23
|
-
background: "inherit",
|
|
24
|
-
width: "8px",
|
|
25
|
-
height: "8px",
|
|
26
|
-
left: (n == null ? void 0 : n.x) != null ? `${n.x}px` : "",
|
|
27
|
-
top: (n == null ? void 0 : n.y) != null ? `${n.y}px` : ""
|
|
28
|
-
};
|
|
29
|
-
switch (F) {
|
|
30
|
-
case "top":
|
|
31
|
-
p.bottom = "-4px";
|
|
32
|
-
break;
|
|
33
|
-
case "bottom":
|
|
34
|
-
p.top = "-4px";
|
|
35
|
-
break;
|
|
36
|
-
case "left":
|
|
37
|
-
p.right = "-4px";
|
|
38
|
-
break;
|
|
39
|
-
case "right":
|
|
40
|
-
p.left = "-4px";
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
return p;
|
|
44
|
-
});
|
|
45
|
-
return S(o, async (n) => {
|
|
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
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const Z = { class: "floating-container" }, ee = /* @__PURE__ */ k({
|
|
68
|
-
__name: "SbContainer",
|
|
69
|
-
props: {
|
|
70
|
-
placement: { default: "bottom-start" },
|
|
71
|
-
strategy: { default: "absolute" },
|
|
72
|
-
offsetValue: { default: 15 },
|
|
73
|
-
hasArrow: { type: Boolean, default: !1 },
|
|
74
|
-
hasResize: { type: Boolean, default: !1 }
|
|
75
|
-
},
|
|
76
|
-
setup(a) {
|
|
77
|
-
const e = a, {
|
|
78
|
-
isOpen: l,
|
|
79
|
-
reference: r,
|
|
80
|
-
floating: o,
|
|
81
|
-
floatingArrow: s,
|
|
82
|
-
floatingPlacement: t,
|
|
83
|
-
floatingStyle: f,
|
|
84
|
-
floatingArrowStyle: i,
|
|
85
|
-
toggle: m,
|
|
86
|
-
open: d,
|
|
87
|
-
close: b
|
|
88
|
-
} = Y({
|
|
89
|
-
placement: e.placement,
|
|
90
|
-
strategy: e.strategy,
|
|
91
|
-
offsetValue: e.offsetValue,
|
|
92
|
-
hasArrow: e.hasArrow,
|
|
93
|
-
hasResize: e.hasResize
|
|
94
|
-
}), y = {
|
|
95
|
-
reference: r,
|
|
96
|
-
floating: o,
|
|
97
|
-
floatingArrow: s,
|
|
98
|
-
floatingPlacement: t,
|
|
99
|
-
floatingStyle: f,
|
|
100
|
-
floatingArrowStyle: i,
|
|
101
|
-
isOpen: l,
|
|
102
|
-
toggle: m,
|
|
103
|
-
open: d,
|
|
104
|
-
close: b
|
|
105
|
-
};
|
|
106
|
-
return (h, g) => (v(), x("div", Z, [
|
|
107
|
-
z(h.$slots, "default", U(j(y)), void 0, !0)
|
|
108
|
-
]));
|
|
109
|
-
}
|
|
110
|
-
}), I = (a, e) => {
|
|
111
|
-
const l = a.__vccOpts || a;
|
|
112
|
-
for (const [r, o] of e)
|
|
113
|
-
l[r] = o;
|
|
114
|
-
return l;
|
|
115
|
-
}, ae = /* @__PURE__ */ I(ee, [["__scopeId", "data-v-33e40585"]]), le = /* @__PURE__ */ k({
|
|
116
|
-
__name: "SbReference",
|
|
117
|
-
props: {
|
|
118
|
-
referenceRef: {},
|
|
119
|
-
as: { default: "button" },
|
|
120
|
-
onClick: { type: Function, default: void 0 }
|
|
121
|
-
},
|
|
122
|
-
setup(a) {
|
|
123
|
-
const e = a, l = u(() => e.as === "button" || e.as === "a");
|
|
124
|
-
return (r, o) => (v(), A(q(e.as), $(r.$attrs, {
|
|
125
|
-
ref: e.referenceRef,
|
|
126
|
-
role: l.value ? "button" : void 0,
|
|
127
|
-
tabindex: l.value ? 0 : void 0,
|
|
128
|
-
onClick: o[0] || (o[0] = w((s) => {
|
|
129
|
-
var t;
|
|
130
|
-
return (t = e.onClick) == null ? void 0 : t.call(e);
|
|
131
|
-
}, ["stop"])),
|
|
132
|
-
onKeydown: [
|
|
133
|
-
o[1] || (o[1] = _(w((s) => {
|
|
134
|
-
var t;
|
|
135
|
-
return l.value && ((t = e.onClick) == null ? void 0 : t.call(e));
|
|
136
|
-
}, ["prevent", "stop"]), ["space"])),
|
|
137
|
-
o[2] || (o[2] = _(w((s) => {
|
|
138
|
-
var t;
|
|
139
|
-
return l.value && ((t = e.onClick) == null ? void 0 : t.call(e));
|
|
140
|
-
}, ["prevent", "stop"]), ["enter"]))
|
|
141
|
-
]
|
|
142
|
-
}), {
|
|
143
|
-
default: C(() => [
|
|
144
|
-
z(r.$slots, "default")
|
|
145
|
-
]),
|
|
146
|
-
_: 3
|
|
147
|
-
}, 16, ["role", "tabindex"]));
|
|
148
|
-
}
|
|
149
|
-
}), te = /* @__PURE__ */ k({
|
|
150
|
-
inheritAttrs: !1,
|
|
151
|
-
__name: "SbFloating",
|
|
152
|
-
props: {
|
|
153
|
-
floatingRef: {},
|
|
154
|
-
floatingArrowRef: { default: () => c(null) },
|
|
155
|
-
isOpen: { type: Boolean },
|
|
156
|
-
floatingPlacement: {},
|
|
157
|
-
floatingStyle: {},
|
|
158
|
-
floatingArrowStyle: { default: void 0 },
|
|
159
|
-
arrowDimensions: { default: void 0 },
|
|
160
|
-
zIndex: { default: void 0 },
|
|
161
|
-
animation: { default: "scale-fade" },
|
|
162
|
-
duration: { default: 300 }
|
|
163
|
-
},
|
|
164
|
-
setup(a) {
|
|
165
|
-
const e = a, l = G(), r = u(() => {
|
|
166
|
-
const t = {
|
|
167
|
-
...e.floatingStyle,
|
|
168
|
-
"--sb-transition-duration": e.duration + "ms"
|
|
169
|
-
};
|
|
170
|
-
return e.zIndex !== void 0 && (t.zIndex = e.zIndex), t;
|
|
171
|
-
}), o = u(() => {
|
|
172
|
-
const t = { ...e.floatingArrowStyle || {} };
|
|
173
|
-
if (e.arrowDimensions) {
|
|
174
|
-
const f = e.arrowDimensions, i = `-${f / 2}px`;
|
|
175
|
-
switch (e.floatingPlacement.split("-")[0]) {
|
|
176
|
-
case "top":
|
|
177
|
-
t.bottom = i;
|
|
178
|
-
break;
|
|
179
|
-
case "bottom":
|
|
180
|
-
t.top = i;
|
|
181
|
-
break;
|
|
182
|
-
case "left":
|
|
183
|
-
t.right = i;
|
|
184
|
-
break;
|
|
185
|
-
case "right":
|
|
186
|
-
t.left = i;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
t.width = `${f}px`, t.height = `${f}px`;
|
|
190
|
-
}
|
|
191
|
-
return e.zIndex !== void 0 && (t.zIndex = e.zIndex), t;
|
|
192
|
-
}), s = u(() => e.animation === "fade" ? "fade" : e.animation === "scale-fade" ? "scale-fade" : "");
|
|
193
|
-
return (t, f) => (v(), A(H, { to: "body" }, [
|
|
194
|
-
J(L, { name: s.value }, {
|
|
195
|
-
default: C(() => [
|
|
196
|
-
e.isOpen ? (v(), x("div", $({
|
|
197
|
-
key: 0,
|
|
198
|
-
ref: e.floatingRef,
|
|
199
|
-
style: r.value
|
|
200
|
-
}, Q(l)), [
|
|
201
|
-
z(t.$slots, "default", {}, void 0, !0),
|
|
202
|
-
e.floatingArrowRef ? (v(), x("div", {
|
|
203
|
-
key: 0,
|
|
204
|
-
ref: e.floatingArrowRef,
|
|
205
|
-
style: X(o.value)
|
|
206
|
-
}, null, 4)) : R("", !0)
|
|
207
|
-
], 16)) : R("", !0)
|
|
208
|
-
]),
|
|
209
|
-
_: 3
|
|
210
|
-
}, 8, ["name"])
|
|
211
|
-
]));
|
|
212
|
-
}
|
|
213
|
-
}), se = /* @__PURE__ */ I(te, [["__scopeId", "data-v-366682ad"]]);
|
|
214
|
-
export {
|
|
215
|
-
ae as SbContainer,
|
|
216
|
-
se as SbFloating,
|
|
217
|
-
le as SbReference,
|
|
218
|
-
Y as useSbFloatingPanel
|
|
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, onBeforeUnmount as p, onScopeDispose as m, openBlock as h, provide as g, ref as _, renderSlot as v, resolveDynamicComponent as y, toRef as b, toValue as x, unref as S, useAttrs as C, useId as w, useModel as T, watch as E, watchEffect as D, withCtx as O } from "vue";
|
|
2
|
+
import { autoUpdate as k, flip as A, hide as j, limitShift as M, offset as N, shift as P, size as F, useFloating as I } from "@floating-ui/vue";
|
|
3
|
+
//#region src/composables/useSbFloatingPanel.ts
|
|
4
|
+
var L = (e) => `${Math.max(0, e)}px`, R = (e) => {
|
|
5
|
+
let [t, n] = e.split("-"), r = n === "start" ? "0%" : n === "end" ? "100%" : "50%";
|
|
6
|
+
return t === "top" ? `${r} 100%` : t === "bottom" ? `${r} 0%` : t === "left" ? `100% ${r}` : `0% ${r}`;
|
|
219
7
|
};
|
|
8
|
+
function z(e) {
|
|
9
|
+
let t = _(null), r = _(null), i = n(() => {
|
|
10
|
+
let t = x(e.padding), n = x(e.matchWidth), r = x(e.placement).includes("-"), i = A({
|
|
11
|
+
padding: t,
|
|
12
|
+
crossAxis: "alignment",
|
|
13
|
+
fallbackAxisSideDirection: "end"
|
|
14
|
+
}), a = P({
|
|
15
|
+
padding: t,
|
|
16
|
+
limiter: M()
|
|
17
|
+
}), o = [
|
|
18
|
+
N(x(e.offset)),
|
|
19
|
+
...r ? [i, a] : [a, i],
|
|
20
|
+
F({
|
|
21
|
+
padding: t,
|
|
22
|
+
apply({ rects: e, elements: t, availableWidth: r, availableHeight: i, placement: a }) {
|
|
23
|
+
let { style: o } = t.floating, s = L(e.reference.width);
|
|
24
|
+
o.setProperty("--sbf-reference-width", s), o.setProperty("--sbf-transform-origin", R(a)), o.setProperty("--sbf-available-width", L(r)), o.setProperty("--sbf-available-height", L(i)), o.width = n === !0 ? s : "", o.minWidth = n === "min" ? s : "";
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
];
|
|
28
|
+
return x(e.hideWhenDetached) && o.push(j({ padding: t })), o;
|
|
29
|
+
}), { floatingStyles: a, middlewareData: o, placement: s, isPositioned: c, update: l } = I(t, r, {
|
|
30
|
+
open: () => x(e.isOpen),
|
|
31
|
+
placement: () => x(e.placement),
|
|
32
|
+
strategy: () => x(e.strategy),
|
|
33
|
+
middleware: i,
|
|
34
|
+
whileElementsMounted: k
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
reference: t,
|
|
38
|
+
floating: r,
|
|
39
|
+
floatingStyles: n(() => ({
|
|
40
|
+
...a.value,
|
|
41
|
+
...o.value.hide?.referenceHidden ? { visibility: "hidden" } : {}
|
|
42
|
+
})),
|
|
43
|
+
placement: s,
|
|
44
|
+
side: n(() => s.value.split("-")[0]),
|
|
45
|
+
align: n(() => s.value.split("-")[1]),
|
|
46
|
+
isPositioned: c,
|
|
47
|
+
update: l
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/context.ts
|
|
52
|
+
var B = {
|
|
53
|
+
dialog: "dialog",
|
|
54
|
+
alertdialog: "dialog",
|
|
55
|
+
menu: "menu",
|
|
56
|
+
listbox: "listbox",
|
|
57
|
+
tree: "tree",
|
|
58
|
+
grid: "grid"
|
|
59
|
+
}, V = Symbol("SbFloatingContext");
|
|
60
|
+
function H(e) {
|
|
61
|
+
let t = c(V, null);
|
|
62
|
+
if (!t) throw Error(`[sb-floating-panel-vue] <${e}> must be used inside <SbContainer>.`);
|
|
63
|
+
return t;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/focus.ts
|
|
67
|
+
var U = "data-sbf-focus-guard", W = [
|
|
68
|
+
"a[href]",
|
|
69
|
+
"button:not([disabled])",
|
|
70
|
+
"input:not([disabled]):not([type=\"hidden\"])",
|
|
71
|
+
"select:not([disabled])",
|
|
72
|
+
"textarea:not([disabled])",
|
|
73
|
+
"summary",
|
|
74
|
+
"audio[controls]",
|
|
75
|
+
"video[controls]",
|
|
76
|
+
"[tabindex]",
|
|
77
|
+
"[contenteditable=\"true\"]"
|
|
78
|
+
].join(","), G = (e) => e.tabIndex >= 0 && !e.hasAttribute("data-sbf-focus-guard") && !e.closest("[inert]") && (e.checkVisibility?.() ?? !0);
|
|
79
|
+
function K(e) {
|
|
80
|
+
let t = e instanceof Element ? e.closest(W) : null;
|
|
81
|
+
return !!t && !t.closest("[inert]");
|
|
82
|
+
}
|
|
83
|
+
function q(e) {
|
|
84
|
+
return [...e.querySelectorAll(W)].filter(G);
|
|
85
|
+
}
|
|
86
|
+
function J(e, t) {
|
|
87
|
+
return q(e.ownerDocument).find((n) => !!(e.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_FOLLOWING) && !e.contains(n) && !t(n));
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/components/SbContainer.vue?vue&type=script&setup=true&lang.ts
|
|
91
|
+
var Y = [], X = /* @__PURE__ */ s({
|
|
92
|
+
inheritAttrs: !1,
|
|
93
|
+
__name: "SbContainer",
|
|
94
|
+
props: /*@__PURE__*/ l({
|
|
95
|
+
placement: { default: "bottom-start" },
|
|
96
|
+
strategy: { default: "absolute" },
|
|
97
|
+
offset: { default: 8 },
|
|
98
|
+
padding: { default: 8 },
|
|
99
|
+
matchWidth: {
|
|
100
|
+
type: [Boolean, String],
|
|
101
|
+
default: !1
|
|
102
|
+
},
|
|
103
|
+
hideWhenDetached: {
|
|
104
|
+
type: Boolean,
|
|
105
|
+
default: !1
|
|
106
|
+
},
|
|
107
|
+
defaultOpen: {
|
|
108
|
+
type: Boolean,
|
|
109
|
+
default: !1
|
|
110
|
+
},
|
|
111
|
+
disabled: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: !1
|
|
114
|
+
},
|
|
115
|
+
trigger: { default: "click" },
|
|
116
|
+
closeOnEscape: {
|
|
117
|
+
type: Boolean,
|
|
118
|
+
default: !0
|
|
119
|
+
},
|
|
120
|
+
closeOnClickOutside: {
|
|
121
|
+
type: Boolean,
|
|
122
|
+
default: !0
|
|
123
|
+
},
|
|
124
|
+
closeOnFocusOut: {
|
|
125
|
+
type: Boolean,
|
|
126
|
+
default: !0
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
open: {
|
|
130
|
+
type: Boolean,
|
|
131
|
+
default: void 0
|
|
132
|
+
},
|
|
133
|
+
openModifiers: {}
|
|
134
|
+
}),
|
|
135
|
+
emits: /*@__PURE__*/ l(["open", "close"], ["update:open"]),
|
|
136
|
+
setup(e, { expose: t, emit: r }) {
|
|
137
|
+
let i = e, a = T(e, "open"), o = r, s = i.defaultOpen, l = n(() => !i.disabled && (a.value ?? s)), u = (e) => {
|
|
138
|
+
e && i.disabled || e !== l.value && (a.value = e);
|
|
139
|
+
}, d = () => u(!0), f = () => u(!1), p = () => u(!l.value), h = z({
|
|
140
|
+
isOpen: l,
|
|
141
|
+
placement: () => i.placement,
|
|
142
|
+
strategy: () => i.strategy,
|
|
143
|
+
offset: () => i.offset,
|
|
144
|
+
padding: () => i.padding,
|
|
145
|
+
matchWidth: () => i.matchWidth,
|
|
146
|
+
hideWhenDetached: () => i.hideWhenDetached
|
|
147
|
+
}), y = /* @__PURE__ */ new Set(), x = {
|
|
148
|
+
...h,
|
|
149
|
+
isOpen: l,
|
|
150
|
+
disabled: b(i, "disabled"),
|
|
151
|
+
trigger: b(i, "trigger"),
|
|
152
|
+
floatingId: `${w()}-floating`,
|
|
153
|
+
referenceId: _(),
|
|
154
|
+
floatingRole: _("dialog"),
|
|
155
|
+
skipFocusReturn: !1,
|
|
156
|
+
open: d,
|
|
157
|
+
close: f,
|
|
158
|
+
toggle: p,
|
|
159
|
+
contains: (e) => e instanceof Node ? h.reference.value?.contains(e) || h.floating.value?.contains(e) ? !0 : [...y].some((t) => t.contains(e)) : !1,
|
|
160
|
+
registerChild: (e) => (y.add(e), () => y.delete(e))
|
|
161
|
+
}, C = c(V, null);
|
|
162
|
+
C && m(C.registerChild(x)), g(V, x);
|
|
163
|
+
let D = (e) => {
|
|
164
|
+
e.key === "Escape" && Y[Y.length - 1] === x && (!i.closeOnEscape || e.defaultPrevented || e.isComposing || (e.preventDefault(), f()));
|
|
165
|
+
}, O = (e) => {
|
|
166
|
+
x.contains(e) || (x.skipFocusReturn = K(e), f());
|
|
167
|
+
}, k, A = (e) => {
|
|
168
|
+
if (k?.(), !i.closeOnClickOutside) return;
|
|
169
|
+
let t = e.composedPath()[0] ?? e.target;
|
|
170
|
+
if (e.pointerType !== "touch") {
|
|
171
|
+
O(t);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (x.contains(t)) return;
|
|
175
|
+
let n = (e) => {
|
|
176
|
+
k?.(), O(e.composedPath()[0] ?? e.target);
|
|
177
|
+
};
|
|
178
|
+
document.addEventListener("click", n, !0), k = () => {
|
|
179
|
+
document.removeEventListener("click", n, !0), k = void 0;
|
|
180
|
+
};
|
|
181
|
+
}, j = (e) => {
|
|
182
|
+
i.closeOnFocusOut && (x.contains(e.composedPath()[0] ?? e.target) || f());
|
|
183
|
+
};
|
|
184
|
+
return E(l, (e, t, n) => {
|
|
185
|
+
e && typeof document < "u" && (Y.push(x), document.addEventListener("keydown", D), document.addEventListener("pointerdown", A, !0), document.addEventListener("focusin", j), n(() => {
|
|
186
|
+
document.removeEventListener("keydown", D), document.removeEventListener("pointerdown", A, !0), document.removeEventListener("focusin", j), k?.(), Y.splice(Y.indexOf(x), 1);
|
|
187
|
+
}));
|
|
188
|
+
}, { immediate: !0 }), E(l, (e) => o(e ? "open" : "close")), E(() => i.disabled, (e) => {
|
|
189
|
+
e && (a.value ?? s) && (a.value = !1);
|
|
190
|
+
}), t({
|
|
191
|
+
open: d,
|
|
192
|
+
close: f,
|
|
193
|
+
toggle: p,
|
|
194
|
+
update: h.update
|
|
195
|
+
}), (e, t) => v(e.$slots, "default", {
|
|
196
|
+
isOpen: l.value,
|
|
197
|
+
open: d,
|
|
198
|
+
close: f,
|
|
199
|
+
toggle: p,
|
|
200
|
+
placement: S(h).placement.value,
|
|
201
|
+
side: S(h).side.value,
|
|
202
|
+
align: S(h).align.value
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}), Z = /* @__PURE__ */ s({
|
|
206
|
+
__name: "SbReference",
|
|
207
|
+
props: {
|
|
208
|
+
as: { default: "button" },
|
|
209
|
+
id: { default: void 0 },
|
|
210
|
+
ariaHaspopup: { default: void 0 }
|
|
211
|
+
},
|
|
212
|
+
setup(e) {
|
|
213
|
+
let t = e, i = C(), a = H("SbReference"), { isOpen: o, disabled: s, floatingId: c, floatingRole: l } = a, u = () => typeof t.as != "string" || t.as === "button" || t.as === "a" && i.href != null, d = `${w()}-reference`, f = n(() => t.id ?? d);
|
|
214
|
+
D(() => {
|
|
215
|
+
a.referenceId.value = f.value;
|
|
216
|
+
}), p(() => {
|
|
217
|
+
a.referenceId.value === f.value && (a.referenceId.value = void 0);
|
|
218
|
+
});
|
|
219
|
+
let m = n(() => t.ariaHaspopup ?? (l.value && Object.hasOwn(B, l.value) ? B[l.value] : void 0)), g = (e) => {
|
|
220
|
+
let t = e && typeof e == "object" && "$el" in e ? e.$el : e;
|
|
221
|
+
a.reference.value = t instanceof HTMLElement ? t : null;
|
|
222
|
+
}, _ = () => {
|
|
223
|
+
a.trigger.value === "click" && a.toggle();
|
|
224
|
+
}, b = (e) => {
|
|
225
|
+
let t = a.floating.value, n = t && q(t)[0];
|
|
226
|
+
n && (e.preventDefault(), n.focus());
|
|
227
|
+
}, x = (e) => {
|
|
228
|
+
e.key === "Tab" && !e.shiftKey && o.value ? b(e) : u() || e.key !== "Enter" && e.key !== " " || (e.preventDefault(), _());
|
|
229
|
+
};
|
|
230
|
+
return (e, n) => (h(), r(y(t.as), {
|
|
231
|
+
id: f.value,
|
|
232
|
+
ref: g,
|
|
233
|
+
type: t.as === "button" ? "button" : void 0,
|
|
234
|
+
role: u() ? void 0 : "button",
|
|
235
|
+
tabindex: u() ? void 0 : S(s) ? -1 : 0,
|
|
236
|
+
disabled: t.as === "button" && S(s) ? !0 : void 0,
|
|
237
|
+
"aria-disabled": t.as !== "button" && S(s) ? "true" : void 0,
|
|
238
|
+
"aria-haspopup": m.value,
|
|
239
|
+
"aria-expanded": S(o) ? "true" : "false",
|
|
240
|
+
"aria-controls": S(o) ? S(c) : void 0,
|
|
241
|
+
"data-sbf-state": S(o) ? "open" : "closed",
|
|
242
|
+
onClick: _,
|
|
243
|
+
onKeydown: x
|
|
244
|
+
}, {
|
|
245
|
+
default: O(() => [v(e.$slots, "default")]),
|
|
246
|
+
_: 3
|
|
247
|
+
}, 40, [
|
|
248
|
+
"id",
|
|
249
|
+
"type",
|
|
250
|
+
"role",
|
|
251
|
+
"tabindex",
|
|
252
|
+
"disabled",
|
|
253
|
+
"aria-disabled",
|
|
254
|
+
"aria-haspopup",
|
|
255
|
+
"aria-expanded",
|
|
256
|
+
"aria-controls",
|
|
257
|
+
"data-sbf-state"
|
|
258
|
+
]));
|
|
259
|
+
}
|
|
260
|
+
}), Q = /* @__PURE__ */ s({
|
|
261
|
+
inheritAttrs: !1,
|
|
262
|
+
__name: "SbFloating",
|
|
263
|
+
props: {
|
|
264
|
+
as: { default: "div" },
|
|
265
|
+
role: { default: "dialog" },
|
|
266
|
+
transition: { default: void 0 },
|
|
267
|
+
teleportTo: { default: "body" },
|
|
268
|
+
teleportDisabled: {
|
|
269
|
+
type: Boolean,
|
|
270
|
+
default: !1
|
|
271
|
+
},
|
|
272
|
+
zIndex: { default: void 0 },
|
|
273
|
+
autoFocus: {
|
|
274
|
+
type: Boolean,
|
|
275
|
+
default: !0
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
emits: ["after-enter", "after-leave"],
|
|
279
|
+
setup(s, { emit: c }) {
|
|
280
|
+
let l = s, p = c, m = C(), g = H("SbFloating"), { isOpen: b, floatingId: x, referenceId: w, side: T, align: k } = g;
|
|
281
|
+
D(() => {
|
|
282
|
+
g.floatingRole.value = l.role;
|
|
283
|
+
});
|
|
284
|
+
let A = _(b.value), j = _(null), M = (e) => {
|
|
285
|
+
g.floating.value = e instanceof HTMLElement ? e : null;
|
|
286
|
+
}, N = (e) => {
|
|
287
|
+
j.value = e instanceof HTMLElement ? e : null;
|
|
288
|
+
}, P = n(() => ({
|
|
289
|
+
...g.floatingStyles.value,
|
|
290
|
+
...l.zIndex === void 0 ? {} : { zIndex: l.zIndex }
|
|
291
|
+
})), F = () => ({
|
|
292
|
+
"aria-labelledby": l.role && Object.hasOwn(B, l.role) && m["aria-label"] == null ? w.value : void 0,
|
|
293
|
+
...m
|
|
294
|
+
}), I = n(() => b.value && !l.teleportDisabled), L = {
|
|
295
|
+
[U]: "",
|
|
296
|
+
tabindex: 0,
|
|
297
|
+
style: {
|
|
298
|
+
position: "fixed",
|
|
299
|
+
opacity: 0,
|
|
300
|
+
outline: "none",
|
|
301
|
+
pointerEvents: "none"
|
|
302
|
+
}
|
|
303
|
+
}, R = n(() => {
|
|
304
|
+
let { transition: e } = l;
|
|
305
|
+
return e ? typeof e == "string" ? { name: e } : e : { css: !1 };
|
|
306
|
+
}), z = (e) => e.setAttribute("data-sbf-state", "closed"), V = () => p("after-enter"), W = () => {
|
|
307
|
+
b.value || (A.value = !1), p("after-leave");
|
|
308
|
+
}, G = (e) => e instanceof Node && !!j.value?.contains(e), K = (e) => {
|
|
309
|
+
let t = j.value;
|
|
310
|
+
if (!t) return;
|
|
311
|
+
let n = q(t);
|
|
312
|
+
((e === "first" ? n[0] : n[n.length - 1]) ?? t).focus({ preventScroll: !0 });
|
|
313
|
+
}, Y = (e) => {
|
|
314
|
+
G(e.relatedTarget) ? g.reference.value?.focus() : K("first");
|
|
315
|
+
}, X = (e) => {
|
|
316
|
+
if (!G(e.relatedTarget)) {
|
|
317
|
+
K("last");
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
let t = g.reference.value;
|
|
321
|
+
((t && J(t, (e) => g.contains(e))) ?? t)?.focus();
|
|
322
|
+
}, Z = () => {
|
|
323
|
+
let e = j.value;
|
|
324
|
+
e && (e.querySelector("[autofocus]") ?? q(e)[0] ?? e).focus({ preventScroll: !0 });
|
|
325
|
+
};
|
|
326
|
+
return E(b, (e) => {
|
|
327
|
+
let t = g.skipFocusReturn;
|
|
328
|
+
if (g.skipFocusReturn = !1, e) {
|
|
329
|
+
A.value = !0;
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
let n = document.activeElement;
|
|
333
|
+
!t && n && g.floating.value?.contains(n) && g.reference.value?.focus({ preventScroll: !0 });
|
|
334
|
+
}), E(() => b.value && g.isPositioned.value, async (e) => {
|
|
335
|
+
e && l.autoFocus && (await d(), Z());
|
|
336
|
+
}), (n, s) => (h(), r(e, {
|
|
337
|
+
to: l.teleportTo,
|
|
338
|
+
disabled: l.teleportDisabled
|
|
339
|
+
}, [A.value ? (h(), a("div", {
|
|
340
|
+
key: 0,
|
|
341
|
+
ref: M,
|
|
342
|
+
style: f(P.value)
|
|
343
|
+
}, [
|
|
344
|
+
I.value ? (h(), a("span", u({ key: 0 }, L, { onFocus: Y }), null, 16)) : i("", !0),
|
|
345
|
+
o(t, u(R.value, {
|
|
346
|
+
appear: "",
|
|
347
|
+
onBeforeLeave: z,
|
|
348
|
+
onAfterEnter: V,
|
|
349
|
+
onAfterLeave: W
|
|
350
|
+
}), {
|
|
351
|
+
default: O(() => [S(b) ? (h(), r(y(l.as), u({ key: 0 }, F(), {
|
|
352
|
+
id: S(x),
|
|
353
|
+
ref: N,
|
|
354
|
+
role: l.role ?? void 0,
|
|
355
|
+
tabindex: l.autoFocus ? -1 : void 0,
|
|
356
|
+
"data-sbf-state": "open",
|
|
357
|
+
"data-sbf-side": S(T),
|
|
358
|
+
"data-sbf-align": S(k)
|
|
359
|
+
}), {
|
|
360
|
+
default: O(() => [v(n.$slots, "default")]),
|
|
361
|
+
_: 3
|
|
362
|
+
}, 16, [
|
|
363
|
+
"id",
|
|
364
|
+
"role",
|
|
365
|
+
"tabindex",
|
|
366
|
+
"data-sbf-side",
|
|
367
|
+
"data-sbf-align"
|
|
368
|
+
])) : i("", !0)]),
|
|
369
|
+
_: 3
|
|
370
|
+
}, 16),
|
|
371
|
+
I.value ? (h(), a("span", u({ key: 1 }, L, { onFocus: X }), null, 16)) : i("", !0)
|
|
372
|
+
], 4)) : i("", !0)], 8, ["to", "disabled"]));
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
//#endregion
|
|
376
|
+
export { X as SbContainer, Q as SbFloating, Z as SbReference };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@floating-ui/vue"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@floating-ui/vue","vue"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.SbFloatingPanelVue={},s.FloatingUIVue,s.Vue))})(this,function(s,c,e){"use strict";function k(l){const t=e.ref(null),i=e.ref(null),f=e.ref(null),n=e.ref(!1),r=e.ref(null);let o=!1;const{floatingStyles:p,placement:d,middlewareData:g}=c.useFloating(t,i,{open:n,placement:l.placement,strategy:l.strategy,transform:!1,middleware:[c.offset(l.offsetValue),c.flip(),c.shift(),c.arrow({element:f})],whileElementsMounted:c.autoUpdate}),u=a=>{n.value=a},h=()=>u(!0),y=()=>u(!1),w=()=>u(!n.value),b=()=>{i.value&&t.value&&(i.value.style.width=`${t.value.offsetWidth}px`)},C=e.computed(()=>({...p.value})),B=e.computed(()=>{const a=g.value.arrow,P=d.value.split("-")[0],m={position:"absolute",transform:"rotate(45deg)",background:"inherit",width:"8px",height:"8px",left:(a==null?void 0:a.x)!=null?`${a.x}px`:"",top:(a==null?void 0:a.y)!=null?`${a.y}px`:""};switch(P){case"top":m.bottom="-4px";break;case"bottom":m.top="-4px";break;case"left":m.right="-4px";break;case"right":m.left="-4px";break}return m});return e.watch(n,async a=>{a&&l.hasResize&&o&&(await e.nextTick(),b())}),e.watch(t,a=>{a&&l.hasResize&&!o&&(o=!0,r.value=new ResizeObserver(b),r.value.observe(a))}),e.onMounted(()=>{l.hasResize&&t.value&&(o=!0,r.value=new ResizeObserver(b),r.value.observe(t.value))}),e.onUnmounted(()=>{var a;l.hasResize&&((a=r.value)==null||a.disconnect())}),{reference:t,floating:i,floatingArrow:f,floatingPlacement:d,floatingStyle:C,floatingArrowStyle:B,isOpen:n,toggle:w,open:h,close:y}}const x={class:"floating-container"},_=e.defineComponent({__name:"SbContainer",props:{placement:{default:"bottom-start"},strategy:{default:"absolute"},offsetValue:{default:15},hasArrow:{type:Boolean,default:!1},hasResize:{type:Boolean,default:!1}},setup(l){const t=l,{isOpen:i,reference:f,floating:n,floatingArrow:r,floatingPlacement:o,floatingStyle:p,floatingArrowStyle:d,toggle:g,open:u,close:h}=k({placement:t.placement,strategy:t.strategy,offsetValue:t.offsetValue,hasArrow:t.hasArrow,hasResize:t.hasResize}),y={reference:f,floating:n,floatingArrow:r,floatingPlacement:o,floatingStyle:p,floatingArrowStyle:d,isOpen:i,toggle:g,open:u,close:h};return(w,b)=>(e.openBlock(),e.createElementBlock("div",x,[e.renderSlot(w.$slots,"default",e.normalizeProps(e.guardReactiveProps(y)),void 0,!0)]))}}),S=(l,t)=>{const i=l.__vccOpts||l;for(const[f,n]of t)i[f]=n;return i},z=S(_,[["__scopeId","data-v-33e40585"]]),R=e.defineComponent({__name:"SbReference",props:{referenceRef:{},as:{default:"button"},onClick:{type:Function,default:void 0}},setup(l){const t=l,i=e.computed(()=>t.as==="button"||t.as==="a");return(f,n)=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.as),e.mergeProps(f.$attrs,{ref:t.referenceRef,role:i.value?"button":void 0,tabindex:i.value?0:void 0,onClick:n[0]||(n[0]=e.withModifiers(r=>{var o;return(o=t.onClick)==null?void 0:o.call(t)},["stop"])),onKeydown:[n[1]||(n[1]=e.withKeys(e.withModifiers(r=>{var o;return i.value&&((o=t.onClick)==null?void 0:o.call(t))},["prevent","stop"]),["space"])),n[2]||(n[2]=e.withKeys(e.withModifiers(r=>{var o;return i.value&&((o=t.onClick)==null?void 0:o.call(t))},["prevent","stop"]),["enter"]))]}),{default:e.withCtx(()=>[e.renderSlot(f.$slots,"default")]),_:3},16,["role","tabindex"]))}}),A=S(e.defineComponent({inheritAttrs:!1,__name:"SbFloating",props:{floatingRef:{},floatingArrowRef:{default:()=>e.ref(null)},isOpen:{type:Boolean},floatingPlacement:{},floatingStyle:{},floatingArrowStyle:{default:void 0},arrowDimensions:{default:void 0},zIndex:{default:void 0},animation:{default:"scale-fade"},duration:{default:300}},setup(l){const t=l,i=e.useAttrs(),f=e.computed(()=>{const o={...t.floatingStyle,"--sb-transition-duration":t.duration+"ms"};return t.zIndex!==void 0&&(o.zIndex=t.zIndex),o}),n=e.computed(()=>{const o={...t.floatingArrowStyle||{}};if(t.arrowDimensions){const p=t.arrowDimensions,d=`-${p/2}px`;switch(t.floatingPlacement.split("-")[0]){case"top":o.bottom=d;break;case"bottom":o.top=d;break;case"left":o.right=d;break;case"right":o.left=d;break}o.width=`${p}px`,o.height=`${p}px`}return t.zIndex!==void 0&&(o.zIndex=t.zIndex),o}),r=e.computed(()=>t.animation==="fade"?"fade":t.animation==="scale-fade"?"scale-fade":"");return(o,p)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[e.createVNode(e.Transition,{name:r.value},{default:e.withCtx(()=>[t.isOpen?(e.openBlock(),e.createElementBlock("div",e.mergeProps({key:0,ref:t.floatingRef,style:f.value},e.unref(i)),[e.renderSlot(o.$slots,"default",{},void 0,!0),t.floatingArrowRef?(e.openBlock(),e.createElementBlock("div",{key:0,ref:t.floatingArrowRef,style:e.normalizeStyle(n.value)},null,4)):e.createCommentVNode("",!0)],16)):e.createCommentVNode("",!0)]),_:3},8,["name"])]))}}),[["__scopeId","data-v-366682ad"]]);s.SbContainer=z,s.SbFloating=A,s.SbReference=R,s.useSbFloatingPanel=k,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
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`,i=e=>{let[t,n]=e.split(`-`),r=n===`start`?`0%`:n===`end`?`100%`:`50%`;return t===`top`?`${r} 100%`:t===`bottom`?`${r} 0%`:t===`left`?`100% ${r}`:`0% ${r}`};function a(e){let a=(0,t.ref)(null),o=(0,t.ref)(null),s=(0,t.computed)(()=>{let a=(0,t.toValue)(e.padding),o=(0,t.toValue)(e.matchWidth),s=(0,t.toValue)(e.placement).includes(`-`),c=(0,n.flip)({padding:a,crossAxis:`alignment`,fallbackAxisSideDirection:`end`}),l=(0,n.shift)({padding:a,limiter:(0,n.limitShift)()}),u=[(0,n.offset)((0,t.toValue)(e.offset)),...s?[c,l]:[l,c],(0,n.size)({padding:a,apply({rects:e,elements:t,availableWidth:n,availableHeight:a,placement:s}){let{style:c}=t.floating,l=r(e.reference.width);c.setProperty(`--sbf-reference-width`,l),c.setProperty(`--sbf-transform-origin`,i(s)),c.setProperty(`--sbf-available-width`,r(n)),c.setProperty(`--sbf-available-height`,r(a)),c.width=o===!0?l:``,c.minWidth=o===`min`?l:``}})];return(0,t.toValue)(e.hideWhenDetached)&&u.push((0,n.hide)({padding:a})),u}),{floatingStyles:c,middlewareData:l,placement:u,isPositioned:d,update:f}=(0,n.useFloating)(a,o,{open:()=>(0,t.toValue)(e.isOpen),placement:()=>(0,t.toValue)(e.placement),strategy:()=>(0,t.toValue)(e.strategy),middleware:s,whileElementsMounted:n.autoUpdate});return{reference:a,floating:o,floatingStyles:(0,t.computed)(()=>({...c.value,...l.value.hide?.referenceHidden?{visibility:`hidden`}:{}})),placement:u,side:(0,t.computed)(()=>u.value.split(`-`)[0]),align:(0,t.computed)(()=>u.value.split(`-`)[1]),isPositioned:d,update:f}}var o={dialog:`dialog`,alertdialog:`dialog`,menu:`menu`,listbox:`listbox`,tree:`tree`,grid:`grid`},s=Symbol(`SbFloatingContext`);function c(e){let n=(0,t.inject)(s,null);if(!n)throw Error(`[sb-floating-panel-vue] <${e}> must be used inside <SbContainer>.`);return n}var l=`data-sbf-focus-guard`,u=[`a[href]`,`button:not([disabled])`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`summary`,`audio[controls]`,`video[controls]`,`[tabindex]`,`[contenteditable="true"]`].join(`,`),d=e=>e.tabIndex>=0&&!e.hasAttribute(`data-sbf-focus-guard`)&&!e.closest(`[inert]`)&&(e.checkVisibility?.()??!0);function f(e){let t=e instanceof Element?e.closest(u):null;return!!t&&!t.closest(`[inert]`)}function p(e){return[...e.querySelectorAll(u)].filter(d)}function m(e,t){return p(e.ownerDocument).find(n=>!!(e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING)&&!e.contains(n)&&!t(n))}var h=[],g=(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},closeOnFocusOut:{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 i=e,o=(0,t.useModel)(e,`open`),c=r,l=i.defaultOpen,u=(0,t.computed)(()=>!i.disabled&&(o.value??l)),d=e=>{e&&i.disabled||e!==u.value&&(o.value=e)},p=()=>d(!0),m=()=>d(!1),g=()=>d(!u.value),_=a({isOpen:u,placement:()=>i.placement,strategy:()=>i.strategy,offset:()=>i.offset,padding:()=>i.padding,matchWidth:()=>i.matchWidth,hideWhenDetached:()=>i.hideWhenDetached}),v=new Set,y={..._,isOpen:u,disabled:(0,t.toRef)(i,`disabled`),trigger:(0,t.toRef)(i,`trigger`),floatingId:`${(0,t.useId)()}-floating`,referenceId:(0,t.ref)(),floatingRole:(0,t.ref)(`dialog`),skipFocusReturn:!1,open:p,close:m,toggle:g,contains:e=>e instanceof Node?_.reference.value?.contains(e)||_.floating.value?.contains(e)?!0:[...v].some(t=>t.contains(e)):!1,registerChild:e=>(v.add(e),()=>v.delete(e))},b=(0,t.inject)(s,null);b&&(0,t.onScopeDispose)(b.registerChild(y)),(0,t.provide)(s,y);let x=e=>{e.key===`Escape`&&h[h.length-1]===y&&(!i.closeOnEscape||e.defaultPrevented||e.isComposing||(e.preventDefault(),m()))},S=e=>{y.contains(e)||(y.skipFocusReturn=f(e),m())},C,w=e=>{if(C?.(),!i.closeOnClickOutside)return;let t=e.composedPath()[0]??e.target;if(e.pointerType!==`touch`){S(t);return}if(y.contains(t))return;let n=e=>{C?.(),S(e.composedPath()[0]??e.target)};document.addEventListener(`click`,n,!0),C=()=>{document.removeEventListener(`click`,n,!0),C=void 0}},T=e=>{i.closeOnFocusOut&&(y.contains(e.composedPath()[0]??e.target)||m())};return(0,t.watch)(u,(e,t,n)=>{e&&typeof document<`u`&&(h.push(y),document.addEventListener(`keydown`,x),document.addEventListener(`pointerdown`,w,!0),document.addEventListener(`focusin`,T),n(()=>{document.removeEventListener(`keydown`,x),document.removeEventListener(`pointerdown`,w,!0),document.removeEventListener(`focusin`,T),C?.(),h.splice(h.indexOf(y),1)}))},{immediate:!0}),(0,t.watch)(u,e=>c(e?`open`:`close`)),(0,t.watch)(()=>i.disabled,e=>{e&&(o.value??l)&&(o.value=!1)}),n({open:p,close:m,toggle:g,update:_.update}),(e,n)=>(0,t.renderSlot)(e.$slots,`default`,{isOpen:u.value,open:p,close:m,toggle:g,placement:(0,t.unref)(_).placement.value,side:(0,t.unref)(_).side.value,align:(0,t.unref)(_).align.value})}}),_=(0,t.defineComponent)({__name:`SbReference`,props:{as:{default:`button`},id:{default:void 0},ariaHaspopup:{default:void 0}},setup(e){let n=e,r=(0,t.useAttrs)(),i=c(`SbReference`),{isOpen:a,disabled:s,floatingId:l,floatingRole:u}=i,d=()=>typeof n.as!=`string`||n.as===`button`||n.as===`a`&&r.href!=null,f=`${(0,t.useId)()}-reference`,m=(0,t.computed)(()=>n.id??f);(0,t.watchEffect)(()=>{i.referenceId.value=m.value}),(0,t.onBeforeUnmount)(()=>{i.referenceId.value===m.value&&(i.referenceId.value=void 0)});let h=(0,t.computed)(()=>n.ariaHaspopup??(u.value&&Object.hasOwn(o,u.value)?o[u.value]:void 0)),g=e=>{let t=e&&typeof e==`object`&&`$el`in e?e.$el:e;i.reference.value=t instanceof HTMLElement?t:null},_=()=>{i.trigger.value===`click`&&i.toggle()},v=e=>{let t=i.floating.value,n=t&&p(t)[0];n&&(e.preventDefault(),n.focus())},y=e=>{e.key===`Tab`&&!e.shiftKey&&a.value?v(e):d()||e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),_())};return(e,r)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(n.as),{id:m.value,ref:g,type:n.as===`button`?`button`:void 0,role:d()?void 0:`button`,tabindex:d()?void 0:(0,t.unref)(s)?-1:0,disabled:n.as===`button`&&(0,t.unref)(s)?!0:void 0,"aria-disabled":n.as!==`button`&&(0,t.unref)(s)?`true`:void 0,"aria-haspopup":h.value,"aria-expanded":(0,t.unref)(a)?`true`:`false`,"aria-controls":(0,t.unref)(a)?(0,t.unref)(l):void 0,"data-sbf-state":(0,t.unref)(a)?`open`:`closed`,onClick:_,onKeydown:y},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},40,[`id`,`type`,`role`,`tabindex`,`disabled`,`aria-disabled`,`aria-haspopup`,`aria-expanded`,`aria-controls`,`data-sbf-state`]))}}),v=(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:!0}},emits:[`after-enter`,`after-leave`],setup(e,{emit:n}){let r=e,i=n,a=(0,t.useAttrs)(),s=c(`SbFloating`),{isOpen:u,floatingId:d,referenceId:f,side:h,align:g}=s;(0,t.watchEffect)(()=>{s.floatingRole.value=r.role});let _=(0,t.ref)(u.value),v=(0,t.ref)(null),y=e=>{s.floating.value=e instanceof HTMLElement?e:null},b=e=>{v.value=e instanceof HTMLElement?e:null},x=(0,t.computed)(()=>({...s.floatingStyles.value,...r.zIndex===void 0?{}:{zIndex:r.zIndex}})),S=()=>({"aria-labelledby":r.role&&Object.hasOwn(o,r.role)&&a[`aria-label`]==null?f.value:void 0,...a}),C=(0,t.computed)(()=>u.value&&!r.teleportDisabled),w={[l]:``,tabindex:0,style:{position:`fixed`,opacity:0,outline:`none`,pointerEvents:`none`}},T=(0,t.computed)(()=>{let{transition:e}=r;return e?typeof e==`string`?{name:e}:e:{css:!1}}),E=e=>e.setAttribute(`data-sbf-state`,`closed`),D=()=>i(`after-enter`),O=()=>{u.value||(_.value=!1),i(`after-leave`)},k=e=>e instanceof Node&&!!v.value?.contains(e),A=e=>{let t=v.value;if(!t)return;let n=p(t);((e===`first`?n[0]:n[n.length-1])??t).focus({preventScroll:!0})},j=e=>{k(e.relatedTarget)?s.reference.value?.focus():A(`first`)},M=e=>{if(!k(e.relatedTarget)){A(`last`);return}let t=s.reference.value;((t&&m(t,e=>s.contains(e)))??t)?.focus()},N=()=>{let e=v.value;e&&(e.querySelector(`[autofocus]`)??p(e)[0]??e).focus({preventScroll:!0})};return(0,t.watch)(u,e=>{let t=s.skipFocusReturn;if(s.skipFocusReturn=!1,e){_.value=!0;return}let n=document.activeElement;!t&&n&&s.floating.value?.contains(n)&&s.reference.value?.focus({preventScroll:!0})}),(0,t.watch)(()=>u.value&&s.isPositioned.value,async e=>{e&&r.autoFocus&&(await(0,t.nextTick)(),N())}),(e,n)=>((0,t.openBlock)(),(0,t.createBlock)(t.Teleport,{to:r.teleportTo,disabled:r.teleportDisabled},[_.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:0,ref:y,style:(0,t.normalizeStyle)(x.value)},[C.value?((0,t.openBlock)(),(0,t.createElementBlock)(`span`,(0,t.mergeProps)({key:0},w,{onFocus:j}),null,16)):(0,t.createCommentVNode)(``,!0),(0,t.createVNode)(t.Transition,(0,t.mergeProps)(T.value,{appear:``,onBeforeLeave:E,onAfterEnter:D,onAfterLeave:O}),{default:(0,t.withCtx)(()=>[(0,t.unref)(u)?((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(r.as),(0,t.mergeProps)({key:0},S(),{id:(0,t.unref)(d),ref:b,role:r.role??void 0,tabindex:r.autoFocus?-1:void 0,"data-sbf-state":`open`,"data-sbf-side":(0,t.unref)(h),"data-sbf-align":(0,t.unref)(g)}),{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},16,[`id`,`role`,`tabindex`,`data-sbf-side`,`data-sbf-align`])):(0,t.createCommentVNode)(``,!0)]),_:3},16),C.value?((0,t.openBlock)(),(0,t.createElementBlock)(`span`,(0,t.mergeProps)({key:1},w,{onFocus:M}),null,16)):(0,t.createCommentVNode)(``,!0)],4)):(0,t.createCommentVNode)(``,!0)],8,[`to`,`disabled`]))}});e.SbContainer=g,e.SbFloating=v,e.SbReference=_});
|