suneditor 2.46.2 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.json +64 -0
  3. package/CONTRIBUTING.md +36 -0
  4. package/LICENSE.txt +1 -1
  5. package/README.md +11 -1560
  6. package/package.json +94 -70
  7. package/src/assets/icons/_default.js +194 -0
  8. package/src/assets/suneditor-content.css +642 -0
  9. package/src/assets/suneditor.css +3378 -0
  10. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  11. package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
  12. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
  13. package/src/core/base/eventHandlers/handler_ww_key_input.js +978 -0
  14. package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
  15. package/src/core/base/eventManager.js +1129 -0
  16. package/src/core/base/events.js +320 -0
  17. package/src/core/base/history.js +301 -0
  18. package/src/core/class/char.js +146 -0
  19. package/src/core/class/component.js +624 -0
  20. package/src/core/class/format.js +3255 -0
  21. package/src/core/class/html.js +1621 -0
  22. package/src/core/class/menu.js +260 -0
  23. package/src/core/class/nodeTransform.js +379 -0
  24. package/src/core/class/notice.js +42 -0
  25. package/src/core/class/offset.js +578 -0
  26. package/src/core/class/selection.js +508 -0
  27. package/src/core/class/shortcuts.js +38 -0
  28. package/src/core/class/toolbar.js +440 -0
  29. package/src/core/class/viewer.js +646 -0
  30. package/src/core/editor.js +1588 -0
  31. package/src/core/section/actives.js +107 -0
  32. package/src/core/section/constructor.js +1237 -0
  33. package/src/core/section/context.js +97 -0
  34. package/src/editorInjector/_classes.js +22 -0
  35. package/src/editorInjector/_core.js +28 -0
  36. package/src/editorInjector/index.js +13 -0
  37. package/src/helper/converter.js +313 -0
  38. package/src/helper/domUtils.js +1177 -0
  39. package/src/helper/env.js +250 -0
  40. package/src/helper/index.js +19 -0
  41. package/src/helper/numbers.js +68 -0
  42. package/src/helper/unicode.js +43 -0
  43. package/src/langs/ckb.js +161 -0
  44. package/src/langs/cs.js +161 -0
  45. package/src/langs/da.js +161 -0
  46. package/src/langs/de.js +162 -0
  47. package/src/langs/en.js +199 -0
  48. package/src/langs/es.js +162 -0
  49. package/src/langs/fa.js +159 -0
  50. package/src/langs/fr.js +161 -0
  51. package/src/langs/he.js +162 -0
  52. package/src/{lang → langs}/index.js +0 -2
  53. package/src/langs/it.js +162 -0
  54. package/src/langs/ja.js +162 -0
  55. package/src/langs/ko.js +162 -0
  56. package/src/langs/lv.js +162 -0
  57. package/src/langs/nl.js +162 -0
  58. package/src/langs/pl.js +162 -0
  59. package/src/langs/pt_br.js +162 -0
  60. package/src/langs/ro.js +162 -0
  61. package/src/langs/ru.js +162 -0
  62. package/src/langs/se.js +162 -0
  63. package/src/langs/tr.js +159 -0
  64. package/src/langs/ua.js +162 -0
  65. package/src/langs/ur.js +162 -0
  66. package/src/langs/zh_cn.js +162 -0
  67. package/src/modules/ApiManager.js +168 -0
  68. package/src/modules/ColorPicker.js +302 -0
  69. package/src/modules/Controller.js +315 -0
  70. package/src/modules/Figure.js +1174 -0
  71. package/src/modules/FileBrowser.js +271 -0
  72. package/src/modules/FileManager.js +290 -0
  73. package/src/modules/HueSlider.js +513 -0
  74. package/src/modules/Modal.js +177 -0
  75. package/src/modules/ModalAnchorEditor.js +494 -0
  76. package/src/modules/SelectMenu.js +447 -0
  77. package/src/modules/_DragHandle.js +16 -0
  78. package/src/modules/index.js +14 -0
  79. package/src/plugins/command/blockquote.js +47 -47
  80. package/src/plugins/command/exportPdf.js +168 -0
  81. package/src/plugins/command/fileUpload.js +389 -0
  82. package/src/plugins/command/list_bulleted.js +112 -0
  83. package/src/plugins/command/list_numbered.js +115 -0
  84. package/src/plugins/dropdown/align.js +143 -0
  85. package/src/plugins/dropdown/backgroundColor.js +73 -0
  86. package/src/plugins/dropdown/font.js +113 -0
  87. package/src/plugins/dropdown/fontColor.js +73 -0
  88. package/src/plugins/dropdown/formatBlock.js +141 -0
  89. package/src/plugins/dropdown/hr.js +111 -0
  90. package/src/plugins/dropdown/layout.js +72 -0
  91. package/src/plugins/dropdown/lineHeight.js +114 -0
  92. package/src/plugins/dropdown/list.js +107 -0
  93. package/src/plugins/dropdown/paragraphStyle.js +117 -0
  94. package/src/plugins/dropdown/table.js +2810 -0
  95. package/src/plugins/dropdown/template.js +71 -0
  96. package/src/plugins/dropdown/textStyle.js +137 -0
  97. package/src/plugins/field/mention.js +172 -0
  98. package/src/plugins/fileBrowser/imageGallery.js +76 -59
  99. package/src/plugins/index.js +86 -24
  100. package/src/plugins/input/fontSize.js +357 -0
  101. package/src/plugins/modal/audio.js +492 -0
  102. package/src/plugins/modal/image.js +1062 -0
  103. package/src/plugins/modal/link.js +211 -0
  104. package/src/plugins/modal/math.js +347 -0
  105. package/src/plugins/modal/video.js +870 -0
  106. package/src/suneditor.js +62 -67
  107. package/src/themes/test.css +61 -0
  108. package/typings/CommandPlugin.d.ts +8 -0
  109. package/typings/DialogPlugin.d.ts +20 -0
  110. package/typings/FileBrowserPlugin.d.ts +30 -0
  111. package/typings/Lang.d.ts +124 -0
  112. package/typings/Module.d.ts +15 -0
  113. package/typings/Plugin.d.ts +42 -0
  114. package/typings/SubmenuPlugin.d.ts +8 -0
  115. package/typings/_classes.d.ts +17 -0
  116. package/typings/_colorPicker.d.ts +60 -0
  117. package/typings/_core.d.ts +55 -0
  118. package/typings/align.d.ts +5 -0
  119. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  120. package/typings/backgroundColor.d.ts +5 -0
  121. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  122. package/typings/char.d.ts +39 -0
  123. package/typings/component.d.ts +38 -0
  124. package/typings/context.d.ts +39 -0
  125. package/typings/converter.d.ts +33 -0
  126. package/typings/dialog.d.ts +28 -0
  127. package/typings/domUtils.d.ts +361 -0
  128. package/typings/editor.d.ts +7 -0
  129. package/typings/editor.ts +542 -0
  130. package/typings/env.d.ts +70 -0
  131. package/typings/eventManager.d.ts +37 -0
  132. package/typings/events.d.ts +262 -0
  133. package/typings/fileBrowser.d.ts +42 -0
  134. package/typings/fileManager.d.ts +67 -0
  135. package/typings/font.d.ts +5 -0
  136. package/typings/fontColor.d.ts +5 -0
  137. package/typings/fontSize.d.ts +5 -0
  138. package/typings/format.d.ts +191 -0
  139. package/typings/formatBlock.d.ts +5 -0
  140. package/typings/history.d.ts +48 -0
  141. package/typings/horizontalRule.d.ts +5 -0
  142. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  143. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  144. package/typings/index.d.ts +21 -0
  145. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  146. package/typings/index.plugins.d.ts +58 -0
  147. package/typings/lineHeight.d.ts +5 -0
  148. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  149. package/typings/list.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  151. package/typings/mediaContainer.d.ts +25 -0
  152. package/typings/node.d.ts +57 -0
  153. package/typings/notice.d.ts +16 -0
  154. package/typings/numbers.d.ts +29 -0
  155. package/typings/offset.d.ts +24 -0
  156. package/typings/options.d.ts +589 -0
  157. package/typings/paragraphStyle.d.ts +5 -0
  158. package/typings/resizing.d.ts +141 -0
  159. package/typings/selection.d.ts +94 -0
  160. package/typings/shortcuts.d.ts +13 -0
  161. package/typings/suneditor.d.ts +9 -0
  162. package/typings/table.d.ts +5 -0
  163. package/typings/template.d.ts +5 -0
  164. package/typings/textStyle.d.ts +5 -0
  165. package/typings/toolbar.d.ts +32 -0
  166. package/typings/unicode.d.ts +25 -0
  167. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  168. package/dist/css/suneditor.min.css +0 -1
  169. package/dist/suneditor.min.js +0 -2
  170. package/src/assets/css/suneditor-contents.css +0 -562
  171. package/src/assets/css/suneditor.css +0 -566
  172. package/src/assets/defaultIcons.js +0 -103
  173. package/src/lang/Lang.d.ts +0 -144
  174. package/src/lang/ckb.d.ts +0 -5
  175. package/src/lang/ckb.js +0 -188
  176. package/src/lang/cs.d.ts +0 -5
  177. package/src/lang/cs.js +0 -188
  178. package/src/lang/da.d.ts +0 -5
  179. package/src/lang/da.js +0 -191
  180. package/src/lang/de.d.ts +0 -5
  181. package/src/lang/de.js +0 -188
  182. package/src/lang/en.d.ts +0 -5
  183. package/src/lang/en.js +0 -188
  184. package/src/lang/es.d.ts +0 -5
  185. package/src/lang/es.js +0 -188
  186. package/src/lang/fa.d.ts +0 -5
  187. package/src/lang/fa.js +0 -188
  188. package/src/lang/fr.d.ts +0 -5
  189. package/src/lang/fr.js +0 -188
  190. package/src/lang/he.d.ts +0 -5
  191. package/src/lang/he.js +0 -188
  192. package/src/lang/index.d.ts +0 -23
  193. package/src/lang/it.d.ts +0 -5
  194. package/src/lang/it.js +0 -188
  195. package/src/lang/ja.d.ts +0 -5
  196. package/src/lang/ja.js +0 -188
  197. package/src/lang/ko.d.ts +0 -5
  198. package/src/lang/ko.js +0 -188
  199. package/src/lang/lv.d.ts +0 -5
  200. package/src/lang/lv.js +0 -188
  201. package/src/lang/nl.d.ts +0 -5
  202. package/src/lang/nl.js +0 -188
  203. package/src/lang/pl.d.ts +0 -5
  204. package/src/lang/pl.js +0 -188
  205. package/src/lang/pt_br.d.ts +0 -5
  206. package/src/lang/pt_br.js +0 -189
  207. package/src/lang/ro.d.ts +0 -5
  208. package/src/lang/ro.js +0 -188
  209. package/src/lang/ru.d.ts +0 -5
  210. package/src/lang/ru.js +0 -188
  211. package/src/lang/se.d.ts +0 -5
  212. package/src/lang/se.js +0 -191
  213. package/src/lang/tr.d.ts +0 -5
  214. package/src/lang/tr.js +0 -191
  215. package/src/lang/ua.d.ts +0 -5
  216. package/src/lang/ua.js +0 -188
  217. package/src/lang/ur.d.ts +0 -5
  218. package/src/lang/ur.js +0 -188
  219. package/src/lang/zh_cn.d.ts +0 -5
  220. package/src/lang/zh_cn.js +0 -187
  221. package/src/lib/constructor.js +0 -954
  222. package/src/lib/context.d.ts +0 -42
  223. package/src/lib/context.js +0 -71
  224. package/src/lib/core.d.ts +0 -1135
  225. package/src/lib/core.js +0 -9395
  226. package/src/lib/history.d.ts +0 -48
  227. package/src/lib/history.js +0 -219
  228. package/src/lib/util.d.ts +0 -678
  229. package/src/lib/util.js +0 -2131
  230. package/src/options.d.ts +0 -608
  231. package/src/plugins/CommandPlugin.d.ts +0 -8
  232. package/src/plugins/DialogPlugin.d.ts +0 -20
  233. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  234. package/src/plugins/Module.d.ts +0 -15
  235. package/src/plugins/Plugin.d.ts +0 -42
  236. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  237. package/src/plugins/dialog/audio.js +0 -559
  238. package/src/plugins/dialog/image.js +0 -1126
  239. package/src/plugins/dialog/link.js +0 -223
  240. package/src/plugins/dialog/math.js +0 -295
  241. package/src/plugins/dialog/mention.js +0 -242
  242. package/src/plugins/dialog/video.js +0 -979
  243. package/src/plugins/index.d.ts +0 -79
  244. package/src/plugins/modules/_anchor.js +0 -461
  245. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  246. package/src/plugins/modules/_colorPicker.js +0 -201
  247. package/src/plugins/modules/_notice.d.ts +0 -21
  248. package/src/plugins/modules/_notice.js +0 -72
  249. package/src/plugins/modules/_selectMenu.js +0 -119
  250. package/src/plugins/modules/component.d.ts +0 -25
  251. package/src/plugins/modules/component.js +0 -81
  252. package/src/plugins/modules/dialog.d.ts +0 -28
  253. package/src/plugins/modules/dialog.js +0 -175
  254. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  255. package/src/plugins/modules/fileBrowser.js +0 -374
  256. package/src/plugins/modules/fileManager.d.ts +0 -67
  257. package/src/plugins/modules/fileManager.js +0 -326
  258. package/src/plugins/modules/index.js +0 -9
  259. package/src/plugins/modules/resizing.d.ts +0 -154
  260. package/src/plugins/modules/resizing.js +0 -903
  261. package/src/plugins/submenu/align.d.ts +0 -5
  262. package/src/plugins/submenu/align.js +0 -160
  263. package/src/plugins/submenu/font.d.ts +0 -5
  264. package/src/plugins/submenu/font.js +0 -123
  265. package/src/plugins/submenu/fontColor.d.ts +0 -5
  266. package/src/plugins/submenu/fontColor.js +0 -101
  267. package/src/plugins/submenu/fontSize.d.ts +0 -5
  268. package/src/plugins/submenu/fontSize.js +0 -112
  269. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  270. package/src/plugins/submenu/formatBlock.js +0 -273
  271. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  272. package/src/plugins/submenu/hiliteColor.js +0 -102
  273. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  274. package/src/plugins/submenu/horizontalRule.js +0 -98
  275. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  276. package/src/plugins/submenu/lineHeight.js +0 -104
  277. package/src/plugins/submenu/list.d.ts +0 -5
  278. package/src/plugins/submenu/list.js +0 -456
  279. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  280. package/src/plugins/submenu/paragraphStyle.js +0 -135
  281. package/src/plugins/submenu/table.d.ts +0 -5
  282. package/src/plugins/submenu/table.js +0 -1431
  283. package/src/plugins/submenu/template.d.ts +0 -5
  284. package/src/plugins/submenu/template.js +0 -72
  285. package/src/plugins/submenu/textStyle.d.ts +0 -5
  286. package/src/plugins/submenu/textStyle.js +0 -167
  287. package/src/suneditor.d.ts +0 -9
  288. package/src/suneditor_build.js +0 -18
  289. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -0,0 +1,115 @@
