Tweaks and panel updates

This commit is contained in:
Zef Hemel
2022-05-11 20:10:45 +02:00
parent 4518476c77
commit 8c974161c3
7 changed files with 40 additions and 10 deletions
+8 -1
View File
@@ -1,15 +1,20 @@
import { useEffect, useRef } from "react";
// @ts-ignore
import iframeHtml from "bundle-text:./panel.html";
import { System } from "@plugos/plugos/system";
import { SilverBulletHooks } from "@silverbulletmd/common/manifest";
import { Editor } from "../editor";
export function Panel({
html,
script,
flex,
editor,
}: {
html: string;
script?: string;
flex: number;
editor: Editor;
}) {
const iFrameRef = useRef<HTMLIFrameElement>(null);
useEffect(() => {
@@ -40,7 +45,9 @@ export function Panel({
}
let data = evt.data;
if (!data) return;
console.log("Got message from panel", data);
if (data.type === "event") {
editor.dispatchAppEvent(data.name, data.args);
}
};
window.addEventListener("message", messageListener);
return () => {
+8 -2
View File
@@ -1,3 +1,8 @@
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) {
@@ -14,11 +19,12 @@ window.addEventListener("message", (message) => {
}
});
function sendEvent(data: any) {
function sendEvent(name: string, ...args: any[]) {
window.parent.postMessage(
{
type: "event",
data: data,
name,
args,
},
"*"
);