@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.
Files changed (159) hide show
  1. package/CHANGELOG.md +83 -5
  2. package/README.md +694 -0
  3. package/dist/esm/NavigationConfigurator.interface.js +2 -0
  4. package/dist/esm/NavigationConfigurator.interface.js.map +1 -0
  5. package/dist/esm/NavigationConfigurator.js +144 -0
  6. package/dist/esm/NavigationConfigurator.js.map +1 -0
  7. package/dist/esm/NavigationProvider.interface.js +2 -0
  8. package/dist/esm/NavigationProvider.interface.js.map +1 -0
  9. package/dist/esm/NavigationProvider.js +256 -0
  10. package/dist/esm/NavigationProvider.js.map +1 -0
  11. package/dist/esm/enable-navigation.js +52 -0
  12. package/dist/esm/enable-navigation.js.map +1 -0
  13. package/dist/esm/events.js +23 -0
  14. package/dist/esm/events.js.map +1 -0
  15. package/dist/esm/index.js +6 -5
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/lib/BaseHistory.js +189 -0
  18. package/dist/esm/lib/BaseHistory.js.map +1 -0
  19. package/dist/esm/lib/BrowserHistory.js +91 -0
  20. package/dist/esm/lib/BrowserHistory.js.map +1 -0
  21. package/dist/esm/lib/BrowserHistoryHashStack.js +53 -0
  22. package/dist/esm/lib/BrowserHistoryHashStack.js.map +1 -0
  23. package/dist/esm/lib/BrowserHistoryStack.js +77 -0
  24. package/dist/esm/lib/BrowserHistoryStack.js.map +1 -0
  25. package/dist/esm/lib/MemoryHistory.js +47 -0
  26. package/dist/esm/lib/MemoryHistory.js.map +1 -0
  27. package/dist/esm/lib/MemoryStack.js +98 -0
  28. package/dist/esm/lib/MemoryStack.js.map +1 -0
  29. package/dist/esm/lib/create-history.js +48 -0
  30. package/dist/esm/lib/create-history.js.map +1 -0
  31. package/dist/esm/lib/index.js +8 -1
  32. package/dist/esm/lib/index.js.map +1 -1
  33. package/dist/esm/lib/state/history.actions.js +71 -0
  34. package/dist/esm/lib/state/history.actions.js.map +1 -0
  35. package/dist/esm/lib/state/history.flows.js +212 -0
  36. package/dist/esm/lib/state/history.flows.js.map +1 -0
  37. package/dist/esm/lib/state/history.reducer.js +59 -0
  38. package/dist/esm/lib/state/history.reducer.js.map +1 -0
  39. package/dist/esm/lib/state/history.state.js +37 -0
  40. package/dist/esm/lib/state/history.state.js.map +1 -0
  41. package/dist/esm/lib/state/index.js +4 -0
  42. package/dist/esm/lib/state/index.js.map +1 -0
  43. package/dist/esm/lib/types.js +25 -0
  44. package/dist/esm/lib/types.js.map +1 -0
  45. package/dist/esm/lib/utils/encode-trailing-whitespace.js +19 -0
  46. package/dist/esm/lib/utils/encode-trailing-whitespace.js.map +1 -0
  47. package/dist/esm/lib/utils/has-protocol.js +22 -0
  48. package/dist/esm/lib/utils/has-protocol.js.map +1 -0
  49. package/dist/esm/lib/utils/index.js +6 -0
  50. package/dist/esm/lib/utils/index.js.map +1 -0
  51. package/dist/esm/lib/utils/path-to-string.js +23 -0
  52. package/dist/esm/lib/utils/path-to-string.js.map +1 -0
  53. package/dist/esm/lib/utils/path-to-url.js +47 -0
  54. package/dist/esm/lib/utils/path-to-url.js.map +1 -0
  55. package/dist/esm/lib/utils/resolve-browser-location.js +53 -0
  56. package/dist/esm/lib/utils/resolve-browser-location.js.map +1 -0
  57. package/dist/esm/lib/utils/resolve-path.js +21 -0
  58. package/dist/esm/lib/utils/resolve-path.js.map +1 -0
  59. package/dist/esm/module.js +34 -25
  60. package/dist/esm/module.js.map +1 -1
  61. package/dist/esm/version.js +1 -1
  62. package/dist/esm/version.js.map +1 -1
  63. package/dist/tsconfig.tsbuildinfo +1 -1
  64. package/dist/types/NavigationConfigurator.d.ts +60 -0
  65. package/dist/types/NavigationConfigurator.interface.d.ts +17 -0
  66. package/dist/types/NavigationProvider.d.ts +112 -0
  67. package/dist/types/NavigationProvider.interface.d.ts +75 -0
  68. package/dist/types/enable-navigation.d.ts +40 -0
  69. package/dist/types/events.d.ts +48 -0
  70. package/dist/types/index.d.ts +13 -6
  71. package/dist/types/lib/BaseHistory.d.ts +122 -0
  72. package/dist/types/lib/BrowserHistory.d.ts +53 -0
  73. package/dist/types/lib/BrowserHistoryHashStack.d.ts +41 -0
  74. package/dist/types/lib/BrowserHistoryStack.d.ts +51 -0
  75. package/dist/types/lib/MemoryHistory.d.ts +27 -0
  76. package/dist/types/lib/MemoryStack.d.ts +57 -0
  77. package/dist/types/lib/create-history.d.ts +35 -0
  78. package/dist/types/lib/index.d.ts +7 -1
  79. package/dist/types/lib/state/history.actions.d.ts +61 -0
  80. package/dist/types/lib/state/history.flows.d.ts +102 -0
  81. package/dist/types/lib/state/history.reducer.d.ts +85 -0
  82. package/dist/types/lib/state/history.state.d.ts +27 -0
  83. package/dist/types/lib/state/index.d.ts +3 -0
  84. package/dist/types/lib/types.d.ts +145 -0
  85. package/dist/types/lib/utils/encode-trailing-whitespace.d.ts +16 -0
  86. package/dist/types/lib/utils/has-protocol.d.ts +19 -0
  87. package/dist/types/lib/utils/index.d.ts +5 -0
  88. package/dist/types/lib/utils/path-to-string.d.ts +17 -0
  89. package/dist/types/lib/utils/path-to-url.d.ts +32 -0
  90. package/dist/types/lib/utils/resolve-browser-location.d.ts +42 -0
  91. package/dist/types/lib/utils/resolve-path.d.ts +17 -0
  92. package/dist/types/module.d.ts +33 -5
  93. package/dist/types/version.d.ts +1 -1
  94. package/package.json +25 -7
  95. package/src/NavigationConfigurator.interface.ts +18 -0
  96. package/src/NavigationConfigurator.ts +184 -0
  97. package/src/NavigationProvider.interface.ts +86 -0
  98. package/src/NavigationProvider.ts +313 -0
  99. package/src/__tests__/BrowserHistory.test.ts +151 -0
  100. package/src/__tests__/HashHistory.test.ts +121 -0
  101. package/src/__tests__/MemoryHistory.test.ts +185 -0
  102. package/src/__tests__/NavigationProvider.test.ts +60 -0
  103. package/src/__tests__/setup.ts +8 -0
  104. package/src/enable-navigation.ts +59 -0
  105. package/src/events.ts +65 -0
  106. package/src/index.ts +27 -6
  107. package/src/lib/BaseHistory.ts +229 -0
  108. package/src/lib/BrowserHistory.ts +123 -0
  109. package/src/lib/BrowserHistoryHashStack.ts +56 -0
  110. package/src/lib/BrowserHistoryStack.ts +82 -0
  111. package/src/lib/MemoryHistory.ts +66 -0
  112. package/src/lib/MemoryStack.ts +106 -0
  113. package/src/lib/create-history.ts +63 -0
  114. package/src/lib/index.ts +22 -1
  115. package/src/lib/state/history.actions.ts +108 -0
  116. package/src/lib/state/history.flows.ts +279 -0
  117. package/src/lib/state/history.reducer.ts +70 -0
  118. package/src/lib/state/history.state.ts +62 -0
  119. package/src/lib/state/index.ts +3 -0
  120. package/src/lib/types.ts +159 -0
  121. package/src/lib/utils/encode-trailing-whitespace.ts +18 -0
  122. package/src/lib/utils/has-protocol.ts +21 -0
  123. package/src/lib/utils/index.ts +5 -0
  124. package/src/lib/utils/path-to-string.ts +24 -0
  125. package/src/lib/utils/path-to-url.ts +52 -0
  126. package/src/lib/utils/resolve-browser-location.ts +60 -0
  127. package/src/lib/utils/resolve-path.ts +22 -0
  128. package/src/module.ts +53 -37
  129. package/src/version.ts +1 -1
  130. package/tsconfig.json +10 -1
  131. package/vitest.config.ts +14 -0
  132. package/dist/esm/configurator.js +0 -5
  133. package/dist/esm/configurator.js.map +0 -1
  134. package/dist/esm/createHistory.js +0 -18
  135. package/dist/esm/createHistory.js.map +0 -1
  136. package/dist/esm/lib/provider/INavigationProvider.js +0 -2
  137. package/dist/esm/lib/provider/INavigationProvider.js.map +0 -1
  138. package/dist/esm/lib/provider/NavigationProvider.js +0 -82
  139. package/dist/esm/lib/provider/NavigationProvider.js.map +0 -1
  140. package/dist/esm/lib/provider/index.js +0 -2
  141. package/dist/esm/lib/provider/index.js.map +0 -1
  142. package/dist/esm/navigator.js +0 -158
  143. package/dist/esm/navigator.js.map +0 -1
  144. package/dist/esm/types.js +0 -2
  145. package/dist/esm/types.js.map +0 -1
  146. package/dist/types/configurator.d.ts +0 -9
  147. package/dist/types/createHistory.d.ts +0 -4
  148. package/dist/types/lib/provider/INavigationProvider.d.ts +0 -38
  149. package/dist/types/lib/provider/NavigationProvider.d.ts +0 -22
  150. package/dist/types/lib/provider/index.d.ts +0 -2
  151. package/dist/types/navigator.d.ts +0 -105
  152. package/dist/types/types.d.ts +0 -3
  153. package/src/configurator.ts +0 -11
  154. package/src/createHistory.ts +0 -21
  155. package/src/lib/provider/INavigationProvider.ts +0 -46
  156. package/src/lib/provider/NavigationProvider.ts +0 -117
  157. package/src/lib/provider/index.ts +0 -2
  158. package/src/navigator.ts +0 -204
  159. package/src/types.ts +0 -4
@@ -0,0 +1,60 @@
1
+ import { type ObservableInput } from 'rxjs';
2
+ import { BaseConfigBuilder, type ConfigBuilderCallback, type ConfigBuilderCallbackArgs } from '@equinor/fusion-framework-module';
3
+ import type { ITelemetryProvider } from '@equinor/fusion-framework-module-telemetry';
4
+ import type { IEventModuleProvider } from '@equinor/fusion-framework-module-event';
5
+ import type { INavigationConfigurator } from './NavigationConfigurator.interface';
6
+ import type { History } from './lib/types';
7
+ /**
8
+ * Configurator class for navigation module settings.
9
+ * Extends BaseConfigBuilder to provide fluent configuration API with Zod validation.
10
+ */
11
+ export declare class NavigationConfigurator extends BaseConfigBuilder<INavigationConfigurator> {
12
+ constructor();
13
+ /**
14
+ * @deprecated Use `setBasename()` method instead
15
+ */
16
+ set basename(value: string | undefined);
17
+ /**
18
+ * @deprecated Use `setHistory()` method instead
19
+ */
20
+ set history(value: History | undefined);
21
+ /**
22
+ * Sets the basename for the application.
23
+ *
24
+ * @param basenameOrCallback - Basename string or configuration callback
25
+ * @returns The configurator instance for method chaining
26
+ */
27
+ setBasename(basenameOrCallback?: string | ConfigBuilderCallback<string>): this;
28
+ /**
29
+ * Sets a custom history instance for the navigation module.
30
+ *
31
+ * @param historyOrCallback - History instance or configuration callback
32
+ * @returns The configurator instance for method chaining
33
+ */
34
+ setHistory(historyOrCallback?: History | ConfigBuilderCallback<History>): this;
35
+ /**
36
+ * Sets telemetry configuration for navigation-specific events.
37
+ *
38
+ * @param telemetryOrCallback - Telemetry provider instance or configuration callback
39
+ * @returns The configurator instance for method chaining
40
+ */
41
+ setTelemetry(telemetryOrCallback: ITelemetryProvider | ConfigBuilderCallback<ITelemetryProvider>): this;
42
+ /**
43
+ * Sets event provider for dispatching navigation events.
44
+ *
45
+ * @param eventProviderOrCallback - Event provider instance or configuration callback
46
+ * @returns The configurator instance for method chaining
47
+ */
48
+ setEventProvider(eventProviderOrCallback: IEventModuleProvider | ConfigBuilderCallback<IEventModuleProvider>): this;
49
+ /**
50
+ * Processes and validates the configuration using Zod schema.
51
+ *
52
+ * @param config - Raw configuration object from builder
53
+ * @param _init - Configuration builder callback arguments (unused)
54
+ * @returns Observable that emits validated and processed configuration object
55
+ * @throws {z.ZodError} If the configuration is invalid
56
+ *
57
+ * @protected
58
+ */
59
+ protected _processConfig(config: Partial<INavigationConfigurator>, _init: ConfigBuilderCallbackArgs): ObservableInput<INavigationConfigurator>;
60
+ }
@@ -0,0 +1,17 @@
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
+ * Configuration object for the navigation module.
6
+ * Provides options for customizing history, basename, telemetry, and event settings.
7
+ */
8
+ export interface INavigationConfigurator {
9
+ /** Optional base pathname for the application (e.g., "/app") */
10
+ basename?: string;
11
+ /** Optional custom history instance (browser, hash, or memory). If not provided, defaults to browser history. */
12
+ history?: History;
13
+ /** Optional telemetry provider for tracking navigation events */
14
+ telemetry?: ITelemetryProvider;
15
+ /** Optional event provider for dispatching navigation events */
16
+ eventProvider?: IEventModuleProvider;
17
+ }
@@ -0,0 +1,112 @@
1
+ import { type AgnosticRouteObject } from '@remix-run/router';
2
+ import type { Observable } from 'rxjs';
3
+ import { BaseModuleProvider, type BaseModuleProviderCtorArgs } from '@equinor/fusion-framework-module/provider';
4
+ import type { INavigationProvider } from './NavigationProvider.interface';
5
+ import type { INavigationConfigurator } from './NavigationConfigurator.interface';
6
+ import type { History, NavigateOptions, NavigationUpdate, Path, To } from './lib/types';
7
+ /**
8
+ * Navigation provider implementation.
9
+ * Manages routing and navigation state with basename localization.
10
+ *
11
+ * @remarks
12
+ * This provider:
13
+ * - Wraps the Navigator to provide observable navigation state
14
+ * - Localizes paths by removing basename prefix
15
+ * - Creates routers compatible with industry-standard routers (Remix/React Router)
16
+ * - Handles navigation actions (push, replace, createHref, etc.)
17
+ *
18
+ * Path localization ensures that consumers receive paths relative to the basename,
19
+ * while internally we work with full paths including basename.
20
+ */
21
+ export declare class NavigationProvider extends BaseModuleProvider<INavigationConfigurator> implements INavigationProvider {
22
+ #private;
23
+ /**
24
+ * Observable stream of navigation state updates.
25
+ * Emits localized paths (with basename removed) for consumers.
26
+ */
27
+ get state$(): Observable<NavigationUpdate>;
28
+ /**
29
+ * Gets the basename.
30
+ */
31
+ get basename(): string;
32
+ /**
33
+ * @deprecated Use `history` instead
34
+ */
35
+ get navigator(): History;
36
+ /**
37
+ * Gets the history instance.
38
+ */
39
+ get history(): History;
40
+ /**
41
+ * Gets the current localized path (basename removed).
42
+ */
43
+ get path(): Path;
44
+ /**
45
+ * @param args - Configuration arguments containing module config
46
+ * @throws {Error} If no history is provided in the configuration
47
+ */
48
+ constructor(args: BaseModuleProviderCtorArgs<INavigationConfigurator>);
49
+ /**
50
+ * Sets up navigation subscriptions for events and telemetry.
51
+ *
52
+ * Configures subscriptions for:
53
+ * - NavigatedEvent dispatching when navigation changes
54
+ * - Telemetry tracking for navigation actions and events
55
+ * - History disposal cleanup
56
+ */
57
+ protected _initialize(): void;
58
+ /**
59
+ * Creates a router instance from route configuration.
60
+ *
61
+ * @deprecated Use `@equinor/fusion-framework-react-router` instead
62
+ *
63
+ * @param routes - Route configuration objects compatible with industry-standard routers (Remix/React Router)
64
+ * @returns A configured and initialized router instance
65
+ */
66
+ createRouter(routes: AgnosticRouteObject[]): import("@remix-run/router").Router;
67
+ /**
68
+ * Creates a localized href string for navigation.
69
+ *
70
+ * @param to - Optional path or location (defaults to current path)
71
+ */
72
+ createHref(to?: To): string;
73
+ /**
74
+ * Creates a full URL object for navigation.
75
+ *
76
+ * @param to - Optional path or location (defaults to current path)
77
+ */
78
+ createURL(to?: To): URL;
79
+ /**
80
+ * Pushes a new navigation entry onto the history stack.
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
+ push(to: To, state?: unknown): void;
86
+ /**
87
+ * Replaces the current history entry with a new one.
88
+ *
89
+ * @param to - Path or location to navigate to (relative to basename)
90
+ * @param state - Optional state to associate with the navigation
91
+ */
92
+ replace(to: To, state?: unknown): void;
93
+ /**
94
+ * Navigate to a location with explicit options.
95
+ *
96
+ * @param to - Optional path or location (defaults to current path)
97
+ * @param options - Optional navigation options
98
+ */
99
+ navigate(to?: To, options?: Partial<NavigateOptions>): void;
100
+ /**
101
+ * Checks if a pathname is within the basename scope.
102
+ */
103
+ protected _isWithinBasenameScope(pathname: string): boolean;
104
+ /**
105
+ * Localizes a path by removing the basename prefix.
106
+ */
107
+ protected _localizePath(location: Path): Path;
108
+ /**
109
+ * Creates a full path object from a target location, adding basename prefix.
110
+ */
111
+ protected _createToPath(to: To): Partial<Path>;
112
+ }
@@ -0,0 +1,75 @@
1
+ import type { AgnosticRouteObject, Router } from '@remix-run/router';
2
+ import type { History, NavigateOptions } from './lib/types';
3
+ import type { Action, Path, To } from './lib/types';
4
+ import type { Observable } from 'rxjs';
5
+ import type { IModuleProvider } from '@equinor/fusion-framework-module';
6
+ /**
7
+ * Navigation provider interface.
8
+ * Provides routing and navigation capabilities with basename localization.
9
+ */
10
+ export interface INavigationProvider extends IModuleProvider {
11
+ /**
12
+ * Observable stream of navigation state updates.
13
+ * Emits localized paths (with basename removed) for consumers.
14
+ */
15
+ readonly state$: Observable<{
16
+ action: Action;
17
+ location: Path;
18
+ }>;
19
+ /**
20
+ * Gets the basename.
21
+ */
22
+ readonly basename: string;
23
+ /**
24
+ * Gets the current localized path (basename removed).
25
+ */
26
+ readonly path: Path;
27
+ /**
28
+ * @deprecated Use `history` instead
29
+ */
30
+ readonly navigator: History;
31
+ /**
32
+ * Gets the history instance.
33
+ */
34
+ readonly history: History;
35
+ /**
36
+ * Creates a router instance from route configuration.
37
+ *
38
+ * @param routes - Route configuration objects compatible with industry-standard routers (Remix/React Router)
39
+ * @returns A configured and initialized router instance
40
+ */
41
+ createRouter(routes: AgnosticRouteObject[]): Router;
42
+ /**
43
+ * Creates a localized href string for navigation.
44
+ *
45
+ * @param to - Optional path or location (defaults to current path)
46
+ */
47
+ createHref(to?: To): string;
48
+ /**
49
+ * Creates a full URL object for navigation.
50
+ *
51
+ * @param to - Optional path or location (defaults to current path)
52
+ */
53
+ createURL(to?: To): URL;
54
+ /**
55
+ * Navigates to a location with explicit options.
56
+ *
57
+ * @param to - Optional path or location (defaults to current path)
58
+ * @param options - Optional navigation options
59
+ */
60
+ navigate(to?: To, options?: Partial<NavigateOptions>): void;
61
+ /**
62
+ * Pushes a new navigation entry onto the history stack.
63
+ *
64
+ * @param to - Path or location to navigate to (relative to basename)
65
+ * @param state - Optional state to associate with the navigation
66
+ */
67
+ push(to: To, state?: unknown): void;
68
+ /**
69
+ * Replaces the current history entry with a new one.
70
+ *
71
+ * @param to - Path or location to navigate to (relative to basename)
72
+ * @param state - Optional state to associate with the navigation
73
+ */
74
+ replace(to: To, state?: unknown): void;
75
+ }
@@ -0,0 +1,40 @@
1
+ import type { IModulesConfigurator, ModuleConfigType } from '@equinor/fusion-framework-module';
2
+ import { type NavigationModule } from './module';
3
+ /**
4
+ * Helper function to enable the navigation module.
5
+ *
6
+ * This is the main entry point for consumers to add navigation capabilities to their
7
+ * framework configuration. It registers the navigation module and allows configuration
8
+ * of basename and other navigation settings.
9
+ *
10
+ * The navigation module provides routing and navigation capabilities compatible with
11
+ * industry-standard routers (Remix/React Router), with support for browser history,
12
+ * hash routing, and memory history.
13
+ *
14
+ * @param configurator - The modules configurator to add navigation to
15
+ * @param basenameOrOptions - Optional basename string or configuration object
16
+ * @param basenameOrOptions.configure - Configuration callback for advanced setup
17
+ * @typeParam TRef - Reference type for module composition
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Simple usage with basename
22
+ * enableNavigation(configurator, '/app');
23
+ *
24
+ * // Advanced configuration
25
+ * enableNavigation(configurator, {
26
+ * configure(config, ref) {
27
+ * config.setBasename('/app');
28
+ * config.setHistory(createHistory('browser'));
29
+ * }
30
+ * });
31
+ * ```
32
+ *
33
+ * @see {@link NavigationModule} - The navigation module type
34
+ * @see {@link INavigationConfigurator} - Configuration interface
35
+ * @see {@link INavigationProvider} - Provider interface for accessing navigation
36
+ */
37
+ export declare const enableNavigation: <TRef = unknown>(configurator: IModulesConfigurator<any, any>, basenameOrOptions?: string | {
38
+ configure: (config: ModuleConfigType<NavigationModule>, ref: TRef) => void;
39
+ }) => void;
40
+ export default enableNavigation;
@@ -0,0 +1,48 @@
1
+ import { FrameworkEvent, type FrameworkEventInit } from '@equinor/fusion-framework-module-event';
2
+ import type { INavigationProvider } from './NavigationProvider.interface';
3
+ import type { Action, NavigationUpdate, Path } from './lib/types';
4
+ /**
5
+ * Event detail for navigation events (before navigation).
6
+ */
7
+ export interface NavigateEventDetail {
8
+ /** The target path or location to navigate to */
9
+ location: NavigationUpdate;
10
+ /** Optional current location before navigation */
11
+ currentLocation?: Path;
12
+ }
13
+ /**
14
+ * Event emitted before navigation occurs.
15
+ * Can be canceled by calling `preventDefault()`.
16
+ */
17
+ export declare class NavigateEvent extends FrameworkEvent<FrameworkEventInit<NavigateEventDetail, INavigationProvider>> {
18
+ constructor(detail: NavigateEventDetail, source: INavigationProvider);
19
+ }
20
+ /**
21
+ * Event detail for navigated events (after navigation).
22
+ */
23
+ export interface NavigatedEventDetail {
24
+ /** The navigation action that occurred (PUSH, POP, REPLACE) */
25
+ action: Action;
26
+ /** The new location after navigation */
27
+ current: NavigationUpdate;
28
+ /** The previous location before navigation */
29
+ previous: NavigationUpdate;
30
+ }
31
+ /**
32
+ * Event emitted after navigation occurs.
33
+ * Contains the navigation action and location details.
34
+ */
35
+ export declare class NavigatedEvent extends FrameworkEvent<FrameworkEventInit<NavigatedEventDetail, INavigationProvider>> {
36
+ constructor(detail: NavigatedEventDetail, source: INavigationProvider);
37
+ }
38
+ /**
39
+ * Declares navigation events in the FrameworkEventMap for type safety.
40
+ */
41
+ declare module '@equinor/fusion-framework-module-event' {
42
+ interface FrameworkEventMap {
43
+ /** Event emitted before navigation occurs, can be canceled to prevent navigation */
44
+ onNavigate: NavigateEvent;
45
+ /** Event emitted after navigation occurs */
46
+ onNavigated: NavigatedEvent;
47
+ }
48
+ }
@@ -1,6 +1,13 @@
1
- export type { Action, Path } from '@remix-run/router';
2
- export { INavigationConfigurator, NavigationConfigurator } from './configurator';
3
- export { NavigationModule, enableNavigation, module, moduleKey } from './module';
4
- export { createHistory } from './createHistory';
5
- export * from './lib';
6
- export * from './types';
1
+ export type { INavigationConfigurator } from './NavigationConfigurator.interface';
2
+ export { NavigationConfigurator } from './NavigationConfigurator';
3
+ export { NavigationModule, module, moduleKey } from './module';
4
+ export { enableNavigation } from './enable-navigation';
5
+ export type { INavigationProvider } from './NavigationProvider.interface';
6
+ export { NavigationProvider } from './NavigationProvider';
7
+ export { createHistory } from './lib/create-history';
8
+ export { NavigateEvent, NavigatedEvent, type NavigateEventDetail, type NavigatedEventDetail, } from './events';
9
+ export type { Path, To, Location, History, NavigationBlocker, NavigationListener, } from './lib/types';
10
+ /**
11
+ * @deprecated use History instead
12
+ */
13
+ export type { History as INavigator } from './lib';
@@ -0,0 +1,122 @@
1
+ import { Subscription } from 'rxjs';
2
+ import type { Actions, HistoryState } from './state';
3
+ import type { NavigateOptions, NavigationListener, Path, To, History, NavigationBlocker } from './types';
4
+ /**
5
+ * Abstract base class for history implementations.
6
+ * Provides common state management and navigation logic that can be shared
7
+ * across different history implementations (browser, memory, etc.).
8
+ */
9
+ export declare abstract class BaseHistory implements History {
10
+ #private;
11
+ /**
12
+ * Gets the current location.
13
+ */
14
+ get location(): History['location'];
15
+ /**
16
+ * Gets the current action.
17
+ */
18
+ get action(): History['action'];
19
+ /**
20
+ * Observable stream of navigation state changes.
21
+ * Emits on all navigation events (push, replace, pop).
22
+ */
23
+ get state$(): History['state$'];
24
+ /**
25
+ * Observable stream of navigation actions.
26
+ */
27
+ get action$(): History['action$'];
28
+ /**
29
+ * Checks if there are any active navigation blockers.
30
+ */
31
+ get hasBlockers(): boolean;
32
+ protected constructor(state: HistoryState);
33
+ /**
34
+ * Creates a valid href string for a given path.
35
+ */
36
+ createHref(to: To): string;
37
+ /**
38
+ * Creates a URL object for a given path.
39
+ */
40
+ createURL(to: To): URL;
41
+ /**
42
+ * Encodes a location by properly URL-encoding the pathname.
43
+ */
44
+ encodeLocation(to: To): Path;
45
+ /**
46
+ * Navigate to a location with explicit options.
47
+ *
48
+ * @param to - The target path (string, Path object, or Location object)
49
+ * @param options - Navigation options specifying action (PUSH/REPLACE) and optional state
50
+ */
51
+ navigate(to: To, options: NavigateOptions): void;
52
+ /**
53
+ * Pushes a new location onto the history stack.
54
+ */
55
+ push(to: To, state?: unknown): void;
56
+ /**
57
+ * Replaces the current location in the history stack.
58
+ */
59
+ replace(to: To, state?: unknown): void;
60
+ /**
61
+ * Navigates backward or forward in the history stack.
62
+ *
63
+ * @param delta - The number of steps to move (negative for backward, positive for forward)
64
+ */
65
+ go(delta: number): void;
66
+ /**
67
+ * Sets up a listener for navigation changes.
68
+ *
69
+ * Only listens for POP actions (browser back/forward navigation). PUSH/REPLACE
70
+ * actions are programmatic and synchronous - the caller already knows about them.
71
+ * POP actions come from browser events and are asynchronous, so we need to listen.
72
+ * This matches industry-standard router behavior (Remix/React Router).
73
+ *
74
+ * @param listener - Function to call on navigation changes
75
+ * @returns Function to unsubscribe the listener
76
+ */
77
+ listen(listener: NavigationListener): () => void;
78
+ /**
79
+ * Registers a blocker to intercept navigation attempts.
80
+ *
81
+ * @param blocker - Navigation blocker function to register
82
+ * @returns Function to unsubscribe the blocker
83
+ */
84
+ block(blocker: NavigationBlocker): VoidFunction;
85
+ pop(): void;
86
+ /**
87
+ * Disposes of the history instance and cleans up all subscriptions.
88
+ */
89
+ [Symbol.dispose](): void;
90
+ /**
91
+ * Dispatches an action to trigger state updates.
92
+ *
93
+ * Use this to dispatch actions when external events occur (e.g., browser popstate).
94
+ * The action will be processed by flows and update the history state.
95
+ *
96
+ * @param action - The action to dispatch
97
+ */
98
+ protected _dispatch(action: Actions): void;
99
+ /**
100
+ * Registers a cleanup function or subscription for automatic disposal.
101
+ *
102
+ * All teardowns are automatically cleaned up when the history instance is disposed.
103
+ * Use `executeOnRemove: true` if the teardown should run when manually removed.
104
+ *
105
+ * @param teardown - Function or subscription to clean up
106
+ * @param options - Optional configuration
107
+ * @param options.executeOnRemove - Execute teardown when removed (default: false)
108
+ * @returns Function to manually remove the teardown
109
+ */
110
+ protected _addTeardown(teardown: VoidFunction | Subscription, options?: {
111
+ executeOnRemove: boolean;
112
+ }): VoidFunction;
113
+ /**
114
+ * Removes a teardown from the cleanup collection.
115
+ *
116
+ * Typically called automatically by the function returned from `_addTeardown`.
117
+ * Only call directly if you need to remove a teardown without executing it.
118
+ *
119
+ * @param teardown - The teardown to remove
120
+ */
121
+ protected _removeTeardown(teardown: VoidFunction | Subscription): void;
122
+ }
@@ -0,0 +1,53 @@
1
+ import { BaseHistory } from './BaseHistory';
2
+ import { type HistoryStack, type NavigationBlocker } from './types';
3
+ /**
4
+ * Constructor for a HistoryStack implementation.
5
+ *
6
+ * @param window - The window object to use for history operations
7
+ * @returns A new instance of the HistoryStack implementation
8
+ */
9
+ export interface StackConstructor {
10
+ new (window: Window): HistoryStack;
11
+ }
12
+ /**
13
+ * Options for configuring a BrowserHistory instance.
14
+ */
15
+ export type BrowserHistoryOptions = {
16
+ /** Optional window object (defaults to global window) */
17
+ window?: Window;
18
+ /** Optional stack constructor (defaults to BrowserHistoryStack, use BrowserHistoryHashStack for hash routing) */
19
+ stack?: StackConstructor;
20
+ };
21
+ /**
22
+ * Browser history implementation using native browser APIs.
23
+ *
24
+ * Uses the browser's History API (pushState/replaceState) for navigation.
25
+ * Automatically listens for popstate/hashchange events to detect browser back/forward navigation.
26
+ * Compatible with industry-standard routers (Remix/React Router).
27
+ */
28
+ export declare class BrowserHistory extends BaseHistory {
29
+ #private;
30
+ /**
31
+ * Creates a browser history instance.
32
+ *
33
+ * Initializes with the current window location and sets up listeners for
34
+ * browser navigation events (popstate for regular routing, hashchange for hash routing).
35
+ *
36
+ * @param options - Configuration options
37
+ * @param options.window - Window object to use (defaults to global window)
38
+ * @param options.stack - Stack implementation (defaults to BrowserHistoryStack, use BrowserHistoryHashStack for hash routing)
39
+ * @throws {Error} If window is not available
40
+ */
41
+ constructor(options?: BrowserHistoryOptions);
42
+ /**
43
+ * Registers a blocker to intercept navigation attempts.
44
+ *
45
+ * Adds a beforeunload event listener when blockers are active to prevent
46
+ * page unload (e.g., when user tries to close the tab). This provides
47
+ * browser-level protection in addition to in-app navigation blocking.
48
+ *
49
+ * @param blocker - Navigation blocker function to register
50
+ * @returns Function to unsubscribe the blocker
51
+ */
52
+ block(blocker: NavigationBlocker): VoidFunction;
53
+ }
@@ -0,0 +1,41 @@
1
+ import { BrowserHistoryStack } from './BrowserHistoryStack';
2
+ import type { Location, To } from './types';
3
+ /**
4
+ * Browser history hash stack implementation using hash-based routing.
5
+ *
6
+ * Uses URL hash fragment (#) instead of pathname. The hash is not sent to the server,
7
+ * allowing routing without server configuration.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Regular routing: https://example.com/users
12
+ * // Hash routing: https://example.com/#/users
13
+ * const stack = new BrowserHistoryHashStack(window);
14
+ * ```
15
+ */
16
+ export declare class BrowserHistoryHashStack extends BrowserHistoryStack {
17
+ /**
18
+ * Gets the current location from window.location.hash.
19
+ */
20
+ get current(): Readonly<Location>;
21
+ /**
22
+ * Creates a URL object for a given path with hash-based routing.
23
+ *
24
+ * Uses the current window location as the base and only modifies the hash fragment.
25
+ * The path is normalized to ensure it starts with '#' if not already present.
26
+ *
27
+ * @param to - The target path (string, Path object, or Location object)
28
+ * @returns A URL object with the path in the hash fragment
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // If current URL is 'https://example.com/app'
33
+ * createURL('/users?id=1')
34
+ * // URL { href: 'https://example.com/app#/users?id=1', ... }
35
+ *
36
+ * createURL({ pathname: '/dashboard', search: '?tab=settings' })
37
+ * // URL { href: 'https://example.com/app#/dashboard?tab=settings', ... }
38
+ * ```
39
+ */
40
+ createURL(to: To): URL;
41
+ }
@@ -0,0 +1,51 @@
1
+ import type { HistoryStack, Location, To } from './types';
2
+ /**
3
+ * Browser history stack implementation using native browser APIs.
4
+ *
5
+ * Manages navigation state using the browser's History API (pushState/replaceState).
6
+ * Stores location state in history.state and uses relative paths for navigation.
7
+ * This is the base implementation for regular (non-hash) routing.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const stack = new BrowserHistoryStack(window);
12
+ * stack.push({ pathname: '/users', key: 'abc123', state: { userId: 1 } });
13
+ * // Updates URL to /users and adds entry to history
14
+ * ```
15
+ */
16
+ export declare class BrowserHistoryStack implements HistoryStack {
17
+ protected readonly _window: Window;
18
+ /**
19
+ * @param _window - The window object to use for history operations
20
+ */
21
+ constructor(_window: Window);
22
+ /**
23
+ * Gets the origin of the history stack.
24
+ */
25
+ get origin(): string;
26
+ /**
27
+ * Gets the current location.
28
+ */
29
+ get current(): Location;
30
+ /**
31
+ * Pushes a new entry onto the history stack.
32
+ */
33
+ push(location: Location): void;
34
+ /**
35
+ * Replaces the current entry in the history stack.
36
+ */
37
+ replace(location: Location): void;
38
+ /**
39
+ * Navigates to a location with the specified action.
40
+ */
41
+ navigate(location: Location, action: 'PUSH' | 'REPLACE'): void;
42
+ /**
43
+ * Navigates backward or forward in the history stack.
44
+ */
45
+ go(delta: number): void;
46
+ /**
47
+ * Creates a URL object for a given path.
48
+ */
49
+ createURL(to: To): URL;
50
+ protected _createRelativePath(to: To): string;
51
+ }
@@ -0,0 +1,27 @@
1
+ import { type To, type NavigationUpdate } from './types';
2
+ import { BaseHistory } from './BaseHistory';
3
+ /**
4
+ * Options for configuring a MemoryHistory instance.
5
+ */
6
+ export type MemoryHistoryOptions = {
7
+ /** Optional initial location */
8
+ initialLocation?: NavigationUpdate;
9
+ /** Optional initial history entries */
10
+ initialHistory?: NavigationUpdate[];
11
+ };
12
+ /**
13
+ * Memory history implementation using in-memory storage.
14
+ *
15
+ * Useful for:
16
+ * - Testing: Control navigation state in tests without browser APIs
17
+ * - SSR: Server-side rendering where window is not available
18
+ * - Widgets: Serving applications as widgets without affecting the main browser history
19
+ * - Node.js environments: Environments without browser APIs
20
+ */
21
+ export declare class MemoryHistory extends BaseHistory {
22
+ constructor(options?: MemoryHistoryOptions);
23
+ /**
24
+ * Creates a URL object for a given path using memory:// origin.
25
+ */
26
+ createURL(to: To): URL;
27
+ }