2015-08-20 14:28:25 -07:00
|
|
|
import {isPresent, isBlank, RegExpWrapper} from 'angular2/src/core/facade/lang';
|
|
|
|
import {Promise} from 'angular2/src/core/facade/async';
|
2015-08-28 11:29:19 -07:00
|
|
|
import {Map, MapWrapper, StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
2015-08-26 11:44:59 -07:00
|
|
|
import {
|
|
|
|
ASTWithSource,
|
|
|
|
ChangeDetectionStrategy
|
|
|
|
} from 'angular2/src/core/change_detection/change_detection';
|
2015-03-23 14:10:55 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* General notes:
|
2015-04-15 21:51:30 -07:00
|
|
|
*
|
|
|
|
* The methods for creating / destroying views in this API are used in the AppViewHydrator
|
|
|
|
* and RenderViewHydrator as well.
|
|
|
|
*
|
2015-03-23 14:10:55 -07:00
|
|
|
* We are already parsing expressions on the render side:
|
|
|
|
* - this makes the ElementBinders more compact
|
|
|
|
* (e.g. no need to distinguish interpolations from regular expressions from literals)
|
|
|
|
* - allows to retrieve which properties should be accessed from the event
|
|
|
|
* by looking at the expression
|
|
|
|
* - we need the parse at least for the `template` attribute to match
|
|
|
|
* directives in it
|
|
|
|
* - render compiler is not on the critical path as
|
|
|
|
* its output will be stored in precompiled templates.
|
|
|
|
*/
|
2015-06-18 15:44:44 -07:00
|
|
|
|
2015-04-02 15:56:58 +02:00
|
|
|
export class EventBinding {
|
2015-06-12 23:11:11 +02:00
|
|
|
constructor(public fullName: string, public source: ASTWithSource) {}
|
2015-04-02 15:56:58 +02:00
|
|
|
}
|
|
|
|
|
2015-06-18 15:44:44 -07:00
|
|
|
export enum PropertyBindingType {
|
|
|
|
PROPERTY,
|
|
|
|
ATTRIBUTE,
|
|
|
|
CLASS,
|
|
|
|
STYLE
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ElementPropertyBinding {
|
|
|
|
constructor(public type: PropertyBindingType, public astWithSource: ASTWithSource,
|
|
|
|
public property: string, public unit: string = null) {}
|
|
|
|
}
|
|
|
|
|
2015-08-14 10:03:45 -07:00
|
|
|
export class RenderElementBinder {
|
2015-05-18 11:57:20 -07:00
|
|
|
index: number;
|
|
|
|
parentIndex: number;
|
|
|
|
distanceToParent: number;
|
2015-08-28 11:29:19 -07:00
|
|
|
directives: DirectiveBinder[];
|
2015-05-18 11:57:20 -07:00
|
|
|
nestedProtoView: ProtoViewDto;
|
2015-08-28 11:29:19 -07:00
|
|
|
propertyBindings: ElementPropertyBinding[];
|
2015-06-04 13:45:08 -07:00
|
|
|
variableBindings: Map<string, string>;
|
2015-03-23 14:10:55 -07:00
|
|
|
// Note: this contains a preprocessed AST
|
|
|
|
// that replaced the values that should be extracted from the element
|
|
|
|
// with a local name
|
2015-08-28 11:29:19 -07:00
|
|
|
eventBindings: EventBinding[];
|
2015-04-02 14:40:49 -07:00
|
|
|
readAttributes: Map<string, string>;
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-05-27 11:52:35 -07:00
|
|
|
constructor({index, parentIndex, distanceToParent, directives, nestedProtoView, propertyBindings,
|
2015-06-24 13:46:39 -07:00
|
|
|
variableBindings, eventBindings, readAttributes}: {
|
2015-05-27 11:52:35 -07:00
|
|
|
index?: number,
|
|
|
|
parentIndex?: number,
|
|
|
|
distanceToParent?: number,
|
2015-08-28 11:29:19 -07:00
|
|
|
directives?: DirectiveBinder[],
|
2015-05-27 11:52:35 -07:00
|
|
|
nestedProtoView?: ProtoViewDto,
|
2015-08-28 11:29:19 -07:00
|
|
|
propertyBindings?: ElementPropertyBinding[],
|
2015-06-04 13:45:08 -07:00
|
|
|
variableBindings?: Map<string, string>,
|
2015-08-28 11:29:19 -07:00
|
|
|
eventBindings?: EventBinding[],
|
2015-05-27 11:52:35 -07:00
|
|
|
readAttributes?: Map<string, string>
|
|
|
|
} = {}) {
|
2015-03-23 14:10:55 -07:00
|
|
|
this.index = index;
|
|
|
|
this.parentIndex = parentIndex;
|
|
|
|
this.distanceToParent = distanceToParent;
|
|
|
|
this.directives = directives;
|
|
|
|
this.nestedProtoView = nestedProtoView;
|
|
|
|
this.propertyBindings = propertyBindings;
|
|
|
|
this.variableBindings = variableBindings;
|
|
|
|
this.eventBindings = eventBindings;
|
2015-04-02 14:40:49 -07:00
|
|
|
this.readAttributes = readAttributes;
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DirectiveBinder {
|
2015-04-09 21:20:11 +02:00
|
|
|
// Index into the array of directives in the View instance
|
2015-05-18 11:57:20 -07:00
|
|
|
directiveIndex: number;
|
2015-03-23 14:10:55 -07:00
|
|
|
propertyBindings: Map<string, ASTWithSource>;
|
|
|
|
// Note: this contains a preprocessed AST
|
|
|
|
// that replaced the values that should be extracted from the element
|
|
|
|
// with a local name
|
2015-08-28 11:29:19 -07:00
|
|
|
eventBindings: EventBinding[];
|
|
|
|
hostPropertyBindings: ElementPropertyBinding[];
|
2015-05-27 11:52:35 -07:00
|
|
|
constructor({directiveIndex, propertyBindings, eventBindings, hostPropertyBindings}: {
|
|
|
|
directiveIndex?: number,
|
|
|
|
propertyBindings?: Map<string, ASTWithSource>,
|
2015-08-28 11:29:19 -07:00
|
|
|
eventBindings?: EventBinding[],
|
|
|
|
hostPropertyBindings?: ElementPropertyBinding[]
|
2015-03-23 14:10:55 -07:00
|
|
|
}) {
|
|
|
|
this.directiveIndex = directiveIndex;
|
|
|
|
this.propertyBindings = propertyBindings;
|
|
|
|
this.eventBindings = eventBindings;
|
2015-04-21 11:47:53 -07:00
|
|
|
this.hostPropertyBindings = hostPropertyBindings;
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 15:20:33 +02:00
|
|
|
export enum ViewType {
|
|
|
|
// A view that contains the host element with bound component directive.
|
|
|
|
// Contains a COMPONENT view
|
|
|
|
HOST,
|
2015-04-15 21:51:30 -07:00
|
|
|
// The view of the component
|
2015-06-09 15:20:33 +02:00
|
|
|
// Can contain 0 to n EMBEDDED views
|
|
|
|
COMPONENT,
|
2015-04-29 15:07:55 -07:00
|
|
|
// A view that is embedded into another View via a <template> element
|
2015-06-09 15:20:33 +02:00
|
|
|
// inside of a COMPONENT view
|
|
|
|
EMBEDDED
|
|
|
|
}
|
2015-04-15 21:51:30 -07:00
|
|
|
|
2015-06-09 15:20:33 +02:00
|
|
|
export class ProtoViewDto {
|
2015-04-28 11:20:01 -07:00
|
|
|
render: RenderProtoViewRef;
|
2015-08-28 11:29:19 -07:00
|
|
|
elementBinders: RenderElementBinder[];
|
2015-03-23 14:10:55 -07:00
|
|
|
variableBindings: Map<string, string>;
|
2015-06-09 15:20:33 +02:00
|
|
|
type: ViewType;
|
2015-08-28 11:29:19 -07:00
|
|
|
textBindings: ASTWithSource[];
|
2015-07-20 09:59:44 -07:00
|
|
|
transitiveNgContentCount: number;
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-07-20 09:59:44 -07:00
|
|
|
constructor({render, elementBinders, variableBindings, type, textBindings,
|
|
|
|
transitiveNgContentCount}: {
|
2015-05-27 11:52:35 -07:00
|
|
|
render?: RenderProtoViewRef,
|
2015-08-28 11:29:19 -07:00
|
|
|
elementBinders?: RenderElementBinder[],
|
2015-05-27 11:52:35 -07:00
|
|
|
variableBindings?: Map<string, string>,
|
2015-06-24 13:46:39 -07:00
|
|
|
type?: ViewType,
|
2015-08-28 11:29:19 -07:00
|
|
|
textBindings?: ASTWithSource[],
|
2015-07-20 09:59:44 -07:00
|
|
|
transitiveNgContentCount?: number
|
2015-05-27 11:52:35 -07:00
|
|
|
}) {
|
2015-03-23 14:10:55 -07:00
|
|
|
this.render = render;
|
|
|
|
this.elementBinders = elementBinders;
|
|
|
|
this.variableBindings = variableBindings;
|
2015-04-15 21:51:30 -07:00
|
|
|
this.type = type;
|
2015-06-24 13:46:39 -07:00
|
|
|
this.textBindings = textBindings;
|
2015-07-20 09:59:44 -07:00
|
|
|
this.transitiveNgContentCount = transitiveNgContentCount;
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 10:03:45 -07:00
|
|
|
export class RenderDirectiveMetadata {
|
2015-04-30 13:38:40 -07:00
|
|
|
static get DIRECTIVE_TYPE() { return 0; }
|
2015-03-23 14:10:55 -07:00
|
|
|
static get COMPONENT_TYPE() { return 1; }
|
2015-05-18 11:57:20 -07:00
|
|
|
id: any;
|
|
|
|
selector: string;
|
|
|
|
compileChildren: boolean;
|
2015-08-28 11:29:19 -07:00
|
|
|
events: string[];
|
|
|
|
properties: string[];
|
|
|
|
readAttributes: string[];
|
2015-05-18 11:57:20 -07:00
|
|
|
type: number;
|
|
|
|
callOnDestroy: boolean;
|
2015-08-27 21:19:56 -07:00
|
|
|
callOnChanges: boolean;
|
|
|
|
callDoCheck: boolean;
|
2015-05-27 10:14:37 -07:00
|
|
|
callOnInit: boolean;
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterContentInit: boolean;
|
2015-08-27 21:19:56 -07:00
|
|
|
callAfterContentChecked: boolean;
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterViewInit: boolean;
|
|
|
|
callAfterViewChecked: boolean;
|
2015-08-26 11:44:59 -07:00
|
|
|
changeDetection: ChangeDetectionStrategy;
|
2015-06-04 13:45:08 -07:00
|
|
|
exportAs: string;
|
2015-06-09 12:33:40 +02:00
|
|
|
hostListeners: Map<string, string>;
|
|
|
|
hostProperties: Map<string, string>;
|
|
|
|
hostAttributes: Map<string, string>;
|
2015-06-23 12:46:38 +02:00
|
|
|
// group 1: "property" from "[property]"
|
|
|
|
// group 2: "event" from "(event)"
|
2015-08-26 13:55:53 -07:00
|
|
|
private static _hostRegExp = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))$/g;
|
2015-06-09 12:33:40 +02:00
|
|
|
|
2015-05-27 11:52:35 -07:00
|
|
|
constructor({id, selector, compileChildren, events, hostListeners, hostProperties, hostAttributes,
|
2015-08-27 21:19:56 -07:00
|
|
|
properties, readAttributes, type, callOnDestroy, callOnChanges, callDoCheck,
|
2015-08-28 18:11:04 -07:00
|
|
|
callOnInit, callAfterContentInit, callAfterContentChecked, callAfterViewInit,
|
|
|
|
callAfterViewChecked, changeDetection, exportAs}: {
|
2015-05-27 11:52:35 -07:00
|
|
|
id?: string,
|
|
|
|
selector?: string,
|
|
|
|
compileChildren?: boolean,
|
2015-08-28 11:29:19 -07:00
|
|
|
events?: string[],
|
2015-05-27 11:52:35 -07:00
|
|
|
hostListeners?: Map<string, string>,
|
|
|
|
hostProperties?: Map<string, string>,
|
|
|
|
hostAttributes?: Map<string, string>,
|
2015-08-28 11:29:19 -07:00
|
|
|
properties?: string[],
|
|
|
|
readAttributes?: string[],
|
2015-05-27 11:52:35 -07:00
|
|
|
type?: number,
|
|
|
|
callOnDestroy?: boolean,
|
2015-08-27 21:19:56 -07:00
|
|
|
callOnChanges?: boolean,
|
|
|
|
callDoCheck?: boolean,
|
2015-05-27 10:14:37 -07:00
|
|
|
callOnInit?: boolean,
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterContentInit?: boolean,
|
2015-08-27 21:19:56 -07:00
|
|
|
callAfterContentChecked?: boolean,
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterViewInit?: boolean,
|
|
|
|
callAfterViewChecked?: boolean,
|
2015-08-26 11:44:59 -07:00
|
|
|
changeDetection?: ChangeDetectionStrategy,
|
2015-06-04 13:45:08 -07:00
|
|
|
exportAs?: string
|
2015-05-27 11:52:35 -07:00
|
|
|
}) {
|
2015-03-23 14:10:55 -07:00
|
|
|
this.id = id;
|
|
|
|
this.selector = selector;
|
|
|
|
this.compileChildren = isPresent(compileChildren) ? compileChildren : true;
|
2015-05-11 17:59:39 -07:00
|
|
|
this.events = events;
|
2015-04-09 21:20:11 +02:00
|
|
|
this.hostListeners = hostListeners;
|
2015-05-01 13:41:56 +02:00
|
|
|
this.hostAttributes = hostAttributes;
|
2015-06-09 12:33:40 +02:00
|
|
|
this.hostProperties = hostProperties;
|
2015-04-09 21:20:11 +02:00
|
|
|
this.properties = properties;
|
2015-04-02 14:40:49 -07:00
|
|
|
this.readAttributes = readAttributes;
|
2015-03-23 14:10:55 -07:00
|
|
|
this.type = type;
|
2015-05-11 17:59:39 -07:00
|
|
|
this.callOnDestroy = callOnDestroy;
|
2015-08-27 21:19:56 -07:00
|
|
|
this.callOnChanges = callOnChanges;
|
|
|
|
this.callDoCheck = callDoCheck;
|
2015-05-27 10:14:37 -07:00
|
|
|
this.callOnInit = callOnInit;
|
2015-08-28 18:11:04 -07:00
|
|
|
this.callAfterContentInit = callAfterContentInit;
|
2015-08-27 21:19:56 -07:00
|
|
|
this.callAfterContentChecked = callAfterContentChecked;
|
2015-08-28 18:11:04 -07:00
|
|
|
this.callAfterViewInit = callAfterViewInit;
|
|
|
|
this.callAfterViewChecked = callAfterViewChecked;
|
2015-05-11 17:59:39 -07:00
|
|
|
this.changeDetection = changeDetection;
|
2015-06-04 13:45:08 -07:00
|
|
|
this.exportAs = exportAs;
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
2015-06-09 12:33:40 +02:00
|
|
|
|
|
|
|
static create({id, selector, compileChildren, events, host, properties, readAttributes, type,
|
2015-08-28 18:11:04 -07:00
|
|
|
callOnDestroy, callOnChanges, callDoCheck, callOnInit, callAfterContentInit,
|
|
|
|
callAfterContentChecked, callAfterViewInit, callAfterViewChecked, changeDetection,
|
|
|
|
exportAs}: {
|
2015-06-09 12:33:40 +02:00
|
|
|
id?: string,
|
|
|
|
selector?: string,
|
|
|
|
compileChildren?: boolean,
|
2015-08-28 11:29:19 -07:00
|
|
|
events?: string[],
|
2015-06-09 12:33:40 +02:00
|
|
|
host?: Map<string, string>,
|
2015-08-28 11:29:19 -07:00
|
|
|
properties?: string[],
|
|
|
|
readAttributes?: string[],
|
2015-06-09 12:33:40 +02:00
|
|
|
type?: number,
|
|
|
|
callOnDestroy?: boolean,
|
2015-08-27 21:19:56 -07:00
|
|
|
callOnChanges?: boolean,
|
|
|
|
callDoCheck?: boolean,
|
2015-06-09 12:33:40 +02:00
|
|
|
callOnInit?: boolean,
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterContentInit?: boolean,
|
2015-08-27 21:19:56 -07:00
|
|
|
callAfterContentChecked?: boolean,
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterViewInit?: boolean,
|
|
|
|
callAfterViewChecked?: boolean,
|
2015-08-26 11:44:59 -07:00
|
|
|
changeDetection?: ChangeDetectionStrategy,
|
2015-06-09 12:33:40 +02:00
|
|
|
exportAs?: string
|
2015-08-14 10:03:45 -07:00
|
|
|
}): RenderDirectiveMetadata {
|
2015-06-17 16:21:40 -07:00
|
|
|
let hostListeners = new Map();
|
|
|
|
let hostProperties = new Map();
|
|
|
|
let hostAttributes = new Map();
|
2015-06-09 12:33:40 +02:00
|
|
|
|
|
|
|
if (isPresent(host)) {
|
|
|
|
MapWrapper.forEach(host, (value: string, key: string) => {
|
2015-08-14 10:03:45 -07:00
|
|
|
var matches = RegExpWrapper.firstMatch(RenderDirectiveMetadata._hostRegExp, key);
|
2015-06-09 12:33:40 +02:00
|
|
|
if (isBlank(matches)) {
|
2015-06-17 16:21:40 -07:00
|
|
|
hostAttributes.set(key, value);
|
2015-06-09 12:33:40 +02:00
|
|
|
} else if (isPresent(matches[1])) {
|
2015-06-17 16:21:40 -07:00
|
|
|
hostProperties.set(matches[1], value);
|
2015-06-09 12:33:40 +02:00
|
|
|
} else if (isPresent(matches[2])) {
|
2015-06-17 16:21:40 -07:00
|
|
|
hostListeners.set(matches[2], value);
|
2015-06-09 12:33:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-08-14 10:03:45 -07:00
|
|
|
return new RenderDirectiveMetadata({
|
2015-06-12 09:14:59 +02:00
|
|
|
id: id,
|
|
|
|
selector: selector,
|
|
|
|
compileChildren: compileChildren,
|
|
|
|
events: events,
|
|
|
|
hostListeners: hostListeners,
|
|
|
|
hostProperties: hostProperties,
|
|
|
|
hostAttributes: hostAttributes,
|
|
|
|
properties: properties,
|
|
|
|
readAttributes: readAttributes,
|
|
|
|
type: type,
|
|
|
|
callOnDestroy: callOnDestroy,
|
2015-08-27 21:19:56 -07:00
|
|
|
callOnChanges: callOnChanges,
|
|
|
|
callDoCheck: callDoCheck,
|
2015-06-12 09:14:59 +02:00
|
|
|
callOnInit: callOnInit,
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterContentInit: callAfterContentInit,
|
2015-08-27 21:19:56 -07:00
|
|
|
callAfterContentChecked: callAfterContentChecked,
|
2015-08-28 18:11:04 -07:00
|
|
|
callAfterViewInit: callAfterViewInit,
|
|
|
|
callAfterViewChecked: callAfterViewChecked,
|
2015-06-12 09:14:59 +02:00
|
|
|
changeDetection: changeDetection,
|
|
|
|
exportAs: exportAs
|
|
|
|
});
|
2015-06-09 12:33:40 +02:00
|
|
|
}
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:08:44 -07:00
|
|
|
// An opaque reference to a render proto view
|
2015-05-18 11:57:20 -07:00
|
|
|
export class RenderProtoViewRef {}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-06-24 13:46:39 -07:00
|
|
|
// An opaque reference to a part of a view
|
|
|
|
export class RenderFragmentRef {}
|
|
|
|
|
|
|
|
// An opaque reference to a view
|
2015-05-18 11:57:20 -07:00
|
|
|
export class RenderViewRef {}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-07-24 15:28:44 -07:00
|
|
|
/**
|
|
|
|
* How the template and styles of a view should be encapsulated.
|
|
|
|
*/
|
|
|
|
export enum ViewEncapsulation {
|
|
|
|
/**
|
|
|
|
* Emulate scoping of styles by preprocessing the style rules
|
|
|
|
* and adding additional attributes to elements. This is the default.
|
|
|
|
*/
|
2015-08-28 21:03:19 -07:00
|
|
|
Emulated,
|
2015-07-24 15:28:44 -07:00
|
|
|
/**
|
|
|
|
* Uses the native mechanism of the renderer. For the DOM this means creating a ShadowRoot.
|
|
|
|
*/
|
2015-08-28 21:03:19 -07:00
|
|
|
Native,
|
2015-07-24 15:28:44 -07:00
|
|
|
/**
|
|
|
|
* Don't scope the template nor the styles.
|
|
|
|
*/
|
2015-08-28 21:03:19 -07:00
|
|
|
None
|
2015-07-24 15:28:44 -07:00
|
|
|
}
|
|
|
|
|
2015-09-11 13:35:46 -07:00
|
|
|
var encapsulationMap: Map<number, ViewEncapsulation> = MapWrapper.createFromPairs(
|
|
|
|
[[0, ViewEncapsulation.Emulated], [1, ViewEncapsulation.Native], [2, ViewEncapsulation.None]]);
|
|
|
|
export function viewEncapsulationFromJson(value: number): ViewEncapsulation {
|
|
|
|
return deserializeEnum(value, encapsulationMap);
|
|
|
|
}
|
|
|
|
|
2015-04-09 21:20:11 +02:00
|
|
|
export class ViewDefinition {
|
2015-03-23 14:10:55 -07:00
|
|
|
componentId: string;
|
2015-06-10 14:40:24 +02:00
|
|
|
templateAbsUrl: string;
|
2015-04-09 21:20:11 +02:00
|
|
|
template: string;
|
2015-08-28 11:29:19 -07:00
|
|
|
directives: RenderDirectiveMetadata[];
|
|
|
|
styleAbsUrls: string[];
|
|
|
|
styles: string[];
|
2015-07-24 15:28:44 -07:00
|
|
|
encapsulation: ViewEncapsulation;
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-07-24 15:28:44 -07:00
|
|
|
constructor({componentId, templateAbsUrl, template, styleAbsUrls, styles, directives,
|
|
|
|
encapsulation}: {
|
2015-05-27 11:52:35 -07:00
|
|
|
componentId?: string,
|
2015-06-10 14:40:24 +02:00
|
|
|
templateAbsUrl?: string,
|
2015-05-27 11:52:35 -07:00
|
|
|
template?: string,
|
2015-08-28 11:29:19 -07:00
|
|
|
styleAbsUrls?: string[],
|
|
|
|
styles?: string[],
|
|
|
|
directives?: RenderDirectiveMetadata[],
|
2015-07-24 15:28:44 -07:00
|
|
|
encapsulation?: ViewEncapsulation
|
|
|
|
} = {}) {
|
2015-03-23 14:10:55 -07:00
|
|
|
this.componentId = componentId;
|
2015-06-10 14:40:24 +02:00
|
|
|
this.templateAbsUrl = templateAbsUrl;
|
2015-04-09 21:20:11 +02:00
|
|
|
this.template = template;
|
2015-06-10 14:40:24 +02:00
|
|
|
this.styleAbsUrls = styleAbsUrls;
|
|
|
|
this.styles = styles;
|
2015-03-23 14:10:55 -07:00
|
|
|
this.directives = directives;
|
2015-08-28 21:03:19 -07:00
|
|
|
this.encapsulation = isPresent(encapsulation) ? encapsulation : ViewEncapsulation.Emulated;
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 13:46:39 -07:00
|
|
|
export class RenderProtoViewMergeMapping {
|
|
|
|
constructor(public mergedProtoViewRef: RenderProtoViewRef,
|
|
|
|
// Number of fragments in the merged ProtoView.
|
|
|
|
// Fragments are stored in depth first order of nested ProtoViews.
|
|
|
|
public fragmentCount: number,
|
|
|
|
// Mapping from app element index to render element index.
|
|
|
|
// Mappings of nested ProtoViews are in depth first order, with all
|
2015-09-07 23:37:21 -07:00
|
|
|
// indices for one ProtoView in a consecutive block.
|
2015-06-24 13:46:39 -07:00
|
|
|
public mappedElementIndices: number[],
|
2015-07-23 14:27:49 -07:00
|
|
|
// Number of bound render element.
|
|
|
|
// Note: This could be more than the original ones
|
|
|
|
// as we might have bound a new element for projecting bound text nodes.
|
|
|
|
public mappedElementCount: number,
|
2015-06-24 13:46:39 -07:00
|
|
|
// Mapping from app text index to render text index.
|
|
|
|
// Mappings of nested ProtoViews are in depth first order, with all
|
2015-09-07 23:37:21 -07:00
|
|
|
// indices for one ProtoView in a consecutive block.
|
2015-06-24 13:46:39 -07:00
|
|
|
public mappedTextIndices: number[],
|
|
|
|
// Mapping from view index to app element index
|
2015-07-20 09:59:44 -07:00
|
|
|
public hostElementIndicesByViewIndex: number[],
|
|
|
|
// Number of contained views by view index
|
|
|
|
public nestedViewCountByViewIndex: number[]) {}
|
2015-06-24 13:46:39 -07:00
|
|
|
}
|
|
|
|
|
2015-05-06 10:17:38 -07:00
|
|
|
export class RenderCompiler {
|
2015-04-15 21:51:30 -07:00
|
|
|
/**
|
2015-09-08 16:43:24 +02:00
|
|
|
* Creates a ProtoViewDto that contains a single nested component with the given componentId.
|
2015-04-15 21:51:30 -07:00
|
|
|
*/
|
2015-08-14 10:03:45 -07:00
|
|
|
compileHost(directiveMetadata: RenderDirectiveMetadata): Promise<ProtoViewDto> { return null; }
|
2015-04-15 21:51:30 -07:00
|
|
|
|
2015-03-23 14:10:55 -07:00
|
|
|
/**
|
2015-05-06 11:22:28 -07:00
|
|
|
* Compiles a single DomProtoView. Non recursive so that
|
2015-03-23 14:10:55 -07:00
|
|
|
* we don't need to serialize all possible components over the wire,
|
|
|
|
* but only the needed ones based on previous calls.
|
|
|
|
*/
|
2015-06-15 15:57:42 +02:00
|
|
|
compile(view: ViewDefinition): Promise<ProtoViewDto> { return null; }
|
2015-06-24 13:46:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges ProtoViews.
|
|
|
|
* The first entry of the array is the protoview into which all the other entries of the array
|
|
|
|
* should be merged.
|
|
|
|
* If the array contains other arrays, they will be merged before processing the parent array.
|
|
|
|
* The array must contain an entry for every component and embedded ProtoView of the first entry.
|
2015-08-28 11:29:19 -07:00
|
|
|
* @param protoViewRefs Array of ProtoViewRefs or nested
|
2015-07-20 09:59:44 -07:00
|
|
|
* @return the merge result
|
2015-06-24 13:46:39 -07:00
|
|
|
*/
|
|
|
|
mergeProtoViewsRecursively(
|
2015-08-28 11:29:19 -07:00
|
|
|
protoViewRefs: Array<RenderProtoViewRef | any[]>): Promise<RenderProtoViewMergeMapping> {
|
2015-06-24 13:46:39 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class RenderViewWithFragments {
|
|
|
|
constructor(public viewRef: RenderViewRef, public fragmentRefs: RenderFragmentRef[]) {}
|
2015-05-06 10:17:38 -07:00
|
|
|
}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-07-07 08:15:58 +02:00
|
|
|
/**
|
2015-07-11 17:26:48 +02:00
|
|
|
* Abstract reference to the element which can be marshaled across web-worker boundary.
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
2015-07-22 22:07:51 -07:00
|
|
|
* This interface is used by the Renderer API.
|
2015-07-07 08:15:58 +02:00
|
|
|
*/
|
2015-06-23 11:21:56 -07:00
|
|
|
export interface RenderElementRef {
|
2015-07-07 08:15:58 +02:00
|
|
|
/**
|
2015-07-22 22:07:51 -07:00
|
|
|
* Reference to the `RenderViewRef` where the `RenderElementRef` is inside of.
|
2015-07-07 08:15:58 +02:00
|
|
|
*/
|
2015-06-23 11:21:56 -07:00
|
|
|
renderView: RenderViewRef;
|
2015-07-07 08:15:58 +02:00
|
|
|
/**
|
2015-07-22 22:07:51 -07:00
|
|
|
* Index of the element inside the `RenderViewRef`.
|
2015-07-07 08:15:58 +02:00
|
|
|
*
|
|
|
|
* This is used internally by the Angular framework to locate elements.
|
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
renderBoundElementIndex: number;
|
2015-06-23 11:21:56 -07:00
|
|
|
}
|
|
|
|
|
2015-05-06 10:17:38 -07:00
|
|
|
export class Renderer {
|
2015-03-23 14:10:55 -07:00
|
|
|
/**
|
2015-05-15 09:55:43 -07:00
|
|
|
* Creates a root host view that includes the given element.
|
2015-06-24 13:46:39 -07:00
|
|
|
* Note that the fragmentCount needs to be passed in so that we can create a result
|
|
|
|
* synchronously even when dealing with webworkers!
|
|
|
|
*
|
2015-05-18 11:57:20 -07:00
|
|
|
* @param {RenderProtoViewRef} hostProtoViewRef a RenderProtoViewRef of type
|
|
|
|
* ProtoViewDto.HOST_VIEW_TYPE
|
|
|
|
* @param {any} hostElementSelector css selector for the host element (will be queried against the
|
|
|
|
* main document)
|
2015-06-24 13:46:39 -07:00
|
|
|
* @return {RenderViewWithFragments} the created view including fragments
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
createRootHostView(hostProtoViewRef: RenderProtoViewRef, fragmentCount: number,
|
|
|
|
hostElementSelector: string): RenderViewWithFragments {
|
2015-05-06 10:49:42 -07:00
|
|
|
return null;
|
|
|
|
}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
|
|
|
/**
|
2015-06-24 13:46:39 -07:00
|
|
|
* Creates a regular view out of the given ProtoView.
|
|
|
|
* Note that the fragmentCount needs to be passed in so that we can create a result
|
|
|
|
* synchronously even when dealing with webworkers!
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
createView(protoViewRef: RenderProtoViewRef, fragmentCount: number): RenderViewWithFragments {
|
|
|
|
return null;
|
|
|
|
}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
|
|
|
/**
|
2015-05-06 10:49:42 -07:00
|
|
|
* Destroys the given view after it has been dehydrated and detached
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-05-18 11:57:20 -07:00
|
|
|
destroyView(viewRef: RenderViewRef) {}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-04-15 21:51:30 -07:00
|
|
|
/**
|
2015-06-24 13:46:39 -07:00
|
|
|
* Attaches a fragment after another fragment.
|
2015-04-15 21:51:30 -07:00
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
attachFragmentAfterFragment(previousFragmentRef: RenderFragmentRef,
|
|
|
|
fragmentRef: RenderFragmentRef) {}
|
2015-04-15 21:51:30 -07:00
|
|
|
|
|
|
|
/**
|
2015-06-24 13:46:39 -07:00
|
|
|
* Attaches a fragment after an element.
|
2015-04-15 21:51:30 -07:00
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
attachFragmentAfterElement(elementRef: RenderElementRef, fragmentRef: RenderFragmentRef) {}
|
2015-04-15 21:51:30 -07:00
|
|
|
|
|
|
|
/**
|
2015-06-24 13:46:39 -07:00
|
|
|
* Detaches a fragment.
|
2015-04-15 21:51:30 -07:00
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
detachFragment(fragmentRef: RenderFragmentRef) {}
|
2015-04-15 21:51:30 -07:00
|
|
|
|
2015-03-23 14:10:55 -07:00
|
|
|
/**
|
2015-05-18 11:57:20 -07:00
|
|
|
* Hydrates a view after it has been attached. Hydration/dehydration is used for reusing views
|
|
|
|
* inside of the view pool.
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-05-18 11:57:20 -07:00
|
|
|
hydrateView(viewRef: RenderViewRef) {}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
|
|
|
/**
|
2015-05-18 11:57:20 -07:00
|
|
|
* Dehydrates a view after it has been attached. Hydration/dehydration is used for reusing views
|
|
|
|
* inside of the view pool.
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-05-18 11:57:20 -07:00
|
|
|
dehydrateView(viewRef: RenderViewRef) {}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-06-23 14:26:02 -07:00
|
|
|
/**
|
|
|
|
* Returns the native element at the given location.
|
|
|
|
* Attention: In a WebWorker scenario, this should always return null!
|
|
|
|
*/
|
|
|
|
getNativeElementSync(location: RenderElementRef): any { return null; }
|
|
|
|
|
2015-03-23 14:10:55 -07:00
|
|
|
/**
|
2015-05-11 12:31:16 -07:00
|
|
|
* Sets a property on an element.
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-06-23 11:21:56 -07:00
|
|
|
setElementProperty(location: RenderElementRef, propertyName: string, propertyValue: any) {}
|
2015-05-06 10:49:42 -07:00
|
|
|
|
2015-05-11 12:31:16 -07:00
|
|
|
/**
|
2015-06-18 15:44:44 -07:00
|
|
|
* Sets an attribute on an element.
|
|
|
|
*/
|
2015-06-23 11:21:56 -07:00
|
|
|
setElementAttribute(location: RenderElementRef, attributeName: string, attributeValue: string) {}
|
2015-06-18 15:44:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a class on an element.
|
|
|
|
*/
|
2015-06-23 11:21:56 -07:00
|
|
|
setElementClass(location: RenderElementRef, className: string, isAdd: boolean) {}
|
2015-06-18 15:44:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a style on an element.
|
|
|
|
*/
|
2015-06-23 11:21:56 -07:00
|
|
|
setElementStyle(location: RenderElementRef, styleName: string, styleValue: string) {}
|
2015-06-18 15:44:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls a method on an element.
|
2015-05-11 12:31:16 -07:00
|
|
|
*/
|
2015-08-28 11:29:19 -07:00
|
|
|
invokeElementMethod(location: RenderElementRef, methodName: string, args: any[]) {}
|
2015-05-11 12:31:16 -07:00
|
|
|
|
|
|
|
/**
|
2015-05-06 10:49:42 -07:00
|
|
|
* Sets the value of a text node.
|
|
|
|
*/
|
2015-05-18 11:57:20 -07:00
|
|
|
setText(viewRef: RenderViewRef, textNodeIndex: number, text: string) {}
|
2015-03-23 14:10:55 -07:00
|
|
|
|
|
|
|
/**
|
2015-05-06 10:49:42 -07:00
|
|
|
* Sets the dispatcher for all events of the given view
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
setEventDispatcher(viewRef: RenderViewRef, dispatcher: RenderEventDispatcher) {}
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A dispatcher for all events happening in a view.
|
|
|
|
*/
|
2015-06-24 13:46:39 -07:00
|
|
|
export interface RenderEventDispatcher {
|
2015-03-23 14:10:55 -07:00
|
|
|
/**
|
|
|
|
* Called when an event was triggered for a on-* attribute on an element.
|
2015-04-07 20:54:20 -07:00
|
|
|
* @param {Map<string, any>} locals Locals to be used to evaluate the
|
2015-03-23 14:10:55 -07:00
|
|
|
* event expressions
|
2015-08-26 13:25:00 -07:00
|
|
|
* @return {boolean} False if `preventDefault` should be called on the DOM event.
|
2015-03-23 14:10:55 -07:00
|
|
|
*/
|
2015-08-26 13:25:00 -07:00
|
|
|
dispatchRenderEvent(elementIndex: number, eventName: string, locals: Map<string, any>): boolean;
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|