suneditor 2.46.2 → 3.0.0-alpha.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 (289) 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/package.json +94 -70
  7. package/src/assets/icons/_default.js +194 -0
  8. package/src/assets/suneditor-content.css +642 -0
  9. package/src/assets/suneditor.css +3378 -0
  10. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  11. package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
  12. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
  13. package/src/core/base/eventHandlers/handler_ww_key_input.js +978 -0
  14. package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
  15. package/src/core/base/eventManager.js +1129 -0
  16. package/src/core/base/events.js +320 -0
  17. package/src/core/base/history.js +301 -0
  18. package/src/core/class/char.js +146 -0
  19. package/src/core/class/component.js +624 -0
  20. package/src/core/class/format.js +3255 -0
  21. package/src/core/class/html.js +1621 -0
  22. package/src/core/class/menu.js +260 -0
  23. package/src/core/class/nodeTransform.js +379 -0
  24. package/src/core/class/notice.js +42 -0
  25. package/src/core/class/offset.js +578 -0
  26. package/src/core/class/selection.js +508 -0
  27. package/src/core/class/shortcuts.js +38 -0
  28. package/src/core/class/toolbar.js +440 -0
  29. package/src/core/class/viewer.js +646 -0
  30. package/src/core/editor.js +1588 -0
  31. package/src/core/section/actives.js +107 -0
  32. package/src/core/section/constructor.js +1237 -0
  33. package/src/core/section/context.js +97 -0
  34. package/src/editorInjector/_classes.js +22 -0
  35. package/src/editorInjector/_core.js +28 -0
  36. package/src/editorInjector/index.js +13 -0
  37. package/src/helper/converter.js +313 -0
  38. package/src/helper/domUtils.js +1177 -0
  39. package/src/helper/env.js +250 -0
  40. package/src/helper/index.js +19 -0
  41. package/src/helper/numbers.js +68 -0
  42. package/src/helper/unicode.js +43 -0
  43. package/src/langs/ckb.js +161 -0
  44. package/src/langs/cs.js +161 -0
  45. package/src/langs/da.js +161 -0
  46. package/src/langs/de.js +162 -0
  47. package/src/langs/en.js +199 -0
  48. package/src/langs/es.js +162 -0
  49. package/src/langs/fa.js +159 -0
  50. package/src/langs/fr.js +161 -0
  51. package/src/langs/he.js +162 -0
  52. package/src/{lang → langs}/index.js +0 -2
  53. package/src/langs/it.js +162 -0
  54. package/src/langs/ja.js +162 -0
  55. package/src/langs/ko.js +162 -0
  56. package/src/langs/lv.js +162 -0
  57. package/src/langs/nl.js +162 -0
  58. package/src/langs/pl.js +162 -0
  59. package/src/langs/pt_br.js +162 -0
  60. package/src/langs/ro.js +162 -0
  61. package/src/langs/ru.js +162 -0
  62. package/src/langs/se.js +162 -0
  63. package/src/langs/tr.js +159 -0
  64. package/src/langs/ua.js +162 -0
  65. package/src/langs/ur.js +162 -0
  66. package/src/langs/zh_cn.js +162 -0
  67. package/src/modules/ApiManager.js +168 -0
  68. package/src/modules/ColorPicker.js +302 -0
  69. package/src/modules/Controller.js +315 -0
  70. package/src/modules/Figure.js +1174 -0
  71. package/src/modules/FileBrowser.js +271 -0
  72. package/src/modules/FileManager.js +290 -0
  73. package/src/modules/HueSlider.js +513 -0
  74. package/src/modules/Modal.js +177 -0
  75. package/src/modules/ModalAnchorEditor.js +494 -0
  76. package/src/modules/SelectMenu.js +447 -0
  77. package/src/modules/_DragHandle.js +16 -0
  78. package/src/modules/index.js +14 -0
  79. package/src/plugins/command/blockquote.js +47 -47
  80. package/src/plugins/command/exportPdf.js +168 -0
  81. package/src/plugins/command/fileUpload.js +389 -0
  82. package/src/plugins/command/list_bulleted.js +112 -0
  83. package/src/plugins/command/list_numbered.js +115 -0
  84. package/src/plugins/dropdown/align.js +143 -0
  85. package/src/plugins/dropdown/backgroundColor.js +73 -0
  86. package/src/plugins/dropdown/font.js +113 -0
  87. package/src/plugins/dropdown/fontColor.js +73 -0
  88. package/src/plugins/dropdown/formatBlock.js +141 -0
  89. package/src/plugins/dropdown/hr.js +111 -0
  90. package/src/plugins/dropdown/layout.js +72 -0
  91. package/src/plugins/dropdown/lineHeight.js +114 -0
  92. package/src/plugins/dropdown/list.js +107 -0
  93. package/src/plugins/dropdown/paragraphStyle.js +117 -0
  94. package/src/plugins/dropdown/table.js +2810 -0
  95. package/src/plugins/dropdown/template.js +71 -0
  96. package/src/plugins/dropdown/textStyle.js +137 -0
  97. package/src/plugins/field/mention.js +172 -0
  98. package/src/plugins/fileBrowser/imageGallery.js +76 -59
  99. package/src/plugins/index.js +86 -24
  100. package/src/plugins/input/fontSize.js +357 -0
  101. package/src/plugins/modal/audio.js +492 -0
  102. package/src/plugins/modal/image.js +1062 -0
  103. package/src/plugins/modal/link.js +211 -0
  104. package/src/plugins/modal/math.js +347 -0
  105. package/src/plugins/modal/video.js +870 -0
  106. package/src/suneditor.js +62 -67
  107. package/src/themes/test.css +61 -0
  108. package/typings/CommandPlugin.d.ts +8 -0
  109. package/typings/DialogPlugin.d.ts +20 -0
  110. package/typings/FileBrowserPlugin.d.ts +30 -0
  111. package/typings/Lang.d.ts +124 -0
  112. package/typings/Module.d.ts +15 -0
  113. package/typings/Plugin.d.ts +42 -0
  114. package/typings/SubmenuPlugin.d.ts +8 -0
  115. package/typings/_classes.d.ts +17 -0
  116. package/typings/_colorPicker.d.ts +60 -0
  117. package/typings/_core.d.ts +55 -0
  118. package/typings/align.d.ts +5 -0
  119. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  120. package/typings/backgroundColor.d.ts +5 -0
  121. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  122. package/typings/char.d.ts +39 -0
  123. package/typings/component.d.ts +38 -0
  124. package/typings/context.d.ts +39 -0
  125. package/typings/converter.d.ts +33 -0
  126. package/typings/dialog.d.ts +28 -0
  127. package/typings/domUtils.d.ts +361 -0
  128. package/typings/editor.d.ts +7 -0
  129. package/typings/editor.ts +542 -0
  130. package/typings/env.d.ts +70 -0
  131. package/typings/eventManager.d.ts +37 -0
  132. package/typings/events.d.ts +262 -0
  133. package/typings/fileBrowser.d.ts +42 -0
  134. package/typings/fileManager.d.ts +67 -0
  135. package/typings/font.d.ts +5 -0
  136. package/typings/fontColor.d.ts +5 -0
  137. package/typings/fontSize.d.ts +5 -0
  138. package/typings/format.d.ts +191 -0
  139. package/typings/formatBlock.d.ts +5 -0
  140. package/typings/history.d.ts +48 -0
  141. package/typings/horizontalRule.d.ts +5 -0
  142. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  143. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  144. package/typings/index.d.ts +21 -0
  145. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  146. package/typings/index.plugins.d.ts +58 -0
  147. package/typings/lineHeight.d.ts +5 -0
  148. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  149. package/typings/list.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  151. package/typings/mediaContainer.d.ts +25 -0
  152. package/typings/node.d.ts +57 -0
  153. package/typings/notice.d.ts +16 -0
  154. package/typings/numbers.d.ts +29 -0
  155. package/typings/offset.d.ts +24 -0
  156. package/typings/options.d.ts +589 -0
  157. package/typings/paragraphStyle.d.ts +5 -0
  158. package/typings/resizing.d.ts +141 -0
  159. package/typings/selection.d.ts +94 -0
  160. package/typings/shortcuts.d.ts +13 -0
  161. package/typings/suneditor.d.ts +9 -0
  162. package/typings/table.d.ts +5 -0
  163. package/typings/template.d.ts +5 -0
  164. package/typings/textStyle.d.ts +5 -0
  165. package/typings/toolbar.d.ts +32 -0
  166. package/typings/unicode.d.ts +25 -0
  167. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  168. package/dist/css/suneditor.min.css +0 -1
  169. package/dist/suneditor.min.js +0 -2
  170. package/src/assets/css/suneditor-contents.css +0 -562
  171. package/src/assets/css/suneditor.css +0 -566
  172. package/src/assets/defaultIcons.js +0 -103
  173. package/src/lang/Lang.d.ts +0 -144
  174. package/src/lang/ckb.d.ts +0 -5
  175. package/src/lang/ckb.js +0 -188
  176. package/src/lang/cs.d.ts +0 -5
  177. package/src/lang/cs.js +0 -188
  178. package/src/lang/da.d.ts +0 -5
  179. package/src/lang/da.js +0 -191
  180. package/src/lang/de.d.ts +0 -5
  181. package/src/lang/de.js +0 -188
  182. package/src/lang/en.d.ts +0 -5
  183. package/src/lang/en.js +0 -188
  184. package/src/lang/es.d.ts +0 -5
  185. package/src/lang/es.js +0 -188
  186. package/src/lang/fa.d.ts +0 -5
  187. package/src/lang/fa.js +0 -188
  188. package/src/lang/fr.d.ts +0 -5
  189. package/src/lang/fr.js +0 -188
  190. package/src/lang/he.d.ts +0 -5
  191. package/src/lang/he.js +0 -188
  192. package/src/lang/index.d.ts +0 -23
  193. package/src/lang/it.d.ts +0 -5
  194. package/src/lang/it.js +0 -188
  195. package/src/lang/ja.d.ts +0 -5
  196. package/src/lang/ja.js +0 -188
  197. package/src/lang/ko.d.ts +0 -5
  198. package/src/lang/ko.js +0 -188
  199. package/src/lang/lv.d.ts +0 -5
  200. package/src/lang/lv.js +0 -188
  201. package/src/lang/nl.d.ts +0 -5
  202. package/src/lang/nl.js +0 -188
  203. package/src/lang/pl.d.ts +0 -5
  204. package/src/lang/pl.js +0 -188
  205. package/src/lang/pt_br.d.ts +0 -5
  206. package/src/lang/pt_br.js +0 -189
  207. package/src/lang/ro.d.ts +0 -5
  208. package/src/lang/ro.js +0 -188
  209. package/src/lang/ru.d.ts +0 -5
  210. package/src/lang/ru.js +0 -188
  211. package/src/lang/se.d.ts +0 -5
  212. package/src/lang/se.js +0 -191
  213. package/src/lang/tr.d.ts +0 -5
  214. package/src/lang/tr.js +0 -191
  215. package/src/lang/ua.d.ts +0 -5
  216. package/src/lang/ua.js +0 -188
  217. package/src/lang/ur.d.ts +0 -5
  218. package/src/lang/ur.js +0 -188
  219. package/src/lang/zh_cn.d.ts +0 -5
  220. package/src/lang/zh_cn.js +0 -187
  221. package/src/lib/constructor.js +0 -954
  222. package/src/lib/context.d.ts +0 -42
  223. package/src/lib/context.js +0 -71
  224. package/src/lib/core.d.ts +0 -1135
  225. package/src/lib/core.js +0 -9395
  226. package/src/lib/history.d.ts +0 -48
  227. package/src/lib/history.js +0 -219
  228. package/src/lib/util.d.ts +0 -678
  229. package/src/lib/util.js +0 -2131
  230. package/src/options.d.ts +0 -608
  231. package/src/plugins/CommandPlugin.d.ts +0 -8
  232. package/src/plugins/DialogPlugin.d.ts +0 -20
  233. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  234. package/src/plugins/Module.d.ts +0 -15
  235. package/src/plugins/Plugin.d.ts +0 -42
  236. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  237. package/src/plugins/dialog/audio.js +0 -559
  238. package/src/plugins/dialog/image.js +0 -1126
  239. package/src/plugins/dialog/link.js +0 -223
  240. package/src/plugins/dialog/math.js +0 -295
  241. package/src/plugins/dialog/mention.js +0 -242
  242. package/src/plugins/dialog/video.js +0 -979
  243. package/src/plugins/index.d.ts +0 -79
  244. package/src/plugins/modules/_anchor.js +0 -461
  245. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  246. package/src/plugins/modules/_colorPicker.js +0 -201
  247. package/src/plugins/modules/_notice.d.ts +0 -21
  248. package/src/plugins/modules/_notice.js +0 -72
  249. package/src/plugins/modules/_selectMenu.js +0 -119
  250. package/src/plugins/modules/component.d.ts +0 -25
  251. package/src/plugins/modules/component.js +0 -81
  252. package/src/plugins/modules/dialog.d.ts +0 -28
  253. package/src/plugins/modules/dialog.js +0 -175
  254. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  255. package/src/plugins/modules/fileBrowser.js +0 -374
  256. package/src/plugins/modules/fileManager.d.ts +0 -67
  257. package/src/plugins/modules/fileManager.js +0 -326
  258. package/src/plugins/modules/index.js +0 -9
  259. package/src/plugins/modules/resizing.d.ts +0 -154
  260. package/src/plugins/modules/resizing.js +0 -903
  261. package/src/plugins/submenu/align.d.ts +0 -5
  262. package/src/plugins/submenu/align.js +0 -160
  263. package/src/plugins/submenu/font.d.ts +0 -5
  264. package/src/plugins/submenu/font.js +0 -123
  265. package/src/plugins/submenu/fontColor.d.ts +0 -5
  266. package/src/plugins/submenu/fontColor.js +0 -101
  267. package/src/plugins/submenu/fontSize.d.ts +0 -5
  268. package/src/plugins/submenu/fontSize.js +0 -112
  269. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  270. package/src/plugins/submenu/formatBlock.js +0 -273
  271. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  272. package/src/plugins/submenu/hiliteColor.js +0 -102
  273. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  274. package/src/plugins/submenu/horizontalRule.js +0 -98
  275. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  276. package/src/plugins/submenu/lineHeight.js +0 -104
  277. package/src/plugins/submenu/list.d.ts +0 -5
  278. package/src/plugins/submenu/list.js +0 -456
  279. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  280. package/src/plugins/submenu/paragraphStyle.js +0 -135
  281. package/src/plugins/submenu/table.d.ts +0 -5
  282. package/src/plugins/submenu/table.js +0 -1431
  283. package/src/plugins/submenu/template.d.ts +0 -5
  284. package/src/plugins/submenu/template.js +0 -72
  285. package/src/plugins/submenu/textStyle.d.ts +0 -5
  286. package/src/plugins/submenu/textStyle.js +0 -167
  287. package/src/suneditor.d.ts +0 -9
  288. package/src/suneditor_build.js +0 -18
  289. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -0,0 +1,320 @@
