refactor: Move dom_adapter.ts to @angular/common (#32154)

This work is needed in preparation for turning tokens into tree-shakable injectables.

PR Close #32154
This commit is contained in:
Misko Hevery
2019-08-22 19:16:25 -07:00
parent f7471eea3c
commit 8a47b48912
72 changed files with 96 additions and 114 deletions

View File

@ -6,11 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ɵparseCookieValue as parseCookieValue} from '@angular/common';
import {ɵparseCookieValue as parseCookieValue, ɵsetRootDomAdapter as setRootDomAdapter} from '@angular/common';
import {ɵglobal as global} from '@angular/core';
import {setRootDomAdapter} from '../dom/dom_adapter';
import {GenericBrowserDomAdapter} from './generic_browser_adapter';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DomAdapter} from '../dom/dom_adapter';
import {ɵDomAdapter as DomAdapter} from '@angular/common';

View File

@ -6,15 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT, LocationChangeListener, PlatformLocation} from '@angular/common';
import {DOCUMENT, LocationChangeListener, PlatformLocation, ɵgetDOM as getDOM} from '@angular/common';
import {Inject, Injectable} from '@angular/core';
import {getDOM} from '../../dom/dom_adapter';
import {supportsState} from './history';
/**
* `PlatformLocation` encapsulates all of the direct calls to platform APIs.
* This class should not be used directly by an application developer. Instead, use

View File

@ -6,13 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT} from '@angular/common';
import {DOCUMENT, ɵDomAdapter as DomAdapter, ɵgetDOM as getDOM} from '@angular/common';
import {Inject, Injectable, ɵɵinject} from '@angular/core';
import {DomAdapter, getDOM} from '../dom/dom_adapter';
/**
* Represents a meta element.
*

View File

@ -6,11 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT} from '@angular/common';
import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/common';
import {APP_INITIALIZER, ApplicationInitStatus, Inject, InjectionToken, Injector, StaticProvider} from '@angular/core';
import {getDOM} from '../dom/dom_adapter';
/**
* An id that identifies a particular application being bootstrapped, that should
* match across the client/server boundary.

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ɵgetDOM as getDOM} from '@angular/common';
import {GetTestability, Testability, TestabilityRegistry, setTestabilityGetter, ɵglobal as global} from '@angular/core';
import {getDOM} from '../dom/dom_adapter';
export class BrowserGetTestability implements GetTestability {
static init() { setTestabilityGetter(new BrowserGetTestability()); }

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT} from '@angular/common';
import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/common';
import {Inject, Injectable, ɵɵinject} from '@angular/core';
import {getDOM} from '../dom/dom_adapter';
/**
* Factory to create Title service.

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ɵgetDOM as getDOM} from '@angular/common';
import {ApplicationRef, ComponentRef} from '@angular/core';
import {getDOM} from '../../dom/dom_adapter';
import {window} from './browser';
export class ChangeDetectionPerfRecord {

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ɵgetDOM as getDOM} from '@angular/common';
import {DebugElement, DebugNode, Predicate, Type} from '@angular/core';
import {getDOM} from '../../dom/dom_adapter';

View File

@ -1,110 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
let _DOM: DomAdapter = null !;
export function getDOM() {
return _DOM;
}
export function setDOM(adapter: DomAdapter) {
_DOM = adapter;
}
export function setRootDomAdapter(adapter: DomAdapter) {
if (!_DOM) {
_DOM = adapter;
}
}
/* tslint:disable:requireParameterType */
/**
* Provides DOM operations in an environment-agnostic way.
*
* @security Tread carefully! Interacting with the DOM directly is dangerous and
* can introduce XSS risks.
*/
export abstract class DomAdapter {
// Needs Domino-friendly test utility
abstract getProperty(el: Element, name: string): any;
abstract dispatchEvent(el: any, evt: any): any;
// Used by router
abstract log(error: any): any;
abstract logGroup(error: any): any;
abstract logGroupEnd(): any;
// Used by Meta
abstract querySelectorAll(el: any, selector: string): any[];
abstract remove(el: any): Node;
abstract getAttribute(element: any, attribute: string): string|null;
// Used by platform-server
abstract setProperty(el: Element, name: string, value: any): any;
abstract querySelector(el: any, selector: string): any;
abstract nextSibling(el: any): Node|null;
abstract parentElement(el: any): Node|null;
abstract clearNodes(el: any): any;
abstract appendChild(el: any, node: any): any;
abstract removeChild(el: any, node: any): any;
abstract insertBefore(parent: any, ref: any, node: any): any;
abstract setText(el: any, value: string): any;
abstract createComment(text: string): any;
abstract createElement(tagName: any, doc?: any): HTMLElement;
abstract createElementNS(ns: string, tagName: string, doc?: any): Element;
abstract createTextNode(text: string, doc?: any): Text;
abstract getElementsByTagName(element: any, name: string): HTMLElement[];
abstract addClass(element: any, className: string): any;
abstract removeClass(element: any, className: string): any;
abstract getStyle(element: any, styleName: string): any;
abstract setStyle(element: any, styleName: string, styleValue: string): any;
abstract removeStyle(element: any, styleName: string): any;
abstract setAttribute(element: any, name: string, value: string): any;
abstract setAttributeNS(element: any, ns: string, name: string, value: string): any;
abstract removeAttribute(element: any, attribute: string): any;
abstract removeAttributeNS(element: any, ns: string, attribute: string): any;
abstract createHtmlDocument(): HTMLDocument;
abstract getDefaultDocument(): Document;
// Used by Title
abstract getTitle(doc: Document): string;
abstract setTitle(doc: Document, newTitle: string): any;
// Used by By.css
abstract elementMatches(n: any, selector: string): boolean;
abstract isElementNode(node: any): boolean;
// Used by Testability
abstract isShadowRoot(node: any): boolean;
abstract getHost(el: any): any;
// Used by KeyEventsPlugin
abstract onAndCancel(el: any, evt: any, listener: any): Function;
abstract getEventKey(event: any): string;
abstract supportsDOMEvents(): 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;
abstract resetBaseElement(): void;
// TODO: remove dependency in DefaultValueAccessor
abstract getUserAgent(): string;
// Used by AngularProfiler
abstract performanceNow(): number;
// Used by CookieXSRFStrategy
abstract supportsCookies(): boolean;
abstract getCookie(name: string): string|null;
}

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ɵgetDOM as getDOM} from '@angular/common';
import {Inject, Injectable, InjectionToken, NgZone} from '@angular/core';
import {getDOM} from '../dom_adapter';
/**
* The injection token for the event-manager plug-in service.
*

View File

@ -6,11 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT} from '@angular/common';
import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/common';
import {Inject, Injectable, NgZone} from '@angular/core';
import {getDOM} from '../dom_adapter';
import {EventManagerPlugin} from './event_manager';
/**

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT} from '@angular/common';
import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/common';
import {Inject, Injectable, OnDestroy} from '@angular/core';
import {getDOM} from './dom_adapter';
@Injectable()
export class SharedStylesHost {

View File

@ -13,7 +13,6 @@ export {TRANSITION_ID as ɵTRANSITION_ID} from './browser/server-transition';
export {BrowserGetTestability as ɵBrowserGetTestability} from './browser/testability';
export {escapeHtml as ɵescapeHtml} from './browser/transfer_state';
export {ELEMENT_PROBE_PROVIDERS as ɵELEMENT_PROBE_PROVIDERS} from './dom/debug/ng_probe';
export {DomAdapter as ɵDomAdapter, getDOM as ɵgetDOM, setRootDomAdapter as ɵsetRootDomAdapter} from './dom/dom_adapter';
export {DomRendererFactory2 as ɵDomRendererFactory2, NAMESPACE_URIS as ɵNAMESPACE_URIS, flattenStyles as ɵflattenStyles, shimContentAttribute as ɵshimContentAttribute, shimHostAttribute as ɵshimHostAttribute} from './dom/dom_renderer';
export {DomEventsPlugin as ɵDomEventsPlugin} from './dom/events/dom_events';
export {HammerGesturesPlugin as ɵHammerGesturesPlugin} from './dom/events/hammer_gestures';