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