mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00

git-subtree-dir: _regroup/ckeditor5-mermaid git-subtree-mainline: 90c0f417131d254e86a4a4ab391122cad0930db7 git-subtree-split: c15257da7e57b6303fda9744ee4153d1c5311d6f
53 lines
983 B
JavaScript
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;
|
|
}
|
|
}
|