jodit 4.19.10 → 4.19.12

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 (98) hide show
  1. package/CHANGELOG.md +150 -131
  2. package/es2015/jodit.css +33 -1
  3. package/es2015/jodit.fat.min.css +1 -1
  4. package/es2015/jodit.fat.min.js +10 -10
  5. package/es2015/jodit.js +781 -195
  6. package/es2015/jodit.min.css +1 -1
  7. package/es2015/jodit.min.js +10 -10
  8. package/es2015/plugins/debug/debug.css +1 -1
  9. package/es2015/plugins/debug/debug.js +1 -1
  10. package/es2015/plugins/debug/debug.min.js +1 -1
  11. package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
  12. package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
  13. package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
  14. package/es2018/jodit.fat.min.css +1 -1
  15. package/es2018/jodit.fat.min.js +10 -10
  16. package/es2018/jodit.min.css +1 -1
  17. package/es2018/jodit.min.js +10 -10
  18. package/es2018/plugins/debug/debug.min.js +1 -1
  19. package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
  20. package/es2021/jodit.css +33 -1
  21. package/es2021/jodit.fat.min.css +1 -1
  22. package/es2021/jodit.fat.min.js +15 -15
  23. package/es2021/jodit.js +780 -193
  24. package/es2021/jodit.min.css +1 -1
  25. package/es2021/jodit.min.js +15 -15
  26. package/es2021/plugins/debug/debug.css +1 -1
  27. package/es2021/plugins/debug/debug.js +1 -1
  28. package/es2021/plugins/debug/debug.min.js +1 -1
  29. package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
  30. package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
  31. package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
  32. package/es2021.en/jodit.css +33 -1
  33. package/es2021.en/jodit.fat.min.css +1 -1
  34. package/es2021.en/jodit.fat.min.js +22 -22
  35. package/es2021.en/jodit.js +780 -193
  36. package/es2021.en/jodit.min.css +1 -1
  37. package/es2021.en/jodit.min.js +22 -22
  38. package/es2021.en/plugins/debug/debug.css +1 -1
  39. package/es2021.en/plugins/debug/debug.js +1 -1
  40. package/es2021.en/plugins/debug/debug.min.js +1 -1
  41. package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
  42. package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
  43. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
  44. package/es5/jodit.css +34 -2
  45. package/es5/jodit.fat.min.css +1 -1
  46. package/es5/jodit.fat.min.js +2 -2
  47. package/es5/jodit.js +827 -200
  48. package/es5/jodit.min.css +3 -3
  49. package/es5/jodit.min.js +2 -2
  50. package/es5/plugins/debug/debug.css +1 -1
  51. package/es5/plugins/debug/debug.js +1 -1
  52. package/es5/plugins/debug/debug.min.js +1 -1
  53. package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
  54. package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
  55. package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
  56. package/es5/polyfills.fat.min.js +1 -1
  57. package/es5/polyfills.js +1 -1
  58. package/es5/polyfills.min.js +1 -1
  59. package/esm/core/constants.js +1 -1
  60. package/esm/core/dom/dom.js +2 -2
  61. package/esm/core/helpers/checker/is-html-from-word.d.ts +4 -3
  62. package/esm/core/helpers/checker/is-html-from-word.js +94 -14
  63. package/esm/core/helpers/checker/is-html.d.ts +4 -0
  64. package/esm/core/helpers/checker/is-html.js +54 -2
  65. package/esm/core/helpers/html/apply-styles.js +20 -11
  66. package/esm/core/helpers/html/clean-from-word.js +2 -3
  67. package/esm/core/helpers/html/index.d.ts +1 -0
  68. package/esm/core/helpers/html/index.js +1 -0
  69. package/esm/core/helpers/html/tag-scan.d.ts +36 -0
  70. package/esm/core/helpers/html/tag-scan.js +257 -0
  71. package/esm/core/helpers/string/trim.d.ts +4 -0
  72. package/esm/core/helpers/string/trim.js +29 -10
  73. package/esm/core/selection/helpers/index.js +3 -2
  74. package/esm/core/ui/button/tooltip/tooltip.d.ts +6 -0
  75. package/esm/core/ui/button/tooltip/tooltip.js +14 -3
  76. package/esm/core/view/view-with-toolbar.js +6 -1
  77. package/esm/jodit.js +2 -1
  78. package/esm/plugins/add-new-line/add-new-line.d.ts +5 -0
  79. package/esm/plugins/add-new-line/add-new-line.js +20 -3
  80. package/esm/plugins/delete/delete.d.ts +7 -0
  81. package/esm/plugins/delete/delete.js +38 -2
  82. package/esm/plugins/hr/hr.js +5 -0
  83. package/esm/plugins/iframe/iframe.js +59 -12
  84. package/esm/plugins/media/media.js +10 -9
  85. package/esm/plugins/paste/helpers.js +4 -2
  86. package/esm/plugins/resizer/resizer.js +6 -5
  87. package/esm/plugins/select-cells/select-cells.d.ts +1 -0
  88. package/esm/plugins/select-cells/select-cells.js +12 -18
  89. package/package.json +1 -1
  90. package/types/core/helpers/checker/is-html-from-word.d.ts +4 -3
  91. package/types/core/helpers/checker/is-html.d.ts +4 -0
  92. package/types/core/helpers/html/index.d.ts +1 -0
  93. package/types/core/helpers/html/tag-scan.d.ts +36 -0
  94. package/types/core/helpers/string/trim.d.ts +4 -0
  95. package/types/core/ui/button/tooltip/tooltip.d.ts +6 -0
  96. package/types/plugins/add-new-line/add-new-line.d.ts +5 -0
  97. package/types/plugins/delete/delete.d.ts +7 -0
  98. package/types/plugins/select-cells/select-cells.d.ts +1 -0
