1
0
silverbullet/web/syscalls/space.ts

66 lines
2.0 KiB
TypeScript
Raw Normal View History

import { Editor } from "../editor.tsx";
import { SysCallMapping } from "../../plugos/system.ts";
import { AttachmentMeta, PageMeta } from "../types.ts";
2022-04-03 16:12:16 +00:00
export function spaceSyscalls(editor: Editor): SysCallMapping {
return {
"space.listPages": (): Promise<PageMeta[]> => {
2023-07-14 11:44:30 +00:00
return editor.space.fetchPageList();
},
"space.readPage": async (
_ctx,
name: string,
): Promise<string> => {
2023-07-14 11:44:30 +00:00
return (await editor.space.readPage(name)).text;
},
"space.getPageMeta": (_ctx, name: string): Promise<PageMeta> => {
2023-07-14 11:44:30 +00:00
return editor.space.getPageMeta(name);
},
"space.writePage": (
_ctx,
name: string,
text: string,
): Promise<PageMeta> => {
2023-07-14 11:44:30 +00:00
return editor.space.writePage(name, text);
},
"space.deletePage": async (_ctx, name: string) => {
// If we're deleting the current page, navigate to the index page
if (editor.currentPage === name) {
await editor.navigate("");
}
// Remove page from open pages in editor
2023-07-14 11:58:16 +00:00
editor.openPages.openPages.delete(name);
console.log("Deleting page");
await editor.space.deletePage(name);
},
"space.listPlugs": (): Promise<string[]> => {
2023-07-14 11:44:30 +00:00
return editor.space.listPlugs();
},
"space.listAttachments": async (): Promise<AttachmentMeta[]> => {
2023-07-14 11:44:30 +00:00
return await editor.space.fetchAttachmentList();
},
"space.readAttachment": async (
_ctx,
name: string,
): Promise<Uint8Array> => {
2023-07-14 11:44:30 +00:00
return (await editor.space.readAttachment(name)).data;
},
"space.getAttachmentMeta": async (
_ctx,
name: string,
): Promise<AttachmentMeta> => {
2023-07-14 11:44:30 +00:00
return await editor.space.getAttachmentMeta(name);
},
"space.writeAttachment": (
_ctx,
name: string,
data: Uint8Array,
): Promise<AttachmentMeta> => {
2023-07-14 11:44:30 +00:00
return editor.space.writeAttachment(name, data);
},
"space.deleteAttachment": async (_ctx, name: string) => {
2023-07-14 11:44:30 +00:00
await editor.space.deleteAttachment(name);
},
2022-04-03 16:12:16 +00:00
};
}