formstand 0.12.0 → 0.14.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,193 +1,9 @@
1
+ import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-C9hZffCQ.cjs';
2
+ export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult, I as InvalidSubmitHandler, R as ReadonlyStoreApi, g as ResetOptions, S as SettledFieldValidationResult, h as SettledFieldsValidationResult, i as SettledValidationResult, j as SubmitHandler, k as SubmitOptions, l as SubmitResult, V as ValidationMode, m as ValidationResult, n as ValidationTrigger, o as createForm, p as emptyValueForSchema, q as flattenIssues, r as isAsyncRequiredError, s as shouldValidateOn, v as validateAsync, t as validateSync } from './createForm-C9hZffCQ.cjs';
1
3
  import { z } from 'zod';
2
- import { StoreApi } from 'zustand/vanilla';
3
4
  import * as react from 'react';
4
5
  import { ReactNode, ChangeEvent } from 'react';
5
-
6
- type LeafType = string | number | boolean | bigint | symbol | null | undefined | Date | RegExp;
7
- type IsRecord<T> = T extends LeafType ? false : T extends readonly unknown[] ? false : T extends object ? true : false;
8
- type IsArray<T> = T extends readonly unknown[] ? true : false;
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);
44
- }[keyof T & string] : never;
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;
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;
47
-
48
- type ValidationMode = "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
49
- type ValidationTrigger = "change" | "blur";
50
- declare const shouldValidateOn: (trigger: ValidationTrigger, mode: ValidationMode, reValidateMode: ValidationMode, submitAttempted: boolean, touched?: boolean) => boolean;
51
-
52
- type ErrorMap = Readonly<Record<string, readonly string[]>>;
53
- type BoolMap = Readonly<Record<string, boolean>>;
54
- type FormState<TValues> = Readonly<{
55
- values: TValues;
56
- initialValues: TValues;
57
- errors: ErrorMap;
58
- schemaErrors: ErrorMap;
59
- serverErrors: ErrorMap;
60
- touched: BoolMap;
61
- isSubmitting: boolean;
62
- submitCount: number;
63
- isValidating: BoolMap;
64
- isValidatingForm: boolean;
65
- mode: ValidationMode;
66
- reValidateMode: ValidationMode;
67
- }>;
68
-
69
- type SettledValidationResult<TOutput> = Readonly<{
70
- kind: "valid";
71
- data: TOutput;
72
- }> | Readonly<{
73
- kind: "invalid";
74
- errors: ErrorMap;
75
- }>;
76
- type ValidationResult<TOutput> = SettledValidationResult<TOutput> | Readonly<{
77
- kind: "pending";
78
- promise: Promise<SettledValidationResult<TOutput>>;
79
- }>;
80
- type SettledFieldValidationResult = Readonly<{
81
- kind: "valid";
82
- }> | Readonly<{
83
- kind: "invalid";
84
- errors: readonly string[];
85
- }>;
86
- type FieldValidationResult = SettledFieldValidationResult | Readonly<{
87
- kind: "pending";
88
- promise: Promise<SettledFieldValidationResult>;
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
- }>;
100
- declare const flattenIssues: (issues: readonly z.core.$ZodIssue[]) => ErrorMap;
101
- declare const validateSync: <TSchema extends z.ZodType>(schema: TSchema, values: z.input<TSchema>) => SettledValidationResult<z.output<TSchema>>;
102
- declare const validateAsync: <TSchema extends z.ZodType>(schema: TSchema, values: z.input<TSchema>) => Promise<SettledValidationResult<z.output<TSchema>>>;
103
- declare const isAsyncRequiredError: (e: unknown) => boolean;
104
- declare const emptyValueForSchema: (schema: z.ZodType) => null | undefined;
105
-
106
- type ReadonlyStoreApi<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
107
- type CreateFormOptions<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
108
- initialValues: z.input<TSchema>;
109
- pathDepth?: D & (IsUnion<D> extends true ? never : unknown);
110
- mode?: ValidationMode;
111
- reValidateMode?: ValidationMode;
112
- validateOnMount?: boolean;
113
- devtools?: boolean | string;
114
- }>;
115
- type SubmitHandler<TSchema extends z.ZodType> = (data: z.output<TSchema>) => void | Promise<void>;
116
- type InvalidSubmitHandler = (errors: ErrorMap) => void;
117
- type SubmitOptions = Readonly<{
118
- force?: boolean;
119
- }>;
120
- type SubmitResult<TOutput> = Readonly<{
121
- kind: "valid";
122
- data: TOutput;
123
- }> | Readonly<{
124
- kind: "invalid";
125
- errors: ErrorMap;
126
- }> | Readonly<{
127
- kind: "skipped";
128
- }> | Readonly<{
129
- kind: "error";
130
- error: unknown;
131
- }>;
132
- type ArrayItemOf$1<T> = T extends readonly (infer U)[] ? U : never;
133
- type ErrorPath<TValues, D extends PathDepth = DefaultPathDepth> = FieldPath<TValues, D> | "";
134
- type ResetOptions = Readonly<{
135
- keepErrors?: boolean;
136
- keepTouched?: boolean;
137
- keepSubmitCount?: boolean;
138
- }>;
139
- type FieldSnapshot<TValue> = Readonly<{
140
- value: TValue;
141
- error: readonly string[] | undefined;
142
- touched: boolean;
143
- dirty: boolean;
144
- isValidating: boolean;
145
- }>;
146
- type Form<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
147
- "~pathDepth"?: D;
148
- schema: TSchema;
149
- store: ReadonlyStoreApi<FormState<z.input<TSchema>>>;
150
- getState: () => FormState<z.input<TSchema>>;
151
- subscribe: (listener: (state: FormState<z.input<TSchema>>, prev: FormState<z.input<TSchema>>) => 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;
155
- watchValues: (listener: (values: z.input<TSchema>, previous: z.input<TSchema>) => void) => () => void;
156
- setValue: <P extends FieldPath<z.input<TSchema>, D>>(path: P, value: FieldValue<z.input<TSchema>, P>) => void;
157
- setValues: (next: z.input<TSchema>) => void;
158
- setTouched: (path: FieldPath<z.input<TSchema>, D>, touched?: boolean) => void;
159
- setSubmitting: (value: boolean) => void;
160
- setMode: (mode: ValidationMode) => void;
161
- setReValidateMode: (mode: ValidationMode) => void;
162
- setError: (path: ErrorPath<z.input<TSchema>, D>, errors: string | readonly string[]) => void;
163
- setErrors: (errors: ErrorMap) => void;
164
- clearErrors: (path?: ErrorPath<z.input<TSchema>, D>) => void;
165
- updateState: (updater: (state: FormState<z.input<TSchema>>) => Partial<Omit<FormState<z.input<TSchema>>, "errors">>) => void;
166
- reset: (nextInitial?: Partial<z.input<TSchema>>, options?: ResetOptions) => void;
167
- resetField: (path: FieldPath<z.input<TSchema>, D>) => void;
168
- adoptValues: (values: z.input<TSchema>) => void;
169
- getFieldState: <P extends FieldPath<z.input<TSchema>, D>>(path: P) => FieldSnapshot<FieldValue<z.input<TSchema>, P>>;
170
- validate: () => ValidationResult<z.output<TSchema>>;
171
- validateField: (path: ErrorPath<z.input<TSchema>, D>) => FieldValidationResult;
172
- validateFields: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => FieldsValidationResult;
173
- validateAsync: () => Promise<ValidationResult<z.output<TSchema>>>;
174
- validateFieldAsync: (path: ErrorPath<z.input<TSchema>, D>) => Promise<FieldValidationResult>;
175
- validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => Promise<SettledFieldsValidationResult>;
176
- submit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => Promise<SubmitResult<z.output<TSchema>>>;
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;
182
- handleSubmit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => (event?: {
183
- preventDefault: () => void;
184
- }) => Promise<SubmitResult<z.output<TSchema>>>;
185
- diff: () => Readonly<Record<string, unknown>>;
186
- dirtyFields: () => readonly string[];
187
- snapshot: () => FormState<z.input<TSchema>>;
188
- restore: (snapshot: FormState<z.input<TSchema>>) => void;
189
- }>;
190
- declare const createForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
6
+ import { StoreApi } from 'zustand/vanilla';
191
7
 
