finform-react-builder
Version:
A powerful, flexible React form builder with dynamic field rendering, custom validation, multi-step forms, Material-UI integration, image component support, toggle/radio buttons, switches, autocomplete, and advanced button positioning
1,448 lines • 549 kB
JavaScript
var nu = Object.defineProperty;
var Fo = (e) => {
throw TypeError(e);
};
var iu = (e, t, r) => t in e ? nu(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
var bn = (e, t, r) => iu(e, typeof t != "symbol" ? t + "" : t, r), Hi = (e, t, r) => t.has(e) || Fo("Cannot " + r);
var O = (e, t, r) => (Hi(e, t, "read from private field"), r ? r.call(e) : t.get(e)), ye = (e, t, r) => t.has(e) ? Fo("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), te = (e, t, r, n) => (Hi(e, t, "write to private field"), n ? n.call(e, r) : t.set(e, r), r), we = (e, t, r) => (Hi(e, t, "access private method"), r);
var Un = (e, t, r, n) => ({
set _(i) {
te(e, t, i, r);
},
get _() {
return O(e, t, n);
}
});
import { jsx as m, jsxs as se, Fragment as Fi } from "react/jsx-runtime";
import * as re from "react";
import oe, { isValidElement as ni, cloneElement as ii, Children as au, useState as Pt, useMemo as Ke, useRef as gt, useEffect as jt, useCallback as Ne, useReducer as ou, forwardRef as su, useImperativeHandle as lu, Fragment as cu, createElement as uu } from "react";
import { InputAdornment as pu, Box as J, Typography as be, TextField as _i, FormControl as Ja, InputLabel as du, Select as fu, MenuItem as _o, CircularProgress as gn, OutlinedInput as hu, FormHelperText as eo, Autocomplete as mu, Checkbox as An, FormControlLabel as Jr, FormLabel as Sl, Switch as Cl, RadioGroup as gu, Radio as yu, Divider as to, Chip as El, StepConnector as kl, stepConnectorClasses as hr, Stepper as Tl, Step as Ol, StepLabel as Al, Button as Xe, Card as xt, List as Ro, ListItem as $o, ListItemText as Do, Tabs as vu, Tab as xu, TableContainer as bu, Table as wu, TableHead as Su, TableRow as Po, TableCell as Br, TableBody as Cu, IconButton as ro, Dialog as Eu, DialogTitle as ku, DialogContent as Tu, DialogActions as Ou, LinearProgress as Au, ButtonGroup as Fu, createTheme as _u, ThemeProvider as Ru, Paper as $u, Tooltip as Du, Alert as Pu } from "@mui/material";
import Iu from "@emotion/styled";
import { keyframes as zn, css as Fl } from "@emotion/react";
var Vn = (e) => e.type === "checkbox", Er = (e) => e instanceof Date, ot = (e) => e == null;
const _l = (e) => typeof e == "object";
var Qe = (e) => !ot(e) && !Array.isArray(e) && _l(e) && !Er(e), Rl = (e) => Qe(e) && e.target ? Vn(e.target) ? e.target.checked : e.target.value : e, Mu = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, $l = (e, t) => e.has(Mu(t)), ju = (e) => {
const t = e.constructor && e.constructor.prototype;
return Qe(t) && t.hasOwnProperty("isPrototypeOf");
}, no = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
function ze(e) {
let t;
const r = Array.isArray(e), n = typeof FileList < "u" ? e instanceof FileList : !1;
if (e instanceof Date)
t = new Date(e);
else if (e instanceof Set)
t = new Set(e);
else if (!(no && (e instanceof Blob || n)) && (r || Qe(e)))
if (t = r ? [] : {}, !r && !ju(e))
t = e;
else
for (const i in e)
e.hasOwnProperty(i) && (t[i] = ze(e[i]));
else
return e;
return t;
}
var Ri = (e) => /^\w*$/.test(e), Pe = (e) => e === void 0, $i = (e) => Array.isArray(e) ? e.filter(Boolean) : [], io = (e) => $i(e.replace(/["|']|\]/g, "").split(/\.|\[/)), Y = (e, t, r) => {
if (!t || !Qe(e))
return r;
const n = (Ri(t) ? [t] : io(t)).reduce((i, a) => ot(i) ? i : i[a], e);
return Pe(n) || n === e ? Pe(e[t]) ? r : e[t] : n;
}, mt = (e) => typeof e == "boolean", Ce = (e, t, r) => {
let n = -1;
const i = Ri(t) ? [t] : io(t), a = i.length, o = a - 1;
for (; ++n < a; ) {
const s = i[n];
let l = r;
if (n !== o) {
const p = e[s];
l = Qe(p) || Array.isArray(p) ? p : isNaN(+i[n + 1]) ? {} : [];
}
if (s === "__proto__" || s === "constructor" || s === "prototype")
return;
e[s] = l, e = e[s];
}
};
const pi = {
BLUR: "blur",
FOCUS_OUT: "focusout",
CHANGE: "change"
}, At = {
onBlur: "onBlur",
onChange: "onChange",
onSubmit: "onSubmit",
onTouched: "onTouched",
all: "all"
}, Kt = {
max: "max",
min: "min",
maxLength: "maxLength",
minLength: "minLength",
pattern: "pattern",
required: "required",
validate: "validate"
}, Dl = oe.createContext(null);
Dl.displayName = "HookFormContext";
const Di = () => oe.useContext(Dl);
var Pl = (e, t, r, n = !0) => {
const i = {
defaultValues: t._defaultValues
};
for (const a in e)
Object.defineProperty(i, a, {
get: () => {
const o = a;
return t._proxyFormState[o] !== At.all && (t._proxyFormState[o] = !n || At.all), r && (r[o] = !0), e[o];
}
});
return i;
};
const Pi = typeof window < "u" ? re.useLayoutEffect : re.useEffect;
function zu(e) {
const t = Di(), { control: r = t.control, disabled: n, name: i, exact: a } = e || {}, [o, s] = oe.useState(r._formState), l = oe.useRef({
isDirty: !1,
isLoading: !1,
dirtyFields: !1,
touchedFields: !1,
validatingFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
});
return Pi(() => r._subscribe({
name: i,
formState: l.current,
exact: a,
callback: (p) => {
!n && s({
...r._formState,
...p
});
}
}), [i, n, a]), oe.useEffect(() => {
l.current.isValid && r._setValid(!0);
}, [r]), oe.useMemo(() => Pl(o, r, l.current, !1), [o, r]);
}
var Ht = (e) => typeof e == "string", Il = (e, t, r, n, i) => Ht(e) ? (n && t.watch.add(e), Y(r, e, i)) : Array.isArray(e) ? e.map((a) => (n && t.watch.add(a), Y(r, a))) : (n && (t.watchAll = !0), r);
function Ml(e) {
const t = Di(), { control: r = t.control, name: n, defaultValue: i, disabled: a, exact: o } = e || {}, s = oe.useRef(i), [l, p] = oe.useState(r._getWatch(n, s.current));
return Pi(() => r._subscribe({
name: n,
formState: {
values: !0
},
exact: o,
callback: (d) => !a && p(Il(n, r._names, d.values || r._formValues, !1, s.current))
}), [n, r, a, o]), oe.useEffect(() => r._removeUnmounted()), l;
}
function Vu(e) {
const t = Di(), { name: r, disabled: n, control: i = t.control, shouldUnregister: a } = e, o = $l(i._names.array, r), s = Ml({
control: i,
name: r,
defaultValue: Y(i._formValues, r, Y(i._defaultValues, r, e.defaultValue)),
exact: !0
}), l = zu({
control: i,
name: r,
exact: !0
}), p = oe.useRef(e), d = oe.useRef(i.register(r, {
...e.rules,
value: s,
...mt(e.disabled) ? { disabled: e.disabled } : {}
})), u = oe.useMemo(() => Object.defineProperties({}, {
invalid: {
enumerable: !0,
get: () => !!Y(l.errors, r)
},
isDirty: {
enumerable: !0,
get: () => !!Y(l.dirtyFields, r)
},
isTouched: {
enumerable: !0,
get: () => !!Y(l.touchedFields, r)
},
isValidating: {
enumerable: !0,
get: () => !!Y(l.validatingFields, r)
},
error: {
enumerable: !0,
get: () => Y(l.errors, r)
}
}), [l, r]), h = oe.useCallback((S) => d.current.onChange({
target: {
value: Rl(S),
name: r
},
type: pi.CHANGE
}), [r]), g = oe.useCallback(() => d.current.onBlur({
target: {
value: Y(i._formValues, r),
name: r
},
type: pi.BLUR
}), [r, i._formValues]), k = oe.useCallback((S) => {
const v = Y(i._fields, r);
v && S && (v._f.ref = {
focus: () => S.focus && S.focus(),
select: () => S.select && S.select(),
setCustomValidity: (w) => S.setCustomValidity(w),
reportValidity: () => S.reportValidity()
});
}, [i._fields, r]), f = oe.useMemo(() => ({
name: r,
value: s,
...mt(n) || l.disabled ? { disabled: l.disabled || n } : {},
onChange: h,
onBlur: g,
ref: k
}), [r, n, l.disabled, h, g, k, s]);
return oe.useEffect(() => {
const S = i._options.shouldUnregister || a;
i.register(r, {
...p.current.rules,
...mt(p.current.disabled) ? { disabled: p.current.disabled } : {}
});
const v = (w, D) => {
const b = Y(i._fields, w);
b && b._f && (b._f.mount = D);
};
if (v(r, !0), S) {
const w = ze(Y(i._options.defaultValues, r));
Ce(i._defaultValues, r, w), Pe(Y(i._formValues, r)) && Ce(i._formValues, r, w);
}
return !o && i.register(r), () => {
(o ? S && !i._state.action : S) ? i.unregister(r) : v(r, !1);
};
}, [r, i, o, a]), oe.useEffect(() => {
i._setDisabledField({
disabled: n,
name: r
});
}, [n, r, i]), oe.useMemo(() => ({
field: f,
formState: l,
fieldState: u
}), [f, l, u]);
}
const je = (e) => e.render(Vu(e));
var jl = (e, t, r, n, i) => t ? {
...r[e],
types: {
...r[e] && r[e].types ? r[e].types : {},
[n]: i || !0
}
} : {}, ft = (e) => Array.isArray(e) ? e : [e], Io = () => {
let e = [];
return {
get observers() {
return e;
},
next: (i) => {
for (const a of e)
a.next && a.next(i);
},
subscribe: (i) => (e.push(i), {
unsubscribe: () => {
e = e.filter((a) => a !== i);
}
}),
unsubscribe: () => {
e = [];
}
};
}, va = (e) => ot(e) || !_l(e);
function ar(e, t) {
if (va(e) || va(t))
return e === t;
if (Er(e) && Er(t))
return e.getTime() === t.getTime();
const r = Object.keys(e), n = Object.keys(t);
if (r.length !== n.length)
return !1;
for (const i of r) {
const a = e[i];
if (!n.includes(i))
return !1;
if (i !== "ref") {
const o = t[i];
if (Er(a) && Er(o) || Qe(a) && Qe(o) || Array.isArray(a) && Array.isArray(o) ? !ar(a, o) : a !== o)
return !1;
}
}
return !0;
}
var at = (e) => Qe(e) && !Object.keys(e).length, ao = (e) => e.type === "file", It = (e) => typeof e == "function", di = (e) => {
if (!no)
return !1;
const t = e ? e.ownerDocument : 0;
return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
}, zl = (e) => e.type === "select-multiple", oo = (e) => e.type === "radio", Nu = (e) => oo(e) || Vn(e), Ki = (e) => di(e) && e.isConnected;
function Lu(e, t) {
const r = t.slice(0, -1).length;
let n = 0;
for (; n < r; )
e = Pe(e) ? n++ : e[t[n++]];
return e;
}
function Bu(e) {
for (const t in e)
if (e.hasOwnProperty(t) && !Pe(e[t]))
return !1;
return !0;
}
function Ze(e, t) {
const r = Array.isArray(t) ? t : Ri(t) ? [t] : io(t), n = r.length === 1 ? e : Lu(e, r), i = r.length - 1, a = r[i];
return n && delete n[a], i !== 0 && (Qe(n) && at(n) || Array.isArray(n) && Bu(n)) && Ze(e, r.slice(0, -1)), e;
}
var Vl = (e) => {
for (const t in e)
if (It(e[t]))
return !0;
return !1;
};
function fi(e, t = {}) {
const r = Array.isArray(e);
if (Qe(e) || r)
for (const n in e)
Array.isArray(e[n]) || Qe(e[n]) && !Vl(e[n]) ? (t[n] = Array.isArray(e[n]) ? [] : {}, fi(e[n], t[n])) : ot(e[n]) || (t[n] = !0);
return t;
}
function Nl(e, t, r) {
const n = Array.isArray(e);
if (Qe(e) || n)
for (const i in e)
Array.isArray(e[i]) || Qe(e[i]) && !Vl(e[i]) ? Pe(t) || va(r[i]) ? r[i] = Array.isArray(e[i]) ? fi(e[i], []) : { ...fi(e[i]) } : Nl(e[i], ot(t) ? {} : t[i], r[i]) : r[i] = !ar(e[i], t[i]);
return r;
}
var wn = (e, t) => Nl(e, t, fi(t));
const Mo = {
value: !1,
isValid: !1
}, jo = { value: !0, isValid: !0 };
var Ll = (e) => {
if (Array.isArray(e)) {
if (e.length > 1) {
const t = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
return { value: t, isValid: !!t.length };
}
return e[0].checked && !e[0].disabled ? (
// @ts-expect-error expected to work in the browser
e[0].attributes && !Pe(e[0].attributes.value) ? Pe(e[0].value) || e[0].value === "" ? jo : { value: e[0].value, isValid: !0 } : jo
) : Mo;
}
return Mo;
}, Bl = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: n }) => Pe(e) ? e : t ? e === "" ? NaN : e && +e : r && Ht(e) ? new Date(e) : n ? n(e) : e;
const zo = {
isValid: !1,
value: null
};
var ql = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
isValid: !0,
value: r.value
} : t, zo) : zo;
function Vo(e) {
const t = e.ref;
return ao(t) ? t.files : oo(t) ? ql(e.refs).value : zl(t) ? [...t.selectedOptions].map(({ value: r }) => r) : Vn(t) ? Ll(e.refs).value : Bl(Pe(t.value) ? e.ref.value : t.value, e);
}
var qu = (e, t, r, n) => {
const i = {};
for (const a of e) {
const o = Y(t, a);
o && Ce(i, a, o._f);
}
return {
criteriaMode: r,
names: [...e],
fields: i,
shouldUseNativeValidation: n
};
}, hi = (e) => e instanceof RegExp, Sn = (e) => Pe(e) ? e : hi(e) ? e.source : Qe(e) ? hi(e.value) ? e.value.source : e.value : e, Zr = (e) => ({
isOnSubmit: !e || e === At.onSubmit,
isOnBlur: e === At.onBlur,
isOnChange: e === At.onChange,
isOnAll: e === At.all,
isOnTouch: e === At.onTouched
});
const No = "AsyncFunction";
var Wu = (e) => !!e && !!e.validate && !!(It(e.validate) && e.validate.constructor.name === No || Qe(e.validate) && Object.values(e.validate).find((t) => t.constructor.name === No)), Uu = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), xa = (e, t, r) => !r && (t.watchAll || t.watch.has(e) || [...t.watch].some((n) => e.startsWith(n) && /^\.\w+/.test(e.slice(n.length))));
const en = (e, t, r, n) => {
for (const i of r || Object.keys(e)) {
const a = Y(e, i);
if (a) {
const { _f: o, ...s } = a;
if (o) {
if (o.refs && o.refs[0] && t(o.refs[0], i) && !n)
return !0;
if (o.ref && t(o.ref, o.name) && !n)
return !0;
if (en(s, t))
break;
} else if (Qe(s) && en(s, t))
break;
}
}
};
function Lo(e, t, r) {
const n = Y(e, r);
if (n || Ri(r))
return {
error: n,
name: r
};
const i = r.split(".");
for (; i.length; ) {
const a = i.join("."), o = Y(t, a), s = Y(e, a);
if (o && !Array.isArray(o) && r !== a)
return { name: r };
if (s && s.type)
return {
name: a,
error: s
};
if (s && s.root && s.root.type)
return {
name: `${a}.root`,
error: s.root
};
i.pop();
}
return {
name: r
};
}
var Hu = (e, t, r, n) => {
r(e);
const { name: i, ...a } = e;
return at(a) || Object.keys(a).length >= Object.keys(t).length || Object.keys(a).find((o) => t[o] === (!n || At.all));
}, Ku = (e, t, r) => !e || !t || e === t || ft(e).some((n) => n && (r ? n === t : n.startsWith(t) || t.startsWith(n))), Qu = (e, t, r, n, i) => i.isOnAll ? !1 : !r && i.isOnTouch ? !(t || e) : (r ? n.isOnBlur : i.isOnBlur) ? !e : (r ? n.isOnChange : i.isOnChange) ? e : !0, Yu = (e, t) => !$i(Y(e, t)).length && Ze(e, t), Wl = (e, t, r) => {
const n = ft(Y(e, r));
return Ce(n, "root", t[r]), Ce(e, r, n), e;
}, ai = (e) => Ht(e);
function Bo(e, t, r = "validate") {
if (ai(e) || Array.isArray(e) && e.every(ai) || mt(e) && !e)
return {
type: r,
message: ai(e) ? e : "",
ref: t
};
}
var qr = (e) => Qe(e) && !hi(e) ? e : {
value: e,
message: ""
}, ba = async (e, t, r, n, i, a) => {
const { ref: o, refs: s, required: l, maxLength: p, minLength: d, min: u, max: h, pattern: g, validate: k, name: f, valueAsNumber: S, mount: v } = e._f, w = Y(r, f);
if (!v || t.has(f))
return {};
const D = s ? s[0] : o, b = (V) => {
i && D.reportValidity && (D.setCustomValidity(mt(V) ? "" : V || ""), D.reportValidity());
}, x = {}, _ = oo(o), M = Vn(o), A = _ || M, $ = (S || ao(o)) && Pe(o.value) && Pe(w) || di(o) && o.value === "" || w === "" || Array.isArray(w) && !w.length, c = jl.bind(null, f, n, x), P = (V, F, N, K = Kt.maxLength, ae = Kt.minLength) => {
const ge = V ? F : N;
x[f] = {
type: V ? K : ae,
message: ge,
ref: o,
...c(V ? K : ae, ge)
};
};
if (a ? !Array.isArray(w) || !w.length : l && (!A && ($ || ot(w)) || mt(w) && !w || M && !Ll(s).isValid || _ && !ql(s).isValid)) {
const { value: V, message: F } = ai(l) ? { value: !!l, message: l } : qr(l);
if (V && (x[f] = {
type: Kt.required,
message: F,
ref: D,
...c(Kt.required, F)
}, !n))
return b(F), x;
}
if (!$ && (!ot(u) || !ot(h))) {
let V, F;
const N = qr(h), K = qr(u);
if (!ot(w) && !isNaN(w)) {
const ae = o.valueAsNumber || w && +w;
ot(N.value) || (V = ae > N.value), ot(K.value) || (F = ae < K.value);
} else {
const ae = o.valueAsDate || new Date(w), ge = (z) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + z), pe = o.type == "time", U = o.type == "week";
Ht(N.value) && w && (V = pe ? ge(w) > ge(N.value) : U ? w > N.value : ae > new Date(N.value)), Ht(K.value) && w && (F = pe ? ge(w) < ge(K.value) : U ? w < K.value : ae < new Date(K.value));
}
if ((V || F) && (P(!!V, N.message, K.message, Kt.max, Kt.min), !n))
return b(x[f].message), x;
}
if ((p || d) && !$ && (Ht(w) || a && Array.isArray(w))) {
const V = qr(p), F = qr(d), N = !ot(V.value) && w.length > +V.value, K = !ot(F.value) && w.length < +F.value;
if ((N || K) && (P(N, V.message, F.message), !n))
return b(x[f].message), x;
}
if (g && !$ && Ht(w)) {
const { value: V, message: F } = qr(g);
if (hi(V) && !w.match(V) && (x[f] = {
type: Kt.pattern,
message: F,
ref: o,
...c(Kt.pattern, F)
}, !n))
return b(F), x;
}
if (k) {
if (It(k)) {
const V = await k(w, r), F = Bo(V, D);
if (F && (x[f] = {
...F,
...c(Kt.validate, F.message)
}, !n))
return b(F.message), x;
} else if (Qe(k)) {
let V = {};
for (const F in k) {
if (!at(V) && !n)
break;
const N = Bo(await k[F](w, r), D, F);
N && (V = {
...N,
...c(F, N.message)
}, b(N.message), n && (x[f] = V));
}
if (!at(V) && (x[f] = {
ref: D,
...V
}, !n))
return x;
}
}
return b(!0), x;
};
const Gu = {
mode: At.onSubmit,
reValidateMode: At.onChange,
shouldFocusError: !0
};
function Zu(e = {}) {
let t = {
...Gu,
...e
}, r = {
submitCount: 0,
isDirty: !1,
isReady: !1,
isLoading: It(t.defaultValues),
isValidating: !1,
isSubmitted: !1,
isSubmitting: !1,
isSubmitSuccessful: !1,
isValid: !1,
touchedFields: {},
dirtyFields: {},
validatingFields: {},
errors: t.errors || {},
disabled: t.disabled || !1
};
const n = {};
let i = Qe(t.defaultValues) || Qe(t.values) ? ze(t.defaultValues || t.values) || {} : {}, a = t.shouldUnregister ? {} : ze(i), 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()
}, l, p = 0;
const d = {
isDirty: !1,
dirtyFields: !1,
validatingFields: !1,
touchedFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
};
let u = {
...d
};
const h = {
array: Io(),
state: Io()
}, g = t.criteriaMode === At.all, k = (y) => (C) => {
clearTimeout(p), p = setTimeout(y, C);
}, f = async (y) => {
if (!t.disabled && (d.isValid || u.isValid || y)) {
const C = t.resolver ? at((await M()).errors) : await $(n, !0);
C !== r.isValid && h.state.next({
isValid: C
});
}
}, S = (y, C) => {
!t.disabled && (d.isValidating || d.validatingFields || u.isValidating || u.validatingFields) && ((y || Array.from(s.mount)).forEach((T) => {
T && (C ? Ce(r.validatingFields, T, C) : Ze(r.validatingFields, T));
}), h.state.next({
validatingFields: r.validatingFields,
isValidating: !at(r.validatingFields)
}));
}, v = (y, C = [], T, q, R = !0, I = !0) => {
if (q && T && !t.disabled) {
if (o.action = !0, I && Array.isArray(Y(n, y))) {
const Q = T(Y(n, y), q.argA, q.argB);
R && Ce(n, y, Q);
}
if (I && Array.isArray(Y(r.errors, y))) {
const Q = T(Y(r.errors, y), q.argA, q.argB);
R && Ce(r.errors, y, Q), Yu(r.errors, y);
}
if ((d.touchedFields || u.touchedFields) && I && Array.isArray(Y(r.touchedFields, y))) {
const Q = T(Y(r.touchedFields, y), q.argA, q.argB);
R && Ce(r.touchedFields, y, Q);
}
(d.dirtyFields || u.dirtyFields) && (r.dirtyFields = wn(i, a)), h.state.next({
name: y,
isDirty: P(y, C),
dirtyFields: r.dirtyFields,
errors: r.errors,
isValid: r.isValid
});
} else
Ce(a, y, C);
}, w = (y, C) => {
Ce(r.errors, y, C), h.state.next({
errors: r.errors
});
}, D = (y) => {
r.errors = y, h.state.next({
errors: r.errors,
isValid: !1
});
}, b = (y, C, T, q) => {
const R = Y(n, y);
if (R) {
const I = Y(a, y, Pe(T) ? Y(i, y) : T);
Pe(I) || q && q.defaultChecked || C ? Ce(a, y, C ? I : Vo(R._f)) : N(y, I), o.mount && f();
}
}, x = (y, C, T, q, R) => {
let I = !1, Q = !1;
const ne = {
name: y
};
if (!t.disabled) {
if (!T || q) {
(d.isDirty || u.isDirty) && (Q = r.isDirty, r.isDirty = ne.isDirty = P(), I = Q !== ne.isDirty);
const B = ar(Y(i, y), C);
Q = !!Y(r.dirtyFields, y), B ? Ze(r.dirtyFields, y) : Ce(r.dirtyFields, y, !0), ne.dirtyFields = r.dirtyFields, I = I || (d.dirtyFields || u.dirtyFields) && Q !== !B;
}
if (T) {
const B = Y(r.touchedFields, y);
B || (Ce(r.touchedFields, y, T), ne.touchedFields = r.touchedFields, I = I || (d.touchedFields || u.touchedFields) && B !== T);
}
I && R && h.state.next(ne);
}
return I ? ne : {};
}, _ = (y, C, T, q) => {
const R = Y(r.errors, y), I = (d.isValid || u.isValid) && mt(C) && r.isValid !== C;
if (t.delayError && T ? (l = k(() => w(y, T)), l(t.delayError)) : (clearTimeout(p), l = null, T ? Ce(r.errors, y, T) : Ze(r.errors, y)), (T ? !ar(R, T) : R) || !at(q) || I) {
const Q = {
...q,
...I && mt(C) ? { isValid: C } : {},
errors: r.errors,
name: y
};
r = {
...r,
...Q
}, h.state.next(Q);
}
}, M = async (y) => {
S(y, !0);
const C = await t.resolver(a, t.context, qu(y || s.mount, n, t.criteriaMode, t.shouldUseNativeValidation));
return S(y), C;
}, A = async (y) => {
const { errors: C } = await M(y);
if (y)
for (const T of y) {
const q = Y(C, T);
q ? Ce(r.errors, T, q) : Ze(r.errors, T);
}
else
r.errors = C;
return C;
}, $ = async (y, C, T = {
valid: !0
}) => {
for (const q in y) {
const R = y[q];
if (R) {
const { _f: I, ...Q } = R;
if (I) {
const ne = s.array.has(I.name), B = R._f && Wu(R._f);
B && d.validatingFields && S([q], !0);
const xe = await ba(R, s.disabled, a, g, t.shouldUseNativeValidation && !C, ne);
if (B && d.validatingFields && S([q]), xe[I.name] && (T.valid = !1, C))
break;
!C && (Y(xe, I.name) ? ne ? Wl(r.errors, xe, I.name) : Ce(r.errors, I.name, xe[I.name]) : Ze(r.errors, I.name));
}
!at(Q) && await $(Q, C, T);
}
}
return T.valid;
}, c = () => {
for (const y of s.unMount) {
const C = Y(n, y);
C && (C._f.refs ? C._f.refs.every((T) => !Ki(T)) : !Ki(C._f.ref)) && X(y);
}
s.unMount = /* @__PURE__ */ new Set();
}, P = (y, C) => !t.disabled && (y && C && Ce(a, y, C), !ar(z(), i)), V = (y, C, T) => Il(y, s, {
...o.mount ? a : Pe(C) ? i : Ht(y) ? { [y]: C } : C
}, T, C), F = (y) => $i(Y(o.mount ? a : i, y, t.shouldUnregister ? Y(i, y, []) : [])), N = (y, C, T = {}) => {
const q = Y(n, y);
let R = C;
if (q) {
const I = q._f;
I && (!I.disabled && Ce(a, y, Bl(C, I)), R = di(I.ref) && ot(C) ? "" : C, zl(I.ref) ? [...I.ref.options].forEach((Q) => Q.selected = R.includes(Q.value)) : I.refs ? Vn(I.ref) ? I.refs.forEach((Q) => {
(!Q.defaultChecked || !Q.disabled) && (Array.isArray(R) ? Q.checked = !!R.find((ne) => ne === Q.value) : Q.checked = R === Q.value || !!R);
}) : I.refs.forEach((Q) => Q.checked = Q.value === R) : ao(I.ref) ? I.ref.value = "" : (I.ref.value = R, I.ref.type || h.state.next({
name: y,
values: ze(a)
})));
}
(T.shouldDirty || T.shouldTouch) && x(y, R, T.shouldTouch, T.shouldDirty, !0), T.shouldValidate && U(y);
}, K = (y, C, T) => {
for (const q in C) {
if (!C.hasOwnProperty(q))
return;
const R = C[q], I = y + "." + q, Q = Y(n, I);
(s.array.has(y) || Qe(R) || Q && !Q._f) && !Er(R) ? K(I, R, T) : N(I, R, T);
}
}, ae = (y, C, T = {}) => {
const q = Y(n, y), R = s.array.has(y), I = ze(C);
Ce(a, y, I), R ? (h.array.next({
name: y,
values: ze(a)
}), (d.isDirty || d.dirtyFields || u.isDirty || u.dirtyFields) && T.shouldDirty && h.state.next({
name: y,
dirtyFields: wn(i, a),
isDirty: P(y, I)
})) : q && !q._f && !ot(I) ? K(y, I, T) : N(y, I, T), xa(y, s) && h.state.next({ ...r }), h.state.next({
name: o.mount ? y : void 0,
values: ze(a)
});
}, ge = async (y) => {
o.mount = !0;
const C = y.target;
let T = C.name, q = !0;
const R = Y(n, T), I = (B) => {
q = Number.isNaN(B) || Er(B) && isNaN(B.getTime()) || ar(B, Y(a, T, B));
}, Q = Zr(t.mode), ne = Zr(t.reValidateMode);
if (R) {
let B, xe;
const Ae = C.type ? Vo(R._f) : Rl(y), Fe = y.type === pi.BLUR || y.type === pi.FOCUS_OUT, Be = !Uu(R._f) && !t.resolver && !Y(r.errors, T) && !R._f.deps || Qu(Fe, Y(r.touchedFields, T), r.isSubmitted, ne, Q), He = xa(T, s, Fe);
Ce(a, T, Ae), Fe ? (R._f.onBlur && R._f.onBlur(y), l && l(0)) : R._f.onChange && R._f.onChange(y);
const rt = x(T, Ae, Fe), zt = !at(rt) || He;
if (!Fe && h.state.next({
name: T,
type: y.type,
values: ze(a)
}), Be)
return (d.isValid || u.isValid) && (t.mode === "onBlur" ? Fe && f() : Fe || f()), zt && h.state.next({ name: T, ...He ? {} : rt });
if (!Fe && He && h.state.next({ ...r }), t.resolver) {
const { errors: lt } = await M([T]);
if (I(Ae), q) {
const ht = Lo(r.errors, n, T), Rt = Lo(lt, n, ht.name || T);
B = Rt.error, T = Rt.name, xe = at(lt);
}
} else
S([T], !0), B = (await ba(R, s.disabled, a, g, t.shouldUseNativeValidation))[T], S([T]), I(Ae), q && (B ? xe = !1 : (d.isValid || u.isValid) && (xe = await $(n, !0)));
q && (R._f.deps && U(R._f.deps), _(T, xe, B, rt));
}
}, pe = (y, C) => {
if (Y(r.errors, C) && y.focus)
return y.focus(), 1;
}, U = async (y, C = {}) => {
let T, q;
const R = ft(y);
if (t.resolver) {
const I = await A(Pe(y) ? y : R);
T = at(I), q = y ? !R.some((Q) => Y(I, Q)) : T;
} else y ? (q = (await Promise.all(R.map(async (I) => {
const Q = Y(n, I);
return await $(Q && Q._f ? { [I]: Q } : Q);
}))).every(Boolean), !(!q && !r.isValid) && f()) : q = T = await $(n);
return h.state.next({
...!Ht(y) || (d.isValid || u.isValid) && T !== r.isValid ? {} : { name: y },
...t.resolver || !y ? { isValid: T } : {},
errors: r.errors
}), C.shouldFocus && !q && en(n, pe, y ? R : s.mount), q;
}, z = (y) => {
const C = {
...o.mount ? a : i
};
return Pe(y) ? C : Ht(y) ? Y(C, y) : y.map((T) => Y(C, T));
}, W = (y, C) => ({
invalid: !!Y((C || r).errors, y),
isDirty: !!Y((C || r).dirtyFields, y),
error: Y((C || r).errors, y),
isValidating: !!Y(r.validatingFields, y),
isTouched: !!Y((C || r).touchedFields, y)
}), fe = (y) => {
y && ft(y).forEach((C) => Ze(r.errors, C)), h.state.next({
errors: y ? r.errors : {}
});
}, he = (y, C, T) => {
const q = (Y(n, y, { _f: {} })._f || {}).ref, R = Y(r.errors, y) || {}, { ref: I, message: Q, type: ne, ...B } = R;
Ce(r.errors, y, {
...B,
...C,
ref: q
}), h.state.next({
name: y,
errors: r.errors,
isValid: !1
}), T && T.shouldFocus && q && q.focus && q.focus();
}, de = (y, C) => It(y) ? h.state.subscribe({
next: (T) => y(V(void 0, C), T)
}) : V(y, C, !0), ve = (y) => h.state.subscribe({
next: (C) => {
Ku(y.name, C.name, y.exact) && Hu(C, y.formState || d, ce, y.reRenderRoot) && y.callback({
values: { ...a },
...r,
...C
});
}
}).unsubscribe, L = (y) => (o.mount = !0, u = {
...u,
...y.formState
}, ve({
...y,
formState: u
})), X = (y, C = {}) => {
for (const T of y ? ft(y) : s.mount)
s.mount.delete(T), s.array.delete(T), C.keepValue || (Ze(n, T), Ze(a, T)), !C.keepError && Ze(r.errors, T), !C.keepDirty && Ze(r.dirtyFields, T), !C.keepTouched && Ze(r.touchedFields, T), !C.keepIsValidating && Ze(r.validatingFields, T), !t.shouldUnregister && !C.keepDefaultValue && Ze(i, T);
h.state.next({
values: ze(a)
}), h.state.next({
...r,
...C.keepDirty ? { isDirty: P() } : {}
}), !C.keepIsValid && f();
}, ie = ({ disabled: y, name: C }) => {
(mt(y) && o.mount || y || s.disabled.has(C)) && (y ? s.disabled.add(C) : s.disabled.delete(C));
}, le = (y, C = {}) => {
let T = Y(n, y);
const q = mt(C.disabled) || mt(t.disabled);
return Ce(n, y, {
...T || {},
_f: {
...T && T._f ? T._f : { ref: { name: y } },
name: y,
mount: !0,
...C
}
}), s.mount.add(y), T ? ie({
disabled: mt(C.disabled) ? C.disabled : t.disabled,
name: y
}) : b(y, !0, C.value), {
...q ? { disabled: C.disabled || t.disabled } : {},
...t.progressive ? {
required: !!C.required,
min: Sn(C.min),
max: Sn(C.max),
minLength: Sn(C.minLength),
maxLength: Sn(C.maxLength),
pattern: Sn(C.pattern)
} : {},
name: y,
onChange: ge,
onBlur: ge,
ref: (R) => {
if (R) {
le(y, C), T = Y(n, y);
const I = Pe(R.value) && R.querySelectorAll && R.querySelectorAll("input,select,textarea")[0] || R, Q = Nu(I), ne = T._f.refs || [];
if (Q ? ne.find((B) => B === I) : I === T._f.ref)
return;
Ce(n, y, {
_f: {
...T._f,
...Q ? {
refs: [
...ne.filter(Ki),
I,
...Array.isArray(Y(i, y)) ? [{}] : []
],
ref: { type: I.type, name: y }
} : { ref: I }
}
}), b(y, !1, void 0, I);
} else
T = Y(n, y, {}), T._f && (T._f.mount = !1), (t.shouldUnregister || C.shouldUnregister) && !($l(s.array, y) && o.action) && s.unMount.add(y);
}
};
}, ue = () => t.shouldFocusError && en(n, pe, s.mount), Ee = (y) => {
mt(y) && (h.state.next({ disabled: y }), en(n, (C, T) => {
const q = Y(n, T);
q && (C.disabled = q._f.disabled || y, Array.isArray(q._f.refs) && q._f.refs.forEach((R) => {
R.disabled = q._f.disabled || y;
}));
}, 0, !1));
}, H = (y, C) => async (T) => {
let q;
T && (T.preventDefault && T.preventDefault(), T.persist && T.persist());
let R = ze(a);
if (h.state.next({
isSubmitting: !0
}), t.resolver) {
const { errors: I, values: Q } = await M();
r.errors = I, R = Q;
} else
await $(n);
if (s.disabled.size)
for (const I of s.disabled)
Ce(R, I, void 0);
if (Ze(r.errors, "root"), at(r.errors)) {
h.state.next({
errors: {}
});
try {
await y(R, T);
} catch (I) {
q = I;
}
} else
C && await C({ ...r.errors }, T), ue(), setTimeout(ue);
if (h.state.next({
isSubmitted: !0,
isSubmitting: !1,
isSubmitSuccessful: at(r.errors) && !q,
submitCount: r.submitCount + 1,
errors: r.errors
}), q)
throw q;
}, Me = (y, C = {}) => {
Y(n, y) && (Pe(C.defaultValue) ? ae(y, ze(Y(i, y))) : (ae(y, C.defaultValue), Ce(i, y, ze(C.defaultValue))), C.keepTouched || Ze(r.touchedFields, y), C.keepDirty || (Ze(r.dirtyFields, y), r.isDirty = C.defaultValue ? P(y, ze(Y(i, y))) : P()), C.keepError || (Ze(r.errors, y), d.isValid && f()), h.state.next({ ...r }));
}, Ge = (y, C = {}) => {
const T = y ? ze(y) : i, q = ze(T), R = at(y), I = R ? i : q;
if (C.keepDefaultValues || (i = T), !C.keepValues) {
if (C.keepDirtyValues) {
const Q = /* @__PURE__ */ new Set([
...s.mount,
...Object.keys(wn(i, a))
]);
for (const ne of Array.from(Q))
Y(r.dirtyFields, ne) ? Ce(I, ne, Y(a, ne)) : ae(ne, Y(I, ne));
} else {
if (no && Pe(y))
for (const Q of s.mount) {
const ne = Y(n, Q);
if (ne && ne._f) {
const B = Array.isArray(ne._f.refs) ? ne._f.refs[0] : ne._f.ref;
if (di(B)) {
const xe = B.closest("form");
if (xe) {
xe.reset();
break;
}
}
}
}
for (const Q of s.mount)
ae(Q, Y(I, Q));
}
a = ze(I), h.array.next({
values: { ...I }
}), h.state.next({
values: { ...I }
});
}
s = {
mount: C.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 || !!C.keepIsValid || !!C.keepDirtyValues, o.watch = !!t.shouldUnregister, h.state.next({
submitCount: C.keepSubmitCount ? r.submitCount : 0,
isDirty: R ? !1 : C.keepDirty ? r.isDirty : !!(C.keepDefaultValues && !ar(y, i)),
isSubmitted: C.keepIsSubmitted ? r.isSubmitted : !1,
dirtyFields: R ? {} : C.keepDirtyValues ? C.keepDefaultValues && a ? wn(i, a) : r.dirtyFields : C.keepDefaultValues && y ? wn(i, y) : C.keepDirty ? r.dirtyFields : {},
touchedFields: C.keepTouched ? r.touchedFields : {},
errors: C.keepErrors ? r.errors : {},
isSubmitSuccessful: C.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
isSubmitting: !1
});
}, et = (y, C) => Ge(It(y) ? y(a) : y, C), G = (y, C = {}) => {
const T = Y(n, y), q = T && T._f;
if (q) {
const R = q.refs ? q.refs[0] : q.ref;
R.focus && (R.focus(), C.shouldSelect && It(R.select) && R.select());
}
}, ce = (y) => {
r = {
...r,
...y
};
}, me = {
control: {
register: le,
unregister: X,
getFieldState: W,
handleSubmit: H,
setError: he,
_subscribe: ve,
_runSchema: M,
_focusError: ue,
_getWatch: V,
_getDirty: P,
_setValid: f,
_setFieldArray: v,
_setDisabledField: ie,
_setErrors: D,
_getFieldArray: F,
_reset: Ge,
_resetDefaultValues: () => It(t.defaultValues) && t.defaultValues().then((y) => {
et(y, t.resetOptions), h.state.next({
isLoading: !1
});
}),
_removeUnmounted: c,
_disableForm: Ee,
_subjects: h,
_proxyFormState: d,
get _fields() {
return n;
},
get _formValues() {
return a;
},
get _state() {
return o;
},
set _state(y) {
o = y;
},
get _defaultValues() {
return i;
},
get _names() {
return s;
},
set _names(y) {
s = y;
},
get _formState() {
return r;
},
get _options() {
return t;
},
set _options(y) {
t = {
...t,
...y
};
}
},
subscribe: L,
trigger: U,
register: le,
handleSubmit: H,
watch: de,
setValue: ae,
getValues: z,
reset: et,
resetField: Me,
clearErrors: fe,
unregister: X,
setError: he,
setFocus: G,
getFieldState: W
};
return {
...me,
formControl: me
};
}
var tr = () => {
if (typeof crypto < "u" && crypto.randomUUID)
return crypto.randomUUID();
const e = typeof performance > "u" ? Date.now() : performance.now() * 1e3;
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
const r = (Math.random() * 16 + e) % 16 | 0;
return (t == "x" ? r : r & 3 | 8).toString(16);
});
}, Qi = (e, t, r = {}) => r.shouldFocus || Pe(r.shouldFocus) ? r.focusName || `${e}.${Pe(r.focusIndex) ? t : r.focusIndex}.` : "", Yi = (e, t) => [
...e,
...ft(t)
], Gi = (e) => Array.isArray(e) ? e.map(() => {
}) : void 0;
function Zi(e, t, r) {
return [
...e.slice(0, t),
...ft(r),
...e.slice(t)
];
}
var Xi = (e, t, r) => Array.isArray(e) ? (Pe(e[r]) && (e[r] = void 0), e.splice(r, 0, e.splice(t, 1)[0]), e) : [], Ji = (e, t) => [
...ft(t),
...ft(e)
];
function Xu(e, t) {
let r = 0;
const n = [...e];
for (const i of t)
n.splice(i - r, 1), r++;
return $i(n).length ? n : [];
}
var ea = (e, t) => Pe(t) ? [] : Xu(e, ft(t).sort((r, n) => r - n)), ta = (e, t, r) => {
[e[t], e[r]] = [e[r], e[t]];
}, qo = (e, t, r) => (e[t] = r, e);
function Ju(e) {
const t = Di(), { control: r = t.control, name: n, keyName: i = "id", shouldUnregister: a, rules: o } = e, [s, l] = oe.useState(r._getFieldArray(n)), p = oe.useRef(r._getFieldArray(n).map(tr)), d = oe.useRef(s), u = oe.useRef(n), h = oe.useRef(!1);
u.current = n, d.current = s, r._names.array.add(n), o && r.register(n, o), Pi(() => r._subjects.array.subscribe({
next: ({ values: _, name: M }) => {
if (M === u.current || !M) {
const A = Y(_, u.current);
Array.isArray(A) && (l(A), p.current = A.map(tr));
}
}
}).unsubscribe, [r]);
const g = oe.useCallback((_) => {
h.current = !0, r._setFieldArray(n, _);
}, [r, n]), k = (_, M) => {
const A = ft(ze(_)), $ = Yi(r._getFieldArray(n), A);
r._names.focus = Qi(n, $.length - 1, M), p.current = Yi(p.current, A.map(tr)), g($), l($), r._setFieldArray(n, $, Yi, {
argA: Gi(_)
});
}, f = (_, M) => {
const A = ft(ze(_)), $ = Ji(r._getFieldArray(n), A);
r._names.focus = Qi(n, 0, M), p.current = Ji(p.current, A.map(tr)), g($), l($), r._setFieldArray(n, $, Ji, {
argA: Gi(_)
});
}, S = (_) => {
const M = ea(r._getFieldArray(n), _);
p.current = ea(p.current, _), g(M), l(M), !Array.isArray(Y(r._fields, n)) && Ce(r._fields, n, void 0), r._setFieldArray(n, M, ea, {
argA: _
});
}, v = (_, M, A) => {
const $ = ft(ze(M)), c = Zi(r._getFieldArray(n), _, $);
r._names.focus = Qi(n, _, A), p.current = Zi(p.current, _, $.map(tr)), g(c), l(c), r._setFieldArray(n, c, Zi, {
argA: _,
argB: Gi(M)
});
}, w = (_, M) => {
const A = r._getFieldArray(n);
ta(A, _, M), ta(p.current, _, M), g(A), l(A), r._setFieldArray(n, A, ta, {
argA: _,
argB: M
}, !1);
}, D = (_, M) => {
const A = r._getFieldArray(n);
Xi(A, _, M), Xi(p.current, _, M), g(A), l(A), r._setFieldArray(n, A, Xi, {
argA: _,
argB: M
}, !1);
}, b = (_, M) => {
const A = ze(M), $ = qo(r._getFieldArray(n), _, A);
p.current = [...$].map((c, P) => !c || P === _ ? tr() : p.current[P]), g($), l([...$]), r._setFieldArray(n, $, qo, {
argA: _,
argB: A
}, !0, !1);
}, x = (_) => {
const M = ft(ze(_));
p.current = M.map(tr), g([...M]), l([...M]), r._setFieldArray(n, [...M], (A) => A, {}, !0, !1);
};
return oe.useEffect(() => {
if (r._state.action = !1, xa(n, r._names) && r._subjects.state.next({
...r._formState
}), h.current && (!Zr(r._options.mode).isOnSubmit || r._formState.isSubmitted) && !Zr(r._options.reValidateMode).isOnSubmit)
if (r._options.resolver)
r._runSchema([n]).then((_) => {
const M = Y(_.errors, n), A = Y(r._formState.errors, n);
(A ? !M && A.type || M && (A.type !== M.type || A.message !== M.message) : M && M.type) && (M ? Ce(r._formState.errors, n, M) : Ze(r._formState.errors, n), r._subjects.state.next({
errors: r._formState.errors
}));
});
else {
const _ = Y(r._fields, n);
_ && _._f && !(Zr(r._options.reValidateMode).isOnSubmit && Zr(r._options.mode).isOnSubmit) && ba(_, r._names.disabled, r._formValues, r._options.criteriaMode === At.all, r._options.shouldUseNativeValidation, !0).then((M) => !at(M) && r._subjects.state.next({
errors: Wl(r._formState.errors, M, n)
}));
}
r._subjects.state.next({
name: n,
values: ze(r._formValues)
}), r._names.focus && en(r._fields, (_, M) => {
if (r._names.focus && M.startsWith(r._names.focus) && _.focus)
return _.focus(), 1;
}), r._names.focus = "", r._setValid(), h.current = !1;
}, [s, n, r]), oe.useEffect(() => (!Y(r._formValues, n) && r._setFieldArray(n), () => {
const _ = (M, A) => {
const $ = Y(r._fields, M);
$ && $._f && ($._f.mount = A);
};
r._options.shouldUnregister || a ? r.unregister(n) : _(n, !1);
}), [n, r, i, a]), {
swap: oe.useCallback(w, [g, n, r]),
move: oe.useCallback(D, [g, n, r]),
prepend: oe.useCallback(f, [g, n, r]),
append: oe.useCallback(k, [g, n, r]),
remove: oe.useCallback(S, [g, n, r]),
insert: oe.useCallback(v, [g, n, r]),
update: oe.useCallback(b, [g, n, r]),
replace: oe.useCallback(x, [g, n, r]),
fields: oe.useMemo(() => s.map((_, M) => ({
..._,
[i]: p.current[M] || tr()
})), [s, i])
};
}
function ep(e = {}) {
const t = oe.useRef(void 0), r = oe.useRef(void 0), [n, i] = oe.useState({
isDirty: !1,
isValidating: !1,
isLoading: It(e.defaultValues),
isSubmitted: !1,
isSubmitting: !1,
isSubmitSuccessful: !1,
isValid: !1,
submitCount: 0,
dirtyFields: {},
touchedFields: {},
validatingFields: {},
errors: e.errors || {},
disabled: e.disabled || !1,
isReady: !1,
defaultValues: It(e.defaultValues) ? void 0 : e.defaultValues
});
if (!t.current)
if (e.formControl)
t.current = {
...e.formControl,
formState: n
}, e.defaultValues && !It(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
else {
const { formControl: o, ...s } = Zu(e);
t.current = {
...s,
formState: n
};
}
const a = t.current.control;
return a._options = e, Pi(() => {
const o = a._subscribe({
formState: a._proxyFormState,
callback: () => i({ ...a._formState }),
reRenderRoot: !0
});
return i((s) => ({
...s,
isReady: !0
})), a._formState.isReady = !0, o;
}, [a]), oe.useEffect(() => a._disableForm(e.disabled), [a, e.disabled]), oe.useEffect(() => {
e.mode && (a._options.mode = e.mode), e.reValidateMode && (a._options.reValidateMode = e.reValidateMode);
}, [a, e.mode, e.reValidateMode]), oe.useEffect(() => {
e.errors && (a._setErrors(e.errors), a._focusError());
}, [a, e.errors]), oe.useEffect(() => {
e.shouldUnregister && a._subjects.state.next({
values: a._getWatch()
});
}, [a, e.shouldUnregister]), oe.useEffect(() => {
if (a._proxyFormState.isDirty) {
const o = a._getDirty();
o !== n.isDirty && a._subjects.state.next({
isDirty: o
});
}
}, [a, n.isDirty]), oe.useEffect(() => {
e.values && !ar(e.values, r.current) ? (a._reset(e.values, a._options.resetOptions), r.current = e.values, i((o) => ({ ...o }))) : a._resetDefaultValues();
}, [a, e.values]), oe.useEffect(() => {
a._state.mount || (a._setValid(), a._state.mount = !0), a._state.watch && (a._state.watch = !1, a._subjects.state.next({ ...a._formState })), a._removeUnmounted();
}), t.current.formState = Pl(n, a), t.current;
}
const Wo = (e, t, r) => {
if (e && "reportValidity" in e) {
const n = Y(r, t);
e.setCustomValidity(n && n.message || ""), e.reportValidity();
}
}, Ul = (e, t) => {
for (const r in t.fields) {
const n = t.fields[r];
n && n.ref && "reportValidity" in n.ref ? Wo(n.ref, r, e) : n && n.refs && n.refs.forEach((i) => Wo(i, r, e));
}
}, tp = (e, t) => {
t.shouldUseNativeValidation && Ul(e, t);
const r = {};
for (const n in e) {
const i = Y(t.fields, n), a = Object.assign(e[n] || {}, { ref: i && i.ref });
if (rp(t.names || Object.keys(e), n)) {
const o = Object.assign({}, Y(r, n));
Ce(o, "root", a), Ce(r, n, o);
} else Ce(r, n, a);
}
return r;
}, rp = (e, t) => {
const r = Uo(t);
return e.some((n) => Uo(n).match(`^${r}\\.\\d+`));
};
function Uo(e) {
return e.replace(/\]|\[/g, "");
}
function np(e, t, r) {
return r === void 0 && (r = {}), function(n, i, a) {
try {
return Promise.resolve(function(o, s) {
try {
var l = (t != null && t.context && process.env.NODE_ENV === "development" && console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"), Promise.resolve(e[r.mode === "sync" ? "validateSync" : "validate"](n, Object.assign({ abortEarly: !1 }, t, { context: i }))).then(function(p) {
return a.shouldUseNativeValidation && Ul({}, a), { values: r.raw ? Object.assign({}, n) : p, errors: {} };
}));
} catch (p) {
return s(p);
}
return l && l.then ? l.then(void 0, s) : l;
}(0, function(o) {
if (!o.inner) throw o;
return { values: {}, errors: tp((s = o, l = !a.shouldUseNativeValidation && a.criteriaMode === "all", (s.inner || []).reduce(function(p, d) {
if (p[d.path] || (p[d.path] = { message: d.message, type: d.type }), l) {
var u = p[d.path].types, h = u && u[d.type];
p[d.path] = jl(d.path, l, p, d.type, h ? [].concat(h, d.message) : d.message);
}
return p;
}, {})), a) };
var s, l;
}));
} catch (o) {
return Promise.reject(o);
}
};
}
var Nn = class {
constructor() {
this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
}
subscribe(e) {
return this.listeners.add(e), this.onSubscribe(), () => {
this.listeners.delete(e), this.onUnsubscribe();
};
}
hasListeners() {
return this.listeners.size > 0;
}
onSubscribe() {
}
onUnsubscribe() {
}
}, Mr = typeof window > "u" || "Deno" in globalThis;
function pt() {
}
function ip(e, t) {
return typeof e == "function" ? e(t) : e;
}
function wa(e) {
return typeof e == "number" && e >= 0 && e !== 1 / 0;
}
function Hl(e, t) {
return Math.max(e + (t || 0) - Date.now(), 0);
}
function gr(e, t) {
return typeof e == "function" ? e(t) : e;
}
function kt(e, t) {
return typeof e == "function" ? e(t) : e;
}
function Ho(e, t) {
const {
type: r = "all",
exact: n,
fetchStatus: i,
predicate: a,
queryKey: o,
stale: s
} = e;
if (o) {
if (n) {
if (t.queryHash !== so(o, t.options))
return !1;
} else if (!Rn(t.queryKey, o))
return !1;
}
if (r !== "all") {
const l = t.isActive();
if (r === "active" && !l || r === "inactive" && l)
return !1;
}
return !(typeof s == "boolean" && t.isStale() !== s || i && i !== t.state.fetchStatus || a && !a(t));
}
function Ko(e, t) {
const { exact: r, status: n, predicate: i, mutationKey: a } = e;
if (a) {
if (!t.options.mutationKey)
return !1;
if (r) {
if (_n(t.options.mutationKey) !== _n(a))
return !1;
} else if (!Rn(t.options.mutationKey, a))
return !1;
}
return !(n && t.state.status !== n || i && !i(t));
}
function so(e, t) {
return ((t == null ? void 0 : t.queryKeyHashFn) || _n)(e);
}
function _n(e) {
return JSON.stringify(
e,
(t, r) => Ea(r) ? Object.keys(r).sort().reduce((n, i) => (n[i] = r[i], n), {}) : r
);
}
function Rn(e, t) {
return e === t ? !0 : typeof e != typeof t ? !1 : e && t && typeof e == "object" && typeof t == "object" ? Object.keys(t).every((r) => Rn(e[r], t[r])) : !1;
}
function Sa(e, t) {
if (e === t)
return e;
const r = Qo(e) && Qo(t);
if (r || Ea(e) && Ea(t)) {
const n = r ? e : Object.keys(e), i = n.length, a = r ? t : Object.keys(t), o = a.length, s = r ? [] : {}, l = new Set(n);
let p = 0;
for (let d = 0; d < o; d++) {
const u = r ? d : a[d];
(!r && l.has(u) || r) && e[u] === void 0 && t[u] === void 0 ? (s[u] = void 0, p++) : (s[u] = Sa(e[u], t[u]), s[u] === e[u] && e[u] !== void 0 && p++);
}
return i === o && p === i ? e : s;
}
return t;
}
function Ca(e, t) {
if (!t || Object.keys(e).length !== Object.keys(t).length)
return !1;
for (const r in e)
if (e[r] !== t[r])
return !1;
return !0;
}
function Qo(e) {
return Array.isArray(e) && e.length === Object.keys(e).length;
}
function Ea(e) {
if (!Yo(e))
return !1;
const t = e.constructor;
if (t === void 0)
return !0;
const r = t.prototype;
return !(!Yo(r) || !r.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
}
function Yo(e) {
return Object.prototype.toString.call(e) === "[object Object]";
}
function ap(e) {
return new Promise((t) => {
setTimeout(t, e);
});
}
function ka(e, t, r) {
if (typeof r.structuralSharing == "function")
return r.structuralSharing(e, t);
if (r.structuralSharing !== !1) {
if (process.env.NODE_ENV !== "production")
try {
return Sa(e, t);
} catch (n) {
throw console.error(
`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or