@tramvai/module-router 2.109.0 → 2.110.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.
Files changed (26) hide show
  1. package/lib/modules/common.browser.js +2 -11
  2. package/lib/modules/common.d.ts +4 -0
  3. package/lib/modules/common.es.js +2 -11
  4. package/lib/modules/common.js +0 -9
  5. package/lib/modules/guards/common/index.browser.js +8 -10
  6. package/lib/modules/guards/common/index.es.js +8 -10
  7. package/lib/modules/guards/common/index.js +6 -8
  8. package/lib/modules/guards/common/loadBundle.browser.js +3 -38
  9. package/lib/modules/guards/common/loadBundle.d.ts +4 -7
  10. package/lib/modules/guards/common/loadBundle.es.js +3 -38
  11. package/lib/modules/guards/common/loadBundle.js +3 -42
  12. package/lib/modules/tokens/browser/index.d.ts +20 -14
  13. package/lib/modules/tokens/browser/prefetch.browser.js +13 -33
  14. package/lib/modules/tokens/browser/prefetch.d.ts +11 -7
  15. package/lib/modules/tokens/common/index.browser.js +33 -9
  16. package/lib/modules/tokens/common/index.es.js +33 -9
  17. package/lib/modules/tokens/common/index.js +32 -8
  18. package/lib/modules/tokens/common/pageRegistry.browser.js +57 -0
  19. package/lib/modules/tokens/common/pageRegistry.d.ts +23 -0
  20. package/lib/modules/tokens/common/pageRegistry.es.js +57 -0
  21. package/lib/modules/tokens/common/pageRegistry.js +67 -0
  22. package/lib/{services/page.browser.js → modules/tokens/common/pageService.browser.js} +16 -16
  23. package/lib/{services/page.d.ts → modules/tokens/common/pageService.d.ts} +7 -7
  24. package/lib/{services/page.es.js → modules/tokens/common/pageService.es.js} +16 -16
  25. package/lib/{services/page.js → modules/tokens/common/pageService.js} +16 -16
  26. package/package.json +16 -16
@@ -1,13 +1,17 @@
1
- import { ROUTE_TRANSFORM_TOKEN, ROUTER_TOKEN } from '@tramvai/tokens-router';
1
+ import { provide } from '@tramvai/core';
2
+ import { ROUTE_TRANSFORM_TOKEN, ROUTER_TOKEN, PAGE_SERVICE_TOKEN, PAGE_REGISTRY_TOKEN } from '@tramvai/tokens-router';
2
3
  import { EXTEND_RENDER } from '@tramvai/tokens-render';
4
+ import { COMPONENT_REGISTRY_TOKEN, BUNDLE_MANAGER_TOKEN, ACTION_REGISTRY_TOKEN, DISPATCHER_TOKEN, DISPATCHER_CONTEXT_TOKEN } from '@tramvai/tokens-common';
3
5
  import { routeTransformToken } from '../../tokens.browser.js';
4
6
  import { routeTransform } from './routeTransform.browser.js';
5
7
  import { routeSetDefaults } from './routeSetDefaults.browser.js';
6
8
  import { routeNormalize } from './routeNormalize.browser.js';
7
9
  import { provideRouter } from './render.browser.js';
10
+ import { PageService } from './pageService.browser.js';
11
+ import { PageRegistry } from './pageRegistry.browser.js';
8
12
 
