suneditor 3.0.0-alpha.9 → 3.0.0-beta.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/CONTRIBUTING.md +170 -22
- package/{LICENSE.txt → LICENSE} +9 -9
- package/README.md +168 -30
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +47 -21
- package/src/assets/design/color.css +121 -0
- package/src/assets/design/index.css +3 -0
- package/src/assets/design/size.css +35 -0
- package/src/assets/design/typography.css +37 -0
- package/src/assets/icons/defaultIcons.js +232 -0
- package/src/assets/suneditor-contents.css +181 -46
- package/src/assets/suneditor.css +1403 -650
- package/src/core/base/eventHandlers/handler_toolbar.js +35 -14
- package/src/core/base/eventHandlers/handler_ww_clipboard.js +23 -4
- package/src/core/base/eventHandlers/handler_ww_dragDrop.js +49 -10
- package/src/core/base/eventHandlers/handler_ww_key_input.js +422 -224
- package/src/core/base/eventHandlers/handler_ww_mouse.js +83 -36
- package/src/core/base/eventManager.js +520 -179
- package/src/core/base/history.js +95 -41
- package/src/core/class/char.js +26 -11
- package/src/core/class/component.js +345 -137
- package/src/core/class/format.js +683 -519
- package/src/core/class/html.js +485 -305
- package/src/core/class/menu.js +133 -47
- package/src/core/class/nodeTransform.js +90 -71
- package/src/core/class/offset.js +408 -92
- package/src/core/class/selection.js +216 -106
- package/src/core/class/shortcuts.js +68 -8
- package/src/core/class/toolbar.js +106 -116
- package/src/core/class/ui.js +422 -0
- package/src/core/class/viewer.js +178 -74
- package/src/core/editor.js +496 -389
- package/src/core/section/actives.js +123 -27
- package/src/core/section/constructor.js +615 -206
- package/src/core/section/context.js +28 -23
- package/src/core/section/documentType.js +561 -0
- package/src/editorInjector/_classes.js +19 -5
- package/src/editorInjector/_core.js +71 -7
- package/src/editorInjector/index.js +63 -1
- package/src/events.js +622 -0
- package/src/helper/clipboard.js +59 -0
- package/src/helper/converter.js +202 -26
- package/src/helper/dom/domCheck.js +304 -0
- package/src/helper/dom/domQuery.js +669 -0
- package/src/helper/dom/domUtils.js +557 -0
- package/src/helper/dom/index.js +12 -0
- package/src/helper/env.js +46 -56
- package/src/helper/index.js +10 -4
- package/src/helper/keyCodeMap.js +183 -0
- package/src/helper/numbers.js +12 -8
- package/src/helper/unicode.js +9 -5
- package/src/langs/ckb.js +74 -4
- package/src/langs/cs.js +72 -2
- package/src/langs/da.js +73 -3
- package/src/langs/de.js +73 -4
- package/src/langs/en.js +23 -3
- package/src/langs/es.js +73 -4
- package/src/langs/fa.js +75 -3
- package/src/langs/fr.js +73 -3
- package/src/langs/he.js +73 -4
- package/src/langs/hu.js +230 -0
- package/src/langs/index.js +7 -3
- package/src/langs/it.js +70 -1
- package/src/langs/ja.js +72 -4
- package/src/langs/km.js +230 -0
- package/src/langs/ko.js +22 -2
- package/src/langs/lv.js +74 -5
- package/src/langs/nl.js +73 -4
- package/src/langs/pl.js +73 -4
- package/src/langs/pt_br.js +70 -1
- package/src/langs/ro.js +74 -5
- package/src/langs/ru.js +73 -4
- package/src/langs/se.js +73 -4
- package/src/langs/tr.js +73 -1
- package/src/langs/{ua.js → uk.js} +75 -6
- package/src/langs/ur.js +77 -8
- package/src/langs/zh_cn.js +74 -5
- package/src/modules/ApiManager.js +77 -54
- package/src/modules/Browser.js +667 -0
- package/src/modules/ColorPicker.js +162 -102
- package/src/modules/Controller.js +273 -142
- package/src/modules/Figure.js +925 -484
- package/src/modules/FileManager.js +121 -69
- package/src/modules/HueSlider.js +113 -61
- package/src/modules/Modal.js +291 -122
- package/src/modules/ModalAnchorEditor.js +383 -234
- package/src/modules/SelectMenu.js +270 -168
- package/src/modules/_DragHandle.js +2 -1
- package/src/modules/index.js +3 -3
- package/src/plugins/browser/audioGallery.js +83 -0
- package/src/plugins/browser/fileBrowser.js +103 -0
- package/src/plugins/browser/fileGallery.js +83 -0
- package/src/plugins/browser/imageGallery.js +81 -0
- package/src/plugins/browser/videoGallery.js +103 -0
- package/src/plugins/command/blockquote.js +40 -27
- package/src/plugins/command/exportPDF.js +134 -0
- package/src/plugins/command/fileUpload.js +229 -162
- package/src/plugins/command/list_bulleted.js +83 -47
- package/src/plugins/command/list_numbered.js +83 -47
- package/src/plugins/dropdown/align.js +66 -54
- package/src/plugins/dropdown/backgroundColor.js +63 -49
- package/src/plugins/dropdown/font.js +71 -47
- package/src/plugins/dropdown/fontColor.js +63 -48
- package/src/plugins/dropdown/formatBlock.js +70 -33
- package/src/plugins/dropdown/hr.js +92 -51
- package/src/plugins/dropdown/layout.js +37 -26
- package/src/plugins/dropdown/lineHeight.js +54 -38
- package/src/plugins/dropdown/list.js +60 -45
- package/src/plugins/dropdown/paragraphStyle.js +51 -30
- package/src/plugins/dropdown/table.js +2003 -813
- package/src/plugins/dropdown/template.js +38 -26
- package/src/plugins/dropdown/textStyle.js +43 -31
- package/src/plugins/field/mention.js +147 -86
- package/src/plugins/index.js +32 -6
- package/src/plugins/input/fontSize.js +161 -108
- package/src/plugins/input/pageNavigator.js +70 -0
- package/src/plugins/modal/audio.js +358 -173
- package/src/plugins/modal/drawing.js +531 -0
- package/src/plugins/modal/embed.js +886 -0
- package/src/plugins/modal/image.js +674 -362
- package/src/plugins/modal/link.js +100 -71
- package/src/plugins/modal/math.js +367 -167
- package/src/plugins/modal/video.js +691 -335
- package/src/plugins/popup/anchor.js +222 -0
- package/src/suneditor.js +50 -13
- package/src/themes/dark.css +122 -0
- package/src/typedef.js +130 -0
- package/types/assets/icons/defaultIcons.d.ts +153 -0
- package/types/core/base/eventHandlers/handler_toolbar.d.ts +41 -0
- package/types/core/base/eventHandlers/handler_ww_clipboard.d.ts +40 -0
- package/types/core/base/eventHandlers/handler_ww_dragDrop.d.ts +35 -0
- package/types/core/base/eventHandlers/handler_ww_key_input.d.ts +45 -0
- package/types/core/base/eventHandlers/handler_ww_mouse.d.ts +39 -0
- package/types/core/base/eventManager.d.ts +385 -0
- package/types/core/base/history.d.ts +81 -0
- package/types/core/class/char.d.ts +60 -0
- package/types/core/class/component.d.ts +212 -0
- package/types/core/class/format.d.ts +616 -0
- package/types/core/class/html.d.ts +422 -0
- package/types/core/class/menu.d.ts +126 -0
- package/types/core/class/nodeTransform.d.ts +93 -0
- package/types/core/class/offset.d.ts +522 -0
- package/types/core/class/selection.d.ts +188 -0
- package/types/core/class/shortcuts.d.ts +142 -0
- package/types/core/class/toolbar.d.ts +189 -0
- package/types/core/class/ui.d.ts +164 -0
- package/types/core/class/viewer.d.ts +140 -0
- package/types/core/editor.d.ts +610 -0
- package/types/core/section/actives.d.ts +46 -0
- package/types/core/section/constructor.d.ts +777 -0
- package/types/core/section/context.d.ts +45 -0
- package/types/core/section/documentType.d.ts +178 -0
- package/types/editorInjector/_classes.d.ts +41 -0
- package/types/editorInjector/_core.d.ts +92 -0
- package/types/editorInjector/index.d.ts +71 -0
- package/types/events.d.ts +273 -0
- package/types/helper/clipboard.d.ts +12 -0
- package/types/helper/converter.d.ts +197 -0
- package/types/helper/dom/domCheck.d.ts +189 -0
- package/types/helper/dom/domQuery.d.ts +223 -0
- package/types/helper/dom/domUtils.d.ts +226 -0
- package/types/helper/dom/index.d.ts +9 -0
- package/types/helper/env.d.ts +132 -0
- package/types/helper/index.d.ts +174 -0
- package/types/helper/keyCodeMap.d.ts +110 -0
- package/types/helper/numbers.d.ts +46 -0
- package/types/helper/unicode.d.ts +28 -0
- package/types/index.d.ts +120 -0
- package/{typings/Lang.d.ts → types/langs/_Lang.d.ts} +173 -103
- package/types/langs/ckb.d.ts +3 -0
- package/types/langs/cs.d.ts +3 -0
- package/types/langs/da.d.ts +3 -0
- package/types/langs/de.d.ts +3 -0
- package/types/langs/en.d.ts +3 -0
- package/types/langs/es.d.ts +3 -0
- package/types/langs/fa.d.ts +3 -0
- package/types/langs/fr.d.ts +3 -0
- package/types/langs/he.d.ts +3 -0
- package/types/langs/hu.d.ts +3 -0
- package/types/langs/index.d.ts +54 -0
- package/types/langs/it.d.ts +3 -0
- package/types/langs/ja.d.ts +3 -0
- package/types/langs/km.d.ts +3 -0
- package/types/langs/ko.d.ts +3 -0
- package/types/langs/lv.d.ts +3 -0
- package/types/langs/nl.d.ts +3 -0
- package/types/langs/pl.d.ts +3 -0
- package/types/langs/pt_br.d.ts +3 -0
- package/types/langs/ro.d.ts +3 -0
- package/types/langs/ru.d.ts +3 -0
- package/types/langs/se.d.ts +3 -0
- package/types/langs/tr.d.ts +3 -0
- package/types/langs/uk.d.ts +3 -0
- package/types/langs/ur.d.ts +3 -0
- package/types/langs/zh_cn.d.ts +3 -0
- package/types/modules/ApiManager.d.ts +125 -0
- package/types/modules/Browser.d.ts +326 -0
- package/types/modules/ColorPicker.d.ts +131 -0
- package/types/modules/Controller.d.ts +251 -0
- package/types/modules/Figure.d.ts +517 -0
- package/types/modules/FileManager.d.ts +202 -0
- package/types/modules/HueSlider.d.ts +136 -0
- package/types/modules/Modal.d.ts +111 -0
- package/types/modules/ModalAnchorEditor.d.ts +236 -0
- package/types/modules/SelectMenu.d.ts +194 -0
- package/types/modules/_DragHandle.d.ts +7 -0
- package/types/modules/index.d.ts +26 -0
- package/types/plugins/browser/audioGallery.d.ts +55 -0
- package/types/plugins/browser/fileBrowser.d.ts +64 -0
- package/types/plugins/browser/fileGallery.d.ts +55 -0
- package/types/plugins/browser/imageGallery.d.ts +51 -0
- package/types/plugins/browser/videoGallery.d.ts +57 -0
- package/types/plugins/command/blockquote.d.ts +28 -0
- package/types/plugins/command/exportPDF.d.ts +46 -0
- package/types/plugins/command/fileUpload.d.ts +156 -0
- package/types/plugins/command/list_bulleted.d.ts +46 -0
- package/types/plugins/command/list_numbered.d.ts +46 -0
- package/types/plugins/dropdown/align.d.ts +60 -0
- package/types/plugins/dropdown/backgroundColor.d.ts +63 -0
- package/types/plugins/dropdown/font.d.ts +54 -0
- package/types/plugins/dropdown/fontColor.d.ts +63 -0
- package/types/plugins/dropdown/formatBlock.d.ts +54 -0
- package/types/plugins/dropdown/hr.d.ts +71 -0
- package/types/plugins/dropdown/layout.d.ts +40 -0
- package/types/plugins/dropdown/lineHeight.d.ts +50 -0
- package/types/plugins/dropdown/list.d.ts +39 -0
- package/types/plugins/dropdown/paragraphStyle.d.ts +54 -0
- package/types/plugins/dropdown/table.d.ts +627 -0
- package/types/plugins/dropdown/template.d.ts +40 -0
- package/types/plugins/dropdown/textStyle.d.ts +41 -0
- package/types/plugins/field/mention.d.ts +102 -0
- package/types/plugins/index.d.ts +107 -0
- package/types/plugins/input/fontSize.d.ts +170 -0
- package/types/plugins/input/pageNavigator.d.ts +28 -0
- package/types/plugins/modal/audio.d.ts +269 -0
- package/types/plugins/modal/drawing.d.ts +246 -0
- package/types/plugins/modal/embed.d.ts +387 -0
- package/types/plugins/modal/image.d.ts +451 -0
- package/types/plugins/modal/link.d.ts +128 -0
- package/types/plugins/modal/math.d.ts +193 -0
- package/types/plugins/modal/video.d.ts +485 -0
- package/types/plugins/popup/anchor.d.ts +56 -0
- package/types/suneditor.d.ts +51 -0
- package/types/typedef.d.ts +233 -0
- package/.eslintignore +0 -7
- package/.eslintrc.json +0 -64
- package/src/assets/icons/_default.js +0 -194
- package/src/core/base/events.js +0 -320
- package/src/core/class/notice.js +0 -42
- package/src/helper/domUtils.js +0 -1177
- package/src/modules/FileBrowser.js +0 -271
- package/src/plugins/command/exportPdf.js +0 -168
- package/src/plugins/fileBrowser/imageGallery.js +0 -81
- package/src/themes/test.css +0 -61
- package/typings/CommandPlugin.d.ts +0 -8
- package/typings/DialogPlugin.d.ts +0 -20
- package/typings/FileBrowserPlugin.d.ts +0 -30
- package/typings/Module.d.ts +0 -15
- package/typings/Plugin.d.ts +0 -42
- package/typings/SubmenuPlugin.d.ts +0 -8
- package/typings/_classes.d.ts +0 -17
- package/typings/_colorPicker.d.ts +0 -60
- package/typings/_core.d.ts +0 -55
- package/typings/align.d.ts +0 -5
- package/typings/audio.d.ts +0 -5
- package/typings/backgroundColor.d.ts +0 -5
- package/typings/blockquote.d.ts +0 -5
- package/typings/char.d.ts +0 -39
- package/typings/component.d.ts +0 -38
- package/typings/context.d.ts +0 -39
- package/typings/converter.d.ts +0 -33
- package/typings/dialog.d.ts +0 -28
- package/typings/domUtils.d.ts +0 -361
- package/typings/editor.d.ts +0 -7
- package/typings/editor.ts +0 -542
- package/typings/env.d.ts +0 -70
- package/typings/eventManager.d.ts +0 -37
- package/typings/events.d.ts +0 -262
- package/typings/fileBrowser.d.ts +0 -42
- package/typings/fileManager.d.ts +0 -67
- package/typings/font.d.ts +0 -5
- package/typings/fontColor.d.ts +0 -5
- package/typings/fontSize.d.ts +0 -5
- package/typings/format.d.ts +0 -191
- package/typings/formatBlock.d.ts +0 -5
- package/typings/history.d.ts +0 -48
- package/typings/horizontalRule.d.ts +0 -5
- package/typings/image.d.ts +0 -5
- package/typings/imageGallery.d.ts +0 -5
- package/typings/index.d.ts +0 -21
- package/typings/index.modules.d.ts +0 -11
- package/typings/index.plugins.d.ts +0 -58
- package/typings/lineHeight.d.ts +0 -5
- package/typings/link.d.ts +0 -5
- package/typings/list.d.ts +0 -5
- package/typings/math.d.ts +0 -5
- package/typings/mediaContainer.d.ts +0 -25
- package/typings/mention.d.ts +0 -5
- package/typings/node.d.ts +0 -57
- package/typings/notice.d.ts +0 -16
- package/typings/numbers.d.ts +0 -29
- package/typings/offset.d.ts +0 -24
- package/typings/options.d.ts +0 -589
- package/typings/paragraphStyle.d.ts +0 -5
- package/typings/resizing.d.ts +0 -141
- package/typings/selection.d.ts +0 -94
- package/typings/shortcuts.d.ts +0 -13
- package/typings/suneditor.d.ts +0 -9
- package/typings/table.d.ts +0 -5
- package/typings/template.d.ts +0 -5
- package/typings/textStyle.d.ts +0 -5
- package/typings/toolbar.d.ts +0 -32
- package/typings/unicode.d.ts +0 -25
- package/typings/video.d.ts +0 -5
|
@@ -3,27 +3,38 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import CoreInjector from '../../editorInjector/_core';
|
|
6
|
-
import {
|
|
6
|
+
import { dom, unicode, numbers } from '../../helper';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Omit<NodeTransform & Partial<__se__EditorInjector>, 'nodeTransform'>} NodeTransformThis
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @constructor
|
|
14
|
+
* @this {NodeTransformThis}
|
|
15
|
+
* @description Node utility class. split, merge, etc.
|
|
16
|
+
* @param {__se__EditorCore} editor - The root editor instance
|
|
17
|
+
*/
|
|
18
|
+
function NodeTransform(editor) {
|
|
9
19
|
CoreInjector.call(this, editor);
|
|
10
|
-
}
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
NodeTransform.prototype = {
|
|
13
23
|
/**
|
|
24
|
+
* @this {NodeTransformThis}
|
|
25
|
+
* @template {HTMLElement} T
|
|
14
26
|
* @description Split all tags based on "baseNode"
|
|
15
|
-
* Returns the last element of the splited tag.
|
|
16
27
|
* @param {Node} baseNode Element or text node on which to base
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {number} depth The nesting depth of the element being split. (default: 0)
|
|
19
|
-
* @returns {
|
|
28
|
+
* @param {?number|Node} offset Text offset of "baseNode" (Only valid when "baseNode" is a text node)
|
|
29
|
+
* @param {number} [depth=0] The nesting depth of the element being split. (default: 0)
|
|
30
|
+
* @returns {T} The last element of the splited tag.
|
|
20
31
|
*/
|
|
21
32
|
split(baseNode, offset, depth) {
|
|
22
|
-
if (
|
|
33
|
+
if (dom.check.isWysiwygFrame(baseNode) || this.component.is(baseNode) || !baseNode) return /** @type {T} */ (baseNode);
|
|
23
34
|
|
|
24
35
|
if (offset && !numbers.is(offset)) {
|
|
25
36
|
const children = baseNode.childNodes;
|
|
26
|
-
let index =
|
|
37
|
+
let index = dom.query.getPositionIndex(/** @type {Node} */ (offset));
|
|
27
38
|
const prev = baseNode.cloneNode(false);
|
|
28
39
|
const next = baseNode.cloneNode(false);
|
|
29
40
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
@@ -36,9 +47,9 @@ NodeTransform.prototype = {
|
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
if (prev.childNodes.length > 0) baseNode.parentNode.insertBefore(prev, baseNode);
|
|
39
|
-
if (next.childNodes.length > 0) baseNode.parentNode.insertBefore(next, baseNode.nextElementSibling);
|
|
50
|
+
if (next.childNodes.length > 0) baseNode.parentNode.insertBefore(next, /** @type {HTMLElement|Text} */ (baseNode).nextElementSibling);
|
|
40
51
|
|
|
41
|
-
return baseNode;
|
|
52
|
+
return /** @type {T} */ (baseNode);
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
const bp = baseNode.parentNode;
|
|
@@ -48,12 +59,13 @@ NodeTransform.prototype = {
|
|
|
48
59
|
let newEl, children, temp;
|
|
49
60
|
if (!depth || depth < 0) depth = 0;
|
|
50
61
|
|
|
51
|
-
if (baseNode
|
|
52
|
-
index =
|
|
62
|
+
if (dom.check.isText(baseNode)) {
|
|
63
|
+
index = dom.query.getPositionIndex(baseNode);
|
|
64
|
+
offset = Number(offset);
|
|
53
65
|
if (offset >= 0 && baseNode.length !== offset) {
|
|
54
66
|
baseNode.splitText(offset);
|
|
55
|
-
const after =
|
|
56
|
-
if (
|
|
67
|
+
const after = /** @type {Text} */ (dom.query.getNodeFromPath([index + 1], bp));
|
|
68
|
+
if (dom.check.isZeroWidth(after)) after.data = unicode.zeroWidthSpace;
|
|
57
69
|
}
|
|
58
70
|
} else if (baseNode.nodeType === 1) {
|
|
59
71
|
if (offset === 0) {
|
|
@@ -61,14 +73,14 @@ NodeTransform.prototype = {
|
|
|
61
73
|
baseNode = baseNode.firstChild;
|
|
62
74
|
}
|
|
63
75
|
if (baseNode.nodeType === 3) {
|
|
64
|
-
const after =
|
|
76
|
+
const after = dom.utils.createTextNode(unicode.zeroWidthSpace);
|
|
65
77
|
baseNode.parentNode.insertBefore(after, baseNode);
|
|
66
78
|
baseNode = after;
|
|
67
79
|
}
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
if (!baseNode.previousSibling) {
|
|
71
|
-
if (
|
|
83
|
+
if (dom.query.getNodeDepth(baseNode) === depth) next = false;
|
|
72
84
|
} else {
|
|
73
85
|
baseNode = baseNode.previousSibling;
|
|
74
86
|
}
|
|
@@ -76,8 +88,8 @@ NodeTransform.prototype = {
|
|
|
76
88
|
|
|
77
89
|
if (baseNode.nodeType === 1) suffixIndex = 0;
|
|
78
90
|
let depthEl = baseNode;
|
|
79
|
-
while (
|
|
80
|
-
index =
|
|
91
|
+
while (dom.query.getNodeDepth(depthEl) > depth) {
|
|
92
|
+
index = dom.query.getPositionIndex(depthEl) + suffixIndex;
|
|
81
93
|
depthEl = depthEl.parentNode;
|
|
82
94
|
|
|
83
95
|
temp = newEl;
|
|
@@ -85,9 +97,9 @@ NodeTransform.prototype = {
|
|
|
85
97
|
children = depthEl.childNodes;
|
|
86
98
|
|
|
87
99
|
if (temp) {
|
|
88
|
-
if (
|
|
100
|
+
if (dom.check.isListCell(newEl) && dom.check.isList(temp) && temp.firstElementChild) {
|
|
89
101
|
newEl.innerHTML = temp.firstElementChild.innerHTML;
|
|
90
|
-
|
|
102
|
+
dom.utils.removeItem(temp.firstElementChild);
|
|
91
103
|
if (temp.children.length > 0) newEl.appendChild(temp);
|
|
92
104
|
} else {
|
|
93
105
|
newEl.appendChild(temp);
|
|
@@ -99,35 +111,36 @@ NodeTransform.prototype = {
|
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
113
|
|
|
102
|
-
if (depthEl.childNodes.length <= 1 && (!depthEl.firstChild || depthEl.firstChild.textContent.length === 0)) depthEl.innerHTML = '<br>';
|
|
114
|
+
if (depthEl.childNodes.length <= 1 && (!depthEl.firstChild || depthEl.firstChild.textContent.length === 0)) /** @type {HTMLElement} */ (depthEl).innerHTML = '<br>';
|
|
103
115
|
|
|
104
116
|
const pElement = depthEl.parentNode;
|
|
105
117
|
if (next) depthEl = depthEl.nextSibling;
|
|
106
|
-
if (!newEl) return depthEl;
|
|
118
|
+
if (!newEl) return /** @type {T} */ (depthEl);
|
|
107
119
|
|
|
108
120
|
this.mergeSameTags(newEl, null, false);
|
|
109
|
-
this.mergeNestedTags(newEl,
|
|
121
|
+
this.mergeNestedTags(newEl, dom.check.isList);
|
|
110
122
|
|
|
111
123
|
if (newEl.childNodes.length > 0) pElement.insertBefore(newEl, depthEl);
|
|
112
124
|
else newEl = depthEl;
|
|
113
125
|
|
|
114
|
-
if (
|
|
115
|
-
newEl.insertBefore(
|
|
126
|
+
if (dom.check.isListCell(newEl) && newEl.children && dom.check.isList(newEl.children[0])) {
|
|
127
|
+
newEl.insertBefore(dom.utils.createElement('BR'), newEl.children[0]);
|
|
116
128
|
}
|
|
117
129
|
|
|
118
|
-
if (bp.childNodes.length === 0)
|
|
130
|
+
if (bp.childNodes.length === 0) dom.utils.removeItem(bp);
|
|
119
131
|
|
|
120
|
-
return newEl;
|
|
132
|
+
return /** @type {T} */ (newEl);
|
|
121
133
|
},
|
|
122
134
|
|
|
123
135
|
/**
|
|
124
|
-
* @
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @param {
|
|
129
|
-
* @param {
|
|
130
|
-
* @
|
|
136
|
+
* @this {NodeTransformThis}
|
|
137
|
+
* @description Use with "npdePath (dom-query-GetNodePath)" to merge the same attributes and tags if they are present and modify the nodepath.
|
|
138
|
+
* - If "offset" has been changed, it will return as much "offset" as it has been modified.
|
|
139
|
+
* - An array containing change offsets is returned in the order of the "nodePathArray" array.
|
|
140
|
+
* @param {Node} element Element
|
|
141
|
+
* @param {?number[][]=} nodePathArray Array of NodePath object ([dom-query-GetNodePath(), ..])
|
|
142
|
+
* @param {?boolean=} onlyText If true, non-text nodes like 'span', 'strong'.. are ignored.
|
|
143
|
+
* @returns {Array<number>} [offset, ..]
|
|
131
144
|
*/
|
|
132
145
|
mergeSameTags(element, nodePathArray, onlyText) {
|
|
133
146
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -143,11 +156,12 @@ NodeTransform.prototype = {
|
|
|
143
156
|
const children = current.childNodes;
|
|
144
157
|
|
|
145
158
|
for (let i = 0, len = children.length, child, next; i < len; i++) {
|
|
146
|
-
child = children[i];
|
|
147
|
-
next = children[i + 1];
|
|
159
|
+
child = /** @type {HTMLElement} */ (children[i]);
|
|
160
|
+
next = /** @type {HTMLElement} */ (children[i + 1]);
|
|
148
161
|
if (!child) break;
|
|
149
|
-
if (
|
|
150
|
-
|
|
162
|
+
if (dom.check.isBreak(child) || dom.check.isMedia(child) || dom.check.isInputElement(child)) continue;
|
|
163
|
+
if ((onlyText && inst.format._isIgnoreNodeChange(child)) || (!onlyText && (dom.check.isTableElements(child) || dom.check.isListCell(child) || (inst.format.isLine(child) && !inst.format.isBrLine(child))))) {
|
|
164
|
+
if (dom.check.isTableElements(child) || dom.check.isListCell(child)) {
|
|
151
165
|
recursionFunc(child, depth + 1, i);
|
|
152
166
|
}
|
|
153
167
|
continue;
|
|
@@ -164,7 +178,7 @@ NodeTransform.prototype = {
|
|
|
164
178
|
cDepth = depth;
|
|
165
179
|
spliceDepth = true;
|
|
166
180
|
while (cDepth >= 0) {
|
|
167
|
-
if (
|
|
181
|
+
if (dom.utils.getArrayIndex(p.childNodes, c) !== path[cDepth]) {
|
|
168
182
|
spliceDepth = false;
|
|
169
183
|
break;
|
|
170
184
|
}
|
|
@@ -181,16 +195,17 @@ NodeTransform.prototype = {
|
|
|
181
195
|
}
|
|
182
196
|
|
|
183
197
|
// merge tag
|
|
184
|
-
|
|
198
|
+
dom.utils.copyTagAttributes(child, current);
|
|
185
199
|
current.parentNode.insertBefore(child, current);
|
|
186
|
-
|
|
200
|
+
dom.utils.removeItem(current);
|
|
187
201
|
}
|
|
202
|
+
|
|
188
203
|
if (!next) {
|
|
189
204
|
if (child.nodeType === 1) recursionFunc(child, depth + 1, i);
|
|
190
205
|
break;
|
|
191
206
|
}
|
|
192
207
|
|
|
193
|
-
if (child.nodeName === next.nodeName &&
|
|
208
|
+
if (child.nodeName === next.nodeName && dom.check.isSameAttributes(child, next) && child.getAttribute?.('href') === next.getAttribute?.('href')) {
|
|
194
209
|
const childs = child.childNodes;
|
|
195
210
|
let childLength = 0;
|
|
196
211
|
for (let n = 0, nLen = childs.length; n < nLen; n++) {
|
|
@@ -254,7 +269,7 @@ NodeTransform.prototype = {
|
|
|
254
269
|
child.innerHTML += next.innerHTML;
|
|
255
270
|
}
|
|
256
271
|
|
|
257
|
-
|
|
272
|
+
dom.utils.removeItem(next);
|
|
258
273
|
i--;
|
|
259
274
|
} else if (child.nodeType === 1) {
|
|
260
275
|
recursionFunc(child, depth + 1, i);
|
|
@@ -266,15 +281,15 @@ NodeTransform.prototype = {
|
|
|
266
281
|
},
|
|
267
282
|
|
|
268
283
|
/**
|
|
284
|
+
* @this {NodeTransformThis}
|
|
269
285
|
* @description Remove nested tags without other child nodes.
|
|
270
|
-
* @param {
|
|
271
|
-
* @param {
|
|
286
|
+
* @param {Node} element Element object
|
|
287
|
+
* @param {?(current: Node) => boolean|string=} validation Validation function / String("tag1|tag2..") / If null, all tags are applicable.
|
|
272
288
|
*/
|
|
273
289
|
mergeNestedTags(element, validation) {
|
|
274
290
|
if (typeof validation === 'string') {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}.bind(new RegExp(`^(${validation ? validation : '.+'})$`, 'i'));
|
|
291
|
+
const tagRegExp = new RegExp(`^(${validation ? validation : '.+'})$`, 'i');
|
|
292
|
+
validation = (current) => tagRegExp.test(current.nodeName);
|
|
278
293
|
} else if (typeof validation !== 'function') {
|
|
279
294
|
validation = () => true;
|
|
280
295
|
}
|
|
@@ -293,16 +308,17 @@ NodeTransform.prototype = {
|
|
|
293
308
|
for (let i = 0, len = current.children.length; i < len; i++) {
|
|
294
309
|
recursionFunc(current.children[i]);
|
|
295
310
|
}
|
|
296
|
-
})(element);
|
|
311
|
+
})(/** @type {Element} */ (element));
|
|
297
312
|
},
|
|
298
313
|
|
|
299
314
|
/**
|
|
315
|
+
* @this {NodeTransformThis}
|
|
300
316
|
* @description Delete itself and all parent nodes that match the condition.
|
|
301
|
-
* Returns an {sc: previousSibling, ec: nextSibling}(the deleted node reference) or null.
|
|
317
|
+
* - Returns an {sc: previousSibling, ec: nextSibling}(the deleted node reference) or null.
|
|
302
318
|
* @param {Node} item Node to be remove
|
|
303
|
-
* @param {
|
|
304
|
-
* @param {
|
|
305
|
-
* @returns {
|
|
319
|
+
* @param {?(current: Node) => boolean=} validation Validation function. default(Deleted if it only have breakLine and blanks)
|
|
320
|
+
* @param {?Node=} stopParent Stop when the parent node reaches stopParent
|
|
321
|
+
* @returns {{sc: Node|null, ec: Node|null}|null} {sc: previousSibling, ec: nextSibling} (the deleted node reference) or null.
|
|
306
322
|
*/
|
|
307
323
|
removeAllParents(item, validation, stopParent) {
|
|
308
324
|
if (!item) return null;
|
|
@@ -316,39 +332,41 @@ NodeTransform.prototype = {
|
|
|
316
332
|
}
|
|
317
333
|
|
|
318
334
|
(function recursionFunc(element) {
|
|
319
|
-
if (!
|
|
335
|
+
if (!dom.check.isWysiwygFrame(element)) {
|
|
320
336
|
const parent = element.parentNode;
|
|
321
337
|
if (parent && validation(element)) {
|
|
322
338
|
cc = {
|
|
323
339
|
sc: element.previousElementSibling,
|
|
324
340
|
ec: element.nextElementSibling
|
|
325
341
|
};
|
|
326
|
-
|
|
327
|
-
recursionFunc(parent);
|
|
342
|
+
dom.utils.removeItem(element);
|
|
343
|
+
recursionFunc(/** @type {Element} */ (parent));
|
|
328
344
|
}
|
|
329
345
|
}
|
|
330
|
-
})(item);
|
|
346
|
+
})(/** @type {Element} */ (item));
|
|
331
347
|
|
|
332
348
|
return cc;
|
|
333
349
|
},
|
|
334
350
|
|
|
335
351
|
/**
|
|
352
|
+
* @this {NodeTransformThis}
|
|
336
353
|
* @description Delete a empty child node of argument element
|
|
337
|
-
* @param {
|
|
338
|
-
* @param {Node
|
|
354
|
+
* @param {Node} element Element node
|
|
355
|
+
* @param {?Node} notRemoveNode Do not remove node
|
|
339
356
|
* @param {boolean} forceDelete When all child nodes are deleted, the parent node is also deleted.
|
|
340
357
|
*/
|
|
341
358
|
removeEmptyNode(element, notRemoveNode, forceDelete) {
|
|
342
359
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
343
360
|
const inst = this;
|
|
361
|
+
const allowedEmptyTags = this.options.get('allowedEmptyTags');
|
|
344
362
|
|
|
345
363
|
if (notRemoveNode) {
|
|
346
|
-
notRemoveNode =
|
|
364
|
+
notRemoveNode = dom.query.getParentElement(notRemoveNode, (current) => element === current.parentElement);
|
|
347
365
|
}
|
|
348
366
|
|
|
349
367
|
(function recursionFunc(current) {
|
|
350
|
-
if (inst.format._notTextNode(current) || current === notRemoveNode ||
|
|
351
|
-
if (current !== element &&
|
|
368
|
+
if (inst.format._notTextNode(current) || current === notRemoveNode || dom.check.isNonEditable(current)) return 0;
|
|
369
|
+
if (current !== element && dom.check.isZeroWidth(current.textContent) && (!current.firstChild || !dom.check.isBreak(current.firstChild)) && !current.querySelector(allowedEmptyTags)) {
|
|
352
370
|
if (current.parentNode) {
|
|
353
371
|
current.parentNode.removeChild(current);
|
|
354
372
|
return -1;
|
|
@@ -362,31 +380,32 @@ NodeTransform.prototype = {
|
|
|
362
380
|
}
|
|
363
381
|
|
|
364
382
|
return 0;
|
|
365
|
-
})(element);
|
|
383
|
+
})(/** @type {Element} */ (element));
|
|
366
384
|
|
|
367
385
|
if (element.childNodes.length === 0) {
|
|
368
386
|
if (forceDelete) {
|
|
369
|
-
|
|
387
|
+
dom.utils.removeItem(element);
|
|
370
388
|
} else {
|
|
371
|
-
element.innerHTML = '<br>';
|
|
389
|
+
/** @type {HTMLElement} */ (element).innerHTML = '<br>';
|
|
372
390
|
}
|
|
373
391
|
}
|
|
374
392
|
},
|
|
375
393
|
|
|
376
394
|
/**
|
|
395
|
+
* @this {NodeTransformThis}
|
|
377
396
|
* @description Creates a nested node structure from the given array of nodes.
|
|
378
|
-
* @param {
|
|
379
|
-
* @param {
|
|
380
|
-
* @returns {{ parent:
|
|
397
|
+
* @param {__se__NodeCollection} nodeArray An array of nodes to clone. The first node in the array will be the top-level parent.
|
|
398
|
+
* @param {?(current: Node) => boolean=} validate A validate function.
|
|
399
|
+
* @returns {{ parent: Node, inner: Node }} An object containing the top-level parent node and the innermost child node.
|
|
381
400
|
*/
|
|
382
401
|
createNestedNode(nodeArray, validate) {
|
|
383
402
|
if (typeof validate !== 'function') validate = () => true;
|
|
384
403
|
|
|
385
|
-
const el = nodeArray[0].cloneNode(false);
|
|
404
|
+
const el = /** @type {HTMLElement} */ (nodeArray[0].cloneNode(false));
|
|
386
405
|
let n = el;
|
|
387
406
|
for (let i = 1, len = nodeArray.length, t; i < len; i++) {
|
|
388
407
|
if (!validate(nodeArray[i])) continue;
|
|
389
|
-
t = nodeArray[i].cloneNode(false);
|
|
408
|
+
t = /** @type {HTMLElement} */ (nodeArray[i].cloneNode(false));
|
|
390
409
|
n.appendChild(t);
|
|
391
410
|
n = t;
|
|
392
411
|
}
|