el-text-editor 0.0.66 → 0.0.68

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.
@@ -41,6 +41,7 @@ class ElTextEditorComponent {
41
41
  this.imageEdit2 = new EventEmitter();
42
42
  this.placeHolderRemove = new EventEmitter();
43
43
  this.isOpen = new EventEmitter();
44
+ this.newImageAdded = new EventEmitter();
44
45
  this.value = '';
45
46
  this.showToolbar = false;
46
47
  this.toolbarTop = 0;
@@ -293,12 +294,65 @@ class ElTextEditorComponent {
293
294
  }
294
295
  return userRoleName;
295
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
+ // }
296
351
  addClickListenerToImages() {
297
352
  const editor = document.getElementById('editor');
298
353
  const roles = this.roleCheck(); // Get user roles dynamically
299
354
  const isAdmin = roles.includes('Admin');
300
355
  const isCreator = roles.includes('Creator');
301
- const isApprover = roles.includes('Approver');
302
356
  if (isCreator || isAdmin) {
303
357
  if (editor) {
304
358
  editor.addEventListener('click', (event) => {
@@ -339,15 +393,31 @@ class ElTextEditorComponent {
339
393
  container.appendChild(button);
340
394
  }
341
395
  else {
342
- this.selectedImage = null;
343
- this.selectedItemIndex = null;
344
- const buttons = document.querySelectorAll('.image-edit-button');
345
- buttons.forEach(button => button.remove());
396
+ this.removeEditButtons();
346
397
  }
347
398
  });
399
+ // Monitor editor content changes to handle image deletion
400
+ const observer = new MutationObserver(() => {
401
+ const buttons = editor.querySelectorAll('.image-edit-button');
402
+ buttons.forEach((button) => {
403
+ const container = button.parentElement;
404
+ if (container && !container.querySelector('img')) {
405
+ button.remove(); // Remove the button if the associated image is gone
406
+ container.remove(); // Clean up the container
407
+ }
408
+ });
409
+ });
410
+ // Observe changes in the editor
411
+ observer.observe(editor, { childList: true, subtree: true });
348
412
  }
349
413
  }
350
414
  }
415
+ removeEditButtons() {
416
+ const buttons = document.querySelectorAll('.image-edit-button');
417
+ buttons.forEach((button) => button.remove());
418
+ this.selectedImage = null;
419
+ this.selectedItemIndex = null;
420
+ }
351
421
  // private addClickListenerToImages() {
352
422
  // const editor = document.getElementById('editor');
353
423
  // if (editor) {
@@ -458,9 +528,6 @@ class ElTextEditorComponent {
458
528
  if (value) {
459
529
  const VALUE = value;
460
530
  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
531
  this.onChange(VALUE);
465
532
  this.editorTextChange.emit(VALUE);
466
533
  }
@@ -846,6 +913,7 @@ class ElTextEditorComponent {
846
913
  const imgHTML = imgWidth > editorWidth
847
914
  ? `<img src="${img.src}" style="width: 100%; max-width: ${editorWidth}px; height: auto;">`
848
915
  : `<img src="${img.src}" style="width: ${imgWidth}px; height: auto;">`;
916
+ this.newImageAdded.emit();
849
917
  // Insert the image into the editor
850
918
  document.execCommand('insertHTML', false, imgHTML);
851
919
  };
@@ -1164,73 +1232,24 @@ class ElTextEditorComponent {
1164
1232
  document.execCommand('foreColor', false, event);
1165
1233
  // this.logs.unshift([this.logs.length + 1, trigger, event]);
1166
1234
  }
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
1235
  editImage() {
1207
1236
  let data;
1208
1237
  console.log('this.editorFrom =', this.editorFrom);
1209
1238
  switch (this.editorFrom.name) {
1210
1239
  case 'section-content':
1211
- data = {
1212
- editIMG: true,
1213
- from: 'htmlEditor',
1214
- index: this.selectedItemIndex,
1215
- id: this.editorFrom.id,
1216
- };
1240
+ data = { editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex, id: this.editorFrom.id };
1217
1241
  const compressedData = compress(JSON.stringify(this.imageEditUrl));
1218
1242
  sessionStorage.setItem('editImageFromTemp', compressedData);
1219
1243
  const compressedData2 = compress(JSON.stringify(this.sanitizedContent));
1220
1244
  sessionStorage.setItem('textEditor', compressedData2);
1245
+ // alert('go to editor!')
1221
1246
  this.navigateToIMGEditor(data);
1222
1247
  this.imageEdit.emit();
1223
1248
  break;
1224
1249
  case 'create-document':
1225
1250
  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
- };
1251
+ data = { editIMG: true, from: 'createDocument', index: this.selectedItemIndex, id: this.editorFrom.id, section: this.editorFrom.section, reportSectionId: this.editorFrom.reportSectionId };
1252
+ // this.openDialog(data)
1234
1253
  const compressedData3 = compress(JSON.stringify(this.imageEditUrl));
1235
1254
  const compressedData4 = compress(this.editorText);
1236
1255
  sessionStorage.setItem('editImageFromTemp2', compressedData3);
@@ -1239,8 +1258,18 @@ class ElTextEditorComponent {
1239
1258
  break;
1240
1259
  default:
1241
1260
  null;
1261
+ // sessionStorage.removeItem('editImageFromTemp');
1262
+ // sessionStorage.removeItem('editImageFromTemp2');
1263
+ // sessionStorage.removeItem('templateEditor');
1264
+ // sessionStorage.removeItem('textEditor');
1242
1265
  break;
1243
1266
  }
1267
+ // if (this.editorFrom === 'section-content') {
1268
+ // const data = {editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex}
1269
+ // this.navigateToIMGEditor(data)
1270
+ // sessionStorage.setItem('editImageFromTemp', JSON.stringify(this.imageEditUrl))
1271
+ // sessionStorage.setItem('textEditor', this.editorText)
1272
+ // }
1244
1273
  }
1245
1274
  openDialog(item) {
1246
1275
  // let data: any;
@@ -1589,7 +1618,7 @@ class ElTextEditorComponent {
1589
1618
  }
1590
1619
  }
1591
1620
  ElTextEditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: ElTextEditorComponent, deps: [{ token: i1.Router }, { token: i1.ActivatedRoute }, { token: i0.Renderer2 }, { token: i2.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
1592
- ElTextEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.7", type: ElTextEditorComponent, selector: "text-editor", inputs: { editorText: "editorText", editorFrom: "editorFrom", editorAction: "editorAction", UserRole: "UserRole", style: "style", disableToolbar: "disableToolbar", placeHolder: "placeHolder", reportId: "reportId", backgroundImage: "backgroundImage", toolbarMode: "toolbarMode", value: "value" }, outputs: { editorTextChange: "editorTextChange", editorActionResponse: "editorActionResponse", editorTextClear: "editorTextClear", imageEdit: "imageEdit", imageEdit2: "imageEdit2", placeHolderRemove: "placeHolderRemove", isOpen: "isOpen" }, providers: [{
1621
+ ElTextEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.7", type: ElTextEditorComponent, selector: "text-editor", inputs: { editorText: "editorText", editorFrom: "editorFrom", editorAction: "editorAction", UserRole: "UserRole", style: "style", disableToolbar: "disableToolbar", placeHolder: "placeHolder", reportId: "reportId", backgroundImage: "backgroundImage", toolbarMode: "toolbarMode", value: "value" }, outputs: { editorTextChange: "editorTextChange", editorActionResponse: "editorActionResponse", editorTextClear: "editorTextClear", imageEdit: "imageEdit", imageEdit2: "imageEdit2", placeHolderRemove: "placeHolderRemove", isOpen: "isOpen", newImageAdded: "newImageAdded" }, providers: [{
1593
1622
  provide: NG_VALUE_ACCESSOR,
1594
1623
  useExisting: forwardRef(() => ElTextEditorComponent),
1595
1624
  multi: true
@@ -1635,6 +1664,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImpor
1635
1664
  type: Output
1636
1665
  }], isOpen: [{
1637
1666
  type: Output
1667
+ }], newImageAdded: [{
1668
+ type: Output
1638
1669
  }], value: [{
1639
1670
  type: Input
1640
1671
  }], TextEditor: [{