I am trying to get copied fragment into onCopy
hook vainly.
I've been trying with the event.clipboardData...
const { clipboardData } = event;
const encoded = clipboardData.getData("application/x-slate-fragment");
But it seems as empty. I have also tried with the getEventTransfer
utils. But it returns {type: 'unknow'}
Here is the CodeSandBox that I have been testing.
i think its not possible with the saltejs
to get the fragment, if your will see the doucmentation as well https://docs.slatejs.org/v/v0.47/slate-react/utils#functions here as well they are asking to make the fragment first and then copy the data to it. So i think you could use JavaScript for it, if it helps, just a suggestion.
if you just want to get the copied text then try plain javascript inside onCopy
function
const copied_text = window.getSelection().toString();
if your want to get the fragment of copied text use
event.target.outerHTML
or event.target.innerHTML
in onCopy function
if you want to create another copied fragment you can do
document.createRange().createContextualFragment(event.target.outerHTML)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With