Skip to content

Commit 803e7f4

Browse files
committed
Mermaid block support
1 parent 47a20df commit 803e7f4

13 files changed

Lines changed: 2359 additions & 17 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ markdoc-*.tar
3535
npm-debug.log
3636
/assets/node_modules/
3737

38+
/node_modules
39+
/storage

frontend/package-lock.json

Lines changed: 1452 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
"@blocknote/core": "^0.44.0",
1414
"@blocknote/mantine": "^0.44.0",
1515
"@blocknote/react": "^0.44.0",
16+
"@types/react-syntax-highlighter": "^15.5.13",
17+
"mermaid": "^11.12.2",
1618
"nanoid": "^5.1.6",
1719
"phoenix": "^1.8.2",
1820
"react": "^19.2.0",
1921
"react-dom": "^19.2.0",
22+
"react-syntax-highlighter": "^16.1.0",
2023
"shiki": "^3.19.0",
2124
"yjs": "^13.6.27"
2225
},

frontend/src/components/Editor.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,37 @@ const insertChatBlockItem = (editor: BlockNoteEditor<any, any, any>) => ({
7676
subtext: "Start a collaborative chat discussion",
7777
});
7878

79-
// Get all slash menu items including chat block
79+
// Custom slash menu item for Mermaid block
80+
const insertMermaidBlockItem = (editor: BlockNoteEditor<any, any, any>) => ({
81+
title: "Mermaid Diagram",
82+
onItemClick: () => {
83+
const currentBlock = editor.getTextCursorPosition().block;
84+
editor.insertBlocks(
85+
[{
86+
type: "mermaid" as any,
87+
props: {
88+
diagramId: nanoid(),
89+
title: "Mermaid Diagram",
90+
minimized: false,
91+
height: 400,
92+
width: 600,
93+
}
94+
}],
95+
currentBlock.id,
96+
"after"
97+
);
98+
},
99+
aliases: ["mermaid", "diagram", "flowchart", "chart", "graph"],
100+
group: "Other",
101+
icon: "📊" as any,
102+
subtext: "Create a Mermaid flowchart or diagram",
103+
});
104+
105+
// Get all slash menu items including custom blocks
80106
const getCustomSlashMenuItems = (editor: BlockNoteEditor<any, any, any>) => [
81107
...getDefaultReactSlashMenuItems(editor),
82108
insertChatBlockItem(editor),
109+
insertMermaidBlockItem(editor),
83110
];
84111

85112
// Filter slash menu items based on query
@@ -401,6 +428,7 @@ export function Editor({ docId }: EditorProps) {
401428
editor={editor}
402429
docId={docId}
403430
onNewDocument={handleNewDocument}
431+
yDoc={doc}
404432
/>
405433
)}
406434
</div>

frontend/src/components/ExportMenu.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import { useState } from "react";
99
import type { BlockNoteEditor } from "@blocknote/core";
10+
import type * as Y from "yjs";
1011
import {
1112
exportToMarkdown,
1213
exportToHTML,
@@ -17,9 +18,10 @@ interface ExportMenuProps {
1718
editor: BlockNoteEditor<any, any, any>;
1819
docId: string;
1920
onNewDocument: () => void;
21+
yDoc?: Y.Doc;
2022
}
2123

22-
export function ExportMenu({ editor, docId, onNewDocument }: ExportMenuProps) {
24+
export function ExportMenu({ editor, docId, onNewDocument, yDoc }: ExportMenuProps) {
2325
const [isOpen, setIsOpen] = useState(false);
2426

2527
const handleNewDocument = () => {
@@ -32,7 +34,7 @@ export function ExportMenu({ editor, docId, onNewDocument }: ExportMenuProps) {
3234

3335
switch (format) {
3436
case "markdown":
35-
await exportToMarkdown(editor, docId);
37+
await exportToMarkdown(editor, docId, yDoc);
3638
break;
3739
case "html":
3840
await exportToHTML(editor, docId);

frontend/src/components/chat/ChatBlock.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface EditorContextData {
3030
userName: string;
3131
userColor: string;
3232
presenceUsers: Record<string, UserPresence>;
33+
awareness?: any; // Optional awareness for collaborative features
3334
}
3435

3536
export const EditorContext = createContext<EditorContextData | null>(null);

0 commit comments

Comments
 (0)