@ -25,7 +25,9 @@ export class By {
|
||||
*
|
||||
* {@example platform-browser/dom/debug/ts/by/by.ts region='by_all'}
|
||||
*/
|
||||
static all(): Predicate<DebugNode> { return () => true; }
|
||||
static all(): Predicate<DebugNode> {
|
||||
return () => true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match elements by the given CSS selector.
|
||||
@ -52,7 +54,7 @@ export class By {
|
||||
* {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'}
|
||||
*/
|
||||
static directive(type: Type<any>): Predicate<DebugNode> {
|
||||
return (debugNode) => debugNode.providerTokens !.indexOf(type) !== -1;
|
||||
return (debugNode) => debugNode.providerTokens!.indexOf(type) !== -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,11 +137,17 @@ class DefaultDomRenderer2 implements Renderer2 {
|
||||
return document.createElement(name);
|
||||
}
|
||||
|
||||
createComment(value: string): any { return document.createComment(value); }
|
||||
createComment(value: string): any {
|
||||
return document.createComment(value);
|
||||
}
|
||||
|
||||
createText(value: string): any { return document.createTextNode(value); }
|
||||
createText(value: string): any {
|
||||
return document.createTextNode(value);
|
||||
}
|
||||
|
||||
appendChild(parent: any, newChild: any): void { parent.appendChild(newChild); }
|
||||
appendChild(parent: any, newChild: any): void {
|
||||
parent.appendChild(newChild);
|
||||
}
|
||||
|
||||
insertBefore(parent: any, newChild: any, refChild: any): void {
|
||||
if (parent) {
|
||||
@ -167,9 +173,13 @@ class DefaultDomRenderer2 implements Renderer2 {
|
||||
return el;
|
||||
}
|
||||
|
||||
parentNode(node: any): any { return node.parentNode; }
|
||||
parentNode(node: any): any {
|
||||
return node.parentNode;
|
||||
}
|
||||
|
||||
nextSibling(node: any): any { return node.nextSibling; }
|
||||
nextSibling(node: any): any {
|
||||
return node.nextSibling;
|
||||
}
|
||||
|
||||
setAttribute(el: any, name: string, value: string, namespace?: string): void {
|
||||
if (namespace) {
|
||||
@ -205,9 +215,13 @@ class DefaultDomRenderer2 implements Renderer2 {
|
||||
}
|
||||
}
|
||||
|
||||
addClass(el: any, name: string): void { el.classList.add(name); }
|
||||
addClass(el: any, name: string): void {
|
||||
el.classList.add(name);
|
||||
}
|
||||
|
||||
removeClass(el: any, name: string): void { el.classList.remove(name); }
|
||||
removeClass(el: any, name: string): void {
|
||||
el.classList.remove(name);
|
||||
}
|
||||
|
||||
setStyle(el: any, style: string, value: any, flags: RendererStyleFlags2): void {
|
||||
if (flags & RendererStyleFlags2.DashCase) {
|
||||
@ -233,7 +247,9 @@ class DefaultDomRenderer2 implements Renderer2 {
|
||||
el[name] = value;
|
||||
}
|
||||
|
||||
setValue(node: any, value: string): void { node.nodeValue = value; }
|
||||
setValue(node: any, value: string): void {
|
||||
node.nodeValue = value;
|
||||
}
|
||||
|
||||
listen(target: 'window'|'document'|'body'|any, event: string, callback: (event: any) => boolean):
|
||||
() => void {
|
||||
@ -243,15 +259,15 @@ class DefaultDomRenderer2 implements Renderer2 {
|
||||
target, event, decoratePreventDefault(callback));
|
||||
}
|
||||
return <() => void>this.eventManager.addEventListener(
|
||||
target, event, decoratePreventDefault(callback)) as() => void;
|
||||
target, event, decoratePreventDefault(callback)) as () => void;
|
||||
}
|
||||
}
|
||||
|
||||
const AT_CHARCODE = (() => '@'.charCodeAt(0))();
|
||||
function checkNoSyntheticProp(name: string, nameKind: string) {
|
||||
if (name.charCodeAt(0) === AT_CHARCODE) {
|
||||
throw new Error(
|
||||
`Found the synthetic ${nameKind} ${name}. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.`);
|
||||
throw new Error(`Found the synthetic ${nameKind} ${
|
||||
name}. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +286,9 @@ class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 {
|
||||
this.hostAttr = shimHostAttribute(appId + '-' + component.id);
|
||||
}
|
||||
|
||||
applyToHost(element: any) { super.setAttribute(element, this.hostAttr, ''); }
|
||||
applyToHost(element: any) {
|
||||
super.setAttribute(element, this.hostAttr, '');
|
||||
}
|
||||
|
||||
createElement(parent: any, name: string): Element {
|
||||
const el = super.createElement(parent, name);
|
||||
@ -300,9 +318,13 @@ class ShadowDomRenderer extends DefaultDomRenderer2 {
|
||||
}
|
||||
}
|
||||
|
||||
private nodeOrShadowRoot(node: any): any { return node === this.hostEl ? this.shadowRoot : node; }
|
||||
private nodeOrShadowRoot(node: any): any {
|
||||
return node === this.hostEl ? this.shadowRoot : node;
|
||||
}
|
||||
|
||||
destroy() { this.sharedStylesHost.removeHost(this.shadowRoot); }
|
||||
destroy() {
|
||||
this.sharedStylesHost.removeHost(this.shadowRoot);
|
||||
}
|
||||
|
||||
appendChild(parent: any, newChild: any): void {
|
||||
return super.appendChild(this.nodeOrShadowRoot(parent), newChild);
|
||||
|
@ -13,11 +13,15 @@ import {EventManagerPlugin} from './event_manager';
|
||||
|
||||
@Injectable()
|
||||
export class DomEventsPlugin extends EventManagerPlugin {
|
||||
constructor(@Inject(DOCUMENT) doc: any) { super(doc); }
|
||||
constructor(@Inject(DOCUMENT) doc: any) {
|
||||
super(doc);
|
||||
}
|
||||
|
||||
// This plugin should come last in the list of plugins, because it accepts all
|
||||
// events.
|
||||
supports(eventName: string): boolean { return true; }
|
||||
supports(eventName: string): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
|
||||
element.addEventListener(eventName, handler as EventListener, false);
|
||||
|
@ -67,7 +67,9 @@ export class EventManager {
|
||||
/**
|
||||
* Retrieves the compilation zone in which event listeners are registered.
|
||||
*/
|
||||
getZone(): NgZone { return this._zone; }
|
||||
getZone(): NgZone {
|
||||
return this._zone;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_findPluginFor(eventName: string): EventManagerPlugin {
|
||||
@ -92,7 +94,7 @@ export abstract class EventManagerPlugin {
|
||||
constructor(private _doc: any) {}
|
||||
|
||||
// TODO(issue/24571): remove '!'.
|
||||
manager !: EventManager;
|
||||
manager!: EventManager;
|
||||
|
||||
abstract supports(eventName: string): boolean;
|
||||
|
||||
|
@ -99,21 +99,21 @@ export class HammerGestureConfig {
|
||||
events: string[] = [];
|
||||
|
||||
/**
|
||||
* Maps gesture event names to a set of configuration options
|
||||
* that specify overrides to the default values for specific properties.
|
||||
*
|
||||
* The key is a supported event name to be configured,
|
||||
* and the options object contains a set of properties, with override values
|
||||
* to be applied to the named recognizer event.
|
||||
* For example, to disable recognition of the rotate event, specify
|
||||
* `{"rotate": {"enable": false}}`.
|
||||
*
|
||||
* Properties that are not present take the HammerJS default values.
|
||||
* For information about which properties are supported for which events,
|
||||
* and their allowed and default values, see
|
||||
* [HammerJS documentation](http://hammerjs.github.io/).
|
||||
*
|
||||
*/
|
||||
* Maps gesture event names to a set of configuration options
|
||||
* that specify overrides to the default values for specific properties.
|
||||
*
|
||||
* The key is a supported event name to be configured,
|
||||
* and the options object contains a set of properties, with override values
|
||||
* to be applied to the named recognizer event.
|
||||
* For example, to disable recognition of the rotate event, specify
|
||||
* `{"rotate": {"enable": false}}`.
|
||||
*
|
||||
* Properties that are not present take the HammerJS default values.
|
||||
* For information about which properties are supported for which events,
|
||||
* and their allowed and default values, see
|
||||
* [HammerJS documentation](http://hammerjs.github.io/).
|
||||
*
|
||||
*/
|
||||
overrides: {[key: string]: Object} = {};
|
||||
|
||||
/**
|
||||
@ -124,7 +124,9 @@ export class HammerGestureConfig {
|
||||
* [HammerJS documentation](http://hammerjs.github.io/).
|
||||
*/
|
||||
options?: {
|
||||
cssProps?: any; domEvents?: boolean; enable?: boolean | ((manager: any) => boolean);
|
||||
cssProps?: any;
|
||||
domEvents?: boolean;
|
||||
enable?: boolean | ((manager: any) => boolean);
|
||||
preset?: any[];
|
||||
touchAction?: string;
|
||||
recognizers?: any[];
|
||||
@ -139,7 +141,7 @@ export class HammerGestureConfig {
|
||||
* @returns A HammerJS event-manager object.
|
||||
*/
|
||||
buildHammer(element: HTMLElement): HammerInstance {
|
||||
const mc = new Hammer !(element, this.options);
|
||||
const mc = new Hammer!(element, this.options);
|
||||
|
||||
mc.get('pinch').set({enable: true});
|
||||
mc.get('rotate').set({enable: true});
|
||||
@ -192,7 +194,9 @@ export class HammerGesturesPlugin extends EventManagerPlugin {
|
||||
// Until Hammer is loaded, the returned function needs to *cancel* the registration rather
|
||||
// than remove anything.
|
||||
let cancelRegistration = false;
|
||||
let deregister: Function = () => { cancelRegistration = true; };
|
||||
let deregister: Function = () => {
|
||||
cancelRegistration = true;
|
||||
};
|
||||
|
||||
this.loader()
|
||||
.then(() => {
|
||||
@ -220,14 +224,18 @@ export class HammerGesturesPlugin extends EventManagerPlugin {
|
||||
// Return a function that *executes* `deregister` (and not `deregister` itself) so that we
|
||||
// can change the behavior of `deregister` once the listener is added. Using a closure in
|
||||
// this way allows us to avoid any additional data structures to track listener removal.
|
||||
return () => { deregister(); };
|
||||
return () => {
|
||||
deregister();
|
||||
};
|
||||
}
|
||||
|
||||
return zone.runOutsideAngular(() => {
|
||||
// Creating the manager bind events, must be done outside of angular
|
||||
const mc = this._config.buildHammer(element);
|
||||
const callback = function(eventObj: HammerInput) {
|
||||
zone.runGuarded(function() { handler(eventObj); });
|
||||
zone.runGuarded(function() {
|
||||
handler(eventObj);
|
||||
});
|
||||
};
|
||||
mc.on(eventName, callback);
|
||||
return () => {
|
||||
@ -240,7 +248,9 @@ export class HammerGesturesPlugin extends EventManagerPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
isCustomEvent(eventName: string): boolean { return this._config.events.indexOf(eventName) > -1; }
|
||||
isCustomEvent(eventName: string): boolean {
|
||||
return this._config.events.indexOf(eventName) > -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,14 +79,18 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
* Initializes an instance of the browser plug-in.
|
||||
* @param doc The document in which key events will be detected.
|
||||
*/
|
||||
constructor(@Inject(DOCUMENT) doc: any) { super(doc); }
|
||||
constructor(@Inject(DOCUMENT) doc: any) {
|
||||
super(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports whether a named key event is supported.
|
||||
* @param eventName The event name to query.
|
||||
* @return True if the named key event is supported.
|
||||
* Reports whether a named key event is supported.
|
||||
* @param eventName The event name to query.
|
||||
* @return True if the named key event is supported.
|
||||
*/
|
||||
supports(eventName: string): boolean { return KeyEventsPlugin.parseEventName(eventName) != null; }
|
||||
supports(eventName: string): boolean {
|
||||
return KeyEventsPlugin.parseEventName(eventName) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a handler for a specific element and key event.
|
||||
@ -95,9 +99,9 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
* @param handler A function to call when the notification occurs. Receives the
|
||||
* event object as an argument.
|
||||
* @returns The key event that was registered.
|
||||
*/
|
||||
*/
|
||||
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
|
||||
const parsedEvent = KeyEventsPlugin.parseEventName(eventName) !;
|
||||
const parsedEvent = KeyEventsPlugin.parseEventName(eventName)!;
|
||||
|
||||
const outsideHandler =
|
||||
KeyEventsPlugin.eventCallback(parsedEvent['fullKey'], handler, this.manager.getZone());
|
||||
@ -115,7 +119,7 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
const key = KeyEventsPlugin._normalizeKey(parts.pop() !);
|
||||
const key = KeyEventsPlugin._normalizeKey(parts.pop()!);
|
||||
|
||||
let fullKey = '';
|
||||
MODIFIER_KEYS.forEach(modifierName => {
|
||||
|
@ -27,7 +27,9 @@ export class SharedStylesHost {
|
||||
|
||||
onStylesAdded(additions: Set<string>): void {}
|
||||
|
||||
getAllStyles(): string[] { return Array.from(this._stylesSet); }
|
||||
getAllStyles(): string[] {
|
||||
return Array.from(this._stylesSet);
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@ -52,11 +54,15 @@ export class DomSharedStylesHost extends SharedStylesHost implements OnDestroy {
|
||||
this._hostNodes.add(hostNode);
|
||||
}
|
||||
|
||||
removeHost(hostNode: Node): void { this._hostNodes.delete(hostNode); }
|
||||
removeHost(hostNode: Node): void {
|
||||
this._hostNodes.delete(hostNode);
|
||||
}
|
||||
|
||||
onStylesAdded(additions: Set<string>): void {
|
||||
this._hostNodes.forEach(hostNode => this._addStylesToHost(additions, hostNode));
|
||||
}
|
||||
|
||||
ngOnDestroy(): void { this._styleNodes.forEach(styleNode => getDOM().remove(styleNode)); }
|
||||
ngOnDestroy(): void {
|
||||
this._styleNodes.forEach(styleNode => getDOM().remove(styleNode));
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ export function exportNgVar(name: string, value: any): void {
|
||||
// - closure declares globals itself for minified names, which sometimes clobber our `ng` global
|
||||
// - we can't declare a closure extern as the namespace `ng` is already used within Google
|
||||
// for typings for angularJS (via `goog.provide('ng....')`).
|
||||
const ng = global['ng'] = (global['ng'] as{[key: string]: any} | undefined) || {};
|
||||
const ng = global['ng'] = (global['ng'] as {[key: string]: any} | undefined) || {};
|
||||
ng[name] = value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user