dragon-editor 3.4.4 → 3.5.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.
Files changed (70) hide show
  1. package/README.md +9 -15
  2. package/dist/module.d.mts +5 -0
  3. package/dist/module.json +8 -1
  4. package/dist/module.mjs +5 -3
  5. package/dist/runtime/components/DragonEditor.vue +252 -720
  6. package/dist/runtime/components/DragonEditorViewer.vue +59 -45
  7. package/dist/runtime/scss/editor.css +83 -34
  8. package/dist/runtime/scss/viewer.css +31 -4
  9. package/dist/runtime/type.d.ts +78 -23
  10. package/dist/runtime/utils/event/block.d.ts +0 -0
  11. package/dist/runtime/utils/event/block.js +78 -0
  12. package/dist/runtime/utils/event/cursor.d.ts +0 -0
  13. package/dist/runtime/utils/{cursor.mjs → event/cursor.js} +4 -16
  14. package/dist/runtime/utils/event/data.d.ts +0 -0
  15. package/dist/runtime/utils/event/data.js +342 -0
  16. package/dist/runtime/utils/event/index.d.ts +8 -0
  17. package/dist/runtime/utils/event/index.js +8 -0
  18. package/dist/runtime/utils/event/keyboard.d.ts +0 -0
  19. package/dist/runtime/utils/event/keyboard.js +1368 -0
  20. package/dist/runtime/utils/event/mouse.d.ts +0 -0
  21. package/dist/runtime/utils/event/mouse.js +70 -0
  22. package/dist/runtime/utils/event/scroll.d.ts +0 -0
  23. package/dist/runtime/utils/event/scroll.js +29 -0
  24. package/dist/runtime/utils/event/touch.d.ts +0 -0
  25. package/dist/runtime/utils/event/touch.js +10 -0
  26. package/dist/runtime/utils/event/window.d.ts +0 -0
  27. package/dist/runtime/utils/event/window.js +32 -0
  28. package/dist/runtime/utils/layout/block.d.ts +0 -0
  29. package/dist/runtime/utils/layout/block.js +105 -0
  30. package/dist/runtime/utils/layout/body.d.ts +0 -0
  31. package/dist/runtime/utils/layout/body.js +22 -0
  32. package/dist/runtime/utils/layout/controlbar.d.ts +0 -0
  33. package/dist/runtime/utils/layout/controlbar.js +99 -0
  34. package/dist/runtime/utils/layout/icon.d.ts +0 -0
  35. package/dist/runtime/utils/layout/icon.js +156 -0
  36. package/dist/runtime/utils/layout/index.d.ts +5 -0
  37. package/dist/runtime/utils/layout/index.js +5 -0
  38. package/dist/runtime/utils/layout/menuBar.d.ts +0 -0
  39. package/dist/runtime/utils/layout/menuBar.js +358 -0
  40. package/dist/runtime/utils/node/block.d.ts +0 -0
  41. package/dist/runtime/utils/node/block.js +235 -0
  42. package/dist/runtime/utils/{element.d.ts → node/element.d.ts} +1 -0
  43. package/dist/runtime/utils/{element.mjs → node/element.js} +19 -4
  44. package/dist/runtime/utils/node/index.d.ts +2 -0
  45. package/dist/runtime/utils/node/index.js +2 -0
  46. package/dist/runtime/utils/style/anchor.d.ts +0 -0
  47. package/dist/runtime/utils/style/anchor.js +240 -0
  48. package/dist/runtime/utils/style/decoration.d.ts +0 -0
  49. package/dist/runtime/utils/style/decoration.js +378 -0
  50. package/dist/runtime/utils/style/index.d.ts +2 -0
  51. package/dist/runtime/utils/style/index.js +2 -0
  52. package/dist/types.d.mts +7 -0
  53. package/dist/types.d.ts +3 -3
  54. package/package.json +15 -16
  55. package/dist/runtime/store.d.ts +0 -11
  56. package/dist/runtime/store.mjs +0 -51
  57. package/dist/runtime/utils/block.d.ts +0 -13
  58. package/dist/runtime/utils/block.mjs +0 -144
  59. package/dist/runtime/utils/content.d.ts +0 -2
  60. package/dist/runtime/utils/content.mjs +0 -19
  61. package/dist/runtime/utils/controlBar.d.ts +0 -9
  62. package/dist/runtime/utils/controlBar.mjs +0 -172
  63. package/dist/runtime/utils/convertor.d.ts +0 -3
  64. package/dist/runtime/utils/convertor.mjs +0 -138
  65. package/dist/runtime/utils/cursor.d.ts +0 -6
  66. package/dist/runtime/utils/keyboardEvent.d.ts +0 -10
  67. package/dist/runtime/utils/keyboardEvent.mjs +0 -978
  68. package/dist/runtime/utils/style.d.ts +0 -5
  69. package/dist/runtime/utils/style.mjs +0 -617
  70. /package/dist/runtime/{plugin.mjs → plugin.js} +0 -0
