formstand 0.22.1 → 0.24.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/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-BJum0RBu.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-BJum0RBu.cjs';
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, type ArrayPathsOf, type BoundUseField, type BoundUseFieldArray, type BoundUseFields, type BoundUseFlag, type BoundUseSelector, type BoundUseVariantField, CheckboxField, type CheckboxFieldProps, type CheckboxProps, CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, DefaultPathDepth, ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, FieldPath, type FieldPathArg, type FieldRef, FieldValidationResult, FieldValue, Form, type FormActionHandler, type FormActionOptions, type FormActionStateHandler, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, type FormStep, InvalidSubmitHandler, type MaskedInputBinding, type MaskedInputOptions, type MaskedParse, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsAccepting, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SelectValueAt, SettledFieldValidationResult, type StepStatus, TextField, type TextFieldProps, type TextInputProps, type UnionValueAt, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, type UseFormStepsReturn, type VariantFieldPath, type VariantFieldValue, type VariantKeys, 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 };
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-BJum0RBu.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-BJum0RBu.js';
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, type ArrayPathsOf, type BoundUseField, type BoundUseFieldArray, type BoundUseFields, type BoundUseFlag, type BoundUseSelector, type BoundUseVariantField, CheckboxField, type CheckboxFieldProps, type CheckboxProps, CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, DefaultPathDepth, ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, FieldPath, type FieldPathArg, type FieldRef, FieldValidationResult, FieldValue, Form, type FormActionHandler, type FormActionOptions, type FormActionStateHandler, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, type FormStep, InvalidSubmitHandler, type MaskedInputBinding, type MaskedInputOptions, type MaskedParse, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsAccepting, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SelectValueAt, SettledFieldValidationResult, type StepStatus, TextField, type TextFieldProps, type TextInputProps, type UnionValueAt, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, type UseFormStepsReturn, type VariantFieldPath, type VariantFieldValue, type VariantKeys, 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 };
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-BMXIZEI4.js';
2
- export { getAtPath, parsePath, setAtPath, useFormSelector, useFormSelectorShallow } from './chunk-BMXIZEI4.js';
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,42 @@ var fieldSchemaForIntrospection = (schema, path) => {
217
220
  schema
218
221
  );
219
222
  };
