2023-07-14 14:56:20 +00:00
|
|
|
import { Client } from "../client.ts";
|
2022-10-10 12:50:21 +00:00
|
|
|
import { SysCallMapping } from "../../plugos/system.ts";
|
2023-10-03 12:16:33 +00:00
|
|
|
import { AttachmentMeta, FileMeta, PageMeta } from "$sb/types.ts";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2023-07-14 14:56:20 +00:00
|
|
|
export function spaceSyscalls(editor: Client): SysCallMapping {
|
2023-05-23 18:53:53 +00:00
|
|
|
return {
|
|
|
|
"space.listPages": (): Promise<PageMeta[]> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return editor.space.fetchPageList();
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"space.readPage": async (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
): Promise<string> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return (await editor.space.readPage(name)).text;
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"space.getPageMeta": (_ctx, name: string): Promise<PageMeta> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return editor.space.getPageMeta(name);
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"space.writePage": (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
text: string,
|
|
|
|
): Promise<PageMeta> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return editor.space.writePage(name, text);
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"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);
|
2023-05-23 18:53:53 +00:00
|
|
|
console.log("Deleting page");
|
|
|
|
await editor.space.deletePage(name);
|
|
|
|
},
|
2023-12-06 17:44:48 +00:00
|
|
|
"space.listPlugs": (): Promise<FileMeta[]> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return editor.space.listPlugs();
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"space.listAttachments": async (): Promise<AttachmentMeta[]> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return await editor.space.fetchAttachmentList();
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"space.readAttachment": async (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
2023-05-26 12:04:32 +00:00
|
|
|
): Promise<Uint8Array> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return (await editor.space.readAttachment(name)).data;
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"space.getAttachmentMeta": async (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
): Promise<AttachmentMeta> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return await editor.space.getAttachmentMeta(name);
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
2023-05-26 12:04:32 +00:00
|
|
|
"space.writeAttachment": (
|
2023-05-23 18:53:53 +00:00
|
|
|
_ctx,
|
|
|
|
name: string,
|
2023-05-26 12:04:32 +00:00
|
|
|
data: Uint8Array,
|
2023-05-23 18:53:53 +00:00
|
|
|
): Promise<AttachmentMeta> => {
|
2023-07-14 11:44:30 +00:00
|
|
|
return editor.space.writeAttachment(name, data);
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
|
|
|
"space.deleteAttachment": async (_ctx, name: string) => {
|
2023-07-14 11:44:30 +00:00
|
|
|
await editor.space.deleteAttachment(name);
|
2023-05-23 18:53:53 +00:00
|
|
|
},
|
2023-08-20 15:51:00 +00:00
|
|
|
|
|
|
|
// FS
|
|
|
|
"space.listFiles": (): Promise<FileMeta[]> => {
|
|
|
|
return editor.space.spacePrimitives.fetchFileList();
|
|
|
|
},
|
|
|
|
"space.getFileMeta": (_ctx, name: string): Promise<FileMeta> => {
|
|
|
|
return editor.space.spacePrimitives.getFileMeta(name);
|
|
|
|
},
|
|
|
|
"space.readFile": async (_ctx, name: string): Promise<Uint8Array> => {
|
|
|
|
return (await editor.space.spacePrimitives.readFile(name)).data;
|
|
|
|
},
|
|
|
|
"space.writeFile": (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
data: Uint8Array,
|
|
|
|
): Promise<FileMeta> => {
|
|
|
|
return editor.space.spacePrimitives.writeFile(name, data);
|
|
|
|
},
|
|
|
|
"space.deleteFile": (_ctx, name: string) => {
|
|
|
|
return editor.space.spacePrimitives.deleteFile(name);
|
|
|
|
},
|
2022-04-03 16:12:16 +00:00
|
|
|
};
|
|
|
|
}
|