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-08-08 13:22:52 -07:00
|
|
|
import {Provider, ViewEncapsulation} from '../../core';
|
2018-01-09 18:38:17 -08:00
|
|
|
import {Type} from '../../type';
|
2018-03-29 16:41:45 -07:00
|
|
|
import {CssSelectorList} from './projection';
|
2018-03-04 20:21:23 -08:00
|
|
|
|
2018-07-18 01:59:49 +00:00
|
|
|
|
2017-12-01 14:23:03 -08:00
|
|
|
/**
|
2018-07-18 01:59:49 +00:00
|
|
|
* Definition of what a template rendering function should look like for a component.
|
2017-12-01 14:23:03 -08:00
|
|
|
*/
|
|
|
|
|
export type ComponentTemplate<T> = {
|
2018-07-18 01:59:49 +00:00
|
|
|
(rf: RenderFlags, ctx: T): void; ngPrivateData?: never;
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-19 17:58:42 +02:00
|
|
|
/**
|
|
|
|
|
* Definition of what a query function should look like.
|
|
|
|
|
*/
|
|
|
|
|
export type ComponentQuery<T> = ComponentTemplate<T>;
|
|
|
|
|
|
2018-04-10 20:57:09 -07:00
|
|
|
/**
|
|
|
|
|
* Flags passed into template functions to determine which blocks (i.e. creation, update)
|
|
|
|
|
* should be executed.
|
|
|
|
|
*
|
|
|
|
|
* Typically, a template runs both the creation block and the update block on initialization and
|
|
|
|
|
* subsequent runs only execute the update block. However, dynamically created views require that
|
|
|
|
|
* the creation block be executed separately from the update block (for backwards compat).
|
|
|
|
|
*/
|
|
|
|
|
export const enum RenderFlags {
|
|
|
|
|
/* Whether to run the creation block (e.g. create elements and directives) */
|
|
|
|
|
Create = 0b01,
|
|
|
|
|
|
|
|
|
|
/* Whether to run the update block (e.g. refresh bindings) */
|
|
|
|
|
Update = 0b10
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
2018-04-13 23:02:29 -07:00
|
|
|
* A subclass of `Type` which has a static `ngComponentDef`:`ComponentDef` field making it
|
2018-03-04 20:21:23 -08:00
|
|
|
* consumable for rendering.
|
|
|
|
|
*/
|
2018-04-14 09:18:38 -07:00
|
|
|
export interface ComponentType<T> extends Type<T> { ngComponentDef: never; }
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
2018-04-13 23:02:29 -07:00
|
|
|
* A subclass of `Type` which has a static `ngDirectiveDef`:`DirectiveDef` field making it
|
2018-03-04 20:21:23 -08:00
|
|
|
* consumable for rendering.
|
|
|
|
|
*/
|
2018-04-14 09:18:38 -07:00
|
|
|
export interface DirectiveType<T> extends Type<T> { ngDirectiveDef: never; }
|
2017-12-01 14:23:03 -08:00
|
|
|
|
|
|
|
|
export const enum DirectiveDefFlags {ContentQuery = 0b10}
|
|
|
|
|
|
2018-03-04 20:21:23 -08:00
|
|
|
/**
|
2018-04-13 23:02:29 -07:00
|
|
|
* A subclass of `Type` which has a static `ngPipeDef`:`PipeDef` field making it
|
2018-03-04 20:21:23 -08:00
|
|
|
* consumable for rendering.
|
|
|
|
|
*/
|
2018-04-14 09:18:38 -07:00
|
|
|
export interface PipeType<T> extends Type<T> { ngPipeDef: never; }
|
2018-01-27 13:07:03 -08:00
|
|
|
|
2018-05-31 15:50:02 -07:00
|
|
|
/**
|
|
|
|
|
* A version of {@link DirectiveDef} that represents the runtime type shape only, and excludes
|
|
|
|
|
* metadata parameters.
|
|
|
|
|
*/
|
|
|
|
|
export type DirectiveDefInternal<T> = DirectiveDef<T, string>;
|
|
|
|
|
|
2017-12-01 14:23:03 -08:00
|
|
|
/**
|
2018-07-23 17:01:22 -07:00
|
|
|
* Runtime information for classes that are inherited by components or directives
|
|
|
|
|
* that aren't defined as components or directives.
|
2018-03-04 20:21:23 -08:00
|
|
|
*
|
2018-07-23 17:01:22 -07:00
|
|
|
* This is an internal data structure used by the render to determine what inputs
|
|
|
|
|
* and outputs should be inherited.
|
2018-03-04 20:21:23 -08:00
|
|
|
*
|
2018-07-23 17:01:22 -07:00
|
|
|
* See: {@link defineBase}
|
2017-12-01 14:23:03 -08:00
|
|
|
*/
|
2018-07-23 17:01:22 -07:00
|
|
|
export interface BaseDef<T> {
|
2017-12-01 14:23:03 -08:00
|
|
|
/**
|
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-06-25 11:11:22 +02:00
|
|
|
readonly inputs: {[P in keyof T]: string};
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-06-18 08:05:06 -07:00
|
|
|
/**
|
|
|
|
|
* @deprecated This is only here because `NgOnChanges` incorrectly uses declared name instead of
|
|
|
|
|
* public or minified name.
|
|
|
|
|
*/
|
|
|
|
|
readonly declaredInputs: {[P in keyof T]: P};
|
|
|
|
|
|
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};
|
2018-07-23 17:01:22 -07: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.
|
|
|
|
|
*
|
|
|
|
|
* @param Selector type metadata specifying the selector of the directive or component
|
|
|
|
|
*
|
|
|
|
|
* See: {@link defineDirective}
|
|
|
|
|
*/
|
|
|
|
|
export interface DirectiveDef<T, Selector extends string> extends BaseDef<T> {
|
|
|
|
|
/** Token representing the directive. Used by DI. */
|
|
|
|
|
type: Type<T>;
|
|
|
|
|
|
|
|
|
|
/** Function that makes a directive public to the DI system. */
|
|
|
|
|
diPublic: ((def: DirectiveDef<T, string>) => void)|null;
|
|
|
|
|
|
|
|
|
|
/** The selectors that will be used to match nodes to this directive. */
|
|
|
|
|
selectors: CssSelectorList;
|
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
|
|
|
*/
|
2018-03-16 16:42:13 -07:00
|
|
|
factory(): T|[T];
|
2017-12-01 14:23:03 -08:00
|
|
|
|
2018-07-10 10:43:07 +02:00
|
|
|
/**
|
|
|
|
|
* Function to create instances of content queries associated with a given directive.
|
|
|
|
|
*/
|
|
|
|
|
contentQueries: (() => void)|null;
|
|
|
|
|
|
|
|
|
|
/** Refreshes content queries associated with directives in a given view */
|
|
|
|
|
contentQueriesRefresh: ((directiveIndex: number, queryIndex: number) => void)|null;
|
|
|
|
|
|
2018-08-20 13:03:03 -07:00
|
|
|
/**
|
|
|
|
|
* The number of host bindings (including pure fn bindings) in this directive/component.
|
|
|
|
|
*
|
|
|
|
|
* Used to calculate the length of the LViewData array for the *parent* component
|
|
|
|
|
* of this directive/component.
|
|
|
|
|
*/
|
|
|
|
|
hostVars: number;
|
|
|
|
|
|
2018-03-16 16:42:13 -07:00
|
|
|
/** Refreshes host bindings on the associated directive. */
|
|
|
|
|
hostBindings: ((directiveIndex: number, elementIndex: number) => void)|null;
|
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;
|
2018-06-18 08:05:06 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The features applied to this directive
|
|
|
|
|
*/
|
|
|
|
|
features: DirectiveDefFeature[]|null;
|
2017-12-01 14:23:03 -08:00
|
|
|
}
|
|
|
|
|
|
2018-05-31 15:50:02 -07:00
|
|
|
/**
|
|
|
|
|
* A version of {@link ComponentDef} that represents the runtime type shape only, and excludes
|
|
|
|
|
* metadata parameters.
|
|
|
|
|
*/
|
|
|
|
|
export type ComponentDefInternal<T> = ComponentDef<T, string>;
|
|
|
|
|
|
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}
|
|
|
|
|
*/
|
2018-05-31 15:50:02 -07:00
|
|
|
export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T, Selector> {
|
2018-08-08 13:22:52 -07:00
|
|
|
/**
|
|
|
|
|
* Runtime unique component ID.
|
|
|
|
|
*/
|
|
|
|
|
id: string;
|
|
|
|
|
|
2017-12-01 14:23:03 -08:00
|
|
|
/**
|
|
|
|
|
* The View template of the component.
|
|
|
|
|
*/
|
2018-01-09 16:43:12 -08:00
|
|
|
readonly template: ComponentTemplate<T>;
|
2017-12-11 16:30:46 +01:00
|
|
|
|
2018-08-08 13:22:52 -07:00
|
|
|
/**
|
|
|
|
|
* A set of styles that the component needs to be present for component to render correctly.
|
|
|
|
|
*/
|
|
|
|
|
readonly styles: string[];
|
|
|
|
|
|
2018-08-16 18:53:21 -07:00
|
|
|
/**
|
|
|
|
|
* The number of nodes, local refs, and pipes in this component template.
|
|
|
|
|
*
|
|
|
|
|
* Used to calculate the length of the component's LViewData array, so we
|
|
|
|
|
* can pre-fill the array and set the binding start index.
|
|
|
|
|
*/
|
|
|
|
|
// TODO(kara): remove queries from this count
|
|
|
|
|
consts: number;
|
|
|
|
|
|
2018-08-18 11:14:50 -07:00
|
|
|
/**
|
|
|
|
|
* The number of bindings in this component template (including pure fn bindings).
|
|
|
|
|
*
|
|
|
|
|
* Used to calculate the length of the component's LViewData array, so we
|
|
|
|
|
* can pre-fill the array and set the host binding start index.
|
|
|
|
|
*/
|
|
|
|
|
vars: number;
|
|
|
|
|
|
2018-06-19 17:58:42 +02:00
|
|
|
/**
|
|
|
|
|
* Query-related instructions for a component.
|
|
|
|
|
*/
|
2018-08-17 12:49:02 -07:00
|
|
|
viewQuery: ComponentQuery<T>|null;
|
2018-06-19 17:58:42 +02:00
|
|
|
|
2017-12-11 16:30:46 +01:00
|
|
|
/**
|
2018-08-08 13:22:52 -07:00
|
|
|
* The view encapsulation type, which determines how styles are applied to
|
|
|
|
|
* DOM elements. One of
|
|
|
|
|
* - `Emulated` (default): Emulate native scoping of styles.
|
|
|
|
|
* - `Native`: Use the native encapsulation mechanism of the renderer.
|
|
|
|
|
* - `ShadowDom`: Use modern [ShadowDOM](https://w3c.github.io/webcomponents/spec/shadow/) and
|
|
|
|
|
* create a ShadowRoot for component's host element.
|
|
|
|
|
* - `None`: Do not provide any template or style encapsulation.
|
|
|
|
|
*/
|
|
|
|
|
readonly encapsulation: ViewEncapsulation;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines arbitrary developer-defined data to be stored on a renderer instance.
|
|
|
|
|
* This is useful for renderers that delegate to other renderers.
|
2017-12-11 16:30:46 +01:00
|
|
|
*/
|
2018-08-08 13:22:52 -07:00
|
|
|
readonly data: {[kind: string]: any};
|
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[];
|
2018-03-25 21:32:39 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Registry of directives and components that may be found in this view.
|
|
|
|
|
*
|
2018-04-13 23:02:29 -07:00
|
|
|
* The property is either an array of `DirectiveDef`s or a function which returns the array of
|
|
|
|
|
* `DirectiveDef`s. The function is necessary to be able to support forward declarations.
|
2018-03-25 21:32:39 -07:00
|
|
|
*/
|
|
|
|
|
directiveDefs: DirectiveDefListOrFactory|null;
|
2018-03-27 15:53:48 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Registry of pipes that may be found in this view.
|
|
|
|
|
*
|
|
|
|
|
* The property is either an array of `PipeDefs`s or a function which returns the array of
|
|
|
|
|
* `PipeDefs`s. The function is necessary to be able to support forward declarations.
|
|
|
|
|
*/
|
|
|
|
|
pipeDefs: PipeDefListOrFactory|null;
|
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
|
|
|
*/
|
2018-06-26 10:43:06 -07:00
|
|
|
export interface PipeDef<T, S extends string> {
|
2018-03-27 15:53:48 -07:00
|
|
|
/**
|
|
|
|
|
* Pipe name.
|
|
|
|
|
*
|
|
|
|
|
* Used to resolve pipe in templates.
|
|
|
|
|
*/
|
2018-06-26 10:43:06 -07:00
|
|
|
name: S;
|
2018-03-27 15:53:48 -07:00
|
|
|
|
2018-01-27 13:07:03 -08:00
|
|
|
/**
|
2018-05-13 18:29:45 +02:00
|
|
|
* Factory function used to create a new pipe instance.
|
2018-01-27 13:07:03 -08:00
|
|
|
*/
|
2018-05-13 18:29:45 +02:00
|
|
|
factory: () => 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-06-26 10:43:06 -07:00
|
|
|
export type PipeDefInternal<T> = PipeDef<T, string>;
|
|
|
|
|
|
2018-05-31 15:50:02 -07:00
|
|
|
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T, string>) => void;
|
|
|
|
|
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T, string>) => void;
|
2018-01-09 18:38:17 -08:00
|
|
|
|
2018-03-25 21:32:39 -07:00
|
|
|
/**
|
|
|
|
|
* Type used for directiveDefs on component definition.
|
|
|
|
|
*
|
|
|
|
|
* The function is necessary to be able to support forward declarations.
|
|
|
|
|
*/
|
|
|
|
|
export type DirectiveDefListOrFactory = (() => DirectiveDefList) | DirectiveDefList;
|
|
|
|
|
|
2018-05-31 15:50:02 -07:00
|
|
|
export type DirectiveDefList = (DirectiveDef<any, string>| ComponentDef<any, string>)[];
|
2018-03-25 21:32:39 -07:00
|
|
|
|
2018-03-29 12:58:41 -07:00
|
|
|
export type DirectiveTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
|
|
|
|
|
|
|
|
|
|
export type DirectiveTypeList =
|
2018-05-31 15:50:02 -07:00
|
|
|
(DirectiveDef<any, string>| ComponentDef<any, string>|
|
2018-03-29 12:58:41 -07:00
|
|
|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
|
|
|
|
|
|
2018-03-27 15:53:48 -07:00
|
|
|
/**
|
|
|
|
|
* Type used for PipeDefs on component definition.
|
|
|
|
|
*
|
|
|
|
|
* The function is necessary to be able to support forward declarations.
|
|
|
|
|
*/
|
|
|
|
|
export type PipeDefListOrFactory = (() => PipeDefList) | PipeDefList;
|
|
|
|
|
|
2018-06-26 10:43:06 -07:00
|
|
|
export type PipeDefList = PipeDefInternal<any>[];
|
2018-03-27 15:53:48 -07:00
|
|
|
|
2018-03-29 12:58:41 -07:00
|
|
|
export type PipeTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
|
|
|
|
|
|
|
|
|
|
export type PipeTypeList =
|
2018-06-26 10:43:06 -07:00
|
|
|
(PipeDefInternal<any>|
|
|
|
|
|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
|
2018-03-29 12:58:41 -07:00
|
|
|
|
|
|
|
|
|
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;
|
2018-06-19 12:45:00 -07:00
|
|
|
|
|
|
|
|
export const enum InitialStylingFlags {
|
2018-07-11 09:56:47 -07:00
|
|
|
VALUES_MODE = 0b1,
|
2018-06-19 12:45:00 -07:00
|
|
|
}
|