react-simple-formkit 2.3.0 → 2.4.0

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