2017-12-01 14:23:03 -08:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-23 13:17:20 -08:00
|
|
|
import {ChangeDetectionStrategy} from '../../change_detection/constants';
|
2018-01-27 13:07:03 -08:00
|
|
|
import {PipeTransform} from '../../change_detection/pipe_transform';
|
2018-03-04 20:21:23 -08:00
|
|
|
import {Provider} from '../../core';
|
2018-01-09 18:38:17 -08:00
|
|
|
import {RendererType2} from '../../render/api';
|
|
|
|
|
import {Type} from '../../type';
|
|
|
|
|
import {resolveRendererType2} from '../../view/util';
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
|
2017-12-01 14:23:03 -08:00
|
|
|
/**
|
|
|
|
|
* Definition of what a template rendering function should look like.
|
|
|
|
|
*/
|
|
|
|
|
export type ComponentTemplate<T> = {
|
2018-01-10 18:19:16 -08:00
|
|
|
(ctx: T, creationMode: boolean): void; ngPrivateData?: never;
|
2017-12-01 14:23:03 -08:00
|
|
|
};
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* A subclass of `Type` which has a static `ngComponentDef`:`ComponentDef` field making it
|
|
|
|
|
* consumable for rendering.
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
export interface ComponentType<T> extends Type<T> { ngComponentDef: ComponentDef<T>; }
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* A subclass of `Type` which has a static `ngDirectiveDef`:`DirectiveDef` field making it
|
|
|
|
|
* consumable for rendering.
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
export interface DirectiveType<T> extends Type<T> { ngDirectiveDef: DirectiveDef<T>; }
|
|
|
|
|
|
|
|
|
|
export const enum DirectiveDefFlags {ContentQuery = 0b10}
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* A subclass of `Type` which has a static `ngPipeDef`:`PipeDef` field making it
|
|
|
|
|
* consumable for rendering.
|
|
|
|
|
*/
|
2018-01-27 13:07:03 -08:00
|
|
|
export interface PipeType<T> extends Type<T> { ngPipeDef: PipeDef<T>; }
|
|
|
|
|
|
2017-12-01 14:23:03 -08:00
|
|
|
/**
|
2018-03-04 20:21:23 -08:00
|
|
|
* Runtime link information for Directives.
|
|
|
|
|
*
|
|
|
|
|
* This is internal data structure used by the render to link
|
|
|
|
|
* directives into templates.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: Always use `defineDirective` function to create this object,
|
|
|
|
|
* never create the object directly since the shape of this object
|
|
|
|
|
* can change between versions.
|
|
|
|
|
*
|
|
|
|
|
* See: {@link defineDirective}
|
2017-12-01 14:23:03 -08:00
|
|
|
*/
|
|
|
|
|
export interface DirectiveDef<T> {
|
2018-01-22 15:27:21 -08:00
|
|
|
/** Token representing the directive. Used by DI. */
|
|
|
|
|
type: Type<T>;
|
|
|
|
|
|
2017-12-01 14:23:03 -08:00
|
|
|
/** Function that makes a directive public to the DI system. */
|
|
|
|
|
diPublic: ((def: DirectiveDef<any>) => void)|null;
|
|
|
|
|
|
|
|
|
|
/**
|
2018-02-21 18:12:02 +01:00
|
|
|
* A dictionary mapping the inputs' minified property names to their public API names, which
|
|
|
|
|
* are their aliases if any, or their original unminified property names
|
|
|
|
|
* (as in `@Input('alias') propertyName: any;`).
|
2017-12-01 14:23:03 -08:00
|
|
|
*/
|
2018-01-09 16:43:12 -08:00
|
|
|
readonly inputs: {[P in keyof T]: P};
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-02-21 18:12:02 +01:00
|
|
|
/**
|
|
|
|
|
* A dictionary mapping the outputs' minified property names to their public API names, which
|
|
|
|
|
* are their aliases if any, or their original unminified property names
|
|
|
|
|
* (as in `@Output('alias') propertyName: any;`).
|
2017-12-01 14:23:03 -08:00
|
|
|
*/
|
2018-01-09 16:43:12 -08:00
|
|
|
readonly outputs: {[P in keyof T]: P};
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-01-08 21:57:50 -08:00
|
|
|
/**
|
|
|
|
|
* Name under which the directive is exported (for use with local references in template)
|
|
|
|
|
*/
|
2018-01-09 16:43:12 -08:00
|
|
|
readonly exportAs: string|null;
|
2018-01-08 21:57:50 -08:00
|
|
|
|
2017-12-01 14:23:03 -08:00
|
|
|
/**
|
2018-01-30 15:37:01 -08:00
|
|
|
* Factory function used to create a new directive instance.
|
|
|
|
|
*
|
|
|
|
|
* Usually returns the directive instance, but if the directive has a content query,
|
|
|
|
|
* it instead returns an array that contains the instance as well as content query data.
|
2017-12-01 14:23:03 -08:00
|
|
|
*
|
|
|
|
|
* NOTE: this property is short (1 char) because it is used in
|
|
|
|
|
* component templates which is sensitive to size.
|
|
|
|
|
*/
|
2018-01-30 15:37:01 -08:00
|
|
|
n(): T|[T];
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2017-12-20 16:26:07 -08:00
|
|
|
/**
|
|
|
|
|
* Refreshes host bindings on the associated directive. Also calls lifecycle hooks
|
|
|
|
|
* like ngOnInit and ngDoCheck, if they are defined on the directive.
|
|
|
|
|
*/
|
|
|
|
|
h(directiveIndex: number, elementIndex: number): void;
|
2018-01-22 15:27:21 -08:00
|
|
|
|
2018-02-16 12:09:47 -08:00
|
|
|
/**
|
|
|
|
|
* Static attributes to set on host element.
|
|
|
|
|
*
|
|
|
|
|
* Even indices: attribute name
|
|
|
|
|
* Odd indices: attribute value
|
|
|
|
|
*/
|
|
|
|
|
attributes: string[]|null;
|
|
|
|
|
|
2018-01-23 18:39:09 -08:00
|
|
|
/* The following are lifecycle hooks for this component */
|
|
|
|
|
onInit: (() => void)|null;
|
|
|
|
|
doCheck: (() => void)|null;
|
|
|
|
|
afterContentInit: (() => void)|null;
|
|
|
|
|
afterContentChecked: (() => void)|null;
|
|
|
|
|
afterViewInit: (() => void)|null;
|
|
|
|
|
afterViewChecked: (() => void)|null;
|
|
|
|
|
onDestroy: (() => void)|null;
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* Runtime link information for Components.
|
|
|
|
|
*
|
|
|
|
|
* This is internal data structure used by the render to link
|
|
|
|
|
* components into templates.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: Always use `defineComponent` function to create this object,
|
|
|
|
|
* never create the object directly since the shape of this object
|
|
|
|
|
* can change between versions.
|
|
|
|
|
*
|
|
|
|
|
* See: {@link defineComponent}
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
export interface ComponentDef<T> extends DirectiveDef<T> {
|
|
|
|
|
/**
|
|
|
|
|
* The tag name which should be used by the component.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: only used with component directives.
|
|
|
|
|
*/
|
2018-01-09 16:43:12 -08:00
|
|
|
readonly tag: string;
|
2017-12-01 14:23:03 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The View template of the component.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: only used with component directives.
|
|
|
|
|
*/
|
2018-01-09 16:43:12 -08:00
|
|
|
readonly template: ComponentTemplate<T>;
|
2017-12-11 16:30:46 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renderer type data of the component.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: only used with component directives.
|
|
|
|
|
*/
|
2018-01-09 16:43:12 -08:00
|
|
|
readonly rendererType: RendererType2|null;
|
2018-02-23 13:17:20 -08:00
|
|
|
|
|
|
|
|
/** Whether or not this component's ChangeDetectionStrategy is OnPush */
|
|
|
|
|
readonly onPush: boolean;
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines the set of injectable providers that are visible to a Directive and its content DOM
|
|
|
|
|
* children.
|
|
|
|
|
*/
|
|
|
|
|
readonly providers?: Provider[];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines the set of injectable providers that are visible to a Directive and its view DOM
|
|
|
|
|
* children only.
|
|
|
|
|
*/
|
|
|
|
|
readonly viewProviders?: Provider[];
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|
|
|
|
|
|
2018-01-27 13:07:03 -08:00
|
|
|
/**
|
2018-03-04 20:21:23 -08:00
|
|
|
* Runtime link information for Pipes.
|
|
|
|
|
*
|
|
|
|
|
* This is internal data structure used by the renderer to link
|
|
|
|
|
* pipes into templates.
|
2018-01-27 13:07:03 -08:00
|
|
|
*
|
2018-03-04 20:21:23 -08:00
|
|
|
* NOTE: Always use `definePipe` function to create this object,
|
|
|
|
|
* never create the object directly since the shape of this object
|
|
|
|
|
* can change between versions.
|
|
|
|
|
*
|
|
|
|
|
* See: {@link definePipe}
|
2018-01-27 13:07:03 -08:00
|
|
|
*/
|
|
|
|
|
export interface PipeDef<T> {
|
|
|
|
|
/**
|
|
|
|
|
* factory function used to create a new directive instance.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: this property is short (1 char) because it is used in
|
|
|
|
|
* component templates which is sensitive to size.
|
|
|
|
|
*/
|
2018-02-16 16:23:27 +01:00
|
|
|
n: () => T;
|
2018-01-27 13:07:03 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether or not the pipe is pure.
|
|
|
|
|
*
|
|
|
|
|
* Pure pipes result only depends on the pipe input and not on internal
|
|
|
|
|
* state of the pipe.
|
|
|
|
|
*/
|
|
|
|
|
pure: boolean;
|
|
|
|
|
|
|
|
|
|
/* The following are lifecycle hooks for this pipe */
|
|
|
|
|
onDestroy: (() => void)|null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* Arguments for `defineDirective`
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
export interface DirectiveDefArgs<T> {
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* Directive type, needed to configure the injector.
|
|
|
|
|
*/
|
2018-01-22 15:27:21 -08:00
|
|
|
type: Type<T>;
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method used to create an instance of directive.
|
|
|
|
|
*/
|
2018-02-08 08:59:25 -08:00
|
|
|
factory: () => T | ({0: T} & any[]); /* trying to say T | [T, ...any] */
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Static attributes to set on host element.
|
|
|
|
|
*
|
|
|
|
|
* Even indices: attribute name
|
|
|
|
|
* Odd indices: attribute value
|
|
|
|
|
*/
|
2018-02-16 12:09:47 -08:00
|
|
|
attributes?: string[];
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A map of input names.
|
|
|
|
|
*
|
|
|
|
|
* The format is in: `{[actualPropertyName: string]:string}`.
|
|
|
|
|
*
|
|
|
|
|
* Which the minifier may translate to: `{[minifiedPropertyName: string]:string}`.
|
|
|
|
|
*
|
|
|
|
|
* This allows the render to re-construct the minified and non-minified names
|
|
|
|
|
* of properties.
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
inputs?: {[P in keyof T]?: string};
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A map of output names.
|
|
|
|
|
*
|
|
|
|
|
* The format is in: `{[actualPropertyName: string]:string}`.
|
|
|
|
|
*
|
|
|
|
|
* Which the minifier may translate to: `{[minifiedPropertyName: string]:string}`.
|
|
|
|
|
*
|
|
|
|
|
* This allows the render to re-construct the minified and non-minified names
|
|
|
|
|
* of properties.
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
outputs?: {[P in keyof T]?: string};
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A list of optional features to apply.
|
|
|
|
|
*
|
|
|
|
|
* See: {@link NgOnChangesFeature}, {@link PublicFeature}
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
features?: DirectiveDefFeature[];
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function executed by the parent template to allow child directive to apply host bindings.
|
|
|
|
|
*/
|
2018-01-22 19:52:06 -08:00
|
|
|
hostBindings?: (directiveIndex: number, elementIndex: number) => void;
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines the name that can be used in the template to assign this directive to a variable.
|
|
|
|
|
*
|
|
|
|
|
* See: {@link Directive.exportAs}
|
|
|
|
|
*/
|
2018-01-08 21:57:50 -08:00
|
|
|
exportAs?: string;
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* Arguments for `defineComponent`.
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
export interface ComponentDefArgs<T> extends DirectiveDefArgs<T> {
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
|
|
|
|
* HTML tag name to use in place where this component should be instantiated.
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
tag: string;
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Template function use for rendering DOM.
|
|
|
|
|
*
|
|
|
|
|
* This function has following structure.
|
|
|
|
|
*
|
|
|
|
|
* ```
|
|
|
|
|
* function Template<T>(ctx:T, creationMode: boolean) {
|
|
|
|
|
* if (creationMode) {
|
|
|
|
|
* // Contains creation mode instructions.
|
|
|
|
|
* }
|
|
|
|
|
* // Contains binding update instructions
|
|
|
|
|
* }
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Common instructions are:
|
|
|
|
|
* Creation mode instructions:
|
|
|
|
|
* - `elementStart`, `elementEnd`
|
|
|
|
|
* - `text`
|
|
|
|
|
* - `container`
|
|
|
|
|
* - `listener`
|
|
|
|
|
*
|
|
|
|
|
* Binding update instructions:
|
|
|
|
|
* - `bind`
|
|
|
|
|
* - `elementAttribute`
|
|
|
|
|
* - `elementProperty`
|
|
|
|
|
* - `elementClass`
|
|
|
|
|
* - `elementStyle`
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
template: ComponentTemplate<T>;
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A list of optional features to apply.
|
|
|
|
|
*
|
|
|
|
|
* See: {@link NgOnChancesFeature}, {@link PublicFeature}
|
|
|
|
|
*/
|
2017-12-01 14:23:03 -08:00
|
|
|
features?: ComponentDefFeature[];
|
2018-03-04 20:21:23 -08:00
|
|
|
|
2017-12-11 16:30:46 +01:00
|
|
|
rendererType?: RendererType2;
|
2018-03-04 20:21:23 -08:00
|
|
|
|
2018-02-23 13:17:20 -08:00
|
|
|
changeDetection?: ChangeDetectionStrategy;
|
2018-03-04 20:21:23 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines the set of injectable objects that are visible to a Directive and its light DOM
|
|
|
|
|
* children.
|
|
|
|
|
*/
|
|
|
|
|
providers?: Provider[];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines the set of injectable objects that are visible to its view DOM children.
|
|
|
|
|
*/
|
|
|
|
|
viewProviders?: Provider[];
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
|
2018-03-04 20:21:23 -08:00
|
|
|
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
|
2018-01-09 18:38:17 -08:00
|
|
|
|
|
|
|
|
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
|
|
|
|
// failure based on types.
|
|
|
|
|
export const unusedValueExportToPlacateAjd = 1;
|