2024-07-30 23:33:33 +08:00
|
|
|
import type { CodeWidgetContent } from "../../plug-api/types.ts";
|
|
|
|
import type { SysCallMapping } from "../../lib/plugos/system.ts";
|
|
|
|
import type { CodeWidgetHook } from "../hooks/code_widget.ts";
|
2023-10-03 20:16:33 +08:00
|
|
|
|
2023-10-31 17:33:38 +08:00
|
|
|
export function codeWidgetSyscalls(
|
|
|
|
codeWidgetHook: CodeWidgetHook,
|
2023-10-03 20:16:33 +08:00
|
|
|
): SysCallMapping {
|
|
|
|
return {
|
2023-10-31 17:33:38 +08:00
|
|
|
"codeWidget.render": (
|
2023-10-03 20:16:33 +08:00
|
|
|
_ctx,
|
|
|
|
lang: string,
|
|
|
|
body: string,
|
2023-10-31 17:33:38 +08:00
|
|
|
pageName: string,
|
2024-01-09 00:08:26 +08:00
|
|
|
): Promise<CodeWidgetContent | null> => {
|
2023-10-31 17:33:38 +08:00
|
|
|
const langCallback = codeWidgetHook.codeWidgetCallbacks.get(
|
2023-10-03 20:16:33 +08:00
|
|
|
lang,
|
|
|
|
);
|
|
|
|
if (!langCallback) {
|
|
|
|
throw new Error(`Code widget ${lang} not found`);
|
|
|
|
}
|
2023-10-31 17:33:38 +08:00
|
|
|
return langCallback(body, pageName);
|
2023-10-03 20:16:33 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|