UNPKG

@konstructio/ui

Version:

A set of reusable and customizable React components built for konstruct.io

481 lines (478 loc) 16.1 kB
import { n as T, t as ge } from "./dist-C4El7dZ5.js"; import { a as _, o as Ee, r as ye, s as he, t as O } from "./dist-D_9sBzad.js"; import { t as w } from "./dist-CQfmhKEs.js"; import { t as V } from "./dist-D6dB-_Oy.js"; import { r as De, t as Ce } from "./dist-AZfrfAUz.js"; import { t as U } from "./dist-DF7Yi2EK.js"; import { t as be } from "./Combination-DFcElBFt.js"; import * as i from "react"; import { Fragment as j, jsx as l, jsxs as B } from "react/jsx-runtime"; var x = "focusScope.autoFocusOnMount", L = "focusScope.autoFocusOnUnmount", H = { bubbles: !1, cancelable: !0 }, Ae = "FocusScope", J = i.forwardRef((e, t) => { const { loop: n = !1, trapped: o = !1, onMountAutoFocus: r, onUnmountAutoFocus: a, ...u } = e, [s, g] = i.useState(null), p = V(r), E = V(a), c = i.useRef(null), d = T(t, (f) => g(f)), v = i.useRef({ paused: !1, pause() { this.paused = !0; }, resume() { this.paused = !1; } }).current; i.useEffect(() => { if (o) { let f = function(D) { if (v.paused || !s) return; const y = D.target; s.contains(y) ? c.current = y : b(c.current, { select: !0 }); }, m = function(D) { if (v.paused || !s) return; const y = D.relatedTarget; y !== null && (s.contains(y) || b(c.current, { select: !0 })); }, C = function(D) { if (document.activeElement === document.body) for (const y of D) y.removedNodes.length > 0 && b(s); }; document.addEventListener("focusin", f), document.addEventListener("focusout", m); const N = new MutationObserver(C); return s && N.observe(s, { childList: !0, subtree: !0 }), () => { document.removeEventListener("focusin", f), document.removeEventListener("focusout", m), N.disconnect(); }; } }, [ o, s, v.paused ]), i.useEffect(() => { if (s) { Z.add(v); const f = document.activeElement; if (!s.contains(f)) { const m = new CustomEvent(x, H); s.addEventListener(x, p), s.dispatchEvent(m), m.defaultPrevented || (Re(Pe(Q(s)), { select: !0 }), document.activeElement === f && b(s)); } return () => { s.removeEventListener(x, p), setTimeout(() => { const m = new CustomEvent(L, H); s.addEventListener(L, E), s.dispatchEvent(m), m.defaultPrevented || b(f ?? document.body, { select: !0 }), s.removeEventListener(L, E), Z.remove(v); }, 0); }; } }, [ s, p, E, v ]); const S = i.useCallback((f) => { if (!n && !o || v.paused) return; const m = f.key === "Tab" && !f.altKey && !f.ctrlKey && !f.metaKey, C = document.activeElement; if (m && C) { const N = f.currentTarget, [D, y] = Oe(N); D && y ? !f.shiftKey && C === y ? (f.preventDefault(), n && b(D, { select: !0 })) : f.shiftKey && C === D && (f.preventDefault(), n && b(y, { select: !0 })) : C === N && f.preventDefault(); } }, [ n, o, v.paused ]); return /* @__PURE__ */ l(O.div, { tabIndex: -1, ...u, ref: d, onKeyDown: S }); }); J.displayName = Ae; function Re(e, { select: t = !1 } = {}) { const n = document.activeElement; for (const o of e) if (b(o, { select: t }), document.activeElement !== n) return; } function Oe(e) { const t = Q(e); return [q(t, e), q(t.reverse(), e)]; } function Q(e) { const t = [], n = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, { acceptNode: (o) => { const r = o.tagName === "INPUT" && o.type === "hidden"; return o.disabled || o.hidden || r ? NodeFilter.FILTER_SKIP : o.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP; } }); for (; n.nextNode(); ) t.push(n.currentNode); return t; } function q(e, t) { for (const n of e) if (!Ne(n, { upTo: t })) return n; } function Ne(e, { upTo: t }) { if (getComputedStyle(e).visibility === "hidden") return !0; for (; e; ) { if (t !== void 0 && e === t) return !1; if (getComputedStyle(e).display === "none") return !0; e = e.parentElement; } return !1; } function _e(e) { return e instanceof HTMLInputElement && "select" in e; } function b(e, { select: t = !1 } = {}) { if (e && e.focus) { const n = document.activeElement; e.focus({ preventScroll: !0 }), e !== n && _e(e) && t && e.select(); } } var Z = Se(); function Se() { let e = []; return { add(t) { const n = e[0]; t !== n && n?.pause(), e = Y(e, t), e.unshift(t); }, remove(t) { e = Y(e, t), e[0]?.resume(); } }; } function Y(e, t) { const n = [...e], o = n.indexOf(t); return o !== -1 && n.splice(o, 1), n; } function Pe(e) { return e.filter((t) => t.tagName !== "A"); } var W = 0; function Fe() { i.useEffect(() => { const e = document.querySelectorAll("[data-radix-focus-guard]"); return document.body.insertAdjacentElement("afterbegin", e[0] ?? z()), document.body.insertAdjacentElement("beforeend", e[1] ?? z()), W++, () => { W === 1 && document.querySelectorAll("[data-radix-focus-guard]").forEach((t) => t.remove()), W--; }; }, []); } function z() { const e = document.createElement("span"); return e.setAttribute("data-radix-focus-guard", ""), e.tabIndex = 0, e.style.outline = "none", e.style.opacity = "0", e.style.position = "fixed", e.style.pointerEvents = "none", e; } var Ie = function(e) { return typeof document > "u" ? null : (Array.isArray(e) ? e[0] : e).ownerDocument.body; }, R = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), F = {}, k = 0, X = function(e) { return e && (e.host || X(e.parentNode)); }, Te = function(e, t) { return t.map(function(n) { if (e.contains(n)) return n; var o = X(n); return o && e.contains(o) ? o : (console.error("aria-hidden", n, "in not contained inside", e, ". Doing nothing"), null); }).filter(function(n) { return !!n; }); }, Me = function(e, t, n, o) { var r = Te(t, Array.isArray(e) ? e : [e]); F[n] || (F[n] = /* @__PURE__ */ new WeakMap()); var a = F[n], u = [], s = /* @__PURE__ */ new Set(), g = new Set(r), p = function(c) { !c || s.has(c) || (s.add(c), p(c.parentNode)); }; r.forEach(p); var E = function(c) { !c || g.has(c) || Array.prototype.forEach.call(c.children, function(d) { if (s.has(d)) E(d); else try { var v = d.getAttribute(o), S = v !== null && v !== "false", f = (R.get(d) || 0) + 1, m = (a.get(d) || 0) + 1; R.set(d, f), a.set(d, m), u.push(d), f === 1 && S && P.set(d, !0), m === 1 && d.setAttribute(n, "true"), S || d.setAttribute(o, "true"); } catch (C) { console.error("aria-hidden: cannot operate on ", d, C); } }); }; return E(t), s.clear(), k++, function() { u.forEach(function(c) { var d = R.get(c) - 1, v = a.get(c) - 1; R.set(c, d), a.set(c, v), d || (P.has(c) || c.removeAttribute(o), P.delete(c)), v || c.removeAttribute(n); }), k--, k || (R = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), F = {}); }; }, we = function(e, t, n) { n === void 0 && (n = "data-aria-hidden"); var o = Array.from(Array.isArray(e) ? e : [e]), r = t || Ie(e); return r ? (o.push.apply(o, Array.from(r.querySelectorAll("[aria-live], script"))), Me(o, r, n, "aria-hidden")) : function() { return null; }; }; // @__NO_SIDE_EFFECTS__ function xe(e) { const t = /* @__PURE__ */ Le(e), n = i.forwardRef((o, r) => { const { children: a, ...u } = o, s = i.Children.toArray(a), g = s.find(ke); if (g) { const p = g.props.children, E = s.map((c) => c === g ? i.Children.count(p) > 1 ? i.Children.only(null) : i.isValidElement(p) ? p.props.children : null : c); return /* @__PURE__ */ l(t, { ...u, ref: r, children: i.isValidElement(p) ? i.cloneElement(p, void 0, E) : null }); } return /* @__PURE__ */ l(t, { ...u, ref: r, children: a }); }); return n.displayName = `${e}.Slot`, n; } // @__NO_SIDE_EFFECTS__ function Le(e) { const t = i.forwardRef((n, o) => { const { children: r, ...a } = n; if (i.isValidElement(r)) { const u = Ke(r), s = Ue(a, r.props); return r.type !== i.Fragment && (s.ref = o ? ge(o, u) : u), i.cloneElement(r, s); } return i.Children.count(r) > 1 ? i.Children.only(null) : null; }); return t.displayName = `${e}.SlotClone`, t; } var We = /* @__PURE__ */ Symbol("radix.slottable"); function ke(e) { return i.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === We; } function Ue(e, t) { const n = { ...t }; for (const o in t) { const r = e[o], a = t[o]; /^on[A-Z]/.test(o) ? r && a ? n[o] = (...u) => { const s = a(...u); return r(...u), s; } : r && (n[o] = r) : o === "style" ? n[o] = { ...r, ...a } : o === "className" && (n[o] = [r, a].filter(Boolean).join(" ")); } return { ...e, ...n }; } function Ke(e) { let t = Object.getOwnPropertyDescriptor(e.props, "ref")?.get, n = t && "isReactWarning" in t && t.isReactWarning; return n ? e.ref : (t = Object.getOwnPropertyDescriptor(e, "ref")?.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref); } var M = "Dialog", [ee, rt] = he(M), [$e, h] = ee(M), te = (e) => { const { __scopeDialog: t, children: n, open: o, defaultOpen: r, onOpenChange: a, modal: u = !0 } = e, s = i.useRef(null), g = i.useRef(null), [p, E] = ye({ prop: o, defaultProp: r ?? !1, onChange: a, caller: M }); return /* @__PURE__ */ l($e, { scope: t, triggerRef: s, contentRef: g, contentId: w(), titleId: w(), descriptionId: w(), open: p, onOpenChange: E, onOpenToggle: i.useCallback(() => E((c) => !c), [E]), modal: u, children: n }); }; te.displayName = M; var ne = "DialogTrigger", oe = i.forwardRef((e, t) => { const { __scopeDialog: n, ...o } = e, r = h(ne, n), a = T(t, r.triggerRef); return /* @__PURE__ */ l(O.button, { type: "button", "aria-haspopup": "dialog", "aria-expanded": r.open, "aria-controls": r.contentId, "data-state": G(r.open), ...o, ref: a, onClick: _(e.onClick, r.onOpenToggle) }); }); oe.displayName = ne; var K = "DialogPortal", [Ge, re] = ee(K, { forceMount: void 0 }), ae = (e) => { const { __scopeDialog: t, forceMount: n, children: o, container: r } = e, a = h(K, t); return /* @__PURE__ */ l(Ge, { scope: t, forceMount: n, children: i.Children.map(o, (u) => /* @__PURE__ */ l(U, { present: n || a.open, children: /* @__PURE__ */ l(Ce, { asChild: !0, container: r, children: u }) })) }); }; ae.displayName = K; var I = "DialogOverlay", se = i.forwardRef((e, t) => { const n = re(I, e.__scopeDialog), { forceMount: o = n.forceMount, ...r } = e, a = h(I, e.__scopeDialog); return a.modal ? /* @__PURE__ */ l(U, { present: o || a.open, children: /* @__PURE__ */ l(je, { ...r, ref: t }) }) : null; }); se.displayName = I; var Ve = /* @__PURE__ */ xe("DialogOverlay.RemoveScroll"), je = i.forwardRef((e, t) => { const { __scopeDialog: n, ...o } = e, r = h(I, n); return /* @__PURE__ */ l(be, { as: Ve, allowPinchZoom: !0, shards: [r.contentRef], children: /* @__PURE__ */ l(O.div, { "data-state": G(r.open), ...o, ref: t, style: { pointerEvents: "auto", ...o.style } }) }); }), A = "DialogContent", ie = i.forwardRef((e, t) => { const n = re(A, e.__scopeDialog), { forceMount: o = n.forceMount, ...r } = e, a = h(A, e.__scopeDialog); return /* @__PURE__ */ l(U, { present: o || a.open, children: a.modal ? /* @__PURE__ */ l(Be, { ...r, ref: t }) : /* @__PURE__ */ l(He, { ...r, ref: t }) }); }); ie.displayName = A; var Be = i.forwardRef((e, t) => { const n = h(A, e.__scopeDialog), o = i.useRef(null), r = T(t, n.contentRef, o); return i.useEffect(() => { const a = o.current; if (a) return we(a); }, []), /* @__PURE__ */ l(ce, { ...e, ref: r, trapFocus: n.open, disableOutsidePointerEvents: !0, onCloseAutoFocus: _(e.onCloseAutoFocus, (a) => { a.preventDefault(), n.triggerRef.current?.focus(); }), onPointerDownOutside: _(e.onPointerDownOutside, (a) => { const u = a.detail.originalEvent, s = u.button === 0 && u.ctrlKey === !0; (u.button === 2 || s) && a.preventDefault(); }), onFocusOutside: _(e.onFocusOutside, (a) => a.preventDefault()) }); }), He = i.forwardRef((e, t) => { const n = h(A, e.__scopeDialog), o = i.useRef(!1), r = i.useRef(!1); return /* @__PURE__ */ l(ce, { ...e, ref: t, trapFocus: !1, disableOutsidePointerEvents: !1, onCloseAutoFocus: (a) => { e.onCloseAutoFocus?.(a), a.defaultPrevented || (o.current || n.triggerRef.current?.focus(), a.preventDefault()), o.current = !1, r.current = !1; }, onInteractOutside: (a) => { e.onInteractOutside?.(a), a.defaultPrevented || (o.current = !0, a.detail.originalEvent.type === "pointerdown" && (r.current = !0)); const u = a.target; n.triggerRef.current?.contains(u) && a.preventDefault(), a.detail.originalEvent.type === "focusin" && r.current && a.preventDefault(); } }); }), ce = i.forwardRef((e, t) => { const { __scopeDialog: n, trapFocus: o, onOpenAutoFocus: r, onCloseAutoFocus: a, ...u } = e, s = h(A, n), g = i.useRef(null), p = T(t, g); return Fe(), /* @__PURE__ */ B(j, { children: [/* @__PURE__ */ l(J, { asChild: !0, loop: !0, trapped: o, onMountAutoFocus: r, onUnmountAutoFocus: a, children: /* @__PURE__ */ l(De, { role: "dialog", id: s.contentId, "aria-describedby": s.descriptionId, "aria-labelledby": s.titleId, "data-state": G(s.open), ...u, ref: p, onDismiss: () => s.onOpenChange(!1) }) }), /* @__PURE__ */ B(j, { children: [/* @__PURE__ */ l(qe, { titleId: s.titleId }), /* @__PURE__ */ l(Ye, { contentRef: g, descriptionId: s.descriptionId })] })] }); }), $ = "DialogTitle", ue = i.forwardRef((e, t) => { const { __scopeDialog: n, ...o } = e, r = h($, n); return /* @__PURE__ */ l(O.h2, { id: r.titleId, ...o, ref: t }); }); ue.displayName = $; var le = "DialogDescription", fe = i.forwardRef((e, t) => { const { __scopeDialog: n, ...o } = e, r = h(le, n); return /* @__PURE__ */ l(O.p, { id: r.descriptionId, ...o, ref: t }); }); fe.displayName = le; var de = "DialogClose", pe = i.forwardRef((e, t) => { const { __scopeDialog: n, ...o } = e, r = h(de, n); return /* @__PURE__ */ l(O.button, { type: "button", ...o, ref: t, onClick: _(e.onClick, () => r.onOpenChange(!1)) }); }); pe.displayName = de; function G(e) { return e ? "open" : "closed"; } var ve = "DialogTitleWarning", [at, me] = Ee(ve, { contentName: A, titleName: $, docsSlug: "dialog" }), qe = ({ titleId: e }) => { const t = me(ve), n = `\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users. If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component. For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`; return i.useEffect(() => { e && (document.getElementById(e) || console.error(n)); }, [n, e]), null; }, Ze = "DialogDescriptionWarning", Ye = ({ contentRef: e, descriptionId: t }) => { const n = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${me(Ze).contentName}}.`; return i.useEffect(() => { const o = e.current?.getAttribute("aria-describedby"); t && o && (document.getElementById(t) || console.warn(n)); }, [ n, e, t ]), null; }, st = te, it = oe, ct = ae, ut = se, lt = ie, ft = ue, dt = fe, pt = pe; export { ue as a, st as c, at as d, rt as f, ae as i, ft as l, lt as n, ut as o, dt as r, ct as s, pt as t, it as u };