refactor(core): remove shadow dom utility from DomAdapters (#32278)
PR Close #32278
This commit is contained in:
parent
24127a2492
commit
28c8b03797
|
@ -491,7 +491,7 @@ describe('projection', () => {
|
|||
expect(main.nativeElement).toHaveText('TREE(0:TREE2(1:TREE(2:)))');
|
||||
});
|
||||
|
||||
if (getDOM().supportsNativeShadowDOM()) {
|
||||
if (supportsNativeShadowDOM()) {
|
||||
it('should support native content projection and isolate styles per component', () => {
|
||||
TestBed.configureTestingModule({declarations: [SimpleNative1, SimpleNative2]});
|
||||
TestBed.overrideComponent(MainComp, {
|
||||
|
@ -1032,3 +1032,7 @@ class CmpA1 {
|
|||
})
|
||||
class CmpA2 {
|
||||
}
|
||||
|
||||
function supportsNativeShadowDOM(): boolean {
|
||||
return typeof(<any>document.body).createShadowRoot === 'function';
|
||||
}
|
||||
|
|
|
@ -198,8 +198,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
doc = doc || this.getDefaultDocument();
|
||||
return doc.createTextNode(text);
|
||||
}
|
||||
createShadowRoot(el: HTMLElement): DocumentFragment { return (<any>el).createShadowRoot(); }
|
||||
getShadowRoot(el: HTMLElement): DocumentFragment { return (<any>el).shadowRoot; }
|
||||
getHost(el: HTMLElement): HTMLElement { return (<any>el).host; }
|
||||
clone(node: Node): Node { return node.cloneNode(true); }
|
||||
getElementsByTagName(element: any, name: string): HTMLElement[] {
|
||||
|
@ -261,11 +259,8 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
}
|
||||
isTextNode(node: Node): boolean { return node.nodeType === Node.TEXT_NODE; }
|
||||
isElementNode(node: Node): boolean { return node.nodeType === Node.ELEMENT_NODE; }
|
||||
hasShadowRoot(node: any): boolean {
|
||||
return node.shadowRoot != null && node instanceof HTMLElement;
|
||||
}
|
||||
|
||||
isShadowRoot(node: any): boolean { return node instanceof DocumentFragment; }
|
||||
getHref(el: Element): string { return el.getAttribute('href') !; }
|
||||
|
||||
getEventKey(event: any): string {
|
||||
let key = event.key;
|
||||
|
|
|
@ -21,7 +21,4 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
|
|||
|
||||
getDistributedNodes(el: HTMLElement): Node[] { return (<any>el).getDistributedNodes(); }
|
||||
supportsDOMEvents(): boolean { return true; }
|
||||
supportsNativeShadowDOM(): boolean {
|
||||
return typeof(<any>document.body).createShadowRoot === 'function';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,8 +77,6 @@ export abstract class DomAdapter {
|
|||
abstract createElement(tagName: any, doc?: any): HTMLElement;
|
||||
abstract createElementNS(ns: string, tagName: string, doc?: any): Element;
|
||||
abstract createTextNode(text: string, doc?: any): Text;
|
||||
abstract createShadowRoot(el: any): any;
|
||||
abstract getShadowRoot(el: any): any;
|
||||
abstract getHost(el: any): any;
|
||||
abstract getDistributedNodes(el: any): Node[];
|
||||
abstract clone /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
||||
|
@ -107,13 +105,18 @@ export abstract class DomAdapter {
|
|||
abstract isTemplateElement(el: any): boolean;
|
||||
abstract isTextNode(node: any): boolean;
|
||||
abstract isElementNode(node: any): boolean;
|
||||
abstract hasShadowRoot(node: any): boolean;
|
||||
|
||||
// Used by Testability
|
||||
abstract isShadowRoot(node: any): boolean;
|
||||
abstract getHref(element: any): string;
|
||||
|
||||
// Used by KeyEventsPlugin
|
||||
abstract getEventKey(event: any): string;
|
||||
abstract supportsDOMEvents(): boolean;
|
||||
abstract supportsNativeShadowDOM(): boolean;
|
||||
|
||||
// Used by PlatformLocation and ServerEventManagerPlugin
|
||||
abstract getGlobalEventTarget(doc: Document, target: string): any;
|
||||
|
||||
// Used by PlatformLocation
|
||||
abstract getHistory(): History;
|
||||
abstract getLocation(): Location;
|
||||
abstract getBaseHref(doc: Document): string|null;
|
||||
|
|
|
@ -16,6 +16,8 @@ import {isCommentNode} from '@angular/platform-browser/testing/src/browser_util'
|
|||
|
||||
/**
|
||||
* Jasmine matchers that check Angular specific conditions.
|
||||
*
|
||||
* Note: These matchers will only work in a browser environment.
|
||||
*/
|
||||
export interface NgMatchers<T = any> extends jasmine.Matchers<T> {
|
||||
/**
|
||||
|
@ -294,8 +296,8 @@ function elementText(n: any): string {
|
|||
return elementText(Array.prototype.slice.apply(getDOM().getDistributedNodes(n)));
|
||||
}
|
||||
|
||||
if (getDOM().hasShadowRoot(n)) {
|
||||
return elementText(getDOM().childNodesAsList(getDOM().getShadowRoot(n)));
|
||||
if (hasShadowRoot(n)) {
|
||||
return elementText(getDOM().childNodesAsList((<any>n).shadowRoot));
|
||||
}
|
||||
|
||||
if (hasNodes(n)) {
|
||||
|
@ -304,3 +306,7 @@ function elementText(n: any): string {
|
|||
|
||||
return getDOM().getText(n) !;
|
||||
}
|
||||
|
||||
function hasShadowRoot(node: any): boolean {
|
||||
return node.shadowRoot != null && node instanceof HTMLElement;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ export class DominoAdapter extends BrowserDomAdapter {
|
|||
logGroupEnd() {}
|
||||
|
||||
supportsDOMEvents(): boolean { return false; }
|
||||
supportsNativeShadowDOM(): boolean { return false; }
|
||||
|
||||
contains(nodeA: any, nodeB: any): boolean {
|
||||
let inner = nodeB;
|
||||
|
@ -80,19 +79,11 @@ export class DominoAdapter extends BrowserDomAdapter {
|
|||
return DominoAdapter.defaultDoc;
|
||||
}
|
||||
|
||||
createShadowRoot(el: any, doc: Document = document): DocumentFragment {
|
||||
el.shadowRoot = doc.createDocumentFragment();
|
||||
el.shadowRoot.parent = el;
|
||||
return el.shadowRoot;
|
||||
}
|
||||
getShadowRoot(el: any): DocumentFragment { return el.shadowRoot; }
|
||||
|
||||
isTextNode(node: any): boolean { return node.nodeType === DominoAdapter.defaultDoc.TEXT_NODE; }
|
||||
isElementNode(node: any): boolean {
|
||||
return node ? node.nodeType === DominoAdapter.defaultDoc.ELEMENT_NODE : false;
|
||||
}
|
||||
hasShadowRoot(node: any): boolean { return node.shadowRoot != null; }
|
||||
isShadowRoot(node: any): boolean { return this.getShadowRoot(node) == node; }
|
||||
isShadowRoot(node: any): boolean { return node.shadowRoot == node; }
|
||||
|
||||
getProperty(el: Element, name: string): any {
|
||||
if (name === 'href') {
|
||||
|
@ -135,7 +126,7 @@ export class DominoAdapter extends BrowserDomAdapter {
|
|||
const base = this.querySelector(doc.documentElement !, 'base');
|
||||
let href = '';
|
||||
if (base) {
|
||||
href = this.getHref(base);
|
||||
href = base.getAttribute('href') !;
|
||||
}
|
||||
// TODO(alxhub): Need relative path logic from BrowserDomAdapter here?
|
||||
return href;
|
||||
|
|
|
@ -86,8 +86,6 @@ export class WorkerDomAdapter extends DomAdapter {
|
|||
createElement(tagName: any, doc?: any): HTMLElement { throw 'not implemented'; }
|
||||
createElementNS(ns: string, tagName: string, doc?: any): Element { throw 'not implemented'; }
|
||||
createTextNode(text: string, doc?: any): Text { throw 'not implemented'; }
|
||||
createShadowRoot(el: any): any { throw 'not implemented'; }
|
||||
getShadowRoot(el: any): any { throw 'not implemented'; }
|
||||
getHost(el: any): any { throw 'not implemented'; }
|
||||
getDistributedNodes(el: any): Node[] { throw 'not implemented'; }
|
||||
clone(node: Node): Node { throw 'not implemented'; }
|
||||
|
@ -118,12 +116,9 @@ export class WorkerDomAdapter extends DomAdapter {
|
|||
isTemplateElement(el: any): boolean { throw 'not implemented'; }
|
||||
isTextNode(node: any): boolean { throw 'not implemented'; }
|
||||
isElementNode(node: any): boolean { throw 'not implemented'; }
|
||||
hasShadowRoot(node: any): boolean { throw 'not implemented'; }
|
||||
isShadowRoot(node: any): boolean { throw 'not implemented'; }
|
||||
getHref(element: any): string { throw 'not implemented'; }
|
||||
getEventKey(event: any): string { throw 'not implemented'; }
|
||||
supportsDOMEvents(): boolean { throw 'not implemented'; }
|
||||
supportsNativeShadowDOM(): boolean { throw 'not implemented'; }
|
||||
getGlobalEventTarget(doc: Document, target: string): any { throw 'not implemented'; }
|
||||
getHistory(): History { throw 'not implemented'; }
|
||||
getLocation(): Location { throw 'not implemented'; }
|
||||
|
|
Loading…
Reference in New Issue