Part-DB.Part-DB-server/assets/ckeditor/plugins/PartDBLabel/PartDBLabelCommand.js

31 lines
1 KiB
JavaScript
Raw Normal View History

import Command from '@ckeditor/ckeditor5-core/src/command';
export default class PartDBLabelCommand extends Command {
execute( { value } ) {
const editor = this.editor;
const selection = editor.model.document.selection;
editor.model.change( writer => {
// Create a <placeholder> elment with the "name" attribute (and all the selection attributes)...
const placeholder = writer.createElement( 'partdb_label', {
...Object.fromEntries( selection.getAttributes() ),
name: value
} );
// ... and insert it into the document.
editor.model.insertContent( placeholder );
// Put the selection on the inserted element.
writer.setSelection( placeholder, 'on' );
} );
}
refresh() {
const model = this.editor.model;
const selection = model.document.selection;
const isAllowed = model.schema.checkChild( selection.focus.parent, 'partdb_label' );
this.isEnabled = isAllowed;
}
}