@angular-wave/angular.ts 0.7.8 → 0.8.0

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 (285) hide show
  1. package/@types/core/parse/parse.d.ts +6 -7
  2. package/@types/directive/bind/bind.d.ts +2 -1
  3. package/@types/index.d.ts +1 -1
  4. package/@types/interface.d.ts +3 -1
  5. package/@types/{public.d.ts → ng.d.ts} +2 -2
  6. package/@types/router/globals.d.ts +1 -1
  7. package/@types/router/path/path-utils.d.ts +8 -11
  8. package/@types/router/state/interface.d.ts +1 -1
  9. package/@types/router/state/state-object.d.ts +1 -1
  10. package/@types/router/state/state-service.d.ts +8 -7
  11. package/@types/router/state-filters.d.ts +24 -2
  12. package/@types/router/transition/transition.d.ts +12 -15
  13. package/@types/router/url/url-matcher.d.ts +3 -3
  14. package/@types/router/url/url-rule.d.ts +1 -0
  15. package/@types/router/url/url-rules.d.ts +26 -6
  16. package/@types/router/url/url-service.d.ts +28 -38
  17. package/@types/services/http/http.d.ts +48 -1
  18. package/@types/services/http-backend/http-backend.d.ts +48 -35
  19. package/@types/services/location/interface.d.ts +55 -0
  20. package/@types/services/location/location.d.ts +225 -252
  21. package/@types/shared/common.d.ts +0 -2
  22. package/@types/shared/interface.d.ts +0 -4
  23. package/@types/{router/common → shared}/queue.d.ts +2 -2
  24. package/@types/shared/url-utils/interface.d.ts +0 -1
  25. package/@types/shared/url-utils/url-utils.d.ts +0 -5
  26. package/@types/shared/utils.d.ts +29 -6
  27. package/Makefile +6 -3
  28. package/dist/angular-ts.esm.js +960 -1062
  29. package/dist/angular-ts.umd.js +960 -1062
  30. package/dist/angular-ts.umd.min.js +1 -1
  31. package/docs/assets/scss/index.scss +23 -0
  32. package/docs/content/_index.md +9 -8
  33. package/docs/content/docs/_index.md +1 -1
  34. package/docs/content/docs/directive/app.md +1 -1
  35. package/docs/content/docs/directive/bind.md +1 -1
  36. package/docs/content/docs/directive/blur.md +1 -1
  37. package/docs/content/docs/directive/channel.md +2 -2
  38. package/docs/content/docs/directive/class-even.md +1 -1
  39. package/docs/content/docs/directive/class-odd.md +1 -1
  40. package/docs/content/docs/directive/class.md +1 -1
  41. package/docs/content/docs/directive/click.md +1 -1
  42. package/docs/content/docs/directive/copy.md +1 -1
  43. package/docs/content/docs/directive/cut.md +1 -1
  44. package/docs/content/docs/directive/dblclick.md +1 -1
  45. package/docs/content/docs/directive/focus.md +1 -1
  46. package/docs/content/docs/directive/get.md +3 -3
  47. package/docs/content/docs/directive/keydown.md +1 -1
  48. package/docs/content/docs/directive/keyup.md +1 -1
  49. package/docs/content/docs/directive/load.md +1 -1
  50. package/docs/content/docs/directive/mousedown.md +1 -1
  51. package/docs/content/docs/directive/mouseenter.md +1 -1
  52. package/docs/content/docs/directive/mouseleave.md +1 -1
  53. package/docs/content/docs/directive/mousemove.md +1 -1
  54. package/docs/content/docs/directive/mouseout.md +1 -1
  55. package/docs/content/docs/directive/mouseover.md +1 -1
  56. package/docs/content/docs/directive/mouseup.md +1 -1
  57. package/docs/content/docs/directive/non-bindable.md +28 -0
  58. package/docs/content/docs/provider/locationProvider.md +26 -0
  59. package/docs/content/docs/provider/templateCacheProvider.md +2 -2
  60. package/docs/content/docs/service/location.md +57 -0
  61. package/docs/content/docs/service/url.md +5 -0
  62. package/docs/layouts/partials/hooks/head-end.html +1 -1
  63. package/docs/layouts/shortcodes/version.html +1 -0
  64. package/docs/static/examples/counter/counter-test.html +0 -4
  65. package/docs/static/examples/eventbus/eventbus-test.html +0 -4
  66. package/docs/static/examples/ng-non-bindable/ng-non-bindable-test.html +13 -0
  67. package/docs/static/examples/ng-non-bindable/ng-non-bindable.html +3 -0
  68. package/docs/static/examples/ng-non-bindable/ng-non-bindable.test.js +11 -0
  69. package/docs/static/typedoc/assets/highlight.css +6 -6
  70. package/docs/static/typedoc/assets/navigation.js +1 -1
  71. package/docs/static/typedoc/assets/search.js +1 -1
  72. package/docs/static/typedoc/classes/Location.html +55 -0
  73. package/docs/static/typedoc/classes/LocationProvider.html +20 -0
  74. package/docs/static/typedoc/index.html +1 -1
  75. package/docs/static/typedoc/interfaces/DefaultPorts.html +5 -0
  76. package/docs/static/typedoc/interfaces/Html5Mode.html +23 -0
  77. package/docs/static/typedoc/interfaces/Provider.html +2 -1
  78. package/docs/static/typedoc/interfaces/UrlParts.html +9 -0
  79. package/docs/static/typedoc/types/AnnotatedFactory.html +1 -1
  80. package/docs/static/typedoc/types/Expression.html +1 -1
  81. package/docs/static/typedoc/types/UrlChangeListener.html +5 -0
  82. package/docs/static/version.js +13 -0
  83. package/docs/test-results/.last-run.json +4 -0
  84. package/docs/test-results/static-examples-counter-counter-counter-example/error-context.md +50 -0
  85. package/package.json +1 -1
  86. package/src/{loader.js → angular.js} +1 -1
  87. package/src/angular.spec.js +189 -21
  88. package/src/animations/animate-css.js +17 -18
  89. package/src/animations/animate.spec.js +1 -1
  90. package/src/animations/shared.js +2 -3
  91. package/src/binding.spec.js +1 -1
  92. package/src/core/compile/compile.js +4 -7
  93. package/src/core/compile/compile.spec.js +1 -1
  94. package/src/core/controller/controller.spec.js +1 -1
  95. package/src/core/controller/controller.test.js +1 -0
  96. package/src/core/di/injector.js +7 -8
  97. package/src/core/di/injector.spec.js +2 -2
  98. package/src/core/di/injector.test.js +2 -2
  99. package/src/core/di/internal-injector.js +3 -6
  100. package/src/core/filter/filter.js +1 -1
  101. package/src/core/filter/filter.spec.js +1 -1
  102. package/src/core/filter/filter.test.js +1 -0
  103. package/src/core/interpolate/interpolate.js +4 -6
  104. package/src/core/interpolate/interpolate.spec.js +1 -1
  105. package/src/core/interpolate/interpolate.test.js +1 -0
  106. package/src/core/parse/ast/ast.spec.js +1 -1
  107. package/src/core/parse/ast/ast.test.js +1 -1
  108. package/src/core/parse/lexer/lexer.spec.js +1 -1
  109. package/src/core/parse/parse.js +150 -146
  110. package/src/core/parse/parse.spec.js +17 -16
  111. package/src/core/prop.spec.js +1 -1
  112. package/src/core/root-element.spec.js +1 -1
  113. package/src/core/scope/scope.js +10 -11
  114. package/src/core/scope/scope.spec.js +3 -4
  115. package/src/directive/aria/aria.spec.js +1 -1
  116. package/src/directive/aria/aria.test.js +1 -0
  117. package/src/directive/attrs/attrs.spec.js +1 -1
  118. package/src/directive/attrs/attrs.test.js +1 -0
  119. package/src/directive/attrs/boolean.spec.js +1 -1
  120. package/src/directive/attrs/boolean.test.js +1 -0
  121. package/src/directive/attrs/element-style.spec.js +1 -1
  122. package/src/directive/attrs/element-style.test.js +1 -0
  123. package/src/directive/attrs/src.spec.js +1 -1
  124. package/src/directive/attrs/src.test.js +1 -0
  125. package/src/directive/bind/bind-html.spec.js +1 -1
  126. package/src/directive/bind/bind.js +1 -0
  127. package/src/directive/bind/bind.spec.js +1 -1
  128. package/src/directive/bind/bind.test.js +1 -0
  129. package/src/directive/channel/channel.spec.js +1 -1
  130. package/src/directive/channel/channel.test.js +1 -0
  131. package/src/directive/class/class.spec.js +1 -1
  132. package/src/directive/class/class.test.js +1 -0
  133. package/src/directive/cloak/cloak.spec.js +1 -1
  134. package/src/directive/cloak/cloak.test.js +1 -0
  135. package/src/directive/controller/controller.spec.js +1 -1
  136. package/src/directive/controller/controller.test.js +1 -0
  137. package/src/directive/events/click.spec.js +1 -1
  138. package/src/directive/events/event.spec.js +1 -1
  139. package/src/directive/events/events.test.js +1 -0
  140. package/src/directive/form/form.js +8 -5
  141. package/src/directive/form/form.spec.js +1 -1
  142. package/src/directive/form/form.test.js +1 -0
  143. package/src/directive/http/delete.spec.js +1 -1
  144. package/src/directive/http/form-test.html +18 -0
  145. package/src/directive/http/get.spec.js +1 -1
  146. package/src/directive/http/http.js +12 -3
  147. package/src/directive/http/post.spec.js +504 -9
  148. package/src/directive/http/put.spec.js +1 -1
  149. package/src/directive/if/if.spec.js +1 -1
  150. package/src/directive/include/include.spec.js +1 -1
  151. package/src/directive/init/init.spec.js +1 -1
  152. package/src/directive/init/init.test.js +1 -0
  153. package/src/directive/input/input.js +13 -15
  154. package/src/directive/input/input.spec.js +1 -2
  155. package/src/directive/input/input.test.js +1 -0
  156. package/src/directive/messages/messages.spec.js +1 -1
  157. package/src/directive/messages/messages.test.js +1 -0
  158. package/src/directive/model/model.js +13 -13
  159. package/src/directive/model/model.spec.js +1 -1
  160. package/src/directive/model/model.test.js +1 -0
  161. package/src/directive/model-options/model-option.test.js +1 -0
  162. package/src/directive/model-options/model-options.js +1 -1
  163. package/src/directive/model-options/model-options.spec.js +1 -1
  164. package/src/directive/non-bindable/non-bindable.spec.js +1 -1
  165. package/src/directive/non-bindable/non-bindable.test.js +1 -0
  166. package/src/directive/observe/observe.spec.js +1 -1
  167. package/src/directive/observe/observe.test.js +1 -0
  168. package/src/directive/on/on.spec.js +1 -1
  169. package/src/directive/on/on.test.js +1 -0
  170. package/src/directive/options/options.spec.js +1 -1
  171. package/src/directive/options/options.test.js +1 -0
  172. package/src/directive/ref/href.spec.js +1 -1
  173. package/src/directive/ref/href.test.js +2 -0
  174. package/src/directive/ref/ref.spec.js +1 -1
  175. package/src/directive/repeat/repeat.spec.js +2 -3
  176. package/src/directive/repeat/repeat.test.js +1 -0
  177. package/src/directive/script/script.spec.js +1 -1
  178. package/src/directive/script/script.test.js +1 -0
  179. package/src/directive/select/select.js +1 -1
  180. package/src/directive/select/select.spec.js +1 -1
  181. package/src/directive/select/select.test.js +1 -0
  182. package/src/directive/setter/setter.spec.js +1 -1
  183. package/src/directive/setter/setter.test.js +1 -0
  184. package/src/directive/show-hide/show-hide.spec.js +1 -1
  185. package/src/directive/show-hide/show-hide.test.js +1 -0
  186. package/src/directive/style/style.spec.js +1 -1
  187. package/src/directive/style/style.test.js +1 -0
  188. package/src/directive/switch/switch.spec.js +1 -1
  189. package/src/directive/switch/switch.test.js +1 -0
  190. package/src/directive/validators/validators.js +82 -84
  191. package/src/directive/validators/validators.spec.js +5 -4
  192. package/src/directive/validators/validators.test.js +1 -0
  193. package/src/filters/filter.spec.js +1 -1
  194. package/src/filters/filters.spec.js +1 -1
  195. package/src/filters/limit-to.js +2 -3
  196. package/src/filters/limit-to.spec.js +1 -1
  197. package/src/filters/order-by.spec.js +1 -1
  198. package/src/index.js +1 -1
  199. package/src/injection-tokens.js +5 -1
  200. package/src/interface.ts +3 -1
  201. package/src/loader.md +0 -155
  202. package/src/{public.js → ng.js} +7 -8
  203. package/src/{public.spec.js → ng.spec.js} +1 -1
  204. package/src/router/directives/state-directives.spec.js +8 -7
  205. package/src/router/directives/view-directive.js +2 -8
  206. package/src/router/directives/view-directive.spec.js +8 -9
  207. package/src/router/{common/common.html → glob/glob.html} +2 -3
  208. package/src/router/{common/common.test.js → glob/glob.test.js} +2 -1
  209. package/src/router/globals.js +1 -1
  210. package/src/router/path/path-utils.js +5 -0
  211. package/src/router/router-test-hashbang.html +45 -0
  212. package/src/router/services.spec.js +5 -6
  213. package/src/router/state/interface.ts +1 -1
  214. package/src/router/state/state-builder.js +3 -3
  215. package/src/router/state/state-builder.spec.js +1 -1
  216. package/src/router/state/state-object.js +1 -1
  217. package/src/router/state/state-registry.js +2 -2
  218. package/src/router/state/state-service.js +13 -10
  219. package/src/router/state/state.spec.js +23 -22
  220. package/src/router/state/state.test.js +1 -0
  221. package/src/router/state/views.js +1 -1
  222. package/src/router/state-filter.spec.js +1 -1
  223. package/src/router/state-filters.js +13 -9
  224. package/src/router/template-factory.js +5 -4
  225. package/src/router/template-factory.spec.js +1 -1
  226. package/src/router/transition/hook-registry.js +1 -1
  227. package/src/router/transition/transition-service.js +6 -5
  228. package/src/router/transition/transition.js +4 -4
  229. package/src/router/url/url-matcher.js +3 -3
  230. package/src/router/url/url-rule.js +1 -0
  231. package/src/router/url/url-rules.js +8 -5
  232. package/src/router/url/url-service.js +77 -76
  233. package/src/router/url/url-service.spec.js +55 -39
  234. package/src/router/url/url.test.js +1 -0
  235. package/src/router/view/view.js +4 -5
  236. package/src/router/view/view.spec.js +10 -12
  237. package/src/router/view/view.test.js +1 -0
  238. package/src/router/view-hook.spec.js +1 -1
  239. package/src/router/view-scroll.spec.js +1 -1
  240. package/src/services/anchor-scroll.html +2 -2
  241. package/src/services/anchor-scroll.js +5 -4
  242. package/src/services/http/http.js +9 -4
  243. package/src/services/http/http.spec.js +2 -7
  244. package/src/services/http/template-request.spec.js +1 -1
  245. package/src/services/http-backend/http-backend.js +51 -77
  246. package/src/services/http-backend/http-backend.spec.js +1 -2
  247. package/src/services/http-backend/http-backend.test.js +1 -0
  248. package/src/services/location/interface.ts +62 -0
  249. package/src/services/location/location.js +433 -520
  250. package/src/services/location/location.spec.js +909 -530
  251. package/src/services/location/location.test.js +2 -2
  252. package/src/services/log/log.spec.js +1 -1
  253. package/src/services/log/log.test.js +1 -0
  254. package/src/services/pubsub/pubsub.spec.js +1 -1
  255. package/src/services/sce/sce.js +5 -7
  256. package/src/services/sce/sce.md +2 -2
  257. package/src/services/sce/sce.spec.js +1 -1
  258. package/src/services/template-cache/template-cache.spec.js +1 -1
  259. package/src/services/template-cache/template-cache.test.js +1 -0
  260. package/src/shared/common.js +0 -5
  261. package/src/shared/common.spec.js +1 -1
  262. package/src/shared/interface.ts +0 -4
  263. package/src/{router/common → shared}/queue.js +7 -7
  264. package/src/shared/shared.html +1 -0
  265. package/src/shared/shared.test.js +1 -0
  266. package/src/shared/url-utils/interface.ts +0 -2
  267. package/src/shared/url-utils/url-utils.js +6 -30
  268. package/src/shared/url-utils/url-utils.spec.js +10 -9
  269. package/src/shared/utils.js +32 -9
  270. package/src/shared/utils.spec.js +35 -1
  271. package/src/src.html +1 -2
  272. package/typedoc.json +0 -1
  273. package/utils/express.js +27 -1
  274. package/utils/version.cjs +23 -0
  275. package/@types/router/state-provider.d.ts +0 -123
  276. package/src/directive/non-bindable/non-bindable.md +0 -17
  277. package/src/loader.spec.js +0 -169
  278. package/src/router/state-provider.js +0 -146
  279. package/src/services/location/location.md +0 -114
  280. package/src/shared/url-utils/url-utils.md +0 -46
  281. /package/@types/{loader.d.ts → angular.d.ts} +0 -0
  282. /package/@types/router/{common → glob}/glob.d.ts +0 -0
  283. /package/src/router/{common → glob}/glob.js +0 -0
  284. /package/src/router/{common → glob}/glob.spec.js +0 -0
  285. /package/src/{router/common → shared}/queue.spec.js +0 -0
