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