dragon-editor 2.0.0-beta.1.3 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -135
- package/README_en.md +14 -62
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -1
- package/dist/runtime/core/components/SvgIcon.vue +175 -0
- package/dist/runtime/core/components/editor/ImageBlock.vue +174 -0
- package/dist/runtime/core/components/editor/TextBlock.vue +137 -0
- package/dist/runtime/core/components/icon/Accept.vue +5 -0
- package/dist/runtime/core/components/icon/AlignCenter.vue +6 -0
- package/dist/runtime/core/components/icon/AlignLeft.vue +6 -0
- package/dist/runtime/core/components/icon/AlignRight.vue +6 -0
- package/dist/runtime/core/components/icon/ArrowDown.vue +3 -0
- package/dist/runtime/core/components/icon/ArrowUp.vue +3 -0
- package/dist/runtime/core/components/icon/Cancel.vue +5 -0
- package/dist/runtime/core/components/icon/CodeBlock.vue +6 -0
- package/dist/runtime/core/components/icon/DecorationBold.vue +6 -0
- package/dist/runtime/core/components/icon/DecorationItalic.vue +6 -0
- package/dist/runtime/core/components/icon/DecorationStrikethrough.vue +6 -0
- package/dist/runtime/core/components/icon/DecorationUnderline.vue +6 -0
- package/dist/runtime/core/components/icon/Delete.vue +3 -0
- package/dist/runtime/core/components/icon/ImageBlock.vue +5 -0
- package/dist/runtime/core/components/icon/LinkPath.vue +6 -0
- package/dist/runtime/core/components/icon/OlBlock.vue +6 -0
- package/dist/runtime/core/components/icon/QuotationBlock.vue +6 -0
- package/dist/runtime/core/components/icon/TableBlock.vue +8 -0
- package/dist/runtime/core/components/icon/TextBlock.vue +5 -0
- package/dist/runtime/core/components/icon/UlBlock.vue +6 -0
- package/dist/runtime/core/style/common.css +419 -0
- package/dist/runtime/core/style/viewer.css +191 -0
- package/dist/runtime/core/utils/cursor.d.ts +4 -0
- package/dist/runtime/core/utils/cursor.mjs +84 -0
- package/dist/runtime/core/utils/element.d.ts +2 -0
- package/dist/runtime/core/utils/element.mjs +29 -0
- package/dist/runtime/core/utils/index.d.ts +6 -0
- package/dist/runtime/core/utils/index.mjs +67 -0
- package/dist/runtime/core/utils/keyboard.d.ts +6 -0
- package/dist/runtime/core/utils/keyboard.mjs +322 -0
- package/dist/runtime/core/utils/style.d.ts +6 -0
- package/dist/runtime/core/utils/style.mjs +359 -0
- package/dist/runtime/shared/components/DragonEditor.vue +560 -0
- package/dist/runtime/{components → shared/components}/DragonEditorComment.vue +33 -11
- package/dist/runtime/shared/components/DragonEditorViewer.vue +29 -0
- package/package.json +1 -1
- package/dist/runtime/components/DragonEditor.vue +0 -361
- package/dist/runtime/components/DragonEditorViewer.vue +0 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function findEditableElement(node) {
|
|
2
|
+
if (node) {
|
|
3
|
+
if (node.constructor.name === "Text") {
|
|
4
|
+
return findEditableElement(node.parentNode);
|
|
5
|
+
} else {
|
|
6
|
+
if (node.getAttribute) {
|
|
7
|
+
const hasAttr = node.getAttribute("contenteditable") !== null;
|
|
8
|
+
if (hasAttr) {
|
|
9
|
+
return node;
|
|
10
|
+
} else {
|
|
11
|
+
return findEditableElement(node.parentNode);
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function findChildNumber(parent, child) {
|
|
22
|
+
let idx = 0;
|
|
23
|
+
parent.childNodes.forEach((item, count) => {
|
|
24
|
+
if (item === child) {
|
|
25
|
+
idx = count;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return idx;
|
|
29
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function generateId() {
|
|
2
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
3
|
+
let str = "";
|
|
4
|
+
for (let i = 0; i < 20; i++) {
|
|
5
|
+
str += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
6
|
+
}
|
|
7
|
+
return str;
|
|
8
|
+
}
|
|
9
|
+
function createTextBlock(data) {
|
|
10
|
+
if (data) {
|
|
11
|
+
return {
|
|
12
|
+
type: "text",
|
|
13
|
+
id: generateId(),
|
|
14
|
+
classList: data.classList,
|
|
15
|
+
content: data.content
|
|
16
|
+
};
|
|
17
|
+
} else {
|
|
18
|
+
return {
|
|
19
|
+
type: "text",
|
|
20
|
+
id: generateId(),
|
|
21
|
+
classList: [],
|
|
22
|
+
content: ""
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function createImageBlock(data) {
|
|
27
|
+
const totalSize = data.width + data.height;
|
|
28
|
+
const w = Math.round(100 / totalSize * data.width);
|
|
29
|
+
const h = Math.round(100 / totalSize * data.height);
|
|
30
|
+
const contrast = w - h;
|
|
31
|
+
let classList = ["d-align-center"];
|
|
32
|
+
switch (true) {
|
|
33
|
+
case contrast < -40:
|
|
34
|
+
classList.push("--5");
|
|
35
|
+
break;
|
|
36
|
+
case contrast < -15:
|
|
37
|
+
classList.push("--10");
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
classList.push("--20");
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
type: "image",
|
|
44
|
+
id: generateId(),
|
|
45
|
+
classList,
|
|
46
|
+
src: data.src,
|
|
47
|
+
width: data.width,
|
|
48
|
+
height: data.height,
|
|
49
|
+
webp: data.webp,
|
|
50
|
+
caption: data.caption
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function createBlock(name, value) {
|
|
54
|
+
let blockData;
|
|
55
|
+
switch (name) {
|
|
56
|
+
case "image":
|
|
57
|
+
blockData = createImageBlock(value);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
blockData = createTextBlock(value);
|
|
61
|
+
}
|
|
62
|
+
return blockData;
|
|
63
|
+
}
|
|
64
|
+
export * from "./keyboard.mjs";
|
|
65
|
+
export * from "./cursor.mjs";
|
|
66
|
+
export * from "./style.mjs";
|
|
67
|
+
export * from "./element.mjs";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function keyboardEvent(type: string, event: KeyboardEvent, action: Function, update: Function): void;
|
|
2
|
+
export declare function getClipboardData(data: DataTransfer): {
|
|
3
|
+
type: any;
|
|
4
|
+
value: any;
|
|
5
|
+
};
|
|
6
|
+
export declare function pasteText(type: string, value: string): void;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { getCursor, setCursor } from "./cursor.mjs";
|
|
2
|
+
import { findEditableElement, findChildNumber } from "./element.mjs";
|
|
3
|
+
import { getTagName } from "./style.mjs";
|
|
4
|
+
let enterCount = 0;
|
|
5
|
+
function enterEvent(type, event, action) {
|
|
6
|
+
if (event.code === "Enter") {
|
|
7
|
+
event.preventDefault();
|
|
8
|
+
const useShift = event.shiftKey;
|
|
9
|
+
switch (type) {
|
|
10
|
+
case "image":
|
|
11
|
+
action("addBlock", {
|
|
12
|
+
name: "text"
|
|
13
|
+
});
|
|
14
|
+
break;
|
|
15
|
+
case "comment":
|
|
16
|
+
addBrEvent();
|
|
17
|
+
break;
|
|
18
|
+
default:
|
|
19
|
+
if (useShift === false) {
|
|
20
|
+
if (enterCount == 0) {
|
|
21
|
+
textEnterEvent(event, action);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
addBrEvent();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
enterCount += 1;
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
enterCount = 0;
|
|
30
|
+
}, 150);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function textEnterEvent(event, action) {
|
|
34
|
+
const cursorData = getCursor();
|
|
35
|
+
if (cursorData.startNode) {
|
|
36
|
+
const editableElement = findEditableElement(cursorData.startNode);
|
|
37
|
+
const editableElementClassList = [...editableElement.classList].slice(0, 1);
|
|
38
|
+
const startNode = cursorData.startNode;
|
|
39
|
+
const endNode = cursorData.endNode;
|
|
40
|
+
let startChild = startNode;
|
|
41
|
+
let endChild = endNode;
|
|
42
|
+
if (startNode.parentNode !== editableElement) {
|
|
43
|
+
startChild = startNode.parentNode;
|
|
44
|
+
}
|
|
45
|
+
if (endNode.parentNode !== editableElement) {
|
|
46
|
+
endChild = endNode.parentNode;
|
|
47
|
+
}
|
|
48
|
+
const startChildIdx = findChildNumber(editableElement, startChild);
|
|
49
|
+
const endChildIdx = findChildNumber(editableElement, endChild);
|
|
50
|
+
let startIdx = 0;
|
|
51
|
+
let endIdx = 0;
|
|
52
|
+
let startOffset = 0;
|
|
53
|
+
let endOffset = 0;
|
|
54
|
+
let preHTMLStructor = "";
|
|
55
|
+
let nextHTMLStructor = "";
|
|
56
|
+
if (startChildIdx > endChildIdx) {
|
|
57
|
+
startIdx = endChildIdx;
|
|
58
|
+
endIdx = startChildIdx;
|
|
59
|
+
startOffset = cursorData.endOffset;
|
|
60
|
+
endOffset = cursorData.startOffset;
|
|
61
|
+
} else {
|
|
62
|
+
startIdx = startChildIdx;
|
|
63
|
+
endIdx = endChildIdx;
|
|
64
|
+
startOffset = cursorData.startOffset;
|
|
65
|
+
endOffset = cursorData.endOffset;
|
|
66
|
+
}
|
|
67
|
+
if (editableElement.childNodes.length === 0 || endChildIdx === editableElement.childNodes.length - 1 && editableElement.childNodes[endChildIdx].textContent.length === endOffset) {
|
|
68
|
+
action("addBlock", {
|
|
69
|
+
name: "text"
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
editableElement.childNodes.forEach((child, count) => {
|
|
73
|
+
const text = child.textContent;
|
|
74
|
+
if (count < startChildIdx) {
|
|
75
|
+
if (child.constructor.name === "Text") {
|
|
76
|
+
preHTMLStructor += child.textContent;
|
|
77
|
+
} else {
|
|
78
|
+
preHTMLStructor += child.outerHTML;
|
|
79
|
+
}
|
|
80
|
+
} else if (count > endChildIdx) {
|
|
81
|
+
if (child.constructor.name === "Text") {
|
|
82
|
+
nextHTMLStructor += child.textContent;
|
|
83
|
+
} else {
|
|
84
|
+
nextHTMLStructor += child.outerHTML;
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
if (startChildIdx === endChildIdx) {
|
|
88
|
+
if (child.constructor.name === "Text") {
|
|
89
|
+
preHTMLStructor += text.substring(0, startOffset);
|
|
90
|
+
nextHTMLStructor += text.substring(endOffset, text.length);
|
|
91
|
+
} else {
|
|
92
|
+
const childClassList = [...child.classList];
|
|
93
|
+
const originTag = getTagName(child);
|
|
94
|
+
preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
|
|
95
|
+
nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (count === startChildIdx) {
|
|
99
|
+
if (child.constructor.name === "Text") {
|
|
100
|
+
preHTMLStructor += text.substring(0, startOffset);
|
|
101
|
+
} else {
|
|
102
|
+
const childClassList = [...child.classList];
|
|
103
|
+
const originTag = getTagName(child);
|
|
104
|
+
preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
|
|
105
|
+
}
|
|
106
|
+
} else if (count === endChildIdx) {
|
|
107
|
+
if (child.constructor.name === "Text") {
|
|
108
|
+
nextHTMLStructor += text.substring(endOffset, text.length);
|
|
109
|
+
} else {
|
|
110
|
+
const childClassList = [...child.classList];
|
|
111
|
+
const originTag = getTagName(child);
|
|
112
|
+
nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
editableElement.innerHTML = preHTMLStructor;
|
|
119
|
+
action("addBlock", {
|
|
120
|
+
name: "text",
|
|
121
|
+
value: { classList: editableElementClassList, content: nextHTMLStructor }
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function backspaceEvent(type, event, action, update) {
|
|
127
|
+
if (event.code === "Backspace") {
|
|
128
|
+
if (type === "text") {
|
|
129
|
+
const cursorData = getCursor();
|
|
130
|
+
if (cursorData.type === "Caret" && cursorData.startOffset === 0) {
|
|
131
|
+
const editableElement = findEditableElement(cursorData.startNode);
|
|
132
|
+
let $target = cursorData.startNode;
|
|
133
|
+
if ($target.constructor.name === "Text") {
|
|
134
|
+
$target = $target.parentNode;
|
|
135
|
+
}
|
|
136
|
+
if ($target === editableElement) {
|
|
137
|
+
update();
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
action("deleteBlockLocal");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function keyboardEvent(type, event, action, update) {
|
|
146
|
+
enterEvent(type, event, action);
|
|
147
|
+
backspaceEvent(type, event, action, update);
|
|
148
|
+
}
|
|
149
|
+
export function getClipboardData(data) {
|
|
150
|
+
let type, clipboardData;
|
|
151
|
+
if (!data) {
|
|
152
|
+
type = null;
|
|
153
|
+
}
|
|
154
|
+
const items = data.items;
|
|
155
|
+
if (items === void 0) {
|
|
156
|
+
type = null;
|
|
157
|
+
}
|
|
158
|
+
const count = items.length;
|
|
159
|
+
for (let i = 0; i < count; i += 1) {
|
|
160
|
+
if (items[i].type.indexOf("image") === 0) {
|
|
161
|
+
type = "image";
|
|
162
|
+
clipboardData = items[i].getAsFile();
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
type = "text";
|
|
166
|
+
}
|
|
167
|
+
if (type === "text") {
|
|
168
|
+
clipboardData = data.getData("text");
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
type,
|
|
172
|
+
value: clipboardData
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export function pasteText(type, value) {
|
|
176
|
+
const selection = window.getSelection();
|
|
177
|
+
const range = document.createRange();
|
|
178
|
+
let textNode;
|
|
179
|
+
if (type !== "codeBlock") {
|
|
180
|
+
textNode = document.createTextNode(value.replace("\n", "").replace(/ +/g, " "));
|
|
181
|
+
} else {
|
|
182
|
+
textNode = document.createTextNode(value);
|
|
183
|
+
}
|
|
184
|
+
selection.deleteFromDocument();
|
|
185
|
+
selection.getRangeAt(0).insertNode(textNode);
|
|
186
|
+
range.setStart(textNode, textNode.length);
|
|
187
|
+
range.collapse(true);
|
|
188
|
+
selection.removeAllRanges();
|
|
189
|
+
selection.addRange(range);
|
|
190
|
+
}
|
|
191
|
+
function addBrEvent() {
|
|
192
|
+
const cursorData = getCursor();
|
|
193
|
+
if (cursorData.startNode) {
|
|
194
|
+
let $target = cursorData.startNode;
|
|
195
|
+
const preEditableElement = findEditableElement($target);
|
|
196
|
+
if ($target.constructor.name === "Text") {
|
|
197
|
+
$target = $target.parentNode;
|
|
198
|
+
}
|
|
199
|
+
if (preEditableElement !== $target && $target.constructor.name !== "HTMLBRElement") {
|
|
200
|
+
let startNode = cursorData.startNode;
|
|
201
|
+
let endNode = cursorData.endNode;
|
|
202
|
+
let startChild = startNode;
|
|
203
|
+
let endChild = endNode;
|
|
204
|
+
if (startNode.parentNode !== preEditableElement) {
|
|
205
|
+
startChild = startNode.parentNode;
|
|
206
|
+
}
|
|
207
|
+
if (endNode.parentNode !== preEditableElement) {
|
|
208
|
+
endChild = endNode.parentNode;
|
|
209
|
+
}
|
|
210
|
+
const startChildIdx = findChildNumber(preEditableElement, startChild);
|
|
211
|
+
const endChildIdx = findChildNumber(preEditableElement, endChild);
|
|
212
|
+
let startIdx = 0;
|
|
213
|
+
let endIdx = 0;
|
|
214
|
+
let startOffset = 0;
|
|
215
|
+
let endOffset = 0;
|
|
216
|
+
let htmlStructure = "";
|
|
217
|
+
if (startChildIdx > endChildIdx) {
|
|
218
|
+
startIdx = endChildIdx;
|
|
219
|
+
endIdx = startChildIdx;
|
|
220
|
+
startOffset = cursorData.endOffset;
|
|
221
|
+
endOffset = cursorData.startOffset;
|
|
222
|
+
} else {
|
|
223
|
+
startIdx = startChildIdx;
|
|
224
|
+
endIdx = endChildIdx;
|
|
225
|
+
startOffset = cursorData.startOffset;
|
|
226
|
+
endOffset = cursorData.endOffset;
|
|
227
|
+
}
|
|
228
|
+
if (enterCount === 1) {
|
|
229
|
+
const text = startChild.textContent;
|
|
230
|
+
startChild.textContent = text.substring(1, text.length);
|
|
231
|
+
setCursor(startChild, 0);
|
|
232
|
+
} else {
|
|
233
|
+
if (startNode === endNode) {
|
|
234
|
+
const text = startChild.textContent;
|
|
235
|
+
const childClassList = [...startChild.classList];
|
|
236
|
+
const tagData = getTagName(startChild);
|
|
237
|
+
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}>`;
|
|
238
|
+
htmlStructure += `<br>`;
|
|
239
|
+
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}>`;
|
|
240
|
+
startChild.insertAdjacentHTML("beforebegin", htmlStructure);
|
|
241
|
+
setCursor(preEditableElement.childNodes[startChildIdx + 2], 0);
|
|
242
|
+
startChild.remove();
|
|
243
|
+
} else {
|
|
244
|
+
preEditableElement.childNodes.forEach((child, count) => {
|
|
245
|
+
const type = child.constructor.name;
|
|
246
|
+
const text = child.textContent;
|
|
247
|
+
if (count > startIdx && count < endIdx) {
|
|
248
|
+
} else if (count === startIdx) {
|
|
249
|
+
if (type === "Text") {
|
|
250
|
+
htmlStructure += text.substring(0, startOffset);
|
|
251
|
+
} else {
|
|
252
|
+
const childClassList = [...child.classList];
|
|
253
|
+
const tagData = getTagName(child);
|
|
254
|
+
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}><br>`;
|
|
255
|
+
}
|
|
256
|
+
} else if (count === endIdx) {
|
|
257
|
+
if (type === "Text") {
|
|
258
|
+
htmlStructure += text.substring(endOffset, text.length);
|
|
259
|
+
} else {
|
|
260
|
+
const childClassList = [...child.classList];
|
|
261
|
+
const tagData = getTagName(child);
|
|
262
|
+
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}><br>`;
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
if (type === "Text") {
|
|
266
|
+
htmlStructure += child.textContent;
|
|
267
|
+
} else {
|
|
268
|
+
htmlStructure += child.outerHTML;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
preEditableElement.innerHTML = htmlStructure;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
const brTag = document.createElement("br");
|
|
277
|
+
const selection = window.getSelection();
|
|
278
|
+
const range = document.createRange();
|
|
279
|
+
if (enterCount === 1) {
|
|
280
|
+
const nextCursorData = getCursor();
|
|
281
|
+
const editableElement = findEditableElement(nextCursorData.startNode);
|
|
282
|
+
const childList = editableElement.childNodes;
|
|
283
|
+
const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
|
|
284
|
+
setCursor(childList[childIdx + 2], 0);
|
|
285
|
+
} else {
|
|
286
|
+
selection.deleteFromDocument();
|
|
287
|
+
selection.getRangeAt(0).insertNode(brTag);
|
|
288
|
+
range.setStart(brTag, 0);
|
|
289
|
+
range.collapse(true);
|
|
290
|
+
selection.removeAllRanges();
|
|
291
|
+
selection.addRange(range);
|
|
292
|
+
const nextCursorData = getCursor();
|
|
293
|
+
const editableElement = findEditableElement(nextCursorData.startNode);
|
|
294
|
+
const childList = editableElement.childNodes;
|
|
295
|
+
const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
|
|
296
|
+
let hasText = false;
|
|
297
|
+
childList.forEach((row) => {
|
|
298
|
+
if (row.constructor.name === "Text") {
|
|
299
|
+
hasText = true;
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
if (hasText) {
|
|
303
|
+
if (childList[childIdx + 1].textContent?.length === 0) {
|
|
304
|
+
if (childList[childIdx + 2]) {
|
|
305
|
+
if (childList[childIdx + 2].constructor.name == "HTMLBRElement") {
|
|
306
|
+
setCursor(childList[childIdx + 1], 0);
|
|
307
|
+
} else {
|
|
308
|
+
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
setCursor(childList[childIdx + 1], 0);
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { allBlock, styleUtilArgument } from "../../../types";
|
|
2
|
+
export declare function styleSettings({ kind, blockData, $target, url, cursorData }: styleUtilArgument): allBlock;
|
|
3
|
+
export declare function getTagName(node: HTMLElement): {
|
|
4
|
+
name: string;
|
|
5
|
+
href: string | null;
|
|
6
|
+
};
|