suneditor 2.46.1 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +7 -0
- package/.eslintrc.json +64 -0
- package/CONTRIBUTING.md +36 -0
- package/LICENSE.txt +1 -1
- package/README.md +174 -805
- package/dist/suneditor.min.css +1 -0
- package/dist/suneditor.min.js +1 -2
- package/package.json +96 -70
- package/src/assets/icons/_default.js +194 -0
- package/src/assets/suneditor-content.css +646 -0
- package/src/assets/suneditor.css +3378 -0
- package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
- package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
- package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
- package/src/core/base/eventHandlers/handler_ww_key_input.js +975 -0
- package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
- package/src/core/base/eventManager.js +1115 -0
- package/src/core/base/events.js +320 -0
- package/src/core/base/history.js +301 -0
- package/src/core/class/char.js +146 -0
- package/src/core/class/component.js +627 -0
- package/src/core/class/format.js +3255 -0
- package/src/core/class/html.js +1621 -0
- package/src/core/class/menu.js +260 -0
- package/src/core/class/nodeTransform.js +379 -0
- package/src/core/class/notice.js +42 -0
- package/src/core/class/offset.js +578 -0
- package/src/core/class/selection.js +508 -0
- package/src/core/class/shortcuts.js +38 -0
- package/src/core/class/toolbar.js +440 -0
- package/src/core/class/viewer.js +646 -0
- package/src/core/editor.js +1593 -0
- package/src/core/section/actives.js +107 -0
- package/src/core/section/constructor.js +1237 -0
- package/src/core/section/context.js +97 -0
- package/src/editorInjector/_classes.js +22 -0
- package/src/editorInjector/_core.js +28 -0
- package/src/editorInjector/index.js +13 -0
- package/src/helper/converter.js +313 -0
- package/src/helper/domUtils.js +1177 -0
- package/src/helper/env.js +250 -0
- package/src/helper/index.js +19 -0
- package/src/helper/numbers.js +68 -0
- package/src/helper/unicode.js +43 -0
- package/src/langs/ckb.js +161 -0
- package/src/langs/cs.js +161 -0
- package/src/langs/da.js +161 -0
- package/src/langs/de.js +162 -0
- package/src/langs/en.js +199 -0
- package/src/langs/es.js +162 -0
- package/src/langs/fa.js +159 -0
- package/src/langs/fr.js +161 -0
- package/src/langs/he.js +162 -0
- package/src/{lang → langs}/index.js +0 -2
- package/src/langs/it.js +162 -0
- package/src/langs/ja.js +162 -0
- package/src/langs/ko.js +162 -0
- package/src/langs/lv.js +162 -0
- package/src/langs/nl.js +162 -0
- package/src/langs/pl.js +162 -0
- package/src/langs/pt_br.js +162 -0
- package/src/langs/ro.js +162 -0
- package/src/langs/ru.js +162 -0
- package/src/langs/se.js +162 -0
- package/src/langs/tr.js +159 -0
- package/src/langs/ua.js +162 -0
- package/src/langs/ur.js +162 -0
- package/src/langs/zh_cn.js +162 -0
- package/src/modules/ApiManager.js +168 -0
- package/src/modules/ColorPicker.js +302 -0
- package/src/modules/Controller.js +315 -0
- package/src/modules/Figure.js +1160 -0
- package/src/modules/FileBrowser.js +271 -0
- package/src/modules/FileManager.js +290 -0
- package/src/modules/HueSlider.js +513 -0
- package/src/modules/Modal.js +177 -0
- package/src/modules/ModalAnchorEditor.js +494 -0
- package/src/modules/SelectMenu.js +447 -0
- package/src/modules/_DragHandle.js +16 -0
- package/src/modules/index.js +14 -0
- package/src/plugins/command/blockquote.js +47 -47
- package/src/plugins/command/exportPdf.js +168 -0
- package/src/plugins/command/fileUpload.js +389 -0
- package/src/plugins/command/list_bulleted.js +112 -0
- package/src/plugins/command/list_numbered.js +115 -0
- package/src/plugins/dropdown/align.js +143 -0
- package/src/plugins/dropdown/backgroundColor.js +73 -0
- package/src/plugins/dropdown/font.js +113 -0
- package/src/plugins/dropdown/fontColor.js +73 -0
- package/src/plugins/dropdown/formatBlock.js +141 -0
- package/src/plugins/dropdown/hr.js +111 -0
- package/src/plugins/dropdown/layout.js +72 -0
- package/src/plugins/dropdown/lineHeight.js +114 -0
- package/src/plugins/dropdown/list.js +107 -0
- package/src/plugins/dropdown/paragraphStyle.js +117 -0
- package/src/plugins/dropdown/table.js +2810 -0
- package/src/plugins/dropdown/template.js +71 -0
- package/src/plugins/dropdown/textStyle.js +137 -0
- package/src/plugins/field/mention.js +172 -0
- package/src/plugins/fileBrowser/imageGallery.js +76 -59
- package/src/plugins/index.js +86 -24
- package/src/plugins/input/fontSize.js +357 -0
- package/src/plugins/modal/audio.js +510 -0
- package/src/plugins/modal/image.js +1062 -0
- package/src/plugins/modal/link.js +211 -0
- package/src/plugins/modal/math.js +347 -0
- package/src/plugins/modal/video.js +870 -0
- package/src/suneditor.js +62 -67
- package/src/themes/test.css +61 -0
- package/typings/CommandPlugin.d.ts +8 -0
- package/typings/DialogPlugin.d.ts +20 -0
- package/typings/FileBrowserPlugin.d.ts +30 -0
- package/typings/Lang.d.ts +124 -0
- package/typings/Module.d.ts +15 -0
- package/typings/Plugin.d.ts +42 -0
- package/typings/SubmenuPlugin.d.ts +8 -0
- package/typings/_classes.d.ts +17 -0
- package/typings/_colorPicker.d.ts +60 -0
- package/typings/_core.d.ts +55 -0
- package/typings/align.d.ts +5 -0
- package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
- package/typings/backgroundColor.d.ts +5 -0
- package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
- package/typings/char.d.ts +39 -0
- package/typings/component.d.ts +38 -0
- package/typings/context.d.ts +39 -0
- package/typings/converter.d.ts +33 -0
- package/typings/dialog.d.ts +28 -0
- package/typings/domUtils.d.ts +361 -0
- package/typings/editor.d.ts +7 -0
- package/typings/editor.ts +542 -0
- package/typings/env.d.ts +70 -0
- package/typings/eventManager.d.ts +37 -0
- package/typings/events.d.ts +262 -0
- package/typings/fileBrowser.d.ts +42 -0
- package/typings/fileManager.d.ts +67 -0
- package/typings/font.d.ts +5 -0
- package/typings/fontColor.d.ts +5 -0
- package/typings/fontSize.d.ts +5 -0
- package/typings/format.d.ts +191 -0
- package/typings/formatBlock.d.ts +5 -0
- package/typings/history.d.ts +48 -0
- package/typings/horizontalRule.d.ts +5 -0
- package/{src/plugins/dialog → typings}/image.d.ts +1 -1
- package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
- package/typings/index.d.ts +21 -0
- package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
- package/typings/index.plugins.d.ts +58 -0
- package/typings/lineHeight.d.ts +5 -0
- package/{src/plugins/dialog → typings}/link.d.ts +1 -1
- package/typings/list.d.ts +5 -0
- package/{src/plugins/dialog → typings}/math.d.ts +1 -1
- package/typings/mediaContainer.d.ts +25 -0
- package/typings/node.d.ts +57 -0
- package/typings/notice.d.ts +16 -0
- package/typings/numbers.d.ts +29 -0
- package/typings/offset.d.ts +24 -0
- package/typings/options.d.ts +589 -0
- package/typings/paragraphStyle.d.ts +5 -0
- package/typings/resizing.d.ts +141 -0
- package/typings/selection.d.ts +94 -0
- package/typings/shortcuts.d.ts +13 -0
- package/typings/suneditor.d.ts +9 -0
- package/typings/table.d.ts +5 -0
- package/typings/template.d.ts +5 -0
- package/typings/textStyle.d.ts +5 -0
- package/typings/toolbar.d.ts +32 -0
- package/typings/unicode.d.ts +25 -0
- package/{src/plugins/dialog → typings}/video.d.ts +1 -1
- package/dist/css/suneditor.min.css +0 -1
- package/src/assets/css/suneditor-contents.css +0 -562
- package/src/assets/css/suneditor.css +0 -566
- package/src/assets/defaultIcons.js +0 -103
- package/src/lang/Lang.d.ts +0 -144
- package/src/lang/ckb.d.ts +0 -5
- package/src/lang/ckb.js +0 -188
- package/src/lang/cs.d.ts +0 -5
- package/src/lang/cs.js +0 -188
- package/src/lang/da.d.ts +0 -5
- package/src/lang/da.js +0 -191
- package/src/lang/de.d.ts +0 -5
- package/src/lang/de.js +0 -188
- package/src/lang/en.d.ts +0 -5
- package/src/lang/en.js +0 -188
- package/src/lang/es.d.ts +0 -5
- package/src/lang/es.js +0 -188
- package/src/lang/fa.d.ts +0 -5
- package/src/lang/fa.js +0 -188
- package/src/lang/fr.d.ts +0 -5
- package/src/lang/fr.js +0 -188
- package/src/lang/he.d.ts +0 -5
- package/src/lang/he.js +0 -188
- package/src/lang/index.d.ts +0 -23
- package/src/lang/it.d.ts +0 -5
- package/src/lang/it.js +0 -188
- package/src/lang/ja.d.ts +0 -5
- package/src/lang/ja.js +0 -188
- package/src/lang/ko.d.ts +0 -5
- package/src/lang/ko.js +0 -188
- package/src/lang/lv.d.ts +0 -5
- package/src/lang/lv.js +0 -188
- package/src/lang/nl.d.ts +0 -5
- package/src/lang/nl.js +0 -188
- package/src/lang/pl.d.ts +0 -5
- package/src/lang/pl.js +0 -188
- package/src/lang/pt_br.d.ts +0 -5
- package/src/lang/pt_br.js +0 -189
- package/src/lang/ro.d.ts +0 -5
- package/src/lang/ro.js +0 -188
- package/src/lang/ru.d.ts +0 -5
- package/src/lang/ru.js +0 -188
- package/src/lang/se.d.ts +0 -5
- package/src/lang/se.js +0 -191
- package/src/lang/tr.d.ts +0 -5
- package/src/lang/tr.js +0 -191
- package/src/lang/ua.d.ts +0 -5
- package/src/lang/ua.js +0 -188
- package/src/lang/ur.d.ts +0 -5
- package/src/lang/ur.js +0 -188
- package/src/lang/zh_cn.d.ts +0 -5
- package/src/lang/zh_cn.js +0 -187
- package/src/lib/constructor.js +0 -954
- package/src/lib/context.d.ts +0 -42
- package/src/lib/context.js +0 -71
- package/src/lib/core.d.ts +0 -1135
- package/src/lib/core.js +0 -9395
- package/src/lib/history.d.ts +0 -48
- package/src/lib/history.js +0 -219
- package/src/lib/util.d.ts +0 -678
- package/src/lib/util.js +0 -2131
- package/src/options.d.ts +0 -608
- package/src/plugins/CommandPlugin.d.ts +0 -8
- package/src/plugins/DialogPlugin.d.ts +0 -20
- package/src/plugins/FileBrowserPlugin.d.ts +0 -30
- package/src/plugins/Module.d.ts +0 -15
- package/src/plugins/Plugin.d.ts +0 -42
- package/src/plugins/SubmenuPlugin.d.ts +0 -8
- package/src/plugins/dialog/audio.js +0 -559
- package/src/plugins/dialog/image.js +0 -1126
- package/src/plugins/dialog/link.js +0 -223
- package/src/plugins/dialog/math.js +0 -295
- package/src/plugins/dialog/mention.js +0 -242
- package/src/plugins/dialog/video.js +0 -979
- package/src/plugins/index.d.ts +0 -79
- package/src/plugins/modules/_anchor.js +0 -461
- package/src/plugins/modules/_colorPicker.d.ts +0 -60
- package/src/plugins/modules/_colorPicker.js +0 -201
- package/src/plugins/modules/_notice.d.ts +0 -21
- package/src/plugins/modules/_notice.js +0 -72
- package/src/plugins/modules/_selectMenu.js +0 -119
- package/src/plugins/modules/component.d.ts +0 -25
- package/src/plugins/modules/component.js +0 -81
- package/src/plugins/modules/dialog.d.ts +0 -28
- package/src/plugins/modules/dialog.js +0 -175
- package/src/plugins/modules/fileBrowser.d.ts +0 -42
- package/src/plugins/modules/fileBrowser.js +0 -374
- package/src/plugins/modules/fileManager.d.ts +0 -67
- package/src/plugins/modules/fileManager.js +0 -326
- package/src/plugins/modules/index.js +0 -9
- package/src/plugins/modules/resizing.d.ts +0 -154
- package/src/plugins/modules/resizing.js +0 -903
- package/src/plugins/submenu/align.d.ts +0 -5
- package/src/plugins/submenu/align.js +0 -160
- package/src/plugins/submenu/font.d.ts +0 -5
- package/src/plugins/submenu/font.js +0 -123
- package/src/plugins/submenu/fontColor.d.ts +0 -5
- package/src/plugins/submenu/fontColor.js +0 -101
- package/src/plugins/submenu/fontSize.d.ts +0 -5
- package/src/plugins/submenu/fontSize.js +0 -112
- package/src/plugins/submenu/formatBlock.d.ts +0 -5
- package/src/plugins/submenu/formatBlock.js +0 -273
- package/src/plugins/submenu/hiliteColor.d.ts +0 -5
- package/src/plugins/submenu/hiliteColor.js +0 -102
- package/src/plugins/submenu/horizontalRule.d.ts +0 -5
- package/src/plugins/submenu/horizontalRule.js +0 -98
- package/src/plugins/submenu/lineHeight.d.ts +0 -5
- package/src/plugins/submenu/lineHeight.js +0 -104
- package/src/plugins/submenu/list.d.ts +0 -5
- package/src/plugins/submenu/list.js +0 -456
- package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
- package/src/plugins/submenu/paragraphStyle.js +0 -135
- package/src/plugins/submenu/table.d.ts +0 -5
- package/src/plugins/submenu/table.js +0 -1431
- package/src/plugins/submenu/template.d.ts +0 -5
- package/src/plugins/submenu/template.js +0 -72
- package/src/plugins/submenu/textStyle.d.ts +0 -5
- package/src/plugins/submenu/textStyle.js +0 -167
- package/src/suneditor.d.ts +0 -9
- package/src/suneditor_build.js +0 -18
- /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* wysiwyg web editor
|
|
3
|
-
*
|
|
4
|
-
* suneditor.js
|
|
5
|
-
* Copyright 2017 JiHong Lee.
|
|
6
|
-
* MIT license.
|
|
7
|
-
*/
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
import dialog from '../modules/dialog';
|
|
11
|
-
import anchor from '../modules/_anchor';
|
|
12
|
-
|
|
13
|
-
export default {
|
|
14
|
-
name: 'link',
|
|
15
|
-
display: 'dialog',
|
|
16
|
-
add: function (core) {
|
|
17
|
-
core.addModule([dialog, anchor]);
|
|
18
|
-
|
|
19
|
-
const context = core.context;
|
|
20
|
-
const contextLink = context.link = {
|
|
21
|
-
focusElement: null, // @Override dialog // This element has focus when the dialog is opened.
|
|
22
|
-
_linkAnchor: null,
|
|
23
|
-
anchorCtx: null
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/** link dialog */
|
|
27
|
-
let link_dialog = this.setDialog(core);
|
|
28
|
-
contextLink.modal = link_dialog;
|
|
29
|
-
|
|
30
|
-
/** link controller */
|
|
31
|
-
let link_controller = this.setController_LinkButton(core);
|
|
32
|
-
contextLink.linkController = link_controller;
|
|
33
|
-
|
|
34
|
-
link_dialog.querySelector('form').addEventListener('submit', this.submit.bind(core));
|
|
35
|
-
link_controller.addEventListener('click', this.onClick_linkController.bind(core));
|
|
36
|
-
|
|
37
|
-
/** append html */
|
|
38
|
-
context.dialog.modal.appendChild(link_dialog);
|
|
39
|
-
|
|
40
|
-
/** append controller */
|
|
41
|
-
context.element.relative.appendChild(link_controller);
|
|
42
|
-
|
|
43
|
-
/** link event */
|
|
44
|
-
core.plugins.anchor.initEvent.call(core, 'link', link_dialog);
|
|
45
|
-
contextLink.focusElement = context.anchor.caller.link.urlInput;
|
|
46
|
-
|
|
47
|
-
/** empty memory */
|
|
48
|
-
link_dialog = null, link_controller = null;
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
/** dialog */
|
|
52
|
-
setDialog: function (core) {
|
|
53
|
-
const lang = core.lang;
|
|
54
|
-
const dialog = core.util.createElement('DIV');
|
|
55
|
-
const icons = core.icons;
|
|
56
|
-
|
|
57
|
-
dialog.className = 'se-dialog-content';
|
|
58
|
-
dialog.style.display = 'none';
|
|
59
|
-
let html = '' +
|
|
60
|
-
'<form>' +
|
|
61
|
-
'<div class="se-dialog-header">' +
|
|
62
|
-
'<button type="button" data-command="close" class="se-btn se-dialog-close" title="' + lang.dialogBox.close + '" aria-label="' + lang.dialogBox.close + '">' +
|
|
63
|
-
icons.cancel +
|
|
64
|
-
'</button>' +
|
|
65
|
-
'<span class="se-modal-title">' + lang.dialogBox.linkBox.title + '</span>' +
|
|
66
|
-
'</div>' +
|
|
67
|
-
core.context.anchor.forms.innerHTML +
|
|
68
|
-
'<div class="se-dialog-footer">' +
|
|
69
|
-
'<button type="submit" class="se-btn-primary" title="' + lang.dialogBox.submitButton + '" aria-label="' + lang.dialogBox.submitButton + '"><span>' + lang.dialogBox.submitButton + '</span></button>' +
|
|
70
|
-
'</div>' +
|
|
71
|
-
'</form>';
|
|
72
|
-
|
|
73
|
-
dialog.innerHTML = html;
|
|
74
|
-
return dialog;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
/** modify controller button */
|
|
78
|
-
setController_LinkButton: function (core) {
|
|
79
|
-
const lang = core.lang;
|
|
80
|
-
const icons = core.icons;
|
|
81
|
-
const link_btn = core.util.createElement('DIV');
|
|
82
|
-
|
|
83
|
-
link_btn.className = 'se-controller se-controller-link';
|
|
84
|
-
link_btn.innerHTML = '' +
|
|
85
|
-
'<div class="se-arrow se-arrow-up"></div>' +
|
|
86
|
-
'<div class="link-content"><span><a target="_blank" href=""></a> </span>' +
|
|
87
|
-
'<div class="se-btn-group">' +
|
|
88
|
-
'<button type="button" data-command="update" tabindex="-1" class="se-btn se-tooltip">' +
|
|
89
|
-
icons.edit +
|
|
90
|
-
'<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.edit + '</span></span>' +
|
|
91
|
-
'</button>' +
|
|
92
|
-
'<button type="button" data-command="unlink" tabindex="-1" class="se-btn se-tooltip">' +
|
|
93
|
-
icons.unlink +
|
|
94
|
-
'<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.unlink + '</span></span>' +
|
|
95
|
-
'</button>' +
|
|
96
|
-
'<button type="button" data-command="delete" tabindex="-1" class="se-btn se-tooltip">' +
|
|
97
|
-
icons.delete +
|
|
98
|
-
'<span class="se-tooltip-inner"><span class="se-tooltip-text">' + lang.controller.remove + '</span></span>' +
|
|
99
|
-
'</button>' +
|
|
100
|
-
'</div>' +
|
|
101
|
-
'</div>';
|
|
102
|
-
|
|
103
|
-
return link_btn;
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* @Override dialog
|
|
108
|
-
*/
|
|
109
|
-
open: function () {
|
|
110
|
-
this.plugins.dialog.open.call(this, 'link', 'link' === this.currentControllerName);
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
submit: function (e) {
|
|
114
|
-
this.showLoading();
|
|
115
|
-
|
|
116
|
-
e.preventDefault();
|
|
117
|
-
e.stopPropagation();
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
const oA = this.plugins.anchor.createAnchor.call(this, this.context.anchor.caller.link, false);
|
|
121
|
-
if (oA === null) return;
|
|
122
|
-
|
|
123
|
-
if (!this.context.dialog.updateModal) {
|
|
124
|
-
const selectedFormats = this.getSelectedElements();
|
|
125
|
-
if (selectedFormats.length > 1) {
|
|
126
|
-
const oFormat = this.util.createElement(selectedFormats[0].nodeName);
|
|
127
|
-
oFormat.appendChild(oA);
|
|
128
|
-
if (!this.insertNode(oFormat, null, true)) return;
|
|
129
|
-
} else {
|
|
130
|
-
if (!this.insertNode(oA, null, true)) return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
this.setRange(oA.childNodes[0], 0, oA.childNodes[0], oA.textContent.length);
|
|
134
|
-
} else {
|
|
135
|
-
// set range
|
|
136
|
-
const textNode = this.context.link._linkAnchor.childNodes[0];
|
|
137
|
-
this.setRange(textNode, 0, textNode, textNode.textContent.length);
|
|
138
|
-
}
|
|
139
|
-
} finally {
|
|
140
|
-
this.plugins.dialog.close.call(this);
|
|
141
|
-
this.closeLoading();
|
|
142
|
-
// history stack
|
|
143
|
-
this.history.push(false);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return false;
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* @Override core
|
|
151
|
-
*/
|
|
152
|
-
active: function (element) {
|
|
153
|
-
if (!element) {
|
|
154
|
-
if (this.controllerArray.indexOf(this.context.link.linkController) > -1) {
|
|
155
|
-
this.controllersOff();
|
|
156
|
-
}
|
|
157
|
-
} else if (this.util.isAnchor(element) && element.getAttribute('data-image-link') === null) {
|
|
158
|
-
if (this.controllerArray.indexOf(this.context.link.linkController) < 0) {
|
|
159
|
-
this.plugins.link.call_controller.call(this, element);
|
|
160
|
-
}
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return false;
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @Override dialog
|
|
169
|
-
*/
|
|
170
|
-
on: function (update) {
|
|
171
|
-
this.plugins.anchor.on.call(this, this.context.anchor.caller.link, update);
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
call_controller: function (selectionATag) {
|
|
175
|
-
this.editLink = this.context.link._linkAnchor = this.context.anchor.caller.link.linkAnchor = selectionATag;
|
|
176
|
-
const linkBtn = this.context.link.linkController;
|
|
177
|
-
const link = linkBtn.querySelector('a');
|
|
178
|
-
|
|
179
|
-
link.href = selectionATag.href;
|
|
180
|
-
link.title = selectionATag.textContent;
|
|
181
|
-
link.textContent = selectionATag.textContent;
|
|
182
|
-
|
|
183
|
-
this.util.addClass(selectionATag, 'on');
|
|
184
|
-
this.setControllerPosition(linkBtn, selectionATag, 'bottom', {left: 0, top: 0});
|
|
185
|
-
this.controllersOn(linkBtn, selectionATag, 'link', this.util.removeClass.bind(this.util, this.context.link._linkAnchor, 'on'));
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
onClick_linkController: function (e) {
|
|
189
|
-
e.stopPropagation();
|
|
190
|
-
|
|
191
|
-
const command = e.target.getAttribute('data-command') || e.target.parentNode.getAttribute('data-command');
|
|
192
|
-
if (!command) return;
|
|
193
|
-
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
|
|
196
|
-
if (/update/.test(command)) {
|
|
197
|
-
this.plugins.dialog.open.call(this, 'link', true);
|
|
198
|
-
} else if (/unlink/.test(command)) {
|
|
199
|
-
const sc = this.util.getChildElement(this.context.link._linkAnchor, function (current) { return current.childNodes.length === 0 || current.nodeType === 3; }, false);
|
|
200
|
-
const ec = this.util.getChildElement(this.context.link._linkAnchor, function (current) { return current.childNodes.length === 0 || current.nodeType === 3; }, true);
|
|
201
|
-
this.setRange(sc, 0, ec, ec.textContent.length);
|
|
202
|
-
this.nodeChange(null, null, ['A'], false);
|
|
203
|
-
} else {
|
|
204
|
-
/** delete */
|
|
205
|
-
this.util.removeItem(this.context.link._linkAnchor);
|
|
206
|
-
this.context.anchor.caller.link.linkAnchor = null;
|
|
207
|
-
this.focus();
|
|
208
|
-
|
|
209
|
-
// history stack
|
|
210
|
-
this.history.push(false);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
this.controllersOff();
|
|
214
|
-
},
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* @Override dialog
|
|
218
|
-
*/
|
|
219
|
-
init: function () {
|
|
220
|
-
this.context.link.linkController.style.display = 'none';
|
|
221
|
-
this.plugins.anchor.init.call(this, this.context.anchor.caller.link);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
@@ -1,295 +0,0 @@
|
|
|
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
|
-
};
|