UNPKG

@anoki/fse-ui

Version:

FSE UI components library

72 lines (71 loc) 2.12 kB
import * as u from "react"; import { j as h } from "./index.es237.js"; function j(e, c) { const o = u.createContext(c), a = (r) => { const { children: t, ...n } = r, s = u.useMemo(() => n, Object.values(n)); return /* @__PURE__ */ h.jsx(o.Provider, { value: s, children: t }); }; a.displayName = e + "Provider"; function i(r) { const t = u.useContext(o); if (t) return t; if (c !== void 0) return c; throw new Error(`\`${r}\` must be used within \`${e}\``); } return [a, i]; } function w(e, c = []) { let o = []; function a(r, t) { const n = u.createContext(t), s = o.length; o = [...o, t]; const d = (m) => { var S; const { scope: x, children: C, ...p } = m, v = ((S = x == null ? void 0 : x[e]) == null ? void 0 : S[s]) || n, P = u.useMemo(() => p, Object.values(p)); return /* @__PURE__ */ h.jsx(v.Provider, { value: P, children: C }); }; d.displayName = r + "Provider"; function f(m, x) { var v; const C = ((v = x == null ? void 0 : x[e]) == null ? void 0 : v[s]) || n, p = u.useContext(C); if (p) return p; if (t !== void 0) return t; throw new Error(`\`${m}\` must be used within \`${r}\``); } return [d, f]; } const i = () => { const r = o.map((t) => u.createContext(t)); return function(n) { const s = (n == null ? void 0 : n[e]) || r; return u.useMemo( () => ({ [`__scope${e}`]: { ...n, [e]: s } }), [n, s] ); }; }; return i.scopeName = e, [a, l(i, ...c)]; } function l(...e) { const c = e[0]; if (e.length === 1) return c; const o = () => { const a = e.map((i) => ({ useScope: i(), scopeName: i.scopeName })); return function(r) { const t = a.reduce((n, { useScope: s, scopeName: d }) => { const m = s(r)[`__scope${d}`]; return { ...n, ...m }; }, {}); return u.useMemo(() => ({ [`__scope${c.scopeName}`]: t }), [t]); }; }; return o.scopeName = c.scopeName, o; } export { j as createContext, w as createContextScope }; //# sourceMappingURL=index.es464.js.map