Assign file handle to dropped files (#2125)

Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
Thomas Steiner 2020-08-31 13:11:14 +02:00 committed by GitHub
parent 0ab58b38e0
commit 730a11e0a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3570,7 +3570,9 @@ class App extends React.Component<ExcalidrawProps, AppState> {
} }
}; };
private handleCanvasOnDrop = (event: React.DragEvent<HTMLCanvasElement>) => { private handleCanvasOnDrop = async (
event: React.DragEvent<HTMLCanvasElement>,
) => {
const libraryShapes = event.dataTransfer.getData( const libraryShapes = event.dataTransfer.getData(
"application/vnd.excalidrawlib+json", "application/vnd.excalidrawlib+json",
); );
@ -3589,6 +3591,19 @@ class App extends React.Component<ExcalidrawProps, AppState> {
file?.name.endsWith(".excalidraw") file?.name.endsWith(".excalidraw")
) { ) {
this.setState({ isLoading: true }); this.setState({ isLoading: true });
if (
"chooseFileSystemEntries" in window ||
"showOpenFilePicker" in window
) {
try {
// This will only work as of Chrome 86,
// but can be safely ignored on older releases.
const item = event.dataTransfer.items[0];
(window as any).handle = await (item as any).getAsFileSystemHandle();
} catch (error) {
console.warn(error.name, error.message);
}
}
loadFromBlob(file, this.state) loadFromBlob(file, this.state)
.then(({ elements, appState }) => .then(({ elements, appState }) =>
this.syncActionResult({ this.syncActionResult({