Skip to content

Commit 7101ed1

Browse files
committed
fix(ui): satisfy table interaction gates
1 parent 3e612ff commit 7101ed1

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎ui/src/components/markdown-tables.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { t } from "../i18n/index.ts";
44
import { copyToClipboard } from "../lib/clipboard.ts";
55
import { toolIcons } from "./icons-tools.ts";
66
import { icons } from "./icons.ts";
7-
import type { MarkdownRenderEnv } from "./markdown-render-options.ts";
87
import { escapeMarkdownHtml } from "./markdown-text.ts";
98

109
const tableShellSelector = ".chat-text .markdown-table[data-table-interactions]";
@@ -19,17 +18,26 @@ type TableOwnerState = {
1918
observedViewports: Set<HTMLElement>;
2019
};
2120

21+
function tableInteractionsEnabled(env: unknown): boolean {
22+
return (
23+
typeof env === "object" &&
24+
env !== null &&
25+
"tableInteractions" in env &&
26+
env.tableInteractions === "enabled"
27+
);
28+
}
29+
2230
export function installMarkdownTables(markdownParser: MarkdownIt): void {
2331
const defaultTableOpen = markdownParser.renderer.rules.table_open;
2432
const defaultTableClose = markdownParser.renderer.rules.table_close;
2533
markdownParser.renderer.rules.table_open = (tokens, index, options, env, renderer) => {
26-
if ((env as Partial<MarkdownRenderEnv>).tableInteractions !== "enabled") {
34+
if (!tableInteractionsEnabled(env)) {
2735
return defaultTableOpen?.(tokens, index, options, env, renderer) ?? "<table>\n";
2836
}
2937
return '<div class="markdown-table" data-table-interactions><div class="markdown-table__viewport"><table>';
3038
};
3139
markdownParser.renderer.rules.table_close = (tokens, index, options, env, renderer) => {
32-
if ((env as Partial<MarkdownRenderEnv>).tableInteractions !== "enabled") {
40+
if (!tableInteractionsEnabled(env)) {
3341
return defaultTableClose?.(tokens, index, options, env, renderer) ?? "</table>\n";
3442
}
3543
return `</table></div><div class="markdown-table__actions"><button type="button" class="markdown-table__expand" aria-label="${escapeMarkdownHtml(t("common.expandTable"))}"></button><button type="button" class="markdown-table__copy" aria-label="${escapeMarkdownHtml(t("common.copyTable"))}"></button></div></div>`;

‎ui/src/pages/chat/components/chat-message.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ describe("grouped chat rendering", () => {
902902
fileLinks: true,
903903
interactiveImages: false,
904904
sessionLinks: true,
905+
tableInteractions: "enabled",
905906
});
906907
});
907908

@@ -1021,6 +1022,7 @@ describe("grouped chat rendering", () => {
10211022
fileLinks: true,
10221023
interactiveImages: false,
10231024
sessionLinks: true,
1025+
tableInteractions: "enabled",
10241026
});
10251027
});
10261028

@@ -1564,6 +1566,7 @@ describe("grouped chat rendering", () => {
15641566
fileLinks: true,
15651567
interactiveImages: false,
15661568
sessionLinks: true,
1569+
tableInteractions: "enabled",
15671570
});
15681571
const text = container.querySelector(".streaming-markdown");
15691572
expect(text?.textContent).toBe("**live**\nreply");

0 commit comments

Comments
 (0)