mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Implement Save without re-prompt and Save as (#1709)
* Implement Save without re-prompt and Save as Fixes #1668 * Add save-as icon * Make .excalidraw the default extension * Only show save as button on supporting browsers
This commit is contained in:
parent
0ed6a96b6a
commit
5d3867d8ac
11 changed files with 74 additions and 26 deletions
|
@ -1,7 +1,7 @@
|
|||
import React from "react";
|
||||
import { ProjectName } from "../components/ProjectName";
|
||||
import { saveAsJSON, loadFromJSON } from "../data";
|
||||
import { load, save } from "../components/icons";
|
||||
import { load, save, saveAs } from "../components/icons";
|
||||
import { ToolButton } from "../components/ToolButton";
|
||||
import { t } from "../i18n";
|
||||
import useIsMobile from "../is-mobile";
|
||||
|
@ -65,11 +65,13 @@ export const actionChangeShouldAddWatermark = register({
|
|||
export const actionSaveScene = register({
|
||||
name: "saveScene",
|
||||
perform: (elements, appState, value) => {
|
||||
saveAsJSON(elements, appState).catch((error) => console.error(error));
|
||||
saveAsJSON(elements, appState, (window as any).handle).catch((error) =>
|
||||
console.error(error),
|
||||
);
|
||||
return { commitToHistory: false };
|
||||
},
|
||||
keyTest: (event) => {
|
||||
return event.key === "s" && event[KEYS.CTRL_OR_CMD];
|
||||
return event.key === "s" && event[KEYS.CTRL_OR_CMD] && !event.shiftKey;
|
||||
},
|
||||
PanelComponent: ({ updateData }) => (
|
||||
<ToolButton
|
||||
|
@ -83,6 +85,28 @@ export const actionSaveScene = register({
|
|||
),
|
||||
});
|
||||
|
||||
export const actionSaveAsScene = register({
|
||||
name: "saveAsScene",
|
||||
perform: (elements, appState, value) => {
|
||||
saveAsJSON(elements, appState, null).catch((error) => console.error(error));
|
||||
return { commitToHistory: false };
|
||||
},
|
||||
keyTest: (event) => {
|
||||
return event.key === "s" && event.shiftKey && event[KEYS.CTRL_OR_CMD];
|
||||
},
|
||||
PanelComponent: ({ updateData }) => (
|
||||
<ToolButton
|
||||
type="button"
|
||||
icon={saveAs}
|
||||
title={t("buttons.saveAs")}
|
||||
aria-label={t("buttons.saveAs")}
|
||||
showAriaLabel={useIsMobile()}
|
||||
hidden={!("chooseFileSystemEntries" in window)}
|
||||
onClick={() => updateData(null)}
|
||||
/>
|
||||
),
|
||||
});
|
||||
|
||||
export const actionLoadScene = register({
|
||||
name: "loadScene",
|
||||
perform: (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue