1
0
silverbullet/webapp/syscalls/space.ts

29 lines
909 B
TypeScript
Raw Normal View History

import { Editor } from "../editor";
import { PageMeta } from "../types";
2022-03-27 09:31:12 +00:00
import { SysCallMapping } from "../../plugos/system";
2022-03-25 11:03:06 +00:00
export default (editor: Editor): SysCallMapping => ({
listPages: (): PageMeta[] => {
return [...editor.viewState.allPages];
},
2022-03-25 11:03:06 +00:00
readPage: async (
ctx,
name: string
): Promise<{ text: string; meta: PageMeta }> => {
return await editor.space.readPage(name);
},
2022-03-25 11:03:06 +00:00
writePage: async (ctx, name: string, text: string): Promise<PageMeta> => {
return await editor.space.writePage(name, text);
},
2022-03-25 11:03:06 +00:00
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);
},
});