9
13
  const commonTokens = [
10
- {
14
+ provide({
11
15
  provide: routeTransformToken,
12
16
  useFactory: routeTransform,
13
17
  deps: {
@@ -16,25 +20,45 @@ const commonTokens = [
16
20
  optional: true,
17
21
  },
18
22
  },
19
- },
20
- {
23
+ }),
24
+ provide({
21
25
  provide: ROUTE_TRANSFORM_TOKEN,
22
26
  multi: true,
23
27
  useValue: routeSetDefaults,
24
- },
25
- {
28
+ }),
29
+ provide({
26
30
  provide: ROUTE_TRANSFORM_TOKEN,
27
31
  multi: true,
28
32
  useValue: routeNormalize,
29
- },
30
- {
33
+ }),
34
+ provide({
31
35
  provide: EXTEND_RENDER,
32
36
  multi: true,
33
37
  useFactory: provideRouter,
34
38
  deps: {
35
39
  router: ROUTER_TOKEN,
36
40
  },
37
- },
41
+ }),
42
+ provide({
43
+ provide: PAGE_SERVICE_TOKEN,
44
+ useClass: PageService,
45
+ deps: {
46
+ router: ROUTER_TOKEN,
47
+ componentRegistry: COMPONENT_REGISTRY_TOKEN,
48
+ },
49
+ }),
50
+ provide({
51
+ provide: PAGE_REGISTRY_TOKEN,
52
+ useClass: PageRegistry,
53
+ deps: {
54
+ bundleManager: BUNDLE_MANAGER_TOKEN,
55
+ pageService: PAGE_SERVICE_TOKEN,
56
+ componentRegistry: COMPONENT_REGISTRY_TOKEN,
57
+ actionRegistry: ACTION_REGISTRY_TOKEN,
58
+ dispatcher: DISPATCHER_TOKEN,
59
+ dispatcherContext: DISPATCHER_CONTEXT_TOKEN,
60
+ },
61
+ }),
38
62
  ];
39
63
 
40
64
  export { commonTokens };
@@ -1,13 +1,17 @@
1
- import { ROUTE_TRANSFORM_TOKEN, ROUTER_TOKEN } from '@tramvai/tokens-router';
1
+ import { provide } from '@tramvai/core';
2
+ import { ROUTE_TRANSFORM_TOKEN, ROUTER_TOKEN, PAGE_SERVICE_TOKEN, PAGE_REGISTRY_TOKEN } from '@tramvai/tokens-router';
2
3
  import { EXTEND_RENDER } from '@tramvai/tokens-render';
4
+ import { COMPONENT_REGISTRY_TOKEN, BUNDLE_MANAGER_TOKEN, ACTION_REGISTRY_TOKEN, DISPATCHER_TOKEN, DISPATCHER_CONTEXT_TOKEN } from '@tramvai/tokens-common';
3
5
  import { routeTransformToken } from '../../tokens.es.js';
4
6
  import { routeTransform } from './routeTransform.es.js';
5
7
  import { routeSetDefaults } from './routeSetDefaults.es.js';
6
8
  import { routeNormalize } from './routeNormalize.es.js';
7
9
  import { provideRouter } from './render.es.js';
10
+ import { PageService } from './pageService.es.js';
11
+ import { PageRegistry } from './pageRegistry.es.js';
8
12
 
9
13
  const commonTokens = [
10
- {
14
+ provide({
11
15
  provide: routeTransformToken,
12
16
  useFactory: routeTransform,
13
17
  deps: {
@@ -16,25 +20,45 @@ const commonTokens = [
16
20
  optional: true,
17
21
  },
18
22
  },
19
- },
20
- {
23
+ }),
24
+ provide({
21
25
  provide: ROUTE_TRANSFORM_TOKEN,
22
26
  multi: true,
23
27
  useValue: routeSetDefaults,
24
- },
25
- {
28
+ }),
29
+ provide({
26
30
  provide: ROUTE_TRANSFORM_TOKEN,
27
31
  multi: true,
28
32
  useValue: routeNormalize,
29
- },
30
- {
33
+ }),
34
+ provide({
31
35
  provide: EXTEND_RENDER,
32
36
  multi: true,
33
37
  useFactory: provideRouter,
34
38
  deps: {
35
39
  router: ROUTER_TOKEN,
36
40
  },
37
- },
41
+ }),
42
+ provide({
43
+ provide: PAGE_SERVICE_TOKEN,
44
+ useClass: PageService,
45
+ deps: {
46
+ router: ROUTER_TOKEN,
47
+ componentRegistry: COMPONENT_REGISTRY_TOKEN,
48
+ },
49
+ }),
50
+ provide({
51
+ provide: PAGE_REGISTRY_TOKEN,
52
+ useClass: PageRegistry,
53
+ deps: {
54
+ bundleManager: BUNDLE_MANAGER_TOKEN,
55
+ pageService: PAGE_SERVICE_TOKEN,
56
+ componentRegistry: COMPONENT_REGISTRY_TOKEN,
57
+ actionRegistry: ACTION_REGISTRY_TOKEN,
58
+ dispatcher: DISPATCHER_TOKEN,
59
+ dispatcherContext: DISPATCHER_CONTEXT_TOKEN,
60
+ },
61
+ }),
38
62
  ];
