jodit 4.19.6 → 4.19.8

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/es2015/jodit.css +1 -1
  3. package/es2015/jodit.fat.min.js +10 -10
  4. package/es2015/jodit.js +787 -200
  5. package/es2015/jodit.min.js +10 -10
  6. package/es2015/plugins/debug/debug.css +1 -1
  7. package/es2015/plugins/debug/debug.js +1 -1
  8. package/es2015/plugins/debug/debug.min.js +1 -1
  9. package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
  10. package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
  11. package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
  12. package/es2018/jodit.fat.min.js +10 -10
  13. package/es2018/jodit.min.js +10 -10
  14. package/es2018/plugins/debug/debug.min.js +1 -1
  15. package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
  16. package/es2021/jodit.css +1 -1
  17. package/es2021/jodit.fat.min.js +12 -12
  18. package/es2021/jodit.js +709 -143
  19. package/es2021/jodit.min.js +12 -12
  20. package/es2021/plugins/debug/debug.css +1 -1
  21. package/es2021/plugins/debug/debug.js +1 -1
  22. package/es2021/plugins/debug/debug.min.js +1 -1
  23. package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
  24. package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
  25. package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
  26. package/es2021.en/jodit.css +1 -1
  27. package/es2021.en/jodit.fat.min.js +18 -18
  28. package/es2021.en/jodit.js +709 -143
  29. package/es2021.en/jodit.min.js +18 -18
  30. package/es2021.en/plugins/debug/debug.css +1 -1
  31. package/es2021.en/plugins/debug/debug.js +1 -1
  32. package/es2021.en/plugins/debug/debug.min.js +1 -1
  33. package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
  34. package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
  35. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
  36. package/es5/jodit.css +2 -2
  37. package/es5/jodit.fat.min.js +2 -2
  38. package/es5/jodit.js +947 -208
  39. package/es5/jodit.min.css +2 -2
  40. package/es5/jodit.min.js +2 -2
  41. package/es5/plugins/debug/debug.css +1 -1
  42. package/es5/plugins/debug/debug.js +1 -1
  43. package/es5/plugins/debug/debug.min.js +1 -1
  44. package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
  45. package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
  46. package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
  47. package/es5/polyfills.fat.min.js +1 -1
  48. package/es5/polyfills.js +1 -1
  49. package/es5/polyfills.min.js +1 -1
  50. package/esm/core/constants.d.ts +1 -0
  51. package/esm/core/constants.js +3 -1
  52. package/esm/core/helpers/utils/error/error.d.ts +1 -0
  53. package/esm/core/helpers/utils/error/error.js +4 -1
  54. package/esm/core/helpers/utils/error/errors/answer-error.d.ts +13 -0
  55. package/esm/core/helpers/utils/error/errors/answer-error.js +17 -0
  56. package/esm/core/helpers/utils/error/errors/index.d.ts +1 -0
  57. package/esm/core/helpers/utils/error/errors/index.js +1 -0
  58. package/esm/core/request/ajax.d.ts +1 -0
  59. package/esm/core/request/ajax.js +20 -1
  60. package/esm/core/selection/style/apply-style.js +31 -2
  61. package/esm/jodit.js +14 -2
  62. package/esm/modules/file-browser/data-provider.js +5 -3
  63. package/esm/modules/uploader/config.js +4 -0
  64. package/esm/modules/uploader/helpers/send-files.d.ts +2 -2
  65. package/esm/modules/uploader/helpers/send-files.js +76 -9
  66. package/esm/modules/uploader/helpers/upload-error.d.ts +15 -0
  67. package/esm/modules/uploader/helpers/upload-error.js +16 -0
  68. package/esm/modules/uploader/uploader.js +15 -3
  69. package/esm/plugins/backspace/cases/check-join-neighbors.js +36 -7
  70. package/esm/plugins/backspace/cases/check-remove-empty-parent.js +3 -1
  71. package/esm/plugins/bold/bold.js +4 -1
  72. package/esm/plugins/delete/delete.d.ts +12 -0
  73. package/esm/plugins/delete/delete.js +50 -1
  74. package/esm/plugins/resize-cells/resize-cells.d.ts +25 -1
  75. package/esm/plugins/resize-cells/resize-cells.js +84 -15
  76. package/esm/plugins/select/select.d.ts +35 -0
  77. package/esm/plugins/select/select.js +153 -1
  78. package/esm/plugins/select-cells/select-cells.d.ts +24 -0
  79. package/esm/plugins/select-cells/select-cells.js +81 -18
  80. package/esm/types/style.d.ts +5 -0
  81. package/esm/types/uploader.d.ts +117 -11
  82. package/package.json +2 -2
  83. package/types/core/constants.d.ts +1 -0
  84. package/types/core/helpers/utils/error/error.d.ts +1 -0
  85. package/types/core/helpers/utils/error/errors/answer-error.d.ts +13 -0
  86. package/types/core/helpers/utils/error/errors/index.d.ts +1 -0
  87. package/types/core/request/ajax.d.ts +1 -0
  88. package/types/modules/uploader/helpers/send-files.d.ts +2 -2
  89. package/types/modules/uploader/helpers/upload-error.d.ts +15 -0
  90. package/types/plugins/delete/delete.d.ts +12 -0
  91. package/types/plugins/resize-cells/resize-cells.d.ts +25 -1
  92. package/types/plugins/select/select.d.ts +35 -0
  93. package/types/plugins/select-cells/select-cells.d.ts +24 -0
  94. package/types/types/style.d.ts +5 -0
  95. package/types/types/uploader.d.ts +117 -11
