@xynogen/pix-display 0.6.0 → 0.7.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 +1 -1
- package/src/tables.ts +13 -7
package/package.json
CHANGED
package/src/tables.ts
CHANGED
|
@@ -86,12 +86,18 @@ export function columnAt(plain: string, x: number): number | undefined {
|
|
|
86
86
|
return col < 0 ? last - 1 : col;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
/** A copy of the table token with
|
|
90
|
-
function
|
|
91
|
-
const arrow =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
/** A copy of the table token with sort hints in every header and optional sorted rows. */
|
|
90
|
+
function sortableToken(token: TableToken, sort?: Sort): TableToken {
|
|
91
|
+
const arrow = (i: number) => ({
|
|
92
|
+
type: "text",
|
|
93
|
+
raw: "",
|
|
94
|
+
text: i === sort?.col ? (sort.desc ? "▼ " : "▲ ") : "▾ ",
|
|
95
|
+
});
|
|
96
|
+
const header = token.header.map((cell, i) => ({
|
|
97
|
+
...cell,
|
|
98
|
+
tokens: [arrow(i), ...(cell.tokens ?? [])],
|
|
99
|
+
}));
|
|
100
|
+
if (!sort) return { ...token, header };
|
|
95
101
|
const numeric = isNumericColumn(token.rows, sort.col);
|
|
96
102
|
return { ...token, header, rows: sortRows(token.rows, sort.col, sort.desc, numeric) };
|
|
97
103
|
}
|
|
@@ -204,7 +210,7 @@ function patchTableRenderer(): void {
|
|
|
204
210
|
(native) =>
|
|
205
211
|
function renderStyledTable(this: object, token: TableToken, ...rest: unknown[]) {
|
|
206
212
|
const sort = token.raw ? sorts.get(token.raw) : undefined;
|
|
207
|
-
const lines: string[] = native.call(this,
|
|
213
|
+
const lines: string[] = native.call(this, sortableToken(token, sort), ...rest);
|
|
208
214
|
const styled = activeTheme ? styleTable(lines, token.align ?? [], activeTheme) : lines;
|
|
209
215
|
rememberHeader(this, token, styled);
|
|
210
216
|
return styled;
|