@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/tables.ts +13 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-display",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Pi core extension — inline chips, thinking blocks, and framed code rendering",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
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 rows sorted and an arrow on the sorted header. */
90
- function sortedToken(token: TableToken, sort: Sort): TableToken {
91
- const arrow = { type: "text", raw: "", text: sort.desc ? " ▼" : " ▲" };
92
- const header = token.header.map((cell, i) =>
93
- i === sort.col ? { ...cell, tokens: [...(cell.tokens ?? []), arrow] } : cell,
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, sort ? sortedToken(token, sort) : token, ...rest);
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;