192
8
  type PathSegment = string | number;
193
9
  declare const parsePath: (path: string) => readonly PathSegment[];
@@ -255,10 +71,17 @@ type UseFieldReturn<TValue> = Readonly<{
255
71
  validateAsync: () => Promise<FieldValidationResult>;
256
72
  onBlur: () => void;
257
73
  }>;
74
+ declare const inferredCallsOnly$2: unique symbol;
75
+ interface InferredTypeArg$2 {
76
+ readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
77
+ }
258
78
  declare function useField<TSchema extends z.ZodType>(form: FieldFormApi & Readonly<{
259
79
  schema: TSchema;
260
80
  store: ReadonlyStore$2<FormState<z.input<TSchema>>>;
261
81
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
82
+ declare function useField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
83
+ schema: z.ZodType;
84
+ }>, path: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
262
85
  declare function useField<TValue = unknown>(form: FieldFormApi & {
263
86
  readonly schema?: undefined;
264
87
  }, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
@@ -269,10 +92,17 @@ type CommonKeys<V> = keyof V;
269
92
  type AllKeys<V> = V extends unknown ? keyof V : never;
270
93
  type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
271
94
  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;
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>;
95
+ declare const inferredCallsOnly$1: unique symbol;
96
+ interface InferredTypeArg$1 {
97
+ readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
98
+ }
99
+ declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi & Readonly<{
100
+ schema: z.ZodType;
101
+ }>, unionPath: TValue extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
273
102
  declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
274
103
  readonly schema?: undefined;
275
104
  }, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
105
+ 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>;
276
106
 
277
107
  type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
278
108
  type FieldArrayFormApi = Readonly<{
@@ -300,10 +130,17 @@ type UseFieldArrayReturn<TItem> = Readonly<{
300
130
  swap: (a: number, b: number) => void;
301
131
  }>;
302
132
  type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
133
+ declare const inferredCallsOnly: unique symbol;
134
+ interface InferredTypeArg {
135
+ readonly [inferredCallsOnly]: typeof inferredCallsOnly;
136
+ }
303
137
  declare function useFieldArray<TSchema extends z.ZodType>(form: FieldArrayFormApi & Readonly<{
304
138
  schema: TSchema;
305
139
  store: ReadonlyStore$1<FormState<z.input<TSchema>>>;
306
140
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
141
+ declare function useFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
142
+ schema: z.ZodType;
143
+ }>, path: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
307
144
  declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
308
145
  readonly schema?: undefined;
309
146
  }, path: FieldPathArg<unknown>): UseFieldArrayReturn<TItem>;
@@ -356,6 +193,11 @@ declare function useFormSelectorShallow<U>(form: FormStateApi & {
356
193
  readonly schema?: undefined;
357
194
  }, selector: (state: FormState<unknown>) => U): U;
358
195
 
196
+ declare function useFormValues<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>): z.input<TSchema>;
197
+ declare function useFormValues(form: FormStateApi & {
198
+ readonly schema?: undefined;
199
+ }): unknown;
200
+
359
201
  declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
