suneditor 3.0.0-beta.9 → 3.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -57
- package/dist/suneditor-contents.min.css +1 -0
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +110 -61
- package/src/assets/design/color.css +36 -17
- package/src/assets/design/size.css +2 -0
- package/src/assets/icons/defaultIcons.js +17 -2
- package/src/assets/suneditor-contents.css +51 -16
- package/src/assets/suneditor.css +116 -43
- package/src/core/config/contextProvider.js +288 -0
- package/src/core/config/eventManager.js +188 -0
- package/src/core/config/instanceCheck.js +59 -0
- package/src/core/config/optionProvider.js +452 -0
- package/src/core/editor.js +166 -1637
- package/src/core/event/actions/index.js +229 -0
- package/src/core/event/effects/common.registry.js +74 -0
- package/src/core/event/effects/keydown.registry.js +573 -0
- package/src/core/event/effects/ruleHelpers.js +148 -0
- package/src/core/event/eventOrchestrator.js +944 -0
- package/src/core/event/executor.js +27 -0
- package/src/core/{base/eventHandlers → event/handlers}/handler_toolbar.js +27 -28
- package/src/core/{base/eventHandlers → event/handlers}/handler_ww_clipboard.js +10 -8
- package/src/core/{base/eventHandlers → event/handlers}/handler_ww_dragDrop.js +22 -23
- package/src/core/event/handlers/handler_ww_input.js +75 -0
- package/src/core/event/handlers/handler_ww_key.js +228 -0
- package/src/core/event/handlers/handler_ww_mouse.js +166 -0
- package/src/core/event/ports.js +211 -0
- package/src/core/event/reducers/keydown.reducer.js +97 -0
- package/src/core/event/rules/keydown.rule.arrow.js +63 -0
- package/src/core/event/rules/keydown.rule.backspace.js +208 -0
- package/src/core/event/rules/keydown.rule.delete.js +132 -0
- package/src/core/event/rules/keydown.rule.enter.js +150 -0
- package/src/core/event/rules/keydown.rule.tab.js +35 -0
- package/src/core/event/support/defaultLineManager.js +136 -0
- package/src/core/event/support/selectionState.js +204 -0
- package/src/core/kernel/coreKernel.js +320 -0
- package/src/core/kernel/kernelInjector.js +19 -0
- package/src/core/kernel/store.js +173 -0
- package/src/core/{class → logic/dom}/char.js +42 -45
- package/src/core/logic/dom/format.js +1075 -0
- package/src/core/{class → logic/dom}/html.js +743 -624
- package/src/core/logic/dom/inline.js +1847 -0
- package/src/core/logic/dom/listFormat.js +601 -0
- package/src/core/{class → logic/dom}/nodeTransform.js +92 -72
- package/src/core/{class → logic/dom}/offset.js +254 -317
- package/src/core/logic/dom/selection.js +754 -0
- package/src/core/logic/panel/menu.js +389 -0
- package/src/core/logic/panel/toolbar.js +449 -0
- package/src/core/logic/panel/viewer.js +761 -0
- package/src/core/logic/shell/_commandExecutor.js +380 -0
- package/src/core/logic/shell/commandDispatcher.js +241 -0
- package/src/core/logic/shell/component.js +970 -0
- package/src/core/logic/shell/focusManager.js +110 -0
- package/src/core/{base → logic/shell}/history.js +110 -60
- package/src/core/logic/shell/pluginManager.js +363 -0
- package/src/core/logic/shell/shortcuts.js +130 -0
- package/src/core/logic/shell/ui.js +904 -0
- package/src/core/schema/context.js +66 -0
- package/src/core/schema/frameContext.js +160 -0
- package/src/core/schema/options.js +628 -0
- package/src/core/section/constructor.js +194 -500
- package/src/core/section/documentType.js +297 -222
- package/src/events.js +808 -543
- package/src/helper/clipboard.js +27 -16
- package/src/helper/converter.js +100 -78
- package/src/helper/dom/domCheck.js +56 -30
- package/src/helper/dom/domQuery.js +159 -89
- package/src/helper/dom/domUtils.js +114 -49
- package/src/helper/dom/index.js +5 -1
- package/src/helper/env.js +26 -26
- package/src/helper/index.js +1 -1
- package/src/helper/keyCodeMap.js +25 -28
- package/src/helper/numbers.js +4 -8
- package/src/helper/unicode.js +4 -8
- package/src/hooks/base.js +307 -0
- package/src/hooks/params.js +130 -0
- package/src/interfaces/contracts.js +227 -0
- package/src/interfaces/index.js +7 -0
- package/src/interfaces/plugins.js +239 -0
- package/src/langs/ckb.js +4 -4
- package/src/langs/cs.js +4 -4
- package/src/langs/da.js +4 -4
- package/src/langs/de.js +4 -4
- package/src/langs/en.js +4 -4
- package/src/langs/es.js +4 -4
- package/src/langs/fa.js +4 -4
- package/src/langs/fr.js +4 -4
- package/src/langs/he.js +4 -4
- package/src/langs/hu.js +4 -4
- package/src/langs/it.js +4 -4
- package/src/langs/ja.js +4 -4
- package/src/langs/km.js +4 -4
- package/src/langs/ko.js +4 -4
- package/src/langs/lv.js +4 -4
- package/src/langs/nl.js +4 -4
- package/src/langs/pl.js +4 -4
- package/src/langs/pt_br.js +13 -13
- package/src/langs/ro.js +4 -4
- package/src/langs/ru.js +4 -4
- package/src/langs/se.js +4 -4
- package/src/langs/tr.js +4 -4
- package/src/langs/uk.js +4 -4
- package/src/langs/ur.js +4 -4
- package/src/langs/zh_cn.js +4 -4
- package/src/modules/{Browser.js → contract/Browser.js} +119 -128
- package/src/modules/{ColorPicker.js → contract/ColorPicker.js} +132 -142
- package/src/modules/contract/Controller.js +589 -0
- package/src/modules/{Figure.js → contract/Figure.js} +591 -411
- package/src/modules/{HueSlider.js → contract/HueSlider.js} +125 -86
- package/src/modules/contract/Modal.js +357 -0
- package/src/modules/contract/index.js +9 -0
- package/src/modules/manager/ApiManager.js +197 -0
- package/src/modules/{FileManager.js → manager/FileManager.js} +128 -160
- package/src/modules/manager/index.js +5 -0
- package/src/modules/{ModalAnchorEditor.js → ui/ModalAnchorEditor.js} +108 -138
- package/src/modules/{SelectMenu.js → ui/SelectMenu.js} +119 -120
- package/src/modules/{_DragHandle.js → ui/_DragHandle.js} +1 -1
- package/src/modules/ui/index.js +6 -0
- package/src/plugins/browser/audioGallery.js +23 -26
- package/src/plugins/browser/fileBrowser.js +25 -28
- package/src/plugins/browser/fileGallery.js +20 -23
- package/src/plugins/browser/imageGallery.js +24 -23
- package/src/plugins/browser/videoGallery.js +27 -29
- package/src/plugins/command/blockquote.js +11 -17
- package/src/plugins/command/exportPDF.js +26 -26
- package/src/plugins/command/fileUpload.js +138 -133
- package/src/plugins/command/list_bulleted.js +48 -44
- package/src/plugins/command/list_numbered.js +48 -44
- package/src/plugins/dropdown/align.js +64 -50
- package/src/plugins/dropdown/backgroundColor.js +34 -35
- package/src/plugins/dropdown/{formatBlock.js → blockStyle.js} +43 -37
- package/src/plugins/dropdown/font.js +50 -36
- package/src/plugins/dropdown/fontColor.js +34 -35
- package/src/plugins/dropdown/hr.js +55 -50
- package/src/plugins/dropdown/layout.js +20 -15
- package/src/plugins/dropdown/lineHeight.js +46 -30
- package/src/plugins/dropdown/list.js +32 -33
- package/src/plugins/dropdown/paragraphStyle.js +40 -34
- package/src/plugins/dropdown/table/index.js +915 -0
- package/src/plugins/dropdown/table/render/table.html.js +308 -0
- package/src/plugins/dropdown/table/render/table.menu.js +121 -0
- package/src/plugins/dropdown/table/services/table.cell.js +465 -0
- package/src/plugins/dropdown/table/services/table.clipboard.js +414 -0
- package/src/plugins/dropdown/table/services/table.grid.js +504 -0
- package/src/plugins/dropdown/table/services/table.resize.js +463 -0
- package/src/plugins/dropdown/table/services/table.selection.js +466 -0
- package/src/plugins/dropdown/table/services/table.style.js +844 -0
- package/src/plugins/dropdown/table/shared/table.constants.js +109 -0
- package/src/plugins/dropdown/table/shared/table.utils.js +219 -0
- package/src/plugins/dropdown/template.js +20 -15
- package/src/plugins/dropdown/textStyle.js +28 -22
- package/src/plugins/field/mention.js +54 -49
- package/src/plugins/index.js +5 -5
- package/src/plugins/input/fontSize.js +100 -97
- package/src/plugins/input/pageNavigator.js +13 -10
- package/src/plugins/modal/audio.js +208 -219
- package/src/plugins/modal/drawing.js +99 -104
- package/src/plugins/modal/embed.js +323 -312
- package/src/plugins/modal/image/index.js +942 -0
- package/src/plugins/modal/image/render/image.html.js +150 -0
- package/src/plugins/modal/image/services/image.size.js +198 -0
- package/src/plugins/modal/image/services/image.upload.js +216 -0
- package/src/plugins/modal/image/shared/image.constants.js +20 -0
- package/src/plugins/modal/link.js +74 -54
- package/src/plugins/modal/math.js +126 -119
- package/src/plugins/modal/video/index.js +858 -0
- package/src/plugins/modal/video/render/video.html.js +131 -0
- package/src/plugins/modal/video/services/video.size.js +281 -0
- package/src/plugins/modal/video/services/video.upload.js +92 -0
- package/src/plugins/popup/anchor.js +57 -49
- package/src/suneditor.js +73 -61
- package/src/themes/cobalt.css +155 -0
- package/src/themes/dark.css +143 -120
- package/src/typedef.js +214 -63
- package/types/assets/icons/defaultIcons.d.ts +8 -0
- package/types/assets/suneditor-contents.css.d.ts +1 -0
- package/types/assets/suneditor.css.d.ts +1 -0
- package/types/core/config/contextProvider.d.ts +148 -0
- package/types/core/config/eventManager.d.ts +68 -0
- package/types/core/config/instanceCheck.d.ts +33 -0
- package/types/core/config/optionProvider.d.ts +147 -0
- package/types/core/editor.d.ts +27 -586
- package/types/core/event/actions/index.d.ts +50 -0
- package/types/core/event/effects/common.registry.d.ts +56 -0
- package/types/core/event/effects/keydown.registry.d.ts +80 -0
- package/types/core/event/effects/ruleHelpers.d.ts +36 -0
- package/types/core/event/eventOrchestrator.d.ts +191 -0
- package/types/core/event/executor.d.ts +13 -0
- package/types/core/event/handlers/handler_toolbar.d.ts +38 -0
- package/types/core/event/handlers/handler_ww_clipboard.d.ts +36 -0
- package/types/core/event/handlers/handler_ww_dragDrop.d.ts +26 -0
- package/types/core/event/handlers/handler_ww_input.d.ts +38 -0
- package/types/core/event/handlers/handler_ww_key.d.ts +40 -0
- package/types/core/event/handlers/handler_ww_mouse.d.ts +47 -0
- package/types/core/event/ports.d.ts +256 -0
- package/types/core/event/reducers/keydown.reducer.d.ts +84 -0
- package/types/core/event/rules/keydown.rule.arrow.d.ts +19 -0
- package/types/core/event/rules/keydown.rule.backspace.d.ts +18 -0
- package/types/core/event/rules/keydown.rule.delete.d.ts +18 -0
- package/types/core/event/rules/keydown.rule.enter.d.ts +18 -0
- package/types/core/event/rules/keydown.rule.tab.d.ts +18 -0
- package/types/core/event/support/defaultLineManager.d.ts +22 -0
- package/types/core/event/support/selectionState.d.ts +29 -0
- package/types/core/kernel/coreKernel.d.ts +219 -0
- package/types/core/kernel/kernelInjector.d.ts +16 -0
- package/types/core/kernel/store.d.ts +170 -0
- package/types/core/logic/dom/char.d.ts +46 -0
- package/types/core/logic/dom/format.d.ts +234 -0
- package/types/core/logic/dom/html.d.ts +290 -0
- package/types/core/logic/dom/inline.d.ts +93 -0
- package/types/core/logic/dom/listFormat.d.ts +101 -0
- package/types/core/logic/dom/nodeTransform.d.ts +110 -0
- package/types/core/logic/dom/offset.d.ts +335 -0
- package/types/core/logic/dom/selection.d.ts +165 -0
- package/types/core/logic/panel/menu.d.ts +93 -0
- package/types/core/logic/panel/toolbar.d.ts +128 -0
- package/types/core/logic/panel/viewer.d.ts +89 -0
- package/types/core/logic/shell/_commandExecutor.d.ts +18 -0
- package/types/core/logic/shell/commandDispatcher.d.ts +65 -0
- package/types/core/logic/shell/component.d.ts +182 -0
- package/types/core/logic/shell/focusManager.d.ts +31 -0
- package/types/core/{base → logic/shell}/history.d.ts +13 -12
- package/types/core/logic/shell/pluginManager.d.ts +115 -0
- package/types/core/logic/shell/shortcuts.d.ts +131 -0
- package/types/core/logic/shell/ui.d.ts +261 -0
- package/types/core/schema/context.d.ts +104 -0
- package/types/core/schema/frameContext.d.ts +320 -0
- package/types/core/schema/options.d.ts +1241 -0
- package/types/core/section/constructor.d.ts +117 -652
- package/types/core/section/documentType.d.ts +43 -61
- package/types/events.d.ts +796 -65
- package/types/helper/clipboard.d.ts +5 -4
- package/types/helper/converter.d.ts +55 -43
- package/types/helper/dom/domCheck.d.ts +27 -19
- package/types/helper/dom/domQuery.d.ts +76 -57
- package/types/helper/dom/domUtils.d.ts +62 -39
- package/types/helper/dom/index.d.ts +87 -1
- package/types/helper/env.d.ts +16 -13
- package/types/helper/index.d.ts +8 -2
- package/types/helper/keyCodeMap.d.ts +24 -23
- package/types/helper/numbers.d.ts +4 -6
- package/types/helper/unicode.d.ts +4 -3
- package/types/hooks/base.d.ts +239 -0
- package/types/hooks/params.d.ts +65 -0
- package/types/index.d.ts +20 -117
- package/types/interfaces/contracts.d.ts +183 -0
- package/types/interfaces/index.d.ts +3 -0
- package/types/interfaces/plugins.d.ts +168 -0
- package/types/langs/_Lang.d.ts +2 -2
- package/types/langs/index.d.ts +2 -2
- package/types/modules/contract/Browser.d.ts +262 -0
- package/types/modules/contract/ColorPicker.d.ts +99 -0
- package/types/modules/contract/Controller.d.ts +204 -0
- package/types/modules/contract/Figure.d.ts +529 -0
- package/types/modules/{HueSlider.d.ts → contract/HueSlider.d.ts} +39 -28
- package/types/modules/contract/Modal.d.ts +62 -0
- package/types/modules/contract/index.d.ts +7 -0
- package/types/modules/manager/ApiManager.d.ts +106 -0
- package/types/modules/manager/FileManager.d.ts +124 -0
- package/types/modules/manager/index.d.ts +3 -0
- package/types/modules/ui/ModalAnchorEditor.d.ts +152 -0
- package/types/modules/ui/SelectMenu.d.ts +107 -0
- package/types/modules/{_DragHandle.d.ts → ui/_DragHandle.d.ts} +1 -0
- package/types/modules/ui/index.d.ts +4 -0
- package/types/plugins/browser/audioGallery.d.ts +33 -41
- package/types/plugins/browser/fileBrowser.d.ts +42 -50
- package/types/plugins/browser/fileGallery.d.ts +33 -41
- package/types/plugins/browser/imageGallery.d.ts +30 -37
- package/types/plugins/browser/videoGallery.d.ts +33 -41
- package/types/plugins/command/blockquote.d.ts +4 -21
- package/types/plugins/command/exportPDF.d.ts +23 -33
- package/types/plugins/command/fileUpload.d.ts +80 -100
- package/types/plugins/command/list_bulleted.d.ts +9 -35
- package/types/plugins/command/list_numbered.d.ts +9 -35
- package/types/plugins/dropdown/align.d.ts +23 -46
- package/types/plugins/dropdown/backgroundColor.d.ts +35 -53
- package/types/plugins/dropdown/blockStyle.d.ts +45 -0
- package/types/plugins/dropdown/font.d.ts +18 -41
- package/types/plugins/dropdown/fontColor.d.ts +35 -53
- package/types/plugins/dropdown/hr.d.ts +26 -52
- package/types/plugins/dropdown/layout.d.ts +19 -25
- package/types/plugins/dropdown/lineHeight.d.ts +21 -39
- package/types/plugins/dropdown/list.d.ts +6 -34
- package/types/plugins/dropdown/paragraphStyle.d.ts +34 -45
- package/types/plugins/dropdown/table/index.d.ts +158 -0
- package/types/plugins/dropdown/table/render/table.html.d.ts +71 -0
- package/types/plugins/dropdown/table/render/table.menu.d.ts +59 -0
- package/types/plugins/dropdown/table/services/table.cell.d.ts +76 -0
- package/types/plugins/dropdown/table/services/table.clipboard.d.ts +26 -0
- package/types/plugins/dropdown/table/services/table.grid.d.ts +77 -0
- package/types/plugins/dropdown/table/services/table.resize.d.ts +72 -0
- package/types/plugins/dropdown/table/services/table.selection.d.ts +59 -0
- package/types/plugins/dropdown/table/services/table.style.d.ts +162 -0
- package/types/plugins/dropdown/table/shared/table.constants.d.ts +134 -0
- package/types/plugins/dropdown/table/shared/table.utils.d.ts +91 -0
- package/types/plugins/dropdown/template.d.ts +19 -25
- package/types/plugins/dropdown/textStyle.d.ts +23 -30
- package/types/plugins/field/mention.d.ts +66 -72
- package/types/plugins/index.d.ts +41 -40
- package/types/plugins/input/fontSize.d.ts +57 -96
- package/types/plugins/input/pageNavigator.d.ts +5 -8
- package/types/plugins/modal/audio.d.ts +60 -153
- package/types/plugins/modal/drawing.d.ts +16 -118
- package/types/plugins/modal/embed.d.ts +46 -166
- package/types/plugins/modal/image/index.d.ts +281 -0
- package/types/plugins/modal/image/render/image.html.d.ts +45 -0
- package/types/plugins/modal/image/services/image.size.d.ts +55 -0
- package/types/plugins/modal/image/services/image.upload.d.ts +24 -0
- package/types/plugins/modal/image/shared/image.constants.d.ts +17 -0
- package/types/plugins/modal/link.d.ts +46 -66
- package/types/plugins/modal/math.d.ts +17 -86
- package/types/plugins/modal/{video.d.ts → video/index.d.ts} +89 -221
- package/types/plugins/modal/video/render/video.html.d.ts +37 -0
- package/types/plugins/modal/video/services/video.size.d.ts +74 -0
- package/types/plugins/modal/video/services/video.upload.d.ts +19 -0
- package/types/plugins/popup/anchor.d.ts +8 -38
- package/types/suneditor.d.ts +55 -24
- package/types/typedef.d.ts +344 -228
- package/CONTRIBUTING.md +0 -186
- package/src/core/base/eventHandlers/handler_ww_key_input.js +0 -1200
- package/src/core/base/eventHandlers/handler_ww_mouse.js +0 -194
- package/src/core/base/eventManager.js +0 -1523
- package/src/core/class/component.js +0 -856
- package/src/core/class/format.js +0 -3433
- package/src/core/class/menu.js +0 -346
- package/src/core/class/selection.js +0 -610
- package/src/core/class/shortcuts.js +0 -98
- package/src/core/class/toolbar.js +0 -431
- package/src/core/class/ui.js +0 -424
- package/src/core/class/viewer.js +0 -750
- package/src/core/section/actives.js +0 -266
- package/src/core/section/context.js +0 -102
- package/src/editorInjector/_classes.js +0 -36
- package/src/editorInjector/_core.js +0 -87
- package/src/editorInjector/index.js +0 -73
- package/src/modules/ApiManager.js +0 -191
- package/src/modules/Controller.js +0 -474
- package/src/modules/Modal.js +0 -346
- package/src/modules/index.js +0 -14
- package/src/plugins/dropdown/table.js +0 -4034
- package/src/plugins/modal/image.js +0 -1376
- package/src/plugins/modal/video.js +0 -1226
- package/types/core/base/eventHandlers/handler_toolbar.d.ts +0 -41
- package/types/core/base/eventHandlers/handler_ww_clipboard.d.ts +0 -40
- package/types/core/base/eventHandlers/handler_ww_dragDrop.d.ts +0 -35
- package/types/core/base/eventHandlers/handler_ww_key_input.d.ts +0 -45
- package/types/core/base/eventHandlers/handler_ww_mouse.d.ts +0 -39
- package/types/core/base/eventManager.d.ts +0 -401
- package/types/core/class/char.d.ts +0 -61
- package/types/core/class/component.d.ts +0 -213
- package/types/core/class/format.d.ts +0 -623
- package/types/core/class/html.d.ts +0 -430
- package/types/core/class/menu.d.ts +0 -126
- package/types/core/class/nodeTransform.d.ts +0 -93
- package/types/core/class/offset.d.ts +0 -522
- package/types/core/class/selection.d.ts +0 -188
- package/types/core/class/shortcuts.d.ts +0 -142
- package/types/core/class/toolbar.d.ts +0 -189
- package/types/core/class/ui.d.ts +0 -164
- package/types/core/class/viewer.d.ts +0 -140
- package/types/core/section/actives.d.ts +0 -46
- package/types/core/section/context.d.ts +0 -45
- package/types/editorInjector/_classes.d.ts +0 -41
- package/types/editorInjector/_core.d.ts +0 -87
- package/types/editorInjector/index.d.ts +0 -69
- package/types/modules/ApiManager.d.ts +0 -125
- package/types/modules/Browser.d.ts +0 -326
- package/types/modules/ColorPicker.d.ts +0 -135
- package/types/modules/Controller.d.ts +0 -251
- package/types/modules/Figure.d.ts +0 -517
- package/types/modules/FileManager.d.ts +0 -202
- package/types/modules/Modal.d.ts +0 -111
- package/types/modules/ModalAnchorEditor.d.ts +0 -236
- package/types/modules/SelectMenu.d.ts +0 -194
- package/types/modules/index.d.ts +0 -26
- package/types/plugins/dropdown/formatBlock.d.ts +0 -55
- package/types/plugins/dropdown/table.d.ts +0 -627
- package/types/plugins/modal/image.d.ts +0 -451
- /package/{LICENSE → LICENSE.txt} +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { dom } from '../../../../helper';
|
|
2
|
+
import { Modal } from '../../../../modules/contract';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} ModalReturns_image
|
|
6
|
+
* @property {HTMLElement} html
|
|
7
|
+
* @property {HTMLElement} alignForm
|
|
8
|
+
* @property {HTMLElement} fileModalWrapper
|
|
9
|
+
* @property {HTMLInputElement} imgInputFile
|
|
10
|
+
* @property {HTMLInputElement} imgUrlFile
|
|
11
|
+
* @property {HTMLInputElement} altText
|
|
12
|
+
* @property {HTMLInputElement} captionCheckEl
|
|
13
|
+
* @property {HTMLElement} previewSrc
|
|
14
|
+
* @property {HTMLElement} tabs
|
|
15
|
+
* @property {HTMLButtonElement} galleryButton
|
|
16
|
+
* @property {HTMLInputElement} proportion
|
|
17
|
+
* @property {HTMLInputElement} inputX
|
|
18
|
+
* @property {HTMLInputElement} inputY
|
|
19
|
+
* @property {HTMLButtonElement} revertBtn
|
|
20
|
+
* @property {HTMLButtonElement} asBlock
|
|
21
|
+
* @property {HTMLButtonElement} asInline
|
|
22
|
+
* @property {HTMLButtonElement} fileRemoveBtn
|
|
23
|
+
*
|
|
24
|
+
* @param {SunEditor.Deps} $
|
|
25
|
+
* @param {*} pluginOptions
|
|
26
|
+
* @returns {ModalReturns_image}
|
|
27
|
+
*/
|
|
28
|
+
export function CreateHTML_modal({ lang, icons, plugins }, pluginOptions) {
|
|
29
|
+
const createFileInputHtml = !pluginOptions.createFileInput
|
|
30
|
+
? ''
|
|
31
|
+
: /*html*/ `
|
|
32
|
+
<div class="se-modal-form">
|
|
33
|
+
<label>${lang.image_modal_file}</label>
|
|
34
|
+
${Modal.CreateFileInput({ icons, lang }, pluginOptions)}
|
|
35
|
+
</div>`;
|
|
36
|
+
|
|
37
|
+
const createUrlInputHtml = !pluginOptions.createUrlInput
|
|
38
|
+
? ''
|
|
39
|
+
: /*html*/ `
|
|
40
|
+
<div class="se-modal-form">
|
|
41
|
+
<label>${lang.image_modal_url}</label>
|
|
42
|
+
<div class="se-modal-form-files">
|
|
43
|
+
<input class="se-input-form se-input-url" data-focus type="text" />
|
|
44
|
+
${
|
|
45
|
+
plugins.imageGallery
|
|
46
|
+
? `<button type="button" class="se-btn se-tooltip se-modal-files-edge-button __se__gallery" aria-label="${lang.imageGallery}">
|
|
47
|
+
${icons.image_gallery}
|
|
48
|
+
${dom.utils.createTooltipInner(lang.imageGallery)}
|
|
49
|
+
</button>`
|
|
50
|
+
: ''
|
|
51
|
+
}
|
|
52
|
+
</div>
|
|
53
|
+
<pre class="se-link-preview"></pre>
|
|
54
|
+
</div>`;
|
|
55
|
+
|
|
56
|
+
const canResizeHtml = !pluginOptions.canResize
|
|
57
|
+
? ''
|
|
58
|
+
: /*html*/ `
|
|
59
|
+
<div class="se-modal-form">
|
|
60
|
+
<div class="se-modal-size-text">
|
|
61
|
+
<label class="size-w">${lang.width}</label>
|
|
62
|
+
<label class="se-modal-size-x"> </label>
|
|
63
|
+
<label class="size-h">${lang.height}</label>
|
|
64
|
+
</div>
|
|
65
|
+
<input class="se-input-control _se_size_x" placeholder="auto" type="text" />
|
|
66
|
+
<label class="se-modal-size-x">x</label>
|
|
67
|
+
<input type="text" class="se-input-control _se_size_y" placeholder="auto" />
|
|
68
|
+
<label><input type="checkbox" class="se-modal-btn-check _se_check_proportion" checked/> ${lang.proportion}</label>
|
|
69
|
+
<button type="button" aria-label="${lang.revert}" class="se-btn se-tooltip se-modal-btn-revert">
|
|
70
|
+
${icons.revert}
|
|
71
|
+
${dom.utils.createTooltipInner(lang.revert)}
|
|
72
|
+
</button>
|
|
73
|
+
</div>`;
|
|
74
|
+
|
|
75
|
+
const useFormatTypeHtml = !pluginOptions.useFormatType
|
|
76
|
+
? ''
|
|
77
|
+
: /*html*/ `
|
|
78
|
+
<div class="se-modal-form">
|
|
79
|
+
<div class="se-modal-flex-form">
|
|
80
|
+
<button type="button" data-command="asBlock" class="se-btn se-tooltip" aria-label="${lang.inlineStyle}">
|
|
81
|
+
${icons.as_block}
|
|
82
|
+
${dom.utils.createTooltipInner(lang.blockStyle)}
|
|
83
|
+
</button>
|
|
84
|
+
<button type="button" data-command="asInline" class="se-btn se-tooltip" aria-label="${lang.inlineStyle}">
|
|
85
|
+
${icons.as_inline}
|
|
86
|
+
${dom.utils.createTooltipInner(lang.inlineStyle)}
|
|
87
|
+
</button>
|
|
88
|
+
</div>
|
|
89
|
+
</div>`;
|
|
90
|
+
|
|
91
|
+
const html = /*html*/ `
|
|
92
|
+
<div class="se-modal-header">
|
|
93
|
+
<button type="button" data-command="close" class="se-btn se-close-btn close" title="${lang.close}" aria-label="${lang.close}">${icons.cancel}</button>
|
|
94
|
+
<span class="se-modal-title">${lang.image_modal_title}</span>
|
|
95
|
+
</div>
|
|
96
|
+
<div class="se-modal-tabs">
|
|
97
|
+
<button type="button" class="_se_tab_link active" data-tab-link="image">${lang.image}</button>
|
|
98
|
+
<button type="button" class="_se_tab_link" data-tab-link="url">${lang.link}</button>
|
|
99
|
+
</div>
|
|
100
|
+
<form method="post" enctype="multipart/form-data">
|
|
101
|
+
<div class="_se_tab_content _se_tab_content_image">
|
|
102
|
+
<div class="se-modal-body">
|
|
103
|
+
${createFileInputHtml}
|
|
104
|
+
${createUrlInputHtml}
|
|
105
|
+
<div class="se-modal-hr"></div>
|
|
106
|
+
<div class="se-modal-form">
|
|
107
|
+
<label>${lang.image_modal_altText}</label><input class="se-input-form _se_image_alt" type="text" />
|
|
108
|
+
</div>
|
|
109
|
+
${canResizeHtml}
|
|
110
|
+
${useFormatTypeHtml}
|
|
111
|
+
<div class="se-modal-form se-modal-form-footer">
|
|
112
|
+
<label><input type="checkbox" class="se-modal-btn-check _se_image_check_caption" /> ${lang.caption}</label>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
<div class="se-anchor-editor _se_tab_content _se_tab_content_url" style="display: none;">
|
|
117
|
+
</div>
|
|
118
|
+
<div class="se-modal-footer">
|
|
119
|
+
<div class="se-figure-align">
|
|
120
|
+
<label><input type="radio" name="suneditor_image_radio" class="se-modal-btn-radio" value="none" checked>${lang.basic}</label>
|
|
121
|
+
<label><input type="radio" name="suneditor_image_radio" class="se-modal-btn-radio" value="left">${lang.left}</label>
|
|
122
|
+
<label><input type="radio" name="suneditor_image_radio" class="se-modal-btn-radio" value="center">${lang.center}</label>
|
|
123
|
+
<label><input type="radio" name="suneditor_image_radio" class="se-modal-btn-radio" value="right">${lang.right}</label>
|
|
124
|
+
</div>
|
|
125
|
+
<button type="submit" class="se-btn-primary" title="${lang.submitButton}" aria-label="${lang.submitButton}"><span>${lang.submitButton}</span></button>
|
|
126
|
+
</div>
|
|
127
|
+
</form>`;
|
|
128
|
+
|
|
129
|
+
const content = dom.utils.createElement('DIV', { class: 'se-modal-content' }, html);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
html: content,
|
|
133
|
+
alignForm: content.querySelector('.se-figure-align'),
|
|
134
|
+
fileModalWrapper: content.querySelector('.se-flex-input-wrapper'),
|
|
135
|
+
imgInputFile: content.querySelector('.__se__file_input'),
|
|
136
|
+
imgUrlFile: content.querySelector('.se-input-url'),
|
|
137
|
+
altText: content.querySelector('._se_image_alt'),
|
|
138
|
+
captionCheckEl: content.querySelector('._se_image_check_caption'),
|
|
139
|
+
previewSrc: content.querySelector('._se_tab_content_image .se-link-preview'),
|
|
140
|
+
tabs: content.querySelector('.se-modal-tabs'),
|
|
141
|
+
galleryButton: content.querySelector('.__se__gallery'),
|
|
142
|
+
proportion: content.querySelector('._se_check_proportion'),
|
|
143
|
+
inputX: content.querySelector('._se_size_x'),
|
|
144
|
+
inputY: content.querySelector('._se_size_y'),
|
|
145
|
+
revertBtn: content.querySelector('.se-modal-btn-revert'),
|
|
146
|
+
asBlock: content.querySelector('[data-command="asBlock"]'),
|
|
147
|
+
asInline: content.querySelector('[data-command="asInline"]'),
|
|
148
|
+
fileRemoveBtn: content.querySelector('.se-file-remove'),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { keyCodeMap } from '../../../../helper';
|
|
2
|
+
import { Figure } from '../../../../modules/contract';
|
|
3
|
+
import { SIZE_UNIT } from '../shared/image.constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @class ImageSizeService
|
|
7
|
+
* @description Handles image resizing, proportion calculations, and size input management.
|
|
8
|
+
*/
|
|
9
|
+
export class ImageSizeService {
|
|
10
|
+
#main;
|
|
11
|
+
#$;
|
|
12
|
+
#state;
|
|
13
|
+
#pluginOptions;
|
|
14
|
+
|
|
15
|
+
#resizing;
|
|
16
|
+
#origin_w;
|
|
17
|
+
#origin_h;
|
|
18
|
+
|
|
19
|
+
#ratio = { w: 0, h: 0 };
|
|
20
|
+
#proportion = null;
|
|
21
|
+
#inputX = null;
|
|
22
|
+
#inputY = null;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('../index').default} main - The main Image_ plugin instance.
|
|
26
|
+
* @param {import('../render/image.html').ModalReturns_image} modalEl - Modal element
|
|
27
|
+
*/
|
|
28
|
+
constructor(main, modalEl) {
|
|
29
|
+
this.#main = main;
|
|
30
|
+
this.#$ = main.$;
|
|
31
|
+
this.#state = main.state;
|
|
32
|
+
this.#pluginOptions = main.pluginOptions;
|
|
33
|
+
|
|
34
|
+
this.#resizing = this.#pluginOptions.canResize;
|
|
35
|
+
this.#origin_w = this.#pluginOptions.defaultWidth === 'auto' ? '' : this.#pluginOptions.defaultWidth;
|
|
36
|
+
this.#origin_h = this.#pluginOptions.defaultHeight === 'auto' ? '' : this.#pluginOptions.defaultHeight;
|
|
37
|
+
|
|
38
|
+
if (this.#resizing) {
|
|
39
|
+
this.#proportion = modalEl.proportion;
|
|
40
|
+
this.#inputX = modalEl.inputX;
|
|
41
|
+
this.#inputY = modalEl.inputY;
|
|
42
|
+
this.#inputX.value = this.#pluginOptions.defaultWidth;
|
|
43
|
+
this.#inputY.value = this.#pluginOptions.defaultHeight;
|
|
44
|
+
|
|
45
|
+
const ratioChange = this.#OnChangeRatio.bind(this);
|
|
46
|
+
this.#$.eventManager.addEvent(this.#inputX, 'keyup', this.#OnInputSize.bind(this, 'x'));
|
|
47
|
+
this.#$.eventManager.addEvent(this.#inputY, 'keyup', this.#OnInputSize.bind(this, 'y'));
|
|
48
|
+
this.#$.eventManager.addEvent(this.#inputX, 'change', ratioChange);
|
|
49
|
+
this.#$.eventManager.addEvent(this.#inputY, 'change', ratioChange);
|
|
50
|
+
this.#$.eventManager.addEvent(this.#proportion, 'change', ratioChange);
|
|
51
|
+
this.#$.eventManager.addEvent(modalEl.revertBtn, 'click', this.#OnClickRevert.bind(this));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description Sets the width and height input values.
|
|
57
|
+
* @param {string} w - Width value
|
|
58
|
+
* @param {string} h - Height value
|
|
59
|
+
*/
|
|
60
|
+
setInputSize(w, h) {
|
|
61
|
+
this.#inputX.value = w === 'auto' ? '' : w;
|
|
62
|
+
|
|
63
|
+
if (this.#state.onlyPercentage) return;
|
|
64
|
+
this.#inputY.value = h === 'auto' ? '' : h;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @description Gets the current width and height input values.
|
|
69
|
+
* @returns {{w: string, h: string}}
|
|
70
|
+
*/
|
|
71
|
+
getInputSize() {
|
|
72
|
+
return {
|
|
73
|
+
w: this.#inputX?.value || '',
|
|
74
|
+
h: this.#inputY?.value || '',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @description Sets the original width and height of the image.
|
|
80
|
+
* @param {string} w - Original width
|
|
81
|
+
* @param {string} h - Original height
|
|
82
|
+
*/
|
|
83
|
+
setOriginSize(w, h) {
|
|
84
|
+
this.#origin_w = w;
|
|
85
|
+
this.#origin_h = h;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @description Applies the specified width and height to the image.
|
|
90
|
+
* @param {string} w - Image width.
|
|
91
|
+
* @param {string} h - Image height.
|
|
92
|
+
*/
|
|
93
|
+
applySize(w, h) {
|
|
94
|
+
w ||= this.#inputX?.value || this.#pluginOptions.defaultWidth;
|
|
95
|
+
h ||= this.#inputY?.value || this.#pluginOptions.defaultHeight;
|
|
96
|
+
|
|
97
|
+
if (this.#state.onlyPercentage) {
|
|
98
|
+
if (!w) w = '100%';
|
|
99
|
+
else if (!/%$/.test(w)) w += SIZE_UNIT.PERCENTAGE;
|
|
100
|
+
}
|
|
101
|
+
this.#main.figure.setSize(w, h);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @description Called when the modal is opened. Resets size inputs to default.
|
|
106
|
+
*/
|
|
107
|
+
on() {
|
|
108
|
+
if (!this.#resizing) return;
|
|
109
|
+
|
|
110
|
+
const x = this.#pluginOptions.defaultWidth;
|
|
111
|
+
const y = this.#pluginOptions.defaultHeight;
|
|
112
|
+
this.setInputSize(x, y);
|
|
113
|
+
this.setOriginSize(x, y);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @description Prepares the size inputs and proportion state when an image is selected.
|
|
118
|
+
* @param {SunEditor.Module.Figure.TargetInfo} figureInfo - Figure size information
|
|
119
|
+
* @param {string} w - Current width
|
|
120
|
+
* @param {string} h - Current height
|
|
121
|
+
*/
|
|
122
|
+
ready(figureInfo, w, h) {
|
|
123
|
+
this.setInputSize(w, h);
|
|
124
|
+
|
|
125
|
+
const percentageRotation = this.#state.onlyPercentage && this.#main.figure.isVertical;
|
|
126
|
+
this.#proportion.checked = true;
|
|
127
|
+
this.#inputX.disabled = percentageRotation;
|
|
128
|
+
this.#inputY.disabled = percentageRotation;
|
|
129
|
+
this.#proportion.disabled = percentageRotation;
|
|
130
|
+
|
|
131
|
+
this.#ratio = this.#proportion.checked
|
|
132
|
+
? figureInfo.ratio
|
|
133
|
+
: {
|
|
134
|
+
w: 0,
|
|
135
|
+
h: 0,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @description Initializes the size service state.
|
|
141
|
+
*/
|
|
142
|
+
init() {
|
|
143
|
+
this.#ratio = {
|
|
144
|
+
w: 0,
|
|
145
|
+
h: 0,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
if (this.#resizing) {
|
|
149
|
+
this.setInputSize(this.#pluginOptions.defaultWidth, this.#pluginOptions.defaultHeight);
|
|
150
|
+
this.#proportion.checked = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @description Handles keyup events on size inputs to calculate proportion.
|
|
156
|
+
* @param {'x'|'y'} xy - Axis (`'x'` for width, `'y'` for height)
|
|
157
|
+
* @param {KeyboardEvent} e - Event object
|
|
158
|
+
*/
|
|
159
|
+
#OnInputSize(xy, e) {
|
|
160
|
+
if (keyCodeMap.isSpace(e.code)) {
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const target = /** @type {HTMLInputElement} */ (e.target);
|
|
166
|
+
if (xy === 'x' && this.#state.onlyPercentage && Number(target.value) > 100) {
|
|
167
|
+
target.value = '100';
|
|
168
|
+
} else if (this.#proportion.checked) {
|
|
169
|
+
const ratioSize = Figure.CalcRatio(this.#inputX.value, this.#inputY.value, this.#state.sizeUnit, this.#ratio);
|
|
170
|
+
if (xy === 'x') {
|
|
171
|
+
this.#inputY.value = String(ratioSize.h);
|
|
172
|
+
} else {
|
|
173
|
+
this.#inputX.value = String(ratioSize.w);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @description Updates the ratio based on current input values.
|
|
180
|
+
*/
|
|
181
|
+
#OnChangeRatio() {
|
|
182
|
+
this.#ratio = this.#proportion.checked ? Figure.GetRatio(this.#inputX.value, this.#inputY.value, this.#state.sizeUnit) : { w: 0, h: 0 };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @description Reverts the size inputs to the original image size.
|
|
187
|
+
*/
|
|
188
|
+
#OnClickRevert() {
|
|
189
|
+
if (this.#state.onlyPercentage) {
|
|
190
|
+
this.#inputX.value = Number(this.#origin_w) > 100 ? '100' : this.#origin_w;
|
|
191
|
+
} else {
|
|
192
|
+
this.#inputX.value = this.#origin_w;
|
|
193
|
+
this.#inputY.value = this.#origin_h;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default ImageSizeService;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { env } from '../../../../helper';
|
|
2
|
+
import { FORMAT_TYPE } from '../shared/image.constants';
|
|
3
|
+
const { NO_EVENT } = env;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @class ImageUploadService
|
|
7
|
+
* @description Handles image upload operations including file upload, URL upload, and `Base64` conversion.
|
|
8
|
+
*/
|
|
9
|
+
export class ImageUploadService {
|
|
10
|
+
#main;
|
|
11
|
+
#$;
|
|
12
|
+
#pluginOptions;
|
|
13
|
+
|
|
14
|
+
#resizing;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {import('../index').default} main - The main Image_ plugin instance.
|
|
18
|
+
*/
|
|
19
|
+
constructor(main) {
|
|
20
|
+
this.#main = main;
|
|
21
|
+
this.#$ = main.$;
|
|
22
|
+
this.#pluginOptions = main.pluginOptions;
|
|
23
|
+
|
|
24
|
+
this.#resizing = this.#pluginOptions.canResize;
|
|
25
|
+
|
|
26
|
+
this._base64RenderIndex = 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get #sizeService() {
|
|
30
|
+
return this.#main.sizeService;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @description Uploads the image to the server.
|
|
35
|
+
* @param {SunEditor.EventParams.ImageInfo} info - Image upload info.
|
|
36
|
+
*/
|
|
37
|
+
serverUpload(info) {
|
|
38
|
+
if (!info.files) return;
|
|
39
|
+
|
|
40
|
+
// server upload
|
|
41
|
+
const imageUploadUrl = this.#pluginOptions.uploadUrl;
|
|
42
|
+
if (typeof imageUploadUrl === 'string' && imageUploadUrl.length > 0) {
|
|
43
|
+
this.#main.fileManager.upload(imageUploadUrl, this.#pluginOptions.uploadHeaders, info.files, this.#UploadCallBack.bind(this, info), this.#error.bind(this));
|
|
44
|
+
} else {
|
|
45
|
+
this.#setBase64(info);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @description Handles image upload via URL.
|
|
51
|
+
* @param {*} info - Image information.
|
|
52
|
+
*/
|
|
53
|
+
urlUpload(info) {
|
|
54
|
+
this.#main.setState('produceIndex', 0);
|
|
55
|
+
const infoUrl = info.url;
|
|
56
|
+
|
|
57
|
+
if (this.#main.modal.isUpdate) this.#updateSrc(infoUrl, info.element, info.files);
|
|
58
|
+
else this.#produce(infoUrl, info.anchor, info.inputWidth, info.inputHeight, info.align, info.files, info.alt, true);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @description Creates a new image component based on provided parameters.
|
|
63
|
+
* @param {string} src - The image source URL.
|
|
64
|
+
* @param {?Node} anchor - Optional anchor wrapping the image.
|
|
65
|
+
* @param {string} width - Image width.
|
|
66
|
+
* @param {string} height - Image height.
|
|
67
|
+
* @param {string} align - Image alignment.
|
|
68
|
+
* @param {{name: string, size: number}} file - File metadata.
|
|
69
|
+
* @param {string} alt - Alternative text.
|
|
70
|
+
* @param {boolean} isLast - Indicates if this is the last image in a batch (for scroll and insert behavior).
|
|
71
|
+
*/
|
|
72
|
+
#produce(src, anchor, width, height, align, file, alt, isLast) {
|
|
73
|
+
if (this.#main.as !== FORMAT_TYPE.INLINE) {
|
|
74
|
+
this.#main.create(src, anchor, width, height, align, file, alt, isLast);
|
|
75
|
+
} else {
|
|
76
|
+
this.#main.createInline(src, anchor, width, height, file, alt, isLast);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @description Updates the image source URL.
|
|
82
|
+
* @param {string} src - The new image source.
|
|
83
|
+
* @param {HTMLImageElement} element - The image element.
|
|
84
|
+
* @param {{ name: string, size: number }} file - File metadata.
|
|
85
|
+
*/
|
|
86
|
+
#updateSrc(src, element, file) {
|
|
87
|
+
element.src = src;
|
|
88
|
+
this.#main.fileManager.setFileData(element, file);
|
|
89
|
+
this.#$.component.select(element, this.#main.constructor['key']);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @description Registers the uploaded image and inserts it into the editor.
|
|
94
|
+
* @param {SunEditor.EventParams.ImageInfo} info - Image info.
|
|
95
|
+
* @param {Object<string, *>} response - Server response data.
|
|
96
|
+
*/
|
|
97
|
+
#register(info, response) {
|
|
98
|
+
this.#main.setState('produceIndex', 0);
|
|
99
|
+
const fileList = response.result;
|
|
100
|
+
|
|
101
|
+
for (let i = 0, len = fileList.length, file; i < len; i++) {
|
|
102
|
+
file = {
|
|
103
|
+
name: fileList[i].name,
|
|
104
|
+
size: fileList[i].size,
|
|
105
|
+
};
|
|
106
|
+
if (info.isUpdate) {
|
|
107
|
+
this.#updateSrc(fileList[i].url, info.element, file);
|
|
108
|
+
break;
|
|
109
|
+
} else {
|
|
110
|
+
this.#produce(fileList[i].url, info.anchor, info.inputWidth, info.inputHeight, info.align, file, info.alt, i === len - 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @description Converts an image file to `Base64` and inserts it into the editor.
|
|
117
|
+
* @param {SunEditor.EventParams.ImageInfo} info - Image upload info.
|
|
118
|
+
* @throws {Error} Throws error if `Base64` conversion fails.
|
|
119
|
+
*/
|
|
120
|
+
#setBase64(info) {
|
|
121
|
+
try {
|
|
122
|
+
const { files, element, anchor, inputWidth, inputHeight, align, alt, isUpdate } = info;
|
|
123
|
+
const filesLen = this.#main.modal.isUpdate ? 1 : files.length;
|
|
124
|
+
|
|
125
|
+
if (filesLen === 0) {
|
|
126
|
+
this.#$.ui.hideLoading();
|
|
127
|
+
console.warn('[SUNEDITOR.image.base64.fail] cause : No applicable files');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
this._base64RenderIndex = filesLen;
|
|
132
|
+
const filesStack = new Array(filesLen);
|
|
133
|
+
|
|
134
|
+
if (this.#resizing) {
|
|
135
|
+
this.#sizeService.setInputSize(inputWidth, inputHeight);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (let i = 0, renderFunc = this.#onRenderBase64.bind(this), reader, file; i < filesLen; i++) {
|
|
139
|
+
reader = new FileReader();
|
|
140
|
+
file = files[i];
|
|
141
|
+
|
|
142
|
+
reader.onload = function (loadCallback, on_reader, update, updateElement, on_file, index) {
|
|
143
|
+
filesStack[index] = {
|
|
144
|
+
result: on_reader.result,
|
|
145
|
+
file: on_file,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
if (--this._base64RenderIndex === 0) {
|
|
149
|
+
loadCallback(update, filesStack, updateElement, anchor, inputWidth, inputHeight, align, alt);
|
|
150
|
+
this.#$.ui.hideLoading();
|
|
151
|
+
}
|
|
152
|
+
}.bind(this, renderFunc, reader, isUpdate, element, file, i);
|
|
153
|
+
|
|
154
|
+
reader.readAsDataURL(file);
|
|
155
|
+
}
|
|
156
|
+
} catch (error) {
|
|
157
|
+
this.#$.ui.hideLoading();
|
|
158
|
+
throw Error(`[SUNEDITOR.plugins.image._setBase64.fail] ${error.message}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @description Inserts an image using a `Base64`-encoded string.
|
|
164
|
+
* @param {boolean} update - Whether the image is being updated.
|
|
165
|
+
* @param {Array<{result: string, file: { name: string, size: number }}>} filesStack - Stack of `Base64`-encoded files.
|
|
166
|
+
* - result: Image url or `Base64`-encoded string
|
|
167
|
+
* - file: File metadata ({ name: string, size: number })
|
|
168
|
+
* @param {HTMLImageElement} updateElement - The image element being updated.
|
|
169
|
+
* @param {?HTMLAnchorElement} anchor - Optional anchor wrapping the image.
|
|
170
|
+
* @param {string} width - Image width.
|
|
171
|
+
* @param {string} height - Image height.
|
|
172
|
+
* @param {string} align - Image alignment.
|
|
173
|
+
* @param {string} alt - Alternative text.
|
|
174
|
+
*/
|
|
175
|
+
#onRenderBase64(update, filesStack, updateElement, anchor, width, height, align, alt) {
|
|
176
|
+
this.#main.setState('produceIndex', 0);
|
|
177
|
+
|
|
178
|
+
for (let i = 0, len = filesStack.length; i < len; i++) {
|
|
179
|
+
if (update) {
|
|
180
|
+
this.#updateSrc(filesStack[i].result, updateElement, filesStack[i].file);
|
|
181
|
+
} else {
|
|
182
|
+
this.#produce(filesStack[i].result, anchor, width, height, align, filesStack[i].file, alt, i === len - 1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @description Handles errors during image upload and displays appropriate messages.
|
|
189
|
+
* @param {Object<string, *>} response - The error response from the server.
|
|
190
|
+
* @returns {Promise<void>}
|
|
191
|
+
*/
|
|
192
|
+
async #error(response) {
|
|
193
|
+
const message = await this.#$.eventManager.triggerEvent('onImageUploadError', { error: response });
|
|
194
|
+
const err = message === NO_EVENT ? response.errorMessage : message || response.errorMessage;
|
|
195
|
+
this.#$.ui.alertOpen(err, 'error');
|
|
196
|
+
console.error('[SUNEDITOR.plugin.image.error]', err);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @description Handles the callback function for image upload completion.
|
|
201
|
+
* @param {SunEditor.EventParams.ImageInfo} info - Image information.
|
|
202
|
+
* @param {XMLHttpRequest} xmlHttp - The XMLHttpRequest object.
|
|
203
|
+
*/
|
|
204
|
+
async #UploadCallBack(info, xmlHttp) {
|
|
205
|
+
if ((await this.#$.eventManager.triggerEvent('imageUploadHandler', { xmlHttp, info })) === NO_EVENT) {
|
|
206
|
+
const response = JSON.parse(xmlHttp.responseText);
|
|
207
|
+
if (response.errorMessage) {
|
|
208
|
+
this.#error(response);
|
|
209
|
+
} else {
|
|
210
|
+
this.#register(info, response);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export default ImageUploadService;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Image plugin constants
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_SVG_SIZE = '30%';
|
|
6
|
+
|
|
7
|
+
export const SIZE_UNIT = {
|
|
8
|
+
PERCENTAGE: '%',
|
|
9
|
+
PIXEL: 'px',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type {{ BLOCK: 'block', INLINE: 'inline' }}
|
|
14
|
+
*/
|
|
15
|
+
export const FORMAT_TYPE = {
|
|
16
|
+
BLOCK: 'block',
|
|
17
|
+
INLINE: 'inline',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const DEFAULT_ACCEPTED_FORMATS = 'image/*';
|