2022-10-10 12:50:21 +00:00
|
|
|
import { Editor } from "../editor.tsx";
|
|
|
|
import { SysCallMapping } from "../../plugos/system.ts";
|
|
|
|
import { AttachmentMeta, PageMeta } from "../../common/types.ts";
|
2022-09-12 12:50:37 +00:00
|
|
|
import {
|
|
|
|
FileData,
|
|
|
|
FileEncoding,
|
2022-10-10 12:50:21 +00:00
|
|
|
} from "../../common/spaces/space_primitives.ts";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-04-03 16:12:16 +00:00
|
|
|
export function spaceSyscalls(editor: Editor): SysCallMapping {
|
|
|
|
return {
|
2022-10-10 12:50:21 +00:00
|
|
|
"space.listPages": (): PageMeta[] => {
|
2022-09-12 12:50:37 +00:00
|
|
|
return [...editor.space.listPages()];
|
2022-04-03 16:12:16 +00:00
|
|
|
},
|
2022-04-03 16:42:12 +00:00
|
|
|
"space.readPage": async (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
|
|
|
name: string,
|
2022-04-03 16:12:16 +00:00
|
|
|
): Promise<{ text: string; meta: PageMeta }> => {
|
|
|
|
return await editor.space.readPage(name);
|
|
|
|
},
|
2022-10-10 12:50:21 +00:00
|
|
|
"space.getPageMeta": async (_ctx, name: string): Promise<PageMeta> => {
|
2022-08-08 11:33:20 +00:00
|
|
|
return await editor.space.getPageMeta(name);
|
|
|
|
},
|
2022-04-03 16:42:12 +00:00
|
|
|
"space.writePage": async (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
2022-04-03 16:42:12 +00:00
|
|
|
name: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
text: string,
|
2022-04-03 16:42:12 +00:00
|
|
|
): Promise<PageMeta> => {
|
2022-04-03 16:12:16 +00:00
|
|
|
return await editor.space.writePage(name, text);
|
|
|
|
},
|
2022-10-10 12:50:21 +00:00
|
|
|
"space.deletePage": async (_ctx, name: string) => {
|
2022-06-28 12:14:15 +00:00
|
|
|
// If we're deleting the current page, navigate to the index page
|
2022-04-03 16:12:16 +00:00
|
|
|
if (editor.currentPage === name) {
|
2022-08-02 10:43:39 +00:00
|
|
|
await editor.navigate("");
|
2022-04-03 16:12:16 +00:00
|
|
|
}
|
|
|
|
// Remove page from open pages in editor
|
|
|
|
editor.openPages.delete(name);
|
|
|
|
console.log("Deleting page");
|
|
|
|
await editor.space.deletePage(name);
|
|
|
|
},
|
2022-10-10 12:50:21 +00:00
|
|
|
"space.listPlugs": (): Promise<string[]> => {
|
|
|
|
return editor.space.listPlugs();
|
2022-09-12 12:50:37 +00:00
|
|
|
},
|
2022-10-10 12:50:21 +00:00
|
|
|
"space.listAttachments": (): Promise<AttachmentMeta[]> => {
|
|
|
|
return editor.space.fetchAttachmentList();
|
2022-09-05 11:36:04 +00:00
|
|
|
},
|
|
|
|
"space.readAttachment": async (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
|
|
|
name: string,
|
2022-09-12 12:50:37 +00:00
|
|
|
): Promise<{ data: FileData; meta: AttachmentMeta }> => {
|
2022-09-05 14:15:01 +00:00
|
|
|
return await editor.space.readAttachment(name, "dataurl");
|
2022-09-05 11:36:04 +00:00
|
|
|
},
|
|
|
|
"space.getAttachmentMeta": async (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
|
|
|
name: string,
|
2022-09-05 11:36:04 +00:00
|
|
|
): Promise<AttachmentMeta> => {
|
|
|
|
return await editor.space.getAttachmentMeta(name);
|
|
|
|
},
|
|
|
|
"space.writeAttachment": async (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
2022-09-05 11:36:04 +00:00
|
|
|
name: string,
|
2022-09-12 12:50:37 +00:00
|
|
|
encoding: FileEncoding,
|
2022-10-10 12:50:21 +00:00
|
|
|
data: FileData,
|
2022-09-05 11:36:04 +00:00
|
|
|
): Promise<AttachmentMeta> => {
|
2022-09-12 12:50:37 +00:00
|
|
|
return await editor.space.writeAttachment(name, encoding, data);
|
2022-09-05 11:36:04 +00:00
|
|
|
},
|
2022-10-10 12:50:21 +00:00
|
|
|
"space.deleteAttachment": async (_ctx, name: string) => {
|
2022-09-05 11:36:04 +00:00
|
|
|
await editor.space.deleteAttachment(name);
|
|
|
|
},
|
2022-04-03 16:12:16 +00:00
|
|
|
};
|
|
|
|
}
|