drawContent.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.drawContent = void 0;
  4. const drawContent = (parameters) => {
  5. const { contents, separatorGetter, drawSeparator, spanningCellManager, rowIndex, elementType } = parameters;
  6. const contentSize = contents.length;
  7. const result = [];
  8. if (drawSeparator(0, contentSize)) {
  9. result.push(separatorGetter(0, contentSize));
  10. }
  11. contents.forEach((content, contentIndex) => {
  12. if (!elementType || elementType === 'border' || elementType === 'row') {
  13. result.push(content);
  14. }
  15. if (elementType === 'cell' && rowIndex === undefined) {
  16. result.push(content);
  17. }
  18. if (elementType === 'cell' && rowIndex !== undefined) {
  19. /* istanbul ignore next */
  20. const containingRange = spanningCellManager === null || spanningCellManager === void 0 ? void 0 : spanningCellManager.getContainingRange({ col: contentIndex,
  21. row: rowIndex });
  22. // when drawing content row, just add a cell when it is a normal cell
  23. // or belongs to first column of spanning cell
  24. if (!containingRange || contentIndex === containingRange.topLeft.col) {
  25. result.push(content);
  26. }
  27. }
  28. // Only append the middle separator if the content is not the last
  29. if (contentIndex + 1 < contentSize && drawSeparator(contentIndex + 1, contentSize)) {
  30. const separator = separatorGetter(contentIndex + 1, contentSize);
  31. if (elementType === 'cell' && rowIndex !== undefined) {
  32. const currentCell = { col: contentIndex + 1,
  33. row: rowIndex };
  34. /* istanbul ignore next */
  35. const containingRange = spanningCellManager === null || spanningCellManager === void 0 ? void 0 : spanningCellManager.getContainingRange(currentCell);
  36. if (!containingRange || containingRange.topLeft.col === currentCell.col) {
  37. result.push(separator);
  38. }
  39. }
  40. else {
  41. result.push(separator);
  42. }
  43. }
  44. });
  45. if (drawSeparator(contentSize, contentSize)) {
  46. result.push(separatorGetter(contentSize, contentSize));
  47. }
  48. return result.join('');
  49. };
  50. exports.drawContent = drawContent;
  51. //# sourceMappingURL=drawContent.js.map