Create local style sheets if the editor is in a shadow DOM

This commit is contained in:
Alex Dima
2020-01-19 21:40:52 +01:00
parent a3d4675a6f
commit c201d89e6a
13 changed files with 190 additions and 33 deletions

View File

@@ -820,6 +820,23 @@ export function hasParentWithClass(node: HTMLElement, clazz: string, stopAtClazz
return !!findParentWithClass(node, clazz, stopAtClazzOrNode);
}
export function isShadowRoot(node: Node): node is ShadowRoot {
return (
node && !!(<ShadowRoot>node).host && !!(<ShadowRoot>node).mode
);
}
export function isInShadowDOM(domNode: Node): boolean {
while (domNode.parentNode) {
if (domNode === document.body) {
// reached the body
return false;
}
domNode = domNode.parentNode;
}
return isShadowRoot(domNode);
}
export function createStyleSheet(container: HTMLElement = document.getElementsByTagName('head')[0]): HTMLStyleElement {
let style = document.createElement('style');
style.type = 'text/css';