suneditor 3.0.0-alpha.9 → 3.0.0-beta.2

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 (315) hide show
  1. package/CONTRIBUTING.md +170 -22
  2. package/{LICENSE.txt → LICENSE} +9 -9
  3. package/README.md +168 -30
  4. package/dist/suneditor.min.css +1 -1
  5. package/dist/suneditor.min.js +1 -1
  6. package/package.json +47 -21
  7. package/src/assets/design/color.css +121 -0
  8. package/src/assets/design/index.css +3 -0
  9. package/src/assets/design/size.css +35 -0
  10. package/src/assets/design/typography.css +37 -0
  11. package/src/assets/icons/defaultIcons.js +232 -0
  12. package/src/assets/suneditor-contents.css +181 -46
  13. package/src/assets/suneditor.css +1403 -650
  14. package/src/core/base/eventHandlers/handler_toolbar.js +35 -14
  15. package/src/core/base/eventHandlers/handler_ww_clipboard.js +23 -4
  16. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +49 -10
  17. package/src/core/base/eventHandlers/handler_ww_key_input.js +422 -224
  18. package/src/core/base/eventHandlers/handler_ww_mouse.js +83 -36
  19. package/src/core/base/eventManager.js +520 -179
  20. package/src/core/base/history.js +95 -41
  21. package/src/core/class/char.js +26 -11
  22. package/src/core/class/component.js +345 -137
  23. package/src/core/class/format.js +683 -519
  24. package/src/core/class/html.js +485 -305
  25. package/src/core/class/menu.js +133 -47
  26. package/src/core/class/nodeTransform.js +90 -71
  27. package/src/core/class/offset.js +408 -92
  28. package/src/core/class/selection.js +216 -106
  29. package/src/core/class/shortcuts.js +68 -8
  30. package/src/core/class/toolbar.js +106 -116
  31. package/src/core/class/ui.js +422 -0
  32. package/src/core/class/viewer.js +178 -74
  33. package/src/core/editor.js +496 -389
  34. package/src/core/section/actives.js +123 -27
  35. package/src/core/section/constructor.js +615 -206
  36. package/src/core/section/context.js +28 -23
  37. package/src/core/section/documentType.js +561 -0
  38. package/src/editorInjector/_classes.js +19 -5
  39. package/src/editorInjector/_core.js +71 -7
  40. package/src/editorInjector/index.js +63 -1
  41. package/src/events.js +622 -0
  42. package/src/helper/clipboard.js +59 -0
  43. package/src/helper/converter.js +202 -26
  44. package/src/helper/dom/domCheck.js +304 -0
  45. package/src/helper/dom/domQuery.js +669 -0
  46. package/src/helper/dom/domUtils.js +557 -0
  47. package/src/helper/dom/index.js +12 -0
  48. package/src/helper/env.js +46 -56
  49. package/src/helper/index.js +10 -4
  50. package/src/helper/keyCodeMap.js +183 -0
  51. package/src/helper/numbers.js +12 -8
  52. package/src/helper/unicode.js +9 -5
  53. package/src/langs/ckb.js +74 -4
  54. package/src/langs/cs.js +72 -2
  55. package/src/langs/da.js +73 -3
  56. package/src/langs/de.js +73 -4
  57. package/src/langs/en.js +23 -3
  58. package/src/langs/es.js +73 -4
  59. package/src/langs/fa.js +75 -3
  60. package/src/langs/fr.js +73 -3
  61. package/src/langs/he.js +73 -4
  62. package/src/langs/hu.js +230 -0
  63. package/src/langs/index.js +7 -3
  64. package/src/langs/it.js +70 -1
  65. package/src/langs/ja.js +72 -4
  66. package/src/langs/km.js +230 -0
  67. package/src/langs/ko.js +22 -2
  68. package/src/langs/lv.js +74 -5
  69. package/src/langs/nl.js +73 -4
  70. package/src/langs/pl.js +73 -4
  71. package/src/langs/pt_br.js +70 -1
  72. package/src/langs/ro.js +74 -5
  73. package/src/langs/ru.js +73 -4
  74. package/src/langs/se.js +73 -4
  75. package/src/langs/tr.js +73 -1
  76. package/src/langs/{ua.js → uk.js} +75 -6
  77. package/src/langs/ur.js +77 -8
  78. package/src/langs/zh_cn.js +74 -5
  79. package/src/modules/ApiManager.js +77 -54
  80. package/src/modules/Browser.js +667 -0
  81. package/src/modules/ColorPicker.js +162 -102
  82. package/src/modules/Controller.js +273 -142
  83. package/src/modules/Figure.js +925 -484
  84. package/src/modules/FileManager.js +121 -69
  85. package/src/modules/HueSlider.js +113 -61
  86. package/src/modules/Modal.js +291 -122
  87. package/src/modules/ModalAnchorEditor.js +383 -234
  88. package/src/modules/SelectMenu.js +270 -168
  89. package/src/modules/_DragHandle.js +2 -1
  90. package/src/modules/index.js +3 -3
  91. package/src/plugins/browser/audioGallery.js +83 -0
  92. package/src/plugins/browser/fileBrowser.js +103 -0
  93. package/src/plugins/browser/fileGallery.js +83 -0
  94. package/src/plugins/browser/imageGallery.js +81 -0
  95. package/src/plugins/browser/videoGallery.js +103 -0
  96. package/src/plugins/command/blockquote.js +40 -27
  97. package/src/plugins/command/exportPDF.js +134 -0
  98. package/src/plugins/command/fileUpload.js +229 -162
  99. package/src/plugins/command/list_bulleted.js +83 -47
  100. package/src/plugins/command/list_numbered.js +83 -47
  101. package/src/plugins/dropdown/align.js +66 -54
  102. package/src/plugins/dropdown/backgroundColor.js +63 -49
  103. package/src/plugins/dropdown/font.js +71 -47
  104. package/src/plugins/dropdown/fontColor.js +63 -48
  105. package/src/plugins/dropdown/formatBlock.js +70 -33
  106. package/src/plugins/dropdown/hr.js +92 -51
  107. package/src/plugins/dropdown/layout.js +37 -26
  108. package/src/plugins/dropdown/lineHeight.js +54 -38
  109. package/src/plugins/dropdown/list.js +60 -45
  110. package/src/plugins/dropdown/paragraphStyle.js +51 -30
  111. package/src/plugins/dropdown/table.js +2003 -813
  112. package/src/plugins/dropdown/template.js +38 -26
  113. package/src/plugins/dropdown/textStyle.js +43 -31
  114. package/src/plugins/field/mention.js +147 -86
  115. package/src/plugins/index.js +32 -6
  116. package/src/plugins/input/fontSize.js +161 -108
  117. package/src/plugins/input/pageNavigator.js +70 -0
  118. package/src/plugins/modal/audio.js +358 -173
  119. package/src/plugins/modal/drawing.js +531 -0
  120. package/src/plugins/modal/embed.js +886 -0
  121. package/src/plugins/modal/image.js +674 -362
  122. package/src/plugins/modal/link.js +100 -71
  123. package/src/plugins/modal/math.js +367 -167
  124. package/src/plugins/modal/video.js +691 -335
  125. package/src/plugins/popup/anchor.js +222 -0
  126. package/src/suneditor.js +50 -13
  127. package/src/themes/dark.css +122 -0
  128. package/src/typedef.js +130 -0
  129. package/types/assets/icons/defaultIcons.d.ts +153 -0
  130. package/types/core/base/eventHandlers/handler_toolbar.d.ts +41 -0
  131. package/types/core/base/eventHandlers/handler_ww_clipboard.d.ts +40 -0
  132. package/types/core/base/eventHandlers/handler_ww_dragDrop.d.ts +35 -0
  133. package/types/core/base/eventHandlers/handler_ww_key_input.d.ts +45 -0
  134. package/types/core/base/eventHandlers/handler_ww_mouse.d.ts +39 -0
  135. package/types/core/base/eventManager.d.ts +385 -0
  136. package/types/core/base/history.d.ts +81 -0
  137. package/types/core/class/char.d.ts +60 -0
  138. package/types/core/class/component.d.ts +212 -0
  139. package/types/core/class/format.d.ts +616 -0
  140. package/types/core/class/html.d.ts +422 -0
  141. package/types/core/class/menu.d.ts +126 -0
  142. package/types/core/class/nodeTransform.d.ts +93 -0
  143. package/types/core/class/offset.d.ts +522 -0
  144. package/types/core/class/selection.d.ts +188 -0
  145. package/types/core/class/shortcuts.d.ts +142 -0
  146. package/types/core/class/toolbar.d.ts +189 -0
  147. package/types/core/class/ui.d.ts +164 -0
  148. package/types/core/class/viewer.d.ts +140 -0
  149. package/types/core/editor.d.ts +610 -0
  150. package/types/core/section/actives.d.ts +46 -0
  151. package/types/core/section/constructor.d.ts +777 -0
  152. package/types/core/section/context.d.ts +45 -0
  153. package/types/core/section/documentType.d.ts +178 -0
  154. package/types/editorInjector/_classes.d.ts +41 -0
  155. package/types/editorInjector/_core.d.ts +92 -0
  156. package/types/editorInjector/index.d.ts +71 -0
  157. package/types/events.d.ts +273 -0
  158. package/types/helper/clipboard.d.ts +12 -0
  159. package/types/helper/converter.d.ts +197 -0
  160. package/types/helper/dom/domCheck.d.ts +189 -0
  161. package/types/helper/dom/domQuery.d.ts +223 -0
  162. package/types/helper/dom/domUtils.d.ts +226 -0
  163. package/types/helper/dom/index.d.ts +9 -0
  164. package/types/helper/env.d.ts +132 -0
  165. package/types/helper/index.d.ts +174 -0
  166. package/types/helper/keyCodeMap.d.ts +110 -0
  167. package/types/helper/numbers.d.ts +46 -0
  168. package/types/helper/unicode.d.ts +28 -0
  169. package/types/index.d.ts +120 -0
  170. package/{typings/Lang.d.ts → types/langs/_Lang.d.ts} +173 -103
  171. package/types/langs/ckb.d.ts +3 -0
  172. package/types/langs/cs.d.ts +3 -0
  173. package/types/langs/da.d.ts +3 -0
  174. package/types/langs/de.d.ts +3 -0
  175. package/types/langs/en.d.ts +3 -0
  176. package/types/langs/es.d.ts +3 -0
  177. package/types/langs/fa.d.ts +3 -0
  178. package/types/langs/fr.d.ts +3 -0
  179. package/types/langs/he.d.ts +3 -0
  180. package/types/langs/hu.d.ts +3 -0
  181. package/types/langs/index.d.ts +54 -0
  182. package/types/langs/it.d.ts +3 -0
  183. package/types/langs/ja.d.ts +3 -0
  184. package/types/langs/km.d.ts +3 -0
  185. package/types/langs/ko.d.ts +3 -0
  186. package/types/langs/lv.d.ts +3 -0
  187. package/types/langs/nl.d.ts +3 -0
  188. package/types/langs/pl.d.ts +3 -0
  189. package/types/langs/pt_br.d.ts +3 -0
  190. package/types/langs/ro.d.ts +3 -0
  191. package/types/langs/ru.d.ts +3 -0
  192. package/types/langs/se.d.ts +3 -0
  193. package/types/langs/tr.d.ts +3 -0
  194. package/types/langs/uk.d.ts +3 -0
  195. package/types/langs/ur.d.ts +3 -0
  196. package/types/langs/zh_cn.d.ts +3 -0
  197. package/types/modules/ApiManager.d.ts +125 -0
  198. package/types/modules/Browser.d.ts +326 -0
  199. package/types/modules/ColorPicker.d.ts +131 -0
  200. package/types/modules/Controller.d.ts +251 -0
  201. package/types/modules/Figure.d.ts +517 -0
  202. package/types/modules/FileManager.d.ts +202 -0
  203. package/types/modules/HueSlider.d.ts +136 -0
  204. package/types/modules/Modal.d.ts +111 -0
  205. package/types/modules/ModalAnchorEditor.d.ts +236 -0
  206. package/types/modules/SelectMenu.d.ts +194 -0
  207. package/types/modules/_DragHandle.d.ts +7 -0
  208. package/types/modules/index.d.ts +26 -0
  209. package/types/plugins/browser/audioGallery.d.ts +55 -0
  210. package/types/plugins/browser/fileBrowser.d.ts +64 -0
  211. package/types/plugins/browser/fileGallery.d.ts +55 -0
  212. package/types/plugins/browser/imageGallery.d.ts +51 -0
  213. package/types/plugins/browser/videoGallery.d.ts +57 -0
  214. package/types/plugins/command/blockquote.d.ts +28 -0
  215. package/types/plugins/command/exportPDF.d.ts +46 -0
  216. package/types/plugins/command/fileUpload.d.ts +156 -0
  217. package/types/plugins/command/list_bulleted.d.ts +46 -0
  218. package/types/plugins/command/list_numbered.d.ts +46 -0
  219. package/types/plugins/dropdown/align.d.ts +60 -0
  220. package/types/plugins/dropdown/backgroundColor.d.ts +63 -0
  221. package/types/plugins/dropdown/font.d.ts +54 -0
  222. package/types/plugins/dropdown/fontColor.d.ts +63 -0
  223. package/types/plugins/dropdown/formatBlock.d.ts +54 -0
  224. package/types/plugins/dropdown/hr.d.ts +71 -0
  225. package/types/plugins/dropdown/layout.d.ts +40 -0
  226. package/types/plugins/dropdown/lineHeight.d.ts +50 -0
  227. package/types/plugins/dropdown/list.d.ts +39 -0
  228. package/types/plugins/dropdown/paragraphStyle.d.ts +54 -0
  229. package/types/plugins/dropdown/table.d.ts +627 -0
  230. package/types/plugins/dropdown/template.d.ts +40 -0
  231. package/types/plugins/dropdown/textStyle.d.ts +41 -0
  232. package/types/plugins/field/mention.d.ts +102 -0
  233. package/types/plugins/index.d.ts +107 -0
  234. package/types/plugins/input/fontSize.d.ts +170 -0
  235. package/types/plugins/input/pageNavigator.d.ts +28 -0
  236. package/types/plugins/modal/audio.d.ts +269 -0
  237. package/types/plugins/modal/drawing.d.ts +246 -0
  238. package/types/plugins/modal/embed.d.ts +387 -0
  239. package/types/plugins/modal/image.d.ts +451 -0
  240. package/types/plugins/modal/link.d.ts +128 -0
  241. package/types/plugins/modal/math.d.ts +193 -0
  242. package/types/plugins/modal/video.d.ts +485 -0
  243. package/types/plugins/popup/anchor.d.ts +56 -0
  244. package/types/suneditor.d.ts +51 -0
  245. package/types/typedef.d.ts +233 -0
  246. package/.eslintignore +0 -7
  247. package/.eslintrc.json +0 -64
  248. package/src/assets/icons/_default.js +0 -194
  249. package/src/core/base/events.js +0 -320
  250. package/src/core/class/notice.js +0 -42
  251. package/src/helper/domUtils.js +0 -1177
  252. package/src/modules/FileBrowser.js +0 -271
  253. package/src/plugins/command/exportPdf.js +0 -168
  254. package/src/plugins/fileBrowser/imageGallery.js +0 -81
  255. package/src/themes/test.css +0 -61
  256. package/typings/CommandPlugin.d.ts +0 -8
  257. package/typings/DialogPlugin.d.ts +0 -20
  258. package/typings/FileBrowserPlugin.d.ts +0 -30
  259. package/typings/Module.d.ts +0 -15
  260. package/typings/Plugin.d.ts +0 -42
  261. package/typings/SubmenuPlugin.d.ts +0 -8
  262. package/typings/_classes.d.ts +0 -17
  263. package/typings/_colorPicker.d.ts +0 -60
  264. package/typings/_core.d.ts +0 -55
  265. package/typings/align.d.ts +0 -5
  266. package/typings/audio.d.ts +0 -5
  267. package/typings/backgroundColor.d.ts +0 -5
  268. package/typings/blockquote.d.ts +0 -5
  269. package/typings/char.d.ts +0 -39
  270. package/typings/component.d.ts +0 -38
  271. package/typings/context.d.ts +0 -39
  272. package/typings/converter.d.ts +0 -33
  273. package/typings/dialog.d.ts +0 -28
  274. package/typings/domUtils.d.ts +0 -361
  275. package/typings/editor.d.ts +0 -7
  276. package/typings/editor.ts +0 -542
  277. package/typings/env.d.ts +0 -70
  278. package/typings/eventManager.d.ts +0 -37
  279. package/typings/events.d.ts +0 -262
  280. package/typings/fileBrowser.d.ts +0 -42
  281. package/typings/fileManager.d.ts +0 -67
  282. package/typings/font.d.ts +0 -5
  283. package/typings/fontColor.d.ts +0 -5
  284. package/typings/fontSize.d.ts +0 -5
  285. package/typings/format.d.ts +0 -191
  286. package/typings/formatBlock.d.ts +0 -5
  287. package/typings/history.d.ts +0 -48
  288. package/typings/horizontalRule.d.ts +0 -5
  289. package/typings/image.d.ts +0 -5
  290. package/typings/imageGallery.d.ts +0 -5
  291. package/typings/index.d.ts +0 -21
  292. package/typings/index.modules.d.ts +0 -11
  293. package/typings/index.plugins.d.ts +0 -58
  294. package/typings/lineHeight.d.ts +0 -5
  295. package/typings/link.d.ts +0 -5
  296. package/typings/list.d.ts +0 -5
  297. package/typings/math.d.ts +0 -5
  298. package/typings/mediaContainer.d.ts +0 -25
  299. package/typings/mention.d.ts +0 -5
  300. package/typings/node.d.ts +0 -57
  301. package/typings/notice.d.ts +0 -16
  302. package/typings/numbers.d.ts +0 -29
  303. package/typings/offset.d.ts +0 -24
  304. package/typings/options.d.ts +0 -589
  305. package/typings/paragraphStyle.d.ts +0 -5
  306. package/typings/resizing.d.ts +0 -141
  307. package/typings/selection.d.ts +0 -94
  308. package/typings/shortcuts.d.ts +0 -13
  309. package/typings/suneditor.d.ts +0 -9
  310. package/typings/table.d.ts +0 -5
  311. package/typings/template.d.ts +0 -5
  312. package/typings/textStyle.d.ts +0 -5
  313. package/typings/toolbar.d.ts +0 -32
  314. package/typings/unicode.d.ts +0 -25
  315. package/typings/video.d.ts +0 -5
