suneditor 2.46.2 → 3.0.0-alpha.10

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