@angular-wave/angular.ts 0.0.67 → 0.0.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,179 @@
1
+ /\*\*
2
+
3
+ -
4
+ - The `ngOptions` attribute can be used to dynamically generate a list of `<option>`
5
+ - elements for the `<select>` element using the array or object obtained by evaluating the
6
+ - `ngOptions` comprehension expression.
7
+ -
8
+ - In many cases, {@link ng.directive:ngRepeat ngRepeat} can be used on `<option>` elements instead of
9
+ - `ngOptions` to achieve a similar result. However, `ngOptions` provides some benefits:
10
+ - - more flexibility in how the `<select>`'s model is assigned via the `select` **`as`** part of the
11
+ - comprehension expression
12
+ - - reduced memory consumption by not creating a new scope for each repeated instance
13
+ - - increased render speed by creating the options in a documentFragment instead of individually
14
+ -
15
+ - When an item in the `<select>` menu is selected, the array element or object property
16
+ - represented by the selected option will be bound to the model identified by the `ngModel`
17
+ - directive.
18
+ -
19
+ - Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
20
+ - be nested into the `<select>` element. This element will then represent the `null` or "not selected"
21
+ - option. See example below for demonstration.
22
+ -
23
+ - ## Complex Models (objects or collections)
24
+ -
25
+ - By default, `ngModel` watches the model by reference, not value. This is important to know when
26
+ - binding the select to a model that is an object or a collection.
27
+ -
28
+ - One issue occurs if you want to preselect an option. For example, if you set
29
+ - the model to an object that is equal to an object in your collection, `ngOptions` won't be able to set the selection,
30
+ - because the objects are not identical. So by default, you should always reference the item in your collection
31
+ - for preselections, e.g.: `$scope.selected = $scope.collection[3]`.
32
+ -
33
+ - Another solution is to use a `track by` clause, because then `ngOptions` will track the identity
34
+ - of the item not by reference, but by the result of the `track by` expression. For example, if your
35
+ - collection items have an id property, you would `track by item.id`.
36
+ -
37
+ - A different issue with objects or collections is that ngModel won't detect if an object property or
38
+ - a collection item changes. For that reason, `ngOptions` additionally watches the model using
39
+ - `$watchCollection`, when the expression contains a `track by` clause or the the select has the `multiple` attribute.
40
+ - This allows ngOptions to trigger a re-rendering of the options even if the actual object/collection
41
+ - has not changed identity, but only a property on the object or an item in the collection changes.
42
+ -
43
+ - Note that `$watchCollection` does a shallow comparison of the properties of the object (or the items in the collection
44
+ - if the model is an array). This means that changing a property deeper than the first level inside the
45
+ - object/collection will not trigger a re-rendering.
46
+ -
47
+ - ## `select` **`as`**
48
+ -
49
+ - Using `select` **`as`** will bind the result of the `select` expression to the model, but
50
+ - the value of the `<select>` and `<option>` html elements will be either the index (for array data sources)
51
+ - or property name (for object data sources) of the value within the collection. If a **`track by`** expression
52
+ - is used, the result of that expression will be set as the value of the `option` and `select` elements.
53
+ -
54
+ -
55
+ - ### `select` **`as`** and **`track by`**
56
+ -
57
+ - <div class="alert alert-warning">
58
+ - Be careful when using `select` **`as`** and **`track by`** in the same expression.
59
+ - </div>
60
+ -
61
+ - Given this array of items on the $scope:
62
+ -
63
+ - ```js
64
+
65
+ ```
66
+
67
+ - $scope.items = [{
68
+ - id: 1,
69
+ - label: 'aLabel',
70
+ - subItem: { name: 'aSubItem' }
71
+ - }, {
72
+ - id: 2,
73
+ - label: 'bLabel',
74
+ - subItem: { name: 'bSubItem' }
75
+ - }];
76
+ - ```
77
+
78
+ ```
79
+
80
+ -
81
+ - This will work:
82
+ -
83
+ - ```html
84
+
85
+ ```
86
+
87
+ - <select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>
88
+ - ```
89
+
90
+ ```
91
+
92
+ - ```js
93
+
94
+ ```
95
+
96
+ - $scope.selected = $scope.items[0];
97
+ - ```
98
+
99
+ ```
100
+
101
+ -
102
+ - but this will not work:
103
+ -
104
+ - ```html
105
+
106
+ ```
107
+
108
+ - <select ng-options="item.subItem as item.label for item in items track by item.id" ng-model="selected"></select>
109
+ - ```
110
+
111
+ ```
112
+
113
+ - ```js
114
+
115
+ ```
116
+
117
+ - $scope.selected = $scope.items[0].subItem;
118
+ - ```
119
+
120
+ ```
121
+
122
+ -
123
+ - In both examples, the **`track by`** expression is applied successfully to each `item` in the
124
+ - `items` array. Because the selected option has been set programmatically in the controller, the
125
+ - **`track by`** expression is also applied to the `ngModel` value. In the first example, the
126
+ - `ngModel` value is `items[0]` and the **`track by`** expression evaluates to `items[0].id` with
127
+ - no issue. In the second example, the `ngModel` value is `items[0].subItem` and the **`track by`**
128
+ - expression evaluates to `items[0].subItem.id` (which is undefined). As a result, the model value
129
+ - is not matched against any `<option>` and the `<select>` appears as having no selected value.
130
+ -
131
+ -
132
+ - @param {string} ngModel Assignable AngularJS expression to data-bind to.
133
+ - @param {string} ngOptions in one of the following forms:
134
+ -
135
+ - - for array data sources:
136
+ - * `label` **`for`** `value` **`in`** `array`
137
+ - * `select` **`as`** `label` **`for`** `value` **`in`** `array`
138
+ - * `label` **`group by`** `group` **`for`** `value` **`in`** `array`
139
+ - * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array`
140
+ - * `label` **`group by`** `group` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
141
+ - * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
142
+ - * `label` **`for`** `value` **`in`** `array` | orderBy:`orderexpr` **`track by`** `trackexpr`
143
+ - (for including a filter with `track by`)
144
+ - - for object data sources:
145
+ - * `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
146
+ - * `select` **`as`** `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
147
+ - * `label` **`group by`** `group` **`for (`**`key`**`,`** `value`**`) in`** `object`
148
+ - * `label` **`disable when`** `disable` **`for (`**`key`**`,`** `value`**`) in`** `object`
149
+ - * `select` **`as`** `label` **`group by`** `group`
150
+ - **`for` `(`**`key`**`,`** `value`**`) in`** `object`
151
+ - * `select` **`as`** `label` **`disable when`** `disable`
152
+ - **`for` `(`**`key`**`,`** `value`**`) in`** `object`
153
+ -
154
+ - Where:
155
+ -
156
+ - - `array` / `object`: an expression which evaluates to an array / object to iterate over.
157
+ - - `value`: local variable which will refer to each item in the `array` or each property value
158
+ - of `object` during iteration.
159
+ - - `key`: local variable which will refer to a property name in `object` during iteration.
160
+ - - `label`: The result of this expression will be the label for `<option>` element. The
161
+ - `expression` will most likely refer to the `value` variable (e.g. `value.propertyName`).
162
+ - - `select`: The result of this expression will be bound to the model of the parent `<select>`
163
+ - element. If not specified, `select` expression will default to `value`.
164
+ - - `group`: The result of this expression will be used to group options using the `<optgroup>`
165
+ - DOM element.
166
+ - - `disable`: The result of this expression will be used to disable the rendered `<option>`
167
+ - element. Return `true` to disable.
168
+ - - `trackexpr`: Used when working with an array of objects. The result of this expression will be
169
+ - used to identify the objects in the array. The `trackexpr` will most likely refer to the
170
+ - `value` variable (e.g. `value.propertyName`). With this the selection is preserved
171
+ - even when the options are recreated (e.g. reloaded from the server).
172
+ - @param {string=} name Property name of the form under which the control is published.
173
+ - @param {string=} required The control is considered valid only if value is entered.
174
+ - @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
175
+ - the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
176
+ - `required` when you want to data-bind to the `required` attribute.
177
+ - @param {string=} ngAttrSize sets the size of the select element dynamically. Uses the
178
+ - {@link guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes ngAttr} directive.
179
+ - \*/
@@ -8,8 +8,6 @@ import {
8
8
  shallowCopy,
9
9
  } from "../../shared/utils";
10
10
 
11
- const noopNgModelController = { $setViewValue: () => {}, $render: () => {} };
12
-
13
11
  function setOptionSelectedStatus(optionEl, value) {
14
12
  optionEl[0].selected = value;
15
13
  /**
@@ -29,6 +27,11 @@ function setOptionSelectedStatus(optionEl, value) {
29
27
  *
30
28
  */
31
29
  SelectController.$inject = ["$element", "$scope"];
30
+ /**
31
+ *
32
+ * @param {JQLite} $element
33
+ * @param {import('../../core/scope/scope').Scope} $scope
34
+ */
32
35
  function SelectController($element, $scope) {
33
36
  const self = this;
34
37
  const optionsMap = new Map();
@@ -36,7 +39,7 @@ function SelectController($element, $scope) {
36
39
  self.selectValueMap = {}; // Keys are the hashed values, values the original values
37
40
 
38
41
  // If the ngModel doesn't get provided then provide a dummy noop version to prevent errors
39
- self.ngModelCtrl = noopNgModelController;
42
+ self.ngModelCtrl = {};
40
43
  self.multiple = false;
41
44
 
42
45
  // The "unknown" option is one that is prepended to the list if the viewValue
@@ -101,7 +104,7 @@ function SelectController($element, $scope) {
101
104
 
102
105
  // Read the value of the select control, the implementation of this changes depending
103
106
  // upon whether the select can have multiple values and whether ngOptions is at work.
104
- self.readValue = function readSingleValue() {
107
+ self.readValue = function () {
105
108
  const val = $element.val();
106
109
  // ngValue added option values are stored in the selectValueMap, normal interpolations are not
107
110
  const realVal = val in self.selectValueMap ? self.selectValueMap[val] : val;
@@ -20,6 +20,8 @@ export function initMessageModule(angular) {
20
20
  const ctrl = this;
21
21
  let latestKey = 0;
22
22
  let nextAttachId = 0;
23
+ this.head = undefined;
24
+ this.default = undefined;
23
25
 
24
26
  this.getAttachId = function getAttachId() {
25
27
  return nextAttachId++;
@@ -86,47 +86,6 @@ function getReplace(config, arrayMode, isOptional, squash) {
86
86
  ).concat(replace);
87
87
  }
88
88
  export class Param {
89
- static values(params, values = {}) {
90
- const paramValues = {};
91
- for (const param of params) {
92
- paramValues[param.id] = param.value(values[param.id]);
93
- }
94
- return paramValues;
95
- }
96
- /**
97
- * Finds [[Param]] objects which have different param values
98
- *
99
- * Filters a list of [[Param]] objects to only those whose parameter values differ in two param value objects
100
- *
101
- * @param params: The list of Param objects to filter
102
- * @param values1: The first set of parameter values
103
- * @param values2: the second set of parameter values
104
- *
105
- * @returns any Param objects whose values were different between values1 and values2
106
- */
107
- static changed(params, values1 = {}, values2 = {}) {
108
- return params.filter(
109
- (param) => !param.type.equals(values1[param.id], values2[param.id]),
110
- );
111
- }
112
- /**
113
- * Checks if two param value objects are equal (for a set of [[Param]] objects)
114
- *
115
- * @param params The list of [[Param]] objects to check
116
- * @param values1 The first set of param values
117
- * @param values2 The second set of param values
118
- *
119
- * @returns true if the param values in values1 and values2 are equal
120
- */
121
- static equals(params, values1 = {}, values2 = {}) {
122
- return Param.changed(params, values1, values2).length === 0;
123
- }
124
- /** Returns true if a the parameter values are valid, according to the Param definitions */
125
- static validates(params, values = {}) {
126
- return params
127
- .map((param) => param.validates(values[param.id]))
128
- .reduce(allTrueR, true);
129
- }
130
89
  constructor(id, type, location, urlConfig, state) {
131
90
  const config = getParamDeclaration(id, location, state);
132
91
  type = getType(config, type, location, id, urlConfig.paramTypes);
@@ -157,20 +116,19 @@ export class Param {
157
116
  const arrayParamNomenclature = id.match(/\[\]$/) ? { array: true } : {};
158
117
  return Object.assign(arrayDefaults, arrayParamNomenclature, config).array;
159
118
  }
160
- Object.assign(this, {
161
- id,
162
- type,
163
- location,
164
- isOptional,
165
- dynamic,
166
- raw,
167
- squash,
168
- replace,
169
- inherit,
170
- array: arrayMode,
171
- config,
172
- });
119
+ this.isOptional = isOptional;
120
+ this.type = type;
121
+ this.location = location;
122
+ this.id = id;
123
+ this.dynamic = dynamic;
124
+ this.raw = raw;
125
+ this.squash = squash;
126
+ this.replace = replace;
127
+ this.inherit = inherit;
128
+ this.array = arrayMode;
129
+ this.config = config;
173
130
  }
131
+
174
132
  isDefaultValue(value) {
175
133
  return this.isOptional && this.type.equals(this.value(), value);
176
134
  }
@@ -227,4 +185,46 @@ export class Param {
227
185
  toString() {
228
186
  return `{Param:${this.id} ${this.type} squash: '${this.squash}' optional: ${this.isOptional}}`;
229
187
  }
188
+
189
+ static values(params, values = {}) {
190
+ const paramValues = {};
191
+ for (const param of params) {
192
+ paramValues[param.id] = param.value(values[param.id]);
193
+ }
194
+ return paramValues;
195
+ }
196
+ /**
197
+ * Finds [[Param]] objects which have different param values
198
+ *
199
+ * Filters a list of [[Param]] objects to only those whose parameter values differ in two param value objects
200
+ *
201
+ * @param params: The list of Param objects to filter
202
+ * @param values1: The first set of parameter values
203
+ * @param values2: the second set of parameter values
204
+ *
205
+ * @returns any Param objects whose values were different between values1 and values2
206
+ */
207
+ static changed(params, values1 = {}, values2 = {}) {
208
+ return params.filter(
209
+ (param) => !param.type.equals(values1[param.id], values2[param.id]),
210
+ );
211
+ }
212
+ /**
213
+ * Checks if two param value objects are equal (for a set of [[Param]] objects)
214
+ *
215
+ * @param params The list of [[Param]] objects to check
216
+ * @param values1 The first set of param values
217
+ * @param values2 The second set of param values
218
+ *
219
+ * @returns true if the param values in values1 and values2 are equal
220
+ */
221
+ static equals(params, values1 = {}, values2 = {}) {
222
+ return Param.changed(params, values1, values2).length === 0;
223
+ }
224
+ /** Returns true if a the parameter values are valid, according to the Param definitions */
225
+ static validates(params, values = {}) {
226
+ return params
227
+ .map((param) => param.validates(values[param.id]))
228
+ .reduce(allTrueR, true);
229
+ }
230
230
  }
@@ -74,6 +74,7 @@ export class PathUtils {
74
74
  */
75
75
  static inheritParams(fromPath, toPath, toKeys = []) {
76
76
  function nodeParamVals(path, state) {
77
+ /** @type {PathNode} */
77
78
  const node = find(path, propEq("state", state));
78
79
  return Object.assign({}, node && node.paramValues);
79
80
  }
@@ -92,6 +92,13 @@ export class UrlService {
92
92
  "$location",
93
93
  "$browser",
94
94
  "$rootScope",
95
+ /**
96
+ *
97
+ * @param {import('../../core/location/location').Location} $location
98
+ * @param {import('../../services/browser').Browser} $browser
99
+ * @param {import('../../core/scope/scope').Scope} $rootScope
100
+ * @returns
101
+ */
95
102
  ($location, $browser, $rootScope) => {
96
103
  this.$location = $location;
97
104
  this.$browser = $browser;
@@ -18,13 +18,11 @@ export function AnchorScrollProvider() {
18
18
  "$rootScope",
19
19
  /**
20
20
  *
21
- * @param {*} $location
21
+ * @param {import('../core/location/location').Location} $location
22
22
  * @param {import('../core/scope/scope').Scope} $rootScope
23
23
  * @returns
24
24
  */
25
25
  function ($location, $rootScope) {
26
- const { document } = window;
27
-
28
26
  // Helper function to get first anchor from a NodeList
29
27
  // (using `Array#some()` instead of `angular#forEach()` since it's more performant