223
+ var containerKindAt = (schema) => (prefix) => {
224
+ const unwrapAll = (s) => {
225
+ const inner2 = unwrapForWalk(s);
226
+ return inner2 === null ? s : unwrapAll(inner2);
227
+ };
228
+ const step = (s, segment) => {
229
+ const inner2 = unwrapAll(s);
230
+ if (inner2 instanceof z.ZodObject && typeof segment === "string") {
231
+ const shape = inner2.shape;
232
+ return Object.hasOwn(shape, segment) ? shape[segment] ?? null : null;
233
+ }
234
+ if (inner2 instanceof z.ZodArray && typeof segment === "number") {
235
+ return inner2.element;
236
+ }
237
+ if (inner2 instanceof z.ZodTuple && typeof segment === "number") {
238
+ return inner2.def.items[segment] ?? null;
239
+ }
240
+ if (inner2 instanceof z.ZodRecord) {
241
+ return inner2.valueType;
242
+ }
243
+ return null;
244
+ };
245
+ const sub = parsePath(prefix).reduce(
246
+ (current, segment) => current === null ? null : step(current, segment),
247
+ schema
248
+ );
249
+ if (sub === null) return null;
250
+ const inner = unwrapAll(sub);
251
+ if (inner instanceof z.ZodArray || inner instanceof z.ZodTuple) {
252
+ return "array";
253
+ }
254
+ if (inner instanceof z.ZodObject || inner instanceof z.ZodRecord) {
255
+ return "record";
256
+ }
257
+ return null;
258
+ };
220
259
  var fieldSchemaAtPath = (schema, path) => parsePath(path).reduce((current, segment) => {
221
260
  if (current === null || hasChecks(current)) return null;
222
261
  if (current instanceof z.ZodObject && typeof segment === "string") {
@@ -320,6 +359,7 @@ var releaseChangedSlices = (server, prevValues, nextValues) => {
320
359
  };
321
360
  var createForm = (schema, options) => {
322
361
  const initialMode = options.mode ?? "onBlur";
362
+ const kindAt = containerKindAt(schema);
323
363
  const initialReValidateMode = options.reValidateMode ?? "onChange";
324
364
  const initial = {
325
365
  values: options.initialValues,
@@ -677,7 +717,7 @@ var createForm = (schema, options) => {
677
717
  }
678
718
  const arr = Array.isArray(current) ? current : [];
679
719
  const next = nextArray(arr);
680
- const written = setAtPath(store.getState().values, path, next);
720
+ const written = setAtPath(store.getState().values, path, next, kindAt);
681
721
  clearArrayOpsUnder(store, path, true);
682
722
  if (Array.isArray(current) && getAtPath(written, path) === next) {
683
723
  recordArrayOp(store, path, {
@@ -839,7 +879,7 @@ var createForm = (schema, options) => {
839
879
  clearArrayOpsUnder(store, path);
840
880
  store.setState((state) => ({
841
881
  ...state,
842
- values: setAtPath(state.values, path, value),
882
+ values: setAtPath(state.values, path, value, kindAt),
843
883
  ...errorChannels(state, {
844
884
  serverErrors: releaseSpine(state.serverErrors, path)
845
885
  })
@@ -986,7 +1026,7 @@ var createForm = (schema, options) => {
986
1026
  }
987
1027
  store.setState((state) => ({
988
1028
  ...state,
989
- values: initialSlot.exists ? setAtPath(state.values, path, initialSlot.value) : state.values,
1029
+ values: initialSlot.exists ? setAtPath(state.values, path, initialSlot.value, kindAt) : state.values,
990
1030
  // A runtime "" path scopes the whole form (the imperative surface is
991
1031
  // string-typed even though FieldPath excludes ""). Server entries
992
1032
  // follow the setValue release contract (releaseSpine).
@@ -1845,7 +1885,10 @@ function useFieldArray(form, pathArg) {
1845
1885
  items: Array.isArray(value) ? value : EMPTY_ITEMS,
1846
1886
  // Own-key read, like useField: an array named "constructor" must
1847
1887
  // not read Object as its error list.
1848
- error: entryAt(state.errors, path)
1888
+ error: entryAt(state.errors, path),
1889
+ touched: flagAt(state.touched, path),
1890
+ dirty: isFieldDirty(value, getAtPath(state.initialValues, path)),
1891
+ isValidating: flagAt(state.isValidating, path)
1849
1892
  };
1850
1893
  })
1851
1894
  );
@@ -1914,6 +1957,52 @@ function useFieldArray(form, pathArg) {
1914
1957
  [form, path]
1915
1958
  );
1916
1959
  const clearError = useCallback(() => form.clearErrors?.(path), [form, path]);
1960
+ const setTouched = useCallback(
1961
+ (touched) => form.setTouched?.(path, touched),
1962
+ [form, path]
1963
+ );
1964
+ const onBlur = useCallback(() => {
1965
+ form.setTouched?.(path, true);
1966
+ const state = form.store.getState();
1967
+ if (shouldValidateOn(
1968
+ "blur",
1969
+ state.mode,
1970
+ state.reValidateMode,
1971
+ state.submitCount > 0,
1972
+ true
1973
+ )) {
1974
+ form.validateField?.(path);
1975
+ }
1976
+ }, [form, path]);
1977
+ const validate = useCallback(
1978
+ () => form.validateField?.(path) ?? { kind: "valid" },
1979
+ [form, path]
1980
+ );
1981
+ const replace = useCallback(
1982
+ (next) => {
1983
+ form.setValue?.(path, next);
1984
+ revalidate();
1985
+ },
1986
+ [form, path, revalidate]
1987
+ );
1988
+ const update = useCallback(
1989
+ (index, item) => {
1990
+ form.setValue?.(`${path}.${index}`, item);
1991
+ revalidate();
1992
+ },
1993
+ [form, path, revalidate]
1994
+ );
1995
+ const prepend = useCallback(
1996
+ (item) => {
1997
+ form.arrayInsert(path, 0, item);
1998
+ revalidate();
1999
+ },
2000
+ [form, path, revalidate]
2001
+ );
2002
+ const clear = useCallback(() => {
2003
+ form.setValue?.(path, []);
2004
+ revalidate();
2005
+ }, [form, path, revalidate]);
1917
2006
  return useMemo(
1918
2007
  () => ({
1919
2008
  path,
@@ -1924,13 +2013,45 @@ function useFieldArray(form, pathArg) {
1924
2013
  firstError: error?.[0],
1925
2014
  setError,
1926
2015
  clearError,
2016
+ touched: slice.touched,
2017
+ dirty: slice.dirty,
2018
+ isValidating: slice.isValidating,
2019
+ setTouched,
2020
+ onBlur,
2021
+ validate,
1927
2022
  push,
1928
2023
  remove,
1929
2024
  insert,
1930
2025
  move,
1931
- swap
2026
+ swap,
2027
+ replace,
2028
+ update,
2029
+ prepend,
2030
+ clear
1932
2031
  }),
1933
- [path, fields, items, error, setError, clearError, push, remove, insert, move, swap]
2032
+ [
2033
+ path,
2034
+ fields,
2035
+ items,
2036
+ error,
2037
+ setError,
2038
+ clearError,
2039
+ slice.touched,
2040
+ slice.dirty,
2041
+ slice.isValidating,
2042
+ setTouched,
2043
+ onBlur,
2044
+ validate,
2045
+ push,
2046
+ remove,
2047
+ insert,
2048
+ move,
2049
+ swap,
2050
+ replace,
2051
+ update,
2052
+ prepend,
2053
+ clear
2054
+ ]
1934
2055
  );
1935
2056
  }
1936
2057
  var useFormError = (form) => useStore(