Skip to content

Commit

Permalink
bug: disable iframes within shadowdom during dnd
Browse files Browse the repository at this point in the history
  • Loading branch information
mathuo committed Dec 10, 2024
1 parent 4291774 commit 53a59c5
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions packages/dockview-core/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<HTMLElement, string>(); // don't hold onto HTMLElement references longer than required
Expand Down

0 comments on commit 53a59c5

Please sign in to comment.