1
0
silverbullet/webapp/syscalls/space.ts

31 lines
1003 B
TypeScript
Raw Normal View History

2022-04-03 16:12:16 +00:00
import {Editor} from "../editor";
import {SysCallMapping} from "../../plugos/system";
import {PageMeta} from "../../common/types";
2022-04-03 16:12:16 +00:00
export function spaceSyscalls(editor: Editor): SysCallMapping {
return {
listPages: async (): Promise<PageMeta[]> => {
return [...(await editor.space.listPages())];
},
readPage: async (
ctx,
name: string
): Promise<{ text: string; meta: PageMeta }> => {
return await editor.space.readPage(name);
},
writePage: async (ctx, name: string, text: string): Promise<PageMeta> => {
return await editor.space.writePage(name, text);
},
deletePage: async (ctx, name: string) => {
// If we're deleting the current page, navigate to the start page
if (editor.currentPage === name) {
await editor.navigate("start");
}
// Remove page from open pages in editor
editor.openPages.delete(name);
console.log("Deleting page");
await editor.space.deletePage(name);
},
};
}