From 14bb42edee3d6fee6be264e3ee78670b3b9cee79 Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:35:28 +0100 Subject: [PATCH] feat(editor): lay Mermaid diagrams out with Pele (mermaid-to-excalidraw v3) (#12480) * chore: type-check linked packages' `@excalidraw/excalidraw/{element,common}/*` imports against the sources Packages linked into the monorepo (e.g. a local `@excalidraw/mermaid-to-excalidraw`) import types from `@excalidraw/excalidraw/element/*` and `.../common/*`, which didn't map to the sources and fell back to the linked package's own (published) copy of `@excalidraw/excalidraw`, failing the type check. The mocked arrows in the Mermaid tests now use the `LocalPoint` their points are typed as. Claude Opus 5.5 (xhigh) * feat(editor): TTD Mermaid errors on their source line, with guidance by diagram type - Mermaid (and Pele) number lines as they parse the definition: without its front matter, directives, comment lines and leading blank lines (and in flowcharts and ER diagrams, a line ending with a comment runs on into the next one). Errors are now mapped back to the line of the source they're on for the highlighted line, the summary, the shown message, the auto-fixer and the AI repair prompt. Errors past the end (e.g. a missing `end`) are on its last non-empty line. - The likely causes depend on the diagram type: an unclosed class body, composite state or entity (not "a decision node"), sequence blocks missing their `end`, labels with brackets or parentheses that need quoting, `end` used as a node. - Definitions without a (known) diagram type get a summary and hint, and their first line is highlighted. Mermaid and Pele word that error differently. Claude Opus 5.5 (xhigh) * feat(editor): auto-fix more common Mermaid mistakes in TTD New auto-fix candidates (each still only offered if it parses): - quote labels with brackets or parentheses in them: `A[Process (main)]` -> `A["Process (main)"]` - close unclosed blocks (`subgraph`/`loop`/... `end`s, class/state/entity `}`s) where their indentation ends, not only at the end of the definition - close a node label left open before its edge (`A[Start --> B` -> `A[Start] --> B`), and drop closing brackets that close nothing - `->` -> `-->` in flowcharts and state diagrams (labels left alone) - `end` used as a flowchart node -> `End` - the `:` missing before a sequence message's or ER relationship's label - an invalid flowchart direction -> `TD` - a misspelled diagram type (`flowchar TD`, `sequencediagram`), or a missing one Claude Opus 5.5 (xhigh) * feat(editor): fix and explain invalid or misplaced directions in TTD Mermaid - A flowchart subgraph's `direction` is uppercased (`lr` -> `LR`), `TD` is `TB` there (unlike in the flowchart's header), and one that isn't any direction is dropped, for the subgraph to keep the flowchart's. - A direction on the first line of a class, state or ER diagram (`classDiagram LR`, `erDiagram direction LR`) is moved to a `direction` statement on the next line, unless the diagram has one already. - Sequence diagrams have no direction: it's dropped from their first line and their `direction` statements. - The likely causes explain all of these. Claude Opus 5.5 (xhigh) * feat(editor): mark TTD assistant messages rendered with Pele Assistant messages are saved with the chat with `renderer: "pele"`, to tell their diagrams from those of chats saved before mermaid-to-excalidraw v3, which Mermaid rendered (and which can't be told apart later). Claude Opus 5.5 (xhigh) * feat(editor): paste `swimlane-beta` diagrams as Mermaid mermaid-to-excalidraw v3 converts them (Pele renders them, Mermaid doesn't), but pasting one inserted it as text, as `swimlane` wasn't a diagram type that marks pasted text as Mermaid. Claude Opus 5.5 (xhigh) * feat(editor): lay Mermaid diagrams out with Pele (mermaid-to-excalidraw 3.0.0) mermaid-to-excalidraw 3.0.0 parses and lays out diagrams with Pele instead of Mermaid, which is no longer bundled. It keeps labels where Pele placed them along their arrows with `label.labelPosition`, which skeleton arrows support since #12425. Claude Opus 5.5 (xhigh) * docs: changelog for mermaid-to-excalidraw v3 and skeleton bound arrows Claude Opus 5.5 (xhigh) --- packages/excalidraw/CHANGELOG.md | 6 + .../components/TTDDialog/Chat/useChatAgent.ts | 3 + .../components/TTDDialog/TTDDialogOutput.tsx | 2 +- .../components/TTDDialog/TextToDiagram.tsx | 6 +- .../excalidraw/components/TTDDialog/types.ts | 6 + .../TTDDialog/utils/mermaidAutoFix.test.ts | 252 ++++++ .../TTDDialog/utils/mermaidAutoFix.ts | 468 +++++++++- .../TTDDialog/utils/mermaidError.test.ts | 184 ++++ .../TTDDialog/utils/mermaidError.ts | 292 +++++- packages/excalidraw/mermaid.test.ts | 3 + packages/excalidraw/mermaid.ts | 2 + packages/excalidraw/package.json | 2 +- .../tests/MermaidToExcalidraw.test.tsx | 8 +- .../tests/renderEnvironmentLabels.test.tsx | 5 +- tsconfig.json | 2 + yarn.lock | 848 +----------------- 16 files changed, 1227 insertions(+), 862 deletions(-) diff --git a/packages/excalidraw/CHANGELOG.md b/packages/excalidraw/CHANGELOG.md index 690dfbc91f..95630ea3b8 100644 --- a/packages/excalidraw/CHANGELOG.md +++ b/packages/excalidraw/CHANGELOG.md @@ -162,6 +162,8 @@ The toolbar UI was rewritten from hidden radio/checkbox inputs to real `