Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(diagram): keep flowchart palettes from reverting to forest green

tianma-if2217a48e96d9
diff --git a/apps/web/src/components/DiagramEditorPane.test.mjs b/apps/web/src/components/DiagramEditorPane.test.mjs
index 11451df3..f46de479 100644
--- a/apps/web/src/components/DiagramEditorPane.test.mjs
+++ b/apps/web/src/components/DiagramEditorPane.test.mjs
@@ -189,6 +189,10 @@ describe("diagram editor canvas surface", () => {
expect(source).toContain("flowchartEdgeIsStraight");
expect(source).toContain('showTheme={document.kind !== "architecture"}');
expect(source).toContain('themeCatalog={document.kind === "flowchart" ? "flowchart" : "mind-map"}');
+ expect(source).toContain('document?.kind === "flowchart"');
+ expect(source).toContain("resolveFlowchartTheme(document.theme)");
+ expect(source).toContain("resolveDiagramTheme(document?.theme)");
+ expect(source).not.toContain("const documentTheme = resolveDiagramTheme(document?.theme)");
expect(toolbarSource).toContain("showTheme = true");
expect(toolbarSource).toContain("themeCatalog = \"mind-map\"");
expect(toolbarSource).toContain("FLOWCHART_SELECTABLE_THEMES");
diff --git a/apps/web/src/components/DiagramEditorPane.tsx b/apps/web/src/components/DiagramEditorPane.tsx
index d16f3c34..2ac41953 100644
--- a/apps/web/src/components/DiagramEditorPane.tsx
+++ b/apps/web/src/components/DiagramEditorPane.tsx
@@ -84,6 +84,7 @@ import {
parseDiagramDocument,
resolveDiagramStructure,
resolveDiagramTheme,
+ resolveFlowchartTheme,
serializeDiagramDocument,
architectureEdgeVisual,
architectureIconOffset,
@@ -1356,7 +1357,9 @@ export const DiagramEditorPane = ({
const editSessionRef = useRef<MemoEditSession | null>(null);
const saveRef = useRef<() => void>(() => undefined);
const document = parseDiagramDocument(memo.contentMarkdown);
- const documentTheme = resolveDiagramTheme(document?.theme);
+ const documentTheme = document?.kind === "flowchart"
+ ? resolveFlowchartTheme(document.theme)
+ : resolveDiagramTheme(document?.theme);
const documentStructure = resolveDiagramStructure(document?.structure);
const [title, setTitle] = useState(memo.title ?? "");
const [tagsText, setTagsText] = useState(memo.tags.join(", "));
@@ -2475,20 +2478,23 @@ export const DiagramEditorPane = ({
const applyTheme = (nextTheme: DiagramTheme) => {
const graph = graphRef.current;
- if (nextTheme === theme) return;
- themeRef.current = nextTheme;
- setTheme(nextTheme);
+ const nextResolvedTheme = document?.kind === "flowchart"
+ ? resolveFlowchartTheme(nextTheme)
+ : resolveDiagramTheme(nextTheme);
+ if (nextResolvedTheme === theme) return;
+ themeRef.current = nextResolvedTheme;
+ setTheme(nextResolvedTheme);
if (!graph || readOnly) return;
applyGraphPalette(
graph,
- nextTheme,
+ nextResolvedTheme,
document?.kind ?? "flowchart",
appearanceRef.current,
structureRef.current,
);
setDirty(savedSnapshotRef.current !== diagramEditorSnapshot(
titleRef.current,
- graphToDocument(graph, document?.kind ?? "flowchart", nextTheme, structureRef.current),
+ graphToDocument(graph, document?.kind ?? "flowchart", nextResolvedTheme, structureRef.current),
));
};
diff --git a/packages/shared/src/diagram-flowchart-style.test.mjs b/packages/shared/src/diagram-flowchart-style.test.mjs
index 79aa4e68..7c6ca81e 100644
--- a/packages/shared/src/diagram-flowchart-style.test.mjs
+++ b/packages/shared/src/diagram-flowchart-style.test.mjs
@@ -71,6 +71,20 @@ describe("flowchart semantic paint", () => {
expect(resolveFlowchartSurface("light", "paper").canvas).toBe("#F6F1E8");
expect(resolveFlowchartSurface("light", "mint").terminator.stroke).toBe("#1A7A70");
});
+
+ test("keeps flowchart-only schemes instead of collapsing them onto mind-map brand", async () => {
+ const { resolveDiagramTheme } = await import("./diagram.ts");
+ for (const theme of ["ink", "paper", "island", "tea", "sun", "wa", "rose"]) {
+ expect(resolveFlowchartTheme(theme)).toBe(theme);
+ }
+ expect(resolveDiagramTheme("ink")).toBe("brand");
+ expect(resolveDiagramTheme("paper")).toBe("brand");
+ expect(resolveDiagramTheme("island")).toBe("dune");
+ expect(resolveDiagramTheme("tea")).toBe("slate");
+ expect(resolveDiagramTheme("sun")).toBe("sunrise");
+ expect(resolveDiagramTheme("wa")).toBe("marine");
+ expect(resolveDiagramTheme("rose")).toBe("blossom");
+ });
});
describe("flowchart node presentation", () => {