@nestledjs/forms
Version:
A flexible React form library supporting both declarative and imperative usage patterns with TypeScript support
1,476 lines • 636 kB
JavaScript
import { jsxs as G, Fragment as Se, jsx as h } from "react/jsx-runtime";
import * as li from "react";
import M, { createContext as ka, useContext as Ta, lazy as rl, useEffect as rt, useCallback as ze, Suspense as ci, useRef as or, useMemo as Pt, useState as et } from "react";
function nl(t, e) {
for (var r = 0; r < e.length; r++) {
const n = e[r];
if (typeof n != "string" && !Array.isArray(n)) {
for (const a in n)
if (a !== "default" && !(a in t)) {
const i = Object.getOwnPropertyDescriptor(n, a);
i && Object.defineProperty(t, a, i.get ? i : {
enumerable: !0,
get: () => n[a]
});
}
}
}
return Object.freeze(Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }));
}
var vr = (t) => t.type === "checkbox", Ot = (t) => t instanceof Date, Be = (t) => t == null;
const Ls = (t) => typeof t == "object";
var Ae = (t) => !Be(t) && !Array.isArray(t) && Ls(t) && !Ot(t), Vs = (t) => Ae(t) && t.target ? vr(t.target) ? t.target.checked : t.target.value : t, al = (t) => t.substring(0, t.search(/\.\d+(\.|$)/)) || t, Us = (t, e) => t.has(al(e)), il = (t) => {
const e = t.constructor && t.constructor.prototype;
return Ae(e) && e.hasOwnProperty("isPrototypeOf");
}, Ia = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
function Le(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 (t instanceof Set)
e = new Set(t);
else if (!(Ia && (t instanceof Blob || n)) && (r || Ae(t)))
if (e = r ? [] : {}, !r && !il(t))
e = t;
else
for (const a in t)
t.hasOwnProperty(a) && (e[a] = Le(t[a]));
else
return t;
return e;
}
var nn = (t) => /^\w*$/.test(t), Ee = (t) => t === void 0, Ea = (t) => Array.isArray(t) ? t.filter(Boolean) : [], Aa = (t) => Ea(t.replace(/["|']|\]/g, "").split(/\.|\[/)), W = (t, e, r) => {
if (!e || !Ae(t))
return r;
const n = (nn(e) ? [e] : Aa(e)).reduce((a, i) => Be(a) ? a : a[i], t);
return Ee(n) || n === t ? Ee(t[e]) ? r : t[e] : n;
}, Ge = (t) => typeof t == "boolean", _e = (t, e, r) => {
let n = -1;
const a = nn(e) ? [e] : Aa(e), i = a.length, o = i - 1;
for (; ++n < i; ) {
const s = a[n];
let u = r;
if (n !== o) {
const d = t[s];
u = Ae(d) || Array.isArray(d) ? d : isNaN(+a[n + 1]) ? {} : [];
}
if (s === "__proto__" || s === "constructor" || s === "prototype")
return;
t[s] = u, t = t[s];
}
};
const Dr = {
BLUR: "blur",
FOCUS_OUT: "focusout",
CHANGE: "change"
}, Xe = {
onBlur: "onBlur",
onChange: "onChange",
onSubmit: "onSubmit",
onTouched: "onTouched",
all: "all"
}, it = {
max: "max",
min: "min",
maxLength: "maxLength",
minLength: "minLength",
pattern: "pattern",
required: "required",
validate: "validate"
}, Bs = M.createContext(null);
Bs.displayName = "HookFormContext";
const Fa = () => M.useContext(Bs);
var qs = (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] !== Xe.all && (e._proxyFormState[o] = !n || Xe.all), r && (r[o] = !0), t[o];
}
});
return a;
};
const Ra = typeof window < "u" ? li.useLayoutEffect : li.useEffect;
function ol(t) {
const e = Fa(), { control: r = e.control, disabled: n, name: a, exact: i } = t || {}, [o, s] = M.useState(r._formState), u = M.useRef({
isDirty: !1,
isLoading: !1,
dirtyFields: !1,
touchedFields: !1,
validatingFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
});
return Ra(() => r._subscribe({
name: a,
formState: u.current,
exact: i,
callback: (d) => {
!n && s({
...r._formState,
...d
});
}
}), [a, n, i]), M.useEffect(() => {
u.current.isValid && r._setValid(!0);
}, [r]), M.useMemo(() => qs(o, r, u.current, !1), [o, r]);
}
var nt = (t) => typeof t == "string", Ws = (t, e, r, n, a) => nt(t) ? (n && e.watch.add(t), W(r, t, a)) : Array.isArray(t) ? t.map((i) => (n && e.watch.add(i), W(r, i))) : (n && (e.watchAll = !0), r);
function Da(t) {
const e = Fa(), { control: r = e.control, name: n, defaultValue: a, disabled: i, exact: o } = t || {}, s = M.useRef(a), [u, d] = M.useState(r._getWatch(n, s.current));
return Ra(() => r._subscribe({
name: n,
formState: {
values: !0
},
exact: o,
callback: (l) => !i && d(Ws(n, r._names, l.values || r._formValues, !1, s.current))
}), [n, r, i, o]), M.useEffect(() => r._removeUnmounted()), u;
}
function sl(t) {
const e = Fa(), { name: r, disabled: n, control: a = e.control, shouldUnregister: i } = t, o = Us(a._names.array, r), s = Da({
control: a,
name: r,
defaultValue: W(a._formValues, r, W(a._defaultValues, r, t.defaultValue)),
exact: !0
}), u = ol({
control: a,
name: r,
exact: !0
}), d = M.useRef(t), l = M.useRef(a.register(r, {
...t.rules,
value: s,
...Ge(t.disabled) ? { disabled: t.disabled } : {}
})), f = M.useMemo(() => Object.defineProperties({}, {
invalid: {
enumerable: !0,
get: () => !!W(u.errors, r)
},
isDirty: {
enumerable: !0,
get: () => !!W(u.dirtyFields, r)
},
isTouched: {
enumerable: !0,
get: () => !!W(u.touchedFields, r)
},
isValidating: {
enumerable: !0,
get: () => !!W(u.validatingFields, r)
},
error: {
enumerable: !0,
get: () => W(u.errors, r)
}
}), [u, r]), p = M.useCallback((g) => l.current.onChange({
target: {
value: Vs(g),
name: r
},
type: Dr.CHANGE
}), [r]), m = M.useCallback(() => l.current.onBlur({
target: {
value: W(a._formValues, r),
name: r
},
type: Dr.BLUR
}), [r, a._formValues]), w = M.useCallback((g) => {
const v = W(a._fields, r);
v && g && (v._f.ref = {
focus: () => g.focus && g.focus(),
select: () => g.select && g.select(),
setCustomValidity: ($) => g.setCustomValidity($),
reportValidity: () => g.reportValidity()
});
}, [a._fields, r]), C = M.useMemo(() => ({
name: r,
value: s,
...Ge(n) || u.disabled ? { disabled: u.disabled || n } : {},
onChange: p,
onBlur: m,
ref: w
}), [r, n, u.disabled, p, m, w, s]);
return M.useEffect(() => {
const g = a._options.shouldUnregister || i;
a.register(r, {
...d.current.rules,
...Ge(d.current.disabled) ? { disabled: d.current.disabled } : {}
});
const v = ($, I) => {
const S = W(a._fields, $);
S && S._f && (S._f.mount = I);
};
if (v(r, !0), g) {
const $ = Le(W(a._options.defaultValues, r));
_e(a._defaultValues, r, $), Ee(W(a._formValues, r)) && _e(a._formValues, r, $);
}
return !o && a.register(r), () => {
(o ? g && !a._state.action : g) ? a.unregister(r) : v(r, !1);
};
}, [r, a, o, i]), M.useEffect(() => {
a._setDisabledField({
disabled: n,
name: r
});
}, [n, r, a]), M.useMemo(() => ({
field: C,
formState: u,
fieldState: f
}), [C, u, f]);
}
const ft = (t) => t.render(sl(t));
var ul = (t, e, r, n, a) => e ? {
...r[t],
types: {
...r[t] && r[t].types ? r[t].types : {},
[n]: a || !0
}
} : {}, sr = (t) => Array.isArray(t) ? t : [t], fi = () => {
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 = [];
}
};
}, Bn = (t) => Be(t) || !Ls(t);
function gt(t, e) {
if (Bn(t) || Bn(e))
return t === e;
if (Ot(t) && Ot(e))
return t.getTime() === e.getTime();
const r = Object.keys(t), n = Object.keys(e);
if (r.length !== n.length)
return !1;
for (const a of r) {
const i = t[a];
if (!n.includes(a))
return !1;
if (a !== "ref") {
const o = e[a];
if (Ot(i) && Ot(o) || Ae(i) && Ae(o) || Array.isArray(i) && Array.isArray(o) ? !gt(i, o) : i !== o)
return !1;
}
}
return !0;
}
var We = (t) => Ae(t) && !Object.keys(t).length, Ma = (t) => t.type === "file", Je = (t) => typeof t == "function", Mr = (t) => {
if (!Ia)
return !1;
const e = t ? t.ownerDocument : 0;
return t instanceof (e && e.defaultView ? e.defaultView.HTMLElement : HTMLElement);
}, Gs = (t) => t.type === "select-multiple", ja = (t) => t.type === "radio", dl = (t) => ja(t) || vr(t), $n = (t) => Mr(t) && t.isConnected;
function ll(t, e) {
const r = e.slice(0, -1).length;
let n = 0;
for (; n < r; )
t = Ee(t) ? n++ : t[e[n++]];
return t;
}
function cl(t) {
for (const e in t)
if (t.hasOwnProperty(e) && !Ee(t[e]))
return !1;
return !0;
}
function Re(t, e) {
const r = Array.isArray(e) ? e : nn(e) ? [e] : Aa(e), n = r.length === 1 ? t : ll(t, r), a = r.length - 1, i = r[a];
return n && delete n[i], a !== 0 && (Ae(n) && We(n) || Array.isArray(n) && cl(n)) && Re(t, r.slice(0, -1)), t;
}
var Hs = (t) => {
for (const e in t)
if (Je(t[e]))
return !0;
return !1;
};
function jr(t, e = {}) {
const r = Array.isArray(t);
if (Ae(t) || r)
for (const n in t)
Array.isArray(t[n]) || Ae(t[n]) && !Hs(t[n]) ? (e[n] = Array.isArray(t[n]) ? [] : {}, jr(t[n], e[n])) : Be(t[n]) || (e[n] = !0);
return e;
}
function Zs(t, e, r) {
const n = Array.isArray(t);
if (Ae(t) || n)
for (const a in t)
Array.isArray(t[a]) || Ae(t[a]) && !Hs(t[a]) ? Ee(e) || Bn(r[a]) ? r[a] = Array.isArray(t[a]) ? jr(t[a], []) : { ...jr(t[a]) } : Zs(t[a], Be(e) ? {} : e[a], r[a]) : r[a] = !gt(t[a], e[a]);
return r;
}
var er = (t, e) => Zs(t, e, jr(e));
const hi = {
value: !1,
isValid: !1
}, pi = { value: !0, isValid: !0 };
var zs = (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 && !Ee(t[0].attributes.value) ? Ee(t[0].value) || t[0].value === "" ? pi : { value: t[0].value, isValid: !0 } : pi
) : hi;
}
return hi;
}, Ks = (t, { valueAsNumber: e, valueAsDate: r, setValueAs: n }) => Ee(t) ? t : e ? t === "" ? NaN : t && +t : r && nt(t) ? new Date(t) : n ? n(t) : t;
const yi = {
isValid: !1,
value: null
};
var Ys = (t) => Array.isArray(t) ? t.reduce((e, r) => r && r.checked && !r.disabled ? {
isValid: !0,
value: r.value
} : e, yi) : yi;
function mi(t) {
const e = t.ref;
return Ma(e) ? e.files : ja(e) ? Ys(t.refs).value : Gs(e) ? [...e.selectedOptions].map(({ value: r }) => r) : vr(e) ? zs(t.refs).value : Ks(Ee(e.value) ? t.ref.value : e.value, t);
}
var fl = (t, e, r, n) => {
const a = {};
for (const i of t) {
const o = W(e, i);
o && _e(a, i, o._f);
}
return {
criteriaMode: r,
names: [...t],
fields: a,
shouldUseNativeValidation: n
};
}, Lr = (t) => t instanceof RegExp, tr = (t) => Ee(t) ? t : Lr(t) ? t.source : Ae(t) ? Lr(t.value) ? t.value.source : t.value : t, gi = (t) => ({
isOnSubmit: !t || t === Xe.onSubmit,
isOnBlur: t === Xe.onBlur,
isOnChange: t === Xe.onChange,
isOnAll: t === Xe.all,
isOnTouch: t === Xe.onTouched
});
const vi = "AsyncFunction";
var hl = (t) => !!t && !!t.validate && !!(Je(t.validate) && t.validate.constructor.name === vi || Ae(t.validate) && Object.values(t.validate).find((e) => e.constructor.name === vi)), pl = (t) => t.mount && (t.required || t.min || t.max || t.maxLength || t.minLength || t.pattern || t.validate), $i = (t, e, r) => !r && (e.watchAll || e.watch.has(t) || [...e.watch].some((n) => t.startsWith(n) && /^\.\w+/.test(t.slice(n.length))));
const ur = (t, e, r, n) => {
for (const a of r || Object.keys(t)) {
const i = W(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 (ur(s, e))
break;
} else if (Ae(s) && ur(s, e))
break;
}
}
};
function bi(t, e, r) {
const n = W(t, r);
if (n || nn(r))
return {
error: n,
name: r
};
const a = r.split(".");
for (; a.length; ) {
const i = a.join("."), o = W(e, i), s = W(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 yl = (t, e, r, n) => {
r(t);
const { name: a, ...i } = t;
return We(i) || Object.keys(i).length >= Object.keys(e).length || Object.keys(i).find((o) => e[o] === (!n || Xe.all));
}, ml = (t, e, r) => !t || !e || t === e || sr(t).some((n) => n && (r ? n === e : n.startsWith(e) || e.startsWith(n))), gl = (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, vl = (t, e) => !Ea(W(t, e)).length && Re(t, e), $l = (t, e, r) => {
const n = sr(W(t, r));
return _e(n, "root", e[r]), _e(t, r, n), t;
}, kr = (t) => nt(t);
function xi(t, e, r = "validate") {
if (kr(t) || Array.isArray(t) && t.every(kr) || Ge(t) && !t)
return {
type: r,
message: kr(t) ? t : "",
ref: e
};
}
var Et = (t) => Ae(t) && !Lr(t) ? t : {
value: t,
message: ""
}, wi = async (t, e, r, n, a, i) => {
const { ref: o, refs: s, required: u, maxLength: d, minLength: l, min: f, max: p, pattern: m, validate: w, name: C, valueAsNumber: g, mount: v } = t._f, $ = W(r, C);
if (!v || e.has(C))
return {};
const I = s ? s[0] : o, S = (J) => {
a && I.reportValidity && (I.setCustomValidity(Ge(J) ? "" : J || ""), I.reportValidity());
}, b = {}, z = ja(o), fe = vr(o), pe = z || fe, de = (g || Ma(o)) && Ee(o.value) && Ee($) || Mr(o) && o.value === "" || $ === "" || Array.isArray($) && !$.length, se = ul.bind(null, C, n, b), X = (J, he, L, A = it.maxLength, P = it.minLength) => {
const j = J ? he : L;
b[C] = {
type: J ? A : P,
message: j,
ref: o,
...se(J ? A : P, j)
};
};
if (i ? !Array.isArray($) || !$.length : u && (!pe && (de || Be($)) || Ge($) && !$ || fe && !zs(s).isValid || z && !Ys(s).isValid)) {
const { value: J, message: he } = kr(u) ? { value: !!u, message: u } : Et(u);
if (J && (b[C] = {
type: it.required,
message: he,
ref: I,
...se(it.required, he)
}, !n))
return S(he), b;
}
if (!de && (!Be(f) || !Be(p))) {
let J, he;
const L = Et(p), A = Et(f);
if (!Be($) && !isNaN($)) {
const P = o.valueAsNumber || $ && +$;
Be(L.value) || (J = P > L.value), Be(A.value) || (he = P < A.value);
} else {
const P = o.valueAsDate || new Date($), j = (_) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + _), R = o.type == "time", ee = o.type == "week";
nt(L.value) && $ && (J = R ? j($) > j(L.value) : ee ? $ > L.value : P > new Date(L.value)), nt(A.value) && $ && (he = R ? j($) < j(A.value) : ee ? $ < A.value : P < new Date(A.value));
}
if ((J || he) && (X(!!J, L.message, A.message, it.max, it.min), !n))
return S(b[C].message), b;
}
if ((d || l) && !de && (nt($) || i && Array.isArray($))) {
const J = Et(d), he = Et(l), L = !Be(J.value) && $.length > +J.value, A = !Be(he.value) && $.length < +he.value;
if ((L || A) && (X(L, J.message, he.message), !n))
return S(b[C].message), b;
}
if (m && !de && nt($)) {
const { value: J, message: he } = Et(m);
if (Lr(J) && !$.match(J) && (b[C] = {
type: it.pattern,
message: he,
ref: o,
...se(it.pattern, he)
}, !n))
return S(he), b;
}
if (w) {
if (Je(w)) {
const J = await w($, r), he = xi(J, I);
if (he && (b[C] = {
...he,
...se(it.validate, he.message)
}, !n))
return S(he.message), b;
} else if (Ae(w)) {
let J = {};
for (const he in w) {
if (!We(J) && !n)
break;
const L = xi(await w[he]($, r), I, he);
L && (J = {
...L,
...se(he, L.message)
}, S(L.message), n && (b[C] = J));
}
if (!We(J) && (b[C] = {
ref: I,
...J
}, !n))
return b;
}
}
return S(!0), b;
};
const bl = {
mode: Xe.onSubmit,
reValidateMode: Xe.onChange,
shouldFocusError: !0
};
function xl(t = {}) {
let e = {
...bl,
...t
}, r = {
submitCount: 0,
isDirty: !1,
isReady: !1,
isLoading: Je(e.defaultValues),
isValidating: !1,
isSubmitted: !1,
isSubmitting: !1,
isSubmitSuccessful: !1,
isValid: !1,
touchedFields: {},
dirtyFields: {},
validatingFields: {},
errors: e.errors || {},
disabled: e.disabled || !1
};
const n = {};
let a = Ae(e.defaultValues) || Ae(e.values) ? Le(e.defaultValues || e.values) || {} : {}, i = e.shouldUnregister ? {} : Le(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()
}, u, d = 0;
const l = {
isDirty: !1,
dirtyFields: !1,
validatingFields: !1,
touchedFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
};
let f = {
...l
};
const p = {
array: fi(),
state: fi()
}, m = e.criteriaMode === Xe.all, w = (y) => (x) => {
clearTimeout(d), d = setTimeout(y, x);
}, C = async (y) => {
if (!e.disabled && (l.isValid || f.isValid || y)) {
const x = e.resolver ? We((await fe()).errors) : await de(n, !0);
x !== r.isValid && p.state.next({
isValid: x
});
}
}, g = (y, x) => {
!e.disabled && (l.isValidating || l.validatingFields || f.isValidating || f.validatingFields) && ((y || Array.from(s.mount)).forEach((N) => {
N && (x ? _e(r.validatingFields, N, x) : Re(r.validatingFields, N));
}), p.state.next({
validatingFields: r.validatingFields,
isValidating: !We(r.validatingFields)
}));
}, v = (y, x = [], N, Z, B = !0, D = !0) => {
if (Z && N && !e.disabled) {
if (o.action = !0, D && Array.isArray(W(n, y))) {
const ie = N(W(n, y), Z.argA, Z.argB);
B && _e(n, y, ie);
}
if (D && Array.isArray(W(r.errors, y))) {
const ie = N(W(r.errors, y), Z.argA, Z.argB);
B && _e(r.errors, y, ie), vl(r.errors, y);
}
if ((l.touchedFields || f.touchedFields) && D && Array.isArray(W(r.touchedFields, y))) {
const ie = N(W(r.touchedFields, y), Z.argA, Z.argB);
B && _e(r.touchedFields, y, ie);
}
(l.dirtyFields || f.dirtyFields) && (r.dirtyFields = er(a, i)), p.state.next({
name: y,
isDirty: X(y, x),
dirtyFields: r.dirtyFields,
errors: r.errors,
isValid: r.isValid
});
} else
_e(i, y, x);
}, $ = (y, x) => {
_e(r.errors, y, x), p.state.next({
errors: r.errors
});
}, I = (y) => {
r.errors = y, p.state.next({
errors: r.errors,
isValid: !1
});
}, S = (y, x, N, Z) => {
const B = W(n, y);
if (B) {
const D = W(i, y, Ee(N) ? W(a, y) : N);
Ee(D) || Z && Z.defaultChecked || x ? _e(i, y, x ? D : mi(B._f)) : L(y, D), o.mount && C();
}
}, b = (y, x, N, Z, B) => {
let D = !1, ie = !1;
const xe = {
name: y
};
if (!e.disabled) {
if (!N || Z) {
(l.isDirty || f.isDirty) && (ie = r.isDirty, r.isDirty = xe.isDirty = X(), D = ie !== xe.isDirty);
const Ce = gt(W(a, y), x);
ie = !!W(r.dirtyFields, y), Ce ? Re(r.dirtyFields, y) : _e(r.dirtyFields, y, !0), xe.dirtyFields = r.dirtyFields, D = D || (l.dirtyFields || f.dirtyFields) && ie !== !Ce;
}
if (N) {
const Ce = W(r.touchedFields, y);
Ce || (_e(r.touchedFields, y, N), xe.touchedFields = r.touchedFields, D = D || (l.touchedFields || f.touchedFields) && Ce !== N);
}
D && B && p.state.next(xe);
}
return D ? xe : {};
}, z = (y, x, N, Z) => {
const B = W(r.errors, y), D = (l.isValid || f.isValid) && Ge(x) && r.isValid !== x;
if (e.delayError && N ? (u = w(() => $(y, N)), u(e.delayError)) : (clearTimeout(d), u = null, N ? _e(r.errors, y, N) : Re(r.errors, y)), (N ? !gt(B, N) : B) || !We(Z) || D) {
const ie = {
...Z,
...D && Ge(x) ? { isValid: x } : {},
errors: r.errors,
name: y
};
r = {
...r,
...ie
}, p.state.next(ie);
}
}, fe = async (y) => {
g(y, !0);
const x = await e.resolver(i, e.context, fl(y || s.mount, n, e.criteriaMode, e.shouldUseNativeValidation));
return g(y), x;
}, pe = async (y) => {
const { errors: x } = await fe(y);
if (y)
for (const N of y) {
const Z = W(x, N);
Z ? _e(r.errors, N, Z) : Re(r.errors, N);
}
else
r.errors = x;
return x;
}, de = async (y, x, N = {
valid: !0
}) => {
for (const Z in y) {
const B = y[Z];
if (B) {
const { _f: D, ...ie } = B;
if (D) {
const xe = s.array.has(D.name), Ce = B._f && hl(B._f);
Ce && l.validatingFields && g([Z], !0);
const Ze = await wi(B, s.disabled, i, m, e.shouldUseNativeValidation && !x, xe);
if (Ce && l.validatingFields && g([Z]), Ze[D.name] && (N.valid = !1, x))
break;
!x && (W(Ze, D.name) ? xe ? $l(r.errors, Ze, D.name) : _e(r.errors, D.name, Ze[D.name]) : Re(r.errors, D.name));
}
!We(ie) && await de(ie, x, N);
}
}
return N.valid;
}, se = () => {
for (const y of s.unMount) {
const x = W(n, y);
x && (x._f.refs ? x._f.refs.every((N) => !$n(N)) : !$n(x._f.ref)) && q(y);
}
s.unMount = /* @__PURE__ */ new Set();
}, X = (y, x) => !e.disabled && (y && x && _e(i, y, x), !gt(_(), a)), J = (y, x, N) => Ws(y, s, {
...o.mount ? i : Ee(x) ? a : nt(y) ? { [y]: x } : x
}, N, x), he = (y) => Ea(W(o.mount ? i : a, y, e.shouldUnregister ? W(a, y, []) : [])), L = (y, x, N = {}) => {
const Z = W(n, y);
let B = x;
if (Z) {
const D = Z._f;
D && (!D.disabled && _e(i, y, Ks(x, D)), B = Mr(D.ref) && Be(x) ? "" : x, Gs(D.ref) ? [...D.ref.options].forEach((ie) => ie.selected = B.includes(ie.value)) : D.refs ? vr(D.ref) ? D.refs.forEach((ie) => {
(!ie.defaultChecked || !ie.disabled) && (Array.isArray(B) ? ie.checked = !!B.find((xe) => xe === ie.value) : ie.checked = B === ie.value || !!B);
}) : D.refs.forEach((ie) => ie.checked = ie.value === B) : Ma(D.ref) ? D.ref.value = "" : (D.ref.value = B, D.ref.type || p.state.next({
name: y,
values: Le(i)
})));
}
(N.shouldDirty || N.shouldTouch) && b(y, B, N.shouldTouch, N.shouldDirty, !0), N.shouldValidate && ee(y);
}, A = (y, x, N) => {
for (const Z in x) {
if (!x.hasOwnProperty(Z))
return;
const B = x[Z], D = y + "." + Z, ie = W(n, D);
(s.array.has(y) || Ae(B) || ie && !ie._f) && !Ot(B) ? A(D, B, N) : L(D, B, N);
}
}, P = (y, x, N = {}) => {
const Z = W(n, y), B = s.array.has(y), D = Le(x);
_e(i, y, D), B ? (p.array.next({
name: y,
values: Le(i)
}), (l.isDirty || l.dirtyFields || f.isDirty || f.dirtyFields) && N.shouldDirty && p.state.next({
name: y,
dirtyFields: er(a, i),
isDirty: X(y, D)
})) : Z && !Z._f && !Be(D) ? A(y, D, N) : L(y, D, N), $i(y, s) && p.state.next({ ...r }), p.state.next({
name: o.mount ? y : void 0,
values: Le(i)
});
}, j = async (y) => {
o.mount = !0;
const x = y.target;
let N = x.name, Z = !0;
const B = W(n, N), D = (Ce) => {
Z = Number.isNaN(Ce) || Ot(Ce) && isNaN(Ce.getTime()) || gt(Ce, W(i, N, Ce));
}, ie = gi(e.mode), xe = gi(e.reValidateMode);
if (B) {
let Ce, Ze;
const xr = x.type ? mi(B._f) : Vs(y), pt = y.type === Dr.BLUR || y.type === Dr.FOCUS_OUT, Jd = !pl(B._f) && !e.resolver && !W(r.errors, N) && !B._f.deps || gl(pt, W(r.touchedFields, N), r.isSubmitted, xe, ie), gn = $i(N, s, pt);
_e(i, N, xr), pt ? (B._f.onBlur && B._f.onBlur(y), u && u(0)) : B._f.onChange && B._f.onChange(y);
const vn = b(N, xr, pt), el = !We(vn) || gn;
if (!pt && p.state.next({
name: N,
type: y.type,
values: Le(i)
}), Jd)
return (l.isValid || f.isValid) && (e.mode === "onBlur" ? pt && C() : pt || C()), el && p.state.next({ name: N, ...gn ? {} : vn });
if (!pt && gn && p.state.next({ ...r }), e.resolver) {
const { errors: ui } = await fe([N]);
if (D(xr), Z) {
const tl = bi(r.errors, n, N), di = bi(ui, n, tl.name || N);
Ce = di.error, N = di.name, Ze = We(ui);
}
} else
g([N], !0), Ce = (await wi(B, s.disabled, i, m, e.shouldUseNativeValidation))[N], g([N]), D(xr), Z && (Ce ? Ze = !1 : (l.isValid || f.isValid) && (Ze = await de(n, !0)));
Z && (B._f.deps && ee(B._f.deps), z(N, Ze, Ce, vn));
}
}, R = (y, x) => {
if (W(r.errors, x) && y.focus)
return y.focus(), 1;
}, ee = async (y, x = {}) => {
let N, Z;
const B = sr(y);
if (e.resolver) {
const D = await pe(Ee(y) ? y : B);
N = We(D), Z = y ? !B.some((ie) => W(D, ie)) : N;
} else y ? (Z = (await Promise.all(B.map(async (D) => {
const ie = W(n, D);
return await de(ie && ie._f ? { [D]: ie } : ie);
}))).every(Boolean), !(!Z && !r.isValid) && C()) : Z = N = await de(n);
return p.state.next({
...!nt(y) || (l.isValid || f.isValid) && N !== r.isValid ? {} : { name: y },
...e.resolver || !y ? { isValid: N } : {},
errors: r.errors
}), x.shouldFocus && !Z && ur(n, R, y ? B : s.mount), Z;
}, _ = (y) => {
const x = {
...o.mount ? i : a
};
return Ee(y) ? x : nt(y) ? W(x, y) : y.map((N) => W(x, N));
}, T = (y, x) => ({
invalid: !!W((x || r).errors, y),
isDirty: !!W((x || r).dirtyFields, y),
error: W((x || r).errors, y),
isValidating: !!W(r.validatingFields, y),
isTouched: !!W((x || r).touchedFields, y)
}), K = (y) => {
y && sr(y).forEach((x) => Re(r.errors, x)), p.state.next({
errors: y ? r.errors : {}
});
}, k = (y, x, N) => {
const Z = (W(n, y, { _f: {} })._f || {}).ref, B = W(r.errors, y) || {}, { ref: D, message: ie, type: xe, ...Ce } = B;
_e(r.errors, y, {
...Ce,
...x,
ref: Z
}), p.state.next({
name: y,
errors: r.errors,
isValid: !1
}), N && N.shouldFocus && Z && Z.focus && Z.focus();
}, U = (y, x) => Je(y) ? p.state.subscribe({
next: (N) => y(J(void 0, x), N)
}) : J(y, x, !0), re = (y) => p.state.subscribe({
next: (x) => {
ml(y.name, x.name, y.exact) && yl(x, y.formState || l, Xd, y.reRenderRoot) && y.callback({
values: { ...i },
...r,
...x
});
}
}).unsubscribe, oe = (y) => (o.mount = !0, f = {
...f,
...y.formState
}, re({
...y,
formState: f
})), q = (y, x = {}) => {
for (const N of y ? sr(y) : s.mount)
s.mount.delete(N), s.array.delete(N), x.keepValue || (Re(n, N), Re(i, N)), !x.keepError && Re(r.errors, N), !x.keepDirty && Re(r.dirtyFields, N), !x.keepTouched && Re(r.touchedFields, N), !x.keepIsValidating && Re(r.validatingFields, N), !e.shouldUnregister && !x.keepDefaultValue && Re(a, N);
p.state.next({
values: Le(i)
}), p.state.next({
...r,
...x.keepDirty ? { isDirty: X() } : {}
}), !x.keepIsValid && C();
}, ae = ({ disabled: y, name: x }) => {
(Ge(y) && o.mount || y || s.disabled.has(x)) && (y ? s.disabled.add(x) : s.disabled.delete(x));
}, ue = (y, x = {}) => {
let N = W(n, y);
const Z = Ge(x.disabled) || Ge(e.disabled);
return _e(n, y, {
...N || {},
_f: {
...N && N._f ? N._f : { ref: { name: y } },
name: y,
mount: !0,
...x
}
}), s.mount.add(y), N ? ae({
disabled: Ge(x.disabled) ? x.disabled : e.disabled,
name: y
}) : S(y, !0, x.value), {
...Z ? { disabled: x.disabled || e.disabled } : {},
...e.progressive ? {
required: !!x.required,
min: tr(x.min),
max: tr(x.max),
minLength: tr(x.minLength),
maxLength: tr(x.maxLength),
pattern: tr(x.pattern)
} : {},
name: y,
onChange: j,
onBlur: j,
ref: (B) => {
if (B) {
ue(y, x), N = W(n, y);
const D = Ee(B.value) && B.querySelectorAll && B.querySelectorAll("input,select,textarea")[0] || B, ie = dl(D), xe = N._f.refs || [];
if (ie ? xe.find((Ce) => Ce === D) : D === N._f.ref)
return;
_e(n, y, {
_f: {
...N._f,
...ie ? {
refs: [
...xe.filter($n),
D,
...Array.isArray(W(a, y)) ? [{}] : []
],
ref: { type: D.type, name: y }
} : { ref: D }
}
}), S(y, !1, void 0, D);
} else
N = W(n, y, {}), N._f && (N._f.mount = !1), (e.shouldUnregister || x.shouldUnregister) && !(Us(s.array, y) && o.action) && s.unMount.add(y);
}
};
}, te = () => e.shouldFocusError && ur(n, R, s.mount), we = (y) => {
Ge(y) && (p.state.next({ disabled: y }), ur(n, (x, N) => {
const Z = W(n, N);
Z && (x.disabled = Z._f.disabled || y, Array.isArray(Z._f.refs) && Z._f.refs.forEach((B) => {
B.disabled = Z._f.disabled || y;
}));
}, 0, !1));
}, V = (y, x) => async (N) => {
let Z;
N && (N.preventDefault && N.preventDefault(), N.persist && N.persist());
let B = Le(i);
if (p.state.next({
isSubmitting: !0
}), e.resolver) {
const { errors: D, values: ie } = await fe();
r.errors = D, B = ie;
} else
await de(n);
if (s.disabled.size)
for (const D of s.disabled)
_e(B, D, void 0);
if (Re(r.errors, "root"), We(r.errors)) {
p.state.next({
errors: {}
});
try {
await y(B, N);
} catch (D) {
Z = D;
}
} else
x && await x({ ...r.errors }, N), te(), setTimeout(te);
if (p.state.next({
isSubmitted: !0,
isSubmitting: !1,
isSubmitSuccessful: We(r.errors) && !Z,
submitCount: r.submitCount + 1,
errors: r.errors
}), Z)
throw Z;
}, Me = (y, x = {}) => {
W(n, y) && (Ee(x.defaultValue) ? P(y, Le(W(a, y))) : (P(y, x.defaultValue), _e(a, y, Le(x.defaultValue))), x.keepTouched || Re(r.touchedFields, y), x.keepDirty || (Re(r.dirtyFields, y), r.isDirty = x.defaultValue ? X(y, Le(W(a, y))) : X()), x.keepError || (Re(r.errors, y), l.isValid && C()), p.state.next({ ...r }));
}, _t = (y, x = {}) => {
const N = y ? Le(y) : a, Z = Le(N), B = We(y), D = B ? a : Z;
if (x.keepDefaultValues || (a = N), !x.keepValues) {
if (x.keepDirtyValues) {
const ie = /* @__PURE__ */ new Set([
...s.mount,
...Object.keys(er(a, i))
]);
for (const xe of Array.from(ie))
W(r.dirtyFields, xe) ? _e(D, xe, W(i, xe)) : P(xe, W(D, xe));
} else {
if (Ia && Ee(y))
for (const ie of s.mount) {
const xe = W(n, ie);
if (xe && xe._f) {
const Ce = Array.isArray(xe._f.refs) ? xe._f.refs[0] : xe._f.ref;
if (Mr(Ce)) {
const Ze = Ce.closest("form");
if (Ze) {
Ze.reset();
break;
}
}
}
}
for (const ie of s.mount)
P(ie, W(D, ie));
}
i = Le(D), p.array.next({
values: { ...D }
}), p.state.next({
values: { ...D }
});
}
s = {
mount: x.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 || !!x.keepIsValid || !!x.keepDirtyValues, o.watch = !!e.shouldUnregister, p.state.next({
submitCount: x.keepSubmitCount ? r.submitCount : 0,
isDirty: B ? !1 : x.keepDirty ? r.isDirty : !!(x.keepDefaultValues && !gt(y, a)),
isSubmitted: x.keepIsSubmitted ? r.isSubmitted : !1,
dirtyFields: B ? {} : x.keepDirtyValues ? x.keepDefaultValues && i ? er(a, i) : r.dirtyFields : x.keepDefaultValues && y ? er(a, y) : x.keepDirty ? r.dirtyFields : {},
touchedFields: x.keepTouched ? r.touchedFields : {},
errors: x.keepErrors ? r.errors : {},
isSubmitSuccessful: x.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
isSubmitting: !1
});
}, Jt = (y, x) => _t(Je(y) ? y(i) : y, x), Qd = (y, x = {}) => {
const N = W(n, y), Z = N && N._f;
if (Z) {
const B = Z.refs ? Z.refs[0] : Z.ref;
B.focus && (B.focus(), x.shouldSelect && Je(B.select) && B.select());
}
}, Xd = (y) => {
r = {
...r,
...y
};
}, si = {
control: {
register: ue,
unregister: q,
getFieldState: T,
handleSubmit: V,
setError: k,
_subscribe: re,
_runSchema: fe,
_focusError: te,
_getWatch: J,
_getDirty: X,
_setValid: C,
_setFieldArray: v,
_setDisabledField: ae,
_setErrors: I,
_getFieldArray: he,
_reset: _t,
_resetDefaultValues: () => Je(e.defaultValues) && e.defaultValues().then((y) => {
Jt(y, e.resetOptions), p.state.next({
isLoading: !1
});
}),
_removeUnmounted: se,
_disableForm: we,
_subjects: p,
_proxyFormState: l,
get _fields() {
return n;
},
get _formValues() {
return i;
},
get _state() {
return o;
},
set _state(y) {
o = y;
},
get _defaultValues() {
return a;
},
get _names() {
return s;
},
set _names(y) {
s = y;
},
get _formState() {
return r;
},
get _options() {
return e;
},
set _options(y) {
e = {
...e,
...y
};
}
},
subscribe: oe,
trigger: ee,
register: ue,
handleSubmit: V,
watch: U,
setValue: P,
getValues: _,
reset: Jt,
resetField: Me,
clearErrors: K,
unregister: q,
setError: k,
setFocus: Qd,
getFieldState: T
};
return {
...si,
formControl: si
};
}
function wl(t = {}) {
const e = M.useRef(void 0), r = M.useRef(void 0), [n, a] = M.useState({
isDirty: !1,
isValidating: !1,
isLoading: Je(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: Je(t.defaultValues) ? void 0 : t.defaultValues
});
if (!e.current)
if (t.formControl)
e.current = {
...t.formControl,
formState: n
}, t.defaultValues && !Je(t.defaultValues) && t.formControl.reset(t.defaultValues, t.resetOptions);
else {
const { formControl: o, ...s } = xl(t);
e.current = {
...s,
formState: n
};
}
const i = e.current.control;
return i._options = t, Ra(() => {
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]), M.useEffect(() => i._disableForm(t.disabled), [i, t.disabled]), M.useEffect(() => {
t.mode && (i._options.mode = t.mode), t.reValidateMode && (i._options.reValidateMode = t.reValidateMode);
}, [i, t.mode, t.reValidateMode]), M.useEffect(() => {
t.errors && (i._setErrors(t.errors), i._focusError());
}, [i, t.errors]), M.useEffect(() => {
t.shouldUnregister && i._subjects.state.next({
values: i._getWatch()
});
}, [i, t.shouldUnregister]), M.useEffect(() => {
if (i._proxyFormState.isDirty) {
const o = i._getDirty();
o !== n.isDirty && i._subjects.state.next({
isDirty: o
});
}
}, [i, n.isDirty]), M.useEffect(() => {
t.values && !gt(t.values, r.current) ? (i._reset(t.values, i._options.resetOptions), r.current = t.values, a((o) => ({ ...o }))) : i._resetDefaultValues();
}, [i, t.values]), M.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 = qs(n, i), e.current;
}
function Qs(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 = Qs(t[e])) && (n && (n += " "), n += r);
} else for (r in t) t[r] && (n && (n += " "), n += r);
return n;
}
function O() {
for (var t, e, r = 0, n = "", a = arguments.length; r < a; r++) (t = arguments[r]) && (e = Qs(t)) && (n && (n += " "), n += e);
return n;
}
const Xs = ka(null);
function _l() {
const t = Ta(Xs);
if (!t)
throw new Error("FormField components must be used within a <Form> component.");
return t;
}
var ne = /* @__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))(ne || {});
const Js = ka({
labelDisplay: "default"
// 'default' is the sensible default
});
function Cl() {
const t = Ta(Js);
if (!t)
throw new Error("useFormConfig must be used within a <Form> component.");
return t;
}
var ve;
(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;
})(ve || (ve = {}));
var _i;
(function(t) {
t.mergeShapes = (e, r) => ({
...e,
...r
// second overwrites first
});
})(_i || (_i = {}));
const Y = ve.arrayToEnum([
"string",
"nan",
"number",
"integer",
"float",
"boolean",
"date",
"bigint",
"symbol",
"function",
"undefined",
"null",
"array",
"object",
"unknown",
"promise",
"void",
"never",
"map",
"set"
]), mt = (t) => {
switch (typeof t) {
case "undefined":
return Y.undefined;
case "string":
return Y.string;
case "number":
return Number.isNaN(t) ? Y.nan : Y.number;
case "boolean":
return Y.boolean;
case "function":
return Y.function;
case "bigint":
return Y.bigint;
case "symbol":
return Y.symbol;
case "object":
return Array.isArray(t) ? Y.array : t === null ? Y.null : t.then && typeof t.then == "function" && t.catch && typeof t.catch == "function" ? Y.promise : typeof Map < "u" && t instanceof Map ? Y.map : typeof Set < "u" && t instanceof Set ? Y.set : typeof Date < "u" && t instanceof Date ? Y.date : Y.object;
default:
return Y.unknown;
}
}, F = ve.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 lt 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, u = 0;
for (; u < o.path.length; ) {
const d = o.path[u];
u === o.path.length - 1 ? (s[d] = s[d] || { _errors: [] }, s[d]._errors.push(r(o))) : s[d] = s[d] || { _errors: [] }, s = s[d], u++;
}
}
};
return a(this), n;
}
static assert(e) {
if (!(e instanceof lt))
throw new Error(`Not a ZodError: ${e}`);
}
toString() {
return this.message;
}
get message() {
return JSON.stringify(this.issues, ve.jsonStringifyReplacer, 2);
}
get isEmpty() {
return this.issues.length === 0;
}
flatten(e = (r) => r.message) {
const r = {}, n = [];
for (const a of this.issues)
a.path.length > 0 ? (r[a.path[0]] = r[a.path[0]] || [], r[a.path[0]].push(e(a))) : n.push(e(a));
return { formErrors: n, fieldErrors: r };
}
get formErrors() {
return this.flatten();
}
}
lt.create = (t) => new lt(t);
const qn = (t, e) => {
let r;
switch (t.code) {
case F.invalid_type:
t.received === Y.undefined ? r = "Required" : r = `Expected ${t.expected}, received ${t.received}`;
break;
case F.invalid_literal:
r = `Invalid literal value, expected ${JSON.stringify(t.expected, ve.jsonStringifyReplacer)}`;
break;
case F.unrecognized_keys:
r = `Unrecognized key(s) in object: ${ve.joinValues(t.keys, ", ")}`;
break;
case F.invalid_union:
r = "Invalid input";
break;
case F.invalid_union_discriminator:
r = `Invalid discriminator value. Expected ${ve.joinValues(t.options)}`;
break;
case F.invalid_enum_value:
r = `Invalid enum value. Expected ${ve.joinValues(t.options)}, received '${t.received}'`;
break;
case F.invalid_arguments:
r = "Invalid function arguments";
break;
case F.invalid_return_type:
r = "Invalid function return type";
break;
case F.invalid_date:
r = "Invalid date";
break;
case F.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}"` : ve.assertNever(t.validation) : t.validation !== "regex" ? r = `Invalid ${t.validation}` : r = "Invalid";
break;
case F.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 === "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 F.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 F.custom:
r = "Invalid input";
break;
case F.invalid_intersection_types:
r = "Intersection results could not be merged";
break;
case F.not_multiple_of:
r = `Number must be a multiple of ${t.multipleOf}`;
break;
case F.not_finite:
r = "Number must be finite";
break;
default:
r = e.defaultError, ve.assertNever(t);
}
return { message: r };
};
let Ol = qn;
function Sl() {
return Ol;
}
const Nl = (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 u = n.filter((d) => !!d).slice().reverse();
for (const d of u)
s = d(o, { data: e, defaultError: s }).message;
return {
...a,
path: i,
message: s
};
};
function H(t, e) {
const r = Sl(), n = Nl({
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 === qn ? void 0 : qn
// then global default map
].filter((a) => !!a)
});
t.common.issues.push(n);
}
class He {
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 le;
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
});
}
return He.mergeObjectSync(e, n);
}
static mergeObjectSync(e, r) {
const n = {};
for (const a of r) {
const { key: i, value: o } = a;
if (i.status === "aborted" || o.status === "aborted")
return le;
i.status === "dirty" && e.dirty(), o.status === "dirty" && e.dirty(), i.value !== "__proto__" && (typeof o.value < "u" || a.alwaysSet) && (n[i.value] = o.value);
}
return { status: e.value, value: n };
}
}
const le = Object.freeze({
status: "aborted"
}), ir = (t) => ({ status: "dirty", value: t }), Ke = (t) => ({ status: "valid", value: t }), Ci = (t) => t.status === "aborted", Oi = (t) => t.status === "dirty", Bt = (t) => t.status === "valid", Vr = (t) => typeof Promise < "u" && t instanceof Promise;
var Q;
(function(t) {
t.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, t.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message;
})(Q || (Q = {}));
class bt {
constructor(e, r, n, a) {
this._cachedPath = [], this.parent = e, this.data = r, this._path = n, this._key = a;
}
get path() {
return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
}
}
const Si = (t, e) => {
if (Bt(e))
return { success: !0, data: e.value };
if (!t.common