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