@tooee/renderers 0.7.3 → 0.9.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 (171) hide show
  1. package/dist/chooser/choose-filter.d.ts +13 -0
  2. package/dist/chooser/choose-filter.d.ts.map +1 -0
  3. package/dist/chooser/choose-filter.js +22 -0
  4. package/dist/chooser/choose-filter.js.map +1 -0
  5. package/dist/chooser/choose-highlighted-text.d.ts +9 -0
  6. package/dist/chooser/choose-highlighted-text.d.ts.map +1 -0
  7. package/dist/chooser/choose-highlighted-text.js +32 -0
  8. package/dist/chooser/choose-highlighted-text.js.map +1 -0
  9. package/dist/chooser/choose-list.d.ts +29 -0
  10. package/dist/chooser/choose-list.d.ts.map +1 -0
  11. package/dist/chooser/choose-list.js +66 -0
  12. package/dist/chooser/choose-list.js.map +1 -0
  13. package/dist/chooser/choose-store.d.ts +58 -0
  14. package/dist/chooser/choose-store.d.ts.map +1 -0
  15. package/dist/chooser/choose-store.js +102 -0
  16. package/dist/chooser/choose-store.js.map +1 -0
  17. package/dist/chooser/chooser.d.ts +18 -0
  18. package/dist/chooser/chooser.d.ts.map +1 -0
  19. package/dist/chooser/chooser.js +25 -0
  20. package/dist/chooser/chooser.js.map +1 -0
  21. package/dist/chooser/fuzzy.d.ts +9 -0
  22. package/dist/chooser/fuzzy.d.ts.map +1 -0
  23. package/dist/chooser/fuzzy.js +5 -0
  24. package/dist/chooser/fuzzy.js.map +1 -0
  25. package/dist/chooser/source.d.ts +5 -0
  26. package/dist/chooser/source.d.ts.map +1 -0
  27. package/dist/chooser/source.js +26 -0
  28. package/dist/chooser/source.js.map +1 -0
  29. package/dist/chooser/types.d.ts +22 -0
  30. package/dist/chooser/types.d.ts.map +1 -0
  31. package/dist/chooser/types.js +2 -0
  32. package/dist/chooser/types.js.map +1 -0
  33. package/dist/chooser/use-choose.d.ts +84 -0
  34. package/dist/chooser/use-choose.d.ts.map +1 -0
  35. package/dist/chooser/use-choose.js +382 -0
  36. package/dist/chooser/use-choose.js.map +1 -0
  37. package/dist/code-blocks.d.ts +2 -1
  38. package/dist/code-blocks.d.ts.map +1 -1
  39. package/dist/code-blocks.js +20 -18
  40. package/dist/code-blocks.js.map +1 -1
  41. package/dist/code-view.d.ts +2 -1
  42. package/dist/code-view.d.ts.map +1 -1
  43. package/dist/code-view.js.map +1 -1
  44. package/dist/command-palette.d.ts +2 -1
  45. package/dist/command-palette.d.ts.map +1 -1
  46. package/dist/command-palette.js +15 -76
  47. package/dist/command-palette.js.map +1 -1
  48. package/dist/context-menu.d.ts +2 -1
  49. package/dist/context-menu.d.ts.map +1 -1
  50. package/dist/context-menu.js +50 -15
  51. package/dist/context-menu.js.map +1 -1
  52. package/dist/index.d.ts +19 -3
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +9 -1
  55. package/dist/index.js.map +1 -1
  56. package/dist/markdown/blocks/blockquote.d.ts +11 -0
  57. package/dist/markdown/blocks/blockquote.d.ts.map +1 -0
  58. package/dist/markdown/blocks/blockquote.js +26 -0
  59. package/dist/markdown/blocks/blockquote.js.map +1 -0
  60. package/dist/markdown/blocks/flat-block.d.ts +20 -0
  61. package/dist/markdown/blocks/flat-block.d.ts.map +1 -0
  62. package/dist/markdown/blocks/flat-block.js +52 -0
  63. package/dist/markdown/blocks/flat-block.js.map +1 -0
  64. package/dist/markdown/blocks/heading.d.ts +11 -0
  65. package/dist/markdown/blocks/heading.d.ts.map +1 -0
  66. package/dist/markdown/blocks/heading.js +23 -0
  67. package/dist/markdown/blocks/heading.js.map +1 -0
  68. package/dist/markdown/blocks/horizontal-rule.d.ts +7 -0
  69. package/dist/markdown/blocks/horizontal-rule.d.ts.map +1 -0
  70. package/dist/markdown/blocks/horizontal-rule.js +5 -0
  71. package/dist/markdown/blocks/horizontal-rule.js.map +1 -0
  72. package/dist/markdown/blocks/list-line.d.ts +10 -0
  73. package/dist/markdown/blocks/list-line.d.ts.map +1 -0
  74. package/dist/markdown/blocks/list-line.js +21 -0
  75. package/dist/markdown/blocks/list-line.js.map +1 -0
  76. package/dist/markdown/blocks/paragraph.d.ts +12 -0
  77. package/dist/markdown/blocks/paragraph.d.ts.map +1 -0
  78. package/dist/markdown/blocks/paragraph.js +27 -0
  79. package/dist/markdown/blocks/paragraph.js.map +1 -0
  80. package/dist/markdown/blocks/table.d.ts +7 -0
  81. package/dist/markdown/blocks/table.d.ts.map +1 -0
  82. package/dist/markdown/blocks/table.js +30 -0
  83. package/dist/markdown/blocks/table.js.map +1 -0
  84. package/dist/markdown/chunks.d.ts +5 -0
  85. package/dist/markdown/chunks.d.ts.map +1 -0
  86. package/dist/markdown/chunks.js +29 -0
  87. package/dist/markdown/chunks.js.map +1 -0
  88. package/dist/markdown/inline.d.ts +8 -0
  89. package/dist/markdown/inline.d.ts.map +1 -0
  90. package/dist/markdown/inline.js +27 -0
  91. package/dist/markdown/inline.js.map +1 -0
  92. package/dist/markdown/links.d.ts +11 -0
  93. package/dist/markdown/links.d.ts.map +1 -0
  94. package/dist/markdown/links.js +107 -0
  95. package/dist/markdown/links.js.map +1 -0
  96. package/dist/markdown/plain-text.d.ts +4 -0
  97. package/dist/markdown/plain-text.d.ts.map +1 -0
  98. package/dist/markdown/plain-text.js +21 -0
  99. package/dist/markdown/plain-text.js.map +1 -0
  100. package/dist/markdown/tokens.d.ts +32 -0
  101. package/dist/markdown/tokens.d.ts.map +1 -0
  102. package/dist/markdown/tokens.js +25 -0
  103. package/dist/markdown/tokens.js.map +1 -0
  104. package/dist/markdown/visit-inline.d.ts +17 -0
  105. package/dist/markdown/visit-inline.d.ts.map +1 -0
  106. package/dist/markdown/visit-inline.js +61 -0
  107. package/dist/markdown/visit-inline.js.map +1 -0
  108. package/dist/markdown-blocks.d.ts.map +1 -1
  109. package/dist/markdown-blocks.js +6 -4
  110. package/dist/markdown-blocks.js.map +1 -1
  111. package/dist/markdown-images.d.ts.map +1 -1
  112. package/dist/markdown-images.js +14 -5
  113. package/dist/markdown-images.js.map +1 -1
  114. package/dist/markdown-view.d.ts +10 -32
  115. package/dist/markdown-view.d.ts.map +1 -1
  116. package/dist/markdown-view.js +9 -468
  117. package/dist/markdown-view.js.map +1 -1
  118. package/dist/mermaid.d.ts +5 -4
  119. package/dist/mermaid.d.ts.map +1 -1
  120. package/dist/mermaid.js +5 -5
  121. package/dist/mermaid.js.map +1 -1
  122. package/dist/parsers.d.ts +6 -13
  123. package/dist/parsers.d.ts.map +1 -1
  124. package/dist/parsers.js +66 -46
  125. package/dist/parsers.js.map +1 -1
  126. package/dist/row-document-renderable.d.ts +7 -6
  127. package/dist/row-document-renderable.d.ts.map +1 -1
  128. package/dist/row-document-renderable.js +2 -7
  129. package/dist/row-document-renderable.js.map +1 -1
  130. package/dist/table-types.d.ts +4 -0
  131. package/dist/table-types.d.ts.map +1 -1
  132. package/dist/table.d.ts +4 -1
  133. package/dist/table.d.ts.map +1 -1
  134. package/dist/table.js +30 -23
  135. package/dist/table.js.map +1 -1
  136. package/package.json +9 -5
  137. package/src/chooser/choose-filter.tsx +66 -0
  138. package/src/chooser/choose-highlighted-text.tsx +49 -0
  139. package/src/chooser/choose-list.tsx +159 -0
  140. package/src/chooser/choose-store.ts +147 -0
  141. package/src/chooser/chooser.tsx +80 -0
  142. package/src/chooser/fuzzy.ts +13 -0
  143. package/src/chooser/source.ts +36 -0
  144. package/src/chooser/types.ts +28 -0
  145. package/src/chooser/use-choose.ts +540 -0
  146. package/src/code-blocks.tsx +28 -26
  147. package/src/code-view.tsx +2 -1
  148. package/src/command-palette.tsx +49 -137
  149. package/src/context-menu.tsx +54 -15
  150. package/src/index.ts +46 -3
  151. package/src/markdown/blocks/blockquote.tsx +53 -0
  152. package/src/markdown/blocks/flat-block.tsx +119 -0
  153. package/src/markdown/blocks/heading.tsx +53 -0
  154. package/src/markdown/blocks/horizontal-rule.tsx +16 -0
  155. package/src/markdown/blocks/list-line.tsx +52 -0
  156. package/src/markdown/blocks/paragraph.tsx +90 -0
  157. package/src/markdown/blocks/table.tsx +55 -0
  158. package/src/markdown/chunks.ts +42 -0
  159. package/src/markdown/inline.tsx +45 -0
  160. package/src/markdown/links.ts +133 -0
  161. package/src/markdown/plain-text.ts +22 -0
  162. package/src/markdown/tokens.ts +53 -0
  163. package/src/markdown/visit-inline.ts +82 -0
  164. package/src/markdown-blocks.ts +6 -4
  165. package/src/markdown-images.ts +15 -6
  166. package/src/markdown-view.tsx +20 -845
  167. package/src/mermaid.ts +11 -9
  168. package/src/parsers.ts +86 -62
  169. package/src/row-document-renderable.ts +13 -15
  170. package/src/table-types.ts +5 -0
  171. package/src/table.tsx +36 -30
