el-text-editor 0.0.75 → 0.0.77
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 +33 -41
 - package/fesm2015/el-text-editor.mjs +32 -40
 - package/fesm2015/el-text-editor.mjs.map +1 -1
 - package/fesm2020/el-text-editor.mjs +32 -40
 - package/fesm2020/el-text-editor.mjs.map +1 -1
 - package/lib/el-text-editor.component.d.ts +1 -0
 - package/package.json +1 -1
 
| 
         @@ -91,16 +91,6 @@ class ElTextEditorComponent { 
     | 
|
| 
       91 
91 
     | 
    
         
             
                            this.isOpen.emit(this.IsOpen);
         
     | 
| 
       92 
92 
     | 
    
         
             
                        }
         
     | 
| 
       93 
93 
     | 
    
         
             
                    };
         
     | 
| 
       94 
     | 
    
         
            -
                    // private setCaretToEnd(element: HTMLElement) {
         
     | 
| 
       95 
     | 
    
         
            -
                    //   const range = document.createRange();
         
     | 
| 
       96 
     | 
    
         
            -
                    //   const sel = window.getSelection();
         
     | 
| 
       97 
     | 
    
         
            -
                    //     if (sel) {
         
     | 
| 
       98 
     | 
    
         
            -
                    //     range.selectNodeContents(element);
         
     | 
| 
       99 
     | 
    
         
            -
                    //   range.collapse(false);
         
     | 
| 
       100 
     | 
    
         
            -
                    //   sel.removeAllRanges();
         
     | 
| 
       101 
     | 
    
         
            -
                    //   sel.addRange(range);
         
     | 
| 
       102 
     | 
    
         
            -
                    //   }
         
     | 
| 
       103 
     | 
    
         
            -
                    // }
         
     | 
| 
       104 
94 
     | 
    
         
             
                    // openColorPicker(inputId: string) {
         
     | 
| 
       105 
95 
     | 
    
         
             
                    //   const inputElement = document.getElementById(inputId);
         
     | 
| 
       106 
96 
     | 
    
         
             
                    //   if (inputElement) {
         
     | 
