1
0
silverbullet/packages/web/components/panel_page.ts
2022-05-11 20:10:45 +02:00

36 lines
705 B
TypeScript

declare global {
function syscall(name: string, ...args: any[]): Promise<any>;
// function require(moduleName: string): any;
}
window.addEventListener("message", (message) => {
const data = message.data;
switch (data.type) {
case "html":
document.body.innerHTML = data.html;
if (data.script) {
try {
eval(data.script);
} catch (e: any) {
console.error("Error evaling script", e);
}
}
break;
}
});
function sendEvent(name: string, ...args: any[]) {
window.parent.postMessage(
{
type: "event",
name,
args,
},
"*"
);
}
//
// setInterval(() => {
// self.sendEvent("testing");
// }, 2000);