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