UNPKG

@konstructio/ui

Version:

A set of reusable and customizable React components built for konstruct.io

224 lines (223 loc) 6.1 kB
import { t as S } from "./dist-C4El7dZ5.js"; import * as r from "react"; import * as w from "react-dom"; import { jsx as m } from "react/jsx-runtime"; function F(e, t) { const n = r.createContext(t), s = (c) => { const { children: i, ...u } = c, a = r.useMemo(() => u, Object.values(u)); return /* @__PURE__ */ m(n.Provider, { value: a, children: i }); }; s.displayName = e + "Provider"; function o(c) { const i = r.useContext(n); if (i) return i; if (t !== void 0) return t; throw new Error(`\`${c}\` must be used within \`${e}\``); } return [s, o]; } function V(e, t = []) { let n = []; function s(c, i) { const u = r.createContext(i), a = n.length; n = [...n, i]; const l = (d) => { const { scope: v, children: C, ...p } = d, h = v?.[e]?.[a] || u, y = r.useMemo(() => p, Object.values(p)); return /* @__PURE__ */ m(h.Provider, { value: y, children: C }); }; l.displayName = c + "Provider"; function f(d, v) { const C = v?.[e]?.[a] || u, p = r.useContext(C); if (p) return p; if (i !== void 0) return i; throw new Error(`\`${d}\` must be used within \`${c}\``); } return [l, f]; } const o = () => { const c = n.map((i) => r.createContext(i)); return function(u) { const a = u?.[e] || c; return r.useMemo(() => ({ [`__scope${e}`]: { ...u, [e]: a } }), [u, a]); }; }; return o.scopeName = e, [s, E(o, ...t)]; } function E(...e) { const t = e[0]; if (e.length === 1) return t; const n = () => { const s = e.map((o) => ({ useScope: o(), scopeName: o.scopeName })); return function(c) { const i = s.reduce((u, { useScope: a, scopeName: l }) => { const f = a(c)[`__scope${l}`]; return { ...u, ...f }; }, {}); return r.useMemo(() => ({ [`__scope${t.scopeName}`]: i }), [i]); }; }; return n.scopeName = t.scopeName, n; } var W = !!(typeof window < "u" && window.document && window.document.createElement); function A(e, t, { checkForDefaultPrevented: n = !0 } = {}) { return function(o) { if (e?.(o), n === !1 || !o.defaultPrevented) return t?.(o); }; } var x = globalThis?.document ? r.useLayoutEffect : () => { }, g = r[" useInsertionEffect ".trim().toString()] || x; function L({ prop: e, defaultProp: t, onChange: n = () => { }, caller: s }) { const [o, c, i] = b({ defaultProp: t, onChange: n }), u = e !== void 0, a = u ? e : o; { const l = r.useRef(e !== void 0); r.useEffect(() => { const f = l.current; f !== u && console.warn(`${s} is changing from ${f ? "controlled" : "uncontrolled"} to ${u ? "controlled" : "uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`), l.current = u; }, [u, s]); } return [a, r.useCallback((l) => { if (u) { const f = P(l) ? l(e) : l; f !== e && i.current?.(f); } else c(l); }, [ u, e, c, i ])]; } function b({ defaultProp: e, onChange: t }) { const [n, s] = r.useState(e), o = r.useRef(n), c = r.useRef(t); return g(() => { c.current = t; }, [t]), r.useEffect(() => { o.current !== n && (c.current?.(n), o.current = n); }, [n, o]), [ n, s, c ]; } function P(e) { return typeof e == "function"; } // @__NO_SIDE_EFFECTS__ function R(e) { const t = /* @__PURE__ */ $(e), n = r.forwardRef((s, o) => { const { children: c, ...i } = s, u = r.Children.toArray(c), a = u.find(O); if (a) { const l = a.props.children, f = u.map((d) => d === a ? r.Children.count(l) > 1 ? r.Children.only(null) : r.isValidElement(l) ? l.props.children : null : d); return /* @__PURE__ */ m(t, { ...i, ref: o, children: r.isValidElement(l) ? r.cloneElement(l, void 0, f) : null }); } return /* @__PURE__ */ m(t, { ...i, ref: o, children: c }); }); return n.displayName = `${e}.Slot`, n; } // @__NO_SIDE_EFFECTS__ function $(e) { const t = r.forwardRef((n, s) => { const { children: o, ...c } = n; if (r.isValidElement(o)) { const i = I(o), u = D(c, o.props); return o.type !== r.Fragment && (u.ref = s ? S(s, i) : i), r.cloneElement(o, u); } return r.Children.count(o) > 1 ? r.Children.only(null) : null; }); return t.displayName = `${e}.SlotClone`, t; } var _ = /* @__PURE__ */ Symbol("radix.slottable"); function O(e) { return r.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === _; } function D(e, t) { const n = { ...t }; for (const s in t) { const o = e[s], c = t[s]; /^on[A-Z]/.test(s) ? o && c ? n[s] = (...i) => { const u = c(...i); return o(...i), u; } : o && (n[s] = o) : s === "style" ? n[s] = { ...o, ...c } : s === "className" && (n[s] = [o, c].filter(Boolean).join(" ")); } return { ...e, ...n }; } function I(e) { let t = Object.getOwnPropertyDescriptor(e.props, "ref")?.get, n = t && "isReactWarning" in t && t.isReactWarning; return n ? e.ref : (t = Object.getOwnPropertyDescriptor(e, "ref")?.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref); } var T = [ "a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "select", "span", "svg", "ul" ].reduce((e, t) => { const n = /* @__PURE__ */ R(`Primitive.${t}`), s = r.forwardRef((o, c) => { const { asChild: i, ...u } = o, a = i ? n : t; return typeof window < "u" && (window[/* @__PURE__ */ Symbol.for("radix-ui")] = !0), /* @__PURE__ */ m(a, { ...u, ref: c }); }); return s.displayName = `Primitive.${t}`, { ...e, [t]: s }; }, {}); function B(e, t) { e && w.flushSync(() => e.dispatchEvent(t)); } export { A as a, x as i, B as n, F as o, L as r, V as s, T as t };