el-text-editor 0.0.66 → 0.0.67

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.
@@ -293,12 +293,65 @@ class ElTextEditorComponent {
293
293
  }
294
294
  return userRoleName;
295
295
  }
296
+ // private addClickListenerToImages() {
297
+ // const editor = document.getElementById('editor');
298
+ // const roles = this.roleCheck(); // Get user roles dynamically
299
+ // const isAdmin = roles.includes('Admin');
300
+ // const isCreator = roles.includes('Creator');
301
+ // const isApprover = roles.includes('Approver');
302
+ // if (isCreator || isAdmin) {
303
+ // if (editor) {
304
+ // editor.addEventListener('click', (event) => {
305
+ // const target = event.target as HTMLElement;
306
+ // if (target.tagName === 'IMG') {
307
+ // this.selectedImage = target as HTMLImageElement;
308
+ // this.imageEditUrl = this.selectedImage.src;
309
+ // let container = this.selectedImage.parentElement;
310
+ // if (!container || container.className !== 'image-container') {
311
+ // container = document.createElement('div');
312
+ // container.className = 'image-container';
313
+ // container.style.position = 'relative';
314
+ // container.style.display = 'inline-block';
315
+ // this.selectedImage.parentNode?.insertBefore(container, this.selectedImage);
316
+ // container.appendChild(this.selectedImage);
317
+ // }
318
+ // const existingButton = container.querySelector('.image-edit-button');
319
+ // if (existingButton) {
320
+ // existingButton.remove();
321
+ // }
322
+ // const button = document.createElement('button');
323
+ // button.textContent = 'Edit Image';
324
+ // button.className = 'image-edit-button btn btn-sm';
325
+ // button.style.position = 'absolute';
326
+ // button.style.top = '50%';
327
+ // button.style.left = '50%';
328
+ // button.style.transform = 'translate(-50%, -50%)';
329
+ // button.style.zIndex = '1000';
330
+ // button.style.backgroundColor = '#fff';
331
+ // button.style.border = '2px solid #fff';
332
+ // button.style.color = '#313a46';
333
+ // button.style.cursor = 'pointer';
334
+ // button.style.userSelect = 'none';
335
+ // button.addEventListener('click', (e) => {
336
+ // e.stopPropagation();
337
+ // this.editImage();
338
+ // });
339
+ // container.appendChild(button);
340
+ // } else {
341
+ // this.selectedImage = null;
342
+ // this.selectedItemIndex = null;
343
+ // const buttons = document.querySelectorAll('.image-edit-button');
344
+ // buttons.forEach(button => button.remove());
345
+ // }
346
+ // });
347
+ // }
348
+ // }
349
+ // }
296
350
  addClickListenerToImages() {
297
351
  const editor = document.getElementById('editor');
298
352
  const roles = this.roleCheck(); // Get user roles dynamically
299
353
  const isAdmin = roles.includes('Admin');
300
354
  const isCreator = roles.includes('Creator');
301
- const isApprover = roles.includes('Approver');
302
355
  if (isCreator || isAdmin) {
303
356
  if (editor) {
304
357
  editor.addEventListener('click', (event) => {
@@ -339,15 +392,31 @@ class ElTextEditorComponent {
339
392
  container.appendChild(button);
340
393
  }
341
394
  else {
342
- this.selectedImage = null;
343
- this.selectedItemIndex = null;
344
- const buttons = document.querySelectorAll('.image-edit-button');
345
- buttons.forEach(button => button.remove());
395
+ this.removeEditButtons();
346
396
  }
347
397
  });
398
+ // Monitor editor content changes to handle image deletion
399
+ const observer = new MutationObserver(() => {
400
+ const buttons = editor.querySelectorAll('.image-edit-button');
401
+ buttons.forEach((button) => {
402
+ const container = button.parentElement;
403
+ if (container && !container.querySelector('img')) {
404
+ button.remove(); // Remove the button if the associated image is gone
405
+ container.remove(); // Clean up the container
406
+ }
407
+ });
408
+ });
409
+ // Observe changes in the editor
410
+ observer.observe(editor, { childList: true, subtree: true });
348
411
  }
349
412
  }
350
413
  }
414
+ removeEditButtons() {
415
+ const buttons = document.querySelectorAll('.image-edit-button');
416
+ buttons.forEach((button) => button.remove());
417
+ this.selectedImage = null;
418
+ this.selectedItemIndex = null;
419
+ }
351
420
  // private addClickListenerToImages() {
352
421
  // const editor = document.getElementById('editor');
353
422
  // if (editor) {
@@ -458,9 +527,6 @@ class ElTextEditorComponent {
458
527
  if (value) {
459
528
  const VALUE = value;
460
529
  this.editorText = VALUE;
461
- const editorContent = VALUE;
462
- // Check if there's an image in the editor content
463
- this.showEditButton = editorContent.includes('<img');
464
530
  this.onChange(VALUE);
465
531
  this.editorTextChange.emit(VALUE);
466
532
  }
@@ -1164,73 +1230,24 @@ class ElTextEditorComponent {
1164
1230
  document.execCommand('foreColor', false, event);
1165
1231
  // this.logs.unshift([this.logs.length + 1, trigger, event]);
1166
1232
  }
1167
- // editImage() {
1168
- // let data
1169
- // console.log('this.editorFrom =',this.editorFrom)
1170
- // switch (this.editorFrom.name) {
1171
- // case 'section-content':
1172
- // data = { editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex, id: this.editorFrom.id };
1173
- // const compressedData: string = compress(JSON.stringify(this.imageEditUrl));
1174
- // sessionStorage.setItem('editImageFromTemp', compressedData);
1175
- // const compressedData2 = compress(JSON.stringify(this.sanitizedContent));
1176
- // sessionStorage.setItem('textEditor', compressedData2);
1177
- // // alert('go to editor!')
1178
- // this.navigateToIMGEditor(data);
1179
- // this.imageEdit.emit()
1180
- // break;
1181
- // case 'create-document':
1182
- // this.imageEdit.emit()
1183
- // data = { editIMG: true, from: 'createDocument', index: this.selectedItemIndex, id: this.editorFrom.id, section: this.editorFrom.section, reportSectionId: this.editorFrom.reportSectionId };
1184
- // // this.openDialog(data)
1185
- // const compressedData3 = compress(JSON.stringify(this.imageEditUrl));
1186
- // const compressedData4 = compress(this.editorText);
1187
- // sessionStorage.setItem('editImageFromTemp2', compressedData3);
1188
- // sessionStorage.setItem('textEditor2', compressedData4);
1189
- // this.navigateToIMGEditor(data);
1190
- // break;
1191
- // default:
1192
- // null
1193
- // // sessionStorage.removeItem('editImageFromTemp');
1194
- // // sessionStorage.removeItem('editImageFromTemp2');
1195
- // // sessionStorage.removeItem('templateEditor');
1196
- // // sessionStorage.removeItem('textEditor');
1197
- // break;
1198
- // }
1199
- // // if (this.editorFrom === 'section-content') {
1200
- // // const data = {editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex}
1201
- // // this.navigateToIMGEditor(data)
1202
- // // sessionStorage.setItem('editImageFromTemp', JSON.stringify(this.imageEditUrl))
1203
- // // sessionStorage.setItem('textEditor', this.editorText)
1204
- // // }
1205
- // }
1206
1233
  editImage() {
1207
1234
  let data;
1208
1235
  console.log('this.editorFrom =', this.editorFrom);
1209
1236
  switch (this.editorFrom.name) {
1210
1237
  case 'section-content':
1211
- data = {
1212
- editIMG: true,
1213
- from: 'htmlEditor',
1214
- index: this.selectedItemIndex,
1215
- id: this.editorFrom.id,
1216
- };
1238
+ data = { editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex, id: this.editorFrom.id };
1217
1239
  const compressedData = compress(JSON.stringify(this.imageEditUrl));
1218
1240
  sessionStorage.setItem('editImageFromTemp', compressedData);
1219
1241
  const compressedData2 = compress(JSON.stringify(this.sanitizedContent));
1220
1242
  sessionStorage.setItem('textEditor', compressedData2);
1243
+ // alert('go to editor!')
1221
1244
  this.navigateToIMGEditor(data);
1222
1245
  this.imageEdit.emit();
1223
1246
  break;
1224
1247
  case 'create-document':
1225
1248
  this.imageEdit.emit();
1226
- data = {
1227
- editIMG: true,
1228
- from: 'createDocument',
1229
- index: this.selectedItemIndex,
1230
- id: this.editorFrom.id,
1231
- section: this.editorFrom.section,
1232
- reportSectionId: this.editorFrom.reportSectionId,
1233
- };
1249
+ data = { editIMG: true, from: 'createDocument', index: this.selectedItemIndex, id: this.editorFrom.id, section: this.editorFrom.section, reportSectionId: this.editorFrom.reportSectionId };
1250
+ // this.openDialog(data)
1234
1251
  const compressedData3 = compress(JSON.stringify(this.imageEditUrl));
1235
1252
  const compressedData4 = compress(this.editorText);
1236
1253
  sessionStorage.setItem('editImageFromTemp2', compressedData3);
@@ -1239,8 +1256,18 @@ class ElTextEditorComponent {
1239
1256
  break;
1240
1257
  default:
1241
1258
  null;
1259
+ // sessionStorage.removeItem('editImageFromTemp');
1260
+ // sessionStorage.removeItem('editImageFromTemp2');
1261
+ // sessionStorage.removeItem('templateEditor');
1262
+ // sessionStorage.removeItem('textEditor');
1242
1263
  break;
1243
1264
  }
1265
+ // if (this.editorFrom === 'section-content') {
1266
+ // const data = {editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex}
1267
+ // this.navigateToIMGEditor(data)
1268
+ // sessionStorage.setItem('editImageFromTemp', JSON.stringify(this.imageEditUrl))
1269
+ // sessionStorage.setItem('textEditor', this.editorText)
1270
+ // }
1244
1271
  }
1245
1272
  openDialog(item) {
1246
1273
  // let data: any;