Library

mermaid-editor

A React component for editing Mermaid diagrams. You click and drag on the drawing, and the value stays plain Mermaid text. An edit changes only the lines it has to.

Why I built it

Mermaid diagrams are text, so every change means editing the syntax by hand. A drawing tool would lose the text. I wanted to edit on the drawing and keep the text as the source, with only the changed lines touched.

Install from npm Get started View source @dinesh-gamage/mermaid-editor
LibrariesDev toolsv0.1.0MITReact 18 or 19Mermaid 11+Open source
On npm
1 / 2
Features

What it does

01

Edit on the drawing

Flowcharts are edited where you see them. Here is one edit, step by step.

  1. 1

    Click a node

    A panel opens with its label, shape and group. You can also connect it to another node or delete it.

    The Orders API node is selected
  2. 2

    Change it

    Rename it to Checkout API. The drawing updates, and only that line of text changes.

    The new label in the drawing and the text
  3. 3

    Arrows too

    Click an arrow to change its label, line and ends, or to reverse it. Drag from one node to another to add one.

    An arrow is selected
02

Sequence diagrams

Add, rename and reorder participants. Add messages and notes, and move them up and down. Wrap steps in loop, alt, opt, par, critical or break blocks.

A sequence diagram with a message selected
03

Only the lines it has to

Comments, styles and lines the editor does not understand stay exactly as written. Here the label changes and nothing else does.

Before
%% checkout flow
flowchart LR
  shop[Shop] --> api{{Orders API}}
  api --> db[(Orders DB)]
  classDef hot fill:#f96
  class api hot
After renaming the node
%% checkout flow
flowchart LR
  shop[Shop] --> api{{Checkout API}}
  api --> db[(Orders DB)]
  classDef hot fill:#f96
  class api hot
04

Every other kind as text

State diagrams, class diagrams and the rest are edited as text, with a live drawing next to it.

A state diagram in text mode
05

Use the text operations on their own

The functions behind the editor work without React, in a script or on a server. Each takes Mermaid text and returns Mermaid text.

script.ts
import { flowchart } from '@dinesh-gamage/mermaid-editor/core'

const next = flowchart.setNodeText(text, 'api', 'Checkout API')
  • 06

    Themeable

    Every color and size is a CSS custom property on .mmde. Set them on the editor or on any parent.

  • 07

    Mermaid places the nodes

    Mermaid text holds no positions, so nodes cannot be placed by hand. Mermaid arranges the diagram.

How to use

Get started

Read the full docs
  1. 1

    Install

    Mermaid, React and React DOM are peers, so your app keeps one copy of each.

    $npm install @dinesh-gamage/mermaid-editor mermaid
  2. 2

    Add the editor

    Pass Mermaid text in, and get the new text back after every edit.

    import { useState } from 'react'
    import { MermaidEditor } from '@dinesh-gamage/mermaid-editor'
    
    function Example() {
      const [text, setText] = useState('flowchart LR\n  web[Web site] --> api{{API}}')
      return <MermaidEditor value={text} onChange={setText} />
    }