1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 22:45:18 +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 state.isComposing = false
} }
const window = ReactEditor.getWindow(editor) // use a weak comparison instead of 'instanceof' to allow
if (data instanceof window.DataTransfer) { // programmatic access of paste events coming from external windows
ReactEditor.insertData(editor, data as DataTransfer) // like cypress where cy.window does not work realibly
if (data?.constructor.name === 'DataTransfer') {
ReactEditor.insertData(editor, data)
} else if (typeof data === 'string') { } else if (typeof data === 'string') {
// Only insertText operations use the native functionality, for now. // Only insertText operations use the native functionality, for now.
// Potentially expand to single character deletes, as well. // Potentially expand to single character deletes, as well.