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
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
import { isURL } from "../../core/helpers/checker/is-url.js";
|
|
10
|
+
import { TLDS } from "./tlds.js";
|
|
11
|
+
/**
|
|
12
|
+
* An email address, for `mailto:`
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
export const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
16
|
+
const OPENING = new Set(['(', '[', '"', "'", '“', '‘', '<']);
|
|
17
|
+
const CLOSING = new Set([
|
|
18
|
+
'.',
|
|
19
|
+
',',
|
|
20
|
+
';',
|
|
21
|
+
':',
|
|
22
|
+
'!',
|
|
23
|
+
'?',
|
|
24
|
+
'"',
|
|
25
|
+
"'",
|
|
26
|
+
'”',
|
|
27
|
+
'’',
|
|
28
|
+
'>'
|
|
29
|
+
]);
|
|
30
|
+
const BRACKETS = { ')': '(', ']': '[' };
|
|
31
|
+
const LABEL = /^[a-z\d][a-z\d-]{0,62}$/i;
|
|
32
|
+
/**
|
|
33
|
+
* The address that ends at `end` in a line of text typed, back to the
|
|
34
|
+
* whitespace before it, as `[start, end, href]`. Punctuation round it, such as
|
|
35
|
+
* a sentence's full stop or a bracket the address doesn't open, stays out.
|
|
36
|
+
* An address counts with a scheme, with `www.`, as an email address, or as a
|
|
37
|
+
* bare domain that `isBareDomain` accepts, so `Node.js` or `e.g.` don't
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
export function findTypedLink(text, end, tlds, fileEndings) {
|
|
41
|
+
let start = end;
|
|
42
|
+
while (start > 0 && !/\s/.test(text[start - 1])) {
|
|
43
|
+
start -= 1;
|
|
44
|
+
}
|
|
45
|
+
while (start < end && OPENING.has(text[start])) {
|
|
46
|
+
start += 1;
|
|
47
|
+
}
|
|
48
|
+
while (end > start) {
|
|
49
|
+
const char = text[end - 1];
|
|
50
|
+
const opening = BRACKETS[char];
|
|
51
|
+
if (CLOSING.has(char) ||
|
|
52
|
+
(opening && !text.slice(start, end - 1).includes(opening))) {
|
|
53
|
+
end -= 1;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const href = typedLinkHref(text.slice(start, end), tlds, fileEndings);
|
|
60
|
+
return href ? [start, end, href] : null;
|
|
61
|
+
}
|
|
62
|
+
function typedLinkHref(address, tlds, fileEndings) {
|
|
63
|
+
const email = address.replace(/^mailto:/i, '');
|
|
64
|
+
if (EMAIL.test(email)) {
|
|
65
|
+
return `mailto:${email}`;
|
|
66
|
+
}
|
|
67
|
+
if (/^www\.[^\s.]+\.\S+$/i.test(address) ||
|
|
68
|
+
isBareDomain(address, tlds, fileEndings)) {
|
|
69
|
+
return `https://${address}`;
|
|
70
|
+
}
|
|
71
|
+
return /^[a-z][a-z\d+.-]*:\/\//i.test(address) && isURL(address)
|
|
72
|
+
? address
|
|
73
|
+
: '';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A domain typed without a scheme or `www.`, as `example.com`, `elections.nz`
|
|
77
|
+
* or `bit.ly/enrol`. Its ending has to be in `TLDS` or `tlds`, typed in lower
|
|
78
|
+
* case, so `Node.js` and a sentence run on, as in `home.It`, don't count, and
|
|
79
|
+
* not in `fileEndings`, as in `photos.zip`. The first part has a letter,
|
|
80
|
+
* which leaves out a time or a numbered step such as `11.am`
|
|
81
|
+
*/
|
|
82
|
+
function isBareDomain(address, tlds, fileEndings) {
|
|
83
|
+
const cut = address.search(/[/?#]/);
|
|
84
|
+
const host = cut < 0 ? address : address.slice(0, cut);
|
|
85
|
+
const labels = host.split('.');
|
|
86
|
+
const ending = labels[labels.length - 1];
|
|
87
|
+
return (labels.length > 1 &&
|
|
88
|
+
labels.every(label => LABEL.test(label) && !label.endsWith('-')) &&
|
|
89
|
+
(TLDS.has(ending) || tlds.includes(ending)) &&
|
|
90
|
+
!fileEndings.includes(ending) &&
|
|
91
|
+
/[a-z]/i.test(labels[0]));
|
|
92
|
+
}
|
package/package.json
CHANGED
package/types/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
|
|
@@ -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
|
|
@@ -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
|
}
|
|
@@ -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,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;
|