@f5-sales-demo/pi-tui 23.6.9 → 23.8.0
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/package.json +3 -3
- package/src/components/table.ts +14 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/pi-tui",
|
|
4
|
-
"version": "23.
|
|
4
|
+
"version": "23.8.0",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"fmt": "biome format --write ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@f5-sales-demo/pi-natives": "23.
|
|
41
|
-
"@f5-sales-demo/pi-utils": "23.
|
|
40
|
+
"@f5-sales-demo/pi-natives": "23.8.0",
|
|
41
|
+
"@f5-sales-demo/pi-utils": "23.8.0",
|
|
42
42
|
"marked": "18.0.11"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
package/src/components/table.ts
CHANGED
|
@@ -15,6 +15,7 @@ export function renderTable(
|
|
|
15
15
|
availableWidth: number,
|
|
16
16
|
theme: TableTheme,
|
|
17
17
|
alignment?: readonly ("left" | "right" | "center" | null)[],
|
|
18
|
+
columnSizing?: readonly { minWidth?: number; maxWidth?: number }[],
|
|
18
19
|
): string[] {
|
|
19
20
|
const lines: string[] = [];
|
|
20
21
|
const numCols = headers.length;
|
|
@@ -56,6 +57,18 @@ export function renderTable(
|
|
|
56
57
|
minWordWidths[i] = Math.max(minWordWidths[i] || 1, longestWordWidth(cellText, maxUnbrokenWordWidth));
|
|
57
58
|
}
|
|
58
59
|
}
|
|
60
|
+
const readableWidths = naturalWidths.map((natural, index) => {
|
|
61
|
+
const declared = columnSizing?.[index]?.minWidth;
|
|
62
|
+
return Number.isFinite(declared) ? Math.max(1, Math.floor(declared!)) : Math.min(6, natural);
|
|
63
|
+
});
|
|
64
|
+
if (readableWidths.reduce((sum, width) => sum + width, 0) > availableForCells) return reflow();
|
|
65
|
+
for (let i = 0; i < numCols; i++) {
|
|
66
|
+
const max = columnSizing?.[i]?.maxWidth;
|
|
67
|
+
if (Number.isFinite(max))
|
|
68
|
+
naturalWidths[i] = Math.min(naturalWidths[i], Math.max(readableWidths[i], Math.floor(max!)));
|
|
69
|
+
naturalWidths[i] = Math.max(naturalWidths[i], readableWidths[i]);
|
|
70
|
+
minWordWidths[i] = Math.max(readableWidths[i], Math.min(minWordWidths[i], naturalWidths[i]));
|
|
71
|
+
}
|
|
59
72
|
|
|
60
73
|
let minColumnWidths = minWordWidths;
|
|
61
74
|
let minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
|
|
@@ -127,7 +140,7 @@ export function renderTable(
|
|
|
127
140
|
}
|
|
128
141
|
}
|
|
129
142
|
|
|
130
|
-
if (columnWidths.some((width, index) => width <
|
|
143
|
+
if (columnWidths.some((width, index) => width < readableWidths[index])) return reflow();
|
|
131
144
|
|
|
132
145
|
const t = theme.symbols;
|
|
133
146
|
const h = t.horizontal;
|