welcome-ui
Version:
Customizable design system with react, typescript, tailwindcss and ariakit.
302 lines (301 loc) • 8.99 kB
JavaScript
"use client";
import { e as Y, h as $, g as Ce, c as q, U as xe, _ as G, w as J, d as S, p as Q, a as P, r as X, f as Z, b as ee, A as Se, u as R, ao as Pe, ap as O, j as A, aj as we, l as V, aq as he, ar as Ee, x as ye, O as Te, as as De, v as Re } from "./OE2EFRVA-C3721cM3.js";
import { createContext as te, useRef as F, useEffect as Oe, useContext as Ae, useCallback as Fe, useMemo as _e } from "react";
import { u as ke } from "./2W3RN7C5-bkX-rIa3.js";
import { g as ze } from "./RTNCFSKZ-P4icqVD0.js";
import { jsx as Ke } from "react/jsx-runtime";
var w = Y(), Le = w.useContext;
w.useScopedContext;
w.useProviderContext;
var Ne = w.ContextProvider, Be = w.ScopedContextProvider, h = Y(
[Ne],
[Be]
), Me = h.useContext;
h.useScopedContext;
var at = h.useProviderContext, ut = h.ContextProvider, lt = h.ScopedContextProvider, He = te(
void 0
), Ue = te(
void 0
), je = { id: null };
function ct(r, n, o = !1) {
const t = r.findIndex((u) => u.id === n);
return [
...r.slice(t + 1),
...o ? [je] : [],
...r.slice(0, t)
];
}
function ft(r, n) {
return r.find((o) => !o.disabled);
}
function Ve(r, n) {
return n && r.item(n) || null;
}
function dt(r) {
const n = [];
for (const o of r) {
const t = n.find((u) => {
var d;
return ((d = u[0]) == null ? void 0 : d.rowId) === o.rowId;
});
t ? t.push(o) : n.push([o]);
}
return n;
}
function We(r, n = !1) {
if ($(r))
r.setSelectionRange(
n ? r.value.length : 0,
r.value.length
);
else if (r.isContentEditable) {
const o = Ce(r).getSelection();
o == null || o.selectAllChildren(r), n && (o == null || o.collapseToEnd());
}
}
var _ = Symbol("FOCUS_SILENTLY");
function Ye(r) {
r[_] = !0, r.focus({ preventScroll: !0 });
}
function mt(r) {
const n = r[_];
return delete r[_], n;
}
function re(r, n, o) {
return !(!n || n === o || !r.item(n.id));
}
var $e = "div", ne = q(
function(n) {
var o = n, {
store: t,
shouldRegisterItem: u = !0,
getItem: d = xe,
element: g
} = o, v = G(o, [
"store",
"shouldRegisterItem",
"getItem",
// @ts-expect-error This prop may come from a collection renderer.
"element"
]);
const c = Le();
t = t || c;
const m = J(v.id), p = F(g);
return Oe(() => {
const i = p.current;
if (!m || !i || !u) return;
const b = d({ id: m, element: i });
return t == null ? void 0 : t.renderItem(b);
}, [m, u, d, t]), v = S(P({}, v), {
ref: Q(p, v.ref)
}), X(v);
}
);
Z(function(n) {
const o = ne(n);
return ee($e, o);
});
var qe = "button";
function Ge(r) {
return O(r) ? !0 : r.tagName === "INPUT" && !Te(r);
}
function Je(r, n = !1) {
const o = r.clientHeight, { top: t } = r.getBoundingClientRect(), u = Math.max(o * 0.875, o - 40) * 1.5, d = n ? o - u + t : u + t;
return r.tagName === "HTML" ? d + r.scrollTop : d;
}
function Qe(r, n = !1) {
const { top: o } = r.getBoundingClientRect();
return n ? o + r.clientHeight : o;
}
function W(r, n, o, t = !1) {
var u;
if (!n || !o) return;
const { renderedItems: d } = n.getState(), g = De(r);
if (!g) return;
const v = Je(g, t);
let c, m;
for (let p = 0; p < d.length; p += 1) {
const i = c;
if (c = o(p), !c) break;
if (c === i) continue;
const b = (u = Ve(n, c)) == null ? void 0 : u.element;
if (!b) continue;
const C = Qe(b, t) - v, l = Math.abs(C);
if (t && C <= 0 || !t && C >= 0) {
m !== void 0 && m < l && (c = i);
break;
}
m = l;
}
return c;
}
function Xe(r, n) {
return A(r) ? !1 : re(n, r.target);
}
var Ze = q(
function(n) {
var o = n, {
store: t,
rowId: u,
preventScrollOnKeyDown: d = !1,
moveOnKeyPress: g = !0,
tabbable: v = !1,
getItem: c,
"aria-setsize": m,
"aria-posinset": p
} = o, i = G(o, [
"store",
"rowId",
"preventScrollOnKeyDown",
"moveOnKeyPress",
"tabbable",
"getItem",
"aria-setsize",
"aria-posinset"
]);
const b = Me();
t = t || b;
const f = J(i.id), C = F(null), l = Ae(Ue), k = Se(i) && !i.accessibleWhenDisabled, {
rowId: y,
baseElement: z,
isActiveItem: oe,
ariaSetSize: ie,
ariaPosInSet: se,
isTabbable: ae
} = ze(t, {
rowId(e) {
if (u) return u;
if (e && l != null && l.baseElement && l.baseElement === e.baseElement)
return l.id;
},
baseElement(e) {
return (e == null ? void 0 : e.baseElement) || void 0;
},
isActiveItem(e) {
return !!e && e.activeId === f;
},
ariaSetSize(e) {
if (m != null) return m;
if (e && l != null && l.ariaSetSize && l.baseElement === e.baseElement)
return l.ariaSetSize;
},
ariaPosInSet(e) {
if (p != null) return p;
if (!e || !(l != null && l.ariaPosInSet) || l.baseElement !== e.baseElement) return;
const s = e.renderedItems.filter(
(a) => a.rowId === y
);
return l.ariaPosInSet + s.findIndex((a) => a.id === f);
},
isTabbable(e) {
if (!(e != null && e.renderedItems.length)) return !0;
if (e.virtualFocus) return !1;
if (v) return !0;
if (e.activeId === null) return !1;
const s = t == null ? void 0 : t.item(e.activeId);
return s != null && s.disabled || !(s != null && s.element) ? !0 : e.activeId === f;
}
}), ue = Fe(
(e) => {
var s;
const a = S(P({}, e), {
id: f || e.id,
rowId: y,
disabled: !!k,
children: (s = e.element) == null ? void 0 : s.textContent
});
return c ? c(a) : a;
},
[f, y, k, c]
), K = i.onFocus, T = F(!1), le = R((e) => {
if (K == null || K(e), e.defaultPrevented || Pe(e) || !f || !t || Xe(e, t)) return;
const { virtualFocus: s, baseElement: a } = t.getState();
if (t.setActiveId(f), O(e.currentTarget) && We(e.currentTarget), !s || !A(e) || Ge(e.currentTarget) || !(a != null && a.isConnected)) return;
we() && e.currentTarget.hasAttribute("data-autofocus") && e.currentTarget.scrollIntoView({
block: "nearest",
inline: "nearest"
}), T.current = !0, e.relatedTarget === a || re(t, e.relatedTarget) ? Ye(a) : a.focus();
}), L = i.onBlurCapture, ce = R((e) => {
if (L == null || L(e), e.defaultPrevented) return;
const s = t == null ? void 0 : t.getState();
s != null && s.virtualFocus && T.current && (T.current = !1, e.preventDefault(), e.stopPropagation());
}), N = i.onKeyDown, fe = V(d), de = V(g), me = R((e) => {
if (N == null || N(e), e.defaultPrevented || !A(e) || !t) return;
const { currentTarget: s } = e, a = t.getState(), D = t.item(f), I = !!(D != null && D.rowId), E = a.orientation !== "horizontal", x = a.orientation !== "vertical", M = () => !!(I || x || !a.baseElement || !$(a.baseElement)), H = {
ArrowUp: (I || E) && t.up,
ArrowRight: (I || x) && t.next,
ArrowDown: (I || E) && t.down,
ArrowLeft: (I || x) && t.previous,
Home: () => {
if (M())
return !I || e.ctrlKey ? t == null ? void 0 : t.first() : t == null ? void 0 : t.previous(-1);
},
End: () => {
if (M())
return !I || e.ctrlKey ? t == null ? void 0 : t.last() : t == null ? void 0 : t.next(-1);
},
PageUp: () => W(s, t, t == null ? void 0 : t.up, !0),
PageDown: () => W(s, t, t == null ? void 0 : t.down)
}[e.key];
if (H) {
if (O(s)) {
const j = he(s), ve = x && e.key === "ArrowLeft", pe = x && e.key === "ArrowRight", Ie = E && e.key === "ArrowUp", ge = E && e.key === "ArrowDown";
if (pe || ge) {
const { length: be } = Ee(s);
if (j.end !== be) return;
} else if ((ve || Ie) && j.start !== 0) return;
}
const U = H();
if (fe(e) || U !== void 0) {
if (!de(e)) return;
e.preventDefault(), t.move(U);
}
}
}), B = _e(
() => ({ id: f, baseElement: z }),
[f, z]
);
return i = ye(
i,
(e) => /* @__PURE__ */ Ke(He.Provider, { value: B, children: e }),
[B]
), i = S(P({
id: f,
"data-active-item": oe || void 0
}, i), {
ref: Q(C, i.ref),
tabIndex: ae ? i.tabIndex : -1,
onFocus: le,
onBlurCapture: ce,
onKeyDown: me
}), i = ke(i), i = ne(S(P({
store: t
}, i), {
getItem: ue,
shouldRegisterItem: f ? i.shouldRegisterItem : !1
})), X(S(P({}, i), {
"aria-setsize": ie,
"aria-posinset": se
}));
}
), vt = Re(
Z(function(n) {
const o = Ze(n);
return ee(qe, o);
})
);
export {
lt as C,
ut as a,
Ze as b,
at as c,
ft as d,
dt as e,
ct as f,
Ve as g,
vt as h,
re as i,
ne as j,
mt as s,
Me as u
};