react-simple-formkit 2.4.1 → 2.4.3

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 Ar, { createContext as Or, useContext as wr, useCallback as g, useEffect as dr, useState as Q, useRef as $, useMemo as lr, useLayoutEffect as br } from "react";
2
- var ur = { exports: {} }, X = {};
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 gr;
13
- function jr() {
14
- if (gr) return X;
15
- gr = 1;
16
- var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
17
- function s(i, c, l) {
18
- var u = null;
19
- if (l !== void 0 && (u = "" + l), c.key !== void 0 && (u = "" + c.key), "key" in c) {
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 d in c)
22
- d !== "key" && (l[d] = c[d]);
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: o,
26
- type: i,
27
- key: u,
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 X.Fragment = t, X.jsx = s, X.jsxs = s, X;
32
+ return K.Fragment = t, K.jsx = u, K.jsxs = u, K;
33
33
  }
34
- var Z = {};
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 Er;
45
- function Cr() {
46
- return Er || (Er = 1, process.env.NODE_ENV !== "production" && function() {
47
- function o(e) {
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 === ar ? null : e.displayName || e.name || null;
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 R:
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 cr:
59
+ case ir:
60
60
  return "Suspense";
61
- case K:
61
+ case lr:
62
62
  return "SuspenseList";
63
- case rr:
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 M:
72
+ case x:
73
73
  return (e.displayName || "Context") + ".Provider";
74
- case D:
74
+ case Y:
75
75
  return (e._context.displayName || "Context") + ".Consumer";
76
- case q:
77
- var E = e.render;
78
- return e = e.displayName, e || (e = E.displayName || E.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case U:
80
- return E = e.displayName || null, E !== null ? E : o(e.type) || "Memo";
81
- case T:
82
- E = e._payload, e = e._init;
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 o(e(E));
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 s(e) {
93
+ function u(e) {
94
94
  try {
95
95
  t(e);
96
- var E = !1;
96
+ var f = !1;
97
97
  } catch {
98
- E = !0;
98
+ f = !0;
99
99
  }
100
- if (E) {
101
- E = console;
102
- var y = E.error, O = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
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
- E,
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
- O
106
+ j
107
107
  ), t(e);
108
108
  }
109
109
  }
110
- function i(e) {
111
- if (e === R) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === T)
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 E = o(e);
116
- return E ? "<" + E + ">" : "<...>";
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 = z.A;
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 u(e) {
129
- if (er.call(e, "key")) {
130
- var E = Object.getOwnPropertyDescriptor(e, "key").get;
131
- if (E && E.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
133
  return e.key !== void 0;
134
134
  }
135
- function d(e, E) {
135
+ function m(e, f) {
136
136
  function y() {
137
- nr || (nr = !0, console.error(
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
- E
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 f() {
148
- var e = o(this.type);
149
- return x[e] || (x[e] = !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
151
  )), e = this.props.ref, e !== void 0 ? e : null;
152
152
  }
153
- function m(e, E, y, O, I, k, J, H) {
153
+ function b(e, f, y, j, M, k, Z, U) {
154
154
  return y = k.ref, e = {
155
- $$typeof: j,
155
+ $$typeof: O,
156
156
  type: e,
157
- key: E,
157
+ key: f,
158
158
  props: k,
159
- _owner: I
159
+ _owner: M
160
160
  }, (y !== void 0 ? y : null) !== null ? Object.defineProperty(e, "ref", {
161
161
  enumerable: !1,
162
- get: f
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: J
177
+ value: Z
178
178
  }), Object.defineProperty(e, "_debugTask", {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: H
182
+ value: U
183
183
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
184
  }
185
- function a(e, E, y, O, I, k, J, H) {
186
- var w = E.children;
185
+ function i(e, f, y, j, M, k, Z, U) {
186
+ var w = f.children;
187
187
  if (w !== void 0)
188
- if (O)
189
- if (tr(w)) {
190
- for (O = 0; O < w.length; O++)
191
- v(w[O]);
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 v(w);
198
- if (er.call(E, "key")) {
199
- w = o(e);
200
- var r = Object.keys(E).filter(function(b) {
201
- return b !== "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
- O = 0 < r.length ? "{key: someKey, " + r.join(": ..., ") + ": ...}" : "{key: someKey}", G[w + O] || (r = 0 < r.length ? "{" + r.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
- O,
210
+ j,
211
211
  w,
212
- r,
212
+ q,
213
213
  w
214
- ), G[w + O] = !0);
214
+ ), cr[w + j] = !0);
215
215
  }
216
- if (w = null, y !== void 0 && (s(y), w = "" + y), u(E) && (s(E.key), w = "" + E.key), "key" in E) {
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 n in E)
219
- n !== "key" && (y[n] = E[n]);
220
- } else y = E;
221
- return w && d(
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
- ), m(
224
+ ), b(
225
225
  e,
226
226
  w,
227
227
  k,
228
- I,
228
+ M,
229
229
  c(),
230
230
  y,
231
- J,
232
- H
231
+ Z,
232
+ U
233
233
  );
234
234
  }
235
- function v(e) {
236
- typeof e == "object" && e !== null && e.$$typeof === j && e._store && (e._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 p = Ar, j = Symbol.for("react.transitional.element"), S = Symbol.for("react.portal"), R = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), C = Symbol.for("react.profiler"), D = Symbol.for("react.consumer"), M = Symbol.for("react.context"), q = Symbol.for("react.forward_ref"), cr = Symbol.for("react.suspense"), K = Symbol.for("react.suspense_list"), U = Symbol.for("react.memo"), T = Symbol.for("react.lazy"), rr = Symbol.for("react.activity"), ar = Symbol.for("react.client.reference"), z = p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, er = Object.prototype.hasOwnProperty, tr = Array.isArray, V = 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
- p = {
241
+ R = {
242
242
  "react-stack-bottom-frame": function(e) {
243
243
  return e();
244
244
  }
245
245
  };
246
- var nr, x = {}, sr = p["react-stack-bottom-frame"].bind(
247
- p,
246
+ var J, or = {}, D = R["react-stack-bottom-frame"].bind(
247
+ R,
248
248
  l
249
- )(), or = V(i(l)), G = {};
250
- Z.Fragment = R, Z.jsx = function(e, E, y, O, I) {
251
- var k = 1e4 > z.recentlyCreatedOwnerStacks++;
252
- return a(
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
- E,
254
+ f,
255
255
  y,
256
256
  !1,
257
- O,
258
- I,
259
- k ? Error("react-stack-top-frame") : sr,
260
- k ? V(i(e)) : or
257
+ j,
258
+ M,
259
+ k ? Error("react-stack-top-frame") : D,
260
+ k ? z(a(e)) : ur
261
261
  );
262
- }, Z.jsxs = function(e, E, y, O, I) {
263
- var k = 1e4 > z.recentlyCreatedOwnerStacks++;
264
- return a(
262
+ }, rr.jsxs = function(e, f, y, j, M) {
263
+ var k = 1e4 > X.recentlyCreatedOwnerStacks++;
264
+ return i(
265
265
  e,
266
- E,
266
+ f,
267
267
  y,
268
268
  !0,
269
- O,
270
- I,
271
- k ? Error("react-stack-top-frame") : sr,
272
- k ? V(i(e)) : or
269
+ j,
270
+ M,
271
+ k ? Error("react-stack-top-frame") : D,
272
+ k ? z(a(e)) : ur
273
273
  );
274
274
  };
275
- }()), Z;
275
+ }()), rr;
276
276
  }
277
- var hr;
278
- function Pr() {
279
- return hr || (hr = 1, process.env.NODE_ENV === "production" ? ur.exports = jr() : ur.exports = Cr()), ur.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 mr = Pr();
281
+ var pr = xr();
282
282
  const F = () => {
283
- }, Sr = Or({
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
- }), pr = () => wr(Sr), Lr = ({
312
- id: o,
311
+ }), Ar = () => Pr(Fr), qr = ({
312
+ id: n,
313
313
  control: t,
314
- method: s,
315
- action: i,
314
+ method: u,
315
+ action: a,
316
316
  children: c,
317
317
  onChange: l,
318
- onBlur: u,
319
- onSubmit: d = () => {
318
+ onBlur: o,
319
+ onSubmit: m = () => {
320
320
  },
321
- onInput: f = () => {
321
+ onInput: E = () => {
322
322
  },
323
- onReset: m = () => {
323
+ onReset: b = () => {
324
324
  },
325
- numberFields: a = [],
326
- className: v,
327
- ...p
325
+ numberFields: i = [],
326
+ className: g,
327
+ ...R
328
328
  }) => {
329
- const j = g(
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 dr(() => {
335
+ return Er(() => {
336
336
  let S = () => {
337
- }, R = () => {
337
+ }, p = () => {
338
338
  };
339
- return l && (S = t.channels.subscribe("onChange", l)), u && (R = t.channels.subscribe("onBlur", u)), () => {
340
- S(), R();
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__ */ mr.jsx(Sr.Provider, { value: t, children: /* @__PURE__ */ mr.jsx(
342
+ }, [t.lastReloadedAt]), /* @__PURE__ */ pr.jsx(Fr.Provider, { value: t, children: /* @__PURE__ */ pr.jsx(
343
343
  "form",
344
344
  {
345
- id: o,
346
- ref: j,
347
- action: i,
348
- method: s,
349
- className: v,
350
- onInput: f,
345
+ id: n,
346
+ ref: O,
347
+ action: a,
348
+ method: u,
349
+ className: g,
350
+ onInput: E,
351
351
  onSubmit: (S) => {
352
- s || S.preventDefault();
353
- const R = t.loadFormValues();
354
- d(R);
352
+ u || S.preventDefault();
353
+ const p = t.loadFormValues();
354
+ m(p);
355
355
  },
356
356
  onChange: (S) => {
357
- const R = S.target.name;
358
- !R || t.actions.getControlledFields().has(R) || t.actions.setValue(R, S.target.value);
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 R = S.target.name;
362
- if (!R || t.actions.getControlledFields().has(R)) return;
363
- const _ = S.target.value;
364
- t.channels.publish("onBlur", R, _, t.actions.getValues());
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(), m(S);
367
+ t.actions.reset(), b(S);
368
368
  },
369
- ...p,
369
+ ...R,
370
370
  children: c
371
371
  },
372
372
  t.lastReloadedAt
373
373
  ) });
374
- }, fr = { isDirty: !1, isTouched: !1, error: null }, vr = {
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
- }, Nr = {}, Dr = [
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 = (o = {}, t = "") => t.split(".").reduce((s, i) => s && s[i] !== void 0 ? s[i] : void 0, o), W = (o = {}, t = "", s) => {
393
- const i = { ...o };
394
- let c = i;
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((u, d) => {
397
- d < l.length - 1 ? (c[u] || (c[u] = {}), Array.isArray(c[u]) ? c[u] = [...c[u]] : c[u] = { ...c[u] }, c = c[u]) : c[u] = s;
398
- }), i;
399
- }, kr = (o) => {
400
- let t = { ...o };
401
- return Object.keys(t).forEach((s) => {
402
- if (s.includes(".")) {
403
- const i = N(t, s);
404
- t = W(t, s, i || ""), delete t[s];
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
- }, xr = ["errors", "fieldStates", "formState"], B = (o) => xr.some((t) => o.startsWith(t)) ? o : "values." + o, Rr = (o) => {
408
- typeof o.setCustomValidity == "function" && o.setCustomValidity("");
409
- let t = o.validity, s = Dr.find((i) => t[i]);
410
- if (s) return { type: s, message: o.validationMessage };
411
- }, yr = (o = /* @__PURE__ */ new Set(), t = {}, s = "") => Object.keys(t).reduce((i, c) => {
412
- const l = t[c];
413
- return o.has(s + c) ? [...i, ...yr(o, l, s + c + ".")] : l.isDirty ? [...i, s + c] : i;
414
- }, []), Fr = (o = /* @__PURE__ */ new Set(), t = {}, s = "") => Object.keys(t).reduce((i, c) => {
415
- const l = t[c];
416
- return o.has(s + c) ? [...i, ...Fr(o, l, s + c + ".")] : l.isTouched ? [...i, s + c] : i;
417
- }, []), Tr = (o = /* @__PURE__ */ new Set(), t = {}, s = "") => Object.keys(t).reduce((i, c) => {
418
- const l = t[c];
419
- return o.has(s + c) ? [...i, ...Tr(o, l, s + c + ".")] : l ? [...i, s + c] : i;
420
- }, []), Br = ({ control: o, name: t, compute: s }) => {
421
- const { getWatchValue: i, registerHookWatcher: c } = o || pr(), l = i({ name: t, compute: s }), [u, d] = Q(l);
422
- return dr(() => c({ name: t, compute: s, value: u, setValue: d }), []), u;
423
- }, $r = ({ control: o, name: t, defaultValue: s }) => {
424
- const { actions: i, registerController: c, channels: l, getWatchValue: u } = o || pr(), d = $(), f = $(), m = N(i.getDefaultValues(), t) || s || "", [a, v] = Q(m), [p, j] = Q({}), S = g(
425
- (_, { shouldDirty: C = !0, shouldOnChange: D = !0 } = {}) => {
426
- var q;
427
- let M = _;
428
- ((q = _ == null ? void 0 : _.target) == null ? void 0 : q.value) !== void 0 && (M = _.target.value), v(M), i.setValue(t, M, { shouldDirty: C, shouldOnChange: D });
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
- [i.setValue]
431
- ), R = g((_) => {
432
- const C = i.getValues(), D = _ ?? N(C, t);
433
- l.publish("onBlur", t, D, C);
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 dr(() => {
436
- const _ = c(t, v);
435
+ return Er(() => {
436
+ const A = c(t, g);
437
437
  return () => {
438
- _(), f.current && f.current();
438
+ A(), E.current && E.current();
439
439
  };
440
440
  }, []), new Proxy(
441
- { ref: d, name: t, defaultValue: m, value: a, onChange: S, onBlur: R, fieldState: p },
441
+ { ref: m, name: t, defaultValue: b, value: i, onChange: S, onBlur: p, fieldState: R },
442
442
  {
443
- get(_, C, D) {
444
- return typeof C == "string" && C === "fieldState" && (f.current && f.current(), f.current = i.subscribe(`fieldStates.${t}`, () => {
445
- j(u({ name: `fieldStates.${t}` }));
446
- })), Reflect.get(_, C, D);
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
- }, Ur = ({
451
- name: o,
450
+ }, Jr = ({
451
+ name: n,
452
452
  control: t,
453
- defaultValue: s,
454
- render: i = ({ ref: c, name: l, defaultValue: u, value: d, onChange: f, onBlur: m, fieldState: a }) => null
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 = $r({ name: o, defaultValue: s, control: t });
457
- return i(c);
458
- }, Wr = () => {
459
- const [o, t] = Q(), s = g(() => t((/* @__PURE__ */ new Date()).toString()), []);
460
- return [o, s];
461
- }, Mr = () => {
462
- const [, o] = Q({});
463
- return g(() => o({}), []);
464
- }, Ir = ({ channels: o, getWatchValue: t }) => {
465
- const s = Mr(), i = g((u) => {
466
- if (!u)
467
- return o.subscribeWatch("values", () => s()), t();
468
- if (typeof u == "string") {
469
- const d = B(u);
470
- o.subscribeWatch(d, (f, m) => {
471
- f !== m && s();
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(u) && u.forEach((d) => {
475
- const f = B(d);
476
- o.subscribeWatch(f, (m, a) => {
477
- m !== a && s();
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: u });
480
- }, []), c = g(({ name: u, compute: d, setValue: f }) => {
481
- if (typeof d == "function")
482
- return o.subscribe("values", () => {
483
- const a = t({ compute: d });
484
- f(a);
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 (!u)
487
- return o.subscribe("values", () => {
488
- f(t());
486
+ if (!o)
487
+ return n.subscribe("values", () => {
488
+ E(t());
489
489
  });
490
- if (typeof u == "string") {
491
- const m = B(u);
492
- return o.subscribe(m, () => {
493
- const v = t({ name: u });
494
- f(v);
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(u)) {
498
- const m = [];
499
- return u.forEach((a) => {
500
- const v = B(a), p = o.subscribe(v, () => {
501
- const j = t({ name: u });
502
- f(j);
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
- m.push(p);
505
- }), () => m.forEach((a) => a());
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 = g((u, d) => {
509
- if (!u)
510
- return o.subscribe("values", () => d(t()));
511
- if (["onChange", "onBlur"].includes(u))
512
- return o.subscribe(u, d);
513
- if (typeof u == "string") {
514
- const f = B(u);
515
- return o.subscribe(f, () => d(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 })));
516
516
  }
517
- if (Array.isArray(u)) {
518
- const f = [];
519
- return u.forEach((m) => {
520
- const a = B(m), v = o.subscribe(a, () => {
521
- d(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 }));
522
522
  });
523
- f.push(v);
524
- }), () => f.forEach((m) => m());
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: i, registerHookWatcher: c, getWatchValue: t, subscribe: l };
529
- }, Yr = ({ getWatchValue: o }) => {
530
- const t = $(/* @__PURE__ */ new Map()), s = $(/* @__PURE__ */ new Map()), i = g(() => s.current, []), c = g(() => t.current, []), l = g(() => {
531
- t.current.clear(), s.current.clear();
532
- }, []), u = g((a, ...v) => {
533
- const p = t.current.get(a), j = s.current.get(a);
534
- p && p.forEach((S) => S(...v)), j && j.forEach((S) => S(...v)), t.current.forEach((S, R) => {
535
- if (R !== a && a.startsWith(R)) {
536
- const _ = o({ name: R.replace("values.", "").replace("values", "") });
537
- S.forEach((C) => C(W(_, a.replace(`${R}.`, ""), v[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])));
538
538
  }
539
- }), s.current.forEach((S, R) => {
540
- if (R !== a && a.startsWith(R)) {
541
- const _ = o({ name: R.replace("values.", "").replace("values", "") });
542
- S.forEach((C) => C(W(_, a.replace(`${R}.`, ""), v[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])));
543
543
  }
544
544
  });
545
- }, []), d = g((a) => {
546
- t.current.forEach((v, p) => {
547
- p.startsWith(a) && v.forEach((j) => j(o({ name: p.replace("values.", "").replace("values", "") })));
548
- }), s.current.forEach((v, p) => {
549
- p.startsWith(a) && v.forEach((j) => j(o({ name: p.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", "") })));
550
550
  });
551
- }, []), f = g((a, v) => (t.current.has(a) || t.current.set(a, /* @__PURE__ */ new Set()), t.current.get(a).add(v), () => {
552
- var p;
553
- return (p = t.current.get(a)) == null ? void 0 : p.delete(v);
554
- }), []), m = g((a, v) => {
555
- s.current.has(a) || (s.current.set(a, /* @__PURE__ */ new Set()), s.current.get(a).add(v));
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: u, subscribe: f, subscribeWatch: m, getEvents: c, getWatchEvents: i, trigger: d };
558
- }, qr = ({ defaultValues: o = Nr, shouldUnRegister: t = !1 } = {}) => {
559
- const [s, i] = Wr(), c = $(), l = $(/* @__PURE__ */ new Map()), u = $({}), d = $({}), f = $({ ...vr }), m = $({ ...o }), a = $({ ...o }), v = $(/* @__PURE__ */ new Set()), p = g((r, n = a.current) => Object.keys(n).reduce((b, h) => {
560
- if (typeof n[h] == "object")
561
- return { ...b, [h]: p(r, n[h]) };
562
- const P = { ...r ? {} : d.current[h] || {}, ...fr };
563
- return { ...b, [h]: P };
564
- }, {}), []), j = g(
565
- (r = {}, { clearCustomFormStates: n = !1, clearCustomFieldStates: b = !1 } = {}) => {
566
- a.current = { ...a.current, ...r }, m.current = { ...a.current }, l.current.forEach((h, P) => {
567
- h(N(a.current, P) ?? "");
568
- }), u.current = {}, l.current = /* @__PURE__ */ new Map(), f.current = { ...n ? {} : f.current, ...vr }, d.current = p(b), T.reset(), i();
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
- ), S = g(() => {
572
- let r = Object.fromEntries(new FormData(c.current));
573
- l.current.forEach((b, h) => {
574
- r = W(r, h, N(m.current, h));
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 n = { ...m.current, ...r };
577
- return kr(n);
578
- }, []), R = g((r) => Rr(r.target), []), _ = g(() => a.current, []), C = g(() => l.current, []), D = g((r, n) => n ? Array.isArray(n) ? n.reduce((b, h) => ({ ...b, [h]: N(r, h) }), {}) : N(r, n) : { ...r }, []), M = g((r) => D(m.current, r), [D]), q = g((r) => D(u.current, r), [D]), cr = g((r) => D(d.current, r), [D]), K = g(
579
- (r) => D({ ...f.current, lastReset: s }, r),
580
- [s]
581
- ), U = g(({ name: r, compute: n } = {}) => !r && !n || r === "values" ? M() : typeof n == "function" ? n(M()) : Array.isArray(r) ? r.reduce((b, h) => ({ ...b, [h]: U({ name: h }) }), {}) : N(
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
- ...m.current,
584
- errors: u.current,
585
- fieldStates: d.current,
586
- formState: K()
583
+ ...i.current,
584
+ errors: m.current,
585
+ fieldStates: E.current,
586
+ formState: tr()
587
587
  },
588
588
  r
589
- ), []), T = Yr({ getWatchValue: U }), { watch: rr, registerHookWatcher: ar, subscribe: z } = Ir({ getWatchValue: U, channels: T }), er = g((r, n) => {
590
- const b = f.current, h = N(b, r);
591
- h !== n && (f.current = W(f.current, r, n), T.publish(`formState.${r}`, n, h));
592
- }, []), tr = g((r, n) => {
593
- x(r, "error", n);
594
- }, []), V = g((r) => {
595
- x(r, "error", null);
596
- }, []), nr = g(() => {
597
- f.current.isError && Object.keys(u.current).forEach((r) => V(r));
598
- }, []), x = g((r, n, b) => {
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 b == "function" && (b = b(U({ name: r }))), v.current.has(r))
601
- if (typeof b == "object" && b !== null) {
602
- Object.keys(b).forEach((A) => {
603
- x(`${r}.${A}`, n, b[A]);
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 h = N(d.current, r) || { ...fr }, P = N(h, n);
611
- if (P !== b) {
612
- if (d.current = W(d.current, `${r}.${n}`, b), T.publish(`fieldStates.${r}.${n}`, b, P), n === "error") {
613
- const A = N(u.current, r), Y = b || null;
614
- A !== Y && (u.current = W(u.current, r, Y), T.publish(`errors.${r}`, Y, A));
615
- const L = Tr(v.current, u.current);
616
- f.current.errorFields = L, T.publish("formState.errorFields", L);
617
- const ir = L.length > 0;
618
- if (f.current.isError !== ir) {
619
- const _r = f.current.isError;
620
- f.current.isError = ir, T.publish("formState.isError", ir, _r);
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 (n === "isDirty") {
624
- const A = yr(v.current, d.current);
625
- f.current.dirtyFields = A, T.publish("formState.dirtyFields", A);
626
- const Y = A.length > 0;
627
- if (f.current.isDirty !== Y) {
628
- const L = f.current.isDirty;
629
- f.current.isDirty = Y, T.publish("formState.isDirty", Y, L);
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 (n === "isTouched") {
633
- const A = Fr(v.current, d.current);
634
- f.current.touchedFields = A, T.publish("formState.touchedFields", A);
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 (h) {
638
- console.log(h);
637
+ } catch (v) {
638
+ console.log(v);
639
639
  }
640
- }, []), sr = g((r) => {
641
- x(r, "isDirty", !1), x(r, "isTouched", !1), x(r, "error", !1);
642
- }, []), or = g((r) => {
643
- const n = Rr(r.target);
644
- n ? tr(r.target.name, n) : V(r.target.name);
645
- }, []), G = g((r, n, { shouldDirty: b = !0, shouldOnChange: h = !0 } = {}) => {
646
- if (typeof n == "function" && (n = n(M(r))), v.current.has(r)) {
647
- typeof n == "object" && n !== null ? Object.keys(n).forEach((L) => {
648
- G(`${r}.${L}`, n[L], { shouldDirty: b, shouldOnChange: h });
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(m.current, r);
655
- if (n === P) return;
656
- m.current = W(m.current, r, n), T.publish(`values.${r}`, n, P);
657
- const A = l.current.get(r);
658
- A && A(n), n && x(r, "isTouched", !0);
659
- const Y = n !== (N(a.current, r) || "");
660
- b && x(r, "isDirty", Y), h && T.publish("onChange", r, n, P);
661
- }, []), e = g((r) => {
662
- const n = r.split(".");
663
- let b = "";
664
- n.forEach((h, P) => {
665
- P < n.length - 1 && (b = b ? `${b}.${h}` : h, v.current.add(b));
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
- }, []), E = g((r = "", n) => (l.current.set(r, n), d.current = W(d.current, r, { ...fr }), r.includes(".") && e(r), () => {
668
- t && l.current.delete(r);
669
- }), []), y = g((r, { keepError: n, keepDirty: b, keepTouched: h, defaultValue: P }) => {
670
- const A = l.current.get(r);
671
- if (!A)
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
- a.current = W(a.current, r, P), m.current = W(m.current, r, P), A && A(P), n || V(r), b || x(r, "isDirty", !1), h || x(r, "isTouched", !1);
674
- }, []), O = g((r) => {
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 n = B(r);
678
- T.trigger(n);
685
+ const s = G(r);
686
+ T.trigger(s);
679
687
  return;
680
688
  }
681
- r.forEach((n) => {
682
- const b = B(n);
683
- T.trigger(b);
689
+ r.forEach((s) => {
690
+ const h = G(s);
691
+ T.trigger(h);
684
692
  });
685
- }, []), I = g((r, n = k.getValues(r)) => {
686
- T.publish("onBlur", r, n, k.getValues());
687
- }, []), k = lr(
693
+ }, []), Z = d((r, s = U.getValues(r)) => {
694
+ T.publish("onBlur", r, s, U.getValues());
695
+ }, []), U = dr(
688
696
  () => ({
689
- subscribe: z,
690
- reset: j,
691
- trigger: O,
692
- reload: i,
693
- resetField: y,
694
- setValue: G,
695
- getValues: M,
696
- getErrors: q,
697
- getFieldStates: cr,
698
- getFormState: K,
699
- setError: tr,
700
- clearError: V,
701
- clearErrors: nr,
702
- checkValidity: or,
703
- getFieldValidity: R,
704
- getDefaultValues: _,
705
- setFieldState: x,
706
- triggerFieldBlur: I,
707
- resetFieldState: sr,
708
- getControlledFields: C,
709
- setFormState: er,
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
- [s]
714
- ), J = g(() => {
715
- [...c.current.querySelectorAll("[name]")].forEach((b) => {
716
- const h = b.name || "";
717
- h.includes(".") && e(h), !b.defaultValue && !l.current.has(h) && N(a.current, h) && (b.defaultValue = N(a.current, h));
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 n = S();
720
- m.current = { ...n }, a.current = { ...n };
721
- }, []), H = lr(
728
+ const s = p();
729
+ i.current = { ...s }, g.current = { ...s };
730
+ }, []), q = dr(
722
731
  () => ({
723
- ref: c,
724
- watch: rr,
725
- actions: k,
726
- initForm: J,
727
- registerController: E,
728
- registerHookWatcher: ar,
729
- lastReloadedAt: s,
730
- loadFormValues: S,
731
- getWatchValue: U,
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
- [s]
735
- ), w = lr(() => ({ control: H, actions: k, watch: rr }), [s]);
736
- return br(() => {
737
- c.current && J();
738
- }, [s]), br(() => {
739
- d.current = p(!1);
740
- }, []), w;
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
- Ur as Controller,
744
- Lr as Form,
745
- kr as restoreFromDotNotation,
746
- $r as useController,
747
- qr as useForm,
748
- pr as useFormContext,
749
- Br 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
750
759
  };