suneditor 2.44.12 → 2.45.0

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 (130) hide show
  1. package/LICENSE.txt +20 -20
  2. package/README.md +1588 -1585
  3. package/dist/suneditor.min.js +2 -2
  4. package/package.json +71 -71
  5. package/src/assets/css/suneditor-contents.css +561 -561
  6. package/src/assets/css/suneditor.css +0 -0
  7. package/src/assets/defaultIcons.js +103 -103
  8. package/src/lang/Lang.d.ts +143 -143
  9. package/src/lang/ckb.d.ts +4 -4
  10. package/src/lang/ckb.js +187 -187
  11. package/src/lang/da.d.ts +4 -4
  12. package/src/lang/da.js +191 -191
  13. package/src/lang/de.d.ts +4 -4
  14. package/src/lang/de.js +188 -188
  15. package/src/lang/en.d.ts +4 -4
  16. package/src/lang/en.js +187 -187
  17. package/src/lang/es.d.ts +4 -4
  18. package/src/lang/es.js +187 -187
  19. package/src/lang/fr.d.ts +4 -4
  20. package/src/lang/fr.js +188 -188
  21. package/src/lang/he.d.ts +4 -4
  22. package/src/lang/he.js +188 -188
  23. package/src/lang/index.d.ts +22 -22
  24. package/src/lang/index.js +25 -25
  25. package/src/lang/it.d.ts +4 -4
  26. package/src/lang/it.js +188 -188
  27. package/src/lang/ja.d.ts +4 -4
  28. package/src/lang/ja.js +187 -187
  29. package/src/lang/ko.d.ts +4 -4
  30. package/src/lang/ko.js +187 -187
  31. package/src/lang/lv.d.ts +4 -4
  32. package/src/lang/lv.js +187 -187
  33. package/src/lang/nl.d.ts +4 -4
  34. package/src/lang/nl.js +187 -187
  35. package/src/lang/pl.d.ts +4 -4
  36. package/src/lang/pl.js +187 -187
  37. package/src/lang/pt_br.d.ts +4 -4
  38. package/src/lang/pt_br.js +189 -189
  39. package/src/lang/ro.d.ts +4 -4
  40. package/src/lang/ro.js +187 -187
  41. package/src/lang/ru.d.ts +4 -4
  42. package/src/lang/ru.js +187 -187
  43. package/src/lang/se.d.ts +4 -4
  44. package/src/lang/se.js +191 -191
  45. package/src/lang/ua.d.ts +5 -5
  46. package/src/lang/ua.js +188 -188
  47. package/src/lang/ur.d.ts +4 -4
  48. package/src/lang/ur.js +187 -187
  49. package/src/lang/zh_cn.d.ts +4 -4
  50. package/src/lang/zh_cn.js +187 -187
  51. package/src/lib/constructor.js +3 -1
  52. package/src/lib/context.d.ts +42 -42
  53. package/src/lib/context.js +0 -0
  54. package/src/lib/core.d.ts +1101 -1101
  55. package/src/lib/core.js +96 -51
  56. package/src/lib/history.d.ts +48 -48
  57. package/src/lib/history.js +218 -218
  58. package/src/lib/util.d.ts +677 -677
  59. package/src/lib/util.js +39 -11
  60. package/src/options.d.ts +608 -608
  61. package/src/plugins/CommandPlugin.d.ts +7 -7
  62. package/src/plugins/DialogPlugin.d.ts +19 -19
  63. package/src/plugins/FileBrowserPlugin.d.ts +29 -29
  64. package/src/plugins/Module.d.ts +14 -14
  65. package/src/plugins/Plugin.d.ts +41 -41
  66. package/src/plugins/SubmenuPlugin.d.ts +7 -7
  67. package/src/plugins/command/blockquote.d.ts +4 -4
  68. package/src/plugins/command/blockquote.js +46 -46
  69. package/src/plugins/dialog/audio.d.ts +4 -4
  70. package/src/plugins/dialog/audio.js +556 -556
  71. package/src/plugins/dialog/image.d.ts +4 -4
  72. package/src/plugins/dialog/image.js +1115 -1115
  73. package/src/plugins/dialog/link.d.ts +4 -4
  74. package/src/plugins/dialog/link.js +223 -223
  75. package/src/plugins/dialog/math.d.ts +4 -4
  76. package/src/plugins/dialog/math.js +295 -295
  77. package/src/plugins/dialog/mention.d.ts +5 -5
  78. package/src/plugins/dialog/mention.js +242 -242
  79. package/src/plugins/dialog/video.d.ts +4 -4
  80. package/src/plugins/dialog/video.js +977 -977
  81. package/src/plugins/fileBrowser/imageGallery.d.ts +4 -4
  82. package/src/plugins/fileBrowser/imageGallery.js +63 -63
  83. package/src/plugins/index.d.ts +79 -79
  84. package/src/plugins/index.js +32 -32
  85. package/src/plugins/modules/_anchor.js +461 -461
  86. package/src/plugins/modules/_colorPicker.d.ts +59 -59
  87. package/src/plugins/modules/_colorPicker.js +0 -0
  88. package/src/plugins/modules/_notice.d.ts +20 -20
  89. package/src/plugins/modules/_notice.js +72 -72
  90. package/src/plugins/modules/_selectMenu.js +118 -118
  91. package/src/plugins/modules/component.d.ts +24 -24
  92. package/src/plugins/modules/component.js +80 -80
  93. package/src/plugins/modules/dialog.d.ts +27 -27
  94. package/src/plugins/modules/dialog.js +174 -174
  95. package/src/plugins/modules/fileBrowser.d.ts +41 -41
  96. package/src/plugins/modules/fileBrowser.js +373 -373
  97. package/src/plugins/modules/fileManager.d.ts +66 -66
  98. package/src/plugins/modules/fileManager.js +325 -325
  99. package/src/plugins/modules/index.d.ts +10 -10
  100. package/src/plugins/modules/index.js +8 -8
  101. package/src/plugins/modules/resizing.d.ts +153 -153
  102. package/src/plugins/modules/resizing.js +895 -895
  103. package/src/plugins/submenu/align.d.ts +4 -4
  104. package/src/plugins/submenu/align.js +160 -160
  105. package/src/plugins/submenu/font.d.ts +4 -4
  106. package/src/plugins/submenu/font.js +120 -120
  107. package/src/plugins/submenu/fontColor.d.ts +4 -4
  108. package/src/plugins/submenu/fontColor.js +0 -0
  109. package/src/plugins/submenu/fontSize.d.ts +4 -4
  110. package/src/plugins/submenu/fontSize.js +112 -112
  111. package/src/plugins/submenu/formatBlock.d.ts +4 -4
  112. package/src/plugins/submenu/formatBlock.js +273 -273
  113. package/src/plugins/submenu/hiliteColor.d.ts +4 -4
  114. package/src/plugins/submenu/hiliteColor.js +0 -0
  115. package/src/plugins/submenu/horizontalRule.d.ts +4 -4
  116. package/src/plugins/submenu/horizontalRule.js +98 -98
  117. package/src/plugins/submenu/lineHeight.d.ts +4 -4
  118. package/src/plugins/submenu/lineHeight.js +104 -104
  119. package/src/plugins/submenu/list.d.ts +4 -4
  120. package/src/plugins/submenu/list.js +456 -456
  121. package/src/plugins/submenu/paragraphStyle.d.ts +4 -4
  122. package/src/plugins/submenu/paragraphStyle.js +135 -135
  123. package/src/plugins/submenu/table.d.ts +4 -4
  124. package/src/plugins/submenu/template.d.ts +4 -4
  125. package/src/plugins/submenu/template.js +71 -71
  126. package/src/plugins/submenu/textStyle.d.ts +4 -4
  127. package/src/plugins/submenu/textStyle.js +167 -167
  128. package/src/suneditor.d.ts +9 -9
  129. package/src/suneditor.js +75 -75
  130. package/src/suneditor_build.js +17 -17
