UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

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