@rachelallyson/hero-hook-form 2.7.0 → 2.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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React$1, { ComponentProps } from 'react';
2
2
  import { Button } from '@heroui/react';
3
3
  import * as react_hook_form from 'react-hook-form';
4
- import { FieldValues, Path, RegisterOptions, Control, UseFormReturn, FieldErrors, UseFormProps, SubmitHandler, UseFormSetError, DefaultValues, ArrayPath, FieldArrayWithId } from 'react-hook-form';
4
+ import { FieldValues, Path, RegisterOptions, ArrayPath, Control, UseFormReturn, FieldErrors, UseFormProps, SubmitHandler, DefaultValues, UseFormSetError, FieldPath, FieldArrayWithId } from 'react-hook-form';
5
5
  export { UseFormReturn, useFormContext } from 'react-hook-form';
6
6
  import * as zod from 'zod';
7
7
  import { z, ZodSchema } from 'zod';
@@ -17,6 +17,19 @@ import { Slider } from '@heroui/slider';
17
17
  import { Switch } from '@heroui/switch';
18
18
  import { Button as Button$1 } from '@heroui/button';
19
19
 
20
+ /**
21
+ * All supported field types that can be used in form builders
22
+ * This type is used throughout the codebase to ensure consistency
23
+ */
24
+ type FormFieldType = "input" | "textarea" | "select" | "autocomplete" | "checkbox" | "switch" | "radio" | "slider" | "date" | "file" | "fontPicker" | "stringArray";
25
+ /**
26
+ * Helper to convert a Path<T>, ArrayPath<T>, or string to a string for use in React keys and DOM operations.
27
+ * Path<T> and ArrayPath<T> are branded string types, so this is safe - it's just removing the brand.
28
+ *
29
+ * @param path - The path to convert (can be Path<T>, ArrayPath<T>, string, or undefined)
30
+ * @returns The path as a plain string, or empty string if undefined
31
+ */
32
+ declare function pathToString<T extends FieldValues>(path: Path<T> | ArrayPath<T> | string | undefined): string;
20
33
  interface FieldBaseProps<TFieldValues extends FieldValues, TValue> {
21
34
  name: Path<TFieldValues>;
22
35
  label?: string;
@@ -30,7 +43,7 @@ interface FieldBaseProps<TFieldValues extends FieldValues, TValue> {
30
43
  isDisabled?: boolean;
31
44
  }
32
45
  interface WithControl<TFieldValues extends FieldValues> {
33
- control: Control<TFieldValues>;
46
+ control: Control<TFieldValues, any>;
34
47
  }
35
48
  interface BaseFormFieldConfig<TFieldValues extends FieldValues> {
36
49
  name: Path<TFieldValues>;
@@ -73,6 +86,16 @@ interface RadioFieldConfig<TFieldValues extends FieldValues> extends BaseFormFie
73
86
  value: string | number;
74
87
  }[];
75
88
  }
89
+ interface CheckboxGroupFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
90
+ type: "checkboxGroup";
91
+ defaultValue?: (string | number)[];
92
+ checkboxGroupOptions?: {
93
+ label: string;
94
+ value: string | number;
95
+ }[];
96
+ checkboxProps?: Omit<React.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled" | "name">;
97
+ orientation?: "vertical" | "horizontal";
98
+ }
76
99
  interface SliderFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
77
100
  type: "slider";
78
101
  defaultValue?: number;
@@ -100,10 +123,35 @@ interface FontPickerFieldConfig<TFieldValues extends FieldValues> extends BaseFo
100
123
  fontsLoadedTimeout?: number;
101
124
  };
102
125
  }
