jodit 4.19.5 → 4.19.7
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 +32 -0
- package/es2015/jodit.css +1 -1
- package/es2015/jodit.fat.min.js +21 -8
- package/es2015/jodit.js +847 -155
- package/es2015/jodit.min.js +21 -8
- 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 +20 -7
- package/es2018/jodit.min.js +21 -8
- 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 +21 -8
- package/es2021/jodit.js +832 -154
- package/es2021/jodit.min.js +69 -56
- 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 +31 -18
- package/es2021.en/jodit.js +832 -154
- package/es2021.en/jodit.min.js +31 -18
- 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 +947 -166
- 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/core/selection/style/apply-style.js +31 -2
- package/esm/jodit.js +14 -2
- package/esm/plugins/backspace/cases/check-join-neighbors.js +36 -7
- package/esm/plugins/backspace/cases/check-remove-empty-parent.js +3 -1
- package/esm/plugins/bold/bold.js +4 -1
- package/esm/plugins/delete/delete.d.ts +12 -0
- package/esm/plugins/delete/delete.js +50 -1
- 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/esm/plugins/resize-cells/resize-cells.d.ts +25 -1
- package/esm/plugins/resize-cells/resize-cells.js +84 -15
- package/esm/plugins/select/select.d.ts +35 -0
- package/esm/plugins/select/select.js +153 -1
- package/esm/plugins/select-cells/select-cells.d.ts +24 -0
- package/esm/plugins/select-cells/select-cells.js +81 -18
- package/esm/types/style.d.ts +5 -0
- package/package.json +1 -1
- package/types/config.d.ts +31 -0
- package/types/plugins/delete/delete.d.ts +12 -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/types/plugins/resize-cells/resize-cells.d.ts +25 -1
- package/types/plugins/select/select.d.ts +35 -0
- package/types/plugins/select-cells/select-cells.d.ts +24 -0
- package/types/types/style.d.ts +5 -0
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;
|
|
@@ -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
|
+
}
|
|
@@ -39,11 +39,24 @@ export declare class resizeCells extends Plugin {
|
|
|
39
39
|
private startX;
|
|
40
40
|
/**
|
|
41
41
|
* The table's and its cells' styles as a column drag started, put back
|
|
42
|
-
* before
|
|
42
|
+
* as it ends, before the final widths
|
|
43
43
|
*/
|
|
44
44
|
private startStyles;
|
|
45
45
|
private startLeft;
|
|
46
46
|
private startEdge;
|
|
47
|
+
/**
|
|
48
|
+
* For each of the two columns a drag resizes, the cell whose width
|
|
49
|
+
* `setColumnWidthByDelta` sets, with its width as the drag started, and
|
|
50
|
+
* the cells below it, whose widths it clears
|
|
51
|
+
*/
|
|
52
|
+
private startWidths;
|
|
53
|
+
/**
|
|
54
|
+
* The table's width as the drag started, and for a drag of its edge, the
|
|
55
|
+
* width inside what holds it and its margin on that side
|
|
56
|
+
*/
|
|
57
|
+
private startTableWidth;
|
|
58
|
+
private startParentWidth;
|
|
59
|
+
private startMargin;
|
|
47
60
|
/**
|
|
48
61
|
* The row whose height the handle sets, or null while it sets a width
|
|
49
62
|
*/
|
|
@@ -88,10 +101,21 @@ export declare class resizeCells extends Plugin {
|
|
|
88
101
|
* row's scroller in view, scrolls it on, and the row's border with it
|
|
89
102
|
*/
|
|
90
103
|
private scrollAlong;
|
|
104
|
+
/**
|
|
105
|
+
* The two columns a column drag resizes: the work cell's last, and the
|
|
106
|
+
* next cell's first
|
|
107
|
+
*/
|
|
108
|
+
private resizedColumns;
|
|
91
109
|
/**
|
|
92
110
|
* Resize only one column
|
|
93
111
|
*/
|
|
94
112
|
private resizeColumns;
|
|
113
|
+
/**
|
|
114
|
+
* Sets the widths `resizeColumns` would while the handle is dragged, from
|
|
115
|
+
* the widths the drag started with, so that a move doesn't put back every
|
|
116
|
+
* cell's style and lay the table out again to measure them
|
|
117
|
+
*/
|
|
118
|
+
private setColumnWidths;
|
|
95
119
|
/**
|
|
96
120
|
* Resize whole table
|
|
97
121
|
*/
|
|
@@ -57,11 +57,24 @@ export class resizeCells extends Plugin {
|
|
|
57
57
|
this.startX = 0;
|
|
58
58
|
/**
|
|
59
59
|
* The table's and its cells' styles as a column drag started, put back
|
|
60
|
-
* before
|
|
60
|
+
* as it ends, before the final widths
|
|
61
61
|
*/
|
|
62
62
|
this.startStyles = [];
|
|
63
63
|
this.startLeft = 0;
|
|
64
64
|
this.startEdge = 0;
|
|
65
|
+
/**
|
|
66
|
+
* For each of the two columns a drag resizes, the cell whose width
|
|
67
|
+
* `setColumnWidthByDelta` sets, with its width as the drag started, and
|
|
68
|
+
* the cells below it, whose widths it clears
|
|
69
|
+
*/
|
|
70
|
+
this.startWidths = [];
|
|
71
|
+
/**
|
|
72
|
+
* The table's width as the drag started, and for a drag of its edge, the
|
|
73
|
+
* width inside what holds it and its margin on that side
|
|
74
|
+
*/
|
|
75
|
+
this.startTableWidth = 0;
|
|
76
|
+
this.startParentWidth = 0;
|
|
77
|
+
this.startMargin = 0;
|
|
65
78
|
/**
|
|
66
79
|
* The row whose height the handle sets, or null while it sets a width
|
|
67
80
|
*/
|
|
@@ -110,7 +123,7 @@ export class resizeCells extends Plugin {
|
|
|
110
123
|
* Click on resize handle
|
|
111
124
|
*/
|
|
112
125
|
onHandleMouseDown(event) {
|
|
113
|
-
if (this.j.isLocked) {
|
|
126
|
+
if (this.j.isLocked || this.j.o.readonly) {
|
|
114
127
|
return;
|
|
115
128
|
}
|
|
116
129
|
this.drag = true;
|
|
@@ -138,10 +151,15 @@ export class resizeCells extends Plugin {
|
|
|
138
151
|
let box;
|
|
139
152
|
this.minX = 0;
|
|
140
153
|
this.maxX = 1000000;
|
|
154
|
+
this.startTableWidth = this.workTable.offsetWidth;
|
|
141
155
|
if (this.wholeTable != null) {
|
|
142
|
-
const
|
|
156
|
+
const parent = this.workTable.parentNode;
|
|
157
|
+
const tableBox = parent.getBoundingClientRect();
|
|
143
158
|
this.minX = tableBox.left;
|
|
144
159
|
this.maxX = this.minX + tableBox.width;
|
|
160
|
+
const side = this.isRTL ? 'marginRight' : 'marginLeft';
|
|
161
|
+
this.startParentWidth = getContentWidth(parent, this.j.ew);
|
|
162
|
+
this.startMargin = parseInt(this.j.ew.getComputedStyle(this.workTable)[side] || '0', 10);
|
|
145
163
|
}
|
|
146
164
|
else {
|
|
147
165
|
// find maximum columns
|
|
@@ -156,6 +174,17 @@ export class resizeCells extends Plugin {
|
|
|
156
174
|
this.maxX = Math.min(box.left + box.width - consts.NEARBY / 2, this.maxX);
|
|
157
175
|
}
|
|
158
176
|
});
|
|
177
|
+
const matrix = this.module.formalMatrix(this.workTable);
|
|
178
|
+
this.startWidths = this.resizedColumns().map(column => {
|
|
179
|
+
const cells = matrix.map(row => row[column]);
|
|
180
|
+
const index = cells.findIndex(td => td.colSpan === 1 || cells.length === 1);
|
|
181
|
+
const cell = cells[index];
|
|
182
|
+
return [
|
|
183
|
+
cell,
|
|
184
|
+
cell ? cell.offsetWidth : 0,
|
|
185
|
+
cells.slice(Math.max(index, 0) + 1)
|
|
186
|
+
];
|
|
187
|
+
});
|
|
159
188
|
}
|
|
160
189
|
return false;
|
|
161
190
|
}
|
|
@@ -189,8 +218,12 @@ export class resizeCells extends Plugin {
|
|
|
189
218
|
}
|
|
190
219
|
this.resizeDelta =
|
|
191
220
|
x - this.startX + (!this.j.o.iframe ? 0 : workplacePosition.left);
|
|
192
|
-
this.
|
|
193
|
-
|
|
221
|
+
if (this.wholeTable == null) {
|
|
222
|
+
this.setColumnWidths();
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
this.resizeTable();
|
|
226
|
+
}
|
|
194
227
|
const tableBox = offset(this.workTable, this.j, this.j.ed);
|
|
195
228
|
Object.assign(this.resizeHandler.style, {
|
|
196
229
|
left: this.startLeft + this.columnEdge() - this.startEdge + 'px',
|
|
@@ -315,6 +348,17 @@ export class resizeCells extends Plugin {
|
|
|
315
348
|
};
|
|
316
349
|
this.scrollFrame = this.j.async.requestAnimationFrame(scroll);
|
|
317
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* The two columns a column drag resizes: the work cell's last, and the
|
|
353
|
+
* next cell's first
|
|
354
|
+
*/
|
|
355
|
+
resizedColumns() {
|
|
356
|
+
const nextTD = call(this.isRTL ? Dom.prev : Dom.next, this.workCell, Dom.isCell, this.workCell.parentNode);
|
|
357
|
+
return [
|
|
358
|
+
this.module.formalCoordinate(this.workTable, this.workCell, true)[1],
|
|
359
|
+
this.module.formalCoordinate(this.workTable, nextTD)[1]
|
|
360
|
+
];
|
|
361
|
+
}
|
|
318
362
|
/**
|
|
319
363
|
* Resize only one column
|
|
320
364
|
*/
|
|
@@ -322,16 +366,35 @@ export class resizeCells extends Plugin {
|
|
|
322
366
|
const delta = this.resizeDelta;
|
|
323
367
|
const marked = [];
|
|
324
368
|
const tableModule = this.module;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
tableModule.setColumnWidthByDelta(this.workTable,
|
|
369
|
+
const [column, nextColumn] = this.resizedColumns();
|
|
370
|
+
tableModule.setColumnWidthByDelta(this.workTable, column, delta, true, marked);
|
|
371
|
+
tableModule.setColumnWidthByDelta(this.workTable, nextColumn, -delta, false, marked);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Sets the widths `resizeColumns` would while the handle is dragged, from
|
|
375
|
+
* the widths the drag started with, so that a move doesn't put back every
|
|
376
|
+
* cell's style and lay the table out again to measure them
|
|
377
|
+
*/
|
|
378
|
+
setColumnWidths() {
|
|
379
|
+
this.startWidths.forEach(([cell, width, below], index) => {
|
|
380
|
+
const delta = index ? -this.resizeDelta : this.resizeDelta;
|
|
381
|
+
if (cell) {
|
|
382
|
+
css(cell, 'width', (((width + delta) / this.startTableWidth) * 100).toFixed(consts.ACCURACY) + '%');
|
|
383
|
+
}
|
|
384
|
+
below.forEach(td => {
|
|
385
|
+
td.style.removeProperty('width');
|
|
386
|
+
if (!attr(td, 'style')) {
|
|
387
|
+
attr(td, 'style', null);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
});
|
|
328
391
|
}
|
|
329
392
|
/**
|
|
330
393
|
* Resize whole table
|
|
331
394
|
*/
|
|
332
395
|
resizeTable() {
|
|
333
396
|
const delta = this.resizeDelta * (this.isRTL ? -1 : 1);
|
|
334
|
-
const width = this.
|
|
397
|
+
const width = this.startTableWidth, parentWidth = this.startParentWidth;
|
|
335
398
|
// for RTL use mirror logic
|
|
336
399
|
const rightSide = !this.wholeTable;
|
|
337
400
|
const needChangeWidth = this.isRTL ? !rightSide : rightSide;
|
|
@@ -341,10 +404,9 @@ export class resizeCells extends Plugin {
|
|
|
341
404
|
}
|
|
342
405
|
else {
|
|
343
406
|
const side = this.isRTL ? 'marginRight' : 'marginLeft';
|
|
344
|
-
const margin = parseInt(this.j.ew.getComputedStyle(this.workTable)[side] || '0', 10);
|
|
345
407
|
css(this.workTable, {
|
|
346
408
|
width: ((width - delta) / parentWidth) * 100 + '%',
|
|
347
|
-
[side]: ((
|
|
409
|
+
[side]: ((this.startMargin + delta) / parentWidth) * 100 + '%'
|
|
348
410
|
});
|
|
349
411
|
}
|
|
350
412
|
}
|
|
@@ -433,12 +495,13 @@ export class resizeCells extends Plugin {
|
|
|
433
495
|
if (!editor.o.tableAllowCellResize) {
|
|
434
496
|
return;
|
|
435
497
|
}
|
|
498
|
+
const observeTables = () => {
|
|
499
|
+
$$('table', editor.editor).forEach(this.observe);
|
|
500
|
+
};
|
|
436
501
|
editor.e
|
|
437
502
|
.off(this.j.ow, '.resize-cells')
|
|
438
503
|
.off('.resize-cells')
|
|
439
|
-
.on('change.resize-cells afterCommand.resize-cells afterSetMode.resize-cells',
|
|
440
|
-
$$('table', editor.editor).forEach(this.observe);
|
|
441
|
-
})
|
|
504
|
+
.on('change.resize-cells afterCommand.resize-cells afterSetMode.resize-cells', observeTables)
|
|
442
505
|
.on(this.j.ow, 'scroll.resize-cells', () => {
|
|
443
506
|
if (!this.drag || this.workRow) {
|
|
444
507
|
return;
|
|
@@ -456,6 +519,8 @@ export class resizeCells extends Plugin {
|
|
|
456
519
|
tableModule.normalizeTable(Dom.closest(td, 'table', editor.editor));
|
|
457
520
|
});
|
|
458
521
|
});
|
|
522
|
+
// None of those events comes with the editor's starting value
|
|
523
|
+
observeTables();
|
|
459
524
|
}
|
|
460
525
|
/**
|
|
461
526
|
* Add to every Table listeners
|
|
@@ -474,7 +539,11 @@ export class resizeCells extends Plugin {
|
|
|
474
539
|
}
|
|
475
540
|
})
|
|
476
541
|
.on(table, 'mousemove.resize-cells touchmove.resize-cells', this.j.async.throttle((event) => {
|
|
477
|
-
|
|
542
|
+
// A drag from a cell isn't a resize, and the handle on
|
|
543
|
+
// a border it passes would take its moves (#1778)
|
|
544
|
+
if (this.j.isLocked ||
|
|
545
|
+
this.j.o.readonly ||
|
|
546
|
+
event.buttons) {
|
|
478
547
|
return;
|
|
479
548
|
}
|
|
480
549
|
const cell = Dom.up(event.target, Dom.isCell, table);
|
|
@@ -46,6 +46,41 @@ export declare class select extends Plugin {
|
|
|
46
46
|
* of the end (#1296); move it to the end of the item's own text.
|
|
47
47
|
*/
|
|
48
48
|
protected onClickRightOfNestedListItem(e: MouseEvent): void;
|
|
49
|
+
/**
|
|
50
|
+
* The row a press to its right was beside, and the caret it put there,
|
|
51
|
+
* while the button is down
|
|
52
|
+
*/
|
|
53
|
+
private __pressBesideRow;
|
|
54
|
+
/**
|
|
55
|
+
* The table row the mouse is to the right of
|
|
56
|
+
*/
|
|
57
|
+
private __rowBeside;
|
|
58
|
+
/**
|
|
59
|
+
* A press to the right of a table row puts the caret where Word's typing
|
|
60
|
+
* goes from there: the start of the next row's first cell, or of the block
|
|
61
|
+
* after the table for the last row (#1770). The browsers put it after the
|
|
62
|
+
* table, whichever row it's beside, so typing starts a new line below it.
|
|
63
|
+
* Their own press is stopped, as its drag would start after the table and
|
|
64
|
+
* take in the rows below first
|
|
65
|
+
*/
|
|
66
|
+
protected onMouseDownBesideTableRow(e: MouseEvent): void;
|
|
67
|
+
/**
|
|
68
|
+
* A drag from beside a row selects from the end of the row to the mouse,
|
|
69
|
+
* and back beside the row it's the caret again
|
|
70
|
+
*/
|
|
71
|
+
private __onDragFromRow;
|
|
72
|
+
/**
|
|
73
|
+
* In iframe mode, a press in an editor without the focus puts the caret at
|
|
74
|
+
* its end, so a release that selected nothing puts it back
|
|
75
|
+
*/
|
|
76
|
+
private __onReleaseFromRow;
|
|
77
|
+
private __endPressBesideRow;
|
|
78
|
+
/**
|
|
79
|
+
* A double click beside a row is two clicks there, so add-new-line,
|
|
80
|
+
* which adds a line on a double click with a caret, doesn't see it
|
|
81
|
+
*/
|
|
82
|
+
private __onDblClickBesideRow;
|
|
83
|
+
private __putCaretBesideRow;
|
|
49
84
|
/**
|
|
50
85
|
* Keep pending inline formatting after a click. Toggling Bold/Italic/etc. on
|
|
51
86
|
* a collapsed cursor leaves empty marker elements with the caret inside; a
|