const modulePath = '/workbench/module.html';
if (location.pathname === modulePath) {
if (window.parent === window) {
location.replace('/workbench/platform.html');
} else {
const available = new Set(['home', 'register', 'archives', 'target-lists', 'maps', 'history', 'receivers']);
let navigating = false;
function send(type, view) {
window.parent.postMessage({ type, view }, location.origin);
}
function ready() {
send('rid-embedded-ready');
}
window.addEventListener('rid-embedded-ready', ready);
if (document.body?.className === 'rid-embedded') ready();
window.addEventListener('message', event => {
if (event.origin !== location.origin || event.source !== window.parent ||
event.data?.type !== 'rid-embedded-navigate' || !available.has(event.data.view)) return;
navigating = true;
try {
const { view, record, mapOptions } = event.data;
if (view === 'history') window.ridHistory?.setMapOptions(mapOptions);
if (document.body.dataset.screen !== view) {
window.dispatchEvent(new CustomEvent('rid-embedded-navigate', { detail: view }));
}
if (view === 'history') {
window.dispatchEvent(new CustomEvent('rid-history-record', {
detail: record ? JSON.stringify(record) : null
}));
}
} finally {
navigating = false;
}
});
window.addEventListener('rid-history-return-records', () => send('rid-embedded-return-records'));
window.addEventListener('rid-workspace-view', () => {
const view = document.body.dataset.screen;
if (!navigating && available.has(view)) send('rid-embedded-view', view);
});
}
}