Tweaks and panel updates
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user