suneditor 3.0.0-alpha.2 → 3.0.0-alpha.20
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/.eslintrc.json +4 -3
- package/CONTRIBUTING.md +4 -2
- package/README.md +19 -11
- package/README_V3_TEMP.md +705 -0
- package/dist/suneditor.min.css +1 -0
- package/dist/suneditor.min.js +1 -0
- package/example.md +587 -0
- package/package.json +15 -9
- package/src/assets/icons/_default.js +166 -131
- package/src/assets/{suneditor-content.css → suneditor-contents.css} +182 -45
- package/src/assets/suneditor.css +1195 -556
- package/src/assets/variables.css +138 -0
- package/src/core/base/eventHandlers/handler_toolbar.js +35 -14
- package/src/core/base/eventHandlers/handler_ww_clipboard.js +29 -4
- package/src/core/base/eventHandlers/handler_ww_dragDrop.js +59 -15
- package/src/core/base/eventHandlers/handler_ww_key_input.js +426 -212
- package/src/core/base/eventHandlers/handler_ww_mouse.js +108 -32
- package/src/core/base/eventManager.js +540 -209
- package/src/core/base/events.js +616 -320
- package/src/core/base/history.js +93 -39
- package/src/core/class/char.js +29 -13
- package/src/core/class/component.js +332 -145
- package/src/core/class/format.js +671 -509
- package/src/core/class/html.js +504 -290
- package/src/core/class/menu.js +114 -47
- package/src/core/class/nodeTransform.js +111 -66
- package/src/core/class/offset.js +409 -105
- package/src/core/class/selection.js +220 -108
- package/src/core/class/shortcuts.js +68 -8
- package/src/core/class/toolbar.js +106 -116
- package/src/core/class/ui.js +330 -0
- package/src/core/class/viewer.js +178 -74
- package/src/core/editor.js +489 -384
- package/src/core/section/actives.js +118 -22
- package/src/core/section/constructor.js +504 -170
- package/src/core/section/context.js +28 -23
- package/src/core/section/documentType.js +561 -0
- package/src/editorInjector/_classes.js +19 -5
- package/src/editorInjector/_core.js +71 -7
- package/src/editorInjector/index.js +63 -1
- package/src/helper/converter.js +137 -19
- package/src/helper/dom/domCheck.js +294 -0
- package/src/helper/dom/domQuery.js +609 -0
- package/src/helper/dom/domUtils.js +533 -0
- package/src/helper/dom/index.js +12 -0
- package/src/helper/env.js +42 -19
- package/src/helper/index.js +7 -4
- package/src/helper/keyCodeMap.js +183 -0
- package/src/helper/numbers.js +8 -8
- package/src/helper/unicode.js +5 -5
- package/src/langs/ckb.js +69 -3
- package/src/langs/cs.js +67 -1
- package/src/langs/da.js +68 -2
- package/src/langs/de.js +68 -3
- package/src/langs/en.js +29 -1
- package/src/langs/es.js +68 -3
- package/src/langs/fa.js +70 -2
- package/src/langs/fr.js +68 -2
- package/src/langs/he.js +68 -3
- package/src/langs/hu.js +226 -0
- package/src/langs/index.js +3 -2
- package/src/langs/it.js +65 -0
- package/src/langs/ja.js +68 -3
- package/src/langs/ko.js +66 -1
- package/src/langs/lv.js +68 -3
- package/src/langs/nl.js +68 -3
- package/src/langs/pl.js +68 -3
- package/src/langs/pt_br.js +65 -0
- package/src/langs/ro.js +69 -4
- package/src/langs/ru.js +68 -3
- package/src/langs/se.js +68 -3
- package/src/langs/tr.js +68 -0
- package/src/langs/ua.js +68 -3
- package/src/langs/ur.js +71 -6
- package/src/langs/zh_cn.js +69 -4
- package/src/modules/ApiManager.js +77 -54
- package/src/modules/Browser.js +667 -0
- package/src/modules/ColorPicker.js +162 -102
- package/src/modules/Controller.js +233 -136
- package/src/modules/Figure.js +913 -489
- package/src/modules/FileManager.js +141 -72
- package/src/modules/HueSlider.js +113 -61
- package/src/modules/Modal.js +292 -113
- package/src/modules/ModalAnchorEditor.js +380 -230
- package/src/modules/SelectMenu.js +270 -168
- package/src/modules/_DragHandle.js +2 -1
- package/src/modules/index.js +3 -3
- package/src/plugins/browser/audioGallery.js +83 -0
- package/src/plugins/browser/fileBrowser.js +103 -0
- package/src/plugins/browser/fileGallery.js +83 -0
- package/src/plugins/browser/imageGallery.js +81 -0
- package/src/plugins/browser/videoGallery.js +103 -0
- package/src/plugins/command/blockquote.js +40 -27
- package/src/plugins/command/exportPDF.js +134 -0
- package/src/plugins/command/fileUpload.js +226 -158
- package/src/plugins/command/list_bulleted.js +93 -47
- package/src/plugins/command/list_numbered.js +93 -47
- package/src/plugins/dropdown/align.js +66 -54
- package/src/plugins/dropdown/backgroundColor.js +76 -45
- package/src/plugins/dropdown/font.js +71 -47
- package/src/plugins/dropdown/fontColor.js +78 -46
- package/src/plugins/dropdown/formatBlock.js +74 -33
- package/src/plugins/dropdown/hr.js +102 -51
- package/src/plugins/dropdown/layout.js +37 -26
- package/src/plugins/dropdown/lineHeight.js +54 -38
- package/src/plugins/dropdown/list.js +60 -45
- package/src/plugins/dropdown/paragraphStyle.js +51 -30
- package/src/plugins/dropdown/table.js +1269 -777
- package/src/plugins/dropdown/template.js +38 -26
- package/src/plugins/dropdown/textStyle.js +43 -31
- package/src/plugins/field/mention.js +144 -82
- package/src/plugins/index.js +32 -6
- package/src/plugins/input/fontSize.js +161 -108
- package/src/plugins/input/pageNavigator.js +70 -0
- package/src/plugins/modal/audio.js +341 -169
- package/src/plugins/modal/drawing.js +530 -0
- package/src/plugins/modal/embed.js +886 -0
- package/src/plugins/modal/image.js +673 -358
- package/src/plugins/modal/link.js +100 -71
- package/src/plugins/modal/math.js +384 -168
- package/src/plugins/modal/video.js +693 -336
- package/src/plugins/popup/anchor.js +222 -0
- package/src/suneditor.js +54 -12
- package/src/themes/dark.css +85 -0
- package/src/typedef.js +86 -0
- package/types/assets/icons/_default.d.ts +152 -0
- package/types/core/base/eventHandlers/handler_toolbar.d.ts +41 -0
- package/types/core/base/eventHandlers/handler_ww_clipboard.d.ts +40 -0
- package/types/core/base/eventHandlers/handler_ww_dragDrop.d.ts +35 -0
- package/types/core/base/eventHandlers/handler_ww_key_input.d.ts +45 -0
- package/types/core/base/eventHandlers/handler_ww_mouse.d.ts +39 -0
- package/types/core/base/eventManager.d.ts +377 -0
- package/types/core/base/events.d.ts +297 -0
- package/types/core/base/history.d.ts +81 -0
- package/types/core/class/char.d.ts +60 -0
- package/types/core/class/component.d.ts +259 -0
- package/types/core/class/format.d.ts +615 -0
- package/types/core/class/html.d.ts +377 -0
- package/types/core/class/menu.d.ts +118 -0
- package/types/core/class/nodeTransform.d.ts +93 -0
- package/types/core/class/offset.d.ts +512 -0
- package/types/core/class/selection.d.ts +188 -0
- package/types/core/class/shortcuts.d.ts +142 -0
- package/types/core/class/toolbar.d.ts +189 -0
- package/types/core/class/ui.d.ts +144 -0
- package/types/core/class/viewer.d.ts +140 -0
- package/types/core/editor.d.ts +606 -0
- package/types/core/section/actives.d.ts +46 -0
- package/types/core/section/constructor.d.ts +748 -0
- package/types/core/section/context.d.ts +45 -0
- package/types/core/section/documentType.d.ts +178 -0
- package/types/editorInjector/_classes.d.ts +41 -0
- package/types/editorInjector/_core.d.ts +92 -0
- package/types/editorInjector/index.d.ts +71 -0
- package/types/helper/converter.d.ts +150 -0
- package/types/helper/dom/domCheck.d.ts +182 -0
- package/types/helper/dom/domQuery.d.ts +214 -0
- package/types/helper/dom/domUtils.d.ts +211 -0
- package/types/helper/dom/index.d.ts +9 -0
- package/types/helper/env.d.ts +149 -0
- package/types/helper/index.d.ts +163 -0
- package/types/helper/keyCodeMap.d.ts +110 -0
- package/types/helper/numbers.d.ts +43 -0
- package/types/helper/unicode.d.ts +28 -0
- package/types/index.d.ts +0 -0
- package/{typings/Lang.d.ts → types/langs/_Lang.d.ts} +170 -103
- package/types/langs/ckb.d.ts +384 -0
- package/types/langs/cs.d.ts +384 -0
- package/types/langs/da.d.ts +384 -0
- package/types/langs/de.d.ts +384 -0
- package/types/langs/en.d.ts +384 -0
- package/types/langs/es.d.ts +384 -0
- package/types/langs/fa.d.ts +384 -0
- package/types/langs/fr.d.ts +384 -0
- package/types/langs/he.d.ts +384 -0
- package/types/langs/hu.d.ts +384 -0
- package/types/langs/index.d.ts +48 -0
- package/types/langs/it.d.ts +384 -0
- package/types/langs/ja.d.ts +384 -0
- package/types/langs/ko.d.ts +384 -0
- package/types/langs/lv.d.ts +384 -0
- package/types/langs/nl.d.ts +384 -0
- package/types/langs/pl.d.ts +384 -0
- package/types/langs/pt_br.d.ts +384 -0
- package/types/langs/ro.d.ts +384 -0
- package/types/langs/ru.d.ts +384 -0
- package/types/langs/se.d.ts +384 -0
- package/types/langs/tr.d.ts +384 -0
- package/types/langs/ua.d.ts +384 -0
- package/types/langs/ur.d.ts +384 -0
- package/types/langs/zh_cn.d.ts +384 -0
- package/types/modules/ApiManager.d.ts +125 -0
- package/types/modules/Browser.d.ts +326 -0
- package/types/modules/ColorPicker.d.ts +131 -0
- package/types/modules/Controller.d.ts +231 -0
- package/types/modules/Figure.d.ts +504 -0
- package/types/modules/FileManager.d.ts +202 -0
- package/types/modules/HueSlider.d.ts +136 -0
- package/types/modules/Modal.d.ts +117 -0
- package/types/modules/ModalAnchorEditor.d.ts +236 -0
- package/types/modules/SelectMenu.d.ts +194 -0
- package/types/modules/_DragHandle.d.ts +7 -0
- package/types/modules/index.d.ts +26 -0
- package/types/plugins/browser/audioGallery.d.ts +55 -0
- package/types/plugins/browser/fileBrowser.d.ts +64 -0
- package/types/plugins/browser/fileGallery.d.ts +55 -0
- package/types/plugins/browser/imageGallery.d.ts +51 -0
- package/types/plugins/browser/videoGallery.d.ts +57 -0
- package/types/plugins/command/blockquote.d.ts +28 -0
- package/types/plugins/command/exportPDF.d.ts +46 -0
- package/types/plugins/command/fileUpload.d.ts +156 -0
- package/types/plugins/command/list_bulleted.d.ts +56 -0
- package/types/plugins/command/list_numbered.d.ts +56 -0
- package/types/plugins/dropdown/align.d.ts +60 -0
- package/types/plugins/dropdown/backgroundColor.d.ts +63 -0
- package/types/plugins/dropdown/font.d.ts +54 -0
- package/types/plugins/dropdown/fontColor.d.ts +63 -0
- package/types/plugins/dropdown/formatBlock.d.ts +58 -0
- package/types/plugins/dropdown/hr.d.ts +81 -0
- package/types/plugins/dropdown/layout.d.ts +40 -0
- package/types/plugins/dropdown/lineHeight.d.ts +50 -0
- package/types/plugins/dropdown/list.d.ts +39 -0
- package/types/plugins/dropdown/paragraphStyle.d.ts +54 -0
- package/types/plugins/dropdown/table.d.ts +579 -0
- package/types/plugins/dropdown/template.d.ts +40 -0
- package/types/plugins/dropdown/textStyle.d.ts +41 -0
- package/types/plugins/field/mention.d.ts +102 -0
- package/types/plugins/index.d.ts +107 -0
- package/types/plugins/input/fontSize.d.ts +170 -0
- package/types/plugins/input/pageNavigator.d.ts +28 -0
- package/types/plugins/modal/audio.d.ts +269 -0
- package/types/plugins/modal/drawing.d.ts +246 -0
- package/types/plugins/modal/embed.d.ts +387 -0
- package/types/plugins/modal/image.d.ts +451 -0
- package/types/plugins/modal/link.d.ts +128 -0
- package/types/plugins/modal/math.d.ts +193 -0
- package/types/plugins/modal/video.d.ts +485 -0
- package/types/plugins/popup/anchor.d.ts +56 -0
- package/types/suneditor.d.ts +51 -0
- package/types/typedef-global.d.ts +144 -0
- package/src/core/class/notice.js +0 -42
- package/src/helper/domUtils.js +0 -1177
- package/src/modules/FileBrowser.js +0 -271
- package/src/plugins/command/exportPdf.js +0 -168
- package/src/plugins/fileBrowser/imageGallery.js +0 -81
- package/src/themes/test.css +0 -61
- package/typings/CommandPlugin.d.ts +0 -8
- package/typings/DialogPlugin.d.ts +0 -20
- package/typings/FileBrowserPlugin.d.ts +0 -30
- package/typings/Module.d.ts +0 -15
- package/typings/Plugin.d.ts +0 -42
- package/typings/SubmenuPlugin.d.ts +0 -8
- package/typings/_classes.d.ts +0 -17
- package/typings/_colorPicker.d.ts +0 -60
- package/typings/_core.d.ts +0 -55
- package/typings/align.d.ts +0 -5
- package/typings/audio.d.ts +0 -5
- package/typings/backgroundColor.d.ts +0 -5
- package/typings/blockquote.d.ts +0 -5
- package/typings/char.d.ts +0 -39
- package/typings/component.d.ts +0 -38
- package/typings/context.d.ts +0 -39
- package/typings/converter.d.ts +0 -33
- package/typings/dialog.d.ts +0 -28
- package/typings/domUtils.d.ts +0 -361
- package/typings/editor.d.ts +0 -7
- package/typings/editor.ts +0 -542
- package/typings/env.d.ts +0 -70
- package/typings/eventManager.d.ts +0 -37
- package/typings/events.d.ts +0 -262
- package/typings/fileBrowser.d.ts +0 -42
- package/typings/fileManager.d.ts +0 -67
- package/typings/font.d.ts +0 -5
- package/typings/fontColor.d.ts +0 -5
- package/typings/fontSize.d.ts +0 -5
- package/typings/format.d.ts +0 -191
- package/typings/formatBlock.d.ts +0 -5
- package/typings/history.d.ts +0 -48
- package/typings/horizontalRule.d.ts +0 -5
- package/typings/image.d.ts +0 -5
- package/typings/imageGallery.d.ts +0 -5
- package/typings/index.d.ts +0 -21
- package/typings/index.modules.d.ts +0 -11
- package/typings/index.plugins.d.ts +0 -58
- package/typings/lineHeight.d.ts +0 -5
- package/typings/link.d.ts +0 -5
- package/typings/list.d.ts +0 -5
- package/typings/math.d.ts +0 -5
- package/typings/mediaContainer.d.ts +0 -25
- package/typings/mention.d.ts +0 -5
- package/typings/node.d.ts +0 -57
- package/typings/notice.d.ts +0 -16
- package/typings/numbers.d.ts +0 -29
- package/typings/offset.d.ts +0 -24
- package/typings/options.d.ts +0 -589
- package/typings/paragraphStyle.d.ts +0 -5
- package/typings/resizing.d.ts +0 -141
- package/typings/selection.d.ts +0 -94
- package/typings/shortcuts.d.ts +0 -13
- package/typings/suneditor.d.ts +0 -9
- package/typings/table.d.ts +0 -5
- package/typings/template.d.ts +0 -5
- package/typings/textStyle.d.ts +0 -5
- package/typings/toolbar.d.ts +0 -32
- package/typings/unicode.d.ts +0 -25
- package/typings/video.d.ts +0 -5
|
@@ -1,28 +1,92 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description Add default properties to the editor core
|
|
3
|
-
* @param {
|
|
4
|
-
* @private
|
|
2
|
+
* @description Add default properties to the editor core object.
|
|
3
|
+
* @param {__se__EditorCore} editor - The root editor instance
|
|
5
4
|
*/
|
|
6
|
-
function CoreInjector(editor) {
|
|
7
|
-
|
|
5
|
+
export default function CoreInjector(editor) {
|
|
6
|
+
/**
|
|
7
|
+
* @description The root editor instance.
|
|
8
|
+
* @type {__se__EditorCore}
|
|
9
|
+
*/
|
|
8
10
|
this.editor = editor;
|
|
11
|
+
|
|
9
12
|
// base
|
|
13
|
+
/**
|
|
14
|
+
* @description The event manager instance.
|
|
15
|
+
* @type {import('../core/base/eventManager').default}
|
|
16
|
+
*/
|
|
10
17
|
this.eventManager = editor.eventManager;
|
|
18
|
+
/**
|
|
19
|
+
* @description The history manager instance.
|
|
20
|
+
* @type {__se__EditorCore['history']}
|
|
21
|
+
*/
|
|
11
22
|
this.history = editor.history;
|
|
23
|
+
/**
|
|
24
|
+
* @description The events instance.
|
|
25
|
+
* @type {__se__EditorCore['events']}
|
|
26
|
+
*/
|
|
12
27
|
this.events = editor.events;
|
|
28
|
+
/**
|
|
29
|
+
* @description The function to trigger an event.
|
|
30
|
+
* @type {__se__EditorCore['triggerEvent']}
|
|
31
|
+
*/
|
|
13
32
|
this.triggerEvent = editor.triggerEvent;
|
|
33
|
+
/**
|
|
34
|
+
* @description The wrapper element for carrying elements.
|
|
35
|
+
* @type {__se__EditorCore['carrierWrapper']}
|
|
36
|
+
*/
|
|
14
37
|
this.carrierWrapper = editor.carrierWrapper;
|
|
38
|
+
|
|
15
39
|
// environment variables
|
|
40
|
+
/**
|
|
41
|
+
* @description The plugins used by the editor.
|
|
42
|
+
* @type {__se__EditorCore['plugins']}
|
|
43
|
+
*/
|
|
16
44
|
this.plugins = editor.plugins;
|
|
45
|
+
/**
|
|
46
|
+
* @description The status of the editor.
|
|
47
|
+
* @type {__se__EditorStatus}
|
|
48
|
+
*/
|
|
17
49
|
this.status = editor.status;
|
|
50
|
+
/**
|
|
51
|
+
* @description The editor's context map.
|
|
52
|
+
* @type {__se__EditorCore['context']}
|
|
53
|
+
*/
|
|
18
54
|
this.context = editor.context;
|
|
55
|
+
/**
|
|
56
|
+
* @description The editor's options map.
|
|
57
|
+
* @type {__se__EditorCore['options']}
|
|
58
|
+
*/
|
|
19
59
|
this.options = editor.options;
|
|
60
|
+
/**
|
|
61
|
+
* @description The editor's icons.
|
|
62
|
+
* @type {__se__EditorCore['icons']}
|
|
63
|
+
*/
|
|
20
64
|
this.icons = editor.icons;
|
|
65
|
+
/**
|
|
66
|
+
* @description The language settings.
|
|
67
|
+
* @type {__se__EditorCore['lang']}
|
|
68
|
+
*/
|
|
21
69
|
this.lang = editor.lang;
|
|
70
|
+
/**
|
|
71
|
+
* @description editor.frameRoots map.
|
|
72
|
+
* @type {__se__EditorCore['frameRoots']}
|
|
73
|
+
*/
|
|
74
|
+
this.frameRoots = editor.frameRoots;
|
|
75
|
+
|
|
22
76
|
// window, document, shadowRoot
|
|
77
|
+
/**
|
|
78
|
+
* @description The window object.
|
|
79
|
+
* @type {Window}
|
|
80
|
+
*/
|
|
23
81
|
this._w = editor._w;
|
|
82
|
+
/**
|
|
83
|
+
* @description The document object.
|
|
84
|
+
* @type {Document}
|
|
85
|
+
*/
|
|
24
86
|
this._d = editor._d;
|
|
87
|
+
/**
|
|
88
|
+
* @description The shadow root object (if any).
|
|
89
|
+
* @type {__se__EditorCore['_shadowRoot']}
|
|
90
|
+
*/
|
|
25
91
|
this._shadowRoot = editor._shadowRoot;
|
|
26
92
|
}
|
|
27
|
-
|
|
28
|
-
export default CoreInjector;
|
|
@@ -3,9 +3,71 @@ import ClassInjector from './_classes';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @description Initializes and adds inner classes and default properties of the editor.
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {__se__EditorCore} editor - The root editor instance
|
|
7
7
|
*/
|
|
8
8
|
function EditorInjector(editor) {
|
|
9
|
+
// CoreInjector props
|
|
10
|
+
/** @type {__se__EditorCore} */
|
|
11
|
+
this.editor;
|
|
12
|
+
/** @type {import('./_core').default['eventManager']} */
|
|
13
|
+
this.eventManager;
|
|
14
|
+
/** @type {import('./_core').default['history']} */
|
|
15
|
+
this.history;
|
|
16
|
+
/** @type {import('./_core').default['events']} */
|
|
17
|
+
this.events;
|
|
18
|
+
/** @type {import('./_core').default['triggerEvent']} */
|
|
19
|
+
this.triggerEvent;
|
|
20
|
+
/** @type {import('./_core').default['carrierWrapper']} */
|
|
21
|
+
this.carrierWrapper;
|
|
22
|
+
/** @type {import('./_core').default['plugins']} */
|
|
23
|
+
this.plugins;
|
|
24
|
+
/** @type {import('./_core').default['status']} */
|
|
25
|
+
this.status;
|
|
26
|
+
/** @type {import('./_core').default['context']} */
|
|
27
|
+
this.context;
|
|
28
|
+
/** @type {import('./_core').default['options']} */
|
|
29
|
+
this.options;
|
|
30
|
+
/** @type {import('./_core').default['icons']} */
|
|
31
|
+
this.icons;
|
|
32
|
+
/** @type {import('./_core').default['lang']} */
|
|
33
|
+
this.lang;
|
|
34
|
+
/** @type {import('./_core').default['frameRoots']} */
|
|
35
|
+
this.frameRoots;
|
|
36
|
+
/** @type {import('./_core').default['_w']} */
|
|
37
|
+
this._w;
|
|
38
|
+
/** @type {import('./_core').default['_d']} */
|
|
39
|
+
this._d;
|
|
40
|
+
/** @type {import('./_core').default['_shadowRoot']} */
|
|
41
|
+
this._shadowRoot;
|
|
42
|
+
|
|
43
|
+
// ClassInjector props
|
|
44
|
+
/** @type {import('./_classes').default['toolbar']} */
|
|
45
|
+
this.toolbar;
|
|
46
|
+
/** @type {import('./_classes').default['subToolbar']} */
|
|
47
|
+
this.subToolbar;
|
|
48
|
+
/** @type {import('./_classes').default['char']} */
|
|
49
|
+
this.char;
|
|
50
|
+
/** @type {import('./_classes').default['component']} */
|
|
51
|
+
this.component;
|
|
52
|
+
/** @type {import('./_classes').default['format']} */
|
|
53
|
+
this.format;
|
|
54
|
+
/** @type {import('./_classes').default['html']} */
|
|
55
|
+
this.html;
|
|
56
|
+
/** @type {import('./_classes').default['menu']} */
|
|
57
|
+
this.menu;
|
|
58
|
+
/** @type {import('./_classes').default['nodeTransform']} */
|
|
59
|
+
this.nodeTransform;
|
|
60
|
+
/** @type {import('./_classes').default['offset']} */
|
|
61
|
+
this.offset;
|
|
62
|
+
/** @type {import('./_classes').default['selection']} */
|
|
63
|
+
this.selection;
|
|
64
|
+
/** @type {import('./_classes').default['shortcuts']} */
|
|
65
|
+
this.shortcuts;
|
|
66
|
+
/** @type {import('./_classes').default['ui']} */
|
|
67
|
+
this.ui;
|
|
68
|
+
/** @type {import('./_classes').default['viewer']} */
|
|
69
|
+
this.viewer;
|
|
70
|
+
|
|
9
71
|
CoreInjector.call(this, editor);
|
|
10
72
|
ClassInjector.call(this, editor);
|
|
11
73
|
}
|
package/src/helper/converter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _d, _w } from './env';
|
|
2
2
|
|
|
3
|
+
const URLPattern = /https?:\/\/[^\s]+/g;
|
|
3
4
|
const FONT_VALUES_MAP = {
|
|
4
5
|
'xx-small': 1,
|
|
5
6
|
'x-small': 2,
|
|
@@ -52,9 +53,9 @@ export function entityToHTML(content) {
|
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* @description Debounce function
|
|
55
|
-
* @param {
|
|
56
|
+
* @param {(...args: *) => void} func function
|
|
56
57
|
* @param {number} wait delay ms
|
|
57
|
-
* @returns
|
|
58
|
+
* @returns {*} executedFunction
|
|
58
59
|
*/
|
|
59
60
|
export function debounce(func, wait) {
|
|
60
61
|
let timeout;
|
|
@@ -70,6 +71,24 @@ export function debounce(func, wait) {
|
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @description Synchronizes two Map objects by updating the first Map with the values from the second,
|
|
76
|
+
* - and deleting any keys in the first Map that are not present in the second.
|
|
77
|
+
* @param {Map<*, *>} targetMap The Map to update (target).
|
|
78
|
+
* @param {Map<*, *>} referenceMap The Map providing the reference values (source).
|
|
79
|
+
*/
|
|
80
|
+
export function syncMaps(targetMap, referenceMap) {
|
|
81
|
+
referenceMap.forEach((value, key) => {
|
|
82
|
+
targetMap.set(key, value);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
targetMap.forEach((_value, key) => {
|
|
86
|
+
if (!referenceMap.has(key)) {
|
|
87
|
+
targetMap.delete(key);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
73
92
|
/**
|
|
74
93
|
*
|
|
75
94
|
* @param {"em"|"rem"|"%"|"pt"|"px"} to Size units to be converted
|
|
@@ -78,7 +97,7 @@ export function debounce(func, wait) {
|
|
|
78
97
|
*/
|
|
79
98
|
export function fontSize(to, size) {
|
|
80
99
|
const value = size.match(/(\d+(?:\.\d+)?)(.+)/);
|
|
81
|
-
const sizeNum = value ? value[1]
|
|
100
|
+
const sizeNum = value ? Number(value[1]) : FONT_VALUES_MAP[size];
|
|
82
101
|
const from = value ? value[2] : 'rem';
|
|
83
102
|
let pxSize = sizeNum;
|
|
84
103
|
|
|
@@ -95,7 +114,7 @@ export function fontSize(to, size) {
|
|
|
95
114
|
case 'rem':
|
|
96
115
|
return (pxSize * 0.0625).toFixed(2) + to;
|
|
97
116
|
case '%':
|
|
98
|
-
return (pxSize * 0.0625).toFixed(2) * 100 + to;
|
|
117
|
+
return Number((pxSize * 0.0625).toFixed(2)) * 100 + to;
|
|
99
118
|
case 'pt':
|
|
100
119
|
return Math.floor(pxSize / 1.333) + to;
|
|
101
120
|
default:
|
|
@@ -106,7 +125,7 @@ export function fontSize(to, size) {
|
|
|
106
125
|
|
|
107
126
|
/**
|
|
108
127
|
* @description Convert the node list to an array. If not, returns an empty array.
|
|
109
|
-
* @param {
|
|
128
|
+
* @param {?__se__NodeCollection} nodeList
|
|
110
129
|
* @returns Array
|
|
111
130
|
*/
|
|
112
131
|
export function nodeListToArray(nodeList) {
|
|
@@ -116,8 +135,8 @@ export function nodeListToArray(nodeList) {
|
|
|
116
135
|
|
|
117
136
|
/**
|
|
118
137
|
* @description Returns a new object with keys and values swapped.
|
|
119
|
-
* @param {Object} obj object
|
|
120
|
-
* @returns {Object}
|
|
138
|
+
* @param {Object<*, *>} obj object
|
|
139
|
+
* @returns {Object<*, *>}
|
|
121
140
|
*/
|
|
122
141
|
export function swapKeyValue(obj) {
|
|
123
142
|
const swappedObj = {};
|
|
@@ -133,9 +152,8 @@ export function swapKeyValue(obj) {
|
|
|
133
152
|
|
|
134
153
|
/**
|
|
135
154
|
* @description Create whitelist RegExp object.
|
|
136
|
-
* Return RegExp format: new RegExp("<\\/?\\b(?!" + list + ")\\b[^>^<]*+>", "gi")
|
|
137
155
|
* @param {string} list Tags list ("br|p|div|pre...")
|
|
138
|
-
* @returns {RegExp}
|
|
156
|
+
* @returns {RegExp} Return RegExp format: new RegExp("<\\/?\\b(?!" + list + ")\\b[^>^<]*+>", "gi")
|
|
139
157
|
*/
|
|
140
158
|
export function createElementWhitelist(list) {
|
|
141
159
|
return new RegExp(`<\\/?\\b(?!\\b${(list || '').replace(/\|/g, '\\b|\\b')}\\b)[^>]*>`, 'gi');
|
|
@@ -143,9 +161,8 @@ export function createElementWhitelist(list) {
|
|
|
143
161
|
|
|
144
162
|
/**
|
|
145
163
|
* @description Create blacklist RegExp object.
|
|
146
|
-
* Return RegExp format: new RegExp("<\\/?\\b(?:" + list + ")\\b[^>^<]*+>", "gi")
|
|
147
164
|
* @param {string} list Tags list ("br|p|div|pre...")
|
|
148
|
-
* @returns {RegExp}
|
|
165
|
+
* @returns {RegExp} Return RegExp format: new RegExp("<\\/?\\b(?:" + list + ")\\b[^>^<]*+>", "gi")
|
|
149
166
|
*/
|
|
150
167
|
export function createElementBlacklist(list) {
|
|
151
168
|
return new RegExp(`<\\/?\\b(?:\\b${(list || '^').replace(/\|/g, '\\b|\\b')}\\b)[^>]*>`, 'gi');
|
|
@@ -161,7 +178,7 @@ export function isHexColor(str) {
|
|
|
161
178
|
|
|
162
179
|
/**
|
|
163
180
|
* @description Function to convert hex format to a rgb color
|
|
164
|
-
* @param {string}
|
|
181
|
+
* @param {string} rgba RGBA color format
|
|
165
182
|
* @returns {string}
|
|
166
183
|
*/
|
|
167
184
|
export function rgb2hex(rgba) {
|
|
@@ -190,24 +207,121 @@ export function rgb2hex(rgba) {
|
|
|
190
207
|
|
|
191
208
|
/**
|
|
192
209
|
* @description Computes the width as a percentage of the parent's width, and returns this value rounded to two decimal places.
|
|
193
|
-
* @param {
|
|
194
|
-
* @param {
|
|
210
|
+
* @param {HTMLElement} target The target element for which to calculate the width percentage.
|
|
211
|
+
* @param {?HTMLElement=} parentTarget The parent element to use as the reference for the width calculation. If not provided, the target's parent element is used.
|
|
195
212
|
* @returns {number}
|
|
196
213
|
*/
|
|
197
214
|
export function getWidthInPercentage(target, parentTarget) {
|
|
198
|
-
const parent = parentTarget || target.parentElement;
|
|
215
|
+
const parent = /** @type {HTMLElement} */ (parentTarget || target.parentElement);
|
|
199
216
|
const parentStyle = _w.getComputedStyle(parent);
|
|
200
|
-
const parentPaddingLeft =
|
|
201
|
-
const parentPaddingRight =
|
|
217
|
+
const parentPaddingLeft = parseFloat(parentStyle.paddingLeft);
|
|
218
|
+
const parentPaddingRight = parseFloat(parentStyle.paddingRight);
|
|
202
219
|
const scrollbarWidth = parent.offsetWidth - parent.clientWidth;
|
|
203
220
|
const parentWidth = parent.offsetWidth - parentPaddingLeft - parentPaddingRight - scrollbarWidth;
|
|
204
221
|
const widthInPercentage = (target.offsetWidth / parentWidth) * 100;
|
|
205
222
|
return widthInPercentage;
|
|
206
223
|
}
|
|
207
224
|
|
|
225
|
+
/**
|
|
226
|
+
* @description Convert url pattern text node to anchor node
|
|
227
|
+
* @param {Node} node Text node
|
|
228
|
+
* @returns {boolean} Return true if the text node is converted to an anchor node
|
|
229
|
+
*/
|
|
230
|
+
export function textToAnchor(node) {
|
|
231
|
+
if (node.nodeType === 3 && URLPattern.test(node.textContent) && !/^A$/i.test(node.parentNode?.nodeName)) {
|
|
232
|
+
const textContent = node.textContent;
|
|
233
|
+
const fragment = _d.createDocumentFragment();
|
|
234
|
+
|
|
235
|
+
let lastIndex = 0;
|
|
236
|
+
textContent.replace(URLPattern, (match, offset) => {
|
|
237
|
+
if (offset > 0) {
|
|
238
|
+
fragment.appendChild(_d.createTextNode(textContent.slice(0, offset)));
|
|
239
|
+
}
|
|
240
|
+
const anchor = _d.createElement('a');
|
|
241
|
+
anchor.href = match;
|
|
242
|
+
anchor.target = '_blank';
|
|
243
|
+
anchor.textContent = match;
|
|
244
|
+
fragment.appendChild(anchor);
|
|
245
|
+
lastIndex = offset + match.length;
|
|
246
|
+
if (lastIndex < textContent.length) {
|
|
247
|
+
fragment.appendChild(_d.createTextNode(textContent.slice(lastIndex)));
|
|
248
|
+
}
|
|
249
|
+
return match;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
node.parentNode.replaceChild(fragment, node);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Converts styles within a <span> tag to corresponding HTML tags (e.g., <strong>, <em>, <u>, <s>).
|
|
261
|
+
* Maintains the original <span> tag and wraps its content with the new tags.
|
|
262
|
+
* @param {{ regex: RegExp, tag: string }} styleToTag An object mapping style properties to HTML tags. ex) {bold: { regex: /font-weight\s*:\s*bold/i, tag: 'strong' },}
|
|
263
|
+
* @param {Node} node Node
|
|
264
|
+
*/
|
|
265
|
+
export function spanToStyleNode(styleToTag, node) {
|
|
266
|
+
if (node.nodeType === 1 && /^SPAN$/i.test(node.nodeName) && /** @type {HTMLElement} */ (node).hasAttribute('style')) {
|
|
267
|
+
const style = /** @type {HTMLElement} */ (node).getAttribute('style');
|
|
268
|
+
const tags = [];
|
|
269
|
+
Object.keys(styleToTag).forEach((key) => {
|
|
270
|
+
if (styleToTag[key].regex.test(style)) {
|
|
271
|
+
const tag = _d.createElement(styleToTag[key].tag);
|
|
272
|
+
tags.push(tag);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (tags.length > 0) {
|
|
277
|
+
const temp = _d.createElement('span');
|
|
278
|
+
let currentNode = node.firstChild;
|
|
279
|
+
|
|
280
|
+
tags.forEach((tag, index) => {
|
|
281
|
+
if (index === 0) {
|
|
282
|
+
temp.appendChild(tag);
|
|
283
|
+
} else {
|
|
284
|
+
tags[index - 1].appendChild(tag);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const parent = tags[tags.length - 1];
|
|
289
|
+
while (currentNode) {
|
|
290
|
+
const nextNode = currentNode.nextSibling;
|
|
291
|
+
parent.appendChild(currentNode);
|
|
292
|
+
currentNode = nextNode;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
while (node.firstChild) {
|
|
296
|
+
node.removeChild(node.firstChild);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
node.appendChild(temp);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Adds a query string to a URL. If the URL already contains a query string, the new query is appended to the existing one.
|
|
306
|
+
* @param {string} url The original URL to which the query string will be added.
|
|
307
|
+
* @param {string} query The query string to be added to the URL.
|
|
308
|
+
* @returns {string} The updated URL with the query string appended.
|
|
309
|
+
*/
|
|
310
|
+
export function addUrlQuery(url, query) {
|
|
311
|
+
if (query.length > 0) {
|
|
312
|
+
if (/\?/.test(url)) {
|
|
313
|
+
const splitUrl = url.split('?');
|
|
314
|
+
url = splitUrl[0] + '?' + query + '&' + splitUrl[1];
|
|
315
|
+
} else {
|
|
316
|
+
url += '?' + query;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return url;
|
|
320
|
+
}
|
|
321
|
+
|
|
208
322
|
/**
|
|
209
323
|
* @description Converts options-related styles and returns them for each frame.
|
|
210
|
-
* @param {
|
|
324
|
+
* @param {Map<string, *>} fo editor.frameOptions
|
|
211
325
|
* @param {string} cssText Style string
|
|
212
326
|
* @returns {{top: string, frame: string, editor: string}}
|
|
213
327
|
* @private
|
|
@@ -252,7 +366,7 @@ export function _setDefaultOptionStyle(fo, cssText) {
|
|
|
252
366
|
|
|
253
367
|
/**
|
|
254
368
|
* @description Set default style tag of the iframe
|
|
255
|
-
* @param {
|
|
369
|
+
* @param {Array<string>} linkNames link names array of CSS files
|
|
256
370
|
* @returns {string} "<link rel="stylesheet" href=".." />.."
|
|
257
371
|
*/
|
|
258
372
|
export function _setIframeStyleLinks(linkNames) {
|
|
@@ -297,6 +411,7 @@ const converter = {
|
|
|
297
411
|
htmlToEntity,
|
|
298
412
|
entityToHTML,
|
|
299
413
|
debounce,
|
|
414
|
+
syncMaps,
|
|
300
415
|
fontSize,
|
|
301
416
|
nodeListToArray,
|
|
302
417
|
swapKeyValue,
|
|
@@ -305,6 +420,9 @@ const converter = {
|
|
|
305
420
|
isHexColor,
|
|
306
421
|
rgb2hex,
|
|
307
422
|
getWidthInPercentage,
|
|
423
|
+
textToAnchor,
|
|
424
|
+
spanToStyleNode,
|
|
425
|
+
addUrlQuery,
|
|
308
426
|
_setDefaultOptionStyle,
|
|
309
427
|
_setIframeStyleLinks,
|
|
310
428
|
_setAutoHeightStyle
|