This reverts commit db973c61e85347120c46adba6cb33e50d49988ba.
This commit is contained in:
parent
829a65b8cb
commit
ae982e9298
@ -18,8 +18,6 @@ import {
|
|||||||
exportAsPNG,
|
exportAsPNG,
|
||||||
restoreFromLocalStorage,
|
restoreFromLocalStorage,
|
||||||
saveToLocalStorage,
|
saveToLocalStorage,
|
||||||
restoreFromURL,
|
|
||||||
saveToURL,
|
|
||||||
hasBackground,
|
hasBackground,
|
||||||
hasStroke,
|
hasStroke,
|
||||||
getElementAtPosition,
|
getElementAtPosition,
|
||||||
@ -122,8 +120,7 @@ class App extends React.Component<{}, AppState> {
|
|||||||
document.addEventListener("keydown", this.onKeyDown, false);
|
document.addEventListener("keydown", this.onKeyDown, false);
|
||||||
window.addEventListener("resize", this.onResize, false);
|
window.addEventListener("resize", this.onResize, false);
|
||||||
|
|
||||||
const savedState =
|
const savedState = restoreFromLocalStorage(elements);
|
||||||
restoreFromURL(elements) || restoreFromLocalStorage(elements);
|
|
||||||
if (savedState) {
|
if (savedState) {
|
||||||
this.setState(savedState);
|
this.setState(savedState);
|
||||||
}
|
}
|
||||||
@ -951,11 +948,6 @@ class App extends React.Component<{}, AppState> {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
private saveDebounced = debounce(() => {
|
|
||||||
saveToLocalStorage(elements, this.state);
|
|
||||||
saveToURL(elements, this.state);
|
|
||||||
}, 300);
|
|
||||||
|
|
||||||
private addElementsFromPaste = (paste: string, x?: number, y?: number) => {
|
private addElementsFromPaste = (paste: string, x?: number, y?: number) => {
|
||||||
let parsedElements;
|
let parsedElements;
|
||||||
try {
|
try {
|
||||||
@ -995,7 +987,7 @@ class App extends React.Component<{}, AppState> {
|
|||||||
scrollY: this.state.scrollY,
|
scrollY: this.state.scrollY,
|
||||||
viewBackgroundColor: this.state.viewBackgroundColor
|
viewBackgroundColor: this.state.viewBackgroundColor
|
||||||
});
|
});
|
||||||
this.saveDebounced();
|
saveToLocalStorage(elements, this.state);
|
||||||
if (history.isRecording()) {
|
if (history.isRecording()) {
|
||||||
history.pushEntry(history.generateCurrentEntry(elements));
|
history.pushEntry(history.generateCurrentEntry(elements));
|
||||||
history.clearRedoStack();
|
history.clearRedoStack();
|
||||||
@ -1004,14 +996,6 @@ class App extends React.Component<{}, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function debounce<T extends any[]>(fn: (...args: T) => void, timeout: number) {
|
|
||||||
let handle = 0;
|
|
||||||
return (...args: T) => {
|
|
||||||
clearTimeout(handle);
|
|
||||||
handle = window.setTimeout(() => fn(...args), timeout);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const rootElement = document.getElementById("root");
|
const rootElement = document.getElementById("root");
|
||||||
ReactDOM.render(<App />, rootElement);
|
ReactDOM.render(<App />, rootElement);
|
||||||
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
|
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
|
||||||
|
@ -174,22 +174,3 @@ export function saveToLocalStorage(
|
|||||||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(elements));
|
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(elements));
|
||||||
localStorage.setItem(LOCAL_STORAGE_KEY_STATE, JSON.stringify(state));
|
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);
|
|
||||||
}
|
|
||||||
|
@ -12,9 +12,7 @@ export {
|
|||||||
loadFromJSON,
|
loadFromJSON,
|
||||||
saveAsJSON,
|
saveAsJSON,
|
||||||
restoreFromLocalStorage,
|
restoreFromLocalStorage,
|
||||||
saveToLocalStorage,
|
saveToLocalStorage
|
||||||
restoreFromURL,
|
|
||||||
saveToURL
|
|
||||||
} from "./data";
|
} from "./data";
|
||||||
export { hasBackground, hasStroke, getElementAtPosition } from "./comparisons";
|
export { hasBackground, hasStroke, getElementAtPosition } from "./comparisons";
|
||||||
export { createScene } from "./createScene";
|
export { createScene } from "./createScene";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user