mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 15:02:51 +02:00
fix: weak guard on DataTransfer to not rely on current window (#4654)
This commit is contained in:
5
.changeset/beige-hotels-vanish.md
Normal file
5
.changeset/beige-hotels-vanish.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-react': patch
|
||||
---
|
||||
|
||||
weak guard on DataTransfer to not rely on current window
|
@@ -429,9 +429,11 @@ export const Editable = (props: EditableProps) => {
|
||||
state.isComposing = false
|
||||
}
|
||||
|
||||
const window = ReactEditor.getWindow(editor)
|
||||
if (data instanceof window.DataTransfer) {
|
||||
ReactEditor.insertData(editor, data as DataTransfer)
|
||||
// use a weak comparison instead of 'instanceof' to allow
|
||||
// programmatic access of paste events coming from external windows
|
||||
// like cypress where cy.window does not work realibly
|
||||
if (data?.constructor.name === 'DataTransfer') {
|
||||
ReactEditor.insertData(editor, data)
|
||||
} else if (typeof data === 'string') {
|
||||
// Only insertText operations use the native functionality, for now.
|
||||
// Potentially expand to single character deletes, as well.
|
||||
|
Reference in New Issue
Block a user