Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Editor.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
48 changes: 41 additions & 7 deletions src/components/Menu/ActionInsertLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
</template>
{{ t('text', 'Remove link') }}
</NcActionButton>
<NcActionButton v-if="hasMenubarLinkCustomAction" @click="linkCustomAction">
<template #icon>
<component :is="menubarLinkCustomAction.icon" />
</template>
{{ menubarLinkCustomAction.label }}
</NcActionButton>
<NcActionButton
v-if="!isUsingDirectEditing"
ref="buttonFile"
Expand Down Expand Up @@ -92,7 +98,7 @@ import { getMarkAttributes, isActive } from '@tiptap/core'
import { t } from '@nextcloud/l10n'
import { useNetworkState } from '../../composables/useNetworkState.ts'
import { buildFilePicker } from '../../helpers/filePicker.js'
import { useFileMixin } from '../Editor.provider.ts'
import { HOOK_MENUBAR_LINK_CUSTOM_ACTION, useFileMixin } from '../Editor.provider.ts'
import { Document, LinkOff, Loading, Shape, Web } from '../icons.js'
import { BaseActionEntry } from './BaseActionEntry.js'
import { useMenuIDMixin } from './MenuBar.provider.js'
Expand All @@ -111,6 +117,12 @@ export default {
},
extends: BaseActionEntry,
mixins: [useFileMixin, useMenuIDMixin],
inject: {
menubarLinkCustomAction: {
from: HOOK_MENUBAR_LINK_CUSTOM_ACTION,
default: null,
},
},
setup() {
const { networkOnline } = useNetworkState()
return { ...BaseActionEntry.setup(), networkOnline }
Expand All @@ -133,6 +145,12 @@ export default {
relativePath() {
return this.$file?.relativePath ?? '/'
},
hasMenubarLinkCustomAction() {
return (
typeof this.menubarLinkCustomAction?.action === 'function'
&& this.menubarLinkCustomAction?.icon
)
},
},
methods: {
/**
Expand Down Expand Up @@ -228,17 +246,33 @@ export default {
linkPicker() {
getLinkWithPicker(null, true)
.then((link) => {
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,
},
}
Expand Down
3 changes: 3 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -249,6 +250,7 @@ window.OCA.Text.createEditor = async function ({
component: null,
props: null,
},
menubarLinkCustomAction = undefined,

onCreate = ({ markdown }) => {},
onLoaded = () => {},
Expand Down Expand Up @@ -296,6 +298,7 @@ window.OCA.Text.createEditor = async function ({
]
},
},
[HOOK_MENUBAR_LINK_CUSTOM_ACTION]: menubarLinkCustomAction,
}
},
data() {
Expand Down
Loading