react-simple-formkit 2.4.7 → 2.4.8
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 +27 -23
- package/dist/react-simple-formkit.js +1 -22
- package/dist/react-simple-formkit.mjs +382 -661
- package/dist/react-simple-formkit.umd.js +1 -22
- package/package.json +5 -4
|
@@ -1,391 +1,112 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* react-jsx-runtime.production.js
|
|
6
|
-
*
|
|
7
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the MIT license found in the
|
|
10
|
-
* LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/
|
|
12
|
-
var vr;
|
|
13
|
-
function Pr() {
|
|
14
|
-
if (vr) return er;
|
|
15
|
-
vr = 1;
|
|
16
|
-
var s = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
17
|
-
function u(l, c, f) {
|
|
18
|
-
var o = null;
|
|
19
|
-
if (f !== void 0 && (o = "" + f), c.key !== void 0 && (o = "" + c.key), "key" in c) {
|
|
20
|
-
f = {};
|
|
21
|
-
for (var b in c)
|
|
22
|
-
b !== "key" && (f[b] = c[b]);
|
|
23
|
-
} else f = c;
|
|
24
|
-
return c = f.ref, {
|
|
25
|
-
$$typeof: s,
|
|
26
|
-
type: l,
|
|
27
|
-
key: o,
|
|
28
|
-
ref: c !== void 0 ? c : null,
|
|
29
|
-
props: f
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return er.Fragment = t, er.jsx = u, er.jsxs = u, er;
|
|
33
|
-
}
|
|
34
|
-
var tr = {};
|
|
35
|
-
/**
|
|
36
|
-
* @license React
|
|
37
|
-
* react-jsx-runtime.development.js
|
|
38
|
-
*
|
|
39
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
40
|
-
*
|
|
41
|
-
* This source code is licensed under the MIT license found in the
|
|
42
|
-
* LICENSE file in the root directory of this source tree.
|
|
43
|
-
*/
|
|
44
|
-
var Rr;
|
|
45
|
-
function kr() {
|
|
46
|
-
return Rr || (Rr = 1, process.env.NODE_ENV !== "production" && function() {
|
|
47
|
-
function s(e) {
|
|
48
|
-
if (e == null) return null;
|
|
49
|
-
if (typeof e == "function")
|
|
50
|
-
return e.$$typeof === nr ? null : e.displayName || e.name || null;
|
|
51
|
-
if (typeof e == "string") return e;
|
|
52
|
-
switch (e) {
|
|
53
|
-
case S:
|
|
54
|
-
return "Fragment";
|
|
55
|
-
case y:
|
|
56
|
-
return "Profiler";
|
|
57
|
-
case $:
|
|
58
|
-
return "StrictMode";
|
|
59
|
-
case x:
|
|
60
|
-
return "Suspense";
|
|
61
|
-
case q:
|
|
62
|
-
return "SuspenseList";
|
|
63
|
-
case F:
|
|
64
|
-
return "Activity";
|
|
65
|
-
}
|
|
66
|
-
if (typeof e == "object")
|
|
67
|
-
switch (typeof e.tag == "number" && console.error(
|
|
68
|
-
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
69
|
-
), e.$$typeof) {
|
|
70
|
-
case A:
|
|
71
|
-
return "Portal";
|
|
72
|
-
case O:
|
|
73
|
-
return (e.displayName || "Context") + ".Provider";
|
|
74
|
-
case _:
|
|
75
|
-
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
|
-
case P:
|
|
77
|
-
var g = e.render;
|
|
78
|
-
return e = e.displayName, e || (e = g.displayName || g.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
79
|
-
case H:
|
|
80
|
-
return g = e.displayName || null, g !== null ? g : s(e.type) || "Memo";
|
|
81
|
-
case J:
|
|
82
|
-
g = e._payload, e = e._init;
|
|
83
|
-
try {
|
|
84
|
-
return s(e(g));
|
|
85
|
-
} catch {
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
function t(e) {
|
|
91
|
-
return "" + e;
|
|
92
|
-
}
|
|
93
|
-
function u(e) {
|
|
94
|
-
try {
|
|
95
|
-
t(e);
|
|
96
|
-
var g = !1;
|
|
97
|
-
} catch {
|
|
98
|
-
g = !0;
|
|
99
|
-
}
|
|
100
|
-
if (g) {
|
|
101
|
-
g = console;
|
|
102
|
-
var T = g.error, w = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
103
|
-
return T.call(
|
|
104
|
-
g,
|
|
105
|
-
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
106
|
-
w
|
|
107
|
-
), t(e);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function l(e) {
|
|
111
|
-
if (e === S) return "<>";
|
|
112
|
-
if (typeof e == "object" && e !== null && e.$$typeof === J)
|
|
113
|
-
return "<...>";
|
|
114
|
-
try {
|
|
115
|
-
var g = s(e);
|
|
116
|
-
return g ? "<" + g + ">" : "<...>";
|
|
117
|
-
} catch {
|
|
118
|
-
return "<...>";
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function c() {
|
|
122
|
-
var e = K.A;
|
|
123
|
-
return e === null ? null : e.getOwner();
|
|
124
|
-
}
|
|
125
|
-
function f() {
|
|
126
|
-
return Error("react-stack-top-frame");
|
|
127
|
-
}
|
|
128
|
-
function o(e) {
|
|
129
|
-
if (sr.call(e, "key")) {
|
|
130
|
-
var g = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
131
|
-
if (g && g.isReactWarning) return !1;
|
|
132
|
-
}
|
|
133
|
-
return e.key !== void 0;
|
|
134
|
-
}
|
|
135
|
-
function b(e, g) {
|
|
136
|
-
function T() {
|
|
137
|
-
z || (z = !0, console.error(
|
|
138
|
-
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
139
|
-
g
|
|
140
|
-
));
|
|
141
|
-
}
|
|
142
|
-
T.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
143
|
-
get: T,
|
|
144
|
-
configurable: !0
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function E() {
|
|
148
|
-
var e = s(this.type);
|
|
149
|
-
return or[e] || (or[e] = !0, console.error(
|
|
150
|
-
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
151
|
-
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
152
|
-
}
|
|
153
|
-
function R(e, g, T, w, L, I, Z, Q) {
|
|
154
|
-
return T = I.ref, e = {
|
|
155
|
-
$$typeof: C,
|
|
156
|
-
type: e,
|
|
157
|
-
key: g,
|
|
158
|
-
props: I,
|
|
159
|
-
_owner: L
|
|
160
|
-
}, (T !== void 0 ? T : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
|
-
enumerable: !1,
|
|
162
|
-
get: E
|
|
163
|
-
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
164
|
-
configurable: !1,
|
|
165
|
-
enumerable: !1,
|
|
166
|
-
writable: !0,
|
|
167
|
-
value: 0
|
|
168
|
-
}), Object.defineProperty(e, "_debugInfo", {
|
|
169
|
-
configurable: !1,
|
|
170
|
-
enumerable: !1,
|
|
171
|
-
writable: !0,
|
|
172
|
-
value: null
|
|
173
|
-
}), Object.defineProperty(e, "_debugStack", {
|
|
174
|
-
configurable: !1,
|
|
175
|
-
enumerable: !1,
|
|
176
|
-
writable: !0,
|
|
177
|
-
value: Z
|
|
178
|
-
}), Object.defineProperty(e, "_debugTask", {
|
|
179
|
-
configurable: !1,
|
|
180
|
-
enumerable: !1,
|
|
181
|
-
writable: !0,
|
|
182
|
-
value: Q
|
|
183
|
-
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
|
-
}
|
|
185
|
-
function m(e, g, T, w, L, I, Z, Q) {
|
|
186
|
-
var j = g.children;
|
|
187
|
-
if (j !== void 0)
|
|
188
|
-
if (w)
|
|
189
|
-
if (fr(j)) {
|
|
190
|
-
for (w = 0; w < j.length; w++)
|
|
191
|
-
a(j[w]);
|
|
192
|
-
Object.freeze && Object.freeze(j);
|
|
193
|
-
} else
|
|
194
|
-
console.error(
|
|
195
|
-
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
196
|
-
);
|
|
197
|
-
else a(j);
|
|
198
|
-
if (sr.call(g, "key")) {
|
|
199
|
-
j = s(e);
|
|
200
|
-
var V = Object.keys(g).filter(function(dr) {
|
|
201
|
-
return dr !== "key";
|
|
202
|
-
});
|
|
203
|
-
w = 0 < V.length ? "{key: someKey, " + V.join(": ..., ") + ": ...}" : "{key: someKey}", cr[j + w] || (V = 0 < V.length ? "{" + V.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
204
|
-
`A props object containing a "key" prop is being spread into JSX:
|
|
205
|
-
let props = %s;
|
|
206
|
-
<%s {...props} />
|
|
207
|
-
React keys must be passed directly to JSX without using spread:
|
|
208
|
-
let props = %s;
|
|
209
|
-
<%s key={someKey} {...props} />`,
|
|
210
|
-
w,
|
|
211
|
-
j,
|
|
212
|
-
V,
|
|
213
|
-
j
|
|
214
|
-
), cr[j + w] = !0);
|
|
215
|
-
}
|
|
216
|
-
if (j = null, T !== void 0 && (u(T), j = "" + T), o(g) && (u(g.key), j = "" + g.key), "key" in g) {
|
|
217
|
-
T = {};
|
|
218
|
-
for (var rr in g)
|
|
219
|
-
rr !== "key" && (T[rr] = g[rr]);
|
|
220
|
-
} else T = g;
|
|
221
|
-
return j && b(
|
|
222
|
-
T,
|
|
223
|
-
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
|
-
), R(
|
|
225
|
-
e,
|
|
226
|
-
j,
|
|
227
|
-
I,
|
|
228
|
-
L,
|
|
229
|
-
c(),
|
|
230
|
-
T,
|
|
231
|
-
Z,
|
|
232
|
-
Q
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
function a(e) {
|
|
236
|
-
typeof e == "object" && e !== null && e.$$typeof === C && e._store && (e._store.validated = 1);
|
|
237
|
-
}
|
|
238
|
-
var v = jr, C = Symbol.for("react.transitional.element"), A = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), $ = Symbol.for("react.strict_mode"), y = Symbol.for("react.profiler"), _ = Symbol.for("react.consumer"), O = Symbol.for("react.context"), P = Symbol.for("react.forward_ref"), x = Symbol.for("react.suspense"), q = Symbol.for("react.suspense_list"), H = Symbol.for("react.memo"), J = Symbol.for("react.lazy"), F = Symbol.for("react.activity"), nr = Symbol.for("react.client.reference"), K = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, sr = Object.prototype.hasOwnProperty, fr = Array.isArray, X = console.createTask ? console.createTask : function() {
|
|
239
|
-
return null;
|
|
240
|
-
};
|
|
241
|
-
v = {
|
|
242
|
-
"react-stack-bottom-frame": function(e) {
|
|
243
|
-
return e();
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
var z, or = {}, W = v["react-stack-bottom-frame"].bind(
|
|
247
|
-
v,
|
|
248
|
-
f
|
|
249
|
-
)(), ur = X(l(f)), cr = {};
|
|
250
|
-
tr.Fragment = S, tr.jsx = function(e, g, T, w, L) {
|
|
251
|
-
var I = 1e4 > K.recentlyCreatedOwnerStacks++;
|
|
252
|
-
return m(
|
|
253
|
-
e,
|
|
254
|
-
g,
|
|
255
|
-
T,
|
|
256
|
-
!1,
|
|
257
|
-
w,
|
|
258
|
-
L,
|
|
259
|
-
I ? Error("react-stack-top-frame") : W,
|
|
260
|
-
I ? X(l(e)) : ur
|
|
261
|
-
);
|
|
262
|
-
}, tr.jsxs = function(e, g, T, w, L) {
|
|
263
|
-
var I = 1e4 > K.recentlyCreatedOwnerStacks++;
|
|
264
|
-
return m(
|
|
265
|
-
e,
|
|
266
|
-
g,
|
|
267
|
-
T,
|
|
268
|
-
!0,
|
|
269
|
-
w,
|
|
270
|
-
L,
|
|
271
|
-
I ? Error("react-stack-top-frame") : W,
|
|
272
|
-
I ? X(l(e)) : ur
|
|
273
|
-
);
|
|
274
|
-
};
|
|
275
|
-
}()), tr;
|
|
276
|
-
}
|
|
277
|
-
var Sr;
|
|
278
|
-
function Nr() {
|
|
279
|
-
return Sr || (Sr = 1, process.env.NODE_ENV === "production" ? ir.exports = Pr() : ir.exports = kr()), ir.exports;
|
|
280
|
-
}
|
|
281
|
-
var yr = Nr();
|
|
282
|
-
const p = () => {
|
|
283
|
-
}, Ar = wr({
|
|
1
|
+
import { jsx as tr } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as $r, useContext as Cr, useCallback as l, useEffect as q, useState as U, useRef as N, useMemo as Q, useLayoutEffect as pr } from "react";
|
|
3
|
+
const F = () => {
|
|
4
|
+
}, nr = $r({
|
|
284
5
|
ref: null,
|
|
285
|
-
watch:
|
|
6
|
+
watch: F,
|
|
286
7
|
actions: {
|
|
287
|
-
subscribe:
|
|
288
|
-
reset:
|
|
289
|
-
trigger:
|
|
290
|
-
reload:
|
|
291
|
-
resetField:
|
|
292
|
-
setValue:
|
|
293
|
-
getValues:
|
|
294
|
-
getErrors:
|
|
295
|
-
getFieldStates:
|
|
296
|
-
getFormState:
|
|
297
|
-
setError:
|
|
298
|
-
clearError:
|
|
299
|
-
clearErrors:
|
|
300
|
-
checkValidity:
|
|
301
|
-
getFieldValidity:
|
|
302
|
-
getDefaultValues:
|
|
303
|
-
setFieldState:
|
|
304
|
-
triggerFieldBlur:
|
|
305
|
-
resetFieldState:
|
|
306
|
-
getControlledFields:
|
|
307
|
-
setFormState:
|
|
308
|
-
getEvents:
|
|
309
|
-
getWatchEvents:
|
|
310
|
-
addGroups:
|
|
8
|
+
subscribe: F,
|
|
9
|
+
reset: F,
|
|
10
|
+
trigger: F,
|
|
11
|
+
reload: F,
|
|
12
|
+
resetField: F,
|
|
13
|
+
setValue: F,
|
|
14
|
+
getValues: F,
|
|
15
|
+
getErrors: F,
|
|
16
|
+
getFieldStates: F,
|
|
17
|
+
getFormState: F,
|
|
18
|
+
setError: F,
|
|
19
|
+
clearError: F,
|
|
20
|
+
clearErrors: F,
|
|
21
|
+
checkValidity: F,
|
|
22
|
+
getFieldValidity: F,
|
|
23
|
+
getDefaultValues: F,
|
|
24
|
+
setFieldState: F,
|
|
25
|
+
triggerFieldBlur: F,
|
|
26
|
+
resetFieldState: F,
|
|
27
|
+
getControlledFields: F,
|
|
28
|
+
setFormState: F,
|
|
29
|
+
getEvents: F,
|
|
30
|
+
getWatchEvents: F,
|
|
31
|
+
addGroups: F
|
|
311
32
|
},
|
|
312
|
-
registerController:
|
|
313
|
-
registerHookWatcher:
|
|
314
|
-
lastReloadedAt:
|
|
315
|
-
loadFormValues:
|
|
316
|
-
getWatchValue:
|
|
33
|
+
registerController: F,
|
|
34
|
+
registerHookWatcher: F,
|
|
35
|
+
lastReloadedAt: F,
|
|
36
|
+
loadFormValues: F,
|
|
37
|
+
getWatchValue: F,
|
|
317
38
|
channels: {}
|
|
318
|
-
}),
|
|
39
|
+
}), or = () => Cr(nr), Ir = ({
|
|
319
40
|
id: s,
|
|
320
41
|
control: t,
|
|
321
|
-
method:
|
|
322
|
-
action:
|
|
323
|
-
children:
|
|
324
|
-
onChange:
|
|
325
|
-
onBlur:
|
|
326
|
-
onSubmit:
|
|
42
|
+
method: o,
|
|
43
|
+
action: f,
|
|
44
|
+
children: a,
|
|
45
|
+
onChange: b,
|
|
46
|
+
onBlur: n,
|
|
47
|
+
onSubmit: h = () => {
|
|
327
48
|
},
|
|
328
|
-
onInput:
|
|
49
|
+
onInput: d = () => {
|
|
329
50
|
},
|
|
330
|
-
onReset:
|
|
51
|
+
onReset: E = () => {
|
|
331
52
|
},
|
|
332
|
-
numberFields:
|
|
333
|
-
className:
|
|
334
|
-
...
|
|
53
|
+
numberFields: g = [],
|
|
54
|
+
className: u,
|
|
55
|
+
...y
|
|
335
56
|
}) => {
|
|
336
|
-
const
|
|
337
|
-
(
|
|
338
|
-
t.ref && (t.ref.current =
|
|
57
|
+
const A = l(
|
|
58
|
+
($) => {
|
|
59
|
+
t.ref && (t.ref.current = $, t.ref.current && t.initForm());
|
|
339
60
|
},
|
|
340
61
|
[t]
|
|
341
62
|
);
|
|
342
|
-
return
|
|
343
|
-
let
|
|
344
|
-
},
|
|
63
|
+
return q(() => {
|
|
64
|
+
let $ = () => {
|
|
65
|
+
}, m = () => {
|
|
345
66
|
};
|
|
346
|
-
return
|
|
347
|
-
|
|
67
|
+
return b && ($ = t.channels.subscribe("onChange", b)), n && (m = t.channels.subscribe("onBlur", n)), () => {
|
|
68
|
+
$(), m();
|
|
348
69
|
};
|
|
349
|
-
}, [t.lastReloadedAt]), /* @__PURE__ */
|
|
70
|
+
}, [t.lastReloadedAt]), /* @__PURE__ */ tr(nr.Provider, { value: t, children: /* @__PURE__ */ tr(
|
|
350
71
|
"form",
|
|
351
72
|
{
|
|
352
73
|
id: s,
|
|
353
|
-
ref:
|
|
354
|
-
action:
|
|
355
|
-
method:
|
|
356
|
-
className:
|
|
357
|
-
onInput:
|
|
358
|
-
onSubmit: (
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
|
|
74
|
+
ref: A,
|
|
75
|
+
action: f,
|
|
76
|
+
method: o,
|
|
77
|
+
className: u,
|
|
78
|
+
onInput: d,
|
|
79
|
+
onSubmit: ($) => {
|
|
80
|
+
o || $.preventDefault();
|
|
81
|
+
const m = t.loadFormValues();
|
|
82
|
+
h(m);
|
|
362
83
|
},
|
|
363
|
-
onChange: (
|
|
364
|
-
const
|
|
365
|
-
!
|
|
84
|
+
onChange: ($) => {
|
|
85
|
+
const m = $.target.name;
|
|
86
|
+
!m || t.actions.getControlledFields().has(m) || t.actions.setValue(m, $.target.value);
|
|
366
87
|
},
|
|
367
|
-
onBlur: (
|
|
368
|
-
const
|
|
369
|
-
if (!
|
|
370
|
-
const
|
|
371
|
-
t.channels.publish("onBlur",
|
|
88
|
+
onBlur: ($) => {
|
|
89
|
+
const m = $.target.name;
|
|
90
|
+
if (!m || t.actions.getControlledFields().has(m)) return;
|
|
91
|
+
const B = $.target.value;
|
|
92
|
+
t.channels.publish("onBlur", m, B, t.actions.getValues()), t.triggerBlurWatchers(m);
|
|
372
93
|
},
|
|
373
|
-
onReset: (
|
|
374
|
-
t.actions.reset(),
|
|
94
|
+
onReset: ($) => {
|
|
95
|
+
t.actions.reset(), E($);
|
|
375
96
|
},
|
|
376
|
-
...
|
|
377
|
-
children:
|
|
97
|
+
...y,
|
|
98
|
+
children: a
|
|
378
99
|
},
|
|
379
100
|
t.lastReloadedAt
|
|
380
101
|
) });
|
|
381
|
-
},
|
|
102
|
+
}, X = { isDirty: !1, isTouched: !1, error: null }, er = {
|
|
382
103
|
lastReset: null,
|
|
383
104
|
isDirty: !1,
|
|
384
105
|
isError: !1,
|
|
385
106
|
errorFields: [],
|
|
386
107
|
dirtyFields: [],
|
|
387
108
|
touchedFields: []
|
|
388
|
-
},
|
|
109
|
+
}, Ar = {}, Dr = [
|
|
389
110
|
"badInput",
|
|
390
111
|
"customError",
|
|
391
112
|
"patternMismatch",
|
|
@@ -396,395 +117,395 @@ const p = () => {
|
|
|
396
117
|
"tooShort",
|
|
397
118
|
"typeMismatch",
|
|
398
119
|
"valueMissing"
|
|
399
|
-
],
|
|
400
|
-
const
|
|
401
|
-
let
|
|
402
|
-
const
|
|
403
|
-
return
|
|
404
|
-
|
|
405
|
-
}),
|
|
406
|
-
},
|
|
120
|
+
], R = (s = {}, t = "") => t.split(".").reduce((o, f) => o && o[f] !== void 0 ? o[f] : void 0, s), M = (s = {}, t = "", o) => {
|
|
121
|
+
const f = Array.isArray(s) ? [...s] : { ...s };
|
|
122
|
+
let a = f;
|
|
123
|
+
const b = t.split(".");
|
|
124
|
+
return b.forEach((n, h) => {
|
|
125
|
+
h < b.length - 1 ? (a[n] || (a[n] = /^\d+$/.test(b[h + 1]) ? [] : {}), Array.isArray(a[n]) ? a[n] = [...a[n]] : a[n] = { ...a[n] }, a = a[n]) : a[n] = o;
|
|
126
|
+
}), f;
|
|
127
|
+
}, Rr = (s) => {
|
|
407
128
|
let t = Array.isArray(s) ? [...s] : { ...s };
|
|
408
|
-
return Object.keys(t).forEach((
|
|
409
|
-
if (
|
|
410
|
-
const
|
|
411
|
-
t = M(t,
|
|
129
|
+
return Object.keys(t).forEach((o) => {
|
|
130
|
+
if (o.includes(".")) {
|
|
131
|
+
const f = R(t, o);
|
|
132
|
+
t = M(t, o, f || ""), delete t[o];
|
|
412
133
|
}
|
|
413
134
|
}), t;
|
|
414
|
-
}, Br = ["errors", "fieldStates", "formState"],
|
|
135
|
+
}, Br = ["errors", "fieldStates", "formState"], I = (s) => Br.some((t) => s.startsWith(t)) ? s : "values." + s, sr = (s) => {
|
|
415
136
|
typeof s.setCustomValidity == "function" && s.setCustomValidity("");
|
|
416
|
-
let t = s.validity,
|
|
417
|
-
if (
|
|
418
|
-
},
|
|
419
|
-
const
|
|
420
|
-
return s.has(
|
|
421
|
-
}, []),
|
|
422
|
-
const
|
|
423
|
-
return s.has(
|
|
424
|
-
}, []),
|
|
425
|
-
const
|
|
426
|
-
return s.has(
|
|
427
|
-
}, []),
|
|
428
|
-
const { getWatchValue:
|
|
429
|
-
return
|
|
430
|
-
},
|
|
431
|
-
const { actions:
|
|
432
|
-
(
|
|
433
|
-
var
|
|
434
|
-
let
|
|
435
|
-
((
|
|
137
|
+
let t = s.validity, o = Dr.find((f) => t[f]);
|
|
138
|
+
if (o) return { type: o, message: s.validationMessage };
|
|
139
|
+
}, cr = (s = /* @__PURE__ */ new Set(), t = {}, o = "") => Object.keys(t || {}).reduce((f, a) => {
|
|
140
|
+
const b = (t || {})[a];
|
|
141
|
+
return s.has(o + a) ? [...f, ...cr(s, b, o + a + ".")] : b != null && b.isDirty ? [...f, o + a] : f;
|
|
142
|
+
}, []), ur = (s = /* @__PURE__ */ new Set(), t = {}, o = "") => Object.keys(t || {}).reduce((f, a) => {
|
|
143
|
+
const b = (t || {})[a];
|
|
144
|
+
return s.has(o + a) ? [...f, ...ur(s, b, o + a + ".")] : b != null && b.isTouched ? [...f, o + a] : f;
|
|
145
|
+
}, []), ir = (s = /* @__PURE__ */ new Set(), t = {}, o = "") => Object.keys(t || {}).reduce((f, a) => {
|
|
146
|
+
const b = (t || {})[a];
|
|
147
|
+
return s.has(o + a) ? [...f, ...ir(s, b, o + a + ".")] : b ? [...f, o + a] : f;
|
|
148
|
+
}, []), jr = ({ control: s, name: t, compute: o, mode: f }) => {
|
|
149
|
+
const { getWatchValue: a, registerHookWatcher: b } = s || or(), n = a({ name: t, compute: o }), [h, d] = U(n);
|
|
150
|
+
return q(() => b({ name: t, compute: o, value: h, setValue: d, mode: f }), []), h;
|
|
151
|
+
}, wr = ({ control: s, name: t, defaultValue: o, shouldUnRegister: f }) => {
|
|
152
|
+
const { actions: a, registerController: b, channels: n, getWatchValue: h, triggerBlurWatchers: d } = s || or(), E = N(), g = N(), u = R(a.getDefaultValues(), t) || o || "", y = jr({ name: t }) ?? u, [A, $] = U({}), m = l(
|
|
153
|
+
(S, { shouldDirty: C = !0, shouldOnChange: p = !0 } = {}) => {
|
|
154
|
+
var W;
|
|
155
|
+
let j = S;
|
|
156
|
+
((W = S == null ? void 0 : S.target) == null ? void 0 : W.value) !== void 0 && (j = S.target.value), a.setValue(t, j, { shouldDirty: C, shouldOnChange: p });
|
|
436
157
|
},
|
|
437
|
-
[
|
|
438
|
-
),
|
|
439
|
-
const
|
|
440
|
-
|
|
158
|
+
[a.setValue]
|
|
159
|
+
), B = l((S) => {
|
|
160
|
+
const C = a.getValues(), p = S ?? R(C, t);
|
|
161
|
+
n.publish("onBlur", t, p, C), d(t);
|
|
441
162
|
}, []);
|
|
442
|
-
return
|
|
443
|
-
const
|
|
163
|
+
return q(() => {
|
|
164
|
+
const S = b(t, { shouldUnRegister: f });
|
|
444
165
|
return () => {
|
|
445
|
-
|
|
166
|
+
S && S(), g.current && g.current();
|
|
446
167
|
};
|
|
447
|
-
}, [
|
|
448
|
-
{ ref:
|
|
168
|
+
}, [f, t]), new Proxy(
|
|
169
|
+
{ ref: E, name: t, defaultValue: u, value: y, onChange: m, onBlur: B, fieldState: A },
|
|
449
170
|
{
|
|
450
|
-
get(
|
|
451
|
-
return typeof
|
|
452
|
-
|
|
453
|
-
})), Reflect.get(
|
|
171
|
+
get(S, C, p) {
|
|
172
|
+
return typeof C == "string" && C === "fieldState" && (g.current && g.current(), g.current = a.subscribe(`fieldStates.${t}`, () => {
|
|
173
|
+
$(h({ name: `fieldStates.${t}` }));
|
|
174
|
+
})), Reflect.get(S, C, p);
|
|
454
175
|
}
|
|
455
176
|
}
|
|
456
177
|
);
|
|
457
|
-
},
|
|
178
|
+
}, Gr = ({
|
|
458
179
|
name: s,
|
|
459
180
|
control: t,
|
|
460
|
-
shouldUnRegister:
|
|
461
|
-
defaultValue:
|
|
462
|
-
render:
|
|
181
|
+
shouldUnRegister: o,
|
|
182
|
+
defaultValue: f,
|
|
183
|
+
render: a = ({ ref: b, name: n, defaultValue: h, value: d, onChange: E, onBlur: g, fieldState: u }) => null
|
|
463
184
|
}) => {
|
|
464
|
-
const
|
|
465
|
-
return
|
|
466
|
-
},
|
|
467
|
-
const [s, t] =
|
|
468
|
-
return [s,
|
|
469
|
-
},
|
|
470
|
-
const [, s] =
|
|
471
|
-
return
|
|
472
|
-
},
|
|
473
|
-
const
|
|
474
|
-
if (!
|
|
475
|
-
return s.subscribeWatch("values", () =>
|
|
476
|
-
if (typeof
|
|
477
|
-
let
|
|
478
|
-
|
|
479
|
-
|
|
185
|
+
const b = wr({ name: s, defaultValue: f, shouldUnRegister: o, control: t });
|
|
186
|
+
return a(b);
|
|
187
|
+
}, Or = () => {
|
|
188
|
+
const [s, t] = U(), o = l(() => t((/* @__PURE__ */ new Date()).toString()), []);
|
|
189
|
+
return [s, o];
|
|
190
|
+
}, Wr = () => {
|
|
191
|
+
const [, s] = U({});
|
|
192
|
+
return l(() => s({}), []);
|
|
193
|
+
}, Nr = ({ channels: s, getWatchValue: t }) => {
|
|
194
|
+
const o = Wr(), f = l((n, h = "onChange") => {
|
|
195
|
+
if (!n)
|
|
196
|
+
return s.subscribeWatch("values", () => o()), t();
|
|
197
|
+
if (typeof n == "string") {
|
|
198
|
+
let d = I(n);
|
|
199
|
+
h === "onBlur" && (d = `blur.${d}`), s.subscribeWatch(d, (E, g) => {
|
|
200
|
+
E !== g && o();
|
|
480
201
|
});
|
|
481
202
|
}
|
|
482
|
-
return Array.isArray(
|
|
483
|
-
let
|
|
484
|
-
|
|
485
|
-
|
|
203
|
+
return Array.isArray(n) && n.forEach((d) => {
|
|
204
|
+
let E = I(d);
|
|
205
|
+
h === "onBlur" && (E = `blur.${E}`), s.subscribeWatch(E, (g, u) => {
|
|
206
|
+
g !== u && o();
|
|
486
207
|
});
|
|
487
|
-
}), t({ name:
|
|
488
|
-
}, []),
|
|
489
|
-
if (typeof
|
|
208
|
+
}), t({ name: n });
|
|
209
|
+
}, []), a = l(({ name: n, compute: h, setValue: d, mode: E = "onChange" }) => {
|
|
210
|
+
if (typeof h == "function")
|
|
490
211
|
return s.subscribe("values", () => {
|
|
491
|
-
const
|
|
492
|
-
|
|
212
|
+
const u = t({ compute: h });
|
|
213
|
+
d(u);
|
|
493
214
|
});
|
|
494
|
-
if (!
|
|
215
|
+
if (!n)
|
|
495
216
|
return s.subscribe("values", () => {
|
|
496
|
-
|
|
217
|
+
d(t());
|
|
497
218
|
});
|
|
498
|
-
if (typeof
|
|
499
|
-
let
|
|
500
|
-
return
|
|
501
|
-
const
|
|
502
|
-
|
|
219
|
+
if (typeof n == "string") {
|
|
220
|
+
let g = I(n);
|
|
221
|
+
return E === "onBlur" && (g = `blur.${g}`), s.subscribe(g, () => {
|
|
222
|
+
const y = t({ name: n });
|
|
223
|
+
d(y);
|
|
503
224
|
});
|
|
504
225
|
}
|
|
505
|
-
if (Array.isArray(
|
|
506
|
-
const
|
|
507
|
-
return
|
|
508
|
-
let
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
const
|
|
512
|
-
|
|
226
|
+
if (Array.isArray(n)) {
|
|
227
|
+
const g = [];
|
|
228
|
+
return n.forEach((u) => {
|
|
229
|
+
let y = I(u);
|
|
230
|
+
E === "onBlur" && (y = `blur.${y}`);
|
|
231
|
+
const A = s.subscribe(y, () => {
|
|
232
|
+
const $ = t({ name: n });
|
|
233
|
+
d($);
|
|
513
234
|
});
|
|
514
|
-
|
|
515
|
-
}), () =>
|
|
235
|
+
g.push(A);
|
|
236
|
+
}), () => g.forEach((u) => u());
|
|
516
237
|
}
|
|
517
238
|
throw new Error("Parameters of name must be string or array of string or compute must be a function");
|
|
518
|
-
}, []),
|
|
519
|
-
if (!
|
|
520
|
-
return s.subscribe("values", () =>
|
|
521
|
-
if (["onChange", "onBlur"].includes(
|
|
522
|
-
return s.subscribe(
|
|
523
|
-
if (typeof
|
|
524
|
-
let
|
|
525
|
-
return
|
|
239
|
+
}, []), b = l((n, h, d = "onChange") => {
|
|
240
|
+
if (!n)
|
|
241
|
+
return s.subscribe("values", () => h(t()));
|
|
242
|
+
if (["onChange", "onBlur"].includes(n))
|
|
243
|
+
return s.subscribe(n, h);
|
|
244
|
+
if (typeof n == "string") {
|
|
245
|
+
let E = I(n);
|
|
246
|
+
return d === "onBlur" && (E = `blur.${E}`), s.subscribe(E, () => h(t({ name: n })));
|
|
526
247
|
}
|
|
527
|
-
if (Array.isArray(
|
|
528
|
-
const
|
|
529
|
-
return
|
|
530
|
-
let
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
|
|
248
|
+
if (Array.isArray(n)) {
|
|
249
|
+
const E = [];
|
|
250
|
+
return n.forEach((g) => {
|
|
251
|
+
let u = I(g);
|
|
252
|
+
d === "onBlur" && (u = `blur.${u}`);
|
|
253
|
+
const y = s.subscribe(u, () => {
|
|
254
|
+
h(t({ name: n }));
|
|
534
255
|
});
|
|
535
|
-
|
|
536
|
-
}), () =>
|
|
256
|
+
E.push(y);
|
|
257
|
+
}), () => E.forEach((g) => g());
|
|
537
258
|
}
|
|
538
259
|
throw new Error("Parameters of name must be string or array of string");
|
|
539
260
|
}, []);
|
|
540
|
-
return { watch:
|
|
541
|
-
},
|
|
542
|
-
const t =
|
|
543
|
-
t.current.clear(),
|
|
544
|
-
}, []),
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
if (
|
|
549
|
-
const
|
|
550
|
-
|
|
261
|
+
return { watch: f, registerHookWatcher: a, getWatchValue: t, subscribe: b };
|
|
262
|
+
}, Pr = ({ getWatchValue: s }) => {
|
|
263
|
+
const t = N(/* @__PURE__ */ new Map()), o = N(/* @__PURE__ */ new Map()), f = l(() => o.current, []), a = l(() => t.current, []), b = l(() => {
|
|
264
|
+
t.current.clear(), o.current.clear();
|
|
265
|
+
}, []), n = (u) => u.replace("values.", "").replace("values", ""), h = l((u, ...y) => {
|
|
266
|
+
const A = u.split(".");
|
|
267
|
+
A.forEach(($, m) => {
|
|
268
|
+
const B = A.slice(0, A.length - m).join("."), S = t.current.get(B), C = o.current.get(B);
|
|
269
|
+
if (m > 0) {
|
|
270
|
+
const p = y[0], j = s({ name: n(B) });
|
|
271
|
+
y = [M(j, u.replace(B, ""), p)];
|
|
551
272
|
}
|
|
552
|
-
|
|
273
|
+
S && S.forEach((p) => p(...y)), C && C.forEach((p) => p(...y));
|
|
553
274
|
});
|
|
554
|
-
}, []),
|
|
555
|
-
const
|
|
556
|
-
let
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
if (
|
|
560
|
-
const
|
|
561
|
-
|
|
275
|
+
}, []), d = l((u, { trickle: y = !1, bubble: A = !1 }) => {
|
|
276
|
+
const $ = u.split(".");
|
|
277
|
+
let m = [s({ name: n(u) })];
|
|
278
|
+
$.forEach((B, S) => {
|
|
279
|
+
const C = $.slice(0, $.length - S).join("."), p = t.current.get(C), j = o.current.get(C);
|
|
280
|
+
if (S > 0 && A) {
|
|
281
|
+
const W = m[0], G = s({ name: n(C) });
|
|
282
|
+
m = [M(G, u.replace(C, ""), W)];
|
|
562
283
|
}
|
|
563
|
-
|
|
564
|
-
}),
|
|
565
|
-
|
|
566
|
-
}),
|
|
567
|
-
|
|
284
|
+
p && (S === 0 || A) && p.forEach((W) => W(...m)), j && (S === 0 || A) && j.forEach((W) => W(...m));
|
|
285
|
+
}), y && (t.current.forEach((B, S) => {
|
|
286
|
+
S.startsWith(u) && B.forEach((C) => C(s({ name: n(S) })));
|
|
287
|
+
}), o.current.forEach((B, S) => {
|
|
288
|
+
S.startsWith(u) && B.forEach((C) => C(s({ name: n(S) })));
|
|
568
289
|
}));
|
|
569
|
-
}, []),
|
|
570
|
-
var
|
|
571
|
-
return (
|
|
572
|
-
}), []),
|
|
573
|
-
|
|
290
|
+
}, []), E = l((u, y) => (t.current.has(u) || t.current.set(u, /* @__PURE__ */ new Set()), t.current.get(u).add(y), () => {
|
|
291
|
+
var A;
|
|
292
|
+
return (A = t.current.get(u)) == null ? void 0 : A.delete(y);
|
|
293
|
+
}), []), g = l((u, y) => {
|
|
294
|
+
o.current.has(u) || (o.current.set(u, /* @__PURE__ */ new Set()), o.current.get(u).add(y));
|
|
574
295
|
}, []);
|
|
575
|
-
return { reset:
|
|
576
|
-
},
|
|
577
|
-
const [
|
|
578
|
-
if (typeof
|
|
579
|
-
return { ...
|
|
580
|
-
const
|
|
581
|
-
return { ...
|
|
582
|
-
}, {}), []),
|
|
583
|
-
(r = {}, { clearCustomFormStates:
|
|
584
|
-
|
|
296
|
+
return { reset: b, publish: h, subscribe: E, subscribeWatch: g, getEvents: a, getWatchEvents: f, trigger: d };
|
|
297
|
+
}, Hr = ({ defaultValues: s = Ar, shouldUnRegister: t = !1, groups: o = [] } = {}) => {
|
|
298
|
+
const [f, a] = Or(), b = N(), n = N({}), h = N({}), d = N({ ...er }), E = N({ ...s }), g = N({ ...s }), u = N(/* @__PURE__ */ new Set()), y = N(new Set(o)), A = l((r, e = g.current) => Object.keys(e).reduce((c, i) => {
|
|
299
|
+
if (typeof e[i] == "object")
|
|
300
|
+
return { ...c, [i]: A(r, e[i]) };
|
|
301
|
+
const D = { ...r ? {} : h.current[i] || {}, ...X };
|
|
302
|
+
return { ...c, [i]: D };
|
|
303
|
+
}, {}), []), $ = l(
|
|
304
|
+
(r = {}, { clearCustomFormStates: e = !1, clearCustomFieldStates: c = !1, groups: i = y.current } = {}) => {
|
|
305
|
+
n.current = {}, g.current = { ...g.current, ...r }, E.current = { ...g.current }, u.current = /* @__PURE__ */ new Set(), y.current = new Set(i), d.current = { ...e ? {} : d.current, ...er }, h.current = A(c), v.reset(), a();
|
|
585
306
|
},
|
|
586
307
|
[]
|
|
587
|
-
),
|
|
588
|
-
let r = Object.fromEntries(new FormData(
|
|
589
|
-
|
|
590
|
-
r = M(r,
|
|
308
|
+
), m = l(() => {
|
|
309
|
+
let r = Object.fromEntries(new FormData(b.current));
|
|
310
|
+
u.current.forEach((c) => {
|
|
311
|
+
r = M(r, c, R(E.current, c));
|
|
591
312
|
});
|
|
592
|
-
let
|
|
593
|
-
return
|
|
594
|
-
}, []),
|
|
595
|
-
(r) =>
|
|
596
|
-
[
|
|
597
|
-
),
|
|
313
|
+
let e = { ...E.current, ...r };
|
|
314
|
+
return Rr(e);
|
|
315
|
+
}, []), B = l((r) => sr(r.target), []), S = l(() => g.current, []), C = l(() => u.current, []), p = l((r, e) => e ? Array.isArray(e) ? e.reduce((c, i) => ({ ...c, [i]: R(r, i) }), {}) : R(r, e) : r, []), j = l((r) => p(E.current, r), [p]), W = l((r) => p(n.current, r), [p]), G = l((r) => p(h.current, r), [p]), H = l(
|
|
316
|
+
(r) => p({ ...d.current, lastReset: f }, r),
|
|
317
|
+
[f]
|
|
318
|
+
), K = l(({ name: r, compute: e } = {}) => !r && !e || r === "values" ? j() : typeof e == "function" ? e(j()) : Array.isArray(r) ? r.reduce((c, i) => ({ ...c, [i]: K({ name: i }) }), {}) : R(
|
|
598
319
|
{
|
|
599
|
-
...
|
|
600
|
-
errors:
|
|
601
|
-
fieldStates:
|
|
320
|
+
...E.current,
|
|
321
|
+
errors: n.current,
|
|
322
|
+
fieldStates: h.current,
|
|
602
323
|
formState: H()
|
|
603
324
|
},
|
|
604
325
|
r
|
|
605
|
-
), []),
|
|
606
|
-
typeof
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
}, []),
|
|
610
|
-
typeof
|
|
611
|
-
}, []),
|
|
612
|
-
|
|
613
|
-
}, []),
|
|
614
|
-
|
|
615
|
-
}, []),
|
|
326
|
+
), []), v = Pr({ getWatchValue: K }), { watch: Y, registerHookWatcher: ar, subscribe: lr } = Nr({ getWatchValue: K, channels: v }), fr = l((r, e) => {
|
|
327
|
+
typeof e == "function" && (e = e(H(r)));
|
|
328
|
+
const c = d.current, i = R(c, r);
|
|
329
|
+
i !== e && (d.current = M(d.current, r, e), v.publish(`formState.${r}`, e, i));
|
|
330
|
+
}, []), Z = l((r, e) => {
|
|
331
|
+
typeof e == "function" && (e = e(W(r))), P(r, "error", e);
|
|
332
|
+
}, []), L = l((r) => {
|
|
333
|
+
P(r, "error", null);
|
|
334
|
+
}, []), dr = l(() => {
|
|
335
|
+
d.current.isError && Object.keys(n.current).forEach((r) => L(r));
|
|
336
|
+
}, []), P = l((r, e, c) => {
|
|
616
337
|
try {
|
|
617
|
-
if (typeof
|
|
618
|
-
if (typeof
|
|
619
|
-
Object.keys(
|
|
620
|
-
|
|
338
|
+
if (typeof c == "function" && (c = c(G(r))), y.current.has(r))
|
|
339
|
+
if (typeof c == "object" && c !== null) {
|
|
340
|
+
Object.keys(c).forEach((w) => {
|
|
341
|
+
P(`${r}.${w}`, e, c[w]);
|
|
621
342
|
});
|
|
622
343
|
return;
|
|
623
344
|
} else
|
|
624
345
|
return console.error(
|
|
625
346
|
`Cannot set primitive value for nested parent field "${r}". Please set value for its children or provide an object.`
|
|
626
347
|
);
|
|
627
|
-
const
|
|
628
|
-
if (
|
|
629
|
-
if (
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
const
|
|
635
|
-
if (
|
|
636
|
-
const
|
|
637
|
-
|
|
348
|
+
const i = R(h.current, r) || { ...X }, D = R(i, e);
|
|
349
|
+
if (D !== c) {
|
|
350
|
+
if (h.current = M(h.current, `${r}.${e}`, c), v.publish(`fieldStates.${r}.${e}`, c, D), e === "error") {
|
|
351
|
+
const w = R(n.current, r), O = c || null;
|
|
352
|
+
w !== O && (n.current = M(n.current, r, O), v.publish(`errors.${r}`, O, w));
|
|
353
|
+
const T = ir(y.current, n.current);
|
|
354
|
+
d.current.errorFields = T, v.publish("formState.errorFields", T);
|
|
355
|
+
const _ = T.length > 0;
|
|
356
|
+
if (d.current.isError !== _) {
|
|
357
|
+
const J = d.current.isError;
|
|
358
|
+
d.current.isError = _, v.publish("formState.isError", _, J);
|
|
638
359
|
}
|
|
639
360
|
}
|
|
640
|
-
if (
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
const
|
|
644
|
-
if (
|
|
645
|
-
const
|
|
646
|
-
|
|
361
|
+
if (e === "isDirty") {
|
|
362
|
+
const w = cr(y.current, h.current);
|
|
363
|
+
d.current.dirtyFields = w, v.publish("formState.dirtyFields", w);
|
|
364
|
+
const O = w.length > 0;
|
|
365
|
+
if (d.current.isDirty !== O) {
|
|
366
|
+
const T = d.current.isDirty;
|
|
367
|
+
d.current.isDirty = O, v.publish("formState.isDirty", O, T);
|
|
647
368
|
}
|
|
648
369
|
}
|
|
649
|
-
if (
|
|
650
|
-
const
|
|
651
|
-
|
|
370
|
+
if (e === "isTouched") {
|
|
371
|
+
const w = ur(y.current, h.current);
|
|
372
|
+
d.current.touchedFields = w, v.publish("formState.touchedFields", w);
|
|
652
373
|
}
|
|
653
374
|
}
|
|
654
|
-
} catch (
|
|
655
|
-
console.log(
|
|
375
|
+
} catch (i) {
|
|
376
|
+
console.log(i);
|
|
656
377
|
}
|
|
657
|
-
}, []),
|
|
658
|
-
|
|
659
|
-
}, []),
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
}, []),
|
|
663
|
-
if (typeof
|
|
664
|
-
typeof
|
|
665
|
-
|
|
378
|
+
}, []), gr = l((r) => {
|
|
379
|
+
P(r, "isDirty", !1), P(r, "isTouched", !1), P(r, "error", null);
|
|
380
|
+
}, []), hr = l((r) => {
|
|
381
|
+
const e = sr(r.target);
|
|
382
|
+
e ? Z(r.target.name, e) : L(r.target.name);
|
|
383
|
+
}, []), z = l((r, e, { shouldDirty: c = !0, shouldOnChange: i = !0 } = {}) => {
|
|
384
|
+
if (typeof e == "function" && (e = e(j(r))), y.current.has(r)) {
|
|
385
|
+
typeof e == "object" && e !== null ? Object.keys(e).forEach((O) => {
|
|
386
|
+
z(`${r}.${O}`, e[O], { shouldDirty: c, shouldOnChange: i });
|
|
666
387
|
}) : console.error(
|
|
667
388
|
`Cannot set primitive value for nested parent field "${r}". Please set value for its children or provide an object.`
|
|
668
389
|
);
|
|
669
390
|
return;
|
|
670
391
|
}
|
|
671
|
-
const
|
|
672
|
-
if (
|
|
673
|
-
if (
|
|
674
|
-
const
|
|
675
|
-
(
|
|
392
|
+
const D = R(E.current, r);
|
|
393
|
+
if (e === D) return;
|
|
394
|
+
if (E.current = M(E.current, r, e), v.publish(`values.${r}`, e, D), r.includes(".")) {
|
|
395
|
+
const O = r.split("."), T = O.findIndex(
|
|
396
|
+
(_, J) => !y.current.has(O.slice(0, J + 1).join("."))
|
|
676
397
|
);
|
|
677
|
-
|
|
398
|
+
T !== -1 && (r = O.slice(0, T + 1).join("."));
|
|
678
399
|
}
|
|
679
|
-
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
}, []),
|
|
683
|
-
const
|
|
684
|
-
let
|
|
685
|
-
|
|
686
|
-
|
|
400
|
+
e && P(r, "isTouched", !0);
|
|
401
|
+
const w = e !== (R(g.current, r) || "");
|
|
402
|
+
c && P(r, "isDirty", w), i && v.publish("onChange", r, e, D);
|
|
403
|
+
}, []), V = l((r) => {
|
|
404
|
+
const e = r.split(".");
|
|
405
|
+
let c = "";
|
|
406
|
+
e.forEach((i, D) => {
|
|
407
|
+
D < e.length - 1 && (c = c ? `${c}.${i}` : i, y.current.add(c));
|
|
687
408
|
});
|
|
688
|
-
}, []),
|
|
689
|
-
Array.isArray(r) ? r.forEach((
|
|
690
|
-
}, []),
|
|
691
|
-
(r = "", { shouldUnRegister:
|
|
692
|
-
|
|
409
|
+
}, []), br = l((r) => {
|
|
410
|
+
Array.isArray(r) ? r.forEach((e) => V(e + ".")) : V(r + ".");
|
|
411
|
+
}, []), Er = l(
|
|
412
|
+
(r = "", { shouldUnRegister: e = t } = {}) => r ? (u.current.add(r), h.current = M(h.current, r, { ...X }), r.includes(".") && V(r), () => {
|
|
413
|
+
e && (z(r, void 0, { shouldDirty: !1, shouldOnChange: !1 }), u.current.delete(r));
|
|
693
414
|
}) : console.error("Controller must have a name"),
|
|
694
415
|
[]
|
|
695
|
-
),
|
|
696
|
-
if (!
|
|
416
|
+
), yr = l((r, { keepError: e, keepDirty: c, keepTouched: i, defaultValue: D } = {}) => {
|
|
417
|
+
if (!u.current.has(r))
|
|
697
418
|
throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);
|
|
698
|
-
|
|
699
|
-
}, []),
|
|
419
|
+
D === void 0 && (D = R(g.current, r)), g.current = M(g.current, r, D), E.current = M(E.current, r, D), v.publish(`values.${r}`, D), e || L(r), c || P(r, "isDirty", !1), i || P(r, "isTouched", !1);
|
|
420
|
+
}, []), Fr = l((r, { bubble: e, trickle: c } = {}) => {
|
|
700
421
|
if (!r) {
|
|
701
|
-
|
|
422
|
+
v.trigger("values", { bubble: e, trickle: c ?? !0 }), v.trigger("blur.values", { bubble: e, trickle: c ?? !0 });
|
|
702
423
|
return;
|
|
703
424
|
}
|
|
704
425
|
if (!Array.isArray(r)) {
|
|
705
|
-
const
|
|
706
|
-
|
|
426
|
+
const i = I(r);
|
|
427
|
+
v.trigger(i, { bubble: e, trickle: c }), v.trigger(`blur.${i}`, { bubble: e, trickle: c });
|
|
707
428
|
return;
|
|
708
429
|
}
|
|
709
|
-
r.forEach((
|
|
710
|
-
const
|
|
711
|
-
|
|
430
|
+
r.forEach((i) => {
|
|
431
|
+
const D = I(i);
|
|
432
|
+
v.trigger(D, { bubble: e, trickle: c }), v.trigger(`blur.${D}`, { bubble: e, trickle: c });
|
|
712
433
|
});
|
|
713
|
-
}, []),
|
|
714
|
-
|
|
715
|
-
const
|
|
716
|
-
Object.keys(
|
|
717
|
-
|
|
434
|
+
}, []), x = l((r) => {
|
|
435
|
+
v.publish(`blur.values.${r}`, j(r)), v.publish(`blur.errors.${r}`, W(r));
|
|
436
|
+
const e = G(r);
|
|
437
|
+
Object.keys(e || {}).forEach((i) => {
|
|
438
|
+
v.publish(`blur.fieldStates.${r}.${i}`, e[i]);
|
|
718
439
|
});
|
|
719
|
-
const
|
|
720
|
-
Object.keys(
|
|
721
|
-
|
|
440
|
+
const c = H();
|
|
441
|
+
Object.keys(c || {}).forEach((i) => {
|
|
442
|
+
v.publish(`blur.formState.${i}`, c[i]);
|
|
722
443
|
});
|
|
723
|
-
}, []),
|
|
724
|
-
|
|
725
|
-
}, []),
|
|
444
|
+
}, []), Sr = l((r, e = j(r)) => {
|
|
445
|
+
v.publish("onBlur", r, e, j()), x(r);
|
|
446
|
+
}, []), k = Q(
|
|
726
447
|
() => ({
|
|
727
|
-
subscribe:
|
|
728
|
-
reset:
|
|
729
|
-
trigger:
|
|
730
|
-
reload:
|
|
731
|
-
resetField:
|
|
732
|
-
setValue:
|
|
733
|
-
getValues:
|
|
734
|
-
getErrors:
|
|
735
|
-
getFieldStates:
|
|
448
|
+
subscribe: lr,
|
|
449
|
+
reset: $,
|
|
450
|
+
trigger: Fr,
|
|
451
|
+
reload: a,
|
|
452
|
+
resetField: yr,
|
|
453
|
+
setValue: z,
|
|
454
|
+
getValues: j,
|
|
455
|
+
getErrors: W,
|
|
456
|
+
getFieldStates: G,
|
|
736
457
|
getFormState: H,
|
|
737
|
-
setError:
|
|
738
|
-
clearError:
|
|
739
|
-
clearErrors:
|
|
740
|
-
checkValidity:
|
|
741
|
-
getFieldValidity:
|
|
742
|
-
getDefaultValues:
|
|
743
|
-
setFieldState:
|
|
744
|
-
triggerFieldBlur:
|
|
745
|
-
resetFieldState:
|
|
746
|
-
getControlledFields:
|
|
458
|
+
setError: Z,
|
|
459
|
+
clearError: L,
|
|
460
|
+
clearErrors: dr,
|
|
461
|
+
checkValidity: hr,
|
|
462
|
+
getFieldValidity: B,
|
|
463
|
+
getDefaultValues: S,
|
|
464
|
+
setFieldState: P,
|
|
465
|
+
triggerFieldBlur: Sr,
|
|
466
|
+
resetFieldState: gr,
|
|
467
|
+
getControlledFields: C,
|
|
747
468
|
setFormState: fr,
|
|
748
|
-
getEvents:
|
|
749
|
-
getWatchEvents:
|
|
750
|
-
addGroups:
|
|
469
|
+
getEvents: v.getEvents,
|
|
470
|
+
getWatchEvents: v.getWatchEvents,
|
|
471
|
+
addGroups: br
|
|
751
472
|
}),
|
|
752
|
-
[
|
|
753
|
-
),
|
|
754
|
-
[...
|
|
755
|
-
const
|
|
756
|
-
|
|
473
|
+
[f]
|
|
474
|
+
), rr = l(() => {
|
|
475
|
+
[...b.current.querySelectorAll("[name]")].forEach((c) => {
|
|
476
|
+
const i = c.name || "";
|
|
477
|
+
i.includes(".") && V(i), !c.defaultValue && !u.current.has(i) && R(g.current, i) && (c.defaultValue = R(g.current, i));
|
|
757
478
|
});
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
}, []),
|
|
479
|
+
const e = m();
|
|
480
|
+
E.current = { ...e }, g.current = { ...e };
|
|
481
|
+
}, []), vr = Q(
|
|
761
482
|
() => ({
|
|
762
|
-
ref:
|
|
763
|
-
watch:
|
|
764
|
-
actions:
|
|
765
|
-
initForm:
|
|
766
|
-
registerController:
|
|
767
|
-
registerHookWatcher:
|
|
768
|
-
lastReloadedAt:
|
|
769
|
-
loadFormValues:
|
|
770
|
-
getWatchValue:
|
|
771
|
-
triggerBlurWatchers:
|
|
772
|
-
channels:
|
|
483
|
+
ref: b,
|
|
484
|
+
watch: Y,
|
|
485
|
+
actions: k,
|
|
486
|
+
initForm: rr,
|
|
487
|
+
registerController: Er,
|
|
488
|
+
registerHookWatcher: ar,
|
|
489
|
+
lastReloadedAt: f,
|
|
490
|
+
loadFormValues: m,
|
|
491
|
+
getWatchValue: K,
|
|
492
|
+
triggerBlurWatchers: x,
|
|
493
|
+
channels: v
|
|
773
494
|
}),
|
|
774
|
-
[
|
|
775
|
-
),
|
|
776
|
-
return
|
|
777
|
-
|
|
778
|
-
}, [
|
|
779
|
-
|
|
780
|
-
}, []),
|
|
495
|
+
[f]
|
|
496
|
+
), mr = Q(() => ({ control: vr, actions: k, watch: Y }), [f]);
|
|
497
|
+
return pr(() => {
|
|
498
|
+
b.current && rr();
|
|
499
|
+
}, [f]), q(() => {
|
|
500
|
+
h.current = A(!1);
|
|
501
|
+
}, []), mr;
|
|
781
502
|
};
|
|
782
503
|
export {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
504
|
+
Gr as Controller,
|
|
505
|
+
Ir as Form,
|
|
506
|
+
Rr as restoreFromDotNotation,
|
|
507
|
+
wr as useController,
|
|
508
|
+
Hr as useForm,
|
|
509
|
+
or as useFormContext,
|
|
510
|
+
jr as useWatch
|
|
790
511
|
};
|