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