suneditor 2.44.2 → 2.44.4
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.
- package/LICENSE.txt +20 -20
- package/README.md +1585 -1585
- package/dist/css/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +2 -2
- package/package.json +71 -71
- package/src/assets/css/suneditor-contents.css +556 -556
- package/src/assets/css/suneditor.css +0 -0
- package/src/assets/defaultIcons.js +103 -103
- package/src/lang/Lang.d.ts +143 -143
- package/src/lang/ckb.d.ts +4 -4
- package/src/lang/ckb.js +187 -187
- package/src/lang/da.d.ts +4 -4
- package/src/lang/da.js +191 -191
- package/src/lang/de.d.ts +4 -4
- package/src/lang/de.js +187 -187
- package/src/lang/en.d.ts +4 -4
- package/src/lang/en.js +187 -187
- package/src/lang/es.d.ts +4 -4
- package/src/lang/es.js +187 -187
- package/src/lang/fr.d.ts +4 -4
- package/src/lang/fr.js +188 -188
- package/src/lang/he.d.ts +4 -4
- package/src/lang/he.js +188 -188
- package/src/lang/index.d.ts +22 -21
- package/src/lang/index.js +25 -24
- package/src/lang/it.d.ts +4 -4
- package/src/lang/it.js +188 -188
- package/src/lang/ja.d.ts +4 -4
- package/src/lang/ja.js +187 -187
- package/src/lang/ko.d.ts +4 -4
- package/src/lang/ko.js +187 -187
- package/src/lang/lv.d.ts +4 -4
- package/src/lang/lv.js +187 -187
- package/src/lang/nl.d.ts +4 -4
- package/src/lang/nl.js +187 -187
- package/src/lang/pl.d.ts +4 -4
- package/src/lang/pl.js +187 -187
- package/src/lang/pt_br.d.ts +4 -4
- package/src/lang/pt_br.js +189 -189
- package/src/lang/ro.d.ts +4 -4
- package/src/lang/ro.js +187 -187
- package/src/lang/ru.d.ts +4 -4
- package/src/lang/ru.js +187 -187
- package/src/lang/se.d.ts +4 -4
- package/src/lang/se.js +191 -191
- package/src/lang/ua.d.ts +5 -5
- package/src/lang/ua.js +188 -188
- package/src/lang/ur.d.ts +5 -0
- package/src/lang/ur.js +188 -0
- package/src/lang/zh_cn.d.ts +4 -4
- package/src/lang/zh_cn.js +187 -187
- package/src/lib/constructor.js +1 -2
- package/src/lib/context.d.ts +42 -42
- package/src/lib/context.js +0 -0
- package/src/lib/core.d.ts +1101 -1101
- package/src/lib/core.js +220 -99
- package/src/lib/history.d.ts +48 -48
- package/src/lib/history.js +218 -218
- package/src/lib/util.d.ts +677 -677
- package/src/lib/util.js +38 -12
- package/src/options.d.ts +608 -608
- package/src/plugins/CommandPlugin.d.ts +7 -7
- package/src/plugins/DialogPlugin.d.ts +19 -19
- package/src/plugins/FileBrowserPlugin.d.ts +29 -29
- package/src/plugins/Module.d.ts +14 -14
- package/src/plugins/Plugin.d.ts +41 -41
- package/src/plugins/SubmenuPlugin.d.ts +7 -7
- package/src/plugins/command/blockquote.d.ts +4 -4
- package/src/plugins/command/blockquote.js +46 -46
- package/src/plugins/dialog/audio.d.ts +4 -4
- package/src/plugins/dialog/audio.js +556 -554
- package/src/plugins/dialog/image.d.ts +4 -4
- package/src/plugins/dialog/image.js +1122 -1107
- package/src/plugins/dialog/link.d.ts +4 -4
- package/src/plugins/dialog/link.js +223 -223
- package/src/plugins/dialog/math.d.ts +4 -4
- package/src/plugins/dialog/math.js +294 -294
- package/src/plugins/dialog/mention.d.ts +5 -5
- package/src/plugins/dialog/mention.js +242 -242
- package/src/plugins/dialog/video.d.ts +4 -4
- package/src/plugins/dialog/video.js +983 -981
- package/src/plugins/fileBrowser/imageGallery.d.ts +4 -4
- package/src/plugins/fileBrowser/imageGallery.js +63 -63
- package/src/plugins/index.d.ts +79 -79
- package/src/plugins/index.js +32 -32
- package/src/plugins/modules/_anchor.js +461 -462
- package/src/plugins/modules/_colorPicker.d.ts +59 -59
- package/src/plugins/modules/_colorPicker.js +0 -0
- package/src/plugins/modules/_notice.d.ts +20 -20
- package/src/plugins/modules/_notice.js +72 -72
- package/src/plugins/modules/_selectMenu.js +118 -118
- package/src/plugins/modules/component.d.ts +24 -24
- package/src/plugins/modules/component.js +82 -82
- package/src/plugins/modules/dialog.d.ts +27 -27
- package/src/plugins/modules/dialog.js +174 -174
- package/src/plugins/modules/fileBrowser.d.ts +41 -41
- package/src/plugins/modules/fileBrowser.js +373 -373
- package/src/plugins/modules/fileManager.d.ts +66 -66
- package/src/plugins/modules/fileManager.js +325 -324
- package/src/plugins/modules/index.d.ts +10 -10
- package/src/plugins/modules/index.js +8 -8
- package/src/plugins/modules/resizing.d.ts +153 -153
- package/src/plugins/modules/resizing.js +895 -895
- package/src/plugins/submenu/align.d.ts +4 -4
- package/src/plugins/submenu/align.js +160 -160
- package/src/plugins/submenu/font.d.ts +4 -4
- package/src/plugins/submenu/font.js +120 -120
- package/src/plugins/submenu/fontColor.d.ts +4 -4
- package/src/plugins/submenu/fontColor.js +0 -0
- package/src/plugins/submenu/fontSize.d.ts +4 -4
- package/src/plugins/submenu/fontSize.js +112 -112
- package/src/plugins/submenu/formatBlock.d.ts +4 -4
- package/src/plugins/submenu/formatBlock.js +273 -273
- package/src/plugins/submenu/hiliteColor.d.ts +4 -4
- package/src/plugins/submenu/hiliteColor.js +0 -0
- package/src/plugins/submenu/horizontalRule.d.ts +4 -4
- package/src/plugins/submenu/horizontalRule.js +98 -98
- package/src/plugins/submenu/lineHeight.d.ts +4 -4
- package/src/plugins/submenu/lineHeight.js +104 -104
- package/src/plugins/submenu/list.d.ts +4 -4
- package/src/plugins/submenu/list.js +456 -455
- package/src/plugins/submenu/paragraphStyle.d.ts +4 -4
- package/src/plugins/submenu/paragraphStyle.js +135 -135
- package/src/plugins/submenu/table.d.ts +4 -4
- package/src/plugins/submenu/template.d.ts +4 -4
- package/src/plugins/submenu/template.js +71 -71
- package/src/plugins/submenu/textStyle.d.ts +4 -4
- package/src/plugins/submenu/textStyle.js +167 -167
- package/src/suneditor.d.ts +9 -9
- package/src/suneditor.js +75 -75
- package/src/suneditor_build.js +17 -17
|
@@ -1,294 +1,294 @@
|
|
|
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
|
-
}
|
|
139
|
-
};
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
_renderer: function (exp) {
|
|
143
|
-
let result = '';
|
|
144
|
-
try {
|
|
145
|
-
this.util.removeClass(this.context.math.focusElement, 'se-error');
|
|
146
|
-
result = this.options.katex.src.renderToString(exp, {throwOnError: true, displayMode: true});
|
|
147
|
-
} catch(error) {
|
|
148
|
-
this.util.addClass(this.context.math.focusElement, 'se-error');
|
|
149
|
-
result = '<span class="se-math-katex-error">Katex syntax error. (Refer <a href="' + KATEX_WEBSITE + '" target="_blank">KaTeX</a>)</span>';
|
|
150
|
-
console.warn('[SUNEDITOR.math.Katex.error] ', error);
|
|
151
|
-
}
|
|
152
|
-
return result;
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
_renderMathExp: function (contextMath, e) {
|
|
156
|
-
contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, e.target.value);
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
submit: function (e) {
|
|
160
|
-
this.showLoading();
|
|
161
|
-
|
|
162
|
-
e.preventDefault();
|
|
163
|
-
e.stopPropagation();
|
|
164
|
-
|
|
165
|
-
const submitAction = function () {
|
|
166
|
-
if (this.context.math.focusElement.value.trim().length === 0) return false;
|
|
167
|
-
|
|
168
|
-
const contextMath = this.context.math;
|
|
169
|
-
const mathExp = contextMath.focusElement.value;
|
|
170
|
-
const katexEl = contextMath.previewElement.querySelector('.katex');
|
|
171
|
-
|
|
172
|
-
if (!katexEl) return false;
|
|
173
|
-
katexEl.className = '__se__katex ' + katexEl.className;
|
|
174
|
-
katexEl.setAttribute('contenteditable', false);
|
|
175
|
-
katexEl.setAttribute('data-exp', this.util.HTMLEncoder(mathExp));
|
|
176
|
-
katexEl.setAttribute('data-font-size', contextMath.fontSizeElement.value);
|
|
177
|
-
katexEl.style.fontSize = contextMath.fontSizeElement.value;
|
|
178
|
-
|
|
179
|
-
if (!this.context.dialog.updateModal) {
|
|
180
|
-
const selectedFormats = this.getSelectedElements();
|
|
181
|
-
|
|
182
|
-
if (selectedFormats.length > 1) {
|
|
183
|
-
const oFormat = this.util.createElement(selectedFormats[0].nodeName);
|
|
184
|
-
oFormat.appendChild(katexEl);
|
|
185
|
-
if (!this.insertNode(oFormat, null, true)) return false;
|
|
186
|
-
} else {
|
|
187
|
-
if (!this.insertNode(katexEl, null, true)) return false;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const empty = this.util.createTextNode(this.util.zeroWidthSpace);
|
|
191
|
-
katexEl.parentNode.insertBefore(empty, katexEl.nextSibling);
|
|
192
|
-
this.setRange(katexEl, 0, katexEl, 1);
|
|
193
|
-
} else {
|
|
194
|
-
const containerEl = this.util.getParentElement(contextMath._mathExp, '.katex');
|
|
195
|
-
containerEl.parentNode.replaceChild(katexEl, containerEl);
|
|
196
|
-
this.setRange(katexEl, 0, katexEl, 1);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
contextMath.focusElement.value = '';
|
|
200
|
-
contextMath.fontSizeElement.value = '1em';
|
|
201
|
-
contextMath.previewElement.style.fontSize = '1em';
|
|
202
|
-
contextMath.previewElement.innerHTML = '';
|
|
203
|
-
|
|
204
|
-
return true;
|
|
205
|
-
}.bind(this);
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
if (submitAction()) {
|
|
209
|
-
this.plugins.dialog.close.call(this);
|
|
210
|
-
// history stack
|
|
211
|
-
this.history.push(false);
|
|
212
|
-
}
|
|
213
|
-
} catch (e) {
|
|
214
|
-
this.plugins.dialog.close.call(this);
|
|
215
|
-
} finally {
|
|
216
|
-
this.closeLoading();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return false;
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
active: function (element) {
|
|
223
|
-
if (!element) {
|
|
224
|
-
if (this.controllerArray.indexOf(this.context.math.mathController) > -1) {
|
|
225
|
-
this.controllersOff();
|
|
226
|
-
}
|
|
227
|
-
} else if (element.getAttribute('data-exp')) {
|
|
228
|
-
if (this.controllerArray.indexOf(this.context.math.mathController) < 0) {
|
|
229
|
-
this.setRange(element, 0, element, 1);
|
|
230
|
-
this.plugins.math.call_controller.call(this, element);
|
|
231
|
-
}
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return false;
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
on: function (update) {
|
|
239
|
-
if (!update) {
|
|
240
|
-
this.plugins.math.init.call(this);
|
|
241
|
-
} else {
|
|
242
|
-
const contextMath = this.context.math;
|
|
243
|
-
if (contextMath._mathExp) {
|
|
244
|
-
const exp = this.util.HTMLDecoder(contextMath._mathExp.getAttribute('data-exp'));
|
|
245
|
-
const fontSize = contextMath._mathExp.getAttribute('data-font-size') || '1em';
|
|
246
|
-
this.context.dialog.updateModal = true;
|
|
247
|
-
contextMath.focusElement.value = exp;
|
|
248
|
-
contextMath.fontSizeElement.value = fontSize;
|
|
249
|
-
contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, exp);
|
|
250
|
-
contextMath.previewElement.style.fontSize = fontSize;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
call_controller: function (mathTag) {
|
|
256
|
-
this.context.math._mathExp = mathTag;
|
|
257
|
-
const mathBtn = this.context.math.mathController;
|
|
258
|
-
|
|
259
|
-
this.setControllerPosition(mathBtn, mathTag, 'bottom', {left: 0, top: 0});
|
|
260
|
-
this.controllersOn(mathBtn, mathTag, 'math');
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
onClick_mathController: function (e) {
|
|
264
|
-
e.stopPropagation();
|
|
265
|
-
|
|
266
|
-
const command = e.target.getAttribute('data-command') || e.target.parentNode.getAttribute('data-command');
|
|
267
|
-
if (!command) return;
|
|
268
|
-
|
|
269
|
-
e.preventDefault();
|
|
270
|
-
|
|
271
|
-
if (/update/.test(command)) {
|
|
272
|
-
this.context.math.focusElement.value = this.util.HTMLDecoder(this.context.math._mathExp.getAttribute('data-exp'));
|
|
273
|
-
this.plugins.dialog.open.call(this, 'math', true);
|
|
274
|
-
} else {
|
|
275
|
-
/** delete */
|
|
276
|
-
this.util.removeItem(this.context.math._mathExp);
|
|
277
|
-
this.context.math._mathExp = null;
|
|
278
|
-
this.focus();
|
|
279
|
-
|
|
280
|
-
// history stack
|
|
281
|
-
this.history.push(false);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
this.controllersOff();
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
init: function () {
|
|
288
|
-
const contextMath = this.context.math;
|
|
289
|
-
contextMath.mathController.style.display = 'none';
|
|
290
|
-
contextMath._mathExp = null;
|
|
291
|
-
contextMath.focusElement.value = '';
|
|
292
|
-
contextMath.previewElement.innerHTML = '';
|
|
293
|
-
}
|
|
294
|
-
};
|
|
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
|
+
}
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
_renderer: function (exp) {
|
|
143
|
+
let result = '';
|
|
144
|
+
try {
|
|
145
|
+
this.util.removeClass(this.context.math.focusElement, 'se-error');
|
|
146
|
+
result = this.options.katex.src.renderToString(exp, {throwOnError: true, displayMode: true});
|
|
147
|
+
} catch(error) {
|
|
148
|
+
this.util.addClass(this.context.math.focusElement, 'se-error');
|
|
149
|
+
result = '<span class="se-math-katex-error">Katex syntax error. (Refer <a href="' + KATEX_WEBSITE + '" target="_blank">KaTeX</a>)</span>';
|
|
150
|
+
console.warn('[SUNEDITOR.math.Katex.error] ', error);
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
_renderMathExp: function (contextMath, e) {
|
|
156
|
+
contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, e.target.value);
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
submit: function (e) {
|
|
160
|
+
this.showLoading();
|
|
161
|
+
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
e.stopPropagation();
|
|
164
|
+
|
|
165
|
+
const submitAction = function () {
|
|
166
|
+
if (this.context.math.focusElement.value.trim().length === 0) return false;
|
|
167
|
+
|
|
168
|
+
const contextMath = this.context.math;
|
|
169
|
+
const mathExp = contextMath.focusElement.value;
|
|
170
|
+
const katexEl = contextMath.previewElement.querySelector('.katex');
|
|
171
|
+
|
|
172
|
+
if (!katexEl) return false;
|
|
173
|
+
katexEl.className = '__se__katex ' + katexEl.className;
|
|
174
|
+
katexEl.setAttribute('contenteditable', false);
|
|
175
|
+
katexEl.setAttribute('data-exp', this.util.HTMLEncoder(mathExp));
|
|
176
|
+
katexEl.setAttribute('data-font-size', contextMath.fontSizeElement.value);
|
|
177
|
+
katexEl.style.fontSize = contextMath.fontSizeElement.value;
|
|
178
|
+
|
|
179
|
+
if (!this.context.dialog.updateModal) {
|
|
180
|
+
const selectedFormats = this.getSelectedElements();
|
|
181
|
+
|
|
182
|
+
if (selectedFormats.length > 1) {
|
|
183
|
+
const oFormat = this.util.createElement(selectedFormats[0].nodeName);
|
|
184
|
+
oFormat.appendChild(katexEl);
|
|
185
|
+
if (!this.insertNode(oFormat, null, true)) return false;
|
|
186
|
+
} else {
|
|
187
|
+
if (!this.insertNode(katexEl, null, true)) return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const empty = this.util.createTextNode(this.util.zeroWidthSpace);
|
|
191
|
+
katexEl.parentNode.insertBefore(empty, katexEl.nextSibling);
|
|
192
|
+
this.setRange(katexEl, 0, katexEl, 1);
|
|
193
|
+
} else {
|
|
194
|
+
const containerEl = this.util.getParentElement(contextMath._mathExp, '.katex');
|
|
195
|
+
containerEl.parentNode.replaceChild(katexEl, containerEl);
|
|
196
|
+
this.setRange(katexEl, 0, katexEl, 1);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
contextMath.focusElement.value = '';
|
|
200
|
+
contextMath.fontSizeElement.value = '1em';
|
|
201
|
+
contextMath.previewElement.style.fontSize = '1em';
|
|
202
|
+
contextMath.previewElement.innerHTML = '';
|
|
203
|
+
|
|
204
|
+
return true;
|
|
205
|
+
}.bind(this);
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
if (submitAction()) {
|
|
209
|
+
this.plugins.dialog.close.call(this);
|
|
210
|
+
// history stack
|
|
211
|
+
this.history.push(false);
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
this.plugins.dialog.close.call(this);
|
|
215
|
+
} finally {
|
|
216
|
+
this.closeLoading();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return false;
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
active: function (element) {
|
|
223
|
+
if (!element) {
|
|
224
|
+
if (this.controllerArray.indexOf(this.context.math.mathController) > -1) {
|
|
225
|
+
this.controllersOff();
|
|
226
|
+
}
|
|
227
|
+
} else if (element.getAttribute('data-exp')) {
|
|
228
|
+
if (this.controllerArray.indexOf(this.context.math.mathController) < 0) {
|
|
229
|
+
this.setRange(element, 0, element, 1);
|
|
230
|
+
this.plugins.math.call_controller.call(this, element);
|
|
231
|
+
}
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return false;
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
on: function (update) {
|
|
239
|
+
if (!update) {
|
|
240
|
+
this.plugins.math.init.call(this);
|
|
241
|
+
} else {
|
|
242
|
+
const contextMath = this.context.math;
|
|
243
|
+
if (contextMath._mathExp) {
|
|
244
|
+
const exp = this.util.HTMLDecoder(contextMath._mathExp.getAttribute('data-exp'));
|
|
245
|
+
const fontSize = contextMath._mathExp.getAttribute('data-font-size') || '1em';
|
|
246
|
+
this.context.dialog.updateModal = true;
|
|
247
|
+
contextMath.focusElement.value = exp;
|
|
248
|
+
contextMath.fontSizeElement.value = fontSize;
|
|
249
|
+
contextMath.previewElement.innerHTML = this.plugins.math._renderer.call(this, exp);
|
|
250
|
+
contextMath.previewElement.style.fontSize = fontSize;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
call_controller: function (mathTag) {
|
|
256
|
+
this.context.math._mathExp = mathTag;
|
|
257
|
+
const mathBtn = this.context.math.mathController;
|
|
258
|
+
|
|
259
|
+
this.setControllerPosition(mathBtn, mathTag, 'bottom', {left: 0, top: 0});
|
|
260
|
+
this.controllersOn(mathBtn, mathTag, 'math');
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
onClick_mathController: function (e) {
|
|
264
|
+
e.stopPropagation();
|
|
265
|
+
|
|
266
|
+
const command = e.target.getAttribute('data-command') || e.target.parentNode.getAttribute('data-command');
|
|
267
|
+
if (!command) return;
|
|
268
|
+
|
|
269
|
+
e.preventDefault();
|
|
270
|
+
|
|
271
|
+
if (/update/.test(command)) {
|
|
272
|
+
this.context.math.focusElement.value = this.util.HTMLDecoder(this.context.math._mathExp.getAttribute('data-exp'));
|
|
273
|
+
this.plugins.dialog.open.call(this, 'math', true);
|
|
274
|
+
} else {
|
|
275
|
+
/** delete */
|
|
276
|
+
this.util.removeItem(this.context.math._mathExp);
|
|
277
|
+
this.context.math._mathExp = null;
|
|
278
|
+
this.focus();
|
|
279
|
+
|
|
280
|
+
// history stack
|
|
281
|
+
this.history.push(false);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
this.controllersOff();
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
init: function () {
|
|
288
|
+
const contextMath = this.context.math;
|
|
289
|
+
contextMath.mathController.style.display = 'none';
|
|
290
|
+
contextMath._mathExp = null;
|
|
291
|
+
contextMath.focusElement.value = '';
|
|
292
|
+
contextMath.previewElement.innerHTML = '';
|
|
293
|
+
}
|
|
294
|
+
};
|
|
@@ -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;
|