@@ -1,295 +1,295 @@
1
- 'use strict';
2
-
3
- import dialog from '../modules/dialog';
4
-
5
- const KATEX_WEBSITE = "https://katex.org/docs/supported.html";
6
-
7
- export default {
8
- name: 'math',
9
- display: 'dialog',
10
- add: function (core) {
11
- core.addModule([dialog]);
12
-
13
- const context = core.context;
14
- context.math = {
15
- focusElement: null, // @Override dialog // This element has focus when the dialog is opened.
16
- previewElement: null,
17
- fontSizeElement: null,
18
- defaultFontSize: '',
19
- _mathExp: null
20
- };
21
-
22
- /** math dialog */
23
- let math_dialog = this.setDialog(core);
24
- context.math.modal = math_dialog;
25
- context.math.focusElement = math_dialog.querySelector('.se-math-exp');
26
- context.math.previewElement = math_dialog.querySelector('.se-math-preview');
27
- context.math.fontSizeElement = math_dialog.querySelector('.se-math-size');
28
- context.math.focusElement.addEventListener(core.util.isIE ? 'textinput' : 'input', this._renderMathExp.bind(core, context.math), false);
29
- context.math.fontSizeElement.addEventListener('change', function (e) { this.fontSize = e.target.value; }.bind(context.math.previewElement.style), false);
30
-
31
- /** math controller */
32
- let math_controller = this.setController_MathButton(core);
33
- context.math.mathController = math_controller;
34
- context.math._mathExp = null;
35
-
36
- /** add event listeners */
37
- math_dialog.querySelector('form').addEventListener('submit', this.submit.bind(core), false);
38
- math_controller.addEventListener('click', this.onClick_mathController.bind(core));
39
- context.math.previewElement.style.fontSize = context.math.defaultFontSize;
40
-
41
- /** append html */
42
- context.dialog.modal.appendChild(math_dialog);
43
- context.element.relative.appendChild(math_controller);
44
-
45
- /** empty memory */
46
- math_dialog = null, math_controller = null;
47
- },
48
-
49
- /** dialog */
50
- setDialog: function (core) {
51
- const lang = core.lang;
52
- const dialog = core.util.createElement('DIV');
53
- const fontSize = core.options.mathFontSize;
54
- let defaultFontSize = fontSize[0].value;
55
-
56
- dialog.className = 'se-dialog-content';
57
- dialog.style.display = 'none';
58
- let html = '' +
59
- '<form>' +
60
- '<div class="se-dialog-header">' +
61
- '<button type="button" data-command="close" class="se-btn se-dialog-close" title="' + lang.dialogBox.close + '" aria-label="' + lang.dialogBox.close + '">' +
62
- core.icons.cancel +
63
- '</button>' +
64
- '<span class="se-modal-title">' + lang.dialogBox.mathBox.title + '</span>' +
65
- '</div>' +
66
- '<div class="se-dialog-body">' +
67
- '<div class="se-dialog-form">' +
68
- '<label>' + lang.dialogBox.mathBox.inputLabel + ' (<a href="' + KATEX_WEBSITE + '" target="_blank">KaTeX</a>)</label>' +
69
- '<textarea class="se-input-form se-math-exp" type="text"></textarea>' +
70
- '</div>' +
71
- '<div class="se-dialog-form">' +
72
- '<label>' + lang.dialogBox.mathBox.fontSizeLabel + '</label>' +
73
- '<select class="se-input-select se-math-size">';
74
- for (let i = 0, len = fontSize.length, f; i < len; i++) {
75
- f = fontSize[i];
76
- if (f.default) defaultFontSize = f.value;
77
- html += '<option value="' + f.value + '"' + (f.default ? ' selected' : '') + '>' + f.text + '</option>';
78
- }
79
- html += '</select>' +
80
- '</div>' +
81
- '<div class="se-dialog-form">' +
82
- '<label>' + lang.dialogBox.mathBox.previewLabel + '</label>' +
83
- '<p class="se-math-preview"></p>' +
84
- '</div>' +
85
- '</div>' +
86
- '<div class="se-dialog-footer">' +
87
- '<button type="submit" class="se-btn-primary" title="' + lang.dialogBox.submitButton + '" aria-label="' + lang.dialogBox.submitButton + '"><span>' + lang.dialogBox.submitButton + '</span></button>' +
88
- '</div>' +
89
- '</form>';
90
-
91
- core.context.math.defaultFontSize = defaultFontSize;
92
- dialog.innerHTML = html;
93
- return dialog;
94
- },
95
-
96
- /** modify controller button */
97
- setController_MathButton: function (core) {
98
- const lang = core.lang;
99
- const math_btn = core.util.createElement('DIV');
100
-
101
- math_btn.className = 'se-controller se-controller-link';
102
- math_btn.innerHTML = '' +
103
- '<div class="se-arrow se-arrow-up"></div>' +
104
- '<div class="link-content">' +
105
- '<div class="se-btn-group">' +
106
- '<button type="button" data-command="update" tabindex="-1" class="se-btn se-tooltip">' +
107
- core.icons.edit +
108
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.edit + '</span></span>' +
109
- '</button>' +
110
- '<button type="button" data-command="delete" tabindex="-1" class="se-btn se-tooltip">' +
111
- core.icons.delete +
112
- '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.remove + '</span></span>' +
113
- '</button>' +
114
- '</div>' +
115
- '</div>' +
116
- '';
117
-
118
- return math_btn;
119
- },
120
-
121
- /**
122
- * @Required @Override dialog
123
- */
124
- open: function () {
125
- this.plugins.dialog.open.call(this, 'math', 'math' === this.currentControllerName);
126
- },
127
-
128
- /**
129
- * @Override core - managedTagsInfo
130
- */
131
- managedTags: function () {
132
- return {
133
- className: 'katex',
134
- method: function (element) {
135
- if (!element.getAttribute('data-exp') || !this.options.katex) return;
136
- const dom = this._d.createRange().createContextualFragment(this.plugins.math._renderer.call(this, this.util.HTMLDecoder(element.getAttribute('data-exp'))));
137
- element.innerHTML = dom.querySelector('.katex').innerHTML;
138
- element.setAttribute('contenteditable', false);
139
- }
140
- };
141
- },
142
-
143
- _renderer: function (exp) {
144
- let result = '';
145
- try {
146
- this.util.removeClass(this.context.math.focusElement, 'se-error');
147
- result = this.options.katex.src.renderToString(exp, {throwOnError: true, displayMode: true});
148
- } catch(error) {
149
- this.util.addClass(this.context.math.focusElement, 'se-error');
150
- result = '<span class="se-math-katex-error">Katex syntax error. (Refer <a href="' + KATEX_WEBSITE + '" target="_blank">KaTeX</a>)</span>';
151
- console.warn('[SUNEDITOR.math.Katex.error] ', error);
152
- }
153
- return result;
154
- },
155
-
156
- _renderMathExp: function (contextMath, e) {
157
- contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, e.target.value);
158
- },
159
-
160
- submit: function (e) {
161
- this.showLoading();
162
-
163
- e.preventDefault();
164
- e.stopPropagation();
165
-
166
- const submitAction = function () {
167
- if (this.context.math.focusElement.value.trim().length === 0) return false;
168
-
169
- const contextMath = this.context.math;
170
- const mathExp = contextMath.focusElement.value;
171
- const katexEl = contextMath.previewElement.querySelector('.katex');
172
-
173
- if (!katexEl) return false;
174
- katexEl.className = '__se__katex ' + katexEl.className;
175
- katexEl.setAttribute('contenteditable', false);
176
- katexEl.setAttribute('data-exp', this.util.HTMLEncoder(mathExp));
177
- katexEl.setAttribute('data-font-size', contextMath.fontSizeElement.value);
178
- katexEl.style.fontSize = contextMath.fontSizeElement.value;
179
-
180
- if (!this.context.dialog.updateModal) {
181
- const selectedFormats = this.getSelectedElements();
182
-
183
- if (selectedFormats.length > 1) {
184
- const oFormat = this.util.createElement(selectedFormats[0].nodeName);
185
- oFormat.appendChild(katexEl);
186
- if (!this.insertNode(oFormat, null, true)) return false;
187
- } else {
188
- if (!this.insertNode(katexEl, null, true)) return false;
189
- }
190
-
191
- const empty = this.util.createTextNode(this.util.zeroWidthSpace);
192
- katexEl.parentNode.insertBefore(empty, katexEl.nextSibling);
193
- this.setRange(katexEl, 0, katexEl, 1);
194
- } else {
195
- const containerEl = this.util.getParentElement(contextMath._mathExp, '.katex');
196
- containerEl.parentNode.replaceChild(katexEl, containerEl);
197
- this.setRange(katexEl, 0, katexEl, 1);
198
- }
199
-
200
- contextMath.focusElement.value = '';
201
- contextMath.fontSizeElement.value = '1em';
202
- contextMath.previewElement.style.fontSize = '1em';
203
- contextMath.previewElement.innerHTML = '';
204
-
205
- return true;
206
- }.bind(this);
207
-
208
- try {
209
- if (submitAction()) {
210
- this.plugins.dialog.close.call(this);
211
- // history stack
212
- this.history.push(false);
213
- }
214
- } catch (e) {
215
- this.plugins.dialog.close.call(this);
216
- } finally {
217
- this.closeLoading();
218
- }
219
-
220
- return false;
221
- },
222
-
223
- active: function (element) {
224
- if (!element) {
225
- if (this.controllerArray.indexOf(this.context.math.mathController) > -1) {
226
- this.controllersOff();
227
- }
228
- } else if (element.getAttribute('data-exp')) {
229
- if (this.controllerArray.indexOf(this.context.math.mathController) < 0) {
230
- this.setRange(element, 0, element, 1);
231
- this.plugins.math.call_controller.call(this, element);
232
- }
233
- return true;
234
- }
235
-
236
- return false;
237
- },
238
-
239
- on: function (update) {
240
- if (!update) {
241
- this.plugins.math.init.call(this);
242
- } else {
243
- const contextMath = this.context.math;
244
- if (contextMath._mathExp) {
245
- const exp = this.util.HTMLDecoder(contextMath._mathExp.getAttribute('data-exp'));
246
- const fontSize = contextMath._mathExp.getAttribute('data-font-size') || '1em';
247
- this.context.dialog.updateModal = true;
248
- contextMath.focusElement.value = exp;
249
- contextMath.fontSizeElement.value = fontSize;
250
- contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, exp);
251
- contextMath.previewElement.style.fontSize = fontSize;
252
- }
253
- }
254
- },
255
-
256
- call_controller: function (mathTag) {
257
- this.context.math._mathExp = mathTag;
258
- const mathBtn = this.context.math.mathController;
259
-
260
- this.setControllerPosition(mathBtn, mathTag, 'bottom', {left: 0, top: 0});
261
- this.controllersOn(mathBtn, mathTag, 'math');
262
- },
263
-
264
- onClick_mathController: function (e) {
265
- e.stopPropagation();
266
-
267
- const command = e.target.getAttribute('data-command') || e.target.parentNode.getAttribute('data-command');
268
- if (!command) return;
269
-
270
- e.preventDefault();
271
-
272
- if (/update/.test(command)) {
273
- this.context.math.focusElement.value = this.util.HTMLDecoder(this.context.math._mathExp.getAttribute('data-exp'));
274
- this.plugins.dialog.open.call(this, 'math', true);
275
- } else {
276
- /** delete */
277
- this.util.removeItem(this.context.math._mathExp);
278
- this.context.math._mathExp = null;
279
- this.focus();
280
-
281
- // history stack
282
- this.history.push(false);
283
- }
284
-
285
- this.controllersOff();
286
- },
287
-
288
- init: function () {
289
- const contextMath = this.context.math;
290
- contextMath.mathController.style.display = 'none';
291
- contextMath._mathExp = null;
292
- contextMath.focusElement.value = '';
293
- contextMath.previewElement.innerHTML = '';
294
- }
295
- };
1
+ 'use strict';
2
+
3
+ import dialog from '../modules/dialog';
4
+
5
+ const KATEX_WEBSITE = "https://katex.org/docs/supported.html";
6
+
7
+ export default {
8
+ name: 'math',
9
+ display: 'dialog',
10
+ add: function (core) {
11
+ core.addModule([dialog]);
12
+
13
+ const context = core.context;
14
+ context.math = {
15
+ focusElement: null, // @Override dialog // This element has focus when the dialog is opened.
16
+ previewElement: null,
17
+ fontSizeElement: null,
18
+ defaultFontSize: '',
19
+ _mathExp: null
20
+ };
21
+
22
+ /** math dialog */
23
+ let math_dialog = this.setDialog(core);
24
+ context.math.modal = math_dialog;
25
+ context.math.focusElement = math_dialog.querySelector('.se-math-exp');
26
+ context.math.previewElement = math_dialog.querySelector('.se-math-preview');
27
+ context.math.fontSizeElement = math_dialog.querySelector('.se-math-size');
28
+ context.math.focusElement.addEventListener(core.util.isIE ? 'textinput' : 'input', this._renderMathExp.bind(core, context.math), false);
29
+ context.math.fontSizeElement.addEventListener('change', function (e) { this.fontSize = e.target.value; }.bind(context.math.previewElement.style), false);
30
+
31
+ /** math controller */
32
+ let math_controller = this.setController_MathButton(core);
33
+ context.math.mathController = math_controller;
34
+ context.math._mathExp = null;
35
+
36
+ /** add event listeners */
37
+ math_dialog.querySelector('form').addEventListener('submit', this.submit.bind(core), false);
38
+ math_controller.addEventListener('click', this.onClick_mathController.bind(core));
39
+ context.math.previewElement.style.fontSize = context.math.defaultFontSize;
40
+
41
+ /** append html */
42
+ context.dialog.modal.appendChild(math_dialog);
43
+ context.element.relative.appendChild(math_controller);
44
+
45
+ /** empty memory */
46
+ math_dialog = null, math_controller = null;
47
+ },
48
+
49
+ /** dialog */
50
+ setDialog: function (core) {
51
+ const lang = core.lang;
52
+ const dialog = core.util.createElement('DIV');
53
+ const fontSize = core.options.mathFontSize;
54
+ let defaultFontSize = fontSize[0].value;
55
+
56
+ dialog.className = 'se-dialog-content';
57
+ dialog.style.display = 'none';
58
+ let html = '' +
59
+ '<form>' +
60
+ '<div class="se-dialog-header">' +
61
+ '<button type="button" data-command="close" class="se-btn se-dialog-close" title="' + lang.dialogBox.close + '" aria-label="' + lang.dialogBox.close + '">' +
62
+ core.icons.cancel +
63
+ '</button>' +
64
+ '<span class="se-modal-title">' + lang.dialogBox.mathBox.title + '</span>' +
65
+ '</div>' +
66
+ '<div class="se-dialog-body">' +
67
+ '<div class="se-dialog-form">' +
68
+ '<label>' + lang.dialogBox.mathBox.inputLabel + ' (<a href="' + KATEX_WEBSITE + '" target="_blank">KaTeX</a>)</label>' +
69
+ '<textarea class="se-input-form se-math-exp" type="text"></textarea>' +
70
+ '</div>' +
71
+ '<div class="se-dialog-form">' +
72
+ '<label>' + lang.dialogBox.mathBox.fontSizeLabel + '</label>' +
73
+ '<select class="se-input-select se-math-size">';
74
+ for (let i = 0, len = fontSize.length, f; i < len; i++) {
75
+ f = fontSize[i];
76
+ if (f.default) defaultFontSize = f.value;
77
+ html += '<option value="' + f.value + '"' + (f.default ? ' selected' : '') + '>' + f.text + '</option>';
78
+ }
79
+ html += '</select>' +
80
+ '</div>' +
81
+ '<div class="se-dialog-form">' +
82
+ '<label>' + lang.dialogBox.mathBox.previewLabel + '</label>' +
83
+ '<p class="se-math-preview"></p>' +
84
+ '</div>' +
85
+ '</div>' +
86
+ '<div class="se-dialog-footer">' +
87
+ '<button type="submit" class="se-btn-primary" title="' + lang.dialogBox.submitButton + '" aria-label="' + lang.dialogBox.submitButton + '"><span>' + lang.dialogBox.submitButton + '</span></button>' +
88
+ '</div>' +
89
+ '</form>';
90
+
91
+ core.context.math.defaultFontSize = defaultFontSize;
92
+ dialog.innerHTML = html;
93
+ return dialog;
94
+ },
95
+
96
+ /** modify controller button */
97
+ setController_MathButton: function (core) {
98
+ const lang = core.lang;
99
+ const math_btn = core.util.createElement('DIV');
100
+
101
+ math_btn.className = 'se-controller se-controller-link';
102
+ math_btn.innerHTML = '' +
103
+ '<div class="se-arrow se-arrow-up"></div>' +
104
+ '<div class="link-content">' +
105
+ '<div class="se-btn-group">' +
106
+ '<button type="button" data-command="update" tabindex="-1" class="se-btn se-tooltip">' +
107
+ core.icons.edit +
108
+ '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.edit + '</span></span>' +
109
+ '</button>' +
110
+ '<button type="button" data-command="delete" tabindex="-1" class="se-btn se-tooltip">' +
111
+ core.icons.delete +
112
+ '<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.remove + '</span></span>' +
113
+ '</button>' +
114
+ '</div>' +
115
+ '</div>' +
116
+ '';
117
+
118
+ return math_btn;
119
+ },
120
+
121
+ /**
122
+ * @Required @Override dialog
123
+ */
124
+ open: function () {
125
+ this.plugins.dialog.open.call(this, 'math', 'math' === this.currentControllerName);
126
+ },
127
+
128
+ /**
129
+ * @Override core - managedTagsInfo
130
+ */
131
+ managedTags: function () {
132
+ return {
133
+ className: 'katex',
134
+ method: function (element) {
135
+ if (!element.getAttribute('data-exp') || !this.options.katex) return;
136
+ const dom = this._d.createRange().createContextualFragment(this.plugins.math._renderer.call(this, this.util.HTMLDecoder(element.getAttribute('data-exp'))));
137
+ element.innerHTML = dom.querySelector('.katex').innerHTML;
138
+ element.setAttribute('contenteditable', false);
139
+ }
140
+ };
141
+ },
142
+
143
+ _renderer: function (exp) {
144
+ let result = '';
145
+ try {
146
+ this.util.removeClass(this.context.math.focusElement, 'se-error');
147
+ result = this.options.katex.src.renderToString(exp, {throwOnError: true, displayMode: true});
148
+ } catch(error) {
149
+ this.util.addClass(this.context.math.focusElement, 'se-error');
150
+ result = '<span class="se-math-katex-error">Katex syntax error. (Refer <a href="' + KATEX_WEBSITE + '" target="_blank">KaTeX</a>)</span>';
151
+ console.warn('[SUNEDITOR.math.Katex.error] ', error);
152
+ }
153
+ return result;
154
+ },
155
+
156
+ _renderMathExp: function (contextMath, e) {
157
+ contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, e.target.value);
158
+ },
159
+
160
+ submit: function (e) {
161
+ this.showLoading();
162
+
163
+ e.preventDefault();
164
+ e.stopPropagation();
165
+
166
+ const submitAction = function () {
167
+ if (this.context.math.focusElement.value.trim().length === 0) return false;
168
+
169
+ const contextMath = this.context.math;
170
+ const mathExp = contextMath.focusElement.value;
171
+ const katexEl = contextMath.previewElement.querySelector('.katex');
172
+
173
+ if (!katexEl) return false;
174
+ katexEl.className = '__se__katex ' + katexEl.className;
175
+ katexEl.setAttribute('contenteditable', false);
176
+ katexEl.setAttribute('data-exp', this.util.HTMLEncoder(mathExp));
177
+ katexEl.setAttribute('data-font-size', contextMath.fontSizeElement.value);
178
+ katexEl.style.fontSize = contextMath.fontSizeElement.value;
179
+
180
+ if (!this.context.dialog.updateModal) {
181
+ const selectedFormats = this.getSelectedElements();
182
+
183
+ if (selectedFormats.length > 1) {
184
+ const oFormat = this.util.createElement(selectedFormats[0].nodeName);
185
+ oFormat.appendChild(katexEl);
186
+ if (!this.insertNode(oFormat, null, true)) return false;
187
+ } else {
188
+ if (!this.insertNode(katexEl, null, true)) return false;
189
+ }
190
+
191
+ const empty = this.util.createTextNode(this.util.zeroWidthSpace);
192
+ katexEl.parentNode.insertBefore(empty, katexEl.nextSibling);
193
+ this.setRange(katexEl, 0, katexEl, 1);
194
+ } else {
195
+ const containerEl = this.util.getParentElement(contextMath._mathExp, '.katex');
196
+ containerEl.parentNode.replaceChild(katexEl, containerEl);
197
+ this.setRange(katexEl, 0, katexEl, 1);
198
+ }
199
+
200
+ contextMath.focusElement.value = '';
201
+ contextMath.fontSizeElement.value = '1em';
202
+ contextMath.previewElement.style.fontSize = '1em';
203
+ contextMath.previewElement.innerHTML = '';
204
+
205
+ return true;
206
+ }.bind(this);
207
+
208
+ try {
209
+ if (submitAction()) {
210
+ this.plugins.dialog.close.call(this);
211
+ // history stack
212
+ this.history.push(false);
213
+ }
214
+ } catch (e) {
215
+ this.plugins.dialog.close.call(this);
216
+ } finally {
217
+ this.closeLoading();
218
+ }
219
+
220
+ return false;
221
+ },
222
+
223
+ active: function (element) {
224
+ if (!element) {
225
+ if (this.controllerArray.indexOf(this.context.math.mathController) > -1) {
226
+ this.controllersOff();
227
+ }
228
+ } else if (element.getAttribute('data-exp')) {
229
+ if (this.controllerArray.indexOf(this.context.math.mathController) < 0) {
230
+ this.setRange(element, 0, element, 1);
231
+ this.plugins.math.call_controller.call(this, element);
232
+ }
233
+ return true;
234
+ }
235
+
236
+ return false;
237
+ },
238
+
239
+ on: function (update) {
240
+ if (!update) {
241
+ this.plugins.math.init.call(this);
242
+ } else {
243
+ const contextMath = this.context.math;
244
+ if (contextMath._mathExp) {
245
+ const exp = this.util.HTMLDecoder(contextMath._mathExp.getAttribute('data-exp'));
246
+ const fontSize = contextMath._mathExp.getAttribute('data-font-size') || '1em';
247
+ this.context.dialog.updateModal = true;
248
+ contextMath.focusElement.value = exp;
249
+ contextMath.fontSizeElement.value = fontSize;
250
+ contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, exp);
251
+ contextMath.previewElement.style.fontSize = fontSize;
252
+ }
253
+ }
254
+ },
255
+
256
+ call_controller: function (mathTag) {
257
+ this.context.math._mathExp = mathTag;
258
+ const mathBtn = this.context.math.mathController;
259
+
260
+ this.setControllerPosition(mathBtn, mathTag, 'bottom', {left: 0, top: 0});
261
+ this.controllersOn(mathBtn, mathTag, 'math');
262
+ },
263
+
264
+ onClick_mathController: function (e) {
265
+ e.stopPropagation();
266
+
267
+ const command = e.target.getAttribute('data-command') || e.target.parentNode.getAttribute('data-command');
268
+ if (!command) return;
269
+
270
+ e.preventDefault();
271
+
272
+ if (/update/.test(command)) {
273
+ this.context.math.focusElement.value = this.util.HTMLDecoder(this.context.math._mathExp.getAttribute('data-exp'));
274
+ this.plugins.dialog.open.call(this, 'math', true);
275
+ } else {
276
+ /** delete */
277
+ this.util.removeItem(this.context.math._mathExp);
278
+ this.context.math._mathExp = null;
279
+ this.focus();
280
+
281
+ // history stack
282
+ this.history.push(false);
283
+ }
284
+
285
+ this.controllersOff();
286
+ },
287
+
288
+ init: function () {
289
+ const contextMath = this.context.math;
290
+ contextMath.mathController.style.display = 'none';
291
+ contextMath._mathExp = null;
292
+ contextMath.focusElement.value = '';
293
+ contextMath.previewElement.innerHTML = '';
294
+ }
295
+ };
@@ -1,5 +1,5 @@
1
- import { DialogPlugin } from '../DialogPlugin';
2
-
3
- declare const mention: DialogPlugin;
4
-
5
- export default mention;
1
+ import { DialogPlugin } from '../DialogPlugin';
2
+
3
+ declare const mention: DialogPlugin;
4
+
5
+ export default mention;