formstand 0.18.0 → 0.20.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 +83 -0
- package/dist/chunk-MQ6262S3.js +20 -0
- package/dist/chunk-MQ6262S3.js.map +1 -0
- package/dist/index.cjs +288 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -17
- package/dist/index.d.ts +72 -17
- package/dist/index.js +280 -115
- package/dist/index.js.map +1 -1
- package/dist/testing/index.cjs +70 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +11 -0
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.js +49 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +11 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-B73p1TgL.cjs';
|
|
2
|
-
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult,
|
|
1
|
+
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, E as ErrorMap } from './createForm-B73p1TgL.cjs';
|
|
2
|
+
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult, R as ReadonlyStoreApi, g as ResetOptions, 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 isClearableSchema, t as shouldValidateOn, v as validateAsync, u as validateSync } from './createForm-B73p1TgL.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as react from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { ChangeEvent, ReactNode } from 'react';
|
|
6
6
|
import { StoreApi } from 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
type PathSegment = string | number;
|
|
@@ -33,16 +33,6 @@ declare const usePersistForm: <TSchema extends z.ZodType, D extends PathDepth =
|
|
|
33
33
|
|
|
34
34
|
declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
|
|
35
35
|
|
|
36
|
-
type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
37
|
-
form: Form<TSchema, D>;
|
|
38
|
-
children: ReactNode;
|
|
39
|
-
}>;
|
|
40
|
-
type FormContextApi<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
41
|
-
Provider: (props: FormProviderProps<TSchema, D>) => ReactNode;
|
|
42
|
-
useFormContext: () => Form<TSchema, D>;
|
|
43
|
-
}>;
|
|
44
|
-
declare const createFormContext: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>() => FormContextApi<TSchema, D>;
|
|
45
|
-
|
|
46
36
|
type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
47
37
|
type FieldFormApi = Readonly<{
|
|
48
38
|
store: ReadonlyStore$2<FormState<unknown>>;
|
|
@@ -92,10 +82,73 @@ declare function useField<TValue = unknown>(form: FieldFormApi & {
|
|
|
92
82
|
}, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
93
83
|
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>>;
|
|
94
84
|
|
|
95
|
-
type
|
|
85
|
+
type MaskedParse<TValue> = Readonly<{
|
|
86
|
+
kind: "value";
|
|
87
|
+
value: TValue;
|
|
88
|
+
}> | Readonly<{
|
|
89
|
+
kind: "empty";
|
|
90
|
+
}> | Readonly<{
|
|
91
|
+
kind: "invalid";
|
|
92
|
+
}>;
|
|
93
|
+
type MaskedInputOptions<TValue> = Readonly<{
|
|
94
|
+
parse: (text: string) => MaskedParse<TValue>;
|
|
95
|
+
format: (value: TValue) => string;
|
|
96
|
+
}>;
|
|
97
|
+
type MaskedInputBinding = Readonly<{
|
|
98
|
+
name: string;
|
|
99
|
+
value: string;
|
|
100
|
+
"aria-invalid": true | undefined;
|
|
101
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
102
|
+
onBlur: () => void;
|
|
103
|
+
}>;
|
|
104
|
+
declare const useMaskedInput: <TValue>(field: UseFieldReturn<TValue>, options: MaskedInputOptions<NonNullable<TValue>>) => MaskedInputBinding;
|
|
105
|
+
|
|
106
|
+
type FormStep<TValues, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
107
|
+
name?: string;
|
|
108
|
+
fields: readonly FieldPath<TValues, D>[];
|
|
109
|
+
}>;
|
|
110
|
+
type StepStatus = Readonly<{
|
|
111
|
+
name: string | undefined;
|
|
112
|
+
visited: boolean;
|
|
113
|
+
hasErrors: boolean;
|
|
114
|
+
}>;
|
|
115
|
+
type UseFormStepsReturn = Readonly<{
|
|
116
|
+
step: number;
|
|
117
|
+
name: string | undefined;
|
|
118
|
+
count: number;
|
|
119
|
+
isFirst: boolean;
|
|
120
|
+
isLast: boolean;
|
|
121
|
+
next: () => Promise<boolean>;
|
|
122
|
+
back: () => void;
|
|
123
|
+
goTo: (target: number) => Promise<number>;
|
|
124
|
+
steps: readonly StepStatus[];
|
|
125
|
+
}>;
|
|
126
|
+
declare const useFormSteps: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, steps: readonly FormStep<z.input<TSchema>, D>[]) => UseFormStepsReturn;
|
|
127
|
+
|
|
128
|
+
type FormActionHandler<TSchema extends z.ZodType> = (data: z.output<TSchema>, formData: FormData) => void | Promise<void>;
|
|
129
|
+
type FormActionStateHandler<TSchema extends z.ZodType, S> = (prevState: S, data: z.output<TSchema>, formData: FormData) => S | Promise<S>;
|
|
130
|
+
type FormActionOptions = Readonly<{
|
|
131
|
+
onInvalid?: InvalidSubmitHandler;
|
|
132
|
+
onError?: (error: unknown) => void;
|
|
133
|
+
}>;
|
|
134
|
+
declare const useFormAction: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, onValid: FormActionHandler<TSchema>, options?: FormActionOptions) => ((formData: FormData) => Promise<void>);
|
|
135
|
+
declare const useFormActionState: <TSchema extends z.ZodType, S, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, action: FormActionStateHandler<TSchema, S>, initialState: S, options?: FormActionOptions) => [state: S, formAction: (formData: FormData) => void, isPending: boolean];
|
|
136
|
+
|
|
137
|
+
type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
138
|
+
form: Form<TSchema, D>;
|
|
139
|
+
children: ReactNode;
|
|
140
|
+
}>;
|
|
141
|
+
type FormContextApi<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
142
|
+
Provider: (props: FormProviderProps<TSchema, D>) => ReactNode;
|
|
143
|
+
useFormContext: () => Form<TSchema, D>;
|
|
144
|
+
}>;
|
|
145
|
+
declare const createFormContext: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>() => FormContextApi<TSchema, D>;
|
|
146
|
+
|
|
147
|
+
type VariantFieldValue<V, TField extends string> = V extends unknown ? FieldValue<V, TField> : never;
|
|
96
148
|
type CommonKeys<V> = keyof V;
|
|
97
149
|
type AllKeys<V> = V extends unknown ? keyof V : never;
|
|
98
150
|
type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
|
|
151
|
+
type VariantFieldPath<V, D extends PathDepth = DefaultPathDepth> = Exclude<V extends unknown ? FieldPath<V, D> : never, (CommonKeys<V> & string) | `${CommonKeys<V> & string}.${string}`> & string;
|
|
99
152
|
type UnionValueAt<TValues, P extends string> = P extends keyof TValues ? NonNullable<TValues[P]> : TValues extends readonly (infer Item)[] ? P extends `${number}` ? NonNullable<Item> : P extends `${infer Head}.${infer Tail}` ? Head extends keyof TValues ? UnionValueAt<NonNullable<TValues[Head]>, Tail> : Head extends `${number}` ? UnionValueAt<NonNullable<Item>, Tail> : never : never : P extends `${infer Head}.${infer Tail}` ? Head extends keyof TValues ? UnionValueAt<NonNullable<TValues[Head]>, Tail> : never : never;
|
|
100
153
|
declare const inferredCallsOnly$1: unique symbol;
|
|
101
154
|
interface InferredTypeArg$1 {
|
|
@@ -107,7 +160,7 @@ declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi
|
|
|
107
160
|
declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
|
|
108
161
|
readonly schema?: undefined;
|
|
109
162
|
}, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
|
|
110
|
-
declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends
|
|
163
|
+
declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends VariantFieldPath<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>;
|
|
111
164
|
|
|
112
165
|
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
113
166
|
type FieldArrayFormApi = Readonly<{
|
|
@@ -177,7 +230,7 @@ type BoundUseField<TSchema extends z.ZodType, D extends PathDepth = DefaultPathD
|
|
|
177
230
|
(pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
|
|
178
231
|
<P extends FieldPath<z.input<TSchema>, D>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
|
|
179
232
|
};
|
|
180
|
-
type BoundUseVariantField<TSchema extends z.ZodType> = <P extends string, TField extends
|
|
233
|
+
type BoundUseVariantField<TSchema extends z.ZodType> = <P extends string, TField extends VariantFieldPath<UnionValueAt<z.input<TSchema>, P>>>(unionPath: P, field: TField) => UseFieldReturn<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField> | undefined>;
|
|
181
234
|
type BoundUseFieldArray<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
|
|
182
235
|
(pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
183
236
|
<P extends FieldPath<z.input<TSchema>, D>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
@@ -210,6 +263,8 @@ type FormHooks<TSchema extends z.ZodType, N extends string, D extends PathDepth
|
|
|
210
263
|
[K in `use${Capitalize<N>}Values`]: () => z.input<TSchema>;
|
|
211
264
|
} & {
|
|
212
265
|
[K in `use${Capitalize<N>}Fields`]: BoundUseFields<TSchema, D>;
|
|
266
|
+
} & {
|
|
267
|
+
[K in `use${Capitalize<N>}Steps`]: (steps: readonly FormStep<z.input<TSchema>, D>[]) => UseFormStepsReturn;
|
|
213
268
|
}>;
|
|
214
269
|
type BoundUseFields<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = <const P extends readonly FieldPath<z.input<TSchema>, D>[]>(paths: P) => UseFieldsReturn<{
|
|
215
270
|
readonly [K in keyof P]: UseFieldReturn<FieldValue<z.input<TSchema>, P[K] & string>>;
|
|
@@ -380,4 +435,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
380
435
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
381
436
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
382
437
|
|
|
383
|
-
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, SettledFieldValidationResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
|
438
|
+
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 FormActionHandler, type FormActionOptions, type FormActionStateHandler, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, type FormStep, InvalidSubmitHandler, type MaskedInputBinding, type MaskedInputOptions, type MaskedParse, 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, SettledFieldValidationResult, type StepStatus, TextField, type TextFieldProps, type TextInputProps, type UnionValueAt, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, type UseFormStepsReturn, type VariantFieldPath, type VariantFieldValue, type VariantKeys, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSelector, useFormSelectorShallow, useFormSteps, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useMaskedInput, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-B73p1TgL.js';
|
|
2
|
-
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult,
|
|
1
|
+
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, E as ErrorMap } from './createForm-B73p1TgL.js';
|
|
2
|
+
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult, R as ReadonlyStoreApi, g as ResetOptions, 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 isClearableSchema, t as shouldValidateOn, v as validateAsync, u as validateSync } from './createForm-B73p1TgL.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as react from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { ChangeEvent, ReactNode } from 'react';
|
|
6
6
|
import { StoreApi } from 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
type PathSegment = string | number;
|
|
@@ -33,16 +33,6 @@ declare const usePersistForm: <TSchema extends z.ZodType, D extends PathDepth =
|
|
|
33
33
|
|
|
34
34
|
declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
|
|
35
35
|
|
|
36
|
-
type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
37
|
-
form: Form<TSchema, D>;
|
|
38
|
-
children: ReactNode;
|
|
39
|
-
}>;
|
|
40
|
-
type FormContextApi<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
41
|
-
Provider: (props: FormProviderProps<TSchema, D>) => ReactNode;
|
|
42
|
-
useFormContext: () => Form<TSchema, D>;
|
|
43
|
-
}>;
|
|
44
|
-
declare const createFormContext: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>() => FormContextApi<TSchema, D>;
|
|
45
|
-
|
|
46
36
|
type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
47
37
|
type FieldFormApi = Readonly<{
|
|
48
38
|
store: ReadonlyStore$2<FormState<unknown>>;
|
|
@@ -92,10 +82,73 @@ declare function useField<TValue = unknown>(form: FieldFormApi & {
|
|
|
92
82
|
}, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
93
83
|
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>>;
|
|
94
84
|
|
|
95
|
-
type
|
|
85
|
+
type MaskedParse<TValue> = Readonly<{
|
|
86
|
+
kind: "value";
|
|
87
|
+
value: TValue;
|
|
88
|
+
}> | Readonly<{
|
|
89
|
+
kind: "empty";
|
|
90
|
+
}> | Readonly<{
|
|
91
|
+
kind: "invalid";
|
|
92
|
+
}>;
|
|
93
|
+
type MaskedInputOptions<TValue> = Readonly<{
|
|
94
|
+
parse: (text: string) => MaskedParse<TValue>;
|
|
95
|
+
format: (value: TValue) => string;
|
|
96
|
+
}>;
|
|
97
|
+
type MaskedInputBinding = Readonly<{
|
|
98
|
+
name: string;
|
|
99
|
+
value: string;
|
|
100
|
+
"aria-invalid": true | undefined;
|
|
101
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
102
|
+
onBlur: () => void;
|
|
103
|
+
}>;
|
|
104
|
+
declare const useMaskedInput: <TValue>(field: UseFieldReturn<TValue>, options: MaskedInputOptions<NonNullable<TValue>>) => MaskedInputBinding;
|
|
105
|
+
|
|
106
|
+
type FormStep<TValues, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
107
|
+
name?: string;
|
|
108
|
+
fields: readonly FieldPath<TValues, D>[];
|
|
109
|
+
}>;
|
|
110
|
+
type StepStatus = Readonly<{
|
|
111
|
+
name: string | undefined;
|
|
112
|
+
visited: boolean;
|
|
113
|
+
hasErrors: boolean;
|
|
114
|
+
}>;
|
|
115
|
+
type UseFormStepsReturn = Readonly<{
|
|
116
|
+
step: number;
|
|
117
|
+
name: string | undefined;
|
|
118
|
+
count: number;
|
|
119
|
+
isFirst: boolean;
|
|
120
|
+
isLast: boolean;
|
|
121
|
+
next: () => Promise<boolean>;
|
|
122
|
+
back: () => void;
|
|
123
|
+
goTo: (target: number) => Promise<number>;
|
|
124
|
+
steps: readonly StepStatus[];
|
|
125
|
+
}>;
|
|
126
|
+
declare const useFormSteps: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, steps: readonly FormStep<z.input<TSchema>, D>[]) => UseFormStepsReturn;
|
|
127
|
+
|
|
128
|
+
type FormActionHandler<TSchema extends z.ZodType> = (data: z.output<TSchema>, formData: FormData) => void | Promise<void>;
|
|
129
|
+
type FormActionStateHandler<TSchema extends z.ZodType, S> = (prevState: S, data: z.output<TSchema>, formData: FormData) => S | Promise<S>;
|
|
130
|
+
type FormActionOptions = Readonly<{
|
|
131
|
+
onInvalid?: InvalidSubmitHandler;
|
|
132
|
+
onError?: (error: unknown) => void;
|
|
133
|
+
}>;
|
|
134
|
+
declare const useFormAction: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, onValid: FormActionHandler<TSchema>, options?: FormActionOptions) => ((formData: FormData) => Promise<void>);
|
|
135
|
+
declare const useFormActionState: <TSchema extends z.ZodType, S, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, action: FormActionStateHandler<TSchema, S>, initialState: S, options?: FormActionOptions) => [state: S, formAction: (formData: FormData) => void, isPending: boolean];
|
|
136
|
+
|
|
137
|
+
type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
138
|
+
form: Form<TSchema, D>;
|
|
139
|
+
children: ReactNode;
|
|
140
|
+
}>;
|
|
141
|
+
type FormContextApi<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
142
|
+
Provider: (props: FormProviderProps<TSchema, D>) => ReactNode;
|
|
143
|
+
useFormContext: () => Form<TSchema, D>;
|
|
144
|
+
}>;
|
|
145
|
+
declare const createFormContext: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>() => FormContextApi<TSchema, D>;
|
|
146
|
+
|
|
147
|
+
type VariantFieldValue<V, TField extends string> = V extends unknown ? FieldValue<V, TField> : never;
|
|
96
148
|
type CommonKeys<V> = keyof V;
|
|
97
149
|
type AllKeys<V> = V extends unknown ? keyof V : never;
|
|
98
150
|
type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
|
|
151
|
+
type VariantFieldPath<V, D extends PathDepth = DefaultPathDepth> = Exclude<V extends unknown ? FieldPath<V, D> : never, (CommonKeys<V> & string) | `${CommonKeys<V> & string}.${string}`> & string;
|
|
99
152
|
type UnionValueAt<TValues, P extends string> = P extends keyof TValues ? NonNullable<TValues[P]> : TValues extends readonly (infer Item)[] ? P extends `${number}` ? NonNullable<Item> : P extends `${infer Head}.${infer Tail}` ? Head extends keyof TValues ? UnionValueAt<NonNullable<TValues[Head]>, Tail> : Head extends `${number}` ? UnionValueAt<NonNullable<Item>, Tail> : never : never : P extends `${infer Head}.${infer Tail}` ? Head extends keyof TValues ? UnionValueAt<NonNullable<TValues[Head]>, Tail> : never : never;
|
|
100
153
|
declare const inferredCallsOnly$1: unique symbol;
|
|
101
154
|
interface InferredTypeArg$1 {
|
|
@@ -107,7 +160,7 @@ declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi
|
|
|
107
160
|
declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
|
|
108
161
|
readonly schema?: undefined;
|
|
109
162
|
}, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
|
|
110
|
-
declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends
|
|
163
|
+
declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends VariantFieldPath<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>;
|
|
111
164
|
|
|
112
165
|
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
113
166
|
type FieldArrayFormApi = Readonly<{
|
|
@@ -177,7 +230,7 @@ type BoundUseField<TSchema extends z.ZodType, D extends PathDepth = DefaultPathD
|
|
|
177
230
|
(pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
|
|
178
231
|
<P extends FieldPath<z.input<TSchema>, D>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
|
|
179
232
|
};
|
|
180
|
-
type BoundUseVariantField<TSchema extends z.ZodType> = <P extends string, TField extends
|
|
233
|
+
type BoundUseVariantField<TSchema extends z.ZodType> = <P extends string, TField extends VariantFieldPath<UnionValueAt<z.input<TSchema>, P>>>(unionPath: P, field: TField) => UseFieldReturn<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField> | undefined>;
|
|
181
234
|
type BoundUseFieldArray<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
|
|
182
235
|
(pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
183
236
|
<P extends FieldPath<z.input<TSchema>, D>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
|
|
@@ -210,6 +263,8 @@ type FormHooks<TSchema extends z.ZodType, N extends string, D extends PathDepth
|
|
|
210
263
|
[K in `use${Capitalize<N>}Values`]: () => z.input<TSchema>;
|
|
211
264
|
} & {
|
|
212
265
|
[K in `use${Capitalize<N>}Fields`]: BoundUseFields<TSchema, D>;
|
|
266
|
+
} & {
|
|
267
|
+
[K in `use${Capitalize<N>}Steps`]: (steps: readonly FormStep<z.input<TSchema>, D>[]) => UseFormStepsReturn;
|
|
213
268
|
}>;
|
|
214
269
|
type BoundUseFields<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = <const P extends readonly FieldPath<z.input<TSchema>, D>[]>(paths: P) => UseFieldsReturn<{
|
|
215
270
|
readonly [K in keyof P]: UseFieldReturn<FieldValue<z.input<TSchema>, P[K] & string>>;
|
|
@@ -380,4 +435,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
380
435
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
381
436
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
382
437
|
|
|
383
|
-
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, SettledFieldValidationResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
|
438
|
+
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 FormActionHandler, type FormActionOptions, type FormActionStateHandler, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, type FormStep, InvalidSubmitHandler, type MaskedInputBinding, type MaskedInputOptions, type MaskedParse, 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, SettledFieldValidationResult, type StepStatus, TextField, type TextFieldProps, type TextInputProps, type UnionValueAt, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, type UseFormStepsReturn, type VariantFieldPath, type VariantFieldValue, type VariantKeys, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSelector, useFormSelectorShallow, useFormSteps, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useMaskedInput, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|