mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
move footer into layerUI & refactor ActionManager (#729)
This commit is contained in:
parent
88eacc9da7
commit
d79293de06
7 changed files with 164 additions and 179 deletions
|
@ -123,17 +123,15 @@ export async function loadFromBlob(blob: any) {
|
|||
if ("text" in Blob) {
|
||||
contents = await blob.text();
|
||||
} else {
|
||||
contents = await (async () => {
|
||||
return new Promise(resolve => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(blob, "utf8");
|
||||
reader.onloadend = () => {
|
||||
if (reader.readyState === FileReader.DONE) {
|
||||
resolve(reader.result as string);
|
||||
}
|
||||
};
|
||||
});
|
||||
})();
|
||||
contents = await new Promise(resolve => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(blob, "utf8");
|
||||
reader.onloadend = () => {
|
||||
if (reader.readyState === FileReader.DONE) {
|
||||
resolve(reader.result as string);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
const { elements, appState } = updateAppState(contents);
|
||||
if (!elements.length) {
|
||||
|
@ -488,3 +486,23 @@ export function addToLoadedScenes(id: string, k: string | undefined): void {
|
|||
JSON.stringify(scenes),
|
||||
);
|
||||
}
|
||||
|
||||
export async function loadScene(id: string | null, k?: string) {
|
||||
let data;
|
||||
let selectedId;
|
||||
if (id != null) {
|
||||
// k is the private key used to decrypt the content from the server, take
|
||||
// extra care not to leak it
|
||||
data = await importFromBackend(id, k);
|
||||
addToLoadedScenes(id, k);
|
||||
selectedId = id;
|
||||
window.history.replaceState({}, "Excalidraw", window.location.origin);
|
||||
} else {
|
||||
data = restoreFromLocalStorage();
|
||||
}
|
||||
|
||||
return {
|
||||
elements: data.elements,
|
||||
appState: data.appState && { ...data.appState, selectedId },
|
||||
};
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ export {
|
|||
importFromBackend,
|
||||
addToLoadedScenes,
|
||||
loadedScenes,
|
||||
loadScene,
|
||||
calculateScrollCenter,
|
||||
} from "./data";
|
||||
export {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue