@rachelallyson/hero-hook-form 1.2.0 → 2.0.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
@@ -103,7 +103,27 @@ interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFi
103
103
  isSubmitting: boolean;
104
104
  }) => React.ReactNode;
105
105
  }
106
- type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | FontPickerFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues>;
106
+ interface ConditionalFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
107
+ type: "conditional";
108
+ condition: (formData: Partial<TFieldValues>) => boolean;
109
+ field: ZodFormFieldConfig<TFieldValues>;
110
+ }
111
+ interface FieldArrayConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
112
+ type: "fieldArray";
113
+ fields: ZodFormFieldConfig<TFieldValues>[];
114
+ min?: number;
115
+ max?: number;
116
+ addButtonText?: string;
117
+ removeButtonText?: string;
118
+ }
119
+ interface DynamicSectionConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
120
+ type: "dynamicSection";
121
+ title?: string;
122
+ description?: string;
123
+ condition: (formData: Partial<TFieldValues>) => boolean;
124
+ fields: ZodFormFieldConfig<TFieldValues>[];
125
+ }
126
+ 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>;
107
127
  interface FormConfig<TFieldValues extends FieldValues> {
108
128
  fields: FormFieldConfig<TFieldValues>[];
109
129
  layout?: "vertical" | "horizontal" | "grid" | "custom";
@@ -117,7 +137,7 @@ interface FormConfig<TFieldValues extends FieldValues> {
117
137
  className?: string;
118
138
  defaultValues?: Partial<TFieldValues>;
119
139
  }
120
- 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">;
140
+ 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">;
121
141
  interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
122
142
  schema: zod.ZodSchema<TFieldValues>;
123
143
  fields: ZodFormFieldConfig<TFieldValues>[];
@@ -220,7 +240,7 @@ interface FormFieldProps<TFieldValues extends FieldValues> {
220
240
  form: UseFormReturn<TFieldValues>;
221
241
  submissionState: FormSubmissionState;
222
242
  }
223
- declare function FormField<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;
243
+ declare const FormField: <TFieldValues extends FieldValues>(props: FormFieldProps<TFieldValues>) => React$1.JSX.Element;
224
244
 
225
245
  type CheckboxFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
226
246
  checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
@@ -256,7 +276,7 @@ type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldVa
256
276
  inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
257
277
  transform?: (value: string) => string;
258
278
  };
259
- declare function InputField<TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>): React$1.JSX.Element;
279
+ declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
260
280
 
