Skip to content

CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.

feat(ui): restyle the version picker, and give both canvases one code block

codingFeng1018fc42c84efeb
diff --git a/client/index.css b/client/index.css
index 4fdb3c0..12efcbd 100644
--- a/client/index.css
+++ b/client/index.css
@@ -145,6 +145,47 @@
h1, h2, h3 {
letter-spacing: -0.015em;
}
+
+ /* Scrollbars.
+
+ Every scrolling surface in the app was drawing the platform's default bar
+ -- on Windows a 17px light-grey trough with square arrows, which is both
+ the widest and the oldest-looking element on the page, and does not follow
+ the theme into dark mode. `scrollbar-width`/`scrollbar-color` cover Firefox
+ and Chromium 121+; the `::-webkit-` rules cover the rest. Colours are
+ tokens, so the bar flips with everything else.
+
+ Not applied to `*`: the draw.io and PPT editor iframes own their chrome. */
+ html {
+ scrollbar-color: hsl(var(--foreground) / 0.22) transparent;
+ }
+
+ ::-webkit-scrollbar {
+ width: 10px;
+ height: 10px;
+ }
+
+ ::-webkit-scrollbar-track,
+ ::-webkit-scrollbar-corner {
+ background: transparent;
+ }
+
+ ::-webkit-scrollbar-thumb {
+ background-color: hsl(var(--foreground) / 0.18);
+ border: 3px solid transparent;
+ border-radius: 9999px;
+ /* Padding-box keeps the transparent border as breathing room rather than
+ letting the thumb paint into it. */
+ background-clip: padding-box;
+ }
+
+ ::-webkit-scrollbar-thumb:hover {
+ background-color: hsl(var(--foreground) / 0.32);
+ }
+
+ ::-webkit-scrollbar-button {
+ display: none;
+ }
}
/* ---------------------------------------------------------------------------
@@ -195,6 +236,21 @@
box-shadow: inset 0 0 0 1px hsl(var(--border) / 0.7);
}
+ /* Used by six code blocks, and until now defined by nobody: it is a
+ `tailwind-scrollbar` class and that plugin is not installed. */
+ .scrollbar-thin {
+ scrollbar-width: thin;
+ }
+
+ .scrollbar-thin::-webkit-scrollbar {
+ width: 8px;
+ height: 8px;
+ }
+
+ .scrollbar-thin::-webkit-scrollbar-thumb {
+ border-width: 2px;
+ }
+
/* Wide tables scroll inside the message instead of stretching the panel. */
.prose-scroll-x {
overflow-x: auto;
diff --git a/client/pages/portal/PortalPage.tsx b/client/pages/portal/PortalPage.tsx
index 613eece..f17f208 100644
--- a/client/pages/portal/PortalPage.tsx
+++ b/client/pages/portal/PortalPage.tsx
@@ -97,9 +97,9 @@ const canvasIcons: Record<PortalWorkspace, typeof Blocks> = {
const detailConfigs: Record<PortalWorkspace, DetailConfig> = {
flow: {
- title: "\u6d41\u7a0b\u753b\u5e03",
- subtitle: "\u4e00\u53e5\u9700\u6c42\uff0c\u5feb\u901f\u751f\u6210\u7ed3\u6784\u5316\u6d41\u7a0b\u56fe",
- intro: "\u6d41\u7a0b\u753b\u5e03\u8ba9\u4f60\u7528\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\u6d41\u7a0b\uff0c\u81ea\u52a8\u751f\u6210\u53ef\u7f16\u8f91\u7684\u6d41\u7a0b\u56fe\u3002\u652f\u6301\u8282\u70b9\u4e0e\u8fde\u7ebf\u7f16\u8f91\u3001\u5c40\u90e8\u4fee\u6539\uff0c\u5e76\u53ef\u5bfc\u51fa draw.io XML\u3002",
+ title: "\u56fe\u6807\u753b\u5e03",
+ subtitle: "\u4e00\u53e5\u9700\u6c42\uff0c\u5feb\u901f\u751f\u6210\u7ed3\u6784\u5316\u56fe\u6807",
+ intro: "\u56fe\u6807\u753b\u5e03\u8ba9\u4f60\u7528\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\u6d41\u7a0b\uff0c\u81ea\u52a8\u751f\u6210\u53ef\u7f16\u8f91\u7684\u56fe\u6807\u3002\u652f\u6301\u8282\u70b9\u4e0e\u8fde\u7ebf\u7f16\u8f91\u3001\u5c40\u90e8\u4fee\u6539\uff0c\u5e76\u53ef\u5bfc\u51fa draw.io XML\u3002",
tags: ["\u7ed3\u6784\u5316\u751f\u6210", "\u5c40\u90e8\u4fee\u6539", "draw.io XML"],
bullets: ["\u667a\u80fd\u89e3\u6790\u9700\u6c42\uff0c\u81ea\u52a8\u62bd\u53d6\u6d41\u7a0b\u8282\u70b9\u4e0e\u5173\u7cfb", "\u652f\u6301\u8282\u70b9\u4e0e\u8fde\u7ebf\u7f16\u8f91\uff0c\u62d6\u62fd\u5373\u6539", "\u5c40\u90e8\u4fee\u6539\uff0c\u5feb\u901f\u5fae\u8c03\u590d\u6742\u6d41\u7a0b", "\u5bfc\u51fa draw.io XML\uff0c\u4fbf\u4e8e\u590d\u7528\u4e0e\u534f\u4f5c"],
previews: [
@@ -111,13 +111,13 @@ const detailConfigs: Record<PortalWorkspace, DetailConfig> = {
steps: [
{ title: "\u8f93\u5165\u9700\u6c42", text: "\u7528\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\u6d41\u7a0b\u76ee\u6807\u4e0e\u7ea6\u675f\u3002", icon: FileText },
{ title: "\u7ed3\u6784\u5316\u89e3\u6790", text: "AI \u62bd\u53d6\u8282\u70b9\u3001\u5173\u7cfb\u4e0e\u65b9\u5411\u3002", icon: Share2 },
- { title: "\u751f\u6210 XML", text: "\u8f6c\u6362\u4e3a draw.io \u517c\u5bb9\u7684\u6d41\u7a0b\u56fe\u6570\u636e\u3002", icon: Code2 },
+ { title: "\u751f\u6210 XML", text: "\u8f6c\u6362\u4e3a draw.io \u517c\u5bb9\u7684\u56fe\u6807\u6570\u636e\u3002", icon: Code2 },
{ title: "\u9884\u89c8\u4e0e\u6821\u9a8c", text: "\u68c0\u67e5\u8282\u70b9\u4e0e\u8fde\u7ebf\u662f\u5426\u7b26\u5408\u9884\u671f\u3002", icon: ChartNoAxesCombined },
{ title: "\u5c40\u90e8\u4fee\u6539", text: "\u5bf9\u8282\u70b9\u6216\u8fde\u7ebf\u8fdb\u884c\u7cbe\u7ec6\u8c03\u6574\u3002", icon: Pencil },
{ title: "\u5bfc\u51fa\u590d\u7528", text: "\u5bfc\u51fa draw.io XML\uff0c\u7528\u4e8e\u534f\u4f5c\u4e0e\u590d\u7528\u3002", icon: Upload },
],
cta: "\u5f00\u59cb\u7ed8\u5236",
- slogan: "\u8ba9\u6d41\u7a0b\u56fe\u50cf\u753b\u5e03\u4e00\u6837\u81ea\u7531\u521b\u4f5c",
+ slogan: "\u8ba9\u56fe\u6807\u50cf\u753b\u5e03\u4e00\u6837\u81ea\u7531\u521b\u4f5c",
},
cad: {
title: "\u5ba4\u5185\u8bbe\u8ba1\u753b\u5e03",
@@ -563,7 +563,7 @@ export function PortalPage({ onEnterWorkspace }: PortalPageProps) {
titleB: "\u521b\u4f5c\u7684",
titleAccent: "\u667a\u80fd\u5de5\u4f5c\u53f0",
intro:
- "CanvasAnvil \u652f\u6301\u4e09\u79cd\u753b\u5e03\uff1a\u6d41\u7a0b\u753b\u5e03\u3001\u5ba4\u5185\u8bbe\u8ba1\u753b\u5e03\u3001PPT\u753b\u5e03\u3002\u63d0\u4f9b\u7ed3\u6784\u5316\u751f\u6210\u4e0e\u672c\u5730\u5c40\u90e8\u4fee\u6539\u80fd\u529b\uff0c\u5e2e\u52a9\u4f60\u9ad8\u6548\u3001\u53ef\u63a7\u5730\u5b8c\u6210\u5404\u7c7b\u53ef\u89c6\u5316\u521b\u4f5c\u3002",
+ "CanvasAnvil \u652f\u6301\u4e09\u79cd\u753b\u5e03\uff1a\u56fe\u6807\u753b\u5e03\u3001\u5ba4\u5185\u8bbe\u8ba1\u753b\u5e03\u3001PPT\u753b\u5e03\u3002\u63d0\u4f9b\u7ed3\u6784\u5316\u751f\u6210\u4e0e\u672c\u5730\u5c40\u90e8\u4fee\u6539\u80fd\u529b\uff0c\u5e2e\u52a9\u4f60\u9ad8\u6548\u3001\u53ef\u63a7\u5730\u5b8c\u6210\u5404\u7c7b\u53ef\u89c6\u5316\u521b\u4f5c\u3002",
tagA: "\u4e09\u79cd\u753b\u5e03",
tagB: "\u7ed3\u6784\u5316\u751f\u6210",
tagC: "\u5c40\u90e8\u4fee\u6539",
diff --git a/client/pages/portal/data.ts b/client/pages/portal/data.ts
index 3a9017a..26c0d47 100644
--- a/client/pages/portal/data.ts
+++ b/client/pages/portal/data.ts
@@ -14,9 +14,9 @@ export type PortalCanvasItem = {
export const portalCanvasItems: PortalCanvasItem[] = [
{
id: "flow",
- zhTitle: "\u6d41\u7a0b\u753b\u5e03",
+ zhTitle: "\u56fe\u6807\u753b\u5e03",
enTitle: "Flow Canvas",
- zhSummary: "\u7ed3\u6784\u5316\u6d41\u7a0b\u56fe\u4e0e\u8282\u70b9\u7ea7\u5c40\u90e8\u4fee\u6539",
+ zhSummary: "\u7ed3\u6784\u5316\u56fe\u6807\u4e0e\u8282\u70b9\u7ea7\u5c40\u90e8\u4fee\u6539",
enSummary: "Structured flow diagrams with node-level edits",
image: "/examples/flow/01.png",
angle: -90,
diff --git a/client/shared/chat/code-card.tsx b/client/shared/chat/code-card.tsx
new file mode 100644
index 0000000..010f14d
--- /dev/null
+++ b/client/shared/chat/code-card.tsx
@@ -0,0 +1,286 @@
+import { useMemo, useState, type ReactNode } from "react";
+import { Check, ChevronDown, ChevronUp, Copy, Play, X } from "lucide-react";
+import { Highlight } from "prism-react-renderer";
+import { syntaxTheme } from "@/shared/chat/syntax-theme";
+import { formatCodeForDisplay, toPrismLanguage } from "@/shared/chat/code-format";
+import { cn } from "@/shared/lib/utils";
+import { useUiLanguage } from "@/shared/i18n";
+
+/**
+ * The code block the assistant's replies render into, shared by the canvases.
+ *
+ * CAD and Flow had grown two of these. CAD's laid the code out -- indented XML,
+ * re-serialised JSON -- inside a titled card; Flow's dumped the model's raw
+ * single-line XML into a bare `<pre>` with `break-all`, which turns a draw.io
+ * document into an unreadable wall of characters. The two also disagreed on
+ * where the copy and apply buttons live. One component, one answer.
+ */
+
+const ACTION_CLASS =
+ "inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium text-muted-foreground transition-colors duration-fast ease-out-soft hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-60";
+
+/** Copy, with the same three states and the same shape everywhere. */
+export function CopyCodeButton({ code, className }: { code: string; className?: string }) {
+ const uiLang = useUiLanguage();
+ const tr = (zh: string, en: string) => (uiLang === "zh" ? zh : en);
+ const [copied, setCopied] = useState(false);
+ const [failed, setFailed] = useState(false);
+
+ const run = async () => {
+ try {
+ await navigator.clipboard.writeText(code);
+ setCopied(true);
+ setFailed(false);
+ setTimeout(() => setCopied(false), 1500);
+ } catch {
+ setFailed(true);
+ setCopied(false);
+ setTimeout(() => setFailed(false), 1500);
+ }
+ };
+
+ return (
+ <button
+ type="button"
+ onClick={run}
+ className={cn(ACTION_CLASS, className)}
+ title={copied ? tr("已复制", "Copied") : failed ? tr("复制失败", "Copy failed") : tr("复制代码", "Copy code")}
+ >
+ {copied ? (
+ <Check className="h-3 w-3 text-success" />
+ ) : failed ? (
+ <X className="h-3 w-3 text-destructive" />
+ ) : (
+ <Copy className="h-3 w-3" />
+ )}
+ <span>{copied ? tr("已复制", "Copied") : tr("复制", "Copy")}</span>
+ </button>
+ );
+}
+
+export type ApplyCode = (
+ code: string,
+ language: string,
+) => void | boolean | Promise<void | boolean>;
+
+/** Apply to canvas. A falsy `onApply` renders nothing at all. */
+export function ApplyCodeButton({
+ code,
+ language,
+ onApply,
+ className,
+}: {
+ code: string;
+ language: string;
+ onApply?: ApplyCode;
+ className?: string;
+}) {
+ const uiLang = useUiLanguage();
+ const tr = (zh: string, en: string) => (uiLang === "zh" ? zh : en);
+ const [applying, setApplying] = useState(false);
+ const [applied, setApplied] = useState(false);
+ const [failed, setFailed] = useState(false);
+
+ if (!onApply) return null;
+
+ const run = async () => {
+ if (applying) return;
+ try {
+ setApplying(true);
+ const result = await onApply(code, language);
+ if (result === false) {
+ setFailed(true);
+ setApplied(false);
+ setTimeout(() => setFailed(false), 1500);
+ return;
+ }
+ setApplied(true);
+ setFailed(false);
+ setTimeout(() => setApplied(false), 1500);
+ } catch {
+ setFailed(true);
+ setApplied(false);
+ setTimeout(() => setFailed(false), 1500);
+ } finally {
+ setApplying(false);
+ }
+ };
+
+ return (
+ <button
+ type="button"
+ onClick={run}
+ disabled={applying}
+ className={cn(ACTION_CLASS, className)}
+ title={applied ? tr("已应用", "Applied") : failed ? tr("应用失败", "Apply failed") : tr("应用到画布", "Apply to canvas")}
+ >
+ {applying ? (
+ <div className="h-3 w-3 animate-spin rounded-full border-2 border-primary border-t-transparent" />
+ ) : applied ? (
+ <Check className="h-3 w-3 text-success" />
+ ) : failed ? (
+ <X className="h-3 w-3 text-destructive" />
+ ) : (
+ <Play className="h-3 w-3" />
+ )}
+ <span>{applying ? tr("应用中", "Applying") : applied ? tr("已应用", "Applied") : tr("应用", "Apply")}</span>
+ </button>
+ );
+}
+
+/** Collapsed state survives a re-render, keyed by the block's identity. */
+const openStateById = new Map<string, boolean>();
+
+export interface CodeCardProps {
+ code: string;
+ language?: string;
+ /** Header label. Ignored when `framed` is false. */
+ title?: ReactNode;
+ /** Header glyph. Ignored when `framed` is false. */
+ icon?: ReactNode;
+ isStreaming?: boolean;
+ blockId?: string;
+ onApply?: ApplyCode;
+ /**
+ * `false` drops the card chrome and keeps only the action row and the code,
+ * for blocks that already sit inside a titled panel.
+ */
+ framed?: boolean;
+ defaultExpanded?: boolean;
+ className?: string;
+}
+
+export function CodeCard({
+ code,
+ language = "xml",
+ title,
+ icon,
+ isStreaming = false,
+ blockId,
+ onApply,
+ framed = true,
+ defaultExpanded = true,
+ className,
+}: CodeCardProps) {
+ const uiLang = useUiLanguage();
+ const tr = (zh: string, en: string) => (uiLang === "zh" ? zh : en);
+ const [isExpanded, setIsExpanded] = useState(() => {
+ if (blockId && openStateById.has(blockId)) return Boolean(openStateById.get(blockId));
+ return defaultExpanded;
+ });
+
+ const normalizedLanguage = useMemo(() => (language || "text").toLowerCase(), [language]);
+ const normalizedCode = useMemo(() => String(code ?? ""), [code]);
+ const prismLanguage = useMemo(() => toPrismLanguage(normalizedLanguage), [normalizedLanguage]);
+ const displayCode = useMemo(
+ () => formatCodeForDisplay(normalizedCode, prismLanguage),
+ [normalizedCode, prismLanguage],
+ );
+
+ const setExpanded = (next: boolean) => {
+ setIsExpanded(next);
+ if (blockId) openStateById.set(blockId, next);
+ };
+
+ const actions = (
+ <>
+ <ApplyCodeButton code={normalizedCode} language={normalizedLanguage} onApply={onApply} />
+ <CopyCodeButton code={normalizedCode} />
+ </>
+ );
+
+ const body = (
+ <Highlight theme={syntaxTheme} code={displayCode} language={prismLanguage}>
+ {({ style, tokens, getLineProps, getTokenProps }) => (
+ <pre
+ className="scrollbar-thin max-h-48 overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed"
+ style={{
+ ...style,
+ backgroundColor: "transparent",
+ margin: 0,
+ padding: 0,
+ wordBreak: "break-word",
+ whiteSpace: "pre-wrap",
+ }}
+ >
+ {tokens.map((line, i) => (
+ <div key={i} {...getLineProps({ line })} style={{ wordBreak: "break-word" }}>
+ {line.map((token, key) => (
+ <span key={key} {...getTokenProps({ token })} />
+ ))}
+ </div>
+ ))}
+ </pre>
+ )}
+ </Highlight>
+ );
+
+ if (!framed) {
+ return (
+ <div className={cn("w-full min-w-0 overflow-hidden", className)}>
+ <div className="mb-1 flex items-center justify-between gap-2">
+ <span className="text-[10px] uppercase tracking-wide text-muted-foreground">
+ {normalizedLanguage}
+ </span>
+ <div className="flex items-center gap-1">{actions}</div>
+ </div>
+ {body}
+ </div>
+ );
+ }
+
+ return (
+ <div
+ className={cn(
+ "my-3 w-full min-w-0 max-w-full overflow-hidden rounded-xl border border-border/60 bg-muted/30",
+ className,
+ )}
+ >
+ <div className="flex items-center justify-between gap-2 bg-muted/50 px-4 py-3">
+ <div className="flex min-w-0 items-center gap-2">
+ {icon && (
+ <div className="flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary-strong">
+ {icon}
+ </div>
+ )}
+ <span className="truncate text-sm font-medium text-foreground/80">
+ {title ?? normalizedLanguage.toUpperCase()}
+ </span>
+ </div>
+ <div className="flex items-center gap-2">
+ {isStreaming ? (
+ <div className="h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent" />
+ ) : (
+ <span className="rounded-full bg-success/[0.08] px-2 py-0.5 text-xs font-medium text-success">
+ {tr("完成", "Complete")}
+ </span>
+ )}
+ <div className="flex items-center gap-1">
+ {actions}
+ <button
+ type="button"
+ onClick={() => setExpanded(!isExpanded)}
+ aria-expanded={isExpanded}
+ aria-label={isExpanded ? tr("收起代码", "Collapse code") : tr("展开代码", "Expand code")}
+ className="rounded p-1 transition-colors duration-fast ease-out-soft hover:bg-muted"
+ >
+ {isExpanded ? (
+ <ChevronUp className="h-4 w-4 text-muted-foreground" />
+ ) : (
+ <ChevronDown className="h-4 w-4 text-muted-foreground" />
+ )}
+ </button>
+ </div>
+ </div>
+ </div>
+ {isExpanded && (
+ <div className="border-t border-border/40 bg-muted/20 px-4 py-3">
+ <div className="mb-1 text-[10px] uppercase tracking-wide text-muted-foreground">
+ {normalizedLanguage}
+ </div>
+ {body}
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/client/shared/chat/code-format.ts b/client/shared/chat/code-format.ts
new file mode 100644
index 0000000..3fa60fb
--- /dev/null
+++ b/client/shared/chat/code-format.ts
@@ -0,0 +1,87 @@
+import type { Language } from "prism-react-renderer";
+
+/**
+ * Turning what the model emits into something readable.
+ *
+ * Separate from `code-card.tsx` only so that file exports components and
+ * nothing else, which is what Fast Refresh needs to swap it in place.
+ */
+
+const PRISM_ALIASES: Record<string, Language> = {
+ svg: "xml",
+ yml: "yaml",
+ shell: "bash",
+ sh: "bash",
+ zsh: "bash",
+ ts: "typescript",
+ js: "javascript",
+ md: "markdown",
+};
+
+const PRISM_SUPPORTED = new Set([
+ "text",
+ "xml",
+ "json",
+ "javascript",
+ "typescript",
+ "tsx",
+ "jsx",
+ "python",
+ "bash",
+ "yaml",
+ "markdown",
+ "css",
+ "html",
+]);
+
+/** Anything Prism cannot highlight falls back to plain text, never throws. */
+export function toPrismLanguage(language: string): Language {
+ const lang = (language || "text").toLowerCase();
+ if (PRISM_ALIASES[lang]) return PRISM_ALIASES[lang];
+ return PRISM_SUPPORTED.has(lang) ? (lang as Language) : "text";
+}
+
+/**
+ * Break `<a><b/></a>` onto one tag per line and indent by nesting depth. The
+ * model streams draw.io XML as a single line, and no amount of wrapping makes
+ * that readable.
+ */
+function formatXmlLike(input: string): string {
+ const source = String(input || "").trim();
+ if (!source) return source;
+
+ const normalized = source.replace(/\r\n/g, "\n").replace(/>\s*</g, ">\n<");
+ const lines = normalized.split("\n");
+ let indent = 0;
+ const unit = " ";
+
+ return lines
+ .map((line) => line.trim())
+ .filter((line) => line.length > 0)
+ .map((line) => {
+ if (/^<\//.test(line)) indent = Math.max(indent - 1, 0);
+ const formatted = `${unit.repeat(indent)}${line}`;
+
+ const isOpeningTag =
+ /^<[^!?/][^>]*>$/.test(line) &&
+ !/\/>$/.test(line) &&
+ !/^<[^>]+>.*<\/[^>]+>$/.test(line);
+ if (isOpeningTag) indent += 1;
+
+ return formatted;
+ })
+ .join("\n");
+}
+
+/** Indents XML/HTML and re-serialises JSON; leaves everything else alone. */
+export function formatCodeForDisplay(code: string, prismLanguage: Language): string {
+ if (prismLanguage === "xml" || prismLanguage === "html") return formatXmlLike(code);
+ if (prismLanguage === "json") {
+ try {
+ return JSON.stringify(JSON.parse(code), null, 2);
+ } catch {
+ return code;
+ }
+ }
+ return code;
+}
diff --git a/client/shared/chat/index.ts b/client/shared/chat/index.ts
index 7f005cb..c0f6438 100644
--- a/client/shared/chat/index.ts
+++ b/client/shared/chat/index.ts
@@ -1,6 +1,7 @@
export * from "@/shared/chat/shimmer";
export * from "@/shared/chat/message-image";
export * from "@/shared/chat/message-attachments";
+export * from "@/shared/chat/code-card";
export * from "@/shared/chat/reasoning";
export * from "@/shared/chat/button-with-tooltip";
export * from "@/shared/chat/reset-warning-modal";
diff --git a/client/shared/i18n/messages.ts b/client/shared/i18n/messages.ts
index 63f178d..4251833 100644
--- a/client/shared/i18n/messages.ts
+++ b/client/shared/i18n/messages.ts
@@ -40,7 +40,7 @@ const messages = {
"chat.collapseLocked": { zh: "PPT 生成完成前不能收起聊天", en: "Chat cannot be collapsed while PPT is generating" },
"chat.collapse": { zh: "收起聊天", en: "Collapse chat" },
- "nav.flow": { zh: "流程绘制", en: "Flow" },
+ "nav.flow": { zh: "图标绘制", en: "Flow" },
"nav.cad": { zh: "室内设计", en: "CAD" },
"nav.ppt": { zh: "PPT演示", en: "PPT" },
diff --git a/client/workspaces/cad/chat/code-block.tsx b/client/workspaces/cad/chat/code-block.tsx
index e289935..18acd0b 100644
--- a/client/workspaces/cad/chat/code-block.tsx
+++ b/client/workspaces/cad/chat/code-block.tsx
@@ -1,7 +1,5 @@
-import { useMemo, useState } from "react";
-import { Check, ChevronDown, ChevronUp, Copy, Cpu, Play, X } from "lucide-react";
-import { Highlight, type Language } from "prism-react-renderer";
-import { syntaxTheme } from "@/shared/chat/syntax-theme";
+import { Cpu } from "lucide-react";
+import { CodeCard, type ApplyCode } from "@/shared/chat/code-card";
import { useUiLanguage } from "@/shared/i18n";
interface CodeBlockProps {
@@ -9,256 +7,27 @@ interface CodeBlockProps {
language?: string;
isStreaming?: boolean;
blockId?: string;
- onApply?: (code: string, language: string) => void | boolean | Promise<void | boolean>;
-}
-
-const openStateById = new Map<string, boolean>();
-
-function formatXmlLike(input: string): string {
- const source = String(input || "").trim();
- if (!source) return source;
-
- const normalized = source.replace(/\r\n/g, "\n").replace(/>\s*</g, ">\n<");
- const lines = normalized.split("\n");
- let indent = 0;
- const unit = " ";
-
- return lines
- .map((line) => line.trim())
- .filter((line) => line.length > 0)
- .map((line) => {
- if (/^<\//.test(line)) indent = Math.max(indent - 1, 0);
- const formatted = `${unit.repeat(indent)}${line}`;
-
- const isOpeningTag =
- /^<[^!?/][^>]*>$/.test(line) &&
- !/\/>$/.test(line) &&
- !/^<[^>]+>.*<\/[^>]+>$/.test(line);
- if (isOpeningTag) indent += 1;
-
- return formatted;
- })
- .join("\n");
+ onApply?: ApplyCode;
}
+/** The CAD canvas's framing of the shared code card. */
export function CodeBlock({
code,
language = "xml",
- isStreaming: _isStreaming = false,
- blockId: _blockId,
+ isStreaming = false,
+ blockId,
onApply,
}: CodeBlockProps) {
const uiLang = useUiLanguage();
- const tr = (zhText: string, enText: string) => (uiLang === "zh" ? zhText : enText);
- const [isExpanded, setIsExpanded] = useState(() => {
- if (_blockId && openStateById.has(_blockId)) return Boolean(openStateById.get(_blockId));
- return true;
- });
- const [copied, setCopied] = useState(false);
- const [copyFailed, setCopyFailed] = useState(false);
- const [applying, setApplying] = useState(false);
- const [applied, setApplied] = useState(false);
- const [applyFailed, setApplyFailed] = useState(false);
- const normalizedLanguage = useMemo(() => (language || "text").toLowerCase(), [language]);
- const normalizedCode = useMemo(() => String(code ?? ""), [code]);
- const prismLanguage = useMemo<Language>(() => {
- const lang = normalizedLanguage;
- if (lang === "svg") return "xml";
- if (lang === "yml") return "yaml";
- if (lang === "shell" || lang === "sh" || lang === "zsh") return "bash";
- if (lang === "ts") return "typescript";
- if (lang === "tsx") return "tsx";
- if (lang === "js") return "javascript";
- if (lang === "md") return "markdown";
- const allowed = new Set([
- "text",
- "xml",
- "json",
- "javascript",
- "typescript",
- "tsx",
- "jsx",
- "python",
- "bash",
- "yaml",
- "markdown",
- "css",
- "html",
- ]);
- if (allowed.has(lang)) return lang as Language;
- return "text";
- }, [normalizedLanguage]);
-
- const displayCode = useMemo(() => {
- if (prismLanguage === "xml" || prismLanguage === "html") {
- return formatXmlLike(normalizedCode);
- }
- if (prismLanguage === "json") {
- try {
- return JSON.stringify(JSON.parse(normalizedCode), null, 2);
- } catch {
- return normalizedCode;
- }
- }
- return normalizedCode;
- }, [normalizedCode, prismLanguage]);
-
- const copyCode = async () => {
- try {
- await navigator.clipboard.writeText(normalizedCode);
- setCopied(true);
- setCopyFailed(false);
- setTimeout(() => setCopied(false), 1500);
- } catch {
- setCopyFailed(true);
- setCopied(false);
- setTimeout(() => setCopyFailed(false), 1500);
- }
- };
-
- const applyCode = async () => {
- if (!onApply || applying) return;
- try {
- setApplying(true);
- const result = await onApply(normalizedCode, normalizedLanguage);
- if (result === false) {
- setApplyFailed(true);
- setApplied(false);
- setTimeout(() => setApplyFailed(false), 1500);
- return;
- }
- setApplied(true);
- setApplyFailed(false);
- setTimeout(() => setApplied(false), 1500);
- } catch {
- setApplyFailed(true);
- setApplied(false);
- setTimeout(() => setApplyFailed(false), 1500);
- } finally {
- setApplying(false);
- }
- };
-
- const setExpanded = (next: boolean) => {
- setIsExpanded(next);
- if (_blockId) openStateById.set(_blockId, next);
- };
-
return (
- <div className="my-3 w-full min-w-0 max-w-full overflow-hidden rounded-xl border border-border/60 bg-muted/30">
- <div className="flex items-center justify-between px-4 py-3 bg-muted/50">
- <div className="flex items-center gap-2">
- <div className="w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center">
- <Cpu className="w-3.5 h-3.5 text-primary-strong" />
- </div>
- <span className="text-sm font-medium text-foreground/80">{tr("生成 CAD", "Generate CAD")}</span>
- </div>
- <div className="flex items-center gap-2">
- {_isStreaming ? (
- <div className="h-4 w-4 border-2 border-primary border-t-transparent rounded-full animate-spin" />
- ) : (
- <span className="text-xs font-medium text-success bg-success/[0.08] px-2 py-0.5 rounded-full">
- {tr("完成", "Complete")}
- </span>
- )}
- <div className="flex items-center gap-1">
- {onApply && (
- <button
- type="button"
- onClick={applyCode}
- disabled={applying}
- className="inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted transition-colors disabled:opacity-60 disabled:cursor-not-allowed"
- title={applied ? tr("已应用", "Applied") : applyFailed ? tr("应用失败", "Apply failed") : tr("应用到画布", "Apply to canvas")}
- >
- {applying ? (
- <div className="h-3 w-3 border-2 border-primary border-t-transparent rounded-full animate-spin" />
- ) : applied ? (
- <Check className="h-3 w-3 text-success" />
- ) : applyFailed ? (
- <X className="h-3 w-3 text-destructive" />
- ) : (
- <Play className="h-3 w-3" />
- )}
- <span>{applying ? tr("应用中", "Applying") : applied ? tr("已应用", "Applied") : tr("应用", "Apply")}</span>
- </button>
- )}
- <button
- type="button"
- onClick={() => setExpanded(!isExpanded)}
- className="p-1 rounded hover:bg-muted transition-colors"
- >
- {isExpanded ? (
- <ChevronUp className="w-4 h-4 text-muted-foreground" />
- ) : (
- <ChevronDown className="w-4 h-4 text-muted-foreground" />
- )}
- </button>
- </div>
- </div>
- </div>
- {isExpanded && (
- <div className="px-4 py-3 border-t border-border/40 bg-muted/20">
- <div className="mb-1 flex items-center justify-between">
- <span className="text-[10px] uppercase text-muted-foreground">{normalizedLanguage}</span>
- <button
- type="button"
- onClick={copyCode}
- className="inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted transition-colors"
- title={
- copied
- ? tr("已复制", "Copied")
- : copyFailed
- ? tr("复制失败", "Copy failed")
- : tr("复制代码", "Copy code")
- }
- >
- {copied ? (
- <Check className="h-3 w-3 text-success" />
- ) : copyFailed ? (
- <X className="h-3 w-3 text-destructive" />
- ) : (
- <Copy className="h-3 w-3" />
- )}
- <span>{copied ? tr("已复制", "Copied") : tr("复制", "Copy")}</span>
- </button>
- </div>
- <Highlight theme={syntaxTheme} code={displayCode} language={prismLanguage}>
- {({
- className: _className,
- style,
- tokens,
- getLineProps,
- getTokenProps,
- }) => (
- <pre
- className="text-[11px] leading-relaxed overflow-x-hidden overflow-y-auto max-h-48 scrollbar-thin whitespace-pre-wrap break-words"
- style={{
- ...style,
- fontFamily:
- "var(--font-mono), ui-monospace, monospace",
- backgroundColor: "transparent",
- margin: 0,
- padding: 0,
- wordBreak: "break-word",
- whiteSpace: "pre-wrap",
- }}
- >
- {tokens.map((line, i) => (
- <div
- key={i}
- {...getLineProps({ line })}
- style={{ wordBreak: "break-word" }}
- >
- {line.map((token, key) => (
- <span key={key} {...getTokenProps({ token })} />
- ))}
- </div>
- ))}
- </pre>
- )}
- </Highlight>
- </div>
- )}
- </div>
+ <CodeCard
+ code={code}
+ language={language}
+ isStreaming={isStreaming}
+ blockId={blockId}
+ onApply={onApply}
+ icon={<Cpu className="h-3.5 w-3.5" />}
+ title={uiLang === "zh" ? "生成 CAD" : "Generate CAD"}
+ />
);
}
diff --git a/client/workspaces/flow/chat/ChatMessageDisplay.tsx b/client/workspaces/flow/chat/ChatMessageDisplay.tsx
index 93ca9c4..0971b82 100644
--- a/client/workspaces/flow/chat/ChatMessageDisplay.tsx
+++ b/client/workspaces/flow/chat/ChatMessageDisplay.tsx
@@ -37,7 +37,6 @@ import {
FileCode,
FileText,
Pencil,
- Play,
RotateCcw,
X,
} from "lucide-react"
@@ -46,6 +45,7 @@ import type { MutableRefObject } from "react"
import { Fragment, useCallback, useEffect, useRef, useState } from "react"
import ReactMarkdown from "react-markdown"
import {
+ ApplyCodeButton,
Reasoning,
ReasoningContent,
ReasoningTrigger,
@@ -333,18 +333,24 @@ export function ChatMessageDisplay({
const getToolDisplayName = (name: string) => {
switch (name) {
case "display_diagram":
- return "Generate Diagram"
+ return t("tool.display_diagram")
case "edit_diagram":
- return "Edit Diagram"
+ return t("tool.edit_diagram")
case "append_diagram":
- return "Append Diagram"
+ return t("tool.append_diagram")
case "get_shape_library":
- return "Get Shape Library"
+ return t("tool.get_shape_library")
default:
return name
}
}
+ /** A truncated diagram is a warning, not a failure: the XML arrived
+ incomplete but what did arrive is still shown. */
+ const isTruncated =
+ (toolName === "display_diagram" || toolName === "append_diagram") &&
+ !isMxCellXmlComplete(String(input?.xml || ""))
+
return (
<div
key={callId}
@@ -365,12 +371,18 @@ export function ChatMessageDisplay({
)}
{state === "output-available" && (
<span className="text-xs font-medium text-success bg-success/[0.08] px-2 py-0.5 rounded-full">
- Complete
+ {t("tool.status.complete")}
</span>
)}
{state === "output-error" && (
- <span className={`text-xs font-medium px-2 py-0.5 rounded-full ${((toolName === "display_diagram" || toolName === "append_diagram") && !isMxCellXmlComplete(String(input?.xml || ""))) ? "text-yellow-700 bg-yellow-50" : "text-destructive bg-destructive/[0.08]"}`}>
- {((toolName === "display_diagram" || toolName === "append_diagram") && !isMxCellXmlComplete(String(input?.xml || ""))) ? "Truncated" : "Error"}
+ // `text-yellow-700 bg-yellow-50` was raw Tailwind
+ // palette in a token-driven interface: it stayed a
+ // light-mode chip on a dark card.
+ <span className={cn(
+ "text-xs font-medium px-2 py-0.5 rounded-full",
+ isTruncated ? "text-warning bg-warning/[0.10]" : "text-destructive bg-destructive/[0.08]",
+ )}>
+ {isTruncated ? t("tool.status.truncated") : t("tool.status.error")}
</span>
)}
{input && Object.keys(input).length > 0 && (
@@ -391,34 +403,27 @@ export function ChatMessageDisplay({
{input && isExpanded && (
<div className="px-4 py-3 border-t border-border/40 bg-muted/20">
{typeof input === "object" && input.xml ? (
- <CodeBlock code={input.xml} language="xml" onApply={applyCodeToDiagram} />
+ <CodeBlock code={input.xml} language="xml" onApply={applyCodeToDiagram} framed={false} />
) : typeof input === "object" &&
input.operations &&
Array.isArray(input.operations) ? (
<div className="space-y-2">
<div className="flex justify-end">
- <button
- type="button"
- onClick={() =>
- void applyCodeToDiagram(
- JSON.stringify(
- {
- type: "flow_patch",
- mode: "patch",
- operations: input.operations,
- },
- null,
- 2,
- ),
- "json",
- )
- }
- className="inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted transition-colors"
- title="Apply to canvas"
- >
- <Play className="h-3 w-3" />
- <span>Apply</span>
- </button>
+ {/* The same apply button the code blocks use,
+ rather than a third hand-rolled copy. */}
+ <ApplyCodeButton
+ code={JSON.stringify(
+ {
+ type: "flow_patch",
+ mode: "patch",
+ operations: input.operations,
+ },
+ null,
+ 2,
+ )}
+ language="json"
+ onApply={(code) => applyCodeToDiagram(code, "json")}
+ />
</div>
<OperationsDisplay operations={input.operations} />
</div>
@@ -433,6 +438,7 @@ export function ChatMessageDisplay({
code={JSON.stringify(input, null, 2)}
language="json"
onApply={applyCodeToDiagram}
+ framed={false}
/>
) : null}
</div>
@@ -1073,6 +1079,16 @@ export function ChatMessageDisplay({
<ReactMarkdown
remarkPlugins={[remarkGfm]}
components={{
+ // A fenced block arrives as
+ // `<pre><code>`, and the `code`
+ // override below returns a card --
+ // which was then sitting inside
+ // prose's own `<pre>`, box in box.
+ // The card and the plain fallback
+ // both bring their own container.
+ pre({ children }: any) {
+ return <>{children}</>
+ },
table({
children,
...props
diff --git a/client/workspaces/flow/chat/code-block.tsx b/client/workspaces/flow/chat/code-block.tsx
index 1cbcfb6..803b8ad 100644
--- a/client/workspaces/flow/chat/code-block.tsx
+++ b/client/workspaces/flow/chat/code-block.tsx
@@ -1,142 +1,43 @@
"use client"
-import { Check, Copy, Play, X } from "lucide-react"
-import { Highlight } from "prism-react-renderer"
-import { syntaxTheme } from "@/shared/chat/syntax-theme"
-import { useState } from "react"
+import { Workflow } from "lucide-react"
+import { CodeCard, type ApplyCode } from "@/shared/chat/code-card"
+import { useUiLanguage } from "@/shared/i18n"
interface CodeBlockProps {
code: string
language?: "xml" | "json"
onApply?: (code: string, language: "xml" | "json") => void | boolean | Promise<void | boolean>
+ isStreaming?: boolean
+ blockId?: string
+ /**
+ * These blocks appear in two places: on their own inside an assistant
+ * reply, and nested inside a tool-call panel that already has its own
+ * header. The nested one drops the card so the chat is not a box in a box.
+ */
+ framed?: boolean
}
-export function CodeBlock({ code, language = "xml", onApply }: CodeBlockProps) {
- const [copied, setCopied] = useState(false)
- const [copyFailed, setCopyFailed] = useState(false)
- const [applying, setApplying] = useState(false)
- const [applied, setApplied] = useState(false)
- const [applyFailed, setApplyFailed] = useState(false)
-
- const copyCode = async () => {
- try {
- await navigator.clipboard.writeText(code)
- setCopied(true)
- setCopyFailed(false)
- setTimeout(() => setCopied(false), 1500)
- } catch {
- setCopyFailed(true)
- setCopied(false)
- setTimeout(() => setCopyFailed(false), 1500)
- }
- }
-
- const applyCode = async () => {
- if (!onApply || applying) return
- try {
- setApplying(true)
- const result = await onApply(code, language)
- if (result === false) {
- setApplyFailed(true)
- setApplied(false)
- setTimeout(() => setApplyFailed(false), 1500)
- return
- }
- setApplied(true)
- setApplyFailed(false)
- setTimeout(() => setApplied(false), 1500)
- } catch {
- setApplyFailed(true)
- setApplied(false)
- setTimeout(() => setApplyFailed(false), 1500)
- } finally {
- setApplying(false)
- }
- }
-
+/** The diagram canvas's framing of the shared code card. */
+export function CodeBlock({
+ code,
+ language = "xml",
+ onApply,
+ isStreaming = false,
+ blockId,
+ framed = true,
+}: CodeBlockProps) {
+ const uiLang = useUiLanguage()
return (
- <div className="overflow-hidden w-full">
- <div className="mb-1 flex justify-end gap-1">
- {onApply ? (
- <button
- type="button"
- onClick={applyCode}
- disabled={applying}
- className="inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted transition-colors disabled:opacity-60 disabled:cursor-not-allowed"
- title={applied ? "Applied" : applyFailed ? "Apply failed" : "Apply to canvas"}
- >
- {applying ? (
- <div className="h-3 w-3 border-2 border-primary border-t-transparent rounded-full animate-spin" />
- ) : applied ? (
- <Check className="h-3 w-3 text-success" />
- ) : applyFailed ? (
- <X className="h-3 w-3 text-destructive" />
- ) : (
- <Play className="h-3 w-3" />
- )}
- <span>{applying ? "Applying" : applied ? "Applied" : "Apply"}</span>
- </button>
- ) : null}
- <button
- type="button"
- onClick={copyCode}
- className="inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted transition-colors"
- title={
- copied
- ? "Copied"
- : copyFailed
- ? "Copy failed"
- : "Copy code"
- }
- >
- {copied ? (
- <Check className="h-3 w-3 text-success" />
- ) : copyFailed ? (
- <X className="h-3 w-3 text-destructive" />
- ) : (
- <Copy className="h-3 w-3" />
- )}
- <span>{copied ? "Copied" : "Copy"}</span>
- </button>
- </div>
- <Highlight theme={syntaxTheme} code={code} language={language}>
- {({
- className: _className,
- style,
- tokens,
- getLineProps,
- getTokenProps,
- }) => (
- <pre
- className="text-[11px] leading-relaxed overflow-x-auto overflow-y-auto max-h-48 scrollbar-thin break-all"
- style={{
- ...style,
- fontFamily:
- "var(--font-mono), ui-monospace, monospace",
- backgroundColor: "transparent",
- margin: 0,
- padding: 0,
- wordBreak: "break-all",
- whiteSpace: "pre-wrap",
- }}
- >
- {tokens.map((line, i) => (
- <div
- key={i}
- {...getLineProps({ line })}
- style={{ wordBreak: "break-all" }}
- >
- {line.map((token, key) => (
- <span
- key={key}
- {...getTokenProps({ token })}
- />
- ))}
- </div>
- ))}
- </pre>
- )}
- </Highlight>
- </div>
+ <CodeCard
+ code={code}
+ language={language}
+ isStreaming={isStreaming}
+ blockId={blockId}
+ framed={framed}
+ onApply={onApply as ApplyCode | undefined}
+ icon={<Workflow className="h-3.5 w-3.5" />}
+ title={uiLang === "zh" ? "生成图标" : "Generate diagram"}
+ />
)
}
diff --git a/client/workspaces/flow/lib/translations.ts b/client/workspaces/flow/lib/translations.ts
index 15fb27d..417069d 100644
--- a/client/workspaces/flow/lib/translations.ts
+++ b/client/workspaces/flow/lib/translations.ts
@@ -3,18 +3,18 @@ import { createTranslator, type Dict } from "@/shared/i18n/translator";
/** Strings owned by the Flow workspace. */
const messages = {
// ChatPanel
- "app.title": { zh: "流程图助手", en: "Next AI Drawio" },
- "welcome.title": { zh: "用 AI 创建流程图", en: "Create diagrams with AI" },
+ "app.title": { zh: "图标助手", en: "Next AI Drawio" },
+ "welcome.title": { zh: "用 AI 创建图标", en: "Create diagrams with AI" },
"welcome.desc": { zh: "描述你想创建的内容,或上传图片进行复刻", en: "Describe what you want to create or upload an image to replicate" },
"app.about": { zh: "关于", en: "About" },
"chat.panel.show": { zh: "展开交互区 (Ctrl+B)", en: "Show chat panel (Ctrl+B)" },
"chat.panel.hide": { zh: "收起交互区 (Ctrl+B)", en: "Hide chat panel (Ctrl+B)" },
- "chat.panel.title": { zh: "流程图交互区", en: "Flowchart Assistant" },
+ "chat.panel.title": { zh: "图标交互区", en: "Flowchart Assistant" },
"chat.settings": { zh: "设置", en: "Settings" },
"chat.vertical.title": { zh: "AI 对话", en: "AI Chat" },
// ChatInput
- "input.placeholder": { zh: "描述你的流程图需求,或上传文件...", en: "Describe your diagram or upload a file..." },
+ "input.placeholder": { zh: "描述你的图标需求,或上传文件...", en: "Describe your diagram or upload a file..." },
"input.clear": { zh: "清空对话", en: "Clear conversation" },
"input.upload": { zh: "上传文件(图片、PDF、文本)", en: "Upload file (image, PDF, text)" },
"input.upload_image": { zh: "上传图片", en: "Upload image" },
@@ -82,12 +82,12 @@ const messages = {
// ResetWarningModal
"reset.title": { zh: "确认清空?", en: "Clear Everything?" },
- "reset.desc": { zh: "这会清空当前对话并重置流程图,且无法撤销。", en: "This will clear the current conversation and reset the diagram. This action cannot be undone." },
+ "reset.desc": { zh: "这会清空当前对话并重置图标,且无法撤销。", en: "This will clear the current conversation and reset the diagram. This action cannot be undone." },
"reset.confirm": { zh: "确认清空", en: "Clear Everything" },
"reset.cancel": { zh: "取消", en: "Cancel" },
// SaveDialog
- "save.title": { zh: "保存流程图", en: "Save Diagram" },
+ "save.title": { zh: "保存图标", en: "Save Diagram" },
"save.desc": { zh: "选择保存格式。", en: "Choose a format to save your diagram." },
"save.format": { zh: "格式", en: "Format" },
"save.filename": { zh: "文件名", en: "Filename" },
@@ -97,23 +97,23 @@ const messages = {
// ExamplePanel
"example.aws.title": { zh: "AWS 架构图", en: "AWS Architecture" },
"example.aws.desc": { zh: "用 AWS 图标生成云架构图", en: "Create a cloud architecture diagram with AWS icons" },
- "example.flowchart.title": { zh: "复刻流程图", en: "Replicate Flowchart" },
- "example.flowchart.desc": { zh: "上传并复刻已有流程图", en: "Upload and replicate an existing flowchart" },
+ "example.flowchart.title": { zh: "复刻图标", en: "Replicate Flowchart" },
+ "example.flowchart.desc": { zh: "上传并复刻已有图标", en: "Upload and replicate an existing flowchart" },
"example.creative.title": { zh: "创意绘图", en: "Creative Drawing" },
"example.creative.desc": { zh: "生成有趣的创意图形", en: "Draw something fun and creative" },
"example.cached": { zh: "示例已缓存,可快速响应", en: "Examples are cached for instant response" },
"example.new": { zh: "新", en: "NEW" },
"examples.title": { zh: "快速示例", en: "Quick Examples" },
- "examples.paper.title": { zh: "论文转流程图", en: "Paper to Diagram" },
+ "examples.paper.title": { zh: "论文转图标", en: "Paper to Diagram" },
"examples.paper.desc": { zh: "支持上传 .pdf、.txt、.md、.json、.csv、.py、.js、.ts 等文件", en: "Upload .pdf, .txt, .md, .json, .csv, .py, .js, .ts and more" },
- "examples.animated.title": { zh: "动画流程图", en: "Animated Diagram" },
+ "examples.animated.title": { zh: "动画图标", en: "Animated Diagram" },
"examples.animated.desc": { zh: "绘制带动画连线的 Transformer 架构图", en: "Draw a transformer architecture with animated connectors" },
- "tooltip.history": { zh: "流程图历史", en: "Diagram history" },
- "tooltip.save": { zh: "保存流程图", en: "Save diagram" },
+ "tooltip.history": { zh: "图标历史", en: "Diagram history" },
+ "tooltip.save": { zh: "保存图标", en: "Save diagram" },
"tooltip.deep_thinking": { zh: "深度思考", en: "Deep Think" },
// HistoryDialog
- "history.title": { zh: "流程图历史记录", en: "Diagram History" },
+ "history.title": { zh: "图标历史记录", en: "Diagram History" },
"history.empty": { zh: "暂无历史记录,发送消息后会生成历史版本。", en: "No history available yet. Send messages to create diagram history." },
"history.version": { zh: "版本", en: "Version" },
"history.restore": { zh: "恢复到版本", en: "Restore to Version" },
@@ -127,6 +127,16 @@ const messages = {
"global_constraints.placeholder": { zh: "例如:决策节点统一使用蓝色...", en: "e.g., Always use blue for decision nodes..." },
"tooltip.global_constraints": { zh: "全局约束", en: "Global Constraints" },
+ // Tool call cards. These were the last hardcoded English in the panel: the
+ // card sat directly above a fully translated code block.
+ "tool.display_diagram": { zh: "生成图标", en: "Generate Diagram" },
+ "tool.edit_diagram": { zh: "编辑图标", en: "Edit Diagram" },
+ "tool.append_diagram": { zh: "追加图标", en: "Append Diagram" },
+ "tool.get_shape_library": { zh: "读取图形库", en: "Get Shape Library" },
+ "tool.status.complete": { zh: "完成", en: "Complete" },
+ "tool.status.truncated": { zh: "已截断", en: "Truncated" },
+ "tool.status.error": { zh: "错误", en: "Error" },
+
// Common
"common.error": { zh: "错误", en: "Error" },
"common.loading": { zh: "加载中...", en: "Loading..." },
diff --git a/client/workspaces/ppt/canvas/views/CreationStart.tsx b/client/workspaces/ppt/canvas/views/CreationStart.tsx
index 0211a2b..9ad311e 100644
--- a/client/workspaces/ppt/canvas/views/CreationStart.tsx
+++ b/client/workspaces/ppt/canvas/views/CreationStart.tsx
@@ -372,9 +372,12 @@ export function CreationStart({
// The blue-to-indigo gradient was the loudest element on
// the screen; the solid variant carries the same weight
// without introducing a second hue.
- className="w-full h-auto py-5 text-base font-medium rounded-xl shadow-soft hover:shadow-soft-lg"
+ className="w-full h-auto py-5 text-lg font-semibold tracking-[-0.01em] rounded-xl shadow-soft hover:shadow-soft-lg"
>
- {progress.message ? <Loader2 className="w-5 h-5 mr-2 animate-spin" /> : <Sparkles className="w-5 h-5 mr-2" />}
+ {/* `size-5`, not `w-5 h-5`: the button's own
+ `[&_svg:not([class*='size-'])]:size-4` rule outranks a
+ plain width/height pair, so these icons were 16px. */}
+ {progress.message ? <Loader2 className="size-5 mr-2 animate-spin" /> : <Sparkles className="size-5 mr-2" />}
{progress.message || (creationMode === "beautify" ? tr("开始渲染", "Start rendering") : creationMode === "image_transform" ? tr("开始转化", "Start transform") : creationMode === "idea" ? tr("开始生成大纲", "Generate outline") : tr("载入大纲", "Load outline"))}
</Button>
</div>
diff --git a/client/workspaces/ppt/canvas/views/DeckView.tsx b/client/workspaces/ppt/canvas/views/DeckView.tsx
index f68d945..25b3cda 100644
--- a/client/workspaces/ppt/canvas/views/DeckView.tsx
+++ b/client/workspaces/ppt/canvas/views/DeckView.tsx
@@ -20,6 +20,13 @@ import {
ContextMenuTrigger,
} from "@/shared/ui/context-menu";
import { Button } from "@/shared/ui/button";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/shared/ui/select";
import {
Dialog,
DialogContent,
@@ -357,28 +364,42 @@ export function DeckView({
{status.isGeneratingImage ? <Loader2 className="w-3 h-3 mr-1 animate-spin" /> : null}
{tr("重新渲染本页", "Regenerate this slide")}
</Button>
+ {/* A bare <select> here rendered the OS widget -- system font, system
+ chevron, system dropdown -- inside a card that is otherwise all
+ tokens. The styled primitive already existed and had no callers. */}
{deck.currentSlide && deck.getVisibleVersions(deck.currentSlide.id).length > 0 && (
- <select
- className="h-7 text-xs rounded-md border border-input bg-background px-2"
- value={deck.currentVersionId}
- onChange={(e) => {
+ <Select
+ value={deck.currentVersionId || undefined}
+ onValueChange={(versionId) => {
const slideId = deck.currentSlide!.id;
- const versionId = e.target.value;
const versions = deck.getVisibleVersions(slideId);
- const v = versions.find(x => x.id === versionId);
- if (v) {
+ if (versions.some((x) => x.id === versionId)) {
deck.setVersionIdBySlide(prev => ({ ...prev, [slideId]: versionId }));
}
}}
>
- {deck.getVisibleVersions(deck.currentSlide.id).map((v, idx) => (
- <option key={v.id} value={v.id}>
- {v.type === "derived_textless"
- ? deck.formatVersionLabel(v, idx)
- : `${deck.formatVersionLabel(v, idx)} · ${new Date(v.timestamp).toLocaleString()}`}
- </option>
- ))}
- </select>
+ <SelectTrigger
+ size="sm"
+ aria-label={tr("选择版本", "Select version")}
+ className="h-7 max-w-[260px] gap-1.5 rounded-md border-border/70 px-2 text-xs shadow-none"
+ >
+ <SelectValue placeholder={tr("选择版本", "Select version")} />
+ </SelectTrigger>
+ <SelectContent align="start" className="max-w-[320px]">
+ {deck.getVisibleVersions(deck.currentSlide.id).map((v, idx) => (
+ <SelectItem key={v.id} value={v.id} className="text-xs">
+ <span className="flex min-w-0 items-baseline gap-2">
+ <span className="shrink-0 font-medium">{deck.formatVersionLabel(v, idx)}</span>
+ {v.type !== "derived_textless" && (
+ <span className="truncate text-[11px] text-muted-foreground tabular-nums">
+ {new Date(v.timestamp).toLocaleString()}
+ </span>
+ )}
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
)}
</div>
{status.currentSlideFailure ? (
diff --git a/client/workspaces/ppt/chat/code-block.tsx b/client/workspaces/ppt/chat/code-block.tsx
index ca4267d..caf8f4b 100644
--- a/client/workspaces/ppt/chat/code-block.tsx
+++ b/client/workspaces/ppt/chat/code-block.tsx
@@ -1,6 +1,7 @@
import { useMemo, useRef, useState } from 'react';
-import { Highlight, type Language } from "prism-react-renderer";
+import { Highlight } from "prism-react-renderer";
import { syntaxTheme } from "@/shared/chat/syntax-theme";
+import { toPrismLanguage } from "@/shared/chat/code-format";
import { Shimmer } from "@/shared/chat/shimmer";
import { useUiLanguage } from "@/shared/i18n";
import { ChevronRight } from 'lucide-react';
@@ -24,33 +25,7 @@ export function CodeBlock({ code, language = "xml", isStreaming = false, blockId
const preRef = useRef<HTMLPreElement | null>(null);
const normalizedLanguage = useMemo(() => (language || "text").toLowerCase(), [language]);
const normalizedCode = useMemo(() => String(code ?? ""), [code]);
- const prismLanguage = useMemo<Language>(() => {
- const lang = normalizedLanguage;
- if (lang === "svg") return "xml";
- if (lang === "yml") return "yaml";
- if (lang === "shell" || lang === "sh" || lang === "zsh") return "bash";
- if (lang === "ts") return "typescript";
- if (lang === "tsx") return "tsx";
- if (lang === "js") return "javascript";
- if (lang === "md") return "markdown";
- const allowed = new Set([
- "text",
- "xml",
- "json",
- "javascript",
- "typescript",
- "tsx",
- "jsx",
- "python",
- "bash",
- "yaml",
- "markdown",
- "css",
- "html",
- ]);
- if (allowed.has(lang)) return lang as Language;
- return "text";
- }, [normalizedLanguage]);
+ const prismLanguage = useMemo(() => toPrismLanguage(normalizedLanguage), [normalizedLanguage]);
const setOpen = (open: boolean) => {
setIsOpen(open);
@@ -94,10 +69,9 @@ export function CodeBlock({ code, language = "xml", isStreaming = false, blockId
}) => (
<pre
ref={preRef}
- className="text-[11px] leading-relaxed overflow-x-hidden overflow-y-auto overscroll-contain max-h-[500px] scrollbar-thin p-3 whitespace-pre-wrap break-words"
+ className="text-[11px] leading-relaxed overflow-x-hidden overflow-y-auto overscroll-contain max-h-[500px] scrollbar-thin p-3 whitespace-pre-wrap break-words font-mono"
style={{
...style,
- fontFamily: "var(--font-mono), ui-monospace, monospace",
backgroundColor: "transparent",
margin: 0,
}}