react-simple-formkit 2.2.0 → 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 pe, useContext as ve, useEffect as le, useState as ce, useRef as C, useCallback as f, useMemo as ae, useLayoutEffect as fe } 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 de;
13
- function ye() {
14
- if (de) return re;
15
- de = 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 be;
45
- function Fe() {
46
- return be || (be = 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 Fe() {
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 l:
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 Fe() {
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 Fe() {
99
99
  }
100
100
  if (o) {
101
101
  o = console;
102
- var S = o.error, T = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
102
+ var S = o.error, F = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
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,23 +118,23 @@ function Fe() {
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) {
135
+ function p(e, o) {
136
136
  function S() {
137
- H || (H = !0, console.error(
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
  ));
@@ -144,22 +144,22 @@ function Fe() {
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, S, T, j, A, I, B) {
153
+ function k(e, o, S, F, C, A, I, L) {
154
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
159
+ _owner: C
160
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,216 +179,216 @@ function Fe() {
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, S, T, j, A, I, B) {
186
- var R = o.children;
187
- if (R !== void 0)
188
- if (T)
189
- if (V(R)) {
190
- for (T = 0; T < R.length; T++)
191
- b(R[T]);
192
- Object.freeze && Object.freeze(R);
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(R);
198
- if ($.call(o, "key")) {
199
- R = 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[R + 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
- R,
212
- x,
213
- R
214
- ), Q[R + T] = !0);
212
+ N,
213
+ T
214
+ ), K[T + F] = !0);
215
215
  }
216
- if (R = null, S !== void 0 && (a(S), R = "" + S), E(o) && (a(o.key), R = "" + o.key), "key" in o) {
216
+ if (T = null, S !== void 0 && (i(S), T = "" + S), l(o) && (i(o.key), T = "" + o.key), "key" in o) {
217
217
  S = {};
218
- for (var K in o)
219
- K !== "key" && (S[K] = o[K]);
218
+ for (var x in o)
219
+ x !== "key" && (S[x] = o[x]);
220
220
  } else S = o;
221
- return R && y(
221
+ return T && p(
222
222
  S,
223
223
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
224
224
  ), k(
225
225
  e,
226
- R,
226
+ T,
227
227
  A,
228
- j,
229
- d(),
228
+ C,
229
+ E(),
230
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 i = Re, u = Symbol.for("react.transitional.element"), l = 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 = i.__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
- i = {
241
+ f = {
242
242
  "react-stack-bottom-frame": function(e) {
243
243
  return e();
244
244
  }
245
245
  };
246
- var H, X = {}, Z = i["react-stack-bottom-frame"].bind(
247
- i,
246
+ var X, Z = {}, Q = f["react-stack-bottom-frame"].bind(
247
+ f,
248
248
  h
249
- )(), v = D(g(h)), Q = {};
250
- te.Fragment = m, te.jsx = function(e, o, S, 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
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, S, 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
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 me;
278
- function Te() {
279
- return me || (me = 1, process.env.NODE_ENV === "production" ? ue.exports = ye() : ue.exports = Fe()), 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 Ee = Te();
282
- const p = () => {
283
- }, he = pe({
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
- }), Se = () => ve(he), $e = ({
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,
329
- ...i
330
- }) => (le(() => {
331
- const u = n.channels.subscribe("onChange", y), l = n.channels.subscribe("onBlur", F);
328
+ className: m,
329
+ ...f
330
+ }) => (fe(() => {
331
+ const u = n.channels.subscribe("onChange", p), d = n.channels.subscribe("onBlur", y);
332
332
  return () => {
333
- u(), l();
333
+ u(), d();
334
334
  };
335
- }, []), /* @__PURE__ */ Ee.jsx(he.Provider, { value: n, children: /* @__PURE__ */ Ee.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 l = n.loadFormValues();
347
- h(l);
345
+ i || u.preventDefault();
346
+ const d = n.loadFormValues();
347
+ h(d);
348
348
  },
349
349
  onChange: (u) => {
350
- const l = u.target.name;
351
- n.actions.getControlledFields().has(l) || n.actions.setValue(l, 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 l = u.target.name;
355
- if (n.actions.getControlledFields().has(l)) return;
356
- const m = u.target.value;
357
- n.channels.publish("onBlur", l, 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
- ...i,
363
- children: d
362
+ ...f,
363
+ children: E
364
364
  },
365
365
  n.lastReloadedAt
366
- ) })), _e = ({ control: s, name: n, compute: a }) => {
367
- const { getWatchValue: g, registerHookWatcher: d } = s || Se(), h = g({ name: n, compute: a }), [E, y] = ce(h);
368
- return le(() => {
369
- const F = d({ name: n, compute: a, value: E, setValue: y });
370
- return () => F.forEach((k) => k());
371
- }, []), E;
372
- }, ke = ({ name: s, defaultValue: n }) => {
373
- const { actions: a, registerController: g, channels: d } = Se(), h = C(), E = a.getDefaultValues()[s] || n || "", [y, F] = ce(E), k = _e({ name: `fieldStates.${s}.customState` }), c = f((u) => {
374
- a.setFieldState(s, "customState", u);
375
- }, []), b = f(
376
- (u, { shouldDirty: l = !0, shouldOnChange: m = !0 } = {}) => {
377
- F(u), a.setValue(s, u, { shouldDirty: l, 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
- ), i = f(() => {
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 le(() => g(s, F), []), { ref: h, name: s, defaultValue: E, value: y, onChange: b, onBlur: i, customState: k, setCustomState: c };
384
- }, Me = ({
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 = ke({ name: s, defaultValue: n });
390
- return a(g);
391
- }, we = ["errors", "fieldStates", "formState"], U = (s) => we.some((n) => s.startsWith(n)) ? s : "values." + s, Ae = [
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
- ], ge = (s) => {
402
+ ], he = (s) => {
403
403
  typeof s.setCustomValidity == "function" && s.setCustomValidity("");
404
- let n = s.validity, a = Ae.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 Oe {
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 je = () => {
431
- const s = C(new Oe()), n = f((d, ...h) => {
432
- s.current.publish(d, ...h);
433
- }, []), a = f((d, h) => s.current.subscribe(d, h), []), g = f(() => {
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
- }, Ce = () => {
438
- const [s, n] = ce(), a = f(() => n((/* @__PURE__ */ new Date()).toString()), []);
439
- return [s, a];
440
- }, Pe = () => {
441
- const [, s] = ce({});
442
- return f(() => s({}), []);
443
- }, xe = ({ channels: s, getValues: n, getErrors: a, getFieldStates: g, getFormState: d }) => {
444
- const h = Pe(), E = f(({ 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
- const i = {};
447
+ const f = {};
448
448
  return c.forEach((u) => {
449
- i[u] = E({ name: u });
450
- }), i;
449
+ f[u] = l({ name: u });
450
+ }), f;
451
451
  }
452
452
  return c.split(".").reduce(
453
- (i, u) => i && i[u] !== void 0 ? i[u] : void 0,
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 = f((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 = {};
470
- return c.forEach((i) => {
471
- const u = U(i);
472
- s.subscribe(u, () => h()), b[i] = E({ name: i });
473
- }), { ...b };
469
+ const m = {};
470
+ return c.forEach((f) => {
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 = f(({ name: c, compute: b, value: i, 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 l = U(c);
488
- return [s.subscribe(l, () => {
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 l = 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
- l[O] = q, u({ ...l });
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 = f(
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 i = U(c);
510
- return s.subscribe(i, b);
509
+ const f = q(c);
510
+ return s.subscribe(f, m);
511
511
  }
512
512
  if (Array.isArray(c)) {
513
- const i = {}, u = [];
514
- return c.forEach((l) => {
515
- const m = U(l), O = s.subscribe(m, () => {
516
- i[l] = E({ name: l }), b({ ...i });
513
+ const f = {}, u = [];
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,186 +522,190 @@ const je = () => {
522
522
  },
523
523
  [s]
524
524
  );
525
- return { watch: y, registerHookWatcher: F, getWatchValue: E, subscribe: k };
526
- }, ie = { isError: !1, isDirty: !1, isTouched: !1, customState: null }, Ne = [], Ve = {}, Ye = ({
527
- numberFields: s = Ne,
528
- defaultValues: n = Ve,
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] = Ce(), E = C(), y = C(!1), F = C(!1), k = C(s), c = C(/* @__PURE__ */ new Map()), b = C({}), i = C({}), u = C(n), l = C(n), m = je(), O = f(() => {
533
- i.current = Object.keys(l.current).reduce((r, t) => ({ ...r, [t]: { ...ie } }), {});
534
- }, []), Y = f((r = {}) => {
535
- l.current = { ...l.current, ...r }, u.current = { ...l.current }, c.current.forEach((t, _) => {
536
- t(l.current[_]);
537
- }), y.current = !1, b.current = {}, k.current = s, c.current = /* @__PURE__ */ new Map(), m.reset(), O(), s.length > 0 && (g = !0), h();
538
- }, []), W = f(() => {
539
- 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));
540
540
  return c.current.forEach((_, w) => {
541
541
  r[w] = u.current[w];
542
542
  }), g && k.current.forEach(
543
543
  (_) => r.hasOwnProperty(_) && (r[_] = Number(r[_]) || 0)
544
544
  ), r;
545
- }, []), q = f(() => !!Object.values($()).find((r) => r.isDirty), []), J = f(() => !!Object.values(N()).find((r) => !!r), []), se = f((r) => ge(r.target), []), ne = f(() => l.current, []), oe = f(() => k.current, []), z = f(() => c.current, []), P = f((r, t) => t ? Array.isArray(t) ? t.map((_) => r[_]) : r[t] : { ...r }, []), G = f((r) => P(u.current, r), [P]), N = f((r) => P(b.current, r), [P]), $ = f((r) => P(i.current, r), [P]), V = f(
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(
546
546
  (r) => P(
547
547
  {
548
- isDirty: y.current,
549
- isError: F.current,
550
- errorFields: Object.keys(b.current).filter((t) => !!b.current[t]),
551
- dirtyFields: Object.keys(i.current).filter((t) => i.current[t].isDirty),
552
- touchedFields: Object.keys(i.current).filter((t) => i.current[t].isTouched)
548
+ isDirty: p.current,
549
+ isError: y.current,
550
+ errorFields: Object.keys(m.current).filter((t) => !!m.current[t]),
551
+ dirtyFields: Object.keys(f.current).filter((t) => f.current[t].isDirty),
552
+ touchedFields: Object.keys(f.current).filter((t) => f.current[t].isTouched)
553
553
  },
554
554
  r
555
555
  ),
556
556
  [P]
557
- ), { watch: D, registerHookWatcher: H, getWatchValue: X, subscribe: Z } = xe({
558
- channels: m,
559
- getValues: G,
560
- getErrors: N,
561
- getFieldStates: $,
562
- getFormState: V
563
- }), v = f((r, t, _) => {
564
- const w = i.current[r] || { ...ie };
565
- w[t] !== _ && (i.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")));
566
- }, []), Q = f(
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(
567
567
  (r) => {
568
568
  v(r, "isError", !1), v(r, "isDirty", !1), v(r, "isTouched", !1), v(r, "customState", null);
569
569
  },
570
570
  [v]
571
- ), e = f(
571
+ ), e = a(
572
572
  (r, t) => {
573
- if (b.current[r] === t) return;
574
- b.current[r] = t, v(r, "isError", !!t), m.publish(`errors.${r}`, t);
575
- const w = J();
576
- 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));
577
577
  },
578
578
  [v]
579
- ), o = f(
579
+ ), o = a(
580
580
  (r) => {
581
- if (!b.current[r]) return;
582
- b.current[r] = null, v(r, "isError", !1), m.publish(`errors.${r}`, null);
583
- const t = J();
584
- 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));
585
585
  },
586
586
  [v]
587
- ), S = f(() => {
588
- if (Object.keys(b.current) === 0) return;
589
- Object.keys(b.current).forEach((t) => o(t)), b.current = {};
590
- const r = J();
591
- F.current !== r && (F.current = r, m.publish("formState.isError", r));
592
- }, []), T = f(
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(
593
593
  (r) => {
594
- const t = ge(r.target);
594
+ const t = he(r.target);
595
595
  t ? e(r.target.name, t) : o(r.target.name);
596
596
  },
597
597
  [e, o]
598
- ), j = f(
598
+ ), C = a(
599
599
  (r, t, { shouldDirty: _ = !0, shouldOnChange: w = !0 } = {}) => {
600
600
  if (t === u.current[r]) return;
601
601
  g && k.current.includes(r) && (t = Number(t) || void 0), v(r, "isTouched", !0);
602
- const ee = t !== l.current[r];
603
- _ && i.current[r].isDirty !== ee && v(r, "isDirty", ee);
604
- const M = q();
605
- y.current !== M && (y.current = M, m.publish("formState.isDirty", M)), u.current[r] = t;
606
- const L = c.current.get(r);
607
- L && L(t), m.publish(`values.${r}`, t, { shouldDirty: _, shouldOnChange: w }), w && m.publish("onChange", r, t, u.current);
602
+ const ee = t !== d.current[r];
603
+ _ && f.current[r].isDirty !== ee && v(r, "isDirty", ee);
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);
608
608
  },
609
609
  [v]
610
- ), A = f((r, t) => (c.current.set(r, t), i.current[r] = { ...ie }, () => {
611
- a && c.current.delete(r);
612
- }), []), I = f(
613
- (r, { keepError: t, keepDirty: _, keepTouched: w, keepCustomState: ee, defaultValue: M }) => {
614
- const L = c.current.get(r);
615
- 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)
616
616
  throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);
617
- l.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);
618
618
  },
619
619
  [o, v]
620
- ), B = f((r, t = R.getValues(r)) => {
621
- m.publish("onBlur", r, t, R.getValues());
622
- }, []), R = 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(
623
623
  () => ({
624
- subscribe: Z,
625
- reset: Y,
624
+ subscribe: Q,
625
+ reset: B,
626
626
  resetField: I,
627
- setValue: j,
628
- getValues: G,
629
- getErrors: N,
630
- getFieldStates: $,
631
- getFormState: V,
627
+ setValue: C,
628
+ getValues: H,
629
+ getErrors: V,
630
+ getFieldStates: M,
631
+ getFormState: D,
632
632
  setError: e,
633
633
  clearError: o,
634
634
  clearErrors: S,
635
- checkValidity: T,
635
+ checkValidity: F,
636
636
  getNumberFields: oe,
637
637
  getFieldValidity: se,
638
638
  getDefaultValues: ne,
639
639
  setFieldState: v,
640
- triggerFieldBlur: B,
641
- resetFieldState: Q,
642
- getControlledFields: z
640
+ triggerFieldBlur: L,
641
+ resetFieldState: K,
642
+ getControlledFields: G,
643
+ subscribeChange: T,
644
+ subscribeBlur: N
643
645
  }),
644
646
  [
645
- Z,
646
- Y,
647
+ Q,
648
+ B,
647
649
  I,
648
- j,
649
- G,
650
- N,
651
- $,
650
+ C,
651
+ H,
652
652
  V,
653
+ M,
654
+ D,
653
655
  e,
654
656
  o,
655
657
  S,
656
- T,
658
+ F,
657
659
  oe,
658
660
  se,
659
661
  ne,
660
662
  v,
661
- Q,
662
- B,
663
- z
663
+ K,
664
+ L,
665
+ G,
666
+ T,
667
+ N
664
668
  ]
665
- ), x = ae(
669
+ ), ue = ie(
666
670
  () => ({
667
- ref: E,
668
- watch: D,
669
- actions: R,
671
+ ref: l,
672
+ watch: W,
673
+ actions: x,
670
674
  registerController: A,
671
- registerHookWatcher: H,
672
- lastReloadedAt: d,
673
- loadFormValues: W,
674
- getWatchValue: X,
675
- channels: m
675
+ registerHookWatcher: X,
676
+ lastReloadedAt: E,
677
+ loadFormValues: $,
678
+ getWatchValue: Z,
679
+ channels: b
676
680
  }),
677
681
  [
678
- E,
679
- D,
680
- R,
681
- A,
682
- H,
683
- d,
682
+ l,
684
683
  W,
684
+ x,
685
+ A,
685
686
  X,
686
- m
687
+ E,
688
+ $,
689
+ Z,
690
+ b
687
691
  ]
688
- ), K = ae(() => ({ control: x, actions: R, watch: D }), [d, x, R, D]);
689
- return fe(() => {
690
- if ([...E.current.querySelectorAll("[name]")].forEach((t) => {
691
- !t.defaultValue && !c.current.has(t.name) && l.current[t.name] && (t.defaultValue = l.current[t.name]), t.type === "number" && !k.current.includes(t.name) && k.current.push(t.name);
692
- }), E.current) {
693
- const t = W();
694
- u.current = { ...t }, l.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 };
695
699
  }
696
- }, [d]), fe(() => {
700
+ }, [E]), de(() => {
697
701
  O();
698
- }, []), K;
702
+ }, []), ve;
699
703
  };
700
704
  export {
701
- Me as Controller,
702
- $e as Form,
703
- ke as useController,
704
- Ye as useForm,
705
- Se as useFormContext,
706
- _e 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
707
711
  };