package/src/mermaid.ts CHANGED
@@ -24,6 +24,11 @@ export interface MermaidRenderOptions {
24
24
  theme?: BeautifulMermaidAsciiTheme;
25
25
  }
26
26
 
27
+ export interface AnsiStyledText {
28
+ text: string;
29
+ content: StyledText;
30
+ }
31
+
27
32
  // beautiful-mermaid's flowchart renderer uses unbounded synchronous A* pathfinding.
28
33
  // Dense graphs can therefore block the UI thread and exhaust the process heap when
29
34
  // an edge cannot be routed. Keep synchronous work within a conservative budget;
@@ -65,11 +70,11 @@ const appendStyledChunk = function appendStyledChunk(
65
70
  return;
66
71
  }
67
72
 
68
- chunks.push({
69
- __isChunk: true,
70
- text,
71
- ...(fg !== undefined && fg !== "" ? { fg: parseColor(fg) } : {}),
72
- });
73
+ const chunk: TextChunk = { __isChunk: true, text };
74
+ if (fg !== undefined && fg !== "") {
75
+ chunk.fg = parseColor(fg);
76
+ }
77
+ chunks.push(chunk);
73
78
  };
74
79
 
75
80
  const sgrParams = function sgrParams(rawParams: string): number[] {
@@ -118,10 +123,7 @@ const updateAnsiForeground = function updateAnsiForeground(
118
123
  };
119
124
 
120
125
  /** Convert beautiful-mermaid truecolor ANSI output into OpenTUI StyledText. */
121
- export const ansiToStyledText = function ansiToStyledText(input: string): {
122
- text: string;
123
- content: StyledText;
124
- } {
126
+ export const ansiToStyledText = function ansiToStyledText(input: string): AnsiStyledText {
125
127
  const chunks: TextChunk[] = [];
126
128
  let plainText = "";
127
129
  let cursor = 0;
package/src/parsers.ts CHANGED
@@ -1,25 +1,78 @@
1
1
  import type { ColumnDef, TableRow } from "./table-types.js";
2
2
 
3
- export interface ParsedTable {
3
+ export interface TableData {
4
4
  columns: ColumnDef[];
5
5
  rows: TableRow[];
6
+ }
7
+
8
+ export interface ParsedTable extends TableData {
6
9
  format: Format;
7
10
  }
8
11
 
9
- export const parseCSV = function parseCSV(input: string): {
10
- columns: ColumnDef[];
11
- rows: TableRow[];
12
- } {
13
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): parser helpers are kept below the public entry points
14
- const lines = splitLines(input);
15
- if (lines.length === 0) {
16
- return { columns: [], rows: [] };
12
+ type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
13
+
14
+ interface JsonObject {
15
+ readonly [key: string]: JsonValue | undefined;
16
+ }
17
+
18
+ const parseJsonDocument = function parseJsonDocument(input: string): JsonValue {
19
+ // SAFETY: JSON.parse without a reviver produces only values in the JsonValue grammar above.
20
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- JSON.parse is typed any; JsonValue restates the parser contract
21
+ return JSON.parse(input) as JsonValue;
22
+ };
23
+
24
+ const isJsonArray = function isJsonArray(value: JsonValue): value is JsonValue[] {
25
+ return Array.isArray(value);
26
+ };
27
+
28
+ const jsonEntryKeys = function jsonEntryKeys(value: JsonValue): string[] {
29
+ if (value === null) {
30
+ throw new TypeError("A JSON table row cannot be null");
17
31
  }
18
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): parser helpers are kept below the public entry points
19
- const columns = createColumnDefs(parseCSVLine(lines[0]));
20
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): parser helpers are kept below the public entry points
21
- const rows = buildRows(columns, lines.slice(1).map(parseCSVLine));
22
- return { columns, rows };
32
+ return Object.keys(value);
33
+ };
34
+
35
+ const readJsonEntry = function readJsonEntry(value: JsonValue, key: string): JsonValue | undefined {
36
+ if (isJsonArray(value)) {
37
+ return value[Number(key)];
38
+ }
39
+ if (value instanceof Object) {
40
+ return value[key];
41
+ }
42
+ if (Object.prototype.toString.call(value) === "[object String]") {
43
+ return String.prototype.charAt.call(value, Number(key));
44
+ }
45
+ return undefined;
46
+ };
47
+
48
+ const splitLines = function splitLines(input: string): string[] {
49
+ return input.split("\n").filter((line) => line.trim().length > 0);
50
+ };
51
+
52
+ const createColumnDefs = function createColumnDefs(rawHeaders: string[]): ColumnDef[] {
53
+ const seen = new Map<string, number>();
54
+ return rawHeaders.map((header, index) => {
55
+ const trimmed = header.trim();
56
+ const fallback = `column_${index + 1}`;
57
+ const base = trimmed === "" ? fallback : trimmed;
58
+ const count = seen.get(base) ?? 0;
59
+ seen.set(base, count + 1);
60
+ const key = count === 0 ? base : `${base}_${count + 1}`;
61
+ return {
62
+ header: trimmed || undefined,
63
+ key,
64
+ };
65
+ });
66
+ };
67
+
68
+ const buildRows = function buildRows(columns: ColumnDef[], rawRows: string[][]): TableRow[] {
69
+ return rawRows.map((row) => {
70
+ const record: TableRow = {};
71
+ for (const [index, column] of columns.entries()) {
72
+ record[column.key] = row[index] ?? "";
73
+ }
74
+ return record;
75
+ });
23
76
  };
24
77
 
25
78
  const parseCSVLine = function parseCSVLine(line: string): string[] {
@@ -63,18 +116,22 @@ const parseCSVLine = function parseCSVLine(line: string): string[] {
63
116
  return fields;
64
117
  };
65
118
 
66
- export const parseTSV = function parseTSV(input: string): {
67
- columns: ColumnDef[];
68
- rows: TableRow[];
69
- } {
70
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): parser helpers are kept below the public entry points
119
+ export const parseCSV = function parseCSV(input: string): TableData {
120
+ const lines = splitLines(input);
121
+ if (lines.length === 0) {
122
+ return { columns: [], rows: [] };
123
+ }
124
+ const columns = createColumnDefs(parseCSVLine(lines[0]));
125
+ const rows = buildRows(columns, lines.slice(1).map(parseCSVLine));
126
+ return { columns, rows };
127
+ };
128
+
129
+ export const parseTSV = function parseTSV(input: string): TableData {
71
130
  const lines = splitLines(input);
72
131
  if (lines.length === 0) {
73
132
  return { columns: [], rows: [] };
74
133
  }
75
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): parser helpers are kept below the public entry points
76
134
  const columns = createColumnDefs(lines[0].split("\t"));
77
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): parser helpers are kept below the public entry points
78
135
  const rows = buildRows(
79
136
  columns,
80
137
  lines.slice(1).map((line) => line.split("\t")),
@@ -82,20 +139,17 @@ export const parseTSV = function parseTSV(input: string): {
82
139
  return { columns, rows };
83
140
  };
84
141
 
85
- export const parseJSON = function parseJSON(input: string): {
86
- columns: ColumnDef[];
87
- rows: TableRow[];
88
- } {
89
- const data: unknown = JSON.parse(input);
90
- if (!Array.isArray(data) || data.length === 0) {
142
+ export const parseJSON = function parseJSON(input: string): TableData {
143
+ const data = parseJsonDocument(input);
144
+ if (!isJsonArray(data) || data.length === 0) {
91
145
  return { columns: [], rows: [] };
92
146
  }
93
- const keys = [...new Set(data.flatMap((item: Record<string, unknown>) => Object.keys(item)))];
147
+ const keys = [...new Set(data.flatMap(jsonEntryKeys))];
94
148
  const columns: ColumnDef[] = keys.map((key) => ({ header: key, key }));
95
- const rows = data.map((item: Record<string, unknown>) => {
149
+ const rows = data.map((item) => {
96
150
  const row: TableRow = {};
97
151
  for (const column of columns) {
98
- row[column.key] = item[column.key] ?? "";
152
+ row[column.key] = readJsonEntry(item, column.key) ?? "";
99
153
  }
100
154
  return row;
101
155
  });
@@ -108,8 +162,8 @@ export const detectFormat = function detectFormat(input: string): Format {
108
162
  const trimmed = input.trimStart();
109
163
  if (trimmed.startsWith("[")) {
110
164
  try {
111
- const parsed: unknown = JSON.parse(trimmed);
112
- if (Array.isArray(parsed)) {
165
+ const parsed = parseJsonDocument(trimmed);
166
+ if (isJsonArray(parsed)) {
113
167
  return "json";
114
168
  }
115
169
  } catch {
@@ -155,33 +209,3 @@ export const parseAuto = function parseAuto(input: string): ParsedTable {
155
209
  }
156
210
  return { columns, format, rows };
157
211
  };
158
-
159
- const splitLines = function splitLines(input: string): string[] {
160
- return input.split("\n").filter((line) => line.trim().length > 0);
161
- };
162
-
163
- const createColumnDefs = function createColumnDefs(rawHeaders: string[]): ColumnDef[] {
164
- const seen = new Map<string, number>();
165
- return rawHeaders.map((header, index) => {
166
- const trimmed = header.trim();
167
- const fallback = `column_${index + 1}`;
168
- const base = trimmed === "" ? fallback : trimmed;
169
- const count = seen.get(base) ?? 0;
170
- seen.set(base, count + 1);
171
- const key = count === 0 ? base : `${base}_${count + 1}`;
172
- return {
173
- header: trimmed || undefined,
174
- key,
175
- };
176
- });
177
- };
178
-
179
- const buildRows = function buildRows(columns: ColumnDef[], rawRows: string[][]): TableRow[] {
180
- return rawRows.map((row) => {
181
- const record: TableRow = {};
182
- for (const [index, column] of columns.entries()) {
183
- record[column.key] = row[index] ?? "";
184
- }
185
- return record;
186
- });
187
- };
@@ -4,6 +4,7 @@ import type {
4
4
  LineInfoProvider,
5
5
  ScrollBoxOptions,
6
6
  OptimizedBuffer,
7
+ Renderable,
7
8
  } from "@opentui/core";
8
9
  import type { DecorationLayer, RowDecoration } from "./decoration-layer.js";
9
10
 
@@ -18,6 +19,13 @@ export interface RowDocumentPalette {
18
19
  gutterBg?: string;
19
20
  }
20
21
 
22
+ export interface VisibleRowRange {
23
+ virtualTop: number;
24
+ virtualBottom: number;
25
+ firstRow: number;
26
+ lastRow: number;
27
+ }
28
+
21
29
  export interface RowDocumentOptions extends ScrollBoxOptions {
22
30
  mode?: "auto" | "multi" | "provider";
23
31
 
@@ -40,15 +48,10 @@ export interface RowDocumentOptions extends ScrollBoxOptions {
40
48
  // Provider detection
41
49
  // ---------------------------------------------------------------------------
42
50
 
43
- const isRowContentProvider = function isRowContentProvider(x: unknown): x is LineInfoProvider {
44
- return (
45
- x !== null &&
46
- x !== undefined &&
47
- typeof x === "object" &&
48
- "lineInfo" in x &&
49
- "lineCount" in x &&
50
- "virtualLineCount" in x
51
- );
51
+ const isRowContentProvider = function isRowContentProvider(
52
+ renderable: Renderable,
53
+ ): renderable is Renderable & LineInfoProvider {
54
+ return "lineInfo" in renderable && "lineCount" in renderable && "virtualLineCount" in renderable;
52
55
  };
53
56
 
54
57
  // ---------------------------------------------------------------------------
@@ -260,12 +263,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
260
263
  return this.getRowAtVirtualY(virtualY);
261
264
  }
262
265
 
263
- getVisibleRange(): {
264
- virtualTop: number;
265
- virtualBottom: number;
266
- firstRow: number;
267
- lastRow: number;
268
- } {
266
+ getVisibleRange(): VisibleRowRange {
269
267
  const top = Math.floor(this.scrollTop);
270
268
  const bottom = top + this.viewport.height;
271
269
  return {
@@ -4,4 +4,9 @@ export interface ColumnDef {
4
4
  align?: "left" | "right";
5
5
  }
6
6
 
7
+ /**
8
+ * One public table row. Hosts can supply any JavaScript value because the table
9
+ * formatter has long supported dates, functions, symbols, and arbitrary objects.
10
+ */
11
+ // oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- public compatibility contract; formatTableCell owns conversion of every cell value
7
12
  export type TableRow = Record<string, unknown>;
package/src/table.tsx CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import type { RowDocumentRenderable } from "./row-document-renderable.js";
11
11
  import { useGutterPalette } from "./use-gutter-palette.js";
12
12
  import "./row-document.js";
13
+ import type { ReactNode } from "react";
13
14
 
14
15
  export interface TableProps {
15
16
  columns: ColumnDef[];
@@ -141,40 +142,45 @@ const computeColumnWidths = function computeColumnWidths(
141
142
  });
142
143
  };
143
144
 
144
- const formatCellValue = function formatCellValue(value: unknown): string {
145
+ /** Convert a public table cell value to the text used for display and document actions. */
146
+ export const formatTableCell = function formatTableCell(value: TableRow[string]): string {
145
147
  if (value === null || value === undefined) {
146
148
  return "";
147
149
  }
148
- if (typeof value === "string") {
149
- return value;
150
- }
151
- if (typeof value === "number" || typeof value === "boolean") {
152
- return String(value);
153
- }
154
150
  if (value instanceof Date) {
155
151
  return value.toISOString();
156
152
  }
157
- if (typeof value === "string") {
158
- return value;
159
- }
160
- if (
161
- typeof value === "number" ||
162
- typeof value === "bigint" ||
163
- typeof value === "boolean" ||
164
- typeof value === "symbol"
165
- ) {
166
- return value.toString();
167
- }
168
- if (value === null || value === undefined) {
169
- return String(value);
170
- }
171
- if (typeof value === "function") {
172
- return Function.prototype.toString.call(value);
153
+ const valueTag = Object.prototype.toString.call(value);
154
+ switch (valueTag) {
155
+ case "[object String]": {
156
+ return String.prototype.toString.call(value);
157
+ }
158
+ case "[object Number]": {
159
+ return Number.prototype.toString.call(value);
160
+ }
161
+ case "[object BigInt]": {
162
+ return BigInt.prototype.toString.call(value);
163
+ }
164
+ case "[object Boolean]": {
165
+ return Boolean.prototype.toString.call(value);
166
+ }
167
+ case "[object Symbol]": {
168
+ return Symbol.prototype.toString.call(value);
169
+ }
170
+ case "[object Function]":
171
+ case "[object AsyncFunction]":
172
+ case "[object GeneratorFunction]":
173
+ case "[object AsyncGeneratorFunction]": {
174
+ return Function.prototype.toString.call(value);
175
+ }
176
+ default: {
177
+ break;
178
+ }
173
179
  }
174
180
  try {
175
181
  return JSON.stringify(value);
176
182
  } catch {
177
- return Array.isArray(value) ? value.join(",") : Object.prototype.toString.call(value);
183
+ return Array.isArray(value) ? value.join(",") : valueTag;
178
184
  }
179
185
  };
180
186
 
@@ -188,7 +194,7 @@ export const Table = function Table({
188
194
  showLineNumbers = true,
189
195
  document,
190
196
  columnWidthMode = "content",
191
- }: TableProps): React.ReactNode {
197
+ }: TableProps): ReactNode {
192
198
  const { theme } = useTheme();
193
199
  const palette = useGutterPalette();
194
200
  const { width: terminalWidth } = useTerminalDimensions();
@@ -212,7 +218,7 @@ export const Table = function Table({
212
218
 
213
219
  const headers = useMemo(() => columns.map((column) => column.header ?? column.key), [columns]);
214
220
  const normalizedRows = useMemo(
215
- () => rows.map((row) => columns.map((column) => formatCellValue(row[column.key]))),
221
+ () => rows.map((row) => columns.map((column) => formatTableCell(row[column.key]))),
216
222
  [columns, rows],
217
223
  );
218
224
 
@@ -255,9 +261,9 @@ export const Table = function Table({
255
261
  const rowElements = useMemo(
256
262
  () =>
257
263
  normalizedRows.map(
258
- (row, i): React.ReactNode => (
264
+ (row, i): ReactNode => (
259
265
  <box key={i} style={{ flexDirection: "row" }}>
260
- {row.map((cell, j): React.ReactNode => {
266
+ {row.map((cell, j): ReactNode => {
261
267
  const contentWidth = colWidths[j] - PADDING * 2;
262
268
  const cellWidth = Bun.stringWidth(cell);
263
269
  const displayCell =
@@ -297,7 +303,7 @@ export const Table = function Table({
297
303
  {/* Fixed header row — outside row-document so it stays visible */}
298
304
  <box style={{ flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }}>
299
305
  {headers.map(
300
- (h, i): React.ReactNode => (
306
+ (h, i): ReactNode => (
301
307
  <text
302
308
  key={i}
303
309
  content={h}
@@ -311,7 +317,7 @@ export const Table = function Table({
311
317
  {/* Fixed header underline */}
312
318
  <box style={{ flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }}>
313
319
  {colWidths.map(
314
- (w, i): React.ReactNode => (
320
+ (w, i): ReactNode => (
315
321
  <text
316
322
  key={i}
317
323
  content={"\u2500".repeat(w - PADDING * 2)}