@angular-wave/angular.ts 0.6.4 → 0.6.5
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-js.js +1 -1
- package/src/animations/animation.js +1 -1
- package/src/core/compile/attributes.js +21 -4
- package/src/core/compile/compile.js +66 -109
- package/src/core/compile/compile.spec.js +3 -1
- package/src/core/controller/controller.js +1 -1
- package/src/core/di/internal-injector.js +1 -1
- package/src/core/filter/filter.js +1 -1
- package/src/core/q/q.js +1 -1
- package/src/core/sce/sce.js +1 -1
- package/src/core/scope/scope.js +2 -2
- package/src/core/timeout/timeout.js +1 -1
- package/src/directive/channel/channel.js +25 -7
- package/src/directive/channel/channel.spec.js +17 -0
- package/src/directive/events/events.js +1 -1
- package/src/directive/model/model.js +1 -1
- package/src/loader.js +4 -13
- package/src/router/common/coreservices.js +1 -1
- package/src/router/state/state-registry.js +1 -1
- package/src/router/template-factory.js +8 -7
- package/src/router/url/url-matcher.js +1 -1
- package/src/services/http/http.js +1 -1
- package/src/services/template-request.js +1 -1
- package/types/animations/animate-js.d.ts +1 -1
- package/types/animations/animation.d.ts +1 -1
- package/types/core/compile/compile.d.ts +2 -1
- package/types/core/controller/controller.d.ts +1 -1
- package/types/core/filter/filter.d.ts +1 -1
- package/types/core/q/q.d.ts +1 -1
- package/types/core/sce/sce.d.ts +1 -1
- package/types/core/scope/scope.d.ts +1 -1
- package/types/core/timeout/timeout.d.ts +1 -1
- package/types/directive/channel/channel.d.ts +13 -4
- package/types/directive/model/model.d.ts +8 -8
- package/types/directive/repeat/repeat.d.ts +10 -7
- package/types/loader.d.ts +4 -7
- package/types/router/common/coreservices.d.ts +1 -1
- package/types/router/state/state-registry.d.ts +2 -2
- package/types/router/template-factory.d.ts +2 -2
- package/types/services/http/http.d.ts +1 -1
- package/types/services/template-request.d.ts +1 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@angular-wave/angular.ts",
|
|
3
3
|
"description": "A modern, optimized and typesafe version of AngularJS",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/angular-ts.esm.js",
|
|
8
8
|
"browser": "dist/angular-ts.umd.js",
|
|
@@ -15,7 +15,7 @@ export function AnimateJsProvider($animateProvider) {
|
|
|
15
15
|
"$$AnimateRunner",
|
|
16
16
|
/**
|
|
17
17
|
*
|
|
18
|
-
* @param {import("../core/di/internal-injector").InjectorService} $injector
|
|
18
|
+
* @param {import("../core/di/internal-injector.js").InjectorService} $injector
|
|
19
19
|
* @param {*} $$AnimateRunner
|
|
20
20
|
* @returns
|
|
21
21
|
*/
|
|
@@ -38,7 +38,7 @@ export function AnimationProvider() {
|
|
|
38
38
|
/**
|
|
39
39
|
*
|
|
40
40
|
* @param {*} $rootScope
|
|
41
|
-
* @param {import("../core/di/internal-injector").InjectorService} $injector
|
|
41
|
+
* @param {import("../core/di/internal-injector.js").InjectorService} $injector
|
|
42
42
|
* @param {*} $$AnimateRunner
|
|
43
43
|
* @param {import("./raf-scheduler").RafScheduler} $$rAFScheduler
|
|
44
44
|
* @param {*} $$animateCache
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
minErr,
|
|
8
8
|
trim,
|
|
9
9
|
directiveNormalize,
|
|
10
|
+
hasAnimate,
|
|
10
11
|
} from "../../shared/utils.js";
|
|
11
12
|
import { ALIASED_ATTR } from "../../shared/constants.js";
|
|
12
13
|
|
|
@@ -75,7 +76,11 @@ export class Attributes {
|
|
|
75
76
|
*/
|
|
76
77
|
$addClass(classVal) {
|
|
77
78
|
if (classVal && classVal.length > 0) {
|
|
78
|
-
|
|
79
|
+
if (hasAnimate(this.$$element[0])) {
|
|
80
|
+
this.$animate.addClass(this.$$element, classVal);
|
|
81
|
+
} else {
|
|
82
|
+
this.$$element[0].classList.add(classVal.trim());
|
|
83
|
+
}
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
|
|
@@ -87,7 +92,11 @@ export class Attributes {
|
|
|
87
92
|
*/
|
|
88
93
|
$removeClass(classVal) {
|
|
89
94
|
if (classVal && classVal.length > 0) {
|
|
90
|
-
|
|
95
|
+
if (hasAnimate(this.$$element[0])) {
|
|
96
|
+
this.$animate.removeClass(this.$$element, classVal);
|
|
97
|
+
} else {
|
|
98
|
+
this.$$element[0].classList.remove(classVal.trim());
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
|
|
@@ -101,12 +110,20 @@ export class Attributes {
|
|
|
101
110
|
$updateClass(newClasses, oldClasses) {
|
|
102
111
|
const toAdd = tokenDifference(newClasses, oldClasses);
|
|
103
112
|
if (toAdd && toAdd.length) {
|
|
104
|
-
|
|
113
|
+
if (hasAnimate(this.$$element[0])) {
|
|
114
|
+
this.$animate.addClass(this.$$element, toAdd);
|
|
115
|
+
} else {
|
|
116
|
+
this.$$element[0].classList.add(...toAdd.trim().split(/\s+/));
|
|
117
|
+
}
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
const toRemove = tokenDifference(oldClasses, newClasses);
|
|
108
121
|
if (toRemove && toRemove.length) {
|
|
109
|
-
|
|
122
|
+
if (hasAnimate(this.$$element[0])) {
|
|
123
|
+
this.$animate.removeClass(this.$$element, toRemove);
|
|
124
|
+
} else {
|
|
125
|
+
this.$$element[0].classList.remove(...toRemove.trim().split(/\s+/));
|
|
126
|
+
}
|
|
110
127
|
}
|
|
111
128
|
}
|
|
112
129
|
|
|
@@ -50,11 +50,10 @@ const $compileMinErr = minErr("$compile");
|
|
|
50
50
|
|
|
51
51
|
const UNINITALIZED_VALIED = new Object();
|
|
52
52
|
const EXCLUDED_DIRECTIVES = ["ngIf", "ngRepeat"];
|
|
53
|
-
|
|
53
|
+
export const DIRECTIVE_SUFFIX = "Directive";
|
|
54
54
|
CompileProvider.$inject = ["$provide", "$$sanitizeUriProvider"];
|
|
55
55
|
export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
56
56
|
const hasDirectives = {};
|
|
57
|
-
const Suffix = "Directive";
|
|
58
57
|
const ALL_OR_NOTHING_ATTRS = {
|
|
59
58
|
ngSrc: true,
|
|
60
59
|
ngSrcset: true,
|
|
@@ -196,14 +195,14 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
196
195
|
assertArg(directiveFactory, "directiveFactory");
|
|
197
196
|
if (!Object.prototype.hasOwnProperty.call(hasDirectives, name)) {
|
|
198
197
|
hasDirectives[name] = [];
|
|
199
|
-
$provide.factory(name +
|
|
198
|
+
$provide.factory(name + DIRECTIVE_SUFFIX, [
|
|
200
199
|
"$injector",
|
|
201
200
|
"$exceptionHandler",
|
|
202
201
|
/**
|
|
203
202
|
*
|
|
204
|
-
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
205
|
-
* @param {import(
|
|
206
|
-
* @returns
|
|
203
|
+
* @param {import("../../core/di/internal-injector.js").InjectorService} $injector
|
|
204
|
+
* @param {import("../exception-handler.js").ErrorHandler} $exceptionHandler
|
|
205
|
+
* @returns {import("../../types.js").Directive[]}
|
|
207
206
|
*/
|
|
208
207
|
function ($injector, $exceptionHandler) {
|
|
209
208
|
const directives = [];
|
|
@@ -524,7 +523,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
524
523
|
"$sce",
|
|
525
524
|
"$animate",
|
|
526
525
|
/**
|
|
527
|
-
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
526
|
+
* @param {import("../../core/di/internal-injector.js").InjectorService} $injector
|
|
528
527
|
* @param {*} $interpolate
|
|
529
528
|
* @param {import("../exception-handler").ErrorHandler} $exceptionHandler
|
|
530
529
|
* @param {*} $templateRequest
|
|
@@ -723,7 +722,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
723
722
|
* Compile function matches each node in nodeList against the directives. Once all directives
|
|
724
723
|
* for a particular node are collected their compile functions are executed. The compile
|
|
725
724
|
* functions return values - the linking functions - are combined into a composite linking
|
|
726
|
-
* function, which is the
|
|
725
|
+
* function, which is the linking function for the node.
|
|
727
726
|
*
|
|
728
727
|
* @param {NodeList|JQLite} nodeList an array of nodes or NodeList to compile
|
|
729
728
|
* @param {*} transcludeFn A linking function, where the
|
|
@@ -745,27 +744,29 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
745
744
|
previousCompileContext,
|
|
746
745
|
) {
|
|
747
746
|
const linkFns = [];
|
|
748
|
-
let attrs;
|
|
749
|
-
let directives;
|
|
750
747
|
/**
|
|
751
748
|
* @type {any}
|
|
752
749
|
*/
|
|
753
|
-
var nodeLinkFn;
|
|
750
|
+
var nodeLinkFn = null;
|
|
754
751
|
let childNodes;
|
|
755
752
|
let childLinkFn;
|
|
756
753
|
let linkFnFound;
|
|
757
754
|
let nodeLinkFnFound;
|
|
758
755
|
|
|
759
756
|
for (let i = 0; i < nodeList.length; i++) {
|
|
760
|
-
attrs = new Attributes(
|
|
757
|
+
const attrs = new Attributes(
|
|
758
|
+
$rootScope,
|
|
759
|
+
$animate,
|
|
760
|
+
$exceptionHandler,
|
|
761
|
+
$sce,
|
|
762
|
+
);
|
|
761
763
|
|
|
762
764
|
// We must always refer to `nodeList[i]` hereafter,
|
|
763
765
|
// since the nodes can be replaced underneath us.
|
|
764
|
-
directives = collectDirectives(
|
|
766
|
+
const directives = collectDirectives(
|
|
765
767
|
/** @type Element */ (nodeList[i]),
|
|
766
|
-
[],
|
|
767
768
|
attrs,
|
|
768
|
-
|
|
769
|
+
maxPriority,
|
|
769
770
|
ignoreDirective,
|
|
770
771
|
);
|
|
771
772
|
|
|
@@ -822,8 +823,6 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
822
823
|
let childLinkFn;
|
|
823
824
|
let node;
|
|
824
825
|
let childScope;
|
|
825
|
-
let i;
|
|
826
|
-
let ii;
|
|
827
826
|
let idx;
|
|
828
827
|
let childBoundTranscludeFn;
|
|
829
828
|
let stableNodeList;
|
|
@@ -834,7 +833,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
834
833
|
stableNodeList = new Array(nodeList.length);
|
|
835
834
|
|
|
836
835
|
// create a sparse array by only copying the elements which have a linkFn
|
|
837
|
-
for (i = 0; i < linkFns.length; i += 3) {
|
|
836
|
+
for (let i = 0; i < linkFns.length; i += 3) {
|
|
838
837
|
idx = linkFns[i];
|
|
839
838
|
stableNodeList[idx] = nodeList[idx];
|
|
840
839
|
}
|
|
@@ -842,7 +841,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
842
841
|
stableNodeList = nodeList;
|
|
843
842
|
}
|
|
844
843
|
|
|
845
|
-
for (i = 0, ii = linkFns.length; i < ii; ) {
|
|
844
|
+
for (let i = 0, ii = linkFns.length; i < ii; ) {
|
|
846
845
|
node = stableNodeList[linkFns[i++]];
|
|
847
846
|
nodeLinkFn = linkFns[i++];
|
|
848
847
|
childLinkFn = linkFns[i++];
|
|
@@ -944,15 +943,14 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
944
943
|
* the function returns.
|
|
945
944
|
* @param {Attributes|import("./attributes").AttributeLike} attrs The shared attrs object which is used to populate the normalized attributes.
|
|
946
945
|
* @param {number=} maxPriority Max directive priority.
|
|
947
|
-
* @param {
|
|
946
|
+
* @param {string} [ignoreDirective]
|
|
947
|
+
* @return {import('../../types.js').Directive[]} An array to which the directives are added to. This array is sorted before the function returns.
|
|
948
948
|
*/
|
|
949
|
-
function collectDirectives(
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
ignoreDirective,
|
|
955
|
-
) {
|
|
949
|
+
function collectDirectives(node, attrs, maxPriority, ignoreDirective) {
|
|
950
|
+
/**
|
|
951
|
+
* @type {import('../../types.js').Directive[]}
|
|
952
|
+
*/
|
|
953
|
+
const directives = [];
|
|
956
954
|
const { nodeType } = node;
|
|
957
955
|
const attrsMap = attrs.$attr;
|
|
958
956
|
let nodeName;
|
|
@@ -960,42 +958,31 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
960
958
|
switch (nodeType) {
|
|
961
959
|
case Node.ELEMENT_NODE /* Element */:
|
|
962
960
|
nodeName = node.nodeName.toLowerCase();
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
961
|
+
if (ignoreDirective !== directiveNormalize(nodeName)) {
|
|
962
|
+
// use the node name: <directive>
|
|
963
|
+
addDirective(
|
|
964
|
+
directives,
|
|
965
|
+
directiveNormalize(nodeName),
|
|
966
|
+
"E",
|
|
967
|
+
maxPriority,
|
|
968
|
+
);
|
|
969
|
+
}
|
|
972
970
|
|
|
973
971
|
// iterate over the attributes
|
|
974
|
-
for (
|
|
975
|
-
var attr,
|
|
976
|
-
name,
|
|
977
|
-
nName,
|
|
978
|
-
value,
|
|
979
|
-
ngPrefixMatch,
|
|
980
|
-
nAttrs = node.attributes,
|
|
981
|
-
j = 0,
|
|
982
|
-
jj = nAttrs && nAttrs.length;
|
|
983
|
-
j < jj;
|
|
984
|
-
j++
|
|
985
|
-
) {
|
|
972
|
+
for (let j = 0; j < node.attributes?.length; j++) {
|
|
986
973
|
let isNgAttr = false;
|
|
987
974
|
let isNgProp = false;
|
|
988
975
|
let isNgEvent = false;
|
|
989
976
|
let isNgObserve = false;
|
|
990
977
|
|
|
991
|
-
attr =
|
|
992
|
-
name = attr.name;
|
|
993
|
-
value = attr.value;
|
|
994
|
-
|
|
995
|
-
nName = directiveNormalize(name.toLowerCase());
|
|
978
|
+
let attr = node.attributes[j];
|
|
979
|
+
let name = attr.name;
|
|
980
|
+
let value = attr.value;
|
|
981
|
+
let nName = directiveNormalize(name.toLowerCase());
|
|
996
982
|
|
|
997
983
|
// Support ng-attr-*, ng-prop-* and ng-on-*
|
|
998
|
-
|
|
984
|
+
const ngPrefixMatch = nName.match(NG_PREFIX_BINDING);
|
|
985
|
+
if (ngPrefixMatch) {
|
|
999
986
|
isNgAttr = ngPrefixMatch[1] === "Attr";
|
|
1000
987
|
isNgProp = ngPrefixMatch[1] === "Prop";
|
|
1001
988
|
isNgEvent = ngPrefixMatch[1] === "On";
|
|
@@ -1016,10 +1003,19 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1016
1003
|
if (isNgProp) {
|
|
1017
1004
|
addPropertyDirective(node, directives, nName, name);
|
|
1018
1005
|
} else {
|
|
1019
|
-
|
|
1006
|
+
directives.push(
|
|
1007
|
+
createEventDirective(
|
|
1008
|
+
$parse,
|
|
1009
|
+
$rootScope,
|
|
1010
|
+
$exceptionHandler,
|
|
1011
|
+
nName,
|
|
1012
|
+
name,
|
|
1013
|
+
/* forceAsync= */ false,
|
|
1014
|
+
),
|
|
1015
|
+
);
|
|
1020
1016
|
}
|
|
1021
1017
|
} else if (isNgObserve) {
|
|
1022
|
-
|
|
1018
|
+
directives.push(ngObserveDirective(name, value));
|
|
1023
1019
|
} else {
|
|
1024
1020
|
// Update nName for cases where a prefix was removed
|
|
1025
1021
|
// NOTE: the .toLowerCase() is unnecessary and causes https://github.com/angular/angular.js/issues/16624 for ng-attr-*
|
|
@@ -1043,13 +1039,10 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1043
1039
|
nName,
|
|
1044
1040
|
isNgAttr,
|
|
1045
1041
|
);
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
nName,
|
|
1049
|
-
|
|
1050
|
-
maxPriority,
|
|
1051
|
-
ignoreDirective,
|
|
1052
|
-
);
|
|
1042
|
+
|
|
1043
|
+
if (nName !== ignoreDirective) {
|
|
1044
|
+
addDirective(directives, nName, "A", maxPriority);
|
|
1045
|
+
}
|
|
1053
1046
|
}
|
|
1054
1047
|
}
|
|
1055
1048
|
|
|
@@ -1742,7 +1735,6 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
1742
1735
|
// - combine directives as: processed + template + unprocessed
|
|
1743
1736
|
const templateDirectives = collectDirectives(
|
|
1744
1737
|
/** @type {Element} */ (compileNode),
|
|
1745
|
-
[],
|
|
1746
1738
|
newTemplateAttrs,
|
|
1747
1739
|
);
|
|
1748
1740
|
const unprocessedDirectives = directives.splice(
|
|
@@ -2011,33 +2003,21 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2011
2003
|
* looks up the directive and decorates it with exception handling and proper parameters. We
|
|
2012
2004
|
* call this the boundDirective.
|
|
2013
2005
|
*
|
|
2006
|
+
* @param {import('../../types.js').Directive[]} tDirectives
|
|
2014
2007
|
* @param {string} name name of the directive to look up.
|
|
2015
2008
|
* @param {string} location The directive must be found in specific format.
|
|
2016
2009
|
* String containing any of these characters:
|
|
2017
|
-
*
|
|
2018
2010
|
* * `E`: element name
|
|
2019
2011
|
* * `A': attribute
|
|
2012
|
+
* @param maxPriority
|
|
2020
2013
|
* @returns {boolean} true if directive was added.
|
|
2021
2014
|
*/
|
|
2022
|
-
function addDirective(
|
|
2023
|
-
tDirectives,
|
|
2024
|
-
name,
|
|
2025
|
-
location,
|
|
2026
|
-
maxPriority,
|
|
2027
|
-
ignoreDirective,
|
|
2028
|
-
) {
|
|
2029
|
-
if (name === ignoreDirective) return false;
|
|
2015
|
+
function addDirective(tDirectives, name, location, maxPriority) {
|
|
2030
2016
|
let match = false;
|
|
2031
2017
|
if (Object.prototype.hasOwnProperty.call(hasDirectives, name)) {
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
i = 0,
|
|
2036
|
-
ii = directives.length;
|
|
2037
|
-
i < ii;
|
|
2038
|
-
i++
|
|
2039
|
-
) {
|
|
2040
|
-
directive = directives[i];
|
|
2018
|
+
let directives = $injector.get(name + DIRECTIVE_SUFFIX);
|
|
2019
|
+
for (let i = 0, ii = directives.length; i < ii; i++) {
|
|
2020
|
+
let directive = directives[i];
|
|
2041
2021
|
if (
|
|
2042
2022
|
(isUndefined(maxPriority) || maxPriority > directive.priority) &&
|
|
2043
2023
|
directive.restrict.indexOf(location) !== -1
|
|
@@ -2168,7 +2148,6 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2168
2148
|
replaceWith($rootElement, $compileNode, compileNode);
|
|
2169
2149
|
const templateDirectives = collectDirectives(
|
|
2170
2150
|
compileNode,
|
|
2171
|
-
[],
|
|
2172
2151
|
tempTemplateAttrs,
|
|
2173
2152
|
);
|
|
2174
2153
|
|
|
@@ -2331,15 +2310,13 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2331
2310
|
}
|
|
2332
2311
|
|
|
2333
2312
|
function addTextInterpolateDirective(directives, text) {
|
|
2334
|
-
const interpolateFn = $interpolate(text, true);
|
|
2313
|
+
const interpolateFn = $interpolate(text, true);
|
|
2335
2314
|
if (interpolateFn) {
|
|
2336
2315
|
directives.push({
|
|
2337
2316
|
priority: 0,
|
|
2338
|
-
// When transcluding a template that has bindings in the root
|
|
2339
|
-
// we don't have a parent and thus need to add the class during linking fn.
|
|
2340
2317
|
compile: () => (scope, node) => {
|
|
2341
2318
|
scope.$watch(interpolateFn, (value) => {
|
|
2342
|
-
node[0].nodeValue = value;
|
|
2319
|
+
node[0].nodeValue = value;
|
|
2343
2320
|
});
|
|
2344
2321
|
},
|
|
2345
2322
|
});
|
|
@@ -2411,10 +2388,6 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2411
2388
|
);
|
|
2412
2389
|
}
|
|
2413
2390
|
|
|
2414
|
-
function sanitizeSrcsetPropertyValue(value) {
|
|
2415
|
-
return sanitizeSrcset($sce.valueOf(value), "ng-prop-srcset");
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
2391
|
function sanitizeSrcset(value, invokeType) {
|
|
2419
2392
|
if (!value) {
|
|
2420
2393
|
return value;
|
|
@@ -2487,7 +2460,8 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2487
2460
|
propName === "srcset" &&
|
|
2488
2461
|
(nodeName === "img" || nodeName === "source")
|
|
2489
2462
|
) {
|
|
2490
|
-
sanitizer =
|
|
2463
|
+
sanitizer = (value) =>
|
|
2464
|
+
sanitizeSrcset($sce.valueOf(value), "ng-prop-srcset");
|
|
2491
2465
|
} else if (trustedContext) {
|
|
2492
2466
|
sanitizer = $sce.getTrusted.bind($sce, trustedContext);
|
|
2493
2467
|
}
|
|
@@ -2516,23 +2490,6 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
2516
2490
|
});
|
|
2517
2491
|
}
|
|
2518
2492
|
|
|
2519
|
-
function addEventDirective(directives, attrName, eventName) {
|
|
2520
|
-
directives.push(
|
|
2521
|
-
createEventDirective(
|
|
2522
|
-
$parse,
|
|
2523
|
-
$rootScope,
|
|
2524
|
-
$exceptionHandler,
|
|
2525
|
-
attrName,
|
|
2526
|
-
eventName,
|
|
2527
|
-
/* forceAsync= */ false,
|
|
2528
|
-
),
|
|
2529
|
-
);
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
function addObserveDirective(directives, source, prop) {
|
|
2533
|
-
directives.push(ngObserveDirective(source, prop));
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
2493
|
function addAttrInterpolateDirective(
|
|
2537
2494
|
node,
|
|
2538
2495
|
directives,
|
|
@@ -3664,7 +3664,9 @@ describe("$compile", () => {
|
|
|
3664
3664
|
return {
|
|
3665
3665
|
transclude: "element",
|
|
3666
3666
|
link: function (scope, el, attrs, ctrl, transclude) {
|
|
3667
|
-
|
|
3667
|
+
debugger;
|
|
3668
|
+
const res = transclude();
|
|
3669
|
+
el.after(res);
|
|
3668
3670
|
},
|
|
3669
3671
|
};
|
|
3670
3672
|
},
|
|
@@ -66,7 +66,7 @@ export class ControllerProvider {
|
|
|
66
66
|
/**
|
|
67
67
|
* $get method for dependency injection.
|
|
68
68
|
*
|
|
69
|
-
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
69
|
+
* @param {import("../../core/di/internal-injector.js").InjectorService} $injector
|
|
70
70
|
* @returns {Function} A service function that creates controllers.
|
|
71
71
|
*/
|
|
72
72
|
$get = [
|
|
@@ -28,7 +28,7 @@ export function FilterProvider($provide) {
|
|
|
28
28
|
"$injector",
|
|
29
29
|
/**
|
|
30
30
|
*
|
|
31
|
-
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
31
|
+
* @param {import("../../core/di/internal-injector.js").InjectorService} $injector
|
|
32
32
|
* @returns
|
|
33
33
|
*/
|
|
34
34
|
function ($injector) {
|
package/src/core/q/q.js
CHANGED
|
@@ -65,7 +65,7 @@ export class $QProvider {
|
|
|
65
65
|
/**
|
|
66
66
|
*
|
|
67
67
|
* @param {import('../scope/scope').Scope} $rootScope
|
|
68
|
-
* @param {import(
|
|
68
|
+
* @param {import("../exception-handler.js").ErrorHandler} $exceptionHandler
|
|
69
69
|
* @returns
|
|
70
70
|
*/
|
|
71
71
|
function ($rootScope, $exceptionHandler) {
|
package/src/core/sce/sce.js
CHANGED
|
@@ -230,7 +230,7 @@ export function SceDelegateProvider() {
|
|
|
230
230
|
"$$sanitizeUri",
|
|
231
231
|
/**
|
|
232
232
|
*
|
|
233
|
-
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
233
|
+
* @param {import("../../core/di/internal-injector.js").InjectorService} $injector
|
|
234
234
|
* @param {*} $$sanitizeUri
|
|
235
235
|
* @returns
|
|
236
236
|
*/
|
package/src/core/scope/scope.js
CHANGED
|
@@ -72,7 +72,7 @@ let applyAsyncId = null;
|
|
|
72
72
|
let $parse;
|
|
73
73
|
/** @type {import('../../services/browser').Browser} */
|
|
74
74
|
let $browser;
|
|
75
|
-
/**@type {import(
|
|
75
|
+
/**@type {import("../exception-handler.js").ErrorHandler} */
|
|
76
76
|
let $exceptionHandler;
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -96,7 +96,7 @@ export class RootScopeProvider {
|
|
|
96
96
|
"$parse",
|
|
97
97
|
"$browser",
|
|
98
98
|
/**
|
|
99
|
-
* @param {import(
|
|
99
|
+
* @param {import("../exception-handler.js").ErrorHandler} exceptionHandler
|
|
100
100
|
* @param {import('../parse/parse').ParseService} parse
|
|
101
101
|
* @param {import('../../services/browser').Browser} browser
|
|
102
102
|
* @returns {Scope} root scope
|
|
@@ -14,7 +14,7 @@ export class TimeoutProvider {
|
|
|
14
14
|
* @param {import('../scope/scope').Scope} $rootScope
|
|
15
15
|
* @param {import('../../services/browser').Browser} $browser
|
|
16
16
|
* @param {*} $q
|
|
17
|
-
* @param {import(
|
|
17
|
+
* @param {import("../exception-handler.js").ErrorHandler} $exceptionHandler
|
|
18
18
|
* @returns
|
|
19
19
|
*/
|
|
20
20
|
($rootScope, $browser, $q, $exceptionHandler) => {
|
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
import { EventBus } from "../../core/pubsub/pubsub";
|
|
1
|
+
import { EventBus } from "../../core/pubsub/pubsub.js";
|
|
2
|
+
import { isObject } from "../../shared/utils.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Dynamically updates an element's content based on events published on a specified channel.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* If data is sent via `EventBus` on the specified `ngChannel`, the directive attempts to update the element's content accordingly,
|
|
7
|
+
* either by directly setting the inner HTML or merging the scope's data if the element contains a template.
|
|
8
|
+
*
|
|
9
|
+
* If the element has a template and incoming data is an object, the directive will merge all key/value pairs onto the scope,
|
|
10
|
+
* allowing Angular expressions (`{{ yourModel }}`) to be evaluated and rendered.
|
|
7
11
|
*
|
|
8
12
|
* When the scope is destroyed, the directive automatically unsubscribes from the channel.
|
|
13
|
+
* Example:
|
|
14
|
+
*
|
|
15
|
+
* HTML:
|
|
16
|
+
* <div ng-channel="userChannel">Hello {{ user.firstName }} {{ user.lastName }}</div>
|
|
9
17
|
*
|
|
18
|
+
* JavaScript:
|
|
19
|
+
* angular.EventBus.publish('userChannel', { user: { firstName: 'John', lastName: 'Smith' } });
|
|
10
20
|
*
|
|
11
|
-
* @returns {import("../../types").Directive}
|
|
21
|
+
* @returns {import("../../types.js").Directive}
|
|
12
22
|
*/
|
|
13
23
|
export function ngChannelDirective() {
|
|
14
24
|
return {
|
|
15
25
|
restrict: "EA",
|
|
16
26
|
link: (scope, element, attrs) => {
|
|
17
|
-
const
|
|
27
|
+
const hasTemplate = element[0].childNodes.length > 0;
|
|
18
28
|
const channel = attrs["ngChannel"];
|
|
19
29
|
|
|
20
|
-
const key = EventBus.subscribe(channel, (val) => {
|
|
21
|
-
|
|
30
|
+
const key = EventBus.subscribe(channel, async (val) => {
|
|
31
|
+
if (!hasTemplate) {
|
|
32
|
+
element[0].innerHTML = val;
|
|
33
|
+
} else {
|
|
34
|
+
if (isObject(val)) {
|
|
35
|
+
Object.entries(val).forEach(([key, value]) => {
|
|
36
|
+
scope[key] = value;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
22
40
|
});
|
|
23
41
|
|
|
24
42
|
scope.$on("$destroy", () => {
|
|
@@ -49,4 +49,21 @@ describe("channel", () => {
|
|
|
49
49
|
|
|
50
50
|
expect(unsubscribeSpy).toHaveBeenCalled();
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
it("should handle templates when EventBus emits a value", async () => {
|
|
54
|
+
element = $compile(
|
|
55
|
+
'<div ng-channel="testChannel">{{ a.firstName }} {{ a.lastName }}</div>',
|
|
56
|
+
)($scope);
|
|
57
|
+
$scope.$digest();
|
|
58
|
+
expect(element[0].textContent).toBe(" ");
|
|
59
|
+
|
|
60
|
+
EventBus.publish("testChannel", {
|
|
61
|
+
a: { firstName: "John", lastName: "Doe" },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await wait(100);
|
|
65
|
+
$scope.$digest();
|
|
66
|
+
|
|
67
|
+
expect(element[0].textContent).toBe("John Doe");
|
|
68
|
+
});
|
|
52
69
|
});
|
|
@@ -27,7 +27,7 @@ const forceAsyncEvents = {
|
|
|
27
27
|
*
|
|
28
28
|
* @param {*} $parse
|
|
29
29
|
* @param {*} $rootScope
|
|
30
|
-
* @param {import('../../core/exception-handler').ErrorHandler} $exceptionHandler
|
|
30
|
+
* @param {import('../../core/exception-handler.js').ErrorHandler} $exceptionHandler
|
|
31
31
|
* @returns
|
|
32
32
|
*/
|
|
33
33
|
($parse, $rootScope, $exceptionHandler) => {
|
|
@@ -83,7 +83,7 @@ export class NgModelController {
|
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* @param {import('../../core/scope/scope').Scope} $scope
|
|
86
|
-
* @param {import('../../core/exception-handler').ErrorHandler} $exceptionHandler
|
|
86
|
+
* @param {import('../../core/exception-handler.js').ErrorHandler} $exceptionHandler
|
|
87
87
|
* @param {import('../../core/compile/attributes').Attributes} $attr
|
|
88
88
|
* @param {import('../../shared/jqlite/jqlite').JQLite} $element
|
|
89
89
|
* @param {import("../../core/parse/parse.js").ParseService} $parse
|