@angular-wave/angular.ts 0.0.27 → 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.
- package/README.md +1 -2
- package/dist/angular-ts.esm.js +1 -1
- package/dist/angular-ts.umd.js +1 -1
- package/e2e/unit.spec.ts +2 -1
- package/index.html +6 -6
- package/package.json +1 -1
- package/src/core/pubsub.js +329 -0
- package/src/router/common/trace.js +6 -6
- package/src/router/directives/state-directives.js +74 -74
- package/src/router/directives/view-directive.js +21 -21
- package/src/router/hooks/core-resolvables.js +12 -11
- package/src/router/hooks/ignored-transition.js +1 -1
- package/src/router/hooks/lazy-load.js +40 -41
- package/src/router/hooks/redirect-to.js +32 -29
- package/src/router/hooks/update-globals.js +1 -1
- package/src/router/hooks/url.js +33 -24
- package/src/router/hooks/views.js +21 -20
- package/src/router/index.js +12 -12
- package/src/router/injectables.js +3 -3
- package/src/router/params/param-factory.js +17 -0
- package/src/router/router.js +75 -10
- package/src/router/services.js +4 -8
- package/src/router/state/state-builder.js +1 -0
- package/src/router/state/state-queue-manager.js +5 -4
- package/src/router/state/state-registry.js +63 -7
- package/src/router/state/state-service.js +47 -51
- package/src/router/state/views.js +4 -4
- package/src/router/state-filters.js +0 -2
- package/src/router/state-provider.js +0 -2
- package/src/router/template-factory.js +4 -4
- package/src/router/transition/hook-builder.js +2 -2
- package/src/router/transition/transition-hook.js +2 -1
- package/src/router/transition/transition-service.js +11 -18
- package/src/router/transition/transition.js +28 -25
- package/src/router/url/url-config.js +1 -49
- package/src/router/url/url-matcher-factory.js +10 -51
- package/src/router/url/url-router.js +31 -17
- package/src/router/url/url-rule.js +9 -13
- package/src/router/url/url-rules.js +3 -3
- package/src/router/url/url-service.js +22 -18
- package/src/router/view/view.js +67 -67
- package/src/services/browser.js +1 -5
- package/src/shared/hof.js +1 -1
- package/test/angular.spec.js +1 -0
- package/test/aria/aria.spec.js +2 -1
- package/test/core/pubsub.spec.js +387 -0
- package/test/directive/bind.spec.js +2 -1
- package/test/directive/boolean.spec.js +4 -2
- package/test/directive/change.spec.js +1 -1
- package/test/directive/class.spec.js +1 -0
- package/test/directive/click.spec.js +2 -1
- package/test/directive/cloak.spec.js +1 -2
- package/test/directive/{constoller.spec.js → controller.spec.js} +1 -0
- package/test/directive/element-style.spec.js +1 -0
- package/test/directive/event.spec.js +1 -1
- package/test/directive/href.spec.js +2 -1
- package/test/directive/init.spec.js +1 -0
- package/test/directive/input.spec.js +200 -285
- package/test/directive/list.spec.js +2 -1
- package/test/directive/model.spec.js +1 -0
- package/test/directive/non-bindable.spec.js +2 -1
- package/test/directive/script.spec.js +1 -0
- package/test/directive/scrset.spec.js +2 -1
- package/test/directive/show-hide.spec.js +1 -0
- package/test/directive/src.spec.js +2 -1
- package/test/directive/style.spec.js +1 -0
- package/test/directive/switch.spec.js +2 -1
- package/test/directive/validators.spec.js +1 -1
- package/test/module-test.html +5 -5
- package/test/original-test.html +3 -3
- package/test/router/services.spec.js +1 -1
- package/test/router/state-directives.spec.js +72 -80
- package/test/router/state-filter.spec.js +6 -4
- package/test/router/state.spec.js +15 -13
- package/test/router/template-factory.spec.js +4 -4
- package/test/router/url-matcher-factory.spec.js +2 -2
- package/test/router/view-directive.spec.js +165 -163
- package/test/router/view-hook.spec.js +4 -4
- package/test/router/view-scroll.spec.js +15 -15
- package/test/router/view.spec.js +3 -3
- package/types/router/core/common/coreservices.d.ts +2 -3
- package/types/router/core/globals.d.ts +1 -4
- package/types/router/core/interface.d.ts +2 -8
- package/types/router/core/params/paramTypes.d.ts +0 -1
- package/types/router/core/router.d.ts +2 -3
- package/types/router/core/state/interface.d.ts +6 -6
- package/types/router/core/state/stateQueueManager.d.ts +1 -3
- package/types/router/core/state/stateRegistry.d.ts +1 -2
- package/types/router/core/state/stateService.d.ts +5 -6
- package/types/router/core/transition/interface.d.ts +4 -4
- package/types/router/core/transition/transitionService.d.ts +1 -2
- package/types/router/core/url/urlConfig.d.ts +1 -2
- package/types/router/core/url/urlRules.d.ts +1 -2
- package/types/router/core/url/urlService.d.ts +1 -2
- package/types/router/core/view/interface.d.ts +2 -2
- package/types/router/core/view/view.d.ts +16 -16
- package/types/router/directives/viewDirective.d.ts +3 -3
- package/types/router/interface.d.ts +4 -4
- package/types/router/locationServices.d.ts +0 -1
- package/types/router/stateProvider.d.ts +3 -3
- package/types/router/statebuilders/views.d.ts +1 -1
- package/types/router/templateFactory.d.ts +2 -2
- package/types/router/viewScroll.d.ts +1 -1
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import { isString, isFunction } from "../../shared/utils";
|
|
2
2
|
import { services } from "../common/coreservices";
|
|
3
3
|
import { TargetState } from "../state/target-state";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
4
|
+
|
|
5
|
+
export const registerRedirectToHook = (transitionService, stateService) => {
|
|
6
|
+
/**
|
|
7
|
+
* A [[TransitionHookFn]] that redirects to a different state or params
|
|
8
|
+
*
|
|
9
|
+
* Registered using `transitionService.onStart({ to: (state) => !!state.redirectTo }, redirectHook);`
|
|
10
|
+
*
|
|
11
|
+
* See [[StateDeclaration.redirectTo]]
|
|
12
|
+
*/
|
|
13
|
+
const redirectToHook = (trans) => {
|
|
14
|
+
const redirect = trans.to().redirectTo;
|
|
15
|
+
if (!redirect) return;
|
|
16
|
+
const $state = stateService;
|
|
17
|
+
function handleResult(result) {
|
|
18
|
+
if (!result) return;
|
|
19
|
+
if (result instanceof TargetState) return result;
|
|
20
|
+
if (isString(result))
|
|
21
|
+
return $state.target(result, trans.params(), trans.options());
|
|
22
|
+
if (result["state"] || result["params"])
|
|
23
|
+
return $state.target(
|
|
24
|
+
result["state"] || trans.to(),
|
|
25
|
+
result["params"] || trans.params(),
|
|
26
|
+
trans.options(),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
if (isFunction(redirect)) {
|
|
30
|
+
return services.$q.when(redirect(trans)).then(handleResult);
|
|
31
|
+
}
|
|
32
|
+
return handleResult(redirect);
|
|
33
|
+
};
|
|
34
|
+
|
|
33
35
|
transitionService.onStart(
|
|
34
36
|
{ to: (state) => !!state.redirectTo },
|
|
35
37
|
redirectToHook,
|
|
36
38
|
);
|
|
39
|
+
};
|
|
@@ -12,7 +12,7 @@ import { copy } from "../../shared/common";
|
|
|
12
12
|
* [[StateService.transition]], [[StateService.current]], [[StateService.params]]
|
|
13
13
|
*/
|
|
14
14
|
const updateGlobalState = (trans) => {
|
|
15
|
-
const globals = trans.
|
|
15
|
+
const globals = trans.globals;
|
|
16
16
|
const transitionSuccessful = () => {
|
|
17
17
|
globals.successfulTransitions.enqueue(trans);
|
|
18
18
|
globals.$current = trans.$to();
|
package/src/router/hooks/url.js
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
options.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
export const registerUpdateUrl = (
|
|
2
|
+
transitionService,
|
|
3
|
+
stateService,
|
|
4
|
+
urlRouter,
|
|
5
|
+
) => {
|
|
6
|
+
/**
|
|
7
|
+
* A [[TransitionHookFn]] which updates the URL after a successful transition
|
|
8
|
+
*
|
|
9
|
+
* Registered using `transitionService.onSuccess({}, updateUrl);`
|
|
10
|
+
*/
|
|
11
|
+
const updateUrl = (transition) => {
|
|
12
|
+
const options = transition.options();
|
|
13
|
+
const $state = stateService;
|
|
14
|
+
const $urlRouter = urlRouter;
|
|
15
|
+
// Dont update the url in these situations:
|
|
16
|
+
// The transition was triggered by a URL sync (options.source === 'url')
|
|
17
|
+
// The user doesn't want the url to update (options.location === false)
|
|
18
|
+
// The destination state, and all parents have no navigable url
|
|
19
|
+
if (
|
|
20
|
+
options.source !== "url" &&
|
|
21
|
+
options.location &&
|
|
22
|
+
$state.$current.navigable
|
|
23
|
+
) {
|
|
24
|
+
const urlOptions = { replace: options.location === "replace" };
|
|
25
|
+
$urlRouter.push(
|
|
26
|
+
$state.$current.navigable.url,
|
|
27
|
+
$state.globals.params,
|
|
28
|
+
urlOptions,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
$urlRouter.update(true);
|
|
32
|
+
};
|
|
25
33
|
transitionService.onSuccess({}, updateUrl, { priority: 9999 });
|
|
34
|
+
};
|
|
@@ -17,24 +17,25 @@ const loadEnteringViews = (transition) => {
|
|
|
17
17
|
};
|
|
18
18
|
export const registerLoadEnteringViews = (transitionService) =>
|
|
19
19
|
transitionService.onFinish({}, loadEnteringViews);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
20
|
+
|
|
21
|
+
export const registerActivateViews = (transitionService, viewService) => {
|
|
22
|
+
/**
|
|
23
|
+
* A [[TransitionHookFn]] which activates the new views when a transition is successful.
|
|
24
|
+
*
|
|
25
|
+
* Registered using `transitionService.onSuccess({}, activateViews);`
|
|
26
|
+
*
|
|
27
|
+
* After a transition is complete, this hook deactivates the old views from the previous state,
|
|
28
|
+
* and activates the new views from the destination state.
|
|
29
|
+
*
|
|
30
|
+
* See [[ViewService]]
|
|
31
|
+
*/
|
|
32
|
+
const activateViews = (transition) => {
|
|
33
|
+
const enteringViews = transition.views("entering");
|
|
34
|
+
const exitingViews = transition.views("exiting");
|
|
35
|
+
if (!enteringViews.length && !exitingViews.length) return;
|
|
36
|
+
exitingViews.forEach((vc) => viewService.deactivateViewConfig(vc));
|
|
37
|
+
enteringViews.forEach((vc) => viewService.activateViewConfig(vc));
|
|
38
|
+
viewService.sync();
|
|
39
|
+
};
|
|
40
40
|
transitionService.onSuccess({}, activateViews);
|
|
41
|
+
};
|
package/src/router/index.js
CHANGED
|
@@ -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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
ngSrefActiveDirective,
|
|
15
|
+
ngStateDirective,
|
|
16
|
+
ngSrefDirective,
|
|
17
17
|
} from "./directives/state-directives";
|
|
18
|
-
import {
|
|
18
|
+
import { ngView, $ViewDirectiveFill } from "./directives/view-directive";
|
|
19
19
|
|
|
20
20
|
export function initRouter() {
|
|
21
21
|
window.angular
|
|
22
|
-
.module("
|
|
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("$
|
|
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("
|
|
50
|
-
.directive("
|
|
51
|
-
.directive("
|
|
52
|
-
.directive("
|
|
53
|
-
.directive("
|
|
54
|
-
.directive("
|
|
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 $
|
|
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.
|
|
210
|
+
* Note: this function is used by the [[directives.ngView]] when the `autoscroll` expression evaluates to true.
|
|
211
211
|
*/
|
|
212
|
-
let $
|
|
212
|
+
let $ngViewScroll;
|
|
213
213
|
/**
|
|
214
214
|
* The StateProvider
|
|
215
215
|
*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DefType, Param } from "../params/param";
|
|
2
|
+
|
|
3
|
+
export class ParamFactory {
|
|
4
|
+
constructor(urlServiceConfig) {
|
|
5
|
+
this.urlServiceConfig = urlServiceConfig;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
fromConfig(id, type, state) {
|
|
9
|
+
return new Param(id, type, DefType.CONFIG, this.urlServiceConfig, state);
|
|
10
|
+
}
|
|
11
|
+
fromPath(id, type, state) {
|
|
12
|
+
return new Param(id, type, DefType.PATH, this.urlServiceConfig, state);
|
|
13
|
+
}
|
|
14
|
+
fromSearch(id, type, state) {
|
|
15
|
+
return new Param(id, type, DefType.SEARCH, this.urlServiceConfig, state);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/router/router.js
CHANGED
|
@@ -7,6 +7,11 @@ import { StateService } from "./state/state-service";
|
|
|
7
7
|
import { UIRouterGlobals } from "./globals";
|
|
8
8
|
import { UrlService } from "./url/url-service";
|
|
9
9
|
import { trace } from "./common/trace";
|
|
10
|
+
import { UrlRuleFactory } from "./url/url-rule";
|
|
11
|
+
import { registerLazyLoadHook } from "./hooks/lazy-load";
|
|
12
|
+
import { registerUpdateUrl } from "./hooks/url";
|
|
13
|
+
import { registerActivateViews } from "./hooks/views";
|
|
14
|
+
import { registerRedirectToHook } from "./hooks/redirect-to";
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
* Router id tracker
|
|
@@ -27,33 +32,93 @@ export class UIRouter {
|
|
|
27
32
|
* @param {angular.ILocationProvider} $locationProvider
|
|
28
33
|
*/
|
|
29
34
|
constructor($locationProvider) {
|
|
30
|
-
/** @type {number} */
|
|
35
|
+
/** @type {number} */
|
|
36
|
+
this.$id = routerId++;
|
|
31
37
|
|
|
32
38
|
/** Enable/disable tracing to the javascript console */
|
|
33
39
|
this.trace = trace;
|
|
34
40
|
this.$locationProvider = $locationProvider;
|
|
41
|
+
|
|
35
42
|
/** Provides services related to ui-view synchronization */
|
|
36
|
-
this.viewService = new ViewService(
|
|
43
|
+
this.viewService = new ViewService(routerId);
|
|
44
|
+
|
|
37
45
|
/** @type {UIRouterGlobals} An object that contains global router state, such as the current state and params */
|
|
38
46
|
this.globals = new UIRouterGlobals();
|
|
47
|
+
|
|
39
48
|
/** @type {TransitionService} A service that exposes global Transition Hooks */
|
|
40
|
-
this.transitionService = new TransitionService(
|
|
49
|
+
this.transitionService = new TransitionService(
|
|
50
|
+
this.globals,
|
|
51
|
+
this.viewService,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
/** @type {StateService} Provides services related to states */
|
|
55
|
+
this.stateService = new StateService(this.globals, this.transitionService);
|
|
56
|
+
|
|
57
|
+
/** Provides services related to the URL */
|
|
58
|
+
let urlRuleFactory = new UrlRuleFactory(
|
|
59
|
+
this.urlMatcherFactory,
|
|
60
|
+
this.stateService,
|
|
61
|
+
this.globals,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @type {angular.UrlService}
|
|
66
|
+
*/
|
|
67
|
+
this.urlService = new UrlService(
|
|
68
|
+
$locationProvider,
|
|
69
|
+
urlRuleFactory,
|
|
70
|
+
this.stateService,
|
|
71
|
+
);
|
|
72
|
+
|
|
41
73
|
/**
|
|
42
74
|
* Deprecated for public use. Use [[urlService]] instead.
|
|
43
75
|
* @deprecated Use [[urlService]] instead
|
|
44
76
|
*/
|
|
45
|
-
this.urlMatcherFactory = new UrlMatcherFactory(this);
|
|
77
|
+
this.urlMatcherFactory = new UrlMatcherFactory(this.urlService.config);
|
|
78
|
+
|
|
46
79
|
/**
|
|
47
80
|
* Deprecated for public use. Use [[urlService]] instead.
|
|
48
81
|
* @deprecated Use [[urlService]] instead
|
|
49
82
|
*/
|
|
50
|
-
this.urlRouter = new UrlRouter(
|
|
51
|
-
|
|
52
|
-
|
|
83
|
+
this.urlRouter = new UrlRouter(
|
|
84
|
+
this.urlService,
|
|
85
|
+
urlRuleFactory,
|
|
86
|
+
$locationProvider,
|
|
87
|
+
);
|
|
88
|
+
|
|
53
89
|
/** Provides a registry for states, and related registration services */
|
|
54
|
-
this.stateRegistry = new StateRegistry(
|
|
55
|
-
|
|
56
|
-
|
|
90
|
+
this.stateRegistry = new StateRegistry(
|
|
91
|
+
this.urlMatcherFactory,
|
|
92
|
+
this.urlService.rules,
|
|
93
|
+
);
|
|
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
|
+
|
|
100
|
+
// Lazy load state trees
|
|
101
|
+
this.transitionService._deregisterHookFns.lazyLoad = registerLazyLoadHook(
|
|
102
|
+
this.transitionService,
|
|
103
|
+
this.stateService,
|
|
104
|
+
this.urlService,
|
|
105
|
+
this.stateRegistry,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// After globals.current is updated at priority: 10000
|
|
109
|
+
this.transitionService._deregisterHookFns.updateUrl = registerUpdateUrl(
|
|
110
|
+
this.transitionService,
|
|
111
|
+
this.stateService,
|
|
112
|
+
this.urlRouter,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// Wire up redirectTo hook
|
|
116
|
+
this.transitionService._deregisterHookFns.redirectTo =
|
|
117
|
+
registerRedirectToHook(this.transitionService, this.stateService);
|
|
118
|
+
|
|
119
|
+
this.transitionService._deregisterHookFns.activateViews =
|
|
120
|
+
registerActivateViews(this.transitionService, this.viewService);
|
|
121
|
+
|
|
57
122
|
/** @internal plugin instances are registered here */
|
|
58
123
|
this._plugins = {};
|
|
59
124
|
this.viewService._pluginapi._rootViewContext(this.stateRegistry.root());
|
package/src/router/services.js
CHANGED
|
@@ -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 {
|
|
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 === "";
|
|
@@ -4,8 +4,9 @@ import { isString } from "../../shared/utils";
|
|
|
4
4
|
import { StateObject } from "./state-object";
|
|
5
5
|
|
|
6
6
|
export class StateQueueManager {
|
|
7
|
-
constructor(
|
|
8
|
-
this.
|
|
7
|
+
constructor(stateRegistry, urlServiceRules, states, builder, listeners) {
|
|
8
|
+
this.stateRegistry = stateRegistry;
|
|
9
|
+
this.urlServiceRules = urlServiceRules;
|
|
9
10
|
this.states = states;
|
|
10
11
|
this.builder = builder;
|
|
11
12
|
this.listeners = listeners;
|
|
@@ -55,7 +56,7 @@ export class StateQueueManager {
|
|
|
55
56
|
const existingFutureState = getState(name + ".**");
|
|
56
57
|
if (existingFutureState) {
|
|
57
58
|
// Remove future state of the same name
|
|
58
|
-
this.
|
|
59
|
+
this.stateRegistry.deregister(existingFutureState);
|
|
59
60
|
}
|
|
60
61
|
states[name] = state;
|
|
61
62
|
this.attachRoute(state);
|
|
@@ -81,7 +82,7 @@ export class StateQueueManager {
|
|
|
81
82
|
}
|
|
82
83
|
attachRoute(state) {
|
|
83
84
|
if (state.abstract || !state.url) return;
|
|
84
|
-
const rulesApi = this.
|
|
85
|
+
const rulesApi = this.urlServiceRules;
|
|
85
86
|
rulesApi.rule(rulesApi.urlRuleFactory.create(state));
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -3,21 +3,32 @@ 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
|
|
12
|
+
* This API is found at `$stateRegistry` ([[UIRouter.stateRegistry]])
|
|
10
13
|
*/
|
|
11
14
|
export class StateRegistry {
|
|
12
|
-
constructor(
|
|
13
|
-
this.router = router;
|
|
15
|
+
constructor(urlMatcherFactory, urlServiceRules) {
|
|
14
16
|
this.states = {};
|
|
15
|
-
|
|
17
|
+
this.urlServiceRules = urlServiceRules;
|
|
18
|
+
this.$injector = undefined;
|
|
16
19
|
this.listeners = [];
|
|
17
20
|
this.matcher = new StateMatcher(this.states);
|
|
18
|
-
this.builder = new StateBuilder(this.matcher,
|
|
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,
|
|
31
|
+
urlServiceRules,
|
|
21
32
|
this.states,
|
|
22
33
|
this.builder,
|
|
23
34
|
this.listeners,
|
|
@@ -25,6 +36,41 @@ export class StateRegistry {
|
|
|
25
36
|
this._registerRoot();
|
|
26
37
|
}
|
|
27
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
|
+
|
|
28
74
|
_registerRoot() {
|
|
29
75
|
const rootStateDef = {
|
|
30
76
|
name: "",
|
|
@@ -114,7 +160,7 @@ export class StateRegistry {
|
|
|
114
160
|
const children = getChildren([state]);
|
|
115
161
|
const deregistered = [state].concat(children).reverse();
|
|
116
162
|
deregistered.forEach((_state) => {
|
|
117
|
-
const rulesApi = this.
|
|
163
|
+
const rulesApi = this.urlServiceRules;
|
|
118
164
|
// Remove URL rule
|
|
119
165
|
rulesApi
|
|
120
166
|
.rules()
|
|
@@ -147,12 +193,14 @@ export class StateRegistry {
|
|
|
147
193
|
);
|
|
148
194
|
return deregisteredStates;
|
|
149
195
|
}
|
|
196
|
+
|
|
150
197
|
get(stateOrName, base) {
|
|
151
198
|
if (arguments.length === 0)
|
|
152
199
|
return Object.keys(this.states).map((name) => this.states[name].self);
|
|
153
200
|
const found = this.matcher.find(stateOrName, base);
|
|
154
201
|
return (found && found.self) || null;
|
|
155
202
|
}
|
|
203
|
+
|
|
156
204
|
/**
|
|
157
205
|
* Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`).
|
|
158
206
|
* More than one BuilderFunction can be registered for a given property.
|
|
@@ -166,4 +214,12 @@ export class StateRegistry {
|
|
|
166
214
|
decorator(property, builderFunction) {
|
|
167
215
|
return this.builder.builder(property, builderFunction);
|
|
168
216
|
}
|
|
217
|
+
|
|
218
|
+
$get = [
|
|
219
|
+
"$injector",
|
|
220
|
+
function ($injector) {
|
|
221
|
+
this.init($injector);
|
|
222
|
+
return this;
|
|
223
|
+
},
|
|
224
|
+
];
|
|
169
225
|
}
|