diff --git a/src/components/Editor.provider.ts b/src/components/Editor.provider.ts index 9e866078fa1..def138d9ea2 100644 --- a/src/components/Editor.provider.ts +++ b/src/components/Editor.provider.ts @@ -13,6 +13,7 @@ export const EDITOR_UPLOAD = Symbol('editor:upload') export const HOOK_MENTION_SEARCH = Symbol('hook:mention-search') export const HOOK_MENTION_INSERT = Symbol('hook:mention-insert') export const OPEN_LINK_HANDLER = Symbol('editor:open-link-handler') +export const HOOK_MENUBAR_LINK_CUSTOM_ACTION = Symbol('menubar:link-custom-action') export const useIsMobileMixin = { inject: { diff --git a/src/components/Menu/ActionInsertLink.vue b/src/components/Menu/ActionInsertLink.vue index c1bbd09fde0..80deeabb0a3 100644 --- a/src/components/Menu/ActionInsertLink.vue +++ b/src/components/Menu/ActionInsertLink.vue @@ -33,6 +33,12 @@ {{ t('text', 'Remove link') }} + + + {{ menubarLinkCustomAction.label }} + { - const chain = this.editor?.chain() - if (this.editor?.view.state?.selection.empty) { - chain.focus().insertPreview(link).run() - } else { - chain.setLink({ href: link }).focus().run() - } + this.insertLink(link) }) .catch((error) => { console.error('Smart picker promise rejected', error) }) }, + linkCustomAction() { + this.menubarLinkCustomAction + .action() + .then((link) => { + this.insertLink(link) + }) + .catch((error) => { + console.error('Custom link action promise rejected', error) + }) + }, + insertLink(link) { + if (!link) { + return + } + const chain = this.editor?.chain() + if (this.editor?.view.state?.selection.empty) { + chain.focus().insertPreview(link).run() + } else { + chain.setLink({ href: link }).focus().run() + } + }, t, }, } diff --git a/src/editor.js b/src/editor.js index 4c19602cac6..37fd1b71c6b 100644 --- a/src/editor.js +++ b/src/editor.js @@ -10,6 +10,7 @@ import { EDITOR_UPLOAD, HOOK_MENTION_INSERT, HOOK_MENTION_SEARCH, + HOOK_MENUBAR_LINK_CUSTOM_ACTION, OPEN_LINK_HANDLER, } from './components/Editor.provider.ts' import { ACTION_ATTACHMENT_PROMPT } from './components/Editor/MediaHandler.provider.js' @@ -249,6 +250,7 @@ window.OCA.Text.createEditor = async function ({ component: null, props: null, }, + menubarLinkCustomAction = undefined, onCreate = ({ markdown }) => {}, onLoaded = () => {}, @@ -296,6 +298,7 @@ window.OCA.Text.createEditor = async function ({ ] }, }, + [HOOK_MENUBAR_LINK_CUSTOM_ACTION]: menubarLinkCustomAction, } }, data() {