suneditor 3.0.0-beta.2 → 3.0.0-beta.20

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 (177) hide show
  1. package/CONTRIBUTING.md +186 -184
  2. package/LICENSE +21 -21
  3. package/README.md +157 -180
  4. package/dist/suneditor.min.css +1 -1
  5. package/dist/suneditor.min.js +1 -1
  6. package/package.json +126 -123
  7. package/src/assets/design/color.css +131 -121
  8. package/src/assets/design/index.css +3 -3
  9. package/src/assets/design/size.css +37 -35
  10. package/src/assets/design/typography.css +37 -37
  11. package/src/assets/icons/defaultIcons.js +247 -232
  12. package/src/assets/suneditor-contents.css +779 -778
  13. package/src/assets/suneditor.css +43 -35
  14. package/src/core/base/eventHandlers/handler_toolbar.js +135 -135
  15. package/src/core/base/eventHandlers/handler_ww_clipboard.js +56 -56
  16. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +115 -113
  17. package/src/core/base/eventHandlers/handler_ww_key_input.js +1200 -1200
  18. package/src/core/base/eventHandlers/handler_ww_mouse.js +194 -194
  19. package/src/core/base/eventManager.js +1550 -1484
  20. package/src/core/base/history.js +355 -355
  21. package/src/core/class/char.js +163 -162
  22. package/src/core/class/component.js +856 -842
  23. package/src/core/class/format.js +3433 -3422
  24. package/src/core/class/html.js +1927 -1890
  25. package/src/core/class/menu.js +357 -346
  26. package/src/core/class/nodeTransform.js +424 -424
  27. package/src/core/class/offset.js +858 -891
  28. package/src/core/class/selection.js +710 -620
  29. package/src/core/class/shortcuts.js +98 -98
  30. package/src/core/class/toolbar.js +438 -430
  31. package/src/core/class/ui.js +424 -422
  32. package/src/core/class/viewer.js +750 -750
  33. package/src/core/editor.js +1810 -1708
  34. package/src/core/section/actives.js +268 -241
  35. package/src/core/section/constructor.js +1348 -1661
  36. package/src/core/section/context.js +102 -102
  37. package/src/core/section/documentType.js +582 -561
  38. package/src/core/section/options.js +367 -0
  39. package/src/core/util/instanceCheck.js +59 -0
  40. package/src/editorInjector/_classes.js +36 -36
  41. package/src/editorInjector/_core.js +92 -92
  42. package/src/editorInjector/index.js +75 -75
  43. package/src/events.js +634 -622
  44. package/src/helper/clipboard.js +59 -59
  45. package/src/helper/converter.js +586 -564
  46. package/src/helper/dom/domCheck.js +304 -304
  47. package/src/helper/dom/domQuery.js +677 -669
  48. package/src/helper/dom/domUtils.js +618 -557
  49. package/src/helper/dom/index.js +12 -12
  50. package/src/helper/env.js +249 -240
  51. package/src/helper/index.js +25 -25
  52. package/src/helper/keyCodeMap.js +183 -183
  53. package/src/helper/numbers.js +72 -72
  54. package/src/helper/unicode.js +47 -47
  55. package/src/langs/ckb.js +231 -231
  56. package/src/langs/cs.js +231 -231
  57. package/src/langs/da.js +231 -231
  58. package/src/langs/de.js +231 -231
  59. package/src/langs/en.js +230 -230
  60. package/src/langs/es.js +231 -231
  61. package/src/langs/fa.js +231 -231
  62. package/src/langs/fr.js +231 -231
  63. package/src/langs/he.js +231 -231
  64. package/src/langs/hu.js +230 -230
  65. package/src/langs/index.js +28 -28
  66. package/src/langs/it.js +231 -231
  67. package/src/langs/ja.js +230 -230
  68. package/src/langs/km.js +230 -230
  69. package/src/langs/ko.js +230 -230
  70. package/src/langs/lv.js +231 -231
  71. package/src/langs/nl.js +231 -231
  72. package/src/langs/pl.js +231 -231
  73. package/src/langs/pt_br.js +231 -231
  74. package/src/langs/ro.js +231 -231
  75. package/src/langs/ru.js +231 -231
  76. package/src/langs/se.js +231 -231
  77. package/src/langs/tr.js +231 -231
  78. package/src/langs/uk.js +231 -231
  79. package/src/langs/ur.js +231 -231
  80. package/src/langs/zh_cn.js +231 -231
  81. package/src/modules/ApiManager.js +191 -191
  82. package/src/modules/Browser.js +669 -667
  83. package/src/modules/ColorPicker.js +364 -362
  84. package/src/modules/Controller.js +474 -454
  85. package/src/modules/Figure.js +1620 -1617
  86. package/src/modules/FileManager.js +359 -359
  87. package/src/modules/HueSlider.js +577 -565
  88. package/src/modules/Modal.js +346 -346
  89. package/src/modules/ModalAnchorEditor.js +643 -643
  90. package/src/modules/SelectMenu.js +549 -549
  91. package/src/modules/_DragHandle.js +17 -17
  92. package/src/modules/index.js +14 -14
  93. package/src/plugins/browser/audioGallery.js +83 -83
  94. package/src/plugins/browser/fileBrowser.js +103 -103
  95. package/src/plugins/browser/fileGallery.js +83 -83
  96. package/src/plugins/browser/imageGallery.js +81 -81
  97. package/src/plugins/browser/videoGallery.js +103 -103
  98. package/src/plugins/command/blockquote.js +61 -60
  99. package/src/plugins/command/exportPDF.js +134 -134
  100. package/src/plugins/command/fileUpload.js +456 -456
  101. package/src/plugins/command/list_bulleted.js +149 -148
  102. package/src/plugins/command/list_numbered.js +152 -151
  103. package/src/plugins/dropdown/align.js +157 -155
  104. package/src/plugins/dropdown/backgroundColor.js +108 -104
  105. package/src/plugins/dropdown/font.js +141 -137
  106. package/src/plugins/dropdown/fontColor.js +109 -105
  107. package/src/plugins/dropdown/formatBlock.js +170 -178
  108. package/src/plugins/dropdown/hr.js +152 -152
  109. package/src/plugins/dropdown/layout.js +83 -83
  110. package/src/plugins/dropdown/lineHeight.js +131 -130
  111. package/src/plugins/dropdown/list.js +123 -122
  112. package/src/plugins/dropdown/paragraphStyle.js +138 -138
  113. package/src/plugins/dropdown/table.js +4110 -4000
  114. package/src/plugins/dropdown/template.js +83 -83
  115. package/src/plugins/dropdown/textStyle.js +149 -149
  116. package/src/plugins/field/mention.js +242 -242
  117. package/src/plugins/index.js +120 -120
  118. package/src/plugins/input/fontSize.js +414 -410
  119. package/src/plugins/input/pageNavigator.js +71 -70
  120. package/src/plugins/modal/audio.js +677 -677
  121. package/src/plugins/modal/drawing.js +537 -531
  122. package/src/plugins/modal/embed.js +886 -886
  123. package/src/plugins/modal/image.js +1377 -1376
  124. package/src/plugins/modal/link.js +248 -240
  125. package/src/plugins/modal/math.js +563 -563
  126. package/src/plugins/modal/video.js +1226 -1226
  127. package/src/plugins/popup/anchor.js +224 -222
  128. package/src/suneditor.js +114 -107
  129. package/src/themes/dark.css +132 -122
  130. package/src/typedef.js +132 -130
  131. package/types/assets/icons/defaultIcons.d.ts +8 -0
  132. package/types/core/base/eventManager.d.ts +29 -4
  133. package/types/core/class/char.d.ts +2 -1
  134. package/types/core/class/component.d.ts +1 -2
  135. package/types/core/class/format.d.ts +8 -1
  136. package/types/core/class/html.d.ts +8 -0
  137. package/types/core/class/menu.d.ts +8 -0
  138. package/types/core/class/offset.d.ts +24 -26
  139. package/types/core/class/selection.d.ts +2 -0
  140. package/types/core/class/toolbar.d.ts +6 -0
  141. package/types/core/class/ui.d.ts +1 -1
  142. package/types/core/editor.d.ts +34 -12
  143. package/types/core/section/constructor.d.ts +5 -638
  144. package/types/core/section/documentType.d.ts +12 -2
  145. package/types/core/section/options.d.ts +740 -0
  146. package/types/core/util/instanceCheck.d.ts +50 -0
  147. package/types/editorInjector/_core.d.ts +5 -5
  148. package/types/editorInjector/index.d.ts +2 -2
  149. package/types/events.d.ts +2 -0
  150. package/types/helper/converter.d.ts +9 -0
  151. package/types/helper/dom/domQuery.d.ts +5 -5
  152. package/types/helper/dom/domUtils.d.ts +8 -0
  153. package/types/helper/env.d.ts +6 -1
  154. package/types/helper/index.d.ts +4 -1
  155. package/types/index.d.ts +122 -120
  156. package/types/langs/_Lang.d.ts +194 -194
  157. package/types/modules/ColorPicker.d.ts +5 -1
  158. package/types/modules/Controller.d.ts +8 -4
  159. package/types/modules/Figure.d.ts +2 -1
  160. package/types/modules/HueSlider.d.ts +4 -1
  161. package/types/modules/SelectMenu.d.ts +1 -1
  162. package/types/plugins/command/blockquote.d.ts +1 -0
  163. package/types/plugins/command/list_bulleted.d.ts +1 -0
  164. package/types/plugins/command/list_numbered.d.ts +1 -0
  165. package/types/plugins/dropdown/align.d.ts +1 -0
  166. package/types/plugins/dropdown/backgroundColor.d.ts +1 -0
  167. package/types/plugins/dropdown/font.d.ts +1 -0
  168. package/types/plugins/dropdown/fontColor.d.ts +1 -0
  169. package/types/plugins/dropdown/formatBlock.d.ts +3 -2
  170. package/types/plugins/dropdown/lineHeight.d.ts +1 -0
  171. package/types/plugins/dropdown/list.d.ts +1 -0
  172. package/types/plugins/dropdown/table.d.ts +6 -0
  173. package/types/plugins/input/fontSize.d.ts +1 -0
  174. package/types/plugins/modal/drawing.d.ts +4 -0
  175. package/types/plugins/modal/link.d.ts +32 -15
  176. package/types/suneditor.d.ts +13 -9
  177. package/types/typedef.d.ts +8 -0
