UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

77 lines 2.82 kB
import { forEach, isEqual } from 'lodash'; import { CellType, DATA_CELL_ID_SEPARATOR, InteractionStateName, } from '../../common/constant'; /** * @description Determine if the current cell belongs to Cells * @param cells active cells * @param currentCell current activated cell */ export const includeCell = (cells, currentCell) => { const currentId = currentCell.getMeta().id; return cells.some((cell) => isEqual(cell.id, currentId)); }; export const getDataCellId = (rowId, colId) => { return `${rowId}${DATA_CELL_ID_SEPARATOR}${colId}`; }; export const shouldUpdateBySelectedCellsHighlight = (s2) => { const { currentRow, currentCol, rowHeader, colHeader } = s2.interaction.getSelectedCellHighlight(); return currentRow || currentCol || rowHeader || colHeader; }; export const isDataCell = (cell) => cell.type === CellType.DATA_CELL; /** * highlight cells of the row * @param cells cells selected * @param dataCell cell to render */ export const updateCurrentRowCellState = (cells, dataCell) => { forEach(cells, (cell) => { if (isDataCell(cell) && cell.rowIndex === dataCell.getMeta().rowIndex) { dataCell.updateByState(InteractionStateName.SELECTED); } }); }; /** * highlight cells of the column * @param cells cells selected * @param dataCell cell to render */ export const updateCurrentColumnCellState = (cells, dataCell) => { forEach(cells, (cell) => { if (isDataCell(cell) && cell.colIndex === dataCell.getMeta().colIndex) { dataCell.updateByState(InteractionStateName.SELECTED); } }); }; /** * highlight cells * @param cells cells selected * @param dataCell cell to render */ export const updateCurrentCellState = (cells, dataCell) => { forEach(cells, (cell) => { if (isDataCell(cell) && cell.rowIndex === dataCell.getMeta().rowIndex && cell.colIndex === dataCell.getMeta().colIndex) { dataCell.updateByState(InteractionStateName.SELECTED); } }); }; export const updateBySelectedCellsHighlight = (cells, dataCell, s2) => { var _a; const { rowHeader, colHeader, currentRow, currentCol } = s2.interaction.getSelectedCellHighlight(); const isRowCell = dataCell.cellType === CellType.ROW_CELL; // 高亮序号 const showSNWhenRowHeaderHighlight = s2.isTableMode() && ((_a = s2.options.seriesNumber) === null || _a === void 0 ? void 0 : _a.enable) && rowHeader && isRowCell; if (currentRow || showSNWhenRowHeaderHighlight) { updateCurrentRowCellState(cells, dataCell); } if (currentCol) { updateCurrentColumnCellState(cells, dataCell); } if (rowHeader || colHeader) { updateCurrentCellState(cells, dataCell); } }; //# sourceMappingURL=data-cell.js.map