Notes/_regroup/ckeditor5-mermaid/src/commands/insertMermaidCommand.js
Elian Doran 178903f6b2 Add '_regroup/ckeditor5-mermaid/' from commit 'c15257da7e57b6303fda9744ee4153d1c5311d6f'
git-subtree-dir: _regroup/ckeditor5-mermaid
git-subtree-mainline: 90c0f417131d254e86a4a4ab391122cad0930db7
git-subtree-split: c15257da7e57b6303fda9744ee4153d1c5311d6f
2025-05-04 15:23:12 +03:00

53 lines
983 B
JavaScript

/**
* @module mermaid/insertmermaidcommand
*/
import { Command } from 'ckeditor5/src/core.js';
const MOCK_MERMAID_MARKUP = `flowchart TB
A --> B
B --> C`;
/**
* The insert mermaid command.
*
* Allows to insert mermaid.
*
* @extends module:core/command~Command
*/
export default class InsertMermaidCommand extends Command {
/**
* @inheritDoc
*/
refresh() {
const documentSelection = this.editor.model.document.selection;
const selectedElement = documentSelection.getSelectedElement();
if ( selectedElement && selectedElement.name === 'mermaid' ) {
this.isEnabled = false;
} else {
this.isEnabled = true;
}
}
/**
* @inheritDoc
*/
execute() {
const editor = this.editor;
const model = editor.model;
let mermaidItem;
model.change( writer => {
mermaidItem = writer.createElement( 'mermaid', {
displayMode: 'split',
source: MOCK_MERMAID_MARKUP
} );
model.insertContent( mermaidItem );
} );
return mermaidItem;
}
}