@scbt-ecom/ui 0.63.1 → 0.64.1

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