360
202
 
361
203
  declare function useIsDirty(form: FormStateApi & {
@@ -498,4 +340,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
498
340
  declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
499
341
  declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
500
342
 
501
- 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 NumberInputBinding, 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, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
343
+ export { type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, 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 FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField };
package/dist/index.d.ts CHANGED
@@ -1,193 +1,9 @@
1
+ import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-C9hZffCQ.js';
2
+ export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult, I as InvalidSubmitHandler, R as ReadonlyStoreApi, g as ResetOptions, S as SettledFieldValidationResult, h as SettledFieldsValidationResult, i as SettledValidationResult, j as SubmitHandler, k as SubmitOptions, l as SubmitResult, V as ValidationMode, m as ValidationResult, n as ValidationTrigger, o as createForm, p as emptyValueForSchema, q as flattenIssues, r as isAsyncRequiredError, s as shouldValidateOn, v as validateAsync, t as validateSync } from './createForm-C9hZffCQ.js';
1
3
  import { z } from 'zod';
2
- import { StoreApi } from 'zustand/vanilla';
3
4
  import * as react from 'react';
4
5
  import { ReactNode, ChangeEvent } from 'react';
5
-
6
- type LeafType = string | number | boolean | bigint | symbol | null | undefined | Date | RegExp;
7
- type IsRecord<T> = T extends LeafType ? false : T extends readonly unknown[] ? false : T extends object ? true : false;
8
- type IsArray<T> = T extends readonly unknown[] ? true : false;
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);
44
- }[keyof T & string] : never;
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;
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;
47
-
48
- type ValidationMode = "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
49
- type ValidationTrigger = "change" | "blur";
50
- declare const shouldValidateOn: (trigger: ValidationTrigger, mode: ValidationMode, reValidateMode: ValidationMode, submitAttempted: boolean, touched?: boolean) => boolean;
51
-
52
- type ErrorMap = Readonly<Record<string, readonly string[]>>;
53
- type BoolMap = Readonly<Record<string, boolean>>;
54
- type FormState<TValues> = Readonly<{
55
- values: TValues;
56
- initialValues: TValues;
57
- errors: ErrorMap;
58
- schemaErrors: ErrorMap;
59
- serverErrors: ErrorMap;
60
- touched: BoolMap;
61
- isSubmitting: boolean;
62
- submitCount: number;
63
- isValidating: BoolMap;
64
- isValidatingForm: boolean;
65
- mode: ValidationMode;
66
- reValidateMode: ValidationMode;
67
- }>;
68
-
69
- type SettledValidationResult<TOutput> = Readonly<{
70
- kind: "valid";
71
- data: TOutput;
72
- }> | Readonly<{
73
- kind: "invalid";
74
- errors: ErrorMap;
75
- }>;
76
- type ValidationResult<TOutput> = SettledValidationResult<TOutput> | Readonly<{
77
- kind: "pending";
78
- promise: Promise<SettledValidationResult<TOutput>>;
79
- }>;
80
- type SettledFieldValidationResult = Readonly<{
81
- kind: "valid";
82
- }> | Readonly<{
83
- kind: "invalid";
84
- errors: readonly string[];
85
- }>;
86
- type FieldValidationResult = SettledFieldValidationResult | Readonly<{
87
- kind: "pending";
88
- promise: Promise<SettledFieldValidationResult>;
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
- }>;
100
- declare const flattenIssues: (issues: readonly z.core.$ZodIssue[]) => ErrorMap;
101
- declare const validateSync: <TSchema extends z.ZodType>(schema: TSchema, values: z.input<TSchema>) => SettledValidationResult<z.output<TSchema>>;
102
- declare const validateAsync: <TSchema extends z.ZodType>(schema: TSchema, values: z.input<TSchema>) => Promise<SettledValidationResult<z.output<TSchema>>>;
103
- declare const isAsyncRequiredError: (e: unknown) => boolean;
104
- declare const emptyValueForSchema: (schema: z.ZodType) => null | undefined;
105
-
106
- type ReadonlyStoreApi<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
107
- type CreateFormOptions<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
108
- initialValues: z.input<TSchema>;
109
- pathDepth?: D & (IsUnion<D> extends true ? never : unknown);
110
- mode?: ValidationMode;
111
- reValidateMode?: ValidationMode;
112
- validateOnMount?: boolean;
113
- devtools?: boolean | string;
114
- }>;
115
- type SubmitHandler<TSchema extends z.ZodType> = (data: z.output<TSchema>) => void | Promise<void>;
116
- type InvalidSubmitHandler = (errors: ErrorMap) => void;
117
- type SubmitOptions = Readonly<{
118
- force?: boolean;
119
- }>;
120
- type SubmitResult<TOutput> = Readonly<{
121
- kind: "valid";
122
- data: TOutput;
123
- }> | Readonly<{
124
- kind: "invalid";
125
- errors: ErrorMap;
126
- }> | Readonly<{
127
- kind: "skipped";
128
- }> | Readonly<{
129
- kind: "error";
130
- error: unknown;
131
- }>;
132
- type ArrayItemOf$1<T> = T extends readonly (infer U)[] ? U : never;
133
- type ErrorPath<TValues, D extends PathDepth = DefaultPathDepth> = FieldPath<TValues, D> | "";
134
- type ResetOptions = Readonly<{
135
- keepErrors?: boolean;
136
- keepTouched?: boolean;
137
- keepSubmitCount?: boolean;
138
- }>;
139
- type FieldSnapshot<TValue> = Readonly<{
140
- value: TValue;
141
- error: readonly string[] | undefined;
142
- touched: boolean;
143
- dirty: boolean;
144
- isValidating: boolean;
145
- }>;
146
- type Form<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
147
- "~pathDepth"?: D;
148
- schema: TSchema;
149
- store: ReadonlyStoreApi<FormState<z.input<TSchema>>>;
150
- getState: () => FormState<z.input<TSchema>>;
151
- subscribe: (listener: (state: FormState<z.input<TSchema>>, prev: FormState<z.input<TSchema>>) => 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;
155
- watchValues: (listener: (values: z.input<TSchema>, previous: z.input<TSchema>) => void) => () => void;
156
- setValue: <P extends FieldPath<z.input<TSchema>, D>>(path: P, value: FieldValue<z.input<TSchema>, P>) => void;
157
- setValues: (next: z.input<TSchema>) => void;
158
- setTouched: (path: FieldPath<z.input<TSchema>, D>, touched?: boolean) => void;
159
- setSubmitting: (value: boolean) => void;
160
- setMode: (mode: ValidationMode) => void;
161
- setReValidateMode: (mode: ValidationMode) => void;
162
- setError: (path: ErrorPath<z.input<TSchema>, D>, errors: string | readonly string[]) => void;
163
- setErrors: (errors: ErrorMap) => void;
164
- clearErrors: (path?: ErrorPath<z.input<TSchema>, D>) => void;
165
- updateState: (updater: (state: FormState<z.input<TSchema>>) => Partial<Omit<FormState<z.input<TSchema>>, "errors">>) => void;
166
- reset: (nextInitial?: Partial<z.input<TSchema>>, options?: ResetOptions) => void;
167
- resetField: (path: FieldPath<z.input<TSchema>, D>) => void;
168
- adoptValues: (values: z.input<TSchema>) => void;
169
- getFieldState: <P extends FieldPath<z.input<TSchema>, D>>(path: P) => FieldSnapshot<FieldValue<z.input<TSchema>, P>>;
170
- validate: () => ValidationResult<z.output<TSchema>>;
171
- validateField: (path: ErrorPath<z.input<TSchema>, D>) => FieldValidationResult;
172
- validateFields: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => FieldsValidationResult;
173
- validateAsync: () => Promise<ValidationResult<z.output<TSchema>>>;
174
- validateFieldAsync: (path: ErrorPath<z.input<TSchema>, D>) => Promise<FieldValidationResult>;
175
- validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => Promise<SettledFieldsValidationResult>;
176
- submit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => Promise<SubmitResult<z.output<TSchema>>>;
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;
182
- handleSubmit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => (event?: {
183
- preventDefault: () => void;
184
- }) => Promise<SubmitResult<z.output<TSchema>>>;
185
- diff: () => Readonly<Record<string, unknown>>;
186
- dirtyFields: () => readonly string[];
187
- snapshot: () => FormState<z.input<TSchema>>;
188
- restore: (snapshot: FormState<z.input<TSchema>>) => void;
189
- }>;
190
- declare const createForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
6
+ import { StoreApi } from 'zustand/vanilla';
191
7
 
