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;
@@ -294,12 +295,65 @@ class ElTextEditorComponent {
294
295
  }
295
296
  return userRoleName;
296
297
  }
298
+ // private addClickListenerToImages() {
299
+ // const editor = document.getElementById('editor');
300
+ // const roles = this.roleCheck(); // Get user roles dynamically
301
+ // const isAdmin = roles.includes('Admin');
302
+ // const isCreator = roles.includes('Creator');
303
+ // const isApprover = roles.includes('Approver');
304
+ // if (isCreator || isAdmin) {
305
+ // if (editor) {
306
+ // editor.addEventListener('click', (event) => {
307
+ // const target = event.target as HTMLElement;
308
+ // if (target.tagName === 'IMG') {
309
+ // this.selectedImage = target as HTMLImageElement;
310
+ // this.imageEditUrl = this.selectedImage.src;
311
+ // let container = this.selectedImage.parentElement;
312
+ // if (!container || container.className !== 'image-container') {
313
+ // container = document.createElement('div');
314
+ // container.className = 'image-container';
315
+ // container.style.position = 'relative';
316
+ // container.style.display = 'inline-block';
317
+ // this.selectedImage.parentNode?.insertBefore(container, this.selectedImage);
318
+ // container.appendChild(this.selectedImage);
319
+ // }
320
+ // const existingButton = container.querySelector('.image-edit-button');
321
+ // if (existingButton) {
322
+ // existingButton.remove();
323
+ // }
324
+ // const button = document.createElement('button');
325
+ // button.textContent = 'Edit Image';
326
+ // button.className = 'image-edit-button btn btn-sm';
327
+ // button.style.position = 'absolute';
328
+ // button.style.top = '50%';
329
+ // button.style.left = '50%';
330
+ // button.style.transform = 'translate(-50%, -50%)';
331
+ // button.style.zIndex = '1000';
332
+ // button.style.backgroundColor = '#fff';
333
+ // button.style.border = '2px solid #fff';
334
+ // button.style.color = '#313a46';
335
+ // button.style.cursor = 'pointer';
336
+ // button.style.userSelect = 'none';
337
+ // button.addEventListener('click', (e) => {
338
+ // e.stopPropagation();
339
+ // this.editImage();
340
+ // });
341
+ // container.appendChild(button);
342
+ // } else {
343
+ // this.selectedImage = null;
344
+ // this.selectedItemIndex = null;
345
+ // const buttons = document.querySelectorAll('.image-edit-button');
346
+ // buttons.forEach(button => button.remove());
347
+ // }
348
+ // });
349
+ // }
350
+ // }
351
+ // }
297
352
  addClickListenerToImages() {
298
353
  const editor = document.getElementById('editor');
299
354
  const roles = this.roleCheck(); // Get user roles dynamically
300
355
  const isAdmin = roles.includes('Admin');
301
356
  const isCreator = roles.includes('Creator');
302
- const isApprover = roles.includes('Approver');
303
357
  if (isCreator || isAdmin) {
304
358
  if (editor) {
305
359
  editor.addEventListener('click', (event) => {
@@ -341,15 +395,31 @@ class ElTextEditorComponent {
341
395
  container.appendChild(button);
342
396
  }
343
397
  else {
344
- this.selectedImage = null;
345
- this.selectedItemIndex = null;
346
- const buttons = document.querySelectorAll('.image-edit-button');
347
- buttons.forEach(button => button.remove());
398
+ this.removeEditButtons();
348
399
  }
349
400
  });
401
+ // Monitor editor content changes to handle image deletion
402
+ const observer = new MutationObserver(() => {
403
+ const buttons = editor.querySelectorAll('.image-edit-button');
404
+ buttons.forEach((button) => {
405
+ const container = button.parentElement;
406
+ if (container && !container.querySelector('img')) {
407
+ button.remove(); // Remove the button if the associated image is gone
408
+ container.remove(); // Clean up the container
409
+ }
410
+ });
411
+ });
412
+ // Observe changes in the editor
413
+ observer.observe(editor, { childList: true, subtree: true });
350
414
  }
351
415
  }
352
416
  }
417
+ removeEditButtons() {
418
+ const buttons = document.querySelectorAll('.image-edit-button');
419
+ buttons.forEach((button) => button.remove());
420
+ this.selectedImage = null;
421
+ this.selectedItemIndex = null;
422
+ }
353
423
  // private addClickListenerToImages() {
