mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-31 20:22:27 +08:00
30 lines
935 B
TypeScript
30 lines
935 B
TypeScript
![]() |
import { ButtonView, Plugin } from 'ckeditor5';
|
||
|
import dateTimeIcon from '../icons/date-time.svg?raw';
|
||
|
|
||
|
export default class InsertDateTimePlugin extends Plugin {
|
||
|
init() {
|
||
|
const editor = this.editor;
|
||
|
|
||
|
editor.ui.componentFactory.add('dateTime', locale => {
|
||
|
const view = new ButtonView( locale );
|
||
|
|
||
|
view.set( {
|
||
|
label: 'Date time',
|
||
|
icon: dateTimeIcon,
|
||
|
tooltip: true
|
||
|
} );
|
||
|
|
||
|
// enable internal link only if the editor is not read only
|
||
|
view.bind('isEnabled').to(editor, 'isReadOnly', isReadOnly => !isReadOnly);
|
||
|
|
||
|
view.on('execute', () => {
|
||
|
const editorEl = editor.editing.view.getDomRoot();
|
||
|
const component = glob.getComponentByEl(editorEl);
|
||
|
|
||
|
component.triggerCommand('insertDateTimeToText');
|
||
|
} );
|
||
|
|
||
|
return view;
|
||
|
});
|
||
|
}
|
||
|
}
|