mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: Make library local to given excalidraw instance and allow consumer to control it (#3451)
* feat: dnt share library & attach to the excalidraw instance * fix * Add addToLibrary, resetLibrary and libraryItems in initialData * remove comment * handle errors & improve types * remove resetLibrary and addToLibrary and add onLibraryChange prop * set library cache to empty arrary on reset * Add i18n for remove/add library * Update src/locales/en.json Co-authored-by: David Luzar <luzar.david@gmail.com> * update docs * Assign unique ID to each excalidraw component and remove csrfToken from library as its not needed * tweaks Co-authored-by: David Luzar <luzar.david@gmail.com> * update * tweak Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
46624cc953
commit
37d513ad59
15 changed files with 189 additions and 77 deletions
|
@ -5,12 +5,13 @@ import { clearElementsForExport } from "../element";
|
|||
import { ExcalidrawElement } from "../element/types";
|
||||
import { AppState } from "../types";
|
||||
import { loadFromBlob } from "./blob";
|
||||
import { Library } from "./library";
|
||||
|
||||
import {
|
||||
ExportedDataState,
|
||||
ImportedDataState,
|
||||
ExportedLibraryData,
|
||||
} from "./types";
|
||||
import Library from "./library";
|
||||
|
||||
export const serializeAsJSON = (
|
||||
elements: readonly ExcalidrawElement[],
|
||||
|
@ -88,13 +89,13 @@ export const isValidLibrary = (json: any) => {
|
|||
);
|
||||
};
|
||||
|
||||
export const saveLibraryAsJSON = async () => {
|
||||
const library = await Library.loadLibrary();
|
||||
export const saveLibraryAsJSON = async (library: Library) => {
|
||||
const libraryItems = await library.loadLibrary();
|
||||
const data: ExportedLibraryData = {
|
||||
type: EXPORT_DATA_TYPES.excalidrawLibrary,
|
||||
version: 1,
|
||||
source: EXPORT_SOURCE,
|
||||
library,
|
||||
library: libraryItems,
|
||||
};
|
||||
const serialized = JSON.stringify(data, null, 2);
|
||||
const fileName = "library.excalidrawlib";
|
||||
|
@ -108,7 +109,7 @@ export const saveLibraryAsJSON = async () => {
|
|||
});
|
||||
};
|
||||
|
||||
export const importLibraryFromJSON = async () => {
|
||||
export const importLibraryFromJSON = async (library: Library) => {
|
||||
const blob = await fileOpen({
|
||||
description: "Excalidraw library files",
|
||||
// ToDo: Be over-permissive until https://bugs.webkit.org/show_bug.cgi?id=34442
|
||||
|
@ -117,5 +118,5 @@ export const importLibraryFromJSON = async () => {
|
|||
extensions: [".json", ".excalidrawlib"],
|
||||
*/
|
||||
});
|
||||
await Library.importLibrary(blob);
|
||||
await library.importLibrary(blob);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue