jodit 4.19.4 → 4.19.6
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 +16 -0
- package/es2015/jodit.css +1 -1
- package/es2015/jodit.fat.min.js +20 -7
- package/es2015/jodit.js +393 -56
- package/es2015/jodit.min.js +17 -4
- package/es2015/plugins/debug/debug.css +1 -1
- package/es2015/plugins/debug/debug.js +1 -1
- package/es2015/plugins/debug/debug.min.js +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2018/jodit.fat.min.js +17 -4
- package/es2018/jodit.min.js +17 -4
- package/es2018/plugins/debug/debug.min.js +1 -1
- package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2021/jodit.css +1 -1
- package/es2021/jodit.fat.min.js +18 -5
- package/es2021/jodit.js +390 -56
- package/es2021/jodit.min.js +18 -5
- package/es2021/plugins/debug/debug.css +1 -1
- package/es2021/plugins/debug/debug.js +1 -1
- package/es2021/plugins/debug/debug.min.js +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es2021.en/jodit.css +1 -1
- package/es2021.en/jodit.fat.min.js +20 -7
- package/es2021.en/jodit.js +390 -56
- package/es2021.en/jodit.min.js +20 -7
- package/es2021.en/plugins/debug/debug.css +1 -1
- package/es2021.en/plugins/debug/debug.js +1 -1
- package/es2021.en/plugins/debug/debug.min.js +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es5/jodit.css +2 -2
- package/es5/jodit.fat.min.js +2 -2
- package/es5/jodit.js +410 -62
- package/es5/jodit.min.css +2 -2
- package/es5/jodit.min.js +2 -2
- package/es5/plugins/debug/debug.css +1 -1
- package/es5/plugins/debug/debug.js +1 -1
- package/es5/plugins/debug/debug.min.js +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
- package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
- package/es5/polyfills.fat.min.js +1 -1
- package/es5/polyfills.js +1 -1
- package/es5/polyfills.min.js +1 -1
- package/esm/config.d.ts +31 -0
- package/esm/core/constants.js +1 -1
- package/esm/core/selection/helpers/move-node-inside-start.js +5 -2
- package/esm/plugins/file/file.js +39 -3
- package/esm/plugins/link/config.d.ts +31 -0
- package/esm/plugins/link/config.js +3 -0
- package/esm/plugins/link/link.d.ts +27 -0
- package/esm/plugins/link/link.js +144 -2
- package/esm/plugins/link/tlds.d.ts +18 -0
- package/esm/plugins/link/tlds.js +33 -0
- package/esm/plugins/link/typed-link.d.ts +23 -0
- package/esm/plugins/link/typed-link.js +92 -0
- package/package.json +1 -1
- package/types/config.d.ts +31 -0
- package/types/plugins/link/config.d.ts +31 -0
- package/types/plugins/link/link.d.ts +27 -0
- package/types/plugins/link/tlds.d.ts +18 -0
- package/types/plugins/link/typed-link.d.ts +23 -0
package/es5/polyfills.fat.min.js
CHANGED
package/es5/polyfills.js
CHANGED
package/es5/polyfills.min.js
CHANGED
package/esm/config.d.ts
CHANGED
|
@@ -1564,6 +1564,37 @@ interface Config {
|
|
|
1564
1564
|
* Wrap inserted link
|
|
1565
1565
|
*/
|
|
1566
1566
|
processPastedLink: boolean;
|
|
1567
|
+
/**
|
|
1568
|
+
* Link an address when the space, Enter or Tab after it is typed:
|
|
1569
|
+
* one with a scheme (`https://…`), one that starts with `www.` or a
|
|
1570
|
+
* bare domain such as `example.com` or `education.govt.nz`, which
|
|
1571
|
+
* get `https://`, or an email address, which gets `mailto:`.
|
|
1572
|
+
* Punctuation that ends a sentence stays outside the link, and
|
|
1573
|
+
* Backspace or Undo straight after takes the link off. Not inside a
|
|
1574
|
+
* link, `<pre>` or `<code>`. Default: false.
|
|
1575
|
+
*/
|
|
1576
|
+
processTypedLink: boolean;
|
|
1577
|
+
/**
|
|
1578
|
+
* With `processTypedLink`, more endings a bare domain links with,
|
|
1579
|
+
* in lower case and without the dot, as `['gle', 'school']` for
|
|
1580
|
+
* `forms.gle` and `example.school`. Built in are every two-letter
|
|
1581
|
+
* ending, such as `nz` and `io`, and the generic ones of at least 1
|
|
1582
|
+
* in 1,000 of the most visited sites, such as `com`, `org`, `edu`
|
|
1583
|
+
* and `app`. IANA lists them all:
|
|
1584
|
+
* https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
|
1585
|
+
* Default: `[]`.
|
|
1586
|
+
*/
|
|
1587
|
+
typedLinkTlds: string[];
|
|
1588
|
+
/**
|
|
1589
|
+
* With `processTypedLink`, the endings a bare domain doesn't link
|
|
1590
|
+
* with, as they're more often a file's: `photos.zip`, `README.md`,
|
|
1591
|
+
* even when `typedLinkTlds` has them. In lower case, without the
|
|
1592
|
+
* dot. A plain list replaces this one entry by entry from the
|
|
1593
|
+
* start, so use `Jodit.atom` to replace the whole list.
|
|
1594
|
+
* `Jodit.atom([])` lets every ending link.
|
|
1595
|
+
* Default: `['zip', 'mov', 'md', 'py', 'sh', 'pub']`.
|
|
1596
|
+
*/
|
|
1597
|
+
typedLinkFileEndings: string[];
|
|
1567
1598
|
/**
|
|
1568
1599
|
* When opening the link dialog for a new link with an empty URL field,
|
|
1569
1600
|
* pre-fill it from the selected text if that text looks like a URL or
|
package/esm/core/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
4
|
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
5
|
*/
|
|
6
|
-
export const APP_VERSION = "4.19.
|
|
6
|
+
export const APP_VERSION = "4.19.6";
|
|
7
7
|
// prettier-ignore
|
|
8
8
|
export const ES = "es2020";
|
|
9
9
|
export const IS_ES_MODERN = true;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
4
|
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
5
|
*/
|
|
6
|
-
import { INSEPARABLE_TAGS } from "../../constants.js";
|
|
6
|
+
import { INSEPARABLE_TAGS, NBSP_SPACE } from "../../constants.js";
|
|
7
7
|
import { Dom } from "../../dom/dom.js";
|
|
8
8
|
/**
|
|
9
9
|
* Moves the fake node inside the adjacent element if it lies next to it but not inside.
|
|
@@ -11,7 +11,10 @@ import { Dom } from "../../dom/dom.js";
|
|
|
11
11
|
* @private
|
|
12
12
|
*/
|
|
13
13
|
export function moveNodeInsideStart(j, node, start) {
|
|
14
|
-
|
|
14
|
+
// A text node of non-breaking spaces trims to nothing, but it's text the
|
|
15
|
+
// node mustn't move past
|
|
16
|
+
const isContent = (n) => { var _a; return !Dom.isEmptyTextNode(n) || Boolean((_a = n.nodeValue) === null || _a === void 0 ? void 0 : _a.includes(NBSP_SPACE)); };
|
|
17
|
+
let sibling = Dom.findSibling(node, start, isContent), anotherSibling = Dom.findSibling(node, !start, isContent);
|
|
15
18
|
while (Dom.isElement(sibling) &&
|
|
16
19
|
!Dom.isTag(sibling, INSEPARABLE_TAGS) &&
|
|
17
20
|
Dom.isContentEditable(sibling, j.editor) &&
|
package/esm/plugins/file/file.js
CHANGED
|
@@ -8,12 +8,35 @@ import { pluginSystem } from "../../core/global.js";
|
|
|
8
8
|
import { attr } from "../../core/helpers/utils/attr.js";
|
|
9
9
|
import { Config } from "../../config.js";
|
|
10
10
|
import { FileSelectorWidget } from "../../modules/widget/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Selected text becomes the link's text, as the Link button does, instead
|
|
13
|
+
* of being replaced by the file's name. Returns false with nothing selected
|
|
14
|
+
*/
|
|
15
|
+
function wrapSelectionInLink(editor, href, title = '') {
|
|
16
|
+
if (editor.s.isCollapsed()) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const links = editor.s.wrapInTag('a');
|
|
20
|
+
if (!links.length) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
links.forEach(link => {
|
|
24
|
+
attr(link, 'href', href);
|
|
25
|
+
if (title) {
|
|
26
|
+
attr(link, 'title', title);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
editor.s.setCursorAfter(links[links.length - 1]);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
11
32
|
function insertLinks(data) {
|
|
12
33
|
var _a;
|
|
13
34
|
(_a = data.files) === null || _a === void 0 ? void 0 : _a.forEach(file => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
35
|
+
const href = data.baseurl + file;
|
|
36
|
+
if (wrapSelectionInLink(this, href)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const link = this.createInside.element('a', { href });
|
|
17
40
|
link.textContent = this.o.uploader.getDisplayName.call(this.uploader, data.baseurl, file);
|
|
18
41
|
this.s.insertNode(link);
|
|
19
42
|
});
|
|
@@ -23,7 +46,19 @@ Config.prototype.file = {
|
|
|
23
46
|
};
|
|
24
47
|
Config.prototype.controls.file = {
|
|
25
48
|
popup: (editor, current, close) => {
|
|
49
|
+
// The popup's first field takes the focus, so the selection the
|
|
50
|
+
// popup was opened for is kept and put back before the link goes in
|
|
51
|
+
const selected = editor.s.isCollapsed() ? null : editor.s.range;
|
|
52
|
+
const restoreSelection = () => {
|
|
53
|
+
if (selected) {
|
|
54
|
+
editor.s.selectRange(selected);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
26
57
|
const insert = (url, title = '') => {
|
|
58
|
+
restoreSelection();
|
|
59
|
+
if (wrapSelectionInLink(editor, url, title)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
27
62
|
editor.s.insertNode(editor.createInside.fromHTML(`<a href="${url}" title="${title}">${title || url}</a>`));
|
|
28
63
|
};
|
|
29
64
|
let sourceAnchor = null;
|
|
@@ -42,6 +77,7 @@ Config.prototype.controls.file = {
|
|
|
42
77
|
},
|
|
43
78
|
upload: (data) => {
|
|
44
79
|
var _a, _b;
|
|
80
|
+
restoreSelection();
|
|
45
81
|
((_b = (_a = editor.o.file) === null || _a === void 0 ? void 0 : _a.defaultHandlerSuccess) !== null && _b !== void 0 ? _b : insertLinks).call(editor, data);
|
|
46
82
|
},
|
|
47
83
|
url: (url, text) => {
|
|
@@ -27,6 +27,37 @@ declare module 'jodit/config' {
|
|
|
27
27
|
* Wrap inserted link
|
|
28
28
|
*/
|
|
29
29
|
processPastedLink: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Link an address when the space, Enter or Tab after it is typed:
|
|
32
|
+
* one with a scheme (`https://…`), one that starts with `www.` or a
|
|
33
|
+
* bare domain such as `example.com` or `education.govt.nz`, which
|
|
34
|
+
* get `https://`, or an email address, which gets `mailto:`.
|
|
35
|
+
* Punctuation that ends a sentence stays outside the link, and
|
|
36
|
+
* Backspace or Undo straight after takes the link off. Not inside a
|
|
37
|
+
* link, `<pre>` or `<code>`. Default: false.
|
|
38
|
+
*/
|
|
39
|
+
processTypedLink: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* With `processTypedLink`, more endings a bare domain links with,
|
|
42
|
+
* in lower case and without the dot, as `['gle', 'school']` for
|
|
43
|
+
* `forms.gle` and `example.school`. Built in are every two-letter
|
|
44
|
+
* ending, such as `nz` and `io`, and the generic ones of at least 1
|
|
45
|
+
* in 1,000 of the most visited sites, such as `com`, `org`, `edu`
|
|
46
|
+
* and `app`. IANA lists them all:
|
|
47
|
+
* https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
|
48
|
+
* Default: `[]`.
|
|
49
|
+
*/
|
|
50
|
+
typedLinkTlds: string[];
|
|
51
|
+
/**
|
|
52
|
+
* With `processTypedLink`, the endings a bare domain doesn't link
|
|
53
|
+
* with, as they're more often a file's: `photos.zip`, `README.md`,
|
|
54
|
+
* even when `typedLinkTlds` has them. In lower case, without the
|
|
55
|
+
* dot. A plain list replaces this one entry by entry from the
|
|
56
|
+
* start, so use `Jodit.atom` to replace the whole list.
|
|
57
|
+
* `Jodit.atom([])` lets every ending link.
|
|
58
|
+
* Default: `['zip', 'mov', 'md', 'py', 'sh', 'pub']`.
|
|
59
|
+
*/
|
|
60
|
+
typedLinkFileEndings: string[];
|
|
30
61
|
/**
|
|
31
62
|
* When opening the link dialog for a new link with an empty URL field,
|
|
32
63
|
* pre-fill it from the selected text if that text looks like a URL or
|
|
@@ -14,6 +14,9 @@ Config.prototype.link = {
|
|
|
14
14
|
followOnDblClick: false,
|
|
15
15
|
processVideoLink: true,
|
|
16
16
|
processPastedLink: true,
|
|
17
|
+
processTypedLink: false,
|
|
18
|
+
typedLinkTlds: [],
|
|
19
|
+
typedLinkFileEndings: ['zip', 'mov', 'md', 'py', 'sh', 'pub'],
|
|
17
20
|
deriveUrlFromText: false,
|
|
18
21
|
noFollowCheckbox: true,
|
|
19
22
|
openInNewTabCheckbox: true,
|
|
@@ -24,5 +24,32 @@ export declare class link extends Plugin {
|
|
|
24
24
|
private __generateForm;
|
|
25
25
|
/** @override */
|
|
26
26
|
protected beforeDestruct(jodit: IJodit): void;
|
|
27
|
+
private __onTypedSpace;
|
|
28
|
+
/**
|
|
29
|
+
* Where the caret was when Enter was pressed. Enter splits the line in a
|
|
30
|
+
* history transaction, so the link waits until it's over
|
|
31
|
+
*/
|
|
32
|
+
private __enteredAt;
|
|
33
|
+
private __linkAfterEnter;
|
|
34
|
+
private __onBeforeEnter;
|
|
35
|
+
private __onAfterEnter;
|
|
36
|
+
/**
|
|
37
|
+
* The link just made, which Backspace straight after takes off again, as
|
|
38
|
+
* in CKEditor 5. Any other key but a modifier, a click or a command
|
|
39
|
+
* forgets it
|
|
40
|
+
*/
|
|
41
|
+
private __justLinked;
|
|
42
|
+
private __forgetLink;
|
|
43
|
+
private __onKeyDown;
|
|
44
|
+
/**
|
|
45
|
+
* Links the address that ends at `end` in a text node, as a step of its
|
|
46
|
+
* own in the history, so Undo straight after takes the link off and
|
|
47
|
+
* leaves the text
|
|
48
|
+
*/
|
|
49
|
+
private __linkTyped;
|
|
50
|
+
/**
|
|
51
|
+
* Reports what's changed and makes it a history step of its own
|
|
52
|
+
*/
|
|
53
|
+
private __recordStep;
|
|
27
54
|
private __onClickReadOnlyLink;
|
|
28
55
|
}
|
package/esm/plugins/link/link.js
CHANGED
|
@@ -13,12 +13,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
13
13
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
14
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
15
|
};
|
|
16
|
+
import { KEY_BACKSPACE, KEY_TAB } from "../../core/constants.js";
|
|
16
17
|
import { autobind } from "../../core/decorators/index.js";
|
|
17
18
|
import { Dom } from "../../core/dom/index.js";
|
|
18
19
|
import { pluginSystem } from "../../core/global.js";
|
|
19
20
|
import { attr, call, convertMediaUrlToVideoEmbed, isString, isURL, prepareEmbedCode, refs, stripTags } from "../../core/helpers/index.js";
|
|
20
21
|
import { Plugin } from "../../core/plugin/index.js";
|
|
21
22
|
import "./config.js";
|
|
23
|
+
import { EMAIL, findTypedLink } from "./typed-link.js";
|
|
22
24
|
/**
|
|
23
25
|
* Process link. Insert, dblclick or remove format
|
|
24
26
|
*/
|
|
@@ -32,6 +34,18 @@ export class link extends Plugin {
|
|
|
32
34
|
group: 'insert'
|
|
33
35
|
}
|
|
34
36
|
];
|
|
37
|
+
/**
|
|
38
|
+
* Where the caret was when Enter was pressed. Enter splits the line in a
|
|
39
|
+
* history transaction, so the link waits until it's over
|
|
40
|
+
*/
|
|
41
|
+
this.__enteredAt = null;
|
|
42
|
+
this.__linkAfterEnter = () => { };
|
|
43
|
+
/**
|
|
44
|
+
* The link just made, which Backspace straight after takes off again, as
|
|
45
|
+
* in CKEditor 5. Any other key but a modifier, a click or a command
|
|
46
|
+
* forgets it
|
|
47
|
+
*/
|
|
48
|
+
this.__justLinked = null;
|
|
35
49
|
}
|
|
36
50
|
/** @override */
|
|
37
51
|
afterInit(jodit) {
|
|
@@ -42,6 +56,17 @@ export class link extends Plugin {
|
|
|
42
56
|
if (jodit.o.link.processPastedLink) {
|
|
43
57
|
jodit.e.on('processPaste.link', this.onProcessPasteLink);
|
|
44
58
|
}
|
|
59
|
+
if (jodit.o.link.processTypedLink) {
|
|
60
|
+
this.__linkAfterEnter = jodit.async.microDebounce(this.__linkTyped);
|
|
61
|
+
jodit.e
|
|
62
|
+
.on('input.link', this.__onTypedSpace)
|
|
63
|
+
.on('beforeEnter.link', this.__onBeforeEnter)
|
|
64
|
+
.on('afterEnter.link', this.__onAfterEnter)
|
|
65
|
+
.on('mousedown.link blur.link beforeCommand.link', this.__forgetLink)
|
|
66
|
+
// Without a namespace it runs ahead of table navigation,
|
|
67
|
+
// which moves the caret on Tab, and of the backspace plugin
|
|
68
|
+
.on('keydown', this.__onKeyDown, { top: true });
|
|
69
|
+
}
|
|
45
70
|
jodit.e.on('generateLinkForm.link', this.__generateForm);
|
|
46
71
|
jodit.registerCommand('openLinkDialog', {
|
|
47
72
|
exec: () => {
|
|
@@ -287,7 +312,104 @@ export class link extends Plugin {
|
|
|
287
312
|
.off('generateLinkForm.link', this.__generateForm)
|
|
288
313
|
.off('dblclick.link', this.__onDblClickOnLink)
|
|
289
314
|
.off(jodit.editor, 'click.link', this.__onClickReadOnlyLink)
|
|
290
|
-
.off('processPaste.link', this.onProcessPasteLink)
|
|
315
|
+
.off('processPaste.link', this.onProcessPasteLink)
|
|
316
|
+
.off('input.link', this.__onTypedSpace)
|
|
317
|
+
.off('beforeEnter.link', this.__onBeforeEnter)
|
|
318
|
+
.off('afterEnter.link', this.__onAfterEnter)
|
|
319
|
+
.off('mousedown.link blur.link beforeCommand.link', this.__forgetLink)
|
|
320
|
+
.off('keydown', this.__onKeyDown);
|
|
321
|
+
}
|
|
322
|
+
__onTypedSpace(event) {
|
|
323
|
+
if (event.inputType !== 'insertText' ||
|
|
324
|
+
!event.data ||
|
|
325
|
+
/\S/.test(event.data)) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const { range } = this.j.s;
|
|
329
|
+
if (range.collapsed) {
|
|
330
|
+
this.__linkTyped(range.startContainer, range.startOffset - event.data.length);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
__onBeforeEnter() {
|
|
334
|
+
const { range } = this.j.s;
|
|
335
|
+
this.__enteredAt = range.collapsed
|
|
336
|
+
? [range.startContainer, range.startOffset]
|
|
337
|
+
: null;
|
|
338
|
+
}
|
|
339
|
+
__onAfterEnter() {
|
|
340
|
+
if (this.__enteredAt) {
|
|
341
|
+
this.__linkAfterEnter(...this.__enteredAt);
|
|
342
|
+
this.__enteredAt = null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
__forgetLink() {
|
|
346
|
+
this.__justLinked = null;
|
|
347
|
+
}
|
|
348
|
+
__onKeyDown(event) {
|
|
349
|
+
const { jodit } = this;
|
|
350
|
+
if (jodit.o.readonly) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const link = this.__justLinked;
|
|
354
|
+
const modified = event.ctrlKey || event.metaKey || event.altKey;
|
|
355
|
+
if (!MODIFIER_KEYS.has(event.key)) {
|
|
356
|
+
this.__justLinked = null;
|
|
357
|
+
}
|
|
358
|
+
if (event.key === KEY_BACKSPACE && !modified && (link === null || link === void 0 ? void 0 : link.isConnected)) {
|
|
359
|
+
this.__recordStep();
|
|
360
|
+
jodit.s.save();
|
|
361
|
+
Dom.unwrap(link);
|
|
362
|
+
jodit.s.restore();
|
|
363
|
+
this.__recordStep();
|
|
364
|
+
// Or the backspace plugin takes a character too
|
|
365
|
+
jodit.e.stopPropagation('keydown');
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
const { range } = jodit.s;
|
|
369
|
+
if (event.key === KEY_TAB && !modified && range.collapsed) {
|
|
370
|
+
this.__linkTyped(range.startContainer, range.startOffset);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Links the address that ends at `end` in a text node, as a step of its
|
|
375
|
+
* own in the history, so Undo straight after takes the link off and
|
|
376
|
+
* leaves the text
|
|
377
|
+
*/
|
|
378
|
+
__linkTyped(node, end) {
|
|
379
|
+
const { jodit } = this;
|
|
380
|
+
if (!Dom.isText(node) ||
|
|
381
|
+
!node.isConnected ||
|
|
382
|
+
end < 0 ||
|
|
383
|
+
end > node.length ||
|
|
384
|
+
Dom.closest(node, NO_TYPED_LINKS, jodit.editor)) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const found = findTypedLink(node.data, end, jodit.o.link.typedLinkTlds, jodit.o.link.typedLinkFileEndings);
|
|
388
|
+
if (!found) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const [start, stop, href] = found;
|
|
392
|
+
this.__recordStep();
|
|
393
|
+
// The text round the caret splits, and WebKit doesn't keep the caret
|
|
394
|
+
// where it was
|
|
395
|
+
jodit.s.save();
|
|
396
|
+
const range = jodit.ed.createRange();
|
|
397
|
+
range.setStart(node, start);
|
|
398
|
+
range.setEnd(node, stop);
|
|
399
|
+
const a = jodit.createInside.element('a');
|
|
400
|
+
attr(a, 'href', href);
|
|
401
|
+
range.surroundContents(a);
|
|
402
|
+
jodit.s.restore();
|
|
403
|
+
jodit.e.fire('applyLink', jodit, a, null);
|
|
404
|
+
this.__recordStep();
|
|
405
|
+
this.__justLinked = a;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Reports what's changed and makes it a history step of its own
|
|
409
|
+
*/
|
|
410
|
+
__recordStep() {
|
|
411
|
+
this.j.setEditorValue();
|
|
412
|
+
this.j.e.fire('internalChange');
|
|
291
413
|
}
|
|
292
414
|
__onClickReadOnlyLink(e) {
|
|
293
415
|
const { jodit } = this;
|
|
@@ -307,9 +429,29 @@ __decorate([
|
|
|
307
429
|
__decorate([
|
|
308
430
|
autobind
|
|
309
431
|
], link.prototype, "__generateForm", null);
|
|
432
|
+
__decorate([
|
|
433
|
+
autobind
|
|
434
|
+
], link.prototype, "__onTypedSpace", null);
|
|
435
|
+
__decorate([
|
|
436
|
+
autobind
|
|
437
|
+
], link.prototype, "__onBeforeEnter", null);
|
|
438
|
+
__decorate([
|
|
439
|
+
autobind
|
|
440
|
+
], link.prototype, "__onAfterEnter", null);
|
|
441
|
+
__decorate([
|
|
442
|
+
autobind
|
|
443
|
+
], link.prototype, "__forgetLink", null);
|
|
444
|
+
__decorate([
|
|
445
|
+
autobind
|
|
446
|
+
], link.prototype, "__onKeyDown", null);
|
|
447
|
+
__decorate([
|
|
448
|
+
autobind
|
|
449
|
+
], link.prototype, "__linkTyped", null);
|
|
310
450
|
__decorate([
|
|
311
451
|
autobind
|
|
312
452
|
], link.prototype, "__onClickReadOnlyLink", null);
|
|
453
|
+
const NO_TYPED_LINKS = new Set(['a', 'pre', 'code']);
|
|
454
|
+
const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta', 'CapsLock']);
|
|
313
455
|
pluginSystem.add('link', link);
|
|
314
456
|
/**
|
|
315
457
|
* Guess a usable `href` from the selected text for the link dialog.
|
|
@@ -326,7 +468,7 @@ function guessUrlFromText(text) {
|
|
|
326
468
|
return value;
|
|
327
469
|
}
|
|
328
470
|
// email address -> mailto:
|
|
329
|
-
if (
|
|
471
|
+
if (EMAIL.test(value)) {
|
|
330
472
|
return `mailto:${value}`;
|
|
331
473
|
}
|
|
332
474
|
// bare domain like example.com or www.example.com/path -> https://
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Jodit Editor (https://xdsoft.net/jodit/)
|
|
3
|
+
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
|
+
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @module plugins/link
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The endings a bare domain links with, besides those `link.typedLinkTlds`
|
|
11
|
+
* adds: the generic ones of at least 1 in 1,000 of the sites in Tranco's top
|
|
12
|
+
* million (list GQ38K, https://tranco-list.eu/list/GQ38K), then every
|
|
13
|
+
* two-letter one in IANA's list (version 2026102900,
|
|
14
|
+
* https://data.iana.org/TLD/tlds-alpha-by-domain.txt). Together they're the
|
|
15
|
+
* endings of 96% of those sites
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export declare const TLDS: Set<string>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Jodit Editor (https://xdsoft.net/jodit/)
|
|
3
|
+
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
|
+
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @module plugins/link
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The endings a bare domain links with, besides those `link.typedLinkTlds`
|
|
11
|
+
* adds: the generic ones of at least 1 in 1,000 of the sites in Tranco's top
|
|
12
|
+
* million (list GQ38K, https://tranco-list.eu/list/GQ38K), then every
|
|
13
|
+
* two-letter one in IANA's list (version 2026102900,
|
|
14
|
+
* https://data.iana.org/TLD/tlds-alpha-by-domain.txt). Together they're the
|
|
15
|
+
* endings of 96% of those sites
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export const TLDS = new Set(`
|
|
19
|
+
app biz casino click cloud club com dev edu gov info live net online org pro
|
|
20
|
+
shop site space store tech top vip xyz
|
|
21
|
+
ac ad ae af ag ai al am ao aq ar as at au aw ax az ba bb bd be bf bg bh bi
|
|
22
|
+
bj bm bn bo br bs bt bv bw by bz ca cc cd cf cg ch ci ck cl cm cn co cr cu
|
|
23
|
+
cv cw cx cy cz de dj dk dm do dz ec ee eg er es et eu fi fj fk fm fo fr ga
|
|
24
|
+
gb gd ge gf gg gh gi gl gm gn gp gq gr gs gt gu gw gy hk hm hn hr ht hu id
|
|
25
|
+
ie il im in io iq ir is it je jm jo jp ke kg kh ki km kn kp kr kw ky kz la
|
|
26
|
+
lb lc li lk lr ls lt lu lv ly ma mc md me mg mh mk ml mm mn mo mp mq mr ms
|
|
27
|
+
mt mu mv mw mx my mz na nc ne nf ng ni nl no np nr nu nz om pa pe pf pg ph
|
|
28
|
+
pk pl pm pn pr ps pt pw py qa re ro rs ru rw sa sb sc sd se sg sh si sj sk
|
|
29
|
+
sl sm sn so sr ss st su sv sx sy sz tc td tf tg th tj tk tl tm tn to tr tt
|
|
30
|
+
tv tw tz ua ug uk us uy uz va vc ve vg vi vn vu wf ws ye yt za zm zw
|
|
31
|
+
`
|
|
32
|
+
.trim()
|
|
33
|
+
.split(/\s+/));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Jodit Editor (https://xdsoft.net/jodit/)
|
|
3
|
+
* Released under MIT see LICENSE.txt in the project root for license information.
|
|
4
|
+
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* An email address, for `mailto:`
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
export declare const EMAIL: RegExp;
|
|
11
|
+
/**
|
|
12
|
+
* The address that ends at `end` in a line of text typed, back to the
|
|
13
|
+
* whitespace before it, as `[start, end, href]`. Punctuation round it, such as
|
|
14
|
+
* a sentence's full stop or a bracket the address doesn't open, stays out.
|
|
15
|
+
* An address counts with a scheme, with `www.`, as an email address, or as a
|
|
16
|
+
* bare domain that `isBareDomain` accepts, so `Node.js` or `e.g.` don't
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
export declare function findTypedLink(text: string, end: number, tlds: string[], fileEndings: string[]): [
|
|
20
|
+
number,
|
|
21
|
+
number,
|
|
22
|
+
string
|
|
23
|
+
] | null;
|