@angular-wave/angular.ts 0.0.30 → 0.0.31

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "license": "MIT",
4
- "version": "0.0.30",
4
+ "version": "0.0.31",
5
5
  "type": "module",
6
6
  "main": "dist/angular-ts.esm.js",
7
7
  "browser": "dist/angular-ts.umd.js",
@@ -1,7 +1,7 @@
1
1
  export const registerUpdateUrl = (
2
2
  transitionService,
3
3
  stateService,
4
- urlRouter,
4
+ urlService,
5
5
  ) => {
6
6
  /**
7
7
  * A [[TransitionHookFn]] which updates the URL after a successful transition
@@ -11,7 +11,7 @@ export const registerUpdateUrl = (
11
11
  const updateUrl = (transition) => {
12
12
  const options = transition.options();
13
13
  const $state = stateService;
14
- const $urlRouter = urlRouter;
14
+
15
15
  // Dont update the url in these situations:
16
16
  // The transition was triggered by a URL sync (options.source === 'url')
17
17
  // The user doesn't want the url to update (options.location === false)
@@ -22,13 +22,13 @@ export const registerUpdateUrl = (
22
22
  $state.$current.navigable
23
23
  ) {
24
24
  const urlOptions = { replace: options.location === "replace" };
25
- $urlRouter.push(
25
+ urlService.push(
26
26
  $state.$current.navigable.url,
27
27
  $state.globals.params,
28
28
  urlOptions,
29
29
  );
30
30
  }
31
- $urlRouter.update(true);
31
+ urlService.update(true);
32
32
  };
33
33
  transitionService.onSuccess({}, updateUrl, { priority: 9999 });
34
34
  };
@@ -22,12 +22,6 @@ export function initRouter() {
22
22
  .module("ng.router", ["ng"])
23
23
  .provider("$router", $routerProvider)
24
24
  .provider("$urlService", getProviderFor("urlService"))
25
- .provider("$urlMatcherFactory", [
26
- "$routerProvider",
27
- function RouterProvide() {
28
- return router.urlMatcherFactory;
29
- },
30
- ])
31
25
  .provider("$templateFactory", TemplateFactory)
32
26
  .provider("$stateRegistry", getProviderFor("stateRegistry"))
33
27
  .provider("$routerGlobals", getProviderFor("globals"))
@@ -259,56 +259,5 @@ let $urlServiceProvider;
259
259
  * ##### Note: This service can also be injected during the config phase as [[$urlServiceProvider]].
260
260
  */
261
261
  let $urlService;
262
- /**
263
- * The URL Router Provider
264
- *
265
- * ### Deprecation warning: This object is now considered internal. Use [[$urlServiceProvider]] instead.
266
- *
267
- * The [[UrlRouter]] singleton as a **Provider Object** (injectable during config time).
268
- *
269
- * #### Note: This object is also exposed as [[$urlRouter]] for injection during runtime.
270
- *
271
- * @deprecated
272
- */
273
- let $urlRouterProvider;
274
- /**
275
- * The Url Router
276
- *
277
- * ### Deprecation warning: This object is now considered internal. Use [[$urlService]] instead.
278
- *
279
- * The [[UrlRouter]] singleton as a **Service Object** (injectable during runtime).
280
- *
281
- * #### Note: This object is also exposed as [[$urlRouterProvider]] for injection during angular config time.
282
- *
283
- * @deprecated
284
- */
285
- let $urlRouter;
286
- /**
287
- * The URL Matcher Factory
288
- *
289
- * ### Deprecation warning: This object is now considered internal. Use [[$urlService]] instead.
290
- *
291
- * The [[UrlMatcherFactory]] singleton as a **Service Object** (injectable during runtime).
292
- *
293
- * This service is used to set url mapping options, define custom parameter types, and create [[UrlMatcher]] objects.
294
- *
295
- * #### Note: This object is also exposed as [[$urlMatcherFactoryProvider]] for injection during angular config time.
296
- *
297
- * @deprecated
298
- */
299
- let $urlMatcherFactory;
300
- /**
301
- * The URL Matcher Factory
302
- *
303
- * ### Deprecation warning: This object is now considered internal. Use [[$urlService]] instead.
304
- *
305
- * The [[UrlMatcherFactory]] singleton as a **Provider Object** (injectable during config time).
306
- *
307
- * This service is used to set url mapping options, define custom parameter types, and create [[UrlMatcher]] objects.
308
- *
309
- * #### Note: This object is also exposed as [[$urlMatcherFactory]] for injection during runtime.
310
- *
311
- * @deprecated
312
- */
313
- let $urlMatcherFactoryProvider;
262
+
314
263
  export {};
@@ -1,5 +1,3 @@
1
- import { UrlMatcherFactory } from "./url/url-matcher-factory";
2
- import { UrlRouter } from "./url/url-router";
3
1
  import { TransitionService } from "./transition/transition-service";
4
2
  import { ViewService } from "./view/view";
5
3
  import { StateRegistry } from "./state/state-registry";
@@ -70,31 +68,11 @@ export class UIRouter {
70
68
  this.stateService,
71
69
  );
72
70
 
73
- /**
74
- * Deprecated for public use. Use [[urlService]] instead.
75
- * @deprecated Use [[urlService]] instead
76
- */
77
- this.urlMatcherFactory = new UrlMatcherFactory(this.urlService.config);
78
-
79
- /**
80
- * Deprecated for public use. Use [[urlService]] instead.
81
- * @deprecated Use [[urlService]] instead
82
- */
83
- this.urlRouter = new UrlRouter(
84
- this.urlService,
85
- urlRuleFactory,
86
- $locationProvider,
87
- );
88
-
89
71
  /** Provides a registry for states, and related registration services */
90
- this.stateRegistry = new StateRegistry(
91
- this.urlMatcherFactory,
92
- this.urlService.rules,
93
- );
72
+ this.stateRegistry = new StateRegistry(this.urlService);
94
73
 
95
74
  // Manual wiring ideally we would want to do this at runtime
96
75
  this.stateService.stateRegistry = this.stateRegistry;
97
- this.stateService.urlRouter = this.urlRouter;
98
76
  this.stateService.urlService = this.urlService; // <-- NOTE: circular dependency
99
77
 
100
78
  // Lazy load state trees
@@ -109,7 +87,7 @@ export class UIRouter {
109
87
  this.transitionService._deregisterHookFns.updateUrl = registerUpdateUrl(
110
88
  this.transitionService,
111
89
  this.stateService,
112
- this.urlRouter,
90
+ this.urlService,
113
91
  );
114
92
 
115
93
  // Wire up redirectTo hook
@@ -27,27 +27,6 @@ export function $routerProvider($locationProvider) {
27
27
  router.stateService,
28
28
  );
29
29
 
30
- /**
31
- * Applys ng1-specific path parameter encoding
32
- *
33
- * The Angular 1 `$location` service is a bit weird.
34
- * It doesn't allow slashes to be encoded/decoded bi-directionally.
35
- *
36
- * See the writeup at https://github.com/angular-ui/ui-router/issues/2598
37
- *
38
- * This code patches the `path` parameter type so it encoded/decodes slashes as ~2F
39
- *
40
- */
41
- const pathType = router.urlMatcherFactory.type("path");
42
- pathType.encode = (x) =>
43
- x != null
44
- ? x.toString().replace(/(~|\/)/g, (m) => ({ "~": "~~", "/": "~2F" })[m])
45
- : x;
46
- pathType.decode = (x) =>
47
- x != null
48
- ? x.toString().replace(/(~~|~2F)/g, (m) => ({ "~~": "~", "~2F": "/" })[m])
49
- : x;
50
-
51
30
  // backwards compat: also expose router instance as $routerProvider.router
52
31
  router["router"] = router;
53
32
  router["$get"] = $get;
@@ -99,7 +78,6 @@ export function runBlock($injector, $q, $router) {
99
78
  }
100
79
 
101
80
  // $state service and $stateProvider
102
- // $urlRouter service and $urlRouterProvider
103
81
  export function getStateProvider() {
104
82
  return Object.assign(router.stateProvider, {
105
83
  $get: () => router.stateService,
@@ -29,7 +29,7 @@ function dataBuilder(state) {
29
29
  }
30
30
  return state.data;
31
31
  }
32
- const getUrlBuilder = ($urlMatcherFactoryProvider, root) =>
32
+ const getUrlBuilder = ($urlService, root) =>
33
33
  function urlBuilder(stateObject) {
34
34
  let stateDec = stateObject.self;
35
35
  // For future states, i.e., states whose name ends with `.**`,
@@ -49,9 +49,9 @@ const getUrlBuilder = ($urlMatcherFactoryProvider, root) =>
49
49
  const parsed = parseUrl(stateDec.url);
50
50
  const url = !parsed
51
51
  ? stateDec.url
52
- : $urlMatcherFactoryProvider.compile(parsed.val, { state: stateDec });
52
+ : $urlService.compile(parsed.val, { state: stateDec });
53
53
  if (!url) return null;
54
- if (!$urlMatcherFactoryProvider.isMatcher(url))
54
+ if (!$urlService.isMatcher(url))
55
55
  throw new Error(`Invalid url '${url}' in state '${stateObject}'`);
56
56
  return parsed && parsed.root
57
57
  ? url
@@ -238,7 +238,7 @@ export function resolvablesBuilder(state) {
238
238
  * using the [[builder]] method.
239
239
  */
240
240
  export class StateBuilder {
241
- constructor(matcher, urlMatcherFactory) {
241
+ constructor(matcher, urlService) {
242
242
  this.matcher = matcher;
243
243
  this.$injector = undefined;
244
244
  const self = this;
@@ -254,10 +254,11 @@ export class StateBuilder {
254
254
  parent: [parentBuilder],
255
255
  data: [dataBuilder],
256
256
  // Build a URLMatcher if necessary, either via a relative or absolute URL
257
- url: [getUrlBuilder(urlMatcherFactory, root)],
257
+ url: [getUrlBuilder(urlService, root)],
258
258
  // Keep track of the closest ancestor state that has a URL (i.e. is navigable)
259
259
  navigable: [getNavigableBuilder(isRoot)],
260
- params: [getParamsBuilder(urlMatcherFactory.paramFactory)],
260
+ // TODO
261
+ params: [getParamsBuilder(urlService.paramFactory)],
261
262
  // Each framework-specific ui-router implementation should define its own `views` builder
262
263
  // e.g., src/ng1/statebuilders/views.ts
263
264
  views: [],
@@ -12,13 +12,14 @@ import { ng1ViewsBuilder } from "./views";
12
12
  * This API is found at `$stateRegistry` ([[UIRouter.stateRegistry]])
13
13
  */
14
14
  export class StateRegistry {
15
- constructor(urlMatcherFactory, urlServiceRules) {
15
+ constructor(urlService) {
16
16
  this.states = {};
17
- this.urlServiceRules = urlServiceRules;
17
+ this.urlService = urlService;
18
+ this.urlServiceRules = urlService.rules;
18
19
  this.$injector = undefined;
19
20
  this.listeners = [];
20
21
  this.matcher = new StateMatcher(this.states);
21
- this.builder = new StateBuilder(this.matcher, urlMatcherFactory);
22
+ this.builder = new StateBuilder(this.matcher, urlService);
22
23
  // Apply ng1 specific StateBuilder code for `views`, `resolve`, and `onExit/Retain/Enter` properties
23
24
  // TODO we can probably move this inside buildr
24
25
  this.builder.builder("views", ng1ViewsBuilder);
@@ -28,7 +29,7 @@ export class StateRegistry {
28
29
 
29
30
  this.stateQueue = new StateQueueManager(
30
31
  this,
31
- urlServiceRules,
32
+ this.urlServiceRules,
32
33
  this.states,
33
34
  this.builder,
34
35
  this.listeners,
@@ -52,10 +52,9 @@ export class StateService {
52
52
  return this.globals.$current;
53
53
  }
54
54
 
55
- // Needs access to urlRouter, stateRegistry
55
+ // Needs access to urlService, stateRegistry
56
56
  constructor(globals, transitionService) {
57
57
  this.stateRegistry = undefined;
58
- this.urlRouter = undefined;
59
58
  this.urlService = undefined;
60
59
  this.globals = globals;
61
60
  this.transitionService = transitionService;
@@ -344,7 +343,7 @@ export class StateService {
344
343
  if (error instanceof Rejection) {
345
344
  const isLatest = this.globals.lastStartedTransitionId <= trans.$id;
346
345
  if (error.type === RejectType.IGNORED) {
347
- isLatest && EventBus.publish("urlRouter.update");
346
+ isLatest && this.urlService.update();
348
347
  // Consider ignored `Transition.run()` as a successful `transitionTo`
349
348
  return services.$q.when(this.globals.current);
350
349
  }
@@ -360,7 +359,7 @@ export class StateService {
360
359
  return redirect.run().catch(rejectedTransitionHandler(redirect));
361
360
  }
362
361
  if (error.type === RejectType.ABORTED) {
363
- isLatest && EventBus.publish("urlRouter.update");
362
+ isLatest && this.urlService.update();
364
363
  return services.$q.reject(error);
365
364
  }
366
365
  }
@@ -519,7 +518,7 @@ export class StateService {
519
518
  if (!nav || nav.url === undefined || nav.url === null) {
520
519
  return null;
521
520
  }
522
- return this.urlRouter.href(nav.url, params, {
521
+ return this.urlService.href(nav.url, params, {
523
522
  absolute: options.absolute,
524
523
  });
525
524
  }
@@ -23,7 +23,32 @@ export class UrlConfig {
23
23
  this._isStrictMode = true;
24
24
  /** @type {boolean} */
25
25
  this._defaultSquashPolicy = false;
26
+ /**
27
+ * Applys ng1-specific path parameter encoding
28
+ *
29
+ * The Angular 1 `$location` service is a bit weird.
30
+ * It doesn't allow slashes to be encoded/decoded bi-directionally.
31
+ *
32
+ * See the writeup at https://github.com/angular-ui/ui-router/issues/2598
33
+ *
34
+ * This code patches the `path` parameter type so it encoded/decodes slashes as ~2F
35
+ *
36
+ */
37
+ const pathType = this.type("path");
38
+ pathType.encode = (x) =>
39
+ x != null
40
+ ? x.toString().replace(/(~|\/)/g, (m) => ({ "~": "~~", "/": "~2F" })[m])
41
+ : x;
42
+ pathType.decode = (x) =>
43
+ x != null
44
+ ? x
45
+ .toString()
46
+ .replace(/(~~|~2F)/g, (m) => ({ "~~": "~", "~2F": "/" })[m])
47
+ : x;
48
+ this.paramTypes.enqueue = false;
49
+ this.paramTypes._flushTypeQueue();
26
50
  }
51
+
27
52
  /**
28
53
  * Defines whether URL matching should be case sensitive (the default behavior), or not.
29
54
  *
@@ -1,9 +1,18 @@
1
- import { isDefined, isObject, isString } from "../../shared/utils";
1
+ import {
2
+ forEach,
3
+ isFunction,
4
+ isDefined,
5
+ isObject,
6
+ isString,
7
+ } from "../../shared/utils";
2
8
  import { is, pattern } from "../../shared/hof";
3
9
  import { UrlRules } from "./url-rules";
4
10
  import { UrlConfig } from "./url-config";
5
11
  import { TargetState } from "../state/target-state";
6
12
  import { removeFrom } from "../../shared/common";
13
+ import { stripLastPathElement } from "../../shared/strings";
14
+ import { UrlMatcher } from "./url-matcher";
15
+ import { ParamFactory } from "../params/param-factory";
7
16
 
8
17
  /**
9
18
  * API for URL management
@@ -14,8 +23,9 @@ export class UrlService {
14
23
  */
15
24
  constructor($locationProvider, urlRuleFactory, stateService) {
16
25
  this.stateService = stateService;
17
-
18
26
  this.$locationProvider = $locationProvider;
27
+ this.$location = undefined;
28
+ this.$browser = undefined;
19
29
 
20
30
  /** @type {boolean} */
21
31
  this.interceptDeferred = false;
@@ -34,6 +44,9 @@ export class UrlService {
34
44
  */
35
45
  this.config = new UrlConfig();
36
46
 
47
+ /** Creates a new [[Param]] for a given location (DefType) */
48
+ this.paramFactory = new ParamFactory(this.config);
49
+
37
50
  /**
38
51
  * Gets the path part of the current url
39
52
  *
@@ -312,4 +325,121 @@ export class UrlService {
312
325
  this._urlListeners.forEach((fn) => fn(evt)),
313
326
  );
314
327
  }
328
+
329
+ update(read) {
330
+ if (read) {
331
+ this.location = this.url();
332
+ return;
333
+ }
334
+ if (this.url() === this.location) return;
335
+ this.url(this.location, true);
336
+ }
337
+
338
+ /**
339
+ * Internal API.
340
+ *
341
+ * Pushes a new location to the browser history.
342
+ *
343
+ * @internal
344
+ * @param urlMatcher
345
+ * @param params
346
+ * @param options
347
+ */
348
+ push(urlMatcher, params, options) {
349
+ const replace = options && !!options.replace;
350
+ this.url(urlMatcher.format(params || {}), replace);
351
+ }
352
+
353
+ /**
354
+ * Builds and returns a URL with interpolated parameters
355
+ *
356
+ * #### Example:
357
+ * ```js
358
+ * matcher = $umf.compile("/about/:person");
359
+ * params = { person: "bob" };
360
+ * $bob = $urlService.href(matcher, params);
361
+ * // $bob == "/about/bob";
362
+ * ```
363
+ *
364
+ * @param urlMatcher The [[UrlMatcher]] object which is used as the template of the URL to generate.
365
+ * @param params An object of parameter values to fill the matcher's required parameters.
366
+ * @param options Options object. The options are:
367
+ *
368
+ * - **`absolute`** - {boolean=false}, If true will generate an absolute url, e.g. "http://www.example.com/fullurl".
369
+ *
370
+ * @returns Returns the fully compiled URL, or `null` if `params` fail validation against `urlMatcher`
371
+ */
372
+ href(urlMatcher, params, options) {
373
+ let url = urlMatcher.format(params);
374
+ if (url == null) return null;
375
+ options = options || { absolute: false };
376
+ const isHtml5 = this.html5Mode();
377
+ if (!isHtml5 && url !== null) {
378
+ url = "#" + this.$locationProvider.hashPrefix() + url;
379
+ }
380
+ url = appendBasePath(url, isHtml5, options.absolute, this.baseHref());
381
+ if (!options.absolute || !url) {
382
+ return url;
383
+ }
384
+ const slash = !isHtml5 && url ? "/" : "";
385
+ const cfgPort = this.$location.port();
386
+ const port = cfgPort === 80 || cfgPort === 443 ? "" : ":" + cfgPort;
387
+ return [
388
+ this.$location.protocol(),
389
+ "://",
390
+ this.$location.host(),
391
+ port,
392
+ slash,
393
+ url,
394
+ ].join("");
395
+ }
396
+
397
+ /**
398
+ * Creates a [[UrlMatcher]] for the specified pattern.
399
+ *
400
+ * @param pattern The URL pattern.
401
+ * @param config The config object hash.
402
+ * @returns The UrlMatcher.
403
+ */
404
+ compile(pattern, config) {
405
+ const urlConfig = this.config;
406
+ // backward-compatible support for config.params -> config.state.params
407
+ const params = config && !config.state && config.params;
408
+ config = params ? Object.assign({ state: { params } }, config) : config;
409
+ const globalConfig = {
410
+ strict: urlConfig._isStrictMode,
411
+ caseInsensitive: urlConfig._isCaseInsensitive,
412
+ };
413
+ return new UrlMatcher(
414
+ pattern,
415
+ urlConfig.paramTypes,
416
+ this.paramFactory,
417
+ Object.assign(globalConfig, config),
418
+ );
419
+ }
420
+
421
+ /**
422
+ * Returns true if the specified object is a [[UrlMatcher]], or false otherwise.
423
+ *
424
+ * @param object The object to perform the type check against.
425
+ * @returns `true` if the object matches the `UrlMatcher` interface, by
426
+ * implementing all the same methods.
427
+ */
428
+ isMatcher(object) {
429
+ // TODO: typeof?
430
+ if (!isObject(object)) return false;
431
+ let result = true;
432
+ forEach(UrlMatcher.prototype, (val, name) => {
433
+ if (isFunction(val))
434
+ result = result && isDefined(object[name]) && isFunction(object[name]);
435
+ });
436
+ return result;
437
+ }
438
+ }
439
+
440
+ function appendBasePath(url, isHtml5, absolute, baseHref) {
441
+ if (baseHref === "/") return url;
442
+ if (isHtml5) return stripLastPathElement(baseHref) + url;
443
+ if (absolute) return baseHref.slice(1) + url;
444
+ return url;
315
445
  }
@@ -86,7 +86,7 @@ export class ViewService {
86
86
  if (relativeMatch.exec(ngViewContextAnchor)) {
87
87
  const anchorState = ngViewContextAnchor
88
88
  .split(".")
89
- .reduce((anchor, x) => anchor.parent, context);
89
+ .reduce((anchor) => anchor.parent, context);
90
90
  ngViewContextAnchor = anchorState.name;
91
91
  } else if (ngViewContextAnchor === ".") {
92
92
  ngViewContextAnchor = context.name;
@@ -495,6 +495,6 @@ function _arraysEq(a1, a2) {
495
495
  }
496
496
  // issue #2676
497
497
  export const silenceUncaughtInPromise = (promise) =>
498
- promise.catch((e) => 0) && promise;
498
+ promise.catch(() => 0) && promise;
499
499
  export const silentRejection = (error) =>
500
500
  silenceUncaughtInPromise(services.$q.reject(error));
@@ -13,7 +13,7 @@ describe("router services", () => {
13
13
  module.config(
14
14
  (
15
15
  _$routerProvider_,
16
- $urlMatcherFactoryProvider,
16
+ $urlServiceProvider,
17
17
  $stateRegistryProvider,
18
18
  $routerGlobalsProvider,
19
19
  $transitionsProvider,
@@ -23,7 +23,7 @@ describe("router services", () => {
23
23
  expect($routerProvider["router"]).toBe($routerProvider);
24
24
  providers = {
25
25
  $routerProvider,
26
- $urlMatcherFactoryProvider,
26
+ $urlServiceProvider,
27
27
  $stateRegistryProvider,
28
28
  $routerGlobalsProvider,
29
29
  $transitionsProvider,
@@ -38,26 +38,17 @@ describe("router services", () => {
38
38
  });
39
39
 
40
40
  it("Should expose ui-router providers from the UIRouter instance", () => {
41
- expect(providers.$urlMatcherFactoryProvider).toBe(
42
- $routerProvider.urlMatcherFactory,
43
- );
44
- expect(providers.$urlRouterProvider).toBe(
45
- $routerProvider.urlRouterProvider,
46
- );
47
- expect(providers.$stateRegistryProvider).toBe(
48
- $routerProvider.stateRegistry,
49
- );
50
- expect(providers.$routerGlobalsProvider).toBe($routerProvider.globals);
51
- expect(providers.$transitionsProvider).toBe(
52
- $routerProvider.transitionService,
53
- );
54
- expect(providers.$stateProvider).toBe($routerProvider.stateProvider);
41
+ expect(providers.$routerProvider).toBeDefined();
42
+ expect(providers.$urlServiceProvider).toBeDefined();
43
+ expect(providers.$stateRegistryProvider).toBeDefined();
44
+ expect(providers.$stateRegistryProvider).toBeDefined();
45
+ expect(providers.$transitionsProvider).toBeDefined();
46
+ expect(providers.$stateProvider).toBeDefined();
55
47
  });
56
48
 
57
49
  it("Should expose ui-router services from the UIRouter instance", () => {
58
50
  let $router = $injector.get("$router");
59
51
  expect($router).toBe($routerProvider);
60
- expect($injector.get("$urlMatcherFactory")).toBe($router.urlMatcherFactory);
61
52
  expect($injector.get("$urlService")).toBe($router.urlService);
62
53
  expect($injector.get("$stateRegistry")).toBe($router.stateRegistry);
63
54
  expect($injector.get("$routerGlobals")).toBe($router.globals);