react-simple-formkit 2.4.0 → 2.4.1

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