Started to rewrite CKEDITOR placeholder plugin for CKEDITOR5.

This commit is contained in:
Jan Böhmer 2022-07-29 01:03:17 +02:00
parent a33e93826a
commit eba89cee62
8 changed files with 374 additions and 1 deletions

View file

@ -0,0 +1,31 @@
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;
}
}