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
|
@ -4,6 +4,8 @@ import { cleanAppStateForExport } from "../appState";
|
|||
|
||||
import { fileOpen, fileSave } from "browser-nativefs";
|
||||
import { loadFromBlob } from "./blob";
|
||||
import { loadLibrary } from "./localStorage";
|
||||
import { Library } from "./library";
|
||||
|
||||
export const serializeAsJSON = (
|
||||
elements: readonly ExcalidrawElement[],
|
||||
|
@ -50,3 +52,34 @@ export const loadFromJSON = async (appState: AppState) => {
|
|||
});
|
||||
return loadFromBlob(blob, appState);
|
||||
};
|
||||
|
||||
export const saveLibraryAsJSON = async () => {
|
||||
const library = await loadLibrary();
|
||||
const serialized = JSON.stringify(
|
||||
{
|
||||
type: "excalidrawlib",
|
||||
version: 1,
|
||||
library,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
const fileName = `library.excalidrawlib`;
|
||||
const blob = new Blob([serialized], {
|
||||
type: "application/vnd.excalidrawlib+json",
|
||||
});
|
||||
await fileSave(blob, {
|
||||
fileName,
|
||||
description: "Excalidraw library file",
|
||||
extensions: ["excalidrawlib"],
|
||||
});
|
||||
};
|
||||
|
||||
export const importLibraryFromJSON = async () => {
|
||||
const blob = await fileOpen({
|
||||
description: "Excalidraw library files",
|
||||
extensions: ["json", "excalidrawlib"],
|
||||
mimeTypes: ["application/json"],
|
||||
});
|
||||
Library.importLibrary(blob);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue