formstand 0.22.1 → 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 +56 -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 +128 -16
- 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 +109 -8
- 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 +2 -2
- 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).
|
|
@@ -1845,7 +1865,10 @@ function useFieldArray(form, pathArg) {
|
|
|
1845
1865
|
items: Array.isArray(value) ? value : EMPTY_ITEMS,
|
|
1846
1866
|
// Own-key read, like useField: an array named "constructor" must
|
|
1847
1867
|
// not read Object as its error list.
|
|
1848
|
-
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)
|
|
1849
1872
|
};
|
|
1850
1873
|
})
|
|
1851
1874
|
);
|
|
@@ -1914,6 +1937,52 @@ function useFieldArray(form, pathArg) {
|
|
|
1914
1937
|
[form, path]
|
|
1915
1938
|
);
|
|
1916
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]);
|
|
1917
1986
|
return useMemo(
|
|
1918
1987
|
() => ({
|
|
1919
1988
|
path,
|
|
@@ -1924,13 +1993,45 @@ function useFieldArray(form, pathArg) {
|
|
|
1924
1993
|
firstError: error?.[0],
|
|
1925
1994
|
setError,
|
|
1926
1995
|
clearError,
|
|
1996
|
+
touched: slice.touched,
|
|
1997
|
+
dirty: slice.dirty,
|
|
1998
|
+
isValidating: slice.isValidating,
|
|
1999
|
+
setTouched,
|
|
2000
|
+
onBlur,
|
|
2001
|
+
validate,
|
|
1927
2002
|
push,
|
|
1928
2003
|
remove,
|
|
1929
2004
|
insert,
|
|
1930
2005
|
move,
|
|
1931
|
-
swap
|
|
2006
|
+
swap,
|
|
2007
|
+
replace,
|
|
2008
|
+
update,
|
|
2009
|
+
prepend,
|
|
2010
|
+
clear
|
|
1932
2011
|
}),
|
|
1933
|
-
[
|
|
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
|
+
]
|
|
1934
2035
|
);
|
|
1935
2036
|
}
|
|
1936
2037
|
var useFormError = (form) => useStore(
|