react-simple-formkit 1.3.6 → 2.0.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 ue, { createContext as le, useContext as ie, useEffect as oe, useRef as O, useState as N, useCallback as m, useMemo as ae, useLayoutEffect as fe } from "react";
2
- var G = { exports: {} }, M = {};
1
+ import Ae, { createContext as Pe, useContext as Ce, 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 = {};
3
3
  /**
4
4
  * @license React
5
5
  * react-jsx-runtime.production.js
@@ -9,29 +9,29 @@ var G = { exports: {} }, M = {};
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 K;
13
- function de() {
14
- if (K) return M;
15
- K = 1;
16
- var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
17
- function a(l, u, i) {
18
- var R = null;
19
- if (i !== void 0 && (R = "" + i), u.key !== void 0 && (R = "" + u.key), "key" in u) {
20
- i = {};
21
- for (var d in u)
22
- d !== "key" && (i[d] = u[d]);
23
- } else i = u;
24
- return u = i.ref, {
25
- $$typeof: o,
26
- type: l,
27
- key: R,
28
- ref: u !== void 0 ? u : null,
29
- props: i
12
+ var ye;
13
+ function je() {
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, {
25
+ $$typeof: s,
26
+ type: m,
27
+ key: v,
28
+ ref: i !== void 0 ? i : null,
29
+ props: f
30
30
  };
31
31
  }
32
- return M.Fragment = t, M.jsx = a, M.jsxs = a, M;
32
+ return Q.Fragment = u, Q.jsx = l, Q.jsxs = l, Q;
33
33
  }
34
- var L = {};
34
+ var K = {};
35
35
  /**
36
36
  * @license React
37
37
  * react-jsx-runtime.development.js
@@ -41,125 +41,125 @@ var L = {};
41
41
  * This source code is licensed under the MIT license found in the
42
42
  * LICENSE file in the root directory of this source tree.
43
43
  */
44
- var ee;
45
- function Ee() {
46
- return ee || (ee = 1, process.env.NODE_ENV !== "production" && function() {
47
- function o(e) {
44
+ var pe;
45
+ function xe() {
46
+ return pe || (pe = 1, process.env.NODE_ENV !== "production" && function() {
47
+ function s(e) {
48
48
  if (e == null) return null;
49
49
  if (typeof e == "function")
50
- return e.$$typeof === j ? null : e.displayName || e.name || null;
50
+ return e.$$typeof === ne ? null : e.displayName || e.name || null;
51
51
  if (typeof e == "string") return e;
52
52
  switch (e) {
53
- case A:
53
+ case x:
54
54
  return "Fragment";
55
- case k:
55
+ case Y:
56
56
  return "Profiler";
57
- case g:
58
- return "StrictMode";
59
57
  case W:
58
+ return "StrictMode";
59
+ case re:
60
60
  return "Suspense";
61
- case B:
61
+ case te:
62
62
  return "SuspenseList";
63
- case q:
63
+ case V:
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 X:
70
+ case D:
71
71
  return "Portal";
72
- case Y:
72
+ case $:
73
73
  return (e.displayName || "Context") + ".Provider";
74
- case D:
74
+ case B:
75
75
  return (e._context.displayName || "Context") + ".Consumer";
76
- case y:
77
- var r = e.render;
78
- return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case U:
80
- return r = e.displayName || null, r !== null ? r : o(e.type) || "Memo";
81
- case I:
82
- r = e._payload, e = e._init;
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;
83
83
  try {
84
- return o(e(r));
84
+ return s(e(o));
85
85
  } catch {
86
86
  }
87
87
  }
88
88
  return null;
89
89
  }
90
- function t(e) {
90
+ function u(e) {
91
91
  return "" + e;
92
92
  }
93
- function a(e) {
93
+ function l(e) {
94
94
  try {
95
- t(e);
96
- var r = !1;
95
+ u(e);
96
+ var o = !1;
97
97
  } catch {
98
- r = !0;
98
+ o = !0;
99
99
  }
100
- if (r) {
101
- r = console;
102
- var s = r.error, c = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
- return s.call(
104
- r,
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,
105
105
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
- c
107
- ), t(e);
106
+ b
107
+ ), u(e);
108
108
  }
109
109
  }
110
- function l(e) {
111
- if (e === A) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === I)
110
+ function m(e) {
111
+ if (e === x) return "<>";
112
+ if (typeof e == "object" && e !== null && e.$$typeof === X)
113
113
  return "<...>";
114
114
  try {
115
- var r = o(e);
116
- return r ? "<" + r + ">" : "<...>";
115
+ var o = s(e);
116
+ return o ? "<" + o + ">" : "<...>";
117
117
  } catch {
118
118
  return "<...>";
119
119
  }
120
120
  }
121
- function u() {
122
- var e = x.A;
121
+ function i() {
122
+ var e = U.A;
123
123
  return e === null ? null : e.getOwner();
124
124
  }
125
- function i() {
125
+ function f() {
126
126
  return Error("react-stack-top-frame");
127
127
  }
128
- function R(e) {
129
- if (w.call(e, "key")) {
130
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
131
- if (r && r.isReactWarning) return !1;
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;
132
132
  }
133
133
  return e.key !== void 0;
134
134
  }
135
- function d(e, r) {
136
- function s() {
135
+ function E(e, o) {
136
+ function c() {
137
137
  P || (P = !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
- r
139
+ o
140
140
  ));
141
141
  }
142
- s.isReactWarning = !0, Object.defineProperty(e, "key", {
143
- get: s,
142
+ c.isReactWarning = !0, Object.defineProperty(e, "key", {
143
+ get: c,
144
144
  configurable: !0
145
145
  });
146
146
  }
147
- function E() {
148
- var e = o(this.type);
149
- return $[e] || ($[e] = !0, console.error(
147
+ function O() {
148
+ var e = s(this.type);
149
+ return q[e] || (q[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 _(e, r, s, c, T, h, H, Z) {
154
- return s = h.ref, e = {
155
- $$typeof: V,
153
+ function j(e, o, c, b, _, T, z, G) {
154
+ return c = T.ref, e = {
155
+ $$typeof: y,
156
156
  type: e,
157
- key: r,
158
- props: h,
159
- _owner: T
160
- }, (s !== void 0 ? s : null) !== null ? Object.defineProperty(e, "ref", {
157
+ key: o,
158
+ props: T,
159
+ _owner: _
160
+ }, (c !== void 0 ? c : null) !== null ? Object.defineProperty(e, "ref", {
161
161
  enumerable: !1,
162
- get: E
162
+ get: O
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,297 +174,421 @@ function Ee() {
174
174
  configurable: !1,
175
175
  enumerable: !1,
176
176
  writable: !0,
177
- value: H
177
+ value: z
178
178
  }), Object.defineProperty(e, "_debugTask", {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: Z
182
+ value: G
183
183
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
184
  }
185
- function S(e, r, s, c, T, h, H, Z) {
186
- var p = r.children;
187
- if (p !== void 0)
188
- if (c)
189
- if (J(p)) {
190
- for (c = 0; c < p.length; c++)
191
- b(p[c]);
192
- Object.freeze && Object.freeze(p);
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);
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(p);
198
- if (w.call(r, "key")) {
199
- p = o(e);
200
- var C = Object.keys(r).filter(function(ce) {
201
- return ce !== "key";
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";
202
202
  });
203
- c = 0 < C.length ? "{key: someKey, " + C.join(": ..., ") + ": ...}" : "{key: someKey}", f[p + c] || (C = 0 < C.length ? "{" + C.join(": ..., ") + ": ...}" : "{}", console.error(
203
+ b = 0 < A.length ? "{key: someKey, " + A.join(": ..., ") + ": ...}" : "{key: someKey}", L[R + b] || (A = 0 < A.length ? "{" + A.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
- c,
211
- p,
212
- C,
213
- p
214
- ), f[p + c] = !0);
210
+ b,
211
+ R,
212
+ A,
213
+ R
214
+ ), L[R + b] = !0);
215
215
  }
216
- if (p = null, s !== void 0 && (a(s), p = "" + s), R(r) && (a(r.key), p = "" + r.key), "key" in r) {
217
- s = {};
218
- for (var Q in r)
219
- Q !== "key" && (s[Q] = r[Q]);
220
- } else s = r;
221
- return p && d(
222
- s,
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,
223
223
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
224
- ), _(
224
+ ), j(
225
225
  e,
226
- p,
227
- h,
226
+ R,
228
227
  T,
229
- u(),
230
- s,
231
- H,
232
- Z
228
+ _,
229
+ i(),
230
+ c,
231
+ z,
232
+ G
233
233
  );
234
234
  }
235
- function b(e) {
236
- typeof e == "object" && e !== null && e.$$typeof === V && e._store && (e._store.validated = 1);
235
+ function g(e) {
236
+ typeof e == "object" && e !== null && e.$$typeof === y && e._store && (e._store.validated = 1);
237
237
  }
238
- var v = ue, V = Symbol.for("react.transitional.element"), X = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), g = Symbol.for("react.strict_mode"), k = Symbol.for("react.profiler"), D = Symbol.for("react.consumer"), Y = Symbol.for("react.context"), y = Symbol.for("react.forward_ref"), W = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), U = Symbol.for("react.memo"), I = Symbol.for("react.lazy"), q = Symbol.for("react.activity"), j = Symbol.for("react.client.reference"), x = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, w = Object.prototype.hasOwnProperty, J = Array.isArray, F = console.createTask ? console.createTask : function() {
238
+ var d = Ae, y = Symbol.for("react.transitional.element"), D = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), W = Symbol.for("react.strict_mode"), Y = 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"), V = 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, N = console.createTask ? console.createTask : function() {
239
239
  return null;
240
240
  };
241
- v = {
241
+ d = {
242
242
  "react-stack-bottom-frame": function(e) {
243
243
  return e();
244
244
  }
245
245
  };
246
- var P, $ = {}, z = v["react-stack-bottom-frame"].bind(
247
- v,
248
- i
249
- )(), n = F(l(i)), f = {};
250
- L.Fragment = A, L.jsx = function(e, r, s, c, T) {
251
- var h = 1e4 > x.recentlyCreatedOwnerStacks++;
246
+ var P, q = {}, J = d["react-stack-bottom-frame"].bind(
247
+ d,
248
+ f
249
+ )(), M = N(m(f)), L = {};
250
+ K.Fragment = x, K.jsx = function(e, o, c, b, _) {
251
+ var T = 1e4 > U.recentlyCreatedOwnerStacks++;
252
252
  return S(
253
253
  e,
254
- r,
255
- s,
256
- !1,
254
+ o,
257
255
  c,
258
- T,
259
- h ? Error("react-stack-top-frame") : z,
260
- h ? F(l(e)) : n
256
+ !1,
257
+ b,
258
+ _,
259
+ T ? Error("react-stack-top-frame") : J,
260
+ T ? N(m(e)) : M
261
261
  );
262
- }, L.jsxs = function(e, r, s, c, T) {
263
- var h = 1e4 > x.recentlyCreatedOwnerStacks++;
262
+ }, K.jsxs = function(e, o, c, b, _) {
263
+ var T = 1e4 > U.recentlyCreatedOwnerStacks++;
264
264
  return S(
265
265
  e,
266
- r,
267
- s,
268
- !0,
266
+ o,
269
267
  c,
270
- T,
271
- h ? Error("react-stack-top-frame") : z,
272
- h ? F(l(e)) : n
268
+ !0,
269
+ b,
270
+ _,
271
+ T ? Error("react-stack-top-frame") : J,
272
+ T ? N(m(e)) : M
273
273
  );
274
274
  };
275
- }()), L;
275
+ }()), K;
276
276
  }
277
- var re;
278
- function be() {
279
- return re || (re = 1, process.env.NODE_ENV === "production" ? G.exports = de() : G.exports = Ee()), G.exports;
277
+ var ve;
278
+ function Fe() {
279
+ return ve || (ve = 1, process.env.NODE_ENV === "production" ? ce.exports = je() : ce.exports = xe()), ce.exports;
280
280
  }
281
- var te = be();
282
- const se = le({}), me = () => ie(se), he = ({
283
- id: o,
284
- form: t,
285
- method: a,
286
- action: l,
287
- children: u,
288
- onSubmit: i = () => {
281
+ var ke = Fe();
282
+ const h = () => {
283
+ }, Te = Pe({
284
+ ref: null,
285
+ watch: null,
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
299
+ },
300
+ registerController: h,
301
+ registerHookWatcher: h,
302
+ lastReloadedAt: h,
303
+ registerOnchange: h,
304
+ loadFormValues: h,
305
+ getWatchValue: h
306
+ }), Oe = () => Ce(Te), Le = ({
307
+ id: s,
308
+ control: u,
309
+ method: l,
310
+ action: m,
311
+ children: i,
312
+ onSubmit: f = () => {
289
313
  },
290
- onInput: R = () => {
314
+ onInput: v = () => {
291
315
  },
292
- onChange: d = () => {
316
+ onChange: E = () => {
293
317
  },
294
- numberFields: E = [],
295
- className: _,
296
- ...S
297
- }) => (oe(() => t.actions.registerOnchange(d), [d]), /* @__PURE__ */ te.jsx(se.Provider, { value: t, children: t.ready && /* @__PURE__ */ te.jsx(
318
+ onReset: O = () => {
319
+ },
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(
298
324
  "form",
299
325
  {
300
- id: o,
301
- ref: t == null ? void 0 : t.ref,
302
- action: l,
303
- method: a,
304
- className: _,
305
- onSubmit: (b) => {
306
- a || b.preventDefault();
307
- const v = t.actions.loadFormValues();
308
- i(v);
309
- },
310
- onInput: (b) => {
311
- if (b.target.tagName === "FORM") {
312
- const v = t.actions.loadFormValues();
313
- t.actions.setFormState(v);
314
- } else
315
- R(b);
326
+ id: s,
327
+ ref: u.ref,
328
+ action: m,
329
+ method: l,
330
+ className: S,
331
+ onInput: v,
332
+ onSubmit: (d) => {
333
+ l || d.preventDefault();
334
+ const y = u.loadFormValues();
335
+ f(y);
316
336
  },
317
- onChange: () => {
318
- const b = t.actions.loadFormValues();
319
- t.actions.setFormState(b);
337
+ onChange: (d) => {
338
+ const y = d.target.name;
339
+ u.actions.getControlledFields()[y] || u.actions.setValue(y, d.target.value);
320
340
  },
321
- onReset: (b) => {
322
- t && (b.preventDefault(), t.actions.reset());
341
+ onReset: (d) => {
342
+ u.actions.reset(), O(d);
323
343
  },
324
- ...S,
325
- children: u
344
+ ...g,
345
+ children: i
326
346
  },
327
- t == null ? void 0 : t.lastReloadedAt
328
- ) })), Se = ({ name: o, render: t = ({ ref: a, name: l, defaultValue: u, value: i, setValue: R }) => null }) => {
329
- const a = O(), l = me(), u = l.actions.getDefaultValues()[o], [i, R] = N(u), d = m(
330
- (E, { shouldDirty: _ = !0 } = {}) => {
331
- l.actions.setFormState((S) => ({ ...S, [o]: E }), { shouldDirty: _ }), R(E);
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);
332
357
  },
333
- [R, l.actions.setFormState]
358
+ [l.setValue]
334
359
  );
335
- return oe(() => l.subscribe(o, (_, { shouldDirty: S = !0, shouldOnChange: b = !0 } = {}) => {
336
- R(_), l.actions.setFormState((v) => ({ ...v, [o]: _ }), { shouldDirty: S, shouldOnChange: b }), a.current && typeof a.current.dispatchEvent == "function" && b && a.current.dispatchEvent(new Event("change"));
337
- }), []), t({ ref: a, name: o, defaultValue: u, value: i, setValue: d });
338
- }, Re = (o, t) => {
339
- let a = !1;
340
- return Object.keys(t).forEach((l) => {
341
- if (!(l in o) || a) return;
342
- const u = t[l], i = o[l];
343
- (typeof u == "object" || u !== i) && (a = !0);
344
- }), a;
345
- }, ne = (o) => (typeof o.setCustomValidity == "function" && o.setCustomValidity(""), !o || typeof o.checkValidity != "function" || o.checkValidity() ? null : o.validationMessage), pe = () => {
346
- const [o, t] = N({}), a = ae(() => Object.values(o).filter(Boolean).length > 0, [o]), l = m((d, E) => {
347
- t((_) => _[d] === E ? _ : { ..._, [d]: E });
348
- }, []), u = m((d) => {
349
- t((E) => ({ ...E, ...d }));
350
- }, []), i = m((d) => {
351
- t((E) => E[d] ? { ...E, [d]: "" } : E);
352
- }, []), R = m(() => {
353
- t({});
354
- }, []);
355
- return { isError: a, errors: o, changeError: l, changeErrors: u, clearError: i, clearErrors: R };
356
- }, _e = () => {
357
- const [o, t] = N(), a = m(() => t((/* @__PURE__ */ new Date()).toString()), []);
358
- return [o, a];
359
- }, ve = () => {
360
- const [, o] = N({});
361
- return m(() => o({}), []);
362
- }, ge = [], ke = ({ numberFields: o = ge, defaultValues: t = {} } = {}) => {
363
- const { changeError: a, errors: l, changeErrors: u, clearError: i, clearErrors: R, isError: d } = pe(), [E, _] = N(!1), [S, b] = _e(), [v, V] = N(!1), X = ve(), A = O(/* @__PURE__ */ new Set()), g = O(t), k = O(t), D = O({}), Y = O(() => {
364
- }), y = O(), W = m(
365
- (n, { shouldDirty: f = !0, shouldOnChange: e = !0 } = {}) => {
366
- let r = n;
367
- typeof n == "function" && (r = n(g.current)), [...A.current].forEach((T) => {
368
- g.current[T] !== r[T] && X();
369
- }), g.current = r;
370
- let c = E;
371
- f && (console.log(c, g.current.password, k.current.password), c = Re(g.current, k.current), c !== E && _(c)), e && Y.current(g.current);
372
- },
373
- [E]
374
- ), B = m((n, f) => {
375
- const e = D.current;
376
- return e[n] = f, () => {
377
- delete e[n], delete g.current[n], delete k.current[n];
378
- };
379
- }, []), U = m((n) => (Y.current = n, () => Y.current = () => {
380
- })), I = m(() => V(!1), []), q = m((n) => ne(n.target), []), j = m((n) => n ? g.current[n] : g.current, []), x = m(() => k.current, []), w = m(() => {
381
- setTimeout(() => y.current.dispatchEvent(new Event("input", { bubbles: !0 })));
382
- }, []), J = m(
383
- (n) => {
384
- const f = ne(n.target);
385
- f ? a(n.target.name, f) : a(n.target.name, null);
360
+ return Ee(() => m(s, E), []), { ref: i, name: s, defaultValue: f, value: v, onChange: S, customState: O, setCustomState: j };
361
+ }, Ue = ({
362
+ name: s,
363
+ defaultValue: u,
364
+ render: l = ({ ref: m, name: i, defaultValue: f, value: v, onChange: E, customState: O, setCustomState: j }) => null
365
+ }) => {
366
+ const m = Ne({ name: s, defaultValue: u });
367
+ return l(m);
368
+ }, we = [
369
+ "badInput",
370
+ "customError",
371
+ "patternMismatch",
372
+ "rangeOverflow",
373
+ "rangeUnderflow",
374
+ "stepMismatch",
375
+ "tooLong",
376
+ "tooShort",
377
+ "typeMismatch",
378
+ "valueMissing"
379
+ ], _e = (s) => {
380
+ typeof s.setCustomValidity == "function" && s.setCustomValidity("");
381
+ let u = s.validity;
382
+ console.log(s.valid);
383
+ let l = we.find((m) => u[m]);
384
+ 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()), []);
390
+ 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), D = k({}), x = k([]), W = k([]), Y = 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, Y.current = {}, y.current = s, d.current = /* @__PURE__ */ new Set(), W.current = [], x.current = [], D.current = {}, ee(), s.length > 0 && (m = !0), v();
405
+ }, []), te = a(() => !!Object.values(N()).find((r) => r.isDirty), []), ae = a(() => !!Object.values(I()).find((r) => !!r), []), X = a((r) => _e(r.target), []), V = a((r) => r ? S.current[r] : S.current, []), ne = a(() => g.current, []), U = a(() => y.current, []), I = a(() => Y.current, []), oe = a(() => D.current, []), N = a(() => $.current, []), P = a(({ name: r, compute: t }) => {
406
+ var p;
407
+ if (typeof t == "function") return t(V());
408
+ if (Array.isArray(r)) {
409
+ const C = {};
410
+ return r.forEach((F) => {
411
+ C[F] = P({ name: F });
412
+ }), C;
413
+ }
414
+ if (r === "isDirty") return te();
415
+ if (r === "isError") return ae();
416
+ if (r === "values") return { ...V() };
417
+ if (r === "errors") return { ...I() };
418
+ if (r === "fieldStates") return { ...N() };
419
+ const n = r.split(".");
420
+ if (n.length > 1) {
421
+ const C = n[1];
422
+ if (n[0] === "errors")
423
+ return n.length === 2 ? { ...I()[C] } : { ...I()[C] };
424
+ if (n[0] === "fieldStates") {
425
+ if (n.length === 2) return { ...N()[C] };
426
+ const F = n[2];
427
+ return (p = N()[C]) == null ? void 0 : p[F];
428
+ }
429
+ }
430
+ return V()[r];
431
+ }, []), q = (r) => {
432
+ W.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
+ Y.current[r] = t, J(r);
448
+ }, []), L = a((r) => {
449
+ Y.current[r] = null, J(r);
450
+ }, []), e = a(() => {
451
+ Y.current = {}, J();
452
+ }, []), o = a(
453
+ (r) => {
454
+ const t = _e(r.target);
455
+ t ? M(r.target.name, t) : L(r.target.name);
386
456
  },
387
- [a]
388
- ), F = m(
389
- (n, f, { shouldDirty: e = !0, shouldOnChange: r = !0 } = {}) => {
390
- const s = D.current;
391
- switch (typeof n) {
392
- case "string":
393
- {
394
- const c = s[n];
395
- if (!c)
396
- throw new Error(`${n} is uncontrolled, please use Controller for it!`);
397
- c(f, { shouldDirty: e, shouldOnChange: r }), r && w();
398
- }
399
- break;
400
- case "object":
401
- Object.entries(n).forEach(([c, T]) => {
402
- const h = s[c];
403
- if (!h)
404
- throw new Error(`${c} is uncontrolled, please use Controller for it!`);
405
- h(T, { shouldDirty: e, shouldOnChange: r });
406
- }), r && w();
407
- default:
408
- return;
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 F = ({ name: w }) => w === "fieldStates" || w === `fieldStates.${r}` || w === `fieldStates.${r}.${t}`;
463
+ if ([...d.current].forEach((w) => {
464
+ F({ name: w }) && i();
465
+ }), t === "customState") {
466
+ x.current.forEach(({ name: w, setValue: se }) => {
467
+ w.includes(r) && se(n);
468
+ });
469
+ return;
409
470
  }
471
+ q(F);
472
+ }
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 C = S.current[r], F = $.current[r], se = D.current[r];
477
+ if (c(r, "isTouched", !0), n) {
478
+ const Z = t !== g.current[r];
479
+ F.isDirty !== Z && c(r, "isDirty", Z);
480
+ }
481
+ const ie = te(), ge = j.current, Re = t !== C;
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(V());
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);
410
492
  },
411
- [w]
412
- ), P = m(() => {
413
- const n = Object.fromEntries(new FormData(y.current)), f = D.current;
414
- return Object.keys(f).map((e) => {
415
- n[e] = g.current[e];
416
- }), o.forEach((e) => n.hasOwnProperty(e) && (n[e] = +n[e])), n;
417
- }, []), $ = (n) => (A.current.add(n), n === "data" ? j() : j()[n]), z = ae(
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 = D.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") ? x.current.push({ key: t, ...r }) : W.current.push({ key: t, ...r }), B.current++, () => {
514
+ W.current = W.current.filter((p) => p.key !== t), x.current = x.current.filter((p) => p.key !== t);
515
+ };
516
+ }, []), R = a(() => {
517
+ const r = Object.fromEntries(new FormData(E.current)), t = D.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)
522
+ ), r;
523
+ }, []), A = me(
418
524
  () => ({
419
- setValue: F,
420
- instantChange: w,
421
- getDefaultValues: x,
422
- getFormState: j,
423
- setFormState: W,
424
- changeError: a,
425
- changeErrors: u,
426
- clearError: i,
427
- clearErrors: R,
428
- loadFormValues: P,
429
- checkValidity: J,
430
- getFieldValidity: q,
431
- registerOnchange: U,
432
- reload: b,
433
- reset: I,
434
- watch: $
525
+ reset: re,
526
+ setValue: b,
527
+ getValues: V,
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
435
537
  }),
436
538
  [
437
- F,
438
- w,
439
- x,
440
- j,
441
- W,
442
- a,
443
- u,
444
- i,
445
- P,
446
- q,
447
- J,
448
- U,
539
+ re,
449
540
  b,
450
- I,
451
- $
541
+ V,
542
+ M,
543
+ L,
544
+ e,
545
+ o,
546
+ U,
547
+ X,
548
+ ne,
549
+ c,
550
+ oe
452
551
  ]
453
- );
454
- return fe(() => {
455
- if (!v)
456
- k.current = { ...t }, g.current = { ...t }, _(!1), R(), V(!0);
457
- else if ([...y.current.querySelectorAll("[name]")].forEach((f) => {
458
- !f.defaultValue && t[f.name] && (f.defaultValue = t[f.name]);
459
- }), y.current) {
460
- const f = P();
461
- k.current = f, g.current = f;
552
+ ), H = me(
553
+ () => ({
554
+ 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
563
+ }),
564
+ [
565
+ E,
566
+ _,
567
+ A,
568
+ T,
569
+ G,
570
+ f,
571
+ z,
572
+ R,
573
+ P
574
+ ]
575
+ ), le = me(() => ({ control: H, actions: A, watch: _ }), [f, H, A, _]);
576
+ return Se(() => {
577
+ 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);
579
+ }), E.current) {
580
+ const t = R();
581
+ S.current = { ...t }, g.current = { ...t };
462
582
  }
463
- }, [v]), { ready: v, ref: y, isDirty: E, isError: d, errors: l, numberFields: o, subscribe: B, actions: z };
583
+ }, [f]), Se(() => {
584
+ ee();
585
+ }, []), le;
464
586
  };
465
587
  export {
466
- Se as Controller,
467
- he as Form,
468
- ke as useForm,
469
- pe as useValidateForm
588
+ Ue as Controller,
589
+ Le as Form,
590
+ Ne as useController,
591
+ qe as useForm,
592
+ Oe as useFormContext,
593
+ Ve as useWatch
470
594
  };