react-simple-formkit 1.3.5 → 2.0.0
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.
- package/README.md +234 -252
- package/dist/react-simple-formkit.js +4 -4
- package/dist/react-simple-formkit.mjs +439 -326
- package/dist/react-simple-formkit.umd.js +4 -4
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
var
|
|
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 X = { exports: {} }, $ = {};
|
|
|
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
|
|
13
|
-
function
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
function
|
|
18
|
-
var
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
for (var
|
|
22
|
-
|
|
23
|
-
} else
|
|
24
|
-
return
|
|
25
|
-
$$typeof:
|
|
26
|
-
type:
|
|
27
|
-
key:
|
|
28
|
-
ref:
|
|
29
|
-
props:
|
|
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
|
|
32
|
+
return Q.Fragment = u, Q.jsx = l, Q.jsxs = l, Q;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var K = {};
|
|
35
35
|
/**
|
|
36
36
|
* @license React
|
|
37
37
|
* react-jsx-runtime.development.js
|
|
@@ -41,125 +41,125 @@ var M = {};
|
|
|
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
|
|
45
|
-
function
|
|
46
|
-
return
|
|
47
|
-
function
|
|
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 ===
|
|
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
|
|
53
|
+
case x:
|
|
54
54
|
return "Fragment";
|
|
55
|
-
case
|
|
55
|
+
case Y:
|
|
56
56
|
return "Profiler";
|
|
57
|
-
case
|
|
57
|
+
case W:
|
|
58
58
|
return "StrictMode";
|
|
59
|
-
case
|
|
59
|
+
case re:
|
|
60
60
|
return "Suspense";
|
|
61
|
-
case
|
|
61
|
+
case te:
|
|
62
62
|
return "SuspenseList";
|
|
63
|
-
case
|
|
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
|
|
70
|
+
case D:
|
|
71
71
|
return "Portal";
|
|
72
|
-
case
|
|
72
|
+
case $:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
|
-
case
|
|
74
|
+
case B:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
|
-
case
|
|
77
|
-
var
|
|
78
|
-
return e = e.displayName, e || (e =
|
|
79
|
-
case
|
|
80
|
-
return
|
|
81
|
-
case
|
|
82
|
-
|
|
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
|
|
84
|
+
return s(e(o));
|
|
85
85
|
} catch {
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function u(e) {
|
|
91
91
|
return "" + e;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function l(e) {
|
|
94
94
|
try {
|
|
95
|
-
|
|
96
|
-
var
|
|
95
|
+
u(e);
|
|
96
|
+
var o = !1;
|
|
97
97
|
} catch {
|
|
98
|
-
|
|
98
|
+
o = !0;
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
return
|
|
104
|
-
|
|
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
|
-
|
|
107
|
-
),
|
|
106
|
+
b
|
|
107
|
+
), u(e);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
if (e ===
|
|
112
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
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
|
|
116
|
-
return
|
|
115
|
+
var o = s(e);
|
|
116
|
+
return o ? "<" + o + ">" : "<...>";
|
|
117
117
|
} catch {
|
|
118
118
|
return "<...>";
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
var e =
|
|
121
|
+
function i() {
|
|
122
|
+
var e = U.A;
|
|
123
123
|
return e === null ? null : e.getOwner();
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function f() {
|
|
126
126
|
return Error("react-stack-top-frame");
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
if (
|
|
130
|
-
var
|
|
131
|
-
if (
|
|
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
|
|
136
|
-
function
|
|
137
|
-
|
|
135
|
+
function E(e, o) {
|
|
136
|
+
function c() {
|
|
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
|
-
|
|
139
|
+
o
|
|
140
140
|
));
|
|
141
141
|
}
|
|
142
|
-
|
|
143
|
-
get:
|
|
142
|
+
c.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
143
|
+
get: c,
|
|
144
144
|
configurable: !0
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
var e =
|
|
149
|
-
return
|
|
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
|
|
154
|
-
return
|
|
155
|
-
$$typeof:
|
|
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:
|
|
158
|
-
props:
|
|
159
|
-
_owner:
|
|
160
|
-
}, (
|
|
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:
|
|
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,307 +174,420 @@ function Ee() {
|
|
|
174
174
|
configurable: !1,
|
|
175
175
|
enumerable: !1,
|
|
176
176
|
writable: !0,
|
|
177
|
-
value:
|
|
177
|
+
value: z
|
|
178
178
|
}), Object.defineProperty(e, "_debugTask", {
|
|
179
179
|
configurable: !1,
|
|
180
180
|
enumerable: !1,
|
|
181
181
|
writable: !0,
|
|
182
|
-
value:
|
|
182
|
+
value: G
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
var
|
|
187
|
-
if (
|
|
188
|
-
if (
|
|
189
|
-
if (
|
|
190
|
-
for (
|
|
191
|
-
|
|
192
|
-
Object.freeze && Object.freeze(
|
|
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
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
var
|
|
201
|
-
return
|
|
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
|
-
|
|
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
|
+
b,
|
|
210
211
|
R,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
), S[v + R] = !0);
|
|
212
|
+
A,
|
|
213
|
+
R
|
|
214
|
+
), L[R + b] = !0);
|
|
215
215
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
for (var
|
|
219
|
-
|
|
220
|
-
} else
|
|
221
|
-
return
|
|
222
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
R,
|
|
227
|
+
T,
|
|
228
|
+
_,
|
|
229
|
+
i(),
|
|
230
|
+
c,
|
|
231
|
+
z,
|
|
232
|
+
G
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
236
|
-
typeof e == "object" && e !== null && e.$$typeof ===
|
|
235
|
+
function g(e) {
|
|
236
|
+
typeof e == "object" && e !== null && e.$$typeof === y && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
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
|
-
|
|
241
|
+
d = {
|
|
242
242
|
"react-stack-bottom-frame": function(e) {
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
)(),
|
|
250
|
-
|
|
251
|
-
var
|
|
252
|
-
return
|
|
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
|
+
return S(
|
|
253
253
|
e,
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
o,
|
|
255
|
+
c,
|
|
256
256
|
!1,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
b,
|
|
258
|
+
_,
|
|
259
|
+
T ? Error("react-stack-top-frame") : J,
|
|
260
|
+
T ? N(m(e)) : M
|
|
261
261
|
);
|
|
262
|
-
},
|
|
263
|
-
var
|
|
264
|
-
return
|
|
262
|
+
}, K.jsxs = function(e, o, c, b, _) {
|
|
263
|
+
var T = 1e4 > U.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return S(
|
|
265
265
|
e,
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
o,
|
|
267
|
+
c,
|
|
268
268
|
!0,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
b,
|
|
270
|
+
_,
|
|
271
|
+
T ? Error("react-stack-top-frame") : J,
|
|
272
|
+
T ? N(m(e)) : M
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
|
-
}()),
|
|
275
|
+
}()), K;
|
|
276
276
|
}
|
|
277
|
-
var
|
|
278
|
-
function
|
|
279
|
-
return
|
|
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
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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:
|
|
314
|
+
onInput: v = () => {
|
|
291
315
|
},
|
|
292
|
-
onChange:
|
|
316
|
+
onChange: E = () => {
|
|
293
317
|
},
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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:
|
|
301
|
-
ref:
|
|
302
|
-
action:
|
|
303
|
-
method:
|
|
304
|
-
className:
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
onInput: (b) => {
|
|
311
|
-
if (b.target.tagName === "FORM") {
|
|
312
|
-
const h = n.actions.loadFormValues();
|
|
313
|
-
n.actions.setFormState(h);
|
|
314
|
-
} else
|
|
315
|
-
E(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
|
|
319
|
-
|
|
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: (
|
|
322
|
-
|
|
341
|
+
onReset: (d) => {
|
|
342
|
+
u.actions.reset(), O(d);
|
|
323
343
|
},
|
|
324
|
-
...
|
|
325
|
-
children:
|
|
344
|
+
...g,
|
|
345
|
+
children: i
|
|
326
346
|
},
|
|
327
|
-
|
|
328
|
-
) })),
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
[
|
|
358
|
+
[l.setValue]
|
|
334
359
|
);
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
(
|
|
391
|
-
|
|
392
|
-
|
|
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);
|
|
393
456
|
},
|
|
394
|
-
[
|
|
395
|
-
),
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
case "object":
|
|
408
|
-
Object.entries(t).forEach(([r, s]) => {
|
|
409
|
-
const R = e[r];
|
|
410
|
-
if (!R)
|
|
411
|
-
throw new Error(`${r} is uncontrolled, please use Controller for it!`);
|
|
412
|
-
R(s, { shouldDirty: m, shouldOnChange: S });
|
|
413
|
-
}), S && j();
|
|
414
|
-
default:
|
|
415
|
-
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;
|
|
416
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);
|
|
417
492
|
},
|
|
418
|
-
[
|
|
419
|
-
),
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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(
|
|
425
524
|
() => ({
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
registerOnchange: q,
|
|
439
|
-
reload: b,
|
|
440
|
-
reset: U,
|
|
441
|
-
watch: C
|
|
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
|
|
442
537
|
}),
|
|
443
538
|
[
|
|
444
|
-
|
|
445
|
-
j,
|
|
446
|
-
z,
|
|
447
|
-
A,
|
|
448
|
-
W,
|
|
449
|
-
a,
|
|
450
|
-
c,
|
|
451
|
-
l,
|
|
452
|
-
I,
|
|
453
|
-
J,
|
|
454
|
-
P,
|
|
455
|
-
q,
|
|
539
|
+
re,
|
|
456
540
|
b,
|
|
541
|
+
V,
|
|
542
|
+
M,
|
|
543
|
+
L,
|
|
544
|
+
e,
|
|
545
|
+
o,
|
|
457
546
|
U,
|
|
458
|
-
|
|
547
|
+
X,
|
|
548
|
+
ne,
|
|
549
|
+
c,
|
|
550
|
+
oe
|
|
459
551
|
]
|
|
460
|
-
)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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 };
|
|
465
582
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}, [T]), fe(() => {
|
|
470
|
-
w.current && [...w.current.querySelectorAll("[name]")].forEach((i) => {
|
|
471
|
-
!i.defaultValue && n[i.name] && (i.defaultValue = n[i.name]);
|
|
472
|
-
});
|
|
473
|
-
}, [T]), { ref: w, lastReloadedAt: T, isDirty: d, isError: f, errors: u, numberFields: o, subscribe: B, actions: G };
|
|
583
|
+
}, [f]), Se(() => {
|
|
584
|
+
ee();
|
|
585
|
+
}, []), le;
|
|
474
586
|
};
|
|
475
587
|
export {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
588
|
+
Ue as Controller,
|
|
589
|
+
Le as Form,
|
|
590
|
+
Ne as useController,
|
|
591
|
+
qe as useForm,
|
|
592
|
+
Ve as useWatch
|
|
480
593
|
};
|