@@ -5,6 +5,7 @@ import {
5
5
  isString,
6
6
  getNodeName,
7
7
  } from "../shared/utils.js";
8
+ import { $injectTokens as $t } from "../injection-tokens.js";
8
9
 
9
10
  /**
10
11
  * @typedef {Object} AnchorScrollObject
@@ -25,8 +26,8 @@ export class AnchorScrollProvider {
25
26
  }
26
27
 
27
28
  $get = [
28
- "$location",
29
- "$rootScope",
29
+ $t.$location,
30
+ $t.$rootScope,
30
31
  /**
31
32
  *
32
33
  * @param {import('../services/location/location.js').Location} $location
@@ -104,7 +105,7 @@ export class AnchorScrollProvider {
104
105
  ? hash
105
106
  : isNumber(hash)
106
107
  ? hash.toString()
107
- : $location.hash();
108
+ : $location.getHash();
108
109
  let elm;
109
110
 
110
111
  // empty hash, scroll to the top of the page
@@ -121,7 +122,7 @@ export class AnchorScrollProvider {
121
122
  };
122
123
 
123
124
  // does not scroll when user clicks on anchor link that is currently on
124
- // (no url change, no $location.hash() change), browser native does scroll
125
+ // (no url change, no $location.getHash() change), browser native does scroll
125
126
  if (this.autoScrollingEnabled) {
126
127
  $rootScope["$location"] = $location;
127
128
  $rootScope.$watch("$location.$$hash", (newVal, oldVal) => {
@@ -291,6 +291,7 @@ export function HttpProvider() {
291
291
  });
292
292
 
293
293
  let useApplyAsync = false;
294
+
294
295
  /**
295
296
  * Configure $http service to combine processing of multiple http responses received at around
296
297
  * the same time via {@link ng.$rootScope.Scope#$applyAsync $rootScope.$applyAsync}. This can result in
@@ -323,7 +324,7 @@ export function HttpProvider() {
323
324
  *
324
325
  * {@link ng.$http#interceptors Interceptors detailed info}
325
326
  */