39
63
 
40
64
  export { commonTokens };
@@ -2,16 +2,20 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var core = require('@tramvai/core');
5
6
  var tokensRouter = require('@tramvai/tokens-router');
6
7
  var tokensRender = require('@tramvai/tokens-render');
8
+ var tokensCommon = require('@tramvai/tokens-common');
7
9
  var tokens = require('../../tokens.js');
8
10
  var routeTransform = require('./routeTransform.js');
9
11
  var routeSetDefaults = require('./routeSetDefaults.js');
10
12
  var routeNormalize = require('./routeNormalize.js');
11
13
  var render = require('./render.js');
14
+ var pageService = require('./pageService.js');
15
+ var pageRegistry = require('./pageRegistry.js');
12
16
 
13
17
  const commonTokens = [
14
- {
18
+ core.provide({
15
19
  provide: tokens.routeTransformToken,
16
20
  useFactory: routeTransform.routeTransform,
17
21
  deps: {
@@ -20,25 +24,45 @@ const commonTokens = [
20
24
  optional: true,
21
25
  },
22
26
  },
23
- },
24
- {
27
+ }),
28
+ core.provide({
25
29
  provide: tokensRouter.ROUTE_TRANSFORM_TOKEN,
26
30
  multi: true,
27
31
  useValue: routeSetDefaults.routeSetDefaults,
28
- },
29
- {
32
+ }),
33
+ core.provide({
30
34
  provide: tokensRouter.ROUTE_TRANSFORM_TOKEN,
31
35
  multi: true,
32
36
  useValue: routeNormalize.routeNormalize,
33
- },
34
- {
37
+ }),
38
+ core.provide({
35
39
  provide: tokensRender.EXTEND_RENDER,
36
40
  multi: true,
37
41
  useFactory: render.provideRouter,
38
42
  deps: {
39
43
  router: tokensRouter.ROUTER_TOKEN,
40
44
  },
41
- },
45
+ }),
46
+ core.provide({
47
+ provide: tokensRouter.PAGE_SERVICE_TOKEN,
48
+ useClass: pageService.PageService,
49
+ deps: {
50
+ router: tokensRouter.ROUTER_TOKEN,
51
+ componentRegistry: tokensCommon.COMPONENT_REGISTRY_TOKEN,
52
+ },
53
+ }),
54
+ core.provide({
55
+ provide: tokensRouter.PAGE_REGISTRY_TOKEN,
56
+ useClass: pageRegistry.PageRegistry,
57
+ deps: {
58
+ bundleManager: tokensCommon.BUNDLE_MANAGER_TOKEN,
59
+ pageService: tokensRouter.PAGE_SERVICE_TOKEN,
60
+ componentRegistry: tokensCommon.COMPONENT_REGISTRY_TOKEN,
61
+ actionRegistry: tokensCommon.ACTION_REGISTRY_TOKEN,
62
+ dispatcher: tokensCommon.DISPATCHER_TOKEN,
63
+ dispatcherContext: tokensCommon.DISPATCHER_CONTEXT_TOKEN,
64
+ },
65
+ }),
42
66
  ];
43
67
 
44
68
  exports.commonTokens = commonTokens;
