react-simple-formkit 2.4.4 → 2.4.6

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