@@ -0,0 +1,257 @@
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 helpers/html
8
+ */
9
+ // Single passes over HTML that comes from the clipboard or the editor value.
10
+ // A regex with `[^>]*` or `.*?` before a required literal backtracks
11
+ // quadratically on a long run of tag openers, so these walk with `indexOf`.
12
+ const TAG_NAME = /[a-z0-9:-]/i;
13
+ // The tags the Word clean-up strips: `<html>`, `<colgroup>`, `<col>`, `<o:p>` and their closers
14
+ const WORD_WRAPPER_TAGS = ['<html', '</html', '<col', '</col', '<o:p', '</o:p'];
15
+ function startsWithIgnoreCase(html, index, prefix) {
16
+ return html.substr(index, prefix.length).toLowerCase() === prefix;
17
+ }
18
+ // The first `<` at or after `from` that opens one of the prefixes (`<meta`, `</html`, `<!--`)
19
+ function indexOfPrefix(html, prefixes, from) {
20
+ let index = html.indexOf('<', from);
21
+ while (index !== -1) {
22
+ for (const prefix of prefixes) {
23
+ if (startsWithIgnoreCase(html, index, prefix)) {
24
+ return [index, prefix];
25
+ }
26
+ }
27
+ index = html.indexOf('<', index + 1);
28
+ }
29
+ return [-1, ''];
30
+ }
31
+ /**
32
+ * The first `</name>` at or after `from`, case-insensitive, or -1
33
+ */
34
+ export function indexOfClosingTag(html, name, from) {
35
+ const closing = '</' + name + '>';
36
+ let index = html.indexOf('</', from);
37
+ while (index !== -1) {
38
+ if (startsWithIgnoreCase(html, index, closing)) {
39
+ return index;
40
+ }
41
+ index = html.indexOf('</', index + 2);
42
+ }
43
+ return -1;
44
+ }
45
+ /**
46
+ * Remove every tag that starts with one of the prefixes, up to its `>`:
47
+ * `removeTagsByPrefix(html, ['<meta', '<!--'])`
48
+ */
49
+ export function removeTagsByPrefix(html, prefixes) {
50
+ const lower = prefixes.map(prefix => prefix.toLowerCase());
51
+ let result = '';
52
+ let cursor = 0;
53
+ for (;;) {
54
+ const [start] = indexOfPrefix(html, lower, cursor);
55
+ if (start === -1) {
56
+ break;
57
+ }
58
+ const end = html.indexOf('>', start);
59
+ if (end === -1) {
60
+ break;
61
+ }
62
+ result += html.slice(cursor, start);
63
+ cursor = end + 1;
64
+ }
65
+ return cursor === 0 ? html : result + html.slice(cursor);
66
+ }
67
+ /**
68
+ * Strip the Word wrapper tags and then the comments, as the clean-up always did
69
+ */
70
+ export function removeWordWrappers(html) {
71
+ return removeTagsByPrefix(removeTagsByPrefix(html, WORD_WRAPPER_TAGS), [
72
+ '<!--'
73
+ ]);
74
+ }
75
+ // Every `</name>` position by name, so the closer of an element is found by a binary search
76
+ function closingTagPositions(html) {
77
+ const positions = new Map();
78
+ let index = html.indexOf('</');
79
+ while (index !== -1) {
80
+ const name = readTagName(html, index + 2).toLowerCase();
81
+ if (name !== '' && html.charAt(index + 2 + name.length) === '>') {
82
+ const list = positions.get(name);
83
+ if (list) {
84
+ list.push(index);
85
+ }
86
+ else {
87
+ positions.set(name, [index]);
88
+ }
89
+ }
90
+ index = html.indexOf('</', index + 2);
91
+ }
92
+ return positions;
93
+ }
94
+ // The first position in the sorted list that is >= from, or -1
95
+ function firstAfter(list, from) {
96
+ if (!list) {
97
+ return -1;
98
+ }
99
+ let low = 0;
100
+ let high = list.length;
101
+ while (low < high) {
102
+ const middle = (low + high) >> 1;
103
+ if (list[middle] < from) {
104
+ low = middle + 1;
105
+ }
106
+ else {
107
+ high = middle;
108
+ }
109
+ }
110
+ return low < list.length ? list[low] : -1;
111
+ }
112
+ /**
113
+ * The index of the first `<name>` or `<name …>` tag, or -1
114
+ */
115
+ export function indexOfOpenTag(html, name) {
116
+ const prefix = '<' + name.toLowerCase();
117
+ let cursor = 0;
118
+ for (;;) {
119
+ const [start] = indexOfPrefix(html, [prefix], cursor);
120
+ if (start === -1) {
121
+ return -1;
122
+ }
123
+ const next = html.charAt(start + prefix.length);
124
+ if (next === '>') {
125
+ return start;
126
+ }
127
+ if (/\s/.test(next)) {
128
+ if (html.indexOf('>', start) === -1) {
129
+ return -1;
130
+ }
131
+ return start;
132
+ }
133
+ cursor = start + 1;
134
+ }
135
+ }
136
+ function readTagName(html, from) {
137
+ let end = from;
138
+ while (TAG_NAME.test(html.charAt(end))) {
139
+ end += 1;
140
+ }
141
+ return html.slice(from, end);
142
+ }
143
+ /**
144
+ * Replace every `<name … marker …>inner</name>` with `inner`.
145
+ * `name` null takes any tag; `keep` can refuse an element by its inner HTML.
146
+ */
147
+ export function unwrapMarkedTags(html, name, marker, keep) {
148
+ const lowerMarker = marker.toLowerCase();
149
+ const prefixes = [name == null ? '<' : '<' + name.toLowerCase()];
150
+ const closings = closingTagPositions(html);
151
+ let result = '';
152
+ let cursor = 0;
153
+ for (;;) {
154
+ const [start] = indexOfPrefix(html, prefixes, cursor);
155
+ if (start === -1) {
156
+ break;
157
+ }
158
+ const tagName = (name !== null && name !== void 0 ? name : readTagName(html, start + 1)).toLowerCase();
159
+ const gt = html.indexOf('>', start);
160
+ if (gt === -1) {
161
+ break;
162
+ }
163
+ const close = tagName !== '' &&
164
+ html.slice(start, gt).toLowerCase().includes(lowerMarker)
165
+ ? firstAfter(closings.get(tagName), gt + 1)
166
+ : -1;
167
+ // Not a marked element: the `<` is text, the next one may still open an element
168
+ if (close === -1) {
169
+ result += html.slice(cursor, start + 1);
170
+ cursor = start + 1;
171
+ continue;
172
+ }
173
+ const inner = html.slice(gt + 1, close);
174
+ const after = close + tagName.length + 3;
175
+ result += html.slice(cursor, start);
176
+ result +=
177
+ inner !== '' && (!keep || keep(inner))
178
+ ? inner
179
+ : html.slice(start, after);
180
+ cursor = after;
181
+ }
182
+ return cursor === 0 ? html : result + html.slice(cursor);
183
+ }
184
+ // The first `literal` at or after `from`, case-insensitive, or -1
185
+ function indexOfLiteral(html, literal, from) {
186
+ const head = literal.charAt(0);
187
+ let index = html.indexOf(head, from);
188
+ while (index !== -1) {
189
+ if (startsWithIgnoreCase(html, index, literal)) {
190
+ return index;
191
+ }
192
+ index = html.indexOf(head, index + 1);
193
+ }
194
+ return -1;
195
+ }
196
+ /**
197
+ * Remove every `open … openEnd … close` block whose opener holds `marker` (any opener when it is ''):
198
+ * `removeBetween(html, '<style', '>', '</style>', 'jodit-box')`
199
+ */
200
+ export function removeBetween(html, open, openEnd, close, marker = '') {
201
+ const lowerOpen = open.toLowerCase();
202
+ const lowerMarker = marker.toLowerCase();
203
+ let result = '';
204
+ let cursor = 0;
205
+ for (;;) {
206
+ const start = indexOfLiteral(html, lowerOpen, cursor);
207
+ if (start === -1) {
208
+ break;
209
+ }
210
+ const end = indexOfLiteral(html, openEnd, start + open.length);
211
+ if (end === -1) {
212
+ break;
213
+ }
214
+ if (lowerMarker !== '' &&
215
+ !html.slice(start, end).toLowerCase().includes(lowerMarker)) {
216
+ result += html.slice(cursor, end + openEnd.length);
217
+ cursor = end + openEnd.length;
218
+ continue;
219
+ }
220
+ const closeIndex = indexOfLiteral(html, close, end + openEnd.length);
221
+ if (closeIndex === -1) {
222
+ break;
223
+ }
224
+ result += html.slice(cursor, start);
225
+ cursor = closeIndex + close.length;
226
+ }
227
+ return cursor === 0 ? html : result + html.slice(cursor);
228
+ }
229
+ /**
230
+ * Remove every empty `<name … marker …></name>` element
231
+ */
232
+ export function removeEmptyMarkedTags(html, name, marker) {
233
+ const lowerName = name.toLowerCase();
234
+ const lowerMarker = marker.toLowerCase();
235
+ const closing = '</' + lowerName + '>';
236
+ let result = '';
237
+ let cursor = 0;
238
+ for (;;) {
239
+ const [start] = indexOfPrefix(html, ['<' + lowerName], cursor);
240
+ if (start === -1) {
241
+ break;
242
+ }
243
+ const gt = html.indexOf('>', start);
244
+ if (gt === -1) {
245
+ break;
246
+ }
247
+ if (html.slice(start, gt).toLowerCase().includes(lowerMarker) &&
248
+ startsWithIgnoreCase(html, gt + 1, closing)) {
249
+ result += html.slice(cursor, start);
250
+ cursor = gt + 1 + closing.length;
251
+ continue;
252
+ }
253
+ result += html.slice(cursor, gt + 1);
254
+ cursor = gt + 1;
255
+ }
256
+ return cursor === 0 ? html : result + html.slice(cursor);
257
+ }
@@ -13,3 +13,7 @@ export declare function trimChars(value: string, chars: string): string;
13
13
  * Trim only invisible chars