@@ -1,1200 +1,1200 @@
1
- import { dom, env, unicode, keyCodeMap } from '../../../helper';
2
-
3
- const { _w, isOSX_IOS } = env;
4
- const FRONT_ZEROWIDTH = new RegExp(unicode.zeroWidthSpace + '+', '');
5
-
6
- const keyState = {
7
- ctrl: false,
8
- alt: false
9
- };
10
- let _styleNodes = null;
11
-
12
- /**
13
- * @typedef {Omit<import('../eventManager').default & Partial<__se__EditorInjector>, 'eventManager'>} EventManagerThis_handler_ww_key_input
14
- */
15
-
16
- /**
17
- * @private
18
- * @param {HTMLElement} formatEl - Format element
19
- * @returns {Node}
20
- */
21
- function LineDelete_next(formatEl) {
22
- const focusNode = formatEl.lastChild;
23
- const next = formatEl.nextElementSibling;
24
-
25
- if (!next) return focusNode;
26
-
27
- if (dom.check.isZeroWidth(next)) {
28
- dom.utils.removeItem(next);
29
- return focusNode;
30
- }
31
-
32
- const nextChild = next.childNodes;
33
- while (nextChild[0]) {
34
- formatEl.appendChild(nextChild[0]);
35
- }
36
-
37
- dom.utils.removeItem(next);
38
-
39
- return focusNode;
40
- }
41
-
42
- /**
43
- * @private
44
- * @param {HTMLElement} formatEl - Format element
45
- * @returns {{focusNode: Node, focusOffset: number}}
46
- */
47
- function LineDelete_prev(formatEl) {
48
- const formatChild = formatEl.childNodes;
49
- const prev = formatEl.previousElementSibling;
50
- let focusNode = formatChild[0];
51
- let focusOffset = 0;
52
-
53
- if (!prev) return { focusNode, focusOffset };
54
-
55
- if (dom.check.isZeroWidth(prev)) {
56
- dom.utils.removeItem(prev);
57
- return { focusNode, focusOffset };
58
- }
59
-
60
- if (formatChild.length > 1 || formatChild[0]?.textContent.length > 0) {
61
- while (formatChild[0]) {
62
- prev.appendChild(formatChild[0]);
63
- }
64
- } else {
65
- focusNode = prev.lastChild;
66
- focusOffset = focusNode.textContent.length;
67
- }
68
-
69
- dom.utils.removeItem(formatEl);
70
-
71
- return { focusNode, focusOffset };
72
- }
73
-
74
- /**
75
- * @private
76
- * @this {EventManagerThis_handler_ww_key_input}
77
- * @param {__se__FrameContext} fc - Frame context object
78
- * @param {InputEvent} e - Event object
79
- */
80
- export async function OnInput_wysiwyg(fc, e) {
81
- if (fc.get('isReadOnly') || fc.get('isDisabled')) {
82
- e.preventDefault();
83
- e.stopPropagation();
84
- return false;
85
- }
86
-
87
- const range = this.selection.getRange();
88
- const selectionNode = this.selection.getNode();
89
- const formatEl = this.format.getLine(selectionNode, null);
90
- if (!formatEl && range.collapsed && !this.component.is(selectionNode) && !dom.check.isList(selectionNode)) {
91
- const rangeEl = this.format.getBlock(selectionNode, null);
92
- this._setDefaultLine(this.format.isBlock(rangeEl) ? 'DIV' : this.options.get('defaultLine'));
93
- }
94
-
95
- this.selection._init();
96
-
97
- const data = (e.data === null ? '' : e.data === undefined ? ' ' : e.data) || '';
98
- if (!this.char.test(data, true)) {
99
- e.preventDefault();
100
- e.stopPropagation();
101
- return false;
102
- }
103
-
104
- // user event
105
- if ((await this.triggerEvent('onInput', { frameContext: fc, event: e, data })) === false) return;
106
- // plugin event
107
- if (this._callPluginEvent('onInput', { frameContext: fc, event: e, data }) === false) return;
108
-
109
- this.history.push(true);
110
- }
111
-
112
- /**
113
- * @private
114
- * @this {EventManagerThis_handler_ww_key_input}
115
- * @param {__se__FrameContext} fc - Frame context object
116
- * @param {KeyboardEvent} e - Event object
117
- */
118
- export async function OnKeyDown_wysiwyg(fc, e) {
119
- if (this.editor.selectMenuOn || !e.isTrusted) return;
120
-
121
- let selectionNode = this.selection.getNode();
122
- if (dom.check.isInputElement(selectionNode)) return;
123
- if (this.menu.currentDropdownName) return;
124
-
125
- const keyCode = e.code;
126
- const shift = keyCodeMap.isShift(e);
127
- const ctrl = (keyState.ctrl = keyCodeMap.isCtrl(e));
128
- const alt = (keyState.alt = keyCodeMap.isAlt(e));
129
- this.isComposing = keyCodeMap.isComposing(e);
130
-
131
- if (!ctrl && fc.get('isReadOnly') && !keyCodeMap.isDirectionKey(keyCode)) {
132
- e.preventDefault();
133
- return false;
134
- }
135
-
136
- this.menu.dropdownOff();
137
-
138
- if (this.editor.isBalloon) {
139
- this._hideToolbar();
140
- } else if (this.editor.isSubBalloon) {
141
- this._hideToolbar_sub();
142
- }
143
-
144
- // user event
145
- if ((await this.triggerEvent('onKeyDown', { frameContext: fc, event: e })) === false) return;
146
-
147
- /** default key action */
148
- if (keyCodeMap.isEnter(keyCode) && this.format.isLine(this.selection.getRange()?.startContainer)) {
149
- this.selection._resetRangeToTextNode();
150
- selectionNode = this.selection.getNode();
151
- }
152
-
153
- const range = this.selection.getRange();
154
- const selectRange = !range.collapsed || range.startContainer !== range.endContainer;
155
- let formatEl = /** @type {HTMLElement} */ (this.format.getLine(selectionNode, null) || selectionNode);
156
- let rangeEl = this.format.getBlock(formatEl, null);
157
-
158
- /** Shortcuts */
159
- if (ctrl && !keyCodeMap.isNonTextKey(keyCode) && this.shortcuts.command(e, ctrl, shift, keyCode, '', false, null, null)) {
160
- this._onShortcutKey = true;
161
- e.preventDefault();
162
- e.stopPropagation();
163
- return false;
164
- } else if (!ctrl && !keyCodeMap.isNonTextKey(keyCode) && this.format.isLine(formatEl) && range.collapsed && dom.check.isEdgePoint(range.startContainer, 0, 'front')) {
165
- const keyword = /** @type {Text} */ (range.startContainer).substringData?.(0, range.startOffset);
166
- if (keyword && this.shortcuts.command(e, false, shift, keyCode, keyword, true, formatEl, range)) {
167
- this._onShortcutKey = true;
168
- e.preventDefault();
169
- e.stopPropagation();
170
- return false;
171
- }
172
- } else if (this._onShortcutKey) {
173
- this._onShortcutKey = false;
174
- }
175
-
176
- // plugin event
177
- if (this._callPluginEvent('onKeyDown', { frameContext: fc, event: e, range, line: formatEl }) === false) return;
178
-
179
- switch (keyCode) {
180
- case 'Backspace' /** backspace key */: {
181
- this.component.deselect();
182
- _styleNodes = this.__cacheStyleNodes;
183
- if (selectRange && this._hardDelete()) {
184
- e.preventDefault();
185
- e.stopPropagation();
186
- break;
187
- }
188
-
189
- if (!this.format.isLine(formatEl) && !fc.get('wysiwyg').firstElementChild && !this.component.is(selectionNode) && this._setDefaultLine(this.options.get('defaultLine')) !== null) {
190
- e.preventDefault();
191
- e.stopPropagation();
192
- return false;
193
- }
194
-
195
- // line delete
196
- if (this.format.isLine(formatEl) && (!range.collapsed || dom.check.isEdgePoint(range.endContainer, range.endOffset, 'front')) && !range.endContainer.previousSibling && this.format.isLine(formatEl.previousElementSibling)) {
197
- e.preventDefault();
198
- e.stopPropagation();
199
-
200
- let focusNode;
201
- if (!range.collapsed) {
202
- const rInfo = this.html.remove();
203
- if (rInfo.commonCon !== rInfo.container && formatEl.parentElement) {
204
- if (formatEl.contains(range.startContainer)) {
205
- focusNode = LineDelete_next(formatEl);
206
- this.selection.setRange(focusNode, focusNode.textContent.length, focusNode, focusNode.textContent.length);
207
- } else {
208
- const prevInfo = LineDelete_prev(formatEl);
209
- this.selection.setRange(prevInfo.focusNode, prevInfo.focusOffset, prevInfo.focusNode, prevInfo.focusOffset);
210
- }
211
- }
212
- this.history.push(true);
213
- return;
214
- }
215
-
216
- const prevInfo = LineDelete_prev(formatEl);
217
- this.selection.setRange(prevInfo.focusNode, prevInfo.focusOffset, prevInfo.focusNode, prevInfo.focusOffset);
218
- this.history.push(true);
219
-
220
- return;
221
- }
222
-
223
- if (
224
- !selectRange &&
225
- !formatEl.previousElementSibling &&
226
- range.startOffset === 0 &&
227
- !selectionNode.previousSibling &&
228
- !dom.check.isListCell(formatEl) &&
229
- this.format.isLine(formatEl) &&
230
- (!this.format.isBrLine(formatEl) || this.format.isClosureBrLine(formatEl))
231
- ) {
232
- // closure range
233
- if (this.format.isClosureBlock(formatEl.parentNode)) {
234
- e.preventDefault();
235
- e.stopPropagation();
236
- return false;
237
- }
238
- // maintain default format
239
- if (dom.check.isWysiwygFrame(formatEl.parentNode) && formatEl.childNodes.length <= 1 && (!formatEl.firstChild || dom.check.isZeroWidth(formatEl.textContent))) {
240
- e.preventDefault();
241
- e.stopPropagation();
242
-
243
- if (formatEl.nodeName.toUpperCase() === this.options.get('defaultLine').toUpperCase()) {
244
- formatEl.innerHTML = '<br>';
245
- const attrs = formatEl.attributes;
246
- while (attrs[0]) {
247
- formatEl.removeAttribute(attrs[0].name);
248
- }
249
- } else {
250
- formatEl.parentNode.replaceChild(dom.utils.createElement(this.options.get('defaultLine'), null, '<br>'), formatEl);
251
- }
252
-
253
- this.editor._nativeFocus();
254
- return false;
255
- }
256
- }
257
-
258
- // clean remove tag
259
- const startCon = range.startContainer;
260
- if (formatEl && !formatEl.previousElementSibling && range.startOffset === 0 && startCon.nodeType === 3 && dom.check.isZeroWidth(startCon)) {
261
- let prev = startCon.parentNode.previousSibling;
262
- const next = startCon.parentNode.nextSibling;
263
- if (!prev) {
264
- if (!next) {
265
- prev = dom.utils.createElement('BR');
266
- formatEl.appendChild(prev);
267
- } else {
268
- prev = next;
269
- }
270
- }
271
-
272
- let con = startCon;
273
- while (formatEl.contains(con) && !con.previousSibling) {
274
- con = con.parentNode;
275
- }
276
-
277
- if (!formatEl.contains(con)) {
278
- startCon.textContent = '';
279
- this.nodeTransform.removeAllParents(startCon, null, formatEl);
280
- break;
281
- }
282
- }
283
-
284
- // line component
285
- if (!selectRange && formatEl && (range.startOffset === 0 || selectionNode === formatEl)) {
286
- const sel = selectionNode === formatEl ? this._isUneditableNode(range, true) : dom.check.isEdgePoint(range.startContainer, range.startOffset) ? dom.query.getPreviousDeepestNode(range.startContainer) : null;
287
- if (this.component.is(sel)) {
288
- const fileComponentInfo = this.component.get(sel);
289
- if (fileComponentInfo) {
290
- e.preventDefault();
291
- e.stopPropagation();
292
- if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
293
- break;
294
- }
295
- }
296
- }
297
-
298
- // tag[contenteditable='false']
299
- if (this._isUneditableNode(range, true)) {
300
- e.preventDefault();
301
- e.stopPropagation();
302
- break;
303
- }
304
-
305
- // format attributes
306
- if (!selectRange && this.format.isEdgeLine(range.startContainer, range.startOffset, 'front')) {
307
- if (this.format.isLine(formatEl.previousElementSibling)) {
308
- this._formatAttrsTemp = formatEl.previousElementSibling.attributes;
309
- }
310
- }
311
-
312
- // nested list
313
- const commonCon = range.commonAncestorContainer;
314
- formatEl = this.format.getLine(range.startContainer, null);
315
- rangeEl = this.format.getBlock(formatEl, null);
316
- if (rangeEl && formatEl && !dom.check.isTableCell(rangeEl) && !/^FIGCAPTION$/i.test(rangeEl.nodeName)) {
317
- if (
318
- dom.check.isListCell(formatEl) &&
319
- dom.check.isList(rangeEl) &&
320
- (dom.check.isListCell(rangeEl.parentElement) || formatEl.previousElementSibling) &&
321
- (selectionNode === formatEl || (selectionNode.nodeType === 3 && (!selectionNode.previousSibling || dom.check.isList(selectionNode.previousSibling)))) &&
322
- (this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null) ? rangeEl.contains(range.startContainer) : range.startOffset === 0 && range.collapsed)
323
- ) {
324
- if (range.startContainer !== range.endContainer) {
325
- e.preventDefault();
326
-
327
- this.html.remove();
328
- if (range.startContainer.nodeType === 3) {
329
- this.selection.setRange(range.startContainer, range.startContainer.textContent.length, range.startContainer, range.startContainer.textContent.length);
330
- }
331
-
332
- this.history.push(true);
333
- } else {
334
- let prev = formatEl.previousElementSibling || rangeEl.parentElement;
335
- if (dom.check.isListCell(prev)) {
336
- e.preventDefault();
337
-
338
- let prevLast = prev;
339
- if (!prev.contains(formatEl) && dom.check.isListCell(prevLast) && dom.check.isList(prevLast.lastElementChild)) {
340
- prevLast = /** @type {HTMLLIElement} */ (prevLast.lastElementChild.lastElementChild);
341
- while (dom.check.isListCell(prevLast) && dom.check.isList(prevLast.lastElementChild)) {
342
- prevLast = /** @type {HTMLLIElement} */ (prevLast.lastElementChild && prevLast.lastElementChild.lastElementChild);
343
- }
344
- prev = prevLast;
345
- }
346
-
347
- let con = prev === rangeEl.parentNode ? rangeEl.previousSibling : prev.lastChild;
348
- if (!con) {
349
- con = dom.utils.createTextNode(unicode.zeroWidthSpace);
350
- rangeEl.parentNode.insertBefore(con, rangeEl.parentNode.firstChild);
351
- }
352
- const offset = con.nodeType === 3 ? con.textContent.length : 1;
353
- const children = formatEl.childNodes;
354
- let after = con;
355
- let child = children[0];
356
- while ((child = children[0])) {
357
- prev.insertBefore(child, after.nextSibling);
358
- after = child;
359
- }
360
-
361
- dom.utils.removeItem(formatEl);
362
- if (rangeEl.children.length === 0) dom.utils.removeItem(rangeEl);
363
-
364
- this.selection.setRange(con, offset, con, offset);
365
- this.history.push(true);
366
- }
367
- }
368
-
369
- break;
370
- }
371
-
372
- // detach range
373
- if (!selectRange && range.startOffset === 0) {
374
- let detach = true;
375
- let comm = commonCon;
376
- while (comm && comm !== rangeEl && !dom.check.isWysiwygFrame(comm)) {
377
- if (comm.previousSibling) {
378
- if (comm.previousSibling.nodeType === 1 || !dom.check.isZeroWidth(comm.previousSibling.textContent.trim())) {
379
- detach = false;
380
- break;
381
- }
382
- }
383
- comm = comm.parentNode;
384
- }
385
-
386
- if (detach && rangeEl.parentNode) {
387
- e.preventDefault();
388
- this.format.removeBlock(rangeEl, { selectedFormats: dom.check.isListCell(formatEl) ? [formatEl] : null, newBlockElement: null, shouldDelete: false, skipHistory: false });
389
- this.history.push(true);
390
- break;
391
- }
392
- }
393
- }
394
-
395
- // component
396
- if (!selectRange && formatEl && (range.startOffset === 0 || (selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : false))) {
397
- const sel = selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : selectionNode;
398
- const prev = formatEl.previousSibling;
399
- // select file component
400
- const ignoreZWS = (commonCon.nodeType === 3 || dom.check.isBreak(commonCon)) && !commonCon.previousSibling && range.startOffset === 0;
401
- if (sel && !sel.previousSibling && ((commonCon && this.component.is(commonCon.previousSibling)) || (ignoreZWS && this.component.is(prev)))) {
402
- const fileComponentInfo = this.component.get(prev);
403
- if (fileComponentInfo) {
404
- e.preventDefault();
405
- e.stopPropagation();
406
- if (formatEl.textContent.length === 0) dom.utils.removeItem(formatEl);
407
- if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
408
- } else if (this.component.is(prev)) {
409
- e.preventDefault();
410
- e.stopPropagation();
411
- dom.utils.removeItem(prev);
412
- }
413
- break;
414
- }
415
- // delete nonEditable
416
- if (sel && dom.check.isNonEditable(sel.previousSibling)) {
417
- e.preventDefault();
418
- e.stopPropagation();
419
- dom.utils.removeItem(sel.previousSibling);
420
- break;
421
- }
422
- }
423
-
424
- break;
425
- }
426
- case 'Delete' /** delete key */: {
427
- this.component.deselect();
428
- _styleNodes = this.__cacheStyleNodes;
429
- if (selectRange && this._hardDelete()) {
430
- e.preventDefault();
431
- e.stopPropagation();
432
- break;
433
- }
434
-
435
- if (!selectRange && this.format.isEdgeLine(range.endContainer, range.endOffset, 'end') && !formatEl.nextSibling) {
436
- e.preventDefault();
437
- e.stopPropagation();
438
- return;
439
- }
440
-
441
- // line delete
442
- if (this.format.isLine(formatEl) && (!range.collapsed || dom.check.isEdgePoint(range.startContainer, range.endOffset, 'end')) && !range.startContainer.nextSibling && this.format.isLine(formatEl.nextElementSibling)) {
443
- e.preventDefault();
444
- e.stopPropagation();
445
-
446
- let focusNode;
447
- if (!range.collapsed) {
448
- const rInfo = this.html.remove();
449
- if (rInfo.commonCon !== rInfo.container && formatEl.parentElement) {
450
- if (formatEl.contains(range.startContainer)) {
451
- focusNode = LineDelete_next(formatEl);
452
- this.selection.setRange(focusNode, focusNode.textContent.length, focusNode, focusNode.textContent.length);
453
- } else {
454
- const prevInfo = LineDelete_prev(formatEl);
455
- this.selection.setRange(prevInfo.focusNode, prevInfo.focusOffset, prevInfo.focusNode, prevInfo.focusOffset);
456
- }
457
- }
458
- this.history.push(true);
459
- return;
460
- }
461
-
462
- LineDelete_next(formatEl);
463
- this.history.push(true);
464
-
465
- return;
466
- }
467
-
468
- // line component
469
- if (!selectRange && formatEl && (range.endOffset === range.endContainer.textContent.length || selectionNode === formatEl)) {
470
- const sel = selectionNode === formatEl ? this._isUneditableNode(range, false) : dom.check.isEdgePoint(range.endContainer, range.endOffset) ? dom.query.getNextDeepestNode(range.endContainer, null) : null;
471
- if (this.component.is(sel)) {
472
- const fileComponentInfo = this.component.get(sel);
473
- if (fileComponentInfo) {
474
- e.preventDefault();
475
- e.stopPropagation();
476
- if (dom.check.isZeroWidth(formatEl.textContent)) dom.utils.removeItem(formatEl);
477
- if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
478
- break;
479
- }
480
- }
481
- }
482
-
483
- // tag[contenteditable='false']
484
- if (this._isUneditableNode(range, false)) {
485
- e.preventDefault();
486
- e.stopPropagation();
487
- break;
488
- }
489
-
490
- // component
491
- if (
492
- (this.format.isLine(selectionNode) || selectionNode.nextSibling === null || (dom.check.isZeroWidth(selectionNode.nextSibling) && selectionNode.nextSibling.nextSibling === null)) &&
493
- range.startOffset === selectionNode.textContent.length
494
- ) {
495
- const nextEl = formatEl.nextElementSibling;
496
- if (!nextEl) break;
497
- if (this.component.is(nextEl)) {
498
- e.preventDefault();
499
-
500
- if (dom.check.isZeroWidth(formatEl)) {
501
- dom.utils.removeItem(formatEl);
502
- // table component
503
- if (dom.check.isTable(nextEl)) {
504
- let cell = /** @type {HTMLElement} */ (dom.query.getEdgeChild(nextEl, dom.check.isTableCell, false));
505
- cell = /** @type {HTMLElement} */ (cell.firstElementChild || cell);
506
- this.selection.setRange(cell, 0, cell, 0);
507
- break;
508
- }
509
- }
510
-
511
- // select file component
512
- const fileComponentInfo = this.component.get(nextEl);
513
- if (fileComponentInfo) {
514
- e.stopPropagation();
515
- if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
516
- } else if (this.component.is(nextEl)) {
517
- e.stopPropagation();
518
- dom.utils.removeItem(nextEl);
519
- }
520
-
521
- break;
522
- }
523
- }
524
-
525
- if (!selectRange && (dom.check.isEdgePoint(range.endContainer, range.endOffset) || (selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : false))) {
526
- const sel = selectionNode === formatEl ? formatEl.childNodes[range.startOffset] || selectionNode : selectionNode;
527
- // delete nonEditable
528
- if (sel && dom.check.isNonEditable(sel.nextSibling)) {
529
- e.preventDefault();
530
- e.stopPropagation();
531
- dom.utils.removeItem(sel.nextSibling);
532
- break;
533
- } else if (this.component.is(sel)) {
534
- e.preventDefault();
535
- e.stopPropagation();
536
- dom.utils.removeItem(sel);
537
- break;
538
- }
539
- }
540
-
541
- // format attributes
542
- if (!selectRange && this.format.isEdgeLine(range.endContainer, range.endOffset, 'end')) {
543
- if (this.format.isLine(formatEl.nextElementSibling)) {
544
- this._formatAttrsTemp = formatEl.attributes;
545
- }
546
- }
547
-
548
- // nested list
549
- formatEl = this.format.getLine(range.startContainer, null);
550
- rangeEl = this.format.getBlock(formatEl, null);
551
- if (
552
- dom.check.isListCell(formatEl) &&
553
- dom.check.isList(rangeEl) &&
554
- (selectionNode === formatEl ||
555
- (selectionNode.nodeType === 3 &&
556
- (!selectionNode.nextSibling || dom.check.isList(selectionNode.nextSibling)) &&
557
- (this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null) ? rangeEl.contains(range.endContainer) : range.endOffset === selectionNode.textContent.length && range.collapsed)))
558
- ) {
559
- if (range.startContainer !== range.endContainer) this.html.remove();
560
-
561
- const next = /** @type {HTMLElement} */ (dom.utils.arrayFind(formatEl.children, dom.check.isList) || formatEl.nextElementSibling || rangeEl.parentElement.nextElementSibling);
562
- if (next && (dom.check.isList(next) || dom.utils.arrayFind(next.children, dom.check.isList))) {
563
- e.preventDefault();
564
-
565
- let con, children;
566
- if (dom.check.isList(next)) {
567
- const child = next.firstElementChild;
568
- children = child.childNodes;
569
- con = children[0];
570
- while (children[0]) {
571
- formatEl.insertBefore(children[0], next);
572
- }
573
- dom.utils.removeItem(child);
574
- } else {
575
- con = next.firstChild;
576
- children = next.childNodes;
577
- while (children[0]) {
578
- formatEl.appendChild(children[0]);
579
- }
580
- dom.utils.removeItem(next);
581
- }
582
- this.selection.setRange(con, 0, con, 0);
583
- this.history.push(true);
584
- }
585
- break;
586
- }
587
-
588
- break;
589
- }
590
- case 'Tab' /** tab key */: {
591
- if (this.options.get('tabDisable')) break;
592
- e.preventDefault();
593
- if (ctrl || alt || dom.check.isWysiwygFrame(selectionNode)) break;
594
-
595
- const isEdge = !range.collapsed || dom.check.isEdgePoint(range.startContainer, range.startOffset);
596
- const selectedFormats = this.format.getLines(null);
597
- selectionNode = this.selection.getNode();
598
- const cells = [];
599
- const lines = [];
600
- const firstCell = dom.check.isListCell(selectedFormats[0]),
601
- lastCell = dom.check.isListCell(selectedFormats[selectedFormats.length - 1]);
602
- let r = {
603
- sc: range.startContainer,
604
- so: range.startOffset,
605
- ec: range.endContainer,
606
- eo: range.endOffset
607
- };
608
- for (let i = 0, len = selectedFormats.length, f; i < len; i++) {
609
- f = selectedFormats[i];
610
- if (dom.check.isListCell(f)) {
611
- if (!f.previousElementSibling && !shift) {
612
- continue;
613
- } else {
614
- cells.push(f);
615
- }
616
- } else {
617
- lines.push(f);
618
- }
619
- }
620
-
621
- // Nested list
622
- if (cells.length > 0 && isEdge) {
623
- r = this.format._applyNestedList(cells, shift);
624
- }
625
-
626
- // Lines tab
627
- if (lines.length > 0) {
628
- if (!shift) {
629
- if (lines.length === 1) {
630
- let tabSize = this.status.tabSize + 1;
631
- if (this.options.get('syncTabIndent')) {
632
- const baseIndex = dom.query.findTextIndexOnLine(formatEl, range.startContainer, range.startOffset, this.component.is.bind(this.component));
633
- const prevTabEndIndex = this.format.isLine(formatEl.previousElementSibling) ? dom.query.findTabEndIndex(formatEl.previousElementSibling, baseIndex, 2) : 0;
634
- if (prevTabEndIndex > baseIndex) {
635
- tabSize = prevTabEndIndex - baseIndex + 1;
636
- }
637
- }
638
-
639
- const tabText = dom.utils.createTextNode(new Array(tabSize).join('\u00A0'));
640
- if (!this.html.insertNode(tabText, { afterNode: null, skipCharCount: false })) return false;
641
- if (!firstCell) {
642
- r.sc = tabText;
643
- r.so = tabText.length;
644
- }
645
- if (!lastCell) {
646
- r.ec = tabText;
647
- r.eo = tabText.length;
648
- }
649
- } else {
650
- const tabText = dom.utils.createTextNode(new Array(this.status.tabSize + 1).join('\u00A0'));
651
- const len = lines.length - 1;
652
- for (let i = 0, child; i <= len; i++) {
653
- child = lines[i].firstChild;
654
- if (!child) continue;
655
-
656
- if (dom.check.isBreak(child)) {
657
- lines[i].insertBefore(tabText.cloneNode(false), child);
658
- } else {
659
- child.textContent = tabText.textContent + child.textContent;
660
- }
661
- }
662
-
663
- const firstChild = dom.query.getEdgeChild(lines[0], 'text', false);
664
- const endChild = dom.query.getEdgeChild(lines[len], 'text', true);
665
- if (!firstCell && firstChild) {
666
- r.sc = firstChild;
667
- r.so = 0;
668
- }
669
- if (!lastCell && endChild) {
670
- r.ec = endChild;
671
- r.eo = endChild.textContent.length;
672
- }
673
- }
674
- } else {
675
- const len = lines.length - 1;
676
- for (let i = 0, line; i <= len; i++) {
677
- line = lines[i].childNodes;
678
- for (let c = 0, cLen = line.length, child; c < cLen; c++) {
679
- child = line[c];
680
- if (!child) break;
681
- if (dom.check.isZeroWidth(child)) continue;
682
-
683
- if (/^\s{1,4}$/.test(child.textContent)) {
684
- dom.utils.removeItem(child);
685
- } else if (/^\s{1,4}/.test(child.textContent)) {
686
- child.textContent = child.textContent.replace(/^\s{1,4}/, '');
687
- }
688
-
689
- break;
690
- }
691
- }
692
-
693
- const firstChild = dom.query.getEdgeChild(lines[0], 'text', false);
694
- const endChild = dom.query.getEdgeChild(lines[len], 'text', true);
695
- if (!firstCell && firstChild) {
696
- r.sc = firstChild;
697
- r.so = 0;
698
- }
699
- if (!lastCell && endChild) {
700
- r.ec = endChild;
701
- r.eo = endChild.textContent.length;
702
- }
703
- }
704
- }
705
-
706
- this.selection.setRange(r.sc, r.so, r.ec, r.eo);
707
- this.history.push(false);
708
-
709
- break;
710
- }
711
- case 'Enter' /** enter key */: {
712
- this.component.deselect();
713
- const brBlock = this.format.getBrLine(selectionNode, null);
714
-
715
- if (this.editor.frameOptions.get('charCounter_type') === 'byte-html') {
716
- let enterHTML = '';
717
- if ((!shift && brBlock) || shift) {
718
- enterHTML = '<br>';
719
- } else {
720
- enterHTML = '<' + formatEl.nodeName + '><br></' + formatEl.nodeName + '>';
721
- }
722
-
723
- if (!this.char.check(enterHTML)) {
724
- e.preventDefault();
725
- return false;
726
- }
727
- }
728
-
729
- if (!shift) {
730
- const formatEndEdge = !range.endContainer.nextSibling && this.format.isEdgeLine(range.endContainer, range.endOffset, 'end');
731
- const formatStartEdge = !range.startContainer.previousSibling && this.format.isEdgeLine(range.startContainer, range.startOffset, 'front');
732
-
733
- // add default format line
734
- if (formatEndEdge && (/^H[1-6]$/i.test(formatEl.nodeName) || /^HR$/i.test(formatEl.nodeName))) {
735
- this.__enterPrevent(e);
736
- const newFormat = this.format.addLine(formatEl, this.options.get('defaultLine'));
737
- const temp = newFormat.firstChild;
738
- if (dom.check.isBreak(temp)) {
739
- const zeroWidth = dom.utils.createTextNode(unicode.zeroWidthSpace);
740
- temp.parentNode.insertBefore(zeroWidth, temp);
741
- this.selection.setRange(zeroWidth, 1, zeroWidth, 1);
742
- } else {
743
- this.selection.setRange(temp, 0, temp, 0);
744
- }
745
-
746
- // enter scroll
747
- this.__enterScrollTo(range);
748
- break;
749
- } else if (rangeEl && formatEl && !dom.check.isTableCell(rangeEl) && !/^FIGCAPTION$/i.test(rangeEl.nodeName)) {
750
- const rangeEnt = this.selection.getRange();
751
- if (dom.check.isEdgePoint(rangeEnt.endContainer, rangeEnt.endOffset) && dom.check.isList(selectionNode.nextSibling)) {
752
- this.__enterPrevent(e);
753
- const br = dom.utils.createElement('BR');
754
- const newEl = dom.utils.createElement('LI', null, br);
755
-
756
- formatEl.parentNode.insertBefore(newEl, formatEl.nextElementSibling);
757
- newEl.appendChild(selectionNode.nextSibling);
758
-
759
- this.selection.setRange(br, 1, br, 1);
760
-
761
- // enter scroll
762
- this.__enterScrollTo(range);
763
- break;
764
- }
765
-
766
- if (
767
- (rangeEnt.commonAncestorContainer.nodeType === 3 ? !(/** @type {HTMLElement} */ (rangeEnt.commonAncestorContainer).nextElementSibling) : true) &&
768
- dom.check.isZeroWidth(formatEl.innerText.trim()) &&
769
- !dom.check.isListCell(formatEl.nextElementSibling)
770
- ) {
771
- this.__enterPrevent(e);
772
- let newEl = null;
773
-
774
- if (dom.check.isListCell(rangeEl.parentElement)) {
775
- const parentLi = formatEl.parentNode.parentElement;
776
- rangeEl = parentLi.parentElement;
777
- const newListCell = dom.utils.createElement('LI');
778
- newListCell.innerHTML = '<br>';
779
- dom.utils.copyTagAttributes(newListCell, formatEl, this.options.get('lineAttrReset'));
780
- newEl = newListCell;
781
- rangeEl.insertBefore(newEl, parentLi.nextElementSibling);
782
- } else {
783
- let newFormat;
784
- if (dom.check.isTableCell(rangeEl.parentElement)) {
785
- newFormat = 'DIV';
786
- } else if (dom.check.isList(rangeEl.parentElement)) {
787
- newFormat = 'LI';
788
- } else if (this.format.isLine(rangeEl.nextElementSibling)) {
789
- newFormat = rangeEl.nextElementSibling.nodeName;
790
- } else if (this.format.isLine(rangeEl.previousElementSibling)) {
791
- newFormat = rangeEl.previousElementSibling.nodeName;
792
- } else {
793
- newFormat = this.options.get('defaultLine');
794
- }
795
-
796
- newEl = dom.utils.createElement(newFormat);
797
- const edge = this.format.removeBlock(rangeEl, { selectedFormats: [formatEl], newBlockElement: null, shouldDelete: true, skipHistory: true });
798
- edge.cc.insertBefore(newEl, edge.ec);
799
- }
800
-
801
- newEl.innerHTML = '<br>';
802
- this.nodeTransform.removeAllParents(formatEl, null, null);
803
- this.selection.setRange(newEl, 1, newEl, 1);
804
- break;
805
- }
806
- }
807
-
808
- if (brBlock) {
809
- this.__enterPrevent(e);
810
- const selectionFormat = selectionNode === brBlock;
811
- const wSelection = this.selection.get();
812
- const children = selectionNode.childNodes,
813
- offset = wSelection.focusOffset,
814
- prev = selectionNode.previousElementSibling,
815
- next = selectionNode.nextSibling;
816
-
817
- if (
818
- !this.format.isClosureBrLine(brBlock) &&
819
- children &&
820
- ((selectionFormat &&
821
- range.collapsed &&
822
- children.length - 1 <= offset + 1 &&
823
- dom.check.isBreak(children[offset]) &&
824
- (!children[offset + 1] || ((!children[offset + 2] || dom.check.isZeroWidth(children[offset + 2].textContent)) && children[offset + 1].nodeType === 3 && dom.check.isZeroWidth(children[offset + 1].textContent))) &&
825
- offset > 0 &&
826
- dom.check.isBreak(children[offset - 1])) ||
827
- (!selectionFormat &&
828
- dom.check.isZeroWidth(selectionNode.textContent) &&
829
- dom.check.isBreak(prev) &&
830
- (dom.check.isBreak(prev.previousSibling) || !dom.check.isZeroWidth(prev.previousSibling?.textContent)) &&
831
- (!next || (!dom.check.isBreak(next) && dom.check.isZeroWidth(next.textContent)))))
832
- ) {
833
- if (selectionFormat) dom.utils.removeItem(children[offset - 1]);
834
- else dom.utils.removeItem(selectionNode);
835
- const brBlockNext = /** @type {HTMLElement} */ (brBlock).nextElementSibling;
836
- const newEl = this.format.addLine(brBlock, this.format.isLine(brBlockNext) ? brBlockNext : null);
837
- dom.utils.copyFormatAttributes(newEl, brBlock);
838
- this.selection.setRange(newEl, 1, newEl, 1);
839
-
840
- // enter scroll
841
- this.__enterScrollTo(range);
842
- break;
843
- }
844
-
845
- if (selectionFormat) {
846
- this.html.insert(range.collapsed && dom.check.isBreak(range.startContainer.childNodes[range.startOffset - 1]) ? '<br>' : '<br><br>', { selectInserted: false, skipCharCount: true, skipCleaning: true });
847
-
848
- let focusNode = wSelection.focusNode;
849
- const wOffset = wSelection.focusOffset;
850
- if (brBlock === focusNode) {
851
- focusNode = focusNode.childNodes[wOffset - offset > 1 ? wOffset - 1 : wOffset];
852
- }
853
-
854
- this.selection.setRange(focusNode, 1, focusNode, 1);
855
- } else {
856
- const focusNext = wSelection.focusNode.nextSibling;
857
- const br = dom.utils.createElement('BR');
858
- this.html.insertNode(br, { afterNode: null, skipCharCount: true });
859
-
860
- const brPrev = br.previousSibling,
861
- brNext = br.nextSibling;
862
- if (!dom.check.isBreak(focusNext) && !dom.check.isBreak(brPrev) && (!brNext || dom.check.isZeroWidth(brNext))) {
863
- br.parentNode.insertBefore(br.cloneNode(false), br);
864
- this.selection.setRange(br, 1, br, 1);
865
- } else {
866
- this.selection.setRange(brNext, 0, brNext, 0);
867
- }
868
- }
869
-
870
- this._onShortcutKey = true;
871
-
872
- // enter scroll
873
- this.__enterScrollTo(range);
874
- break;
875
- }
876
-
877
- // set format attrs - edge
878
- if (range.collapsed && (formatStartEdge || formatEndEdge)) {
879
- this.__enterPrevent(e);
880
- const focusBR = dom.utils.createElement('BR');
881
- const newFormat = dom.utils.createElement(formatEl.nodeName, null, focusBR);
882
-
883
- dom.utils.copyTagAttributes(newFormat, formatEl, this.options.get('lineAttrReset'));
884
-
885
- let child = focusBR;
886
- do {
887
- if (!dom.check.isBreak(selectionNode) && selectionNode.nodeType === 1) {
888
- const f = /** @type {HTMLElement} */ (selectionNode.cloneNode(false));
889
- f.appendChild(child);
890
- child = f;
891
- }
892
- selectionNode = selectionNode.parentElement;
893
- } while (formatEl !== selectionNode && formatEl.contains(selectionNode));
894
-
895
- newFormat.appendChild(child);
896
- formatEl.parentNode.insertBefore(newFormat, formatStartEdge && !formatEndEdge ? formatEl : formatEl.nextElementSibling);
897
- if (formatEndEdge) {
898
- this.selection.setRange(focusBR, 1, focusBR, 1);
899
- } else {
900
- const firstEl = formatEl.firstChild || formatEl;
901
- this.selection.setRange(firstEl, 0, firstEl, 0);
902
- }
903
-
904
- // enter scroll
905
- this.__enterScrollTo(range);
906
- break;
907
- }
908
-
909
- if (formatEl) {
910
- e.stopPropagation();
911
-
912
- /** @type {HTMLElement} */
913
- let newEl;
914
- let offset = 0;
915
- if (!range.collapsed) {
916
- const isMultiLine = this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null);
917
- const newFormat = /** @type {HTMLElement} */ (formatEl.cloneNode(false));
918
- newFormat.innerHTML = '<br>';
919
- const commonCon = /** @type {HTMLElement} */ (range.commonAncestorContainer);
920
- const rcon =
921
- commonCon === range.startContainer && commonCon === range.endContainer && dom.check.isZeroWidth(commonCon)
922
- ? { container: commonCon, offset: range.endOffset, prevContainer: commonCon.previousElementSibling, commonCon: commonCon }
923
- : this.html.remove();
924
- newEl = this.format.getLine(rcon.container, null);
925
- if (!newEl) {
926
- if (dom.check.isWysiwygFrame(rcon.container)) {
927
- this.__enterPrevent(e);
928
- fc.get('wysiwyg').appendChild(newFormat);
929
- newEl = newFormat;
930
- dom.utils.copyTagAttributes(newEl, formatEl, this.options.get('lineAttrReset'));
931
- this.selection.setRange(newEl, offset, newEl, offset);
932
- }
933
-
934
- // enter scroll
935
- this.__enterScrollTo(range);
936
- break;
937
- }
938
-
939
- const innerRange = this.format.getBlock(rcon.container);
940
- newEl = newEl.contains(innerRange) ? dom.query.getEdgeChild(innerRange, this.format.getLine.bind(this.format), false) : newEl;
941
- if (isMultiLine) {
942
- if (formatEndEdge && !formatStartEdge) {
943
- newEl.parentNode.insertBefore(newFormat, !rcon.prevContainer || rcon.container === rcon.prevContainer ? newEl.nextElementSibling : newEl);
944
- newEl = newFormat;
945
- offset = 0;
946
- } else {
947
- offset = rcon.offset;
948
- if (formatStartEdge) {
949
- const tempEl = newEl.parentNode.insertBefore(newFormat, newEl);
950
- if (formatEndEdge) {
951
- newEl = tempEl;
952
- offset = 0;
953
- }
954
- }
955
- }
956
- } else {
957
- if (formatEndEdge && formatStartEdge) {
958
- newEl.parentNode.insertBefore(newFormat, rcon.prevContainer && rcon.container === rcon.prevContainer ? newEl.nextElementSibling : newEl);
959
- newEl = newFormat;
960
- offset = 0;
961
- } else if (formatEndEdge) {
962
- newEl = newEl.parentNode.insertBefore(newFormat, newEl.nextElementSibling);
963
- newEl = newFormat;
964
- offset = 0;
965
- } else {
966
- newEl = this.nodeTransform.split(rcon.container, rcon.offset, dom.query.getNodeDepth(formatEl));
967
- }
968
- }
969
- } else {
970
- if (dom.check.isZeroWidth(formatEl)) {
971
- newEl = this.format.addLine(formatEl, formatEl.cloneNode(false));
972
- } else {
973
- newEl = this.nodeTransform.split(range.endContainer, range.endOffset, dom.query.getNodeDepth(formatEl));
974
- }
975
- }
976
-
977
- this.__enterPrevent(e);
978
- dom.utils.copyTagAttributes(newEl, formatEl, this.options.get('lineAttrReset'));
979
- this.selection.setRange(newEl, offset, newEl, offset);
980
-
981
- // enter scroll
982
- this.__enterScrollTo(range);
983
- break;
984
- }
985
- }
986
-
987
- if (selectRange) {
988
- // enter scroll
989
- this.__enterScrollTo(range);
990
- break;
991
- }
992
-
993
- if (rangeEl && dom.query.getParentElement(rangeEl, 'FIGCAPTION') && dom.query.getParentElement(rangeEl, dom.check.isList)) {
994
- this.__enterPrevent(e);
995
- formatEl = this.format.addLine(formatEl, null);
996
- this.selection.setRange(formatEl, 0, formatEl, 0);
997
-
998
- // enter scroll
999
- this.__enterScrollTo(range);
1000
- }
1001
-
1002
- break;
1003
- }
1004
- }
1005
-
1006
- if (shift && (isOSX_IOS ? alt : ctrl) && keyCodeMap.isSpace(keyCode)) {
1007
- e.preventDefault();
1008
- e.stopPropagation();
1009
- const nbsp = this.html.insertNode(dom.utils.createTextNode('\u00a0'), { afterNode: null, skipCharCount: true });
1010
- if (nbsp) {
1011
- this.selection.setRange(nbsp, nbsp.length, nbsp, nbsp.length);
1012
- return;
1013
- }
1014
- }
1015
-
1016
- if (!ctrl && !alt && !selectRange && !keyCodeMap.isNonTextKey(keyCode) && dom.check.isBreak(range.commonAncestorContainer)) {
1017
- const zeroWidth = dom.utils.createTextNode(unicode.zeroWidthSpace);
1018
- this.html.insertNode(zeroWidth, { afterNode: null, skipCharCount: true });
1019
- this.selection.setRange(zeroWidth, 1, zeroWidth, 1);
1020
- }
1021
-
1022
- // document type
1023
- if (fc.has('documentType-use-header') && !range.collapsed && !ctrl && !alt && !shift && !keyCodeMap.isDirectionKey(keyCode)) {
1024
- _w.setTimeout(() => {
1025
- fc.get('documentType').reHeader();
1026
- }, 0);
1027
- return;
1028
- }
1029
-
1030
- // next component
1031
- let cmponentInfo = null;
1032
- switch (keyCode) {
1033
- case 'ArrowUp' /** up key */:
1034
- if (this.component.is(formatEl.previousElementSibling)) {
1035
- cmponentInfo = this.component.get(formatEl.previousElementSibling);
1036
- }
1037
- break;
1038
- case 'ArrowLeft' /** left key */:
1039
- if (dom.check.isEdgePoint(selectionNode, range.startOffset, 'front')) {
1040
- const prevEl = selectionNode.previousElementSibling || dom.query.getPreviousDeepestNode(selectionNode);
1041
- if (prevEl) {
1042
- if (this.component.is(prevEl)) cmponentInfo = this.component.get(prevEl);
1043
- } else if (this.component.is(formatEl.previousElementSibling)) {
1044
- cmponentInfo = this.component.get(formatEl.previousElementSibling);
1045
- }
1046
- }
1047
- break;
1048
- case 'ArrowDown' /** down key */:
1049
- if (this.component.is(formatEl.nextElementSibling)) {
1050
- cmponentInfo = this.component.get(formatEl.nextElementSibling);
1051
- }
1052
- break;
1053
- case 'ArrowRight' /** right key */:
1054
- if (dom.check.isEdgePoint(selectionNode, range.endOffset, 'end')) {
1055
- const nextEl = selectionNode.nextElementSibling || dom.query.getNextDeepestNode(selectionNode);
1056
- if (nextEl) {
1057
- if (this.component.is(nextEl)) cmponentInfo = this.component.get(nextEl);
1058
- } else if (this.component.is(formatEl.nextElementSibling)) {
1059
- cmponentInfo = this.component.get(formatEl.nextElementSibling);
1060
- }
1061
- }
1062
- break;
1063
- }
1064
-
1065
- if (cmponentInfo && !cmponentInfo.options?.isInputComponent) {
1066
- e.preventDefault();
1067
- if (this.component.select(cmponentInfo.target, cmponentInfo.pluginName) === false) this.editor.blur();
1068
- }
1069
- }
1070
-
1071
- /**
1072
- * @private
1073
- * @this {EventManagerThis_handler_ww_key_input}
1074
- * @param {__se__FrameContext} fc - Frame context object
1075
- * @param {KeyboardEvent} e - Event object
1076
- */
1077
- export async function OnKeyUp_wysiwyg(fc, e) {
1078
- if (this._onShortcutKey || this.menu.currentDropdownName) return;
1079
-
1080
- const keyCode = e.code;
1081
- const ctrl = keyCodeMap.isCtrl(e);
1082
- const alt = keyCodeMap.isAlt(e);
1083
-
1084
- if (ctrl) keyState.ctrl = false;
1085
- if (alt) keyState.alt = false;
1086
-
1087
- if (fc.get('isReadOnly')) return;
1088
-
1089
- const range = this.selection.getRange();
1090
- let selectionNode = this.selection.getNode();
1091
-
1092
- if ((this.editor.isBalloon || this.editor.isSubBalloon) && (((this.editor.isBalloonAlways || this.editor.isSubBalloonAlways) && !keyCodeMap.isEsc(keyCode)) || !range.collapsed)) {
1093
- if (this.editor.isBalloonAlways || this.editor.isSubBalloonAlways) {
1094
- if (!keyCodeMap.isEsc(keyCode)) this._showToolbarBalloonDelay();
1095
- } else {
1096
- if (this.editor.isSubBalloon) this.subToolbar._showBalloon();
1097
- else this.toolbar._showBalloon();
1098
- return;
1099
- }
1100
- }
1101
-
1102
- /** when format tag deleted */
1103
- if (keyCodeMap.isBackspace(keyCode) && dom.check.isWysiwygFrame(selectionNode) && selectionNode.textContent === '' && selectionNode.children.length === 0) {
1104
- e.preventDefault();
1105
- e.stopPropagation();
1106
-
1107
- selectionNode.innerHTML = '';
1108
-
1109
- const oFormatTag = dom.utils.createElement(this.format.isLine(this.status.currentNodes[0]) && !dom.check.isListCell(this.status.currentNodes[0]) ? this.status.currentNodes[0] : this.options.get('defaultLine'), null, '<br>');
1110
- selectionNode.appendChild(oFormatTag);
1111
- this.selection.setRange(oFormatTag, 0, oFormatTag, 0);
1112
- this.applyTagEffect();
1113
-
1114
- this.history.push(false);
1115
-
1116
- // document type
1117
- if (fc.has('documentType-use-header')) {
1118
- if (keyCodeMap.isDocumentTypeObserverKey(keyCode)) {
1119
- fc.get('documentType').reHeader();
1120
- }
1121
- }
1122
-
1123
- return;
1124
- }
1125
-
1126
- const formatEl = this.format.getLine(selectionNode, null);
1127
- const rangeEl = this.format.getBlock(selectionNode, null);
1128
- const attrs = this._formatAttrsTemp;
1129
-
1130
- if (formatEl && attrs) {
1131
- for (let i = 0, len = attrs.length; i < len; i++) {
1132
- if (keyCodeMap.isEnter(keyCode) && /^id$/i.test(attrs[i].name)) {
1133
- formatEl.removeAttribute('id');
1134
- continue;
1135
- }
1136
- formatEl.setAttribute(attrs[i].name, attrs[i].value);
1137
- }
1138
- this._formatAttrsTemp = null;
1139
- }
1140
-
1141
- if (!formatEl && range.collapsed && !this.component.is(selectionNode) && !dom.check.isList(selectionNode) && this._setDefaultLine(this.format.isBlock(rangeEl) ? 'DIV' : this.options.get('defaultLine')) !== null) {
1142
- selectionNode = this.selection.getNode();
1143
- }
1144
-
1145
- const textKey = !keyState.ctrl && !keyState.alt && !keyCodeMap.isNonTextKey(keyCode);
1146
- if (textKey && selectionNode.nodeType === 3 && unicode.zeroWidthRegExp.test(selectionNode.textContent) && !(e.isComposing !== undefined ? e.isComposing : this.isComposing)) {
1147
- let so = range.startOffset,
1148
- eo = range.endOffset;
1149
- const frontZeroWidthCnt = (selectionNode.textContent.substring(0, eo).match(FRONT_ZEROWIDTH) || '').length;
1150
- so = range.startOffset - frontZeroWidthCnt;
1151
- eo = range.endOffset - frontZeroWidthCnt;
1152
- selectionNode.textContent = selectionNode.textContent.replace(unicode.zeroWidthRegExp, '');
1153
- this.selection.setRange(selectionNode, so < 0 ? 0 : so, selectionNode, eo < 0 ? 0 : eo);
1154
- }
1155
-
1156
- if (keyCodeMap.isRemoveKey(keyCode) && dom.check.isZeroWidth(formatEl?.textContent) && !formatEl.previousElementSibling) {
1157
- const rsMode = this.options.get('retainStyleMode');
1158
- if (rsMode !== 'none' && _styleNodes?.length > 0) {
1159
- if (rsMode === 'repeat') {
1160
- if (this.__retainTimer) {
1161
- this.__retainTimer = _w.clearTimeout(this.__retainTimer);
1162
- this._clearRetainStyleNodes(formatEl);
1163
- } else {
1164
- this.__retainTimer = _w.setTimeout(() => {
1165
- this.__retainTimer = null;
1166
- }, 0);
1167
- this._retainStyleNodes(formatEl, _styleNodes);
1168
- }
1169
- } else {
1170
- this.__retainTimer = null;
1171
- this._retainStyleNodes(formatEl, _styleNodes);
1172
- }
1173
- } else {
1174
- this._clearRetainStyleNodes(formatEl);
1175
- }
1176
- }
1177
-
1178
- this.char.test('', false);
1179
-
1180
- // document type
1181
- if (fc.has('documentType-use-header')) {
1182
- if (keyCodeMap.isDocumentTypeObserverKey(keyCode)) {
1183
- fc.get('documentType').reHeader();
1184
- const el = dom.query.getParentElement(this.selection.selectionNode, this.format.isLine.bind(this.format));
1185
- fc.get('documentType').on(el);
1186
- } else {
1187
- const el = dom.query.getParentElement(selectionNode, (current) => current.nodeType === 1);
1188
- fc.get('documentType').onChangeText(el);
1189
- }
1190
- }
1191
-
1192
- // user event
1193
- if ((await this.triggerEvent('onKeyUp', { frameContext: fc, event: e })) === false) return;
1194
- // plugin event
1195
- if (this._callPluginEvent('onKeyUp', { frameContext: fc, event: e, range, line: formatEl }) === false) return;
1196
-
1197
- if (keyCodeMap.isHistoryRelevantKey(keyCode)) {
1198
- this.history.push(true);
1199
- }
1200
- }
1
+ import { dom, env, unicode, keyCodeMap } from '../../../helper';
2
+
3
+ const { _w, isOSX_IOS } = env;
4
+ const FRONT_ZEROWIDTH = new RegExp(unicode.zeroWidthSpace + '+', '');
5
+
6
+ const keyState = {
7
+ ctrl: false,
8
+ alt: false
9
+ };
10
+ let _styleNodes = null;
11
+
12
+ /**
13
+ * @typedef {Omit<import('../eventManager').default & Partial<__se__EditorInjector>, 'eventManager'>} EventManagerThis_handler_ww_key_input
14
+ */
15
+
16
+ /**
17
+ * @private
18
+ * @param {HTMLElement} formatEl - Format element
19
+ * @returns {Node}
20
+ */
21
+ function LineDelete_next(formatEl) {
22
+ const focusNode = formatEl.lastChild;
23
+ const next = formatEl.nextElementSibling;
24
+
25
+ if (!next) return focusNode;
26
+
27
+ if (dom.check.isZeroWidth(next)) {
28
+ dom.utils.removeItem(next);
29
+ return focusNode;
30
+ }
31
+
32
+ const nextChild = next.childNodes;
33
+ while (nextChild[0]) {
34
+ formatEl.appendChild(nextChild[0]);
35
+ }
36
+
37
+ dom.utils.removeItem(next);
38
+
39
+ return focusNode;
40
+ }
41
+
42
+ /**
43
+ * @private
44
+ * @param {HTMLElement} formatEl - Format element
45
+ * @returns {{focusNode: Node, focusOffset: number}}
46
+ */
47
+ function LineDelete_prev(formatEl) {
48
+ const formatChild = formatEl.childNodes;
49
+ const prev = formatEl.previousElementSibling;
50
+ let focusNode = formatChild[0];
51
+ let focusOffset = 0;
52
+
53
+ if (!prev) return { focusNode, focusOffset };
54
+
55
+ if (dom.check.isZeroWidth(prev)) {
56
+ dom.utils.removeItem(prev);
57
+ return { focusNode, focusOffset };
58
+ }
59
+
60
+ if (formatChild.length > 1 || formatChild[0]?.textContent.length > 0) {
61
+ while (formatChild[0]) {
62
+ prev.appendChild(formatChild[0]);
63
+ }
64
+ } else {
65
+ focusNode = prev.lastChild;
66
+ focusOffset = focusNode.textContent.length;
67
+ }
68
+
69
+ dom.utils.removeItem(formatEl);
70
+
71
+ return { focusNode, focusOffset };
72
+ }
73
+
74
+ /**
75
+ * @private
76
+ * @this {EventManagerThis_handler_ww_key_input}
77
+ * @param {__se__FrameContext} fc - Frame context object
78
+ * @param {InputEvent} e - Event object
79
+ */
80
+ export async function OnInput_wysiwyg(fc, e) {
81
+ if (fc.get('isReadOnly') || fc.get('isDisabled')) {
82
+ e.preventDefault();
83
+ e.stopPropagation();
84
+ return false;
85
+ }
86
+
87
+ const range = this.selection.getRange();
88
+ const selectionNode = this.selection.getNode();
89
+ const formatEl = this.format.getLine(selectionNode, null);
90
+ if (!formatEl && range.collapsed && !this.component.is(selectionNode) && !dom.check.isList(selectionNode)) {
91
+ const rangeEl = this.format.getBlock(selectionNode, null);
92
+ this._setDefaultLine(this.format.isBlock(rangeEl) ? 'DIV' : this.options.get('defaultLine'));
93
+ }
94
+
95
+ this.selection._init();
96
+
97
+ const data = (e.data === null ? '' : e.data === undefined ? ' ' : e.data) || '';
98
+ if (!this.char.test(data, true)) {
99
+ e.preventDefault();
100
+ e.stopPropagation();
101
+ return false;
102
+ }
103
+
104
+ // user event
105
+ if ((await this.triggerEvent('onInput', { frameContext: fc, event: e, data })) === false) return;
106
+ // plugin event
107
+ if (this._callPluginEvent('onInput', { frameContext: fc, event: e, data }) === false) return;
108
+
109
+ this.history.push(true);
110
+ }
111
+
112
+ /**
113
+ * @private
114
+ * @this {EventManagerThis_handler_ww_key_input}
115
+ * @param {__se__FrameContext} fc - Frame context object
116
+ * @param {KeyboardEvent} e - Event object
117
+ */
118
+ export async function OnKeyDown_wysiwyg(fc, e) {
119
+ if (this.editor.selectMenuOn || !e.isTrusted) return;
120
+
121
+ let selectionNode = this.selection.getNode();
122
+ if (dom.check.isInputElement(selectionNode)) return;
123
+ if (this.menu.currentDropdownName) return;
124
+
125
+ const keyCode = e.code;
126
+ const shift = keyCodeMap.isShift(e);
127
+ const ctrl = (keyState.ctrl = keyCodeMap.isCtrl(e));
128
+ const alt = (keyState.alt = keyCodeMap.isAlt(e));
129
+ this.isComposing = keyCodeMap.isComposing(e);
130
+
131
+ if (!ctrl && fc.get('isReadOnly') && !keyCodeMap.isDirectionKey(keyCode)) {
132
+ e.preventDefault();
133
+ return false;
134
+ }
135
+
136
+ this.menu.dropdownOff();
137
+
138
+ if (this.editor.isBalloon) {
139
+ this._hideToolbar();
140
+ } else if (this.editor.isSubBalloon) {
141
+ this._hideToolbar_sub();
142
+ }
143
+
144
+ // user event
145
+ if ((await this.triggerEvent('onKeyDown', { frameContext: fc, event: e })) === false) return;
146
+
147
+ /** default key action */
148
+ if (keyCodeMap.isEnter(keyCode) && this.format.isLine(this.selection.getRange()?.startContainer)) {
149
+ this.selection._resetRangeToTextNode();
150
+ selectionNode = this.selection.getNode();
151
+ }
152
+
153
+ const range = this.selection.getRange();
154
+ const selectRange = !range.collapsed || range.startContainer !== range.endContainer;
155
+ let formatEl = /** @type {HTMLElement} */ (this.format.getLine(selectionNode, null) || selectionNode);
156
+ let rangeEl = this.format.getBlock(formatEl, null);
157
+
158
+ /** Shortcuts */
159
+ if (ctrl && !keyCodeMap.isNonTextKey(keyCode) && this.shortcuts.command(e, ctrl, shift, keyCode, '', false, null, null)) {
160
+ this._onShortcutKey = true;
161
+ e.preventDefault();
162
+ e.stopPropagation();
163
+ return false;
164
+ } else if (!ctrl && !keyCodeMap.isNonTextKey(keyCode) && this.format.isLine(formatEl) && range.collapsed && dom.check.isEdgePoint(range.startContainer, 0, 'front')) {
165
+ const keyword = /** @type {Text} */ (range.startContainer).substringData?.(0, range.startOffset);
166
+ if (keyword && this.shortcuts.command(e, false, shift, keyCode, keyword, true, formatEl, range)) {
167
+ this._onShortcutKey = true;
168
+ e.preventDefault();
169
+ e.stopPropagation();
170
+ return false;
171
+ }
172
+ } else if (this._onShortcutKey) {
173
+ this._onShortcutKey = false;
174
+ }
175
+
176
+ // plugin event
177
+ if (this._callPluginEvent('onKeyDown', { frameContext: fc, event: e, range, line: formatEl }) === false) return;
178
+
179
+ switch (keyCode) {
180
+ case 'Backspace' /** backspace key */: {
181
+ this.component.deselect();
182
+ _styleNodes = this.__cacheStyleNodes;
183
+ if (selectRange && this._hardDelete()) {
184
+ e.preventDefault();
185
+ e.stopPropagation();
186
+ break;
187
+ }
188
+
189
+ if (!this.format.isLine(formatEl) && !fc.get('wysiwyg').firstElementChild && !this.component.is(selectionNode) && this._setDefaultLine(this.options.get('defaultLine')) !== null) {
190
+ e.preventDefault();
191
+ e.stopPropagation();
192
+ return false;
193
+ }
194
+
195
+ // line delete
196
+ if (this.format.isLine(formatEl) && (!range.collapsed || dom.check.isEdgePoint(range.endContainer, range.endOffset, 'front')) && !range.endContainer.previousSibling && this.format.isLine(formatEl.previousElementSibling)) {
197
+ e.preventDefault();
198
+ e.stopPropagation();
199
+
200
+ let focusNode;
201
+ if (!range.collapsed) {
202
+ const rInfo = this.html.remove();
203
+ if (rInfo.commonCon !== rInfo.container && formatEl.parentElement) {
204
+ if (formatEl.contains(range.startContainer)) {
205
+ focusNode = LineDelete_next(formatEl);
206
+ this.selection.setRange(focusNode, focusNode.textContent.length, focusNode, focusNode.textContent.length);
207
+ } else {
208
+ const prevInfo = LineDelete_prev(formatEl);
209
+ this.selection.setRange(prevInfo.focusNode, prevInfo.focusOffset, prevInfo.focusNode, prevInfo.focusOffset);
210
+ }
211
+ }
212
+ this.history.push(true);
213
+ return;
214
+ }
215
+
216
+ const prevInfo = LineDelete_prev(formatEl);
217
+ this.selection.setRange(prevInfo.focusNode, prevInfo.focusOffset, prevInfo.focusNode, prevInfo.focusOffset);
218
+ this.history.push(true);
219
+
220
+ return;
221
+ }
222
+
223
+ if (
224
+ !selectRange &&
225
+ !formatEl.previousElementSibling &&
226
+ range.startOffset === 0 &&
227
+ !selectionNode.previousSibling &&
228
+ !dom.check.isListCell(formatEl) &&
229
+ this.format.isLine(formatEl) &&
230
+ (!this.format.isBrLine(formatEl) || this.format.isClosureBrLine(formatEl))
231
+ ) {
232
+ // closure range
233
+ if (this.format.isClosureBlock(formatEl.parentNode)) {
234
+ e.preventDefault();
235
+ e.stopPropagation();
236
+ return false;
237
+ }
238
+ // maintain default format
239
+ if (dom.check.isWysiwygFrame(formatEl.parentNode) && formatEl.childNodes.length <= 1 && (!formatEl.firstChild || dom.check.isZeroWidth(formatEl.textContent))) {
240
+ e.preventDefault();
241
+ e.stopPropagation();
242
+
243
+ if (formatEl.nodeName.toUpperCase() === this.options.get('defaultLine').toUpperCase()) {
244
+ formatEl.innerHTML = '<br>';
245
+ const attrs = formatEl.attributes;
246
+ while (attrs[0]) {
247
+ formatEl.removeAttribute(attrs[0].name);
248
+ }
249
+ } else {
250
+ formatEl.parentNode.replaceChild(dom.utils.createElement(this.options.get('defaultLine'), null, '<br>'), formatEl);
251
+ }
252
+
253
+ this.editor._nativeFocus();
254
+ return false;
255
+ }
256
+ }
257
+
258
+ // clean remove tag
259
+ const startCon = range.startContainer;
260
+ if (formatEl && !formatEl.previousElementSibling && range.startOffset === 0 && startCon.nodeType === 3 && dom.check.isZeroWidth(startCon)) {
261
+ let prev = startCon.parentNode.previousSibling;
262
+ const next = startCon.parentNode.nextSibling;
263
+ if (!prev) {
264
+ if (!next) {
265
+ prev = dom.utils.createElement('BR');
266
+ formatEl.appendChild(prev);
267
+ } else {
268
+ prev = next;
269
+ }
270
+ }
271
+
272
+ let con = startCon;
273
+ while (formatEl.contains(con) && !con.previousSibling) {
274
+ con = con.parentNode;
275
+ }
276
+
277
+ if (!formatEl.contains(con)) {
278
+ startCon.textContent = '';
279
+ this.nodeTransform.removeAllParents(startCon, null, formatEl);
280
+ break;
281
+ }
282
+ }
283
+
284
+ // line component
285
+ if (!selectRange && formatEl && (range.startOffset === 0 || selectionNode === formatEl)) {
286
+ const sel = selectionNode === formatEl ? this._isUneditableNode(range, true) : dom.check.isEdgePoint(range.startContainer, range.startOffset) ? dom.query.getPreviousDeepestNode(range.startContainer) : null;
287
+ if (this.component.is(sel)) {
288
+ const fileComponentInfo = this.component.get(sel);
289
+ if (fileComponentInfo) {
290
+ e.preventDefault();
291
+ e.stopPropagation();
292
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
293
+ break;
294
+ }
295
+ }
296
+ }
297
+
298
+ // tag[contenteditable='false']
299
+ if (this._isUneditableNode(range, true)) {
300
+ e.preventDefault();
301
+ e.stopPropagation();
302
+ break;
303
+ }
304
+
305
+ // format attributes
306
+ if (!selectRange && this.format.isEdgeLine(range.startContainer, range.startOffset, 'front')) {
307
+ if (this.format.isLine(formatEl.previousElementSibling)) {
308
+ this._formatAttrsTemp = formatEl.previousElementSibling.attributes;
309
+ }
310
+ }
311
+
312
+ // nested list
313
+ const commonCon = range.commonAncestorContainer;
314
+ formatEl = this.format.getLine(range.startContainer, null);
315
+ rangeEl = this.format.getBlock(formatEl, null);
316
+ if (rangeEl && formatEl && !dom.check.isTableCell(rangeEl) && !/^FIGCAPTION$/i.test(rangeEl.nodeName)) {
317
+ if (
318
+ dom.check.isListCell(formatEl) &&
319
+ dom.check.isList(rangeEl) &&
320
+ (dom.check.isListCell(rangeEl.parentElement) || formatEl.previousElementSibling) &&
321
+ (selectionNode === formatEl || (selectionNode.nodeType === 3 && (!selectionNode.previousSibling || dom.check.isList(selectionNode.previousSibling)))) &&
322
+ (this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null) ? rangeEl.contains(range.startContainer) : range.startOffset === 0 && range.collapsed)
323
+ ) {
324
+ if (range.startContainer !== range.endContainer) {
325
+ e.preventDefault();
326
+
327
+ this.html.remove();
328
+ if (range.startContainer.nodeType === 3) {
329
+ this.selection.setRange(range.startContainer, range.startContainer.textContent.length, range.startContainer, range.startContainer.textContent.length);
330
+ }
331
+
332
+ this.history.push(true);
333
+ } else {
334
+ let prev = formatEl.previousElementSibling || rangeEl.parentElement;
335
+ if (dom.check.isListCell(prev)) {
336
+ e.preventDefault();
337
+
338
+ let prevLast = prev;
339
+ if (!prev.contains(formatEl) && dom.check.isListCell(prevLast) && dom.check.isList(prevLast.lastElementChild)) {
340
+ prevLast = /** @type {HTMLLIElement} */ (prevLast.lastElementChild.lastElementChild);
341
+ while (dom.check.isListCell(prevLast) && dom.check.isList(prevLast.lastElementChild)) {
342
+ prevLast = /** @type {HTMLLIElement} */ (prevLast.lastElementChild && prevLast.lastElementChild.lastElementChild);
343
+ }
344
+ prev = prevLast;
345
+ }
346
+
347
+ let con = prev === rangeEl.parentNode ? rangeEl.previousSibling : prev.lastChild;
348
+ if (!con) {
349
+ con = dom.utils.createTextNode(unicode.zeroWidthSpace);
350
+ rangeEl.parentNode.insertBefore(con, rangeEl.parentNode.firstChild);
351
+ }
352
+ const offset = con.nodeType === 3 ? con.textContent.length : 1;
353
+ const children = formatEl.childNodes;
354
+ let after = con;
355
+ let child = children[0];
356
+ while ((child = children[0])) {
357
+ prev.insertBefore(child, after.nextSibling);
358
+ after = child;
359
+ }
360
+
361
+ dom.utils.removeItem(formatEl);
362
+ if (rangeEl.children.length === 0) dom.utils.removeItem(rangeEl);
363
+
364
+ this.selection.setRange(con, offset, con, offset);
365
+ this.history.push(true);
366
+ }
367
+ }
368
+
369
+ break;
370
+ }
371
+
372
+ // detach range
373
+ if (!selectRange && range.startOffset === 0) {
374
+ let detach = true;
375
+ let comm = commonCon;
376
+ while (comm && comm !== rangeEl && !dom.check.isWysiwygFrame(comm)) {
377
+ if (comm.previousSibling) {
378
+ if (comm.previousSibling.nodeType === 1 || !dom.check.isZeroWidth(comm.previousSibling.textContent.trim())) {
379
+ detach = false;
380
+ break;
381
+ }
382
+ }
383
+ comm = comm.parentNode;
384
+ }
385
+
386
+ if (detach && rangeEl.parentNode) {
387
+ e.preventDefault();
388
+ this.format.removeBlock(rangeEl, { selectedFormats: dom.check.isListCell(formatEl) ? [formatEl] : null, newBlockElement: null, shouldDelete: false, skipHistory: false });
389
+ this.history.push(true);
390
+ break;
391
+ }
392
+ }
393
+ }
394
+
395
+ // component
396
+ if (!selectRange && formatEl && (range.startOffset === 0 || (selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : false))) {
397
+ const sel = selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : selectionNode;
398
+ const prev = formatEl.previousSibling;
399
+ // select file component
400
+ const ignoreZWS = (commonCon.nodeType === 3 || dom.check.isBreak(commonCon)) && !commonCon.previousSibling && range.startOffset === 0;
401
+ if (sel && !sel.previousSibling && ((commonCon && this.component.is(commonCon.previousSibling)) || (ignoreZWS && this.component.is(prev)))) {
402
+ const fileComponentInfo = this.component.get(prev);
403
+ if (fileComponentInfo) {
404
+ e.preventDefault();
405
+ e.stopPropagation();
406
+ if (formatEl.textContent.length === 0) dom.utils.removeItem(formatEl);
407
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
408
+ } else if (this.component.is(prev)) {
409
+ e.preventDefault();
410
+ e.stopPropagation();
411
+ dom.utils.removeItem(prev);
412
+ }
413
+ break;
414
+ }
415
+ // delete nonEditable
416
+ if (sel && dom.check.isNonEditable(sel.previousSibling)) {
417
+ e.preventDefault();
418
+ e.stopPropagation();
419
+ dom.utils.removeItem(sel.previousSibling);
420
+ break;
421
+ }
422
+ }
423
+
424
+ break;
425
+ }
426
+ case 'Delete' /** delete key */: {
427
+ this.component.deselect();
428
+ _styleNodes = this.__cacheStyleNodes;
429
+ if (selectRange && this._hardDelete()) {
430
+ e.preventDefault();
431
+ e.stopPropagation();
432
+ break;
433
+ }
434
+
435
+ if (!selectRange && this.format.isEdgeLine(range.endContainer, range.endOffset, 'end') && !formatEl.nextSibling) {
436
+ e.preventDefault();
437
+ e.stopPropagation();
438
+ return;
439
+ }
440
+
441
+ // line delete
442
+ if (this.format.isLine(formatEl) && (!range.collapsed || dom.check.isEdgePoint(range.startContainer, range.endOffset, 'end')) && !range.startContainer.nextSibling && this.format.isLine(formatEl.nextElementSibling)) {
443
+ e.preventDefault();
444
+ e.stopPropagation();
445
+
446
+ let focusNode;
447
+ if (!range.collapsed) {
448
+ const rInfo = this.html.remove();
449
+ if (rInfo.commonCon !== rInfo.container && formatEl.parentElement) {
450
+ if (formatEl.contains(range.startContainer)) {
451
+ focusNode = LineDelete_next(formatEl);
452
+ this.selection.setRange(focusNode, focusNode.textContent.length, focusNode, focusNode.textContent.length);
453
+ } else {
454
+ const prevInfo = LineDelete_prev(formatEl);
455
+ this.selection.setRange(prevInfo.focusNode, prevInfo.focusOffset, prevInfo.focusNode, prevInfo.focusOffset);
456
+ }
457
+ }
458
+ this.history.push(true);
459
+ return;
460
+ }
461
+
462
+ LineDelete_next(formatEl);
463
+ this.history.push(true);
464
+
465
+ return;
466
+ }
467
+
468
+ // line component
469
+ if (!selectRange && formatEl && (range.endOffset === range.endContainer.textContent.length || selectionNode === formatEl)) {
470
+ const sel = selectionNode === formatEl ? this._isUneditableNode(range, false) : dom.check.isEdgePoint(range.endContainer, range.endOffset) ? dom.query.getNextDeepestNode(range.endContainer, null) : null;
471
+ if (this.component.is(sel)) {
472
+ const fileComponentInfo = this.component.get(sel);
473
+ if (fileComponentInfo) {
474
+ e.preventDefault();
475
+ e.stopPropagation();
476
+ if (dom.check.isZeroWidth(formatEl.textContent)) dom.utils.removeItem(formatEl);
477
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
478
+ break;
479
+ }
480
+ }
481
+ }
482
+
483
+ // tag[contenteditable='false']
484
+ if (this._isUneditableNode(range, false)) {
485
+ e.preventDefault();
486
+ e.stopPropagation();
487
+ break;
488
+ }
489
+
490
+ // component
491
+ if (
492
+ (this.format.isLine(selectionNode) || selectionNode.nextSibling === null || (dom.check.isZeroWidth(selectionNode.nextSibling) && selectionNode.nextSibling.nextSibling === null)) &&
493
+ range.startOffset === selectionNode.textContent.length
494
+ ) {
495
+ const nextEl = formatEl.nextElementSibling;
496
+ if (!nextEl) break;
497
+ if (this.component.is(nextEl)) {
498
+ e.preventDefault();
499
+
500
+ if (dom.check.isZeroWidth(formatEl)) {
501
+ dom.utils.removeItem(formatEl);
502
+ // table component
503
+ if (dom.check.isTable(nextEl)) {
504
+ let cell = /** @type {HTMLElement} */ (dom.query.getEdgeChild(nextEl, dom.check.isTableCell, false));
505
+ cell = /** @type {HTMLElement} */ (cell.firstElementChild || cell);
506
+ this.selection.setRange(cell, 0, cell, 0);
507
+ break;
508
+ }
509
+ }
510
+
511
+ // select file component
512
+ const fileComponentInfo = this.component.get(nextEl);
513
+ if (fileComponentInfo) {
514
+ e.stopPropagation();
515
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName) === false) this.editor.blur();
516
+ } else if (this.component.is(nextEl)) {
517
+ e.stopPropagation();
518
+ dom.utils.removeItem(nextEl);
519
+ }
520
+
521
+ break;
522
+ }
523
+ }
524
+
525
+ if (!selectRange && (dom.check.isEdgePoint(range.endContainer, range.endOffset) || (selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : false))) {
526
+ const sel = selectionNode === formatEl ? formatEl.childNodes[range.startOffset] || selectionNode : selectionNode;
527
+ // delete nonEditable
528
+ if (sel && dom.check.isNonEditable(sel.nextSibling)) {
529
+ e.preventDefault();
530
+ e.stopPropagation();
531
+ dom.utils.removeItem(sel.nextSibling);
532
+ break;
533
+ } else if (this.component.is(sel)) {
534
+ e.preventDefault();
535
+ e.stopPropagation();
536
+ dom.utils.removeItem(sel);
537
+ break;
538
+ }
539
+ }
540
+
541
+ // format attributes
542
+ if (!selectRange && this.format.isEdgeLine(range.endContainer, range.endOffset, 'end')) {
543
+ if (this.format.isLine(formatEl.nextElementSibling)) {
544
+ this._formatAttrsTemp = formatEl.attributes;
545
+ }
546
+ }
547
+
548
+ // nested list
549
+ formatEl = this.format.getLine(range.startContainer, null);
550
+ rangeEl = this.format.getBlock(formatEl, null);
551
+ if (
552
+ dom.check.isListCell(formatEl) &&
553
+ dom.check.isList(rangeEl) &&
554
+ (selectionNode === formatEl ||
555
+ (selectionNode.nodeType === 3 &&
556
+ (!selectionNode.nextSibling || dom.check.isList(selectionNode.nextSibling)) &&
557
+ (this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null) ? rangeEl.contains(range.endContainer) : range.endOffset === selectionNode.textContent.length && range.collapsed)))
558
+ ) {
559
+ if (range.startContainer !== range.endContainer) this.html.remove();
560
+
561
+ const next = /** @type {HTMLElement} */ (dom.utils.arrayFind(formatEl.children, dom.check.isList) || formatEl.nextElementSibling || rangeEl.parentElement.nextElementSibling);
562
+ if (next && (dom.check.isList(next) || dom.utils.arrayFind(next.children, dom.check.isList))) {
563
+ e.preventDefault();
564
+
565
+ let con, children;
566
+ if (dom.check.isList(next)) {
567
+ const child = next.firstElementChild;
568
+ children = child.childNodes;
569
+ con = children[0];
570
+ while (children[0]) {
571
+ formatEl.insertBefore(children[0], next);
572
+ }
573
+ dom.utils.removeItem(child);
574
+ } else {
575
+ con = next.firstChild;
576
+ children = next.childNodes;
577
+ while (children[0]) {
578
+ formatEl.appendChild(children[0]);
579
+ }
580
+ dom.utils.removeItem(next);
581
+ }
582
+ this.selection.setRange(con, 0, con, 0);
583
+ this.history.push(true);
584
+ }
585
+ break;
586
+ }
587
+
588
+ break;
589
+ }
590
+ case 'Tab' /** tab key */: {
591
+ if (this.options.get('tabDisable')) break;
592
+ e.preventDefault();
593
+ if (ctrl || alt || dom.check.isWysiwygFrame(selectionNode)) break;
594
+
595
+ const isEdge = !range.collapsed || dom.check.isEdgePoint(range.startContainer, range.startOffset);
596
+ const selectedFormats = this.format.getLines(null);
597
+ selectionNode = this.selection.getNode();
598
+ const cells = [];
599
+ const lines = [];
600
+ const firstCell = dom.check.isListCell(selectedFormats[0]),
601
+ lastCell = dom.check.isListCell(selectedFormats[selectedFormats.length - 1]);
602
+ let r = {
603
+ sc: range.startContainer,
604
+ so: range.startOffset,
605
+ ec: range.endContainer,
606
+ eo: range.endOffset
607
+ };
608
+ for (let i = 0, len = selectedFormats.length, f; i < len; i++) {
609
+ f = selectedFormats[i];
610
+ if (dom.check.isListCell(f)) {
611
+ if (!f.previousElementSibling && !shift) {
612
+ continue;
613
+ } else {
614
+ cells.push(f);
615
+ }
616
+ } else {
617
+ lines.push(f);
618
+ }
619
+ }
620
+
621
+ // Nested list
622
+ if (cells.length > 0 && isEdge) {
623
+ r = this.format._applyNestedList(cells, shift);
624
+ }
625
+
626
+ // Lines tab
627
+ if (lines.length > 0) {
628
+ if (!shift) {
629
+ if (lines.length === 1) {
630
+ let tabSize = this.status.tabSize + 1;
631
+ if (this.options.get('syncTabIndent')) {
632
+ const baseIndex = dom.query.findTextIndexOnLine(formatEl, range.startContainer, range.startOffset, this.component.is.bind(this.component));
633
+ const prevTabEndIndex = this.format.isLine(formatEl.previousElementSibling) ? dom.query.findTabEndIndex(formatEl.previousElementSibling, baseIndex, 2) : 0;
634
+ if (prevTabEndIndex > baseIndex) {
635
+ tabSize = prevTabEndIndex - baseIndex;
636
+ }
637
+ }
638
+
639
+ const tabText = dom.utils.createTextNode(new Array(tabSize).join('\u00A0'));
640
+ if (!this.html.insertNode(tabText, { afterNode: null, skipCharCount: false })) return false;
641
+ if (!firstCell) {
642
+ r.sc = tabText;
643
+ r.so = tabText.length;
644
+ }
645
+ if (!lastCell) {
646
+ r.ec = tabText;
647
+ r.eo = tabText.length;
648
+ }
649
+ } else {
650
+ const tabText = dom.utils.createTextNode(new Array(this.status.tabSize + 1).join('\u00A0'));
651
+ const len = lines.length - 1;
652
+ for (let i = 0, child; i <= len; i++) {
653
+ child = lines[i].firstChild;
654
+ if (!child) continue;
655
+
656
+ if (dom.check.isBreak(child)) {
657
+ lines[i].insertBefore(tabText.cloneNode(false), child);
658
+ } else {
659
+ child.textContent = tabText.textContent + child.textContent;
660
+ }
661
+ }
662
+
663
+ const firstChild = dom.query.getEdgeChild(lines[0], 'text', false);
664
+ const endChild = dom.query.getEdgeChild(lines[len], 'text', true);
665
+ if (!firstCell && firstChild) {
666
+ r.sc = firstChild;
667
+ r.so = 0;
668
+ }
669
+ if (!lastCell && endChild) {
670
+ r.ec = endChild;
671
+ r.eo = endChild.textContent.length;
672
+ }
673
+ }
674
+ } else {
675
+ const len = lines.length - 1;
676
+ for (let i = 0, line; i <= len; i++) {
677
+ line = lines[i].childNodes;
678
+ for (let c = 0, cLen = line.length, child; c < cLen; c++) {
679
+ child = line[c];
680
+ if (!child) break;
681
+ if (dom.check.isZeroWidth(child)) continue;
682
+
683
+ if (/^\s{1,4}$/.test(child.textContent)) {
684
+ dom.utils.removeItem(child);
685
+ } else if (/^\s{1,4}/.test(child.textContent)) {
686
+ child.textContent = child.textContent.replace(/^\s{1,4}/, '');
687
+ }
688
+
689
+ break;
690
+ }
691
+ }
692
+
693
+ const firstChild = dom.query.getEdgeChild(lines[0], 'text', false);
694
+ const endChild = dom.query.getEdgeChild(lines[len], 'text', true);
695
+ if (!firstCell && firstChild) {
696
+ r.sc = firstChild;
697
+ r.so = 0;
698
+ }
699
+ if (!lastCell && endChild) {
700
+ r.ec = endChild;
701
+ r.eo = endChild.textContent.length;
702
+ }
703
+ }
704
+ }
705
+
706
+ this.selection.setRange(r.sc, r.so, r.ec, r.eo);
707
+ this.history.push(false);
708
+
709
+ break;
710
+ }
711
+ case 'Enter' /** enter key */: {
712
+ this.component.deselect();
713
+ const brBlock = this.format.getBrLine(selectionNode, null);
714
+
715
+ if (this.editor.frameOptions.get('charCounter_type') === 'byte-html') {
716
+ let enterHTML = '';
717
+ if ((!shift && brBlock) || shift) {
718
+ enterHTML = '<br>';
719
+ } else {
720
+ enterHTML = '<' + formatEl.nodeName + '><br></' + formatEl.nodeName + '>';
721
+ }
722
+
723
+ if (!this.char.check(enterHTML)) {
724
+ e.preventDefault();
725
+ return false;
726
+ }
727
+ }
728
+
729
+ if (!shift) {
730
+ const formatEndEdge = !range.endContainer.nextSibling && this.format.isEdgeLine(range.endContainer, range.endOffset, 'end');
731
+ const formatStartEdge = !range.startContainer.previousSibling && this.format.isEdgeLine(range.startContainer, range.startOffset, 'front');
732
+
733
+ // add default format line
734
+ if (formatEndEdge && (/^H[1-6]$/i.test(formatEl.nodeName) || /^HR$/i.test(formatEl.nodeName))) {
735
+ this.__enterPrevent(e);
736
+ const newFormat = this.format.addLine(formatEl, this.options.get('defaultLine'));
737
+ const temp = newFormat.firstChild;
738
+ if (dom.check.isBreak(temp)) {
739
+ const zeroWidth = dom.utils.createTextNode(unicode.zeroWidthSpace);
740
+ temp.parentNode.insertBefore(zeroWidth, temp);
741
+ this.selection.setRange(zeroWidth, 1, zeroWidth, 1);
742
+ } else {
743
+ this.selection.setRange(temp, 0, temp, 0);
744
+ }
745
+
746
+ // enter scroll
747
+ this.__enterScrollTo(range);
748
+ break;
749
+ } else if (rangeEl && formatEl && !dom.check.isTableCell(rangeEl) && !/^FIGCAPTION$/i.test(rangeEl.nodeName)) {
750
+ const rangeEnt = this.selection.getRange();
751
+ if (dom.check.isEdgePoint(rangeEnt.endContainer, rangeEnt.endOffset) && dom.check.isList(selectionNode.nextSibling)) {
752
+ this.__enterPrevent(e);
753
+ const br = dom.utils.createElement('BR');
754
+ const newEl = dom.utils.createElement('LI', null, br);
755
+
756
+ formatEl.parentNode.insertBefore(newEl, formatEl.nextElementSibling);
757
+ newEl.appendChild(selectionNode.nextSibling);
758
+
759
+ this.selection.setRange(br, 1, br, 1);
760
+
761
+ // enter scroll
762
+ this.__enterScrollTo(range);
763
+ break;
764
+ }
765
+
766
+ if (
767
+ (rangeEnt.commonAncestorContainer.nodeType === 3 ? !(/** @type {HTMLElement} */ (rangeEnt.commonAncestorContainer).nextElementSibling) : true) &&
768
+ dom.check.isZeroWidth(formatEl.innerText.trim()) &&
769
+ !dom.check.isListCell(formatEl.nextElementSibling)
770
+ ) {
771
+ this.__enterPrevent(e);
772
+ let newEl = null;
773
+
774
+ if (dom.check.isListCell(rangeEl.parentElement)) {
775
+ const parentLi = formatEl.parentNode.parentElement;
776
+ rangeEl = parentLi.parentElement;
777
+ const newListCell = dom.utils.createElement('LI');
778
+ newListCell.innerHTML = '<br>';
779
+ dom.utils.copyTagAttributes(newListCell, formatEl, this.options.get('lineAttrReset'));
780
+ newEl = newListCell;
781
+ rangeEl.insertBefore(newEl, parentLi.nextElementSibling);
782
+ } else {
783
+ let newFormat;
784
+ if (dom.check.isTableCell(rangeEl.parentElement)) {
785
+ newFormat = 'DIV';
786
+ } else if (dom.check.isList(rangeEl.parentElement)) {
787
+ newFormat = 'LI';
788
+ } else if (this.format.isLine(rangeEl.nextElementSibling)) {
789
+ newFormat = rangeEl.nextElementSibling.nodeName;
790
+ } else if (this.format.isLine(rangeEl.previousElementSibling)) {
791
+ newFormat = rangeEl.previousElementSibling.nodeName;
792
+ } else {
793
+ newFormat = this.options.get('defaultLine');
794
+ }
795
+
796
+ newEl = dom.utils.createElement(newFormat);
797
+ const edge = this.format.removeBlock(rangeEl, { selectedFormats: [formatEl], newBlockElement: null, shouldDelete: true, skipHistory: true });
798
+ edge.cc.insertBefore(newEl, edge.ec);
799
+ }
800
+
801
+ newEl.innerHTML = '<br>';
802
+ this.nodeTransform.removeAllParents(formatEl, null, null);
803
+ this.selection.setRange(newEl, 1, newEl, 1);
804
+ break;
805
+ }
806
+ }
807
+
808
+ if (brBlock) {
809
+ this.__enterPrevent(e);
810
+ const selectionFormat = selectionNode === brBlock;
811
+ const wSelection = this.selection.get();
812
+ const children = selectionNode.childNodes,
813
+ offset = wSelection.focusOffset,
814
+ prev = selectionNode.previousElementSibling,
815
+ next = selectionNode.nextSibling;
816
+
817
+ if (
818
+ !this.format.isClosureBrLine(brBlock) &&
819
+ children &&
820
+ ((selectionFormat &&
821
+ range.collapsed &&
822
+ children.length - 1 <= offset + 1 &&
823
+ dom.check.isBreak(children[offset]) &&
824
+ (!children[offset + 1] || ((!children[offset + 2] || dom.check.isZeroWidth(children[offset + 2].textContent)) && children[offset + 1].nodeType === 3 && dom.check.isZeroWidth(children[offset + 1].textContent))) &&
825
+ offset > 0 &&
826
+ dom.check.isBreak(children[offset - 1])) ||
827
+ (!selectionFormat &&
828
+ dom.check.isZeroWidth(selectionNode.textContent) &&
829
+ dom.check.isBreak(prev) &&
830
+ (dom.check.isBreak(prev.previousSibling) || !dom.check.isZeroWidth(prev.previousSibling?.textContent)) &&
831
+ (!next || (!dom.check.isBreak(next) && dom.check.isZeroWidth(next.textContent)))))
832
+ ) {
833
+ if (selectionFormat) dom.utils.removeItem(children[offset - 1]);
834
+ else dom.utils.removeItem(selectionNode);
835
+ const brBlockNext = /** @type {HTMLElement} */ (brBlock).nextElementSibling;
836
+ const newEl = this.format.addLine(brBlock, this.format.isLine(brBlockNext) ? brBlockNext : null);
837
+ dom.utils.copyFormatAttributes(newEl, brBlock);
838
+ this.selection.setRange(newEl, 1, newEl, 1);
839
+
840
+ // enter scroll
841
+ this.__enterScrollTo(range);
842
+ break;
843
+ }
844
+
845
+ if (selectionFormat) {
846
+ this.html.insert(range.collapsed && dom.check.isBreak(range.startContainer.childNodes[range.startOffset - 1]) ? '<br>' : '<br><br>', { selectInserted: false, skipCharCount: true, skipCleaning: true });
847
+
848
+ let focusNode = wSelection.focusNode;
849
+ const wOffset = wSelection.focusOffset;
850
+ if (brBlock === focusNode) {
851
+ focusNode = focusNode.childNodes[wOffset - offset > 1 ? wOffset - 1 : wOffset];
852
+ }
853
+
854
+ this.selection.setRange(focusNode, 1, focusNode, 1);
855
+ } else {
856
+ const focusNext = wSelection.focusNode.nextSibling;
857
+ const br = dom.utils.createElement('BR');
858
+ this.html.insertNode(br, { afterNode: null, skipCharCount: true });
859
+
860
+ const brPrev = br.previousSibling,
861
+ brNext = br.nextSibling;
862
+ if (!dom.check.isBreak(focusNext) && !dom.check.isBreak(brPrev) && (!brNext || dom.check.isZeroWidth(brNext))) {
863
+ br.parentNode.insertBefore(br.cloneNode(false), br);
864
+ this.selection.setRange(br, 1, br, 1);
865
+ } else {
866
+ this.selection.setRange(brNext, 0, brNext, 0);
867
+ }
868
+ }
869
+
870
+ this._onShortcutKey = true;
871
+
872
+ // enter scroll
873
+ this.__enterScrollTo(range);
874
+ break;
875
+ }
876
+
877
+ // set format attrs - edge
878
+ if (range.collapsed && (formatStartEdge || formatEndEdge)) {
879
+ this.__enterPrevent(e);
880
+ const focusBR = dom.utils.createElement('BR');
881
+ const newFormat = dom.utils.createElement(formatEl.nodeName, null, focusBR);
882
+
883
+ dom.utils.copyTagAttributes(newFormat, formatEl, this.options.get('lineAttrReset'));
884
+
885
+ let child = focusBR;
886
+ do {
887
+ if (!dom.check.isBreak(selectionNode) && selectionNode.nodeType === 1) {
888
+ const f = /** @type {HTMLElement} */ (selectionNode.cloneNode(false));
889
+ f.appendChild(child);
890
+ child = f;
891
+ }
892
+ selectionNode = selectionNode.parentElement;
893
+ } while (formatEl !== selectionNode && formatEl.contains(selectionNode));
894
+
895
+ newFormat.appendChild(child);
896
+ formatEl.parentNode.insertBefore(newFormat, formatStartEdge && !formatEndEdge ? formatEl : formatEl.nextElementSibling);
897
+ if (formatEndEdge) {
898
+ this.selection.setRange(focusBR, 1, focusBR, 1);
899
+ } else {
900
+ const firstEl = formatEl.firstChild || formatEl;
901
+ this.selection.setRange(firstEl, 0, firstEl, 0);
902
+ }
903
+
904
+ // enter scroll
905
+ this.__enterScrollTo(range);
906
+ break;
907
+ }
908
+
909
+ if (formatEl) {
910
+ e.stopPropagation();
911
+
912
+ /** @type {HTMLElement} */
913
+ let newEl;
914
+ let offset = 0;
915
+ if (!range.collapsed) {
916
+ const isMultiLine = this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null);
917
+ const newFormat = /** @type {HTMLElement} */ (formatEl.cloneNode(false));
918
+ newFormat.innerHTML = '<br>';
919
+ const commonCon = /** @type {HTMLElement} */ (range.commonAncestorContainer);
920
+ const rcon =
921
+ commonCon === range.startContainer && commonCon === range.endContainer && dom.check.isZeroWidth(commonCon)
922
+ ? { container: commonCon, offset: range.endOffset, prevContainer: commonCon.previousElementSibling, commonCon: commonCon }
923
+ : this.html.remove();
924
+ newEl = this.format.getLine(rcon.container, null);
925
+ if (!newEl) {
926
+ if (dom.check.isWysiwygFrame(rcon.container)) {
927
+ this.__enterPrevent(e);
928
+ fc.get('wysiwyg').appendChild(newFormat);
929
+ newEl = newFormat;
930
+ dom.utils.copyTagAttributes(newEl, formatEl, this.options.get('lineAttrReset'));
931
+ this.selection.setRange(newEl, offset, newEl, offset);
932
+ }
933
+
934
+ // enter scroll
935
+ this.__enterScrollTo(range);
936
+ break;
937
+ }
938
+
939
+ const innerRange = this.format.getBlock(rcon.container);
940
+ newEl = newEl.contains(innerRange) ? dom.query.getEdgeChild(innerRange, this.format.getLine.bind(this.format), false) : newEl;
941
+ if (isMultiLine) {
942
+ if (formatEndEdge && !formatStartEdge) {
943
+ newEl.parentNode.insertBefore(newFormat, !rcon.prevContainer || rcon.container === rcon.prevContainer ? newEl.nextElementSibling : newEl);
944
+ newEl = newFormat;
945
+ offset = 0;
946
+ } else {
947
+ offset = rcon.offset;
948
+ if (formatStartEdge) {
949
+ const tempEl = newEl.parentNode.insertBefore(newFormat, newEl);
950
+ if (formatEndEdge) {
951
+ newEl = tempEl;
952
+ offset = 0;
953
+ }
954
+ }
955
+ }
956
+ } else {
957
+ if (formatEndEdge && formatStartEdge) {
958
+ newEl.parentNode.insertBefore(newFormat, rcon.prevContainer && rcon.container === rcon.prevContainer ? newEl.nextElementSibling : newEl);
959
+ newEl = newFormat;
960
+ offset = 0;
961
+ } else if (formatEndEdge) {
962
+ newEl = newEl.parentNode.insertBefore(newFormat, newEl.nextElementSibling);
963
+ newEl = newFormat;
964
+ offset = 0;
965
+ } else {
966
+ newEl = this.nodeTransform.split(rcon.container, rcon.offset, dom.query.getNodeDepth(formatEl));
967
+ }
968
+ }
969
+ } else {
970
+ if (dom.check.isZeroWidth(formatEl)) {
971
+ newEl = this.format.addLine(formatEl, formatEl.cloneNode(false));
972
+ } else {
973
+ newEl = this.nodeTransform.split(range.endContainer, range.endOffset, dom.query.getNodeDepth(formatEl));
974
+ }
975
+ }
976
+
977
+ this.__enterPrevent(e);
978
+ dom.utils.copyTagAttributes(newEl, formatEl, this.options.get('lineAttrReset'));
979
+ this.selection.setRange(newEl, offset, newEl, offset);
980
+
981
+ // enter scroll
982
+ this.__enterScrollTo(range);
983
+ break;
984
+ }
985
+ }
986
+
987
+ if (selectRange) {
988
+ // enter scroll
989
+ this.__enterScrollTo(range);
990
+ break;
991
+ }
992
+
993
+ if (rangeEl && dom.query.getParentElement(rangeEl, 'FIGCAPTION') && dom.query.getParentElement(rangeEl, dom.check.isList)) {
994
+ this.__enterPrevent(e);
995
+ formatEl = this.format.addLine(formatEl, null);
996
+ this.selection.setRange(formatEl, 0, formatEl, 0);
997
+
998
+ // enter scroll
999
+ this.__enterScrollTo(range);
1000
+ }
1001
+
1002
+ break;
1003
+ }
1004
+ }
1005
+
1006
+ if (shift && (isOSX_IOS ? alt : ctrl) && keyCodeMap.isSpace(keyCode)) {
1007
+ e.preventDefault();
1008
+ e.stopPropagation();
1009
+ const nbsp = this.html.insertNode(dom.utils.createTextNode('\u00a0'), { afterNode: null, skipCharCount: true });
1010
+ if (nbsp) {
1011
+ this.selection.setRange(nbsp, nbsp.length, nbsp, nbsp.length);
1012
+ return;
1013
+ }
1014
+ }
1015
+
1016
+ if (!ctrl && !alt && !selectRange && !keyCodeMap.isNonTextKey(keyCode) && dom.check.isBreak(range.commonAncestorContainer)) {
1017
+ const zeroWidth = dom.utils.createTextNode(unicode.zeroWidthSpace);
1018
+ this.html.insertNode(zeroWidth, { afterNode: null, skipCharCount: true });
1019
+ this.selection.setRange(zeroWidth, 1, zeroWidth, 1);
1020
+ }
1021
+
1022
+ // document type
1023
+ if (fc.has('documentType-use-header') && !range.collapsed && !ctrl && !alt && !shift && !keyCodeMap.isDirectionKey(keyCode)) {
1024
+ _w.setTimeout(() => {
1025
+ fc.get('documentType').reHeader();
1026
+ }, 0);
1027
+ return;
1028
+ }
1029
+
1030
+ // next component
1031
+ let cmponentInfo = null;
1032
+ switch (keyCode) {
1033
+ case 'ArrowUp' /** up key */:
1034
+ if (this.component.is(formatEl.previousElementSibling)) {
1035
+ cmponentInfo = this.component.get(formatEl.previousElementSibling);
1036
+ }
1037
+ break;
1038
+ case 'ArrowLeft' /** left key */:
1039
+ if (dom.check.isEdgePoint(selectionNode, range.startOffset, 'front')) {
1040
+ const prevEl = selectionNode.previousElementSibling || dom.query.getPreviousDeepestNode(selectionNode);
1041
+ if (prevEl) {
1042
+ if (this.component.is(prevEl)) cmponentInfo = this.component.get(prevEl);
1043
+ } else if (this.component.is(formatEl.previousElementSibling)) {
1044
+ cmponentInfo = this.component.get(formatEl.previousElementSibling);
1045
+ }
1046
+ }
1047
+ break;
1048
+ case 'ArrowDown' /** down key */:
1049
+ if (this.component.is(formatEl.nextElementSibling)) {
1050
+ cmponentInfo = this.component.get(formatEl.nextElementSibling);
1051
+ }
1052
+ break;
1053
+ case 'ArrowRight' /** right key */:
1054
+ if (dom.check.isEdgePoint(selectionNode, range.endOffset, 'end')) {
1055
+ const nextEl = selectionNode.nextElementSibling || dom.query.getNextDeepestNode(selectionNode);
1056
+ if (nextEl) {
1057
+ if (this.component.is(nextEl)) cmponentInfo = this.component.get(nextEl);
1058
+ } else if (this.component.is(formatEl.nextElementSibling)) {
1059
+ cmponentInfo = this.component.get(formatEl.nextElementSibling);
1060
+ }
1061
+ }
1062
+ break;
1063
+ }
1064
+
1065
+ if (cmponentInfo && !cmponentInfo.options?.isInputComponent) {
1066
+ e.preventDefault();
1067
+ if (this.component.select(cmponentInfo.target, cmponentInfo.pluginName) === false) this.editor.blur();
1068
+ }
1069
+ }
1070
+
1071
+ /**
1072
+ * @private
1073
+ * @this {EventManagerThis_handler_ww_key_input}
1074
+ * @param {__se__FrameContext} fc - Frame context object
1075
+ * @param {KeyboardEvent} e - Event object
1076
+ */
1077
+ export async function OnKeyUp_wysiwyg(fc, e) {
1078
+ if (this._onShortcutKey || this.menu.currentDropdownName) return;
1079
+
1080
+ const keyCode = e.code;
1081
+ const ctrl = keyCodeMap.isCtrl(e);
1082
+ const alt = keyCodeMap.isAlt(e);
1083
+
1084
+ if (ctrl) keyState.ctrl = false;
1085
+ if (alt) keyState.alt = false;
1086
+
1087
+ if (fc.get('isReadOnly')) return;
1088
+
1089
+ const range = this.selection.getRange();
1090
+ let selectionNode = this.selection.getNode();
1091
+
1092
+ if ((this.editor.isBalloon || this.editor.isSubBalloon) && (((this.editor.isBalloonAlways || this.editor.isSubBalloonAlways) && !keyCodeMap.isEsc(keyCode)) || !range.collapsed)) {
1093
+ if (this.editor.isBalloonAlways || this.editor.isSubBalloonAlways) {
1094
+ if (!keyCodeMap.isEsc(keyCode)) this._showToolbarBalloonDelay();
1095
+ } else {
1096
+ if (this.editor.isSubBalloon) this.subToolbar._showBalloon();
1097
+ else this.toolbar._showBalloon();
1098
+ return;
1099
+ }
1100
+ }
1101
+
1102
+ /** when format tag deleted */
1103
+ if (keyCodeMap.isBackspace(keyCode) && dom.check.isWysiwygFrame(selectionNode) && selectionNode.textContent === '' && selectionNode.children.length === 0) {
1104
+ e.preventDefault();
1105
+ e.stopPropagation();
1106
+
1107
+ selectionNode.innerHTML = '';
1108
+
1109
+ const oFormatTag = dom.utils.createElement(this.format.isLine(this.status.currentNodes[0]) && !dom.check.isListCell(this.status.currentNodes[0]) ? this.status.currentNodes[0] : this.options.get('defaultLine'), null, '<br>');
1110
+ selectionNode.appendChild(oFormatTag);
1111
+ this.selection.setRange(oFormatTag, 0, oFormatTag, 0);
1112
+ this.applyTagEffect();
1113
+
1114
+ this.history.push(false);
1115
+
1116
+ // document type
1117
+ if (fc.has('documentType-use-header')) {
1118
+ if (keyCodeMap.isDocumentTypeObserverKey(keyCode)) {
1119
+ fc.get('documentType').reHeader();
1120
+ }
1121
+ }
1122
+
1123
+ return;
1124
+ }
1125
+
1126
+ const formatEl = this.format.getLine(selectionNode, null);
1127
+ const rangeEl = this.format.getBlock(selectionNode, null);
1128
+ const attrs = this._formatAttrsTemp;
1129
+
1130
+ if (formatEl && attrs) {
1131
+ for (let i = 0, len = attrs.length; i < len; i++) {
1132
+ if (keyCodeMap.isEnter(keyCode) && /^id$/i.test(attrs[i].name)) {
1133
+ formatEl.removeAttribute('id');
1134
+ continue;
1135
+ }
1136
+ formatEl.setAttribute(attrs[i].name, attrs[i].value);
1137
+ }
1138
+ this._formatAttrsTemp = null;
1139
+ }
1140
+
1141
+ if (!formatEl && range.collapsed && !this.component.is(selectionNode) && !dom.check.isList(selectionNode) && this._setDefaultLine(this.format.isBlock(rangeEl) ? 'DIV' : this.options.get('defaultLine')) !== null) {
1142
+ selectionNode = this.selection.getNode();
1143
+ }
1144
+
1145
+ const textKey = !keyState.ctrl && !keyState.alt && !keyCodeMap.isNonTextKey(keyCode);
1146
+ if (textKey && selectionNode.nodeType === 3 && unicode.zeroWidthRegExp.test(selectionNode.textContent) && !(e.isComposing !== undefined ? e.isComposing : this.isComposing)) {
1147
+ let so = range.startOffset,
1148
+ eo = range.endOffset;
1149
+ const frontZeroWidthCnt = (selectionNode.textContent.substring(0, eo).match(FRONT_ZEROWIDTH) || '').length;
1150
+ so = range.startOffset - frontZeroWidthCnt;
1151
+ eo = range.endOffset - frontZeroWidthCnt;
1152
+ selectionNode.textContent = selectionNode.textContent.replace(unicode.zeroWidthRegExp, '');
1153
+ this.selection.setRange(selectionNode, so < 0 ? 0 : so, selectionNode, eo < 0 ? 0 : eo);
1154
+ }
1155
+
1156
+ if (keyCodeMap.isRemoveKey(keyCode) && dom.check.isZeroWidth(formatEl?.textContent) && !formatEl.previousElementSibling) {
1157
+ const rsMode = this.options.get('retainStyleMode');
1158
+ if (rsMode !== 'none' && _styleNodes?.length > 0) {
1159
+ if (rsMode === 'repeat') {
1160
+ if (this.__retainTimer) {
1161
+ this.__retainTimer = _w.clearTimeout(this.__retainTimer);
1162
+ this._clearRetainStyleNodes(formatEl);
1163
+ } else {
1164
+ this.__retainTimer = _w.setTimeout(() => {
1165
+ this.__retainTimer = null;
1166
+ }, 0);
1167
+ this._retainStyleNodes(formatEl, _styleNodes);
1168
+ }
1169
+ } else {
1170
+ this.__retainTimer = null;
1171
+ this._retainStyleNodes(formatEl, _styleNodes);
1172
+ }
1173
+ } else {
1174
+ this._clearRetainStyleNodes(formatEl);
1175
+ }
1176
+ }
1177
+
1178
+ this.char.test('', false);
1179
+
1180
+ // document type
1181
+ if (fc.has('documentType-use-header')) {
1182
+ if (keyCodeMap.isDocumentTypeObserverKey(keyCode)) {
1183
+ fc.get('documentType').reHeader();
1184
+ const el = dom.query.getParentElement(this.selection.selectionNode, this.format.isLine.bind(this.format));
1185
+ fc.get('documentType').on(el);
1186
+ } else {
1187
+ const el = dom.query.getParentElement(selectionNode, (current) => current.nodeType === 1);
1188
+ fc.get('documentType').onChangeText(el);
1189
+ }
1190
+ }
1191
+
1192
+ // user event
1193
+ if ((await this.triggerEvent('onKeyUp', { frameContext: fc, event: e })) === false) return;
1194
+ // plugin event
1195
+ if (this._callPluginEvent('onKeyUp', { frameContext: fc, event: e, range, line: formatEl }) === false) return;
1196
+
1197
+ if (keyCodeMap.isHistoryRelevantKey(keyCode)) {
1198
+ this.history.push(true);
1199
+ }
1200
+ }