@angular-wave/angular.ts 0.0.69 → 0.0.71
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/shared.js +14 -5
- package/src/core/compile/attributes.js +326 -0
- package/src/core/compile/compile.js +76 -434
- package/src/core/compile/compile.spec.js +2 -2
- 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/scope/scope.js +4 -8
- package/src/{exts → directive}/aria/aria.html +1 -1
- package/src/directive/aria/aria.js +382 -0
- package/src/{exts → directive}/aria/aria.spec.js +12 -12
- package/src/{exts → directive}/aria/aria.test.js +1 -1
- package/src/directive/form/form.js +3 -1
- package/src/directive/messages/messages.js +268 -274
- package/src/filters/filter.js +0 -3
- package/src/filters/limit-to.js +0 -1
- package/src/public.js +27 -3
- 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/shared/jqlite/jqlite.js +13 -1
- package/src/shared/utils.js +0 -2
- package/src/types.js +1 -1
- 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/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 +21 -22
- package/types/directive/aria/aria.d.ts +94 -0
- 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 +8 -4
- package/types/shared/utils.d.ts +0 -2
- package/types/types.d.ts +1 -1
- package/src/exts/aria/aria.js +0 -415
- package/types/exts/aria/aria.d.ts +0 -1
- /package/src/{exts → directive}/aria/aria.md +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}
|
|
@@ -512,15 +426,10 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
512
426
|
|
|
513
427
|
/**
|
|
514
428
|
* The security context of DOM Properties.
|
|
515
|
-
* @private
|
|
516
429
|
*/
|
|
517
430
|
const PROP_CONTEXTS = Object.create(null);
|
|
518
431
|
|
|
519
432
|
/**
|
|
520
|
-
* @ngdoc method
|
|
521
|
-
* @name $compileProvider#addPropertySecurityContext
|
|
522
|
-
* @description
|
|
523
|
-
*
|
|
524
433
|
* Defines the security context for DOM properties bound by ng-prop-*.
|
|
525
434
|
*
|
|
526
435
|
* @param {string} elementName The element name or '*' to match any element.
|
|
@@ -622,11 +531,11 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
622
531
|
/**
|
|
623
532
|
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
624
533
|
* @param {*} $interpolate
|
|
625
|
-
* @param {
|
|
534
|
+
* @param {import("../exception-handler").ExceptionHandlerProvider} $exceptionHandler
|
|
626
535
|
* @param {*} $templateRequest
|
|
627
|
-
* @param {
|
|
536
|
+
* @param {import("../parser/parse").ParseService} $parse
|
|
628
537
|
* @param {*} $controller
|
|
629
|
-
* @param {
|
|
538
|
+
* @param {import('../scope/scope').Scope} $rootScope
|
|
630
539
|
* @param {*} $sce
|
|
631
540
|
* @param {*} $animate
|
|
632
541
|
* @returns
|
|
@@ -642,9 +551,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
642
551
|
$sce,
|
|
643
552
|
$animate,
|
|
644
553
|
) {
|
|
645
|
-
const SIMPLE_ATTR_NAME = /^\w/;
|
|
646
|
-
const specialAttrHolder = window.document.createElement("div");
|
|
647
|
-
|
|
648
554
|
// The onChanges hooks should all be run together in a single digest
|
|
649
555
|
// When changes occur, the call to trigger their hooks will be added to this queue
|
|
650
556
|
let onChangesQueue;
|
|
@@ -678,284 +584,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
678
584
|
}
|
|
679
585
|
}
|
|
680
586
|
|
|
681
|
-
function sanitizeSrcset(value, invokeType) {
|
|
682
|
-
if (!value) {
|
|
683
|
-
return value;
|
|
684
|
-
}
|
|
685
|
-
if (!isString(value)) {
|
|
686
|
-
throw $compileMinErr(
|
|
687
|
-
"srcset",
|
|
688
|
-
'Can\'t pass trusted values to `{0}`: "{1}"',
|
|
689
|
-
invokeType,
|
|
690
|
-
value.toString(),
|
|
691
|
-
);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
// Such values are a bit too complex to handle automatically inside $sce.
|
|
695
|
-
// Instead, we sanitize each of the URIs individually, which works, even dynamically.
|
|
696
|
-
|
|
697
|
-
// It's not possible to work around this using `$sce.trustAsMediaUrl`.
|
|
698
|
-
// If you want to programmatically set explicitly trusted unsafe URLs, you should use
|
|
699
|
-
// `$sce.trustAsHtml` on the whole `img` tag and inject it into the DOM using the
|
|
700
|
-
// `ng-bind-html` directive.
|
|
701
|
-
|
|
702
|
-
var result = "";
|
|
703
|
-
|
|
704
|
-
// first check if there are spaces because it's not the same pattern
|
|
705
|
-
var trimmedSrcset = trim(value);
|
|
706
|
-
// ( 999x ,| 999w ,| ,|, )
|
|
707
|
-
var srcPattern = /(\s+\d+x\s*,|\s+\d+w\s*,|\s+,|,\s+)/;
|
|
708
|
-
var pattern = /\s/.test(trimmedSrcset) ? srcPattern : /(,)/;
|
|
709
|
-
|
|
710
|
-
// split srcset into tuple of uri and descriptor except for the last item
|
|
711
|
-
var rawUris = trimmedSrcset.split(pattern);
|
|
712
|
-
|
|
713
|
-
// for each tuples
|
|
714
|
-
var nbrUrisWith2parts = Math.floor(rawUris.length / 2);
|
|
715
|
-
for (var i = 0; i < nbrUrisWith2parts; i++) {
|
|
716
|
-
var innerIdx = i * 2;
|
|
717
|
-
// sanitize the uri
|
|
718
|
-
result += $sce.getTrustedMediaUrl(trim(rawUris[innerIdx]));
|
|
719
|
-
// add the descriptor
|
|
720
|
-
result += " " + trim(rawUris[innerIdx + 1]);
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
// split the last item into uri and descriptor
|
|
724
|
-
var lastTuple = trim(rawUris[i * 2]).split(/\s/);
|
|
725
|
-
|
|
726
|
-
// sanitize the last uri
|
|
727
|
-
result += $sce.getTrustedMediaUrl(trim(lastTuple[0]));
|
|
728
|
-
|
|
729
|
-
// and add the last descriptor if any
|
|
730
|
-
if (lastTuple.length === 2) {
|
|
731
|
-
result += " " + trim(lastTuple[1]);
|
|
732
|
-
}
|
|
733
|
-
return result;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
class Attributes {
|
|
737
|
-
constructor(element, attributesToCopy) {
|
|
738
|
-
if (attributesToCopy) {
|
|
739
|
-
const keys = Object.keys(attributesToCopy);
|
|
740
|
-
for (let i = 0, l = keys.length; i < l; i++) {
|
|
741
|
-
const key = keys[i];
|
|
742
|
-
this[key] = attributesToCopy[key];
|
|
743
|
-
}
|
|
744
|
-
} else {
|
|
745
|
-
this.$attr = {};
|
|
746
|
-
}
|
|
747
|
-
this.$$element = element;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
* @ngdoc method
|
|
752
|
-
* @name $compile.directive.Attributes#$normalize
|
|
753
|
-
* @kind function
|
|
754
|
-
*
|
|
755
|
-
* @description
|
|
756
|
-
* Converts an attribute name (e.g. dash/colon/underscore-delimited string, optionally prefixed with `x-` or
|
|
757
|
-
* `data-`) to its normalized, camelCase form.
|
|
758
|
-
*
|
|
759
|
-
* Also there is special case for Moz prefix starting with upper case letter.
|
|
760
|
-
*
|
|
761
|
-
* For further information check out the guide on {@link guide/directive#matching-directives Matching Directives}
|
|
762
|
-
*
|
|
763
|
-
* @param {string} name Name to normalize
|
|
764
|
-
*/
|
|
765
|
-
$normalize = directiveNormalize;
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* @ngdoc method
|
|
769
|
-
* @name $compile.directive.Attributes#$addClass
|
|
770
|
-
* @kind function
|
|
771
|
-
*
|
|
772
|
-
* @description
|
|
773
|
-
* Adds the CSS class value specified by the classVal parameter to the element. If animations
|
|
774
|
-
* are enabled then an animation will be triggered for the class addition.
|
|
775
|
-
*
|
|
776
|
-
* @param {string} classVal The className value that will be added to the element
|
|
777
|
-
*/
|
|
778
|
-
$addClass(classVal) {
|
|
779
|
-
if (classVal && classVal.length > 0) {
|
|
780
|
-
$animate.addClass(this.$$element, classVal);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
/**
|
|
785
|
-
* @ngdoc method
|
|
786
|
-
* @name $compile.directive.Attributes#$removeClass
|
|
787
|
-
* @kind function
|
|
788
|
-
*
|
|
789
|
-
* @description
|
|
790
|
-
* Removes the CSS class value specified by the classVal parameter from the element. If
|
|
791
|
-
* animations are enabled then an animation will be triggered for the class removal.
|
|
792
|
-
*
|
|
793
|
-
* @param {string} classVal The className value that will be removed from the element
|
|
794
|
-
*/
|
|
795
|
-
$removeClass(classVal) {
|
|
796
|
-
if (classVal && classVal.length > 0) {
|
|
797
|
-
$animate.removeClass(this.$$element, classVal);
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
* @ngdoc method
|
|
803
|
-
* @name $compile.directive.Attributes#$updateClass
|
|
804
|
-
* @kind function
|
|
805
|
-
*
|
|
806
|
-
* @description
|
|
807
|
-
* Adds and removes the appropriate CSS class values to the element based on the difference
|
|
808
|
-
* between the new and old CSS class values (specified as newClasses and oldClasses).
|
|
809
|
-
*
|
|
810
|
-
* @param {string} newClasses The current CSS className value
|
|
811
|
-
* @param {string} oldClasses The former CSS className value
|
|
812
|
-
*/
|
|
813
|
-
$updateClass(newClasses, oldClasses) {
|
|
814
|
-
const toAdd = tokenDifference(newClasses, oldClasses);
|
|
815
|
-
if (toAdd && toAdd.length) {
|
|
816
|
-
$animate.addClass(this.$$element, toAdd);
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
const toRemove = tokenDifference(oldClasses, newClasses);
|
|
820
|
-
if (toRemove && toRemove.length) {
|
|
821
|
-
$animate.removeClass(this.$$element, toRemove);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/**
|
|
826
|
-
* Set a normalized attribute on the element in a way such that all directives
|
|
827
|
-
* can share the attribute. This function properly handles boolean attributes.
|
|
828
|
-
* @param {string} key Normalized key. (ie ngAttribute)
|
|
829
|
-
* @param {string|boolean} value The value to set. If `null` attribute will be deleted.
|
|
830
|
-
* @param {boolean=} writeAttr If false, does not write the value to DOM element attribute.
|
|
831
|
-
* Defaults to true.
|
|
832
|
-
* @param {string=} attrName Optional none normalized name. Defaults to key.
|
|
833
|
-
*/
|
|
834
|
-
$set(key, value, writeAttr, attrName) {
|
|
835
|
-
// TODO: decide whether or not to throw an error if "class"
|
|
836
|
-
// is set through this function since it may cause $updateClass to
|
|
837
|
-
// become unstable.
|
|
838
|
-
|
|
839
|
-
const node = this.$$element[0];
|
|
840
|
-
const booleanKey = getBooleanAttrName(node, key);
|
|
841
|
-
const aliasedKey = ALIASED_ATTR[key];
|
|
842
|
-
let observer = key;
|
|
843
|
-
|
|
844
|
-
if (booleanKey) {
|
|
845
|
-
this.$$element[0][key] = value;
|
|
846
|
-
attrName = booleanKey;
|
|
847
|
-
} else if (aliasedKey) {
|
|
848
|
-
this[aliasedKey] = value;
|
|
849
|
-
observer = aliasedKey;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
this[key] = value;
|
|
853
|
-
|
|
854
|
-
// translate normalized key to actual key
|
|
855
|
-
if (attrName) {
|
|
856
|
-
this.$attr[key] = attrName;
|
|
857
|
-
} else {
|
|
858
|
-
attrName = this.$attr[key];
|
|
859
|
-
if (!attrName) {
|
|
860
|
-
this.$attr[key] = attrName = snakeCase(key, "-");
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
let nodeName = this.$$element[0].nodeName.toLowerCase();
|
|
865
|
-
|
|
866
|
-
// Sanitize img[srcset] values.
|
|
867
|
-
if (nodeName === "img" && key === "srcset") {
|
|
868
|
-
this[key] = value = sanitizeSrcset(value, "$set('srcset', value)");
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
if (writeAttr !== false) {
|
|
872
|
-
if (value === null || isUndefined(value)) {
|
|
873
|
-
this.$$element[0].removeAttribute(attrName);
|
|
874
|
-
//
|
|
875
|
-
} else if (SIMPLE_ATTR_NAME.test(attrName)) {
|
|
876
|
-
// jQuery skips special boolean attrs treatment in XML nodes for
|
|
877
|
-
// historical reasons and hence AngularJS cannot freely call
|
|
878
|
-
// `.attr(attrName, false) with such attributes. To avoid issues
|
|
879
|
-
// in XHTML, call `removeAttr` in such cases instead.
|
|
880
|
-
// See https://github.com/jquery/jquery/issues/4249
|
|
881
|
-
if (booleanKey && value === false) {
|
|
882
|
-
this.$$element[0].removeAttribute(attrName);
|
|
883
|
-
} else {
|
|
884
|
-
this.$$element.attr(attrName, value);
|
|
885
|
-
}
|
|
886
|
-
} else {
|
|
887
|
-
setSpecialAttr(this.$$element[0], attrName, value);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
// fire observers
|
|
892
|
-
const { $$observers } = this;
|
|
893
|
-
if ($$observers) {
|
|
894
|
-
forEach($$observers[observer], (fn) => {
|
|
895
|
-
try {
|
|
896
|
-
fn(value);
|
|
897
|
-
} catch (e) {
|
|
898
|
-
$exceptionHandler(e);
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
/**
|
|
905
|
-
* @ngdoc method
|
|
906
|
-
* @name $compile.directive.Attributes#$observe
|
|
907
|
-
* @kind function
|
|
908
|
-
*
|
|
909
|
-
* @description
|
|
910
|
-
* Observes an interpolated attribute.
|
|
911
|
-
*
|
|
912
|
-
* The observer function will be invoked once during the next `$digest` following
|
|
913
|
-
* compilation. The observer is then invoked whenever the interpolated value
|
|
914
|
-
* changes.
|
|
915
|
-
*
|
|
916
|
-
* @param {string} key Normalized key. (ie ngAttribute) .
|
|
917
|
-
* @param {function(interpolatedValue)} fn Function that will be called whenever
|
|
918
|
-
the interpolated value of the attribute changes.
|
|
919
|
-
* See the {@link guide/interpolation#how-text-and-attribute-bindings-work Interpolation
|
|
920
|
-
* guide} for more info.
|
|
921
|
-
* @returns {function()} Returns a deregistration function for this observer.
|
|
922
|
-
*/
|
|
923
|
-
$observe(key, fn) {
|
|
924
|
-
const $$observers =
|
|
925
|
-
this.$$observers || (this.$$observers = Object.create(null));
|
|
926
|
-
const listeners = $$observers[key] || ($$observers[key] = []);
|
|
927
|
-
|
|
928
|
-
listeners.push(fn);
|
|
929
|
-
$rootScope.$evalAsync(() => {
|
|
930
|
-
if (
|
|
931
|
-
!listeners.$$inter &&
|
|
932
|
-
Object.prototype.hasOwnProperty.call(this, key) &&
|
|
933
|
-
!isUndefined(this[key])
|
|
934
|
-
) {
|
|
935
|
-
// no one registered attribute interpolation function, so lets call it manually
|
|
936
|
-
fn(this[key]);
|
|
937
|
-
}
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
return function () {
|
|
941
|
-
arrayRemove(listeners, fn);
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
function setSpecialAttr(element, attrName, value) {
|
|
947
|
-
// Attributes names that do not start with letters (such as `(click)`) cannot be set using `setAttribute`
|
|
948
|
-
// so we have to jump through some hoops to get such an attribute
|
|
949
|
-
// https://github.com/angular/angular.js/pull/13318
|
|
950
|
-
specialAttrHolder.innerHTML = `<span ${attrName}>`;
|
|
951
|
-
const { attributes } = specialAttrHolder.firstChild;
|
|
952
|
-
const attribute = attributes[0];
|
|
953
|
-
// We have to remove the attribute from its container element before we can add it to the destination element
|
|
954
|
-
attributes.removeNamedItem(attribute.name);
|
|
955
|
-
attribute.value = value;
|
|
956
|
-
element.attributes.setNamedItem(attribute);
|
|
957
|
-
}
|
|
958
|
-
|
|
959
587
|
const startSymbol = $interpolate.startSymbol();
|
|
960
588
|
const endSymbol = $interpolate.endSymbol();
|
|
961
589
|
const denormalizeTemplate =
|
|
@@ -988,20 +616,15 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
988
616
|
ignoreDirective,
|
|
989
617
|
previousCompileContext,
|
|
990
618
|
) {
|
|
991
|
-
|
|
992
|
-
// jquery always rewraps, whereas we need to preserve the original selector so that we can
|
|
993
|
-
// modify it.
|
|
994
|
-
|
|
995
|
-
$compileNodes = JQLite($compileNodes);
|
|
996
|
-
}
|
|
619
|
+
let jqCompileNodes = JQLite($compileNodes);
|
|
997
620
|
|
|
998
621
|
/**
|
|
999
622
|
* @type {CompositeLinkFn}
|
|
1000
623
|
*/
|
|
1001
624
|
let compositeLinkFn = compileNodes(
|
|
1002
|
-
|
|
625
|
+
jqCompileNodes,
|
|
1003
626
|
transcludeFn,
|
|
1004
|
-
|
|
627
|
+
jqCompileNodes,
|
|
1005
628
|
maxPriority,
|
|
1006
629
|
ignoreDirective,
|
|
1007
630
|
previousCompileContext,
|
|
@@ -1009,7 +632,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1009
632
|
|
|
1010
633
|
let namespace = null;
|
|
1011
634
|
return function publicLinkFn(scope, cloneConnectFn, options) {
|
|
1012
|
-
if (
|
|
635
|
+
if (!jqCompileNodes) {
|
|
1013
636
|
throw $compileMinErr(
|
|
1014
637
|
"multilink",
|
|
1015
638
|
"This element has already been linked.",
|
|
@@ -1048,7 +671,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1048
671
|
}
|
|
1049
672
|
let $linkNode;
|
|
1050
673
|
if (namespace !== "html") {
|
|
1051
|
-
// When using a directive with replace:true and templateUrl the
|
|
674
|
+
// When using a directive with replace:true and templateUrl the jqCompileNodes
|
|
1052
675
|
// (or a child element inside of them)
|
|
1053
676
|
// might change, so we need to recreate the namespace adapted compileNodes
|
|
1054
677
|
// for call to the link function.
|
|
@@ -1056,17 +679,16 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1056
679
|
$linkNode = JQLite(
|
|
1057
680
|
wrapTemplate(
|
|
1058
681
|
namespace,
|
|
1059
|
-
JQLite("<div></div>").append(
|
|
682
|
+
JQLite("<div></div>").append(jqCompileNodes).html(),
|
|
1060
683
|
),
|
|
1061
684
|
);
|
|
1062
685
|
} else if (cloneConnectFn) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
);
|
|
686
|
+
let elements = jqCompileNodes
|
|
687
|
+
.elements()
|
|
688
|
+
.map((element) => element.cloneNode(true));
|
|
689
|
+
$linkNode = new JQLite(elements);
|
|
1068
690
|
} else {
|
|
1069
|
-
$linkNode =
|
|
691
|
+
$linkNode = jqCompileNodes;
|
|
1070
692
|
}
|
|
1071
693
|
|
|
1072
694
|
if (transcludeControllers) {
|
|
@@ -1087,7 +709,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1087
709
|
);
|
|
1088
710
|
|
|
1089
711
|
if (!cloneConnectFn) {
|
|
1090
|
-
|
|
712
|
+
jqCompileNodes = compositeLinkFn = null;
|
|
1091
713
|
}
|
|
1092
714
|
return $linkNode;
|
|
1093
715
|
};
|
|
@@ -1112,12 +734,14 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1112
734
|
* function, which is the a linking function for the node.
|
|
1113
735
|
*
|
|
1114
736
|
* @param {NodeList} nodeList an array of nodes or NodeList to compile
|
|
1115
|
-
* @param {
|
|
737
|
+
* @param {*} transcludeFn A linking function, where the
|
|
1116
738
|
* scope argument is auto-generated to the new child of the transcluded parent scope.
|
|
1117
739
|
* @param {Element=} $rootElement If the nodeList is the root of the compilation tree then
|
|
1118
740
|
* the rootElement must be set the JQLite collection of the compile root. This is
|
|
1119
741
|
* needed so that the JQLite collection items can be replaced with widgets.
|
|
1120
742
|
* @param {number=} maxPriority Max directive priority.
|
|
743
|
+
* @param {*} [ignoreDirective]
|
|
744
|
+
* @param {*} [previousCompileContext]
|
|
1121
745
|
* @returns {Function} A composite linking function of all of the matched directives or null.
|
|
1122
746
|
*/
|
|
1123
747
|
function compileNodes(
|
|
@@ -1138,12 +762,12 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1138
762
|
let nodeLinkFnFound;
|
|
1139
763
|
|
|
1140
764
|
for (let i = 0; i < nodeList.length; i++) {
|
|
1141
|
-
attrs = new Attributes();
|
|
765
|
+
attrs = new Attributes($rootScope, $animate, $exceptionHandler, $sce);
|
|
1142
766
|
|
|
1143
767
|
// We must always refer to `nodeList[i]` hereafter,
|
|
1144
768
|
// since the nodes can be replaced underneath us.
|
|
1145
769
|
directives = collectDirectives(
|
|
1146
|
-
nodeList[i],
|
|
770
|
+
/** @type Element */ (nodeList[i]),
|
|
1147
771
|
[],
|
|
1148
772
|
attrs,
|
|
1149
773
|
i === 0 ? maxPriority : undefined,
|
|
@@ -1323,7 +947,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1323
947
|
* @param {Element} node Node to search.
|
|
1324
948
|
* @param directives An array to which the directives are added to. This array is sorted before
|
|
1325
949
|
* the function returns.
|
|
1326
|
-
* @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.
|
|
1327
951
|
* @param {number=} maxPriority Max directive priority.
|
|
1328
952
|
*/
|
|
1329
953
|
function collectDirectives(
|
|
@@ -1578,7 +1202,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1578
1202
|
* this needs to be pre-sorted by priority order.
|
|
1579
1203
|
* @param {Node} compileNode The raw DOM node to apply the compile functions to
|
|
1580
1204
|
* @param {Object} templateAttrs The shared attribute function
|
|
1581
|
-
* @param {function(
|
|
1205
|
+
* @param {function(import('../../core/scope/scope').Scope, Function=):any} transcludeFn A linking function, where the
|
|
1582
1206
|
* scope argument is auto-generated to the new
|
|
1583
1207
|
* child of the transcluded parent scope.
|
|
1584
1208
|
* @param {JQLite} jqCollection If we are working on the root of the compile tree then this
|
|
@@ -1586,9 +1210,9 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1586
1210
|
* on it.
|
|
1587
1211
|
* @param {Object=} originalReplaceDirective An optional directive that will be ignored when
|
|
1588
1212
|
* compiling the transclusion.
|
|
1589
|
-
* @param {Array.<Function>} preLinkFns
|
|
1590
|
-
* @param {Array.<Function>} postLinkFns
|
|
1591
|
-
* @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
|
|
1592
1216
|
* node
|
|
1593
1217
|
* @returns {Function} linkFn
|
|
1594
1218
|
*/
|
|
@@ -1633,7 +1257,11 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1633
1257
|
|
|
1634
1258
|
// collect multiblock sections
|
|
1635
1259
|
if (attrStart) {
|
|
1636
|
-
$compileNode = groupScan(
|
|
1260
|
+
$compileNode = groupScan(
|
|
1261
|
+
/** @type {Element} */ (compileNode),
|
|
1262
|
+
attrStart,
|
|
1263
|
+
attrEnd,
|
|
1264
|
+
);
|
|
1637
1265
|
}
|
|
1638
1266
|
$template = undefined;
|
|
1639
1267
|
|
|
@@ -2065,7 +1693,14 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2065
1693
|
$element = templateAttrs.$$element;
|
|
2066
1694
|
} else {
|
|
2067
1695
|
$element = JQLite(linkNode);
|
|
2068
|
-
attrs = new Attributes(
|
|
1696
|
+
attrs = new Attributes(
|
|
1697
|
+
$rootScope,
|
|
1698
|
+
$animate,
|
|
1699
|
+
$exceptionHandler,
|
|
1700
|
+
$sce,
|
|
1701
|
+
$element,
|
|
1702
|
+
templateAttrs,
|
|
1703
|
+
);
|
|
2069
1704
|
}
|
|
2070
1705
|
|
|
2071
1706
|
controllerScope = scope;
|
|
@@ -3195,7 +2830,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
3195
2830
|
destination[scopeName] = lastValue;
|
|
3196
2831
|
}
|
|
3197
2832
|
initialChanges[scopeName] = new SimpleChange(
|
|
3198
|
-
|
|
2833
|
+
UNINITALIZED_VALIED,
|
|
3199
2834
|
destination[scopeName],
|
|
3200
2835
|
);
|
|
3201
2836
|
removeWatchCollection.push(removeWatch);
|
|
@@ -3272,7 +2907,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
3272
2907
|
|
|
3273
2908
|
var initialValue = (destination[scopeName] = parentGet(scope));
|
|
3274
2909
|
initialChanges[scopeName] = new SimpleChange(
|
|
3275
|
-
|
|
2910
|
+
UNINITALIZED_VALIED,
|
|
3276
2911
|
destination[scopeName],
|
|
3277
2912
|
);
|
|
3278
2913
|
|
|
@@ -3370,25 +3005,10 @@ class SimpleChange {
|
|
|
3370
3005
|
* @returns {boolean}
|
|
3371
3006
|
*/
|
|
3372
3007
|
isFirstChange() {
|
|
3373
|
-
return this.previousValue ===
|
|
3008
|
+
return this.previousValue === UNINITALIZED_VALIED;
|
|
3374
3009
|
}
|
|
3375
3010
|
}
|
|
3376
3011
|
|
|
3377
|
-
function tokenDifference(str1, str2) {
|
|
3378
|
-
let values = "";
|
|
3379
|
-
const tokens1 = str1.split(/\s+/);
|
|
3380
|
-
const tokens2 = str2.split(/\s+/);
|
|
3381
|
-
|
|
3382
|
-
outer: for (let i = 0; i < tokens1.length; i++) {
|
|
3383
|
-
const token = tokens1[i];
|
|
3384
|
-
for (let j = 0; j < tokens2.length; j++) {
|
|
3385
|
-
if (token === tokens2[j]) continue outer;
|
|
3386
|
-
}
|
|
3387
|
-
values += (values.length > 0 ? " " : "") + token;
|
|
3388
|
-
}
|
|
3389
|
-
return values;
|
|
3390
|
-
}
|
|
3391
|
-
|
|
3392
3012
|
function removeComments(jqNodes) {
|
|
3393
3013
|
jqNodes = JQLite(jqNodes);
|
|
3394
3014
|
let i = jqNodes.length;
|
|
@@ -3408,3 +3028,25 @@ function removeComments(jqNodes) {
|
|
|
3408
3028
|
}
|
|
3409
3029
|
return jqNodes;
|
|
3410
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
|
+
}
|