/** * Main types module for Reform * Exports all types used throughout the library */ import { Control, FieldPath, UseFormRegister, UseFormReturn, UseFormSetValue, } from 'react-hook-form'; import { FormErrorsState } from './core/errors/state/types'; import { FormStateManager } from './core/form/form-state'; // import { FormValidation } from './core/validation/base/types'; import { FieldArrayHelpers } from './features/field-array/types'; import { ConditionalFieldsManager } from './features/conditional/types'; import { FieldConfig, ReformYupIntegration, ValidationConfig, YupSchemaConfig, } from './core/validation'; // import { ReformGroupHandler, FormGroup } from "./core/groups/types"; import { FormGroup } from './core/form/form-groups'; import { Maybe, AnyObject } from 'yup'; import { ReformGroupHandler } from './typessss'; /** * Main return type for the useReform hook * Combines all functionality from various modules * * @template T - The type of form data */ export interface ReformReturn> extends FormErrorsState, FormStateManager, // FormHandlers, // FormValidation, ReformGroupHandler, FieldArrayHelpers, ConditionalFieldsManager { /** React Hook Form methods */ formMethods: UseFormReturn<{ groups: FormGroup[] }>; /** Form configuration */ config: DynamicFormConfig; /** Yup integration utilities */ yup: ReformYupIntegration; /** Get all form groups */ getGroups: () => FormGroup[]; /** Get data for a specific group */ getGroupData: (index: number) => T | undefined; } // Utility Types export type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; export type InferFormData = T & Record; // Form Path Types export type FormDataPath = FieldPath<{ groups: FormGroup[] }>; // Form Control Types export type FormControl = Control<{ groups: FormGroup[]; }>; // Form State Types export interface FormState { isDirty: boolean; touched: boolean; submitCount: number; isSubmitting: boolean; } export interface YupIntegrationConfig> { /** * Configuration for Yup integration */ yupConfig?: Partial>; } export type DynamicFormConfig = { value?: FormGroup[]; minGroups?: number; maxGroups?: number; defaultData?: Partial; fields?: { [K in keyof T]: FieldConfig; }; onChange?: (groups: FormGroup[]) => void; } & ValidationConfig & YupIntegrationConfig; export interface DynamicFormProps extends DynamicFormConfig { disabled?: boolean; className?: string; } // Field Types export type FieldKey = keyof T; export type FieldValue> = T[K]; export type FieldData = T; export type FieldErrorMessage = string; export type FieldErrors = Record, FieldErrorMessage>; // Field State export interface FieldState { isDirty: boolean; touched: boolean; initialValue: any; } // Field Render Props export interface FieldRenderProps { name: string; value: T[K]; error?: string; group: FormGroup; index: number; onChange: (value: T[K]) => void; register: UseFormRegister<{ groups: FormGroup[] }>; setValue: UseFormSetValue<{ groups: FormGroup[] }>; fieldPath: string; }