Spaces:
Running
Running
File size: 976 Bytes
9a4ea8c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | /** Carry the selected reference into the existing analytical workbench. */
export function createAnalysis(report, onPoint) {
const frame = document.querySelector("#comparison");
let ready = false,
selection = null;
function deliver() {
if (ready && selection)
frame.contentWindow.postMessage(
{ type: "pe:topology", ...selection },
location.origin,
);
}
window.addEventListener("message", (event) => {
if (
event.origin !== location.origin ||
event.source !== frame.contentWindow
)
return;
if (event.data?.type === "pe:analysis-ready") {
ready = true;
deliver();
}
if (event.data?.type === "pe:analysis-point") onPoint(event.data);
if (event.data?.type === "pe:analysis-error") report(event.data.message);
});
function show(next) {
if (next) selection = next;
if (!frame.getAttribute("src")) frame.src = frame.dataset.src;
deliver();
}
return { show };
}
|