mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-24 13:12:56 +08:00
52 lines
962 B
JavaScript
52 lines
962 B
JavaScript
![]() |
/**
|
||
|
* @module mermaid/insertmermaidcommand
|
||
|
*/
|
||
|
|
||
|
import { Command } from 'ckeditor5/src/core';
|
||
|
|
||
|
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;
|
||
|
|
||
|
model.change( writer => {
|
||
|
const item = writer.createElement( 'mermaid', {
|
||
|
displayMode: 'split',
|
||
|
source: MOCK_MERMAID_MARKUP
|
||
|
} );
|
||
|
|
||
|
model.insertContent( item );
|
||
|
} );
|
||
|
|
||
|
editor.editing.view.focus();
|
||
|
}
|
||
|
}
|