UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

94 lines (93 loc) 3.72 kB
import * as l from "react"; import R from "react"; import { b as T } from "./index-BVqmUhu5.es.js"; import { c as P, u as A } from "./index-DLcqcWxM.es.js"; import { jsx as E } from "react/jsx-runtime"; // @__NO_SIDE_EFFECTS__ function M(e) { const t = /* @__PURE__ */ v(e), r = l.forwardRef((n, o) => { const { children: c, ...a } = n, s = l.Children.toArray(c), d = s.find(w); if (d) { const f = d.props.children, y = s.map((I) => I === d ? l.Children.count(f) > 1 ? l.Children.only(null) : l.isValidElement(f) ? f.props.children : null : I); return /* @__PURE__ */ E(t, { ...a, ref: o, children: l.isValidElement(f) ? l.cloneElement(f, void 0, y) : null }); } return /* @__PURE__ */ E(t, { ...a, ref: o, children: c }); }); return r.displayName = `${e}.Slot`, r; } // @__NO_SIDE_EFFECTS__ function v(e) { const t = l.forwardRef((r, n) => { const { children: o, ...c } = r; if (l.isValidElement(o)) { const a = D(o), s = V(c, o.props); return o.type !== l.Fragment && (s.ref = n ? P(n, a) : a), l.cloneElement(o, s); } return l.Children.count(o) > 1 ? l.Children.only(null) : null; }); return t.displayName = `${e}.SlotClone`, t; } var b = Symbol("radix.slottable"); function w(e) { return l.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === b; } function V(e, t) { const r = { ...t }; for (const n in t) { const o = e[n], c = t[n]; /^on[A-Z]/.test(n) ? o && c ? r[n] = (...s) => { const d = c(...s); return o(...s), d; } : o && (r[n] = o) : n === "style" ? r[n] = { ...o, ...c } : n === "className" && (r[n] = [o, c].filter(Boolean).join(" ")); } return { ...e, ...r }; } function D(e) { var n, o; let t = (n = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : n.get, r = t && "isReactWarning" in t && t.isReactWarning; return r ? e.ref : (t = (o = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : o.get, r = t && "isReactWarning" in t && t.isReactWarning, r ? e.props.ref : e.props.ref || e.ref); } function B(e) { const t = e + "CollectionProvider", [r, n] = T(t), [o, c] = r( t, { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() } ), a = (m) => { const { scope: i, children: S } = m, u = R.useRef(null), p = R.useRef(/* @__PURE__ */ new Map()).current; return /* @__PURE__ */ E(o, { scope: i, itemMap: p, collectionRef: u, children: S }); }; a.displayName = t; const s = e + "CollectionSlot", d = /* @__PURE__ */ M(s), f = R.forwardRef( (m, i) => { const { scope: S, children: u } = m, p = c(s, S), C = A(i, p.collectionRef); return /* @__PURE__ */ E(d, { ref: C, children: u }); } ); f.displayName = s; const y = e + "CollectionItemSlot", I = "data-radix-collection-item", N = /* @__PURE__ */ M(y), _ = R.forwardRef( (m, i) => { const { scope: S, children: u, ...p } = m, C = R.useRef(null), g = A(i, C), x = c(y, S); return R.useEffect(() => (x.itemMap.set(C, { ref: C, ...p }), () => void x.itemMap.delete(C))), /* @__PURE__ */ E(N, { [I]: "", ref: g, children: u }); } ); _.displayName = y; function O(m) { const i = c(e + "CollectionConsumer", m); return R.useCallback(() => { const u = i.collectionRef.current; if (!u) return []; const p = Array.from(u.querySelectorAll(`[${I}]`)); return Array.from(i.itemMap.values()).sort( (x, h) => p.indexOf(x.ref.current) - p.indexOf(h.ref.current) ); }, [i.collectionRef, i.itemMap]); } return [ { Provider: a, Slot: f, ItemSlot: _ }, O, n ]; } export { B as c }; //# sourceMappingURL=index-CbjDVb-G.es.js.map