suneditor 2.46.2 → 3.0.0-alpha.1

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 (290) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.json +64 -0
  3. package/CONTRIBUTING.md +36 -0
  4. package/LICENSE.txt +1 -1
  5. package/README.md +174 -805
  6. package/dist/suneditor.min.css +1 -0
  7. package/dist/suneditor.min.js +1 -2
  8. package/package.json +96 -69
  9. package/src/assets/icons/_default.js +194 -0
  10. package/src/assets/suneditor-content.css +646 -0
  11. package/src/assets/suneditor.css +3378 -0
  12. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  13. package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
  14. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
  15. package/src/core/base/eventHandlers/handler_ww_key_input.js +975 -0
  16. package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
  17. package/src/core/base/eventManager.js +1115 -0
  18. package/src/core/base/events.js +320 -0
  19. package/src/core/base/history.js +301 -0
  20. package/src/core/class/char.js +146 -0
  21. package/src/core/class/component.js +627 -0
  22. package/src/core/class/format.js +3255 -0
  23. package/src/core/class/html.js +1621 -0
  24. package/src/core/class/menu.js +260 -0
  25. package/src/core/class/nodeTransform.js +379 -0
  26. package/src/core/class/notice.js +42 -0
  27. package/src/core/class/offset.js +578 -0
  28. package/src/core/class/selection.js +508 -0
  29. package/src/core/class/shortcuts.js +38 -0
  30. package/src/core/class/toolbar.js +440 -0
  31. package/src/core/class/viewer.js +646 -0
  32. package/src/core/editor.js +1593 -0
  33. package/src/core/section/actives.js +107 -0
  34. package/src/core/section/constructor.js +1237 -0
  35. package/src/core/section/context.js +97 -0
  36. package/src/editorInjector/_classes.js +22 -0
  37. package/src/editorInjector/_core.js +28 -0
  38. package/src/editorInjector/index.js +13 -0
  39. package/src/helper/converter.js +313 -0
  40. package/src/helper/domUtils.js +1177 -0
  41. package/src/helper/env.js +250 -0
  42. package/src/helper/index.js +19 -0
  43. package/src/helper/numbers.js +68 -0
  44. package/src/helper/unicode.js +43 -0
  45. package/src/langs/ckb.js +161 -0
  46. package/src/langs/cs.js +161 -0
  47. package/src/langs/da.js +161 -0
  48. package/src/langs/de.js +162 -0
  49. package/src/langs/en.js +199 -0
  50. package/src/langs/es.js +162 -0
  51. package/src/langs/fa.js +159 -0
  52. package/src/langs/fr.js +161 -0
  53. package/src/langs/he.js +162 -0
  54. package/src/{lang → langs}/index.js +0 -2
  55. package/src/langs/it.js +162 -0
  56. package/src/langs/ja.js +162 -0
  57. package/src/langs/ko.js +162 -0
  58. package/src/langs/lv.js +162 -0
  59. package/src/langs/nl.js +162 -0
  60. package/src/langs/pl.js +162 -0
  61. package/src/langs/pt_br.js +162 -0
  62. package/src/langs/ro.js +162 -0
  63. package/src/langs/ru.js +162 -0
  64. package/src/langs/se.js +162 -0
  65. package/src/langs/tr.js +159 -0
  66. package/src/langs/ua.js +162 -0
  67. package/src/langs/ur.js +162 -0
  68. package/src/langs/zh_cn.js +162 -0
  69. package/src/modules/ApiManager.js +168 -0
  70. package/src/modules/ColorPicker.js +302 -0
  71. package/src/modules/Controller.js +315 -0
  72. package/src/modules/Figure.js +1160 -0
  73. package/src/modules/FileBrowser.js +271 -0
  74. package/src/modules/FileManager.js +290 -0
  75. package/src/modules/HueSlider.js +513 -0
  76. package/src/modules/Modal.js +177 -0
  77. package/src/modules/ModalAnchorEditor.js +494 -0
  78. package/src/modules/SelectMenu.js +447 -0
  79. package/src/modules/_DragHandle.js +16 -0
  80. package/src/modules/index.js +14 -0
  81. package/src/plugins/command/blockquote.js +47 -47
  82. package/src/plugins/command/exportPdf.js +168 -0
  83. package/src/plugins/command/fileUpload.js +389 -0
  84. package/src/plugins/command/list_bulleted.js +112 -0
  85. package/src/plugins/command/list_numbered.js +115 -0
  86. package/src/plugins/dropdown/align.js +143 -0
  87. package/src/plugins/dropdown/backgroundColor.js +73 -0
  88. package/src/plugins/dropdown/font.js +113 -0
  89. package/src/plugins/dropdown/fontColor.js +73 -0
  90. package/src/plugins/dropdown/formatBlock.js +141 -0
  91. package/src/plugins/dropdown/hr.js +111 -0
  92. package/src/plugins/dropdown/layout.js +72 -0
  93. package/src/plugins/dropdown/lineHeight.js +114 -0
  94. package/src/plugins/dropdown/list.js +107 -0
  95. package/src/plugins/dropdown/paragraphStyle.js +117 -0
  96. package/src/plugins/dropdown/table.js +2810 -0
  97. package/src/plugins/dropdown/template.js +71 -0
  98. package/src/plugins/dropdown/textStyle.js +137 -0
  99. package/src/plugins/field/mention.js +172 -0
  100. package/src/plugins/fileBrowser/imageGallery.js +76 -59
  101. package/src/plugins/index.js +86 -24
  102. package/src/plugins/input/fontSize.js +357 -0
  103. package/src/plugins/modal/audio.js +510 -0
  104. package/src/plugins/modal/image.js +1062 -0
  105. package/src/plugins/modal/link.js +211 -0
  106. package/src/plugins/modal/math.js +347 -0
  107. package/src/plugins/modal/video.js +870 -0
  108. package/src/suneditor.js +62 -67
  109. package/src/themes/test.css +61 -0
  110. package/typings/CommandPlugin.d.ts +8 -0
  111. package/typings/DialogPlugin.d.ts +20 -0
  112. package/typings/FileBrowserPlugin.d.ts +30 -0
  113. package/typings/Lang.d.ts +124 -0
  114. package/typings/Module.d.ts +15 -0
  115. package/typings/Plugin.d.ts +42 -0
  116. package/typings/SubmenuPlugin.d.ts +8 -0
  117. package/typings/_classes.d.ts +17 -0
  118. package/typings/_colorPicker.d.ts +60 -0
  119. package/typings/_core.d.ts +55 -0
  120. package/typings/align.d.ts +5 -0
  121. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  122. package/typings/backgroundColor.d.ts +5 -0
  123. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  124. package/typings/char.d.ts +39 -0
  125. package/typings/component.d.ts +38 -0
  126. package/typings/context.d.ts +39 -0
  127. package/typings/converter.d.ts +33 -0
  128. package/typings/dialog.d.ts +28 -0
  129. package/typings/domUtils.d.ts +361 -0
  130. package/typings/editor.d.ts +7 -0
  131. package/typings/editor.ts +542 -0
  132. package/typings/env.d.ts +70 -0
  133. package/typings/eventManager.d.ts +37 -0
  134. package/typings/events.d.ts +262 -0
  135. package/typings/fileBrowser.d.ts +42 -0
  136. package/typings/fileManager.d.ts +67 -0
  137. package/typings/font.d.ts +5 -0
  138. package/typings/fontColor.d.ts +5 -0
  139. package/typings/fontSize.d.ts +5 -0
  140. package/typings/format.d.ts +191 -0
  141. package/typings/formatBlock.d.ts +5 -0
  142. package/typings/history.d.ts +48 -0
  143. package/typings/horizontalRule.d.ts +5 -0
  144. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  145. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  146. package/typings/index.d.ts +21 -0
  147. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  148. package/typings/index.plugins.d.ts +58 -0
  149. package/typings/lineHeight.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  151. package/typings/list.d.ts +5 -0
  152. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  153. package/typings/mediaContainer.d.ts +25 -0
  154. package/typings/node.d.ts +57 -0
  155. package/typings/notice.d.ts +16 -0
  156. package/typings/numbers.d.ts +29 -0
  157. package/typings/offset.d.ts +24 -0
  158. package/typings/options.d.ts +589 -0
  159. package/typings/paragraphStyle.d.ts +5 -0
  160. package/typings/resizing.d.ts +141 -0
  161. package/typings/selection.d.ts +94 -0
  162. package/typings/shortcuts.d.ts +13 -0
  163. package/typings/suneditor.d.ts +9 -0
  164. package/typings/table.d.ts +5 -0
  165. package/typings/template.d.ts +5 -0
  166. package/typings/textStyle.d.ts +5 -0
  167. package/typings/toolbar.d.ts +32 -0
  168. package/typings/unicode.d.ts +25 -0
  169. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  170. package/dist/css/suneditor.min.css +0 -1
  171. package/src/assets/css/suneditor-contents.css +0 -562
  172. package/src/assets/css/suneditor.css +0 -566
  173. package/src/assets/defaultIcons.js +0 -103
  174. package/src/lang/Lang.d.ts +0 -144
  175. package/src/lang/ckb.d.ts +0 -5
  176. package/src/lang/ckb.js +0 -188
  177. package/src/lang/cs.d.ts +0 -5
  178. package/src/lang/cs.js +0 -188
  179. package/src/lang/da.d.ts +0 -5
  180. package/src/lang/da.js +0 -191
  181. package/src/lang/de.d.ts +0 -5
  182. package/src/lang/de.js +0 -188
  183. package/src/lang/en.d.ts +0 -5
  184. package/src/lang/en.js +0 -188
  185. package/src/lang/es.d.ts +0 -5
  186. package/src/lang/es.js +0 -188
  187. package/src/lang/fa.d.ts +0 -5
  188. package/src/lang/fa.js +0 -188
  189. package/src/lang/fr.d.ts +0 -5
  190. package/src/lang/fr.js +0 -188
  191. package/src/lang/he.d.ts +0 -5
  192. package/src/lang/he.js +0 -188
  193. package/src/lang/index.d.ts +0 -23
  194. package/src/lang/it.d.ts +0 -5
  195. package/src/lang/it.js +0 -188
  196. package/src/lang/ja.d.ts +0 -5
  197. package/src/lang/ja.js +0 -188
  198. package/src/lang/ko.d.ts +0 -5
  199. package/src/lang/ko.js +0 -188
  200. package/src/lang/lv.d.ts +0 -5
  201. package/src/lang/lv.js +0 -188
  202. package/src/lang/nl.d.ts +0 -5
  203. package/src/lang/nl.js +0 -188
  204. package/src/lang/pl.d.ts +0 -5
  205. package/src/lang/pl.js +0 -188
  206. package/src/lang/pt_br.d.ts +0 -5
  207. package/src/lang/pt_br.js +0 -189
  208. package/src/lang/ro.d.ts +0 -5
  209. package/src/lang/ro.js +0 -188
  210. package/src/lang/ru.d.ts +0 -5
  211. package/src/lang/ru.js +0 -188
  212. package/src/lang/se.d.ts +0 -5
  213. package/src/lang/se.js +0 -191
  214. package/src/lang/tr.d.ts +0 -5
  215. package/src/lang/tr.js +0 -191
  216. package/src/lang/ua.d.ts +0 -5
  217. package/src/lang/ua.js +0 -188
  218. package/src/lang/ur.d.ts +0 -5
  219. package/src/lang/ur.js +0 -188
  220. package/src/lang/zh_cn.d.ts +0 -5
  221. package/src/lang/zh_cn.js +0 -187
  222. package/src/lib/constructor.js +0 -954
  223. package/src/lib/context.d.ts +0 -42
  224. package/src/lib/context.js +0 -71
  225. package/src/lib/core.d.ts +0 -1135
  226. package/src/lib/core.js +0 -9395
  227. package/src/lib/history.d.ts +0 -48
  228. package/src/lib/history.js +0 -219
  229. package/src/lib/util.d.ts +0 -678
  230. package/src/lib/util.js +0 -2131
  231. package/src/options.d.ts +0 -608
  232. package/src/plugins/CommandPlugin.d.ts +0 -8
  233. package/src/plugins/DialogPlugin.d.ts +0 -20
  234. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  235. package/src/plugins/Module.d.ts +0 -15
  236. package/src/plugins/Plugin.d.ts +0 -42
  237. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  238. package/src/plugins/dialog/audio.js +0 -559
  239. package/src/plugins/dialog/image.js +0 -1126
  240. package/src/plugins/dialog/link.js +0 -223
  241. package/src/plugins/dialog/math.js +0 -295
  242. package/src/plugins/dialog/mention.js +0 -242
  243. package/src/plugins/dialog/video.js +0 -979
  244. package/src/plugins/index.d.ts +0 -79
  245. package/src/plugins/modules/_anchor.js +0 -461
  246. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  247. package/src/plugins/modules/_colorPicker.js +0 -201
  248. package/src/plugins/modules/_notice.d.ts +0 -21
  249. package/src/plugins/modules/_notice.js +0 -72
  250. package/src/plugins/modules/_selectMenu.js +0 -119
  251. package/src/plugins/modules/component.d.ts +0 -25
  252. package/src/plugins/modules/component.js +0 -81
  253. package/src/plugins/modules/dialog.d.ts +0 -28
  254. package/src/plugins/modules/dialog.js +0 -175
  255. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  256. package/src/plugins/modules/fileBrowser.js +0 -374
  257. package/src/plugins/modules/fileManager.d.ts +0 -67
  258. package/src/plugins/modules/fileManager.js +0 -326
  259. package/src/plugins/modules/index.js +0 -9
  260. package/src/plugins/modules/resizing.d.ts +0 -154
  261. package/src/plugins/modules/resizing.js +0 -903
  262. package/src/plugins/submenu/align.d.ts +0 -5
  263. package/src/plugins/submenu/align.js +0 -160
  264. package/src/plugins/submenu/font.d.ts +0 -5
  265. package/src/plugins/submenu/font.js +0 -123
  266. package/src/plugins/submenu/fontColor.d.ts +0 -5
  267. package/src/plugins/submenu/fontColor.js +0 -101
  268. package/src/plugins/submenu/fontSize.d.ts +0 -5
  269. package/src/plugins/submenu/fontSize.js +0 -112
  270. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  271. package/src/plugins/submenu/formatBlock.js +0 -273
  272. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  273. package/src/plugins/submenu/hiliteColor.js +0 -102
  274. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  275. package/src/plugins/submenu/horizontalRule.js +0 -98
  276. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  277. package/src/plugins/submenu/lineHeight.js +0 -104
  278. package/src/plugins/submenu/list.d.ts +0 -5
  279. package/src/plugins/submenu/list.js +0 -456
  280. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  281. package/src/plugins/submenu/paragraphStyle.js +0 -135
  282. package/src/plugins/submenu/table.d.ts +0 -5
  283. package/src/plugins/submenu/table.js +0 -1431
  284. package/src/plugins/submenu/template.d.ts +0 -5
  285. package/src/plugins/submenu/template.js +0 -72
  286. package/src/plugins/submenu/textStyle.d.ts +0 -5
  287. package/src/plugins/submenu/textStyle.js +0 -167
  288. package/src/suneditor.d.ts +0 -9
  289. package/src/suneditor_build.js +0 -18
  290. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -0,0 +1,975 @@
