formstand 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/README.md +88 -386
- package/dist/chunk-N7WPXYCU.js +144 -0
- package/dist/chunk-N7WPXYCU.js.map +1 -0
- package/dist/createForm-C9hZffCQ.d.cts +190 -0
- package/dist/createForm-C9hZffCQ.d.ts +190 -0
- package/dist/devtools/index.cjs +313 -0
- package/dist/devtools/index.cjs.map +1 -0
- package/dist/devtools/index.d.cts +27 -0
- package/dist/devtools/index.d.ts +27 -0
- package/dist/devtools/index.js +276 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/index.cjs +44 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -188
- package/dist/index.d.ts +5 -188
- package/dist/index.js +47 -143
- package/dist/index.js.map +1 -1
- package/package.json +12 -2
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[];
|
|
@@ -203,6 +19,7 @@ type PersistOptions<TSchema extends z.ZodType> = Readonly<{
|
|
|
203
19
|
key: string;
|
|
204
20
|
storage?: PersistStorage;
|
|
205
21
|
debounceMs?: number;
|
|
22
|
+
version?: string | number;
|
|
206
23
|
apply?: "adopt" | "restore" | "manual";
|
|
207
24
|
}>;
|
|
208
25
|
type PersistHandle = Readonly<{
|
|
@@ -524,4 +341,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
524
341
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
525
342
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
526
343
|
|
|
527
|
-
export { type
|
|
344
|
+
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[];
|
|
@@ -203,6 +19,7 @@ type PersistOptions<TSchema extends z.ZodType> = Readonly<{
|
|
|
203
19
|
key: string;
|
|
204
20
|
storage?: PersistStorage;
|
|
205
21
|
debounceMs?: number;
|
|
22
|
+
version?: string | number;
|
|
206
23
|
apply?: "adopt" | "restore" | "manual";
|
|
207
24
|
}>;
|
|
208
25
|
type PersistHandle = Readonly<{
|
|
@@ -524,4 +341,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
524
341
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
525
342
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
526
343
|
|
|
527
|
-
export { type
|
|
344
|
+
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 };
|