formstand 0.22.0 → 0.23.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/CHANGELOG.md +227 -0
- package/dist/{chunk-BMXIZEI4.js → chunk-EQIS5IVH.js} +23 -12
- package/dist/chunk-EQIS5IVH.js.map +1 -0
- package/dist/{createForm-BJum0RBu.d.cts → createForm-BexUOCjZ.d.cts} +7 -3
- package/dist/{createForm-BJum0RBu.d.ts → createForm-BexUOCjZ.d.ts} +7 -3
- package/dist/devtools/index.cjs.map +1 -1
- package/dist/devtools/index.d.cts +3 -2
- package/dist/devtools/index.d.ts +3 -2
- package/dist/devtools/index.js +1 -1
- package/dist/index.cjs +164 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -4
- package/dist/index.d.ts +19 -4
- package/dist/index.js +145 -13
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/package.json +18 -18
- package/dist/chunk-BMXIZEI4.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-
|
|
2
|
-
export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-
|
|
1
|
+
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-BexUOCjZ.cjs';
|
|
2
|
+
export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-BexUOCjZ.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ChangeEvent, ReactNode } from 'react';
|
|
6
6
|
import { StoreApi } from 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
type PathSegment = string | number;
|
|
9
|
+
type ContainerKind = "array" | "record";
|
|
10
|
+
type ContainerKindAt = (prefix: string) => ContainerKind | null;
|
|
9
11
|
declare const parsePath: (path: string) => readonly PathSegment[];
|
|
10
12
|
declare const getAtPath: (obj: unknown, path: string) => unknown;
|
|
11
|
-
declare const setAtPath: <T>(obj: T, path: string, value: unknown) => T;
|
|
13
|
+
declare const setAtPath: <T>(obj: T, path: string, value: unknown, containerKindAt?: ContainerKindAt) => T;
|
|
12
14
|
|
|
13
15
|
type PersistStorage = Readonly<{
|
|
14
16
|
getItem: (key: string) => string | null;
|
|
@@ -173,6 +175,8 @@ type FieldArrayFormApi = Readonly<{
|
|
|
173
175
|
validateField?(path: string): FieldValidationResult;
|
|
174
176
|
setError?(path: string, errors: string | readonly string[]): void;
|
|
175
177
|
clearErrors?(path?: string): void;
|
|
178
|
+
setTouched?(path: string, touched?: boolean): void;
|
|
179
|
+
setValue?(path: string, value: unknown): void;
|
|
176
180
|
}>;
|
|
177
181
|
type FieldArrayEntry<TItem> = Readonly<{
|
|
178
182
|
id: string;
|
|
@@ -187,11 +191,21 @@ type UseFieldArrayReturn<TItem> = Readonly<{
|
|
|
187
191
|
firstError: string | undefined;
|
|
188
192
|
setError: (errors: string | readonly string[]) => void;
|
|
189
193
|
clearError: () => void;
|
|
194
|
+
touched: boolean;
|
|
195
|
+
dirty: boolean;
|
|
196
|
+
isValidating: boolean;
|
|
197
|
+
setTouched: (touched?: boolean) => void;
|
|
198
|
+
onBlur: () => void;
|
|
199
|
+
validate: () => FieldValidationResult;
|
|
190
200
|
push: (item: TItem) => void;
|
|
191
201
|
remove: (index: number) => void;
|
|
192
202
|
insert: (index: number, item: TItem) => void;
|
|
193
203
|
move: (from: number, to: number) => void;
|
|
194
204
|
swap: (a: number, b: number) => void;
|
|
205
|
+
replace: (items: readonly TItem[]) => void;
|
|
206
|
+
update: (index: number, item: TItem) => void;
|
|
207
|
+
prepend: (item: TItem) => void;
|
|
208
|
+
clear: () => void;
|
|
195
209
|
}>;
|
|
196
210
|
declare const inferredCallsOnly: unique symbol;
|
|
197
211
|
interface InferredTypeArg {
|
|
@@ -438,4 +452,5 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
438
452
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
439
453
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
440
454
|
|
|
441
|
-
export { ArrayFieldPath, ArrayItemOf,
|
|
455
|
+
export { ArrayFieldPath, ArrayItemOf, CheckboxField, CreateFormOptions, DateField, DefaultPathDepth, ErrorMap, FieldPath, FieldValidationResult, FieldValue, Form, FormState, InvalidSubmitHandler, NumberField, PathDepth, SelectField, SettledFieldValidationResult, TextField, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSelector, useFormSelectorShallow, useFormSteps, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useMaskedInput, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
|
456
|
+
export type { ArrayPathsOf, BoundUseField, BoundUseFieldArray, BoundUseFields, BoundUseFlag, BoundUseSelector, BoundUseVariantField, CheckboxFieldProps, CheckboxProps, DateFieldProps, DateInputProps, FieldArrayEntry, FieldArrayFormApi, FieldFormApi, FieldPathArg, FieldRef, FormActionHandler, FormActionOptions, FormActionStateHandler, FormContextApi, FormHooks, FormProviderProps, FormStateApi, FormStep, MaskedInputBinding, MaskedInputOptions, MaskedParse, NumberFieldProps, NumberInputBinding, NumberInputProps, ParsedDateText, ParsedNumberText, PathSegment, PathsAccepting, PathsOf, PersistHandle, PersistOptions, PersistStorage, SelectFieldOption, SelectFieldProps, SelectProps, SelectValueAt, StepStatus, TextFieldProps, TextInputProps, UnionValueAt, UseFieldArrayReturn, UseFieldOptions, UseFieldReturn, UseFieldsReturn, UseFormStepsReturn, VariantFieldPath, VariantFieldValue, VariantKeys };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-
|
|
2
|
-
export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-
|
|
1
|
+
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-BexUOCjZ.js';
|
|
2
|
+
export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-BexUOCjZ.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ChangeEvent, ReactNode } from 'react';
|
|
6
6
|
import { StoreApi } from 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
type PathSegment = string | number;
|
|
9
|
+
type ContainerKind = "array" | "record";
|
|
10
|
+
type ContainerKindAt = (prefix: string) => ContainerKind | null;
|
|
9
11
|
declare const parsePath: (path: string) => readonly PathSegment[];
|
|
10
12
|
declare const getAtPath: (obj: unknown, path: string) => unknown;
|
|
11
|
-
declare const setAtPath: <T>(obj: T, path: string, value: unknown) => T;
|
|
13
|
+
declare const setAtPath: <T>(obj: T, path: string, value: unknown, containerKindAt?: ContainerKindAt) => T;
|
|
12
14
|
|
|
13
15
|
type PersistStorage = Readonly<{
|
|
14
16
|
getItem: (key: string) => string | null;
|
|
@@ -173,6 +175,8 @@ type FieldArrayFormApi = Readonly<{
|
|
|
173
175
|
validateField?(path: string): FieldValidationResult;
|
|
174
176
|
setError?(path: string, errors: string | readonly string[]): void;
|
|
175
177
|
clearErrors?(path?: string): void;
|
|
178
|
+
setTouched?(path: string, touched?: boolean): void;
|
|
179
|
+
setValue?(path: string, value: unknown): void;
|
|
176
180
|
}>;
|
|
177
181
|
type FieldArrayEntry<TItem> = Readonly<{
|
|
178
182
|
id: string;
|
|
@@ -187,11 +191,21 @@ type UseFieldArrayReturn<TItem> = Readonly<{
|
|
|
187
191
|
firstError: string | undefined;
|
|
188
192
|
setError: (errors: string | readonly string[]) => void;
|
|
189
193
|
clearError: () => void;
|
|
194
|
+
touched: boolean;
|
|
195
|
+
dirty: boolean;
|
|
196
|
+
isValidating: boolean;
|
|
197
|
+
setTouched: (touched?: boolean) => void;
|
|
198
|
+
onBlur: () => void;
|
|
199
|
+
validate: () => FieldValidationResult;
|
|
190
200
|
push: (item: TItem) => void;
|
|
191
201
|
remove: (index: number) => void;
|
|
192
202
|
insert: (index: number, item: TItem) => void;
|
|
193
203
|
move: (from: number, to: number) => void;
|
|
194
204
|
swap: (a: number, b: number) => void;
|
|
205
|
+
replace: (items: readonly TItem[]) => void;
|
|
206
|
+
update: (index: number, item: TItem) => void;
|
|
207
|
+
prepend: (item: TItem) => void;
|
|
208
|
+
clear: () => void;
|
|
195
209
|
}>;
|
|
196
210
|
declare const inferredCallsOnly: unique symbol;
|
|
197
211
|
interface InferredTypeArg {
|
|
@@ -438,4 +452,5 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
438
452
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
439
453
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
440
454
|
|
|
441
|
-
export { ArrayFieldPath, ArrayItemOf,
|
|
455
|
+
export { ArrayFieldPath, ArrayItemOf, CheckboxField, CreateFormOptions, DateField, DefaultPathDepth, ErrorMap, FieldPath, FieldValidationResult, FieldValue, Form, FormState, InvalidSubmitHandler, NumberField, PathDepth, SelectField, SettledFieldValidationResult, TextField, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSelector, useFormSelectorShallow, useFormSteps, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useMaskedInput, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
|
456
|
+
export type { ArrayPathsOf, BoundUseField, BoundUseFieldArray, BoundUseFields, BoundUseFlag, BoundUseSelector, BoundUseVariantField, CheckboxFieldProps, CheckboxProps, DateFieldProps, DateInputProps, FieldArrayEntry, FieldArrayFormApi, FieldFormApi, FieldPathArg, FieldRef, FormActionHandler, FormActionOptions, FormActionStateHandler, FormContextApi, FormHooks, FormProviderProps, FormStateApi, FormStep, MaskedInputBinding, MaskedInputOptions, MaskedParse, NumberFieldProps, NumberInputBinding, NumberInputProps, ParsedDateText, ParsedNumberText, PathSegment, PathsAccepting, PathsOf, PersistHandle, PersistOptions, PersistStorage, SelectFieldOption, SelectFieldProps, SelectProps, SelectValueAt, StepStatus, TextFieldProps, TextInputProps, UnionValueAt, UseFieldArrayReturn, UseFieldOptions, UseFieldReturn, UseFieldsReturn, UseFormStepsReturn, VariantFieldPath, VariantFieldValue, VariantKeys };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isDevToolsBuild, getAtPath, isDevBuild, slotAtPath, setAtPath, isPlainObject, hasOwnSlot, valuesEqual, useFormSelectorShallow, isFieldDirty, useFormSelector, parsePath } from './chunk-
|
|
2
|
-
export { getAtPath, parsePath, setAtPath, useFormSelector, useFormSelectorShallow } from './chunk-
|
|
1
|
+
import { isDevToolsBuild, getAtPath, isDevBuild, slotAtPath, setAtPath, isPlainObject, hasOwnSlot, valuesEqual, useFormSelectorShallow, isFieldDirty, useFormSelector, parsePath } from './chunk-EQIS5IVH.js';
|
|
2
|
+
export { getAtPath, parsePath, setAtPath, useFormSelector, useFormSelectorShallow } from './chunk-EQIS5IVH.js';
|
|
3
3
|
import { flagAt, entryAt, shouldValidateOn } from './chunk-V3PDMTPP.js';
|
|
4
4
|
export { shouldValidateOn } from './chunk-V3PDMTPP.js';
|
|
5
5
|
import { createStore } from 'zustand/vanilla';
|
|
@@ -203,6 +203,9 @@ var fieldSchemaForIntrospection = (schema, path) => {
|
|
|
203
203
|
if (s instanceof z.ZodTuple && typeof segment === "number") {
|
|
204
204
|
return s.def.items[segment] ?? null;
|
|
205
205
|
}
|
|
206
|
+
if (s instanceof z.ZodRecord) {
|
|
207
|
+
return s.valueType;
|
|
208
|
+
}
|
|
206
209
|
if (s instanceof z.ZodDiscriminatedUnion || s instanceof z.ZodUnion) {
|
|
207
210
|
const options = s.def.options;
|
|
208
211
|
return options.reduce(
|
|
@@ -217,6 +220,22 @@ var fieldSchemaForIntrospection = (schema, path) => {
|
|
|
217
220
|
schema
|
|
218
221
|
);
|
|
219
222
|
};
|
|
223
|
+
var containerKindAt = (schema) => (prefix) => {
|
|
224
|
+
const sub = fieldSchemaForIntrospection(schema, prefix);
|
|
225
|
+
if (sub === null) return null;
|
|
226
|
+
const unwrapAll = (s) => {
|
|
227
|
+
const inner2 = unwrapForWalk(s);
|
|
228
|
+
return inner2 === null ? s : unwrapAll(inner2);
|
|
229
|
+
};
|
|
230
|
+
const inner = unwrapAll(sub);
|
|
231
|
+
if (inner instanceof z.ZodArray || inner instanceof z.ZodTuple) {
|
|
232
|
+
return "array";
|
|
233
|
+
}
|
|
234
|
+
if (inner instanceof z.ZodObject || inner instanceof z.ZodRecord) {
|
|
235
|
+
return "record";
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
};
|
|
220
239
|
var fieldSchemaAtPath = (schema, path) => parsePath(path).reduce((current, segment) => {
|
|
221
240
|
if (current === null || hasChecks(current)) return null;
|
|
222
241
|
if (current instanceof z.ZodObject && typeof segment === "string") {
|
|
@@ -320,6 +339,7 @@ var releaseChangedSlices = (server, prevValues, nextValues) => {
|
|
|
320
339
|
};
|
|
321
340
|
var createForm = (schema, options) => {
|
|
322
341
|
const initialMode = options.mode ?? "onBlur";
|
|
342
|
+
const kindAt = containerKindAt(schema);
|
|
323
343
|
const initialReValidateMode = options.reValidateMode ?? "onChange";
|
|
324
344
|
const initial = {
|
|
325
345
|
values: options.initialValues,
|
|
@@ -677,7 +697,7 @@ var createForm = (schema, options) => {
|
|
|
677
697
|
}
|
|
678
698
|
const arr = Array.isArray(current) ? current : [];
|
|
679
699
|
const next = nextArray(arr);
|
|
680
|
-
const written = setAtPath(store.getState().values, path, next);
|
|
700
|
+
const written = setAtPath(store.getState().values, path, next, kindAt);
|
|
681
701
|
clearArrayOpsUnder(store, path, true);
|
|
682
702
|
if (Array.isArray(current) && getAtPath(written, path) === next) {
|
|
683
703
|
recordArrayOp(store, path, {
|
|
@@ -839,7 +859,7 @@ var createForm = (schema, options) => {
|
|
|
839
859
|
clearArrayOpsUnder(store, path);
|
|
840
860
|
store.setState((state) => ({
|
|
841
861
|
...state,
|
|
842
|
-
values: setAtPath(state.values, path, value),
|
|
862
|
+
values: setAtPath(state.values, path, value, kindAt),
|
|
843
863
|
...errorChannels(state, {
|
|
844
864
|
serverErrors: releaseSpine(state.serverErrors, path)
|
|
845
865
|
})
|
|
@@ -986,7 +1006,7 @@ var createForm = (schema, options) => {
|
|
|
986
1006
|
}
|
|
987
1007
|
store.setState((state) => ({
|
|
988
1008
|
...state,
|
|
989
|
-
values: initialSlot.exists ? setAtPath(state.values, path, initialSlot.value) : state.values,
|
|
1009
|
+
values: initialSlot.exists ? setAtPath(state.values, path, initialSlot.value, kindAt) : state.values,
|
|
990
1010
|
// A runtime "" path scopes the whole form (the imperative surface is
|
|
991
1011
|
// string-typed even though FieldPath excludes ""). Server entries
|
|
992
1012
|
// follow the setValue release contract (releaseSpine).
|
|
@@ -1759,10 +1779,13 @@ var mappedIdState = (prev, mapping, liveItems) => {
|
|
|
1759
1779
|
};
|
|
1760
1780
|
var MAX_ID_PATHS = 4096;
|
|
1761
1781
|
var sharedIdEntries = /* @__PURE__ */ new WeakMap();
|
|
1762
|
-
var
|
|
1763
|
-
const
|
|
1764
|
-
const forStore =
|
|
1765
|
-
if (
|
|
1782
|
+
var storeIdEntries = (store) => {
|
|
1783
|
+
const existing = sharedIdEntries.get(store);
|
|
1784
|
+
const forStore = existing ?? { byPath: /* @__PURE__ */ new Map(), seq: 1 };
|
|
1785
|
+
if (existing === void 0) sharedIdEntries.set(store, forStore);
|
|
1786
|
+
return forStore;
|
|
1787
|
+
};
|
|
1788
|
+
var sharedIdEntry = (forStore, path) => {
|
|
1766
1789
|
const existing = forStore.byPath.get(path);
|
|
1767
1790
|
if (existing !== void 0) {
|
|
1768
1791
|
forStore.byPath.delete(path);
|
|
@@ -1792,12 +1815,40 @@ var walkOps = (start, items, ops) => {
|
|
|
1792
1815
|
}, start);
|
|
1793
1816
|
return walked.items === items ? walked : reconcileIds(walked, items);
|
|
1794
1817
|
};
|
|
1818
|
+
var reseatDescendants = (forStore, path, prev, next) => {
|
|
1819
|
+
if (prev.ids.length === 0) return;
|
|
1820
|
+
const newIndexById = new Map(next.ids.map((id, i) => [id, i]));
|
|
1821
|
+
const moves = prev.ids.map((id) => newIndexById.get(id));
|
|
1822
|
+
if (moves.every((to, from) => to === from)) return;
|
|
1823
|
+
const prefix = `${path}.`;
|
|
1824
|
+
const descendants = [...forStore.byPath.keys()].filter(
|
|
1825
|
+
(key) => key.startsWith(prefix)
|
|
1826
|
+
);
|
|
1827
|
+
const relocations = descendants.flatMap((key) => {
|
|
1828
|
+
const rest = key.slice(prefix.length);
|
|
1829
|
+
const dot = rest.indexOf(".");
|
|
1830
|
+
const segment = dot === -1 ? rest : rest.slice(0, dot);
|
|
1831
|
+
const from = Number(segment);
|
|
1832
|
+
if (!/^\d+$/.test(segment) || from >= prev.ids.length) return [];
|
|
1833
|
+
const entry = forStore.byPath.get(key);
|
|
1834
|
+
if (entry === void 0) return [];
|
|
1835
|
+
const to = moves[from];
|
|
1836
|
+
const target = to === void 0 ? void 0 : `${prefix}${to}${dot === -1 ? "" : rest.slice(dot)}`;
|
|
1837
|
+
return [{ key, target, entry }];
|
|
1838
|
+
});
|
|
1839
|
+
relocations.forEach(({ key }) => forStore.byPath.delete(key));
|
|
1840
|
+
relocations.forEach(({ target, entry }) => {
|
|
1841
|
+
if (target !== void 0) forStore.byPath.set(target, entry);
|
|
1842
|
+
});
|
|
1843
|
+
};
|
|
1795
1844
|
var deriveIds = (store, path, items) => {
|
|
1796
|
-
const
|
|
1845
|
+
const forStore = storeIdEntries(store);
|
|
1846
|
+
const entry = sharedIdEntry(forStore, path);
|
|
1797
1847
|
if (entry.state.items === items) return entry.state;
|
|
1798
1848
|
const ops = arrayOpsFor(store, path);
|
|
1799
1849
|
if (ops.length > 0) clearArrayOps(store, path);
|
|
1800
1850
|
const next = walkOps(entry.state, items, ops);
|
|
1851
|
+
reseatDescendants(forStore, path, entry.state, next);
|
|
1801
1852
|
entry.state = next;
|
|
1802
1853
|
return next;
|
|
1803
1854
|
};
|
|
@@ -1814,7 +1865,10 @@ function useFieldArray(form, pathArg) {
|
|
|
1814
1865
|
items: Array.isArray(value) ? value : EMPTY_ITEMS,
|
|
1815
1866
|
// Own-key read, like useField: an array named "constructor" must
|
|
1816
1867
|
// not read Object as its error list.
|
|
1817
|
-
error: entryAt(state.errors, path)
|
|
1868
|
+
error: entryAt(state.errors, path),
|
|
1869
|
+
touched: flagAt(state.touched, path),
|
|
1870
|
+
dirty: isFieldDirty(value, getAtPath(state.initialValues, path)),
|
|
1871
|
+
isValidating: flagAt(state.isValidating, path)
|
|
1818
1872
|
};
|
|
1819
1873
|
})
|
|
1820
1874
|
);
|
|
@@ -1883,6 +1937,52 @@ function useFieldArray(form, pathArg) {
|
|
|
1883
1937
|
[form, path]
|
|
1884
1938
|
);
|
|
1885
1939
|
const clearError = useCallback(() => form.clearErrors?.(path), [form, path]);
|
|
1940
|
+
const setTouched = useCallback(
|
|
1941
|
+
(touched) => form.setTouched?.(path, touched),
|
|
1942
|
+
[form, path]
|
|
1943
|
+
);
|
|
1944
|
+
const onBlur = useCallback(() => {
|
|
1945
|
+
form.setTouched?.(path, true);
|
|
1946
|
+
const state = form.store.getState();
|
|
1947
|
+
if (shouldValidateOn(
|
|
1948
|
+
"blur",
|
|
1949
|
+
state.mode,
|
|
1950
|
+
state.reValidateMode,
|
|
1951
|
+
state.submitCount > 0,
|
|
1952
|
+
true
|
|
1953
|
+
)) {
|
|
1954
|
+
form.validateField?.(path);
|
|
1955
|
+
}
|
|
1956
|
+
}, [form, path]);
|
|
1957
|
+
const validate = useCallback(
|
|
1958
|
+
() => form.validateField?.(path) ?? { kind: "valid" },
|
|
1959
|
+
[form, path]
|
|
1960
|
+
);
|
|
1961
|
+
const replace = useCallback(
|
|
1962
|
+
(next) => {
|
|
1963
|
+
form.setValue?.(path, next);
|
|
1964
|
+
revalidate();
|
|
1965
|
+
},
|
|
1966
|
+
[form, path, revalidate]
|
|
1967
|
+
);
|
|
1968
|
+
const update = useCallback(
|
|
1969
|
+
(index, item) => {
|
|
1970
|
+
form.setValue?.(`${path}.${index}`, item);
|
|
1971
|
+
revalidate();
|
|
1972
|
+
},
|
|
1973
|
+
[form, path, revalidate]
|
|
1974
|
+
);
|
|
1975
|
+
const prepend = useCallback(
|
|
1976
|
+
(item) => {
|
|
1977
|
+
form.arrayInsert(path, 0, item);
|
|
1978
|
+
revalidate();
|
|
1979
|
+
},
|
|
1980
|
+
[form, path, revalidate]
|
|
1981
|
+
);
|
|
1982
|
+
const clear = useCallback(() => {
|
|
1983
|
+
form.setValue?.(path, []);
|
|
1984
|
+
revalidate();
|
|
1985
|
+
}, [form, path, revalidate]);
|
|
1886
1986
|
return useMemo(
|
|
1887
1987
|
() => ({
|
|
1888
1988
|
path,
|
|
@@ -1893,13 +1993,45 @@ function useFieldArray(form, pathArg) {
|
|
|
1893
1993
|
firstError: error?.[0],
|
|
1894
1994
|
setError,
|
|
1895
1995
|
clearError,
|
|
1996
|
+
touched: slice.touched,
|
|
1997
|
+
dirty: slice.dirty,
|
|
1998
|
+
isValidating: slice.isValidating,
|
|
1999
|
+
setTouched,
|
|
2000
|
+
onBlur,
|
|
2001
|
+
validate,
|
|
1896
2002
|
push,
|
|
1897
2003
|
remove,
|
|
1898
2004
|
insert,
|
|
1899
2005
|
move,
|
|
1900
|
-
swap
|
|
2006
|
+
swap,
|
|
2007
|
+
replace,
|
|
2008
|
+
update,
|
|
2009
|
+
prepend,
|
|
2010
|
+
clear
|
|
1901
2011
|
}),
|
|
1902
|
-
[
|
|
2012
|
+
[
|
|
2013
|
+
path,
|
|
2014
|
+
fields,
|
|
2015
|
+
items,
|
|
2016
|
+
error,
|
|
2017
|
+
setError,
|
|
2018
|
+
clearError,
|
|
2019
|
+
slice.touched,
|
|
2020
|
+
slice.dirty,
|
|
2021
|
+
slice.isValidating,
|
|
2022
|
+
setTouched,
|
|
2023
|
+
onBlur,
|
|
2024
|
+
validate,
|
|
2025
|
+
push,
|
|
2026
|
+
remove,
|
|
2027
|
+
insert,
|
|
2028
|
+
move,
|
|
2029
|
+
swap,
|
|
2030
|
+
replace,
|
|
2031
|
+
update,
|
|
2032
|
+
prepend,
|
|
2033
|
+
clear
|
|
2034
|
+
]
|
|
1903
2035
|
);
|
|
1904
2036
|
}
|
|
1905
2037
|
var useFormError = (form) => useStore(
|