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