1
0
silverbullet/packages/silverbullet-web/syscalls/space.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-04-05 15:02:17 +00:00
import { Editor } from "../editor";
import { SysCallMapping } from "@silverbulletmd/plugos/system";
import { PageMeta } from "@silverbulletmd/common/types";
2022-04-03 16:12:16 +00:00
export function spaceSyscalls(editor: Editor): SysCallMapping {
return {
"space.listPages": async (): Promise<PageMeta[]> => {
2022-04-03 16:12:16 +00:00
return [...(await editor.space.listPages())];
},
"space.readPage": async (
2022-04-03 16:12:16 +00:00
ctx,
name: string
): Promise<{ text: string; meta: PageMeta }> => {
return await editor.space.readPage(name);
},
"space.writePage": async (
ctx,
name: string,
text: string
): Promise<PageMeta> => {
2022-04-03 16:12:16 +00:00
return await editor.space.writePage(name, text);
},
"space.deletePage": async (ctx, name: string) => {
2022-04-03 16:12:16 +00:00
// 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);
},
};
}