el-text-editor 0.0.77 → 0.0.79
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.
@@ -360,6 +360,13 @@ class ElTextEditorComponent {
|
|
360
360
|
if (target.tagName === 'IMG') {
|
361
361
|
this.selectedImage = target;
|
362
362
|
this.imageEditUrl = this.selectedImage.src;
|
363
|
+
const images = editor.getElementsByTagName('img');
|
364
|
+
for (let i = 0; i < images.length; i++) {
|
365
|
+
if (images[i] === this.selectedImage) {
|
366
|
+
this.selectedItemIndex = i;
|
367
|
+
break;
|
368
|
+
}
|
369
|
+
}
|
363
370
|
let container = this.selectedImage.parentElement;
|
364
371
|
if (!container || container.className !== 'image-container') {
|
365
372
|
container = document.createElement('div');
|
@@ -1168,24 +1175,58 @@ class ElTextEditorComponent {
|
|
1168
1175
|
inputElement.click();
|
1169
1176
|
}
|
1170
1177
|
}
|
1178
|
+
// setTextColor(event: any) {
|
1179
|
+
// if (this.savedSelection) {
|
1180
|
+
// const color = event.target.value;
|
1181
|
+
// this.selectedTextColor = color;
|
1182
|
+
// // Restore the saved selection
|
1183
|
+
// const selection = window.getSelection();
|
1184
|
+
// if (selection) {
|
1185
|
+
// selection.removeAllRanges();
|
1186
|
+
// selection.addRange(this.savedSelection);
|
1187
|
+
// // Apply the color using a span
|
1188
|
+
// const range = this.savedSelection;
|
1189
|
+
// const span = document.createElement('span');
|
1190
|
+
// span.style.color = color;
|
1191
|
+
// span.textContent = range.toString();
|
1192
|
+
// // Replace the selected text with the styled span
|
1193
|
+
// range.deleteContents();
|
1194
|
+
// range.insertNode(span);
|
1195
|
+
// // Clear the saved selection
|
1196
|
+
// this.savedSelection = null;
|
1197
|
+
// }
|
1198
|
+
// }
|
1199
|
+
// }
|
1171
1200
|
setTextColor(event) {
|
1172
1201
|
if (this.savedSelection) {
|
1173
1202
|
const color = event.target.value;
|
1174
1203
|
this.selectedTextColor = color;
|
1175
1204
|
// Restore the saved selection
|
1176
1205
|
const selection = window.getSelection();
|
1177
|
-
if (selection) {
|
1178
|
-
selection.removeAllRanges();
|
1179
|
-
selection.addRange(this.savedSelection);
|
1180
|
-
// Apply the color using a span
|
1206
|
+
if (selection && selection.rangeCount > 0) {
|
1181
1207
|
const range = this.savedSelection;
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1208
|
+
selection.removeAllRanges();
|
1209
|
+
selection.addRange(range);
|
1210
|
+
// Get selected elements
|
1211
|
+
const selectedContent = range.cloneContents();
|
1212
|
+
const elements = Array.from(selectedContent.querySelectorAll("*")); // ✅ Explicitly cast to HTMLElement[]
|
1213
|
+
// Apply color to each element without modifying structure
|
1214
|
+
elements.forEach((el) => {
|
1215
|
+
el.style.color = color;
|
1216
|
+
});
|
1217
|
+
// Apply color to the top-level text nodes (without wrapping them)
|
1218
|
+
Array.from(selectedContent.childNodes).forEach((node) => {
|
1219
|
+
if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim() !== "") {
|
1220
|
+
const parent = range.commonAncestorContainer.parentElement;
|
1221
|
+
if (parent) {
|
1222
|
+
parent.style.color = color;
|
1223
|
+
}
|
1224
|
+
}
|
1225
|
+
});
|
1226
|
+
// Replace selected content
|
1186
1227
|
range.deleteContents();
|
1187
|
-
range.insertNode(
|
1188
|
-
// Clear
|
1228
|
+
range.insertNode(selectedContent);
|
1229
|
+
// Clear saved selection
|
1189
1230
|
this.savedSelection = null;
|
1190
1231
|
}
|
1191
1232
|
}
|