From 53a59c5b403c0fe5d5c53ea5fb02f2291cf8bfe7 Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:57:53 +0000 Subject: [PATCH] bug: disable iframes within shadowdom during dnd --- packages/dockview-core/src/dom.ts | 32 ++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/dockview-core/src/dom.ts b/packages/dockview-core/src/dom.ts index d61b1cacb..50114138e 100644 --- a/packages/dockview-core/src/dom.ts +++ b/packages/dockview-core/src/dom.ts @@ -112,8 +112,11 @@ export function isAncestor( return false; } -export function getElementsByTagName(tag: string): HTMLElement[] { - return Array.prototype.slice.call(document.getElementsByTagName(tag), 0); +export function getElementsByTagName( + tag: string, + document: ParentNode +): HTMLElement[] { + return Array.prototype.slice.call(document.querySelectorAll(tag), 0); } export interface IFocusTracker extends IDisposable { @@ -288,10 +291,29 @@ export function addTestId(element: HTMLElement, id: string): void { element.setAttribute('data-testid', id); } -export function disableIframePointEvents() { +export function disableIframePointEvents(rootNode: ParentNode = document) { + const includeShadowDom = true; + + const shadowRoots = []; + + if (includeShadowDom) { + const items = rootNode.querySelectorAll('*'); + + for (let i = 0; i < items.length; i++) { + const item = items[i]; + if (item.shadowRoot) { + shadowRoots.push(item.shadowRoot); + } + } + } + const iframes: HTMLElement[] = [ - ...getElementsByTagName('iframe'), - ...getElementsByTagName('webview'), + ...getElementsByTagName('iframe', rootNode), + ...getElementsByTagName('webview', rootNode), + ...shadowRoots.flatMap((root) => [ + ...getElementsByTagName('iframe', root), + ...getElementsByTagName('webview', root), + ]), ]; const original = new WeakMap(); // don't hold onto HTMLElement references longer than required