chore(packaging): move files to match target file structure
This commit is contained in:
29
modules/angular2/src/directives/ng_if.js
vendored
Normal file
29
modules/angular2/src/directives/ng_if.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
import {Template} from 'core/src/annotations/annotations';
|
||||
import {ViewPort} from 'core/src/compiler/viewport';
|
||||
import {isBlank} from 'facade/src/lang';
|
||||
|
||||
@Template({
|
||||
selector: '[ng-if]',
|
||||
bind: {
|
||||
'ng-if': 'condition'
|
||||
}
|
||||
})
|
||||
export class NgIf {
|
||||
viewPort: ViewPort;
|
||||
prevCondition: boolean;
|
||||
|
||||
constructor(viewPort: ViewPort) {
|
||||
this.viewPort = viewPort;
|
||||
this.prevCondition = null;
|
||||
}
|
||||
|
||||
set condition(newCondition) {
|
||||
if (newCondition && (isBlank(this.prevCondition) || !this.prevCondition)) {
|
||||
this.prevCondition = true;
|
||||
this.viewPort.create();
|
||||
} else if (!newCondition && (isBlank(this.prevCondition) || this.prevCondition)) {
|
||||
this.prevCondition = false;
|
||||
this.viewPort.clear();
|
||||
}
|
||||
}
|
||||
}
|
8
modules/angular2/src/directives/ng_non_bindable.js
vendored
Normal file
8
modules/angular2/src/directives/ng_non_bindable.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import {Decorator} from 'core/src/annotations/annotations';
|
||||
|
||||
@Decorator({
|
||||
selector: '[ng-non-bindable]',
|
||||
compileChildren: false
|
||||
})
|
||||
export class NgNonBindable {
|
||||
}
|
93
modules/angular2/src/directives/ng_repeat.js
vendored
Normal file
93
modules/angular2/src/directives/ng_repeat.js
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
import {Template} from 'core/src/annotations/annotations';
|
||||
import {OnChange} from 'core/src/compiler/interfaces';
|
||||
import {ViewPort} from 'core/src/compiler/viewport';
|
||||
import {View} from 'core/src/compiler/view';
|
||||
import {isPresent, isBlank} from 'facade/src/lang';
|
||||
import {ListWrapper} from 'facade/src/collection';
|
||||
|
||||
@Template({
|
||||
selector: '[ng-repeat]',
|
||||
bind: {
|
||||
'in': 'iterable[]'
|
||||
}
|
||||
})
|
||||
export class NgRepeat extends OnChange {
|
||||
viewPort: ViewPort;
|
||||
iterable;
|
||||
constructor(viewPort: ViewPort) {
|
||||
this.viewPort = viewPort;
|
||||
}
|
||||
onChange(changes) {
|
||||
var iteratorChanges = changes['iterable'];
|
||||
if (isBlank(iteratorChanges) || isBlank(iteratorChanges.currentValue)) {
|
||||
this.viewPort.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(rado): check if change detection can produce a change record that is
|
||||
// easier to consume than current.
|
||||
var recordViewTuples = [];
|
||||
iteratorChanges.currentValue.forEachRemovedItem(
|
||||
(removedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(removedRecord, null))
|
||||
);
|
||||
|
||||
iteratorChanges.currentValue.forEachMovedItem(
|
||||
(movedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(movedRecord, null))
|
||||
);
|
||||
|
||||
var insertTuples = NgRepeat.bulkRemove(recordViewTuples, this.viewPort);
|
||||
|
||||
iteratorChanges.currentValue.forEachAddedItem(
|
||||
(addedRecord) => ListWrapper.push(insertTuples, new RecordViewTuple(addedRecord, null))
|
||||
);
|
||||
|
||||
NgRepeat.bulkInsert(insertTuples, this.viewPort);
|
||||
|
||||
for (var i = 0; i < insertTuples.length; i++) {
|
||||
this.perViewChange(insertTuples[i].view, insertTuples[i].record);
|
||||
}
|
||||
}
|
||||
|
||||
perViewChange(view, record) {
|
||||
view.setLocal('\$implicit', record.item);
|
||||
view.setLocal('index', record.currentIndex);
|
||||
}
|
||||
|
||||
static bulkRemove(tuples, viewPort) {
|
||||
tuples.sort((a, b) => a.record.previousIndex - b.record.previousIndex);
|
||||
var movedTuples = [];
|
||||
for (var i = tuples.length - 1; i >= 0; i--) {
|
||||
var tuple = tuples[i];
|
||||
// separate moved views from removed views.
|
||||
if (isPresent(tuple.record.currentIndex)) {
|
||||
tuple.view = viewPort.detach(tuple.record.previousIndex);
|
||||
ListWrapper.push(movedTuples, tuple);
|
||||
} else {
|
||||
viewPort.remove(tuple.record.previousIndex);
|
||||
}
|
||||
}
|
||||
return movedTuples;
|
||||
}
|
||||
|
||||
static bulkInsert(tuples, viewPort) {
|
||||
tuples.sort((a, b) => a.record.currentIndex - b.record.currentIndex);
|
||||
for (var i = 0; i < tuples.length; i++) {
|
||||
var tuple = tuples[i];
|
||||
if (isPresent(tuple.view)) {
|
||||
viewPort.insert(tuple.view, tuple.record.currentIndex);
|
||||
} else {
|
||||
tuple.view = viewPort.create(tuple.record.currentIndex);
|
||||
}
|
||||
}
|
||||
return tuples;
|
||||
}
|
||||
}
|
||||
|
||||
class RecordViewTuple {
|
||||
view: View;
|
||||
record: any;
|
||||
constructor(record, view) {
|
||||
this.record = record;
|
||||
this.view = view;
|
||||
}
|
||||
}
|
190
modules/angular2/src/directives/ng_switch.js
vendored
Normal file
190
modules/angular2/src/directives/ng_switch.js
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
import {Decorator, Template} from 'core/src/annotations/annotations';
|
||||
import {ViewPort} from 'core/src/compiler/viewport';
|
||||
import {NgElement} from 'core/src/dom/element';
|
||||
import {DOM} from 'facade/src/dom';
|
||||
import {isPresent, isBlank} from 'facade/src/lang';
|
||||
import {ListWrapper, List, MapWrapper, Map} from 'facade/src/collection';
|
||||
import {Parent} from 'core/src/annotations/visibility';
|
||||
|
||||
/**
|
||||
* The `ngSwitch` directive is used to conditionally swap DOM structure on your template based on a
|
||||
* scope expression.
|
||||
* Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchDefault` directives will be
|
||||
* preserved at the location as specified in the template.
|
||||
*
|
||||
* `ngSwitch` simply chooses nested elements and makes them visible based on which element matches
|
||||
* the value obtained from the evaluated expression. In other words, you define a container element
|
||||
* (where you place the directive), place an expression on the **`[ng-switch]="..."` attribute**),
|
||||
* define any inner elements inside of the directive and place a `[ng-switch-when]` attribute per
|
||||
* element.
|
||||
* The when attribute is used to inform ngSwitch which element to display when the expression is
|
||||
* evaluated. If a matching expression is not found via a when attribute then an element with the
|
||||
* default attribute is displayed.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* <ANY [ng-switch]="expression">
|
||||
* <template [ng-switch-when]="whenExpression1">...</template>
|
||||
* <template [ng-switch-when]="whenExpression1">...</template>
|
||||
* <template [ng-switch-default]>...</template>
|
||||
* </ANY>
|
||||
* ```
|
||||
*/
|
||||
@Decorator({
|
||||
selector: '[ng-switch]',
|
||||
bind: {
|
||||
'ng-switch': 'value'
|
||||
}
|
||||
})
|
||||
export class NgSwitch {
|
||||
_switchValue: any;
|
||||
_useDefault: boolean;
|
||||
_valueViewPorts: Map;
|
||||
_activeViewPorts: List;
|
||||
|
||||
constructor() {
|
||||
this._valueViewPorts = MapWrapper.create();
|
||||
this._activeViewPorts = ListWrapper.create();
|
||||
this._useDefault = false;
|
||||
}
|
||||
|
||||
set value(value) {
|
||||
// Remove the currently active viewports
|
||||
this._removeAllActiveViewPorts();
|
||||
|
||||
// Add the viewports matching the value (with a fallback to default)
|
||||
this._useDefault = false;
|
||||
var viewPorts = MapWrapper.get(this._valueViewPorts, value);
|
||||
if (isBlank(viewPorts)) {
|
||||
this._useDefault = true;
|
||||
viewPorts = MapWrapper.get(this._valueViewPorts, _whenDefault);
|
||||
}
|
||||
this._activateViewPorts(viewPorts);
|
||||
|
||||
this._switchValue = value;
|
||||
}
|
||||
|
||||
_onWhenValueChanged(oldWhen, newWhen, viewPort: ViewPort) {
|
||||
this._deregisterViewPort(oldWhen, viewPort);
|
||||
this._registerViewPort(newWhen, viewPort);
|
||||
|
||||
if (oldWhen === this._switchValue) {
|
||||
viewPort.remove();
|
||||
ListWrapper.remove(this._activeViewPorts, viewPort);
|
||||
} else if (newWhen === this._switchValue) {
|
||||
if (this._useDefault) {
|
||||
this._useDefault = false;
|
||||
this._removeAllActiveViewPorts();
|
||||
}
|
||||
viewPort.create();
|
||||
ListWrapper.push(this._activeViewPorts, viewPort);
|
||||
}
|
||||
|
||||
// Switch to default when there is no more active viewports
|
||||
if (this._activeViewPorts.length === 0 && !this._useDefault) {
|
||||
this._useDefault = true;
|
||||
this._activateViewPorts(MapWrapper.get(this._valueViewPorts, _whenDefault));
|
||||
}
|
||||
}
|
||||
|
||||
_removeAllActiveViewPorts() {
|
||||
var activeViewPorts = this._activeViewPorts;
|
||||
for (var i = 0; i < activeViewPorts.length; i++) {
|
||||
activeViewPorts[i].remove();
|
||||
}
|
||||
this._activeViewPorts = ListWrapper.create();
|
||||
}
|
||||
|
||||
_activateViewPorts(viewPorts) {
|
||||
// TODO(vicb): assert(this._activeViewPorts.length === 0);
|
||||
if (isPresent(viewPorts)) {
|
||||
for (var i = 0; i < viewPorts.length; i++) {
|
||||
viewPorts[i].create();
|
||||
}
|
||||
this._activeViewPorts = viewPorts;
|
||||
}
|
||||
}
|
||||
|
||||
_registerViewPort(value, viewPort: ViewPort) {
|
||||
var viewPorts = MapWrapper.get(this._valueViewPorts, value);
|
||||
if (isBlank(viewPorts)) {
|
||||
viewPorts = ListWrapper.create();
|
||||
MapWrapper.set(this._valueViewPorts, value, viewPorts);
|
||||
}
|
||||
ListWrapper.push(viewPorts, viewPort);
|
||||
}
|
||||
|
||||
_deregisterViewPort(value, viewPort: ViewPort) {
|
||||
// `_whenDefault` is used a marker for non-registered whens
|
||||
if (value == _whenDefault) return;
|
||||
var viewPorts = MapWrapper.get(this._valueViewPorts, value);
|
||||
if (viewPorts.length == 1) {
|
||||
MapWrapper.delete(this._valueViewPorts, value);
|
||||
} else {
|
||||
ListWrapper.remove(viewPorts, viewPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a case statement as an expression.
|
||||
*
|
||||
* If multiple `ngSwitchWhen` match the `ngSwitch` value, all of them are displayed.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* // match against a context variable
|
||||
* <template [ng-switch-when]="contextVariable">...</template>
|
||||
*
|
||||
* // match against a constant string
|
||||
* <template [ng-switch-when]="'stringValue'">...</template>
|
||||
* ```
|
||||
*/
|
||||
@Template({
|
||||
selector: '[ng-switch-when]',
|
||||
bind: {
|
||||
'ng-switch-when' : 'when'
|
||||
}
|
||||
})
|
||||
export class NgSwitchWhen {
|
||||
_value: any;
|
||||
_ngSwitch: NgSwitch;
|
||||
_viewPort: ViewPort;
|
||||
|
||||
constructor(el: NgElement, viewPort: ViewPort, @Parent() ngSwitch: NgSwitch) {
|
||||
// `_whenDefault` is used as a marker for a not yet initialized value
|
||||
this._value = _whenDefault;
|
||||
this._ngSwitch = ngSwitch;
|
||||
this._viewPort = viewPort;
|
||||
}
|
||||
|
||||
set when(value) {
|
||||
this._ngSwitch._onWhenValueChanged(this._value, value, this._viewPort);
|
||||
this._value = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines a default case statement.
|
||||
*
|
||||
* Default case statements are displayed when no `NgSwitchWhen` match the `ngSwitch` value.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```
|
||||
* <template [ng-switch-default]>...</template>
|
||||
* ```
|
||||
*/
|
||||
@Template({
|
||||
selector: '[ng-switch-default]'
|
||||
})
|
||||
export class NgSwitchDefault {
|
||||
constructor(viewPort: ViewPort, @Parent() ngSwitch: NgSwitch) {
|
||||
ngSwitch._registerViewPort(_whenDefault, viewPort);
|
||||
}
|
||||
}
|
||||
|
||||
var _whenDefault = new Object();
|
Reference in New Issue
Block a user