| 
         @@ -634,20 +624,20 @@ class ElTextEditorComponent { 
     | 
|
| 
       634 
624 
     | 
    
         
             
                        const tempDiv = document.createElement('div');
         
     | 
| 
       635 
625 
     | 
    
         
             
                        tempDiv.innerHTML = newData;
         
     | 
| 
       636 
626 
     | 
    
         
             
                        // Append the new data to the fragment (supports HTML insertion)
         
     | 
| 
       637 
     | 
    
         
            -
                         
     | 
| 
       638 
     | 
    
         
            -
             
     | 
| 
       639 
     | 
    
         
            -
                         
     | 
| 
       640 
     | 
    
         
            -
                        //  
     | 
| 
       641 
     | 
    
         
            -
                         
     | 
| 
       642 
     | 
    
         
            -
                         
     | 
| 
       643 
     | 
    
         
            -
                        //  
     | 
| 
       644 
     | 
    
         
            -
                         
     | 
| 
       645 
     | 
    
         
            -
                         
     | 
| 
       646 
     | 
    
         
            -
             
     | 
| 
       647 
     | 
    
         
            -
             
     | 
| 
       648 
     | 
    
         
            -
             
     | 
| 
       649 
     | 
    
         
            -
             
     | 
| 
       650 
     | 
    
         
            -
                         
     | 
| 
      
 627 
     | 
    
         
            +
                        while (tempDiv.firstChild) {
         
     | 
| 
      
 628 
     | 
    
         
            +
                            fragment.appendChild(tempDiv.firstChild);
         
     | 
| 
      
 629 
     | 
    
         
            +
                        }
         
     | 
| 
      
 630 
     | 
    
         
            +
                        // Insert the fragment at the caret position
         
     | 
| 
      
 631 
     | 
    
         
            +
                        range.deleteContents(); // Remove any selected content if applicable
         
     | 
| 
      
 632 
     | 
    
         
            +
                        range.insertNode(fragment);
         
     | 
| 
      
 633 
     | 
    
         
            +
                        // Move the caret after the inserted content
         
     | 
| 
      
 634 
     | 
    
         
            +
                        const lastChild = fragment.lastChild;
         
     | 
| 
      
 635 
     | 
    
         
            +
                        if (lastChild) {
         
     | 
| 
      
 636 
     | 
    
         
            +
                            range.setStartAfter(lastChild);
         
     | 
| 
      
 637 
     | 
    
         
            +
                            range.setEndAfter(lastChild);
         
     | 
| 
      
 638 
     | 
    
         
            +
                            selection.removeAllRanges();
         
     | 
| 
      
 639 
     | 
    
         
            +
                            selection.addRange(range);
         
     | 
| 
      
 640 
     | 
    
         
            +
                        }
         
     | 
| 
       651 
641 
     | 
    
         
             
                        let editor = document.getElementById('editor');
         
     | 
| 
       652 
642 
     | 
    
         
             
                        if (editor) {
         
     | 
| 
       653 
643 
     | 
    
         
             
                            this.moveCaretToEnd(editor);
         
     | 
| 
         @@ -699,29 +689,21 @@ class ElTextEditorComponent { 
     | 
|
| 
       699 
689 
     | 
    
         
             
                setupMutationObserver(editor) {
         
     | 
| 
       700 
690 
     | 
    
         
             
                    const observer = new MutationObserver(() => {
         
     | 
| 
       701 
691 
     | 
    
         
             
                        // Move the caret to the end after content changes
         
     | 
| 
       702 
     | 
    
         
            -
                        this.moveCaretToEnd(editor);
         
     | 
| 
      
 692 
     | 
    
         
            +
                        // this.moveCaretToEnd(editor);
         
     | 
| 
       703 
693 
     | 
    
         
             
                        // Update model with the current content
         
     | 
| 
       704 
694 
     | 
    
         
             
                        this.onModelChange(editor.innerHTML);
         
     | 
| 
       705 
695 
     | 
    
         
             
                    });
         
     | 
| 
       706 
696 
     | 
    
         
             
                    observer.observe(editor, { childList: true, subtree: true, characterData: true });
         
     | 
| 
       707 
697 
     | 
    
         
             
                }
         
     | 
| 
       708 
698 
     | 
    
         
             
                moveCaretToEnd(editor) {
         
     | 
| 
       709 
     | 
    
         
            -
                    // const selection = window.getSelection();
         
     | 
| 
       710 
     | 
    
         
            -
                    // const range = document.createRange();
         
     | 
| 
       711 
     | 
    
         
            -
                    // if (editor.lastChild) {
         
     | 
| 
       712 
     | 
    
         
            -
                    //   range.selectNodeContents(editor);
         
     | 
| 
       713 
     | 
    
         
            -
                    //   range.collapse(false); // Collapse to the end
         
     | 
| 
       714 
     | 
    
         
            -
                    //   selection?.removeAllRanges();
         
     | 
| 
       715 
     | 
    
         
            -
                    //   selection?.addRange(range);
         
     | 
| 
       716 
     | 
    
         
            -
                    // }
         
     | 
| 
       717 
699 
     | 
    
         
             
                    const selection = window.getSelection();
         
     | 
| 
       718 
     | 
    
         
            -
                     
     | 
| 
       719 
     | 
    
         
            -
             
     | 
| 
       720 
     | 
    
         
            -
                         
     | 
| 
       721 
     | 
    
         
            -
             
     | 
| 
       722 
     | 
    
         
            -
                         
     | 
| 
      
 700 
     | 
    
         
            +
                    const range = document.createRange();
         
     | 
| 
      
 701 
     | 
    
         
            +
                    if (editor.lastChild) {
         
     | 
| 
      
 702 
     | 
    
         
            +
                        range.selectNodeContents(editor);
         
     | 
| 
      
 703 
     | 
    
         
            +
                        range.collapse(false); // Collapse to the end
         
     | 
| 
      
 704 
     | 
    
         
            +
                        selection?.removeAllRanges();
         
     | 
| 
      
 705 
     | 
    
         
            +
                        selection?.addRange(range);
         
     | 
| 
       723 
706 
     | 
    
         
             
                    }
         
     | 
| 
       724 
     | 
    
         
            -
                    return null;
         
     | 
| 
       725 
707 
     | 
    
         
             
                }
         
     | 
| 
       726 
708 
     | 
    
         
             
                //   init_Func(html: any) {
         
     | 
| 
       727 
709 
     | 
    
         
             
                //   if (html) {
         
     | 
| 
         @@ -919,7 +901,7 @@ class ElTextEditorComponent { 
     | 
|
| 
       919 
901 
     | 
    
         
             
                                const imgWidth = img.width;
         
     | 
| 
       920 
902 
     | 
    
         
             
                                // If the image width exceeds the editor's width, fit it to the editor
         
     | 
| 
       921 
903 
     | 
    
         
             
                                const imgHTML = imgWidth > editorWidth
         
     | 
| 
       922 
     | 
    
         
            -
                                    ? `<img src="${img.src}" style=" 
     | 
| 
      
 904 
     | 
    
         
            +
                                    ? `<img src="${img.src}" style=" max-width: ${700}px; height: auto;">`
         
     | 
| 
       923 
905 
     | 
    
         
             
                                    : `<img src="${img.src}" style="width: ${imgWidth}px; height: auto;">`;
         
     | 
| 
       924 
906 
     | 
    
         
             
                                this.newImageAdded.emit();
         
     | 
| 
       925 
907 
     | 
    
         
             
                                // Insert the image into the editor
         
     | 
| 
         @@ -1165,6 +1147,16 @@ class ElTextEditorComponent { 
     | 
|
| 
       1165 
1147 
     | 
    
         
             
                        }
         
     | 
| 
       1166 
1148 
     | 
    
         
             
                    }
         
     | 
| 
       1167 
1149 
     | 
    
         
             
                }
         
     | 
| 
      
 1150 
     | 
    
         
            +
                setCaretToEnd(element) {
         
     | 
| 
      
 1151 
     | 
    
         
            +
                    const range = document.createRange();
         
     | 
| 
      
 1152 
     | 
    
         
            +
                    const sel = window.getSelection();
         
     | 
| 
      
 1153 
     | 
    
         
            +
                    if (sel) {
         
     | 
| 
      
 1154 
     | 
    
         
            +
                        range.selectNodeContents(element);
         
     | 
| 
      
 1155 
     | 
    
         
            +
                        range.collapse(false);
         
     | 
| 
      
 1156 
     | 
    
         
            +
                        sel.removeAllRanges();
         
     | 
| 
      
 1157 
     | 
    
         
            +
                        sel.addRange(range);
         
     | 
| 
      
 1158 
     | 
    
         
            +
                    }
         
     | 
| 
      
 1159 
     | 
    
         
            +
                }
         
     | 
| 
       1168 
1160 
     | 
    
         
             
                openColorPicker(inputId) {
         
     | 
| 
       1169 
1161 
     | 
    
         
             
                    const inputElement = document.getElementById(inputId);
         
     | 
| 
       1170 
1162 
     | 
    
         
             
                    if (inputElement) {
         
     |