@ckeditor/ckeditor5-link 47.6.1 → 48.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/LICENSE.md +1 -1
- package/ckeditor5-metadata.json +6 -6
- package/{src → dist}/autolink.d.ts +2 -2
- package/dist/index-editor.css +181 -105
- package/dist/index.css +169 -151
- package/dist/index.css.map +1 -1
- package/{src → dist}/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/{src → dist}/link.d.ts +1 -1
- package/{src → dist}/linkcommand.d.ts +2 -2
- package/{src → dist}/linkconfig.d.ts +1 -1
- package/{src → dist}/linkediting.d.ts +3 -3
- package/{src → dist}/linkimage.d.ts +1 -1
- package/{src → dist}/linkimageediting.d.ts +3 -2
- package/{src → dist}/linkimageui.d.ts +3 -2
- package/{src → dist}/linkui.d.ts +2 -2
- package/{src → dist}/ui/linkbuttonview.d.ts +2 -2
- package/{src → dist}/ui/linkformview.d.ts +2 -4
- package/{src → dist}/ui/linkpreviewbuttonview.d.ts +2 -2
- package/{src → dist}/ui/linkpropertiesview.d.ts +2 -2
- package/{src → dist}/ui/linkprovideritemsview.d.ts +2 -2
- package/{src → dist}/unlinkcommand.d.ts +1 -1
- package/{src → dist}/utils/automaticdecorators.d.ts +2 -2
- package/{src → dist}/utils/manualdecorator.d.ts +4 -4
- package/{src → dist}/utils.d.ts +2 -2
- package/package.json +29 -52
- package/build/link.js +0 -5
- package/build/translations/af.js +0 -1
- package/build/translations/ar.js +0 -1
- package/build/translations/ast.js +0 -1
- package/build/translations/az.js +0 -1
- package/build/translations/be.js +0 -1
- package/build/translations/bg.js +0 -1
- package/build/translations/bn.js +0 -1
- package/build/translations/bs.js +0 -1
- package/build/translations/ca.js +0 -1
- package/build/translations/cs.js +0 -1
- package/build/translations/da.js +0 -1
- package/build/translations/de-ch.js +0 -1
- package/build/translations/de.js +0 -1
- package/build/translations/el.js +0 -1
- package/build/translations/en-au.js +0 -1
- package/build/translations/en-gb.js +0 -1
- package/build/translations/eo.js +0 -1
- package/build/translations/es-co.js +0 -1
- package/build/translations/es.js +0 -1
- package/build/translations/et.js +0 -1
- package/build/translations/eu.js +0 -1
- package/build/translations/fa.js +0 -1
- package/build/translations/fi.js +0 -1
- package/build/translations/fr.js +0 -1
- package/build/translations/gl.js +0 -1
- package/build/translations/gu.js +0 -1
- package/build/translations/he.js +0 -1
- package/build/translations/hi.js +0 -1
- package/build/translations/hr.js +0 -1
- package/build/translations/hu.js +0 -1
- package/build/translations/hy.js +0 -1
- package/build/translations/id.js +0 -1
- package/build/translations/it.js +0 -1
- package/build/translations/ja.js +0 -1
- package/build/translations/jv.js +0 -1
- package/build/translations/kk.js +0 -1
- package/build/translations/km.js +0 -1
- package/build/translations/kn.js +0 -1
- package/build/translations/ko.js +0 -1
- package/build/translations/ku.js +0 -1
- package/build/translations/lt.js +0 -1
- package/build/translations/lv.js +0 -1
- package/build/translations/ms.js +0 -1
- package/build/translations/nb.js +0 -1
- package/build/translations/ne.js +0 -1
- package/build/translations/nl.js +0 -1
- package/build/translations/no.js +0 -1
- package/build/translations/oc.js +0 -1
- package/build/translations/pl.js +0 -1
- package/build/translations/pt-br.js +0 -1
- package/build/translations/pt.js +0 -1
- package/build/translations/ro.js +0 -1
- package/build/translations/ru.js +0 -1
- package/build/translations/si.js +0 -1
- package/build/translations/sk.js +0 -1
- package/build/translations/sl.js +0 -1
- package/build/translations/sq.js +0 -1
- package/build/translations/sr-latn.js +0 -1
- package/build/translations/sr.js +0 -1
- package/build/translations/sv.js +0 -1
- package/build/translations/th.js +0 -1
- package/build/translations/ti.js +0 -1
- package/build/translations/tk.js +0 -1
- package/build/translations/tr.js +0 -1
- package/build/translations/tt.js +0 -1
- package/build/translations/ug.js +0 -1
- package/build/translations/uk.js +0 -1
- package/build/translations/ur.js +0 -1
- package/build/translations/uz.js +0 -1
- package/build/translations/vi.js +0 -1
- package/build/translations/zh-cn.js +0 -1
- package/build/translations/zh.js +0 -1
- package/lang/contexts.json +0 -16
- package/lang/translations/af.po +0 -68
- package/lang/translations/ar.po +0 -68
- package/lang/translations/ast.po +0 -68
- package/lang/translations/az.po +0 -68
- package/lang/translations/be.po +0 -68
- package/lang/translations/bg.po +0 -68
- package/lang/translations/bn.po +0 -70
- package/lang/translations/bs.po +0 -68
- package/lang/translations/ca.po +0 -68
- package/lang/translations/cs.po +0 -68
- package/lang/translations/da.po +0 -68
- package/lang/translations/de-ch.po +0 -68
- package/lang/translations/de.po +0 -68
- package/lang/translations/el.po +0 -68
- package/lang/translations/en-au.po +0 -68
- package/lang/translations/en-gb.po +0 -68
- package/lang/translations/en.po +0 -68
- package/lang/translations/eo.po +0 -68
- package/lang/translations/es-co.po +0 -68
- package/lang/translations/es.po +0 -68
- package/lang/translations/et.po +0 -68
- package/lang/translations/eu.po +0 -68
- package/lang/translations/fa.po +0 -68
- package/lang/translations/fi.po +0 -68
- package/lang/translations/fr.po +0 -68
- package/lang/translations/gl.po +0 -68
- package/lang/translations/gu.po +0 -68
- package/lang/translations/he.po +0 -68
- package/lang/translations/hi.po +0 -68
- package/lang/translations/hr.po +0 -68
- package/lang/translations/hu.po +0 -68
- package/lang/translations/hy.po +0 -68
- package/lang/translations/id.po +0 -68
- package/lang/translations/it.po +0 -68
- package/lang/translations/ja.po +0 -68
- package/lang/translations/jv.po +0 -68
- package/lang/translations/kk.po +0 -68
- package/lang/translations/km.po +0 -68
- package/lang/translations/kn.po +0 -68
- package/lang/translations/ko.po +0 -68
- package/lang/translations/ku.po +0 -68
- package/lang/translations/lt.po +0 -68
- package/lang/translations/lv.po +0 -68
- package/lang/translations/ms.po +0 -68
- package/lang/translations/nb.po +0 -68
- package/lang/translations/ne.po +0 -68
- package/lang/translations/nl.po +0 -68
- package/lang/translations/no.po +0 -68
- package/lang/translations/oc.po +0 -68
- package/lang/translations/pl.po +0 -68
- package/lang/translations/pt-br.po +0 -68
- package/lang/translations/pt.po +0 -68
- package/lang/translations/ro.po +0 -68
- package/lang/translations/ru.po +0 -68
- package/lang/translations/si.po +0 -68
- package/lang/translations/sk.po +0 -68
- package/lang/translations/sl.po +0 -68
- package/lang/translations/sq.po +0 -68
- package/lang/translations/sr-latn.po +0 -68
- package/lang/translations/sr.po +0 -68
- package/lang/translations/sv.po +0 -68
- package/lang/translations/th.po +0 -68
- package/lang/translations/ti.po +0 -68
- package/lang/translations/tk.po +0 -68
- package/lang/translations/tr.po +0 -68
- package/lang/translations/tt.po +0 -68
- package/lang/translations/ug.po +0 -68
- package/lang/translations/uk.po +0 -68
- package/lang/translations/ur.po +0 -68
- package/lang/translations/uz.po +0 -68
- package/lang/translations/vi.po +0 -68
- package/lang/translations/zh-cn.po +0 -68
- package/lang/translations/zh.po +0 -68
- package/src/augmentation.js +0 -5
- package/src/autolink.js +0 -307
- package/src/index.js +0 -25
- package/src/link.js +0 -37
- package/src/linkcommand.js +0 -431
- package/src/linkconfig.js +0 -5
- package/src/linkediting.js +0 -402
- package/src/linkimage.js +0 -37
- package/src/linkimageediting.js +0 -264
- package/src/linkimageui.js +0 -102
- package/src/linkui.js +0 -1072
- package/src/ui/linkbuttonview.js +0 -54
- package/src/ui/linkformview.js +0 -302
- package/src/ui/linkpreviewbuttonview.js +0 -43
- package/src/ui/linkpropertiesview.js +0 -170
- package/src/ui/linkprovideritemsview.js +0 -207
- package/src/unlinkcommand.js +0 -66
- package/src/utils/automaticdecorators.js +0 -181
- package/src/utils/conflictingdecorators.js +0 -80
- package/src/utils/manualdecorator.js +0 -69
- package/src/utils.js +0 -157
- package/theme/link.css +0 -10
- package/theme/linkform.css +0 -24
- package/theme/linkimage.css +0 -16
- package/theme/linkproperties.css +0 -4
- package/theme/linkprovideritems.css +0 -18
- package/theme/linktoolbar.css +0 -12
- /package/{src → dist}/augmentation.d.ts +0 -0
- /package/{src → dist}/utils/conflictingdecorators.d.ts +0 -0
package/src/autolink.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link/autolink
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { Delete, TextWatcher, getLastTextLine, findAttributeRange } from 'ckeditor5/src/typing.js';
|
|
10
|
-
import { addLinkProtocolIfApplicable, linkHasProtocol } from './utils.js';
|
|
11
|
-
import { LinkEditing } from './linkediting.js';
|
|
12
|
-
const MIN_LINK_LENGTH_WITH_SPACE_AT_END = 4; // Ie: "t.co " (length 5).
|
|
13
|
-
// This was a tweak from https://gist.github.com/dperini/729294.
|
|
14
|
-
const URL_REG_EXP = new RegExp(
|
|
15
|
-
// Group 1: Line start or after a space.
|
|
16
|
-
'(^|\\s)' +
|
|
17
|
-
// Group 2: Detected URL (or e-mail).
|
|
18
|
-
'(' +
|
|
19
|
-
// Protocol identifier or short syntax "//"
|
|
20
|
-
// a. Full form http://user@foo.bar.baz:8080/foo/bar.html#baz?foo=bar
|
|
21
|
-
'(' +
|
|
22
|
-
'(?:(?:(?:https?|ftp):)?\\/\\/)' +
|
|
23
|
-
// BasicAuth using user:pass (optional)
|
|
24
|
-
'(?:\\S+(?::\\S*)?@)?' +
|
|
25
|
-
'(?:' +
|
|
26
|
-
// IP address dotted notation octets
|
|
27
|
-
// excludes loopback network 0.0.0.0
|
|
28
|
-
// excludes reserved space >= 224.0.0.0
|
|
29
|
-
// excludes network & broadcast addresses
|
|
30
|
-
// (first & last IP address of each class)
|
|
31
|
-
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
|
|
32
|
-
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
|
|
33
|
-
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
|
|
34
|
-
'|' +
|
|
35
|
-
'(' +
|
|
36
|
-
// Do not allow `www.foo` - see https://github.com/ckeditor/ckeditor5/issues/8050.
|
|
37
|
-
'((?!www\\.)|(www\\.))' +
|
|
38
|
-
// Host & domain names.
|
|
39
|
-
'(?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.)+' +
|
|
40
|
-
// TLD identifier name.
|
|
41
|
-
'(?:[a-z\\u00a1-\\uffff]{2,63})' +
|
|
42
|
-
')' +
|
|
43
|
-
'|' +
|
|
44
|
-
// Allow localhost as a valid hostname
|
|
45
|
-
'localhost' +
|
|
46
|
-
')' +
|
|
47
|
-
// port number (optional)
|
|
48
|
-
'(?::\\d{2,5})?' +
|
|
49
|
-
// resource path (optional)
|
|
50
|
-
'(?:[/?#]\\S*)?' +
|
|
51
|
-
')' +
|
|
52
|
-
'|' +
|
|
53
|
-
// b. Short form (either www.example.com or example@example.com)
|
|
54
|
-
'(' +
|
|
55
|
-
'(www.|(\\S+@))' +
|
|
56
|
-
// Host & domain names.
|
|
57
|
-
'((?![-_])(?:[-_a-z0-9\\u00a1-\\uffff]{1,63}\\.))+' +
|
|
58
|
-
// TLD identifier name.
|
|
59
|
-
'(?:[a-z\\u00a1-\\uffff]{2,63})' +
|
|
60
|
-
')' +
|
|
61
|
-
')$', 'i');
|
|
62
|
-
const URL_GROUP_IN_MATCH = 2;
|
|
63
|
-
/**
|
|
64
|
-
* The autolink plugin.
|
|
65
|
-
*/
|
|
66
|
-
export class AutoLink extends Plugin {
|
|
67
|
-
/**
|
|
68
|
-
* @inheritDoc
|
|
69
|
-
*/
|
|
70
|
-
static get requires() {
|
|
71
|
-
return [Delete, LinkEditing];
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @inheritDoc
|
|
75
|
-
*/
|
|
76
|
-
static get pluginName() {
|
|
77
|
-
return 'AutoLink';
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @inheritDoc
|
|
81
|
-
*/
|
|
82
|
-
static get isOfficialPlugin() {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* @inheritDoc
|
|
87
|
-
*/
|
|
88
|
-
init() {
|
|
89
|
-
const editor = this.editor;
|
|
90
|
-
const selection = editor.model.document.selection;
|
|
91
|
-
selection.on('change:range', () => {
|
|
92
|
-
// Disable plugin when selection is inside a code block.
|
|
93
|
-
this.isEnabled = !selection.anchor.parent.is('element', 'codeBlock');
|
|
94
|
-
});
|
|
95
|
-
this._enableTypingHandling();
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* @inheritDoc
|
|
99
|
-
*/
|
|
100
|
-
afterInit() {
|
|
101
|
-
this._enableEnterHandling();
|
|
102
|
-
this._enableShiftEnterHandling();
|
|
103
|
-
this._enablePasteLinking();
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* For given position, returns a range that includes the whole link that contains the position.
|
|
107
|
-
*
|
|
108
|
-
* If position is not inside a link, returns `null`.
|
|
109
|
-
*/
|
|
110
|
-
_expandLinkRange(model, position) {
|
|
111
|
-
if (position.textNode && position.textNode.hasAttribute('linkHref')) {
|
|
112
|
-
return findAttributeRange(position, 'linkHref', position.textNode.getAttribute('linkHref'), model);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Extends the document selection to includes all links that intersects with given `selectedRange`.
|
|
120
|
-
*/
|
|
121
|
-
_selectEntireLinks(writer, selectedRange) {
|
|
122
|
-
const editor = this.editor;
|
|
123
|
-
const model = editor.model;
|
|
124
|
-
const selection = model.document.selection;
|
|
125
|
-
const selStart = selection.getFirstPosition();
|
|
126
|
-
const selEnd = selection.getLastPosition();
|
|
127
|
-
let updatedSelection = selectedRange.getJoined(this._expandLinkRange(model, selStart) || selectedRange);
|
|
128
|
-
if (updatedSelection) {
|
|
129
|
-
updatedSelection = updatedSelection.getJoined(this._expandLinkRange(model, selEnd) || selectedRange);
|
|
130
|
-
}
|
|
131
|
-
if (updatedSelection && (updatedSelection.start.isBefore(selStart) || updatedSelection.end.isAfter(selEnd))) {
|
|
132
|
-
// Only update the selection if it changed.
|
|
133
|
-
writer.setSelection(updatedSelection);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Enables autolinking on pasting a URL when some content is selected.
|
|
138
|
-
*/
|
|
139
|
-
_enablePasteLinking() {
|
|
140
|
-
const editor = this.editor;
|
|
141
|
-
const model = editor.model;
|
|
142
|
-
const selection = model.document.selection;
|
|
143
|
-
const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
|
|
144
|
-
const linkCommand = editor.commands.get('link');
|
|
145
|
-
clipboardPipeline.on('inputTransformation', (evt, data) => {
|
|
146
|
-
if (!this.isEnabled || !linkCommand.isEnabled || selection.isCollapsed || data.method !== 'paste') {
|
|
147
|
-
// Abort if we are disabled or the selection is collapsed.
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (selection.rangeCount > 1) {
|
|
151
|
-
// Abort if there are multiple selection ranges.
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const selectedRange = selection.getFirstRange();
|
|
155
|
-
const newLink = data.dataTransfer.getData('text/plain');
|
|
156
|
-
if (!newLink) {
|
|
157
|
-
// Abort if there is no plain text on the clipboard.
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const matches = newLink.match(URL_REG_EXP);
|
|
161
|
-
// If the text in the clipboard has a URL, and that URL is the whole clipboard.
|
|
162
|
-
if (matches && matches[2] === newLink) {
|
|
163
|
-
model.change(writer => {
|
|
164
|
-
this._selectEntireLinks(writer, selectedRange);
|
|
165
|
-
linkCommand.execute(newLink);
|
|
166
|
-
});
|
|
167
|
-
evt.stop();
|
|
168
|
-
}
|
|
169
|
-
}, { priority: 'high' });
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Enables autolinking on typing.
|
|
173
|
-
*/
|
|
174
|
-
_enableTypingHandling() {
|
|
175
|
-
const editor = this.editor;
|
|
176
|
-
const watcher = new TextWatcher(editor.model, text => {
|
|
177
|
-
let mappedText = text;
|
|
178
|
-
// 1. Detect <kbd>Space</kbd> after a text with a potential link.
|
|
179
|
-
if (!isSingleSpaceAtTheEnd(mappedText)) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
// 2. Remove the last space character.
|
|
183
|
-
mappedText = mappedText.slice(0, -1);
|
|
184
|
-
// 3. Remove punctuation at the end of the URL if it exists.
|
|
185
|
-
if ('!.:,;?'.includes(mappedText[mappedText.length - 1])) {
|
|
186
|
-
mappedText = mappedText.slice(0, -1);
|
|
187
|
-
}
|
|
188
|
-
// 4. Check text before last typed <kbd>Space</kbd> or punctuation.
|
|
189
|
-
const url = getUrlAtTextEnd(mappedText);
|
|
190
|
-
if (url) {
|
|
191
|
-
return {
|
|
192
|
-
url,
|
|
193
|
-
removedTrailingCharacters: text.length - mappedText.length
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
watcher.on('matched:data', (evt, data) => {
|
|
198
|
-
const { batch, range, url, removedTrailingCharacters } = data;
|
|
199
|
-
if (!batch.isTyping) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const linkEnd = range.end.getShiftedBy(-removedTrailingCharacters); // Executed after a space character or punctuation.
|
|
203
|
-
const linkStart = linkEnd.getShiftedBy(-url.length);
|
|
204
|
-
const linkRange = editor.model.createRange(linkStart, linkEnd);
|
|
205
|
-
this._applyAutoLink(url, linkRange);
|
|
206
|
-
});
|
|
207
|
-
watcher.bind('isEnabled').to(this);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Enables autolinking on the <kbd>Enter</kbd> key.
|
|
211
|
-
*/
|
|
212
|
-
_enableEnterHandling() {
|
|
213
|
-
const editor = this.editor;
|
|
214
|
-
const model = editor.model;
|
|
215
|
-
const enterCommand = editor.commands.get('enter');
|
|
216
|
-
if (!enterCommand) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
enterCommand.on('execute', () => {
|
|
220
|
-
const position = model.document.selection.getFirstPosition();
|
|
221
|
-
let rangeToCheck;
|
|
222
|
-
// Previous sibling might not be an element if enter was blocked due to be triggered in a limit element.
|
|
223
|
-
if (position.parent.previousSibling?.is('element')) {
|
|
224
|
-
rangeToCheck = model.createRangeIn(position.parent.previousSibling);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
rangeToCheck = model.createRange(model.createPositionAt(position.parent, 0), position);
|
|
228
|
-
}
|
|
229
|
-
this._checkAndApplyAutoLinkOnRange(rangeToCheck);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Enables autolinking on the <kbd>Shift</kbd>+<kbd>Enter</kbd> keyboard shortcut.
|
|
234
|
-
*/
|
|
235
|
-
_enableShiftEnterHandling() {
|
|
236
|
-
const editor = this.editor;
|
|
237
|
-
const model = editor.model;
|
|
238
|
-
const shiftEnterCommand = editor.commands.get('shiftEnter');
|
|
239
|
-
if (!shiftEnterCommand) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
shiftEnterCommand.on('execute', () => {
|
|
243
|
-
const position = model.document.selection.getFirstPosition();
|
|
244
|
-
const rangeToCheck = model.createRange(model.createPositionAt(position.parent, 0), position.getShiftedBy(-1));
|
|
245
|
-
this._checkAndApplyAutoLinkOnRange(rangeToCheck);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Checks if the passed range contains a linkable text.
|
|
250
|
-
*/
|
|
251
|
-
_checkAndApplyAutoLinkOnRange(rangeToCheck) {
|
|
252
|
-
const model = this.editor.model;
|
|
253
|
-
const { text, range } = getLastTextLine(rangeToCheck, model);
|
|
254
|
-
const url = getUrlAtTextEnd(text);
|
|
255
|
-
if (url) {
|
|
256
|
-
const linkRange = model.createRange(range.end.getShiftedBy(-url.length), range.end);
|
|
257
|
-
this._applyAutoLink(url, linkRange);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Applies a link on a given range if the link should be applied.
|
|
262
|
-
*
|
|
263
|
-
* @param url The URL to link.
|
|
264
|
-
* @param range The text range to apply the link attribute to.
|
|
265
|
-
*/
|
|
266
|
-
_applyAutoLink(url, range) {
|
|
267
|
-
const model = this.editor.model;
|
|
268
|
-
const defaultProtocol = this.editor.config.get('link.defaultProtocol');
|
|
269
|
-
const fullUrl = addLinkProtocolIfApplicable(url, defaultProtocol);
|
|
270
|
-
if (!this.isEnabled || !isLinkAllowedOnRange(range, model) || !linkHasProtocol(fullUrl) || linkIsAlreadySet(range)) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
this._persistAutoLink(fullUrl, range);
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Enqueues autolink changes in the model.
|
|
277
|
-
*
|
|
278
|
-
* @param url The URL to link.
|
|
279
|
-
* @param range The text range to apply the link attribute to.
|
|
280
|
-
*/
|
|
281
|
-
_persistAutoLink(url, range) {
|
|
282
|
-
const model = this.editor.model;
|
|
283
|
-
const deletePlugin = this.editor.plugins.get('Delete');
|
|
284
|
-
// Enqueue change to make undo step.
|
|
285
|
-
model.enqueueChange(writer => {
|
|
286
|
-
writer.setAttribute('linkHref', url, range);
|
|
287
|
-
model.enqueueChange(() => {
|
|
288
|
-
deletePlugin.requestUndoOnBackspace();
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
// Check if text should be evaluated by the plugin in order to reduce number of RegExp checks on whole text.
|
|
294
|
-
function isSingleSpaceAtTheEnd(text) {
|
|
295
|
-
return text.length > MIN_LINK_LENGTH_WITH_SPACE_AT_END && text[text.length - 1] === ' ' && text[text.length - 2] !== ' ';
|
|
296
|
-
}
|
|
297
|
-
function getUrlAtTextEnd(text) {
|
|
298
|
-
const match = URL_REG_EXP.exec(text);
|
|
299
|
-
return match ? match[URL_GROUP_IN_MATCH] : null;
|
|
300
|
-
}
|
|
301
|
-
function isLinkAllowedOnRange(range, model) {
|
|
302
|
-
return model.schema.checkAttributeInSelection(model.createSelection(range), 'linkHref');
|
|
303
|
-
}
|
|
304
|
-
function linkIsAlreadySet(range) {
|
|
305
|
-
const item = range.start.nodeAfter;
|
|
306
|
-
return !!item && item.hasAttribute('linkHref');
|
|
307
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link
|
|
7
|
-
*/
|
|
8
|
-
export { Link } from './link.js';
|
|
9
|
-
export { LinkEditing } from './linkediting.js';
|
|
10
|
-
export { LinkUI } from './linkui.js';
|
|
11
|
-
export { LinkImage } from './linkimage.js';
|
|
12
|
-
export { LinkImageEditing } from './linkimageediting.js';
|
|
13
|
-
export { LinkImageUI } from './linkimageui.js';
|
|
14
|
-
export { AutoLink } from './autolink.js';
|
|
15
|
-
export { LinkFormView } from './ui/linkformview.js';
|
|
16
|
-
export { LinkCommand } from './linkcommand.js';
|
|
17
|
-
export { UnlinkCommand } from './unlinkcommand.js';
|
|
18
|
-
export { LinkButtonView as _LinkButtonView } from './ui/linkbuttonview.js';
|
|
19
|
-
export { LinkPreviewButtonView as _LinkPreviewButtonView } from './ui/linkpreviewbuttonview.js';
|
|
20
|
-
export { LinkPropertiesView } from './ui/linkpropertiesview.js';
|
|
21
|
-
export { LinkProviderItemsView } from './ui/linkprovideritemsview.js';
|
|
22
|
-
export { addLinkProtocolIfApplicable, ensureSafeUrl, ensureSafeUrl as _ensureSafeLinkUrl, isLinkableElement, isLinkElement, LINK_KEYSTROKE as _LINK_KEYSTROKE, createLinkElement as _createLinkElement, getLocalizedDecorators as _getLocalizedLinkDecorators, normalizeDecorators as _normalizeLinkDecorators, isEmail as _isEmailLink, linkHasProtocol as _hasLinkProtocol, openLink as _openLink, extractTextFromLinkRange as _extractTextFromLinkRange } from './utils.js';
|
|
23
|
-
export { AutomaticLinkDecorators } from './utils/automaticdecorators.js';
|
|
24
|
-
export { LinkManualDecorator } from './utils/manualdecorator.js';
|
|
25
|
-
import './augmentation.js';
|
package/src/link.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module link/link
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { LinkEditing } from './linkediting.js';
|
|
10
|
-
import { LinkUI } from './linkui.js';
|
|
11
|
-
import { AutoLink } from './autolink.js';
|
|
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 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
|
-
/**
|
|
32
|
-
* @inheritDoc
|
|
33
|
-
*/
|
|
34
|
-
static get isOfficialPlugin() {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|