myrta-ui 1.1.78 → 1.1.81
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/components/form/editor/editor.component.mjs +69 -1
- package/fesm2015/myrta-ui.mjs +71 -1
- package/fesm2015/myrta-ui.mjs.map +1 -1
- package/fesm2020/myrta-ui.mjs +68 -0
- package/fesm2020/myrta-ui.mjs.map +1 -1
- package/lib/components/form/editor/editor.component.d.ts +4 -0
- package/package.json +3 -1
package/fesm2020/myrta-ui.mjs
CHANGED
|
@@ -10589,8 +10589,12 @@ class EditorComponent {
|
|
|
10589
10589
|
beautifyHTML: true,
|
|
10590
10590
|
addNewLine: true,
|
|
10591
10591
|
createAttributes: {},
|
|
10592
|
+
disablePlugins: ['paste'],
|
|
10592
10593
|
events: {
|
|
10593
10594
|
getIcon: changeIconsFunction,
|
|
10595
|
+
paste: (event) => {
|
|
10596
|
+
this.handlePaste(event);
|
|
10597
|
+
},
|
|
10594
10598
|
},
|
|
10595
10599
|
// uploader: {
|
|
10596
10600
|
// insertImageAsBase64URI: true
|
|
@@ -10752,6 +10756,70 @@ class EditorComponent {
|
|
|
10752
10756
|
this.updateValue(this.editorElementRef.editor.value);
|
|
10753
10757
|
}
|
|
10754
10758
|
}
|
|
10759
|
+
handlePaste(event) {
|
|
10760
|
+
if (!event.clipboardData) {
|
|
10761
|
+
return;
|
|
10762
|
+
}
|
|
10763
|
+
const { clipboardData } = event;
|
|
10764
|
+
const htmlData = clipboardData.getData('text/html');
|
|
10765
|
+
const hasHtmlImage = htmlData?.includes('<img');
|
|
10766
|
+
const hasImage = Array.from(clipboardData.items).some(item => item.type.startsWith('image/'));
|
|
10767
|
+
if (!hasImage && !hasHtmlImage) {
|
|
10768
|
+
return;
|
|
10769
|
+
}
|
|
10770
|
+
event.preventDefault();
|
|
10771
|
+
event.stopPropagation();
|
|
10772
|
+
const { editor } = this.editorElementRef;
|
|
10773
|
+
const plainText = clipboardData.getData('text/plain');
|
|
10774
|
+
if (htmlData) {
|
|
10775
|
+
const tempDiv = document.createElement('div');
|
|
10776
|
+
tempDiv.innerHTML = htmlData;
|
|
10777
|
+
this.removeImageNodes(tempDiv);
|
|
10778
|
+
if (this.hasContent(tempDiv)) {
|
|
10779
|
+
this.insertNodes(editor, tempDiv);
|
|
10780
|
+
return;
|
|
10781
|
+
}
|
|
10782
|
+
}
|
|
10783
|
+
if (plainText) {
|
|
10784
|
+
editor.s.insertHTML(plainText);
|
|
10785
|
+
}
|
|
10786
|
+
}
|
|
10787
|
+
removeImageNodes(container) {
|
|
10788
|
+
container.querySelectorAll('img').forEach(img => img.remove());
|
|
10789
|
+
const comments = [];
|
|
10790
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_COMMENT, null);
|
|
10791
|
+
let node;
|
|
10792
|
+
while (node = walker.nextNode()) {
|
|
10793
|
+
comments.push(node);
|
|
10794
|
+
}
|
|
10795
|
+
comments.forEach(comment => comment.parentNode?.removeChild(comment));
|
|
10796
|
+
const emptyElements = container.querySelectorAll('p, div, span, br');
|
|
10797
|
+
emptyElements.forEach(el => {
|
|
10798
|
+
if (el.tagName === 'BR' && !el.nextSibling && !el.previousSibling) {
|
|
10799
|
+
el.remove();
|
|
10800
|
+
}
|
|
10801
|
+
else if (!el.textContent?.trim() && el.children.length === 0) {
|
|
10802
|
+
el.remove();
|
|
10803
|
+
}
|
|
10804
|
+
});
|
|
10805
|
+
container.querySelectorAll('p, div').forEach(el => {
|
|
10806
|
+
if (el.children.length === 1 && el.innerHTML.trim() === '<br>') {
|
|
10807
|
+
el.remove();
|
|
10808
|
+
}
|
|
10809
|
+
});
|
|
10810
|
+
}
|
|
10811
|
+
hasContent(container) {
|
|
10812
|
+
return !!container.textContent?.trim() || container.children.length > 0;
|
|
10813
|
+
}
|
|
10814
|
+
insertNodes(editor, container) {
|
|
10815
|
+
const nodes = Array.from(container.childNodes).map(node => node.cloneNode(true));
|
|
10816
|
+
nodes.forEach(node => {
|
|
10817
|
+
if (node.nodeType === Node.ELEMENT_NODE ||
|
|
10818
|
+
(node.nodeType === Node.TEXT_NODE && node.textContent?.trim())) {
|
|
10819
|
+
editor.s.insertNode(node);
|
|
10820
|
+
}
|
|
10821
|
+
});
|
|
10822
|
+
}
|
|
10755
10823
|
}
|
|
10756
10824
|
EditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: EditorComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
10757
10825
|
EditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: EditorComponent, selector: "mrx-editor", inputs: { fields: "fields", toolbar: "toolbar", maxLength: "maxLength", minHeight: "minHeight", customClasses: "customClasses", placeholder: "placeholder", disabled: "disabled", readonly: "readonly", iframe: "iframe", config: "config", defaultInlineStyle: "defaultInlineStyle", defaultActionOnPaste: "defaultActionOnPaste", askBeforePasteHTML: "askBeforePasteHTML", editHTMLDocumentMode: "editHTMLDocumentMode", askBeforePasteFromWord: "askBeforePasteFromWord", defaultMode: "defaultMode", invalid: "invalid", invalidMessage: "invalidMessage", checkInvalid: "checkInvalid" }, outputs: { changed: "changed", modelChange: "modelChange", blurred: "blurred" }, providers: [
|