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