Editor refactor: extract system stuff
This commit is contained in:
+10
-11
@@ -3,26 +3,25 @@ import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { AttachmentMeta, PageMeta } from "../types.ts";
|
||||
|
||||
export function spaceSyscalls(editor: Editor): SysCallMapping {
|
||||
const space = editor.space;
|
||||
return {
|
||||
"space.listPages": (): Promise<PageMeta[]> => {
|
||||
return space.fetchPageList();
|
||||
return editor.space.fetchPageList();
|
||||
},
|
||||
"space.readPage": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
): Promise<string> => {
|
||||
return (await space.readPage(name)).text;
|
||||
return (await editor.space.readPage(name)).text;
|
||||
},
|
||||
"space.getPageMeta": (_ctx, name: string): Promise<PageMeta> => {
|
||||
return space.getPageMeta(name);
|
||||
return editor.space.getPageMeta(name);
|
||||
},
|
||||
"space.writePage": (
|
||||
_ctx,
|
||||
name: string,
|
||||
text: string,
|
||||
): Promise<PageMeta> => {
|
||||
return space.writePage(name, text);
|
||||
return editor.space.writePage(name, text);
|
||||
},
|
||||
"space.deletePage": async (_ctx, name: string) => {
|
||||
// If we're deleting the current page, navigate to the index page
|
||||
@@ -35,32 +34,32 @@ export function spaceSyscalls(editor: Editor): SysCallMapping {
|
||||
await editor.space.deletePage(name);
|
||||
},
|
||||
"space.listPlugs": (): Promise<string[]> => {
|
||||
return space.listPlugs();
|
||||
return editor.space.listPlugs();
|
||||
},
|
||||
"space.listAttachments": async (): Promise<AttachmentMeta[]> => {
|
||||
return await space.fetchAttachmentList();
|
||||
return await editor.space.fetchAttachmentList();
|
||||
},
|
||||
"space.readAttachment": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
): Promise<Uint8Array> => {
|
||||
return (await space.readAttachment(name)).data;
|
||||
return (await editor.space.readAttachment(name)).data;
|
||||
},
|
||||
"space.getAttachmentMeta": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
): Promise<AttachmentMeta> => {
|
||||
return await space.getAttachmentMeta(name);
|
||||
return await editor.space.getAttachmentMeta(name);
|
||||
},
|
||||
"space.writeAttachment": (
|
||||
_ctx,
|
||||
name: string,
|
||||
data: Uint8Array,
|
||||
): Promise<AttachmentMeta> => {
|
||||
return space.writeAttachment(name, data);
|
||||
return editor.space.writeAttachment(name, data);
|
||||
},
|
||||
"space.deleteAttachment": async (_ctx, name: string) => {
|
||||
await space.deleteAttachment(name);
|
||||
await editor.space.deleteAttachment(name);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { SyncService } from "../sync_service.ts";
|
||||
import type { Editor } from "../editor.tsx";
|
||||
|
||||
export function syncSyscalls(syncService: SyncService): SysCallMapping {
|
||||
export function syncSyscalls(editor: Editor): SysCallMapping {
|
||||
return {
|
||||
"sync.isSyncing": (): Promise<boolean> => {
|
||||
return syncService.isSyncing();
|
||||
return editor.syncService.isSyncing();
|
||||
},
|
||||
"sync.hasInitialSyncCompleted": (): Promise<boolean> => {
|
||||
return syncService.hasInitialSyncCompleted();
|
||||
return editor.syncService.hasInitialSyncCompleted();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export function systemSyscalls(
|
||||
},
|
||||
"system.listCommands": (): { [key: string]: CommandDef } => {
|
||||
const allCommands: { [key: string]: CommandDef } = {};
|
||||
for (let [cmd, def] of editor.commandHook.editorCommands) {
|
||||
for (const [cmd, def] of editor.system.commandHook.editorCommands) {
|
||||
allCommands[cmd] = def.command;
|
||||
}
|
||||
return allCommands;
|
||||
|
||||
Reference in New Issue
Block a user