Skip to content

Mermaid import export - #1

Merged
Kalter666 merged 3 commits into
mainfrom
mermaid-import-export
Jul 27, 2026
Merged

Mermaid import export#1
Kalter666 merged 3 commits into
mainfrom
mermaid-import-export

Conversation

@Kalter666

Copy link
Copy Markdown
Owner

No description provided.

Kalter666 and others added 3 commits July 27, 2026 13:38
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>
@Kalter666
Kalter666 merged commit cb690a7 into main Jul 27, 2026
1 check passed
@Kalter666
Kalter666 deleted the mermaid-import-export branch July 27, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant