Skip to content

Commit

Permalink
chore(LinkBubble): Remove code to customize link click handling
Browse files Browse the repository at this point in the history
We no longer allow custom link click handlers in Text. Instead, the
reference widgets for link previews have to implement their own click
handlers.

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Jan 23, 2024
1 parent 840eeee commit 2153566
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 66 deletions.
9 changes: 0 additions & 9 deletions src/components/Editor.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const IS_RICH_EDITOR = Symbol('editor:is-rich-editor')
export const IS_RICH_WORKSPACE = Symbol('editor:is-rich-woskapace')
export const SYNC_SERVICE = Symbol('sync:service')
export const EDITOR_UPLOAD = Symbol('editor:upload')
export const HOOK_LINK_CLICK = Symbol('hook:link-click')
export const HOOK_MENTION_SEARCH = Symbol('hook:mention-search')
export const HOOK_MENTION_INSERT = Symbol('hook:mention-insert')

Expand Down Expand Up @@ -117,11 +116,3 @@ export const useMentionHook = {
},
},
}
export const useLinkClickHook = {
inject: {
$linkHookClick: {
from: HOOK_LINK_CLICK,
default: null,
},
},
}
10 changes: 1 addition & 9 deletions src/components/Editor/MarkdownContentEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { Editor } from '@tiptap/core'
/* eslint-disable import/no-named-as-default */
import History from '@tiptap/extension-history'
import { getCurrentUser } from '@nextcloud/auth'
import { ATTACHMENT_RESOLVER, EDITOR, IS_RICH_EDITOR, useLinkClickHook } from '../Editor.provider.js'
import { ATTACHMENT_RESOLVER, EDITOR, IS_RICH_EDITOR } from '../Editor.provider.js'
import { createMarkdownSerializer } from '../../extensions/Markdown.js'
import AttachmentResolver from '../../services/AttachmentResolver.js'
import markdownit from '../../markdownit/index.js'
Expand All @@ -52,7 +52,6 @@ import ContentContainer from './ContentContainer.vue'
export default {
name: 'MarkdownContentEditor',
components: { ContentContainer, ReadonlyBar, MenuBar, MainContainer, Wrapper },
mixins: [useLinkClickHook],
provide() {
const val = {}

Expand Down Expand Up @@ -136,13 +135,6 @@ export default {
return [
RichText.configure({
component: this,
link: this?.$linkHookClick
? {
onClick: (event, attrs) => {
return this?.$linkHookClick?.(event, attrs)
},
}
: undefined,
extensions: [
History,
],
Expand Down
4 changes: 1 addition & 3 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import Vue from 'vue'
import store from './store/index.js'
import { EDITOR_UPLOAD, HOOK_MENTION_SEARCH, HOOK_MENTION_INSERT, HOOK_LINK_CLICK, ATTACHMENT_RESOLVER } from './components/Editor.provider.js'
import { EDITOR_UPLOAD, HOOK_MENTION_SEARCH, HOOK_MENTION_INSERT, ATTACHMENT_RESOLVER } from './components/Editor.provider.js'
import { ACTION_ATTACHMENT_PROMPT } from './components/Editor/MediaHandler.provider.js'

__webpack_nonce__ = btoa(OC.requestToken) // eslint-disable-line
Expand Down Expand Up @@ -152,7 +152,6 @@ window.OCA.Text.createEditor = async function({
onLoaded = () => {},
onUpdate = ({ markdown }) => {},
onOutlineToggle = (visible) => {},
onLinkClick = undefined,
onFileInsert = undefined,
onMentionSearch = undefined,
onMentionInsert = undefined,
Expand All @@ -171,7 +170,6 @@ window.OCA.Text.createEditor = async function({
const vm = new Vue({
provide() {
return {
[HOOK_LINK_CLICK]: onLinkClick,
[ACTION_ATTACHMENT_PROMPT]: onFileInsert,
[EDITOR_UPLOAD]: !!sessionEditor,
[HOOK_MENTION_SEARCH]: sessionEditor ? true : onMentionSearch,
Expand Down
2 changes: 0 additions & 2 deletions src/extensions/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default Extension.create({
addOptions() {
return {
editing: true,
link: {},
extensions: [],
component: null,
relativePath: null,
Expand Down Expand Up @@ -115,7 +114,6 @@ export default Extension.create({
}),
LinkPicker,
Link.configure({
...this.options.link,
openOnClick: true,
validate: href => /^https?:\/\//.test(href),
relativePath: this.options.relativePath,
Expand Down
43 changes: 0 additions & 43 deletions src/helpers/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

import { generateUrl } from '@nextcloud/router'

import { logger } from '../helpers/logger.js'
import markdownit from './../markdownit/index.js'

const absolutePath = function(base, rel) {
if (!rel) {
return base
Expand Down Expand Up @@ -93,47 +90,7 @@ const parseHref = function(dom) {
return ref
}

const openLink = function(event, target = '_self') {
const linkElement = event.target.closest('a')
const htmlHref = linkElement.href
const query = OC.parseQueryString(htmlHref)
const fragment = htmlHref.split('#').pop()
const fragmentQuery = OC.parseQueryString(fragment)
if (query?.dir && fragmentQuery?.relPath) {
const filename = fragmentQuery.relPath.split('/').pop()
const path = `${query.dir}/${filename}`
document.title = `${filename} - ${OC.theme.title}`
if (window.location.pathname.match(/apps\/files\/$/)) {
// The files app still lacks a popState handler
// to allow for using the back button
// OC.Util.History.pushState('', htmlHref)
}
OCA.Viewer.open({ path })
return
}
if (htmlHref.match(/apps\/files\//) && query?.fileId) {
// open the direct file link
window.open(generateUrl(`/f/${query.fileId}`), '_self')
return
}
if (!markdownit.validateLink(htmlHref)) {
logger.error('Invalid link', { htmlHref })
return false
}
if (fragment) {
const el = document.getElementById(fragment)
if (el) {
el.scrollIntoView()
window.location.hash = fragment
return
}
}
window.open(htmlHref, target)
return true
}

export {
domHref,
parseHref,
openLink,
}

0 comments on commit 2153566

Please sign in to comment.