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
package/src/helper/clipboard.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview clipboard helper
|
|
3
|
-
*/
|
|
4
1
|
import { isClipboardSupported } from './env';
|
|
5
2
|
import { isElement } from './dom/domCheck';
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* @description Write the content to the clipboard
|
|
9
|
-
* - Iframe is replaced with a placeholder :
|
|
10
|
-
* -
|
|
6
|
+
* - Iframe is replaced with a placeholder : `<div data-se-iframe-holder-src="iframe.src">[iframe: iframe.src]</div>`
|
|
7
|
+
* - `iframe placeholder` is re-rendered in `html.clean` when pasted into the editor.
|
|
11
8
|
* @param {Element|Text|string} content Content to be copied to the clipboard
|
|
12
|
-
* @returns {Promise<void>}
|
|
9
|
+
* @returns {Promise<void|false>} If it fails, it returns `false`.
|
|
13
10
|
*/
|
|
14
11
|
export async function write(content) {
|
|
15
12
|
if (!isClipboardSupported) {
|
|
16
13
|
console.error('Clipboard is not supported in this browser.');
|
|
17
|
-
return;
|
|
14
|
+
return false;
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
let htmlString = '';
|
|
@@ -44,16 +41,30 @@ export async function write(content) {
|
|
|
44
41
|
plainText = content.textContent;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
try {
|
|
45
|
+
await navigator.clipboard.write([
|
|
46
|
+
/* eslint-disable-next-line compat/compat */
|
|
47
|
+
new ClipboardItem({
|
|
48
|
+
'text/html': new Blob([htmlString], { type: 'text/html' }),
|
|
49
|
+
'text/plain': new Blob([plainText], { type: 'text/plain' }),
|
|
50
|
+
}),
|
|
51
|
+
]);
|
|
52
|
+
} catch {
|
|
53
|
+
console.warn('[SUNEDITOR.copy.warn] This browser is not supported Clipboard API');
|
|
54
|
+
try {
|
|
55
|
+
await navigator.clipboard.writeText(plainText || stripHtml(htmlString));
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error('[SUNEDITOR.copy.fail] ' + err);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function stripHtml(html) {
|
|
63
|
+
const div = document.createElement('div');
|
|
64
|
+
div.innerHTML = html;
|
|
65
|
+
return div.textContent || div.innerText || '';
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
export default {
|
|
58
|
-
write
|
|
69
|
+
write,
|
|
59
70
|
};
|
package/src/helper/converter.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { _d, _w } from './env';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const _RE_HTML_CHARS = /&|\u00A0|'|"|<|>/g;
|
|
4
|
+
const _RE_HTML_ENTITIES = /&| |'|"|<|>/g;
|
|
5
|
+
const _HTML_TO_ENTITY = { '&': '&', '\u00A0': ' ', "'": ''', '"': '"', '<': '<', '>': '>' };
|
|
6
|
+
const _ENTITY_TO_HTML = { '&': '&', ' ': '\u00A0', ''': "'", '"': '"', '<': '<', '>': '>' };
|
|
7
|
+
const _RE_UPPER_CASE = /[A-Z]/g;
|
|
8
|
+
const _RE_KEBAB_CHAR = /-[a-zA-Z]/g;
|
|
9
|
+
|
|
4
10
|
const FONT_VALUES_MAP = {
|
|
5
11
|
'xx-small': 0.5625,
|
|
6
12
|
'x-small': 0.625,
|
|
@@ -9,7 +15,7 @@ const FONT_VALUES_MAP = {
|
|
|
9
15
|
large: 1.125,
|
|
10
16
|
'x-large': 1.5,
|
|
11
17
|
'xx-large': 2,
|
|
12
|
-
'xxx-large': 2.5
|
|
18
|
+
'xxx-large': 2.5,
|
|
13
19
|
};
|
|
14
20
|
|
|
15
21
|
function NodeToJson(node) {
|
|
@@ -26,7 +32,7 @@ function NodeToJson(node) {
|
|
|
26
32
|
type: 'element',
|
|
27
33
|
tag: node.tagName.toLowerCase(),
|
|
28
34
|
attributes: {},
|
|
29
|
-
children: []
|
|
35
|
+
children: [],
|
|
30
36
|
};
|
|
31
37
|
|
|
32
38
|
// get attribute
|
|
@@ -48,8 +54,13 @@ function NodeToJson(node) {
|
|
|
48
54
|
|
|
49
55
|
/**
|
|
50
56
|
* @description Parses an HTML string into a DOM tree, then recursively traverses the nodes to convert them into a structured JSON representation.
|
|
51
|
-
* -Each element includes its tag name, attributes, and children.
|
|
52
|
-
* -Text nodes are represented as { type: 'text', content: '...' }
|
|
57
|
+
* - Each element includes its tag name, attributes, and children.
|
|
58
|
+
* - Text nodes are represented as `{ type: 'text', content: '...' }`.
|
|
59
|
+
* @example
|
|
60
|
+
* const json = converter.htmlToJson('<p class="txt">Hello</p>');
|
|
61
|
+
* // { type: 'element', tag: 'p', attributes: { class: 'txt' }, children: [
|
|
62
|
+
* // { type: 'text', content: 'Hello' }
|
|
63
|
+
* // ]}
|
|
53
64
|
* @param {string} content HTML string
|
|
54
65
|
* @returns {Object<string, *>} JSON data
|
|
55
66
|
*/
|
|
@@ -61,9 +72,15 @@ export function htmlToJson(content) {
|
|
|
61
72
|
|
|
62
73
|
/**
|
|
63
74
|
* @description Takes a JSON structure representing HTML elements and recursively serializes it into a valid HTML string.
|
|
64
|
-
* -It rebuilds each tag with attributes and inner content.
|
|
75
|
+
* - It rebuilds each tag with attributes and inner content.
|
|
65
76
|
* Text content and attributes are safely escaped to prevent parsing issues or XSS.
|
|
66
77
|
* Useful for restoring dynamic HTML from a data format.
|
|
78
|
+
* @example
|
|
79
|
+
* const html = converter.jsonToHtml({
|
|
80
|
+
* type: 'element', tag: 'p', attributes: { class: 'txt' },
|
|
81
|
+
* children: [{ type: 'text', content: 'Hello' }],
|
|
82
|
+
* });
|
|
83
|
+
* // '<p class="txt">Hello</p>'
|
|
67
84
|
* @param {Object<string, *>} jsonData
|
|
68
85
|
* @returns {string} HTML string
|
|
69
86
|
*/
|
|
@@ -97,19 +114,10 @@ export function jsonToHtml(jsonData) {
|
|
|
97
114
|
* @description Convert HTML string to HTML Entity
|
|
98
115
|
* @param {string} content
|
|
99
116
|
* @returns {string} Content string
|
|
100
|
-
* @private
|
|
101
117
|
*/
|
|
102
118
|
export function htmlToEntity(content) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
'\u00A0': ' ',
|
|
106
|
-
"'": ''',
|
|
107
|
-
'"': '"',
|
|
108
|
-
'<': '<',
|
|
109
|
-
'>': '>'
|
|
110
|
-
};
|
|
111
|
-
return content.replace(/&|\u00A0|'|"|<|>/g, (m) => {
|
|
112
|
-
return typeof ec[m] === 'string' ? ec[m] : m;
|
|
119
|
+
return content.replace(_RE_HTML_CHARS, (m) => {
|
|
120
|
+
return _HTML_TO_ENTITY[m] || m;
|
|
113
121
|
});
|
|
114
122
|
}
|
|
115
123
|
|
|
@@ -119,16 +127,8 @@ export function htmlToEntity(content) {
|
|
|
119
127
|
* @returns {string}
|
|
120
128
|
*/
|
|
121
129
|
export function entityToHTML(content) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
' ': '\u00A0',
|
|
125
|
-
''': "'",
|
|
126
|
-
'"': '"',
|
|
127
|
-
'<': '<',
|
|
128
|
-
'>': '>'
|
|
129
|
-
};
|
|
130
|
-
return content.replace(/&| |'|"|\$lt;|\$gt;/g, (m) => {
|
|
131
|
-
return typeof ec[m] === 'string' ? ec[m] : m;
|
|
130
|
+
return content.replace(_RE_HTML_ENTITIES, (m) => {
|
|
131
|
+
return _ENTITY_TO_HTML[m] || m;
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -200,16 +200,16 @@ export function getValues(obj) {
|
|
|
200
200
|
? []
|
|
201
201
|
: Object.keys(obj).map(function (i) {
|
|
202
202
|
return obj[i];
|
|
203
|
-
|
|
203
|
+
});
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
/**
|
|
207
|
-
* @description Convert the CamelCase To the KebabCase
|
|
207
|
+
* @description Convert the `CamelCase` To the `KebabCase`.
|
|
208
208
|
* @param {string|Array<string>} param [Camel string]
|
|
209
209
|
*/
|
|
210
210
|
export function camelToKebabCase(param) {
|
|
211
211
|
if (typeof param === 'string') {
|
|
212
|
-
return param.replace(
|
|
212
|
+
return param.replace(_RE_UPPER_CASE, (letter) => '-' + letter.toLowerCase());
|
|
213
213
|
} else {
|
|
214
214
|
return param.map(function (str) {
|
|
215
215
|
return camelToKebabCase(str);
|
|
@@ -219,28 +219,33 @@ export function camelToKebabCase(param) {
|
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
221
|
* @overload
|
|
222
|
-
* @param {string} param - Kebab-case string.
|
|
223
|
-
* @returns {string} CamelCase string.
|
|
222
|
+
* @param {string} param - `Kebab-case` string.
|
|
223
|
+
* @returns {string} `CamelCase` string.
|
|
224
224
|
*/
|
|
225
225
|
/**
|
|
226
226
|
* @overload
|
|
227
|
-
* @param {Array<string>} param - Array of Kebab-case strings.
|
|
228
|
-
* @returns {Array<string>} Array of CamelCase strings.
|
|
227
|
+
* @param {Array<string>} param - Array of `Kebab-case` strings.
|
|
228
|
+
* @returns {Array<string>} Array of `CamelCase` strings.
|
|
229
229
|
*/
|
|
230
230
|
export function kebabToCamelCase(param) {
|
|
231
231
|
if (typeof param === 'string') {
|
|
232
|
-
return param.replace(
|
|
232
|
+
return param.replace(_RE_KEBAB_CHAR, (letter) => letter.replace('-', '').toUpperCase());
|
|
233
233
|
} else {
|
|
234
234
|
return param.map(function (str) {
|
|
235
|
-
return
|
|
235
|
+
return kebabToCamelCase(str);
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
/**
|
|
241
|
-
*
|
|
241
|
+
* @description Converts a font size string from one CSS unit to another.
|
|
242
|
+
* @example
|
|
243
|
+
* converter.toFontUnit('px', '1rem'); // '16px'
|
|
244
|
+
* converter.toFontUnit('em', '16px'); // '1.00em'
|
|
245
|
+
* converter.toFontUnit('pt', '16px'); // '12pt'
|
|
246
|
+
* converter.toFontUnit('%', '16px'); // '100%'
|
|
242
247
|
* @param {"em"|"rem"|"%"|"pt"|"px"} to Size units to be converted
|
|
243
|
-
* @param {string} size
|
|
248
|
+
* @param {string} size Size to convert with units (ex: `"15rem"`)
|
|
244
249
|
* @returns {string}
|
|
245
250
|
*/
|
|
246
251
|
export function toFontUnit(to, size) {
|
|
@@ -273,7 +278,7 @@ export function toFontUnit(to, size) {
|
|
|
273
278
|
|
|
274
279
|
/**
|
|
275
280
|
* @description Convert the node list to an array. If not, returns an empty array.
|
|
276
|
-
* @param {?
|
|
281
|
+
* @param {?SunEditor.NodeCollection} [nodeList]
|
|
277
282
|
* @returns Array
|
|
278
283
|
*/
|
|
279
284
|
export function nodeListToArray(nodeList) {
|
|
@@ -300,8 +305,8 @@ export function swapKeyValue(obj) {
|
|
|
300
305
|
}
|
|
301
306
|
|
|
302
307
|
/**
|
|
303
|
-
* @description Create whitelist RegExp object.
|
|
304
|
-
* @param {string} list Tags list ("br|p|div|pre...")
|
|
308
|
+
* @description Create whitelist `RegExp` object.
|
|
309
|
+
* @param {string} list Tags list (`"br|p|div|pre..."`)
|
|
305
310
|
* @returns {RegExp} Return RegExp format: new RegExp("<\\/?\\b(?!" + list + ")\\b[^>^<]*+>", "gi")
|
|
306
311
|
*/
|
|
307
312
|
export function createElementWhitelist(list) {
|
|
@@ -309,8 +314,8 @@ export function createElementWhitelist(list) {
|
|
|
309
314
|
}
|
|
310
315
|
|
|
311
316
|
/**
|
|
312
|
-
* @description Create blacklist RegExp object.
|
|
313
|
-
* @param {string} list Tags list ("br|p|div|pre...")
|
|
317
|
+
* @description Create blacklist `RegExp` object.
|
|
318
|
+
* @param {string} list Tags list (`"br|p|div|pre..."`)
|
|
314
319
|
* @returns {RegExp} Return RegExp format: new RegExp("<\\/?\\b(?:" + list + ")\\b[^>^<]*+>", "gi")
|
|
315
320
|
*/
|
|
316
321
|
export function createElementBlacklist(list) {
|
|
@@ -326,7 +331,7 @@ export function isHexColor(str) {
|
|
|
326
331
|
}
|
|
327
332
|
|
|
328
333
|
/**
|
|
329
|
-
* @description Function to convert hex format to a rgb color
|
|
334
|
+
* @description Function to convert hex format to a `rgb` color
|
|
330
335
|
* @param {string} rgba RGBA color format
|
|
331
336
|
* @returns {string}
|
|
332
337
|
*/
|
|
@@ -342,7 +347,7 @@ export function rgb2hex(rgba) {
|
|
|
342
347
|
|
|
343
348
|
let a = '';
|
|
344
349
|
if (rgba.includes('rgba')) {
|
|
345
|
-
const alphaMatch = rgba.match(
|
|
350
|
+
const alphaMatch = rgba.match(/,\s*([\d]+\.?[\d]*)\s*\)/);
|
|
346
351
|
if (alphaMatch) {
|
|
347
352
|
a = ('0' + Math.round(parseFloat(alphaMatch[1]) * 255).toString(16)).slice(-2);
|
|
348
353
|
}
|
|
@@ -357,7 +362,7 @@ export function rgb2hex(rgba) {
|
|
|
357
362
|
/**
|
|
358
363
|
* @description Computes the width as a percentage of the parent's width, and returns this value rounded to two decimal places.
|
|
359
364
|
* @param {HTMLElement} target The target element for which to calculate the width percentage.
|
|
360
|
-
* @param {?HTMLElement
|
|
365
|
+
* @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.
|
|
361
366
|
* @returns {number}
|
|
362
367
|
*/
|
|
363
368
|
export function getWidthInPercentage(target, parentTarget) {
|
|
@@ -374,17 +379,19 @@ export function getWidthInPercentage(target, parentTarget) {
|
|
|
374
379
|
/**
|
|
375
380
|
* @description Convert url pattern text node to anchor node
|
|
376
381
|
* @param {Node} node Text node
|
|
377
|
-
* @returns {boolean} Return true if the text node is converted to an anchor node
|
|
382
|
+
* @returns {boolean} Return `true` if the text node is converted to an anchor node
|
|
378
383
|
*/
|
|
379
384
|
export function textToAnchor(node) {
|
|
385
|
+
const URLPattern = /https?:\/\/[^\s]+/g;
|
|
386
|
+
|
|
380
387
|
if (node.nodeType === 3 && URLPattern.test(node.textContent) && !/^A$/i.test(node.parentNode?.nodeName)) {
|
|
381
388
|
const textContent = node.textContent;
|
|
382
389
|
const fragment = _d.createDocumentFragment();
|
|
383
390
|
|
|
384
391
|
let lastIndex = 0;
|
|
385
392
|
textContent.replace(URLPattern, (match, offset) => {
|
|
386
|
-
if (offset >
|
|
387
|
-
fragment.appendChild(_d.createTextNode(textContent.slice(
|
|
393
|
+
if (offset > lastIndex) {
|
|
394
|
+
fragment.appendChild(_d.createTextNode(textContent.slice(lastIndex, offset)));
|
|
388
395
|
}
|
|
389
396
|
const anchor = _d.createElement('a');
|
|
390
397
|
anchor.href = match;
|
|
@@ -392,12 +399,13 @@ export function textToAnchor(node) {
|
|
|
392
399
|
anchor.textContent = match;
|
|
393
400
|
fragment.appendChild(anchor);
|
|
394
401
|
lastIndex = offset + match.length;
|
|
395
|
-
if (lastIndex < textContent.length) {
|
|
396
|
-
fragment.appendChild(_d.createTextNode(textContent.slice(lastIndex)));
|
|
397
|
-
}
|
|
398
402
|
return match;
|
|
399
403
|
});
|
|
400
404
|
|
|
405
|
+
if (lastIndex < textContent.length) {
|
|
406
|
+
fragment.appendChild(_d.createTextNode(textContent.slice(lastIndex)));
|
|
407
|
+
}
|
|
408
|
+
|
|
401
409
|
node.parentNode.replaceChild(fragment, node);
|
|
402
410
|
return true;
|
|
403
411
|
}
|
|
@@ -406,8 +414,8 @@ export function textToAnchor(node) {
|
|
|
406
414
|
}
|
|
407
415
|
|
|
408
416
|
/**
|
|
409
|
-
* Converts styles within a
|
|
410
|
-
* Maintains the original
|
|
417
|
+
* Converts styles within a `<span>` tag to corresponding HTML tags (e.g., `<strong>`, `<em>`, `<u>`, `<s>`).
|
|
418
|
+
* Maintains the original `<span>` tag and wraps its content with the new tags.
|
|
411
419
|
* @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' },}
|
|
412
420
|
* @param {Node} node Node
|
|
413
421
|
*/
|
|
@@ -441,10 +449,6 @@ export function spanToStyleNode(styleToTag, node) {
|
|
|
441
449
|
currentNode = nextNode;
|
|
442
450
|
}
|
|
443
451
|
|
|
444
|
-
while (node.firstChild) {
|
|
445
|
-
node.removeChild(node.firstChild);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
452
|
node.appendChild(temp);
|
|
449
453
|
}
|
|
450
454
|
}
|
|
@@ -468,12 +472,15 @@ export function addUrlQuery(url, query) {
|
|
|
468
472
|
return url;
|
|
469
473
|
}
|
|
470
474
|
|
|
475
|
+
/**
|
|
476
|
+
* @typedef {import('../core/schema/options').OptionStyleResult} OptionStyleResult_converter
|
|
477
|
+
*/
|
|
478
|
+
|
|
471
479
|
/**
|
|
472
480
|
* @description Converts options-related styles and returns them for each frame.
|
|
473
|
-
* @param {
|
|
481
|
+
* @param {SunEditor.FrameOptions} fo `editor.frameOptions`
|
|
474
482
|
* @param {string} cssText Style string
|
|
475
|
-
* @returns {
|
|
476
|
-
* @private
|
|
483
|
+
* @returns {OptionStyleResult_converter}
|
|
477
484
|
*/
|
|
478
485
|
export function _setDefaultOptionStyle(fo, cssText) {
|
|
479
486
|
let optionStyle = '';
|
|
@@ -509,34 +516,49 @@ export function _setDefaultOptionStyle(fo, cssText) {
|
|
|
509
516
|
return {
|
|
510
517
|
top: top,
|
|
511
518
|
frame: frame,
|
|
512
|
-
editor: editor
|
|
519
|
+
editor: editor,
|
|
513
520
|
};
|
|
514
521
|
}
|
|
515
522
|
|
|
516
523
|
/**
|
|
517
|
-
* @description Set default style tag of the iframe
|
|
518
|
-
* @param {Array<string>} linkNames link names array of CSS files
|
|
519
|
-
* @returns {string} "<link rel="stylesheet" href=".." />.."
|
|
524
|
+
* @description Set default style tag of the `iframe`
|
|
525
|
+
* @param {Array<string>} linkNames link names array of CSS files or `'*'` for all stylesheets
|
|
526
|
+
* @returns {string} `"<link rel="stylesheet" href=".." />.."`
|
|
520
527
|
*/
|
|
521
528
|
export function _setIframeStyleLinks(linkNames) {
|
|
522
529
|
let tagString = '';
|
|
523
530
|
|
|
524
531
|
if (linkNames) {
|
|
532
|
+
const allLinks = _d.getElementsByTagName('link');
|
|
533
|
+
|
|
525
534
|
for (let f = 0, len = linkNames.length, path; f < len; f++) {
|
|
526
535
|
path = [];
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
536
|
+
const linkName = linkNames[f];
|
|
537
|
+
|
|
538
|
+
// Wildcard: include all stylesheets
|
|
539
|
+
if (linkName === '*') {
|
|
540
|
+
for (let i = 0, cLen = allLinks.length; i < cLen; i++) {
|
|
541
|
+
if (allLinks[i].rel === 'stylesheet' && allLinks[i].href) {
|
|
542
|
+
path.push(allLinks[i].href);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
// Absolute URL or data URL
|
|
547
|
+
else if (/(^https?:\/\/)|(^data:text\/css,)/.test(linkName)) {
|
|
548
|
+
path.push(linkName);
|
|
549
|
+
}
|
|
550
|
+
// String pattern (convert to regex)
|
|
551
|
+
else {
|
|
552
|
+
const CSSFileName = new RegExp(`(^|.*[\\/])${linkName}(\\..+)?.css((\\??.+?)|\\b)$`, 'i');
|
|
553
|
+
for (let i = 0, cLen = allLinks.length, styleTag; i < cLen; i++) {
|
|
554
|
+
styleTag = allLinks[i].href.match(CSSFileName);
|
|
534
555
|
if (styleTag) path.push(styleTag[0]);
|
|
535
556
|
}
|
|
536
557
|
}
|
|
537
558
|
|
|
538
|
-
if (!path || path.length === 0)
|
|
539
|
-
throw '[SUNEDITOR.constructor.iframe.fail] The suneditor CSS files installation path could not be automatically detected. Please set the option property "iframe_cssFileName" before creating editor instances.';
|
|
559
|
+
if (!path || path.length === 0) {
|
|
560
|
+
throw new Error('[SUNEDITOR.constructor.iframe.fail] The suneditor CSS files installation path could not be automatically detected. Please set the option property "iframe_cssFileName" before creating editor instances.');
|
|
561
|
+
}
|
|
540
562
|
|
|
541
563
|
for (let i = 0, pLen = path.length; i < pLen; i++) {
|
|
542
564
|
tagString += '<link href="' + path[i] + '" rel="stylesheet">';
|
|
@@ -548,9 +570,9 @@ export function _setIframeStyleLinks(linkNames) {
|
|
|
548
570
|
}
|
|
549
571
|
|
|
550
572
|
/**
|
|
551
|
-
* @description When iframe height options is "auto" return "<style>" tag that required.
|
|
552
|
-
* @param {string} frameHeight height
|
|
553
|
-
* @returns {string} "<style>...</style>"
|
|
573
|
+
* @description When `iframe` height options is `"auto"` return `"<style>"` tag that required.
|
|
574
|
+
* @param {string|number} frameHeight height
|
|
575
|
+
* @returns {string} `"<style>...</style>"`
|
|
554
576
|
*/
|
|
555
577
|
export function _setAutoHeightStyle(frameHeight) {
|
|
556
578
|
return frameHeight === 'auto' ? '<style>\n/** Iframe height auto */\nbody{height: min-content; overflow: hidden;}\n</style>' : '';
|
|
@@ -580,7 +602,7 @@ const converter = {
|
|
|
580
602
|
addUrlQuery,
|
|
581
603
|
_setDefaultOptionStyle,
|
|
582
604
|
_setIframeStyleLinks,
|
|
583
|
-
_setAutoHeightStyle
|
|
605
|
+
_setAutoHeightStyle,
|
|
584
606
|
};
|
|
585
607
|
|
|
586
608
|
export default converter;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Implements Helper for checking the node type and attributes.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
import { onlyZeroWidthRegExp } from '../unicode';
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
const _RE_EXCLUDE_FORMAT = /(\s|^)(katex|MathJax|se-exclude-format)(\s|$)/;
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
|
-
* @description A method that checks If the text is blank or to see if it contains
|
|
6
|
+
* @description A method that checks If the text is blank or to see if it contains `ZERO WIDTH SPACE` or empty (`unicode.zeroWidthSpace`)
|
|
10
7
|
* @param {string|Node} text String value or Node
|
|
11
8
|
* @returns {boolean}
|
|
12
9
|
*/
|
|
13
10
|
export function isZeroWidth(text) {
|
|
14
11
|
if (text === null || text === undefined) return false;
|
|
15
|
-
if (typeof text !== 'string')
|
|
12
|
+
if (typeof text !== 'string') {
|
|
13
|
+
if (isElement(text)) {
|
|
14
|
+
const children = text.children;
|
|
15
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
16
|
+
const child = children[i];
|
|
17
|
+
if (!isContentLess(child)) return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
text = text.textContent;
|
|
21
|
+
}
|
|
16
22
|
return text === '' || onlyZeroWidthRegExp.test(text);
|
|
17
23
|
}
|
|
18
24
|
|
|
@@ -20,16 +26,16 @@ export function isZeroWidth(text) {
|
|
|
20
26
|
* @description Determine if this offset is the edge offset of container
|
|
21
27
|
* @param {Node} container The node of the selection object. (range.startContainer..)
|
|
22
28
|
* @param {number} offset The offset of the selection object. (core.getRange().startOffset...)
|
|
23
|
-
* @param {?"front"|"end"
|
|
29
|
+
* @param {?("front"|"end")} [dir] Select check point - Both edge, Front edge or End edge. (`"front"`: Front edge, `"end"`: End edge, `undefined`: Both edge)
|
|
24
30
|
* @returns {boolean}
|
|
25
31
|
*/
|
|
26
32
|
export function isEdgePoint(container, offset, dir) {
|
|
27
|
-
return (dir !== 'end' && offset === 0) || ((!dir || dir !== 'front') && !container.nodeValue && offset
|
|
33
|
+
return (dir !== 'end' && offset === 0) || ((!dir || dir !== 'front') && !container.nodeValue && offset <= 1) || ((!dir || dir === 'end') && container.nodeValue && offset >= container.nodeValue.length);
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
37
|
* @description Check the node is a text node.
|
|
32
|
-
* @param {
|
|
38
|
+
* @param {?*} node The node to check
|
|
33
39
|
* @returns {node is Text}
|
|
34
40
|
*/
|
|
35
41
|
export function isText(node) {
|
|
@@ -38,7 +44,7 @@ export function isText(node) {
|
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* @description Check the node is an HTMLElement node.
|
|
41
|
-
* @param {
|
|
47
|
+
* @param {?*} node The node to check
|
|
42
48
|
* @returns {node is HTMLElement}
|
|
43
49
|
*/
|
|
44
50
|
export function isElement(node) {
|
|
@@ -47,7 +53,7 @@ export function isElement(node) {
|
|
|
47
53
|
|
|
48
54
|
/**
|
|
49
55
|
* @description It is judged whether it is the input element (INPUT, TEXTAREA)
|
|
50
|
-
* @param {
|
|
56
|
+
* @param {?*} node The node to check
|
|
51
57
|
* @returns {node is HTMLInputElement}
|
|
52
58
|
*/
|
|
53
59
|
export function isInputElement(node) {
|
|
@@ -56,7 +62,7 @@ export function isInputElement(node) {
|
|
|
56
62
|
|
|
57
63
|
/**
|
|
58
64
|
* @description It is judged whether it is the button element
|
|
59
|
-
* @param {
|
|
65
|
+
* @param {?*} node The node to check
|
|
60
66
|
* @returns {node is HTMLButtonElement}
|
|
61
67
|
*/
|
|
62
68
|
export function isButtonElement(node) {
|
|
@@ -172,8 +178,8 @@ export function isContentLess(node) {
|
|
|
172
178
|
}
|
|
173
179
|
|
|
174
180
|
/**
|
|
175
|
-
* @description Check the line element is empty.
|
|
176
|
-
* @param {Node} node
|
|
181
|
+
* @description Check the `line` element is empty.
|
|
182
|
+
* @param {Node} node `line` element node
|
|
177
183
|
* @returns {boolean}
|
|
178
184
|
*/
|
|
179
185
|
export function isEmptyLine(node) {
|
|
@@ -183,16 +189,37 @@ export function isEmptyLine(node) {
|
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
/**
|
|
186
|
-
* @description
|
|
192
|
+
* @description Checks if the given node is a container component (class `se-component-container`).
|
|
193
|
+
* @param {Node} element
|
|
194
|
+
* @returns {boolean} `true` if the node is a container component, otherwise `false`.
|
|
195
|
+
*/
|
|
196
|
+
export function isComponentContainer(element) {
|
|
197
|
+
if (element?.nodeType !== 1) return false;
|
|
198
|
+
|
|
199
|
+
const el = /** @type {Element} */ (element);
|
|
200
|
+
const cls = el.classList;
|
|
201
|
+
|
|
202
|
+
if (!cls) return false;
|
|
203
|
+
return cls.contains('se-component') || cls.contains('se-flex-component');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @description It is judged whether it is the edit region top `div` element or `iframe`'s `body` tag.
|
|
187
208
|
* @param {?Node} node The node to check
|
|
188
209
|
* @returns {node is HTMLElement}
|
|
189
210
|
*/
|
|
190
211
|
export function isWysiwygFrame(node) {
|
|
191
|
-
|
|
212
|
+
if (node?.nodeType !== 1) return false;
|
|
213
|
+
|
|
214
|
+
const el = /** @type {Element} */ (node);
|
|
215
|
+
const cls = el.classList;
|
|
216
|
+
|
|
217
|
+
if (!cls) return false;
|
|
218
|
+
return node.nodeName.toUpperCase() === 'BODY' || cls.contains('se-wrapper-wysiwyg') || cls.contains('sun-editor-carrier-wrapper') || cls.contains('se-wrapper');
|
|
192
219
|
}
|
|
193
220
|
|
|
194
221
|
/**
|
|
195
|
-
* @description It is judged whether it is the contenteditable property is false
|
|
222
|
+
* @description It is judged whether it is the `contenteditable` property is `false`.
|
|
196
223
|
* @param {?Node} node The node to check
|
|
197
224
|
* @returns {node is HTMLElement}
|
|
198
225
|
*/
|
|
@@ -201,14 +228,14 @@ export function isNonEditable(node) {
|
|
|
201
228
|
}
|
|
202
229
|
|
|
203
230
|
/**
|
|
204
|
-
* @description Check the span's attributes are empty.
|
|
231
|
+
* @description Check the `span`'s attributes are empty.
|
|
205
232
|
* @param {?Node} node Element node
|
|
206
233
|
* @returns {boolean}
|
|
207
234
|
*/
|
|
208
235
|
export function isSpanWithoutAttr(node) {
|
|
209
236
|
if (node?.nodeType !== 1) return false;
|
|
210
237
|
const el = /** @type {HTMLElement} */ (node);
|
|
211
|
-
return /^SPAN$/i.test(el.nodeName) && !el.className &&
|
|
238
|
+
return /^SPAN$/i.test(el.nodeName) && !el.className && el.style.length === 0;
|
|
212
239
|
}
|
|
213
240
|
|
|
214
241
|
/**
|
|
@@ -234,33 +261,31 @@ export function isSameAttributes(a, b) {
|
|
|
234
261
|
|
|
235
262
|
const class_a = aEl.classList;
|
|
236
263
|
const class_b = bEl.classList;
|
|
237
|
-
const wRegExp = RegExp;
|
|
238
264
|
let compClass = 0;
|
|
239
|
-
|
|
240
265
|
for (let i = 0, len = class_a.length; i < len; i++) {
|
|
241
|
-
if (
|
|
266
|
+
if (class_b.contains(class_a[i])) compClass++;
|
|
242
267
|
}
|
|
243
268
|
|
|
244
269
|
return compStyle === style_b.length && compStyle === style_a.length && compClass === class_b.length && compClass === class_a.length;
|
|
245
270
|
}
|
|
246
271
|
|
|
247
272
|
/**
|
|
248
|
-
* @description It is judged whether it is the not checking node. (class
|
|
273
|
+
* @description It is judged whether it is the not checking node. (class=`katex`, `MathJax`, `se-exclude-format`)
|
|
249
274
|
* @param {Node} node The node to check
|
|
250
275
|
* @returns {node is HTMLElement}
|
|
251
276
|
*/
|
|
252
277
|
export function isExcludeFormat(node) {
|
|
253
|
-
return
|
|
278
|
+
return _RE_EXCLUDE_FORMAT.test(/** @type {HTMLElement} */ (node)?.className);
|
|
254
279
|
}
|
|
255
280
|
|
|
256
281
|
/**
|
|
257
|
-
* @description Checks for
|
|
258
|
-
* - Components with class
|
|
282
|
+
* @description Checks for `__se__uneditable` in the class list.
|
|
283
|
+
* - Components with class `__se__uneditable` cannot be modified.
|
|
259
284
|
* @param {Node} node The element to check
|
|
260
285
|
* @returns {boolean}
|
|
261
286
|
*/
|
|
262
287
|
export function isUneditable(node) {
|
|
263
|
-
return
|
|
288
|
+
return /** @type {HTMLElement} */ (node)?.classList.contains('__se__uneditable');
|
|
264
289
|
}
|
|
265
290
|
|
|
266
291
|
/**
|
|
@@ -269,7 +294,7 @@ export function isUneditable(node) {
|
|
|
269
294
|
* @returns {boolean}
|
|
270
295
|
*/
|
|
271
296
|
export function isImportantDisabled(node) {
|
|
272
|
-
return /** @type {HTMLElement} */ (node)
|
|
297
|
+
return /** @type {HTMLElement} */ (node)?.hasAttribute('data-important-disabled');
|
|
273
298
|
}
|
|
274
299
|
|
|
275
300
|
const check = {
|
|
@@ -292,13 +317,14 @@ const check = {
|
|
|
292
317
|
isFigure,
|
|
293
318
|
isContentLess,
|
|
294
319
|
isEmptyLine,
|
|
320
|
+
isComponentContainer,
|
|
295
321
|
isWysiwygFrame,
|
|
296
322
|
isNonEditable,
|
|
297
323
|
isSpanWithoutAttr,
|
|
298
324
|
isSameAttributes,
|
|
299
325
|
isExcludeFormat,
|
|
300
326
|
isUneditable,
|
|
301
|
-
isImportantDisabled
|
|
327
|
+
isImportantDisabled,
|
|
302
328
|
};
|
|
303
329
|
|
|
304
330
|
export default check;
|