@angular-wave/angular.ts 0.0.12 → 0.0.14
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/dist/angular-ts.esm.js +1 -1
- package/dist/angular-ts.umd.js +1 -1
- package/package.json +1 -1
- package/src/exts/messages.md +30 -30
- package/src/router/adapter/directives/stateDirectives.js +14 -23
- package/src/router/adapter/directives/viewDirective.js +34 -44
- package/src/router/adapter/locationServices.js +3 -5
- package/src/router/adapter/services.js +9 -16
- package/src/router/adapter/stateFilters.js +2 -7
- package/src/router/adapter/templateFactory.js +1 -1
- package/src/router/adapter/viewScroll.js +1 -8
- package/src/router/core/common/common.js +1 -11
- package/src/router/core/hooks/coreResolvables.js +2 -2
- package/src/router/core/path/pathUtils.js +1 -2
- package/src/router/core/router.js +4 -2
- package/src/router/core/state/stateBuilder.js +2 -3
- package/src/router/core/state/stateMatcher.js +1 -2
- package/src/router/core/state/stateObject.js +7 -6
- package/src/router/core/state/stateQueueManager.js +1 -1
- package/src/router/core/transition/hookRegistry.js +3 -10
- package/src/router/core/transition/transitionService.js +2 -2
- package/src/router/router.js +43 -19
- package/test/module-test.html +18 -11
- package/test/module-test.js +0 -0
- package/test/ng/directive/if.spec.js +0 -1
- package/test/original-test.html +27 -15
- package/src/router/adapter/urlRouterProvider.js +0 -196
- package/src/router/core/vanilla/baseLocationService.js +0 -31
- package/src/router/core/vanilla/browserLocationConfig.js +0 -42
- package/src/router/core/vanilla/hashLocationService.js +0 -19
- package/src/router/core/vanilla/injector.js +0 -98
- package/src/router/core/vanilla/interface.js +0 -1
- package/src/router/core/vanilla/memoryLocationConfig.js +0 -20
- package/src/router/core/vanilla/memoryLocationService.js +0 -13
- package/src/router/core/vanilla/plugins.js +0 -35
- package/src/router/core/vanilla/pushStateLocationService.js +0 -69
- package/src/router/core/vanilla/q.js +0 -54
- package/src/router/core/vanilla/utils.js +0 -63
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extend,
|
|
3
|
-
removeFrom,
|
|
4
|
-
tail,
|
|
5
|
-
values,
|
|
6
|
-
identity,
|
|
7
|
-
mapObj,
|
|
8
|
-
} from "../common/common";
|
|
1
|
+
import { extend, removeFrom, tail, identity, mapObj } from "../common/common";
|
|
9
2
|
import { isString, isFunction } from "../common/predicates";
|
|
10
3
|
import { Glob } from "../common/glob";
|
|
11
4
|
import {
|
|
@@ -125,7 +118,7 @@ export class RegisteredHook {
|
|
|
125
118
|
this._getDefaultMatchCriteria(),
|
|
126
119
|
this.matchCriteria,
|
|
127
120
|
);
|
|
128
|
-
const paths = values(this.tranSvc._pluginapi._getPathTypes());
|
|
121
|
+
const paths = Object.values(this.tranSvc._pluginapi._getPathTypes());
|
|
129
122
|
return paths.reduce((mn, pathtype) => {
|
|
130
123
|
// STATE scope criteria matches against every node in the path.
|
|
131
124
|
// TRANSITION scope criteria matches against only the last node in the path
|
|
@@ -149,7 +142,7 @@ export class RegisteredHook {
|
|
|
149
142
|
matches(treeChanges, transition) {
|
|
150
143
|
const matches = this._getMatchingNodes(treeChanges, transition);
|
|
151
144
|
// Check if all the criteria matched the TreeChanges object
|
|
152
|
-
const allMatched = values(matches).every(identity);
|
|
145
|
+
const allMatched = Object.values(matches).every(identity);
|
|
153
146
|
return allMatched ? matches : null;
|
|
154
147
|
}
|
|
155
148
|
deregister() {
|
|
@@ -26,7 +26,7 @@ import { registerLazyLoadHook } from "../hooks/lazyLoad";
|
|
|
26
26
|
import { TransitionEventType } from "./transitionEventType";
|
|
27
27
|
import { TransitionHook } from "./transitionHook";
|
|
28
28
|
import { isDefined } from "../common/predicates";
|
|
29
|
-
import { removeFrom,
|
|
29
|
+
import { removeFrom, createProxyFunctions } from "../common/common";
|
|
30
30
|
import { val } from "../common/hof";
|
|
31
31
|
import { registerIgnoredTransitionHook } from "../hooks/ignoredTransition";
|
|
32
32
|
import { registerInvalidTransitionHook } from "../hooks/invalidTransition";
|
|
@@ -148,7 +148,7 @@ export class TransitionService {
|
|
|
148
148
|
* @internal
|
|
149
149
|
*/
|
|
150
150
|
dispose(router) {
|
|
151
|
-
values(this._registeredHooks).forEach((hooksArray) =>
|
|
151
|
+
Object.values(this._registeredHooks).forEach((hooksArray) =>
|
|
152
152
|
hooksArray.forEach((hook) => {
|
|
153
153
|
hook._deregistered = true;
|
|
154
154
|
removeFrom(hooksArray, hook);
|
package/src/router/router.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
$uiRouterProvider,
|
|
3
|
-
getUrlRouterProvider,
|
|
4
3
|
getProviderFor,
|
|
5
4
|
getStateProvider,
|
|
6
5
|
router,
|
|
@@ -9,17 +8,24 @@ import {
|
|
|
9
8
|
} from "./adapter/services";
|
|
10
9
|
import { TemplateFactory } from "./adapter/templateFactory";
|
|
11
10
|
import { trace } from "./core/common/trace";
|
|
11
|
+
import { $ViewScrollProvider } from "./adapter/viewScroll";
|
|
12
|
+
import { $IsStateFilter, $IncludedByStateFilter } from "./adapter/stateFilters";
|
|
13
|
+
import {
|
|
14
|
+
uiSrefActiveDirective,
|
|
15
|
+
uiStateDirective,
|
|
16
|
+
uiSrefDirective,
|
|
17
|
+
} from "./adapter/directives/stateDirectives";
|
|
18
|
+
import { uiView, $ViewDirectiveFill } from "./adapter/directives/viewDirective";
|
|
12
19
|
|
|
13
20
|
export function initRouter() {
|
|
14
21
|
window.angular.module("ui.router.angular1", []);
|
|
15
22
|
const mod_init = window.angular.module("ui.router.init", ["ng"]);
|
|
16
23
|
const mod_util = window.angular.module("ui.router.util", ["ui.router.init"]);
|
|
17
|
-
const mod_rtr = window.angular.module("ui.router.router", ["ui.router.util"]);
|
|
18
24
|
const mod_state = window.angular.module("ui.router.state", [
|
|
19
|
-
"ui.router.router",
|
|
20
25
|
"ui.router.util",
|
|
21
26
|
"ui.router.angular1",
|
|
22
27
|
]);
|
|
28
|
+
|
|
23
29
|
const mod_main = window.angular.module("ui.router", [
|
|
24
30
|
"ui.router.init",
|
|
25
31
|
"ui.router.state",
|
|
@@ -27,26 +33,44 @@ export function initRouter() {
|
|
|
27
33
|
]);
|
|
28
34
|
|
|
29
35
|
mod_init.provider("$uiRouter", $uiRouterProvider);
|
|
30
|
-
mod_rtr.provider("$urlRouter", ["$uiRouterProvider", getUrlRouterProvider]);
|
|
31
36
|
mod_util.provider("$urlService", getProviderFor("urlService"));
|
|
32
37
|
mod_util.provider("$urlMatcherFactory", [
|
|
33
38
|
"$uiRouterProvider",
|
|
34
|
-
()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
mod_state.provider("$stateRegistry", getProviderFor("stateRegistry"));
|
|
38
|
-
mod_state.provider("$uiRouterGlobals", getProviderFor("globals"));
|
|
39
|
-
mod_state.provider("$transitions", getProviderFor("transitionService"));
|
|
40
|
-
mod_state.provider("$state", ["$uiRouterProvider", getStateProvider]);
|
|
41
|
-
mod_state.factory("$stateParams", [
|
|
42
|
-
"$uiRouter",
|
|
43
|
-
($uiRouter) => $uiRouter.globals.params,
|
|
39
|
+
function RouterProvide() {
|
|
40
|
+
return router.urlMatcherFactory;
|
|
41
|
+
},
|
|
44
42
|
]);
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
mod_util.provider("$templateFactory", function () {
|
|
44
|
+
return new TemplateFactory();
|
|
45
|
+
});
|
|
46
|
+
mod_state
|
|
47
|
+
.provider("$stateRegistry", getProviderFor("stateRegistry"))
|
|
48
|
+
.provider("$uiRouterGlobals", getProviderFor("globals"))
|
|
49
|
+
.provider("$transitions", getProviderFor("transitionService"))
|
|
50
|
+
.provider("$state", ["$uiRouterProvider", getStateProvider])
|
|
51
|
+
.provider("$uiViewScroll", $ViewScrollProvider)
|
|
52
|
+
.factory("$stateParams", [
|
|
53
|
+
"$uiRouter",
|
|
54
|
+
function StateParamse($uiRouter) {
|
|
55
|
+
return $uiRouter.globals.params;
|
|
56
|
+
},
|
|
57
|
+
])
|
|
58
|
+
.filter("isState", $IsStateFilter)
|
|
59
|
+
.filter("includedByState", $IncludedByStateFilter)
|
|
60
|
+
.directive("uiSref", uiSrefDirective)
|
|
61
|
+
.directive("uiSrefActive", uiSrefActiveDirective)
|
|
62
|
+
.directive("uiSrefActiveEq", uiSrefActiveDirective)
|
|
63
|
+
.directive("uiState", uiStateDirective)
|
|
64
|
+
.directive("uiView", uiView)
|
|
65
|
+
.directive("uiView", $ViewDirectiveFill);
|
|
66
|
+
mod_main.factory("$view", function View() {
|
|
67
|
+
return router.viewService;
|
|
68
|
+
});
|
|
69
|
+
mod_main.service("$trace", function Trace() {
|
|
70
|
+
return trace;
|
|
71
|
+
});
|
|
47
72
|
mod_main.run(watchDigests);
|
|
48
|
-
mod_util.run(["$urlMatcherFactory", function (
|
|
49
|
-
mod_state.run(["$state", function (
|
|
50
|
-
mod_rtr.run(["$urlRouter", function ($urlRouter) {}]);
|
|
73
|
+
mod_util.run(["$urlMatcherFactory", function MatcherFac() {}]);
|
|
74
|
+
mod_state.run(["$state", function State() {}]);
|
|
51
75
|
mod_init.run(runBlock);
|
|
52
76
|
}
|
package/test/module-test.html
CHANGED
|
@@ -3,17 +3,24 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<script></script>
|
|
5
5
|
<script type="module" src="../src/index.js"></script>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
<script>
|
|
7
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
8
|
+
var myApp = window.angular.module("test", ["ui.router"]);
|
|
9
|
+
myApp.config(function ($stateProvider) {
|
|
10
|
+
var helloState = {
|
|
11
|
+
name: "hello",
|
|
12
|
+
url: "/",
|
|
13
|
+
template: "<h3>hello world!</h3>",
|
|
14
|
+
};
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
</
|
|
16
|
+
$stateProvider.state(helloState);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
</head>
|
|
21
|
+
<body ng-app="test">
|
|
22
|
+
{{ 2 + 2 }}
|
|
23
|
+
<a ui-sref="hello" ui-sref-active="active">Hello</a>
|
|
24
|
+
<ui-view></ui-view>
|
|
18
25
|
</body>
|
|
19
26
|
</html>
|
|
File without changes
|
package/test/original-test.html
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html>
|
|
3
3
|
<head>
|
|
4
|
-
<script src="../legacy/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
<script src="../legacy/angular.js"></script>
|
|
5
|
+
<script src="//unpkg.com/@uirouter/angularjs/release/angular-ui-router.min.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
var myApp = angular.module("helloworld", ["ui.router"]);
|
|
8
|
+
|
|
9
|
+
myApp.config(function ($stateProvider) {
|
|
10
|
+
var helloState = {
|
|
11
|
+
name: "hello",
|
|
12
|
+
url: "/",
|
|
13
|
+
template: "<h3>hello world!</h3>",
|
|
14
|
+
};
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
var aboutState = {
|
|
17
|
+
name: "about",
|
|
18
|
+
url: "/about",
|
|
19
|
+
template: "<h3>Its the UI-Router hello world app!</h3>",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
$stateProvider.state(helloState);
|
|
23
|
+
$stateProvider.state(aboutState);
|
|
16
24
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
</script>
|
|
26
|
+
</head>
|
|
27
|
+
<body ng-app="helloworld">
|
|
28
|
+
<a ui-sref="hello" ui-sref-active="active">Hello</a>
|
|
29
|
+
{{ 2 + 2}}
|
|
30
|
+
<ui-view></ui-view>
|
|
31
|
+
{{ 2 + 2}}
|
|
32
|
+
</body>
|
|
21
33
|
</html>
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/** @publicapi @module url */ /** */
|
|
2
|
-
|
|
3
|
-
import { BaseUrlRule } from "../core/url/urlRule";
|
|
4
|
-
import { isString, isFunction, isArray, identity } from "../../core/utils";
|
|
5
|
-
import { services } from "../core/common/coreservices";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Manages rules for client-side URL
|
|
9
|
-
*
|
|
10
|
-
* ### Deprecation warning:
|
|
11
|
-
* This class is now considered to be an internal API
|
|
12
|
-
* Use the [[UrlService]] instead.
|
|
13
|
-
* For configuring URL rules, use the [[UrlRulesApi]] which can be found as [[UrlService.rules]].
|
|
14
|
-
*
|
|
15
|
-
* This class manages the router rules for what to do when the URL changes.
|
|
16
|
-
*
|
|
17
|
-
* This provider remains for backwards compatibility.
|
|
18
|
-
*
|
|
19
|
-
* @internalapi
|
|
20
|
-
* @deprecated
|
|
21
|
-
*/
|
|
22
|
-
export class UrlRouterProvider {
|
|
23
|
-
static injectableHandler(router, handler) {
|
|
24
|
-
return (match) =>
|
|
25
|
-
services.$injector.invoke(handler, null, {
|
|
26
|
-
$match: match,
|
|
27
|
-
$stateParams: router.globals.params,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/** @hidden */
|
|
31
|
-
constructor(/** @hidden */ router) {
|
|
32
|
-
this.router = router;
|
|
33
|
-
}
|
|
34
|
-
/** @hidden */
|
|
35
|
-
$get() {
|
|
36
|
-
const urlService = this.router.urlService;
|
|
37
|
-
this.router.urlRouter.update(true);
|
|
38
|
-
if (!urlService.interceptDeferred) urlService.listen();
|
|
39
|
-
return this.router.urlRouter;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Registers a url handler function.
|
|
43
|
-
*
|
|
44
|
-
* Registers a low level url handler (a `rule`).
|
|
45
|
-
* A rule detects specific URL patterns and returns a redirect, or performs some action.
|
|
46
|
-
*
|
|
47
|
-
* If a rule returns a string, the URL is replaced with the string, and all rules are fired again.
|
|
48
|
-
*
|
|
49
|
-
* #### Example:
|
|
50
|
-
* ```js
|
|
51
|
-
* var app = angular.module('app', ['ui.router.router']);
|
|
52
|
-
*
|
|
53
|
-
* app.config(function ($urlRouterProvider) {
|
|
54
|
-
* // Here's an example of how you might allow case insensitive urls
|
|
55
|
-
* $urlRouterProvider.rule(function ($injector, $location) {
|
|
56
|
-
* var path = $location.path(),
|
|
57
|
-
* normalized = path.toLowerCase();
|
|
58
|
-
*
|
|
59
|
-
* if (path !== normalized) {
|
|
60
|
-
* return normalized;
|
|
61
|
-
* }
|
|
62
|
-
* });
|
|
63
|
-
* });
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @param ruleFn
|
|
67
|
-
* Handler function that takes `$injector` and `$location` services as arguments.
|
|
68
|
-
* You can use them to detect a url and return a different url as a string.
|
|
69
|
-
*
|
|
70
|
-
* @return [[UrlRouterProvider]] (`this`)
|
|
71
|
-
*/
|
|
72
|
-
rule(ruleFn) {
|
|
73
|
-
if (!isFunction(ruleFn)) throw new Error("'rule' must be a function");
|
|
74
|
-
const match = () => ruleFn(services.$injector, this.router.locationService);
|
|
75
|
-
const rule = new BaseUrlRule(match, identity);
|
|
76
|
-
this.router.urlService.rules.rule(rule);
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Defines the path or behavior to use when no url can be matched.
|
|
81
|
-
*
|
|
82
|
-
* #### Example:
|
|
83
|
-
* ```js
|
|
84
|
-
* var app = angular.module('app', ['ui.router.router']);
|
|
85
|
-
*
|
|
86
|
-
* app.config(function ($urlRouterProvider) {
|
|
87
|
-
* // if the path doesn't match any of the urls you configured
|
|
88
|
-
* // otherwise will take care of routing the user to the
|
|
89
|
-
* // specified url
|
|
90
|
-
* $urlRouterProvider.otherwise('/index');
|
|
91
|
-
*
|
|
92
|
-
* // Example of using function rule as param
|
|
93
|
-
* $urlRouterProvider.otherwise(function ($injector, $location) {
|
|
94
|
-
* return '/a/valid/url';
|
|
95
|
-
* });
|
|
96
|
-
* });
|
|
97
|
-
* ```
|
|
98
|
-
*
|
|
99
|
-
* @param rule
|
|
100
|
-
* The url path you want to redirect to or a function rule that returns the url path or performs a `$state.go()`.
|
|
101
|
-
* The function version is passed two params: `$injector` and `$location` services, and should return a url string.
|
|
102
|
-
*
|
|
103
|
-
* @return {object} `$urlRouterProvider` - `$urlRouterProvider` instance
|
|
104
|
-
*/
|
|
105
|
-
otherwise(rule) {
|
|
106
|
-
const urlRules = this.router.urlService.rules;
|
|
107
|
-
if (isString(rule)) {
|
|
108
|
-
urlRules.otherwise(rule);
|
|
109
|
-
} else if (isFunction(rule)) {
|
|
110
|
-
urlRules.otherwise(() =>
|
|
111
|
-
rule(services.$injector, this.router.locationService),
|
|
112
|
-
);
|
|
113
|
-
} else {
|
|
114
|
-
throw new Error("'rule' must be a string or function");
|
|
115
|
-
}
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Registers a handler for a given url matching.
|
|
120
|
-
*
|
|
121
|
-
* If the handler is a string, it is
|
|
122
|
-
* treated as a redirect, and is interpolated according to the syntax of match
|
|
123
|
-
* (i.e. like `String.replace()` for `RegExp`, or like a `UrlMatcher` pattern otherwise).
|
|
124
|
-
*
|
|
125
|
-
* If the handler is a function, it is injectable.
|
|
126
|
-
* It gets invoked if `$location` matches.
|
|
127
|
-
* You have the option of inject the match object as `$match`.
|
|
128
|
-
*
|
|
129
|
-
* The handler can return
|
|
130
|
-
*
|
|
131
|
-
* - **falsy** to indicate that the rule didn't match after all, then `$urlRouter`
|
|
132
|
-
* will continue trying to find another one that matches.
|
|
133
|
-
* - **string** which is treated as a redirect and passed to `$location.url()`
|
|
134
|
-
* - **void** or any **truthy** value tells `$urlRouter` that the url was handled.
|
|
135
|
-
*
|
|
136
|
-
* #### Example:
|
|
137
|
-
* ```js
|
|
138
|
-
* var app = angular.module('app', ['ui.router.router']);
|
|
139
|
-
*
|
|
140
|
-
* app.config(function ($urlRouterProvider) {
|
|
141
|
-
* $urlRouterProvider.when($state.url, function ($match, $stateParams) {
|
|
142
|
-
* if ($state.$current.navigable !== state ||
|
|
143
|
-
* !equalForKeys($match, $stateParams) {
|
|
144
|
-
* $state.transitionTo(state, $match, false);
|
|
145
|
-
* }
|
|
146
|
-
* });
|
|
147
|
-
* });
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
* @param what A pattern string to match, compiled as a [[UrlMatcher]].
|
|
151
|
-
* @param handler The path (or function that returns a path) that you want to redirect your user to.
|
|
152
|
-
* @param ruleCallback [optional] A callback that receives the `rule` registered with [[UrlMatcher.rule]]
|
|
153
|
-
*
|
|
154
|
-
* Note: the handler may also invoke arbitrary code, such as `$state.go()`
|
|
155
|
-
*/
|
|
156
|
-
when(what, handler) {
|
|
157
|
-
if (isArray(handler) || isFunction(handler)) {
|
|
158
|
-
handler = UrlRouterProvider.injectableHandler(this.router, handler);
|
|
159
|
-
}
|
|
160
|
-
this.router.urlService.rules.when(what, handler);
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Disables monitoring of the URL.
|
|
165
|
-
*
|
|
166
|
-
* Call this method before UI-Router has bootstrapped.
|
|
167
|
-
* It will stop UI-Router from performing the initial url sync.
|
|
168
|
-
*
|
|
169
|
-
* This can be useful to perform some asynchronous initialization before the router starts.
|
|
170
|
-
* Once the initialization is complete, call [[listen]] to tell UI-Router to start watching and synchronizing the URL.
|
|
171
|
-
*
|
|
172
|
-
* #### Example:
|
|
173
|
-
* ```js
|
|
174
|
-
* var app = angular.module('app', ['ui.router']);
|
|
175
|
-
*
|
|
176
|
-
* app.config(function ($urlRouterProvider) {
|
|
177
|
-
* // Prevent $urlRouter from automatically intercepting URL changes;
|
|
178
|
-
* $urlRouterProvider.deferIntercept();
|
|
179
|
-
* })
|
|
180
|
-
*
|
|
181
|
-
* app.run(function (MyService, $urlRouter, $http) {
|
|
182
|
-
* $http.get("/stuff").then(function(resp) {
|
|
183
|
-
* MyService.doStuff(resp.data);
|
|
184
|
-
* $urlRouter.listen();
|
|
185
|
-
* $urlRouter.sync();
|
|
186
|
-
* });
|
|
187
|
-
* });
|
|
188
|
-
* ```
|
|
189
|
-
*
|
|
190
|
-
* @param defer Indicates whether to defer location change interception.
|
|
191
|
-
* Passing no parameter is equivalent to `true`.
|
|
192
|
-
*/
|
|
193
|
-
deferIntercept(defer) {
|
|
194
|
-
this.router.urlService.deferIntercept(defer);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { deregAll, isDefined, removeFrom, root } from "../common/index";
|
|
2
|
-
import { buildUrl, getParams, parseUrl } from "./utils";
|
|
3
|
-
/** A base `LocationServices` */
|
|
4
|
-
export class BaseLocationServices {
|
|
5
|
-
constructor(router, fireAfterUpdate) {
|
|
6
|
-
this.fireAfterUpdate = fireAfterUpdate;
|
|
7
|
-
this._listeners = [];
|
|
8
|
-
this._listener = (evt) => this._listeners.forEach((cb) => cb(evt));
|
|
9
|
-
this.hash = () => parseUrl(this._get()).hash;
|
|
10
|
-
this.path = () => parseUrl(this._get()).path;
|
|
11
|
-
this.search = () => getParams(parseUrl(this._get()).search);
|
|
12
|
-
this._location = root.location;
|
|
13
|
-
this._history = root.history;
|
|
14
|
-
}
|
|
15
|
-
url(url, replace = true) {
|
|
16
|
-
if (isDefined(url) && url !== this._get()) {
|
|
17
|
-
this._set(null, null, url, replace);
|
|
18
|
-
if (this.fireAfterUpdate) {
|
|
19
|
-
this._listeners.forEach((cb) => cb({ url }));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return buildUrl(this);
|
|
23
|
-
}
|
|
24
|
-
onChange(cb) {
|
|
25
|
-
this._listeners.push(cb);
|
|
26
|
-
return () => removeFrom(this._listeners, cb);
|
|
27
|
-
}
|
|
28
|
-
dispose(router) {
|
|
29
|
-
deregAll(this._listeners);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { isDefined, isUndefined } from "../common/predicates";
|
|
2
|
-
/** A `LocationConfig` that delegates to the browser's `location` object */
|
|
3
|
-
export class BrowserLocationConfig {
|
|
4
|
-
constructor(router, _isHtml5 = false) {
|
|
5
|
-
this._isHtml5 = _isHtml5;
|
|
6
|
-
this._baseHref = undefined;
|
|
7
|
-
this._hashPrefix = "";
|
|
8
|
-
}
|
|
9
|
-
port() {
|
|
10
|
-
if (location.port) {
|
|
11
|
-
return Number(location.port);
|
|
12
|
-
}
|
|
13
|
-
return this.protocol() === "https" ? 443 : 80;
|
|
14
|
-
}
|
|
15
|
-
protocol() {
|
|
16
|
-
return location.protocol.replace(/:/g, "");
|
|
17
|
-
}
|
|
18
|
-
host() {
|
|
19
|
-
return location.hostname;
|
|
20
|
-
}
|
|
21
|
-
html5Mode() {
|
|
22
|
-
return this._isHtml5;
|
|
23
|
-
}
|
|
24
|
-
hashPrefix(newprefix) {
|
|
25
|
-
return isDefined(newprefix)
|
|
26
|
-
? (this._hashPrefix = newprefix)
|
|
27
|
-
: this._hashPrefix;
|
|
28
|
-
}
|
|
29
|
-
baseHref(href) {
|
|
30
|
-
if (isDefined(href)) this._baseHref = href;
|
|
31
|
-
if (isUndefined(this._baseHref)) this._baseHref = this.getBaseHref();
|
|
32
|
-
return this._baseHref;
|
|
33
|
-
}
|
|
34
|
-
getBaseHref() {
|
|
35
|
-
const baseTag = document.getElementsByTagName("base")[0];
|
|
36
|
-
if (baseTag && baseTag.href) {
|
|
37
|
-
return baseTag.href.replace(/^([^/:]*:)?\/\/[^/]*/, "");
|
|
38
|
-
}
|
|
39
|
-
return this._isHtml5 ? "/" : location.pathname || "/";
|
|
40
|
-
}
|
|
41
|
-
dispose() {}
|
|
42
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { root, trimHashVal } from "../common/index";
|
|
2
|
-
import { BaseLocationServices } from "./baseLocationService";
|
|
3
|
-
/** A `LocationServices` that uses the browser hash "#" to get/set the current location */
|
|
4
|
-
export class HashLocationService extends BaseLocationServices {
|
|
5
|
-
constructor(router) {
|
|
6
|
-
super(router, false);
|
|
7
|
-
root.addEventListener("hashchange", this._listener, false);
|
|
8
|
-
}
|
|
9
|
-
_get() {
|
|
10
|
-
return trimHashVal(this._location.hash);
|
|
11
|
-
}
|
|
12
|
-
_set(state, title, url, replace) {
|
|
13
|
-
this._location.hash = url;
|
|
14
|
-
}
|
|
15
|
-
dispose(router) {
|
|
16
|
-
super.dispose(router);
|
|
17
|
-
root.removeEventListener("hashchange", this._listener);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extend,
|
|
3
|
-
assertPredicate,
|
|
4
|
-
isFunction,
|
|
5
|
-
isArray,
|
|
6
|
-
isInjectable,
|
|
7
|
-
} from "../common/index";
|
|
8
|
-
// globally available injectables
|
|
9
|
-
const globals = {};
|
|
10
|
-
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
11
|
-
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
12
|
-
/**
|
|
13
|
-
* A basic angular1-like injector api
|
|
14
|
-
*
|
|
15
|
-
* This object implements four methods similar to the
|
|
16
|
-
* [angular 1 dependency injector](https://docs.angularjs.org/api/auto/service/$injector)
|
|
17
|
-
*
|
|
18
|
-
* UI-Router evolved from an angular 1 library to a framework agnostic library.
|
|
19
|
-
* However, some of the `@uirouter/core` code uses these ng1 style APIs to support ng1 style dependency injection.
|
|
20
|
-
*
|
|
21
|
-
* This object provides a naive implementation of a globally scoped dependency injection system.
|
|
22
|
-
* It supports the following DI approaches:
|
|
23
|
-
*
|
|
24
|
-
* ### Function parameter names
|
|
25
|
-
*
|
|
26
|
-
* A function's `.toString()` is called, and the parameter names are parsed.
|
|
27
|
-
* This only works when the parameter names aren't "mangled" by a minifier such as UglifyJS.
|
|
28
|
-
*
|
|
29
|
-
* ```js
|
|
30
|
-
* function injectedFunction(FooService, BarService) {
|
|
31
|
-
* // FooService and BarService are injected
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* ### Function annotation
|
|
36
|
-
*
|
|
37
|
-
* A function may be annotated with an array of dependency names as the `$inject` property.
|
|
38
|
-
*
|
|
39
|
-
* ```js
|
|
40
|
-
* injectedFunction.$inject = [ 'FooService', 'BarService' ];
|
|
41
|
-
* function injectedFunction(fs, bs) {
|
|
42
|
-
* // FooService and BarService are injected as fs and bs parameters
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* ### Array notation
|
|
47
|
-
*
|
|
48
|
-
* An array provides the names of the dependencies to inject (as strings).
|
|
49
|
-
* The function is the last element of the array.
|
|
50
|
-
*
|
|
51
|
-
* ```js
|
|
52
|
-
* [ 'FooService', 'BarService', function (fs, bs) {
|
|
53
|
-
* // FooService and BarService are injected as fs and bs parameters
|
|
54
|
-
* }]
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @type {$InjectorLike}
|
|
58
|
-
*/
|
|
59
|
-
export const $injector = {
|
|
60
|
-
/** Gets an object from DI based on a string token */
|
|
61
|
-
get: (name) => globals[name],
|
|
62
|
-
/** Returns true if an object named `name` exists in global DI */
|
|
63
|
-
has: (name) => $injector.get(name) != null,
|
|
64
|
-
/**
|
|
65
|
-
* Injects a function
|
|
66
|
-
*
|
|
67
|
-
* @param fn the function to inject
|
|
68
|
-
* @param context the function's `this` binding
|
|
69
|
-
* @param locals An object with additional DI tokens and values, such as `{ someToken: { foo: 1 } }`
|
|
70
|
-
*/
|
|
71
|
-
invoke: (fn, context, locals) => {
|
|
72
|
-
const all = extend({}, globals, locals || {});
|
|
73
|
-
const params = $injector.annotate(fn);
|
|
74
|
-
const ensureExist = assertPredicate(
|
|
75
|
-
(key) => all.hasOwnProperty(key),
|
|
76
|
-
(key) => `DI can't find injectable: '${key}'`,
|
|
77
|
-
);
|
|
78
|
-
const args = params.filter(ensureExist).map((x) => all[x]);
|
|
79
|
-
if (isFunction(fn)) return fn.apply(context, args);
|
|
80
|
-
else return fn.slice(-1)[0].apply(context, args);
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* Returns a function's dependencies
|
|
84
|
-
*
|
|
85
|
-
* Analyzes a function (or array) and returns an array of DI tokens that the function requires.
|
|
86
|
-
* @return an array of `string`s
|
|
87
|
-
*/
|
|
88
|
-
annotate: (fn) => {
|
|
89
|
-
if (!isInjectable(fn)) throw new Error(`Not an injectable function: ${fn}`);
|
|
90
|
-
if (fn && fn.$inject) return fn.$inject;
|
|
91
|
-
if (isArray(fn)) return fn.slice(0, -1);
|
|
92
|
-
const fnStr = fn.toString().replace(STRIP_COMMENTS, "");
|
|
93
|
-
const result = fnStr
|
|
94
|
-
.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
|
|
95
|
-
.match(ARGUMENT_NAMES);
|
|
96
|
-
return result || [];
|
|
97
|
-
},
|
|
98
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { isDefined } from "../common/predicates";
|
|
2
|
-
import { noop } from "../common/index";
|
|
3
|
-
/** A `LocationConfig` mock that gets/sets all config from an in-memory object */
|
|
4
|
-
export class MemoryLocationConfig {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.dispose = noop;
|
|
7
|
-
this._baseHref = "";
|
|
8
|
-
this._port = 80;
|
|
9
|
-
this._protocol = "http";
|
|
10
|
-
this._host = "localhost";
|
|
11
|
-
this._hashPrefix = "";
|
|
12
|
-
this.port = () => this._port;
|
|
13
|
-
this.protocol = () => this._protocol;
|
|
14
|
-
this.host = () => this._host;
|
|
15
|
-
this.baseHref = () => this._baseHref;
|
|
16
|
-
this.html5Mode = () => false;
|
|
17
|
-
this.hashPrefix = (newval) =>
|
|
18
|
-
isDefined(newval) ? (this._hashPrefix = newval) : this._hashPrefix;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseLocationServices } from "./baseLocationService";
|
|
2
|
-
/** A `LocationServices` that gets/sets the current location from an in-memory object */
|
|
3
|
-
export class MemoryLocationService extends BaseLocationServices {
|
|
4
|
-
constructor(router) {
|
|
5
|
-
super(router, true);
|
|
6
|
-
}
|
|
7
|
-
_get() {
|
|
8
|
-
return this._url;
|
|
9
|
-
}
|
|
10
|
-
_set(state, title, url, replace) {
|
|
11
|
-
this._url = url;
|
|
12
|
-
}
|
|
13
|
-
}
|