@tinkoff/router 0.2.17 → 0.2.19
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/lib/components/react/context.d.ts +1 -0
- package/lib/components/react/index.d.ts +1 -0
- package/lib/components/react/provider.d.ts +1 -0
- package/lib/components/react/useNavigate.d.ts +1 -0
- package/lib/components/react/useRoute.d.ts +1 -0
- package/lib/components/react/useRouter.d.ts +1 -0
- package/lib/components/react/useUrl.d.ts +1 -0
- package/lib/history/base.d.ts +1 -0
- package/lib/history/client.browser.js +16 -1
- package/lib/history/client.d.ts +1 -0
- package/lib/history/client.es.js +16 -1
- package/lib/history/client.js +16 -1
- package/lib/history/server.d.ts +1 -0
- package/lib/history/wrapper.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/logger.d.ts +1 -0
- package/lib/router/abstract.browser.js +6 -0
- package/lib/router/abstract.d.ts +3 -0
- package/lib/router/abstract.es.js +6 -0
- package/lib/router/abstract.js +6 -0
- package/lib/router/browser.d.ts +1 -0
- package/lib/router/client.d.ts +1 -0
- package/lib/router/clientNoSpa.d.ts +1 -0
- package/lib/router/server.d.ts +1 -0
- package/lib/tree/constants.d.ts +1 -0
- package/lib/tree/tree.d.ts +1 -0
- package/lib/tree/types.d.ts +1 -0
- package/lib/tree/utils.d.ts +1 -0
- package/lib/types.d.ts +6 -0
- package/lib/utils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -4,3 +4,4 @@ import type { NavigationRoute } from '../../types';
|
|
|
4
4
|
export declare const RouterContext: import("react").Context<AbstractRouter>;
|
|
5
5
|
export declare const RouteContext: import("react").Context<NavigationRoute>;
|
|
6
6
|
export declare const UrlContext: import("react").Context<Url>;
|
|
7
|
+
//# sourceMappingURL=context.d.ts.map
|
package/lib/history/base.d.ts
CHANGED
|
@@ -10,16 +10,31 @@ const generateKey = (navigation) => {
|
|
|
10
10
|
return `${to.name}_${to.path}`;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
+
const generatePreviousNavigateState = (navigation) => {
|
|
14
|
+
const state = {};
|
|
15
|
+
if (navigation.from) {
|
|
16
|
+
state.previousRoute = navigation.from;
|
|
17
|
+
}
|
|
18
|
+
if (navigation.fromUrl) {
|
|
19
|
+
state.previousUrl = navigation.fromUrl;
|
|
20
|
+
}
|
|
21
|
+
return state;
|
|
22
|
+
};
|
|
13
23
|
const generateState = (navigation, currentState) => {
|
|
14
24
|
const key = generateKey(navigation);
|
|
25
|
+
const previousNavigateState = generatePreviousNavigateState(navigation);
|
|
15
26
|
let { type } = navigation;
|
|
16
27
|
if (navigation.replace && currentState) {
|
|
17
28
|
type = currentState.type === type ? type : 'navigate';
|
|
18
29
|
}
|
|
30
|
+
const navigateState = {
|
|
31
|
+
...previousNavigateState,
|
|
32
|
+
...navigation.navigateState,
|
|
33
|
+
};
|
|
19
34
|
return {
|
|
20
35
|
key,
|
|
21
36
|
type,
|
|
22
|
-
navigateState
|
|
37
|
+
navigateState,
|
|
23
38
|
};
|
|
24
39
|
};
|
|
25
40
|
class ClientHistory extends History {
|
package/lib/history/client.d.ts
CHANGED
package/lib/history/client.es.js
CHANGED
|
@@ -10,16 +10,31 @@ const generateKey = (navigation) => {
|
|
|
10
10
|
return `${to.name}_${to.path}`;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
+
const generatePreviousNavigateState = (navigation) => {
|
|
14
|
+
const state = {};
|
|
15
|
+
if (navigation.from) {
|
|
16
|
+
state.previousRoute = navigation.from;
|
|
17
|
+
}
|
|
18
|
+
if (navigation.fromUrl) {
|
|
19
|
+
state.previousUrl = navigation.fromUrl;
|
|
20
|
+
}
|
|
21
|
+
return state;
|
|
22
|
+
};
|
|
13
23
|
const generateState = (navigation, currentState) => {
|
|
14
24
|
const key = generateKey(navigation);
|
|
25
|
+
const previousNavigateState = generatePreviousNavigateState(navigation);
|
|
15
26
|
let { type } = navigation;
|
|
16
27
|
if (navigation.replace && currentState) {
|
|
17
28
|
type = currentState.type === type ? type : 'navigate';
|
|
18
29
|
}
|
|
30
|
+
const navigateState = {
|
|
31
|
+
...previousNavigateState,
|
|
32
|
+
...navigation.navigateState,
|
|
33
|
+
};
|
|
19
34
|
return {
|
|
20
35
|
key,
|
|
21
36
|
type,
|
|
22
|
-
navigateState
|
|
37
|
+
navigateState,
|
|
23
38
|
};
|
|
24
39
|
};
|
|
25
40
|
class ClientHistory extends History {
|
package/lib/history/client.js
CHANGED
|
@@ -14,16 +14,31 @@ const generateKey = (navigation) => {
|
|
|
14
14
|
return `${to.name}_${to.path}`;
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
+
const generatePreviousNavigateState = (navigation) => {
|
|
18
|
+
const state = {};
|
|
19
|
+
if (navigation.from) {
|
|
20
|
+
state.previousRoute = navigation.from;
|
|
21
|
+
}
|
|
22
|
+
if (navigation.fromUrl) {
|
|
23
|
+
state.previousUrl = navigation.fromUrl;
|
|
24
|
+
}
|
|
25
|
+
return state;
|
|
26
|
+
};
|
|
17
27
|
const generateState = (navigation, currentState) => {
|
|
18
28
|
const key = generateKey(navigation);
|
|
29
|
+
const previousNavigateState = generatePreviousNavigateState(navigation);
|
|
19
30
|
let { type } = navigation;
|
|
20
31
|
if (navigation.replace && currentState) {
|
|
21
32
|
type = currentState.type === type ? type : 'navigate';
|
|
22
33
|
}
|
|
34
|
+
const navigateState = {
|
|
35
|
+
...previousNavigateState,
|
|
36
|
+
...navigation.navigateState,
|
|
37
|
+
};
|
|
23
38
|
return {
|
|
24
39
|
key,
|
|
25
40
|
type,
|
|
26
|
-
navigateState
|
|
41
|
+
navigateState,
|
|
27
42
|
};
|
|
28
43
|
};
|
|
29
44
|
class ClientHistory extends base.History {
|
package/lib/history/server.d.ts
CHANGED
package/lib/history/wrapper.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/logger.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ class AbstractRouter {
|
|
|
26
26
|
this.onRedirect = onRedirect;
|
|
27
27
|
this.onNotFound = onNotFound;
|
|
28
28
|
this.onBlock = onBlock;
|
|
29
|
+
this.currentUuid = 0;
|
|
29
30
|
}
|
|
30
31
|
// start is using as marker that any preparation for proper work has done in the app
|
|
31
32
|
// and now router can manage any navigations
|
|
@@ -88,6 +89,7 @@ class AbstractRouter {
|
|
|
88
89
|
history,
|
|
89
90
|
navigateState,
|
|
90
91
|
code: updateRouteOptions.code,
|
|
92
|
+
key: this.uuid(),
|
|
91
93
|
};
|
|
92
94
|
logger.debug({
|
|
93
95
|
event: 'update-current-route',
|
|
@@ -127,6 +129,7 @@ class AbstractRouter {
|
|
|
127
129
|
code,
|
|
128
130
|
redirect,
|
|
129
131
|
redirectFrom,
|
|
132
|
+
key: this.uuid(),
|
|
130
133
|
};
|
|
131
134
|
await this.runHooks('beforeResolve', navigation);
|
|
132
135
|
const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
|
|
@@ -390,6 +393,9 @@ class AbstractRouter {
|
|
|
390
393
|
registerHook(hookName, hook) {
|
|
391
394
|
return registerHook(this.hooks.get(hookName), hook);
|
|
392
395
|
}
|
|
396
|
+
uuid() {
|
|
397
|
+
return this.currentUuid++;
|
|
398
|
+
}
|
|
393
399
|
}
|
|
394
400
|
|
|
395
401
|
export { AbstractRouter };
|
package/lib/router/abstract.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare abstract class AbstractRouter {
|
|
|
34
34
|
protected guards: Set<NavigationGuard>;
|
|
35
35
|
protected hooks: Map<HookName, Set<NavigationHook>>;
|
|
36
36
|
protected syncHooks: Map<SyncHookName, Set<NavigationSyncHook>>;
|
|
37
|
+
private currentUuid;
|
|
37
38
|
constructor({ trailingSlash, mergeSlashes, beforeResolve, beforeNavigate, afterNavigate, beforeUpdateCurrent, afterUpdateCurrent, guards, onChange, onRedirect, onNotFound, onBlock, }: Options);
|
|
38
39
|
protected onRedirect?: NavigationHook;
|
|
39
40
|
protected onNotFound?: NavigationHook;
|
|
@@ -77,5 +78,7 @@ export declare abstract class AbstractRouter {
|
|
|
77
78
|
registerSyncHook(hookName: SyncHookName, hook: NavigationSyncHook): () => void;
|
|
78
79
|
protected runHooks(hookName: HookName, navigation: Navigation): Promise<void>;
|
|
79
80
|
registerHook(hookName: HookName, hook: NavigationHook): () => void;
|
|
81
|
+
private uuid;
|
|
80
82
|
}
|
|
81
83
|
export {};
|
|
84
|
+
//# sourceMappingURL=abstract.d.ts.map
|
|
@@ -26,6 +26,7 @@ class AbstractRouter {
|
|
|
26
26
|
this.onRedirect = onRedirect;
|
|
27
27
|
this.onNotFound = onNotFound;
|
|
28
28
|
this.onBlock = onBlock;
|
|
29
|
+
this.currentUuid = 0;
|
|
29
30
|
}
|
|
30
31
|
// start is using as marker that any preparation for proper work has done in the app
|
|
31
32
|
// and now router can manage any navigations
|
|
@@ -88,6 +89,7 @@ class AbstractRouter {
|
|
|
88
89
|
history,
|
|
89
90
|
navigateState,
|
|
90
91
|
code: updateRouteOptions.code,
|
|
92
|
+
key: this.uuid(),
|
|
91
93
|
};
|
|
92
94
|
logger.debug({
|
|
93
95
|
event: 'update-current-route',
|
|
@@ -127,6 +129,7 @@ class AbstractRouter {
|
|
|
127
129
|
code,
|
|
128
130
|
redirect,
|
|
129
131
|
redirectFrom,
|
|
132
|
+
key: this.uuid(),
|
|
130
133
|
};
|
|
131
134
|
await this.runHooks('beforeResolve', navigation);
|
|
132
135
|
const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
|
|
@@ -390,6 +393,9 @@ class AbstractRouter {
|
|
|
390
393
|
registerHook(hookName, hook) {
|
|
391
394
|
return registerHook(this.hooks.get(hookName), hook);
|
|
392
395
|
}
|
|
396
|
+
uuid() {
|
|
397
|
+
return this.currentUuid++;
|
|
398
|
+
}
|
|
393
399
|
}
|
|
394
400
|
|
|
395
401
|
export { AbstractRouter };
|
package/lib/router/abstract.js
CHANGED
|
@@ -35,6 +35,7 @@ class AbstractRouter {
|
|
|
35
35
|
this.onRedirect = onRedirect;
|
|
36
36
|
this.onNotFound = onNotFound;
|
|
37
37
|
this.onBlock = onBlock;
|
|
38
|
+
this.currentUuid = 0;
|
|
38
39
|
}
|
|
39
40
|
// start is using as marker that any preparation for proper work has done in the app
|
|
40
41
|
// and now router can manage any navigations
|
|
@@ -97,6 +98,7 @@ class AbstractRouter {
|
|
|
97
98
|
history,
|
|
98
99
|
navigateState,
|
|
99
100
|
code: updateRouteOptions.code,
|
|
101
|
+
key: this.uuid(),
|
|
100
102
|
};
|
|
101
103
|
logger.logger.debug({
|
|
102
104
|
event: 'update-current-route',
|
|
@@ -136,6 +138,7 @@ class AbstractRouter {
|
|
|
136
138
|
code,
|
|
137
139
|
redirect,
|
|
138
140
|
redirectFrom,
|
|
141
|
+
key: this.uuid(),
|
|
139
142
|
};
|
|
140
143
|
await this.runHooks('beforeResolve', navigation);
|
|
141
144
|
const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
|
|
@@ -399,6 +402,9 @@ class AbstractRouter {
|
|
|
399
402
|
registerHook(hookName, hook) {
|
|
400
403
|
return utils.registerHook(this.hooks.get(hookName), hook);
|
|
401
404
|
}
|
|
405
|
+
uuid() {
|
|
406
|
+
return this.currentUuid++;
|
|
407
|
+
}
|
|
402
408
|
}
|
|
403
409
|
|
|
404
410
|
exports.AbstractRouter = AbstractRouter;
|
package/lib/router/browser.d.ts
CHANGED
package/lib/router/client.d.ts
CHANGED
package/lib/router/server.d.ts
CHANGED
package/lib/tree/constants.d.ts
CHANGED
package/lib/tree/tree.d.ts
CHANGED
package/lib/tree/types.d.ts
CHANGED
package/lib/tree/utils.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare const isWildcard: (part: string) => boolean;
|
|
|
6
6
|
export declare const isParameterized: (part: string) => boolean;
|
|
7
7
|
export declare const parse: (part: string) => ParsedPath;
|
|
8
8
|
export declare const makePath: (pathname: string, params: Params) => string;
|
|
9
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/lib/types.d.ts
CHANGED
|
@@ -45,9 +45,15 @@ export interface Navigation {
|
|
|
45
45
|
code?: number;
|
|
46
46
|
redirect?: boolean;
|
|
47
47
|
redirectFrom?: NavigationRoute;
|
|
48
|
+
/**
|
|
49
|
+
* Helps to separate commandLineRunner launches on navigation processes.
|
|
50
|
+
* Defines internally within the router
|
|
51
|
+
*/
|
|
52
|
+
key?: number;
|
|
48
53
|
}
|
|
49
54
|
export type NavigationGuard = (navigation: Navigation) => Promise<void | NavigateOptions | string | boolean>;
|
|
50
55
|
export type NavigationHook = (navigation: Navigation) => Promise<void>;
|
|
51
56
|
export type NavigationSyncHook = (navigation: Navigation) => void;
|
|
52
57
|
export type HookName = 'beforeResolve' | 'beforeNavigate' | 'afterNavigate' | 'beforeUpdateCurrent' | 'afterUpdateCurrent';
|
|
53
58
|
export type SyncHookName = 'change';
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
package/lib/utils.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare const normalizeManySlashes: (hrefOrPath: string) => string;
|
|
|
6
6
|
export declare const isSameHost: import("@tinkoff/utils/typings/types").Func<true> | ((url: Url | URL) => boolean);
|
|
7
7
|
export declare const makeNavigateOptions: (options: string | NavigateOptions) => NavigateOptions;
|
|
8
8
|
export declare const registerHook: <T extends NavigationHook | NavigationSyncHook | NavigationGuard>(hooksSet: Set<T>, hook: T) => () => void;
|
|
9
|
+
//# sourceMappingURL=utils.d.ts.map
|