react-simple-formkit 2.0.3 → 2.1.4

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