|
1 | | -import { generateUrl } from '@nextcloud/router' |
2 | | -import { Plugin } from 'prosemirror-state' |
3 | | -import markdownit from './../markdownit/index.js' |
| 1 | +import { Plugin, PluginKey } from 'prosemirror-state' |
4 | 2 |
|
5 | | -const clickHandler = ({ editor }) => { |
| 3 | +const clickHandler = ({ editor, type, onClick }) => { |
6 | 4 | return new Plugin({ |
7 | 5 | props: { |
| 6 | + key: new PluginKey('textLink'), |
8 | 7 | handleClick: (view, pos, event) => { |
9 | | - const linkElement = event.target.parentElement instanceof HTMLAnchorElement |
10 | | - ? event.target.parentElement |
11 | | - : event.target |
12 | | - |
13 | | - const isLink = linkElement && linkElement instanceof HTMLAnchorElement |
14 | | - |
15 | | - const htmlHref = linkElement?.href |
16 | | - |
17 | | - // is handleable link |
18 | | - if (htmlHref && isLink) { |
19 | | - event.stopPropagation() |
20 | | - |
21 | | - if (event.button === 0 && !event.ctrlKey && htmlHref.startsWith(window.location.origin)) { |
22 | | - const query = OC.parseQueryString(htmlHref) |
23 | | - const fragment = OC.parseQueryString(htmlHref.split('#').pop()) |
24 | | - if (query.dir && fragment.relPath) { |
25 | | - const filename = fragment.relPath.split('/').pop() |
26 | | - const path = `${query.dir}/${filename}` |
27 | | - document.title = `${filename} - ${OC.theme.title}` |
28 | | - if (window.location.pathname.match(/apps\/files\/$/)) { |
29 | | - // The files app still lacks a popState handler |
30 | | - // to allow for using the back button |
31 | | - // OC.Util.History.pushState('', htmlHref) |
32 | | - } |
33 | | - OCA.Viewer.open({ path }) |
34 | | - return |
35 | | - } |
36 | | - if (query.fileId) { |
37 | | - // open the direct file link |
38 | | - window.open(generateUrl(`/f/${query.fileId}`)) |
39 | | - return |
40 | | - } |
41 | | - } |
42 | | - |
43 | | - if (!markdownit.validateLink(htmlHref)) { |
44 | | - console.error('Invalid link', htmlHref) |
45 | | - return |
46 | | - } |
47 | | - |
48 | | - window.open(htmlHref) |
| 8 | + const attrs = editor.getAttributes(type) |
| 9 | + const link = event.target.closest('a') |
| 10 | + if (link && attrs.href && onClick) { |
| 11 | + return onClick(event, attrs) |
49 | 12 | } |
| 13 | + return false |
50 | 14 | }, |
51 | 15 | }, |
52 | 16 | }) |
|
0 commit comments