formstand 0.9.0 → 0.10.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.ts CHANGED
@@ -6,9 +6,41 @@ import { ReactNode, ChangeEvent } from 'react';
6
6
  type LeafType = string | number | boolean | bigint | symbol | null | undefined | Date | RegExp;
7
7
  type IsRecord<T> = T extends LeafType ? false : T extends readonly unknown[] ? false : T extends object ? true : false;
8
8
  type IsArray<T> = T extends readonly unknown[] ? true : false;
9
- type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8];
10
- type FieldPath<T, D extends number = 7> = [D] extends [0] ? never : IsArray<T> extends true ? T extends readonly (infer U)[] ? `${number}` | (IsRecord<NonNullable<U>> extends true ? `${number}.${FieldPath<NonNullable<U>, Prev[D]>}` : IsArray<NonNullable<U>> extends true ? `${number}.${FieldPath<NonNullable<U>, Prev[D]>}` : never) : never : IsRecord<T> extends true ? {
11
- [K in keyof T & string]: K | (IsRecord<NonNullable<T[K]>> extends true ? `${K}.${FieldPath<NonNullable<T[K]>, Prev[D]>}` : IsArray<NonNullable<T[K]>> extends true ? `${K}.${FieldPath<NonNullable<T[K]>, Prev[D]>}` : never);
9
+ type Prev = [
10
+ never,
11
+ 0,
12
+ 1,
13
+ 2,
14
+ 3,
15
+ 4,
16
+ 5,
17
+ 6,
18
+ 7,
19
+ 8,
20
+ 9,
21
+ 10,
22
+ 11,
23
+ 12,
24
+ 13,
25
+ 14,
26
+ 15,
27
+ 16,
28
+ 17,
29
+ 18,
30
+ 19,
31
+ 20,
32
+ 21,
33
+ 22,
34
+ 23,
35
+ 24
36
+ ];
37
+ type DefaultPathDepth = 9;
38
+ type PathDepth = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25;
39
+ type IsUnion<T, U = T> = [T] extends [never] ? false : T extends unknown ? [U] extends [T] ? false : true : never;
40
+ type NormalizeDepth<D extends number> = number extends D ? DefaultPathDepth : [D] extends [PathDepth] ? IsUnion<D> extends true ? DefaultPathDepth : D : DefaultPathDepth;
41
+ type FieldPath<T, D extends number = DefaultPathDepth> = FieldPathRec<T, NormalizeDepth<D>>;
42
+ type FieldPathRec<T, D extends number> = [D] extends [0] ? never : IsArray<T> extends true ? T extends readonly (infer U)[] ? `${number}` | (IsRecord<NonNullable<U>> extends true ? `${number}.${FieldPathRec<NonNullable<U>, Prev[D]>}` : IsArray<NonNullable<U>> extends true ? `${number}.${FieldPathRec<NonNullable<U>, Prev[D]>}` : never) : never : IsRecord<T> extends true ? {
43
+ [K in keyof T & string]: K | (IsRecord<NonNullable<T[K]>> extends true ? `${K}.${FieldPathRec<NonNullable<T[K]>, Prev[D]>}` : IsArray<NonNullable<T[K]>> extends true ? `${K}.${FieldPathRec<NonNullable<T[K]>, Prev[D]>}` : never);
12
44
  }[keyof T & string] : never;
13
45
  type StepValue<T, K extends string> = T extends readonly (infer U)[] ? K extends `${number}` ? U : never : T extends object ? K extends keyof T ? T[K] : never : never;
14
46
  type FieldValue<T, P extends string> = [T] extends [NonNullable<T>] ? P extends `${infer Head}.${infer Tail}` ? FieldValue<StepValue<T, Head>, Tail> : StepValue<T, P> : FieldValue<NonNullable<T>, P> | undefined;
@@ -55,6 +87,16 @@ type FieldValidationResult = SettledFieldValidationResult | Readonly<{
55
87
  kind: "pending";
56
88
  promise: Promise<SettledFieldValidationResult>;
57
89
  }>;
90
+ type SettledFieldsValidationResult = Readonly<{
91
+ kind: "valid";
92
+ }> | Readonly<{
93
+ kind: "invalid";
94
+ errors: ErrorMap;
95
+ }>;
96
+ type FieldsValidationResult = SettledFieldsValidationResult | Readonly<{
97
+ kind: "pending";
98
+ promise: Promise<SettledFieldsValidationResult>;
99
+ }>;
58
100
  declare const flattenIssues: (issues: readonly z.core.$ZodIssue[]) => ErrorMap;
59
101
  declare const validateSync: <TSchema extends z.ZodType>(schema: TSchema, values: z.input<TSchema>) => SettledValidationResult<z.output<TSchema>>;
60
102
  declare const validateAsync: <TSchema extends z.ZodType>(schema: TSchema, values: z.input<TSchema>) => Promise<SettledValidationResult<z.output<TSchema>>>;
@@ -62,8 +104,9 @@ declare const isAsyncRequiredError: (e: unknown) => boolean;
62
104
  declare const emptyValueForSchema: (schema: z.ZodType) => null | undefined;
63
105
 
64
106
  type ReadonlyStoreApi<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
65
- type CreateFormOptions<TSchema extends z.ZodType> = Readonly<{
107
+ type CreateFormOptions<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
66
108
  initialValues: z.input<TSchema>;
109
+ pathDepth?: D & (IsUnion<D> extends true ? never : unknown);
67
110
  mode?: ValidationMode;
68
111
  reValidateMode?: ValidationMode;
69
112
  validateOnMount?: boolean;
@@ -87,7 +130,7 @@ type SubmitResult<TOutput> = Readonly<{
87
130
  error: unknown;
88
131
  }>;
89
132
  type ArrayItemOf$1<T> = T extends readonly (infer U)[] ? U : never;
90
- type ErrorPath<TValues> = FieldPath<TValues> | "";
133
+ type ErrorPath<TValues, D extends PathDepth = DefaultPathDepth> = FieldPath<TValues, D> | "";
91
134
  type ResetOptions = Readonly<{
92
135
  keepErrors?: boolean;
93
136
  keepTouched?: boolean;
@@ -100,41 +143,42 @@ type FieldSnapshot<TValue> = Readonly<{
100
143
  dirty: boolean;
101
144
  isValidating: boolean;
102
145
  }>;
103
- type Form<TSchema extends z.ZodType> = Readonly<{
146
+ type Form<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
147
+ "~pathDepth"?: D;
104
148
  schema: TSchema;
105
149
  store: ReadonlyStoreApi<FormState<z.input<TSchema>>>;
106
150
  getState: () => FormState<z.input<TSchema>>;
107
151
  subscribe: (listener: (state: FormState<z.input<TSchema>>, prev: FormState<z.input<TSchema>>) => void) => () => void;
108
- getField: <P extends FieldPath<z.input<TSchema>>>(path: P) => FieldValue<z.input<TSchema>, P>;
109
- watchField: <P extends FieldPath<z.input<TSchema>>>(path: P, listener: (snapshot: FieldSnapshot<FieldValue<z.input<TSchema>, P>>) => void) => () => void;
110
- watchValue: <P extends FieldPath<z.input<TSchema>>>(path: P, listener: (value: FieldValue<z.input<TSchema>, P>, previous: FieldValue<z.input<TSchema>, P>) => void) => () => void;
152
+ getField: <P extends FieldPath<z.input<TSchema>, D>>(path: P) => FieldValue<z.input<TSchema>, P>;
153
+ watchField: <P extends FieldPath<z.input<TSchema>, D>>(path: P, listener: (snapshot: FieldSnapshot<FieldValue<z.input<TSchema>, P>>) => void) => () => void;
154
+ watchValue: <P extends FieldPath<z.input<TSchema>, D>>(path: P, listener: (value: FieldValue<z.input<TSchema>, P>, previous: FieldValue<z.input<TSchema>, P>) => void) => () => void;
111
155
  watchValues: (listener: (values: z.input<TSchema>, previous: z.input<TSchema>) => void) => () => void;
112
- setValue: <P extends FieldPath<z.input<TSchema>>>(path: P, value: FieldValue<z.input<TSchema>, P>) => void;
156
+ setValue: <P extends FieldPath<z.input<TSchema>, D>>(path: P, value: FieldValue<z.input<TSchema>, P>) => void;
113
157
  setValues: (next: z.input<TSchema>) => void;
114
- setTouched: (path: FieldPath<z.input<TSchema>>, touched?: boolean) => void;
158
+ setTouched: (path: FieldPath<z.input<TSchema>, D>, touched?: boolean) => void;
115
159
  setSubmitting: (value: boolean) => void;
116
160
  setMode: (mode: ValidationMode) => void;
117
161
  setReValidateMode: (mode: ValidationMode) => void;
118
- setError: (path: ErrorPath<z.input<TSchema>>, errors: string | readonly string[]) => void;
162
+ setError: (path: ErrorPath<z.input<TSchema>, D>, errors: string | readonly string[]) => void;
119
163
  setErrors: (errors: ErrorMap) => void;
120
- clearErrors: (path?: ErrorPath<z.input<TSchema>>) => void;
164
+ clearErrors: (path?: ErrorPath<z.input<TSchema>, D>) => void;
121
165
  updateState: (updater: (state: FormState<z.input<TSchema>>) => Partial<Omit<FormState<z.input<TSchema>>, "errors">>) => void;
122
166
  reset: (nextInitial?: Partial<z.input<TSchema>>, options?: ResetOptions) => void;
123
- resetField: (path: FieldPath<z.input<TSchema>>) => void;
167
+ resetField: (path: FieldPath<z.input<TSchema>, D>) => void;
124
168
  adoptValues: (values: z.input<TSchema>) => void;
125
- getFieldState: <P extends FieldPath<z.input<TSchema>>>(path: P) => FieldSnapshot<FieldValue<z.input<TSchema>, P>>;
169
+ getFieldState: <P extends FieldPath<z.input<TSchema>, D>>(path: P) => FieldSnapshot<FieldValue<z.input<TSchema>, P>>;
126
170
  validate: () => ValidationResult<z.output<TSchema>>;
127
- validateField: (path: ErrorPath<z.input<TSchema>>) => FieldValidationResult;
128
- validateFields: (paths: readonly FieldPath<z.input<TSchema>>[]) => boolean | Promise<boolean>;
171
+ validateField: (path: ErrorPath<z.input<TSchema>, D>) => FieldValidationResult;
172
+ validateFields: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => FieldsValidationResult;
129
173
  validateAsync: () => Promise<ValidationResult<z.output<TSchema>>>;
130
- validateFieldAsync: (path: ErrorPath<z.input<TSchema>>) => Promise<FieldValidationResult>;
131
- validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema>>[]) => Promise<boolean>;
174
+ validateFieldAsync: (path: ErrorPath<z.input<TSchema>, D>) => Promise<FieldValidationResult>;
175
+ validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => Promise<SettledFieldsValidationResult>;
132
176
  submit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => Promise<SubmitResult<z.output<TSchema>>>;
133
- arrayPush: <P extends FieldPath<z.input<TSchema>>>(path: P, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
134
- arrayRemove: (path: FieldPath<z.input<TSchema>>, index: number) => void;
135
- arrayInsert: <P extends FieldPath<z.input<TSchema>>>(path: P, index: number, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
136
- arrayMove: (path: FieldPath<z.input<TSchema>>, from: number, to: number) => void;
137
- arraySwap: (path: FieldPath<z.input<TSchema>>, a: number, b: number) => void;
177
+ arrayPush: <P extends FieldPath<z.input<TSchema>, D>>(path: P, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
178
+ arrayRemove: (path: FieldPath<z.input<TSchema>, D>, index: number) => void;
179
+ arrayInsert: <P extends FieldPath<z.input<TSchema>, D>>(path: P, index: number, item: ArrayItemOf$1<NonNullable<FieldValue<z.input<TSchema>, P>>>) => void;
180
+ arrayMove: (path: FieldPath<z.input<TSchema>, D>, from: number, to: number) => void;
181
+ arraySwap: (path: FieldPath<z.input<TSchema>, D>, a: number, b: number) => void;
138
182
  handleSubmit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => (event?: {
139
183
  preventDefault: () => void;
140
184
  }) => Promise<SubmitResult<z.output<TSchema>>>;
@@ -143,7 +187,7 @@ type Form<TSchema extends z.ZodType> = Readonly<{
143
187
  snapshot: () => FormState<z.input<TSchema>>;
144
188
  restore: (snapshot: FormState<z.input<TSchema>>) => void;
145
189
  }>;
146
- declare const createForm: <TSchema extends z.ZodType>(schema: TSchema, options: CreateFormOptions<TSchema>) => Form<TSchema>;
190
+ declare const createForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
147
191
 
148
192
  type PathSegment = string | number;
149
193
  declare const parsePath: (path: string) => readonly PathSegment[];
@@ -166,19 +210,19 @@ type PersistHandle = Readonly<{
166
210
  clear: () => void;
167
211
  dispose: () => void;
168
212
  }>;
169
- declare const persistForm: <TSchema extends z.ZodType>(form: Form<TSchema>, options: PersistOptions<TSchema>) => PersistHandle;
213
+ declare const persistForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, options: PersistOptions<TSchema>) => PersistHandle;
170
214
 
171
- declare const useForm: <TSchema extends z.ZodType>(schema: TSchema, options: CreateFormOptions<TSchema>) => Form<TSchema>;
215
+ declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
172
216
 
173
- type FormProviderProps<TSchema extends z.ZodType> = Readonly<{
174
- form: Form<TSchema>;
217
+ type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
218
+ form: Form<TSchema, D>;
175
219
  children: ReactNode;
176
220
  }>;
177
- type FormContextApi<TSchema extends z.ZodType> = Readonly<{
178
- Provider: (props: FormProviderProps<TSchema>) => ReactNode;
179
- useFormContext: () => Form<TSchema>;
221
+ type FormContextApi<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
222
+ Provider: (props: FormProviderProps<TSchema, D>) => ReactNode;
223
+ useFormContext: () => Form<TSchema, D>;
180
224
  }>;
181
- declare const createFormContext: <TSchema extends z.ZodType>() => FormContextApi<TSchema>;
225
+ declare const createFormContext: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>() => FormContextApi<TSchema, D>;
182
226
 
183
227
  type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
184
228
  type FieldFormApi = Readonly<{
@@ -211,18 +255,21 @@ type UseFieldReturn<TValue> = Readonly<{
211
255
  validateAsync: () => Promise<FieldValidationResult>;
212
256
  onBlur: () => void;
213
257
  }>;
214
- declare function useField<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
258
+ declare function useField<TSchema extends z.ZodType>(form: FieldFormApi & Readonly<{
259
+ schema: TSchema;
260
+ store: ReadonlyStore$2<FormState<z.input<TSchema>>>;
261
+ }>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
215
262
  declare function useField<TValue = unknown>(form: FieldFormApi & {
216
263
  readonly schema?: undefined;
217
- }, path: string | ((state: FormState<unknown>) => string), options?: UseFieldOptions): UseFieldReturn<TValue>;
218
- declare function useField<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
264
+ }, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
265
+ declare function useField<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
219
266
 
220
267
  type VariantFieldValue<V, TField extends string> = V extends unknown ? TField extends keyof V ? V[TField] : never : never;
221
268
  type CommonKeys<V> = keyof V;
222
269
  type AllKeys<V> = V extends unknown ? keyof V : never;
223
270
  type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
224
271
  type UnionValueAt<TValues, P extends string> = P extends keyof TValues ? NonNullable<TValues[P]> : P extends `${infer Head}.${infer Tail}` ? Head extends keyof TValues ? UnionValueAt<NonNullable<TValues[Head]>, Tail> : never : never;
225
- declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends VariantKeys<UnionValueAt<z.input<TSchema>, P>>>(form: Form<TSchema>, unionPath: P, field: TField): UseFieldReturn<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField> | undefined>;
272
+ declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends VariantKeys<UnionValueAt<z.input<TSchema>, P>>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, unionPath: P, field: TField): UseFieldReturn<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField> | undefined>;
226
273
  declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
227
274
  readonly schema?: undefined;
228
275
  }, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
@@ -252,29 +299,32 @@ type UseFieldArrayReturn<TItem> = Readonly<{
252
299
  swap: (a: number, b: number) => void;
253
300
  }>;
254
301
  type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
255
- declare function useFieldArray<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
302
+ declare function useFieldArray<TSchema extends z.ZodType>(form: FieldArrayFormApi & Readonly<{
303
+ schema: TSchema;
304
+ store: ReadonlyStore$1<FormState<z.input<TSchema>>>;
305
+ }>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
256
306
  declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
257
307
  readonly schema?: undefined;
258
- }, path: string | ((state: FormState<unknown>) => string)): UseFieldArrayReturn<TItem>;
259
- declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
308
+ }, path: FieldPathArg<unknown>): UseFieldArrayReturn<TItem>;
309
+ declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
260
310
 
261
- type BoundUseField<TSchema extends z.ZodType> = {
311
+ type BoundUseField<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
262
312
  (pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
263
- <P extends FieldPath<z.input<TSchema>>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
313
+ <P extends FieldPath<z.input<TSchema>, D>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
264
314
  };
265
315
  type BoundUseVariantField<TSchema extends z.ZodType> = <P extends string, TField extends VariantKeys<UnionValueAt<z.input<TSchema>, P>>>(unionPath: P, field: TField) => UseFieldReturn<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField> | undefined>;
266
- type BoundUseFieldArray<TSchema extends z.ZodType> = {
316
+ type BoundUseFieldArray<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
267
317
  (pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
268
- <P extends FieldPath<z.input<TSchema>>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
318
+ <P extends FieldPath<z.input<TSchema>, D>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
269
319
  };
270
320
  type BoundUseSelector<TSchema extends z.ZodType> = <U>(selector: (state: FormState<z.input<TSchema>>) => U) => U;
271
- type BoundUseFlag<TSchema extends z.ZodType> = (path?: FieldPath<z.input<TSchema>>) => boolean;
272
- type FormHooks<TSchema extends z.ZodType, N extends string> = Readonly<{
273
- [K in `use${Capitalize<N>}Field`]: BoundUseField<TSchema>;
321
+ type BoundUseFlag<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = (path?: FieldPath<z.input<TSchema>, D>) => boolean;
322
+ type FormHooks<TSchema extends z.ZodType, N extends string, D extends PathDepth = DefaultPathDepth> = Readonly<{
323
+ [K in `use${Capitalize<N>}Field`]: BoundUseField<TSchema, D>;
274
324
  } & {
275
325
  [K in `use${Capitalize<N>}VariantField`]: BoundUseVariantField<TSchema>;
276
326
  } & {
277
- [K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema>;
327
+ [K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema, D>;
278
328
  } & {
279
329
  [K in `use${Capitalize<N>}Selector`]: BoundUseSelector<TSchema>;
280
330
  } & {
@@ -282,25 +332,25 @@ type FormHooks<TSchema extends z.ZodType, N extends string> = Readonly<{
282
332
  } & {
283
333
  [K in `use${Capitalize<N>}Error`]: () => readonly string[] | undefined;
284
334
  } & {
285
- [K in `use${Capitalize<N>}IsDirty`]: BoundUseFlag<TSchema>;
335
+ [K in `use${Capitalize<N>}IsDirty`]: BoundUseFlag<TSchema, D>;
286
336
  } & {
287
- [K in `use${Capitalize<N>}IsValid`]: BoundUseFlag<TSchema>;
337
+ [K in `use${Capitalize<N>}IsValid`]: BoundUseFlag<TSchema, D>;
288
338
  } & {
289
339
  [K in `use${Capitalize<N>}IsSubmitting`]: () => boolean;
290
340
  } & {
291
341
  [K in `use${Capitalize<N>}SubmitCount`]: () => number;
292
342
  }>;
293
- declare const createFormHooks: <TSchema extends z.ZodType, N extends string = "">(form: Form<TSchema>, name?: N) => FormHooks<TSchema, N>;
343
+ declare const createFormHooks: <TSchema extends z.ZodType, N extends string = "", D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, name?: N) => FormHooks<TSchema, N, D>;
294
344
 
295
345
  type ReadonlyStore<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
296
346
  type FormStateApi = Readonly<{
297
347
  store: ReadonlyStore<FormState<unknown>>;
298
348
  }>;
299
- declare function useFormSelector<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
349
+ declare function useFormSelector<TSchema extends z.ZodType, U, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, selector: (state: FormState<z.input<TSchema>>) => U): U;
300
350
  declare function useFormSelector<U>(form: FormStateApi & {
301
351
  readonly schema?: undefined;
302
352
  }, selector: (state: FormState<unknown>) => U): U;
303
- declare function useFormSelectorShallow<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
353
+ declare function useFormSelectorShallow<TSchema extends z.ZodType, U, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, selector: (state: FormState<z.input<TSchema>>) => U): U;
304
354
  declare function useFormSelectorShallow<U>(form: FormStateApi & {
305
355
  readonly schema?: undefined;
306
356
  }, selector: (state: FormState<unknown>) => U): U;
@@ -310,15 +360,15 @@ declare const useFormError: (form: FormStateApi) => readonly string[] | undefine
310
360
  declare function useIsDirty(form: FormStateApi & {
311
361
  readonly schema?: undefined;
312
362
  }, path?: string): boolean;
313
- declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
363
+ declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path?: P): boolean;
314
364
  declare function useIsValid(form: FormStateApi & {
315
365
  readonly schema?: undefined;
316
366
  }, path?: string): boolean;
317
- declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
367
+ declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>, D>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path?: P): boolean;
318
368
  declare const useIsSubmitting: (form: FormStateApi) => boolean;
319
369
  declare const useSubmitCount: (form: FormStateApi) => number;
320
370
 
321
- type PathsOf<F extends FieldFormApi> = F extends Form<infer TSchema extends z.ZodType> ? FieldPath<z.input<TSchema>> : string;
371
+ type PathsOf<F extends FieldFormApi> = F extends Form<infer TSchema extends z.ZodType, infer D extends PathDepth> ? FieldPath<z.input<TSchema>, D> : string;
322
372
  type FieldRef<T> = ((instance: T | null) => void) | Readonly<{
323
373
  current: T | null;
324
374
  }> | null;
@@ -411,6 +461,7 @@ type SelectProps = Readonly<{
411
461
  onChange: (e: ChangeEvent<HTMLSelectElement>) => void;
412
462
  onBlur: () => void;
413
463
  }>;
464
+ declare const hasFieldError: (error: readonly string[] | undefined) => boolean;
414
465
  declare const numberToInputText: (value: number | null | undefined) => string;
415
466
  type ParsedNumberText = Readonly<{
416
467
  kind: "empty";
@@ -437,4 +488,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
437
488
  declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
438
489
  declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
439
490
 
440
- export { type BoolMap, type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, type CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, type ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, type FieldPath, type FieldPathArg, type FieldRef, type FieldSnapshot, type FieldValidationResult, type FieldValue, type Form, type FormContextApi, type FormHooks, type FormProviderProps, type FormState, type FormStateApi, type InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputProps, type ParsedDateText, type ParsedNumberText, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, type ReadonlyStoreApi, type ResetOptions, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SettledFieldValidationResult, type SettledValidationResult, type SubmitHandler, type SubmitOptions, type SubmitResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type ValidationMode, type ValidationResult, type ValidationTrigger, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useIsDirty, useIsSubmitting, useIsValid, useSubmitCount, useVariantField, validateAsync, validateSync };
491
+ export { type BoolMap, type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, type CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, type DefaultPathDepth, type ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, type FieldPath, type FieldPathArg, type FieldRef, type FieldSnapshot, type FieldValidationResult, type FieldValue, type FieldsValidationResult, type Form, type FormContextApi, type FormHooks, type FormProviderProps, type FormState, type FormStateApi, type InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputProps, type ParsedDateText, type ParsedNumberText, type PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, type ReadonlyStoreApi, type ResetOptions, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SettledFieldValidationResult, type SettledFieldsValidationResult, type SettledValidationResult, type SubmitHandler, type SubmitOptions, type SubmitResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type ValidationMode, type ValidationResult, type ValidationTrigger, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useIsDirty, useIsSubmitting, useIsValid, useSubmitCount, useVariantField, validateAsync, validateSync };