mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Import and export library from/to a file (#1940)
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
7eff6893c5
commit
ee8fa6aaad
11 changed files with 199 additions and 39 deletions
|
@ -143,6 +143,7 @@ import { actionFinalize, actionDeleteSelected } from "../actions";
|
|||
import {
|
||||
restoreUsernameFromLocalStorage,
|
||||
saveUsernameToLocalStorage,
|
||||
loadLibrary,
|
||||
} from "../data/localStorage";
|
||||
|
||||
import throttle from "lodash.throttle";
|
||||
|
@ -153,6 +154,7 @@ import {
|
|||
isElementInGroup,
|
||||
getSelectedGroupIdForElement,
|
||||
} from "../groups";
|
||||
import { Library } from "../data/library";
|
||||
|
||||
/**
|
||||
* @param func handler taking at most single parameter (event).
|
||||
|
@ -3206,7 +3208,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
|
||||
private handleCanvasOnDrop = (event: React.DragEvent<HTMLCanvasElement>) => {
|
||||
const libraryShapes = event.dataTransfer.getData(
|
||||
"application/vnd.excalidraw.json",
|
||||
"application/vnd.excalidrawlib+json",
|
||||
);
|
||||
if (libraryShapes !== "") {
|
||||
this.addElementsFromPasteOrLibrary(
|
||||
|
@ -3237,6 +3239,17 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
.catch((error) => {
|
||||
this.setState({ isLoading: false, errorMessage: error.message });
|
||||
});
|
||||
} else if (
|
||||
file?.type === "application/vnd.excalidrawlib+json" ||
|
||||
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,
|
||||
|
@ -3484,6 +3497,7 @@ declare global {
|
|||
setState: React.Component<any, AppState>["setState"];
|
||||
history: SceneHistory;
|
||||
app: InstanceType<typeof App>;
|
||||
library: ReturnType<typeof loadLibrary>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3506,6 +3520,9 @@ if (
|
|||
history: {
|
||||
get: () => history,
|
||||
},
|
||||
library: {
|
||||
get: () => loadLibrary(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue