dragon-editor 3.0.1 → 3.1.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.
@@ -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
- const $element = _findContentEditableElement(store.cursorData.startNode);
5
- if ($element !== null) {
6
- if (store.cursorData.type === "Caret") {
7
- if ($element.hasChildNodes() === true) {
8
- let $target = store.cursorData.startNode;
9
- if ($target.constructor.name === "Text") {
10
- const $parentElement = $target.parentElement;
11
- if ($parentElement === $element) {
12
- const childList = $element.childNodes;
13
- let targetIdx = -1;
14
- let structure = "";
15
- let cursorOffset = 0;
16
- for (let i = 0; childList.length > i; i += 1) {
17
- if ($target === childList[i]) {
18
- targetIdx = i;
19
- break;
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
- childList.forEach((node, i) => {
23
- if (i === targetIdx) {
24
- structure += `<span class="${className}">${node.textContent}</span>`;
25
- cursorOffset = node.textContent.length;
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 (node.constructor.name === "Text") {
28
- structure += node.textContent;
78
+ if (childNode.constructor.name === "Text") {
79
+ structure += childNode.textContent;
29
80
  } else {
30
- structure += node.outerHTML;
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[targetIdx], cursorOffset);
90
+ _setCursor($element.childNodes[childNumber], cursorData.endOffset - cursorData.startOffset);
36
91
  } else {
37
- if ($parentElement.tagName === "A") {
38
- alert(store.message.linkTextNoStyle);
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
- $parentElement.classList.add(className);
45
- _setCursor($parentElement.childNodes[0], store.cursorData.startOffset);
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
- $parentElement.insertAdjacentText("afterend", $parentElement.textContent);
49
- _setCursor($parentElement.nextSibling, store.cursorData.startOffset);
50
- $parentElement.remove();
111
+ structure += $target.textContent.slice(cursorData.startOffset, cursorData.endOffset);
51
112
  } else {
52
- $parentElement.classList.remove(className);
53
- _setCursor($parentElement.childNodes[0], store.cursorData.startOffset);
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
- const $target = cursorData.startNode;
92
- if ($target.tagName !== "A") {
93
- const classList = [...$target.classList];
94
- const classIdx = classList.indexOf(className);
95
- if (classIdx === -1) {
96
- if (cursorData.startOffset !== 0) {
97
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(0, cursorData.startOffset)}</span>`;
98
- isDuble = true;
99
- }
100
- structure += `<span class="${classList.join(" ")} ${className}">${$target.textContent.slice(cursorData.startOffset, cursorData.endOffset)}</span>`;
101
- if (cursorData.endOffset !== $target.textContent.length) {
102
- structure += `<span class="${classList.join(" ")}">${$target.textContent.slice(cursorData.endOffset)}</span>`;
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
- const copyList = [...classList];
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
- if (cursorData.startNodeIdx === i) {
148
- const preTextContent = childNode.textContent.slice(0, cursorData.startOffset);
149
- const textContent = childNode.textContent.slice(cursorData.startOffset);
150
- if (isText === true) {
151
- structureArray.push(preTextContent);
152
- structureArray.push(`<span class="${className}">${textContent}</span>`);
153
- isWrap = true;
154
- if (cursorData.startOffset !== 0) {
155
- isDuble = true;
156
- }
157
- } else {
158
- const classList = [...$elementNode.classList];
159
- const classIdx = classList.indexOf(className);
160
- if ($elementNode.tagName === "SPAN") {
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
- const newClassList = [...classList];
175
- newClassList.splice(classIdx, 1);
176
- if (preTextContent !== "") {
177
- structureArray.push(`<span class="${classList.join(" ")}">${preTextContent}</span>`);
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
- if (cursorData.startNodeIdx < i && cursorData.endNodeIdx > i) {
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
- if (classIdx === -1) {
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
- if (classIdx === -1) {
208
- structureArray.push($elementNode.outerHTML);
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 (classList.length === 1) {
211
- structureArray.push(childNode.textContent);
208
+ if (classIdx === -1) {
209
+ structureArray.push($elementNode.outerHTML);
212
210
  } else {
213
- const newClassList = [...classList];
214
- newClassList.splice(classIdx, 1);
215
- structureArray.push(`<span class="${newClassList.join(" ")}">${childNode.textContent}</span>`);
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
- if (cursorData.endNodeIdx === i) {
227
- const textContent = childNode.textContent.slice(0, cursorData.endOffset);
228
- const endTextContent = childNode.textContent.slice(cursorData.endOffset);
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
- if (classIdx === -1) {
242
- structureArray.push(`<span class="${classList.join(" ")} ${className}">${textContent}</span>`);
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
- if (classIdx === -1) {
251
- structureArray.push($elementNode.outerHTML);
252
- } else {
253
- if (classList.length === 1) {
254
- structureArray.push(textContent);
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
- const newClassList = [...classList];
260
- newClassList.splice(classIdx, 1);
261
- structureArray.push(`<span class="${newClassList.join(" ")}">${textContent}</span>`);
262
- if (endTextContent !== "") {
263
- structureArray.push(`<span class="${classList.join(" ")}">${endTextContent}</span>`);
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
- if (cursorData.endNodeIdx < i) {
276
- if (isText === true) {
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
- endMinusCount += 1;
305
- newEndOffset += string.length;
280
+ structureArray.push($elementNode.outerHTML);
306
281
  }
307
282
  }
308
283
  });
309
- if (isTagList[startNodeIdx - 1] === false) {
310
- newStartNodeIdx = startNodeIdx - 1;
311
- newStartOffset = startOffset + structureArray[startNodeIdx - 1].length;
312
- }
313
- if (isTagList.slice(startNodeIdx, endNodeIdx).includes(true) === true) {
314
- endNodeIdx -= endMinusCount - 1;
315
- endOffset = newEndOffset;
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
- endNodeIdx = newStartNodeIdx;
318
- endOffset = newStartOffset + newEndOffset;
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;