@react-formgen/json-schema
Version:
A headless, type-safe, customizable, and super simple React form generator.
1,422 lines (1,421 loc) • 45.4 kB
JavaScript
import L, { createContext as ye, useContext as ae } from "react";
function Ie(r) {
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
}
var de = { exports: {} }, J = {};
/**
* @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 ve;
function Fe() {
if (ve) return J;
ve = 1;
var r = Symbol.for("react.transitional.element"), o = Symbol.for("react.fragment");
function i(s, t, n) {
var p = null;
if (n !== void 0 && (p = "" + n), t.key !== void 0 && (p = "" + t.key), "key" in t) {
n = {};
for (var d in t)
d !== "key" && (n[d] = t[d]);
} else n = t;
return t = n.ref, {
$$typeof: r,
type: s,
key: p,
ref: t !== void 0 ? t : null,
props: n
};
}
return J.Fragment = o, J.jsx = i, J.jsxs = i, J;
}
var X = {};
/**
* @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 be;
function Ve() {
return be || (be = 1, process.env.NODE_ENV !== "production" && function() {
function r(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === te ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case c:
return "Fragment";
case b:
return "Profiler";
case _:
return "StrictMode";
case N:
return "Suspense";
case h:
return "SuspenseList";
case re:
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 v:
return "Portal";
case w:
return (e.displayName || "Context") + ".Provider";
case T:
return (e._context.displayName || "Context") + ".Consumer";
case P:
var a = e.render;
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case j:
return a = e.displayName || null, a !== null ? a : r(e.type) || "Memo";
case D:
a = e._payload, e = e._init;
try {
return r(e(a));
} catch {
}
}
return null;
}
function o(e) {
return "" + e;
}
function i(e) {
try {
o(e);
var a = !1;
} catch {
a = !0;
}
if (a) {
a = console;
var E = a.error, O = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return E.call(
a,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
O
), o(e);
}
}
function s(e) {
if (e === c) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === D)
return "<...>";
try {
var a = r(e);
return a ? "<" + a + ">" : "<...>";
} catch {
return "<...>";
}
}
function t() {
var e = I.A;
return e === null ? null : e.getOwner();
}
function n() {
return Error("react-stack-top-frame");
}
function p(e) {
if (W.call(e, "key")) {
var a = Object.getOwnPropertyDescriptor(e, "key").get;
if (a && a.isReactWarning) return !1;
}
return e.key !== void 0;
}
function d(e, a) {
function E() {
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)",
a
));
}
E.isReactWarning = !0, Object.defineProperty(e, "key", {
get: E,
configurable: !0
});
}
function S() {
var e = r(this.type);
return z[e] || (z[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 m(e, a, E, O, x, R, V, $) {
return E = R.ref, e = {
$$typeof: l,
type: e,
key: a,
props: R,
_owner: x
}, (E !== void 0 ? E : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: S
}) : 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: V
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: $
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function u(e, a, E, O, x, R, V, $) {
var g = a.children;
if (g !== void 0)
if (O)
if (ne(g)) {
for (O = 0; O < g.length; O++)
y(g[O]);
Object.freeze && Object.freeze(g);
} 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 y(g);
if (W.call(a, "key")) {
g = r(e);
var k = Object.keys(a).filter(function(oe) {
return oe !== "key";
});
O = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", H[g + O] || (k = 0 < k.length ? "{" + k.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} />`,
O,
g,
k,
g
), H[g + O] = !0);
}
if (g = null, E !== void 0 && (i(E), g = "" + E), p(a) && (i(a.key), g = "" + a.key), "key" in a) {
E = {};
for (var M in a)
M !== "key" && (E[M] = a[M]);
} else E = a;
return g && d(
E,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), m(
e,
g,
R,
x,
t(),
E,
V,
$
);
}
function y(e) {
typeof e == "object" && e !== null && e.$$typeof === l && e._store && (e._store.validated = 1);
}
var f = L, l = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), c = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), T = Symbol.for("react.consumer"), w = Symbol.for("react.context"), P = Symbol.for("react.forward_ref"), N = Symbol.for("react.suspense"), h = Symbol.for("react.suspense_list"), j = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), re = Symbol.for("react.activity"), te = Symbol.for("react.client.reference"), I = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, W = Object.prototype.hasOwnProperty, ne = Array.isArray, F = console.createTask ? console.createTask : function() {
return null;
};
f = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var Y, z = {}, G = f["react-stack-bottom-frame"].bind(
f,
n
)(), B = F(s(n)), H = {};
X.Fragment = c, X.jsx = function(e, a, E, O, x) {
var R = 1e4 > I.recentlyCreatedOwnerStacks++;
return u(
e,
a,
E,
!1,
O,
x,
R ? Error("react-stack-top-frame") : G,
R ? F(s(e)) : B
);
}, X.jsxs = function(e, a, E, O, x) {
var R = 1e4 > I.recentlyCreatedOwnerStacks++;
return u(
e,
a,
E,
!0,
O,
x,
R ? Error("react-stack-top-frame") : G,
R ? F(s(e)) : B
);
};
}()), X;
}
process.env.NODE_ENV === "production" ? de.exports = Fe() : de.exports = Ve();
var C = de.exports, $e = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
const _e = (r) => {
let o;
const i = /* @__PURE__ */ new Set(), s = (d, S) => {
const m = typeof d == "function" ? d(o) : d;
if (!Object.is(m, o)) {
const u = o;
o = S ?? (typeof m != "object" || m === null) ? m : Object.assign({}, o, m), i.forEach((y) => y(o, u));
}
}, t = () => o, n = { setState: s, getState: t, getInitialState: () => p, subscribe: (d) => (i.add(d), () => i.delete(d)), destroy: () => {
($e ? "production" : void 0) !== "production" && console.warn(
"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
), i.clear();
} }, p = o = r(s, t, n);
return n;
}, Ee = (r) => r ? _e(r) : _e;
var fe = { exports: {} }, se = {}, ie = { exports: {} }, le = {};
/**
* @license React
* use-sync-external-store-shim.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 Se;
function Me() {
if (Se) return le;
Se = 1;
var r = L;
function o(y, f) {
return y === f && (y !== 0 || 1 / y === 1 / f) || y !== y && f !== f;
}
var i = typeof Object.is == "function" ? Object.is : o, s = r.useState, t = r.useEffect, n = r.useLayoutEffect, p = r.useDebugValue;
function d(y, f) {
var l = f(), v = s({ inst: { value: l, getSnapshot: f } }), c = v[0].inst, _ = v[1];
return n(
function() {
c.value = l, c.getSnapshot = f, S(c) && _({ inst: c });
},
[y, l, f]
), t(
function() {
return S(c) && _({ inst: c }), y(function() {
S(c) && _({ inst: c });
});
},
[y]
), p(l), l;
}
function S(y) {
var f = y.getSnapshot;
y = y.value;
try {
var l = f();
return !i(y, l);
} catch {
return !0;
}
}
function m(y, f) {
return f();
}
var u = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? m : d;
return le.useSyncExternalStore = r.useSyncExternalStore !== void 0 ? r.useSyncExternalStore : u, le;
}
var Oe = {};
/**
* @license React
* use-sync-external-store-shim.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 ge;
function Ue() {
return ge || (ge = 1, process.env.NODE_ENV !== "production" && function() {
function r(l, v) {
return l === v && (l !== 0 || 1 / l === 1 / v) || l !== l && v !== v;
}
function o(l, v) {
u || t.startTransition === void 0 || (u = !0, console.error(
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
));
var c = v();
if (!y) {
var _ = v();
n(c, _) || (console.error(
"The result of getSnapshot should be cached to avoid an infinite loop"
), y = !0);
}
_ = p({
inst: { value: c, getSnapshot: v }
});
var b = _[0].inst, T = _[1];
return S(
function() {
b.value = c, b.getSnapshot = v, i(b) && T({ inst: b });
},
[l, c, v]
), d(
function() {
return i(b) && T({ inst: b }), l(function() {
i(b) && T({ inst: b });
});
},
[l]
), m(c), c;
}
function i(l) {
var v = l.getSnapshot;
l = l.value;
try {
var c = v();
return !n(l, c);
} catch {
return !0;
}
}
function s(l, v) {
return v();
}
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var t = L, n = typeof Object.is == "function" ? Object.is : r, p = t.useState, d = t.useEffect, S = t.useLayoutEffect, m = t.useDebugValue, u = !1, y = !1, f = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? s : o;
Oe.useSyncExternalStore = t.useSyncExternalStore !== void 0 ? t.useSyncExternalStore : f, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
}()), Oe;
}
var Te;
function Ne() {
return Te || (Te = 1, process.env.NODE_ENV === "production" ? ie.exports = Me() : ie.exports = Ue()), ie.exports;
}
/**
* @license React
* use-sync-external-store-shim/with-selector.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 he;
function We() {
if (he) return se;
he = 1;
var r = L, o = Ne();
function i(m, u) {
return m === u && (m !== 0 || 1 / m === 1 / u) || m !== m && u !== u;
}
var s = typeof Object.is == "function" ? Object.is : i, t = o.useSyncExternalStore, n = r.useRef, p = r.useEffect, d = r.useMemo, S = r.useDebugValue;
return se.useSyncExternalStoreWithSelector = function(m, u, y, f, l) {
var v = n(null);
if (v.current === null) {
var c = { hasValue: !1, value: null };
v.current = c;
} else c = v.current;
v = d(
function() {
function b(h) {
if (!T) {
if (T = !0, w = h, h = f(h), l !== void 0 && c.hasValue) {
var j = c.value;
if (l(j, h))
return P = j;
}
return P = h;
}
if (j = P, s(w, h)) return j;
var D = f(h);
return l !== void 0 && l(j, D) ? (w = h, j) : (w = h, P = D);
}
var T = !1, w, P, N = y === void 0 ? null : y;
return [
function() {
return b(u());
},
N === null ? void 0 : function() {
return b(N());
}
];
},
[u, y, f, l]
);
var _ = t(m, v[0], v[1]);
return p(
function() {
c.hasValue = !0, c.value = _;
},
[_]
), S(_), _;
}, se;
}
var Re = {};
/**
* @license React
* use-sync-external-store-shim/with-selector.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 we;
function Ye() {
return we || (we = 1, process.env.NODE_ENV !== "production" && function() {
function r(m, u) {
return m === u && (m !== 0 || 1 / m === 1 / u) || m !== m && u !== u;
}
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var o = L, i = Ne(), s = typeof Object.is == "function" ? Object.is : r, t = i.useSyncExternalStore, n = o.useRef, p = o.useEffect, d = o.useMemo, S = o.useDebugValue;
Re.useSyncExternalStoreWithSelector = function(m, u, y, f, l) {
var v = n(null);
if (v.current === null) {
var c = { hasValue: !1, value: null };
v.current = c;
} else c = v.current;
v = d(
function() {
function b(h) {
if (!T) {
if (T = !0, w = h, h = f(h), l !== void 0 && c.hasValue) {
var j = c.value;
if (l(j, h))
return P = j;
}
return P = h;
}
if (j = P, s(w, h))
return j;
var D = f(h);
return l !== void 0 && l(j, D) ? (w = h, j) : (w = h, P = D);
}
var T = !1, w, P, N = y === void 0 ? null : y;
return [
function() {
return b(u());
},
N === null ? void 0 : function() {
return b(N());
}
];
},
[u, y, f, l]
);
var _ = t(m, v[0], v[1]);
return p(
function() {
c.hasValue = !0, c.value = _;
},
[_]
), S(_), _;
}, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
}()), Re;
}
process.env.NODE_ENV === "production" ? fe.exports = We() : fe.exports = Ye();
var ze = fe.exports;
const Ge = /* @__PURE__ */ Ie(ze);
var Be = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
const { useDebugValue: He } = L, { useSyncExternalStoreWithSelector: Je } = Ge;
let je = !1;
const qe = (r) => r;
function Ke(r, o = qe, i) {
(Be ? "production" : void 0) !== "production" && i && !je && (console.warn(
"[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
), je = !0);
const s = Je(
r.subscribe,
r.getState,
r.getServerState || r.getInitialState,
o,
i
);
return He(s), s;
}
var ue = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
const pe = /* @__PURE__ */ new Map(), Z = (r) => {
const o = pe.get(r);
return o ? Object.fromEntries(
Object.entries(o.stores).map(([i, s]) => [i, s.getState()])
) : {};
}, Xe = (r, o, i) => {
if (r === void 0)
return {
type: "untracked",
connection: o.connect(i)
};
const s = pe.get(i.name);
if (s)
return { type: "tracked", store: r, ...s };
const t = {
connection: o.connect(i),
stores: {}
};
return pe.set(i.name, t), { type: "tracked", store: r, ...t };
}, Ze = (r, o = {}) => (i, s, t) => {
const { enabled: n, anonymousActionType: p, store: d, ...S } = o;
let m;
try {
m = (n ?? (ue ? "production" : void 0) !== "production") && window.__REDUX_DEVTOOLS_EXTENSION__;
} catch {
}
if (!m)
return (ue ? "production" : void 0) !== "production" && n && console.warn(
"[zustand devtools middleware] Please install/enable Redux devtools extension"
), r(i, s, t);
const { connection: u, ...y } = Xe(d, m, S);
let f = !0;
t.setState = (c, _, b) => {
const T = i(c, _);
if (!f) return T;
const w = b === void 0 ? { type: p || "anonymous" } : typeof b == "string" ? { type: b } : b;
return d === void 0 ? (u == null || u.send(w, s()), T) : (u == null || u.send(
{
...w,
type: `${d}/${w.type}`
},
{
...Z(S.name),
[d]: t.getState()
}
), T);
};
const l = (...c) => {
const _ = f;
f = !1, i(...c), f = _;
}, v = r(t.setState, s, t);
if (y.type === "untracked" ? u == null || u.init(v) : (y.stores[y.store] = t, u == null || u.init(
Object.fromEntries(
Object.entries(y.stores).map(([c, _]) => [
c,
c === y.store ? v : _.getState()
])
)
)), t.dispatchFromDevtools && typeof t.dispatch == "function") {
let c = !1;
const _ = t.dispatch;
t.dispatch = (...b) => {
(ue ? "production" : void 0) !== "production" && b[0].type === "__setState" && !c && (console.warn(
'[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'
), c = !0), _(...b);
};
}
return u.subscribe((c) => {
var _;
switch (c.type) {
case "ACTION":
if (typeof c.payload != "string") {
console.error(
"[zustand devtools middleware] Unsupported action format"
);
return;
}
return ce(
c.payload,
(b) => {
if (b.type === "__setState") {
if (d === void 0) {
l(b.state);
return;
}
Object.keys(b.state).length !== 1 && console.error(
`
[zustand devtools middleware] Unsupported __setState action format.
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
`
);
const T = b.state[d];
if (T == null)
return;
JSON.stringify(t.getState()) !== JSON.stringify(T) && l(T);
return;
}
t.dispatchFromDevtools && typeof t.dispatch == "function" && t.dispatch(b);
}
);
case "DISPATCH":
switch (c.payload.type) {
case "RESET":
return l(v), d === void 0 ? u == null ? void 0 : u.init(t.getState()) : u == null ? void 0 : u.init(Z(S.name));
case "COMMIT":
if (d === void 0) {
u == null || u.init(t.getState());
return;
}
return u == null ? void 0 : u.init(Z(S.name));
case "ROLLBACK":
return ce(c.state, (b) => {
if (d === void 0) {
l(b), u == null || u.init(t.getState());
return;
}
l(b[d]), u == null || u.init(Z(S.name));
});
case "JUMP_TO_STATE":
case "JUMP_TO_ACTION":
return ce(c.state, (b) => {
if (d === void 0) {
l(b);
return;
}
JSON.stringify(t.getState()) !== JSON.stringify(b[d]) && l(b[d]);
});
case "IMPORT_STATE": {
const { nextLiftedState: b } = c.payload, T = (_ = b.computedStates.slice(-1)[0]) == null ? void 0 : _.state;
if (!T) return;
l(d === void 0 ? T : T[d]), u == null || u.send(
null,
// FIXME no-any
b
);
return;
}
case "PAUSE_RECORDING":
return f = !f;
}
return;
}
}), v;
}, Qe = Ze, ce = (r, o) => {
let i;
try {
i = JSON.parse(r);
} catch (s) {
console.error(
"[zustand devtools middleware] Could not parse the received json",
s
);
}
i !== void 0 && o(i);
}, er = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
let rr = (r = 21) => {
let o = "", i = crypto.getRandomValues(new Uint8Array(r |= 0));
for (; r--; )
o += er[i[r] & 63];
return o;
};
const tr = (r, o, i, s, t = !1) => {
const n = {
...i(o),
...r
}, p = (d) => ({
schema: o,
formData: n,
errors: null,
readonly: s || !1,
setFormData: (S, m) => d((u) => {
const y = { ...u.formData };
let f = y;
return S.slice(0, -1).forEach((l) => {
f[l] || (f[l] = {}), f = f[l];
}), f[S[S.length - 1]] = m, { formData: y };
}),
setErrors: (S) => d({ errors: S }),
setReadonly: (S) => d({ readonly: S })
});
if (t) {
const d = `FormStore_${rr()}`;
return console.warn(
`WARNING: Zustand Devtools is enabled for FormStore: ${d}. This should be disabled in production.`
), Ee(
Qe(p, { name: d, enabled: t })
);
}
return Ee(p);
}, xe = ye(null), Ae = ye(null), Pe = ye(null), nr = (r, o, i, s, t) => {
const n = ({
initialData: m = {},
schema: u,
children: y,
templates: f = t,
readonly: l = !1,
renderTemplate: v = i,
enableDevtools: c = !1
}) => {
const _ = L.useRef(null);
return _.current || (_.current = tr(
m,
u,
r,
l,
c
)), f ? /* @__PURE__ */ C.jsx(xe.Provider, { value: _.current, children: /* @__PURE__ */ C.jsx(Ae.Provider, { value: f, children: /* @__PURE__ */ C.jsx(Pe.Provider, { value: v, children: y }) }) }) : (console.error("Templates are missing. Please provide base Templates."), /* @__PURE__ */ C.jsx("div", { children: "Templates are missing. Please provide base Templates." }));
}, p = (m) => {
const u = ae(xe);
if (!u)
throw console.error(
"FormContext is missing. Ensure you are within a FormProvider."
), new Error("useFormContext must be used within a FormProvider");
return Ke(u, m);
}, d = (m, u = null) => {
const y = p((l) => l.formData), f = p(
(l) => l.setFormData
);
return [m.reduce((l, v) => l == null ? void 0 : l[v], y) ?? u, (l) => f(m, l)];
}, S = (m) => {
const u = p((y) => y.errors);
return o(u ?? [], m);
};
return {
FormProvider: n,
useFormContext: p,
useFormDataAtPath: d,
useErrorsAtPath: S,
useArrayTemplate: (m, u, y = null) => {
const [f, l] = d(
m,
y
), v = S(m);
return {
valueAtPath: f,
errorsAtPath: v,
moveItem: (c, _) => {
const b = [...f], [T] = b.splice(c, 1);
b.splice(_ === "up" ? c - 1 : c + 1, 0, T), l(b);
},
removeItem: (c) => {
const _ = [...f];
_.splice(c, 1), l(_);
},
addItem: () => {
l([...f, u()]);
}
};
},
useTemplates: () => {
const m = ae(Ae);
if (!m)
throw console.error(
"TemplatesContext is missing. Ensure you are within a FormProvider with templates provided."
), new Error(
"useTemplates must be used within a FormProvider with templates provided"
);
return m;
},
useRenderTemplate: () => {
const m = ae(Pe);
if (!m)
throw console.error(
"RenderTemplateContext is missing. Ensure you are within a FormProvider with renderTemplate provided."
), new Error(
"useRenderTemplate must be used within a FormProvider with renderTemplate provided"
);
return m;
},
Form: ({
schema: m,
initialData: u = {},
onSubmit: y = (T) => console.warn(
"This is a default `onSubmit` function. You should override this if you want to do something with the form data.",
T
),
onError: f = (T, w) => console.error(
"This is a default `onError` function. You should override this if you want to do something with the form errors.",
T,
w
),
templates: l = t,
formRoot: v = s,
readonly: c = !1,
renderTemplate: _ = i,
enableDevtools: b = !1
}) => v ? l ? _ ? /* @__PURE__ */ C.jsx(
n,
{
schema: m,
initialData: u,
templates: l,
readonly: c,
renderTemplate: _,
enableDevtools: b,
children: /* @__PURE__ */ C.jsx(v, { onSubmit: y, onError: f })
}
) : (console.error(
"RenderTemplate component is missing. Please provide a base RenderTemplate."
), /* @__PURE__ */ C.jsx("div", { children: "RenderTemplate component is missing. Please provide a base RenderTemplate." })) : (console.error("Templates are missing. Please provide base Templates."), /* @__PURE__ */ C.jsx("div", { children: "Templates are missing. Please provide base Templates." })) : (console.error(
"FormRoot is missing. Please provide a base FormRoot component."
), /* @__PURE__ */ C.jsx("div", { children: "FormRoot is missing. Please provide a base FormRoot component." }))
};
}, U = (r, o) => {
if (r.$ref)
try {
const i = r.$ref.replace("#/definitions/", "").split("/");
let s = o;
for (const t of i)
if (s = s[t], !s)
throw new Error(`Could not resolve reference: ${r.$ref}`);
return s;
} catch (i) {
return console.error("Error resolving schema reference:", i), r;
}
return r;
}, Q = (r, o, i, s) => {
switch (r = U(r, o), r.type) {
case "object": {
const t = {};
for (const n in r.properties)
t[n] = Q(
r.properties[n],
o,
r,
n
);
return t;
}
case "array":
if (Array.isArray(r.items)) {
const t = r.items;
if (Array.isArray(r.default)) {
const n = [];
for (let p = 0; p < t.length; p++) {
const d = t[p];
ee(r.default[p], d, o) ? n.push(r.default[p]) : n.push(
Q(
d,
o,
r,
s
)
);
}
return n;
} else {
let n = !1;
if (i && s && Array.isArray(i.required) && (n = i.required.includes(s)), n) {
const p = [];
if (t.some((d) => d.default))
for (const d of t)
p.push(
Q(
d,
o,
r,
s
)
);
return p;
} else
return;
}
} else {
if (Array.isArray(r.default)) {
const t = r.items, n = r.default.filter(
(p) => ee(p, t, o)
);
return n.length > 0 ? n : [];
}
return [];
}
case "string":
case "number":
case "integer":
case "boolean":
case "null":
return r.default || void 0;
default:
return r.default || void 0;
}
}, ee = (r, o, i) => {
if (o = U(o, i), o.type === "object") {
if (typeof r != "object" || r === null) return !1;
const s = o.properties || {}, t = Object.keys(r), n = Object.keys(s);
if (!t.every((p) => n.includes(p))) return !1;
for (const p in s)
if (p in r && !ee(
r[p],
s[p],
i
))
return !1;
return !0;
}
switch (o.type) {
case "string":
return typeof r == "string";
case "number":
return typeof r == "number";
case "integer":
return Number.isInteger(r);
case "boolean":
return typeof r == "boolean";
case "null":
return r === null;
case "array": {
if (!Array.isArray(r)) return !1;
const s = o.items;
return r.every(
(t) => ee(t, s, i)
);
}
default:
return !0;
}
};
var me = { exports: {} }, q = {};
/**
* @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 ke;
function or() {
if (ke) return q;
ke = 1;
var r = Symbol.for("react.transitional.element"), o = Symbol.for("react.fragment");
function i(s, t, n) {
var p = null;
if (n !== void 0 && (p = "" + n), t.key !== void 0 && (p = "" + t.key), "key" in t) {
n = {};
for (var d in t)
d !== "key" && (n[d] = t[d]);
} else n = t;
return t = n.ref, {
$$typeof: r,
type: s,
key: p,
ref: t !== void 0 ? t : null,
props: n
};
}
return q.Fragment = o, q.jsx = i, q.jsxs = i, q;
}
var K = {};
/**
* @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 De;
function ar() {
return De || (De = 1, process.env.NODE_ENV !== "production" && function() {
function r(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === te ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case c:
return "Fragment";
case b:
return "Profiler";
case _:
return "StrictMode";
case N:
return "Suspense";
case h:
return "SuspenseList";
case re:
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 v:
return "Portal";
case w:
return (e.displayName || "Context") + ".Provider";
case T:
return (e._context.displayName || "Context") + ".Consumer";
case P:
var a = e.render;
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case j:
return a = e.displayName || null, a !== null ? a : r(e.type) || "Memo";
case D:
a = e._payload, e = e._init;
try {
return r(e(a));
} catch {
}
}
return null;
}
function o(e) {
return "" + e;
}
function i(e) {
try {
o(e);
var a = !1;
} catch {
a = !0;
}
if (a) {
a = console;
var E = a.error, O = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return E.call(
a,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
O
), o(e);
}
}
function s(e) {
if (e === c) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === D)
return "<...>";
try {
var a = r(e);
return a ? "<" + a + ">" : "<...>";
} catch {
return "<...>";
}
}
function t() {
var e = I.A;
return e === null ? null : e.getOwner();
}
function n() {
return Error("react-stack-top-frame");
}
function p(e) {
if (W.call(e, "key")) {
var a = Object.getOwnPropertyDescriptor(e, "key").get;
if (a && a.isReactWarning) return !1;
}
return e.key !== void 0;
}
function d(e, a) {
function E() {
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)",
a
));
}
E.isReactWarning = !0, Object.defineProperty(e, "key", {
get: E,
configurable: !0
});
}
function S() {
var e = r(this.type);
return z[e] || (z[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 m(e, a, E, O, x, R, V, $) {
return E = R.ref, e = {
$$typeof: l,
type: e,
key: a,
props: R,
_owner: x
}, (E !== void 0 ? E : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: S
}) : 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: V
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: $
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function u(e, a, E, O, x, R, V, $) {
var g = a.children;
if (g !== void 0)
if (O)
if (ne(g)) {
for (O = 0; O < g.length; O++)
y(g[O]);
Object.freeze && Object.freeze(g);
} 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 y(g);
if (W.call(a, "key")) {
g = r(e);
var k = Object.keys(a).filter(function(oe) {
return oe !== "key";
});
O = 0 < k.length ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}", H[g + O] || (k = 0 < k.length ? "{" + k.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} />`,
O,
g,
k,
g
), H[g + O] = !0);
}
if (g = null, E !== void 0 && (i(E), g = "" + E), p(a) && (i(a.key), g = "" + a.key), "key" in a) {
E = {};
for (var M in a)
M !== "key" && (E[M] = a[M]);
} else E = a;
return g && d(
E,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), m(
e,
g,
R,
x,
t(),
E,
V,
$
);
}
function y(e) {
typeof e == "object" && e !== null && e.$$typeof === l && e._store && (e._store.validated = 1);
}
var f = L, l = Symbol.for("react.transitional.element"), v = Symbol.for("react.portal"), c = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), T = Symbol.for("react.consumer"), w = Symbol.for("react.context"), P = Symbol.for("react.forward_ref"), N = Symbol.for("react.suspense"), h = Symbol.for("react.suspense_list"), j = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), re = Symbol.for("react.activity"), te = Symbol.for("react.client.reference"), I = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, W = Object.prototype.hasOwnProperty, ne = Array.isArray, F = console.createTask ? console.createTask : function() {
return null;
};
f = {
"react-stack-bottom-frame": function(e) {
return e();
}
};
var Y, z = {}, G = f["react-stack-bottom-frame"].bind(
f,
n
)(), B = F(s(n)), H = {};
K.Fragment = c, K.jsx = function(e, a, E, O, x) {
var R = 1e4 > I.recentlyCreatedOwnerStacks++;
return u(
e,
a,
E,
!1,
O,
x,
R ? Error("react-stack-top-frame") : G,
R ? F(s(e)) : B
);
}, K.jsxs = function(e, a, E, O, x) {
var R = 1e4 > I.recentlyCreatedOwnerStacks++;
return u(
e,
a,
E,
!0,
O,
x,
R ? Error("react-stack-top-frame") : G,
R ? F(s(e)) : B
);
};
}()), K;
}
process.env.NODE_ENV === "production" ? me.exports = or() : me.exports = ar();
var A = me.exports;
const Ce = ({
schema: r,
path: o
}) => {
const i = Le(
(S) => S.schema.definitions || {}
), {
StringTemplate: s,
NumberTemplate: t,
BooleanTemplate: n,
ObjectTemplate: p,
ArrayTemplate: d
} = ur();
try {
r = U(r, i);
} catch (S) {
return console.error("Error resolving schema:", S), /* @__PURE__ */ A.jsxs("div", { style: { color: "red" }, children: [
"Failed to resolve schema at path: ",
o.join("/")
] });
}
if (Array.isArray(r.type))
if (r.type.length === 2 && r.type.includes("null") && (r.type.includes("string") || r.type.includes("number") || r.type.includes("boolean") || r.type.includes("integer"))) {
const S = r.type.find((u) => u !== "null"), m = {
...r,
type: S
};
return /* @__PURE__ */ A.jsx(Ce, { schema: m, path: o });
} else
return console.error(
`Unsupported union type at path ${o.join("/")}:`,
r.type
), /* @__PURE__ */ A.jsxs(
"div",
{
style: {
border: "1px dashed red",
padding: "1rem",
color: "red",
display: "flex",
flexDirection: "column",
gap: "0.25rem"
},
children: [
/* @__PURE__ */ A.jsx("strong", { children: "ERROR:" }),
" This field has multiple types:",
/* @__PURE__ */ A.jsx("ul", { style: { marginLeft: "1rem" }, children: r.type.map((S) => /* @__PURE__ */ A.jsx("li", { children: S }, S)) }),
/* @__PURE__ */ A.jsx("small", { children: "Please provide a specialized UI or a fallback for multi-type fields." })
]
}
);
switch (r.type) {
case "string":
return /* @__PURE__ */ A.jsx(s, { schema: r, path: o });
case "integer":
case "number":
return /* @__PURE__ */ A.jsx(t, { schema: r, path: o });
case "boolean":
return /* @__PURE__ */ A.jsx(n, { schema: r, path: o });
case "null":
return /* @__PURE__ */ A.jsx("input", { type: "text", value: "null", disabled: !0 });
case "object":
return /* @__PURE__ */ A.jsx(p, { schema: r, path: o });
case "array":
return /* @__PURE__ */ A.jsx(d, { schema: r, path: o });
default:
return console.error(`Unsupported schema type "${r.type}" at path:`, o), /* @__PURE__ */ A.jsxs(
"div",
{
style: {
color: "red",
display: "flex",
flexDirection: "column",
border: "1px dashed red",
padding: "1rem"
},
children: [
/* @__PURE__ */ A.jsx("strong", { children: "ERROR:" }),
/* @__PURE__ */ A.jsxs("small", { children: [
"Unsupported schema type `",
r.type || "UNKNOWN",
"` at path: `",
o.join("/"),
"`"
] })
]
}
);
}
}, fr = (r) => {
const o = Le((s) => s.schema), i = (s, t) => {
let n = s;
for (const p of t.slice(0, -1))
if (n.type === "object" && n.properties)
n = U(
n.properties[p],
s.definitions
);
else if (n.type === "array" && n.items)
if (Array.isArray(n.items)) {
const d = parseInt(p, 10);
if (!isNaN(d) && n.items[d])
n = U(
n.items[d],
s.definitions
);
else
return { parentSchema: null, key: null, isTupleItem: !1 };
} else
n = U(
n.items,
s.definitions
);
else
return { parentSchema: null, key: null, isTupleItem: !1 };
return {
parentSchema: n,
key: t[t.length - 1],
isTupleItem: Array.isArray(n == null ? void 0 : n.items)
};
};
try {
const { parentSchema: s, key: t, isTupleItem: n } = i(
o,
r
);
return n ? !0 : s && s.type === "object" && Array.isArray(s.required) && t ? s.required.includes(t) : !1;
} catch (s) {
return console.error("Error determining if field is required:", s), !1;
}
}, sr = (r) => Q(r, r.definitions || {}), ir = (r, o) => {
const i = {};
r.forEach((t) => {
const n = t.instancePath ? `/${(t.instancePath || "").split("/").slice(1).join("/")}` : "/", p = t.keyword === "required" ? `${n === "/" ? "" : n}/${t.params.missingProperty}` : n;
i[p] = i[p] || [], i[p].push(t);
});
const s = `/${o.join("/")}`;
return i[s] || [];
}, {
FormProvider: lr,
useFormContext: Le,
useFormDataAtPath: pr,
useErrorsAtPath: mr,
useArrayTemplate: yr,
useTemplates: ur,
useRenderTemplate: vr,
Form: cr
} = nr(
sr,
ir,
Ce
), br = lr, _r = cr;
export {
cr as CoreForm,
lr as CoreFormProvider,
_r as Form,
br as FormProvider,
Ce as RenderTemplate,
Q as generateInitialData,
U as resolveSchema,
yr as useArrayTemplate,
mr as useErrorsAtPath,
Le as useFormContext,
pr as useFormDataAtPath,
fr as useIsRequired,
vr as useRenderTemplate,
ur as useTemplates
};