import type { ComputedRef, Ref, ToRefs } from 'vue'; import type { ColProps } from '../col/type'; import type { RowProps } from '../row/type'; import type { LooseRequired, RestAttrs } from '../share/type'; export type RuleLevel = 'error' | 'warning' | 'success' | 'normal'; export type FieldItem = { field: string; reset: Function; clearValidation: Function; validate: () => Promise<{ message: string; level: RuleLevel; }>; }; export type FieldType = 'number' | 'string' | 'boolean' | 'array' | 'dict' | 'function' | 'date'; export type RuleTrigger = 'blur' | 'change' | 'input'; export type FormProps = { /** * @property {Record} [model] * @version 0.0.3 */ model?: Record; /** * @property {FormInstance} [form] * @version 0.0.3 */ form?: UseFormReturn; /** * @property {Record} [rules] * @version 0.0.3 */ rules?: Record; /** * @property {boolean} [enterSubmit=false] * @version 0.2.0 */ enterSubmit?: boolean; /** * @property {boolean} [disabled=false] * @version 0.0.3 */ disabled?: boolean; /** * @property {boolean} [readonly=false] * @version 0.0.3 */ readonly?: boolean; /** * @property {'small' | 'medium' | 'large'} [size='medium'] * @version 0.0.3 */ size?: 'small' | 'medium' | 'large'; /** * @property {'left' | 'right' | 'top'} [labelAlign='right'] * @version 0.0.3 */ labelAlign?: 'left' | 'right' | 'top'; /** * @property {boolean} [showAsterisk] * @version 0.0.3 */ showAsterisk?: boolean; /** * @property {'left' | 'right' | 'end'} [asteriskPlacement='left'] * @version 0.0.3 */ asteriskPlacement?: 'left' | 'right' | 'end'; /** * @property {boolean} [labelAutoWidth=false] * @version 0.0.3 */ labelAutoWidth?: boolean; /** * @property {RowProps & RestAttrs} [rowProps] * @version 0.0.3 */ rowProps?: RowProps & RestAttrs; /** * @property {ColProps & RestAttrs} [labelProps] * @version 0.0.3 */ labelProps?: ColProps & RestAttrs; /** * @property {ColProps & RestAttrs} [contentProps] * @version 0.0.3 */ contentProps?: ColProps & RestAttrs; /** * @property {boolean} [pollSizeChange=false] * @version 0.1.0 */ pollSizeChange?: boolean; }; export interface UseFormReturn = Record> { /** * @property {Ref>} model * @version 0.0.3 */ model: Ref; /** * @property {(field?: string | string[]) => FormValidateResult} validate * @version 0.0.3 */ validate: (field?: string | string[]) => FormValidateResult; /** * @property {(field?: string | string[]) => void} reset * @version 0.0.3 */ reset: (field?: string | string[]) => void; /** * @property {(field?: string | string[]) => void} clearValidation * @version 0.0.3 */ clearValidation: (field?: string | string[]) => void; /** * @ignore */ register: (registerOptions: UseFormRegisterOptions) => void; } export type FormEvents = { /** * @event submit * @param {Record} form * @param {SubmitEvent} event * @version 0.0.3 */ submit: [form: Record, event: SubmitEvent]; /** * @event reset * @param {Record} form * @param {Event} event * @version 0.0.3 */ reset: [form: Record, event: Event]; }; export type FormSlots = { /** * @slot default * @version 0.0.3 */ default: {}; }; export type FormValidateResult = Promise<{ isValid: boolean; results: Record>; }>; export type FormExpose = { /** * @property {(field?: string | string[]) => FormValidateResult} validate * @version 0.0.3 */ validate: (field?: string | string[]) => FormValidateResult; /** * @property {(field?: string | string[]) => void} reset * @version 0.0.3 */ reset: (field?: string | string[]) => void; /** * @property {(field?: string | string[]) => void} clearValidation * @version 0.0.3 */ clearValidation: (field?: string | string[]) => void; }; export type RuleItem = { /** * @property {boolean} [required=false] * @version 0.0.3 */ required?: boolean; /** * @property {string} [message] * @version 0.0.3 */ message?: string; /** * @property {RuleTrigger | RuleTrigger[]} [trigger=['change', 'blur']] * @version 0.0.3 */ trigger?: RuleTrigger | RuleTrigger[]; /** * @property {FieldType | FieldType[]} [type] * @version 0.0.3 */ type?: FieldType | FieldType[]; /** * @property {number} [max] * @version 0.0.3 */ max?: number; /** * @property {number} [min] * @version 0.0.3 */ min?: number; /** * @property {number} [maxLength] * @version 0.0.3 */ maxLength?: number; /** * @property {number} [minLength] * @version 0.0.3 */ minLength?: number; /** * @property {boolean} [email=false] * @version 0.0.3 */ email?: boolean; /** * @property {boolean} [url=false] * @version 0.0.3 */ url?: boolean; /** * @property {boolean} [numberString=false] * @version 0.0.3 */ numberString?: boolean; /** * @property {RuleLevel} [level='error'] * @version 0.0.3 */ level?: RuleLevel; /** * @property {(value: any, model: Record) => string | void | Promise} [validator] * @version 0.0.3 */ validator?: (value: any, model: Record) => string | void | Promise; }; export type FormProvide = { maxLabelWidth: ComputedRef; registerField: (fieldItem: FieldItem) => void; unregisterField: (field: string) => void; collectLabelWidth: (item: { id: string; width: number; }) => void; removeLabelWidth: (itemId: string) => void; model: Ref>; } & ToRefs>>; export type UseFormRegisterOptions = { validate: (field?: string | string[]) => FormValidateResult; clearValidation: (field?: string | string[]) => void; };