UNPKG

@zkochan/table

Version:

Formats data into a string table.

40 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateRowHeights = void 0; const calculateCellHeight_1 = require("./calculateCellHeight"); const utils_1 = require("./utils"); /** * Produces an array of values that describe the largest value length (height) in every row. */ const calculateRowHeights = (rows, config) => { const rowHeights = []; for (const [rowIndex, row] of rows.entries()) { let rowHeight = 1; row.forEach((cell, cellIndex) => { const containingRange = config.spanningCellManager?.getContainingRange({ col: cellIndex, row: rowIndex }); if (!containingRange) { const cellHeight = (0, calculateCellHeight_1.calculateCellHeight)(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord); rowHeight = Math.max(rowHeight, cellHeight); return; } const { topLeft, bottomRight, height } = containingRange; // bottom-most cell of a range needs to contain all remain lines of spanning cells if (rowIndex === bottomRight.row) { const totalOccupiedSpanningCellHeight = (0, utils_1.sumArray)(rowHeights.slice(topLeft.row)); const totalHorizontalBorderHeight = bottomRight.row - topLeft.row; const totalHiddenHorizontalBorderHeight = (0, utils_1.sequence)(topLeft.row + 1, bottomRight.row).filter((horizontalBorderIndex) => { /* istanbul ignore next */ return !config.drawHorizontalLine?.(horizontalBorderIndex, rows.length); }).length; const cellHeight = height - totalOccupiedSpanningCellHeight - totalHorizontalBorderHeight + totalHiddenHorizontalBorderHeight; rowHeight = Math.max(rowHeight, cellHeight); } // otherwise, just depend on other sibling cell heights in the row }); rowHeights.push(rowHeight); } return rowHeights; }; exports.calculateRowHeights = calculateRowHeights; //# sourceMappingURL=calculateRowHeights.js.map