import React from 'react'; import { VALIDATION_MODE } from '../constants'; import { Subject, Subscription } from '../utils/createSubject'; import { ErrorOption, FieldError, FieldErrors } from './errors'; import { EventType } from './events'; import { FieldArray } from './fieldArray'; import { Field, FieldName, FieldRefs, FieldValue, FieldValues, InternalFieldName } from './fields'; import { FieldArrayPath, FieldPath, FieldPathValue, FieldPathValues } from './path'; import { Resolver } from './resolvers'; import { DeepMap, DeepPartial, Noop } from './utils'; import { RegisterOptions } from './validator'; declare const $NestedValue: unique symbol; /** * @deprecated to be removed in the next major version */ export type NestedValue = { [$NestedValue]: never; } & TValue; /** * @deprecated to be removed in the next major version */ export type UnpackNestedValue = T extends NestedValue ? U : T extends Date | FileList | File | Blob ? T : T extends object ? { [K in keyof T]: UnpackNestedValue; } : T; export type DefaultValues = TFieldValues extends AsyncDefaultValues ? DeepPartial> : DeepPartial; export type InternalNameSet = Set; export type ValidationMode = typeof VALIDATION_MODE; export type Mode = keyof ValidationMode; export type ValidationModeFlags = { isOnSubmit: boolean; isOnBlur: boolean; isOnChange: boolean; isOnAll: boolean; isOnTouch: boolean; }; export type CriteriaMode = 'firstError' | 'all'; export type SubmitHandler = (data: TFieldValues, event?: React.BaseSyntheticEvent) => unknown | Promise; export type FormSubmitHandler = (payload: { data: TFieldValues; event?: React.BaseSyntheticEvent; formData: FormData; formDataJson: string; method?: 'post' | 'put' | 'delete'; }) => unknown | Promise; export type SubmitErrorHandler = (errors: FieldErrors, event?: React.BaseSyntheticEvent) => unknown | Promise; export type SetValueConfig = Partial<{ shouldValidate: boolean; shouldDirty: boolean; shouldTouch: boolean; }>; export type TriggerConfig = Partial<{ shouldFocus: boolean; }>; export type ChangeHandler = (event: { target: any; type?: any; }) => Promise; export type DelayCallback = (wait: number) => void; type AsyncDefaultValues = (payload?: unknown) => Promise; export type UseFormProps = Partial<{ mode: Mode; disabled: boolean; reValidateMode: Exclude; defaultValues: DefaultValues | AsyncDefaultValues; values: TFieldValues; errors: FieldErrors; resetOptions: Parameters>[1]; resolver: Resolver; context: TContext; shouldFocusError: boolean; shouldUnregister: boolean; shouldUseNativeValidation: boolean; progressive: boolean; criteriaMode: CriteriaMode; delayError: number; }>; export type FieldNamesMarkedBoolean = DeepMap, boolean>; export type FormStateProxy = { isDirty: boolean; isValidating: boolean; dirtyFields: FieldNamesMarkedBoolean; touchedFields: FieldNamesMarkedBoolean; validatingFields: FieldNamesMarkedBoolean; errors: boolean; isValid: boolean; }; export type ReadFormState = { [K in keyof FormStateProxy]: boolean | 'all'; }; export type FormState = { isDirty: boolean; isLoading: boolean; isSubmitted: boolean; isSubmitSuccessful: boolean; isSubmitting: boolean; isValidating: boolean; isValid: boolean; disabled: boolean; submitCount: number; defaultValues?: undefined | Readonly>; dirtyFields: Partial>>; touchedFields: Partial>>; validatingFields: Partial>>; errors: FieldErrors; }; export type KeepStateOptions = Partial<{ keepDirtyValues: boolean; keepErrors: boolean; keepDirty: boolean; keepValues: boolean; keepDefaultValues: boolean; keepIsSubmitted: boolean; keepIsSubmitSuccessful: boolean; keepTouched: boolean; keepIsValidating: boolean; keepIsValid: boolean; keepSubmitCount: boolean; }>; export type SetFieldValue = FieldValue; export type RefCallBack = (instance: any) => void; export type UseFormRegisterReturn = { onChange: ChangeHandler; onBlur: ChangeHandler; ref: RefCallBack; name: TFieldName; min?: string | number; max?: string | number; maxLength?: number; minLength?: number; pattern?: string; required?: boolean; disabled?: boolean; }; /** * Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`. * * @remarks * [API](https://react-hook-form.com/docs/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA) * * @param name - the path name to the form field value, name is required and unique * @param options - register options include validation, disabled, unregister, value as and dependent validation * * @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled. * * @example * ```tsx * // Register HTML native input * *