dragon-editor 3.8.7 → 4.0.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 (91) hide show
  1. package/README.md +10 -9
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +9 -7
  4. package/dist/runtime/components/Block/Code.d.vue.ts +13 -0
  5. package/dist/runtime/components/Block/Code.vue +193 -0
  6. package/dist/runtime/components/Block/Code.vue.d.ts +13 -0
  7. package/dist/runtime/components/Block/Custom.d.vue.ts +9 -0
  8. package/dist/runtime/components/Block/Custom.vue +28 -0
  9. package/dist/runtime/components/Block/Custom.vue.d.ts +9 -0
  10. package/dist/runtime/components/Block/Divider.d.vue.ts +9 -0
  11. package/dist/runtime/components/Block/Divider.vue +27 -0
  12. package/dist/runtime/components/Block/Divider.vue.d.ts +9 -0
  13. package/dist/runtime/components/Block/Heading.d.vue.ts +13 -0
  14. package/dist/runtime/components/Block/Heading.vue +84 -0
  15. package/dist/runtime/components/Block/Heading.vue.d.ts +13 -0
  16. package/dist/runtime/components/Block/Image.d.vue.ts +13 -0
  17. package/dist/runtime/components/Block/Image.vue +146 -0
  18. package/dist/runtime/components/Block/Image.vue.d.ts +13 -0
  19. package/dist/runtime/components/Block/List.d.vue.ts +13 -0
  20. package/dist/runtime/components/Block/List.vue +170 -0
  21. package/dist/runtime/components/Block/List.vue.d.ts +13 -0
  22. package/dist/runtime/components/Block/Text.d.vue.ts +13 -0
  23. package/dist/runtime/components/Block/Text.vue +84 -0
  24. package/dist/runtime/components/Block/Text.vue.d.ts +13 -0
  25. package/dist/runtime/components/DragonEditor.d.vue.ts +27 -22
  26. package/dist/runtime/components/DragonEditor.vue +311 -474
  27. package/dist/runtime/components/DragonEditor.vue.d.ts +27 -22
  28. package/dist/runtime/components/DragonEditorViewer.d.vue.ts +12 -5
  29. package/dist/runtime/components/DragonEditorViewer.vue +200 -227
  30. package/dist/runtime/components/DragonEditorViewer.vue.d.ts +12 -5
  31. package/dist/runtime/components/MenuBar.d.vue.ts +3 -0
  32. package/dist/runtime/components/MenuBar.vue +385 -0
  33. package/dist/runtime/components/MenuBar.vue.d.ts +3 -0
  34. package/dist/runtime/scss/editor.css +237 -283
  35. package/dist/runtime/scss/viewer.css +184 -210
  36. package/dist/runtime/store/editor.d.ts +2 -0
  37. package/dist/runtime/store/editor.js +59 -0
  38. package/dist/runtime/type.d.mts +101 -124
  39. package/dist/runtime/utils/data/block.d.ts +20 -0
  40. package/dist/runtime/utils/data/block.js +663 -0
  41. package/dist/runtime/utils/data/cursor.d.ts +9 -0
  42. package/dist/runtime/utils/data/cursor.js +137 -0
  43. package/dist/runtime/utils/data/index.d.ts +5 -0
  44. package/dist/runtime/utils/data/index.js +17 -0
  45. package/dist/runtime/utils/data/node.d.ts +9 -0
  46. package/dist/runtime/utils/data/node.js +101 -0
  47. package/dist/runtime/utils/event/cursor.d.ts +3 -6
  48. package/dist/runtime/utils/event/cursor.js +52 -105
  49. package/dist/runtime/utils/event/index.d.ts +2 -6
  50. package/dist/runtime/utils/event/index.js +48 -6
  51. package/dist/runtime/utils/event/keyboard.d.ts +22 -7
  52. package/dist/runtime/utils/event/keyboard.js +910 -1406
  53. package/dist/runtime/utils/layout/body.d.ts +3 -4
  54. package/dist/runtime/utils/layout/body.js +83 -51
  55. package/dist/runtime/utils/layout/icon.d.ts +1 -2
  56. package/dist/runtime/utils/layout/icon.js +64 -67
  57. package/dist/runtime/utils/layout/index.d.ts +0 -3
  58. package/dist/runtime/utils/layout/index.js +0 -3
  59. package/dist/runtime/utils/node/element.d.ts +4 -6
  60. package/dist/runtime/utils/node/element.js +58 -71
  61. package/dist/runtime/utils/node/index.d.ts +1 -1
  62. package/dist/runtime/utils/node/index.js +1 -1
  63. package/dist/runtime/utils/node/style.d.ts +5 -0
  64. package/dist/runtime/utils/node/style.js +702 -0
  65. package/package.json +32 -18
  66. package/dist/runtime/utils/event/block.d.ts +0 -7
  67. package/dist/runtime/utils/event/block.js +0 -110
  68. package/dist/runtime/utils/event/data.d.ts +0 -8
  69. package/dist/runtime/utils/event/data.js +0 -379
  70. package/dist/runtime/utils/event/mouse.d.ts +0 -11
  71. package/dist/runtime/utils/event/mouse.js +0 -85
  72. package/dist/runtime/utils/event/scroll.d.ts +0 -3
  73. package/dist/runtime/utils/event/scroll.js +0 -29
  74. package/dist/runtime/utils/event/touch.d.ts +0 -5
  75. package/dist/runtime/utils/event/touch.js +0 -10
  76. package/dist/runtime/utils/event/window.d.ts +0 -5
  77. package/dist/runtime/utils/event/window.js +0 -47
  78. package/dist/runtime/utils/layout/block.d.ts +0 -7
  79. package/dist/runtime/utils/layout/block.js +0 -123
  80. package/dist/runtime/utils/layout/controlbar.d.ts +0 -3
  81. package/dist/runtime/utils/layout/controlbar.js +0 -99
  82. package/dist/runtime/utils/layout/menuBar.d.ts +0 -3
  83. package/dist/runtime/utils/layout/menuBar.js +0 -408
  84. package/dist/runtime/utils/node/block.d.ts +0 -19
  85. package/dist/runtime/utils/node/block.js +0 -256
  86. package/dist/runtime/utils/style/anchor.d.ts +0 -5
  87. package/dist/runtime/utils/style/anchor.js +0 -245
  88. package/dist/runtime/utils/style/decoration.d.ts +0 -4
  89. package/dist/runtime/utils/style/decoration.js +0 -378
  90. package/dist/runtime/utils/style/index.d.ts +0 -2
  91. package/dist/runtime/utils/style/index.js +0 -2
