import * as React$1 from 'react'; import React__default, { ReactNode } from 'react'; declare const EVENTS: { readonly BLUR: "blur"; readonly FOCUS_OUT: "focusout"; readonly CHANGE: "change"; readonly SUBMIT: "submit"; readonly TRIGGER: "trigger"; readonly VALID: "valid"; }; declare const VALIDATION_MODE: { readonly onBlur: "onBlur"; readonly onChange: "onChange"; readonly onSubmit: "onSubmit"; readonly onTouched: "onTouched"; readonly all: "all"; }; declare const INPUT_VALIDATION_RULES: { readonly max: "max"; readonly min: "min"; readonly maxLength: "maxLength"; readonly minLength: "minLength"; readonly pattern: "pattern"; readonly required: "required"; readonly validate: "validate"; }; type Observer = { next: (value: T) => void; }; type Subscription = { unsubscribe: Noop; }; type Subject = { readonly observers: Observer[]; subscribe: (value: Observer) => Subscription; unsubscribe: Noop; } & Observer; type EventType = 'focus' | 'blur' | 'change' | 'changeText' | 'valueChange' | 'contentSizeChange' | 'endEditing' | 'keyPress' | 'submitEditing' | 'layout' | 'selectionChange' | 'longPress' | 'press' | 'pressIn' | 'pressOut' | 'momentumScrollBegin' | 'momentumScrollEnd' | 'scroll' | 'scrollBeginDrag' | 'scrollEndDrag' | 'load' | 'error' | 'progress' | 'custom'; /** * Decrement table for path depth limiting. * Prev[N] = N − 1 for N ≥ 1; Prev[0] = never (signals recursion stop). * Path traversal types default to D = 9, yielding a max of 10 path segments. */ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, ...0[]]; /** * Type alias to `string` which describes a lodash-like path through an object. * E.g. `'foo.bar.0.baz'` */ type PathString = string; /** * Type to query whether an array type T is a tuple type. * @typeParam T - type which may be an array or tuple * @example * ``` * IsTuple<[number]> = true * IsTuple = false * ``` */ type IsTuple> = number extends T['length'] ? false : true; /** * Type which can be used to index an array or tuple type. */ type ArrayKey = number; /** * Type which given a tuple type returns its own keys, i.e. only its indices. * @typeParam T - tuple type * @example * ``` * TupleKeys<[number, string]> = '0' | '1' * ``` */ type TupleKeys> = Exclude; /** * Helper function to break apart T1 and check if any are equal to T2 * * See {@link IsEqual} */ type AnyIsEqual = T1 extends T2 ? IsEqual extends true ? true : never : never; /** * Helper type for recursively constructing paths through a type. * This actually constructs the strings and recurses into nested * object types. * * See {@link Path} */ type PathImpl = V extends Primitive | BrowserNativeObject | OpaqueType ? `${K}` : true extends AnyIsEqual ? `${K}` : `${K}` | `${K}.${PathInternal}`; /** * Helper type for recursively constructing paths through a type. * This obscures the internal type param TraversedTypes from exported contract. * * See {@link Path} */ type PathInternal = [D] extends [ never ] ? never : T extends ReadonlyArray ? IsTuple extends true ? { [K in TupleKeys]-?: PathImpl; }[TupleKeys] : PathImpl : { [K in keyof T]-?: PathImpl; }[keyof T]; /** * Type which eagerly collects all paths through a type * @typeParam T - type which should be introspected * @example * ``` * Path<{foo: {bar: string}}> = 'foo' | 'foo.bar' * ``` */ type Path = T extends any ? PathInternal : never; /** * See {@link Path} */ type FieldPath = Path; /** * Helper type for recursively constructing paths through a type. * This actually constructs the strings and recurses into nested * object types. * * See {@link ArrayPath} */ type ArrayPathImpl = V extends Primitive | BrowserNativeObject | OpaqueType ? IsAny extends true ? string : never : V extends ReadonlyArray ? U extends Primitive | BrowserNativeObject | OpaqueType ? IsAny extends true ? string : never : true extends AnyIsEqual ? never : `${K}` | `${K}.${ArrayPathInternal}` : true extends AnyIsEqual ? never : `${K}.${ArrayPathInternal}`; /** * Helper type for recursively constructing paths through a type. * This obscures the internal type param TraversedTypes from exported contract. * * See {@link ArrayPath} */ type ArrayPathInternal = [ D ] extends [never] ? never : T extends ReadonlyArray ? IsTuple extends true ? { [K in TupleKeys]-?: ArrayPathImpl; }[TupleKeys] : ArrayPathImpl : { [K in keyof T]-?: ArrayPathImpl; }[keyof T]; /** * Type which eagerly collects all paths through a type which point to an array * type. * @typeParam T - type which should be introspected. * @example * ``` * Path<{foo: {bar: string[], baz: number[]}}> = 'foo.bar' | 'foo.baz' * ``` */ type ArrayPath = T extends any ? ArrayPathInternal : never; /** * See {@link ArrayPath} */ type FieldArrayPath = ArrayPath; /** * Type to evaluate the type which the given path points to. * @typeParam T - deeply nested type which is indexed by the path * @typeParam P - path into the deeply nested type * @example * ``` * PathValue<{foo: {bar: string}}, 'foo.bar'> = string * PathValue<[number, string], '1'> = string * ``` */ type PathValue | ArrayPath> = PathValueImpl; type PathValueImpl = T extends any ? P extends `${infer K}.${infer R}` ? K extends keyof T ? undefined extends T[K] ? PathValueImpl | undefined : PathValueImpl : K extends `${ArrayKey}` ? T extends ReadonlyArray ? PathValueImpl : never : never : P extends keyof T ? T[P] : P extends `${ArrayKey}` ? T extends ReadonlyArray ? V : T extends undefined ? undefined : never : never : never; /** * See {@link PathValue} */ type FieldPathValue> = PathValue; /** * See {@link PathValue} */ type FieldArrayPathValue> = PathValue; /** * Type to evaluate the type which the given paths point to. * @typeParam TFieldValues - field values which are indexed by the paths * @typeParam TPath - paths into the deeply nested field values * @example * ``` * FieldPathValues<{foo: {bar: string}}, ['foo', 'foo.bar']> * = [{bar: string}, string] * ``` */ type FieldPathValues[] | readonly FieldPath[]> = {} & { [K in keyof TPath]: FieldPathValue>; }; /** * Type which eagerly collects all paths through a fieldType that matches a give type * @typeParam TFieldValues - field values which are indexed by the paths * @typeParam TValue - the value you want to match into each type * @example * ```typescript * FieldPathByValue<{foo: {bar: number}, baz: number, bar: string}, number> * = 'foo.bar' | 'baz' * ``` */ type FieldPathByValue = { [Key in FieldPath]: FieldPathValue extends TValue ? Key : never; }[FieldPath]; /** * Type which eagerly collects all array paths through a fieldType that matches a give type * @typeParam TFieldValues - field values which are indexed by the paths * @typeParam TValue - the value you want to match into each type * @example * ```typescript * FieldArrayPathByValue<{foo: {bar: number}[], baz: number, bar: string}, {bar: number}[]> * = 'foo' * ``` */ type FieldArrayPathByValue = { [Key in FieldArrayPath]: FieldArrayPathValue extends TValue ? Key : never; }[FieldArrayPath]; type UseFieldArrayProps = FieldArrayPath, TKeyName extends string = 'id', TTransformedValues = TFieldValues> = { name: TFieldArrayName; keyName?: TKeyName; control?: Control; rules?: { validate?: Validate[], TFieldValues> | Record[], TFieldValues>>; } & Pick, 'maxLength' | 'minLength' | 'required'>; shouldUnregister?: boolean; disabled?: boolean; }; /** * `useFieldArray` returned `fields` with unique id */ type FieldArrayWithId = FieldArrayPath, TKeyName extends string = 'id'> = FieldArray$1 & Record; type FieldArray$1 = FieldArrayPath> = FieldArrayPathValue extends ReadonlyArray | null | undefined ? U : never; /** * `useFieldArray` focus option, ability to toggle focus on and off with `shouldFocus` and setting focus by either field index or name. */ type FieldArrayMethodProps = { shouldFocus?: boolean; focusIndex?: number; focusName?: string; }; /** * Swap field array by supplying from and to index * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param indexA - from index * @param indexB - to index * * @example * ```tsx * * ``` */ type UseFieldArraySwap = (indexA: number, indexB: number) => void; /** * Move field array by supplying from and to index * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param indexA - from index * @param indexB - to index * * @example * ```tsx * * ``` */ type UseFieldArrayMove = (indexA: number, indexB: number) => void; /** * Prepend field/fields to the start of the fields and optionally focus. The input value will be registered during this action. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param value - prepend items or items * @param options - focus options * * @example * ```tsx * * * * ``` */ type UseFieldArrayPrepend = FieldArrayPath> = (value: FieldArray$1 | FieldArray$1[], options?: FieldArrayMethodProps) => void; /** * Append field/fields to the end of your fields and focus. The input value will be registered during this action. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param value - append items or items. * @param options - focus options * * @example * ```tsx * * * * ``` */ type UseFieldArrayAppend = FieldArrayPath> = (value: FieldArray$1 | FieldArray$1[], options?: FieldArrayMethodProps) => void; /** * Remove field/fields at particular position. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param index - index to remove at, or remove all when no index provided. * * @example * ```tsx * * * ``` */ type UseFieldArrayRemove = (index?: number | number[]) => void; /** * Insert field/fields at particular position and focus. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param index - insert position * @param value - insert field or fields * @param options - focus options * * @example * ```tsx * * * * ``` */ type UseFieldArrayInsert = FieldArrayPath> = (index: number, value: FieldArray$1 | FieldArray$1[], options?: FieldArrayMethodProps) => void; /** * Update field/fields at particular position. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param index - insert position * @param value - insert field or fields * * @example * ```tsx * * * ``` */ type UseFieldArrayUpdate = FieldArrayPath> = (index: number, value: FieldArray$1) => void; /** * Replace the entire field array values. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param value - the entire field values. * * @example * ```tsx * * ``` */ type UseFieldArrayReplace = FieldArrayPath> = (value: FieldArray$1 | FieldArray$1[]) => void; type UseFieldArrayReturn = FieldArrayPath, TKeyName extends string = 'id'> = { swap: UseFieldArraySwap; move: UseFieldArrayMove; prepend: UseFieldArrayPrepend; append: UseFieldArrayAppend; remove: UseFieldArrayRemove; insert: UseFieldArrayInsert; update: UseFieldArrayUpdate; replace: UseFieldArrayReplace; fields: (FieldArrayWithId & { disabled?: boolean; })[]; }; /** * * @example * ```tsx * const { fields } = useFieldArray({ * name: 'test', * }); * * * fields.map((field, index) => ( * * )) * } * /> * ``` */ type FieldArrayProps = FieldArrayPath, TKeyName extends string = 'id'> = { render: (fieldArray: UseFieldArrayReturn) => React.ReactElement; } & UseFieldArrayProps; type ResolverSuccess = { values: TTransformedValues; errors: Record; }; type ResolverError = { values: Record; errors: FieldErrors; }; type ResolverResult = ResolverSuccess | ResolverError; interface ResolverOptions { criteriaMode?: CriteriaMode; fields: Record; names?: FieldName[]; shouldUseNativeValidation: boolean | undefined; } type Resolver = (values: TFieldValues, context: TContext | undefined, options: ResolverOptions) => Promise> | ResolverResult; declare const $NestedValue: unique symbol; /** * @deprecated to be removed in the next major version */ type NestedValue = { [$NestedValue]: never; } & TValue; type DefaultValues = TFieldValues extends AsyncDefaultValues ? DeepPartial> : DeepPartial; type InternalNameSet = Set; type ValidationMode = typeof VALIDATION_MODE; type Mode = keyof ValidationMode; type ValidationModeFlags = { isOnSubmit: boolean; isOnBlur: boolean; isOnChange: boolean; isOnAll: boolean; isOnTouch: boolean; }; type CriteriaMode = 'firstError' | 'all'; type SubmitHandler = (data: T, event?: React__default.BaseSyntheticEvent) => TResult; type FormSubmitHandler = (payload: { data: TTransformedValues; event?: React__default.BaseSyntheticEvent; formData: FormData; formDataJson: string; method?: 'post' | 'put' | 'delete'; }) => unknown | Promise; type SubmitErrorHandler = (errors: FieldErrors, event?: React__default.BaseSyntheticEvent) => unknown | Promise; type SetValueConfig = Partial<{ shouldValidate: boolean; shouldDirty: boolean; shouldTouch: boolean; delayError: boolean; }>; type TriggerConfig = Partial<{ shouldFocus: boolean; shouldTouch: boolean; }>; type ResetFieldConfig = FieldPath> = Partial<{ keepDirty: boolean; keepTouched: boolean; keepError: boolean; defaultValue: FieldPathValue; }>; type ChangeHandler = (event: { target: any; type?: any; }) => Promise; type DelayCallback = (wait: number) => void; type AsyncDefaultValues = (payload?: unknown) => Promise; 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; formControl?: Omit, 'formState'>; validate: ValidateForm; }>; type FieldNamesMarkedBoolean = DeepMap, boolean>; type FormStateProxy = { isDirty: boolean; isValidating: boolean; dirtyFields: FieldNamesMarkedBoolean; touchedFields: FieldNamesMarkedBoolean; validatingFields: FieldNamesMarkedBoolean; errors: boolean; isValid: boolean; }; type ReadFormState = { [K in keyof FormStateProxy]: boolean | 'all'; } & { values?: boolean; defaultValues?: boolean | 'all'; isSubmitted?: boolean | 'all'; submitCount?: boolean | 'all'; }; type FormState$1 = { 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; isReady: boolean; }; 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; keepFieldsRef: boolean; }>; type SetFieldValue = FieldValue; type RefCallBack = (instance: any) => void; 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; }; /** * Registers a field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including in `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 including validation, disabled, unregister, value as, and dependent validation. * * @returns onChange, onBlur, name, ref, and native HTML validation attributes if browser validation is enabled. * * @example * ```tsx * // Register HTML native input * *