@lanaco/lnc-react-ui
Version:
React component library
1,199 lines (1,198 loc) • 38.4 kB
JavaScript
import { c as Je, g as fe } from "./floating-ui.dom-vNhdy5RI.js";
import * as s from "react";
import { useLayoutEffect as Be, useEffect as Ke, useRef as Qe } from "react";
import { r as ge } from "./index-64mXPFBC.js";
var te = typeof document < "u" ? Be : Ke;
function re(e, t) {
if (e === t)
return !0;
if (typeof e != typeof t)
return !1;
if (typeof e == "function" && e.toString() === t.toString())
return !0;
let n, r, o;
if (e && t && typeof e == "object") {
if (Array.isArray(e)) {
if (n = e.length, n != t.length) return !1;
for (r = n; r-- !== 0; )
if (!re(e[r], t[r]))
return !1;
return !0;
}
if (o = Object.keys(e), n = o.length, n !== Object.keys(t).length)
return !1;
for (r = n; r-- !== 0; )
if (!Object.prototype.hasOwnProperty.call(t, o[r]))
return !1;
for (r = n; r-- !== 0; ) {
const i = o[r];
if (!(i === "_owner" && e.$$typeof) && !re(e[i], t[i]))
return !1;
}
return !0;
}
return e !== e && t !== t;
}
function Ie(e) {
const t = s.useRef(e);
return te(() => {
t.current = e;
}), t;
}
function et(e) {
e === void 0 && (e = {});
const {
placement: t = "bottom",
strategy: n = "absolute",
middleware: r = [],
platform: o,
whileElementsMounted: i,
open: u
} = e, [a, f] = s.useState({
x: null,
y: null,
strategy: n,
placement: t,
middlewareData: {},
isPositioned: !1
}), [v, m] = s.useState(r);
re(v, r) || m(r);
const c = s.useRef(null), l = s.useRef(null), p = s.useRef(a), w = Ie(i), b = Ie(o), [d, g] = s.useState(null), [I, E] = s.useState(null), F = s.useCallback((T) => {
c.current !== T && (c.current = T, g(T));
}, []), k = s.useCallback((T) => {
l.current !== T && (l.current = T, E(T));
}, []), O = s.useCallback(() => {
if (!c.current || !l.current)
return;
const T = {
placement: t,
strategy: n,
middleware: v
};
b.current && (T.platform = b.current), Je(c.current, l.current, T).then((D) => {
const A = {
...D,
isPositioned: !0
};
V.current && !re(p.current, A) && (p.current = A, ge.flushSync(() => {
f(A);
}));
});
}, [v, t, n, b]);
te(() => {
u === !1 && p.current.isPositioned && (p.current.isPositioned = !1, f((T) => ({
...T,
isPositioned: !1
})));
}, [u]);
const V = s.useRef(!1);
te(() => (V.current = !0, () => {
V.current = !1;
}), []), te(() => {
if (d && I) {
if (w.current)
return w.current(d, I, O);
O();
}
}, [d, I, O, w]);
const W = s.useMemo(() => ({
reference: c,
floating: l,
setReference: F,
setFloating: k
}), [F, k]), K = s.useMemo(() => ({
reference: d,
floating: I
}), [d, I]);
return s.useMemo(() => ({
...a,
update: O,
refs: W,
elements: K,
reference: F,
floating: k
}), [a, O, W, K, F, k]);
}
var tt = function(e) {
if (typeof document > "u")
return null;
var t = Array.isArray(e) ? e[0] : e;
return t.ownerDocument.body;
}, z = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), ee = {}, de = 0, Ve = function(e) {
return e && (e.host || Ve(e.parentNode));
}, nt = function(e, t) {
return t.map(function(n) {
if (e.contains(n))
return n;
var r = Ve(n);
return r && e.contains(r) ? r : (console.error("aria-hidden", n, "in not contained inside", e, ". Doing nothing"), null);
}).filter(function(n) {
return !!n;
});
}, rt = function(e, t, n, r) {
var o = nt(t, Array.isArray(e) ? e : [e]);
ee[n] || (ee[n] = /* @__PURE__ */ new WeakMap());
var i = ee[n], u = [], a = /* @__PURE__ */ new Set(), f = new Set(o), v = function(c) {
!c || a.has(c) || (a.add(c), v(c.parentNode));
};
o.forEach(v);
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, d = (i.get(l) || 0) + 1;
z.set(l, b), i.set(l, d), u.push(l), b === 1 && w && Q.set(l, !0), d === 1 && l.setAttribute(n, "true"), w || l.setAttribute(r, "true");
} catch (g) {
console.error("aria-hidden: cannot operate on ", l, g);
}
});
};
return m(t), 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 = {});
};
}, ot = function(e, t, n) {
n === void 0 && (n = "data-aria-hidden");
var r = Array.from(Array.isArray(e) ? e : [e]), o = tt(e);
return o ? (r.push.apply(r, Array.from(o.querySelectorAll("[aria-live], script"))), rt(r, o, n, "aria-hidden")) : function() {
return null;
};
};
/*!
* tabbable 6.2.0
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*/
var it = ["input:not([inert])", "select:not([inert])", "textarea:not([inert])", "a[href]:not([inert])", "button:not([inert])", "[tabindex]:not(slot):not([inert])", "audio[controls]:not([inert])", "video[controls]:not([inert])", '[contenteditable]:not([contenteditable="false"]):not([inert])', "details>summary:first-of-type:not([inert])", "details:not([inert])"], he = /* @__PURE__ */ it.join(","), We = typeof Element > "u", X = We ? function() {
} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector, oe = !We && Element.prototype.getRootNode ? function(e) {
var t;
return e == null || (t = e.getRootNode) === null || t === void 0 ? void 0 : t.call(e);
} : function(e) {
return e == null ? void 0 : e.ownerDocument;
}, ie = function e(t, n) {
var r;
n === void 0 && (n = !0);
var o = t == null || (r = t.getAttribute) === null || r === void 0 ? void 0 : r.call(t, "inert"), i = o === "" || o === "true", u = i || n && t && e(t.parentNode);
return u;
}, ut = function(t) {
var n, r = t == null || (n = t.getAttribute) === null || n === void 0 ? void 0 : n.call(t, "contenteditable");
return r === "" || r === "true";
}, st = function(t, n, r) {
if (ie(t))
return [];
var o = Array.prototype.slice.apply(t.querySelectorAll(he));
return n && X.call(t, he) && o.unshift(t), o = o.filter(r), o;
}, at = function e(t, n, r) {
for (var o = [], i = Array.from(t); i.length; ) {
var u = i.shift();
if (!ie(u, !1))
if (u.tagName === "SLOT") {
var a = u.assignedElements(), f = a.length ? a : u.children, v = e(f, !0, r);
r.flatten ? o.push.apply(o, v) : o.push({
scopeParent: u,
candidates: v
});
} else {
var m = X.call(u, he);
m && r.filter(u) && (n || !t.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 = e(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;
}, $e = function(t) {
return !isNaN(parseInt(t.getAttribute("tabindex"), 10));
}, qe = function(t) {
if (!t)
throw new Error("No node provided");
return t.tabIndex < 0 && (/^(AUDIO|VIDEO|DETAILS)$/.test(t.tagName) || ut(t)) && !$e(t) ? 0 : t.tabIndex;
}, lt = function(t, n) {
var r = qe(t);
return r < 0 && n && !$e(t) ? 0 : r;
}, ct = function(t, n) {
return t.tabIndex === n.tabIndex ? t.documentOrder - n.documentOrder : t.tabIndex - n.tabIndex;
}, je = function(t) {
return t.tagName === "INPUT";
}, ft = function(t) {
return je(t) && t.type === "hidden";
}, dt = function(t) {
var n = t.tagName === "DETAILS" && Array.prototype.slice.apply(t.children).some(function(r) {
return r.tagName === "SUMMARY";
});
return n;
}, vt = function(t, n) {
for (var r = 0; r < t.length; r++)
if (t[r].checked && t[r].form === n)
return t[r];
}, pt = function(t) {
if (!t.name)
return !0;
var n = t.form || oe(t), 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(t.name));
else
try {
o = r(t.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 = vt(o, t.form);
return !i || i === t;
}, bt = function(t) {
return je(t) && t.type === "radio";
}, mt = function(t) {
return bt(t) && !pt(t);
}, gt = function(t) {
var n, r = t && oe(t), o = (n = r) === null || n === void 0 ? void 0 : n.host, i = !1;
if (r && r !== t) {
var u, a, f;
for (i = !!((u = o) !== null && u !== void 0 && (a = u.ownerDocument) !== null && a !== void 0 && a.contains(o) || t != null && (f = t.ownerDocument) !== null && f !== void 0 && f.contains(t)); !i && o; ) {
var v, m, c;
r = oe(o), o = (v = r) === null || v === void 0 ? void 0 : v.host, i = !!((m = o) !== null && m !== void 0 && (c = m.ownerDocument) !== null && c !== void 0 && c.contains(o));
}
}
return i;
}, Ae = function(t) {
var n = t.getBoundingClientRect(), r = n.width, o = n.height;
return r === 0 && o === 0;
}, ht = function(t, n) {
var r = n.displayCheck, o = n.getShadowRoot;
if (getComputedStyle(t).visibility === "hidden")
return !0;
var i = X.call(t, "details>summary:first-of-type"), u = i ? t.parentElement : t;
if (X.call(u, "details:not([open]) *"))
return !0;
if (!r || r === "full" || r === "legacy-full") {
if (typeof o == "function") {
for (var a = t; t; ) {
var f = t.parentElement, v = oe(t);
if (f && !f.shadowRoot && o(f) === !0)
return Ae(t);
t.assignedSlot ? t = t.assignedSlot : !f && v !== t.ownerDocument ? t = v.host : t = f;
}
t = a;
}
if (gt(t))
return !t.getClientRects().length;
if (r !== "legacy-full")
return !0;
} else if (r === "non-zero-area")
return Ae(t);
return !1;
}, yt = function(t) {
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(t.tagName))
for (var n = t.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(t);
}
return !0;
}
n = n.parentElement;
}
return !1;
}, Et = function(t, n) {
return !(n.disabled || // we must do an inert look up to filter out any elements inside an inert ancestor
// because we're limited in the type of selectors we can use in JSDom (see related
// note related to `candidateSelectors`)
ie(n) || ft(n) || ht(n, t) || // For a details element with a summary, the summary element gets the focus
dt(n) || yt(n));
}, Pe = function(t, n) {
return !(mt(n) || qe(n) < 0 || !Et(t, n));
}, Rt = function(t) {
var n = parseInt(t.getAttribute("tabindex"), 10);
return !!(isNaN(n) || n >= 0);
}, wt = function e(t) {
var n = [], r = [];
return t.forEach(function(o, i) {
var u = !!o.scopeParent, a = u ? o.scopeParent : o, f = lt(a, u), v = u ? e(o.candidates) : a;
f === 0 ? u ? n.push.apply(n, v) : n.push(a) : r.push({
documentOrder: i,
tabIndex: f,
item: o,
isScope: u,
content: v
});
}), r.sort(ct).reduce(function(o, i) {
return i.isScope ? o.push.apply(o, i.content) : o.push(i.content), o;
}, []).concat(n);
}, ue = function(t, n) {
n = n || {};
var r;
return n.getShadowRoot ? r = at([t], n.includeContainer, {
filter: Pe.bind(null, n),
flatten: !1,
getShadowRoot: n.getShadowRoot,
shadowRootFilter: Rt
}) : r = st(t, n.includeContainer, Pe.bind(null, n)), wt(r);
}, q = typeof document < "u" ? Be : Ke;
let ve = !1, St = 0;
const Fe = () => "floating-ui-" + St++;
function xt() {
const [e, t] = s.useState(() => ve ? Fe() : void 0);
return q(() => {
e == null && t(Fe());
}, []), s.useEffect(() => {
ve || (ve = !0);
}, []), e;
}
const Tt = s.useId, ye = Tt || xt;
function Ct() {
const e = /* @__PURE__ */ new Map();
return {
emit(t, n) {
var r;
(r = e.get(t)) == null || r.forEach((o) => o(n));
},
on(t, n) {
e.set(t, [...e.get(t) || [], n]);
},
off(t, n) {
e.set(t, (e.get(t) || []).filter((r) => r !== n));
}
};
}
const It = /* @__PURE__ */ s.createContext(null), At = /* @__PURE__ */ s.createContext(null), Pt = () => {
var e;
return ((e = s.useContext(It)) == null ? void 0 : e.id) || null;
}, we = () => s.useContext(At);
function G(e) {
return (e == null ? void 0 : e.ownerDocument) || document;
}
function He() {
const e = navigator.userAgentData;
return e != null && e.platform ? e.platform : navigator.platform;
}
function Ft() {
const e = navigator.userAgentData;
return e && Array.isArray(e.brands) ? e.brands.map((t) => {
let {
brand: n,
version: r
} = t;
return n + "/" + r;
}).join(" ") : navigator.userAgent;
}
function Se(e) {
return G(e).defaultView || window;
}
function H(e) {
return e ? e instanceof Se(e).Element : !1;
}
function Z(e) {
return e ? e instanceof Se(e).HTMLElement : !1;
}
function Ot(e) {
if (typeof ShadowRoot > "u")
return !1;
const t = Se(e).ShadowRoot;
return e instanceof t || e instanceof ShadowRoot;
}
function Dt(e) {
if (e.mozInputSource === 0 && e.isTrusted)
return !0;
const t = /Android/i;
return (t.test(He()) || t.test(Ft())) && e.pointerType ? e.type === "click" && e.buttons === 1 : e.detail === 0 && !e.pointerType;
}
function Mt(e) {
return e.width === 0 && e.height === 0 || e.width === 1 && e.height === 1 && e.pressure === 0 && e.detail === 0 && e.pointerType !== "mouse" || // iOS VoiceOver returns 0.333• for width/height.
e.width < 1 && e.height < 1 && e.pressure === 0 && e.detail === 0;
}
function Oe() {
return /apple/i.test(navigator.vendor);
}
function Nt() {
return He().toLowerCase().startsWith("mac") && !navigator.maxTouchPoints;
}
function De(e, t) {
return ["mouse", "pen"].includes(e);
}
function $(e, t) {
if (!e || !t)
return !1;
const n = t.getRootNode && t.getRootNode();
if (e.contains(t))
return !0;
if (n && Ot(n)) {
let r = t;
do {
if (r && e === r)
return !0;
r = r.parentNode || r.host;
} while (r);
}
return !1;
}
function ne(e, t) {
let n = e.filter((o) => {
var i;
return o.parentId === t && ((i = o.context) == null ? void 0 : i.open);
}) || [], r = n;
for (; r.length; )
r = e.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 Ue(e) {
return "composedPath" in e ? e.composedPath()[0] : e.target;
}
function kt(e) {
const t = Qe(e);
return q(() => {
t.current = e;
}), t;
}
function se() {
return se = Object.assign || function(e) {
for (var t = 1; t < arguments.length; t++) {
var n = arguments[t];
for (var r in n)
Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
}
return e;
}, se.apply(this, arguments);
}
function Ee(e) {
let t = e.activeElement;
for (; ((n = t) == null || (r = n.shadowRoot) == null ? void 0 : r.activeElement) != null; ) {
var n, r;
t = t.shadowRoot.activeElement;
}
return t;
}
let Me = 0;
function j(e, t) {
t === void 0 && (t = {});
const {
preventScroll: n = !1,
cancelPrevious: r = !0,
sync: o = !1
} = t;
r && cancelAnimationFrame(Me);
const i = () => e == null ? void 0 : e.focus({
preventScroll: n
});
o ? i() : Me = requestAnimationFrame(i);
}
function Lt(e, t) {
var n;
let r = [], o = (n = e.find((i) => i.id === t)) == null ? void 0 : n.parentId;
for (; o; ) {
const i = e.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 _e(e) {
return Z(e) && e.matches(Bt);
}
function pe(e) {
e.preventDefault(), e.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 ze(e, t) {
const n = ue(e, ae());
t === "prev" && n.reverse();
const r = n.indexOf(Ee(G(e)));
return n.slice(r + 1)[0];
}
function Ge() {
return ze(document.body, "next");
}
function Ye() {
return ze(document.body, "prev");
}
function Y(e, t) {
const n = t || e.currentTarget, r = e.relatedTarget;
return !r || !$(n, r);
}
function Kt(e) {
ue(e, ae()).forEach((n) => {
n.dataset.tabindex = n.getAttribute("tabindex") || "", n.setAttribute("tabindex", "-1");
});
}
function Vt(e) {
e.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 || ((e) => e());
function xe(e) {
const t = s.useRef(() => {
if (process.env.NODE_ENV !== "production")
throw new Error("Cannot call an event handler while rendering.");
});
return $t(() => {
t.current = e;
}), s.useCallback(function() {
for (var n = arguments.length, r = new Array(n), o = 0; o < n; o++)
r[o] = arguments[o];
return t.current == null ? void 0 : t.current(...r);
}, []);
}
const Te = {
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 Re, Ce;
function Ne(e) {
e.key === "Tab" && (Re = e.target, clearTimeout(Ce));
}
function qt(e) {
const t = Re === e.relatedTarget;
return Re = e.relatedTarget, clearTimeout(Ce), t;
}
const le = /* @__PURE__ */ s.forwardRef(function(t, n) {
const r = xe(t.onFocus), [o, i] = s.useState();
return q(() => (Oe() && i("button"), document.addEventListener("keydown", Ne), () => {
document.removeEventListener("keydown", Ne);
}), []), /* @__PURE__ */ s.createElement("span", se({}, t, {
ref: n,
tabIndex: 0,
role: o,
"aria-hidden": o ? void 0 : !0,
"data-floating-ui-focus-guard": "",
style: Te,
onFocus: (u) => {
Oe() && Nt() && !qt(u) ? (u.persist(), Ce = window.setTimeout(() => {
r(u);
}, 50)) : r(u);
}
}));
}), Xe = /* @__PURE__ */ s.createContext(null), jt = function(e) {
let {
id: t,
enabled: n = !0
} = e === void 0 ? {} : e;
const [r, o] = s.useState(null), i = ye(), u = Ze();
return q(() => {
if (!n)
return;
const a = t ? document.getElementById(t) : null;
if (a)
a.setAttribute("data-floating-ui-portal", ""), o(a);
else {
const f = document.createElement("div");
f.id = t || i, f.setAttribute("data-floating-ui-portal", ""), o(f);
const v = (u == null ? void 0 : u.portalNode) || document.body;
return v.appendChild(f), () => {
v.removeChild(f);
};
}
}, [t, u, i, n]), r;
}, Zt = (e) => {
let {
children: t,
id: n,
root: r = null,
preserveTabOrder: o = !0
} = e;
const i = jt({
id: n,
enabled: !r
}), [u, a] = s.useState(null), f = s.useRef(null), v = 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" ? Vt : Kt)(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(Xe.Provider, {
value: s.useMemo(() => ({
preserveTabOrder: o,
beforeOutsideRef: f,
afterOutsideRef: v,
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 = Ye() || (u == null ? void 0 : u.refs.domReference.current);
b == null || b.focus();
}
}
}), l && i && /* @__PURE__ */ s.createElement("span", {
"aria-owns": i.id,
style: Te
}), r ? /* @__PURE__ */ ge.createPortal(t, r) : i ? /* @__PURE__ */ ge.createPortal(t, i) : null, l && i && /* @__PURE__ */ s.createElement(le, {
ref: v,
onFocus: (p) => {
if (Y(p, i)) {
var w;
(w = c.current) == null || w.focus();
} else {
const b = Ge() || (u == null ? void 0 : u.refs.domReference.current);
b == null || b.focus(), u != null && u.closeOnFocusOut && (u == null || u.onOpenChange(!1));
}
}
}));
}, Ze = () => s.useContext(Xe), Ht = /* @__PURE__ */ s.forwardRef(function(t, n) {
return /* @__PURE__ */ s.createElement("button", se({}, t, {
ref: n,
tabIndex: -1,
style: Te
}));
});
function Jt(e) {
let {
context: t,
children: n,
order: r = ["content"],
guards: o = !0,
initialFocus: i = 0,
returnFocus: u = !0,
modal: a = !0,
visuallyHiddenDismiss: f = !1,
closeOnFocusOut: v = !0
} = e;
const {
refs: m,
nodeId: c,
onOpenChange: l,
events: p,
dataRef: w,
elements: {
domReference: b,
floating: d
}
} = t, g = kt(r), I = we(), E = Ze(), [F, k] = s.useState(null), O = typeof i == "number" && i < 0, V = s.useRef(null), W = s.useRef(null), K = s.useRef(!1), T = s.useRef(null), D = s.useRef(!1), A = E != null, S = b && b.getAttribute("role") === "combobox" && _e(b), L = s.useCallback(function(h) {
return h === void 0 && (h = d), h ? ue(h, ae()) : [];
}, [d]), C = s.useCallback((h) => {
const R = L(h);
return g.current.map((y) => b && y === "reference" ? b : d && y === "floating" ? d : R).filter(Boolean).flat();
}, [b, d, g, L]);
s.useEffect(() => {
if (!a)
return;
function h(y) {
if (y.key === "Tab") {
L().length === 0 && !S && pe(y);
const x = C(), M = Ue(y);
g.current[0] === "reference" && M === b && (pe(y), y.shiftKey ? j(x[x.length - 1]) : j(x[1])), g.current[1] === "floating" && M === d && y.shiftKey && (pe(y), j(x[0]));
}
}
const R = G(d);
return R.addEventListener("keydown", h), () => {
R.removeEventListener("keydown", h);
};
}, [b, d, a, g, m, S, L, C]), s.useEffect(() => {
if (!v)
return;
function h() {
D.current = !0, setTimeout(() => {
D.current = !1;
});
}
function R(y) {
const x = y.relatedTarget, M = !($(b, x) || $(d, x) || $(x, d) || $(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 N, B;
return $((N = P.context) == null ? void 0 : N.elements.floating, x) || $((B = P.context) == null ? void 0 : B.elements.domReference, x);
}) || Lt(I.nodesRef.current, c).find((P) => {
var N, B;
return ((N = P.context) == null ? void 0 : N.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 && (K.current = !0, setTimeout(() => l(!1)));
}
if (d && Z(b))
return b.addEventListener("focusout", R), b.addEventListener("pointerdown", h), !a && d.addEventListener("focusout", R), () => {
b.removeEventListener("focusout", R), b.removeEventListener("pointerdown", h), !a && d.removeEventListener("focusout", R);
};
}, [b, d, a, c, I, E, l, v]), 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 [V.current, W.current].filter(Boolean);
}
if (d && a) {
const x = [d, ...R, ...y()], M = ot(g.current.includes("reference") || S ? x.concat(b || []) : x);
return () => {
M();
};
}
}, [b, d, a, g, E, S]), s.useEffect(() => {
if (a && !o && d) {
const h = [], R = ae(), y = ue(G(d).body, R), x = C(), M = y.filter((P) => !x.includes(P));
return M.forEach((P, N) => {
h[N] = P.getAttribute("tabindex"), P.setAttribute("tabindex", "-1");
}), () => {
M.forEach((P, N) => {
const B = h[N];
B == null ? P.removeAttribute("tabindex") : P.setAttribute("tabindex", B);
});
};
}
}, [d, a, o, C]), q(() => {
if (!d) return;
const h = G(d);
let R = u, y = !1;
const x = Ee(h), M = w.current;
T.current = x;
const P = C(d), N = (typeof i == "number" ? P[i] : i.current) || d;
!O && j(N, {
preventScroll: N === d
});
function B(_) {
if (_.type === "escapeKey" && m.domReference.current && (T.current = m.domReference.current), ["referencePress", "escapeKey"].includes(_.type))
return;
const ce = _.data.returnFocus;
typeof ce == "object" ? (R = !0, y = ce.preventScroll) : R = ce;
}
return p.on("dismiss", B), () => {
if (p.off("dismiss", B), $(d, Ee(h)) && m.domReference.current && (T.current = m.domReference.current), R && Z(T.current) && !K.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 _;
M.__syncReturnFocus = !0, (_ = T.current) == null || _.focus({
preventScroll: y
}), setTimeout(() => {
delete M.__syncReturnFocus;
});
}
};
}, [d, C, i, u, w, m, p, O]), q(() => {
if (E)
return E.setFocusManagerState({
...t,
modal: a,
closeOnFocusOut: v
// Not concerned about the <RT> generic type.
}), () => {
E.setFocusManagerState(null);
};
}, [E, a, v, t]), q(() => {
if (O || !d) return;
function h() {
k(L().length);
}
if (h(), typeof MutationObserver == "function") {
const R = new MutationObserver(h);
return R.observe(d, {
childList: !0,
subtree: !0
}), () => {
R.disconnect();
};
}
}, [d, L, O, m]);
const J = o && (A || a) && !S;
function U(h) {
return f && a ? /* @__PURE__ */ s.createElement(Ht, {
ref: h === "start" ? V : 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 (K.current = !1, Y(h, E.portalNode)) {
const y = Ge() || b;
y == null || y.focus();
} else {
var R;
(R = E.beforeOutsideRef.current) == null || R.focus();
}
}
}), S ? null : U("start"), /* @__PURE__ */ s.cloneElement(n, F === 0 || r.includes("floating") ? {
tabIndex: 0
} : {}), U("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 (K.current = !0, Y(h, E.portalNode)) {
const y = Ye() || b;
y == null || y.focus();
} else {
var R;
(R = E.afterOutsideRef.current) == null || R.focus();
}
}
}));
}
function ke(e) {
return Z(e.target) && e.target.tagName === "BUTTON";
}
function Le(e) {
return _e(e);
}
const Qt = function(e, t) {
let {
open: n,
onOpenChange: r,
dataRef: o,
refs: i
} = e, {
enabled: u = !0,
event: a = "click",
toggle: f = !0,
ignoreMouse: v = !1,
keyboardHandlers: m = !0
} = t === void 0 ? {} : t;
const c = s.useRef();
return s.useMemo(() => u ? {
reference: {
onPointerDown(l) {
c.current = l.pointerType;
},
onMouseDown(l) {
l.button === 0 && (De(c.current) && v || 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;
}
De(c.current) && v || (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 && (ke(l) || (l.key === " " && !Le(i.domReference.current) && l.preventDefault(), l.key === "Enter" && (n ? f && r(!1) : r(!0))));
},
onKeyUp(l) {
m && (ke(l) || Le(i.domReference.current) || l.key === " " && (n ? f && r(!1) : r(!0)));
}
}
} : {}, [u, o, a, v, m, i, f, n, r]);
};
function be(e, t) {
if (t == null)
return !1;
if ("composedPath" in e)
return e.composedPath().includes(t);
const n = e;
return n.target != null && t.contains(n.target);
}
const Ut = {
pointerdown: "onPointerDown",
mousedown: "onMouseDown",
click: "onClick"
}, _t = {
pointerdown: "onPointerDownCapture",
mousedown: "onMouseDownCapture",
click: "onClickCapture"
}, zt = function(e) {
var t, n;
return e === void 0 && (e = !0), {
escapeKeyBubbles: typeof e == "boolean" ? e : (t = e.escapeKey) != null ? t : !0,
outsidePressBubbles: typeof e == "boolean" ? e : (n = e.outsidePress) != null ? n : !0
};
}, en = function(e, t) {
let {
open: n,
onOpenChange: r,
events: o,
nodeId: i,
elements: {
reference: u,
domReference: a,
floating: f
}
} = e, {
enabled: v = !0,
escapeKey: m = !0,
outsidePress: c = !0,
outsidePressEvent: l = "pointerdown",
referencePress: p = !1,
referencePressEvent: w = "pointerdown",
ancestorScroll: b = !1,
bubbles: d = !0
} = {};
const g = we(), I = Pt() != null, E = xe(typeof c == "function" ? c : () => !1), F = typeof c == "function" ? E : c, k = s.useRef(!1), {
escapeKeyBubbles: O,
outsidePressBubbles: V
} = zt(d);
return s.useEffect(() => {
if (!n || !v)
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 K(S) {
const L = k.current;
if (k.current = !1, L || typeof F == "function" && !F(S))
return;
const C = Ue(S);
if (Z(C) && f) {
const U = f.ownerDocument.defaultView || window, h = C.scrollWidth > C.clientWidth, R = C.scrollHeight > C.clientHeight;
let y = R && S.offsetX > C.clientWidth;
if (R && U.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((U) => {
var h;
return be(S, (h = U.context) == null ? void 0 : h.elements.floating);
});
be(S, f) || be(S, a) || J || !V && 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, K);
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, K), A.forEach((S) => {
S.removeEventListener("scroll", T);
});
};
}, [f, a, u, m, F, l, o, g, i, n, r, b, v, O, V, I]), s.useEffect(() => {
k.current = !1;
}, [F, l]), s.useMemo(() => v ? {
reference: {
[Ut[w]]: () => {
p && (o.emit("dismiss", {
type: "referencePress",
data: {
returnFocus: !1
}
}), r(!1));
}
},
floating: {
[_t[l]]: () => {
k.current = !0;
}
}
} : {}, [v, o, p, l, w, r]);
};
function tn(e) {
return s.useMemo(() => e.every((t) => t == null) ? null : (t) => {
e.forEach((n) => {
typeof n == "function" ? n(t) : n != null && (n.current = t);
});
}, e);
}
const nn = function(e, t) {
let {
open: n
} = e, {
enabled: r = !0,
role: o = "dialog"
} = {};
const i = ye(), u = ye();
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(e) {
e === void 0 && (e = {});
const {
open: t = !1,
onOpenChange: n,
nodeId: r
} = e, o = et(e), i = we(), u = s.useRef(null), a = s.useRef({}), f = s.useState(() => Ct())[0], [v, 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: v
}), [o.elements, v]), b = xe(n), d = s.useMemo(() => ({
...o,
refs: p,
elements: w,
dataRef: a,
nodeId: r,
events: f,
open: t,
onOpenChange: b
}), [o, r, f, t, b, p, w]);
return q(() => {
const g = i == null ? void 0 : i.nodesRef.current.find((I) => I.id === r);
g && (g.context = d);
}), s.useMemo(() => ({
...o,
context: d,
refs: p,
reference: l,
positionReference: c
}), [o, p, d, l, c]);
}
function me(e, t, n) {
const r = /* @__PURE__ */ new Map();
return {
...n === "floating" && {
tabIndex: -1
},
...e,
...t.map((o) => o ? o[n] : null).concat(e).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 v;
(v = r.get(a)) == null || v.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(e) {
e === void 0 && (e = []);
const t = e, n = s.useCallback(
(i) => me(i, e, "reference"),
// eslint-disable-next-line react-hooks/exhaustive-deps
t
), r = s.useCallback(
(i) => me(i, e, "floating"),
// eslint-disable-next-line react-hooks/exhaustive-deps
t
), o = s.useCallback(
(i) => me(i, e, "item"),
// eslint-disable-next-line react-hooks/exhaustive-deps
t
);
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,
ye as u
};