import { type InjectionKey, type Ref } from 'vue'; import { type Validator, type Rule } from './Validator'; import { type DefaultProps } from '../config'; export interface FormRules { [key: PropertyKey]: Rule | Rule[] | FormRules; } export type FieldName = string | number | (string | number)[]; export type ValidateState = '' | 'success' | 'error' | 'validating'; export type TriggerType = 'change' | 'blur' | ('change' | 'blur')[]; export interface FieldValidateError { name: FieldName; value: any; message: string; } export interface FormProps { model?: Record; rules?: FormRules; validateTrigger?: TriggerType; validateOnRuleChange?: boolean; direction?: 'horizontal' | 'vertical'; labelWidth?: string; labelAlign?: 'start' | 'center' | 'end'; labelValign?: 'start' | 'center' | 'end'; starPosition?: 'start' | 'end'; contentPosition?: 'start' | 'end'; hideStar?: boolean; showError?: boolean; scrollToFirstError?: boolean; scrollIntoViewOptions?: ScrollIntoViewOptions; disabled?: boolean; readonly?: boolean; card?: boolean; } export declare const defaultFormProps: DefaultProps; export interface FormSlots { default?(props: Record): any; } export interface FormExpose { validate: (nameList?: FieldName[]) => Promise; reset: (nameList?: FieldName[]) => Promise; clearValidate: (nameList?: FieldName[]) => void; scrollToField: (name: FieldName) => void; } export interface FormItemProps { direction?: 'horizontal' | 'vertical'; labelWidth?: string; labelAlign?: 'start' | 'center' | 'end'; labelValign?: 'start' | 'center' | 'end'; starPosition?: 'start' | 'end'; label?: string; hideStar?: boolean; contentPosition?: 'start' | 'end'; required?: boolean | undefined; name?: FieldName; rules?: Rule | Rule[]; validateTrigger?: TriggerType; error?: string; showError?: boolean; inlaid?: boolean; } export declare const defaultFormItemProps: DefaultProps; export interface FormItemSlots { default?(props: Record): any; label?(props: Record): any; validate?(props: { state: ValidateState; }): any; error?(props: { message: string; showError: boolean; }): any; } export interface FormItemExpose { validate: (trigger?: string | string[]) => Promise; reset: () => Promise; clearValidate: () => void; scrollToField: () => void; validateMessage: Ref; validateState: Ref; } export interface FormContext { model: FormProps['model']; rules: FormProps['rules']; validateTrigger: FormProps['validateTrigger']; direction: FormProps['direction']; labelWidth: FormProps['labelWidth']; labelAlign: FormProps['labelAlign']; labelValign: FormProps['labelValign']; starPosition: FormProps['starPosition']; contentPosition: FormProps['contentPosition']; hideStar: FormProps['hideStar']; showError: FormProps['showError']; scrollIntoViewOptions: FormProps['scrollIntoViewOptions']; disabled: FormProps['disabled']; readonly: FormProps['readonly']; addField: (context: FormItemContext) => void; removeField: (context: FormItemContext) => void; validator: Validator; } export interface FormItemContext { name: FormItemProps['name']; validateMessage: string; validateState: ValidateState; validate: (trigger?: string | string[]) => Promise; reset: () => Promise; clearValidate: () => void; scrollToField: () => void; onBlur: () => void; onChange: () => void; } export declare const formContextKey: InjectionKey; export declare const formItemContextKey: InjectionKey; export declare function useFormContext(): FormContext | null; export declare function useFormItemContext(): FormItemContext | null;