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 • 579 kB
JavaScript
var yu = Object.defineProperty;
var Lo = (e) => {
throw TypeError(e);
};
var vu = (e, t, r) => t in e ? yu(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
var Cn = (e, t, r) => vu(e, typeof t != "symbol" ? t + "" : t, r), Xi = (e, t, r) => t.has(e) || Lo("Cannot " + r);
var F = (e, t, r) => (Xi(e, t, "read from private field"), r ? r.call(e) : t.get(e)), ye = (e, t, r) => t.has(e) ? Lo("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), se = (e, t, r, n) => (Xi(e, t, "write to private field"), n ? n.call(e, r) : t.set(e, r), r), be = (e, t, r) => (Xi(e, t, "access private method"), r);
var Qn = (e, t, r, n) => ({
set _(i) {
se(e, t, i, r);
},
get _() {
return F(e, t, n);
}
});
import { jsx as p, jsxs as te, Fragment as Ii } from "react/jsx-runtime";
import * as ae from "react";
import ce, { isValidElement as oi, cloneElement as si, Children as xu, useState as Ft, useMemo as Xe, useRef as bt, useEffect as Rt, useCallback as Fe, useReducer as bu, forwardRef as wu, useImperativeHandle as Su, Fragment as Cu, createElement as Eu } from "react";
import { InputAdornment as ku, Box as K, Typography as he, TextField as Mi, FormControl as oo, InputLabel as Tu, Select as Au, MenuItem as Bo, CircularProgress as xn, OutlinedInput as Ou, FormHelperText as so, Autocomplete as Fu, Checkbox as $n, FormControlLabel as nn, FormLabel as Pl, Switch as Dl, RadioGroup as _u, Radio as Ru, Divider as lo, Button as Ge, Chip as co, StepConnector as Il, stepConnectorClasses as gr, Stepper as Ml, Step as jl, StepLabel as zl, Card as mt, List as qo, ListItem as Wo, ListItemText as Uo, Tabs as $u, Tab as Pu, TableContainer as Du, Table as Iu, TableHead as Mu, TableRow as Ho, TableCell as Ur, TableBody as ju, IconButton as ji, CardContent as zu, Tooltip as li, Dialog as Vu, DialogTitle as Nu, DialogContent as Lu, DialogActions as Bu, LinearProgress as qu, ButtonGroup as Wu, createTheme as Uu, ThemeProvider as Hu, Paper as Ku, Alert as Yu } from "@mui/material";
import Qu from "@emotion/styled";
import { ThemeContext as Gu, keyframes as Bn, css as Vl } from "@emotion/react";
var qn = (e) => e.type === "checkbox", Or = (e) => e instanceof Date, lt = (e) => e == null;
const Nl = (e) => typeof e == "object";
var Ue = (e) => !lt(e) && !Array.isArray(e) && Nl(e) && !Or(e), Ll = (e) => Ue(e) && e.target ? qn(e.target) ? e.target.checked : e.target.value : e, Zu = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, Bl = (e, t) => e.has(Zu(t)), Xu = (e) => {
const t = e.constructor && e.constructor.prototype;
return Ue(t) && t.hasOwnProperty("isPrototypeOf");
}, uo = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
function Me(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 (!(uo && (e instanceof Blob || n)) && (r || Ue(e)))
if (t = r ? [] : {}, !r && !Xu(e))
t = e;
else
for (const i in e)
e.hasOwnProperty(i) && (t[i] = Me(e[i]));
else
return e;
return t;
}
var zi = (e) => /^\w*$/.test(e), $e = (e) => e === void 0, Vi = (e) => Array.isArray(e) ? e.filter(Boolean) : [], po = (e) => Vi(e.replace(/["|']|\]/g, "").split(/\.|\[/)), ee = (e, t, r) => {
if (!t || !Ue(e))
return r;
const n = (zi(t) ? [t] : po(t)).reduce((i, a) => lt(i) ? i : i[a], e);
return $e(n) || n === e ? $e(e[t]) ? r : e[t] : n;
}, xt = (e) => typeof e == "boolean", Ce = (e, t, r) => {
let n = -1;
const i = zi(t) ? [t] : po(t), a = i.length, o = a - 1;
for (; ++n < a; ) {
const s = i[n];
let l = r;
if (n !== o) {
const u = e[s];
l = Ue(u) || Array.isArray(u) ? u : isNaN(+i[n + 1]) ? {} : [];
}
if (s === "__proto__" || s === "constructor" || s === "prototype")
return;
e[s] = l, e = e[s];
}
};
const gi = {
BLUR: "blur",
FOCUS_OUT: "focusout",
CHANGE: "change"
}, _t = {
onBlur: "onBlur",
onChange: "onChange",
onSubmit: "onSubmit",
onTouched: "onTouched",
all: "all"
}, Yt = {
max: "max",
min: "min",
maxLength: "maxLength",
minLength: "minLength",
pattern: "pattern",
required: "required",
validate: "validate"
}, ql = ce.createContext(null);
ql.displayName = "HookFormContext";
const Ni = () => ce.useContext(ql);
var Wl = (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] !== _t.all && (t._proxyFormState[o] = !n || _t.all), r && (r[o] = !0), e[o];
}
});
return i;
};
const Li = typeof window < "u" ? ae.useLayoutEffect : ae.useEffect;
function Ju(e) {
const t = Ni(), { control: r = t.control, disabled: n, name: i, exact: a } = e || {}, [o, s] = ce.useState(r._formState), l = ce.useRef({
isDirty: !1,
isLoading: !1,
dirtyFields: !1,
touchedFields: !1,
validatingFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
});
return Li(() => r._subscribe({
name: i,
formState: l.current,
exact: a,
callback: (u) => {
!n && s({
...r._formState,
...u
});
}
}), [i, n, a]), ce.useEffect(() => {
l.current.isValid && r._setValid(!0);
}, [r]), ce.useMemo(() => Wl(o, r, l.current, !1), [o, r]);
}
var Kt = (e) => typeof e == "string", Ul = (e, t, r, n, i) => Kt(e) ? (n && t.watch.add(e), ee(r, e, i)) : Array.isArray(e) ? e.map((a) => (n && t.watch.add(a), ee(r, a))) : (n && (t.watchAll = !0), r);
function Hl(e) {
const t = Ni(), { control: r = t.control, name: n, defaultValue: i, disabled: a, exact: o } = e || {}, s = ce.useRef(i), [l, u] = ce.useState(r._getWatch(n, s.current));
return Li(() => r._subscribe({
name: n,
formState: {
values: !0
},
exact: o,
callback: (d) => !a && u(Ul(n, r._names, d.values || r._formValues, !1, s.current))
}), [n, r, a, o]), ce.useEffect(() => r._removeUnmounted()), l;
}
function ep(e) {
const t = Ni(), { name: r, disabled: n, control: i = t.control, shouldUnregister: a } = e, o = Bl(i._names.array, r), s = Hl({
control: i,
name: r,
defaultValue: ee(i._formValues, r, ee(i._defaultValues, r, e.defaultValue)),
exact: !0
}), l = Ju({
control: i,
name: r,
exact: !0
}), u = ce.useRef(e), d = ce.useRef(i.register(r, {
...e.rules,
value: s,
...xt(e.disabled) ? { disabled: e.disabled } : {}
})), f = ce.useMemo(() => Object.defineProperties({}, {
invalid: {
enumerable: !0,
get: () => !!ee(l.errors, r)
},
isDirty: {
enumerable: !0,
get: () => !!ee(l.dirtyFields, r)
},
isTouched: {
enumerable: !0,
get: () => !!ee(l.touchedFields, r)
},
isValidating: {
enumerable: !0,
get: () => !!ee(l.validatingFields, r)
},
error: {
enumerable: !0,
get: () => ee(l.errors, r)
}
}), [l, r]), c = ce.useCallback((w) => d.current.onChange({
target: {
value: Ll(w),
name: r
},
type: gi.CHANGE
}), [r]), y = ce.useCallback(() => d.current.onBlur({
target: {
value: ee(i._formValues, r),
name: r
},
type: gi.BLUR
}), [r, i._formValues]), C = ce.useCallback((w) => {
const v = ee(i._fields, r);
v && w && (v._f.ref = {
focus: () => w.focus && w.focus(),
select: () => w.select && w.select(),
setCustomValidity: (T) => w.setCustomValidity(T),
reportValidity: () => w.reportValidity()
});
}, [i._fields, r]), m = ce.useMemo(() => ({
name: r,
value: s,
...xt(n) || l.disabled ? { disabled: l.disabled || n } : {},
onChange: c,
onBlur: y,
ref: C
}), [r, n, l.disabled, c, y, C, s]);
return ce.useEffect(() => {
const w = i._options.shouldUnregister || a;
i.register(r, {
...u.current.rules,
...xt(u.current.disabled) ? { disabled: u.current.disabled } : {}
});
const v = (T, P) => {
const A = ee(i._fields, T);
A && A._f && (A._f.mount = P);
};
if (v(r, !0), w) {
const T = Me(ee(i._options.defaultValues, r));
Ce(i._defaultValues, r, T), $e(ee(i._formValues, r)) && Ce(i._formValues, r, T);
}
return !o && i.register(r), () => {
(o ? w && !i._state.action : w) ? i.unregister(r) : v(r, !1);
};
}, [r, i, o, a]), ce.useEffect(() => {
i._setDisabledField({
disabled: n,
name: r
});
}, [n, r, i]), ce.useMemo(() => ({
field: m,
formState: l,
fieldState: f
}), [m, l, f]);
}
const Ie = (e) => e.render(ep(e));
var Kl = (e, t, r, n, i) => t ? {
...r[e],
types: {
...r[e] && r[e].types ? r[e].types : {},
[n]: i || !0
}
} : {}, gt = (e) => Array.isArray(e) ? e : [e], Ko = () => {
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 = [];
}
};
}, Ta = (e) => lt(e) || !Nl(e);
function sr(e, t) {
if (Ta(e) || Ta(t))
return e === t;
if (Or(e) && Or(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 (Or(a) && Or(o) || Ue(a) && Ue(o) || Array.isArray(a) && Array.isArray(o) ? !sr(a, o) : a !== o)
return !1;
}
}
return !0;
}
var st = (e) => Ue(e) && !Object.keys(e).length, fo = (e) => e.type === "file", zt = (e) => typeof e == "function", yi = (e) => {
if (!uo)
return !1;
const t = e ? e.ownerDocument : 0;
return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
}, Yl = (e) => e.type === "select-multiple", ho = (e) => e.type === "radio", tp = (e) => ho(e) || qn(e), Ji = (e) => yi(e) && e.isConnected;
function rp(e, t) {
const r = t.slice(0, -1).length;
let n = 0;
for (; n < r; )
e = $e(e) ? n++ : e[t[n++]];
return e;
}
function np(e) {
for (const t in e)
if (e.hasOwnProperty(t) && !$e(e[t]))
return !1;
return !0;
}
function Qe(e, t) {
const r = Array.isArray(t) ? t : zi(t) ? [t] : po(t), n = r.length === 1 ? e : rp(e, r), i = r.length - 1, a = r[i];
return n && delete n[a], i !== 0 && (Ue(n) && st(n) || Array.isArray(n) && np(n)) && Qe(e, r.slice(0, -1)), e;
}
var Ql = (e) => {
for (const t in e)
if (zt(e[t]))
return !0;
return !1;
};
function vi(e, t = {}) {
const r = Array.isArray(e);
if (Ue(e) || r)
for (const n in e)
Array.isArray(e[n]) || Ue(e[n]) && !Ql(e[n]) ? (t[n] = Array.isArray(e[n]) ? [] : {}, vi(e[n], t[n])) : lt(e[n]) || (t[n] = !0);
return t;
}
function Gl(e, t, r) {
const n = Array.isArray(e);
if (Ue(e) || n)
for (const i in e)
Array.isArray(e[i]) || Ue(e[i]) && !Ql(e[i]) ? $e(t) || Ta(r[i]) ? r[i] = Array.isArray(e[i]) ? vi(e[i], []) : { ...vi(e[i]) } : Gl(e[i], lt(t) ? {} : t[i], r[i]) : r[i] = !sr(e[i], t[i]);
return r;
}
var En = (e, t) => Gl(e, t, vi(t));
const Yo = {
value: !1,
isValid: !1
}, Qo = { value: !0, isValid: !0 };
var Zl = (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 && !$e(e[0].attributes.value) ? $e(e[0].value) || e[0].value === "" ? Qo : { value: e[0].value, isValid: !0 } : Qo
) : Yo;
}
return Yo;
}, Xl = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: n }) => $e(e) ? e : t ? e === "" ? NaN : e && +e : r && Kt(e) ? new Date(e) : n ? n(e) : e;
const Go = {
isValid: !1,
value: null
};
var Jl = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
isValid: !0,
value: r.value
} : t, Go) : Go;
function Zo(e) {
const t = e.ref;
return fo(t) ? t.files : ho(t) ? Jl(e.refs).value : Yl(t) ? [...t.selectedOptions].map(({ value: r }) => r) : qn(t) ? Zl(e.refs).value : Xl($e(t.value) ? e.ref.value : t.value, e);
}
var ip = (e, t, r, n) => {
const i = {};
for (const a of e) {
const o = ee(t, a);
o && Ce(i, a, o._f);
}
return {
criteriaMode: r,
names: [...e],
fields: i,
shouldUseNativeValidation: n
};
}, xi = (e) => e instanceof RegExp, kn = (e) => $e(e) ? e : xi(e) ? e.source : Ue(e) ? xi(e.value) ? e.value.source : e.value : e, en = (e) => ({
isOnSubmit: !e || e === _t.onSubmit,
isOnBlur: e === _t.onBlur,
isOnChange: e === _t.onChange,
isOnAll: e === _t.all,
isOnTouch: e === _t.onTouched
});
const Xo = "AsyncFunction";
var ap = (e) => !!e && !!e.validate && !!(zt(e.validate) && e.validate.constructor.name === Xo || Ue(e.validate) && Object.values(e.validate).find((t) => t.constructor.name === Xo)), op = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), Aa = (e, t, r) => !r && (t.watchAll || t.watch.has(e) || [...t.watch].some((n) => e.startsWith(n) && /^\.\w+/.test(e.slice(n.length))));
const an = (e, t, r, n) => {
for (const i of r || Object.keys(e)) {
const a = ee(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 (an(s, t))
break;
} else if (Ue(s) && an(s, t))
break;
}
}
};
function Jo(e, t, r) {
const n = ee(e, r);
if (n || zi(r))
return {
error: n,
name: r
};
const i = r.split(".");
for (; i.length; ) {
const a = i.join("."), o = ee(t, a), s = ee(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 sp = (e, t, r, n) => {
r(e);
const { name: i, ...a } = e;
return st(a) || Object.keys(a).length >= Object.keys(t).length || Object.keys(a).find((o) => t[o] === (!n || _t.all));
}, lp = (e, t, r) => !e || !t || e === t || gt(e).some((n) => n && (r ? n === t : n.startsWith(t) || t.startsWith(n))), cp = (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, up = (e, t) => !Vi(ee(e, t)).length && Qe(e, t), ec = (e, t, r) => {
const n = gt(ee(e, r));
return Ce(n, "root", t[r]), Ce(e, r, n), e;
}, ci = (e) => Kt(e);
function es(e, t, r = "validate") {
if (ci(e) || Array.isArray(e) && e.every(ci) || xt(e) && !e)
return {
type: r,
message: ci(e) ? e : "",
ref: t
};
}
var Hr = (e) => Ue(e) && !xi(e) ? e : {
value: e,
message: ""
}, Oa = async (e, t, r, n, i, a) => {
const { ref: o, refs: s, required: l, maxLength: u, minLength: d, min: f, max: c, pattern: y, validate: C, name: m, valueAsNumber: w, mount: v } = e._f, T = ee(r, m);
if (!v || t.has(m))
return {};
const P = s ? s[0] : o, A = (L) => {
i && P.reportValidity && (P.setCustomValidity(xt(L) ? "" : L || ""), P.reportValidity());
}, S = {}, _ = ho(o), D = qn(o), R = _ || D, H = (w || fo(o)) && $e(o.value) && $e(T) || yi(o) && o.value === "" || T === "" || Array.isArray(T) && !T.length, h = Kl.bind(null, m, n, S), j = (L, G, N, W = Yt.maxLength, Y = Yt.minLength) => {
const ne = L ? G : N;
S[m] = {
type: L ? W : Y,
message: ne,
ref: o,
...h(L ? W : Y, ne)
};
};
if (a ? !Array.isArray(T) || !T.length : l && (!R && (H || lt(T)) || xt(T) && !T || D && !Zl(s).isValid || _ && !Jl(s).isValid)) {
const { value: L, message: G } = ci(l) ? { value: !!l, message: l } : Hr(l);
if (L && (S[m] = {
type: Yt.required,
message: G,
ref: P,
...h(Yt.required, G)
}, !n))
return A(G), S;
}
if (!H && (!lt(f) || !lt(c))) {
let L, G;
const N = Hr(c), W = Hr(f);
if (!lt(T) && !isNaN(T)) {
const Y = o.valueAsNumber || T && +T;
lt(N.value) || (L = Y > N.value), lt(W.value) || (G = Y < W.value);
} else {
const Y = o.valueAsDate || new Date(T), ne = (q) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + q), pe = o.type == "time", $ = o.type == "week";
Kt(N.value) && T && (L = pe ? ne(T) > ne(N.value) : $ ? T > N.value : Y > new Date(N.value)), Kt(W.value) && T && (G = pe ? ne(T) < ne(W.value) : $ ? T < W.value : Y < new Date(W.value));
}
if ((L || G) && (j(!!L, N.message, W.message, Yt.max, Yt.min), !n))
return A(S[m].message), S;
}
if ((u || d) && !H && (Kt(T) || a && Array.isArray(T))) {
const L = Hr(u), G = Hr(d), N = !lt(L.value) && T.length > +L.value, W = !lt(G.value) && T.length < +G.value;
if ((N || W) && (j(N, L.message, G.message), !n))
return A(S[m].message), S;
}
if (y && !H && Kt(T)) {
const { value: L, message: G } = Hr(y);
if (xi(L) && !T.match(L) && (S[m] = {
type: Yt.pattern,
message: G,
ref: o,
...h(Yt.pattern, G)
}, !n))
return A(G), S;
}
if (C) {
if (zt(C)) {
const L = await C(T, r), G = es(L, P);
if (G && (S[m] = {
...G,
...h(Yt.validate, G.message)
}, !n))
return A(G.message), S;
} else if (Ue(C)) {
let L = {};
for (const G in C) {
if (!st(L) && !n)
break;
const N = es(await C[G](T, r), P, G);
N && (L = {
...N,
...h(G, N.message)
}, A(N.message), n && (S[m] = L));
}
if (!st(L) && (S[m] = {
ref: P,
...L
}, !n))
return S;
}
}
return A(!0), S;
};
const pp = {
mode: _t.onSubmit,
reValidateMode: _t.onChange,
shouldFocusError: !0
};
function dp(e = {}) {
let t = {
...pp,
...e
}, r = {
submitCount: 0,
isDirty: !1,
isReady: !1,
isLoading: zt(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 = Ue(t.defaultValues) || Ue(t.values) ? Me(t.defaultValues || t.values) || {} : {}, a = t.shouldUnregister ? {} : Me(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, u = 0;
const d = {
isDirty: !1,
dirtyFields: !1,
validatingFields: !1,
touchedFields: !1,
isValidating: !1,
isValid: !1,
errors: !1
};
let f = {
...d
};
const c = {
array: Ko(),
state: Ko()
}, y = t.criteriaMode === _t.all, C = (b) => (k) => {
clearTimeout(u), u = setTimeout(b, k);
}, m = async (b) => {
if (!t.disabled && (d.isValid || f.isValid || b)) {
const k = t.resolver ? st((await D()).errors) : await H(n, !0);
k !== r.isValid && c.state.next({
isValid: k
});
}
}, w = (b, k) => {
!t.disabled && (d.isValidating || d.validatingFields || f.isValidating || f.validatingFields) && ((b || Array.from(s.mount)).forEach((g) => {
g && (k ? Ce(r.validatingFields, g, k) : Qe(r.validatingFields, g));
}), c.state.next({
validatingFields: r.validatingFields,
isValidating: !st(r.validatingFields)
}));
}, v = (b, k = [], g, I, x = !0, O = !0) => {
if (I && g && !t.disabled) {
if (o.action = !0, O && Array.isArray(ee(n, b))) {
const z = g(ee(n, b), I.argA, I.argB);
x && Ce(n, b, z);
}
if (O && Array.isArray(ee(r.errors, b))) {
const z = g(ee(r.errors, b), I.argA, I.argB);
x && Ce(r.errors, b, z), up(r.errors, b);
}
if ((d.touchedFields || f.touchedFields) && O && Array.isArray(ee(r.touchedFields, b))) {
const z = g(ee(r.touchedFields, b), I.argA, I.argB);
x && Ce(r.touchedFields, b, z);
}
(d.dirtyFields || f.dirtyFields) && (r.dirtyFields = En(i, a)), c.state.next({
name: b,
isDirty: j(b, k),
dirtyFields: r.dirtyFields,
errors: r.errors,
isValid: r.isValid
});
} else
Ce(a, b, k);
}, T = (b, k) => {
Ce(r.errors, b, k), c.state.next({
errors: r.errors
});
}, P = (b) => {
r.errors = b, c.state.next({
errors: r.errors,
isValid: !1
});
}, A = (b, k, g, I) => {
const x = ee(n, b);
if (x) {
const O = ee(a, b, $e(g) ? ee(i, b) : g);
$e(O) || I && I.defaultChecked || k ? Ce(a, b, k ? O : Zo(x._f)) : N(b, O), o.mount && m();
}
}, S = (b, k, g, I, x) => {
let O = !1, z = !1;
const M = {
name: b
};
if (!t.disabled) {
if (!g || I) {
(d.isDirty || f.isDirty) && (z = r.isDirty, r.isDirty = M.isDirty = j(), O = z !== M.isDirty);
const U = sr(ee(i, b), k);
z = !!ee(r.dirtyFields, b), U ? Qe(r.dirtyFields, b) : Ce(r.dirtyFields, b, !0), M.dirtyFields = r.dirtyFields, O = O || (d.dirtyFields || f.dirtyFields) && z !== !U;
}
if (g) {
const U = ee(r.touchedFields, b);
U || (Ce(r.touchedFields, b, g), M.touchedFields = r.touchedFields, O = O || (d.touchedFields || f.touchedFields) && U !== g);
}
O && x && c.state.next(M);
}
return O ? M : {};
}, _ = (b, k, g, I) => {
const x = ee(r.errors, b), O = (d.isValid || f.isValid) && xt(k) && r.isValid !== k;
if (t.delayError && g ? (l = C(() => T(b, g)), l(t.delayError)) : (clearTimeout(u), l = null, g ? Ce(r.errors, b, g) : Qe(r.errors, b)), (g ? !sr(x, g) : x) || !st(I) || O) {
const z = {
...I,
...O && xt(k) ? { isValid: k } : {},
errors: r.errors,
name: b
};
r = {
...r,
...z
}, c.state.next(z);
}
}, D = async (b) => {
w(b, !0);
const k = await t.resolver(a, t.context, ip(b || s.mount, n, t.criteriaMode, t.shouldUseNativeValidation));
return w(b), k;
}, R = async (b) => {
const { errors: k } = await D(b);
if (b)
for (const g of b) {
const I = ee(k, g);
I ? Ce(r.errors, g, I) : Qe(r.errors, g);
}
else
r.errors = k;
return k;
}, H = async (b, k, g = {
valid: !0
}) => {
for (const I in b) {
const x = b[I];
if (x) {
const { _f: O, ...z } = x;
if (O) {
const M = s.array.has(O.name), U = x._f && ap(x._f);
U && d.validatingFields && w([I], !0);
const me = await Oa(x, s.disabled, a, y, t.shouldUseNativeValidation && !k, M);
if (U && d.validatingFields && w([I]), me[O.name] && (g.valid = !1, k))
break;
!k && (ee(me, O.name) ? M ? ec(r.errors, me, O.name) : Ce(r.errors, O.name, me[O.name]) : Qe(r.errors, O.name));
}
!st(z) && await H(z, k, g);
}
}
return g.valid;
}, h = () => {
for (const b of s.unMount) {
const k = ee(n, b);
k && (k._f.refs ? k._f.refs.every((g) => !Ji(g)) : !Ji(k._f.ref)) && Q(b);
}
s.unMount = /* @__PURE__ */ new Set();
}, j = (b, k) => !t.disabled && (b && k && Ce(a, b, k), !sr(q(), i)), L = (b, k, g) => Ul(b, s, {
...o.mount ? a : $e(k) ? i : Kt(b) ? { [b]: k } : k
}, g, k), G = (b) => Vi(ee(o.mount ? a : i, b, t.shouldUnregister ? ee(i, b, []) : [])), N = (b, k, g = {}) => {
const I = ee(n, b);
let x = k;
if (I) {
const O = I._f;
O && (!O.disabled && Ce(a, b, Xl(k, O)), x = yi(O.ref) && lt(k) ? "" : k, Yl(O.ref) ? [...O.ref.options].forEach((z) => z.selected = x.includes(z.value)) : O.refs ? qn(O.ref) ? O.refs.forEach((z) => {
(!z.defaultChecked || !z.disabled) && (Array.isArray(x) ? z.checked = !!x.find((M) => M === z.value) : z.checked = x === z.value || !!x);
}) : O.refs.forEach((z) => z.checked = z.value === x) : fo(O.ref) ? O.ref.value = "" : (O.ref.value = x, O.ref.type || c.state.next({
name: b,
values: Me(a)
})));
}
(g.shouldDirty || g.shouldTouch) && S(b, x, g.shouldTouch, g.shouldDirty, !0), g.shouldValidate && $(b);
}, W = (b, k, g) => {
for (const I in k) {
if (!k.hasOwnProperty(I))
return;
const x = k[I], O = b + "." + I, z = ee(n, O);
(s.array.has(b) || Ue(x) || z && !z._f) && !Or(x) ? W(O, x, g) : N(O, x, g);
}
}, Y = (b, k, g = {}) => {
const I = ee(n, b), x = s.array.has(b), O = Me(k);
Ce(a, b, O), x ? (c.array.next({
name: b,
values: Me(a)
}), (d.isDirty || d.dirtyFields || f.isDirty || f.dirtyFields) && g.shouldDirty && c.state.next({
name: b,
dirtyFields: En(i, a),
isDirty: j(b, O)
})) : I && !I._f && !lt(O) ? W(b, O, g) : N(b, O, g), Aa(b, s) && c.state.next({ ...r }), c.state.next({
name: o.mount ? b : void 0,
values: Me(a)
});
}, ne = async (b) => {
o.mount = !0;
const k = b.target;
let g = k.name, I = !0;
const x = ee(n, g), O = (U) => {
I = Number.isNaN(U) || Or(U) && isNaN(U.getTime()) || sr(U, ee(a, g, U));
}, z = en(t.mode), M = en(t.reValidateMode);
if (x) {
let U, me;
const xe = k.type ? Zo(x._f) : Ll(b), ve = b.type === gi.BLUR || b.type === gi.FOCUS_OUT, We = !op(x._f) && !t.resolver && !ee(r.errors, g) && !x._f.deps || cp(ve, ee(r.touchedFields, g), r.isSubmitted, M, z), Pe = Aa(g, s, ve);
Ce(a, g, xe), ve ? (x._f.onBlur && x._f.onBlur(b), l && l(0)) : x._f.onChange && x._f.onChange(b);
const ut = S(g, xe, ve), vt = !st(ut) || Pe;
if (!ve && c.state.next({
name: g,
type: b.type,
values: Me(a)
}), We)
return (d.isValid || f.isValid) && (t.mode === "onBlur" ? ve && m() : ve || m()), vt && c.state.next({ name: g, ...Pe ? {} : ut });
if (!ve && Pe && c.state.next({ ...r }), t.resolver) {
const { errors: Ne } = await D([g]);
if (O(xe), I) {
const ie = Jo(r.errors, n, g), et = Jo(Ne, n, ie.name || g);
U = et.error, g = et.name, me = st(Ne);
}
} else
w([g], !0), U = (await Oa(x, s.disabled, a, y, t.shouldUseNativeValidation))[g], w([g]), O(xe), I && (U ? me = !1 : (d.isValid || f.isValid) && (me = await H(n, !0)));
I && (x._f.deps && $(x._f.deps), _(g, me, U, ut));
}
}, pe = (b, k) => {
if (ee(r.errors, k) && b.focus)
return b.focus(), 1;
}, $ = async (b, k = {}) => {
let g, I;
const x = gt(b);
if (t.resolver) {
const O = await R($e(b) ? b : x);
g = st(O), I = b ? !x.some((z) => ee(O, z)) : g;
} else b ? (I = (await Promise.all(x.map(async (O) => {
const z = ee(n, O);
return await H(z && z._f ? { [O]: z } : z);
}))).every(Boolean), !(!I && !r.isValid) && m()) : I = g = await H(n);
return c.state.next({
...!Kt(b) || (d.isValid || f.isValid) && g !== r.isValid ? {} : { name: b },
...t.resolver || !b ? { isValid: g } : {},
errors: r.errors
}), k.shouldFocus && !I && an(n, pe, b ? x : s.mount), I;
}, q = (b) => {
const k = {
...o.mount ? a : i
};
return $e(b) ? k : Kt(b) ? ee(k, b) : b.map((g) => ee(k, g));
}, Z = (b, k) => ({
invalid: !!ee((k || r).errors, b),
isDirty: !!ee((k || r).dirtyFields, b),
error: ee((k || r).errors, b),
isValidating: !!ee(r.validatingFields, b),
isTouched: !!ee((k || r).touchedFields, b)
}), de = (b) => {
b && gt(b).forEach((k) => Qe(r.errors, k)), c.state.next({
errors: b ? r.errors : {}
});
}, ge = (b, k, g) => {
const I = (ee(n, b, { _f: {} })._f || {}).ref, x = ee(r.errors, b) || {}, { ref: O, message: z, type: M, ...U } = x;
Ce(r.errors, b, {
...U,
...k,
ref: I
}), c.state.next({
name: b,
errors: r.errors,
isValid: !1
}), g && g.shouldFocus && I && I.focus && I.focus();
}, fe = (b, k) => zt(b) ? c.state.subscribe({
next: (g) => b(L(void 0, k), g)
}) : L(b, k, !0), re = (b) => c.state.subscribe({
next: (k) => {
lp(b.name, k.name, b.exact) && sp(k, b.formState || d, Je, b.reRenderRoot) && b.callback({
values: { ...a },
...r,
...k
});
}
}).unsubscribe, B = (b) => (o.mount = !0, f = {
...f,
...b.formState
}, re({
...b,
formState: f
})), Q = (b, k = {}) => {
for (const g of b ? gt(b) : s.mount)
s.mount.delete(g), s.array.delete(g), k.keepValue || (Qe(n, g), Qe(a, g)), !k.keepError && Qe(r.errors, g), !k.keepDirty && Qe(r.dirtyFields, g), !k.keepTouched && Qe(r.touchedFields, g), !k.keepIsValidating && Qe(r.validatingFields, g), !t.shouldUnregister && !k.keepDefaultValue && Qe(i, g);
c.state.next({
values: Me(a)
}), c.state.next({
...r,
...k.keepDirty ? { isDirty: j() } : {}
}), !k.keepIsValid && m();
}, oe = ({ disabled: b, name: k }) => {
(xt(b) && o.mount || b || s.disabled.has(k)) && (b ? s.disabled.add(k) : s.disabled.delete(k));
}, le = (b, k = {}) => {
let g = ee(n, b);
const I = xt(k.disabled) || xt(t.disabled);
return Ce(n, b, {
...g || {},
_f: {
...g && g._f ? g._f : { ref: { name: b } },
name: b,
mount: !0,
...k
}
}), s.mount.add(b), g ? oe({
disabled: xt(k.disabled) ? k.disabled : t.disabled,
name: b
}) : A(b, !0, k.value), {
...I ? { disabled: k.disabled || t.disabled } : {},
...t.progressive ? {
required: !!k.required,
min: kn(k.min),
max: kn(k.max),
minLength: kn(k.minLength),
maxLength: kn(k.maxLength),
pattern: kn(k.pattern)
} : {},
name: b,
onChange: ne,
onBlur: ne,
ref: (x) => {
if (x) {
le(b, k), g = ee(n, b);
const O = $e(x.value) && x.querySelectorAll && x.querySelectorAll("input,select,textarea")[0] || x, z = tp(O), M = g._f.refs || [];
if (z ? M.find((U) => U === O) : O === g._f.ref)
return;
Ce(n, b, {
_f: {
...g._f,
...z ? {
refs: [
...M.filter(Ji),
O,
...Array.isArray(ee(i, b)) ? [{}] : []
],
ref: { type: O.type, name: b }
} : { ref: O }
}
}), A(b, !1, void 0, O);
} else
g = ee(n, b, {}), g._f && (g._f.mount = !1), (t.shouldUnregister || k.shouldUnregister) && !(Bl(s.array, b) && o.action) && s.unMount.add(b);
}
};
}, ue = () => t.shouldFocusError && an(n, pe, s.mount), Se = (b) => {
xt(b) && (c.state.next({ disabled: b }), an(n, (k, g) => {
const I = ee(n, g);
I && (k.disabled = I._f.disabled || b, Array.isArray(I._f.refs) && I._f.refs.forEach((x) => {
x.disabled = I._f.disabled || b;
}));
}, 0, !1));
}, X = (b, k) => async (g) => {
let I;
g && (g.preventDefault && g.preventDefault(), g.persist && g.persist());
let x = Me(a);
if (c.state.next({
isSubmitting: !0
}), t.resolver) {
const { errors: O, values: z } = await D();
r.errors = O, x = z;
} else
await H(n);
if (s.disabled.size)
for (const O of s.disabled)
Ce(x, O, void 0);
if (Qe(r.errors, "root"), st(r.errors)) {
c.state.next({
errors: {}
});
try {
await b(x, g);
} catch (O) {
I = O;
}
} else
k && await k({ ...r.errors }, g), ue(), setTimeout(ue);
if (c.state.next({
isSubmitted: !0,
isSubmitting: !1,
isSubmitSuccessful: st(r.errors) && !I,
submitCount: r.submitCount + 1,
errors: r.errors
}), I)
throw I;
}, Ve = (b, k = {}) => {
ee(n, b) && ($e(k.defaultValue) ? Y(b, Me(ee(i, b))) : (Y(b, k.defaultValue), Ce(i, b, Me(k.defaultValue))), k.keepTouched || Qe(r.touchedFields, b), k.keepDirty || (Qe(r.dirtyFields, b), r.isDirty = k.defaultValue ? j(b, Me(ee(i, b))) : j()), k.keepError || (Qe(r.errors, b), d.isValid && m()), c.state.next({ ...r }));
}, Ze = (b, k = {}) => {
const g = b ? Me(b) : i, I = Me(g), x = st(b), O = x ? i : I;
if (k.keepDefaultValues || (i = g), !k.keepValues) {
if (k.keepDirtyValues) {
const z = /* @__PURE__ */ new Set([
...s.mount,
...Object.keys(En(i, a))
]);
for (const M of Array.from(z))
ee(r.dirtyFields, M) ? Ce(O, M, ee(a, M)) : Y(M, ee(O, M));
} else {
if (uo && $e(b))
for (const z of s.mount) {
const M = ee(n, z);
if (M && M._f) {
const U = Array.isArray(M._f.refs) ? M._f.refs[0] : M._f.ref;
if (yi(U)) {
const me = U.closest("form");
if (me) {
me.reset();
break;
}
}
}
}
for (const z of s.mount)
Y(z, ee(O, z));
}
a = Me(O), c.array.next({
values: { ...O }
}), c.state.next({
values: { ...O }
});
}
s = {
mount: k.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 || !!k.keepIsValid || !!k.keepDirtyValues, o.watch = !!t.shouldUnregister, c.state.next({
submitCount: k.keepSubmitCount ? r.submitCount : 0,
isDirty: x ? !1 : k.keepDirty ? r.isDirty : !!(k.keepDefaultValues && !sr(b, i)),
isSubmitted: k.keepIsSubmitted ? r.isSubmitted : !1,
dirtyFields: x ? {} : k.keepDirtyValues ? k.keepDefaultValues && a ? En(i, a) : r.dirtyFields : k.keepDefaultValues && b ? En(i, b) : k.keepDirty ? r.dirtyFields : {},
touchedFields: k.keepTouched ? r.touchedFields : {},
errors: k.keepErrors ? r.errors : {},
isSubmitSuccessful: k.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
isSubmitting: !1
});
}, rt = (b, k) => Ze(zt(b) ? b(a) : b, k), Dt = (b, k = {}) => {
const g = ee(n, b), I = g && g._f;
if (I) {
const x = I.refs ? I.refs[0] : I.ref;
x.focus && (x.focus(), k.shouldSelect && zt(x.select) && x.select());
}
}, Je = (b) => {
r = {
...r,
...b
};
}, Ye = {
control: {
register: le,
unregister: Q,
getFieldState: Z,
handleSubmit: X,
setError: ge,
_subscribe: re,
_runSchema: D,
_focusError: ue,
_getWatch: L,
_getDirty: j,
_setValid: m,
_setFieldArray: v,
_setDisabledField: oe,
_setErrors: P,
_getFieldArray: G,
_reset: Ze,
_resetDefaultValues: () => zt(t.defaultValues) && t.defaultValues().then((b) => {
rt(b, t.resetOptions), c.state.next({
isLoading: !1
});
}),
_removeUnmounted: h,
_disableForm: Se,
_subjects: c,
_proxyFormState: d,
get _fields() {
return n;
},
get _formValues() {
return a;
},
get _state() {
return o;
},
set _state(b) {
o = b;
},
get _defaultValues() {
return i;
},
get _names() {
return s;
},
set _names(b) {
s = b;
},
get _formState() {
return r;
},
get _options() {
return t;
},
set _options(b) {
t = {
...t,
...b
};
}
},
subscribe: B,
trigger: $,
register: le,
handleSubmit: X,
watch: fe,
setValue: Y,
getValues: q,
reset: rt,
resetField: Ve,
clearErrors: de,
unregister: Q,
setError: ge,
setFocus: Dt,
getFieldState: Z
};
return {
...Ye,
formControl: Ye
};
}
var nr = () => {
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);
});
}, ea = (e, t, r = {}) => r.shouldFocus || $e(r.shouldFocus) ? r.focusName || `${e}.${$e(r.focusIndex) ? t : r.focusIndex}.` : "", ta = (e, t) => [
...e,
...gt(t)
], ra = (e) => Array.isArray(e) ? e.map(() => {
}) : void 0;
function na(e, t, r) {
return [
...e.slice(0, t),
...gt(r),
...e.slice(t)
];
}
var ia = (e, t, r) => Array.isArray(e) ? ($e(e[r]) && (e[r] = void 0), e.splice(r, 0, e.splice(t, 1)[0]), e) : [], aa = (e, t) => [
...gt(t),
...gt(e)
];
function fp(e, t) {
let r = 0;
const n = [...e];
for (const i of t)
n.splice(i - r, 1), r++;
return Vi(n).length ? n : [];
}
var oa = (e, t) => $e(t) ? [] : fp(e, gt(t).sort((r, n) => r - n)), sa = (e, t, r) => {
[e[t], e[r]] = [e[r], e[t]];
}, ts = (e, t, r) => (e[t] = r, e);
function hp(e) {
const t = Ni(), { control: r = t.control, name: n, keyName: i = "id", shouldUnregister: a, rules: o } = e, [s, l] = ce.useState(r._getFieldArray(n)), u = ce.useRef(r._getFieldArray(n).map(nr)), d = ce.useRef(s), f = ce.useRef(n), c = ce.useRef(!1);
f.current = n, d.current = s, r._names.array.add(n), o && r.register(n, o), Li(() => r._subjects.array.subscribe({
next: ({ values: _, name: D }) => {
if (D === f.current || !D) {
const R = ee(_, f.current);
Array.isArray(R) && (l(R), u.current = R.map(nr));
}
}
}).unsubscribe, [r]);
const y = ce.useCallback((_) => {
c.current = !0, r._setFieldArray(n, _);
}, [r, n]), C = (_, D) => {
const R = gt(Me(_)), H = ta(r._getFieldArray(n), R);
r._names.focus = ea(n, H.length - 1, D), u.current = ta(u.current, R.map(nr)), y(H), l(H), r._setFieldArray(n, H, ta, {
argA: ra(_)
});
}, m = (_, D) => {
const R = gt(Me(_)), H = aa(r._getFieldArray(n), R);
r._names.focus = ea(n, 0, D), u.current = aa(u.current, R.map(nr)), y(H), l(H), r._setFieldArray(n, H, aa, {
argA: ra(_)
});
}, w = (_) => {
const D = oa(r._getFieldArray(n), _);
u.current = oa(u.current, _), y(D), l(D), !Array.isArray(ee(r._fields, n)) && Ce(r._fields, n, void 0), r._setFieldArray(n, D, oa, {
argA: _
});
}, v = (_, D, R) => {
const H = gt(Me(D)), h = na(r._getFieldArray(n), _, H);
r._names.focus = ea(n, _, R), u.current = na(u.current, _, H.map(nr)), y(h), l(h), r._setFieldArray(n, h, na, {
argA: _,
argB: ra(D)
});
}, T = (_, D) => {
const R = r._getFieldArray(n);
sa(R, _, D), sa(u.current, _, D), y(R), l(R), r._setFieldArray(n, R, sa, {
argA: _,
argB: D
}, !1);
}, P = (_, D) => {
const R = r._getFieldArray(n);
ia(R, _, D), ia(u.current, _, D), y(R), l(R), r._setFieldArray(n, R, ia, {
argA: _,
argB: D
}, !1);
}, A = (_, D) => {
const R = Me(D), H = ts(r._getFieldArray(n), _, R);
u.current = [...H].map((h, j) => !h || j === _ ? nr() : u.current[j]), y(H), l([...H]), r._setFieldArray(n, H, ts, {
argA: _,
argB: R
}, !0, !1);
}, S = (_) => {
const D = gt(Me(_));
u.current = D.map(nr), y([...D]), l([...D]), r._setFieldArray(n, [...D], (R) => R, {}, !0, !1);
};
return ce.useEffect(() => {
if (r._state.action = !1, Aa(n, r._names) && r._subjects.state.next({
...r._formState
}), c.current && (!en(r._options.mode).isOnSubmit || r._formState.isSubmitted) && !en(r._options.reValidateMode).isOnSubmit)
if (r._options.resolver)
r._runSchema([n]).then((_) => {
const D = ee(_.errors, n), R = ee(r._formState.errors, n);
(R ? !D && R.type || D && (R.type !== D.type || R.message !== D.message) : D && D.type) && (D ? Ce(r._formState.errors, n, D) : Qe(r._formState.errors, n), r._subjects.state.next({
errors: r._formState.errors
}));
});
else {
const _ = ee(r._fields, n);
_ && _._f && !(en(r._options.reValidateMode).isOnSubmit && en(r._options.mode).isOnSubmit) && Oa(_, r._names.disabled, r._formValues, r._options.criteriaMode === _t.all, r._options.shouldUseNativeValidation, !0).then((D) => !st(D) && r._subjects.state.next({
errors: ec(r._formState.errors, D, n)
}));
}
r._subjects.state.next({
name: n,
values: Me(r._formValues)
}), r._names.focus && an(r._fields, (_, D) => {
if (r._names.focus && D.startsWith(r._names.focus) && _.focus)
return _.focus(), 1;
}), r._names.focus = "", r._setValid(), c.current = !1;
}, [s, n, r]), ce.useEffect(() => (!ee(r._formValues, n) && r._setFieldArray(n), () => {
const _ = (D, R) => {
const H = ee(r._fields, D);
H && H._f && (H._f.mount = R);
};
r._options.shouldUnregister || a ? r.unregister(n) : _(n, !1);
}), [n, r, i, a]), {
swap: ce.useCallback(T, [y, n, r]),
move: ce.useCallback(P, [y, n, r]),
prepend: ce.useCallback(m, [y, n, r]),
append: ce.useCallback(C, [y, n, r]),
remove: ce.useCallback(w, [y, n, r]),
insert: ce.useCallback(v, [y, n, r]),
update: ce.useCallback(A, [y, n, r]),
replace: ce.useCallback(S, [y, n, r]),
fields: ce.useMemo(() => s.map((_, D) => ({
..._,
[i]: u.current[D] || nr()
})), [s, i])
};
}
function mp(e = {}) {
const t = ce.useRef(void 0), r = ce.useRef(void 0), [n, i] = ce.useState({
isDirty: !1,
isValidating: !1,
isLoading: zt(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: zt(e.defaultValues) ? void 0 : e.defaultValues
});
if (!t.current)
if (e.formControl)
t.current = {
...e.formControl,
formState: n
}, e.defaultValues && !zt(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
else {
const { formControl: o, ...s } = dp(e);
t.current = {
...s,
formState: n
};
}
const a = t.current.control;
return a._options = e, Li(() => {
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]), ce.useEffect(() => a._disableForm(e.disabled), [a, e.disabled]), ce.useEffect(() => {
e.mode && (a._options.mode = e.mode), e.reValidateMode && (a._options.reValidateMode = e.reValidateMode);
}, [a, e.mode, e.reValidateMode]), ce.useEffect(() => {
e.errors && (a._setErrors(e.errors), a._focusError());
}, [a, e.errors]), ce.useEffect(() => {
e.shouldUnregister && a._subjects.state.next({
values: a._getWatch()
});
}, [a, e.shouldUnregister]), ce.useEffect(() => {
if (a._proxyFormState.isDirty) {
const o = a._getDirty();
o !== n.isDirty && a._subjects.state.next({
isDirty: o
});
}
}, [a, n.isDirty]), ce.useEffect(() => {
e.values && !sr(e.values, r.current) ? (a._reset(e.values, a._options.resetOptions), r.current = e.values, i((o) => ({ ...o }))) : a._resetDefaultValues();
}, [a, e.values]), ce.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 = Wl(n, a), t.current;
}
const rs = (e, t, r) => {
if (e && "reportValidity" in e) {
const n = ee(r, t);
e.setCustomValidity(n && n.message || ""), e.reportValidity();
}
}, tc = (e, t) => {
for (const r in t.fields) {
const n = t.fields[r];
n && n.ref && "reportValidity" in n.ref ? rs(n.ref, r, e) : n && n.refs && n.refs.forEach((i) => rs(i, r, e));
}
}, gp = (e, t) => {
t.shouldUseNativeValidation && tc(e, t);
const r = {};
for (const n in e) {
const i = ee(t.fields, n), a = Object.assign(e[n] || {}, { ref: i && i.ref });
if (yp(t.names || Object.keys(e), n)) {
const o = Object.assign({}, ee(r, n));
Ce(o, "root", a), Ce(r, n, o);
} else Ce(r, n, a);
}
return r;
}, yp = (e, t) => {
const r = ns(t);
return e.some((n) => ns(n).match(`^${r}\\.\\d+`));
};
function ns(e) {
return e.replace(/\]|\[/g, "");
}
function vp(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(u) {
return a.shouldUseNativeValidation && tc({}, a), { values: r.raw ? Object.assign({}, n) : u, errors: {} };
}));
} catch (u) {
return s(u);
}
return l && l.then ? l.then(void 0, s) : l;
}(0, function(o) {
if (!o.inner) throw o;
return { values: {}, errors: gp((s = o, l = !a.shouldUseNativeValidation && a.criteriaMode === "all", (s.inner || []).reduce(function(u, d) {
if (u[d.path] || (u[d.path] = { message: d.message, type: d.type }), l) {
var f = u[d.path].types, c = f && f[d.type];
u[d.path] = Kl(d.path, l, u, d.type, c ? [].concat(c, d.message) : d.message);
}
return u;
}, {})), a) };
var s, l;
}));
} catch (o) {
return Promise.reject(o);
}
};
}
var Wn = 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() {
}
}, Nr = typeof window > "u" || "Deno" in globalThis;
function ft() {
}
function xp(e, t) {
return typeof e == "function" ? e(t) : e;
}
function Fa(e) {
return typeof e == "number" && e >= 0 && e !== 1 / 0;
}
function rc(e, t) {
return Math.max(e + (t || 0) - Date.now(), 0);
}
function vr(e, t) {
return typeof e == "function" ? e(t) : e;
}
function Tt(e, t) {
return typeof e == "function" ? e(t) : e;
}
function is(e, t) {
const {
type: r = "all",
exact: n,
fetchStatus: i,
predicate: a,
queryKey: o,
stale: s
} = e;
if (o) {
if (n) {
if (t.queryHash !== mo(o, t.options))
return !1;
} else if (!In(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 as(e, t) {
const { exact: r, status: n, predicate: i, mutationKey: a } = e;
if (a) {
if (!t.options.mutationKey)
return !1;
if (r) {
if (Dn(t.options.mutationKey) !== Dn(a))
return !1;
} else if (!In(t.options.mutationKey, a))
return !1;
}
return !(n && t.state.status !== n || i && !i(t));
}
function mo(e, t) {
return ((t == null ? void 0 : t.queryKeyHashFn) || Dn)(e);
}
function Dn(e) {
return JSON.stringify(
e,
(t, r) => $a(r) ? Object.keys(r).sort().reduce((n, i) => (n[i] = r[i], n), {}) : r
);
}
function In(e, t) {
return e === t ? !0 : typeof e != typeof t ? !1 : e && t && typeof e == "object" && typeof t == "object" ? Object.keys(t).every((r) => In(e[r], t[r])) : !1;
}
function _a(e, t) {
if (e === t)
return e;
const r = os(e) && os(t);
if (r || $a(e) && $a(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 u = 0;
for (let d = 0; d < o; d++) {
const f = r ? d : a[d];
(!r && l.has(f) || r) && e[f] === void 0 && t[f] === void 0 ? (s[f] = void 0, u++) : (s[f] = _a(e[f], t[f]), s[f] === e[f] && e[f] !== void 0 && u++);
}
return i === o && u === i ? e : s;
}
return t;
}
function Ra(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 os(e) {
return Array.isArray(e) && e.length === Object.keys(e).length;
}
function $a(e) {
if (!ss(e))
return !1;
const t = e.constructor;
if (t === void 0)
return !0;
const r = t.prototype;
return !(!ss(r) || !r.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
}
function ss(e) {
return Object.prototype.toString.call(e) === "[object Object]";
}
function bp(e) {
return new Promise((t) => {
setTimeout(t, e);
});
}
function Pa(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 _a(e, t);
} catch (n) {
throw console.error(
`Structural sharing re