Merge pull request #4423 from ioma8/link-click-fix

Link click fix
This commit is contained in:
Jan Thurau 2023-11-20 21:37:33 +01:00 committed by GitHub
commit 2e96ed5d7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import './styles.scss'
import Bold from '@tiptap/extension-bold'
import Code from '@tiptap/extension-code'
import Document from '@tiptap/extension-document'
import Link from '@tiptap/extension-link'
@ -15,13 +16,14 @@ export default () => {
Paragraph,
Text,
Code,
Bold,
Link.configure({
openOnClick: false,
openOnClick: true,
}),
],
content: `
<p>
Wow, this editor has support for links to the whole <a href="https://en.wikipedia.org/wiki/World_Wide_Web">world wide web</a>. We tested a lot of URLs and I think you can add *every URL* you want. Isnt that cool? Lets try <a href="https://statamic.com/">another one!</a> Yep, seems to work.
Wow, this editor has support for links to the whole <a href="https://en.wikipedia.org/wiki/World_Wide_Web"><b>world wide web</b></a>. We tested a lot of URLs and I think you can add *every URL* you want. Isnt that cool? Lets try <a href="https://statamic.com/">another one!</a> Yep, seems to work.
</p>
<p>
By default every link will get a <code>rel="noopener noreferrer nofollow"</code> attribute. Its configurable though.

View File

@ -15,9 +15,15 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
return false
}
const eventTarget = event.target as HTMLElement
let a = event.target as HTMLElement
const els = []
if (eventTarget.nodeName !== 'A') {
while (a.nodeName !== 'DIV') {
els.push(a)
a = a.parentNode as HTMLElement
}
if (!els.find(value => value.nodeName === 'A')) {
return false
}
@ -28,9 +34,7 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
const target = link?.target ?? attrs.target
if (link && href) {
if (view.editable) {
window.open(href, target)
}
window.open(href, target)
return true
}