import { type default as React } from 'react'; import { type FormState, type FieldState, type FormApi, type FormSubscription, type FieldSubscription, type SubmissionErrors, type ValidationErrors } from 'final-form'; import { Model } from './index.ts'; /** 基于 final-form 的面向对象的表单模型 Object-oriented form model based on final-form. 用于封装 @tencent/tea-componet Designed to work seamlessly with Form component of @tencent/tea-componet. @see https://github.com/ShenHongFei/react-object-model @example ```ts class UserForm extends FormModel { name = new FormField(this.form, 'name', '') age = new FormField(this.form, 'age', '0') override async submit (values: UserFormValues) { await delay(3000) console.log('submit', values) } override validate ({ name, age }: UserFormValues) { return { name: name ? undefined : 'name cannot be empty', age: Number(age) < 18 ? 'age is less than 18' : undefined, } } } let fuser = new UserForm() ``` */ export declare class FormModel { static subscription_form_all: { [k: string]: boolean; }; /** final-form 实例和表单状态 final-form instance & form state */ form: FormApi & FormState; /** 在组件中订阅表单状态(不传参则默认订阅所有表单状态修改) subscribe to form state in a component (defaults to subscribe all changes) @example const { form: { hasValidationErrors, submitting, submit } } = fuser.use({ hasValidationErrors: true, submitting: true }) */ use(subscription?: FormSubscription): this; /** 需要被子类重写,在 final-form 的 submit 被调用时执行 should be overriden by subclass, called when final-form submit is called */ submit(values: FormValues, form: FormApi): SubmissionErrors | Promise | void; /** 需要被子类重写,用于自定义字段校验错误 should be overriden by subclass for customized fields validation errors */ validate(values: FormValues): ValidationErrors | Promise; } export interface FormField extends FieldState { } export declare class FormField extends Model> { static subscription_field_all: { [k: string]: boolean; }; static get_event_value(event: any): any; value: Value; form: FormApi; item: { label: string; status: 'success' | 'error' | 'validating'; message: React.ReactNode; }; input: { name: string; onBlur(event?: React.FocusEvent): void; onChange(event: React.ChangeEvent | Value): void; onFocus(event?: React.FocusEvent): void; value: Value; checked?: boolean; }; meta: NonFunctionProperties>; unsubscribe: () => void; constructor(form: FormApi, name: keyof FormValues, initial_value: Value, subscription?: FieldSubscription); get_field_item({ touched, error }: { touched?: boolean; error?: any; }, value: Value): { status: 'success' | 'error' | 'validating'; message: React.ReactNode; label: string; }; } type NonFunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]; type NonFunctionProperties = Pick>; export {};