@angular-wave/angular.ts 0.0.28 → 0.0.30
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/index.html +2 -2
- package/package.json +1 -1
- package/src/core/controller.js +3 -0
- package/src/directive/controller.js +0 -56
- package/src/directive/controller.md +46 -0
- package/src/router/common/trace.js +7 -7
- package/src/router/directives/state-directives.js +75 -75
- package/src/router/directives/view-directive.js +21 -21
- package/src/router/hooks/update-globals.js +1 -1
- package/src/router/index.js +12 -12
- package/src/router/injectables.js +11 -11
- package/src/router/resolve/resolve-context.js +1 -1
- package/src/router/router.js +8 -77
- package/src/router/services.js +5 -43
- package/src/router/state/state-builder.js +1 -0
- package/src/router/state/state-object.js +1 -1
- package/src/router/state/state-registry.js +56 -3
- package/src/router/state/state-service.js +16 -25
- package/src/router/state/target-state.js +1 -1
- package/src/router/state/views.js +5 -5
- 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/transition-service.js +2 -3
- package/src/router/url/url-config.js +0 -2
- package/src/router/url/url-matcher-factory.js +0 -1
- package/src/router/url/url-matcher.js +0 -8
- package/src/router/url/url-router.js +4 -0
- package/src/router/url/url-service.js +6 -6
- package/src/router/view/view.js +67 -65
- package/src/services/browser.js +1 -5
- package/src/shared/common.js +1 -1
- package/test/core/pubsub.spec.js +73 -0
- 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 +2 -2
- package/test/router/view-scroll.spec.js +14 -14
- package/test/router/view.spec.js +2 -2
- package/types/router/core/common/coreservices.d.ts +2 -2
- package/types/router/core/common/trace.d.ts +7 -7
- package/types/router/core/globals.d.ts +2 -1
- package/types/router/core/interface.d.ts +3 -10
- package/types/router/core/params/interface.d.ts +3 -3
- package/types/router/core/resolve/resolveContext.d.ts +4 -4
- package/types/router/core/router.d.ts +5 -51
- package/types/router/core/state/interface.d.ts +12 -12
- package/types/router/core/state/stateObject.d.ts +1 -1
- package/types/router/core/state/stateQueueManager.d.ts +2 -2
- package/types/router/core/state/stateRegistry.d.ts +5 -4
- package/types/router/core/state/stateService.d.ts +13 -13
- package/types/router/core/state/targetState.d.ts +1 -1
- package/types/router/core/transition/interface.d.ts +2 -2
- package/types/router/core/transition/transition.d.ts +12 -12
- package/types/router/core/transition/transitionService.d.ts +5 -5
- package/types/router/core/url/interface.d.ts +3 -3
- package/types/router/core/url/urlConfig.d.ts +3 -3
- package/types/router/core/url/urlMatcherFactory.d.ts +3 -3
- package/types/router/core/url/urlRouter.d.ts +2 -2
- package/types/router/core/url/urlRule.d.ts +6 -6
- package/types/router/core/url/urlRules.d.ts +6 -6
- package/types/router/core/url/urlService.d.ts +8 -8
- package/types/router/core/view/interface.d.ts +3 -3
- package/types/router/core/view/view.d.ts +26 -26
- package/types/router/directives/viewDirective.d.ts +6 -6
- package/types/router/interface.d.ts +8 -8
- package/types/router/locationServices.d.ts +3 -3
- package/types/router/services.d.ts +1 -1
- package/types/router/stateProvider.d.ts +5 -5
- package/types/router/statebuilders/views.d.ts +1 -1
- package/types/router/templateFactory.d.ts +2 -2
- package/types/router/viewScroll.d.ts +2 -2
|
@@ -19,7 +19,7 @@ import { jqLite } from "../../jqLite";
|
|
|
19
19
|
* The ui-view can be targeted in a View using the name ([[Ng1StateDeclaration.views]]).
|
|
20
20
|
*
|
|
21
21
|
* - `autoscroll`: an expression. When it evaluates to true, the `ui-view` will be scrolled into view when it is activated.
|
|
22
|
-
* Uses [[$
|
|
22
|
+
* Uses [[$ngViewScroll]] to do the scrolling.
|
|
23
23
|
*
|
|
24
24
|
* - `onload`: Expression to evaluate whenever the view updates.
|
|
25
25
|
*
|
|
@@ -133,13 +133,13 @@ import { jqLite } from "../../jqLite";
|
|
|
133
133
|
* });
|
|
134
134
|
* ```
|
|
135
135
|
*/
|
|
136
|
-
export let
|
|
136
|
+
export let ngView = [
|
|
137
137
|
"$view",
|
|
138
138
|
"$animate",
|
|
139
|
-
"$
|
|
139
|
+
"$ngViewScroll",
|
|
140
140
|
"$interpolate",
|
|
141
141
|
"$q",
|
|
142
|
-
function $ViewDirective($view, $animate, $
|
|
142
|
+
function $ViewDirective($view, $animate, $ngViewScroll, $interpolate, $q) {
|
|
143
143
|
function getRenderer() {
|
|
144
144
|
return {
|
|
145
145
|
enter: function (element, target, cb) {
|
|
@@ -155,7 +155,7 @@ export let uiView = [
|
|
|
155
155
|
}
|
|
156
156
|
const rootData = {
|
|
157
157
|
$cfg: { viewDecl: { $context: $view._pluginapi._rootViewContext() } },
|
|
158
|
-
$
|
|
158
|
+
$ngView: {},
|
|
159
159
|
};
|
|
160
160
|
const directive = {
|
|
161
161
|
count: 0,
|
|
@@ -168,17 +168,17 @@ export let uiView = [
|
|
|
168
168
|
const onloadExp = attrs["onload"] || "",
|
|
169
169
|
autoScrollExp = attrs["autoscroll"],
|
|
170
170
|
renderer = getRenderer(),
|
|
171
|
-
inherited = $element.inheritedData("$
|
|
171
|
+
inherited = $element.inheritedData("$ngView") || rootData,
|
|
172
172
|
name =
|
|
173
|
-
$interpolate(attrs["
|
|
173
|
+
$interpolate(attrs["ngView"] || attrs["name"] || "")(scope) ||
|
|
174
174
|
"$default";
|
|
175
175
|
let previousEl, currentEl, currentScope, viewConfig;
|
|
176
176
|
const activeUIView = {
|
|
177
177
|
$type: "ng1",
|
|
178
178
|
id: directive.count++, // Global sequential ID for ui-view tags added to DOM
|
|
179
179
|
name: name, // ui-view name (<div ui-view="name"></div>
|
|
180
|
-
fqn: inherited.$
|
|
181
|
-
? inherited.$
|
|
180
|
+
fqn: inherited.$ngView.fqn
|
|
181
|
+
? inherited.$ngView.fqn + "." + name
|
|
182
182
|
: name, // fully qualified name, describes location in DOM
|
|
183
183
|
config: null, // The ViewConfig loaded (from a state.views definition)
|
|
184
184
|
configUpdated: configUpdatedCallback, // Called when the matching ViewConfig changes
|
|
@@ -189,7 +189,7 @@ export let uiView = [
|
|
|
189
189
|
);
|
|
190
190
|
// Allow <ui-view name="foo"><ui-view name="bar"></ui-view></ui-view>
|
|
191
191
|
// See https://github.com/angular-ui/ui-router/issues/3355
|
|
192
|
-
const fromParentTag = parse("$
|
|
192
|
+
const fromParentTag = parse("$ngView.creationContext")(inherited);
|
|
193
193
|
return fromParentTagConfig || fromParentTag;
|
|
194
194
|
},
|
|
195
195
|
};
|
|
@@ -204,7 +204,7 @@ export let uiView = [
|
|
|
204
204
|
viewConfig = config;
|
|
205
205
|
updateView(config);
|
|
206
206
|
}
|
|
207
|
-
$element.data("$
|
|
207
|
+
$element.data("$ngView", { $ngView: activeUIView });
|
|
208
208
|
updateView();
|
|
209
209
|
const unregister = $view.registerUIView(activeUIView);
|
|
210
210
|
scope.$on("$destroy", function () {
|
|
@@ -215,7 +215,7 @@ export let uiView = [
|
|
|
215
215
|
if (previousEl) {
|
|
216
216
|
trace.traceUIViewEvent(
|
|
217
217
|
"Removing (previous) el",
|
|
218
|
-
previousEl.data("$
|
|
218
|
+
previousEl.data("$ngView"),
|
|
219
219
|
);
|
|
220
220
|
previousEl.remove();
|
|
221
221
|
previousEl = null;
|
|
@@ -226,7 +226,7 @@ export let uiView = [
|
|
|
226
226
|
currentScope = null;
|
|
227
227
|
}
|
|
228
228
|
if (currentEl) {
|
|
229
|
-
const _viewData = currentEl.data("$
|
|
229
|
+
const _viewData = currentEl.data("$ngViewAnim");
|
|
230
230
|
trace.traceUIViewEvent("Animate out", _viewData);
|
|
231
231
|
renderer.leave(currentEl, function () {
|
|
232
232
|
_viewData.$$animLeave.resolve();
|
|
@@ -240,11 +240,11 @@ export let uiView = [
|
|
|
240
240
|
const newScope = scope.$new();
|
|
241
241
|
const animEnter = $q.defer(),
|
|
242
242
|
animLeave = $q.defer();
|
|
243
|
-
const $
|
|
243
|
+
const $ngViewData = {
|
|
244
244
|
$cfg: config,
|
|
245
|
-
$
|
|
245
|
+
$ngView: activeUIView,
|
|
246
246
|
};
|
|
247
|
-
const $
|
|
247
|
+
const $ngViewAnim = {
|
|
248
248
|
$animEnter: animEnter.promise,
|
|
249
249
|
$animLeave: animLeave.promise,
|
|
250
250
|
$$animLeave: animLeave,
|
|
@@ -263,8 +263,8 @@ export let uiView = [
|
|
|
263
263
|
*/
|
|
264
264
|
newScope.$emit("$viewContentLoading", name);
|
|
265
265
|
const cloned = $transclude(newScope, function (clone) {
|
|
266
|
-
clone.data("$
|
|
267
|
-
clone.data("$
|
|
266
|
+
clone.data("$ngViewAnim", $ngViewAnim);
|
|
267
|
+
clone.data("$ngView", $ngViewData);
|
|
268
268
|
renderer.enter(clone, $element, function () {
|
|
269
269
|
animEnter.resolve();
|
|
270
270
|
if (currentScope)
|
|
@@ -273,7 +273,7 @@ export let uiView = [
|
|
|
273
273
|
(isDefined(autoScrollExp) && !autoScrollExp) ||
|
|
274
274
|
scope.$eval(autoScrollExp)
|
|
275
275
|
) {
|
|
276
|
-
$
|
|
276
|
+
$ngViewScroll(clone);
|
|
277
277
|
}
|
|
278
278
|
});
|
|
279
279
|
cleanupLastView();
|
|
@@ -322,7 +322,7 @@ export function $ViewDirectiveFill(
|
|
|
322
322
|
const initial = tElement.html();
|
|
323
323
|
tElement.empty();
|
|
324
324
|
return function (scope, $element) {
|
|
325
|
-
const data = $element.data("$
|
|
325
|
+
const data = $element.data("$ngView");
|
|
326
326
|
if (!data) {
|
|
327
327
|
$element.html(initial);
|
|
328
328
|
$compile($element[0].contentDocument || $element[0].childNodes)(
|
|
@@ -333,7 +333,7 @@ export function $ViewDirectiveFill(
|
|
|
333
333
|
const cfg = data.$cfg || { viewDecl: {}, getTemplate: () => {} };
|
|
334
334
|
const resolveCtx = cfg.path && new ResolveContext(cfg.path);
|
|
335
335
|
$element.html(cfg.getTemplate($element, resolveCtx) || initial);
|
|
336
|
-
trace.traceUIViewFill(data.$
|
|
336
|
+
trace.traceUIViewFill(data.$ngView, $element.html());
|
|
337
337
|
const link = $compile(
|
|
338
338
|
$element[0].contentDocument || $element[0].childNodes,
|
|
339
339
|
);
|
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);
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
*/
|
|
62
62
|
let $stateParams;
|
|
63
63
|
/**
|
|
64
|
-
* Global
|
|
64
|
+
* Global ng-router variables
|
|
65
65
|
*
|
|
66
66
|
* The router global state as a **Service Object** (injectable during runtime).
|
|
67
67
|
*
|
|
@@ -69,23 +69,23 @@ let $stateParams;
|
|
|
69
69
|
*/
|
|
70
70
|
let $routerGlobals;
|
|
71
71
|
/**
|
|
72
|
-
* The
|
|
72
|
+
* The ng-router instance
|
|
73
73
|
*
|
|
74
74
|
* The [[UIRouter]] singleton (the router instance) as a **Service Object** (injectable during runtime).
|
|
75
75
|
*
|
|
76
|
-
* This object is the
|
|
77
|
-
* It has references to the other
|
|
76
|
+
* This object is the ng-router singleton instance, created by angular dependency injection during application bootstrap.
|
|
77
|
+
* It has references to the other ng-router services
|
|
78
78
|
*
|
|
79
79
|
* #### Note: This object is also exposed as [[$routerProvider]] for injection during angular config time.
|
|
80
80
|
*/
|
|
81
81
|
let $router;
|
|
82
82
|
/**
|
|
83
|
-
* The
|
|
83
|
+
* The ng-router instance
|
|
84
84
|
*
|
|
85
85
|
* The [[UIRouter]] singleton (the router instance) as a **Provider Object** (injectable during config phase).
|
|
86
86
|
*
|
|
87
|
-
* This object is the
|
|
88
|
-
* It has references to the other
|
|
87
|
+
* This object is the ng-router singleton instance, created by angular dependency injection during application bootstrap.
|
|
88
|
+
* It has references to the other ng-router services
|
|
89
89
|
*
|
|
90
90
|
* #### Note: This object is also exposed as [[$router]] for injection during runtime.
|
|
91
91
|
*/
|
|
@@ -193,9 +193,9 @@ let $stateRegistryProvider;
|
|
|
193
193
|
* The [[UIViewScrollProvider]] as a **Provider Object** (injectable during config time).
|
|
194
194
|
*
|
|
195
195
|
* This angular service exposes the [[UIViewScrollProvider]] singleton and is
|
|
196
|
-
* used to disable
|
|
196
|
+
* used to disable ng-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
|
*
|
|
@@ -26,7 +26,7 @@ export const NATIVE_INJECTOR_TOKEN = "Native Injector";
|
|
|
26
26
|
/**
|
|
27
27
|
* Encapsulates Dependency Injection for a path of nodes
|
|
28
28
|
*
|
|
29
|
-
*
|
|
29
|
+
* ng-router states are organized as a tree.
|
|
30
30
|
* A nested state has a path of ancestors to the root of the tree.
|
|
31
31
|
* When a state is being activated, each element in the path is wrapped as a [[PathNode]].
|
|
32
32
|
* A `PathNode` is a stateful object that holds things like parameters and resolvables for the state being activated.
|
package/src/router/router.js
CHANGED
|
@@ -20,7 +20,7 @@ import { registerRedirectToHook } from "./hooks/redirect-to";
|
|
|
20
20
|
let routerId = 0;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* An instance of
|
|
23
|
+
* An instance of ng-router.
|
|
24
24
|
* @class
|
|
25
25
|
*
|
|
26
26
|
* This object contains references to service APIs which define your application's routing behavior.
|
|
@@ -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
|
-
|
|
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,
|
|
@@ -117,78 +118,8 @@ export class UIRouter {
|
|
|
117
118
|
|
|
118
119
|
this.transitionService._deregisterHookFns.activateViews =
|
|
119
120
|
registerActivateViews(this.transitionService, this.viewService);
|
|
120
|
-
|
|
121
|
-
/** @internal plugin instances are registered here */
|
|
122
|
-
this._plugins = {};
|
|
123
121
|
this.viewService._pluginapi._rootViewContext(this.stateRegistry.root());
|
|
124
122
|
this.globals.$current = this.stateRegistry.root();
|
|
125
123
|
this.globals.current = this.globals.$current.self;
|
|
126
124
|
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Adds a plugin to UI-Router
|
|
130
|
-
*
|
|
131
|
-
* This method adds a UI-Router Plugin.
|
|
132
|
-
* A plugin can enhance or change UI-Router behavior using any public API.
|
|
133
|
-
*
|
|
134
|
-
* #### Example:
|
|
135
|
-
* ```js
|
|
136
|
-
* import { MyCoolPlugin } from "ui-router-cool-plugin";
|
|
137
|
-
*
|
|
138
|
-
* var plugin = router.addPlugin(MyCoolPlugin);
|
|
139
|
-
* ```
|
|
140
|
-
*
|
|
141
|
-
* ### Plugin authoring
|
|
142
|
-
*
|
|
143
|
-
* A plugin is simply a class (or constructor function) which accepts a [[UIRouter]] instance and (optionally) an options object.
|
|
144
|
-
*
|
|
145
|
-
* The plugin can implement its functionality using any of the public APIs of [[UIRouter]].
|
|
146
|
-
* For example, it may configure router options or add a Transition Hook.
|
|
147
|
-
*
|
|
148
|
-
* The plugin can then be published as a separate module.
|
|
149
|
-
*
|
|
150
|
-
* #### Example:
|
|
151
|
-
* ```js
|
|
152
|
-
* export class MyAuthPlugin implements UIRouterPlugin {
|
|
153
|
-
* constructor(router: UIRouter, options: any) {
|
|
154
|
-
* this.name = "MyAuthPlugin";
|
|
155
|
-
* let $transitions = router.transitionService;
|
|
156
|
-
* let $state = router.stateService;
|
|
157
|
-
*
|
|
158
|
-
* let authCriteria = {
|
|
159
|
-
* to: (state) => state.data && state.data.requiresAuth
|
|
160
|
-
* };
|
|
161
|
-
*
|
|
162
|
-
* function authHook(transition: Transition) {
|
|
163
|
-
* let authService = transition.injector().get('AuthService');
|
|
164
|
-
* if (!authService.isAuthenticated()) {
|
|
165
|
-
* return $state.target('login');
|
|
166
|
-
* }
|
|
167
|
-
* }
|
|
168
|
-
*
|
|
169
|
-
* $transitions.onStart(authCriteria, authHook);
|
|
170
|
-
* }
|
|
171
|
-
* }
|
|
172
|
-
* ```
|
|
173
|
-
*
|
|
174
|
-
* @param plugin one of:
|
|
175
|
-
* - a plugin class which implements [[UIRouterPlugin]]
|
|
176
|
-
* - a constructor function for a [[UIRouterPlugin]] which accepts a [[UIRouter]] instance
|
|
177
|
-
* - a factory function which accepts a [[UIRouter]] instance and returns a [[UIRouterPlugin]] instance
|
|
178
|
-
* @param options options to pass to the plugin class/factory
|
|
179
|
-
* @returns the registered plugin instance
|
|
180
|
-
*/
|
|
181
|
-
plugin(plugin, options = {}) {
|
|
182
|
-
const pluginInstance = new plugin(this, options);
|
|
183
|
-
if (!pluginInstance.name)
|
|
184
|
-
throw new Error(
|
|
185
|
-
"Required property `name` missing on plugin: " + pluginInstance,
|
|
186
|
-
);
|
|
187
|
-
return (this._plugins[pluginInstance.name] = pluginInstance);
|
|
188
|
-
}
|
|
189
|
-
getPlugin(pluginName) {
|
|
190
|
-
return pluginName
|
|
191
|
-
? this._plugins[pluginName]
|
|
192
|
-
: Object.values(this._plugins);
|
|
193
|
-
}
|
|
194
125
|
}
|
package/src/router/services.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* # Angular 1 types
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* The customizations to the core types for
|
|
4
|
+
* ng-router core provides various Typescript types which you can use for code completion and validating parameter values, etc.
|
|
5
|
+
* The customizations to the core types for ng-router are documented here.
|
|
6
6
|
*
|
|
7
7
|
* The optional [[$resolve]] service is also documented here.
|
|
8
8
|
*
|
|
@@ -13,10 +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";
|
|
17
|
-
|
|
18
16
|
import { StateProvider } from "./state-provider";
|
|
19
|
-
import { ResolveContext } from "./resolve/resolve-context";
|
|
20
17
|
|
|
21
18
|
/** @type {angular.UIRouter}} */
|
|
22
19
|
export let router = null;
|
|
@@ -29,17 +26,6 @@ export function $routerProvider($locationProvider) {
|
|
|
29
26
|
router.stateRegistry,
|
|
30
27
|
router.stateService,
|
|
31
28
|
);
|
|
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
|
-
router.viewService._pluginapi._viewConfigFactory(
|
|
38
|
-
"ng1",
|
|
39
|
-
getNg1ViewConfigFactory(),
|
|
40
|
-
);
|
|
41
|
-
// Disable decoding of params by UrlMatcherFactory because $location already handles this
|
|
42
|
-
router.urlService.config._decodeParams = false;
|
|
43
29
|
|
|
44
30
|
/**
|
|
45
31
|
* Applys ng1-specific path parameter encoding
|
|
@@ -65,8 +51,9 @@ export function $routerProvider($locationProvider) {
|
|
|
65
51
|
// backwards compat: also expose router instance as $routerProvider.router
|
|
66
52
|
router["router"] = router;
|
|
67
53
|
router["$get"] = $get;
|
|
68
|
-
$get.$inject = ["$location", "$browser", "$rootScope"];
|
|
69
|
-
function $get($location, $browser, $rootScope) {
|
|
54
|
+
$get.$inject = ["$location", "$browser", "$rootScope", "$injector"];
|
|
55
|
+
function $get($location, $browser, $rootScope, $injector) {
|
|
56
|
+
router.stateRegistry.init($injector);
|
|
70
57
|
router.urlService._runtimeServices($rootScope, $location, $browser);
|
|
71
58
|
return router;
|
|
72
59
|
}
|
|
@@ -139,28 +126,3 @@ export const getLocals = (ctx) => {
|
|
|
139
126
|
});
|
|
140
127
|
return tuples.reduce(applyPairs, {});
|
|
141
128
|
};
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`,
|
|
145
|
-
* `onRetain` callback hooks on a [[Ng1StateDeclaration]].
|
|
146
|
-
*
|
|
147
|
-
* When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder
|
|
148
|
-
* ensures that those hooks are injectable for @uirouter/angularjs (ng1).
|
|
149
|
-
*
|
|
150
|
-
* @internalapi
|
|
151
|
-
*/
|
|
152
|
-
const getStateHookBuilder = (hookName) =>
|
|
153
|
-
function stateHookBuilder(stateObject) {
|
|
154
|
-
const hook = stateObject[hookName];
|
|
155
|
-
const pathname = hookName === "onExit" ? "from" : "to";
|
|
156
|
-
function decoratedNg1Hook(trans, state) {
|
|
157
|
-
const resolveContext = new ResolveContext(trans.treeChanges(pathname));
|
|
158
|
-
const subContext = resolveContext.subContext(state.$$state());
|
|
159
|
-
const locals = Object.assign(getLocals(subContext), {
|
|
160
|
-
$state$: state,
|
|
161
|
-
$transition$: trans,
|
|
162
|
-
});
|
|
163
|
-
return services.$injector.invoke(hook, this, locals);
|
|
164
|
-
}
|
|
165
|
-
return hook ? decoratedNg1Hook : undefined;
|
|
166
|
-
};
|
|
@@ -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,7 +3,7 @@ import { propEq } from "../../shared/hof";
|
|
|
3
3
|
import { Glob } from "../common/glob";
|
|
4
4
|
import { isFunction, isObject } from "../../shared/utils";
|
|
5
5
|
/**
|
|
6
|
-
* Internal representation of a
|
|
6
|
+
* Internal representation of a ng-router state.
|
|
7
7
|
*
|
|
8
8
|
* Instances of this class are created when a [[StateDeclaration]] is registered with the [[StateRegistry]].
|
|
9
9
|
*
|
|
@@ -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
|
|
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: "",
|
|
@@ -80,7 +125,7 @@ export class StateRegistry {
|
|
|
80
125
|
* Gets the implicit root state
|
|
81
126
|
*
|
|
82
127
|
* Gets the root of the state tree.
|
|
83
|
-
* The root state is implicitly created by
|
|
128
|
+
* The root state is implicitly created by ng-router.
|
|
84
129
|
* Note: this returns the internal [[StateObject]] representation, not a [[StateDeclaration]]
|
|
85
130
|
*
|
|
86
131
|
* @return the root [[StateObject]]
|
|
@@ -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
|
}
|