/* eslint-disable max-len */ import { DefaultAdapter } from '../base/foundation'; import { Options as scrollIntoViewOptions } from 'scroll-into-view-if-needed'; export type BasicTriggerType = 'blur' | 'change' | 'custom' | 'mount'; export type FieldValidateTriggerType = BasicTriggerType | Array; export type CommonFieldError = boolean | string | Array | undefined | unknown; export interface BaseFormAdapter

, S = Record> extends DefaultAdapter { cloneDeep: (val: any, ...rest: any[]) => any; notifySubmit: (values: any) => void; notifySubmitFail: (errors: Record, values: any) => void; forceUpdate: () => void; notifyChange: (formState: FormState) => void; notifyValueChange: (values: any, changedValues: any) => void; notifyReset: () => void; getInitValues: () => Record; getFormProps: (keys: undefined | string | Array) => any; getAllErrorDOM: () => NodeList; getFieldDOM: (field: string) => Node; } export interface FormState = any> { values?: T extends Record ? T : Record; errors?: T extends Record ? { [K in keyof T]?: string } : Record; touched?: T extends Record ? { [K in keyof T]?: boolean } : Record; } export interface setValuesConfig { isOverride: boolean; } export interface BaseFormApi = any> { /** get value of field */ getValue: (field?: K) => T[K]; /** set value of field */ setValue: (field: K, newFieldValue: T[K]) => void; /** get error of field */ getError: (field: K) => any; /** set error of field */ setError: (field: K, fieldError: any) => void; /** get touched of field */ getTouched: (field: K) => boolean; /** set touch of field */ setTouched: (field: K, fieldTouch: boolean) => void; /** judge field exist */ getFieldExist: (field: K) => boolean; /** get formState of form */ getFormState: () => FormState ? T : Record>; /** submit form manual */ submitForm: () => void; /** reset form manual */ reset: () => void; /** trigger validate manual */ validate: , V extends Params[number]>(fields?: Params) => Promise<{ [R in V]: T[R] }>; getInitValue: (field: K) => any; getInitValues: () => any; getValues: () => T; /** set value of multiple fields */ setValues: (fieldsValue: Partial, config?: setValuesConfig) => void; scrollToField: (field: K, scrollConfig?: scrollIntoViewOptions) => void; } export interface CallOpts { [x: string]: any; notNotify?: boolean; notUpdate?: boolean; needClone?: boolean; } export interface ComponentProps { [x: string]: any; } export interface FieldState { value?: any; touched?: any; error?: any; status?: 'error' | 'success'; } export interface withFieldOption { valueKey?: string; onKeyChangeFnName?: string; valuePath?: string; maintainCursor?: boolean; shouldMemo?: boolean; shouldInject?: boolean; } export interface InternalFieldApi { setValue: (val: any, opts: CallOpts) => void; setTouched: (isTouched: boolean, opts: CallOpts) => void; setError: (errors: any, opts: CallOpts) => void; reset: () => void; validate: (val: any, opts: CallOpts) => Promise; } export interface FieldStaff { field: string; fieldApi: InternalFieldApi; keepState: boolean; allowEmpty: boolean; } export interface ArrayFieldStaff { field: string; updateKey?: string; initValue?: any; } export interface FormUpdaterContextType { register: (field: string, fieldState: FieldState, fieldStuff: FieldStaff) => void; unRegister: (field: string) => void; updateStateValue: (field: string, value: any, opts: CallOpts) => void; updateStateError: (field: string, error: any, opts: CallOpts) => void; updateStateTouched: (field: string, isTouched: boolean, opts?: CallOpts) => void; getValue: (field?: string | undefined, opts?: CallOpts) => any; getError: (field?: string) => any; getTouched: (field?: string) => boolean | Record | undefined; getInitValues: () => any; getInitValue: (field?: string) => any; getFormProps: (keys?: Array) => ComponentProps; getField: (field: string) => FieldStaff | undefined; registerArrayField: (arrayFieldPath: string, val: any) => void; unRegisterArrayField: (arrayField: string) => void; getArrayField: (arrayField: string) => ArrayFieldStaff; updateArrayField: (arrayField: string, updateValue: any) => void; }