@lanaco/lnc-react-ui
Version:
React component library
1,216 lines (1,215 loc) • 39.3 kB
JavaScript
import { c as et, g as fe } from "./floating-ui.dom-C16Oktn3.js";
import * as s from "react";
import { useLayoutEffect as Ve, useEffect as Ke, useRef as tt } from "react";
import { r as ge } from "./index-B2yaYXE2.js";
var te = typeof document < "u" ? Ve : Ke;
function re(t, e) {
if (t === e)
return !0;
if (typeof t != typeof e)
return !1;
if (typeof t == "function" && t.toString() === e.toString())
return !0;
let n, r, o;
if (t && e && typeof t == "object") {
if (Array.isArray(t)) {
if (n = t.length, n != e.length) return !1;
for (r = n; r-- !== 0; )
if (!re(t[r], e[r]))
return !1;
return !0;
}
if (o = Object.keys(t), n = o.length, n !== Object.keys(e).length)
return !1;
for (r = n; r-- !== 0; )
if (!Object.prototype.hasOwnProperty.call(e, o[r]))
return !1;
for (r = n; r-- !== 0; ) {
const i = o[r];
if (!(i === "_owner" && t.$$typeof) && !re(t[i], e[i]))
return !1;
}
return !0;
}
return t !== t && e !== e;
}
function Ae(t) {
const e = s.useRef(t);
return te(() => {
e.current = t;
}), e;
}
function nt(t) {
t === void 0 && (t = {});
const {
placement: e = "bottom",
strategy: n = "absolute",
middleware: r = [],
platform: o,
whileElementsMounted: i,
open: u
} = t, [a, f] = s.useState({
x: null,
y: null,
strategy: n,
placement: e,
middlewareData: {},
isPositioned: !1
}), [d, m] = s.useState(r);
re(d, r) || m(r);
const c = s.useRef(null), l = s.useRef(null), p = s.useRef(a), w = Ae(i), b = Ae(o), [v, g] = s.useState(null), [I, E] = s.useState(null), F = s.useCallback((T) => {
c.current !== T && (c.current = T, g(T));
}, []), N = s.useCallback((T) => {
l.current !== T && (l.current = T, E(T));
}, []), O = s.useCallback(() => {
if (!c.current || !l.current)
return;
const T = {
placement: e,
strategy: n,
middleware: d
};
b.current && (T.platform = b.current), et(c.current, l.current, T).then((D) => {
const A = {
...D,
isPositioned: !0
};
K.current && !re(p.current, A) && (p.current = A, ge.flushSync(() => {
f(A);
}));
});
}, [d, e, n, b]);
te(() => {
u === !1 && p.current.isPositioned && (p.current.isPositioned = !1, f((T) => ({
...T,
isPositioned: !1
})));
}, [u]);
const K = s.useRef(!1);
te(() => (K.current = !0, () => {
K.current = !1;
}), []), te(() => {
if (v && I) {
if (w.current)
return w.current(v, I, O);
O();
}
}, [v, I, O, w]);
const W = s.useMemo(() => ({
reference: c,
floating: l,
setReference: F,
setFloating: N
}), [F, N]), V = s.useMemo(() => ({
reference: v,
floating: I
}), [v, I]);
return s.useMemo(() => ({
...a,
update: O,
refs: W,
elements: V,
reference: F,
floating: N
}), [a, O, W, V, F, N]);
}
var rt = function(t) {
if (typeof document > "u")
return null;
var e = Array.isArray(t) ? t[0] : t;
return e.ownerDocument.body;
}, z = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), ee = {}, de = 0, We = function(t) {
return t && (t.host || We(t.parentNode));
}, ot = function(t, e) {
return e.map(function(n) {
if (t.contains(n))
return n;
var r = We(n);
return r && t.contains(r) ? r : (console.error("aria-hidden", n, "in not contained inside", t, ". Doing nothing"), null);
}).filter(function(n) {
return !!n;
});
}, it = function(t, e, n, r) {
var o = ot(e, Array.isArray(t) ? t : [t]);
ee[n] || (ee[n] = /* @__PURE__ */ new WeakMap());
var i = ee[n], u = [], a = /* @__PURE__ */ new Set(), f = new Set(o), d = function(c) {
!c || a.has(c) || (a.add(c), d(c.parentNode));
};
o.forEach(d);
var m = function(c) {
!c || f.has(c) || Array.prototype.forEach.call(c.children, function(l) {
if (a.has(l))
m(l);
else
try {
var p = l.getAttribute(r), w = p !== null && p !== "false", b = (z.get(l) || 0) + 1, v = (i.get(l) || 0) + 1;
z.set(l, b), i.set(l, v), u.push(l), b === 1 && w && Q.set(l, !0), v === 1 && l.setAttribute(n, "true"), w || l.setAttribute(r, "true");
} catch (g) {
console.error("aria-hidden: cannot operate on ", l, g);
}
});
};
return m(e), a.clear(), de++, function() {
u.forEach(function(c) {
var l = z.get(c) - 1, p = i.get(c) - 1;
z.set(c, l), i.set(c, p), l || (Q.has(c) || c.removeAttribute(r), Q.delete(c)), p || c.removeAttribute(n);
}), de--, de || (z = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), ee = {});
};
}, ut = function(t, e, n) {
n === void 0 && (n = "data-aria-hidden");
var r = Array.from(Array.isArray(t) ? t : [t]), o = rt(t);
return o ? (r.push.apply(r, Array.from(o.querySelectorAll("[aria-live], script"))), it(r, o, n, "aria-hidden")) : function() {
return null;
};
};
/*!
* tabbable 6.4.0
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*/
var st = ["input:not([inert]):not([inert] *)", "select:not([inert]):not([inert] *)", "textarea:not([inert]):not([inert] *)", "a[href]:not([inert]):not([inert] *)", "button:not([inert]):not([inert] *)", "[tabindex]:not(slot):not([inert]):not([inert] *)", "audio[controls]:not([inert]):not([inert] *)", "video[controls]:not([inert]):not([inert] *)", '[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)', "details>summary:first-of-type:not([inert]):not([inert] *)", "details:not([inert]):not([inert] *)"], he = /* @__PURE__ */ st.join(","), $e = typeof Element > "u", X = $e ? function() {
} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector, oe = !$e && Element.prototype.getRootNode ? function(t) {
var e;
return t == null || (e = t.getRootNode) === null || e === void 0 ? void 0 : e.call(t);
} : function(t) {
return t == null ? void 0 : t.ownerDocument;
}, ie = function(e, n) {
var r;
n === void 0 && (n = !0);
var o = e == null || (r = e.getAttribute) === null || r === void 0 ? void 0 : r.call(e, "inert"), i = o === "" || o === "true", u = i || n && e && // closest does not exist on shadow roots, so we fall back to a manual
// lookup upward, in case it is not defined.
(typeof e.closest == "function" ? e.closest("[inert]") : ie(e.parentNode));
return u;
}, at = function(e) {
var n, r = e == null || (n = e.getAttribute) === null || n === void 0 ? void 0 : n.call(e, "contenteditable");
return r === "" || r === "true";
}, lt = function(e, n, r) {
if (ie(e))
return [];
var o = Array.prototype.slice.apply(e.querySelectorAll(he));
return n && X.call(e, he) && o.unshift(e), o = o.filter(r), o;
}, ye = function(e, n, r) {
for (var o = [], i = Array.from(e); i.length; ) {
var u = i.shift();
if (!ie(u, !1))
if (u.tagName === "SLOT") {
var a = u.assignedElements(), f = a.length ? a : u.children, d = ye(f, !0, r);
r.flatten ? o.push.apply(o, d) : o.push({
scopeParent: u,
candidates: d
});
} else {
var m = X.call(u, he);
m && r.filter(u) && (n || !e.includes(u)) && o.push(u);
var c = u.shadowRoot || // check for an undisclosed shadow
typeof r.getShadowRoot == "function" && r.getShadowRoot(u), l = !ie(c, !1) && (!r.shadowRootFilter || r.shadowRootFilter(u));
if (c && l) {
var p = ye(c === !0 ? u.children : c.children, !0, r);
r.flatten ? o.push.apply(o, p) : o.push({
scopeParent: u,
candidates: p
});
} else
i.unshift.apply(i, u.children);
}
}
return o;
}, qe = function(e) {
return !isNaN(parseInt(e.getAttribute("tabindex"), 10));
}, je = function(e) {
if (!e)
throw new Error("No node provided");
return e.tabIndex < 0 && (/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName) || at(e)) && !qe(e) ? 0 : e.tabIndex;
}, ct = function(e, n) {
var r = je(e);
return r < 0 && n && !qe(e) ? 0 : r;
}, ft = function(e, n) {
return e.tabIndex === n.tabIndex ? e.documentOrder - n.documentOrder : e.tabIndex - n.tabIndex;
}, He = function(e) {
return e.tagName === "INPUT";
}, dt = function(e) {
return He(e) && e.type === "hidden";
}, vt = function(e) {
var n = e.tagName === "DETAILS" && Array.prototype.slice.apply(e.children).some(function(r) {
return r.tagName === "SUMMARY";
});
return n;
}, pt = function(e, n) {
for (var r = 0; r < e.length; r++)
if (e[r].checked && e[r].form === n)
return e[r];
}, bt = function(e) {
if (!e.name)
return !0;
var n = e.form || oe(e), r = function(a) {
return n.querySelectorAll('input[type="radio"][name="' + a + '"]');
}, o;
if (typeof window < "u" && typeof window.CSS < "u" && typeof window.CSS.escape == "function")
o = r(window.CSS.escape(e.name));
else
try {
o = r(e.name);
} catch (u) {
return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s", u.message), !1;
}
var i = pt(o, e.form);
return !i || i === e;
}, mt = function(e) {
return He(e) && e.type === "radio";
}, gt = function(e) {
return mt(e) && !bt(e);
}, ht = function(e) {
var n, r = e && oe(e), o = (n = r) === null || n === void 0 ? void 0 : n.host, i = !1;
if (r && r !== e) {
var u, a, f;
for (i = !!((u = o) !== null && u !== void 0 && (a = u.ownerDocument) !== null && a !== void 0 && a.contains(o) || e != null && (f = e.ownerDocument) !== null && f !== void 0 && f.contains(e)); !i && o; ) {
var d, m, c;
r = oe(o), o = (d = r) === null || d === void 0 ? void 0 : d.host, i = !!((m = o) !== null && m !== void 0 && (c = m.ownerDocument) !== null && c !== void 0 && c.contains(o));
}
}
return i;
}, Pe = function(e) {
var n = e.getBoundingClientRect(), r = n.width, o = n.height;
return r === 0 && o === 0;
}, yt = function(e, n) {
var r = n.displayCheck, o = n.getShadowRoot;
if (r === "full-native" && "checkVisibility" in e) {
var i = e.checkVisibility({
// Checking opacity might be desirable for some use cases, but natively,
// opacity zero elements _are_ focusable and tabbable.
checkOpacity: !1,
opacityProperty: !1,
contentVisibilityAuto: !0,
visibilityProperty: !0,
// This is an alias for `visibilityProperty`. Contemporary browsers
// support both. However, this alias has wider browser support (Chrome
// >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
// we include it anyway.
checkVisibilityCSS: !0
});
return !i;
}
if (getComputedStyle(e).visibility === "hidden")
return !0;
var u = X.call(e, "details>summary:first-of-type"), a = u ? e.parentElement : e;
if (X.call(a, "details:not([open]) *"))
return !0;
if (!r || r === "full" || // full-native can run this branch when it falls through in case
// Element#checkVisibility is unsupported
r === "full-native" || r === "legacy-full") {
if (typeof o == "function") {
for (var f = e; e; ) {
var d = e.parentElement, m = oe(e);
if (d && !d.shadowRoot && o(d) === !0)
return Pe(e);
e.assignedSlot ? e = e.assignedSlot : !d && m !== e.ownerDocument ? e = m.host : e = d;
}
e = f;
}
if (ht(e))
return !e.getClientRects().length;
if (r !== "legacy-full")
return !0;
} else if (r === "non-zero-area")
return Pe(e);
return !1;
}, Et = function(e) {
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))
for (var n = e.parentElement; n; ) {
if (n.tagName === "FIELDSET" && n.disabled) {
for (var r = 0; r < n.children.length; r++) {
var o = n.children.item(r);
if (o.tagName === "LEGEND")
return X.call(n, "fieldset[disabled] *") ? !0 : !o.contains(e);
}
return !0;
}
n = n.parentElement;
}
return !1;
}, Rt = function(e, n) {
return !(n.disabled || dt(n) || yt(n, e) || // For a details element with a summary, the summary element gets the focus
vt(n) || Et(n));
}, Fe = function(e, n) {
return !(gt(n) || je(n) < 0 || !Rt(e, n));
}, wt = function(e) {
var n = parseInt(e.getAttribute("tabindex"), 10);
return !!(isNaN(n) || n >= 0);
}, _e = function(e) {
var n = [], r = [];
return e.forEach(function(o, i) {
var u = !!o.scopeParent, a = u ? o.scopeParent : o, f = ct(a, u), d = u ? _e(o.candidates) : a;
f === 0 ? u ? n.push.apply(n, d) : n.push(a) : r.push({
documentOrder: i,
tabIndex: f,
item: o,
isScope: u,
content: d
});
}), r.sort(ft).reduce(function(o, i) {
return i.isScope ? o.push.apply(o, i.content) : o.push(i.content), o;
}, []).concat(n);
}, ue = function(e, n) {
n = n || {};
var r;
return n.getShadowRoot ? r = ye([e], n.includeContainer, {
filter: Fe.bind(null, n),
flatten: !1,
getShadowRoot: n.getShadowRoot,
shadowRootFilter: wt
}) : r = lt(e, n.includeContainer, Fe.bind(null, n)), _e(r);
}, q = typeof document < "u" ? Ve : Ke;
let ve = !1, St = 0;
const Oe = () => "floating-ui-" + St++;
function xt() {
const [t, e] = s.useState(() => ve ? Oe() : void 0);
return q(() => {
t == null && e(Oe());
}, []), s.useEffect(() => {
ve || (ve = !0);
}, []), t;
}
const Tt = s.useId, Ee = Tt || xt;
function Ct() {
const t = /* @__PURE__ */ new Map();
return {
emit(e, n) {
var r;
(r = t.get(e)) == null || r.forEach((o) => o(n));
},
on(e, n) {
t.set(e, [...t.get(e) || [], n]);
},
off(e, n) {
t.set(e, (t.get(e) || []).filter((r) => r !== n));
}
};
}
const It = /* @__PURE__ */ s.createContext(null), At = /* @__PURE__ */ s.createContext(null), Pt = () => {
var t;
return ((t = s.useContext(It)) == null ? void 0 : t.id) || null;
}, Se = () => s.useContext(At);
function G(t) {
return (t == null ? void 0 : t.ownerDocument) || document;
}
function Ue() {
const t = navigator.userAgentData;
return t != null && t.platform ? t.platform : navigator.platform;
}
function Ft() {
const t = navigator.userAgentData;
return t && Array.isArray(t.brands) ? t.brands.map((e) => {
let {
brand: n,
version: r
} = e;
return n + "/" + r;
}).join(" ") : navigator.userAgent;
}
function xe(t) {
return G(t).defaultView || window;
}
function H(t) {
return t ? t instanceof xe(t).Element : !1;
}
function Z(t) {
return t ? t instanceof xe(t).HTMLElement : !1;
}
function Ot(t) {
if (typeof ShadowRoot > "u")
return !1;
const e = xe(t).ShadowRoot;
return t instanceof e || t instanceof ShadowRoot;
}
function Dt(t) {
if (t.mozInputSource === 0 && t.isTrusted)
return !0;
const e = /Android/i;
return (e.test(Ue()) || e.test(Ft())) && t.pointerType ? t.type === "click" && t.buttons === 1 : t.detail === 0 && !t.pointerType;
}
function Mt(t) {
return t.width === 0 && t.height === 0 || t.width === 1 && t.height === 1 && t.pressure === 0 && t.detail === 0 && t.pointerType !== "mouse" || // iOS VoiceOver returns 0.333• for width/height.
t.width < 1 && t.height < 1 && t.pressure === 0 && t.detail === 0;
}
function De() {
return /apple/i.test(navigator.vendor);
}
function kt() {
return Ue().toLowerCase().startsWith("mac") && !navigator.maxTouchPoints;
}
function Me(t, e) {
return ["mouse", "pen"].includes(t);
}
function $(t, e) {
if (!t || !e)
return !1;
const n = e.getRootNode && e.getRootNode();
if (t.contains(e))
return !0;
if (n && Ot(n)) {
let r = e;
do {
if (r && t === r)
return !0;
r = r.parentNode || r.host;
} while (r);
}
return !1;
}
function ne(t, e) {
let n = t.filter((o) => {
var i;
return o.parentId === e && ((i = o.context) == null ? void 0 : i.open);
}) || [], r = n;
for (; r.length; )
r = t.filter((o) => {
var i;
return (i = r) == null ? void 0 : i.some((u) => {
var a;
return o.parentId === u.id && ((a = o.context) == null ? void 0 : a.open);
});
}) || [], n = n.concat(r);
return n;
}
function ze(t) {
return "composedPath" in t ? t.composedPath()[0] : t.target;
}
function Nt(t) {
const e = tt(t);
return q(() => {
e.current = t;
}), e;
}
function se() {
return se = Object.assign || function(t) {
for (var e = 1; e < arguments.length; e++) {
var n = arguments[e];
for (var r in n)
Object.prototype.hasOwnProperty.call(n, r) && (t[r] = n[r]);
}
return t;
}, se.apply(this, arguments);
}
function Re(t) {
let e = t.activeElement;
for (; ((n = e) == null || (r = n.shadowRoot) == null ? void 0 : r.activeElement) != null; ) {
var n, r;
e = e.shadowRoot.activeElement;
}
return e;
}
let ke = 0;
function j(t, e) {
e === void 0 && (e = {});
const {
preventScroll: n = !1,
cancelPrevious: r = !0,
sync: o = !1
} = e;
r && cancelAnimationFrame(ke);
const i = () => t == null ? void 0 : t.focus({
preventScroll: n
});
o ? i() : ke = requestAnimationFrame(i);
}
function Lt(t, e) {
var n;
let r = [], o = (n = t.find((i) => i.id === e)) == null ? void 0 : n.parentId;
for (; o; ) {
const i = t.find((u) => u.id === o);
o = i == null ? void 0 : i.parentId, i && (r = r.concat(i));
}
return r;
}
const Bt = "input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
function Ge(t) {
return Z(t) && t.matches(Bt);
}
function pe(t) {
t.preventDefault(), t.stopPropagation();
}
const ae = () => ({
getShadowRoot: !0,
displayCheck: (
// JSDOM does not support the `tabbable` library. To solve this we can
// check if `ResizeObserver` is a real function (not polyfilled), which
// determines if the current environment is JSDOM-like.
typeof ResizeObserver == "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
)
});
function Ye(t, e) {
const n = ue(t, ae());
e === "prev" && n.reverse();
const r = n.indexOf(Re(G(t)));
return n.slice(r + 1)[0];
}
function Xe() {
return Ye(document.body, "next");
}
function Ze() {
return Ye(document.body, "prev");
}
function Y(t, e) {
const n = e || t.currentTarget, r = t.relatedTarget;
return !r || !$(n, r);
}
function Vt(t) {
ue(t, ae()).forEach((n) => {
n.dataset.tabindex = n.getAttribute("tabindex") || "", n.setAttribute("tabindex", "-1");
});
}
function Kt(t) {
t.querySelectorAll("[data-tabindex]").forEach((n) => {
const r = n.dataset.tabindex;
delete n.dataset.tabindex, r ? n.setAttribute("tabindex", r) : n.removeAttribute("tabindex");
});
}
const Wt = s.useInsertionEffect, $t = Wt || ((t) => t());
function Te(t) {
const e = s.useRef(() => {
if (process.env.NODE_ENV !== "production")
throw new Error("Cannot call an event handler while rendering.");
});
return $t(() => {
e.current = t;
}), s.useCallback(function() {
for (var n = arguments.length, r = new Array(n), o = 0; o < n; o++)
r[o] = arguments[o];
return e.current == null ? void 0 : e.current(...r);
}, []);
}
const Ce = {
border: 0,
clip: "rect(0 0 0 0)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: 0,
position: "fixed",
whiteSpace: "nowrap",
width: "1px",
top: 0,
left: 0
};
let we, Ie;
function Ne(t) {
t.key === "Tab" && (we = t.target, clearTimeout(Ie));
}
function qt(t) {
const e = we === t.relatedTarget;
return we = t.relatedTarget, clearTimeout(Ie), e;
}
const le = /* @__PURE__ */ s.forwardRef(function(e, n) {
const r = Te(e.onFocus), [o, i] = s.useState();
return q(() => (De() && i("button"), document.addEventListener("keydown", Ne), () => {
document.removeEventListener("keydown", Ne);
}), []), /* @__PURE__ */ s.createElement("span", se({}, e, {
ref: n,
tabIndex: 0,
role: o,
"aria-hidden": o ? void 0 : !0,
"data-floating-ui-focus-guard": "",
style: Ce,
onFocus: (u) => {
De() && kt() && !qt(u) ? (u.persist(), Ie = window.setTimeout(() => {
r(u);
}, 50)) : r(u);
}
}));
}), Je = /* @__PURE__ */ s.createContext(null), jt = function(t) {
let {
id: e,
enabled: n = !0
} = t === void 0 ? {} : t;
const [r, o] = s.useState(null), i = Ee(), u = Qe();
return q(() => {
if (!n)
return;
const a = e ? document.getElementById(e) : null;
if (a)
a.setAttribute("data-floating-ui-portal", ""), o(a);
else {
const f = document.createElement("div");
f.id = e || i, f.setAttribute("data-floating-ui-portal", ""), o(f);
const d = (u == null ? void 0 : u.portalNode) || document.body;
return d.appendChild(f), () => {
d.removeChild(f);
};
}
}, [e, u, i, n]), r;
}, Zt = (t) => {
let {
children: e,
id: n,
root: r = null,
preserveTabOrder: o = !0
} = t;
const i = jt({
id: n,
enabled: !r
}), [u, a] = s.useState(null), f = s.useRef(null), d = s.useRef(null), m = s.useRef(null), c = s.useRef(null), l = (
// The FocusManager and therefore floating element are currently open/
// rendered.
!!u && // Guards are only for non-modal focus management.
!u.modal && !!(r || i) && o
);
return s.useEffect(() => {
if (!i || !o || u != null && u.modal)
return;
function p(w) {
i && Y(w) && (w.type === "focusin" ? Kt : Vt)(i);
}
return i.addEventListener("focusin", p, !0), i.addEventListener("focusout", p, !0), () => {
i.removeEventListener("focusin", p, !0), i.removeEventListener("focusout", p, !0);
};
}, [i, o, u == null ? void 0 : u.modal]), /* @__PURE__ */ s.createElement(Je.Provider, {
value: s.useMemo(() => ({
preserveTabOrder: o,
beforeOutsideRef: f,
afterOutsideRef: d,
beforeInsideRef: m,
afterInsideRef: c,
portalNode: i,
setFocusManagerState: a
}), [o, i])
}, l && i && /* @__PURE__ */ s.createElement(le, {
ref: f,
onFocus: (p) => {
if (Y(p, i)) {
var w;
(w = m.current) == null || w.focus();
} else {
const b = Ze() || (u == null ? void 0 : u.refs.domReference.current);
b == null || b.focus();
}
}
}), l && i && /* @__PURE__ */ s.createElement("span", {
"aria-owns": i.id,
style: Ce
}), r ? /* @__PURE__ */ ge.createPortal(e, r) : i ? /* @__PURE__ */ ge.createPortal(e, i) : null, l && i && /* @__PURE__ */ s.createElement(le, {
ref: d,
onFocus: (p) => {
if (Y(p, i)) {
var w;
(w = c.current) == null || w.focus();
} else {
const b = Xe() || (u == null ? void 0 : u.refs.domReference.current);
b == null || b.focus(), u != null && u.closeOnFocusOut && (u == null || u.onOpenChange(!1));
}
}
}));
}, Qe = () => s.useContext(Je), Ht = /* @__PURE__ */ s.forwardRef(function(e, n) {
return /* @__PURE__ */ s.createElement("button", se({}, e, {
ref: n,
tabIndex: -1,
style: Ce
}));
});
function Jt(t) {
let {
context: e,
children: n,
order: r = ["content"],
guards: o = !0,
initialFocus: i = 0,
returnFocus: u = !0,
modal: a = !0,
visuallyHiddenDismiss: f = !1,
closeOnFocusOut: d = !0
} = t;
const {
refs: m,
nodeId: c,
onOpenChange: l,
events: p,
dataRef: w,
elements: {
domReference: b,
floating: v
}
} = e, g = Nt(r), I = Se(), E = Qe(), [F, N] = s.useState(null), O = typeof i == "number" && i < 0, K = s.useRef(null), W = s.useRef(null), V = s.useRef(!1), T = s.useRef(null), D = s.useRef(!1), A = E != null, S = b && b.getAttribute("role") === "combobox" && Ge(b), L = s.useCallback(function(h) {
return h === void 0 && (h = v), h ? ue(h, ae()) : [];
}, [v]), C = s.useCallback((h) => {
const R = L(h);
return g.current.map((y) => b && y === "reference" ? b : v && y === "floating" ? v : R).filter(Boolean).flat();
}, [b, v, g, L]);
s.useEffect(() => {
if (!a)
return;
function h(y) {
if (y.key === "Tab") {
L().length === 0 && !S && pe(y);
const x = C(), M = ze(y);
g.current[0] === "reference" && M === b && (pe(y), y.shiftKey ? j(x[x.length - 1]) : j(x[1])), g.current[1] === "floating" && M === v && y.shiftKey && (pe(y), j(x[0]));
}
}
const R = G(v);
return R.addEventListener("keydown", h), () => {
R.removeEventListener("keydown", h);
};
}, [b, v, a, g, m, S, L, C]), s.useEffect(() => {
if (!d)
return;
function h() {
D.current = !0, setTimeout(() => {
D.current = !1;
});
}
function R(y) {
const x = y.relatedTarget, M = !($(b, x) || $(v, x) || $(x, v) || $(E == null ? void 0 : E.portalNode, x) || x != null && x.hasAttribute("data-floating-ui-focus-guard") || I && (ne(I.nodesRef.current, c).find((P) => {
var k, B;
return $((k = P.context) == null ? void 0 : k.elements.floating, x) || $((B = P.context) == null ? void 0 : B.elements.domReference, x);
}) || Lt(I.nodesRef.current, c).find((P) => {
var k, B;
return ((k = P.context) == null ? void 0 : k.elements.floating) === x || ((B = P.context) == null ? void 0 : B.elements.domReference) === x;
})));
x && M && !D.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
x !== T.current && (V.current = !0, setTimeout(() => l(!1)));
}
if (v && Z(b))
return b.addEventListener("focusout", R), b.addEventListener("pointerdown", h), !a && v.addEventListener("focusout", R), () => {
b.removeEventListener("focusout", R), b.removeEventListener("pointerdown", h), !a && v.removeEventListener("focusout", R);
};
}, [b, v, a, c, I, E, l, d]), s.useEffect(() => {
var h;
const R = Array.from((E == null || (h = E.portalNode) == null ? void 0 : h.querySelectorAll("[data-floating-ui-portal]")) || []);
function y() {
return [K.current, W.current].filter(Boolean);
}
if (v && a) {
const x = [v, ...R, ...y()], M = ut(g.current.includes("reference") || S ? x.concat(b || []) : x);
return () => {
M();
};
}
}, [b, v, a, g, E, S]), s.useEffect(() => {
if (a && !o && v) {
const h = [], R = ae(), y = ue(G(v).body, R), x = C(), M = y.filter((P) => !x.includes(P));
return M.forEach((P, k) => {
h[k] = P.getAttribute("tabindex"), P.setAttribute("tabindex", "-1");
}), () => {
M.forEach((P, k) => {
const B = h[k];
B == null ? P.removeAttribute("tabindex") : P.setAttribute("tabindex", B);
});
};
}
}, [v, a, o, C]), q(() => {
if (!v) return;
const h = G(v);
let R = u, y = !1;
const x = Re(h), M = w.current;
T.current = x;
const P = C(v), k = (typeof i == "number" ? P[i] : i.current) || v;
!O && j(k, {
preventScroll: k === v
});
function B(U) {
if (U.type === "escapeKey" && m.domReference.current && (T.current = m.domReference.current), ["referencePress", "escapeKey"].includes(U.type))
return;
const ce = U.data.returnFocus;
typeof ce == "object" ? (R = !0, y = ce.preventScroll) : R = ce;
}
return p.on("dismiss", B), () => {
if (p.off("dismiss", B), $(v, Re(h)) && m.domReference.current && (T.current = m.domReference.current), R && Z(T.current) && !V.current)
if (!m.domReference.current || D.current)
j(T.current, {
// When dismissing nested floating elements, by the time the rAF has
// executed, the menus will all have been unmounted. When they try
// to get focused, the calls get ignored — leaving the root
// reference focused as desired.
cancelPrevious: !1,
preventScroll: y
});
else {
var U;
M.__syncReturnFocus = !0, (U = T.current) == null || U.focus({
preventScroll: y
}), setTimeout(() => {
delete M.__syncReturnFocus;
});
}
};
}, [v, C, i, u, w, m, p, O]), q(() => {
if (E)
return E.setFocusManagerState({
...e,
modal: a,
closeOnFocusOut: d
// Not concerned about the <RT> generic type.
}), () => {
E.setFocusManagerState(null);
};
}, [E, a, d, e]), q(() => {
if (O || !v) return;
function h() {
N(L().length);
}
if (h(), typeof MutationObserver == "function") {
const R = new MutationObserver(h);
return R.observe(v, {
childList: !0,
subtree: !0
}), () => {
R.disconnect();
};
}
}, [v, L, O, m]);
const J = o && (A || a) && !S;
function _(h) {
return f && a ? /* @__PURE__ */ s.createElement(Ht, {
ref: h === "start" ? K : W,
onClick: () => l(!1)
}, typeof f == "string" ? f : "Dismiss") : null;
}
return /* @__PURE__ */ s.createElement(s.Fragment, null, J && /* @__PURE__ */ s.createElement(le, {
ref: E == null ? void 0 : E.beforeInsideRef,
onFocus: (h) => {
if (a) {
const y = C();
j(r[0] === "reference" ? y[0] : y[y.length - 1]);
} else if (E != null && E.preserveTabOrder && E.portalNode)
if (V.current = !1, Y(h, E.portalNode)) {
const y = Xe() || b;
y == null || y.focus();
} else {
var R;
(R = E.beforeOutsideRef.current) == null || R.focus();
}
}
}), S ? null : _("start"), /* @__PURE__ */ s.cloneElement(n, F === 0 || r.includes("floating") ? {
tabIndex: 0
} : {}), _("end"), J && /* @__PURE__ */ s.createElement(le, {
ref: E == null ? void 0 : E.afterInsideRef,
onFocus: (h) => {
if (a)
j(C()[0]);
else if (E != null && E.preserveTabOrder && E.portalNode)
if (V.current = !0, Y(h, E.portalNode)) {
const y = Ze() || b;
y == null || y.focus();
} else {
var R;
(R = E.afterOutsideRef.current) == null || R.focus();
}
}
}));
}
function Le(t) {
return Z(t.target) && t.target.tagName === "BUTTON";
}
function Be(t) {
return Ge(t);
}
const Qt = function(t, e) {
let {
open: n,
onOpenChange: r,
dataRef: o,
refs: i
} = t, {
enabled: u = !0,
event: a = "click",
toggle: f = !0,
ignoreMouse: d = !1,
keyboardHandlers: m = !0
} = e === void 0 ? {} : e;
const c = s.useRef();
return s.useMemo(() => u ? {
reference: {
onPointerDown(l) {
c.current = l.pointerType;
},
onMouseDown(l) {
l.button === 0 && (Me(c.current) && d || a !== "click" && (n ? f && (!o.current.openEvent || o.current.openEvent.type === "mousedown") && r(!1) : (l.preventDefault(), r(!0)), o.current.openEvent = l.nativeEvent));
},
onClick(l) {
if (!o.current.__syncReturnFocus) {
if (a === "mousedown" && c.current) {
c.current = void 0;
return;
}
Me(c.current) && d || (n ? f && (!o.current.openEvent || o.current.openEvent.type === "click") && r(!1) : r(!0), o.current.openEvent = l.nativeEvent);
}
},
onKeyDown(l) {
c.current = void 0, m && (Le(l) || (l.key === " " && !Be(i.domReference.current) && l.preventDefault(), l.key === "Enter" && (n ? f && r(!1) : r(!0))));
},
onKeyUp(l) {
m && (Le(l) || Be(i.domReference.current) || l.key === " " && (n ? f && r(!1) : r(!0)));
}
}
} : {}, [u, o, a, d, m, i, f, n, r]);
};
function be(t, e) {
if (e == null)
return !1;
if ("composedPath" in t)
return t.composedPath().includes(e);
const n = t;
return n.target != null && e.contains(n.target);
}
const _t = {
pointerdown: "onPointerDown",
mousedown: "onMouseDown",
click: "onClick"
}, Ut = {
pointerdown: "onPointerDownCapture",
mousedown: "onMouseDownCapture",
click: "onClickCapture"
}, zt = function(t) {
var e, n;
return t === void 0 && (t = !0), {
escapeKeyBubbles: typeof t == "boolean" ? t : (e = t.escapeKey) != null ? e : !0,
outsidePressBubbles: typeof t == "boolean" ? t : (n = t.outsidePress) != null ? n : !0
};
}, en = function(t, e) {
let {
open: n,
onOpenChange: r,
events: o,
nodeId: i,
elements: {
reference: u,
domReference: a,
floating: f
}
} = t, {
enabled: d = !0,
escapeKey: m = !0,
outsidePress: c = !0,
outsidePressEvent: l = "pointerdown",
referencePress: p = !1,
referencePressEvent: w = "pointerdown",
ancestorScroll: b = !1,
bubbles: v = !0
} = {};
const g = Se(), I = Pt() != null, E = Te(typeof c == "function" ? c : () => !1), F = typeof c == "function" ? E : c, N = s.useRef(!1), {
escapeKeyBubbles: O,
outsidePressBubbles: K
} = zt(v);
return s.useEffect(() => {
if (!n || !d)
return;
function W(S) {
if (S.key === "Escape") {
if (!O && g && ne(g.nodesRef.current, i).length > 0)
return;
o.emit("dismiss", {
type: "escapeKey",
data: {
returnFocus: {
preventScroll: !1
}
}
}), r(!1);
}
}
function V(S) {
const L = N.current;
if (N.current = !1, L || typeof F == "function" && !F(S))
return;
const C = ze(S);
if (Z(C) && f) {
const _ = f.ownerDocument.defaultView || window, h = C.scrollWidth > C.clientWidth, R = C.scrollHeight > C.clientHeight;
let y = R && S.offsetX > C.clientWidth;
if (R && _.getComputedStyle(C).direction === "rtl" && (y = S.offsetX <= C.offsetWidth - C.clientWidth), y || h && S.offsetY > C.clientHeight)
return;
}
const J = g && ne(g.nodesRef.current, i).some((_) => {
var h;
return be(S, (h = _.context) == null ? void 0 : h.elements.floating);
});
be(S, f) || be(S, a) || J || !K && g && ne(g.nodesRef.current, i).length > 0 || (o.emit("dismiss", {
type: "outsidePress",
data: {
returnFocus: I ? {
preventScroll: !0
} : Dt(S) || Mt(S)
}
}), r(!1));
}
function T() {
r(!1);
}
const D = G(f);
m && D.addEventListener("keydown", W), F && D.addEventListener(l, V);
let A = [];
return b && (H(a) && (A = fe(a)), H(f) && (A = A.concat(fe(f))), !H(u) && u && u.contextElement && (A = A.concat(fe(u.contextElement)))), A = A.filter((S) => {
var L;
return S !== ((L = D.defaultView) == null ? void 0 : L.visualViewport);
}), A.forEach((S) => {
S.addEventListener("scroll", T, {
passive: !0
});
}), () => {
m && D.removeEventListener("keydown", W), F && D.removeEventListener(l, V), A.forEach((S) => {
S.removeEventListener("scroll", T);
});
};
}, [f, a, u, m, F, l, o, g, i, n, r, b, d, O, K, I]), s.useEffect(() => {
N.current = !1;
}, [F, l]), s.useMemo(() => d ? {
reference: {
[_t[w]]: () => {
p && (o.emit("dismiss", {
type: "referencePress",
data: {
returnFocus: !1
}
}), r(!1));
}
},
floating: {
[Ut[l]]: () => {
N.current = !0;
}
}
} : {}, [d, o, p, l, w, r]);
};
function tn(t) {
return s.useMemo(() => t.every((e) => e == null) ? null : (e) => {
t.forEach((n) => {
typeof n == "function" ? n(e) : n != null && (n.current = e);
});
}, t);
}
const nn = function(t, e) {
let {
open: n
} = t, {
enabled: r = !0,
role: o = "dialog"
} = {};
const i = Ee(), u = Ee();
return s.useMemo(() => {
const a = {
id: i,
role: o
};
return r ? o === "tooltip" ? {
reference: {
"aria-describedby": n ? i : void 0
},
floating: a
} : {
reference: {
"aria-expanded": n ? "true" : "false",
"aria-haspopup": o === "alertdialog" ? "dialog" : o,
"aria-controls": n ? i : void 0,
...o === "listbox" && {
role: "combobox"
},
...o === "menu" && {
id: u
}
},
floating: {
...a,
...o === "menu" && {
"aria-labelledby": u
}
}
} : {};
}, [r, o, n, i, u]);
};
function rn(t) {
t === void 0 && (t = {});
const {
open: e = !1,
onOpenChange: n,
nodeId: r
} = t, o = nt(t), i = Se(), u = s.useRef(null), a = s.useRef({}), f = s.useState(() => Ct())[0], [d, m] = s.useState(null), c = s.useCallback((g) => {
const I = H(g) ? {
getBoundingClientRect: () => g.getBoundingClientRect(),
contextElement: g
} : g;
o.refs.setReference(I);
}, [o.refs]), l = s.useCallback((g) => {
(H(g) || g === null) && (u.current = g, m(g)), (H(o.refs.reference.current) || o.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
// `null` to support `positionReference` + an unstable `reference`
// callback ref.
g !== null && !H(g)) && o.refs.setReference(g);
}, [o.refs]), p = s.useMemo(() => ({
...o.refs,
setReference: l,
setPositionReference: c,
domReference: u
}), [o.refs, l, c]), w = s.useMemo(() => ({
...o.elements,
domReference: d
}), [o.elements, d]), b = Te(n), v = s.useMemo(() => ({
...o,
refs: p,
elements: w,
dataRef: a,
nodeId: r,
events: f,
open: e,
onOpenChange: b
}), [o, r, f, e, b, p, w]);
return q(() => {
const g = i == null ? void 0 : i.nodesRef.current.find((I) => I.id === r);
g && (g.context = v);
}), s.useMemo(() => ({
...o,
context: v,
refs: p,
reference: l,
positionReference: c
}), [o, p, v, l, c]);
}
function me(t, e, n) {
const r = /* @__PURE__ */ new Map();
return {
...n === "floating" && {
tabIndex: -1
},
...t,
...e.map((o) => o ? o[n] : null).concat(t).reduce((o, i) => (i && Object.entries(i).forEach((u) => {
let [a, f] = u;
if (a.indexOf("on") === 0) {
if (r.has(a) || r.set(a, []), typeof f == "function") {
var d;
(d = r.get(a)) == null || d.push(f), o[a] = function() {
for (var m, c = arguments.length, l = new Array(c), p = 0; p < c; p++)
l[p] = arguments[p];
(m = r.get(a)) == null || m.forEach((w) => w(...l));
};
}
} else
o[a] = f;
}), o), {})
};
}
const on = function(t) {
t === void 0 && (t = []);
const e = t, n = s.useCallback(
(i) => me(i, t, "reference"),
// eslint-disable-next-line react-hooks/exhaustive-deps
e
), r = s.useCallback(
(i) => me(i, t, "floating"),
// eslint-disable-next-line react-hooks/exhaustive-deps
e
), o = s.useCallback(
(i) => me(i, t, "item"),
// eslint-disable-next-line react-hooks/exhaustive-deps
e
);
return s.useMemo(() => ({
getReferenceProps: n,
getFloatingProps: r,
getItemProps: o
}), [n, r, o]);
};
export {
Zt as F,
tn as a,
Jt as b,
rn as c,
Qt as d,
en as e,
nn as f,
on as g,
Ee as u
};