Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(text): hand editor dialogs to the host through editor config
Elian Doran75050c0b9996
diff --git a/.claude/skills/ckeditor5-testing/references/patterns.md b/.claude/skills/ckeditor5-testing/references/patterns.mdindex 5b6390f87b..1ac7973eb9 100644--- a/.claude/skills/ckeditor5-testing/references/patterns.md+++ b/.claude/skills/ckeditor5-testing/references/patterns.md@@ -39,9 +39,11 @@ Host services that need no component come through the editor config, so a spec p`createTestEditor( plugins, { … } )` instead of mocking `glob`: `formatDateTime` (date/time),`referenceLink: { getTitle, getTitleSync }` (reference links), `linkEmbed` (link previews —`createLinkEmbedHost()` in `test/link-embed-kit.ts` builds the mocked entry), and `getNoteId` plus-`attachmentUpload: { getHeaders, getLocalUpload, getEmbedBoxSize }` (uploads). Each falls back to a-placeholder when left out (an upload without `getNoteId` is rejected), so a spec that does not-assert on it can omit it. A spec sharing one editor across tests can swap an entry with+`attachmentUpload: { getHeaders, getLocalUpload, getEmbedBoxSize }` (uploads), and the dialogs a+button hands over to the host: `internalLink: { openDialog }`, `markdownImport: { open }`,+`contentEmbed: { pickNote }` and `cutToNote: { cut, saveNow }`. Each falls back to a placeholder or a+no-op when left out (an upload without `getNoteId` is rejected), so a spec that does not assert on+it can omit it. A spec sharing one editor across tests can swap an entry with`editor.config.set()`, which the plugins read at call time.Many in-aggregate plugins still reach for a global `glob` (the Trilium bridge — typed in@@ -55,9 +57,9 @@ converter in `packages/ckeditor5/src/plugins/referencelink.ts`). Use the globalsimport { installGlobMock, mockClipboard } from '../../test/globals-test-kit.js';beforeEach( async () => {- const triggerCommand = vi.fn();- installGlobMock( { getComponentByEl: () => ( { triggerCommand } ) } ); // removed after the test- editor = await createTestEditor( [ Essentials, Paragraph, InternalLinkPlugin ] );+ const loadReferenceLinkTitle = vi.fn( async () => undefined );+ installGlobMock( { getComponentByEl: () => ( { loadReferenceLinkTitle } ) } ); // removed after the test+ editor = await createTestEditor( [ Essentials, Paragraph, ReferenceLink ] );} );// no afterEach: setup.ts runs the kit's cleanups (and destroys the editor)```diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex 1b1847fb95..855249d469 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -386,6 +386,7 @@ export type CommandMappings = {insertDateTimeToText: CommandData;pasteMarkdownIntoText: CommandData;cutIntoNote: CommandData;+ saveNoteDetailNow: CommandData;addIncludeNoteToText: CommandData;editReadOnlyNote: CommandData;toggleRibbonTabClassicEditor: CommandData;diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex cafc30dd2d..e25458b4fa 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -1572,10 +1572,10 @@ export function useLegacyImperativeHandlers(handlers: Record<string, Function>)** The counterpart of {@link useLegacyImperativeHandlers} — that hook writes methods onto the parent* component, and this is what lets a caller holding only a DOM node arrive at the same object. The- * text editor is the caller that matters: every one of its calls back into the app resolves the host- * that way (`glob.getComponentByEl(editor.editing.view.getDomRoot())` — reference-link titles,- * included notes, link embeds), so an editor mounted in a subtree whose parent component the DOM- * cannot name reaches whichever widget happens to enclose it and dies on the first of those calls.+ * text editor is the caller that matters: the calls that need state of the host component, such as+ * drawing reference-link titles and rendering included notes, find it with+ * `glob.getComponentByEl(editor.editing.view.getDomRoot())`. An editor in a subtree whose parent+ * component the DOM cannot name finds whichever widget encloses it, and fails on the first such call.** Only needed where a subtree provides a `ParentComponent` of its own. A component built as a widget* marks its own element (see `BasicWidget.render`), and a React tree mounted under one answers todiff --git a/apps/client/src/widgets/type_widgets/text/CKEditor.tsx b/apps/client/src/widgets/type_widgets/text/CKEditor.tsxindex 5400d42b58..d77632fa35 100644--- a/apps/client/src/widgets/type_widgets/text/CKEditor.tsx+++ b/apps/client/src/widgets/type_widgets/text/CKEditor.tsx@@ -286,7 +286,8 @@ export default function CKEditor({ containerRef: externalContainerRef, contentLatemplates: templatesRef.current,getNoteLocation: () => noteLocationRef.current,getNoteId: () => noteIdRef.current,- getComponentId: () => parentComponent?.componentId+ getComponentId: () => parentComponent?.componentId,+ triggerHostCommand: (command) => parentComponent?.triggerCommand(command)});if (isStale) {diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.tsindex 4bf19888cb..f61fdec4e6 100644--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts@@ -389,6 +389,24 @@ describe("CK config - tables", () => {expect(config.attachmentUpload?.getEmbedBoxSize?.("image/png", 1)).toBe("medium");});+ it("hands the dialogs and cut to note of the editor to the app commands that do them", async () => {+ const triggerHostCommand = vi.fn(async () => undefined);+ const config = await buildConfig(baseOpts({ triggerHostCommand }));+ const callbacks = [+ [ config.internalLink?.openDialog, "addLinkToText" ],+ [ config.markdownImport?.open, "pasteMarkdownIntoText" ],+ [ config.contentEmbed?.pickNote, "addIncludeNoteToText" ],+ [ config.cutToNote?.cut, "cutIntoNote" ],+ [ config.cutToNote?.saveNow, "saveNoteDetailNow" ]+ ] as const;++ for (const [ callback, command ] of callbacks) {+ await callback?.();+ expect(triggerHostCommand).toHaveBeenLastCalledWith(command);+ }+ expect(triggerHostCommand).toHaveBeenCalledTimes(callbacks.length);+ });+it("titles reference links through the link service", async () => {expect((await buildConfig(baseOpts())).referenceLink).toStrictEqual({getTitle: linkService.getReferenceLinkTitle,diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.tsindex 209d24df37..6b9acc6e9d 100644--- a/apps/client/src/widgets/type_widgets/text/config.ts+++ b/apps/client/src/widgets/type_widgets/text/config.ts@@ -3,6 +3,7 @@ import emojiDefinitionsUrl from "@triliumnext/ckeditor5/src/emoji_definitions/enimport { ALLOWED_PROTOCOLS, DISPLAYABLE_LOCALE_IDS, formatShortcut, IMAGE_UPLOAD_SUBTYPES, joinShortcut, KATEX_MACROS, MIME_TYPE_AUTO, normalizeMimeTypeForCKEditor } from "@triliumnext/commons";import i18next from "i18next";+import type { CommandNames } from "../../../components/app_context.js";import { copyHtmlWithToast, copyTextWithToast } from "../../../services/clipboard_ext.js";import { getUploadBoxSize } from "../../../services/content_renderer.js";import { prompt } from "../../../services/dialog.js";@@ -54,6 +55,8 @@ export interface BuildEditorOptions {getNoteId?: () => string | undefined;/** The ID of the component that hosts the editor, which changes the editor makes are sent as. */getComponentId?: () => string | undefined;+ /** Triggers `command` on the component that hosts the editor. */+ triggerHostCommand?: (command: CommandNames) => Promise<unknown> | undefined | null;}export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfig> {@@ -83,6 +86,7 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfisamples: SAMPLE_DIAGRAMS},contentEmbed: {+ pickNote: bindHostCommand(opts, "addIncludeNoteToText"),inlineLanguages: SOURCE_EMBED_TYPES.map((type) => type.language),renderInlinePreview: (language, source, container) => {void getSourceEmbedTypeByLanguage(language)?.renderPreview(source, container);@@ -213,6 +217,12 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfilinkEmbed: buildLinkEmbedHost(opts.getNoteId),getNoteId: opts.getNoteId,attachmentUpload: buildAttachmentUploadHost(opts.getComponentId),+ internalLink: { openDialog: bindHostCommand(opts, "addLinkToText") },+ markdownImport: { open: bindHostCommand(opts, "pasteMarkdownIntoText") },+ cutToNote: {+ cut: bindHostCommand(opts, "cutIntoNote"),+ saveNow: bindHostCommand(opts, "saveNoteDetailNow")+ },slashCommand: {// Drop CKEditor's built-in list slash commands, whose Title Case titles the palette// re-defines in sentence case.@@ -350,6 +360,13 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfi};}+/** A callback that triggers `command` on the component that hosts the editor, and waits for it. */+function bindHostCommand(opts: BuildEditorOptions, command: CommandNames) {+ return async () => {+ await opts.triggerHostCommand?.(command);+ };+}+/** The upload services of the editor, sending its uploads as changes of `getComponentId()`. */function buildAttachmentUploadHost(getComponentId?: () => string | undefined): AttachmentUploadHost {return {diff --git a/packages/ckeditor5/src/augmentation.ts b/packages/ckeditor5/src/augmentation.tsindex 1fe9a3eabd..69c926a804 100644--- a/packages/ckeditor5/src/augmentation.ts+++ b/packages/ckeditor5/src/augmentation.ts@@ -3,11 +3,6 @@ import "ckeditor5";import type { InlineEmbedSource } from "./plugins/content_embed/inline_source.js";declare global {- interface Component {- componentId: string;- triggerCommand(command: string): void;- }-interface LinkEmbedMetadata {url: string;embedType: string;@@ -94,7 +89,7 @@ declare global {hasDisplayModes?: boolean;}- interface EditorComponent extends Component {+ interface EditorComponent {/*** Paints the host's icon picker into `container`, and answers with the way to take it down* again. A host that shows the picker somewhere of its own — a phone, which has no room for@@ -175,7 +170,7 @@ declare global {}var glob: {- getComponentByEl<T extends Component>(el: unknown): T;+ getComponentByEl<T>(el: unknown): T;};}diff --git a/packages/ckeditor5/src/index.ts b/packages/ckeditor5/src/index.tsindex 624371bc0a..c193e8883c 100644--- a/packages/ckeditor5/src/index.ts+++ b/packages/ckeditor5/src/index.ts@@ -55,6 +55,7 @@ import "./plugins/content_embed/content_embed_caret.js";import "./plugins/find_in_link_widgets.js";import "./plugins/find_reveal.js";import "./plugins/insert_date_time.js";+import "./plugins/markdownimport.js";import "./plugins/math/math.js";import "./plugins/tabs/tabs.js";import "./plugins/multicolumn/multicolumn.js";diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.tsindex f42bf17a0c..b81b688520 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts@@ -45,17 +45,19 @@ import ContentEmbed, {describe("ContentEmbed", () => {let editor: ClassicEditor;- let triggerCommand: ReturnType<typeof vi.fn>;+ let pickNote: ReturnType<typeof vi.fn>;let loadEmbeddedNote: ReturnType<typeof vi.fn>;beforeEach(async () => {- triggerCommand = vi.fn();+ pickNote = vi.fn();loadEmbeddedNote = vi.fn();installGlobMock({- getComponentByEl: () => ({ triggerCommand, loadEmbeddedNote })+ getComponentByEl: () => ({ loadEmbeddedNote })});- editor = await createTestEditor([Essentials, Paragraph, Widget, ContentEmbed]);+ editor = await createTestEditor([Essentials, Paragraph, Widget, ContentEmbed], {+ contentEmbed: { pickNote }+ });});// -----------------------------------------------------------------------@@ -207,9 +209,9 @@ describe("ContentEmbed", () => {// InsertContentEmbedCommand// ------------------------------------------------------------------------ it("triggers addIncludeNoteToText on the Trilium component when the insert command executes", () => {+ it("has the host open the Include note dialog when the insert command executes", () => {editor.execute(COMMAND_NAME);- expect(triggerCommand).toHaveBeenCalledWith("addIncludeNoteToText");+ expect(pickNote).toHaveBeenCalledOnce();});it("enables the insert command in a paragraph and disables it where blocks are disallowed", () => {@@ -387,7 +389,6 @@ describe("ContentEmbed", () => {it("keeps the renderer's focus off for a press on a link preview", async () => {installGlobMock({getComponentByEl: () => ({- triggerCommand,loadEmbeddedNote})});diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.tsindex 6a8ff48dc4..0eb5ff6652 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.ts@@ -807,10 +807,7 @@ class ContentEmbedEditing extends Plugin {class InsertContentEmbedCommand extends Command {override execute() {- const editorEl = this.editor.editing.view.getDomRoot();- const component = glob.getComponentByEl(editorEl);-- component.triggerCommand('addIncludeNoteToText');+ this.editor.config.get( 'contentEmbed' )?.pickNote?.();}override refresh() {@@ -1667,6 +1664,23 @@ declare module 'ckeditor5' {setContentEmbedCodeView: SetContentEmbedCodeViewCommand;contentEmbedDisplayMode: ContentEmbedDisplayModeCommand;}++ interface EditorConfig {+ contentEmbed?: {+ /** Opens the dialog that picks a note to include at the selection. */+ pickNote?: () => void;+ /**+ * The languages whose `<pre><code class="language-…">` code blocks show as embeds of+ * their source, rendered by the host's `loadInlineEmbed()`.+ */+ inlineLanguages?: string[];+ /**+ * Renders the `source` of an inline language into `container`, outside an embed, as+ * the AI assistant previews a response.+ */+ renderInlinePreview?: ( language: string, source: string, container: HTMLElement ) => void;+ };+ }}/** A toolbar separator that shows only while `isVisible`, as the items on both sides do. */diff --git a/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts b/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.tsindex 026ba1b8f6..ca9e002b8d 100644--- a/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/inline_source.spec.ts@@ -38,7 +38,7 @@ describe("ContentEmbedInlineSource", () => {loadInlineEmbed = vi.fn();installGlobMock({getComponentByEl: () => ({- triggerCommand: vi.fn(), loadEmbeddedNote: vi.fn(), loadInlineEmbed+ loadEmbeddedNote: vi.fn(), loadInlineEmbed})});diff --git a/packages/ckeditor5/src/plugins/content_embed/inline_source.ts b/packages/ckeditor5/src/plugins/content_embed/inline_source.tsindex 21cb92a06c..3eddc8667b 100644--- a/packages/ckeditor5/src/plugins/content_embed/inline_source.ts+++ b/packages/ckeditor5/src/plugins/content_embed/inline_source.ts@@ -312,18 +312,4 @@ declare module 'ckeditor5' {[ ContentEmbedInlineSource.pluginName ]: ContentEmbedInlineSource;}- interface EditorConfig {- contentEmbed?: {- /**- * The languages whose `<pre><code class="language-…">` code blocks show as embeds of- * their source, rendered by the host's `loadInlineEmbed()`.- */- inlineLanguages?: string[];- /**- * Renders the `source` of an inline language into `container`, outside an embed, as- * the AI assistant previews a response.- */- renderInlinePreview?: ( language: string, source: string, container: HTMLElement ) => void;- };- }}diff --git a/packages/ckeditor5/src/plugins/cuttonote.spec.ts b/packages/ckeditor5/src/plugins/cuttonote.spec.tsindex 3e98f89529..09046d0efe 100644--- a/packages/ckeditor5/src/plugins/cuttonote.spec.ts+++ b/packages/ckeditor5/src/plugins/cuttonote.spec.ts@@ -14,21 +14,21 @@ import {import { beforeEach, describe, expect, it, vi } from "vitest";import { createTestEditor } from "../../test/editor-kit.js";-import { installGlobMock } from "../../test/globals-test-kit.js";import ClipboardPlainTextIndent from "./clipboard_plain_text_indent.js";import CutToNotePlugin from "./cuttonote.js";describe("CutToNotePlugin", () => {let editor: ClassicEditor;- let triggerCommand: ReturnType<typeof vi.fn>;+ let cut: ReturnType<typeof vi.fn>;+ let saveNow: ReturnType<typeof vi.fn>;beforeEach(async () => {- triggerCommand = vi.fn();- installGlobMock({- getComponentByEl: () => ({ triggerCommand })- });+ cut = vi.fn();+ saveNow = vi.fn(async () => undefined);- editor = await createTestEditor([Essentials, Paragraph, CutToNotePlugin]);+ editor = await createTestEditor([Essentials, Paragraph, CutToNotePlugin], {+ cutToNote: { cut, saveNow }+ });});it("loads the plugin and registers the toolbar button", () => {@@ -41,10 +41,10 @@ describe("CutToNotePlugin", () => {expect(view.label).toBe("Cut selection into a sub-note");});- it("triggers the cutIntoNote command on the Trilium component when the button is executed", () => {+ it("has the host cut the selection into a note when the button is executed", () => {const view = editor.ui.componentFactory.create("cutToNote") as { fire(name: string): void };view.fire("execute");- expect(triggerCommand).toHaveBeenCalledWith("cutIntoNote");+ expect(cut).toHaveBeenCalledOnce();});it("augments the editor with getSelectedHtml that serializes the selected content", () => {@@ -324,7 +324,7 @@ describe("CutToNotePlugin", () => {expect(editor.getData()).not.toContain("bar");expect(editor.getData()).toContain("foobaz");- expect(triggerCommand).toHaveBeenCalledWith("saveNoteDetailNow");+ expect(saveNow).toHaveBeenCalledOnce();});it("removeSelection on a collapsed selection still inserts a paragraph and saves", async () => {@@ -333,7 +333,17 @@ describe("CutToNotePlugin", () => {await editor.removeSelection();expect(editor.getData()).toContain("foobar");- expect(triggerCommand).toHaveBeenCalledWith("saveNoteDetailNow");+ expect(saveNow).toHaveBeenCalledOnce();+ });++ it("removes the selection without the cutToNote config entry, and cuts nothing", async () => {+ const plainEditor = await createTestEditor([Essentials, Paragraph, CutToNotePlugin]);+ setModelData(plainEditor.model, "<paragraph>foo[bar]baz</paragraph>");++ const view = plainEditor.ui.componentFactory.create("cutToNote") as { fire(name: string): void };+ expect(() => view.fire("execute")).not.toThrow();+ await plainEditor.removeSelection();+ expect(plainEditor.getData()).toContain("foobaz");});});diff --git a/packages/ckeditor5/src/plugins/cuttonote.ts b/packages/ckeditor5/src/plugins/cuttonote.tsindex e17192f490..1507afd3e0 100644--- a/packages/ckeditor5/src/plugins/cuttonote.ts+++ b/packages/ckeditor5/src/plugins/cuttonote.ts@@ -45,12 +45,8 @@ export default class CutToNotePlugin extends Plugin {tooltip: true} );- // Callback executed once the image is clicked.view.on('execute', () => {- const editorEl = this.editor.editing.view.getDomRoot();- const component = glob.getComponentByEl(editorEl);-- component.triggerCommand('cutIntoNote');+ this.editor.config.get('cutToNote')?.cut();});return view;@@ -185,14 +181,17 @@ export default class CutToNotePlugin extends Plugin {model.deleteContent(model.document.selection);this.editor.execute("paragraph");- const component = this.getComponent();-- await component.triggerCommand('saveNoteDetailNow');+ await this.editor.config.get('cutToNote')?.saveNow();}+}- getComponent() {- const editorEl = this.editor.editing.view.getDomRoot();-- return glob.getComponentByEl( editorEl );+declare module 'ckeditor5' {+ interface EditorConfig {+ cutToNote?: {+ /** Moves the selection into a new child note of the note the editor holds. */+ cut(): void;+ /** Saves the note now, once the selection is removed, rather than after the usual delay. */+ saveNow(): Promise<void>;+ };}}diff --git a/packages/ckeditor5/src/plugins/internallink.spec.ts b/packages/ckeditor5/src/plugins/internallink.spec.tsindex f2a569ee02..5812826781 100644--- a/packages/ckeditor5/src/plugins/internallink.spec.ts+++ b/packages/ckeditor5/src/plugins/internallink.spec.ts@@ -12,15 +12,13 @@ import InternalLinkPlugin, {describe("InternalLinkPlugin", () => {let editor: ClassicEditor;- let triggerCommand: ReturnType<typeof vi.fn>;+ let openDialog: ReturnType<typeof vi.fn>;beforeEach(async () => {- triggerCommand = vi.fn();- installGlobMock({- getComponentByEl: () => ({ triggerCommand })+ openDialog = vi.fn();+ editor = await createTestEditor([Essentials, Paragraph, CodeBlock, InternalLinkPlugin], {+ internalLink: { openDialog }});-- editor = await createTestEditor([Essentials, Paragraph, CodeBlock, InternalLinkPlugin]);});it("loads the plugin and registers the command and toolbar button", () => {@@ -29,9 +27,9 @@ describe("InternalLinkPlugin", () => {expect(editor.ui.componentFactory.has("internalLink")).toBe(true);});- it("triggers the addLinkToText command on the Trilium component when executed", () => {+ it("has the host open the Add link dialog when executed", () => {editor.execute(COMMAND_NAME);- expect(triggerCommand).toHaveBeenCalledWith("addLinkToText");+ expect(openDialog).toHaveBeenCalledOnce();});it("labels the button without the shortcut, leaving that to the keystroke", () => {@@ -172,14 +170,13 @@ describe("the link at the selection", () => {describe("the edit button of the link toolbar", () => {let editor: ClassicEditor;- let triggerCommand: ReturnType<typeof vi.fn>;+ let openDialog: ReturnType<typeof vi.fn>;beforeEach(async () => {- triggerCommand = vi.fn();- installGlobMock({- getComponentByEl: () => ({ triggerCommand })+ openDialog = vi.fn();+ editor = await createTestEditor([Essentials, Paragraph, Link, InternalLinkPlugin], {+ internalLink: { openDialog }});- editor = await createTestEditor([Essentials, Paragraph, Link, InternalLinkPlugin]);});it("opens the Add link dialog in place of the link form, closing the toolbar", () => {@@ -195,7 +192,7 @@ describe("the edit button of the link toolbar", () => {expect(edit).toBeInstanceOf(ButtonView);edit?.fire("execute");- expect(triggerCommand).toHaveBeenCalledWith("addLinkToText");+ expect(openDialog).toHaveBeenCalledOnce();expect(toolbarView && balloon.hasView(toolbarView)).toBe(false);expect(linkUI.formView && balloon.hasView(linkUI.formView)).toBe(false);});diff --git a/packages/ckeditor5/src/plugins/internallink.ts b/packages/ckeditor5/src/plugins/internallink.tsindex b559946e2b..03110bab6e 100644--- a/packages/ckeditor5/src/plugins/internallink.ts+++ b/packages/ckeditor5/src/plugins/internallink.ts@@ -82,11 +82,7 @@ class InsertInternalLinkCommand extends Command {}execute() {- const editor = this.editor;- const editorEl = editor.editing.view.getDomRoot();- const component = glob.getComponentByEl(editorEl);-- component.triggerCommand('addLinkToText');+ this.editor.config.get('internalLink')?.openDialog();}}@@ -171,3 +167,12 @@ function findLinkAtSelection(editor: Editor): { href: string; range: ModelRangereturn { href, range: findAttributeRange(position, 'linkHref', href, model) };}++declare module 'ckeditor5' {+ interface EditorConfig {+ internalLink?: {+ /** Opens the dialog that adds a link to a note at the selection, or edits the link there. */+ openDialog(): void;+ };+ }+}diff --git a/packages/ckeditor5/src/plugins/markdownimport.spec.ts b/packages/ckeditor5/src/plugins/markdownimport.spec.tsindex c02ea79380..9f3c3304b6 100644--- a/packages/ckeditor5/src/plugins/markdownimport.spec.ts+++ b/packages/ckeditor5/src/plugins/markdownimport.spec.ts@@ -2,20 +2,17 @@ import { ClassicEditor, Essentials, Paragraph } from "ckeditor5";import { beforeEach, describe, expect, it, vi } from "vitest";import { createTestEditor } from "../../test/editor-kit.js";-import { installGlobMock } from "../../test/globals-test-kit.js";import MarkdownImportPlugin, { COMMAND_NAME } from "./markdownimport.js";describe("MarkdownImportPlugin", () => {let editor: ClassicEditor;- let triggerCommand: ReturnType<typeof vi.fn>;+ let open: ReturnType<typeof vi.fn>;beforeEach(async () => {- triggerCommand = vi.fn();- installGlobMock({- getComponentByEl: () => ({ triggerCommand })+ open = vi.fn();+ editor = await createTestEditor([Essentials, Paragraph, MarkdownImportPlugin], {+ markdownImport: { open }});-- editor = await createTestEditor([Essentials, Paragraph, MarkdownImportPlugin]);});it("loads the plugin and registers the command and toolbar button", () => {@@ -29,9 +26,9 @@ describe("MarkdownImportPlugin", () => {expect(view.label).toBe("Markdown import from clipboard");});- it("triggers pasteMarkdownIntoText on the Trilium component when executed", () => {+ it("has the host open the Markdown import when executed", () => {editor.execute(COMMAND_NAME);- expect(triggerCommand).toHaveBeenCalledWith("pasteMarkdownIntoText");+ expect(open).toHaveBeenCalledOnce();});it("wires the button to the command (enablement and execution)", () => {diff --git a/packages/ckeditor5/src/plugins/markdownimport.ts b/packages/ckeditor5/src/plugins/markdownimport.tsindex dc12eff3e5..eae1493597 100644--- a/packages/ckeditor5/src/plugins/markdownimport.ts+++ b/packages/ckeditor5/src/plugins/markdownimport.ts@@ -32,10 +32,16 @@ export default class MarkdownImportPlugin extends Plugin {class ImportMarkdownCommand extends Command {execute() {- const editorEl = this.editor.editing.view.getDomRoot();- const component = glob.getComponentByEl(editorEl);-- component.triggerCommand('pasteMarkdownIntoText');+ this.editor.config.get('markdownImport')?.open();}}++declare module 'ckeditor5' {+ interface EditorConfig {+ markdownImport?: {+ /** Opens the dialog that converts Markdown into the note at the selection. */+ open(): void;+ };+ }+}diff --git a/packages/ckeditor5/src/plugins/mermaid/mermaid_ui.spec.ts b/packages/ckeditor5/src/plugins/mermaid/mermaid_ui.spec.tsindex 1f2f91ac30..2c0381d2f2 100644--- a/packages/ckeditor5/src/plugins/mermaid/mermaid_ui.spec.ts+++ b/packages/ckeditor5/src/plugins/mermaid/mermaid_ui.spec.ts@@ -28,7 +28,7 @@ describe("MermaidUI", () => {beforeEach(async () => {installGlobMock({getComponentByEl: () => ({- triggerCommand: vi.fn(), loadEmbeddedNote: vi.fn(), loadInlineEmbed: vi.fn()+ loadEmbeddedNote: vi.fn(), loadInlineEmbed: vi.fn()})});diff --git a/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.ts b/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.tsindex 358e8c859d..d71c29aa03 100644--- a/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.ts+++ b/packages/ckeditor5/src/plugins/mobile_toolbar_items.spec.ts@@ -43,7 +43,6 @@ import editorStylesheetUrl from "ckeditor5/ckeditor5.css?url";import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";import { createTestEditor } from "../../test/editor-kit.js";-import { installGlobMock } from "../../test/globals-test-kit.js";import admonitionIcon from "../icons/admonition.svg?raw";import blockTypeIcon from "../icons/block-type.svg?raw";import AdmonitionEditing from "./admonition/admonition_editing.js";@@ -302,10 +301,10 @@ describe("MobileToolbarItems", () => {describe("addLink", () => {it("opens the link dialog of the internal link button, under the link icon", async () => {- const triggerCommand = vi.fn();- installGlobMock({ getComponentByEl: () => ({ triggerCommand }) });+ const openDialog = vi.fn();const editor = await createTestEditor([Essentials, Paragraph, InternalLinkPlugin, MobileToolbarItems], {- toolbar: ["addLink"]+ toolbar: ["addLink"],+ internalLink: { openDialog }});setModelData(editor.model, "<paragraph>foo[]</paragraph>");@@ -314,7 +313,7 @@ describe("addLink", () => {};expect([button.label, button.icon, button.isEnabled]).toStrictEqual(["Link", IconLink, true]);button.fire("execute");- expect(triggerCommand).toHaveBeenCalledExactlyOnceWith("addLinkToText");+ expect(openDialog).toHaveBeenCalledOnce();editor.enableReadOnlyMode("spec");expect(button.isEnabled).toBe(false);