You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up to #268. This package now uses the undocumented onCopy and onCut props of the Draft.js Editor, but not onPaste. The benefits of onPaste aren’t that clear-cut to me just yet. It would make it possible to use a custom MIME type rather than having to hack the transfer of the content in a data- attribute, but requires importing more Draft.js internals so we can fall back to the Draft.js default paste handling.
Describe the solution you’d like
First draft – to add to the copy/cut handler (potentially also removing all the other custom logic):
Here is what the new paste handler would look like:
importeditOnPastefrom"draft-js/lib/editOnPaste";exportconstonDraftEditorPaste=(editor: Editor,e: SyntheticClipboardEvent<>,)=>{consteditorState=editor._latestEditorState;constdraftEditorPaste=e.clipboardData.getData("application/x-draftjs-conductor-fragment",);if(draftEditorPaste){letrawContent;try{// If JSON parsing fails, leave paste handling to Draft.js.// There is no reason for this to happen, unless the clipboard was altered somehow.// $FlowFixMerawContent=JSON.parse(draftEditorPaste);}catch(error){return;}console.log(rawContent);constfragment=convertFromRaw(rawContent).getBlockMap();constcontent=Modifier.replaceWithFragment(editorState.getCurrentContent(),editorState.getSelection(),fragment,);e.preventDefault();editor.update(EditorState.push(editorState,content,"insert-fragment"));return;}console.log("here?");editOnPaste(editor,e);};
Describe alternatives you’ve considered
Keep on using handlePastedText.
Additional context
One of the reasons I haven’t done this yet is that it feels like a much bigger departure from the Draft.js 0.10 implementation than the copy/cut listeners are – ideally we’d only change this implementation as part of a breaking change to remove support for Draft.js 0.10, in a future major release.
Is your proposal related to a problem?
Follow-up to #268. This package now uses the undocumented
onCopy
andonCut
props of the Draft.js Editor, but not onPaste. The benefits of onPaste aren’t that clear-cut to me just yet. It would make it possible to use a custom MIME type rather than having to hack the transfer of the content in a data- attribute, but requires importing more Draft.js internals so we can fall back to the Draft.js default paste handling.Describe the solution you’d like
First draft – to add to the copy/cut handler (potentially also removing all the other custom logic):
Here is what the new paste handler would look like:
Describe alternatives you’ve considered
Keep on using
handlePastedText
.Additional context
One of the reasons I haven’t done this yet is that it feels like a much bigger departure from the Draft.js 0.10 implementation than the copy/cut listeners are – ideally we’d only change this implementation as part of a breaking change to remove support for Draft.js 0.10, in a future major release.
The text was updated successfully, but these errors were encountered: