formstand 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-BexUOCjZ.cjs';
2
- export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-BexUOCjZ.cjs';
1
+ import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-CMVALnc3.cjs';
2
+ export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-CMVALnc3.cjs';
3
3
  import { z } from 'zod';
4
4
  import * as react from 'react';
5
5
  import { ChangeEvent, ReactNode } from 'react';
@@ -33,7 +33,7 @@ declare const persistForm: <TSchema extends z.ZodType, D extends PathDepth = Def
33
33
 
34
34
  declare const usePersistForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, options: PersistOptions<TSchema>) => PersistHandle;
35
35
 
36
- declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
36
+ declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, NoInfer<D>>;
37
37
 
38
38
  type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
39
39
  type FieldFormApi = Readonly<{
@@ -68,17 +68,17 @@ type UseFieldReturn<TValue> = Readonly<{
68
68
  validateAsync: () => Promise<SettledFieldValidationResult>;
69
69
  onBlur: () => void;
70
70
  }>;
71
- declare const inferredCallsOnly$2: unique symbol;
72
- interface InferredTypeArg$2 {
73
- readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
71
+ declare const inferredCallsOnly$3: unique symbol;
72
+ interface InferredTypeArg$3 {
73
+ readonly [inferredCallsOnly$3]: typeof inferredCallsOnly$3;
74
74
  }
75
75
  declare function useField<TSchema extends z.ZodType>(form: FieldFormApi & Readonly<{
76
76
  schema: TSchema;
77
77
  store: ReadonlyStore$2<FormState<z.input<TSchema>>>;
78
78
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
79
- declare function useField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
79
+ declare function useField<TValue = InferredTypeArg$3>(form: FieldFormApi & Readonly<{
80
80
  schema: z.ZodType;
81
- }>, path: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
81
+ }>, path: TValue extends InferredTypeArg$3 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
82
82
  declare function useField<TValue = unknown>(form: FieldFormApi & {
83
83
  readonly schema?: undefined;
84
84
  }, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
@@ -152,13 +152,13 @@ type AllKeys<V> = V extends unknown ? keyof V : never;
152
152
  type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
153
153
  type VariantFieldPath<V, D extends PathDepth = DefaultPathDepth> = Exclude<V extends unknown ? FieldPath<V, D> : never, (CommonKeys<V> & string) | `${CommonKeys<V> & string}.${string}`> & string;
154
154
  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;
155
- declare const inferredCallsOnly$1: unique symbol;
156
- interface InferredTypeArg$1 {
157
- readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
155
+ declare const inferredCallsOnly$2: unique symbol;
156
+ interface InferredTypeArg$2 {
157
+ readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
158
158
  }
159
- declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi & Readonly<{
159
+ declare function useVariantField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
160
160
  schema: z.ZodType;
161
- }>, unionPath: TValue extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
161
+ }>, unionPath: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
162
162
  declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
163
163
  readonly schema?: undefined;
164
164
  }, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
@@ -207,22 +207,35 @@ type UseFieldArrayReturn<TItem> = Readonly<{
207
207
  prepend: (item: TItem) => void;
208
208
  clear: () => void;
209
209
  }>;
210
- declare const inferredCallsOnly: unique symbol;
211
- interface InferredTypeArg {
212
- readonly [inferredCallsOnly]: typeof inferredCallsOnly;
210
+ declare const inferredCallsOnly$1: unique symbol;
211
+ interface InferredTypeArg$1 {
212
+ readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
213
213
  }
214
214
  declare function useFieldArray<TSchema extends z.ZodType>(form: FieldArrayFormApi & Readonly<{
215
215
  schema: TSchema;
216
216
  store: ReadonlyStore$1<FormState<z.input<TSchema>>>;
217
217
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
218
- declare function useFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
218
+ declare function useFieldArray<TItem = InferredTypeArg$1>(form: FieldArrayFormApi & Readonly<{
219
219
  schema: z.ZodType;
220
- }>, path: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
220
+ }>, path: TItem extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
221
221
  declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
222
222
  readonly schema?: undefined;
223
223
  }, path: FieldPathArg<unknown>): UseFieldArrayReturn<TItem>;
224
224
  declare function useFieldArray<TSchema extends z.ZodType, P extends ArrayFieldPath<z.input<TSchema>, D> & string, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
225
225
 
226
+ type VariantArrayFieldPath<V, D extends PathDepth = DefaultPathDepth> = Exclude<V extends unknown ? ArrayFieldPath<V, D> : never, (keyof V & string) | `${keyof V & string}.${string}`> & string;
227
+ declare const inferredCallsOnly: unique symbol;
228
+ interface InferredTypeArg {
229
+ readonly [inferredCallsOnly]: typeof inferredCallsOnly;
230
+ }
231
+ declare function useVariantFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
232
+ schema: z.ZodType;
233
+ }>, unionPath: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the union path and field", field: string): UseFieldArrayReturn<TItem>;
234
+ declare function useVariantFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
235
+ readonly schema?: undefined;
236
+ }, unionPath: string, field: string): UseFieldArrayReturn<TItem>;
237
+ declare function useVariantFieldArray<TSchema extends z.ZodType, P extends string, TField extends VariantArrayFieldPath<UnionValueAt<z.input<TSchema>, P>>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, unionPath: P, field: TField): UseFieldArrayReturn<ArrayItemOf<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField>>>;
238
+
226
239
  type UseFieldsReturn<TFields extends readonly unknown[]> = Readonly<{
227
240
  fields: TFields;
228
241
  error: readonly string[] | undefined;
@@ -244,6 +257,7 @@ type BoundUseField<TSchema extends z.ZodType, D extends PathDepth = DefaultPathD
244
257
  <P extends FieldPath<z.input<TSchema>, D>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
245
258
  };
246
259
  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>;
260
+ type BoundUseVariantFieldArray<TSchema extends z.ZodType> = <P extends string, TField extends VariantArrayFieldPath<UnionValueAt<z.input<TSchema>, P>>>(unionPath: P, field: TField) => UseFieldArrayReturn<ArrayItemOf<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField>>>;
247
261
  type BoundUseFieldArray<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
248
262
  (pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
249
263
  <P extends ArrayFieldPath<z.input<TSchema>, D>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
@@ -256,6 +270,8 @@ type FormHooks<TSchema extends z.ZodType, N extends string, D extends PathDepth
256
270
  [K in `use${Capitalize<N>}VariantField`]: BoundUseVariantField<TSchema>;
257
271
  } & {
258
272
  [K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema, D>;
273
+ } & {
274
+ [K in `use${Capitalize<N>}VariantFieldArray`]: BoundUseVariantFieldArray<TSchema>;
259
275
  } & {
260
276
  [K in `use${Capitalize<N>}Selector`]: BoundUseSelector<TSchema>;
261
277
  } & {
@@ -452,5 +468,5 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
452
468
  declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
453
469
  declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
454
470
 
455
- export { ArrayFieldPath, ArrayItemOf, CheckboxField, CreateFormOptions, DateField, DefaultPathDepth, ErrorMap, FieldPath, FieldValidationResult, FieldValue, Form, FormState, InvalidSubmitHandler, NumberField, PathDepth, SelectField, SettledFieldValidationResult, TextField, 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 };
456
- export type { ArrayPathsOf, BoundUseField, BoundUseFieldArray, BoundUseFields, BoundUseFlag, BoundUseSelector, BoundUseVariantField, CheckboxFieldProps, CheckboxProps, DateFieldProps, DateInputProps, FieldArrayEntry, FieldArrayFormApi, FieldFormApi, FieldPathArg, FieldRef, FormActionHandler, FormActionOptions, FormActionStateHandler, FormContextApi, FormHooks, FormProviderProps, FormStateApi, FormStep, MaskedInputBinding, MaskedInputOptions, MaskedParse, NumberFieldProps, NumberInputBinding, NumberInputProps, ParsedDateText, ParsedNumberText, PathSegment, PathsAccepting, PathsOf, PersistHandle, PersistOptions, PersistStorage, SelectFieldOption, SelectFieldProps, SelectProps, SelectValueAt, StepStatus, TextFieldProps, TextInputProps, UnionValueAt, UseFieldArrayReturn, UseFieldOptions, UseFieldReturn, UseFieldsReturn, UseFormStepsReturn, VariantFieldPath, VariantFieldValue, VariantKeys };
471
+ export { ArrayFieldPath, ArrayItemOf, CheckboxField, CreateFormOptions, DateField, DefaultPathDepth, ErrorMap, FieldPath, FieldValidationResult, FieldValue, Form, FormState, InvalidSubmitHandler, NumberField, PathDepth, SelectField, SettledFieldValidationResult, TextField, 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, useVariantFieldArray };
472
+ export type { ArrayPathsOf, BoundUseField, BoundUseFieldArray, BoundUseFields, BoundUseFlag, BoundUseSelector, BoundUseVariantField, BoundUseVariantFieldArray, CheckboxFieldProps, CheckboxProps, DateFieldProps, DateInputProps, FieldArrayEntry, FieldArrayFormApi, FieldFormApi, FieldPathArg, FieldRef, FormActionHandler, FormActionOptions, FormActionStateHandler, FormContextApi, FormHooks, FormProviderProps, FormStateApi, FormStep, MaskedInputBinding, MaskedInputOptions, MaskedParse, NumberFieldProps, NumberInputBinding, NumberInputProps, ParsedDateText, ParsedNumberText, PathSegment, PathsAccepting, PathsOf, PersistHandle, PersistOptions, PersistStorage, SelectFieldOption, SelectFieldProps, SelectProps, SelectValueAt, StepStatus, TextFieldProps, TextInputProps, UnionValueAt, UseFieldArrayReturn, UseFieldOptions, UseFieldReturn, UseFieldsReturn, UseFormStepsReturn, VariantArrayFieldPath, VariantFieldPath, VariantFieldValue, VariantKeys };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-BexUOCjZ.js';
2
- export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-BexUOCjZ.js';
1
+ import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FormState, b as FieldValidationResult, S as SettledFieldValidationResult, c as FieldPath, d as FieldValue, I as InvalidSubmitHandler, A as ArrayFieldPath, e as ArrayItemOf, E as ErrorMap } from './createForm-CMVALnc3.js';
2
+ export { B as BoolMap, f as FieldSnapshot, g as FieldsValidationResult, R as ReadonlyStoreApi, h as ResetOptions, i as SettledFieldsValidationResult, j as SettledValidationResult, k as SubmitHandler, l as SubmitOptions, m as SubmitResult, V as ValidationMode, n as ValidationResult, o as ValidationTrigger, p as createForm, q as emptyValueForSchema, r as flattenIssues, s as isAsyncRequiredError, t as isClearableSchema, u as shouldValidateOn, v as validateAsync, w as validateSync } from './createForm-CMVALnc3.js';
3
3
  import { z } from 'zod';
4
4
  import * as react from 'react';
5
5
  import { ChangeEvent, ReactNode } from 'react';
@@ -33,7 +33,7 @@ declare const persistForm: <TSchema extends z.ZodType, D extends PathDepth = Def
33
33
 
34
34
  declare const usePersistForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, options: PersistOptions<TSchema>) => PersistHandle;
35
35
 
36
- declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
36
+ declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, NoInfer<D>>;
37
37
 
38
38
  type ReadonlyStore$2<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
39
39
  type FieldFormApi = Readonly<{
@@ -68,17 +68,17 @@ type UseFieldReturn<TValue> = Readonly<{
68
68
  validateAsync: () => Promise<SettledFieldValidationResult>;
69
69
  onBlur: () => void;
70
70
  }>;
71
- declare const inferredCallsOnly$2: unique symbol;
72
- interface InferredTypeArg$2 {
73
- readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
71
+ declare const inferredCallsOnly$3: unique symbol;
72
+ interface InferredTypeArg$3 {
73
+ readonly [inferredCallsOnly$3]: typeof inferredCallsOnly$3;
74
74
  }
75
75
  declare function useField<TSchema extends z.ZodType>(form: FieldFormApi & Readonly<{
76
76
  schema: TSchema;
77
77
  store: ReadonlyStore$2<FormState<z.input<TSchema>>>;
78
78
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
79
- declare function useField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
79
+ declare function useField<TValue = InferredTypeArg$3>(form: FieldFormApi & Readonly<{
80
80
  schema: z.ZodType;
81
- }>, path: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
81
+ }>, path: TValue extends InferredTypeArg$3 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
82
82
  declare function useField<TValue = unknown>(form: FieldFormApi & {
83
83
  readonly schema?: undefined;
84
84
  }, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
@@ -152,13 +152,13 @@ type AllKeys<V> = V extends unknown ? keyof V : never;
152
152
  type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
153
153
  type VariantFieldPath<V, D extends PathDepth = DefaultPathDepth> = Exclude<V extends unknown ? FieldPath<V, D> : never, (CommonKeys<V> & string) | `${CommonKeys<V> & string}.${string}`> & string;
154
154
  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;
155
- declare const inferredCallsOnly$1: unique symbol;
156
- interface InferredTypeArg$1 {
157
- readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
155
+ declare const inferredCallsOnly$2: unique symbol;
156
+ interface InferredTypeArg$2 {
157
+ readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
158
158
  }
159
- declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi & Readonly<{
159
+ declare function useVariantField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
160
160
  schema: z.ZodType;
161
- }>, unionPath: TValue extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
161
+ }>, unionPath: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
162
162
  declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
163
163
  readonly schema?: undefined;
164
164
  }, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
@@ -207,22 +207,35 @@ type UseFieldArrayReturn<TItem> = Readonly<{
207
207
  prepend: (item: TItem) => void;
208
208
  clear: () => void;
209
209
  }>;
210
- declare const inferredCallsOnly: unique symbol;
211
- interface InferredTypeArg {
212
- readonly [inferredCallsOnly]: typeof inferredCallsOnly;
210
+ declare const inferredCallsOnly$1: unique symbol;
211
+ interface InferredTypeArg$1 {
212
+ readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
213
213
  }
214
214
  declare function useFieldArray<TSchema extends z.ZodType>(form: FieldArrayFormApi & Readonly<{
215
215
  schema: TSchema;
216
216
  store: ReadonlyStore$1<FormState<z.input<TSchema>>>;
217
217
  }>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
218
- declare function useFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
218
+ declare function useFieldArray<TItem = InferredTypeArg$1>(form: FieldArrayFormApi & Readonly<{
219
219
  schema: z.ZodType;
220
- }>, path: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
220
+ }>, path: TItem extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
221
221
  declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
222
222
  readonly schema?: undefined;
223
223
  }, path: FieldPathArg<unknown>): UseFieldArrayReturn<TItem>;
224
224
  declare function useFieldArray<TSchema extends z.ZodType, P extends ArrayFieldPath<z.input<TSchema>, D> & string, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
225
225
 
226
+ type VariantArrayFieldPath<V, D extends PathDepth = DefaultPathDepth> = Exclude<V extends unknown ? ArrayFieldPath<V, D> : never, (keyof V & string) | `${keyof V & string}.${string}`> & string;
227
+ declare const inferredCallsOnly: unique symbol;
228
+ interface InferredTypeArg {
229
+ readonly [inferredCallsOnly]: typeof inferredCallsOnly;
230
+ }
231
+ declare function useVariantFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
232
+ schema: z.ZodType;
233
+ }>, unionPath: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the union path and field", field: string): UseFieldArrayReturn<TItem>;
234
+ declare function useVariantFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
235
+ readonly schema?: undefined;
236
+ }, unionPath: string, field: string): UseFieldArrayReturn<TItem>;
237
+ declare function useVariantFieldArray<TSchema extends z.ZodType, P extends string, TField extends VariantArrayFieldPath<UnionValueAt<z.input<TSchema>, P>>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, unionPath: P, field: TField): UseFieldArrayReturn<ArrayItemOf<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField>>>;
238
+
226
239
  type UseFieldsReturn<TFields extends readonly unknown[]> = Readonly<{
227
240
  fields: TFields;
228
241
  error: readonly string[] | undefined;
@@ -244,6 +257,7 @@ type BoundUseField<TSchema extends z.ZodType, D extends PathDepth = DefaultPathD
244
257
  <P extends FieldPath<z.input<TSchema>, D>>(path: P, options?: UseFieldOptions): UseFieldReturn<FieldValue<z.input<TSchema>, P>>;
245
258
  };
246
259
  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>;
260
+ type BoundUseVariantFieldArray<TSchema extends z.ZodType> = <P extends string, TField extends VariantArrayFieldPath<UnionValueAt<z.input<TSchema>, P>>>(unionPath: P, field: TField) => UseFieldArrayReturn<ArrayItemOf<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField>>>;
247
261
  type BoundUseFieldArray<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = {
248
262
  (pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
249
263
  <P extends ArrayFieldPath<z.input<TSchema>, D>>(path: P): UseFieldArrayReturn<ArrayItemOf<FieldValue<z.input<TSchema>, P>>>;
@@ -256,6 +270,8 @@ type FormHooks<TSchema extends z.ZodType, N extends string, D extends PathDepth
256
270
  [K in `use${Capitalize<N>}VariantField`]: BoundUseVariantField<TSchema>;
257
271
  } & {
258
272
  [K in `use${Capitalize<N>}FieldArray`]: BoundUseFieldArray<TSchema, D>;
273
+ } & {
274
+ [K in `use${Capitalize<N>}VariantFieldArray`]: BoundUseVariantFieldArray<TSchema>;
259
275
  } & {
260
276
  [K in `use${Capitalize<N>}Selector`]: BoundUseSelector<TSchema>;
261
277
  } & {
@@ -452,5 +468,5 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
452
468
  declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
453
469
  declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
454
470
 
455
- export { ArrayFieldPath, ArrayItemOf, CheckboxField, CreateFormOptions, DateField, DefaultPathDepth, ErrorMap, FieldPath, FieldValidationResult, FieldValue, Form, FormState, InvalidSubmitHandler, NumberField, PathDepth, SelectField, SettledFieldValidationResult, TextField, 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 };
456
- export type { ArrayPathsOf, BoundUseField, BoundUseFieldArray, BoundUseFields, BoundUseFlag, BoundUseSelector, BoundUseVariantField, CheckboxFieldProps, CheckboxProps, DateFieldProps, DateInputProps, FieldArrayEntry, FieldArrayFormApi, FieldFormApi, FieldPathArg, FieldRef, FormActionHandler, FormActionOptions, FormActionStateHandler, FormContextApi, FormHooks, FormProviderProps, FormStateApi, FormStep, MaskedInputBinding, MaskedInputOptions, MaskedParse, NumberFieldProps, NumberInputBinding, NumberInputProps, ParsedDateText, ParsedNumberText, PathSegment, PathsAccepting, PathsOf, PersistHandle, PersistOptions, PersistStorage, SelectFieldOption, SelectFieldProps, SelectProps, SelectValueAt, StepStatus, TextFieldProps, TextInputProps, UnionValueAt, UseFieldArrayReturn, UseFieldOptions, UseFieldReturn, UseFieldsReturn, UseFormStepsReturn, VariantFieldPath, VariantFieldValue, VariantKeys };
471
+ export { ArrayFieldPath, ArrayItemOf, CheckboxField, CreateFormOptions, DateField, DefaultPathDepth, ErrorMap, FieldPath, FieldValidationResult, FieldValue, Form, FormState, InvalidSubmitHandler, NumberField, PathDepth, SelectField, SettledFieldValidationResult, TextField, 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, useVariantFieldArray };
472
+ export type { ArrayPathsOf, BoundUseField, BoundUseFieldArray, BoundUseFields, BoundUseFlag, BoundUseSelector, BoundUseVariantField, BoundUseVariantFieldArray, CheckboxFieldProps, CheckboxProps, DateFieldProps, DateInputProps, FieldArrayEntry, FieldArrayFormApi, FieldFormApi, FieldPathArg, FieldRef, FormActionHandler, FormActionOptions, FormActionStateHandler, FormContextApi, FormHooks, FormProviderProps, FormStateApi, FormStep, MaskedInputBinding, MaskedInputOptions, MaskedParse, NumberFieldProps, NumberInputBinding, NumberInputProps, ParsedDateText, ParsedNumberText, PathSegment, PathsAccepting, PathsOf, PersistHandle, PersistOptions, PersistStorage, SelectFieldOption, SelectFieldProps, SelectProps, SelectValueAt, StepStatus, TextFieldProps, TextInputProps, UnionValueAt, UseFieldArrayReturn, UseFieldOptions, UseFieldReturn, UseFieldsReturn, UseFormStepsReturn, VariantArrayFieldPath, VariantFieldPath, VariantFieldValue, VariantKeys };
package/dist/index.js CHANGED
@@ -221,12 +221,32 @@ var fieldSchemaForIntrospection = (schema, path) => {
221
221
  );
222
222
  };
223
223
  var containerKindAt = (schema) => (prefix) => {
224
- const sub = fieldSchemaForIntrospection(schema, prefix);
225
- if (sub === null) return null;
226
224
  const unwrapAll = (s) => {
227
225
  const inner2 = unwrapForWalk(s);
228
226
  return inner2 === null ? s : unwrapAll(inner2);
229
227
  };
228
+ const step = (s, segment) => {
229
+ const inner2 = unwrapAll(s);
230
+ if (inner2 instanceof z.ZodObject && typeof segment === "string") {
231
+ const shape = inner2.shape;
232
+ return Object.hasOwn(shape, segment) ? shape[segment] ?? null : null;
233
+ }
234
+ if (inner2 instanceof z.ZodArray && typeof segment === "number") {
235
+ return inner2.element;
236
+ }
237
+ if (inner2 instanceof z.ZodTuple && typeof segment === "number") {
238
+ return inner2.def.items[segment] ?? null;
239
+ }
240
+ if (inner2 instanceof z.ZodRecord) {
241
+ return inner2.valueType;
242
+ }
243
+ return null;
244
+ };
245
+ const sub = parsePath(prefix).reduce(
246
+ (current, segment) => current === null ? null : step(current, segment),
247
+ schema
248
+ );
249
+ if (sub === null) return null;
230
250
  const inner = unwrapAll(sub);
231
251
  if (inner instanceof z.ZodArray || inner instanceof z.ZodTuple) {
232
252
  return "array";
@@ -2034,6 +2054,14 @@ function useFieldArray(form, pathArg) {
2034
2054
  ]
2035
2055
  );
2036
2056
  }
2057
+
2058
+ // src/react/useVariantFieldArray.ts
2059
+ function useVariantFieldArray(form, unionPath, field) {
2060
+ return useFieldArray(
2061
+ form,
2062
+ `${unionPath}.${field}`
2063
+ );
2064
+ }
2037
2065
  var useFormError = (form) => useStore(
2038
2066
  form.store,
2039
2067
  useShallow((state) => state.errors[""])
@@ -2112,6 +2140,11 @@ var createFormHooks = (form, name) => {
2112
2140
  field
2113
2141
  );
2114
2142
  const useBoundFieldArray = (path) => useFieldArray(structural, path);
2143
+ const useBoundVariantFieldArray = (unionPath, field) => useVariantFieldArray(
2144
+ structural,
2145
+ unionPath,
2146
+ field
2147
+ );
2115
2148
  const useBoundSelector = (selector) => useFormSelector(structural, selector);
2116
2149
  const useBoundSelectorShallow = (selector) => useFormSelectorShallow(structural, selector);
2117
2150
  const useBoundError = () => useFormError(structural);
@@ -2131,6 +2164,7 @@ var createFormHooks = (form, name) => {
2131
2164
  [`use${prefix}Field`]: useBoundField,
2132
2165
  [`use${prefix}VariantField`]: useBoundVariantField,
2133
2166
  [`use${prefix}FieldArray`]: useBoundFieldArray,
2167
+ [`use${prefix}VariantFieldArray`]: useBoundVariantFieldArray,
2134
2168
  [`use${prefix}Selector`]: useBoundSelector,
2135
2169
  [`use${prefix}SelectorShallow`]: useBoundSelectorShallow,
2136
2170
  [`use${prefix}Error`]: useBoundError,
@@ -2436,6 +2470,6 @@ var focusField = (path, root) => {
2436
2470
  return path === "" ? (root !== void 0 || document.querySelectorAll("form").length <= 1) && focusFirstOf(namedControls(scope).filter(isFocusCandidate)) : focusFirstOf(pathCandidates(scope, [path]).filter(isFocusCandidate));
2437
2471
  };
2438
2472
 
2439
- export { CheckboxField, DateField, NumberField, SelectField, TextField, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, hasFieldError, isAsyncRequiredError, isClearableSchema, numberInputProps, numberToInputText, parseDateText, parseNumberText, persistForm, selectProps, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSteps, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useMaskedInput, useNumberInput, usePersistForm, useSubmitCount, useVariantField, validateAsync, validateSync };
2473
+ export { CheckboxField, DateField, NumberField, SelectField, TextField, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, hasFieldError, isAsyncRequiredError, isClearableSchema, numberInputProps, numberToInputText, parseDateText, parseNumberText, persistForm, selectProps, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSteps, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useMaskedInput, useNumberInput, usePersistForm, useSubmitCount, useVariantField, useVariantFieldArray, validateAsync, validateSync };
2440
2474
  //# sourceMappingURL=index.js.map
2441
2475
  //# sourceMappingURL=index.js.map