react-simple-formkit 2.4.4 → 2.4.5

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