1
0
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:
Andreas Hörnicke
2021-11-15 09:59:02 +01:00
committed by GitHub
parent b6643132f1
commit 2c7750cac5
2 changed files with 10 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
weak guard on DataTransfer to not rely on current window

View File

@@ -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.