react-slottable
Version:
Package that allows to turn react components into slottable ones
375 lines (374 loc) • 11.2 kB
JavaScript
import ce, { createContext as le, useState as z, useRef as ue, memo as ie, useContext as q, useEffect as G, useCallback as C, useMemo as fe } from "react";
var x = { exports: {} }, p = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var U;
function me() {
if (U)
return p;
U = 1;
var n = Symbol.for("react.transitional.element"), u = Symbol.for("react.fragment");
function t(i, a, l) {
var f = null;
if (l !== void 0 && (f = "" + l), a.key !== void 0 && (f = "" + a.key), "key" in a) {
l = {};
for (var m in a)
m !== "key" && (l[m] = a[m]);
} else
l = a;
return a = l.ref, {
$$typeof: n,
type: i,
key: f,
ref: a !== void 0 ? a : null,
props: l
};
}
return p.Fragment = u, p.jsx = t, p.jsxs = t, p;
}
var b = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var W;
function de() {
return W || (W = 1, process.env.NODE_ENV !== "production" && function() {
function n(e) {
if (e == null)
return null;
if (typeof e == "function")
return e.$$typeof === oe ? null : e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case A:
return "Fragment";
case H:
return "Profiler";
case B:
return "StrictMode";
case ee:
return "Suspense";
case re:
return "SuspenseList";
case ne:
return "Activity";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case X:
return "Portal";
case Q:
return e.displayName || "Context";
case Z:
return (e._context.displayName || "Context") + ".Consumer";
case K:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case te:
return r = e.displayName || null, r !== null ? r : n(e.type) || "Memo";
case P:
r = e._payload, e = e._init;
try {
return n(e(r));
} catch {
}
}
return null;
}
function u(e) {
return "" + e;
}
function t(e) {
try {
u(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var o = r.error, s = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return o.call(
r,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
s
), u(e);
}
}
function i(e) {
if (e === A)
return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === P)
return "<...>";
try {
var r = n(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function a() {
var e = h.A;
return e === null ? null : e.getOwner();
}
function l() {
return Error("react-stack-top-frame");
}
function f(e) {
if ($.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function m(e, r) {
function o() {
F || (F = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
r
));
}
o.isReactWarning = !0, Object.defineProperty(e, "key", {
get: o,
configurable: !0
});
}
function v() {
var e = n(this.type);
return I[e] || (I[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function O(e, r, o, s, g, w) {
var c = o.ref;
return e = {
$$typeof: Y,
type: e,
key: r,
props: o,
_owner: s
}, (c !== void 0 ? c : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: v
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(e, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: g
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: w
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function R(e, r, o, s, g, w) {
var c = r.children;
if (c !== void 0)
if (s)
if (ae(c)) {
for (s = 0; s < c.length; s++)
_(c[s]);
Object.freeze && Object.freeze(c);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else
_(c);
if ($.call(r, "key")) {
c = n(e);
var E = Object.keys(r).filter(function(se) {
return se !== "key";
});
s = 0 < E.length ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}", M[c + s] || (E = 0 < E.length ? "{" + E.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
s,
c,
E,
c
), M[c + s] = !0);
}
if (c = null, o !== void 0 && (t(o), c = "" + o), f(r) && (t(r.key), c = "" + r.key), "key" in r) {
o = {};
for (var y in r)
y !== "key" && (o[y] = r[y]);
} else
o = r;
return c && m(
o,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), O(
e,
c,
o,
a(),
g,
w
);
}
function _(e) {
T(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === P && (e._payload.status === "fulfilled" ? T(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
}
function T(e) {
return typeof e == "object" && e !== null && e.$$typeof === Y;
}
var S = ce, Y = Symbol.for("react.transitional.element"), X = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), B = Symbol.for("react.strict_mode"), H = Symbol.for("react.profiler"), Z = Symbol.for("react.consumer"), Q = Symbol.for("react.context"), K = Symbol.for("react.forward_ref"), ee = Symbol.for("react.suspense"), re = Symbol.for("react.suspense_list"), te = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), ne = Symbol.for("react.activity"), oe = Symbol.for("react.client.reference"), h = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, $ = Object.prototype.hasOwnProperty, ae = Array.isArray, j = console.createTask ? console.createTask : function() {
return null;
};
S = {
react_stack_bottom_frame: function(e) {
return e();
}
};
var F, I = {}, D = S.react_stack_bottom_frame.bind(
S,
l
)(), L = j(i(l)), M = {};
b.Fragment = A, b.jsx = function(e, r, o) {
var s = 1e4 > h.recentlyCreatedOwnerStacks++;
return R(
e,
r,
o,
!1,
s ? Error("react-stack-top-frame") : D,
s ? j(i(e)) : L
);
}, b.jsxs = function(e, r, o) {
var s = 1e4 > h.recentlyCreatedOwnerStacks++;
return R(
e,
r,
o,
!0,
s ? Error("react-stack-top-frame") : D,
s ? j(i(e)) : L
);
};
}()), b;
}
(function(n) {
process.env.NODE_ENV === "production" ? n.exports = me() : n.exports = de();
})(x);
const k = x.exports.Fragment, d = x.exports.jsx, N = le({
slots: {},
hasSlot: () => !1,
registerSlot: () => {
},
getSlot: () => /* @__PURE__ */ d(k, {})
}), _e = ({
children: n
}) => {
const [, u] = z(0), t = ue({}), i = (f) => f in t, a = (f, m) => {
t.current = {
...t.current,
[f]: m
}, u(new Date().getTime());
}, l = (f) => t.current[f];
return /* @__PURE__ */ d(N.Provider, {
value: {
slots: t.current,
hasSlot: i,
registerSlot: a,
getSlot: l
},
children: n
});
}, V = ie(({
name: n,
children: u
}) => {
const {
registerSlot: t
} = q(N);
return G(() => t(n, u), [u]), /* @__PURE__ */ d(k, {});
}), J = (n) => {
const [u, ...t] = n.replace(/[-_\s.]+(.)?/g, (i, a) => a ? a.toUpperCase() : "");
return `${u.toUpperCase()}${t.join("")}`;
}, be = (n, u) => {
const t = (i) => /* @__PURE__ */ d(_e, {
children: /* @__PURE__ */ d(n, {
...i
})
});
return Object.assign(t, {
Slot: V
}), u.forEach((i) => {
const a = J(i);
Object.assign(t, {
[a]: ({
children: l
}) => /* @__PURE__ */ d(V, {
name: i,
children: l
})
});
}), t;
}, Ee = (n = !1) => {
const [u, t] = z(n), i = C(() => t((f) => !f), []), a = C(() => t(!0), []), l = C(() => t(!1), []);
return [u, { setValue: t, toggle: i, on: a, off: l }];
}, ve = (n) => {
const {
getSlot: u
} = q(N), [t, {
on: i
}] = Ee(!1);
return G(i, []), fe(
() => n.reduce((l, f) => {
const m = J(f), v = ({
children: O,
...R
}) => {
const _ = u(f), T = typeof _ == "function" ? _(R) : _;
return t ? /* @__PURE__ */ d(k, {
children: T || O
}) : /* @__PURE__ */ d(k, {});
};
return v.displayName = m, {
...l,
[m]: v
};
}, {}),
[t]
);
};
export {
V as Slot,
N as SlotContext,
_e as SlotProvider,
ve as useSlots,
be as withSlots
};