UNPKG

welcome-ui

Version:

Customizable design system with react, typescript, tailwindcss and ariakit.

188 lines (187 loc) 6.24 kB
"use client"; import { c as te, g as v, s as re, i as w, a as z, d as oe, e as se, C as ne } from "./SBSPVDDI-CW8jwL0u.js"; import { c as ie, _ as L, i as ae, ak as ue, al as ce, M as B, am as C, o as le, af as fe, u as I, j as P, l as de, h as U, x as pe, d as me, p as ve, a as R, W as ge, an as ye, f as Ce, b as Pe, e as Ee } from "./OE2EFRVA-C3721cM3.js"; import { f as Ie, r as Se } from "./B7UTNDHN-C-gORHYH.js"; import { useRef as H, useEffect as V, useState as Fe, useCallback as xe, createContext as b } from "react"; import { jsx as we } from "react/jsx-runtime"; import { P as be, a as Ke } from "./Y67KZUMI-CtXJ_hZt.js"; var ke = "div"; function Ae(r) { return r.some((i) => !!i.rowId); } function _e(r) { const i = r.target; return i && !U(i) ? !1 : r.key.length === 1 && !r.ctrlKey && !r.metaKey; } function he(r) { return r.key === "Shift" || r.key === "Control" || r.key === "Alt" || r.key === "Meta"; } function O(r, i, l) { return I((e) => { var s; if (i == null || i(e), e.defaultPrevented || e.isPropagationStopped() || !P(e) || he(e) || _e(e)) return; const f = r.getState(), p = (s = v(r, f.activeId)) == null ? void 0 : s.element; if (!p) return; const n = e, { view: K } = n, x = L(n, ["view"]), c = l == null ? void 0 : l.current; p !== c && p.focus(), ye(p, e.type, x) || e.preventDefault(), e.currentTarget.contains(p) && e.stopPropagation(); }); } function Te(r) { return oe( Ie(Se(se(r))) ); } function De(r) { const [i, l] = Fe(!1), e = xe(() => l(!0), []), s = r.useState( (f) => v(r, f.activeId) ); return V(() => { const f = s == null ? void 0 : s.element; i && f && (l(!1), f.focus({ preventScroll: !0 })); }, [s, i]), e; } var Me = ie( function(i) { var l = i, { store: e, composite: s = !0, focusOnMove: f = s, moveOnKeyPress: p = !0 } = l, n = L(l, [ "store", "composite", "focusOnMove", "moveOnKeyPress" ]); const K = te(); e = e || K, ae( e, process.env.NODE_ENV !== "production" && "Composite must receive a `store` prop or be wrapped in a CompositeProvider component." ); const x = H(null), c = H(null), N = De(e), S = e.useState("moves"), [, W] = ue( s ? e.setBaseElement : null ); V(() => { var t; if (!e || !S || !s || !f) return; const { activeId: o } = e.getState(), a = (t = v(e, o)) == null ? void 0 : t.element; a && ce(a); }, [e, S, s, f]), B(() => { if (!e || !S || !s) return; const { baseElement: t, activeId: o } = e.getState(); if (!(o === null) || !t) return; const u = c.current; c.current = null, u && C(u, { relatedTarget: t }), le(t) || t.focus(); }, [e, S, s]); const k = e.useState("activeId"), A = e.useState("virtualFocus"); B(() => { var t; if (!e || !s || !A) return; const o = c.current; if (c.current = null, !o) return; const u = ((t = v(e, k)) == null ? void 0 : t.element) || fe(o); u !== o && C(o, { relatedTarget: u }); }, [e, k, A, s]); const q = O( e, n.onKeyDownCapture, c ), G = O( e, n.onKeyUpCapture, c ), _ = n.onFocusCapture, J = I((t) => { if (_ == null || _(t), t.defaultPrevented || !e) return; const { virtualFocus: o } = e.getState(); if (!o) return; const a = t.relatedTarget, u = re(t.currentTarget); P(t) && u && (t.stopPropagation(), c.current = a); }), h = n.onFocus, Q = I((t) => { if (h == null || h(t), t.defaultPrevented || !s || !e) return; const { relatedTarget: o } = t, { virtualFocus: a } = e.getState(); a ? P(t) && !w(e, o) && queueMicrotask(N) : P(t) && e.setActiveId(null); }), T = n.onBlurCapture, X = I((t) => { var o; if (T == null || T(t), t.defaultPrevented || !e) return; const { virtualFocus: a, activeId: u } = e.getState(); if (!a) return; const m = (o = v(e, u)) == null ? void 0 : o.element, g = t.relatedTarget, F = w(e, g), d = c.current; c.current = null, P(t) && F ? (g === m ? d && d !== g && C(d, t) : m ? C(m, t) : d && C(d, t), t.stopPropagation()) : !w(e, t.target) && m && C(m, t); }), D = n.onKeyDown, Y = de(p), Z = I((t) => { var o; if (D == null || D(t), t.nativeEvent.isComposing || t.defaultPrevented || !e || !P(t)) return; const { orientation: a, renderedItems: u, activeId: m } = e.getState(), g = v(e, m); if ((o = g == null ? void 0 : g.element) != null && o.isConnected) return; const F = a !== "horizontal", d = a !== "vertical", y = Ae(u); if ((t.key === "ArrowLeft" || t.key === "ArrowRight" || t.key === "Home" || t.key === "End") && U(t.currentTarget)) return; const M = { ArrowUp: (y || F) && (() => { if (y) { const E = Te(u); return E == null ? void 0 : E.id; } return e == null ? void 0 : e.last(); }), ArrowRight: (y || d) && e.first, ArrowDown: (y || F) && e.first, ArrowLeft: (y || d) && e.last, Home: e.first, End: e.last, PageUp: e.first, PageDown: e.last }[t.key]; if (M) { const E = M(); if (E !== void 0) { if (!Y(t)) return; t.preventDefault(), e.move(E); } } }); n = pe( n, (t) => /* @__PURE__ */ we(z, { value: e, children: t }), [e] ); const $ = e.useState((t) => { var o; if (e && s && t.virtualFocus) return (o = v(e, t.activeId)) == null ? void 0 : o.id; }); n = me(R({ "aria-activedescendant": $ }, n), { ref: ve(x, W, n.ref), onKeyDownCapture: q, onKeyUpCapture: G, onFocusCapture: J, onFocus: Q, onBlurCapture: X, onKeyDown: Z }); const ee = e.useState( (t) => s && (t.virtualFocus || t.activeId === null) ); return n = ge(R({ focusable: ee }, n)), n; } ); Ce(function(i) { const l = Me(i); return Pe(ke, l); }); b( void 0 ); var j = Ee( [Ke, z], [be, ne] ), Ne = j.useContext, We = j.useProviderContext; b( void 0 ); b(!1); export { We as a, Ne as b, Me as u };