dragon-editor 2.1.2 → 3.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 +82 -96
- package/dist/module.json +1 -1
- package/dist/module.mjs +10 -12
- package/dist/runtime/components/DragonEditor.vue +457 -0
- package/dist/runtime/components/DragonEditorViewer.vue +228 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.mjs +10 -0
- package/dist/runtime/scss/editor.css +261 -0
- package/dist/runtime/scss/viewer.css +198 -0
- package/dist/runtime/store.d.ts +7 -0
- package/dist/runtime/store.mjs +27 -0
- package/dist/runtime/type.d.ts +24 -0
- package/dist/runtime/utils/block.d.ts +9 -0
- package/dist/runtime/utils/block.mjs +70 -0
- package/dist/runtime/utils/convertor.d.ts +2 -0
- package/dist/runtime/utils/convertor.mjs +86 -0
- package/dist/runtime/utils/cursor.d.ts +6 -0
- package/dist/runtime/utils/cursor.mjs +132 -0
- package/dist/runtime/utils/element.d.ts +3 -0
- package/dist/runtime/utils/element.mjs +39 -0
- package/dist/runtime/utils/keyboardEvent.d.ts +10 -0
- package/dist/runtime/utils/keyboardEvent.mjs +781 -0
- package/dist/runtime/utils/style.d.ts +1 -0
- package/dist/runtime/utils/style.mjs +330 -0
- package/dist/runtime/utils/ui.d.ts +1 -0
- package/dist/runtime/utils/ui.mjs +35 -0
- package/package.json +10 -4
- package/README_en.md +0 -30
- package/dist/runtime/core/components/SvgIcon.d.ts +0 -10
- package/dist/runtime/core/components/SvgIcon.mjs +0 -98
- package/dist/runtime/core/components/editor/ImageBlock.vue +0 -175
- package/dist/runtime/core/components/editor/OlBlock.vue +0 -162
- package/dist/runtime/core/components/editor/TextBlock.vue +0 -172
- package/dist/runtime/core/components/editor/UlBlock.vue +0 -162
- package/dist/runtime/core/style/common.css +0 -496
- package/dist/runtime/core/style/viewer.css +0 -205
- package/dist/runtime/core/utils/converter.d.ts +0 -2
- package/dist/runtime/core/utils/converter.mjs +0 -90
- package/dist/runtime/core/utils/cursor.d.ts +0 -4
- package/dist/runtime/core/utils/cursor.mjs +0 -84
- package/dist/runtime/core/utils/element.d.ts +0 -3
- package/dist/runtime/core/utils/element.mjs +0 -40
- package/dist/runtime/core/utils/global.d.ts +0 -3
- package/dist/runtime/core/utils/global.mjs +0 -81
- package/dist/runtime/core/utils/index.d.ts +0 -7
- package/dist/runtime/core/utils/index.mjs +0 -7
- package/dist/runtime/core/utils/keyboard.d.ts +0 -6
- package/dist/runtime/core/utils/keyboard.mjs +0 -565
- package/dist/runtime/core/utils/style.d.ts +0 -6
- package/dist/runtime/core/utils/style.mjs +0 -374
- package/dist/runtime/core/utils/ui.d.ts +0 -4
- package/dist/runtime/core/utils/ui.mjs +0 -13
- package/dist/runtime/shared/components/DragonEditor.vue +0 -695
- package/dist/runtime/shared/components/DragonEditorComment.vue +0 -172
- package/dist/runtime/shared/components/DragonEditorNew.d.ts +0 -16
- package/dist/runtime/shared/components/DragonEditorNew.mjs +0 -62
- package/dist/runtime/shared/components/DragonEditorViewer.d.ts +0 -14
- package/dist/runtime/shared/components/DragonEditorViewer.mjs +0 -15
|
@@ -1,565 +0,0 @@
|
|
|
1
|
-
import { getCursor, setCursor } from "./cursor.mjs";
|
|
2
|
-
import { findEditableElement, findChildNumber, findLiElement } from "./element.mjs";
|
|
3
|
-
import { getTagName } from "./style.mjs";
|
|
4
|
-
let enterCount = 0;
|
|
5
|
-
function enterEvent(type, event, action, update) {
|
|
6
|
-
if (event.code === "Enter") {
|
|
7
|
-
event.preventDefault();
|
|
8
|
-
const useShift = event.shiftKey;
|
|
9
|
-
switch (type) {
|
|
10
|
-
case "list":
|
|
11
|
-
if (useShift === false) {
|
|
12
|
-
if (enterCount == 0) {
|
|
13
|
-
listEnterEvent(action, update);
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
addBrEvent();
|
|
17
|
-
}
|
|
18
|
-
break;
|
|
19
|
-
case "image":
|
|
20
|
-
action("addBlock", {
|
|
21
|
-
name: "text"
|
|
22
|
-
});
|
|
23
|
-
break;
|
|
24
|
-
case "comment":
|
|
25
|
-
addBrEvent();
|
|
26
|
-
break;
|
|
27
|
-
default:
|
|
28
|
-
if (useShift === false) {
|
|
29
|
-
if (enterCount == 0) {
|
|
30
|
-
textEnterEvent(action);
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
addBrEvent();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
enterCount += 1;
|
|
37
|
-
setTimeout(() => {
|
|
38
|
-
enterCount = 0;
|
|
39
|
-
}, 150);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function listEnterEvent(action, update) {
|
|
43
|
-
const cursorData = getCursor();
|
|
44
|
-
if (cursorData.startNode) {
|
|
45
|
-
const editableElement = findEditableElement(cursorData.startNode);
|
|
46
|
-
const editableElementClassList = [...editableElement.classList].slice(0, 1);
|
|
47
|
-
const startNode = cursorData.startNode;
|
|
48
|
-
const endNode = cursorData.endNode;
|
|
49
|
-
let startChild = startNode;
|
|
50
|
-
let endChild = endNode;
|
|
51
|
-
if (startNode.parentNode !== editableElement) {
|
|
52
|
-
startChild = startNode.parentNode;
|
|
53
|
-
}
|
|
54
|
-
if (endNode.parentNode !== editableElement) {
|
|
55
|
-
endChild = endNode.parentNode;
|
|
56
|
-
}
|
|
57
|
-
const startChildIdx = findChildNumber(editableElement, startChild);
|
|
58
|
-
const endChildIdx = findChildNumber(editableElement, endChild);
|
|
59
|
-
let startIdx = 0;
|
|
60
|
-
let endIdx = 0;
|
|
61
|
-
let startOffset = 0;
|
|
62
|
-
let endOffset = 0;
|
|
63
|
-
let preHTMLStructor = "";
|
|
64
|
-
let nextHTMLStructor = "";
|
|
65
|
-
if (startChildIdx > endChildIdx) {
|
|
66
|
-
startIdx = endChildIdx;
|
|
67
|
-
endIdx = startChildIdx;
|
|
68
|
-
startOffset = cursorData.endOffset;
|
|
69
|
-
endOffset = cursorData.startOffset;
|
|
70
|
-
} else {
|
|
71
|
-
startIdx = startChildIdx;
|
|
72
|
-
endIdx = endChildIdx;
|
|
73
|
-
startOffset = cursorData.startOffset;
|
|
74
|
-
endOffset = cursorData.endOffset;
|
|
75
|
-
}
|
|
76
|
-
if (editableElement.childNodes.length === 0 || endChildIdx === editableElement.childNodes.length - 1 && editableElement.childNodes[endChildIdx].textContent.length === endOffset) {
|
|
77
|
-
if (editableElement.childNodes.length === 0) {
|
|
78
|
-
editableElement.remove();
|
|
79
|
-
action("addBlock", {
|
|
80
|
-
name: "text"
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
editableElement.insertAdjacentHTML("afterend", `<li class="d-li-item" contenteditable></li>`);
|
|
84
|
-
setCursor(editableElement.nextSibling, 0);
|
|
85
|
-
update();
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
editableElement.childNodes.forEach((child, count) => {
|
|
89
|
-
const text = child.textContent;
|
|
90
|
-
if (count < startChildIdx) {
|
|
91
|
-
if (child.constructor.name === "Text") {
|
|
92
|
-
preHTMLStructor += child.textContent;
|
|
93
|
-
} else {
|
|
94
|
-
preHTMLStructor += child.outerHTML;
|
|
95
|
-
}
|
|
96
|
-
} else if (count > endChildIdx) {
|
|
97
|
-
if (child.constructor.name === "Text") {
|
|
98
|
-
nextHTMLStructor += child.textContent;
|
|
99
|
-
} else {
|
|
100
|
-
nextHTMLStructor += child.outerHTML;
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
if (startChildIdx === endChildIdx) {
|
|
104
|
-
if (child.constructor.name === "Text") {
|
|
105
|
-
preHTMLStructor += text.substring(0, startOffset);
|
|
106
|
-
nextHTMLStructor += text.substring(endOffset, text.length);
|
|
107
|
-
} else {
|
|
108
|
-
const childClassList = [...child.classList];
|
|
109
|
-
const originTag = getTagName(child);
|
|
110
|
-
preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
|
|
111
|
-
nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
if (count === startChildIdx) {
|
|
115
|
-
if (child.constructor.name === "Text") {
|
|
116
|
-
preHTMLStructor += text.substring(0, startOffset);
|
|
117
|
-
} else {
|
|
118
|
-
const childClassList = [...child.classList];
|
|
119
|
-
const originTag = getTagName(child);
|
|
120
|
-
preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
|
|
121
|
-
}
|
|
122
|
-
} else if (count === endChildIdx) {
|
|
123
|
-
if (child.constructor.name === "Text") {
|
|
124
|
-
nextHTMLStructor += text.substring(endOffset, text.length);
|
|
125
|
-
} else {
|
|
126
|
-
const childClassList = [...child.classList];
|
|
127
|
-
const originTag = getTagName(child);
|
|
128
|
-
nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
editableElement.innerHTML = preHTMLStructor;
|
|
135
|
-
editableElement.insertAdjacentHTML("afterend", `<li class="d-li-item ${editableElementClassList.join(" ")}">${nextHTMLStructor}</li>`);
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
setCursor(editableElement.nextSibling.childNodes[0], 0);
|
|
138
|
-
update();
|
|
139
|
-
}, 100);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function textEnterEvent(action) {
|
|
144
|
-
const cursorData = getCursor();
|
|
145
|
-
if (cursorData.startNode) {
|
|
146
|
-
const editableElement = findEditableElement(cursorData.startNode);
|
|
147
|
-
const editableElementClassList = [...editableElement.classList].slice(0, 1);
|
|
148
|
-
const startNode = cursorData.startNode;
|
|
149
|
-
const endNode = cursorData.endNode;
|
|
150
|
-
let startChild = startNode;
|
|
151
|
-
let endChild = endNode;
|
|
152
|
-
if (startNode.parentNode !== editableElement) {
|
|
153
|
-
startChild = startNode.parentNode;
|
|
154
|
-
}
|
|
155
|
-
if (endNode.parentNode !== editableElement) {
|
|
156
|
-
endChild = endNode.parentNode;
|
|
157
|
-
}
|
|
158
|
-
const startChildIdx = findChildNumber(editableElement, startChild);
|
|
159
|
-
const endChildIdx = findChildNumber(editableElement, endChild);
|
|
160
|
-
let startIdx = 0;
|
|
161
|
-
let endIdx = 0;
|
|
162
|
-
let startOffset = 0;
|
|
163
|
-
let endOffset = 0;
|
|
164
|
-
let preHTMLStructor = "";
|
|
165
|
-
let nextHTMLStructor = "";
|
|
166
|
-
if (startChildIdx > endChildIdx) {
|
|
167
|
-
startIdx = endChildIdx;
|
|
168
|
-
endIdx = startChildIdx;
|
|
169
|
-
startOffset = cursorData.endOffset;
|
|
170
|
-
endOffset = cursorData.startOffset;
|
|
171
|
-
} else {
|
|
172
|
-
startIdx = startChildIdx;
|
|
173
|
-
endIdx = endChildIdx;
|
|
174
|
-
startOffset = cursorData.startOffset;
|
|
175
|
-
endOffset = cursorData.endOffset;
|
|
176
|
-
}
|
|
177
|
-
if (editableElement.childNodes.length === 0 || endChildIdx === editableElement.childNodes.length - 1 && editableElement.childNodes[endChildIdx].textContent.length === endOffset) {
|
|
178
|
-
action("addBlock", {
|
|
179
|
-
name: "text"
|
|
180
|
-
});
|
|
181
|
-
} else {
|
|
182
|
-
editableElement.childNodes.forEach((child, count) => {
|
|
183
|
-
const text = child.textContent;
|
|
184
|
-
if (count < startChildIdx) {
|
|
185
|
-
if (child.constructor.name === "Text") {
|
|
186
|
-
preHTMLStructor += child.textContent;
|
|
187
|
-
} else {
|
|
188
|
-
preHTMLStructor += child.outerHTML;
|
|
189
|
-
}
|
|
190
|
-
} else if (count > endChildIdx) {
|
|
191
|
-
if (child.constructor.name === "Text") {
|
|
192
|
-
nextHTMLStructor += child.textContent;
|
|
193
|
-
} else {
|
|
194
|
-
nextHTMLStructor += child.outerHTML;
|
|
195
|
-
}
|
|
196
|
-
} else {
|
|
197
|
-
if (startChildIdx === endChildIdx) {
|
|
198
|
-
if (child.constructor.name === "Text") {
|
|
199
|
-
preHTMLStructor += text.substring(0, startOffset);
|
|
200
|
-
nextHTMLStructor += text.substring(endOffset, text.length);
|
|
201
|
-
} else {
|
|
202
|
-
const childClassList = [...child.classList];
|
|
203
|
-
const originTag = getTagName(child);
|
|
204
|
-
preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
|
|
205
|
-
nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
|
|
206
|
-
}
|
|
207
|
-
} else {
|
|
208
|
-
if (count === startChildIdx) {
|
|
209
|
-
if (child.constructor.name === "Text") {
|
|
210
|
-
preHTMLStructor += text.substring(0, startOffset);
|
|
211
|
-
} else {
|
|
212
|
-
const childClassList = [...child.classList];
|
|
213
|
-
const originTag = getTagName(child);
|
|
214
|
-
preHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${originTag.name}>`;
|
|
215
|
-
}
|
|
216
|
-
} else if (count === endChildIdx) {
|
|
217
|
-
if (child.constructor.name === "Text") {
|
|
218
|
-
nextHTMLStructor += text.substring(endOffset, text.length);
|
|
219
|
-
} else {
|
|
220
|
-
const childClassList = [...child.classList];
|
|
221
|
-
const originTag = getTagName(child);
|
|
222
|
-
nextHTMLStructor += `<${originTag.name} ${originTag.href ? `href="${originTag.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${originTag.name}>`;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
editableElement.innerHTML = preHTMLStructor;
|
|
229
|
-
action("addBlock", {
|
|
230
|
-
name: "text",
|
|
231
|
-
value: { classList: editableElementClassList, content: nextHTMLStructor }
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function backspaceEvent(type, event, action, update) {
|
|
237
|
-
if (event.code === "Backspace") {
|
|
238
|
-
if (type === "text") {
|
|
239
|
-
const cursorData = getCursor();
|
|
240
|
-
if (cursorData.type === "Caret" && cursorData.startOffset === 0) {
|
|
241
|
-
const editableElement = findEditableElement(cursorData.startNode);
|
|
242
|
-
let $target = cursorData.startNode;
|
|
243
|
-
if ($target.constructor.name === "Text") {
|
|
244
|
-
$target = $target.parentNode;
|
|
245
|
-
}
|
|
246
|
-
if ($target === editableElement) {
|
|
247
|
-
update();
|
|
248
|
-
event.preventDefault();
|
|
249
|
-
action("deleteBlockLocal");
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
export function keyboardEvent(type, event, action, update) {
|
|
256
|
-
enterEvent(type, event, action, update);
|
|
257
|
-
backspaceEvent(type, event, action, update);
|
|
258
|
-
}
|
|
259
|
-
export function getClipboardData(data) {
|
|
260
|
-
let type, clipboardData;
|
|
261
|
-
if (!data) {
|
|
262
|
-
type = null;
|
|
263
|
-
}
|
|
264
|
-
const items = data.items;
|
|
265
|
-
if (items === void 0) {
|
|
266
|
-
type = null;
|
|
267
|
-
}
|
|
268
|
-
const count = items.length;
|
|
269
|
-
for (let i = 0; i < count; i += 1) {
|
|
270
|
-
if (items[i].type.indexOf("image") === 0) {
|
|
271
|
-
type = "image";
|
|
272
|
-
clipboardData = items[i].getAsFile();
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
type = "text";
|
|
276
|
-
}
|
|
277
|
-
if (type === "text") {
|
|
278
|
-
clipboardData = data.getData("text");
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
type,
|
|
282
|
-
value: clipboardData
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
export function pasteText(type, value) {
|
|
286
|
-
const selection = window.getSelection();
|
|
287
|
-
const range = document.createRange();
|
|
288
|
-
let textNode;
|
|
289
|
-
if (type !== "codeBlock") {
|
|
290
|
-
textNode = document.createTextNode(value.replace("\n", "").replace(/ +/g, " "));
|
|
291
|
-
} else {
|
|
292
|
-
textNode = document.createTextNode(value);
|
|
293
|
-
}
|
|
294
|
-
selection.deleteFromDocument();
|
|
295
|
-
selection.getRangeAt(0).insertNode(textNode);
|
|
296
|
-
range.setStart(textNode, textNode.length);
|
|
297
|
-
range.collapse(true);
|
|
298
|
-
selection.removeAllRanges();
|
|
299
|
-
selection.addRange(range);
|
|
300
|
-
}
|
|
301
|
-
function addBrEvent() {
|
|
302
|
-
const cursorData = getCursor();
|
|
303
|
-
if (cursorData.startNode) {
|
|
304
|
-
let $target = cursorData.startNode;
|
|
305
|
-
const preEditableElement = findEditableElement($target);
|
|
306
|
-
if ($target.constructor.name === "Text") {
|
|
307
|
-
$target = $target.parentNode;
|
|
308
|
-
}
|
|
309
|
-
if (preEditableElement !== $target && $target.constructor.name !== "HTMLBRElement") {
|
|
310
|
-
let startNode = cursorData.startNode;
|
|
311
|
-
let endNode = cursorData.endNode;
|
|
312
|
-
let startChild = startNode;
|
|
313
|
-
let endChild = endNode;
|
|
314
|
-
if (startNode.parentNode !== preEditableElement) {
|
|
315
|
-
startChild = startNode.parentNode;
|
|
316
|
-
}
|
|
317
|
-
if (endNode.parentNode !== preEditableElement) {
|
|
318
|
-
endChild = endNode.parentNode;
|
|
319
|
-
}
|
|
320
|
-
const startChildIdx = findChildNumber(preEditableElement, startChild);
|
|
321
|
-
const endChildIdx = findChildNumber(preEditableElement, endChild);
|
|
322
|
-
let startIdx = 0;
|
|
323
|
-
let endIdx = 0;
|
|
324
|
-
let startOffset = 0;
|
|
325
|
-
let endOffset = 0;
|
|
326
|
-
let htmlStructure = "";
|
|
327
|
-
if (startChildIdx > endChildIdx) {
|
|
328
|
-
startIdx = endChildIdx;
|
|
329
|
-
endIdx = startChildIdx;
|
|
330
|
-
startOffset = cursorData.endOffset;
|
|
331
|
-
endOffset = cursorData.startOffset;
|
|
332
|
-
} else {
|
|
333
|
-
startIdx = startChildIdx;
|
|
334
|
-
endIdx = endChildIdx;
|
|
335
|
-
startOffset = cursorData.startOffset;
|
|
336
|
-
endOffset = cursorData.endOffset;
|
|
337
|
-
}
|
|
338
|
-
if (enterCount === 1) {
|
|
339
|
-
const text = startChild.textContent;
|
|
340
|
-
startChild.textContent = text.substring(1, text.length);
|
|
341
|
-
setCursor(startChild, 0);
|
|
342
|
-
} else {
|
|
343
|
-
if (startNode === endNode) {
|
|
344
|
-
const text = startChild.textContent;
|
|
345
|
-
const childClassList = [...startChild.classList];
|
|
346
|
-
const tagData = getTagName(startChild);
|
|
347
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}>`;
|
|
348
|
-
htmlStructure += `<br>`;
|
|
349
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}>`;
|
|
350
|
-
startChild.insertAdjacentHTML("beforebegin", htmlStructure);
|
|
351
|
-
setCursor(preEditableElement.childNodes[startChildIdx + 2], 0);
|
|
352
|
-
startChild.remove();
|
|
353
|
-
} else {
|
|
354
|
-
preEditableElement.childNodes.forEach((child, count) => {
|
|
355
|
-
const type = child.constructor.name;
|
|
356
|
-
const text = child.textContent;
|
|
357
|
-
if (count > startIdx && count < endIdx) {
|
|
358
|
-
} else if (count === startIdx) {
|
|
359
|
-
if (type === "Text") {
|
|
360
|
-
htmlStructure += text.substring(0, startOffset);
|
|
361
|
-
} else {
|
|
362
|
-
const childClassList = [...child.classList];
|
|
363
|
-
const tagData = getTagName(child);
|
|
364
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}><br>`;
|
|
365
|
-
}
|
|
366
|
-
} else if (count === endIdx) {
|
|
367
|
-
if (type === "Text") {
|
|
368
|
-
htmlStructure += text.substring(endOffset, text.length);
|
|
369
|
-
} else {
|
|
370
|
-
const childClassList = [...child.classList];
|
|
371
|
-
const tagData = getTagName(child);
|
|
372
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}><br>`;
|
|
373
|
-
}
|
|
374
|
-
} else {
|
|
375
|
-
if (type === "Text") {
|
|
376
|
-
htmlStructure += child.textContent;
|
|
377
|
-
} else {
|
|
378
|
-
htmlStructure += child.outerHTML;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
preEditableElement.innerHTML = htmlStructure;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
} else {
|
|
386
|
-
const brTag = document.createElement("br");
|
|
387
|
-
const selection = window.getSelection();
|
|
388
|
-
const range = document.createRange();
|
|
389
|
-
if (enterCount === 1) {
|
|
390
|
-
const nextCursorData = getCursor();
|
|
391
|
-
const editableElement = findEditableElement(nextCursorData.startNode);
|
|
392
|
-
const childList = editableElement.childNodes;
|
|
393
|
-
const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
|
|
394
|
-
setCursor(childList[childIdx + 2], 0);
|
|
395
|
-
} else {
|
|
396
|
-
selection.deleteFromDocument();
|
|
397
|
-
selection.getRangeAt(0).insertNode(brTag);
|
|
398
|
-
range.setStart(brTag, 0);
|
|
399
|
-
range.collapse(true);
|
|
400
|
-
selection.removeAllRanges();
|
|
401
|
-
selection.addRange(range);
|
|
402
|
-
const nextCursorData = getCursor();
|
|
403
|
-
const editableElement = findEditableElement(nextCursorData.startNode);
|
|
404
|
-
const childList = editableElement.childNodes;
|
|
405
|
-
const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
|
|
406
|
-
let hasText = false;
|
|
407
|
-
childList.forEach((row) => {
|
|
408
|
-
if (row.constructor.name === "Text") {
|
|
409
|
-
hasText = true;
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
if (hasText) {
|
|
413
|
-
if (childList[childIdx + 1].textContent?.length === 0) {
|
|
414
|
-
if (childList[childIdx + 2]) {
|
|
415
|
-
if (childList[childIdx + 2].constructor.name == "HTMLBRElement") {
|
|
416
|
-
setCursor(childList[childIdx + 1], 0);
|
|
417
|
-
} else {
|
|
418
|
-
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
419
|
-
}
|
|
420
|
-
} else {
|
|
421
|
-
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
422
|
-
}
|
|
423
|
-
} else {
|
|
424
|
-
setCursor(childList[childIdx + 1], 0);
|
|
425
|
-
}
|
|
426
|
-
} else {
|
|
427
|
-
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
function addBrEventWithList() {
|
|
434
|
-
const cursorData = getCursor();
|
|
435
|
-
if (cursorData.startNode) {
|
|
436
|
-
let $target = cursorData.startNode;
|
|
437
|
-
const preEditableElement = findLiElement($target);
|
|
438
|
-
if ($target.constructor.name === "Text") {
|
|
439
|
-
$target = $target.parentNode;
|
|
440
|
-
}
|
|
441
|
-
if (preEditableElement !== $target && $target.constructor.name !== "HTMLBRElement") {
|
|
442
|
-
let startNode = cursorData.startNode;
|
|
443
|
-
let endNode = cursorData.endNode;
|
|
444
|
-
let startChild = startNode;
|
|
445
|
-
let endChild = endNode;
|
|
446
|
-
if (startNode.parentNode !== preEditableElement) {
|
|
447
|
-
startChild = startNode.parentNode;
|
|
448
|
-
}
|
|
449
|
-
if (endNode.parentNode !== preEditableElement) {
|
|
450
|
-
endChild = endNode.parentNode;
|
|
451
|
-
}
|
|
452
|
-
const startChildIdx = findChildNumber(preEditableElement, startChild);
|
|
453
|
-
const endChildIdx = findChildNumber(preEditableElement, endChild);
|
|
454
|
-
let startIdx = 0;
|
|
455
|
-
let endIdx = 0;
|
|
456
|
-
let startOffset = 0;
|
|
457
|
-
let endOffset = 0;
|
|
458
|
-
let htmlStructure = "";
|
|
459
|
-
if (startChildIdx > endChildIdx) {
|
|
460
|
-
startIdx = endChildIdx;
|
|
461
|
-
endIdx = startChildIdx;
|
|
462
|
-
startOffset = cursorData.endOffset;
|
|
463
|
-
endOffset = cursorData.startOffset;
|
|
464
|
-
} else {
|
|
465
|
-
startIdx = startChildIdx;
|
|
466
|
-
endIdx = endChildIdx;
|
|
467
|
-
startOffset = cursorData.startOffset;
|
|
468
|
-
endOffset = cursorData.endOffset;
|
|
469
|
-
}
|
|
470
|
-
if (enterCount === 1) {
|
|
471
|
-
const text = startChild.textContent;
|
|
472
|
-
startChild.textContent = text.substring(1, text.length);
|
|
473
|
-
setCursor(startChild, 0);
|
|
474
|
-
} else {
|
|
475
|
-
if (startNode === endNode) {
|
|
476
|
-
const text = startChild.textContent;
|
|
477
|
-
const childClassList = [...startChild.classList];
|
|
478
|
-
const tagData = getTagName(startChild);
|
|
479
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}>`;
|
|
480
|
-
htmlStructure += `<br>`;
|
|
481
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}>`;
|
|
482
|
-
startChild.insertAdjacentHTML("beforebegin", htmlStructure);
|
|
483
|
-
setCursor(preEditableElement.childNodes[startChildIdx + 2], 0);
|
|
484
|
-
startChild.remove();
|
|
485
|
-
} else {
|
|
486
|
-
preEditableElement.childNodes.forEach((child, count) => {
|
|
487
|
-
const type = child.constructor.name;
|
|
488
|
-
const text = child.textContent;
|
|
489
|
-
if (count > startIdx && count < endIdx) {
|
|
490
|
-
} else if (count === startIdx) {
|
|
491
|
-
if (type === "Text") {
|
|
492
|
-
htmlStructure += text.substring(0, startOffset);
|
|
493
|
-
} else {
|
|
494
|
-
const childClassList = [...child.classList];
|
|
495
|
-
const tagData = getTagName(child);
|
|
496
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(0, startOffset)}</${tagData.name}><br>`;
|
|
497
|
-
}
|
|
498
|
-
} else if (count === endIdx) {
|
|
499
|
-
if (type === "Text") {
|
|
500
|
-
htmlStructure += text.substring(endOffset, text.length);
|
|
501
|
-
} else {
|
|
502
|
-
const childClassList = [...child.classList];
|
|
503
|
-
const tagData = getTagName(child);
|
|
504
|
-
htmlStructure += `<${tagData.name} ${tagData.href ? `href="${tagData.href}" rel="nofollow"` : ""} class="${childClassList.join(" ")}">${text.substring(endOffset, text.length)}</${tagData.name}><br>`;
|
|
505
|
-
}
|
|
506
|
-
} else {
|
|
507
|
-
if (type === "Text") {
|
|
508
|
-
htmlStructure += child.textContent;
|
|
509
|
-
} else {
|
|
510
|
-
htmlStructure += child.outerHTML;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
preEditableElement.innerHTML = htmlStructure;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
} else {
|
|
518
|
-
const brTag = document.createElement("br");
|
|
519
|
-
const selection = window.getSelection();
|
|
520
|
-
const range = document.createRange();
|
|
521
|
-
console.log("br");
|
|
522
|
-
if (enterCount === 1) {
|
|
523
|
-
const nextCursorData = getCursor();
|
|
524
|
-
const editableElement = findEditableElement(nextCursorData.startNode);
|
|
525
|
-
const childList = editableElement.childNodes;
|
|
526
|
-
const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
|
|
527
|
-
setCursor(childList[childIdx + 2], 0);
|
|
528
|
-
} else {
|
|
529
|
-
selection.deleteFromDocument();
|
|
530
|
-
selection.getRangeAt(0).insertNode(brTag);
|
|
531
|
-
range.setStart(brTag, 0);
|
|
532
|
-
range.collapse(true);
|
|
533
|
-
selection.removeAllRanges();
|
|
534
|
-
selection.addRange(range);
|
|
535
|
-
const nextCursorData = getCursor();
|
|
536
|
-
const editableElement = findEditableElement(nextCursorData.startNode);
|
|
537
|
-
const childList = editableElement.childNodes;
|
|
538
|
-
const childIdx = findChildNumber(editableElement, nextCursorData.startNode);
|
|
539
|
-
let hasText = false;
|
|
540
|
-
childList.forEach((row) => {
|
|
541
|
-
if (row.constructor.name === "Text") {
|
|
542
|
-
hasText = true;
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
if (hasText) {
|
|
546
|
-
if (childList[childIdx + 1].textContent?.length === 0) {
|
|
547
|
-
if (childList[childIdx + 2]) {
|
|
548
|
-
if (childList[childIdx + 2].constructor.name == "HTMLBRElement") {
|
|
549
|
-
setCursor(childList[childIdx + 1], 0);
|
|
550
|
-
} else {
|
|
551
|
-
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
552
|
-
}
|
|
553
|
-
} else {
|
|
554
|
-
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
555
|
-
}
|
|
556
|
-
} else {
|
|
557
|
-
setCursor(childList[childIdx + 1], 0);
|
|
558
|
-
}
|
|
559
|
-
} else {
|
|
560
|
-
childList[childIdx].insertAdjacentHTML("beforebegin", "<br>");
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
};
|