@@ -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)) {
@@ -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: control.tags ? control.tags[0] : undefined
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 each new width
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 each new width
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 tableBox = this.workTable.parentNode.getBoundingClientRect();
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.restoreStyles();
193
- this.resizeColumnsOrTable();
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
- tableModule.setColumnWidthByDelta(this.workTable, tableModule.formalCoordinate(this.workTable, this.workCell, true)[1], delta, true, marked);
326
- const nextTD = call(this.isRTL ? Dom.prev : Dom.next, this.workCell, Dom.isCell, this.workCell.parentNode);
327
- tableModule.setColumnWidthByDelta(this.workTable, tableModule.formalCoordinate(this.workTable, nextTD)[1], -delta, false, marked);
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.workTable.offsetWidth, parentWidth = getContentWidth(this.workTable.parentNode, this.j.ew);
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]: ((margin + delta) / parentWidth) * 100 + '%'
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
- if (this.j.isLocked) {
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
@@ -17,6 +17,7 @@ import { IS_INLINE, LIST_TAGS } from "../../core/constants.js";
17
17
  import { autobind, watch } from "../../core/decorators/index.js";
18
18
  import { Dom } from "../../core/dom/dom.js";
19
19
  import { pluginSystem } from "../../core/global.js";
20
+ import { toArray } from "../../core/helpers/array/to-array.js";
20
21
  import { camelCase } from "../../core/helpers/string/camel-case.js";
21
22
  import { Plugin } from "../../core/plugin/index.js";
22
23
  import { Popup, UIElement } from "../../core/ui/index.js";
@@ -48,16 +49,24 @@ export class select extends Plugin {
48
49
  * press inside a popup is remembered to tell such a drag from a real click.
49
50
  */
50
51
  this.__pressTarget = null;
52
+ /**
53
+ * The row a press to its right was beside, and the caret it put there,
54
+ * while the button is down
55
+ */
56
+ this.__pressBesideRow = null;
51
57
  }
52
58
  afterInit(jodit) {
53
59
  this.proxyEventsList.forEach(eventName => {
54
60
  jodit.e.on(eventName + '.select', this.onStartSelection);
55
61
  });
62
+ jodit.e.on('dblclick', this.__onDblClickBesideRow, { top: true });
56
63
  }
57
64
  beforeDestruct(jodit) {
58
65
  this.proxyEventsList.forEach(eventName => {
59
- jodit.e.on(eventName + '.select', this.onStartSelection);
66
+ jodit.e.off(eventName + '.select', this.onStartSelection);
60
67
  });
68
+ this.__endPressBesideRow();
69
+ jodit.e.off('dblclick', this.__onDblClickBesideRow);
61
70
  }
62
71
  onStartSelection(e) {
63
72
  const { j } = this;
@@ -137,6 +146,137 @@ export class select extends Plugin {
137
146
  s.setCursorAfter(text);
138
147
  }
139
148
  }
149
+ /**
150
+ * The table row the mouse is to the right of
151
+ */
152
+ __rowBeside(e) {
153
+ var _a;
154
+ const { j } = this;
155
+ const target = e.target;
156
+ if (j.o.readonly ||
157
+ e.button !== 0 ||
158
+ e.detail > 2 ||
159
+ !Dom.isHTMLElement(target) ||
160
+ Dom.closest(target, Dom.isCell, j.editor)) {
161
+ return null;
162
+ }
163
+ const table = toArray(target.children).find((elm) => {
164
+ if (!Dom.isTag(elm, 'table')) {
165
+ return false;
166
+ }
167
+ const box = elm.getBoundingClientRect();
168
+ return (e.clientX >= box.right &&
169
+ e.clientY >= box.top &&
170
+ e.clientY < box.bottom);
171
+ });
172
+ const rows = table
173
+ ? toArray(table.rows).filter(row => row.cells.length)
174
+ : [];
175
+ if (!table || !rows.length) {
176
+ return null;
177
+ }
178
+ const row = (_a = rows.find(row => e.clientY < row.getBoundingClientRect().bottom)) !== null && _a !== void 0 ? _a : rows[rows.length - 1];
179
+ return { table, row };
180
+ }
181
+ /**
182
+ * A press to the right of a table row puts the caret where Word's typing
183
+ * goes from there: the start of the next row's first cell, or of the block
184
+ * after the table for the last row (#1770). The browsers put it after the
185
+ * table, whichever row it's beside, so typing starts a new line below it.
186
+ * Their own press is stopped, as its drag would start after the table and
187
+ * take in the rows below first
188
+ */
189
+ onMouseDownBesideTableRow(e) {
190
+ const { j } = this;
191
+ const beside = this.__rowBeside(e);
192
+ if (!beside) {
193
+ return;
194
+ }
195
+ // A press before the last one was let go must not stack its listeners
196
+ this.__endPressBesideRow();
197
+ e.preventDefault();
198
+ this.__putCaretBesideRow(beside.table, beside.row);
199
+ this.__pressBesideRow = {
200
+ row: beside.row,
201
+ caret: j.s.range.cloneRange()
202
+ };
203
+ j.e.on(j.ew, 'mousemove', this.__onDragFromRow);
204
+ new Set([j.ew, j.ow]).forEach(win => j.e.on(win, 'mouseup', this.__onReleaseFromRow));
205
+ }
206
+ /**
207
+ * A drag from beside a row selects from the end of the row to the mouse,
208
+ * and back beside the row it's the caret again
209
+ */
210
+ __onDragFromRow(e) {
211
+ var _a, _b;
212
+ const { s } = this.j;
213
+ const press = this.__pressBesideRow;
214
+ if (!press || !(e.buttons & 1)) {
215
+ this.__endPressBesideRow();
216
+ return;
217
+ }
218
+ if (((_a = this.__rowBeside(e)) === null || _a === void 0 ? void 0 : _a.row) === press.row) {
219
+ if (!s.isCollapsed()) {
220
+ s.selectRange(press.caret.cloneRange());
221
+ }
222
+ return;
223
+ }
224
+ const { cells } = press.row;
225
+ const last = cells[cells.length - 1];
226
+ if (s.insertCursorAtPoint(e.clientX, e.clientY)) {
227
+ const { startContainer, startOffset } = s.range;
228
+ (_b = s.sel) === null || _b === void 0 ? void 0 : _b.setBaseAndExtent(last, last.childNodes.length, startContainer, startOffset);
229
+ }
230
+ }
231
+ /**
232
+ * In iframe mode, a press in an editor without the focus puts the caret at
233
+ * its end, so a release that selected nothing puts it back
234
+ */
235
+ __onReleaseFromRow() {
236
+ const press = this.__pressBesideRow;
237
+ this.__endPressBesideRow();
238
+ if (press && this.j.s.isCollapsed()) {
239
+ this.j.s.selectRange(press.caret);
240
+ }
241
+ }
242
+ __endPressBesideRow() {
243
+ const { j } = this;
244
+ this.__pressBesideRow = null;
245
+ j.e.off(j.ew, 'mousemove', this.__onDragFromRow);
246
+ new Set([j.ew, j.ow]).forEach(win => j.e.off(win, 'mouseup', this.__onReleaseFromRow));
247
+ }
248
+ /**
249
+ * A double click beside a row is two clicks there, so add-new-line,
250
+ * which adds a line on a double click with a caret, doesn't see it
251
+ */
252
+ __onDblClickBesideRow(e) {
253
+ if (this.__rowBeside(e)) {
254
+ this.j.e.stopPropagation('dblclick');
255
+ return false;
256
+ }
257
+ }
258
+ __putCaretBesideRow(table, row) {
259
+ const { j } = this;
260
+ const rows = toArray(table.rows);
261
+ const next = rows
262
+ .slice(rows.indexOf(row) + 1)
263
+ .find(row => row.cells.length);
264
+ let after = table.nextSibling;
265
+ while (after && Dom.isEmptyTextNode(after)) {
266
+ after = after.nextSibling;
267
+ }
268
+ if (next) {
269
+ j.s.setCursorIn(next.cells[0], true);
270
+ }
271
+ else if (Dom.isBlock(after) &&
272
+ !Dom.isTag(after, 'table') &&
273
+ Dom.isContentEditable(after, j.editor)) {
274
+ j.s.setCursorIn(after, true);
275
+ }
276
+ else {
277
+ j.s.setCursorAfter(table);
278
+ }
279
+ }
140
280
  /**
141
281
  * Keep pending inline formatting after a click. Toggling Bold/Italic/etc. on
142
282
  * a collapsed cursor leaves empty marker elements with the caret inside; a
@@ -216,6 +356,18 @@ __decorate([
216
356
  __decorate([
217
357
  watch([':click'])
218
358
  ], select.prototype, "onClickRightOfNestedListItem", null);
359
+ __decorate([
360
+ watch(':mousedown')
361
+ ], select.prototype, "onMouseDownBesideTableRow", null);
362
+ __decorate([
363
+ autobind
364
+ ], select.prototype, "__onDragFromRow", null);
365
+ __decorate([
366
+ autobind
367
+ ], select.prototype, "__onReleaseFromRow", null);
368
+ __decorate([
369
+ autobind
370
+ ], select.prototype, "__onDblClickBesideRow", null);
219
371
  __decorate([
220
372
  watch([':click'])
221
373
  ], select.prototype, "onClickKeepPendingFormat", null);
@@ -49,11 +49,28 @@ export declare class selectCells extends Plugin {
49
49
  * User is selecting cells now
50
50
  */
51
51
  private __isSelectionMode;
52
+ /**
53
+ * The cell the marks were last drawn to
54
+ */
55
+ private __movedTo;
56
+ /**
57
+ * A drag let go outside the table ends in a click on the editor, which
58
+ * would unmark its cells
59
+ */
60
+ private __keepMarks;
52
61
  /**
53
62
  * Mouse click inside the table
54
63
  */
55
64
  protected onStartSelection(cell: HTMLTableCellElement, event?: MouseEvent): void | false;
56
65
  protected onOutsideClick(): void;
66
+ protected onMouseDown(): void;
67
+ /**
68
+ * The click that ends a drag let go outside the table, and inside the
69
+ * editor, lands on the editor. Taken on, it would unmark the cells and
70
+ * close their popup. As for the click on a row after a drag over the
71
+ * cells, the browser's own selection from the drag goes
72
+ */
73
+ private __onClickAfterDrag;
57
74
  protected onChange(): void;
58
75
  /**
59
76
  * Mouse move inside the table
@@ -67,6 +84,13 @@ export declare class selectCells extends Plugin {
67
84
  * Stop a selection process
68
85
  */
69
86
  private __onStopSelection;
87
+ /**
88
+ * A drag let go outside the table doesn't reach the table's `mouseup`, so
89
+ * the window's ends it, leaving the cells marked as they were (#1774)
90
+ */
91
+ private __onRelease;
92
+ private __showCellsPopup;
93
+ private __stopListening;
70
94
  /**
71
95
  * Remove selection for all cells
72
96
  */