suprform 1.0.7 → 1.0.9
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.
- package/dist/components/SuprForm.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/suprform.cjs.js +1 -1
- package/dist/suprform.cjs.js.map +1 -1
- package/dist/suprform.es.js +1466 -1
- package/dist/suprform.es.js.map +1 -1
- package/package.json +1 -1
package/dist/suprform.es.js
CHANGED
|
@@ -1,2 +1,1467 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as ne, Fragment as jr, jsxs as cr } from "react/jsx-runtime";
|
|
2
|
+
import F, { createContext as Qr, useContext as Gr, useMemo as We, useImperativeHandle as Fr, cloneElement as He, Children as zr, isValidElement as Kr } from "react";
|
|
3
|
+
var ve = (e) => e.type === "checkbox", le = (e) => e instanceof Date, G = (e) => e == null;
|
|
4
|
+
const br = (e) => typeof e == "object";
|
|
5
|
+
var M = (e) => !G(e) && !Array.isArray(e) && br(e) && !le(e), Ar = (e) => M(e) && e.target ? ve(e.target) ? e.target.checked : e.target.value : e, Yr = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, pr = (e, t) => e.has(Yr(t)), Jr = (e) => {
|
|
6
|
+
const t = e.constructor && e.constructor.prototype;
|
|
7
|
+
return M(t) && t.hasOwnProperty("isPrototypeOf");
|
|
8
|
+
}, ze = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
|
|
9
|
+
function U(e) {
|
|
10
|
+
let t;
|
|
11
|
+
const r = Array.isArray(e), s = typeof FileList < "u" ? e instanceof FileList : !1;
|
|
12
|
+
if (e instanceof Date)
|
|
13
|
+
t = new Date(e);
|
|
14
|
+
else if (!(ze && (e instanceof Blob || s)) && (r || M(e)))
|
|
15
|
+
if (t = r ? [] : Object.create(Object.getPrototypeOf(e)), !r && !Jr(e))
|
|
16
|
+
t = e;
|
|
17
|
+
else
|
|
18
|
+
for (const u in e)
|
|
19
|
+
e.hasOwnProperty(u) && (t[u] = U(e[u]));
|
|
20
|
+
else
|
|
21
|
+
return e;
|
|
22
|
+
return t;
|
|
23
|
+
}
|
|
24
|
+
var xe = (e) => /^\w*$/.test(e), T = (e) => e === void 0, Se = (e) => Array.isArray(e) ? e.filter(Boolean) : [], Ke = (e) => Se(e.replace(/["|']|\]/g, "").split(/\.|\[/)), m = (e, t, r) => {
|
|
25
|
+
if (!t || !M(e))
|
|
26
|
+
return r;
|
|
27
|
+
const s = (xe(t) ? [t] : Ke(t)).reduce((u, i) => G(u) ? u : u[i], e);
|
|
28
|
+
return T(s) || s === e ? T(e[t]) ? r : e[t] : s;
|
|
29
|
+
}, K = (e) => typeof e == "boolean", R = (e, t, r) => {
|
|
30
|
+
let s = -1;
|
|
31
|
+
const u = xe(t) ? [t] : Ke(t), i = u.length, l = i - 1;
|
|
32
|
+
for (; ++s < i; ) {
|
|
33
|
+
const c = u[s];
|
|
34
|
+
let v = r;
|
|
35
|
+
if (s !== l) {
|
|
36
|
+
const p = e[c];
|
|
37
|
+
v = M(p) || Array.isArray(p) ? p : isNaN(+u[s + 1]) ? {} : [];
|
|
38
|
+
}
|
|
39
|
+
if (c === "__proto__" || c === "constructor" || c === "prototype")
|
|
40
|
+
return;
|
|
41
|
+
e[c] = v, e = e[c];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const be = {
|
|
45
|
+
BLUR: "blur",
|
|
46
|
+
FOCUS_OUT: "focusout",
|
|
47
|
+
CHANGE: "change"
|
|
48
|
+
}, X = {
|
|
49
|
+
onBlur: "onBlur",
|
|
50
|
+
onChange: "onChange",
|
|
51
|
+
onSubmit: "onSubmit",
|
|
52
|
+
onTouched: "onTouched",
|
|
53
|
+
all: "all"
|
|
54
|
+
}, ae = {
|
|
55
|
+
max: "max",
|
|
56
|
+
min: "min",
|
|
57
|
+
maxLength: "maxLength",
|
|
58
|
+
minLength: "minLength",
|
|
59
|
+
pattern: "pattern",
|
|
60
|
+
required: "required",
|
|
61
|
+
validate: "validate"
|
|
62
|
+
}, Ye = F.createContext(null);
|
|
63
|
+
Ye.displayName = "HookFormContext";
|
|
64
|
+
const _e = () => F.useContext(Ye), Xr = (e) => {
|
|
65
|
+
const { children: t, ...r } = e;
|
|
66
|
+
return F.createElement(Ye.Provider, { value: r }, t);
|
|
67
|
+
};
|
|
68
|
+
var xr = (e, t, r, s = !0) => {
|
|
69
|
+
const u = {
|
|
70
|
+
defaultValues: t._defaultValues
|
|
71
|
+
};
|
|
72
|
+
for (const i in e)
|
|
73
|
+
Object.defineProperty(u, i, {
|
|
74
|
+
get: () => {
|
|
75
|
+
const l = i;
|
|
76
|
+
return t._proxyFormState[l] !== X.all && (t._proxyFormState[l] = !s || X.all), r && (r[l] = !0), e[l];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return u;
|
|
80
|
+
};
|
|
81
|
+
const Ee = typeof window < "u" ? F.useLayoutEffect : F.useEffect;
|
|
82
|
+
function Zr(e) {
|
|
83
|
+
const t = _e(), { control: r = t.control, disabled: s, name: u, exact: i } = e || {}, [l, c] = F.useState(r._formState), v = F.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 Ee(() => r._subscribe({
|
|
94
|
+
name: u,
|
|
95
|
+
formState: v.current,
|
|
96
|
+
exact: i,
|
|
97
|
+
callback: (p) => {
|
|
98
|
+
!s && c({
|
|
99
|
+
...r._formState,
|
|
100
|
+
...p
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}), [u, s, i]), F.useEffect(() => {
|
|
104
|
+
v.current.isValid && r._setValid(!0);
|
|
105
|
+
}, [r]), F.useMemo(() => xr(l, r, v.current, !1), [l, r]);
|
|
106
|
+
}
|
|
107
|
+
var Y = (e) => typeof e == "string", $e = (e, t, r, s, u) => Y(e) ? (s && t.watch.add(e), m(r, e, u)) : Array.isArray(e) ? e.map((i) => (s && t.watch.add(i), m(r, i))) : (s && (t.watchAll = !0), r), qe = (e) => G(e) || !br(e);
|
|
108
|
+
function ee(e, t, r = /* @__PURE__ */ new WeakSet()) {
|
|
109
|
+
if (qe(e) || qe(t))
|
|
110
|
+
return Object.is(e, t);
|
|
111
|
+
if (le(e) && le(t))
|
|
112
|
+
return e.getTime() === t.getTime();
|
|
113
|
+
const s = Object.keys(e), u = Object.keys(t);
|
|
114
|
+
if (s.length !== u.length)
|
|
115
|
+
return !1;
|
|
116
|
+
if (r.has(e) || r.has(t))
|
|
117
|
+
return !0;
|
|
118
|
+
r.add(e), r.add(t);
|
|
119
|
+
for (const i of s) {
|
|
120
|
+
const l = e[i];
|
|
121
|
+
if (!u.includes(i))
|
|
122
|
+
return !1;
|
|
123
|
+
if (i !== "ref") {
|
|
124
|
+
const c = t[i];
|
|
125
|
+
if (le(l) && le(c) || M(l) && M(c) || Array.isArray(l) && Array.isArray(c) ? !ee(l, c, r) : !Object.is(l, c))
|
|
126
|
+
return !1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return !0;
|
|
130
|
+
}
|
|
131
|
+
function Sr(e) {
|
|
132
|
+
const t = _e(), { control: r = t.control, name: s, defaultValue: u, disabled: i, exact: l, compute: c } = e || {}, v = F.useRef(u), p = F.useRef(c), V = F.useRef(void 0), g = F.useRef(r), b = F.useRef(s);
|
|
133
|
+
p.current = c;
|
|
134
|
+
const [H, I] = F.useState(() => {
|
|
135
|
+
const f = r._getWatch(s, v.current);
|
|
136
|
+
return p.current ? p.current(f) : f;
|
|
137
|
+
}), C = F.useCallback((f) => {
|
|
138
|
+
const y = $e(s, r._names, f || r._formValues, !1, v.current);
|
|
139
|
+
return p.current ? p.current(y) : y;
|
|
140
|
+
}, [r._formValues, r._names, s]), B = F.useCallback((f) => {
|
|
141
|
+
if (!i) {
|
|
142
|
+
const y = $e(s, r._names, f || r._formValues, !1, v.current);
|
|
143
|
+
if (p.current) {
|
|
144
|
+
const x = p.current(y);
|
|
145
|
+
ee(x, V.current) || (I(x), V.current = x);
|
|
146
|
+
} else
|
|
147
|
+
I(y);
|
|
148
|
+
}
|
|
149
|
+
}, [r._formValues, r._names, i, s]);
|
|
150
|
+
Ee(() => ((g.current !== r || !ee(b.current, s)) && (g.current = r, b.current = s, B()), r._subscribe({
|
|
151
|
+
name: s,
|
|
152
|
+
formState: {
|
|
153
|
+
values: !0
|
|
154
|
+
},
|
|
155
|
+
exact: l,
|
|
156
|
+
callback: (f) => {
|
|
157
|
+
B(f.values);
|
|
158
|
+
}
|
|
159
|
+
})), [r, l, s, B]), F.useEffect(() => r._removeUnmounted());
|
|
160
|
+
const j = g.current !== r, S = b.current, P = F.useMemo(() => {
|
|
161
|
+
if (i)
|
|
162
|
+
return null;
|
|
163
|
+
const f = !j && !ee(S, s);
|
|
164
|
+
return j || f ? C() : null;
|
|
165
|
+
}, [i, j, s, S, C]);
|
|
166
|
+
return P !== null ? P : H;
|
|
167
|
+
}
|
|
168
|
+
function et(e) {
|
|
169
|
+
const t = _e(), { name: r, disabled: s, control: u = t.control, shouldUnregister: i, defaultValue: l, exact: c = !0 } = e, v = pr(u._names.array, r), p = F.useMemo(() => m(u._formValues, r, m(u._defaultValues, r, l)), [u, r, l]), V = Sr({
|
|
170
|
+
control: u,
|
|
171
|
+
name: r,
|
|
172
|
+
defaultValue: p,
|
|
173
|
+
exact: c
|
|
174
|
+
}), g = Zr({
|
|
175
|
+
control: u,
|
|
176
|
+
name: r,
|
|
177
|
+
exact: c
|
|
178
|
+
}), b = F.useRef(e), H = F.useRef(void 0), I = F.useRef(u.register(r, {
|
|
179
|
+
...e.rules,
|
|
180
|
+
value: V,
|
|
181
|
+
...K(e.disabled) ? { disabled: e.disabled } : {}
|
|
182
|
+
}));
|
|
183
|
+
b.current = e;
|
|
184
|
+
const C = F.useMemo(() => Object.defineProperties({}, {
|
|
185
|
+
invalid: {
|
|
186
|
+
enumerable: !0,
|
|
187
|
+
get: () => !!m(g.errors, r)
|
|
188
|
+
},
|
|
189
|
+
isDirty: {
|
|
190
|
+
enumerable: !0,
|
|
191
|
+
get: () => !!m(g.dirtyFields, r)
|
|
192
|
+
},
|
|
193
|
+
isTouched: {
|
|
194
|
+
enumerable: !0,
|
|
195
|
+
get: () => !!m(g.touchedFields, r)
|
|
196
|
+
},
|
|
197
|
+
isValidating: {
|
|
198
|
+
enumerable: !0,
|
|
199
|
+
get: () => !!m(g.validatingFields, r)
|
|
200
|
+
},
|
|
201
|
+
error: {
|
|
202
|
+
enumerable: !0,
|
|
203
|
+
get: () => m(g.errors, r)
|
|
204
|
+
}
|
|
205
|
+
}), [g, r]), B = F.useCallback((f) => I.current.onChange({
|
|
206
|
+
target: {
|
|
207
|
+
value: Ar(f),
|
|
208
|
+
name: r
|
|
209
|
+
},
|
|
210
|
+
type: be.CHANGE
|
|
211
|
+
}), [r]), j = F.useCallback(() => I.current.onBlur({
|
|
212
|
+
target: {
|
|
213
|
+
value: m(u._formValues, r),
|
|
214
|
+
name: r
|
|
215
|
+
},
|
|
216
|
+
type: be.BLUR
|
|
217
|
+
}), [r, u._formValues]), S = F.useCallback((f) => {
|
|
218
|
+
const y = m(u._fields, r);
|
|
219
|
+
y && f && (y._f.ref = {
|
|
220
|
+
focus: () => f.focus && f.focus(),
|
|
221
|
+
select: () => f.select && f.select(),
|
|
222
|
+
setCustomValidity: (x) => f.setCustomValidity(x),
|
|
223
|
+
reportValidity: () => f.reportValidity()
|
|
224
|
+
});
|
|
225
|
+
}, [u._fields, r]), P = F.useMemo(() => ({
|
|
226
|
+
name: r,
|
|
227
|
+
value: V,
|
|
228
|
+
...K(s) || g.disabled ? { disabled: g.disabled || s } : {},
|
|
229
|
+
onChange: B,
|
|
230
|
+
onBlur: j,
|
|
231
|
+
ref: S
|
|
232
|
+
}), [r, s, g.disabled, B, j, S, V]);
|
|
233
|
+
return F.useEffect(() => {
|
|
234
|
+
const f = u._options.shouldUnregister || i, y = H.current;
|
|
235
|
+
y && y !== r && !v && u.unregister(y), u.register(r, {
|
|
236
|
+
...b.current.rules,
|
|
237
|
+
...K(b.current.disabled) ? { disabled: b.current.disabled } : {}
|
|
238
|
+
});
|
|
239
|
+
const x = (E, Z) => {
|
|
240
|
+
const W = m(u._fields, E);
|
|
241
|
+
W && W._f && (W._f.mount = Z);
|
|
242
|
+
};
|
|
243
|
+
if (x(r, !0), f) {
|
|
244
|
+
const E = U(m(u._options.defaultValues, r, b.current.defaultValue));
|
|
245
|
+
R(u._defaultValues, r, E), T(m(u._formValues, r)) && R(u._formValues, r, E);
|
|
246
|
+
}
|
|
247
|
+
return !v && u.register(r), H.current = r, () => {
|
|
248
|
+
(v ? f && !u._state.action : f) ? u.unregister(r) : x(r, !1);
|
|
249
|
+
};
|
|
250
|
+
}, [r, u, v, i]), F.useEffect(() => {
|
|
251
|
+
u._setDisabledField({
|
|
252
|
+
disabled: s,
|
|
253
|
+
name: r
|
|
254
|
+
});
|
|
255
|
+
}, [s, r, u]), F.useMemo(() => ({
|
|
256
|
+
field: P,
|
|
257
|
+
formState: g,
|
|
258
|
+
fieldState: C
|
|
259
|
+
}), [P, g, C]);
|
|
260
|
+
}
|
|
261
|
+
const rt = (e) => e.render(et(e));
|
|
262
|
+
var tt = (e, t, r, s, u) => t ? {
|
|
263
|
+
...r[e],
|
|
264
|
+
types: {
|
|
265
|
+
...r[e] && r[e].types ? r[e].types : {},
|
|
266
|
+
[s]: u || !0
|
|
267
|
+
}
|
|
268
|
+
} : {}, z = (e) => Array.isArray(e) ? e : [e], dr = () => {
|
|
269
|
+
let e = [];
|
|
270
|
+
return {
|
|
271
|
+
get observers() {
|
|
272
|
+
return e;
|
|
273
|
+
},
|
|
274
|
+
next: (u) => {
|
|
275
|
+
for (const i of e)
|
|
276
|
+
i.next && i.next(u);
|
|
277
|
+
},
|
|
278
|
+
subscribe: (u) => (e.push(u), {
|
|
279
|
+
unsubscribe: () => {
|
|
280
|
+
e = e.filter((i) => i !== u);
|
|
281
|
+
}
|
|
282
|
+
}),
|
|
283
|
+
unsubscribe: () => {
|
|
284
|
+
e = [];
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
function Er(e, t) {
|
|
289
|
+
const r = {};
|
|
290
|
+
for (const s in e)
|
|
291
|
+
if (e.hasOwnProperty(s)) {
|
|
292
|
+
const u = e[s], i = t[s];
|
|
293
|
+
if (u && M(u) && i) {
|
|
294
|
+
const l = Er(u, i);
|
|
295
|
+
M(l) && (r[s] = l);
|
|
296
|
+
} else e[s] && (r[s] = i);
|
|
297
|
+
}
|
|
298
|
+
return r;
|
|
299
|
+
}
|
|
300
|
+
var $ = (e) => M(e) && !Object.keys(e).length, Je = (e) => e.type === "file", re = (e) => typeof e == "function", Ae = (e) => {
|
|
301
|
+
if (!ze)
|
|
302
|
+
return !1;
|
|
303
|
+
const t = e ? e.ownerDocument : 0;
|
|
304
|
+
return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
|
|
305
|
+
}, wr = (e) => e.type === "select-multiple", Xe = (e) => e.type === "radio", st = (e) => Xe(e) || ve(e), Oe = (e) => Ae(e) && e.isConnected;
|
|
306
|
+
function at(e, t) {
|
|
307
|
+
const r = t.slice(0, -1).length;
|
|
308
|
+
let s = 0;
|
|
309
|
+
for (; s < r; )
|
|
310
|
+
e = T(e) ? s++ : e[t[s++]];
|
|
311
|
+
return e;
|
|
312
|
+
}
|
|
313
|
+
function nt(e) {
|
|
314
|
+
for (const t in e)
|
|
315
|
+
if (e.hasOwnProperty(t) && !T(e[t]))
|
|
316
|
+
return !1;
|
|
317
|
+
return !0;
|
|
318
|
+
}
|
|
319
|
+
function L(e, t) {
|
|
320
|
+
const r = Array.isArray(t) ? t : xe(t) ? [t] : Ke(t), s = r.length === 1 ? e : at(e, r), u = r.length - 1, i = r[u];
|
|
321
|
+
return s && delete s[i], u !== 0 && (M(s) && $(s) || Array.isArray(s) && nt(s)) && L(e, r.slice(0, -1)), e;
|
|
322
|
+
}
|
|
323
|
+
var it = (e) => {
|
|
324
|
+
for (const t in e)
|
|
325
|
+
if (re(e[t]))
|
|
326
|
+
return !0;
|
|
327
|
+
return !1;
|
|
328
|
+
};
|
|
329
|
+
function Cr(e) {
|
|
330
|
+
return Array.isArray(e) || M(e) && !it(e);
|
|
331
|
+
}
|
|
332
|
+
function je(e, t = {}) {
|
|
333
|
+
for (const r in e) {
|
|
334
|
+
const s = e[r];
|
|
335
|
+
Cr(s) ? (t[r] = Array.isArray(s) ? [] : {}, je(s, t[r])) : T(s) || (t[r] = !0);
|
|
336
|
+
}
|
|
337
|
+
return t;
|
|
338
|
+
}
|
|
339
|
+
function fe(e, t, r) {
|
|
340
|
+
r || (r = je(t));
|
|
341
|
+
for (const s in e) {
|
|
342
|
+
const u = e[s];
|
|
343
|
+
if (Cr(u))
|
|
344
|
+
T(t) || qe(r[s]) ? r[s] = je(u, Array.isArray(u) ? [] : {}) : fe(u, G(t) ? {} : t[s], r[s]);
|
|
345
|
+
else {
|
|
346
|
+
const i = t[s];
|
|
347
|
+
r[s] = !ee(u, i);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return r;
|
|
351
|
+
}
|
|
352
|
+
const fr = {
|
|
353
|
+
value: !1,
|
|
354
|
+
isValid: !1
|
|
355
|
+
}, yr = { value: !0, isValid: !0 };
|
|
356
|
+
var kr = (e) => {
|
|
357
|
+
if (Array.isArray(e)) {
|
|
358
|
+
if (e.length > 1) {
|
|
359
|
+
const t = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
|
|
360
|
+
return { value: t, isValid: !!t.length };
|
|
361
|
+
}
|
|
362
|
+
return e[0].checked && !e[0].disabled ? (
|
|
363
|
+
// @ts-expect-error expected to work in the browser
|
|
364
|
+
e[0].attributes && !T(e[0].attributes.value) ? T(e[0].value) || e[0].value === "" ? yr : { value: e[0].value, isValid: !0 } : yr
|
|
365
|
+
) : fr;
|
|
366
|
+
}
|
|
367
|
+
return fr;
|
|
368
|
+
}, Dr = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: s }) => T(e) ? e : t ? e === "" ? NaN : e && +e : r && Y(e) ? new Date(e) : s ? s(e) : e;
|
|
369
|
+
const mr = {
|
|
370
|
+
isValid: !1,
|
|
371
|
+
value: null
|
|
372
|
+
};
|
|
373
|
+
var Rr = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
|
|
374
|
+
isValid: !0,
|
|
375
|
+
value: r.value
|
|
376
|
+
} : t, mr) : mr;
|
|
377
|
+
function _r(e) {
|
|
378
|
+
const t = e.ref;
|
|
379
|
+
return Je(t) ? t.files : Xe(t) ? Rr(e.refs).value : wr(t) ? [...t.selectedOptions].map(({ value: r }) => r) : ve(t) ? kr(e.refs).value : Dr(T(t.value) ? e.ref.value : t.value, e);
|
|
380
|
+
}
|
|
381
|
+
var ut = (e, t, r, s) => {
|
|
382
|
+
const u = {};
|
|
383
|
+
for (const i of e) {
|
|
384
|
+
const l = m(t, i);
|
|
385
|
+
l && R(u, i, l._f);
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
criteriaMode: r,
|
|
389
|
+
names: [...e],
|
|
390
|
+
fields: u,
|
|
391
|
+
shouldUseNativeValidation: s
|
|
392
|
+
};
|
|
393
|
+
}, pe = (e) => e instanceof RegExp, he = (e) => T(e) ? e : pe(e) ? e.source : M(e) ? pe(e.value) ? e.value.source : e.value : e, ye = (e) => ({
|
|
394
|
+
isOnSubmit: !e || e === X.onSubmit,
|
|
395
|
+
isOnBlur: e === X.onBlur,
|
|
396
|
+
isOnChange: e === X.onChange,
|
|
397
|
+
isOnAll: e === X.all,
|
|
398
|
+
isOnTouch: e === X.onTouched
|
|
399
|
+
});
|
|
400
|
+
const gr = "AsyncFunction";
|
|
401
|
+
var ot = (e) => !!e && !!e.validate && !!(re(e.validate) && e.validate.constructor.name === gr || M(e.validate) && Object.values(e.validate).find((t) => t.constructor.name === gr)), lt = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), Qe = (e, t, r) => !r && (t.watchAll || t.watch.has(e) || [...t.watch].some((s) => e.startsWith(s) && /^\.\w+/.test(e.slice(s.length))));
|
|
402
|
+
const me = (e, t, r, s) => {
|
|
403
|
+
for (const u of r || Object.keys(e)) {
|
|
404
|
+
const i = m(e, u);
|
|
405
|
+
if (i) {
|
|
406
|
+
const { _f: l, ...c } = i;
|
|
407
|
+
if (l) {
|
|
408
|
+
if (l.refs && l.refs[0] && t(l.refs[0], u) && !s)
|
|
409
|
+
return !0;
|
|
410
|
+
if (l.ref && t(l.ref, l.name) && !s)
|
|
411
|
+
return !0;
|
|
412
|
+
if (me(c, t))
|
|
413
|
+
break;
|
|
414
|
+
} else if (M(c) && me(c, t))
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
function hr(e, t, r) {
|
|
420
|
+
const s = m(e, r);
|
|
421
|
+
if (s || xe(r))
|
|
422
|
+
return {
|
|
423
|
+
error: s,
|
|
424
|
+
name: r
|
|
425
|
+
};
|
|
426
|
+
const u = r.split(".");
|
|
427
|
+
for (; u.length; ) {
|
|
428
|
+
const i = u.join("."), l = m(t, i), c = m(e, i);
|
|
429
|
+
if (l && !Array.isArray(l) && r !== i)
|
|
430
|
+
return { name: r };
|
|
431
|
+
if (c && c.type)
|
|
432
|
+
return {
|
|
433
|
+
name: i,
|
|
434
|
+
error: c
|
|
435
|
+
};
|
|
436
|
+
if (c && c.root && c.root.type)
|
|
437
|
+
return {
|
|
438
|
+
name: `${i}.root`,
|
|
439
|
+
error: c.root
|
|
440
|
+
};
|
|
441
|
+
u.pop();
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
name: r
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
var ct = (e, t, r, s) => {
|
|
448
|
+
r(e);
|
|
449
|
+
const { name: u, ...i } = e;
|
|
450
|
+
return $(i) || Object.keys(i).length >= Object.keys(t).length || Object.keys(i).find((l) => t[l] === (!s || X.all));
|
|
451
|
+
}, dt = (e, t, r) => !e || !t || e === t || z(e).some((s) => s && (r ? s === t : s.startsWith(t) || t.startsWith(s))), ft = (e, t, r, s, u) => u.isOnAll ? !1 : !r && u.isOnTouch ? !(t || e) : (r ? s.isOnBlur : u.isOnBlur) ? !e : (r ? s.isOnChange : u.isOnChange) ? e : !0, yt = (e, t) => !Se(m(e, t)).length && L(e, t), Or = (e, t, r) => {
|
|
452
|
+
const s = z(m(e, r));
|
|
453
|
+
return R(s, "root", t[r]), R(e, r, s), e;
|
|
454
|
+
};
|
|
455
|
+
function vr(e, t, r = "validate") {
|
|
456
|
+
if (Y(e) || Array.isArray(e) && e.every(Y) || K(e) && !e)
|
|
457
|
+
return {
|
|
458
|
+
type: r,
|
|
459
|
+
message: Y(e) ? e : "",
|
|
460
|
+
ref: t
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
var de = (e) => M(e) && !pe(e) ? e : {
|
|
464
|
+
value: e,
|
|
465
|
+
message: ""
|
|
466
|
+
}, Ge = async (e, t, r, s, u, i) => {
|
|
467
|
+
const { ref: l, refs: c, required: v, maxLength: p, minLength: V, min: g, max: b, pattern: H, validate: I, name: C, valueAsNumber: B, mount: j } = e._f, S = m(r, C);
|
|
468
|
+
if (!j || t.has(C))
|
|
469
|
+
return {};
|
|
470
|
+
const P = c ? c[0] : l, f = (w) => {
|
|
471
|
+
u && P.reportValidity && (P.setCustomValidity(K(w) ? "" : w || ""), P.reportValidity());
|
|
472
|
+
}, y = {}, x = Xe(l), E = ve(l), Z = x || E, W = (B || Je(l)) && T(l.value) && T(S) || Ae(l) && l.value === "" || S === "" || Array.isArray(S) && !S.length, oe = tt.bind(null, C, s, y), te = (w, D, N, q = ae.maxLength, Q = ae.minLength) => {
|
|
473
|
+
const se = w ? D : N;
|
|
474
|
+
y[C] = {
|
|
475
|
+
type: w ? q : Q,
|
|
476
|
+
message: se,
|
|
477
|
+
ref: l,
|
|
478
|
+
...oe(w ? q : Q, se)
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
if (i ? !Array.isArray(S) || !S.length : v && (!Z && (W || G(S)) || K(S) && !S || E && !kr(c).isValid || x && !Rr(c).isValid)) {
|
|
482
|
+
const { value: w, message: D } = Y(v) ? { value: !!v, message: v } : de(v);
|
|
483
|
+
if (w && (y[C] = {
|
|
484
|
+
type: ae.required,
|
|
485
|
+
message: D,
|
|
486
|
+
ref: P,
|
|
487
|
+
...oe(ae.required, D)
|
|
488
|
+
}, !s))
|
|
489
|
+
return f(D), y;
|
|
490
|
+
}
|
|
491
|
+
if (!W && (!G(g) || !G(b))) {
|
|
492
|
+
let w, D;
|
|
493
|
+
const N = de(b), q = de(g);
|
|
494
|
+
if (!G(S) && !isNaN(S)) {
|
|
495
|
+
const Q = l.valueAsNumber || S && +S;
|
|
496
|
+
G(N.value) || (w = Q > N.value), G(q.value) || (D = Q < q.value);
|
|
497
|
+
} else {
|
|
498
|
+
const Q = l.valueAsDate || new Date(S), se = (Ve) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + Ve), ge = l.type == "time", ce = l.type == "week";
|
|
499
|
+
Y(N.value) && S && (w = ge ? se(S) > se(N.value) : ce ? S > N.value : Q > new Date(N.value)), Y(q.value) && S && (D = ge ? se(S) < se(q.value) : ce ? S < q.value : Q < new Date(q.value));
|
|
500
|
+
}
|
|
501
|
+
if ((w || D) && (te(!!w, N.message, q.message, ae.max, ae.min), !s))
|
|
502
|
+
return f(y[C].message), y;
|
|
503
|
+
}
|
|
504
|
+
if ((p || V) && !W && (Y(S) || i && Array.isArray(S))) {
|
|
505
|
+
const w = de(p), D = de(V), N = !G(w.value) && S.length > +w.value, q = !G(D.value) && S.length < +D.value;
|
|
506
|
+
if ((N || q) && (te(N, w.message, D.message), !s))
|
|
507
|
+
return f(y[C].message), y;
|
|
508
|
+
}
|
|
509
|
+
if (H && !W && Y(S)) {
|
|
510
|
+
const { value: w, message: D } = de(H);
|
|
511
|
+
if (pe(w) && !S.match(w) && (y[C] = {
|
|
512
|
+
type: ae.pattern,
|
|
513
|
+
message: D,
|
|
514
|
+
ref: l,
|
|
515
|
+
...oe(ae.pattern, D)
|
|
516
|
+
}, !s))
|
|
517
|
+
return f(D), y;
|
|
518
|
+
}
|
|
519
|
+
if (I) {
|
|
520
|
+
if (re(I)) {
|
|
521
|
+
const w = await I(S, r), D = vr(w, P);
|
|
522
|
+
if (D && (y[C] = {
|
|
523
|
+
...D,
|
|
524
|
+
...oe(ae.validate, D.message)
|
|
525
|
+
}, !s))
|
|
526
|
+
return f(D.message), y;
|
|
527
|
+
} else if (M(I)) {
|
|
528
|
+
let w = {};
|
|
529
|
+
for (const D in I) {
|
|
530
|
+
if (!$(w) && !s)
|
|
531
|
+
break;
|
|
532
|
+
const N = vr(await I[D](S, r), P, D);
|
|
533
|
+
N && (w = {
|
|
534
|
+
...N,
|
|
535
|
+
...oe(D, N.message)
|
|
536
|
+
}, f(N.message), s && (y[C] = w));
|
|
537
|
+
}
|
|
538
|
+
if (!$(w) && (y[C] = {
|
|
539
|
+
ref: P,
|
|
540
|
+
...w
|
|
541
|
+
}, !s))
|
|
542
|
+
return y;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return f(!0), y;
|
|
546
|
+
};
|
|
547
|
+
const mt = {
|
|
548
|
+
mode: X.onSubmit,
|
|
549
|
+
reValidateMode: X.onChange,
|
|
550
|
+
shouldFocusError: !0
|
|
551
|
+
};
|
|
552
|
+
function _t(e = {}) {
|
|
553
|
+
let t = {
|
|
554
|
+
...mt,
|
|
555
|
+
...e
|
|
556
|
+
}, r = {
|
|
557
|
+
submitCount: 0,
|
|
558
|
+
isDirty: !1,
|
|
559
|
+
isReady: !1,
|
|
560
|
+
isLoading: re(t.defaultValues),
|
|
561
|
+
isValidating: !1,
|
|
562
|
+
isSubmitted: !1,
|
|
563
|
+
isSubmitting: !1,
|
|
564
|
+
isSubmitSuccessful: !1,
|
|
565
|
+
isValid: !1,
|
|
566
|
+
touchedFields: {},
|
|
567
|
+
dirtyFields: {},
|
|
568
|
+
validatingFields: {},
|
|
569
|
+
errors: t.errors || {},
|
|
570
|
+
disabled: t.disabled || !1
|
|
571
|
+
}, s = {}, u = M(t.defaultValues) || M(t.values) ? U(t.defaultValues || t.values) || {} : {}, i = t.shouldUnregister ? {} : U(u), l = {
|
|
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
|
+
}, v, p = 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 g = {
|
|
592
|
+
...V
|
|
593
|
+
};
|
|
594
|
+
const b = {
|
|
595
|
+
array: dr(),
|
|
596
|
+
state: dr()
|
|
597
|
+
}, H = t.criteriaMode === X.all, I = (a) => (n) => {
|
|
598
|
+
clearTimeout(p), p = setTimeout(a, n);
|
|
599
|
+
}, C = async (a) => {
|
|
600
|
+
if (!t.disabled && (V.isValid || g.isValid || a)) {
|
|
601
|
+
const n = t.resolver ? $((await E()).errors) : await W(s, !0);
|
|
602
|
+
n !== r.isValid && b.state.next({
|
|
603
|
+
isValid: n
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
}, B = (a, n) => {
|
|
607
|
+
!t.disabled && (V.isValidating || V.validatingFields || g.isValidating || g.validatingFields) && ((a || Array.from(c.mount)).forEach((o) => {
|
|
608
|
+
o && (n ? R(r.validatingFields, o, n) : L(r.validatingFields, o));
|
|
609
|
+
}), b.state.next({
|
|
610
|
+
validatingFields: r.validatingFields,
|
|
611
|
+
isValidating: !$(r.validatingFields)
|
|
612
|
+
}));
|
|
613
|
+
}, j = (a, n = [], o, h, _ = !0, d = !0) => {
|
|
614
|
+
if (h && o && !t.disabled) {
|
|
615
|
+
if (l.action = !0, d && Array.isArray(m(s, a))) {
|
|
616
|
+
const A = o(m(s, a), h.argA, h.argB);
|
|
617
|
+
_ && R(s, a, A);
|
|
618
|
+
}
|
|
619
|
+
if (d && Array.isArray(m(r.errors, a))) {
|
|
620
|
+
const A = o(m(r.errors, a), h.argA, h.argB);
|
|
621
|
+
_ && R(r.errors, a, A), yt(r.errors, a);
|
|
622
|
+
}
|
|
623
|
+
if ((V.touchedFields || g.touchedFields) && d && Array.isArray(m(r.touchedFields, a))) {
|
|
624
|
+
const A = o(m(r.touchedFields, a), h.argA, h.argB);
|
|
625
|
+
_ && R(r.touchedFields, a, A);
|
|
626
|
+
}
|
|
627
|
+
(V.dirtyFields || g.dirtyFields) && (r.dirtyFields = fe(u, i)), b.state.next({
|
|
628
|
+
name: a,
|
|
629
|
+
isDirty: te(a, n),
|
|
630
|
+
dirtyFields: r.dirtyFields,
|
|
631
|
+
errors: r.errors,
|
|
632
|
+
isValid: r.isValid
|
|
633
|
+
});
|
|
634
|
+
} else
|
|
635
|
+
R(i, a, n);
|
|
636
|
+
}, S = (a, n) => {
|
|
637
|
+
R(r.errors, a, n), b.state.next({
|
|
638
|
+
errors: r.errors
|
|
639
|
+
});
|
|
640
|
+
}, P = (a) => {
|
|
641
|
+
r.errors = a, b.state.next({
|
|
642
|
+
errors: r.errors,
|
|
643
|
+
isValid: !1
|
|
644
|
+
});
|
|
645
|
+
}, f = (a, n, o, h) => {
|
|
646
|
+
const _ = m(s, a);
|
|
647
|
+
if (_) {
|
|
648
|
+
const d = m(i, a, T(o) ? m(u, a) : o);
|
|
649
|
+
T(d) || h && h.defaultChecked || n ? R(i, a, n ? d : _r(_._f)) : N(a, d), l.mount && !l.action && C();
|
|
650
|
+
}
|
|
651
|
+
}, y = (a, n, o, h, _) => {
|
|
652
|
+
let d = !1, A = !1;
|
|
653
|
+
const k = {
|
|
654
|
+
name: a
|
|
655
|
+
};
|
|
656
|
+
if (!t.disabled) {
|
|
657
|
+
if (!o || h) {
|
|
658
|
+
(V.isDirty || g.isDirty) && (A = r.isDirty, r.isDirty = k.isDirty = te(), d = A !== k.isDirty);
|
|
659
|
+
const O = ee(m(u, a), n);
|
|
660
|
+
A = !!m(r.dirtyFields, a), O ? L(r.dirtyFields, a) : R(r.dirtyFields, a, !0), k.dirtyFields = r.dirtyFields, d = d || (V.dirtyFields || g.dirtyFields) && A !== !O;
|
|
661
|
+
}
|
|
662
|
+
if (o) {
|
|
663
|
+
const O = m(r.touchedFields, a);
|
|
664
|
+
O || (R(r.touchedFields, a, o), k.touchedFields = r.touchedFields, d = d || (V.touchedFields || g.touchedFields) && O !== o);
|
|
665
|
+
}
|
|
666
|
+
d && _ && b.state.next(k);
|
|
667
|
+
}
|
|
668
|
+
return d ? k : {};
|
|
669
|
+
}, x = (a, n, o, h) => {
|
|
670
|
+
const _ = m(r.errors, a), d = (V.isValid || g.isValid) && K(n) && r.isValid !== n;
|
|
671
|
+
if (t.delayError && o ? (v = I(() => S(a, o)), v(t.delayError)) : (clearTimeout(p), v = null, o ? R(r.errors, a, o) : L(r.errors, a)), (o ? !ee(_, o) : _) || !$(h) || d) {
|
|
672
|
+
const A = {
|
|
673
|
+
...h,
|
|
674
|
+
...d && K(n) ? { isValid: n } : {},
|
|
675
|
+
errors: r.errors,
|
|
676
|
+
name: a
|
|
677
|
+
};
|
|
678
|
+
r = {
|
|
679
|
+
...r,
|
|
680
|
+
...A
|
|
681
|
+
}, b.state.next(A);
|
|
682
|
+
}
|
|
683
|
+
}, E = async (a) => {
|
|
684
|
+
B(a, !0);
|
|
685
|
+
const n = await t.resolver(i, t.context, ut(a || c.mount, s, t.criteriaMode, t.shouldUseNativeValidation));
|
|
686
|
+
return B(a), n;
|
|
687
|
+
}, Z = async (a) => {
|
|
688
|
+
const { errors: n } = await E(a);
|
|
689
|
+
if (a)
|
|
690
|
+
for (const o of a) {
|
|
691
|
+
const h = m(n, o);
|
|
692
|
+
h ? R(r.errors, o, h) : L(r.errors, o);
|
|
693
|
+
}
|
|
694
|
+
else
|
|
695
|
+
r.errors = n;
|
|
696
|
+
return n;
|
|
697
|
+
}, W = async (a, n, o = {
|
|
698
|
+
valid: !0
|
|
699
|
+
}) => {
|
|
700
|
+
for (const h in a) {
|
|
701
|
+
const _ = a[h];
|
|
702
|
+
if (_) {
|
|
703
|
+
const { _f: d, ...A } = _;
|
|
704
|
+
if (d) {
|
|
705
|
+
const k = c.array.has(d.name), O = _._f && ot(_._f);
|
|
706
|
+
O && V.validatingFields && B([d.name], !0);
|
|
707
|
+
const J = await Ge(_, c.disabled, i, H, t.shouldUseNativeValidation && !n, k);
|
|
708
|
+
if (O && V.validatingFields && B([d.name]), J[d.name] && (o.valid = !1, n))
|
|
709
|
+
break;
|
|
710
|
+
!n && (m(J, d.name) ? k ? Or(r.errors, J, d.name) : R(r.errors, d.name, J[d.name]) : L(r.errors, d.name));
|
|
711
|
+
}
|
|
712
|
+
!$(A) && await W(A, n, o);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return o.valid;
|
|
716
|
+
}, oe = () => {
|
|
717
|
+
for (const a of c.unMount) {
|
|
718
|
+
const n = m(s, a);
|
|
719
|
+
n && (n._f.refs ? n._f.refs.every((o) => !Oe(o)) : !Oe(n._f.ref)) && we(a);
|
|
720
|
+
}
|
|
721
|
+
c.unMount = /* @__PURE__ */ new Set();
|
|
722
|
+
}, te = (a, n) => !t.disabled && (a && n && R(i, a, n), !ee(Ve(), u)), w = (a, n, o) => $e(a, c, {
|
|
723
|
+
...l.mount ? i : T(n) ? u : Y(a) ? { [a]: n } : n
|
|
724
|
+
}, o, n), D = (a) => Se(m(l.mount ? i : u, a, t.shouldUnregister ? m(u, a, []) : [])), N = (a, n, o = {}) => {
|
|
725
|
+
const h = m(s, a);
|
|
726
|
+
let _ = n;
|
|
727
|
+
if (h) {
|
|
728
|
+
const d = h._f;
|
|
729
|
+
d && (!d.disabled && R(i, a, Dr(n, d)), _ = Ae(d.ref) && G(n) ? "" : n, wr(d.ref) ? [...d.ref.options].forEach((A) => A.selected = _.includes(A.value)) : d.refs ? ve(d.ref) ? d.refs.forEach((A) => {
|
|
730
|
+
(!A.defaultChecked || !A.disabled) && (Array.isArray(_) ? A.checked = !!_.find((k) => k === A.value) : A.checked = _ === A.value || !!_);
|
|
731
|
+
}) : d.refs.forEach((A) => A.checked = A.value === _) : Je(d.ref) ? d.ref.value = "" : (d.ref.value = _, d.ref.type || b.state.next({
|
|
732
|
+
name: a,
|
|
733
|
+
values: U(i)
|
|
734
|
+
})));
|
|
735
|
+
}
|
|
736
|
+
(o.shouldDirty || o.shouldTouch) && y(a, _, o.shouldTouch, o.shouldDirty, !0), o.shouldValidate && ce(a);
|
|
737
|
+
}, q = (a, n, o) => {
|
|
738
|
+
for (const h in n) {
|
|
739
|
+
if (!n.hasOwnProperty(h))
|
|
740
|
+
return;
|
|
741
|
+
const _ = n[h], d = a + "." + h, A = m(s, d);
|
|
742
|
+
(c.array.has(a) || M(_) || A && !A._f) && !le(_) ? q(d, _, o) : N(d, _, o);
|
|
743
|
+
}
|
|
744
|
+
}, Q = (a, n, o = {}) => {
|
|
745
|
+
const h = m(s, a), _ = c.array.has(a), d = U(n);
|
|
746
|
+
R(i, a, d), _ ? (b.array.next({
|
|
747
|
+
name: a,
|
|
748
|
+
values: U(i)
|
|
749
|
+
}), (V.isDirty || V.dirtyFields || g.isDirty || g.dirtyFields) && o.shouldDirty && b.state.next({
|
|
750
|
+
name: a,
|
|
751
|
+
dirtyFields: fe(u, i),
|
|
752
|
+
isDirty: te(a, d)
|
|
753
|
+
})) : h && !h._f && !G(d) ? q(a, d, o) : N(a, d, o), Qe(a, c) && b.state.next({ ...r, name: a }), b.state.next({
|
|
754
|
+
name: l.mount ? a : void 0,
|
|
755
|
+
values: U(i)
|
|
756
|
+
});
|
|
757
|
+
}, se = async (a) => {
|
|
758
|
+
l.mount = !0;
|
|
759
|
+
const n = a.target;
|
|
760
|
+
let o = n.name, h = !0;
|
|
761
|
+
const _ = m(s, o), d = (O) => {
|
|
762
|
+
h = Number.isNaN(O) || le(O) && isNaN(O.getTime()) || ee(O, m(i, o, O));
|
|
763
|
+
}, A = ye(t.mode), k = ye(t.reValidateMode);
|
|
764
|
+
if (_) {
|
|
765
|
+
let O, J;
|
|
766
|
+
const Fe = n.type ? _r(_._f) : Ar(a), ie = a.type === be.BLUR || a.type === be.FOCUS_OUT, Hr = !lt(_._f) && !t.resolver && !m(r.errors, o) && !_._f.deps || ft(ie, m(r.touchedFields, o), r.isSubmitted, k, A), De = Qe(o, c, ie);
|
|
767
|
+
R(i, o, Fe), ie ? (!n || !n.readOnly) && (_._f.onBlur && _._f.onBlur(a), v && v(0)) : _._f.onChange && _._f.onChange(a);
|
|
768
|
+
const Re = y(o, Fe, ie), $r = !$(Re) || De;
|
|
769
|
+
if (!ie && b.state.next({
|
|
770
|
+
name: o,
|
|
771
|
+
type: a.type,
|
|
772
|
+
values: U(i)
|
|
773
|
+
}), Hr)
|
|
774
|
+
return (V.isValid || g.isValid) && (t.mode === "onBlur" ? ie && C() : ie || C()), $r && b.state.next({ name: o, ...De ? {} : Re });
|
|
775
|
+
if (!ie && De && b.state.next({ ...r }), t.resolver) {
|
|
776
|
+
const { errors: or } = await E([o]);
|
|
777
|
+
if (d(Fe), h) {
|
|
778
|
+
const qr = hr(r.errors, s, o), lr = hr(or, s, qr.name || o);
|
|
779
|
+
O = lr.error, o = lr.name, J = $(or);
|
|
780
|
+
}
|
|
781
|
+
} else
|
|
782
|
+
B([o], !0), O = (await Ge(_, c.disabled, i, H, t.shouldUseNativeValidation))[o], B([o]), d(Fe), h && (O ? J = !1 : (V.isValid || g.isValid) && (J = await W(s, !0)));
|
|
783
|
+
h && (_._f.deps && (!Array.isArray(_._f.deps) || _._f.deps.length > 0) && ce(_._f.deps), x(o, J, O, Re));
|
|
784
|
+
}
|
|
785
|
+
}, ge = (a, n) => {
|
|
786
|
+
if (m(r.errors, n) && a.focus)
|
|
787
|
+
return a.focus(), 1;
|
|
788
|
+
}, ce = async (a, n = {}) => {
|
|
789
|
+
let o, h;
|
|
790
|
+
const _ = z(a);
|
|
791
|
+
if (t.resolver) {
|
|
792
|
+
const d = await Z(T(a) ? a : _);
|
|
793
|
+
o = $(d), h = a ? !_.some((A) => m(d, A)) : o;
|
|
794
|
+
} else a ? (h = (await Promise.all(_.map(async (d) => {
|
|
795
|
+
const A = m(s, d);
|
|
796
|
+
return await W(A && A._f ? { [d]: A } : A);
|
|
797
|
+
}))).every(Boolean), !(!h && !r.isValid) && C()) : h = o = await W(s);
|
|
798
|
+
return b.state.next({
|
|
799
|
+
...!Y(a) || (V.isValid || g.isValid) && o !== r.isValid ? {} : { name: a },
|
|
800
|
+
...t.resolver || !a ? { isValid: o } : {},
|
|
801
|
+
errors: r.errors
|
|
802
|
+
}), n.shouldFocus && !h && me(s, ge, a ? _ : c.mount), h;
|
|
803
|
+
}, Ve = (a, n) => {
|
|
804
|
+
let o = {
|
|
805
|
+
...l.mount ? i : u
|
|
806
|
+
};
|
|
807
|
+
return n && (o = Er(n.dirtyFields ? r.dirtyFields : r.touchedFields, o)), T(a) ? o : Y(a) ? m(o, a) : a.map((h) => m(o, h));
|
|
808
|
+
}, er = (a, n) => ({
|
|
809
|
+
invalid: !!m((n || r).errors, a),
|
|
810
|
+
isDirty: !!m((n || r).dirtyFields, a),
|
|
811
|
+
error: m((n || r).errors, a),
|
|
812
|
+
isValidating: !!m(r.validatingFields, a),
|
|
813
|
+
isTouched: !!m((n || r).touchedFields, a)
|
|
814
|
+
}), Nr = (a) => {
|
|
815
|
+
a && z(a).forEach((n) => L(r.errors, n)), b.state.next({
|
|
816
|
+
errors: a ? r.errors : {}
|
|
817
|
+
});
|
|
818
|
+
}, rr = (a, n, o) => {
|
|
819
|
+
const h = (m(s, a, { _f: {} })._f || {}).ref, _ = m(r.errors, a) || {}, { ref: d, message: A, type: k, ...O } = _;
|
|
820
|
+
R(r.errors, a, {
|
|
821
|
+
...O,
|
|
822
|
+
...n,
|
|
823
|
+
ref: h
|
|
824
|
+
}), b.state.next({
|
|
825
|
+
name: a,
|
|
826
|
+
errors: r.errors,
|
|
827
|
+
isValid: !1
|
|
828
|
+
}), o && o.shouldFocus && h && h.focus && h.focus();
|
|
829
|
+
}, Lr = (a, n) => re(a) ? b.state.subscribe({
|
|
830
|
+
next: (o) => "values" in o && a(w(void 0, n), o)
|
|
831
|
+
}) : w(a, n, !0), tr = (a) => b.state.subscribe({
|
|
832
|
+
next: (n) => {
|
|
833
|
+
dt(a.name, n.name, a.exact) && ct(n, a.formState || V, Wr, a.reRenderRoot) && a.callback({
|
|
834
|
+
values: { ...i },
|
|
835
|
+
...r,
|
|
836
|
+
...n,
|
|
837
|
+
defaultValues: u
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}).unsubscribe, Mr = (a) => (l.mount = !0, g = {
|
|
841
|
+
...g,
|
|
842
|
+
...a.formState
|
|
843
|
+
}, tr({
|
|
844
|
+
...a,
|
|
845
|
+
formState: g
|
|
846
|
+
})), we = (a, n = {}) => {
|
|
847
|
+
for (const o of a ? z(a) : c.mount)
|
|
848
|
+
c.mount.delete(o), c.array.delete(o), n.keepValue || (L(s, o), L(i, o)), !n.keepError && L(r.errors, o), !n.keepDirty && L(r.dirtyFields, o), !n.keepTouched && L(r.touchedFields, o), !n.keepIsValidating && L(r.validatingFields, o), !t.shouldUnregister && !n.keepDefaultValue && L(u, o);
|
|
849
|
+
b.state.next({
|
|
850
|
+
values: U(i)
|
|
851
|
+
}), b.state.next({
|
|
852
|
+
...r,
|
|
853
|
+
...n.keepDirty ? { isDirty: te() } : {}
|
|
854
|
+
}), !n.keepIsValid && C();
|
|
855
|
+
}, sr = ({ disabled: a, name: n }) => {
|
|
856
|
+
(K(a) && l.mount || a || c.disabled.has(n)) && (a ? c.disabled.add(n) : c.disabled.delete(n));
|
|
857
|
+
}, Ce = (a, n = {}) => {
|
|
858
|
+
let o = m(s, a);
|
|
859
|
+
const h = K(n.disabled) || K(t.disabled);
|
|
860
|
+
return R(s, a, {
|
|
861
|
+
...o || {},
|
|
862
|
+
_f: {
|
|
863
|
+
...o && o._f ? o._f : { ref: { name: a } },
|
|
864
|
+
name: a,
|
|
865
|
+
mount: !0,
|
|
866
|
+
...n
|
|
867
|
+
}
|
|
868
|
+
}), c.mount.add(a), o ? sr({
|
|
869
|
+
disabled: K(n.disabled) ? n.disabled : t.disabled,
|
|
870
|
+
name: a
|
|
871
|
+
}) : f(a, !0, n.value), {
|
|
872
|
+
...h ? { disabled: n.disabled || t.disabled } : {},
|
|
873
|
+
...t.progressive ? {
|
|
874
|
+
required: !!n.required,
|
|
875
|
+
min: he(n.min),
|
|
876
|
+
max: he(n.max),
|
|
877
|
+
minLength: he(n.minLength),
|
|
878
|
+
maxLength: he(n.maxLength),
|
|
879
|
+
pattern: he(n.pattern)
|
|
880
|
+
} : {},
|
|
881
|
+
name: a,
|
|
882
|
+
onChange: se,
|
|
883
|
+
onBlur: se,
|
|
884
|
+
ref: (_) => {
|
|
885
|
+
if (_) {
|
|
886
|
+
Ce(a, n), o = m(s, a);
|
|
887
|
+
const d = T(_.value) && _.querySelectorAll && _.querySelectorAll("input,select,textarea")[0] || _, A = st(d), k = o._f.refs || [];
|
|
888
|
+
if (A ? k.find((O) => O === d) : d === o._f.ref)
|
|
889
|
+
return;
|
|
890
|
+
R(s, a, {
|
|
891
|
+
_f: {
|
|
892
|
+
...o._f,
|
|
893
|
+
...A ? {
|
|
894
|
+
refs: [
|
|
895
|
+
...k.filter(Oe),
|
|
896
|
+
d,
|
|
897
|
+
...Array.isArray(m(u, a)) ? [{}] : []
|
|
898
|
+
],
|
|
899
|
+
ref: { type: d.type, name: a }
|
|
900
|
+
} : { ref: d }
|
|
901
|
+
}
|
|
902
|
+
}), f(a, !1, void 0, d);
|
|
903
|
+
} else
|
|
904
|
+
o = m(s, a, {}), o._f && (o._f.mount = !1), (t.shouldUnregister || n.shouldUnregister) && !(pr(c.array, a) && l.action) && c.unMount.add(a);
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
}, ke = () => t.shouldFocusError && me(s, ge, c.mount), Ir = (a) => {
|
|
908
|
+
K(a) && (b.state.next({ disabled: a }), me(s, (n, o) => {
|
|
909
|
+
const h = m(s, o);
|
|
910
|
+
h && (n.disabled = h._f.disabled || a, Array.isArray(h._f.refs) && h._f.refs.forEach((_) => {
|
|
911
|
+
_.disabled = h._f.disabled || a;
|
|
912
|
+
}));
|
|
913
|
+
}, 0, !1));
|
|
914
|
+
}, ar = (a, n) => async (o) => {
|
|
915
|
+
let h;
|
|
916
|
+
o && (o.preventDefault && o.preventDefault(), o.persist && o.persist());
|
|
917
|
+
let _ = U(i);
|
|
918
|
+
if (b.state.next({
|
|
919
|
+
isSubmitting: !0
|
|
920
|
+
}), t.resolver) {
|
|
921
|
+
const { errors: d, values: A } = await E();
|
|
922
|
+
r.errors = d, _ = U(A);
|
|
923
|
+
} else
|
|
924
|
+
await W(s);
|
|
925
|
+
if (c.disabled.size)
|
|
926
|
+
for (const d of c.disabled)
|
|
927
|
+
L(_, d);
|
|
928
|
+
if (L(r.errors, "root"), $(r.errors)) {
|
|
929
|
+
b.state.next({
|
|
930
|
+
errors: {}
|
|
931
|
+
});
|
|
932
|
+
try {
|
|
933
|
+
await a(_, o);
|
|
934
|
+
} catch (d) {
|
|
935
|
+
h = d;
|
|
936
|
+
}
|
|
937
|
+
} else
|
|
938
|
+
n && await n({ ...r.errors }, o), ke(), setTimeout(ke);
|
|
939
|
+
if (b.state.next({
|
|
940
|
+
isSubmitted: !0,
|
|
941
|
+
isSubmitting: !1,
|
|
942
|
+
isSubmitSuccessful: $(r.errors) && !h,
|
|
943
|
+
submitCount: r.submitCount + 1,
|
|
944
|
+
errors: r.errors
|
|
945
|
+
}), h)
|
|
946
|
+
throw h;
|
|
947
|
+
}, Br = (a, n = {}) => {
|
|
948
|
+
m(s, a) && (T(n.defaultValue) ? Q(a, U(m(u, a))) : (Q(a, n.defaultValue), R(u, a, U(n.defaultValue))), n.keepTouched || L(r.touchedFields, a), n.keepDirty || (L(r.dirtyFields, a), r.isDirty = n.defaultValue ? te(a, U(m(u, a))) : te()), n.keepError || (L(r.errors, a), V.isValid && C()), b.state.next({ ...r }));
|
|
949
|
+
}, nr = (a, n = {}) => {
|
|
950
|
+
const o = a ? U(a) : u, h = U(o), _ = $(a), d = _ ? u : h;
|
|
951
|
+
if (n.keepDefaultValues || (u = o), !n.keepValues) {
|
|
952
|
+
if (n.keepDirtyValues) {
|
|
953
|
+
const A = /* @__PURE__ */ new Set([
|
|
954
|
+
...c.mount,
|
|
955
|
+
...Object.keys(fe(u, i))
|
|
956
|
+
]);
|
|
957
|
+
for (const k of Array.from(A))
|
|
958
|
+
m(r.dirtyFields, k) ? R(d, k, m(i, k)) : Q(k, m(d, k));
|
|
959
|
+
} else {
|
|
960
|
+
if (ze && T(a))
|
|
961
|
+
for (const A of c.mount) {
|
|
962
|
+
const k = m(s, A);
|
|
963
|
+
if (k && k._f) {
|
|
964
|
+
const O = Array.isArray(k._f.refs) ? k._f.refs[0] : k._f.ref;
|
|
965
|
+
if (Ae(O)) {
|
|
966
|
+
const J = O.closest("form");
|
|
967
|
+
if (J) {
|
|
968
|
+
J.reset();
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (n.keepFieldsRef)
|
|
975
|
+
for (const A of c.mount)
|
|
976
|
+
Q(A, m(d, A));
|
|
977
|
+
else
|
|
978
|
+
s = {};
|
|
979
|
+
}
|
|
980
|
+
i = t.shouldUnregister ? n.keepDefaultValues ? U(u) : {} : U(d), b.array.next({
|
|
981
|
+
values: { ...d }
|
|
982
|
+
}), b.state.next({
|
|
983
|
+
values: { ...d }
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
c = {
|
|
987
|
+
mount: n.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
|
+
}, l.mount = !V.isValid || !!n.keepIsValid || !!n.keepDirtyValues || !t.shouldUnregister && !$(d), l.watch = !!t.shouldUnregister, l.action = !1, n.keepErrors || (r.errors = {}), b.state.next({
|
|
995
|
+
submitCount: n.keepSubmitCount ? r.submitCount : 0,
|
|
996
|
+
isDirty: _ ? !1 : n.keepDirty ? r.isDirty : !!(n.keepDefaultValues && !ee(a, u)),
|
|
997
|
+
isSubmitted: n.keepIsSubmitted ? r.isSubmitted : !1,
|
|
998
|
+
dirtyFields: _ ? {} : n.keepDirtyValues ? n.keepDefaultValues && i ? fe(u, i) : r.dirtyFields : n.keepDefaultValues && a ? fe(u, a) : n.keepDirty ? r.dirtyFields : {},
|
|
999
|
+
touchedFields: n.keepTouched ? r.touchedFields : {},
|
|
1000
|
+
errors: n.keepErrors ? r.errors : {},
|
|
1001
|
+
isSubmitSuccessful: n.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
|
|
1002
|
+
isSubmitting: !1,
|
|
1003
|
+
defaultValues: u
|
|
1004
|
+
});
|
|
1005
|
+
}, ir = (a, n) => nr(re(a) ? a(i) : a, n), Pr = (a, n = {}) => {
|
|
1006
|
+
const o = m(s, a), h = o && o._f;
|
|
1007
|
+
if (h) {
|
|
1008
|
+
const _ = h.refs ? h.refs[0] : h.ref;
|
|
1009
|
+
_.focus && (_.focus(), n.shouldSelect && re(_.select) && _.select());
|
|
1010
|
+
}
|
|
1011
|
+
}, Wr = (a) => {
|
|
1012
|
+
r = {
|
|
1013
|
+
...r,
|
|
1014
|
+
...a
|
|
1015
|
+
};
|
|
1016
|
+
}, ur = {
|
|
1017
|
+
control: {
|
|
1018
|
+
register: Ce,
|
|
1019
|
+
unregister: we,
|
|
1020
|
+
getFieldState: er,
|
|
1021
|
+
handleSubmit: ar,
|
|
1022
|
+
setError: rr,
|
|
1023
|
+
_subscribe: tr,
|
|
1024
|
+
_runSchema: E,
|
|
1025
|
+
_focusError: ke,
|
|
1026
|
+
_getWatch: w,
|
|
1027
|
+
_getDirty: te,
|
|
1028
|
+
_setValid: C,
|
|
1029
|
+
_setFieldArray: j,
|
|
1030
|
+
_setDisabledField: sr,
|
|
1031
|
+
_setErrors: P,
|
|
1032
|
+
_getFieldArray: D,
|
|
1033
|
+
_reset: nr,
|
|
1034
|
+
_resetDefaultValues: () => re(t.defaultValues) && t.defaultValues().then((a) => {
|
|
1035
|
+
ir(a, t.resetOptions), b.state.next({
|
|
1036
|
+
isLoading: !1
|
|
1037
|
+
});
|
|
1038
|
+
}),
|
|
1039
|
+
_removeUnmounted: oe,
|
|
1040
|
+
_disableForm: Ir,
|
|
1041
|
+
_subjects: b,
|
|
1042
|
+
_proxyFormState: V,
|
|
1043
|
+
get _fields() {
|
|
1044
|
+
return s;
|
|
1045
|
+
},
|
|
1046
|
+
get _formValues() {
|
|
1047
|
+
return i;
|
|
1048
|
+
},
|
|
1049
|
+
get _state() {
|
|
1050
|
+
return l;
|
|
1051
|
+
},
|
|
1052
|
+
set _state(a) {
|
|
1053
|
+
l = a;
|
|
1054
|
+
},
|
|
1055
|
+
get _defaultValues() {
|
|
1056
|
+
return u;
|
|
1057
|
+
},
|
|
1058
|
+
get _names() {
|
|
1059
|
+
return c;
|
|
1060
|
+
},
|
|
1061
|
+
set _names(a) {
|
|
1062
|
+
c = a;
|
|
1063
|
+
},
|
|
1064
|
+
get _formState() {
|
|
1065
|
+
return r;
|
|
1066
|
+
},
|
|
1067
|
+
get _options() {
|
|
1068
|
+
return t;
|
|
1069
|
+
},
|
|
1070
|
+
set _options(a) {
|
|
1071
|
+
t = {
|
|
1072
|
+
...t,
|
|
1073
|
+
...a
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
},
|
|
1077
|
+
subscribe: Mr,
|
|
1078
|
+
trigger: ce,
|
|
1079
|
+
register: Ce,
|
|
1080
|
+
handleSubmit: ar,
|
|
1081
|
+
watch: Lr,
|
|
1082
|
+
setValue: Q,
|
|
1083
|
+
getValues: Ve,
|
|
1084
|
+
reset: ir,
|
|
1085
|
+
resetField: Br,
|
|
1086
|
+
clearErrors: Nr,
|
|
1087
|
+
unregister: we,
|
|
1088
|
+
setError: rr,
|
|
1089
|
+
setFocus: Pr,
|
|
1090
|
+
getFieldState: er
|
|
1091
|
+
};
|
|
1092
|
+
return {
|
|
1093
|
+
...ur,
|
|
1094
|
+
formControl: ur
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
var ue = () => {
|
|
1098
|
+
if (typeof crypto < "u" && crypto.randomUUID)
|
|
1099
|
+
return crypto.randomUUID();
|
|
1100
|
+
const e = typeof performance > "u" ? Date.now() : performance.now() * 1e3;
|
|
1101
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
|
|
1102
|
+
const r = (Math.random() * 16 + e) % 16 | 0;
|
|
1103
|
+
return (t == "x" ? r : r & 3 | 8).toString(16);
|
|
1104
|
+
});
|
|
1105
|
+
}, Te = (e, t, r = {}) => r.shouldFocus || T(r.shouldFocus) ? r.focusName || `${e}.${T(r.focusIndex) ? t : r.focusIndex}.` : "", Ue = (e, t) => [
|
|
1106
|
+
...e,
|
|
1107
|
+
...z(t)
|
|
1108
|
+
], Ne = (e) => Array.isArray(e) ? e.map(() => {
|
|
1109
|
+
}) : void 0;
|
|
1110
|
+
function Le(e, t, r) {
|
|
1111
|
+
return [
|
|
1112
|
+
...e.slice(0, t),
|
|
1113
|
+
...z(r),
|
|
1114
|
+
...e.slice(t)
|
|
1115
|
+
];
|
|
1116
|
+
}
|
|
1117
|
+
var Me = (e, t, r) => Array.isArray(e) ? (T(e[r]) && (e[r] = void 0), e.splice(r, 0, e.splice(t, 1)[0]), e) : [], Ie = (e, t) => [
|
|
1118
|
+
...z(t),
|
|
1119
|
+
...z(e)
|
|
1120
|
+
];
|
|
1121
|
+
function gt(e, t) {
|
|
1122
|
+
let r = 0;
|
|
1123
|
+
const s = [...e];
|
|
1124
|
+
for (const u of t)
|
|
1125
|
+
s.splice(u - r, 1), r++;
|
|
1126
|
+
return Se(s).length ? s : [];
|
|
1127
|
+
}
|
|
1128
|
+
var Be = (e, t) => T(t) ? [] : gt(e, z(t).sort((r, s) => r - s)), Pe = (e, t, r) => {
|
|
1129
|
+
[e[t], e[r]] = [e[r], e[t]];
|
|
1130
|
+
}, Vr = (e, t, r) => (e[t] = r, e);
|
|
1131
|
+
function ht(e) {
|
|
1132
|
+
const t = _e(), { control: r = t.control, name: s, keyName: u = "id", shouldUnregister: i, rules: l } = e, [c, v] = F.useState(r._getFieldArray(s)), p = F.useRef(r._getFieldArray(s).map(ue)), V = F.useRef(!1);
|
|
1133
|
+
r._names.array.add(s), F.useMemo(() => l && c.length >= 0 && r.register(s, l), [r, s, c.length, l]), Ee(() => r._subjects.array.subscribe({
|
|
1134
|
+
next: ({ values: f, name: y }) => {
|
|
1135
|
+
if (y === s || !y) {
|
|
1136
|
+
const x = m(f, s);
|
|
1137
|
+
Array.isArray(x) && (v(x), p.current = x.map(ue));
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}).unsubscribe, [r, s]);
|
|
1141
|
+
const g = F.useCallback((f) => {
|
|
1142
|
+
V.current = !0, r._setFieldArray(s, f);
|
|
1143
|
+
}, [r, s]), b = (f, y) => {
|
|
1144
|
+
const x = z(U(f)), E = Ue(r._getFieldArray(s), x);
|
|
1145
|
+
r._names.focus = Te(s, E.length - 1, y), p.current = Ue(p.current, x.map(ue)), g(E), v(E), r._setFieldArray(s, E, Ue, {
|
|
1146
|
+
argA: Ne(f)
|
|
1147
|
+
});
|
|
1148
|
+
}, H = (f, y) => {
|
|
1149
|
+
const x = z(U(f)), E = Ie(r._getFieldArray(s), x);
|
|
1150
|
+
r._names.focus = Te(s, 0, y), p.current = Ie(p.current, x.map(ue)), g(E), v(E), r._setFieldArray(s, E, Ie, {
|
|
1151
|
+
argA: Ne(f)
|
|
1152
|
+
});
|
|
1153
|
+
}, I = (f) => {
|
|
1154
|
+
const y = Be(r._getFieldArray(s), f);
|
|
1155
|
+
p.current = Be(p.current, f), g(y), v(y), !Array.isArray(m(r._fields, s)) && R(r._fields, s, void 0), r._setFieldArray(s, y, Be, {
|
|
1156
|
+
argA: f
|
|
1157
|
+
});
|
|
1158
|
+
}, C = (f, y, x) => {
|
|
1159
|
+
const E = z(U(y)), Z = Le(r._getFieldArray(s), f, E);
|
|
1160
|
+
r._names.focus = Te(s, f, x), p.current = Le(p.current, f, E.map(ue)), g(Z), v(Z), r._setFieldArray(s, Z, Le, {
|
|
1161
|
+
argA: f,
|
|
1162
|
+
argB: Ne(y)
|
|
1163
|
+
});
|
|
1164
|
+
}, B = (f, y) => {
|
|
1165
|
+
const x = r._getFieldArray(s);
|
|
1166
|
+
Pe(x, f, y), Pe(p.current, f, y), g(x), v(x), r._setFieldArray(s, x, Pe, {
|
|
1167
|
+
argA: f,
|
|
1168
|
+
argB: y
|
|
1169
|
+
}, !1);
|
|
1170
|
+
}, j = (f, y) => {
|
|
1171
|
+
const x = r._getFieldArray(s);
|
|
1172
|
+
Me(x, f, y), Me(p.current, f, y), g(x), v(x), r._setFieldArray(s, x, Me, {
|
|
1173
|
+
argA: f,
|
|
1174
|
+
argB: y
|
|
1175
|
+
}, !1);
|
|
1176
|
+
}, S = (f, y) => {
|
|
1177
|
+
const x = U(y), E = Vr(r._getFieldArray(s), f, x);
|
|
1178
|
+
p.current = [...E].map((Z, W) => !Z || W === f ? ue() : p.current[W]), g(E), v([...E]), r._setFieldArray(s, E, Vr, {
|
|
1179
|
+
argA: f,
|
|
1180
|
+
argB: x
|
|
1181
|
+
}, !0, !1);
|
|
1182
|
+
}, P = (f) => {
|
|
1183
|
+
const y = z(U(f));
|
|
1184
|
+
p.current = y.map(ue), g([...y]), v([...y]), r._setFieldArray(s, [...y], (x) => x, {}, !0, !1);
|
|
1185
|
+
};
|
|
1186
|
+
return F.useEffect(() => {
|
|
1187
|
+
if (r._state.action = !1, Qe(s, r._names) && r._subjects.state.next({
|
|
1188
|
+
...r._formState
|
|
1189
|
+
}), V.current && (!ye(r._options.mode).isOnSubmit || r._formState.isSubmitted) && !ye(r._options.reValidateMode).isOnSubmit)
|
|
1190
|
+
if (r._options.resolver)
|
|
1191
|
+
r._runSchema([s]).then((f) => {
|
|
1192
|
+
const y = m(f.errors, s), x = m(r._formState.errors, s);
|
|
1193
|
+
(x ? !y && x.type || y && (x.type !== y.type || x.message !== y.message) : y && y.type) && (y ? R(r._formState.errors, s, y) : L(r._formState.errors, s), r._subjects.state.next({
|
|
1194
|
+
errors: r._formState.errors
|
|
1195
|
+
}));
|
|
1196
|
+
});
|
|
1197
|
+
else {
|
|
1198
|
+
const f = m(r._fields, s);
|
|
1199
|
+
f && f._f && !(ye(r._options.reValidateMode).isOnSubmit && ye(r._options.mode).isOnSubmit) && Ge(f, r._names.disabled, r._formValues, r._options.criteriaMode === X.all, r._options.shouldUseNativeValidation, !0).then((y) => !$(y) && r._subjects.state.next({
|
|
1200
|
+
errors: Or(r._formState.errors, y, s)
|
|
1201
|
+
}));
|
|
1202
|
+
}
|
|
1203
|
+
r._subjects.state.next({
|
|
1204
|
+
name: s,
|
|
1205
|
+
values: U(r._formValues)
|
|
1206
|
+
}), r._names.focus && me(r._fields, (f, y) => {
|
|
1207
|
+
if (r._names.focus && y.startsWith(r._names.focus) && f.focus)
|
|
1208
|
+
return f.focus(), 1;
|
|
1209
|
+
}), r._names.focus = "", r._setValid(), V.current = !1;
|
|
1210
|
+
}, [c, s, r]), F.useEffect(() => (!m(r._formValues, s) && r._setFieldArray(s), () => {
|
|
1211
|
+
const f = (y, x) => {
|
|
1212
|
+
const E = m(r._fields, y);
|
|
1213
|
+
E && E._f && (E._f.mount = x);
|
|
1214
|
+
};
|
|
1215
|
+
r._options.shouldUnregister || i ? r.unregister(s) : f(s, !1);
|
|
1216
|
+
}), [s, r, u, i]), {
|
|
1217
|
+
swap: F.useCallback(B, [g, s, r]),
|
|
1218
|
+
move: F.useCallback(j, [g, s, r]),
|
|
1219
|
+
prepend: F.useCallback(H, [g, s, r]),
|
|
1220
|
+
append: F.useCallback(b, [g, s, r]),
|
|
1221
|
+
remove: F.useCallback(I, [g, s, r]),
|
|
1222
|
+
insert: F.useCallback(C, [g, s, r]),
|
|
1223
|
+
update: F.useCallback(S, [g, s, r]),
|
|
1224
|
+
replace: F.useCallback(P, [g, s, r]),
|
|
1225
|
+
fields: F.useMemo(() => c.map((f, y) => ({
|
|
1226
|
+
...f,
|
|
1227
|
+
[u]: p.current[y] || ue()
|
|
1228
|
+
})), [c, u])
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
function vt(e = {}) {
|
|
1232
|
+
const t = F.useRef(void 0), r = F.useRef(void 0), [s, u] = F.useState({
|
|
1233
|
+
isDirty: !1,
|
|
1234
|
+
isValidating: !1,
|
|
1235
|
+
isLoading: re(e.defaultValues),
|
|
1236
|
+
isSubmitted: !1,
|
|
1237
|
+
isSubmitting: !1,
|
|
1238
|
+
isSubmitSuccessful: !1,
|
|
1239
|
+
isValid: !1,
|
|
1240
|
+
submitCount: 0,
|
|
1241
|
+
dirtyFields: {},
|
|
1242
|
+
touchedFields: {},
|
|
1243
|
+
validatingFields: {},
|
|
1244
|
+
errors: e.errors || {},
|
|
1245
|
+
disabled: e.disabled || !1,
|
|
1246
|
+
isReady: !1,
|
|
1247
|
+
defaultValues: re(e.defaultValues) ? void 0 : e.defaultValues
|
|
1248
|
+
});
|
|
1249
|
+
if (!t.current)
|
|
1250
|
+
if (e.formControl)
|
|
1251
|
+
t.current = {
|
|
1252
|
+
...e.formControl,
|
|
1253
|
+
formState: s
|
|
1254
|
+
}, e.defaultValues && !re(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
|
|
1255
|
+
else {
|
|
1256
|
+
const { formControl: l, ...c } = _t(e);
|
|
1257
|
+
t.current = {
|
|
1258
|
+
...c,
|
|
1259
|
+
formState: s
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
const i = t.current.control;
|
|
1263
|
+
return i._options = e, Ee(() => {
|
|
1264
|
+
const l = i._subscribe({
|
|
1265
|
+
formState: i._proxyFormState,
|
|
1266
|
+
callback: () => u({ ...i._formState }),
|
|
1267
|
+
reRenderRoot: !0
|
|
1268
|
+
});
|
|
1269
|
+
return u((c) => ({
|
|
1270
|
+
...c,
|
|
1271
|
+
isReady: !0
|
|
1272
|
+
})), i._formState.isReady = !0, l;
|
|
1273
|
+
}, [i]), F.useEffect(() => i._disableForm(e.disabled), [i, e.disabled]), F.useEffect(() => {
|
|
1274
|
+
e.mode && (i._options.mode = e.mode), e.reValidateMode && (i._options.reValidateMode = e.reValidateMode);
|
|
1275
|
+
}, [i, e.mode, e.reValidateMode]), F.useEffect(() => {
|
|
1276
|
+
e.errors && (i._setErrors(e.errors), i._focusError());
|
|
1277
|
+
}, [i, e.errors]), F.useEffect(() => {
|
|
1278
|
+
e.shouldUnregister && i._subjects.state.next({
|
|
1279
|
+
values: i._getWatch()
|
|
1280
|
+
});
|
|
1281
|
+
}, [i, e.shouldUnregister]), F.useEffect(() => {
|
|
1282
|
+
if (i._proxyFormState.isDirty) {
|
|
1283
|
+
const l = i._getDirty();
|
|
1284
|
+
l !== s.isDirty && i._subjects.state.next({
|
|
1285
|
+
isDirty: l
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
}, [i, s.isDirty]), F.useEffect(() => {
|
|
1289
|
+
var l;
|
|
1290
|
+
e.values && !ee(e.values, r.current) ? (i._reset(e.values, {
|
|
1291
|
+
keepFieldsRef: !0,
|
|
1292
|
+
...i._options.resetOptions
|
|
1293
|
+
}), !((l = i._options.resetOptions) === null || l === void 0) && l.keepIsValid || i._setValid(), r.current = e.values, u((c) => ({ ...c }))) : i._resetDefaultValues();
|
|
1294
|
+
}, [i, e.values]), F.useEffect(() => {
|
|
1295
|
+
i._state.mount || (i._setValid(), i._state.mount = !0), i._state.watch && (i._state.watch = !1, i._subjects.state.next({ ...i._formState })), i._removeUnmounted();
|
|
1296
|
+
}), t.current.formState = xr(s, i), t.current;
|
|
1297
|
+
}
|
|
1298
|
+
const Tr = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ */ ne(Tr.Provider, { value: { showAsterisk: e }, children: t }), Ft = () => {
|
|
1299
|
+
const e = Gr(Tr);
|
|
1300
|
+
if (!e)
|
|
1301
|
+
throw new Error("useSuprFormContext must be used within a SuprFormProvider");
|
|
1302
|
+
return e;
|
|
1303
|
+
}, bt = ({
|
|
1304
|
+
children: e,
|
|
1305
|
+
visibility: t
|
|
1306
|
+
}) => {
|
|
1307
|
+
const { getValues: r } = _e(), s = We(() => typeof t == "boolean" ? [] : (t == null ? void 0 : t.conditions.map((l) => l.name)) || [], [t]), u = Sr({ name: s });
|
|
1308
|
+
return We(() => {
|
|
1309
|
+
if (typeof t == "boolean") return t;
|
|
1310
|
+
if (!t || (t == null ? void 0 : t.conditions.length) === 0) return !0;
|
|
1311
|
+
const { conditions: l, operator: c } = t, v = s.reduce((V, g, b) => (V[g] = u[b], V), {}), p = l.map((V) => {
|
|
1312
|
+
const g = v[V.name];
|
|
1313
|
+
switch (V.operator) {
|
|
1314
|
+
case "EQUALS":
|
|
1315
|
+
return g === V.value;
|
|
1316
|
+
case "NOT_EQUALS":
|
|
1317
|
+
return g !== V.value;
|
|
1318
|
+
case "GREATER_THAN":
|
|
1319
|
+
return g > V.value;
|
|
1320
|
+
case "LESS_THAN":
|
|
1321
|
+
return g < V.value;
|
|
1322
|
+
case "GREATER_THAN_OR_EQUAL":
|
|
1323
|
+
return g >= V.value;
|
|
1324
|
+
case "LESS_THAN_OR_EQUAL":
|
|
1325
|
+
return g <= V.value;
|
|
1326
|
+
case "STARTS_WITH":
|
|
1327
|
+
return g.startsWith(V.value);
|
|
1328
|
+
case "ENDS_WITH":
|
|
1329
|
+
return g.endsWith(V.value);
|
|
1330
|
+
case "INCLUDES":
|
|
1331
|
+
return g.includes(V.value);
|
|
1332
|
+
case "NOT_INCLUDES":
|
|
1333
|
+
return !g.includes(V.value);
|
|
1334
|
+
default:
|
|
1335
|
+
return !1;
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
return c === "AND" ? p.every(Boolean) : p.some(Boolean);
|
|
1339
|
+
}, [t, s, u, r]) ? e : null;
|
|
1340
|
+
}, Ur = ({
|
|
1341
|
+
children: e,
|
|
1342
|
+
onSubmit: t = () => {
|
|
1343
|
+
},
|
|
1344
|
+
onError: r = () => {
|
|
1345
|
+
},
|
|
1346
|
+
style: s = {},
|
|
1347
|
+
className: u = "",
|
|
1348
|
+
formOptions: i,
|
|
1349
|
+
showAsterisk: l,
|
|
1350
|
+
ref: c
|
|
1351
|
+
}) => {
|
|
1352
|
+
const v = vt({
|
|
1353
|
+
mode: "onSubmit",
|
|
1354
|
+
reValidateMode: "onChange",
|
|
1355
|
+
shouldFocusError: !0,
|
|
1356
|
+
...i
|
|
1357
|
+
});
|
|
1358
|
+
return Fr(
|
|
1359
|
+
c,
|
|
1360
|
+
() => ({
|
|
1361
|
+
setValue: v.setValue,
|
|
1362
|
+
setError: v.setError,
|
|
1363
|
+
clearErrors: v.clearErrors,
|
|
1364
|
+
getValues: v.getValues,
|
|
1365
|
+
reset: v.reset,
|
|
1366
|
+
setFocus: v.setFocus,
|
|
1367
|
+
resetField: v.resetField,
|
|
1368
|
+
trigger: v.trigger,
|
|
1369
|
+
unregister: v.unregister,
|
|
1370
|
+
watch: v.watch
|
|
1371
|
+
}),
|
|
1372
|
+
[v]
|
|
1373
|
+
), /* @__PURE__ */ ne(Vt, { showAsterisk: l, children: /* @__PURE__ */ ne(Xr, { ...v, children: /* @__PURE__ */ ne(
|
|
1374
|
+
"form",
|
|
1375
|
+
{
|
|
1376
|
+
noValidate: !0,
|
|
1377
|
+
onSubmit: v.handleSubmit(t, r),
|
|
1378
|
+
style: s,
|
|
1379
|
+
className: u,
|
|
1380
|
+
children: e
|
|
1381
|
+
}
|
|
1382
|
+
) }) });
|
|
1383
|
+
}, Ze = ({
|
|
1384
|
+
children: e,
|
|
1385
|
+
name: t,
|
|
1386
|
+
rules: r,
|
|
1387
|
+
className: s,
|
|
1388
|
+
label: u,
|
|
1389
|
+
id: i,
|
|
1390
|
+
disabled: l,
|
|
1391
|
+
shouldUnregister: c,
|
|
1392
|
+
visibility: v
|
|
1393
|
+
}) => {
|
|
1394
|
+
const { control: p } = _e(), V = e.props.value, { showAsterisk: g } = Ft(), b = e.props.onChange, H = e.props.onBlur, I = We(() => i || crypto.randomUUID(), []), C = /* @__PURE__ */ ne(
|
|
1395
|
+
rt,
|
|
1396
|
+
{
|
|
1397
|
+
control: p,
|
|
1398
|
+
name: t,
|
|
1399
|
+
rules: r,
|
|
1400
|
+
defaultValue: V,
|
|
1401
|
+
disabled: l,
|
|
1402
|
+
shouldUnregister: c,
|
|
1403
|
+
render: ({ field: { name: B, onBlur: j, value: S, onChange: P, ref: f }, fieldState: { error: y } }) => /* @__PURE__ */ cr(
|
|
1404
|
+
"div",
|
|
1405
|
+
{
|
|
1406
|
+
className: `controlled-field ${s}`,
|
|
1407
|
+
style: { display: "flex", flexDirection: "column", gap: "5px" },
|
|
1408
|
+
children: [
|
|
1409
|
+
u && /* @__PURE__ */ cr("label", { htmlFor: I, className: "controlled-field-label", children: [
|
|
1410
|
+
u,
|
|
1411
|
+
g && !!r && /* @__PURE__ */ ne("span", { style: { color: "red" }, children: " *" })
|
|
1412
|
+
] }),
|
|
1413
|
+
He(e, {
|
|
1414
|
+
...e.props,
|
|
1415
|
+
id: I,
|
|
1416
|
+
name: B,
|
|
1417
|
+
disabled: l,
|
|
1418
|
+
onChange: (...x) => {
|
|
1419
|
+
P(...x), b == null || b(...x);
|
|
1420
|
+
},
|
|
1421
|
+
value: S,
|
|
1422
|
+
onBlur: (...x) => {
|
|
1423
|
+
j(), H == null || H(...x);
|
|
1424
|
+
},
|
|
1425
|
+
ref: f
|
|
1426
|
+
}),
|
|
1427
|
+
y && /* @__PURE__ */ ne("div", { style: { color: "red", fontSize: 13 }, className: "controlled-field-error", children: y.message })
|
|
1428
|
+
]
|
|
1429
|
+
}
|
|
1430
|
+
)
|
|
1431
|
+
}
|
|
1432
|
+
);
|
|
1433
|
+
return v ? /* @__PURE__ */ ne(bt, { visibility: v, children: C }) : C;
|
|
1434
|
+
}, At = ({ name: e, rules: t, ref: r, children: s }) => {
|
|
1435
|
+
const u = ht({
|
|
1436
|
+
name: e,
|
|
1437
|
+
rules: t
|
|
1438
|
+
});
|
|
1439
|
+
Fr(r, () => u, [u]);
|
|
1440
|
+
const i = (l, c) => zr.map(l, (v) => {
|
|
1441
|
+
if (!Kr(v))
|
|
1442
|
+
return v;
|
|
1443
|
+
const p = v.props, V = v.type;
|
|
1444
|
+
if (((V == null ? void 0 : V.displayName) === "SuprFormControl" || V === Ze || p.name !== void 0 && typeof V != "string") && p.name !== void 0) {
|
|
1445
|
+
const b = {
|
|
1446
|
+
...p,
|
|
1447
|
+
name: `${c}${p.name}`
|
|
1448
|
+
};
|
|
1449
|
+
return p.id !== void 0 && (b.id = `${c}${p.id}`), He(v, b);
|
|
1450
|
+
}
|
|
1451
|
+
return p.children ? He(v, {
|
|
1452
|
+
...p,
|
|
1453
|
+
children: i(p.children, c)
|
|
1454
|
+
}) : v;
|
|
1455
|
+
});
|
|
1456
|
+
return /* @__PURE__ */ ne(jr, { children: u.fields.map((l, c) => {
|
|
1457
|
+
const v = `${e}.${c}.`;
|
|
1458
|
+
return i(s, v);
|
|
1459
|
+
}) });
|
|
1460
|
+
};
|
|
1461
|
+
Ze.displayName = "SuprFormControl";
|
|
1462
|
+
Ur.Control = Ze;
|
|
1463
|
+
Ur.ControlArray = At;
|
|
1464
|
+
export {
|
|
1465
|
+
Ur as SuprForm
|
|
1466
|
+
};
|
|
2
1467
|
//# sourceMappingURL=suprform.es.js.map
|