suneditor 2.46.2 → 3.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.json +64 -0
  3. package/CONTRIBUTING.md +36 -0
  4. package/LICENSE.txt +1 -1
  5. package/README.md +11 -1560
  6. package/dist/suneditor.min.css +1 -0
  7. package/dist/suneditor.min.js +1 -2
  8. package/package.json +97 -70
  9. package/src/assets/icons/_default.js +194 -0
  10. package/src/assets/suneditor-contents.css +643 -0
  11. package/src/assets/suneditor.css +3394 -0
  12. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  13. package/src/core/base/eventHandlers/handler_ww_clipboard.js +37 -0
  14. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +74 -0
  15. package/src/core/base/eventHandlers/handler_ww_key_input.js +1002 -0
  16. package/src/core/base/eventHandlers/handler_ww_mouse.js +147 -0
  17. package/src/core/base/eventManager.js +1156 -0
  18. package/src/core/base/events.js +320 -0
  19. package/src/core/base/history.js +301 -0
  20. package/src/core/class/char.js +147 -0
  21. package/src/core/class/component.js +639 -0
  22. package/src/core/class/format.js +3258 -0
  23. package/src/core/class/html.js +1710 -0
  24. package/src/core/class/menu.js +260 -0
  25. package/src/core/class/nodeTransform.js +405 -0
  26. package/src/core/class/notice.js +42 -0
  27. package/src/core/class/offset.js +575 -0
  28. package/src/core/class/selection.js +511 -0
  29. package/src/core/class/shortcuts.js +38 -0
  30. package/src/core/class/toolbar.js +440 -0
  31. package/src/core/class/viewer.js +646 -0
  32. package/src/core/editor.js +1601 -0
  33. package/src/core/section/actives.js +145 -0
  34. package/src/core/section/constructor.js +1252 -0
  35. package/src/core/section/context.js +97 -0
  36. package/src/editorInjector/_classes.js +22 -0
  37. package/src/editorInjector/_core.js +28 -0
  38. package/src/editorInjector/index.js +13 -0
  39. package/src/helper/converter.js +388 -0
  40. package/src/helper/domUtils.js +1177 -0
  41. package/src/helper/env.js +250 -0
  42. package/src/helper/index.js +19 -0
  43. package/src/helper/numbers.js +68 -0
  44. package/src/helper/unicode.js +43 -0
  45. package/src/langs/ckb.js +161 -0
  46. package/src/langs/cs.js +161 -0
  47. package/src/langs/da.js +161 -0
  48. package/src/langs/de.js +162 -0
  49. package/src/langs/en.js +210 -0
  50. package/src/langs/es.js +162 -0
  51. package/src/langs/fa.js +159 -0
  52. package/src/langs/fr.js +161 -0
  53. package/src/langs/he.js +162 -0
  54. package/src/{lang → langs}/index.js +0 -2
  55. package/src/langs/it.js +162 -0
  56. package/src/langs/ja.js +162 -0
  57. package/src/langs/ko.js +210 -0
  58. package/src/langs/lv.js +162 -0
  59. package/src/langs/nl.js +162 -0
  60. package/src/langs/pl.js +162 -0
  61. package/src/langs/pt_br.js +162 -0
  62. package/src/langs/ro.js +162 -0
  63. package/src/langs/ru.js +162 -0
  64. package/src/langs/se.js +162 -0
  65. package/src/langs/tr.js +159 -0
  66. package/src/langs/ua.js +162 -0
  67. package/src/langs/ur.js +162 -0
  68. package/src/langs/zh_cn.js +162 -0
  69. package/src/modules/ApiManager.js +168 -0
  70. package/src/modules/ColorPicker.js +302 -0
  71. package/src/modules/Controller.js +323 -0
  72. package/src/modules/Figure.js +1176 -0
  73. package/src/modules/FileBrowser.js +271 -0
  74. package/src/modules/FileManager.js +307 -0
  75. package/src/modules/HueSlider.js +513 -0
  76. package/src/modules/Modal.js +177 -0
  77. package/src/modules/ModalAnchorEditor.js +494 -0
  78. package/src/modules/SelectMenu.js +447 -0
  79. package/src/modules/_DragHandle.js +16 -0
  80. package/src/modules/index.js +14 -0
  81. package/src/plugins/command/blockquote.js +47 -47
  82. package/src/plugins/command/exportPdf.js +168 -0
  83. package/src/plugins/command/fileUpload.js +389 -0
  84. package/src/plugins/command/list_bulleted.js +112 -0
  85. package/src/plugins/command/list_numbered.js +115 -0
  86. package/src/plugins/dropdown/align.js +143 -0
  87. package/src/plugins/dropdown/backgroundColor.js +90 -0
  88. package/src/plugins/dropdown/font.js +113 -0
  89. package/src/plugins/dropdown/fontColor.js +90 -0
  90. package/src/plugins/dropdown/formatBlock.js +141 -0
  91. package/src/plugins/dropdown/hr.js +111 -0
  92. package/src/plugins/dropdown/layout.js +72 -0
  93. package/src/plugins/dropdown/lineHeight.js +114 -0
  94. package/src/plugins/dropdown/list.js +107 -0
  95. package/src/plugins/dropdown/paragraphStyle.js +117 -0
  96. package/src/plugins/dropdown/table.js +2810 -0
  97. package/src/plugins/dropdown/template.js +71 -0
  98. package/src/plugins/dropdown/textStyle.js +137 -0
  99. package/src/plugins/field/mention.js +181 -0
  100. package/src/plugins/fileBrowser/imageGallery.js +76 -59
  101. package/src/plugins/index.js +86 -24
  102. package/src/plugins/input/fontSize.js +357 -0
  103. package/src/plugins/modal/audio.js +492 -0
  104. package/src/plugins/modal/image.js +1064 -0
  105. package/src/plugins/modal/link.js +211 -0
  106. package/src/plugins/modal/math.js +363 -0
  107. package/src/plugins/modal/video.js +870 -0
  108. package/src/suneditor.js +62 -67
  109. package/src/themes/test.css +61 -0
  110. package/typings/CommandPlugin.d.ts +8 -0
  111. package/typings/DialogPlugin.d.ts +20 -0
  112. package/typings/FileBrowserPlugin.d.ts +30 -0
  113. package/typings/Lang.d.ts +124 -0
  114. package/typings/Module.d.ts +15 -0
  115. package/typings/Plugin.d.ts +42 -0
  116. package/typings/SubmenuPlugin.d.ts +8 -0
  117. package/typings/_classes.d.ts +17 -0
  118. package/typings/_colorPicker.d.ts +60 -0
  119. package/typings/_core.d.ts +55 -0
  120. package/typings/align.d.ts +5 -0
  121. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  122. package/typings/backgroundColor.d.ts +5 -0
  123. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  124. package/typings/char.d.ts +39 -0
  125. package/typings/component.d.ts +38 -0
  126. package/typings/context.d.ts +39 -0
  127. package/typings/converter.d.ts +33 -0
  128. package/typings/dialog.d.ts +28 -0
  129. package/typings/domUtils.d.ts +361 -0
  130. package/typings/editor.d.ts +7 -0
  131. package/typings/editor.ts +542 -0
  132. package/typings/env.d.ts +70 -0
  133. package/typings/eventManager.d.ts +37 -0
  134. package/typings/events.d.ts +262 -0
  135. package/typings/fileBrowser.d.ts +42 -0
  136. package/typings/fileManager.d.ts +67 -0
  137. package/typings/font.d.ts +5 -0
  138. package/typings/fontColor.d.ts +5 -0
  139. package/typings/fontSize.d.ts +5 -0
  140. package/typings/format.d.ts +191 -0
  141. package/typings/formatBlock.d.ts +5 -0
  142. package/typings/history.d.ts +48 -0
  143. package/typings/horizontalRule.d.ts +5 -0
  144. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  145. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  146. package/typings/index.d.ts +21 -0
  147. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  148. package/typings/index.plugins.d.ts +58 -0
  149. package/typings/lineHeight.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  151. package/typings/list.d.ts +5 -0
  152. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  153. package/typings/mediaContainer.d.ts +25 -0
  154. package/typings/node.d.ts +57 -0
  155. package/typings/notice.d.ts +16 -0
  156. package/typings/numbers.d.ts +29 -0
  157. package/typings/offset.d.ts +24 -0
  158. package/typings/options.d.ts +589 -0
  159. package/typings/paragraphStyle.d.ts +5 -0
  160. package/typings/resizing.d.ts +141 -0
  161. package/typings/selection.d.ts +94 -0
  162. package/typings/shortcuts.d.ts +13 -0
  163. package/typings/suneditor.d.ts +9 -0
  164. package/typings/table.d.ts +5 -0
  165. package/typings/template.d.ts +5 -0
  166. package/typings/textStyle.d.ts +5 -0
  167. package/typings/toolbar.d.ts +32 -0
  168. package/typings/unicode.d.ts +25 -0
  169. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  170. package/dist/css/suneditor.min.css +0 -1
  171. package/src/assets/css/suneditor-contents.css +0 -562
  172. package/src/assets/css/suneditor.css +0 -566
  173. package/src/assets/defaultIcons.js +0 -103
  174. package/src/lang/Lang.d.ts +0 -144
  175. package/src/lang/ckb.d.ts +0 -5
  176. package/src/lang/ckb.js +0 -188
  177. package/src/lang/cs.d.ts +0 -5
  178. package/src/lang/cs.js +0 -188
  179. package/src/lang/da.d.ts +0 -5
  180. package/src/lang/da.js +0 -191
  181. package/src/lang/de.d.ts +0 -5
  182. package/src/lang/de.js +0 -188
  183. package/src/lang/en.d.ts +0 -5
  184. package/src/lang/en.js +0 -188
  185. package/src/lang/es.d.ts +0 -5
  186. package/src/lang/es.js +0 -188
  187. package/src/lang/fa.d.ts +0 -5
  188. package/src/lang/fa.js +0 -188
  189. package/src/lang/fr.d.ts +0 -5
  190. package/src/lang/fr.js +0 -188
  191. package/src/lang/he.d.ts +0 -5
  192. package/src/lang/he.js +0 -188
  193. package/src/lang/index.d.ts +0 -23
  194. package/src/lang/it.d.ts +0 -5
  195. package/src/lang/it.js +0 -188
  196. package/src/lang/ja.d.ts +0 -5
  197. package/src/lang/ja.js +0 -188
  198. package/src/lang/ko.d.ts +0 -5
  199. package/src/lang/ko.js +0 -188
  200. package/src/lang/lv.d.ts +0 -5
  201. package/src/lang/lv.js +0 -188
  202. package/src/lang/nl.d.ts +0 -5
  203. package/src/lang/nl.js +0 -188
  204. package/src/lang/pl.d.ts +0 -5
  205. package/src/lang/pl.js +0 -188
  206. package/src/lang/pt_br.d.ts +0 -5
  207. package/src/lang/pt_br.js +0 -189
  208. package/src/lang/ro.d.ts +0 -5
  209. package/src/lang/ro.js +0 -188
  210. package/src/lang/ru.d.ts +0 -5
  211. package/src/lang/ru.js +0 -188
  212. package/src/lang/se.d.ts +0 -5
  213. package/src/lang/se.js +0 -191
  214. package/src/lang/tr.d.ts +0 -5
  215. package/src/lang/tr.js +0 -191
  216. package/src/lang/ua.d.ts +0 -5
  217. package/src/lang/ua.js +0 -188
  218. package/src/lang/ur.d.ts +0 -5
  219. package/src/lang/ur.js +0 -188
  220. package/src/lang/zh_cn.d.ts +0 -5
  221. package/src/lang/zh_cn.js +0 -187
  222. package/src/lib/constructor.js +0 -954
  223. package/src/lib/context.d.ts +0 -42
  224. package/src/lib/context.js +0 -71
  225. package/src/lib/core.d.ts +0 -1135
  226. package/src/lib/core.js +0 -9395
  227. package/src/lib/history.d.ts +0 -48
  228. package/src/lib/history.js +0 -219
  229. package/src/lib/util.d.ts +0 -678
  230. package/src/lib/util.js +0 -2131
  231. package/src/options.d.ts +0 -608
  232. package/src/plugins/CommandPlugin.d.ts +0 -8
  233. package/src/plugins/DialogPlugin.d.ts +0 -20
  234. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  235. package/src/plugins/Module.d.ts +0 -15
  236. package/src/plugins/Plugin.d.ts +0 -42
  237. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  238. package/src/plugins/dialog/audio.js +0 -559
  239. package/src/plugins/dialog/image.js +0 -1126
  240. package/src/plugins/dialog/link.js +0 -223
  241. package/src/plugins/dialog/math.js +0 -295
  242. package/src/plugins/dialog/mention.js +0 -242
  243. package/src/plugins/dialog/video.js +0 -979
  244. package/src/plugins/index.d.ts +0 -79
  245. package/src/plugins/modules/_anchor.js +0 -461
  246. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  247. package/src/plugins/modules/_colorPicker.js +0 -201
  248. package/src/plugins/modules/_notice.d.ts +0 -21
  249. package/src/plugins/modules/_notice.js +0 -72
  250. package/src/plugins/modules/_selectMenu.js +0 -119
  251. package/src/plugins/modules/component.d.ts +0 -25
  252. package/src/plugins/modules/component.js +0 -81
  253. package/src/plugins/modules/dialog.d.ts +0 -28
  254. package/src/plugins/modules/dialog.js +0 -175
  255. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  256. package/src/plugins/modules/fileBrowser.js +0 -374
  257. package/src/plugins/modules/fileManager.d.ts +0 -67
  258. package/src/plugins/modules/fileManager.js +0 -326
  259. package/src/plugins/modules/index.js +0 -9
  260. package/src/plugins/modules/resizing.d.ts +0 -154
  261. package/src/plugins/modules/resizing.js +0 -903
  262. package/src/plugins/submenu/align.d.ts +0 -5
  263. package/src/plugins/submenu/align.js +0 -160
  264. package/src/plugins/submenu/font.d.ts +0 -5
  265. package/src/plugins/submenu/font.js +0 -123
  266. package/src/plugins/submenu/fontColor.d.ts +0 -5
  267. package/src/plugins/submenu/fontColor.js +0 -101
  268. package/src/plugins/submenu/fontSize.d.ts +0 -5
  269. package/src/plugins/submenu/fontSize.js +0 -112
  270. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  271. package/src/plugins/submenu/formatBlock.js +0 -273
  272. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  273. package/src/plugins/submenu/hiliteColor.js +0 -102
  274. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  275. package/src/plugins/submenu/horizontalRule.js +0 -98
  276. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  277. package/src/plugins/submenu/lineHeight.js +0 -104
  278. package/src/plugins/submenu/list.d.ts +0 -5
  279. package/src/plugins/submenu/list.js +0 -456
  280. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  281. package/src/plugins/submenu/paragraphStyle.js +0 -135
  282. package/src/plugins/submenu/table.d.ts +0 -5
  283. package/src/plugins/submenu/table.js +0 -1431
  284. package/src/plugins/submenu/template.d.ts +0 -5
  285. package/src/plugins/submenu/template.js +0 -72
  286. package/src/plugins/submenu/textStyle.d.ts +0 -5
  287. package/src/plugins/submenu/textStyle.js +0 -167
  288. package/src/suneditor.d.ts +0 -9
  289. package/src/suneditor_build.js +0 -18
  290. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -1,175 +0,0 @@