14
14
  */
15
15
  export declare function trimInv(value: string): string;
16
+ /**
17
+ * Without the invisible chars at the end
18
+ */
19
+ export declare function trimInvEnd(value: string): string;
@@ -6,26 +6,45 @@
6
6
  /**
7
7
  * @module helpers/string
8
8
  */
9
- import { INVISIBLE_SPACE_REG_EXP_END, INVISIBLE_SPACE_REG_EXP_START, SPACE_REG_EXP_END, SPACE_REG_EXP_START } from "../../constants.js";
9
+ const SPACE = /[\s\u200b]/;
10
+ const INVISIBLE = /\uFEFF/;
11
+ // Cut the chars matching `char` from both ends; `[…]+$` backtracks on a long run that is not at the end
12
+ function trimBy(value, char) {
13
+ let start = 0;
14
+ let end = value.length;
15
+ while (start < end && char.test(value.charAt(start))) {
16
+ start += 1;
17
+ }
18
+ while (end > start && char.test(value.charAt(end - 1))) {
19
+ end -= 1;
20
+ }
21
+ return start === 0 && end === value.length
22
+ ? value
23
+ : value.slice(start, end);
24
+ }
10
25
  /**
11
26
  * It clears the line of all auxiliary invisible characters , from the spaces and line breaks , tabs
12
27
  * from the beginning and end of the line
13
28
  */
