2022-04-04 13:25:07 +00:00
|
|
|
import {useEffect, useRef} from "react";
|
|
|
|
// @ts-ignore
|
|
|
|
import iframeHtml from "bundle-text:./panel.html";
|
|
|
|
import {Simulate} from "react-dom/test-utils";
|
2022-03-28 13:25:05 +00:00
|
|
|
|
|
|
|
export function Panel({ html }: { html: string }) {
|
|
|
|
const iFrameRef = useRef<HTMLIFrameElement>(null);
|
2022-04-04 13:25:07 +00:00
|
|
|
useEffect(() => {
|
|
|
|
function loadContent() {
|
|
|
|
if (iFrameRef.current?.contentWindow) {
|
|
|
|
iFrameRef.current.contentWindow.postMessage({
|
|
|
|
type: "html",
|
|
|
|
html: html,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!iFrameRef.current) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let iframe = iFrameRef.current;
|
|
|
|
iframe.onload = loadContent;
|
|
|
|
loadContent();
|
|
|
|
return () => {
|
|
|
|
iframe.onload = null;
|
|
|
|
};
|
|
|
|
}, [html]);
|
2022-03-28 13:25:05 +00:00
|
|
|
return (
|
|
|
|
<div className="panel">
|
2022-04-04 13:25:07 +00:00
|
|
|
<iframe srcDoc={iframeHtml} ref={iFrameRef} />
|
2022-03-28 13:25:05 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|