103
- interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
126
+ interface StringArrayFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
127
+ type: "stringArray";
128
+ defaultValue?: string[];
129
+ stringArrayProps?: {
130
+ /** Placeholder text for the input */
131
+ placeholder?: string;
132
+ /** Maximum number of items allowed */
133
+ maxItems?: number;
134
+ /** Minimum number of items required */
135
+ minItems?: number;
136
+ /** Allow duplicate values */
137
+ allowDuplicates?: boolean;
138
+ /** Custom validation function for each item */
139
+ validateItem?: (item: string) => string | true;
140
+ /** Transform item before adding (e.g., trim whitespace) */
141
+ transformItem?: (item: string) => string;
142
+ /** Custom chip render function */
143
+ renderChip?: (item: string, onRemove: () => void) => React.ReactNode;
144
+ /** Custom add button text */
145
+ addButtonText?: string;
146
+ /** Whether to show add button or use enter key */
147
+ showAddButton?: boolean;
148
+ };
149
+ }
150
+ interface CustomFieldConfig<TFieldValues extends FieldValues> extends Omit<BaseFormFieldConfig<TFieldValues>, "name"> {
104
151
  type: "custom";
152
+ name: Path<TFieldValues> | ArrayPath<TFieldValues>;
105
153
  render: (field: {
106
- name: Path<TFieldValues>;
154
+ name: Path<TFieldValues> | ArrayPath<TFieldValues>;
107
155
  control: Control<TFieldValues>;
108
156
  form: UseFormReturn<TFieldValues>;
109
157
  errors: FieldErrors<TFieldValues>;
@@ -124,8 +172,10 @@ interface ConditionalFieldConfig<TFieldValues extends FieldValues> extends BaseF
124
172
  *
125
173
  * @template TFieldValues - The form data type
126
174
  */
127
- interface FieldArrayConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
175
+ interface FieldArrayConfig<TFieldValues extends FieldValues> extends Omit<BaseFormFieldConfig<TFieldValues>, "name"> {
128
176
  type: "fieldArray";
177
+ /** Field array name - must be an ArrayPath (points to an array field) */
178
+ name: ArrayPath<TFieldValues>;
129
179
  /** Field configurations for each array item */
130
180
  fields: ZodFormFieldConfig<TFieldValues>[];
131
181
  /** Minimum number of items (default: 0) */
@@ -147,6 +197,8 @@ interface FieldArrayConfig<TFieldValues extends FieldValues> extends BaseFormFie
147
197
  };
148
198
  /** Function to create default item when adding new array item */
149
199
  defaultItem?: () => any;
200
+ /** Whether this field array should always be registered (for conditional rendering) */
201
+ alwaysRegistered?: boolean;
150
202
  /** Custom render function for array items */
151
203
  renderItem?: (props: {
152
204
  /** Item index (0-based) */
@@ -193,7 +245,7 @@ interface DynamicSectionConfig<TFieldValues extends FieldValues> extends BaseFor
193
245
  }
194
246
  interface ContentFieldConfig<TFieldValues extends FieldValues = FieldValues> {
195
247
  type: "content";
196
- name?: string;
248
+ name?: Path<TFieldValues>;
197
249
  title?: string;
198
250
  description?: string;
199
251
  render?: (field: {
@@ -203,7 +255,7 @@ interface ContentFieldConfig<TFieldValues extends FieldValues = FieldValues> {
203
255
  }) => React.ReactNode;
204
256
  className?: string;
205
257
  }
206
- type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | FontPickerFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues> | ConditionalFieldConfig<TFieldValues> | FieldArrayConfig<TFieldValues> | DynamicSectionConfig<TFieldValues> | ContentFieldConfig<TFieldValues>;
258
+ type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | CheckboxGroupFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | FontPickerFieldConfig<TFieldValues> | StringArrayFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues> | ConditionalFieldConfig<TFieldValues> | FieldArrayConfig<TFieldValues> | DynamicSectionConfig<TFieldValues> | ContentFieldConfig<TFieldValues>;
207
259
  interface FormConfig<TFieldValues extends FieldValues> {
208
260
  fields: FormFieldConfig<TFieldValues>[];
209
261
  layout?: "vertical" | "horizontal" | "grid" | "custom";
@@ -217,10 +269,12 @@ interface FormConfig<TFieldValues extends FieldValues> {
217
269
  className?: string;
218
270
  defaultValues?: Partial<TFieldValues>;
219
271
  }
220
- type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules"> | Omit<FontPickerFieldConfig<TFieldValues>, "rules"> | Omit<CustomFieldConfig<TFieldValues>, "rules"> | Omit<ConditionalFieldConfig<TFieldValues>, "rules"> | Omit<FieldArrayConfig<TFieldValues>, "rules"> | Omit<DynamicSectionConfig<TFieldValues>, "rules"> | ContentFieldConfig<TFieldValues>;
272
+ type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<CheckboxGroupFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules"> | Omit<FontPickerFieldConfig<TFieldValues>, "rules"> | Omit<StringArrayFieldConfig<TFieldValues>, "rules"> | Omit<CustomFieldConfig<TFieldValues>, "rules"> | Omit<ConditionalFieldConfig<TFieldValues>, "rules"> | Omit<FieldArrayConfig<TFieldValues>, "rules"> | Omit<DynamicSectionConfig<TFieldValues>, "rules"> | ContentFieldConfig<TFieldValues>;
221
273
  interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
222
274
  schema: zod.ZodSchema<TFieldValues>;
223
- fields: ZodFormFieldConfig<TFieldValues>[];
275
+ fields: (ZodFormFieldConfig<TFieldValues> | (Omit<ZodFormFieldConfig<FieldValues>, "name"> & {
276
+ name: Path<TFieldValues>;
277
+ }))[];
224
278
  onError?: (errors: FieldErrors<TFieldValues>) => void;
225
279
  errorDisplay?: "inline" | "toast" | "modal" | "none";
226
280
  }
@@ -308,7 +362,7 @@ interface FormProps$1<T extends FieldValues> {
308
362
  submitButtonText?: string;
309
363
  subtitle?: string;
310
364
  title?: string;
311
- defaultValues?: Partial<T>;
365
+ defaultValues?: DefaultValues<T>;
312
366
  }
313
367
  /**
314
368
  * Base form component for building forms without Zod validation.
@@ -364,11 +418,16 @@ interface FormProps$1<T extends FieldValues> {
364
418
  declare function ConfigurableForm<T extends FieldValues>({ className, columns, defaultValues, fields, layout, onError, onSubmit, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: FormProps$1<T>): React$1.JSX.Element;
365
419
 
366
420
  interface FormFieldProps<TFieldValues extends FieldValues> {
367
- config: FormFieldConfig<TFieldValues>;
421
+ config: FormFieldConfig<TFieldValues> | ZodFormFieldConfig<TFieldValues> | (Omit<FormFieldConfig<FieldValues>, "name"> & {
422
+ name: Path<TFieldValues>;
423
+ }) | (Omit<ZodFormFieldConfig<FieldValues>, "name"> & {
424
+ name: Path<TFieldValues>;
425
+ });
368
426
  form: UseFormReturn<TFieldValues>;
369
427
  submissionState: FormSubmissionState;
370
428
  }
371
- declare const FormField: <TFieldValues extends FieldValues>(props: FormFieldProps<TFieldValues>) => React$1.JSX.Element;
429
+ declare function FormFieldComponent<TFieldValues extends FieldValues>({ config, form, submissionState, }: FormFieldProps<TFieldValues>): string | number | bigint | boolean | Iterable<React$1.ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<React$1.ReactNode> | null | undefined> | React$1.JSX.Element | null | undefined;
430
+ declare const FormField: typeof FormFieldComponent;
372
431
 
373
432
  type ServerAction<TState = unknown, TFormData = FormData> = (state: TState | undefined, formData: TFormData) => Promise<TState>;
374
433
  interface ActionState {
@@ -384,8 +443,12 @@ interface ServerActionFormProps<T extends FieldValues> {
384
443
  className?: string;
385
444
  columns?: 1 | 2 | 3;
386
445
  /** Default values for form fields */
387
- defaultValues?: Partial<T>;
388
- fields: FormFieldConfig<T>[];
446
+ defaultValues?: Partial<T> | Record<string, unknown>;
447
+ fields: (FormFieldConfig<T> | FormFieldConfig<any> | ZodFormFieldConfig<any> | (Omit<FormFieldConfig<FieldValues>, "name"> & {
448
+ name: Path<T>;
449
+ }) | (Omit<ZodFormFieldConfig<FieldValues>, "name"> & {
450
+ name: Path<T>;
451
+ }))[];
389
452
  /** Initial state for useActionState */
390
453
  initialState?: ActionState;
391
454
  layout?: "vertical" | "horizontal" | "grid";
@@ -494,7 +557,7 @@ interface ServerActionFormProps<T extends FieldValues> {
494
557
  * @see {@link ConfigurableForm} for forms without Server Actions
495
558
  * @category Components
496
559
  */
497
- declare function ServerActionForm<T extends FieldValues>({ action, className, clientValidationSchema, columns, defaultValues, fields, initialState, layout, onError, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ServerActionFormProps<T>): React$1.JSX.Element;
560
+ declare function ServerActionForm<T extends FieldValues = FieldValues>({ action, className, clientValidationSchema, columns, defaultValues, fields, initialState, layout, onError, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ServerActionFormProps<T>): React$1.JSX.Element;
498
561
 
499
562
  /**
500
563
  * Configuration for an autocomplete option.
@@ -698,6 +761,119 @@ type CheckboxFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFiel
698
761
  */
699
762
  declare function CheckboxField<TFieldValues extends FieldValues>(props: CheckboxFieldProps<TFieldValues>): React$1.JSX.Element;
700
763
 
764
+ /**
765
+ * Configuration for a checkbox option in a checkbox group.
766
+ *
767
+ * @template TValue - The value type for the option
768
+ */
769
+ interface CheckboxOption<TValue extends string | number> {
770
+ /** Display label for the option */
771
+ label: string;
772
+ /** Value of the option */
773
+ value: TValue;
774
+ /** Optional description text */
775
+ description?: string;
776
+ /** Whether the option is disabled */
777
+ disabled?: boolean;
778
+ }
779
+ /**
780
+ * Props for the CheckboxGroupField component.
781
+ *
782
+ * @template TFieldValues - The form data type
783
+ * @template TValue - The value type for the checkbox group (string or number)
784
+ *
785
+ * @example
786
+ * ```tsx
787
+ * import { CheckboxGroupField } from "@rachelallyson/hero-hook-form";
788
+ * import { useForm } from "react-hook-form";
789
+ *
790
+ * const form = useForm({
791
+ * defaultValues: { interests: [] },
792
+ * });
793
+ *
794
+ * const options = [
795
+ * { label: "Reading", value: "reading" },
796
+ * { label: "Sports", value: "sports" },
797
+ * { label: "Music", value: "music" },
798
+ * ];
799
+ *
800
+ * <CheckboxGroupField
801
+ * control={form.control}
802
+ * name="interests"
803
+ * label="Interests"
804
+ * options={options}
805
+ * />
806
+ * ```
807
+ */
808
+ type CheckboxGroupFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue[]> & WithControl<TFieldValues> & {
809
+ /** Array of checkbox options */
810
+ options: readonly CheckboxOption<TValue>[];
811
+ /** Additional props to pass to individual Checkbox components */
812
+ checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled" | "name">;
813
+ /** Layout orientation for the checkboxes */
814
+ orientation?: "vertical" | "horizontal";
815
+ };
816
+ /**
817
+ * A checkbox group field component that integrates React Hook Form with HeroUI Checkbox.
818
+ *
819
+ * This component provides a type-safe checkbox group field with validation support,
820
+ * error handling, and accessibility features. Multiple options can be selected,
821
+ * and the value is stored as an array of selected option values.
822
+ *
823
+ * @template TFieldValues - The form data type
824
+ * @template TValue - The value type for the checkbox group (string or number)
825
+ *
826
+ * @param props - The checkbox group field props
827
+ * @returns The rendered checkbox group field component
828
+ *
829
+ * @example
830
+ * ```tsx
831
+ * import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
832
+ * import { z } from "zod";
833
+ *
834
+ * const schema = z.object({
835
+ * interests: z.array(z.string()).min(1, "Please select at least one interest"),
836
+ * });
837
+ *
838
+ * const options = [
839
+ * { label: "Reading", value: "reading" },
840
+ * { label: "Sports", value: "sports" },
841
+ * { label: "Music", value: "music" },
842
+ * ];
843
+ *
844
+ * function MyForm() {
845
+ * return (
846
+ * <ZodForm
847
+ * config={{
848
+ * schema,
849
+ * fields: [
850
+ * FormFieldHelpers.checkboxGroup("interests", "Interests", options),
851
+ * ],
852
+ * }}
853
+ * onSubmit={(data) => console.log(data)}
854
+ * />
855
+ * );
856
+ * }
857
+ * ```
858
+ *
859
+ * @example
860
+ * ```tsx
861
+ * // With custom styling and horizontal layout
862
+ * <CheckboxGroupField
863
+ * control={form.control}
864
+ * name="interests"
865
+ * label="Interests"
866
+ * options={options}
867
+ * orientation="horizontal"
868
+ * checkboxProps={{
869
+ * color: "primary",
870
+ * size: "lg",
871
+ * }}
872
+ * />
873
+ * ```
874
+ */
875
+ declare function CheckboxGroupField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: CheckboxGroupFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
876
+
701
877
  /**
702
878
  * Props for the DateField component.
703
879
  *
@@ -1423,7 +1599,7 @@ interface UseFormHelperOptions<T extends FieldValues> {
1423
1599
  onError?: (error: FormValidationError) => void;
1424
1600
  onSubmit: SubmitHandler<T>;
1425
1601
  onSuccess?: (data: T) => void;
1426
- defaultValues?: Partial<T>;
1602
+ defaultValues?: DefaultValues<T>;
1427
1603
  methods?: UseFormReturn<T>;
1428
1604
  }
1429
1605
  /**
@@ -1558,7 +1734,7 @@ declare function useFormHelper<T extends FieldValues>({ defaultValues, methods,
1558
1734
  * @category Hooks
1559
1735
  */
1560
1736
  declare function useHeroForm<TFieldValues extends FieldValues>(): {
1561
- defaults: Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "select" | "switch" | "radioGroup" | "checkbox" | "slider" | "dateInput" | "submitButton">>;
1737
+ defaults: Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "select" | "checkbox" | "switch" | "slider" | "radioGroup" | "dateInput" | "submitButton">>;
1562
1738
  watch: react_hook_form.UseFormWatch<TFieldValues>;
1563
1739
  getValues: react_hook_form.UseFormGetValues<TFieldValues>;
1564
1740
  getFieldState: react_hook_form.UseFormGetFieldState<TFieldValues>;
@@ -2001,6 +2177,7 @@ interface ZodFormProps<T extends FieldValues> {
2001
2177
  className?: string;
2002
2178
  columns?: 1 | 2 | 3;
2003
2179
  config: ZodFormConfig<T>;
2180
+ errorDisplay?: "inline" | "toast" | "modal" | "none";
2004
2181
  layout?: "vertical" | "horizontal" | "grid";
2005
2182
  onError?: (error: FormValidationError) => void;
2006
2183
  onSubmit: SubmitHandler<T>;
@@ -2177,7 +2354,7 @@ declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormCon
2177
2354
  /**
2178
2355
  * Helper function to create Zod form configurations
2179
2356
  */
2180
- declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: Partial<TFieldValues>): ZodFormConfig<TFieldValues>;
2357
+ declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: DefaultValues<TFieldValues>): ZodFormConfig<TFieldValues>;
2181
2358
 
2182
2359
  /**
2183
2360
  * Basic form field builder for creating form field configurations.
@@ -2327,6 +2504,11 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2327
2504
  * @see {@link createBasicFormBuilder} for builder pattern alternative
2328
2505
  * @category Builders
2329
2506
  */
2507
+ type InputPropsType = Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
2508
+ declare function inputHelper<T extends FieldValues>(name: Path<T>, label: string): ZodFormFieldConfig<T>;
2509
+ declare function inputHelper<T extends FieldValues>(name: Path<T>, label: string, type: "text" | "email" | "tel" | "password"): ZodFormFieldConfig<T>;
2510
+ declare function inputHelper<T extends FieldValues>(name: Path<T>, label: string, inputProps: InputPropsType): ZodFormFieldConfig<T>;
2511
+ declare function inputHelper<T extends FieldValues>(name: Path<T>, label: string, type: "text" | "email" | "tel" | "password", inputProps: InputPropsType): ZodFormFieldConfig<T>;
2330
2512
  declare const FormFieldHelpers: {
2331
2513
  /**
2332
2514
  * Create an autocomplete field
@@ -2366,6 +2548,33 @@ declare const FormFieldHelpers: {
2366
2548
  * ```
2367
2549
  */
2368
2550
  checkbox: <T extends FieldValues>(name: Path<T>, label: string, checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2551
+ /**
2552
+ * Create a checkbox group field (multiple checkboxes saving to an array)
2553
+ *
2554
+ * @example
2555
+ * ```tsx
2556
+ * // Simple checkbox group
2557
+ * FormFieldHelpers.checkboxGroup("interests", "Interests", [
2558
+ * { label: "Reading", value: "reading" },
2559
+ * { label: "Sports", value: "sports" },
2560
+ * { label: "Music", value: "music" },
2561
+ * ])
2562
+ *
2563
+ * // With horizontal layout and custom styling
2564
+ * FormFieldHelpers.checkboxGroup("interests", "Interests", options, {
2565
+ * orientation: "horizontal",
2566
+ * checkboxProps: { color: "primary", size: "lg" }
2567
+ * })
2568
+ * ```
2569
+ */
2570
+ checkboxGroup: <T extends FieldValues>(name: Path<T>, label: string, options: {
2571
+ label: string;
2572
+ value: string | number;
2573
+ }[], config?: {
2574
+ checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled" | "name">;
2575
+ orientation?: "vertical" | "horizontal";
2576
+ description?: string;
2577
+ }) => ZodFormFieldConfig<T>;
2369
2578
  /**
2370
2579
  * Create a conditional field that shows/hides based on form data
2371
2580
  *
@@ -2390,6 +2599,41 @@ declare const FormFieldHelpers: {
2390
2599
  * ```
2391
2600
  */
2392
2601
  conditional: <T extends FieldValues = FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
2602
+ /**
2603
+ * Create a conditional field array that avoids memory leaks in Cypress tests.
2604
+ *
2605
+ * This helper creates a field array that is always registered but conditionally
2606
+ * rendered, preventing the register/unregister cycles that cause memory
2607
+ * accumulation in Cypress Electron renderer.
2608
+ *
2609
+ * @param name - The field array name
2610
+ * @param condition - Function that determines if the field array should be visible
2611
+ * @param label - Display label for the field array
2612
+ * @param fields - Field configurations for array items
2613
+ * @param options - Additional field array options
2614
+ *
2615
+ * @example
2616
+ * ```tsx
2617
+ * // Memory-safe conditional field array for multiple choice options
2618
+ * FormFieldHelpers.conditionalFieldArray(
2619
+ * "choices",
2620
+ * (data) => data.questionType === 'MULTIPLE_CHOICE',
2621
+ * "Answer Choices",
2622
+ * [
2623
+ * FormFieldHelpers.input("text", "Choice Text"),
2624
+ * FormFieldHelpers.checkbox("isCorrect", "Correct Answer"),
2625
+ * ]
2626
+ * )
2627
+ * ```
2628
+ */
2629
+ conditionalFieldArray: <T extends FieldValues = FieldValues>(name: ArrayPath<T>, condition: (formData: Partial<T>) => boolean, label: string, fields: ZodFormFieldConfig<T>[], options?: {
2630
+ min?: number;
2631
+ max?: number;
2632
+ addButtonText?: string;
2633
+ removeButtonText?: string;
2634
+ enableReordering?: boolean;
2635
+ defaultItem?: () => any;
2636
+ }) => ZodFormFieldConfig<T>;
2393
2637
  /**
2394
2638
  * Create a content field for headers, questions, or custom content between fields
2395
2639
  *
@@ -2411,7 +2655,34 @@ declare const FormFieldHelpers: {
2411
2655
  isSubmitting: boolean;
2412
2656
  }) => React$1.ReactNode;
2413
2657
  className?: string;
2414
- name?: string;
2658
+ name?: Path<T>;
2659
+ }) => ZodFormFieldConfig<T>;
2660
+ /**
2661
+ * Create a custom field with full control over rendering
2662
+ *
2663
+ * @example
2664
+ * ```tsx
2665
+ * // Custom field with render function
2666
+ * FormFieldHelpers.custom<FormData>(
2667
+ * "skills",
2668
+ * "Skills",
2669
+ * ({ form, control }) => {
2670
+ * // Custom rendering logic
2671
+ * return <div>...</div>;
2672
+ * }
2673
+ * )
2674
+ * ```
2675
+ */
2676
+ custom: <T extends FieldValues>(name: Path<T> | ArrayPath<T>, label: string, render: (field: {
2677
+ name: Path<T> | ArrayPath<T>;
2678
+ control: Control<T>;
2679
+ form: UseFormReturn<T>;
2680
+ errors: FieldErrors<T>;
2681
+ isSubmitting: boolean;
2682
+ }) => React$1.ReactNode, options?: {
2683
+ description?: string;
2684
+ className?: string;
2685
+ isDisabled?: boolean;
2415
2686
  }) => ZodFormFieldConfig<T>;
2416
2687
  /**
2417
2688
  * Create a date field
@@ -2490,7 +2761,10 @@ declare const FormFieldHelpers: {
2490
2761
  * // With type
2491
2762
  * FormFieldHelpers.input("email", "Email", "email")
2492
2763
  *
2493
- * // With full customization
2764
+ * // With props only (no type)
2765
+ * FormFieldHelpers.input("name", "Name", { placeholder: "Enter name" })
2766
+ *
2767
+ * // With type and props
2494
2768
  * FormFieldHelpers.input("email", "Email", "email", {
2495
2769
  * placeholder: "Enter your email",
2496
2770
  * classNames: { input: "custom-input" },
@@ -2499,7 +2773,25 @@ declare const FormFieldHelpers: {
2499
2773
  * })
2500
2774
  * ```
2501
2775
  */
2502
- input: <T extends FieldValues>(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password", inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2776
+ input: typeof inputHelper;
2777
+ /**
2778
+ * Create a radio group field
2779
+ *
2780
+ * @example
2781
+ * ```tsx
2782
+ * // Simple radio group
2783
+ * FormFieldHelpers.radio("gender", "Gender", [
2784
+ * { label: "Male", value: "male" },
2785
+ * { label: "Female", value: "female" }
2786
+ * ])
2787
+ *
2788
+ * // With full customization
2789
+ * FormFieldHelpers.radio("gender", "Gender", options, {
2790
+ * orientation: "horizontal",
2791
+ * classNames: { base: "custom-radio" }
2792
+ * })
2793
+ * ```
2794
+ */
2503
2795
  /**
2504
2796
  * Create a radio group field
2505
2797
  *
@@ -2604,6 +2896,26 @@ declare const FormFieldHelpers: {
2604
2896
  };
2605
2897
  /**
2606
2898
  * Common field collections
2899
+ *
2900
+ * These helpers provide reusable field sets for common form patterns.
2901
+ * The `as Path<T>` assertions are necessary because TypeScript cannot prove
2902
+ * that string literals like "street" or "email" are valid paths in an arbitrary
2903
+ * form type `T`. These helpers are designed to work with any form type that
2904
+ * happens to have these fields - the type safety is enforced when you use them
2905
+ * with a specific form schema.
2906
+ *
2907
+ * @example
2908
+ * ```tsx
2909
+ * const schema = z.object({
2910
+ * street: z.string(),
2911
+ * city: z.string(),
2912
+ * // ... other fields
2913
+ * });
2914
+ *
2915
+ * const fields = [
2916
+ * ...CommonFields.address<z.infer<typeof schema>>(),
2917
+ * ];
2918
+ * ```
2607
2919
  */
2608
2920
  declare const CommonFields: {
2609
2921
  /**
@@ -2621,10 +2933,163 @@ declare const CommonFields: {
2621
2933
  };
2622
2934
 
2623
2935
  /**
2624
- * Unified field creation function
2625
- * Takes field type as first argument and delegates to appropriate helper
2936
+ * Discriminated union types for field creation parameters
2937
+ * This eliminates the need for 'unknown' types and type assertions
2938
+ */
2939
+ type FieldCreationParams<T extends FieldValues> = {
2940
+ type: "input";
2941
+ name: Path<T>;
2942
+ label: string;
2943
+ props?: {
2944
+ type?: "text" | "email" | "tel" | "password" | "number" | "url";
2945
+ placeholder?: string;
2946
+ description?: string;
2947
+ isDisabled?: boolean;
2948
+ className?: string;
2949
+ };
2950
+ } | {
2951
+ type: "textarea";
2952
+ name: Path<T>;
2953
+ label: string;
2954
+ props?: {
2955
+ placeholder?: string;
2956
+ description?: string;
2957
+ isDisabled?: boolean;
2958
+ className?: string;
2959
+ rows?: number;
2960
+ };
2961
+ } | {
2962
+ type: "select";
2963
+ name: Path<T>;
2964
+ label: string;
2965
+ options: {
2966
+ label: string;
2967
+ value: string | number;
2968
+ }[];
2969
+ } | {
2970
+ type: "autocomplete";
2971
+ name: Path<T>;
2972
+ label: string;
2973
+ options: {
2974
+ label: string;
2975
+ value: string | number;
2976
+ }[];
2977
+ props?: Record<string, unknown>;
2978
+ } | {
2979
+ type: "checkbox";
2980
+ name: Path<T>;
2981
+ label: string;
2982
+ props?: {
2983
+ description?: string;
2984
+ isDisabled?: boolean;
2985
+ className?: string;
2986
+ };
2987
+ } | {
2988
+ type: "switch";
2989
+ name: Path<T>;
2990
+ label: string;
2991
+ props?: {
2992
+ description?: string;
2993
+ isDisabled?: boolean;
2994
+ className?: string;
2995
+ };
2996
+ } | {
2997
+ type: "radio";
2998
+ name: Path<T>;
2999
+ label: string;
3000
+ options: {
3001
+ label: string;
3002
+ value: string | number;
3003
+ }[];
3004
+ props?: {
3005
+ description?: string;
3006
+ isDisabled?: boolean;
3007
+ className?: string;
3008
+ orientation?: "horizontal" | "vertical";
3009
+ };
3010
+ } | {
3011
+ type: "slider";
3012
+ name: Path<T>;
3013
+ label: string;
3014
+ props?: {
3015
+ min?: number;
3016
+ max?: number;
3017
+ step?: number;
3018
+ description?: string;
3019
+ isDisabled?: boolean;
3020
+ className?: string;
3021
+ };
3022
+ } | {
3023
+ type: "date";
3024
+ name: Path<T>;
3025
+ label: string;
3026
+ props?: {
3027
+ placeholder?: string;
3028
+ description?: string;
3029
+ isDisabled?: boolean;
3030
+ className?: string;
3031
+ };
3032
+ } | {
3033
+ type: "file";
3034
+ name: Path<T>;
3035
+ label: string;
3036
+ props?: {
3037
+ accept?: string;
3038
+ multiple?: boolean;
3039
+ description?: string;
3040
+ isDisabled?: boolean;
3041
+ className?: string;
3042
+ };
3043
+ } | {
3044
+ type: "fontPicker";
3045
+ name: Path<T>;
3046
+ label: string;
3047
+ props?: {
3048
+ description?: string;
3049
+ isDisabled?: boolean;
3050
+ className?: string;
3051
+ fontPickerProps?: {
3052
+ showFontPreview?: boolean;
3053
+ loadAllVariants?: boolean;
3054
+ onFontsLoaded?: (loaded: boolean) => void;
3055
+ fontsLoadedTimeout?: number;
3056
+ };
3057
+ };
3058
+ } | {
3059
+ type: "stringArray";
3060
+ name: Path<T>;
3061
+ label: string;
3062
+ props?: {
3063
+ placeholder?: string;
3064
+ maxItems?: number;
3065
+ minItems?: number;
3066
+ allowDuplicates?: boolean;
3067
+ validateItem?: (item: string) => string | true;
3068
+ transformItem?: (item: string) => string;
3069
+ addButtonText?: string;
3070
+ showAddButton?: boolean;
3071
+ description?: string;
3072
+ isDisabled?: boolean;
3073
+ className?: string;
3074
+ };
3075
+ } | {
3076
+ type: "content";
3077
+ name?: Path<T>;
3078
+ label?: string;
3079
+ title?: string | null;
3080
+ description?: string | null;
3081
+ render?: (field: {
3082
+ form: UseFormReturn<T>;
3083
+ errors: FieldErrors<T>;
3084
+ isSubmitting: boolean;
3085
+ }) => React$1.ReactNode;
3086
+ className?: string;
3087
+ };
3088
+ /**
3089
+ * Unified field creation function using discriminated union types
3090
+ * This provides full type safety without complex overloads
2626
3091
  */
2627
- declare function createField<T extends FieldValues>(type: string, name: Path<T>, label: string, optionsOrProps?: any, props?: any): ZodFormFieldConfig<T>;
3092
+ declare function createField<T extends FieldValues>(params: FieldCreationParams<T>): ZodFormFieldConfig<T>;
2628
3093
  /**
2629
3094
  * Builder pattern for advanced field creation
2630
3095
  */
@@ -2633,21 +3098,7 @@ declare class AdvancedFieldBuilder<T extends FieldValues> {
2633
3098
  /**
2634
3099
  * Add any field type using the unified API
2635
3100
  */
2636
- field(type: "input", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
2637
- field(type: "textarea", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
2638
- field(type: "select", name: Path<T>, label: string, options: {
2639
- label: string;
2640
- value: string | number;
2641
- }[], props?: Parameters<typeof createField<T>>[4]): this;
2642
- field(type: "checkbox", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
2643
- field(type: "switch", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
2644
- field(type: "radio", name: Path<T>, label: string, options: {
2645
- label: string;
2646
- value: string | number;
2647
- }[], props?: Parameters<typeof createField<T>>[4]): this;
2648
- field(type: "slider", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
2649
- field(type: "date", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
2650
- field(type: "file", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
3101
+ field(params: FieldCreationParams<T>): this;
2651
3102
  /**
2652
3103
  * Add a conditional field that shows/hides based on form data
2653
3104
  */
@@ -2655,7 +3106,7 @@ declare class AdvancedFieldBuilder<T extends FieldValues> {
2655
3106
  /**
2656
3107
  * Add a field array for dynamic repeating field groups
2657
3108
  */
2658
- fieldArray(name: Path<T>, label: string, fields: ZodFormFieldConfig<any>[], options?: {
3109
+ fieldArray(name: ArrayPath<T>, label: string, fields: ZodFormFieldConfig<T>[], options?: {
2659
3110
  min?: number;
2660
3111
  max?: number;
2661
3112
  addButtonText?: string;
@@ -2681,22 +3132,7 @@ declare class FieldArrayItemBuilder<TItem extends FieldValues> {
2681
3132
  /**
2682
3133
  * Add any field type using the unified API for array items
2683
3134
  */
2684
- field(type: "input", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
2685
- field(type: "textarea", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
2686
- field(type: "select", name: Path<TItem>, label: string, options: {
2687
- label: string;
2688
- value: string | number;
2689
- }[], props?: Parameters<typeof createField<TItem>>[4]): this;
2690
- field(type: "checkbox", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
2691
- field(type: "switch", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
2692
- field(type: "radio", name: Path<TItem>, label: string, options: {
2693
- label: string;
2694
- value: string | number;
2695
- }[], props?: Parameters<typeof createField<TItem>>[4]): this;
2696
- field(type: "slider", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
2697
- field(type: "date", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
2698
- field(type: "file", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
2699
- field(type: "fontPicker", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
3135
+ field(params: FieldCreationParams<TItem>): this;
2700
3136
  /**
2701
3137
  * Build the field array item configuration
2702
3138
  */
@@ -2713,8 +3149,8 @@ declare class FieldArrayBuilder<T extends FieldValues, TArrayName extends Path<T
2713
3149
  private arrayName;
2714
3150
  private fields;
2715
3151
  constructor(arrayName: TArrayName);
2716
- field(type: string, name: string, label: string, optionsOrProps?: any, props?: any): this;
2717
- build(): ZodFormFieldConfig<any>[];
3152
+ field(params: FieldCreationParams<Record<string, any>>): this;
3153
+ build(): ZodFormFieldConfig<T>[];
2718
3154
  }
2719
3155
  /**
2720
3156
  * Create a field array builder that constructs proper paths for array items
@@ -2883,17 +3319,32 @@ declare const field: {
2883
3319
  textarea: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["textarea"]>[2]) => TypeInferredBuilder<T>;
2884
3320
  };
2885
3321
 
3322
+ /**
3323
+ * Helper type to construct a nested path from a base path and sub-path.
3324
+ * Attempts to construct the path and falls back to Path<T> if TypeScript
3325
+ * can't verify the nested structure at compile time.
3326
+ *
3327
+ * @example
3328
+ * type T = { user: { name: string } };
3329
+ * type Nested = ConstructNestedPath<T, "user", "name">; // "user.name"
3330
+ */
3331
+ type ConstructNestedPath<T extends FieldValues, TBasePath extends Path<T>, TSubPath extends string> = `${TBasePath}.${TSubPath}` extends Path<T> ? `${TBasePath}.${TSubPath}` : Path<T>;
2886
3332
  /**
2887
3333
  * Enhanced nested path builder with better syntax for complex nested structures
2888
3334
  * Provides multiple approaches for handling nested field paths
2889
3335
  */
2890
3336
  declare class NestedPathBuilder<T extends FieldValues> {
2891
- private fields;
3337
+ fields: ZodFormFieldConfig<T>[];
2892
3338
  /**
2893
3339
  * Create a nested object path builder
2894
3340
  * Usage: builder.nest("address").field("street", "Street Address")
3341
+ *
3342
+ * @param path - A path in the form data structure. When called from root level,
3343
+ * accepts Path<T>. When called after .end() from a nested context,
3344
+ * accepts any string for nested paths under sections.
3345
+ * @returns A builder for nested paths under the specified path
2895
3346
  */
2896
- nest<TPath extends Path<T>>(path: TPath): NestedObjectBuilder<T, TPath>;
3347
+ nest(path: string & {}): NestedObjectBuilder<T, Path<T>>;
2897
3348
  /**
2898
3349
  * Create a section-based path builder
2899
3350
  * Usage: builder.section("shipping").field("street", "Street Address")
@@ -2901,14 +3352,14 @@ declare class NestedPathBuilder<T extends FieldValues> {
2901
3352
  section<TPath extends Path<T>>(path: TPath): SectionBuilder<T, TPath>;
2902
3353
  /**
2903
3354
  * Add a field with single path
2904
- * Usage: builder.field("firstName", "First Name")
3355
+ * Usage: builder.field({ type: "input", name: "firstName", label: "First Name" })
2905
3356
  */
2906
- field(name: Path<T>, label: string, type?: string, props?: any): this;
3357
+ field(params: FieldCreationParams<T> | FieldCreationParams<Record<string, any>>): this;
2907
3358
  /**
2908
3359
  * Add a field with path segments
2909
- * Usage: builder.fieldPath(["user", "profile", "name"], "Full Name")
3360
+ * Usage: builder.fieldPath({ type: "input", name: path.join("."), label: "Full Name" })
2910
3361
  */
2911
- fieldPath(path: string[], label: string, type?: string, props?: any): this;
3362
+ fieldPath(params: FieldCreationParams<T>): this;
2912
3363
  /**
2913
3364
  * Add a field with template literal path
2914
3365
  * Usage: builder.field`user.profile.name`("Full Name")
@@ -2930,11 +3381,16 @@ declare class NestedObjectBuilder<T extends FieldValues, TPath extends Path<T>>
2930
3381
  /**
2931
3382
  * Add a field to the current nested path
2932
3383
  */
2933
- field<FName extends string>(fieldName: FName, label: string, type?: string, props?: any): NestedObjectBuilder<T, TPath>;
3384
+ field(params: FieldCreationParams<Record<string, any>>): NestedObjectBuilder<T, TPath>;
2934
3385
  /**
2935
3386
  * Nest deeper into the object
3387
+ *
3388
+ * @param subPath - A string representing a nested path under the current path.
3389
+ * The parameter accepts any string; TypeScript validates the constructed
3390
+ * path (basePath.subPath) in the return type.
3391
+ * @returns A builder for the nested path
2936
3392
  */
2937
- nest<SubPath extends string>(subPath: SubPath): NestedObjectBuilder<T, TPath>;
3393
+ nest<SubPath extends string>(subPath: SubPath): NestedObjectBuilder<T, ConstructNestedPath<T, TPath, SubPath>>;
2938
3394
  /**
2939
3395
  * Return to the parent builder
2940
3396
  */
@@ -2950,20 +3406,25 @@ declare class SectionBuilder<T extends FieldValues, TPath extends Path<T>> {
2950
3406
  /**
2951
3407
  * Add a field to the current section
2952
3408
  */
2953
- field<FName extends string>(fieldName: FName, label: string, type?: string, props?: any): SectionBuilder<T, TPath>;
3409
+ field(params: FieldCreationParams<Record<string, any>>): SectionBuilder<T, TPath>;
2954
3410
  /**
2955
3411
  * Add multiple fields to the section
2956
3412
  */
2957
3413
  fields(fieldDefinitions: {
2958
3414
  name: string;
2959
3415
  label: string;
2960
- type?: string;
2961
- props?: any;
3416
+ type?: FormFieldType;
3417
+ props?: Record<string, unknown>;
2962
3418
  }[]): SectionBuilder<T, TPath>;
2963
3419
  /**
2964
3420
  * Nest deeper into the section
3421
+ *
3422
+ * @param subPath - A string representing a nested path under the current section path.
3423
+ * The parameter accepts any string; TypeScript validates the constructed
3424
+ * path (basePath.subPath) in the return type.
3425
+ * @returns A builder for the nested path
2965
3426
  */
2966
- nest<SubPath extends string>(subPath: SubPath): NestedObjectBuilder<T, TPath>;
3427
+ nest<SubPath extends string = string>(subPath: SubPath): NestedObjectBuilder<T, ConstructNestedPath<T, TPath, string>>;
2967
3428
  /**
2968
3429
  * Return to the parent builder
2969
3430
  */
@@ -2979,7 +3440,9 @@ declare class FieldTemplateBuilder<T extends FieldValues> {
2979
3440
  /**
2980
3441
  * Complete the field definition
2981
3442
  */
2982
- complete(label: string, type?: string, props?: any): NestedPathBuilder<T>;
3443
+ complete(params: Omit<FieldCreationParams<Record<string, any>>, "name"> & {
3444
+ name?: string;
3445
+ }): NestedPathBuilder<T>;
2983
3446
  }
2984
3447
  /**
2985
3448
  * Factory function for creating the nested path builder
@@ -2989,9 +3452,9 @@ declare function createNestedPathBuilder<T extends FieldValues>(): NestedPathBui
2989
3452
  /**
2990
3453
  * Options for the useDebouncedValidation hook.
2991
3454
  */
2992
- interface UseDebouncedValidationOptions {
3455
+ interface UseDebouncedValidationOptions<T extends FieldValues = FieldValues> {
2993
3456
  delay?: number;
2994
- fields?: string[];
3457
+ fields?: Path<T>[];
2995
3458
  enabled?: boolean;
2996
3459
  }
2997
3460
  /**
@@ -3044,7 +3507,7 @@ interface UseDebouncedValidationOptions {
3044
3507
  * @see {@link useDebouncedFieldValidation} for single field debouncing
3045
3508
  * @category Hooks
3046
3509
  */
3047
- declare function useDebouncedValidation<T extends Record<string, any>>(form: UseFormReturn<T>, options?: UseDebouncedValidationOptions): {
3510
+ declare function useDebouncedValidation<T extends FieldValues>(form: UseFormReturn<T>, options?: UseDebouncedValidationOptions<T>): {
3048
3511
  debouncedTrigger: () => void;
3049
3512
  isDebouncing: boolean;
3050
3513
  };
@@ -3095,7 +3558,7 @@ declare function useDebouncedValidation<T extends Record<string, any>>(form: Use
3095
3558
  * @see {@link useDebouncedValidation} for multiple fields
3096
3559
  * @category Hooks
3097
3560
  */
3098
- declare function useDebouncedFieldValidation<T extends Record<string, any>>(form: UseFormReturn<T>, fieldName: keyof T, options?: {
3561
+ declare function useDebouncedFieldValidation<T extends FieldValues>(form: UseFormReturn<T>, fieldName: Path<T>, options?: {
3099
3562
  delay?: number;
3100
3563
  enabled?: boolean;
3101
3564
  }): {
@@ -3109,7 +3572,7 @@ declare function useDebouncedFieldValidation<T extends Record<string, any>>(form
3109
3572
  * @template T - The form data type
3110
3573
  */
3111
3574
  interface UseInferredFormOptions<T extends FieldValues> {
3112
- defaultValues?: Partial<T>;
3575
+ defaultValues?: DefaultValues<T>;
3113
3576
  mode?: "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
3114
3577
  reValidateMode?: "onChange" | "onBlur" | "onSubmit";
3115
3578
  shouldFocusError?: boolean;
@@ -3213,6 +3676,33 @@ declare function useTypeInferredForm<T extends FieldValues>(formConfig: {
3213
3676
  fields: ZodFormFieldConfig<T>[];
3214
3677
  }, options?: UseInferredFormOptions<T>): UseFormReturn<T>;
3215
3678
 
3679
+ /**
3680
+ * Hook for lazy field registration to reduce initial memory usage.
3681
+ *
3682
+ * This hook registers fields only when they become active (e.g., when a condition is met),
3683
+ * preventing the memory overhead of always-registered fields while avoiding
3684
+ * register/unregister cycles that cause memory leaks in Cypress.
3685
+ *
3686
+ * @param fieldName - The field name to potentially register
3687
+ * @param shouldRegister - Function that determines if the field should be registered
3688
+ * @param defaultValue - Default value for the field when registered
3689
+ * @param rules - Validation rules for the field
3690
+ */
3691
+ declare function useLazyFieldRegistration<TFieldValues extends FieldValues>(fieldName: FieldPath<TFieldValues>, shouldRegister: () => boolean, defaultValue?: any, rules?: any): {
3692
+ currentValue: undefined;
3693
+ isRegistered: boolean;
3694
+ };
3695
+ /**
3696
+ * Hook for lazy field array registration.
3697
+ *
3698
+ * Similar to useLazyFieldRegistration but specifically for field arrays,
3699
+ * which have more complex registration requirements.
3700
+ */
3701
+ declare function useLazyFieldArrayRegistration<TFieldValues extends FieldValues>(arrayName: FieldPath<TFieldValues>, shouldRegister: () => boolean, defaultValue?: any[]): {
3702
+ currentValue: any;
3703
+ isRegistered: boolean;
3704
+ };
3705
+
3216
3706
  /**
3217
3707
  * Props for the ConditionalField component.
3218
3708
  *
@@ -3292,6 +3782,8 @@ declare function ContentField<TFieldValues extends FieldValues>({ config, form,
3292
3782
  interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
3293
3783
  config: FieldArrayConfig<TFieldValues>;
3294
3784
  className?: string;
3785
+ /** Whether this field array should always be registered (for conditional rendering) */
3786
+ alwaysRegistered?: boolean;
3295
3787
  }
3296
3788
  /**
3297
3789
  * Field array component for dynamic repeating field groups.
@@ -3408,7 +3900,7 @@ interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
3408
3900
  * @see {@link createFieldArrayCustomConfig} for advanced custom rendering
3409
3901
  * @category Fields
3410
3902
  */
3411
- declare function FieldArrayField<TFieldValues extends FieldValues>({ className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
3903
+ declare function FieldArrayField<TFieldValues extends FieldValues>({ alwaysRegistered, className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
3412
3904
 
3413
3905
  /**
3414
3906
  * Props for the DynamicSectionField component.
@@ -3521,7 +4013,7 @@ declare function throttle<T extends (...args: any[]) => any>(func: T, limit: num
3521
4013
  /**
3522
4014
  * Memoization helper for expensive computations
3523
4015
  */
3524
- declare function useMemoizedCallback<T extends (...args: any[]) => any>(callback: T, deps: React.DependencyList): T;
4016
+ declare function useMemoizedCallback<T extends (...args: unknown[]) => unknown>(callback: T, deps: React.DependencyList): T;
3525
4017
  /**
3526
4018
  * Shallow comparison for React.memo
3527
4019
  */
@@ -3700,6 +4192,40 @@ interface CreateFieldArrayCustomConfigOptions<TFieldValues extends FieldValues>
3700
4192
  */
3701
4193
  declare function createFieldArrayCustomConfig<TFieldValues extends FieldValues>(options: CreateFieldArrayCustomConfigOptions<TFieldValues>): CustomFieldConfig<TFieldValues>;
3702
4194
 
4195
+ /**
4196
+ * Memory management utilities for field arrays to prevent memory leaks
4197
+ * in Cypress tests and long-running applications.
4198
+ */
4199
+ /**
4200
+ * Hook to clean up field array memory when component unmounts.
4201
+ * Helps prevent memory accumulation in Cypress Electron renderer.
4202
+ */
4203
+ declare function useFieldArrayMemoryCleanup<TFieldValues extends FieldValues>(arrayName: FieldPath<TFieldValues>): {
4204
+ cleanup: () => void;
4205
+ };
4206
+ /**
4207
+ * Utility to force garbage collection hints for Cypress tests.
4208
+ * Only effective when experimentalMemoryManagement is enabled.
4209
+ */
4210
+ declare function suggestGarbageCollection(): void;
4211
+ /**
4212
+ * Memory-safe field array operations that include cleanup hints.
4213
+ */
4214
+ declare const memorySafeFieldArray: {
4215
+ /**
4216
+ * Add items to a field array with memory management.
4217
+ */
4218
+ addItems: <TFieldValues extends FieldValues>(append: (value: any) => void, items: any[], onProgress?: (addedCount: number) => void) => void;
4219
+ /**
4220
+ * Clear entire field array with memory cleanup.
4221
+ */
4222
+ clearArray: <TFieldValues extends FieldValues>(setValue: (name: FieldPath<TFieldValues>, value: any) => void, arrayName: FieldPath<TFieldValues>) => void;
4223
+ /**
4224
+ * Remove items from a field array with memory cleanup.
4225
+ */
4226
+ removeItems: <TFieldValues extends FieldValues>(remove: (index: number) => void, indices: number[]) => void;
4227
+ };
4228
+
3703
4229
  /**
3704
4230
  * Common validation patterns for forms
3705
4231
  */
@@ -3783,4 +4309,4 @@ declare const validationUtils: {
3783
4309
  }>;
3784
4310
  };
3785
4311
 
3786
- export { AdvancedFieldBuilder, type ArraySyncOptions, type ArraySyncResult, AutocompleteField, type AutocompleteFieldProps, type AutocompleteOption, type BaseFormFieldConfig, BasicFormBuilder, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, CommonFields, ConditionalField, type ConditionalFieldConfig, type ConditionalFieldProps, type ConditionalValidation, ConfigurableForm, ContentField, type ContentFieldConfig, type CreateFieldArrayCustomConfigOptions, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type DynamicSectionConfig, DynamicSectionField, type DynamicSectionFieldProps, type EnhancedFormState, FieldArrayBuilder, type FieldArrayConfig, FieldArrayField, type FieldArrayFieldProps, FieldArrayItemBuilder, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, FormFieldHelpers, type FormProps, FormProvider, FormStatus, type FormStatusProps, type FormStep, type FormSubmissionState, type FormTestUtils, FormToast, type FormToastProps, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, ServerActionForm, type ServerFieldError, type ServerFormError, SimpleForm, type SimpleFormProps, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, TypeInferredBuilder, type UseDebouncedValidationOptions, type UseEnhancedFormStateOptions, type UseInferredFormOptions, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, asyncValidation, commonValidations, createAdvancedBuilder, createBasicFormBuilder, createDateSchema, createEmailSchema, createField, createFieldArrayBuilder, createFieldArrayCustomConfig, createFieldArrayItemBuilder, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNestedPathBuilder, createNumberRangeSchema, createOptimizedFieldHandler, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createTypeInferredBuilder, createUrlSchema, createZodFormConfig, crossFieldValidation, debounce, deepEqual, defineInferredForm, errorMessages, field, getFieldError, getFormErrors, hasFieldError, hasFormErrors, serverValidation, shallowEqual, simulateFieldInput, simulateFormSubmission, syncArrays, throttle, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };
4312
+ export { AdvancedFieldBuilder, type ArraySyncOptions, type ArraySyncResult, AutocompleteField, type AutocompleteFieldProps, type AutocompleteOption, type BaseFormFieldConfig, BasicFormBuilder, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, CheckboxGroupField, type CheckboxGroupFieldConfig, type CheckboxGroupFieldProps, type CommonFieldDefaults, CommonFields, ConditionalField, type ConditionalFieldConfig, type ConditionalFieldProps, type ConditionalValidation, ConfigurableForm, ContentField, type ContentFieldConfig, type CreateFieldArrayCustomConfigOptions, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type DynamicSectionConfig, DynamicSectionField, type DynamicSectionFieldProps, type EnhancedFormState, FieldArrayBuilder, type FieldArrayConfig, FieldArrayField, type FieldArrayFieldProps, FieldArrayItemBuilder, type FieldBaseProps, type FieldCreationParams, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, FormFieldHelpers, type FormFieldType, type FormProps, FormProvider, FormStatus, type FormStatusProps, type FormStep, type FormSubmissionState, type FormTestUtils, FormToast, type FormToastProps, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, ServerActionForm, type ServerFieldError, type ServerFormError, SimpleForm, type SimpleFormProps, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringArrayFieldConfig, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, TypeInferredBuilder, type UseDebouncedValidationOptions, type UseEnhancedFormStateOptions, type UseInferredFormOptions, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, asyncValidation, commonValidations, createAdvancedBuilder, createBasicFormBuilder, createDateSchema, createEmailSchema, createField, createFieldArrayBuilder, createFieldArrayCustomConfig, createFieldArrayItemBuilder, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNestedPathBuilder, createNumberRangeSchema, createOptimizedFieldHandler, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createTypeInferredBuilder, createUrlSchema, createZodFormConfig, crossFieldValidation, debounce, deepEqual, defineInferredForm, errorMessages, field, getFieldError, getFormErrors, hasFieldError, hasFormErrors, memorySafeFieldArray, pathToString, serverValidation, shallowEqual, simulateFieldInput, simulateFormSubmission, suggestGarbageCollection, syncArrays, throttle, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFieldArrayMemoryCleanup, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useLazyFieldArrayRegistration, useLazyFieldRegistration, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };