@tooee/renderers 0.10.1 → 0.10.3
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/chooser/choose-filter.d.ts.map +1 -1
- package/dist/chooser/choose-filter.js.map +1 -1
- package/dist/chooser/choose-highlighted-text.d.ts.map +1 -1
- package/dist/chooser/choose-highlighted-text.js.map +1 -1
- package/dist/chooser/choose-list.d.ts.map +1 -1
- package/dist/chooser/choose-list.js +5 -2
- package/dist/chooser/choose-list.js.map +1 -1
- package/dist/chooser/choose-store.d.ts.map +1 -1
- package/dist/chooser/choose-store.js.map +1 -1
- package/dist/chooser/chooser.d.ts.map +1 -1
- package/dist/chooser/chooser.js.map +1 -1
- package/dist/chooser/fuzzy.d.ts.map +1 -1
- package/dist/chooser/fuzzy.js.map +1 -1
- package/dist/chooser/use-choose.d.ts.map +1 -1
- package/dist/chooser/use-choose.js +2 -2
- package/dist/chooser/use-choose.js.map +1 -1
- package/dist/code-blocks.d.ts +2 -2
- package/dist/code-blocks.d.ts.map +1 -1
- package/dist/code-blocks.js.map +1 -1
- package/dist/code-view.d.ts +1 -1
- package/dist/code-view.d.ts.map +1 -1
- package/dist/code-view.js +1 -1
- package/dist/code-view.js.map +1 -1
- package/dist/command-palette.d.ts.map +1 -1
- package/dist/command-palette.js +2 -2
- package/dist/command-palette.js.map +1 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +1 -1
- package/dist/context-menu.js.map +1 -1
- package/dist/document-bindings.d.ts +1 -1
- package/dist/document-bindings.d.ts.map +1 -1
- package/dist/markdown/blocks/blockquote.d.ts +1 -1
- package/dist/markdown/blocks/blockquote.d.ts.map +1 -1
- package/dist/markdown/blocks/blockquote.js.map +1 -1
- package/dist/markdown/blocks/flat-block.d.ts +1 -1
- package/dist/markdown/blocks/flat-block.d.ts.map +1 -1
- package/dist/markdown/blocks/flat-block.js +2 -2
- package/dist/markdown/blocks/flat-block.js.map +1 -1
- package/dist/markdown/blocks/heading.d.ts +1 -1
- package/dist/markdown/blocks/heading.d.ts.map +1 -1
- package/dist/markdown/blocks/heading.js.map +1 -1
- package/dist/markdown/blocks/horizontal-rule.d.ts +1 -1
- package/dist/markdown/blocks/horizontal-rule.d.ts.map +1 -1
- package/dist/markdown/blocks/list-line.d.ts +1 -1
- package/dist/markdown/blocks/list-line.d.ts.map +1 -1
- package/dist/markdown/blocks/list-line.js.map +1 -1
- package/dist/markdown/blocks/paragraph.d.ts +1 -1
- package/dist/markdown/blocks/paragraph.d.ts.map +1 -1
- package/dist/markdown/blocks/paragraph.js.map +1 -1
- package/dist/markdown/blocks/table.d.ts +3 -1
- package/dist/markdown/blocks/table.d.ts.map +1 -1
- package/dist/markdown/blocks/table.js +5 -3
- package/dist/markdown/blocks/table.js.map +1 -1
- package/dist/markdown/chunks.d.ts +1 -1
- package/dist/markdown/chunks.d.ts.map +1 -1
- package/dist/markdown/chunks.js +1 -1
- package/dist/markdown/chunks.js.map +1 -1
- package/dist/markdown/inline.d.ts +1 -1
- package/dist/markdown/inline.d.ts.map +1 -1
- package/dist/markdown/inline.js.map +1 -1
- package/dist/markdown/links.d.ts +1 -1
- package/dist/markdown/links.d.ts.map +1 -1
- package/dist/markdown/links.js.map +1 -1
- package/dist/markdown/plain-text.d.ts.map +1 -1
- package/dist/markdown/plain-text.js.map +1 -1
- package/dist/markdown/table-links.d.ts +10 -0
- package/dist/markdown/table-links.d.ts.map +1 -0
- package/dist/markdown/table-links.js +47 -0
- package/dist/markdown/table-links.js.map +1 -0
- package/dist/markdown/visit-inline.d.ts.map +1 -1
- package/dist/markdown/visit-inline.js.map +1 -1
- package/dist/markdown-blocks.d.ts +2 -0
- package/dist/markdown-blocks.d.ts.map +1 -1
- package/dist/markdown-blocks.js +3 -1
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-images.d.ts.map +1 -1
- package/dist/markdown-images.js.map +1 -1
- package/dist/markdown-view.d.ts +1 -1
- package/dist/markdown-view.d.ts.map +1 -1
- package/dist/markdown-view.js +1 -1
- package/dist/markdown-view.js.map +1 -1
- package/dist/mermaid.d.ts.map +1 -1
- package/dist/mermaid.js +1 -1
- package/dist/mermaid.js.map +1 -1
- package/dist/row-document-renderable.d.ts.map +1 -1
- package/dist/row-document-renderable.js.map +1 -1
- package/dist/row-document.d.ts.map +1 -1
- package/dist/row-document.js.map +1 -1
- package/dist/table.d.ts +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +1 -1
- package/dist/table.js.map +1 -1
- package/dist/text-table-internals.d.ts +34 -0
- package/dist/text-table-internals.d.ts.map +1 -0
- package/dist/text-table-internals.js +68 -0
- package/dist/text-table-internals.js.map +1 -0
- package/dist/text-table.d.ts.map +1 -1
- package/dist/text-table.js +1 -1
- package/dist/text-table.js.map +1 -1
- package/dist/use-gutter-palette.d.ts.map +1 -1
- package/dist/use-gutter-palette.js +1 -1
- package/dist/use-gutter-palette.js.map +1 -1
- package/package.json +15 -15
- package/src/chooser/choose-filter.tsx +2 -1
- package/src/chooser/choose-highlighted-text.tsx +5 -7
- package/src/chooser/choose-list.tsx +7 -4
- package/src/chooser/choose-store.ts +2 -1
- package/src/chooser/chooser.tsx +2 -1
- package/src/chooser/fuzzy.ts +1 -0
- package/src/chooser/source.ts +1 -1
- package/src/chooser/use-choose.ts +11 -10
- package/src/code-blocks.tsx +6 -5
- package/src/code-view.tsx +3 -2
- package/src/command-palette.tsx +5 -4
- package/src/context-menu.tsx +29 -31
- package/src/document-bindings.ts +2 -1
- package/src/markdown/blocks/blockquote.tsx +2 -1
- package/src/markdown/blocks/flat-block.tsx +5 -4
- package/src/markdown/blocks/heading.tsx +3 -2
- package/src/markdown/blocks/horizontal-rule.tsx +1 -1
- package/src/markdown/blocks/list-line.tsx +3 -2
- package/src/markdown/blocks/paragraph.tsx +14 -14
- package/src/markdown/blocks/table.tsx +14 -4
- package/src/markdown/chunks.ts +7 -4
- package/src/markdown/inline.tsx +2 -1
- package/src/markdown/links.ts +5 -4
- package/src/markdown/plain-text.ts +1 -0
- package/src/markdown/table-links.ts +58 -0
- package/src/markdown/tokens.ts +1 -1
- package/src/markdown/visit-inline.ts +2 -1
- package/src/markdown-blocks.ts +8 -5
- package/src/markdown-images.ts +5 -4
- package/src/markdown-view.tsx +20 -21
- package/src/mermaid.ts +9 -9
- package/src/parsers.ts +1 -1
- package/src/row-document-renderable.ts +8 -7
- package/src/row-document.ts +1 -0
- package/src/source.ts +1 -1
- package/src/table.tsx +54 -59
- package/src/text-table-internals.ts +124 -0
- package/src/text-table.ts +1 -1
- package/src/use-gutter-palette.ts +3 -2
package/src/mermaid.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { parseMermaid, renderMermaidASCII } from "beautiful-mermaid";
|
|
2
1
|
import { parseColor, StyledText } from "@opentui/core";
|
|
3
2
|
import type { TextChunk } from "@opentui/core";
|
|
3
|
+
import { parseMermaid, renderMermaidASCII } from "beautiful-mermaid";
|
|
4
4
|
|
|
5
5
|
interface BeautifulMermaidAsciiTheme {
|
|
6
6
|
fg?: string;
|
|
@@ -52,7 +52,7 @@ export const isMermaidFence = function isMermaidFence(lang?: string): boolean {
|
|
|
52
52
|
const hasDirectedPath = function hasDirectedPath(
|
|
53
53
|
adjacency: Map<string, Set<string>>,
|
|
54
54
|
source: string,
|
|
55
|
-
target: string
|
|
55
|
+
target: string
|
|
56
56
|
): boolean {
|
|
57
57
|
const pending = [...(adjacency.get(source) ?? [])];
|
|
58
58
|
const visited = new Set<string>([source]);
|
|
@@ -77,7 +77,7 @@ const hasDirectedPath = function hasDirectedPath(
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
const hasUnsafeCyclicFanTopology = function hasUnsafeCyclicFanTopology(
|
|
80
|
-
edges: ReturnType<typeof parseMermaid>["edges"]
|
|
80
|
+
edges: ReturnType<typeof parseMermaid>["edges"]
|
|
81
81
|
): boolean {
|
|
82
82
|
const adjacency = new Map<string, Set<string>>();
|
|
83
83
|
const incomingDegree = new Map<string, number>();
|
|
@@ -101,13 +101,13 @@ const hasUnsafeCyclicFanTopology = function hasUnsafeCyclicFanTopology(
|
|
|
101
101
|
return fanInNodes.some((fanIn) =>
|
|
102
102
|
fanOutNodes.some(
|
|
103
103
|
(fanOut) =>
|
|
104
|
-
hasDirectedPath(adjacency, fanIn, fanOut) && hasDirectedPath(adjacency, fanOut, fanIn)
|
|
105
|
-
)
|
|
104
|
+
hasDirectedPath(adjacency, fanIn, fanOut) && hasDirectedPath(adjacency, fanOut, fanIn)
|
|
105
|
+
)
|
|
106
106
|
);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
const exceedsSynchronousRenderBudget = function exceedsSynchronousRenderBudget(
|
|
110
|
-
source: string
|
|
110
|
+
source: string
|
|
111
111
|
): boolean {
|
|
112
112
|
if (source.length > MAX_SOURCE_LENGTH || source.split("\n").length > MAX_SOURCE_LINES) {
|
|
113
113
|
return true;
|
|
@@ -127,7 +127,7 @@ const exceedsSynchronousRenderBudget = function exceedsSynchronousRenderBudget(
|
|
|
127
127
|
const appendStyledChunk = function appendStyledChunk(
|
|
128
128
|
chunks: TextChunk[],
|
|
129
129
|
text: string,
|
|
130
|
-
fg?: string
|
|
130
|
+
fg?: string
|
|
131
131
|
) {
|
|
132
132
|
if (text.length === 0) {
|
|
133
133
|
return;
|
|
@@ -149,7 +149,7 @@ const sgrParams = function sgrParams(rawParams: string): number[] {
|
|
|
149
149
|
|
|
150
150
|
const updateAnsiForeground = function updateAnsiForeground(
|
|
151
151
|
params: number[],
|
|
152
|
-
currentFg: string | undefined
|
|
152
|
+
currentFg: string | undefined
|
|
153
153
|
): string | undefined {
|
|
154
154
|
let fg = currentFg;
|
|
155
155
|
|
|
@@ -216,7 +216,7 @@ export const ansiToStyledText = function ansiToStyledText(input: string): AnsiSt
|
|
|
216
216
|
*/
|
|
217
217
|
export const renderMermaidForTerminal = function renderMermaidForTerminal(
|
|
218
218
|
source: string,
|
|
219
|
-
options: MermaidRenderOptions = {}
|
|
219
|
+
options: MermaidRenderOptions = {}
|
|
220
220
|
): MermaidRenderResult {
|
|
221
221
|
if (source.trim().length === 0) {
|
|
222
222
|
return { message: "Mermaid block is empty", ok: false, reason: "empty" };
|
package/src/parsers.ts
CHANGED
|
@@ -134,7 +134,7 @@ export const parseTSV = function parseTSV(input: string): TableData {
|
|
|
134
134
|
const columns = createColumnDefs(lines[0].split("\t"));
|
|
135
135
|
const rows = buildRows(
|
|
136
136
|
columns,
|
|
137
|
-
lines.slice(1).map((line) => line.split("\t"))
|
|
137
|
+
lines.slice(1).map((line) => line.split("\t"))
|
|
138
138
|
);
|
|
139
139
|
return { columns, rows };
|
|
140
140
|
};
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
OptimizedBuffer,
|
|
7
7
|
Renderable,
|
|
8
8
|
} from "@opentui/core";
|
|
9
|
+
|
|
9
10
|
import type { DecorationLayer, RowDecoration } from "./decoration-layer.js";
|
|
10
11
|
|
|
11
12
|
// ---------------------------------------------------------------------------
|
|
@@ -49,7 +50,7 @@ export interface RowDocumentOptions extends ScrollBoxOptions {
|
|
|
49
50
|
// ---------------------------------------------------------------------------
|
|
50
51
|
|
|
51
52
|
const isRowContentProvider = function isRowContentProvider(
|
|
52
|
-
renderable: Renderable
|
|
53
|
+
renderable: Renderable
|
|
53
54
|
): renderable is Renderable & LineInfoProvider {
|
|
54
55
|
return "lineInfo" in renderable && "lineCount" in renderable && "virtualLineCount" in renderable;
|
|
55
56
|
};
|
|
@@ -70,7 +71,7 @@ const cachedColor = function cachedColor(hex: string): RGBA {
|
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
const normalizePalette = function normalizePalette(
|
|
73
|
-
palette: RowDocumentPalette = {}
|
|
74
|
+
palette: RowDocumentPalette = {}
|
|
74
75
|
): Required<RowDocumentPalette> {
|
|
75
76
|
return {
|
|
76
77
|
gutterBg: palette.gutterBg ?? "#0d1117",
|
|
@@ -79,7 +80,7 @@ const normalizePalette = function normalizePalette(
|
|
|
79
80
|
};
|
|
80
81
|
|
|
81
82
|
const normalizeDecorationLayers = function normalizeDecorationLayers(
|
|
82
|
-
layers: readonly DecorationLayer[] | undefined
|
|
83
|
+
layers: readonly DecorationLayer[] | undefined
|
|
83
84
|
): readonly DecorationLayer[] {
|
|
84
85
|
if (!layers || layers.length === 0) {
|
|
85
86
|
return [];
|
|
@@ -433,7 +434,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
433
434
|
rowVirtualHeights,
|
|
434
435
|
virtualRowToRow,
|
|
435
436
|
virtualRowWraps,
|
|
436
|
-
rowCount
|
|
437
|
+
rowCount
|
|
437
438
|
);
|
|
438
439
|
}
|
|
439
440
|
|
|
@@ -485,7 +486,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
485
486
|
rowVirtualHeights,
|
|
486
487
|
virtualRowToRow,
|
|
487
488
|
virtualRowWraps,
|
|
488
|
-
rowCount
|
|
489
|
+
rowCount
|
|
489
490
|
);
|
|
490
491
|
}
|
|
491
492
|
|
|
@@ -494,7 +495,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
494
495
|
rowVirtualHeights: number[],
|
|
495
496
|
virtualRowToRow: number[],
|
|
496
497
|
virtualRowWraps: number[],
|
|
497
|
-
rowCount: number
|
|
498
|
+
rowCount: number
|
|
498
499
|
): void {
|
|
499
500
|
let contentVirtualEnd = 0;
|
|
500
501
|
for (let row = 0; row < rowCount; row += 1) {
|
|
@@ -669,7 +670,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
669
670
|
drawX + col,
|
|
670
671
|
vpY + screenY,
|
|
671
672
|
signFg,
|
|
672
|
-
effectiveGutterBg
|
|
673
|
+
effectiveGutterBg
|
|
673
674
|
);
|
|
674
675
|
}
|
|
675
676
|
}
|
package/src/row-document.ts
CHANGED
package/src/source.ts
CHANGED
|
@@ -175,7 +175,7 @@ export interface SourceLineRow {
|
|
|
175
175
|
*/
|
|
176
176
|
export const sourceLines = function sourceLines(
|
|
177
177
|
source: string,
|
|
178
|
-
options?: { sourceId?: string }
|
|
178
|
+
options?: { sourceId?: string }
|
|
179
179
|
): SourceLineRow[] {
|
|
180
180
|
const index = new SourceIndex(source, options?.sourceId);
|
|
181
181
|
const rows: SourceLineRow[] = [];
|
package/src/table.tsx
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { useTerminalDimensions } from "@opentui/react";
|
|
2
2
|
import { useTheme } from "@tooee/themes";
|
|
3
3
|
import { useMemo, useRef } from "react";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
|
|
4
6
|
import type { DocumentBindings } from "./document-bindings.js";
|
|
5
|
-
import type { ColumnDef, TableRow } from "./table-types.js";
|
|
6
7
|
import {
|
|
7
8
|
DEFAULT_SIGN_COLUMN_WIDTH,
|
|
8
9
|
computeRowDocumentGutterWidth,
|
|
9
10
|
} from "./row-document-renderable.js";
|
|
10
11
|
import type { RowDocumentRenderable } from "./row-document-renderable.js";
|
|
11
|
-
import {
|
|
12
|
+
import type { ColumnDef, TableRow } from "./table-types.js";
|
|
12
13
|
import "./row-document.js";
|
|
13
|
-
import
|
|
14
|
+
import { useGutterPalette } from "./use-gutter-palette.js";
|
|
14
15
|
|
|
15
16
|
export interface TableProps {
|
|
16
17
|
columns: ColumnDef[];
|
|
@@ -70,7 +71,7 @@ const computeColumnWidths = function computeColumnWidths(
|
|
|
70
71
|
headers: string[],
|
|
71
72
|
rows: string[][],
|
|
72
73
|
maxWidth: number,
|
|
73
|
-
options: ColumnWidthOptions
|
|
74
|
+
options: ColumnWidthOptions
|
|
74
75
|
): number[] {
|
|
75
76
|
const { minColumnWidth, maxColumnWidth, sampleSize } = options;
|
|
76
77
|
const colCount = headers.length;
|
|
@@ -116,7 +117,7 @@ const computeColumnWidths = function computeColumnWidths(
|
|
|
116
117
|
// Extreme case: not even minimum widths fit
|
|
117
118
|
if (maxWidth <= colCount * minColWidthWithPadding) {
|
|
118
119
|
return naturalWidths.map(() =>
|
|
119
|
-
Math.max(minColWidthWithPadding, Math.floor(available / colCount))
|
|
120
|
+
Math.max(minColWidthWithPadding, Math.floor(available / colCount))
|
|
120
121
|
);
|
|
121
122
|
}
|
|
122
123
|
|
|
@@ -130,7 +131,7 @@ const computeColumnWidths = function computeColumnWidths(
|
|
|
130
131
|
// All compact or no space left -- distribute evenly
|
|
131
132
|
const total = naturalWidths.reduce((a, b) => a + b, 0);
|
|
132
133
|
return naturalWidths.map((w) =>
|
|
133
|
-
Math.max(minColWidthWithPadding, Math.floor((w / total) * available))
|
|
134
|
+
Math.max(minColWidthWithPadding, Math.floor((w / total) * available))
|
|
134
135
|
);
|
|
135
136
|
}
|
|
136
137
|
|
|
@@ -209,17 +210,17 @@ export const Table = function Table({
|
|
|
209
210
|
showLineNumbers,
|
|
210
211
|
signColumnWidth: DEFAULT_SIGN_COLUMN_WIDTH,
|
|
211
212
|
}),
|
|
212
|
-
[showLineNumbers, rows.length]
|
|
213
|
+
[showLineNumbers, rows.length]
|
|
213
214
|
);
|
|
214
215
|
const effectiveMaxWidth = Math.max(
|
|
215
216
|
0,
|
|
216
|
-
(maxWidth ?? terminalWidth) - TABLE_MARGIN * 2 - gutterWidth
|
|
217
|
+
(maxWidth ?? terminalWidth) - TABLE_MARGIN * 2 - gutterWidth
|
|
217
218
|
);
|
|
218
219
|
|
|
219
220
|
const headers = useMemo(() => columns.map((column) => column.header ?? column.key), [columns]);
|
|
220
221
|
const normalizedRows = useMemo(
|
|
221
222
|
() => rows.map((row) => columns.map((column) => formatTableCell(row[column.key]))),
|
|
222
|
-
[columns, rows]
|
|
223
|
+
[columns, rows]
|
|
223
224
|
);
|
|
224
225
|
|
|
225
226
|
const colWidths = useMemo(
|
|
@@ -238,7 +239,7 @@ export const Table = function Table({
|
|
|
238
239
|
maxColumnWidth,
|
|
239
240
|
sampleSize,
|
|
240
241
|
columnWidthMode,
|
|
241
|
-
]
|
|
242
|
+
]
|
|
242
243
|
);
|
|
243
244
|
|
|
244
245
|
// Detect right-aligned columns: explicit align prop or auto-detect numeric
|
|
@@ -255,39 +256,37 @@ export const Table = function Table({
|
|
|
255
256
|
const numericCount = sampleValues.filter(isNumeric).length;
|
|
256
257
|
return numericCount > sampleValues.length / 2;
|
|
257
258
|
}),
|
|
258
|
-
[columns, normalizedRows]
|
|
259
|
+
[columns, normalizedRows]
|
|
259
260
|
);
|
|
260
261
|
|
|
261
262
|
const rowElements = useMemo(
|
|
262
263
|
() =>
|
|
263
|
-
normalizedRows.map(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
),
|
|
290
|
-
[normalizedRows, colWidths, alignments, theme.text],
|
|
264
|
+
normalizedRows.map((row, i): ReactNode => (
|
|
265
|
+
<box key={i} style={{ flexDirection: "row" }}>
|
|
266
|
+
{row.map((cell, j): ReactNode => {
|
|
267
|
+
const contentWidth = colWidths[j] - PADDING * 2;
|
|
268
|
+
const cellWidth = Bun.stringWidth(cell);
|
|
269
|
+
const displayCell =
|
|
270
|
+
alignments[j] && cellWidth <= contentWidth
|
|
271
|
+
? " ".repeat(contentWidth - cellWidth) + cell
|
|
272
|
+
: cell;
|
|
273
|
+
return (
|
|
274
|
+
<text
|
|
275
|
+
key={j}
|
|
276
|
+
content={displayCell}
|
|
277
|
+
wrapMode="word"
|
|
278
|
+
style={{
|
|
279
|
+
paddingLeft: PADDING,
|
|
280
|
+
paddingRight: PADDING,
|
|
281
|
+
width: colWidths[j],
|
|
282
|
+
}}
|
|
283
|
+
fg={theme.text}
|
|
284
|
+
/>
|
|
285
|
+
);
|
|
286
|
+
})}
|
|
287
|
+
</box>
|
|
288
|
+
)),
|
|
289
|
+
[normalizedRows, colWidths, alignments, theme.text]
|
|
291
290
|
);
|
|
292
291
|
|
|
293
292
|
return (
|
|
@@ -302,30 +301,26 @@ export const Table = function Table({
|
|
|
302
301
|
>
|
|
303
302
|
{/* Fixed header row — outside row-document so it stays visible */}
|
|
304
303
|
<box style={{ flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }}>
|
|
305
|
-
{headers.map(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
),
|
|
314
|
-
)}
|
|
304
|
+
{headers.map((h, i): ReactNode => (
|
|
305
|
+
<text
|
|
306
|
+
key={i}
|
|
307
|
+
content={h}
|
|
308
|
+
style={{ paddingLeft: PADDING, paddingRight: PADDING, width: colWidths[i] }}
|
|
309
|
+
fg={theme.primary}
|
|
310
|
+
/>
|
|
311
|
+
))}
|
|
315
312
|
</box>
|
|
316
313
|
|
|
317
314
|
{/* Fixed header underline */}
|
|
318
315
|
<box style={{ flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }}>
|
|
319
|
-
{colWidths.map(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
),
|
|
328
|
-
)}
|
|
316
|
+
{colWidths.map((w, i): ReactNode => (
|
|
317
|
+
<text
|
|
318
|
+
key={i}
|
|
319
|
+
content={"\u2500".repeat(w - PADDING * 2)}
|
|
320
|
+
style={{ paddingLeft: PADDING, paddingRight: PADDING, width: w }}
|
|
321
|
+
fg={theme.border}
|
|
322
|
+
/>
|
|
323
|
+
))}
|
|
329
324
|
</box>
|
|
330
325
|
|
|
331
326
|
{/* Scrollable data rows */}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { TextBufferView } from "@opentui/core";
|
|
2
|
+
import type { Renderable } from "@opentui/core";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* OpenTUI 0.5.12 has no public cell hit test for `TextTableRenderable`. This module is the only
|
|
6
|
+
* place that reads its private members, the `_layout` arrays and the `_cells` text views. It reads
|
|
7
|
+
* the layout of the last render, which is the layout the user clicked on.
|
|
8
|
+
* `test/text-table-internals.test.tsx` fails when OpenTUI renames or reshapes these members.
|
|
9
|
+
* Replace this module when OpenTUI exposes a public hit test.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface TextTableInternals {
|
|
13
|
+
readonly cellPaddingX: number;
|
|
14
|
+
readonly cellPaddingY: number;
|
|
15
|
+
readonly _layout: {
|
|
16
|
+
readonly columnOffsets: readonly number[];
|
|
17
|
+
readonly columnWidths: readonly number[];
|
|
18
|
+
readonly rowHeights: readonly number[];
|
|
19
|
+
readonly rowOffsets: readonly number[];
|
|
20
|
+
};
|
|
21
|
+
readonly _cells: readonly (readonly (
|
|
22
|
+
| { readonly textBufferView: TextBufferView }
|
|
23
|
+
| undefined
|
|
24
|
+
)[])[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Private `TextTableRenderable` members that the cell hit test reads. */
|
|
28
|
+
export const hasTextTableInternals = function hasTextTableInternals(
|
|
29
|
+
table: Renderable
|
|
30
|
+
): table is Renderable & TextTableInternals {
|
|
31
|
+
if (
|
|
32
|
+
!("_layout" in table && "_cells" in table && "cellPaddingX" in table && "cellPaddingY" in table)
|
|
33
|
+
) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const { _layout: layout } = table;
|
|
37
|
+
return (
|
|
38
|
+
Array.isArray(table._cells) &&
|
|
39
|
+
Number.isInteger(table.cellPaddingX) &&
|
|
40
|
+
Number.isInteger(table.cellPaddingY) &&
|
|
41
|
+
layout instanceof Object &&
|
|
42
|
+
"columnOffsets" in layout &&
|
|
43
|
+
"columnWidths" in layout &&
|
|
44
|
+
"rowHeights" in layout &&
|
|
45
|
+
"rowOffsets" in layout &&
|
|
46
|
+
Array.isArray(layout.columnOffsets) &&
|
|
47
|
+
Array.isArray(layout.columnWidths) &&
|
|
48
|
+
Array.isArray(layout.rowHeights) &&
|
|
49
|
+
Array.isArray(layout.rowOffsets)
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
interface Span {
|
|
54
|
+
index: number;
|
|
55
|
+
/** Distance from the first cell of the span. */
|
|
56
|
+
inside: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Find the row or column that holds a local coordinate. Each offset marks the border or gap
|
|
61
|
+
* before its span, so the span starts one cell later. This matches OpenTUI's own private
|
|
62
|
+
* `getCellAtLocalPosition`.
|
|
63
|
+
*/
|
|
64
|
+
const spanAt = function spanAt(
|
|
65
|
+
offsets: readonly number[],
|
|
66
|
+
sizes: readonly number[],
|
|
67
|
+
local: number
|
|
68
|
+
): Span | null {
|
|
69
|
+
for (const [index, size] of sizes.entries()) {
|
|
70
|
+
const inside = local - (offsets[index] ?? 0) - 1;
|
|
71
|
+
if (inside >= 0 && inside < size) {
|
|
72
|
+
return { index, inside };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** A pointer position inside one table cell, in the cell's own text coordinates. */
|
|
79
|
+
export interface TextTableCellHit {
|
|
80
|
+
row: number;
|
|
81
|
+
column: number;
|
|
82
|
+
/** Logical line inside the cell text. */
|
|
83
|
+
line: number;
|
|
84
|
+
/** Display column inside that logical line. */
|
|
85
|
+
offset: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Map a screen position to a cell of a rendered text table and to a text position in that cell.
|
|
90
|
+
* Wrapped cells map each visual line back to its logical line. Returns null for borders, padding,
|
|
91
|
+
* and blank space after the text on a line.
|
|
92
|
+
*/
|
|
93
|
+
export const textTableCellAt = function textTableCellAt(
|
|
94
|
+
table: Renderable,
|
|
95
|
+
x: number,
|
|
96
|
+
y: number
|
|
97
|
+
): TextTableCellHit | null {
|
|
98
|
+
if (!hasTextTableInternals(table)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const { columnOffsets, columnWidths, rowHeights, rowOffsets } = table._layout;
|
|
102
|
+
const row = spanAt(rowOffsets, rowHeights, y - table.y);
|
|
103
|
+
const column = spanAt(columnOffsets, columnWidths, x - table.x);
|
|
104
|
+
if (row === null || column === null) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const view = table._cells[row.index]?.[column.index]?.textBufferView;
|
|
108
|
+
if (!(view instanceof TextBufferView)) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const cellX = column.inside - table.cellPaddingX;
|
|
112
|
+
const visualLine = row.inside - table.cellPaddingY;
|
|
113
|
+
const { lineSources, lineStartCols, lineWidthCols } = view.lineInfo;
|
|
114
|
+
const line = lineSources[visualLine];
|
|
115
|
+
const start = lineStartCols[visualLine];
|
|
116
|
+
const width = lineWidthCols[visualLine];
|
|
117
|
+
if (line === undefined || start === undefined || width === undefined) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
if (cellX < 0 || cellX >= width) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return { column: column.index, line, offset: start + cellX, row: row.index };
|
|
124
|
+
};
|
package/src/text-table.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
1
|
import { useTheme } from "@tooee/themes";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
|
|
3
4
|
import type { RowDocumentPalette } from "./row-document-renderable.js";
|
|
4
5
|
|
|
5
6
|
export const useGutterPalette = function useGutterPalette(): RowDocumentPalette {
|
|
@@ -10,6 +11,6 @@ export const useGutterPalette = function useGutterPalette(): RowDocumentPalette
|
|
|
10
11
|
gutterBg: theme.backgroundElement,
|
|
11
12
|
gutterFg: theme.textMuted,
|
|
12
13
|
}),
|
|
13
|
-
[theme.textMuted, theme.backgroundElement]
|
|
14
|
+
[theme.textMuted, theme.backgroundElement]
|
|
14
15
|
);
|
|
15
16
|
};
|