Index: third_party/pkg/angular/lib/core/annotation_src.dart |
diff --git a/third_party/pkg/angular/lib/core/directive.dart b/third_party/pkg/angular/lib/core/annotation_src.dart |
similarity index 54% |
rename from third_party/pkg/angular/lib/core/directive.dart |
rename to third_party/pkg/angular/lib/core/annotation_src.dart |
index 63fd69a0f399265c0802e00cad8e36877290f71f..ee5270362408878aae0dfbc55a5c15309b69a6ce 100644 |
--- a/third_party/pkg/angular/lib/core/directive.dart |
+++ b/third_party/pkg/angular/lib/core/annotation_src.dart |
@@ -1,6 +1,55 @@ |
-part of angular.core; |
+library angular.core.annotation_src; |
+ |
+import "package:di/di.dart" show Injector, Visibility; |
+ |
+RegExp _ATTR_NAME = new RegExp(r'\[([^\]]+)\]$'); |
+ |
+const String SHADOW_DOM_INJECTOR_NAME = 'SHADOW_INJECTOR'; |
+ |
+skipShadow(Injector injector) |
+ => injector.name == SHADOW_DOM_INJECTOR_NAME ? injector.parent : injector; |
+ |
+localVisibility (Injector requesting, Injector defining) |
+ => identical(skipShadow(requesting), defining); |
+ |
+directChildrenVisibility(Injector requesting, Injector defining) { |
+ requesting = skipShadow(requesting); |
+ return identical(requesting.parent, defining) || localVisibility(requesting, defining); |
+} |
+ |
+Directive cloneWithNewMap(Directive annotation, map) |
+ => annotation._cloneWithNewMap(map); |
+ |
+String mappingSpec(DirectiveAnnotation annotation) => annotation._mappingSpec; |
+ |
+ |
+/** |
+ * An annotation when applied to a class indicates that the class (service) will |
+ * be instantiated by di injector. This annotation is also used to designate which |
+ * classes need to have a static factory generated when using static angular, and |
+ * therefore is required on any injectable class. |
+ */ |
+class Injectable { |
+ const Injectable(); |
+} |
+ |
+/** |
+ * Abstract supper class of [Controller], [Component], and [Decorator]. |
+ */ |
+abstract class Directive { |
+ |
+ /// The directive can only be injected to other directives on the same element. |
+ static const Visibility LOCAL_VISIBILITY = localVisibility; |
+ |
+ /// The directive can be injected to other directives on the same or child elements. |
+ static const Visibility CHILDREN_VISIBILITY = null; |
+ |
+ /** |
+ * The directive on this element can only be injected to other directives |
+ * declared on elements which are direct children of the current element. |
+ */ |
+ static const Visibility DIRECT_CHILDREN_VISIBILITY = directChildrenVisibility; |
-abstract class NgAnnotation { |
/** |
* CSS selector which will trigger this component/directive. |
* CSS Selectors are limited to a single element and can contain: |
@@ -9,6 +58,7 @@ abstract class NgAnnotation { |
* * `.class` limit to an element with a given class. |
* * `[attribute]` limit to an element with a given attribute name. |
* * `[attribute=value]` limit to an element with a given attribute and value. |
+ * * `:contains(/abc/)` limit to an element which contains the given text. |
* |
* |
* Example: `input[type=checkbox][ng-model]` |
@@ -23,21 +73,25 @@ abstract class NgAnnotation { |
* * [TRANSCLUDE_CHILDREN] |
* * [IGNORE_CHILDREN] |
*/ |
+ @deprecated |
final String children; |
/** |
* Compile the child nodes of the element. This is the default. |
*/ |
+ @deprecated |
static const String COMPILE_CHILDREN = 'compile'; |
/** |
* Compile the child nodes for transclusion and makes available |
- * [BoundBlockFactory], [BlockFactory] and [BlockHole] for injection. |
+ * [BoundViewFactory], [ViewFactory] and [ViewPort] for injection. |
*/ |
+ @deprecated |
static const String TRANSCLUDE_CHILDREN = 'transclude'; |
/** |
* Do not compile/visit the child nodes. Angular markup on descendant nodes |
* will not be processed. |
*/ |
+ @deprecated |
static const String IGNORE_CHILDREN = 'ignore'; |
/** |
@@ -45,17 +99,40 @@ abstract class NgAnnotation { |
* directives/components. This attribute controls whether the |
* controller is available to others. |
* |
- * * `local` [NgDirective.LOCAL_VISIBILITY] - the controller can be injected |
+ * * `local` [Directive.LOCAL_VISIBILITY] - the controller can be injected |
* into other directives / components on the same DOM element. |
- * * `children` [NgDirective.CHILDREN_VISIBILITY] - the controller can be |
+ * * `children` [Directive.CHILDREN_VISIBILITY] - the controller can be |
* injected into other directives / components on the same or child DOM |
* elements. |
- * * `direct_children` [NgDirective.DIRECT_CHILDREN_VISIBILITY] - the |
+ * * `direct_children` [Directive.DIRECT_CHILDREN_VISIBILITY] - the |
* controller can be injected into other directives / components on the |
* direct children of the current DOM element. |
*/ |
- final String visibility; |
- final List<Type> publishTypes; |
+ final Visibility visibility; |
+ |
+ /** |
+ * A directive/component class can publish types by using a factory |
+ * function to generate a module. The module is then installed into |
+ * the injector at that element. Any types declared in the module then |
+ * become available for injection. |
+ * |
+ * Example: |
+ * |
+ * @Decorator( |
+ * selector: '[foo]', |
+ * module: Foo.moduleFactory) |
+ * class Foo { |
+ * static moduleFactory() => new Module() |
+ * ..type(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY); |
+ * } |
+ * |
+ * When specifying types, factories or values in the module, notice that |
+ * `Visibility` maps to: |
+ * * [Directive.LOCAL_VISIBILITY] |
+ * * [Directive.CHILDREN_VISIBILITY] |
+ * * [Directive.DIRECT_CHILDREN_VISIBILITY] |
+ */ |
+ final Function module; |
/** |
* Use map to define the mapping of DOM attributes to fields. |
@@ -91,14 +168,12 @@ abstract class NgAnnotation { |
* selection="selectedItem" |
* on-selection-change="doSomething()"> |
* |
- * @NgComponent( |
+ * @Component( |
* selector: 'my-component' |
* map: const { |
* 'title': '@title', |
* 'selection': '<=>currentItem', |
- * 'on-selection-change': '&onChange' |
- * } |
- * ) |
+ * 'on-selection-change': '&onChange'}) |
* class MyComponent { |
* String title; |
* var currentItem; |
@@ -125,22 +200,24 @@ abstract class NgAnnotation { |
final Map<String, String> map; |
/** |
- * Use the list to specify expression containing attributes which are not |
- * included under [map] with '=' or '@' specification. |
+ * Use the list to specify expressions containing attributes which are not |
+ * included under [map] with '=' or '@' specification. This is used by |
+ * angular transformer during deployment. |
*/ |
final List<String> exportExpressionAttrs; |
/** |
- * Use the list to specify a expressions which are evaluated dynamically |
+ * Use the list to specify expressions which are evaluated dynamically |
* (ex. via [Scope.eval]) and are otherwise not statically discoverable. |
+ * This is used by angular transformer during deployment. |
*/ |
final List<String> exportExpressions; |
- const NgAnnotation({ |
+ const Directive({ |
this.selector, |
- this.children: NgAnnotation.COMPILE_CHILDREN, |
- this.visibility: NgDirective.LOCAL_VISIBILITY, |
- this.publishTypes: const [], |
+ this.children: Directive.COMPILE_CHILDREN, |
+ this.visibility: Directive.LOCAL_VISIBILITY, |
+ this.module, |
this.map: const {}, |
this.exportExpressions: const [], |
this.exportExpressionAttrs: const [] |
@@ -149,12 +226,15 @@ abstract class NgAnnotation { |
toString() => selector; |
get hashCode => selector.hashCode; |
operator==(other) => |
- other is NgAnnotation && this.selector == other.selector; |
+ other is Directive && selector == other.selector; |
- NgAnnotation cloneWithNewMap(newMap); |
+ Directive _cloneWithNewMap(newMap); |
} |
+bool _applyAuthorStylesDeprecationWarningPrinted = false; |
+bool _resetStyleInheritanceDeprecationWarningPrinted = false; |
+ |
/** |
* Meta-data marker placed on a class which should act as a controller for the |
* component. Angular components are a light-weight version of web-components. |
@@ -164,14 +244,14 @@ abstract class NgAnnotation { |
* ask for any injectable object in their constructor. Components |
* can also ask for other components or directives declared on the DOM element. |
* |
- * Components can implement [NgAttachAware], [NgDetachAware], |
- * [NgShadowRootAware] and declare these optional methods: |
+ * Components can implement [AttachAware], [DetachAware], |
+ * [ShadowRootAware] and declare these optional methods: |
* |
* * `attach()` - Called on first [Scope.apply()]. |
* * `detach()` - Called on when owning scope is destroyed. |
* * `onShadowRoot(ShadowRoot shadowRoot)` - Called when [ShadowRoot] is loaded. |
*/ |
-class NgComponent extends NgAnnotation { |
+class Component extends Directive { |
/** |
* Inlined HTML template for the component. |
*/ |
@@ -191,41 +271,72 @@ class NgComponent extends NgAnnotation { |
/** |
* Set the shadow root applyAuthorStyles property. See shadow-DOM |
* documentation for further details. |
+ * |
+ * This feature will be removed in Chrome 35. |
*/ |
- final bool applyAuthorStyles; |
+ @deprecated |
+ bool get applyAuthorStyles { |
+ if (!_applyAuthorStylesDeprecationWarningPrinted && _applyAuthorStyles == true) { |
+ print("WARNING applyAuthorStyles is deprecated in component $selector"); |
+ _applyAuthorStylesDeprecationWarningPrinted = true; |
+ } |
+ return _applyAuthorStyles; |
+ } |
+ final bool _applyAuthorStyles; |
/** |
* Set the shadow root resetStyleInheritance property. See shadow-DOM |
* documentation for further details. |
+ * |
+ * This feature will be removed in Chrome 35. |
*/ |
- final bool resetStyleInheritance; |
+ @deprecated |
+ bool get resetStyleInheritance { |
+ if (!_resetStyleInheritanceDeprecationWarningPrinted && _resetStyleInheritance == true) { |
+ print("WARNING resetStyleInheritance is deprecated in component $selector"); |
+ _resetStyleInheritanceDeprecationWarningPrinted = true; |
+ } |
+ return _resetStyleInheritance; |
+ } |
+ final bool _resetStyleInheritance; |
/** |
* An expression under which the component's controller instance will be |
* published into. This allows the expressions in the template to be referring |
* to controller instance and its properties. |
*/ |
+ @deprecated |
final String publishAs; |
- const NgComponent({ |
+ /** |
+ * If set to true, this component will always use shadow DOM. |
+ * If set to false, this component will never use shadow DOM. |
+ * If unset, the compiler's default construction strategy will be used |
+ */ |
+ final bool useShadowDom; |
+ |
+ const Component({ |
this.template, |
this.templateUrl, |
cssUrl, |
- this.applyAuthorStyles, |
- this.resetStyleInheritance, |
+ applyAuthorStyles, |
+ resetStyleInheritance, |
this.publishAs, |
+ module, |
map, |
selector, |
visibility, |
- publishTypes : const <Type>[], |
exportExpressions, |
- exportExpressionAttrs}) |
+ exportExpressionAttrs, |
+ this.useShadowDom}) |
: _cssUrls = cssUrl, |
+ _applyAuthorStyles = applyAuthorStyles, |
+ _resetStyleInheritance = resetStyleInheritance, |
super(selector: selector, |
- children: NgAnnotation.COMPILE_CHILDREN, |
+ children: Directive.COMPILE_CHILDREN, |
visibility: visibility, |
- publishTypes: publishTypes, |
map: map, |
+ module: module, |
exportExpressions: exportExpressions, |
exportExpressionAttrs: exportExpressionAttrs); |
@@ -233,8 +344,8 @@ class NgComponent extends NgAnnotation { |
const [] : |
_cssUrls is List ? _cssUrls : [_cssUrls]; |
- NgAnnotation cloneWithNewMap(newMap) => |
- new NgComponent( |
+ Directive _cloneWithNewMap(newMap) => |
+ new Component( |
template: template, |
templateUrl: templateUrl, |
cssUrl: cssUrls, |
@@ -242,15 +353,14 @@ class NgComponent extends NgAnnotation { |
resetStyleInheritance: resetStyleInheritance, |
publishAs: publishAs, |
map: newMap, |
+ module: module, |
selector: selector, |
visibility: visibility, |
- publishTypes: publishTypes, |
exportExpressions: exportExpressions, |
- exportExpressionAttrs: exportExpressionAttrs); |
+ exportExpressionAttrs: exportExpressionAttrs, |
+ useShadowDom: useShadowDom); |
} |
-RegExp _ATTR_NAME = new RegExp(r'\[([^\]]+)\]$'); |
- |
/** |
* Meta-data marker placed on a class which should act as a directive. |
* |
@@ -258,60 +368,58 @@ RegExp _ATTR_NAME = new RegExp(r'\[([^\]]+)\]$'); |
* ask for any injectable object in their constructor. Directives |
* can also ask for other components or directives declared on the DOM element. |
* |
- * Directives can implement [NgAttachAware], [NgDetachAware] and |
+ * Directives can implement [AttachAware], [DetachAware] and |
* declare these optional methods: |
* |
* * `attach()` - Called on first [Scope.apply()]. |
* * `detach()` - Called on when owning scope is destroyed. |
*/ |
-class NgDirective extends NgAnnotation { |
- static const String LOCAL_VISIBILITY = 'local'; |
- static const String CHILDREN_VISIBILITY = 'children'; |
- static const String DIRECT_CHILDREN_VISIBILITY = 'direct_children'; |
- |
- const NgDirective({children: NgAnnotation.COMPILE_CHILDREN, |
+class Decorator extends Directive { |
+ const Decorator({children: Directive.COMPILE_CHILDREN, |
map, |
selector, |
+ module, |
visibility, |
- publishTypes : const <Type>[], |
exportExpressions, |
- exportExpressionAttrs}) : super(selector: selector, children: children, visibility: visibility, |
- publishTypes: publishTypes, map: map, |
- exportExpressions: exportExpressions, |
- exportExpressionAttrs: exportExpressionAttrs); |
- |
- NgAnnotation cloneWithNewMap(newMap) => |
- new NgDirective( |
+ exportExpressionAttrs}) |
+ : super(selector: selector, |
+ children: children, |
+ visibility: visibility, |
+ map: map, |
+ module: module, |
+ exportExpressions: exportExpressions, |
+ exportExpressionAttrs: exportExpressionAttrs); |
+ |
+ Directive _cloneWithNewMap(newMap) => |
+ new Decorator( |
children: children, |
map: newMap, |
+ module: module, |
selector: selector, |
visibility: visibility, |
- publishTypes: publishTypes, |
exportExpressions: exportExpressions, |
exportExpressionAttrs: exportExpressionAttrs); |
} |
/** |
- * Meta-data marker placed on a class which should act as a controller for your application. |
+ * Meta-data marker placed on a class which should act as a controller for your |
+ * application. |
* |
- * Controllers are essentially [NgDirective]s with few key differences: |
+ * Controllers are essentially [Decorator]s with few key differences: |
* |
* * Controllers create a new scope at the element. |
* * Controllers should not do any DOM manipulation. |
* * Controllers are meant for application-logic |
- * (rather then DOM monipulation logic which directives are meant for.) |
+ * (rather then DOM manipulation logic which directives are meant for.) |
* |
- * Controllers can implement [NgAttachAware], [NgDetachAware] and |
+ * Controllers can implement [AttachAware], [DetachAware] and |
* declare these optional methods: |
* |
* * `attach()` - Called on first [Scope.apply()]. |
* * `detach()` - Called on when owning scope is destroyed. |
*/ |
-class NgController extends NgDirective { |
- static const String LOCAL_VISIBILITY = 'local'; |
- static const String CHILDREN_VISIBILITY = 'children'; |
- static const String DIRECT_CHILDREN_VISIBILITY = 'direct_children'; |
- |
+@deprecated |
+class Controller extends Decorator { |
/** |
* An expression under which the controller instance will be published into. |
* This allows the expressions in the template to be referring to controller |
@@ -319,36 +427,45 @@ class NgController extends NgDirective { |
*/ |
final String publishAs; |
- const NgController({ |
- children: NgAnnotation.COMPILE_CHILDREN, |
+ const Controller({ |
+ children: Directive.COMPILE_CHILDREN, |
this.publishAs, |
map, |
+ module, |
selector, |
visibility, |
- publishTypes : const <Type>[], |
exportExpressions, |
exportExpressionAttrs |
- }) : super(selector: selector, children: children, visibility: visibility, |
- publishTypes: publishTypes, map: map, |
- exportExpressions: exportExpressions, |
- exportExpressionAttrs: exportExpressionAttrs); |
- |
- NgAnnotation cloneWithNewMap(newMap) => |
- new NgController( |
+ }) |
+ : super(selector: selector, |
+ children: children, |
+ visibility: visibility, |
+ map: map, |
+ module: module, |
+ exportExpressions: exportExpressions, |
+ exportExpressionAttrs: exportExpressionAttrs); |
+ |
+ Directive _cloneWithNewMap(newMap) => |
+ new Controller( |
children: children, |
publishAs: publishAs, |
+ module: module, |
map: newMap, |
selector: selector, |
visibility: visibility, |
- publishTypes: publishTypes, |
exportExpressions: exportExpressions, |
exportExpressionAttrs: exportExpressionAttrs); |
} |
-abstract class AttrFieldAnnotation { |
+/** |
+ * Abstract supper class of [NgAttr], [NgCallback], [NgOneWay], [NgOneWayOneTime], and [NgTwoWay]. |
+ */ |
+abstract class DirectiveAnnotation { |
+ /// Element attribute name |
final String attrName; |
- const AttrFieldAnnotation(this.attrName); |
- String get mappingSpec; |
+ const DirectiveAnnotation(this.attrName); |
+ /// Element attribute mapping mode: `@`, `=>`, `=>!`, `<=>`, and `&`. |
+ String get _mappingSpec; |
} |
/** |
@@ -357,70 +474,108 @@ abstract class AttrFieldAnnotation { |
* The value of the attribute to be treated as a string, equivalent |
* to `@` specification. |
*/ |
-class NgAttr extends AttrFieldAnnotation { |
- final mappingSpec = '@'; |
+@deprecated |
+class NgAttr extends DirectiveAnnotation { |
+ final _mappingSpec = '@'; |
const NgAttr(String attrName) : super(attrName); |
} |
/** |
* When applied as an annotation on a directive field specifies that |
* the field is to be mapped to DOM attribute with the provided [attrName]. |
- * The value of the attribute to be treated as a one-way expession, equivalent |
+ * The value of the attribute to be treated as a one-way expression, equivalent |
* to `=>` specification. |
*/ |
-class NgOneWay extends AttrFieldAnnotation { |
- final mappingSpec = '=>'; |
+@deprecated |
+class NgOneWay extends DirectiveAnnotation { |
+ final _mappingSpec = '=>'; |
const NgOneWay(String attrName) : super(attrName); |
} |
/** |
* When applied as an annotation on a directive field specifies that |
* the field is to be mapped to DOM attribute with the provided [attrName]. |
- * The value of the attribute to be treated as a one time one-way expession, |
+ * The value of the attribute to be treated as a one time one-way expression, |
* equivalent to `=>!` specification. |
*/ |
-class NgOneWayOneTime extends AttrFieldAnnotation { |
- final mappingSpec = '=>!'; |
+@deprecated |
+class NgOneWayOneTime extends DirectiveAnnotation { |
+ final _mappingSpec = '=>!'; |
const NgOneWayOneTime(String attrName) : super(attrName); |
} |
/** |
* When applied as an annotation on a directive field specifies that |
* the field is to be mapped to DOM attribute with the provided [attrName]. |
- * The value of the attribute to be treated as a two-way expession, |
+ * The value of the attribute to be treated as a two-way expression, |
* equivalent to `<=>` specification. |
*/ |
-class NgTwoWay extends AttrFieldAnnotation { |
- final mappingSpec = '<=>'; |
+@deprecated |
+class NgTwoWay extends DirectiveAnnotation { |
+ final _mappingSpec = '<=>'; |
const NgTwoWay(String attrName) : super(attrName); |
} |
/** |
* When applied as an annotation on a directive field specifies that |
* the field is to be mapped to DOM attribute with the provided [attrName]. |
- * The value of the attribute to be treated as a callback expession, |
+ * The value of the attribute to be treated as a callback expression, |
* equivalent to `&` specification. |
*/ |
-class NgCallback extends AttrFieldAnnotation { |
- final mappingSpec = '&'; |
+@deprecated |
+class NgCallback extends DirectiveAnnotation { |
+ final _mappingSpec = '&'; |
const NgCallback(String attrName) : super(attrName); |
} |
/** |
- * Implementing directives or components [attach] method will be called when |
- * the next scope digest occurs after component instantiation. It is guaranteed |
- * that when [attach] is invoked, that all attribute mappings have already |
- * been processed. |
+ * A directives or components may chose to implements [AttachAware].[attach] method. |
+ * If implemented the method will be called when the next scope digest occurs after |
+ * component instantiation. It is guaranteed that when [attach] is invoked, that all |
+ * attribute mappings have already been processed. |
*/ |
-abstract class NgAttachAware { |
+abstract class AttachAware { |
void attach(); |
} |
/** |
- * Implementing directives or components [detach] method will be called when |
- * the associated scope is destroyed. |
+ * A directives or components may chose to implements [DetachAware].[detach] method. |
+ * If implemented the method will be called when the next associated scope is destroyed. |
*/ |
-abstract class NgDetachAware { |
+abstract class DetachAware { |
void detach(); |
} |
+/** |
+ * Use @[Formatter] annotation to register a new formatter. A formatter is a class |
+ * with a [call] method (a callable function). |
+ * |
+ * Usage: |
+ * |
+ * // Declaration |
+ * @Formatter(name:'myFilter') |
+ * class MyFilter { |
+ * call(valueToFilter, optArg1, optArg2) { |
+ * return ...; |
+ * } |
+ * } |
+ * |
+ * |
+ * // Registration |
+ * var module = ...; |
+ * module.type(MyFilter); |
+ * |
+ * |
+ * <!-- Usage --> |
+ * <span>{{something | myFilter:arg1:arg2}}</span> |
+ */ |
+class Formatter { |
+ final String name; |
+ |
+ const Formatter({this.name}); |
+ |
+ int get hashCode => name.hashCode; |
+ bool operator==(other) => name == other.name; |
+ |
+ toString() => 'Formatter: $name'; |
+} |