mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Warning when leave without save
This commit is contained in:
parent
9e6db9a31c
commit
54d466de60
1 changed files with 22 additions and 0 deletions
|
@ -359,6 +359,8 @@ function save() {
|
||||||
|
|
||||||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(items));
|
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(items));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.removeEventListener("beforeunload", onUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore() {
|
function restore() {
|
||||||
|
@ -373,6 +375,18 @@ function restore() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onUnload(event: BeforeUnloadEvent) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const confirmationMessage = "excalibur";
|
||||||
|
event.returnValue = confirmationMessage;
|
||||||
|
return confirmationMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addOnBeforeUnload() {
|
||||||
|
window.addEventListener("beforeunload", onUnload);
|
||||||
|
}
|
||||||
|
|
||||||
type AppState = {
|
type AppState = {
|
||||||
draggingElement: ExcaliburElement | null;
|
draggingElement: ExcaliburElement | null;
|
||||||
elementType: string;
|
elementType: string;
|
||||||
|
@ -388,6 +402,7 @@ class App extends React.Component<{}, AppState> {
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
document.removeEventListener("keydown", this.onKeyDown, false);
|
document.removeEventListener("keydown", this.onKeyDown, false);
|
||||||
|
window.removeEventListener("beforeunload", onUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public state: AppState = {
|
public state: AppState = {
|
||||||
|
@ -408,6 +423,7 @@ class App extends React.Component<{}, AppState> {
|
||||||
drawScene();
|
drawScene();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.key === "Backspace") {
|
} else if (event.key === "Backspace") {
|
||||||
|
addOnBeforeUnload();
|
||||||
deleteSelectedElements();
|
deleteSelectedElements();
|
||||||
drawScene();
|
drawScene();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -417,6 +433,8 @@ class App extends React.Component<{}, AppState> {
|
||||||
event.key === "ArrowUp" ||
|
event.key === "ArrowUp" ||
|
||||||
event.key === "ArrowDown"
|
event.key === "ArrowDown"
|
||||||
) {
|
) {
|
||||||
|
addOnBeforeUnload();
|
||||||
|
|
||||||
const step = event.shiftKey ? 5 : 1;
|
const step = event.shiftKey ? 5 : 1;
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
if (element.isSelected) {
|
if (element.isSelected) {
|
||||||
|
@ -547,6 +565,7 @@ class App extends React.Component<{}, AppState> {
|
||||||
parsedElement.y += 10;
|
parsedElement.y += 10;
|
||||||
generateDraw(parsedElement);
|
generateDraw(parsedElement);
|
||||||
elements.push(parsedElement);
|
elements.push(parsedElement);
|
||||||
|
addOnBeforeUnload();
|
||||||
});
|
});
|
||||||
drawScene();
|
drawScene();
|
||||||
}
|
}
|
||||||
|
@ -598,6 +617,8 @@ class App extends React.Component<{}, AppState> {
|
||||||
if (isDraggingElements) {
|
if (isDraggingElements) {
|
||||||
document.documentElement.style.cursor = "move";
|
document.documentElement.style.cursor = "move";
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
addOnBeforeUnload();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTextElement(element)) {
|
if (isTextElement(element)) {
|
||||||
|
@ -658,6 +679,7 @@ class App extends React.Component<{}, AppState> {
|
||||||
lastX = x;
|
lastX = x;
|
||||||
lastY = y;
|
lastY = y;
|
||||||
drawScene();
|
drawScene();
|
||||||
|
addOnBeforeUnload();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue