mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 10:18:56 +02:00
Started to rewrite CKEDITOR placeholder plugin for CKEDITOR5.
This commit is contained in:
parent
a33e93826a
commit
eba89cee62
8 changed files with 374 additions and 1 deletions
31
assets/ckeditor/plugins/PartDBLabel/PartDBLabelCommand.js
Normal file
31
assets/ckeditor/plugins/PartDBLabel/PartDBLabelCommand.js
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue