@angular-wave/angular.ts 0.0.28 → 0.0.29

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 (47) hide show
  1. package/dist/angular-ts.esm.js +1 -1
  2. package/dist/angular-ts.umd.js +1 -1
  3. package/index.html +6 -5
  4. package/package.json +1 -1
  5. package/src/router/common/trace.js +6 -6
  6. package/src/router/directives/state-directives.js +74 -74
  7. package/src/router/directives/view-directive.js +21 -21
  8. package/src/router/index.js +12 -12
  9. package/src/router/injectables.js +3 -3
  10. package/src/router/router.js +7 -6
  11. package/src/router/services.js +4 -8
  12. package/src/router/state/state-builder.js +1 -0
  13. package/src/router/state/state-registry.js +55 -2
  14. package/src/router/state/state-service.js +16 -25
  15. package/src/router/state/views.js +4 -4
  16. package/src/router/state-filters.js +0 -2
  17. package/src/router/state-provider.js +0 -2
  18. package/src/router/template-factory.js +4 -4
  19. package/src/router/transition/transition-service.js +2 -3
  20. package/src/router/url/url-router.js +4 -0
  21. package/src/router/view/view.js +65 -65
  22. package/src/services/browser.js +1 -5
  23. package/test/core/pubsub.spec.js +73 -0
  24. package/test/module-test.html +5 -5
  25. package/test/original-test.html +3 -3
  26. package/test/router/services.spec.js +1 -1
  27. package/test/router/state-directives.spec.js +72 -80
  28. package/test/router/state-filter.spec.js +6 -4
  29. package/test/router/state.spec.js +15 -13
  30. package/test/router/template-factory.spec.js +4 -4
  31. package/test/router/url-matcher-factory.spec.js +2 -2
  32. package/test/router/view-directive.spec.js +165 -163
  33. package/test/router/view-hook.spec.js +2 -2
  34. package/test/router/view-scroll.spec.js +14 -14
  35. package/test/router/view.spec.js +2 -2
  36. package/types/router/core/state/interface.d.ts +6 -6
  37. package/types/router/core/state/stateRegistry.d.ts +1 -0
  38. package/types/router/core/state/stateService.d.ts +4 -4
  39. package/types/router/core/transition/interface.d.ts +1 -1
  40. package/types/router/core/view/interface.d.ts +2 -2
  41. package/types/router/core/view/view.d.ts +16 -16
  42. package/types/router/directives/viewDirective.d.ts +3 -3
  43. package/types/router/interface.d.ts +4 -4
  44. package/types/router/stateProvider.d.ts +3 -3
  45. package/types/router/statebuilders/views.d.ts +1 -1
  46. package/types/router/templateFactory.d.ts +2 -2
  47. package/types/router/viewScroll.d.ts +1 -1
@@ -11,15 +11,15 @@ import { trace } from "./common/trace";
11
11
  import { $ViewScrollProvider } from "./view-scroll";
12
12
  import { $IsStateFilter, $IncludedByStateFilter } from "./state-filters";
13
13
  import {
14
- uiSrefActiveDirective,
15
- uiStateDirective,
16
- uiSrefDirective,
14
+ ngSrefActiveDirective,
15
+ ngStateDirective,
16
+ ngSrefDirective,
17
17
  } from "./directives/state-directives";
18
- import { uiView, $ViewDirectiveFill } from "./directives/view-directive";
18
+ import { ngView, $ViewDirectiveFill } from "./directives/view-directive";
19
19
 
20
20
  export function initRouter() {
21
21
  window.angular
22
- .module("ui.router", ["ng"])
22
+ .module("ng.router", ["ng"])
23
23
  .provider("$router", $routerProvider)
24
24
  .provider("$urlService", getProviderFor("urlService"))
25
25
  .provider("$urlMatcherFactory", [
@@ -33,7 +33,7 @@ export function initRouter() {
33
33
  .provider("$routerGlobals", getProviderFor("globals"))
34
34
  .provider("$transitions", getProviderFor("transitionService"))
35
35
  .provider("$state", ["$routerProvider", getStateProvider])
36
- .provider("$uiViewScroll", $ViewScrollProvider)
36
+ .provider("$ngViewScroll", $ViewScrollProvider)
37
37
  .factory("$stateParams", [
38
38
  "$router",
39
39
  function ($router) {
@@ -46,12 +46,12 @@ export function initRouter() {
46
46
  .value("$trace", trace)
47
47
  .filter("isState", $IsStateFilter)
48
48
  .filter("includedByState", $IncludedByStateFilter)
49
- .directive("uiSref", uiSrefDirective)
50
- .directive("uiSrefActive", uiSrefActiveDirective)
51
- .directive("uiSrefActiveEq", uiSrefActiveDirective)
52
- .directive("uiState", uiStateDirective)
53
- .directive("uiView", uiView)
54
- .directive("uiView", $ViewDirectiveFill)
49
+ .directive("ngSref", ngSrefDirective)
50
+ .directive("ngSrefActive", ngSrefActiveDirective)
51
+ .directive("ngSrefActiveEq", ngSrefActiveDirective)
52
+ .directive("ngState", ngStateDirective)
53
+ .directive("ngView", ngView)
54
+ .directive("ngView", $ViewDirectiveFill)
55
55
 
56
56
  .run(watchDigests)
57
57
  .run(runBlock);
@@ -195,7 +195,7 @@ let $stateRegistryProvider;
195
195
  * This angular service exposes the [[UIViewScrollProvider]] singleton and is
196
196
  * used to disable UI-Router's scroll behavior.
197
197
  */
198
- let $uiViewScrollProvider;
198
+ let $ngViewScrollProvider;
199
199
  /**
200
200
  * The View Scroll function
201
201
  *
@@ -207,9 +207,9 @@ let $uiViewScrollProvider;
207
207
  * If you prefer to rely on `$anchorScroll` to scroll the view to the anchor,
208
208
  * this can be enabled by calling [[UIViewScrollProvider.useAnchorScroll]].
209
209
  *
210
- * Note: this function is used by the [[directives.uiView]] when the `autoscroll` expression evaluates to true.
210
+ * Note: this function is used by the [[directives.ngView]] when the `autoscroll` expression evaluates to true.
211
211
  */
212
- let $uiViewScroll;
212
+ let $ngViewScroll;
213
213
  /**
214
214
  * The StateProvider
215
215
  *
@@ -47,17 +47,13 @@ export class UIRouter {
47
47
 
48
48
  /** @type {TransitionService} A service that exposes global Transition Hooks */
49
49
  this.transitionService = new TransitionService(
50
- this,
51
50
  this.globals,
52
51
  this.viewService,
53
52
  );
54
53
 
55
54
  /** @type {StateService} Provides services related to states */
56
- this.stateService = new StateService(
57
- this, // access to StateRegistry and UrlRouter
58
- this.globals,
59
- this.transitionService,
60
- );
55
+ this.stateService = new StateService(this.globals, this.transitionService);
56
+
61
57
  /** Provides services related to the URL */
62
58
  let urlRuleFactory = new UrlRuleFactory(
63
59
  this.urlMatcherFactory,
@@ -96,6 +92,11 @@ export class UIRouter {
96
92
  this.urlService.rules,
97
93
  );
98
94
 
95
+ // Manual wiring ideally we would want to do this at runtime
96
+ this.stateService.stateRegistry = this.stateRegistry;
97
+ this.stateService.urlRouter = this.urlRouter;
98
+ this.stateService.urlService = this.urlService; // <-- NOTE: circular dependency
99
+
99
100
  // Lazy load state trees
100
101
  this.transitionService._deregisterHookFns.lazyLoad = registerLazyLoadHook(
101
102
  this.transitionService,
@@ -13,7 +13,7 @@ import { applyPairs, unnestR } from "../shared/common";
13
13
  import { isString } from "../shared/utils";
14
14
  import { trace } from "./common/trace";
15
15
  import { UIRouter } from "./router";
16
- import { ng1ViewsBuilder, getNg1ViewConfigFactory } from "./state/views";
16
+ import { getNg1ViewConfigFactory } from "./state/views";
17
17
 
18
18
  import { StateProvider } from "./state-provider";
19
19
  import { ResolveContext } from "./resolve/resolve-context";
@@ -29,11 +29,6 @@ export function $routerProvider($locationProvider) {
29
29
  router.stateRegistry,
30
30
  router.stateService,
31
31
  );
32
- // Apply ng1 specific StateBuilder code for `views`, `resolve`, and `onExit/Retain/Enter` properties
33
- router.stateRegistry.decorator("views", ng1ViewsBuilder);
34
- router.stateRegistry.decorator("onExit", getStateHookBuilder("onExit"));
35
- router.stateRegistry.decorator("onRetain", getStateHookBuilder("onRetain"));
36
- router.stateRegistry.decorator("onEnter", getStateHookBuilder("onEnter"));
37
32
  router.viewService._pluginapi._viewConfigFactory(
38
33
  "ng1",
39
34
  getNg1ViewConfigFactory(),
@@ -65,8 +60,9 @@ export function $routerProvider($locationProvider) {
65
60
  // backwards compat: also expose router instance as $routerProvider.router
66
61
  router["router"] = router;
67
62
  router["$get"] = $get;
68
- $get.$inject = ["$location", "$browser", "$rootScope"];
69
- function $get($location, $browser, $rootScope) {
63
+ $get.$inject = ["$location", "$browser", "$rootScope", "$injector"];
64
+ function $get($location, $browser, $rootScope, $injector) {
65
+ router.stateRegistry.init($injector);
70
66
  router.urlService._runtimeServices($rootScope, $location, $browser);
71
67
  return router;
72
68
  }
@@ -240,6 +240,7 @@ export function resolvablesBuilder(state) {
240
240
  export class StateBuilder {
241
241
  constructor(matcher, urlMatcherFactory) {
242
242
  this.matcher = matcher;
243
+ this.$injector = undefined;
243
244
  const self = this;
244
245
  const root = () => matcher.find("");
245
246
  const isRoot = (state) => state.name === "";
@@ -3,19 +3,29 @@ import { StateBuilder } from "./state-builder";
3
3
  import { StateQueueManager } from "./state-queue-manager";
4
4
  import { removeFrom } from "../../shared/common";
5
5
  import { propEq } from "../../shared/hof";
6
+ import { ResolveContext } from "../resolve/resolve-context";
7
+ import { getLocals } from "../services";
8
+ import { ng1ViewsBuilder } from "./views";
6
9
  /**
7
10
  * A registry for all of the application's [[StateDeclaration]]s
8
11
  *
9
- * This API is found at `router.stateRegistry` ([[UIRouter.stateRegistry]])
12
+ * This API is found at `$stateRegistry` ([[UIRouter.stateRegistry]])
10
13
  */
11
14
  export class StateRegistry {
12
15
  constructor(urlMatcherFactory, urlServiceRules) {
13
16
  this.states = {};
14
17
  this.urlServiceRules = urlServiceRules;
15
-
18
+ this.$injector = undefined;
16
19
  this.listeners = [];
17
20
  this.matcher = new StateMatcher(this.states);
18
21
  this.builder = new StateBuilder(this.matcher, urlMatcherFactory);
22
+ // Apply ng1 specific StateBuilder code for `views`, `resolve`, and `onExit/Retain/Enter` properties
23
+ // TODO we can probably move this inside buildr
24
+ this.builder.builder("views", ng1ViewsBuilder);
25
+ this.builder.builder("onExit", this.getStateHookBuilder("onExit"));
26
+ this.builder.builder("onRetain", this.getStateHookBuilder("onRetain"));
27
+ this.builder.builder("onEnter", this.getStateHookBuilder("onEnter"));
28
+
19
29
  this.stateQueue = new StateQueueManager(
20
30
  this,
21
31
  urlServiceRules,
@@ -26,6 +36,41 @@ export class StateRegistry {
26
36
  this._registerRoot();
27
37
  }
28
38
 
39
+ /**
40
+ * @param {angular.$InjectorLike} $injector
41
+ */
42
+ init($injector) {
43
+ this.$injector = $injector;
44
+ this.builder.$injector = $injector;
45
+ }
46
+
47
+ /**
48
+ * This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`,
49
+ * `onRetain` callback hooks on a [[Ng1StateDeclaration]].
50
+ *
51
+ * When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder
52
+ * ensures that those hooks are injectable for @uirouter/angularjs (ng1).
53
+ *
54
+ * @internalapi
55
+ */
56
+ getStateHookBuilder(hookName) {
57
+ let that = this;
58
+ return function stateHookBuilder(stateObject) {
59
+ const hook = stateObject[hookName];
60
+ const pathname = hookName === "onExit" ? "from" : "to";
61
+ function decoratedNg1Hook(trans, state) {
62
+ const resolveContext = new ResolveContext(trans.treeChanges(pathname));
63
+ const subContext = resolveContext.subContext(state.$$state());
64
+ const locals = Object.assign(getLocals(subContext), {
65
+ $state$: state,
66
+ $transition$: trans,
67
+ });
68
+ return that.$injector.invoke(hook, this, locals);
69
+ }
70
+ return hook ? decoratedNg1Hook : undefined;
71
+ };
72
+ }
73
+
29
74
  _registerRoot() {
30
75
  const rootStateDef = {
31
76
  name: "",
@@ -169,4 +214,12 @@ export class StateRegistry {
169
214
  decorator(property, builderFunction) {
170
215
  return this.builder.builder(property, builderFunction);
171
216
  }
217
+
218
+ $get = [
219
+ "$injector",
220
+ function ($injector) {
221
+ this.init($injector);
222
+ return this;
223
+ },
224
+ ];
172
225
  }
@@ -53,8 +53,10 @@ export class StateService {
53
53
  }
54
54
 
55
55
  // Needs access to urlRouter, stateRegistry
56
- constructor(router, globals, transitionService) {
57
- this.router = router;
56
+ constructor(globals, transitionService) {
57
+ this.stateRegistry = undefined;
58
+ this.urlRouter = undefined;
59
+ this.urlService = undefined;
58
60
  this.globals = globals;
59
61
  this.transitionService = transitionService;
60
62
  this.invalidCallbacks = [];
@@ -96,10 +98,7 @@ export class StateService {
96
98
  * @internal
97
99
  */
98
100
  _handleInvalidTargetState(fromPath, toState) {
99
- const fromState = PathUtils.makeTargetState(
100
- this.router.stateRegistry,
101
- fromPath,
102
- );
101
+ const fromState = PathUtils.makeTargetState(this.stateRegistry, fromPath);
103
102
  const globals = this.globals;
104
103
  const latestThing = () => globals.transitionHistory.peekTail();
105
104
  const latest = latestThing();
@@ -278,7 +277,7 @@ export class StateService {
278
277
  // If we're reloading, find the state object to reload from
279
278
  if (isObject(options.reload) && !options.reload.name)
280
279
  throw new Error("Invalid reload state object");
281
- const reg = this.router.stateRegistry;
280
+ const reg = this.stateRegistry;
282
281
  options.reloadState =
283
282
  options.reload === true
284
283
  ? reg.root()
@@ -287,18 +286,13 @@ export class StateService {
287
286
  throw new Error(
288
287
  `No such reload state '${isString(options.reload) ? options.reload : options.reload.name}'`,
289
288
  );
290
- return new TargetState(
291
- this.router.stateRegistry,
292
- identifier,
293
- params,
294
- options,
295
- );
289
+ return new TargetState(this.stateRegistry, identifier, params, options);
296
290
  }
297
291
 
298
292
  getCurrentPath() {
299
293
  const globals = this.globals;
300
294
  const latestSuccess = globals.successfulTransitions.peekTail();
301
- const rootPath = () => [new PathNode(this.router.stateRegistry.root())];
295
+ const rootPath = () => [new PathNode(this.stateRegistry.root())];
302
296
  return latestSuccess ? latestSuccess.treeChanges().to : rootPath();
303
297
  }
304
298
  /**
@@ -350,7 +344,7 @@ export class StateService {
350
344
  if (error instanceof Rejection) {
351
345
  const isLatest = this.globals.lastStartedTransitionId <= trans.$id;
352
346
  if (error.type === RejectType.IGNORED) {
353
- isLatest && this.router.urlRouter.update();
347
+ isLatest && EventBus.publish("urlRouter.update");
354
348
  // Consider ignored `Transition.run()` as a successful `transitionTo`
355
349
  return services.$q.when(this.globals.current);
356
350
  }
@@ -366,7 +360,7 @@ export class StateService {
366
360
  return redirect.run().catch(rejectedTransitionHandler(redirect));
367
361
  }
368
362
  if (error.type === RejectType.ABORTED) {
369
- isLatest && this.router.urlRouter.update();
363
+ isLatest && EventBus.publish("urlRouter.update");
370
364
  return services.$q.reject(error);
371
365
  }
372
366
  }
@@ -415,7 +409,7 @@ export class StateService {
415
409
  */
416
410
  is(stateOrName, params, options) {
417
411
  options = defaults(options, { relative: this.$current });
418
- const state = this.router.stateRegistry.matcher.find(
412
+ const state = this.stateRegistry.matcher.find(
419
413
  stateOrName,
420
414
  options.relative,
421
415
  );
@@ -474,7 +468,7 @@ export class StateService {
474
468
  if (!glob.matches(this.$current.name)) return false;
475
469
  stateOrName = this.$current.name;
476
470
  }
477
- const state = this.router.stateRegistry.matcher.find(
471
+ const state = this.stateRegistry.matcher.find(
478
472
  stateOrName,
479
473
  options.relative,
480
474
  ),
@@ -514,7 +508,7 @@ export class StateService {
514
508
  };
515
509
  options = defaults(options, defaultHrefOpts);
516
510
  params = params || {};
517
- const state = this.router.stateRegistry.matcher.find(
511
+ const state = this.stateRegistry.matcher.find(
518
512
  stateOrName,
519
513
  options.relative,
520
514
  );
@@ -525,7 +519,7 @@ export class StateService {
525
519
  if (!nav || nav.url === undefined || nav.url === null) {
526
520
  return null;
527
521
  }
528
- return this.router.urlRouter.href(nav.url, params, {
522
+ return this.urlRouter.href(nav.url, params, {
529
523
  absolute: options.absolute,
530
524
  });
531
525
  }
@@ -557,7 +551,7 @@ export class StateService {
557
551
  return (this._defaultErrorHandler = handler || this._defaultErrorHandler);
558
552
  }
559
553
  get(stateOrName, base) {
560
- const reg = this.router.stateRegistry;
554
+ const reg = this.stateRegistry;
561
555
  if (arguments.length === 0) return reg.get();
562
556
  return reg.get(stateOrName, base || this.$current);
563
557
  }
@@ -578,10 +572,7 @@ export class StateService {
578
572
  if (!state || !state.lazyLoad)
579
573
  throw new Error("Can not lazy load " + stateOrName);
580
574
  const currentPath = this.getCurrentPath();
581
- const target = PathUtils.makeTargetState(
582
- this.router.stateRegistry,
583
- currentPath,
584
- );
575
+ const target = PathUtils.makeTargetState(this.stateRegistry, currentPath);
585
576
  transition =
586
577
  transition || this.transitionService.create(currentPath, target);
587
578
  return lazyLoadState(transition, state);
@@ -81,8 +81,8 @@ export function ng1ViewsBuilder(state) {
81
81
  config.$context,
82
82
  config.$name,
83
83
  );
84
- config.$uiViewName = normalized.uiViewName;
85
- config.$uiViewContextAnchor = normalized.uiViewContextAnchor;
84
+ config.$ngViewName = normalized.ngViewName;
85
+ config.$ngViewContextAnchor = normalized.ngViewContextAnchor;
86
86
  views[name] = config;
87
87
  });
88
88
  return views;
@@ -101,10 +101,10 @@ export class Ng1ViewConfig {
101
101
 
102
102
  /** @type {Number} */ this.$id = id++;
103
103
  this.loaded = false;
104
- this.getTemplate = (uiView, context) =>
104
+ this.getTemplate = (ngView, context) =>
105
105
  this.component
106
106
  ? this.factory.makeComponentTemplate(
107
- uiView,
107
+ ngView,
108
108
  context,
109
109
  this.component,
110
110
  this.viewDecl.bindings,
@@ -1,5 +1,3 @@
1
- /** @publicapi @module ng1 */ /** */
2
-
3
1
  /**
4
2
  * `isState` Filter: truthy if the current state is the parameter
5
3
  *
@@ -1,5 +1,3 @@
1
- /** @publicapi @module ng1 */ /** */
2
-
3
1
  import { val } from "../shared/hof";
4
2
  import { createProxyFunctions } from "../shared/common";
5
3
  import { minErr } from "../shared/utils";
@@ -172,13 +172,13 @@ export class TemplateFactory {
172
172
  * It analyses the component's bindings, then constructs a template that instantiates the component.
173
173
  * The template wires input and output bindings to resolves or from the parent component.
174
174
  *
175
- * @param {angular.IAugmentedJQuery} uiView {object} The parent ui-view (for binding outputs to callbacks)
175
+ * @param {angular.IAugmentedJQuery} ngView {object} The parent ui-view (for binding outputs to callbacks)
176
176
  * @param {angular.ResolveContext} context The ResolveContext (for binding outputs to callbacks returned from resolves)
177
177
  * @param {string} component {string} Component's name in camel case.
178
178
  * @param {any} [bindings] An object defining the component's bindings: {foo: '<'}
179
179
  * @return {string} The template as a string: "<component-name input1='::$resolve.foo'></component-name>".
180
180
  */
181
- makeComponentTemplate(uiView, context, component, bindings) {
181
+ makeComponentTemplate(ngView, context, component, bindings) {
182
182
  bindings = bindings || {};
183
183
  // Bind once prefix
184
184
  const prefix = "::"; //angular.version.minor >= 3 ? "::" : "";
@@ -194,8 +194,8 @@ export class TemplateFactory {
194
194
  // If the ui-view has an attribute which matches a binding on the routed component
195
195
  // then pass that attribute through to the routed component template.
196
196
  // Prefer ui-view wired mappings to resolve data, unless the resolve was explicitly bound using `bindings:`
197
- if (uiView.attr(attrName) && !bindings[name])
198
- return `${attrName}='${uiView.attr(attrName)}'`;
197
+ if (ngView.attr(attrName) && !bindings[name])
198
+ return `${attrName}='${ngView.attr(attrName)}'`;
199
199
  const resolveName = bindings[name] || name;
200
200
  // Pre-evaluate the expression for "@" bindings by enclosing in {{ }}
201
201
  // some-attr="{{ ::$resolve.someResolveName }}"
@@ -57,9 +57,9 @@ export let defaultTransOpts = {
57
57
  */
58
58
  export class TransitionService {
59
59
  /**
60
- * @param {import('../router').UIRouter} router
60
+ * @param {import('../globals').UIRouterGlobals} globals
61
61
  */
62
- constructor(router, globals, viewService) {
62
+ constructor(globals, viewService) {
63
63
  this._transitionCount = 0;
64
64
  /** The transition hook types, such as `onEnter`, `onStart`, etc */
65
65
  this._eventTypes = [];
@@ -67,7 +67,6 @@ export class TransitionService {
67
67
  this._registeredHooks = {};
68
68
  /** The paths on a criteria object */
69
69
  this._criteriaPaths = {};
70
- this.router = router;
71
70
  this.globals = globals;
72
71
  this.$view = viewService;
73
72
  this._deregisterHookFns = {};
@@ -1,3 +1,4 @@
1
+ import { EventBus } from "../../core/pubsub";
1
2
  import { stripLastPathElement } from "../../shared/strings";
2
3
 
3
4
  function appendBasePath(url, isHtml5, absolute, baseHref) {
@@ -22,6 +23,9 @@ export class UrlRouter {
22
23
  this.urlService = urlService;
23
24
  this.urlRuleFactory = urlRuleFactory;
24
25
  this.$locationProvider = $locationProvider;
26
+ EventBus.subscribe("$urlRouter:update", () => {
27
+ this.update();
28
+ });
25
29
  }
26
30
 
27
31
  update(read) {