@scaffold-ai/react-service-provider
Version:
React context-based service provider for dependency injection.
298 lines (297 loc) • 9.39 kB
JavaScript
import re, { createContext as te, useContext as ne } from "react";
var T = { exports: {} }, _ = {};
/**
* @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 I;
function oe() {
if (I) return _;
I = 1;
var a = Symbol.for("react.transitional.element"), i = Symbol.for("react.fragment");
function l(d, s, u) {
var E = null;
if (u !== void 0 && (E = "" + u), s.key !== void 0 && (E = "" + s.key), "key" in s) {
u = {};
for (var v in s)
v !== "key" && (u[v] = s[v]);
} else u = s;
return s = u.ref, {
$$typeof: a,
type: d,
key: E,
ref: s !== void 0 ? s : null,
props: u
};
}
return _.Fragment = i, _.jsx = l, _.jsxs = l, _;
}
var R = {};
/**
* @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 F;
function ae() {
return F || (F = 1, process.env.NODE_ENV !== "production" && (function() {
function a(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === Q ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case p:
return "Fragment";
case J:
return "Profiler";
case q:
return "StrictMode";
case X:
return "Suspense";
case B:
return "SuspenseList";
case Z:
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 U:
return "Portal";
case V:
return (e.displayName || "Context") + ".Provider";
case z:
return (e._context.displayName || "Context") + ".Consumer";
case G:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case H:
return r = e.displayName || null, r !== null ? r : a(e.type) || "Memo";
case j:
r = e._payload, e = e._init;
try {
return a(e(r));
} catch {
}
}
return null;
}
function i(e) {
return "" + e;
}
function l(e) {
try {
i(e);
var r = !1;
} catch {
r = !0;
}
if (r) {
r = console;
var t = r.error, n = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t.call(
r,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
n
), i(e);
}
}
function d(e) {
if (e === p) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === j)
return "<...>";
try {
var r = a(e);
return r ? "<" + r + ">" : "<...>";
} catch {
return "<...>";
}
}
function s() {
var e = k.A;
return e === null ? null : e.getOwner();
}
function u() {
return Error("react-stack-top-frame");
}
function E(e) {
if (g.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function v(e, r) {
function t() {
y || (y = !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
));
}
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
function M() {
var e = a(this.type);
return N[e] || (N[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 W(e, r, t, n, f, c, w, O) {
return t = c.ref, e = {
$$typeof: h,
type: e,
key: r,
props: c,
_owner: f
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: M
}) : 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: w
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: O
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function x(e, r, t, n, f, c, w, O) {
var o = r.children;
if (o !== void 0)
if (n)
if (K(o)) {
for (n = 0; n < o.length; n++)
A(o[n]);
Object.freeze && Object.freeze(o);
} 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 A(o);
if (g.call(r, "key")) {
o = a(e);
var m = Object.keys(r).filter(function(ee) {
return ee !== "key";
});
n = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", $[o + n] || (m = 0 < m.length ? "{" + m.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} />`,
n,
o,
m,
o
), $[o + n] = !0);
}
if (o = null, t !== void 0 && (l(t), o = "" + t), E(r) && (l(r.key), o = "" + r.key), "key" in r) {
t = {};
for (var P in r)
P !== "key" && (t[P] = r[P]);
} else t = r;
return o && v(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), W(
e,
o,
c,
f,
s(),
t,
w,
O
);
}
function A(e) {
typeof e == "object" && e !== null && e.$$typeof === h && e._store && (e._store.validated = 1);
}
var b = re, h = Symbol.for("react.transitional.element"), U = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), J = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), V = Symbol.for("react.context"), G = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), H = Symbol.for("react.memo"), j = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), Q = Symbol.for("react.client.reference"), k = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, g = Object.prototype.hasOwnProperty, K = Array.isArray, S = console.createTask ? console.createTask : function() {
return null;
};
b = {
react_stack_bottom_frame: function(e) {
return e();
}
};
var y, N = {}, C = b.react_stack_bottom_frame.bind(
b,
u
)(), Y = S(d(u)), $ = {};
R.Fragment = p, R.jsx = function(e, r, t, n, f) {
var c = 1e4 > k.recentlyCreatedOwnerStacks++;
return x(
e,
r,
t,
!1,
n,
f,
c ? Error("react-stack-top-frame") : C,
c ? S(d(e)) : Y
);
}, R.jsxs = function(e, r, t, n, f) {
var c = 1e4 > k.recentlyCreatedOwnerStacks++;
return x(
e,
r,
t,
!0,
n,
f,
c ? Error("react-stack-top-frame") : C,
c ? S(d(e)) : Y
);
};
})()), R;
}
var D;
function se() {
return D || (D = 1, process.env.NODE_ENV === "production" ? T.exports = oe() : T.exports = ae()), T.exports;
}
var ue = se();
const L = te(null), ie = ({
value: a,
children: i
}) => /* @__PURE__ */ ue.jsx(L.Provider, { value: a, children: i }), le = (a) => {
const i = ne(L);
if (!i)
throw new Error("useService must be used within a ServiceProvider");
const l = i.find((d) => d.serviceId === a);
if (!l)
throw new Error(`Service with id ${a.description} not found`);
return l;
};
export {
ie as ServiceProvider,
le as useService
};