Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit ed09f78

Browse files
mrkevfacebook-github-bot
authored andcommitted
Flow-type DataTransfer.js
Summary: Flowifies DataTransfer.js. We have a flow libdef for the browser's DataTransfer object, **so the only non-flow change this involved was a quick name check to avoid the collision**. This surfaced a couple of places where the module is misused (yay! means it's surfacing potential bugs!). Putting them behind flowfixme's to avoid changing functionality and keep this diff simple (and eye-testable). I can make tasks for fixing these flowfixme's if desired. Differential Revision: D16176363 fbshipit-source-id: 755da606d0d86b74f2024b6d8e522746072bfc61
1 parent 8e9cabf commit ed09f78

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/component/handlers/drag/DraftEditorDragHandler.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ const DraftEditorDragHandler = {
9191
return;
9292
}
9393

94-
const files = data.getFiles();
94+
/* $FlowFixMe This comment suppresses an error found DataTransfer was typed.
95+
* getFiles() returns an array of <Files extends Blob>, not Blob */
96+
const files: Array<Blob> = (data.getFiles(): any);
9597
if (files.length > 0) {
9698
if (
9799
editor.props.handleDroppedFiles &&
@@ -119,7 +121,11 @@ const DraftEditorDragHandler = {
119121
editor.update(moveText(editorState, dropSelection));
120122
} else {
121123
editor.update(
122-
insertTextAtSelection(editorState, dropSelection, data.getText()),
124+
insertTextAtSelection(
125+
editorState,
126+
dropSelection,
127+
(data.getText(): any),
128+
),
123129
);
124130
}
125131
endDrag(editor);

src/component/handlers/edit/editOnPaste.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ function editOnPaste(editor: DraftEditor, e: SyntheticClipboardEvent<>): void {
3737

3838
// Get files, unless this is likely to be a string the user wants inline.
3939
if (!data.isRichText()) {
40-
const files = data.getFiles();
40+
/* $FlowFixMe This comment suppresses an error found DataTransfer was typed.
41+
* getFiles() returns an array of <Files extends Blob>, not Blob */
42+
const files: Array<Blob> = (data.getFiles(): any);
4143
const defaultFileText = data.getText();
4244
if (files.length > 0) {
4345
// Allow customized paste handling for images, etc. Otherwise, fall
@@ -91,8 +93,8 @@ function editOnPaste(editor: DraftEditor, e: SyntheticClipboardEvent<>): void {
9193
}
9294

9395
let textBlocks: Array<string> = [];
94-
const text = data.getText();
95-
const html = data.getHTML();
96+
const text: string = (data.getText(): any);
97+
const html: string = (data.getHTML(): any);
9698
const editorState = editor._latestEditorState;
9799

98100
if (

0 commit comments

Comments
 (0)