import type { MouseEvent } from "react"; import type { EditorView } from "@codemirror/view"; import { executeMarkdownEditorCommand, getMarkdownEditorCommand } from "./markdown-editor-commands"; import { MarkdownTableTool } from "./MarkdownTableTool"; interface MarkdownToolbarProps { editorView: EditorView | null; } const toolbarGroups = [ ["undo", "redo"], ["bold", "italic", "strikethrough", "inline-code"], [ "code-block", "quote", "unordered-list", "ordered-list", "task-list" ], ["table", "horizontal-rule"] ] as const; function preserveEditorSelection(event: MouseEvent) { event.preventDefault(); } export function MarkdownToolbar({ editorView }: MarkdownToolbarProps) { function execute(commandId: string) { if (!editorView) { return; } executeMarkdownEditorCommand(commandId, { view: editorView }); } return (
{toolbarGroups.map((group, groupIndex) => (
{group.map((commandId) => { if (commandId === "table") { return ( ); } const command = getMarkdownEditorCommand(commandId); if (!command) { return null; } const disabled = !editorView || (command.isEnabled?.({ view: editorView }) === false); return ( ); })}
))}
); }