asma-ui-core 3.134.3 → 3.134.5
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,134 +1,144 @@
|
|
|
1
|
-
import { cn as
|
|
2
|
-
import { resolveSx as
|
|
3
|
-
import { tabbableWithin as
|
|
4
|
-
import { TOP_LAYER_PROPS as
|
|
5
|
-
import { OverlayBackOwnerContext as
|
|
6
|
-
import { useEffect as
|
|
1
|
+
import { cn as $ } from "../../../helpers/cn.js";
|
|
2
|
+
import { resolveSx as R } from "../../../helpers/sx.js";
|
|
3
|
+
import { tabbableWithin as y } from "../../../helpers/focusable.js";
|
|
4
|
+
import { TOP_LAYER_PROPS as j, TOP_LAYER_RESET_STYLE as q, getOpenModalDialogAncestor as C, shouldUsePopoverTopLayer as G, useTopLayerRef as J } from "../../../hooks/useTopLayer.hook.js";
|
|
5
|
+
import { OverlayBackOwnerContext as Q, useBackCloses as V } from "../../../hooks/useBackCloses.hook.js";
|
|
6
|
+
import { useEffect as x, useMemo as X, useRef as Z, useState as b } from "react";
|
|
7
7
|
import { jsx as P } from "react/jsx-runtime";
|
|
8
|
-
import { FloatingPortal as
|
|
9
|
-
var
|
|
8
|
+
import { FloatingPortal as ee, autoUpdate as te, flip as oe, offset as ne, shift as re, size as se, useDismiss as ae, useFloating as ie, useInteractions as ce, useMergeRefs as fe } from "@floating-ui/react";
|
|
9
|
+
var le = {
|
|
10
10
|
vertical: "bottom",
|
|
11
11
|
horizontal: "left"
|
|
12
|
-
},
|
|
12
|
+
}, ue = {
|
|
13
13
|
vertical: "top",
|
|
14
14
|
horizontal: "left"
|
|
15
|
-
},
|
|
16
|
-
const
|
|
17
|
-
t
|
|
18
|
-
|
|
19
|
-
o
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
}, de = (o) => {
|
|
16
|
+
const t = getComputedStyle(o);
|
|
17
|
+
return t.boxSizing === "border-box" ? 0 : parseFloat(t.paddingTop) + parseFloat(t.paddingBottom) + parseFloat(t.borderTopWidth) + parseFloat(t.borderBottomWidth);
|
|
18
|
+
}, pe = (o, t) => `${t.vertical === "bottom" ? "top" : t.vertical === "top" ? "bottom" : o.vertical === "top" ? "top" : "bottom"}${o.horizontal === "left" ? "-start" : o.horizontal === "right" ? "-end" : ""}`, Le = ({ open: o, anchorEl: t, onClose: c, anchorOrigin: h = le, transformOrigin: w = ue, id: T, className: D, sx: F, slotProps: u, onClick: K, children: S, keepMounted: E = !1, tabIntoContent: d = !0, registerBackClose: k = !0 }) => {
|
|
19
|
+
const O = X(() => pe(h, w), [h, w]), [L, _] = b(o), f = Z(!1), [M, H] = b();
|
|
20
|
+
o && !L && _(!0);
|
|
21
|
+
const p = o || E && L, m = C(t), [g, z] = b(m);
|
|
22
|
+
t && g !== m && z(m);
|
|
23
|
+
const { refs: a, floatingStyles: A, context: B } = ie({
|
|
24
|
+
open: o,
|
|
25
|
+
placement: O,
|
|
23
26
|
strategy: "fixed",
|
|
24
|
-
whileElementsMounted:
|
|
25
|
-
elements: { reference:
|
|
27
|
+
whileElementsMounted: te,
|
|
28
|
+
elements: { reference: t ?? void 0 },
|
|
26
29
|
middleware: [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
ne(4),
|
|
31
|
+
oe({ padding: 8 }),
|
|
32
|
+
re({ padding: 8 }),
|
|
33
|
+
se({
|
|
34
|
+
padding: 8,
|
|
35
|
+
apply: ({ availableHeight: e, elements: n }) => H(Math.max(0, e - de(n.floating)))
|
|
36
|
+
})
|
|
30
37
|
],
|
|
31
|
-
onOpenChange: (e,
|
|
32
|
-
e || c?.(
|
|
38
|
+
onOpenChange: (e, n, r) => {
|
|
39
|
+
e || c?.(n ?? {}, r === "escape-key" ? "escapeKeyDown" : "backdropClick");
|
|
33
40
|
}
|
|
34
|
-
}), { getFloatingProps:
|
|
41
|
+
}), { getFloatingProps: N } = ce([ae(B, {
|
|
35
42
|
outsidePress: (e) => {
|
|
36
|
-
const
|
|
37
|
-
return !(
|
|
43
|
+
const n = e.target;
|
|
44
|
+
return !(t instanceof Element && n instanceof Node && t.contains(n));
|
|
38
45
|
},
|
|
39
46
|
escapeKey: !0
|
|
40
47
|
})]);
|
|
41
|
-
|
|
42
|
-
active:
|
|
48
|
+
V({
|
|
49
|
+
active: o && k,
|
|
43
50
|
requestClose: (e) => c ? c(e ?? new Event("overlayBack"), "escapeKeyDown") : !1,
|
|
44
|
-
ownerRef:
|
|
51
|
+
ownerRef: a.floating
|
|
45
52
|
});
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
if (!
|
|
49
|
-
const e =
|
|
50
|
-
let
|
|
53
|
+
const l = G(g), U = fe([J(a.setFloating, l)]);
|
|
54
|
+
x(() => {
|
|
55
|
+
if (!o) return;
|
|
56
|
+
const e = t instanceof HTMLElement ? t : null, n = () => a.floating.current?.contains(document.activeElement) ?? !1;
|
|
57
|
+
let r = n();
|
|
51
58
|
const s = () => {
|
|
52
|
-
|
|
59
|
+
r = n();
|
|
53
60
|
};
|
|
54
61
|
return document.addEventListener("focusin", s), () => {
|
|
55
62
|
document.removeEventListener("focusin", s);
|
|
56
|
-
const
|
|
57
|
-
|
|
63
|
+
const i = document.activeElement, v = !i || i === document.body || n();
|
|
64
|
+
r && v && e?.isConnected && e.focus({ preventScroll: !0 });
|
|
58
65
|
};
|
|
59
66
|
}, [
|
|
60
|
-
t,
|
|
61
67
|
o,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
t,
|
|
69
|
+
a.floating
|
|
70
|
+
]), x(() => {
|
|
71
|
+
if (!o) return;
|
|
72
|
+
const e = (r) => {
|
|
73
|
+
if (f.current = r.key === "Tab", !d || !f.current || r.shiftKey || r.defaultPrevented) return;
|
|
74
|
+
const s = a.floating.current;
|
|
75
|
+
if (!s || !(t instanceof Element) || !t.contains(document.activeElement)) return;
|
|
76
|
+
const [i] = y(s);
|
|
77
|
+
i && (r.preventDefault(), i.focus({ preventScroll: !0 }), f.current = !1);
|
|
78
|
+
}, n = (r) => {
|
|
79
|
+
const s = r.target, i = s instanceof Node && ((a.floating.current?.contains(s) ?? !1) || t instanceof Element && t.contains(s));
|
|
80
|
+
f.current && !i && c?.(r, "tabKeyDown"), f.current = !1;
|
|
74
81
|
};
|
|
75
|
-
return document.addEventListener("keydown", e, !0), document.addEventListener("focusin",
|
|
76
|
-
document.removeEventListener("keydown", e, !0), document.removeEventListener("focusin",
|
|
82
|
+
return document.addEventListener("keydown", e, !0), document.addEventListener("focusin", n), () => {
|
|
83
|
+
document.removeEventListener("keydown", e, !0), document.removeEventListener("focusin", n);
|
|
77
84
|
};
|
|
78
85
|
}, [
|
|
79
|
-
t,
|
|
80
86
|
o,
|
|
87
|
+
t,
|
|
81
88
|
c,
|
|
82
|
-
|
|
89
|
+
a.floating,
|
|
83
90
|
d
|
|
84
91
|
]);
|
|
85
|
-
const
|
|
86
|
-
onClick:
|
|
92
|
+
const W = o ? N({
|
|
93
|
+
onClick: K,
|
|
87
94
|
onKeyDown: (e) => {
|
|
88
|
-
if (e.key !== "Tab" || e.defaultPrevented || !(
|
|
89
|
-
const
|
|
90
|
-
if (s === -1 || (e.shiftKey ? s !== 0 : s !==
|
|
95
|
+
if (e.key !== "Tab" || e.defaultPrevented || !(t instanceof HTMLElement)) return;
|
|
96
|
+
const n = e.currentTarget, r = y(n), s = r.indexOf(document.activeElement);
|
|
97
|
+
if (s === -1 || (e.shiftKey ? s !== 0 : s !== r.length - 1)) return;
|
|
91
98
|
e.preventDefault();
|
|
92
|
-
const
|
|
93
|
-
f.current = !1,
|
|
99
|
+
const i = y(document).filter((Y) => !n.contains(Y)), v = i[i.indexOf(t) + (e.shiftKey ? -1 : 1)], I = (d && e.shiftKey ? void 0 : v) ?? t;
|
|
100
|
+
f.current = !1, I.focus({ preventScroll: !0 }), c?.(e, "tabKeyDown");
|
|
94
101
|
}
|
|
95
102
|
}) : {};
|
|
96
|
-
return
|
|
97
|
-
if (!
|
|
98
|
-
const e =
|
|
103
|
+
return x(() => {
|
|
104
|
+
if (!p || !l) return;
|
|
105
|
+
const e = a.floating.current;
|
|
99
106
|
if (!(!e || typeof e.showPopover != "function"))
|
|
100
107
|
try {
|
|
101
|
-
|
|
108
|
+
o && !e.matches(":popover-open") && e.showPopover(), !o && e.matches(":popover-open") && e.hidePopover();
|
|
102
109
|
} catch {
|
|
103
110
|
}
|
|
104
111
|
}, [
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
]),
|
|
110
|
-
root:
|
|
112
|
+
o,
|
|
113
|
+
p,
|
|
114
|
+
l,
|
|
115
|
+
a.floating
|
|
116
|
+
]), p ? /* @__PURE__ */ P(ee, {
|
|
117
|
+
root: g,
|
|
111
118
|
children: /* @__PURE__ */ P("div", {
|
|
112
|
-
ref:
|
|
113
|
-
id:
|
|
114
|
-
...
|
|
119
|
+
ref: U,
|
|
120
|
+
id: T,
|
|
121
|
+
...l ? j : {},
|
|
115
122
|
style: {
|
|
116
|
-
...
|
|
117
|
-
...
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
...
|
|
123
|
+
...l ? q : {},
|
|
124
|
+
...o ? {
|
|
125
|
+
...A,
|
|
126
|
+
maxHeight: M
|
|
127
|
+
} : {},
|
|
128
|
+
...R(F),
|
|
129
|
+
...R(u?.paper?.sx),
|
|
130
|
+
...u?.paper?.style,
|
|
131
|
+
...o ? null : { display: "none" }
|
|
122
132
|
},
|
|
123
|
-
...
|
|
124
|
-
className:
|
|
125
|
-
children: /* @__PURE__ */ P(
|
|
126
|
-
value:
|
|
127
|
-
children:
|
|
133
|
+
...W,
|
|
134
|
+
className: $("z-[1300] overflow-auto rounded bg-white shadow-[0px_1px_12px_0px_rgba(0,0,0,0.15)]", D ?? "my-1", u?.paper?.className),
|
|
135
|
+
children: /* @__PURE__ */ P(Q.Provider, {
|
|
136
|
+
value: a.floating,
|
|
137
|
+
children: S
|
|
128
138
|
})
|
|
129
139
|
})
|
|
130
140
|
}) : null;
|
|
131
141
|
};
|
|
132
142
|
export {
|
|
133
|
-
|
|
143
|
+
Le as StyledPopover
|
|
134
144
|
};
|