354
424
  // const editor = document.getElementById('editor');
355
425
  // if (editor) {
@@ -460,9 +530,6 @@ class ElTextEditorComponent {
460
530
  if (value) {
461
531
  const VALUE = value;
462
532
  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
533
  this.onChange(VALUE);
467
534
  this.editorTextChange.emit(VALUE);
468
535
  }
@@ -848,6 +915,7 @@ class ElTextEditorComponent {
848
915
  const imgHTML = imgWidth > editorWidth
849
916
  ? `<img src="${img.src}" style="width: 100%; max-width: ${editorWidth}px; height: auto;">`
850
917
  : `<img src="${img.src}" style="width: ${imgWidth}px; height: auto;">`;
918
+ this.newImageAdded.emit();
851
919
  // Insert the image into the editor
852
920
  document.execCommand('insertHTML', false, imgHTML);
853
921
  };
@@ -1168,73 +1236,24 @@ class ElTextEditorComponent {
1168
1236
  document.execCommand('foreColor', false, event);
1169
1237
  // this.logs.unshift([this.logs.length + 1, trigger, event]);
1170
1238
  }
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
1239
  editImage() {
1211
1240
  let data;
1212
1241
  console.log('this.editorFrom =', this.editorFrom);
1213
1242
  switch (this.editorFrom.name) {
1214
1243
  case 'section-content':
1215
- data = {
1216
- editIMG: true,
1217
- from: 'htmlEditor',
1218
- index: this.selectedItemIndex,
1219
- id: this.editorFrom.id,
1220
- };
1244
+ data = { editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex, id: this.editorFrom.id };
1221
1245
  const compressedData = compress(JSON.stringify(this.imageEditUrl));
1222
1246
  sessionStorage.setItem('editImageFromTemp', compressedData);
1223
1247
  const compressedData2 = compress(JSON.stringify(this.sanitizedContent));
1224
1248
  sessionStorage.setItem('textEditor', compressedData2);
1249
+ // alert('go to editor!')
1225
1250
  this.navigateToIMGEditor(data);
1226
1251
  this.imageEdit.emit();
1227
1252
  break;
1228
1253
  case 'create-document':
1229
1254
  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
- };
1255
+ data = { editIMG: true, from: 'createDocument', index: this.selectedItemIndex, id: this.editorFrom.id, section: this.editorFrom.section, reportSectionId: this.editorFrom.reportSectionId };
1256
+ // this.openDialog(data)
1238
1257
  const compressedData3 = compress(JSON.stringify(this.imageEditUrl));
1239
1258
  const compressedData4 = compress(this.editorText);
1240
1259
  sessionStorage.setItem('editImageFromTemp2', compressedData3);
@@ -1243,8 +1262,18 @@ class ElTextEditorComponent {
1243
1262
  break;
1244
1263
  default:
1245
1264
  null;
1265
+ // sessionStorage.removeItem('editImageFromTemp');
1266
+ // sessionStorage.removeItem('editImageFromTemp2');
1267
+ // sessionStorage.removeItem('templateEditor');
1268
+ // sessionStorage.removeItem('textEditor');
1246
1269
  break;
1247
1270
  }
1271
+ // if (this.editorFrom === 'section-content') {
1272
+ // const data = {editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex}
1273
+ // this.navigateToIMGEditor(data)
1274
+ // sessionStorage.setItem('editImageFromTemp', JSON.stringify(this.imageEditUrl))
1275
+ // sessionStorage.setItem('textEditor', this.editorText)
1276
+ // }
1248
1277
  }
1249
1278
  openDialog(item) {
1250
1279
  // let data: any;
@@ -1595,7 +1624,7 @@ class ElTextEditorComponent {
1595
1624
  }
1596
1625
  }
1597
1626
  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 });
1598
- 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: [{
1627
+ 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: [{
1599
1628
  provide: NG_VALUE_ACCESSOR,
1600
1629
  useExisting: forwardRef(() => ElTextEditorComponent),
1601
1630
  multi: true
@@ -1641,6 +1670,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImpor
1641
1670
  type: Output
1642
1671
  }], isOpen: [{
1643
1672
  type: Output
1673
+ }], newImageAdded: [{
1674
+ type: Output
1644
1675
  }], value: [{
1645
1676
  type: Input
1646
1677
  }], TextEditor: [{