UNPKG

table

Version:

Formats data into a string table.

46 lines • 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateRowHeights = void 0; const utils_1 = require("./utils"); const wrapCell_1 = require("./wrapCell"); /** * Produces an array of values that describe the largest value length (height) in every row. The lines of * the wrapped cells are kept in wrappedCells, if it is given. */ const calculateRowHeights = (rows, config, wrappedCells) => { const rowHeights = []; for (const [rowIndex, row] of rows.entries()) { let rowHeight = 1; const wrappedRow = []; wrappedCells === null || wrappedCells === void 0 ? void 0 : wrappedCells.push(wrappedRow); row.forEach((cell, cellIndex) => { var _a; const containingRange = (_a = config.spanningCellManager) === null || _a === void 0 ? void 0 : _a.getContainingRange({ col: cellIndex, row: rowIndex }); if (!containingRange) { const cellLines = (0, wrapCell_1.wrapCell)(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord); wrappedRow[cellIndex] = cellLines; rowHeight = Math.max(rowHeight, cellLines.length); 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) => { var _a; /* istanbul ignore next */ return !((_a = config.drawHorizontalLine) === null || _a === void 0 ? void 0 : _a.call(config, 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