@xynogen/pix-display 0.6.0 → 0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-display",
3
- "version": "0.6.0",
3
+ "version": "0.8.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",
@@ -100,7 +100,7 @@ function bottomRule(width: number, theme: CodeFrameTheme): string {
100
100
  return theme.fg("borderMuted", "─".repeat(width));
101
101
  }
102
102
 
103
- function bodyLine(line: string, width: number, layoutIndent: number): string {
103
+ function codeCell(line: string, width: number, layoutIndent: number): string {
104
104
  // Code column only; the caller prepends the same numbered gutter as the
105
105
  // file-content renderer.
106
106
  return truncateToWidth(stripLayoutWhitespace(line, layoutIndent), width, "…");
@@ -148,7 +148,7 @@ export function renderCodeFences(
148
148
  if (!isFoldedBlock) {
149
149
  for (let index = start + 1; index < end; index++) {
150
150
  framed.push(
151
- `${oscSequences(out[index] ?? "")}${lineGutter(index - start, numberWidth)}${bodyLine(out[index] ?? "", codeWidth, bodyIndent)}${RST}`,
151
+ `${oscSequences(out[index] ?? "")}${lineGutter(index - start, numberWidth)}${codeCell(out[index] ?? "", codeWidth, bodyIndent)}${RST}`,
152
152
  );
153
153
  }
154
154
  framed.push(`${oscSequences(out[end] ?? "")}${bottomRule(frameWidth, theme)}`);
package/src/code-frame.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Interactions on a code frame's header row: the arrow at the left folds the block,
3
- * the `copy` button at the right end writes its source to the system clipboard.
2
+ * Interactions on a code frame's header row: a click anywhere on the row folds the
3
+ * block, except the `copy` button at its right end, which writes the source to the
4
+ * system clipboard.
4
5
  *
5
6
  * Rows come from the same render that drew the frames, so a hit test cannot drift
6
7
  * from what the user sees. Display only: the session keeps the raw text.
@@ -66,20 +67,19 @@ function copyFrame(frame: CodeFrame): void {
66
67
  }
67
68
 
68
69
  /**
69
- * Left click on a frame's header: the arrow folds the block, the trailing `copy`
70
- * button writes it. Returns true when the click was ours.
70
+ * Left click on a frame's header row: the trailing `copy` button writes the block,
71
+ * anywhere else on the row folds it. Returns true when the click was ours.
71
72
  */
72
73
  export function frameClickAt(owner: Owner, event: Click): boolean {
73
74
  if (event.type !== "click" || event.button !== "left") return false;
74
75
  const frame = frames.get(owner)?.find((candidate) => candidate.row === event.y);
75
76
  if (!frame) return false;
76
- if (event.x < FOLD_ARROW) {
77
- if (folded.has(frame.text)) folded.delete(frame.text);
78
- else folded.add(frame.text);
79
- owner.invalidate?.();
77
+ if (event.x >= event.width - COPY_BUTTON.length) {
78
+ copyFrame(frame);
80
79
  return true;
81
80
  }
82
- if (event.x < event.width - COPY_BUTTON.length) return false;
83
- copyFrame(frame);
81
+ if (folded.has(frame.text)) folded.delete(frame.text);
82
+ else folded.add(frame.text);
83
+ owner.invalidate?.();
84
84
  return true;
85
85
  }
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;