mapDataUsingRowHeights.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.mapDataUsingRowHeights = exports.padCellVertically = void 0;
  4. const utils_1 = require("./utils");
  5. const wrapCell_1 = require("./wrapCell");
  6. const createEmptyStrings = (length) => {
  7. return new Array(length).fill('');
  8. };
  9. const padCellVertically = (lines, rowHeight, verticalAlignment) => {
  10. const availableLines = rowHeight - lines.length;
  11. if (verticalAlignment === 'top') {
  12. return [...lines, ...createEmptyStrings(availableLines)];
  13. }
  14. if (verticalAlignment === 'bottom') {
  15. return [...createEmptyStrings(availableLines), ...lines];
  16. }
  17. return [
  18. ...createEmptyStrings(Math.floor(availableLines / 2)),
  19. ...lines,
  20. ...createEmptyStrings(Math.ceil(availableLines / 2)),
  21. ];
  22. };
  23. exports.padCellVertically = padCellVertically;
  24. const mapDataUsingRowHeights = (unmappedRows, rowHeights, config) => {
  25. const nColumns = unmappedRows[0].length;
  26. const mappedRows = unmappedRows.map((unmappedRow, unmappedRowIndex) => {
  27. const outputRowHeight = rowHeights[unmappedRowIndex];
  28. const outputRow = Array.from({ length: outputRowHeight }, () => {
  29. return new Array(nColumns).fill('');
  30. });
  31. unmappedRow.forEach((cell, cellIndex) => {
  32. var _a;
  33. const containingRange = (_a = config.spanningCellManager) === null || _a === void 0 ? void 0 : _a.getContainingRange({ col: cellIndex,
  34. row: unmappedRowIndex });
  35. if (containingRange) {
  36. containingRange.extractCellContent(unmappedRowIndex).forEach((cellLine, cellLineIndex) => {
  37. outputRow[cellLineIndex][cellIndex] = cellLine;
  38. });
  39. return;
  40. }
  41. const cellLines = (0, wrapCell_1.wrapCell)(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
  42. const paddedCellLines = (0, exports.padCellVertically)(cellLines, outputRowHeight, config.columns[cellIndex].verticalAlignment);
  43. paddedCellLines.forEach((cellLine, cellLineIndex) => {
  44. outputRow[cellLineIndex][cellIndex] = cellLine;
  45. });
  46. });
  47. return outputRow;
  48. });
  49. return (0, utils_1.flatten)(mappedRows);
  50. };
  51. exports.mapDataUsingRowHeights = mapDataUsingRowHeights;
  52. //# sourceMappingURL=mapDataUsingRowHeights.js.map