refactor: move angular source to /packages rather than modules/@angular

This commit is contained in:
Jason Aden
2017-03-02 10:48:42 -08:00
parent 5ad5301a3e
commit 3e51a19983
1051 changed files with 18 additions and 18 deletions

View File

@ -0,0 +1,415 @@
/**
* @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
*/
import {InjectionToken} from '../di/injection_token';
import {Type} from '../type';
import {makeParamDecorator, makePropDecorator} from '../util/decorators';
/**
* This token can be used to create a virtual provider that will populate the
* `entryComponents` fields of components and ng modules based on its `useValue`.
* All components that are referenced in the `useValue` value (either directly
* or in a nested array or map) will be added to the `entryComponents` property.
*
* ### Example
* The following example shows how the router can populate the `entryComponents`
* field of an NgModule based on the router configuration which refers
* to components.
*
* ```typescript
* // helper function inside the router
* function provideRoutes(routes) {
* return [
* {provide: ROUTES, useValue: routes},
* {provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: routes, multi: true}
* ];
* }
*
* // user code
* let routes = [
* {path: '/root', component: RootComp},
* {path: '/teams', component: TeamsComp}
* ];
*
* @NgModule({
* providers: [provideRoutes(routes)]
* })
* class ModuleWithRoutes {}
* ```
*
* @experimental
*/
export const ANALYZE_FOR_ENTRY_COMPONENTS = new InjectionToken<any>('AnalyzeForEntryComponents');
/**
* Type of the Attribute decorator / constructor function.
*
* @stable
*/
export interface AttributeDecorator {
/**
* Specifies that a constant attribute value should be injected.
*
* The directive can inject constant string literals of host element attributes.
*
* ### Example
*
* Suppose we have an `<input>` element and want to know its `type`.
*
* ```html
* <input type="text">
* ```
*
* A decorator can inject string literal `text` like so:
*
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
*
* ### Example as TypeScript Decorator
*
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
*
* ### Example as ES5 DSL
*
* ```
* var MyComponent = ng
* .Component({...})
* .Class({
* constructor: [new ng.Attribute('title'), function(title) {
* ...
* }]
* })
* ```
*
* ### Example as ES5 annotation
*
* ```
* var MyComponent = function(title) {
* ...
* };
*
* MyComponent.annotations = [
* new ng.Component({...})
* ]
* MyComponent.parameters = [
* [new ng.Attribute('title')]
* ]
* ```
*
* @stable
*/
(name: string): any;
new (name: string): Attribute;
}
/**
* Type of the Attribute metadata.
*/
export interface Attribute { attributeName?: string; }
/**
* Attribute decorator and metadata.
*
* @stable
* @Annotation
*/
export const Attribute: AttributeDecorator =
makeParamDecorator('Attribute', [['attributeName', undefined]]);
/**
* Type of the Query metadata.
*
* @stable
*/
export interface Query {
descendants: boolean;
first: boolean;
read: any;
isViewQuery: boolean;
selector: any;
}
/**
* Base class for query metadata.
*
* See {@link ContentChildren}, {@link ContentChild}, {@link ViewChildren}, {@link ViewChild} for
* more information.
*
* @stable
*/
export abstract class Query {}
/**
* Type of the ContentChildren decorator / constructor function.
*
* See {@link ContentChildren}.
*
* @stable
*/
export interface ContentChildrenDecorator {
/**
* @whatItDoes Configures a content query.
*
* @howToUse
*
* {@example core/di/ts/contentChildren/content_children_howto.ts region='HowTo'}
*
* @description
*
* You can use ContentChildren to get the {@link QueryList} of elements or directives from the
* content DOM. Any time a child element is added, removed, or moved, the query list will be
* updated,
* and the changes observable of the query list will emit a new value.
*
* Content queries are set before the `ngAfterContentInit` callback is called.
*
* **Metadata Properties**:
*
* * **selector** - the directive type or the name used for querying.
* * **descendants** - include only direct children or all descendants.
* * **read** - read a different token from the queried elements.
*
* Let's look at an example:
*
* {@example core/di/ts/contentChildren/content_children_example.ts region='Component'}
*
* **npm package**: `@angular/core`
*
* @stable
* @Annotation
*/
(selector: Type<any>|Function|string,
{descendants, read}?: {descendants?: boolean, read?: any}): any;
new (
selector: Type<any>|Function|string,
{descendants, read}?: {descendants?: boolean, read?: any}): Query;
}
/**
* Type of the ContentChildren metadata.
*
* @stable
* @Annotation
*/
export type ContentChildren = Query;
/**
* ContentChildren decorator and metadata.
*
* @stable
* @Annotation
*/
export const ContentChildren: ContentChildrenDecorator =
<ContentChildrenDecorator>makePropDecorator(
'ContentChildren',
[
['selector', undefined], {
first: false,
isViewQuery: false,
descendants: false,
read: undefined,
}
],
Query);
/**
* Type of the ContentChild decorator / constructor function.
*
*
* @stable
*/
export interface ContentChildDecorator {
/**
* @whatItDoes Configures a content query.
*
* @howToUse
*
* {@example core/di/ts/contentChild/content_child_howto.ts region='HowTo'}
*
* @description
*
* You can use ContentChild to get the first element or the directive matching the selector from
* the content DOM. If the content DOM changes, and a new child matches the selector,
* the property will be updated.
*
* Content queries are set before the `ngAfterContentInit` callback is called.
*
* **Metadata Properties**:
*
* * **selector** - the directive type or the name used for querying.
* * **read** - read a different token from the queried element.
*
* Let's look at an example:
*
* {@example core/di/ts/contentChild/content_child_example.ts region='Component'}
*
* **npm package**: `@angular/core`
*
* @stable
* @Annotation
*/
(selector: Type<any>|Function|string, {read}?: {read?: any}): any;
new (selector: Type<any>|Function|string, {read}?: {read?: any}): ContentChild;
}
/**
* Type of the ContentChild metadata.
*
* See {@link ContentChild}.
*
* @stable
*/
export type ContentChild = Query;
/**
* ContentChild decorator and metadata.
*
* @stable
* @Annotation
*/
export const ContentChild: ContentChildDecorator = makePropDecorator(
'ContentChild',
[
['selector', undefined], {
first: true,
isViewQuery: false,
descendants: true,
read: undefined,
}
],
Query);
/**
* Type of the ViewChildren decorator / constructor function.
*
* See {@ViewChildren}.
*
* @stable
*/
export interface ViewChildrenDecorator {
/**
* @whatItDoes Configures a view query.
*
* @howToUse
*
* {@example core/di/ts/viewChildren/view_children_howto.ts region='HowTo'}
*
* @description
*
* You can use ViewChildren to get the {@link QueryList} of elements or directives from the
* view DOM. Any time a child element is added, removed, or moved, the query list will be updated,
* and the changes observable of the query list will emit a new value.
*
* View queries are set before the `ngAfterViewInit` callback is called.
*
* **Metadata Properties**:
*
* * **selector** - the directive type or the name used for querying.
* * **read** - read a different token from the queried elements.
*
* Let's look at an example:
*
* {@example core/di/ts/viewChildren/view_children_example.ts region='Component'}
*
* **npm package**: `@angular/core`
*
* @stable
* @Annotation
*/
(selector: Type<any>|Function|string, {read}?: {read?: any}): any;
new (selector: Type<any>|Function|string, {read}?: {read?: any}): ViewChildren;
}
/**
* Type of the ViewChildren metadata.
*
* @stable
*/
export type ViewChildren = Query;
/**
* ViewChildren decorator and metadata.
*
* @stable
* @Annotation
*/
export const ViewChildren: ViewChildrenDecorator = makePropDecorator(
'ViewChildren',
[
['selector', undefined], {
first: false,
isViewQuery: true,
descendants: true,
read: undefined,
}
],
Query);
/**
* Type of the ViewChild decorator / constructor function.
*
* See {@link ViewChild}
*
* @stable
*/
export interface ViewChildDecorator {
/**
* @whatItDoes Configures a view query.
*
* @howToUse
*
* {@example core/di/ts/viewChild/view_child_howto.ts region='HowTo'}
*
* @description
*
* You can use ViewChild to get the first element or the directive matching the selector from the
* view DOM. If the view DOM changes, and a new child matches the selector,
* the property will be updated.
*
* View queries are set before the `ngAfterViewInit` callback is called.
*
* **Metadata Properties**:
*
* * **selector** - the directive type or the name used for querying.
* * **read** - read a different token from the queried elements.
*
* {@example core/di/ts/viewChild/view_child_example.ts region='Component'}
*
* **npm package**: `@angular/core`
*
* @stable
* @Annotation
*/
(selector: Type<any>|Function|string, {read}?: {read?: any}): any;
new (selector: Type<any>|Function|string, {read}?: {read?: any}): ViewChild;
}
/**
* Type of the ViewChild metadata.
*
* @stable
*/
export type ViewChild = Query;
/**
* ViewChild decorator and metadata.
*
* @stable
* @Annotation
*/
export const ViewChild: ViewChildDecorator = makePropDecorator(
'ViewChild',
[
['selector', undefined], {
first: true,
isViewQuery: true,
descendants: true,
read: undefined,
}
],
Query);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,158 @@
/**
* @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
*/
import {SimpleChange} from '../change_detection/change_detection_util';
/**
* @stable
*/
export enum LifecycleHooks {
OnInit,
OnDestroy,
DoCheck,
OnChanges,
AfterContentInit,
AfterContentChecked,
AfterViewInit,
AfterViewChecked
}
/**
* A `changes` object whose keys are property names and
* values are instances of {@link SimpleChange}. See {@link OnChanges}
* @stable
*/
export interface SimpleChanges { [propName: string]: SimpleChange; }
export const LIFECYCLE_HOOKS_VALUES = [
LifecycleHooks.OnInit, LifecycleHooks.OnDestroy, LifecycleHooks.DoCheck, LifecycleHooks.OnChanges,
LifecycleHooks.AfterContentInit, LifecycleHooks.AfterContentChecked, LifecycleHooks.AfterViewInit,
LifecycleHooks.AfterViewChecked
];
/**
* @whatItDoes Lifecycle hook that is called when any data-bound property of a directive changes.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='OnChanges'}
*
* @description
* `ngOnChanges` is called right after the data-bound properties have been checked and before view
* and content children are checked if at least one of them has changed.
* The `changes` parameter contains the changed properties.
*
* See {@linkDocs guide/lifecycle-hooks#onchanges "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface OnChanges { ngOnChanges(changes: SimpleChanges): void; }
/**
* @whatItDoes Lifecycle hook that is called after data-bound properties of a directive are
* initialized.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='OnInit'}
*
* @description
* `ngOnInit` is called right after the directive's data-bound properties have been checked for the
* first time, and before any of its children have been checked. It is invoked only once when the
* directive is instantiated.
*
* See {@linkDocs guide/lifecycle-hooks "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface OnInit { ngOnInit(): void; }
/**
* @whatItDoes Lifecycle hook that is called when Angular dirty checks a directive.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='DoCheck'}
*
* @description
* `ngDoCheck` gets called to check the changes in the directives in addition to the default
* algorithm. The default change detection algorithm looks for differences by comparing
* bound-property values by reference across change detection runs.
*
* Note that a directive typically should not use both `DoCheck` and {@link OnChanges} to respond to
* changes on the same input, as `ngOnChanges` will continue to be called when the default change
* detector detects changes.
*
* See {@link KeyValueDiffers} and {@link IterableDiffers} for implementing custom dirty checking
* for collections.
*
* See {@linkDocs guide/lifecycle-hooks#docheck "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface DoCheck { ngDoCheck(): void; }
/**
* @whatItDoes Lifecycle hook that is called when a directive, pipe or service is destroyed.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='OnDestroy'}
*
* @description
* `ngOnDestroy` callback is typically used for any custom cleanup that needs to occur when the
* instance is destroyed.
*
* See {@linkDocs guide/lifecycle-hooks "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface OnDestroy { ngOnDestroy(): void; }
/**
*
* @whatItDoes Lifecycle hook that is called after a directive's content has been fully
* initialized.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterContentInit'}
*
* @description
* See {@linkDocs guide/lifecycle-hooks#aftercontent "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface AfterContentInit { ngAfterContentInit(): void; }
/**
* @whatItDoes Lifecycle hook that is called after every check of a directive's content.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterContentChecked'}
*
* @description
* See {@linkDocs guide/lifecycle-hooks#aftercontent "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface AfterContentChecked { ngAfterContentChecked(): void; }
/**
* @whatItDoes Lifecycle hook that is called after a component's view has been fully
* initialized.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterViewInit'}
*
* @description
* See {@linkDocs guide/lifecycle-hooks#afterview "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface AfterViewInit { ngAfterViewInit(): void; }
/**
* @whatItDoes Lifecycle hook that is called after every check of a component's view.
* @howToUse
* {@example core/ts/metadata/lifecycle_hooks_spec.ts region='AfterViewChecked'}
*
* @description
* See {@linkDocs guide/lifecycle-hooks#afterview "Lifecycle Hooks Guide"}.
*
* @stable
*/
export interface AfterViewChecked { ngAfterViewChecked(): void; }

