Дальнейшая работа над интеграцией
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { DiagramDocument } from '../types';
|
||||
import type { HostAdapter } from './HostAdapter';
|
||||
import type { DiagramDocument } from "../types";
|
||||
import type { HostAdapter } from "./HostAdapter";
|
||||
|
||||
/**
|
||||
* postMessage handshake with the Bitrix bridge script (see
|
||||
@@ -7,9 +7,9 @@ import type { HostAdapter } from './HostAdapter';
|
||||
* concrete origin, never '*' — matches the security requirement from the
|
||||
* original design doc.
|
||||
*/
|
||||
const READY_MESSAGE = 'diagram:ready';
|
||||
const INIT_MESSAGE = 'diagram:init';
|
||||
const CHANGE_MESSAGE = 'diagram:change';
|
||||
const READY_MESSAGE = "diagram:ready";
|
||||
const INIT_MESSAGE = "diagram:init";
|
||||
const CHANGE_MESSAGE = "diagram:change";
|
||||
|
||||
function getBitrixOrigin(): string {
|
||||
const origin = import.meta.env.VITE_BITRIX_ORIGIN;
|
||||
@@ -29,10 +29,11 @@ export function createBitrixAdapter(): HostAdapter {
|
||||
let delivered = false;
|
||||
|
||||
function onMessage(event: MessageEvent) {
|
||||
if (event.origin !== targetOrigin || event.source !== window.parent) return;
|
||||
if (event.origin !== targetOrigin || event.source !== window.parent)
|
||||
return;
|
||||
if (delivered || event.data?.type !== INIT_MESSAGE) return;
|
||||
delivered = true;
|
||||
window.removeEventListener('message', onMessage);
|
||||
window.removeEventListener("message", onMessage);
|
||||
|
||||
const payload = event.data.payload as string | null | undefined;
|
||||
if (!payload) {
|
||||
@@ -46,11 +47,14 @@ export function createBitrixAdapter(): HostAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('message', onMessage);
|
||||
window.addEventListener("message", onMessage);
|
||||
window.parent.postMessage({ type: READY_MESSAGE }, targetOrigin);
|
||||
},
|
||||
onChange(doc) {
|
||||
window.parent.postMessage({ type: CHANGE_MESSAGE, payload: JSON.stringify(doc) }, targetOrigin);
|
||||
window.parent.postMessage(
|
||||
{ type: CHANGE_MESSAGE, payload: JSON.stringify(doc) },
|
||||
targetOrigin,
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user