1
+ import EditorInjector from '../../editorInjector';
2
+ import { domUtils } from '../../helper';
3
+
4
+ const DEFAULT_TYPE = 'decimal';
5
+
6
+ const List_numbered = function (editor) {
7
+ // plugin bisic properties
8
+ EditorInjector.call(this, editor);
9
+ this.title = this.lang.numberedList;
10
+ this.icon = 'list_numbered';
11
+ this.afterButton = domUtils.createElement(
12
+ 'button',
13
+ { class: 'se-btn se-tooltip se-sub-arrow-btn', 'data-command': List_numbered.key, 'data-type': 'dropdown' },
14
+ `${this.icons.arrow_down}<span class="se-tooltip-inner"><span class="se-tooltip-text">${this.lang.numberedList}</span></span>`
15
+ );
16
+
17
+ // create HTML
18
+ const menu = CreateHTML();
19
+
20
+ // members
21
+ this.listItems = menu.querySelectorAll('li button ol');
22
+
23
+ // init
24
+ this.menu.initDropdownTarget({ key: List_numbered.key, type: 'dropdown' }, menu);
25
+ };
26
+
27
+ List_numbered.key = 'list_numbered';
28
+ List_numbered.type = 'command';
29
+ List_numbered.className = 'se-icon-flip-rtl';
30
+ List_numbered.prototype = {
31
+ /**
32
+ * @override core
33
+ */
34
+ active(element, target) {
35
+ if (domUtils.isListCell(element) && /^OL$/i.test(element.parentElement.nodeName)) {
36
+ domUtils.addClass(target, 'active');
37
+ return true;
38
+ }
39
+
40
+ domUtils.removeClass(target, 'active');
41
+ return false;
42
+ },
43
+
44
+ /**
45
+ * @override dropdown
46
+ */
47
+ on() {
48
+ const list = this.listItems;
49
+ const el = this.format.getBlock(this.selection.getNode());
50
+ const type = el?.style ? el.style.listStyleType || DEFAULT_TYPE : '';
51
+
52
+ for (let i = 0, len = list.length, l; i < len; i++) {
53
+ l = list[i];
54
+ if (type === l.style.listStyleType) {
55
+ domUtils.addClass(l.parentElement, 'active');
56
+ } else {
57
+ domUtils.removeClass(l.parentElement, 'active');
58
+ }
59
+ }
60
+ },
61
+
62
+ /**
63
+ * @override core
64
+ * @param {Element|null} target Target command button
65
+ */
66
+ action(target) {
67
+ const el = this.format.getBlock(this.selection.getNode());
68
+ const type = target?.querySelector('ol')?.style.listStyleType || '';
69
+
70
+ if (domUtils.isList(el) && type) {
71
+ el.style.listStyleType = type;
72
+ } else {
73
+ const range = this.format.applyList(`ol:${type}`, null, false);
74
+ if (range) this.selection.setRange(range.sc, range.so, range.ec, range.eo);
75
+ }
76
+
77
+ this.menu.dropdownOff();
78
+ this.editor.focus();
79
+ this.history.push(false);
80
+ },
81
+
82
+ constructor: List_numbered
83
+ };
84
+
85
+ function CreateHTML() {
86
+ const html = /*html*/ `
87
+ <div class="se-list-inner">
88
+ <ul class="se-list-basic se-list-horizontal se-list-carrier">
89
+ ${_CreateLI(['decimal', 'upper-roman', 'lower-roman'])}
90
+ </ul>
91
+ <ul class="se-list-basic se-list-horizontal se-list-carrier">
92
+ ${_CreateLI(['lower-latin', 'upper-latin', 'lower-greek'])}
93
+ </ul>
94
+ </div>`;
95
+
96
+ return domUtils.createElement('DIV', { class: 'se-dropdown se-list-layer' }, html);
97
+ }
98
+
99
+ function _CreateLI(types) {
100
+ return types
101
+ .map((v) => {
102
+ return /*html*/ `
103
+ <li>
104
+ <button type="button" class="se-btn se-btn-list se-icon-flip-rtl" data-command="${v}" title="${v}" aria-label="${v}">
105
+ <ol style="list-style-type: ${v};">
106
+ <li></li><li></li><li></li>
107
+ </ol>
108
+ </button>
109
+ </li>
110
+ `;
111
+ })
112
+ .join('');
113
+ }
114
+
115
+ export default List_numbered;
@@ -0,0 +1,143 @@
1
+ import EditorInjector from '../../editorInjector';
2
+ import { domUtils } from '../../helper';
3
+
4
+ const Align = function (editor, pluginOptions) {
5
+ // plugin bisic properties
6
+ EditorInjector.call(this, editor);
7
+ this.title = this.lang.align;
8
+ this.icon = this.options.get('_rtl') ? 'align_right' : 'align_left';
9
+
10
+ // create HTML
11
+ const menu = CreateHTML(editor, pluginOptions.items);
12
+ const commandArea = (this._itemMenu = menu.querySelector('ul'));
13
+
14
+ // members
15
+ this.defaultDir = editor.options.get('_rtl') ? 'right' : 'left';
16
+ this.alignIcons = {
17
+ justify: editor.icons.align_justify,
18
+ left: editor.icons.align_left,
19
+ right: editor.icons.align_right,
20
+ center: editor.icons.align_center
21
+ };
22
+ this.alignList = commandArea.querySelectorAll('li button');
23
+
24
+ // init
25
+ this.menu.initDropdownTarget(Align, menu);
26
+ };
27
+
28
+ Align.key = 'align';
29
+ Align.type = 'dropdown';
30
+ Align.className = '';
31
+ Align.prototype = {
32
+ /**
33
+ * @override core
34
+ * @param {Node} element Selection node.
35
+ * @param {Element} target Target button.
36
+ * @returns {boolean}
37
+ */
38
+ active(element, target) {
39
+ const targetChild = target.firstElementChild;
40
+
41
+ if (!element) {
42
+ domUtils.changeElement(targetChild, this.alignIcons[this.defaultDir]);
43
+ target.removeAttribute('data-focus');
44
+ } else if (this.format.isLine(element)) {
45
+ const textAlign = element.style.textAlign;
46
+ if (textAlign) {
47
+ domUtils.changeElement(targetChild, this.alignIcons[textAlign] || this.alignIcons[this.defaultDir]);
48
+ target.setAttribute('data-focus', textAlign);
49
+ return true;
50
+ }
51
+ }
52
+
53
+ return false;
54
+ },
55
+
56
+ /**
57
+ * @override dropdown
58
+ */
59
+ on(target) {
60
+ const currentAlign = target.getAttribute('data-focus') || this.defaultDir;
61
+ if (!currentAlign) return;
62
+
63
+ const alignList = this.alignList;
64
+ for (let i = 0, len = alignList.length; i < len; i++) {
65
+ if (currentAlign === alignList[i].getAttribute('data-command')) {
66
+ domUtils.addClass(alignList[i], 'active');
67
+ } else {
68
+ domUtils.removeClass(alignList[i], 'active');
69
+ }
70
+ }
71
+ },
72
+
73
+ /**
74
+ * @override core
75
+ * @param {"rtl"|"ltr"} dir Direction
76
+ */
77
+ setDir(dir) {
78
+ const _dir = dir === 'rtl' ? 'right' : 'left';
79
+ if (this.defaultDir === _dir) return;
80
+
81
+ this.defaultDir = _dir;
82
+ const leftBtn = this._itemMenu.querySelector('[data-command="left"]');
83
+ const rightBtn = this._itemMenu.querySelector('[data-command="right"]');
84
+ if (leftBtn && rightBtn) {
85
+ const lp = leftBtn.parentElement;
86
+ const rp = rightBtn.parentElement;
87
+ lp.appendChild(rightBtn);
88
+ rp.appendChild(leftBtn);
89
+ }
90
+ },
91
+
92
+ /**
93
+ * @override core
94
+ * @param {Element} target Target command button
95
+ * @returns
96
+ */
97
+ action(target) {
98
+ const value = target.getAttribute('data-command');
99
+ if (!value) return;
100
+
101
+ const defaultDir = this.defaultDir;
102
+ const selectedFormsts = this.format.getLines();
103
+ for (let i = 0, len = selectedFormsts.length; i < len; i++) {
104
+ domUtils.setStyle(selectedFormsts[i], 'textAlign', value === defaultDir ? '' : value);
105
+ }
106
+
107
+ this.editor.effectNode = null;
108
+ this.menu.dropdownOff();
109
+ this.editor.focus();
110
+ this.history.push(false);
111
+ },
112
+
113
+ constructor: Align
114
+ };
115
+
116
+ function CreateHTML({ lang, icons, options }, items) {
117
+ const alignItems = Array.isArray(items) ? items : options.get('_rtl') ? ['right', 'center', 'left', 'justify'] : ['left', 'center', 'right', 'justify'];
118
+
119
+ let html = '';
120
+ for (let i = 0, item, text; i < alignItems.length; i++) {
121
+ item = alignItems[i];
122
+ text = lang['align' + item.charAt(0).toUpperCase() + item.slice(1)];
123
+ html += /*html*/ `
124
+ <li>
125
+ <button type="button" class="se-btn se-btn-list" data-command="${item}" title="${text}" aria-label="${text}">
126
+ <span class="se-list-icon">${icons['align_' + item]}</span>${text}
127
+ </button>
128
+ </li>`;
129
+ }
130
+
131
+ return domUtils.createElement(
132
+ 'div',
133
+ {
134
+ class: 'se-dropdown se-list-layer se-list-align'
135
+ },
136
+ /*html*/ `
137
+ <div class="se-list-inner">
138
+ <ul class="se-list-basic">${html}</ul>
139
+ </div>`
140
+ );
141
+ }
142
+
143
+ export default Align;
@@ -0,0 +1,73 @@
1
+ import EditorInjector from '../../editorInjector';
2
+ import ColorPicker from '../../modules/ColorPicker';
3
+ import { domUtils } from '../../helper';
4
+
5
+ const BackgroundColor = function (editor, pluginOptions) {
6
+ EditorInjector.call(this, editor);
7
+ // plugin basic properties
8
+ this.title = this.lang.backgroundColor;
9
+ this.icon = 'background_color';
10
+
11
+ // create HTML
12
+ const menu = CreateHTML();
13
+
14
+ // members
15
+ this.colorPicker = new ColorPicker(this, 'backgroundColor', {
16
+ colorList: pluginOptions.items,
17
+ splitNum: pluginOptions.splitNum,
18
+ disableHEXInput: pluginOptions.disableHEXInput,
19
+ hueSliderOptions: { controllerOptions: { parents: [menu], isOutsideForm: true } }
20
+ });
21
+
22
+ // itit
23
+ menu.appendChild(this.colorPicker.target);
24
+ this.menu.initDropdownTarget(BackgroundColor, menu);
25
+ };
26
+
27
+ BackgroundColor.key = 'backgroundColor';
28
+ BackgroundColor.type = 'dropdown-free';
29
+ BackgroundColor.className = '';
30
+ BackgroundColor.prototype = {
31
+ /**
32
+ * @override dropdown
33
+ */
34
+ on(target) {
35
+ this.colorPicker.init(this.selection.getNode(), target);
36
+ },
37
+
38
+ /**
39
+ * @Override dropdown
40
+ */
41
+ off() {
42
+ this.colorPicker.hueSliderClose();
43
+ },
44
+
45
+ /**
46
+ * @override ColorPicker
47
+ */
48
+ colorPickerAction(value) {
49
+ this.action(value);
50
+ },
51
+
52
+ /**
53
+ * @override core
54
+ */
55
+ action(value) {
56
+ if (value) {
57
+ const newNode = domUtils.createElement('SPAN', { style: 'background-color: ' + value + ';' });
58
+ this.format.applyTextStyle(newNode, ['background-color'], null, null);
59
+ } else {
60
+ this.format.applyTextStyle(null, ['background-color'], ['span'], true);
61
+ }
62
+
63
+ this.menu.dropdownOff();
64
+ },
65
+
66
+ constructor: BackgroundColor
67
+ };
68
+
69
+ function CreateHTML() {
70
+ return domUtils.createElement('DIV', { class: 'se-dropdown se-list-layer' }, null);
71
+ }
72
+
73
+ export default BackgroundColor;
@@ -0,0 +1,113 @@
1
+ import EditorInjector from '../../editorInjector';
2
+ import { domUtils } from '../../helper';
3
+
4
+ const Font = function (editor, pluginOptions) {
5
+ EditorInjector.call(this, editor);
6
+ // plugin basic properties
7
+ this.title = this.lang.font;
8
+ this.inner = '<span class="se-txt">' + this.lang.font + '</span>' + this.icons.arrow_down;
9
+
10
+ // create HTML
11
+ const fontList = pluginOptions.items || ['Arial', 'Comic Sans MS', 'Courier New', 'Impact', 'Georgia', 'tahoma', 'Trebuchet MS', 'Verdana'];
12
+ const menu = CreateHTML(editor, fontList);
13
+
14
+ // members
15
+ this.currentFont = '';
16
+ this.fontList = menu.querySelectorAll('ul li button');
17
+ this.fontArray = fontList;
18
+
19
+ // init
20
+ this.menu.initDropdownTarget(Font, menu);
21
+ };
22
+
23
+ Font.key = 'font';
24
+ Font.type = 'dropdown';
25
+ Font.className = 'se-btn-select se-btn-tool-font';
26
+ Font.prototype = {
27
+ /**
28
+ * @override core
29
+ */
30
+ active(element, target) {
31
+ const targetText = target.querySelector('.se-txt');
32
+ const tooltip = target.parentNode.querySelector('.se-tooltip-text');
33
+
34
+ if (!element) {
35
+ const font = this.status.hasFocus ? this.editor.frameContext.get('wwComputedStyle').fontFamily : this.lang.font;
36
+ domUtils.changeTxt(targetText, font);
37
+ domUtils.changeTxt(tooltip, this.status.hasFocus ? this.lang.font + (font ? ' (' + font + ')' : '') : font);
38
+ } else if (element?.style.fontFamily.length > 0) {
39
+ const selectFont = element.style.fontFamily.replace(/["']/g, '');
40
+ domUtils.changeTxt(targetText, selectFont);
41
+ domUtils.changeTxt(tooltip, this.lang.font + ' (' + selectFont + ')');
42
+ return true;
43
+ }
44
+
45
+ return false;
46
+ },
47
+
48
+ /**
49
+ * @override dropdown
50
+ */
51
+ on(target) {
52
+ const fontList = this.fontList;
53
+ const currentFont = target.querySelector('.se-txt').textContent;
54
+
55
+ if (currentFont !== this.currentFont) {
56
+ for (let i = 0, len = fontList.length; i < len; i++) {
57
+ if (currentFont === (fontList[i].getAttribute('data-command') || '').replace(/'|"/g, '')) {
58
+ domUtils.addClass(fontList[i], 'active');
59
+ } else {
60
+ domUtils.removeClass(fontList[i], 'active');
61
+ }
62
+ }
63
+
64
+ this.currentFont = currentFont;
65
+ }
66
+ },
67
+
68
+ /**
69
+ * @override core
70
+ * @param {Element} target Target command button
71
+ */
72
+ action(target) {
73
+ let value = target.getAttribute('data-command');
74
+ if (value) {
75
+ if (/[\s\d\W]/.test(value) && !/^['"].*['"]$/.test(value)) {
76
+ value = `"${value}"`;
77
+ }
78
+ const newNode = domUtils.createElement('SPAN', { style: 'font-family: ' + value + ';' });
79
+ this.format.applyTextStyle(newNode, ['font-family'], null, null);
80
+ } else {
81
+ this.format.applyTextStyle(null, ['font-family'], ['span'], true);
82
+ }
83
+
84
+ this.menu.dropdownOff();
85
+ },
86
+
87
+ constructor: Font
88
+ };
89
+
90
+ function CreateHTML({ lang }, fontList) {
91
+ let list = /*html*/ `
92
+ <div class="se-list-inner">
93
+ <ul class="se-list-basic">
94
+ <li>
95
+ <button type="button" class="se-btn se-btn-list default_value" title="${lang.default}" aria-label="${lang.default}">(${lang.default})</button>
96
+ </li>`;
97
+
98
+ for (let i = 0, len = fontList.length, font, text; i < len; i++) {
99
+ font = fontList[i];
100
+ text = font.split(',')[0];
101
+ list += /*html*/ `
102
+ <li>
103
+ <button type="button" class="se-btn se-btn-list" data-command="${font}" data-txt="${text}" title="${text}" aria-label="${text}" style="font-family:${font};">${text}</button>
104
+ </li>`;
105
+ }
106
+ list += /*html*/ `
107
+ </ul>
108
+ </div>`;
109
+
110
+ return domUtils.createElement('DIV', { class: 'se-dropdown se-list-layer se-list-font-family' }, list);
111
+ }
112
+
113
+ export default Font;
@@ -0,0 +1,73 @@
1
+ import EditorInjector from '../../editorInjector';
2
+ import ColorPicker from '../../modules/ColorPicker';
3
+ import { domUtils } from '../../helper';
4
+
5
+ const FontColor = function (editor, pluginOptions) {
6
+ EditorInjector.call(this, editor);
7
+ // plugin basic properties
8
+ this.title = this.lang.fontColor;
9
+ this.icon = 'font_color';
10
+
11
+ // create HTML
12
+ const menu = CreateHTML();
13
+
14
+ // members
15
+ this.colorPicker = new ColorPicker(this, 'color', {
16
+ colorList: pluginOptions.items,
17
+ splitNum: pluginOptions.splitNum,
18
+ disableHEXInput: pluginOptions.disableHEXInput,
19
+ hueSliderOptions: { controllerOptions: { parents: [menu], isOutsideForm: true } }
20
+ });
21
+
22
+ // itit
23
+ menu.appendChild(this.colorPicker.target);
24
+ this.menu.initDropdownTarget(FontColor, menu);
25
+ };
26
+
27
+ FontColor.key = 'fontColor';
28
+ FontColor.type = 'dropdown-free';
29
+ FontColor.className = '';
30
+ FontColor.prototype = {
31
+ /**
32
+ * @override dropdown
33
+ */
34
+ on(target) {
35
+ this.colorPicker.init(this.selection.getNode(), target);
36
+ },
37
+
38
+ /**
39
+ * @Override dropdown
40
+ */
41
+ onDropdownClose() {
42
+ this.colorPicker.hueSliderClose();
43
+ },
44
+
45
+ /**
46
+ * @override ColorPicker
47
+ */
48
+ colorPickerAction(value) {
49
+ this.action(value);
50
+ },
51
+
52
+ /**
53
+ * @override core
54
+ */
55
+ action(value) {
56
+ if (value) {
57
+ const newNode = domUtils.createElement('SPAN', { style: 'color: ' + value + ';' });
58
+ this.format.applyTextStyle(newNode, ['color'], null, null);
59
+ } else {
60
+ this.format.applyTextStyle(null, ['color'], ['span'], true);
61
+ }
62
+
63
+ this.menu.dropdownOff();
64
+ },
65
+
66
+ constructor: FontColor
67
+ };
68
+
69
+ function CreateHTML() {
70
+ return domUtils.createElement('DIV', { class: 'se-dropdown se-list-layer' }, null);
71
+ }
72
+
73
+ export default FontColor;
@@ -0,0 +1,141 @@
1
+ import EditorInjector from '../../editorInjector';
2
+ import { domUtils } from '../../helper';
3
+
4
+ const FormatBlock = function (editor, pluginOptions) {
5
+ EditorInjector.call(this, editor);
6
+ // plugin basic properties
7
+ this.title = this.lang.formats;
8
+ this.inner = '<span class="se-txt">' + this.lang.formats + '</span>' + this.icons.arrow_down;
9
+
10
+ // create HTML
11
+ const menu = CreateHTML(editor, pluginOptions.items);
12
+
13
+ // members
14
+ this.formatList = menu.querySelectorAll('li button');
15
+ this.currentFormat = '';
16
+
17
+ // init
18
+ this.menu.initDropdownTarget(FormatBlock, menu);
19
+ };
20
+
21
+ FormatBlock.key = 'formatBlock';
22
+ FormatBlock.type = 'dropdown';
23
+ FormatBlock.className = 'se-btn-select se-btn-tool-format';
24
+ FormatBlock.prototype = {
25
+ /**
26
+ * @override core
27
+ */
28
+ active(element, target) {
29
+ let formatTitle = this.lang.formats;
30
+ const targetText = target.querySelector('.se-txt');
31
+
32
+ if (!element) {
33
+ domUtils.changeTxt(targetText, formatTitle);
34
+ } else if (this.format.isLine(element)) {
35
+ const formatList = this.formatList;
36
+ const nodeName = element.nodeName.toLowerCase();
37
+ const className = (element.className.match(/(\s|^)__se__format__[^\s]+/) || [''])[0].trim();
38
+
39
+ for (let i = 0, len = formatList.length, f; i < len; i++) {
40
+ f = formatList[i];
41
+ if (nodeName === f.getAttribute('data-value') && className === f.getAttribute('data-class')) {
42
+ formatTitle = f.title;
43
+ break;
44
+ }
45
+ }
46
+
47
+ domUtils.changeTxt(targetText, formatTitle);
48
+ targetText.setAttribute('data-value', nodeName);
49
+ targetText.setAttribute('data-class', className);
50
+
51
+ return true;
52
+ }
53
+
54
+ return false;
55
+ },
56
+
57
+ /**
58
+ * @override dropdown
59
+ */
60
+ on(target) {
61
+ const formatList = this.formatList;
62
+ const targetText = target.querySelector('.se-txt');
63
+ const currentFormat = (targetText.getAttribute('data-value') || '') + (targetText.getAttribute('data-class') || '');
64
+
65
+ if (currentFormat !== this.currentFormat) {
66
+ for (let i = 0, len = formatList.length, f; i < len; i++) {
67
+ f = formatList[i];
68
+ if (currentFormat === f.getAttribute('data-value') + f.getAttribute('data-class')) {
69
+ domUtils.addClass(f, 'active');
70
+ } else {
71
+ domUtils.removeClass(f, 'active');
72
+ }
73
+ }
74
+
75
+ this.currentFormat = currentFormat;
76
+ }
77
+ },
78
+
79
+ /**
80
+ * @override core
81
+ * @param {Element} target Target command button
82
+ */
83
+ action(target) {
84
+ // "line"|"br-line"|"block"
85
+ const command = target.getAttribute('data-command');
86
+ const tag = target.firstElementChild;
87
+ if (command === 'block') {
88
+ this.format.applyBlock(tag);
89
+ } else if (command === 'br-line') {
90
+ this.format.setBrLine(tag);
91
+ } else {
92
+ this.format.setLine(tag);
93
+ }
94
+
95
+ this.menu.dropdownOff();
96
+ },
97
+
98
+ constructor: FormatBlock
99
+ };
100
+
101
+ function CreateHTML({ lang }, items) {
102
+ const defaultFormats = ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
103
+ const formatList = !items || items.length === 0 ? defaultFormats : items;
104
+
105
+ let list = /*html*/ `
106
+ <div class="se-list-inner">
107
+ <ul class="se-list-basic">`;
108
+
109
+ for (let i = 0, len = formatList.length, format, tagName, command, name, h, attrs, className; i < len; i++) {
110
+ format = formatList[i];
111
+
112
+ if (typeof format === 'string' && defaultFormats.includes(format)) {
113
+ tagName = format.toLowerCase();
114
+ command = tagName === 'blockquote' ? 'block' : tagName === 'pre' ? 'br-line' : 'line';
115
+ h = /^h/.test(tagName) ? tagName.match(/\d+/)[0] : '';
116
+ name = lang['tag_' + (h ? 'h' : tagName)] + h;
117
+ className = '';
118
+ attrs = '';
119
+ } else {
120
+ tagName = format.tag.toLowerCase();
121
+ command = format.command;
122
+ name = format.name || tagName;
123
+ className = format.class;
124
+ attrs = className ? ' class="' + className + '"' : '';
125
+ }
126
+
127
+ list += /*html*/ `
128
+ <li>
129
+ <button type="button" class="se-btn se-btn-list" data-command="${command}" data-value="${tagName}" data-class="${className}" title="${name}" aria-label="${name}">
130
+ <${tagName}${attrs}>${name}</${tagName}>
131
+ </button>
132
+ </li>`;
133
+ }
134
+ list += /*html*/ `
135
+ </ul>
136
+ </div>`;
137
+
138
+ return domUtils.createElement('DIV', { class: 'se-dropdown se-list-layer se-list-format' }, list);
139
+ }
140
+
141
+ export default FormatBlock;