cross-state 1.9.6 → 1.9.7
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/dist/{diff-Bcr0h7-x.d.cts → diff-BzE2cDaU.d.cts} +2 -2
- package/dist/{diff-CwiTYAVK.d.ts → diff-Cvc-z20n.d.ts} +2 -2
- package/dist/{extendedJson-DA3RQ_ly.js → extendedJson-BOmrkRrD.js} +2 -2
- package/dist/{extendedJson-DA3RQ_ly.js.map → extendedJson-BOmrkRrD.js.map} +1 -1
- package/dist/{extendedJson-DzXMFE1P.cjs → extendedJson-pbOLcymB.cjs} +2 -2
- package/dist/{extendedJson-DzXMFE1P.cjs.map → extendedJson-pbOLcymB.cjs.map} +1 -1
- package/dist/index.cjs +9 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/mutative/index.cjs +2 -1
- package/dist/mutative/index.d.cts +1 -1
- package/dist/mutative/index.d.ts +1 -1
- package/dist/mutative/index.js +1 -1
- package/dist/mutative/register.cjs +2 -2
- package/dist/mutative/register.cjs.map +1 -1
- package/dist/mutative/register.d.cts +2 -2
- package/dist/mutative/register.d.ts +2 -2
- package/dist/mutative/register.js +2 -2
- package/dist/mutative/register.js.map +1 -1
- package/dist/{mutativeMethods-CwDMtUNs.cjs → mutativeMethods-AiKkraqx.cjs} +1 -1
- package/dist/mutativeMethods-AiKkraqx.cjs.map +1 -0
- package/dist/{mutativeMethods-Do8JiJ5A.d.cts → mutativeMethods-BHPlSHBi.d.cts} +2 -2
- package/dist/{mutativeMethods-t67Kp1uA.d.ts → mutativeMethods-COQxFB3B.d.ts} +2 -2
- package/dist/{mutativeMethods-BrDU8SwY.js → mutativeMethods-qVJ36MY5.js} +1 -1
- package/dist/mutativeMethods-qVJ36MY5.js.map +1 -0
- package/dist/{patchMethods-C21iQqML.d.ts → patchMethods--ekCkYUF.d.ts} +4 -4
- package/dist/{patchMethods-CZje49Dk.cjs → patchMethods-BBQDDqwe.cjs} +9 -9
- package/dist/patchMethods-BBQDDqwe.cjs.map +1 -0
- package/dist/{patchMethods-Cui462lc.js → patchMethods-D3cdG80W.js} +9 -9
- package/dist/patchMethods-D3cdG80W.js.map +1 -0
- package/dist/{patchMethods-Cyb6MEOG.d.cts → patchMethods-R3f7HxTy.d.cts} +4 -4
- package/dist/patches/index.cjs +2 -1
- package/dist/patches/index.d.cts +1 -1
- package/dist/patches/index.d.ts +1 -1
- package/dist/patches/index.js +1 -1
- package/dist/patches/register.cjs +2 -2
- package/dist/patches/register.cjs.map +1 -1
- package/dist/patches/register.d.cts +2 -2
- package/dist/patches/register.d.ts +2 -2
- package/dist/patches/register.js +2 -2
- package/dist/patches/register.js.map +1 -1
- package/dist/{path-Il5r4PV4.cjs → path-B9-Z0127.cjs} +1 -1
- package/dist/{path-Il5r4PV4.cjs.map → path-B9-Z0127.cjs.map} +1 -1
- package/dist/{path-CCEtQjMB.js → path-C-5jTZu5.js} +1 -1
- package/dist/{path-CCEtQjMB.js.map → path-C-5jTZu5.js.map} +1 -1
- package/dist/persist/register.cjs +2 -2
- package/dist/persist/register.cjs.map +1 -1
- package/dist/persist/register.d.cts +2 -2
- package/dist/persist/register.d.ts +2 -2
- package/dist/persist/register.js +2 -2
- package/dist/persist/register.js.map +1 -1
- package/dist/{persist-CG1WHP6D.cjs → persist-B341lrOA.cjs} +43 -45
- package/dist/persist-B341lrOA.cjs.map +1 -0
- package/dist/{persist-CkZ7CzW8.d.cts → persist-CoSWtRt0.d.cts} +3 -3
- package/dist/{persist-3Nff6j1f.d.ts → persist-XVT4fROX.d.ts} +3 -3
- package/dist/{persist-CNA2sYtB.js → persist-xv73m7UR.js} +43 -45
- package/dist/persist-xv73m7UR.js.map +1 -0
- package/dist/{propAccess-BxCKNeOj.js → propAccess-CsUaG5V_.js} +8 -8
- package/dist/propAccess-CsUaG5V_.js.map +1 -0
- package/dist/{propAccess-udIdjqwY.cjs → propAccess-DdLF12Jq.cjs} +8 -8
- package/dist/propAccess-DdLF12Jq.cjs.map +1 -0
- package/dist/react/index.cjs +118 -117
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +98 -98
- package/dist/react/index.d.ts +97 -97
- package/dist/react/index.js +119 -119
- package/dist/react/index.js.map +1 -1
- package/dist/react/register.cjs +3 -3
- package/dist/react/register.cjs.map +1 -1
- package/dist/react/register.d.cts +2 -2
- package/dist/react/register.d.ts +2 -2
- package/dist/react/register.js +3 -3
- package/dist/react/register.js.map +1 -1
- package/dist/{scope-DkX72a-2.cjs → scope-8MUrzqlS.cjs} +60 -60
- package/dist/scope-8MUrzqlS.cjs.map +1 -0
- package/dist/{scope-8uUaV6I8.d.cts → scope-BQjncWGt.d.cts} +25 -25
- package/dist/{scope-CQE3HDNI.js → scope-BfaweXvz.js} +61 -61
- package/dist/scope-BfaweXvz.js.map +1 -0
- package/dist/{scope-qdOAlRWQ.d.ts → scope-BztVo2P8.d.ts} +25 -25
- package/dist/{store-D4q5zD7q.js → store-BmlnyYal.js} +81 -81
- package/dist/store-BmlnyYal.js.map +1 -0
- package/dist/{store-Cq1PqvEo.d.ts → store-dThvqc0k.d.cts} +55 -55
- package/dist/{store-21GsOOLS.d.cts → store-dThvqc0k.d.ts} +55 -55
- package/dist/{store-CPqOf4y5.cjs → store-fmAYV5hy.cjs} +80 -80
- package/dist/store-fmAYV5hy.cjs.map +1 -0
- package/dist/{storeMethods-BjuI0joo.d.cts → storeMethods-CYX3AAnA.d.ts} +4 -4
- package/dist/{storeMethods-BZb4k7Ma.cjs → storeMethods-DYgUGHSk.cjs} +14 -14
- package/dist/storeMethods-DYgUGHSk.cjs.map +1 -0
- package/dist/{storeMethods-CK9-Q17H.d.ts → storeMethods-DrMQ7hqX.d.cts} +4 -4
- package/dist/{storeMethods-CWeGkXoz.js → storeMethods-pGlt0zfb.js} +14 -14
- package/dist/storeMethods-pGlt0zfb.js.map +1 -0
- package/package.json +46 -63
- package/dist/mutativeMethods-BrDU8SwY.js.map +0 -1
- package/dist/mutativeMethods-CwDMtUNs.cjs.map +0 -1
- package/dist/patchMethods-CZje49Dk.cjs.map +0 -1
- package/dist/patchMethods-Cui462lc.js.map +0 -1
- package/dist/persist-CG1WHP6D.cjs.map +0 -1
- package/dist/persist-CNA2sYtB.js.map +0 -1
- package/dist/propAccess-BxCKNeOj.js.map +0 -1
- package/dist/propAccess-udIdjqwY.cjs.map +0 -1
- package/dist/scope-CQE3HDNI.js.map +0 -1
- package/dist/scope-DkX72a-2.cjs.map +0 -1
- package/dist/store-CPqOf4y5.cjs.map +0 -1
- package/dist/store-D4q5zD7q.js.map +0 -1
- package/dist/storeMethods-BZb4k7Ma.cjs.map +0 -1
- package/dist/storeMethods-CWeGkXoz.js.map +0 -1
package/dist/react/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_store = require('../store-fmAYV5hy.cjs');
|
|
3
|
+
const require_propAccess = require('../propAccess-DdLF12Jq.cjs');
|
|
4
|
+
const require_extendedJson = require('../extendedJson-pbOLcymB.cjs');
|
|
5
|
+
const require_storeMethods = require('../storeMethods-DYgUGHSk.cjs');
|
|
5
6
|
let react = require("react");
|
|
6
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
8
|
let mutative = require("mutative");
|
|
@@ -29,96 +30,12 @@ function CustomInput({ name, children, ...props }) {
|
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region src/lib/wildcardMatch.ts
|
|
34
|
-
function getWildCardMatches(object, path) {
|
|
35
|
-
const matches = {};
|
|
36
|
-
const [first, second, ...rest] = require_propAccess.castArrayPath(path);
|
|
37
|
-
if (first === void 0) throw new Error("Path is empty");
|
|
38
|
-
if (!Array.isArray(object) && !require_propAccess.isObject(object)) object = {};
|
|
39
|
-
for (const [key, value] of first !== "*" ? [[first, object[first]]] : Object.entries(object)) {
|
|
40
|
-
if (first !== "*" && first !== key) continue;
|
|
41
|
-
if (second === void 0) {
|
|
42
|
-
matches[key] = value;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
for (const [subKey, subValue] of Object.entries(getWildCardMatches(value, [second, ...rest]))) matches[`${key}.${subKey}`] = subValue;
|
|
46
|
-
}
|
|
47
|
-
return matches;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/react/form/closestFormContext.tsx
|
|
52
|
-
const GeneralFormContext = (0, react.createContext)(null);
|
|
53
|
-
function useClosestForm() {
|
|
54
|
-
return (0, react.useContext)(GeneralFormContext);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/react/form/legacyFormField.tsx
|
|
59
|
-
function LegacyFormField({ name = "", component, commitOnBlur, commitDebounce, inputFilter, defaultValue, serialize, deserialize = (x) => x, onChange, onBlur, ...restProps }) {
|
|
60
|
-
const form = this.useForm();
|
|
61
|
-
const getFormState = () => ({
|
|
62
|
-
...form,
|
|
63
|
-
...getDerivedState(form)
|
|
64
|
-
});
|
|
65
|
-
const [localValue, setLocalValue] = (0, react.useState)();
|
|
66
|
-
const value = this.useFormState((form$1) => {
|
|
67
|
-
const value$1 = form$1.getField(name).value;
|
|
68
|
-
if (serialize) return serialize(value$1, getFormState());
|
|
69
|
-
if (value$1 !== void 0) return value$1;
|
|
70
|
-
return defaultValue;
|
|
71
|
-
});
|
|
72
|
-
const setValue = require_storeMethods.useLatestFunction((x) => form.getField(name).setValue(deserialize(x, getFormState())));
|
|
73
|
-
const hasTriggeredValidations = this.useFormState((form$1) => form$1.hasTriggeredValidations);
|
|
74
|
-
const commitDebounceMs = commitDebounce !== void 0 ? require_store.calcDuration(commitDebounce) : void 0;
|
|
75
|
-
(0, react.useEffect)(() => {
|
|
76
|
-
if (localValue === void 0 || commitDebounceMs === void 0 || commitDebounceMs <= 0) return;
|
|
77
|
-
const timeout = setTimeout(() => {
|
|
78
|
-
setValue(localValue);
|
|
79
|
-
setLocalValue(void 0);
|
|
80
|
-
}, commitDebounceMs);
|
|
81
|
-
return () => clearTimeout(timeout);
|
|
82
|
-
}, [
|
|
83
|
-
localValue,
|
|
84
|
-
commitDebounceMs,
|
|
85
|
-
setValue
|
|
86
|
-
]);
|
|
87
|
-
let props = {
|
|
88
|
-
name,
|
|
89
|
-
value: localValue ?? value,
|
|
90
|
-
onChange: (event, ...moreArgs) => {
|
|
91
|
-
const value$1 = typeof event === "object" && event !== null && "target" in event ? event.target.value : event;
|
|
92
|
-
if (inputFilter && !inputFilter(value$1)) return;
|
|
93
|
-
if (commitOnBlur || commitDebounce) setLocalValue(value$1);
|
|
94
|
-
else setValue(value$1);
|
|
95
|
-
onChange?.(event, ...moreArgs);
|
|
96
|
-
},
|
|
97
|
-
onBlur(...args) {
|
|
98
|
-
if (localValue !== void 0) {
|
|
99
|
-
setValue(localValue);
|
|
100
|
-
setLocalValue(void 0);
|
|
101
|
-
}
|
|
102
|
-
onBlur?.(...args);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
if (this.options.transformFieldProps) props = this.options.transformFieldProps(props, {
|
|
106
|
-
...form.getField(name),
|
|
107
|
-
hasTriggeredValidations
|
|
108
|
-
}, form);
|
|
109
|
-
if (component) return (0, react.createElement)(component, {
|
|
110
|
-
...restProps,
|
|
111
|
-
...props
|
|
112
|
-
});
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
33
|
//#endregion
|
|
117
34
|
//#region src/react/form/formField.tsx
|
|
118
|
-
function FormField({ name
|
|
35
|
+
function FormField({ name, commitOnBlur, commitDebounce, children, render = children, includeNestedErrors }) {
|
|
119
36
|
const form = this.useForm();
|
|
120
37
|
const field = this.useField(name);
|
|
121
|
-
const hasTriggeredValidations = this.useFormState((form
|
|
38
|
+
const hasTriggeredValidations = this.useFormState((form) => form.hasTriggeredValidations);
|
|
122
39
|
const renderProps = useFormFieldProps.call(this, {
|
|
123
40
|
name,
|
|
124
41
|
commitOnBlur,
|
|
@@ -131,10 +48,10 @@ function FormField({ name = "", commitOnBlur, commitDebounce, children, render =
|
|
|
131
48
|
}, form) });
|
|
132
49
|
return null;
|
|
133
50
|
}
|
|
134
|
-
function useFormFieldProps({ name
|
|
51
|
+
function useFormFieldProps({ name, commitOnBlur, commitDebounce, includeNestedErrors }) {
|
|
135
52
|
const form = this.useForm();
|
|
136
53
|
const field = this.useField(name, { includeNestedErrors });
|
|
137
|
-
const hasTriggeredValidations = this.useFormState((form
|
|
54
|
+
const hasTriggeredValidations = this.useFormState((form) => form.hasTriggeredValidations);
|
|
138
55
|
const [localValue, setLocalValue] = (0, react.useState)();
|
|
139
56
|
const commitDebounceMs = commitDebounce !== void 0 ? require_store.calcDuration(commitDebounce) : void 0;
|
|
140
57
|
const commitLocalValue = require_storeMethods.useLatestFunction(() => {
|
|
@@ -191,24 +108,24 @@ function FormForEach({ name, renderElement, renderAdditionalElement, filter, chi
|
|
|
191
108
|
const add = (0, react.useCallback)((...args) => {
|
|
192
109
|
form.getField(name).add(...args);
|
|
193
110
|
}, [form, name]);
|
|
194
|
-
const remove
|
|
111
|
+
const remove = (0, react.useCallback)((key) => {
|
|
195
112
|
form.getField(name).remove(key);
|
|
196
113
|
}, [form, name]);
|
|
197
114
|
const setValue = (0, react.useCallback)((value) => {
|
|
198
115
|
form.getField(name).setValue(value);
|
|
199
116
|
}, [form, name]);
|
|
200
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderElement && items.map(({ key, name
|
|
117
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderElement && items.map(({ key, name }, index) => {
|
|
201
118
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderElement({
|
|
202
|
-
name
|
|
119
|
+
name,
|
|
203
120
|
key,
|
|
204
121
|
index,
|
|
205
|
-
remove: () => remove
|
|
122
|
+
remove: () => remove(key),
|
|
206
123
|
count: items.length
|
|
207
124
|
}) }, key);
|
|
208
125
|
}), children?.({
|
|
209
126
|
names: items.map((item) => item.name),
|
|
210
127
|
add,
|
|
211
|
-
remove
|
|
128
|
+
remove,
|
|
212
129
|
setValue
|
|
213
130
|
})] });
|
|
214
131
|
}
|
|
@@ -304,9 +221,93 @@ function useFormAutosave(form) {
|
|
|
304
221
|
};
|
|
305
222
|
}
|
|
306
223
|
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/lib/wildcardMatch.ts
|
|
226
|
+
function getWildCardMatches(object, path) {
|
|
227
|
+
const matches = {};
|
|
228
|
+
const [first, second, ...rest] = require_propAccess.castArrayPath(path);
|
|
229
|
+
if (first === void 0) throw new Error("Path is empty");
|
|
230
|
+
if (!Array.isArray(object) && !require_propAccess.isObject(object)) object = {};
|
|
231
|
+
for (const [key, value] of first !== "*" ? [[first, object[first]]] : Object.entries(object)) {
|
|
232
|
+
if (first !== "*" && first !== key) continue;
|
|
233
|
+
if (second === void 0) {
|
|
234
|
+
matches[key] = value;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
for (const [subKey, subValue] of Object.entries(getWildCardMatches(value, [second, ...rest]))) matches[`${key}.${subKey}`] = subValue;
|
|
238
|
+
}
|
|
239
|
+
return matches;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/react/form/closestFormContext.tsx
|
|
244
|
+
const GeneralFormContext = (0, react.createContext)(null);
|
|
245
|
+
function useClosestForm() {
|
|
246
|
+
return (0, react.useContext)(GeneralFormContext);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/react/form/legacyFormField.tsx
|
|
251
|
+
function LegacyFormField({ name, component, commitOnBlur, commitDebounce, inputFilter, defaultValue, serialize, deserialize = (x) => x, onChange, onBlur, ...restProps }) {
|
|
252
|
+
const form = this.useForm();
|
|
253
|
+
const getFormState = () => ({
|
|
254
|
+
...form,
|
|
255
|
+
...getDerivedState(form)
|
|
256
|
+
});
|
|
257
|
+
const [localValue, setLocalValue] = (0, react.useState)();
|
|
258
|
+
const value = this.useFormState((form) => {
|
|
259
|
+
const value = form.getField(name).value;
|
|
260
|
+
if (serialize) return serialize(value, getFormState());
|
|
261
|
+
if (value !== void 0) return value;
|
|
262
|
+
return defaultValue;
|
|
263
|
+
});
|
|
264
|
+
const setValue = require_storeMethods.useLatestFunction((x) => form.getField(name).setValue(deserialize(x, getFormState())));
|
|
265
|
+
const hasTriggeredValidations = this.useFormState((form) => form.hasTriggeredValidations);
|
|
266
|
+
const commitDebounceMs = commitDebounce !== void 0 ? require_store.calcDuration(commitDebounce) : void 0;
|
|
267
|
+
(0, react.useEffect)(() => {
|
|
268
|
+
if (localValue === void 0 || commitDebounceMs === void 0 || commitDebounceMs <= 0) return;
|
|
269
|
+
const timeout = setTimeout(() => {
|
|
270
|
+
setValue(localValue);
|
|
271
|
+
setLocalValue(void 0);
|
|
272
|
+
}, commitDebounceMs);
|
|
273
|
+
return () => clearTimeout(timeout);
|
|
274
|
+
}, [
|
|
275
|
+
localValue,
|
|
276
|
+
commitDebounceMs,
|
|
277
|
+
setValue
|
|
278
|
+
]);
|
|
279
|
+
let props = {
|
|
280
|
+
name,
|
|
281
|
+
value: localValue ?? value,
|
|
282
|
+
onChange: (event, ...moreArgs) => {
|
|
283
|
+
const value = typeof event === "object" && event !== null && "target" in event ? event.target.value : event;
|
|
284
|
+
if (inputFilter && !inputFilter(value)) return;
|
|
285
|
+
if (commitOnBlur || commitDebounce) setLocalValue(value);
|
|
286
|
+
else setValue(value);
|
|
287
|
+
onChange?.(event, ...moreArgs);
|
|
288
|
+
},
|
|
289
|
+
onBlur(...args) {
|
|
290
|
+
if (localValue !== void 0) {
|
|
291
|
+
setValue(localValue);
|
|
292
|
+
setLocalValue(void 0);
|
|
293
|
+
}
|
|
294
|
+
onBlur?.(...args);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
if (this.options.transformFieldProps) props = this.options.transformFieldProps(props, {
|
|
298
|
+
...form.getField(name),
|
|
299
|
+
hasTriggeredValidations
|
|
300
|
+
}, form);
|
|
301
|
+
if (component) return (0, react.createElement)(component, {
|
|
302
|
+
...restProps,
|
|
303
|
+
...props
|
|
304
|
+
});
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
|
|
307
308
|
//#endregion
|
|
308
309
|
//#region src/react/form/form.tsx
|
|
309
|
-
const FormContainer = (0, react.forwardRef)(function FormContainer
|
|
310
|
+
const FormContainer = (0, react.forwardRef)(function FormContainer({ form, ...formProps }, ref) {
|
|
310
311
|
const formInstance = form.useForm();
|
|
311
312
|
const hasTriggeredValidations = form.useFormState((state) => state.hasTriggeredValidations);
|
|
312
313
|
const hasErrors = form.useFormState((state) => hasTriggeredValidations && state.errors.size > 0);
|
|
@@ -455,7 +456,7 @@ var Form = class Form {
|
|
|
455
456
|
}
|
|
456
457
|
useField(name, { includeNestedErrors, ...useStoreOptions } = {}) {
|
|
457
458
|
const form = this.useForm();
|
|
458
|
-
this.useFormState((form
|
|
459
|
+
this.useFormState((form) => [form.getField(name).value, form.original], useStoreOptions);
|
|
459
460
|
return form.getField(name, { includeNestedErrors });
|
|
460
461
|
}
|
|
461
462
|
useFieldProps(name, options) {
|
|
@@ -471,7 +472,7 @@ var Form = class Form {
|
|
|
471
472
|
...defaultValue
|
|
472
473
|
},
|
|
473
474
|
validations: typeof validations === "function" ? validations : validations ? {
|
|
474
|
-
...this.options.validations,
|
|
475
|
+
...typeof this.options.validations === "function" ? void 0 : this.options.validations,
|
|
475
476
|
...validations
|
|
476
477
|
} : this.options.validations,
|
|
477
478
|
localizeError: localizeError ?? this.options.localizeError,
|
|
@@ -540,10 +541,10 @@ var Form = class Form {
|
|
|
540
541
|
isValid() {
|
|
541
542
|
return lazy("isValid", () => this.getErrors().size === 0);
|
|
542
543
|
},
|
|
543
|
-
validate({ reportValidity
|
|
544
|
+
validate({ reportValidity = options.reportValidity, button } = {}) {
|
|
544
545
|
formState.set("hasTriggeredValidations", true);
|
|
545
546
|
updateValidity(this.getErrors(), button);
|
|
546
|
-
switch (reportValidity
|
|
547
|
+
switch (reportValidity) {
|
|
547
548
|
case "browser":
|
|
548
549
|
formRef.current?.reportValidity();
|
|
549
550
|
break;
|
|
@@ -568,14 +569,14 @@ var Form = class Form {
|
|
|
568
569
|
formState.set("hasTriggeredValidations", false);
|
|
569
570
|
}
|
|
570
571
|
};
|
|
571
|
-
context.getField = (path, options
|
|
572
|
+
context.getField = (path, options) => lazy(`${path}:${options?.includeNestedErrors}`, () => getField(context, path, options));
|
|
572
573
|
(0, react.useEffect)(() => {
|
|
573
|
-
const transform
|
|
574
|
-
if (!transform
|
|
574
|
+
const transform = options.transform;
|
|
575
|
+
if (!transform) return;
|
|
575
576
|
return context.formState.subscribe((state, prev) => {
|
|
576
577
|
const value = state.draft ?? options.original ?? options.defaultValue;
|
|
577
578
|
const previousValue = prev?.draft ?? options.original ?? options.defaultValue;
|
|
578
|
-
const result = (0, mutative.create)(value, (draft) => transform
|
|
579
|
+
const result = (0, mutative.create)(value, (draft) => transform(draft, {
|
|
579
580
|
...context,
|
|
580
581
|
previousValue
|
|
581
582
|
}));
|
|
@@ -628,9 +629,9 @@ var Form = class Form {
|
|
|
628
629
|
return Reflect.apply(FormForEach, this, [props]);
|
|
629
630
|
}
|
|
630
631
|
withForm(Component, formProps) {
|
|
631
|
-
const { Form
|
|
632
|
+
const { Form } = this;
|
|
632
633
|
return function FormWrapper(props) {
|
|
633
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Form
|
|
634
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Form, {
|
|
634
635
|
...formProps,
|
|
635
636
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, { ...props })
|
|
636
637
|
});
|
|
@@ -810,24 +811,24 @@ function useDecoupledState(value, onChange, options = {}) {
|
|
|
810
811
|
const debounceOptions = require_storeMethods.useMemoEquals(options.debounce);
|
|
811
812
|
const throttleOptions = require_storeMethods.useMemoEquals(options.throttle);
|
|
812
813
|
const update = (0, react.useMemo)(() => {
|
|
813
|
-
const update
|
|
814
|
-
const result = latestOnChange(value
|
|
814
|
+
const update = async (value) => {
|
|
815
|
+
const result = latestOnChange(value);
|
|
815
816
|
if (require_store.isPromise(result)) {
|
|
816
817
|
const ac = onChangeAC.current = new AbortController();
|
|
817
818
|
await result;
|
|
818
819
|
if (ac.signal.aborted) return;
|
|
819
820
|
}
|
|
820
|
-
latestOnCommit(value
|
|
821
|
+
latestOnCommit(value);
|
|
821
822
|
setDirty(void 0);
|
|
822
823
|
};
|
|
823
824
|
let delayedUpdate;
|
|
824
|
-
if (debounceOptions) delayedUpdate = require_store.debounce(update
|
|
825
|
-
else if (throttleOptions) delayedUpdate = require_store.throttle(update
|
|
826
|
-
else delayedUpdate = (value
|
|
827
|
-
return (value
|
|
825
|
+
if (debounceOptions) delayedUpdate = require_store.debounce(update, debounceOptions);
|
|
826
|
+
else if (throttleOptions) delayedUpdate = require_store.throttle(update, throttleOptions);
|
|
827
|
+
else delayedUpdate = (value) => (0, react.startTransition)(() => update(value));
|
|
828
|
+
return (value) => {
|
|
828
829
|
onChangeAC.current?.abort();
|
|
829
|
-
setDirty({ v: value
|
|
830
|
-
delayedUpdate(value
|
|
830
|
+
setDirty({ v: value });
|
|
831
|
+
delayedUpdate(value);
|
|
831
832
|
};
|
|
832
833
|
}, [
|
|
833
834
|
latestOnChange,
|