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