Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: third_party/pkg/angular/lib/core/annotation_src.dart

Issue 256553002: Revert "Update all Angular libs (run update_all.sh)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library angular.core.annotation_src;
2
3 import "package:di/di.dart" show Injector, Visibility;
4
5 RegExp _ATTR_NAME = new RegExp(r'\[([^\]]+)\]$');
6
7 const String SHADOW_DOM_INJECTOR_NAME = 'SHADOW_INJECTOR';
8
9 skipShadow(Injector injector)
10 => injector.name == SHADOW_DOM_INJECTOR_NAME ? injector.parent : injector;
11
12 localVisibility (Injector requesting, Injector defining)
13 => identical(skipShadow(requesting), defining);
14
15 directChildrenVisibility(Injector requesting, Injector defining) {
16 requesting = skipShadow(requesting);
17 return identical(requesting.parent, defining) || localVisibility(requesting, d efining);
18 }
19
20 Directive cloneWithNewMap(Directive annotation, map)
21 => annotation._cloneWithNewMap(map);
22
23 String mappingSpec(DirectiveAnnotation annotation) => annotation._mappingSpec;
24
25
26 /**
27 * An annotation when applied to a class indicates that the class (service) will
28 * be instantiated by di injector. This annotation is also used to designate whi ch
29 * classes need to have a static factory generated when using static angular, an d
30 * therefore is required on any injectable class.
31 */
32 class Injectable {
33 const Injectable();
34 }
35
36 /**
37 * Abstract supper class of [Controller], [Component], and [Decorator].
38 */
39 abstract class Directive {
40
41 /// The directive can only be injected to other directives on the same element .
42 static const Visibility LOCAL_VISIBILITY = localVisibility;
43
44 /// The directive can be injected to other directives on the same or child ele ments.
45 static const Visibility CHILDREN_VISIBILITY = null;
46
47 /**
48 * The directive on this element can only be injected to other directives
49 * declared on elements which are direct children of the current element.
50 */
51 static const Visibility DIRECT_CHILDREN_VISIBILITY = directChildrenVisibility;
52
53 /**
54 * CSS selector which will trigger this component/directive.
55 * CSS Selectors are limited to a single element and can contain:
56 *
57 * * `element-name` limit to a given element name.
58 * * `.class` limit to an element with a given class.
59 * * `[attribute]` limit to an element with a given attribute name.
60 * * `[attribute=value]` limit to an element with a given attribute and value.
61 * * `:contains(/abc/)` limit to an element which contains the given text.
62 *
63 *
64 * Example: `input[type=checkbox][ng-model]`
65 */
66 final String selector;
67
68 /**
69 * Specifies the compiler action to be taken on the child nodes of the
70 * element which this currently being compiled. The values are:
71 *
72 * * [COMPILE_CHILDREN] (*default*)
73 * * [TRANSCLUDE_CHILDREN]
74 * * [IGNORE_CHILDREN]
75 */
76 @deprecated
77 final String children;
78
79 /**
80 * Compile the child nodes of the element. This is the default.
81 */
82 @deprecated
83 static const String COMPILE_CHILDREN = 'compile';
84 /**
85 * Compile the child nodes for transclusion and makes available
86 * [BoundViewFactory], [ViewFactory] and [ViewPort] for injection.
87 */
88 @deprecated
89 static const String TRANSCLUDE_CHILDREN = 'transclude';
90 /**
91 * Do not compile/visit the child nodes. Angular markup on descendant nodes
92 * will not be processed.
93 */
94 @deprecated
95 static const String IGNORE_CHILDREN = 'ignore';
96
97 /**
98 * A directive/component controller class can be injected into other
99 * directives/components. This attribute controls whether the
100 * controller is available to others.
101 *
102 * * `local` [Directive.LOCAL_VISIBILITY] - the controller can be injected
103 * into other directives / components on the same DOM element.
104 * * `children` [Directive.CHILDREN_VISIBILITY] - the controller can be
105 * injected into other directives / components on the same or child DOM
106 * elements.
107 * * `direct_children` [Directive.DIRECT_CHILDREN_VISIBILITY] - the
108 * controller can be injected into other directives / components on the
109 * direct children of the current DOM element.
110 */
111 final Visibility visibility;
112
113 /**
114 * A directive/component class can publish types by using a factory
115 * function to generate a module. The module is then installed into
116 * the injector at that element. Any types declared in the module then
117 * become available for injection.
118 *
119 * Example:
120 *
121 * @Decorator(
122 * selector: '[foo]',
123 * module: Foo.moduleFactory)
124 * class Foo {
125 * static moduleFactory() => new Module()
126 * ..type(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY);
127 * }
128 *
129 * When specifying types, factories or values in the module, notice that
130 * `Visibility` maps to:
131 * * [Directive.LOCAL_VISIBILITY]
132 * * [Directive.CHILDREN_VISIBILITY]
133 * * [Directive.DIRECT_CHILDREN_VISIBILITY]
134 */
135 final Function module;
136
137 /**
138 * Use map to define the mapping of DOM attributes to fields.
139 * The map's key is the DOM attribute name (DOM attribute is in dash-case).
140 * The Map's value consists of a mode prefix followed by an expression.
141 * The destination expression will be evaluated against the instance of the
142 * directive / component class.
143 *
144 * * `@` - Map the DOM attribute string. The attribute string will be taken
145 * literally or interpolated if it contains binding {{}} systax and assigned
146 * to the expression. (cost: 0 watches)
147 *
148 * * `=>` - Treat the DOM attribute value as an expression. Set up a watch,
149 * which will read the expression in the attribute and assign the value
150 * to destination expression. (cost: 1 watch)
151 *
152 * * `<=>` - Treat the DOM attribute value as an expression. Set up a watch
153 * on both outside as well as component scope to keep the src and
154 * destination in sync. (cost: 2 watches)
155 *
156 * * `=>!` - Treat the DOM attribute value as an expression. Set up a one time
157 * watch on expression. Once the expression turns truthy it will no longer
158 * update. (cost: 1 watches until not null, then 0 watches)
159 *
160 * * `&` - Treat the DOM attribute value as an expression. Assign a closure
161 * function into the field. This allows the component to control
162 * the invocation of the closure. This is useful for passing
163 * expressions into controllers which act like callbacks. (cost: 0 watches)
164 *
165 * Example:
166 *
167 * <my-component title="Hello {{username}}"
168 * selection="selectedItem"
169 * on-selection-change="doSomething()">
170 *
171 * @Component(
172 * selector: 'my-component'
173 * map: const {
174 * 'title': '@title',
175 * 'selection': '<=>currentItem',
176 * 'on-selection-change': '&onChange'})
177 * class MyComponent {
178 * String title;
179 * var currentItem;
180 * ParsedFn onChange;
181 * }
182 *
183 * The above example shows how all three mapping modes are used.
184 *
185 * * `@title` maps the title DOM attribute to the controller `title`
186 * field. Notice that this maps the content of the attribute, which
187 * means that it can be used with `{{}}` interpolation.
188 *
189 * * `<=>currentItem` maps the expression (in this case the `selectedItem`
190 * in the current scope into the `currentItem` in the controller. Notice
191 * that mapping is bi-directional. A change either in field or on
192 * parent scope will result in change to the other.
193 *
194 * * `&onChange` maps the expression into the controller `onChange`
195 * field. The result of mapping is a callable function which can be
196 * invoked at any time by the controller. The invocation of the
197 * callable function will result in the expression `doSomething()` to
198 * be executed in the parent context.
199 */
200 final Map<String, String> map;
201
202 /**
203 * Use the list to specify expressions containing attributes which are not
204 * included under [map] with '=' or '@' specification. This is used by
205 * angular transformer during deployment.
206 */
207 final List<String> exportExpressionAttrs;
208
209 /**
210 * Use the list to specify expressions which are evaluated dynamically
211 * (ex. via [Scope.eval]) and are otherwise not statically discoverable.
212 * This is used by angular transformer during deployment.
213 */
214 final List<String> exportExpressions;
215
216 const Directive({
217 this.selector,
218 this.children: Directive.COMPILE_CHILDREN,
219 this.visibility: Directive.LOCAL_VISIBILITY,
220 this.module,
221 this.map: const {},
222 this.exportExpressions: const [],
223 this.exportExpressionAttrs: const []
224 });
225
226 toString() => selector;
227 get hashCode => selector.hashCode;
228 operator==(other) =>
229 other is Directive && selector == other.selector;
230
231 Directive _cloneWithNewMap(newMap);
232 }
233
234
235 bool _applyAuthorStylesDeprecationWarningPrinted = false;
236 bool _resetStyleInheritanceDeprecationWarningPrinted = false;
237
238 /**
239 * Meta-data marker placed on a class which should act as a controller for the
240 * component. Angular components are a light-weight version of web-components.
241 * Angular components use shadow-DOM for rendering their templates.
242 *
243 * Angular components are instantiated using dependency injection, and can
244 * ask for any injectable object in their constructor. Components
245 * can also ask for other components or directives declared on the DOM element.
246 *
247 * Components can implement [AttachAware], [DetachAware],
248 * [ShadowRootAware] and declare these optional methods:
249 *
250 * * `attach()` - Called on first [Scope.apply()].
251 * * `detach()` - Called on when owning scope is destroyed.
252 * * `onShadowRoot(ShadowRoot shadowRoot)` - Called when [ShadowRoot] is loaded.
253 */
254 class Component extends Directive {
255 /**
256 * Inlined HTML template for the component.
257 */
258 final String template;
259
260 /**
261 * A URL to HTML template. This will be loaded asynchronously and
262 * cached for future component instances.
263 */
264 final String templateUrl;
265
266 /**
267 * A list of CSS URLs to load into the shadow DOM.
268 */
269 final _cssUrls;
270
271 /**
272 * Set the shadow root applyAuthorStyles property. See shadow-DOM
273 * documentation for further details.
274 *
275 * This feature will be removed in Chrome 35.
276 */
277 @deprecated
278 bool get applyAuthorStyles {
279 if (!_applyAuthorStylesDeprecationWarningPrinted && _applyAuthorStyles == tr ue) {
280 print("WARNING applyAuthorStyles is deprecated in component $selector");
281 _applyAuthorStylesDeprecationWarningPrinted = true;
282 }
283 return _applyAuthorStyles;
284 }
285 final bool _applyAuthorStyles;
286
287 /**
288 * Set the shadow root resetStyleInheritance property. See shadow-DOM
289 * documentation for further details.
290 *
291 * This feature will be removed in Chrome 35.
292 */
293 @deprecated
294 bool get resetStyleInheritance {
295 if (!_resetStyleInheritanceDeprecationWarningPrinted && _resetStyleInheritan ce == true) {
296 print("WARNING resetStyleInheritance is deprecated in component $selector" );
297 _resetStyleInheritanceDeprecationWarningPrinted = true;
298 }
299 return _resetStyleInheritance;
300 }
301 final bool _resetStyleInheritance;
302
303 /**
304 * An expression under which the component's controller instance will be
305 * published into. This allows the expressions in the template to be referring
306 * to controller instance and its properties.
307 */
308 @deprecated
309 final String publishAs;
310
311 /**
312 * If set to true, this component will always use shadow DOM.
313 * If set to false, this component will never use shadow DOM.
314 * If unset, the compiler's default construction strategy will be used
315 */
316 final bool useShadowDom;
317
318 const Component({
319 this.template,
320 this.templateUrl,
321 cssUrl,
322 applyAuthorStyles,
323 resetStyleInheritance,
324 this.publishAs,
325 module,
326 map,
327 selector,
328 visibility,
329 exportExpressions,
330 exportExpressionAttrs,
331 this.useShadowDom})
332 : _cssUrls = cssUrl,
333 _applyAuthorStyles = applyAuthorStyles,
334 _resetStyleInheritance = resetStyleInheritance,
335 super(selector: selector,
336 children: Directive.COMPILE_CHILDREN,
337 visibility: visibility,
338 map: map,
339 module: module,
340 exportExpressions: exportExpressions,
341 exportExpressionAttrs: exportExpressionAttrs);
342
343 List<String> get cssUrls => _cssUrls == null ?
344 const [] :
345 _cssUrls is List ? _cssUrls : [_cssUrls];
346
347 Directive _cloneWithNewMap(newMap) =>
348 new Component(
349 template: template,
350 templateUrl: templateUrl,
351 cssUrl: cssUrls,
352 applyAuthorStyles: applyAuthorStyles,
353 resetStyleInheritance: resetStyleInheritance,
354 publishAs: publishAs,
355 map: newMap,
356 module: module,
357 selector: selector,
358 visibility: visibility,
359 exportExpressions: exportExpressions,
360 exportExpressionAttrs: exportExpressionAttrs,
361 useShadowDom: useShadowDom);
362 }
363
364 /**
365 * Meta-data marker placed on a class which should act as a directive.
366 *
367 * Angular directives are instantiated using dependency injection, and can
368 * ask for any injectable object in their constructor. Directives
369 * can also ask for other components or directives declared on the DOM element.
370 *
371 * Directives can implement [AttachAware], [DetachAware] and
372 * declare these optional methods:
373 *
374 * * `attach()` - Called on first [Scope.apply()].
375 * * `detach()` - Called on when owning scope is destroyed.
376 */
377 class Decorator extends Directive {
378 const Decorator({children: Directive.COMPILE_CHILDREN,
379 map,
380 selector,
381 module,
382 visibility,
383 exportExpressions,
384 exportExpressionAttrs})
385 : super(selector: selector,
386 children: children,
387 visibility: visibility,
388 map: map,
389 module: module,
390 exportExpressions: exportExpressions,
391 exportExpressionAttrs: exportExpressionAttrs);
392
393 Directive _cloneWithNewMap(newMap) =>
394 new Decorator(
395 children: children,
396 map: newMap,
397 module: module,
398 selector: selector,
399 visibility: visibility,
400 exportExpressions: exportExpressions,
401 exportExpressionAttrs: exportExpressionAttrs);
402 }
403
404 /**
405 * Meta-data marker placed on a class which should act as a controller for your
406 * application.
407 *
408 * Controllers are essentially [Decorator]s with few key differences:
409 *
410 * * Controllers create a new scope at the element.
411 * * Controllers should not do any DOM manipulation.
412 * * Controllers are meant for application-logic
413 * (rather then DOM manipulation logic which directives are meant for.)
414 *
415 * Controllers can implement [AttachAware], [DetachAware] and
416 * declare these optional methods:
417 *
418 * * `attach()` - Called on first [Scope.apply()].
419 * * `detach()` - Called on when owning scope is destroyed.
420 */
421 @deprecated
422 class Controller extends Decorator {
423 /**
424 * An expression under which the controller instance will be published into.
425 * This allows the expressions in the template to be referring to controller
426 * instance and its properties.
427 */
428 final String publishAs;
429
430 const Controller({
431 children: Directive.COMPILE_CHILDREN,
432 this.publishAs,
433 map,
434 module,
435 selector,
436 visibility,
437 exportExpressions,
438 exportExpressionAttrs
439 })
440 : super(selector: selector,
441 children: children,
442 visibility: visibility,
443 map: map,
444 module: module,
445 exportExpressions: exportExpressions,
446 exportExpressionAttrs: exportExpressionAttrs);
447
448 Directive _cloneWithNewMap(newMap) =>
449 new Controller(
450 children: children,
451 publishAs: publishAs,
452 module: module,
453 map: newMap,
454 selector: selector,
455 visibility: visibility,
456 exportExpressions: exportExpressions,
457 exportExpressionAttrs: exportExpressionAttrs);
458 }
459
460 /**
461 * Abstract supper class of [NgAttr], [NgCallback], [NgOneWay], [NgOneWayOneTime ], and [NgTwoWay].
462 */
463 abstract class DirectiveAnnotation {
464 /// Element attribute name
465 final String attrName;
466 const DirectiveAnnotation(this.attrName);
467 /// Element attribute mapping mode: `@`, `=>`, `=>!`, `<=>`, and `&`.
468 String get _mappingSpec;
469 }
470
471 /**
472 * When applied as an annotation on a directive field specifies that
473 * the field is to be mapped to DOM attribute with the provided [attrName].
474 * The value of the attribute to be treated as a string, equivalent
475 * to `@` specification.
476 */
477 @deprecated
478 class NgAttr extends DirectiveAnnotation {
479 final _mappingSpec = '@';
480 const NgAttr(String attrName) : super(attrName);
481 }
482
483 /**
484 * When applied as an annotation on a directive field specifies that
485 * the field is to be mapped to DOM attribute with the provided [attrName].
486 * The value of the attribute to be treated as a one-way expression, equivalent
487 * to `=>` specification.
488 */
489 @deprecated
490 class NgOneWay extends DirectiveAnnotation {
491 final _mappingSpec = '=>';
492 const NgOneWay(String attrName) : super(attrName);
493 }
494
495 /**
496 * When applied as an annotation on a directive field specifies that
497 * the field is to be mapped to DOM attribute with the provided [attrName].
498 * The value of the attribute to be treated as a one time one-way expression,
499 * equivalent to `=>!` specification.
500 */
501 @deprecated
502 class NgOneWayOneTime extends DirectiveAnnotation {
503 final _mappingSpec = '=>!';
504 const NgOneWayOneTime(String attrName) : super(attrName);
505 }
506
507 /**
508 * When applied as an annotation on a directive field specifies that
509 * the field is to be mapped to DOM attribute with the provided [attrName].
510 * The value of the attribute to be treated as a two-way expression,
511 * equivalent to `<=>` specification.
512 */
513 @deprecated
514 class NgTwoWay extends DirectiveAnnotation {
515 final _mappingSpec = '<=>';
516 const NgTwoWay(String attrName) : super(attrName);
517 }
518
519 /**
520 * When applied as an annotation on a directive field specifies that
521 * the field is to be mapped to DOM attribute with the provided [attrName].
522 * The value of the attribute to be treated as a callback expression,
523 * equivalent to `&` specification.
524 */
525 @deprecated
526 class NgCallback extends DirectiveAnnotation {
527 final _mappingSpec = '&';
528 const NgCallback(String attrName) : super(attrName);
529 }
530
531 /**
532 * A directives or components may chose to implements [AttachAware].[attach] met hod.
533 * If implemented the method will be called when the next scope digest occurs af ter
534 * component instantiation. It is guaranteed that when [attach] is invoked, that all
535 * attribute mappings have already been processed.
536 */
537 abstract class AttachAware {
538 void attach();
539 }
540
541 /**
542 * A directives or components may chose to implements [DetachAware].[detach] met hod.
543 * If implemented the method will be called when the next associated scope is de stroyed.
544 */
545 abstract class DetachAware {
546 void detach();
547 }
548
549 /**
550 * Use @[Formatter] annotation to register a new formatter. A formatter is a cla ss
551 * with a [call] method (a callable function).
552 *
553 * Usage:
554 *
555 * // Declaration
556 * @Formatter(name:'myFilter')
557 * class MyFilter {
558 * call(valueToFilter, optArg1, optArg2) {
559 * return ...;
560 * }
561 * }
562 *
563 *
564 * // Registration
565 * var module = ...;
566 * module.type(MyFilter);
567 *
568 *
569 * <!-- Usage -->
570 * <span>{{something | myFilter:arg1:arg2}}</span>
571 */
572 class Formatter {
573 final String name;
574
575 const Formatter({this.name});
576
577 int get hashCode => name.hashCode;
578 bool operator==(other) => name == other.name;
579
580 toString() => 'Formatter: $name';
581 }
OLDNEW
« no previous file with comments | « third_party/pkg/angular/lib/core/annotation.dart ('k') | third_party/pkg/angular/lib/core/cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698