feat: add comment button to mermaid diagram toolbar

Allow users to comment on mermaid diagrams via the selection toolbar,
matching the existing comment-on-image pattern.

https://claude.ai/code/session_01E7BvJCgSpXJZdQEqj9mHgs
This commit is contained in:
Claude
2026-05-23 16:30:25 +00:00
parent 92be631350
commit 864079e30b
2 changed files with 22 additions and 1 deletions
+14 -1
View File
@@ -1,4 +1,10 @@
import { CopyIcon, EditIcon, ExpandedIcon, TextWrapIcon } from "outline-icons";
import {
CommentIcon,
CopyIcon,
EditIcon,
ExpandedIcon,
TextWrapIcon,
} from "outline-icons";
import type { Node as ProseMirrorNode } from "prosemirror-model";
import { NodeSelection } from "prosemirror-state";
import type { EditorState } from "prosemirror-state";
@@ -71,6 +77,13 @@ export default function codeMenuItems(
shortcut: `${metaDisplay} Enter`,
visible: isMermaid(node) && !isEditingMermaid && !readOnly,
},
{
name: "commentOnMermaid",
icon: <CommentIcon />,
tooltip: t("Comment"),
shortcut: `${metaDisplay}+⌥+M`,
visible: isMermaid(node) && !isEditingMermaid && !readOnly,
},
{
name: "separator",
},
+8
View File
@@ -20,6 +20,7 @@ import { toast } from "sonner";
import type { Primitive } from "utility-types";
import type { UserPreferences } from "../../types";
import { isBrowser, isMac } from "../../utils/browser";
import { addComment } from "../commands/comment";
import backspaceToParagraph from "../commands/backspaceToParagraph";
import {
newlineInCode,
@@ -151,6 +152,8 @@ function buildCollapseState(
type CodeFenceOptions = {
/** Display preferences for the logged in user, if any. */
userPreferences?: UserPreferences | null;
/** The id of the current user, used for comment attribution. */
userId?: string;
};
export default class CodeFence extends Node<CodeFenceOptions> {
@@ -178,6 +181,9 @@ export default class CodeFence extends Node<CodeFenceOptions> {
default: false,
validate: "boolean",
},
marks: {
default: undefined,
},
},
content: "text*",
marks: "comment",
@@ -333,6 +339,8 @@ export default class CodeFence extends Node<CodeFenceOptions> {
}
return true;
},
commentOnMermaid: (): Command =>
addComment({ userId: this.options.userId }),
copyToClipboard: (): Command => (state, dispatch) => {
const codeBlock = findParentNode(isCode)(state.selection);