react-simple-formkit 2.0.4 → 2.1.5

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 Re, { createContext as Se, useContext as pe, useEffect as ie, useState as ce, useRef as j, useCallback as f, useMemo as ae, useLayoutEffect as le } from "react";
2
+ var ue = { exports: {} }, re = {};
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 fe;
13
+ function ye() {
14
+ if (fe) return re;
15
+ fe = 1;
16
+ var s = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
17
+ function l(g, b, h) {
18
+ var E = null;
19
+ if (h !== void 0 && (E = "" + h), b.key !== void 0 && (E = "" + b.key), "key" in b) {
20
+ h = {};
21
+ for (var v in b)
22
+ v !== "key" && (h[v] = b[v]);
23
+ } else h = b;
24
+ return b = h.ref, {
25
25
  $$typeof: s,
26
- type: m,
27
- key: v,
28
- ref: i !== void 0 ? i : null,
29
- props: f
26
+ type: g,
27
+ key: E,
28
+ ref: b !== void 0 ? b : null,
29
+ props: h
30
30
  };
31
31
  }
32
- return Q.Fragment = u, Q.jsx = l, Q.jsxs = l, Q;
32
+ return re.Fragment = n, re.jsx = l, re.jsxs = l, re;
33
33
  }
34
- var K = {};
34
+ var te = {};
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 de;
45
+ function ve() {
46
+ return de || (de = 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:
56
- return "Profiler";
57
55
  case Y:
56
+ return "Profiler";
57
+ case A:
58
58
  return "StrictMode";
59
- case re:
59
+ case se:
60
60
  return "Suspense";
61
- case te:
61
+ case ne:
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 $:
72
+ case I:
73
73
  return (e.displayName || "Context") + ".Provider";
74
- case B:
74
+ case W:
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 oe:
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, _ = 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
+ _
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 g(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 = N.A;
123
123
  return e === null ? null : e.getOwner();
124
124
  }
125
- function f() {
125
+ function h() {
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 ($.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 v(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 F() {
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, _, O, w, B, L) {
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: F
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: B
178
178
  }), Object.defineProperty(e, "_debugTask", {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: G
182
+ value: L
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, _, O, w, B, L) {
186
+ var S = u.children;
187
+ if (S !== void 0)
188
+ if (_)
189
+ if (V(S)) {
190
+ for (_ = 0; _ < S.length; _++)
191
+ m(S[_]);
192
+ Object.freeze && Object.freeze(S);
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(S);
198
+ if ($.call(u, "key")) {
199
+ S = s(e);
200
+ var x = Object.keys(u).filter(function(r) {
201
+ return r !== "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
+ _ = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", Q[S + _] || (x = 0 < x.length ? "{" + x.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
+ _,
211
+ S,
212
+ x,
213
+ S
214
+ ), Q[S + _] = !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 (S = null, R !== void 0 && (l(R), S = "" + R), E(u) && (l(u.key), S = "" + u.key), "key" in u) {
217
+ R = {};
218
+ for (var K in u)
219
+ K !== "key" && (R[K] = u[K]);
220
+ } else R = u;
221
+ return S && v(
222
+ R,
223
223
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
224
- ), j(
224
+ ), k(
225
225
  e,
226
+ S,
227
+ w,
228
+ O,
229
+ b(),
226
230
  R,
227
- T,
228
- _,
229
- i(),
230
- c,
231
- z,
232
- G
231
+ B,
232
+ L
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 = Re, o = Symbol.for("react.transitional.element"), i = Symbol.for("react.portal"), d = Symbol.for("react.fragment"), A = Symbol.for("react.strict_mode"), Y = Symbol.for("react.profiler"), W = Symbol.for("react.consumer"), I = 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 = a.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, $ = Object.prototype.hasOwnProperty, V = 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
+ h
249
+ )(), y = D(g(h)), Q = {};
250
+ te.Fragment = d, te.jsx = function(e, u, R, _, O) {
251
+ var w = 1e4 > N.recentlyCreatedOwnerStacks++;
252
+ return c(
253
253
  e,
254
- o,
255
- c,
254
+ u,
255
+ R,
256
256
  !1,
257
- b,
258
257
  _,
259
- T ? Error("react-stack-top-frame") : J,
260
- T ? w(m(e)) : M
258
+ O,
259
+ w ? Error("react-stack-top-frame") : Z,
260
+ w ? D(g(e)) : y
261
261
  );
262
- }, K.jsxs = function(e, o, c, b, _) {
263
- var T = 1e4 > U.recentlyCreatedOwnerStacks++;
264
- return S(
262
+ }, te.jsxs = function(e, u, R, _, O) {
263
+ var w = 1e4 > N.recentlyCreatedOwnerStacks++;
264
+ return c(
265
265
  e,
266
- o,
267
- c,
266
+ u,
267
+ R,
268
268
  !0,
269
- b,
270
269
  _,
271
- T ? Error("react-stack-top-frame") : J,
272
- T ? w(m(e)) : M
270
+ O,
271
+ w ? Error("react-stack-top-frame") : Z,
272
+ w ? D(g(e)) : y
273
273
  );
274
274
  };
275
- }()), K;
275
+ }()), te;
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 be;
278
+ function Te() {
279
+ return be || (be = 1, process.env.NODE_ENV === "production" ? ue.exports = ye() : ue.exports = ve()), ue.exports;
280
280
  }
281
- var ke = Fe();
282
- const h = () => {
283
- }, Te = Pe({
281
+ var me = Te();
282
+ const p = () => {
283
+ }, ge = Se({
284
284
  ref: null,
285
- watch: null,
285
+ watch: p,
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: 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
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: p,
306
+ registerHookWatcher: p,
307
+ lastReloadedAt: p,
308
+ loadFormValues: p,
309
+ getWatchValue: p,
310
+ channels: {}
311
+ }), he = () => pe(ge), We = ({
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: g,
316
+ children: b,
317
+ onSubmit: h = () => {
318
+ },
319
+ onInput: E = () => {
313
320
  },
314
- onInput: v = () => {
321
+ onChange: v = () => {
315
322
  },
316
- onChange: E = () => {
323
+ onBlur: F = () => {
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
+ }) => (ie(() => {
331
+ const o = n.channels.subscribe("onChange", v), i = n.channels.subscribe("onBlur", F);
332
+ return () => {
333
+ o(), i();
334
+ };
335
+ }, []), /* @__PURE__ */ me.jsx(ge.Provider, { value: n, children: /* @__PURE__ */ me.jsx(
324
336
  "form",
325
337
  {
326
338
  id: s,
327
- ref: u.ref,
328
- action: m,
339
+ ref: n.ref,
340
+ action: g,
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
+ h(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
+ ) })), Fe = ({ control: s, name: n, compute: l }) => {
367
+ const { getWatchValue: g, registerHookWatcher: b } = s || he(), h = g({ name: n, compute: l }), [E, v] = ce(h);
368
+ return ie(() => {
369
+ const F = b({ name: n, compute: l, value: E, setValue: v });
370
+ return () => F.forEach((k) => k());
371
+ }, []), E;
372
+ }, _e = ({ name: s, defaultValue: n }) => {
373
+ const { actions: l, registerController: g, channels: b } = he(), h = j(), E = l.getDefaultValues()[s] || n, [v, F] = ce(E), k = Fe({ 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
+ F(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, v, l.getValues());
382
+ }, []);
383
+ return ie(() => g(s, F), []), { ref: h, name: s, defaultValue: E, value: v, onChange: m, onBlur: a, customState: k, setCustomState: c };
384
+ }, $e = ({
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: g, name: b, defaultValue: h, value: E, onChange: v, onBlur: F, customState: k, setCustomState: c }) => null
365
388
  }) => {
366
- const m = Ne({ name: s, defaultValue: u });
367
- return l(m);
368
- }, we = [
389
+ const g = _e({ name: s, defaultValue: n });
390
+ return l(g);
391
+ }, ke = ["errors", "fieldStates", "formState"], q = (s) => ke.some((n) => s.startsWith(n)) ? s : "values." + s, Ae = [
369
392
  "badInput",
370
393
  "customError",
371
394
  "patternMismatch",
@@ -376,219 +399,316 @@ const h = () => {
376
399
  "tooShort",
377
400
  "typeMismatch",
378
401
  "valueMissing"
379
- ], _e = (s) => {
402
+ ], Ee = (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 = Ae.find((g) => n[g]);
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 we {
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 g;
417
+ return (g = this.events.get(n)) == null ? void 0 : g.delete(l);
418
+ };
419
+ }
420
+ publish(n, ...l) {
421
+ const g = this.events.get(n);
422
+ g && g.forEach((b) => b(...l)), this.events.forEach((b, h) => {
423
+ n.includes(h) && b.forEach((E) => E(...l));
424
+ });
425
+ }
426
+ reset() {
427
+ this.events.clear();
428
+ }
429
+ }
430
+ const Oe = () => {
431
+ const s = j(new we()), n = f((b, ...h) => {
432
+ s.current.publish(b, ...h);
433
+ }, []), l = f((b, h) => s.current.subscribe(b, h), []), g = f(() => {
434
+ s.current.reset();
435
+ }, []);
436
+ return { publish: n, subscribe: l, reset: g };
437
+ }, Ce = () => {
438
+ const [s, n] = ce(), 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
+ }, je = () => {
441
+ const [, s] = ce({});
442
+ return f(() => s({}), []);
443
+ }, Pe = ({ channels: s, getValues: n, getErrors: l, getFieldStates: g, getFormState: b }) => {
444
+ const h = je(), 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: { ...g() }
428
459
  }
460
+ );
461
+ }, []), v = f((c) => {
462
+ if (!c)
463
+ return s.subscribe("values", () => {
464
+ h();
465
+ }), n();
466
+ if (typeof c == "string") {
467
+ const m = q(c);
468
+ return s.subscribe(m, () => {
469
+ h();
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
+ h();
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
+ }, []), F = 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 Y = q(A), W = s.subscribe(Y, () => {
499
+ const I = E({ name: A });
500
+ i[A] !== I && (i[A] = I, o({ ...i }));
501
+ });
502
+ d.push(W);
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: v, registerHookWatcher: F, getWatchValue: E, subscribe: k };
530
+ }, xe = [], Ne = {}, Me = ({
531
+ numberFields: s = xe,
532
+ defaultValues: n = Ne,
533
+ shouldUnRegister: l = !1,
534
+ shouldConvertNumber: g = !1
535
+ } = {}) => {
536
+ const [b, h] = Ce(), E = j(), v = j(!1), F = j(!1), k = j(s), c = j(/* @__PURE__ */ new Map()), m = j({}), a = j({}), o = j(n), i = j(n), d = Oe(), 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
+ }, []), Y = f((r = {}) => {
542
+ i.current = { ...i.current, ...r }, o.current = { ...i.current }, c.current.forEach((t, T) => {
543
+ t(i.current[T]);
544
+ }), v.current = !1, m.current = {}, k.current = s, c.current = /* @__PURE__ */ new Map(), d.reset(), A(), s.length > 0 && (g = !0), h();
545
+ }, []), W = f(() => {
546
+ const r = Object.fromEntries(new FormData(E.current));
547
+ return c.current.forEach((T) => {
548
+ r[T] = o.current[T];
549
+ }), g && k.current.forEach(
550
+ (T) => r.hasOwnProperty(T) && (r[T] = Number(r[T]) || 0)
522
551
  ), r;
523
- }, []), A = me(
552
+ }, []), I = f(() => !!Object.values($()).find((r) => r.isDirty), []), J = f(() => !!Object.values(N()).find((r) => !!r), []), se = f((r) => Ee(r.target), []), ne = f(() => i.current, []), oe = f(() => k.current, []), z = f(() => c.current, []), P = f((r, t) => t ? Array.isArray(t) ? t.map((T) => r[T]) : r[t] : { ...r }, []), G = f((r) => P(o.current, r), [P]), N = f((r) => P(m.current, r), [P]), $ = f((r) => P(a.current, r), [P]), V = f(
553
+ (r) => P(
554
+ {
555
+ isDirty: v.current,
556
+ isError: F.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 } = Pe({
565
+ channels: d,
566
+ getValues: G,
567
+ getErrors: N,
568
+ getFieldStates: $,
569
+ getFormState: V
570
+ }), y = f((r, t, T) => {
571
+ const C = a.current[r];
572
+ C[t] !== T && (a.current[r] = { ...C, [t]: T }, d.publish(`fieldStates.${r}.${t}`, T), t === "isError" && d.publish("formState.errorFields", V("errorFields")), t === "isDirty" && d.publish("formState.dirtyFields", V("dirtyFields")), t === "isTouched" && d.publish("formState.touchedFields", V("touchedFields")));
573
+ }, []), Q = f(
574
+ (r) => {
575
+ y(r, "isError", !1), y(r, "isDirty", !1), y(r, "isTouched", !1), y(r, "customState", null);
576
+ },
577
+ [y]
578
+ ), e = f(
579
+ (r, t) => {
580
+ if (m.current[r] === t) return;
581
+ m.current[r] = t, y(r, "isError", !!t), d.publish(`errors.${r}`, t);
582
+ const C = J();
583
+ F.current !== C && (F.current = C, d.publish("formState.isError", C));
584
+ },
585
+ [y]
586
+ ), u = f(
587
+ (r) => {
588
+ if (!m.current[r]) return;
589
+ m.current[r] = null, y(r, "isError", !1), d.publish(`errors.${r}`, null);
590
+ const t = J();
591
+ F.current !== t && (F.current = t, d.publish("formState.isError", t));
592
+ },
593
+ [y]
594
+ ), R = f(() => {
595
+ if (Object.keys(m.current) === 0) return;
596
+ m.current = {}, d.publish("errors", m.current);
597
+ const r = J();
598
+ F.current !== r && (F.current = r, d.publish("formState.isError", r));
599
+ }, []), _ = f(
600
+ (r) => {
601
+ const t = Ee(r.target);
602
+ t ? e(r.target.name, t) : u(r.target.name);
603
+ },
604
+ [e, u]
605
+ ), O = f(
606
+ (r, t, { shouldDirty: T = !0, shouldOnChange: C = !0 } = {}) => {
607
+ if (t === o.current[r]) return;
608
+ g && k.current.includes(r) && (t = Number(t) || void 0), y(r, "isTouched", !0);
609
+ const ee = t !== i.current[r];
610
+ T && a.current[r].isDirty !== ee && y(r, "isDirty", ee);
611
+ const M = I();
612
+ v.current !== M && (v.current = M, d.publish("formState.isDirty", M)), o.current[r] = t;
613
+ const U = c.current.get(r);
614
+ U && U(t), d.publish(`values.${r}`, t, { shouldDirty: T, shouldOnChange: C }), C && d.publish("onChange", r, t, o.current);
615
+ },
616
+ [y]
617
+ ), w = f((r, t) => (c.current.set(r, t), () => {
618
+ l && c.current.delete(r);
619
+ }), []), B = f(
620
+ (r, { keepError: t, keepDirty: T, keepTouched: C, keepCustomState: ee, defaultValue: M }) => {
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] = M, o.current[r] = M, U && U(M), t || u(r), T || y(r, "isDirty", !1), C || y(r, "isTouched", !1), ee || y(r, "customState", null);
625
+ },
626
+ [u, y]
627
+ ), L = f((r, t = S.getValues(r)) => {
628
+ d.publish("onBlur", r, t, S.getValues());
629
+ }, []), S = ae(
524
630
  () => ({
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,
631
+ subscribe: Z,
632
+ reset: Y,
633
+ resetField: B,
634
+ setValue: O,
635
+ getValues: G,
636
+ getErrors: N,
637
+ getFieldStates: $,
638
+ getFormState: V,
639
+ setError: e,
640
+ clearError: u,
641
+ clearErrors: R,
642
+ checkValidity: _,
643
+ getNumberFields: oe,
644
+ getFieldValidity: se,
534
645
  getDefaultValues: ne,
535
- setFieldStateProperty: c,
536
- getControlledFields: oe
646
+ setFieldState: y,
647
+ triggerFieldBlur: L,
648
+ resetFieldState: Q,
649
+ getControlledFields: z
537
650
  }),
538
651
  [
539
- re,
540
- b,
652
+ Z,
653
+ Y,
654
+ B,
655
+ O,
656
+ G,
541
657
  N,
542
- M,
543
- L,
658
+ $,
659
+ V,
544
660
  e,
545
- o,
546
- U,
547
- X,
661
+ u,
662
+ R,
663
+ _,
664
+ oe,
665
+ se,
548
666
  ne,
549
- c,
550
- oe
667
+ y,
668
+ Q,
669
+ L,
670
+ z
551
671
  ]
552
- ), H = me(
672
+ ), x = ae(
553
673
  () => ({
554
674
  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
675
+ watch: D,
676
+ actions: S,
677
+ registerController: w,
678
+ registerHookWatcher: H,
679
+ lastReloadedAt: b,
680
+ loadFormValues: W,
681
+ getWatchValue: X,
682
+ channels: d
563
683
  }),
564
684
  [
565
685
  E,
566
- _,
567
- A,
568
- T,
569
- G,
570
- f,
571
- z,
572
- R,
573
- P
686
+ D,
687
+ S,
688
+ w,
689
+ H,
690
+ b,
691
+ W,
692
+ X,
693
+ d
574
694
  ]
575
- ), le = me(() => ({ control: H, actions: A, watch: _ }), [f, H, A, _]);
576
- return Se(() => {
695
+ ), K = ae(() => ({ control: x, actions: S, watch: D }), [b, x, S, D]);
696
+ return le(() => {
577
697
  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);
698
+ !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
699
  }), E.current) {
580
- const t = R();
581
- S.current = { ...t }, g.current = { ...t };
700
+ const t = W();
701
+ o.current = { ...t }, i.current = { ...t };
582
702
  }
583
- }, [f]), Se(() => {
584
- ee();
585
- }, []), le;
703
+ }, [b]), le(() => {
704
+ A();
705
+ }, []), K;
586
706
  };
587
707
  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
708
+ $e as Controller,
709
+ We as Form,
710
+ _e as useController,
711
+ Me as useForm,
712
+ he as useFormContext,
713
+ Fe as useWatch
594
714
  };