el-text-editor 0.0.68 → 0.0.70

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.
@@ -498,12 +498,6 @@ class ElTextEditorComponent {
498
498
  if (index >= 0) {
499
499
  images[index].setAttribute('src', newSrc);
500
500
  }
501
- else {
502
- console.warn(`Index ${index} is out of bounds. Total images: ${images.length}`);
503
- }
504
- }
505
- else {
506
- console.error('Editor element not found');
507
501
  }
508
502
  }
509
503
  initEditor() {
@@ -649,12 +643,10 @@ class ElTextEditorComponent {
649
643
  let editor = document.getElementById('editor');
650
644
  if (editor) {
651
645
  this.moveCaretToEnd(editor);
646
+ this.onEditorClick(editor);
647
+ this.onKeyboardMove(editor);
652
648
  }
653
649
  this.placeHolderRemove.emit();
654
- console.log('New data inserted at caret.');
655
- }
656
- else {
657
- console.log('No caret position found.');
658
650
  }
659
651
  }
660
652
  // // Move caret to the end of the editor content
@@ -678,6 +670,8 @@ class ElTextEditorComponent {
678
670
  this.setupMutationObserver(editor);
679
671
  // Move the caret to the end after initial content setup
680
672
  this.moveCaretToEnd(editor);
673
+ this.onEditorClick(editor);
674
+ this.onKeyboardMove(editor);
681
675
  // Track caret position on mouse click
682
676
  editor.addEventListener('click', () => {
683
677
  if (editor) { // Ensure editor is not null
@@ -707,6 +701,16 @@ class ElTextEditorComponent {
707
701
  });
708
702
  observer.observe(editor, { childList: true, subtree: true, characterData: true });
709
703
  }
704
+ // private moveCaretToEnd(editor: HTMLElement) {
705
+ // const selection = window.getSelection();
706
+ // const range = document.createRange();
707
+ // if (editor.lastChild) {
708
+ // range.selectNodeContents(editor);
709
+ // range.collapse(false); // Collapse to the end
710
+ // selection?.removeAllRanges();
711
+ // selection?.addRange(range);
712
+ // }
713
+ // }
710
714
  moveCaretToEnd(editor) {
711
715
  const selection = window.getSelection();
712
716
  const range = document.createRange();
@@ -717,6 +721,39 @@ class ElTextEditorComponent {
717
721
  selection === null || selection === void 0 ? void 0 : selection.addRange(range);
718
722
  }
719
723
  }
724
+ onKeyboardMove(editor) {
725
+ editor.addEventListener('keydown', (event) => {
726
+ const selection = window.getSelection();
727
+ const range = document.createRange();
728
+ if (selection && selection.rangeCount > 0) {
729
+ const currentRange = selection.getRangeAt(0);
730
+ const currentCaretPosition = currentRange.startContainer;
731
+ if (event.key === 'ArrowRight' || event.key === 'ArrowLeft' || event.key === 'ArrowUp' || event.key === 'ArrowDown') {
732
+ // You can handle specific behavior for different arrow keys here
733
+ // For example, move caret within a specific node or across nodes
734
+ }
735
+ }
736
+ });
737
+ }
738
+ onEditorClick(editor) {
739
+ editor.addEventListener('click', (event) => {
740
+ const selection = window.getSelection();
741
+ const range = document.createRange();
742
+ const clickedNode = event.target;
743
+ if (clickedNode && clickedNode !== editor) {
744
+ // Place the caret at the clicked position
745
+ range.setStart(clickedNode, 0);
746
+ range.setEnd(clickedNode, clickedNode === null || clickedNode === void 0 ? void 0 : clickedNode.length);
747
+ }
748
+ else {
749
+ // Move caret to the end if clicked inside the editor but not on text node
750
+ range.selectNodeContents(editor);
751
+ range.collapse(false);
752
+ }
753
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
754
+ selection === null || selection === void 0 ? void 0 : selection.addRange(range);
755
+ });
756
+ }
720
757
  // init_Func(html: any) {
721
758
  // if (html) {
722
759
  // let editor = document.getElementById('editor');
@@ -1238,7 +1275,6 @@ class ElTextEditorComponent {
1238
1275
  }
1239
1276
  editImage() {
1240
1277
  let data;
1241
- console.log('this.editorFrom =', this.editorFrom);
1242
1278
  switch (this.editorFrom.name) {
1243
1279
  case 'section-content':
1244
1280
  data = { editIMG: true, from: 'htmlEditor', index: this.selectedItemIndex, id: this.editorFrom.id };
@@ -1300,12 +1336,6 @@ class ElTextEditorComponent {
1300
1336
  imgTags[index].setAttribute('src', newSrc);
1301
1337
  this.editorText = doc.body.innerHTML;
1302
1338
  }
1303
- else {
1304
- console.error(`Invalid index ${index}. There are only ${imgTags.length} <img> tags.`);
1305
- }
1306
- }
1307
- else {
1308
- console.error('No <img> tags found in the editor text.');
1309
1339
  }
1310
1340
  }
1311
1341
  navigateToIMGEditor(data) {