mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 13:26:01 +01:00
feat(slash): insert date/time
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { ButtonView, Plugin } from 'ckeditor5';
|
||||
import { ButtonView, Command, Plugin } from 'ckeditor5';
|
||||
import dateTimeIcon from '../icons/date-time.svg?raw';
|
||||
|
||||
const COMMAND_NAME = 'insertDateTimeToText';
|
||||
|
||||
export default class InsertDateTimePlugin extends Plugin {
|
||||
init() {
|
||||
const editor = this.editor;
|
||||
|
||||
editor.commands.add(COMMAND_NAME, new InsertDateTimeCommand(editor));
|
||||
|
||||
editor.ui.componentFactory.add('dateTime', locale => {
|
||||
const view = new ButtonView( locale );
|
||||
|
||||
@@ -15,17 +19,30 @@ export default class InsertDateTimePlugin extends Plugin {
|
||||
} );
|
||||
|
||||
// enable only if the editor is not read only
|
||||
view.bind('isEnabled').to(editor, 'isReadOnly', isReadOnly => !isReadOnly);
|
||||
|
||||
const command = editor.commands.get(COMMAND_NAME)!;
|
||||
view.bind('isEnabled').to(command, 'isEnabled');
|
||||
view.on('execute', () => {
|
||||
const editorEl = editor.editing.view.getDomRoot();
|
||||
const component = glob.getComponentByEl(editorEl);
|
||||
|
||||
component.triggerCommand('insertDateTimeToText');
|
||||
editor.execute(COMMAND_NAME);
|
||||
editor.editing.view.focus();
|
||||
} );
|
||||
|
||||
});
|
||||
return view;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class InsertDateTimeCommand extends Command {
|
||||
|
||||
refresh() {
|
||||
this.isEnabled = !this.editor.isReadOnly;
|
||||
}
|
||||
|
||||
execute() {
|
||||
const editor = this.editor;
|
||||
const editorEl = editor.editing.view.getDomRoot();
|
||||
const component = glob.getComponentByEl(editorEl);
|
||||
|
||||
component.triggerCommand('insertDateTimeToText');
|
||||
editor.editing.view.focus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user