fix: support d&d of files without extension (#3168)
This commit is contained in:
parent
b081a09962
commit
8670b2d587
@ -3626,9 +3626,18 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||||||
|
|
||||||
const file = event.dataTransfer?.files[0];
|
const file = event.dataTransfer?.files[0];
|
||||||
if (
|
if (
|
||||||
file?.type === "application/json" ||
|
file?.type === MIME_TYPES.excalidrawlib ||
|
||||||
file?.name.endsWith(".excalidraw")
|
file?.name?.endsWith(".excalidrawlib")
|
||||||
) {
|
) {
|
||||||
|
Library.importLibrary(file)
|
||||||
|
.then(() => {
|
||||||
|
this.setState({ isLibraryOpen: false });
|
||||||
|
})
|
||||||
|
.catch((error) =>
|
||||||
|
this.setState({ isLoading: false, errorMessage: error.message }),
|
||||||
|
);
|
||||||
|
// default: assume an Excalidraw file regardless of extension/MimeType
|
||||||
|
} else {
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
if (supported) {
|
if (supported) {
|
||||||
try {
|
try {
|
||||||
@ -3640,23 +3649,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||||||
console.warn(error.name, error.message);
|
console.warn(error.name, error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.loadFileToCanvas(file);
|
await this.loadFileToCanvas(file);
|
||||||
} else if (
|
|
||||||
file?.type === MIME_TYPES.excalidrawlib ||
|
|
||||||
file?.name.endsWith(".excalidrawlib")
|
|
||||||
) {
|
|
||||||
Library.importLibrary(file)
|
|
||||||
.then(() => {
|
|
||||||
this.setState({ isLibraryOpen: false });
|
|
||||||
})
|
|
||||||
.catch((error) =>
|
|
||||||
this.setState({ isLoading: false, errorMessage: error.message }),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
isLoading: false,
|
|
||||||
errorMessage: t("alerts.couldNotLoadInvalidFile"),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { cleanAppStateForExport } from "../appState";
|
import { cleanAppStateForExport } from "../appState";
|
||||||
import { EXPORT_DATA_TYPES, MIME_TYPES } from "../constants";
|
import { EXPORT_DATA_TYPES } from "../constants";
|
||||||
import { clearElementsForExport } from "../element";
|
import { clearElementsForExport } from "../element";
|
||||||
import { CanvasError } from "../errors";
|
import { CanvasError } from "../errors";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
@ -95,13 +95,7 @@ export const loadFromBlob = async (
|
|||||||
elements: clearElementsForExport(data.elements || []),
|
elements: clearElementsForExport(data.elements || []),
|
||||||
appState: {
|
appState: {
|
||||||
theme: localAppState?.theme,
|
theme: localAppState?.theme,
|
||||||
fileHandle:
|
fileHandle: blob.handle ?? null,
|
||||||
blob.handle &&
|
|
||||||
["application/json", MIME_TYPES.excalidraw].includes(
|
|
||||||
getMimeType(blob),
|
|
||||||
)
|
|
||||||
? blob.handle
|
|
||||||
: null,
|
|
||||||
...cleanAppStateForExport(data.appState || {}),
|
...cleanAppStateForExport(data.appState || {}),
|
||||||
...(localAppState
|
...(localAppState
|
||||||
? calculateScrollCenter(data.elements || [], localAppState, null)
|
? calculateScrollCenter(data.elements || [], localAppState, null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user