diff --git a/packages/ckeditor5/src/augmentation.ts b/packages/ckeditor5/src/augmentation.ts index b8e34fec0..2b2b2e84e 100644 --- a/packages/ckeditor5/src/augmentation.ts +++ b/packages/ckeditor5/src/augmentation.ts @@ -8,6 +8,7 @@ declare global { interface EditorComponent extends Component { loadReferenceLinkTitle($el: JQuery, href: string): Promise; createNoteForReferenceLink(title: string): Promise; + loadIncludedNote(noteId: string, $el: JQuery): void; } var glob: { diff --git a/_regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/icons/note.svg b/packages/ckeditor5/src/icons/note.svg similarity index 100% rename from _regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/icons/note.svg rename to packages/ckeditor5/src/icons/note.svg diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts index 26b4d310c..61c428d6a 100644 --- a/packages/ckeditor5/src/plugins.ts +++ b/packages/ckeditor5/src/plugins.ts @@ -11,6 +11,7 @@ import SpecialCharactersEmojiPlugin from "./plugins/special_characters_emoji.js" import IndentBlockShortcutPlugin from "./plugins/indent_block_shortcut.js"; import MarkdownImportPlugin from "./plugins/markdownimport.js"; import MentionCustomization from "./plugins/mention_customization.js"; +import IncludeNote from "./plugins/includenote.js"; const TRILIUM_PLUGINS: typeof Plugin[] = [ CutToNotePlugin, @@ -23,7 +24,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [ SpecialCharactersEmojiPlugin, IndentBlockShortcutPlugin, MarkdownImportPlugin, - MentionCustomization + MentionCustomization, + IncludeNote ]; export const COMMON_PLUGINS: typeof Plugin[] = [ diff --git a/_regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/includenote.js b/packages/ckeditor5/src/plugins/includenote.ts similarity index 85% rename from _regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/includenote.js rename to packages/ckeditor5/src/plugins/includenote.ts index 72a465c47..c6dd615ba 100644 --- a/_regroup/ckeditor5-build-trilium/packages/ckeditor5-build-trilium/src/includenote.js +++ b/packages/ckeditor5/src/plugins/includenote.ts @@ -1,9 +1,5 @@ -import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; -import {toWidget} from '@ckeditor/ckeditor5-widget/src/utils'; -import Widget from '@ckeditor/ckeditor5-widget/src/widget'; -import Command from '@ckeditor/ckeditor5-core/src/command'; -import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; -import noteIcon from './icons/note.svg'; +import { ButtonView, Command, Plugin, toWidget, Widget, type Editor, type Observable } from 'ckeditor5'; +import noteIcon from '../icons/note.svg?raw'; export default class IncludeNote extends Plugin { static get requires() { @@ -34,7 +30,9 @@ class IncludeNoteUI extends Plugin { } ); // Bind the state of the button to the command. - buttonView.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); + if (command) { + buttonView.bind( 'isOn', 'isEnabled' ).to( command as Observable & { value: boolean; } & { isEnabled: boolean; }, 'value', 'isEnabled' ); + } // Execute the command when the button is clicked (executed). this.listenTo( buttonView, 'execute', () => editor.execute( 'insertIncludeNote' ) ); @@ -103,7 +101,7 @@ class IncludeNoteEditing extends Plugin { model: 'includeNote', view: ( modelElement, { writer: viewWriter } ) => { - const noteId = modelElement.getAttribute( 'noteId' ); + const noteId = modelElement.getAttribute( 'noteId' ) as string; const boxSize = modelElement.getAttribute( 'boxSize' ); const section = viewWriter.createContainerElement( 'section', { @@ -119,7 +117,7 @@ class IncludeNoteEditing extends Plugin { const domElement = this.toDomElement( domDocument ); const editorEl = editor.editing.view.getDomRoot(); - const component = glob.getComponentByEl( editorEl ); + const component = glob.getComponentByEl( editorEl ); component.loadIncludedNote( noteId, $( domElement ) ); @@ -147,7 +145,8 @@ class InsertIncludeNoteCommand extends Command { refresh() { const model = this.editor.model; const selection = model.document.selection; - const allowedIn = model.schema.findAllowedParent( selection.getFirstPosition(), 'includeNote' ); + const firstPosition = selection.getFirstPosition(); + const allowedIn = firstPosition && model.schema.findAllowedParent( firstPosition, 'includeNote' ); this.isEnabled = allowedIn !== null; } @@ -157,7 +156,7 @@ class InsertIncludeNoteCommand extends Command { * Hack coming from https://github.com/ckeditor/ckeditor5/issues/4465 * Source issue: https://github.com/zadam/trilium/issues/1117 */ -function preventCKEditorHandling( domElement, editor ) { +function preventCKEditorHandling( domElement: HTMLElement, editor: Editor ) { // Prevent the editor from listening on below events in order to stop rendering selection. // commenting out click events to allow link click handler to still work @@ -168,9 +167,10 @@ function preventCKEditorHandling( domElement, editor ) { // Prevents TAB handling or other editor keys listeners which might be executed on editors selection. domElement.addEventListener( 'keydown', stopEventPropagationAndHackRendererFocus, { capture: true } ); - function stopEventPropagationAndHackRendererFocus( evt ) { + function stopEventPropagationAndHackRendererFocus( evt: Event ) { evt.stopPropagation(); // This prevents rendering changed view selection thus preventing to changing DOM selection while inside a widget. + //@ts-expect-error: We are accessing a private field. editor.editing.view._renderer.isFocused = false; } }