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
@@ -1,271 +0,0 @@
1
- import CoreInjector from '../editorInjector/_core';
2
- import { domUtils } from '../helper';
3
- import ApiManager from './ApiManager';
4
-
5
- /**
6
- * @param {*} inst
7
- * @param {Object} params
8
- * @param {string} params.title - File browser window title. Required. Can be overridden in fileBrowser.
9
- * @param {string} params.url - File server url. Required. Can be overridden in fileBrowser.
10
- * @param {Object} params.headers - File server http header. Required. Can be overridden in fileBrowser.
11
- * @param {string} params.listClass - Class name of list div. Required. Can be overridden in fileBrowser.
12
- * @param {function} params.drawItemHandler - Function that defines the HTML of a file item. Required. Can be overridden in fileBrowser.
13
- * @param {function} params.selectorHandler - Function that actions when an item is clicked. Required. Can be overridden in fileBrowser.
14
- * @param {number} params.columnSize - Number of "div.se-file-item-column" to be created. Optional. Can be overridden in fileBrowser. Default: 4.
15
- */
16
- const FileBrowser = function (inst, params) {
17
- CoreInjector.call(this, inst.editor);
18
-
19
- // create HTML
20
- const browserFrame = domUtils.createElement('DIV', { class: 'se-file-browser sun-editor-common' });
21
- const content = domUtils.createElement('DIV', { class: 'se-file-browser-inner' }, CreateHTML(inst.editor));
22
-
23
- // members
24
- this.kind = inst.constructor.key || inst.constructor.name;
25
- this.inst = inst;
26
- this.area = browserFrame;
27
- this.header = content.querySelector('.se-file-browser-header');
28
- this.titleArea = content.querySelector('.se-file-browser-title');
29
- this.tagArea = content.querySelector('.se-file-browser-tags');
30
- this.body = content.querySelector('.se-file-browser-body');
31
- this.list = content.querySelector('.se-file-browser-list');
32
- this._loading = content.querySelector('.se-loading-box');
33
-
34
- this.title = params.title;
35
- this.listClass = params.listClass;
36
- this.url = params.url;
37
- this.urlHeader = params.headers;
38
- this.drawItemHandler = params.drawItemHandler;
39
- this.selectorHandler = params.selectorHandler;
40
- this.columnSize = params.columnSize || 4;
41
-
42
- this.items = [];
43
- this.selectedTags = [];
44
- this._closeSignal = false;
45
- this._bindClose = null;
46
- this.__globalEventHandler = (e) => {
47
- if (!/27/.test(e.keyCode)) return;
48
- this.close();
49
- };
50
- // api manager
51
- this.apiManager = new ApiManager(this, { method: 'GET' });
52
-
53
- // init
54
- browserFrame.appendChild(domUtils.createElement('DIV', { class: 'se-file-browser-back' }));
55
- browserFrame.appendChild(content);
56
- this.carrierWrapper.appendChild(browserFrame);
57
-
58
- this.eventManager.addEvent(this.tagArea, 'click', OnClickTag.bind(this));
59
- this.eventManager.addEvent(this.list, 'click', OnClickFile.bind(this));
60
- this.eventManager.addEvent(content, 'mousedown', OnMouseDown_browser.bind(this));
61
- this.eventManager.addEvent(content, 'click', OnClick_browser.bind(this));
62
- };
63
-
64
- FileBrowser.prototype = {
65
- /**
66
- * @description Open a file browser plugin
67
- * @param {Object|null} params {
68
- * selectorHandler: When the function comes as an argument value, it substitutes "context.selectorHandler".
69
- * }
70
- */
71
- open(params) {
72
- if (!params) params = {};
73
- this.__addGlobalEvent();
74
-
75
- const listClassName = params.listClass || this.listClass;
76
- if (!domUtils.hasClass(this.list, listClassName)) {
77
- this.list.className = 'se-file-browser-list ' + listClassName;
78
- }
79
- this.titleArea.textContent = params.title || this.title;
80
- this.area.style.display = 'block';
81
-
82
- this._drawFileList(params.url || this.url, params.urlHeader || this.urlHeader);
83
- },
84
-
85
- /**
86
- * @description Close a fileBrowser plugin
87
- * The plugin's "init" method is called.
88
- */
89
- close() {
90
- this.__removeGlobalEvent();
91
- this.apiManager.cancel();
92
-
93
- this.area.style.display = 'none';
94
- this.selectedTags = [];
95
- this.items = [];
96
- this.list.innerHTML = this.tagArea.innerHTML = this.titleArea.textContent = '';
97
-
98
- if (typeof this.inst.init === 'function') this.inst.init();
99
- },
100
-
101
- /**
102
- * @description Show file browser loading box
103
- */
104
- showBrowserLoading() {
105
- this._loading.style.display = 'block';
106
- },
107
-
108
- /**
109
- * @description Close file browser loading box
110
- */
111
- closeBrowserLoading() {
112
- this._loading.style.display = 'none';
113
- },
114
-
115
- _drawFileList(url, urlHeader) {
116
- this.apiManager.call({ method: 'GET', url, headers: urlHeader, callBack: CallBackGet.bind(this), errorCallBack: CallBackError.bind(this) });
117
- this.showBrowserLoading();
118
- },
119
-
120
- _drawListItem(items, update) {
121
- const _tags = [];
122
- const len = items.length;
123
- const columnSize = this.columnSize;
124
- const splitSize = columnSize <= 1 ? 1 : Math.round(len / columnSize) || 1;
125
- const drawItemHandler = this.drawItemHandler;
126
-
127
- let tagsHTML = '';
128
- let listHTML = '<div class="se-file-item-column">';
129
- let columns = 1;
130
- for (let i = 0, item, tags; i < len; i++) {
131
- item = items[i];
132
- tags = !item.tag ? [] : typeof item.tag === 'string' ? item.tag.split(',') : item.tag;
133
- tags = item.tag = tags.map(function (v) {
134
- return v.trim();
135
- });
136
- listHTML += drawItemHandler(item);
137
-
138
- if ((i + 1) % splitSize === 0 && columns < columnSize && i + 1 < len) {
139
- columns++;
140
- listHTML += '</div><div class="se-file-item-column">';
141
- }
142
-
143
- if (update && tags.length > 0) {
144
- for (let t = 0, tLen = tags.length, tag; t < tLen; t++) {
145
- tag = tags[t];
146
- if (tag && !_tags.includes(tag)) {
147
- _tags.push(tag);
148
- tagsHTML += `<a title="${tag}" aria-label="${tag}">${tag}</a>`;
149
- }
150
- }
151
- }
152
- }
153
- listHTML += '</div>';
154
-
155
- this.list.innerHTML = listHTML;
156
-
157
- if (update) {
158
- this.items = items;
159
- this.tagArea.innerHTML = tagsHTML;
160
- }
161
- },
162
-
163
- __addGlobalEvent() {
164
- this.__removeGlobalEvent();
165
- this._bindClose = this.eventManager.addGlobalEvent('keydown', this.__globalEventHandler, true);
166
- },
167
-
168
- __removeGlobalEvent() {
169
- if (this._bindClose) this._bindClose = this.eventManager.removeGlobalEvent(this._bindClose);
170
- },
171
-
172
- constructor: FileBrowser
173
- };
174
-
175
- function CallBackGet(xmlHttp) {
176
- try {
177
- const res = JSON.parse(xmlHttp.responseText);
178
- if (res.result.length > 0) {
179
- this._drawListItem(res.result, true);
180
- } else if (res.nullMessage) {
181
- this.list.innerHTML = res.nullMessage;
182
- }
183
- } catch (e) {
184
- throw Error(`[SUNEDITOR.fileBrowser.drawList.fail] cause: "${e.message}"`);
185
- } finally {
186
- this.closeBrowserLoading();
187
- this.body.style.maxHeight = domUtils.getClientSize().h - this.header.offsetHeight - 50 + 'px';
188
- }
189
- }
190
-
191
- function CallBackError(res, xmlHttp) {
192
- this.closeBrowserLoading();
193
- throw Error(`[SUNEDITOR.fileBrowser.get.serverException] status: ${xmlHttp.status}, response: ${res.errorMessage || xmlHttp.responseText}`);
194
- }
195
-
196
- function OnClickTag(e) {
197
- const target = e.target;
198
- if (!domUtils.isAnchor(target)) return;
199
-
200
- const tagName = target.textContent;
201
- const selectTag = this.tagArea.querySelector('a[title="' + tagName + '"]');
202
- const selectedTags = this.selectedTags;
203
- const sTagIndex = selectedTags.indexOf(tagName);
204
-
205
- if (sTagIndex > -1) {
206
- selectedTags.splice(sTagIndex, 1);
207
- domUtils.removeClass(selectTag, 'on');
208
- } else {
209
- selectedTags.push(tagName);
210
- domUtils.addClass(selectTag, 'on');
211
- }
212
-
213
- this._drawListItem(
214
- selectedTags.length === 0
215
- ? this.items
216
- : this.items.filter(function (item) {
217
- return item.tag.some(function (tag) {
218
- return selectedTags.includes(tag);
219
- });
220
- }),
221
- false
222
- );
223
- }
224
-
225
- function OnClickFile(e) {
226
- e.preventDefault();
227
- e.stopPropagation();
228
-
229
- if (e.target === this.list) return;
230
-
231
- const target = domUtils.getCommandTarget(e.target);
232
- if (!target) return;
233
-
234
- this.close();
235
- this.selectorHandler(target);
236
- }
237
-
238
- function OnMouseDown_browser(e) {
239
- if (/se-file-browser-inner/.test(e.target.className)) {
240
- this._closeSignal = true;
241
- } else {
242
- this._closeSignal = false;
243
- }
244
- }
245
-
246
- function OnClick_browser(e) {
247
- e.stopPropagation();
248
-
249
- if (/close/.test(e.target.getAttribute('data-command')) || this._closeSignal) {
250
- this.close();
251
- }
252
- }
253
-
254
- function CreateHTML({ lang, icons }) {
255
- return /*html*/ `
256
- <div class="se-file-browser-content">
257
- <div class="se-file-browser-header">
258
- <button type="button" data-command="close" class="se-btn se-file-browser-close" class="close" title="${lang.close}" aria-label="${lang.close}">
259
- ${icons.cancel}
260
- </button>
261
- <span class="se-file-browser-title"></span>
262
- <div class="se-file-browser-tags"></div>
263
- </div>
264
- <div class="se-file-browser-body">
265
- <div class="se-loading-box sun-editor-common"><div class="se-loading-effect"></div></div>
266
- <div class="se-file-browser-list"></div>
267
- </div>
268
- </div>`;
269
- }
270
-
271
- export default FileBrowser;
@@ -1,168 +0,0 @@
1
- import EditorInjector from '../../editorInjector';
2
- import { domUtils, env } from '../../helper';
3
- import { ApiManager } from '../../modules';
4
-
5
- const { _d } = env;
6
-
7
- const ExportPdf = function (editor, pluginOptions) {
8
- EditorInjector.call(this, editor);
9
- // plugin basic properties
10
- this.title = this.lang.exportPdf;
11
- this.icon = 'pdf';
12
-
13
- // plugin options
14
- this.apiUrl = pluginOptions.apiUrl;
15
- this.fileName = pluginOptions.fileName || 'suneditor-pdf';
16
- this.jsPDFOptions = pluginOptions.jsPDFOptions || {};
17
- this.html2canvasOptions = pluginOptions.html2canvasOptions || {};
18
-
19
- // option check
20
- if (!this.apiUrl && !this.options.get('externalLibs').html2canvas && !this.options.get('externalLibs').jsPDF) {
21
- console.warn('[SUNEDITOR.plugins.exportPdf.error] Requires "apiUrl" or externalLibs.html2canvas and externalLibs.jsPDF options.');
22
- } else if (this.apiUrl) {
23
- this.apiManager = new ApiManager(this, {
24
- method: 'POST',
25
- url: this.apiUrl,
26
- headers: {
27
- 'Content-Type': 'application/json'
28
- },
29
- responseType: 'blob'
30
- });
31
- }
32
- };
33
-
34
- ExportPdf.key = 'exportPdf';
35
- ExportPdf.type = 'command';
36
- ExportPdf.className = 'se-component-enabled';
37
- ExportPdf.prototype = {
38
- /**
39
- * @override core
40
- * @param {Element} target Target command button
41
- */
42
- async action() {
43
- this.editor.showLoading();
44
- let ww = null;
45
-
46
- try {
47
- const topArea = this.editor.frameContext.get('topArea');
48
- const editableDiv = domUtils.createElement('div', { class: this.editor.frameContext.get('wysiwygFrame').className }, this.html.get());
49
- ww = domUtils.createElement('div', { style: `position: absolute; left: -10000px; width: ${topArea.clientWidth}px; height: auto;` }, editableDiv);
50
-
51
- if (this.apiUrl) {
52
- const inlineWW = domUtils.applyInlineStylesAll(editableDiv, true, this.options.get('allUsedStyles'));
53
- ww.innerHTML = inlineWW.outerHTML;
54
- }
55
-
56
- _d.body.appendChild(ww);
57
-
58
- // before event
59
- if ((await this.triggerEvent('onExportPdfBefore', { editableDiv })) === false) return;
60
-
61
- // at server
62
- if (this.apiUrl) {
63
- await this._createByServer(ww);
64
- return;
65
- }
66
-
67
- // at client
68
- const checkAndProcessResources = async () => {
69
- const resources = ww.querySelectorAll('img, audio, video');
70
- const resourcesLoaded = Array.from(resources).map((resource) => {
71
- switch (resource.tagName.toLowerCase()) {
72
- case 'img':
73
- return new Promise((resolve) => {
74
- if (resource.complete && resource.naturalHeight !== 0) {
75
- resolve();
76
- } else {
77
- resource.onload = resolve;
78
- resource.onerror = () => resolve();
79
- }
80
- });
81
- case 'audio':
82
- case 'video':
83
- return new Promise((resolve) => {
84
- if (resource.readyState >= 4) {
85
- // HAVE_ENOUGH_DATA
86
- resolve();
87
- } else {
88
- resource.onloadeddata = resolve;
89
- resource.onerror = () => resolve();
90
- }
91
- });
92
- default:
93
- return Promise.resolve();
94
- }
95
- });
96
-
97
- await Promise.all(resourcesLoaded);
98
- await this._createByHtml2canvas(ww);
99
- };
100
-
101
- // run observer
102
- const observer = new MutationObserver(checkAndProcessResources);
103
- observer.observe(ww, { childList: true, subtree: true, attributes: true });
104
-
105
- await checkAndProcessResources();
106
- } catch (error) {
107
- console.error(`[SUNEDITOR.plugins.exportPdf.error] ${error.message}`);
108
- } finally {
109
- // domUtils.removeItem(ww);
110
- this.editor.hideLoading();
111
- }
112
- },
113
-
114
- async _createByHtml2canvas(ww) {
115
- const canvas = await this.options.get('externalLibs').html2canvas(ww, {
116
- useCORS: true,
117
- logging: true,
118
- ...this.html2canvasOptions
119
- });
120
- const imageData = canvas.toDataURL('image/png');
121
-
122
- const pdf = new (this.options.get('externalLibs').jsPDF)({
123
- orientation: 'portrait',
124
- unit: 'px',
125
- format: [canvas.width, canvas.height],
126
- ...this.jsPDFOptions
127
- });
128
-
129
- pdf.addImage(imageData, 'PNG', 0, 0, canvas.width, canvas.height);
130
-
131
- // save PDF file
132
- pdf.save(`${this.fileName}.pdf`);
133
- },
134
-
135
- async _createByServer(ww) {
136
- const data = {
137
- fileName: this.fileName,
138
- htmlContent: ww.innerHTML
139
- };
140
-
141
- const xhr = await this.apiManager.asyncCall({ data: JSON.stringify(data) });
142
-
143
- if (xhr.status !== 200) {
144
- const res = !xhr.responseText ? xhr : JSON.parse(xhr.responseText);
145
- throw Error(`[SUNEDITOR.plugins.exportPdf.error] ${res.errorMessage}`);
146
- }
147
-
148
- const blob = new Blob([xhr.response], { type: 'application/pdf' });
149
- const contentDisposition = xhr.getResponseHeader('Content-Disposition');
150
- const downloadUrl = URL.createObjectURL(blob);
151
- const filename = (contentDisposition.match(/filename="([^"]+)/) || [])[1] || this.fileName + '.pdf';
152
- const a = domUtils.createElement('A', { href: downloadUrl, download: filename, style: 'display: none;' }, null);
153
-
154
- try {
155
- _d.body.appendChild(a);
156
- a.click();
157
- } finally {
158
- setTimeout(() => {
159
- domUtils.removeItem(a);
160
- URL.revokeObjectURL(downloadUrl);
161
- }, 100);
162
- }
163
- },
164
-
165
- constructor: ExportPdf
166
- };
167
-
168
- export default ExportPdf;
@@ -1,81 +0,0 @@
1
- import EditorInjector from '../../editorInjector';
2
- import { FileBrowser } from '../../modules';
3
-
4
- const ImageGallery = function (editor, pluginOptions) {
5
- // plugin bisic properties
6
- EditorInjector.call(this, editor);
7
- this.title = this.lang.imageGallery;
8
- this.icon = 'image_gallery';
9
-
10
- // modules
11
- this.fileBrowser = new FileBrowser(this, {
12
- title: this.lang.imageGallery,
13
- url: pluginOptions.url,
14
- headers: pluginOptions.headers,
15
- listClass: 'se-image-list',
16
- drawItemHandler: DrawItems,
17
- selectorHandler: SetImage.bind(this),
18
- columnSize: 4
19
- });
20
-
21
- // members
22
- this.width = this.plugins.image.pluginOptions.defaultWidth === 'auto' ? '' : this.plugins.image.pluginOptions.defaultWidth;
23
- this.height = this.plugins.image.pluginOptions.defaultHeight === 'auto' ? '' : this.plugins.image.pluginOptions.defaultHeight;
24
- };
25
-
26
- ImageGallery.key = 'imageGallery';
27
- ImageGallery.type = 'fileBrowser';
28
- ImageGallery.className = '';
29
- ImageGallery.prototype = {
30
- /**
31
- * @description Open image gallery
32
- */
33
- open(inputTarget) {
34
- this.inputTarget = inputTarget;
35
- this.fileBrowser.open();
36
- },
37
-
38
- /**
39
- * @description Close image gallery
40
- */
41
- close() {
42
- this.inputTarget = null;
43
- this.fileBrowser.close();
44
- },
45
-
46
- constructor: ImageGallery
47
- };
48
-
49
- /**
50
- * @Required @override fileBrowser
51
- * @description Define the HTML of the item to be put in "div.se-file-item-column".
52
- * Format: [
53
- * { src: "image src", name: "name(@option)", alt: "image alt(@option)", tag: "tag name(@option)" }
54
- * ]
55
- * @param {Object} item Item of the response data's array
56
- */
57
- function DrawItems(item) {
58
- const srcName = item.src.split('/').pop();
59
- return /*html*/ `
60
- <div class="se-file-item-img">
61
- <img
62
- src="${item.thumbnail || item.src}"
63
- alt="${item.alt || srcName}"
64
- data-command="${item.src || item.thumbnail}"
65
- data-value="${item.name || srcName}">
66
- <div class="se-file-name-image se-file-name-back"></div>
67
- <div class="se-file-name-image">${item.name || srcName}</div>
68
- </div>`;
69
- }
70
-
71
- function SetImage(target) {
72
- if (this.inputTarget) {
73
- this.inputTarget(target);
74
- } else {
75
- const file = { name: target.getAttribute('data-value'), size: 0 };
76
- this.plugins.image.init();
77
- this.plugins.image.create(target.getAttribute('data-command'), null, this.width, this.height, 'none', file, target.alt);
78
- }
79
- }
80
-
81
- export default ImageGallery;
@@ -1,61 +0,0 @@
1
- .sun-editor button > svg,
2
- .sun-editor .se-svg {
3
- width: 14px;
4
- height: 14px;
5
- }
6
-
7
- /** se-btn button */
8
- .sun-editor .se-btn {
9
- width: 32px;
10
- font-size: 12px;
11
- line-height: 1.8;
12
- }
13
-
14
- .sun-editor .close > svg,
15
- .sun-editor .se-modal .se-close-btn > svg {
16
- width: 10px;
17
- height: 10px;
18
- }
19
-
20
- /* se-select-btn icon */
21
- .sun-editor .se-btn-select > svg {
22
- width: 8px;
23
- height: 8px;
24
- }
25
-
26
- /* se-btn-list inner icon */
27
- .sun-editor .se-btn-list > .se-list-icon {
28
- width: 12px;
29
- height: 14px;
30
- }
31
-
32
- /* modal */
33
- .sun-editor .se-modal .se-modal-inner .se-modal-form input,
34
- .sun-editor .se-modal .se-modal-inner .se-modal-form select {
35
- height: 32px;
36
- font-size: 13px;
37
- line-height: 1.7;
38
- }
39
-
40
- .sun-editor .se-modal .se-modal-inner .se-modal-content .se-btn-primary {
41
- padding: 5px 11px;
42
- }
43
-
44
- .sun-editor .se-modal .se-modal-inner .se-modal-footer > div {
45
- line-height: 1.7;
46
- }
47
-
48
- .sun-editor .se-line-breaker-component {
49
- width: 22px;
50
- height: 22px;
51
- }
52
-
53
- .sun-editor .se-modal label,
54
- .sun-editor .se-modal input,
55
- .sun-editor .se-modal button {
56
- font-size: 14px;
57
- }
58
-
59
- .sun-editor .se-modal .se-modal-inner .se-modal-header .se-modal-title {
60
- font-size: 15px;
61
- }
@@ -1,8 +0,0 @@
1
- import { Plugin } from './Plugin';
2
-
3
- export interface CommandPlugin extends Plugin {
4
- /**
5
- * @description The behavior of the "command plugin" must be defined in the "action" method.
6
- */
7
- action: () => void;
8
- }
@@ -1,20 +0,0 @@
1
- import { Plugin } from './Plugin';
2
-
3
- export interface DialogPlugin extends Plugin {
4
- /**
5
- * @description This method is called when the plugin button is clicked.
6
- * Open the modal window here.
7
- */
8
- open: () => void;
9
-
10
- /**
11
- * @description Called after the dropdown has been rendered
12
- */
13
- on?: () => void;
14
-
15
- /**
16
- * @description This method is called when the dialog window is closed.
17
- * Initialize the properties.
18
- */
19
- init: () => void;
20
- }
@@ -1,30 +0,0 @@
1
- import { Plugin } from './Plugin';
2
-
3
- export interface FileBrowserPlugin extends Plugin {
4
- /**
5
- * @description Open a file browser window
6
- * @param pluginName Plugin name using the file browser
7
- * @param selectorHandler When the function comes as an argument value, it substitutes "context.selectorHandler".
8
- * @example this.plugins.fileBrowser.open.call(this, 'imageGallery', (selectorHandler || null));
9
- */
10
- open(kind: string, update: boolean): void;
11
-
12
- /**
13
- * @description Define the HTML of the item to be put in "div.se-file-item-column".
14
- * @param item Item of the response data's array
15
- */
16
- drawItems: (item: object) => string;
17
-
18
- /**
19
- * @description Close a file browser window
20
- * The plugin's "init" method is called.
21
- * @example this.plugins.fileBrowser.close.call(this);
22
- */
23
- close(): void;
24
-
25
- /**
26
- * @description This method is called when the file browser window is closed.
27
- * Initialize the properties.
28
- */
29
- init?: () => void;
30
- }
@@ -1,15 +0,0 @@
1
- import SunEditor from '../lib/core';
2
-
3
- export interface Module {
4
- /**
5
- * @description Module name
6
- */
7
- name: string;
8
-
9
- /**
10
- * @description Constructor, It will run automatically.
11
- * @param core Core object
12
- * @example core.addModule([dialog, resizing, fileManager])
13
- */
14
- add?: (core: SunEditor) => void;
15
- }
@@ -1,42 +0,0 @@
1
- export interface Plugin {
2
- /**
3
- * @description Plugin name
4
- */
5
- name: string;
6
-
7
- /**
8
- * @description Plugin type ('container', 'command', 'dropdown', 'dialog')
9
- */
10
- display: string;
11
-
12
- /**
13
- * @description Constructor
14
- * @param core Core object
15
- * @param targetElement Target button Element
16
- */
17
- add: (core: any, targetElement?: any) => void;
18
-
19
- /**
20
- * @description Plugins with active methods load immediately when the editor loads.
21
- * Called each time the selection is moved.
22
- * @param element Selected elements
23
- */
24
- active?: (element: any) => boolean;
25
-
26
- /**
27
- * @description TML title attribute (tooltip) - default: plugin's name
28
- */
29
- title?: string;
30
-
31
- /**
32
- * @description HTML to be append to button (icon)
33
- * Recommend using the inline svg icon. - default: "<span class="se-icon-text">!</span>"
34
- */
35
- innerHTML?: string;
36
-
37
- /**
38
- * @description The class of the button. - default: "se-btn"
39
- * Do not recommend using it unless it is a special situation.
40
- */
41
- className?: string;
42
- }