suprform 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1233 @@
1
+ import { jsx as _e } from "react/jsx-runtime";
2
+ import _, { useCallback as Ye, cloneElement as Et } from "react";
3
+ var he = (e) => e.type === "checkbox", ae = (e) => e instanceof Date, $ = (e) => e == null;
4
+ const ut = (e) => typeof e == "object";
5
+ var M = (e) => !$(e) && !Array.isArray(e) && ut(e) && !ae(e), lt = (e) => M(e) && e.target ? he(e.target) ? e.target.checked : e.target.value : e, St = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, ot = (e, s) => e.has(St(s)), Ct = (e) => {
6
+ const s = e.constructor && e.constructor.prototype;
7
+ return M(s) && s.hasOwnProperty("isPrototypeOf");
8
+ }, Te = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
9
+ function U(e) {
10
+ let s;
11
+ const t = Array.isArray(e), i = typeof FileList < "u" ? e instanceof FileList : !1;
12
+ if (e instanceof Date)
13
+ s = new Date(e);
14
+ else if (!(Te && (e instanceof Blob || i)) && (t || M(e)))
15
+ if (s = t ? [] : Object.create(Object.getPrototypeOf(e)), !t && !Ct(e))
16
+ s = e;
17
+ else
18
+ for (const u in e)
19
+ e.hasOwnProperty(u) && (s[u] = U(e[u]));
20
+ else
21
+ return e;
22
+ return s;
23
+ }
24
+ var Fe = (e) => /^\w*$/.test(e), O = (e) => e === void 0, Le = (e) => Array.isArray(e) ? e.filter(Boolean) : [], Me = (e) => Le(e.replace(/["|']|\]/g, "").split(/\.|\[/)), y = (e, s, t) => {
25
+ if (!s || !M(e))
26
+ return t;
27
+ const i = (Fe(s) ? [s] : Me(s)).reduce((u, n) => $(u) ? u : u[n], e);
28
+ return O(i) || i === e ? O(e[s]) ? t : e[s] : i;
29
+ }, z = (e) => typeof e == "boolean", C = (e, s, t) => {
30
+ let i = -1;
31
+ const u = Fe(s) ? [s] : Me(s), n = u.length, d = n - 1;
32
+ for (; ++i < n; ) {
33
+ const c = u[i];
34
+ let w = t;
35
+ if (i !== d) {
36
+ const E = e[c];
37
+ w = M(E) || Array.isArray(E) ? E : isNaN(+u[i + 1]) ? {} : [];
38
+ }
39
+ if (c === "__proto__" || c === "constructor" || c === "prototype")
40
+ return;
41
+ e[c] = w, e = e[c];
42
+ }
43
+ };
44
+ const be = {
45
+ BLUR: "blur",
46
+ FOCUS_OUT: "focusout",
47
+ CHANGE: "change"
48
+ }, J = {
49
+ onBlur: "onBlur",
50
+ onChange: "onChange",
51
+ onSubmit: "onSubmit",
52
+ onTouched: "onTouched",
53
+ all: "all"
54
+ }, re = {
55
+ max: "max",
56
+ min: "min",
57
+ maxLength: "maxLength",
58
+ minLength: "minLength",
59
+ pattern: "pattern",
60
+ required: "required",
61
+ validate: "validate"
62
+ }, Ue = _.createContext(null);
63
+ Ue.displayName = "HookFormContext";
64
+ const Ae = () => _.useContext(Ue), Rt = (e) => {
65
+ const { children: s, ...t } = e;
66
+ return _.createElement(Ue.Provider, { value: t }, s);
67
+ };
68
+ var dt = (e, s, t, i = !0) => {
69
+ const u = {
70
+ defaultValues: s._defaultValues
71
+ };
72
+ for (const n in e)
73
+ Object.defineProperty(u, n, {
74
+ get: () => {
75
+ const d = n;
76
+ return s._proxyFormState[d] !== J.all && (s._proxyFormState[d] = !i || J.all), t && (t[d] = !0), e[d];
77
+ }
78
+ });
79
+ return u;
80
+ };
81
+ const pe = typeof window < "u" ? _.useLayoutEffect : _.useEffect;
82
+ function Ot(e) {
83
+ const s = Ae(), { control: t = s.control, disabled: i, name: u, exact: n } = e || {}, [d, c] = _.useState(t._formState), w = _.useRef({
84
+ isDirty: !1,
85
+ isLoading: !1,
86
+ dirtyFields: !1,
87
+ touchedFields: !1,
88
+ validatingFields: !1,
89
+ isValidating: !1,
90
+ isValid: !1,
91
+ errors: !1
92
+ });
93
+ return pe(() => t._subscribe({
94
+ name: u,
95
+ formState: w.current,
96
+ exact: n,
97
+ callback: (E) => {
98
+ !i && c({
99
+ ...t._formState,
100
+ ...E
101
+ });
102
+ }
103
+ }), [u, i, n]), _.useEffect(() => {
104
+ w.current.isValid && t._setValid(!0);
105
+ }, [t]), _.useMemo(() => dt(d, t, w.current, !1), [d, t]);
106
+ }
107
+ var G = (e) => typeof e == "string", Ce = (e, s, t, i, u) => G(e) ? (i && s.watch.add(e), y(t, e, u)) : Array.isArray(e) ? e.map((n) => (i && s.watch.add(n), y(t, n))) : (i && (s.watchAll = !0), t), Re = (e) => $(e) || !ut(e);
108
+ function Q(e, s, t = /* @__PURE__ */ new WeakSet()) {
109
+ if (Re(e) || Re(s))
110
+ return Object.is(e, s);
111
+ if (ae(e) && ae(s))
112
+ return e.getTime() === s.getTime();
113
+ const i = Object.keys(e), u = Object.keys(s);
114
+ if (i.length !== u.length)
115
+ return !1;
116
+ if (t.has(e) || t.has(s))
117
+ return !0;
118
+ t.add(e), t.add(s);
119
+ for (const n of i) {
120
+ const d = e[n];
121
+ if (!u.includes(n))
122
+ return !1;
123
+ if (n !== "ref") {
124
+ const c = s[n];
125
+ if (ae(d) && ae(c) || M(d) && M(c) || Array.isArray(d) && Array.isArray(c) ? !Q(d, c, t) : !Object.is(d, c))
126
+ return !1;
127
+ }
128
+ }
129
+ return !0;
130
+ }
131
+ function Tt(e) {
132
+ const s = Ae(), { control: t = s.control, name: i, defaultValue: u, disabled: n, exact: d, compute: c } = e || {}, w = _.useRef(u), E = _.useRef(c), V = _.useRef(void 0), b = _.useRef(t), v = _.useRef(i);
133
+ E.current = c;
134
+ const [p, q] = _.useState(() => {
135
+ const F = t._getWatch(i, w.current);
136
+ return E.current ? E.current(F) : F;
137
+ }), R = _.useCallback((F) => {
138
+ const A = Ce(i, t._names, F || t._formValues, !1, w.current);
139
+ return E.current ? E.current(A) : A;
140
+ }, [t._formValues, t._names, i]), B = _.useCallback((F) => {
141
+ if (!n) {
142
+ const A = Ce(i, t._names, F || t._formValues, !1, w.current);
143
+ if (E.current) {
144
+ const j = E.current(A);
145
+ Q(j, V.current) || (q(j), V.current = j);
146
+ } else
147
+ q(A);
148
+ }
149
+ }, [t._formValues, t._names, n, i]);
150
+ pe(() => ((b.current !== t || !Q(v.current, i)) && (b.current = t, v.current = i, B()), t._subscribe({
151
+ name: i,
152
+ formState: {
153
+ values: !0
154
+ },
155
+ exact: d,
156
+ callback: (F) => {
157
+ B(F.values);
158
+ }
159
+ })), [t, d, i, B]), _.useEffect(() => t._removeUnmounted());
160
+ const Z = b.current !== t, m = v.current, N = _.useMemo(() => {
161
+ if (n)
162
+ return null;
163
+ const F = !Z && !Q(m, i);
164
+ return Z || F ? R() : null;
165
+ }, [n, Z, i, m, R]);
166
+ return N !== null ? N : p;
167
+ }
168
+ function Lt(e) {
169
+ const s = Ae(), { name: t, disabled: i, control: u = s.control, shouldUnregister: n, defaultValue: d, exact: c = !0 } = e, w = ot(u._names.array, t), E = _.useMemo(() => y(u._formValues, t, y(u._defaultValues, t, d)), [u, t, d]), V = Tt({
170
+ control: u,
171
+ name: t,
172
+ defaultValue: E,
173
+ exact: c
174
+ }), b = Ot({
175
+ control: u,
176
+ name: t,
177
+ exact: c
178
+ }), v = _.useRef(e), p = _.useRef(void 0), q = _.useRef(u.register(t, {
179
+ ...e.rules,
180
+ value: V,
181
+ ...z(e.disabled) ? { disabled: e.disabled } : {}
182
+ }));
183
+ v.current = e;
184
+ const R = _.useMemo(() => Object.defineProperties({}, {
185
+ invalid: {
186
+ enumerable: !0,
187
+ get: () => !!y(b.errors, t)
188
+ },
189
+ isDirty: {
190
+ enumerable: !0,
191
+ get: () => !!y(b.dirtyFields, t)
192
+ },
193
+ isTouched: {
194
+ enumerable: !0,
195
+ get: () => !!y(b.touchedFields, t)
196
+ },
197
+ isValidating: {
198
+ enumerable: !0,
199
+ get: () => !!y(b.validatingFields, t)
200
+ },
201
+ error: {
202
+ enumerable: !0,
203
+ get: () => y(b.errors, t)
204
+ }
205
+ }), [b, t]), B = _.useCallback((F) => q.current.onChange({
206
+ target: {
207
+ value: lt(F),
208
+ name: t
209
+ },
210
+ type: be.CHANGE
211
+ }), [t]), Z = _.useCallback(() => q.current.onBlur({
212
+ target: {
213
+ value: y(u._formValues, t),
214
+ name: t
215
+ },
216
+ type: be.BLUR
217
+ }), [t, u._formValues]), m = _.useCallback((F) => {
218
+ const A = y(u._fields, t);
219
+ A && F && (A._f.ref = {
220
+ focus: () => F.focus && F.focus(),
221
+ select: () => F.select && F.select(),
222
+ setCustomValidity: (j) => F.setCustomValidity(j),
223
+ reportValidity: () => F.reportValidity()
224
+ });
225
+ }, [u._fields, t]), N = _.useMemo(() => ({
226
+ name: t,
227
+ value: V,
228
+ ...z(i) || b.disabled ? { disabled: b.disabled || i } : {},
229
+ onChange: B,
230
+ onBlur: Z,
231
+ ref: m
232
+ }), [t, i, b.disabled, B, Z, m, V]);
233
+ return _.useEffect(() => {
234
+ const F = u._options.shouldUnregister || n, A = p.current;
235
+ A && A !== t && !w && u.unregister(A), u.register(t, {
236
+ ...v.current.rules,
237
+ ...z(v.current.disabled) ? { disabled: v.current.disabled } : {}
238
+ });
239
+ const j = (K, oe) => {
240
+ const I = y(u._fields, K);
241
+ I && I._f && (I._f.mount = oe);
242
+ };
243
+ if (j(t, !0), F) {
244
+ const K = U(y(u._options.defaultValues, t, v.current.defaultValue));
245
+ C(u._defaultValues, t, K), O(y(u._formValues, t)) && C(u._formValues, t, K);
246
+ }
247
+ return !w && u.register(t), p.current = t, () => {
248
+ (w ? F && !u._state.action : F) ? u.unregister(t) : j(t, !1);
249
+ };
250
+ }, [t, u, w, n]), _.useEffect(() => {
251
+ u._setDisabledField({
252
+ disabled: i,
253
+ name: t
254
+ });
255
+ }, [i, t, u]), _.useMemo(() => ({
256
+ field: N,
257
+ formState: b,
258
+ fieldState: R
259
+ }), [N, b, R]);
260
+ }
261
+ const Mt = (e) => e.render(Lt(e));
262
+ var Ut = (e, s, t, i, u) => s ? {
263
+ ...t[e],
264
+ types: {
265
+ ...t[e] && t[e].types ? t[e].types : {},
266
+ [i]: u || !0
267
+ }
268
+ } : {}, fe = (e) => Array.isArray(e) ? e : [e], Je = () => {
269
+ let e = [];
270
+ return {
271
+ get observers() {
272
+ return e;
273
+ },
274
+ next: (u) => {
275
+ for (const n of e)
276
+ n.next && n.next(u);
277
+ },
278
+ subscribe: (u) => (e.push(u), {
279
+ unsubscribe: () => {
280
+ e = e.filter((n) => n !== u);
281
+ }
282
+ }),
283
+ unsubscribe: () => {
284
+ e = [];
285
+ }
286
+ };
287
+ };
288
+ function ct(e, s) {
289
+ const t = {};
290
+ for (const i in e)
291
+ if (e.hasOwnProperty(i)) {
292
+ const u = e[i], n = s[i];
293
+ if (u && M(u) && n) {
294
+ const d = ct(u, n);
295
+ M(d) && (t[i] = d);
296
+ } else e[i] && (t[i] = n);
297
+ }
298
+ return t;
299
+ }
300
+ var W = (e) => M(e) && !Object.keys(e).length, Be = (e) => e.type === "file", X = (e) => typeof e == "function", me = (e) => {
301
+ if (!Te)
302
+ return !1;
303
+ const s = e ? e.ownerDocument : 0;
304
+ return e instanceof (s && s.defaultView ? s.defaultView.HTMLElement : HTMLElement);
305
+ }, ft = (e) => e.type === "select-multiple", Ne = (e) => e.type === "radio", pt = (e) => Ne(e) || he(e), Se = (e) => me(e) && e.isConnected;
306
+ function Bt(e, s) {
307
+ const t = s.slice(0, -1).length;
308
+ let i = 0;
309
+ for (; i < t; )
310
+ e = O(e) ? i++ : e[s[i++]];
311
+ return e;
312
+ }
313
+ function Nt(e) {
314
+ for (const s in e)
315
+ if (e.hasOwnProperty(s) && !O(e[s]))
316
+ return !1;
317
+ return !0;
318
+ }
319
+ function L(e, s) {
320
+ const t = Array.isArray(s) ? s : Fe(s) ? [s] : Me(s), i = t.length === 1 ? e : Bt(e, t), u = t.length - 1, n = t[u];
321
+ return i && delete i[n], u !== 0 && (M(i) && W(i) || Array.isArray(i) && Nt(i)) && L(e, t.slice(0, -1)), e;
322
+ }
323
+ var It = (e) => {
324
+ for (const s in e)
325
+ if (X(e[s]))
326
+ return !0;
327
+ return !1;
328
+ };
329
+ function yt(e) {
330
+ return Array.isArray(e) || M(e) && !It(e);
331
+ }
332
+ function Oe(e, s = {}) {
333
+ for (const t in e) {
334
+ const i = e[t];
335
+ yt(i) ? (s[t] = Array.isArray(i) ? [] : {}, Oe(i, s[t])) : O(i) || (s[t] = !0);
336
+ }
337
+ return s;
338
+ }
339
+ function le(e, s, t) {
340
+ t || (t = Oe(s));
341
+ for (const i in e) {
342
+ const u = e[i];
343
+ if (yt(u))
344
+ O(s) || Re(t[i]) ? t[i] = Oe(u, Array.isArray(u) ? [] : {}) : le(u, $(s) ? {} : s[i], t[i]);
345
+ else {
346
+ const n = s[i];
347
+ t[i] = !Q(u, n);
348
+ }
349
+ }
350
+ return t;
351
+ }
352
+ const Qe = {
353
+ value: !1,
354
+ isValid: !1
355
+ }, Xe = { value: !0, isValid: !0 };
356
+ var ht = (e) => {
357
+ if (Array.isArray(e)) {
358
+ if (e.length > 1) {
359
+ const s = e.filter((t) => t && t.checked && !t.disabled).map((t) => t.value);
360
+ return { value: s, isValid: !!s.length };
361
+ }
362
+ return e[0].checked && !e[0].disabled ? (
363
+ // @ts-expect-error expected to work in the browser
364
+ e[0].attributes && !O(e[0].attributes.value) ? O(e[0].value) || e[0].value === "" ? Xe : { value: e[0].value, isValid: !0 } : Xe
365
+ ) : Qe;
366
+ }
367
+ return Qe;
368
+ }, gt = (e, { valueAsNumber: s, valueAsDate: t, setValueAs: i }) => O(e) ? e : s ? e === "" ? NaN : e && +e : t && G(e) ? new Date(e) : i ? i(e) : e;
369
+ const Ze = {
370
+ isValid: !1,
371
+ value: null
372
+ };
373
+ var vt = (e) => Array.isArray(e) ? e.reduce((s, t) => t && t.checked && !t.disabled ? {
374
+ isValid: !0,
375
+ value: t.value
376
+ } : s, Ze) : Ze;
377
+ function et(e) {
378
+ const s = e.ref;
379
+ return Be(s) ? s.files : Ne(s) ? vt(e.refs).value : ft(s) ? [...s.selectedOptions].map(({ value: t }) => t) : he(s) ? ht(e.refs).value : gt(O(s.value) ? e.ref.value : s.value, e);
380
+ }
381
+ var Pt = (e, s, t, i) => {
382
+ const u = {};
383
+ for (const n of e) {
384
+ const d = y(s, n);
385
+ d && C(u, n, d._f);
386
+ }
387
+ return {
388
+ criteriaMode: t,
389
+ names: [...e],
390
+ fields: u,
391
+ shouldUseNativeValidation: i
392
+ };
393
+ }, Ve = (e) => e instanceof RegExp, ce = (e) => O(e) ? e : Ve(e) ? e.source : M(e) ? Ve(e.value) ? e.value.source : e.value : e, tt = (e) => ({
394
+ isOnSubmit: !e || e === J.onSubmit,
395
+ isOnBlur: e === J.onBlur,
396
+ isOnChange: e === J.onChange,
397
+ isOnAll: e === J.all,
398
+ isOnTouch: e === J.onTouched
399
+ });
400
+ const rt = "AsyncFunction";
401
+ var Wt = (e) => !!e && !!e.validate && !!(X(e.validate) && e.validate.constructor.name === rt || M(e.validate) && Object.values(e.validate).find((s) => s.constructor.name === rt)), qt = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), st = (e, s, t) => !t && (s.watchAll || s.watch.has(e) || [...s.watch].some((i) => e.startsWith(i) && /^\.\w+/.test(e.slice(i.length))));
402
+ const ye = (e, s, t, i) => {
403
+ for (const u of t || Object.keys(e)) {
404
+ const n = y(e, u);
405
+ if (n) {
406
+ const { _f: d, ...c } = n;
407
+ if (d) {
408
+ if (d.refs && d.refs[0] && s(d.refs[0], u) && !i)
409
+ return !0;
410
+ if (d.ref && s(d.ref, d.name) && !i)
411
+ return !0;
412
+ if (ye(c, s))
413
+ break;
414
+ } else if (M(c) && ye(c, s))
415
+ break;
416
+ }
417
+ }
418
+ };
419
+ function it(e, s, t) {
420
+ const i = y(e, t);
421
+ if (i || Fe(t))
422
+ return {
423
+ error: i,
424
+ name: t
425
+ };
426
+ const u = t.split(".");
427
+ for (; u.length; ) {
428
+ const n = u.join("."), d = y(s, n), c = y(e, n);
429
+ if (d && !Array.isArray(d) && t !== n)
430
+ return { name: t };
431
+ if (c && c.type)
432
+ return {
433
+ name: n,
434
+ error: c
435
+ };
436
+ if (c && c.root && c.root.type)
437
+ return {
438
+ name: `${n}.root`,
439
+ error: c.root
440
+ };
441
+ u.pop();
442
+ }
443
+ return {
444
+ name: t
445
+ };
446
+ }
447
+ var Ht = (e, s, t, i) => {
448
+ t(e);
449
+ const { name: u, ...n } = e;
450
+ return W(n) || Object.keys(n).length >= Object.keys(s).length || Object.keys(n).find((d) => s[d] === (!i || J.all));
451
+ }, $t = (e, s, t) => !e || !s || e === s || fe(e).some((i) => i && (t ? i === s : i.startsWith(s) || s.startsWith(i))), jt = (e, s, t, i, u) => u.isOnAll ? !1 : !t && u.isOnTouch ? !(s || e) : (t ? i.isOnBlur : u.isOnBlur) ? !e : (t ? i.isOnChange : u.isOnChange) ? e : !0, Kt = (e, s) => !Le(y(e, s)).length && L(e, s), zt = (e, s, t) => {
452
+ const i = fe(y(e, t));
453
+ return C(i, "root", s[t]), C(e, t, i), e;
454
+ };
455
+ function at(e, s, t = "validate") {
456
+ if (G(e) || Array.isArray(e) && e.every(G) || z(e) && !e)
457
+ return {
458
+ type: t,
459
+ message: G(e) ? e : "",
460
+ ref: s
461
+ };
462
+ }
463
+ var ue = (e) => M(e) && !Ve(e) ? e : {
464
+ value: e,
465
+ message: ""
466
+ }, nt = async (e, s, t, i, u, n) => {
467
+ const { ref: d, refs: c, required: w, maxLength: E, minLength: V, min: b, max: v, pattern: p, validate: q, name: R, valueAsNumber: B, mount: Z } = e._f, m = y(t, R);
468
+ if (!Z || s.has(R))
469
+ return {};
470
+ const N = c ? c[0] : d, F = (x) => {
471
+ u && N.reportValidity && (N.setCustomValidity(z(x) ? "" : x || ""), N.reportValidity());
472
+ }, A = {}, j = Ne(d), K = he(d), oe = j || K, I = (B || Be(d)) && O(d.value) && O(m) || me(d) && d.value === "" || m === "" || Array.isArray(m) && !m.length, ie = Ut.bind(null, R, i, A), ee = (x, D, T, P = re.maxLength, H = re.minLength) => {
473
+ const te = x ? D : T;
474
+ A[R] = {
475
+ type: x ? P : H,
476
+ message: te,
477
+ ref: d,
478
+ ...ie(x ? P : H, te)
479
+ };
480
+ };
481
+ if (n ? !Array.isArray(m) || !m.length : w && (!oe && (I || $(m)) || z(m) && !m || K && !ht(c).isValid || j && !vt(c).isValid)) {
482
+ const { value: x, message: D } = G(w) ? { value: !!w, message: w } : ue(w);
483
+ if (x && (A[R] = {
484
+ type: re.required,
485
+ message: D,
486
+ ref: N,
487
+ ...ie(re.required, D)
488
+ }, !i))
489
+ return F(D), A;
490
+ }
491
+ if (!I && (!$(b) || !$(v))) {
492
+ let x, D;
493
+ const T = ue(v), P = ue(b);
494
+ if (!$(m) && !isNaN(m)) {
495
+ const H = d.valueAsNumber || m && +m;
496
+ $(T.value) || (x = H > T.value), $(P.value) || (D = H < P.value);
497
+ } else {
498
+ const H = d.valueAsDate || new Date(m), te = (ge) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + ge), de = d.type == "time", ne = d.type == "week";
499
+ G(T.value) && m && (x = de ? te(m) > te(T.value) : ne ? m > T.value : H > new Date(T.value)), G(P.value) && m && (D = de ? te(m) < te(P.value) : ne ? m < P.value : H < new Date(P.value));
500
+ }
501
+ if ((x || D) && (ee(!!x, T.message, P.message, re.max, re.min), !i))
502
+ return F(A[R].message), A;
503
+ }
504
+ if ((E || V) && !I && (G(m) || n && Array.isArray(m))) {
505
+ const x = ue(E), D = ue(V), T = !$(x.value) && m.length > +x.value, P = !$(D.value) && m.length < +D.value;
506
+ if ((T || P) && (ee(T, x.message, D.message), !i))
507
+ return F(A[R].message), A;
508
+ }
509
+ if (p && !I && G(m)) {
510
+ const { value: x, message: D } = ue(p);
511
+ if (Ve(x) && !m.match(x) && (A[R] = {
512
+ type: re.pattern,
513
+ message: D,
514
+ ref: d,
515
+ ...ie(re.pattern, D)
516
+ }, !i))
517
+ return F(D), A;
518
+ }
519
+ if (q) {
520
+ if (X(q)) {
521
+ const x = await q(m, t), D = at(x, N);
522
+ if (D && (A[R] = {
523
+ ...D,
524
+ ...ie(re.validate, D.message)
525
+ }, !i))
526
+ return F(D.message), A;
527
+ } else if (M(q)) {
528
+ let x = {};
529
+ for (const D in q) {
530
+ if (!W(x) && !i)
531
+ break;
532
+ const T = at(await q[D](m, t), N, D);
533
+ T && (x = {
534
+ ...T,
535
+ ...ie(D, T.message)
536
+ }, F(T.message), i && (A[R] = x));
537
+ }
538
+ if (!W(x) && (A[R] = {
539
+ ref: N,
540
+ ...x
541
+ }, !i))
542
+ return A;
543
+ }
544
+ }
545
+ return F(!0), A;
546
+ };
547
+ const Gt = {
548
+ mode: J.onSubmit,
549
+ reValidateMode: J.onChange,
550
+ shouldFocusError: !0
551
+ };
552
+ function Yt(e = {}) {
553
+ let s = {
554
+ ...Gt,
555
+ ...e
556
+ }, t = {
557
+ submitCount: 0,
558
+ isDirty: !1,
559
+ isReady: !1,
560
+ isLoading: X(s.defaultValues),
561
+ isValidating: !1,
562
+ isSubmitted: !1,
563
+ isSubmitting: !1,
564
+ isSubmitSuccessful: !1,
565
+ isValid: !1,
566
+ touchedFields: {},
567
+ dirtyFields: {},
568
+ validatingFields: {},
569
+ errors: s.errors || {},
570
+ disabled: s.disabled || !1
571
+ }, i = {}, u = M(s.defaultValues) || M(s.values) ? U(s.defaultValues || s.values) || {} : {}, n = s.shouldUnregister ? {} : U(u), d = {
572
+ action: !1,
573
+ mount: !1,
574
+ watch: !1
575
+ }, c = {
576
+ mount: /* @__PURE__ */ new Set(),
577
+ disabled: /* @__PURE__ */ new Set(),
578
+ unMount: /* @__PURE__ */ new Set(),
579
+ array: /* @__PURE__ */ new Set(),
580
+ watch: /* @__PURE__ */ new Set()
581
+ }, w, E = 0;
582
+ const V = {
583
+ isDirty: !1,
584
+ dirtyFields: !1,
585
+ validatingFields: !1,
586
+ touchedFields: !1,
587
+ isValidating: !1,
588
+ isValid: !1,
589
+ errors: !1
590
+ };
591
+ let b = {
592
+ ...V
593
+ };
594
+ const v = {
595
+ array: Je(),
596
+ state: Je()
597
+ }, p = s.criteriaMode === J.all, q = (r) => (a) => {
598
+ clearTimeout(E), E = setTimeout(r, a);
599
+ }, R = async (r) => {
600
+ if (!s.disabled && (V.isValid || b.isValid || r)) {
601
+ const a = s.resolver ? W((await K()).errors) : await I(i, !0);
602
+ a !== t.isValid && v.state.next({
603
+ isValid: a
604
+ });
605
+ }
606
+ }, B = (r, a) => {
607
+ !s.disabled && (V.isValidating || V.validatingFields || b.isValidating || b.validatingFields) && ((r || Array.from(c.mount)).forEach((l) => {
608
+ l && (a ? C(t.validatingFields, l, a) : L(t.validatingFields, l));
609
+ }), v.state.next({
610
+ validatingFields: t.validatingFields,
611
+ isValidating: !W(t.validatingFields)
612
+ }));
613
+ }, Z = (r, a = [], l, h, f = !0, o = !0) => {
614
+ if (h && l && !s.disabled) {
615
+ if (d.action = !0, o && Array.isArray(y(i, r))) {
616
+ const g = l(y(i, r), h.argA, h.argB);
617
+ f && C(i, r, g);
618
+ }
619
+ if (o && Array.isArray(y(t.errors, r))) {
620
+ const g = l(y(t.errors, r), h.argA, h.argB);
621
+ f && C(t.errors, r, g), Kt(t.errors, r);
622
+ }
623
+ if ((V.touchedFields || b.touchedFields) && o && Array.isArray(y(t.touchedFields, r))) {
624
+ const g = l(y(t.touchedFields, r), h.argA, h.argB);
625
+ f && C(t.touchedFields, r, g);
626
+ }
627
+ (V.dirtyFields || b.dirtyFields) && (t.dirtyFields = le(u, n)), v.state.next({
628
+ name: r,
629
+ isDirty: ee(r, a),
630
+ dirtyFields: t.dirtyFields,
631
+ errors: t.errors,
632
+ isValid: t.isValid
633
+ });
634
+ } else
635
+ C(n, r, a);
636
+ }, m = (r, a) => {
637
+ C(t.errors, r, a), v.state.next({
638
+ errors: t.errors
639
+ });
640
+ }, N = (r) => {
641
+ t.errors = r, v.state.next({
642
+ errors: t.errors,
643
+ isValid: !1
644
+ });
645
+ }, F = (r, a, l, h) => {
646
+ const f = y(i, r);
647
+ if (f) {
648
+ const o = y(n, r, O(l) ? y(u, r) : l);
649
+ O(o) || h && h.defaultChecked || a ? C(n, r, a ? o : et(f._f)) : T(r, o), d.mount && !d.action && R();
650
+ }
651
+ }, A = (r, a, l, h, f) => {
652
+ let o = !1, g = !1;
653
+ const k = {
654
+ name: r
655
+ };
656
+ if (!s.disabled) {
657
+ if (!l || h) {
658
+ (V.isDirty || b.isDirty) && (g = t.isDirty, t.isDirty = k.isDirty = ee(), o = g !== k.isDirty);
659
+ const S = Q(y(u, r), a);
660
+ g = !!y(t.dirtyFields, r), S ? L(t.dirtyFields, r) : C(t.dirtyFields, r, !0), k.dirtyFields = t.dirtyFields, o = o || (V.dirtyFields || b.dirtyFields) && g !== !S;
661
+ }
662
+ if (l) {
663
+ const S = y(t.touchedFields, r);
664
+ S || (C(t.touchedFields, r, l), k.touchedFields = t.touchedFields, o = o || (V.touchedFields || b.touchedFields) && S !== l);
665
+ }
666
+ o && f && v.state.next(k);
667
+ }
668
+ return o ? k : {};
669
+ }, j = (r, a, l, h) => {
670
+ const f = y(t.errors, r), o = (V.isValid || b.isValid) && z(a) && t.isValid !== a;
671
+ if (s.delayError && l ? (w = q(() => m(r, l)), w(s.delayError)) : (clearTimeout(E), w = null, l ? C(t.errors, r, l) : L(t.errors, r)), (l ? !Q(f, l) : f) || !W(h) || o) {
672
+ const g = {
673
+ ...h,
674
+ ...o && z(a) ? { isValid: a } : {},
675
+ errors: t.errors,
676
+ name: r
677
+ };
678
+ t = {
679
+ ...t,
680
+ ...g
681
+ }, v.state.next(g);
682
+ }
683
+ }, K = async (r) => {
684
+ B(r, !0);
685
+ const a = await s.resolver(n, s.context, Pt(r || c.mount, i, s.criteriaMode, s.shouldUseNativeValidation));
686
+ return B(r), a;
687
+ }, oe = async (r) => {
688
+ const { errors: a } = await K(r);
689
+ if (r)
690
+ for (const l of r) {
691
+ const h = y(a, l);
692
+ h ? C(t.errors, l, h) : L(t.errors, l);
693
+ }
694
+ else
695
+ t.errors = a;
696
+ return a;
697
+ }, I = async (r, a, l = {
698
+ valid: !0
699
+ }) => {
700
+ for (const h in r) {
701
+ const f = r[h];
702
+ if (f) {
703
+ const { _f: o, ...g } = f;
704
+ if (o) {
705
+ const k = c.array.has(o.name), S = f._f && Wt(f._f);
706
+ S && V.validatingFields && B([o.name], !0);
707
+ const Y = await nt(f, c.disabled, n, p, s.shouldUseNativeValidation && !a, k);
708
+ if (S && V.validatingFields && B([o.name]), Y[o.name] && (l.valid = !1, a))
709
+ break;
710
+ !a && (y(Y, o.name) ? k ? zt(t.errors, Y, o.name) : C(t.errors, o.name, Y[o.name]) : L(t.errors, o.name));
711
+ }
712
+ !W(g) && await I(g, a, l);
713
+ }
714
+ }
715
+ return l.valid;
716
+ }, ie = () => {
717
+ for (const r of c.unMount) {
718
+ const a = y(i, r);
719
+ a && (a._f.refs ? a._f.refs.every((l) => !Se(l)) : !Se(a._f.ref)) && xe(r);
720
+ }
721
+ c.unMount = /* @__PURE__ */ new Set();
722
+ }, ee = (r, a) => !s.disabled && (r && a && C(n, r, a), !Q(ge(), u)), x = (r, a, l) => Ce(r, c, {
723
+ ...d.mount ? n : O(a) ? u : G(r) ? { [r]: a } : a
724
+ }, l, a), D = (r) => Le(y(d.mount ? n : u, r, s.shouldUnregister ? y(u, r, []) : [])), T = (r, a, l = {}) => {
725
+ const h = y(i, r);
726
+ let f = a;
727
+ if (h) {
728
+ const o = h._f;
729
+ o && (!o.disabled && C(n, r, gt(a, o)), f = me(o.ref) && $(a) ? "" : a, ft(o.ref) ? [...o.ref.options].forEach((g) => g.selected = f.includes(g.value)) : o.refs ? he(o.ref) ? o.refs.forEach((g) => {
730
+ (!g.defaultChecked || !g.disabled) && (Array.isArray(f) ? g.checked = !!f.find((k) => k === g.value) : g.checked = f === g.value || !!f);
731
+ }) : o.refs.forEach((g) => g.checked = g.value === f) : Be(o.ref) ? o.ref.value = "" : (o.ref.value = f, o.ref.type || v.state.next({
732
+ name: r,
733
+ values: U(n)
734
+ })));
735
+ }
736
+ (l.shouldDirty || l.shouldTouch) && A(r, f, l.shouldTouch, l.shouldDirty, !0), l.shouldValidate && ne(r);
737
+ }, P = (r, a, l) => {
738
+ for (const h in a) {
739
+ if (!a.hasOwnProperty(h))
740
+ return;
741
+ const f = a[h], o = r + "." + h, g = y(i, o);
742
+ (c.array.has(r) || M(f) || g && !g._f) && !ae(f) ? P(o, f, l) : T(o, f, l);
743
+ }
744
+ }, H = (r, a, l = {}) => {
745
+ const h = y(i, r), f = c.array.has(r), o = U(a);
746
+ C(n, r, o), f ? (v.array.next({
747
+ name: r,
748
+ values: U(n)
749
+ }), (V.isDirty || V.dirtyFields || b.isDirty || b.dirtyFields) && l.shouldDirty && v.state.next({
750
+ name: r,
751
+ dirtyFields: le(u, n),
752
+ isDirty: ee(r, o)
753
+ })) : h && !h._f && !$(o) ? P(r, o, l) : T(r, o, l), st(r, c) && v.state.next({ ...t, name: r }), v.state.next({
754
+ name: d.mount ? r : void 0,
755
+ values: U(n)
756
+ });
757
+ }, te = async (r) => {
758
+ d.mount = !0;
759
+ const a = r.target;
760
+ let l = a.name, h = !0;
761
+ const f = y(i, l), o = (S) => {
762
+ h = Number.isNaN(S) || ae(S) && isNaN(S.getTime()) || Q(S, y(n, l, S));
763
+ }, g = tt(s.mode), k = tt(s.reValidateMode);
764
+ if (f) {
765
+ let S, Y;
766
+ const ve = a.type ? et(f._f) : lt(r), se = r.type === be.BLUR || r.type === be.FOCUS_OUT, wt = !qt(f._f) && !s.resolver && !y(t.errors, l) && !f._f.deps || jt(se, y(t.touchedFields, l), t.isSubmitted, k, g), De = st(l, c, se);
767
+ C(n, l, ve), se ? (!a || !a.readOnly) && (f._f.onBlur && f._f.onBlur(r), w && w(0)) : f._f.onChange && f._f.onChange(r);
768
+ const Ee = A(l, ve, se), kt = !W(Ee) || De;
769
+ if (!se && v.state.next({
770
+ name: l,
771
+ type: r.type,
772
+ values: U(n)
773
+ }), wt)
774
+ return (V.isValid || b.isValid) && (s.mode === "onBlur" ? se && R() : se || R()), kt && v.state.next({ name: l, ...De ? {} : Ee });
775
+ if (!se && De && v.state.next({ ...t }), s.resolver) {
776
+ const { errors: ze } = await K([l]);
777
+ if (o(ve), h) {
778
+ const Dt = it(t.errors, i, l), Ge = it(ze, i, Dt.name || l);
779
+ S = Ge.error, l = Ge.name, Y = W(ze);
780
+ }
781
+ } else
782
+ B([l], !0), S = (await nt(f, c.disabled, n, p, s.shouldUseNativeValidation))[l], B([l]), o(ve), h && (S ? Y = !1 : (V.isValid || b.isValid) && (Y = await I(i, !0)));
783
+ h && (f._f.deps && (!Array.isArray(f._f.deps) || f._f.deps.length > 0) && ne(f._f.deps), j(l, Y, S, Ee));
784
+ }
785
+ }, de = (r, a) => {
786
+ if (y(t.errors, a) && r.focus)
787
+ return r.focus(), 1;
788
+ }, ne = async (r, a = {}) => {
789
+ let l, h;
790
+ const f = fe(r);
791
+ if (s.resolver) {
792
+ const o = await oe(O(r) ? r : f);
793
+ l = W(o), h = r ? !f.some((g) => y(o, g)) : l;
794
+ } else r ? (h = (await Promise.all(f.map(async (o) => {
795
+ const g = y(i, o);
796
+ return await I(g && g._f ? { [o]: g } : g);
797
+ }))).every(Boolean), !(!h && !t.isValid) && R()) : h = l = await I(i);
798
+ return v.state.next({
799
+ ...!G(r) || (V.isValid || b.isValid) && l !== t.isValid ? {} : { name: r },
800
+ ...s.resolver || !r ? { isValid: l } : {},
801
+ errors: t.errors
802
+ }), a.shouldFocus && !h && ye(i, de, r ? f : c.mount), h;
803
+ }, ge = (r, a) => {
804
+ let l = {
805
+ ...d.mount ? n : u
806
+ };
807
+ return a && (l = ct(a.dirtyFields ? t.dirtyFields : t.touchedFields, l)), O(r) ? l : G(r) ? y(l, r) : r.map((h) => y(l, h));
808
+ }, Ie = (r, a) => ({
809
+ invalid: !!y((a || t).errors, r),
810
+ isDirty: !!y((a || t).dirtyFields, r),
811
+ error: y((a || t).errors, r),
812
+ isValidating: !!y(t.validatingFields, r),
813
+ isTouched: !!y((a || t).touchedFields, r)
814
+ }), _t = (r) => {
815
+ r && fe(r).forEach((a) => L(t.errors, a)), v.state.next({
816
+ errors: r ? t.errors : {}
817
+ });
818
+ }, Pe = (r, a, l) => {
819
+ const h = (y(i, r, { _f: {} })._f || {}).ref, f = y(t.errors, r) || {}, { ref: o, message: g, type: k, ...S } = f;
820
+ C(t.errors, r, {
821
+ ...S,
822
+ ...a,
823
+ ref: h
824
+ }), v.state.next({
825
+ name: r,
826
+ errors: t.errors,
827
+ isValid: !1
828
+ }), l && l.shouldFocus && h && h.focus && h.focus();
829
+ }, bt = (r, a) => X(r) ? v.state.subscribe({
830
+ next: (l) => "values" in l && r(x(void 0, a), l)
831
+ }) : x(r, a, !0), We = (r) => v.state.subscribe({
832
+ next: (a) => {
833
+ $t(r.name, a.name, r.exact) && Ht(a, r.formState || V, xt, r.reRenderRoot) && r.callback({
834
+ values: { ...n },
835
+ ...t,
836
+ ...a,
837
+ defaultValues: u
838
+ });
839
+ }
840
+ }).unsubscribe, mt = (r) => (d.mount = !0, b = {
841
+ ...b,
842
+ ...r.formState
843
+ }, We({
844
+ ...r,
845
+ formState: b
846
+ })), xe = (r, a = {}) => {
847
+ for (const l of r ? fe(r) : c.mount)
848
+ c.mount.delete(l), c.array.delete(l), a.keepValue || (L(i, l), L(n, l)), !a.keepError && L(t.errors, l), !a.keepDirty && L(t.dirtyFields, l), !a.keepTouched && L(t.touchedFields, l), !a.keepIsValidating && L(t.validatingFields, l), !s.shouldUnregister && !a.keepDefaultValue && L(u, l);
849
+ v.state.next({
850
+ values: U(n)
851
+ }), v.state.next({
852
+ ...t,
853
+ ...a.keepDirty ? { isDirty: ee() } : {}
854
+ }), !a.keepIsValid && R();
855
+ }, qe = ({ disabled: r, name: a }) => {
856
+ (z(r) && d.mount || r || c.disabled.has(a)) && (r ? c.disabled.add(a) : c.disabled.delete(a));
857
+ }, we = (r, a = {}) => {
858
+ let l = y(i, r);
859
+ const h = z(a.disabled) || z(s.disabled);
860
+ return C(i, r, {
861
+ ...l || {},
862
+ _f: {
863
+ ...l && l._f ? l._f : { ref: { name: r } },
864
+ name: r,
865
+ mount: !0,
866
+ ...a
867
+ }
868
+ }), c.mount.add(r), l ? qe({
869
+ disabled: z(a.disabled) ? a.disabled : s.disabled,
870
+ name: r
871
+ }) : F(r, !0, a.value), {
872
+ ...h ? { disabled: a.disabled || s.disabled } : {},
873
+ ...s.progressive ? {
874
+ required: !!a.required,
875
+ min: ce(a.min),
876
+ max: ce(a.max),
877
+ minLength: ce(a.minLength),
878
+ maxLength: ce(a.maxLength),
879
+ pattern: ce(a.pattern)
880
+ } : {},
881
+ name: r,
882
+ onChange: te,
883
+ onBlur: te,
884
+ ref: (f) => {
885
+ if (f) {
886
+ we(r, a), l = y(i, r);
887
+ const o = O(f.value) && f.querySelectorAll && f.querySelectorAll("input,select,textarea")[0] || f, g = pt(o), k = l._f.refs || [];
888
+ if (g ? k.find((S) => S === o) : o === l._f.ref)
889
+ return;
890
+ C(i, r, {
891
+ _f: {
892
+ ...l._f,
893
+ ...g ? {
894
+ refs: [
895
+ ...k.filter(Se),
896
+ o,
897
+ ...Array.isArray(y(u, r)) ? [{}] : []
898
+ ],
899
+ ref: { type: o.type, name: r }
900
+ } : { ref: o }
901
+ }
902
+ }), F(r, !1, void 0, o);
903
+ } else
904
+ l = y(i, r, {}), l._f && (l._f.mount = !1), (s.shouldUnregister || a.shouldUnregister) && !(ot(c.array, r) && d.action) && c.unMount.add(r);
905
+ }
906
+ };
907
+ }, ke = () => s.shouldFocusError && ye(i, de, c.mount), Vt = (r) => {
908
+ z(r) && (v.state.next({ disabled: r }), ye(i, (a, l) => {
909
+ const h = y(i, l);
910
+ h && (a.disabled = h._f.disabled || r, Array.isArray(h._f.refs) && h._f.refs.forEach((f) => {
911
+ f.disabled = h._f.disabled || r;
912
+ }));
913
+ }, 0, !1));
914
+ }, He = (r, a) => async (l) => {
915
+ let h;
916
+ l && (l.preventDefault && l.preventDefault(), l.persist && l.persist());
917
+ let f = U(n);
918
+ if (v.state.next({
919
+ isSubmitting: !0
920
+ }), s.resolver) {
921
+ const { errors: o, values: g } = await K();
922
+ t.errors = o, f = U(g);
923
+ } else
924
+ await I(i);
925
+ if (c.disabled.size)
926
+ for (const o of c.disabled)
927
+ L(f, o);
928
+ if (L(t.errors, "root"), W(t.errors)) {
929
+ v.state.next({
930
+ errors: {}
931
+ });
932
+ try {
933
+ await r(f, l);
934
+ } catch (o) {
935
+ h = o;
936
+ }
937
+ } else
938
+ a && await a({ ...t.errors }, l), ke(), setTimeout(ke);
939
+ if (v.state.next({
940
+ isSubmitted: !0,
941
+ isSubmitting: !1,
942
+ isSubmitSuccessful: W(t.errors) && !h,
943
+ submitCount: t.submitCount + 1,
944
+ errors: t.errors
945
+ }), h)
946
+ throw h;
947
+ }, Ft = (r, a = {}) => {
948
+ y(i, r) && (O(a.defaultValue) ? H(r, U(y(u, r))) : (H(r, a.defaultValue), C(u, r, U(a.defaultValue))), a.keepTouched || L(t.touchedFields, r), a.keepDirty || (L(t.dirtyFields, r), t.isDirty = a.defaultValue ? ee(r, U(y(u, r))) : ee()), a.keepError || (L(t.errors, r), V.isValid && R()), v.state.next({ ...t }));
949
+ }, $e = (r, a = {}) => {
950
+ const l = r ? U(r) : u, h = U(l), f = W(r), o = f ? u : h;
951
+ if (a.keepDefaultValues || (u = l), !a.keepValues) {
952
+ if (a.keepDirtyValues) {
953
+ const g = /* @__PURE__ */ new Set([
954
+ ...c.mount,
955
+ ...Object.keys(le(u, n))
956
+ ]);
957
+ for (const k of Array.from(g))
958
+ y(t.dirtyFields, k) ? C(o, k, y(n, k)) : H(k, y(o, k));
959
+ } else {
960
+ if (Te && O(r))
961
+ for (const g of c.mount) {
962
+ const k = y(i, g);
963
+ if (k && k._f) {
964
+ const S = Array.isArray(k._f.refs) ? k._f.refs[0] : k._f.ref;
965
+ if (me(S)) {
966
+ const Y = S.closest("form");
967
+ if (Y) {
968
+ Y.reset();
969
+ break;
970
+ }
971
+ }
972
+ }
973
+ }
974
+ if (a.keepFieldsRef)
975
+ for (const g of c.mount)
976
+ H(g, y(o, g));
977
+ else
978
+ i = {};
979
+ }
980
+ n = s.shouldUnregister ? a.keepDefaultValues ? U(u) : {} : U(o), v.array.next({
981
+ values: { ...o }
982
+ }), v.state.next({
983
+ values: { ...o }
984
+ });
985
+ }
986
+ c = {
987
+ mount: a.keepDirtyValues ? c.mount : /* @__PURE__ */ new Set(),
988
+ unMount: /* @__PURE__ */ new Set(),
989
+ array: /* @__PURE__ */ new Set(),
990
+ disabled: /* @__PURE__ */ new Set(),
991
+ watch: /* @__PURE__ */ new Set(),
992
+ watchAll: !1,
993
+ focus: ""
994
+ }, d.mount = !V.isValid || !!a.keepIsValid || !!a.keepDirtyValues || !s.shouldUnregister && !W(o), d.watch = !!s.shouldUnregister, d.action = !1, a.keepErrors || (t.errors = {}), v.state.next({
995
+ submitCount: a.keepSubmitCount ? t.submitCount : 0,
996
+ isDirty: f ? !1 : a.keepDirty ? t.isDirty : !!(a.keepDefaultValues && !Q(r, u)),
997
+ isSubmitted: a.keepIsSubmitted ? t.isSubmitted : !1,
998
+ dirtyFields: f ? {} : a.keepDirtyValues ? a.keepDefaultValues && n ? le(u, n) : t.dirtyFields : a.keepDefaultValues && r ? le(u, r) : a.keepDirty ? t.dirtyFields : {},
999
+ touchedFields: a.keepTouched ? t.touchedFields : {},
1000
+ errors: a.keepErrors ? t.errors : {},
1001
+ isSubmitSuccessful: a.keepIsSubmitSuccessful ? t.isSubmitSuccessful : !1,
1002
+ isSubmitting: !1,
1003
+ defaultValues: u
1004
+ });
1005
+ }, je = (r, a) => $e(X(r) ? r(n) : r, a), At = (r, a = {}) => {
1006
+ const l = y(i, r), h = l && l._f;
1007
+ if (h) {
1008
+ const f = h.refs ? h.refs[0] : h.ref;
1009
+ f.focus && (f.focus(), a.shouldSelect && X(f.select) && f.select());
1010
+ }
1011
+ }, xt = (r) => {
1012
+ t = {
1013
+ ...t,
1014
+ ...r
1015
+ };
1016
+ }, Ke = {
1017
+ control: {
1018
+ register: we,
1019
+ unregister: xe,
1020
+ getFieldState: Ie,
1021
+ handleSubmit: He,
1022
+ setError: Pe,
1023
+ _subscribe: We,
1024
+ _runSchema: K,
1025
+ _focusError: ke,
1026
+ _getWatch: x,
1027
+ _getDirty: ee,
1028
+ _setValid: R,
1029
+ _setFieldArray: Z,
1030
+ _setDisabledField: qe,
1031
+ _setErrors: N,
1032
+ _getFieldArray: D,
1033
+ _reset: $e,
1034
+ _resetDefaultValues: () => X(s.defaultValues) && s.defaultValues().then((r) => {
1035
+ je(r, s.resetOptions), v.state.next({
1036
+ isLoading: !1
1037
+ });
1038
+ }),
1039
+ _removeUnmounted: ie,
1040
+ _disableForm: Vt,
1041
+ _subjects: v,
1042
+ _proxyFormState: V,
1043
+ get _fields() {
1044
+ return i;
1045
+ },
1046
+ get _formValues() {
1047
+ return n;
1048
+ },
1049
+ get _state() {
1050
+ return d;
1051
+ },
1052
+ set _state(r) {
1053
+ d = r;
1054
+ },
1055
+ get _defaultValues() {
1056
+ return u;
1057
+ },
1058
+ get _names() {
1059
+ return c;
1060
+ },
1061
+ set _names(r) {
1062
+ c = r;
1063
+ },
1064
+ get _formState() {
1065
+ return t;
1066
+ },
1067
+ get _options() {
1068
+ return s;
1069
+ },
1070
+ set _options(r) {
1071
+ s = {
1072
+ ...s,
1073
+ ...r
1074
+ };
1075
+ }
1076
+ },
1077
+ subscribe: mt,
1078
+ trigger: ne,
1079
+ register: we,
1080
+ handleSubmit: He,
1081
+ watch: bt,
1082
+ setValue: H,
1083
+ getValues: ge,
1084
+ reset: je,
1085
+ resetField: Ft,
1086
+ clearErrors: _t,
1087
+ unregister: xe,
1088
+ setError: Pe,
1089
+ setFocus: At,
1090
+ getFieldState: Ie
1091
+ };
1092
+ return {
1093
+ ...Ke,
1094
+ formControl: Ke
1095
+ };
1096
+ }
1097
+ function Jt(e = {}) {
1098
+ const s = _.useRef(void 0), t = _.useRef(void 0), [i, u] = _.useState({
1099
+ isDirty: !1,
1100
+ isValidating: !1,
1101
+ isLoading: X(e.defaultValues),
1102
+ isSubmitted: !1,
1103
+ isSubmitting: !1,
1104
+ isSubmitSuccessful: !1,
1105
+ isValid: !1,
1106
+ submitCount: 0,
1107
+ dirtyFields: {},
1108
+ touchedFields: {},
1109
+ validatingFields: {},
1110
+ errors: e.errors || {},
1111
+ disabled: e.disabled || !1,
1112
+ isReady: !1,
1113
+ defaultValues: X(e.defaultValues) ? void 0 : e.defaultValues
1114
+ });
1115
+ if (!s.current)
1116
+ if (e.formControl)
1117
+ s.current = {
1118
+ ...e.formControl,
1119
+ formState: i
1120
+ }, e.defaultValues && !X(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
1121
+ else {
1122
+ const { formControl: d, ...c } = Yt(e);
1123
+ s.current = {
1124
+ ...c,
1125
+ formState: i
1126
+ };
1127
+ }
1128
+ const n = s.current.control;
1129
+ return n._options = e, pe(() => {
1130
+ const d = n._subscribe({
1131
+ formState: n._proxyFormState,
1132
+ callback: () => u({ ...n._formState }),
1133
+ reRenderRoot: !0
1134
+ });
1135
+ return u((c) => ({
1136
+ ...c,
1137
+ isReady: !0
1138
+ })), n._formState.isReady = !0, d;
1139
+ }, [n]), _.useEffect(() => n._disableForm(e.disabled), [n, e.disabled]), _.useEffect(() => {
1140
+ e.mode && (n._options.mode = e.mode), e.reValidateMode && (n._options.reValidateMode = e.reValidateMode);
1141
+ }, [n, e.mode, e.reValidateMode]), _.useEffect(() => {
1142
+ e.errors && (n._setErrors(e.errors), n._focusError());
1143
+ }, [n, e.errors]), _.useEffect(() => {
1144
+ e.shouldUnregister && n._subjects.state.next({
1145
+ values: n._getWatch()
1146
+ });
1147
+ }, [n, e.shouldUnregister]), _.useEffect(() => {
1148
+ if (n._proxyFormState.isDirty) {
1149
+ const d = n._getDirty();
1150
+ d !== i.isDirty && n._subjects.state.next({
1151
+ isDirty: d
1152
+ });
1153
+ }
1154
+ }, [n, i.isDirty]), _.useEffect(() => {
1155
+ var d;
1156
+ e.values && !Q(e.values, t.current) ? (n._reset(e.values, {
1157
+ keepFieldsRef: !0,
1158
+ ...n._options.resetOptions
1159
+ }), !((d = n._options.resetOptions) === null || d === void 0) && d.keepIsValid || n._setValid(), t.current = e.values, u((c) => ({ ...c }))) : n._resetDefaultValues();
1160
+ }, [n, e.values]), _.useEffect(() => {
1161
+ n._state.mount || (n._setValid(), n._state.mount = !0), n._state.watch && (n._state.watch = !1, n._subjects.state.next({ ...n._formState })), n._removeUnmounted();
1162
+ }), s.current.formState = dt(i, n), s.current;
1163
+ }
1164
+ const Qt = ({
1165
+ children: e,
1166
+ onSubmit: s = () => {
1167
+ },
1168
+ style: t = {},
1169
+ className: i = "",
1170
+ formOptions: u
1171
+ }) => {
1172
+ const n = Jt({
1173
+ mode: "onSubmit",
1174
+ reValidateMode: "onChange",
1175
+ shouldFocusError: !0,
1176
+ ...u
1177
+ });
1178
+ return /* @__PURE__ */ _e(Rt, { ...n, children: /* @__PURE__ */ _e(
1179
+ "form",
1180
+ {
1181
+ noValidate: !0,
1182
+ onSubmit: n.handleSubmit(s),
1183
+ style: t,
1184
+ className: i,
1185
+ children: e
1186
+ }
1187
+ ) });
1188
+ }, Xt = ({
1189
+ children: e,
1190
+ name: s,
1191
+ rules: t
1192
+ }) => {
1193
+ const { control: i } = Ae();
1194
+ return /* @__PURE__ */ _e(
1195
+ Mt,
1196
+ {
1197
+ control: i,
1198
+ name: s,
1199
+ rules: t,
1200
+ render: (u) => /* @__PURE__ */ _e(Zt, { ...u, children: e })
1201
+ }
1202
+ );
1203
+ }, Zt = ({
1204
+ field: e,
1205
+ fieldState: s,
1206
+ children: t
1207
+ }) => {
1208
+ const { onChange: i, onBlur: u, value: n, name: d, disabled: c } = e, { error: w } = s, E = t.props.onChange, V = t.props.onBlur, b = Ye(
1209
+ (...p) => {
1210
+ i(...p), E == null || E(...p);
1211
+ },
1212
+ [i, E]
1213
+ ), v = Ye(
1214
+ (...p) => {
1215
+ u(), V == null || V(...p);
1216
+ },
1217
+ [u, V]
1218
+ );
1219
+ return Et(t, {
1220
+ ...t.props,
1221
+ name: d,
1222
+ disabled: c,
1223
+ onChange: b,
1224
+ value: n || t.props.value,
1225
+ onBlur: v,
1226
+ error: w
1227
+ });
1228
+ };
1229
+ Qt.Control = Xt;
1230
+ export {
1231
+ Qt as SuprForm
1232
+ };
1233
+ //# sourceMappingURL=suprform.es.js.map