formstand 0.8.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/CHANGELOG.md +511 -1
- package/README.md +19 -14
- package/dist/index.cjs +662 -250
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +166 -55
- package/dist/index.d.ts +166 -55
- package/dist/index.js +658 -253
- package/dist/index.js.map +1 -1
- package/package.json +11 -2
package/dist/index.d.cts
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 = [
|
|
10
|
-
|
|
11
|
-
|
|
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,11 +104,13 @@ 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;
|
|
113
|
+
devtools?: boolean | string;
|
|
70
114
|
}>;
|
|
71
115
|
type SubmitHandler<TSchema extends z.ZodType> = (data: z.output<TSchema>) => void | Promise<void>;
|
|
72
116
|
type InvalidSubmitHandler = (errors: ErrorMap) => void;
|
|
@@ -86,7 +130,7 @@ type SubmitResult<TOutput> = Readonly<{
|
|
|
86
130
|
error: unknown;
|
|
87
131
|
}>;
|
|
88
132
|
type ArrayItemOf$1<T> = T extends readonly (infer U)[] ? U : never;
|
|
89
|
-
type ErrorPath<TValues> = FieldPath<TValues> | "";
|
|
133
|
+
type ErrorPath<TValues, D extends PathDepth = DefaultPathDepth> = FieldPath<TValues, D> | "";
|
|
90
134
|
type ResetOptions = Readonly<{
|
|
91
135
|
keepErrors?: boolean;
|
|
92
136
|
keepTouched?: boolean;
|
|
@@ -99,41 +143,42 @@ type FieldSnapshot<TValue> = Readonly<{
|
|
|
99
143
|
dirty: boolean;
|
|
100
144
|
isValidating: boolean;
|
|
101
145
|
}>;
|
|
102
|
-
type Form<TSchema extends z.ZodType> = Readonly<{
|
|
146
|
+
type Form<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
147
|
+
"~pathDepth"?: D;
|
|
103
148
|
schema: TSchema;
|
|
104
149
|
store: ReadonlyStoreApi<FormState<z.input<TSchema>>>;
|
|
105
150
|
getState: () => FormState<z.input<TSchema>>;
|
|
106
151
|
subscribe: (listener: (state: FormState<z.input<TSchema>>, prev: FormState<z.input<TSchema>>) => void) => () => void;
|
|
107
|
-
getField: <P extends FieldPath<z.input<TSchema
|
|
108
|
-
watchField: <P extends FieldPath<z.input<TSchema
|
|
109
|
-
watchValue: <P extends FieldPath<z.input<TSchema
|
|
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;
|
|
110
155
|
watchValues: (listener: (values: z.input<TSchema>, previous: z.input<TSchema>) => void) => () => void;
|
|
111
|
-
setValue: <P extends FieldPath<z.input<TSchema
|
|
156
|
+
setValue: <P extends FieldPath<z.input<TSchema>, D>>(path: P, value: FieldValue<z.input<TSchema>, P>) => void;
|
|
112
157
|
setValues: (next: z.input<TSchema>) => void;
|
|
113
|
-
setTouched: (path: FieldPath<z.input<TSchema
|
|
158
|
+
setTouched: (path: FieldPath<z.input<TSchema>, D>, touched?: boolean) => void;
|
|
114
159
|
setSubmitting: (value: boolean) => void;
|
|
115
160
|
setMode: (mode: ValidationMode) => void;
|
|
116
161
|
setReValidateMode: (mode: ValidationMode) => void;
|
|
117
|
-
setError: (path: ErrorPath<z.input<TSchema
|
|
162
|
+
setError: (path: ErrorPath<z.input<TSchema>, D>, errors: string | readonly string[]) => void;
|
|
118
163
|
setErrors: (errors: ErrorMap) => void;
|
|
119
|
-
clearErrors: (path?: ErrorPath<z.input<TSchema
|
|
164
|
+
clearErrors: (path?: ErrorPath<z.input<TSchema>, D>) => void;
|
|
120
165
|
updateState: (updater: (state: FormState<z.input<TSchema>>) => Partial<Omit<FormState<z.input<TSchema>>, "errors">>) => void;
|
|
121
166
|
reset: (nextInitial?: Partial<z.input<TSchema>>, options?: ResetOptions) => void;
|
|
122
|
-
resetField: (path: FieldPath<z.input<TSchema
|
|
167
|
+
resetField: (path: FieldPath<z.input<TSchema>, D>) => void;
|
|
123
168
|
adoptValues: (values: z.input<TSchema>) => void;
|
|
124
|
-
getFieldState: <P extends FieldPath<z.input<TSchema
|
|
169
|
+
getFieldState: <P extends FieldPath<z.input<TSchema>, D>>(path: P) => FieldSnapshot<FieldValue<z.input<TSchema>, P>>;
|
|
125
170
|
validate: () => ValidationResult<z.output<TSchema>>;
|
|
126
|
-
validateField: (path: ErrorPath<z.input<TSchema
|
|
127
|
-
validateFields: (paths: readonly FieldPath<z.input<TSchema
|
|
171
|
+
validateField: (path: ErrorPath<z.input<TSchema>, D>) => FieldValidationResult;
|
|
172
|
+
validateFields: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => FieldsValidationResult;
|
|
128
173
|
validateAsync: () => Promise<ValidationResult<z.output<TSchema>>>;
|
|
129
|
-
validateFieldAsync: (path: ErrorPath<z.input<TSchema
|
|
130
|
-
validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema
|
|
174
|
+
validateFieldAsync: (path: ErrorPath<z.input<TSchema>, D>) => Promise<FieldValidationResult>;
|
|
175
|
+
validateFieldsAsync: (paths: readonly FieldPath<z.input<TSchema>, D>[]) => Promise<SettledFieldsValidationResult>;
|
|
131
176
|
submit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => Promise<SubmitResult<z.output<TSchema>>>;
|
|
132
|
-
arrayPush: <P extends FieldPath<z.input<TSchema
|
|
133
|
-
arrayRemove: (path: FieldPath<z.input<TSchema
|
|
134
|
-
arrayInsert: <P extends FieldPath<z.input<TSchema
|
|
135
|
-
arrayMove: (path: FieldPath<z.input<TSchema
|
|
136
|
-
arraySwap: (path: FieldPath<z.input<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;
|
|
137
182
|
handleSubmit: (onValid: SubmitHandler<TSchema>, onInvalid?: InvalidSubmitHandler, options?: SubmitOptions) => (event?: {
|
|
138
183
|
preventDefault: () => void;
|
|
139
184
|
}) => Promise<SubmitResult<z.output<TSchema>>>;
|
|
@@ -142,24 +187,42 @@ type Form<TSchema extends z.ZodType> = Readonly<{
|
|
|
142
187
|
snapshot: () => FormState<z.input<TSchema>>;
|
|
143
188
|
restore: (snapshot: FormState<z.input<TSchema>>) => void;
|
|
144
189
|
}>;
|
|
145
|
-
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>;
|
|
146
191
|
|
|
147
192
|
type PathSegment = string | number;
|
|
148
193
|
declare const parsePath: (path: string) => readonly PathSegment[];
|
|
149
194
|
declare const getAtPath: (obj: unknown, path: string) => unknown;
|
|
150
195
|
declare const setAtPath: <T>(obj: T, path: string, value: unknown) => T;
|
|
151
196
|
|
|
152
|
-
|
|
197
|
+
type PersistStorage = Readonly<{
|
|
198
|
+
getItem: (key: string) => string | null;
|
|
199
|
+
setItem: (key: string, value: string) => void;
|
|
200
|
+
removeItem: (key: string) => void;
|
|
201
|
+
}>;
|
|
202
|
+
type PersistOptions<TSchema extends z.ZodType> = Readonly<{
|
|
203
|
+
key: string;
|
|
204
|
+
storage?: PersistStorage;
|
|
205
|
+
debounceMs?: number;
|
|
206
|
+
apply?: "adopt" | "restore" | "manual";
|
|
207
|
+
}>;
|
|
208
|
+
type PersistHandle = Readonly<{
|
|
209
|
+
restore: () => boolean;
|
|
210
|
+
clear: () => void;
|
|
211
|
+
dispose: () => void;
|
|
212
|
+
}>;
|
|
213
|
+
declare const persistForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, options: PersistOptions<TSchema>) => PersistHandle;
|
|
153
214
|
|
|
154
|
-
|
|
155
|
-
|
|
215
|
+
declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
|
|
216
|
+
|
|
217
|
+
type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
218
|
+
form: Form<TSchema, D>;
|
|
156
219
|
children: ReactNode;
|
|
157
220
|
}>;
|
|
158
|
-
type FormContextApi<TSchema extends z.ZodType> = Readonly<{
|
|
159
|
-
Provider: (props: FormProviderProps<TSchema>) => ReactNode;
|
|
160
|
-
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>;
|
|
161
224
|
}>;
|
|
162
|
-
declare const createFormContext: <TSchema extends z.ZodType>() => FormContextApi<TSchema>;
|
|
225
|
+
declare const createFormContext: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>() => FormContextApi<TSchema, D>;
|
|
163
226
|
|
|
164
227
|
type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
165
228
|
type FieldFormApi = Readonly<{
|
|
@@ -192,11 +255,24 @@ type UseFieldReturn<TValue> = Readonly<{
|
|
|
192
255
|
validateAsync: () => Promise<FieldValidationResult>;
|
|
193
256
|
onBlur: () => void;
|
|
194
257
|
}>;
|
|
195
|
-
declare function useField<TSchema extends z.ZodType>(form:
|
|
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>;
|
|
196
262
|
declare function useField<TValue = unknown>(form: FieldFormApi & {
|
|
197
263
|
readonly schema?: undefined;
|
|
198
|
-
}, path:
|
|
199
|
-
declare function useField<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema
|
|
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>>;
|
|
266
|
+
|
|
267
|
+
type VariantFieldValue<V, TField extends string> = V extends unknown ? TField extends keyof V ? V[TField] : never : never;
|
|
268
|
+
type CommonKeys<V> = keyof V;
|
|
269
|
+
type AllKeys<V> = V extends unknown ? keyof V : never;
|
|
270
|
+
type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
|
|
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;
|
|
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>;
|
|
273
|
+
declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
|
|
274
|
+
readonly schema?: undefined;
|
|
275
|
+
}, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
|
|
200
276
|
|
|
201
277
|
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
202
278
|
type FieldArrayFormApi = Readonly<{
|
|
@@ -223,26 +299,32 @@ type UseFieldArrayReturn<TItem> = Readonly<{
|
|
|
223
299
|
swap: (a: number, b: number) => void;
|
|
224
300
|
}>;
|
|
225
301
|
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
226
|
-
declare function useFieldArray<TSchema extends z.ZodType>(form:
|
|
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>;
|
|
227
306
|
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
228
307
|
readonly schema?: undefined;
|
|
229
|
-
}, path:
|
|
230
|
-
declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema
|
|
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>>>;
|
|
231
310
|
|
|
232
|
-
type BoundUseField<TSchema extends z.ZodType> = {
|
|
311
|
+
type BoundUseField<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
|
|
233
312
|
(pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
|
|
234
|
-
<P extends FieldPath<z.input<TSchema
|
|
313
|
+
<P extends FieldPath<z.input<TSchema>, D>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
|
|
235
314
|
};
|
|
236
|
-
type
|
|
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>;
|
|
316
|
+
type BoundUseFieldArray<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
|
|
237
317
|
(pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
238
|
-
<P extends FieldPath<z.input<TSchema
|
|
318
|
+
<P extends FieldPath<z.input<TSchema>, D>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
239
319
|
};
|
|
240
320
|
type BoundUseSelector<TSchema extends z.ZodType> = <U>(selector: (state: FormState<z.input<TSchema>>) => U) => U;
|
|
241
|
-
type BoundUseFlag<TSchema extends z.ZodType> = (path?: FieldPath<z.input<TSchema
|
|
242
|
-
type FormHooks<TSchema extends z.ZodType, N extends string> = Readonly<{
|
|
243
|
-
[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>;
|
|
324
|
+
} & {
|
|
325
|
+
[K in `use${Capitalize<N>}VariantField`]: BoundUseVariantField<TSchema>;
|
|
244
326
|
} & {
|
|
245
|
-
[K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema>;
|
|
327
|
+
[K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema, D>;
|
|
246
328
|
} & {
|
|
247
329
|
[K in `use${Capitalize<N>}Selector`]: BoundUseSelector<TSchema>;
|
|
248
330
|
} & {
|
|
@@ -250,25 +332,25 @@ type FormHooks<TSchema extends z.ZodType, N extends string> = Readonly<{
|
|
|
250
332
|
} & {
|
|
251
333
|
[K in `use${Capitalize<N>}Error`]: () => readonly string[] | undefined;
|
|
252
334
|
} & {
|
|
253
|
-
[K in `use${Capitalize<N>}IsDirty`]: BoundUseFlag<TSchema>;
|
|
335
|
+
[K in `use${Capitalize<N>}IsDirty`]: BoundUseFlag<TSchema, D>;
|
|
254
336
|
} & {
|
|
255
|
-
[K in `use${Capitalize<N>}IsValid`]: BoundUseFlag<TSchema>;
|
|
337
|
+
[K in `use${Capitalize<N>}IsValid`]: BoundUseFlag<TSchema, D>;
|
|
256
338
|
} & {
|
|
257
339
|
[K in `use${Capitalize<N>}IsSubmitting`]: () => boolean;
|
|
258
340
|
} & {
|
|
259
341
|
[K in `use${Capitalize<N>}SubmitCount`]: () => number;
|
|
260
342
|
}>;
|
|
261
|
-
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>;
|
|
262
344
|
|
|
263
345
|
type ReadonlyStore<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
264
346
|
type FormStateApi = Readonly<{
|
|
265
347
|
store: ReadonlyStore<FormState<unknown>>;
|
|
266
348
|
}>;
|
|
267
|
-
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;
|
|
268
350
|
declare function useFormSelector<U>(form: FormStateApi & {
|
|
269
351
|
readonly schema?: undefined;
|
|
270
352
|
}, selector: (state: FormState<unknown>) => U): U;
|
|
271
|
-
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;
|
|
272
354
|
declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
273
355
|
readonly schema?: undefined;
|
|
274
356
|
}, selector: (state: FormState<unknown>) => U): U;
|
|
@@ -278,15 +360,15 @@ declare const useFormError: (form: FormStateApi) => readonly string[] | undefine
|
|
|
278
360
|
declare function useIsDirty(form: FormStateApi & {
|
|
279
361
|
readonly schema?: undefined;
|
|
280
362
|
}, path?: string): boolean;
|
|
281
|
-
declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema
|
|
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;
|
|
282
364
|
declare function useIsValid(form: FormStateApi & {
|
|
283
365
|
readonly schema?: undefined;
|
|
284
366
|
}, path?: string): boolean;
|
|
285
|
-
declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema
|
|
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;
|
|
286
368
|
declare const useIsSubmitting: (form: FormStateApi) => boolean;
|
|
287
369
|
declare const useSubmitCount: (form: FormStateApi) => number;
|
|
288
370
|
|
|
289
|
-
type PathsOf<F extends FieldFormApi> = F extends Form<infer TSchema extends z.ZodType> ? FieldPath<z.input<TSchema
|
|
371
|
+
type PathsOf<F extends FieldFormApi> = F extends Form<infer TSchema extends z.ZodType, infer D extends PathDepth> ? FieldPath<z.input<TSchema>, D> : string;
|
|
290
372
|
type FieldRef<T> = ((instance: T | null) => void) | Readonly<{
|
|
291
373
|
current: T | null;
|
|
292
374
|
}> | null;
|
|
@@ -300,6 +382,15 @@ type TextFieldProps<F extends FieldFormApi = FieldFormApi> = Readonly<{
|
|
|
300
382
|
ref?: FieldRef<HTMLInputElement>;
|
|
301
383
|
}>;
|
|
302
384
|
declare const TextField: <F extends FieldFormApi>({ form, path, label, placeholder, type, autoComplete, ref, }: TextFieldProps<F>) => react.JSX.Element;
|
|
385
|
+
type DateFieldProps<F extends FieldFormApi = FieldFormApi> = Readonly<{
|
|
386
|
+
form: F;
|
|
387
|
+
path: PathsOf<F>;
|
|
388
|
+
label?: ReactNode;
|
|
389
|
+
min?: string;
|
|
390
|
+
max?: string;
|
|
391
|
+
ref?: FieldRef<HTMLInputElement>;
|
|
392
|
+
}>;
|
|
393
|
+
declare const DateField: <F extends FieldFormApi>({ form, path, label, min, max, ref, }: DateFieldProps<F>) => react.JSX.Element;
|
|
303
394
|
type NumberFieldProps<F extends FieldFormApi = FieldFormApi> = Readonly<{
|
|
304
395
|
form: F;
|
|
305
396
|
path: PathsOf<F>;
|
|
@@ -347,6 +438,14 @@ type NumberInputProps = Readonly<{
|
|
|
347
438
|
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
348
439
|
onBlur: () => void;
|
|
349
440
|
}>;
|
|
441
|
+
type DateInputProps = Readonly<{
|
|
442
|
+
type: "date";
|
|
443
|
+
name: string;
|
|
444
|
+
value: string;
|
|
445
|
+
"aria-invalid": true | undefined;
|
|
446
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
447
|
+
onBlur: () => void;
|
|
448
|
+
}>;
|
|
350
449
|
type CheckboxProps = Readonly<{
|
|
351
450
|
type: "checkbox";
|
|
352
451
|
name: string;
|
|
@@ -362,6 +461,7 @@ type SelectProps = Readonly<{
|
|
|
362
461
|
onChange: (e: ChangeEvent<HTMLSelectElement>) => void;
|
|
363
462
|
onBlur: () => void;
|
|
364
463
|
}>;
|
|
464
|
+
declare const hasFieldError: (error: readonly string[] | undefined) => boolean;
|
|
365
465
|
declare const numberToInputText: (value: number | null | undefined) => string;
|
|
366
466
|
type ParsedNumberText = Readonly<{
|
|
367
467
|
kind: "empty";
|
|
@@ -374,7 +474,18 @@ type ParsedNumberText = Readonly<{
|
|
|
374
474
|
declare const parseNumberText: (text: string) => ParsedNumberText;
|
|
375
475
|
declare const textInputProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => TextInputProps;
|
|
376
476
|
declare const numberInputProps: <T extends number | null | undefined>(field: UseFieldReturn<T>) => NumberInputProps;
|
|
477
|
+
declare const dateToInputText: (value: Date | null | undefined) => string;
|
|
478
|
+
type ParsedDateText = Readonly<{
|
|
479
|
+
kind: "empty";
|
|
480
|
+
}> | Readonly<{
|
|
481
|
+
kind: "date";
|
|
482
|
+
value: Date;
|
|
483
|
+
}> | Readonly<{
|
|
484
|
+
kind: "invalid";
|
|
485
|
+
}>;
|
|
486
|
+
declare const parseDateText: (text: string) => ParsedDateText;
|
|
487
|
+
declare const dateInputProps: <T extends Date | null | undefined>(field: UseFieldReturn<T>) => DateInputProps;
|
|
377
488
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
378
489
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
379
490
|
|
|
380
|
-
export { type BoolMap, type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, type CreateFormOptions, 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 ParsedNumberText, type PathSegment, type PathsOf, 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, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, isAsyncRequiredError, numberInputProps, numberToInputText, parseNumberText, parsePath, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useIsDirty, useIsSubmitting, useIsValid, useSubmitCount, 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 };
|