1
+ import { domUtils, env, unicode } from '../../../helper';
2
+
3
+ const { _w, isOSX_IOS } = env;
4
+ const DIRECTION_KEYCODE = /^(8|3[2-9]|40|46)$/;
5
+ const DIR_KEYCODE = /^(3[7-9]|40)$/;
6
+ const DELETE_KEYCODE = /^(8|46)$/;
7
+ const NON_TEXT_KEYCODE = /^(8|13|1[6-9]|20|27|3[3-9]|40|45|46|11[2-9]|12[0-3]|144|145|229)$/;
8
+ const HISTORY_IGNORE_KEYCODE = /^(1[6-9]|20|27|3[3-9]|40|45|11[2-9]|12[0-3]|144|145|229)$/;
9
+ const FRONT_ZEROWIDTH = new RegExp(unicode.zeroWidthSpace + '+', '');
10
+ let _styleNodes = null;
11
+
12
+ export function OnInput_wysiwyg(frameContext, e) {
13
+ if (frameContext.get('isReadOnly') || frameContext.get('isDisabled')) {
14
+ e.preventDefault();
15
+ e.stopPropagation();
16
+ return false;
17
+ }
18
+
19
+ this.selection._init();
20
+
21
+ const data = (e.data === null ? '' : e.data === undefined ? ' ' : e.data) || '';
22
+ if (!this.char.test(data, true)) {
23
+ e.preventDefault();
24
+ e.stopPropagation();
25
+ return false;
26
+ }
27
+
28
+ // user event
29
+ if (this.triggerEvent('onInput', { frameContext, event: e, data }) === false) return;
30
+ // plugin event
31
+ if (this._callPluginEvent('onInput', { frameContext, event: e, data }) === false) return;
32
+
33
+ this.history.push(true);
34
+ }
35
+
36
+ export function OnKeyDown_wysiwyg(frameContext, e) {
37
+ if (this.editor.selectMenuOn || !e.isTrusted) return;
38
+
39
+ let selectionNode = this.selection.getNode();
40
+ if (domUtils.isInputElement(selectionNode)) return;
41
+ if (this.menu.currentDropdownName) return;
42
+
43
+ const keyCode = e.keyCode;
44
+ const shift = e.shiftKey;
45
+ const ctrl = e.ctrlKey || e.metaKey || keyCode === 91 || keyCode === 92 || keyCode === 224;
46
+ const alt = e.altKey;
47
+ this.isComposing = keyCode === 229;
48
+
49
+ if (!ctrl && frameContext.get('isReadOnly') && !DIRECTION_KEYCODE.test(keyCode)) {
50
+ e.preventDefault();
51
+ return false;
52
+ }
53
+
54
+ this.menu.dropdownOff();
55
+
56
+ if (this.editor.isBalloon) {
57
+ this._hideToolbar();
58
+ } else if (this.editor.isSubBalloon) {
59
+ this._hideToolbar_sub();
60
+ }
61
+
62
+ // user event
63
+ if (this.triggerEvent('onKeyDown', { frameContext, event: e }) === false) return;
64
+
65
+ /** Shortcuts */
66
+ if (ctrl && this.shortcuts.command(keyCode, shift)) {
67
+ this._onShortcutKey = true;
68
+ e.preventDefault();
69
+ e.stopPropagation();
70
+ return false;
71
+ } else if (this._onShortcutKey) {
72
+ this._onShortcutKey = false;
73
+ }
74
+
75
+ /** default key action */
76
+ const range = this.selection.getRange();
77
+ const selectRange = !range.collapsed || range.startContainer !== range.endContainer;
78
+ let formatEl = this.format.getLine(selectionNode, null) || selectionNode;
79
+ let rangeEl = this.format.getBlock(formatEl, null);
80
+
81
+ // plugin event
82
+ if (this._callPluginEvent('onKeyDown', { frameContext, event: e, range, line: formatEl }) === false) return;
83
+
84
+ switch (keyCode) {
85
+ case 8 /** backspace key */: {
86
+ _styleNodes = this.__cacheStyleNodes;
87
+ if (selectRange && this._hardDelete()) {
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ break;
91
+ }
92
+
93
+ if (!this.format.isLine(formatEl) && !frameContext.get('wysiwyg').firstElementChild && !this.component.is(selectionNode) && this._setDefaultLine(this.options.get('defaultLine')) !== null) {
94
+ e.preventDefault();
95
+ e.stopPropagation();
96
+ return false;
97
+ }
98
+
99
+ if (
100
+ !selectRange &&
101
+ !formatEl.previousElementSibling &&
102
+ range.startOffset === 0 &&
103
+ !selectionNode.previousSibling &&
104
+ !domUtils.isListCell(formatEl) &&
105
+ this.format.isLine(formatEl) &&
106
+ (!this.format.isBrLine(formatEl) || this.format.isClosureBrLine(formatEl))
107
+ ) {
108
+ // closure range
109
+ if (this.format.isClosureBlock(formatEl.parentNode)) {
110
+ e.preventDefault();
111
+ e.stopPropagation();
112
+ return false;
113
+ }
114
+ // maintain default format
115
+ if (domUtils.isWysiwygFrame(formatEl.parentNode) && formatEl.childNodes.length <= 1 && (!formatEl.firstChild || domUtils.isZeroWith(formatEl.textContent))) {
116
+ e.preventDefault();
117
+ e.stopPropagation();
118
+
119
+ if (formatEl.nodeName.toUpperCase() === this.options.get('defaultLine').toUpperCase()) {
120
+ formatEl.innerHTML = '<br>';
121
+ const attrs = formatEl.attributes;
122
+ while (attrs[0]) {
123
+ formatEl.removeAttribute(attrs[0].name);
124
+ }
125
+ } else {
126
+ formatEl.parentElement.replaceChild(domUtils.createElement(this.options.get('defaultLine'), null, '<br>'), formatEl);
127
+ }
128
+
129
+ this.editor._nativeFocus();
130
+ return false;
131
+ }
132
+ }
133
+
134
+ // clean remove tag
135
+ const startCon = range.startContainer;
136
+ if (formatEl && !formatEl.previousElementSibling && range.startOffset === 0 && startCon.nodeType === 3 && domUtils.isZeroWith(startCon)) {
137
+ let prev = startCon.parentNode.previousSibling;
138
+ const next = startCon.parentNode.nextSibling;
139
+ if (!prev) {
140
+ if (!next) {
141
+ prev = domUtils.createElement('BR');
142
+ formatEl.appendChild(prev);
143
+ } else {
144
+ prev = next;
145
+ }
146
+ }
147
+
148
+ let con = startCon;
149
+ while (formatEl.contains(con) && !con.previousSibling) {
150
+ con = con.parentNode;
151
+ }
152
+
153
+ if (!formatEl.contains(con)) {
154
+ startCon.textContent = '';
155
+ this.nodeTransform.removeAllParents(startCon, null, formatEl);
156
+ break;
157
+ }
158
+ }
159
+
160
+ // line component
161
+ if (!selectRange && formatEl && (range.startOffset === 0 || selectionNode === formatEl)) {
162
+ const sel = selectionNode === formatEl ? this._isUneditableNode(range, true) : domUtils.isEdgePoint(range.startContainer, range.startOffset) ? domUtils.getPreviousDeepestNode(range.startContainer) : null;
163
+ if (this.component.is(sel)) {
164
+ const fileComponentInfo = this.component.get(sel);
165
+ if (fileComponentInfo) {
166
+ e.preventDefault();
167
+ e.stopPropagation();
168
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName, false) === false) this.editor.blur();
169
+ break;
170
+ }
171
+ }
172
+ }
173
+
174
+ // tag[contenteditable='false']
175
+ if (this._isUneditableNode(range, true)) {
176
+ e.preventDefault();
177
+ e.stopPropagation();
178
+ break;
179
+ }
180
+
181
+ // format attributes
182
+ if (!selectRange && this.format.isEdgeLine(range.startContainer, range.startOffset, 'start')) {
183
+ if (this.format.isLine(formatEl.previousElementSibling)) {
184
+ this._formatAttrsTemp = formatEl.previousElementSibling.attributes;
185
+ }
186
+ }
187
+
188
+ // nested list
189
+ const commonCon = range.commonAncestorContainer;
190
+ formatEl = this.format.getLine(range.startContainer, null);
191
+ rangeEl = this.format.getBlock(formatEl, null);
192
+ if (rangeEl && formatEl && !domUtils.isTableCell(rangeEl) && !/^FIGCAPTION$/i.test(rangeEl.nodeName)) {
193
+ if (
194
+ domUtils.isListCell(formatEl) &&
195
+ domUtils.isList(rangeEl) &&
196
+ (domUtils.isListCell(rangeEl.parentNode) || formatEl.previousElementSibling) &&
197
+ (selectionNode === formatEl || (selectionNode.nodeType === 3 && (!selectionNode.previousSibling || domUtils.isList(selectionNode.previousSibling)))) &&
198
+ (this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null) ? rangeEl.contains(range.startContainer) : range.startOffset === 0 && range.collapsed)
199
+ ) {
200
+ if (range.startContainer !== range.endContainer) {
201
+ e.preventDefault();
202
+
203
+ this.html.remove();
204
+ if (range.startContainer.nodeType === 3) {
205
+ this.selection.setRange(range.startContainer, range.startContainer.textContent.length, range.startContainer, range.startContainer.textContent.length);
206
+ }
207
+
208
+ this.history.push(true);
209
+ } else {
210
+ let prev = formatEl.previousElementSibling || rangeEl.parentNode;
211
+ if (domUtils.isListCell(prev)) {
212
+ e.preventDefault();
213
+
214
+ let prevLast = prev;
215
+ if (!prev.contains(formatEl) && domUtils.isListCell(prevLast) && domUtils.isList(prevLast.lastElementChild)) {
216
+ prevLast = prevLast.lastElementChild.lastElementChild;
217
+ while (domUtils.isListCell(prevLast) && domUtils.isList(prevLast.lastElementChild)) {
218
+ prevLast = prevLast.lastElementChild && prevLast.lastElementChild.lastElementChild;
219
+ }
220
+ prev = prevLast;
221
+ }
222
+
223
+ let con = prev === rangeEl.parentNode ? rangeEl.previousSibling : prev.lastChild;
224
+ if (!con) {
225
+ con = domUtils.createTextNode(unicode.zeroWidthSpace);
226
+ rangeEl.parentNode.insertBefore(con, rangeEl.parentNode.firstChild);
227
+ }
228
+ const offset = con.nodeType === 3 ? con.textContent.length : 1;
229
+ const children = formatEl.childNodes;
230
+ let after = con;
231
+ let child = children[0];
232
+ while ((child = children[0])) {
233
+ prev.insertBefore(child, after.nextSibling);
234
+ after = child;
235
+ }
236
+
237
+ domUtils.removeItem(formatEl);
238
+ if (rangeEl.children.length === 0) domUtils.removeItem(rangeEl);
239
+
240
+ this.selection.setRange(con, offset, con, offset);
241
+ this.history.push(true);
242
+ }
243
+ }
244
+
245
+ break;
246
+ }
247
+
248
+ // detach range
249
+ if (!selectRange && range.startOffset === 0) {
250
+ let detach = true;
251
+ let comm = commonCon;
252
+ while (comm && comm !== rangeEl && !domUtils.isWysiwygFrame(comm)) {
253
+ if (comm.previousSibling) {
254
+ if (comm.previousSibling.nodeType === 1 || !domUtils.isZeroWith(comm.previousSibling.textContent.trim())) {
255
+ detach = false;
256
+ break;
257
+ }
258
+ }
259
+ comm = comm.parentNode;
260
+ }
261
+
262
+ if (detach && rangeEl.parentNode) {
263
+ e.preventDefault();
264
+ this.format.removeBlock(rangeEl, domUtils.isListCell(formatEl) ? [formatEl] : null, null, false, false);
265
+ this.history.push(true);
266
+ break;
267
+ }
268
+ }
269
+ }
270
+
271
+ // component
272
+ if (!selectRange && formatEl && (range.startOffset === 0 || (selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : false))) {
273
+ const sel = selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : selectionNode;
274
+ const prev = formatEl.previousSibling;
275
+ // select file component
276
+ const ignoreZWS = (commonCon.nodeType === 3 || domUtils.isBreak(commonCon)) && !commonCon.previousSibling && range.startOffset === 0;
277
+ if (sel && !sel.previousSibling && ((commonCon && this.component.is(commonCon.previousSibling)) || (ignoreZWS && this.component.is(prev)))) {
278
+ const fileComponentInfo = this.component.get(prev);
279
+ if (fileComponentInfo) {
280
+ e.preventDefault();
281
+ e.stopPropagation();
282
+ if (formatEl.textContent.length === 0) domUtils.removeItem(formatEl);
283
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName, false) === false) this.editor.blur();
284
+ } else if (this.component.is(prev)) {
285
+ e.preventDefault();
286
+ e.stopPropagation();
287
+ domUtils.removeItem(prev);
288
+ }
289
+ break;
290
+ }
291
+ // delete nonEditable
292
+ if (sel && domUtils.isNonEditable(sel.previousSibling)) {
293
+ e.preventDefault();
294
+ e.stopPropagation();
295
+ domUtils.removeItem(sel.previousSibling);
296
+ break;
297
+ }
298
+ }
299
+
300
+ break;
301
+ }
302
+ case 46 /** delete key */: {
303
+ _styleNodes = this.__cacheStyleNodes;
304
+ if (selectRange && this._hardDelete()) {
305
+ e.preventDefault();
306
+ e.stopPropagation();
307
+ break;
308
+ }
309
+
310
+ // line component
311
+ if (!selectRange && formatEl && (range.endOffset === range.endContainer.textContent.length || selectionNode === formatEl)) {
312
+ const sel = selectionNode === formatEl ? this._isUneditableNode(range, false) : domUtils.isEdgePoint(range.endContainer, range.endOffset) ? domUtils.getNextDeepestNode(range.endContainer, null) : null;
313
+ if (this.component.is(sel)) {
314
+ const fileComponentInfo = this.component.get(sel);
315
+ if (fileComponentInfo) {
316
+ e.preventDefault();
317
+ e.stopPropagation();
318
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName, false) === false) this.editor.blur();
319
+ break;
320
+ }
321
+ }
322
+ }
323
+
324
+ // tag[contenteditable='false']
325
+ if (this._isUneditableNode(range, false)) {
326
+ e.preventDefault();
327
+ e.stopPropagation();
328
+ break;
329
+ }
330
+
331
+ // component
332
+ if (
333
+ (this.format.isLine(selectionNode) || selectionNode.nextSibling === null || (domUtils.isZeroWith(selectionNode.nextSibling) && selectionNode.nextSibling.nextSibling === null)) &&
334
+ range.startOffset === selectionNode.textContent.length
335
+ ) {
336
+ const nextEl = formatEl.nextElementSibling;
337
+ if (!nextEl) break;
338
+ if (this.component.is(nextEl)) {
339
+ e.preventDefault();
340
+
341
+ if (domUtils.isZeroWith(formatEl)) {
342
+ domUtils.removeItem(formatEl);
343
+ // table component
344
+ if (domUtils.isTable(nextEl)) {
345
+ let cell = domUtils.getEdgeChild(nextEl, domUtils.isTableCell, false);
346
+ cell = cell.firstElementChild || cell;
347
+ this.selection.setRange(cell, 0, cell, 0);
348
+ break;
349
+ }
350
+ }
351
+
352
+ // select file component
353
+ const fileComponentInfo = this.component.get(nextEl);
354
+ if (fileComponentInfo) {
355
+ e.stopPropagation();
356
+ if (this.component.select(fileComponentInfo.target, fileComponentInfo.pluginName, false) === false) this.editor.blur();
357
+ } else if (this.component.is(nextEl)) {
358
+ e.stopPropagation();
359
+ domUtils.removeItem(nextEl);
360
+ }
361
+
362
+ break;
363
+ }
364
+ }
365
+
366
+ if (!selectRange && (domUtils.isEdgePoint(range.endContainer, range.endOffset) || (selectionNode === formatEl ? formatEl.childNodes[range.startOffset] : false))) {
367
+ const sel = selectionNode === formatEl ? formatEl.childNodes[range.startOffset] || selectionNode : selectionNode;
368
+ // delete nonEditable
369
+ if (sel && domUtils.isNonEditable(sel.nextSibling)) {
370
+ e.preventDefault();
371
+ e.stopPropagation();
372
+ domUtils.removeItem(sel.nextSibling);
373
+ break;
374
+ } else if (this.component.is(sel)) {
375
+ e.preventDefault();
376
+ e.stopPropagation();
377
+ domUtils.removeItem(sel);
378
+ break;
379
+ }
380
+ }
381
+
382
+ // format attributes
383
+ if (!selectRange && this.format.isEdgeLine(range.endContainer, range.endOffset, 'end')) {
384
+ if (this.format.isLine(formatEl.nextElementSibling)) {
385
+ this._formatAttrsTemp = formatEl.attributes;
386
+ }
387
+ }
388
+
389
+ // nested list
390
+ formatEl = this.format.getLine(range.startContainer, null);
391
+ rangeEl = this.format.getBlock(formatEl, null);
392
+ if (
393
+ domUtils.isListCell(formatEl) &&
394
+ domUtils.isList(rangeEl) &&
395
+ (selectionNode === formatEl ||
396
+ (selectionNode.nodeType === 3 &&
397
+ (!selectionNode.nextSibling || domUtils.isList(selectionNode.nextSibling)) &&
398
+ (this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null) ? rangeEl.contains(range.endContainer) : range.endOffset === selectionNode.textContent.length && range.collapsed)))
399
+ ) {
400
+ if (range.startContainer !== range.endContainer) this.html.remove();
401
+
402
+ let next = domUtils.getArrayItem(formatEl.children, domUtils.isList, false);
403
+ next = next || formatEl.nextElementSibling || rangeEl.parentNode.nextElementSibling;
404
+ if (next && (domUtils.isList(next) || domUtils.getArrayItem(next.children, domUtils.isList, false))) {
405
+ e.preventDefault();
406
+
407
+ let con, children;
408
+ if (domUtils.isList(next)) {
409
+ const child = next.firstElementChild;
410
+ children = child.childNodes;
411
+ con = children[0];
412
+ while (children[0]) {
413
+ formatEl.insertBefore(children[0], next);
414
+ }
415
+ domUtils.removeItem(child);
416
+ } else {
417
+ con = next.firstChild;
418
+ children = next.childNodes;
419
+ while (children[0]) {
420
+ formatEl.appendChild(children[0]);
421
+ }
422
+ domUtils.removeItem(next);
423
+ }
424
+ this.selection.setRange(con, 0, con, 0);
425
+ this.history.push(true);
426
+ }
427
+ break;
428
+ }
429
+
430
+ break;
431
+ }
432
+ case 9 /** tab key */: {
433
+ if (this.options.get('tabDisable')) break;
434
+ e.preventDefault();
435
+ if (ctrl || alt || domUtils.isWysiwygFrame(selectionNode)) break;
436
+
437
+ const isEdge = !range.collapsed || domUtils.isEdgePoint(range.startContainer, range.startOffset);
438
+ const selectedFormats = this.format.getLines(null);
439
+ selectionNode = this.selection.getNode();
440
+ const cells = [];
441
+ const lines = [];
442
+ const fc = domUtils.isListCell(selectedFormats[0]),
443
+ lc = domUtils.isListCell(selectedFormats[selectedFormats.length - 1]);
444
+ let r = {
445
+ sc: range.startContainer,
446
+ so: range.startOffset,
447
+ ec: range.endContainer,
448
+ eo: range.endOffset
449
+ };
450
+ for (let i = 0, len = selectedFormats.length, f; i < len; i++) {
451
+ f = selectedFormats[i];
452
+ if (domUtils.isListCell(f)) {
453
+ if (!f.previousElementSibling && !shift) {
454
+ continue;
455
+ } else {
456
+ cells.push(f);
457
+ }
458
+ } else {
459
+ lines.push(f);
460
+ }
461
+ }
462
+
463
+ // Nested list
464
+ if (cells.length > 0 && isEdge) {
465
+ r = this.format._applyNestedList(cells, shift);
466
+ }
467
+
468
+ // Lines tab(4)
469
+ if (lines.length > 0) {
470
+ if (!shift) {
471
+ const tabText = domUtils.createTextNode(new Array(this.status.tabSize + 1).join('\u00A0'));
472
+ if (lines.length === 1) {
473
+ const textRange = this.html.insertNode(tabText, null, false);
474
+ if (!textRange) return false;
475
+ if (!fc) {
476
+ r.sc = tabText;
477
+ r.so = textRange.endOffset;
478
+ }
479
+ if (!lc) {
480
+ r.ec = tabText;
481
+ r.eo = textRange.endOffset;
482
+ }
483
+ } else {
484
+ const len = lines.length - 1;
485
+ for (let i = 0, child; i <= len; i++) {
486
+ child = lines[i].firstChild;
487
+ if (!child) continue;
488
+
489
+ if (domUtils.isBreak(child)) {
490
+ lines[i].insertBefore(tabText.cloneNode(false), child);
491
+ } else {
492
+ child.textContent = tabText.textContent + child.textContent;
493
+ }
494
+ }
495
+
496
+ const firstChild = domUtils.getEdgeChild(lines[0], 'text', false);
497
+ const endChild = domUtils.getEdgeChild(lines[len], 'text', true);
498
+ if (!fc && firstChild) {
499
+ r.sc = firstChild;
500
+ r.so = 0;
501
+ }
502
+ if (!lc && endChild) {
503
+ r.ec = endChild;
504
+ r.eo = endChild.textContent.length;
505
+ }
506
+ }
507
+ } else {
508
+ const len = lines.length - 1;
509
+ for (let i = 0, line; i <= len; i++) {
510
+ line = lines[i].childNodes;
511
+ for (let c = 0, cLen = line.length, child; c < cLen; c++) {
512
+ child = line[c];
513
+ if (!child) break;
514
+ if (domUtils.isZeroWith(child)) continue;
515
+
516
+ if (/^\s{1,4}$/.test(child.textContent)) {
517
+ domUtils.removeItem(child);
518
+ } else if (/^\s{1,4}/.test(child.textContent)) {
519
+ child.textContent = child.textContent.replace(/^\s{1,4}/, '');
520
+ }
521
+
522
+ break;
523
+ }
524
+ }
525
+
526
+ const firstChild = domUtils.getEdgeChild(lines[0], 'text', false);
527
+ const endChild = domUtils.getEdgeChild(lines[len], 'text', true);
528
+ if (!fc && firstChild) {
529
+ r.sc = firstChild;
530
+ r.so = 0;
531
+ }
532
+ if (!lc && endChild) {
533
+ r.ec = endChild;
534
+ r.eo = endChild.textContent.length;
535
+ }
536
+ }
537
+ }
538
+
539
+ this.selection.setRange(r.sc, r.so, r.ec, r.eo);
540
+ this.history.push(false);
541
+
542
+ break;
543
+ }
544
+ case 13 /** enter key */: {
545
+ const brBlock = this.format.getBrLine(selectionNode, null);
546
+
547
+ if (this.editor.frameOptions.get('charCounter_type') === 'byte-html') {
548
+ let enterHTML = '';
549
+ if ((!shift && brBlock) || shift) {
550
+ enterHTML = '<br>';
551
+ } else {
552
+ enterHTML = '<' + formatEl.nodeName + '><br></' + formatEl.nodeName + '>';
553
+ }
554
+
555
+ if (!this.char.check(enterHTML)) {
556
+ e.preventDefault();
557
+ return false;
558
+ }
559
+ }
560
+
561
+ if (!shift) {
562
+ const formatEndEdge = this.format.isEdgeLine(range.endContainer, range.endOffset, 'end');
563
+ const formatStartEdge = this.format.isEdgeLine(range.startContainer, range.startOffset, 'start');
564
+
565
+ // add default format line
566
+ if (formatEndEdge && (/^H[1-6]$/i.test(formatEl.nodeName) || /^HR$/i.test(formatEl.nodeName))) {
567
+ this.__enterPrevent(e);
568
+ let temp = null;
569
+ const newFormat = this.format.addLine(formatEl, this.options.get('defaultLine'));
570
+
571
+ if (formatEndEdge && formatEndEdge.length > 0) {
572
+ temp = formatEndEdge.pop();
573
+ const innerNode = temp;
574
+ while (formatEndEdge.length > 0) {
575
+ temp = temp.appendChild(formatEndEdge.pop());
576
+ }
577
+ newFormat.appendChild(innerNode);
578
+ }
579
+
580
+ temp = !temp ? newFormat.firstChild : temp.appendChild(newFormat.firstChild);
581
+ if (domUtils.isBreak(temp)) {
582
+ const zeroWidth = domUtils.createTextNode(unicode.zeroWidthSpace);
583
+ temp.parentNode.insertBefore(zeroWidth, temp);
584
+ this.selection.setRange(zeroWidth, 1, zeroWidth, 1);
585
+ } else {
586
+ this.selection.setRange(temp, 0, temp, 0);
587
+ }
588
+ break;
589
+ } else if (rangeEl && formatEl && !domUtils.isTableCell(rangeEl) && !/^FIGCAPTION$/i.test(rangeEl.nodeName)) {
590
+ const rangeEnt = this.selection.getRange();
591
+ if (domUtils.isEdgePoint(rangeEnt.endContainer, rangeEnt.endOffset) && domUtils.isList(selectionNode.nextSibling)) {
592
+ this.__enterPrevent(e);
593
+ const br = domUtils.createElement('BR');
594
+ const newEl = domUtils.createElement('LI', null, br);
595
+
596
+ formatEl.parentNode.insertBefore(newEl, formatEl.nextElementSibling);
597
+ newEl.appendChild(selectionNode.nextSibling);
598
+
599
+ this.selection.setRange(br, 1, br, 1);
600
+ break;
601
+ }
602
+
603
+ if (
604
+ (rangeEnt.commonAncestorContainer.nodeType === 3 ? !rangeEnt.commonAncestorContainer.nextElementSibling : true) &&
605
+ domUtils.isZeroWith(formatEl.innerText.trim()) &&
606
+ !domUtils.isListCell(formatEl.nextElementSibling)
607
+ ) {
608
+ this.__enterPrevent(e);
609
+ let newEl = null;
610
+
611
+ if (domUtils.isListCell(rangeEl.parentNode)) {
612
+ const parentLi = formatEl.parentNode.parentNode;
613
+ rangeEl = parentLi.parentNode;
614
+ const newListCell = domUtils.createElement('LI');
615
+ newListCell.innerHTML = '<br>';
616
+ domUtils.copyTagAttributes(newListCell, formatEl, this.options.get('lineAttrReset'));
617
+ newEl = newListCell;
618
+ rangeEl.insertBefore(newEl, parentLi.nextElementSibling);
619
+ } else {
620
+ let newFormat;
621
+ if (domUtils.isTableCell(rangeEl.parentNode)) {
622
+ newFormat = 'DIV';
623
+ } else if (domUtils.isList(rangeEl.parentNode)) {
624
+ newFormat = 'LI';
625
+ } else if (this.format.isLine(rangeEl.nextElementSibling) && !this.format.isBlock(rangeEl.nextElementSibling)) {
626
+ newFormat = rangeEl.nextElementSibling.nodeName;
627
+ } else if (this.format.isLine(rangeEl.previousElementSibling) && !this.format.isBlock(rangeEl.previousElementSibling)) {
628
+ newFormat = rangeEl.previousElementSibling.nodeName;
629
+ } else {
630
+ newFormat = this.options.get('defaultLine');
631
+ }
632
+
633
+ newEl = domUtils.createElement(newFormat);
634
+ const edge = this.format.removeBlock(rangeEl, [formatEl], null, true, true);
635
+ edge.cc.insertBefore(newEl, edge.ec);
636
+ }
637
+
638
+ newEl.innerHTML = '<br>';
639
+ this.nodeTransform.removeAllParents(formatEl, null, null);
640
+ this.selection.setRange(newEl, 1, newEl, 1);
641
+ break;
642
+ }
643
+ }
644
+
645
+ if (brBlock) {
646
+ this.__enterPrevent(e);
647
+ const selectionFormat = selectionNode === brBlock;
648
+ const wSelection = this.selection.get();
649
+ const children = selectionNode.childNodes,
650
+ offset = wSelection.focusOffset,
651
+ prev = selectionNode.previousElementSibling,
652
+ next = selectionNode.nextSibling;
653
+
654
+ if (
655
+ !this.format.isClosureBrLine(brBlock) &&
656
+ children &&
657
+ ((selectionFormat &&
658
+ range.collapsed &&
659
+ children.length - 1 <= offset + 1 &&
660
+ domUtils.isBreak(children[offset]) &&
661
+ (!children[offset + 1] || ((!children[offset + 2] || domUtils.isZeroWith(children[offset + 2].textContent)) && children[offset + 1].nodeType === 3 && domUtils.isZeroWith(children[offset + 1].textContent))) &&
662
+ offset > 0 &&
663
+ domUtils.isBreak(children[offset - 1])) ||
664
+ (!selectionFormat &&
665
+ domUtils.isZeroWith(selectionNode.textContent) &&
666
+ domUtils.isBreak(prev) &&
667
+ (domUtils.isBreak(prev.previousSibling) || !domUtils.isZeroWith(prev.previousSibling.textContent)) &&
668
+ (!next || (!domUtils.isBreak(next) && domUtils.isZeroWith(next.textContent)))))
669
+ ) {
670
+ if (selectionFormat) domUtils.removeItem(children[offset - 1]);
671
+ else domUtils.removeItem(selectionNode);
672
+ const newEl = this.format.addLine(brBlock, this.format.isLine(brBlock.nextElementSibling) && !this.format.isBlock(brBlock.nextElementSibling) ? brBlock.nextElementSibling : null);
673
+ domUtils.copyFormatAttributes(newEl, brBlock);
674
+ this.selection.setRange(newEl, 1, newEl, 1);
675
+ break;
676
+ }
677
+
678
+ if (selectionFormat) {
679
+ this.html.insert(range.collapsed && domUtils.isBreak(range.startContainer.childNodes[range.startOffset - 1]) ? '<br>' : '<br><br>', false, true, true);
680
+
681
+ let focusNode = wSelection.focusNode;
682
+ const wOffset = wSelection.focusOffset;
683
+ if (brBlock === focusNode) {
684
+ focusNode = focusNode.childNodes[wOffset - offset > 1 ? wOffset - 1 : wOffset];
685
+ }
686
+
687
+ this.selection.setRange(focusNode, 1, focusNode, 1);
688
+ } else {
689
+ const focusNext = wSelection.focusNode.nextSibling;
690
+ const br = domUtils.createElement('BR');
691
+ this.html.insertNode(br, null, true);
692
+
693
+ const brPrev = br.previousSibling,
694
+ brNext = br.nextSibling;
695
+ if (!domUtils.isBreak(focusNext) && !domUtils.isBreak(brPrev) && (!brNext || domUtils.isZeroWith(brNext))) {
696
+ br.parentNode.insertBefore(br.cloneNode(false), br);
697
+ this.selection.setRange(br, 1, br, 1);
698
+ } else {
699
+ this.selection.setRange(brNext, 0, brNext, 0);
700
+ }
701
+ }
702
+
703
+ this._onShortcutKey = true;
704
+ break;
705
+ }
706
+
707
+ // set format attrs - edge
708
+ if (range.collapsed && (formatStartEdge || formatEndEdge)) {
709
+ this.__enterPrevent(e);
710
+ const focusBR = domUtils.createElement('BR');
711
+ const newFormat = domUtils.createElement(formatEl.nodeName, null, focusBR);
712
+
713
+ domUtils.copyTagAttributes(newFormat, formatEl, this.options.get('lineAttrReset'));
714
+
715
+ let child = focusBR;
716
+ do {
717
+ if (!domUtils.isBreak(selectionNode) && selectionNode.nodeType === 1) {
718
+ const f = selectionNode.cloneNode(false);
719
+ f.appendChild(child);
720
+ child = f;
721
+ }
722
+ selectionNode = selectionNode.parentNode;
723
+ } while (formatEl !== selectionNode && formatEl.contains(selectionNode));
724
+
725
+ newFormat.appendChild(child);
726
+ formatEl.parentNode.insertBefore(newFormat, formatStartEdge && !formatEndEdge ? formatEl : formatEl.nextElementSibling);
727
+ if (formatEndEdge) {
728
+ this.selection.setRange(focusBR, 1, focusBR, 1);
729
+ } else {
730
+ const firstEl = formatEl.firstChild || formatEl;
731
+ this.selection.setRange(firstEl, 0, firstEl, 0);
732
+ }
733
+
734
+ break;
735
+ }
736
+
737
+ if (formatEl) {
738
+ e.stopPropagation();
739
+
740
+ let newEl;
741
+ let offset = 0;
742
+ if (!range.collapsed) {
743
+ const isMultiLine = this.format.getLine(range.startContainer, null) !== this.format.getLine(range.endContainer, null);
744
+ const newFormat = formatEl.cloneNode(false);
745
+ newFormat.innerHTML = '<br>';
746
+ const rcon = this.html.remove();
747
+ newEl = this.format.getLine(rcon.container, null);
748
+ if (!newEl) {
749
+ if (domUtils.isWysiwygFrame(rcon.container)) {
750
+ this.__enterPrevent(e);
751
+ frameContext.get('wysiwyg').appendChild(newFormat);
752
+ newEl = newFormat;
753
+ domUtils.copyTagAttributes(newEl, formatEl, this.options.get('lineAttrReset'));
754
+ this.selection.setRange(newEl, offset, newEl, offset);
755
+ }
756
+ break;
757
+ }
758
+
759
+ const innerRange = this.format.getBlock(rcon.container);
760
+ newEl = newEl.contains(innerRange) ? domUtils.getEdgeChild(innerRange, this.format.getLine.bind(this.format)) : newEl;
761
+ if (isMultiLine) {
762
+ if (formatEndEdge && !formatStartEdge) {
763
+ newEl.parentNode.insertBefore(newFormat, !rcon.prevContainer || rcon.container === rcon.prevContainer ? newEl.nextElementSibling : newEl);
764
+ newEl = newFormat;
765
+ offset = 0;
766
+ } else {
767
+ offset = rcon.offset;
768
+ if (formatStartEdge) {
769
+ const tempEl = newEl.parentNode.insertBefore(newFormat, newEl);
770
+ if (formatEndEdge) {
771
+ newEl = tempEl;
772
+ offset = 0;
773
+ }
774
+ }
775
+ }
776
+ } else {
777
+ if (formatEndEdge && formatStartEdge) {
778
+ newEl.parentNode.insertBefore(newFormat, rcon.prevContainer && rcon.container === rcon.prevContainer ? newEl.nextElementSibling : newEl);
779
+ newEl = newFormat;
780
+ offset = 0;
781
+ } else {
782
+ newEl = this.nodeTransform.split(rcon.container, rcon.offset, domUtils.getNodeDepth(formatEl));
783
+ }
784
+ }
785
+ } else {
786
+ if (domUtils.isZeroWith(formatEl)) {
787
+ newEl = this.format.addLine(formatEl, formatEl.cloneNode(false));
788
+ } else {
789
+ newEl = this.nodeTransform.split(range.endContainer, range.endOffset, domUtils.getNodeDepth(formatEl));
790
+ }
791
+ }
792
+
793
+ this.__enterPrevent(e);
794
+ domUtils.copyTagAttributes(newEl, formatEl, this.options.get('lineAttrReset'));
795
+ this.selection.setRange(newEl, offset, newEl, offset);
796
+
797
+ break;
798
+ }
799
+ }
800
+
801
+ if (selectRange) break;
802
+
803
+ if (rangeEl && domUtils.getParentElement(rangeEl, 'FIGCAPTION') && domUtils.getParentElement(rangeEl, domUtils.isList)) {
804
+ this.__enterPrevent(e);
805
+ formatEl = this.format.addLine(formatEl, null);
806
+ this.selection.setRange(formatEl, 0, formatEl, 0);
807
+ }
808
+
809
+ break;
810
+ }
811
+ }
812
+
813
+ if (shift && (isOSX_IOS ? alt : ctrl) && keyCode === 32) {
814
+ e.preventDefault();
815
+ e.stopPropagation();
816
+ const nbsp = this.html.insertNode(domUtils.createTextNode('\u00a0'), null, true);
817
+ if (nbsp && nbsp.container) {
818
+ this.selection.setRange(nbsp.container, nbsp.endOffset, nbsp.container, nbsp.endOffset);
819
+ return;
820
+ }
821
+ }
822
+
823
+ if (!ctrl && !alt && !selectRange && !NON_TEXT_KEYCODE.test(keyCode) && domUtils.isBreak(range.commonAncestorContainer)) {
824
+ const zeroWidth = domUtils.createTextNode(unicode.zeroWidthSpace);
825
+ this.html.insertNode(zeroWidth, null, true);
826
+ this.selection.setRange(zeroWidth, 1, zeroWidth, 1);
827
+ }
828
+
829
+ // enter scroll
830
+ if (keyCode === 13) this.selection.scrollTo(range);
831
+
832
+ // next component
833
+ if (!DIR_KEYCODE.test(keyCode)) return;
834
+
835
+ let cmponentInfo = null;
836
+ switch (keyCode) {
837
+ case 38 /** up key */:
838
+ if (this.component.is(formatEl.previousElementSibling)) {
839
+ cmponentInfo = this.component.get(formatEl.previousElementSibling);
840
+ }
841
+ break;
842
+ case 37 /** left key */:
843
+ if (domUtils.isEdgePoint(selectionNode, range.startOffset, 'front')) {
844
+ const prevEl = selectionNode.previousElementSibling;
845
+ if (prevEl && this.component.is(prevEl)) {
846
+ cmponentInfo = this.component.get(prevEl);
847
+ } else if (this.component.is(formatEl.previousElementSibling)) {
848
+ cmponentInfo = this.component.get(formatEl.previousElementSibling);
849
+ }
850
+ }
851
+ break;
852
+ case 40 /** down key */:
853
+ if (this.component.is(formatEl.nextElementSibling)) {
854
+ cmponentInfo = this.component.get(formatEl.nextElementSibling);
855
+ }
856
+ break;
857
+ case 39 /** right key */:
858
+ if (domUtils.isEdgePoint(selectionNode, range.endOffset, 'end')) {
859
+ const nextEl = selectionNode.nextElementSibling;
860
+ if (nextEl && this.component.is(nextEl)) {
861
+ cmponentInfo = this.component.get(nextEl);
862
+ } else if (this.component.is(formatEl.nextElementSibling)) {
863
+ cmponentInfo = this.component.get(formatEl.nextElementSibling);
864
+ }
865
+ }
866
+ break;
867
+ }
868
+
869
+ if (cmponentInfo && !cmponentInfo.options?.isInputComponent) {
870
+ e.preventDefault();
871
+ if (this.component.select(cmponentInfo.target, cmponentInfo.pluginName, false) === false) this.editor.blur();
872
+ }
873
+ }
874
+
875
+ export function OnKeyUp_wysiwyg(frameContext, e) {
876
+ if (this._onShortcutKey || this.menu.currentDropdownName) return;
877
+
878
+ const keyCode = e.keyCode;
879
+ const ctrl = e.ctrlKey || e.metaKey || keyCode === 91 || keyCode === 92 || keyCode === 224;
880
+ const alt = e.altKey;
881
+
882
+ if (frameContext.get('isReadOnly')) return;
883
+
884
+ const range = this.selection.getRange();
885
+ let selectionNode = this.selection.getNode();
886
+
887
+ if ((this.editor.isBalloon || this.editor.isSubBalloon) && (((this.editor.isBalloonAlways || this.editor.isSubBalloonAlways) && keyCode !== 27) || !range.collapsed)) {
888
+ if (this.editor.isBalloonAlways || this.editor.isSubBalloonAlways) {
889
+ if (keyCode !== 27) this._showToolbarBalloonDelay();
890
+ } else {
891
+ if (this.editor.isSubBalloon) this.subToolbar._showBalloon();
892
+ else this.toolbar._showBalloon();
893
+ return;
894
+ }
895
+ }
896
+
897
+ /** when format tag deleted */
898
+ if (keyCode === 8 && domUtils.isWysiwygFrame(selectionNode) && selectionNode.textContent === '' && selectionNode.children.length === 0) {
899
+ e.preventDefault();
900
+ e.stopPropagation();
901
+
902
+ selectionNode.innerHTML = '';
903
+
904
+ const oFormatTag = domUtils.createElement(this.format.isLine(this.status.currentNodes[0]) && !domUtils.isListCell(this.status.currentNodes[0]) ? this.status.currentNodes[0] : this.options.get('defaultLine'), null, '<br>');
905
+ selectionNode.appendChild(oFormatTag);
906
+ this.selection.setRange(oFormatTag, 0, oFormatTag, 0);
907
+ this.applyTagEffect();
908
+
909
+ this.history.push(false);
910
+ return;
911
+ }
912
+
913
+ const formatEl = this.format.getLine(selectionNode, null);
914
+ const rangeEl = this.format.getBlock(selectionNode, null);
915
+ const attrs = this._formatAttrsTemp;
916
+
917
+ if (formatEl && attrs) {
918
+ for (let i = 0, len = attrs.length; i < len; i++) {
919
+ if (keyCode === 13 && /^id$/i.test(attrs[i].name)) {
920
+ formatEl.removeAttribute('id');
921
+ continue;
922
+ }
923
+ formatEl.setAttribute(attrs[i].name, attrs[i].value);
924
+ }
925
+ this._formatAttrsTemp = null;
926
+ }
927
+
928
+ if (!formatEl && range.collapsed && !this.component.is(selectionNode) && !domUtils.isList(selectionNode) && this._setDefaultLine(this.format.isBlock(rangeEl) ? 'DIV' : this.options.get('defaultLine')) !== null) {
929
+ selectionNode = this.selection.getNode();
930
+ }
931
+
932
+ const textKey = !ctrl && !alt && !NON_TEXT_KEYCODE.test(keyCode);
933
+ if (textKey && selectionNode.nodeType === 3 && unicode.zeroWidthRegExp.test(selectionNode.textContent) && !(e.isComposing !== undefined ? e.isComposing : this.isComposing)) {
934
+ let so = range.startOffset,
935
+ eo = range.endOffset;
936
+ const frontZeroWidthCnt = (selectionNode.textContent.substring(0, eo).match(FRONT_ZEROWIDTH) || '').length;
937
+ so = range.startOffset - frontZeroWidthCnt;
938
+ eo = range.endOffset - frontZeroWidthCnt;
939
+ selectionNode.textContent = selectionNode.textContent.replace(unicode.zeroWidthRegExp, '');
940
+ this.selection.setRange(selectionNode, so < 0 ? 0 : so, selectionNode, eo < 0 ? 0 : eo);
941
+ }
942
+
943
+ if (DELETE_KEYCODE.test(keyCode) && domUtils.isZeroWith(formatEl?.textContent) && !formatEl.previousElementSibling) {
944
+ const rsMode = this.options.get('retainStyleMode');
945
+ if (rsMode !== 'none' && _styleNodes?.length > 0) {
946
+ if (rsMode === 'repeat') {
947
+ if (this.__retainTimer) {
948
+ this.__retainTimer = _w.clearTimeout(this.__retainTimer);
949
+ this._clearRetainStyleNodes(formatEl);
950
+ } else {
951
+ this.__retainTimer = _w.setTimeout(() => {
952
+ this.__retainTimer = null;
953
+ }, 0);
954
+ this._retainStyleNodes(formatEl, _styleNodes);
955
+ }
956
+ } else {
957
+ this.__retainTimer = null;
958
+ this._retainStyleNodes(formatEl, _styleNodes);
959
+ }
960
+ } else {
961
+ this._clearRetainStyleNodes(formatEl);
962
+ }
963
+ }
964
+
965
+ this.char.test('', false);
966
+
967
+ // user event
968
+ if (this.triggerEvent('onKeyUp', { frameContext, event: e }) === false) return;
969
+ // plugin event
970
+ if (this._callPluginEvent('onKeyUp', { frameContext, event: e, range, line: formatEl }) === false) return;
971
+
972
+ if (!ctrl && !alt && !HISTORY_IGNORE_KEYCODE.test(keyCode)) {
973
+ this.history.push(true);
974
+ }
975
+ }