@@ -3,9 +3,19 @@
3
3
  */
4
4
 
5
5
  import CoreInjector from '../../editorInjector/_core';
6
- import { domUtils, env, converter, numbers } from '../../helper';
6
+ import { dom, env, converter, numbers } from '../../helper';
7
7
 
8
- const Viewer = function (editor) {
8
+ /**
9
+ * @typedef {Omit<Viewer & Partial<__se__EditorInjector>, 'viewer'>} ViewerThis
10
+ */
11
+
12
+ /**
13
+ * @constructor
14
+ * @this {ViewerThis}
15
+ * @description Viewer(codeView, fullScreen, showBlocks) class
16
+ * @param {__se__EditorCore} editor - The root editor instance
17
+ */
18
+ function Viewer(editor) {
9
19
  CoreInjector.call(this, editor);
10
20
 
11
21
  // members
@@ -22,12 +32,13 @@ const Viewer = function (editor) {
22
32
  this.fullScreenBalloon = false;
23
33
  this.fullScreenInline = false;
24
34
  this.toolbarParent = null;
25
- };
35
+ }
26
36
 
27
37
  Viewer.prototype = {
28
38
  /**
39
+ * @this {ViewerThis}
29
40
  * @description Changes to code view or wysiwyg view
30
- * @param {boolean|undefined} value true/false, If undefined toggle the codeView mode.
41
+ * @param {boolean=} value true/false, If undefined toggle the codeView mode.
31
42
  */
32
43
  codeView(value) {
33
44
  const fc = this.editor.frameContext;
@@ -35,12 +46,13 @@ Viewer.prototype = {
35
46
  if (value === fc.get('isCodeView')) return;
36
47
 
37
48
  fc.set('isCodeView', value);
38
- this.editor._offCurrentController();
39
- this.editor._offCurrentModal();
49
+ this.ui._offCurrentController();
50
+ this.ui._offCurrentModal();
40
51
 
41
52
  const codeWrapper = fc.get('codeWrapper');
42
53
  const codeFrame = fc.get('code');
43
54
  const wysiwygFrame = fc.get('wysiwygFrame');
55
+ const wrapper = fc.get('wrapper');
44
56
 
45
57
  if (value) {
46
58
  this._setEditorDataToCodeView();
@@ -76,9 +88,10 @@ Viewer.prototype = {
76
88
 
77
89
  this.status._range = null;
78
90
  codeFrame.focus();
79
- domUtils.addClass(this.editor.commandTargets.get('codeView'), 'active');
91
+ dom.utils.addClass(this.editor.commandTargets.get('codeView'), 'active');
92
+ dom.utils.addClass(wrapper, 'se-code-view-status');
80
93
  } else {
81
- if (!domUtils.isNonEditable(wysiwygFrame)) this._setCodeDataToEditor();
94
+ if (!dom.check.isNonEditable(wysiwygFrame)) this._setCodeDataToEditor();
82
95
  wysiwygFrame.scrollTop = 0;
83
96
  codeWrapper.style.setProperty('display', 'none', 'important');
84
97
  wysiwygFrame.style.display = 'block';
@@ -96,24 +109,36 @@ Viewer.prototype = {
96
109
  }
97
110
 
98
111
  this.editor._nativeFocus();
99
- domUtils.removeClass(this.editor.commandTargets.get('codeView'), 'active');
112
+ dom.utils.removeClass(this.editor.commandTargets.get('codeView'), 'active');
100
113
 
101
- if (!domUtils.isNonEditable(wysiwygFrame)) {
114
+ if (!dom.check.isNonEditable(wysiwygFrame)) {
102
115
  this.history.push(false);
103
116
  this.history.resetButtons(fc.get('key'), null);
104
117
  }
118
+ dom.utils.removeClass(wrapper, 'se-code-view-status');
105
119
  }
106
120
 
107
- this.editor._checkPlaceholder();
108
- domUtils.setDisabled(this.editor._codeViewDisabledButtons, value);
121
+ this.editor._checkPlaceholder(fc);
122
+ dom.utils.setDisabled(this.editor._codeViewDisabledButtons, value);
123
+
124
+ // document type
125
+ if (fc.has('documentType-use-header')) {
126
+ if (value) {
127
+ fc.get('documentTypeInner').style.display = 'none';
128
+ } else {
129
+ fc.get('documentTypeInner').style.display = '';
130
+ fc.get('documentType').reHeader();
131
+ }
132
+ }
109
133
 
110
134
  // user event
111
135
  this.triggerEvent('onToggleCodeView', { frameContext: fc, is: fc.get('isCodeView') });
112
136
  },
113
137
 
114
138
  /**
139
+ * @this {ViewerThis}
115
140
  * @description Changes to full screen or default screen
116
- * @param {boolean|undefined} value true/false, If undefined toggle the codeView mode.
141
+ * @param {boolean=} value true/false, If undefined toggle the codeView mode.
117
142
  */
118
143
  fullScreen(value) {
119
144
  const fc = this.editor.frameContext;
@@ -131,7 +156,7 @@ Viewer.prototype = {
131
156
  const isCodeView = this.editor.frameContext.get('isCodeView');
132
157
  const arrow = this.context.get('toolbar._arrow');
133
158
 
134
- this.editor._offCurrentController();
159
+ this.ui._offCurrentController();
135
160
  const wasToolbarHidden = toolbar.style.display === 'none' || (this.editor.isInline && !this.editor.toolbar._inlineToolbarAttr.isShow);
136
161
 
137
162
  if (value) {
@@ -168,7 +193,7 @@ Viewer.prototype = {
168
193
  if (fc.get('_stickyDummy').style.display !== 'none' && fc.get('_stickyDummy').style.display !== '') {
169
194
  this.fullScreenSticky = true;
170
195
  fc.get('_stickyDummy').style.display = 'none';
171
- domUtils.removeClass(toolbar, 'se-toolbar-sticky');
196
+ dom.utils.removeClass(toolbar, 'se-toolbar-sticky');
172
197
  }
173
198
 
174
199
  this.bodyOverflow = this._d.body.style.overflow;
@@ -203,8 +228,8 @@ Viewer.prototype = {
203
228
 
204
229
  const reductionIcon = this.icons.reduction;
205
230
  this.editor.applyCommandTargets('fullScreen', (e) => {
206
- domUtils.changeElement(e.firstElementChild, reductionIcon);
207
- domUtils.addClass(e, 'active');
231
+ dom.utils.changeElement(e.firstElementChild, reductionIcon);
232
+ dom.utils.addClass(e, 'active');
208
233
  });
209
234
  } else {
210
235
  // frame
@@ -224,7 +249,7 @@ Viewer.prototype = {
224
249
  if (arrow) arrow.style.cssText = this.arrowOriginCssText;
225
250
  this._d.body.style.overflow = this.bodyOverflow;
226
251
 
227
- if (this.editor.frameOptions.get('height') === 'auto' && !this.options.get('hasCodeMirror')) this._codeViewAutoHeight(fc);
252
+ if (this.editor.frameOptions.get('height') === 'auto' && !this.options.get('hasCodeMirror')) this._codeViewAutoHeight(fc.get('code'), fc.get('codeNumbers'), true);
228
253
 
229
254
  if (this.toolbarParent) {
230
255
  this.toolbarParent.appendChild(toolbar);
@@ -232,13 +257,13 @@ Viewer.prototype = {
232
257
  }
233
258
 
234
259
  if (this.options.get('toolbar_sticky') > -1) {
235
- domUtils.removeClass(toolbar, 'se-toolbar-sticky');
260
+ dom.utils.removeClass(toolbar, 'se-toolbar-sticky');
236
261
  }
237
262
 
238
263
  if (this.fullScreenSticky && !this.options.get('toolbar_container')) {
239
264
  this.fullScreenSticky = false;
240
265
  fc.get('_stickyDummy').style.display = 'block';
241
- domUtils.addClass(toolbar, 'se-toolbar-sticky');
266
+ dom.utils.addClass(toolbar, 'se-toolbar-sticky');
242
267
  }
243
268
 
244
269
  this.editor.isInline = this.toolbar._isInline = this.fullScreenInline;
@@ -253,8 +278,8 @@ Viewer.prototype = {
253
278
 
254
279
  const expansionIcon = this.icons.expansion;
255
280
  this.editor.applyCommandTargets('fullScreen', (e) => {
256
- domUtils.changeElement(e.firstElementChild, expansionIcon);
257
- domUtils.removeClass(e, 'active');
281
+ dom.utils.changeElement(e.firstElementChild, expansionIcon);
282
+ dom.utils.removeClass(e, 'active');
258
283
  });
259
284
  }
260
285
 
@@ -265,8 +290,9 @@ Viewer.prototype = {
265
290
  },
266
291
 
267
292
  /**
293
+ * @this {ViewerThis}
268
294
  * @description Add or remove the class name of "body" so that the code block is visible
269
- * @param {boolean|undefined} value true/false, If undefined toggle the codeView mode.
295
+ * @param {boolean=} value true/false, If undefined toggle the codeView mode.
270
296
  */
271
297
  showBlocks(value) {
272
298
  const fc = this.editor.frameContext;
@@ -274,68 +300,94 @@ Viewer.prototype = {
274
300
  fc.set('isShowBlocks', !!value);
275
301
 
276
302
  if (value) {
277
- domUtils.addClass(fc.get('wysiwyg'), 'se-show-block');
278
- domUtils.addClass(this.editor.commandTargets.get('showBlocks'), 'active');
303
+ dom.utils.addClass(fc.get('wysiwyg'), 'se-show-block');
304
+ dom.utils.addClass(this.editor.commandTargets.get('showBlocks'), 'active');
279
305
  } else {
280
- domUtils.removeClass(fc.get('wysiwyg'), 'se-show-block');
281
- domUtils.removeClass(this.editor.commandTargets.get('showBlocks'), 'active');
306
+ dom.utils.removeClass(fc.get('wysiwyg'), 'se-show-block');
307
+ dom.utils.removeClass(this.editor.commandTargets.get('showBlocks'), 'active');
282
308
  }
283
309
 
284
310
  this.editor._resourcesStateChange(fc);
285
311
  },
286
312
 
313
+ /**
314
+ * @private
315
+ * @this {ViewerThis}
316
+ * @description Set the active class to the button of the toolbar
317
+ */
287
318
  _setButtonsActive() {
288
319
  const fc = this.editor.frameContext;
289
320
 
290
321
  // codeView
291
322
  if (fc.get('isCodeView')) {
292
- domUtils.addClass(this.editor.commandTargets.get('codeView'), 'active');
323
+ dom.utils.addClass(this.editor.commandTargets.get('codeView'), 'active');
293
324
  } else {
294
- domUtils.removeClass(this.editor.commandTargets.get('codeView'), 'active');
325
+ dom.utils.removeClass(this.editor.commandTargets.get('codeView'), 'active');
295
326
  }
296
327
 
297
328
  // fullScreen
298
329
  if (fc.get('isFullScreen')) {
299
330
  const reductionIcon = this.icons.reduction;
300
331
  this.editor.applyCommandTargets('fullScreen', (e) => {
301
- domUtils.changeElement(e.firstElementChild, reductionIcon);
302
- domUtils.addClass(e, 'active');
332
+ dom.utils.changeElement(e.firstElementChild, reductionIcon);
333
+ dom.utils.addClass(e, 'active');
303
334
  });
304
335
  } else {
305
336
  const expansionIcon = this.icons.expansion;
306
337
  this.editor.applyCommandTargets('fullScreen', (e) => {
307
- domUtils.changeElement(e.firstElementChild, expansionIcon);
308
- domUtils.removeClass(e, 'active');
338
+ dom.utils.changeElement(e.firstElementChild, expansionIcon);
339
+ dom.utils.removeClass(e, 'active');
309
340
  });
310
341
  }
311
342
 
312
343
  // showBlocks
313
344
  if (fc.get('isShowBlocks')) {
314
- domUtils.addClass(this.editor.commandTargets.get('showBlocks'), 'active');
345
+ dom.utils.addClass(this.editor.commandTargets.get('showBlocks'), 'active');
315
346
  } else {
316
- domUtils.removeClass(this.editor.commandTargets.get('showBlocks'), 'active');
347
+ dom.utils.removeClass(this.editor.commandTargets.get('showBlocks'), 'active');
317
348
  }
318
349
  },
319
350
 
320
351
  /**
352
+ * @this {ViewerThis}
321
353
  * @description Prints the current content of the editor.
322
354
  */
323
355
  print() {
324
- const iframe = domUtils.createElement('IFRAME', { style: 'display: none;' });
356
+ /** @type {HTMLIFrameElement} */
357
+ const iframe = dom.utils.createElement('IFRAME', { style: 'display: none;' });
325
358
  this._d.body.appendChild(iframe);
326
359
 
327
- const contentHTML = this.options.get('printTemplate') ? this.options.get('printTemplate').replace(/\{\{\s*contents\s*\}\}/i, this.html.get(true)) : this.html.get(true);
328
- const printDocument = domUtils.getIframeDocument(iframe);
360
+ const innerPadding = this._w.getComputedStyle(this.editor.frameContext.get('wysiwyg')).padding;
361
+ const contentHTML = this.options.get('printTemplate') ? this.options.get('printTemplate').replace(/\{\{\s*contents\s*\}\}/i, this.html.get()) : this.html.get();
362
+ const printDocument = dom.query.getIframeDocument(iframe);
329
363
  const wDoc = this.editor.frameContext.get('_wd');
364
+ const rtlClass = this.options.get('_rtl') ? ' se-rtl' : '';
365
+ const pageCSS = /*html*/ `
366
+ <style>
367
+ @page {
368
+ size: A4;
369
+ margin: ${innerPadding};
370
+ }
371
+ </style>`;
330
372
 
331
373
  if (this.editor.frameOptions.get('iframe')) {
332
374
  const arrts = this.options.get('printClass')
333
- ? 'class="' + this.options.get('printClass') + '"'
375
+ ? 'class="' + this.options.get('printClass') + rtlClass + '"'
334
376
  : this.editor.frameOptions.get('iframe_fullPage')
335
- ? domUtils.getAttributesToString(wDoc.body, ['contenteditable'])
336
- : 'class="' + this.options.get('_editableClass') + '"';
377
+ ? dom.utils.getAttributesToString(wDoc.body, ['contenteditable'])
378
+ : 'class="' + this.options.get('_editableClass') + rtlClass + '"';
337
379
 
338
- printDocument.write('' + '<!DOCTYPE html><html>' + '<head>' + wDoc.head.innerHTML + '</head>' + '<body ' + arrts + '>' + contentHTML + '</body>' + '</html>');
380
+ printDocument.write(/*html*/ `
381
+ <!DOCTYPE html>
382
+ <html>
383
+ <head>
384
+ ${wDoc.head.innerHTML}
385
+ ${pageCSS}
386
+ </head>
387
+ <body ${arrts} style="padding: 0; padding-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0;">
388
+ ${contentHTML}
389
+ </body>
390
+ </html>`);
339
391
  } else {
340
392
  const links = this._d.head.getElementsByTagName('link');
341
393
  const styles = this._d.head.getElementsByTagName('style');
@@ -347,23 +399,25 @@ Viewer.prototype = {
347
399
  linkHTML += styles[i].outerHTML;
348
400
  }
349
401
 
350
- printDocument.write(/*html*/ `<!DOCTYPE html>
402
+ printDocument.write(/*html*/ `
403
+ <!DOCTYPE html>
351
404
  <html>
352
405
  <head>
353
406
  ${linkHTML}
407
+ ${pageCSS}
354
408
  </head>
355
- <body class="${this.options.get('printClass') ? this.options.get('printClass') : this.options.get('_editableClass')}">
356
- ${contentHTML}
409
+ <body class="${(this.options.get('printClass') || this.options.get('_editableClass')) + rtlClass}" style="padding: 0; padding-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0;">
410
+ ${contentHTML}
357
411
  </body>
358
412
  </html>`);
359
413
  }
360
414
 
361
- this.editor.showLoading();
415
+ this.ui.showLoading();
362
416
  this._w.setTimeout(() => {
363
417
  try {
364
418
  iframe.focus();
365
419
  // Edge, Chromium
366
- if (env.isEdge || env.isChromium || this._d.documentMode || this._w.StyleMedia) {
420
+ if (env.isEdge || env.isChromium || 'StyleMedia' in env._w) {
367
421
  try {
368
422
  iframe.contentWindow.document.execCommand('print', false, null);
369
423
  } catch (e) {
@@ -377,39 +431,40 @@ Viewer.prototype = {
377
431
  } catch (error) {
378
432
  throw Error(`[SUNEDITOR.print.fail] error: ${error.message}`);
379
433
  } finally {
380
- this.editor.hideLoading();
381
- domUtils.removeItem(iframe);
434
+ this.ui.hideLoading();
435
+ dom.utils.removeItem(iframe);
382
436
  }
383
437
  }, 1000);
384
438
  },
385
439
 
386
440
  /**
441
+ * @this {ViewerThis}
387
442
  * @description Open the preview window.
388
443
  */
389
444
  preview() {
390
445
  this.menu.dropdownOff();
391
446
  this.menu.containerOff();
392
- this.editor._offCurrentController();
393
- this.editor._offCurrentModal();
447
+ this.ui._offCurrentController();
448
+ this.ui._offCurrentModal();
394
449
 
395
- const contentHTML = this.options.get('previewTemplate') ? this.options.get('previewTemplate').replace(/\{\{\s*contents\s*\}\}/i, this.html.get(true)) : this.html.get(true);
450
+ const contentHTML = this.options.get('previewTemplate') ? this.options.get('previewTemplate').replace(/\{\{\s*contents\s*\}\}/i, this.html.get({ withFrame: true })) : this.html.get({ withFrame: true });
396
451
  const windowObject = this._w.open('', '_blank');
397
- windowObject.mimeType = 'text/html';
398
452
  const wDoc = this.editor.frameContext.get('_wd');
453
+ const rtlClass = this.options.get('_rtl') ? ' se-rtl' : '';
399
454
 
400
455
  if (this.editor.frameOptions.get('iframe')) {
401
456
  const arrts = this.options.get('printClass')
402
- ? 'class="' + this.options.get('printClass') + '"'
457
+ ? 'class="' + this.options.get('printClass') + rtlClass + '"'
403
458
  : this.editor.frameOptions.get('iframe_fullPage')
404
- ? domUtils.getAttributesToString(wDoc.body, ['contenteditable'])
405
- : 'class="' + this.options.get('_editableClass') + '"';
459
+ ? dom.utils.getAttributesToString(wDoc.body, ['contenteditable'])
460
+ : 'class="' + this.options.get('_editableClass') + rtlClass + '"';
406
461
 
407
462
  windowObject.document.write(/*html*/ `<!DOCTYPE html>
408
463
  <html>
409
464
  <head>
410
465
  ${wDoc.head.innerHTML}
411
466
  <style>
412
- body {overflow:auto !important; margin: 10px auto !important; height:auto !important; outline:1px dashed #ccc;}
467
+ body {overflow:auto !important; height:auto !important;}
413
468
  </style>
414
469
  </head>
415
470
  <body ${arrts}>
@@ -435,13 +490,19 @@ Viewer.prototype = {
435
490
  <title>${this.lang.preview}</title>
436
491
  ${linkHTML}
437
492
  </head>
438
- <body class="${this.options.get('printClass') ? this.options.get('printClass') : this.options.get('_editableClass')}" style="margin:10px auto !important; height:auto !important; outline:1px dashed #ccc;">
493
+ <body class="${(this.options.get('printClass') ? this.options.get('printClass') : this.options.get('_editableClass')) + rtlClass}" style="height:auto">
439
494
  ${contentHTML}
440
495
  </body>
441
496
  </html>`);
442
497
  }
443
498
  },
444
499
 
500
+ /**
501
+ * @private
502
+ * @this {ViewerThis}
503
+ * @description Resets the full-screen height of the editor.
504
+ * - Updates the editor's height dynamically when in full-screen mode.
505
+ */
445
506
  _resetFullScreenHeight() {
446
507
  if (this.editor.frameContext.get('isFullScreen')) {
447
508
  this.fullScreenInnerHeight +=
@@ -452,12 +513,12 @@ Viewer.prototype = {
452
513
  },
453
514
 
454
515
  /**
516
+ * @private
517
+ * @this {ViewerThis}
455
518
  * @description Run CodeMirror Editor
456
519
  * @param {"set"|"get"|"readonly"|"refresh"} key method key
457
- * @param {any} value params
520
+ * @param {*} value CodeMirror params
458
521
  * @param {string|undefined} rootKey Root key
459
- * @returns
460
- * @private
461
522
  */
462
523
  _codeMirrorEditor(key, value, rootKey) {
463
524
  const fo = rootKey ? this.frameRoots.get(rootKey).get('options') : this.editor.frameOptions;
@@ -495,9 +556,10 @@ Viewer.prototype = {
495
556
  },
496
557
 
497
558
  /**
559
+ * @private
560
+ * @this {ViewerThis}
498
561
  * @description Set method in the code view area
499
562
  * @param {string} value HTML string
500
- * @private
501
563
  */
502
564
  _setCodeView(value) {
503
565
  if (this.options.get('hasCodeMirror')) {
@@ -508,8 +570,9 @@ Viewer.prototype = {
508
570
  },
509
571
 
510
572
  /**
511
- * @description Get method in the code view area
512
573
  * @private
574
+ * @this {ViewerThis}
575
+ * @description Get method in the code view area
513
576
  */
514
577
  _getCodeView() {
515
578
  if (this.options.get('hasCodeMirror')) {
@@ -520,8 +583,9 @@ Viewer.prototype = {
520
583
  },
521
584
 
522
585
  /**
523
- * @description Convert the data of the code view and put it in the WYSIWYG area.
524
586
  * @private
587
+ * @this {ViewerThis}
588
+ * @description Convert the data of the code view and put it in the WYSIWYG area.
525
589
  */
526
590
  _setCodeDataToEditor() {
527
591
  const code_html = this._getCodeView();
@@ -547,34 +611,38 @@ Viewer.prototype = {
547
611
  }
548
612
 
549
613
  wDoc.head.innerHTML = headers;
550
- wDoc.body.innerHTML = this.html.clean(parseDocument.body.innerHTML, true, null, null);
614
+ wDoc.body.innerHTML = this.html.clean(parseDocument.body.innerHTML, { forceFormat: true, whitelist: null, blacklist: null, _freeCodeViewMode: this.options.get('freeCodeViewMode') });
551
615
 
552
616
  const attrs = parseDocument.body.attributes;
553
617
  for (let i = 0, len = attrs.length; i < len; i++) {
554
618
  if (attrs[i].name === 'contenteditable') continue;
555
619
  wDoc.body.setAttribute(attrs[i].name, attrs[i].value);
556
620
  }
557
- if (!domUtils.hasClass(wDoc.body, 'sun-editor-editable')) {
621
+ if (!dom.utils.hasClass(wDoc.body, 'sun-editor-editable')) {
558
622
  const editableClasses = this.options.get('_editableClass').split(' ');
559
623
  for (let i = 0; i < editableClasses.length; i++) {
560
- domUtils.addClass(wDoc.body, this.options.get('_editableClass')[i]);
624
+ dom.utils.addClass(wDoc.body, this.options.get('_editableClass')[i]);
561
625
  }
562
626
  }
563
627
  } else {
564
- this.editor.frameContext.get('wysiwyg').innerHTML = code_html.length > 0 ? this.html.clean(code_html, true, null, null) : '<' + this.options.get('defaultLine') + '><br></' + this.options.get('defaultLine') + '>';
628
+ this.editor.frameContext.get('wysiwyg').innerHTML =
629
+ code_html.length > 0
630
+ ? this.html.clean(code_html, { forceFormat: true, whitelist: null, blacklist: null, _freeCodeViewMode: this.options.get('freeCodeViewMode') })
631
+ : '<' + this.options.get('defaultLine') + '><br></' + this.options.get('defaultLine') + '>';
565
632
  }
566
633
  },
567
634
 
568
635
  /**
569
- * @description Convert the data of the WYSIWYG area and put it in the code view area.
570
636
  * @private
637
+ * @this {ViewerThis}
638
+ * @description Convert the data of the WYSIWYG area and put it in the code view area.
571
639
  */
572
640
  _setEditorDataToCodeView() {
573
641
  const codeContent = this.html._convertToCode(this.editor.frameContext.get('wysiwyg'), false);
574
642
  let codeValue = '';
575
643
 
576
644
  if (this.editor.frameOptions.get('iframe_fullPage')) {
577
- const attrs = domUtils.getAttributesToString(this.editor.frameContext.get('_wd').body, null);
645
+ const attrs = dom.utils.getAttributesToString(this.editor.frameContext.get('_wd').body, null);
578
646
  codeValue = '<!DOCTYPE html>\n<html>\n' + this.editor.frameContext.get('_wd').head.outerHTML.replace(/>(?!\n)/g, '>\n') + '<body ' + attrs + '>\n' + codeContent + '</body>\n</html>';
579
647
  } else {
580
648
  codeValue = codeContent;
@@ -583,11 +651,28 @@ Viewer.prototype = {
583
651
  this._setCodeView(codeValue);
584
652
  },
585
653
 
654
+ /**
655
+ * @private
656
+ * @this {ViewerThis}
657
+ * @description Adjusts the height of the code view area.
658
+ * - Ensures the code block auto-resizes based on its content.
659
+ * @param {HTMLElement} code - Code area
660
+ * @param {HTMLTextAreaElement} codeNumbers - Code numbers area
661
+ * @param {boolean} isAuto - Auto height option
662
+ */
586
663
  _codeViewAutoHeight(code, codeNumbers, isAuto) {
587
664
  if (isAuto) code.style.height = code.scrollHeight + 'px';
588
665
  this._updateLineNumbers(codeNumbers, code);
589
666
  },
590
667
 
668
+ /**
669
+ * @private
670
+ * @this {ViewerThis}
671
+ * @description Updates the line numbers for the code editor.
672
+ * - Dynamically adjusts line numbers as content grows.
673
+ * @param {HTMLTextAreaElement} lineNumbers - Code numbers area
674
+ * @param {HTMLElement} code - Code area
675
+ */
591
676
  _updateLineNumbers(lineNumbers, code) {
592
677
  if (!lineNumbers) return;
593
678
 
@@ -604,6 +689,13 @@ Viewer.prototype = {
604
689
  }
605
690
  },
606
691
 
692
+ /**
693
+ * @private
694
+ * @this {HTMLElement} Code numbers area
695
+ * @description Synchronizes scrolling of line numbers with the code editor.
696
+ * - Keeps the line numbers aligned with the text.
697
+ * @param {HTMLTextAreaElement} codeNumbers - Code numbers textarea
698
+ */
607
699
  _scrollLineNumbers(codeNumbers) {
608
700
  codeNumbers.scrollTop = this.scrollTop;
609
701
  codeNumbers.scrollLeft = this.scrollLeft;
@@ -612,6 +704,11 @@ Viewer.prototype = {
612
704
  constructor: Viewer
613
705
  };
614
706
 
707
+ /**
708
+ * @private
709
+ * @description Create line numbers for the code view area
710
+ * @param {__se__FrameContext} fc - Frame context
711
+ */
615
712
  function CreateLineNumbers(fc) {
616
713
  const codeNumbers = fc.get('codeNumbers');
617
714
  if (!codeNumbers) return;
@@ -630,17 +727,24 @@ function CreateLineNumbers(fc) {
630
727
  codeNumbers.style.margin = margin || '';
631
728
  }
632
729
 
730
+ /**
731
+ * @private
732
+ * @description Get the line height of the textarea
733
+ * @param {HTMLTextAreaElement} textarea Textarea element
734
+ * @returns {number}
735
+ */
633
736
  function GetLineHeight(textarea) {
634
- let lineHeight = env._w.getComputedStyle(textarea).lineHeight;
737
+ const lineHeight = env._w.getComputedStyle(textarea).lineHeight;
738
+ let lineHeightMatch;
635
739
 
636
740
  if (!numbers.is(lineHeight)) {
637
741
  const fontSize = env._w.getComputedStyle(textarea).fontSize;
638
- lineHeight = numbers.get(fontSize) * 1.2;
742
+ lineHeightMatch = numbers.get(fontSize) * 1.2;
639
743
  } else {
640
- lineHeight = numbers.get(lineHeight);
744
+ lineHeightMatch = numbers.get(lineHeight);
641
745
  }
642
746
 
643
- return lineHeight;
747
+ return lineHeightMatch;
644
748
  }
645
749
 
646
750
  export default Viewer;