@konstructio/ui
Version:
A set of reusable and customizable React components built for konstruct.io
121 lines (120 loc) • 3.75 kB
JavaScript
import { n as A, t as h } from "./dist-C4El7dZ5.js";
import { s as T } from "./dist-D_9sBzad.js";
import * as l from "react";
import m from "react";
import { jsx as I } from "react/jsx-runtime";
// @__NO_SIDE_EFFECTS__
function M(e) {
const t = /* @__PURE__ */ P(e), n = l.forwardRef((r, o) => {
const { children: c, ...i } = r, s = l.Children.toArray(c), R = s.find(b);
if (R) {
const f = R.props.children, S = s.map((y) => y === R ? l.Children.count(f) > 1 ? l.Children.only(null) : l.isValidElement(f) ? f.props.children : null : y);
return /* @__PURE__ */ I(t, {
...i,
ref: o,
children: l.isValidElement(f) ? l.cloneElement(f, void 0, S) : null
});
}
return /* @__PURE__ */ I(t, {
...i,
ref: o,
children: c
});
});
return n.displayName = `${e}.Slot`, n;
}
// @__NO_SIDE_EFFECTS__
function P(e) {
const t = l.forwardRef((n, r) => {
const { children: o, ...c } = n;
if (l.isValidElement(o)) {
const i = V(o), s = w(c, o.props);
return o.type !== l.Fragment && (s.ref = r ? h(r, i) : i), l.cloneElement(o, s);
}
return l.Children.count(o) > 1 ? l.Children.only(null) : null;
});
return t.displayName = `${e}.SlotClone`, t;
}
var v = /* @__PURE__ */ Symbol("radix.slottable");
function b(e) {
return l.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === v;
}
function w(e, t) {
const n = { ...t };
for (const r in t) {
const o = e[r], c = t[r];
/^on[A-Z]/.test(r) ? o && c ? n[r] = (...i) => {
const s = c(...i);
return o(...i), s;
} : o && (n[r] = o) : r === "style" ? n[r] = {
...o,
...c
} : r === "className" && (n[r] = [o, c].filter(Boolean).join(" "));
}
return {
...e,
...n
};
}
function V(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);
}
function F(e) {
const t = e + "CollectionProvider", [n, r] = T(t), [o, c] = n(t, {
collectionRef: { current: null },
itemMap: /* @__PURE__ */ new Map()
}), i = (d) => {
const { scope: a, children: u } = d, p = m.useRef(null), E = m.useRef(/* @__PURE__ */ new Map()).current;
return /* @__PURE__ */ I(o, {
scope: a,
itemMap: E,
collectionRef: p,
children: u
});
};
i.displayName = t;
const s = e + "CollectionSlot", R = /* @__PURE__ */ M(s), f = m.forwardRef((d, a) => {
const { scope: u, children: p } = d;
return /* @__PURE__ */ I(R, {
ref: A(a, c(s, u).collectionRef),
children: p
});
});
f.displayName = s;
const S = e + "CollectionItemSlot", y = "data-radix-collection-item", N = /* @__PURE__ */ M(S), g = m.forwardRef((d, a) => {
const { scope: u, children: p, ...E } = d, C = m.useRef(null), _ = A(a, C), x = c(S, u);
return m.useEffect(() => (x.itemMap.set(C, {
ref: C,
...E
}), () => {
x.itemMap.delete(C);
})), /* @__PURE__ */ I(N, {
[y]: "",
ref: _,
children: p
});
});
g.displayName = S;
function O(d) {
const a = c(e + "CollectionConsumer", d);
return m.useCallback(() => {
const u = a.collectionRef.current;
if (!u) return [];
const p = Array.from(u.querySelectorAll(`[${y}]`));
return Array.from(a.itemMap.values()).sort((E, C) => p.indexOf(E.ref.current) - p.indexOf(C.ref.current));
}, [a.collectionRef, a.itemMap]);
}
return [
{
Provider: i,
Slot: f,
ItemSlot: g
},
O,
r
];
}
export {
F as t
};