2023-10-29 09:02:50 +00:00
|
|
|
import { CodeWidgetContent } from "$sb/types.ts";
|
2023-10-03 12:16:33 +00:00
|
|
|
import { SysCallMapping } from "../../plugos/system.ts";
|
|
|
|
import { Client } from "../client.ts";
|
|
|
|
|
|
|
|
export function widgetSyscalls(
|
|
|
|
client: Client,
|
|
|
|
): SysCallMapping {
|
|
|
|
return {
|
|
|
|
"widget.render": (
|
|
|
|
_ctx,
|
|
|
|
lang: string,
|
|
|
|
body: string,
|
2023-10-29 09:02:50 +00:00
|
|
|
): Promise<CodeWidgetContent> => {
|
2023-10-03 12:16:33 +00:00
|
|
|
const langCallback = client.system.codeWidgetHook.codeWidgetCallbacks.get(
|
|
|
|
lang,
|
|
|
|
);
|
|
|
|
if (!langCallback) {
|
|
|
|
throw new Error(`Code widget ${lang} not found`);
|
|
|
|
}
|
|
|
|
return langCallback(body);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|