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