@@ -0,0 +1,57 @@
1
+ import isArray from '@tinkoff/utils/is/array';
2
+ import isObject from '@tinkoff/utils/is/object';
3
+ import eachObj from '@tinkoff/utils/object/each';
4
+ import { resolveLazyComponent } from '@tramvai/react';
5
+
6
+ class PageRegistry {
7
+ constructor({ bundleManager, pageService, componentRegistry, actionRegistry, dispatcher, dispatcherContext, }) {
8
+ this.bundleManager = bundleManager;
9
+ this.pageService = pageService;
10
+ this.componentRegistry = componentRegistry;
11
+ this.actionRegistry = actionRegistry;
12
+ this.dispatcher = dispatcher;
13
+ this.dispatcherContext = dispatcherContext;
14
+ }
15
+ async resolve(route) {
16
+ var _a;
17
+ const { bundle, pageComponent } = this.pageService.getConfig(route);
18
+ const nestedLayoutComponent = this.pageService.resolveComponentFromConfig('nestedLayout', route);
19
+ const resolvedBundle = await this.bundleManager.get(bundle, pageComponent);
20
+ // register bundle first to be able to load other components later
21
+ await this.registerComponent(bundle, resolvedBundle);
22
+ const resolvedPageComponent = (_a = resolvedBundle.components) === null || _a === void 0 ? void 0 : _a[pageComponent];
23
+ // for file-system pages bundle is virtual, so it will be loaded in parallel with nested layout
24
+ // for classic bundles, page component will be loaded after bundle loading
25
+ const promises = [];
26
+ if (resolvedPageComponent) {
27
+ promises.push(this.registerComponent(pageComponent, resolvedPageComponent));
28
+ }
29
+ // TODO: maybe add the same logic for layoutComponent etc?
30
+ if (nestedLayoutComponent) {
31
+ promises.push(this.registerComponent(pageComponent, this.pageService.resolveComponentFromConfig('nestedLayout')));
32
+ }
33
+ await Promise.all(promises);
34
+ }
35
+ async registerComponent(group, componentOrBundle) {
36
+ // hoist static properties from inner component to lazy wrapper if any
37
+ if ('load' in componentOrBundle) {
38
+ await resolveLazyComponent(componentOrBundle);
39
+ }
40
+ if ('components' in componentOrBundle && isObject(componentOrBundle.components)) {
41
+ eachObj((cmp, name) => {
42
+ this.componentRegistry.add(name, cmp, group);
43
+ }, componentOrBundle.components);
44
+ }
45
+ if ('actions' in componentOrBundle && isArray(componentOrBundle.actions)) {
46
+ this.actionRegistry.add(group, componentOrBundle.actions);
47
+ }
48
+ if ('reducers' in componentOrBundle && isArray(componentOrBundle.reducers)) {
49
+ componentOrBundle.reducers.forEach((reducer) => {
50
+ this.dispatcher.registerStore(reducer);
51
+ this.dispatcherContext.getStore(reducer);
52
+ });
53
+ }
54
+ }
55
+ }
56
+
57
+ export { PageRegistry };
@@ -0,0 +1,23 @@
1
+ import type { Route } from '@tinkoff/router';
2
+ import type { PageRegistry as Interface, PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
3
+ import type { COMPONENT_REGISTRY_TOKEN, ACTION_REGISTRY_TOKEN, DISPATCHER_CONTEXT_TOKEN, DISPATCHER_TOKEN, BUNDLE_MANAGER_TOKEN } from '@tramvai/tokens-common';
4
+ interface Deps {
5
+ bundleManager: typeof BUNDLE_MANAGER_TOKEN;
6
+ pageService: typeof PAGE_SERVICE_TOKEN;
7
+ componentRegistry: typeof COMPONENT_REGISTRY_TOKEN;
8
+ actionRegistry: typeof ACTION_REGISTRY_TOKEN;
9
+ dispatcher: typeof DISPATCHER_TOKEN;
10
+ dispatcherContext: typeof DISPATCHER_CONTEXT_TOKEN;
11
+ }
12
+ export declare class PageRegistry implements Interface {
13
+ private bundleManager;
14
+ private pageService;
15
+ private componentRegistry;
16
+ private actionRegistry;
17
+ private dispatcher;
18
+ private dispatcherContext;
19
+ constructor({ bundleManager, pageService, componentRegistry, actionRegistry, dispatcher, dispatcherContext, }: Deps);
20
+ resolve(route: Route): Promise<void>;
21
+ private registerComponent;
22
+ }
23
+ export {};
@@ -0,0 +1,57 @@
1
+ import isArray from '@tinkoff/utils/is/array';
2
+ import isObject from '@tinkoff/utils/is/object';
3
+ import eachObj from '@tinkoff/utils/object/each';
4
+ import { resolveLazyComponent } from '@tramvai/react';
5
+
6
+ class PageRegistry {
7
+ constructor({ bundleManager, pageService, componentRegistry, actionRegistry, dispatcher, dispatcherContext, }) {
8
+ this.bundleManager = bundleManager;
9
+ this.pageService = pageService;
10
+ this.componentRegistry = componentRegistry;
11
+ this.actionRegistry = actionRegistry;
12
+ this.dispatcher = dispatcher;
13
+ this.dispatcherContext = dispatcherContext;
14
+ }
15
+ async resolve(route) {
16
+ var _a;
17
+ const { bundle, pageComponent } = this.pageService.getConfig(route);
18
+ const nestedLayoutComponent = this.pageService.resolveComponentFromConfig('nestedLayout', route);
19
+ const resolvedBundle = await this.bundleManager.get(bundle, pageComponent);
20
+ // register bundle first to be able to load other components later
21
+ await this.registerComponent(bundle, resolvedBundle);
22
+ const resolvedPageComponent = (_a = resolvedBundle.components) === null || _a === void 0 ? void 0 : _a[pageComponent];
23
+ // for file-system pages bundle is virtual, so it will be loaded in parallel with nested layout
24
+ // for classic bundles, page component will be loaded after bundle loading
25
+ const promises = [];
26
+ if (resolvedPageComponent) {
27
+ promises.push(this.registerComponent(pageComponent, resolvedPageComponent));
28
+ }
29
+ // TODO: maybe add the same logic for layoutComponent etc?
30
+ if (nestedLayoutComponent) {
31
+ promises.push(this.registerComponent(pageComponent, this.pageService.resolveComponentFromConfig('nestedLayout')));
32
+ }
33
+ await Promise.all(promises);
34
+ }
35
+ async registerComponent(group, componentOrBundle) {
36
+ // hoist static properties from inner component to lazy wrapper if any
37
+ if ('load' in componentOrBundle) {
38
+ await resolveLazyComponent(componentOrBundle);
39
+ }
40
+ if ('components' in componentOrBundle && isObject(componentOrBundle.components)) {
41
+ eachObj((cmp, name) => {
42
+ this.componentRegistry.add(name, cmp, group);
43
+ }, componentOrBundle.components);
44
+ }
45
+ if ('actions' in componentOrBundle && isArray(componentOrBundle.actions)) {
46
+ this.actionRegistry.add(group, componentOrBundle.actions);
47
+ }
48
+ if ('reducers' in componentOrBundle && isArray(componentOrBundle.reducers)) {
49
+ componentOrBundle.reducers.forEach((reducer) => {
50
+ this.dispatcher.registerStore(reducer);
51
+ this.dispatcherContext.getStore(reducer);
52
+ });
53
+ }
54
+ }
55
+ }
56
+
57
+ export { PageRegistry };
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var isArray = require('@tinkoff/utils/is/array');
6
+ var isObject = require('@tinkoff/utils/is/object');
7
+ var eachObj = require('@tinkoff/utils/object/each');
8
+ var react = require('@tramvai/react');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
13
+ var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
14
+ var eachObj__default = /*#__PURE__*/_interopDefaultLegacy(eachObj);
15
+
16
+ class PageRegistry {
17
+ constructor({ bundleManager, pageService, componentRegistry, actionRegistry, dispatcher, dispatcherContext, }) {
18
+ this.bundleManager = bundleManager;
19
+ this.pageService = pageService;
20
+ this.componentRegistry = componentRegistry;
21
+ this.actionRegistry = actionRegistry;
22
+ this.dispatcher = dispatcher;
23
+ this.dispatcherContext = dispatcherContext;
24
+ }
25
+ async resolve(route) {
26
+ var _a;
27
+ const { bundle, pageComponent } = this.pageService.getConfig(route);
28
+ const nestedLayoutComponent = this.pageService.resolveComponentFromConfig('nestedLayout', route);
29
+ const resolvedBundle = await this.bundleManager.get(bundle, pageComponent);
30
+ // register bundle first to be able to load other components later
31
+ await this.registerComponent(bundle, resolvedBundle);
32
+ const resolvedPageComponent = (_a = resolvedBundle.components) === null || _a === void 0 ? void 0 : _a[pageComponent];
33
+ // for file-system pages bundle is virtual, so it will be loaded in parallel with nested layout
34
+ // for classic bundles, page component will be loaded after bundle loading
35
+ const promises = [];
36
+ if (resolvedPageComponent) {
37
+ promises.push(this.registerComponent(pageComponent, resolvedPageComponent));
38
+ }
39
+ // TODO: maybe add the same logic for layoutComponent etc?
40
+ if (nestedLayoutComponent) {
41
+ promises.push(this.registerComponent(pageComponent, this.pageService.resolveComponentFromConfig('nestedLayout')));
42
+ }
43
+ await Promise.all(promises);
44
+ }
45
+ async registerComponent(group, componentOrBundle) {
46
+ // hoist static properties from inner component to lazy wrapper if any
47
+ if ('load' in componentOrBundle) {
48
+ await react.resolveLazyComponent(componentOrBundle);
49
+ }
50
+ if ('components' in componentOrBundle && isObject__default["default"](componentOrBundle.components)) {
51
+ eachObj__default["default"]((cmp, name) => {
52
+ this.componentRegistry.add(name, cmp, group);
53
+ }, componentOrBundle.components);
54
+ }
55
+ if ('actions' in componentOrBundle && isArray__default["default"](componentOrBundle.actions)) {
56
+ this.actionRegistry.add(group, componentOrBundle.actions);
57
+ }
58
+ if ('reducers' in componentOrBundle && isArray__default["default"](componentOrBundle.reducers)) {
59
+ componentOrBundle.reducers.forEach((reducer) => {
60
+ this.dispatcher.registerStore(reducer);
61
+ this.dispatcherContext.getStore(reducer);
62
+ });
63
+ }
64
+ }
65
+ }
66
+
67
+ exports.PageRegistry = PageRegistry;
@@ -11,17 +11,17 @@ class PageService {
11
11
  getCurrentUrl() {
12
12
  return this.router.getCurrentUrl();
13
13
  }
14
- getConfig() {
15
- var _a, _b;
16
- return (_b = (_a = this.getCurrentRoute()) === null || _a === void 0 ? void 0 : _a.config) !== null && _b !== void 0 ? _b : {};
14
+ getConfig(route = this.getCurrentRoute()) {
15
+ var _a;
16
+ return (_a = route === null || route === void 0 ? void 0 : route.config) !== null && _a !== void 0 ? _a : {};
17
17
  }
18
- getContent() {
18
+ getContent(route) {
19
19
  var _a;
20
- return (_a = this.getConfig().content) !== null && _a !== void 0 ? _a : {};
20
+ return (_a = this.getConfig(route).content) !== null && _a !== void 0 ? _a : {};
21
21
  }
22
- getMeta() {
22
+ getMeta(route) {
23
23
  var _a;
24
- return (_a = this.getConfig().meta) !== null && _a !== void 0 ? _a : {};
24
+ return (_a = this.getConfig(route).meta) !== null && _a !== void 0 ? _a : {};
25
25
  }
26
26
  navigate(options) {
27
27
  return this.router.navigate(options);
@@ -38,23 +38,23 @@ class PageService {
38
38
  go(to, options) {
39
39
  return this.router.go(to, options);
40
40
  }
41
- addComponent(name, component) {
42
- const group = this.getComponentsGroupName();
41
+ addComponent(name, component, route) {
42
+ const group = this.getComponentsGroupName(route);
43
43
  return this.componentRegistry.add(name, component, group);
44
44
  }
45
- getComponent(name) {
46
- const group = this.getComponentsGroupName();
45
+ getComponent(name, route) {
46
+ const group = this.getComponentsGroupName(route);
47
47
  return this.componentRegistry.get(name, group);
48
48
  }
49
- resolveComponentFromConfig(property) {
49
+ resolveComponentFromConfig(property, route) {
50
50
  var _a;
51
51
  const configName = `${property}Component`;
52
52
  const defaultComponent = `${property}Default`;
53
- const componentName = (_a = this.getConfig()[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
54
- return this.getComponent(componentName) || this.getComponent(defaultComponent);
53
+ const componentName = (_a = this.getConfig(route)[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
54
+ return this.getComponent(componentName, route) || this.getComponent(defaultComponent, route);
55
55
  }
56
- getComponentsGroupName() {
57
- const { bundle, pageComponent } = this.getConfig();
56
+ getComponentsGroupName(route) {
57
+ const { bundle, pageComponent } = this.getConfig(route);
58
58
  const group = isFileSystemPageComponent(pageComponent) ? pageComponent : bundle;
59
59
  return group;
60
60
  }
@@ -1,5 +1,5 @@
1
1
  import type { Url } from '@tinkoff/url';
2
- import type { NavigationRoute, NavigateOptions, UpdateCurrentRouteOptions, HistoryOptions } from '@tinkoff/router';
2
+ import type { NavigationRoute, NavigateOptions, UpdateCurrentRouteOptions, HistoryOptions, Route } from '@tinkoff/router';
3
3
  import type { TramvaiComponent } from '@tramvai/react';
4
4
  import type { PageServiceComponentType, PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
5
5
  type PageServiceInterface = typeof PAGE_SERVICE_TOKEN;
@@ -12,17 +12,17 @@ export declare class PageService implements PageServiceInterface {
12
12
  });
13
13
  getCurrentRoute(): NavigationRoute;
14
14
  getCurrentUrl(): Url;
15
- getConfig(): Record<string, any>;
16
- getContent(): Record<string, any>;
17
- getMeta(): any;
15
+ getConfig(route?: Route): Record<string, any>;
16
+ getContent(route?: Route): Record<string, any>;
17
+ getMeta(route?: Route): any;
18
18
  navigate(options: NavigateOptions | string): Promise<void>;
19
19
  updateCurrentRoute(options: UpdateCurrentRouteOptions): Promise<void>;
20
20
  back(options?: HistoryOptions): Promise<void>;
21
21
  forward(): Promise<void>;
22
22
  go(to: number, options?: HistoryOptions): Promise<void>;
23
- addComponent(name: string, component: TramvaiComponent): void;
24
- getComponent(name: string): TramvaiComponent | undefined;
25
- resolveComponentFromConfig(property: PageServiceComponentType): TramvaiComponent;
23
+ addComponent(name: string, component: TramvaiComponent, route?: Route): void;
24
+ getComponent(name: string, route?: Route): TramvaiComponent | undefined;
25
+ resolveComponentFromConfig(property: PageServiceComponentType, route?: Route): TramvaiComponent;
26
26
  private getComponentsGroupName;
27
27
  }
28
28
  export {};
@@ -11,17 +11,17 @@ class PageService {
11
11
  getCurrentUrl() {
12
12
  return this.router.getCurrentUrl();
13
13
  }
14
- getConfig() {
15
- var _a, _b;
16
- return (_b = (_a = this.getCurrentRoute()) === null || _a === void 0 ? void 0 : _a.config) !== null && _b !== void 0 ? _b : {};
14
+ getConfig(route = this.getCurrentRoute()) {
15
+ var _a;
16
+ return (_a = route === null || route === void 0 ? void 0 : route.config) !== null && _a !== void 0 ? _a : {};
17
17
  }
18
- getContent() {
18
+ getContent(route) {
19
19
  var _a;
20
- return (_a = this.getConfig().content) !== null && _a !== void 0 ? _a : {};
20
+ return (_a = this.getConfig(route).content) !== null && _a !== void 0 ? _a : {};
21
21
  }
22
- getMeta() {
22
+ getMeta(route) {
23
23
  var _a;
24
- return (_a = this.getConfig().meta) !== null && _a !== void 0 ? _a : {};
24
+ return (_a = this.getConfig(route).meta) !== null && _a !== void 0 ? _a : {};
25
25
  }
26
26
  navigate(options) {
27
27
  return this.router.navigate(options);
@@ -38,23 +38,23 @@ class PageService {
38
38
  go(to, options) {
39
39
  return this.router.go(to, options);
40
40
  }
41
- addComponent(name, component) {
42
- const group = this.getComponentsGroupName();
41
+ addComponent(name, component, route) {
42
+ const group = this.getComponentsGroupName(route);
43
43
  return this.componentRegistry.add(name, component, group);
44
44
  }
45
- getComponent(name) {
46
- const group = this.getComponentsGroupName();
45
+ getComponent(name, route) {
46
+ const group = this.getComponentsGroupName(route);
47
47
  return this.componentRegistry.get(name, group);
48
48
  }
49
- resolveComponentFromConfig(property) {
49
+ resolveComponentFromConfig(property, route) {
50
50
  var _a;
51
51
  const configName = `${property}Component`;
52
52
  const defaultComponent = `${property}Default`;
53
- const componentName = (_a = this.getConfig()[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
54
- return this.getComponent(componentName) || this.getComponent(defaultComponent);
53
+ const componentName = (_a = this.getConfig(route)[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
54
+ return this.getComponent(componentName, route) || this.getComponent(defaultComponent, route);
55
55
  }
56
- getComponentsGroupName() {
57
- const { bundle, pageComponent } = this.getConfig();
56
+ getComponentsGroupName(route) {
57
+ const { bundle, pageComponent } = this.getConfig(route);
58
58
  const group = isFileSystemPageComponent(pageComponent) ? pageComponent : bundle;
59
59
  return group;
60
60
  }
@@ -15,17 +15,17 @@ class PageService {
15
15
  getCurrentUrl() {
16
16
  return this.router.getCurrentUrl();
17
17
  }
18
- getConfig() {
19
- var _a, _b;
20
- return (_b = (_a = this.getCurrentRoute()) === null || _a === void 0 ? void 0 : _a.config) !== null && _b !== void 0 ? _b : {};
18
+ getConfig(route = this.getCurrentRoute()) {
19
+ var _a;
20
+ return (_a = route === null || route === void 0 ? void 0 : route.config) !== null && _a !== void 0 ? _a : {};
21
21
  }
22
- getContent() {
22
+ getContent(route) {
23
23
  var _a;
24
- return (_a = this.getConfig().content) !== null && _a !== void 0 ? _a : {};
24
+ return (_a = this.getConfig(route).content) !== null && _a !== void 0 ? _a : {};
25
25
  }
26
- getMeta() {
26
+ getMeta(route) {
27
27
  var _a;
28
- return (_a = this.getConfig().meta) !== null && _a !== void 0 ? _a : {};
28
+ return (_a = this.getConfig(route).meta) !== null && _a !== void 0 ? _a : {};
29
29
  }
30
30
  navigate(options) {
31
31
  return this.router.navigate(options);
@@ -42,23 +42,23 @@ class PageService {
42
42
  go(to, options) {
43
43
  return this.router.go(to, options);
44
44
  }
45
- addComponent(name, component) {
46
- const group = this.getComponentsGroupName();
45
+ addComponent(name, component, route) {
46
+ const group = this.getComponentsGroupName(route);
47
47
  return this.componentRegistry.add(name, component, group);
48
48
  }
49
- getComponent(name) {
50
- const group = this.getComponentsGroupName();
49
+ getComponent(name, route) {
50
+ const group = this.getComponentsGroupName(route);
51
51
  return this.componentRegistry.get(name, group);
52
52
  }
53
- resolveComponentFromConfig(property) {
53
+ resolveComponentFromConfig(property, route) {
54
54
  var _a;
55
55
  const configName = `${property}Component`;
56
56
  const defaultComponent = `${property}Default`;
57
- const componentName = (_a = this.getConfig()[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
58
- return this.getComponent(componentName) || this.getComponent(defaultComponent);
57
+ const componentName = (_a = this.getConfig(route)[configName]) !== null && _a !== void 0 ? _a : defaultComponent;
58
+ return this.getComponent(componentName, route) || this.getComponent(defaultComponent, route);
59
59
  }
60
- getComponentsGroupName() {
61
- const { bundle, pageComponent } = this.getConfig();
60
+ getComponentsGroupName(route) {
61
+ const { bundle, pageComponent } = this.getConfig(route);
62
62
  const group = experiments.isFileSystemPageComponent(pageComponent) ? pageComponent : bundle;
63
63
  return group;
64
64
  }