el-text-editor 0.0.78 → 0.0.80

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.
@@ -1013,13 +1013,25 @@ class ElTextEditorComponent {
1013
1013
  addRow() {
1014
1014
  if (this.selectedTable) {
1015
1015
  let row = this.selectedTable.insertRow();
1016
- row.style.borderBottom = this.themeModeClrVerticalLineForTable(); // Add bottom border to the row
1016
+ // Loop through the columns of the first row to determine the number of cells
1017
1017
  for (let i = 0; i < this.selectedTable.rows[0].cells.length; i++) {
1018
1018
  let cell = row.insertCell(i);
1019
1019
  cell.innerHTML = '&nbsp;';
1020
+ // Apply bottom border explicitly
1021
+ cell.style.borderBottom = `2px solid ${this.themeModeClrVerticalLineColorForTable()}`; // You can replace 'black' with your theme color
1020
1022
  }
1021
1023
  }
1022
1024
  }
1025
+ // addRow() {
1026
+ // if (this.selectedTable) {
1027
+ // let row = this.selectedTable.insertRow();
1028
+ // row.style.borderBottom = this.themeModeClrVerticalLineForTable(); // Add bottom border to the row
1029
+ // for (let i = 0; i < this.selectedTable.rows[0].cells.length; i++) {
1030
+ // let cell = row.insertCell(i);
1031
+ // cell.innerHTML = '&nbsp;';
1032
+ // }
1033
+ // }
1034
+ // }
1023
1035
  // deleteRow() {
1024
1036
  // if (this.selectedTable) {
1025
1037
  // this.selectedTable.deleteRow(-1);
@@ -1099,6 +1111,7 @@ class ElTextEditorComponent {
1099
1111
  cell.style.wordBreak = 'break-all';
1100
1112
  cell.style.whiteSpace = 'normal';
1101
1113
  cell.style.minWidth = `${minWidth}px`;
1114
+ cell.style.borderBottom = `2px solid ${this.themeModeClrVerticalLineColorForTable()}`;
1102
1115
  }
1103
1116
  // Update existing rows' bottom border
1104
1117
  for (let i = 0; i < this.selectedTable.rows.length; i++) {
@@ -1131,6 +1144,15 @@ class ElTextEditorComponent {
1131
1144
  return '2px solid #5F5F5F !important';
1132
1145
  }
1133
1146
  }
1147
+ themeModeClrVerticalLineColorForTable() {
1148
+ const clrMode = document.body.getAttribute('data-layout-color');
1149
+ if (clrMode == 'dark') {
1150
+ return '#414141';
1151
+ }
1152
+ else {
1153
+ return '#5F5F5F';
1154
+ }
1155
+ }
1134
1156
  adjustTableWidth(event) {
1135
1157
  if (this.selectedTable) {
1136
1158
  this.selectedTable.style.width = event.target.value + 'px';
@@ -1175,24 +1197,58 @@ class ElTextEditorComponent {
1175
1197
  inputElement.click();
1176
1198
  }
1177
1199
  }
1200
+ // setTextColor(event: any) {
1201
+ // if (this.savedSelection) {
1202
+ // const color = event.target.value;
1203
+ // this.selectedTextColor = color;
1204
+ // // Restore the saved selection
1205
+ // const selection = window.getSelection();
1206
+ // if (selection) {
1207
+ // selection.removeAllRanges();
1208
+ // selection.addRange(this.savedSelection);
1209
+ // // Apply the color using a span
1210
+ // const range = this.savedSelection;
1211
+ // const span = document.createElement('span');
1212
+ // span.style.color = color;
1213
+ // span.textContent = range.toString();
1214
+ // // Replace the selected text with the styled span
1215
+ // range.deleteContents();
1216
+ // range.insertNode(span);
1217
+ // // Clear the saved selection
1218
+ // this.savedSelection = null;
1219
+ // }
1220
+ // }
1221
+ // }
1178
1222
  setTextColor(event) {
1179
1223
  if (this.savedSelection) {
1180
1224
  const color = event.target.value;
1181
1225
  this.selectedTextColor = color;
1182
1226
  // Restore the saved selection
1183
1227
  const selection = window.getSelection();
1184
- if (selection) {
1185
- selection.removeAllRanges();
1186
- selection.addRange(this.savedSelection);
1187
- // Apply the color using a span
1228
+ if (selection && selection.rangeCount > 0) {
1188
1229
  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
1230
+ selection.removeAllRanges();
1231
+ selection.addRange(range);
1232
+ // Get selected elements
1233
+ const selectedContent = range.cloneContents();
1234
+ const elements = Array.from(selectedContent.querySelectorAll("*")); // ✅ Explicitly cast to HTMLElement[]
1235
+ // Apply color to each element without modifying structure
1236
+ elements.forEach((el) => {
1237
+ el.style.color = color;
1238
+ });
1239
+ // Apply color to the top-level text nodes (without wrapping them)
1240
+ Array.from(selectedContent.childNodes).forEach((node) => {
1241
+ if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim() !== "") {
1242
+ const parent = range.commonAncestorContainer.parentElement;
1243
+ if (parent) {
1244
+ parent.style.color = color;
1245
+ }
1246
+ }
1247
+ });
1248
+ // Replace selected content
1193
1249
  range.deleteContents();
1194
- range.insertNode(span);
1195
- // Clear the saved selection
1250
+ range.insertNode(selectedContent);
1251
+ // Clear saved selection
1196
1252
  this.savedSelection = null;
1197
1253
  }
1198
1254
  }