table 6.5.0 → 6.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/drawTable.d.ts +1 -1
- package/dist/drawTable.js +35 -24
- package/package.json +1 -1
package/dist/drawTable.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TableConfig, Row } from './types/internal';
|
|
2
|
-
declare const _default: (rows: Row[],
|
|
2
|
+
declare const _default: (rows: Row[], columnWidths: number[], rowHeights: number[], config: TableConfig) => string;
|
|
3
3
|
export default _default;
|
package/dist/drawTable.js
CHANGED
|
@@ -5,33 +5,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const drawBorder_1 = require("./drawBorder");
|
|
7
7
|
const drawRow_1 = __importDefault(require("./drawRow"));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Group the array into sub-arrays by sizes.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* chunkBySizes(['a', 'b', 'c', 'd', 'e'], [2, 1, 2]) = [ ['a', 'b'], ['c'], ['d', 'e'] ]
|
|
13
|
+
*/
|
|
14
|
+
const groupBySizes = (array, sizes) => {
|
|
15
|
+
let startIndex = 0;
|
|
16
|
+
return sizes.map((rowHeight) => {
|
|
17
|
+
const chunk = array.slice(startIndex, startIndex + rowHeight);
|
|
18
|
+
startIndex += rowHeight;
|
|
19
|
+
return chunk;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const shouldDrawBorderJoin = (rowIndex, rowCount, config) => {
|
|
23
|
+
const { singleLine, drawHorizontalLine } = config;
|
|
24
|
+
return !singleLine && rowIndex + 1 < rowCount && drawHorizontalLine(rowIndex + 1, rowCount);
|
|
25
|
+
};
|
|
26
|
+
exports.default = (rows, columnWidths, rowHeights, config) => {
|
|
27
|
+
const { drawHorizontalLine, } = config;
|
|
28
|
+
const groupedRows = groupBySizes(rows, rowHeights).map((group) => {
|
|
29
|
+
return group.map((row) => {
|
|
30
|
+
return drawRow_1.default(row, config);
|
|
31
|
+
}).join('');
|
|
32
|
+
});
|
|
33
|
+
const rowCount = groupedRows.length;
|
|
34
|
+
let output = '';
|
|
35
|
+
if (drawHorizontalLine(0, rowCount)) {
|
|
36
|
+
output += drawBorder_1.drawBorderTop(columnWidths, config);
|
|
18
37
|
}
|
|
19
|
-
|
|
20
|
-
output +=
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
realRowIndex++;
|
|
24
|
-
}
|
|
25
|
-
rowHeight--;
|
|
26
|
-
if (!singleLine &&
|
|
27
|
-
rowHeight === 0 &&
|
|
28
|
-
index0 !== rowCount - 1 &&
|
|
29
|
-
drawHorizontalLine(realRowIndex, rowCount)) {
|
|
30
|
-
output += drawBorder_1.drawBorderJoin(columnSizeIndex, config);
|
|
38
|
+
groupedRows.forEach((row, rowIndex) => {
|
|
39
|
+
output += row;
|
|
40
|
+
if (shouldDrawBorderJoin(rowIndex, rowCount, config)) {
|
|
41
|
+
output += drawBorder_1.drawBorderJoin(columnWidths, config);
|
|
31
42
|
}
|
|
32
43
|
});
|
|
33
|
-
if (drawHorizontalLine(
|
|
34
|
-
output += drawBorder_1.drawBorderBottom(
|
|
44
|
+
if (drawHorizontalLine(rowCount, rowCount)) {
|
|
45
|
+
output += drawBorder_1.drawBorderBottom(columnWidths, config);
|
|
35
46
|
}
|
|
36
47
|
return output;
|
|
37
48
|
};
|
package/package.json
CHANGED