Add the File > Export dialog and PNG/JPG downloading (#629)

* Add export dialog

* Code review changes

* More code review feedback

* Fix compilation on stable Rust

* Fixes to problems

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2022-05-08 23:35:22 -07:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent 79d40fa451
commit 1481b03c85
19 changed files with 445 additions and 59 deletions
+11 -4
View File
@@ -1,7 +1,4 @@
export function download(filename: string, fileData: string): void {
const type = filename.endsWith(".svg") ? "image/svg+xml;charset=utf-8" : "text/plain;charset=utf-8";
const blob = new Blob([fileData], { type });
const url = URL.createObjectURL(blob);
export function downloadBlob(url: string, filename: string): void {
const element = document.createElement("a");
element.href = url;
@@ -11,6 +8,16 @@ export function download(filename: string, fileData: string): void {
element.click();
}
export function download(filename: string, fileData: string): void {
const type = filename.endsWith(".svg") ? "image/svg+xml;charset=utf-8" : "text/plain;charset=utf-8";
const blob = new Blob([fileData], { type });
const url = URL.createObjectURL(blob);
downloadBlob(url, filename);
URL.revokeObjectURL(url);
}
export async function upload(acceptedEextensions: string): Promise<{ filename: string; content: string }> {
return new Promise<{ filename: string; content: string }>((resolve, _) => {
const element = document.createElement("input");