react-simple-formkit 2.1.9 → 2.2.1

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