import * as R from 'rambda'; import { wrapAction } from '../helper'; import { getRow, getCell } from '../../store/selectors'; import { EditContext, EditSchema, EditEvent } from '../index.data'; export const guards = { // 保证不是点击外部 hasSelected: (context: EditContext, event: EditEvent) => { return !!event.selectedRow || !!event.selectedCell; }, }; export const actions = { // 第一次选择, 此时没有一行 reSelect: wrapAction((context: EditContext, { selectedRow, selectedCell, state }: EditEvent) => { const _selectedRow = R.isNil(selectedRow) ? R.isNil(selectedCell) ? null : getCell(state!, selectedCell!)!.rowId! : selectedRow; return { selectionType: 'row', selectedRowRange: _selectedRow ? [_selectedRow, _selectedRow] : [], }; }), // 移动过程, 此时一定选中了第一行, 并且第二行有可能是选中行, 也可能选中单元格(应转化为行) appendSelect: wrapAction( (context: EditContext, { selectedRow, selectedCell, state }: EditEvent) => { const lastRowId = context.selectedRowRange[0]; const currentRowId = R.isNil(selectedRow) ? getCell(state!, selectedCell!)!.rowId! : selectedRow; const currentRow = getRow(state!, currentRowId); if (!currentRow) return {}; const selectedRowRange = [lastRowId, currentRow.id]; return { selectionType: 'row', selectedRowRange, }; }, ), };