jodit 4.19.6 → 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 +22 -0
- package/es2015/jodit.css +1 -1
- package/es2015/jodit.fat.min.js +6 -6
- package/es2015/jodit.js +494 -102
- package/es2015/jodit.min.js +8 -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 +6 -6
- package/es2018/jodit.min.js +8 -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 +7 -7
- package/es2021/jodit.js +482 -101
- package/es2021/jodit.min.js +57 -57
- 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 +18 -18
- package/es2021.en/jodit.js +482 -101
- package/es2021.en/jodit.min.js +18 -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 +578 -107
- 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/core/constants.js +1 -1
- 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/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/plugins/delete/delete.d.ts +12 -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/es5/polyfills.fat.min.js
CHANGED
package/es5/polyfills.js
CHANGED
package/es5/polyfills.min.js
CHANGED
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.7";
|
|
7
7
|
// prettier-ignore
|
|
8
8
|
export const ES = "es2020";
|
|
9
9
|
export const IS_ES_MODERN = true;
|
|
@@ -3,12 +3,38 @@
|
|
|
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 {
|
|
6
|
+
import { Dom } from "../../dom/dom.js";
|
|
7
|
+
import { $$ } from "../../helpers/utils/selector.js";
|
|
8
|
+
import { extractSelectedPart, FiniteStateMachine } from "./api/index.js";
|
|
7
9
|
import { INITIAL } from "./constants.js";
|
|
8
10
|
import { states, transactions } from "./transactions.js";
|
|
11
|
+
/**
|
|
12
|
+
* Take a selected fragment out of the elements its style takes the place
|
|
13
|
+
* of: one around it is split, so the fragment leaves it, and one in it is
|
|
14
|
+
* unwrapped
|
|
15
|
+
*/
|
|
16
|
+
function takeOutOf(jodit, font, tags) {
|
|
17
|
+
const range = jodit.s.createRange();
|
|
18
|
+
let outer = Dom.closest(font.parentNode, tags, jodit.editor);
|
|
19
|
+
while (outer) {
|
|
20
|
+
range.selectNodeContents(outer);
|
|
21
|
+
range.setEndBefore(font);
|
|
22
|
+
const before = range.cloneContents();
|
|
23
|
+
range.selectNodeContents(outer);
|
|
24
|
+
range.setStartAfter(font);
|
|
25
|
+
// Split only when there's more in it, as a split leaves empty copies
|
|
26
|
+
// of the elements between
|
|
27
|
+
if (!Dom.isEmpty(before) || !Dom.isEmpty(range.cloneContents())) {
|
|
28
|
+
extractSelectedPart(outer, font, jodit);
|
|
29
|
+
}
|
|
30
|
+
Dom.unwrap(outer);
|
|
31
|
+
outer = Dom.closest(font.parentNode, tags, jodit.editor);
|
|
32
|
+
}
|
|
33
|
+
$$(tags.join(','), font).forEach(inner => Dom.unwrap(inner));
|
|
34
|
+
}
|
|
9
35
|
/** @internal */
|
|
10
36
|
export function ApplyStyle(jodit, cs) {
|
|
11
|
-
var _a;
|
|
37
|
+
var _a, _b;
|
|
12
38
|
const { s: sel, editor } = jodit;
|
|
13
39
|
(_a = editor.firstChild) === null || _a === void 0 ? void 0 : _a.normalize(); // FF fix for test "commandsTest - Exec command "bold"
|
|
14
40
|
const fakes = sel.fakes();
|
|
@@ -18,6 +44,9 @@ export function ApplyStyle(jodit, cs) {
|
|
|
18
44
|
// for...of closes the generator on an exception, releasing every
|
|
19
45
|
// temporary wrapper before the selection is restored in finally.
|
|
20
46
|
for (const font of sel.wrapInTagGen(fakes)) {
|
|
47
|
+
if ((_b = cs.options.exclude) === null || _b === void 0 ? void 0 : _b.length) {
|
|
48
|
+
takeOutOf(jodit, font, cs.options.exclude);
|
|
49
|
+
}
|
|
21
50
|
let state = {
|
|
22
51
|
collapsed,
|
|
23
52
|
mode,
|
package/esm/jodit.js
CHANGED
|
@@ -15,7 +15,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
15
15
|
};
|
|
16
16
|
var Jodit_1;
|
|
17
17
|
import * as constants from "./core/constants.js";
|
|
18
|
-
import { FAT_MODE, IS_PROD, lang } from "./core/constants.js";
|
|
18
|
+
import { FAT_MODE, IS_PROD, KEY_BACKSPACE, KEY_DELETE, KEY_ENTER, lang } from "./core/constants.js";
|
|
19
19
|
import { autobind, cache, cached, derive, throttle, watch } from "./core/decorators/index.js";
|
|
20
20
|
import { eventEmitter, instances, modules, pluginSystem } from "./core/global.js";
|
|
21
21
|
import { asArray, attr, callPromise, ConfigMerge, ConfigProto, css, error, isFunction, isJoditObject, isNumber, isPromise, isString, isVoid, kebabCase, markAsAtomic, normalizeKeyAliases, resolveElement, toArray, ucfirst } from "./core/helpers/index.js";
|
|
@@ -25,6 +25,18 @@ import { Dlgs } from "./core/traits/dlgs.js";
|
|
|
25
25
|
import { Config } from "./config.js";
|
|
26
26
|
import { Create, Dom, History, Plugin, Selection, StatusBar, STATUSES, ViewWithToolbar } from "./modules/index.js";
|
|
27
27
|
const FOCUS_EVENTS = new Set(['focus', 'blur', 'focusin', 'focusout']);
|
|
28
|
+
const EDITING_KEYS = new Set([KEY_ENTER, KEY_BACKSPACE, KEY_DELETE]);
|
|
29
|
+
/**
|
|
30
|
+
* Whether the input method (IME) is using the key. Safari fires the keydown
|
|
31
|
+
* that ends a composition, as the Enter that confirms Japanese text, after
|
|
32
|
+
* `compositionend`, and types Korean without one, so `isComposing` is false and
|
|
33
|
+
* only keyCode 229 tells. Only the keys the editor turns into edits are held
|
|
34
|
+
* back: the handlers that follow typing still see the rest.
|
|
35
|
+
*/
|
|
36
|
+
function isInputMethodKey(event) {
|
|
37
|
+
return (event.isComposing ||
|
|
38
|
+
(event.keyCode === 229 && EDITING_KEYS.has(event.key)));
|
|
39
|
+
}
|
|
28
40
|
const __defaultStyleDisplayKey = 'data-jodit-default-style-display';
|
|
29
41
|
const __defaultClassesKey = 'data-jodit-default-classes';
|
|
30
42
|
const NOEDIT = {
|
|
@@ -1264,7 +1276,7 @@ let Jodit = Jodit_1 = class Jodit extends ViewWithToolbar {
|
|
|
1264
1276
|
}
|
|
1265
1277
|
const w = this.ew;
|
|
1266
1278
|
if (event instanceof w.KeyboardEvent &&
|
|
1267
|
-
event
|
|
1279
|
+
isInputMethodKey(event)) {
|
|
1268
1280
|
return;
|
|
1269
1281
|
}
|
|
1270
1282
|
if (this.e && this.e.fire) {
|
|
@@ -20,6 +20,14 @@ function joinNeighbors(jodit, fakeNode, backspace, moved) {
|
|
|
20
20
|
if (checkJoinBareText(jodit, fakeNode, backspace)) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
+
// Old content can have an inline element round blocks beside the text:
|
|
24
|
+
// moved inside them, the line joins the block as it would bare text
|
|
25
|
+
// (#1781)
|
|
26
|
+
const inline = Dom.findNotEmptySibling(fakeNode, backspace);
|
|
27
|
+
if (joinsBareText(jodit, edgeBlock(inline, backspace)) &&
|
|
28
|
+
moveInlineInside(inline, jodit.editor)) {
|
|
29
|
+
return joinNeighbors(jodit, fakeNode, backspace, moved);
|
|
30
|
+
}
|
|
23
31
|
let nextBox = fakeNode, mainClosestBox = nextBox;
|
|
24
32
|
// Find the main big closest element
|
|
25
33
|
while (nextBox &&
|
|
@@ -350,13 +358,7 @@ function checkJoinInlineSibling(jodit, box, sibling, backspace) {
|
|
|
350
358
|
*/
|
|
351
359
|
function checkJoinBareText(jodit, fakeNode, backspace) {
|
|
352
360
|
const block = Dom.findNotEmptySibling(fakeNode, backspace);
|
|
353
|
-
if (!
|
|
354
|
-
!Dom.isBlock(block) ||
|
|
355
|
-
Dom.isList(block) ||
|
|
356
|
-
Dom.isTag(block, 'table') ||
|
|
357
|
-
Dom.isCell(block) ||
|
|
358
|
-
!Dom.isContentEditable(block, jodit.editor) ||
|
|
359
|
-
Array.from(block.childNodes).some(node => Dom.isBlock(node))) {
|
|
361
|
+
if (!joinsBareText(jodit, block)) {
|
|
360
362
|
return false;
|
|
361
363
|
}
|
|
362
364
|
const filter = getMoveFilter(jodit);
|
|
@@ -384,6 +386,33 @@ function checkJoinBareText(jodit, fakeNode, backspace) {
|
|
|
384
386
|
jodit.s.setCursorBefore(fakeNode);
|
|
385
387
|
return true;
|
|
386
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Whether a block joins the bare text beside it: not a list, a table or a
|
|
391
|
+
* cell, and holding no block of its own
|
|
392
|
+
*/
|
|
393
|
+
function joinsBareText(jodit, block) {
|
|
394
|
+
return (Dom.isElement(block) &&
|
|
395
|
+
Dom.isBlock(block) &&
|
|
396
|
+
!Dom.isList(block) &&
|
|
397
|
+
!Dom.isTag(block, 'table') &&
|
|
398
|
+
!Dom.isCell(block) &&
|
|
399
|
+
Dom.isContentEditable(block, jodit.editor) &&
|
|
400
|
+
!Array.from(block.childNodes).some(node => Dom.isBlock(node)));
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* The block an inline element holds on its side facing the caret, through
|
|
404
|
+
* the inline elements in it: the `<p>` of `<span><strong><p>…</p></strong></span>`
|
|
405
|
+
*/
|
|
406
|
+
function edgeBlock(node, backspace) {
|
|
407
|
+
var _a;
|
|
408
|
+
let edge = node;
|
|
409
|
+
while (Dom.isElement(edge) && !Dom.isBlock(edge)) {
|
|
410
|
+
const children = Array.from(edge.childNodes).filter(child => !Dom.isEmptyTextNode(child));
|
|
411
|
+
edge =
|
|
412
|
+
(_a = (backspace ? children[children.length - 1] : children[0])) !== null && _a !== void 0 ? _a : null;
|
|
413
|
+
}
|
|
414
|
+
return edge === node ? null : edge;
|
|
415
|
+
}
|
|
387
416
|
function checkMoveListContent(jodit, mainClosestBox, sibling, backspace) {
|
|
388
417
|
// Process UL/LI/OL cases
|
|
389
418
|
const siblingIsList = Dom.isTag(sibling, LIST_TAGS);
|
|
@@ -27,7 +27,6 @@ export function checkRemoveEmptyParent(jodit, fakeNode, backspace) {
|
|
|
27
27
|
if (!prn || !Dom.isEmpty(prn)) {
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
const neighbor = Dom.findNotEmptyNeighbor(fakeNode, backspace, jodit.editor);
|
|
31
30
|
do {
|
|
32
31
|
if (prn && Dom.isEmpty(prn) && !Dom.isCell(prn)) {
|
|
33
32
|
Dom.after(prn, fakeNode);
|
|
@@ -43,6 +42,9 @@ export function checkRemoveEmptyParent(jodit, fakeNode, backspace) {
|
|
|
43
42
|
if (found && checkJoinTwoLists(jodit, fakeNode, backspace)) {
|
|
44
43
|
return true;
|
|
45
44
|
}
|
|
45
|
+
// Looked for once the empty elements have gone, as the one beside the
|
|
46
|
+
// caret can be in them: the `<br>` that Delete in `<p>|<br></p>` leaves
|
|
47
|
+
const neighbor = Dom.findNotEmptyNeighbor(fakeNode, backspace, jodit.editor);
|
|
46
48
|
if (neighbor &&
|
|
47
49
|
!Dom.isText(neighbor) &&
|
|
48
50
|
!Dom.isTag(neighbor, INSEPARABLE_TAGS)) {
|
package/esm/plugins/bold/bold.js
CHANGED
|
@@ -32,8 +32,11 @@ export function bold(editor) {
|
|
|
32
32
|
? cssOptions[key][0]
|
|
33
33
|
: cssOptions[key];
|
|
34
34
|
});
|
|
35
|
+
const element = control.tags ? control.tags[0] : undefined;
|
|
35
36
|
editor.s.commitStyle({
|
|
36
|
-
element
|
|
37
|
+
element,
|
|
38
|
+
// As in the browsers and Word, each takes the other's place
|
|
39
|
+
exclude: element === 'sub' ? ['sup'] : element === 'sup' ? ['sub'] : []
|
|
37
40
|
});
|
|
38
41
|
editor.synchronizeValues();
|
|
39
42
|
return false;
|
|
@@ -31,6 +31,18 @@ export declare class deleteCommand extends Plugin {
|
|
|
31
31
|
*/
|
|
32
32
|
private __clearSelectedCells;
|
|
33
33
|
private __moveContentInLeftSibling;
|
|
34
|
+
/**
|
|
35
|
+
* A plain space the deletion leaves at an edge of the block, before a line
|
|
36
|
+
* break or next to another space isn't shown, and the browser drops it when
|
|
37
|
+
* the next char is typed. It becomes non-breaking, as in the browsers' own
|
|
38
|
+
* delete and in Backspace without a selection (#1522)
|
|
39
|
+
*/
|
|
40
|
+
private __keepSpacesVisible;
|
|
41
|
+
/**
|
|
42
|
+
* The text, line break or other element next to the caret in its block,
|
|
43
|
+
* looking inside inline elements
|
|
44
|
+
*/
|
|
45
|
+
private __findNeighbor;
|
|
34
46
|
/**
|
|
35
47
|
* If left sibling is list - return last leaf
|
|
36
48
|
*/
|
|
@@ -3,9 +3,10 @@
|
|
|
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 { NBSP_SPACE } from "../../core/constants.js";
|
|
6
7
|
import { Dom } from "../../core/dom/index.js";
|
|
7
8
|
import { pluginSystem } from "../../core/global.js";
|
|
8
|
-
import { toArray } from "../../core/helpers/index.js";
|
|
9
|
+
import { call, toArray, trimInv } from "../../core/helpers/index.js";
|
|
9
10
|
import { trim } from "../../core/helpers/string/trim.js";
|
|
10
11
|
import { Plugin } from "../../core/plugin/index.js";
|
|
11
12
|
import "./interface.js";
|
|
@@ -16,6 +17,18 @@ const NOT_EMPTY_CONTENT_TAGS = new Set([
|
|
|
16
17
|
'iframe',
|
|
17
18
|
'hr'
|
|
18
19
|
]);
|
|
20
|
+
const KEEPS_SPACES = new Set(['pre', 'pre-wrap', 'break-spaces']);
|
|
21
|
+
/**
|
|
22
|
+
* A plain space beside this neighbor isn't shown: there is none, or it's a
|
|
23
|
+
* line break, a block or text starting (or ending) with a plain space
|
|
24
|
+
*/
|
|
25
|
+
function hidesSpace(neighbor, edge) {
|
|
26
|
+
var _a;
|
|
27
|
+
return (!neighbor ||
|
|
28
|
+
Dom.isTag(neighbor, 'br') ||
|
|
29
|
+
Dom.isBlock(neighbor) ||
|
|
30
|
+
(Dom.isText(neighbor) && edge.test((_a = neighbor.nodeValue) !== null && _a !== void 0 ? _a : '')));
|
|
31
|
+
}
|
|
19
32
|
export class deleteCommand extends Plugin {
|
|
20
33
|
afterInit(jodit) {
|
|
21
34
|
jodit.e.on('afterCommand.delete', (command) => {
|
|
@@ -67,6 +80,7 @@ export class deleteCommand extends Plugin {
|
|
|
67
80
|
const leftSibling = Dom.findSibling(fake, true);
|
|
68
81
|
const rightSibling = Dom.findSibling(fake, false);
|
|
69
82
|
this.__moveContentInLeftSibling(fake, leftSibling, rightSibling);
|
|
83
|
+
this.__keepSpacesVisible(fake);
|
|
70
84
|
range.setStartBefore(fake);
|
|
71
85
|
range.collapse(true);
|
|
72
86
|
this.__moveCursorInEditableSibling(jodit, leftSibling, fake, range);
|
|
@@ -170,6 +184,41 @@ export class deleteCommand extends Plugin {
|
|
|
170
184
|
}
|
|
171
185
|
}
|
|
172
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* A plain space the deletion leaves at an edge of the block, before a line
|
|
189
|
+
* break or next to another space isn't shown, and the browser drops it when
|
|
190
|
+
* the next char is typed. It becomes non-breaking, as in the browsers' own
|
|
191
|
+
* delete and in Backspace without a selection (#1522)
|
|
192
|
+
*/
|
|
193
|
+
__keepSpacesVisible(fake) {
|
|
194
|
+
var _a;
|
|
195
|
+
const { jodit } = this;
|
|
196
|
+
const block = (_a = Dom.closest(fake, Dom.isBlock, jodit.editor)) !== null && _a !== void 0 ? _a : jodit.editor;
|
|
197
|
+
if (KEEPS_SPACES.has(jodit.ew.getComputedStyle(block).whiteSpace)) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const before = this.__findNeighbor(fake, true, block);
|
|
201
|
+
const after = this.__findNeighbor(fake, false, block);
|
|
202
|
+
if (Dom.isText(before) && hidesSpace(after, /^ /)) {
|
|
203
|
+
before.nodeValue = before.nodeValue.replace(/ +$/, spaces => NBSP_SPACE.repeat(spaces.length));
|
|
204
|
+
}
|
|
205
|
+
if (Dom.isText(after) && hidesSpace(before, / $/)) {
|
|
206
|
+
after.nodeValue = after.nodeValue.replace(/^ +/, spaces => NBSP_SPACE.repeat(spaces.length));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The text, line break or other element next to the caret in its block,
|
|
211
|
+
* looking inside inline elements
|
|
212
|
+
*/
|
|
213
|
+
__findNeighbor(fake, left, block) {
|
|
214
|
+
return call(left ? Dom.prev : Dom.next, fake, (node) => {
|
|
215
|
+
var _a;
|
|
216
|
+
return Dom.isText(node)
|
|
217
|
+
? trimInv((_a = node.nodeValue) !== null && _a !== void 0 ? _a : '').length > 0
|
|
218
|
+
: !Dom.isComment(node) &&
|
|
219
|
+
!(Dom.isInlineBlock(node) && node.firstChild);
|
|
220
|
+
}, block);
|
|
221
|
+
}
|
|
173
222
|
/**
|
|
174
223
|
* If left sibling is list - return last leaf
|
|
175
224
|
*/
|
|
@@ -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
|