30
28
  // and working in all supported browsers.)
@@ -117,7 +115,7 @@ export function AnchorScrollProvider() {
117
115
  if (newVal === oldVal && newVal === "") return;
118
116
 
119
117
  const action = () => $rootScope.$evalAsync(scroll);
120
- if (window.document.readyState === "complete") {
118
+ if (document.readyState === "complete") {
121
119
  // Force the action to be run async for consistent behavior
122
120
  // from the action's point of view
123
121
  // i.e. it will definitely not be in a $apply
@@ -522,7 +522,7 @@ JQLite.prototype.append = function (node) {
522
522
  };
523
523
 
524
524
  /**
525
- * @param {string} node
525
+ * @param {string|JQLite} node
526
526
  * @returns {JQLite}
527
527
  */
528
528
  JQLite.prototype.prepend = function (node) {
@@ -1,4 +1,4 @@
1
1
  export function $$IntervalFactoryProvider(): void;
2
2
  export class $$IntervalFactoryProvider {
3
- $get: (string | (($browser: any, $q: any, $$q: any, $rootScope: any) => (setIntervalFn: any, clearIntervalFn: any) => (fn: any, delay: any, count: any, invokeApply: any, ...args: any[]) => any))[];
3
+ $get: (string | (($browser: import("../../services/browser").Browser, $q: any, $$q: any, $rootScope: import("../scope/scope").Scope) => (setIntervalFn: any, clearIntervalFn: any) => (fn: any, delay: any, count: any, invokeApply: any, ...args: any[]) => any))[];
4
4
  }
@@ -2,3 +2,7 @@ export function $IntervalProvider(): void;
2
2
  export class $IntervalProvider {
3
3
  $get: (string | (($$intervalFactory: any) => any))[];
4
4
  }
5
+ /**
6
+ * Interval ID which uniquely identifies the interval and can be used to cancel it
7
+ */
8
+ export type IntervalId = number;