From a4b9255f43175718124de9cb797b3490dc702776 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 ++++++++++--- .../react/dockview/demo-dockview/src/app.tsx | 45 ++++++++++++++++++- .../demo-dockview/src/gridActions.tsx | 23 +++++++++- .../demo-dockview/src/panelActions.tsx | 4 +- 4 files changed, 94 insertions(+), 10 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 diff --git a/packages/docs/sandboxes/react/dockview/demo-dockview/src/app.tsx b/packages/docs/sandboxes/react/dockview/demo-dockview/src/app.tsx index 6595a3fce..7f1d8d8b4 100644 --- a/packages/docs/sandboxes/react/dockview/demo-dockview/src/app.tsx +++ b/packages/docs/sandboxes/react/dockview/demo-dockview/src/app.tsx @@ -7,6 +7,7 @@ import { DockviewApi, } from 'dockview'; import * as React from 'react'; +import * as ReactDOM from 'react-dom/client'; import './app.scss'; import { defaultConfig } from './defaultLayout'; import { GridActions } from './gridActions'; @@ -30,6 +31,20 @@ const Option = (props: { ); }; +const ShadowIframe = (props: IDockviewPanelProps) => { + return ( +