-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb9f0eb
commit 7a23086
Showing
6 changed files
with
54 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
import { downloadAsFile } from "@/utils/html"; | ||
import { CommandContext } from "./context"; | ||
|
||
export const command = { | ||
name: "saveAsCurrentWorkspace", | ||
name: "saveCurrentWorkspaceAsFile", | ||
description: "Save the current workspace as a new file", | ||
execute: async ( | ||
context: CommandContext, | ||
_: CommandContext, | ||
payload: { | ||
workspaceId: string; | ||
layerName: string; | ||
format: "jpeg" | "png"; | ||
} | ||
) => { | ||
console.log("Saving sheet", context, payload); | ||
const { format } = payload; | ||
const canvas = document.querySelector( | ||
"#canvas-renderer" | ||
) as HTMLCanvasElement; | ||
const data = canvas.toDataURL(`image/${format}`, 1.0); | ||
downloadAsFile(data, `picture.${format}`); | ||
}, | ||
} as const; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const downloadAsFile = (data: string, filename: string) => { | ||
var anchor = document.createElement("a"); | ||
anchor.href = data; | ||
anchor.download = filename; | ||
anchor.click(); | ||
}; | ||
|