UNPKG

@nestledjs/forms

Version:

A flexible React form library supporting both declarative and imperative usage patterns with TypeScript support

1,480 lines 656 kB
import { jsxs as W, Fragment as _e, jsx as p } from "react/jsx-runtime"; import F, { createContext as Va, useContext as Ua, useMemo as dt, lazy as gd, useEffect as rt, useCallback as He, Suspense as Ci, useRef as sr, useState as et } from "react"; function vd(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 Er = (t) => t.type === "checkbox", Ot = (t) => t instanceof Date, Be = (t) => t == null; const Js = (t) => typeof t == "object"; var Fe = (t) => !Be(t) && !Array.isArray(t) && Js(t) && !Ot(t), eu = (t) => Fe(t) && t.target ? Er(t.target) ? t.target.checked : t.target.value : t, bd = (t) => t.substring(0, t.search(/\.\d+(\.|$)/)) || t, tu = (t, e) => t.has(bd(e)), $d = (t) => { const e = t.constructor && t.constructor.prototype; return Fe(e) && e.hasOwnProperty("isPrototypeOf"); }, Ba = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u"; function Me(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 (!(Ba && (t instanceof Blob || n)) && (r || Fe(t))) if (e = r ? [] : Object.create(Object.getPrototypeOf(t)), !r && !$d(t)) e = t; else for (const a in t) t.hasOwnProperty(a) && (e[a] = Me(t[a])); else return t; return e; } var mn = (t) => /^\w*$/.test(t), Ae = (t) => t === void 0, qa = (t) => Array.isArray(t) ? t.filter(Boolean) : [], Wa = (t) => qa(t.replace(/["|']|\]/g, "").split(/\.|\[/)), B = (t, e, r) => { if (!e || !Fe(t)) return r; const n = (mn(e) ? [e] : Wa(e)).reduce((a, i) => Be(a) ? a : a[i], t); return Ae(n) || n === t ? Ae(t[e]) ? r : t[e] : n; }, Ge = (t) => typeof t == "boolean", Ce = (t, e, r) => { let n = -1; const a = mn(e) ? [e] : Wa(e), i = a.length, o = i - 1; for (; ++n < i; ) { const s = a[n]; let u = r; if (n !== o) { const l = t[s]; u = Fe(l) || Array.isArray(l) ? l : isNaN(+a[n + 1]) ? {} : []; } if (s === "__proto__" || s === "constructor" || s === "prototype") return; t[s] = u, t = t[s]; } }; const zr = { BLUR: "blur", FOCUS_OUT: "focusout", CHANGE: "change" }, Xe = { onBlur: "onBlur", onChange: "onChange", onSubmit: "onSubmit", onTouched: "onTouched", all: "all" }, ot = { max: "max", min: "min", maxLength: "maxLength", minLength: "minLength", pattern: "pattern", required: "required", validate: "validate" }, ru = F.createContext(null); ru.displayName = "HookFormContext"; const Ga = () => F.useContext(ru); var nu = (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 Ha = typeof window < "u" ? F.useLayoutEffect : F.useEffect; function xd(t) { const e = Ga(), { control: r = e.control, disabled: n, name: a, exact: i } = t || {}, [o, s] = F.useState(r._formState), u = F.useRef({ isDirty: !1, isLoading: !1, dirtyFields: !1, touchedFields: !1, validatingFields: !1, isValidating: !1, isValid: !1, errors: !1 }); return Ha(() => r._subscribe({ name: a, formState: u.current, exact: i, callback: (l) => { !n && s({ ...r._formState, ...l }); } }), [a, n, i]), F.useEffect(() => { u.current.isValid && r._setValid(!0); }, [r]), F.useMemo(() => nu(o, r, u.current, !1), [o, r]); } var at = (t) => typeof t == "string", au = (t, e, r, n, a) => at(t) ? (n && e.watch.add(t), B(r, t, a)) : Array.isArray(t) ? t.map((i) => (n && e.watch.add(i), B(r, i))) : (n && (e.watchAll = !0), r), ea = (t) => Be(t) || !Js(t); function lt(t, e, r = /* @__PURE__ */ new WeakSet()) { if (ea(t) || ea(e)) return t === e; if (Ot(t) && Ot(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 (Ot(o) && Ot(s) || Fe(o) && Fe(s) || Array.isArray(o) && Array.isArray(s) ? !lt(o, s, r) : o !== s) return !1; } } return !0; } function Za(t) { const e = Ga(), { control: r = e.control, name: n, defaultValue: a, disabled: i, exact: o, compute: s } = t || {}, u = F.useRef(a), l = F.useRef(s), d = F.useRef(void 0); l.current = s; const f = F.useMemo(() => r._getWatch(n, u.current), [r, n]), [h, m] = F.useState(l.current ? l.current(f) : f); return Ha(() => r._subscribe({ name: n, formState: { values: !0 }, exact: o, callback: (x) => { if (!i) { const S = au(n, r._names, x.values || r._formValues, !1, u.current); if (l.current) { const v = l.current(S); lt(v, d.current) || (m(v), d.current = v); } else m(S); } } }), [r, i, n, o]), F.useEffect(() => r._removeUnmounted()), h; } function wd(t) { const e = Ga(), { name: r, disabled: n, control: a = e.control, shouldUnregister: i, defaultValue: o } = t, s = tu(a._names.array, r), u = F.useMemo(() => B(a._formValues, r, B(a._defaultValues, r, o)), [a, r, o]), l = Za({ control: a, name: r, defaultValue: u, exact: !0 }), d = xd({ control: a, name: r, exact: !0 }), f = F.useRef(t), h = F.useRef(a.register(r, { ...t.rules, value: l, ...Ge(t.disabled) ? { disabled: t.disabled } : {} })); f.current = t; const m = F.useMemo(() => Object.defineProperties({}, { invalid: { enumerable: !0, get: () => !!B(d.errors, r) }, isDirty: { enumerable: !0, get: () => !!B(d.dirtyFields, r) }, isTouched: { enumerable: !0, get: () => !!B(d.touchedFields, r) }, isValidating: { enumerable: !0, get: () => !!B(d.validatingFields, r) }, error: { enumerable: !0, get: () => B(d.errors, r) } }), [d, r]), x = F.useCallback((g) => h.current.onChange({ target: { value: eu(g), name: r }, type: zr.CHANGE }), [r]), S = F.useCallback(() => h.current.onBlur({ target: { value: B(a._formValues, r), name: r }, type: zr.BLUR }), [r, a._formValues]), v = F.useCallback((g) => { const N = B(a._fields, r); N && g && (N._f.ref = { focus: () => g.focus && g.focus(), select: () => g.select && g.select(), setCustomValidity: (C) => g.setCustomValidity(C), reportValidity: () => g.reportValidity() }); }, [a._fields, r]), b = F.useMemo(() => ({ name: r, value: l, ...Ge(n) || d.disabled ? { disabled: d.disabled || n } : {}, onChange: x, onBlur: S, ref: v }), [r, n, d.disabled, x, S, v, l]); return F.useEffect(() => { const g = a._options.shouldUnregister || i; a.register(r, { ...f.current.rules, ...Ge(f.current.disabled) ? { disabled: f.current.disabled } : {} }); const N = (C, $) => { const q = B(a._fields, C); q && q._f && (q._f.mount = $); }; if (N(r, !0), g) { const C = Me(B(a._options.defaultValues, r)); Ce(a._defaultValues, r, C), Ae(B(a._formValues, r)) && Ce(a._formValues, r, C); } return !s && a.register(r), () => { (s ? g && !a._state.action : g) ? a.unregister(r) : N(r, !1); }; }, [r, a, s, i]), F.useEffect(() => { a._setDisabledField({ disabled: n, name: r }); }, [n, r, a]), F.useMemo(() => ({ field: b, formState: d, fieldState: m }), [b, d, m]); } const pt = (t) => t.render(wd(t)); var iu = (t, e, r, n, a) => e ? { ...r[t], types: { ...r[t] && r[t].types ? r[t].types : {}, [n]: a || !0 } } : {}, ur = (t) => Array.isArray(t) ? t : [t], _i = () => { 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 = []; } }; }, We = (t) => Fe(t) && !Object.keys(t).length, za = (t) => t.type === "file", Je = (t) => typeof t == "function", Kr = (t) => { if (!Ba) return !1; const e = t ? t.ownerDocument : 0; return t instanceof (e && e.defaultView ? e.defaultView.HTMLElement : HTMLElement); }, ou = (t) => t.type === "select-multiple", Ka = (t) => t.type === "radio", Cd = (t) => Ka(t) || Er(t), En = (t) => Kr(t) && t.isConnected; function _d(t, e) { const r = e.slice(0, -1).length; let n = 0; for (; n < r; ) t = Ae(t) ? n++ : t[e[n++]]; return t; } function Sd(t) { for (const e in t) if (t.hasOwnProperty(e) && !Ae(t[e])) return !1; return !0; } function Re(t, e) { const r = Array.isArray(e) ? e : mn(e) ? [e] : Wa(e), n = r.length === 1 ? t : _d(t, r), a = r.length - 1, i = r[a]; return n && delete n[i], a !== 0 && (Fe(n) && We(n) || Array.isArray(n) && Sd(n)) && Re(t, r.slice(0, -1)), t; } var su = (t) => { for (const e in t) if (Je(t[e])) return !0; return !1; }; function Yr(t, e = {}) { const r = Array.isArray(t); if (Fe(t) || r) for (const n in t) Array.isArray(t[n]) || Fe(t[n]) && !su(t[n]) ? (e[n] = Array.isArray(t[n]) ? [] : {}, Yr(t[n], e[n])) : Be(t[n]) || (e[n] = !0); return e; } function uu(t, e, r) { const n = Array.isArray(t); if (Fe(t) || n) for (const a in t) Array.isArray(t[a]) || Fe(t[a]) && !su(t[a]) ? Ae(e) || ea(r[a]) ? r[a] = Array.isArray(t[a]) ? Yr(t[a], []) : { ...Yr(t[a]) } : uu(t[a], Be(e) ? {} : e[a], r[a]) : r[a] = !lt(t[a], e[a]); return r; } var tr = (t, e) => uu(t, e, Yr(e)); const Si = { value: !1, isValid: !1 }, Oi = { value: !0, isValid: !0 }; var lu = (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 && !Ae(t[0].attributes.value) ? Ae(t[0].value) || t[0].value === "" ? Oi : { value: t[0].value, isValid: !0 } : Oi ) : Si; } return Si; }, du = (t, { valueAsNumber: e, valueAsDate: r, setValueAs: n }) => Ae(t) ? t : e ? t === "" ? NaN : t && +t : r && at(t) ? new Date(t) : n ? n(t) : t; const Pi = { isValid: !1, value: null }; var cu = (t) => Array.isArray(t) ? t.reduce((e, r) => r && r.checked && !r.disabled ? { isValid: !0, value: r.value } : e, Pi) : Pi; function Ni(t) { const e = t.ref; return za(e) ? e.files : Ka(e) ? cu(t.refs).value : ou(e) ? [...e.selectedOptions].map(({ value: r }) => r) : Er(e) ? lu(t.refs).value : du(Ae(e.value) ? t.ref.value : e.value, t); } var Od = (t, e, r, n) => { const a = {}; for (const i of t) { const o = B(e, i); o && Ce(a, i, o._f); } return { criteriaMode: r, names: [...t], fields: a, shouldUseNativeValidation: n }; }, Qr = (t) => t instanceof RegExp, rr = (t) => Ae(t) ? t : Qr(t) ? t.source : Fe(t) ? Qr(t.value) ? t.value.source : t.value : t, ki = (t) => ({ isOnSubmit: !t || t === Xe.onSubmit, isOnBlur: t === Xe.onBlur, isOnChange: t === Xe.onChange, isOnAll: t === Xe.all, isOnTouch: t === Xe.onTouched }); const Ti = "AsyncFunction"; var Pd = (t) => !!t && !!t.validate && !!(Je(t.validate) && t.validate.constructor.name === Ti || Fe(t.validate) && Object.values(t.validate).find((e) => e.constructor.name === Ti)), Nd = (t) => t.mount && (t.required || t.min || t.max || t.maxLength || t.minLength || t.pattern || t.validate), Ei = (t, e, r) => !r && (e.watchAll || e.watch.has(t) || [...e.watch].some((n) => t.startsWith(n) && /^\.\w+/.test(t.slice(n.length)))); const lr = (t, e, r, n) => { for (const a of r || Object.keys(t)) { const i = B(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 (lr(s, e)) break; } else if (Fe(s) && lr(s, e)) break; } } }; function Ii(t, e, r) { const n = B(t, r); if (n || mn(r)) return { error: n, name: r }; const a = r.split("."); for (; a.length; ) { const i = a.join("."), o = B(e, i), s = B(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 kd = (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)); }, Td = (t, e, r) => !t || !e || t === e || ur(t).some((n) => n && (r ? n === e : n.startsWith(e) || e.startsWith(n))), Ed = (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, Id = (t, e) => !qa(B(t, e)).length && Re(t, e), Ad = (t, e, r) => { const n = ur(B(t, r)); return Ce(n, "root", e[r]), Ce(t, r, n), t; }, Br = (t) => at(t); function Ai(t, e, r = "validate") { if (Br(t) || Array.isArray(t) && t.every(Br) || Ge(t) && !t) return { type: r, message: Br(t) ? t : "", ref: e }; } var It = (t) => Fe(t) && !Qr(t) ? t : { value: t, message: "" }, Fi = async (t, e, r, n, a, i) => { const { ref: o, refs: s, required: u, maxLength: l, minLength: d, min: f, max: h, pattern: m, validate: x, name: S, valueAsNumber: v, mount: b } = t._f, g = B(r, S); if (!b || e.has(S)) return {}; const N = s ? s[0] : o, C = (re) => { a && N.reportValidity && (N.setCustomValidity(Ge(re) ? "" : re || ""), N.reportValidity()); }, $ = {}, q = Ka(o), de = Er(o), he = q || de, le = (v || za(o)) && Ae(o.value) && Ae(g) || Kr(o) && o.value === "" || g === "" || Array.isArray(g) && !g.length, ue = iu.bind(null, S, n, $), ee = (re, pe, L, A = ot.maxLength, T = ot.minLength) => { const j = re ? pe : L; $[S] = { type: re ? A : T, message: j, ref: o, ...ue(re ? A : T, j) }; }; if (i ? !Array.isArray(g) || !g.length : u && (!he && (le || Be(g)) || Ge(g) && !g || de && !lu(s).isValid || q && !cu(s).isValid)) { const { value: re, message: pe } = Br(u) ? { value: !!u, message: u } : It(u); if (re && ($[S] = { type: ot.required, message: pe, ref: N, ...ue(ot.required, pe) }, !n)) return C(pe), $; } if (!le && (!Be(f) || !Be(h))) { let re, pe; const L = It(h), A = It(f); if (!Be(g) && !isNaN(g)) { const T = o.valueAsNumber || g && +g; Be(L.value) || (re = T > L.value), Be(A.value) || (pe = T < A.value); } else { const T = o.valueAsDate || new Date(g), j = (_) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + _), D = o.type == "time", ne = o.type == "week"; at(L.value) && g && (re = D ? j(g) > j(L.value) : ne ? g > L.value : T > new Date(L.value)), at(A.value) && g && (pe = D ? j(g) < j(A.value) : ne ? g < A.value : T < new Date(A.value)); } if ((re || pe) && (ee(!!re, L.message, A.message, ot.max, ot.min), !n)) return C($[S].message), $; } if ((l || d) && !le && (at(g) || i && Array.isArray(g))) { const re = It(l), pe = It(d), L = !Be(re.value) && g.length > +re.value, A = !Be(pe.value) && g.length < +pe.value; if ((L || A) && (ee(L, re.message, pe.message), !n)) return C($[S].message), $; } if (m && !le && at(g)) { const { value: re, message: pe } = It(m); if (Qr(re) && !g.match(re) && ($[S] = { type: ot.pattern, message: pe, ref: o, ...ue(ot.pattern, pe) }, !n)) return C(pe), $; } if (x) { if (Je(x)) { const re = await x(g, r), pe = Ai(re, N); if (pe && ($[S] = { ...pe, ...ue(ot.validate, pe.message) }, !n)) return C(pe.message), $; } else if (Fe(x)) { let re = {}; for (const pe in x) { if (!We(re) && !n) break; const L = Ai(await x[pe](g, r), N, pe); L && (re = { ...L, ...ue(pe, L.message) }, C(L.message), n && ($[S] = re)); } if (!We(re) && ($[S] = { ref: N, ...re }, !n)) return $; } } return C(!0), $; }; const Fd = { mode: Xe.onSubmit, reValidateMode: Xe.onChange, shouldFocusError: !0 }; function Rd(t = {}) { let e = { ...Fd, ...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 }, n = {}, a = Fe(e.defaultValues) || Fe(e.values) ? Me(e.defaultValues || e.values) || {} : {}, i = e.shouldUnregister ? {} : Me(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, l = 0; const d = { isDirty: !1, dirtyFields: !1, validatingFields: !1, touchedFields: !1, isValidating: !1, isValid: !1, errors: !1 }; let f = { ...d }; const h = { array: _i(), state: _i() }, m = e.criteriaMode === Xe.all, x = (y) => (w) => { clearTimeout(l), l = setTimeout(y, w); }, S = async (y) => { if (!e.disabled && (d.isValid || f.isValid || y)) { const w = e.resolver ? We((await de()).errors) : await le(n, !0); w !== r.isValid && h.state.next({ isValid: w }); } }, v = (y, w) => { !e.disabled && (d.isValidating || d.validatingFields || f.isValidating || f.validatingFields) && ((y || Array.from(s.mount)).forEach((P) => { P && (w ? Ce(r.validatingFields, P, w) : Re(r.validatingFields, P)); }), h.state.next({ validatingFields: r.validatingFields, isValidating: !We(r.validatingFields) })); }, b = (y, w = [], P, Z, U = !0, M = !0) => { if (Z && P && !e.disabled) { if (o.action = !0, M && Array.isArray(B(n, y))) { const oe = P(B(n, y), Z.argA, Z.argB); U && Ce(n, y, oe); } if (M && Array.isArray(B(r.errors, y))) { const oe = P(B(r.errors, y), Z.argA, Z.argB); U && Ce(r.errors, y, oe), Id(r.errors, y); } if ((d.touchedFields || f.touchedFields) && M && Array.isArray(B(r.touchedFields, y))) { const oe = P(B(r.touchedFields, y), Z.argA, Z.argB); U && Ce(r.touchedFields, y, oe); } (d.dirtyFields || f.dirtyFields) && (r.dirtyFields = tr(a, i)), h.state.next({ name: y, isDirty: ee(y, w), dirtyFields: r.dirtyFields, errors: r.errors, isValid: r.isValid }); } else Ce(i, y, w); }, g = (y, w) => { Ce(r.errors, y, w), h.state.next({ errors: r.errors }); }, N = (y) => { r.errors = y, h.state.next({ errors: r.errors, isValid: !1 }); }, C = (y, w, P, Z) => { const U = B(n, y); if (U) { const M = B(i, y, Ae(P) ? B(a, y) : P); Ae(M) || Z && Z.defaultChecked || w ? Ce(i, y, w ? M : Ni(U._f)) : L(y, M), o.mount && S(); } }, $ = (y, w, P, Z, U) => { let M = !1, oe = !1; const we = { name: y }; if (!e.disabled) { if (!P || Z) { (d.isDirty || f.isDirty) && (oe = r.isDirty, r.isDirty = we.isDirty = ee(), M = oe !== we.isDirty); const Se = lt(B(a, y), w); oe = !!B(r.dirtyFields, y), Se ? Re(r.dirtyFields, y) : Ce(r.dirtyFields, y, !0), we.dirtyFields = r.dirtyFields, M = M || (d.dirtyFields || f.dirtyFields) && oe !== !Se; } if (P) { const Se = B(r.touchedFields, y); Se || (Ce(r.touchedFields, y, P), we.touchedFields = r.touchedFields, M = M || (d.touchedFields || f.touchedFields) && Se !== P); } M && U && h.state.next(we); } return M ? we : {}; }, q = (y, w, P, Z) => { const U = B(r.errors, y), M = (d.isValid || f.isValid) && Ge(w) && r.isValid !== w; if (e.delayError && P ? (u = x(() => g(y, P)), u(e.delayError)) : (clearTimeout(l), u = null, P ? Ce(r.errors, y, P) : Re(r.errors, y)), (P ? !lt(U, P) : U) || !We(Z) || M) { const oe = { ...Z, ...M && Ge(w) ? { isValid: w } : {}, errors: r.errors, name: y }; r = { ...r, ...oe }, h.state.next(oe); } }, de = async (y) => { v(y, !0); const w = await e.resolver(i, e.context, Od(y || s.mount, n, e.criteriaMode, e.shouldUseNativeValidation)); return v(y), w; }, he = async (y) => { const { errors: w } = await de(y); if (y) for (const P of y) { const Z = B(w, P); Z ? Ce(r.errors, P, Z) : Re(r.errors, P); } else r.errors = w; return w; }, le = async (y, w, P = { valid: !0 }) => { for (const Z in y) { const U = y[Z]; if (U) { const { _f: M, ...oe } = U; if (M) { const we = s.array.has(M.name), Se = U._f && Pd(U._f); Se && d.validatingFields && v([Z], !0); const ze = await Fi(U, s.disabled, i, m, e.shouldUseNativeValidation && !w, we); if (Se && d.validatingFields && v([Z]), ze[M.name] && (P.valid = !1, w)) break; !w && (B(ze, M.name) ? we ? Ad(r.errors, ze, M.name) : Ce(r.errors, M.name, ze[M.name]) : Re(r.errors, M.name)); } !We(oe) && await le(oe, w, P); } } return P.valid; }, ue = () => { for (const y of s.unMount) { const w = B(n, y); w && (w._f.refs ? w._f.refs.every((P) => !En(P)) : !En(w._f.ref)) && ie(y); } s.unMount = /* @__PURE__ */ new Set(); }, ee = (y, w) => !e.disabled && (y && w && Ce(i, y, w), !lt(_(), a)), re = (y, w, P) => au(y, s, { ...o.mount ? i : Ae(w) ? a : at(y) ? { [y]: w } : w }, P, w), pe = (y) => qa(B(o.mount ? i : a, y, e.shouldUnregister ? B(a, y, []) : [])), L = (y, w, P = {}) => { const Z = B(n, y); let U = w; if (Z) { const M = Z._f; M && (!M.disabled && Ce(i, y, du(w, M)), U = Kr(M.ref) && Be(w) ? "" : w, ou(M.ref) ? [...M.ref.options].forEach((oe) => oe.selected = U.includes(oe.value)) : M.refs ? Er(M.ref) ? M.refs.forEach((oe) => { (!oe.defaultChecked || !oe.disabled) && (Array.isArray(U) ? oe.checked = !!U.find((we) => we === oe.value) : oe.checked = U === oe.value || !!U); }) : M.refs.forEach((oe) => oe.checked = oe.value === U) : za(M.ref) ? M.ref.value = "" : (M.ref.value = U, M.ref.type || h.state.next({ name: y, values: Me(i) }))); } (P.shouldDirty || P.shouldTouch) && $(y, U, P.shouldTouch, P.shouldDirty, !0), P.shouldValidate && ne(y); }, A = (y, w, P) => { for (const Z in w) { if (!w.hasOwnProperty(Z)) return; const U = w[Z], M = y + "." + Z, oe = B(n, M); (s.array.has(y) || Fe(U) || oe && !oe._f) && !Ot(U) ? A(M, U, P) : L(M, U, P); } }, T = (y, w, P = {}) => { const Z = B(n, y), U = s.array.has(y), M = Me(w); Ce(i, y, M), U ? (h.array.next({ name: y, values: Me(i) }), (d.isDirty || d.dirtyFields || f.isDirty || f.dirtyFields) && P.shouldDirty && h.state.next({ name: y, dirtyFields: tr(a, i), isDirty: ee(y, M) })) : Z && !Z._f && !Be(M) ? A(y, M, P) : L(y, M, P), Ei(y, s) && h.state.next({ ...r, name: y }), h.state.next({ name: o.mount ? y : void 0, values: Me(i) }); }, j = async (y) => { o.mount = !0; const w = y.target; let P = w.name, Z = !0; const U = B(n, P), M = (Se) => { Z = Number.isNaN(Se) || Ot(Se) && isNaN(Se.getTime()) || lt(Se, B(i, P, Se)); }, oe = ki(e.mode), we = ki(e.reValidateMode); if (U) { let Se, ze; const Fr = w.type ? Ni(U._f) : eu(y), mt = y.type === zr.BLUR || y.type === zr.FOCUS_OUT, pd = !Nd(U._f) && !e.resolver && !B(r.errors, P) && !U._f.deps || Ed(mt, B(r.touchedFields, P), r.isSubmitted, we, oe), kn = Ei(P, s, mt); Ce(i, P, Fr), mt ? (!w || !w.readOnly) && (U._f.onBlur && U._f.onBlur(y), u && u(0)) : U._f.onChange && U._f.onChange(y); const Tn = $(P, Fr, mt), yd = !We(Tn) || kn; if (!mt && h.state.next({ name: P, type: y.type, values: Me(i) }), pd) return (d.isValid || f.isValid) && (e.mode === "onBlur" ? mt && S() : mt || S()), yd && h.state.next({ name: P, ...kn ? {} : Tn }); if (!mt && kn && h.state.next({ ...r }), e.resolver) { const { errors: xi } = await de([P]); if (M(Fr), Z) { const md = Ii(r.errors, n, P), wi = Ii(xi, n, md.name || P); Se = wi.error, P = wi.name, ze = We(xi); } } else v([P], !0), Se = (await Fi(U, s.disabled, i, m, e.shouldUseNativeValidation))[P], v([P]), M(Fr), Z && (Se ? ze = !1 : (d.isValid || f.isValid) && (ze = await le(n, !0))); Z && (U._f.deps && ne(U._f.deps), q(P, ze, Se, Tn)); } }, D = (y, w) => { if (B(r.errors, w) && y.focus) return y.focus(), 1; }, ne = async (y, w = {}) => { let P, Z; const U = ur(y); if (e.resolver) { const M = await he(Ae(y) ? y : U); P = We(M), Z = y ? !U.some((oe) => B(M, oe)) : P; } else y ? (Z = (await Promise.all(U.map(async (M) => { const oe = B(n, M); return await le(oe && oe._f ? { [M]: oe } : oe); }))).every(Boolean), !(!Z && !r.isValid) && S()) : Z = P = await le(n); return h.state.next({ ...!at(y) || (d.isValid || f.isValid) && P !== r.isValid ? {} : { name: y }, ...e.resolver || !y ? { isValid: P } : {}, errors: r.errors }), w.shouldFocus && !Z && lr(n, D, y ? U : s.mount), Z; }, _ = (y) => { const w = { ...o.mount ? i : a }; return Ae(y) ? w : at(y) ? B(w, y) : y.map((P) => B(w, P)); }, E = (y, w) => ({ invalid: !!B((w || r).errors, y), isDirty: !!B((w || r).dirtyFields, y), error: B((w || r).errors, y), isValidating: !!B(r.validatingFields, y), isTouched: !!B((w || r).touchedFields, y) }), K = (y) => { y && ur(y).forEach((w) => Re(r.errors, w)), h.state.next({ errors: y ? r.errors : {} }); }, Y = (y, w, P) => { const Z = (B(n, y, { _f: {} })._f || {}).ref, U = B(r.errors, y) || {}, { ref: M, message: oe, type: we, ...Se } = U; Ce(r.errors, y, { ...Se, ...w, ref: Z }), h.state.next({ name: y, errors: r.errors, isValid: !1 }), P && P.shouldFocus && Z && Z.focus && Z.focus(); }, k = (y, w) => Je(y) ? h.state.subscribe({ next: (P) => "values" in P && y(re(void 0, w), P) }) : re(y, w, !0), z = (y) => h.state.subscribe({ next: (w) => { Td(y.name, w.name, y.exact) && kd(w, y.formState || d, hd, y.reRenderRoot) && y.callback({ values: { ...i }, ...r, ...w, defaultValues: a }); } }).unsubscribe, se = (y) => (o.mount = !0, f = { ...f, ...y.formState }, z({ ...y, formState: f })), ie = (y, w = {}) => { for (const P of y ? ur(y) : s.mount) s.mount.delete(P), s.array.delete(P), w.keepValue || (Re(n, P), Re(i, P)), !w.keepError && Re(r.errors, P), !w.keepDirty && Re(r.dirtyFields, P), !w.keepTouched && Re(r.touchedFields, P), !w.keepIsValidating && Re(r.validatingFields, P), !e.shouldUnregister && !w.keepDefaultValue && Re(a, P); h.state.next({ values: Me(i) }), h.state.next({ ...r, ...w.keepDirty ? { isDirty: ee() } : {} }), !w.keepIsValid && S(); }, G = ({ disabled: y, name: w }) => { (Ge(y) && o.mount || y || s.disabled.has(w)) && (y ? s.disabled.add(w) : s.disabled.delete(w)); }, ae = (y, w = {}) => { let P = B(n, y); const Z = Ge(w.disabled) || Ge(e.disabled); return Ce(n, y, { ...P || {}, _f: { ...P && P._f ? P._f : { ref: { name: y } }, name: y, mount: !0, ...w } }), s.mount.add(y), P ? G({ disabled: Ge(w.disabled) ? w.disabled : e.disabled, name: y }) : C(y, !0, w.value), { ...Z ? { disabled: w.disabled || e.disabled } : {}, ...e.progressive ? { required: !!w.required, min: rr(w.min), max: rr(w.max), minLength: rr(w.minLength), maxLength: rr(w.maxLength), pattern: rr(w.pattern) } : {}, name: y, onChange: j, onBlur: j, ref: (U) => { if (U) { ae(y, w), P = B(n, y); const M = Ae(U.value) && U.querySelectorAll && U.querySelectorAll("input,select,textarea")[0] || U, oe = Cd(M), we = P._f.refs || []; if (oe ? we.find((Se) => Se === M) : M === P._f.ref) return; Ce(n, y, { _f: { ...P._f, ...oe ? { refs: [ ...we.filter(En), M, ...Array.isArray(B(a, y)) ? [{}] : [] ], ref: { type: M.type, name: y } } : { ref: M } } }), C(y, !1, void 0, M); } else P = B(n, y, {}), P._f && (P._f.mount = !1), (e.shouldUnregister || w.shouldUnregister) && !(tu(s.array, y) && o.action) && s.unMount.add(y); } }; }, X = () => e.shouldFocusError && lr(n, D, s.mount), ve = (y) => { Ge(y) && (h.state.next({ disabled: y }), lr(n, (w, P) => { const Z = B(n, P); Z && (w.disabled = Z._f.disabled || y, Array.isArray(Z._f.refs) && Z._f.refs.forEach((U) => { U.disabled = Z._f.disabled || y; })); }, 0, !1)); }, V = (y, w) => async (P) => { let Z; P && (P.preventDefault && P.preventDefault(), P.persist && P.persist()); let U = Me(i); if (h.state.next({ isSubmitting: !0 }), e.resolver) { const { errors: M, values: oe } = await de(); r.errors = M, U = Me(oe); } else await le(n); if (s.disabled.size) for (const M of s.disabled) Re(U, M); if (Re(r.errors, "root"), We(r.errors)) { h.state.next({ errors: {} }); try { await y(U, P); } catch (M) { Z = M; } } else w && await w({ ...r.errors }, P), X(), setTimeout(X); if (h.state.next({ isSubmitted: !0, isSubmitting: !1, isSubmitSuccessful: We(r.errors) && !Z, submitCount: r.submitCount + 1, errors: r.errors }), Z) throw Z; }, Ie = (y, w = {}) => { B(n, y) && (Ae(w.defaultValue) ? T(y, Me(B(a, y))) : (T(y, w.defaultValue), Ce(a, y, Me(w.defaultValue))), w.keepTouched || Re(r.touchedFields, y), w.keepDirty || (Re(r.dirtyFields, y), r.isDirty = w.defaultValue ? ee(y, Me(B(a, y))) : ee()), w.keepError || (Re(r.errors, y), d.isValid && S()), h.state.next({ ...r })); }, _t = (y, w = {}) => { const P = y ? Me(y) : a, Z = Me(P), U = We(y), M = U ? a : Z; if (w.keepDefaultValues || (a = P), !w.keepValues) { if (w.keepDirtyValues) { const oe = /* @__PURE__ */ new Set([ ...s.mount, ...Object.keys(tr(a, i)) ]); for (const we of Array.from(oe)) B(r.dirtyFields, we) ? Ce(M, we, B(i, we)) : T(we, B(M, we)); } else { if (Ba && Ae(y)) for (const oe of s.mount) { const we = B(n, oe); if (we && we._f) { const Se = Array.isArray(we._f.refs) ? we._f.refs[0] : we._f.ref; if (Kr(Se)) { const ze = Se.closest("form"); if (ze) { ze.reset(); break; } } } } if (w.keepFieldsRef) for (const oe of s.mount) T(oe, B(M, oe)); else n = {}; } i = e.shouldUnregister ? w.keepDefaultValues ? Me(a) : {} : Me(M), h.array.next({ values: { ...M } }), h.state.next({ values: { ...M } }); } s = { mount: w.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 = !d.isValid || !!w.keepIsValid || !!w.keepDirtyValues, o.watch = !!e.shouldUnregister, h.state.next({ submitCount: w.keepSubmitCount ? r.submitCount : 0, isDirty: U ? !1 : w.keepDirty ? r.isDirty : !!(w.keepDefaultValues && !lt(y, a)), isSubmitted: w.keepIsSubmitted ? r.isSubmitted : !1, dirtyFields: U ? {} : w.keepDirtyValues ? w.keepDefaultValues && i ? tr(a, i) : r.dirtyFields : w.keepDefaultValues && y ? tr(a, y) : w.keepDirty ? r.dirtyFields : {}, touchedFields: w.keepTouched ? r.touchedFields : {}, errors: w.keepErrors ? r.errors : {}, isSubmitSuccessful: w.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1, isSubmitting: !1, defaultValues: a }); }, er = (y, w) => _t(Je(y) ? y(i) : y, w), fd = (y, w = {}) => { const P = B(n, y), Z = P && P._f; if (Z) { const U = Z.refs ? Z.refs[0] : Z.ref; U.focus && (U.focus(), w.shouldSelect && Je(U.select) && U.select()); } }, hd = (y) => { r = { ...r, ...y }; }, $i = { control: { register: ae, unregister: ie, getFieldState: E, handleSubmit: V, setError: Y, _subscribe: z, _runSchema: de, _focusError: X, _getWatch: re, _getDirty: ee, _setValid: S, _setFieldArray: b, _setDisabledField: G, _setErrors: N, _getFieldArray: pe, _reset: _t, _resetDefaultValues: () => Je(e.defaultValues) && e.defaultValues().then((y) => { er(y, e.resetOptions), h.state.next({ isLoading: !1 }); }), _removeUnmounted: ue, _disableForm: ve, _subjects: h, _proxyFormState: d, 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: se, trigger: ne, register: ae, handleSubmit: V, watch: k, setValue: T, getValues: _, reset: er, resetField: Ie, clearErrors: K, unregister: ie, setError: Y, setFocus: fd, getFieldState: E }; return { ...$i, formControl: $i }; } function Dd(t = {}) { const e = F.useRef(void 0), r = F.useRef(void 0), [n, a] = F.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 } = Rd(t); e.current = { ...s, formState: n }; } const i = e.current.control; return i._options = t, Ha(() => { 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]), F.useEffect(() => i._disableForm(t.disabled), [i, t.disabled]), F.useEffect(() => { t.mode && (i._options.mode = t.mode), t.reValidateMode && (i._options.reValidateMode = t.reValidateMode); }, [i, t.mode, t.reValidateMode]), F.useEffect(() => { t.errors && (i._setErrors(t.errors), i._focusError()); }, [i, t.errors]), F.useEffect(() => { t.shouldUnregister && i._subjects.state.next({ values: i._getWatch() }); }, [i, t.shouldUnregister]), F.useEffect(() => { if (i._proxyFormState.isDirty) { const o = i._getDirty(); o !== n.isDirty && i._subjects.state.next({ isDirty: o }); } }, [i, n.isDirty]), F.useEffect(() => { t.values && !lt(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]), F.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 = nu(n, i), e.current; } var te = /* @__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))(te || {}); function fu(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 = fu(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 = fu(t)) && (n && (n += " "), n += e); return n; } const hu = Va(null); function Md() { const t = Ua(hu); if (!t) throw new Error("FormField components must be used within a <Form> component."); return t; } const pu = Va({ labelDisplay: "default" // 'default' is the sensible default }); function jd() { const t = Ua(pu); if (!t) throw new Error("useFormConfig must be used within a <Form> component."); return t; } var be; (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; })(be || (be = {})); var Ri; (function(t) { t.mergeShapes = (e, r) => ({ ...e, ...r // second overwrites first }); })(Ri || (Ri = {})); const Q = be.arrayToEnum([ "string", "nan", "number", "integer", "float", "boolean", "date", "bigint", "symbol", "function", "undefined", "null", "array", "object", "unknown", "promise", "void", "never", "map", "set" ]), vt = (t) => { switch (typeof t) { case "undefined": return Q.undefined; case "string": return Q.string; case "number": return Number.isNaN(t) ? Q.nan : Q.number; case "boolean": return Q.boolean; case "function": return Q.function; case "bigint": return Q.bigint; case "symbol": return Q.symbol; case "object": return Array.isArray(t) ? Q.array : t === null ? Q.null : t.then && typeof t.then == "function" && t.catch && typeof t.catch == "function" ? Q.promise : typeof Map < "u" && t instanceof Map ? Q.map : typeof Set < "u" && t instanceof Set ? Q.set : typeof Date < "u" && t instanceof Date ? Q.date : Q.object; default: return Q.unknown; } }, R = be.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 nt 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 l = o.path[u]; u === o.path.length - 1 ? (s[l] = s[l] || { _errors: [] }, s[l]._errors.push(r(o))) : s[l] = s[l] || { _errors: [] }, s = s[l], u++; } } }; return a(this), n; } static assert(e) { if (!(e instanceof nt)) throw new Error(`Not a ZodError: ${e}`); } toString() { return this.message; } get message() { return JSON.stringify(this.issues, be.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(); } } nt.create = (t) => new nt(t); const ta = (t, e) => { let r; switch (t.code) { case R.invalid_type: t.received === Q.undefined ? r = "Required" : r = `Expected ${t.expected}, received ${t.received}`; break; case R.invalid_literal: r = `Invalid literal value, expected ${JSON.stringify(t.expected, be.jsonStringifyReplacer)}`; break; case R.unrecognized_keys: r = `Unrecognized key(s) in object: ${be.joinValues(t.keys, ", ")}`; break; case R.invalid_union: r = "Invalid input"; break; case R.invalid_union_discriminator: r = `Invalid discriminator value. Expected ${be.joinValues(t.options)}`; break; case R.invalid_enum_value: r = `Invalid enum value. Expected ${be.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}"` : be.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, be.assertNever(t); } return { message: r }; }; let Ld = ta; function Vd() { return Ld; } const Ud = (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((l) => !!l).slice().reverse(); for (const l of u) s = l(o, { data: e, defaultError: s }).message; return { ...a, path: i, message: s }; }; function H(t, e) { const r = Vd(), n = Ud({ 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 === ta ? void 0 : ta // then global default map ].filter((a) => !!a) }); t.common.issues.push(n); } class Ze { 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 ce; 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 Ze.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 ce; 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 ce = Object.fr