formstand 0.6.0 → 0.8.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 +236 -0
- package/dist/index.cjs +190 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -59
- package/dist/index.d.ts +90 -59
- package/dist/index.js +191 -148
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.d.cts
CHANGED
|
@@ -162,34 +162,8 @@ type FormContextApi<TSchema extends z.ZodType> = Readonly<{
|
|
|
162
162
|
declare const createFormContext: <TSchema extends z.ZodType>() => FormContextApi<TSchema>;
|
|
163
163
|
|
|
164
164
|
type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
165
|
-
type FormStateApi = Readonly<{
|
|
166
|
-
store: ReadonlyStore$2<FormState<unknown>>;
|
|
167
|
-
}>;
|
|
168
|
-
declare function useFormSelector<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
|
|
169
|
-
declare function useFormSelector<U>(form: FormStateApi & {
|
|
170
|
-
readonly schema?: undefined;
|
|
171
|
-
}, selector: (state: FormState<unknown>) => U): U;
|
|
172
|
-
declare function useFormSelectorShallow<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
|
|
173
|
-
declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
174
|
-
readonly schema?: undefined;
|
|
175
|
-
}, selector: (state: FormState<unknown>) => U): U;
|
|
176
|
-
|
|
177
|
-
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
178
|
-
|
|
179
|
-
declare function useIsDirty(form: FormStateApi & {
|
|
180
|
-
readonly schema?: undefined;
|
|
181
|
-
}, path?: string): boolean;
|
|
182
|
-
declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
183
|
-
declare function useIsValid(form: FormStateApi & {
|
|
184
|
-
readonly schema?: undefined;
|
|
185
|
-
}, path?: string): boolean;
|
|
186
|
-
declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
187
|
-
declare const useIsSubmitting: (form: FormStateApi) => boolean;
|
|
188
|
-
declare const useSubmitCount: (form: FormStateApi) => number;
|
|
189
|
-
|
|
190
|
-
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
191
165
|
type FieldFormApi = Readonly<{
|
|
192
|
-
store: ReadonlyStore$
|
|
166
|
+
store: ReadonlyStore$2<FormState<unknown>>;
|
|
193
167
|
setValue(path: string, value: unknown): void;
|
|
194
168
|
setTouched(path: string, touched?: boolean): void;
|
|
195
169
|
setError(path: string, errors: string | readonly string[]): void;
|
|
@@ -224,6 +198,94 @@ declare function useField<TValue = unknown>(form: FieldFormApi & {
|
|
|
224
198
|
}, path: string | ((state: FormState<unknown>) => string), options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
225
199
|
declare function useField<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
|
|
226
200
|
|
|
201
|
+
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
202
|
+
type FieldArrayFormApi = Readonly<{
|
|
203
|
+
store: ReadonlyStore$1<FormState<unknown>>;
|
|
204
|
+
arrayPush(path: string, item: unknown): void;
|
|
205
|
+
arrayRemove(path: string, index: number): void;
|
|
206
|
+
arrayInsert(path: string, index: number, item: unknown): void;
|
|
207
|
+
arrayMove(path: string, from: number, to: number): void;
|
|
208
|
+
arraySwap(path: string, a: number, b: number): void;
|
|
209
|
+
}>;
|
|
210
|
+
type FieldArrayEntry<TItem> = Readonly<{
|
|
211
|
+
id: string;
|
|
212
|
+
value: TItem;
|
|
213
|
+
}>;
|
|
214
|
+
type UseFieldArrayReturn<TItem> = Readonly<{
|
|
215
|
+
fields: readonly FieldArrayEntry<TItem>[];
|
|
216
|
+
items: readonly TItem[];
|
|
217
|
+
length: number;
|
|
218
|
+
error: readonly string[] | undefined;
|
|
219
|
+
push: (item: TItem) => void;
|
|
220
|
+
remove: (index: number) => void;
|
|
221
|
+
insert: (index: number, item: TItem) => void;
|
|
222
|
+
move: (from: number, to: number) => void;
|
|
223
|
+
swap: (a: number, b: number) => void;
|
|
224
|
+
}>;
|
|
225
|
+
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
226
|
+
declare function useFieldArray<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
227
|
+
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
228
|
+
readonly schema?: undefined;
|
|
229
|
+
}, path: string | ((state: FormState<unknown>) => string)): UseFieldArrayReturn<TItem>;
|
|
230
|
+
declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
231
|
+
|
|
232
|
+
type BoundUseField<TSchema extends z.ZodType> = {
|
|
233
|
+
(pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
|
|
234
|
+
<P extends FieldPath<z.input<TSchema>>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
|
|
235
|
+
};
|
|
236
|
+
type BoundUseFieldArray<TSchema extends z.ZodType> = {
|
|
237
|
+
(pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
238
|
+
<P extends FieldPath<z.input<TSchema>>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
239
|
+
};
|
|
240
|
+
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>>) => boolean;
|
|
242
|
+
type FormHooks<TSchema extends z.ZodType, N extends string> = Readonly<{
|
|
243
|
+
[K in `use${Capitalize<N>}Field`]: BoundUseField<TSchema>;
|
|
244
|
+
} & {
|
|
245
|
+
[K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema>;
|
|
246
|
+
} & {
|
|
247
|
+
[K in `use${Capitalize<N>}Selector`]: BoundUseSelector<TSchema>;
|
|
248
|
+
} & {
|
|
249
|
+
[K in `use${Capitalize<N>}SelectorShallow`]: BoundUseSelector<TSchema>;
|
|
250
|
+
} & {
|
|
251
|
+
[K in `use${Capitalize<N>}Error`]: () => readonly string[] | undefined;
|
|
252
|
+
} & {
|
|
253
|
+
[K in `use${Capitalize<N>}IsDirty`]: BoundUseFlag<TSchema>;
|
|
254
|
+
} & {
|
|
255
|
+
[K in `use${Capitalize<N>}IsValid`]: BoundUseFlag<TSchema>;
|
|
256
|
+
} & {
|
|
257
|
+
[K in `use${Capitalize<N>}IsSubmitting`]: () => boolean;
|
|
258
|
+
} & {
|
|
259
|
+
[K in `use${Capitalize<N>}SubmitCount`]: () => number;
|
|
260
|
+
}>;
|
|
261
|
+
declare const createFormHooks: <TSchema extends z.ZodType, N extends string = "">(form: Form<TSchema>, name?: N) => FormHooks<TSchema, N>;
|
|
262
|
+
|
|
263
|
+
type ReadonlyStore<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
264
|
+
type FormStateApi = Readonly<{
|
|
265
|
+
store: ReadonlyStore<FormState<unknown>>;
|
|
266
|
+
}>;
|
|
267
|
+
declare function useFormSelector<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
|
|
268
|
+
declare function useFormSelector<U>(form: FormStateApi & {
|
|
269
|
+
readonly schema?: undefined;
|
|
270
|
+
}, 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;
|
|
272
|
+
declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
273
|
+
readonly schema?: undefined;
|
|
274
|
+
}, selector: (state: FormState<unknown>) => U): U;
|
|
275
|
+
|
|
276
|
+
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
277
|
+
|
|
278
|
+
declare function useIsDirty(form: FormStateApi & {
|
|
279
|
+
readonly schema?: undefined;
|
|
280
|
+
}, path?: string): boolean;
|
|
281
|
+
declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
282
|
+
declare function useIsValid(form: FormStateApi & {
|
|
283
|
+
readonly schema?: undefined;
|
|
284
|
+
}, path?: string): boolean;
|
|
285
|
+
declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
286
|
+
declare const useIsSubmitting: (form: FormStateApi) => boolean;
|
|
287
|
+
declare const useSubmitCount: (form: FormStateApi) => number;
|
|
288
|
+
|
|
227
289
|
type PathsOf<F extends FieldFormApi> = F extends Form<infer TSchema extends z.ZodType> ? FieldPath<z.input<TSchema>> : string;
|
|
228
290
|
type FieldRef<T> = ((instance: T | null) => void) | Readonly<{
|
|
229
291
|
current: T | null;
|
|
@@ -270,37 +332,6 @@ declare const SelectField: <T extends string, F extends FieldFormApi>({ form, pa
|
|
|
270
332
|
declare const focusFirstError: (errors: ErrorMap, root?: ParentNode) => boolean;
|
|
271
333
|
declare const focusField: (path: string, root?: ParentNode) => boolean;
|
|
272
334
|
|
|
273
|
-
type ReadonlyStore<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
274
|
-
type FieldArrayFormApi = Readonly<{
|
|
275
|
-
store: ReadonlyStore<FormState<unknown>>;
|
|
276
|
-
arrayPush(path: string, item: unknown): void;
|
|
277
|
-
arrayRemove(path: string, index: number): void;
|
|
278
|
-
arrayInsert(path: string, index: number, item: unknown): void;
|
|
279
|
-
arrayMove(path: string, from: number, to: number): void;
|
|
280
|
-
arraySwap(path: string, a: number, b: number): void;
|
|
281
|
-
}>;
|
|
282
|
-
type FieldArrayEntry<TItem> = Readonly<{
|
|
283
|
-
id: string;
|
|
284
|
-
value: TItem;
|
|
285
|
-
}>;
|
|
286
|
-
type UseFieldArrayReturn<TItem> = Readonly<{
|
|
287
|
-
fields: readonly FieldArrayEntry<TItem>[];
|
|
288
|
-
items: readonly TItem[];
|
|
289
|
-
length: number;
|
|
290
|
-
error: readonly string[] | undefined;
|
|
291
|
-
push: (item: TItem) => void;
|
|
292
|
-
remove: (index: number) => void;
|
|
293
|
-
insert: (index: number, item: TItem) => void;
|
|
294
|
-
move: (from: number, to: number) => void;
|
|
295
|
-
swap: (a: number, b: number) => void;
|
|
296
|
-
}>;
|
|
297
|
-
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
298
|
-
declare function useFieldArray<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
299
|
-
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
300
|
-
readonly schema?: undefined;
|
|
301
|
-
}, path: string | ((state: FormState<unknown>) => string)): UseFieldArrayReturn<TItem>;
|
|
302
|
-
declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
303
|
-
|
|
304
335
|
type TextInputProps = Readonly<{
|
|
305
336
|
name: string;
|
|
306
337
|
value: string;
|
|
@@ -346,4 +377,4 @@ declare const numberInputProps: <T extends number | null | undefined>(field: Use
|
|
|
346
377
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
347
378
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
348
379
|
|
|
349
|
-
export { type BoolMap, 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 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, 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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -162,34 +162,8 @@ type FormContextApi<TSchema extends z.ZodType> = Readonly<{
|
|
|
162
162
|
declare const createFormContext: <TSchema extends z.ZodType>() => FormContextApi<TSchema>;
|
|
163
163
|
|
|
164
164
|
type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
165
|
-
type FormStateApi = Readonly<{
|
|
166
|
-
store: ReadonlyStore$2<FormState<unknown>>;
|
|
167
|
-
}>;
|
|
168
|
-
declare function useFormSelector<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
|
|
169
|
-
declare function useFormSelector<U>(form: FormStateApi & {
|
|
170
|
-
readonly schema?: undefined;
|
|
171
|
-
}, selector: (state: FormState<unknown>) => U): U;
|
|
172
|
-
declare function useFormSelectorShallow<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
|
|
173
|
-
declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
174
|
-
readonly schema?: undefined;
|
|
175
|
-
}, selector: (state: FormState<unknown>) => U): U;
|
|
176
|
-
|
|
177
|
-
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
178
|
-
|
|
179
|
-
declare function useIsDirty(form: FormStateApi & {
|
|
180
|
-
readonly schema?: undefined;
|
|
181
|
-
}, path?: string): boolean;
|
|
182
|
-
declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
183
|
-
declare function useIsValid(form: FormStateApi & {
|
|
184
|
-
readonly schema?: undefined;
|
|
185
|
-
}, path?: string): boolean;
|
|
186
|
-
declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
187
|
-
declare const useIsSubmitting: (form: FormStateApi) => boolean;
|
|
188
|
-
declare const useSubmitCount: (form: FormStateApi) => number;
|
|
189
|
-
|
|
190
|
-
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
191
165
|
type FieldFormApi = Readonly<{
|
|
192
|
-
store: ReadonlyStore$
|
|
166
|
+
store: ReadonlyStore$2<FormState<unknown>>;
|
|
193
167
|
setValue(path: string, value: unknown): void;
|
|
194
168
|
setTouched(path: string, touched?: boolean): void;
|
|
195
169
|
setError(path: string, errors: string | readonly string[]): void;
|
|
@@ -224,6 +198,94 @@ declare function useField<TValue = unknown>(form: FieldFormApi & {
|
|
|
224
198
|
}, path: string | ((state: FormState<unknown>) => string), options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
225
199
|
declare function useField<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
|
|
226
200
|
|
|
201
|
+
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
202
|
+
type FieldArrayFormApi = Readonly<{
|
|
203
|
+
store: ReadonlyStore$1<FormState<unknown>>;
|
|
204
|
+
arrayPush(path: string, item: unknown): void;
|
|
205
|
+
arrayRemove(path: string, index: number): void;
|
|
206
|
+
arrayInsert(path: string, index: number, item: unknown): void;
|
|
207
|
+
arrayMove(path: string, from: number, to: number): void;
|
|
208
|
+
arraySwap(path: string, a: number, b: number): void;
|
|
209
|
+
}>;
|
|
210
|
+
type FieldArrayEntry<TItem> = Readonly<{
|
|
211
|
+
id: string;
|
|
212
|
+
value: TItem;
|
|
213
|
+
}>;
|
|
214
|
+
type UseFieldArrayReturn<TItem> = Readonly<{
|
|
215
|
+
fields: readonly FieldArrayEntry<TItem>[];
|
|
216
|
+
items: readonly TItem[];
|
|
217
|
+
length: number;
|
|
218
|
+
error: readonly string[] | undefined;
|
|
219
|
+
push: (item: TItem) => void;
|
|
220
|
+
remove: (index: number) => void;
|
|
221
|
+
insert: (index: number, item: TItem) => void;
|
|
222
|
+
move: (from: number, to: number) => void;
|
|
223
|
+
swap: (a: number, b: number) => void;
|
|
224
|
+
}>;
|
|
225
|
+
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
226
|
+
declare function useFieldArray<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
227
|
+
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
228
|
+
readonly schema?: undefined;
|
|
229
|
+
}, path: string | ((state: FormState<unknown>) => string)): UseFieldArrayReturn<TItem>;
|
|
230
|
+
declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
231
|
+
|
|
232
|
+
type BoundUseField<TSchema extends z.ZodType> = {
|
|
233
|
+
(pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
|
|
234
|
+
<P extends FieldPath<z.input<TSchema>>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
|
|
235
|
+
};
|
|
236
|
+
type BoundUseFieldArray<TSchema extends z.ZodType> = {
|
|
237
|
+
(pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
238
|
+
<P extends FieldPath<z.input<TSchema>>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
239
|
+
};
|
|
240
|
+
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>>) => boolean;
|
|
242
|
+
type FormHooks<TSchema extends z.ZodType, N extends string> = Readonly<{
|
|
243
|
+
[K in `use${Capitalize<N>}Field`]: BoundUseField<TSchema>;
|
|
244
|
+
} & {
|
|
245
|
+
[K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema>;
|
|
246
|
+
} & {
|
|
247
|
+
[K in `use${Capitalize<N>}Selector`]: BoundUseSelector<TSchema>;
|
|
248
|
+
} & {
|
|
249
|
+
[K in `use${Capitalize<N>}SelectorShallow`]: BoundUseSelector<TSchema>;
|
|
250
|
+
} & {
|
|
251
|
+
[K in `use${Capitalize<N>}Error`]: () => readonly string[] | undefined;
|
|
252
|
+
} & {
|
|
253
|
+
[K in `use${Capitalize<N>}IsDirty`]: BoundUseFlag<TSchema>;
|
|
254
|
+
} & {
|
|
255
|
+
[K in `use${Capitalize<N>}IsValid`]: BoundUseFlag<TSchema>;
|
|
256
|
+
} & {
|
|
257
|
+
[K in `use${Capitalize<N>}IsSubmitting`]: () => boolean;
|
|
258
|
+
} & {
|
|
259
|
+
[K in `use${Capitalize<N>}SubmitCount`]: () => number;
|
|
260
|
+
}>;
|
|
261
|
+
declare const createFormHooks: <TSchema extends z.ZodType, N extends string = "">(form: Form<TSchema>, name?: N) => FormHooks<TSchema, N>;
|
|
262
|
+
|
|
263
|
+
type ReadonlyStore<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
264
|
+
type FormStateApi = Readonly<{
|
|
265
|
+
store: ReadonlyStore<FormState<unknown>>;
|
|
266
|
+
}>;
|
|
267
|
+
declare function useFormSelector<TSchema extends z.ZodType, U>(form: Form<TSchema>, selector: (state: FormState<z.input<TSchema>>) => U): U;
|
|
268
|
+
declare function useFormSelector<U>(form: FormStateApi & {
|
|
269
|
+
readonly schema?: undefined;
|
|
270
|
+
}, 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;
|
|
272
|
+
declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
273
|
+
readonly schema?: undefined;
|
|
274
|
+
}, selector: (state: FormState<unknown>) => U): U;
|
|
275
|
+
|
|
276
|
+
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
277
|
+
|
|
278
|
+
declare function useIsDirty(form: FormStateApi & {
|
|
279
|
+
readonly schema?: undefined;
|
|
280
|
+
}, path?: string): boolean;
|
|
281
|
+
declare function useIsDirty<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
282
|
+
declare function useIsValid(form: FormStateApi & {
|
|
283
|
+
readonly schema?: undefined;
|
|
284
|
+
}, path?: string): boolean;
|
|
285
|
+
declare function useIsValid<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path?: P): boolean;
|
|
286
|
+
declare const useIsSubmitting: (form: FormStateApi) => boolean;
|
|
287
|
+
declare const useSubmitCount: (form: FormStateApi) => number;
|
|
288
|
+
|
|
227
289
|
type PathsOf<F extends FieldFormApi> = F extends Form<infer TSchema extends z.ZodType> ? FieldPath<z.input<TSchema>> : string;
|
|
228
290
|
type FieldRef<T> = ((instance: T | null) => void) | Readonly<{
|
|
229
291
|
current: T | null;
|
|
@@ -270,37 +332,6 @@ declare const SelectField: <T extends string, F extends FieldFormApi>({ form, pa
|
|
|
270
332
|
declare const focusFirstError: (errors: ErrorMap, root?: ParentNode) => boolean;
|
|
271
333
|
declare const focusField: (path: string, root?: ParentNode) => boolean;
|
|
272
334
|
|
|
273
|
-
type ReadonlyStore<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
274
|
-
type FieldArrayFormApi = Readonly<{
|
|
275
|
-
store: ReadonlyStore<FormState<unknown>>;
|
|
276
|
-
arrayPush(path: string, item: unknown): void;
|
|
277
|
-
arrayRemove(path: string, index: number): void;
|
|
278
|
-
arrayInsert(path: string, index: number, item: unknown): void;
|
|
279
|
-
arrayMove(path: string, from: number, to: number): void;
|
|
280
|
-
arraySwap(path: string, a: number, b: number): void;
|
|
281
|
-
}>;
|
|
282
|
-
type FieldArrayEntry<TItem> = Readonly<{
|
|
283
|
-
id: string;
|
|
284
|
-
value: TItem;
|
|
285
|
-
}>;
|
|
286
|
-
type UseFieldArrayReturn<TItem> = Readonly<{
|
|
287
|
-
fields: readonly FieldArrayEntry<TItem>[];
|
|
288
|
-
items: readonly TItem[];
|
|
289
|
-
length: number;
|
|
290
|
-
error: readonly string[] | undefined;
|
|
291
|
-
push: (item: TItem) => void;
|
|
292
|
-
remove: (index: number) => void;
|
|
293
|
-
insert: (index: number, item: TItem) => void;
|
|
294
|
-
move: (from: number, to: number) => void;
|
|
295
|
-
swap: (a: number, b: number) => void;
|
|
296
|
-
}>;
|
|
297
|
-
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
298
|
-
declare function useFieldArray<TSchema extends z.ZodType>(form: Form<TSchema>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
299
|
-
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
300
|
-
readonly schema?: undefined;
|
|
301
|
-
}, path: string | ((state: FormState<unknown>) => string)): UseFieldArrayReturn<TItem>;
|
|
302
|
-
declare function useFieldArray<TSchema extends z.ZodType, P extends FieldPath<z.input<TSchema>>>(form: Form<TSchema>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
303
|
-
|
|
304
335
|
type TextInputProps = Readonly<{
|
|
305
336
|
name: string;
|
|
306
337
|
value: string;
|
|
@@ -346,4 +377,4 @@ declare const numberInputProps: <T extends number | null | undefined>(field: Use
|
|
|
346
377
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
347
378
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
348
379
|
|
|
349
|
-
export { type BoolMap, 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 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, 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 };
|
|
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 };
|