@@ -1,5 +0,0 @@
1
- export declare function _setNodeStyle(className: string, store: any): void;
2
- export declare function _setTextAlign(type: DETextalign, store: any): void;
3
- export declare function _setAnchorTag(url: string, isOutsideLink: boolean, store: any): void;
4
- export declare function _unsetAnchorTag(store: any): false | undefined;
5
- export declare function _getAnchorTagValue(store: any): string;
@@ -1,617 +0,0 @@
1
- import { _findContentEditableElement } from "./element.mjs";
2
- import { _soltingCursorDataOnElement, _setCursor, _setRangeCursor, _clenupCursor } from "./cursor.mjs";
3
- import { _getBlockType } from "./block.mjs";
4
- export function _setNodeStyle(className, store) {
5
- if (store.cursorData !== null) {
6
- const { type } = _getBlockType(store.$currentBlock);
7
- const typeIgnoreList = ["image", "code", "other"];
8
- if (typeIgnoreList.includes(type) === false) {
9
- const $element = _findContentEditableElement(store.cursorData.startNode);
10
- if ($element !== null) {
11
- if (store.cursorData.type === "Caret") {
12
- if ($element.hasChildNodes() === true) {
13
- let $target = store.cursorData.startNode;
14
- if ($target.constructor.name === "Text") {
15
- const $parentElement = $target.parentElement;
16
- if ($parentElement === $element) {
17
- let childList = $element.childNodes;
18
- let targetIdx = -1;
19
- let structure = "";
20
- for (let i = 0; childList.length > i; i += 1) {
21
- if ($target === childList[i]) {
22
- targetIdx = i;
23
- break;
24
- }
25
- }
26
- targetIdx = findPoverTextNode(childList[targetIdx], targetIdx);
27
- $element.innerHTML = $element.innerHTML;
28
- childList = $element.childNodes;
29
- childList.forEach((node, i) => {
30
- if (i === targetIdx) {
31
- structure += `<span class="${className}">${node.textContent}</span>`;
32
- } else {
33
- if (node.constructor.name === "Text") {
34
- structure += node.textContent;
35
- } else {
36
- structure += node.outerHTML;
37
- }
38
- }
39
- });
40
- $element.innerHTML = structure;
41
- const targetElement = $element.childNodes[targetIdx];
42
- _setRangeCursor(targetElement, targetElement, 0, targetElement.textContent?.length ?? 0);
43
- } else {
44
- if ($parentElement.tagName === "SPAN") {
45
- const classList = $parentElement.classList.value.split(" ");
46
- const classIdx = classList.indexOf(className);
47
- if (classIdx === -1) {
48
- $parentElement.classList.add(className);
49
- const targetNode = $parentElement.childNodes[0];
50
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
51
- } else {
52
- if (classList.length === 1) {
53
- $parentElement.insertAdjacentText("afterend", $parentElement.textContent);
54
- const targetNode = $parentElement.nextSibling;
55
- $parentElement.remove();
56
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
57
- } else {
58
- $parentElement.classList.remove(className);
59
- const targetNode = $parentElement.childNodes[0];
60
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
61
- }
62
- }
63
- }
64
- }
65
- }
66
- }
67
- } else {
68
- const cursorData = _soltingCursorDataOnElement(store.cursorData, $element);
69
- let structure = "";
70
- let isDuble = false;
71
- if (cursorData.startNodeIdx === cursorData.endNodeIdx) {
72
- if (cursorData.startNode.constructor.name === "Text") {
73
- $element.childNodes.forEach((childNode, i) => {
74
- if (cursorData.startNodeIdx === i) {
75
- if (cursorData.startOffset !== 0) {
76
- structure += childNode.textContent.slice(0, cursorData.startOffset);
77
- isDuble = true;
78
- }
79
- structure += `<span class="${className}">${childNode.textContent.slice(cursorData.startOffset, cursorData.endOffset)}</span>`;
80
- if (cursorData.endOffset !== childNode.textContent.length) {
81
- structure += childNode.textContent.slice(cursorData.endOffset);
82
- }
83
- } else {
84
- if (childNode.constructor.name === "Text") {
85
- structure += childNode.textContent;
86
- } else {
87
- structure += childNode.outerHTML;
88
- }
89
- }
90
- });
91
- let childNumber = cursorData.startNodeIdx;
92
- if (isDuble === true) {
93
- childNumber += 1;
94
- }
95
- $element.innerHTML = structure;
96
- const targetNode = $element.childNodes[childNumber];
97
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
98
- } else {
99
- const $target = cursorData.startNode;
100
- if ($target.tagName !== "A") {
101
- const classList = $target.classList.value.split(" ");
102
- const classIdx = classList.indexOf(className);
103
- if (classIdx === -1) {
104
- if (cursorData.startOffset !== 0) {
105
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(0, cursorData.startOffset)}</span>`;
106
- isDuble = true;
107
- }
108
- structure += `<span class="${classList.join(" ")} ${className}">${$target.textContent.slice(cursorData.startOffset, cursorData.endOffset)}</span>`;
109
- if (cursorData.endOffset !== $target.textContent.length) {
110
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(cursorData.endOffset)}</span>`;
111
- }
112
- } else {
113
- if (cursorData.startOffset !== 0) {
114
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(0, cursorData.startOffset)}</span>`;
115
- isDuble = true;
116
- }
117
- if (classList.length === 1) {
118
- structure += $target.textContent.slice(cursorData.startOffset, cursorData.endOffset);
119
- } else {
120
- const copyList = [...classList];
121
- copyList.splice(classIdx, 1);
122
- structure += `<span class="${copyList.join(" ")}">${$target.textContent.slice(cursorData.startOffset, cursorData.endOffset)}</span>`;
123
- }
124
- if (cursorData.endOffset !== $target.textContent.length) {
125
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(cursorData.endOffset)}</span>`;
126
- }
127
- }
128
- $target.insertAdjacentHTML("afterend", structure);
129
- let $nextElement = $target.nextSibling;
130
- if (isDuble === true) {
131
- $nextElement = $nextElement.nextSibling;
132
- }
133
- $target.remove();
134
- const targetNode = $nextElement;
135
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
136
- }
137
- }
138
- } else {
139
- let isAnchorElement = false;
140
- let isWrap = false;
141
- let startNodeIdx = cursorData.startNodeIdx;
142
- let startOffset = cursorData.startOffset;
143
- let endNodeIdx = cursorData.endNodeIdx;
144
- let endOffset = cursorData.endOffset;
145
- let structureArray = [];
146
- $element.childNodes.forEach((childNode, i) => {
147
- const $elementNode = childNode;
148
- let isText = childNode.constructor.name === "Text";
149
- if (cursorData.startNodeIdx > i) {
150
- if (isText === true) {
151
- structureArray.push(childNode.textContent);
152
- } else {
153
- structureArray.push($elementNode.outerHTML);
154
- }
155
- }
156
- if (cursorData.startNodeIdx === i) {
157
- const preTextContent = childNode.textContent.slice(0, cursorData.startOffset);
158
- const textContent = childNode.textContent.slice(cursorData.startOffset);
159
- if (isText === true) {
160
- structureArray.push(preTextContent);
161
- structureArray.push(`<span class="${className}">${textContent}</span>`);
162
- isWrap = true;
163
- if (cursorData.startOffset !== 0) {
164
- isDuble = true;
165
- }
166
- } else {
167
- const classList = $elementNode.classList.value.split(" ");
168
- const classIdx = classList.indexOf(className);
169
- if ($elementNode.tagName === "SPAN") {
170
- if (classIdx === -1) {
171
- if (preTextContent !== "") {
172
- structureArray.push(`<span class="${classList.join(" ")}">${preTextContent}</span>`);
173
- }
174
- structureArray.push(`<span class="${classList.join(" ")} ${className}">${textContent}</span>`);
175
- isWrap = true;
176
- } else {
177
- if (classList.length === 1) {
178
- if (preTextContent !== "") {
179
- structureArray.push(`<span class="${classList.join(" ")}">${preTextContent}</span>`);
180
- }
181
- structureArray.push(textContent);
182
- } else {
183
- const newClassList = [...classList];
184
- newClassList.splice(classIdx, 1);
185
- if (preTextContent !== "") {
186
- structureArray.push(`<span class="${classList.join(" ")}">${preTextContent}</span>`);
187
- }
188
- structureArray.push(`<span class="${newClassList.join(" ")}">${textContent}</span>`);
189
- }
190
- }
191
- } else if ($elementNode.tagName === "BR") {
192
- structureArray.push("<br>");
193
- } else {
194
- isAnchorElement = true;
195
- }
196
- }
197
- }
198
- if (cursorData.startNodeIdx < i && cursorData.endNodeIdx > i) {
199
- if (isText === true) {
200
- if (isWrap === true) {
201
- structureArray.push(`<span class="${className}">${childNode.textContent}</span>`);
202
- } else {
203
- structureArray.push(childNode.textContent);
204
- }
205
- } else {
206
- const classList = $elementNode.classList.value.split(" ");
207
- const classIdx = classList.indexOf(className);
208
- if ($elementNode.tagName === "SPAN") {
209
- if (isWrap === true) {
210
- if (classIdx === -1) {
211
- structureArray.push(`<span class="${classList.join(" ")} ${className}">${childNode.textContent}</span>`);
212
- } else {
213
- structureArray.push($elementNode.outerHTML);
214
- }
215
- } else {
216
- if (classIdx === -1) {
217
- structureArray.push($elementNode.outerHTML);
218
- } else {
219
- if (classList.length === 1) {
220
- structureArray.push(childNode.textContent);
221
- } else {
222
- const newClassList = [...classList];
223
- newClassList.splice(classIdx, 1);
224
- structureArray.push(`<span class="${newClassList.join(" ")}">${childNode.textContent}</span>`);
225
- }
226
- }
227
- }
228
- } else if ($elementNode.tagName === "BR") {
229
- structureArray.push("<br>");
230
- } else {
231
- isAnchorElement = true;
232
- }
233
- }
234
- }
235
- if (cursorData.endNodeIdx === i) {
236
- const textContent = childNode.textContent.slice(0, cursorData.endOffset);
237
- const endTextContent = childNode.textContent.slice(cursorData.endOffset);
238
- if (isText === true) {
239
- if (isWrap === true) {
240
- structureArray.push(`<span class="${className}">${textContent}</span>`);
241
- structureArray.push(endTextContent);
242
- } else {
243
- structureArray.push(childNode.textContent);
244
- }
245
- } else {
246
- const classList = $elementNode.classList.value.split(" ");
247
- const classIdx = classList.indexOf(className);
248
- if ($elementNode.tagName === "SPAN") {
249
- if (isWrap === true) {
250
- if (classIdx === -1) {
251
- structureArray.push(`<span class="${classList.join(" ")} ${className}">${textContent}</span>`);
252
- if (endTextContent !== "") {
253
- structureArray.push(`<span class="${classList.join(" ")}">${endTextContent}</span>`);
254
- }
255
- } else {
256
- structureArray.push($elementNode.outerHTML);
257
- }
258
- } else {
259
- if (classIdx === -1) {
260
- structureArray.push($elementNode.outerHTML);
261
- } else {
262
- if (classList.length === 1) {
263
- structureArray.push(textContent);
264
- if (endTextContent !== "") {
265
- structureArray.push(`<span class="${classList.join(" ")}">${endTextContent}</span>`);
266
- }
267
- } else {
268
- const newClassList = [...classList];
269
- newClassList.splice(classIdx, 1);
270
- structureArray.push(`<span class="${newClassList.join(" ")}">${textContent}</span>`);
271
- if (endTextContent !== "") {
272
- structureArray.push(`<span class="${classList.join(" ")}">${endTextContent}</span>`);
273
- }
274
- }
275
- }
276
- }
277
- } else if ($elementNode.tagName === "BR") {
278
- structureArray.push("<br>");
279
- } else {
280
- isAnchorElement = true;
281
- }
282
- }
283
- }
284
- if (cursorData.endNodeIdx < i) {
285
- if (isText === true) {
286
- structureArray.push(childNode.textContent);
287
- } else {
288
- structureArray.push($elementNode.outerHTML);
289
- }
290
- }
291
- });
292
- $element.innerHTML = structureArray.join("");
293
- if (isWrap === true) {
294
- if (isDuble === true) {
295
- startNodeIdx += 1;
296
- endNodeIdx += 1;
297
- startOffset = 0;
298
- }
299
- } else {
300
- const tagReg = new RegExp("(<([^>]+)>)", "i");
301
- const isTagList = [];
302
- let newStartNodeIdx = 0;
303
- let newStartOffset = startOffset * 1;
304
- let newEndOffset = 0;
305
- let endMinusCount = 0;
306
- structureArray.forEach((string, i) => {
307
- const isTag = tagReg.test(string);
308
- isTagList.push(isTag);
309
- if (startNodeIdx <= i && i <= endNodeIdx) {
310
- if (isTag === true) {
311
- newEndOffset = 0;
312
- } else {
313
- endMinusCount += 1;
314
- newEndOffset += string.length;
315
- }
316
- }
317
- });
318
- if (isTagList[startNodeIdx - 1] === false) {
319
- newStartNodeIdx = startNodeIdx - 1;
320
- newStartOffset = startOffset + structureArray[startNodeIdx - 1].length;
321
- }
322
- if (isTagList.slice(startNodeIdx, endNodeIdx).includes(true) === true) {
323
- endNodeIdx -= endMinusCount - 1;
324
- endOffset = newEndOffset;
325
- } else {
326
- endNodeIdx = newStartNodeIdx;
327
- endOffset = newStartOffset + newEndOffset;
328
- }
329
- startNodeIdx = newStartNodeIdx;
330
- startOffset = newStartOffset;
331
- }
332
- _setRangeCursor($element.childNodes[startNodeIdx], $element.childNodes[endNodeIdx], startOffset, endOffset);
333
- if (isAnchorElement === true) {
334
- alert(store.message.linkTextNoStyle);
335
- }
336
- }
337
- }
338
- }
339
- _clenupCursor(store);
340
- }
341
- }
342
- }
343
- export function _setTextAlign(type, store) {
344
- const { type: blockType } = _getBlockType(store.$currentBlock);
345
- const typeIgnoreList = ["code", "other"];
346
- if (typeIgnoreList.includes(blockType) === false) {
347
- const alignClassList = ["de-align-left", "de-align-right", "de-align-center", "de-align-justify"];
348
- const className = `de-align-${type}`;
349
- let $element = null;
350
- if (store.$currentBlock.classList.contains("de-image-block") === true) {
351
- $element = store.$currentBlock;
352
- } else {
353
- if (store.cursorData !== null) {
354
- $element = _findContentEditableElement(store.cursorData.startNode);
355
- }
356
- }
357
- if ($element !== null) {
358
- if ($element.classList.contains(className) === true) {
359
- $element.classList.remove(className);
360
- } else {
361
- const curruntClassname = alignClassList.filter((text) => $element.classList.contains(text) === true)[0];
362
- if (curruntClassname !== void 0) {
363
- $element.classList.remove(curruntClassname);
364
- }
365
- $element.classList.add(className);
366
- }
367
- if (store.$currentBlock.classList.contains("de-image-block") !== true) {
368
- _setCursor($element, 0);
369
- }
370
- }
371
- }
372
- }
373
- export function _setAnchorTag(url, isOutsideLink, store) {
374
- if (store.cursorData !== null) {
375
- const { type } = _getBlockType(store.$currentBlock);
376
- const typeIgnoreList = ["image", "code", "other"];
377
- const hrefValue = isOutsideLink === true ? url : `#${url}`;
378
- if (typeIgnoreList.includes(type) === false) {
379
- const $element = _findContentEditableElement(store.cursorData.startNode);
380
- if ($element !== null) {
381
- if (store.cursorData.type === "Caret") {
382
- if ($element.hasChildNodes() === true) {
383
- let $target = store.cursorData.startNode;
384
- if ($target.constructor.name === "Text") {
385
- const $parentElement = $target.parentElement;
386
- if ($parentElement === $element) {
387
- let childList = $element.childNodes;
388
- let targetIdx = -1;
389
- let structure = "";
390
- for (let i = 0; childList.length > i; i += 1) {
391
- if ($target === childList[i]) {
392
- targetIdx = i;
393
- break;
394
- }
395
- }
396
- targetIdx = findPoverTextNode(childList[targetIdx], targetIdx);
397
- $element.innerHTML = $element.innerHTML;
398
- childList = $element.childNodes;
399
- childList.forEach((node, i) => {
400
- if (i === targetIdx) {
401
- structure += `<a class="de-link"`;
402
- structure += `href="${hrefValue}"`;
403
- if (isOutsideLink === true) {
404
- structure += `target="_blank"`;
405
- }
406
- structure += `>`;
407
- structure += `${node.textContent}</a>`;
408
- } else {
409
- if (node.constructor.name === "Text") {
410
- structure += node.textContent;
411
- } else {
412
- structure += node.outerHTML;
413
- }
414
- }
415
- });
416
- $element.innerHTML = structure;
417
- const targetElement = $element.childNodes[targetIdx];
418
- _setRangeCursor(targetElement, targetElement, 0, targetElement.textContent?.length ?? 0);
419
- } else {
420
- if ($parentElement.tagName === "A") {
421
- $parentElement.href = hrefValue;
422
- if (isOutsideLink === true) {
423
- $parentElement.target = "_blank";
424
- } else {
425
- $parentElement.removeAttribute("target");
426
- }
427
- _setRangeCursor($parentElement, $parentElement, 0, $parentElement.textContent?.length ?? 0);
428
- }
429
- }
430
- }
431
- }
432
- } else {
433
- const cursorData = _soltingCursorDataOnElement(store.cursorData, $element);
434
- let structure = "";
435
- let isDuble = false;
436
- if (cursorData.startNodeIdx === cursorData.endNodeIdx) {
437
- if (cursorData.startNode.constructor.name === "Text") {
438
- $element.childNodes.forEach((childNode, i) => {
439
- if (cursorData.startNodeIdx === i) {
440
- if (cursorData.startOffset !== 0) {
441
- structure += childNode.textContent.slice(0, cursorData.startOffset);
442
- isDuble = true;
443
- }
444
- structure += `<a class="de-link"`;
445
- structure += `href="${hrefValue}"`;
446
- if (isOutsideLink === true) {
447
- structure += `target="_blank"`;
448
- }
449
- structure += `>`;
450
- structure += `${childNode.textContent.slice(cursorData.startOffset, cursorData.endOffset)}</a>`;
451
- if (cursorData.endOffset !== childNode.textContent.length) {
452
- structure += childNode.textContent.slice(cursorData.endOffset);
453
- }
454
- } else {
455
- if (childNode.constructor.name === "Text") {
456
- structure += childNode.textContent;
457
- } else {
458
- structure += childNode.outerHTML;
459
- }
460
- }
461
- });
462
- let childNumber = cursorData.startNodeIdx;
463
- if (isDuble === true) {
464
- childNumber += 1;
465
- }
466
- $element.innerHTML = structure;
467
- const targetNode = $element.childNodes[childNumber];
468
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
469
- } else {
470
- const $target = cursorData.startNode;
471
- if ($target.tagName !== "A") {
472
- const classList = $target.classList.value.split(" ");
473
- if (cursorData.startOffset !== 0) {
474
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(0, cursorData.startOffset)}</span>`;
475
- isDuble = true;
476
- }
477
- structure += `<a class="de-link"`;
478
- structure += `href="${hrefValue}"`;
479
- if (isOutsideLink === true) {
480
- structure += `target="_blank"`;
481
- }
482
- structure += `>`;
483
- structure += `${$target.textContent.slice(cursorData.startOffset, cursorData.endOffset)}</a>`;
484
- if (cursorData.endOffset !== $target.textContent.length) {
485
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(cursorData.endOffset)}</span>`;
486
- }
487
- $target.insertAdjacentHTML("afterend", structure);
488
- let $nextElement = $target.nextSibling;
489
- if (isDuble === true) {
490
- $nextElement = $nextElement.nextSibling;
491
- }
492
- $target.remove();
493
- const targetNode = $nextElement;
494
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
495
- } else {
496
- $target.href = hrefValue;
497
- if (isOutsideLink === true) {
498
- $target.target = "_blank";
499
- } else {
500
- $target.removeAttribute("target");
501
- }
502
- _setRangeCursor($target, $target, 0, $target.textContent?.length ?? 0);
503
- }
504
- }
505
- } else {
506
- let preStructure = "";
507
- let anchorTextContent = "";
508
- let nextStructure = "";
509
- $element.childNodes.forEach((childNode, i) => {
510
- const $elementNode = childNode;
511
- let isText = childNode.constructor.name === "Text";
512
- if (cursorData.startNodeIdx > i) {
513
- if (isText === true) {
514
- preStructure += childNode.textContent;
515
- } else {
516
- preStructure += $elementNode.outerHTML;
517
- }
518
- }
519
- if (cursorData.startNodeIdx === i) {
520
- if (isText === true) {
521
- preStructure += childNode.textContent.slice(0, cursorData.startOffset);
522
- } else {
523
- preStructure += `<span class="${childNode.classList.value}">${childNode.textContent.slice(0, cursorData.startOffset)}</span>`;
524
- }
525
- anchorTextContent += childNode.textContent.slice(cursorData.startOffset);
526
- }
527
- if (cursorData.startNodeIdx < i && cursorData.endNodeIdx > i) {
528
- anchorTextContent += childNode.textContent;
529
- }
530
- if (cursorData.endNodeIdx === i) {
531
- anchorTextContent += childNode.textContent.slice(0, cursorData.endOffset);
532
- if (isText === true) {
533
- nextStructure += childNode.textContent.slice(cursorData.startOffset);
534
- } else {
535
- nextStructure += `<span class="${childNode.classList.value}">${childNode.textContent.slice(cursorData.startOffset)}</span>`;
536
- }
537
- }
538
- if (cursorData.endNodeIdx < i) {
539
- if (isText === true) {
540
- nextStructure += childNode.textContent;
541
- } else {
542
- nextStructure += $elementNode.outerHTML;
543
- }
544
- }
545
- });
546
- let anchorTag = "";
547
- anchorTag += `<a class="de-link"`;
548
- anchorTag += `href="${hrefValue}"`;
549
- if (isOutsideLink === true) {
550
- anchorTag += `target="_blank"`;
551
- }
552
- anchorTag += `>`;
553
- anchorTag += anchorTextContent;
554
- anchorTag += `</a>`;
555
- $element.innerHTML = preStructure + anchorTag + nextStructure;
556
- let targetNode = $element.childNodes[cursorData.startNodeIdx];
557
- if (cursorData.startOffset !== 0) {
558
- targetNode = $element.childNodes[cursorData.startNodeIdx + 1];
559
- }
560
- _setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
561
- }
562
- }
563
- }
564
- _clenupCursor(store);
565
- }
566
- }
567
- }
568
- export function _unsetAnchorTag(store) {
569
- if (store.cursorData !== null) {
570
- const $element = _findContentEditableElement(store.cursorData.startNode);
571
- if ($element !== null) {
572
- const cursorData = _soltingCursorDataOnElement(store.cursorData, $element);
573
- if (cursorData.startNode.constructor.name === "HTMLAnchorElement") {
574
- if (store.cursorData.type === "Range") {
575
- if (cursorData.startNodeIdx !== cursorData.endNodeIdx) {
576
- return false;
577
- }
578
- }
579
- const $anchorTag = cursorData.startNode;
580
- $anchorTag.insertAdjacentText("afterend", cursorData.startNode.textContent ?? "");
581
- const $targetNode = $anchorTag.nextSibling;
582
- $anchorTag.remove();
583
- _setRangeCursor($targetNode, $targetNode, 0, $targetNode.textContent?.length ?? 0);
584
- }
585
- }
586
- }
587
- }
588
- export function _getAnchorTagValue(store) {
589
- let href = "";
590
- if (store.cursorData !== null) {
591
- const $element = _findContentEditableElement(store.cursorData.startNode);
592
- if ($element !== null) {
593
- const cursorData = _soltingCursorDataOnElement(store.cursorData, $element);
594
- if (cursorData.startNode.constructor.name === "HTMLAnchorElement") {
595
- if (store.cursorData.type === "Range") {
596
- if (cursorData.startNodeIdx !== cursorData.endNodeIdx) {
597
- return href;
598
- }
599
- }
600
- const $anchorTag = cursorData.startNode;
601
- href = $anchorTag.href;
602
- }
603
- }
604
- }
605
- return href;
606
- }
607
- function findPoverTextNode(node, idx) {
608
- if (node.previousSibling !== null) {
609
- if (node.previousSibling.constructor.name === "Text") {
610
- return findPoverTextNode(node.previousSibling, idx -= 1);
611
- } else {
612
- return idx;
613
- }
614
- } else {
615
- return idx;
616
- }
617
- }
File without changes