Update selectSvgElement.ts

This commit is contained in:
Reda Al Sulais
2023-08-05 20:45:23 +03:00
committed by GitHub
parent ef29388d68
commit 1802f5d0c0

View File

@@ -11,14 +11,12 @@ import type { HTML, SVG } from '../diagram-api/types.js';
export const selectSvgElement = (id: string): SVG => {
const { securityLevel } = getConfig();
// handle root and document for when rendering in sandbox mode
let doc: Document = document;
let root: HTML = select('body');
if (securityLevel === 'sandbox') {
const sandboxElement: HTML = select(`#i${id}`);
doc = sandboxElement.node()?.contentDocument ?? doc;
const doc: Document = sandboxElement.node()?.contentDocument ?? document;
root = select(doc.body as HTMLIFrameElement);
}
const root: HTML =
securityLevel === 'sandbox' ? select(doc.body as HTMLIFrameElement) : select('body');
const svg: SVG = root.select(`#${id}`);
return svg;
};