suneditor
suneditor copied to clipboard
How to stop user from pasting image directly inside editor?
I want user to provide image only through link. So i want to prevent from direct copy and pasting image inside editor. How to do this. Otherwise user may mistakenly paste a lots of image directly , which will slow down netowrk query or sometimes it may stop network query.
There are no related options. You can prevent it in the following way:
editorInstance.core._setClipboardComponent = function (e) {
e.preventDefault();
e.stopPropagation();
return;
}
But this doesn't make much sense because you can copy with range selection.
There are no related options. You can prevent it in the following way:
editorInstance.core._setClipboardComponent = function (e) { e.preventDefault(); e.stopPropagation(); return; }
How to do this in react with typescript. This is important thing because user could mess up by pasting lots of images in a document directly herby increasing document size.
editorInstance.onPaste = (e, cleanData, maxCharCount, core) => {
const dom = core._d.createRange().createContextualFragment(cleanData);
const chilren = dom.childNodes;
let html = '';
chilren.forEach(v=> {
html += core.util.isComponent(v) ? '' : (v.outerHTML || v.textContent);
})
return html;
}
editorInstance.onPaste = (e, cleanData, maxCharCount, core) => { const dom = core._d.createRange().createContextualFragment(cleanData); const chilren = dom.childNodes; let html = ''; chilren.forEach(v=> { html += core.util.isComponent(v) ? '' : (v.outerHTML || v.textContent); }) return html; }
Does this stops pasting everything or only image?