You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
926 B

4 years ago
  1. import _ from 'lodash';
  2. import calculateCellHeight from './calculateCellHeight';
  3. /**
  4. * Calculates the vertical row span index.
  5. *
  6. * @param {Array[]} rows
  7. * @param {Object} config
  8. * @returns {number[]}
  9. */
  10. export default (rows, config) => {
  11. const tableWidth = rows[0].length;
  12. const rowSpanIndex = [];
  13. rows.forEach((cells) => {
  14. const cellHeightIndex = new Array(tableWidth).fill(1);
  15. cells.forEach((value, index1) => {
  16. if (!_.isNumber(config.columns[index1].width)) {
  17. throw new TypeError('column[index].width must be a number.');
  18. }
  19. if (!_.isBoolean(config.columns[index1].wrapWord)) {
  20. throw new TypeError('column[index].wrapWord must be a boolean.');
  21. }
  22. cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
  23. });
  24. rowSpanIndex.push(_.max(cellHeightIndex));
  25. });
  26. return rowSpanIndex;
  27. };