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";
|
2023-10-31 09:33:38 +00:00
|
|
|
import { CodeWidgetHook } from "../hooks/code_widget.ts";
|
2023-10-03 12:16:33 +00:00
|
|
|
|
2023-10-31 09:33:38 +00:00
|
|
|
export function codeWidgetSyscalls(
|
|
|
|
codeWidgetHook: CodeWidgetHook,
|
2023-10-03 12:16:33 +00:00
|
|
|
): SysCallMapping {
|
|
|
|
return {
|
2023-10-31 09:33:38 +00:00
|
|
|
"codeWidget.render": (
|
2023-10-03 12:16:33 +00:00
|
|
|
_ctx,
|
|
|
|
lang: string,
|
|
|
|
body: string,
|
2023-10-31 09:33:38 +00:00
|
|
|
pageName: string,
|
2023-10-29 09:02:50 +00:00
|
|
|
): Promise<CodeWidgetContent> => {
|
2023-10-31 09:33:38 +00:00
|
|
|
const langCallback = codeWidgetHook.codeWidgetCallbacks.get(
|
2023-10-03 12:16:33 +00:00
|
|
|
lang,
|
|
|
|
);
|
|
|
|
if (!langCallback) {
|
|
|
|
throw new Error(`Code widget ${lang} not found`);
|
|
|
|
}
|
2023-10-31 09:33:38 +00:00
|
|
|
return langCallback(body, pageName);
|
2023-10-03 12:16:33 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|