UNPKG

@anoki/fse-ui

Version:

FSE UI components library

50 lines (49 loc) 1.85 kB
import r from "react"; import { createContextScope as y } from "./index.es472.js"; import { useComposedRefs as S } from "./index.es471.js"; import { createSlot as M } from "./index.es481.js"; import { j as d } from "./index.es244.js"; function D(s) { const m = s + "CollectionProvider", [A, E] = y(m), [N, f] = A( m, { 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.jsx(N, { scope: e, itemMap: t, collectionRef: o, children: l }); }; p.displayName = m; const a = s + "CollectionSlot", _ = M(a), C = r.forwardRef( (c, e) => { const { scope: l, children: o } = c, t = f(a, l), n = S(e, t.collectionRef); return /* @__PURE__ */ d.jsx(_, { ref: n, children: o }); } ); C.displayName = a; const u = s + "CollectionItemSlot", R = "data-radix-collection-item", T = M(u), x = r.forwardRef( (c, e) => { const { scope: l, children: o, ...t } = c, n = r.useRef(null), I = S(e, n), i = f(u, l); return r.useEffect(() => (i.itemMap.set(n, { ref: n, ...t }), () => void i.itemMap.delete(n))), /* @__PURE__ */ d.jsx(T, { [R]: "", ref: I, children: o }); } ); x.displayName = u; function O(c) { const e = f(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: x }, O, E ]; } export { D as createCollection }; //# sourceMappingURL=index.es482.js.map