@@ -0,0 +1,702 @@
1
+ import { nextTick } from "#imports";
2
+ import { useEditorStore } from "../../store/editor.js";
3
+ import { _findEditableElement, _findEditableParent, _findParentBlock } from "./index.js";
4
+ import { _arrangementNodeList, _getEditorbleCursorPosition } from "../data/index.js";
5
+ import { _setCursorPosition, _setRangeCursorPosition, _updateCursorData } from "../event/index.js";
6
+ export async function _setAlign(style) {
7
+ const editorStore = useEditorStore();
8
+ const newData = JSON.parse(JSON.stringify(editorStore.data));
9
+ const blockData = newData[editorStore.selectedBlockIndex];
10
+ if (blockData !== void 0 && editorStore.fn.updateEditorData !== null && editorStore.cursorSelection !== null && editorStore.element.body !== null) {
11
+ let className = "";
12
+ const $editableElement = _findEditableParent(editorStore.cursorSelection.anchorNode);
13
+ if ($editableElement !== null) {
14
+ const offset = _getEditorbleCursorPosition($editableElement);
15
+ const classList = ["de-align-left", "de-align-right", "de-align-center", "de-align-justify"];
16
+ switch (style) {
17
+ case "left":
18
+ className = "de-align-left";
19
+ break;
20
+ case "right":
21
+ className = "de-align-right";
22
+ break;
23
+ case "center":
24
+ className = "de-align-center";
25
+ break;
26
+ case "justify":
27
+ className = "de-align-justify";
28
+ break;
29
+ }
30
+ if (blockData.type === "list") {
31
+ const $block = _findParentBlock($editableElement);
32
+ if ($block !== null) {
33
+ const $childList = $block.querySelectorAll(".de-item-text");
34
+ let childIndex = -1;
35
+ for (let i = 0; i < $childList.length; i += 1) {
36
+ const $child = $childList[i];
37
+ if ($child === $editableElement) {
38
+ childIndex = i;
39
+ break;
40
+ }
41
+ }
42
+ const curruntChildData = blockData.child[childIndex];
43
+ if (curruntChildData !== void 0) {
44
+ classList.forEach((name) => {
45
+ if (name !== className) {
46
+ const index = curruntChildData.classList.indexOf(name);
47
+ if (index !== -1) {
48
+ curruntChildData.classList.splice(index, 1);
49
+ }
50
+ }
51
+ });
52
+ const classIndex = curruntChildData.classList.indexOf(className);
53
+ if (classIndex === -1) {
54
+ curruntChildData.classList.push(className);
55
+ } else {
56
+ curruntChildData.classList.splice(classIndex, 1);
57
+ }
58
+ blockData.child[childIndex] = curruntChildData;
59
+ newData[editorStore.selectedBlockIndex] = blockData;
60
+ editorStore.fn.updateEditorData(newData);
61
+ await nextTick();
62
+ const $textArea = $block.querySelectorAll(".de-item-text");
63
+ const $targetTextArea = $textArea[childIndex];
64
+ if ($targetTextArea !== void 0) {
65
+ const $node = $targetTextArea.childNodes[offset.nodeIndex];
66
+ $targetTextArea.dispatchEvent(new Event("blur"));
67
+ if ($node !== void 0) {
68
+ _setCursorPosition($node, offset.offset);
69
+ } else {
70
+ _setCursorPosition($targetTextArea, 0);
71
+ }
72
+ }
73
+ }
74
+ }
75
+ } else {
76
+ classList.forEach((name) => {
77
+ if (name !== className) {
78
+ const index = blockData.classList.indexOf(name);
79
+ if (index !== -1) {
80
+ blockData.classList.splice(index, 1);
81
+ }
82
+ }
83
+ });
84
+ const classIndex = blockData.classList.indexOf(className);
85
+ if (classIndex === -1) {
86
+ blockData.classList.push(className);
87
+ } else {
88
+ blockData.classList.splice(classIndex, 1);
89
+ }
90
+ editorStore.selectedBlockId = "";
91
+ newData[editorStore.selectedBlockIndex] = blockData;
92
+ editorStore.fn.updateEditorData(newData);
93
+ await nextTick();
94
+ const $block = editorStore.element.body.children[editorStore.selectedBlockIndex];
95
+ if ($block !== void 0) {
96
+ if (blockData.type === "image") {
97
+ const $editableElement2 = _findEditableElement($block, "down");
98
+ if ($editableElement2 !== null) {
99
+ const $node = $editableElement2.childNodes[offset.nodeIndex];
100
+ if ($node !== void 0) {
101
+ $node.dispatchEvent(new Event("input"));
102
+ _setCursorPosition($node, offset.offset);
103
+ } else {
104
+ _setCursorPosition($editableElement2, offset.offset);
105
+ }
106
+ }
107
+ } else {
108
+ const $node = $block.childNodes[offset.nodeIndex];
109
+ if ($node !== void 0) {
110
+ $block.dispatchEvent(new Event("input"));
111
+ _setCursorPosition($node, offset.offset);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ export async function _setDecoration(className) {
120
+ const editorStore = useEditorStore();
121
+ if (editorStore.cursorRange !== null) {
122
+ const cloneRange = editorStore.cursorRange.cloneRange();
123
+ const $editableParent = _findEditableParent(cloneRange.startContainer.nodeType === Node.TEXT_NODE ? cloneRange.startContainer.parentElement : cloneRange.startContainer);
124
+ if ($editableParent !== null) {
125
+ const nodeList = [];
126
+ let selectedAll = false;
127
+ let cursorStartNode = null;
128
+ let cursorStartNodeOffset = 0;
129
+ let cursorEndNode = null;
130
+ let cursorEndNodeOffset = 0;
131
+ if (cloneRange.collapsed === true) {
132
+ $editableParent.childNodes.forEach((node) => {
133
+ if (cloneRange.startContainer.parentElement === $editableParent) {
134
+ if (node.nodeType === Node.TEXT_NODE) {
135
+ const styleNode = document.createElement("span");
136
+ styleNode.className = className;
137
+ styleNode.textContent = node.textContent;
138
+ nodeList.push(styleNode);
139
+ } else {
140
+ const $span = node;
141
+ $span.classList.add(className);
142
+ nodeList.push($span);
143
+ }
144
+ selectedAll = true;
145
+ } else {
146
+ const $span = node;
147
+ if (cloneRange.startContainer.parentElement === $span) {
148
+ if ($span.classList.contains(className) === true) {
149
+ $span.classList.remove(className);
150
+ } else {
151
+ $span.classList.add(className);
152
+ }
153
+ if ($span.className === "") {
154
+ const textNode = document.createTextNode($span.textContent || "");
155
+ nodeList.push(textNode);
156
+ cursorStartNode = textNode;
157
+ cursorStartNodeOffset = 0;
158
+ cursorEndNode = textNode;
159
+ cursorEndNodeOffset = textNode.textContent.length;
160
+ } else {
161
+ nodeList.push($span);
162
+ cursorStartNode = $span.childNodes[0] || null;
163
+ cursorStartNodeOffset = 0;
164
+ cursorEndNode = $span.childNodes[0] || null;
165
+ cursorEndNodeOffset = $span.textContent.length;
166
+ }
167
+ } else {
168
+ nodeList.push(node);
169
+ }
170
+ }
171
+ });
172
+ } else {
173
+ let isBettween = false;
174
+ $editableParent.childNodes.forEach((node) => {
175
+ if (cloneRange.startContainer === cloneRange.endContainer) {
176
+ if (cloneRange.startContainer.parentElement === $editableParent) {
177
+ let textNode = node;
178
+ if (node.nodeType !== Node.TEXT_NODE) {
179
+ if (node.textContent === "") {
180
+ textNode = null;
181
+ } else {
182
+ textNode = node.childNodes[0] || null;
183
+ }
184
+ }
185
+ if (textNode !== null && textNode === cloneRange.startContainer) {
186
+ const text = textNode.textContent;
187
+ if (text !== null) {
188
+ const $firstNode = document.createTextNode(text.substring(0, cloneRange.startOffset));
189
+ const $middleNode = document.createElement("span");
190
+ const $lastNode = document.createTextNode(text.substring(cloneRange.endOffset, text.length));
191
+ $middleNode.className = className;
192
+ $middleNode.textContent = text.substring(cloneRange.startOffset, cloneRange.endOffset);
193
+ nodeList.push($firstNode, $middleNode, $lastNode);
194
+ cursorStartNode = $middleNode.childNodes[0] || null;
195
+ cursorStartNodeOffset = 0;
196
+ cursorEndNode = $middleNode.childNodes[0] || null;
197
+ cursorEndNodeOffset = $middleNode.textContent.length;
198
+ }
199
+ } else {
200
+ nodeList.push(node);
201
+ }
202
+ } else {
203
+ if (cloneRange.startContainer.parentElement === node) {
204
+ const $span = node;
205
+ if (cloneRange.startOffset === 0 && cloneRange.endOffset === (node.textContent || "").length) {
206
+ if ($span.classList.contains(className) === true) {
207
+ $span.classList.remove(className);
208
+ } else {
209
+ $span.classList.add(className);
210
+ }
211
+ if ($span.className === "") {
212
+ const textNode = document.createTextNode($span.textContent || "");
213
+ nodeList.push(textNode);
214
+ cursorStartNode = textNode;
215
+ cursorStartNodeOffset = 0;
216
+ cursorEndNode = textNode;
217
+ cursorEndNodeOffset = textNode.textContent.length;
218
+ } else {
219
+ nodeList.push($span);
220
+ cursorStartNode = $span.childNodes[0] || null;
221
+ cursorStartNodeOffset = 0;
222
+ cursorEndNode = $span.childNodes[0] || null;
223
+ cursorEndNodeOffset = $span.textContent.length;
224
+ }
225
+ } else {
226
+ const text = $span.textContent;
227
+ const $firstNode = $span.cloneNode();
228
+ const $middleNode = $span.cloneNode();
229
+ const $lastNode = $span.cloneNode();
230
+ $firstNode.textContent = text.substring(0, cloneRange.startOffset);
231
+ $middleNode.textContent = text.substring(cloneRange.startOffset, cloneRange.endOffset);
232
+ $lastNode.textContent = text.substring(cloneRange.endOffset, text.length);
233
+ if ($middleNode.classList.contains(className) === false) {
234
+ $middleNode.classList.add(className);
235
+ } else {
236
+ $middleNode.classList.remove(className);
237
+ }
238
+ nodeList.push($firstNode);
239
+ if ($middleNode.className === "") {
240
+ const textNode = document.createTextNode($middleNode.textContent || "");
241
+ nodeList.push(textNode);
242
+ cursorStartNode = textNode;
243
+ cursorStartNodeOffset = 0;
244
+ cursorEndNode = textNode;
245
+ cursorEndNodeOffset = textNode.textContent.length;
246
+ } else {
247
+ nodeList.push($middleNode);
248
+ cursorStartNode = $middleNode.childNodes[0] || null;
249
+ cursorStartNodeOffset = 0;
250
+ cursorEndNode = $middleNode.childNodes[0] || null;
251
+ cursorEndNodeOffset = $middleNode.textContent.length;
252
+ }
253
+ nodeList.push($lastNode);
254
+ }
255
+ } else {
256
+ nodeList.push(node);
257
+ }
258
+ }
259
+ } else {
260
+ if (cloneRange.startContainer === node || cloneRange.endContainer === node || cloneRange.startContainer.parentElement === node || cloneRange.endContainer.parentElement === node) {
261
+ const text = node.textContent;
262
+ if (text !== null) {
263
+ const textStartOffset = cloneRange.startOffset;
264
+ const textEndOffset = cloneRange.endOffset;
265
+ if (cloneRange.startContainer === node) {
266
+ const $span = document.createElement("span");
267
+ $span.className = className;
268
+ $span.textContent = text.substring(textStartOffset);
269
+ nodeList.push(document.createTextNode(text.substring(0, textStartOffset)));
270
+ nodeList.push($span);
271
+ cursorStartNode = $span.childNodes[0] || null;
272
+ cursorStartNodeOffset = 0;
273
+ isBettween = true;
274
+ }
275
+ if (cloneRange.startContainer.parentElement === node) {
276
+ const $span = node;
277
+ if ($span.classList.contains(className) === true) {
278
+ nodeList.push($span);
279
+ cursorStartNode = $span.childNodes[0] || null;
280
+ cursorStartNodeOffset = textStartOffset;
281
+ } else {
282
+ const $newSpan = $span.cloneNode();
283
+ $span.textContent = text.substring(0, textStartOffset);
284
+ $newSpan.textContent = text.substring(textStartOffset);
285
+ if ($newSpan.classList.contains(className) === false) {
286
+ $newSpan.classList.add(className);
287
+ }
288
+ nodeList.push($span);
289
+ nodeList.push($newSpan);
290
+ cursorStartNode = $newSpan.childNodes[0] || null;
291
+ cursorStartNodeOffset = 0;
292
+ }
293
+ isBettween = true;
294
+ }
295
+ if (cloneRange.endContainer === node) {
296
+ const $span = document.createElement("span");
297
+ $span.className = className;
298
+ $span.textContent = text.substring(0, textEndOffset);
299
+ nodeList.push($span);
300
+ nodeList.push(document.createTextNode(text.substring(textEndOffset)));
301
+ cursorEndNode = $span.childNodes[0] || null;
302
+ cursorEndNodeOffset = text.substring(0, textEndOffset).length;
303
+ isBettween = false;
304
+ }
305
+ if (cloneRange.endContainer.parentElement === node) {
306
+ const $span = node;
307
+ const $newSpan = $span.cloneNode();
308
+ if ($span.classList.contains(className) === true) {
309
+ nodeList.push($span);
310
+ cursorEndNode = $span.childNodes[0] || null;
311
+ cursorEndNodeOffset = textEndOffset;
312
+ } else {
313
+ $newSpan.textContent = text.substring(0, textEndOffset);
314
+ $span.textContent = text.substring(textEndOffset);
315
+ if ($newSpan.classList.contains(className) === false) {
316
+ $newSpan.classList.add(className);
317
+ }
318
+ nodeList.push($newSpan);
319
+ nodeList.push($span);
320
+ cursorEndNode = $newSpan.childNodes[0] || null;
321
+ cursorEndNodeOffset = text.substring(0, textEndOffset).length;
322
+ }
323
+ isBettween = false;
324
+ }
325
+ }
326
+ } else {
327
+ if (isBettween === false) {
328
+ nodeList.push(node);
329
+ } else {
330
+ if (node.nodeType === Node.TEXT_NODE) {
331
+ const $span = document.createElement("span");
332
+ $span.className = className;
333
+ $span.textContent = node.textContent || "";
334
+ nodeList.push($span);
335
+ } else {
336
+ const $span = node;
337
+ if ($span.classList.contains(className) === false) {
338
+ $span.classList.add(className);
339
+ }
340
+ nodeList.push($span);
341
+ }
342
+ }
343
+ }
344
+ }
345
+ });
346
+ }
347
+ $editableParent.innerHTML = "";
348
+ const { list: newList, cursorStartNode: StartNode, cursorStartNodeOffset: StartNodeOffset, cursorEndNode: EndNode, cursorEndNodeOffset: EndNodeOffset } = _arrangementNodeList(nodeList, cursorStartNode, cursorStartNodeOffset, cursorEndNode, cursorEndNodeOffset);
349
+ if (selectedAll === true) {
350
+ const targetStartNode = newList[0];
351
+ const targetEndNode = newList[newList.length - 1];
352
+ if (targetStartNode !== void 0) {
353
+ if (targetStartNode.nodeType === Node.TEXT_NODE) {
354
+ cursorStartNode = targetStartNode;
355
+ } else {
356
+ cursorStartNode = targetStartNode.childNodes[0] || null;
357
+ }
358
+ }
359
+ if (targetEndNode !== void 0) {
360
+ if (targetEndNode.nodeType === Node.TEXT_NODE) {
361
+ cursorEndNode = targetEndNode;
362
+ } else {
363
+ cursorEndNode = targetEndNode.childNodes[0] || null;
364
+ }
365
+ }
366
+ cursorStartNodeOffset = 0;
367
+ if (cursorEndNode !== null) {
368
+ cursorEndNodeOffset = cursorEndNode.textContent?.length || 0;
369
+ }
370
+ }
371
+ newList.forEach((node) => {
372
+ if (node.textContent !== "") {
373
+ $editableParent.appendChild(node);
374
+ }
375
+ });
376
+ $editableParent.dispatchEvent(new Event("input"));
377
+ await nextTick();
378
+ if (StartNode !== null && EndNode !== null) {
379
+ _setRangeCursorPosition(StartNode, StartNodeOffset, EndNode, EndNodeOffset);
380
+ _updateCursorData();
381
+ }
382
+ }
383
+ }
384
+ }
385
+ export async function _setLink(url) {
386
+ const editorStore = useEditorStore();
387
+ if (editorStore.cursorRange !== null && editorStore.cursorRange.collapsed === false) {
388
+ const $editableParent = _findEditableParent(editorStore.cursorRange.startContainer.nodeType === Node.TEXT_NODE ? editorStore.cursorRange.startContainer.parentElement : editorStore.cursorRange.startContainer);
389
+ if ($editableParent !== null) {
390
+ const cloneRange = editorStore.cursorRange.cloneRange();
391
+ const nodeList = [];
392
+ let cursorStartNode = null;
393
+ let cursorStartNodeOffset = 0;
394
+ let cursorEndNode = null;
395
+ let cursorEndNodeOffset = 0;
396
+ let isBettween = false;
397
+ $editableParent.childNodes.forEach((node) => {
398
+ if (cloneRange.startContainer === cloneRange.endContainer) {
399
+ if (cloneRange.startContainer.parentElement === $editableParent) {
400
+ let textNode = node;
401
+ if (node.nodeType !== Node.TEXT_NODE) {
402
+ if (node.textContent === "") {
403
+ textNode = null;
404
+ } else {
405
+ textNode = node.childNodes[0] || null;
406
+ }
407
+ }
408
+ if (textNode !== null && textNode === cloneRange.startContainer) {
409
+ const text = textNode.textContent;
410
+ if (text !== null) {
411
+ const $firstNode = document.createTextNode(text.substring(0, cloneRange.startOffset));
412
+ const $middleNode = document.createElement("a");
413
+ const $lastNode = document.createTextNode(text.substring(cloneRange.endOffset, text.length));
414
+ if (editorStore.option.anchorTagTarget !== "") {
415
+ $middleNode.target = editorStore.option.anchorTagTarget;
416
+ }
417
+ $middleNode.className = "de-link";
418
+ $middleNode.href = url;
419
+ $middleNode.textContent = text.substring(cloneRange.startOffset, cloneRange.endOffset);
420
+ nodeList.push($firstNode, $middleNode, $lastNode);
421
+ cursorStartNode = $middleNode.childNodes[0] || null;
422
+ cursorStartNodeOffset = 0;
423
+ cursorEndNode = $middleNode.childNodes[0] || null;
424
+ cursorEndNodeOffset = $middleNode.textContent.length;
425
+ }
426
+ } else {
427
+ nodeList.push(node);
428
+ }
429
+ } else {
430
+ if (cloneRange.startContainer.parentElement === node) {
431
+ const $span = node;
432
+ if (cloneRange.startOffset === 0 && cloneRange.endOffset === (node.textContent || "").length) {
433
+ const $aTag = document.createElement("a");
434
+ if (editorStore.option.anchorTagTarget !== "") {
435
+ $aTag.target = editorStore.option.anchorTagTarget;
436
+ }
437
+ $aTag.className = "de-link";
438
+ $aTag.href = url;
439
+ $aTag.textContent = $span.textContent;
440
+ nodeList.push($aTag);
441
+ cursorStartNode = $aTag.childNodes[0] || null;
442
+ cursorStartNodeOffset = 0;
443
+ cursorEndNode = $aTag.childNodes[0] || null;
444
+ cursorEndNodeOffset = $aTag.textContent.length;
445
+ } else {
446
+ const text = $span.textContent;
447
+ const $firstNode = $span.cloneNode();
448
+ const $middleNode = document.createElement("a");
449
+ const $lastNode = $span.cloneNode();
450
+ if (editorStore.option.anchorTagTarget !== "") {
451
+ $middleNode.target = editorStore.option.anchorTagTarget;
452
+ }
453
+ $middleNode.className = "de-link";
454
+ $middleNode.href = url;
455
+ $firstNode.textContent = text.substring(0, cloneRange.startOffset);
456
+ $middleNode.textContent = text.substring(cloneRange.startOffset, cloneRange.endOffset);
457
+ $lastNode.textContent = text.substring(cloneRange.endOffset, text.length);
458
+ nodeList.push($firstNode, $middleNode, $lastNode);
459
+ cursorStartNode = $middleNode.childNodes[0] || null;
460
+ cursorStartNodeOffset = 0;
461
+ cursorEndNode = $middleNode.childNodes[0] || null;
462
+ cursorEndNodeOffset = $middleNode.textContent.length;
463
+ }
464
+ } else {
465
+ nodeList.push(node);
466
+ }
467
+ }
468
+ } else {
469
+ if (cloneRange.startContainer === node || cloneRange.endContainer === node || cloneRange.startContainer.parentElement === node || cloneRange.endContainer.parentElement === node) {
470
+ const text = node.textContent;
471
+ if (text !== null) {
472
+ const textStartOffset = cloneRange.startOffset;
473
+ const textEndOffset = cloneRange.endOffset;
474
+ if (cloneRange.startContainer === node || cloneRange.startContainer.parentElement === node) {
475
+ const $aTag = document.createElement("a");
476
+ if (editorStore.option.anchorTagTarget !== "") {
477
+ $aTag.target = editorStore.option.anchorTagTarget;
478
+ }
479
+ $aTag.className = "de-link";
480
+ $aTag.href = url;
481
+ $aTag.textContent = text.substring(textStartOffset);
482
+ nodeList.push(document.createTextNode(text.substring(0, textStartOffset)));
483
+ nodeList.push($aTag);
484
+ cursorStartNode = $aTag.childNodes[0] || null;
485
+ cursorStartNodeOffset = 0;
486
+ isBettween = true;
487
+ }
488
+ if (cloneRange.endContainer === node || cloneRange.endContainer.parentElement === node) {
489
+ const $aTag = document.createElement("a");
490
+ if (editorStore.option.anchorTagTarget !== "") {
491
+ $aTag.target = editorStore.option.anchorTagTarget;
492
+ }
493
+ $aTag.className = "de-link";
494
+ $aTag.href = url;
495
+ $aTag.textContent = text.substring(0, textEndOffset);
496
+ nodeList.push($aTag);
497
+ nodeList.push(document.createTextNode(text.substring(textEndOffset)));
498
+ cursorEndNode = $aTag.childNodes[0] || null;
499
+ cursorEndNodeOffset = text.substring(0, textEndOffset).length;
500
+ isBettween = false;
501
+ }
502
+ }
503
+ } else {
504
+ if (isBettween === false) {
505
+ nodeList.push(node);
506
+ } else {
507
+ const $aTag = document.createElement("a");
508
+ if (editorStore.option.anchorTagTarget !== "") {
509
+ $aTag.target = editorStore.option.anchorTagTarget;
510
+ }
511
+ $aTag.className = "de-link";
512
+ $aTag.href = url;
513
+ $aTag.textContent = node.textContent;
514
+ nodeList.push($aTag);
515
+ }
516
+ }
517
+ }
518
+ });
519
+ $editableParent.innerHTML = "";
520
+ const { list: newList, cursorStartNode: StartNode, cursorStartNodeOffset: StartNodeOffset, cursorEndNode: EndNode, cursorEndNodeOffset: EndNodeOffset } = _arrangementNodeList(nodeList, cursorStartNode, cursorStartNodeOffset, cursorEndNode, cursorEndNodeOffset);
521
+ newList.forEach((node) => {
522
+ if (node.textContent !== "") {
523
+ $editableParent.appendChild(node);
524
+ }
525
+ });
526
+ editorStore.status.anchorHerf = "";
527
+ $editableParent.dispatchEvent(new Event("input"));
528
+ await nextTick();
529
+ if (StartNode !== null && EndNode !== null) {
530
+ _setRangeCursorPosition(StartNode, StartNodeOffset, EndNode, EndNodeOffset);
531
+ _updateCursorData();
532
+ }
533
+ }
534
+ }
535
+ }
536
+ export async function _removeLink() {
537
+ const editorStore = useEditorStore();
538
+ if (editorStore.cursorRange !== null) {
539
+ const cloneRange = editorStore.cursorRange.cloneRange();
540
+ const $editableParent = _findEditableParent(cloneRange.startContainer.nodeType === Node.TEXT_NODE ? cloneRange.startContainer.parentElement : cloneRange.startContainer);
541
+ if ($editableParent !== null) {
542
+ const nodeList = [];
543
+ let cursorStartNode = null;
544
+ let cursorStartNodeOffset = 0;
545
+ let cursorEndNode = null;
546
+ let cursorEndNodeOffset = 0;
547
+ if (cloneRange.collapsed === true) {
548
+ $editableParent.childNodes.forEach((node) => {
549
+ if (cloneRange.startContainer.parentElement === $editableParent) {
550
+ nodeList.push(node);
551
+ } else {
552
+ const $tag = node;
553
+ if (cloneRange.startContainer.parentElement === $tag) {
554
+ if ($tag.tagName === "A") {
555
+ const $textNode = document.createTextNode($tag.textContent);
556
+ nodeList.push($textNode);
557
+ cursorStartNode = $textNode;
558
+ cursorStartNodeOffset = 0;
559
+ cursorEndNode = $textNode;
560
+ cursorEndNodeOffset = $textNode.textContent.length;
561
+ } else {
562
+ nodeList.push(node);
563
+ }
564
+ } else {
565
+ nodeList.push(node);
566
+ }
567
+ }
568
+ });
569
+ } else {
570
+ let isBettween = false;
571
+ $editableParent.childNodes.forEach((node) => {
572
+ if (cloneRange.startContainer === cloneRange.endContainer) {
573
+ if (cloneRange.startContainer.parentElement === $editableParent) {
574
+ nodeList.push(node);
575
+ cursorStartNode = node;
576
+ cursorStartNodeOffset = cloneRange.startOffset;
577
+ cursorEndNode = node;
578
+ cursorEndNodeOffset = cloneRange.endOffset;
579
+ } else {
580
+ if (cloneRange.startContainer.parentElement === node) {
581
+ const $tag = node;
582
+ if ($tag.tagName === "A") {
583
+ if (cloneRange.startOffset === 0 && cloneRange.endOffset === (node.textContent || "").length) {
584
+ const $textNode = document.createTextNode($tag.textContent || "");
585
+ nodeList.push($textNode);
586
+ cursorStartNode = $textNode;
587
+ cursorStartNodeOffset = 0;
588
+ cursorEndNode = $textNode;
589
+ cursorEndNodeOffset = $textNode.textContent.length;
590
+ } else {
591
+ const text = $tag.textContent;
592
+ const $firstNode = $tag.cloneNode();
593
+ const $middleNode = document.createTextNode(text.substring(cloneRange.startOffset, cloneRange.endOffset));
594
+ const $lastNode = $tag.cloneNode();
595
+ $firstNode.textContent = text.substring(0, cloneRange.startOffset);
596
+ $lastNode.textContent = text.substring(cloneRange.endOffset, text.length);
597
+ nodeList.push($firstNode, $middleNode, $lastNode);
598
+ cursorStartNode = $middleNode;
599
+ cursorStartNodeOffset = 0;
600
+ cursorEndNode = $middleNode;
601
+ cursorEndNodeOffset = $middleNode.textContent.length;
602
+ }
603
+ } else {
604
+ nodeList.push(node);
605
+ cursorStartNode = node;
606
+ cursorStartNodeOffset = cloneRange.startOffset;
607
+ cursorEndNode = node;
608
+ cursorEndNodeOffset = cloneRange.endOffset;
609
+ }
610
+ } else {
611
+ nodeList.push(node);
612
+ }
613
+ }
614
+ } else {
615
+ if (cloneRange.startContainer === node || cloneRange.endContainer === node || cloneRange.startContainer.parentElement === node || cloneRange.endContainer.parentElement === node) {
616
+ const text = node.textContent;
617
+ if (text !== null) {
618
+ const textStartOffset = cloneRange.startOffset;
619
+ const textEndOffset = cloneRange.endOffset;
620
+ if (cloneRange.startContainer === node) {
621
+ nodeList.push(node);
622
+ cursorStartNode = node;
623
+ cursorStartNodeOffset = textStartOffset;
624
+ isBettween = true;
625
+ }
626
+ if (cloneRange.startContainer.parentElement === node) {
627
+ const $tag = node;
628
+ if ($tag.tagName === "A") {
629
+ const $span = $tag.cloneNode();
630
+ const $textNode = document.createTextNode(text.substring(textStartOffset));
631
+ $span.textContent = text.substring(0, textStartOffset);
632
+ nodeList.push($span);
633
+ nodeList.push($textNode);
634
+ cursorStartNode = $textNode;
635
+ cursorStartNodeOffset = 0;
636
+ } else {
637
+ nodeList.push(node);
638
+ cursorStartNode = node;
639
+ cursorStartNodeOffset = textStartOffset;
640
+ }
641
+ isBettween = true;
642
+ }
643
+ if (cloneRange.endContainer === node) {
644
+ nodeList.push(node);
645
+ cursorEndNode = node;
646
+ cursorEndNodeOffset = textEndOffset;
647
+ isBettween = false;
648
+ }
649
+ if (cloneRange.endContainer.parentElement === node) {
650
+ const $tag = node;
651
+ if ($tag.tagName === "A") {
652
+ const $textNode = document.createTextNode(text.substring(0, textEndOffset));
653
+ const $span = $tag.cloneNode();
654
+ $span.textContent = text.substring(textEndOffset);
655
+ nodeList.push($textNode);
656
+ nodeList.push($span);
657
+ cursorEndNode = $textNode;
658
+ cursorEndNodeOffset = textEndOffset;
659
+ } else {
660
+ nodeList.push(node);
661
+ cursorEndNode = node;
662
+ cursorEndNodeOffset = textEndOffset;
663
+ }
664
+ isBettween = false;
665
+ }
666
+ }
667
+ } else {
668
+ if (isBettween === false) {
669
+ nodeList.push(node);
670
+ } else {
671
+ if (node.nodeType === Node.TEXT_NODE) {
672
+ nodeList.push(node);
673
+ } else {
674
+ const $tag = node;
675
+ if ($tag.tagName === "A") {
676
+ const $textNode = document.createTextNode($tag.textContent);
677
+ nodeList.push($textNode);
678
+ } else {
679
+ nodeList.push(node);
680
+ }
681
+ }
682
+ }
683
+ }
684
+ }
685
+ });
686
+ }
687
+ $editableParent.innerHTML = "";
688
+ const { list: newList, cursorStartNode: StartNode, cursorStartNodeOffset: StartNodeOffset, cursorEndNode: EndNode, cursorEndNodeOffset: EndNodeOffset } = _arrangementNodeList(nodeList, cursorStartNode, cursorStartNodeOffset, cursorEndNode, cursorEndNodeOffset);
689
+ newList.forEach((node) => {
690
+ if (node.textContent !== "") {
691
+ $editableParent.appendChild(node);
692
+ }
693
+ });
694
+ $editableParent.dispatchEvent(new Event("input"));
695
+ await nextTick();
696
+ if (StartNode !== null && EndNode !== null) {
697
+ _setRangeCursorPosition(StartNode, StartNodeOffset, EndNode, EndNodeOffset);
698
+ _updateCursorData();
699
+ }
700
+ }
701
+ }
702
+ }