2022-03-20 08:56:28 +00:00
|
|
|
import { Editor } from "../editor";
|
|
|
|
import { PageMeta } from "../types";
|
2022-03-25 11:03:06 +00:00
|
|
|
import { SysCallMapping } from "../../plugbox/system";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-03-25 11:03:06 +00:00
|
|
|
export default (editor: Editor): SysCallMapping => ({
|
|
|
|
listPages: (): PageMeta[] => {
|
2022-03-20 08:56:28 +00:00
|
|
|
return [...editor.viewState.allPages];
|
|
|
|
},
|
2022-03-25 11:03:06 +00:00
|
|
|
readPage: async (
|
|
|
|
ctx,
|
2022-03-20 08:56:28 +00:00
|
|
|
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> => {
|
2022-03-20 08:56:28 +00:00
|
|
|
return await editor.space.writePage(name, text);
|
|
|
|
},
|
2022-03-25 11:03:06 +00:00
|
|
|
deletePage: async (ctx, name: string) => {
|
2022-03-20 08:56:28 +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);
|
|
|
|
},
|
|
|
|
});
|