UNPKG

@visactor/vtable

Version:

canvas table width high performance

45 lines (39 loc) 4.21 kB
import { getProp } from "../../scenegraph/utils/get-prop"; import { HighlightScope } from "../../ts-types"; import { isValid } from "@visactor/vutils"; import { getCellMergeRange } from "../../tools/merge-range"; export function getCellHoverColor(cellGroup, table) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; let colorKey, hoverStyle; if ("cell" === cellGroup.role && isValid(cellGroup.mergeStartCol) && isValid(cellGroup.mergeStartRow) && isValid(cellGroup.mergeEndCol) && isValid(cellGroup.mergeEndRow)) { const {colStart: colStart, colEnd: colEnd, rowStart: rowStart, rowEnd: rowEnd} = getCellMergeRange(cellGroup, table.scenegraph); for (let col = colStart; col <= colEnd; col++) for (let row = rowStart; row <= rowEnd; row++) { const key = isCellHover(table.stateManager, col, row, cellGroup); !key || colorKey && "cellBgColor" !== key || (colorKey = key); } } else "cell" === cellGroup.role && (colorKey = isCellHover(table.stateManager, cellGroup.col, cellGroup.row, cellGroup)); if (!colorKey) return; const layout = table.internalProps.layoutMap; layout.isCornerHeader(cellGroup.col, cellGroup.row) ? hoverStyle = (null === (_a = table.theme.cornerHeaderStyle) || void 0 === _a ? void 0 : _a.hover) || (null === (_b = table.theme.headerStyle) || void 0 === _b ? void 0 : _b.hover) : layout.isColumnHeader(cellGroup.col, cellGroup.row) ? hoverStyle = null === (_c = table.theme.headerStyle) || void 0 === _c ? void 0 : _c.hover : layout.isRowHeader(cellGroup.col, cellGroup.row) ? hoverStyle = null === (_d = table.theme.rowHeaderStyle) || void 0 === _d ? void 0 : _d.hover : layout.isBottomFrozenRow(cellGroup.col, cellGroup.row) ? hoverStyle = (null === (_e = table.theme.bottomFrozenStyle) || void 0 === _e ? void 0 : _e.hover) || (table.isListTable() ? null === (_f = table.theme.bodyStyle) || void 0 === _f ? void 0 : _f.hover : null === (_g = table.theme.headerStyle) || void 0 === _g ? void 0 : _g.hover) : layout.isRightFrozenColumn(cellGroup.col, cellGroup.row) ? hoverStyle = (null === (_h = table.theme.rightFrozenStyle) || void 0 === _h ? void 0 : _h.hover) || (table.isListTable() ? null === (_j = table.theme.bodyStyle) || void 0 === _j ? void 0 : _j.hover : null === (_k = table.theme.rowHeaderStyle) || void 0 === _k ? void 0 : _k.hover) : table.isHeader(cellGroup.col, cellGroup.row) || (hoverStyle = null === (_l = table.theme.bodyStyle) || void 0 === _l ? void 0 : _l.hover); return getProp(colorKey, hoverStyle, cellGroup.col, cellGroup.row, table); } export function isCellHover(state, col, row, cellGroup) { var _a; const {highlightScope: highlightScope, disableHeader: disableHeader, cellPos: cellPos} = state.hover, table = state.table, isHeader = table.isHeader(col, row); if (isHeader && disableHeader) return; let hoverMode; if (highlightScope === HighlightScope.single && cellPos.col === col && cellPos.row === row ? hoverMode = "cellBgColor" : highlightScope === HighlightScope.column && cellPos.col === col ? hoverMode = cellPos.col === col && cellPos.row === row ? "cellBgColor" : "inlineColumnBgColor" : highlightScope === HighlightScope.row && cellPos.row === row ? hoverMode = cellPos.col === col && cellPos.row === row ? "cellBgColor" : "inlineRowBgColor" : highlightScope === HighlightScope.cross && (cellPos.col === col && cellPos.row === row ? hoverMode = "cellBgColor" : cellPos.col === col ? hoverMode = "inlineColumnBgColor" : cellPos.row === row && (hoverMode = "inlineRowBgColor")), hoverMode) { let cellDisable; if (isHeader) { const define = table.getHeaderDefine(col, row); cellDisable = null == define ? void 0 : define.disableHeaderHover, cellGroup.firstChild && "axis" === cellGroup.firstChild.name && (null === (_a = table.options.hover) || void 0 === _a ? void 0 : _a.disableAxisHover) && (cellDisable = !0); } else { const define = table.getBodyColumnDefine(col, row); cellDisable = null == define ? void 0 : define.disableHover; } cellDisable && (hoverMode = void 0); } return hoverMode; } //# sourceMappingURL=is-cell-hover.js.map