UNPKG

@stanfordspezi/spezi-web-design-system

Version:

Stanford Biodesign Digital Health Spezi Web Design System

50 lines (49 loc) 1.74 kB
import r from "react"; import { c as y } from "./index-DFZozV_h.mjs"; import { u as M, c as x } from "./index-D2LZVjSn.mjs"; import { jsx as d } from "react/jsx-runtime"; function D(s) { const f = s + "CollectionProvider", [A, N] = y(f), [_, m] = A( f, { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() } ), p = (c) => { const { scope: e, children: l } = c, o = r.useRef(null), t = r.useRef(/* @__PURE__ */ new Map()).current; return /* @__PURE__ */ d(_, { scope: e, itemMap: t, collectionRef: o, children: l }); }; p.displayName = f; const a = s + "CollectionSlot", E = x(a), C = r.forwardRef( (c, e) => { const { scope: l, children: o } = c, t = m(a, l), n = M(e, t.collectionRef); return /* @__PURE__ */ d(E, { ref: n, children: o }); } ); C.displayName = a; const u = s + "CollectionItemSlot", R = "data-radix-collection-item", T = x(u), I = r.forwardRef( (c, e) => { const { scope: l, children: o, ...t } = c, n = r.useRef(null), S = M(e, n), i = m(u, l); return r.useEffect(() => (i.itemMap.set(n, { ref: n, ...t }), () => { i.itemMap.delete(n); })), /* @__PURE__ */ d(T, { [R]: "", ref: S, children: o }); } ); I.displayName = u; function O(c) { const e = m(s + "CollectionConsumer", c); return r.useCallback(() => { const o = e.collectionRef.current; if (!o) return []; const t = Array.from(o.querySelectorAll(`[${R}]`)); return Array.from(e.itemMap.values()).sort( (i, v) => t.indexOf(i.ref.current) - t.indexOf(v.ref.current) ); }, [e.collectionRef, e.itemMap]); } return [ { Provider: p, Slot: C, ItemSlot: I }, O, N ]; } export { D as c };