This commit is contained in:
Juergen Kunz
2025-06-24 22:45:50 +00:00
parent 68b4e9ec8e
commit e9541da8ff
28 changed files with 4733 additions and 88 deletions

View File

@ -242,4 +242,38 @@ export class WysiwygSelection {
this.setSelectionFromRange(range);
}
}
/**
* Check if a node is contained within an element across Shadow DOM boundaries
* This is needed because element.contains() doesn't work across Shadow DOM
*/
static containsAcrossShadowDOM(container: Node, node: Node): boolean {
if (!container || !node) return false;
// Start with the node and traverse up
let current: Node | null = node;
while (current) {
// Direct match
if (current === container) {
return true;
}
// If we're at a shadow root, check its host
if (current.nodeType === Node.DOCUMENT_FRAGMENT_NODE && (current as any).host) {
const shadowRoot = current as ShadowRoot;
// Check if the container is within this shadow root
if (shadowRoot.contains(container)) {
return false; // Container is in a child shadow DOM
}
// Move to the host element
current = shadowRoot.host;
} else {
// Regular DOM traversal
current = current.parentNode;
}
}
return false;
}
}