View File

@ -0,0 +1,202 @@
/**
* @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
*/
import {Provider} from '../di';
import {Type} from '../type';
import {TypeDecorator, makeDecorator} from '../util/decorators';
/**
* A wrapper around a module that also includes the providers.
*
* @stable
*/
export interface ModuleWithProviders {
ngModule: Type<any>;
providers?: Provider[];
}
/**
* Interface for schema definitions in @NgModules.
*
* @experimental
*/
export interface SchemaMetadata { name: string; }
/**
* Defines a schema that will allow:
* - any non-Angular elements with a `-` in their name,
* - any properties on elements with a `-` in their name which is the common rule for custom
* elements.
*
* @stable
*/
export const CUSTOM_ELEMENTS_SCHEMA: SchemaMetadata = {
name: 'custom-elements'
};
/**
* Defines a schema that will allow any property on any element.
*
* @experimental
*/
export const NO_ERRORS_SCHEMA: SchemaMetadata = {
name: 'no-errors-schema'
};
/**
* Type of the NgModule decorator / constructor function.
*
* @stable
*/
export interface NgModuleDecorator {
/**
* Defines an NgModule.
*/
(obj?: NgModule): TypeDecorator;
new (obj?: NgModule): NgModule;
}
/**
* Type of the NgModule metadata.
*
* @stable
*/
export interface NgModule {
/**
* Defines the set of injectable objects that are available in the injector
* of this module.
*
* ## Simple Example
*
* Here is an example of a class that can be injected:
*
* ```
* class Greeter {
* greet(name:string) {
* return 'Hello ' + name + '!';
* }
* }
*
* @NgModule({
* providers: [
* Greeter
* ]
* })
* class HelloWorld {
* greeter:Greeter;
*
* constructor(greeter:Greeter) {
* this.greeter = greeter;
* }
* }
* ```
*/
providers?: Provider[];
/**
* Specifies a list of directives/pipes that belong to this module.
*
* ### Example
*
* ```javascript
* @NgModule({
* declarations: [NgFor]
* })
* class CommonModule {
* }
* ```
*/
declarations?: Array<Type<any>|any[]>;
/**
* Specifies a list of modules whose exported directives/pipes
* should be available to templates in this module.
* This can also contain {@link ModuleWithProviders}.
*
* ### Example
*
* ```javascript
* @NgModule({
* imports: [CommonModule]
* })
* class MainModule {
* }
* ```
*/
imports?: Array<Type<any>|ModuleWithProviders|any[]>;
/**
* Specifies a list of directives/pipes/modules that can be used within the template
* of any component that is part of an Angular module
* that imports this Angular module.
*
* ### Example
*
* ```javascript
* @NgModule({
* exports: [NgFor]
* })
* class CommonModule {
* }
* ```
*/
exports?: Array<Type<any>|any[]>;
/**
* Specifies a list of components that should be compiled when this module is defined.
* For each component listed here, Angular will create a {@link ComponentFactory}
* and store it in the {@link ComponentFactoryResolver}.
*/
entryComponents?: Array<Type<any>|any[]>;
/**
* Defines the components that should be bootstrapped when
* this module is bootstrapped. The components listed here
* will automatically be added to `entryComponents`.
*/
bootstrap?: Array<Type<any>|any[]>;
/**
* Elements and properties that are not Angular components nor directives have to be declared in
* the schema.
*
* Available schemas:
* - `NO_ERRORS_SCHEMA`: any elements and properties are allowed,
* - `CUSTOM_ELEMENTS_SCHEMA`: any custom elements (tag name has "-") with any properties are
* allowed.
*
* @security When using one of `NO_ERRORS_SCHEMA` or `CUSTOM_ELEMENTS_SCHEMA` we're trusting that
* allowed elements (and its properties) securely escape inputs.
*/
schemas?: Array<SchemaMetadata|any[]>;
/**
* An opaque ID for this module, e.g. a name or a path. Used to identify modules in
* `getModuleFactory`. If left `undefined`, the `NgModule` will not be registered with
* `getModuleFactory`.
*/
id?: string;
}
/**
* NgModule decorator and metadata.
*
* @stable
* @Annotation
*/
export const NgModule: NgModuleDecorator = <NgModuleDecorator>makeDecorator('NgModule', {
providers: undefined,
declarations: undefined,
imports: undefined,
exports: undefined,
entryComponents: undefined,
bootstrap: undefined,
schemas: undefined,
id: undefined,
});

