mapDataUsingRowHeightIndex.js.flow 902 B

12345678910111213141516171819202122232425262728293031323334
  1. import _ from 'lodash';
  2. import wrapCell from './wrapCell';
  3. /**
  4. * @param {Array} unmappedRows
  5. * @param {number[]} rowHeightIndex
  6. * @param {Object} config
  7. * @returns {Array}
  8. */
  9. export default (unmappedRows, rowHeightIndex, config) => {
  10. const tableWidth = unmappedRows[0].length;
  11. const mappedRows = unmappedRows.map((cells, index0) => {
  12. const rowHeight = _.times(rowHeightIndex[index0], () => {
  13. return new Array(tableWidth).fill('');
  14. });
  15. // rowHeight
  16. // [{row index within rowSaw; index2}]
  17. // [{cell index within a virtual row; index1}]
  18. cells.forEach((value, index1) => {
  19. const cellLines = wrapCell(value, config.columns[index1].width, config.columns[index1].wrapWord);
  20. cellLines.forEach((cellLine, index2) => {
  21. rowHeight[index2][index1] = cellLine;
  22. });
  23. });
  24. return rowHeight;
  25. });
  26. return _.flatten(mappedRows);
  27. };