dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
238 lines (237 loc) • 7.75 kB
JavaScript
import { k as P } from "./createLucideIcon-B950nf2d-9wLYOF5y.js";
import * as s from "react";
import g from "react";
import { j as G, i as D, a as p, S as K, g as Z, h as L, b as S, y as J, n as Q } from "./index-BL59b1Bz-C9bJE_xn.js";
function V(e) {
const r = e + "CollectionProvider", [u, n] = G(r), [I, b] = u(
r,
{ collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
), v = (f) => {
const { scope: o, children: a } = f, t = g.useRef(null), c = g.useRef(/* @__PURE__ */ new Map()).current;
return /* @__PURE__ */ p.jsx(I, { scope: o, itemMap: c, collectionRef: t, children: a });
};
v.displayName = r;
const w = e + "CollectionSlot", C = K(w), m = g.forwardRef(
(f, o) => {
const { scope: a, children: t } = f, c = b(w, a), d = D(o, c.collectionRef);
return /* @__PURE__ */ p.jsx(C, { ref: d, children: t });
}
);
m.displayName = w;
const l = e + "CollectionItemSlot", y = "data-radix-collection-item", x = K(l), h = g.forwardRef(
(f, o) => {
const { scope: a, children: t, ...c } = f, d = g.useRef(null), A = D(o, d), E = b(l, a);
return g.useEffect(() => (E.itemMap.set(d, { ref: d, ...c }), () => void E.itemMap.delete(d))), /* @__PURE__ */ p.jsx(x, { [y]: "", ref: A, children: t });
}
);
h.displayName = l;
function F(f) {
const o = b(e + "CollectionConsumer", f);
return g.useCallback(() => {
const a = o.collectionRef.current;
if (!a) return [];
const t = Array.from(a.querySelectorAll(`[${y}]`));
return Array.from(o.itemMap.values()).sort(
(c, d) => t.indexOf(c.ref.current) - t.indexOf(d.ref.current)
);
}, [o.collectionRef, o.itemMap]);
}
return [
{ Provider: v, Slot: m, ItemSlot: h },
F,
n
];
}
var W = s.createContext(void 0);
function ee(e) {
const r = s.useContext(W);
return e || r || "ltr";
}
/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/
const oe = [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]], be = P("check", oe);
/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/
const re = [["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }]], we = P("circle", re);
var j = "rovingFocusGroup.onEntryFocus", te = { bubbles: !1, cancelable: !0 }, T = "RovingFocusGroup", [k, N, ne] = V(T), [ce, ye] = G(
T,
[ne]
), [ae, le] = ce(T), O = s.forwardRef(
(e, r) => /* @__PURE__ */ p.jsx(k.Provider, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ p.jsx(k.Slot, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ p.jsx(se, { ...e, ref: r }) }) })
);
O.displayName = T;
var se = s.forwardRef((e, r) => {
const {
__scopeRovingFocusGroup: u,
orientation: n,
loop: I = !1,
dir: b,
currentTabStopId: v,
defaultCurrentTabStopId: w,
onCurrentTabStopIdChange: C,
onEntryFocus: m,
preventScrollOnEntryFocus: l = !1,
...y
} = e, x = s.useRef(null), h = D(r, x), F = ee(b), [f, o] = J({
prop: v,
defaultProp: w ?? null,
onChange: C,
caller: T
}), [a, t] = s.useState(!1), c = Q(m), d = N(u), A = s.useRef(!1), [E, _] = s.useState(0);
return s.useEffect(() => {
const i = x.current;
if (i)
return i.addEventListener(j, c), () => i.removeEventListener(j, c);
}, [c]), /* @__PURE__ */ p.jsx(
ae,
{
scope: u,
orientation: n,
dir: F,
loop: I,
currentTabStopId: f,
onItemFocus: s.useCallback(
(i) => o(i),
[o]
),
onItemShiftTab: s.useCallback(() => t(!0), []),
onFocusableItemAdd: s.useCallback(
() => _((i) => i + 1),
[]
),
onFocusableItemRemove: s.useCallback(
() => _((i) => i - 1),
[]
),
children: /* @__PURE__ */ p.jsx(
L.div,
{
tabIndex: a || E === 0 ? -1 : 0,
"data-orientation": n,
...y,
ref: h,
style: { outline: "none", ...e.style },
onMouseDown: S(e.onMouseDown, () => {
A.current = !0;
}),
onFocus: S(e.onFocus, (i) => {
const z = !A.current;
if (i.target === i.currentTarget && z && !a) {
const $ = new CustomEvent(j, te);
if (i.currentTarget.dispatchEvent($), !$.defaultPrevented) {
const M = d().filter((R) => R.focusable), H = M.find((R) => R.active), X = M.find((R) => R.id === f), Y = [H, X, ...M].filter(
Boolean
).map((R) => R.ref.current);
q(Y, l);
}
}
A.current = !1;
}),
onBlur: S(e.onBlur, () => t(!1))
}
)
}
);
}), B = "RovingFocusGroupItem", U = s.forwardRef(
(e, r) => {
const {
__scopeRovingFocusGroup: u,
focusable: n = !0,
active: I = !1,
tabStopId: b,
children: v,
...w
} = e, C = Z(), m = b || C, l = le(B, u), y = l.currentTabStopId === m, x = N(u), { onFocusableItemAdd: h, onFocusableItemRemove: F, currentTabStopId: f } = l;
return s.useEffect(() => {
if (n)
return h(), () => F();
}, [n, h, F]), /* @__PURE__ */ p.jsx(
k.ItemSlot,
{
scope: u,
id: m,
focusable: n,
active: I,
children: /* @__PURE__ */ p.jsx(
L.span,
{
tabIndex: y ? 0 : -1,
"data-orientation": l.orientation,
...w,
ref: r,
onMouseDown: S(e.onMouseDown, (o) => {
n ? l.onItemFocus(m) : o.preventDefault();
}),
onFocus: S(e.onFocus, () => l.onItemFocus(m)),
onKeyDown: S(e.onKeyDown, (o) => {
if (o.key === "Tab" && o.shiftKey) {
l.onItemShiftTab();
return;
}
if (o.target !== o.currentTarget) return;
const a = fe(o, l.orientation, l.dir);
if (a !== void 0) {
if (o.metaKey || o.ctrlKey || o.altKey || o.shiftKey) return;
o.preventDefault();
let t = x().filter((c) => c.focusable).map((c) => c.ref.current);
if (a === "last") t.reverse();
else if (a === "prev" || a === "next") {
a === "prev" && t.reverse();
const c = t.indexOf(o.currentTarget);
t = l.loop ? de(t, c + 1) : t.slice(c + 1);
}
setTimeout(() => q(t));
}
}),
children: typeof v == "function" ? v({ isCurrentTabStop: y, hasTabStop: f != null }) : v
}
)
}
);
}
);
U.displayName = B;
var ue = {
ArrowLeft: "prev",
ArrowUp: "prev",
ArrowRight: "next",
ArrowDown: "next",
PageUp: "first",
Home: "first",
PageDown: "last",
End: "last"
};
function ie(e, r) {
return r !== "rtl" ? e : e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e;
}
function fe(e, r, u) {
const n = ie(e.key, u);
if (!(r === "vertical" && ["ArrowLeft", "ArrowRight"].includes(n)) && !(r === "horizontal" && ["ArrowUp", "ArrowDown"].includes(n)))
return ue[n];
}
function q(e, r = !1) {
const u = document.activeElement;
for (const n of e)
if (n === u || (n.focus({ preventScroll: r }), document.activeElement !== u)) return;
}
function de(e, r) {
return e.map((u, n) => e[(r + n) % e.length]);
}
var he = O, Re = U;
export {
V as D,
he as F,
we as a,
ye as b,
Re as g,
ee as n,
be as t
};