@nestledjs/forms
Version:
A flexible React form library supporting both declarative and imperative usage patterns with TypeScript support
1,478 lines (1,477 loc) • 604 kB
JavaScript
import { jsxs as K, Fragment as Ne, jsx as f } from "react/jsx-runtime";
import * as je from "react";
import A, { createContext as ba, useContext as xa, useMemo as it, useRef as Xt, useCallback as Ge, useState as Xe, useEffect as tt } from "react";
var xr = (t) => t.type === "checkbox", bt = (t) => t instanceof Date, Le = (t) => t == null;
const $s = (t) => typeof t == "object";
var Ee = (t) => !Le(t) && !Array.isArray(t) && $s(t) && !bt(t), vs = (t) => Ee(t) && t.target ? xr(t.target) ? t.target.checked : t.target.value : t, xu = (t) => t.substring(0, t.search(/\.\d+(\.|$)/)) || t, bs = (t, e) => t.has(xu(e)), Cu = (t) => {
const e = t.constructor && t.constructor.prototype;
return Ee(e) && e.hasOwnProperty("isPrototypeOf");
}, Ca = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
function Re(t) {
let e;
const r = Array.isArray(t), n = typeof FileList < "u" ? t instanceof FileList : !1;
if (t instanceof Date)
e = new Date(t);
else if (!(Ca && (t instanceof Blob || n)) && (r || Ee(t)))
if (e = r ? [] : Object.create(Object.getPrototypeOf(t)), !r && !Cu(t))
e = t;
else
for (const a in t)
t.hasOwnProperty(a) && (e[a] = Re(t[a]));
else
return t;
return e;
}
var Xr = (t) => /^\w*$/.test(t), ke = (t) => t === void 0, wa = (t) => Array.isArray(t) ? t.filter(Boolean) : [], _a = (t) => wa(t.replace(/["|']|\]/g, "").split(/\.|\[/)), U = (t, e, r) => {
if (!e || !Ee(t))
return r;
const n = (Xr(e) ? [e] : _a(e)).reduce((a, i) => Le(a) ? a : a[i], t);
return ke(n) || n === t ? ke(t[e]) ? r : t[e] : n;
}, Ve = (t) => typeof t == "boolean", Ce = (t, e, r) => {
let n = -1;
const a = Xr(e) ? [e] : _a(e), i = a.length, o = i - 1;
for (; ++n < i; ) {
const s = a[n];
let d = r;
if (n !== o) {
const u = t[s];
d = Ee(u) || Array.isArray(u) ? u : isNaN(+a[n + 1]) ? {} : [];
}
if (s === "__proto__" || s === "constructor" || s === "prototype")
return;
t[s] = d, t = t[s];
}
};
const Ar = {
BLUR: "blur",
FOCUS_OUT: "focusout",
CHANGE: "change"
}, Ke = {
onBlur: "onBlur",
onChange: "onChange",
onSubmit: "onSubmit",
onTouched: "onTouched",
all: "all"
}, rt = {
max: "max",
min: "min",
maxLength: "maxLength",
minLength: "minLength",
pattern: "pattern",
required: "required",
validate: "validate"
}, xs = A.createContext(null);
xs.displayName = "HookFormContext";
const Sa = () => A.useContext(xs);
var Cs = (t, e, r, n = !0) => {
const a = {
defaultValues: e._defaultValues
};
for (const i in t)
Object.defineProperty(a, i, {
get: () => {
const o = i;
return e._proxyFormState[o] !== Ke.all && (e._proxyFormState[o] = !n || Ke.all), r && (r[o] = !0), t[o];
}
});
return a;
};
const Oa = typeof window < "u" ? A.useLayoutEffect : A.useEffect;
function wu(t) {
const e = Sa(), { control: r = e.control, disabled: n, name: a, exact: i } = t || {}, [o, s] = A.useState(r._formState), d = A.useRef({
isDirty: !1,
isLoading: !1,
dirtyFields: !1,
touchedFields: !1,
validatingFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
});
return Oa(() => r._subscribe({
name: a,
formState: d.current,
exact: i,
callback: (u) => {
!n && s({
...r._formState,
...u
});
}
}), [a, n, i]), A.useEffect(() => {
d.current.isValid && r._setValid(!0);
}, [r]), A.useMemo(() => Cs(o, r, d.current, !1), [o, r]);
}
var Be = (t) => typeof t == "string", Fn = (t, e, r, n, a) => Be(t) ? (n && e.watch.add(t), U(r, t, a)) : Array.isArray(t) ? t.map((i) => (n && e.watch.add(i), U(r, i))) : (n && (e.watchAll = !0), r), Rn = (t) => Le(t) || !$s(t);
function ze(t, e, r = /* @__PURE__ */ new WeakSet()) {
if (Rn(t) || Rn(e))
return t === e;
if (bt(t) && bt(e))
return t.getTime() === e.getTime();
const n = Object.keys(t), a = Object.keys(e);
if (n.length !== a.length)
return !1;
if (r.has(t) || r.has(e))
return !0;
r.add(t), r.add(e);
for (const i of n) {
const o = t[i];
if (!a.includes(i))
return !1;
if (i !== "ref") {
const s = e[i];
if (bt(o) && bt(s) || Ee(o) && Ee(s) || Array.isArray(o) && Array.isArray(s) ? !ze(o, s, r) : o !== s)
return !1;
}
}
return !0;
}
function Na(t) {
const e = Sa(), { control: r = e.control, name: n, defaultValue: a, disabled: i, exact: o, compute: s } = t || {}, d = A.useRef(a), u = A.useRef(s), l = A.useRef(void 0), h = A.useRef(r), y = A.useRef(n);
u.current = s;
const [v, C] = A.useState(() => {
const I = r._getWatch(n, d.current);
return u.current ? u.current(I) : I;
}), m = A.useCallback((I) => {
const g = Fn(n, r._names, I || r._formValues, !1, d.current);
return u.current ? u.current(g) : g;
}, [r._formValues, r._names, n]), x = A.useCallback((I) => {
if (!i) {
const g = Fn(n, r._names, I || r._formValues, !1, d.current);
if (u.current) {
const W = u.current(g);
ze(W, l.current) || (C(W), l.current = W);
} else
C(g);
}
}, [r._formValues, r._names, i, n]);
Oa(() => ((h.current !== r || !ze(y.current, n)) && (h.current = r, y.current = n, x()), r._subscribe({
name: n,
formState: {
values: !0
},
exact: o,
callback: (I) => {
x(I.values);
}
})), [r, o, n, x]), A.useEffect(() => r._removeUnmounted());
const $ = h.current !== r, _ = y.current, N = A.useMemo(() => {
if (i)
return null;
const I = !$ && !ze(_, n);
return $ || I ? m() : null;
}, [i, $, n, _, m]);
return N !== null ? N : v;
}
function _u(t) {
const e = Sa(), { name: r, disabled: n, control: a = e.control, shouldUnregister: i, defaultValue: o } = t, s = bs(a._names.array, r), d = A.useMemo(() => U(a._formValues, r, U(a._defaultValues, r, o)), [a, r, o]), u = Na({
control: a,
name: r,
defaultValue: d,
exact: !0
}), l = wu({
control: a,
name: r,
exact: !0
}), h = A.useRef(t), y = A.useRef(void 0), v = A.useRef(a.register(r, {
...t.rules,
value: u,
...Ve(t.disabled) ? { disabled: t.disabled } : {}
}));
h.current = t;
const C = A.useMemo(() => Object.defineProperties({}, {
invalid: {
enumerable: !0,
get: () => !!U(l.errors, r)
},
isDirty: {
enumerable: !0,
get: () => !!U(l.dirtyFields, r)
},
isTouched: {
enumerable: !0,
get: () => !!U(l.touchedFields, r)
},
isValidating: {
enumerable: !0,
get: () => !!U(l.validatingFields, r)
},
error: {
enumerable: !0,
get: () => U(l.errors, r)
}
}), [l, r]), m = A.useCallback((N) => v.current.onChange({
target: {
value: vs(N),
name: r
},
type: Ar.CHANGE
}), [r]), x = A.useCallback(() => v.current.onBlur({
target: {
value: U(a._formValues, r),
name: r
},
type: Ar.BLUR
}), [r, a._formValues]), $ = A.useCallback((N) => {
const I = U(a._fields, r);
I && N && (I._f.ref = {
focus: () => N.focus && N.focus(),
select: () => N.select && N.select(),
setCustomValidity: (g) => N.setCustomValidity(g),
reportValidity: () => N.reportValidity()
});
}, [a._fields, r]), _ = A.useMemo(() => ({
name: r,
value: u,
...Ve(n) || l.disabled ? { disabled: l.disabled || n } : {},
onChange: m,
onBlur: x,
ref: $
}), [r, n, l.disabled, m, x, $, u]);
return A.useEffect(() => {
const N = a._options.shouldUnregister || i, I = y.current;
I && I !== r && !s && a.unregister(I), a.register(r, {
...h.current.rules,
...Ve(h.current.disabled) ? { disabled: h.current.disabled } : {}
});
const g = (W, ce) => {
const pe = U(a._fields, W);
pe && pe._f && (pe._f.mount = ce);
};
if (g(r, !0), N) {
const W = Re(U(a._options.defaultValues, r, h.current.defaultValue));
Ce(a._defaultValues, r, W), ke(U(a._formValues, r)) && Ce(a._formValues, r, W);
}
return !s && a.register(r), y.current = r, () => {
(s ? N && !a._state.action : N) ? a.unregister(r) : g(r, !1);
};
}, [r, a, s, i]), A.useEffect(() => {
a._setDisabledField({
disabled: n,
name: r
});
}, [n, r, a]), A.useMemo(() => ({
field: _,
formState: l,
fieldState: C
}), [_, l, C]);
}
const mt = (t) => t.render(_u(t));
var Pa = (t, e, r, n, a) => e ? {
...r[t],
types: {
...r[t] && r[t].types ? r[t].types : {},
[n]: a || !0
}
} : {}, Jt = (t) => Array.isArray(t) ? t : [t], Qa = () => {
let t = [];
return {
get observers() {
return t;
},
next: (a) => {
for (const i of t)
i.next && i.next(a);
},
subscribe: (a) => (t.push(a), {
unsubscribe: () => {
t = t.filter((i) => i !== a);
}
}),
unsubscribe: () => {
t = [];
}
};
};
function ws(t, e) {
const r = {};
for (const n in t)
if (t.hasOwnProperty(n)) {
const a = t[n], i = e[n];
if (a && Ee(a) && i) {
const o = ws(a, i);
Ee(o) && (r[n] = o);
} else t[n] && (r[n] = i);
}
return r;
}
var De = (t) => Ee(t) && !Object.keys(t).length, ka = (t) => t.type === "file", Ye = (t) => typeof t == "function", Er = (t) => {
if (!Ca)
return !1;
const e = t ? t.ownerDocument : 0;
return t instanceof (e && e.defaultView ? e.defaultView.HTMLElement : HTMLElement);
}, _s = (t) => t.type === "select-multiple", Ta = (t) => t.type === "radio", Su = (t) => Ta(t) || xr(t), pn = (t) => Er(t) && t.isConnected;
function Ou(t, e) {
const r = e.slice(0, -1).length;
let n = 0;
for (; n < r; )
t = ke(t) ? n++ : t[e[n++]];
return t;
}
function Nu(t) {
for (const e in t)
if (t.hasOwnProperty(e) && !ke(t[e]))
return !1;
return !0;
}
function Ie(t, e) {
const r = Array.isArray(e) ? e : Xr(e) ? [e] : _a(e), n = r.length === 1 ? t : Ou(t, r), a = r.length - 1, i = r[a];
return n && delete n[i], a !== 0 && (Ee(n) && De(n) || Array.isArray(n) && Nu(n)) && Ie(t, r.slice(0, -1)), t;
}
var Pu = (t) => {
for (const e in t)
if (Ye(t[e]))
return !0;
return !1;
};
function Ss(t) {
return Array.isArray(t) || Ee(t) && !Pu(t);
}
function Dn(t, e = {}) {
for (const r in t)
Ss(t[r]) ? (e[r] = Array.isArray(t[r]) ? [] : {}, Dn(t[r], e[r])) : ke(t[r]) || (e[r] = !0);
return e;
}
function Tt(t, e, r) {
r || (r = Dn(e));
for (const n in t)
Ss(t[n]) ? ke(e) || Rn(r[n]) ? r[n] = Dn(t[n], Array.isArray(t[n]) ? [] : {}) : Tt(t[n], Le(e) ? {} : e[n], r[n]) : r[n] = !ze(t[n], e[n]);
return r;
}
const ei = {
value: !1,
isValid: !1
}, ti = { value: !0, isValid: !0 };
var Os = (t) => {
if (Array.isArray(t)) {
if (t.length > 1) {
const e = t.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
return { value: e, isValid: !!e.length };
}
return t[0].checked && !t[0].disabled ? (
// @ts-expect-error expected to work in the browser
t[0].attributes && !ke(t[0].attributes.value) ? ke(t[0].value) || t[0].value === "" ? ti : { value: t[0].value, isValid: !0 } : ti
) : ei;
}
return ei;
}, Ns = (t, { valueAsNumber: e, valueAsDate: r, setValueAs: n }) => ke(t) ? t : e ? t === "" ? NaN : t && +t : r && Be(t) ? new Date(t) : n ? n(t) : t;
const ri = {
isValid: !1,
value: null
};
var Ps = (t) => Array.isArray(t) ? t.reduce((e, r) => r && r.checked && !r.disabled ? {
isValid: !0,
value: r.value
} : e, ri) : ri;
function ni(t) {
const e = t.ref;
return ka(e) ? e.files : Ta(e) ? Ps(t.refs).value : _s(e) ? [...e.selectedOptions].map(({ value: r }) => r) : xr(e) ? Os(t.refs).value : Ns(ke(e.value) ? t.ref.value : e.value, t);
}
var ku = (t, e, r, n) => {
const a = {};
for (const i of t) {
const o = U(e, i);
o && Ce(a, i, o._f);
}
return {
criteriaMode: r,
names: [...t],
fields: a,
shouldUseNativeValidation: n
};
}, Fr = (t) => t instanceof RegExp, Ht = (t) => ke(t) ? t : Fr(t) ? t.source : Ee(t) ? Fr(t.value) ? t.value.source : t.value : t, ai = (t) => ({
isOnSubmit: !t || t === Ke.onSubmit,
isOnBlur: t === Ke.onBlur,
isOnChange: t === Ke.onChange,
isOnAll: t === Ke.all,
isOnTouch: t === Ke.onTouched
});
const ii = "AsyncFunction";
var Tu = (t) => !!t && !!t.validate && !!(Ye(t.validate) && t.validate.constructor.name === ii || Ee(t.validate) && Object.values(t.validate).find((e) => e.constructor.name === ii)), Iu = (t) => t.mount && (t.required || t.min || t.max || t.maxLength || t.minLength || t.pattern || t.validate), oi = (t, e, r) => !r && (e.watchAll || e.watch.has(t) || [...e.watch].some((n) => t.startsWith(n) && /^\.\w+/.test(t.slice(n.length))));
const Qt = (t, e, r, n) => {
for (const a of r || Object.keys(t)) {
const i = U(t, a);
if (i) {
const { _f: o, ...s } = i;
if (o) {
if (o.refs && o.refs[0] && e(o.refs[0], a) && !n)
return !0;
if (o.ref && e(o.ref, o.name) && !n)
return !0;
if (Qt(s, e))
break;
} else if (Ee(s) && Qt(s, e))
break;
}
}
};
function si(t, e, r) {
const n = U(t, r);
if (n || Xr(r))
return {
error: n,
name: r
};
const a = r.split(".");
for (; a.length; ) {
const i = a.join("."), o = U(e, i), s = U(t, i);
if (o && !Array.isArray(o) && r !== i)
return { name: r };
if (s && s.type)
return {
name: i,
error: s
};
if (s && s.root && s.root.type)
return {
name: `${i}.root`,
error: s.root
};
a.pop();
}
return {
name: r
};
}
var Au = (t, e, r, n) => {
r(t);
const { name: a, ...i } = t;
return De(i) || Object.keys(i).length >= Object.keys(e).length || Object.keys(i).find((o) => e[o] === (!n || Ke.all));
}, Eu = (t, e, r) => !t || !e || t === e || Jt(t).some((n) => n && (r ? n === e : n.startsWith(e) || e.startsWith(n))), Fu = (t, e, r, n, a) => a.isOnAll ? !1 : !r && a.isOnTouch ? !(e || t) : (r ? n.isOnBlur : a.isOnBlur) ? !t : (r ? n.isOnChange : a.isOnChange) ? t : !0, Ru = (t, e) => !wa(U(t, e)).length && Ie(t, e), Du = (t, e, r) => {
const n = Jt(U(t, r));
return Ce(n, "root", e[r]), Ce(t, r, n), t;
};
function di(t, e, r = "validate") {
if (Be(t) || Array.isArray(t) && t.every(Be) || Ve(t) && !t)
return {
type: r,
message: Be(t) ? t : "",
ref: e
};
}
var Nt = (t) => Ee(t) && !Fr(t) ? t : {
value: t,
message: ""
}, ui = async (t, e, r, n, a, i) => {
const { ref: o, refs: s, required: d, maxLength: u, minLength: l, min: h, max: y, pattern: v, validate: C, name: m, valueAsNumber: x, mount: $ } = t._f, _ = U(r, m);
if (!$ || e.has(m))
return {};
const N = s ? s[0] : o, I = (ie) => {
a && N.reportValidity && (N.setCustomValidity(Ve(ie) ? "" : ie || ""), N.reportValidity());
}, g = {}, W = Ta(o), ce = xr(o), pe = W || ce, fe = (x || ka(o)) && ke(o.value) && ke(_) || Er(o) && o.value === "" || _ === "" || Array.isArray(_) && !_.length, le = Pa.bind(null, m, n, g), ne = (ie, he, L, F = rt.maxLength, k = rt.minLength) => {
const M = ie ? he : L;
g[m] = {
type: ie ? F : k,
message: M,
ref: o,
...le(ie ? F : k, M)
};
};
if (i ? !Array.isArray(_) || !_.length : d && (!pe && (fe || Le(_)) || Ve(_) && !_ || ce && !Os(s).isValid || W && !Ps(s).isValid)) {
const { value: ie, message: he } = Be(d) ? { value: !!d, message: d } : Nt(d);
if (ie && (g[m] = {
type: rt.required,
message: he,
ref: N,
...le(rt.required, he)
}, !n))
return I(he), g;
}
if (!fe && (!Le(h) || !Le(y))) {
let ie, he;
const L = Nt(y), F = Nt(h);
if (!Le(_) && !isNaN(_)) {
const k = o.valueAsNumber || _ && +_;
Le(L.value) || (ie = k > L.value), Le(F.value) || (he = k < F.value);
} else {
const k = o.valueAsDate || new Date(_), M = (w) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + w), j = o.type == "time", te = o.type == "week";
Be(L.value) && _ && (ie = j ? M(_) > M(L.value) : te ? _ > L.value : k > new Date(L.value)), Be(F.value) && _ && (he = j ? M(_) < M(F.value) : te ? _ < F.value : k < new Date(F.value));
}
if ((ie || he) && (ne(!!ie, L.message, F.message, rt.max, rt.min), !n))
return I(g[m].message), g;
}
if ((u || l) && !fe && (Be(_) || i && Array.isArray(_))) {
const ie = Nt(u), he = Nt(l), L = !Le(ie.value) && _.length > +ie.value, F = !Le(he.value) && _.length < +he.value;
if ((L || F) && (ne(L, ie.message, he.message), !n))
return I(g[m].message), g;
}
if (v && !fe && Be(_)) {
const { value: ie, message: he } = Nt(v);
if (Fr(ie) && !_.match(ie) && (g[m] = {
type: rt.pattern,
message: he,
ref: o,
...le(rt.pattern, he)
}, !n))
return I(he), g;
}
if (C) {
if (Ye(C)) {
const ie = await C(_, r), he = di(ie, N);
if (he && (g[m] = {
...he,
...le(rt.validate, he.message)
}, !n))
return I(he.message), g;
} else if (Ee(C)) {
let ie = {};
for (const he in C) {
if (!De(ie) && !n)
break;
const L = di(await C[he](_, r), N, he);
L && (ie = {
...L,
...le(he, L.message)
}, I(L.message), n && (g[m] = ie));
}
if (!De(ie) && (g[m] = {
ref: N,
...ie
}, !n))
return g;
}
}
return I(!0), g;
};
const ju = {
mode: Ke.onSubmit,
reValidateMode: Ke.onChange,
shouldFocusError: !0
};
function Mu(t = {}) {
let e = {
...ju,
...t
}, r = {
submitCount: 0,
isDirty: !1,
isReady: !1,
isLoading: Ye(e.defaultValues),
isValidating: !1,
isSubmitted: !1,
isSubmitting: !1,
isSubmitSuccessful: !1,
isValid: !1,
touchedFields: {},
dirtyFields: {},
validatingFields: {},
errors: e.errors || {},
disabled: e.disabled || !1
}, n = {}, a = Ee(e.defaultValues) || Ee(e.values) ? Re(e.defaultValues || e.values) || {} : {}, i = e.shouldUnregister ? {} : Re(a), o = {
action: !1,
mount: !1,
watch: !1
}, s = {
mount: /* @__PURE__ */ new Set(),
disabled: /* @__PURE__ */ new Set(),
unMount: /* @__PURE__ */ new Set(),
array: /* @__PURE__ */ new Set(),
watch: /* @__PURE__ */ new Set()
}, d, u = 0;
const l = {
isDirty: !1,
dirtyFields: !1,
validatingFields: !1,
touchedFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
};
let h = {
...l
};
const y = {
array: Qa(),
state: Qa()
}, v = e.criteriaMode === Ke.all, C = (p) => (b) => {
clearTimeout(u), u = setTimeout(p, b);
}, m = async (p) => {
if (!e.disabled && (l.isValid || h.isValid || p)) {
const b = e.resolver ? De((await ce()).errors) : await fe(n, !0);
b !== r.isValid && y.state.next({
isValid: b
});
}
}, x = (p, b) => {
!e.disabled && (l.isValidating || l.validatingFields || h.isValidating || h.validatingFields) && ((p || Array.from(s.mount)).forEach((O) => {
O && (b ? Ce(r.validatingFields, O, b) : Ie(r.validatingFields, O));
}), y.state.next({
validatingFields: r.validatingFields,
isValidating: !De(r.validatingFields)
}));
}, $ = (p, b = [], O, q, B = !0, D = !0) => {
if (q && O && !e.disabled) {
if (o.action = !0, D && Array.isArray(U(n, p))) {
const ae = O(U(n, p), q.argA, q.argB);
B && Ce(n, p, ae);
}
if (D && Array.isArray(U(r.errors, p))) {
const ae = O(U(r.errors, p), q.argA, q.argB);
B && Ce(r.errors, p, ae), Ru(r.errors, p);
}
if ((l.touchedFields || h.touchedFields) && D && Array.isArray(U(r.touchedFields, p))) {
const ae = O(U(r.touchedFields, p), q.argA, q.argB);
B && Ce(r.touchedFields, p, ae);
}
(l.dirtyFields || h.dirtyFields) && (r.dirtyFields = Tt(a, i)), y.state.next({
name: p,
isDirty: ne(p, b),
dirtyFields: r.dirtyFields,
errors: r.errors,
isValid: r.isValid
});
} else
Ce(i, p, b);
}, _ = (p, b) => {
Ce(r.errors, p, b), y.state.next({
errors: r.errors
});
}, N = (p) => {
r.errors = p, y.state.next({
errors: r.errors,
isValid: !1
});
}, I = (p, b, O, q) => {
const B = U(n, p);
if (B) {
const D = U(i, p, ke(O) ? U(a, p) : O);
ke(D) || q && q.defaultChecked || b ? Ce(i, p, b ? D : ni(B._f)) : L(p, D), o.mount && m();
}
}, g = (p, b, O, q, B) => {
let D = !1, ae = !1;
const xe = {
name: p
};
if (!e.disabled) {
if (!O || q) {
(l.isDirty || h.isDirty) && (ae = r.isDirty, r.isDirty = xe.isDirty = ne(), D = ae !== xe.isDirty);
const we = ze(U(a, p), b);
ae = !!U(r.dirtyFields, p), we ? Ie(r.dirtyFields, p) : Ce(r.dirtyFields, p, !0), xe.dirtyFields = r.dirtyFields, D = D || (l.dirtyFields || h.dirtyFields) && ae !== !we;
}
if (O) {
const we = U(r.touchedFields, p);
we || (Ce(r.touchedFields, p, O), xe.touchedFields = r.touchedFields, D = D || (l.touchedFields || h.touchedFields) && we !== O);
}
D && B && y.state.next(xe);
}
return D ? xe : {};
}, W = (p, b, O, q) => {
const B = U(r.errors, p), D = (l.isValid || h.isValid) && Ve(b) && r.isValid !== b;
if (e.delayError && O ? (d = C(() => _(p, O)), d(e.delayError)) : (clearTimeout(u), d = null, O ? Ce(r.errors, p, O) : Ie(r.errors, p)), (O ? !ze(B, O) : B) || !De(q) || D) {
const ae = {
...q,
...D && Ve(b) ? { isValid: b } : {},
errors: r.errors,
name: p
};
r = {
...r,
...ae
}, y.state.next(ae);
}
}, ce = async (p) => {
x(p, !0);
const b = await e.resolver(i, e.context, ku(p || s.mount, n, e.criteriaMode, e.shouldUseNativeValidation));
return x(p), b;
}, pe = async (p) => {
const { errors: b } = await ce(p);
if (p)
for (const O of p) {
const q = U(b, O);
q ? Ce(r.errors, O, q) : Ie(r.errors, O);
}
else
r.errors = b;
return b;
}, fe = async (p, b, O = {
valid: !0
}) => {
for (const q in p) {
const B = p[q];
if (B) {
const { _f: D, ...ae } = B;
if (D) {
const xe = s.array.has(D.name), we = B._f && Tu(B._f);
we && l.validatingFields && x([D.name], !0);
const We = await ui(B, s.disabled, i, v, e.shouldUseNativeValidation && !b, xe);
if (we && l.validatingFields && x([D.name]), We[D.name] && (O.valid = !1, b))
break;
!b && (U(We, D.name) ? xe ? Du(r.errors, We, D.name) : Ce(r.errors, D.name, We[D.name]) : Ie(r.errors, D.name));
}
!De(ae) && await fe(ae, b, O);
}
}
return O.valid;
}, le = () => {
for (const p of s.unMount) {
const b = U(n, p);
b && (b._f.refs ? b._f.refs.every((O) => !pn(O)) : !pn(b._f.ref)) && ee(p);
}
s.unMount = /* @__PURE__ */ new Set();
}, ne = (p, b) => !e.disabled && (p && b && Ce(i, p, b), !ze(w(), a)), ie = (p, b, O) => Fn(p, s, {
...o.mount ? i : ke(b) ? a : Be(p) ? { [p]: b } : b
}, O, b), he = (p) => wa(U(o.mount ? i : a, p, e.shouldUnregister ? U(a, p, []) : [])), L = (p, b, O = {}) => {
const q = U(n, p);
let B = b;
if (q) {
const D = q._f;
D && (!D.disabled && Ce(i, p, Ns(b, D)), B = Er(D.ref) && Le(b) ? "" : b, _s(D.ref) ? [...D.ref.options].forEach((ae) => ae.selected = B.includes(ae.value)) : D.refs ? xr(D.ref) ? D.refs.forEach((ae) => {
(!ae.defaultChecked || !ae.disabled) && (Array.isArray(B) ? ae.checked = !!B.find((xe) => xe === ae.value) : ae.checked = B === ae.value || !!B);
}) : D.refs.forEach((ae) => ae.checked = ae.value === B) : ka(D.ref) ? D.ref.value = "" : (D.ref.value = B, D.ref.type || y.state.next({
name: p,
values: Re(i)
})));
}
(O.shouldDirty || O.shouldTouch) && g(p, B, O.shouldTouch, O.shouldDirty, !0), O.shouldValidate && te(p);
}, F = (p, b, O) => {
for (const q in b) {
if (!b.hasOwnProperty(q))
return;
const B = b[q], D = p + "." + q, ae = U(n, D);
(s.array.has(p) || Ee(B) || ae && !ae._f) && !bt(B) ? F(D, B, O) : L(D, B, O);
}
}, k = (p, b, O = {}) => {
const q = U(n, p), B = s.array.has(p), D = Re(b);
Ce(i, p, D), B ? (y.array.next({
name: p,
values: Re(i)
}), (l.isDirty || l.dirtyFields || h.isDirty || h.dirtyFields) && O.shouldDirty && y.state.next({
name: p,
dirtyFields: Tt(a, i),
isDirty: ne(p, D)
})) : q && !q._f && !Le(D) ? F(p, D, O) : L(p, D, O), oi(p, s) && y.state.next({ ...r, name: p }), y.state.next({
name: o.mount ? p : void 0,
values: Re(i)
});
}, M = async (p) => {
o.mount = !0;
const b = p.target;
let O = b.name, q = !0;
const B = U(n, O), D = (we) => {
q = Number.isNaN(we) || bt(we) && isNaN(we.getTime()) || ze(we, U(i, O, we));
}, ae = ai(e.mode), xe = ai(e.reValidateMode);
if (B) {
let we, We;
const _r = b.type ? ni(B._f) : vs(p), ut = p.type === Ar.BLUR || p.type === Ar.FOCUS_OUT, $u = !Iu(B._f) && !e.resolver && !U(r.errors, O) && !B._f.deps || Fu(ut, U(r.touchedFields, O), r.isSubmitted, xe, ae), fn = oi(O, s, ut);
Ce(i, O, _r), ut ? (!b || !b.readOnly) && (B._f.onBlur && B._f.onBlur(p), d && d(0)) : B._f.onChange && B._f.onChange(p);
const hn = g(O, _r, ut), vu = !De(hn) || fn;
if (!ut && y.state.next({
name: O,
type: p.type,
values: Re(i)
}), $u)
return (l.isValid || h.isValid) && (e.mode === "onBlur" ? ut && m() : ut || m()), vu && y.state.next({ name: O, ...fn ? {} : hn });
if (!ut && fn && y.state.next({ ...r }), e.resolver) {
const { errors: Xa } = await ce([O]);
if (D(_r), q) {
const bu = si(r.errors, n, O), Ja = si(Xa, n, bu.name || O);
we = Ja.error, O = Ja.name, We = De(Xa);
}
} else
x([O], !0), we = (await ui(B, s.disabled, i, v, e.shouldUseNativeValidation))[O], x([O]), D(_r), q && (we ? We = !1 : (l.isValid || h.isValid) && (We = await fe(n, !0)));
q && (B._f.deps && (!Array.isArray(B._f.deps) || B._f.deps.length > 0) && te(B._f.deps), W(O, We, we, hn));
}
}, j = (p, b) => {
if (U(r.errors, b) && p.focus)
return p.focus(), 1;
}, te = async (p, b = {}) => {
let O, q;
const B = Jt(p);
if (e.resolver) {
const D = await pe(ke(p) ? p : B);
O = De(D), q = p ? !B.some((ae) => U(D, ae)) : O;
} else p ? (q = (await Promise.all(B.map(async (D) => {
const ae = U(n, D);
return await fe(ae && ae._f ? { [D]: ae } : ae);
}))).every(Boolean), !(!q && !r.isValid) && m()) : q = O = await fe(n);
return y.state.next({
...!Be(p) || (l.isValid || h.isValid) && O !== r.isValid ? {} : { name: p },
...e.resolver || !p ? { isValid: O } : {},
errors: r.errors
}), b.shouldFocus && !q && Qt(n, j, p ? B : s.mount), q;
}, w = (p, b) => {
let O = {
...o.mount ? i : a
};
return b && (O = ws(b.dirtyFields ? r.dirtyFields : r.touchedFields, O)), ke(p) ? O : Be(p) ? U(O, p) : p.map((q) => U(O, q));
}, T = (p, b) => ({
invalid: !!U((b || r).errors, p),
isDirty: !!U((b || r).dirtyFields, p),
error: U((b || r).errors, p),
isValidating: !!U(r.validatingFields, p),
isTouched: !!U((b || r).touchedFields, p)
}), Y = (p) => {
p && Jt(p).forEach((b) => Ie(r.errors, b)), y.state.next({
errors: p ? r.errors : {}
});
}, X = (p, b, O) => {
const q = (U(n, p, { _f: {} })._f || {}).ref, B = U(r.errors, p) || {}, { ref: D, message: ae, type: xe, ...we } = B;
Ce(r.errors, p, {
...we,
...b,
ref: q
}), y.state.next({
name: p,
errors: r.errors,
isValid: !1
}), O && O.shouldFocus && q && q.focus && q.focus();
}, P = (p, b) => Ye(p) ? y.state.subscribe({
next: (O) => "values" in O && p(ie(void 0, b), O)
}) : ie(p, b, !0), H = (p) => y.state.subscribe({
next: (b) => {
Eu(p.name, b.name, p.exact) && Au(b, p.formState || l, gu, p.reRenderRoot) && p.callback({
values: { ...i },
...r,
...b,
defaultValues: a
});
}
}).unsubscribe, se = (p) => (o.mount = !0, h = {
...h,
...p.formState
}, H({
...p,
formState: h
})), ee = (p, b = {}) => {
for (const O of p ? Jt(p) : s.mount)
s.mount.delete(O), s.array.delete(O), b.keepValue || (Ie(n, O), Ie(i, O)), !b.keepError && Ie(r.errors, O), !b.keepDirty && Ie(r.dirtyFields, O), !b.keepTouched && Ie(r.touchedFields, O), !b.keepIsValidating && Ie(r.validatingFields, O), !e.shouldUnregister && !b.keepDefaultValue && Ie(a, O);
y.state.next({
values: Re(i)
}), y.state.next({
...r,
...b.keepDirty ? { isDirty: ne() } : {}
}), !b.keepIsValid && m();
}, Z = ({ disabled: p, name: b }) => {
(Ve(p) && o.mount || p || s.disabled.has(b)) && (p ? s.disabled.add(b) : s.disabled.delete(b));
}, oe = (p, b = {}) => {
let O = U(n, p);
const q = Ve(b.disabled) || Ve(e.disabled);
return Ce(n, p, {
...O || {},
_f: {
...O && O._f ? O._f : { ref: { name: p } },
name: p,
mount: !0,
...b
}
}), s.mount.add(p), O ? Z({
disabled: Ve(b.disabled) ? b.disabled : e.disabled,
name: p
}) : I(p, !0, b.value), {
...q ? { disabled: b.disabled || e.disabled } : {},
...e.progressive ? {
required: !!b.required,
min: Ht(b.min),
max: Ht(b.max),
minLength: Ht(b.minLength),
maxLength: Ht(b.maxLength),
pattern: Ht(b.pattern)
} : {},
name: p,
onChange: M,
onBlur: M,
ref: (B) => {
if (B) {
oe(p, b), O = U(n, p);
const D = ke(B.value) && B.querySelectorAll && B.querySelectorAll("input,select,textarea")[0] || B, ae = Su(D), xe = O._f.refs || [];
if (ae ? xe.find((we) => we === D) : D === O._f.ref)
return;
Ce(n, p, {
_f: {
...O._f,
...ae ? {
refs: [
...xe.filter(pn),
D,
...Array.isArray(U(a, p)) ? [{}] : []
],
ref: { type: D.type, name: p }
} : { ref: D }
}
}), I(p, !1, void 0, D);
} else
O = U(n, p, {}), O._f && (O._f.mount = !1), (e.shouldUnregister || b.shouldUnregister) && !(bs(s.array, p) && o.action) && s.unMount.add(p);
}
};
}, re = () => e.shouldFocusError && Qt(n, j, s.mount), $e = (p) => {
Ve(p) && (y.state.next({ disabled: p }), Qt(n, (b, O) => {
const q = U(n, O);
q && (b.disabled = q._f.disabled || p, Array.isArray(q._f.refs) && q._f.refs.forEach((B) => {
B.disabled = q._f.disabled || p;
}));
}, 0, !1));
}, V = (p, b) => async (O) => {
let q;
O && (O.preventDefault && O.preventDefault(), O.persist && O.persist());
let B = Re(i);
if (y.state.next({
isSubmitting: !0
}), e.resolver) {
const { errors: D, values: ae } = await ce();
r.errors = D, B = Re(ae);
} else
await fe(n);
if (s.disabled.size)
for (const D of s.disabled)
Ie(B, D);
if (Ie(r.errors, "root"), De(r.errors)) {
y.state.next({
errors: {}
});
try {
await p(B, O);
} catch (D) {
q = D;
}
} else
b && await b({ ...r.errors }, O), re(), setTimeout(re);
if (y.state.next({
isSubmitted: !0,
isSubmitting: !1,
isSubmitSuccessful: De(r.errors) && !q,
submitCount: r.submitCount + 1,
errors: r.errors
}), q)
throw q;
}, Te = (p, b = {}) => {
U(n, p) && (ke(b.defaultValue) ? k(p, Re(U(a, p))) : (k(p, b.defaultValue), Ce(a, p, Re(b.defaultValue))), b.keepTouched || Ie(r.touchedFields, p), b.keepDirty || (Ie(r.dirtyFields, p), r.isDirty = b.defaultValue ? ne(p, Re(U(a, p))) : ne()), b.keepError || (Ie(r.errors, p), l.isValid && m()), y.state.next({ ...r }));
}, vt = (p, b = {}) => {
const O = p ? Re(p) : a, q = Re(O), B = De(p), D = B ? a : q;
if (b.keepDefaultValues || (a = O), !b.keepValues) {
if (b.keepDirtyValues) {
const ae = /* @__PURE__ */ new Set([
...s.mount,
...Object.keys(Tt(a, i))
]);
for (const xe of Array.from(ae))
U(r.dirtyFields, xe) ? Ce(D, xe, U(i, xe)) : k(xe, U(D, xe));
} else {
if (Ca && ke(p))
for (const ae of s.mount) {
const xe = U(n, ae);
if (xe && xe._f) {
const we = Array.isArray(xe._f.refs) ? xe._f.refs[0] : xe._f.ref;
if (Er(we)) {
const We = we.closest("form");
if (We) {
We.reset();
break;
}
}
}
}
if (b.keepFieldsRef)
for (const ae of s.mount)
k(ae, U(D, ae));
else
n = {};
}
i = e.shouldUnregister ? b.keepDefaultValues ? Re(a) : {} : Re(D), y.array.next({
values: { ...D }
}), y.state.next({
values: { ...D }
});
}
s = {
mount: b.keepDirtyValues ? s.mount : /* @__PURE__ */ new Set(),
unMount: /* @__PURE__ */ new Set(),
array: /* @__PURE__ */ new Set(),
disabled: /* @__PURE__ */ new Set(),
watch: /* @__PURE__ */ new Set(),
watchAll: !1,
focus: ""
}, o.mount = !l.isValid || !!b.keepIsValid || !!b.keepDirtyValues || !e.shouldUnregister && !De(D), o.watch = !!e.shouldUnregister, y.state.next({
submitCount: b.keepSubmitCount ? r.submitCount : 0,
isDirty: B ? !1 : b.keepDirty ? r.isDirty : !!(b.keepDefaultValues && !ze(p, a)),
isSubmitted: b.keepIsSubmitted ? r.isSubmitted : !1,
dirtyFields: B ? {} : b.keepDirtyValues ? b.keepDefaultValues && i ? Tt(a, i) : r.dirtyFields : b.keepDefaultValues && p ? Tt(a, p) : b.keepDirty ? r.dirtyFields : {},
touchedFields: b.keepTouched ? r.touchedFields : {},
errors: b.keepErrors ? r.errors : {},
isSubmitSuccessful: b.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
isSubmitting: !1,
defaultValues: a
});
}, Zt = (p, b) => vt(Ye(p) ? p(i) : p, b), mu = (p, b = {}) => {
const O = U(n, p), q = O && O._f;
if (q) {
const B = q.refs ? q.refs[0] : q.ref;
B.focus && (B.focus(), b.shouldSelect && Ye(B.select) && B.select());
}
}, gu = (p) => {
r = {
...r,
...p
};
}, Ya = {
control: {
register: oe,
unregister: ee,
getFieldState: T,
handleSubmit: V,
setError: X,
_subscribe: H,
_runSchema: ce,
_focusError: re,
_getWatch: ie,
_getDirty: ne,
_setValid: m,
_setFieldArray: $,
_setDisabledField: Z,
_setErrors: N,
_getFieldArray: he,
_reset: vt,
_resetDefaultValues: () => Ye(e.defaultValues) && e.defaultValues().then((p) => {
Zt(p, e.resetOptions), y.state.next({
isLoading: !1
});
}),
_removeUnmounted: le,
_disableForm: $e,
_subjects: y,
_proxyFormState: l,
get _fields() {
return n;
},
get _formValues() {
return i;
},
get _state() {
return o;
},
set _state(p) {
o = p;
},
get _defaultValues() {
return a;
},
get _names() {
return s;
},
set _names(p) {
s = p;
},
get _formState() {
return r;
},
get _options() {
return e;
},
set _options(p) {
e = {
...e,
...p
};
}
},
subscribe: se,
trigger: te,
register: oe,
handleSubmit: V,
watch: P,
setValue: k,
getValues: w,
reset: Zt,
resetField: Te,
clearErrors: Y,
unregister: ee,
setError: X,
setFocus: mu,
getFieldState: T
};
return {
...Ya,
formControl: Ya
};
}
function Lu(t = {}) {
const e = A.useRef(void 0), r = A.useRef(void 0), [n, a] = A.useState({
isDirty: !1,
isValidating: !1,
isLoading: Ye(t.defaultValues),
isSubmitted: !1,
isSubmitting: !1,
isSubmitSuccessful: !1,
isValid: !1,
submitCount: 0,
dirtyFields: {},
touchedFields: {},
validatingFields: {},
errors: t.errors || {},
disabled: t.disabled || !1,
isReady: !1,
defaultValues: Ye(t.defaultValues) ? void 0 : t.defaultValues
});
if (!e.current)
if (t.formControl)
e.current = {
...t.formControl,
formState: n
}, t.defaultValues && !Ye(t.defaultValues) && t.formControl.reset(t.defaultValues, t.resetOptions);
else {
const { formControl: o, ...s } = Mu(t);
e.current = {
...s,
formState: n
};
}
const i = e.current.control;
return i._options = t, Oa(() => {
const o = i._subscribe({
formState: i._proxyFormState,
callback: () => a({ ...i._formState }),
reRenderRoot: !0
});
return a((s) => ({
...s,
isReady: !0
})), i._formState.isReady = !0, o;
}, [i]), A.useEffect(() => i._disableForm(t.disabled), [i, t.disabled]), A.useEffect(() => {
t.mode && (i._options.mode = t.mode), t.reValidateMode && (i._options.reValidateMode = t.reValidateMode);
}, [i, t.mode, t.reValidateMode]), A.useEffect(() => {
t.errors && (i._setErrors(t.errors), i._focusError());
}, [i, t.errors]), A.useEffect(() => {
t.shouldUnregister && i._subjects.state.next({
values: i._getWatch()
});
}, [i, t.shouldUnregister]), A.useEffect(() => {
if (i._proxyFormState.isDirty) {
const o = i._getDirty();
o !== n.isDirty && i._subjects.state.next({
isDirty: o
});
}
}, [i, n.isDirty]), A.useEffect(() => {
t.values && !ze(t.values, r.current) ? (i._reset(t.values, {
keepFieldsRef: !0,
...i._options.resetOptions
}), r.current = t.values, a((o) => ({ ...o }))) : i._resetDefaultValues();
}, [i, t.values]), A.useEffect(() => {
i._state.mount || (i._setValid(), i._state.mount = !0), i._state.watch && (i._state.watch = !1, i._subjects.state.next({ ...i._formState })), i._removeUnmounted();
}), e.current.formState = Cs(n, i), e.current;
}
var J = /* @__PURE__ */ ((t) => (t.Text = "Text", t.TextArea = "TextArea", t.Email = "Email", t.Password = "Password", t.Url = "Url", t.Phone = "Phone", t.Number = "Number", t.Currency = "Currency", t.Checkbox = "Checkbox", t.Switch = "Switch", t.Button = "Button", t.DatePicker = "DatePicker", t.DateTimePicker = "DateTimePicker", t.TimePicker = "TimePicker", t.Select = "Select", t.EnumSelect = "EnumSelect", t.MultiSelect = "MultiSelect", t.Radio = "Radio", t.CheckboxGroup = "CheckboxGroup", t.SearchSelect = "SearchSelect", t.SearchSelectApollo = "SearchSelectApollo", t.SearchSelectMulti = "SearchSelectMulti", t.SearchSelectMultiApollo = "SearchSelectMultiApollo", t.Content = "Content", t.Custom = "Custom", t.CustomCheckbox = "CustomCheckbox", t.MarkdownEditor = "MarkdownEditor", t))(J || {});
function ks(t) {
var e, r, n = "";
if (typeof t == "string" || typeof t == "number") n += t;
else if (typeof t == "object") if (Array.isArray(t)) {
var a = t.length;
for (e = 0; e < a; e++) t[e] && (r = ks(t[e])) && (n && (n += " "), n += r);
} else for (r in t) t[r] && (n && (n += " "), n += r);
return n;
}
function S() {
for (var t, e, r = 0, n = "", a = arguments.length; r < a; r++) (t = arguments[r]) && (e = ks(t)) && (n && (n += " "), n += e);
return n;
}
const Ts = ba(null);
function Vu() {
const t = xa(Ts);
if (!t)
throw new Error("FormField components must be used within a <Form> component.");
return t;
}
const Is = ba({
labelDisplay: "default"
// 'default' is the sensible default
});
function Bu() {
const t = xa(Is);
if (!t)
throw new Error("useFormConfig must be used within a <Form> component.");
return t;
}
const Rr = "This field is required";
var ge;
(function(t) {
t.assertEqual = (a) => {
};
function e(a) {
}
t.assertIs = e;
function r(a) {
throw new Error();
}
t.assertNever = r, t.arrayToEnum = (a) => {
const i = {};
for (const o of a)
i[o] = o;
return i;
}, t.getValidEnumValues = (a) => {
const i = t.objectKeys(a).filter((s) => typeof a[a[s]] != "number"), o = {};
for (const s of i)
o[s] = a[s];
return t.objectValues(o);
}, t.objectValues = (a) => t.objectKeys(a).map(function(i) {
return a[i];
}), t.objectKeys = typeof Object.keys == "function" ? (a) => Object.keys(a) : (a) => {
const i = [];
for (const o in a)
Object.prototype.hasOwnProperty.call(a, o) && i.push(o);
return i;
}, t.find = (a, i) => {
for (const o of a)
if (i(o))
return o;
}, t.isInteger = typeof Number.isInteger == "function" ? (a) => Number.isInteger(a) : (a) => typeof a == "number" && Number.isFinite(a) && Math.floor(a) === a;
function n(a, i = " | ") {
return a.map((o) => typeof o == "string" ? `'${o}'` : o).join(i);
}
t.joinValues = n, t.jsonStringifyReplacer = (a, i) => typeof i == "bigint" ? i.toString() : i;
})(ge || (ge = {}));
var li;
(function(t) {
t.mergeShapes = (e, r) => ({
...e,
...r
// second overwrites first
});
})(li || (li = {}));
const z = ge.arrayToEnum([
"string",
"nan",
"number",
"integer",
"float",
"boolean",
"date",
"bigint",
"symbol",
"function",
"undefined",
"null",
"array",
"object",
"unknown",
"promise",
"void",
"never",
"map",
"set"
]), ct = (t) => {
switch (typeof t) {
case "undefined":
return z.undefined;
case "string":
return z.string;
case "number":
return Number.isNaN(t) ? z.nan : z.number;
case "boolean":
return z.boolean;
case "function":
return z.function;
case "bigint":
return z.bigint;
case "symbol":
return z.symbol;
case "object":
return Array.isArray(t) ? z.array : t === null ? z.null : t.then && typeof t.then == "function" && t.catch && typeof t.catch == "function" ? z.promise : typeof Map < "u" && t instanceof Map ? z.map : typeof Set < "u" && t instanceof Set ? z.set : typeof Date < "u" && t instanceof Date ? z.date : z.object;
default:
return z.unknown;
}
}, R = ge.arrayToEnum([
"invalid_type",
"invalid_literal",
"custom",
"invalid_union",
"invalid_union_discriminator",
"invalid_enum_value",
"unrecognized_keys",
"invalid_arguments",
"invalid_return_type",
"invalid_date",
"invalid_string",
"too_small",
"too_big",
"invalid_intersection_types",
"not_multiple_of",
"not_finite"
]);
class Qe extends Error {
get errors() {
return this.issues;
}
constructor(e) {
super(), this.issues = [], this.addIssue = (n) => {
this.issues = [...this.issues, n];
}, this.addIssues = (n = []) => {
this.issues = [...this.issues, ...n];
};
const r = new.target.prototype;
Object.setPrototypeOf ? Object.setPrototypeOf(this, r) : this.__proto__ = r, this.name = "ZodError", this.issues = e;
}
format(e) {
const r = e || function(i) {
return i.message;
}, n = { _errors: [] }, a = (i) => {
for (const o of i.issues)
if (o.code === "invalid_union")
o.unionErrors.map(a);
else if (o.code === "invalid_return_type")
a(o.returnTypeError);
else if (o.code === "invalid_arguments")
a(o.argumentsError);
else if (o.path.length === 0)
n._errors.push(r(o));
else {
let s = n, d = 0;
for (; d < o.path.length; ) {
const u = o.path[d];
d === o.path.length - 1 ? (s[u] = s[u] || { _errors: [] }, s[u]._errors.push(r(o))) : s[u] = s[u] || { _errors: [] }, s = s[u], d++;
}
}
};
return a(this), n;
}
static assert(e) {
if (!(e instanceof Qe))
throw new Error(`Not a ZodError: ${e}`);
}
toString() {
return this.message;
}
get message() {
return JSON.stringify(this.issues, ge.jsonStringifyReplacer, 2);
}
get isEmpty() {
return this.issues.length === 0;
}
flatten(e = (r) => r.message) {
const r = {}, n = [];
for (const a of this.issues)
if (a.path.length > 0) {
const i = a.path[0];
r[i] = r[i] || [], r[i].push(e(a));
} else
n.push(e(a));
return { formErrors: n, fieldErrors: r };
}
get formErrors() {
return this.flatten();
}
}
Qe.create = (t) => new Qe(t);
const jn = (t, e) => {
let r;
switch (t.code) {
case R.invalid_type:
t.received === z.undefined ? r = "Required" : r = `Expected ${t.expected}, received ${t.received}`;
break;
case R.invalid_literal:
r = `Invalid literal value, expected ${JSON.stringify(t.expected, ge.jsonStringifyReplacer)}`;
break;
case R.unrecognized_keys:
r = `Unrecognized key(s) in object: ${ge.joinValues(t.keys, ", ")}`;
break;
case R.invalid_union:
r = "Invalid input";
break;
case R.invalid_union_discriminator:
r = `Invalid discriminator value. Expected ${ge.joinValues(t.options)}`;
break;
case R.invalid_enum_value:
r = `Invalid enum value. Expected ${ge.joinValues(t.options)}, received '${t.received}'`;
break;
case R.invalid_arguments:
r = "Invalid function arguments";
break;
case R.invalid_return_type:
r = "Invalid function return type";
break;
case R.invalid_date:
r = "Invalid date";
break;
case R.invalid_string:
typeof t.validation == "object" ? "includes" in t.validation ? (r = `Invalid input: must include "${t.validation.includes}"`, typeof t.validation.position == "number" && (r = `${r} at one or more positions greater than or equal to ${t.validation.position}`)) : "startsWith" in t.validation ? r = `Invalid input: must start with "${t.validation.startsWith}"` : "endsWith" in t.validation ? r = `Invalid input: must end with "${t.validation.endsWith}"` : ge.assertNever(t.validation) : t.validation !== "regex" ? r = `Invalid ${t.validation}` : r = "Invalid";
break;
case R.too_small:
t.type === "array" ? r = `Array must contain ${t.exact ? "exactly" : t.inclusive ? "at least" : "more than"} ${t.minimum} element(s)` : t.type === "string" ? r = `String must contain ${t.exact ? "exactly" : t.inclusive ? "at least" : "over"} ${t.minimum} character(s)` : t.type === "number" ? r = `Number must be ${t.exact ? "exactly equal to " : t.inclusive ? "greater than or equal to " : "greater than "}${t.minimum}` : t.type === "bigint" ? r = `Number must be ${t.exact ? "exactly equal to " : t.inclusive ? "greater than or equal to " : "greater than "}${t.minimum}` : t.type === "date" ? r = `Date must be ${t.exact ? "exactly equal to " : t.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(t.minimum))}` : r = "Invalid input";
break;
case R.too_big:
t.type === "array" ? r = `Array must contain ${t.exact ? "exactly" : t.inclusive ? "at most" : "less than"} ${t.maximum} element(s)` : t.type === "string" ? r = `String must contain ${t.exact ? "exactly" : t.inclusive ? "at most" : "under"} ${t.maximum} character(s)` : t.type === "number" ? r = `Number must be ${t.exact ? "exactly" : t.inclusive ? "less than or equal to" : "less than"} ${t.maximum}` : t.type === "bigint" ? r = `BigInt must be ${t.exact ? "exactly" : t.inclusive ? "less than or equal to" : "less than"} ${t.maximum}` : t.type === "date" ? r = `Date must be ${t.exact ? "exactly" : t.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(t.maximum))}` : r = "Invalid input";
break;
case R.custom:
r = "Invalid input";
break;
case R.invalid_intersection_types:
r = "Intersection results could not be merged";
break;
case R.not_multiple_of:
r = `Number must be a multiple of ${t.multipleOf}`;
break;
case R.not_finite:
r = "Number must be finite";
break;
default:
r = e.defaultError, ge.assertNever(t);
}
return { message: r };
};
let Uu = jn;
function Wu() {
return Uu;
}
const Gu = (t) => {
const { data: e, path: r, errorMaps: n, issueData: a } = t, i = [...r, ...a.path || []], o = {
...a,
path: i
};
if (a.message !== void 0)
return {
...a,
path: i,
message: a.message
};
let s = "";
const d = n.filter((u) => !!u).slice().reverse();
for (const u of d)
s = u(o, { data: e, defaultError: s }).message;
return {
...a,
path: i,
message: s
};
};
function G(t, e) {
const r = Wu(), n = Gu({
issueData: e,
data: t.data,
path: t.path,
errorMaps: [
t.common.contextualErrorMap,
// contextual error map is first priority
t.schemaErrorMap,
// then schema-bound map if available
r,
// then global override map
r === jn ? void 0 : jn
// then global default map
].filter((a) => !!a)
});
t.common.issues.push(n);
}
class Ue {
constructor() {
this.value = "valid";
}
dirty() {
this.value === "valid" && (this.value = "dirty");
}
abort() {
this.value !== "aborted" && (this.value = "aborted");
}
static mergeArray(e, r) {
const n = [];
for (const a of r) {
if (a.status === "aborted")
return de;
a.status === "dirty" && e.dirty(), n.push(a.value);
}
return { status: e.value, value: n };
}
static async mergeObjectAsync(e, r) {
const n = [];
for (const a of r) {
const i = await a.key, o = await a.value;
n.push({
key: i,
value: o