Skip to content

Commit

Permalink
Allow setFragmentData without clipboardData object (#4333)
Browse files Browse the repository at this point in the history
* allow setFragmentData to be used without a copy/paste or DnD data structure

* Add changeset

* return data for use outside of setFragmentData call
  • Loading branch information
dylans authored Aug 6, 2021
1 parent f0721ac commit e0776c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quiet-teachers-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Allow setFragmentData to work without copy/paste or DnD data structure
3 changes: 2 additions & 1 deletion packages/slate-react/src/plugin/with-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const withReact = <T extends Editor>(editor: T) => {
}
}

e.setFragmentData = (data: DataTransfer) => {
e.setFragmentData = (data: Pick<DataTransfer, 'getData' | 'setData'>) => {
const { selection } = e

if (!selection) {
Expand Down Expand Up @@ -179,6 +179,7 @@ export const withReact = <T extends Editor>(editor: T) => {
data.setData('text/html', div.innerHTML)
data.setData('text/plain', getPlainText(div))
document.body.removeChild(div)
return data
}

e.insertData = (data: DataTransfer) => {
Expand Down

0 comments on commit e0776c5

Please sign in to comment.