@angular-wave/angular.ts 0.0.1
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/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { forEach, isArray, isUndefined, trim } from "../core/utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @returns {angular.IDirective}
|
|
5
|
+
*/
|
|
6
|
+
export function ngListDirective() {
|
|
7
|
+
return {
|
|
8
|
+
restrict: "A",
|
|
9
|
+
priority: 100,
|
|
10
|
+
require: "ngModel",
|
|
11
|
+
link(_scope, _element, attr, ctrl) {
|
|
12
|
+
const ngList = attr.ngList || ", ";
|
|
13
|
+
const trimValues = attr.ngTrim !== "false";
|
|
14
|
+
const separator = trimValues ? trim(ngList) : ngList;
|
|
15
|
+
|
|
16
|
+
const parse = function (viewValue) {
|
|
17
|
+
// If the viewValue is invalid (say required but empty) it will be `undefined`
|
|
18
|
+
if (isUndefined(viewValue)) return;
|
|
19
|
+
|
|
20
|
+
const list = [];
|
|
21
|
+
|
|
22
|
+
if (viewValue) {
|
|
23
|
+
forEach(viewValue.split(separator), (value) => {
|
|
24
|
+
if (value) list.push(trimValues ? trim(value) : value);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return list;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
ctrl.$parsers.push(parse);
|
|
32
|
+
ctrl.$formatters.push((value) => {
|
|
33
|
+
if (isArray(value)) {
|
|
34
|
+
return value.join(ngList);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return undefined;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Override the standard $isEmpty because an empty array means the input is empty.
|
|
41
|
+
ctrl.$isEmpty = function (value) {
|
|
42
|
+
return !value || !value.length;
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## `ngList` Directive
|
|
2
|
+
|
|
3
|
+
### Restrict
|
|
4
|
+
|
|
5
|
+
`A`
|
|
6
|
+
|
|
7
|
+
### Priority
|
|
8
|
+
|
|
9
|
+
100
|
|
10
|
+
|
|
11
|
+
### Parameter
|
|
12
|
+
|
|
13
|
+
- `{string=} ngList`: Optional delimiter that should be used to split the value.
|
|
14
|
+
|
|
15
|
+
### Description
|
|
16
|
+
|
|
17
|
+
Text input that converts between a delimited string and an array of strings. The default delimiter is a comma followed by a space - equivalent to `ng-list=", "`. You can specify a custom delimiter as the value of the `ngList` attribute - for example, `ng-list=" | "`.
|
|
18
|
+
|
|
19
|
+
The behavior of the directive is affected by the use of the `ngTrim` attribute.
|
|
20
|
+
|
|
21
|
+
- If `ngTrim` is set to `"false"` then whitespace around both the separator and each list item is respected. This implies that the user of the directive is responsible for dealing with whitespace but also allows you to use whitespace as a delimiter, such as a tab or newline character.
|
|
22
|
+
- Otherwise, whitespace around the delimiter is ignored when splitting (although it is respected when joining the list items back together) and whitespace around each list item is stripped before it is added to the model.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { createMap, forEach, isArray, isObject, isString } from "../core/utils";
|
|
2
|
+
|
|
3
|
+
function classDirective(name, selector) {
|
|
4
|
+
// eslint-disable-next-line no-param-reassign
|
|
5
|
+
name = `ngClass${name}`;
|
|
6
|
+
var indexWatchExpression;
|
|
7
|
+
|
|
8
|
+
return [
|
|
9
|
+
"$parse",
|
|
10
|
+
($parse) => ({
|
|
11
|
+
restrict: "EA",
|
|
12
|
+
link(scope, element, attr) {
|
|
13
|
+
let classCounts = element.data("$classCounts");
|
|
14
|
+
let oldModulo = true;
|
|
15
|
+
let oldClassString;
|
|
16
|
+
|
|
17
|
+
if (!classCounts) {
|
|
18
|
+
// Use createMap() to prevent class assumptions involving property
|
|
19
|
+
// names in Object.prototype
|
|
20
|
+
classCounts = createMap();
|
|
21
|
+
element.data("$classCounts", classCounts);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (name !== "ngClass") {
|
|
25
|
+
if (!indexWatchExpression) {
|
|
26
|
+
indexWatchExpression = $parse("$index", function moduloTwo($index) {
|
|
27
|
+
// eslint-disable-next-line no-bitwise
|
|
28
|
+
return $index & 1;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
scope.$watch(indexWatchExpression, ngClassIndexWatchAction);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
scope.$watch($parse(attr[name], toClassString), ngClassWatchAction);
|
|
36
|
+
|
|
37
|
+
function addClasses(classString) {
|
|
38
|
+
classString = digestClassCounts(split(classString), 1);
|
|
39
|
+
attr.$addClass(classString);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function removeClasses(classString) {
|
|
43
|
+
classString = digestClassCounts(split(classString), -1);
|
|
44
|
+
attr.$removeClass(classString);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function updateClasses(oldClassString, newClassString) {
|
|
48
|
+
const oldClassArray = split(oldClassString);
|
|
49
|
+
const newClassArray = split(newClassString);
|
|
50
|
+
|
|
51
|
+
const toRemoveArray = arrayDifference(oldClassArray, newClassArray);
|
|
52
|
+
const toAddArray = arrayDifference(newClassArray, oldClassArray);
|
|
53
|
+
|
|
54
|
+
const toRemoveString = digestClassCounts(toRemoveArray, -1);
|
|
55
|
+
const toAddString = digestClassCounts(toAddArray, 1);
|
|
56
|
+
|
|
57
|
+
attr.$addClass(toAddString);
|
|
58
|
+
attr.$removeClass(toRemoveString);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function digestClassCounts(classArray, count) {
|
|
62
|
+
const classesToUpdate = [];
|
|
63
|
+
|
|
64
|
+
forEach(classArray, (className) => {
|
|
65
|
+
if (count > 0 || classCounts[className]) {
|
|
66
|
+
classCounts[className] = (classCounts[className] || 0) + count;
|
|
67
|
+
if (classCounts[className] === +(count > 0)) {
|
|
68
|
+
classesToUpdate.push(className);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return classesToUpdate.join(" ");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function ngClassIndexWatchAction(newModulo) {
|
|
77
|
+
// This watch-action should run before the `ngClassWatchAction()`, thus it
|
|
78
|
+
// adds/removes `oldClassString`. If the `ngClass` expression has changed as well, the
|
|
79
|
+
// `ngClassWatchAction()` will update the classes.
|
|
80
|
+
if (newModulo === selector) {
|
|
81
|
+
addClasses(oldClassString);
|
|
82
|
+
} else {
|
|
83
|
+
removeClasses(oldClassString);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
oldModulo = newModulo;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function ngClassWatchAction(newClassString) {
|
|
90
|
+
if (oldModulo === selector) {
|
|
91
|
+
updateClasses(oldClassString, newClassString);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
oldClassString = newClassString;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
// Helpers
|
|
101
|
+
function arrayDifference(tokens1, tokens2) {
|
|
102
|
+
if (!tokens1 || !tokens1.length) return [];
|
|
103
|
+
if (!tokens2 || !tokens2.length) return tokens1;
|
|
104
|
+
|
|
105
|
+
const values = [];
|
|
106
|
+
|
|
107
|
+
outer: for (let i = 0; i < tokens1.length; i++) {
|
|
108
|
+
const token = tokens1[i];
|
|
109
|
+
for (let j = 0; j < tokens2.length; j++) {
|
|
110
|
+
if (token === tokens2[j]) continue outer;
|
|
111
|
+
}
|
|
112
|
+
values.push(token);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return values;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function split(classString) {
|
|
119
|
+
return classString && classString.split(" ");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function toClassString(classValue) {
|
|
123
|
+
if (!classValue) return classValue;
|
|
124
|
+
|
|
125
|
+
let classString = classValue;
|
|
126
|
+
|
|
127
|
+
if (isArray(classValue)) {
|
|
128
|
+
classString = classValue.map(toClassString).join(" ");
|
|
129
|
+
} else if (isObject(classValue)) {
|
|
130
|
+
classString = Object.keys(classValue)
|
|
131
|
+
.filter((key) => classValue[key])
|
|
132
|
+
.join(" ");
|
|
133
|
+
} else if (!isString(classValue)) {
|
|
134
|
+
classString = `${classValue}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return classString;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @ngdoc directive
|
|
143
|
+
* @name ngClass
|
|
144
|
+
* @restrict AC
|
|
145
|
+
* @element ANY
|
|
146
|
+
*
|
|
147
|
+
* @description
|
|
148
|
+
* The `ngClass` directive allows you to dynamically set CSS classes on an HTML element by databinding
|
|
149
|
+
* an expression that represents all classes to be added.
|
|
150
|
+
*
|
|
151
|
+
* The directive operates in three different ways, depending on which of three types the expression
|
|
152
|
+
* evaluates to:
|
|
153
|
+
*
|
|
154
|
+
* 1. If the expression evaluates to a string, the string should be one or more space-delimited class
|
|
155
|
+
* names.
|
|
156
|
+
*
|
|
157
|
+
* 2. If the expression evaluates to an object, then for each key-value pair of the
|
|
158
|
+
* object with a truthy value the corresponding key is used as a class name.
|
|
159
|
+
*
|
|
160
|
+
* 3. If the expression evaluates to an array, each element of the array should either be a string as in
|
|
161
|
+
* type 1 or an object as in type 2. This means that you can mix strings and objects together in an array
|
|
162
|
+
* to give you more control over what CSS classes appear. See the code below for an example of this.
|
|
163
|
+
*
|
|
164
|
+
*
|
|
165
|
+
* The directive won't add duplicate classes if a particular class was already set.
|
|
166
|
+
*
|
|
167
|
+
* When the expression changes, the previously added classes are removed and only then are the
|
|
168
|
+
* new classes added.
|
|
169
|
+
*
|
|
170
|
+
* @knownIssue
|
|
171
|
+
* You should not use {@link guide/interpolation interpolation} in the value of the `class`
|
|
172
|
+
* attribute, when using the `ngClass` directive on the same element.
|
|
173
|
+
* See {@link guide/interpolation#known-issues here} for more info.
|
|
174
|
+
*
|
|
175
|
+
* @animations
|
|
176
|
+
* | Animation | Occurs |
|
|
177
|
+
* |----------------------------------|-------------------------------------|
|
|
178
|
+
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
|
|
179
|
+
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
|
|
180
|
+
* | {@link ng.$animate#setClass setClass} | just before classes are added and classes are removed from the element at the same time |
|
|
181
|
+
*
|
|
182
|
+
* ### ngClass and pre-existing CSS3 Transitions/Animations
|
|
183
|
+
The ngClass directive still supports CSS3 Transitions/Animations even if they do not follow the ngAnimate CSS naming structure.
|
|
184
|
+
Upon animation ngAnimate will apply supplementary CSS classes to track the start and end of an animation, but this will not hinder
|
|
185
|
+
any pre-existing CSS transitions already on the element. To get an idea of what happens during a class-based animation, be sure
|
|
186
|
+
to view the step by step details of {@link $animate#addClass $animate.addClass} and
|
|
187
|
+
{@link $animate#removeClass $animate.removeClass}.
|
|
188
|
+
*
|
|
189
|
+
* @param {String} ngClass {@link guide/expression Expression} to eval. The result
|
|
190
|
+
* of the evaluation can be a string representing space delimited class
|
|
191
|
+
* names, an array, or a map of class names to boolean values. In the case of a map, the
|
|
192
|
+
* names of the properties whose values are truthy will be added as css classes to the
|
|
193
|
+
* element.
|
|
194
|
+
*
|
|
195
|
+
*/
|
|
196
|
+
export const ngClassDirective = classDirective("", true);
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @ngdoc directive
|
|
200
|
+
* @name ngClassOdd
|
|
201
|
+
* @restrict AC
|
|
202
|
+
*
|
|
203
|
+
* @description
|
|
204
|
+
* The `ngClassOdd` and `ngClassEven` directives work exactly as
|
|
205
|
+
* {@link ng.directive:ngClass ngClass}, except they work in
|
|
206
|
+
* conjunction with `ngRepeat` and take effect only on odd (even) rows.
|
|
207
|
+
*
|
|
208
|
+
* This directive can be applied only within the scope of an
|
|
209
|
+
* {@link ng.directive:ngRepeat ngRepeat}.
|
|
210
|
+
*
|
|
211
|
+
* @animations
|
|
212
|
+
* | Animation | Occurs |
|
|
213
|
+
* |----------------------------------|-------------------------------------|
|
|
214
|
+
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
|
|
215
|
+
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
|
|
216
|
+
*
|
|
217
|
+
* @element ANY
|
|
218
|
+
* @param {String} ngClassOdd {@link guide/expression Expression} to eval. The result
|
|
219
|
+
* of the evaluation can be a string representing space delimited class names or an array.
|
|
220
|
+
*
|
|
221
|
+
*
|
|
222
|
+
*/
|
|
223
|
+
export const ngClassOddDirective = classDirective("Odd", 0);
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @ngdoc directive
|
|
227
|
+
* @name ngClassEven
|
|
228
|
+
* @restrict AC
|
|
229
|
+
*
|
|
230
|
+
* @description
|
|
231
|
+
* The `ngClassOdd` and `ngClassEven` directives work exactly as
|
|
232
|
+
* {@link ng.directive:ngClass ngClass}, except they work in
|
|
233
|
+
* conjunction with `ngRepeat` and take effect only on odd (even) rows.
|
|
234
|
+
*
|
|
235
|
+
* This directive can be applied only within the scope of an
|
|
236
|
+
* {@link ng.directive:ngRepeat ngRepeat}.
|
|
237
|
+
*
|
|
238
|
+
* @animations
|
|
239
|
+
* | Animation | Occurs |
|
|
240
|
+
* |----------------------------------|-------------------------------------|
|
|
241
|
+
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
|
|
242
|
+
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
|
|
243
|
+
*
|
|
244
|
+
* @element ANY
|
|
245
|
+
* @param {String} ngClassEven {@link guide/expression Expression} to eval. The
|
|
246
|
+
* result of the evaluation can be a string representing space delimited class names or an array.
|
|
247
|
+
*
|
|
248
|
+
*/
|
|
249
|
+
export const ngClassEvenDirective = classDirective("Even", 1);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ngdoc directive
|
|
3
|
+
* @name ngController
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* The `ngController` directive attaches a controller class to the view. This is a key aspect of how angular
|
|
7
|
+
* supports the principles behind the Model-View-Controller design pattern.
|
|
8
|
+
*
|
|
9
|
+
* MVC components in angular:
|
|
10
|
+
*
|
|
11
|
+
* * Model — Models are the properties of a scope; scopes are attached to the DOM where scope properties
|
|
12
|
+
* are accessed through bindings.
|
|
13
|
+
* * View — The template (HTML with data bindings) that is rendered into the View.
|
|
14
|
+
* * Controller — The `ngController` directive specifies a Controller class; the class contains business
|
|
15
|
+
* logic behind the application to decorate the scope with functions and values
|
|
16
|
+
*
|
|
17
|
+
* Note that you can also attach controllers to the DOM by declaring it in a route definition
|
|
18
|
+
* via the {@link ngRoute.$route $route} service. A common mistake is to declare the controller
|
|
19
|
+
* again using `ng-controller` in the template itself. This will cause the controller to be attached
|
|
20
|
+
* and executed twice.
|
|
21
|
+
*
|
|
22
|
+
* @element ANY
|
|
23
|
+
* @scope
|
|
24
|
+
* @priority 500
|
|
25
|
+
* @param {String} ngController Name of a constructor function registered with the current
|
|
26
|
+
* {@link ng.$controllerProvider $controllerProvider} or an {@link guide/expression expression}
|
|
27
|
+
* that on the current scope evaluates to a constructor function.
|
|
28
|
+
*
|
|
29
|
+
* The controller instance can be published into a scope property by specifying
|
|
30
|
+
* `ng-controller="as propertyName"`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* Here is a simple form for editing user contact information. Adding, removing, clearing, and
|
|
34
|
+
* greeting are methods declared on the controller (see source tab). These methods can
|
|
35
|
+
* easily be called from the AngularJS markup. Any changes to the data are automatically reflected
|
|
36
|
+
* in the View without the need for a manual update.
|
|
37
|
+
*
|
|
38
|
+
* Two different declaration styles are included below:
|
|
39
|
+
*
|
|
40
|
+
* * one binds methods and properties directly onto the controller using `this`:
|
|
41
|
+
* `ng-controller="SettingsController1 as settings"`
|
|
42
|
+
* * one injects `$scope` into the controller:
|
|
43
|
+
* `ng-controller="SettingsController2"`
|
|
44
|
+
*
|
|
45
|
+
* The second option is more common in the AngularJS community, and is generally used in boilerplates
|
|
46
|
+
* and in this guide. However, there are advantages to binding properties directly to the controller
|
|
47
|
+
* and avoiding scope.
|
|
48
|
+
*
|
|
49
|
+
* * Using `controller as` makes it obvious which controller you are accessing in the template when
|
|
50
|
+
* multiple controllers apply to an element.
|
|
51
|
+
* * If you are writing your controllers as classes you have easier access to the properties and
|
|
52
|
+
* methods, which will appear on the scope, from inside the controller code.
|
|
53
|
+
* * Since there is always a `.` in the bindings, you don't have to worry about prototypal
|
|
54
|
+
* inheritance masking primitives.
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
export const ngControllerDirective = [
|
|
58
|
+
() => ({
|
|
59
|
+
restrict: "A",
|
|
60
|
+
scope: true,
|
|
61
|
+
controller: "@",
|
|
62
|
+
priority: 500,
|
|
63
|
+
}),
|
|
64
|
+
];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ngdoc directive
|
|
3
|
+
* @name ngCsp
|
|
4
|
+
*
|
|
5
|
+
* @restrict A
|
|
6
|
+
* @element ANY
|
|
7
|
+
* @description
|
|
8
|
+
*
|
|
9
|
+
* AngularJS has some features that can conflict with certain restrictions that are applied when using
|
|
10
|
+
* [CSP (Content Security Policy)](https://developer.mozilla.org/en/Security/CSP) rules.
|
|
11
|
+
*
|
|
12
|
+
* If you intend to implement CSP with these rules then you must tell AngularJS not to use these
|
|
13
|
+
* features.
|
|
14
|
+
*
|
|
15
|
+
* This is necessary when developing things like Google Chrome Extensions or Universal Windows Apps.
|
|
16
|
+
*
|
|
17
|
+
*
|
|
18
|
+
* The following default rules in CSP affect AngularJS:
|
|
19
|
+
*
|
|
20
|
+
* * The use of `eval()`, `Function(string)` and similar functions to dynamically create and execute
|
|
21
|
+
* code from strings is forbidden. AngularJS makes use of this in the {@link $parse} service to
|
|
22
|
+
* provide a 30% increase in the speed of evaluating AngularJS expressions. (This CSP rule can be
|
|
23
|
+
* disabled with the CSP keyword `unsafe-eval`, but it is generally not recommended as it would
|
|
24
|
+
* weaken the protections offered by CSP.)
|
|
25
|
+
*
|
|
26
|
+
* * The use of inline resources, such as inline `<script>` and `<style>` elements, are forbidden.
|
|
27
|
+
* This prevents apps from injecting custom styles directly into the document. AngularJS makes use of
|
|
28
|
+
* this to include some CSS rules (e.g. {@link ngCloak} and {@link ngHide}). To make these
|
|
29
|
+
* directives work when a CSP rule is blocking inline styles, you must link to the `angular-csp.css`
|
|
30
|
+
* in your HTML manually. (This CSP rule can be disabled with the CSP keyword `unsafe-inline`, but
|
|
31
|
+
* it is generally not recommended as it would weaken the protections offered by CSP.)
|
|
32
|
+
*
|
|
33
|
+
* If you do not provide `ngCsp` then AngularJS tries to autodetect if CSP is blocking dynamic code
|
|
34
|
+
* creation from strings (e.g., `unsafe-eval` not specified in CSP header) and automatically
|
|
35
|
+
* deactivates this feature in the {@link $parse} service. This autodetection, however, triggers a
|
|
36
|
+
* CSP error to be logged in the console:
|
|
37
|
+
*
|
|
38
|
+
* ```
|
|
39
|
+
* Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of
|
|
40
|
+
* script in the following Content Security Policy directive: "default-src 'self'". Note that
|
|
41
|
+
* 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* This error is harmless but annoying. To prevent the error from showing up, put the `ngCsp`
|
|
45
|
+
* directive on an element of the HTML document that appears before the `<script>` tag that loads
|
|
46
|
+
* the `angular.js` file.
|
|
47
|
+
*
|
|
48
|
+
* *Note: This directive is only available in the `ng-csp` and `data-ng-csp` attribute form.*
|
|
49
|
+
*
|
|
50
|
+
* You can specify which of the CSP related AngularJS features should be deactivated by providing
|
|
51
|
+
* a value for the `ng-csp` attribute. The options are as follows:
|
|
52
|
+
*
|
|
53
|
+
* * no-inline-style: this stops AngularJS from injecting CSS styles into the DOM
|
|
54
|
+
*
|
|
55
|
+
* * no-unsafe-eval: this stops AngularJS from optimizing $parse with unsafe eval of strings
|
|
56
|
+
*
|
|
57
|
+
* You can use these values in the following combinations:
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* * No declaration means that AngularJS will assume that you can do inline styles, but it will do
|
|
61
|
+
* a runtime check for unsafe-eval. E.g. `<body>`. This is backwardly compatible with previous
|
|
62
|
+
* versions of AngularJS.
|
|
63
|
+
*
|
|
64
|
+
* * A simple `ng-csp` (or `data-ng-csp`) attribute will tell AngularJS to deactivate both inline
|
|
65
|
+
* styles and unsafe eval. E.g. `<body ng-csp>`. This is backwardly compatible with previous
|
|
66
|
+
* versions of AngularJS.
|
|
67
|
+
*
|
|
68
|
+
* * Specifying only `no-unsafe-eval` tells AngularJS that we must not use eval, but that we can
|
|
69
|
+
* inject inline styles. E.g. `<body ng-csp="no-unsafe-eval">`.
|
|
70
|
+
*
|
|
71
|
+
* * Specifying only `no-inline-style` tells AngularJS that we must not inject styles, but that we can
|
|
72
|
+
* run eval - no automatic check for unsafe eval will occur. E.g. `<body ng-csp="no-inline-style">`
|
|
73
|
+
*
|
|
74
|
+
* * Specifying both `no-unsafe-eval` and `no-inline-style` tells AngularJS that we must not inject
|
|
75
|
+
* styles nor use eval, which is the same as an empty: ng-csp.
|
|
76
|
+
* E.g.`<body ng-csp="no-inline-style;no-unsafe-eval">`
|
|
77
|
+
|
|
78
|
+
// `ngCsp` is not implemented as a proper directive any more, because we need it be processed while
|
|
79
|
+
// we bootstrap the app (before `$parse` is instantiated). For this reason, we just have the `csp()`
|
|
80
|
+
// fn that looks for the `ng-csp` attribute anywhere in the current doc.
|
|
81
|
+
// TODO MOVE CSP to PARSE CONFIG as this should not even be a directive
|
|
82
|
+
*/
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { getBlockNodes } from "../jqLite";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc directive
|
|
5
|
+
* @name ngIf
|
|
6
|
+
* @restrict A
|
|
7
|
+
* @multiElement
|
|
8
|
+
*
|
|
9
|
+
* @description
|
|
10
|
+
* The `ngIf` directive removes or recreates a portion of the DOM tree based on an
|
|
11
|
+
* {expression}. If the expression assigned to `ngIf` evaluates to a false
|
|
12
|
+
* value then the element is removed from the DOM, otherwise a clone of the
|
|
13
|
+
* element is reinserted into the DOM.
|
|
14
|
+
*
|
|
15
|
+
* `ngIf` differs from `ngShow` and `ngHide` in that `ngIf` completely removes and recreates the
|
|
16
|
+
* element in the DOM rather than changing its visibility via the `display` css property. A common
|
|
17
|
+
* case when this difference is significant is when using css selectors that rely on an element's
|
|
18
|
+
* position within the DOM, such as the `:first-child` or `:last-child` pseudo-classes.
|
|
19
|
+
*
|
|
20
|
+
* Note that when an element is removed using `ngIf` its scope is destroyed and a new scope
|
|
21
|
+
* is created when the element is restored. The scope created within `ngIf` inherits from
|
|
22
|
+
* its parent scope using
|
|
23
|
+
* [prototypal inheritance](https://github.com/angular/angular.js/wiki/Understanding-Scopes#javascript-prototypal-inheritance).
|
|
24
|
+
* An important implication of this is if `ngModel` is used within `ngIf` to bind to
|
|
25
|
+
* a javascript primitive defined in the parent scope. In this case any modifications made to the
|
|
26
|
+
* variable within the child scope will override (hide) the value in the parent scope.
|
|
27
|
+
*
|
|
28
|
+
* Also, `ngIf` recreates elements using their compiled state. An example of this behavior
|
|
29
|
+
* is if an element's class attribute is directly modified after it's compiled, using something like
|
|
30
|
+
* jQuery's `.addClass()` method, and the element is later removed. When `ngIf` recreates the element
|
|
31
|
+
* the added class will be lost because the original compiled state is used to regenerate the element.
|
|
32
|
+
*
|
|
33
|
+
* Additionally, you can provide animations via the `ngAnimate` module to animate the `enter`
|
|
34
|
+
* and `leave` effects.
|
|
35
|
+
*
|
|
36
|
+
* @animations
|
|
37
|
+
* | Animation | Occurs |
|
|
38
|
+
* |----------------------------------|-------------------------------------|
|
|
39
|
+
* | {@link ng.$animate#enter enter} | just after the `ngIf` contents change and a new DOM element is created and injected into the `ngIf` container |
|
|
40
|
+
* | {@link ng.$animate#leave leave} | just before the `ngIf` contents are removed from the DOM |
|
|
41
|
+
*
|
|
42
|
+
* @element ANY
|
|
43
|
+
* @scope
|
|
44
|
+
* @priority 600
|
|
45
|
+
* @param {string} ngIf If the {@link guide/expression expression} is falsy then
|
|
46
|
+
* the element is removed from the DOM tree. If it is truthy a copy of the compiled
|
|
47
|
+
* element is added to the DOM tree.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
<example module="ngAnimate" deps="angular-animate.js" animations="true" name="ng-if">
|
|
51
|
+
<file name="index.html">
|
|
52
|
+
<label>Click me: <input type="checkbox" ng-model="checked" ng-init="checked=true" /></label><br/>
|
|
53
|
+
Show when checked:
|
|
54
|
+
<span ng-if="checked" class="animate-if">
|
|
55
|
+
This is removed when the checkbox is unchecked.
|
|
56
|
+
</span>
|
|
57
|
+
</file>
|
|
58
|
+
<file name="animations.css">
|
|
59
|
+
.animate-if {
|
|
60
|
+
background:white;
|
|
61
|
+
border:1px solid black;
|
|
62
|
+
padding:10px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.animate-if.ng-enter, .animate-if.ng-leave {
|
|
66
|
+
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.animate-if.ng-enter,
|
|
70
|
+
.animate-if.ng-leave.ng-leave-active {
|
|
71
|
+
opacity:0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.animate-if.ng-leave,
|
|
75
|
+
.animate-if.ng-enter.ng-enter-active {
|
|
76
|
+
opacity:1;
|
|
77
|
+
}
|
|
78
|
+
</file>
|
|
79
|
+
</example>
|
|
80
|
+
*/
|
|
81
|
+
export const ngIfDirective = [
|
|
82
|
+
"$animate",
|
|
83
|
+
"$compile",
|
|
84
|
+
($animate, $compile) => ({
|
|
85
|
+
multiElement: true,
|
|
86
|
+
transclude: "element",
|
|
87
|
+
priority: 600,
|
|
88
|
+
terminal: true,
|
|
89
|
+
restrict: "A",
|
|
90
|
+
$$tlb: true,
|
|
91
|
+
link($scope, $element, $attr, ctrl, $transclude) {
|
|
92
|
+
let block;
|
|
93
|
+
let childScope;
|
|
94
|
+
let previousElements;
|
|
95
|
+
$scope.$watch($attr.ngIf, (value) => {
|
|
96
|
+
if (value) {
|
|
97
|
+
if (!childScope) {
|
|
98
|
+
$transclude((clone, newScope) => {
|
|
99
|
+
childScope = newScope;
|
|
100
|
+
// eslint-disable-next-line no-plusplus, no-param-reassign
|
|
101
|
+
clone[clone.length++] = $compile.$$createComment(
|
|
102
|
+
"end ngIf",
|
|
103
|
+
$attr.ngIf,
|
|
104
|
+
);
|
|
105
|
+
// Note: We only need the first/last node of the cloned nodes.
|
|
106
|
+
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
|
|
107
|
+
// by a directive with templateUrl when its template arrives.
|
|
108
|
+
block = {
|
|
109
|
+
clone,
|
|
110
|
+
};
|
|
111
|
+
$animate.enter(clone, $element.parent(), $element);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
if (previousElements) {
|
|
116
|
+
previousElements.remove();
|
|
117
|
+
previousElements = null;
|
|
118
|
+
}
|
|
119
|
+
if (childScope) {
|
|
120
|
+
childScope.$destroy();
|
|
121
|
+
childScope = null;
|
|
122
|
+
}
|
|
123
|
+
if (block) {
|
|
124
|
+
previousElements = getBlockNodes(block.clone);
|
|
125
|
+
$animate.leave(previousElements).done((response) => {
|
|
126
|
+
if (response !== false) previousElements = null;
|
|
127
|
+
});
|
|
128
|
+
block = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
];
|