Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Chat: a reply's prose runs to the same edge as its wide table
luishron12377c988bc4c3f
diff --git a/src/components/ReplyBlocks.tsx b/src/components/ReplyBlocks.tsxindex 8b2e0e842a..b0be774b34 100644--- a/src/components/ReplyBlocks.tsx+++ b/src/components/ReplyBlocks.tsx@@ -5,7 +5,8 @@ import type { ReplyBlock } from "@/lib/formatted-reply";import { joinedCorners, SIMPLE_BOT_BUBBLE, type BubbleJoin } from "./chat-bubble";/** Simple mode's reply with tables: one bubble holding the prose and each table in order. The bubble may grow to the- * message's card width so a table's columns show; its prose keeps the reading width. The hover tray sits beside it. */+ * message's card width so a table's columns show. Prose widens the bubble only up to the reading width (its max-width),+ * then fills whatever width the tables gave it (its min-width, which outranks max-width). The hover tray sits beside it. */export function ReplyBlocks({ blocks, join, citation, tray, render }: {blocks: readonly ReplyBlock[];join?: BubbleJoin;@@ -26,7 +27,7 @@ export function ReplyBlocks({ blocks, join, citation, tray, render }: {joinedCorners("start", { above: Boolean(join?.above), below: Boolean(join?.below) }))}>{blocks.map((block, index) => block.kind === "table"? <div key={index} data-reply-table className="min-w-0">{render(block.text)}</div>- : <div key={index} className="max-w-[var(--chat-bubble-max)]">{render(block.text)}</div>)}+ : <div key={index} data-reply-prose className="min-w-full max-w-[var(--chat-bubble-max)]">{render(block.text)}</div>)}</div>{tray}</div>diff --git a/src/components/RichTable.fit.test.ts b/src/components/RichTable.fit.test.tsindex a03fed04ff..a0393a49bd 100644--- a/src/components/RichTable.fit.test.ts+++ b/src/components/RichTable.fit.test.ts@@ -8,6 +8,7 @@ import { flushSync } from "react-dom";import { describe, expect, it, vi } from "vitest";import { RichTable } from "./RichTable";import { ChatMarkdown } from "./ChatMarkdown";+import { ReplyBlocks } from "./ReplyBlocks";import { CHAR_PX, COLUMN_MAX_CHARS, COLUMN_MIN_CHARS, columnMinimums, fitsColumns } from "@/lib/table-fit";import { formattedReplyWidth } from "@/lib/formatted-reply";@@ -92,11 +93,25 @@ describe("a table in a reply", () => {expect(columnMinimums(["Verdict"], [["Best open coding agent"]])).toEqual([Math.round(7 * CHAR_PX)]);});- it("gives a reply with a table the message's full width and keeps its prose at reading width", () => {+ it("gives a reply with a table the message's full width and runs its prose to the same edge as the table", () => {expect(formattedReplyWidth(markdown)).toContain("max-w-[var(--chat-card-pct)]");expect(formattedReplyWidth(markdown)).toContain("chat-wide");expect(formattedReplyWidth("- one\n- two")).toBe("w-full max-w-[min(var(--chat-prose-max),var(--chat-card-pct))]");const css = readFileSync(join(process.cwd(), "src/styles.css"), "utf8");- expect(css).toMatch(/\.chat-wide \.chat-md > :not\(\.chat-table\) \{\s*max-width: var\(--chat-prose-max\);/);+ expect(css).toMatch(/\.chat-wide \.chat-md \{\s*width: fit-content;\s*min-width: min\(100%, var\(--chat-prose-max\)\);\s*max-width: 100%;/);+ expect(css).toMatch(/\.chat-wide \.chat-md > :not\(\.chat-table\) \{\s*max-width: var\(--chat-prose-max\);\s*min-width: 100%;/);+ });++ it("lets Simple mode's prose widen the bubble only to the reading width, then fill the width its tables gave it", () => {+ const doc = parse(renderToStaticMarkup(createElement(ReplyBlocks, {+ blocks: [{ kind: "prose", text: "Before" }, { kind: "table", text: markdown }, { kind: "prose", text: "After" }],+ citation: { messageId: "m1", ownerType: "bot", ownerId: "b1", threadId: "t1" },+ render: (text: string) => text,+ })));+ expect(doc.querySelector("[data-reply-bubble]")!.className).toContain("w-fit");+ const prose = [...doc.querySelectorAll("[data-reply-prose]")];+ expect(prose).toHaveLength(2);+ for (const block of prose) expect(block.className).toBe("min-w-full max-w-[var(--chat-bubble-max)]");+ expect(doc.querySelector("[data-reply-table]")!.className).toBe("min-w-0");});});diff --git a/src/lib/formatted-reply.ts b/src/lib/formatted-reply.tsindex cb2d7d345c..7961371ed8 100644--- a/src/lib/formatted-reply.ts+++ b/src/lib/formatted-reply.ts@@ -13,7 +13,7 @@ export function isFormattedReply(text: string): boolean {}/** A formatted reply reads at prose width; one with a table takes the message's full width so every column shows,- * and its prose stays at reading width (`.chat-wide` in styles.css). */+ * and its prose runs to the same edge as its widest table (`.chat-wide` in styles.css). */export function formattedReplyWidth(text: string): string {return TABLE_DIVIDER.test(text)? "chat-wide w-full max-w-[var(--chat-card-pct)]"diff --git a/src/styles.css b/src/styles.cssindex def24f1a68..83fc9d5bbf 100644--- a/src/styles.css+++ b/src/styles.css@@ -1218,9 +1218,17 @@src: local("Noto Sans Hebrew"), local("Arial Hebrew"), local("SF Hebrew");unicode-range: U+0590-05FF, U+FB1D-FB4F;}-/* A reply with a table is as wide as the message; its prose keeps the reading width. */+/* A reply with a table is as wide as its widest table, and never narrower than the reading width. The prose's+ percentage min-width counts for nothing while the reply is measured, so only a table can widen it past the+ reading width; once the reply has its width, the same min-width outranks max-width and the prose fills it. */+.chat-wide .chat-md {+ width: fit-content;+ min-width: min(100%, var(--chat-prose-max));+ max-width: 100%;+}.chat-wide .chat-md > :not(.chat-table) {max-width: var(--chat-prose-max);+ min-width: 100%;}/* A reply's long unbroken text (a URL, a run of letters) wraps inside its bubble instead of running past the window.