View File

@ -0,0 +1,97 @@
/**
* @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
*/
/**
* Defines template and style encapsulation options available for Component's {@link Component}.
*
* See {@link ViewMetadata#encapsulation}.
* @stable
*/
export enum ViewEncapsulation {
/**
* Emulate `Native` scoping of styles by adding an attribute containing surrogate id to the Host
* Element and pre-processing the style rules provided via
* {@link ViewMetadata#styles} or {@link ViewMetadata#stylesUrls}, and adding the new Host Element
* attribute to all selectors.
*
* This is the default option.
*/
Emulated,
/**
* Use the native encapsulation mechanism of the renderer.
*
* For the DOM this means using [Shadow DOM](https://w3c.github.io/webcomponents/spec/shadow/) and
* creating a ShadowRoot for Component's Host Element.
*/
Native,
/**
* Don't provide any template or style encapsulation.
*/
None
}
/**
* Metadata properties available for configuring Views.
*
* For details on the `@Component` annotation, see {@link Component}.
*
* ### Example
*
* ```
* @Component({
* selector: 'greet',
* template: 'Hello {{name}}!',
* })
* class Greet {
* name: string;
*
* constructor() {
* this.name = 'World';
* }
* }
* ```
*
* @deprecated Use Component instead.
*
* {@link Component}
*/
export class ViewMetadata {
/** {@link Component.templateUrl} */
templateUrl: string;
/** {@link Component.template} */
template: string;
/** {@link Component.stylesUrl} */
styleUrls: string[];
/** {@link Component.styles} */
styles: string[];
/** {@link Component.encapsulation} */
encapsulation: ViewEncapsulation;
/** {@link Component.animation} */
animations: any[];
/** {@link Component.interpolation} */
interpolation: [string, string];
constructor(
{templateUrl, template, encapsulation, styles, styleUrls, animations, interpolation}: {
templateUrl?: string,
template?: string,
encapsulation?: ViewEncapsulation,
styles?: string[],
styleUrls?: string[],
animations?: any[],
interpolation?: [string, string]
} = {}) {
this.templateUrl = templateUrl;
this.template = template;
this.styleUrls = styleUrls;
this.styles = styles;
this.encapsulation = encapsulation;
this.animations = animations;
this.interpolation = interpolation;
}
}