@ckeditor/ckeditor5-link 43.3.1-alpha.0 → 44.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -7
- package/build/link.js +2 -2
- package/build/translations/af.js +1 -1
- package/build/translations/ar.js +1 -1
- package/build/translations/ast.js +1 -1
- package/build/translations/az.js +1 -1
- package/build/translations/bg.js +1 -1
- package/build/translations/bn.js +1 -1
- package/build/translations/bs.js +1 -1
- package/build/translations/ca.js +1 -1
- package/build/translations/cs.js +1 -1
- package/build/translations/da.js +1 -1
- package/build/translations/de-ch.js +1 -1
- package/build/translations/de.js +1 -1
- package/build/translations/el.js +1 -1
- package/build/translations/en-au.js +1 -1
- package/build/translations/en-gb.js +1 -1
- package/build/translations/eo.js +1 -1
- package/build/translations/es-co.js +1 -1
- package/build/translations/es.js +1 -1
- package/build/translations/et.js +1 -1
- package/build/translations/eu.js +1 -1
- package/build/translations/fa.js +1 -1
- package/build/translations/fi.js +1 -1
- package/build/translations/fr.js +1 -1
- package/build/translations/gl.js +1 -1
- package/build/translations/gu.js +1 -1
- package/build/translations/he.js +1 -1
- package/build/translations/hi.js +1 -1
- package/build/translations/hr.js +1 -1
- package/build/translations/hu.js +1 -1
- package/build/translations/hy.js +1 -1
- package/build/translations/id.js +1 -1
- package/build/translations/it.js +1 -1
- package/build/translations/ja.js +1 -1
- package/build/translations/jv.js +1 -1
- package/build/translations/kk.js +1 -1
- package/build/translations/km.js +1 -1
- package/build/translations/kn.js +1 -1
- package/build/translations/ko.js +1 -1
- package/build/translations/ku.js +1 -1
- package/build/translations/lt.js +1 -1
- package/build/translations/lv.js +1 -1
- package/build/translations/ms.js +1 -1
- package/build/translations/nb.js +1 -1
- package/build/translations/ne.js +1 -1
- package/build/translations/nl.js +1 -1
- package/build/translations/no.js +1 -1
- package/build/translations/oc.js +1 -1
- package/build/translations/pl.js +1 -1
- package/build/translations/pt-br.js +1 -1
- package/build/translations/pt.js +1 -1
- package/build/translations/ro.js +1 -1
- package/build/translations/ru.js +1 -1
- package/build/translations/si.js +1 -1
- package/build/translations/sk.js +1 -1
- package/build/translations/sl.js +1 -1
- package/build/translations/sq.js +1 -1
- package/build/translations/sr-latn.js +1 -1
- package/build/translations/sr.js +1 -1
- package/build/translations/sv.js +1 -1
- package/build/translations/th.js +1 -1
- package/build/translations/ti.js +1 -1
- package/build/translations/tk.js +1 -1
- package/build/translations/tr.js +1 -1
- package/build/translations/tt.js +1 -1
- package/build/translations/ug.js +1 -1
- package/build/translations/uk.js +1 -1
- package/build/translations/ur.js +1 -1
- package/build/translations/uz.js +1 -1
- package/build/translations/vi.js +1 -1
- package/build/translations/zh-cn.js +1 -1
- package/build/translations/zh.js +1 -1
- package/dist/index.js +58 -7
- package/dist/index.js.map +1 -1
- package/dist/translations/af.js +1 -1
- package/dist/translations/af.umd.js +1 -1
- package/dist/translations/ar.js +1 -1
- package/dist/translations/ar.umd.js +1 -1
- package/dist/translations/ast.js +1 -1
- package/dist/translations/ast.umd.js +1 -1
- package/dist/translations/az.js +1 -1
- package/dist/translations/az.umd.js +1 -1
- package/dist/translations/bg.js +1 -1
- package/dist/translations/bg.umd.js +1 -1
- package/dist/translations/bn.js +1 -1
- package/dist/translations/bn.umd.js +1 -1
- package/dist/translations/bs.js +1 -1
- package/dist/translations/bs.umd.js +1 -1
- package/dist/translations/ca.js +1 -1
- package/dist/translations/ca.umd.js +1 -1
- package/dist/translations/cs.js +1 -1
- package/dist/translations/cs.umd.js +1 -1
- package/dist/translations/da.js +1 -1
- package/dist/translations/da.umd.js +1 -1
- package/dist/translations/de-ch.js +1 -1
- package/dist/translations/de-ch.umd.js +1 -1
- package/dist/translations/de.js +1 -1
- package/dist/translations/de.umd.js +1 -1
- package/dist/translations/el.js +1 -1
- package/dist/translations/el.umd.js +1 -1
- package/dist/translations/en-au.js +1 -1
- package/dist/translations/en-au.umd.js +1 -1
- package/dist/translations/en-gb.js +1 -1
- package/dist/translations/en-gb.umd.js +1 -1
- package/dist/translations/en.js +1 -1
- package/dist/translations/en.umd.js +1 -1
- package/dist/translations/eo.js +1 -1
- package/dist/translations/eo.umd.js +1 -1
- package/dist/translations/es-co.js +1 -1
- package/dist/translations/es-co.umd.js +1 -1
- package/dist/translations/es.js +1 -1
- package/dist/translations/es.umd.js +1 -1
- package/dist/translations/et.js +1 -1
- package/dist/translations/et.umd.js +1 -1
- package/dist/translations/eu.js +1 -1
- package/dist/translations/eu.umd.js +1 -1
- package/dist/translations/fa.js +1 -1
- package/dist/translations/fa.umd.js +1 -1
- package/dist/translations/fi.js +1 -1
- package/dist/translations/fi.umd.js +1 -1
- package/dist/translations/fr.js +1 -1
- package/dist/translations/fr.umd.js +1 -1
- package/dist/translations/gl.js +1 -1
- package/dist/translations/gl.umd.js +1 -1
- package/dist/translations/gu.js +1 -1
- package/dist/translations/gu.umd.js +1 -1
- package/dist/translations/he.js +1 -1
- package/dist/translations/he.umd.js +1 -1
- package/dist/translations/hi.js +1 -1
- package/dist/translations/hi.umd.js +1 -1
- package/dist/translations/hr.js +1 -1
- package/dist/translations/hr.umd.js +1 -1
- package/dist/translations/hu.js +1 -1
- package/dist/translations/hu.umd.js +1 -1
- package/dist/translations/hy.js +1 -1
- package/dist/translations/hy.umd.js +1 -1
- package/dist/translations/id.js +1 -1
- package/dist/translations/id.umd.js +1 -1
- package/dist/translations/it.js +1 -1
- package/dist/translations/it.umd.js +1 -1
- package/dist/translations/ja.js +1 -1
- package/dist/translations/ja.umd.js +1 -1
- package/dist/translations/jv.js +1 -1
- package/dist/translations/jv.umd.js +1 -1
- package/dist/translations/kk.js +1 -1
- package/dist/translations/kk.umd.js +1 -1
- package/dist/translations/km.js +1 -1
- package/dist/translations/km.umd.js +1 -1
- package/dist/translations/kn.js +1 -1
- package/dist/translations/kn.umd.js +1 -1
- package/dist/translations/ko.js +1 -1
- package/dist/translations/ko.umd.js +1 -1
- package/dist/translations/ku.js +1 -1
- package/dist/translations/ku.umd.js +1 -1
- package/dist/translations/lt.js +1 -1
- package/dist/translations/lt.umd.js +1 -1
- package/dist/translations/lv.js +1 -1
- package/dist/translations/lv.umd.js +1 -1
- package/dist/translations/ms.js +1 -1
- package/dist/translations/ms.umd.js +1 -1
- package/dist/translations/nb.js +1 -1
- package/dist/translations/nb.umd.js +1 -1
- package/dist/translations/ne.js +1 -1
- package/dist/translations/ne.umd.js +1 -1
- package/dist/translations/nl.js +1 -1
- package/dist/translations/nl.umd.js +1 -1
- package/dist/translations/no.js +1 -1
- package/dist/translations/no.umd.js +1 -1
- package/dist/translations/oc.js +1 -1
- package/dist/translations/oc.umd.js +1 -1
- package/dist/translations/pl.js +1 -1
- package/dist/translations/pl.umd.js +1 -1
- package/dist/translations/pt-br.js +1 -1
- package/dist/translations/pt-br.umd.js +1 -1
- package/dist/translations/pt.js +1 -1
- package/dist/translations/pt.umd.js +1 -1
- package/dist/translations/ro.js +1 -1
- package/dist/translations/ro.umd.js +1 -1
- package/dist/translations/ru.js +1 -1
- package/dist/translations/ru.umd.js +1 -1
- package/dist/translations/si.js +1 -1
- package/dist/translations/si.umd.js +1 -1
- package/dist/translations/sk.js +1 -1
- package/dist/translations/sk.umd.js +1 -1
- package/dist/translations/sl.js +1 -1
- package/dist/translations/sl.umd.js +1 -1
- package/dist/translations/sq.js +1 -1
- package/dist/translations/sq.umd.js +1 -1
- package/dist/translations/sr-latn.js +1 -1
- package/dist/translations/sr-latn.umd.js +1 -1
- package/dist/translations/sr.js +1 -1
- package/dist/translations/sr.umd.js +1 -1
- package/dist/translations/sv.js +1 -1
- package/dist/translations/sv.umd.js +1 -1
- package/dist/translations/th.js +1 -1
- package/dist/translations/th.umd.js +1 -1
- package/dist/translations/ti.js +1 -1
- package/dist/translations/ti.umd.js +1 -1
- package/dist/translations/tk.js +1 -1
- package/dist/translations/tk.umd.js +1 -1
- package/dist/translations/tr.js +1 -1
- package/dist/translations/tr.umd.js +1 -1
- package/dist/translations/tt.js +1 -1
- package/dist/translations/tt.umd.js +1 -1
- package/dist/translations/ug.js +1 -1
- package/dist/translations/ug.umd.js +1 -1
- package/dist/translations/uk.js +1 -1
- package/dist/translations/uk.umd.js +1 -1
- package/dist/translations/ur.js +1 -1
- package/dist/translations/ur.umd.js +1 -1
- package/dist/translations/uz.js +1 -1
- package/dist/translations/uz.umd.js +1 -1
- package/dist/translations/vi.js +1 -1
- package/dist/translations/vi.umd.js +1 -1
- package/dist/translations/zh-cn.js +1 -1
- package/dist/translations/zh-cn.umd.js +1 -1
- package/dist/translations/zh.js +1 -1
- package/dist/translations/zh.umd.js +1 -1
- package/dist/ui/linkactionsview.d.ts +15 -1
- package/dist/utils.d.ts +6 -0
- package/lang/contexts.json +1 -0
- package/lang/translations/af.po +4 -0
- package/lang/translations/ar.po +4 -0
- package/lang/translations/ast.po +4 -0
- package/lang/translations/az.po +4 -0
- package/lang/translations/bg.po +4 -0
- package/lang/translations/bn.po +4 -0
- package/lang/translations/bs.po +4 -0
- package/lang/translations/ca.po +4 -0
- package/lang/translations/cs.po +4 -0
- package/lang/translations/da.po +4 -0
- package/lang/translations/de-ch.po +4 -0
- package/lang/translations/de.po +4 -0
- package/lang/translations/el.po +4 -0
- package/lang/translations/en-au.po +4 -0
- package/lang/translations/en-gb.po +4 -0
- package/lang/translations/en.po +4 -0
- package/lang/translations/eo.po +4 -0
- package/lang/translations/es-co.po +4 -0
- package/lang/translations/es.po +4 -0
- package/lang/translations/et.po +4 -0
- package/lang/translations/eu.po +4 -0
- package/lang/translations/fa.po +4 -0
- package/lang/translations/fi.po +4 -0
- package/lang/translations/fr.po +4 -0
- package/lang/translations/gl.po +4 -0
- package/lang/translations/gu.po +4 -0
- package/lang/translations/he.po +4 -0
- package/lang/translations/hi.po +4 -0
- package/lang/translations/hr.po +4 -0
- package/lang/translations/hu.po +4 -0
- package/lang/translations/hy.po +4 -0
- package/lang/translations/id.po +4 -0
- package/lang/translations/it.po +4 -0
- package/lang/translations/ja.po +4 -0
- package/lang/translations/jv.po +4 -0
- package/lang/translations/kk.po +4 -0
- package/lang/translations/km.po +4 -0
- package/lang/translations/kn.po +4 -0
- package/lang/translations/ko.po +4 -0
- package/lang/translations/ku.po +4 -0
- package/lang/translations/lt.po +4 -0
- package/lang/translations/lv.po +4 -0
- package/lang/translations/ms.po +4 -0
- package/lang/translations/nb.po +4 -0
- package/lang/translations/ne.po +4 -0
- package/lang/translations/nl.po +4 -0
- package/lang/translations/no.po +4 -0
- package/lang/translations/oc.po +4 -0
- package/lang/translations/pl.po +4 -0
- package/lang/translations/pt-br.po +4 -0
- package/lang/translations/pt.po +4 -0
- package/lang/translations/ro.po +4 -0
- package/lang/translations/ru.po +4 -0
- package/lang/translations/si.po +4 -0
- package/lang/translations/sk.po +4 -0
- package/lang/translations/sl.po +4 -0
- package/lang/translations/sq.po +4 -0
- package/lang/translations/sr-latn.po +4 -0
- package/lang/translations/sr.po +4 -0
- package/lang/translations/sv.po +4 -0
- package/lang/translations/th.po +4 -0
- package/lang/translations/ti.po +4 -0
- package/lang/translations/tk.po +4 -0
- package/lang/translations/tr.po +4 -0
- package/lang/translations/tt.po +4 -0
- package/lang/translations/ug.po +4 -0
- package/lang/translations/uk.po +4 -0
- package/lang/translations/ur.po +4 -0
- package/lang/translations/uz.po +4 -0
- package/lang/translations/vi.po +4 -0
- package/lang/translations/zh-cn.po +4 -0
- package/lang/translations/zh.po +4 -0
- package/package.json +9 -9
- package/src/linkediting.js +12 -3
- package/src/linkui.js +2 -2
- package/src/ui/linkactionsview.d.ts +15 -1
- package/src/ui/linkactionsview.js +21 -5
- package/src/utils.d.ts +6 -0
- package/src/utils.js +35 -0
package/lang/translations/vi.po
CHANGED
|
@@ -58,3 +58,7 @@ msgstr "Tạo liên kết"
|
|
|
58
58
|
msgctxt "Keystroke description for assistive technologies: keystroke for moving out of a link."
|
|
59
59
|
msgid "Move out of a link"
|
|
60
60
|
msgstr "Di chuyển ra khỏi một liên kết"
|
|
61
|
+
|
|
62
|
+
msgctxt "Button scrolling to the link target."
|
|
63
|
+
msgid "Scroll to target"
|
|
64
|
+
msgstr ""
|
package/lang/translations/zh.po
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-link",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "44.0.0-alpha.0",
|
|
4
4
|
"description": "Link feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ckeditor/ckeditor5-clipboard": "
|
|
17
|
-
"@ckeditor/ckeditor5-core": "
|
|
18
|
-
"@ckeditor/ckeditor5-engine": "
|
|
19
|
-
"@ckeditor/ckeditor5-typing": "
|
|
20
|
-
"@ckeditor/ckeditor5-ui": "
|
|
21
|
-
"@ckeditor/ckeditor5-utils": "
|
|
22
|
-
"@ckeditor/ckeditor5-widget": "
|
|
23
|
-
"ckeditor5": "
|
|
16
|
+
"@ckeditor/ckeditor5-clipboard": "44.0.0-alpha.0",
|
|
17
|
+
"@ckeditor/ckeditor5-core": "44.0.0-alpha.0",
|
|
18
|
+
"@ckeditor/ckeditor5-engine": "44.0.0-alpha.0",
|
|
19
|
+
"@ckeditor/ckeditor5-typing": "44.0.0-alpha.0",
|
|
20
|
+
"@ckeditor/ckeditor5-ui": "44.0.0-alpha.0",
|
|
21
|
+
"@ckeditor/ckeditor5-utils": "44.0.0-alpha.0",
|
|
22
|
+
"@ckeditor/ckeditor5-widget": "44.0.0-alpha.0",
|
|
23
|
+
"ckeditor5": "44.0.0-alpha.0",
|
|
24
24
|
"lodash-es": "4.17.21"
|
|
25
25
|
},
|
|
26
26
|
"author": "CKSource (http://cksource.com/)",
|
package/src/linkediting.js
CHANGED
|
@@ -12,7 +12,7 @@ import { keyCodes, env } from 'ckeditor5/src/utils.js';
|
|
|
12
12
|
import LinkCommand from './linkcommand.js';
|
|
13
13
|
import UnlinkCommand from './unlinkcommand.js';
|
|
14
14
|
import ManualDecorator from './utils/manualdecorator.js';
|
|
15
|
-
import { createLinkElement, ensureSafeUrl, getLocalizedDecorators, normalizeDecorators,
|
|
15
|
+
import { createLinkElement, ensureSafeUrl, getLocalizedDecorators, normalizeDecorators, addLinkProtocolIfApplicable, createBookmarkCallbacks, openLink } from './utils.js';
|
|
16
16
|
import '../theme/link.css';
|
|
17
17
|
const HIGHLIGHT_CLASS = 'ck-link_selected';
|
|
18
18
|
const DECORATOR_AUTOMATIC = 'automatic';
|
|
@@ -193,6 +193,15 @@ export default class LinkEditing extends Plugin {
|
|
|
193
193
|
const editor = this.editor;
|
|
194
194
|
const view = editor.editing.view;
|
|
195
195
|
const viewDocument = view.document;
|
|
196
|
+
const bookmarkCallbacks = createBookmarkCallbacks(editor);
|
|
197
|
+
function handleLinkOpening(url) {
|
|
198
|
+
if (bookmarkCallbacks.isScrollableToTarget(url)) {
|
|
199
|
+
bookmarkCallbacks.scrollToTarget(url);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
openLink(url);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
196
205
|
this.listenTo(viewDocument, 'click', (evt, data) => {
|
|
197
206
|
const shouldOpen = env.isMac ? data.domEvent.metaKey : data.domEvent.ctrlKey;
|
|
198
207
|
if (!shouldOpen) {
|
|
@@ -211,7 +220,7 @@ export default class LinkEditing extends Plugin {
|
|
|
211
220
|
}
|
|
212
221
|
evt.stop();
|
|
213
222
|
data.preventDefault();
|
|
214
|
-
|
|
223
|
+
handleLinkOpening(url);
|
|
215
224
|
}, { context: '$capture' });
|
|
216
225
|
// Open link on Alt+Enter.
|
|
217
226
|
this.listenTo(viewDocument, 'keydown', (evt, data) => {
|
|
@@ -222,7 +231,7 @@ export default class LinkEditing extends Plugin {
|
|
|
222
231
|
return;
|
|
223
232
|
}
|
|
224
233
|
evt.stop();
|
|
225
|
-
|
|
234
|
+
handleLinkOpening(url);
|
|
226
235
|
});
|
|
227
236
|
}
|
|
228
237
|
/**
|
package/src/linkui.js
CHANGED
|
@@ -11,7 +11,7 @@ import { ButtonView, ContextualBalloon, clickOutsideHandler, CssTransitionDisabl
|
|
|
11
11
|
import { isWidget } from 'ckeditor5/src/widget.js';
|
|
12
12
|
import LinkFormView from './ui/linkformview.js';
|
|
13
13
|
import LinkActionsView from './ui/linkactionsview.js';
|
|
14
|
-
import { addLinkProtocolIfApplicable, isLinkElement, LINK_KEYSTROKE } from './utils.js';
|
|
14
|
+
import { addLinkProtocolIfApplicable, isLinkElement, createBookmarkCallbacks, LINK_KEYSTROKE } from './utils.js';
|
|
15
15
|
import linkIcon from '../theme/icons/link.svg';
|
|
16
16
|
const VISUAL_SELECTION_MARKER_NAME = 'link-ui';
|
|
17
17
|
/**
|
|
@@ -124,7 +124,7 @@ export default class LinkUI extends Plugin {
|
|
|
124
124
|
*/
|
|
125
125
|
_createActionsView() {
|
|
126
126
|
const editor = this.editor;
|
|
127
|
-
const actionsView = new LinkActionsView(editor.locale, editor.config.get('link'));
|
|
127
|
+
const actionsView = new LinkActionsView(editor.locale, editor.config.get('link'), createBookmarkCallbacks(editor));
|
|
128
128
|
const linkCommand = editor.commands.get('link');
|
|
129
129
|
const unlinkCommand = editor.commands.get('unlink');
|
|
130
130
|
actionsView.bind('href').to(linkCommand, 'value');
|
|
@@ -50,11 +50,12 @@ export default class LinkActionsView extends View {
|
|
|
50
50
|
*/
|
|
51
51
|
private readonly _focusCycler;
|
|
52
52
|
private readonly _linkConfig;
|
|
53
|
+
private readonly _options?;
|
|
53
54
|
t: LocaleTranslate;
|
|
54
55
|
/**
|
|
55
56
|
* @inheritDoc
|
|
56
57
|
*/
|
|
57
|
-
constructor(locale: Locale, linkConfig?: LinkConfig);
|
|
58
|
+
constructor(locale: Locale, linkConfig?: LinkConfig, options?: LinkActionsViewOptions);
|
|
58
59
|
/**
|
|
59
60
|
* @inheritDoc
|
|
60
61
|
*/
|
|
@@ -101,3 +102,16 @@ export type UnlinkEvent = {
|
|
|
101
102
|
name: 'unlink';
|
|
102
103
|
args: [];
|
|
103
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* The options that are passed to the {@link ~LinkActionsView#constructor} constructor.
|
|
107
|
+
*/
|
|
108
|
+
export type LinkActionsViewOptions = {
|
|
109
|
+
/**
|
|
110
|
+
* Returns `true` when bookmark `id` matches the hash from `link`.
|
|
111
|
+
*/
|
|
112
|
+
isScrollableToTarget: (href: string | undefined) => boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Scrolls the view to the desired bookmark or open a link in new window.
|
|
115
|
+
*/
|
|
116
|
+
scrollToTarget: (href: string) => void;
|
|
117
|
+
};
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { ButtonView, View, ViewCollection, FocusCycler } from 'ckeditor5/src/ui.js';
|
|
9
9
|
import { FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils.js';
|
|
10
10
|
import { icons } from 'ckeditor5/src/core.js';
|
|
11
|
-
import { ensureSafeUrl } from '../utils.js';
|
|
11
|
+
import { ensureSafeUrl, openLink } from '../utils.js';
|
|
12
12
|
// See: #8833.
|
|
13
13
|
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
14
14
|
import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
|
|
@@ -22,7 +22,7 @@ export default class LinkActionsView extends View {
|
|
|
22
22
|
/**
|
|
23
23
|
* @inheritDoc
|
|
24
24
|
*/
|
|
25
|
-
constructor(locale, linkConfig = {}) {
|
|
25
|
+
constructor(locale, linkConfig = {}, options) {
|
|
26
26
|
super(locale);
|
|
27
27
|
/**
|
|
28
28
|
* Tracks information about DOM focus in the actions.
|
|
@@ -37,6 +37,7 @@ export default class LinkActionsView extends View {
|
|
|
37
37
|
*/
|
|
38
38
|
this._focusables = new ViewCollection();
|
|
39
39
|
const t = locale.t;
|
|
40
|
+
this._options = options;
|
|
40
41
|
this.previewButtonView = this._createPreviewButton();
|
|
41
42
|
this.unlinkButtonView = this._createButton(t('Unlink'), unlinkIcon, 'unlink');
|
|
42
43
|
this.editButtonView = this._createButton(t('Edit link'), icons.pencil, 'edit');
|
|
@@ -132,8 +133,7 @@ export default class LinkActionsView extends View {
|
|
|
132
133
|
const bind = this.bindTemplate;
|
|
133
134
|
const t = this.t;
|
|
134
135
|
button.set({
|
|
135
|
-
withText: true
|
|
136
|
-
tooltip: t('Open link in new tab')
|
|
136
|
+
withText: true
|
|
137
137
|
});
|
|
138
138
|
button.extendTemplate({
|
|
139
139
|
attributes: {
|
|
@@ -144,14 +144,30 @@ export default class LinkActionsView extends View {
|
|
|
144
144
|
href: bind.to('href', href => href && ensureSafeUrl(href, this._linkConfig.allowedProtocols)),
|
|
145
145
|
target: '_blank',
|
|
146
146
|
rel: 'noopener noreferrer'
|
|
147
|
+
},
|
|
148
|
+
on: {
|
|
149
|
+
click: bind.to(evt => {
|
|
150
|
+
if (this._options && this._options.isScrollableToTarget(this.href)) {
|
|
151
|
+
evt.preventDefault();
|
|
152
|
+
this._options.scrollToTarget(this.href);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
openLink(this.href);
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
button.bind('tooltip').to(this, 'href', href => {
|
|
161
|
+
if (this._options && this._options.isScrollableToTarget(href)) {
|
|
162
|
+
return t('Scroll to target');
|
|
147
163
|
}
|
|
164
|
+
return t('Open link in new tab');
|
|
148
165
|
});
|
|
149
166
|
button.bind('label').to(this, 'href', href => {
|
|
150
167
|
return href || t('This link has no URL');
|
|
151
168
|
});
|
|
152
169
|
button.bind('isEnabled').to(this, 'href', href => !!href);
|
|
153
170
|
button.template.tag = 'a';
|
|
154
|
-
button.template.eventListeners = {};
|
|
155
171
|
return button;
|
|
156
172
|
}
|
|
157
173
|
}
|
package/src/utils.d.ts
CHANGED
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* @module link/utils
|
|
7
7
|
*/
|
|
8
8
|
import type { DowncastConversionApi, Element, Schema, ViewAttributeElement, ViewNode, ViewDocumentFragment } from 'ckeditor5/src/engine.js';
|
|
9
|
+
import type { Editor } from 'ckeditor5/src/core.js';
|
|
9
10
|
import type { LocaleTranslate } from 'ckeditor5/src/utils.js';
|
|
10
11
|
import type { LinkDecoratorAutomaticDefinition, LinkDecoratorDefinition, LinkDecoratorManualDefinition } from './linkconfig.js';
|
|
12
|
+
import type { LinkActionsViewOptions } from './ui/linkactionsview.js';
|
|
11
13
|
/**
|
|
12
14
|
* A keystroke used by the {@link module:link/linkui~LinkUI link UI feature}.
|
|
13
15
|
*/
|
|
@@ -71,6 +73,10 @@ export declare function linkHasProtocol(link: string): boolean;
|
|
|
71
73
|
* Opens the link in a new browser tab.
|
|
72
74
|
*/
|
|
73
75
|
export declare function openLink(link: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Creates the bookmark callbacks for handling link opening experience.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createBookmarkCallbacks(editor: Editor): LinkActionsViewOptions;
|
|
74
80
|
export type NormalizedLinkDecoratorAutomaticDefinition = LinkDecoratorAutomaticDefinition & {
|
|
75
81
|
id: string;
|
|
76
82
|
};
|
package/src/utils.js
CHANGED
|
@@ -133,3 +133,38 @@ export function linkHasProtocol(link) {
|
|
|
133
133
|
export function openLink(link) {
|
|
134
134
|
window.open(link, '_blank', 'noopener');
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Creates the bookmark callbacks for handling link opening experience.
|
|
138
|
+
*/
|
|
139
|
+
export function createBookmarkCallbacks(editor) {
|
|
140
|
+
const bookmarkEditing = editor.plugins.has('BookmarkEditing') ?
|
|
141
|
+
editor.plugins.get('BookmarkEditing') :
|
|
142
|
+
null;
|
|
143
|
+
/**
|
|
144
|
+
* Returns `true` when bookmark `id` matches the hash from `link`.
|
|
145
|
+
*/
|
|
146
|
+
function isScrollableToTarget(link) {
|
|
147
|
+
return !!link &&
|
|
148
|
+
link.startsWith('#') &&
|
|
149
|
+
!!bookmarkEditing &&
|
|
150
|
+
!!bookmarkEditing.getElementForBookmarkId(link.slice(1));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Scrolls the view to the desired bookmark or open a link in new window.
|
|
154
|
+
*/
|
|
155
|
+
function scrollToTarget(link) {
|
|
156
|
+
const bookmarkId = link.slice(1);
|
|
157
|
+
const modelBookmark = bookmarkEditing.getElementForBookmarkId(bookmarkId);
|
|
158
|
+
editor.model.change(writer => {
|
|
159
|
+
writer.setSelection(modelBookmark, 'on');
|
|
160
|
+
});
|
|
161
|
+
editor.editing.view.scrollToTheSelection({
|
|
162
|
+
alignToTop: true,
|
|
163
|
+
forceScroll: true
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
isScrollableToTarget,
|
|
168
|
+
scrollToTarget
|
|
169
|
+
};
|
|
170
|
+
}
|