mirror of
https://github.com/docmost/docmost.git
synced 2026-05-18 07:24:04 +08:00
d8da307a61
* WIP * use next excalidraw version * support local persistence for excalidraw library. Co-authored-by: Drauggy <n.fomenko@safe-tech.ru> --------- Co-authored-by: Drauggy <n.fomenko@safe-tech.ru>
43 lines
1010 B
TypeScript
43 lines
1010 B
TypeScript
type LibraryItems = any;
|
|
|
|
type LibraryPersistedData = {
|
|
libraryItems: LibraryItems;
|
|
};
|
|
|
|
export interface LibraryPersistenceAdapter {
|
|
load(metadata: { source: "load" | "save" }):
|
|
| Promise<{ libraryItems: LibraryItems } | null>
|
|
| {
|
|
libraryItems: LibraryItems;
|
|
}
|
|
| null;
|
|
|
|
save(libraryData: LibraryPersistedData): Promise<void> | void;
|
|
}
|
|
|
|
const LOCAL_STORAGE_KEY = "excalidrawLibrary";
|
|
|
|
export const localStorageLibraryAdapter: LibraryPersistenceAdapter = {
|
|
async load() {
|
|
try {
|
|
const data = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
if (data) {
|
|
return JSON.parse(data);
|
|
}
|
|
} catch (e) {
|
|
console.error("Error downloading Excalidraw library from localStorage", e);
|
|
}
|
|
return null;
|
|
},
|
|
async save(libraryData) {
|
|
try {
|
|
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(libraryData));
|
|
} catch (e) {
|
|
console.error(
|
|
"Error while saving library from Excalidraw to localStorage",
|
|
e,
|
|
);
|
|
}
|
|
},
|
|
};
|