@equinor/fusion-framework-module-navigation 6.0.1 → 7.0.0-next.2
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/CHANGELOG.md +83 -5
- package/README.md +694 -0
- package/dist/esm/NavigationConfigurator.interface.js +2 -0
- package/dist/esm/NavigationConfigurator.interface.js.map +1 -0
- package/dist/esm/NavigationConfigurator.js +144 -0
- package/dist/esm/NavigationConfigurator.js.map +1 -0
- package/dist/esm/NavigationProvider.interface.js +2 -0
- package/dist/esm/NavigationProvider.interface.js.map +1 -0
- package/dist/esm/NavigationProvider.js +256 -0
- package/dist/esm/NavigationProvider.js.map +1 -0
- package/dist/esm/enable-navigation.js +52 -0
- package/dist/esm/enable-navigation.js.map +1 -0
- package/dist/esm/events.js +23 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/index.js +6 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/BaseHistory.js +189 -0
- package/dist/esm/lib/BaseHistory.js.map +1 -0
- package/dist/esm/lib/BrowserHistory.js +91 -0
- package/dist/esm/lib/BrowserHistory.js.map +1 -0
- package/dist/esm/lib/BrowserHistoryHashStack.js +53 -0
- package/dist/esm/lib/BrowserHistoryHashStack.js.map +1 -0
- package/dist/esm/lib/BrowserHistoryStack.js +77 -0
- package/dist/esm/lib/BrowserHistoryStack.js.map +1 -0
- package/dist/esm/lib/MemoryHistory.js +47 -0
- package/dist/esm/lib/MemoryHistory.js.map +1 -0
- package/dist/esm/lib/MemoryStack.js +98 -0
- package/dist/esm/lib/MemoryStack.js.map +1 -0
- package/dist/esm/lib/create-history.js +48 -0
- package/dist/esm/lib/create-history.js.map +1 -0
- package/dist/esm/lib/index.js +8 -1
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/esm/lib/state/history.actions.js +71 -0
- package/dist/esm/lib/state/history.actions.js.map +1 -0
- package/dist/esm/lib/state/history.flows.js +212 -0
- package/dist/esm/lib/state/history.flows.js.map +1 -0
- package/dist/esm/lib/state/history.reducer.js +59 -0
- package/dist/esm/lib/state/history.reducer.js.map +1 -0
- package/dist/esm/lib/state/history.state.js +37 -0
- package/dist/esm/lib/state/history.state.js.map +1 -0
- package/dist/esm/lib/state/index.js +4 -0
- package/dist/esm/lib/state/index.js.map +1 -0
- package/dist/esm/lib/types.js +25 -0
- package/dist/esm/lib/types.js.map +1 -0
- package/dist/esm/lib/utils/encode-trailing-whitespace.js +19 -0
- package/dist/esm/lib/utils/encode-trailing-whitespace.js.map +1 -0
- package/dist/esm/lib/utils/has-protocol.js +22 -0
- package/dist/esm/lib/utils/has-protocol.js.map +1 -0
- package/dist/esm/lib/utils/index.js +6 -0
- package/dist/esm/lib/utils/index.js.map +1 -0
- package/dist/esm/lib/utils/path-to-string.js +23 -0
- package/dist/esm/lib/utils/path-to-string.js.map +1 -0
- package/dist/esm/lib/utils/path-to-url.js +47 -0
- package/dist/esm/lib/utils/path-to-url.js.map +1 -0
- package/dist/esm/lib/utils/resolve-browser-location.js +53 -0
- package/dist/esm/lib/utils/resolve-browser-location.js.map +1 -0
- package/dist/esm/lib/utils/resolve-path.js +21 -0
- package/dist/esm/lib/utils/resolve-path.js.map +1 -0
- package/dist/esm/module.js +34 -25
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/NavigationConfigurator.d.ts +60 -0
- package/dist/types/NavigationConfigurator.interface.d.ts +17 -0
- package/dist/types/NavigationProvider.d.ts +112 -0
- package/dist/types/NavigationProvider.interface.d.ts +75 -0
- package/dist/types/enable-navigation.d.ts +40 -0
- package/dist/types/events.d.ts +48 -0
- package/dist/types/index.d.ts +13 -6
- package/dist/types/lib/BaseHistory.d.ts +122 -0
- package/dist/types/lib/BrowserHistory.d.ts +53 -0
- package/dist/types/lib/BrowserHistoryHashStack.d.ts +41 -0
- package/dist/types/lib/BrowserHistoryStack.d.ts +51 -0
- package/dist/types/lib/MemoryHistory.d.ts +27 -0
- package/dist/types/lib/MemoryStack.d.ts +57 -0
- package/dist/types/lib/create-history.d.ts +35 -0
- package/dist/types/lib/index.d.ts +7 -1
- package/dist/types/lib/state/history.actions.d.ts +61 -0
- package/dist/types/lib/state/history.flows.d.ts +102 -0
- package/dist/types/lib/state/history.reducer.d.ts +85 -0
- package/dist/types/lib/state/history.state.d.ts +27 -0
- package/dist/types/lib/state/index.d.ts +3 -0
- package/dist/types/lib/types.d.ts +145 -0
- package/dist/types/lib/utils/encode-trailing-whitespace.d.ts +16 -0
- package/dist/types/lib/utils/has-protocol.d.ts +19 -0
- package/dist/types/lib/utils/index.d.ts +5 -0
- package/dist/types/lib/utils/path-to-string.d.ts +17 -0
- package/dist/types/lib/utils/path-to-url.d.ts +32 -0
- package/dist/types/lib/utils/resolve-browser-location.d.ts +42 -0
- package/dist/types/lib/utils/resolve-path.d.ts +17 -0
- package/dist/types/module.d.ts +33 -5
- package/dist/types/version.d.ts +1 -1
- package/package.json +25 -7
- package/src/NavigationConfigurator.interface.ts +18 -0
- package/src/NavigationConfigurator.ts +184 -0
- package/src/NavigationProvider.interface.ts +86 -0
- package/src/NavigationProvider.ts +313 -0
- package/src/__tests__/BrowserHistory.test.ts +151 -0
- package/src/__tests__/HashHistory.test.ts +121 -0
- package/src/__tests__/MemoryHistory.test.ts +185 -0
- package/src/__tests__/NavigationProvider.test.ts +60 -0
- package/src/__tests__/setup.ts +8 -0
- package/src/enable-navigation.ts +59 -0
- package/src/events.ts +65 -0
- package/src/index.ts +27 -6
- package/src/lib/BaseHistory.ts +229 -0
- package/src/lib/BrowserHistory.ts +123 -0
- package/src/lib/BrowserHistoryHashStack.ts +56 -0
- package/src/lib/BrowserHistoryStack.ts +82 -0
- package/src/lib/MemoryHistory.ts +66 -0
- package/src/lib/MemoryStack.ts +106 -0
- package/src/lib/create-history.ts +63 -0
- package/src/lib/index.ts +22 -1
- package/src/lib/state/history.actions.ts +108 -0
- package/src/lib/state/history.flows.ts +279 -0
- package/src/lib/state/history.reducer.ts +70 -0
- package/src/lib/state/history.state.ts +62 -0
- package/src/lib/state/index.ts +3 -0
- package/src/lib/types.ts +159 -0
- package/src/lib/utils/encode-trailing-whitespace.ts +18 -0
- package/src/lib/utils/has-protocol.ts +21 -0
- package/src/lib/utils/index.ts +5 -0
- package/src/lib/utils/path-to-string.ts +24 -0
- package/src/lib/utils/path-to-url.ts +52 -0
- package/src/lib/utils/resolve-browser-location.ts +60 -0
- package/src/lib/utils/resolve-path.ts +22 -0
- package/src/module.ts +53 -37
- package/src/version.ts +1 -1
- package/tsconfig.json +10 -1
- package/vitest.config.ts +14 -0
- package/dist/esm/configurator.js +0 -5
- package/dist/esm/configurator.js.map +0 -1
- package/dist/esm/createHistory.js +0 -18
- package/dist/esm/createHistory.js.map +0 -1
- package/dist/esm/lib/provider/INavigationProvider.js +0 -2
- package/dist/esm/lib/provider/INavigationProvider.js.map +0 -1
- package/dist/esm/lib/provider/NavigationProvider.js +0 -82
- package/dist/esm/lib/provider/NavigationProvider.js.map +0 -1
- package/dist/esm/lib/provider/index.js +0 -2
- package/dist/esm/lib/provider/index.js.map +0 -1
- package/dist/esm/navigator.js +0 -158
- package/dist/esm/navigator.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/types/configurator.d.ts +0 -9
- package/dist/types/createHistory.d.ts +0 -4
- package/dist/types/lib/provider/INavigationProvider.d.ts +0 -38
- package/dist/types/lib/provider/NavigationProvider.d.ts +0 -22
- package/dist/types/lib/provider/index.d.ts +0 -2
- package/dist/types/navigator.d.ts +0 -105
- package/dist/types/types.d.ts +0 -3
- package/src/configurator.ts +0 -11
- package/src/createHistory.ts +0 -21
- package/src/lib/provider/INavigationProvider.ts +0 -46
- package/src/lib/provider/NavigationProvider.ts +0 -117
- package/src/lib/provider/index.ts +0 -2
- package/src/navigator.ts +0 -204
- package/src/types.ts +0 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Path, To } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a 'to' value into a Path object.
|
|
4
|
+
*
|
|
5
|
+
* @param to - The target path (string, Path object, or Location object)
|
|
6
|
+
* @returns A Path object with the pathname, search, and hash components
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* resolvePath('/users?id=1#section')
|
|
11
|
+
* // { pathname: '/users', search: '?id=1', hash: '#section' }
|
|
12
|
+
*
|
|
13
|
+
* resolvePath({ pathname: '/users', search: 'id=1', hash: 'section' })
|
|
14
|
+
* // { pathname: '/users', search: '?id=1', hash: '#section' }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const resolvePath: (to: To) => Path;
|
package/dist/types/module.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { type Module } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { NavigationConfigurator } from './NavigationConfigurator';
|
|
3
|
+
import type { INavigationProvider } from './NavigationProvider.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Module key identifier for the navigation module.
|
|
6
|
+
*/
|
|
4
7
|
export declare const moduleKey = "navigation";
|
|
5
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Type definition for the navigation module.
|
|
10
|
+
*
|
|
11
|
+
* This is the main type definition for the navigation module. It represents the complete
|
|
12
|
+
* module structure with its key identifier, provider interface, and configurator class.
|
|
13
|
+
*
|
|
14
|
+
* The navigation module provides routing and navigation capabilities compatible with
|
|
15
|
+
* industry-standard routers (Remix/React Router), with support for browser history,
|
|
16
|
+
* hash routing, and memory history. It integrates with the Fusion Framework module
|
|
17
|
+
* system and provides a {@link INavigationProvider} instance that can be used to
|
|
18
|
+
* access navigation functionality.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link INavigationProvider} - The provider interface for accessing navigation
|
|
21
|
+
* @see {@link NavigationConfigurator} - The configurator class for setting up navigation
|
|
22
|
+
* @see {@link enableNavigation} - Helper function to enable the navigation module
|
|
23
|
+
* @see {@link module} - The module implementation instance
|
|
24
|
+
*/
|
|
25
|
+
export type NavigationModule = Module<typeof moduleKey, INavigationProvider, NavigationConfigurator>;
|
|
26
|
+
/**
|
|
27
|
+
* Navigation module implementation.
|
|
28
|
+
* Provides routing and navigation capabilities compatible with industry-standard routers (Remix/React Router).
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* - Uses BaseConfigBuilder pattern with Zod validation
|
|
32
|
+
* - Basename must match the URL path prefix where your app is served
|
|
33
|
+
* - The router requires URL pathname to start with the basename
|
|
34
|
+
*/
|
|
6
35
|
export declare const module: NavigationModule;
|
|
7
|
-
export declare const enableNavigation: <TRef = unknown>(configurator: IModulesConfigurator<any, any>, basenameOrOptions?: string | Omit<IModuleConfigurator<NavigationModule, TRef>, "module">) => void;
|
|
8
36
|
export default module;
|
|
9
37
|
declare module '@equinor/fusion-framework-module' {
|
|
10
38
|
interface Modules {
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "7.0.0-next.2";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-navigation",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "7.0.0-next.2",
|
|
4
|
+
"description": "Navigation module for Fusion Framework providing routing and navigation capabilities using React Router 7",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/esm/index.js",
|
|
11
11
|
"types": "./dist/types/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./lib": {
|
|
14
|
+
"import": "./dist/esm/lib/index.js",
|
|
15
|
+
"types": "./dist/types/lib/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./utils": {
|
|
18
|
+
"import": "./dist/esm/utils/index.js",
|
|
19
|
+
"types": "./dist/types/utils/index.d.ts"
|
|
12
20
|
}
|
|
13
21
|
},
|
|
14
22
|
"keywords": [],
|
|
@@ -23,19 +31,29 @@
|
|
|
23
31
|
"directory": "packages/modules/navigation"
|
|
24
32
|
},
|
|
25
33
|
"dependencies": {
|
|
26
|
-
"@remix-run/router": "^1.
|
|
34
|
+
"@remix-run/router": "^1.23.0",
|
|
35
|
+
"uuid": "^13.0.0",
|
|
36
|
+
"zod": "^4.1.11"
|
|
27
37
|
},
|
|
28
38
|
"devDependencies": {
|
|
39
|
+
"@types/uuid": "^11.0.0",
|
|
40
|
+
"jsdom": "^27.1.0",
|
|
29
41
|
"rxjs": "^7.8.1",
|
|
30
42
|
"typescript": "^5.8.2",
|
|
31
|
-
"
|
|
43
|
+
"vitest": "^3.2.4",
|
|
44
|
+
"@equinor/fusion-framework-module": "^5.0.7-next.0",
|
|
45
|
+
"@equinor/fusion-framework-module-event": "^5.0.2-next.0",
|
|
46
|
+
"@equinor/fusion-framework-module-telemetry": "^4.6.5-next.0",
|
|
47
|
+
"@equinor/fusion-observable": "^8.5.9-next.0"
|
|
32
48
|
},
|
|
33
49
|
"peerDependencies": {
|
|
34
|
-
"@remix-run/router": "^1.
|
|
50
|
+
"@remix-run/router": "^1.23.0",
|
|
35
51
|
"rxjs": "^7.0.0",
|
|
36
|
-
"@equinor/fusion-framework-module": "^5.0.
|
|
52
|
+
"@equinor/fusion-framework-module": "^5.0.7-next.0",
|
|
53
|
+
"@equinor/fusion-observable": "^8.5.9-next.0"
|
|
37
54
|
},
|
|
38
55
|
"scripts": {
|
|
39
|
-
"build": "tsc -b"
|
|
56
|
+
"build": "tsc -b",
|
|
57
|
+
"test": "vitest"
|
|
40
58
|
}
|
|
41
59
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { History } from './lib/types';
|
|
2
|
+
import type { ITelemetryProvider } from '@equinor/fusion-framework-module-telemetry';
|
|
3
|
+
import type { IEventModuleProvider } from '@equinor/fusion-framework-module-event';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration object for the navigation module.
|
|
7
|
+
* Provides options for customizing history, basename, telemetry, and event settings.
|
|
8
|
+
*/
|
|
9
|
+
export interface INavigationConfigurator {
|
|
10
|
+
/** Optional base pathname for the application (e.g., "/app") */
|
|
11
|
+
basename?: string;
|
|
12
|
+
/** Optional custom history instance (browser, hash, or memory). If not provided, defaults to browser history. */
|
|
13
|
+
history?: History;
|
|
14
|
+
/** Optional telemetry provider for tracking navigation events */
|
|
15
|
+
telemetry?: ITelemetryProvider;
|
|
16
|
+
/** Optional event provider for dispatching navigation events */
|
|
17
|
+
eventProvider?: IEventModuleProvider;
|
|
18
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { of, type ObservableInput } from 'rxjs';
|
|
3
|
+
import {
|
|
4
|
+
BaseConfigBuilder,
|
|
5
|
+
type ModulesInstance,
|
|
6
|
+
type ConfigBuilderCallback,
|
|
7
|
+
type ConfigBuilderCallbackArgs,
|
|
8
|
+
} from '@equinor/fusion-framework-module';
|
|
9
|
+
import type { ITelemetryProvider } from '@equinor/fusion-framework-module-telemetry';
|
|
10
|
+
import type { IEventModuleProvider } from '@equinor/fusion-framework-module-event';
|
|
11
|
+
import type { INavigationConfigurator } from './NavigationConfigurator.interface';
|
|
12
|
+
|
|
13
|
+
import type { History } from './lib/types';
|
|
14
|
+
import { createHistory } from './lib/create-history';
|
|
15
|
+
import type { NavigationModule } from './module';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Zod schema for navigation module configuration validation.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
const navigationConfigSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
basename: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe(
|
|
28
|
+
'Base pathname for the application (e.g., "/app"). Must match the URL path prefix where your app is served. The router requires the pathname to start with this basename.',
|
|
29
|
+
),
|
|
30
|
+
history: z
|
|
31
|
+
.custom<History>()
|
|
32
|
+
.describe(
|
|
33
|
+
'Custom history instance implementing the History interface. Defaults to browser history if not provided. Use createHistory("browser"|"hash"|"memory") to create instances.',
|
|
34
|
+
),
|
|
35
|
+
telemetry: z
|
|
36
|
+
.custom<ITelemetryProvider>()
|
|
37
|
+
.optional()
|
|
38
|
+
.describe(
|
|
39
|
+
'Telemetry provider for tracking navigation events. Used to log navigation actions, location changes, and errors for monitoring and debugging.',
|
|
40
|
+
),
|
|
41
|
+
eventProvider: z
|
|
42
|
+
.custom<IEventModuleProvider>()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe(
|
|
45
|
+
'Event provider for dispatching navigation events (NavigateEvent, NavigatedEvent). Allows other modules to listen for navigation changes and block navigation attempts.',
|
|
46
|
+
),
|
|
47
|
+
})
|
|
48
|
+
.describe(
|
|
49
|
+
'Validates navigation module configuration settings for routing and navigation capabilities.',
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parses and validates a navigation configuration object.
|
|
54
|
+
*
|
|
55
|
+
* @param config - The configuration object to parse
|
|
56
|
+
* @returns Validated navigation configuration
|
|
57
|
+
* @throws {z.ZodError} If the configuration is invalid
|
|
58
|
+
*/
|
|
59
|
+
const parseNavigationConfig = (config: unknown): INavigationConfigurator => {
|
|
60
|
+
return navigationConfigSchema.parse(config);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Configurator class for navigation module settings.
|
|
65
|
+
* Extends BaseConfigBuilder to provide fluent configuration API with Zod validation.
|
|
66
|
+
*/
|
|
67
|
+
export class NavigationConfigurator extends BaseConfigBuilder<INavigationConfigurator> {
|
|
68
|
+
constructor() {
|
|
69
|
+
super();
|
|
70
|
+
this.setEventProvider(async (args) => {
|
|
71
|
+
if (args.hasModule('event')) {
|
|
72
|
+
return await args.requireInstance('event');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
this.setHistory(async (args) => {
|
|
76
|
+
const history = (args.ref as ModulesInstance<[NavigationModule]>)?.navigation?.history;
|
|
77
|
+
if (history) {
|
|
78
|
+
return history;
|
|
79
|
+
}
|
|
80
|
+
if (typeof window !== 'undefined') {
|
|
81
|
+
return createHistory('browser');
|
|
82
|
+
}
|
|
83
|
+
return createHistory('memory');
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Use `setBasename()` method instead
|
|
88
|
+
*/
|
|
89
|
+
public set basename(value: string | undefined) {
|
|
90
|
+
if (process.env.NODE_ENV === 'development') {
|
|
91
|
+
console.warn('NavigationConfigurator.basename', 'use setBasename() method instead');
|
|
92
|
+
}
|
|
93
|
+
this.setBasename(value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use `setHistory()` method instead
|
|
98
|
+
*/
|
|
99
|
+
public set history(value: History | undefined) {
|
|
100
|
+
if (process.env.NODE_ENV === 'development') {
|
|
101
|
+
console.warn('NavigationConfigurator.history', 'use setHistory() method instead');
|
|
102
|
+
}
|
|
103
|
+
this.setHistory(value);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Sets the basename for the application.
|
|
108
|
+
*
|
|
109
|
+
* @param basenameOrCallback - Basename string or configuration callback
|
|
110
|
+
* @returns The configurator instance for method chaining
|
|
111
|
+
*/
|
|
112
|
+
public setBasename(basenameOrCallback?: string | ConfigBuilderCallback<string>): this {
|
|
113
|
+
const fn =
|
|
114
|
+
typeof basenameOrCallback === 'function'
|
|
115
|
+
? basenameOrCallback
|
|
116
|
+
: async () => basenameOrCallback;
|
|
117
|
+
this._set('basename', fn);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Sets a custom history instance for the navigation module.
|
|
123
|
+
*
|
|
124
|
+
* @param historyOrCallback - History instance or configuration callback
|
|
125
|
+
* @returns The configurator instance for method chaining
|
|
126
|
+
*/
|
|
127
|
+
public setHistory(historyOrCallback?: History | ConfigBuilderCallback<History>): this {
|
|
128
|
+
const fn =
|
|
129
|
+
typeof historyOrCallback === 'function' ? historyOrCallback : async () => historyOrCallback;
|
|
130
|
+
this._set('history', fn);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Sets telemetry configuration for navigation-specific events.
|
|
136
|
+
*
|
|
137
|
+
* @param telemetryOrCallback - Telemetry provider instance or configuration callback
|
|
138
|
+
* @returns The configurator instance for method chaining
|
|
139
|
+
*/
|
|
140
|
+
public setTelemetry(
|
|
141
|
+
telemetryOrCallback: ITelemetryProvider | ConfigBuilderCallback<ITelemetryProvider>,
|
|
142
|
+
): this {
|
|
143
|
+
const fn =
|
|
144
|
+
typeof telemetryOrCallback === 'function'
|
|
145
|
+
? telemetryOrCallback
|
|
146
|
+
: async () => telemetryOrCallback;
|
|
147
|
+
this._set('telemetry', fn);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Sets event provider for dispatching navigation events.
|
|
153
|
+
*
|
|
154
|
+
* @param eventProviderOrCallback - Event provider instance or configuration callback
|
|
155
|
+
* @returns The configurator instance for method chaining
|
|
156
|
+
*/
|
|
157
|
+
public setEventProvider(
|
|
158
|
+
eventProviderOrCallback: IEventModuleProvider | ConfigBuilderCallback<IEventModuleProvider>,
|
|
159
|
+
): this {
|
|
160
|
+
const fn =
|
|
161
|
+
typeof eventProviderOrCallback === 'function'
|
|
162
|
+
? eventProviderOrCallback
|
|
163
|
+
: async () => eventProviderOrCallback;
|
|
164
|
+
this._set('eventProvider', fn);
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Processes and validates the configuration using Zod schema.
|
|
170
|
+
*
|
|
171
|
+
* @param config - Raw configuration object from builder
|
|
172
|
+
* @param _init - Configuration builder callback arguments (unused)
|
|
173
|
+
* @returns Observable that emits validated and processed configuration object
|
|
174
|
+
* @throws {z.ZodError} If the configuration is invalid
|
|
175
|
+
*
|
|
176
|
+
* @protected
|
|
177
|
+
*/
|
|
178
|
+
protected _processConfig(
|
|
179
|
+
config: Partial<INavigationConfigurator>,
|
|
180
|
+
_init: ConfigBuilderCallbackArgs,
|
|
181
|
+
): ObservableInput<INavigationConfigurator> {
|
|
182
|
+
return of(parseNavigationConfig(config));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// TODO: Remove @remix-run/router dependency once all apps have migrated to @equinor/fusion-framework-react-router
|
|
2
|
+
import type { AgnosticRouteObject, Router } from '@remix-run/router';
|
|
3
|
+
|
|
4
|
+
import type { History, NavigateOptions } from './lib/types';
|
|
5
|
+
import type { Action, Path, To } from './lib/types';
|
|
6
|
+
|
|
7
|
+
import type { Observable } from 'rxjs';
|
|
8
|
+
import type { IModuleProvider } from '@equinor/fusion-framework-module';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Navigation provider interface.
|
|
12
|
+
* Provides routing and navigation capabilities with basename localization.
|
|
13
|
+
*/
|
|
14
|
+
export interface INavigationProvider extends IModuleProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Observable stream of navigation state updates.
|
|
17
|
+
* Emits localized paths (with basename removed) for consumers.
|
|
18
|
+
*/
|
|
19
|
+
readonly state$: Observable<{ action: Action; location: Path }>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Gets the basename.
|
|
23
|
+
*/
|
|
24
|
+
readonly basename: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Gets the current localized path (basename removed).
|
|
28
|
+
*/
|
|
29
|
+
readonly path: Path;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `history` instead
|
|
33
|
+
*/
|
|
34
|
+
readonly navigator: History;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the history instance.
|
|
38
|
+
*/
|
|
39
|
+
readonly history: History;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a router instance from route configuration.
|
|
43
|
+
*
|
|
44
|
+
* @param routes - Route configuration objects compatible with industry-standard routers (Remix/React Router)
|
|
45
|
+
* @returns A configured and initialized router instance
|
|
46
|
+
*/
|
|
47
|
+
createRouter(routes: AgnosticRouteObject[]): Router;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a localized href string for navigation.
|
|
51
|
+
*
|
|
52
|
+
* @param to - Optional path or location (defaults to current path)
|
|
53
|
+
*/
|
|
54
|
+
createHref(to?: To): string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a full URL object for navigation.
|
|
58
|
+
*
|
|
59
|
+
* @param to - Optional path or location (defaults to current path)
|
|
60
|
+
*/
|
|
61
|
+
createURL(to?: To): URL;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Navigates to a location with explicit options.
|
|
65
|
+
*
|
|
66
|
+
* @param to - Optional path or location (defaults to current path)
|
|
67
|
+
* @param options - Optional navigation options
|
|
68
|
+
*/
|
|
69
|
+
navigate(to?: To, options?: Partial<NavigateOptions>): void;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Pushes a new navigation entry onto the history stack.
|
|
73
|
+
*
|
|
74
|
+
* @param to - Path or location to navigate to (relative to basename)
|
|
75
|
+
* @param state - Optional state to associate with the navigation
|
|
76
|
+
*/
|
|
77
|
+
push(to: To, state?: unknown): void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Replaces the current history entry with a new one.
|
|
81
|
+
*
|
|
82
|
+
* @param to - Path or location to navigate to (relative to basename)
|
|
83
|
+
* @param state - Optional state to associate with the navigation
|
|
84
|
+
*/
|
|
85
|
+
replace(to: To, state?: unknown): void;
|
|
86
|
+
}
|