@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.
Files changed (231) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.cjs +29 -0
  3. package/.github/workflows/playwright.yml +27 -0
  4. package/CHANGELOG.md +17974 -0
  5. package/CODE_OF_CONDUCT.md +3 -0
  6. package/CONTRIBUTING.md +246 -0
  7. package/DEVELOPERS.md +488 -0
  8. package/LICENSE +22 -0
  9. package/Makefile +31 -0
  10. package/README.md +115 -0
  11. package/RELEASE.md +98 -0
  12. package/SECURITY.md +16 -0
  13. package/TRIAGING.md +135 -0
  14. package/css/angular.css +22 -0
  15. package/dist/angular-ts.cjs.js +36843 -0
  16. package/dist/angular-ts.esm.js +36841 -0
  17. package/dist/angular-ts.umd.js +36848 -0
  18. package/dist/build/angular-animate.js +4272 -0
  19. package/dist/build/angular-aria.js +426 -0
  20. package/dist/build/angular-message-format.js +1072 -0
  21. package/dist/build/angular-messages.js +829 -0
  22. package/dist/build/angular-mocks.js +3757 -0
  23. package/dist/build/angular-parse-ext.js +1275 -0
  24. package/dist/build/angular-resource.js +911 -0
  25. package/dist/build/angular-route.js +1266 -0
  26. package/dist/build/angular-sanitize.js +891 -0
  27. package/dist/build/angular-touch.js +368 -0
  28. package/dist/build/angular.js +36600 -0
  29. package/e2e/unit.spec.ts +15 -0
  30. package/images/android-chrome-192x192.png +0 -0
  31. package/images/android-chrome-512x512.png +0 -0
  32. package/images/apple-touch-icon.png +0 -0
  33. package/images/favicon-16x16.png +0 -0
  34. package/images/favicon-32x32.png +0 -0
  35. package/images/favicon.ico +0 -0
  36. package/images/site.webmanifest +1 -0
  37. package/index.html +104 -0
  38. package/package.json +47 -0
  39. package/playwright.config.ts +78 -0
  40. package/public/circle.html +1 -0
  41. package/public/my_child_directive.html +1 -0
  42. package/public/my_directive.html +1 -0
  43. package/public/my_other_directive.html +1 -0
  44. package/public/test.html +1 -0
  45. package/rollup.config.js +31 -0
  46. package/src/animations/animateCache.js +55 -0
  47. package/src/animations/animateChildrenDirective.js +105 -0
  48. package/src/animations/animateCss.js +1139 -0
  49. package/src/animations/animateCssDriver.js +291 -0
  50. package/src/animations/animateJs.js +367 -0
  51. package/src/animations/animateJsDriver.js +67 -0
  52. package/src/animations/animateQueue.js +851 -0
  53. package/src/animations/animation.js +506 -0
  54. package/src/animations/module.js +779 -0
  55. package/src/animations/ngAnimateSwap.js +119 -0
  56. package/src/animations/rafScheduler.js +50 -0
  57. package/src/animations/shared.js +378 -0
  58. package/src/constants.js +20 -0
  59. package/src/core/animate.js +845 -0
  60. package/src/core/animateCss.js +73 -0
  61. package/src/core/animateRunner.js +195 -0
  62. package/src/core/attributes.js +199 -0
  63. package/src/core/cache.js +45 -0
  64. package/src/core/compile.js +4727 -0
  65. package/src/core/controller.js +225 -0
  66. package/src/core/exceptionHandler.js +63 -0
  67. package/src/core/filter.js +146 -0
  68. package/src/core/interpolate.js +442 -0
  69. package/src/core/interval.js +188 -0
  70. package/src/core/intervalFactory.js +57 -0
  71. package/src/core/location.js +1086 -0
  72. package/src/core/parser/parse.js +2562 -0
  73. package/src/core/parser/parse.md +13 -0
  74. package/src/core/q.js +746 -0
  75. package/src/core/rootScope.js +1596 -0
  76. package/src/core/sanitizeUri.js +85 -0
  77. package/src/core/sce.js +1161 -0
  78. package/src/core/taskTrackerFactory.js +125 -0
  79. package/src/core/timeout.js +121 -0
  80. package/src/core/urlUtils.js +187 -0
  81. package/src/core/utils.js +1349 -0
  82. package/src/directive/a.js +37 -0
  83. package/src/directive/attrs.js +283 -0
  84. package/src/directive/bind.js +51 -0
  85. package/src/directive/bind.md +142 -0
  86. package/src/directive/change.js +12 -0
  87. package/src/directive/change.md +25 -0
  88. package/src/directive/cloak.js +12 -0
  89. package/src/directive/cloak.md +24 -0
  90. package/src/directive/events.js +75 -0
  91. package/src/directive/events.md +166 -0
  92. package/src/directive/form.js +725 -0
  93. package/src/directive/init.js +15 -0
  94. package/src/directive/init.md +41 -0
  95. package/src/directive/input.js +1783 -0
  96. package/src/directive/list.js +46 -0
  97. package/src/directive/list.md +22 -0
  98. package/src/directive/ngClass.js +249 -0
  99. package/src/directive/ngController.js +64 -0
  100. package/src/directive/ngCsp.js +82 -0
  101. package/src/directive/ngIf.js +134 -0
  102. package/src/directive/ngInclude.js +217 -0
  103. package/src/directive/ngModel.js +1356 -0
  104. package/src/directive/ngModelOptions.js +509 -0
  105. package/src/directive/ngOptions.js +670 -0
  106. package/src/directive/ngRef.js +90 -0
  107. package/src/directive/ngRepeat.js +650 -0
  108. package/src/directive/ngShowHide.js +255 -0
  109. package/src/directive/ngSwitch.js +178 -0
  110. package/src/directive/ngTransclude.js +98 -0
  111. package/src/directive/non-bindable.js +11 -0
  112. package/src/directive/non-bindable.md +17 -0
  113. package/src/directive/script.js +30 -0
  114. package/src/directive/select.js +624 -0
  115. package/src/directive/style.js +25 -0
  116. package/src/directive/style.md +23 -0
  117. package/src/directive/validators.js +329 -0
  118. package/src/exts/aria.js +544 -0
  119. package/src/exts/messages.js +852 -0
  120. package/src/filters/filter.js +207 -0
  121. package/src/filters/filter.md +69 -0
  122. package/src/filters/filters.js +239 -0
  123. package/src/filters/json.md +16 -0
  124. package/src/filters/limit-to.js +43 -0
  125. package/src/filters/limit-to.md +19 -0
  126. package/src/filters/order-by.js +183 -0
  127. package/src/filters/order-by.md +83 -0
  128. package/src/index.js +13 -0
  129. package/src/injector.js +1034 -0
  130. package/src/jqLite.js +1117 -0
  131. package/src/loader.js +1320 -0
  132. package/src/public.js +215 -0
  133. package/src/routeToRegExp.js +41 -0
  134. package/src/services/anchorScroll.js +135 -0
  135. package/src/services/browser.js +321 -0
  136. package/src/services/cacheFactory.js +398 -0
  137. package/src/services/cookieReader.js +72 -0
  138. package/src/services/document.js +64 -0
  139. package/src/services/http.js +1537 -0
  140. package/src/services/httpBackend.js +206 -0
  141. package/src/services/log.js +160 -0
  142. package/src/services/templateRequest.js +139 -0
  143. package/test/angular.spec.js +2153 -0
  144. package/test/aria/aria.spec.js +1245 -0
  145. package/test/binding.spec.js +504 -0
  146. package/test/build-test.html +14 -0
  147. package/test/injector.spec.js +2327 -0
  148. package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
  149. package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
  150. package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
  151. package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
  152. package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
  153. package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
  154. package/test/jasmine/jasmine-browser.json +17 -0
  155. package/test/jasmine/jasmine.json +9 -0
  156. package/test/jqlite.spec.js +2133 -0
  157. package/test/loader.spec.js +219 -0
  158. package/test/messages/messages.spec.js +1146 -0
  159. package/test/min-err.spec.js +174 -0
  160. package/test/mock-test.html +13 -0
  161. package/test/module-test.html +15 -0
  162. package/test/ng/anomate.spec.js +606 -0
  163. package/test/ng/cache-factor.spec.js +334 -0
  164. package/test/ng/compile.spec.js +17956 -0
  165. package/test/ng/controller-provider.spec.js +227 -0
  166. package/test/ng/cookie-reader.spec.js +98 -0
  167. package/test/ng/directive/a.spec.js +192 -0
  168. package/test/ng/directive/bind.spec.js +334 -0
  169. package/test/ng/directive/boolean.spec.js +136 -0
  170. package/test/ng/directive/change.spec.js +71 -0
  171. package/test/ng/directive/class.spec.js +858 -0
  172. package/test/ng/directive/click.spec.js +38 -0
  173. package/test/ng/directive/cloak.spec.js +44 -0
  174. package/test/ng/directive/constoller.spec.js +194 -0
  175. package/test/ng/directive/element-style.spec.js +92 -0
  176. package/test/ng/directive/event.spec.js +282 -0
  177. package/test/ng/directive/form.spec.js +1518 -0
  178. package/test/ng/directive/href.spec.js +143 -0
  179. package/test/ng/directive/if.spec.js +402 -0
  180. package/test/ng/directive/include.spec.js +828 -0
  181. package/test/ng/directive/init.spec.js +68 -0
  182. package/test/ng/directive/input.spec.js +3810 -0
  183. package/test/ng/directive/list.spec.js +170 -0
  184. package/test/ng/directive/model-options.spec.js +1008 -0
  185. package/test/ng/directive/model.spec.js +1905 -0
  186. package/test/ng/directive/non-bindable.spec.js +55 -0
  187. package/test/ng/directive/options.spec.js +3583 -0
  188. package/test/ng/directive/ref.spec.js +575 -0
  189. package/test/ng/directive/repeat.spec.js +1675 -0
  190. package/test/ng/directive/script.spec.js +52 -0
  191. package/test/ng/directive/scrset.spec.js +67 -0
  192. package/test/ng/directive/select.spec.js +2541 -0
  193. package/test/ng/directive/show-hide.spec.js +253 -0
  194. package/test/ng/directive/src.spec.js +157 -0
  195. package/test/ng/directive/style.spec.js +178 -0
  196. package/test/ng/directive/switch.spec.js +647 -0
  197. package/test/ng/directive/validators.spec.js +717 -0
  198. package/test/ng/document.spec.js +52 -0
  199. package/test/ng/filter/filter.spec.js +714 -0
  200. package/test/ng/filter/filters.spec.js +35 -0
  201. package/test/ng/filter/limit-to.spec.js +251 -0
  202. package/test/ng/filter/order-by.spec.js +891 -0
  203. package/test/ng/filter.spec.js +149 -0
  204. package/test/ng/http-backend.spec.js +398 -0
  205. package/test/ng/http.spec.js +4071 -0
  206. package/test/ng/interpolate.spec.js +642 -0
  207. package/test/ng/interval.spec.js +343 -0
  208. package/test/ng/location.spec.js +3488 -0
  209. package/test/ng/on.spec.js +229 -0
  210. package/test/ng/parse.spec.js +4655 -0
  211. package/test/ng/prop.spec.js +805 -0
  212. package/test/ng/q.spec.js +2904 -0
  213. package/test/ng/root-element.spec.js +16 -0
  214. package/test/ng/sanitize-uri.spec.js +249 -0
  215. package/test/ng/sce.spec.js +660 -0
  216. package/test/ng/scope.spec.js +3442 -0
  217. package/test/ng/template-request.spec.js +236 -0
  218. package/test/ng/timeout.spec.js +351 -0
  219. package/test/ng/url-utils.spec.js +156 -0
  220. package/test/ng/utils.spec.js +144 -0
  221. package/test/original-test.html +21 -0
  222. package/test/public.spec.js +34 -0
  223. package/test/sanitize/bing-html.spec.js +36 -0
  224. package/test/server/express.js +158 -0
  225. package/test/test-utils.js +11 -0
  226. package/tsconfig.json +17 -0
  227. package/types/angular.d.ts +138 -0
  228. package/types/global.d.ts +9 -0
  229. package/types/index.d.ts +2357 -0
  230. package/types/jqlite.d.ts +558 -0
  231. package/vite.config.js +14 -0
@@ -0,0 +1,206 @@
1
+ import { urlResolve } from "../core/urlUtils";
2
+ import { forEach, isDefined, isPromiseLike, isUndefined } from "../core/utils";
3
+
4
+ /**
5
+ * @ngdoc service
6
+ * @name $xhrFactory
7
+ *
8
+ *
9
+ * @description
10
+ * Factory function used to create XMLHttpRequest objects.
11
+ *
12
+ * Replace or decorate this service to create your own custom XMLHttpRequest objects.
13
+ *
14
+ * ```
15
+ * angular.module('myApp', [])
16
+ * .factory('$xhrFactory', function() {
17
+ * return function createXhr(method, url) {
18
+ * return new window.XMLHttpRequest({mozSystem: true});
19
+ * };
20
+ * });
21
+ * ```
22
+ *
23
+ * @param {string} method HTTP method of the request (GET, POST, PUT, ..)
24
+ * @param {string} url URL of the request.
25
+ */
26
+ export function $xhrFactoryProvider() {
27
+ this.$get = () => {
28
+ return function createXhr() {
29
+ return new window.XMLHttpRequest();
30
+ };
31
+ };
32
+ }
33
+
34
+ /**
35
+ * @ngdoc service
36
+ * @name $httpBackend
37
+ * @requires $document
38
+ * @requires $xhrFactory
39
+ *
40
+ *
41
+ * @description
42
+ * HTTP backend used by the {@link ng.$http service} that delegates to
43
+ * XMLHttpRequest object and deals with browser incompatibilities.
44
+ *
45
+ * You should never need to use this service directly, instead use the higher-level abstractions:
46
+ * {@link ng.$http $http}.
47
+ *
48
+ */
49
+ export function $HttpBackendProvider() {
50
+ this.$get = [
51
+ "$browser",
52
+ "$xhrFactory",
53
+ function ($browser, $xhrFactory) {
54
+ return createHttpBackend($browser, $xhrFactory, $browser.defer);
55
+ },
56
+ ];
57
+ }
58
+
59
+ export function createHttpBackend($browser, createXhr, $browserDefer) {
60
+ // TODO(vojta): fix the signature
61
+ return function (
62
+ method,
63
+ url,
64
+ post,
65
+ callback,
66
+ headers,
67
+ timeout,
68
+ withCredentials,
69
+ responseType,
70
+ eventHandlers,
71
+ uploadEventHandlers,
72
+ ) {
73
+ url = url || $browser.url();
74
+
75
+ let xhr = createXhr(method, url);
76
+ let abortedByTimeout = false;
77
+
78
+ xhr.open(method, url, true);
79
+ forEach(headers, (value, key) => {
80
+ if (isDefined(value)) {
81
+ xhr.setRequestHeader(key, value);
82
+ }
83
+ });
84
+
85
+ xhr.onload = function () {
86
+ const statusText = xhr.statusText || "";
87
+
88
+ // responseText is the old-school way of retrieving response (supported by IE9)
89
+ // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
90
+ const response = "response" in xhr ? xhr.response : xhr.responseText;
91
+
92
+ let status = xhr.status;
93
+
94
+ // fix status code when it is 0 (0 status is undocumented).
95
+ // Occurs when accessing file resources or on Android 4.1 stock browser
96
+ // while retrieving files from application cache.
97
+ if (status === 0) {
98
+ status = response ? 200 : urlResolve(url).protocol === "file" ? 404 : 0;
99
+ }
100
+
101
+ completeRequest(
102
+ callback,
103
+ status,
104
+ response,
105
+ xhr.getAllResponseHeaders(),
106
+ statusText,
107
+ "complete",
108
+ );
109
+ };
110
+
111
+ xhr.onerror = function () {
112
+ // The response is always empty
113
+ // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
114
+ completeRequest(callback, -1, null, null, "", "error");
115
+ };
116
+ xhr.ontimeout = function () {
117
+ // The response is always empty
118
+ // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
119
+ completeRequest(callback, -1, null, null, "", "timeout");
120
+ };
121
+
122
+ xhr.onabort = function () {
123
+ completeRequest(
124
+ callback,
125
+ -1,
126
+ null,
127
+ null,
128
+ "",
129
+ abortedByTimeout ? "timeout" : "abort",
130
+ );
131
+ };
132
+
133
+ forEach(eventHandlers, (value, key) => {
134
+ xhr.addEventListener(key, value);
135
+ });
136
+
137
+ forEach(uploadEventHandlers, (value, key) => {
138
+ xhr.upload.addEventListener(key, value);
139
+ });
140
+
141
+ if (withCredentials) {
142
+ xhr.withCredentials = true;
143
+ }
144
+
145
+ if (responseType) {
146
+ try {
147
+ xhr.responseType = responseType;
148
+ } catch (e) {
149
+ // WebKit added support for the json responseType value on 09/03/2013
150
+ // https://bugs.webkit.org/show_bug.cgi?id=73648. Versions of Safari prior to 7 are
151
+ // known to throw when setting the value "json" as the response type. Other older
152
+ // browsers implementing the responseType
153
+ //
154
+ // The json response type can be ignored if not supported, because JSON payloads are
155
+ // parsed on the client-side regardless.
156
+ if (responseType !== "json") {
157
+ throw e;
158
+ }
159
+ }
160
+ }
161
+
162
+ xhr.send(isUndefined(post) ? null : post);
163
+
164
+ // Since we are using xhr.abort() when a request times out, we have to set a flag that
165
+ // indicates to requestAborted if the request timed out or was aborted.
166
+ //
167
+ // http.timeout = numerical timeout timeout
168
+ // http.timeout = $timeout timeout
169
+ // http.timeout = promise abort
170
+ // xhr.abort() abort (The xhr object is normally inaccessible, but
171
+ // can be exposed with the xhrFactory)
172
+ if (timeout > 0) {
173
+ var timeoutId = $browserDefer(() => {
174
+ timeoutRequest("timeout");
175
+ }, timeout);
176
+ } else if (isPromiseLike(timeout)) {
177
+ timeout.then(() => {
178
+ timeoutRequest(isDefined(timeout.$$timeoutId) ? "timeout" : "abort");
179
+ });
180
+ }
181
+
182
+ function timeoutRequest(reason) {
183
+ abortedByTimeout = reason === "timeout";
184
+ if (xhr) {
185
+ xhr.abort();
186
+ }
187
+ }
188
+
189
+ function completeRequest(
190
+ callback,
191
+ status,
192
+ response,
193
+ headersString,
194
+ statusText,
195
+ xhrStatus,
196
+ ) {
197
+ // cancel timeout and subsequent timeout promise resolution
198
+ if (isDefined(timeoutId)) {
199
+ $browserDefer.cancel(timeoutId);
200
+ }
201
+ xhr = null;
202
+
203
+ callback(status, response, headersString, statusText, xhrStatus);
204
+ }
205
+ };
206
+ }
@@ -0,0 +1,160 @@
1
+ /**
2
+ * @ngdoc service
3
+ * @name $log
4
+ *
5
+ * @description
6
+ * Simple service for logging. Default implementation safely writes the message
7
+ * into the browser's console (if present).
8
+ *
9
+ * The main purpose of this service is to simplify debugging and troubleshooting.
10
+ *
11
+ * To reveal the location of the calls to `$log` in the JavaScript console,
12
+ * you can "blackbox" the AngularJS source in your browser:
13
+ *
14
+ * [Mozilla description of blackboxing](https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Black_box_a_source).
15
+ * [Chrome description of blackboxing](https://developer.chrome.com/devtools/docs/blackboxing).
16
+ *
17
+ * Note: Not all browsers support blackboxing.
18
+ *
19
+ * The default is to log `debug` messages. You can use
20
+ * {@link ng.$logProvider ng.$logProvider#debugEnabled} to change this.
21
+ *
22
+ * @example
23
+ <example module="logExample" name="log-service">
24
+ <file name="script.js">
25
+ angular.module('logExample', [])
26
+ .controller('LogController', ['$scope', '$log', function($scope, $log) {
27
+ $scope.$log = $log;
28
+ $scope.message = 'Hello World!';
29
+ }]);
30
+ </file>
31
+ <file name="index.html">
32
+ <div ng-controller="LogController">
33
+ <p>Reload this page with open console, enter text and hit the log button...</p>
34
+ <label>Message:
35
+ <input type="text" ng-model="message" /></label>
36
+ <button ng-click="$log.log(message)">log</button>
37
+ <button ng-click="$log.warn(message)">warn</button>
38
+ <button ng-click="$log.info(message)">info</button>
39
+ <button ng-click="$log.error(message)">error</button>
40
+ <button ng-click="$log.debug(message)">debug</button>
41
+ </div>
42
+ </file>
43
+ </example>
44
+ */
45
+
46
+ import { forEach, isDefined, isError } from "../core/utils";
47
+
48
+ /**
49
+ * @ngdoc provider
50
+ * @name $logProvider
51
+ * @type {ng.ILogProvider}
52
+ *
53
+ * @description
54
+ * Use the `$logProvider` to configure how the application logs messages
55
+ */
56
+ export function $LogProvider() {
57
+ let debug = true;
58
+ const self = this;
59
+
60
+ /**
61
+ * @ngdoc method
62
+ * @name $logProvider#debugEnabled
63
+ * @description
64
+ * @param {boolean=} flag enable or disable debug level messages
65
+ * @returns {*} current value if used as getter or itself (chaining) if used as setter
66
+ */
67
+ this.debugEnabled = function (flag) {
68
+ if (isDefined(flag)) {
69
+ debug = flag;
70
+ return this;
71
+ }
72
+ return debug;
73
+ };
74
+
75
+ function formatError(arg) {
76
+ if (isError(arg)) {
77
+ if (arg.stack) {
78
+ arg =
79
+ arg.message && arg.stack.indexOf(arg.message) === -1
80
+ ? `Error: ${arg.message}\n${arg.stack}`
81
+ : arg.stack;
82
+ } else if (arg.sourceURL) {
83
+ arg = `${arg.message}\n${arg.sourceURL}:${arg.line}`;
84
+ }
85
+ }
86
+ return arg;
87
+ }
88
+
89
+ function consoleLog(type) {
90
+ const console = window.console || {};
91
+ const logFn = console[type] || console.log || (() => {});
92
+
93
+ return function () {
94
+ var args = [];
95
+ forEach(arguments, function (arg) {
96
+ args.push(formatError(arg));
97
+ });
98
+ return logFn.apply(console, args);
99
+ };
100
+ }
101
+
102
+ this.$get = [
103
+ function () {
104
+ return {
105
+ /**
106
+ * @ngdoc method
107
+ * @name $log#log
108
+ *
109
+ * @description
110
+ * Write a log message
111
+ */
112
+ log: consoleLog("log"),
113
+
114
+ /**
115
+ * @ngdoc method
116
+ * @name $log#info
117
+ *
118
+ * @description
119
+ * Write an information message
120
+ */
121
+ info: consoleLog("info"),
122
+
123
+ /**
124
+ * @ngdoc method
125
+ * @name $log#warn
126
+ *
127
+ * @description
128
+ * Write a warning message
129
+ */
130
+ warn: consoleLog("warn"),
131
+
132
+ /**
133
+ * @ngdoc method
134
+ * @name $log#error
135
+ *
136
+ * @description
137
+ * Write an error message
138
+ */
139
+ error: consoleLog("error"),
140
+
141
+ /**
142
+ * @ngdoc method
143
+ * @name $log#debug
144
+ *
145
+ * @description
146
+ * Write a debug message
147
+ */
148
+ debug: (function () {
149
+ const fn = consoleLog("debug");
150
+
151
+ return function () {
152
+ if (debug) {
153
+ fn.apply(self, arguments);
154
+ }
155
+ };
156
+ })(),
157
+ };
158
+ },
159
+ ];
160
+ }
@@ -0,0 +1,139 @@
1
+ import { defaultHttpResponseTransform } from "./http";
2
+ import { extend, isArray, isString, isUndefined, minErr } from "../core/utils";
3
+
4
+ var $templateRequestMinErr = minErr("$templateRequest");
5
+
6
+ /**
7
+ * @ngdoc provider
8
+ * @name $templateRequestProvider
9
+ * @this
10
+ *
11
+ * @description
12
+ * Used to configure the options passed to the {@link $http} service when making a template request.
13
+ *
14
+ * For example, it can be used for specifying the "Accept" header that is sent to the server, when
15
+ * requesting a template.
16
+ */
17
+ export function TemplateRequestProvider() {
18
+ var httpOptions;
19
+
20
+ /**
21
+ * @ngdoc method
22
+ * @name $templateRequestProvider#httpOptions
23
+ * @description
24
+ * The options to be passed to the {@link $http} service when making the request.
25
+ * You can use this to override options such as the "Accept" header for template requests.
26
+ *
27
+ * The {@link $templateRequest} will set the `cache` and the `transformResponse` properties of the
28
+ * options if not overridden here.
29
+ *
30
+ * @param {string=} value new value for the {@link $http} options.
31
+ * @returns {string|self} Returns the {@link $http} options when used as getter and self if used as setter.
32
+ */
33
+ this.httpOptions = function (val) {
34
+ if (val) {
35
+ httpOptions = val;
36
+ return this;
37
+ }
38
+ return httpOptions;
39
+ };
40
+
41
+ /**
42
+ * @ngdoc service
43
+ * @name $templateRequest
44
+ *
45
+ * @description
46
+ * The `$templateRequest` service runs security checks then downloads the provided template using
47
+ * `$http` and, upon success, stores the contents inside of `$templateCache`. If the HTTP request
48
+ * fails or the response data of the HTTP request is empty, a `$compile` error will be thrown (the
49
+ * exception can be thwarted by setting the 2nd parameter of the function to true). Note that the
50
+ * contents of `$templateCache` are trusted, so the call to `$sce.getTrustedUrl(tpl)` is omitted
51
+ * when `tpl` is of type string and `$templateCache` has the matching entry.
52
+ *
53
+ * If you want to pass custom options to the `$http` service, such as setting the Accept header you
54
+ * can configure this via {@link $templateRequestProvider#httpOptions}.
55
+ *
56
+ * `$templateRequest` is used internally by {@link $compile}, {@link ngRoute.$route}, and directives such
57
+ * as {@link ngInclude} to download and cache templates.
58
+ *
59
+ * 3rd party modules should use `$templateRequest` if their services or directives are loading
60
+ * templates.
61
+ *
62
+ * @param {string|TrustedResourceUrl} tpl The HTTP request template URL
63
+ * @param {boolean=} ignoreRequestError Whether or not to ignore the exception when the request fails or the template is empty
64
+ *
65
+ * @return {Promise} a promise for the HTTP response data of the given URL.
66
+ *
67
+ * @property {number} totalPendingRequests total amount of pending template requests being downloaded.
68
+ */
69
+ this.$get = [
70
+ "$exceptionHandler",
71
+ "$templateCache",
72
+ "$http",
73
+ "$q",
74
+ "$sce",
75
+ function ($exceptionHandler, $templateCache, $http, $q, $sce) {
76
+ function handleRequestFn(tpl, ignoreRequestError) {
77
+ handleRequestFn.totalPendingRequests++;
78
+
79
+ // We consider the template cache holds only trusted templates, so
80
+ // there's no need to go through adding the template again to the trusted
81
+ // resources for keys that already are included in there. This also makes
82
+ // AngularJS accept any script directive, no matter its name. However, we
83
+ // still need to unwrap trusted types.
84
+ if (!isString(tpl) || isUndefined($templateCache.get(tpl))) {
85
+ tpl = $sce.getTrustedResourceUrl(tpl);
86
+ }
87
+
88
+ var transformResponse =
89
+ $http.defaults && $http.defaults.transformResponse;
90
+
91
+ if (isArray(transformResponse)) {
92
+ transformResponse = transformResponse.filter(function (transformer) {
93
+ return transformer !== defaultHttpResponseTransform;
94
+ });
95
+ } else if (transformResponse === defaultHttpResponseTransform) {
96
+ transformResponse = null;
97
+ }
98
+
99
+ return $http
100
+ .get(
101
+ tpl,
102
+ extend(
103
+ {
104
+ cache: $templateCache,
105
+ transformResponse: transformResponse,
106
+ },
107
+ httpOptions,
108
+ ),
109
+ )
110
+ .finally(function () {
111
+ handleRequestFn.totalPendingRequests--;
112
+ })
113
+ .then(function (response) {
114
+ return $templateCache.put(tpl, response.data);
115
+ }, handleError);
116
+
117
+ function handleError(resp) {
118
+ if (!ignoreRequestError) {
119
+ resp = $templateRequestMinErr(
120
+ "tpload",
121
+ "Failed to load template: {0} (HTTP status: {1} {2})",
122
+ tpl,
123
+ resp.status,
124
+ resp.statusText,
125
+ );
126
+
127
+ $exceptionHandler(resp);
128
+ }
129
+
130
+ return $q.reject(resp);
131
+ }
132
+ }
133
+
134
+ handleRequestFn.totalPendingRequests = 0;
135
+
136
+ return handleRequestFn;
137
+ },
138
+ ];
139
+ }