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,204 @@
|
|
|
1
|
+
import { dom, numbers } from '../../../helper';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Service class managing the selection state and toolbar updates.
|
|
5
|
+
* - Handles activating toolbar buttons based on the current selection.
|
|
6
|
+
* - Manages the `active` state of plugins and commands.
|
|
7
|
+
*/
|
|
8
|
+
export default class SelectionState {
|
|
9
|
+
#eventOrchestrator;
|
|
10
|
+
#$;
|
|
11
|
+
|
|
12
|
+
/** @type {RegExp} */
|
|
13
|
+
#onButtonsCheck;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {import('../eventOrchestrator').default} eventOrchestrator
|
|
18
|
+
*/
|
|
19
|
+
constructor(eventOrchestrator) {
|
|
20
|
+
this.#eventOrchestrator = eventOrchestrator;
|
|
21
|
+
this.#$ = eventOrchestrator.$;
|
|
22
|
+
this.#onButtonsCheck = new RegExp(`^(${Object.keys(this.#$.options.get('_defaultStyleTagMap')).join('|')})$`, 'i');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @description Updates the toolbar state based on the current selection.
|
|
27
|
+
* - Traverses the DOM from the selection to the root.
|
|
28
|
+
* - Checks for active tags and styles.
|
|
29
|
+
* - Activates corresponding toolbar buttons.
|
|
30
|
+
* @param {Node} [selectionNode] The node where the selection is currently located.
|
|
31
|
+
* @returns {Node|undefined} The processed selection node.
|
|
32
|
+
*/
|
|
33
|
+
update(selectionNode) {
|
|
34
|
+
selectionNode ||= this.#$.selection.getNode();
|
|
35
|
+
if (selectionNode === this.#$.store.get('_lastSelectionNode')) return;
|
|
36
|
+
this.#$.store.set('_lastSelectionNode', selectionNode);
|
|
37
|
+
|
|
38
|
+
const marginDir = this.#$.options.get('_rtl') ? 'marginRight' : 'marginLeft';
|
|
39
|
+
const plugins = this.#$.plugins;
|
|
40
|
+
const commandTargets = this.#$.commandDispatcher.targets;
|
|
41
|
+
const classOnCheck = this.#onButtonsCheck;
|
|
42
|
+
const styleCommand = this.#$.options.get('_styleCommandMap');
|
|
43
|
+
const commandMapNodes = [];
|
|
44
|
+
const currentNodes = [];
|
|
45
|
+
|
|
46
|
+
const styleTags = this.#$.options.get('_textStyleTags');
|
|
47
|
+
const styleNodes = [];
|
|
48
|
+
|
|
49
|
+
const ignoreCommands = [];
|
|
50
|
+
const activeCommands = this.#$.commandDispatcher.activeCommands;
|
|
51
|
+
const cLen = activeCommands.length;
|
|
52
|
+
let nodeName = '';
|
|
53
|
+
|
|
54
|
+
if (this.#$.component.is(selectionNode) && !this.#$.component.__selectionSelected) {
|
|
55
|
+
const component = this.#$.component.get(selectionNode);
|
|
56
|
+
if (!component) return;
|
|
57
|
+
this.#$.store.set('_lastSelectionNode', null);
|
|
58
|
+
this.#$.component.select(component.target, component.pluginName);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
while (selectionNode.firstChild) {
|
|
63
|
+
selectionNode = selectionNode.firstChild;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const fc = this.#$.frameContext;
|
|
67
|
+
const notReadonly = !fc.get('isReadOnly');
|
|
68
|
+
for (let element = selectionNode; !dom.check.isWysiwygFrame(element); element = element.parentElement) {
|
|
69
|
+
if (!element) break;
|
|
70
|
+
if (element.nodeType !== 1 || dom.check.isBreak(element)) continue;
|
|
71
|
+
if (this.#isNonFocusNode(element)) {
|
|
72
|
+
this.#$.focusManager.blur();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
nodeName = element.nodeName.toLowerCase();
|
|
77
|
+
currentNodes.push(nodeName);
|
|
78
|
+
if (styleTags.includes(nodeName) && !this.#$.format.isLine(nodeName)) styleNodes.push(element);
|
|
79
|
+
|
|
80
|
+
/* Active plugins */
|
|
81
|
+
if (notReadonly) {
|
|
82
|
+
for (let c = 0, name; c < cLen; c++) {
|
|
83
|
+
name = activeCommands[c];
|
|
84
|
+
if (
|
|
85
|
+
!commandMapNodes.includes(name) &&
|
|
86
|
+
!ignoreCommands.includes(name) &&
|
|
87
|
+
commandTargets.get(name) &&
|
|
88
|
+
commandTargets.get(name).filter((e) => {
|
|
89
|
+
const r = plugins[name]?.active(element, e);
|
|
90
|
+
if (r === undefined) {
|
|
91
|
+
ignoreCommands.push(name);
|
|
92
|
+
}
|
|
93
|
+
return r;
|
|
94
|
+
}).length > 0
|
|
95
|
+
) {
|
|
96
|
+
commandMapNodes.push(name);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** indent, outdent */
|
|
102
|
+
if (this.#$.format.isLine(element)) {
|
|
103
|
+
/* Outdent */
|
|
104
|
+
if (!commandMapNodes.includes('outdent') && commandTargets.has('outdent') && (dom.check.isListCell(element) || (element.style[marginDir] && numbers.get(element.style[marginDir], 0) > 0))) {
|
|
105
|
+
if (
|
|
106
|
+
commandTargets.get('outdent').filter((e) => {
|
|
107
|
+
if (dom.check.isImportantDisabled(e)) return false;
|
|
108
|
+
e.disabled = false;
|
|
109
|
+
return true;
|
|
110
|
+
}).length > 0
|
|
111
|
+
) {
|
|
112
|
+
commandMapNodes.push('outdent');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/* Indent */
|
|
116
|
+
if (!commandMapNodes.includes('indent') && commandTargets.has('indent')) {
|
|
117
|
+
const indentDisable = dom.check.isListCell(element) && !element.previousElementSibling;
|
|
118
|
+
if (
|
|
119
|
+
commandTargets.get('indent').filter((e) => {
|
|
120
|
+
if (dom.check.isImportantDisabled(e)) return false;
|
|
121
|
+
e.disabled = indentDisable;
|
|
122
|
+
return true;
|
|
123
|
+
}).length > 0
|
|
124
|
+
) {
|
|
125
|
+
commandMapNodes.push('indent');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** default active buttons [strong, ins, em, del, sub, sup] */
|
|
133
|
+
if (classOnCheck.test(nodeName)) {
|
|
134
|
+
nodeName = styleCommand[nodeName] || nodeName;
|
|
135
|
+
commandMapNodes.push(nodeName);
|
|
136
|
+
dom.utils.addClass(commandTargets.get(nodeName), 'active');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.#setKeyEffect(commandMapNodes);
|
|
141
|
+
|
|
142
|
+
// cache style nodes
|
|
143
|
+
this.#eventOrchestrator.__cacheStyleNodes = styleNodes.reverse();
|
|
144
|
+
|
|
145
|
+
/** save current nodes */
|
|
146
|
+
this.#$.store.set('currentNodes', currentNodes.reverse());
|
|
147
|
+
this.#$.store.set('currentNodesMap', commandMapNodes);
|
|
148
|
+
|
|
149
|
+
/** Displays the current node structure to statusbar */
|
|
150
|
+
if (this.#$.frameOptions.get('statusbar_showPathLabel') && fc.get('navigation')) {
|
|
151
|
+
fc.get('navigation').textContent = this.#$.options.get('_rtl') ? this.#$.store.get('currentNodes').reverse().join(' < ') : this.#$.store.get('currentNodes').join(' > ');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return selectionNode;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @description Resets the toolbar state.
|
|
159
|
+
* - Deactivates all buttons and clears the effect.
|
|
160
|
+
* - Equivalent to calling `setKeyEffect([])`.
|
|
161
|
+
*/
|
|
162
|
+
reset() {
|
|
163
|
+
this.#setKeyEffect([]);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @description Internal logic to update the visual state of buttons.
|
|
168
|
+
* - Checks the list of `active` commands and updates the DOM classes (`active`/inactive).
|
|
169
|
+
* @param {Array<string>} ignoredList List of formatting commands to keep `active` (others will be deactivated).
|
|
170
|
+
*/
|
|
171
|
+
#setKeyEffect(ignoredList) {
|
|
172
|
+
const activeCommands = this.#$.commandDispatcher.activeCommands;
|
|
173
|
+
const commandTargets = this.#$.commandDispatcher.targets;
|
|
174
|
+
const plugins = this.#$.plugins;
|
|
175
|
+
for (let i = 0, len = activeCommands.length, k, c, p; i < len; i++) {
|
|
176
|
+
k = activeCommands[i];
|
|
177
|
+
if (ignoredList.includes(k) || !(c = commandTargets.get(k))) continue;
|
|
178
|
+
|
|
179
|
+
p = plugins[k];
|
|
180
|
+
for (let j = 0, jLen = c.length, e; j < jLen; j++) {
|
|
181
|
+
e = c[j];
|
|
182
|
+
if (!e) continue;
|
|
183
|
+
if (p) {
|
|
184
|
+
p.active(null, e);
|
|
185
|
+
} else if (/^outdent$/i.test(k)) {
|
|
186
|
+
if (!dom.check.isImportantDisabled(e)) e.disabled = true;
|
|
187
|
+
} else if (/^indent$/i.test(k)) {
|
|
188
|
+
if (!dom.check.isImportantDisabled(e)) e.disabled = false;
|
|
189
|
+
} else {
|
|
190
|
+
dom.utils.removeClass(e, 'active');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @description Checks if a node is a non-focusable element(`.data-se-non-focus`). (e.g. fileUpload.component > span)
|
|
198
|
+
* @param {Node} node Node to check
|
|
199
|
+
* @returns {boolean} `true` if the node is non-focusable, otherwise `false`
|
|
200
|
+
*/
|
|
201
|
+
#isNonFocusNode(node) {
|
|
202
|
+
return dom.check.isElement(node) && node.getAttribute('data-se-non-focus') === 'true';
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// L1: kernel
|
|
2
|
+
import Store from './store';
|
|
3
|
+
|
|
4
|
+
// L2: config
|
|
5
|
+
import ContextProvider from '../config/contextProvider';
|
|
6
|
+
import OptionProvider from '../config/optionProvider';
|
|
7
|
+
import InstanceCheck from '../config/instanceCheck';
|
|
8
|
+
import EventManager from '../config/eventManager';
|
|
9
|
+
|
|
10
|
+
// L3: logic/dom
|
|
11
|
+
import Offset from '../logic/dom/offset';
|
|
12
|
+
import Selection_ from '../logic/dom/selection';
|
|
13
|
+
import Format from '../logic/dom/format';
|
|
14
|
+
import Inline from '../logic/dom/inline';
|
|
15
|
+
import ListFormat from '../logic/dom/listFormat';
|
|
16
|
+
import HTML from '../logic/dom/html';
|
|
17
|
+
import NodeTransform from '../logic/dom/nodeTransform';
|
|
18
|
+
import Char from '../logic/dom/char';
|
|
19
|
+
|
|
20
|
+
// L3: logic/shell
|
|
21
|
+
import Shortcuts from '../logic/shell/shortcuts';
|
|
22
|
+
import Component from '../logic/shell/component';
|
|
23
|
+
import PluginManager from '../logic/shell/pluginManager';
|
|
24
|
+
import FocusManager from '../logic/shell/focusManager';
|
|
25
|
+
import UI from '../logic/shell/ui';
|
|
26
|
+
import CommandDispatcher from '../logic/shell/commandDispatcher';
|
|
27
|
+
import History from '../logic/shell/history';
|
|
28
|
+
|
|
29
|
+
// L3: logic/panel
|
|
30
|
+
import Toolbar from '../logic/panel/toolbar';
|
|
31
|
+
import Menu from '../logic/panel/menu';
|
|
32
|
+
import Viewer from '../logic/panel/viewer';
|
|
33
|
+
|
|
34
|
+
// L4: event
|
|
35
|
+
import EventOrchestrator from '../event/eventOrchestrator';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {import('../section/constructor').ConstructorReturnType} ProductType
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {Object} Deps
|
|
43
|
+
* @property {SunEditor.Instance} facade - Editor facade (public API)
|
|
44
|
+
* @property {SunEditor.Store} store - L1: Central state store
|
|
45
|
+
*
|
|
46
|
+
* @property {import('../config/contextProvider').default} contextProvider - L2: Context provider
|
|
47
|
+
* @property {import('../config/optionProvider').default} optionProvider - L2: Option provider
|
|
48
|
+
* @property {import('../config/instanceCheck').default} instanceCheck - L2: Instance type checker
|
|
49
|
+
* @property {import('../config/eventManager').default} eventManager - L2: Event manager (public API)
|
|
50
|
+
*
|
|
51
|
+
* @property {Map<string, SunEditor.FrameContext>} frameRoots - Frame root elements map
|
|
52
|
+
* @property {SunEditor.Context} context - Editor context
|
|
53
|
+
* @property {SunEditor.Options} options - Editor options
|
|
54
|
+
* @property {Object} icons - Icon set
|
|
55
|
+
* @property {Object} lang - Language strings
|
|
56
|
+
* @property {SunEditor.FrameContext} frameContext - Current frame context
|
|
57
|
+
* @property {SunEditor.FrameOptions} frameOptions - Current frame options
|
|
58
|
+
*
|
|
59
|
+
* @property {import('../logic/dom/offset').default} offset - L3: Offset calculator
|
|
60
|
+
* @property {import('../logic/dom/selection').default} selection - L3: Selection handler
|
|
61
|
+
* @property {import('../logic/dom/format').default} format - L3: Block formatting
|
|
62
|
+
* @property {import('../logic/dom/inline').default} inline - L3: Inline styling
|
|
63
|
+
* @property {import('../logic/dom/listFormat').default} listFormat - L3: List operations
|
|
64
|
+
* @property {import('../logic/dom/html').default} html - L3: HTML processing
|
|
65
|
+
* @property {import('../logic/dom/nodeTransform').default} nodeTransform - L3: Node transformation
|
|
66
|
+
* @property {import('../logic/dom/char').default} char - L3: Character counting
|
|
67
|
+
*
|
|
68
|
+
* @property {import('../logic/shell/component').default} component - L3: Component lifecycle
|
|
69
|
+
* @property {import('../logic/shell/focusManager').default} focusManager - L3: Focus management
|
|
70
|
+
* @property {import('../logic/shell/pluginManager').default} pluginManager - L3: Plugin registry
|
|
71
|
+
* @property {Object<string, Object>} plugins - Plugin instances map
|
|
72
|
+
* @property {import('../logic/shell/ui').default} ui - L3: UI state management
|
|
73
|
+
* @property {import('../logic/shell/commandDispatcher').default} commandDispatcher - L3: Command routing
|
|
74
|
+
* @property {ReturnType<import('../logic/shell/history').default>} history - L3: Undo/Redo stack
|
|
75
|
+
* @property {import('../logic/shell/shortcuts').default} shortcuts - L3: Shortcut mapping
|
|
76
|
+
*
|
|
77
|
+
* @property {import('../logic/panel/toolbar').default} toolbar - L3: Toolbar renderer
|
|
78
|
+
* @property {import('../logic/panel/toolbar').default} subToolbar - L3: Sub-toolbar renderer
|
|
79
|
+
* @property {import('../logic/panel/menu').default} menu - L3: Menu renderer
|
|
80
|
+
* @property {import('../logic/panel/viewer').default} viewer - L3: View mode handler
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @description Core dependency container for the editor.
|
|
85
|
+
* - Stores and retrieves config/logic/plugin instances.
|
|
86
|
+
* - Orchestrates dependency injection across layers.
|
|
87
|
+
* - Initialization order: L1 Store -> L2 Config (`$` Phase 1) -> L3 Logic (`$` Phase 2) -> L4 Event.
|
|
88
|
+
*/
|
|
89
|
+
class CoreKernel {
|
|
90
|
+
#config = new Map();
|
|
91
|
+
#logic = new Map();
|
|
92
|
+
|
|
93
|
+
/** @type {Deps} */
|
|
94
|
+
$ = null;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {SunEditor.Instance} facade - Editor instance (Public API)
|
|
98
|
+
* @param {Object} config - Initial configuration
|
|
99
|
+
* @param {ProductType} config.product - The initial product object.
|
|
100
|
+
* @param {SunEditor.InitOptions} config.options - The initial options.
|
|
101
|
+
*/
|
|
102
|
+
constructor(facade, config) {
|
|
103
|
+
const { product, options } = config;
|
|
104
|
+
|
|
105
|
+
// L1: Store
|
|
106
|
+
this.store = new Store(product);
|
|
107
|
+
|
|
108
|
+
/** @type {Deps} */
|
|
109
|
+
this.$ = /** @type {*} */ ({ facade, store: this.store });
|
|
110
|
+
|
|
111
|
+
// L2: Config
|
|
112
|
+
this.#registerConfig(product, options);
|
|
113
|
+
|
|
114
|
+
// $ Phase 1: Config deps (available to Logic constructors via kernel.$)
|
|
115
|
+
this.#buildConfigDeps();
|
|
116
|
+
|
|
117
|
+
// L3: Logic (dom, shell, ui)
|
|
118
|
+
this.#registerLogic(product);
|
|
119
|
+
|
|
120
|
+
// $ Phase 2: Add Logic deps
|
|
121
|
+
this.#assignLogicDeps();
|
|
122
|
+
|
|
123
|
+
//----------------------------------------------
|
|
124
|
+
|
|
125
|
+
// Initialize Logic modules that need EventManager reference
|
|
126
|
+
this.#initLogic();
|
|
127
|
+
|
|
128
|
+
// Event orchestrator
|
|
129
|
+
this._eventOrchestrator = new EventOrchestrator(this);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @description L2: Register config instances
|
|
134
|
+
* @param {ProductType} product - The initial product object.
|
|
135
|
+
* @param {SunEditor.InitOptions} options - The initial options.
|
|
136
|
+
*/
|
|
137
|
+
#registerConfig(product, options) {
|
|
138
|
+
const contextProvider = new ContextProvider(product);
|
|
139
|
+
const optionProvider = new OptionProvider(this, product, options);
|
|
140
|
+
|
|
141
|
+
this.#config.set('contextProvider', contextProvider);
|
|
142
|
+
this.#config.set('optionProvider', optionProvider);
|
|
143
|
+
this.#config.set('instanceCheck', new InstanceCheck(contextProvider.frameContext));
|
|
144
|
+
this.#config.set('eventManager', new EventManager(contextProvider, optionProvider, this.$));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @description `$` Phase 1: Build dependency bag with config entries only.
|
|
149
|
+
* Logic constructors can access `kernel.$` for configs.
|
|
150
|
+
*/
|
|
151
|
+
#buildConfigDeps() {
|
|
152
|
+
const contextProvider = this.#config.get('contextProvider');
|
|
153
|
+
const optionProvider = this.#config.get('optionProvider');
|
|
154
|
+
|
|
155
|
+
Object.assign(this.$, {
|
|
156
|
+
// L2: Config
|
|
157
|
+
contextProvider,
|
|
158
|
+
optionProvider,
|
|
159
|
+
instanceCheck: this.#config.get('instanceCheck'),
|
|
160
|
+
eventManager: this.#config.get('eventManager'),
|
|
161
|
+
|
|
162
|
+
// L2: Config - Convenience accessors
|
|
163
|
+
frameRoots: contextProvider.frameRoots,
|
|
164
|
+
context: contextProvider.context,
|
|
165
|
+
options: optionProvider.options,
|
|
166
|
+
icons: contextProvider.icons,
|
|
167
|
+
lang: contextProvider.lang,
|
|
168
|
+
frameContext: contextProvider.frameContext,
|
|
169
|
+
frameOptions: optionProvider.frameOptions,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @description L3: Register logic instances (dom, shell, ui).
|
|
175
|
+
* @param {ProductType} product - The initial product object.
|
|
176
|
+
*/
|
|
177
|
+
#registerLogic(product) {
|
|
178
|
+
// dom
|
|
179
|
+
this.#logic.set('offset', new Offset(this));
|
|
180
|
+
this.#logic.set('selection', new Selection_(this));
|
|
181
|
+
this.#logic.set('html', new HTML(this));
|
|
182
|
+
this.#logic.set('nodeTransform', new NodeTransform(this));
|
|
183
|
+
this.#logic.set('format', new Format(this));
|
|
184
|
+
this.#logic.set('inline', new Inline(this));
|
|
185
|
+
this.#logic.set('listFormat', new ListFormat(this));
|
|
186
|
+
this.#logic.set('char', new Char(this));
|
|
187
|
+
|
|
188
|
+
// shell
|
|
189
|
+
this.#logic.set('shortcuts', new Shortcuts(this));
|
|
190
|
+
this.#logic.set('component', new Component(this));
|
|
191
|
+
this.#logic.set('pluginManager', new PluginManager(this, product));
|
|
192
|
+
this.#logic.set('focusManager', new FocusManager(this));
|
|
193
|
+
this.#logic.set('ui', new UI(this));
|
|
194
|
+
this.#logic.set('commandDispatcher', new CommandDispatcher(this));
|
|
195
|
+
|
|
196
|
+
// ui
|
|
197
|
+
this.#logic.set(
|
|
198
|
+
'toolbar',
|
|
199
|
+
new Toolbar(this, {
|
|
200
|
+
keyName: 'toolbar',
|
|
201
|
+
balloon: this.store.mode.isBalloon,
|
|
202
|
+
balloonAlways: this.store.mode.isBalloonAlways,
|
|
203
|
+
inline: this.store.mode.isInline,
|
|
204
|
+
res: product.responsiveButtons,
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
if (this.$.options.has('_subMode')) {
|
|
208
|
+
this.#logic.set(
|
|
209
|
+
'subToolbar',
|
|
210
|
+
new Toolbar(this, {
|
|
211
|
+
keyName: 'toolbar_sub',
|
|
212
|
+
balloon: this.store.mode.isSubBalloon,
|
|
213
|
+
balloonAlways: this.store.mode.isSubBalloonAlways,
|
|
214
|
+
inline: false,
|
|
215
|
+
res: product.responsiveButtons_sub,
|
|
216
|
+
}),
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
this.#logic.set('menu', new Menu(this));
|
|
220
|
+
this.#logic.set('viewer', new Viewer(this));
|
|
221
|
+
|
|
222
|
+
// history (last — closure captures all L3 modules above)
|
|
223
|
+
this.#logic.set('history', History(this));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @description Initialize Logic modules that need `EventManager` reference.
|
|
228
|
+
* Called after `EventManager` is created.
|
|
229
|
+
*/
|
|
230
|
+
#initLogic() {
|
|
231
|
+
for (const [, instance] of this.#logic) {
|
|
232
|
+
if (typeof instance?._init === 'function') {
|
|
233
|
+
instance._init();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @description `$` Phase 2: Add logic entries to existing `$` object.
|
|
240
|
+
* Called after all logic instances are registered and initialized.
|
|
241
|
+
*/
|
|
242
|
+
#assignLogicDeps() {
|
|
243
|
+
const pluginManager = this.#logic.get('pluginManager');
|
|
244
|
+
|
|
245
|
+
Object.assign(this.$, {
|
|
246
|
+
// L3: Logic (dom)
|
|
247
|
+
offset: this.#logic.get('offset'),
|
|
248
|
+
selection: this.#logic.get('selection'),
|
|
249
|
+
format: this.#logic.get('format'),
|
|
250
|
+
inline: this.#logic.get('inline'),
|
|
251
|
+
listFormat: this.#logic.get('listFormat'),
|
|
252
|
+
html: this.#logic.get('html'),
|
|
253
|
+
nodeTransform: this.#logic.get('nodeTransform'),
|
|
254
|
+
char: this.#logic.get('char'),
|
|
255
|
+
|
|
256
|
+
// L3: Logic (shell)
|
|
257
|
+
component: this.#logic.get('component'),
|
|
258
|
+
focusManager: this.#logic.get('focusManager'),
|
|
259
|
+
pluginManager,
|
|
260
|
+
plugins: pluginManager.plugins,
|
|
261
|
+
ui: this.#logic.get('ui'),
|
|
262
|
+
commandDispatcher: this.#logic.get('commandDispatcher'),
|
|
263
|
+
history: this.#logic.get('history'),
|
|
264
|
+
shortcuts: this.#logic.get('shortcuts'),
|
|
265
|
+
|
|
266
|
+
// L3: Logic (ui)
|
|
267
|
+
toolbar: this.#logic.get('toolbar'),
|
|
268
|
+
subToolbar: this.#logic.get('subToolbar'),
|
|
269
|
+
menu: this.#logic.get('menu'),
|
|
270
|
+
viewer: this.#logic.get('viewer'),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @description Destroy the kernel and release all resources.
|
|
276
|
+
* Teardown order (reverse of init): plugins -> logic -> event -> config -> store
|
|
277
|
+
* Uses error aggregation to ensure all modules are cleaned up even if some fail.
|
|
278
|
+
*/
|
|
279
|
+
_destroy() {
|
|
280
|
+
if (this.$ === null) return;
|
|
281
|
+
|
|
282
|
+
const errors = [];
|
|
283
|
+
|
|
284
|
+
for (const [key, instance] of this.#logic) {
|
|
285
|
+
try {
|
|
286
|
+
instance?._destroy?.();
|
|
287
|
+
} catch (e) {
|
|
288
|
+
errors.push(`[Logic:${key}] ${e.message}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
this.#logic.clear();
|
|
292
|
+
|
|
293
|
+
try {
|
|
294
|
+
this._eventOrchestrator?._removeAllEvents();
|
|
295
|
+
} catch (e) {
|
|
296
|
+
errors.push(`[EventOrchestrator] ${e.message}`);
|
|
297
|
+
}
|
|
298
|
+
this._eventOrchestrator = null;
|
|
299
|
+
|
|
300
|
+
for (const [key, instance] of this.#config) {
|
|
301
|
+
try {
|
|
302
|
+
instance?._destroy?.();
|
|
303
|
+
} catch (e) {
|
|
304
|
+
errors.push(`[Config:${key}] ${e.message}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
this.#config.clear();
|
|
308
|
+
|
|
309
|
+
if (errors.length > 0) {
|
|
310
|
+
console.warn('[CoreKernel._destroy] Cleanup completed with errors:', errors);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
this.$ = null;
|
|
314
|
+
this.store._destroy();
|
|
315
|
+
this.store = null;
|
|
316
|
+
this.facade = null;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export default CoreKernel;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Base class for kernel consumers (plugins, modules).
|
|
3
|
+
* - Provides cached access to kernel dependencies via `$` object.
|
|
4
|
+
* - Dependencies are built once in `CoreKernel` and shared across all consumers.
|
|
5
|
+
* - Eliminates circular references by routing through the kernel.
|
|
6
|
+
*/
|
|
7
|
+
class KernelInjector {
|
|
8
|
+
/** @type {SunEditor.Deps} */
|
|
9
|
+
$;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {SunEditor.Kernel} kernel
|
|
13
|
+
*/
|
|
14
|
+
constructor(kernel) {
|
|
15
|
+
this.$ = kernel.$;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default KernelInjector;
|