1
0
silverbullet/packages/web/components/panel_page.ts

36 lines
705 B
TypeScript
Raw Normal View History

2022-05-11 18:10:45 +00:00
declare global {
function syscall(name: string, ...args: any[]): Promise<any>;
// function require(moduleName: string): any;
}
2022-04-05 15:02:17 +00:00
window.addEventListener("message", (message) => {
const data = message.data;
switch (data.type) {
case "html":
document.body.innerHTML = data.html;
2022-05-09 12:59:12 +00:00
if (data.script) {
try {
eval(data.script);
} catch (e: any) {
console.error("Error evaling script", e);
}
}
2022-04-05 15:02:17 +00:00
break;
}
});
2022-05-11 18:10:45 +00:00
function sendEvent(name: string, ...args: any[]) {
2022-04-05 15:02:17 +00:00
window.parent.postMessage(
{
type: "event",
2022-05-11 18:10:45 +00:00
name,
args,
2022-04-05 15:02:17 +00:00
},
"*"
);
}
//
// setInterval(() => {
// self.sendEvent("testing");
// }, 2000);