3333 </template >
3434 {{ t('text', 'Remove link') }}
3535 </NcActionButton >
36+ <NcActionButton v-if =" hasMenubarLinkCustomAction" @click =" linkCustomAction" >
37+ <template #icon >
38+ <component :is =" menubarLinkCustomAction.icon" />
39+ </template >
40+ {{ menubarLinkCustomAction.label }}
41+ </NcActionButton >
3642 <NcActionButton
3743 v-if =" !isUsingDirectEditing"
3844 ref =" buttonFile"
@@ -92,6 +98,7 @@ import { t } from '@nextcloud/l10n'
9298import { useFileProps } from ' ../../composables/useFileProps.ts'
9399import { useLinkFile } from ' ../../composables/useLinkFile.ts'
94100import { useNetworkState } from ' ../../composables/useNetworkState.ts'
101+ import { HOOK_MENUBAR_LINK_CUSTOM_ACTION } from ' ../Editor.provider.ts'
95102import { Document , LinkOff , Loading , Shape , Web } from ' ../icons.js'
96103import { BaseActionEntry } from ' ./BaseActionEntry.js'
97104import { useMenuIDMixin } from ' ./MenuBar.provider.js'
@@ -110,6 +117,12 @@ export default {
110117 },
111118 extends: BaseActionEntry,
112119 mixins: [useMenuIDMixin],
120+ inject: {
121+ menubarLinkCustomAction: {
122+ from: HOOK_MENUBAR_LINK_CUSTOM_ACTION ,
123+ default: null ,
124+ },
125+ },
113126 setup () {
114127 const base = BaseActionEntry .setup ()
115128 const { networkOnline } = useNetworkState ()
@@ -135,6 +148,12 @@ export default {
135148 activeClass () {
136149 return this .state .active ? ' is-active' : ' '
137150 },
151+ hasMenubarLinkCustomAction () {
152+ return (
153+ typeof this .menubarLinkCustomAction ? .action === ' function'
154+ && this .menubarLinkCustomAction ? .icon
155+ )
156+ },
138157 },
139158 methods: {
140159 /**
@@ -207,17 +226,33 @@ export default {
207226 linkPicker () {
208227 getLinkWithPicker (null , true )
209228 .then ((link ) => {
210- const chain = this .editor ? .chain ()
211- if (this .editor ? .view .state ? .selection .empty ) {
212- chain .focus ().insertPreview (link).run ()
213- } else {
214- chain .setLink ({ href: link }).focus ().run ()
215- }
229+ this .insertLink (link)
216230 })
217231 .catch ((error ) => {
218232 console .error (' Smart picker promise rejected' , error)
219233 })
220234 },
235+ linkCustomAction () {
236+ this .menubarLinkCustomAction
237+ .action ()
238+ .then ((link ) => {
239+ this .insertLink (link)
240+ })
241+ .catch ((error ) => {
242+ console .error (' Custom link action promise rejected' , error)
243+ })
244+ },
245+ insertLink (link ) {
246+ if (! link) {
247+ return
248+ }
249+ const chain = this .editor ? .chain ()
250+ if (this .editor ? .view .state ? .selection .empty ) {
251+ chain .focus ().insertPreview (link).run ()
252+ } else {
253+ chain .setLink ({ href: link }).focus ().run ()
254+ }
255+ },
221256 t,
222257 },
223258}
0 commit comments