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.

53 lines
1.1 KiB

4 years ago
  1. import {
  2. drawBorderTop,
  3. drawBorderJoin,
  4. drawBorderBottom
  5. } from './drawBorder';
  6. import drawRow from './drawRow';
  7. /**
  8. * @param {Array} rows
  9. * @param {Object} border
  10. * @param {Array} columnSizeIndex
  11. * @param {Array} rowSpanIndex
  12. * @param {Function} drawHorizontalLine
  13. * @param {boolean} singleLine
  14. * @returns {string}
  15. */
  16. export default (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine, singleLine) => {
  17. let output;
  18. let realRowIndex;
  19. let rowHeight;
  20. const rowCount = rows.length;
  21. realRowIndex = 0;
  22. output = '';
  23. if (drawHorizontalLine(realRowIndex, rowCount)) {
  24. output += drawBorderTop(columnSizeIndex, border);
  25. }
  26. rows.forEach((row, index0) => {
  27. output += drawRow(row, border);
  28. if (!rowHeight) {
  29. rowHeight = rowSpanIndex[realRowIndex];
  30. realRowIndex++;
  31. }
  32. rowHeight--;
  33. if (!singleLine && rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {
  34. output += drawBorderJoin(columnSizeIndex, border);
  35. }
  36. });
  37. if (drawHorizontalLine(realRowIndex, rowCount)) {
  38. output += drawBorderBottom(columnSizeIndex, border);
  39. }
  40. return output;
  41. };