192
8
  type PathSegment = string | number;
193
9
  declare const parsePath: (path: string) => readonly PathSegment[];
@@ -255,10 +71,17 @@ type UseFieldReturn<TValue> = Readonly<{
255
71
  validateAsync: () => Promise<FieldValidationResult>;
256
72
  onBlur: () => void;
257
73
  }>;
74
+ declare const inferredCallsOnly$2: unique symbol;
75
+ interface InferredTypeArg$2 {
76
+ readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
77
+ }
258
78
  declare function useField<TSchema extends z.ZodType>(form: FieldFormApi & Readonly<{
259
79
  schema: TSchema;
260
80
  store: ReadonlyStore$2<FormState<z.input<TSchema>>>;
261
81
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
82
+ declare function useField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
83
+ schema: z.ZodType;
84
+ }>, path: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
262
85
  declare function useField<TValue = unknown>(form: FieldFormApi & {
263
86
  readonly schema?: undefined;
264
87
  }, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
@@ -269,10 +92,17 @@ type CommonKeys<V> = keyof V;
269
92
  type AllKeys<V> = V extends unknown ? keyof V : never;
270
93
  type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
271
94
  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;
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>;
95
+ declare const inferredCallsOnly$1: unique symbol;
96
+ interface InferredTypeArg$1 {
97
+ readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
98
+ }
99
+ declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi & Readonly<{
100
+ schema: z.ZodType;
101
+ }>, unionPath: TValue extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
273
102
  declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
274
103
  readonly schema?: undefined;
275
104
  }, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
105
+ 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>;
276
106
 
277
107
  type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
278
108
  type FieldArrayFormApi = Readonly<{
@@ -300,10 +130,17 @@ type UseFieldArrayReturn<TItem> = Readonly<{
300
130
  swap: (a: number, b: number) => void;
301
131
  }>;
302
132
  type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
133
+ declare const inferredCallsOnly: unique symbol;
134
+ interface InferredTypeArg {
135
+ readonly [inferredCallsOnly]: typeof inferredCallsOnly;
136
+ }
303
137
  declare function useFieldArray<TSchema extends z.ZodType>(form: FieldArrayFormApi & Readonly<{
304
138
  schema: TSchema;
305
139
  store: ReadonlyStore$1<FormState<z.input<TSchema>>>;
306
140
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
141
+ declare function useFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
142
+ schema: z.ZodType;
143
+ }>, path: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
307
144
  declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
308
145
  readonly schema?: undefined;
309
146
  }, path: FieldPathArg<unknown>): UseFieldArrayReturn<TItem>;
@@ -356,6 +193,11 @@ declare function useFormSelectorShallow<U>(form: FormStateApi & {
356
193
  readonly schema?: undefined;
357
194
  }, selector: (state: FormState<unknown>) => U): U;
358
195
 
196
+ declare function useFormValues<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>): z.input<TSchema>;
197
+ declare function useFormValues(form: FormStateApi & {
198
+ readonly schema?: undefined;
199
+ }): unknown;
200
+
359
201
  declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
360
202
 
361
203
  declare function useIsDirty(form: FormStateApi & {
@@ -498,4 +340,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
498
340
  declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
499
341
  declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
500
342
 
501
- 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 NumberInputBinding, 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, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
343
+ export { type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, 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 FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField };