cross-state 1.9.5 → 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 +10 -9
- 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 +9 -9
- 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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as set, c as deepEqual, i as remove, n as get, o as isObject, r as join, t as castArrayPath } from "../propAccess-
|
|
3
|
-
import { a as diff, i as toExtendedJsonString, n as fromExtendedJsonString } from "../extendedJson-
|
|
4
|
-
import { a as useProp, c as useCache, d as useStore, f as useMemoEquals, i as useScope, l as LoadingBoundary, n as scopeMethods, o as useLatestFunction, r as ScopeProvider, s as cacheMethods, t as storeMethods, u as useLoadingBoundary } from "../storeMethods-
|
|
1
|
+
import { f as queue, h as autobind, l as debounce, m as isPromise, n as createStore, r as throttle, t as Store, u as calcDuration } from "../store-BmlnyYal.js";
|
|
2
|
+
import { a as set, c as deepEqual, i as remove, n as get, o as isObject, r as join, t as castArrayPath } from "../propAccess-CsUaG5V_.js";
|
|
3
|
+
import { a as diff, i as toExtendedJsonString, n as fromExtendedJsonString } from "../extendedJson-BOmrkRrD.js";
|
|
4
|
+
import { a as useProp, c as useCache, d as useStore, f as useMemoEquals, i as useScope, l as LoadingBoundary, n as scopeMethods, o as useLatestFunction, r as ScopeProvider, s as cacheMethods, t as storeMethods, u as useLoadingBoundary } from "../storeMethods-pGlt0zfb.js";
|
|
5
5
|
import { Fragment, createContext, createElement, forwardRef, startTransition, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { create } from "mutative";
|
|
@@ -29,96 +29,12 @@ function CustomInput({ name, children, ...props }) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region src/lib/wildcardMatch.ts
|
|
34
|
-
function getWildCardMatches(object, path) {
|
|
35
|
-
const matches = {};
|
|
36
|
-
const [first, second, ...rest] = castArrayPath(path);
|
|
37
|
-
if (first === void 0) throw new Error("Path is empty");
|
|
38
|
-
if (!Array.isArray(object) && !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 = createContext(null);
|
|
53
|
-
function useClosestForm() {
|
|
54
|
-
return 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] = 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 = 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 ? calcDuration(commitDebounce) : void 0;
|
|
75
|
-
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 createElement(component, {
|
|
110
|
-
...restProps,
|
|
111
|
-
...props
|
|
112
|
-
});
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
32
|
//#endregion
|
|
117
33
|
//#region src/react/form/formField.tsx
|
|
118
|
-
function FormField({ name
|
|
34
|
+
function FormField({ name, commitOnBlur, commitDebounce, children, render = children, includeNestedErrors }) {
|
|
119
35
|
const form = this.useForm();
|
|
120
36
|
const field = this.useField(name);
|
|
121
|
-
const hasTriggeredValidations = this.useFormState((form
|
|
37
|
+
const hasTriggeredValidations = this.useFormState((form) => form.hasTriggeredValidations);
|
|
122
38
|
const renderProps = useFormFieldProps.call(this, {
|
|
123
39
|
name,
|
|
124
40
|
commitOnBlur,
|
|
@@ -131,10 +47,10 @@ function FormField({ name = "", commitOnBlur, commitDebounce, children, render =
|
|
|
131
47
|
}, form) });
|
|
132
48
|
return null;
|
|
133
49
|
}
|
|
134
|
-
function useFormFieldProps({ name
|
|
50
|
+
function useFormFieldProps({ name, commitOnBlur, commitDebounce, includeNestedErrors }) {
|
|
135
51
|
const form = this.useForm();
|
|
136
52
|
const field = this.useField(name, { includeNestedErrors });
|
|
137
|
-
const hasTriggeredValidations = this.useFormState((form
|
|
53
|
+
const hasTriggeredValidations = this.useFormState((form) => form.hasTriggeredValidations);
|
|
138
54
|
const [localValue, setLocalValue] = useState();
|
|
139
55
|
const commitDebounceMs = commitDebounce !== void 0 ? calcDuration(commitDebounce) : void 0;
|
|
140
56
|
const commitLocalValue = useLatestFunction(() => {
|
|
@@ -191,24 +107,24 @@ function FormForEach({ name, renderElement, renderAdditionalElement, filter, chi
|
|
|
191
107
|
const add = useCallback((...args) => {
|
|
192
108
|
form.getField(name).add(...args);
|
|
193
109
|
}, [form, name]);
|
|
194
|
-
const remove
|
|
110
|
+
const remove = useCallback((key) => {
|
|
195
111
|
form.getField(name).remove(key);
|
|
196
112
|
}, [form, name]);
|
|
197
113
|
const setValue = useCallback((value) => {
|
|
198
114
|
form.getField(name).setValue(value);
|
|
199
115
|
}, [form, name]);
|
|
200
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [renderElement && items.map(({ key, name
|
|
116
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [renderElement && items.map(({ key, name }, index) => {
|
|
201
117
|
return /* @__PURE__ */ jsx(Fragment, { children: renderElement({
|
|
202
|
-
name
|
|
118
|
+
name,
|
|
203
119
|
key,
|
|
204
120
|
index,
|
|
205
|
-
remove: () => remove
|
|
121
|
+
remove: () => remove(key),
|
|
206
122
|
count: items.length
|
|
207
123
|
}) }, key);
|
|
208
124
|
}), children?.({
|
|
209
125
|
names: items.map((item) => item.name),
|
|
210
126
|
add,
|
|
211
|
-
remove
|
|
127
|
+
remove,
|
|
212
128
|
setValue
|
|
213
129
|
})] });
|
|
214
130
|
}
|
|
@@ -304,9 +220,93 @@ function useFormAutosave(form) {
|
|
|
304
220
|
};
|
|
305
221
|
}
|
|
306
222
|
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/lib/wildcardMatch.ts
|
|
225
|
+
function getWildCardMatches(object, path) {
|
|
226
|
+
const matches = {};
|
|
227
|
+
const [first, second, ...rest] = castArrayPath(path);
|
|
228
|
+
if (first === void 0) throw new Error("Path is empty");
|
|
229
|
+
if (!Array.isArray(object) && !isObject(object)) object = {};
|
|
230
|
+
for (const [key, value] of first !== "*" ? [[first, object[first]]] : Object.entries(object)) {
|
|
231
|
+
if (first !== "*" && first !== key) continue;
|
|
232
|
+
if (second === void 0) {
|
|
233
|
+
matches[key] = value;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
for (const [subKey, subValue] of Object.entries(getWildCardMatches(value, [second, ...rest]))) matches[`${key}.${subKey}`] = subValue;
|
|
237
|
+
}
|
|
238
|
+
return matches;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/react/form/closestFormContext.tsx
|
|
243
|
+
const GeneralFormContext = createContext(null);
|
|
244
|
+
function useClosestForm() {
|
|
245
|
+
return useContext(GeneralFormContext);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/react/form/legacyFormField.tsx
|
|
250
|
+
function LegacyFormField({ name, component, commitOnBlur, commitDebounce, inputFilter, defaultValue, serialize, deserialize = (x) => x, onChange, onBlur, ...restProps }) {
|
|
251
|
+
const form = this.useForm();
|
|
252
|
+
const getFormState = () => ({
|
|
253
|
+
...form,
|
|
254
|
+
...getDerivedState(form)
|
|
255
|
+
});
|
|
256
|
+
const [localValue, setLocalValue] = useState();
|
|
257
|
+
const value = this.useFormState((form) => {
|
|
258
|
+
const value = form.getField(name).value;
|
|
259
|
+
if (serialize) return serialize(value, getFormState());
|
|
260
|
+
if (value !== void 0) return value;
|
|
261
|
+
return defaultValue;
|
|
262
|
+
});
|
|
263
|
+
const setValue = useLatestFunction((x) => form.getField(name).setValue(deserialize(x, getFormState())));
|
|
264
|
+
const hasTriggeredValidations = this.useFormState((form) => form.hasTriggeredValidations);
|
|
265
|
+
const commitDebounceMs = commitDebounce !== void 0 ? calcDuration(commitDebounce) : void 0;
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
if (localValue === void 0 || commitDebounceMs === void 0 || commitDebounceMs <= 0) return;
|
|
268
|
+
const timeout = setTimeout(() => {
|
|
269
|
+
setValue(localValue);
|
|
270
|
+
setLocalValue(void 0);
|
|
271
|
+
}, commitDebounceMs);
|
|
272
|
+
return () => clearTimeout(timeout);
|
|
273
|
+
}, [
|
|
274
|
+
localValue,
|
|
275
|
+
commitDebounceMs,
|
|
276
|
+
setValue
|
|
277
|
+
]);
|
|
278
|
+
let props = {
|
|
279
|
+
name,
|
|
280
|
+
value: localValue ?? value,
|
|
281
|
+
onChange: (event, ...moreArgs) => {
|
|
282
|
+
const value = typeof event === "object" && event !== null && "target" in event ? event.target.value : event;
|
|
283
|
+
if (inputFilter && !inputFilter(value)) return;
|
|
284
|
+
if (commitOnBlur || commitDebounce) setLocalValue(value);
|
|
285
|
+
else setValue(value);
|
|
286
|
+
onChange?.(event, ...moreArgs);
|
|
287
|
+
},
|
|
288
|
+
onBlur(...args) {
|
|
289
|
+
if (localValue !== void 0) {
|
|
290
|
+
setValue(localValue);
|
|
291
|
+
setLocalValue(void 0);
|
|
292
|
+
}
|
|
293
|
+
onBlur?.(...args);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
if (this.options.transformFieldProps) props = this.options.transformFieldProps(props, {
|
|
297
|
+
...form.getField(name),
|
|
298
|
+
hasTriggeredValidations
|
|
299
|
+
}, form);
|
|
300
|
+
if (component) return createElement(component, {
|
|
301
|
+
...restProps,
|
|
302
|
+
...props
|
|
303
|
+
});
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
307
|
//#endregion
|
|
308
308
|
//#region src/react/form/form.tsx
|
|
309
|
-
const FormContainer = forwardRef(function FormContainer
|
|
309
|
+
const FormContainer = forwardRef(function FormContainer({ form, ...formProps }, ref) {
|
|
310
310
|
const formInstance = form.useForm();
|
|
311
311
|
const hasTriggeredValidations = form.useFormState((state) => state.hasTriggeredValidations);
|
|
312
312
|
const hasErrors = form.useFormState((state) => hasTriggeredValidations && state.errors.size > 0);
|
|
@@ -455,7 +455,7 @@ var Form = class Form {
|
|
|
455
455
|
}
|
|
456
456
|
useField(name, { includeNestedErrors, ...useStoreOptions } = {}) {
|
|
457
457
|
const form = this.useForm();
|
|
458
|
-
this.useFormState((form
|
|
458
|
+
this.useFormState((form) => [form.getField(name).value, form.original], useStoreOptions);
|
|
459
459
|
return form.getField(name, { includeNestedErrors });
|
|
460
460
|
}
|
|
461
461
|
useFieldProps(name, options) {
|
|
@@ -471,7 +471,7 @@ var Form = class Form {
|
|
|
471
471
|
...defaultValue
|
|
472
472
|
},
|
|
473
473
|
validations: typeof validations === "function" ? validations : validations ? {
|
|
474
|
-
...this.options.validations,
|
|
474
|
+
...typeof this.options.validations === "function" ? void 0 : this.options.validations,
|
|
475
475
|
...validations
|
|
476
476
|
} : this.options.validations,
|
|
477
477
|
localizeError: localizeError ?? this.options.localizeError,
|
|
@@ -540,10 +540,10 @@ var Form = class Form {
|
|
|
540
540
|
isValid() {
|
|
541
541
|
return lazy("isValid", () => this.getErrors().size === 0);
|
|
542
542
|
},
|
|
543
|
-
validate({ reportValidity
|
|
543
|
+
validate({ reportValidity = options.reportValidity, button } = {}) {
|
|
544
544
|
formState.set("hasTriggeredValidations", true);
|
|
545
545
|
updateValidity(this.getErrors(), button);
|
|
546
|
-
switch (reportValidity
|
|
546
|
+
switch (reportValidity) {
|
|
547
547
|
case "browser":
|
|
548
548
|
formRef.current?.reportValidity();
|
|
549
549
|
break;
|
|
@@ -568,14 +568,14 @@ var Form = class Form {
|
|
|
568
568
|
formState.set("hasTriggeredValidations", false);
|
|
569
569
|
}
|
|
570
570
|
};
|
|
571
|
-
context.getField = (path, options
|
|
571
|
+
context.getField = (path, options) => lazy(`${path}:${options?.includeNestedErrors}`, () => getField(context, path, options));
|
|
572
572
|
useEffect(() => {
|
|
573
|
-
const transform
|
|
574
|
-
if (!transform
|
|
573
|
+
const transform = options.transform;
|
|
574
|
+
if (!transform) return;
|
|
575
575
|
return context.formState.subscribe((state, prev) => {
|
|
576
576
|
const value = state.draft ?? options.original ?? options.defaultValue;
|
|
577
577
|
const previousValue = prev?.draft ?? options.original ?? options.defaultValue;
|
|
578
|
-
const result = create(value, (draft) => transform
|
|
578
|
+
const result = create(value, (draft) => transform(draft, {
|
|
579
579
|
...context,
|
|
580
580
|
previousValue
|
|
581
581
|
}));
|
|
@@ -627,12 +627,12 @@ var Form = class Form {
|
|
|
627
627
|
ForEach(props) {
|
|
628
628
|
return Reflect.apply(FormForEach, this, [props]);
|
|
629
629
|
}
|
|
630
|
-
withForm(Component
|
|
631
|
-
const { Form
|
|
630
|
+
withForm(Component, formProps) {
|
|
631
|
+
const { Form } = this;
|
|
632
632
|
return function FormWrapper(props) {
|
|
633
|
-
return /* @__PURE__ */ jsx(Form
|
|
633
|
+
return /* @__PURE__ */ jsx(Form, {
|
|
634
634
|
...formProps,
|
|
635
|
-
children: /* @__PURE__ */ jsx(Component
|
|
635
|
+
children: /* @__PURE__ */ jsx(Component, { ...props })
|
|
636
636
|
});
|
|
637
637
|
};
|
|
638
638
|
}
|
|
@@ -810,24 +810,24 @@ function useDecoupledState(value, onChange, options = {}) {
|
|
|
810
810
|
const debounceOptions = useMemoEquals(options.debounce);
|
|
811
811
|
const throttleOptions = useMemoEquals(options.throttle);
|
|
812
812
|
const update = useMemo(() => {
|
|
813
|
-
const update
|
|
814
|
-
const result = latestOnChange(value
|
|
813
|
+
const update = async (value) => {
|
|
814
|
+
const result = latestOnChange(value);
|
|
815
815
|
if (isPromise(result)) {
|
|
816
816
|
const ac = onChangeAC.current = new AbortController();
|
|
817
817
|
await result;
|
|
818
818
|
if (ac.signal.aborted) return;
|
|
819
819
|
}
|
|
820
|
-
latestOnCommit(value
|
|
820
|
+
latestOnCommit(value);
|
|
821
821
|
setDirty(void 0);
|
|
822
822
|
};
|
|
823
823
|
let delayedUpdate;
|
|
824
|
-
if (debounceOptions) delayedUpdate = debounce(update
|
|
825
|
-
else if (throttleOptions) delayedUpdate = throttle(update
|
|
826
|
-
else delayedUpdate = (value
|
|
827
|
-
return (value
|
|
824
|
+
if (debounceOptions) delayedUpdate = debounce(update, debounceOptions);
|
|
825
|
+
else if (throttleOptions) delayedUpdate = throttle(update, throttleOptions);
|
|
826
|
+
else delayedUpdate = (value) => startTransition(() => update(value));
|
|
827
|
+
return (value) => {
|
|
828
828
|
onChangeAC.current?.abort();
|
|
829
|
-
setDirty({ v: value
|
|
830
|
-
delayedUpdate(value
|
|
829
|
+
setDirty({ v: value });
|
|
830
|
+
delayedUpdate(value);
|
|
831
831
|
};
|
|
832
832
|
}, [
|
|
833
833
|
latestOnChange,
|