suneditor 2.46.2 → 3.0.0-alpha.1

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 +174 -805
  6. package/dist/suneditor.min.css +1 -0
  7. package/dist/suneditor.min.js +1 -2
  8. package/package.json +96 -69
  9. package/src/assets/icons/_default.js +194 -0
  10. package/src/assets/suneditor-content.css +646 -0
  11. package/src/assets/suneditor.css +3378 -0
  12. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  13. package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
  14. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
  15. package/src/core/base/eventHandlers/handler_ww_key_input.js +975 -0
  16. package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
  17. package/src/core/base/eventManager.js +1115 -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 +146 -0
  21. package/src/core/class/component.js +627 -0
  22. package/src/core/class/format.js +3255 -0
  23. package/src/core/class/html.js +1621 -0
  24. package/src/core/class/menu.js +260 -0
  25. package/src/core/class/nodeTransform.js +379 -0
  26. package/src/core/class/notice.js +42 -0
  27. package/src/core/class/offset.js +578 -0
  28. package/src/core/class/selection.js +508 -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 +1593 -0
  33. package/src/core/section/actives.js +107 -0
  34. package/src/core/section/constructor.js +1237 -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 +313 -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 +199 -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 +162 -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 +315 -0
  72. package/src/modules/Figure.js +1160 -0
  73. package/src/modules/FileBrowser.js +271 -0
  74. package/src/modules/FileManager.js +290 -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 +73 -0
  88. package/src/plugins/dropdown/font.js +113 -0
  89. package/src/plugins/dropdown/fontColor.js +73 -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 +172 -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 +510 -0
  104. package/src/plugins/modal/image.js +1062 -0
  105. package/src/plugins/modal/link.js +211 -0
  106. package/src/plugins/modal/math.js +347 -0
  107. package/src/plugins/modal/video.js +870 -0
  108. package/src/suneditor.js +62 -67
  109. package/src/themes/test.css +61 -0
  110. package/typings/CommandPlugin.d.ts +8 -0
  111. package/typings/DialogPlugin.d.ts +20 -0
  112. package/typings/FileBrowserPlugin.d.ts +30 -0
  113. package/typings/Lang.d.ts +124 -0
  114. package/typings/Module.d.ts +15 -0
  115. package/typings/Plugin.d.ts +42 -0
  116. package/typings/SubmenuPlugin.d.ts +8 -0
  117. package/typings/_classes.d.ts +17 -0
  118. package/typings/_colorPicker.d.ts +60 -0
  119. package/typings/_core.d.ts +55 -0
  120. package/typings/align.d.ts +5 -0
  121. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  122. package/typings/backgroundColor.d.ts +5 -0
  123. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  124. package/typings/char.d.ts +39 -0
  125. package/typings/component.d.ts +38 -0
  126. package/typings/context.d.ts +39 -0
  127. package/typings/converter.d.ts +33 -0
  128. package/typings/dialog.d.ts +28 -0
  129. package/typings/domUtils.d.ts +361 -0
  130. package/typings/editor.d.ts +7 -0
  131. package/typings/editor.ts +542 -0
  132. package/typings/env.d.ts +70 -0
  133. package/typings/eventManager.d.ts +37 -0
  134. package/typings/events.d.ts +262 -0
  135. package/typings/fileBrowser.d.ts +42 -0
  136. package/typings/fileManager.d.ts +67 -0
  137. package/typings/font.d.ts +5 -0
  138. package/typings/fontColor.d.ts +5 -0
  139. package/typings/fontSize.d.ts +5 -0
  140. package/typings/format.d.ts +191 -0
  141. package/typings/formatBlock.d.ts +5 -0
  142. package/typings/history.d.ts +48 -0
  143. package/typings/horizontalRule.d.ts +5 -0
  144. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  145. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  146. package/typings/index.d.ts +21 -0
  147. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  148. package/typings/index.plugins.d.ts +58 -0
  149. package/typings/lineHeight.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  151. package/typings/list.d.ts +5 -0
  152. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  153. package/typings/mediaContainer.d.ts +25 -0
  154. package/typings/node.d.ts +57 -0
  155. package/typings/notice.d.ts +16 -0
  156. package/typings/numbers.d.ts +29 -0
  157. package/typings/offset.d.ts +24 -0
  158. package/typings/options.d.ts +589 -0
  159. package/typings/paragraphStyle.d.ts +5 -0
  160. package/typings/resizing.d.ts +141 -0
  161. package/typings/selection.d.ts +94 -0
  162. package/typings/shortcuts.d.ts +13 -0
  163. package/typings/suneditor.d.ts +9 -0
  164. package/typings/table.d.ts +5 -0
  165. package/typings/template.d.ts +5 -0
  166. package/typings/textStyle.d.ts +5 -0
  167. package/typings/toolbar.d.ts +32 -0
  168. package/typings/unicode.d.ts +25 -0
  169. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  170. package/dist/css/suneditor.min.css +0 -1
  171. package/src/assets/css/suneditor-contents.css +0 -562
  172. package/src/assets/css/suneditor.css +0 -566
  173. package/src/assets/defaultIcons.js +0 -103
  174. package/src/lang/Lang.d.ts +0 -144
  175. package/src/lang/ckb.d.ts +0 -5
  176. package/src/lang/ckb.js +0 -188
  177. package/src/lang/cs.d.ts +0 -5
  178. package/src/lang/cs.js +0 -188
  179. package/src/lang/da.d.ts +0 -5
  180. package/src/lang/da.js +0 -191
  181. package/src/lang/de.d.ts +0 -5
  182. package/src/lang/de.js +0 -188
  183. package/src/lang/en.d.ts +0 -5
  184. package/src/lang/en.js +0 -188
  185. package/src/lang/es.d.ts +0 -5
  186. package/src/lang/es.js +0 -188
  187. package/src/lang/fa.d.ts +0 -5
  188. package/src/lang/fa.js +0 -188
  189. package/src/lang/fr.d.ts +0 -5
  190. package/src/lang/fr.js +0 -188
  191. package/src/lang/he.d.ts +0 -5
  192. package/src/lang/he.js +0 -188
  193. package/src/lang/index.d.ts +0 -23
  194. package/src/lang/it.d.ts +0 -5
  195. package/src/lang/it.js +0 -188
  196. package/src/lang/ja.d.ts +0 -5
  197. package/src/lang/ja.js +0 -188
  198. package/src/lang/ko.d.ts +0 -5
  199. package/src/lang/ko.js +0 -188
  200. package/src/lang/lv.d.ts +0 -5
  201. package/src/lang/lv.js +0 -188
  202. package/src/lang/nl.d.ts +0 -5
  203. package/src/lang/nl.js +0 -188
  204. package/src/lang/pl.d.ts +0 -5
  205. package/src/lang/pl.js +0 -188
  206. package/src/lang/pt_br.d.ts +0 -5
  207. package/src/lang/pt_br.js +0 -189
  208. package/src/lang/ro.d.ts +0 -5
  209. package/src/lang/ro.js +0 -188
  210. package/src/lang/ru.d.ts +0 -5
  211. package/src/lang/ru.js +0 -188
  212. package/src/lang/se.d.ts +0 -5
  213. package/src/lang/se.js +0 -191
  214. package/src/lang/tr.d.ts +0 -5
  215. package/src/lang/tr.js +0 -191
  216. package/src/lang/ua.d.ts +0 -5
  217. package/src/lang/ua.js +0 -188
  218. package/src/lang/ur.d.ts +0 -5
  219. package/src/lang/ur.js +0 -188
  220. package/src/lang/zh_cn.d.ts +0 -5
  221. package/src/lang/zh_cn.js +0 -187
  222. package/src/lib/constructor.js +0 -954
  223. package/src/lib/context.d.ts +0 -42
  224. package/src/lib/context.js +0 -71
  225. package/src/lib/core.d.ts +0 -1135
  226. package/src/lib/core.js +0 -9395
  227. package/src/lib/history.d.ts +0 -48
  228. package/src/lib/history.js +0 -219
  229. package/src/lib/util.d.ts +0 -678
  230. package/src/lib/util.js +0 -2131
  231. package/src/options.d.ts +0 -608
  232. package/src/plugins/CommandPlugin.d.ts +0 -8
  233. package/src/plugins/DialogPlugin.d.ts +0 -20
  234. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  235. package/src/plugins/Module.d.ts +0 -15
  236. package/src/plugins/Plugin.d.ts +0 -42
  237. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  238. package/src/plugins/dialog/audio.js +0 -559
  239. package/src/plugins/dialog/image.js +0 -1126
  240. package/src/plugins/dialog/link.js +0 -223
  241. package/src/plugins/dialog/math.js +0 -295
  242. package/src/plugins/dialog/mention.js +0 -242
  243. package/src/plugins/dialog/video.js +0 -979
  244. package/src/plugins/index.d.ts +0 -79
  245. package/src/plugins/modules/_anchor.js +0 -461
  246. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  247. package/src/plugins/modules/_colorPicker.js +0 -201
  248. package/src/plugins/modules/_notice.d.ts +0 -21
  249. package/src/plugins/modules/_notice.js +0 -72
  250. package/src/plugins/modules/_selectMenu.js +0 -119
  251. package/src/plugins/modules/component.d.ts +0 -25
  252. package/src/plugins/modules/component.js +0 -81
  253. package/src/plugins/modules/dialog.d.ts +0 -28
  254. package/src/plugins/modules/dialog.js +0 -175
  255. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  256. package/src/plugins/modules/fileBrowser.js +0 -374
  257. package/src/plugins/modules/fileManager.d.ts +0 -67
  258. package/src/plugins/modules/fileManager.js +0 -326
  259. package/src/plugins/modules/index.js +0 -9
  260. package/src/plugins/modules/resizing.d.ts +0 -154
  261. package/src/plugins/modules/resizing.js +0 -903
  262. package/src/plugins/submenu/align.d.ts +0 -5
  263. package/src/plugins/submenu/align.js +0 -160
  264. package/src/plugins/submenu/font.d.ts +0 -5
  265. package/src/plugins/submenu/font.js +0 -123
  266. package/src/plugins/submenu/fontColor.d.ts +0 -5
  267. package/src/plugins/submenu/fontColor.js +0 -101
  268. package/src/plugins/submenu/fontSize.d.ts +0 -5
  269. package/src/plugins/submenu/fontSize.js +0 -112
  270. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  271. package/src/plugins/submenu/formatBlock.js +0 -273
  272. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  273. package/src/plugins/submenu/hiliteColor.js +0 -102
  274. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  275. package/src/plugins/submenu/horizontalRule.js +0 -98
  276. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  277. package/src/plugins/submenu/lineHeight.js +0 -104
  278. package/src/plugins/submenu/list.d.ts +0 -5
  279. package/src/plugins/submenu/list.js +0 -456
  280. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  281. package/src/plugins/submenu/paragraphStyle.js +0 -135
  282. package/src/plugins/submenu/table.d.ts +0 -5
  283. package/src/plugins/submenu/table.js +0 -1431
  284. package/src/plugins/submenu/template.d.ts +0 -5
  285. package/src/plugins/submenu/template.js +0 -72
  286. package/src/plugins/submenu/textStyle.d.ts +0 -5
  287. package/src/plugins/submenu/textStyle.js +0 -167
  288. package/src/suneditor.d.ts +0 -9
  289. package/src/suneditor_build.js +0 -18
  290. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -0,0 +1,162 @@
