Handle inline images and attachments via data urls

This commit is contained in:
Zef Hemel
2023-01-08 15:29:34 +01:00
parent 0365673c41
commit 8dac58f38a
7 changed files with 53 additions and 16 deletions
+2 -2
View File
@@ -27,8 +27,8 @@ class InlineImageWidget extends WidgetType {
if (this.url.startsWith("http")) {
img.src = this.url;
} else {
// Specific to mobile
this.space.readAttachment(decodeURI(this.url), "dataurl").then(
// Load the image as a dataURL and inject it into the img's src attribute
this.space.readAttachment(decodeURIComponent(this.url), "dataurl").then(
({ data }) => {
img.src = data as string;
},
+6
View File
@@ -38,6 +38,12 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
win.focus();
}
},
"editor.downloadFile": (_ctx, filename: string, dataUrl: string) => {
const link = document.createElement("a");
link.href = dataUrl;
link.download = filename;
link.click();
},
"editor.flashNotification": (
_ctx,
message: string,