2022-04-05 15:02:17 +00:00
|
|
|
import { Editor } from "../editor";
|
2022-04-25 08:33:38 +00:00
|
|
|
import { SysCallMapping } from "@plugos/plugos/system";
|
2022-09-05 11:36:04 +00:00
|
|
|
import { AttachmentMeta, PageMeta } from "@silverbulletmd/common/types";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-04-03 16:12:16 +00:00
|
|
|
export function spaceSyscalls(editor: Editor): SysCallMapping {
|
|
|
|
return {
|
2022-04-26 17:04:36 +00:00
|
|
|
"space.listPages": async (ctx, unfiltered = false): Promise<PageMeta[]> => {
|
|
|
|
return [...(await editor.space.listPages(unfiltered))];
|
2022-04-03 16:12:16 +00:00
|
|
|
},
|
2022-04-03 16:42:12 +00:00
|
|
|
"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);
|
|
|
|
},
|
2022-08-08 11:33:20 +00:00
|
|
|
"space.getPageMeta": async (ctx, name: string): Promise<PageMeta> => {
|
|
|
|
return await editor.space.getPageMeta(name);
|
|
|
|
},
|
2022-04-03 16:42:12 +00:00
|
|
|
"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);
|
|
|
|
},
|
2022-04-03 16:42:12 +00:00
|
|
|
"space.deletePage": async (ctx, name: string) => {
|
2022-06-28 12:14:15 +00:00
|
|
|
// If we're deleting the current page, navigate to the index page
|
2022-04-03 16:12:16 +00:00
|
|
|
if (editor.currentPage === name) {
|
2022-08-02 10:43:39 +00:00
|
|
|
await editor.navigate("");
|
2022-04-03 16:12:16 +00:00
|
|
|
}
|
|
|
|
// Remove page from open pages in editor
|
|
|
|
editor.openPages.delete(name);
|
|
|
|
console.log("Deleting page");
|
|
|
|
await editor.space.deletePage(name);
|
|
|
|
},
|
2022-09-05 11:36:04 +00:00
|
|
|
"space.listAttachments": async (ctx): Promise<AttachmentMeta[]> => {
|
|
|
|
return [...(await editor.space.fetchAttachmentList()).attachments];
|
|
|
|
},
|
|
|
|
"space.readAttachment": async (
|
|
|
|
ctx,
|
|
|
|
name: string
|
|
|
|
): Promise<{ buffer: ArrayBuffer; meta: AttachmentMeta }> => {
|
|
|
|
return await editor.space.readAttachment(name);
|
|
|
|
},
|
|
|
|
"space.getAttachmentMeta": async (
|
|
|
|
ctx,
|
|
|
|
name: string
|
|
|
|
): Promise<AttachmentMeta> => {
|
|
|
|
return await editor.space.getAttachmentMeta(name);
|
|
|
|
},
|
|
|
|
"space.writeAttachment": async (
|
|
|
|
ctx,
|
|
|
|
name: string,
|
|
|
|
buffer: ArrayBuffer
|
|
|
|
): Promise<AttachmentMeta> => {
|
|
|
|
return await editor.space.writeAttachment(name, buffer);
|
|
|
|
},
|
|
|
|
"space.deleteAttachment": async (ctx, name: string) => {
|
|
|
|
await editor.space.deleteAttachment(name);
|
|
|
|
},
|
2022-04-03 16:12:16 +00:00
|
|
|
};
|
|
|
|
}
|