1
+ export default function () {
2
+ return {
3
+ /**
4
+ * @description Event functions
5
+ */
6
+ onload: null,
7
+ onScroll: null,
8
+ onMouseDown: null,
9
+ onClick: null,
10
+ onInput: null,
11
+ onMouseLeave: null,
12
+ onKeyDown: null,
13
+ onKeyUp: null,
14
+ onCopy: null,
15
+ onCut: null,
16
+ onFocus: null,
17
+ onBlur: null,
18
+ onChange: null,
19
+
20
+ /**
21
+ * @description Called just before the inline toolbar is positioned and displayed on the screen.
22
+ * @param {Element} toolbar Toolbar Element
23
+ * @param {Object} context The editor's context object (editor.getContext())
24
+ * @param {Object} core Core object
25
+ */
26
+ onShowToolbar: null,
27
+
28
+ /**
29
+ * @description Called just after the controller is positioned and displayed on the screen.
30
+ * controller - editing elements displayed on the screen [image resizing, table editor, link editor..]]
31
+ * @param {String} name The name of the plugin that called the controller
32
+ * @param {Array} controllers Array of Controller elements
33
+ * @param {Object} core Core object
34
+ */
35
+ onShowController: null,
36
+ onBeforeShowController: null,
37
+
38
+ /**
39
+ * @description An event when toggling between code view and wysiwyg view.
40
+ * @param {Boolean} isCodeView Whether the current code view mode
41
+ * @param {Object} core Core object
42
+ */
43
+ onToggleCodeView: null,
44
+
45
+ /**
46
+ * @description An event when toggling full screen.
47
+ * @param {Boolean} isFullScreen Whether the current full screen mode
48
+ * @param {Object} core Core object
49
+ */
50
+ onToggleFullScreen: null,
51
+
52
+ /**
53
+ * @description Called when the editor is resized using the bottom bar
54
+ */
55
+ onResizeEditor: null,
56
+
57
+ /**
58
+ * @description Called after the "setToolbarButtons" invocation.
59
+ * Can be used to tweak buttons properties (useful for custom buttons)
60
+ * @param {Element} buttonTray Button tray element
61
+ * @param {Object} core Core object
62
+ */
63
+ onSetToolbarButtons: null,
64
+
65
+ /**
66
+ * --------------------------------------------------- async function ---------------------------------------------------
67
+ */
68
+
69
+ /**
70
+ * @description Event functions
71
+ * @param {String} contents Current contents
72
+ * @param {String|null} key Root key
73
+ */
74
+ onSave: null,
75
+
76
+ /**
77
+ * @description Event functions (drop, paste)
78
+ * When false is returned, the default behavior is stopped.
79
+ * If the string is returned, the cleanData value is modified to the return value.
80
+ * @param {Object} e Event object.
81
+ * @param {String} cleanData HTML string modified for editor format.
82
+ * @param {Boolean} maxChartCount option (true if max character is exceeded)
83
+ * @param {Object} core Core object
84
+ * @returns {Boolean|String}
85
+ */
86
+ onDrop: null,
87
+ onPaste: null,
88
+
89
+ /**
90
+ * @description It replaces the default callback function of the image upload
91
+ * @param {Object} response Response object
92
+ * @param {Object} info Input information
93
+ * - linkValue: Link url value
94
+ * - linkNewWindow: Open in new window Check Value
95
+ * - inputWidth: Value of width input
96
+ * - inputHeight: Value of height input
97
+ * - align: Align Check Value
98
+ * - isUpdate: Update image if true, create image if false
99
+ * - element: If isUpdate is true, the currently selected image.
100
+ * @param {Object} core Core object
101
+ */
102
+ imageUploadHandler: null,
103
+
104
+ /**
105
+ * @description Called before the image is uploaded
106
+ * If true is returned, the internal upload process runs normally.
107
+ * If false is returned, no image upload is performed.
108
+ * If new fileList are returned, replaced the previous fileList
109
+ * If undefined is returned, it waits until "uploadHandler" is executed.
110
+ * @param {Array} files Files array
111
+ * @param {Object} info info: {
112
+ * - linkValue: Link url value
113
+ * - linkNewWindow: Open in new window Check Value
114
+ * - inputWidth: Value of width input
115
+ * - inputHeight: Value of height input
116
+ * - align: Align Check Value
117
+ * - isUpdate: Update image if true, create image if false
118
+ * - element: If isUpdate is true, the currently selected image.
119
+ * }
120
+ * @param {Object} core Core object
121
+ * @param {Function} uploadHandler If undefined is returned, it waits until "uploadHandler" is executed.
122
+ * "uploadHandler" is an upload function with "core" and "info" bound.
123
+ * [upload files] : uploadHandler(files or [new File(...),])
124
+ * [error] : uploadHandler("Error message")
125
+ * [Just finish] : uploadHandler()
126
+ * [directly register] : uploadHandler(response) // Same format as "imageUploadUrl" response
127
+ * ex) {
128
+ * // "errorMessage": "insert error message",
129
+ * "result": [ { "url": "...", "name": "...", "size": "999" }, ]
130
+ * }
131
+ * @returns {Boolean|Array|undefined}
132
+ */
133
+ onImageUploadBefore: null,
134
+
135
+ /**
136
+ * @description Called before the image is deleted
137
+ */
138
+ onImageDeleteBefore: null,
139
+
140
+ /**
141
+ * @description Called when the editor loaded, file Current editor value
142
+ * -- arguments is same "Image info object" --
143
+ */
144
+ onImageLoad: null,
145
+
146
+ /**
147
+ * @description Called when the image is uploaded, updated, deleted
148
+ * @param {Element} targetElement Target element
149
+ * @param {Number} index Uploaded index
150
+ * @param {String} state Upload status ('create', 'update', 'delete')
151
+ * @param {Object} info Image info object
152
+ * - index: data index
153
+ * - name: file name
154
+ * - size: file size
155
+ * - select: select function
156
+ * - delete: delete function
157
+ * - element: target element
158
+ * - src: src attribute of tag
159
+ * @param {Number} remainingFilesCount Count of remaining files to upload (0 when added as a url)
160
+ * @param {Object} core Core object
161
+ */
162
+ onImageAction: null,
163
+
164
+ /**
165
+ * @description Called when the image is upload failed
166
+ * @param {String} errorMessage Error message
167
+ * @param {Object} result Response Object
168
+ * @param {Object} core Core object
169
+ * @returns {Boolean}
170
+ */
171
+ onImageUploadError: null,
172
+
173
+ /**
174
+ * @description It replaces the default callback function of the video upload
175
+ * @param xmlHttp xmlHttpRequest object
176
+ * @param info Input information
177
+ * - inputWidth: Value of width input
178
+ * - inputHeight: Value of height input
179
+ * - align: Align Check Value
180
+ * - isUpdate: Update video if true, create video if false
181
+ * - element: If isUpdate is true, the currently selected video.
182
+ * @param core Core object
183
+ */
184
+ videoUploadHandler: null,
185
+
186
+ /**
187
+ * @description Called before the video is uploaded
188
+ * If true is returned, the internal upload process runs normally.
189
+ * If false is returned, no video(iframe, video) upload is performed.
190
+ * If new fileList are returned, replaced the previous fileList
191
+ * If undefined is returned, it waits until "uploadHandler" is executed.
192
+ * @param {Array} files Files array
193
+ * @param {Object} info info: {
194
+ * - inputWidth: Value of width input
195
+ * - inputHeight: Value of height input
196
+ * - align: Align Check Value
197
+ * - isUpdate: Update video if true, create video if false
198
+ * - element: If isUpdate is true, the currently selected video.
199
+ * }
200
+ * @param {Object} core Core object
201
+ * @param {Function} uploadHandler If undefined is returned, it waits until "uploadHandler" is executed.
202
+ * "uploadHandler" is an upload function with "core" and "info" bound.
203
+ * [upload files] : uploadHandler(files or [new File(...),])
204
+ * [error] : uploadHandler("Error message")
205
+ * [Just finish] : uploadHandler()
206
+ * [directly register] : uploadHandler(response) // Same format as "videoUploadUrl" response
207
+ * ex) {
208
+ * // "errorMessage": "insert error message",
209
+ * "result": [ { "url": "...", "name": "...", "size": "999" }, ]
210
+ * }
211
+ * @returns {Boolean|Array|undefined}
212
+ */
213
+ onVideoUploadBefore: null,
214
+
215
+ /**
216
+ * @description Called when the video(iframe, video) upload failed
217
+ */
218
+ onVideoUploadError: null,
219
+
220
+ /**
221
+ * @description Called when the editor loaded, file Current editor value
222
+ * -- arguments is same "Image info object" --
223
+ */
224
+ onVideoLoad: null,
225
+
226
+ /**
227
+ * @description Called when the video(iframe, video) is is uploaded, updated, deleted
228
+ * -- arguments is same "onImageUpload" --
229
+ */
230
+ onVideoAction: null,
231
+
232
+ /**
233
+ * @description Called before the video is deleted
234
+ */
235
+ onVideoDeleteBefore: null,
236
+
237
+ /**
238
+ * @description It replaces the default callback function of the audio upload
239
+ * @param xmlHttp xmlHttpRequest object
240
+ * @param info Input information
241
+ * - isUpdate: Update audio if true, create audio if false
242
+ * - element: If isUpdate is true, the currently selected audio.
243
+ * @param core Core object
244
+ */
245
+ audioUploadHandler: null,
246
+
247
+ /**
248
+ * @description Called before the audio is uploaded
249
+ * If true is returned, the internal upload process runs normally.
250
+ * If false is returned, no audio upload is performed.
251
+ * If new fileList are returned, replaced the previous fileList
252
+ * If undefined is returned, it waits until "uploadHandler" is executed.
253
+ * @param {Array} files Files array
254
+ * @param {Object} info info: {
255
+ * - isUpdate: Update audio if true, create audio if false
256
+ * - element: If isUpdate is true, the currently selected audio.
257
+ * }
258
+ * @param {Object} core Core object
259
+ * @param {Function} uploadHandler If undefined is returned, it waits until "uploadHandler" is executed.
260
+ * "uploadHandler" is an upload function with "core" and "info" bound.
261
+ * [upload files] : uploadHandler(files or [new File(...),])
262
+ * [error] : uploadHandler("Error message")
263
+ * [Just finish] : uploadHandler()
264
+ * [directly register] : uploadHandler(response) // Same format as "audioUploadUrl" response
265
+ * ex) {
266
+ * // "errorMessage": "insert error message",
267
+ * "result": [ { "url": "...", "name": "...", "size": "999" }, ]
268
+ * }
269
+ * @returns {Boolean|Array|undefined}
270
+ */
271
+ onAudioUploadBefore: null,
272
+
273
+ /**
274
+ * @description Called when the audio upload failed
275
+ */
276
+ onAudioUploadError: null,
277
+
278
+ /**
279
+ * @description Called when the audio is is uploaded, updated, deleted
280
+ * -- arguments is same "onImageUpload" --
281
+ */
282
+ onAudioAction: null,
283
+
284
+ /**
285
+ * @description Called before the audio is deleted
286
+ */
287
+ onAudioDeleteBefore: null,
288
+
289
+ /**
290
+ * @description Called when the editor loaded, file Current editor value
291
+ * -- arguments is same "Image info object" --
292
+ */
293
+ onAudioLoad: null,
294
+
295
+ /**
296
+ * @description Called when the file is is uploaded, updated, deleted
297
+ * -- arguments is same "onImageUpload" --
298
+ */
299
+ onFileAction: null,
300
+
301
+ /**
302
+ * @description Called before the file is deleted
303
+ */
304
+ onFileDeleteBefore: null,
305
+
306
+ /**
307
+ * @description Called when the editor loaded, file Current editor value
308
+ * -- arguments is same "Image info object" --
309
+ */
310
+ onFileLoad: null,
311
+
312
+ onFileUploadBefore: null,
313
+
314
+ onFileUploadError: null,
315
+
316
+ onExportPdfBefore: null,
317
+
318
+ onFileManagerAction: null
319
+ };
320
+ }
@@ -0,0 +1,301 @@
1
+ /**
2
+ * @fileoverview history stack closure
3
+ */
4
+
5
+ import { _w } from '../../helper/env';
6
+ import { getNodeFromPath, getNodePath } from '../../helper/domUtils';
7
+ import { numbers } from '../../helper';
8
+
9
+ export default function (editor) {
10
+ const frameRoots = editor.frameRoots;
11
+ let delayTime = editor.options.get('historyStackDelayTime');
12
+ let pushDelay = null;
13
+ let stackIndex, stack, rootStack, rootInitContents;
14
+
15
+ function change(fc, index) {
16
+ if (editor.status.hasFocus) editor.eventManager.applyTagEffect();
17
+ editor.history.resetButtons(fc.get('key'), index);
18
+
19
+ // user event
20
+ editor.triggerEvent('onChange', { frameContext: fc, data: fc.get('wysiwyg').innerHTML });
21
+ if (editor.context.get('toolbar.main').style.display === 'block') editor.toolbar._showBalloon();
22
+ else if (editor.isSubBalloon && editor.context.get('toolbar.sub.main').style.display === 'block') editor.subToolbar._showBalloon();
23
+ }
24
+
25
+ function setContentFromStack(increase) {
26
+ const prevKey = stack[stackIndex];
27
+ const prevRoot = rootStack[prevKey];
28
+
29
+ stackIndex += increase;
30
+ const rootKey = increase < 0 && prevKey !== stack[stackIndex] && prevRoot.index > 0 ? prevKey : stack[stackIndex];
31
+ const root = rootStack[rootKey];
32
+ root.index += increase;
33
+
34
+ const item = root.value[root.index];
35
+ frameRoots.get(rootKey).get('wysiwyg').innerHTML = item.content;
36
+
37
+ if (prevKey !== rootKey && increase < 0 && stackIndex === 1) {
38
+ stackIndex = 0;
39
+ } else if (prevKey !== rootKey && increase > 0 && root.index === 1) {
40
+ stackIndex++;
41
+ } else if ((increase < 0 && root.index < 1) || (increase > 0 && root.index > root.value.length)) {
42
+ stackIndex += increase;
43
+ }
44
+
45
+ let focusKey = rootKey;
46
+ let focusItem = item;
47
+ if (increase < 0 && stackIndex > 0 && root.index === 0) {
48
+ const nextKey = stack[stackIndex + increase];
49
+ if (nextKey !== rootKey) {
50
+ const nextRoot = rootStack[nextKey];
51
+ focusKey = nextKey;
52
+ focusItem = nextRoot.value[nextRoot.index];
53
+ }
54
+ }
55
+
56
+ editor.changeFrameContext(focusKey);
57
+ editor.selection.setRange(getNodeFromPath(focusItem.s.path, focusItem.frame), focusItem.s.offset, getNodeFromPath(focusItem.e.path, focusItem.frame), focusItem.e.offset);
58
+ editor.focus();
59
+
60
+ if (stackIndex < 0) stackIndex = 0;
61
+ else if (stackIndex >= stack.length) stackIndex = stack.length - 1;
62
+
63
+ editor._offCurrentController();
64
+ editor._checkComponents();
65
+ editor.char.display();
66
+ editor._resourcesStateChange(editor.frameContext);
67
+
68
+ // onChange
69
+ change(editor.frameContext, root.index);
70
+ }
71
+
72
+ function setStack(content, range, rootKey, increase) {
73
+ let s, e;
74
+ if (!range) {
75
+ s = { path: [0, 0], offset: [0, 0] };
76
+ e = { path: 0, offset: 0 };
77
+ } else {
78
+ s = {
79
+ path: getNodePath(range.startContainer, null, null),
80
+ offset: range.startOffset
81
+ };
82
+ e = {
83
+ path: getNodePath(range.endContainer, null, null),
84
+ offset: range.endOffset
85
+ };
86
+ }
87
+
88
+ // set root stack
89
+ stackIndex += increase;
90
+ stack[stackIndex] = rootKey;
91
+ const root = rootStack[rootKey];
92
+ root.index += increase;
93
+ root.value[root.index] = {
94
+ content: content,
95
+ s: s,
96
+ e: e,
97
+ frame: frameRoots.get(rootKey).get('wysiwyg')
98
+ };
99
+ }
100
+
101
+ function resetRoot(rootKey) {
102
+ stackIndex++;
103
+ stack[stackIndex] = rootKey;
104
+ const root = rootStack[rootKey];
105
+ root.index = 0;
106
+ root.value[0] = {
107
+ content: rootInitContents[rootKey],
108
+ s: { path: [0, 0], offset: [0, 0] },
109
+ e: { path: 0, offset: 0 },
110
+ frame: frameRoots.get(rootKey).get('wysiwyg')
111
+ };
112
+ }
113
+
114
+ function initRoot(rootKey) {
115
+ rootStack[rootKey] = { value: [], index: -1 };
116
+ rootInitContents[rootKey] = frameRoots.get(rootKey).get('wysiwyg').innerHTML;
117
+ }
118
+
119
+ function refreshRoots(root) {
120
+ const deleteRoot = [];
121
+ for (let i = stackIndex + 1, len = stack.length; i < len; i++) {
122
+ if (deleteRoot.includes(stack[i])) continue;
123
+ deleteRoot.push(stack[i]);
124
+ }
125
+
126
+ stack = stack.slice(0, stackIndex + 1);
127
+ root.value.splice(stackIndex + 1);
128
+ editor.applyCommandTargets('redo', (e) => {
129
+ e.setAttribute('disabled', true);
130
+ });
131
+
132
+ for (let i = 0, len = deleteRoot.length; i < len; i++) {
133
+ if (!stack.includes(deleteRoot[i])) initRoot(deleteRoot[i]);
134
+ }
135
+ }
136
+
137
+ function pushStack(rootKey, range) {
138
+ editor._checkComponents();
139
+
140
+ const fc = frameRoots.get(rootKey);
141
+ const current = fc.get('wysiwyg').innerHTML;
142
+ const root = rootStack[rootKey];
143
+ if (!current || (root.value[root.index] && current === root.value[root.index].content)) return;
144
+ if (stack.length > stackIndex + 1) refreshRoots(root);
145
+ if (root.value.length === 0) resetRoot(rootKey);
146
+
147
+ setStack(current, range, rootKey, 1);
148
+
149
+ if (stackIndex === 1) {
150
+ editor.applyCommandTargets('undo', (e) => {
151
+ e.removeAttribute('disabled');
152
+ });
153
+ }
154
+
155
+ editor.char.display();
156
+ change(fc, root.index);
157
+ }
158
+
159
+ return {
160
+ /**
161
+ * @description Saving the current status to the history object stack
162
+ * If "delay" is true, it will be saved after (options.get('historyStackDelayTime') || 400) miliseconds
163
+ * If the function is called again with the "delay" argument true before it is saved, the delay time is renewal
164
+ * You can specify the delay time by sending a number.
165
+ * @param {Boolean|Number} delay If true, Add stack without delay time.
166
+ */
167
+ push(delay, rootKey) {
168
+ rootKey = rootKey || editor.status.rootKey;
169
+ const range = editor.status._range;
170
+
171
+ _w.setTimeout(editor._resourcesStateChange.bind(editor, frameRoots.get(rootKey)), 0);
172
+ const time = typeof delay === 'number' ? (delay > 0 ? delay : 0) : !delay ? 0 : delayTime;
173
+
174
+ if (!time || pushDelay) {
175
+ _w.clearTimeout(pushDelay);
176
+ if (!time) {
177
+ pushStack(rootKey, range);
178
+ return;
179
+ }
180
+ }
181
+
182
+ pushDelay = _w.setTimeout(() => {
183
+ _w.clearTimeout(pushDelay);
184
+ pushDelay = null;
185
+ pushStack(rootKey, range);
186
+ }, time);
187
+ },
188
+
189
+ check(rootKey, range) {
190
+ if (pushDelay) {
191
+ _w.clearTimeout(pushDelay);
192
+ pushDelay = null;
193
+ pushStack(rootKey, range);
194
+ }
195
+ },
196
+
197
+ /**
198
+ * @description Undo function
199
+ */
200
+ undo() {
201
+ if (stackIndex > 0) {
202
+ setContentFromStack(-1);
203
+ }
204
+ },
205
+
206
+ /**
207
+ * @description Redo function
208
+ */
209
+ redo() {
210
+ if (stack.length - 1 > stackIndex) {
211
+ setContentFromStack(1);
212
+ }
213
+ },
214
+
215
+ overwrite(rootKey) {
216
+ setStack(frameRoots.get(rootKey || editor.status.rootKey).get('wysiwyg').innerHTML, null, editor.status.rootKey, 0);
217
+ },
218
+
219
+ /**
220
+ * @description Reset the history object
221
+ */
222
+ reset() {
223
+ editor.applyCommandTargets('undo', (e) => {
224
+ e.setAttribute('disabled', true);
225
+ });
226
+ editor.applyCommandTargets('redo', (e) => {
227
+ e.setAttribute('disabled', true);
228
+ });
229
+
230
+ editor.applyCommandTargets('save', (e) => {
231
+ e.setAttribute('disabled', true);
232
+ });
233
+
234
+ editor.applyFrameRoots((e) => e.set('historyIndex', -1));
235
+ editor.applyFrameRoots((e) => e.set('isChanged', false));
236
+
237
+ stackIndex = -1;
238
+ stack = [];
239
+ rootStack = {};
240
+ rootInitContents = {};
241
+
242
+ const rootKeys = editor.rootKeys;
243
+ for (let i = 0, len = rootKeys.length; i < len; i++) {
244
+ initRoot(rootKeys[i]);
245
+ }
246
+ },
247
+
248
+ /**
249
+ * @description Reset the disabled state of the buttons to fit the current stack.
250
+ */
251
+ resetButtons(rootKey, index) {
252
+ const isReset = !numbers.is(index);
253
+ const root = rootStack[rootKey === undefined ? stack[stackIndex] : rootKey];
254
+ index = !isReset ? index : root.index;
255
+ const target = editor.frameRoots.get(rootKey);
256
+ const rootLen = root.value.length - 1;
257
+
258
+ editor.applyCommandTargets('undo', (e) => {
259
+ if (index > 0 && index <= rootLen) e.removeAttribute('disabled');
260
+ else e.setAttribute('disabled', true);
261
+ });
262
+ editor.applyCommandTargets('redo', (e) => {
263
+ if (index > -1 && index < rootLen) e.removeAttribute('disabled');
264
+ else e.setAttribute('disabled', true);
265
+ });
266
+
267
+ const savedIndex = target.get('savedIndex');
268
+ const historyIndex = target.get('historyIndex');
269
+ const isChanged = savedIndex > -1 ? savedIndex !== index : isReset ? root.length > 0 : index > 0 && historyIndex !== index;
270
+
271
+ target.set('historyIndex', index);
272
+ target.set('isChanged', isChanged);
273
+ editor.applyCommandTargets('save', (e) => {
274
+ if (isChanged) e.removeAttribute('disabled');
275
+ else e.setAttribute('disabled', true);
276
+ });
277
+
278
+ editor.triggerEvent('onResetButtons', { rootKey });
279
+ },
280
+
281
+ getRootStack() {
282
+ return rootStack;
283
+ },
284
+
285
+ /**
286
+ * @description Reset the delay time.
287
+ * @param {number} time millisecond
288
+ */
289
+ resetDelayTime(time) {
290
+ delayTime = time;
291
+ },
292
+
293
+ /**
294
+ * @description Remove all stacks and remove the timeout function.
295
+ */
296
+ destroy() {
297
+ if (pushDelay) _w.clearTimeout(pushDelay);
298
+ stackIndex = stack = rootStack = rootInitContents = null;
299
+ }
300
+ };
301
+ }