Mobile app PoC (#281)

Initial checkin of mobile "native" app
This commit is contained in:
Zef Hemel
2023-01-08 12:24:12 +01:00
committed by GitHub
parent dc7de9d8f9
commit 0365673c41
61 changed files with 5190 additions and 155 deletions
+16 -4
View File
@@ -7,8 +7,14 @@ import {
} from "../deps.ts";
import { decoratorStateField } from "./util.ts";
import type { Space } from "../../common/spaces/space.ts";
class InlineImageWidget extends WidgetType {
constructor(readonly url: string, readonly title: string) {
constructor(
readonly url: string,
readonly title: string,
readonly space: Space,
) {
super();
}
@@ -21,8 +27,14 @@ class InlineImageWidget extends WidgetType {
if (this.url.startsWith("http")) {
img.src = this.url;
} else {
img.src = `fs/${this.url}`;
// Specific to mobile
this.space.readAttachment(decodeURI(this.url), "dataurl").then(
({ data }) => {
img.src = data as string;
},
);
}
img.alt = this.title;
img.title = this.title;
img.style.display = "block";
@@ -32,7 +44,7 @@ class InlineImageWidget extends WidgetType {
}
}
export function inlineImagesPlugin() {
export function inlineImagesPlugin(space: Space) {
return decoratorStateField((state: EditorState) => {
const widgets: Range<Decoration>[] = [];
const imageRegex = /!\[(?<title>[^\]]*)\]\((?<url>.+)\)/;
@@ -54,7 +66,7 @@ export function inlineImagesPlugin() {
const title = imageRexexResult.groups.title;
widgets.push(
Decoration.widget({
widget: new InlineImageWidget(url, title),
widget: new InlineImageWidget(url, title, space),
}).range(node.to),
);
},