Massive restructure of plugin API

This commit is contained in:
Zef Hemel
2022-10-14 15:11:33 +02:00
parent 982623fc38
commit 7d28b53b75
70 changed files with 826 additions and 969 deletions
+1 -20
View File
@@ -54,7 +54,7 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
"editor.reloadPage": async () => {
await editor.reloadPage();
},
"editor.openUrl": async (ctx, url: string) => {
"editor.openUrl": (_ctx, url: string) => {
let win = window.open(url, "_blank");
if (win) {
win.focus();
@@ -95,25 +95,6 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
id: id as any,
});
},
// Deprecated in favor of using "hidePanel" and "showPanel"
"editor.showRhs": (ctx, html: string, script: string, flex: number) => {
syscalls["editor.showPanel"](ctx, "rhs", flex, html, script);
},
"editor.hideRhs": (ctx) => {
syscalls["editor.hidePanel"](ctx, "rhs");
},
"editor.showLhs": (ctx, html: string, script: string, flex: number) => {
syscalls["editor.showPanel"](ctx, "lhs", flex, html, script);
},
"editor.hideLhs": (ctx) => {
syscalls["editor.hidePanel"](ctx, "lhs");
},
"editor.showBhs": (ctx, html: string, script: string, flex: number) => {
syscalls["editor.showPanel"](ctx, "bhs", flex, html, script);
},
"editor.hideBhs": (ctx) => {
syscalls["editor.hidePanel"](ctx, "bhs");
},
"editor.insertAtPos": (ctx, text: string, pos: number) => {
editor.editorView!.dispatch({
changes: {
+4 -4
View File
@@ -14,8 +14,8 @@ export function spaceSyscalls(editor: Editor): SysCallMapping {
"space.readPage": async (
_ctx,
name: string,
): Promise<{ text: string; meta: PageMeta }> => {
return await editor.space.readPage(name);
): Promise<string> => {
return (await editor.space.readPage(name)).text;
},
"space.getPageMeta": async (_ctx, name: string): Promise<PageMeta> => {
return await editor.space.getPageMeta(name);
@@ -46,8 +46,8 @@ export function spaceSyscalls(editor: Editor): SysCallMapping {
"space.readAttachment": async (
_ctx,
name: string,
): Promise<{ data: FileData; meta: AttachmentMeta }> => {
return await editor.space.readAttachment(name, "dataurl");
): Promise<FileData> => {
return (await editor.space.readAttachment(name, "dataurl")).data;
},
"space.getAttachmentMeta": async (
_ctx,
+6 -9
View File
@@ -4,7 +4,7 @@ import { CommandDef } from "../hooks/command.ts";
export function systemSyscalls(editor: Editor): SysCallMapping {
return {
"system.invokeFunction": async (
"system.invokeFunction": (
ctx,
env: string,
name: string,
@@ -20,23 +20,20 @@ export function systemSyscalls(editor: Editor): SysCallMapping {
return editor.space.invokeFunction(ctx.plug, env, name, args);
},
"system.invokeCommand": async (ctx, name: string) => {
"system.invokeCommand": (ctx, name: string) => {
return editor.runCommandByName(name);
},
"system.listCommands": async (
ctx,
): Promise<{ [key: string]: CommandDef }> => {
let allCommands: { [key: string]: CommandDef } = {};
"system.listCommands": (): { [key: string]: CommandDef } => {
const allCommands: { [key: string]: CommandDef } = {};
for (let [cmd, def] of editor.commandHook.editorCommands) {
allCommands[cmd] = def.command;
}
return allCommands;
},
"system.reloadPlugs": async () => {
"system.reloadPlugs": () => {
return editor.reloadPlugs();
},
"sandbox.getServerLogs": async (ctx) => {
"sandbox.getServerLogs": (ctx) => {
return editor.space.proxySyscall(ctx.plug, "sandbox.getLogs", []);
},
};