dragon-editor 3.4.5 → 3.5.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.
- package/README.md +9 -15
- package/dist/module.d.mts +5 -0
- package/dist/module.json +8 -1
- package/dist/module.mjs +6 -4
- package/dist/runtime/components/DragonEditor.vue +252 -734
- package/dist/runtime/components/DragonEditorViewer.vue +59 -45
- package/dist/runtime/scss/editor.css +83 -34
- package/dist/runtime/scss/viewer.css +31 -4
- package/dist/runtime/type.d.ts +89 -42
- package/dist/runtime/utils/event/block.d.ts +0 -0
- package/dist/runtime/utils/event/block.js +78 -0
- package/dist/runtime/utils/event/cursor.d.ts +0 -0
- package/dist/runtime/utils/{cursor.mjs → event/cursor.js} +4 -16
- package/dist/runtime/utils/event/data.d.ts +0 -0
- package/dist/runtime/utils/event/data.js +342 -0
- package/dist/runtime/utils/event/index.d.ts +8 -0
- package/dist/runtime/utils/event/index.js +8 -0
- package/dist/runtime/utils/event/keyboard.d.ts +0 -0
- package/dist/runtime/utils/event/keyboard.js +1368 -0
- package/dist/runtime/utils/event/mouse.d.ts +0 -0
- package/dist/runtime/utils/event/mouse.js +70 -0
- package/dist/runtime/utils/event/scroll.d.ts +0 -0
- package/dist/runtime/utils/event/scroll.js +29 -0
- package/dist/runtime/utils/event/touch.d.ts +0 -0
- package/dist/runtime/utils/event/touch.js +10 -0
- package/dist/runtime/utils/event/window.d.ts +0 -0
- package/dist/runtime/utils/event/window.js +32 -0
- package/dist/runtime/utils/layout/block.d.ts +0 -0
- package/dist/runtime/utils/layout/block.js +105 -0
- package/dist/runtime/utils/layout/body.d.ts +0 -0
- package/dist/runtime/utils/layout/body.js +22 -0
- package/dist/runtime/utils/layout/controlbar.d.ts +0 -0
- package/dist/runtime/utils/layout/controlbar.js +99 -0
- package/dist/runtime/utils/layout/icon.d.ts +0 -0
- package/dist/runtime/utils/layout/icon.js +156 -0
- package/dist/runtime/utils/layout/index.d.ts +5 -0
- package/dist/runtime/utils/layout/index.js +5 -0
- package/dist/runtime/utils/layout/menuBar.d.ts +0 -0
- package/dist/runtime/utils/layout/menuBar.js +358 -0
- package/dist/runtime/utils/node/block.d.ts +0 -0
- package/dist/runtime/utils/node/block.js +235 -0
- package/dist/runtime/utils/{element.d.ts → node/element.d.ts} +1 -0
- package/dist/runtime/utils/{element.mjs → node/element.js} +11 -0
- package/dist/runtime/utils/node/index.d.ts +2 -0
- package/dist/runtime/utils/node/index.js +2 -0
- package/dist/runtime/utils/style/anchor.d.ts +0 -0
- package/dist/runtime/utils/style/anchor.js +240 -0
- package/dist/runtime/utils/style/decoration.d.ts +0 -0
- package/dist/runtime/utils/style/decoration.js +378 -0
- package/dist/runtime/utils/style/index.d.ts +2 -0
- package/dist/runtime/utils/style/index.js +2 -0
- package/dist/types.d.mts +7 -0
- package/dist/types.d.ts +3 -3
- package/package.json +15 -16
- package/dist/runtime/store.d.ts +0 -11
- package/dist/runtime/store.mjs +0 -51
- package/dist/runtime/utils/block.d.ts +0 -13
- package/dist/runtime/utils/block.mjs +0 -144
- package/dist/runtime/utils/content.d.ts +0 -2
- package/dist/runtime/utils/content.mjs +0 -19
- package/dist/runtime/utils/controlBar.d.ts +0 -9
- package/dist/runtime/utils/controlBar.mjs +0 -172
- package/dist/runtime/utils/convertor.d.ts +0 -3
- package/dist/runtime/utils/convertor.mjs +0 -138
- package/dist/runtime/utils/cursor.d.ts +0 -6
- package/dist/runtime/utils/keyboardEvent.d.ts +0 -10
- package/dist/runtime/utils/keyboardEvent.mjs +0 -979
- package/dist/runtime/utils/style.d.ts +0 -5
- package/dist/runtime/utils/style.mjs +0 -617
- /package/dist/runtime/{plugin.mjs → plugin.js} +0 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { _setRangeCursor, _updateCursorData, _updateModelData, _sortingCursorDataOnElement } from "../event/index.js";
|
|
2
|
+
import { _findContentEditableElement, _findPoverTextNode } from "../node/index.js";
|
|
3
|
+
export function _setAnchorTag(url, isOutsideLink, store) {
|
|
4
|
+
if (store.value.controlStatus.previousCorsorData !== null && store.value.controlStatus.$currentBlock !== null) {
|
|
5
|
+
const cursorData = store.value.controlStatus.previousCorsorData;
|
|
6
|
+
const $block = store.value.controlStatus.$currentBlock;
|
|
7
|
+
const typeIgnoreList = ["image", "code", "custom"];
|
|
8
|
+
const hrefValue = isOutsideLink === true ? url : `#${url}`;
|
|
9
|
+
const $element = _findContentEditableElement(cursorData.startNode);
|
|
10
|
+
if (typeIgnoreList.includes(store.value.controlStatus.currentBlockType) === false && $element !== null) {
|
|
11
|
+
if (cursorData.type === "Caret") {
|
|
12
|
+
if ($element.hasChildNodes() === true) {
|
|
13
|
+
let $target = 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 += `<a class="de-link"`;
|
|
32
|
+
structure += `href="${hrefValue}"`;
|
|
33
|
+
if (isOutsideLink === true) {
|
|
34
|
+
structure += `target="_blank"`;
|
|
35
|
+
}
|
|
36
|
+
structure += `>`;
|
|
37
|
+
structure += `${node.textContent}</a>`;
|
|
38
|
+
} else {
|
|
39
|
+
if (node.constructor.name === "Text") {
|
|
40
|
+
structure += node.textContent;
|
|
41
|
+
} else {
|
|
42
|
+
structure += node.outerHTML;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
$element.innerHTML = structure;
|
|
47
|
+
const targetElement = $element.childNodes[targetIdx];
|
|
48
|
+
_setRangeCursor(targetElement, targetElement, 0, targetElement.textContent?.length ?? 0);
|
|
49
|
+
} else {
|
|
50
|
+
if ($parentElement.tagName === "A") {
|
|
51
|
+
$parentElement.href = hrefValue;
|
|
52
|
+
if (isOutsideLink === true) {
|
|
53
|
+
$parentElement.target = "_blank";
|
|
54
|
+
} else {
|
|
55
|
+
$parentElement.removeAttribute("target");
|
|
56
|
+
}
|
|
57
|
+
_setRangeCursor($parentElement, $parentElement, 0, $parentElement.textContent?.length ?? 0);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
const newCursorData = _sortingCursorDataOnElement(cursorData, $element);
|
|
64
|
+
let structure = "";
|
|
65
|
+
let isDuble = false;
|
|
66
|
+
if (newCursorData.startNodeIdx === newCursorData.endNodeIdx) {
|
|
67
|
+
if (newCursorData.startNode.constructor.name === "Text") {
|
|
68
|
+
$element.childNodes.forEach((childNode, i) => {
|
|
69
|
+
if (newCursorData.startNodeIdx === i) {
|
|
70
|
+
if (newCursorData.startOffset !== 0) {
|
|
71
|
+
structure += childNode.textContent.slice(0, newCursorData.startOffset);
|
|
72
|
+
isDuble = true;
|
|
73
|
+
}
|
|
74
|
+
structure += `<a class="de-link"`;
|
|
75
|
+
structure += `href="${hrefValue}"`;
|
|
76
|
+
if (isOutsideLink === true) {
|
|
77
|
+
structure += `target="_blank"`;
|
|
78
|
+
}
|
|
79
|
+
structure += `>`;
|
|
80
|
+
structure += `${childNode.textContent.slice(newCursorData.startOffset, newCursorData.endOffset)}</a>`;
|
|
81
|
+
if (newCursorData.endOffset !== childNode.textContent.length) {
|
|
82
|
+
structure += childNode.textContent.slice(newCursorData.endOffset);
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
if (childNode.constructor.name === "Text") {
|
|
86
|
+
structure += childNode.textContent;
|
|
87
|
+
} else {
|
|
88
|
+
structure += childNode.outerHTML;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
let childNumber = newCursorData.startNodeIdx;
|
|
93
|
+
if (isDuble === true) {
|
|
94
|
+
childNumber += 1;
|
|
95
|
+
}
|
|
96
|
+
$element.innerHTML = structure;
|
|
97
|
+
const targetNode = $element.childNodes[childNumber];
|
|
98
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
99
|
+
} else {
|
|
100
|
+
const $target = newCursorData.startNode;
|
|
101
|
+
if ($target.tagName !== "A") {
|
|
102
|
+
const classList = $target.classList.value.split(" ");
|
|
103
|
+
if (newCursorData.startOffset !== 0) {
|
|
104
|
+
structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(0, newCursorData.startOffset)}</span>`;
|
|
105
|
+
isDuble = true;
|
|
106
|
+
}
|
|
107
|
+
structure += `<a class="de-link"`;
|
|
108
|
+
structure += `href="${hrefValue}"`;
|
|
109
|
+
if (isOutsideLink === true) {
|
|
110
|
+
structure += `target="_blank"`;
|
|
111
|
+
}
|
|
112
|
+
structure += `>`;
|
|
113
|
+
structure += `${$target.textContent.slice(newCursorData.startOffset, newCursorData.endOffset)}</a>`;
|
|
114
|
+
if (newCursorData.endOffset !== $target.textContent.length) {
|
|
115
|
+
structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(newCursorData.endOffset)}</span>`;
|
|
116
|
+
}
|
|
117
|
+
$target.insertAdjacentHTML("afterend", structure);
|
|
118
|
+
let $nextElement = $target.nextSibling;
|
|
119
|
+
if (isDuble === true) {
|
|
120
|
+
$nextElement = $nextElement.nextSibling;
|
|
121
|
+
}
|
|
122
|
+
$target.remove();
|
|
123
|
+
const targetNode = $nextElement;
|
|
124
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
125
|
+
} else {
|
|
126
|
+
$target.href = hrefValue;
|
|
127
|
+
if (isOutsideLink === true) {
|
|
128
|
+
$target.target = "_blank";
|
|
129
|
+
} else {
|
|
130
|
+
$target.removeAttribute("target");
|
|
131
|
+
}
|
|
132
|
+
_setRangeCursor($target, $target, 0, $target.textContent?.length ?? 0);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
let preStructure = "";
|
|
137
|
+
let anchorTextContent = "";
|
|
138
|
+
let nextStructure = "";
|
|
139
|
+
$element.childNodes.forEach((childNode, i) => {
|
|
140
|
+
const $elementNode = childNode;
|
|
141
|
+
let isText = childNode.constructor.name === "Text";
|
|
142
|
+
if (newCursorData.startNodeIdx > i) {
|
|
143
|
+
if (isText === true) {
|
|
144
|
+
preStructure += childNode.textContent;
|
|
145
|
+
} else {
|
|
146
|
+
preStructure += $elementNode.outerHTML;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (newCursorData.startNodeIdx === i) {
|
|
150
|
+
if (isText === true) {
|
|
151
|
+
preStructure += childNode.textContent.slice(0, newCursorData.startOffset);
|
|
152
|
+
} else {
|
|
153
|
+
preStructure += `<span class="${childNode.classList.value}">${childNode.textContent.slice(0, newCursorData.startOffset)}</span>`;
|
|
154
|
+
}
|
|
155
|
+
anchorTextContent += childNode.textContent.slice(newCursorData.startOffset);
|
|
156
|
+
}
|
|
157
|
+
if (newCursorData.startNodeIdx < i && newCursorData.endNodeIdx > i) {
|
|
158
|
+
anchorTextContent += childNode.textContent;
|
|
159
|
+
}
|
|
160
|
+
if (newCursorData.endNodeIdx === i) {
|
|
161
|
+
anchorTextContent += childNode.textContent.slice(0, newCursorData.endOffset);
|
|
162
|
+
if (isText === true) {
|
|
163
|
+
nextStructure += childNode.textContent.slice(newCursorData.startOffset);
|
|
164
|
+
} else {
|
|
165
|
+
nextStructure += `<span class="${childNode.classList.value}">${childNode.textContent.slice(newCursorData.startOffset)}</span>`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (newCursorData.endNodeIdx < i) {
|
|
169
|
+
if (isText === true) {
|
|
170
|
+
nextStructure += childNode.textContent;
|
|
171
|
+
} else {
|
|
172
|
+
nextStructure += $elementNode.outerHTML;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
let anchorTag = "";
|
|
177
|
+
anchorTag += `<a class="de-link"`;
|
|
178
|
+
anchorTag += `href="${hrefValue}"`;
|
|
179
|
+
if (isOutsideLink === true) {
|
|
180
|
+
anchorTag += `target="_blank"`;
|
|
181
|
+
}
|
|
182
|
+
anchorTag += `>`;
|
|
183
|
+
anchorTag += anchorTextContent;
|
|
184
|
+
anchorTag += `</a>`;
|
|
185
|
+
$element.innerHTML = preStructure + anchorTag + nextStructure;
|
|
186
|
+
let targetNode = $element.childNodes[newCursorData.startNodeIdx];
|
|
187
|
+
if (newCursorData.startOffset !== 0) {
|
|
188
|
+
targetNode = $element.childNodes[newCursorData.startNodeIdx + 1];
|
|
189
|
+
}
|
|
190
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
_updateCursorData(store);
|
|
194
|
+
_updateModelData(store);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function _unsetAnchorTag(store) {
|
|
199
|
+
if (store.value.cursorData !== null) {
|
|
200
|
+
const cursorData = store.value.cursorData;
|
|
201
|
+
const $element = _findContentEditableElement(cursorData.startNode);
|
|
202
|
+
if ($element !== null) {
|
|
203
|
+
const newCursorData = _sortingCursorDataOnElement(cursorData, $element);
|
|
204
|
+
if (newCursorData.startNode.constructor.name === "HTMLAnchorElement") {
|
|
205
|
+
if (cursorData.type === "Range") {
|
|
206
|
+
if (newCursorData.startNodeIdx !== newCursorData.endNodeIdx) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const $anchorTag = newCursorData.startNode;
|
|
211
|
+
$anchorTag.insertAdjacentText("afterend", newCursorData.startNode.textContent ?? "");
|
|
212
|
+
const $targetNode = $anchorTag.nextSibling;
|
|
213
|
+
$anchorTag.remove();
|
|
214
|
+
_setRangeCursor($targetNode, $targetNode, 0, $targetNode.textContent?.length ?? 0);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export function _updateAnchorTagValue(store, previous = false) {
|
|
220
|
+
if (store.value.controlStatus.previousCorsorData !== null && store.value.cursorData !== null) {
|
|
221
|
+
const cursorData = previous === true ? store.value.controlStatus.previousCorsorData : store.value.cursorData;
|
|
222
|
+
if (cursorData.type === "Caret" || cursorData.type === "Range" && cursorData.startNode === cursorData.endNode) {
|
|
223
|
+
const $element = _findContentEditableElement(cursorData.startNode);
|
|
224
|
+
let $targetNode = cursorData.startNode;
|
|
225
|
+
if ($targetNode.constructor.name === "Text") {
|
|
226
|
+
if ($targetNode.parentElement !== $element) {
|
|
227
|
+
$targetNode = $targetNode.parentElement;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if ($targetNode.constructor.name === "HTMLAnchorElement") {
|
|
231
|
+
const $tag = $targetNode;
|
|
232
|
+
store.value.controlStatus.anchorHref = $tag.href;
|
|
233
|
+
} else {
|
|
234
|
+
store.value.controlStatus.anchorHref = "";
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
store.value.controlStatus.anchorHref = "";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { _setRangeCursor, _sortingCursorDataOnElement, _updateModelData, _updateCursorData } from "../event/index.js";
|
|
2
|
+
import { _findContentEditableElement, _findPoverTextNode } from "../node/index.js";
|
|
3
|
+
export function _setDecoration(className, store) {
|
|
4
|
+
if (store.value.cursorData !== null && store.value.controlStatus.$currentBlock !== null) {
|
|
5
|
+
const cursorData = store.value.cursorData;
|
|
6
|
+
const typeIgnoreList = ["image", "code", "custom"];
|
|
7
|
+
if (typeIgnoreList.includes(store.value.controlStatus.currentBlockType) === false) {
|
|
8
|
+
const $element = _findContentEditableElement(cursorData.startNode);
|
|
9
|
+
if ($element !== null) {
|
|
10
|
+
if (cursorData.type === "Caret") {
|
|
11
|
+
if ($element.hasChildNodes() === true) {
|
|
12
|
+
let $target = cursorData.startNode;
|
|
13
|
+
if ($target.constructor.name === "Text") {
|
|
14
|
+
const $parentElement = $target.parentElement;
|
|
15
|
+
if ($parentElement === $element) {
|
|
16
|
+
let childList = $element.childNodes;
|
|
17
|
+
let targetIdx = -1;
|
|
18
|
+
let structure = "";
|
|
19
|
+
for (let i = 0; childList.length > i; i += 1) {
|
|
20
|
+
if ($target === childList[i]) {
|
|
21
|
+
targetIdx = i;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
targetIdx = _findPoverTextNode(childList[targetIdx], targetIdx);
|
|
26
|
+
$element.innerHTML = $element.innerHTML;
|
|
27
|
+
childList = $element.childNodes;
|
|
28
|
+
childList.forEach((node, i) => {
|
|
29
|
+
if (i === targetIdx) {
|
|
30
|
+
structure += `<span class="${className}">${node.textContent}</span>`;
|
|
31
|
+
} else {
|
|
32
|
+
if (node.constructor.name === "Text") {
|
|
33
|
+
structure += node.textContent;
|
|
34
|
+
} else {
|
|
35
|
+
structure += node.outerHTML;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
$element.innerHTML = structure;
|
|
40
|
+
const targetElement = $element.childNodes[targetIdx];
|
|
41
|
+
_setRangeCursor(targetElement, targetElement, 0, targetElement.textContent?.length ?? 0);
|
|
42
|
+
} else {
|
|
43
|
+
if ($parentElement.tagName === "SPAN") {
|
|
44
|
+
const classList = $parentElement.classList.value.split(" ");
|
|
45
|
+
const classIdx = classList.indexOf(className);
|
|
46
|
+
if (classIdx === -1) {
|
|
47
|
+
$parentElement.classList.add(className);
|
|
48
|
+
const targetNode = $parentElement.childNodes[0];
|
|
49
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
50
|
+
} else {
|
|
51
|
+
if (classList.length === 1) {
|
|
52
|
+
$parentElement.insertAdjacentText("afterend", $parentElement.textContent);
|
|
53
|
+
const targetNode = $parentElement.nextSibling;
|
|
54
|
+
$parentElement.remove();
|
|
55
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
56
|
+
} else {
|
|
57
|
+
$parentElement.classList.remove(className);
|
|
58
|
+
const targetNode = $parentElement.childNodes[0];
|
|
59
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const newCursorData = _sortingCursorDataOnElement(cursorData, $element);
|
|
68
|
+
let structure = "";
|
|
69
|
+
let isDuble = false;
|
|
70
|
+
if (newCursorData.startNodeIdx === newCursorData.endNodeIdx) {
|
|
71
|
+
if (newCursorData.startNode.constructor.name === "Text") {
|
|
72
|
+
$element.childNodes.forEach((childNode, i) => {
|
|
73
|
+
if (newCursorData.startNodeIdx === i) {
|
|
74
|
+
if (newCursorData.startOffset !== 0) {
|
|
75
|
+
structure += childNode.textContent.slice(0, newCursorData.startOffset);
|
|
76
|
+
isDuble = true;
|
|
77
|
+
}
|
|
78
|
+
structure += `<span class="${className}">${childNode.textContent.slice(newCursorData.startOffset, newCursorData.endOffset)}</span>`;
|
|
79
|
+
if (newCursorData.endOffset !== childNode.textContent.length) {
|
|
80
|
+
structure += childNode.textContent.slice(newCursorData.endOffset);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
if (childNode.constructor.name === "Text") {
|
|
84
|
+
structure += childNode.textContent;
|
|
85
|
+
} else {
|
|
86
|
+
structure += childNode.outerHTML;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
let childNumber = newCursorData.startNodeIdx;
|
|
91
|
+
if (isDuble === true) {
|
|
92
|
+
childNumber += 1;
|
|
93
|
+
}
|
|
94
|
+
$element.innerHTML = structure;
|
|
95
|
+
const targetNode = $element.childNodes[childNumber];
|
|
96
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
97
|
+
} else {
|
|
98
|
+
const $target = newCursorData.startNode;
|
|
99
|
+
if ($target.tagName !== "A") {
|
|
100
|
+
const classList = $target.classList.value.split(" ");
|
|
101
|
+
const classIdx = classList.indexOf(className);
|
|
102
|
+
if (classIdx === -1) {
|
|
103
|
+
if (newCursorData.startOffset !== 0) {
|
|
104
|
+
structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(0, newCursorData.startOffset)}</span>`;
|
|
105
|
+
isDuble = true;
|
|
106
|
+
}
|
|
107
|
+
structure += `<span class="${classList.join(" ")} ${className}">${$target.textContent.slice(newCursorData.startOffset, newCursorData.endOffset)}</span>`;
|
|
108
|
+
if (newCursorData.endOffset !== $target.textContent.length) {
|
|
109
|
+
structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(newCursorData.endOffset)}</span>`;
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
if (newCursorData.startOffset !== 0) {
|
|
113
|
+
structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(0, newCursorData.startOffset)}</span>`;
|
|
114
|
+
isDuble = true;
|
|
115
|
+
}
|
|
116
|
+
if (classList.length === 1) {
|
|
117
|
+
structure += $target.textContent.slice(newCursorData.startOffset, newCursorData.endOffset);
|
|
118
|
+
} else {
|
|
119
|
+
const copyList = [...classList];
|
|
120
|
+
copyList.splice(classIdx, 1);
|
|
121
|
+
structure += `<span class="${copyList.join(" ")}">${$target.textContent.slice(newCursorData.startOffset, newCursorData.endOffset)}</span>`;
|
|
122
|
+
}
|
|
123
|
+
if (newCursorData.endOffset !== $target.textContent.length) {
|
|
124
|
+
structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(newCursorData.endOffset)}</span>`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
$target.insertAdjacentHTML("afterend", structure);
|
|
128
|
+
let $nextElement = $target.nextSibling;
|
|
129
|
+
if (isDuble === true) {
|
|
130
|
+
$nextElement = $nextElement.nextSibling;
|
|
131
|
+
}
|
|
132
|
+
$target.remove();
|
|
133
|
+
const targetNode = $nextElement;
|
|
134
|
+
_setRangeCursor(targetNode, targetNode, 0, targetNode.textContent?.length ?? 0);
|
|
135
|
+
} else {
|
|
136
|
+
alert(store.value.message.linkTextNoStyle);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
let isAnchorElement = false;
|
|
141
|
+
let isWrap = false;
|
|
142
|
+
let startNodeIdx = newCursorData.startNodeIdx;
|
|
143
|
+
let startOffset = newCursorData.startOffset;
|
|
144
|
+
let endNodeIdx = newCursorData.endNodeIdx;
|
|
145
|
+
let endOffset = newCursorData.endOffset;
|
|
146
|
+
let structureArray = [];
|
|
147
|
+
$element.childNodes.forEach((childNode, i) => {
|
|
148
|
+
const $elementNode = childNode;
|
|
149
|
+
let isText = childNode.constructor.name === "Text";
|
|
150
|
+
if (newCursorData.startNodeIdx > i) {
|
|
151
|
+
if (isText === true) {
|
|
152
|
+
structureArray.push(childNode.textContent);
|
|
153
|
+
} else {
|
|
154
|
+
structureArray.push($elementNode.outerHTML);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (newCursorData.startNodeIdx === i) {
|
|
158
|
+
const preTextContent = childNode.textContent.slice(0, newCursorData.startOffset);
|
|
159
|
+
const textContent = childNode.textContent.slice(newCursorData.startOffset);
|
|
160
|
+
if (isText === true) {
|
|
161
|
+
structureArray.push(preTextContent);
|
|
162
|
+
structureArray.push(`<span class="${className}">${textContent}</span>`);
|
|
163
|
+
isWrap = true;
|
|
164
|
+
if (newCursorData.startOffset !== 0) {
|
|
165
|
+
isDuble = true;
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
const classList = $elementNode.classList.value.split(" ");
|
|
169
|
+
const classIdx = classList.indexOf(className);
|
|
170
|
+
if ($elementNode.tagName === "SPAN") {
|
|
171
|
+
if (classIdx === -1) {
|
|
172
|
+
if (preTextContent !== "") {
|
|
173
|
+
structureArray.push(`<span class="${classList.join(" ")}">${preTextContent}</span>`);
|
|
174
|
+
}
|
|
175
|
+
structureArray.push(`<span class="${classList.join(" ")} ${className}">${textContent}</span>`);
|
|
176
|
+
isWrap = true;
|
|
177
|
+
} else {
|
|
178
|
+
if (classList.length === 1) {
|
|
179
|
+
if (preTextContent !== "") {
|
|
180
|
+
structureArray.push(`<span class="${classList.join(" ")}">${preTextContent}</span>`);
|
|
181
|
+
}
|
|
182
|
+
structureArray.push(textContent);
|
|
183
|
+
} else {
|
|
184
|
+
const newClassList = [...classList];
|
|
185
|
+
newClassList.splice(classIdx, 1);
|
|
186
|
+
if (preTextContent !== "") {
|
|
187
|
+
structureArray.push(`<span class="${classList.join(" ")}">${preTextContent}</span>`);
|
|
188
|
+
}
|
|
189
|
+
structureArray.push(`<span class="${newClassList.join(" ")}">${textContent}</span>`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} else if ($elementNode.tagName === "BR") {
|
|
193
|
+
structureArray.push("<br>");
|
|
194
|
+
} else {
|
|
195
|
+
isAnchorElement = true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (newCursorData.startNodeIdx < i && newCursorData.endNodeIdx > i) {
|
|
200
|
+
if (isText === true) {
|
|
201
|
+
if (isWrap === true) {
|
|
202
|
+
structureArray.push(`<span class="${className}">${childNode.textContent}</span>`);
|
|
203
|
+
} else {
|
|
204
|
+
structureArray.push(childNode.textContent);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
const classList = $elementNode.classList.value.split(" ");
|
|
208
|
+
const classIdx = classList.indexOf(className);
|
|
209
|
+
if ($elementNode.tagName === "SPAN") {
|
|
210
|
+
if (isWrap === true) {
|
|
211
|
+
if (classIdx === -1) {
|
|
212
|
+
structureArray.push(`<span class="${classList.join(" ")} ${className}">${childNode.textContent}</span>`);
|
|
213
|
+
} else {
|
|
214
|
+
structureArray.push($elementNode.outerHTML);
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
if (classIdx === -1) {
|
|
218
|
+
structureArray.push($elementNode.outerHTML);
|
|
219
|
+
} else {
|
|
220
|
+
if (classList.length === 1) {
|
|
221
|
+
structureArray.push(childNode.textContent);
|
|
222
|
+
} else {
|
|
223
|
+
const newClassList = [...classList];
|
|
224
|
+
newClassList.splice(classIdx, 1);
|
|
225
|
+
structureArray.push(`<span class="${newClassList.join(" ")}">${childNode.textContent}</span>`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
} else if ($elementNode.tagName === "BR") {
|
|
230
|
+
structureArray.push("<br>");
|
|
231
|
+
} else {
|
|
232
|
+
isAnchorElement = true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (newCursorData.endNodeIdx === i) {
|
|
237
|
+
const textContent = childNode.textContent.slice(0, newCursorData.endOffset);
|
|
238
|
+
const endTextContent = childNode.textContent.slice(newCursorData.endOffset);
|
|
239
|
+
if (isText === true) {
|
|
240
|
+
if (isWrap === true) {
|
|
241
|
+
structureArray.push(`<span class="${className}">${textContent}</span>`);
|
|
242
|
+
structureArray.push(endTextContent);
|
|
243
|
+
} else {
|
|
244
|
+
structureArray.push(childNode.textContent);
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
const classList = $elementNode.classList.value.split(" ");
|
|
248
|
+
const classIdx = classList.indexOf(className);
|
|
249
|
+
if ($elementNode.tagName === "SPAN") {
|
|
250
|
+
if (isWrap === true) {
|
|
251
|
+
if (classIdx === -1) {
|
|
252
|
+
structureArray.push(`<span class="${classList.join(" ")} ${className}">${textContent}</span>`);
|
|
253
|
+
if (endTextContent !== "") {
|
|
254
|
+
structureArray.push(`<span class="${classList.join(" ")}">${endTextContent}</span>`);
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
structureArray.push($elementNode.outerHTML);
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
if (classIdx === -1) {
|
|
261
|
+
structureArray.push($elementNode.outerHTML);
|
|
262
|
+
} else {
|
|
263
|
+
if (classList.length === 1) {
|
|
264
|
+
structureArray.push(textContent);
|
|
265
|
+
if (endTextContent !== "") {
|
|
266
|
+
structureArray.push(`<span class="${classList.join(" ")}">${endTextContent}</span>`);
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
const newClassList = [...classList];
|
|
270
|
+
newClassList.splice(classIdx, 1);
|
|
271
|
+
structureArray.push(`<span class="${newClassList.join(" ")}">${textContent}</span>`);
|
|
272
|
+
if (endTextContent !== "") {
|
|
273
|
+
structureArray.push(`<span class="${classList.join(" ")}">${endTextContent}</span>`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} else if ($elementNode.tagName === "BR") {
|
|
279
|
+
structureArray.push("<br>");
|
|
280
|
+
} else {
|
|
281
|
+
isAnchorElement = true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (newCursorData.endNodeIdx < i) {
|
|
286
|
+
if (isText === true) {
|
|
287
|
+
structureArray.push(childNode.textContent);
|
|
288
|
+
} else {
|
|
289
|
+
structureArray.push($elementNode.outerHTML);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
if (isAnchorElement === false) {
|
|
294
|
+
$element.innerHTML = structureArray.join("");
|
|
295
|
+
if (isWrap === true) {
|
|
296
|
+
if (isDuble === true) {
|
|
297
|
+
startNodeIdx += 1;
|
|
298
|
+
endNodeIdx += 1;
|
|
299
|
+
startOffset = 0;
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
const tagReg = new RegExp("(<([^>]+)>)", "i");
|
|
303
|
+
const isTagList = [];
|
|
304
|
+
let newStartNodeIdx = 0;
|
|
305
|
+
let newStartOffset = startOffset * 1;
|
|
306
|
+
let newEndOffset = 0;
|
|
307
|
+
let endMinusCount = 0;
|
|
308
|
+
structureArray.forEach((string, i) => {
|
|
309
|
+
const isTag = tagReg.test(string);
|
|
310
|
+
isTagList.push(isTag);
|
|
311
|
+
if (startNodeIdx <= i && i <= endNodeIdx) {
|
|
312
|
+
if (isTag === true) {
|
|
313
|
+
newEndOffset = 0;
|
|
314
|
+
} else {
|
|
315
|
+
endMinusCount += 1;
|
|
316
|
+
newEndOffset += string.length;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
if (isTagList[startNodeIdx - 1] === false) {
|
|
321
|
+
newStartNodeIdx = startNodeIdx - 1;
|
|
322
|
+
newStartOffset = startOffset + structureArray[startNodeIdx - 1].length;
|
|
323
|
+
}
|
|
324
|
+
if (isTagList.slice(startNodeIdx, endNodeIdx).includes(true) === true) {
|
|
325
|
+
endNodeIdx -= endMinusCount - 1;
|
|
326
|
+
endOffset = newEndOffset;
|
|
327
|
+
} else {
|
|
328
|
+
endNodeIdx = newStartNodeIdx;
|
|
329
|
+
endOffset = newStartOffset + newEndOffset;
|
|
330
|
+
}
|
|
331
|
+
startNodeIdx = newStartNodeIdx;
|
|
332
|
+
startOffset = newStartOffset;
|
|
333
|
+
}
|
|
334
|
+
_setRangeCursor($element.childNodes[startNodeIdx], $element.childNodes[endNodeIdx], startOffset, endOffset);
|
|
335
|
+
} else {
|
|
336
|
+
alert(store.value.message.linkTextNoStyle);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
_updateCursorData(store);
|
|
341
|
+
_updateModelData(store);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
export function _setTextAlign(type, store) {
|
|
347
|
+
if (store.value.cursorData !== null && store.value.controlStatus.$currentBlock !== null) {
|
|
348
|
+
const cursorData = store.value.cursorData;
|
|
349
|
+
const typeIgnoreList = ["code", "custom"];
|
|
350
|
+
if (typeIgnoreList.includes(store.value.controlStatus.currentBlockType) === false) {
|
|
351
|
+
const alignClassList = ["de-align-left", "de-align-right", "de-align-center", "de-align-justify"];
|
|
352
|
+
const className = `de-align-${type}`;
|
|
353
|
+
let $element = null;
|
|
354
|
+
if (store.value.controlStatus.$currentBlock.classList.contains("de-image-block") === true) {
|
|
355
|
+
$element = store.value.controlStatus.$currentBlock;
|
|
356
|
+
} else {
|
|
357
|
+
if (cursorData !== null) {
|
|
358
|
+
$element = _findContentEditableElement(cursorData.startNode);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if ($element !== null) {
|
|
362
|
+
if ($element.classList.contains(className) === true) {
|
|
363
|
+
$element.classList.remove(className);
|
|
364
|
+
} else {
|
|
365
|
+
const currentClassname = alignClassList.filter((text) => $element.classList.contains(text) === true)[0];
|
|
366
|
+
if (currentClassname !== void 0) {
|
|
367
|
+
$element.classList.remove(currentClassname);
|
|
368
|
+
}
|
|
369
|
+
$element.classList.add(className);
|
|
370
|
+
}
|
|
371
|
+
if (store.value.controlStatus.$currentBlock.classList.contains("de-image-block") !== true) {
|
|
372
|
+
}
|
|
373
|
+
_updateCursorData(store);
|
|
374
|
+
_updateModelData(store);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
package/dist/types.d.mts
ADDED
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
1
2
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import type { default as Module } from './module'
|
|
5
4
|
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
6
|
|
|
7
7
|
export { default } from './module'
|