Features
Libraries
A diagram block written in Mermaid, with a source pane while editing and the drawing when read.
Installation#
bash
pnpm dlx shadcn@latest add @zui/document-editor @zui/editor-mermaidUsage#
tsx
import type { DocJSON, IEditor } from '@zeroxsolutions/editor-core/document/core/index';
import { mermaid } from '@/components/editor/document/features/mermaid';
import { standardKit } from '@/components/editor/document/features/standard';
import { Editor } from '@/components/editor/document/react';tsx
const features = [standardKit(), mermaid()];
function NotesEditor({ content }: { content: DocJSON }) {
return <Editor features={features} content={content} />;
}mermaid adds the mermaid block, whose source attribute holds the diagram. While editing it shows a source pane beside a drawing, and when read only the drawing. Its slash item is "Mermaid" and its command insertMermaid takes an optional source.
Run the command on the editor that Editor hands to onReady, as Document Editor shows:
tsx
function insert(editor: IEditor) {
editor.run('insertMermaid', { source: 'flowchart LR\n A --> B' });
}The Viewer draws the same block, with the same feature in its features, wherever a stored document is only read.