UNPKG

@visactor/vtable

Version:

canvas table width high performance

89 lines (78 loc) 4.85 kB
import { getCellMergeInfo } from "../../../utils/get-cell-merge"; import { updateCell } from "../../cell-helper"; export function checkFirstRowMerge(row, proxy) { for (let col = 0; col < proxy.table.colCount; col++) { if (col >= proxy.table.rowHeaderLevelCount && col < proxy.colStart || col > proxy.colEnd && col < proxy.table.colCount - proxy.table.rightFrozenColCount) continue; const range = getCellMergeInfo(proxy.table, col, row); if (range && clearHadMergedRow(range.start.row, range.end.row, col, proxy), range && range.start.row !== row && "cell" !== proxy.highPerformanceGetCell(range.start.col, range.start.row, !0).role) { const oldCellGroup = proxy.highPerformanceGetCell(col, row, !0), newCellGroup = updateCell(range.start.col, range.start.row, proxy.table, !0); newCellGroup.col = col, newCellGroup.row = row, newCellGroup.setAttribute("y", proxy.table.getRowsHeight(proxy.table.frozenRowCount, range.start.row - 1)), oldCellGroup.parent.insertAfter(newCellGroup, oldCellGroup), oldCellGroup.parent.removeChild(oldCellGroup), oldCellGroup.needUpdate = !1, newCellGroup.needUpdate = !1, proxy.cellCache.get(col) && proxy.cellCache.set(col, newCellGroup); } } } export function checkFirstColMerge(col, proxy) { for (let row = 0; row < proxy.table.rowCount; row++) { if (row >= proxy.table.frozenRowCount && row < proxy.rowStart || row > proxy.rowEnd && row < proxy.table.rowCount - proxy.table.bottomFrozenRowCount) continue; const range = getCellMergeInfo(proxy.table, col, row); if (range && clearHadMergedColumn(range.start.col, range.end.col, row, proxy), range && range.start.col !== col && "cell" !== proxy.highPerformanceGetCell(range.start.col, range.start.row, !0).role) { const oldCellGroup = proxy.highPerformanceGetCell(col, row, !0), newCellGroup = updateCell(range.start.col, range.start.row, proxy.table, !0); newCellGroup.col = col, newCellGroup.row = row, newCellGroup.setAttribute("x", proxy.table.getColsWidth(proxy.table.rowHeaderLevelCount, range.start.col - 1) - oldCellGroup.parent.attribute.x), newCellGroup.setAttributes({ x: proxy.table.getColsWidth(proxy.table.rowHeaderLevelCount, range.start.col - 1) - oldCellGroup.parent.attribute.x, y: proxy.table.getRowsHeight(0, range.start.row - 1) - oldCellGroup.parent.attribute.y }), oldCellGroup.parent.insertAfter(newCellGroup, oldCellGroup), oldCellGroup.parent.removeChild(oldCellGroup), oldCellGroup.needUpdate = !1, newCellGroup.needUpdate = !1, proxy.cellCache.get(col) && proxy.cellCache.set(col, newCellGroup); } } } function clearHadMergedRow(rowStart, rowEnd, col, proxy) { for (let row = rowStart; row <= rowEnd; row++) { const cellGroup = proxy.highPerformanceGetCell(col, row, !0); "shadow-cell" !== cellGroup.role && "empty" !== cellGroup.role && cellGroup.row !== rowStart && (cellGroup.role = "shadow-cell", cellGroup.setAttributes({ width: 0, height: proxy.table.getRowHeight(cellGroup.row), y: proxy.table.getRowsHeight(proxy.table.frozenRowCount, cellGroup.row - 1), x: 0 }), cellGroup.clear()); } } function clearHadMergedColumn(colStart, colEnd, row, proxy) { for (let col = colStart; col <= colEnd; col++) { const cellGroup = proxy.highPerformanceGetCell(col, row, !0); "shadow-cell" !== cellGroup.role && "empty" !== cellGroup.role && cellGroup.col !== colStart && (cellGroup.role = "shadow-cell", cellGroup.setAttributes({ width: 0, height: proxy.table.getRowHeight(cellGroup.row), y: proxy.table.getRowsHeight(0, cellGroup.row - 1), x: 0 }), cellGroup.clear()); } } function checkHasColMerge(colStart, colEnd, row, proxy) { for (let col = colStart; col <= colEnd; col++) if ("shadow-cell" !== proxy.highPerformanceGetCell(col, row, !0).role && "empty" !== proxy.highPerformanceGetCell(col, row, !0).role) return !0; return !1; } export function getFirstChild(containerGroup) { let child = containerGroup.firstChild; for (;child && "group" !== child.type; ) child = child._next; return child; } export function getLastChild(containerGroup) { let child = containerGroup.lastChild; for (;child && "group" !== child.type; ) child = child._prev; return child; } export function getPrevGroup(group) { let child = group._prev; for (;child && "group" !== child.type; ) child = child._prev; return child; } export function getNextGroup(group) { let child = group._next; for (;child && "group" !== child.type; ) child = child._next; return child; } //# sourceMappingURL=util.js.map