@angular-wave/angular.ts 0.0.70 → 0.0.72
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.
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +1 -1
- package/src/animations/animate-children-directive.md +1 -1
- package/src/animations/animate-css-driver.js +1 -1
- package/src/animations/animate-css.html +2 -2
- package/src/animations/animate-js.html +1 -1
- package/src/animations/animate-queue.js +4 -4
- package/src/animations/animate-swap.md +1 -1
- package/src/{core/animate → animations}/animate.html +1 -1
- package/src/{core/animate → animations}/animate.js +4 -120
- package/src/animations/raf-scheduler.js +7 -3
- package/src/animations/raf-scheduler.spec.js +3 -3
- package/src/animations/shared.js +16 -7
- package/src/binding.spec.js +4 -3
- package/src/core/compile/attributes.js +326 -0
- package/src/core/compile/compile.js +76 -433
- package/src/core/compile/compile.spec.js +45 -28
- package/src/core/di/injector.md +1 -1
- package/src/core/di/ng-module.js +46 -3
- package/src/core/interpolate/interpolate.js +1 -12
- package/src/core/location/location.js +26 -4
- package/src/core/parser/parse.js +50 -47
- package/src/core/prop.spec.js +15 -11
- package/src/core/scope/scope.js +4 -7
- package/src/directive/bind/bind.spec.js +80 -44
- package/src/directive/class/class.js +43 -14
- package/src/directive/class/class.spec.js +7 -4
- package/src/directive/form/form.js +3 -1
- package/src/directive/form/form.spec.js +3 -4
- package/src/directive/if/if-animate-css.html +5 -7
- package/src/directive/if/if.js +1 -1
- package/src/directive/if/if.spec.js +3 -2
- package/src/directive/include/include.js +1 -1
- package/src/directive/input/input.spec.js +6 -4
- package/src/directive/list/list.spec.js +4 -2
- package/src/directive/messages/messages.js +5 -4
- package/src/directive/messages/messages.spec.js +4 -4
- package/src/directive/model/model.spec.js +4 -3
- package/src/directive/model-options/model-options.spec.js +3 -1
- package/src/directive/repeat/repeat.md +1 -1
- package/src/directive/repeat/repeat.spec.js +1 -1
- package/src/directive/select/select.spec.js +3 -3
- package/src/directive/show-hide/show-hide.js +36 -6
- package/src/directive/switch/switch.spec.js +5 -2
- package/src/directive/validators/validators.spec.js +6 -4
- package/src/loader.js +1 -2
- package/src/public.js +22 -10
- package/src/router/state/state-object.js +4 -9
- package/src/router/url/url-matcher.js +1 -1
- package/src/router/url/url-rule.js +5 -1
- package/src/router/url/url-service.js +1 -1
- package/src/services/anchor-scroll.html +1 -1
- package/src/shared/jqlite/jqlite.js +14 -2
- package/src/types.js +1 -1
- package/types/animations/animate-css-driver.d.ts +1 -1
- package/types/animations/animate-queue.d.ts +1 -2
- package/types/{core/animate → animations}/animate.d.ts +2 -12
- package/types/animations/raf-scheduler.d.ts +7 -2
- package/types/animations/shared.d.ts +11 -6
- package/types/core/compile/attributes.d.ts +101 -0
- package/types/core/compile/compile.d.ts +10 -67
- package/types/core/di/ng-module.d.ts +55 -12
- package/types/core/interpolate/interpolate.d.ts +1 -12
- package/types/core/location/location.d.ts +12 -2
- package/types/core/parser/parse.d.ts +10 -10
- package/types/core/scope/scope.d.ts +20 -20
- package/types/directive/form/form.d.ts +2 -11
- package/types/router/state/state-object.d.ts +0 -2
- package/types/router/url/url-matcher.d.ts +2 -2
- package/types/router/url/url-rule.d.ts +2 -1
- package/types/shared/jqlite/jqlite.d.ts +10 -6
- package/types/types.d.ts +1 -1
- package/src/animations/module.js +0 -25
- package/src/core/animate/animate-css.js +0 -88
- package/src/core/animate/anomate.md +0 -13
- package/types/animations/module.d.ts +0 -1
- package/types/core/animate/animate-css.d.ts +0 -19
- /package/src/{core/animate → animations}/animate-runner.js +0 -0
- /package/src/{core/animate → animations}/animate.spec.js +0 -0
- /package/src/{core/animate → animations}/helpers.js +0 -0
- /package/types/{core/animate → animations}/animate-runner.d.ts +0 -0
- /package/types/{core/animate → animations}/helpers.d.ts +0 -0
|
@@ -19,13 +19,10 @@ import {
|
|
|
19
19
|
isString,
|
|
20
20
|
lowercase,
|
|
21
21
|
extend,
|
|
22
|
-
reverseParams,
|
|
23
|
-
snakeCase,
|
|
24
22
|
isScope,
|
|
25
23
|
valueFn,
|
|
26
24
|
inherit,
|
|
27
25
|
isUndefined,
|
|
28
|
-
arrayRemove,
|
|
29
26
|
getNodeName,
|
|
30
27
|
bind,
|
|
31
28
|
trim,
|
|
@@ -37,9 +34,10 @@ import {
|
|
|
37
34
|
directiveNormalize,
|
|
38
35
|
} from "../../shared/utils";
|
|
39
36
|
import { SCE_CONTEXTS } from "../sce/sce";
|
|
40
|
-
import { PREFIX_REGEXP
|
|
37
|
+
import { PREFIX_REGEXP } from "../../shared/constants";
|
|
41
38
|
import { createEventDirective } from "../../directive/events/events";
|
|
42
39
|
import { CACHE, EXPANDO } from "../cache/cache";
|
|
40
|
+
import { Attributes } from "./attributes";
|
|
43
41
|
|
|
44
42
|
let ttl = TTL;
|
|
45
43
|
|
|
@@ -50,17 +48,10 @@ let ttl = TTL;
|
|
|
50
48
|
|
|
51
49
|
const $compileMinErr = minErr("$compile");
|
|
52
50
|
|
|
53
|
-
const
|
|
51
|
+
const UNINITALIZED_VALIED = new Object();
|
|
54
52
|
const EXCLUDED_DIRECTIVES = ["ngIf", "ngRepeat"];
|
|
55
53
|
|
|
56
|
-
/**
|
|
57
|
-
* @ngdoc provider
|
|
58
|
-
* @name $compileProvider
|
|
59
|
-
*
|
|
60
|
-
* @description
|
|
61
|
-
*/
|
|
62
54
|
$CompileProvider.$inject = ["$provide", "$$sanitizeUriProvider"];
|
|
63
|
-
|
|
64
55
|
export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
65
56
|
const hasDirectives = {};
|
|
66
57
|
const Suffix = "Directive";
|
|
@@ -159,24 +150,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
159
150
|
return bindings;
|
|
160
151
|
}
|
|
161
152
|
|
|
162
|
-
function assertValidDirectiveName(name) {
|
|
163
|
-
const letter = name.charAt(0);
|
|
164
|
-
if (!letter || letter !== lowercase(letter)) {
|
|
165
|
-
throw $compileMinErr(
|
|
166
|
-
"baddir",
|
|
167
|
-
"Directive/Component name '{0}' is invalid. The first character must be a lowercase letter",
|
|
168
|
-
name,
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
if (name !== name.trim()) {
|
|
172
|
-
throw $compileMinErr(
|
|
173
|
-
"baddir",
|
|
174
|
-
"Directive/Component name '{0}' is invalid. The name should not contain leading or trailing whitespaces",
|
|
175
|
-
name,
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
153
|
function getDirectiveRequire(directive) {
|
|
181
154
|
const require =
|
|
182
155
|
directive.require || (directive.controller && directive.name);
|
|
@@ -206,11 +179,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
206
179
|
}
|
|
207
180
|
|
|
208
181
|
/**
|
|
209
|
-
* @ngdoc method
|
|
210
|
-
* @name $compileProvider#directive
|
|
211
|
-
* @kind function
|
|
212
|
-
*
|
|
213
|
-
* @description
|
|
214
182
|
* Register a new directive with the compiler.
|
|
215
183
|
*
|
|
216
184
|
* @param {string|Object} name Name of the directive in camel-case (i.e. `ngBind` which will match
|
|
@@ -273,18 +241,14 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
273
241
|
};
|
|
274
242
|
|
|
275
243
|
/**
|
|
276
|
-
* @ngdoc method
|
|
277
|
-
* @name $compileProvider#component
|
|
278
|
-
* @module ng
|
|
279
244
|
* @param {string|Object} name Name of the component in camelCase (i.e. `myComp` which will match `<my-comp>`),
|
|
280
245
|
* or an object map of components where the keys are the names and the values are the component definition objects.
|
|
281
246
|
* @param {Object} options Component definition object (a simplified
|
|
282
|
-
* {
|
|
247
|
+
* {directive definition object}),
|
|
283
248
|
* with the following properties (all optional):
|
|
284
249
|
*
|
|
285
250
|
* - `controller` – `{(string|function()=}` – controller constructor function that should be
|
|
286
|
-
* associated with newly created scope or the name of a {
|
|
287
|
-
* registered controller} if passed as a string. An empty `noop` function by default.
|
|
251
|
+
* associated with newly created scope or the name of a {controller} if passed as a string. An empty `noop` function by default.
|
|
288
252
|
* - `controllerAs` – `{string=}` – identifier name for to reference the controller in the component's scope.
|
|
289
253
|
* If present, the controller will be published to scope under the `controllerAs` name.
|
|
290
254
|
* If not present, this will default to be `$ctrl`.
|
|
@@ -292,7 +256,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
292
256
|
* returns an html template as a string which should be used as the contents of this component.
|
|
293
257
|
* Empty string by default.
|
|
294
258
|
*
|
|
295
|
-
* If `template` is a function, then it is {
|
|
259
|
+
* If `template` is a function, then it is {injected} with
|
|
296
260
|
* the following locals:
|
|
297
261
|
*
|
|
298
262
|
* - `$element` - Current element
|
|
@@ -301,7 +265,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
301
265
|
* - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html
|
|
302
266
|
* template that should be used as the contents of this component.
|
|
303
267
|
*
|
|
304
|
-
* If `templateUrl` is a function, then it is {
|
|
268
|
+
* If `templateUrl` is a function, then it is {injected} with
|
|
305
269
|
* the following locals:
|
|
306
270
|
*
|
|
307
271
|
* - `$element` - Current element
|
|
@@ -309,59 +273,20 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
309
273
|
*
|
|
310
274
|
* - `bindings` – `{object=}` – defines bindings between DOM attributes and component properties.
|
|
311
275
|
* Component properties are always bound to the component controller and not to the scope.
|
|
312
|
-
* See {
|
|
313
|
-
* - `transclude` – `{boolean=}` – whether {
|
|
276
|
+
* See {`bindToController`}.
|
|
277
|
+
* - `transclude` – `{boolean=}` – whether {content transclusion} is enabled.
|
|
314
278
|
* Disabled by default.
|
|
315
279
|
* - `require` - `{Object<string, string>=}` - requires the controllers of other directives and binds them to
|
|
316
280
|
* this component's controller. The object keys specify the property names under which the required
|
|
317
|
-
* controllers (object values) will be bound. See {
|
|
281
|
+
* controllers (object values) will be bound. See {`require`}.
|
|
318
282
|
* - `$...` – additional properties to attach to the directive factory function and the controller
|
|
319
283
|
* constructor function. (This is used by the component router to annotate)
|
|
320
284
|
*
|
|
321
|
-
* @returns {
|
|
322
|
-
* @description
|
|
323
|
-
* Register a **component definition** with the compiler. This is a shorthand for registering a special
|
|
324
|
-
* type of directive, which represents a self-contained UI component in your application. Such components
|
|
325
|
-
* are always isolated (i.e. `scope: {}`) and are always restricted to elements (i.e. `restrict: 'E'`).
|
|
326
|
-
*
|
|
327
|
-
* Component definitions are very simple and do not require as much configuration as defining general
|
|
328
|
-
* directives. Component definitions usually consist only of a template and a controller backing it.
|
|
329
|
-
*
|
|
330
|
-
* In order to make the definition easier, components enforce best practices like use of `controllerAs`,
|
|
331
|
-
* `bindToController`. They always have **isolate scope** and are restricted to elements.
|
|
332
|
-
*
|
|
333
|
-
* Here are a few examples of how you would usually define components:
|
|
334
|
-
*
|
|
335
|
-
* ```js
|
|
336
|
-
* let myMod = angular.module(...);
|
|
337
|
-
* myMod.component('myComp', {
|
|
338
|
-
* template: '<div>My name is {{$ctrl.name}}</div>',
|
|
339
|
-
* controller: function() {
|
|
340
|
-
* this.name = 'shahar';
|
|
341
|
-
* }
|
|
342
|
-
* });
|
|
343
|
-
*
|
|
344
|
-
* myMod.component('myComp', {
|
|
345
|
-
* template: '<div>My name is {{$ctrl.name}}</div>',
|
|
346
|
-
* bindings: {name: '@'}
|
|
347
|
-
* });
|
|
348
|
-
*
|
|
349
|
-
* myMod.component('myComp', {
|
|
350
|
-
* templateUrl: 'views/my-comp.html',
|
|
351
|
-
* controller: 'MyCtrl',
|
|
352
|
-
* controllerAs: 'ctrl',
|
|
353
|
-
* bindings: {name: '@'}
|
|
354
|
-
* });
|
|
355
|
-
*
|
|
356
|
-
* ```
|
|
357
|
-
* For more examples, and an in-depth guide, see the {@link guide/component component guide}.
|
|
358
|
-
*
|
|
359
|
-
* <br />
|
|
360
|
-
* See also {@link ng.$compileProvider#directive $compileProvider.directive()}.
|
|
285
|
+
* @returns {$CompileProvider} the compile provider itself, for chaining of function calls.
|
|
361
286
|
*/
|
|
362
|
-
this.component = function
|
|
287
|
+
this.component = function (name, options) {
|
|
363
288
|
if (!isString(name)) {
|
|
364
|
-
forEach(
|
|
289
|
+
Object.entries(name).forEach(([key, val]) => this.component(key, val));
|
|
365
290
|
return this;
|
|
366
291
|
}
|
|
367
292
|
|
|
@@ -454,11 +379,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
454
379
|
};
|
|
455
380
|
|
|
456
381
|
/**
|
|
457
|
-
* @ngdoc method
|
|
458
|
-
* @name $compileProvider#imgSrcSanitizationTrustedUrlList
|
|
459
|
-
* @kind function
|
|
460
|
-
*
|
|
461
|
-
* @description
|
|
462
382
|
* Retrieves or overrides the default regular expression that is used for determining trusted safe
|
|
463
383
|
* urls during img[src] sanitization.
|
|
464
384
|
*
|
|
@@ -482,16 +402,10 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
482
402
|
};
|
|
483
403
|
|
|
484
404
|
/**
|
|
485
|
-
* @ngdoc method
|
|
486
|
-
* @name $compileProvider#strictComponentBindingsEnabled
|
|
487
|
-
*
|
|
488
405
|
* @param {boolean=} enabled update the strictComponentBindingsEnabled state if provided,
|
|
489
406
|
* otherwise return the current strictComponentBindingsEnabled state.
|
|
490
407
|
* @returns {*} current value if used as getter or itself (chaining) if used as setter
|
|
491
408
|
*
|
|
492
|
-
* @kind function
|
|
493
|
-
*
|
|
494
|
-
* @description
|
|
495
409
|
* Call this method to enable / disable the strict component bindings check. If enabled, the
|
|
496
410
|
* compiler will enforce that all scope / controller bindings of a
|
|
497
411
|
* {@link $compileProvider#directive directive} / {@link $compileProvider#component component}
|
|
@@ -516,10 +430,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
516
430
|
const PROP_CONTEXTS = Object.create(null);
|
|
517
431
|
|
|
518
432
|
/**
|
|
519
|
-
* @ngdoc method
|
|
520
|
-
* @name $compileProvider#addPropertySecurityContext
|
|
521
|
-
* @description
|
|
522
|
-
*
|
|
523
433
|
* Defines the security context for DOM properties bound by ng-prop-*.
|
|
524
434
|
*
|
|
525
435
|
* @param {string} elementName The element name or '*' to match any element.
|
|
@@ -621,11 +531,11 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
621
531
|
/**
|
|
622
532
|
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
623
533
|
* @param {*} $interpolate
|
|
624
|
-
* @param {
|
|
534
|
+
* @param {import("../exception-handler").ExceptionHandlerProvider} $exceptionHandler
|
|
625
535
|
* @param {*} $templateRequest
|
|
626
|
-
* @param {
|
|
536
|
+
* @param {import("../parser/parse").ParseService} $parse
|
|
627
537
|
* @param {*} $controller
|
|
628
|
-
* @param {
|
|
538
|
+
* @param {import('../scope/scope').Scope} $rootScope
|
|
629
539
|
* @param {*} $sce
|
|
630
540
|
* @param {*} $animate
|
|
631
541
|
* @returns
|
|
@@ -641,9 +551,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
641
551
|
$sce,
|
|
642
552
|
$animate,
|
|
643
553
|
) {
|
|
644
|
-
const SIMPLE_ATTR_NAME = /^\w/;
|
|
645
|
-
const specialAttrHolder = window.document.createElement("div");
|
|
646
|
-
|
|
647
554
|
// The onChanges hooks should all be run together in a single digest
|
|
648
555
|
// When changes occur, the call to trigger their hooks will be added to this queue
|
|
649
556
|
let onChangesQueue;
|
|
@@ -677,284 +584,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
677
584
|
}
|
|
678
585
|
}
|
|
679
586
|
|
|
680
|
-
function sanitizeSrcset(value, invokeType) {
|
|
681
|
-
if (!value) {
|
|
682
|
-
return value;
|
|
683
|
-
}
|
|
684
|
-
if (!isString(value)) {
|
|
685
|
-
throw $compileMinErr(
|
|
686
|
-
"srcset",
|
|
687
|
-
'Can\'t pass trusted values to `{0}`: "{1}"',
|
|
688
|
-
invokeType,
|
|
689
|
-
value.toString(),
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
// Such values are a bit too complex to handle automatically inside $sce.
|
|
694
|
-
// Instead, we sanitize each of the URIs individually, which works, even dynamically.
|
|
695
|
-
|
|
696
|
-
// It's not possible to work around this using `$sce.trustAsMediaUrl`.
|
|
697
|
-
// If you want to programmatically set explicitly trusted unsafe URLs, you should use
|
|
698
|
-
// `$sce.trustAsHtml` on the whole `img` tag and inject it into the DOM using the
|
|
699
|
-
// `ng-bind-html` directive.
|
|
700
|
-
|
|
701
|
-
var result = "";
|
|
702
|
-
|
|
703
|
-
// first check if there are spaces because it's not the same pattern
|
|
704
|
-
var trimmedSrcset = trim(value);
|
|
705
|
-
// ( 999x ,| 999w ,| ,|, )
|
|
706
|
-
var srcPattern = /(\s+\d+x\s*,|\s+\d+w\s*,|\s+,|,\s+)/;
|
|
707
|
-
var pattern = /\s/.test(trimmedSrcset) ? srcPattern : /(,)/;
|
|
708
|
-
|
|
709
|
-
// split srcset into tuple of uri and descriptor except for the last item
|
|
710
|
-
var rawUris = trimmedSrcset.split(pattern);
|
|
711
|
-
|
|
712
|
-
// for each tuples
|
|
713
|
-
var nbrUrisWith2parts = Math.floor(rawUris.length / 2);
|
|
714
|
-
for (var i = 0; i < nbrUrisWith2parts; i++) {
|
|
715
|
-
var innerIdx = i * 2;
|
|
716
|
-
// sanitize the uri
|
|
717
|
-
result += $sce.getTrustedMediaUrl(trim(rawUris[innerIdx]));
|
|
718
|
-
// add the descriptor
|
|
719
|
-
result += " " + trim(rawUris[innerIdx + 1]);
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// split the last item into uri and descriptor
|
|
723
|
-
var lastTuple = trim(rawUris[i * 2]).split(/\s/);
|
|
724
|
-
|
|
725
|
-
// sanitize the last uri
|
|
726
|
-
result += $sce.getTrustedMediaUrl(trim(lastTuple[0]));
|
|
727
|
-
|
|
728
|
-
// and add the last descriptor if any
|
|
729
|
-
if (lastTuple.length === 2) {
|
|
730
|
-
result += " " + trim(lastTuple[1]);
|
|
731
|
-
}
|
|
732
|
-
return result;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
class Attributes {
|
|
736
|
-
constructor(element, attributesToCopy) {
|
|
737
|
-
if (attributesToCopy) {
|
|
738
|
-
const keys = Object.keys(attributesToCopy);
|
|
739
|
-
for (let i = 0, l = keys.length; i < l; i++) {
|
|
740
|
-
const key = keys[i];
|
|
741
|
-
this[key] = attributesToCopy[key];
|
|
742
|
-
}
|
|
743
|
-
} else {
|
|
744
|
-
this.$attr = {};
|
|
745
|
-
}
|
|
746
|
-
this.$$element = element;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
/**
|
|
750
|
-
* @ngdoc method
|
|
751
|
-
* @name $compile.directive.Attributes#$normalize
|
|
752
|
-
* @kind function
|
|
753
|
-
*
|
|
754
|
-
* @description
|
|
755
|
-
* Converts an attribute name (e.g. dash/colon/underscore-delimited string, optionally prefixed with `x-` or
|
|
756
|
-
* `data-`) to its normalized, camelCase form.
|
|
757
|
-
*
|
|
758
|
-
* Also there is special case for Moz prefix starting with upper case letter.
|
|
759
|
-
*
|
|
760
|
-
* For further information check out the guide on {@link guide/directive#matching-directives Matching Directives}
|
|
761
|
-
*
|
|
762
|
-
* @param {string} name Name to normalize
|
|
763
|
-
*/
|
|
764
|
-
$normalize = directiveNormalize;
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* @ngdoc method
|
|
768
|
-
* @name $compile.directive.Attributes#$addClass
|
|
769
|
-
* @kind function
|
|
770
|
-
*
|
|
771
|
-
* @description
|
|
772
|
-
* Adds the CSS class value specified by the classVal parameter to the element. If animations
|
|
773
|
-
* are enabled then an animation will be triggered for the class addition.
|
|
774
|
-
*
|
|
775
|
-
* @param {string} classVal The className value that will be added to the element
|
|
776
|
-
*/
|
|
777
|
-
$addClass(classVal) {
|
|
778
|
-
if (classVal && classVal.length > 0) {
|
|
779
|
-
$animate.addClass(this.$$element, classVal);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* @ngdoc method
|
|
785
|
-
* @name $compile.directive.Attributes#$removeClass
|
|
786
|
-
* @kind function
|
|
787
|
-
*
|
|
788
|
-
* @description
|
|
789
|
-
* Removes the CSS class value specified by the classVal parameter from the element. If
|
|
790
|
-
* animations are enabled then an animation will be triggered for the class removal.
|
|
791
|
-
*
|
|
792
|
-
* @param {string} classVal The className value that will be removed from the element
|
|
793
|
-
*/
|
|
794
|
-
$removeClass(classVal) {
|
|
795
|
-
if (classVal && classVal.length > 0) {
|
|
796
|
-
$animate.removeClass(this.$$element, classVal);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
* @ngdoc method
|
|
802
|
-
* @name $compile.directive.Attributes#$updateClass
|
|
803
|
-
* @kind function
|
|
804
|
-
*
|
|
805
|
-
* @description
|
|
806
|
-
* Adds and removes the appropriate CSS class values to the element based on the difference
|
|
807
|
-
* between the new and old CSS class values (specified as newClasses and oldClasses).
|
|
808
|
-
*
|
|
809
|
-
* @param {string} newClasses The current CSS className value
|
|
810
|
-
* @param {string} oldClasses The former CSS className value
|
|
811
|
-
*/
|
|
812
|
-
$updateClass(newClasses, oldClasses) {
|
|
813
|
-
const toAdd = tokenDifference(newClasses, oldClasses);
|
|
814
|
-
if (toAdd && toAdd.length) {
|
|
815
|
-
$animate.addClass(this.$$element, toAdd);
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
const toRemove = tokenDifference(oldClasses, newClasses);
|
|
819
|
-
if (toRemove && toRemove.length) {
|
|
820
|
-
$animate.removeClass(this.$$element, toRemove);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
/**
|
|
825
|
-
* Set a normalized attribute on the element in a way such that all directives
|
|
826
|
-
* can share the attribute. This function properly handles boolean attributes.
|
|
827
|
-
* @param {string} key Normalized key. (ie ngAttribute)
|
|
828
|
-
* @param {string|boolean} value The value to set. If `null` attribute will be deleted.
|
|
829
|
-
* @param {boolean=} writeAttr If false, does not write the value to DOM element attribute.
|
|
830
|
-
* Defaults to true.
|
|
831
|
-
* @param {string=} attrName Optional none normalized name. Defaults to key.
|
|
832
|
-
*/
|
|
833
|
-
$set(key, value, writeAttr, attrName) {
|
|
834
|
-
// TODO: decide whether or not to throw an error if "class"
|
|
835
|
-
// is set through this function since it may cause $updateClass to
|
|
836
|
-
// become unstable.
|
|
837
|
-
|
|
838
|
-
const node = this.$$element[0];
|
|
839
|
-
const booleanKey = getBooleanAttrName(node, key);
|
|
840
|
-
const aliasedKey = ALIASED_ATTR[key];
|
|
841
|
-
let observer = key;
|
|
842
|
-
|
|
843
|
-
if (booleanKey) {
|
|
844
|
-
this.$$element[0][key] = value;
|
|
845
|
-
attrName = booleanKey;
|
|
846
|
-
} else if (aliasedKey) {
|
|
847
|
-
this[aliasedKey] = value;
|
|
848
|
-
observer = aliasedKey;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
this[key] = value;
|
|
852
|
-
|
|
853
|
-
// translate normalized key to actual key
|
|
854
|
-
if (attrName) {
|
|
855
|
-
this.$attr[key] = attrName;
|
|
856
|
-
} else {
|
|
857
|
-
attrName = this.$attr[key];
|
|
858
|
-
if (!attrName) {
|
|
859
|
-
this.$attr[key] = attrName = snakeCase(key, "-");
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
let nodeName = this.$$element[0].nodeName.toLowerCase();
|
|
864
|
-
|
|
865
|
-
// Sanitize img[srcset] values.
|
|
866
|
-
if (nodeName === "img" && key === "srcset") {
|
|
867
|
-
this[key] = value = sanitizeSrcset(value, "$set('srcset', value)");
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
if (writeAttr !== false) {
|
|
871
|
-
if (value === null || isUndefined(value)) {
|
|
872
|
-
this.$$element[0].removeAttribute(attrName);
|
|
873
|
-
//
|
|
874
|
-
} else if (SIMPLE_ATTR_NAME.test(attrName)) {
|
|
875
|
-
// jQuery skips special boolean attrs treatment in XML nodes for
|
|
876
|
-
// historical reasons and hence AngularJS cannot freely call
|
|
877
|
-
// `.attr(attrName, false) with such attributes. To avoid issues
|
|
878
|
-
// in XHTML, call `removeAttr` in such cases instead.
|
|
879
|
-
// See https://github.com/jquery/jquery/issues/4249
|
|
880
|
-
if (booleanKey && value === false) {
|
|
881
|
-
this.$$element[0].removeAttribute(attrName);
|
|
882
|
-
} else {
|
|
883
|
-
this.$$element.attr(attrName, value);
|
|
884
|
-
}
|
|
885
|
-
} else {
|
|
886
|
-
setSpecialAttr(this.$$element[0], attrName, value);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
// fire observers
|
|
891
|
-
const { $$observers } = this;
|
|
892
|
-
if ($$observers) {
|
|
893
|
-
forEach($$observers[observer], (fn) => {
|
|
894
|
-
try {
|
|
895
|
-
fn(value);
|
|
896
|
-
} catch (e) {
|
|
897
|
-
$exceptionHandler(e);
|
|
898
|
-
}
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
/**
|
|
904
|
-
* @ngdoc method
|
|
905
|
-
* @name $compile.directive.Attributes#$observe
|
|
906
|
-
* @kind function
|
|
907
|
-
*
|
|
908
|
-
* @description
|
|
909
|
-
* Observes an interpolated attribute.
|
|
910
|
-
*
|
|
911
|
-
* The observer function will be invoked once during the next `$digest` following
|
|
912
|
-
* compilation. The observer is then invoked whenever the interpolated value
|
|
913
|
-
* changes.
|
|
914
|
-
*
|
|
915
|
-
* @param {string} key Normalized key. (ie ngAttribute) .
|
|
916
|
-
* @param {function(interpolatedValue)} fn Function that will be called whenever
|
|
917
|
-
the interpolated value of the attribute changes.
|
|
918
|
-
* See the {@link guide/interpolation#how-text-and-attribute-bindings-work Interpolation
|
|
919
|
-
* guide} for more info.
|
|
920
|
-
* @returns {function()} Returns a deregistration function for this observer.
|
|
921
|
-
*/
|
|
922
|
-
$observe(key, fn) {
|
|
923
|
-
const $$observers =
|
|
924
|
-
this.$$observers || (this.$$observers = Object.create(null));
|
|
925
|
-
const listeners = $$observers[key] || ($$observers[key] = []);
|
|
926
|
-
|
|
927
|
-
listeners.push(fn);
|
|
928
|
-
$rootScope.$evalAsync(() => {
|
|
929
|
-
if (
|
|
930
|
-
!listeners.$$inter &&
|
|
931
|
-
Object.prototype.hasOwnProperty.call(this, key) &&
|
|
932
|
-
!isUndefined(this[key])
|
|
933
|
-
) {
|
|
934
|
-
// no one registered attribute interpolation function, so lets call it manually
|
|
935
|
-
fn(this[key]);
|
|
936
|
-
}
|
|
937
|
-
});
|
|
938
|
-
|
|
939
|
-
return function () {
|
|
940
|
-
arrayRemove(listeners, fn);
|
|
941
|
-
};
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
function setSpecialAttr(element, attrName, value) {
|
|
946
|
-
// Attributes names that do not start with letters (such as `(click)`) cannot be set using `setAttribute`
|
|
947
|
-
// so we have to jump through some hoops to get such an attribute
|
|
948
|
-
// https://github.com/angular/angular.js/pull/13318
|
|
949
|
-
specialAttrHolder.innerHTML = `<span ${attrName}>`;
|
|
950
|
-
const { attributes } = specialAttrHolder.firstChild;
|
|
951
|
-
const attribute = attributes[0];
|
|
952
|
-
// We have to remove the attribute from its container element before we can add it to the destination element
|
|
953
|
-
attributes.removeNamedItem(attribute.name);
|
|
954
|
-
attribute.value = value;
|
|
955
|
-
element.attributes.setNamedItem(attribute);
|
|
956
|
-
}
|
|
957
|
-
|
|
958
587
|
const startSymbol = $interpolate.startSymbol();
|
|
959
588
|
const endSymbol = $interpolate.endSymbol();
|
|
960
589
|
const denormalizeTemplate =
|
|
@@ -987,20 +616,15 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
987
616
|
ignoreDirective,
|
|
988
617
|
previousCompileContext,
|
|
989
618
|
) {
|
|
990
|
-
|
|
991
|
-
// jquery always rewraps, whereas we need to preserve the original selector so that we can
|
|
992
|
-
// modify it.
|
|
993
|
-
|
|
994
|
-
$compileNodes = JQLite($compileNodes);
|
|
995
|
-
}
|
|
619
|
+
let jqCompileNodes = JQLite($compileNodes);
|
|
996
620
|
|
|
997
621
|
/**
|
|
998
622
|
* @type {CompositeLinkFn}
|
|
999
623
|
*/
|
|
1000
624
|
let compositeLinkFn = compileNodes(
|
|
1001
|
-
|
|
625
|
+
jqCompileNodes,
|
|
1002
626
|
transcludeFn,
|
|
1003
|
-
|
|
627
|
+
jqCompileNodes,
|
|
1004
628
|
maxPriority,
|
|
1005
629
|
ignoreDirective,
|
|
1006
630
|
previousCompileContext,
|
|
@@ -1008,7 +632,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1008
632
|
|
|
1009
633
|
let namespace = null;
|
|
1010
634
|
return function publicLinkFn(scope, cloneConnectFn, options) {
|
|
1011
|
-
if (
|
|
635
|
+
if (!jqCompileNodes) {
|
|
1012
636
|
throw $compileMinErr(
|
|
1013
637
|
"multilink",
|
|
1014
638
|
"This element has already been linked.",
|
|
@@ -1047,7 +671,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1047
671
|
}
|
|
1048
672
|
let $linkNode;
|
|
1049
673
|
if (namespace !== "html") {
|
|
1050
|
-
// When using a directive with replace:true and templateUrl the
|
|
674
|
+
// When using a directive with replace:true and templateUrl the jqCompileNodes
|
|
1051
675
|
// (or a child element inside of them)
|
|
1052
676
|
// might change, so we need to recreate the namespace adapted compileNodes
|
|
1053
677
|
// for call to the link function.
|
|
@@ -1055,17 +679,16 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1055
679
|
$linkNode = JQLite(
|
|
1056
680
|
wrapTemplate(
|
|
1057
681
|
namespace,
|
|
1058
|
-
JQLite("<div></div>").append(
|
|
682
|
+
JQLite("<div></div>").append(jqCompileNodes).html(),
|
|
1059
683
|
),
|
|
1060
684
|
);
|
|
1061
685
|
} else if (cloneConnectFn) {
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
);
|
|
686
|
+
let elements = jqCompileNodes
|
|
687
|
+
.elements()
|
|
688
|
+
.map((element) => element.cloneNode(true));
|
|
689
|
+
$linkNode = new JQLite(elements);
|
|
1067
690
|
} else {
|
|
1068
|
-
$linkNode =
|
|
691
|
+
$linkNode = jqCompileNodes;
|
|
1069
692
|
}
|
|
1070
693
|
|
|
1071
694
|
if (transcludeControllers) {
|
|
@@ -1086,7 +709,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1086
709
|
);
|
|
1087
710
|
|
|
1088
711
|
if (!cloneConnectFn) {
|
|
1089
|
-
|
|
712
|
+
jqCompileNodes = compositeLinkFn = null;
|
|
1090
713
|
}
|
|
1091
714
|
return $linkNode;
|
|
1092
715
|
};
|
|
@@ -1111,12 +734,14 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1111
734
|
* function, which is the a linking function for the node.
|
|
1112
735
|
*
|
|
1113
736
|
* @param {NodeList} nodeList an array of nodes or NodeList to compile
|
|
1114
|
-
* @param {
|
|
737
|
+
* @param {*} transcludeFn A linking function, where the
|
|
1115
738
|
* scope argument is auto-generated to the new child of the transcluded parent scope.
|
|
1116
739
|
* @param {Element=} $rootElement If the nodeList is the root of the compilation tree then
|
|
1117
740
|
* the rootElement must be set the JQLite collection of the compile root. This is
|
|
1118
741
|
* needed so that the JQLite collection items can be replaced with widgets.
|
|
1119
742
|
* @param {number=} maxPriority Max directive priority.
|
|
743
|
+
* @param {*} [ignoreDirective]
|
|
744
|
+
* @param {*} [previousCompileContext]
|
|
1120
745
|
* @returns {Function} A composite linking function of all of the matched directives or null.
|
|
1121
746
|
*/
|
|
1122
747
|
function compileNodes(
|
|
@@ -1137,12 +762,12 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1137
762
|
let nodeLinkFnFound;
|
|
1138
763
|
|
|
1139
764
|
for (let i = 0; i < nodeList.length; i++) {
|
|
1140
|
-
attrs = new Attributes();
|
|
765
|
+
attrs = new Attributes($rootScope, $animate, $exceptionHandler, $sce);
|
|
1141
766
|
|
|
1142
767
|
// We must always refer to `nodeList[i]` hereafter,
|
|
1143
768
|
// since the nodes can be replaced underneath us.
|
|
1144
769
|
directives = collectDirectives(
|
|
1145
|
-
nodeList[i],
|
|
770
|
+
/** @type Element */ (nodeList[i]),
|
|
1146
771
|
[],
|
|
1147
772
|
attrs,
|
|
1148
773
|
i === 0 ? maxPriority : undefined,
|
|
@@ -1322,7 +947,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1322
947
|
* @param {Element} node Node to search.
|
|
1323
948
|
* @param directives An array to which the directives are added to. This array is sorted before
|
|
1324
949
|
* the function returns.
|
|
1325
|
-
* @param attrs The shared attrs object which is used to populate the normalized attributes.
|
|
950
|
+
* @param {Attributes} attrs The shared attrs object which is used to populate the normalized attributes.
|
|
1326
951
|
* @param {number=} maxPriority Max directive priority.
|
|
1327
952
|
*/
|
|
1328
953
|
function collectDirectives(
|
|
@@ -1577,7 +1202,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1577
1202
|
* this needs to be pre-sorted by priority order.
|
|
1578
1203
|
* @param {Node} compileNode The raw DOM node to apply the compile functions to
|
|
1579
1204
|
* @param {Object} templateAttrs The shared attribute function
|
|
1580
|
-
* @param {function(
|
|
1205
|
+
* @param {function(import('../../core/scope/scope').Scope, Function=):any} transcludeFn A linking function, where the
|
|
1581
1206
|
* scope argument is auto-generated to the new
|
|
1582
1207
|
* child of the transcluded parent scope.
|
|
1583
1208
|
* @param {JQLite} jqCollection If we are working on the root of the compile tree then this
|
|
@@ -1585,9 +1210,9 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1585
1210
|
* on it.
|
|
1586
1211
|
* @param {Object=} originalReplaceDirective An optional directive that will be ignored when
|
|
1587
1212
|
* compiling the transclusion.
|
|
1588
|
-
* @param {Array.<Function>} preLinkFns
|
|
1589
|
-
* @param {Array.<Function>} postLinkFns
|
|
1590
|
-
* @param {Object} previousCompileContext Context used for previous compilation of the current
|
|
1213
|
+
* @param {Array.<Function>} [preLinkFns]
|
|
1214
|
+
* @param {Array.<Function>} [postLinkFns]
|
|
1215
|
+
* @param {Object} [previousCompileContext] Context used for previous compilation of the current
|
|
1591
1216
|
* node
|
|
1592
1217
|
* @returns {Function} linkFn
|
|
1593
1218
|
*/
|
|
@@ -1632,7 +1257,11 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1632
1257
|
|
|
1633
1258
|
// collect multiblock sections
|
|
1634
1259
|
if (attrStart) {
|
|
1635
|
-
$compileNode = groupScan(
|
|
1260
|
+
$compileNode = groupScan(
|
|
1261
|
+
/** @type {Element} */ (compileNode),
|
|
1262
|
+
attrStart,
|
|
1263
|
+
attrEnd,
|
|
1264
|
+
);
|
|
1636
1265
|
}
|
|
1637
1266
|
$template = undefined;
|
|
1638
1267
|
|
|
@@ -2064,7 +1693,14 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2064
1693
|
$element = templateAttrs.$$element;
|
|
2065
1694
|
} else {
|
|
2066
1695
|
$element = JQLite(linkNode);
|
|
2067
|
-
attrs = new Attributes(
|
|
1696
|
+
attrs = new Attributes(
|
|
1697
|
+
$rootScope,
|
|
1698
|
+
$animate,
|
|
1699
|
+
$exceptionHandler,
|
|
1700
|
+
$sce,
|
|
1701
|
+
$element,
|
|
1702
|
+
templateAttrs,
|
|
1703
|
+
);
|
|
2068
1704
|
}
|
|
2069
1705
|
|
|
2070
1706
|
controllerScope = scope;
|
|
@@ -3194,7 +2830,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
3194
2830
|
destination[scopeName] = lastValue;
|
|
3195
2831
|
}
|
|
3196
2832
|
initialChanges[scopeName] = new SimpleChange(
|
|
3197
|
-
|
|
2833
|
+
UNINITALIZED_VALIED,
|
|
3198
2834
|
destination[scopeName],
|
|
3199
2835
|
);
|
|
3200
2836
|
removeWatchCollection.push(removeWatch);
|
|
@@ -3271,7 +2907,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
3271
2907
|
|
|
3272
2908
|
var initialValue = (destination[scopeName] = parentGet(scope));
|
|
3273
2909
|
initialChanges[scopeName] = new SimpleChange(
|
|
3274
|
-
|
|
2910
|
+
UNINITALIZED_VALIED,
|
|
3275
2911
|
destination[scopeName],
|
|
3276
2912
|
);
|
|
3277
2913
|
|
|
@@ -3369,25 +3005,10 @@ class SimpleChange {
|
|
|
3369
3005
|
* @returns {boolean}
|
|
3370
3006
|
*/
|
|
3371
3007
|
isFirstChange() {
|
|
3372
|
-
return this.previousValue ===
|
|
3008
|
+
return this.previousValue === UNINITALIZED_VALIED;
|
|
3373
3009
|
}
|
|
3374
3010
|
}
|
|
3375
3011
|
|
|
3376
|
-
function tokenDifference(str1, str2) {
|
|
3377
|
-
let values = "";
|
|
3378
|
-
const tokens1 = str1.split(/\s+/);
|
|
3379
|
-
const tokens2 = str2.split(/\s+/);
|
|
3380
|
-
|
|
3381
|
-
outer: for (let i = 0; i < tokens1.length; i++) {
|
|
3382
|
-
const token = tokens1[i];
|
|
3383
|
-
for (let j = 0; j < tokens2.length; j++) {
|
|
3384
|
-
if (token === tokens2[j]) continue outer;
|
|
3385
|
-
}
|
|
3386
|
-
values += (values.length > 0 ? " " : "") + token;
|
|
3387
|
-
}
|
|
3388
|
-
return values;
|
|
3389
|
-
}
|
|
3390
|
-
|
|
3391
3012
|
function removeComments(jqNodes) {
|
|
3392
3013
|
jqNodes = JQLite(jqNodes);
|
|
3393
3014
|
let i = jqNodes.length;
|
|
@@ -3407,3 +3028,25 @@ function removeComments(jqNodes) {
|
|
|
3407
3028
|
}
|
|
3408
3029
|
return jqNodes;
|
|
3409
3030
|
}
|
|
3031
|
+
|
|
3032
|
+
/**
|
|
3033
|
+
* @param {String} name
|
|
3034
|
+
* @returns {void}
|
|
3035
|
+
*/
|
|
3036
|
+
function assertValidDirectiveName(name) {
|
|
3037
|
+
const letter = name.charAt(0);
|
|
3038
|
+
if (!letter || letter !== lowercase(letter)) {
|
|
3039
|
+
throw $compileMinErr(
|
|
3040
|
+
"baddir",
|
|
3041
|
+
"Directive/Component name '{0}' is invalid. The first character must be a lowercase letter",
|
|
3042
|
+
name,
|
|
3043
|
+
);
|
|
3044
|
+
}
|
|
3045
|
+
if (name !== name.trim()) {
|
|
3046
|
+
throw $compileMinErr(
|
|
3047
|
+
"baddir",
|
|
3048
|
+
"Directive/Component name '{0}' is invalid. The name should not contain leading or trailing whitespaces",
|
|
3049
|
+
name,
|
|
3050
|
+
);
|
|
3051
|
+
}
|
|
3052
|
+
}
|