1
- /*
2
- * wysiwyg web editor
3
- *
4
- * suneditor.js
5
- * Copyright 2017 JiHong Lee.
6
- * MIT license.
7
- */
8
- 'use strict';
9
-
10
- (function (global, factory) {
11
- if (typeof module === 'object' && typeof module.exports === 'object') {
12
- module.exports = global.document ?
13
- factory(global, true) :
14
- function (w) {
15
- if (!w.document) {
16
- throw new Error('SUNEDITOR_MODULES a window with a document');
17
- }
18
- return factory(w);
19
- };
20
- } else {
21
- factory(global);
22
- }
23
- }(typeof window !== 'undefined' ? window : this, function (window, noGlobal) {
24
- const dialog = {
25
- name: 'dialog',
26
- /**
27
- * @description Constructor
28
- * @param {Object} core Core object
29
- */
30
- add: function (core) {
31
- const context = core.context;
32
- context.dialog = {
33
- kind: '',
34
- updateModal: false,
35
- _closeSignal: false
36
- };
37
-
38
- /** dialog */
39
- let dialog_div = core.util.createElement('DIV');
40
- dialog_div.className = 'se-dialog sun-editor-common';
41
-
42
- let dialog_back = core.util.createElement('DIV');
43
- dialog_back.className = 'se-dialog-back';
44
- dialog_back.style.display = 'none';
45
-
46
- let dialog_area = core.util.createElement('DIV');
47
- dialog_area.className = 'se-dialog-inner';
48
- dialog_area.style.display = 'none';
49
-
50
- dialog_div.appendChild(dialog_back);
51
- dialog_div.appendChild(dialog_area);
52
-
53
- context.dialog.modalArea = dialog_div;
54
- context.dialog.back = dialog_back;
55
- context.dialog.modal = dialog_area;
56
-
57
- /** add event listeners */
58
- context.dialog.modal.addEventListener('mousedown', this._onMouseDown_dialog.bind(core));
59
- context.dialog.modal.addEventListener('click', this._onClick_dialog.bind(core));
60
-
61
- /** append html */
62
- context.element.relative.appendChild(dialog_div);
63
-
64
- /** empty memory */
65
- dialog_div = null, dialog_back = null, dialog_area = null;
66
- },
67
-
68
- /**
69
- * @description Event to control the behavior of closing the dialog
70
- * @param {MouseEvent} e Event object
71
- * @private
72
- */
73
- _onMouseDown_dialog: function (e) {
74
- if (/se-dialog-inner/.test(e.target.className)) {
75
- this.context.dialog._closeSignal = true;
76
- } else {
77
- this.context.dialog._closeSignal = false;
78
- }
79
- },
80
-
81
- /**
82
- * @description Event to close the window when the outside area of the dialog or close button is click
83
- * @param {MouseEvent} e Event object
84
- * @private
85
- */
86
- _onClick_dialog: function (e) {
87
- if (/close/.test(e.target.getAttribute('data-command')) || this.context.dialog._closeSignal) {
88
- this.plugins.dialog.close.call(this);
89
- }
90
- },
91
-
92
- /**
93
- * @description Open a Dialog plugin
94
- * @param {String} kind Dialog plugin name
95
- * @param {Boolean} update Whether it will open for update ('image' === this.currentControllerName)
96
- */
97
- open: function (kind, update) {
98
- if (this.modalForm) return false;
99
- if (this.plugins.dialog._bindClose) {
100
- this._d.removeEventListener('keydown', this.plugins.dialog._bindClose);
101
- this.plugins.dialog._bindClose = null;
102
- }
103
-
104
- this.plugins.dialog._bindClose = function (e) {
105
- if (!/27/.test(e.keyCode)) return;
106
- this.plugins.dialog.close.call(this);
107
- }.bind(this);
108
- this._d.addEventListener('keydown', this.plugins.dialog._bindClose);
109
-
110
- this.context.dialog.updateModal = update;
111
-
112
- if (this.options.popupDisplay === 'full') {
113
- this.context.dialog.modalArea.style.position = 'fixed';
114
- } else {
115
- this.context.dialog.modalArea.style.position = 'absolute';
116
- }
117
-
118
- this.context.dialog.kind = kind;
119
- this.modalForm = this.context[kind].modal;
120
- const focusElement = this.context[kind].focusElement;
121
-
122
- if (typeof this.plugins[kind].on === 'function') this.plugins[kind].on.call(this, update);
123
-
124
- this.context.dialog.modalArea.style.display = 'block';
125
- this.context.dialog.back.style.display = 'block';
126
- this.context.dialog.modal.style.display = 'block';
127
- this.modalForm.style.display = 'block';
128
-
129
- if (focusElement) focusElement.focus();
130
- },
131
-
132
- _bindClose: null,
133
-
134
- /**
135
- * @description Close a Dialog plugin
136
- * The plugin's "init" method is called.
137
- */
138
- close: function () {
139
- if (this.plugins.dialog._bindClose) {
140
- this._d.removeEventListener('keydown', this.plugins.dialog._bindClose);
141
- this.plugins.dialog._bindClose = null;
142
- }
143
-
144
- const kind = this.context.dialog.kind;
145
- this.modalForm.style.display = 'none';
146
- this.context.dialog.back.style.display = 'none';
147
- this.context.dialog.modalArea.style.display = 'none';
148
- this.context.dialog.updateModal = false;
149
- if (typeof this.plugins[kind].init === 'function') this.plugins[kind].init.call(this);
150
- this.context.dialog.kind = '';
151
- this.modalForm = null;
152
- this.focus();
153
- }
154
- };
155
-
156
- if (typeof noGlobal === typeof undefined) {
157
- if (!window.SUNEDITOR_MODULES) {
158
- Object.defineProperty(window, 'SUNEDITOR_MODULES', {
159
- enumerable: true,
160
- writable: false,
161
- configurable: false,
162
- value: {}
163
- });
164
- }
165
-
166
- Object.defineProperty(window.SUNEDITOR_MODULES, 'dialog', {
167
- enumerable: true,
168
- writable: false,
169
- configurable: false,
170
- value: dialog
171
- });
172
- }
173
-
174
- return dialog;
175
- }));
@@ -1,42 +0,0 @@
1
- import { Module } from '../Module';
2
-
3
- /**
4
- * @description This is a required module of fileBrowser plugin.
5
- Require context properties when using fileBrowser module:
6
- title(@Required): "File browser window title",
7
- url(@Required): "File server url",
8
- listClass(@Required): "Class name of list div",
9
- itemTemplateHandler(@Required): "Function that defines the HTML of an file item",
10
- selectorHandler(@Required): "Function that action when item click",
11
- columnSize(@Option): "Number of "div.se-file-item-column" to be created (default: 4)"
12
- */
13
- declare interface fileBrowser extends Module {
14
- /**
15
- * @description Open a file browser window
16
- * @param pluginName Plugin name using the file browser
17
- * @param selectorHandler When the function comes as an argument value, it substitutes "context.selectorHandler".
18
- * @example this.plugins.fileBrowser.open.call(this, 'imageGallery', (selectorHandler || null));
19
- */
20
- open(kind: string, update: boolean): void;
21
-
22
- /**
23
- * @description Define the HTML of the item to be put in "div.se-file-item-column".
24
- * @param item Item of the response data's array
25
- */
26
- drawItems: (item: object) => string;
27
-
28
- /**
29
- * @description Close a file browser window
30
- * The plugin's "init" method is called.
31
- * @example this.plugins.fileBrowser.close.call(this);
32
- */
33
- close(): void;
34
-
35
- /**
36
- * @description This method is called when the file browser window is closed.
37
- * Initialize the properties.
38
- */
39
- init?: () => void;
40
- }
41
-
42
- export default fileBrowser;
@@ -1,374 +0,0 @@
1
- /*
2
- * wysiwyg web editor
3
- *
4
- * suneditor.js
5
- * Copyright 2017 JiHong Lee.
6
- * MIT license.
7
- */
8
- 'use strict';
9
-
10
- (function (global, factory) {
11
- if (typeof module === 'object' && typeof module.exports === 'object') {
12
- module.exports = global.document ?
13
- factory(global, true) :
14
- function (w) {
15
- if (!w.document) {
16
- throw new Error('SUNEDITOR_MODULES a window with a document');
17
- }
18
- return factory(w);
19
- };
20
- } else {
21
- factory(global);
22
- }
23
- }(typeof window !== 'undefined' ? window : this, function (window, noGlobal) {
24
- const fileBrowser = {
25
- name: 'fileBrowser',
26
- _xmlHttp: null,
27
- _loading: null,
28
-
29
- /**
30
- * @description Constructor
31
- * @param {Object} core Core object
32
- */
33
- add: function (core) {
34
- const context = core.context;
35
- context.fileBrowser = {
36
- _closeSignal: false,
37
- area: null,
38
- header: null,
39
- tagArea: null,
40
- body: null,
41
- list: null,
42
- tagElements: null,
43
- items: [],
44
- selectedTags: [],
45
- selectorHandler: null,
46
- contextPlugin: '',
47
- columnSize: 4
48
- };
49
-
50
- /** fileBrowser */
51
- let browser_div = core.util.createElement('DIV');
52
- browser_div.className = 'se-file-browser sun-editor-common';
53
-
54
- let back = core.util.createElement('DIV');
55
- back.className = 'se-file-browser-back';
56
-
57
- let content = core.util.createElement('DIV');
58
- content.className = 'se-file-browser-inner';
59
- content.innerHTML = this.set_browser(core);
60
-
61
- browser_div.appendChild(back);
62
- browser_div.appendChild(content);
63
- this._loading = browser_div.querySelector('.se-loading-box');
64
-
65
- context.fileBrowser.area = browser_div;
66
- context.fileBrowser.header = content.querySelector('.se-file-browser-header');
67
- context.fileBrowser.titleArea = content.querySelector('.se-file-browser-title');
68
- context.fileBrowser.tagArea = content.querySelector('.se-file-browser-tags');
69
- context.fileBrowser.body = content.querySelector('.se-file-browser-body');
70
- context.fileBrowser.list = content.querySelector('.se-file-browser-list');
71
-
72
- /** add event listeners */
73
- context.fileBrowser.tagArea.addEventListener('click', this.onClickTag.bind(core));
74
- context.fileBrowser.list.addEventListener('click', this.onClickFile.bind(core));
75
- content.addEventListener('mousedown', this._onMouseDown_browser.bind(core));
76
- content.addEventListener('click', this._onClick_browser.bind(core));
77
-
78
- /** append html */
79
- context.element.relative.appendChild(browser_div);
80
-
81
- /** empty memory */
82
- browser_div = null, back = null, content = null;
83
- },
84
-
85
- set_browser: function (core) {
86
- const lang = core.lang;
87
-
88
- return '<div class="se-file-browser-content">' +
89
- '<div class="se-file-browser-header">' +
90
- '<button type="button" data-command="close" class="se-btn se-file-browser-close" class="close" title="' + lang.dialogBox.close + '" aria-label="' + lang.dialogBox.close + '">' +
91
- core.icons.cancel +
92
- '</button>' +
93
- '<span class="se-file-browser-title"></span>' +
94
- '<div class="se-file-browser-tags"></div>' +
95
- '</div>' +
96
- '<div class="se-file-browser-body">' +
97
- '<div class="se-loading-box sun-editor-common"><div class="se-loading-effect"></div></div>' +
98
- '<div class="se-file-browser-list"></div>' +
99
- '</div>' +
100
- '</div>';
101
- },
102
-
103
- /**
104
- * @description Event to control the behavior of closing the browser
105
- * @param {MouseEvent} e Event object
106
- * @private
107
- */
108
- _onMouseDown_browser: function (e) {
109
- if (/se-file-browser-inner/.test(e.target.className)) {
110
- this.context.fileBrowser._closeSignal = true;
111
- } else {
112
- this.context.fileBrowser._closeSignal = false;
113
- }
114
- },
115
-
116
- /**
117
- * @description Event to close the window when the outside area of the browser or close button is click
118
- * @param {MouseEvent} e Event object
119
- * @private
120
- */
121
- _onClick_browser: function (e) {
122
- e.stopPropagation();
123
-
124
- if (/close/.test(e.target.getAttribute('data-command')) || this.context.fileBrowser._closeSignal) {
125
- this.plugins.fileBrowser.close.call(this);
126
- }
127
- },
128
-
129
- /**
130
- * @description Open a file browser plugin
131
- * @param {String} pluginName Plugin name using the file browser
132
- * @param {Function|null} selectorHandler When the function comes as an argument value, it substitutes "context.selectorHandler".
133
- */
134
- open: function (pluginName, selectorHandler) {
135
- if (this.plugins.fileBrowser._bindClose) {
136
- this._d.removeEventListener('keydown', this.plugins.fileBrowser._bindClose);
137
- this.plugins.fileBrowser._bindClose = null;
138
- }
139
-
140
- this.plugins.fileBrowser._bindClose = function (e) {
141
- if (!/27/.test(e.keyCode)) return;
142
- this.plugins.fileBrowser.close.call(this);
143
- }.bind(this);
144
- this._d.addEventListener('keydown', this.plugins.fileBrowser._bindClose);
145
-
146
- const fileBrowserContext = this.context.fileBrowser;
147
- fileBrowserContext.contextPlugin = pluginName;
148
- fileBrowserContext.selectorHandler = selectorHandler;
149
-
150
- const pluginContext = this.context[pluginName];
151
- const listClassName = pluginContext.listClass;
152
- if (!this.util.hasClass(fileBrowserContext.list, listClassName)) {
153
- fileBrowserContext.list.className = 'se-file-browser-list ' + listClassName;
154
- }
155
-
156
- if (this.options.popupDisplay === 'full') {
157
- fileBrowserContext.area.style.position = 'fixed';
158
- } else {
159
- fileBrowserContext.area.style.position = 'absolute';
160
- }
161
-
162
- fileBrowserContext.titleArea.textContent = pluginContext.title;
163
- fileBrowserContext.area.style.display = 'block';
164
-
165
- this.plugins.fileBrowser._drawFileList.call(this, this.context[pluginName].url, this.context[pluginName].header);
166
- },
167
-
168
- _bindClose: null,
169
-
170
- /**
171
- * @description Close a fileBrowser plugin
172
- * The plugin's "init" method is called.
173
- */
174
- close: function () {
175
- const fileBrowserPlugin = this.plugins.fileBrowser;
176
-
177
- if (fileBrowserPlugin._xmlHttp) {
178
- fileBrowserPlugin._xmlHttp.abort();
179
- }
180
-
181
- if (fileBrowserPlugin._bindClose) {
182
- this._d.removeEventListener('keydown', fileBrowserPlugin._bindClose);
183
- fileBrowserPlugin._bindClose = null;
184
- }
185
-
186
- const fileBrowserContext = this.context.fileBrowser;
187
- fileBrowserContext.area.style.display = 'none';
188
- fileBrowserContext.selectorHandler = null;
189
- fileBrowserContext.selectedTags = [];
190
- fileBrowserContext.items = [];
191
- fileBrowserContext.list.innerHTML = fileBrowserContext.tagArea.innerHTML = fileBrowserContext.titleArea.textContent = '';
192
-
193
- if (typeof this.plugins[fileBrowserContext.contextPlugin].init === 'function') this.plugins[fileBrowserContext.contextPlugin].init.call(this);
194
- fileBrowserContext.contextPlugin = '';
195
- },
196
-
197
- /**
198
- * @description Show file browser loading box
199
- */
200
- showBrowserLoading: function () {
201
- this._loading.style.display = 'block';
202
- },
203
-
204
- /**
205
- * @description Close file browser loading box
206
- */
207
- closeBrowserLoading: function () {
208
- this._loading.style.display = 'none';
209
- },
210
-
211
- _drawFileList: function (url, browserHeader) {
212
- const fileBrowserPlugin = this.plugins.fileBrowser;
213
-
214
- const xmlHttp = fileBrowserPlugin._xmlHttp = this.util.getXMLHttpRequest();
215
- xmlHttp.onreadystatechange = fileBrowserPlugin._callBackGet.bind(this, xmlHttp);
216
- xmlHttp.open('get', url, true);
217
- if(browserHeader !== null && typeof browserHeader === 'object' && this._w.Object.keys(browserHeader).length > 0){
218
- for(let key in browserHeader){
219
- xmlHttp.setRequestHeader(key, browserHeader[key]);
220
- }
221
- }
222
- xmlHttp.send(null);
223
-
224
- this.plugins.fileBrowser.showBrowserLoading();
225
- },
226
-
227
- _callBackGet: function (xmlHttp) {
228
- if (xmlHttp.readyState === 4) {
229
- this.plugins.fileBrowser._xmlHttp = null;
230
- if (xmlHttp.status === 200) {
231
- try {
232
- const res = JSON.parse(xmlHttp.responseText);
233
- if (res.result.length > 0) {
234
- this.plugins.fileBrowser._drawListItem.call(this, res.result, true);
235
- } else if (res.nullMessage) {
236
- this.context.fileBrowser.list.innerHTML = res.nullMessage;
237
- }
238
- } catch (e) {
239
- throw Error('[SUNEDITOR.fileBrowser.drawList.fail] cause : "' + e.message + '"');
240
- } finally {
241
- this.plugins.fileBrowser.closeBrowserLoading();
242
- this.context.fileBrowser.body.style.maxHeight = (this._w.innerHeight - this.context.fileBrowser.header.offsetHeight - 50) + 'px';
243
- }
244
- } else { // exception
245
- this.plugins.fileBrowser.closeBrowserLoading();
246
- if (xmlHttp.status !== 0) {
247
- const res = !xmlHttp.responseText ? xmlHttp : JSON.parse(xmlHttp.responseText);
248
- const err = '[SUNEDITOR.fileBrowser.get.serverException] status: ' + xmlHttp.status + ', response: ' + (res.errorMessage || xmlHttp.responseText);
249
- throw Error(err);
250
- }
251
- }
252
- }
253
- },
254
-
255
- _drawListItem: function (items, update) {
256
- const fileBrowserContext = this.context.fileBrowser;
257
- const pluginContext = this.context[fileBrowserContext.contextPlugin];
258
-
259
- const _tags = [];
260
- const len = items.length;
261
- const columnSize = pluginContext.columnSize || fileBrowserContext.columnSize;
262
- const splitSize = columnSize <= 1 ? 1 : (Math.round(len/columnSize) || 1);
263
- const drawItemHandler = pluginContext.itemTemplateHandler;
264
-
265
- let tagsHTML = '';
266
- let listHTML = '<div class="se-file-item-column">';
267
- let columns = 1;
268
- for (let i = 0, item, tags; i < len; i++) {
269
- item = items[i];
270
- tags = !item.tag ? [] : typeof item.tag === 'string' ? item.tag.split(',') : item.tag;
271
- tags = item.tag = tags.map(function (v) { return v.trim(); });
272
- listHTML += drawItemHandler(item);
273
-
274
- if ((i + 1) % splitSize === 0 && columns < columnSize && (i + 1) < len) {
275
- columns++;
276
- listHTML += '</div><div class="se-file-item-column">';
277
- }
278
-
279
- if (update && tags.length > 0) {
280
- for (let t = 0, tLen = tags.length, tag; t < tLen; t++) {
281
- tag = tags[t];
282
- if (tag && _tags.indexOf(tag) === -1) {
283
- _tags.push(tag);
284
- tagsHTML += '<a title="' + tag + '" aria-label="' + tag + '">' + tag + '</a>';
285
- }
286
- }
287
- }
288
- }
289
- listHTML += '</div>';
290
-
291
- fileBrowserContext.list.innerHTML = listHTML;
292
-
293
- if (update) {
294
- fileBrowserContext.items = items;
295
- fileBrowserContext.tagArea.innerHTML = tagsHTML;
296
- fileBrowserContext.tagElements = fileBrowserContext.tagArea.querySelectorAll('A');
297
- }
298
- },
299
-
300
- onClickTag: function (e) {
301
- const target = e.target;
302
- if (!this.util.isAnchor(target)) return;
303
-
304
- const tagName = target.textContent;
305
- const fileBrowserPlugin = this.plugins.fileBrowser;
306
- const fileBrowserContext = this.context.fileBrowser;
307
-
308
- const selectTag = fileBrowserContext.tagArea.querySelector('a[title="' + tagName + '"]');
309
- const selectedTags = fileBrowserContext.selectedTags;
310
- const sTagIndex = selectedTags.indexOf(tagName);
311
-
312
- if (sTagIndex > -1){
313
- selectedTags.splice(sTagIndex, 1);
314
- this.util.removeClass(selectTag, 'on');
315
- } else {
316
- selectedTags.push(tagName);
317
- this.util.addClass(selectTag, 'on');
318
- }
319
-
320
- fileBrowserPlugin._drawListItem.call(this,
321
- selectedTags.length === 0 ?
322
- fileBrowserContext.items :
323
- fileBrowserContext.items.filter(function (item) {
324
- return item.tag.some(function (tag) {
325
- return selectedTags.indexOf(tag) > -1;
326
- });
327
- }), false);
328
- },
329
-
330
- onClickFile: function (e) {
331
- e.preventDefault();
332
- e.stopPropagation();
333
-
334
- const fileBrowserContext = this.context.fileBrowser;
335
- const listEl = fileBrowserContext.list;
336
- let target = e.target;
337
- let command = null;
338
-
339
- if (target === listEl) return;
340
-
341
- while (listEl !== target.parentNode) {
342
- command = target.getAttribute('data-command');
343
- if (command) break;
344
- target = target.parentNode;
345
- }
346
-
347
- if (!command) return;
348
-
349
- const handler = (fileBrowserContext.selectorHandler || this.context[fileBrowserContext.contextPlugin].selectorHandler);
350
- handler(target, target.parentNode.querySelector('.__se__img_name').textContent);
351
- this.plugins.fileBrowser.close.call(this);
352
- }
353
- };
354
-
355
- if (typeof noGlobal === typeof undefined) {
356
- if (!window.SUNEDITOR_MODULES) {
357
- Object.defineProperty(window, 'SUNEDITOR_MODULES', {
358
- enumerable: true,
359
- writable: false,
360
- configurable: false,
361
- value: {}
362
- });
363
- }
364
-
365
- Object.defineProperty(window.SUNEDITOR_MODULES, 'fileBrowser', {
366
- enumerable: true,
367
- writable: false,
368
- configurable: false,
369
- value: fileBrowser
370
- });
371
- }
372
-
373
- return fileBrowser;
374
- }));
@@ -1,67 +0,0 @@
1
- import { Module } from '../Module';
2
-
3
- /**
4
- * @description Require context properties when fileManager module
5
- _infoList: [],
6
- _infoIndex: 0,
7
- _uploadFileLength: 0
8
- */
9
- declare interface fileManager extends Module {
10
- /**
11
- * @description Upload the file to the server.
12
- * @param uploadUrl Upload server url
13
- * @param uploadHeader Request header
14
- * @param formData FormData in body
15
- * @param callBack Success call back function
16
- * @param errorCallBack Error call back function
17
- * @example this.plugins.fileManager.upload.call(this, imageUploadUrl, this.options.imageUploadHeader, formData, this.plugins.image.callBack_imgUpload.bind(this, info), this.functions.onImageUploadError);
18
- */
19
- upload(uploadUrl: string, uploadHeader: Record<string, string> | null, formData: FormData, callBack: Function | null, errorCallBack: Function | null): void;
20
-
21
- /**
22
- * @description Checke the file's information and modify the tag that does not fit the format.
23
- * @param pluginName Plugin name
24
- * @param tagNames Tag array to check
25
- * @param uploadEventHandler Event handler to process updated file info after checking (used in "setInfo")
26
- * @param modifyHandler A function to modify a tag that does not fit the format (Argument value: Tag element)
27
- * @param resizing True if the plugin is using a resizing module
28
- * @example
29
- * const modifyHandler = function (tag) {
30
- * imagePlugin.onModifyMode.call(this, tag, null);
31
- * imagePlugin.openModify.call(this, true);
32
- * imagePlugin.update_image.call(this, true, false, true);
33
- * }.bind(this);
34
- * this.plugins.fileManager.checkInfo.call(this, 'image', ['img'], this.functions.onImageUpload, modifyHandler, true);
35
- */
36
- checkInfo(pluginName: string, tagNames: string[], uploadEventHandler: Function | null, modifyHandler: Function | null, resizing: boolean): void;
37
-
38
- /**
39
- * @description Create info object of file and add it to "_infoList" (this.context[pluginName]._infoList[])
40
- * @param pluginName Plugin name
41
- * @param element
42
- * @param uploadEventHandler Event handler to process updated file info (created in setInfo)
43
- * @param file
44
- * @param resizing True if the plugin is using a resizing module
45
- * @example
46
- * uploadCallBack {.. file = { name: fileList[i].name, size: fileList[i].size };
47
- * this.plugins.fileManager.setInfo.call(this, 'image', oImg, this.functions.onImageUpload, file, true);
48
- */
49
- setInfo(pluginName: string, element, uploadEventHandler: Function | null, file:Record<string, string|number> | null, resizing: boolean): void;
50
-
51
- /**
52
- * @description Delete info object at "_infoList"
53
- * @param pluginName Plugin name
54
- * @param index index of info object (this.context[pluginName]._infoList[].index)
55
- * @param uploadEventHandler Event handler to process updated file info (created in setInfo)
56
- */
57
- deleteInfo(pluginName: string, index, uploadEventHandler: Function | null): void;
58
-
59
- /**
60
- * @description Reset info object and "_infoList = []", "_infoIndex = 0"
61
- * @param pluginName Plugin name
62
- * @param uploadEventHandler Event handler to process updated file info (created in setInfo)
63
- */
64
- resetInfo(pluginName: string, uploadEventHandler: Function | null): void;
65
- }
66
-
67
- export default fileManager;