326
- const interceptorFactories = (this.interceptors = []);
327
+ this.interceptors = [];
327
328
 
328
329
  /**
329
330
  * Array containing URLs whose origins are trusted to receive the XSRF token. See the
@@ -360,8 +361,10 @@ export function HttpProvider() {
360
361
  * $http.get('https://stats.example.com/activity').then(...);
361
362
  * }]);
362
363
  * ```
364
+ *
365
+ * @type {string[]}
363
366
  */
364
- const xsrfTrustedOrigins = (this.xsrfTrustedOrigins = []);
367
+ this.xsrfTrustedOrigins = [];
365
368
 
366
369
  /**
367
370
  * This property is deprecated. Use {@link $httpProvider#xsrfTrustedOrigins xsrfTrustedOrigins}
@@ -407,7 +410,7 @@ export function HttpProvider() {
407
410
  */
408
411
  const reversedInterceptors = [];
409
412
 
410
- interceptorFactories.forEach((interceptorFactory) => {
413
+ this.interceptors.forEach((interceptorFactory) => {
411
414
  reversedInterceptors.unshift(
412
415
  isString(interceptorFactory)
413
416
  ? $injector.get(interceptorFactory)
@@ -418,7 +421,9 @@ export function HttpProvider() {
418
421
  /**
419
422
  * A function to check request URLs against a list of allowed origins.
420
423
  */
421
- const urlIsAllowedOrigin = urlIsAllowedOriginFactory(xsrfTrustedOrigins);
424
+ const urlIsAllowedOrigin = urlIsAllowedOriginFactory(
425
+ this.xsrfTrustedOrigins,
426
+ );
422
427
 
423
428
  /**
424
429
  * @property {Array.<Object>} requestConfig Array of config objects for currently pending
@@ -1,6 +1,6 @@
1
1
  import { createInjector } from "../../core/di/injector.js";
2
2
  import { isObject } from "../../shared/utils.js";
3
- import { Angular } from "../../loader.js";
3
+ import { Angular } from "../../angular.js";
4
4
  import { wait } from "../../shared/test-utils.js";
5
5
 
6
6
  export function getLastAjaxRequest() {
@@ -238,12 +238,7 @@ describe("$http", function () {
238
238
  });
239
239
  expect(response.headers).toBeDefined();
240
240
  expect(response.headers instanceof Function).toBe(true);
241
- expect(response.headers("Content-Type")).toBe(
242
- "application/json; charset=utf-8",
243
- );
244
- expect(response.headers("content-type")).toBe(
245
- "application/json; charset=utf-8",
246
- );
241
+ expect(response.headers("Content-Type")).toBe("text/html; charset=utf-8");
247
242
  });
248
243
 
249
244
  it("may returns all response headers", async function () {
@@ -1,5 +1,5 @@
1
1
  import { createInjector } from "../../core/di/injector.js";
2
- import { Angular } from "../../loader.js";
2
+ import { Angular } from "../../angular.js";
3
3
  import { wait } from "../../shared/test-utils.js";
4
4
 
5
5
  describe("$templateRequest", () => {
@@ -1,25 +1,14 @@
1
- import { trimEmptyHash, urlResolve } from "../../shared/url-utils/url-utils.js";
1
+ import { trimEmptyHash } from "../../shared/url-utils/url-utils.js";
2
2
  import { isDefined, isPromiseLike, isUndefined } from "../../shared/utils.js";
3
3
 
4
4
  /**
5
- * HTTP backend used by the {@link ng.$http service} that delegates to
5
+ * HTTP backend used by the `$http` that delegates to
6
6
  * XMLHttpRequest object and deals with browser incompatibilities.
7
- *
8
- * You should never need to use this service directly, instead use the higher-level abstractions:
9
- * {@link ng.$http $http}.
10
- *
11
- */
12
- /**
13
- * HTTP backend used by the {@link ng.$http service} that delegates to
14
- * XMLHttpRequest object and deals with browser incompatibilities.
15
- *
16
- * You should never need to use this service directly, instead use the higher-level abstractions:
17
- * {@link ng.$http $http}.
18
- *
7
+ * You should never need to use this service directly.
19
8
  */
20
9
  export class HttpBackendProvider {
21
10
  constructor() {
22
- this.$get = [() => createHttpBackend()];
11
+ this.$get = () => createHttpBackend();
23
12
  }
24
13
  }
25
14
 
@@ -27,7 +16,21 @@ export class HttpBackendProvider {
27
16
  * @returns
28
17
  */
29
18
  export function createHttpBackend() {
30
- // TODO(vojta): fix the signature
19
+ /**
20
+ * Makes an HTTP request using XMLHttpRequest with flexible options.
21
+ *
22
+ * @param {string} method - The HTTP method (e.g., "GET", "POST").
23
+ * @param {string} [url] - The URL to send the request to. Defaults to the current page URL.
24
+ * @param {*} [post] - The body to send with the request, if any.
25
+ * @param {function(number, any, string|null, string, string): void} [callback] - Callback invoked when the request completes.
26
+ * @param {Object<string, string|undefined>} [headers] - Headers to set on the request.
27
+ * @param {number|Promise<any>} [timeout] - Timeout in ms or a cancellable promise.
28
+ * @param {boolean} [withCredentials] - Whether to send credentials with the request.
29
+ * @param {XMLHttpRequestResponseType} [responseType] - The type of data expected in the response.
30
+ * @param {Object<string, EventListener>} [eventHandlers] - Event listeners for the XMLHttpRequest object.
31
+ * @param {Object<string, EventListener>} [uploadEventHandlers] - Event listeners for the XMLHttpRequest.upload object.
32
+ * @returns {void}
33
+ */
31
34
  return function (
32
35
  method,
33
36
  url,
@@ -44,34 +47,31 @@ export function createHttpBackend() {
44
47
 
45
48
  const xhr = new XMLHttpRequest();
46
49
  let abortedByTimeout = false;
50
+ let timeoutId;
47
51
 
48
52
  xhr.open(method, url, true);
53
+
49
54
  if (headers) {
50
- Object.entries(headers).forEach(([key, value]) => {
55
+ for (const [key, value] of Object.entries(headers)) {
51
56
  if (isDefined(value)) {
52
57
  xhr.setRequestHeader(key, value);
53
58
  }
54
- });
59
+ }
55
60
  }
56
61
 
57
- xhr.onload = function () {
62
+ xhr.onload = () => {
63
+ let status = xhr.status || 0;
58
64
  const statusText = xhr.statusText || "";
59
65
 
60
- let status = xhr.status;
61
-
62
- // fix status code when it is 0 (0 status is undocumented).
63
- // Occurs when accessing file resources or on Android 4.1 stock browser
64
- // while retrieving files from application cache.
65
66
  if (status === 0) {
66
67
  status = xhr.response
67
68
  ? 200
68
- : urlResolve(url).protocol === "file"
69
+ : new URL(url).protocol === "file:"
69
70
  ? 404
70
71
  : 0;
71
72
  }
72
73
 
73
74
  completeRequest(
74
- callback,
75
75
  status,
76
76
  xhr.response,
77
77
  xhr.getAllResponseHeaders(),
@@ -80,20 +80,11 @@ export function createHttpBackend() {
80
80
  );
81
81
  };
82
82
 
83
- xhr.onerror = function () {
84
- // The response is always empty
85
- // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
86
- completeRequest(callback, -1, null, null, "", "error");
87
- };
88
- xhr.ontimeout = function () {
89
- // The response is always empty
90
- // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
91
- completeRequest(callback, -1, null, null, "", "timeout");
92
- };
83
+ xhr.onerror = () => completeRequest(-1, null, null, "", "error");
84
+ xhr.ontimeout = () => completeRequest(-1, null, null, "", "timeout");
93
85
 
94
- xhr.onabort = function () {
86
+ xhr.onabort = () => {
95
87
  completeRequest(
96
- callback,
97
88
  -1,
98
89
  null,
99
90
  null,
@@ -103,16 +94,15 @@ export function createHttpBackend() {
103
94
  };
104
95
 
105
96
  if (eventHandlers) {
106
- eventHandlers &&
107
- Object.entries(eventHandlers).forEach(([key, value]) => {
108
- xhr.addEventListener(key, value);
109
- });
97
+ for (const [key, handler] of Object.entries(eventHandlers)) {
98
+ xhr.addEventListener(key, handler);
99
+ }
110
100
  }
111
101
 
112
102
  if (uploadEventHandlers) {
113
- Object.entries(uploadEventHandlers).forEach(([key, value]) => {
114
- xhr.upload.addEventListener(key, value);
115
- });
103
+ for (const [key, handler] of Object.entries(uploadEventHandlers)) {
104
+ xhr.upload.addEventListener(key, handler);
105
+ }
116
106
  }
117
107
 
118
108
  if (withCredentials) {
@@ -123,61 +113,45 @@ export function createHttpBackend() {
123
113
  try {
124
114
  xhr.responseType = responseType;
125
115
  } catch (e) {
126
- // WebKit added support for the json responseType value on 09/03/2013
127
- // https://bugs.webkit.org/show_bug.cgi?id=73648. Versions of Safari prior to 7 are
128
- // known to throw when setting the value "json" as the response type. Other older
129
- // browsers implementing the responseType
130
- //
131
- // The json response type can be ignored if not supported, because JSON payloads are
132
- // parsed on the client-side regardless.
133
- if (responseType !== "json") {
134
- throw e;
135
- }
116
+ if (responseType !== "json") throw e;
136
117
  }
137
118
  }
138
119
 
139
120
  xhr.send(isUndefined(post) ? null : post);
140
121
 
141
- // Since we are using xhr.abort() when a request times out, we have to set a flag that
142
- // indicates to requestAborted if the request timed out or was aborted.
143
- //
144
- // http.timeout = numerical timeout timeout
145
- // http.timeout = $timeout timeout
146
- // http.timeout = promise abort
147
- // xhr.abort() abort (The xhr object is normally inaccessible, but
148
- // can be exposed with the xhrFactory)
149
- /** @type {number} */
150
- let timeoutId;
151
- if (timeout > 0) {
152
- timeoutId = setTimeout(() => {
153
- timeoutRequest("timeout");
154
- }, timeout);
122
+ if (typeof timeout === "number" && timeout > 0) {
123
+ timeoutId = setTimeout(() => timeoutRequest("timeout"), timeout);
155
124
  } else if (isPromiseLike(timeout)) {
156
- timeout.then(() => {
157
- timeoutRequest(isDefined(timeout.$$timeoutId) ? "timeout" : "abort");
125
+ /** @type {Promise} */ (timeout).then(() => {
126
+ timeoutRequest(isDefined(timeout["$$timeoutId"]) ? "timeout" : "abort");
158
127
  });
159
128
  }
160
129
 
130
+ /**
131
+ * @param {"timeout"|"abort"} reason
132
+ */
161
133
  function timeoutRequest(reason) {
162
134
  abortedByTimeout = reason === "timeout";
163
- if (xhr) {
164
- xhr.abort();
165
- }
135
+ if (xhr) xhr.abort();
166
136
  }
167
137
 
138
+ /**
139
+ * @param {number} status - HTTP status code or -1 for network errors.
140
+ * @param {*} response - The parsed or raw response from the server.
141
+ * @param {string|null} headersString - The raw response headers as a string.
142
+ * @param {string} statusText - The status text returned by the server.
143
+ * @param {"complete"|"error"|"timeout"|"abort"} xhrStatus - Final status of the request.
144
+ */
168
145
  function completeRequest(
169
- callback,
170
146
  status,
171
147
  response,
172
148
  headersString,
173
149
  statusText,
174
150
  xhrStatus,
175
151
  ) {
176
- // cancel timeout and subsequent timeout promise resolution
177
152
  if (isDefined(timeoutId)) {
178
153
  clearTimeout(timeoutId);
179
154
  }
180
-
181
155
  callback(status, response, headersString, statusText, xhrStatus);
182
156
  }
183
157
  };
@@ -1,5 +1,4 @@
1
- import { createInjector } from "../../core/di/injector.js";
2
- import { Angular } from "../../loader.js";
1
+ import { Angular } from "../../angular.js";
3
2
  import { createHttpBackend } from "./http-backend.js";
4
3
  import sinon from "sinon";
5
4
 
@@ -5,6 +5,7 @@ const TEST_URL = "src/services/http-backend/http-backend.html";
5
5
  test("unit tests contain no errors", async ({ page }) => {
6
6
  await page.goto(TEST_URL);
7
7
  await page.content();
8
+ await page.waitForTimeout(1000);
8
9
  await expect(page.locator(".jasmine-overall-result")).toHaveText(
9
10
  /0 failures/,
10
11
  );
@@ -6,3 +6,65 @@
6
6
  * @returns void
7
7
  */
8
8
  export type UrlChangeListener = (url: string, state: History["state"]) => void;
9
+
10
+ /**
11
+ * Represents the configuration options for HTML5 mode.
12
+ */
13
+ export interface Html5Mode {
14
+ /**
15
+ * If true, will rely on `history.pushState` to change URLs where supported.
16
+ * Falls back to hash-prefixed paths in browsers that do not support `pushState`.
17
+ * @default false
18
+ */
19
+ enabled: boolean;
20
+
21
+ /**
22
+ * When html5Mode is enabled, specifies whether or not a `<base>` tag is required to be present.
23
+ * If both `enabled` and `requireBase` are true, and a `<base>` tag is not present,
24
+ * an error will be thrown when `$location` is injected.
25
+ * @default true
26
+ */
27
+ requireBase: boolean;
28
+
29
+ /**
30
+ * When html5Mode is enabled, enables or disables URL rewriting for relative links.
31
+ * If set to a string, URL rewriting will only apply to links with an attribute that matches the given string.
32
+ * For example, if set to `'internal-link'`, URL rewriting will only occur for `<a internal-link>` links.
33
+ * Attribute name normalization does not apply here.
34
+ * @default true
35
+ */
36
+ rewriteLinks: boolean | string;
37
+ }
38
+
39
+ /**
40
+ * Represents default port numbers for various protocols.
41
+ */
42
+ export interface DefaultPorts {
43
+ http: number;
44
+ https: number;
45
+ ftp: number;
46
+ }
47
+
48
+ /**
49
+ * Represents the individual components of a URL.
50
+ */
51
+ export interface UrlParts {
52
+ /**
53
+ * The URL path (e.g. `/dashboard`, `/users/123`).
54
+ */
55
+ path: string;
56
+
57
+ /**
58
+ * The parsed query string as an object.
59
+ * Mirrors AngularJS’s `$location.setSearch()` format.
60
+ */
61
+ search: Record<
62
+ string,
63
+ string | number | boolean | (string | number | boolean)[]
64
+ >;
65
+
66
+ /**
67
+ * The fragment identifier (everything after `#`, not including the `#` itself).
68
+ */
69
+ hash: string;
70
+ }