14
29
  export function trim(value) {
15
- return value
16
- .replace(SPACE_REG_EXP_END(), '')
17
- .replace(SPACE_REG_EXP_START(), '');
30
+ return trimBy(value, SPACE);
18
31
  }
19
32
  export function trimChars(value, chars) {
20
- return value
21
- .replace(RegExp(`[${chars}]+$`), '')
22
- .replace(RegExp(`^[${chars}]+`), '');
33
+ return trimBy(value, RegExp(`[${chars}]`));
23
34
  }
24
35
  /**
25
36
  * Trim only invisible chars
26
37
  */
27
38
  export function trimInv(value) {
28
- return value
29
- .replace(INVISIBLE_SPACE_REG_EXP_END(), '')
30
- .replace(INVISIBLE_SPACE_REG_EXP_START(), '');
39
+ return trimBy(value, INVISIBLE);
40
+ }
41
+ /**
42
+ * Without the invisible chars at the end
43
+ */
44
+ export function trimInvEnd(value) {
45
+ let end = value.length;
46
+ while (end > 0 && INVISIBLE.test(value.charAt(end - 1))) {
47
+ end -= 1;
48
+ }
49
+ return end === value.length ? value : value.slice(0, end);
31
50
  }
@@ -6,8 +6,9 @@
6
6
  /**
7
7
  * @module selection
8
8
  */
9
- import { INVISIBLE_SPACE_REG_EXP_END as INV_END, INVISIBLE_SPACE_REG_EXP_START as INV_START } from "../../constants.js";
9
+ import { INVISIBLE_SPACE_REG_EXP_START as INV_START } from "../../constants.js";
10
10
  import { Dom } from "../../dom/dom.js";
11
+ import { trimInvEnd } from "../../helpers/string/trim.js";
11
12
  export * from "./composed-ranges.js";
12
13
  export * from "./is-moved.js";
13
14
  export * from "./move-node-inside-start.js";
@@ -21,7 +22,7 @@ export * from "./move-the-node-along-the-edge-outward.js";
21
22
  export function cursorInTheEdgeOfString(container, offset, start, end) {
22
23
  var _a;
23
24
  const text = ((_a = container.nodeValue) === null || _a === void 0 ? void 0 : _a.length) ? container.nodeValue : '';
24
- if (end && text.replace(INV_END(), '').length > offset) {
25
+ if (end && trimInvEnd(text).length > offset) {
25
26
  return true;
26
27
  }
27
28
  const inv = INV_START().exec(text);
@@ -15,6 +15,12 @@ export declare class UITooltip extends UIElement {
15
15
  className(): string;
16
16
  protected render(): string;
17
17
  constructor(view: IViewBased);
18
+ private get __isEnabled();
19
+ /**
20
+ * Show tooltips for the buttons in an element outside the editor's
21
+ * container, such as a toolbar placed by the `toolbar` option
22
+ */
23
+ attach(container: HTMLElement): void;
18
24
  private __attachedContainers;
19
25
  private __onAttach;
20
26
  private __listenClose;
@@ -51,9 +51,7 @@ let UITooltip = UITooltip_1 = class UITooltip extends UIElement {
51
51
  this.__currentTarget = null;
52
52
  this.__delayShowTimeout = 0;
53
53
  this.__hideTimeout = 0;
54
- if (!view.o.textIcons &&
55
- view.o.showTooltip &&
56
- !view.o.useNativeTooltip) {
54
+ if (this.__isEnabled) {
57
55
  this.j.e.on('getContainer', (box) => {
58
56
  this.__onAttach(box);
59
57
  });
@@ -62,6 +60,19 @@ let UITooltip = UITooltip_1 = class UITooltip extends UIElement {
62
60
  });
63
61
  }
64
62
  }
63
+ get __isEnabled() {
64
+ const { o } = this.j;
65
+ return !o.textIcons && Boolean(o.showTooltip) && !o.useNativeTooltip;
66
+ }
67
+ /**
68
+ * Show tooltips for the buttons in an element outside the editor's
69
+ * container, such as a toolbar placed by the `toolbar` option
70
+ */
71
+ attach(container) {
72
+ if (this.__isEnabled) {
73
+ this.__onAttach(container);
74
+ }
75
+ }
65
76
  __onAttach(container) {
66
77
  // TODO Move it inside __show method. Now it is here because testcase failed with capturing
67
78
  Dom.append(getContainer(this.j, UITooltip_1), this.container);
@@ -71,7 +71,12 @@ export class ViewWithToolbar extends View {
71
71
  const buttons = this.o.buttons
72
72
  ? splitArray(this.o.buttons)
73
73
  : [];
74
- (_a = this.toolbar) === null || _a === void 0 ? void 0 : _a.setRemoveButtons(this.o.removeButtons).build(buttons.concat(this.o.extraButtons || [])).appendTo(this.toolbarContainer);
74
+ const container = this.toolbarContainer;
75
+ (_a = this.toolbar) === null || _a === void 0 ? void 0 : _a.setRemoveButtons(this.o.removeButtons).build(buttons.concat(this.o.extraButtons || [])).appendTo(container);
76
+ // The toolbar's own element, as editors can share the one it is placed in
77
+ if (this.toolbar && !Dom.isOrContains(this.container, container)) {
78
+ this.__tooltip.attach(this.toolbar.container);
79
+ }
75
80
  }
76
81
  getRegisteredButtonGroups() {
77
82
  return this.groupToButtons;
package/esm/jodit.js CHANGED
@@ -19,6 +19,7 @@ import { FAT_MODE, IS_PROD, KEY_BACKSPACE, KEY_DELETE, KEY_ENTER, lang } from ".
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";
22
+ import { removeEmptyMarkedTags } from "./core/helpers/html/tag-scan.js";
22
23
  import { cssInline } from "./core/helpers/utils/css.js";
23
24
  import { Ajax } from "./core/request/index.js";
24
25
  import { Dlgs } from "./core/traits/dlgs.js";
@@ -409,7 +410,7 @@ let Jodit = Jodit_1 = class Jodit extends ViewWithToolbar {
409
410
  }
410
411
  value = this.getNativeEditorValue().replace(constants.INVISIBLE_SPACE_REG_EXP(), '');
411
412
  if (removeSelectionMarkers) {
412
- value = value.replace(/<span[^>]+id="jodit-selection_marker_[^>]+><\/span>/g, '');
413
+ value = removeEmptyMarkedTags(value, 'span', 'id="jodit-selection_marker_');
413
414
  }
414
415
  if (value === '<br>') {
415
416
  value = '';
@@ -29,6 +29,11 @@ export declare class addNewLine extends Plugin {
29
29
  private __canGetFocus;
30
30
  protected afterInit(editor: IJodit): void;
31
31
  private __addEventListeners;
32
+ /**
33
+ * An empty line with a `<br>`, as Enter makes, so it keeps its height
34
+ * without clean-html's fillEmptyParagraph (#1807)
35
+ */
36
+ private __newLine;
32
37
  private __onClickLine;
33
38
  /**
34
39
  * A paragraph holding only an embed has no place for the caret, so the
@@ -50,7 +50,7 @@ export class addNewLine extends Plugin {
50
50
  };
51
51
  this.__onClickLine = (e) => {
52
52
  const editor = this.j;
53
- const p = editor.createInside.element(editor.o.enter);
53
+ const p = this.__newLine();
54
54
  if (this.__isBeforeContent &&
55
55
  this.__current &&
56
56
  this.__current.parentNode) {
@@ -129,6 +129,18 @@ export class addNewLine extends Plugin {
129
129
  .on(editor.container, 'mouseleave' + '.' + ns, this.__hide)
130
130
  .on(editor.editor, 'mousemove' + '.' + ns, this.__onMouseMove);
131
131
  }
132
+ /**
133
+ * An empty line with a `<br>`, as Enter makes, so it keeps its height
134
+ * without clean-html's fillEmptyParagraph (#1807)
135
+ */
136
+ __newLine() {
137
+ const { j } = this;
138
+ const line = j.createInside.element(j.o.enter);
139
+ if (!Dom.isTag(line, 'br')) {
140
+ Dom.append(line, j.createInside.element('br'));
141
+ }
142
+ return line;
143
+ }
132
144
  /**
133
145
  * A paragraph holding only an embed has no place for the caret, so the
134
146
  * arrow keys can't get past one that ends the content, or before one that
@@ -147,6 +159,11 @@ export class addNewLine extends Plugin {
147
159
  return;
148
160
  }
149
161
  const { startContainer, startOffset } = editor.s.range;
162
+ // A caret in the editor itself, as beside a horizontal line, is in no
163
+ // paragraph, and the browsers can leave it there with text beyond (#1803)
164
+ if (startContainer === editor.editor) {
165
+ return;
166
+ }
150
167
  // Once the browser has moved the caret, if it could. With a 0 timeout
151
168
  // Jodit would run this at once, before the browser moves it
152
169
  editor.async.setTimeout(() => {
@@ -161,7 +178,7 @@ export class addNewLine extends Plugin {
161
178
  !Dom.findNotEmptyNeighbor(block, !forward, editor.editor)) {
162
179
  return;
163
180
  }
164
- const p = editor.createInside.element(editor.o.enter);
181
+ const p = this.__newLine();
165
182
  forward
166
183
  ? Dom.append(editor.editor, p)
167
184
  : Dom.prepend(editor.editor, p);
@@ -178,7 +195,7 @@ export class addNewLine extends Plugin {
178
195
  editor.s.isCollapsed()) {
179
196
  const editorBound = offset(editor.editor, editor, editor.ed);
180
197
  const top = e.pageY - editor.ew.scrollX;
181
- const p = editor.createInside.element(editor.o.enter);
198
+ const p = this.__newLine();
182
199
  if (Math.abs(top - editorBound.top) <
183
200
  Math.abs(top - (editorBound.height + editorBound.top)) &&
184
201
  editor.editor.firstChild) {
@@ -20,6 +20,13 @@ export declare class deleteCommand extends Plugin {
20
20
  */
21
21
  private __afterDeleteCommand;
22
22
  private __onDeleteCommand;
23
+ /**
24
+ * Firefox selects cells whole from their row, as after a drag into or out
25
+ * of a table nested in a cell, and `deleteContents` would remove them. The
26
+ * edges move into the cells, so their content is cleared instead, as in
27
+ * Firefox's own delete
28
+ */
29
+ private __moveEdgesIntoCells;
23
30
  /**
24
31
  * A selection that starts or ends in a table cell clears the selected part
25
32
  * of each cell it covers and keeps the cells, as the browsers do.
@@ -22,6 +22,20 @@ const KEEPS_SPACES = new Set(['pre', 'pre-wrap', 'break-spaces']);
22
22
  * A plain space beside this neighbor isn't shown: there is none, or it's a
23
23
  * line break, a block or text starting (or ending) with a plain space
24
24
  */
25
+ // The run of spaces at the end (or the start) of the text becomes nbsp; counted, as `/ +$/` backtracks on a long run
26
+ function replaceEdgeSpaces(text, atEnd) {
27
+ let count = 0;
28
+ while (count < text.length &&
29
+ text.charAt(atEnd ? text.length - 1 - count : count) === ' ') {
30
+ count += 1;
31
+ }
32
+ if (count === 0) {
33
+ return text;
34
+ }
35
+ return atEnd
36
+ ? text.slice(0, text.length - count) + NBSP_SPACE.repeat(count)
37
+ : NBSP_SPACE.repeat(count) + text.slice(count);
38
+ }
25
39
  function hidesSpace(neighbor, edge) {
26
40
  var _a;
27
41
  return (!neighbor ||
@@ -69,6 +83,7 @@ export class deleteCommand extends Plugin {
69
83
  }
70
84
  jodit.s.expandSelection();
71
85
  const range = jodit.s.range;
86
+ this.__moveEdgesIntoCells(range);
72
87
  const caret = this.__clearSelectedCells(range);
73
88
  if (caret && range.collapsed) {
74
89
  jodit.s.selectRange(caret);
@@ -90,6 +105,27 @@ export class deleteCommand extends Plugin {
90
105
  jodit.s.selectRange(caret !== null && caret !== void 0 ? caret : range);
91
106
  return false;
92
107
  }
108
+ /**
109
+ * Firefox selects cells whole from their row, as after a drag into or out
110
+ * of a table nested in a cell, and `deleteContents` would remove them. The
111
+ * edges move into the cells, so their content is cleared instead, as in
112
+ * Firefox's own delete
113
+ */
114
+ __moveEdgesIntoCells(range) {
115
+ const { startContainer, startOffset, endContainer, endOffset } = range;
116
+ const first = Dom.isTag(startContainer, 'tr')
117
+ ? startContainer.childNodes[startOffset]
118
+ : null;
119
+ const last = Dom.isTag(endContainer, 'tr')
120
+ ? endContainer.childNodes[endOffset - 1]
121
+ : null;
122
+ if (Dom.isCell(first)) {
123
+ range.setStart(first, 0);
124
+ }
125
+ if (Dom.isCell(last)) {
126
+ range.setEnd(last, last.childNodes.length);
127
+ }
128
+ }
93
129
  /**
94
130
  * A selection that starts or ends in a table cell clears the selected part
95
131
  * of each cell it covers and keeps the cells, as the browsers do.
@@ -219,10 +255,10 @@ export class deleteCommand extends Plugin {
219
255
  const before = this.__findNeighbor(fake, true, block);
220
256
  const after = this.__findNeighbor(fake, false, block);
221
257
  if (Dom.isText(before) && hidesSpace(after, /^ /)) {
222
- before.nodeValue = before.nodeValue.replace(/ +$/, spaces => NBSP_SPACE.repeat(spaces.length));
258
+ before.nodeValue = replaceEdgeSpaces(before.nodeValue, true);
223
259
  }
224
260
  if (Dom.isText(after) && hidesSpace(before, / $/)) {
225
- after.nodeValue = after.nodeValue.replace(/^ +/, spaces => NBSP_SPACE.repeat(spaces.length));
261
+ after.nodeValue = replaceEdgeSpaces(after.nodeValue, false);
226
262
  }
227
263
  }
228
264
  /**
@@ -47,6 +47,11 @@ export function hr(editor) {
47
47
  return false;
48
48
  }
49
49
  const p = editor.createInside.element(editor.o.enter);
50
+ // As Enter's new line has, so it keeps its height without clean-html's
51
+ // fillEmptyParagraph (#1807)
52
+ if (!Dom.isTag(p, 'br')) {
53
+ Dom.append(p, editor.createInside.element('br'));
54
+ }
50
55
  Dom.after(elm, p);
51
56
  editor.s.setCursorIn(p);
52
57
  return false;