261
281
  interface RadioOption<TValue extends string | number> {
262
282
  label: string;
@@ -418,9 +438,38 @@ interface FormProps<TFieldValues extends FieldValues> {
418
438
  }
419
439
  declare function FormProvider<TFieldValues extends FieldValues>(props: FormProps<TFieldValues>): React$1.JSX.Element;
420
440
 
441
+ interface EnhancedFormState<T extends FieldValues> {
442
+ status: "idle" | "submitting" | "success" | "error";
443
+ isSubmitting: boolean;
444
+ isSuccess: boolean;
445
+ isError: boolean;
446
+ error?: string;
447
+ submittedData?: T;
448
+ touchedFields: Set<Path<T>>;
449
+ dirtyFields: Set<Path<T>>;
450
+ hasErrors: boolean;
451
+ errorCount: number;
452
+ handleSuccess: (data: T) => void;
453
+ handleError: (error: string) => void;
454
+ reset: () => void;
455
+ }
456
+ interface UseEnhancedFormStateOptions<T extends FieldValues> {
457
+ onSuccess?: (data: T) => void;
458
+ onError?: (error: string) => void;
459
+ successMessage?: string;
460
+ errorMessage?: string;
461
+ autoReset?: boolean;
462
+ resetDelay?: number;
463
+ }
464
+ declare function useEnhancedFormState<T extends FieldValues>(form: UseFormReturn<T>, options?: UseEnhancedFormStateOptions<T>): EnhancedFormState<T>;
465
+
421
466
  interface SubmitButtonProps {
422
467
  children: React$1.ReactNode;
423
468
  isLoading?: boolean;
469
+ isSuccess?: boolean;
470
+ successText?: string;
471
+ loadingText?: string;
472
+ enhancedState?: EnhancedFormState<any>;
424
473
  buttonProps?: Omit<React$1.ComponentProps<typeof Button$1>, "type" | "isLoading">;
425
474
  }
426
475
  declare function SubmitButton(props: SubmitButtonProps): React$1.JSX.Element;
@@ -565,6 +614,29 @@ declare const commonValidations: {
565
614
  requiredCheckbox: (fieldName: string) => z.ZodBoolean;
566
615
  url: z.ZodString;
567
616
  };
617
+ /**
618
+ * Cross-field validation helpers
619
+ */
620
+ declare const crossFieldValidation: {
621
+ /**
622
+ * Password confirmation validation
623
+ */
624
+ passwordConfirmation: (passwordField: string, confirmField: string) => z.ZodObject<{
625
+ [x: string]: z.ZodString;
626
+ }, z.core.$strip>;
627
+ /**
628
+ * Date range validation
629
+ */
630
+ dateRange: (startField: string, endField: string) => z.ZodObject<{
631
+ [x: string]: z.ZodString;
632
+ }, z.core.$strip>;
633
+ /**
634
+ * Conditional required field validation
635
+ */
636
+ conditionalRequired: (field: string, conditionField: string, conditionValue: any) => z.ZodObject<{
637
+ [x: string]: z.ZodString | z.ZodAny;
638
+ }, z.core.$strip>;
639
+ };
568
640
 
569
641
  interface ZodFormProps<T extends FieldValues> {
570
642
  className?: string;
@@ -602,4 +674,657 @@ declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormCon
602
674
  */
603
675
  declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: Partial<TFieldValues>): ZodFormConfig<TFieldValues>;
604
676
 
605
- export { type BaseFormFieldConfig, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, type ConditionalValidation, ConfigurableForm, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, type FormProps, FormProvider, type FormStep, type FormSubmissionState, type FormTestUtils, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, type ServerFieldError, type ServerFormError, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, commonValidations, createConditionalSchema, createConfirmPasswordSchema, createDateSchema, createEmailSchema, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNumberRangeSchema, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createUrlSchema, createZodFormConfig, getFieldError, getFormErrors, hasFieldError, hasFormErrors, simulateFieldInput, simulateFormSubmission, useFormHelper, useHeroForm, useHeroHookFormDefaults, useZodForm, waitForFormState };
677
+ /**
678
+ * Basic form field builder that eliminates "as const" assertions
679
+ * Focuses on the most common use cases
680
+ */
681
+ declare class BasicFormBuilder<T extends FieldValues> {
682
+ private fields;
683
+ /**
684
+ * Add an input field
685
+ */
686
+ input(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password"): this;
687
+ /**
688
+ * Add a textarea field
689
+ */
690
+ textarea(name: Path<T>, label: string, placeholder?: string): this;
691
+ /**
692
+ * Add a select field
693
+ */
694
+ select(name: Path<T>, label: string, options: {
695
+ label: string;
696
+ value: string | number;
697
+ }[]): this;
698
+ /**
699
+ * Add a checkbox field
700
+ */
701
+ checkbox(name: Path<T>, label: string): this;
702
+ /**
703
+ * Add a switch field
704
+ */
705
+ switch(name: Path<T>, label: string): this;
706
+ /**
707
+ * Build the final field configuration array
708
+ */
709
+ build(): ZodFormFieldConfig<T>[];
710
+ }
711
+ /**
712
+ * Create a new simple form field builder
713
+ */
714
+ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuilder<T>;
715
+ /**
716
+ * Simple helper functions for common field types
717
+ */
718
+ declare const FormFieldHelpers: {
719
+ /**
720
+ * Create an input field
721
+ */
722
+ input: <T extends FieldValues>(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password") => ZodFormFieldConfig<T>;
723
+ /**
724
+ * Create a textarea field
725
+ */
726
+ textarea: <T extends FieldValues>(name: Path<T>, label: string, placeholder?: string) => ZodFormFieldConfig<T>;
727
+ /**
728
+ * Create a select field
729
+ */
730
+ select: <T extends FieldValues>(name: Path<T>, label: string, options: {
731
+ label: string;
732
+ value: string | number;
733
+ }[]) => ZodFormFieldConfig<T>;
734
+ /**
735
+ * Create a checkbox field
736
+ */
737
+ checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
738
+ /**
739
+ * Create a switch field
740
+ */
741
+ switch: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
742
+ };
743
+ /**
744
+ * Common field collections
745
+ */
746
+ declare const CommonFields: {
747
+ /**
748
+ * Personal information fields
749
+ */
750
+ personal: <T extends FieldValues>() => ZodFormFieldConfig<T>[];
751
+ /**
752
+ * Address fields
753
+ */
754
+ address: <T extends FieldValues>() => ZodFormFieldConfig<T>[];
755
+ /**
756
+ * Terms and conditions fields
757
+ */
758
+ terms: <T extends FieldValues>() => ZodFormFieldConfig<T>[];
759
+ };
760
+
761
+ /**
762
+ * Unified field creation function
763
+ * Takes field type as first argument and delegates to appropriate helper
764
+ */
765
+ declare function createField<T extends FieldValues>(type: string, name: Path<T>, label: string, optionsOrProps?: any, props?: any): ZodFormFieldConfig<T>;
766
+ /**
767
+ * Builder pattern for advanced field creation
768
+ */
769
+ declare class AdvancedFieldBuilder<T extends FieldValues> {
770
+ private fields;
771
+ /**
772
+ * Add any field type using the unified API
773
+ */
774
+ field(type: "input", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
775
+ field(type: "textarea", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
776
+ field(type: "select", name: Path<T>, label: string, options: {
777
+ label: string;
778
+ value: string | number;
779
+ }[], props?: Parameters<typeof createField<T>>[4]): this;
780
+ field(type: "checkbox", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
781
+ field(type: "switch", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
782
+ field(type: "radio", name: Path<T>, label: string, options: {
783
+ label: string;
784
+ value: string | number;
785
+ }[], props?: Parameters<typeof createField<T>>[4]): this;
786
+ field(type: "slider", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
787
+ field(type: "date", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
788
+ field(type: "file", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
789
+ /**
790
+ * Add a conditional field that shows/hides based on form data
791
+ */
792
+ conditionalField(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>): this;
793
+ /**
794
+ * Add a field array for dynamic repeating field groups
795
+ */
796
+ fieldArray(name: Path<T>, label: string, fields: ZodFormFieldConfig<any>[], options?: {
797
+ min?: number;
798
+ max?: number;
799
+ addButtonText?: string;
800
+ removeButtonText?: string;
801
+ }): this;
802
+ /**
803
+ * Add a dynamic section that shows/hides based on form data
804
+ */
805
+ dynamicSection(name: Path<T>, condition: (formData: Partial<T>) => boolean, fields: ZodFormFieldConfig<T>[], options?: {
806
+ title?: string;
807
+ description?: string;
808
+ }): this;
809
+ /**
810
+ * Build the final field configuration array
811
+ */
812
+ build(): ZodFormFieldConfig<T>[];
813
+ }
814
+ /**
815
+ * Field Array Builder for strongly-typed array item fields
816
+ */
817
+ declare class FieldArrayItemBuilder<TItem extends FieldValues> {
818
+ private fields;
819
+ /**
820
+ * Add any field type using the unified API for array items
821
+ */
822
+ field(type: "input", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
823
+ field(type: "textarea", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
824
+ field(type: "select", name: Path<TItem>, label: string, options: {
825
+ label: string;
826
+ value: string | number;
827
+ }[], props?: Parameters<typeof createField<TItem>>[4]): this;
828
+ field(type: "checkbox", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
829
+ field(type: "switch", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
830
+ field(type: "radio", name: Path<TItem>, label: string, options: {
831
+ label: string;
832
+ value: string | number;
833
+ }[], props?: Parameters<typeof createField<TItem>>[4]): this;
834
+ field(type: "slider", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
835
+ field(type: "date", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
836
+ field(type: "file", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
837
+ field(type: "fontPicker", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
838
+ /**
839
+ * Build the field array item configuration
840
+ */
841
+ build(): ZodFormFieldConfig<TItem>[];
842
+ }
843
+ /**
844
+ * Create a field array item builder for strongly-typed array fields
845
+ */
846
+ declare function createFieldArrayItemBuilder<TItem extends FieldValues>(): FieldArrayItemBuilder<TItem>;
847
+ /**
848
+ * Field Array Builder for constructing field arrays with proper paths
849
+ */
850
+ declare class FieldArrayBuilder<T extends FieldValues, TArrayName extends Path<T>> {
851
+ private arrayName;
852
+ private fields;
853
+ constructor(arrayName: TArrayName);
854
+ field(type: string, name: string, label: string, optionsOrProps?: any, props?: any): this;
855
+ build(): ZodFormFieldConfig<any>[];
856
+ }
857
+ /**
858
+ * Create a field array builder that constructs proper paths for array items
859
+ */
860
+ declare function createFieldArrayBuilder<T extends FieldValues, TArrayName extends Path<T>>(arrayName: TArrayName): FieldArrayBuilder<T, TArrayName>;
861
+ /**
862
+ * Create a new advanced field builder
863
+ */
864
+ declare function createAdvancedBuilder<T extends FieldValues>(): AdvancedFieldBuilder<T>;
865
+
866
+ /**
867
+ * Type-inferred form builder that auto-generates both schema and field configs
868
+ */
869
+ declare class TypeInferredBuilder<T extends FieldValues> {
870
+ private schemaFields;
871
+ private formFields;
872
+ /**
873
+ * Add a text field
874
+ */
875
+ text(name: Path<T>, label: string, options?: {
876
+ placeholder?: string;
877
+ description?: string;
878
+ isDisabled?: boolean;
879
+ className?: string;
880
+ minLength?: number;
881
+ maxLength?: number;
882
+ pattern?: string;
883
+ }): this;
884
+ /**
885
+ * Add an email field
886
+ */
887
+ email(name: Path<T>, label: string, options?: {
888
+ placeholder?: string;
889
+ description?: string;
890
+ isDisabled?: boolean;
891
+ className?: string;
892
+ }): this;
893
+ /**
894
+ * Add a number field
895
+ */
896
+ number(name: Path<T>, label: string, options?: {
897
+ placeholder?: string;
898
+ description?: string;
899
+ isDisabled?: boolean;
900
+ className?: string;
901
+ min?: number;
902
+ max?: number;
903
+ step?: number;
904
+ }): this;
905
+ /**
906
+ * Add a textarea field
907
+ */
908
+ textarea(name: Path<T>, label: string, options?: {
909
+ placeholder?: string;
910
+ description?: string;
911
+ isDisabled?: boolean;
912
+ className?: string;
913
+ rows?: number;
914
+ minLength?: number;
915
+ }): this;
916
+ /**
917
+ * Add a select field
918
+ */
919
+ select(name: Path<T>, label: string, options: {
920
+ label: string;
921
+ value: string | number;
922
+ }[], fieldOptions?: {
923
+ placeholder?: string;
924
+ description?: string;
925
+ isDisabled?: boolean;
926
+ className?: string;
927
+ }): this;
928
+ /**
929
+ * Add a checkbox field
930
+ */
931
+ checkbox(name: Path<T>, label: string, options?: {
932
+ description?: string;
933
+ isDisabled?: boolean;
934
+ className?: string;
935
+ required?: boolean;
936
+ }): this;
937
+ /**
938
+ * Add a switch field
939
+ */
940
+ switch(name: Path<T>, label: string, options?: {
941
+ description?: string;
942
+ isDisabled?: boolean;
943
+ className?: string;
944
+ }): this;
945
+ /**
946
+ * Add a radio field
947
+ */
948
+ radio(name: Path<T>, label: string, options: {
949
+ label: string;
950
+ value: string | number;
951
+ }[], fieldOptions?: {
952
+ description?: string;
953
+ isDisabled?: boolean;
954
+ className?: string;
955
+ orientation?: "horizontal" | "vertical";
956
+ }): this;
957
+ /**
958
+ * Add a slider field
959
+ */
960
+ slider(name: Path<T>, label: string, options?: {
961
+ min?: number;
962
+ max?: number;
963
+ step?: number;
964
+ description?: string;
965
+ isDisabled?: boolean;
966
+ className?: string;
967
+ }): this;
968
+ /**
969
+ * Add a date field
970
+ */
971
+ date(name: Path<T>, label: string, options?: {
972
+ placeholder?: string;
973
+ description?: string;
974
+ isDisabled?: boolean;
975
+ className?: string;
976
+ }): this;
977
+ /**
978
+ * Add a file field
979
+ */
980
+ file(name: Path<T>, label: string, options?: {
981
+ accept?: string;
982
+ multiple?: boolean;
983
+ description?: string;
984
+ isDisabled?: boolean;
985
+ className?: string;
986
+ }): this;
987
+ /**
988
+ * Build the final schema and fields
989
+ */
990
+ build(): {
991
+ schema: z.ZodSchema<T>;
992
+ fields: ZodFormFieldConfig<T>[];
993
+ };
994
+ }
995
+ /**
996
+ * Create a new type-inferred form builder
997
+ */
998
+ declare function createTypeInferredBuilder<T extends FieldValues>(): TypeInferredBuilder<T>;
999
+ /**
1000
+ * Define a form with type inference
1001
+ */
1002
+ declare function defineInferredForm<T extends FieldValues>(fieldDefinitions: (builder: TypeInferredBuilder<T>) => TypeInferredBuilder<T>): {
1003
+ schema: z.ZodSchema<T>;
1004
+ fields: ZodFormFieldConfig<T>[];
1005
+ };
1006
+ /**
1007
+ * Field type builders for individual field creation
1008
+ */
1009
+ declare const field: {
1010
+ text: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["text"]>[2]) => TypeInferredBuilder<T>;
1011
+ email: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["email"]>[2]) => TypeInferredBuilder<T>;
1012
+ number: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["number"]>[2]) => TypeInferredBuilder<T>;
1013
+ textarea: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["textarea"]>[2]) => TypeInferredBuilder<T>;
1014
+ select: <T extends FieldValues>(name: Path<T>, label: string, options: {
1015
+ label: string;
1016
+ value: string | number;
1017
+ }[], fieldOptions?: Parameters<TypeInferredBuilder<T>["select"]>[3]) => TypeInferredBuilder<T>;
1018
+ checkbox: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["checkbox"]>[2]) => TypeInferredBuilder<T>;
1019
+ switch: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["switch"]>[2]) => TypeInferredBuilder<T>;
1020
+ radio: <T extends FieldValues>(name: Path<T>, label: string, options: {
1021
+ label: string;
1022
+ value: string | number;
1023
+ }[], fieldOptions?: Parameters<TypeInferredBuilder<T>["radio"]>[3]) => TypeInferredBuilder<T>;
1024
+ slider: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["slider"]>[2]) => TypeInferredBuilder<T>;
1025
+ date: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["date"]>[2]) => TypeInferredBuilder<T>;
1026
+ file: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["file"]>[2]) => TypeInferredBuilder<T>;
1027
+ };
1028
+
1029
+ /**
1030
+ * Enhanced nested path builder with better syntax for complex nested structures
1031
+ * Provides multiple approaches for handling nested field paths
1032
+ */
1033
+ declare class NestedPathBuilder<T extends FieldValues> {
1034
+ private fields;
1035
+ /**
1036
+ * Create a nested object path builder
1037
+ * Usage: builder.nest("address").field("street", "Street Address")
1038
+ */
1039
+ nest<TPath extends Path<T>>(path: TPath): NestedObjectBuilder<T, TPath>;
1040
+ /**
1041
+ * Create a section-based path builder
1042
+ * Usage: builder.section("shipping").field("street", "Street Address")
1043
+ */
1044
+ section<TPath extends Path<T>>(path: TPath): SectionBuilder<T, TPath>;
1045
+ /**
1046
+ * Add a field with single path
1047
+ * Usage: builder.field("firstName", "First Name")
1048
+ */
1049
+ field(name: Path<T>, label: string, type?: string, props?: any): this;
1050
+ /**
1051
+ * Add a field with path segments
1052
+ * Usage: builder.fieldPath(["user", "profile", "name"], "Full Name")
1053
+ */
1054
+ fieldPath(path: string[], label: string, type?: string, props?: any): this;
1055
+ /**
1056
+ * Add a field with template literal path
1057
+ * Usage: builder.field`user.profile.name`("Full Name")
1058
+ */
1059
+ fieldTemplate(path: TemplateStringsArray, ...args: any[]): FieldTemplateBuilder<T>;
1060
+ /**
1061
+ * Return to the parent builder (no-op for root builder)
1062
+ */
1063
+ end(): this;
1064
+ build(): ZodFormFieldConfig<T>[];
1065
+ }
1066
+ /**
1067
+ * Nested object builder for chaining nested paths
1068
+ */
1069
+ declare class NestedObjectBuilder<T extends FieldValues, TPath extends Path<T>> {
1070
+ private parent;
1071
+ private path;
1072
+ constructor(parent: NestedPathBuilder<T>, path: TPath);
1073
+ /**
1074
+ * Add a field to the current nested path
1075
+ */
1076
+ field<FName extends string>(fieldName: FName, label: string, type?: string, props?: any): NestedObjectBuilder<T, TPath>;
1077
+ /**
1078
+ * Nest deeper into the object
1079
+ */
1080
+ nest<SubPath extends string>(subPath: SubPath): NestedObjectBuilder<T, TPath>;
1081
+ /**
1082
+ * Return to the parent builder
1083
+ */
1084
+ end(): NestedPathBuilder<T>;
1085
+ }
1086
+ /**
1087
+ * Section builder for grouping related fields
1088
+ */
1089
+ declare class SectionBuilder<T extends FieldValues, TPath extends Path<T>> {
1090
+ private parent;
1091
+ private path;
1092
+ constructor(parent: NestedPathBuilder<T>, path: TPath);
1093
+ /**
1094
+ * Add a field to the current section
1095
+ */
1096
+ field<FName extends string>(fieldName: FName, label: string, type?: string, props?: any): SectionBuilder<T, TPath>;
1097
+ /**
1098
+ * Add multiple fields to the section
1099
+ */
1100
+ fields(fieldDefinitions: Array<{
1101
+ name: string;
1102
+ label: string;
1103
+ type?: string;
1104
+ props?: any;
1105
+ }>): SectionBuilder<T, TPath>;
1106
+ /**
1107
+ * Nest deeper into the section
1108
+ */
1109
+ nest<SubPath extends string>(subPath: SubPath): NestedObjectBuilder<T, TPath>;
1110
+ /**
1111
+ * Return to the parent builder
1112
+ */
1113
+ end(): NestedPathBuilder<T>;
1114
+ }
1115
+ /**
1116
+ * Template literal field builder
1117
+ */
1118
+ declare class FieldTemplateBuilder<T extends FieldValues> {
1119
+ private parent;
1120
+ private path;
1121
+ constructor(parent: NestedPathBuilder<T>, path: string);
1122
+ /**
1123
+ * Complete the field definition
1124
+ */
1125
+ complete(label: string, type?: string, props?: any): NestedPathBuilder<T>;
1126
+ }
1127
+ /**
1128
+ * Factory function for creating the nested path builder
1129
+ */
1130
+ declare function createNestedPathBuilder<T extends FieldValues>(): NestedPathBuilder<T>;
1131
+
1132
+ interface UseDebouncedValidationOptions {
1133
+ delay?: number;
1134
+ fields?: string[];
1135
+ enabled?: boolean;
1136
+ }
1137
+ declare function useDebouncedValidation<T extends Record<string, any>>(form: UseFormReturn<T>, options?: UseDebouncedValidationOptions): {
1138
+ debouncedTrigger: () => void;
1139
+ isDebouncing: boolean;
1140
+ };
1141
+ declare function useDebouncedFieldValidation<T extends Record<string, any>>(form: UseFormReturn<T>, fieldName: keyof T, options?: {
1142
+ delay?: number;
1143
+ enabled?: boolean;
1144
+ }): {
1145
+ debouncedFieldTrigger: () => void;
1146
+ isDebouncing: boolean;
1147
+ };
1148
+
1149
+ interface UseInferredFormOptions<T extends FieldValues> {
1150
+ defaultValues?: Partial<T>;
1151
+ mode?: "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
1152
+ reValidateMode?: "onChange" | "onBlur" | "onSubmit";
1153
+ shouldFocusError?: boolean;
1154
+ shouldUnregister?: boolean;
1155
+ delayError?: number;
1156
+ }
1157
+ declare function useInferredForm<T extends FieldValues>(schema: any, fields: ZodFormFieldConfig<T>[], options?: UseInferredFormOptions<T>): UseFormReturn<T>;
1158
+ /**
1159
+ * Hook that works with type-inferred forms
1160
+ */
1161
+ declare function useTypeInferredForm<T extends FieldValues>(formConfig: {
1162
+ schema: any;
1163
+ fields: ZodFormFieldConfig<T>[];
1164
+ }, options?: UseInferredFormOptions<T>): UseFormReturn<T>;
1165
+
1166
+ interface ConditionalFieldProps<TFieldValues extends FieldValues> {
1167
+ config: ConditionalFieldConfig<TFieldValues>;
1168
+ control: Control<TFieldValues>;
1169
+ className?: string;
1170
+ }
1171
+ declare function ConditionalField<TFieldValues extends FieldValues>({ config, control, className, }: ConditionalFieldProps<TFieldValues>): React$1.JSX.Element | null;
1172
+
1173
+ interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
1174
+ config: FieldArrayConfig<TFieldValues>;
1175
+ className?: string;
1176
+ }
1177
+ declare function FieldArrayField<TFieldValues extends FieldValues>({ config, className, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
1178
+
1179
+ interface DynamicSectionFieldProps<TFieldValues extends FieldValues> {
1180
+ config: DynamicSectionConfig<TFieldValues>;
1181
+ control: Control<TFieldValues>;
1182
+ className?: string;
1183
+ }
1184
+ declare function DynamicSectionField<TFieldValues extends FieldValues>({ config, control, className, }: DynamicSectionFieldProps<TFieldValues>): React$1.JSX.Element | null;
1185
+
1186
+ interface FormStatusProps<T extends Record<string, any>> {
1187
+ state: EnhancedFormState<T>;
1188
+ onDismiss?: () => void;
1189
+ className?: string;
1190
+ showDetails?: boolean;
1191
+ }
1192
+ declare function FormStatus<T extends Record<string, any>>({ state, onDismiss, className, showDetails, }: FormStatusProps<T>): React$1.JSX.Element | null;
1193
+ interface FormToastProps<T extends Record<string, any>> {
1194
+ state: EnhancedFormState<T>;
1195
+ onDismiss?: () => void;
1196
+ position?: "top-right" | "top-left" | "bottom-right" | "bottom-left";
1197
+ duration?: number;
1198
+ }
1199
+ declare function FormToast<T extends Record<string, any>>({ state, onDismiss, position, duration, }: FormToastProps<T>): React$1.JSX.Element | null;
1200
+
1201
+ /**
1202
+ * Debounce function for field changes
1203
+ */
1204
+ declare function debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void;
1205
+ /**
1206
+ * Throttle function for high-frequency events
1207
+ */
1208
+ declare function throttle<T extends (...args: any[]) => any>(func: T, limit: number): (...args: Parameters<T>) => void;
1209
+ /**
1210
+ * Memoization helper for expensive computations
1211
+ */
1212
+ declare function useMemoizedCallback<T extends (...args: any[]) => any>(callback: T, deps: React.DependencyList): T;
1213
+ /**
1214
+ * Shallow comparison for React.memo
1215
+ */
1216
+ declare function shallowEqual<T extends Record<string, any>>(prevProps: T, nextProps: T): boolean;
1217
+ /**
1218
+ * Deep comparison for complex objects
1219
+ */
1220
+ declare function deepEqual<T extends Record<string, any>>(prevProps: T, nextProps: T): boolean;
1221
+ /**
1222
+ * Performance monitoring utilities (dev mode only)
1223
+ */
1224
+ declare function usePerformanceMonitor(componentName: string, enabled?: boolean): {
1225
+ renderCount: number;
1226
+ resetRenderCount: () => void;
1227
+ };
1228
+ /**
1229
+ * Optimized field change handler
1230
+ */
1231
+ declare function createOptimizedFieldHandler<T>(onChange: (value: T) => void, options?: {
1232
+ debounce?: number;
1233
+ throttle?: number;
1234
+ validate?: boolean;
1235
+ }): (value: T) => void;
1236
+ /**
1237
+ * Memoized field props to prevent unnecessary re-renders
1238
+ */
1239
+ declare function useMemoizedFieldProps<T extends Record<string, any>>(props: T, deps: React.DependencyList): T;
1240
+ /**
1241
+ * Batch field updates to reduce re-renders
1242
+ */
1243
+ declare function useBatchedFieldUpdates<T extends Record<string, any>>(form: any, fields: (keyof T)[]): {
1244
+ batchUpdate: (fieldName: keyof T, value: any) => void;
1245
+ };
1246
+
1247
+ /**
1248
+ * Common validation patterns for forms
1249
+ */
1250
+ declare const validationPatterns: {
1251
+ email: z.ZodString;
1252
+ phoneUS: z.ZodString;
1253
+ phoneInternational: z.ZodString;
1254
+ url: z.ZodString;
1255
+ password: z.ZodString;
1256
+ strongPassword: z.ZodString;
1257
+ creditCard: z.ZodString;
1258
+ ssn: z.ZodString;
1259
+ zipCode: z.ZodString;
1260
+ date: z.ZodString;
1261
+ time: z.ZodString;
1262
+ };
1263
+ /**
1264
+ * Async validation helpers
1265
+ */
1266
+ declare const asyncValidation: {
1267
+ /**
1268
+ * Email availability check
1269
+ */
1270
+ emailAvailability: (email: string) => Promise<boolean>;
1271
+ /**
1272
+ * Username availability check
1273
+ */
1274
+ usernameAvailability: (username: string) => Promise<boolean>;
1275
+ };
1276
+ /**
1277
+ * Custom error messages
1278
+ */
1279
+ declare const errorMessages: {
1280
+ required: (fieldName: string) => string;
1281
+ minLength: (fieldName: string, min: number) => string;
1282
+ maxLength: (fieldName: string, max: number) => string;
1283
+ min: (fieldName: string, min: number) => string;
1284
+ max: (fieldName: string, max: number) => string;
1285
+ pattern: (fieldName: string) => string;
1286
+ email: () => string;
1287
+ url: () => string;
1288
+ phone: () => string;
1289
+ date: () => string;
1290
+ time: () => string;
1291
+ };
1292
+ /**
1293
+ * Server-side validation integration
1294
+ */
1295
+ declare const serverValidation: {
1296
+ /**
1297
+ * Apply server errors to form
1298
+ */
1299
+ applyServerErrors: (errors: Record<string, string[]>, setError: any) => void;
1300
+ /**
1301
+ * Clear server errors
1302
+ */
1303
+ clearServerErrors: (fields: string[], clearErrors: any) => void;
1304
+ };
1305
+ /**
1306
+ * Form validation utilities
1307
+ */
1308
+ declare const validationUtils: {
1309
+ /**
1310
+ * Debounced validation
1311
+ */
1312
+ debounceValidation: (fn: Function, delay?: number) => (...args: any[]) => void;
1313
+ /**
1314
+ * Validate form data against schema
1315
+ */
1316
+ validateForm: (data: any, schema: z.ZodSchema) => Promise<{
1317
+ success: boolean;
1318
+ errors: Record<string, string>;
1319
+ }>;
1320
+ /**
1321
+ * Get field error message
1322
+ */
1323
+ getFieldError: (errors: Record<string, string>, field: string) => string | undefined;
1324
+ /**
1325
+ * Check if field has error
1326
+ */
1327
+ hasFieldError: (errors: Record<string, string>, field: string) => boolean;
1328
+ };
1329
+
1330
+ export { AdvancedFieldBuilder, type BaseFormFieldConfig, BasicFormBuilder, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, CommonFields, ConditionalField, type ConditionalFieldConfig, type ConditionalFieldProps, type ConditionalValidation, ConfigurableForm, 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, type ServerFieldError, type ServerFormError, 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, createConditionalSchema, createConfirmPasswordSchema, createDateSchema, createEmailSchema, createField, createFieldArrayBuilder, 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, throttle, useBatchedFieldUpdates, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };