import type { Key, ReactElement } from 'react'; import type { BaseTableProps, ColumnType } from '../base-table/typings'; import type { RuleItem } from 'async-validator/dist-types/interface'; type RowType = { key: Key; index: number; }; type EditableCellFocusedType = 0 | 1 | 2; export type EditableRender = ( val: any, record: T, index: number, opts: { focused: EditableCellFocusedType; onFocus: () => void; errors?: string[]; onChange: (value: Partial) => void; }, ) => ReactElement | null; export type EditableTableRule = Pick< RuleItem, 'required' | 'message' | 'pattern' | 'min' | 'max' | 'len' | 'type' > & { validator?: (rule: unknown, val: any, record: T) => void | Promise; }; export type EditableTableRef = { validate: () => Promise; }; export interface EditableTableColumnType extends Pick< ColumnType, 'key' | 'width' | 'render' | 'align' | 'ellipsis' | 'title' | 'fixed' > { dataIndex: string; render?: ( val: any, record: T, index: number, ) => ReactElement | string | number | null | undefined; editable?: { /** * @description 是否禁止可编辑单元格支持上下键切换,注意不是禁止单元格表单组件的上下键操作,而是EditableCell的上下键切换 */ disableLeftRight?: boolean; /** * @description 同disabledLeftRight */ disableUpDown?: boolean; rules?: EditableTableRule[]; /** * @description 是否自定义渲染单元格内表单组件,需要配合EditableCell组件进行使用,详见demo中的使用方式 */ renderFormItem: EditableRender | ReactElement; }; } export type EditableTableRowError = { key: string; errors: string[]; children?: { key: string; errors: string[]; }[]; }; export interface EditableTableProps extends Pick< BaseTableProps, 'rowKey' | 'virtual' | 'scroll' | 'pagination' | 'loading' | 'summaryRecord' | 'summaryTitle' > { editable?: boolean; value?: T[]; error?: string | EditableTableRowError[]; onChange?: (value: T[]) => void; rowSelection?: BaseTableProps['rowSelection']; rowActions?: BaseTableProps['rowActions']; columns: EditableTableColumnType[]; } export type EditableTableObserverHandler = (params: { record?: T; focused?: EditableCellFocusedType; errors?: string[] | null; }) => void;