@tooee/renderers 0.7.2 → 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/dist/code-blocks.d.ts +2 -1
- package/dist/code-blocks.d.ts.map +1 -1
- package/dist/code-blocks.js +20 -18
- package/dist/code-blocks.js.map +1 -1
- package/dist/code-view.d.ts +2 -1
- package/dist/code-view.d.ts.map +1 -1
- package/dist/code-view.js.map +1 -1
- package/dist/command-palette.d.ts +2 -1
- package/dist/command-palette.d.ts.map +1 -1
- package/dist/command-palette.js +16 -23
- package/dist/command-palette.js.map +1 -1
- package/dist/context-menu.d.ts +2 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +50 -15
- package/dist/context-menu.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown/blocks/blockquote.d.ts +11 -0
- package/dist/markdown/blocks/blockquote.d.ts.map +1 -0
- package/dist/markdown/blocks/blockquote.js +26 -0
- package/dist/markdown/blocks/blockquote.js.map +1 -0
- package/dist/markdown/blocks/flat-block.d.ts +20 -0
- package/dist/markdown/blocks/flat-block.d.ts.map +1 -0
- package/dist/markdown/blocks/flat-block.js +52 -0
- package/dist/markdown/blocks/flat-block.js.map +1 -0
- package/dist/markdown/blocks/heading.d.ts +11 -0
- package/dist/markdown/blocks/heading.d.ts.map +1 -0
- package/dist/markdown/blocks/heading.js +23 -0
- package/dist/markdown/blocks/heading.js.map +1 -0
- package/dist/markdown/blocks/horizontal-rule.d.ts +7 -0
- package/dist/markdown/blocks/horizontal-rule.d.ts.map +1 -0
- package/dist/markdown/blocks/horizontal-rule.js +5 -0
- package/dist/markdown/blocks/horizontal-rule.js.map +1 -0
- package/dist/markdown/blocks/list-line.d.ts +10 -0
- package/dist/markdown/blocks/list-line.d.ts.map +1 -0
- package/dist/markdown/blocks/list-line.js +21 -0
- package/dist/markdown/blocks/list-line.js.map +1 -0
- package/dist/markdown/blocks/paragraph.d.ts +12 -0
- package/dist/markdown/blocks/paragraph.d.ts.map +1 -0
- package/dist/markdown/blocks/paragraph.js +27 -0
- package/dist/markdown/blocks/paragraph.js.map +1 -0
- package/dist/markdown/blocks/table.d.ts +7 -0
- package/dist/markdown/blocks/table.d.ts.map +1 -0
- package/dist/markdown/blocks/table.js +30 -0
- package/dist/markdown/blocks/table.js.map +1 -0
- package/dist/markdown/chunks.d.ts +5 -0
- package/dist/markdown/chunks.d.ts.map +1 -0
- package/dist/markdown/chunks.js +29 -0
- package/dist/markdown/chunks.js.map +1 -0
- package/dist/markdown/inline.d.ts +8 -0
- package/dist/markdown/inline.d.ts.map +1 -0
- package/dist/markdown/inline.js +27 -0
- package/dist/markdown/inline.js.map +1 -0
- package/dist/markdown/links.d.ts +11 -0
- package/dist/markdown/links.d.ts.map +1 -0
- package/dist/markdown/links.js +107 -0
- package/dist/markdown/links.js.map +1 -0
- package/dist/markdown/plain-text.d.ts +4 -0
- package/dist/markdown/plain-text.d.ts.map +1 -0
- package/dist/markdown/plain-text.js +21 -0
- package/dist/markdown/plain-text.js.map +1 -0
- package/dist/markdown/tokens.d.ts +32 -0
- package/dist/markdown/tokens.d.ts.map +1 -0
- package/dist/markdown/tokens.js +25 -0
- package/dist/markdown/tokens.js.map +1 -0
- package/dist/markdown/visit-inline.d.ts +17 -0
- package/dist/markdown/visit-inline.d.ts.map +1 -0
- package/dist/markdown/visit-inline.js +61 -0
- package/dist/markdown/visit-inline.js.map +1 -0
- package/dist/markdown-blocks.d.ts.map +1 -1
- package/dist/markdown-blocks.js +6 -4
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-images.d.ts.map +1 -1
- package/dist/markdown-images.js +14 -5
- package/dist/markdown-images.js.map +1 -1
- package/dist/markdown-view.d.ts +10 -32
- package/dist/markdown-view.d.ts.map +1 -1
- package/dist/markdown-view.js +9 -468
- package/dist/markdown-view.js.map +1 -1
- package/dist/mermaid.d.ts +5 -4
- package/dist/mermaid.d.ts.map +1 -1
- package/dist/mermaid.js +5 -5
- package/dist/mermaid.js.map +1 -1
- package/dist/parsers.d.ts +6 -13
- package/dist/parsers.d.ts.map +1 -1
- package/dist/parsers.js +66 -46
- package/dist/parsers.js.map +1 -1
- package/dist/row-document-renderable.d.ts +7 -6
- package/dist/row-document-renderable.d.ts.map +1 -1
- package/dist/row-document-renderable.js +2 -7
- package/dist/row-document-renderable.js.map +1 -1
- package/dist/table-types.d.ts +4 -0
- package/dist/table-types.d.ts.map +1 -1
- package/dist/table.d.ts +4 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +30 -23
- package/dist/table.js.map +1 -1
- package/package.json +7 -5
- package/src/code-blocks.tsx +28 -26
- package/src/code-view.tsx +2 -1
- package/src/command-palette.tsx +46 -31
- package/src/context-menu.tsx +54 -15
- package/src/index.ts +7 -3
- package/src/markdown/blocks/blockquote.tsx +53 -0
- package/src/markdown/blocks/flat-block.tsx +119 -0
- package/src/markdown/blocks/heading.tsx +53 -0
- package/src/markdown/blocks/horizontal-rule.tsx +16 -0
- package/src/markdown/blocks/list-line.tsx +52 -0
- package/src/markdown/blocks/paragraph.tsx +90 -0
- package/src/markdown/blocks/table.tsx +55 -0
- package/src/markdown/chunks.ts +42 -0
- package/src/markdown/inline.tsx +45 -0
- package/src/markdown/links.ts +133 -0
- package/src/markdown/plain-text.ts +22 -0
- package/src/markdown/tokens.ts +53 -0
- package/src/markdown/visit-inline.ts +82 -0
- package/src/markdown-blocks.ts +6 -4
- package/src/markdown-images.ts +15 -6
- package/src/markdown-view.tsx +20 -845
- package/src/mermaid.ts +11 -9
- package/src/parsers.ts +86 -62
- package/src/row-document-renderable.ts +13 -15
- package/src/table-types.ts +5 -0
- 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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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(
|
|
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
|
|
149
|
+
const rows = data.map((item) => {
|
|
96
150
|
const row: TableRow = {};
|
|
97
151
|
for (const column of columns) {
|
|
98
|
-
row[column.key] = item
|
|
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
|
|
112
|
-
if (
|
|
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(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 {
|
package/src/table-types.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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(",") :
|
|
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):
|
|
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) =>
|
|
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):
|
|
264
|
+
(row, i): ReactNode => (
|
|
259
265
|
<box key={i} style={{ flexDirection: "row" }}>
|
|
260
|
-
{row.map((cell, j):
|
|
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):
|
|
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):
|
|
320
|
+
(w, i): ReactNode => (
|
|
315
321
|
<text
|
|
316
322
|
key={i}
|
|
317
323
|
content={"\u2500".repeat(w - PADDING * 2)}
|