calculateRowHeightIndex.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _lodash = require('lodash');
  6. var _lodash2 = _interopRequireDefault(_lodash);
  7. var _calculateCellHeight = require('./calculateCellHeight');
  8. var _calculateCellHeight2 = _interopRequireDefault(_calculateCellHeight);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * Calculates the vertical row span index.
  12. *
  13. * @param {Array[]} rows
  14. * @param {Object} config
  15. * @returns {number[]}
  16. */
  17. exports.default = (rows, config) => {
  18. const tableWidth = rows[0].length;
  19. const rowSpanIndex = [];
  20. _lodash2.default.forEach(rows, cells => {
  21. const cellHeightIndex = _lodash2.default.fill(Array(tableWidth), 1);
  22. _lodash2.default.forEach(cells, (value, index1) => {
  23. if (!_lodash2.default.isNumber(config.columns[index1].width)) {
  24. throw new TypeError('column[index].width must be a number.');
  25. }
  26. if (!_lodash2.default.isBoolean(config.columns[index1].wrapWord)) {
  27. throw new TypeError('column[index].wrapWord must be a boolean.');
  28. }
  29. cellHeightIndex[index1] = (0, _calculateCellHeight2.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
  30. });
  31. rowSpanIndex.push(_lodash2.default.max(cellHeightIndex));
  32. });
  33. return rowSpanIndex;
  34. };