Mermaid import export - #1
Merged
Merged
Conversation
d2-blocks builds diagrams as blocks over a language-neutral block tree (box/link/group/style/direction). Mermaid flowcharts map onto that same tree, so bridge them without a new dependency or any editor changes. - src/mermaid.js: toMermaid/fromMermaid translating flowcharts <-> the block tree. Covers node shapes, edges + labels, subgraph<->group (incl. edges to a subgraph), direction, and style/classDef<->style blocks. Best-effort, not a round-trip guarantee: mermaid's dotted/thick edge lines collapse to plain (the model has no per-edge style), click/linkStyle/comments are dropped, and non-flowchart diagrams are rejected. - src/MermaidImport.svelte: paste modal whose live preview reuses the d2 engine (fromMermaid -> serialize -> draw), so it shows exactly what will be imported and validates in one pass. - App/store wiring: "Import Mermaid" + "Copy Mermaid"; mermaid()/importMermaid(). - src/mermaid.test.js: shapes, edge labels, subgraph, direction, style, and non-flowchart rejection. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The unit suite exercises the pure logic; nothing drove the running app. Add a Playwright suite (chromium, vite dev server) over the four interactive areas: block editing, the source<->blocks loop with undo/redo and the toolbar, the Examples and Mermaid modals with clipboard, and drag/drop nesting. Locators lean on existing roles/text/aria-labels; the d2 source textarea is the shared assertion surface since it reserialises the block tree on every edit independently of the canvas. open() waits for the cold WASM render to settle before driving the app. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
d2 runs in a single wasm worker, and draw() issues two separate awaited calls (compile, then render) to it. Concurrent draws — a fast edit during the cold ~6 MB first compile, or a modal preview firing while the canvas re-renders — interleaved on that one Go instance and handed back a corrupted SVG, which the sanitiser then rejected, blanking the canvas with a parse error. Route every draw through a one-at-a-time gate (new serial.js) so each compile+ render runs to completion before the next starts. Covered by serial.test.js and an e2e regression that edits during the cold render. Also add a Tests workflow running the unit and Playwright suites on pushes and PRs, and an html reporter so CI can upload the report. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.