1
+ (function (global, factory) {
2
+ if (typeof module === 'object' && typeof module.exports === 'object') {
3
+ module.exports = global.document
4
+ ? factory(global, true)
5
+ : function (w) {
6
+ if (!w.document) {
7
+ throw new Error('SUNEDITOR_LANG a window with a document');
8
+ }
9
+ return factory(w);
10
+ };
11
+ } else {
12
+ factory(global);
13
+ }
14
+ })(typeof window !== 'undefined' ? window : this, function (window, noGlobal) {
15
+ const lang = {
16
+ code: 'zh_cn',
17
+ align: '对齐方式',
18
+ alignCenter: '居中',
19
+ alignJustify: '两端对齐',
20
+ alignLeft: '左对齐',
21
+ alignRight: '右对齐',
22
+ audio: '音讯',
23
+ audio_modal_file: '上传图片',
24
+ audio_modal_title: '插入音频',
25
+ audio_modal_url: '音频网址',
26
+ autoSize: 'Auto size',
27
+ backgroundColor: '背景颜色',
28
+ basic: '基本',
29
+ bold: '粗体',
30
+ bulletedList: '无序列表',
31
+ caption: '标题',
32
+ center: '居中',
33
+ close: '取消',
34
+ codeView: '代码视图',
35
+ default: '默认',
36
+ deleteColumn: '删除列',
37
+ deleteRow: '删除行',
38
+ dir_ltr: '左到右',
39
+ dir_rtl: '右到左',
40
+ edit: '编辑',
41
+ fixedColumnWidth: '固定列宽',
42
+ font: '字体',
43
+ fontColor: '字体颜色',
44
+ fontSize: '字号',
45
+ formats: '格式',
46
+ fullScreen: '全屏',
47
+ height: '高度',
48
+ horizontalLine: '水平线',
49
+ horizontalSplit: '水平分割',
50
+ hr_dashed: '虚线',
51
+ hr_dotted: '点线',
52
+ hr_solid: '实线',
53
+ image: '图片',
54
+ imageGallery: '图片库',
55
+ image_modal_altText: '替换文字',
56
+ image_modal_file: '上传图片',
57
+ image_modal_title: '插入图片',
58
+ image_modal_url: '图片网址',
59
+ indent: '增加缩进',
60
+ insertColumnAfter: '在右侧插入',
61
+ insertColumnBefore: '在左侧插入',
62
+ insertRowAbove: '在上方插入',
63
+ insertRowBelow: '在下方插入',
64
+ italic: '斜体',
65
+ layout: 'Layout',
66
+ left: '左',
67
+ lineHeight: '行高',
68
+ link: '超链接',
69
+ link_modal_bookmark: '书签',
70
+ link_modal_downloadLinkCheck: '下载链接',
71
+ link_modal_newWindowCheck: '在新标签页中打开',
72
+ link_modal_text: '要显示的文字',
73
+ link_modal_title: '插入超链接',
74
+ link_modal_url: '网址',
75
+ list: '列表',
76
+ math: '数学',
77
+ math_modal_fontSizeLabel: '字号',
78
+ math_modal_inputLabel: '数学符号',
79
+ math_modal_previewLabel: '预览',
80
+ math_modal_title: '数学',
81
+ maxSize: '最大尺寸',
82
+ mention: '提到',
83
+ menu_bordered: '边界线',
84
+ menu_code: '代码',
85
+ menu_neon: '霓虹灯',
86
+ menu_shadow: '阴影',
87
+ menu_spaced: '间隔开',
88
+ menu_translucent: '半透明',
89
+ mergeCells: '合并单元格',
90
+ minSize: '最小尺寸',
91
+ mirrorHorizontal: '翻转左右',
92
+ mirrorVertical: '翻转上下',
93
+ numberedList: '有序列表',
94
+ outdent: '减少缩进',
95
+ paragraphStyle: '段落样式',
96
+ preview: '预览',
97
+ print: '打印',
98
+ proportion: '比例',
99
+ ratio: '比',
100
+ redo: '恢复',
101
+ remove: '删除',
102
+ removeFormat: '清除格式',
103
+ resize100: '放大 100%',
104
+ resize25: '放大 25%',
105
+ resize50: '放大 50%',
106
+ resize75: '放大 75%',
107
+ resize: 'Resize',
108
+ revert: '恢复',
109
+ right: '右',
110
+ rotateLeft: '向左旋转',
111
+ rotateRight: '向右旋转',
112
+ save: '保存',
113
+ search: '搜索',
114
+ showBlocks: '显示块区域',
115
+ size: '尺寸',
116
+ splitCells: '分割单元格',
117
+ strike: '删除线',
118
+ submitButton: '确定',
119
+ subscript: '下标',
120
+ superscript: '上标',
121
+ table: '表格',
122
+ tableHeader: '表格标题',
123
+ tags: '标签',
124
+ tag_blockquote: '引用',
125
+ tag_div: '正文 (DIV)',
126
+ tag_h: '标题',
127
+ tag_p: '段落',
128
+ tag_pre: '代码',
129
+ template: '模板',
130
+ textStyle: '文字样式',
131
+ title: 'Title',
132
+ underline: '下划线',
133
+ undo: '撤消',
134
+ unlink: '去除链接',
135
+ verticalSplit: '垂直分割',
136
+ video: '视频',
137
+ video_modal_file: '上传图片',
138
+ video_modal_title: '插入视频',
139
+ video_modal_url: '嵌入网址, Youtube,Vimeo',
140
+ width: '宽度'
141
+ };
142
+
143
+ if (typeof noGlobal === typeof undefined) {
144
+ if (!window.SUNEDITOR_LANG) {
145
+ Object.defineProperty(window, 'SUNEDITOR_LANG', {
146
+ enumerable: true,
147
+ writable: false,
148
+ configurable: false,
149
+ value: {}
150
+ });
151
+ }
152
+
153
+ Object.defineProperty(window.SUNEDITOR_LANG, 'zh_cn', {
154
+ enumerable: true,
155
+ writable: true,
156
+ configurable: true,
157
+ value: lang
158
+ });
159
+ }
160
+
161
+ return lang;
162
+ });
@@ -0,0 +1,168 @@
1
+ import { env } from '../helper';
2
+
3
+ /**
4
+ *
5
+ * @param {*} inst
6
+ * @param {Object|null=} params
7
+ * @param {string|null=} params.method - HTTP method (GET, POST, PUT, DELETE...)
8
+ * @param {string|null=} params.url - API's URL
9
+ * @param {Object|null=} params.headers - HTTP headers
10
+ * @param {Object|null=} params.data - API data
11
+ * @param {Function|null=} params.callBack - API success callback
12
+ * @param {Function|null=} params.errorCallBack - API fail callback
13
+ * @param {string|null=} params.responseType - XMLHttpRequest.responseType
14
+ */
15
+ const ApiManager = function (inst, params) {
16
+ this.editor = inst.editor;
17
+ this.kind = inst.constructor.key || inst.constructor.name;
18
+
19
+ // members
20
+ this._xhr = env.getXMLHttpRequest();
21
+ // members - option
22
+ this.method = params?.method;
23
+ this.url = params?.url;
24
+ this.headers = params?.headers;
25
+ this.data = params?.data;
26
+ this.callBack = params?.callBack;
27
+ this.errorCallBack = params?.errorCallBack;
28
+ this.responseType = params?.responseType;
29
+ };
30
+
31
+ ApiManager.prototype = {
32
+ /**
33
+ * @description Call API
34
+ * @param {Object|null=} params
35
+ * @param {string|null=} params.method - HTTP method (GET, POST, PUT, DELETE...)
36
+ * @param {string|null=} params.url - API's URL
37
+ * @param {Object|null=} params.headers - HTTP headers
38
+ * @param {Object|null=} params.data - API data
39
+ * @param {Function|null=} params.callBack - API success callback
40
+ * @param {Function|null=} params.errorCallBack - API fail callback
41
+ * @param {string|null=} params.responseType - XMLHttpRequest.responseType
42
+ */
43
+ call({ method, url, headers, data, callBack, errorCallBack, responseType }) {
44
+ this.cancel();
45
+
46
+ method = method || this.method;
47
+ url = this._normalizeUrl(url || this.url);
48
+ headers = headers || this.headers;
49
+ data = data || this.data;
50
+ callBack = callBack || this.callBack;
51
+ errorCallBack = errorCallBack || this.errorCallBack;
52
+ responseType = responseType || this.responseType;
53
+
54
+ const xhr = this._xhr;
55
+ if (responseType) xhr.responseType = responseType;
56
+ xhr.onreadystatechange = CallBackApi.bind(this, xhr, callBack, errorCallBack);
57
+ xhr.open(method, url, true);
58
+ if (headers !== null && typeof headers === 'object' && Object.keys(headers).length > 0) {
59
+ for (const key in headers) {
60
+ xhr.setRequestHeader(key, headers[key]);
61
+ }
62
+ }
63
+
64
+ xhr.send(data);
65
+ },
66
+
67
+ /**
68
+ * @description Call Async API
69
+ * @param {Object|null=} params
70
+ * @param {string|null=} params.method - HTTP method (GET, POST, PUT, DELETE...)
71
+ * @param {string|null=} params.url - API's URL
72
+ * @param {Object|null=} params.headers - HTTP headers
73
+ * @param {Object|null=} params.data - API data
74
+ * @param {string|null=} params.responseType - XMLHttpRequest.responseType
75
+ */
76
+ asyncCall({ method, url, headers, data, responseType }) {
77
+ this.cancel();
78
+
79
+ method = method || this.method;
80
+ url = this._normalizeUrl(url || this.url);
81
+ headers = headers || this.headers;
82
+ data = data || this.data;
83
+ responseType = responseType || this.responseType;
84
+
85
+ const xhr = this._xhr;
86
+ if (responseType) xhr.responseType = responseType;
87
+ return new Promise((resolve, reject) => {
88
+ xhr.open(method, url, true);
89
+ if (headers !== null && typeof headers === 'object' && Object.keys(headers).length > 0) {
90
+ for (const key in headers) {
91
+ xhr.setRequestHeader(key, headers[key]);
92
+ }
93
+ }
94
+ xhr.onload = () => {
95
+ if (xhr.status === 200) {
96
+ try {
97
+ resolve(xhr);
98
+ } finally {
99
+ this.editor.hideLoading();
100
+ }
101
+ } else {
102
+ try {
103
+ const res = !xhr.responseText ? xhr : JSON.parse(xhr.responseText);
104
+ reject(res, xhr);
105
+ } finally {
106
+ this.editor.hideLoading();
107
+ }
108
+ }
109
+ };
110
+
111
+ xhr.onerror = () => {
112
+ reject(new Error('Network error'));
113
+ };
114
+
115
+ xhr.send(data);
116
+ });
117
+ },
118
+
119
+ /**
120
+ * @description Cancel API (xhr.abort())
121
+ */
122
+ cancel() {
123
+ if (this._xhr) this._xhr.abort();
124
+ },
125
+
126
+ /**
127
+ * @description Remove unnecessary slashes in API URL.
128
+ * @param {string} url url
129
+ * @returns
130
+ */
131
+ _normalizeUrl(url) {
132
+ return url.replace(/([^:])\/+/g, '$1/').replace(/\/(\?|#|$)/, '$1');
133
+ },
134
+
135
+ constructor: ApiManager
136
+ };
137
+
138
+ async function CallBackApi(xmlHttp, callBack, errorCallBack) {
139
+ if (xmlHttp.readyState === 4) {
140
+ if (xmlHttp.status === 200) {
141
+ try {
142
+ await callBack(xmlHttp);
143
+ } catch (error) {
144
+ throw Error(`[SUNEDITOR.ApiManager[${this.kind}].upload.callBack.fail] ${error.message}`);
145
+ } finally {
146
+ this.editor.hideLoading();
147
+ }
148
+ } else {
149
+ // exception
150
+ console.error(`[SUNEDITOR.ApiManager[${this.kind}].upload.serverException]`, xmlHttp);
151
+ try {
152
+ const res = !xmlHttp.responseText ? xmlHttp : JSON.parse(xmlHttp.responseText);
153
+ let message = '';
154
+ if (typeof errorCallBack === 'function') {
155
+ message = await errorCallBack(res, xmlHttp);
156
+ }
157
+ const err = `[SUNEDITOR.ApiManager[${this.kind}].upload.serverException] status: ${xmlHttp.status}, response: ${message || res.errorMessage || xmlHttp.responseText}`;
158
+ this.editor.notice.open(err);
159
+ } catch (error) {
160
+ throw Error(`[SUNEDITOR.ApiManager[${this.kind}].upload.errorCallBack.fail] ${error.message}`);
161
+ } finally {
162
+ this.editor.hideLoading();
163
+ }
164
+ }
165
+ }
166
+ }
167
+
168
+ export default ApiManager;
@@ -0,0 +1,302 @@
1
+ import { domUtils, converter } from '../helper';
2
+ import CoreInjector from '../editorInjector/_core';
3
+ import { HueSlider } from '../modules';
4
+
5
+ const DEFAULT_COLOR_LIST = [
6
+ '#ff0000',
7
+ '#ff5e00',
8
+ '#ffe400',
9
+ '#abf200',
10
+ '#00d8ff',
11
+ '#0055ff',
12
+ '#6600ff',
13
+ '#ff00dd',
14
+ '#000000',
15
+ '#ffd8d8',
16
+ '#fae0d4',
17
+ '#faf4c0',
18
+ '#e4f7ba',
19
+ '#d4f4fa',
20
+ '#d9e5ff',
21
+ '#e8d9ff',
22
+ '#ffd9fa',
23
+ '#f1f1f1',
24
+ '#ffa7a7',
25
+ '#ffc19e',
26
+ '#faed7d',
27
+ '#cef279',
28
+ '#b2ebf4',
29
+ '#b2ccff',
30
+ '#d1b2ff',
31
+ '#ffb2f5',
32
+ '#bdbdbd',
33
+ '#f15f5f',
34
+ '#f29661',
35
+ '#e5d85c',
36
+ '#bce55c',
37
+ '#5cd1e5',
38
+ '#6699ff',
39
+ '#a366ff',
40
+ '#f261df',
41
+ '#8c8c8c',
42
+ '#980000',
43
+ '#993800',
44
+ '#998a00',
45
+ '#6b9900',
46
+ '#008299',
47
+ '#003399',
48
+ '#3d0099',
49
+ '#990085',
50
+ '#353535',
51
+ '#670000',
52
+ '#662500',
53
+ '#665c00',
54
+ '#476600',
55
+ '#005766',
56
+ '#002266',
57
+ '#290066',
58
+ '#660058',
59
+ '#222222'
60
+ ];
61
+
62
+ const DEFAULLT_COLOR_SPLITNUM = 9;
63
+
64
+ /**
65
+ * @description Create a color picker element and register for related events. (this.target)
66
+ * When calling the color selection, "submit", and "remove" buttons, the "action" method of the instance is called with the "color" value as an argument.
67
+ * @param {Object} inst The "this" object of the calling function.
68
+ * @param {string} styles style property ("color", "backgroundColor"..)
69
+ * @param {Array.<string>} colorList color list
70
+ * @param {string} _defaultColor default color
71
+ */
72
+ const ColorPicker = function (inst, styles, params) {
73
+ const editor = inst.editor;
74
+ CoreInjector.call(this, editor);
75
+
76
+ // members
77
+ this.kind = inst.constructor.key || inst.constructor.name;
78
+ this.inst = inst;
79
+ this.target = CreateHTML(editor, params);
80
+ this.targetButton = null;
81
+ this.inputElement = this.target.querySelector('.se-color-input');
82
+ this.styleProperties = styles;
83
+ this.splitNum = params.splitNum || 0;
84
+ this.defaultColor = params.defaultColor;
85
+ this.hueSliderOptions = params.hueSliderOptions;
86
+ this.parentDisplay = '';
87
+ this.currentColor = '';
88
+ this.parentForm = null;
89
+ this.colorList = this.target.querySelectorAll('li button') || [];
90
+ this.hueSlider = null;
91
+
92
+ // modules - hex, hue slider
93
+ if (!params.disableHEXInput) {
94
+ this.hueSlider = new HueSlider(this, params.hueSliderOptions, 'se-dropdown');
95
+ this.parentFormDisplay = [];
96
+ this.parentForm = params.hueSliderOptions?.controllerOptions?.parents?.length > 0 && !params.hueSliderOptions?.controllerOptions?.isInsideForm ? params.hueSliderOptions.controllerOptions.parents : null;
97
+ // hue open
98
+ this.eventManager.addEvent(this.target.querySelector('.se-btn-info'), 'click', OnColorPalette.bind(this));
99
+ this.eventManager.addEvent(this.inputElement, 'input', OnChangeInput.bind(this));
100
+ this.eventManager.addEvent(this.target.querySelector('form'), 'submit', Submit.bind(this));
101
+ }
102
+
103
+ // remove style
104
+ if (!params.disableRemove) {
105
+ this.eventManager.addEvent(this.target.querySelector('.__se_remove'), 'click', Remove.bind(this));
106
+ }
107
+
108
+ this.eventManager.addEvent(this.target, 'click', OnClickColor.bind(this));
109
+ };
110
+
111
+ ColorPicker.prototype = {
112
+ hueSliderAction(color) {
113
+ this._setInputText(color.hex);
114
+ },
115
+
116
+ hueSliderCancelAction() {
117
+ if (this.parentForm?.length > 0) {
118
+ this.parentFormDisplay.forEach((e) => (e[0].style.display = e[1]));
119
+ }
120
+ },
121
+
122
+ hueSliderClose() {
123
+ this.hueSlider.off();
124
+ },
125
+
126
+ /**
127
+ * @description Displays or resets the currently selected color at color list.
128
+ * @param {Node|String} nodeOrColor Current Selected node
129
+ * @param {string|null} target target
130
+ */
131
+ init(nodeOrColor, target) {
132
+ this.targetButton = target;
133
+
134
+ const computedColor = this.editor.frameContext.get('wwComputedStyle')[this.styleProperties];
135
+ const defaultColor = this.defaultColor || converter.isHexColor(computedColor) ? computedColor : converter.rgb2hex(computedColor);
136
+
137
+ let fillColor = (typeof nodeOrColor === 'string' ? nodeOrColor : this._getColorInNode(nodeOrColor)) || defaultColor;
138
+ fillColor = converter.isHexColor(fillColor) ? fillColor : converter.rgb2hex(fillColor) || fillColor || '';
139
+
140
+ const colorList = this.colorList;
141
+ for (let i = 0, len = colorList.length; i < len; i++) {
142
+ if (fillColor.toLowerCase() === colorList[i].getAttribute('data-value').toLowerCase()) {
143
+ domUtils.addClass(colorList[i], 'active');
144
+ } else {
145
+ domUtils.removeClass(colorList[i], 'active');
146
+ }
147
+ }
148
+
149
+ this._setInputText(this._colorName2hex(fillColor));
150
+ },
151
+
152
+ /**
153
+ * @description Store color values
154
+ * @param {string} hexColorStr Hax color value
155
+ */
156
+ setHexColor(hexColorStr) {
157
+ this.currentColor = hexColorStr;
158
+ this.inputElement.style.borderColor = hexColorStr;
159
+ },
160
+
161
+ /**
162
+ * @description Set color at input element
163
+ * @param {string} hexColorStr Hax color value
164
+ * @private
165
+ */
166
+ _setInputText(hexColorStr) {
167
+ hexColorStr = /^#/.test(hexColorStr) ? hexColorStr : '#' + hexColorStr;
168
+ this.inputElement.value = hexColorStr;
169
+ this.setHexColor.call(this, hexColorStr);
170
+ },
171
+
172
+ /**
173
+ * @description Gets color value at color property of node
174
+ * @param {Node} node Selected node
175
+ * @returns {string}
176
+ * @private
177
+ */
178
+ _getColorInNode(node) {
179
+ let findColor = '';
180
+ const sp = this.styleProperties;
181
+
182
+ while (node && !domUtils.isWysiwygFrame(node) && findColor.length === 0) {
183
+ if (node.nodeType === 1 && node.style[sp]) findColor = node.style[sp];
184
+ node = node.parentNode;
185
+ }
186
+
187
+ return findColor;
188
+ },
189
+
190
+ /**
191
+ * @description Converts color values of other formats to hex color values and returns.
192
+ * @param {string} colorName Color value
193
+ * @returns {string}
194
+ */
195
+ _colorName2hex(colorName) {
196
+ if (/^#/.test(colorName)) return colorName;
197
+ const temp = domUtils.createElement('div', { style: 'display: none; color: ' + colorName });
198
+ const colors = this._w
199
+ .getComputedStyle(this._d.body.appendChild(temp))
200
+ .color.match(/\d+/g)
201
+ .map(function (a) {
202
+ return parseInt(a, 10);
203
+ });
204
+ domUtils.removeItem(temp);
205
+ return colors.length >= 3 ? '#' + ((1 << 24) + (colors[0] << 16) + (colors[1] << 8) + colors[2]).toString(16).substr(1) : false;
206
+ },
207
+
208
+ constructor: ColorPicker
209
+ };
210
+
211
+ function OnColorPalette() {
212
+ if (this.parentForm?.length > 0) {
213
+ this.parentForm.forEach((e) => {
214
+ this.parentFormDisplay.push([e, e.style.display]);
215
+ e.style.display = 'none';
216
+ });
217
+ }
218
+ this.hueSlider.open(this.targetButton);
219
+ }
220
+
221
+ function Submit(e) {
222
+ e.preventDefault();
223
+
224
+ if (typeof this.inst.colorPickerAction !== 'function') return;
225
+ this.inst.colorPickerAction(this.currentColor);
226
+ }
227
+
228
+ function OnClickColor(e) {
229
+ const color = e.target.getAttribute('data-value');
230
+ if (!color) return;
231
+
232
+ if (typeof this.inst.colorPickerAction !== 'function') return;
233
+ this.inst.colorPickerAction(color);
234
+ }
235
+
236
+ function Remove() {
237
+ if (typeof this.inst.colorPickerAction !== 'function') return;
238
+ this.inst.colorPickerAction(null);
239
+ }
240
+
241
+ function OnChangeInput(e) {
242
+ this.setHexColor(e.target.value);
243
+ }
244
+
245
+ function CreateHTML({ lang, icons }, { colorList, disableHEXInput, disableRemove, splitNum }) {
246
+ colorList = colorList || DEFAULT_COLOR_LIST;
247
+ splitNum = colorList === DEFAULT_COLOR_LIST ? DEFAULLT_COLOR_SPLITNUM : splitNum;
248
+
249
+ let list = '';
250
+ for (let i = 0, len = colorList.length, colorArr = [], color; i < len; i++) {
251
+ color = colorList[i];
252
+ if (!color) continue;
253
+
254
+ if (typeof color === 'string' || color.value) {
255
+ colorArr.push(color);
256
+ if (i < len - 1) continue;
257
+ }
258
+ if (colorArr.length > 0) {
259
+ list += `<div class="se-selector-color">${_makeColor(colorArr, splitNum)}</div>`;
260
+ colorArr = [];
261
+ }
262
+ if (typeof color === 'object') {
263
+ list += `<div class="se-selector-color">${_makeColor(color, splitNum)}</div>`;
264
+ }
265
+ }
266
+ list += /*html*/ `
267
+ <form class="se-form-group se-form-w0">
268
+ ${disableHEXInput ? '' : `<button type="button" class="se-btn se-btn-info" title="${lang.colorPicker}" aria-label="${lang.colorPicker}">${icons.color_palette}</button>`}
269
+ <input type="text" class="se-color-input" ${disableHEXInput ? 'readonly' : ''} placeholder="${lang.color}" />
270
+ ${disableHEXInput ? '' : `<button type="submit" class="se-btn se-btn-success" title="${lang.submitButton}" aria-label="${lang.submitButton}">${icons.checked}</button>`}
271
+ ${disableRemove ? '' : `<button type="button" class="se-btn __se_remove" title="${lang.remove}" aria-label="${lang.remove}">${icons.remove_color}</button>`}
272
+ </form>`;
273
+
274
+ return domUtils.createElement('DIV', { class: 'se-list-inner' }, list);
275
+ }
276
+
277
+ function _makeColor(colorList, splitNum) {
278
+ const ulHTML = `<ul class="se-color-pallet${splitNum ? ' se-list-horizontal' : ''}">`;
279
+
280
+ let list = ulHTML;
281
+ for (let i = 0, len = colorList.length, color, v, n; i < len; i++) {
282
+ color = colorList[i];
283
+ if (typeof color === 'string') {
284
+ v = color;
285
+ n = color;
286
+ } else if (typeof color === 'object') {
287
+ v = color.value;
288
+ n = color.name || v;
289
+ }
290
+
291
+ if (i > 0 && i % splitNum === 0) {
292
+ list += `</ul>${ulHTML}`;
293
+ }
294
+
295
+ list += /*html*/ `<li><button type="button" data-value="${v}" title="${n}" aria-label="${n}" style="background-color:${v};"></button></li>`;
296
+ }
297
+ list += '</ul>';
298
+
299
+ return list;
300
+ }
301
+
302
+ export default ColorPicker;