diff --git a/apps/client/src/widgets/type_widgets/ckeditor/config.ts b/apps/client/src/widgets/type_widgets/ckeditor/config.ts index 5a3262a1c..3ea962610 100644 --- a/apps/client/src/widgets/type_widgets/ckeditor/config.ts +++ b/apps/client/src/widgets/type_widgets/ckeditor/config.ts @@ -189,7 +189,7 @@ export function buildClassicToolbar(multilineToolbar: boolean) { { label: "Insert", icon: "plus", - items: ["imageUpload", "|", "link", "bookmark", "internallink", "includeNote", "|", "specialCharacters", "emoji", "math", "mermaid", "horizontalLine", "pageBreak"] + items: ["imageUpload", "|", "link", "bookmark", "internallink", "includeNote", "|", "specialCharacters", "emoji", "math", "mermaid", "horizontalLine", "pageBreak", "dateTime"] }, "|", "outdent", @@ -244,7 +244,7 @@ export function buildFloatingToolbar() { { label: "Insert", icon: "plus", - items: ["internallink", "includeNote", "|", "math", "mermaid", "horizontalLine", "pageBreak"] + items: ["internallink", "includeNote", "|", "math", "mermaid", "horizontalLine", "pageBreak", "dateTime"] }, "|", "outdent", diff --git a/packages/ckeditor5/src/icons/date-time.svg b/packages/ckeditor5/src/icons/date-time.svg new file mode 100644 index 000000000..8e8907da6 --- /dev/null +++ b/packages/ckeditor5/src/icons/date-time.svg @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts index 39932ef6d..ea68af89d 100644 --- a/packages/ckeditor5/src/plugins.ts +++ b/packages/ckeditor5/src/plugins.ts @@ -5,6 +5,7 @@ import UploadimagePlugin from "./plugins/uploadimage.js"; import ItalicAsEmPlugin from "./plugins/italic_as_em.js"; import StrikethroughAsDel from "./plugins/strikethrough_as_del.js"; import InternalLinkPlugin from "./plugins/internallink.js"; +import InsertDateTimePlugin from "./plugins/insertDateTime.js"; import ReferenceLink from "./plugins/referencelink.js"; import RemoveFormatLinksPlugin from "./plugins/remove_format_links.js"; import IndentBlockShortcutPlugin from "./plugins/indent_block_shortcut.js"; @@ -36,6 +37,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [ ItalicAsEmPlugin, StrikethroughAsDel, InternalLinkPlugin, + InsertDateTimePlugin, RemoveFormatLinksPlugin, IndentBlockShortcutPlugin, MarkdownImportPlugin, diff --git a/packages/ckeditor5/src/plugins/insertDateTime.ts b/packages/ckeditor5/src/plugins/insertDateTime.ts new file mode 100644 index 000000000..c614eb9f6 --- /dev/null +++ b/packages/ckeditor5/src/plugins/insertDateTime.ts @@ -0,0 +1,30 @@ +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; + }); + } +} \ No newline at end of file