mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Save scene in URL (#220)
Co-authored-by: Christopher Chedeau <vjeuxx@gmail.com>
This commit is contained in:
parent
abbc04df0e
commit
db973c61e8
3 changed files with 40 additions and 3 deletions
|
@ -181,3 +181,22 @@ export function saveToLocalStorage(
|
|||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(elements));
|
||||
localStorage.setItem(LOCAL_STORAGE_KEY_STATE, JSON.stringify(state));
|
||||
}
|
||||
|
||||
export function restoreFromURL(elements: ExcalidrawElement[]) {
|
||||
try {
|
||||
const [savedElements, savedState] = document.location.hash
|
||||
.slice(1)
|
||||
.split(":")
|
||||
.map(atob);
|
||||
return restore(elements, savedElements, savedState);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveToURL(elements: ExcalidrawElement[], state: AppState) {
|
||||
const hash = [JSON.stringify(elements), JSON.stringify(state)]
|
||||
.map(btoa)
|
||||
.join(":");
|
||||
document.location.replace("#" + hash);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ export {
|
|||
loadFromJSON,
|
||||
saveAsJSON,
|
||||
restoreFromLocalStorage,
|
||||
saveToLocalStorage
|
||||
saveToLocalStorage,
|
||||
restoreFromURL,
|
||||
saveToURL
|
||||
} from "./data";
|
||||
export { hasBackground, hasStroke, getElementAtPosition } from "./comparisons";
|
||||
export { createScene } from "./createScene";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue