dragon-editor 2.0.0-beta.1.4 → 2.0.0-beta.2.1

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