import type { JSX } from '../jsx-runtime.js'; export type MessageInput = string | (() => string); /** Field / rules validator — return message or undefined. */ export type Validator = ( value: any, values?: any, meta?: { path: string } ) => string | undefined | Promise; export type FormErrors = { [K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormErrors[] | string | string[] : string | string[] : Values[K] extends object ? FormErrors : string; }; export type FormTouched = { [K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormTouched[] | boolean : boolean : Values[K] extends object ? FormTouched : boolean; }; export interface FormHelpers { setStatus: (status?: any) => void; setErrors: (errors: FormErrors) => void; setSubmitting: (isSubmitting: boolean) => void; setTouched: ( touched: FormTouched, shouldValidate?: boolean ) => Promise>; setValues: ( values: Values | ((prev: Values) => Values), shouldValidate?: boolean ) => Promise>; setFieldValue: ( field: string, value: any, shouldValidate?: boolean ) => Promise>; setFieldError: (field: string, message: string | undefined) => void; setFieldTouched: ( field: string, isTouched?: boolean, shouldValidate?: boolean ) => Promise>; resetForm: (nextState?: Partial>) => void; validateForm: (values?: Values) => Promise>; validateField: (field: string) => Promise; submitForm: () => Promise; } export interface FormState { values: Values; errors: FormErrors; touched: FormTouched; isSubmitting: boolean; isValidating: boolean; status?: any; submitCount: number; } export interface FormConfig { initialValues: Values; initialErrors?: FormErrors; initialTouched?: FormTouched; initialStatus?: any; onSubmit?: ( values: Values, helpers: FormHelpers ) => void | Promise; onReset?: (values: Values, helpers: FormHelpers) => void; validate?: ( values: Values ) => FormErrors | Promise>; validationSchema?: any | (() => any); /** Per-path built-in / custom validators: `{ email: [required(), isEmail()] }` */ rules?: Record; validateOnChange?: boolean; validateOnBlur?: boolean; validateOnMount?: boolean; enableReinitialize?: boolean; } export interface FormBag extends FormHelpers { values: () => Values; errors: () => FormErrors; touched: () => FormTouched; status: () => any; isSubmitting: () => boolean; isValidating: () => boolean; submitCount: () => number; dirty: () => boolean; isValid: () => boolean; initialValues: () => Values; handleChange: (e: any) => void; handleBlur: (e: any) => void; handleSubmit: (e?: any) => Promise; handleReset: (e?: any) => void; registerField: (name: string, meta?: { validate?: Function }) => void; unregisterField: (name: string) => void; updateConfig: (next: Partial>) => void; getFieldHelpers: (name: string) => FieldHelperProps; getFieldMeta: (name: string) => FieldMetaProps; getFieldProps: (nameOrProps: string | Record) => FieldInputProps; } export interface FieldInputProps { name: string; value?: any; checked?: boolean; onInput: (e: any) => void; onChange: (e: any) => void; onBlur: (e: any) => void; type?: string; } export interface FieldMetaProps { value: any; error?: any; touched: boolean; initialValue?: any; initialTouched?: boolean; initialError?: any; } export interface FieldHelperProps { setValue: (value: any, shouldValidate?: boolean) => Promise; setTouched: (isTouched?: boolean, shouldValidate?: boolean) => Promise; setError: (message: string | undefined) => void; } export interface FieldArrayHelpers { name: string; form: FormBag; push: (value: any) => void; unshift: (value: any) => void; pop: () => any; remove: (index: number) => any; insert: (index: number, value: any) => void; swap: (indexA: number, indexB: number) => void; move: (from: number, to: number) => void; replace: (index: number, value: any) => void; } export interface FormProviderProps extends FormConfig { children?: JSX.Element | ((form: FormBag) => JSX.Element); } export interface FieldProps { name: string; type?: string; validate?: Validator | Validator[]; as?: any; component?: any; value?: any; children?: any; [key: string]: any; } export interface ErrorMessageProps { name: string; component?: any; as?: any; children?: ((message: string) => any) | any; } export interface FieldArrayProps { name: string; children?: ((helpers: FieldArrayHelpers) => any) | any; } export declare function createForm( config: FormConfig ): FormBag; export declare function FormProvider( props: FormProviderProps ): any; export declare function Form(props: Record): any; export declare function Field(props: FieldProps): any; export declare function ErrorMessage(props: ErrorMessageProps): any; export declare function FieldArray(props: FieldArrayProps): any; export declare function useFormContext(): FormBag; export declare function useField( nameOrProps: string | FieldProps ): [FieldInputProps, FieldMetaProps, FieldHelperProps]; export declare const FormContext: any; export declare function getIn(obj: any, path: string | Array, fallback?: any): any; export declare function setIn(obj: any, path: string | Array, value: any): any; export declare function rules( map: Record ): (values: any) => Promise>; export declare function runRules( map: Record | undefined, values: any ): Promise>; export declare function compose(...validators: Validator[]): Validator; export declare const all: typeof compose; export declare function normalizeValidators( validate: Validator | Validator[] | undefined ): Validator | undefined; export declare function isEmptyValue(value: any): boolean; export declare function required(message?: MessageInput): Validator; export declare const isNotEmpty: typeof required; export declare function isEmpty(message?: MessageInput): Validator; export declare function isEmail(message?: MessageInput): Validator; export declare const email: typeof isEmail; export declare function isNumber(message?: MessageInput): Validator; export declare const number: typeof isNumber; export declare function isInteger(message?: MessageInput): Validator; export declare const integer: typeof isInteger; export declare function minLength(min: number, message?: MessageInput): Validator; export declare function maxLength(max: number, message?: MessageInput): Validator; export declare function min(minVal: number, message?: MessageInput): Validator; export declare function max(maxVal: number, message?: MessageInput): Validator; export declare function matches(regex: RegExp | string, message?: MessageInput): Validator; export declare const pattern: typeof matches; export declare function isUrl(message?: MessageInput): Validator; export declare const url: typeof isUrl; export declare function oneOf(list: any[], message?: MessageInput): Validator; export declare function notOneOf(list: any[], message?: MessageInput): Validator; export declare function equalsField(otherPath: string, message?: MessageInput): Validator; export declare function test( predicate: ( value: any, values?: any, meta?: { path: string } ) => boolean | Promise, message?: MessageInput ): Validator;