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