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.
@@ -1,219 +1,270 @@
1
- import { useFloating as V, autoUpdate as B, offset as M, flip as T, shift as W, arrow as D } from "@floating-ui/vue";
2
- import { ref as c, computed as u, watch as S, onMounted as E, onUnmounted as K, nextTick as N, defineComponent as k, createElementBlock as x, openBlock as v, renderSlot as z, normalizeProps as U, guardReactiveProps as j, createBlock as A, resolveDynamicComponent as q, mergeProps as $, withKeys as _, withModifiers as w, withCtx as C, useAttrs as G, Teleport as H, createVNode as J, Transition as L, createCommentVNode as R, unref as Q, normalizeStyle as X } from "vue";
3
- function Y(a) {
4
- const e = c(null), l = c(null), r = c(null), o = c(!1), s = c(null);
5
- let t = !1;
6
- const { floatingStyles: f, placement: i, middlewareData: m } = V(e, l, {
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
- };
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
- 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
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(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`;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});