Allow setFragmentData without clipboardData object #4333
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
It is highly useful to get a copy of the exact selection and it is available in slate-react as e.setFragmentData. Unfortunately the type definition currently requires a DataTransfer object which is difficult to stub as this object comes from ClipboardData or drag-n-drop events. In practice, the only requirement slate-react actually needs is getData/setData. Users could provide a data object that looks like this (let me know if this should be provided as a utility method):
Issue
Fixes: Allows an easy way to get access to the slate tree in
application/x-slate-fragment
,'text/html'
, or'text/plain'
without a copy/paste or DnD operation.Example
The API footprint is exactly the same other than how the DataTransfer object gets passed in. Using the above method, users could do something like:
It's not 100% certain to me if setFragmentData should be async, so I've left it sync.
Context
See above. Let me know if this should work differently and I'll update accordingly.
Checks
yarn test
. (Note: I did not write a new test for this change)yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)