@ckeditor/ckeditor5-link 39.0.1 → 40.0.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/CHANGELOG.md +1 -1
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/build/link.js.map +1 -0
- package/build/translations/de.js +1 -1
- package/build/translations/hy.js +1 -0
- package/build/translations/pt-br.js +1 -1
- package/lang/translations/ar.po +1 -0
- package/lang/translations/ast.po +1 -0
- package/lang/translations/az.po +1 -0
- package/lang/translations/bg.po +1 -0
- package/lang/translations/bn.po +1 -0
- package/lang/translations/ca.po +1 -0
- package/lang/translations/cs.po +1 -0
- package/lang/translations/da.po +1 -0
- package/lang/translations/de-ch.po +1 -0
- package/lang/translations/de.po +2 -1
- package/lang/translations/el.po +1 -0
- package/lang/translations/en-au.po +1 -0
- package/lang/translations/en-gb.po +1 -0
- package/lang/translations/en.po +1 -0
- package/lang/translations/eo.po +1 -0
- package/lang/translations/es.po +1 -0
- package/lang/translations/et.po +1 -0
- package/lang/translations/eu.po +1 -0
- package/lang/translations/fa.po +1 -0
- package/lang/translations/fi.po +1 -0
- package/lang/translations/fr.po +1 -0
- package/lang/translations/gl.po +1 -0
- package/lang/translations/he.po +1 -0
- package/lang/translations/hi.po +1 -0
- package/lang/translations/hr.po +1 -0
- package/lang/translations/hu.po +1 -0
- package/lang/translations/hy.po +54 -0
- package/lang/translations/id.po +1 -0
- package/lang/translations/it.po +1 -0
- package/lang/translations/ja.po +1 -0
- package/lang/translations/km.po +1 -0
- package/lang/translations/kn.po +1 -0
- package/lang/translations/ko.po +1 -0
- package/lang/translations/ku.po +1 -0
- package/lang/translations/lt.po +1 -0
- package/lang/translations/lv.po +1 -0
- package/lang/translations/ms.po +1 -0
- package/lang/translations/nb.po +1 -0
- package/lang/translations/ne.po +1 -0
- package/lang/translations/nl.po +1 -0
- package/lang/translations/no.po +1 -0
- package/lang/translations/pl.po +1 -0
- package/lang/translations/pt-br.po +3 -2
- package/lang/translations/pt.po +1 -0
- package/lang/translations/ro.po +1 -0
- package/lang/translations/ru.po +1 -0
- package/lang/translations/sk.po +1 -0
- package/lang/translations/sq.po +1 -0
- package/lang/translations/sr-latn.po +1 -0
- package/lang/translations/sr.po +1 -0
- package/lang/translations/sv.po +1 -0
- package/lang/translations/th.po +1 -0
- package/lang/translations/tk.po +1 -0
- package/lang/translations/tr.po +1 -0
- package/lang/translations/tt.po +1 -0
- package/lang/translations/ug.po +1 -0
- package/lang/translations/uk.po +1 -0
- package/lang/translations/ur.po +1 -0
- package/lang/translations/uz.po +1 -0
- package/lang/translations/vi.po +1 -0
- package/lang/translations/zh-cn.po +1 -0
- package/lang/translations/zh.po +1 -0
- package/package.json +3 -7
- package/src/augmentation.d.ts +30 -30
- package/src/augmentation.js +5 -5
- package/src/autolink.d.ts +60 -60
- package/src/autolink.js +216 -216
- package/src/index.d.ts +18 -18
- package/src/index.js +17 -17
- package/src/link.d.ts +27 -27
- package/src/link.js +31 -31
- package/src/linkcommand.d.ts +132 -132
- package/src/linkcommand.js +285 -285
- package/src/linkconfig.d.ts +251 -251
- package/src/linkconfig.js +5 -5
- package/src/linkediting.d.ts +106 -106
- package/src/linkediting.js +547 -547
- package/src/linkimage.d.ts +27 -27
- package/src/linkimage.js +31 -31
- package/src/linkimageediting.d.ts +39 -39
- package/src/linkimageediting.js +245 -245
- package/src/linkimageui.d.ts +40 -40
- package/src/linkimageui.js +96 -96
- package/src/linkui.d.ts +165 -165
- package/src/linkui.js +581 -581
- package/src/ui/linkactionsview.d.ts +101 -101
- package/src/ui/linkactionsview.js +156 -156
- package/src/ui/linkformview.d.ts +141 -141
- package/src/ui/linkformview.js +232 -232
- package/src/unlinkcommand.d.ts +31 -31
- package/src/unlinkcommand.js +66 -66
- package/src/utils/automaticdecorators.d.ts +45 -45
- package/src/utils/automaticdecorators.js +140 -140
- package/src/utils/manualdecorator.d.ts +72 -72
- package/src/utils/manualdecorator.js +47 -47
- package/src/utils.d.ts +80 -80
- package/src/utils.js +128 -128
package/src/autolink.js
CHANGED
|
@@ -1,216 +1,216 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link/autolink
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { Delete, TextWatcher, getLastTextLine } from 'ckeditor5/src/typing';
|
|
10
|
-
import { addLinkProtocolIfApplicable, linkHasProtocol } from './utils';
|
|
11
|
-
const MIN_LINK_LENGTH_WITH_SPACE_AT_END = 4; // Ie: "t.co " (length 5).
|
|
12
|
-
// This was a tweak from https://gist.github.com/dperini/729294.
|
|
13
|
-
const URL_REG_EXP = new RegExp(
|
|
14
|
-
// Group 1: Line start or after a space.
|
|
15
|
-
'(^|\\s)' +
|
|
16
|
-
// Group 2: Detected URL (or e-mail).
|
|
17
|
-
'(' +
|
|
18
|
-
// Protocol identifier or short syntax "//"
|
|
19
|
-
// a. Full form http://user@foo.bar.baz:8080/foo/bar.html#baz?foo=bar
|
|
20
|
-
'(' +
|
|
21
|
-
'(?:(?:(?:https?|ftp):)?\\/\\/)' +
|
|
22
|
-
// BasicAuth using user:pass (optional)
|
|
23
|
-
'(?:\\S+(?::\\S*)?@)?' +
|
|
24
|
-
'(?:' +
|
|
25
|
-
// IP address dotted notation octets
|
|
26
|
-
// excludes loopback network 0.0.0.0
|
|
27
|
-
// excludes reserved space >= 224.0.0.0
|
|
28
|
-
// excludes network & broadcast addresses
|
|
29
|
-
// (first & last IP address of each class)
|
|
30
|
-
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
|
|
31
|
-
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
|
|
32
|
-
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
|
|
33
|
-
'|' +
|
|
34
|
-
'(' +
|
|
35
|
-
// Do not allow `www.foo` - see https://github.com/ckeditor/ckeditor5/issues/8050.
|
|
36
|
-
'((?!www\\.)|(www\\.))' +
|
|
37
|
-
// Host & domain names.
|
|
38
|
-
'(?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.)+' +
|
|
39
|
-
// TLD identifier name.
|
|
40
|
-
'(?:[a-z\\u00a1-\\uffff]{2,63})' +
|
|
41
|
-
')' +
|
|
42
|
-
')' +
|
|
43
|
-
// port number (optional)
|
|
44
|
-
'(?::\\d{2,5})?' +
|
|
45
|
-
// resource path (optional)
|
|
46
|
-
'(?:[/?#]\\S*)?' +
|
|
47
|
-
')' +
|
|
48
|
-
'|' +
|
|
49
|
-
// b. Short form (either www.example.com or example@example.com)
|
|
50
|
-
'(' +
|
|
51
|
-
'(www.|(\\S+@))' +
|
|
52
|
-
// Host & domain names.
|
|
53
|
-
'((?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.))+' +
|
|
54
|
-
// TLD identifier name.
|
|
55
|
-
'(?:[a-z\\u00a1-\\uffff]{2,63})' +
|
|
56
|
-
')' +
|
|
57
|
-
')$', 'i');
|
|
58
|
-
const URL_GROUP_IN_MATCH = 2;
|
|
59
|
-
/**
|
|
60
|
-
* The autolink plugin.
|
|
61
|
-
*/
|
|
62
|
-
export default class AutoLink extends Plugin {
|
|
63
|
-
/**
|
|
64
|
-
* @inheritDoc
|
|
65
|
-
*/
|
|
66
|
-
static get requires() {
|
|
67
|
-
return [Delete];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @inheritDoc
|
|
71
|
-
*/
|
|
72
|
-
static get pluginName() {
|
|
73
|
-
return 'AutoLink';
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @inheritDoc
|
|
77
|
-
*/
|
|
78
|
-
init() {
|
|
79
|
-
const editor = this.editor;
|
|
80
|
-
const selection = editor.model.document.selection;
|
|
81
|
-
selection.on('change:range', () => {
|
|
82
|
-
// Disable plugin when selection is inside a code block.
|
|
83
|
-
this.isEnabled = !selection.anchor.parent.is('element', 'codeBlock');
|
|
84
|
-
});
|
|
85
|
-
this._enableTypingHandling();
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @inheritDoc
|
|
89
|
-
*/
|
|
90
|
-
afterInit() {
|
|
91
|
-
this._enableEnterHandling();
|
|
92
|
-
this._enableShiftEnterHandling();
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Enables autolinking on typing.
|
|
96
|
-
*/
|
|
97
|
-
_enableTypingHandling() {
|
|
98
|
-
const editor = this.editor;
|
|
99
|
-
const watcher = new TextWatcher(editor.model, text => {
|
|
100
|
-
// 1. Detect <kbd>Space</kbd> after a text with a potential link.
|
|
101
|
-
if (!isSingleSpaceAtTheEnd(text)) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
// 2. Check text before last typed <kbd>Space</kbd>.
|
|
105
|
-
const url = getUrlAtTextEnd(text.substr(0, text.length - 1));
|
|
106
|
-
if (url) {
|
|
107
|
-
return { url };
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
watcher.on('matched:data', (evt, data) => {
|
|
111
|
-
const { batch, range, url } = data;
|
|
112
|
-
if (!batch.isTyping) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const linkEnd = range.end.getShiftedBy(-1); // Executed after a space character.
|
|
116
|
-
const linkStart = linkEnd.getShiftedBy(-url.length);
|
|
117
|
-
const linkRange = editor.model.createRange(linkStart, linkEnd);
|
|
118
|
-
this._applyAutoLink(url, linkRange);
|
|
119
|
-
});
|
|
120
|
-
watcher.bind('isEnabled').to(this);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Enables autolinking on the <kbd>Enter</kbd> key.
|
|
124
|
-
*/
|
|
125
|
-
_enableEnterHandling() {
|
|
126
|
-
const editor = this.editor;
|
|
127
|
-
const model = editor.model;
|
|
128
|
-
const enterCommand = editor.commands.get('enter');
|
|
129
|
-
if (!enterCommand) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
enterCommand.on('execute', () => {
|
|
133
|
-
const position = model.document.selection.getFirstPosition();
|
|
134
|
-
if (!position.parent.previousSibling) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const rangeToCheck = model.createRangeIn(position.parent.previousSibling);
|
|
138
|
-
this._checkAndApplyAutoLinkOnRange(rangeToCheck);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Enables autolinking on the <kbd>Shift</kbd>+<kbd>Enter</kbd> keyboard shortcut.
|
|
143
|
-
*/
|
|
144
|
-
_enableShiftEnterHandling() {
|
|
145
|
-
const editor = this.editor;
|
|
146
|
-
const model = editor.model;
|
|
147
|
-
const shiftEnterCommand = editor.commands.get('shiftEnter');
|
|
148
|
-
if (!shiftEnterCommand) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
shiftEnterCommand.on('execute', () => {
|
|
152
|
-
const position = model.document.selection.getFirstPosition();
|
|
153
|
-
const rangeToCheck = model.createRange(model.createPositionAt(position.parent, 0), position.getShiftedBy(-1));
|
|
154
|
-
this._checkAndApplyAutoLinkOnRange(rangeToCheck);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Checks if the passed range contains a linkable text.
|
|
159
|
-
*/
|
|
160
|
-
_checkAndApplyAutoLinkOnRange(rangeToCheck) {
|
|
161
|
-
const model = this.editor.model;
|
|
162
|
-
const { text, range } = getLastTextLine(rangeToCheck, model);
|
|
163
|
-
const url = getUrlAtTextEnd(text);
|
|
164
|
-
if (url) {
|
|
165
|
-
const linkRange = model.createRange(range.end.getShiftedBy(-url.length), range.end);
|
|
166
|
-
this._applyAutoLink(url, linkRange);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Applies a link on a given range if the link should be applied.
|
|
171
|
-
*
|
|
172
|
-
* @param url The URL to link.
|
|
173
|
-
* @param range The text range to apply the link attribute to.
|
|
174
|
-
*/
|
|
175
|
-
_applyAutoLink(url, range) {
|
|
176
|
-
const model = this.editor.model;
|
|
177
|
-
const defaultProtocol = this.editor.config.get('link.defaultProtocol');
|
|
178
|
-
const fullUrl = addLinkProtocolIfApplicable(url, defaultProtocol);
|
|
179
|
-
if (!this.isEnabled || !isLinkAllowedOnRange(range, model) || !linkHasProtocol(fullUrl) || linkIsAlreadySet(range)) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
this._persistAutoLink(fullUrl, range);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Enqueues autolink changes in the model.
|
|
186
|
-
*
|
|
187
|
-
* @param url The URL to link.
|
|
188
|
-
* @param range The text range to apply the link attribute to.
|
|
189
|
-
*/
|
|
190
|
-
_persistAutoLink(url, range) {
|
|
191
|
-
const model = this.editor.model;
|
|
192
|
-
const deletePlugin = this.editor.plugins.get('Delete');
|
|
193
|
-
// Enqueue change to make undo step.
|
|
194
|
-
model.enqueueChange(writer => {
|
|
195
|
-
writer.setAttribute('linkHref', url, range);
|
|
196
|
-
model.enqueueChange(() => {
|
|
197
|
-
deletePlugin.requestUndoOnBackspace();
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
// Check if text should be evaluated by the plugin in order to reduce number of RegExp checks on whole text.
|
|
203
|
-
function isSingleSpaceAtTheEnd(text) {
|
|
204
|
-
return text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[text.length - 1] === ' ' && text[text.length - 2] !== ' ';
|
|
205
|
-
}
|
|
206
|
-
function getUrlAtTextEnd(text) {
|
|
207
|
-
const match = URL_REG_EXP.exec(text);
|
|
208
|
-
return match ? match[URL_GROUP_IN_MATCH] : null;
|
|
209
|
-
}
|
|
210
|
-
function isLinkAllowedOnRange(range, model) {
|
|
211
|
-
return model.schema.checkAttributeInSelection(model.createSelection(range), 'linkHref');
|
|
212
|
-
}
|
|
213
|
-
function linkIsAlreadySet(range) {
|
|
214
|
-
const item = range.start.nodeAfter;
|
|
215
|
-
return !!item && item.hasAttribute('linkHref');
|
|
216
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module link/autolink
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { Delete, TextWatcher, getLastTextLine } from 'ckeditor5/src/typing';
|
|
10
|
+
import { addLinkProtocolIfApplicable, linkHasProtocol } from './utils';
|
|
11
|
+
const MIN_LINK_LENGTH_WITH_SPACE_AT_END = 4; // Ie: "t.co " (length 5).
|
|
12
|
+
// This was a tweak from https://gist.github.com/dperini/729294.
|
|
13
|
+
const URL_REG_EXP = new RegExp(
|
|
14
|
+
// Group 1: Line start or after a space.
|
|
15
|
+
'(^|\\s)' +
|
|
16
|
+
// Group 2: Detected URL (or e-mail).
|
|
17
|
+
'(' +
|
|
18
|
+
// Protocol identifier or short syntax "//"
|
|
19
|
+
// a. Full form http://user@foo.bar.baz:8080/foo/bar.html#baz?foo=bar
|
|
20
|
+
'(' +
|
|
21
|
+
'(?:(?:(?:https?|ftp):)?\\/\\/)' +
|
|
22
|
+
// BasicAuth using user:pass (optional)
|
|
23
|
+
'(?:\\S+(?::\\S*)?@)?' +
|
|
24
|
+
'(?:' +
|
|
25
|
+
// IP address dotted notation octets
|
|
26
|
+
// excludes loopback network 0.0.0.0
|
|
27
|
+
// excludes reserved space >= 224.0.0.0
|
|
28
|
+
// excludes network & broadcast addresses
|
|
29
|
+
// (first & last IP address of each class)
|
|
30
|
+
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
|
|
31
|
+
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
|
|
32
|
+
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
|
|
33
|
+
'|' +
|
|
34
|
+
'(' +
|
|
35
|
+
// Do not allow `www.foo` - see https://github.com/ckeditor/ckeditor5/issues/8050.
|
|
36
|
+
'((?!www\\.)|(www\\.))' +
|
|
37
|
+
// Host & domain names.
|
|
38
|
+
'(?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.)+' +
|
|
39
|
+
// TLD identifier name.
|
|
40
|
+
'(?:[a-z\\u00a1-\\uffff]{2,63})' +
|
|
41
|
+
')' +
|
|
42
|
+
')' +
|
|
43
|
+
// port number (optional)
|
|
44
|
+
'(?::\\d{2,5})?' +
|
|
45
|
+
// resource path (optional)
|
|
46
|
+
'(?:[/?#]\\S*)?' +
|
|
47
|
+
')' +
|
|
48
|
+
'|' +
|
|
49
|
+
// b. Short form (either www.example.com or example@example.com)
|
|
50
|
+
'(' +
|
|
51
|
+
'(www.|(\\S+@))' +
|
|
52
|
+
// Host & domain names.
|
|
53
|
+
'((?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.))+' +
|
|
54
|
+
// TLD identifier name.
|
|
55
|
+
'(?:[a-z\\u00a1-\\uffff]{2,63})' +
|
|
56
|
+
')' +
|
|
57
|
+
')$', 'i');
|
|
58
|
+
const URL_GROUP_IN_MATCH = 2;
|
|
59
|
+
/**
|
|
60
|
+
* The autolink plugin.
|
|
61
|
+
*/
|
|
62
|
+
export default class AutoLink extends Plugin {
|
|
63
|
+
/**
|
|
64
|
+
* @inheritDoc
|
|
65
|
+
*/
|
|
66
|
+
static get requires() {
|
|
67
|
+
return [Delete];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @inheritDoc
|
|
71
|
+
*/
|
|
72
|
+
static get pluginName() {
|
|
73
|
+
return 'AutoLink';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
*/
|
|
78
|
+
init() {
|
|
79
|
+
const editor = this.editor;
|
|
80
|
+
const selection = editor.model.document.selection;
|
|
81
|
+
selection.on('change:range', () => {
|
|
82
|
+
// Disable plugin when selection is inside a code block.
|
|
83
|
+
this.isEnabled = !selection.anchor.parent.is('element', 'codeBlock');
|
|
84
|
+
});
|
|
85
|
+
this._enableTypingHandling();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @inheritDoc
|
|
89
|
+
*/
|
|
90
|
+
afterInit() {
|
|
91
|
+
this._enableEnterHandling();
|
|
92
|
+
this._enableShiftEnterHandling();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Enables autolinking on typing.
|
|
96
|
+
*/
|
|
97
|
+
_enableTypingHandling() {
|
|
98
|
+
const editor = this.editor;
|
|
99
|
+
const watcher = new TextWatcher(editor.model, text => {
|
|
100
|
+
// 1. Detect <kbd>Space</kbd> after a text with a potential link.
|
|
101
|
+
if (!isSingleSpaceAtTheEnd(text)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// 2. Check text before last typed <kbd>Space</kbd>.
|
|
105
|
+
const url = getUrlAtTextEnd(text.substr(0, text.length - 1));
|
|
106
|
+
if (url) {
|
|
107
|
+
return { url };
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
watcher.on('matched:data', (evt, data) => {
|
|
111
|
+
const { batch, range, url } = data;
|
|
112
|
+
if (!batch.isTyping) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const linkEnd = range.end.getShiftedBy(-1); // Executed after a space character.
|
|
116
|
+
const linkStart = linkEnd.getShiftedBy(-url.length);
|
|
117
|
+
const linkRange = editor.model.createRange(linkStart, linkEnd);
|
|
118
|
+
this._applyAutoLink(url, linkRange);
|
|
119
|
+
});
|
|
120
|
+
watcher.bind('isEnabled').to(this);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Enables autolinking on the <kbd>Enter</kbd> key.
|
|
124
|
+
*/
|
|
125
|
+
_enableEnterHandling() {
|
|
126
|
+
const editor = this.editor;
|
|
127
|
+
const model = editor.model;
|
|
128
|
+
const enterCommand = editor.commands.get('enter');
|
|
129
|
+
if (!enterCommand) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
enterCommand.on('execute', () => {
|
|
133
|
+
const position = model.document.selection.getFirstPosition();
|
|
134
|
+
if (!position.parent.previousSibling) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const rangeToCheck = model.createRangeIn(position.parent.previousSibling);
|
|
138
|
+
this._checkAndApplyAutoLinkOnRange(rangeToCheck);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Enables autolinking on the <kbd>Shift</kbd>+<kbd>Enter</kbd> keyboard shortcut.
|
|
143
|
+
*/
|
|
144
|
+
_enableShiftEnterHandling() {
|
|
145
|
+
const editor = this.editor;
|
|
146
|
+
const model = editor.model;
|
|
147
|
+
const shiftEnterCommand = editor.commands.get('shiftEnter');
|
|
148
|
+
if (!shiftEnterCommand) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
shiftEnterCommand.on('execute', () => {
|
|
152
|
+
const position = model.document.selection.getFirstPosition();
|
|
153
|
+
const rangeToCheck = model.createRange(model.createPositionAt(position.parent, 0), position.getShiftedBy(-1));
|
|
154
|
+
this._checkAndApplyAutoLinkOnRange(rangeToCheck);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Checks if the passed range contains a linkable text.
|
|
159
|
+
*/
|
|
160
|
+
_checkAndApplyAutoLinkOnRange(rangeToCheck) {
|
|
161
|
+
const model = this.editor.model;
|
|
162
|
+
const { text, range } = getLastTextLine(rangeToCheck, model);
|
|
163
|
+
const url = getUrlAtTextEnd(text);
|
|
164
|
+
if (url) {
|
|
165
|
+
const linkRange = model.createRange(range.end.getShiftedBy(-url.length), range.end);
|
|
166
|
+
this._applyAutoLink(url, linkRange);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Applies a link on a given range if the link should be applied.
|
|
171
|
+
*
|
|
172
|
+
* @param url The URL to link.
|
|
173
|
+
* @param range The text range to apply the link attribute to.
|
|
174
|
+
*/
|
|
175
|
+
_applyAutoLink(url, range) {
|
|
176
|
+
const model = this.editor.model;
|
|
177
|
+
const defaultProtocol = this.editor.config.get('link.defaultProtocol');
|
|
178
|
+
const fullUrl = addLinkProtocolIfApplicable(url, defaultProtocol);
|
|
179
|
+
if (!this.isEnabled || !isLinkAllowedOnRange(range, model) || !linkHasProtocol(fullUrl) || linkIsAlreadySet(range)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this._persistAutoLink(fullUrl, range);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Enqueues autolink changes in the model.
|
|
186
|
+
*
|
|
187
|
+
* @param url The URL to link.
|
|
188
|
+
* @param range The text range to apply the link attribute to.
|
|
189
|
+
*/
|
|
190
|
+
_persistAutoLink(url, range) {
|
|
191
|
+
const model = this.editor.model;
|
|
192
|
+
const deletePlugin = this.editor.plugins.get('Delete');
|
|
193
|
+
// Enqueue change to make undo step.
|
|
194
|
+
model.enqueueChange(writer => {
|
|
195
|
+
writer.setAttribute('linkHref', url, range);
|
|
196
|
+
model.enqueueChange(() => {
|
|
197
|
+
deletePlugin.requestUndoOnBackspace();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Check if text should be evaluated by the plugin in order to reduce number of RegExp checks on whole text.
|
|
203
|
+
function isSingleSpaceAtTheEnd(text) {
|
|
204
|
+
return text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[text.length - 1] === ' ' && text[text.length - 2] !== ' ';
|
|
205
|
+
}
|
|
206
|
+
function getUrlAtTextEnd(text) {
|
|
207
|
+
const match = URL_REG_EXP.exec(text);
|
|
208
|
+
return match ? match[URL_GROUP_IN_MATCH] : null;
|
|
209
|
+
}
|
|
210
|
+
function isLinkAllowedOnRange(range, model) {
|
|
211
|
+
return model.schema.checkAttributeInSelection(model.createSelection(range), 'linkHref');
|
|
212
|
+
}
|
|
213
|
+
function linkIsAlreadySet(range) {
|
|
214
|
+
const item = range.start.nodeAfter;
|
|
215
|
+
return !!item && item.hasAttribute('linkHref');
|
|
216
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link
|
|
7
|
-
*/
|
|
8
|
-
export { default as Link } from './link';
|
|
9
|
-
export { default as LinkEditing } from './linkediting';
|
|
10
|
-
export { default as LinkUI } from './linkui';
|
|
11
|
-
export { default as LinkImage } from './linkimage';
|
|
12
|
-
export { default as LinkImageEditing } from './linkimageediting';
|
|
13
|
-
export { default as LinkImageUI } from './linkimageui';
|
|
14
|
-
export { default as AutoLink } from './autolink';
|
|
15
|
-
export { LinkConfig } from './linkconfig';
|
|
16
|
-
export { default as LinkCommand } from './linkcommand';
|
|
17
|
-
export { default as UnlinkCommand } from './unlinkcommand';
|
|
18
|
-
import './augmentation';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module link
|
|
7
|
+
*/
|
|
8
|
+
export { default as Link } from './link';
|
|
9
|
+
export { default as LinkEditing } from './linkediting';
|
|
10
|
+
export { default as LinkUI } from './linkui';
|
|
11
|
+
export { default as LinkImage } from './linkimage';
|
|
12
|
+
export { default as LinkImageEditing } from './linkimageediting';
|
|
13
|
+
export { default as LinkImageUI } from './linkimageui';
|
|
14
|
+
export { default as AutoLink } from './autolink';
|
|
15
|
+
export { LinkConfig } from './linkconfig';
|
|
16
|
+
export { default as LinkCommand } from './linkcommand';
|
|
17
|
+
export { default as UnlinkCommand } from './unlinkcommand';
|
|
18
|
+
import './augmentation';
|
package/src/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link
|
|
7
|
-
*/
|
|
8
|
-
export { default as Link } from './link';
|
|
9
|
-
export { default as LinkEditing } from './linkediting';
|
|
10
|
-
export { default as LinkUI } from './linkui';
|
|
11
|
-
export { default as LinkImage } from './linkimage';
|
|
12
|
-
export { default as LinkImageEditing } from './linkimageediting';
|
|
13
|
-
export { default as LinkImageUI } from './linkimageui';
|
|
14
|
-
export { default as AutoLink } from './autolink';
|
|
15
|
-
export { default as LinkCommand } from './linkcommand';
|
|
16
|
-
export { default as UnlinkCommand } from './unlinkcommand';
|
|
17
|
-
import './augmentation';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module link
|
|
7
|
+
*/
|
|
8
|
+
export { default as Link } from './link';
|
|
9
|
+
export { default as LinkEditing } from './linkediting';
|
|
10
|
+
export { default as LinkUI } from './linkui';
|
|
11
|
+
export { default as LinkImage } from './linkimage';
|
|
12
|
+
export { default as LinkImageEditing } from './linkimageediting';
|
|
13
|
+
export { default as LinkImageUI } from './linkimageui';
|
|
14
|
+
export { default as AutoLink } from './autolink';
|
|
15
|
+
export { default as LinkCommand } from './linkcommand';
|
|
16
|
+
export { default as UnlinkCommand } from './unlinkcommand';
|
|
17
|
+
import './augmentation';
|
package/src/link.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link/link
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import LinkEditing from './linkediting';
|
|
10
|
-
import LinkUI from './linkui';
|
|
11
|
-
import AutoLink from './autolink';
|
|
12
|
-
/**
|
|
13
|
-
* The link plugin.
|
|
14
|
-
*
|
|
15
|
-
* This is a "glue" plugin that loads the {@link module:link/linkediting~LinkEditing link editing feature}
|
|
16
|
-
* and {@link module:link/linkui~LinkUI link UI feature}.
|
|
17
|
-
*/
|
|
18
|
-
export default class Link extends Plugin {
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get requires(): readonly [typeof LinkEditing, typeof LinkUI, typeof AutoLink];
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
static get pluginName(): "Link";
|
|
27
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module link/link
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import LinkEditing from './linkediting';
|
|
10
|
+
import LinkUI from './linkui';
|
|
11
|
+
import AutoLink from './autolink';
|
|
12
|
+
/**
|
|
13
|
+
* The link plugin.
|
|
14
|
+
*
|
|
15
|
+
* This is a "glue" plugin that loads the {@link module:link/linkediting~LinkEditing link editing feature}
|
|
16
|
+
* and {@link module:link/linkui~LinkUI link UI feature}.
|
|
17
|
+
*/
|
|
18
|
+
export default class Link extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get requires(): readonly [typeof LinkEditing, typeof LinkUI, typeof AutoLink];
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get pluginName(): "Link";
|
|
27
|
+
}
|
package/src/link.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link/link
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import LinkEditing from './linkediting';
|
|
10
|
-
import LinkUI from './linkui';
|
|
11
|
-
import AutoLink from './autolink';
|
|
12
|
-
/**
|
|
13
|
-
* The link plugin.
|
|
14
|
-
*
|
|
15
|
-
* This is a "glue" plugin that loads the {@link module:link/linkediting~LinkEditing link editing feature}
|
|
16
|
-
* and {@link module:link/linkui~LinkUI link UI feature}.
|
|
17
|
-
*/
|
|
18
|
-
export default class Link extends Plugin {
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get requires() {
|
|
23
|
-
return [LinkEditing, LinkUI, AutoLink];
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @inheritDoc
|
|
27
|
-
*/
|
|
28
|
-
static get pluginName() {
|
|
29
|
-
return 'Link';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module link/link
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import LinkEditing from './linkediting';
|
|
10
|
+
import LinkUI from './linkui';
|
|
11
|
+
import AutoLink from './autolink';
|
|
12
|
+
/**
|
|
13
|
+
* The link plugin.
|
|
14
|
+
*
|
|
15
|
+
* This is a "glue" plugin that loads the {@link module:link/linkediting~LinkEditing link editing feature}
|
|
16
|
+
* and {@link module:link/linkui~LinkUI link UI feature}.
|
|
17
|
+
*/
|
|
18
|
+
export default class Link extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get requires() {
|
|
23
|
+
return [LinkEditing, LinkUI, AutoLink];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
static get pluginName() {
|
|
29
|
+
return 'Link';
|
|
30
|
+
}
|
|
31
|
+
}
|