@angular-wave/angular.ts 0.0.69 → 0.0.70

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.
@@ -7,209 +7,203 @@ export function ngMessagesDirective($animate) {
7
7
  return {
8
8
  require: "ngMessages",
9
9
  restrict: "AE",
10
- controller: [
11
- "$element",
12
- "$scope",
13
- "$attrs",
14
- function ($element, $scope, $attrs) {
15
- const ctrl = this;
16
- let latestKey = 0;
17
- let nextAttachId = 0;
18
- this.head = undefined;
19
- this.default = undefined;
20
-
21
- this.getAttachId = function getAttachId() {
22
- return nextAttachId++;
23
- };
24
-
25
- const messages = (this.messages = {});
26
- let renderLater;
27
- let cachedCollection;
28
-
29
- this.render = function (collection) {
30
- collection = collection || {};
31
-
32
- renderLater = false;
33
- cachedCollection = collection;
34
-
35
- // this is true if the attribute is empty or if the attribute value is truthy
36
- const multiple =
37
- isAttrTruthy($scope, $attrs.ngMessagesMultiple) ||
38
- isAttrTruthy($scope, $attrs.multiple);
39
-
40
- const unmatchedMessages = [];
41
- const matchedKeys = {};
42
- let truthyKeys = 0;
43
- let messageItem = ctrl.head;
44
- let messageFound = false;
45
- let totalMessages = 0;
46
-
47
- // we use != instead of !== to allow for both undefined and null values
48
- while (messageItem != null) {
49
- totalMessages++;
50
- const messageCtrl = messageItem.message;
51
-
52
- let messageUsed = false;
53
- if (!messageFound) {
54
- forEach(collection, (value, key) => {
55
- if (truthy(value) && !messageUsed) {
56
- truthyKeys++;
57
-
58
- if (messageCtrl.test(key)) {
59
- // this is to prevent the same error name from showing up twice
60
- if (matchedKeys[key]) return;
61
- matchedKeys[key] = true;
62
-
63
- messageUsed = true;
64
- messageCtrl.attach();
65
- }
66
- }
67
- });
68
- }
10
+ controller: function ($element, $scope, $attrs) {
11
+ const ctrl = this;
12
+ let latestKey = 0;
13
+ let nextAttachId = 0;
14
+ this.head = undefined;
15
+ this.default = undefined;
16
+
17
+ this.getAttachId = function getAttachId() {
18
+ return nextAttachId++;
19
+ };
69
20
 
70
- if (messageUsed) {
71
- // unless we want to display multiple messages then we should
72
- // set a flag here to avoid displaying the next message in the list
73
- messageFound = !multiple;
74
- } else {
75
- unmatchedMessages.push(messageCtrl);
76
- }
21
+ const messages = (this.messages = {});
22
+ let renderLater;
23
+ let cachedCollection;
24
+
25
+ this.render = function (collection) {
26
+ collection = collection || {};
27
+
28
+ renderLater = false;
29
+ cachedCollection = collection;
30
+
31
+ // this is true if the attribute is empty or if the attribute value is truthy
32
+ const multiple =
33
+ isAttrTruthy($scope, $attrs.ngMessagesMultiple) ||
34
+ isAttrTruthy($scope, $attrs.multiple);
35
+
36
+ const unmatchedMessages = [];
37
+ const matchedKeys = {};
38
+ let truthyKeys = 0;
39
+ let messageItem = ctrl.head;
40
+ let messageFound = false;
41
+ let totalMessages = 0;
42
+
43
+ // we use != instead of !== to allow for both undefined and null values
44
+ while (messageItem != null) {
45
+ totalMessages++;
46
+ const messageCtrl = messageItem.message;
47
+
48
+ let messageUsed = false;
49
+ if (!messageFound) {
50
+ forEach(collection, (value, key) => {
51
+ if (truthy(value) && !messageUsed) {
52
+ truthyKeys++;
53
+
54
+ if (messageCtrl.test(key)) {
55
+ // this is to prevent the same error name from showing up twice
56
+ if (matchedKeys[key]) return;
57
+ matchedKeys[key] = true;
58
+
59
+ messageUsed = true;
60
+ messageCtrl.attach();
61
+ }
62
+ }
63
+ });
64
+ }
77
65
 
78
- messageItem = messageItem.next;
66
+ if (messageUsed) {
67
+ // unless we want to display multiple messages then we should
68
+ // set a flag here to avoid displaying the next message in the list
69
+ messageFound = !multiple;
70
+ } else {
71
+ unmatchedMessages.push(messageCtrl);
79
72
  }
80
73
 
81
- forEach(unmatchedMessages, (messageCtrl) => {
82
- messageCtrl.detach();
83
- });
74
+ messageItem = messageItem.next;
75
+ }
84
76
 
85
- const messageMatched = unmatchedMessages.length !== totalMessages;
86
- const attachDefault =
87
- ctrl.default && !messageMatched && truthyKeys > 0;
77
+ forEach(unmatchedMessages, (messageCtrl) => {
78
+ messageCtrl.detach();
79
+ });
88
80
 
89
- if (attachDefault) {
90
- ctrl.default.attach();
91
- } else if (ctrl.default) {
92
- ctrl.default.detach();
93
- }
81
+ const messageMatched = unmatchedMessages.length !== totalMessages;
82
+ const attachDefault = ctrl.default && !messageMatched && truthyKeys > 0;
94
83
 
95
- if (messageMatched || attachDefault) {
96
- $animate.setClass($element, ACTIVE_CLASS, INACTIVE_CLASS);
97
- } else {
98
- $animate.setClass($element, INACTIVE_CLASS, ACTIVE_CLASS);
99
- }
100
- };
84
+ if (attachDefault) {
85
+ ctrl.default.attach();
86
+ } else if (ctrl.default) {
87
+ ctrl.default.detach();
88
+ }
101
89
 
102
- $scope.$watchCollection($attrs.ngMessages || $attrs.for, ctrl.render);
90
+ if (messageMatched || attachDefault) {
91
+ $animate.setClass($element, ACTIVE_CLASS, INACTIVE_CLASS);
92
+ } else {
93
+ $animate.setClass($element, INACTIVE_CLASS, ACTIVE_CLASS);
94
+ }
95
+ };
103
96
 
104
- this.reRender = function () {
105
- if (!renderLater) {
106
- renderLater = true;
107
- $scope.$evalAsync(() => {
108
- if (renderLater && cachedCollection) {
109
- ctrl.render(cachedCollection);
110
- }
111
- });
112
- }
113
- };
97
+ $scope.$watchCollection($attrs.ngMessages || $attrs.for, ctrl.render);
114
98
 
115
- this.register = function (comment, messageCtrl, isDefault) {
116
- if (isDefault) {
117
- ctrl.default = messageCtrl;
118
- } else {
119
- const nextKey = latestKey.toString();
120
- messages[nextKey] = {
121
- message: messageCtrl,
122
- };
123
- insertMessageNode($element[0], comment, nextKey);
124
- comment.$$ngMessageNode = nextKey;
125
- latestKey++;
126
- }
99
+ this.reRender = function () {
100
+ if (!renderLater) {
101
+ renderLater = true;
102
+ $scope.$evalAsync(() => {
103
+ if (renderLater && cachedCollection) {
104
+ ctrl.render(cachedCollection);
105
+ }
106
+ });
107
+ }
108
+ };
127
109
 
128
- ctrl.reRender();
129
- };
110
+ this.register = function (comment, messageCtrl, isDefault) {
111
+ if (isDefault) {
112
+ ctrl.default = messageCtrl;
113
+ } else {
114
+ const nextKey = latestKey.toString();
115
+ messages[nextKey] = {
116
+ message: messageCtrl,
117
+ };
118
+ insertMessageNode($element[0], comment, nextKey);
119
+ comment.$$ngMessageNode = nextKey;
120
+ latestKey++;
121
+ }
130
122
 
131
- this.deregister = function (comment, isDefault) {
132
- if (isDefault) {
133
- delete ctrl.default;
134
- } else {
135
- const key = comment.$$ngMessageNode;
136
- delete comment.$$ngMessageNode;
137
- removeMessageNode($element[0], comment, key);
138
- delete messages[key];
139
- }
140
- ctrl.reRender();
141
- };
123
+ ctrl.reRender();
124
+ };
142
125
 
143
- function findPreviousMessage(parent, comment) {
144
- let prevNode = comment;
145
- const parentLookup = [];
126
+ this.deregister = function (comment, isDefault) {
127
+ if (isDefault) {
128
+ delete ctrl.default;
129
+ } else {
130
+ const key = comment.$$ngMessageNode;
131
+ delete comment.$$ngMessageNode;
132
+ removeMessageNode($element[0], comment, key);
133
+ delete messages[key];
134
+ }
135
+ ctrl.reRender();
136
+ };
146
137
 
147
- while (prevNode && prevNode !== parent) {
148
- const prevKey = prevNode.$$ngMessageNode;
149
- if (prevKey && prevKey.length) {
150
- return messages[prevKey];
151
- }
138
+ function findPreviousMessage(parent, comment) {
139
+ let prevNode = comment;
140
+ const parentLookup = [];
152
141
 
153
- // dive deeper into the DOM and examine its children for any ngMessage
154
- // comments that may be in an element that appears deeper in the list
155
- if (
156
- prevNode.childNodes.length &&
157
- parentLookup.indexOf(prevNode) === -1
158
- ) {
159
- parentLookup.push(prevNode);
160
- prevNode = prevNode.childNodes[prevNode.childNodes.length - 1];
161
- } else if (prevNode.previousSibling) {
162
- prevNode = prevNode.previousSibling;
163
- } else {
164
- prevNode = prevNode.parentNode;
165
- parentLookup.push(prevNode);
166
- }
142
+ while (prevNode && prevNode !== parent) {
143
+ const prevKey = prevNode.$$ngMessageNode;
144
+ if (prevKey && prevKey.length) {
145
+ return messages[prevKey];
167
146
  }
168
- }
169
147
 
170
- function insertMessageNode(parent, comment, key) {
171
- const messageNode = messages[key];
172
- if (!ctrl.head) {
173
- ctrl.head = messageNode;
148
+ // dive deeper into the DOM and examine its children for any ngMessage
149
+ // comments that may be in an element that appears deeper in the list
150
+ if (
151
+ prevNode.childNodes.length &&
152
+ parentLookup.indexOf(prevNode) === -1
153
+ ) {
154
+ parentLookup.push(prevNode);
155
+ prevNode = prevNode.childNodes[prevNode.childNodes.length - 1];
156
+ } else if (prevNode.previousSibling) {
157
+ prevNode = prevNode.previousSibling;
174
158
  } else {
175
- const match = findPreviousMessage(parent, comment);
176
- if (match) {
177
- messageNode.next = match.next;
178
- match.next = messageNode;
179
- } else {
180
- messageNode.next = ctrl.head;
181
- ctrl.head = messageNode;
182
- }
159
+ prevNode = prevNode.parentNode;
160
+ parentLookup.push(prevNode);
183
161
  }
184
162
  }
163
+ }
185
164
 
186
- function removeMessageNode(parent, comment, key) {
187
- const messageNode = messages[key];
188
-
189
- // This message node may have already been removed by a call to deregister()
190
- if (!messageNode) return;
191
-
165
+ function insertMessageNode(parent, comment, key) {
166
+ const messageNode = messages[key];
167
+ if (!ctrl.head) {
168
+ ctrl.head = messageNode;
169
+ } else {
192
170
  const match = findPreviousMessage(parent, comment);
193
171
  if (match) {
194
- match.next = messageNode.next;
172
+ messageNode.next = match.next;
173
+ match.next = messageNode;
195
174
  } else {
196
- ctrl.head = messageNode.next;
175
+ messageNode.next = ctrl.head;
176
+ ctrl.head = messageNode;
197
177
  }
198
178
  }
199
- },
200
- ],
179
+ }
180
+
181
+ function removeMessageNode(parent, comment, key) {
182
+ const messageNode = messages[key];
183
+
184
+ // This message node may have already been removed by a call to deregister()
185
+ if (!messageNode) return;
186
+
187
+ const match = findPreviousMessage(parent, comment);
188
+ if (match) {
189
+ match.next = messageNode.next;
190
+ } else {
191
+ ctrl.head = messageNode.next;
192
+ }
193
+ }
194
+ },
201
195
  };
196
+ }
202
197
 
203
- function isAttrTruthy(scope, attr) {
204
- return (
205
- (isString(attr) && attr.length === 0) || // empty attribute
206
- truthy(scope.$eval(attr))
207
- );
208
- }
198
+ function isAttrTruthy(scope, attr) {
199
+ return (
200
+ (isString(attr) && attr.length === 0) || // empty attribute
201
+ truthy(scope.$eval(attr))
202
+ );
203
+ }
209
204
 
210
- function truthy(val) {
211
- return isString(val) ? val.length : !!val;
212
- }
205
+ function truthy(val) {
206
+ return isString(val) ? val.length : !!val;
213
207
  }
214
208
 
215
209
  ngMessagesIncludeDirective.$inject = ["$templateRequest", "$compile"];
@@ -239,108 +233,107 @@ export const ngMessageExpDirective = ngMessageDirectiveFactory(false);
239
233
  export const ngMessageDefaultDirective = ngMessageDirectiveFactory(true);
240
234
 
241
235
  function ngMessageDirectiveFactory(isDefault) {
242
- return [
243
- "$animate",
244
- function ($animate) {
245
- return {
246
- restrict: "AE",
247
- transclude: "element",
248
- priority: 1, // must run before ngBind, otherwise the text is set on the comment
249
- terminal: true,
250
- require: "^^ngMessages",
251
- link(scope, element, attrs, ngMessagesCtrl, $transclude) {
252
- let commentNode;
253
- let records;
254
- let staticExp;
255
- let dynamicExp;
256
-
257
- if (!isDefault) {
258
- commentNode = element[0];
259
- staticExp = attrs.ngMessage || attrs.when;
260
- dynamicExp = attrs.ngMessageExp || attrs.whenExp;
261
-
262
- const assignRecords = function (items) {
263
- records = items
264
- ? Array.isArray(items)
265
- ? items
266
- : items.split(/[\s,]+/)
267
- : null;
268
- ngMessagesCtrl.reRender();
269
- };
270
-
271
- if (dynamicExp) {
272
- assignRecords(scope.$eval(dynamicExp));
273
- scope.$watchCollection(dynamicExp, assignRecords);
274
- } else {
275
- assignRecords(staticExp);
276
- }
236
+ ngMessageDirective.$inject = ["$animate"];
237
+ function ngMessageDirective($animate) {
238
+ return {
239
+ restrict: "AE",
240
+ transclude: "element",
241
+ priority: 1, // must run before ngBind, otherwise the text is set on the comment
242
+ terminal: true,
243
+ require: "^^ngMessages",
244
+ link(scope, element, attrs, ngMessagesCtrl, $transclude) {
245
+ let commentNode;
246
+ let records;
247
+ let staticExp;
248
+ let dynamicExp;
249
+
250
+ if (!isDefault) {
251
+ commentNode = element[0];
252
+ staticExp = attrs.ngMessage || attrs.when;
253
+ dynamicExp = attrs.ngMessageExp || attrs.whenExp;
254
+
255
+ const assignRecords = function (items) {
256
+ records = items
257
+ ? Array.isArray(items)
258
+ ? items
259
+ : items.split(/[\s,]+/)
260
+ : null;
261
+ ngMessagesCtrl.reRender();
262
+ };
263
+
264
+ if (dynamicExp) {
265
+ assignRecords(scope.$eval(dynamicExp));
266
+ scope.$watchCollection(dynamicExp, assignRecords);
267
+ } else {
268
+ assignRecords(staticExp);
277
269
  }
270
+ }
278
271
 
279
- let currentElement;
280
- let messageCtrl;
281
- ngMessagesCtrl.register(
282
- commentNode,
283
- (messageCtrl = {
284
- test(name) {
285
- return contains(records, name);
286
- },
287
- attach() {
288
- if (!currentElement) {
289
- $transclude((elm, newScope) => {
290
- $animate.enter(elm, null, element);
291
- currentElement = elm;
292
-
293
- // Each time we attach this node to a message we get a new id that we can match
294
- // when we are destroying the node later.
295
- const $$attachId = (currentElement.$$attachId =
296
- ngMessagesCtrl.getAttachId());
297
-
298
- // in the event that the element or a parent element is destroyed
299
- // by another structural directive then it's time
300
- // to deregister the message from the controller
301
- currentElement.on("$destroy", () => {
302
- // If the message element was removed via a call to `detach` then `currentElement` will be null
303
- // So this handler only handles cases where something else removed the message element.
304
- if (
305
- currentElement &&
306
- currentElement.$$attachId === $$attachId
307
- ) {
308
- ngMessagesCtrl.deregister(commentNode, isDefault);
309
- messageCtrl.detach();
310
- }
311
- newScope.$destroy();
312
- });
272
+ let currentElement;
273
+ let messageCtrl;
274
+ ngMessagesCtrl.register(
275
+ commentNode,
276
+ (messageCtrl = {
277
+ test(name) {
278
+ return contains(records, name);
279
+ },
280
+ attach() {
281
+ if (!currentElement) {
282
+ $transclude((elm, newScope) => {
283
+ $animate.enter(elm, null, element);
284
+ currentElement = elm;
285
+
286
+ // Each time we attach this node to a message we get a new id that we can match
287
+ // when we are destroying the node later.
288
+ const $$attachId = (currentElement.$$attachId =
289
+ ngMessagesCtrl.getAttachId());
290
+
291
+ // in the event that the element or a parent element is destroyed
292
+ // by another structural directive then it's time
293
+ // to deregister the message from the controller
294
+ currentElement.on("$destroy", () => {
295
+ // If the message element was removed via a call to `detach` then `currentElement` will be null
296
+ // So this handler only handles cases where something else removed the message element.
297
+ if (
298
+ currentElement &&
299
+ currentElement.$$attachId === $$attachId
300
+ ) {
301
+ ngMessagesCtrl.deregister(commentNode, isDefault);
302
+ messageCtrl.detach();
303
+ }
304
+ newScope.$destroy();
313
305
  });
314
- }
315
- },
316
- detach() {
317
- if (currentElement) {
318
- const elm = currentElement;
319
- currentElement = null;
320
- $animate.leave(elm);
321
- }
322
- },
323
- }),
324
- isDefault,
325
- );
326
-
327
- // We need to ensure that this directive deregisters itself when it no longer exists
328
- // Normally this is done when the attached element is destroyed; but if this directive
329
- // gets removed before we attach the message to the DOM there is nothing to watch
330
- // in which case we must deregister when the containing scope is destroyed.
331
- scope.$on("$destroy", () => {
332
- ngMessagesCtrl.deregister(commentNode, isDefault);
333
- });
334
- },
335
- };
336
- },
337
- ];
338
-
339
- function contains(collection, key) {
340
- if (collection) {
341
- return Array.isArray(collection)
342
- ? collection.indexOf(key) >= 0
343
- : Object.prototype.hasOwnProperty.call(collection, key);
344
- }
306
+ });
307
+ }
308
+ },
309
+ detach() {
310
+ if (currentElement) {
311
+ const elm = currentElement;
312
+ currentElement = null;
313
+ $animate.leave(elm);
314
+ }
315
+ },
316
+ }),
317
+ isDefault,
318
+ );
319
+
320
+ // We need to ensure that this directive deregisters itself when it no longer exists
321
+ // Normally this is done when the attached element is destroyed; but if this directive
322
+ // gets removed before we attach the message to the DOM there is nothing to watch
323
+ // in which case we must deregister when the containing scope is destroyed.
324
+ scope.$on("$destroy", () => {
325
+ ngMessagesCtrl.deregister(commentNode, isDefault);
326
+ });
327
+ },
328
+ };
329
+ }
330
+ return ngMessageDirective;
331
+ }
332
+
333
+ function contains(collection, key) {
334
+ if (collection) {
335
+ return Array.isArray(collection)
336
+ ? collection.indexOf(key) >= 0
337
+ : Object.prototype.hasOwnProperty.call(collection, key);
345
338
  }
346
339
  }
@@ -65,7 +65,6 @@ export function filterFilter() {
65
65
  }
66
66
 
67
67
  // Helper functions for `filterFilter`
68
- /** @private */
69
68
  function createPredicateFn(
70
69
  expression,
71
70
  comparator,
@@ -124,7 +123,6 @@ function createPredicateFn(
124
123
  return predicateFn;
125
124
  }
126
125
 
127
- /** @private */
128
126
  function deepCompare(
129
127
  actual,
130
128
  expected,
@@ -211,7 +209,6 @@ function deepCompare(
211
209
  }
212
210
 
213
211
  // Used for easily differentiating between `null` and actual `object`
214
- /** @private */
215
212
  function getTypeForFilter(val) {
216
213
  return val === null ? "null" : typeof val;
217
214
  }
@@ -45,7 +45,6 @@ export function limitToFilter() {
45
45
  };
46
46
  }
47
47
 
48
- /** @private */
49
48
  function sliceFn(input, begin, end) {
50
49
  if (isString(input)) return input.slice(begin, end);
51
50