dragon-editor 3.8.6 → 4.0.0
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 +10 -9
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -7
- package/dist/runtime/components/Block/Code.d.vue.ts +13 -0
- package/dist/runtime/components/Block/Code.vue +193 -0
- package/dist/runtime/components/Block/Code.vue.d.ts +13 -0
- package/dist/runtime/components/Block/Custom.d.vue.ts +9 -0
- package/dist/runtime/components/Block/Custom.vue +28 -0
- package/dist/runtime/components/Block/Custom.vue.d.ts +9 -0
- package/dist/runtime/components/Block/Divider.d.vue.ts +9 -0
- package/dist/runtime/components/Block/Divider.vue +27 -0
- package/dist/runtime/components/Block/Divider.vue.d.ts +9 -0
- package/dist/runtime/components/Block/Heading.d.vue.ts +13 -0
- package/dist/runtime/components/Block/Heading.vue +84 -0
- package/dist/runtime/components/Block/Heading.vue.d.ts +13 -0
- package/dist/runtime/components/Block/Image.d.vue.ts +13 -0
- package/dist/runtime/components/Block/Image.vue +146 -0
- package/dist/runtime/components/Block/Image.vue.d.ts +13 -0
- package/dist/runtime/components/Block/List.d.vue.ts +13 -0
- package/dist/runtime/components/Block/List.vue +170 -0
- package/dist/runtime/components/Block/List.vue.d.ts +13 -0
- package/dist/runtime/components/Block/Text.d.vue.ts +13 -0
- package/dist/runtime/components/Block/Text.vue +84 -0
- package/dist/runtime/components/Block/Text.vue.d.ts +13 -0
- package/dist/runtime/components/DragonEditor.d.vue.ts +28 -22
- package/dist/runtime/components/DragonEditor.vue +75 -1225
- package/dist/runtime/components/DragonEditor.vue.d.ts +28 -22
- package/dist/runtime/components/DragonEditorViewer.d.vue.ts +13 -5
- package/dist/runtime/components/DragonEditorViewer.vue +17 -813
- package/dist/runtime/components/DragonEditorViewer.vue.d.ts +13 -5
- package/dist/runtime/components/MenuBar.d.vue.ts +3 -0
- package/dist/runtime/components/MenuBar.vue +385 -0
- package/dist/runtime/components/MenuBar.vue.d.ts +3 -0
- package/dist/runtime/scss/editor.css +237 -283
- package/dist/runtime/scss/viewer.css +184 -210
- package/dist/runtime/store/editor.d.ts +2 -0
- package/dist/runtime/store/editor.js +59 -0
- package/dist/runtime/type.d.mts +101 -124
- package/dist/runtime/utils/data/block.d.ts +20 -0
- package/dist/runtime/utils/data/block.js +663 -0
- package/dist/runtime/utils/data/cursor.d.ts +9 -0
- package/dist/runtime/utils/data/cursor.js +137 -0
- package/dist/runtime/utils/data/index.d.ts +5 -0
- package/dist/runtime/utils/data/index.js +17 -0
- package/dist/runtime/utils/data/node.d.ts +9 -0
- package/dist/runtime/utils/data/node.js +101 -0
- package/dist/runtime/utils/event/cursor.d.ts +3 -6
- package/dist/runtime/utils/event/cursor.js +52 -105
- package/dist/runtime/utils/event/index.d.ts +2 -6
- package/dist/runtime/utils/event/index.js +48 -6
- package/dist/runtime/utils/event/keyboard.d.ts +22 -7
- package/dist/runtime/utils/event/keyboard.js +910 -1406
- package/dist/runtime/utils/layout/body.d.ts +3 -4
- package/dist/runtime/utils/layout/body.js +83 -51
- package/dist/runtime/utils/layout/icon.d.ts +1 -2
- package/dist/runtime/utils/layout/icon.js +64 -67
- package/dist/runtime/utils/layout/index.d.ts +0 -3
- package/dist/runtime/utils/layout/index.js +0 -3
- package/dist/runtime/utils/node/element.d.ts +4 -6
- package/dist/runtime/utils/node/element.js +58 -71
- package/dist/runtime/utils/node/index.d.ts +1 -1
- package/dist/runtime/utils/node/index.js +1 -1
- package/dist/runtime/utils/node/style.d.ts +5 -0
- package/dist/runtime/utils/node/style.js +702 -0
- package/package.json +31 -17
- package/dist/runtime/utils/event/block.d.ts +0 -7
- package/dist/runtime/utils/event/block.js +0 -110
- package/dist/runtime/utils/event/data.d.ts +0 -8
- package/dist/runtime/utils/event/data.js +0 -379
- package/dist/runtime/utils/event/mouse.d.ts +0 -11
- package/dist/runtime/utils/event/mouse.js +0 -85
- package/dist/runtime/utils/event/scroll.d.ts +0 -3
- package/dist/runtime/utils/event/scroll.js +0 -29
- package/dist/runtime/utils/event/touch.d.ts +0 -5
- package/dist/runtime/utils/event/touch.js +0 -10
- package/dist/runtime/utils/event/window.d.ts +0 -5
- package/dist/runtime/utils/event/window.js +0 -47
- package/dist/runtime/utils/layout/block.d.ts +0 -7
- package/dist/runtime/utils/layout/block.js +0 -123
- package/dist/runtime/utils/layout/controlbar.d.ts +0 -3
- package/dist/runtime/utils/layout/controlbar.js +0 -99
- package/dist/runtime/utils/layout/menuBar.d.ts +0 -3
- package/dist/runtime/utils/layout/menuBar.js +0 -408
- package/dist/runtime/utils/node/block.d.ts +0 -19
- package/dist/runtime/utils/node/block.js +0 -256
- package/dist/runtime/utils/style/anchor.d.ts +0 -5
- package/dist/runtime/utils/style/anchor.js +0 -245
- package/dist/runtime/utils/style/decoration.d.ts +0 -4
- package/dist/runtime/utils/style/decoration.js +0 -378
- package/dist/runtime/utils/style/index.d.ts +0 -2
- package/dist/runtime/utils/style/index.js +0 -2
|
@@ -1,1586 +1,1090 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
switch (event.key) {
|
|
9
|
-
case "Enter":
|
|
10
|
-
if (event.isComposing === false) {
|
|
11
|
-
__enterEvent(event, store);
|
|
12
|
-
} else {
|
|
13
|
-
event.preventDefault();
|
|
14
|
-
}
|
|
15
|
-
break;
|
|
16
|
-
case "Backspace":
|
|
17
|
-
__backspaceEvent(event, store);
|
|
18
|
-
break;
|
|
19
|
-
case "Delete":
|
|
20
|
-
__deleteEvent(event, store);
|
|
21
|
-
break;
|
|
22
|
-
case "Tab":
|
|
23
|
-
__tabEvent(event, store);
|
|
24
|
-
break;
|
|
25
|
-
case " ":
|
|
26
|
-
__spaceEvent(event, store);
|
|
27
|
-
break;
|
|
28
|
-
case "ArrowUp":
|
|
29
|
-
_moveToBlockEvent(event, store, "up");
|
|
30
|
-
break;
|
|
31
|
-
case "ArrowDown":
|
|
32
|
-
_moveToBlockEvent(event, store, "down");
|
|
33
|
-
break;
|
|
34
|
-
case "`":
|
|
35
|
-
__backtickEvent(event, store);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
_hotKeyEvent(event, store);
|
|
39
|
-
}
|
|
40
|
-
export async function _contentPasteEvent(event, store) {
|
|
1
|
+
import { nextTick } from "#imports";
|
|
2
|
+
import { useEditorStore } from "../../store/editor.js";
|
|
3
|
+
import { _updateCursorData, _setCursorPosition } from "./index.js";
|
|
4
|
+
import { _createTextBlockData, _createHeadingBlockData, _getMultilinePosition, _getBlockType, _getBeforeAndAfterHTMLOfCursor, _createListBlockData, _createListBlockChildData, _isCursorAtLineBoundary, _getEditorbleEndPosition, _getEditorbleCursorPosition, _createDividerBlockData, _convertMarkdownToEditor, _generateId, _createCodeBlockData } from "../data/index.js";
|
|
5
|
+
import { _findEditableElement, _findParentBlock, _setDecoration } from "../node/index.js";
|
|
6
|
+
export async function _sliceAndNewTextBlock(event, data, index) {
|
|
7
|
+
const editorStore = useEditorStore();
|
|
41
8
|
event.preventDefault();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
9
|
+
_updateCursorData();
|
|
10
|
+
if (editorStore.cursorSelection !== null && editorStore.fn.updateEditorData !== null) {
|
|
11
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
12
|
+
const $target = event.currentTarget;
|
|
13
|
+
const { beforeHTML, afterHTML } = _getBeforeAndAfterHTMLOfCursor($target);
|
|
14
|
+
if (beforeHTML === "" && afterHTML !== "") {
|
|
15
|
+
newData.splice(index, 0, _createTextBlockData());
|
|
16
|
+
editorStore.fn.updateEditorData(newData);
|
|
17
|
+
} else if (beforeHTML !== "" && afterHTML === "" || beforeHTML === "" && afterHTML === "") {
|
|
18
|
+
data.textContent = beforeHTML;
|
|
19
|
+
newData.splice(index + 1, 0, _createTextBlockData());
|
|
20
|
+
newData[index] = data;
|
|
21
|
+
editorStore.fn.updateEditorData(newData);
|
|
22
|
+
await nextTick();
|
|
23
|
+
$target.dispatchEvent(new Event("input"));
|
|
24
|
+
await nextTick();
|
|
25
|
+
$target.nextElementSibling.focus();
|
|
53
26
|
} else {
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
const textNode = document.createTextNode(text);
|
|
57
|
-
selection.deleteFromDocument();
|
|
58
|
-
selection.getRangeAt(0).insertNode(textNode);
|
|
59
|
-
_setCursor(textNode, textNode.length);
|
|
27
|
+
if (data.type === "text") {
|
|
28
|
+
newData.splice(index + 1, 0, _createTextBlockData(afterHTML));
|
|
60
29
|
} else {
|
|
61
|
-
|
|
30
|
+
newData.splice(index, 0, _createHeadingBlockData(data.level, beforeHTML));
|
|
31
|
+
newData.splice(index + 1, 1, _createTextBlockData(afterHTML));
|
|
62
32
|
}
|
|
33
|
+
data.textContent = beforeHTML;
|
|
34
|
+
newData[index] = data;
|
|
35
|
+
editorStore.fn.updateEditorData(newData);
|
|
36
|
+
await nextTick();
|
|
37
|
+
if (editorStore.element.body !== null) {
|
|
38
|
+
const $block = editorStore.element.body.children[index + 1];
|
|
39
|
+
$block.focus();
|
|
40
|
+
$block.dispatchEvent(new Event("input"));
|
|
41
|
+
}
|
|
42
|
+
editorStore.selectedBlockIndex += 1;
|
|
43
|
+
_updateCursorData();
|
|
63
44
|
}
|
|
64
45
|
}
|
|
65
46
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
tempData = null;
|
|
117
|
-
}
|
|
47
|
+
export async function _imageEnterEvent(event, data, index) {
|
|
48
|
+
const editorStore = useEditorStore();
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
_updateCursorData();
|
|
51
|
+
if (editorStore.element.body !== null && editorStore.cursorSelection !== null && editorStore.fn.updateEditorData !== null) {
|
|
52
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
53
|
+
const $target = event.currentTarget;
|
|
54
|
+
const { beforeHTML, afterHTML } = _getBeforeAndAfterHTMLOfCursor($target);
|
|
55
|
+
data.caption = beforeHTML;
|
|
56
|
+
newData.splice(index + 1, 0, _createTextBlockData(afterHTML));
|
|
57
|
+
newData[index] = data;
|
|
58
|
+
editorStore.selectedBlockIndex += 1;
|
|
59
|
+
editorStore.fn.updateEditorData(newData);
|
|
60
|
+
await nextTick();
|
|
61
|
+
$target.dispatchEvent(new Event("input"));
|
|
62
|
+
editorStore.element.body.children[index + 1].focus();
|
|
63
|
+
_updateCursorData();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function _listBlockEnterEvent(event, data, index, childIndex, setEvent, abortEvent) {
|
|
67
|
+
const editorStore = useEditorStore();
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
_updateCursorData();
|
|
70
|
+
if (editorStore.cursorSelection !== null && editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
|
|
71
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
72
|
+
const targetChildrenCount = data.child.length;
|
|
73
|
+
const targetChild = data.child[childIndex];
|
|
74
|
+
const $target = event.currentTarget;
|
|
75
|
+
if (targetChild !== void 0) {
|
|
76
|
+
const { beforeHTML, afterHTML } = _getBeforeAndAfterHTMLOfCursor($target);
|
|
77
|
+
abortEvent();
|
|
78
|
+
if (targetChildrenCount === 1) {
|
|
79
|
+
if (beforeHTML === "" && afterHTML === "") {
|
|
80
|
+
newData.splice(index, 1, _createTextBlockData());
|
|
81
|
+
editorStore.fn.updateEditorData(newData);
|
|
82
|
+
await nextTick();
|
|
83
|
+
editorStore.element.body.children[index].focus();
|
|
84
|
+
} else {
|
|
85
|
+
data.child[childIndex].textContent = beforeHTML;
|
|
86
|
+
data.child.push(_createListBlockChildData(afterHTML, targetChild.depth));
|
|
87
|
+
newData[index] = data;
|
|
88
|
+
editorStore.fn.updateEditorData(newData);
|
|
89
|
+
await nextTick();
|
|
90
|
+
const $parentBlock = editorStore.element.body.children[index];
|
|
91
|
+
if ($parentBlock !== void 0) {
|
|
92
|
+
const $childElement = $parentBlock.children[childIndex + 1];
|
|
93
|
+
if ($childElement !== void 0) {
|
|
94
|
+
const $textArea = $childElement.querySelector(".de-item-text");
|
|
95
|
+
if ($textArea !== null) {
|
|
96
|
+
$textArea.focus();
|
|
118
97
|
}
|
|
119
98
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
textContent: ___replaceTextData(olSplitText[1].trim())
|
|
135
|
-
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} else if (targetChildrenCount - 1 === childIndex) {
|
|
102
|
+
if (beforeHTML === "" && afterHTML === "") {
|
|
103
|
+
if (targetChild.depth === void 0) {
|
|
104
|
+
data.child.splice(childIndex, 1);
|
|
105
|
+
newData[index] = data;
|
|
106
|
+
newData.splice(index + 1, 0, _createTextBlockData());
|
|
107
|
+
editorStore.fn.updateEditorData(newData);
|
|
108
|
+
await nextTick();
|
|
109
|
+
editorStore.element.body.children[index + 1].focus();
|
|
110
|
+
} else {
|
|
111
|
+
if (targetChild.depth === 1) {
|
|
112
|
+
delete targetChild.depth;
|
|
136
113
|
} else {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (tempData.depth !== nextOlDepth) {
|
|
151
|
-
blockList.push(tempData);
|
|
152
|
-
tempData = null;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
blockList.push(tempData);
|
|
157
|
-
tempData = null;
|
|
114
|
+
targetChild.depth -= 1;
|
|
115
|
+
}
|
|
116
|
+
data.child[childIndex] = targetChild;
|
|
117
|
+
newData[index] = data;
|
|
118
|
+
editorStore.fn.updateEditorData(newData);
|
|
119
|
+
await nextTick();
|
|
120
|
+
const $parentBlock = editorStore.element.body.children[index];
|
|
121
|
+
if ($parentBlock !== void 0) {
|
|
122
|
+
const $childElement = $parentBlock.querySelectorAll("li")[childIndex];
|
|
123
|
+
if ($childElement !== void 0) {
|
|
124
|
+
const $textArea = $childElement.querySelector(".de-item-text");
|
|
125
|
+
if ($textArea !== null) {
|
|
126
|
+
$textArea.focus();
|
|
158
127
|
}
|
|
159
128
|
}
|
|
160
129
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
textContent: ___replaceTextData(ulSplitText[1].trim())
|
|
176
|
-
});
|
|
177
|
-
} else {
|
|
178
|
-
if (tempData.type === "list") {
|
|
179
|
-
const nextLine = lineList[lineIndex + 1];
|
|
180
|
-
tempData.child.push({
|
|
181
|
-
classList: [],
|
|
182
|
-
textContent: ___replaceTextData(ulSplitText[1].trim())
|
|
183
|
-
});
|
|
184
|
-
if (nextLine !== void 0) {
|
|
185
|
-
const nextUlSplitText = nextLine.split(new RegExp("\\+|\\*|-"));
|
|
186
|
-
const nextUlDepth = Math.floor(nextUlSplitText[0].length / 4);
|
|
187
|
-
if (unorderListReg.test(nextLine) === false) {
|
|
188
|
-
blockList.push(tempData);
|
|
189
|
-
tempData = null;
|
|
190
|
-
} else {
|
|
191
|
-
if (tempData.depth !== nextUlDepth) {
|
|
192
|
-
blockList.push(tempData);
|
|
193
|
-
tempData = null;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
} else {
|
|
197
|
-
blockList.push(tempData);
|
|
198
|
-
tempData = null;
|
|
199
|
-
}
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
data.child[childIndex].textContent = beforeHTML;
|
|
133
|
+
data.child.push(_createListBlockChildData(afterHTML, targetChild.depth));
|
|
134
|
+
newData[index] = data;
|
|
135
|
+
editorStore.fn.updateEditorData(newData);
|
|
136
|
+
await nextTick();
|
|
137
|
+
const $parentBlock = editorStore.element.body.children[index];
|
|
138
|
+
if ($parentBlock !== void 0) {
|
|
139
|
+
const $childElement = $parentBlock.querySelectorAll("li")[childIndex + 1];
|
|
140
|
+
if ($childElement !== void 0) {
|
|
141
|
+
const $textArea = $childElement.querySelector(".de-item-text");
|
|
142
|
+
if ($textArea !== null) {
|
|
143
|
+
$textArea.focus();
|
|
200
144
|
}
|
|
201
145
|
}
|
|
202
|
-
break;
|
|
203
|
-
case new RegExp("^###(?= )").test(text):
|
|
204
|
-
blockList.push({
|
|
205
|
-
type: "heading",
|
|
206
|
-
level: 3,
|
|
207
|
-
id: _generateId(),
|
|
208
|
-
classList: [],
|
|
209
|
-
textContent: ___replaceTextData(text.substring(4))
|
|
210
|
-
});
|
|
211
|
-
break;
|
|
212
|
-
case new RegExp("^##(?= )").test(text):
|
|
213
|
-
blockList.push({
|
|
214
|
-
type: "heading",
|
|
215
|
-
level: 2,
|
|
216
|
-
id: _generateId(),
|
|
217
|
-
classList: [],
|
|
218
|
-
textContent: ___replaceTextData(text.substring(3))
|
|
219
|
-
});
|
|
220
|
-
break;
|
|
221
|
-
case new RegExp("^#(?= )").test(text):
|
|
222
|
-
blockList.push({
|
|
223
|
-
type: "heading",
|
|
224
|
-
level: 1,
|
|
225
|
-
id: _generateId(),
|
|
226
|
-
classList: [],
|
|
227
|
-
textContent: ___replaceTextData(text.substring(2))
|
|
228
|
-
});
|
|
229
|
-
break;
|
|
230
|
-
default:
|
|
231
|
-
blockList.push({
|
|
232
|
-
type: "text",
|
|
233
|
-
classList: [],
|
|
234
|
-
textContent: ___replaceTextData(text)
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
if (store.value.controlStatus.currentBlockType === "heading" || store.value.controlStatus.currentBlockType === "text") {
|
|
239
|
-
if (store.value.controlStatus.$currentBlock !== null) {
|
|
240
|
-
if (store.value.controlStatus.$currentBlock.textContent === "") {
|
|
241
|
-
isDelete = true;
|
|
242
|
-
$target = store.value.controlStatus.$currentBlock;
|
|
243
146
|
}
|
|
244
147
|
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
148
|
+
} else {
|
|
149
|
+
if (beforeHTML === "" && afterHTML === "") {
|
|
150
|
+
if (targetChild.depth === void 0) {
|
|
151
|
+
const beforeChildList = data.child.slice(0, childIndex);
|
|
152
|
+
const afterChildList = data.child.slice(childIndex + 1);
|
|
153
|
+
newData.splice(index, 1, _createListBlockData(data.element, beforeChildList));
|
|
154
|
+
newData.splice(index + 1, 0, _createTextBlockData());
|
|
155
|
+
newData.splice(index + 2, 0, _createListBlockData(data.element, afterChildList));
|
|
156
|
+
editorStore.fn.updateEditorData(newData);
|
|
157
|
+
await nextTick();
|
|
158
|
+
const $block = editorStore.element.body.children[index + 1];
|
|
159
|
+
if ($block !== void 0) {
|
|
160
|
+
$block.focus();
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
if (targetChild.depth === 1) {
|
|
164
|
+
delete targetChild.depth;
|
|
165
|
+
} else {
|
|
166
|
+
targetChild.depth -= 1;
|
|
251
167
|
}
|
|
252
|
-
|
|
253
|
-
|
|
168
|
+
data.child[childIndex] = targetChild;
|
|
169
|
+
newData[index] = data;
|
|
170
|
+
editorStore.fn.updateEditorData(newData);
|
|
171
|
+
await nextTick();
|
|
172
|
+
const $parentBlock = editorStore.element.body.children[index];
|
|
173
|
+
if ($parentBlock !== void 0) {
|
|
174
|
+
const $childElement = $parentBlock.querySelectorAll("li")[childIndex];
|
|
175
|
+
if ($childElement !== void 0) {
|
|
176
|
+
const $textArea = $childElement.querySelector(".de-item-text");
|
|
177
|
+
if ($textArea !== null) {
|
|
178
|
+
$textArea.focus();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
254
181
|
}
|
|
255
|
-
|
|
256
|
-
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
targetChild.textContent = beforeHTML;
|
|
185
|
+
data.child[childIndex] = targetChild;
|
|
186
|
+
data.child.splice(childIndex + 1, 0, _createListBlockChildData(afterHTML, targetChild.depth || 0));
|
|
187
|
+
newData[index] = data;
|
|
188
|
+
editorStore.fn.updateEditorData(newData);
|
|
189
|
+
await nextTick();
|
|
190
|
+
const $parentBlock = editorStore.element.body.children[index];
|
|
191
|
+
if ($parentBlock !== void 0) {
|
|
192
|
+
const $targetChildElement = $parentBlock.querySelectorAll(".de-item-text")[childIndex];
|
|
193
|
+
const $childElement = $parentBlock.querySelectorAll(".de-item-text")[childIndex + 1];
|
|
194
|
+
if ($childElement !== void 0) {
|
|
195
|
+
$childElement.focus();
|
|
257
196
|
}
|
|
258
|
-
|
|
259
|
-
case "list":
|
|
260
|
-
_addBlock(data.element, store, data);
|
|
261
|
-
break;
|
|
262
|
-
default:
|
|
263
|
-
_addBlock(data.type, store, data);
|
|
197
|
+
}
|
|
264
198
|
}
|
|
265
|
-
});
|
|
266
|
-
if (isDelete === true) {
|
|
267
|
-
$target?.remove();
|
|
268
199
|
}
|
|
269
200
|
}
|
|
270
201
|
}
|
|
271
202
|
}
|
|
272
|
-
function
|
|
273
|
-
|
|
203
|
+
export async function _codeBlockShiftEnterEvent(event, index) {
|
|
204
|
+
const editorStore = useEditorStore();
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
_updateCursorData();
|
|
207
|
+
if (editorStore.element.body !== null && editorStore.cursorSelection !== null && editorStore.fn.updateEditorData !== null) {
|
|
208
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
209
|
+
const newTextBlockData = _createTextBlockData();
|
|
210
|
+
newData.splice(index + 1, 0, newTextBlockData);
|
|
211
|
+
editorStore.fn.updateEditorData(newData);
|
|
212
|
+
editorStore.selectedBlockIndex += 1;
|
|
213
|
+
editorStore.selectedBlockId = newTextBlockData.id;
|
|
214
|
+
await nextTick();
|
|
215
|
+
editorStore.element.body.children[index + 1].focus();
|
|
216
|
+
_updateCursorData();
|
|
217
|
+
}
|
|
274
218
|
}
|
|
275
|
-
function
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
const $newTextBlock = _createTextBlock(_getDefaultBlockData("text"));
|
|
298
|
-
$block.insertAdjacentElement("afterend", $newTextBlock);
|
|
299
|
-
$newTextBlock.focus();
|
|
219
|
+
export async function _blockTabEvent(event, data, index, setEvent, abortEvent) {
|
|
220
|
+
const editorStore = useEditorStore();
|
|
221
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
222
|
+
const $target = event.currentTarget;
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
_updateCursorData();
|
|
225
|
+
if (editorStore.cursorSelection !== null && editorStore.fn.updateEditorData !== null && $target !== null) {
|
|
226
|
+
const offset = _getEditorbleCursorPosition($target);
|
|
227
|
+
if (event.shiftKey === false) {
|
|
228
|
+
if (data.depth === void 0) {
|
|
229
|
+
data.depth = 1;
|
|
230
|
+
} else {
|
|
231
|
+
data.depth += 1;
|
|
232
|
+
}
|
|
233
|
+
if (data.depth > 5) {
|
|
234
|
+
data.depth = 5;
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
if (data.depth !== void 0) {
|
|
238
|
+
data.depth -= 1;
|
|
239
|
+
if (data.depth <= 0) {
|
|
240
|
+
delete data.depth;
|
|
300
241
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
abortEvent();
|
|
245
|
+
newData.splice(index, 1, data);
|
|
246
|
+
editorStore.fn.updateEditorData(newData);
|
|
247
|
+
await nextTick();
|
|
248
|
+
setEvent();
|
|
249
|
+
const $node = $target.childNodes[offset.nodeIndex];
|
|
250
|
+
if ($node !== void 0) {
|
|
251
|
+
_setCursorPosition($node, offset.offset);
|
|
310
252
|
}
|
|
311
253
|
}
|
|
312
254
|
}
|
|
313
|
-
function
|
|
255
|
+
export async function _listChildTabEvent(event, data, index, childIndex, setEvent, abortEvent) {
|
|
256
|
+
const editorStore = useEditorStore();
|
|
257
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
258
|
+
const targetChild = data.child[childIndex];
|
|
259
|
+
const $target = event.currentTarget;
|
|
260
|
+
let type = "plus";
|
|
314
261
|
event.preventDefault();
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
if (
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
$block.insertAdjacentElement("afterend", $newTextBlock);
|
|
323
|
-
$newTextBlock.focus();
|
|
324
|
-
} else {
|
|
325
|
-
const brList = $block.querySelectorAll("br");
|
|
326
|
-
if (brList.length === 1) {
|
|
327
|
-
const $newTextBlock = _createTextBlock(_getDefaultBlockData("text"));
|
|
328
|
-
$block.insertAdjacentElement("afterend", $newTextBlock);
|
|
329
|
-
$newTextBlock.focus();
|
|
330
|
-
} else {
|
|
331
|
-
const $nextTextBlock = _createTextBlock(_getDefaultBlockData("text"));
|
|
332
|
-
let preStructure = [];
|
|
333
|
-
let nextStructure = [];
|
|
334
|
-
brList.forEach((_, i) => {
|
|
335
|
-
const $br = document.createElement("br");
|
|
336
|
-
if (cursorData.startOffset < i) {
|
|
337
|
-
preStructure.push($br);
|
|
338
|
-
} else {
|
|
339
|
-
nextStructure.push($br);
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
$block.replaceChildren(...preStructure);
|
|
343
|
-
$block.insertAdjacentElement("afterend", $nextTextBlock);
|
|
344
|
-
if (nextStructure.length === 0) {
|
|
345
|
-
$nextTextBlock.focus();
|
|
346
|
-
} else {
|
|
347
|
-
if (nextStructure.length === 1) {
|
|
348
|
-
nextStructure.push(document.createElement("br"));
|
|
349
|
-
}
|
|
350
|
-
$nextTextBlock.replaceChildren(...nextStructure);
|
|
351
|
-
_setCursor(nextStructure[0], 0);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
262
|
+
_updateCursorData();
|
|
263
|
+
if (data.child.length > 1 && editorStore.cursorSelection !== null && editorStore.fn.updateEditorData !== null && editorStore.element.body !== null && targetChild !== void 0) {
|
|
264
|
+
const offset = _getEditorbleCursorPosition($target);
|
|
265
|
+
if (event.shiftKey === false) {
|
|
266
|
+
const preChildData = data.child[childIndex - 1];
|
|
267
|
+
if (targetChild.depth === void 0) {
|
|
268
|
+
targetChild.depth = 1;
|
|
355
269
|
} else {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
nodeIdx = i;
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
childNodeList.forEach((node, i) => {
|
|
368
|
-
if (nodeIdx < i) {
|
|
369
|
-
nextStructure.push(node);
|
|
370
|
-
} else if (nodeIdx > i) {
|
|
371
|
-
preStructure.push(node);
|
|
372
|
-
} else if (nodeIdx === i) {
|
|
373
|
-
if (node.constructor.name === "Text") {
|
|
374
|
-
const text = node.textContent;
|
|
375
|
-
const preText = document.createTextNode(text.slice(0, cursorData.startOffset));
|
|
376
|
-
const nextText = document.createTextNode(text.slice(cursorData.startOffset));
|
|
377
|
-
preStructure.push(preText);
|
|
378
|
-
nextStructure.push(nextText);
|
|
379
|
-
} else {
|
|
380
|
-
const originalClassList = Array.from(node.classList);
|
|
381
|
-
const text = node.textContent;
|
|
382
|
-
const preSpan = document.createElement("span");
|
|
383
|
-
const nextSpan = document.createElement("span");
|
|
384
|
-
const nextText = text.slice(cursorData.startOffset);
|
|
385
|
-
preSpan.classList.add(...originalClassList);
|
|
386
|
-
preSpan.textContent = text.slice(0, cursorData.startOffset);
|
|
387
|
-
preStructure.push(preSpan);
|
|
388
|
-
if (nextText !== "") {
|
|
389
|
-
nextSpan.classList.add(...originalClassList);
|
|
390
|
-
nextSpan.textContent = nextText;
|
|
391
|
-
nextStructure.push(nextSpan);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
const $nextTextBlock = _createTextBlock(_getDefaultBlockData("text"));
|
|
397
|
-
$block.insertAdjacentElement("afterend", $nextTextBlock);
|
|
398
|
-
$block.replaceChildren(...preStructure);
|
|
399
|
-
$nextTextBlock.replaceChildren(...nextStructure);
|
|
400
|
-
if (nextStructure.length === 0) {
|
|
401
|
-
$nextTextBlock.focus();
|
|
402
|
-
} else {
|
|
403
|
-
_setCursor($nextTextBlock.childNodes[0], 0);
|
|
404
|
-
}
|
|
270
|
+
targetChild.depth += 1;
|
|
271
|
+
}
|
|
272
|
+
if (targetChild.depth > 5) {
|
|
273
|
+
targetChild.depth = 5;
|
|
274
|
+
}
|
|
275
|
+
if (preChildData !== void 0 && targetChild.depth > (preChildData.depth || 0)) {
|
|
276
|
+
targetChild.depth = (preChildData.depth || 0) + 1;
|
|
405
277
|
}
|
|
406
278
|
} else {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (nextText !== "") {
|
|
426
|
-
const textNode = document.createTextNode(nextText);
|
|
427
|
-
nextStructure.push(textNode);
|
|
428
|
-
}
|
|
279
|
+
type = "minus";
|
|
280
|
+
if (targetChild.depth !== void 0) {
|
|
281
|
+
targetChild.depth -= 1;
|
|
282
|
+
if (targetChild.depth <= 0) {
|
|
283
|
+
delete targetChild.depth;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
data.child[childIndex] = targetChild;
|
|
288
|
+
for (let i = 0; i < data.child.length; i += 1) {
|
|
289
|
+
const child = data.child[i];
|
|
290
|
+
if (i > childIndex && child !== void 0) {
|
|
291
|
+
if ((child.depth || 0) <= (targetChild.depth || 0) - 1 || (targetChild.depth || 0) === 0) {
|
|
292
|
+
break;
|
|
293
|
+
} else {
|
|
294
|
+
if (type === "plus") {
|
|
295
|
+
if (child.depth === void 0) {
|
|
296
|
+
child.depth = 1;
|
|
429
297
|
} else {
|
|
430
|
-
|
|
431
|
-
const preText = node.textContent.slice(0, srotingCursorData.startOffset);
|
|
432
|
-
const nextText = node.textContent.slice(srotingCursorData.endOffset);
|
|
433
|
-
if (preText !== "") {
|
|
434
|
-
const $span = document.createElement("span");
|
|
435
|
-
$span.classList.add(...originalClassList);
|
|
436
|
-
$span.textContent = preText;
|
|
437
|
-
preStructure.push($span);
|
|
438
|
-
}
|
|
439
|
-
if (nextText !== "") {
|
|
440
|
-
const $span = document.createElement("span");
|
|
441
|
-
$span.classList.add(...originalClassList);
|
|
442
|
-
$span.textContent = nextText;
|
|
443
|
-
nextStructure.push($span);
|
|
444
|
-
}
|
|
298
|
+
child.depth += 1;
|
|
445
299
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
} else {
|
|
449
|
-
childNodeList.forEach((node, i) => {
|
|
450
|
-
if (srotingCursorData.startNodeIdx > i) {
|
|
451
|
-
preStructure.push(node);
|
|
452
|
-
} else if (srotingCursorData.startNodeIdx === i) {
|
|
453
|
-
if (node.constructor.name === "Text") {
|
|
454
|
-
const text = node.textContent.slice(0, srotingCursorData.startOffset);
|
|
455
|
-
if (text !== "") {
|
|
456
|
-
const textNode = document.createTextNode(text);
|
|
457
|
-
preStructure.push(textNode);
|
|
458
|
-
}
|
|
459
|
-
} else {
|
|
460
|
-
const originalClassList = Array.from(node.classList);
|
|
461
|
-
const text = node.textContent.slice(0, srotingCursorData.startOffset);
|
|
462
|
-
if (text !== "") {
|
|
463
|
-
const $span = document.createElement("span");
|
|
464
|
-
$span.classList.add(...originalClassList);
|
|
465
|
-
$span.textContent = text;
|
|
466
|
-
preStructure.push($span);
|
|
467
|
-
}
|
|
300
|
+
if (child.depth > 5) {
|
|
301
|
+
child.depth = 5;
|
|
468
302
|
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const text = node.textContent.slice(srotingCursorData.endOffset);
|
|
475
|
-
if (text !== "") {
|
|
476
|
-
const textNode = document.createTextNode(text);
|
|
477
|
-
nextStructure.push(textNode);
|
|
478
|
-
}
|
|
479
|
-
} else {
|
|
480
|
-
const originalClassList = Array.from(node.classList);
|
|
481
|
-
const text = node.textContent.slice(srotingCursorData.endOffset);
|
|
482
|
-
const $span = document.createElement("span");
|
|
483
|
-
if (text !== "") {
|
|
484
|
-
$span.classList.add(...originalClassList);
|
|
485
|
-
$span.textContent = text;
|
|
486
|
-
nextStructure.push($span);
|
|
303
|
+
} else {
|
|
304
|
+
if (child.depth !== void 0) {
|
|
305
|
+
child.depth -= 1;
|
|
306
|
+
if (child.depth <= 0) {
|
|
307
|
+
delete child.depth;
|
|
487
308
|
}
|
|
488
309
|
}
|
|
489
310
|
}
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
newData[index] = data;
|
|
315
|
+
abortEvent();
|
|
316
|
+
editorStore.fn.updateEditorData(newData);
|
|
317
|
+
await nextTick();
|
|
318
|
+
setEvent(childIndex, targetChild.id);
|
|
319
|
+
const $parentBlock = editorStore.element.body.children[index];
|
|
320
|
+
if ($parentBlock !== void 0) {
|
|
321
|
+
const $textArea = $parentBlock.querySelectorAll(".de-item-text");
|
|
322
|
+
const $targetTextArea = $textArea[childIndex];
|
|
323
|
+
if ($targetTextArea !== void 0) {
|
|
324
|
+
const $node = $targetTextArea.childNodes[offset.nodeIndex];
|
|
325
|
+
if ($node !== void 0) {
|
|
326
|
+
_setCursorPosition($node, offset.offset);
|
|
497
327
|
} else {
|
|
498
|
-
|
|
328
|
+
_setCursorPosition($targetTextArea, 0);
|
|
499
329
|
}
|
|
500
330
|
}
|
|
501
331
|
}
|
|
502
|
-
} else {
|
|
503
|
-
console.error("[Dragon Editor] : Something wrong.");
|
|
504
332
|
}
|
|
505
333
|
}
|
|
506
|
-
function
|
|
334
|
+
export async function _codeBlockTabEvent(event) {
|
|
335
|
+
const editorStore = useEditorStore();
|
|
336
|
+
const $target = event.currentTarget;
|
|
507
337
|
event.preventDefault();
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
} else {
|
|
517
|
-
const $br = document.createElement("br");
|
|
518
|
-
$block.insertAdjacentElement("beforeend", $br);
|
|
519
|
-
_setCursor($br, 0);
|
|
520
|
-
}
|
|
521
|
-
} else {
|
|
522
|
-
const childList = $block.childNodes;
|
|
523
|
-
let targetIdx = -1;
|
|
524
|
-
let structure = "";
|
|
525
|
-
let $target = cursorData.startNode;
|
|
526
|
-
if ($target.constructor.name === "Text") {
|
|
527
|
-
if ($target.parentNode !== $block) {
|
|
528
|
-
$target = $target.parentNode;
|
|
529
|
-
}
|
|
338
|
+
_updateCursorData();
|
|
339
|
+
if (editorStore.cursorSelection !== null && editorStore.cursorSelection.rangeCount > 0 && $target !== null && $target.contains(editorStore.cursorSelection.getRangeAt(0).startContainer)) {
|
|
340
|
+
let traverse = function(node) {
|
|
341
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
342
|
+
const len = node.textContent?.length || 0;
|
|
343
|
+
if (startNode === null && selectionOffset + len >= newStartOffset) {
|
|
344
|
+
startNode = node;
|
|
345
|
+
startNodeOffset = newStartOffset - selectionOffset;
|
|
530
346
|
}
|
|
531
|
-
if (
|
|
532
|
-
|
|
347
|
+
if (endNode === null && selectionOffset + len >= newEndOffset) {
|
|
348
|
+
endNode = node;
|
|
349
|
+
endNodeOffset = newEndOffset - selectionOffset;
|
|
533
350
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
351
|
+
selectionOffset += len;
|
|
352
|
+
} else {
|
|
353
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
354
|
+
traverse(node.childNodes[i]);
|
|
355
|
+
if (startNode !== null && endNode !== null) {
|
|
537
356
|
break;
|
|
538
357
|
}
|
|
539
358
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
$block.innerHTML = structure;
|
|
578
|
-
if ($block.childNodes[currentIdx + 1] === void 0) {
|
|
579
|
-
$block.insertAdjacentHTML("beforeend", "<br>");
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
const range = editorStore.cursorSelection.getRangeAt(0);
|
|
362
|
+
const startRange = range.cloneRange();
|
|
363
|
+
startRange.selectNodeContents($target);
|
|
364
|
+
startRange.setEnd(range.startContainer, range.startOffset);
|
|
365
|
+
const startOffsetChar = startRange.toString().length;
|
|
366
|
+
const endRange = range.cloneRange();
|
|
367
|
+
endRange.selectNodeContents($target);
|
|
368
|
+
endRange.setEnd(range.endContainer, range.endOffset);
|
|
369
|
+
const endOffsetChar = endRange.toString().length;
|
|
370
|
+
const fullText = $target.innerText || $target.textContent || "";
|
|
371
|
+
const lines = fullText.split("\n");
|
|
372
|
+
const linesInfo = [];
|
|
373
|
+
let currentOffset = 0;
|
|
374
|
+
lines.forEach((lineText) => {
|
|
375
|
+
const start = currentOffset;
|
|
376
|
+
const end = currentOffset + lineText.length;
|
|
377
|
+
linesInfo.push({ text: lineText, start, end });
|
|
378
|
+
currentOffset = end + 1;
|
|
379
|
+
});
|
|
380
|
+
const selectedLineIndices = [];
|
|
381
|
+
if (startOffsetChar === endOffsetChar) {
|
|
382
|
+
let targetLineIdx = -1;
|
|
383
|
+
for (let i = 0; i < linesInfo.length; i++) {
|
|
384
|
+
const line = linesInfo[i];
|
|
385
|
+
const isLast = i === linesInfo.length - 1;
|
|
386
|
+
if (startOffsetChar >= line.start && (startOffsetChar <= line.end || isLast && startOffsetChar <= line.end + 1)) {
|
|
387
|
+
targetLineIdx = i;
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
if (i < linesInfo.length - 1 && startOffsetChar === linesInfo[i + 1].start - 1) {
|
|
391
|
+
targetLineIdx = i;
|
|
392
|
+
break;
|
|
580
393
|
}
|
|
581
|
-
|
|
394
|
+
}
|
|
395
|
+
if (targetLineIdx !== -1) {
|
|
396
|
+
selectedLineIndices.push(targetLineIdx);
|
|
582
397
|
}
|
|
583
398
|
} else {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
if (newCursorData.startNodeIdx > i) {
|
|
589
|
-
if (node.constructor.name === "Text") {
|
|
590
|
-
structure += node.textContent;
|
|
591
|
-
} else {
|
|
592
|
-
structure += node.outerHTML;
|
|
593
|
-
}
|
|
594
|
-
} else if (newCursorData.startNodeIdx === i) {
|
|
595
|
-
if (node.constructor.name === "Text") {
|
|
596
|
-
structure += node.textContent.slice(0, newCursorData.startOffset);
|
|
597
|
-
structure += `<br>`;
|
|
598
|
-
} else {
|
|
599
|
-
if (node.tagName === "BR") {
|
|
600
|
-
structure += `<br>`;
|
|
601
|
-
} else {
|
|
602
|
-
const originalClassList = Array.from(node.classList);
|
|
603
|
-
const text = node.textContent;
|
|
604
|
-
structure += `<span class="${originalClassList.join(" ")}">${text.slice(0, newCursorData.startOffset)}</span><br>`;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
if (childNodeList.length === i) {
|
|
608
|
-
structure += `<br>`;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
if (newCursorData.endNodeIdx < i) {
|
|
612
|
-
if (node.constructor.name === "Text") {
|
|
613
|
-
structure += node.textContent;
|
|
614
|
-
} else {
|
|
615
|
-
structure += node.outerHTML;
|
|
616
|
-
}
|
|
617
|
-
} else if (newCursorData.endNodeIdx === i) {
|
|
618
|
-
if (node.constructor.name === "Text") {
|
|
619
|
-
structure += node.textContent.slice(newCursorData.endOffset);
|
|
620
|
-
} else {
|
|
621
|
-
if (node.tagName === "BR") {
|
|
622
|
-
structure += `<br>`;
|
|
623
|
-
} else {
|
|
624
|
-
const originalClassList = Array.from(node.classList);
|
|
625
|
-
const text = node.textContent;
|
|
626
|
-
structure += `<span class="${originalClassList.join(" ")}">${text.slice(newCursorData.endOffset)}</span><br>`;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
399
|
+
linesInfo.forEach((line, idx) => {
|
|
400
|
+
const hasOverlap = Math.max(startOffsetChar, line.start) < Math.min(endOffsetChar, line.end + 1);
|
|
401
|
+
if (hasOverlap) {
|
|
402
|
+
selectedLineIndices.push(idx);
|
|
629
403
|
}
|
|
630
404
|
});
|
|
631
|
-
$block.innerHTML = structure;
|
|
632
|
-
_setCursor($block.childNodes[newCursorData.startNodeIdx + 2], 0);
|
|
633
405
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
const cursorData = store.value.cursorData;
|
|
642
|
-
const $listBlock = store.value.controlStatus.$currentBlock;
|
|
643
|
-
const $editableElement = _findContentEditableElement(event.target);
|
|
644
|
-
const liList = $listBlock.querySelectorAll(".de-item");
|
|
645
|
-
if ($editableElement !== null) {
|
|
646
|
-
let liIdx = -1;
|
|
647
|
-
for (let i = 0; liList.length > i; i += 1) {
|
|
648
|
-
if (liList[i] === $editableElement) {
|
|
649
|
-
liIdx = i;
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
406
|
+
let startLineIdx = 0;
|
|
407
|
+
let endLineIdx = 0;
|
|
408
|
+
for (let i = 0; i < linesInfo.length; i++) {
|
|
409
|
+
const line = linesInfo[i];
|
|
410
|
+
const isLast = i === linesInfo.length - 1;
|
|
411
|
+
if (startOffsetChar >= line.start && (startOffsetChar <= line.end || isLast && startOffsetChar <= line.end + 1)) {
|
|
412
|
+
startLineIdx = i;
|
|
652
413
|
}
|
|
653
|
-
if (
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
414
|
+
if (endOffsetChar >= line.start && (endOffsetChar <= line.end || isLast && endOffsetChar <= line.end + 1)) {
|
|
415
|
+
endLineIdx = i;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const startRelative = startOffsetChar - linesInfo[startLineIdx].start;
|
|
419
|
+
const endRelative = endOffsetChar - linesInfo[endLineIdx].start;
|
|
420
|
+
const updatedLines = [...lines];
|
|
421
|
+
const lineDiffs = Array(lines.length).fill(0);
|
|
422
|
+
const codeBlockSpaces = editorStore.option.codeBlockSpaces;
|
|
423
|
+
const addedSpacesStr = " ".repeat(codeBlockSpaces);
|
|
424
|
+
linesInfo.forEach((line, idx) => {
|
|
425
|
+
const isSelected = selectedLineIndices.includes(idx);
|
|
426
|
+
if (isSelected) {
|
|
427
|
+
let lineText = line.text;
|
|
428
|
+
let diff = 0;
|
|
429
|
+
if (event.shiftKey === false) {
|
|
430
|
+
lineText = addedSpacesStr + lineText;
|
|
431
|
+
diff = codeBlockSpaces;
|
|
669
432
|
} else {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
if (childNodeList[i] === targetNode) {
|
|
677
|
-
nodeIdx = i;
|
|
433
|
+
let spacesToRemove = 0;
|
|
434
|
+
for (let i = 0; i < codeBlockSpaces; i++) {
|
|
435
|
+
if (lineText[i] === " ") {
|
|
436
|
+
spacesToRemove++;
|
|
437
|
+
} else if (lineText[i] === " ") {
|
|
438
|
+
spacesToRemove = 1;
|
|
678
439
|
break;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
childNodeList.forEach((node, i) => {
|
|
682
|
-
if (nodeIdx < i) {
|
|
683
|
-
nextStructure.push(node);
|
|
684
|
-
} else if (nodeIdx > i) {
|
|
685
|
-
preStructure.push(node);
|
|
686
|
-
} else if (nodeIdx === i) {
|
|
687
|
-
if (node.constructor.name === "Text") {
|
|
688
|
-
const preText = node.textContent.slice(0, cursorData.startOffset);
|
|
689
|
-
const nextText = node.textContent.slice(cursorData.endOffset);
|
|
690
|
-
if (preText !== "") {
|
|
691
|
-
preStructure.push(document.createTextNode(preText));
|
|
692
|
-
}
|
|
693
|
-
if (nextText !== "") {
|
|
694
|
-
nextStructure.push(document.createTextNode(nextText));
|
|
695
|
-
}
|
|
696
|
-
} else {
|
|
697
|
-
const originalClassList = Array.from(node.classList);
|
|
698
|
-
const preText = node.textContent.slice(0, cursorData.startOffset);
|
|
699
|
-
const nextText = node.textContent.slice(cursorData.endOffset);
|
|
700
|
-
if (preText !== "") {
|
|
701
|
-
const $span = document.createElement("span");
|
|
702
|
-
$span.textContent = preText;
|
|
703
|
-
$span.classList.add(...originalClassList);
|
|
704
|
-
preStructure.push($span);
|
|
705
|
-
}
|
|
706
|
-
if (nextText !== "") {
|
|
707
|
-
const $span = document.createElement("span");
|
|
708
|
-
$span.textContent = nextText;
|
|
709
|
-
$span.classList.add(...originalClassList);
|
|
710
|
-
nextStructure.push($span);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
});
|
|
715
|
-
const $liBlock = _createListItemBlock();
|
|
716
|
-
$editableElement.insertAdjacentElement("afterend", $liBlock);
|
|
717
|
-
$editableElement.replaceChildren(...preStructure);
|
|
718
|
-
$liBlock.replaceChildren(...nextStructure);
|
|
719
|
-
if (nextStructure.length === 0) {
|
|
720
|
-
$liBlock.focus();
|
|
721
|
-
} else {
|
|
722
|
-
_setCursor($liBlock.childNodes[0], 0);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
} else {
|
|
726
|
-
const childNodeList = $editableElement.childNodes;
|
|
727
|
-
const newCursorData = _sortingCursorDataOnElement(cursorData, $editableElement);
|
|
728
|
-
const preStructure = [];
|
|
729
|
-
const nextStructure = [];
|
|
730
|
-
childNodeList.forEach((node, i) => {
|
|
731
|
-
if (newCursorData.startNodeIdx > i) {
|
|
732
|
-
preStructure.push(node);
|
|
733
|
-
} else if (newCursorData.startNodeIdx === i) {
|
|
734
|
-
if (node.constructor.name === "Text") {
|
|
735
|
-
const text = node.textContent.slice(0, newCursorData.startOffset);
|
|
736
|
-
if (text !== "") {
|
|
737
|
-
const $textNode = document.createTextNode(text);
|
|
738
|
-
preStructure.push($textNode);
|
|
739
|
-
}
|
|
740
440
|
} else {
|
|
741
|
-
|
|
742
|
-
const text = node.textContent.slice(0, newCursorData.startOffset);
|
|
743
|
-
if (text !== "") {
|
|
744
|
-
const $span = document.createElement("span");
|
|
745
|
-
$span.classList.add(...originalClassList);
|
|
746
|
-
$span.textContent = text;
|
|
747
|
-
preStructure.push($span);
|
|
748
|
-
}
|
|
441
|
+
break;
|
|
749
442
|
}
|
|
750
443
|
}
|
|
751
|
-
if (
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
if (node.constructor.name === "Text") {
|
|
755
|
-
const text = node.textContent.slice(newCursorData.endOffset);
|
|
756
|
-
if (text !== "") {
|
|
757
|
-
const $textNode = document.createTextNode(text);
|
|
758
|
-
nextStructure.push($textNode);
|
|
759
|
-
}
|
|
760
|
-
} else {
|
|
761
|
-
const originalClassList = Array.from(node.classList);
|
|
762
|
-
const text = node.textContent.slice(newCursorData.endOffset);
|
|
763
|
-
if (text !== "") {
|
|
764
|
-
const $span = document.createElement("span");
|
|
765
|
-
$span.classList.add(...originalClassList);
|
|
766
|
-
$span.textContent = text;
|
|
767
|
-
nextStructure.push($span);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
444
|
+
if (spacesToRemove > 0) {
|
|
445
|
+
lineText = lineText.slice(spacesToRemove);
|
|
446
|
+
diff = -spacesToRemove;
|
|
770
447
|
}
|
|
771
|
-
});
|
|
772
|
-
const $liBlock = _createListItemBlock();
|
|
773
|
-
$editableElement.insertAdjacentElement("afterend", $liBlock);
|
|
774
|
-
$editableElement.replaceChildren(...preStructure);
|
|
775
|
-
if (nextStructure.length === 0) {
|
|
776
|
-
$liBlock.focus();
|
|
777
|
-
} else {
|
|
778
|
-
$liBlock.replaceChildren(...nextStructure);
|
|
779
|
-
_setCursor(nextStructure[0], 0);
|
|
780
448
|
}
|
|
449
|
+
updatedLines[idx] = lineText;
|
|
450
|
+
lineDiffs[idx] = diff;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
const updatedText = updatedLines.join("\n");
|
|
454
|
+
const newLinesStart = [];
|
|
455
|
+
let curOffset = 0;
|
|
456
|
+
updatedLines.forEach((lineText) => {
|
|
457
|
+
newLinesStart.push(curOffset);
|
|
458
|
+
curOffset += lineText.length + 1;
|
|
459
|
+
});
|
|
460
|
+
let finalStartRelative = startRelative;
|
|
461
|
+
if (selectedLineIndices.includes(startLineIdx)) {
|
|
462
|
+
const diff = lineDiffs[startLineIdx];
|
|
463
|
+
if (diff > 0) {
|
|
464
|
+
finalStartRelative += diff;
|
|
465
|
+
} else {
|
|
466
|
+
finalStartRelative = Math.max(0, finalStartRelative + diff);
|
|
781
467
|
}
|
|
782
468
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
469
|
+
const newStartOffset = newLinesStart[startLineIdx] + finalStartRelative;
|
|
470
|
+
let finalEndRelative = endRelative;
|
|
471
|
+
if (selectedLineIndices.includes(endLineIdx)) {
|
|
472
|
+
const diff = lineDiffs[endLineIdx];
|
|
473
|
+
if (diff > 0) {
|
|
474
|
+
finalEndRelative += diff;
|
|
475
|
+
} else {
|
|
476
|
+
finalEndRelative = Math.max(0, finalEndRelative + diff);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const newEndOffset = newLinesStart[endLineIdx] + finalEndRelative;
|
|
480
|
+
$target.textContent = updatedText;
|
|
481
|
+
$target.dispatchEvent(new Event("input"));
|
|
482
|
+
await nextTick();
|
|
483
|
+
let selectionOffset = 0;
|
|
484
|
+
let startNode = null;
|
|
485
|
+
let startNodeOffset = 0;
|
|
486
|
+
let endNode = null;
|
|
487
|
+
let endNodeOffset = 0;
|
|
488
|
+
traverse($target);
|
|
489
|
+
if (startNode === null) {
|
|
490
|
+
startNode = $target;
|
|
491
|
+
startNodeOffset = 0;
|
|
791
492
|
}
|
|
792
|
-
|
|
493
|
+
if (endNode === null) {
|
|
494
|
+
endNode = $target;
|
|
495
|
+
endNodeOffset = 0;
|
|
496
|
+
}
|
|
497
|
+
editorStore.cursorSelection.removeAllRanges();
|
|
498
|
+
const newRange = document.createRange();
|
|
499
|
+
newRange.setStart(startNode, startNodeOffset);
|
|
500
|
+
newRange.setEnd(endNode, endNodeOffset);
|
|
501
|
+
editorStore.cursorSelection.addRange(newRange);
|
|
793
502
|
}
|
|
794
503
|
}
|
|
795
|
-
function
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
const $
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
504
|
+
export function _moveBlockDefaultEvent(event, type) {
|
|
505
|
+
const editorStore = useEditorStore();
|
|
506
|
+
_updateCursorData();
|
|
507
|
+
if (editorStore.element.body !== null && editorStore.selectedBlockIndex !== -1) {
|
|
508
|
+
const $block = editorStore.element.body.children[editorStore.selectedBlockIndex];
|
|
509
|
+
const $targetBlock = type === "up" ? $block.previousElementSibling : $block.nextElementSibling;
|
|
510
|
+
const blockType = _getBlockType($block);
|
|
511
|
+
let positionData = _getMultilinePosition($block);
|
|
512
|
+
if (blockType === "image") {
|
|
513
|
+
positionData = _getMultilinePosition($block.querySelector(".de-caption"));
|
|
514
|
+
}
|
|
515
|
+
if ($targetBlock !== null) {
|
|
516
|
+
let logicWork = false;
|
|
517
|
+
if (positionData.lineCount === 1) {
|
|
518
|
+
logicWork = true;
|
|
519
|
+
} else {
|
|
520
|
+
if (type === "up") {
|
|
521
|
+
if (positionData.curruntLine === 1) {
|
|
522
|
+
logicWork = true;
|
|
810
523
|
}
|
|
811
524
|
} else {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
let structure = "";
|
|
815
|
-
let $target = cursorData.startNode;
|
|
816
|
-
if ($target.constructor.name === "Text") {
|
|
817
|
-
if ($target.parentNode !== $editableElement) {
|
|
818
|
-
$target = $target.parentNode;
|
|
819
|
-
}
|
|
525
|
+
if (positionData.curruntLine === positionData.lineCount) {
|
|
526
|
+
logicWork = true;
|
|
820
527
|
}
|
|
821
|
-
if ($editableElement === $target) {
|
|
822
|
-
$target = $editableElement.childNodes[cursorData.startOffset];
|
|
823
|
-
}
|
|
824
|
-
for (let i = 0; childList.length > i; i += 1) {
|
|
825
|
-
if (childList[i] === $target) {
|
|
826
|
-
targetIdx = i;
|
|
827
|
-
break;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
let currentIdx = targetIdx;
|
|
831
|
-
childList.forEach((child, i) => {
|
|
832
|
-
if (i === targetIdx) {
|
|
833
|
-
const constructorName = child.constructor.name;
|
|
834
|
-
if (constructorName === "Text") {
|
|
835
|
-
structure += child.textContent.slice(0, cursorData.startOffset) + "<br>" + child.textContent.slice(cursorData.endOffset);
|
|
836
|
-
if (child.nextSibling === null) {
|
|
837
|
-
if (child.textContent.slice(cursorData.endOffset) === "") {
|
|
838
|
-
structure += `<br>`;
|
|
839
|
-
}
|
|
840
|
-
if (child.textContent.slice(0, cursorData.startOffset) === "") {
|
|
841
|
-
currentIdx -= 1;
|
|
842
|
-
}
|
|
843
|
-
} else {
|
|
844
|
-
if (child.textContent.slice(cursorData.endOffset) !== "" && child.textContent.slice(0, cursorData.startOffset) === "") {
|
|
845
|
-
currentIdx -= 1;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
currentIdx += 1;
|
|
849
|
-
} else {
|
|
850
|
-
if (constructorName === "HTMLBRElement") {
|
|
851
|
-
structure += `<br><br>`;
|
|
852
|
-
} else {
|
|
853
|
-
structure += `<span class="${Array.from(child.classList).join(" ")}">${child.textContent.slice(0, cursorData.startOffset)}</span>`;
|
|
854
|
-
structure += `<br>`;
|
|
855
|
-
structure += `<span class="${Array.from(child.classList).join(" ")}">${child.textContent.slice(cursorData.startOffset)}</span>`;
|
|
856
|
-
currentIdx += 1;
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
} else {
|
|
860
|
-
if (child.constructor.name === "Text") {
|
|
861
|
-
structure += child.textContent;
|
|
862
|
-
} else {
|
|
863
|
-
structure += child.outerHTML;
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
$editableElement.innerHTML = structure;
|
|
868
|
-
_setCursor($editableElement.childNodes[currentIdx + 1], 0);
|
|
869
528
|
}
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
if (node.constructor.name === "Text") {
|
|
883
|
-
structure += node.textContent.slice(0, newCursorData.startOffset);
|
|
884
|
-
structure += `<br>`;
|
|
885
|
-
} else {
|
|
886
|
-
if (node.tagName === "BR") {
|
|
887
|
-
structure += `<br>`;
|
|
888
|
-
} else {
|
|
889
|
-
const originalClassList = Array.from(node.classList);
|
|
890
|
-
const text = node.textContent;
|
|
891
|
-
structure += `<span class="${originalClassList.join(" ")}">${text.slice(0, newCursorData.startOffset)}</span><br>`;
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
if (childNodeList.length === i) {
|
|
895
|
-
structure += `<br>`;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
if (newCursorData.endNodeIdx < i) {
|
|
899
|
-
if (node.constructor.name === "Text") {
|
|
900
|
-
structure += node.textContent;
|
|
901
|
-
} else {
|
|
902
|
-
structure += node.outerHTML;
|
|
903
|
-
}
|
|
904
|
-
} else if (newCursorData.endNodeIdx === i) {
|
|
905
|
-
if (node.constructor.name === "Text") {
|
|
906
|
-
structure += node.textContent.slice(newCursorData.endOffset);
|
|
907
|
-
} else {
|
|
908
|
-
if (node.tagName === "BR") {
|
|
909
|
-
structure += `<br>`;
|
|
910
|
-
} else {
|
|
911
|
-
const originalClassList = Array.from(node.classList);
|
|
912
|
-
const text = node.textContent;
|
|
913
|
-
structure += `<span class="${originalClassList.join(" ")}">${text.slice(newCursorData.endOffset)}</span><br>`;
|
|
914
|
-
}
|
|
915
|
-
}
|
|
529
|
+
}
|
|
530
|
+
if (logicWork === true) {
|
|
531
|
+
event.preventDefault();
|
|
532
|
+
const $editableTarget = _findEditableElement($targetBlock, type);
|
|
533
|
+
if (editorStore.cursorSelection !== null && $editableTarget !== null) {
|
|
534
|
+
const range = document.createRange();
|
|
535
|
+
$editableTarget.focus();
|
|
536
|
+
range.selectNodeContents($editableTarget);
|
|
537
|
+
if (type === "up") {
|
|
538
|
+
range.collapse(false);
|
|
539
|
+
} else {
|
|
540
|
+
range.collapse(true);
|
|
916
541
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
542
|
+
editorStore.cursorSelection.removeAllRanges();
|
|
543
|
+
editorStore.cursorSelection.addRange(range);
|
|
544
|
+
_updateCursorData();
|
|
545
|
+
}
|
|
920
546
|
}
|
|
921
547
|
}
|
|
922
|
-
} else {
|
|
923
|
-
console.error("[Dragon Editor] : Something wrong.");
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
function __codeBlockShiftEnterEvent(event, store) {
|
|
927
|
-
event.preventDefault();
|
|
928
|
-
if (store.value.controlStatus.$currentBlock !== null) {
|
|
929
|
-
const $block = store.value.controlStatus.$currentBlock;
|
|
930
|
-
const $newTextBlock = _createTextBlock(_getDefaultBlockData("text"));
|
|
931
|
-
$block.insertAdjacentElement("afterend", $newTextBlock);
|
|
932
|
-
$newTextBlock.focus();
|
|
933
548
|
}
|
|
934
549
|
}
|
|
935
|
-
function
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
const childList = store.value.$body.querySelectorAll(".de-block");
|
|
952
|
-
const $block = store.value.controlStatus.$currentBlock;
|
|
953
|
-
let $target = cursorData.startNode;
|
|
954
|
-
let elementIdx = -1;
|
|
955
|
-
for (let i = 0; childList.length > i; i += 1) {
|
|
956
|
-
if (childList[i] === $block) {
|
|
957
|
-
elementIdx = i;
|
|
958
|
-
break;
|
|
550
|
+
export function _moveListChildEvent(event, data, index, childIndex, type) {
|
|
551
|
+
const editorStore = useEditorStore();
|
|
552
|
+
_updateCursorData();
|
|
553
|
+
if (editorStore.element.body !== null) {
|
|
554
|
+
const $target = event.currentTarget;
|
|
555
|
+
let positionData = _getMultilinePosition($target);
|
|
556
|
+
let targetType = "child";
|
|
557
|
+
let logicWork = false;
|
|
558
|
+
if (data.child.length === 1) {
|
|
559
|
+
targetType = "block";
|
|
560
|
+
} else {
|
|
561
|
+
if (childIndex === 0 && type === "up") {
|
|
562
|
+
targetType = "block";
|
|
563
|
+
}
|
|
564
|
+
if (childIndex === data.child.length - 1 && type === "down") {
|
|
565
|
+
targetType = "block";
|
|
959
566
|
}
|
|
960
567
|
}
|
|
961
|
-
if (
|
|
962
|
-
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
if ($target.textContent === "") {
|
|
968
|
-
$block.insertAdjacentElement("afterend", _createTextBlock(_getDefaultBlockData("text")));
|
|
969
|
-
_setCursor($block.nextElementSibling, 0);
|
|
970
|
-
$block.remove();
|
|
971
|
-
} else {
|
|
972
|
-
event.preventDefault();
|
|
973
|
-
if (store.value.controlStatus.currentBlockType !== "text") {
|
|
974
|
-
const $newBlock = _createTextBlock({ type: "text", classList: [], textContent: $block.textContent ?? "" });
|
|
975
|
-
$block.insertAdjacentElement("afterend", $newBlock);
|
|
976
|
-
_setCursor($newBlock, 0);
|
|
977
|
-
$block.remove();
|
|
978
|
-
}
|
|
979
|
-
}
|
|
568
|
+
if (positionData.lineCount === 1) {
|
|
569
|
+
logicWork = true;
|
|
570
|
+
} else {
|
|
571
|
+
if (type === "up") {
|
|
572
|
+
if (positionData.curruntLine === 1) {
|
|
573
|
+
logicWork = true;
|
|
980
574
|
}
|
|
981
575
|
} else {
|
|
982
|
-
if (
|
|
983
|
-
|
|
984
|
-
event.preventDefault();
|
|
985
|
-
const $newBlock = _createTextBlock({ type: "text", classList: [], textContent: "" });
|
|
986
|
-
$block.insertAdjacentElement("afterend", $newBlock);
|
|
987
|
-
_setCursor($newBlock, 0);
|
|
988
|
-
$block.remove();
|
|
989
|
-
}
|
|
576
|
+
if (positionData.curruntLine === positionData.lineCount) {
|
|
577
|
+
logicWork = true;
|
|
990
578
|
}
|
|
991
579
|
}
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
childHTML = $block.innerHTML;
|
|
1002
|
-
}
|
|
580
|
+
}
|
|
581
|
+
if (logicWork === true) {
|
|
582
|
+
const $block = editorStore.element.body.children[index];
|
|
583
|
+
let $editableTarget = null;
|
|
584
|
+
event.preventDefault();
|
|
585
|
+
if (targetType === "block") {
|
|
586
|
+
const $targetBlock = type === "up" ? $block.previousElementSibling : $block.nextElementSibling;
|
|
587
|
+
if ($targetBlock !== null) {
|
|
588
|
+
$editableTarget = _findEditableElement($targetBlock, type);
|
|
1003
589
|
}
|
|
1004
|
-
____backspackeLogic(hasChild, childHTML, $block, $block);
|
|
1005
590
|
} else {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
591
|
+
const $targetChildElement = $block.querySelectorAll(".de-item-text");
|
|
592
|
+
$editableTarget = type === "up" ? $targetChildElement[childIndex - 1] : $targetChildElement[childIndex + 1];
|
|
593
|
+
}
|
|
594
|
+
if (editorStore.cursorSelection !== null && $editableTarget !== null) {
|
|
595
|
+
const range = document.createRange();
|
|
596
|
+
$editableTarget.focus();
|
|
597
|
+
range.selectNodeContents($editableTarget);
|
|
598
|
+
if (type === "up") {
|
|
599
|
+
range.collapse(false);
|
|
600
|
+
} else {
|
|
601
|
+
range.collapse(true);
|
|
1010
602
|
}
|
|
603
|
+
editorStore.cursorSelection.removeAllRanges();
|
|
604
|
+
editorStore.cursorSelection.addRange(range);
|
|
605
|
+
_updateCursorData();
|
|
1011
606
|
}
|
|
1012
607
|
}
|
|
1013
|
-
____nodeBackspaceEvent(event, cursorData, $block, $target);
|
|
1014
|
-
_updateCursorData(store);
|
|
1015
608
|
}
|
|
1016
609
|
}
|
|
1017
|
-
function
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
if ($target.constructor.name === "Text") {
|
|
1026
|
-
$target = $target.parentNode;
|
|
1027
|
-
}
|
|
1028
|
-
for (let i = 0; $liList.length > i; i += 1) {
|
|
1029
|
-
if ($liList[i] === $targetItem) {
|
|
1030
|
-
liIdx = i;
|
|
1031
|
-
break;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
if ($liList.length === 1) {
|
|
1035
|
-
if ($targetItem.textContent === "") {
|
|
1036
|
-
event.preventDefault();
|
|
1037
|
-
let hasChild = false;
|
|
1038
|
-
let childHTML = "";
|
|
1039
|
-
if ($targetItem.hasChildNodes() === true) {
|
|
1040
|
-
const $brList = $targetItem.querySelectorAll("br");
|
|
1041
|
-
if ($brList.length > 1) {
|
|
1042
|
-
hasChild = true;
|
|
1043
|
-
childHTML = $targetItem.innerHTML;
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
____backspackeLogic(hasChild, childHTML, $listBlock, $targetItem);
|
|
1047
|
-
$listBlock.remove();
|
|
610
|
+
export function _moveCodeBlockEvent(event, direction, type, $targetElement) {
|
|
611
|
+
const editorStore = useEditorStore();
|
|
612
|
+
_updateCursorData();
|
|
613
|
+
if (editorStore.cursorSelection !== null) {
|
|
614
|
+
if (type === "filename") {
|
|
615
|
+
event.preventDefault();
|
|
616
|
+
if (direction === "up") {
|
|
617
|
+
_moveBlockDefaultEvent(event, direction);
|
|
1048
618
|
} else {
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
619
|
+
const range = document.createRange();
|
|
620
|
+
$targetElement.focus();
|
|
621
|
+
range.selectNodeContents($targetElement);
|
|
622
|
+
range.collapse(true);
|
|
623
|
+
editorStore.cursorSelection.removeAllRanges();
|
|
624
|
+
editorStore.cursorSelection.addRange(range);
|
|
625
|
+
_updateCursorData();
|
|
1055
626
|
}
|
|
1056
627
|
} else {
|
|
1057
|
-
|
|
1058
|
-
|
|
628
|
+
const $content = event.currentTarget;
|
|
629
|
+
const positionData = _getMultilinePosition($content);
|
|
630
|
+
if (direction === "up") {
|
|
631
|
+
if (positionData.curruntLine === 1) {
|
|
1059
632
|
event.preventDefault();
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
____backspackeLogic(hasChild, childHTML, $listBlock, $targetItem);
|
|
1070
|
-
} else {
|
|
1071
|
-
if (cursorData.type === "Caret" && cursorData.startOffset === 0 && ($targetItem.childNodes[0] === cursorData.startNode || $targetItem.childNodes[0] === $target)) {
|
|
1072
|
-
event.preventDefault();
|
|
1073
|
-
let childHTML = $targetItem.innerHTML;
|
|
1074
|
-
____backspackeLogic(true, childHTML, $listBlock, $targetItem);
|
|
1075
|
-
}
|
|
633
|
+
const range = document.createRange();
|
|
634
|
+
$targetElement.focus();
|
|
635
|
+
range.selectNodeContents($targetElement);
|
|
636
|
+
range.collapse(false);
|
|
637
|
+
editorStore.cursorSelection.removeAllRanges();
|
|
638
|
+
editorStore.cursorSelection.addRange(range);
|
|
639
|
+
_updateCursorData();
|
|
1076
640
|
}
|
|
1077
641
|
} else {
|
|
1078
|
-
if (
|
|
1079
|
-
event
|
|
1080
|
-
const $preLi = $targetItem.previousElementSibling;
|
|
1081
|
-
const hasChild = $preLi.hasChildNodes();
|
|
1082
|
-
let childHTML = "";
|
|
1083
|
-
if ($targetItem.hasChildNodes() === true) {
|
|
1084
|
-
const $brList = $targetItem.querySelectorAll("br");
|
|
1085
|
-
if ($brList.length > 1) {
|
|
1086
|
-
childHTML = $targetItem.innerHTML;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
if ($preLi.hasChildNodes() === true) {
|
|
1090
|
-
const textBlockChildList = $preLi.childNodes;
|
|
1091
|
-
const textBlockTargetChild = textBlockChildList[textBlockChildList.length - 1];
|
|
1092
|
-
if (hasChild === true) {
|
|
1093
|
-
$preLi.insertAdjacentHTML("beforeend", childHTML);
|
|
1094
|
-
}
|
|
1095
|
-
_setCursor(textBlockTargetChild, textBlockTargetChild.textContent.length);
|
|
1096
|
-
} else {
|
|
1097
|
-
if (hasChild === true) {
|
|
1098
|
-
$preLi.insertAdjacentHTML("beforeend", childHTML);
|
|
1099
|
-
}
|
|
1100
|
-
_setCursor($preLi, 0);
|
|
1101
|
-
}
|
|
1102
|
-
$targetItem.remove();
|
|
1103
|
-
} else {
|
|
1104
|
-
if (cursorData.type === "Caret" && cursorData.startOffset === 0 && ($targetItem.childNodes[0] === cursorData.startNode || $targetItem.childNodes[0] === $target)) {
|
|
1105
|
-
event.preventDefault();
|
|
1106
|
-
const $preLi = $targetItem.previousElementSibling;
|
|
1107
|
-
const hasChild = $preLi.hasChildNodes();
|
|
1108
|
-
let childHTML = $targetItem.innerHTML;
|
|
1109
|
-
if ($preLi.hasChildNodes() === true) {
|
|
1110
|
-
const textBlockChildList = $preLi.childNodes;
|
|
1111
|
-
const textBlockTargetChild = textBlockChildList[textBlockChildList.length - 1];
|
|
1112
|
-
if (hasChild === true) {
|
|
1113
|
-
$preLi.insertAdjacentHTML("beforeend", childHTML);
|
|
1114
|
-
}
|
|
1115
|
-
_setCursor(textBlockTargetChild, textBlockTargetChild.textContent.length);
|
|
1116
|
-
} else {
|
|
1117
|
-
if (hasChild === true) {
|
|
1118
|
-
$preLi.insertAdjacentHTML("beforeend", childHTML);
|
|
1119
|
-
}
|
|
1120
|
-
_setCursor($preLi, 0);
|
|
1121
|
-
}
|
|
1122
|
-
$targetItem.remove();
|
|
1123
|
-
}
|
|
642
|
+
if (positionData.curruntLine === positionData.lineCount) {
|
|
643
|
+
_moveBlockDefaultEvent(event, direction);
|
|
1124
644
|
}
|
|
1125
645
|
}
|
|
1126
646
|
}
|
|
1127
647
|
}
|
|
1128
648
|
}
|
|
1129
|
-
function
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
$targetBlock = $preBlock;
|
|
1148
|
-
}
|
|
1149
|
-
if (preDelete === false) {
|
|
1150
|
-
if ($targetBlock.hasChildNodes() === true) {
|
|
1151
|
-
const textBlockChildList = $targetBlock.childNodes;
|
|
1152
|
-
const textBlockTargetChild = textBlockChildList[textBlockChildList.length - 1];
|
|
1153
|
-
if (hasChild === true) {
|
|
1154
|
-
$targetBlock.insertAdjacentHTML("beforeend", childHTML);
|
|
649
|
+
export async function _defaultBackspaceEvent(event) {
|
|
650
|
+
const editorStore = useEditorStore();
|
|
651
|
+
const $target = event.currentTarget;
|
|
652
|
+
_updateCursorData();
|
|
653
|
+
if ($target !== null && editorStore.element.body !== null && editorStore.fn.updateEditorData !== null) {
|
|
654
|
+
const multilinePosition = _getMultilinePosition($target);
|
|
655
|
+
const cursorPosition = _isCursorAtLineBoundary();
|
|
656
|
+
if (multilinePosition.curruntLine === 1 && cursorPosition.isStart === true) {
|
|
657
|
+
event.preventDefault();
|
|
658
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
659
|
+
const curruntData = newData[editorStore.selectedBlockIndex];
|
|
660
|
+
if (editorStore.selectedBlockIndex === 0) {
|
|
661
|
+
if (curruntData.type === "heading") {
|
|
662
|
+
newData.splice(editorStore.selectedBlockIndex, 1, _createTextBlockData(curruntData.textContent));
|
|
663
|
+
editorStore.fn.updateEditorData(newData);
|
|
664
|
+
await nextTick();
|
|
665
|
+
const $block = editorStore.element.body.children[0];
|
|
666
|
+
$block.focus();
|
|
1155
667
|
}
|
|
1156
|
-
_setCursor(textBlockTargetChild, textBlockTargetChild.textContent.length);
|
|
1157
668
|
} else {
|
|
1158
|
-
|
|
1159
|
-
|
|
669
|
+
const preveiousData = newData[editorStore.selectedBlockIndex - 1];
|
|
670
|
+
const $preveiousBlock = editorStore.element.body.children[editorStore.selectedBlockIndex - 1];
|
|
671
|
+
if (preveiousData.type === "text" || preveiousData.type === "heading") {
|
|
672
|
+
const blockLastOffset = _getEditorbleEndPosition($preveiousBlock);
|
|
673
|
+
preveiousData.textContent += curruntData.textContent;
|
|
674
|
+
newData.splice(editorStore.selectedBlockIndex - 1, 1, preveiousData);
|
|
675
|
+
newData.splice(editorStore.selectedBlockIndex, 1);
|
|
676
|
+
editorStore.fn.updateEditorData(newData);
|
|
677
|
+
await nextTick();
|
|
678
|
+
const $block = editorStore.element.body.children[editorStore.selectedBlockIndex - 1];
|
|
679
|
+
const $blockTargetNode = $block.childNodes[blockLastOffset.nodeIndex];
|
|
680
|
+
if ($blockTargetNode !== void 0) {
|
|
681
|
+
_setCursorPosition($blockTargetNode, blockLastOffset.offset);
|
|
682
|
+
}
|
|
683
|
+
} else if (preveiousData.type === "list") {
|
|
684
|
+
const $listItems = $preveiousBlock.querySelectorAll(".de-item-text");
|
|
685
|
+
const $listLastChild = $listItems[$listItems.length - 1];
|
|
686
|
+
if ($listLastChild !== void 0) {
|
|
687
|
+
const listChildOffset = _getEditorbleEndPosition($listLastChild);
|
|
688
|
+
const listChildData = preveiousData.child[preveiousData.child.length - 1];
|
|
689
|
+
listChildData.textContent += curruntData.textContent;
|
|
690
|
+
preveiousData.child[preveiousData.child.length - 1] = listChildData;
|
|
691
|
+
newData.splice(editorStore.selectedBlockIndex - 1, 1, preveiousData);
|
|
692
|
+
newData.splice(editorStore.selectedBlockIndex, 1);
|
|
693
|
+
editorStore.fn.updateEditorData(newData);
|
|
694
|
+
await nextTick();
|
|
695
|
+
const $node = $listLastChild.childNodes[listChildOffset.nodeIndex];
|
|
696
|
+
if ($node !== void 0) {
|
|
697
|
+
_setCursorPosition($node, listChildOffset.offset);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
} else {
|
|
701
|
+
newData.splice(editorStore.selectedBlockIndex - 1, 1);
|
|
702
|
+
editorStore.fn.updateEditorData(newData);
|
|
703
|
+
editorStore.selectedBlockIndex -= 1;
|
|
1160
704
|
}
|
|
1161
|
-
_setCursor($targetBlock, 0);
|
|
1162
705
|
}
|
|
1163
|
-
$targetItem.remove();
|
|
1164
|
-
} else {
|
|
1165
|
-
$preBlock.remove();
|
|
1166
706
|
}
|
|
1167
|
-
} else {
|
|
1168
|
-
const newTextBlockData = _getDefaultBlockData("text");
|
|
1169
|
-
newTextBlockData.textContent = childHTML;
|
|
1170
|
-
const $newTextBlock = _createTextBlock(newTextBlockData);
|
|
1171
|
-
$block.insertAdjacentElement("afterend", $newTextBlock);
|
|
1172
|
-
$newTextBlock.focus();
|
|
1173
|
-
$block.remove();
|
|
1174
707
|
}
|
|
1175
708
|
}
|
|
1176
|
-
function
|
|
1177
|
-
|
|
1178
|
-
|
|
709
|
+
export async function _listBackspaceEvent(event, childIndex) {
|
|
710
|
+
const editorStore = useEditorStore();
|
|
711
|
+
const $target = event.currentTarget;
|
|
712
|
+
_updateCursorData();
|
|
713
|
+
if ($target !== null && editorStore.element.body !== null && editorStore.fn.updateEditorData !== null) {
|
|
714
|
+
const multilinePosition = _getMultilinePosition($target);
|
|
715
|
+
const cursorPosition = _isCursorAtLineBoundary();
|
|
716
|
+
if (multilinePosition.curruntLine === 1 && cursorPosition.isStart === true) {
|
|
1179
717
|
event.preventDefault();
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
if (
|
|
1186
|
-
|
|
1187
|
-
|
|
718
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
719
|
+
const curruntData = newData[editorStore.selectedBlockIndex];
|
|
720
|
+
const curruntListItem = curruntData.child[childIndex];
|
|
721
|
+
const $block = _findParentBlock($target);
|
|
722
|
+
if ($block !== null && curruntListItem !== void 0) {
|
|
723
|
+
if (childIndex === 0) {
|
|
724
|
+
if (curruntData.child.length === 1) {
|
|
725
|
+
newData.splice(editorStore.selectedBlockIndex, 1, _createTextBlockData(curruntListItem.textContent));
|
|
726
|
+
editorStore.fn.updateEditorData(newData);
|
|
727
|
+
await nextTick();
|
|
728
|
+
const $targetBlock = editorStore.element.body.children[editorStore.selectedBlockIndex];
|
|
729
|
+
if ($targetBlock !== void 0) {
|
|
730
|
+
$targetBlock.focus();
|
|
731
|
+
}
|
|
732
|
+
} else {
|
|
733
|
+
curruntData.child.splice(childIndex, 1);
|
|
734
|
+
newData.splice(editorStore.selectedBlockIndex, 1, _createTextBlockData(curruntListItem.textContent), curruntData);
|
|
735
|
+
editorStore.fn.updateEditorData(newData);
|
|
736
|
+
await nextTick();
|
|
737
|
+
const $targetBlock = editorStore.element.body.children[editorStore.selectedBlockIndex];
|
|
738
|
+
if ($targetBlock !== void 0) {
|
|
739
|
+
$targetBlock.focus();
|
|
740
|
+
}
|
|
741
|
+
}
|
|
1188
742
|
} else {
|
|
1189
|
-
|
|
1190
|
-
$
|
|
743
|
+
const preveiousListItem = curruntData.child[childIndex - 1];
|
|
744
|
+
const $listItems = $block.querySelectorAll(".de-item-text");
|
|
745
|
+
const $preveiousListBlock = $listItems[childIndex - 1];
|
|
746
|
+
if (preveiousListItem !== void 0 && $preveiousListBlock !== void 0) {
|
|
747
|
+
const listChildEndOffset = _getEditorbleEndPosition($preveiousListBlock);
|
|
748
|
+
preveiousListItem.textContent += curruntListItem.textContent;
|
|
749
|
+
curruntData.child.splice(childIndex, 1);
|
|
750
|
+
newData.splice(editorStore.selectedBlockIndex, 1, curruntData);
|
|
751
|
+
editorStore.fn.updateEditorData(newData);
|
|
752
|
+
await nextTick();
|
|
753
|
+
const $targetNode = $preveiousListBlock.childNodes[listChildEndOffset.nodeIndex];
|
|
754
|
+
if ($targetNode !== void 0) {
|
|
755
|
+
_setCursorPosition($targetNode, listChildEndOffset.offset);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
1191
758
|
}
|
|
1192
759
|
}
|
|
1193
760
|
}
|
|
1194
761
|
}
|
|
1195
762
|
}
|
|
1196
|
-
function
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
763
|
+
export async function _defaultDeleteEvent(event, setEvent, abortEvent) {
|
|
764
|
+
const editorStore = useEditorStore();
|
|
765
|
+
const $target = event.currentTarget;
|
|
766
|
+
_updateCursorData();
|
|
767
|
+
if ($target !== null && editorStore.element.body !== null && editorStore.fn.updateEditorData !== null) {
|
|
768
|
+
const multilinePosition = _getMultilinePosition($target);
|
|
769
|
+
const cursorPosition = _isCursorAtLineBoundary();
|
|
770
|
+
if (multilinePosition.curruntLine === multilinePosition.lineCount && cursorPosition.isEnd === true) {
|
|
771
|
+
event.preventDefault();
|
|
772
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
773
|
+
const curruntData = newData[editorStore.selectedBlockIndex];
|
|
774
|
+
if (editorStore.selectedBlockIndex !== newData.length - 1) {
|
|
775
|
+
const nextData = newData[editorStore.selectedBlockIndex + 1];
|
|
776
|
+
const $nextBlock = editorStore.element.body.children[editorStore.selectedBlockIndex + 1];
|
|
777
|
+
const blockLastOffset = _getEditorbleEndPosition($target);
|
|
778
|
+
if (nextData.type === "text" || nextData.type === "heading") {
|
|
779
|
+
curruntData.textContent += nextData.textContent;
|
|
780
|
+
newData.splice(editorStore.selectedBlockIndex, 1, curruntData);
|
|
781
|
+
newData.splice(editorStore.selectedBlockIndex + 1, 1);
|
|
782
|
+
abortEvent();
|
|
783
|
+
editorStore.fn.updateEditorData(newData);
|
|
784
|
+
await nextTick();
|
|
785
|
+
setEvent(editorStore.selectedBlockIndex, curruntData.id);
|
|
786
|
+
const $block = editorStore.element.body.children[editorStore.selectedBlockIndex];
|
|
787
|
+
const $blockTargetNode = $block.childNodes[blockLastOffset.nodeIndex];
|
|
788
|
+
if ($blockTargetNode !== void 0) {
|
|
789
|
+
_setCursorPosition($blockTargetNode, blockLastOffset.offset);
|
|
790
|
+
}
|
|
791
|
+
} else if (nextData.type === "list") {
|
|
792
|
+
const $listItems = $nextBlock.querySelectorAll(".de-item-text");
|
|
793
|
+
const $listLastChild = $listItems[0];
|
|
794
|
+
if ($listLastChild !== void 0) {
|
|
795
|
+
const listChildData = nextData.child[0];
|
|
796
|
+
curruntData.textContent += listChildData.textContent;
|
|
797
|
+
nextData.child.splice(0, 1);
|
|
798
|
+
newData.splice(editorStore.selectedBlockIndex, 1, curruntData);
|
|
799
|
+
newData.splice(editorStore.selectedBlockIndex + 1, 1, nextData);
|
|
800
|
+
abortEvent();
|
|
801
|
+
editorStore.fn.updateEditorData(newData);
|
|
802
|
+
await nextTick();
|
|
803
|
+
setEvent(editorStore.selectedBlockIndex, curruntData.id);
|
|
804
|
+
const $block = editorStore.element.body.children[editorStore.selectedBlockIndex];
|
|
805
|
+
const $blockTargetNode = $block.childNodes[blockLastOffset.nodeIndex];
|
|
806
|
+
if ($blockTargetNode !== void 0) {
|
|
807
|
+
_setCursorPosition($blockTargetNode, blockLastOffset.offset);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
newData.splice(editorStore.selectedBlockIndex + 1, 1);
|
|
812
|
+
editorStore.fn.updateEditorData(newData);
|
|
813
|
+
}
|
|
1222
814
|
}
|
|
1223
815
|
}
|
|
1224
|
-
if (value === 0) {
|
|
1225
|
-
delete $block.dataset["depth"];
|
|
1226
|
-
} else {
|
|
1227
|
-
$block.dataset["depth"] = String(value);
|
|
1228
|
-
}
|
|
1229
|
-
_updateModelData(store);
|
|
1230
816
|
}
|
|
1231
817
|
}
|
|
1232
|
-
function
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
break;
|
|
1241
|
-
default:
|
|
1242
|
-
___defaultBlockDeleteEvent(event, store);
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
function ___defaultBlockDeleteEvent(event, store) {
|
|
1246
|
-
if (store.value.cursorData !== null && store.value.controlStatus.$currentBlock !== null && store.value.$body !== null) {
|
|
1247
|
-
const cursorData = store.value.cursorData;
|
|
1248
|
-
const $block = store.value.controlStatus.$currentBlock;
|
|
1249
|
-
let $target = cursorData.startNode;
|
|
1250
|
-
if ($target.constructor.name === "Text") {
|
|
1251
|
-
$target = $target.parentNode;
|
|
1252
|
-
}
|
|
1253
|
-
if ($block.textContent === "") {
|
|
818
|
+
export async function _listDeleteEvent(event, childIndex, setEvent, abortEvent) {
|
|
819
|
+
const editorStore = useEditorStore();
|
|
820
|
+
const $target = event.currentTarget;
|
|
821
|
+
_updateCursorData();
|
|
822
|
+
if ($target !== null && editorStore.element.body !== null && editorStore.fn.updateEditorData !== null) {
|
|
823
|
+
const multilinePosition = _getMultilinePosition($target);
|
|
824
|
+
const cursorPosition = _isCursorAtLineBoundary();
|
|
825
|
+
if (multilinePosition.curruntLine === multilinePosition.lineCount && cursorPosition.isEnd === true) {
|
|
1254
826
|
event.preventDefault();
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
827
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
828
|
+
const curruntData = newData[editorStore.selectedBlockIndex];
|
|
829
|
+
const curruntListItem = curruntData.child[childIndex];
|
|
830
|
+
const blockLastOffset = _getEditorbleEndPosition($target);
|
|
831
|
+
const $block = _findParentBlock($target);
|
|
832
|
+
if ($block !== null && curruntListItem !== void 0) {
|
|
833
|
+
if (childIndex === curruntData.child.length - 1) {
|
|
834
|
+
const nextData = newData[editorStore.selectedBlockIndex + 1];
|
|
835
|
+
const $nextBlock = editorStore.element.body.children[editorStore.selectedBlockIndex + 1];
|
|
836
|
+
if (nextData.type === "text" || nextData.type === "heading") {
|
|
837
|
+
curruntListItem.textContent += nextData.textContent;
|
|
838
|
+
curruntData.child.splice(childIndex, 1, curruntListItem);
|
|
839
|
+
newData.splice(editorStore.selectedBlockIndex, 1, curruntData);
|
|
840
|
+
newData.splice(editorStore.selectedBlockIndex + 1, 1);
|
|
841
|
+
abortEvent();
|
|
842
|
+
editorStore.fn.updateEditorData(newData);
|
|
843
|
+
await nextTick();
|
|
844
|
+
setEvent(childIndex, curruntListItem.id);
|
|
845
|
+
const $targetNode = $target.childNodes[blockLastOffset.nodeIndex];
|
|
846
|
+
if ($targetNode !== void 0) {
|
|
847
|
+
_setCursorPosition($targetNode, blockLastOffset.offset);
|
|
848
|
+
}
|
|
849
|
+
} else if (nextData.type === "list") {
|
|
850
|
+
const nextChildData = nextData.child[0];
|
|
851
|
+
curruntListItem.textContent += nextChildData.textContent;
|
|
852
|
+
curruntData.child.splice(childIndex, 1, curruntListItem);
|
|
853
|
+
nextData.child.splice(0, 1);
|
|
854
|
+
newData.splice(editorStore.selectedBlockIndex, 1, curruntData);
|
|
855
|
+
newData.splice(editorStore.selectedBlockIndex + 1, 1, nextData);
|
|
856
|
+
abortEvent();
|
|
857
|
+
editorStore.fn.updateEditorData(newData);
|
|
858
|
+
await nextTick();
|
|
859
|
+
setEvent(childIndex, curruntListItem.id);
|
|
860
|
+
const $targetNode = $target.childNodes[blockLastOffset.nodeIndex];
|
|
861
|
+
if ($targetNode !== void 0) {
|
|
862
|
+
_setCursorPosition($targetNode, blockLastOffset.offset);
|
|
863
|
+
}
|
|
864
|
+
} else {
|
|
865
|
+
newData.splice(editorStore.selectedBlockIndex + 1, 1);
|
|
866
|
+
editorStore.fn.updateEditorData(newData);
|
|
867
|
+
}
|
|
1260
868
|
} else {
|
|
1261
|
-
|
|
869
|
+
const nextListItem = curruntData.child[childIndex + 1];
|
|
870
|
+
const $listItems = $block.querySelectorAll(".de-item-text");
|
|
871
|
+
const $nextListBlock = $listItems[childIndex + 1];
|
|
872
|
+
if (nextListItem !== void 0 && $nextListBlock !== void 0) {
|
|
873
|
+
curruntListItem.textContent += nextListItem.textContent;
|
|
874
|
+
curruntData.child.splice(childIndex, 1, curruntListItem);
|
|
875
|
+
curruntData.child.splice(childIndex + 1, 1);
|
|
876
|
+
newData.splice(editorStore.selectedBlockIndex, 1, curruntData);
|
|
877
|
+
abortEvent();
|
|
878
|
+
editorStore.fn.updateEditorData(newData);
|
|
879
|
+
await nextTick();
|
|
880
|
+
setEvent(childIndex, curruntListItem.id);
|
|
881
|
+
const $targetNode = $target.childNodes[blockLastOffset.nodeIndex];
|
|
882
|
+
if ($targetNode !== void 0) {
|
|
883
|
+
_setCursorPosition($targetNode, blockLastOffset.offset);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
1262
886
|
}
|
|
1263
887
|
}
|
|
1264
|
-
____deleteLogic($block, $block);
|
|
1265
|
-
} else {
|
|
1266
|
-
const lastChild = $block.childNodes[$block.childNodes.length - 1];
|
|
1267
|
-
if (cursorData.type === "Caret" && lastChild !== void 0 && lastChild.textContent && cursorData.startOffset === lastChild.textContent.length && (lastChild === cursorData.startNode || lastChild === $target)) {
|
|
1268
|
-
event.preventDefault();
|
|
1269
|
-
____deleteLogic($block, $block);
|
|
1270
|
-
}
|
|
1271
888
|
}
|
|
1272
889
|
}
|
|
1273
890
|
}
|
|
1274
|
-
function
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
if ($liList.length === 1) {
|
|
1292
|
-
if ($targetItem.textContent === "") {
|
|
1293
|
-
event.preventDefault();
|
|
1294
|
-
____deleteLogic($targetItem, $listBlock);
|
|
1295
|
-
} else {
|
|
1296
|
-
const lastChild = $targetItem.childNodes[$targetItem.childNodes.length - 1];
|
|
1297
|
-
if (cursorData.type === "Caret" && lastChild !== void 0 && lastChild.textContent && cursorData.startOffset === lastChild.textContent.length && (lastChild === cursorData.startNode || lastChild === $target)) {
|
|
1298
|
-
event.preventDefault();
|
|
1299
|
-
____deleteLogic($targetItem, $listBlock);
|
|
891
|
+
export async function _allDataPasteEvent(event, setEvent, abortEvent) {
|
|
892
|
+
event.preventDefault();
|
|
893
|
+
_updateCursorData();
|
|
894
|
+
const editorStore = useEditorStore();
|
|
895
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
896
|
+
const curruntData = newData[editorStore.selectedBlockIndex];
|
|
897
|
+
const textData = await navigator.clipboard.readText();
|
|
898
|
+
const $target = event.target;
|
|
899
|
+
if (editorStore.fn.updateEditorData !== null && editorStore.cursorSelection !== null) {
|
|
900
|
+
if (textData === "") {
|
|
901
|
+
const clipboardItems = await navigator.clipboard.read();
|
|
902
|
+
if (editorStore.fn.uploadImage !== null) {
|
|
903
|
+
const imageItem = clipboardItems[0].types.find((type) => type.startsWith("image/"));
|
|
904
|
+
if (imageItem !== void 0) {
|
|
905
|
+
const blob = await clipboardItems[0].getType(imageItem);
|
|
906
|
+
const file = new File([blob], `${_generateId()}.${imageItem.split("/")[1]}`);
|
|
907
|
+
editorStore.fn.uploadImage([file]);
|
|
1300
908
|
}
|
|
1301
909
|
}
|
|
1302
910
|
} else {
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
}
|
|
911
|
+
const dataLine = textData.split("\n");
|
|
912
|
+
const blockData = await _convertMarkdownToEditor(dataLine);
|
|
913
|
+
const firstBlockData = blockData[0];
|
|
914
|
+
if (dataLine.length === 1 && firstBlockData.type === "text") {
|
|
915
|
+
const textNode = document.createTextNode(firstBlockData.textContent);
|
|
916
|
+
abortEvent();
|
|
917
|
+
editorStore.cursorSelection.deleteFromDocument();
|
|
918
|
+
editorStore.cursorSelection.getRangeAt(0).insertNode(textNode);
|
|
919
|
+
$target.dispatchEvent(new Event("input"));
|
|
920
|
+
setEvent();
|
|
921
|
+
_setCursorPosition(textNode, textNode.length);
|
|
1315
922
|
} else {
|
|
1316
|
-
if (
|
|
1317
|
-
|
|
1318
|
-
____deleteLogic($targetItem, $targetItem);
|
|
923
|
+
if (editorStore.selectedBlockIndex > -1) {
|
|
924
|
+
newData.splice(editorStore.selectedBlockIndex + 1, 0, ...blockData);
|
|
1319
925
|
} else {
|
|
1320
|
-
|
|
1321
|
-
if (cursorData.type === "Caret" && lastChild !== void 0 && lastChild.textContent && cursorData.startOffset === lastChild.textContent.length && (lastChild === cursorData.startNode || lastChild === $target)) {
|
|
1322
|
-
event.preventDefault();
|
|
1323
|
-
____deleteLogic($targetItem, $targetItem);
|
|
1324
|
-
}
|
|
926
|
+
newData.push(...blockData);
|
|
1325
927
|
}
|
|
928
|
+
abortEvent();
|
|
929
|
+
editorStore.fn.updateEditorData(newData);
|
|
930
|
+
await nextTick();
|
|
1326
931
|
}
|
|
1327
932
|
}
|
|
1328
933
|
}
|
|
1329
934
|
}
|
|
1330
|
-
function
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
if ($block.tagName !== "LI") {
|
|
1344
|
-
const $liList = $nextBlock.querySelectorAll(".de-item");
|
|
1345
|
-
$nextBlock = $liList[0];
|
|
1346
|
-
}
|
|
1347
|
-
break;
|
|
1348
|
-
}
|
|
1349
|
-
if (nextDelete === false) {
|
|
1350
|
-
if ($nextBlock.hasChildNodes() === true) {
|
|
1351
|
-
const childHTML = $nextBlock.innerHTML;
|
|
1352
|
-
if ($targetElement.hasChildNodes() === true) {
|
|
1353
|
-
$targetElement.insertAdjacentHTML("beforeend", childHTML);
|
|
1354
|
-
} else {
|
|
1355
|
-
$targetElement.innerHTML = childHTML;
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
$nextBlock.remove();
|
|
935
|
+
export async function _normalPasteEvent(event, setEvent, abortEvent) {
|
|
936
|
+
event.preventDefault();
|
|
937
|
+
_updateCursorData();
|
|
938
|
+
const editorStore = useEditorStore();
|
|
939
|
+
const textData = await navigator.clipboard.readText();
|
|
940
|
+
const $target = event.target;
|
|
941
|
+
if (textData !== "" && editorStore.cursorSelection !== null && $target !== null) {
|
|
942
|
+
const textNode = document.createTextNode(textData);
|
|
943
|
+
if ($target.classList.contains("de-item-text") === true) {
|
|
944
|
+
editorStore.cursorSelection.deleteFromDocument();
|
|
945
|
+
editorStore.cursorSelection.getRangeAt(0).insertNode(textNode);
|
|
946
|
+
$target.dispatchEvent(new Event("input"));
|
|
947
|
+
_setCursorPosition(textNode, textNode.length);
|
|
1359
948
|
} else {
|
|
1360
|
-
|
|
949
|
+
abortEvent();
|
|
950
|
+
editorStore.cursorSelection.deleteFromDocument();
|
|
951
|
+
editorStore.cursorSelection.getRangeAt(0).insertNode(textNode);
|
|
952
|
+
$target.dispatchEvent(new Event("input"));
|
|
953
|
+
setEvent();
|
|
954
|
+
_setCursorPosition(textNode, textNode.length);
|
|
1361
955
|
}
|
|
1362
956
|
}
|
|
1363
957
|
}
|
|
1364
|
-
function
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
$block.remove();
|
|
1398
|
-
break;
|
|
1399
|
-
case "1.":
|
|
1400
|
-
event.preventDefault();
|
|
1401
|
-
const $newOlBlock = _createListBlock(_getDefaultBlockData("ol"));
|
|
1402
|
-
$block.insertAdjacentElement("afterend", $newOlBlock);
|
|
1403
|
-
$newOlBlock.children[0].focus();
|
|
1404
|
-
$block.remove();
|
|
1405
|
-
break;
|
|
958
|
+
export async function _convertTextBlockType(event, data, index) {
|
|
959
|
+
const editorStore = useEditorStore();
|
|
960
|
+
const headingReg = new RegExp("^(#{1,3})");
|
|
961
|
+
const orderedReg = new RegExp("^\\d*\\.");
|
|
962
|
+
const unorderedReg = new RegExp("^-");
|
|
963
|
+
if (editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
|
|
964
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
965
|
+
switch (true) {
|
|
966
|
+
case headingReg.test(data.textContent):
|
|
967
|
+
event.preventDefault();
|
|
968
|
+
const match = data.textContent.match(headingReg);
|
|
969
|
+
if (match !== null) {
|
|
970
|
+
const level = match[0].length;
|
|
971
|
+
newData.splice(index, 1, _createHeadingBlockData(level, data.textContent.replace(headingReg, "")));
|
|
972
|
+
}
|
|
973
|
+
break;
|
|
974
|
+
case orderedReg.test(data.textContent):
|
|
975
|
+
event.preventDefault();
|
|
976
|
+
newData.splice(index, 1, _createListBlockData("ol", [_createListBlockChildData(data.textContent.replace(orderedReg, ""))]));
|
|
977
|
+
break;
|
|
978
|
+
case unorderedReg.test(data.textContent):
|
|
979
|
+
event.preventDefault();
|
|
980
|
+
newData.splice(index, 1, _createListBlockData("ul", [_createListBlockChildData(data.textContent.replace(unorderedReg, ""))]));
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
editorStore.fn.updateEditorData(newData);
|
|
984
|
+
await nextTick();
|
|
985
|
+
const $block = editorStore.element.body.children[index];
|
|
986
|
+
if ($block !== void 0) {
|
|
987
|
+
const $target = _findEditableElement($block, "down");
|
|
988
|
+
if ($target !== null) {
|
|
989
|
+
$target.focus();
|
|
990
|
+
$target.dispatchEvent(new Event("input"));
|
|
1406
991
|
}
|
|
1407
992
|
}
|
|
1408
993
|
}
|
|
1409
994
|
}
|
|
1410
|
-
function
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
} else {
|
|
1426
|
-
suitable = true;
|
|
1427
|
-
}
|
|
1428
|
-
if (suitable === true) {
|
|
1429
|
-
switch (store.value.controlStatus.currentBlockType) {
|
|
1430
|
-
case "code":
|
|
1431
|
-
break;
|
|
1432
|
-
case "ol":
|
|
1433
|
-
case "ul":
|
|
1434
|
-
if (keyType === "up") {
|
|
1435
|
-
$targetElement = $editableElement.previousElementSibling;
|
|
1436
|
-
if ($targetElement === null) {
|
|
1437
|
-
$targetElement = $block.previousElementSibling;
|
|
1438
|
-
}
|
|
1439
|
-
} else {
|
|
1440
|
-
$targetElement = $editableElement.nextElementSibling;
|
|
1441
|
-
if ($targetElement === null) {
|
|
1442
|
-
$targetElement = $block.nextElementSibling;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
break;
|
|
1446
|
-
default:
|
|
1447
|
-
if (keyType === "up") {
|
|
1448
|
-
$targetElement = $block.previousElementSibling;
|
|
1449
|
-
} else {
|
|
1450
|
-
$targetElement = $block.nextElementSibling;
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
if ($targetElement !== null) {
|
|
1454
|
-
const { type, $element } = _getCurrentBlock($targetElement);
|
|
1455
|
-
switch (type) {
|
|
1456
|
-
case "image":
|
|
1457
|
-
if ($element !== null) {
|
|
1458
|
-
const $caption = $element.querySelector(".de-caption");
|
|
1459
|
-
if ($caption !== null) {
|
|
1460
|
-
$targetElement = $caption;
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
break;
|
|
1464
|
-
case "ol":
|
|
1465
|
-
case "ul":
|
|
1466
|
-
if ($targetElement.tagName !== "LI" && $element !== null) {
|
|
1467
|
-
const $childList = $element.querySelectorAll(".de-item");
|
|
1468
|
-
if (keyType === "up") {
|
|
1469
|
-
$targetElement = $childList[$childList.length - 1];
|
|
1470
|
-
} else {
|
|
1471
|
-
$targetElement = $childList[0];
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
break;
|
|
1475
|
-
}
|
|
1476
|
-
_setCursor($targetElement, 0);
|
|
1477
|
-
}
|
|
995
|
+
export async function _convertTextBlockToCodeBlock(event, data, index) {
|
|
996
|
+
const editorStore = useEditorStore();
|
|
997
|
+
const regexp = new RegExp("^``");
|
|
998
|
+
if (regexp.test(data.textContent) === true && editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
|
|
999
|
+
event.preventDefault();
|
|
1000
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
1001
|
+
newData.splice(index, 1, _createCodeBlockData());
|
|
1002
|
+
editorStore.fn.updateEditorData(newData);
|
|
1003
|
+
await nextTick();
|
|
1004
|
+
const $block = editorStore.element.body.children[index];
|
|
1005
|
+
if ($block !== void 0) {
|
|
1006
|
+
const $target = _findEditableElement($block, "down");
|
|
1007
|
+
if ($target !== null) {
|
|
1008
|
+
$target.focus();
|
|
1009
|
+
$target.dispatchEvent(new Event("input"));
|
|
1478
1010
|
}
|
|
1479
1011
|
}
|
|
1480
1012
|
}
|
|
1481
1013
|
}
|
|
1482
|
-
function
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
if (
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1014
|
+
export async function _convertTextBlockToDividerBlock(event, data, index) {
|
|
1015
|
+
const editorStore = useEditorStore();
|
|
1016
|
+
const regexp = new RegExp("^--");
|
|
1017
|
+
if (regexp.test(data.textContent) === true && editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
|
|
1018
|
+
event.preventDefault();
|
|
1019
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
1020
|
+
data.textContent = "";
|
|
1021
|
+
newData.splice(index, 0, _createDividerBlockData());
|
|
1022
|
+
newData.splice(index + 1, 1, data);
|
|
1023
|
+
editorStore.fn.updateEditorData(newData);
|
|
1024
|
+
await nextTick();
|
|
1025
|
+
const $block = editorStore.element.body.children[index + 1];
|
|
1026
|
+
if ($block !== void 0) {
|
|
1027
|
+
const $target = _findEditableElement($block, "down");
|
|
1028
|
+
if ($target !== null) {
|
|
1029
|
+
$target.innerHTML = "";
|
|
1030
|
+
$target.focus();
|
|
1031
|
+
$target.dispatchEvent(new Event("input"));
|
|
1032
|
+
}
|
|
1490
1033
|
}
|
|
1491
1034
|
}
|
|
1492
|
-
return suitable;
|
|
1493
1035
|
}
|
|
1494
|
-
function
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
if (
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1036
|
+
export async function _convertHeadingBlockType(event, data, index, setEvent, abortEvent) {
|
|
1037
|
+
const editorStore = useEditorStore();
|
|
1038
|
+
const regexp = new RegExp("^(#{1,3})");
|
|
1039
|
+
if (regexp.test(data.textContent) === true && editorStore.fn.updateEditorData !== null && editorStore.element.body !== null) {
|
|
1040
|
+
event.preventDefault();
|
|
1041
|
+
const newData = JSON.parse(JSON.stringify(editorStore.data));
|
|
1042
|
+
const match = regexp.exec(data.textContent);
|
|
1043
|
+
if (match !== null) {
|
|
1044
|
+
const level = match[0].length;
|
|
1045
|
+
data.level = level;
|
|
1046
|
+
data.textContent = data.textContent.replace(regexp, "");
|
|
1047
|
+
newData.splice(index, 1, data);
|
|
1048
|
+
abortEvent();
|
|
1049
|
+
editorStore.fn.updateEditorData(newData);
|
|
1050
|
+
await nextTick();
|
|
1051
|
+
setEvent();
|
|
1052
|
+
const $block = editorStore.element.body.children[index];
|
|
1053
|
+
if ($block !== void 0) {
|
|
1054
|
+
$block.focus();
|
|
1055
|
+
$block.dispatchEvent(new Event("input"));
|
|
1056
|
+
}
|
|
1502
1057
|
}
|
|
1503
1058
|
}
|
|
1504
|
-
return suitable;
|
|
1505
1059
|
}
|
|
1506
|
-
export function _hotKeyEvent(event
|
|
1507
|
-
const
|
|
1508
|
-
if (
|
|
1060
|
+
export function _hotKeyEvent(event) {
|
|
1061
|
+
const isControllKeyActive = event.ctrlKey || event.metaKey;
|
|
1062
|
+
if (isControllKeyActive === true) {
|
|
1509
1063
|
switch (event.key) {
|
|
1510
1064
|
case "b":
|
|
1511
1065
|
event.preventDefault();
|
|
1512
|
-
_setDecoration("de-bold"
|
|
1066
|
+
_setDecoration("de-bold");
|
|
1513
1067
|
break;
|
|
1514
1068
|
case "i":
|
|
1515
1069
|
event.preventDefault();
|
|
1516
|
-
_setDecoration("de-italic"
|
|
1070
|
+
_setDecoration("de-italic");
|
|
1517
1071
|
break;
|
|
1518
1072
|
case "u":
|
|
1519
1073
|
event.preventDefault();
|
|
1520
|
-
_setDecoration("de-underline"
|
|
1074
|
+
_setDecoration("de-underline");
|
|
1521
1075
|
break;
|
|
1522
1076
|
case "s":
|
|
1523
1077
|
if (event.shiftKey === true) {
|
|
1524
1078
|
event.preventDefault();
|
|
1525
|
-
_setDecoration("de-strikethrough"
|
|
1079
|
+
_setDecoration("de-strikethrough");
|
|
1526
1080
|
}
|
|
1527
1081
|
break;
|
|
1528
1082
|
case "c":
|
|
1529
1083
|
if (event.shiftKey === true) {
|
|
1530
1084
|
event.preventDefault();
|
|
1531
|
-
_setDecoration("de-code"
|
|
1085
|
+
_setDecoration("de-code");
|
|
1532
1086
|
}
|
|
1533
1087
|
break;
|
|
1534
1088
|
}
|
|
1535
1089
|
}
|
|
1536
1090
|
}
|
|
1537
|
-
function __backtickEvent(event, store) {
|
|
1538
|
-
if (store.value.controlStatus.$currentBlock !== null && store.value.controlStatus.currentBlockType === "text") {
|
|
1539
|
-
const $block = store.value.controlStatus.$currentBlock;
|
|
1540
|
-
if ($block.textContent === "``") {
|
|
1541
|
-
event.preventDefault();
|
|
1542
|
-
const $newBlock = _createCodeBlock(_getDefaultBlockData("code"), store);
|
|
1543
|
-
$block.insertAdjacentElement("afterend", $newBlock);
|
|
1544
|
-
$block.remove();
|
|
1545
|
-
const $code = $newBlock.querySelector(".de-code-content");
|
|
1546
|
-
if ($code !== null) {
|
|
1547
|
-
_setCursor($code, 0);
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
let contentKeyupEvent;
|
|
1553
|
-
export function _contentKeyupEvent(event, store) {
|
|
1554
|
-
_updateCurrentBlock(event, store);
|
|
1555
|
-
_updateCursorData(store);
|
|
1556
|
-
__checkBlock(store);
|
|
1557
|
-
clearTimeout(contentKeyupEvent);
|
|
1558
|
-
contentKeyupEvent = setTimeout(() => {
|
|
1559
|
-
_updateModelData(store);
|
|
1560
|
-
}, 250);
|
|
1561
|
-
}
|
|
1562
|
-
function __checkBlock(store) {
|
|
1563
|
-
if (store.value.$body !== null) {
|
|
1564
|
-
const blockList = store.value.$body.querySelectorAll(".de-block");
|
|
1565
|
-
blockList.forEach(($block) => {
|
|
1566
|
-
const { type } = _getCurrentBlock($block);
|
|
1567
|
-
switch (type) {
|
|
1568
|
-
case "ol":
|
|
1569
|
-
case "ul":
|
|
1570
|
-
if ($block.hasChildNodes() === false) {
|
|
1571
|
-
$block.remove();
|
|
1572
|
-
}
|
|
1573
|
-
break;
|
|
1574
|
-
case "text":
|
|
1575
|
-
case "heading":
|
|
1576
|
-
if ($block.textContent === "" && $block.hasChildNodes() === true) {
|
|
1577
|
-
const textNodeType = $block.childNodes[0].constructor.name;
|
|
1578
|
-
if (textNodeType === "HTMLBRElement") {
|
|
1579
|
-
$block.innerHTML = "";
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
break;
|
|
1583
|
-
}
|
|
1584
|
-
});
|
|
1585
|
-
}
|
|
1586
|
-
}
|