@tramvai/module-router 2.73.1 → 2.75.0
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/hooks/usePrefetch.browser.browser.js +1 -1
- package/lib/index.browser.js +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.es.js +1 -0
- package/lib/index.js +5 -0
- package/lib/modules/tokens/browser/index.browser.js +23 -1
- package/lib/modules/tokens/browser/index.d.ts +69 -5
- package/lib/stores/PageErrorStore.browser.js +19 -0
- package/lib/stores/PageErrorStore.d.ts +14 -0
- package/lib/stores/PageErrorStore.es.js +19 -0
- package/lib/stores/PageErrorStore.js +26 -0
- package/package.json +18 -18
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useDi } from '@tramvai/react';
|
|
3
3
|
import { LINK_PREFETCH_MANAGER_TOKEN } from '@tramvai/tokens-router';
|
|
4
|
-
import { requestIdleCallback, cancelIdleCallback } from '../utils/requestIdleCallback.browser.js';
|
|
5
4
|
import { optional } from '@tinkoff/dippy';
|
|
5
|
+
import { requestIdleCallback, cancelIdleCallback } from '../utils/requestIdleCallback.browser.js';
|
|
6
6
|
|
|
7
7
|
const isUserNetworkConditionsSuitableForPrefetch = () => {
|
|
8
8
|
var _a;
|
package/lib/index.browser.js
CHANGED
|
@@ -6,4 +6,5 @@ export { Link } from './components/link.browser.js';
|
|
|
6
6
|
export * from '@tramvai/tokens-router';
|
|
7
7
|
export { generateForRoot } from './modules/utils/forRoot.browser.js';
|
|
8
8
|
export { RouterStore, setCurrentNavigation, setUrlOnRehydrate } from './stores/RouterStore.browser.js';
|
|
9
|
+
export { PageErrorStore, deserializeError, serializeError, setPageErrorEvent } from './stores/PageErrorStore.browser.js';
|
|
9
10
|
export { usePageService } from './hooks/usePageService.browser.js';
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { Link } from './components/link';
|
|
|
5
5
|
export * from '@tramvai/tokens-router';
|
|
6
6
|
export { generateForRoot } from './modules/utils/forRoot';
|
|
7
7
|
export * from './stores/RouterStore';
|
|
8
|
+
export * from './stores/PageErrorStore';
|
|
8
9
|
export * from './hooks/usePageService';
|
|
9
10
|
type RouteConfig = {
|
|
10
11
|
[key: string]: any;
|
package/lib/index.es.js
CHANGED
|
@@ -5,4 +5,5 @@ export { Link } from './components/link.es.js';
|
|
|
5
5
|
export * from '@tramvai/tokens-router';
|
|
6
6
|
export { generateForRoot } from './modules/utils/forRoot.es.js';
|
|
7
7
|
export { RouterStore, setCurrentNavigation, setUrlOnRehydrate } from './stores/RouterStore.es.js';
|
|
8
|
+
export { PageErrorStore, deserializeError, serializeError, setPageErrorEvent } from './stores/PageErrorStore.es.js';
|
|
8
9
|
export { usePageService } from './hooks/usePageService.es.js';
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var link = require('./components/link.js');
|
|
|
9
9
|
var tokensRouter = require('@tramvai/tokens-router');
|
|
10
10
|
var forRoot = require('./modules/utils/forRoot.js');
|
|
11
11
|
var RouterStore = require('./stores/RouterStore.js');
|
|
12
|
+
var PageErrorStore = require('./stores/PageErrorStore.js');
|
|
12
13
|
var usePageService = require('./hooks/usePageService.js');
|
|
13
14
|
|
|
14
15
|
|
|
@@ -47,6 +48,10 @@ exports.generateForRoot = forRoot.generateForRoot;
|
|
|
47
48
|
exports.RouterStore = RouterStore.RouterStore;
|
|
48
49
|
exports.setCurrentNavigation = RouterStore.setCurrentNavigation;
|
|
49
50
|
exports.setUrlOnRehydrate = RouterStore.setUrlOnRehydrate;
|
|
51
|
+
exports.PageErrorStore = PageErrorStore.PageErrorStore;
|
|
52
|
+
exports.deserializeError = PageErrorStore.deserializeError;
|
|
53
|
+
exports.serializeError = PageErrorStore.serializeError;
|
|
54
|
+
exports.setPageErrorEvent = PageErrorStore.setPageErrorEvent;
|
|
50
55
|
exports.usePageService = usePageService.usePageService;
|
|
51
56
|
Object.keys(tokensRouter).forEach(function (k) {
|
|
52
57
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
+
import { STORE_TOKEN } from '@tramvai/tokens-common';
|
|
2
|
+
import { BlockError, makeErrorSilent } from '@tinkoff/errors';
|
|
3
|
+
import { setPageErrorEvent } from '../../../stores/PageErrorStore.browser.js';
|
|
4
|
+
import { additionalRouterParameters } from '../../tokens.browser.js';
|
|
1
5
|
import { prefetchProviders } from './prefetch.browser.js';
|
|
2
6
|
|
|
3
|
-
const clientTokens = [
|
|
7
|
+
const clientTokens = [
|
|
8
|
+
...prefetchProviders,
|
|
9
|
+
{
|
|
10
|
+
provide: additionalRouterParameters,
|
|
11
|
+
useFactory: ({ store }) => {
|
|
12
|
+
return {
|
|
13
|
+
onBlock: async (navigation) => {
|
|
14
|
+
var _a;
|
|
15
|
+
let error = new BlockError({ message: `Url ${(_a = navigation.to) === null || _a === void 0 ? void 0 : _a.actualPath} is blocked` });
|
|
16
|
+
error = makeErrorSilent(error);
|
|
17
|
+
store.dispatch(setPageErrorEvent(error));
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
deps: {
|
|
22
|
+
store: STORE_TOKEN,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
];
|
|
4
26
|
|
|
5
27
|
export { clientTokens };
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Navigation } from '@tinkoff/router';
|
|
2
|
+
export declare const clientTokens: (import("@tinkoff/dippy/lib/Provider").ValueProvider<Set<string>> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithDeps<unknown, Set<string>> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithoutDeps<Set<string>> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithDeps<unknown, Set<string>> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithoutDeps<Set<string>> | import("@tinkoff/dippy/lib/Provider").ValueProvider<{
|
|
2
3
|
add(run: () => Promise<void>): Promise<void>;
|
|
3
|
-
}> | import("@tinkoff/dippy").
|
|
4
|
+
}> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithDeps<unknown, {
|
|
5
|
+
add(run: () => Promise<void>): Promise<void>;
|
|
6
|
+
}> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithoutDeps<{
|
|
7
|
+
add(run: () => Promise<void>): Promise<void>;
|
|
8
|
+
}> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithDeps<unknown, {
|
|
9
|
+
add(run: () => Promise<void>): Promise<void>;
|
|
10
|
+
}> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithoutDeps<{
|
|
11
|
+
add(run: () => Promise<void>): Promise<void>;
|
|
12
|
+
}> | import("@tinkoff/dippy/lib/Provider").ValueProvider<{
|
|
13
|
+
prefetch: (url: string) => Promise<void>;
|
|
14
|
+
}> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithDeps<{
|
|
4
15
|
router: import("@tinkoff/router").AbstractRouter & {
|
|
5
16
|
__type?: "base token";
|
|
6
17
|
};
|
|
@@ -19,10 +30,10 @@ export declare const clientTokens: (import("@tinkoff/dippy").Provider<unknown, S
|
|
|
19
30
|
bundleManager: import("@tramvai/tokens-common").BundleManager & {
|
|
20
31
|
__type?: "base token";
|
|
21
32
|
};
|
|
22
|
-
logger: import("@
|
|
33
|
+
logger: import("@tramvai/tokens-common").Logger & ((configOrName: string | {
|
|
23
34
|
[key: string]: any;
|
|
24
35
|
name: string;
|
|
25
|
-
}) => import("@
|
|
36
|
+
}) => import("@tramvai/tokens-common").Logger) & {
|
|
26
37
|
__type?: "base token";
|
|
27
38
|
};
|
|
28
39
|
prefetchedLinksCache: Set<string> & {
|
|
@@ -35,4 +46,57 @@ export declare const clientTokens: (import("@tinkoff/dippy").Provider<unknown, S
|
|
|
35
46
|
};
|
|
36
47
|
}, {
|
|
37
48
|
prefetch: (url: string) => Promise<void>;
|
|
38
|
-
}>)
|
|
49
|
+
}> | import("@tinkoff/dippy/lib/Provider").ClassProviderWithoutDeps<{
|
|
50
|
+
prefetch: (url: string) => Promise<void>;
|
|
51
|
+
}> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithDeps<{
|
|
52
|
+
router: import("@tinkoff/router").AbstractRouter & {
|
|
53
|
+
__type?: "base token";
|
|
54
|
+
};
|
|
55
|
+
routeTransform: import("@tramvai/tokens-router").RouteTransform & {
|
|
56
|
+
__type?: "base token";
|
|
57
|
+
};
|
|
58
|
+
routeResolve: {
|
|
59
|
+
token: import("@tramvai/tokens-router").RouteResolve & {
|
|
60
|
+
__type?: "base token";
|
|
61
|
+
};
|
|
62
|
+
optional: boolean;
|
|
63
|
+
};
|
|
64
|
+
componentRegistry: import("@tramvai/tokens-common").ComponentRegistry & {
|
|
65
|
+
__type?: "base token";
|
|
66
|
+
};
|
|
67
|
+
bundleManager: import("@tramvai/tokens-common").BundleManager & {
|
|
68
|
+
__type?: "base token";
|
|
69
|
+
};
|
|
70
|
+
logger: import("@tramvai/tokens-common").Logger & ((configOrName: string | {
|
|
71
|
+
[key: string]: any;
|
|
72
|
+
name: string;
|
|
73
|
+
}) => import("@tramvai/tokens-common").Logger) & {
|
|
74
|
+
__type?: "base token";
|
|
75
|
+
};
|
|
76
|
+
prefetchedLinksCache: Set<string> & {
|
|
77
|
+
__type?: "base token";
|
|
78
|
+
};
|
|
79
|
+
prefetchedLinksQueue: {
|
|
80
|
+
add(run: () => Promise<void>): Promise<void>;
|
|
81
|
+
} & {
|
|
82
|
+
__type?: "base token";
|
|
83
|
+
};
|
|
84
|
+
}, {
|
|
85
|
+
prefetch: (url: string) => Promise<void>;
|
|
86
|
+
}> | import("@tinkoff/dippy/lib/Provider").FactoryProviderWithoutDeps<{
|
|
87
|
+
prefetch: (url: string) => Promise<void>;
|
|
88
|
+
}> | {
|
|
89
|
+
provide: Record<string, any> & {
|
|
90
|
+
__type?: "base token";
|
|
91
|
+
};
|
|
92
|
+
useFactory: ({ store }: {
|
|
93
|
+
store: any;
|
|
94
|
+
}) => {
|
|
95
|
+
onBlock: (navigation: Navigation) => Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
deps: {
|
|
98
|
+
store: import("@tramvai/tokens-common").Store<Record<string, any>> & {
|
|
99
|
+
__type?: "base token";
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
})[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createEvent, createReducer } from '@tramvai/state';
|
|
2
|
+
|
|
3
|
+
function serializeError(error) {
|
|
4
|
+
return {
|
|
5
|
+
...error,
|
|
6
|
+
message: error.message,
|
|
7
|
+
stack: error.stack,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function deserializeError(serializedError) {
|
|
11
|
+
const error = new Error(serializedError.message);
|
|
12
|
+
Object.assign(error, serializedError);
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
const setPageErrorEvent = createEvent('setPageError');
|
|
16
|
+
const initialState = null;
|
|
17
|
+
const PageErrorStore = createReducer('pageError', initialState).on(setPageErrorEvent, (state, error) => error && serializeError(error));
|
|
18
|
+
|
|
19
|
+
export { PageErrorStore, deserializeError, serializeError, setPageErrorEvent };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type AnyError = Error & {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export interface SerializedError {
|
|
5
|
+
message: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export declare function serializeError(error: AnyError): SerializedError;
|
|
10
|
+
export declare function deserializeError(serializedError: SerializedError): AnyError;
|
|
11
|
+
export type IPageErrorStore = SerializedError | null;
|
|
12
|
+
export declare const setPageErrorEvent: import("@tramvai/types-actions-state-context").EventCreator1<AnyError, AnyError>;
|
|
13
|
+
export declare const PageErrorStore: import("@tramvai/state").Reducer<SerializedError, "pageError">;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createEvent, createReducer } from '@tramvai/state';
|
|
2
|
+
|
|
3
|
+
function serializeError(error) {
|
|
4
|
+
return {
|
|
5
|
+
...error,
|
|
6
|
+
message: error.message,
|
|
7
|
+
stack: error.stack,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function deserializeError(serializedError) {
|
|
11
|
+
const error = new Error(serializedError.message);
|
|
12
|
+
Object.assign(error, serializedError);
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
const setPageErrorEvent = createEvent('setPageError');
|
|
16
|
+
const initialState = null;
|
|
17
|
+
const PageErrorStore = createReducer('pageError', initialState).on(setPageErrorEvent, (state, error) => error && serializeError(error));
|
|
18
|
+
|
|
19
|
+
export { PageErrorStore, deserializeError, serializeError, setPageErrorEvent };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var state = require('@tramvai/state');
|
|
6
|
+
|
|
7
|
+
function serializeError(error) {
|
|
8
|
+
return {
|
|
9
|
+
...error,
|
|
10
|
+
message: error.message,
|
|
11
|
+
stack: error.stack,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function deserializeError(serializedError) {
|
|
15
|
+
const error = new Error(serializedError.message);
|
|
16
|
+
Object.assign(error, serializedError);
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
const setPageErrorEvent = state.createEvent('setPageError');
|
|
20
|
+
const initialState = null;
|
|
21
|
+
const PageErrorStore = state.createReducer('pageError', initialState).on(setPageErrorEvent, (state, error) => error && serializeError(error));
|
|
22
|
+
|
|
23
|
+
exports.PageErrorStore = PageErrorStore;
|
|
24
|
+
exports.deserializeError = deserializeError;
|
|
25
|
+
exports.serializeError = serializeError;
|
|
26
|
+
exports.setPageErrorEvent = setPageErrorEvent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-router",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.75.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -25,27 +25,27 @@
|
|
|
25
25
|
"watch": "tsc -w"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tinkoff/errors": "0.3.
|
|
29
|
-
"@tinkoff/router": "0.2.
|
|
28
|
+
"@tinkoff/errors": "0.3.7",
|
|
29
|
+
"@tinkoff/router": "0.2.10",
|
|
30
30
|
"@tinkoff/url": "0.8.5",
|
|
31
|
-
"@tramvai/react": "2.
|
|
32
|
-
"@tramvai/tokens-child-app": "2.
|
|
33
|
-
"@tramvai/tokens-render": "2.
|
|
34
|
-
"@tramvai/tokens-router": "2.
|
|
35
|
-
"@tramvai/tokens-server": "2.
|
|
36
|
-
"@tramvai/experiments": "2.
|
|
31
|
+
"@tramvai/react": "2.75.0",
|
|
32
|
+
"@tramvai/tokens-child-app": "2.75.0",
|
|
33
|
+
"@tramvai/tokens-render": "2.75.0",
|
|
34
|
+
"@tramvai/tokens-router": "2.75.0",
|
|
35
|
+
"@tramvai/tokens-server": "2.75.0",
|
|
36
|
+
"@tramvai/experiments": "2.75.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@tinkoff/utils": "^2.1.2",
|
|
40
|
-
"@tramvai/cli": "2.
|
|
41
|
-
"@tramvai/core": "2.
|
|
42
|
-
"@tramvai/module-log": "2.
|
|
43
|
-
"@tramvai/module-server": "2.
|
|
44
|
-
"@tramvai/papi": "2.
|
|
45
|
-
"@tramvai/state": "2.
|
|
46
|
-
"@tramvai/test-helpers": "2.
|
|
47
|
-
"@tramvai/test-mocks": "2.
|
|
48
|
-
"@tramvai/tokens-common": "2.
|
|
40
|
+
"@tramvai/cli": "2.75.0",
|
|
41
|
+
"@tramvai/core": "2.75.0",
|
|
42
|
+
"@tramvai/module-log": "2.75.0",
|
|
43
|
+
"@tramvai/module-server": "2.75.0",
|
|
44
|
+
"@tramvai/papi": "2.75.0",
|
|
45
|
+
"@tramvai/state": "2.75.0",
|
|
46
|
+
"@tramvai/test-helpers": "2.75.0",
|
|
47
|
+
"@tramvai/test-mocks": "2.75.0",
|
|
48
|
+
"@tramvai/tokens-common": "2.75.0",
|
|
49
49
|
"@tinkoff/dippy": "0.8.13",
|
|
50
50
|
"react": "*",
|
|
51
51
|
"tslib": "^2.4.0"
|