@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,144 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { of } from 'rxjs';
|
|
3
|
+
import { BaseConfigBuilder, } from '@equinor/fusion-framework-module';
|
|
4
|
+
import { createHistory } from './lib/create-history';
|
|
5
|
+
/**
|
|
6
|
+
* Zod schema for navigation module configuration validation.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const navigationConfigSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
basename: z
|
|
13
|
+
.string()
|
|
14
|
+
.optional()
|
|
15
|
+
.describe('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.'),
|
|
16
|
+
history: z
|
|
17
|
+
.custom()
|
|
18
|
+
.describe('Custom history instance implementing the History interface. Defaults to browser history if not provided. Use createHistory("browser"|"hash"|"memory") to create instances.'),
|
|
19
|
+
telemetry: z
|
|
20
|
+
.custom()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe('Telemetry provider for tracking navigation events. Used to log navigation actions, location changes, and errors for monitoring and debugging.'),
|
|
23
|
+
eventProvider: z
|
|
24
|
+
.custom()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('Event provider for dispatching navigation events (NavigateEvent, NavigatedEvent). Allows other modules to listen for navigation changes and block navigation attempts.'),
|
|
27
|
+
})
|
|
28
|
+
.describe('Validates navigation module configuration settings for routing and navigation capabilities.');
|
|
29
|
+
/**
|
|
30
|
+
* Parses and validates a navigation configuration object.
|
|
31
|
+
*
|
|
32
|
+
* @param config - The configuration object to parse
|
|
33
|
+
* @returns Validated navigation configuration
|
|
34
|
+
* @throws {z.ZodError} If the configuration is invalid
|
|
35
|
+
*/
|
|
36
|
+
const parseNavigationConfig = (config) => {
|
|
37
|
+
return navigationConfigSchema.parse(config);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Configurator class for navigation module settings.
|
|
41
|
+
* Extends BaseConfigBuilder to provide fluent configuration API with Zod validation.
|
|
42
|
+
*/
|
|
43
|
+
export class NavigationConfigurator extends BaseConfigBuilder {
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
this.setEventProvider(async (args) => {
|
|
47
|
+
if (args.hasModule('event')) {
|
|
48
|
+
return await args.requireInstance('event');
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
this.setHistory(async (args) => {
|
|
52
|
+
const history = args.ref?.navigation?.history;
|
|
53
|
+
if (history) {
|
|
54
|
+
return history;
|
|
55
|
+
}
|
|
56
|
+
if (typeof window !== 'undefined') {
|
|
57
|
+
return createHistory('browser');
|
|
58
|
+
}
|
|
59
|
+
return createHistory('memory');
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated Use `setBasename()` method instead
|
|
64
|
+
*/
|
|
65
|
+
set basename(value) {
|
|
66
|
+
if (process.env.NODE_ENV === 'development') {
|
|
67
|
+
console.warn('NavigationConfigurator.basename', 'use setBasename() method instead');
|
|
68
|
+
}
|
|
69
|
+
this.setBasename(value);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use `setHistory()` method instead
|
|
73
|
+
*/
|
|
74
|
+
set history(value) {
|
|
75
|
+
if (process.env.NODE_ENV === 'development') {
|
|
76
|
+
console.warn('NavigationConfigurator.history', 'use setHistory() method instead');
|
|
77
|
+
}
|
|
78
|
+
this.setHistory(value);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sets the basename for the application.
|
|
82
|
+
*
|
|
83
|
+
* @param basenameOrCallback - Basename string or configuration callback
|
|
84
|
+
* @returns The configurator instance for method chaining
|
|
85
|
+
*/
|
|
86
|
+
setBasename(basenameOrCallback) {
|
|
87
|
+
const fn = typeof basenameOrCallback === 'function'
|
|
88
|
+
? basenameOrCallback
|
|
89
|
+
: async () => basenameOrCallback;
|
|
90
|
+
this._set('basename', fn);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sets a custom history instance for the navigation module.
|
|
95
|
+
*
|
|
96
|
+
* @param historyOrCallback - History instance or configuration callback
|
|
97
|
+
* @returns The configurator instance for method chaining
|
|
98
|
+
*/
|
|
99
|
+
setHistory(historyOrCallback) {
|
|
100
|
+
const fn = typeof historyOrCallback === 'function' ? historyOrCallback : async () => historyOrCallback;
|
|
101
|
+
this._set('history', fn);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sets telemetry configuration for navigation-specific events.
|
|
106
|
+
*
|
|
107
|
+
* @param telemetryOrCallback - Telemetry provider instance or configuration callback
|
|
108
|
+
* @returns The configurator instance for method chaining
|
|
109
|
+
*/
|
|
110
|
+
setTelemetry(telemetryOrCallback) {
|
|
111
|
+
const fn = typeof telemetryOrCallback === 'function'
|
|
112
|
+
? telemetryOrCallback
|
|
113
|
+
: async () => telemetryOrCallback;
|
|
114
|
+
this._set('telemetry', fn);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sets event provider for dispatching navigation events.
|
|
119
|
+
*
|
|
120
|
+
* @param eventProviderOrCallback - Event provider instance or configuration callback
|
|
121
|
+
* @returns The configurator instance for method chaining
|
|
122
|
+
*/
|
|
123
|
+
setEventProvider(eventProviderOrCallback) {
|
|
124
|
+
const fn = typeof eventProviderOrCallback === 'function'
|
|
125
|
+
? eventProviderOrCallback
|
|
126
|
+
: async () => eventProviderOrCallback;
|
|
127
|
+
this._set('eventProvider', fn);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Processes and validates the configuration using Zod schema.
|
|
132
|
+
*
|
|
133
|
+
* @param config - Raw configuration object from builder
|
|
134
|
+
* @param _init - Configuration builder callback arguments (unused)
|
|
135
|
+
* @returns Observable that emits validated and processed configuration object
|
|
136
|
+
* @throws {z.ZodError} If the configuration is invalid
|
|
137
|
+
*
|
|
138
|
+
* @protected
|
|
139
|
+
*/
|
|
140
|
+
_processConfig(config, _init) {
|
|
141
|
+
return of(parseNavigationConfig(config));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=NavigationConfigurator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationConfigurator.js","sourceRoot":"","sources":["../../src/NavigationConfigurator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,EAAE,EAAwB,MAAM,MAAM,CAAC;AAChD,OAAO,EACL,iBAAiB,GAIlB,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,CAAC;KAC7B,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,0KAA0K,CAC3K;IACH,OAAO,EAAE,CAAC;SACP,MAAM,EAAW;SACjB,QAAQ,CACP,4KAA4K,CAC7K;IACH,SAAS,EAAE,CAAC;SACT,MAAM,EAAsB;SAC5B,QAAQ,EAAE;SACV,QAAQ,CACP,+IAA+I,CAChJ;IACH,aAAa,EAAE,CAAC;SACb,MAAM,EAAwB;SAC9B,QAAQ,EAAE;SACV,QAAQ,CACP,wKAAwK,CACzK;CACJ,CAAC;KACD,QAAQ,CACP,6FAA6F,CAC9F,CAAC;AAEJ;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG,CAAC,MAAe,EAA2B,EAAE;IACzE,OAAO,sBAAsB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,iBAA0C;IACpF;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YACnC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC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OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,UAAU,CAAC,iBAA4D;QAC5E,MAAM,EAAE,GACN,OAAO,iBAAiB,KAAK,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,iBAAiB,CAAC;QAC9F,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,YAAY,CACjB,mBAAmF;QAEnF,MAAM,EAAE,GACN,OAAO,mBAAmB,KAAK,UAAU;YACvC,CAAC,CAAC,mBAAmB;YACrB,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,mBAAmB,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,gBAAgB,CACrB,uBAA2F;QAE3F,MAAM,EAAE,GACN,OAAO,uBAAuB,KAAK,UAAU;YAC3C,CAAC,CAAC,uBAAuB;YACzB,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,uBAAuB,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;OASG;IACO,cAAc,CACtB,MAAwC,EACxC,KAAgC;QAEhC,OAAO,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationProvider.interface.js","sourceRoot":"","sources":["../../src/NavigationProvider.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// TODO: Remove @remix-run/router dependency once all apps have migrated to @equinor/fusion-framework-react-router
|
|
2
|
+
import { createRouter } from '@remix-run/router';
|
|
3
|
+
import { filter, pairwise, shareReplay } from 'rxjs/operators';
|
|
4
|
+
import { BaseModuleProvider, } from '@equinor/fusion-framework-module/provider';
|
|
5
|
+
import { TelemetryLevel, TelemetryScope, } from '@equinor/fusion-framework-module-telemetry';
|
|
6
|
+
import { NavigatedEvent } from './events';
|
|
7
|
+
import { pathToString } from './lib/utils';
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes a pathname by:
|
|
10
|
+
* - Collapsing multiple consecutive slashes into a single slash
|
|
11
|
+
* - Removing trailing slashes
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* normalizePathname("/app//users///profile/") // returns "/app/users/profile"
|
|
15
|
+
* normalizePathname("///multiple///slashes///") // returns "/multiple/slashes"
|
|
16
|
+
*
|
|
17
|
+
* @param path - The pathname to normalize
|
|
18
|
+
* @returns The normalized pathname without consecutive or trailing slashes
|
|
19
|
+
*/
|
|
20
|
+
const normalizePathname = (path) => path.replace(/\/+/g, '/').replace(/\/$/, '');
|
|
21
|
+
/**
|
|
22
|
+
* Navigation provider implementation.
|
|
23
|
+
* Manages routing and navigation state with basename localization.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* This provider:
|
|
27
|
+
* - Wraps the Navigator to provide observable navigation state
|
|
28
|
+
* - Localizes paths by removing basename prefix
|
|
29
|
+
* - Creates routers compatible with industry-standard routers (Remix/React Router)
|
|
30
|
+
* - Handles navigation actions (push, replace, createHref, etc.)
|
|
31
|
+
*
|
|
32
|
+
* Path localization ensures that consumers receive paths relative to the basename,
|
|
33
|
+
* while internally we work with full paths including basename.
|
|
34
|
+
*/
|
|
35
|
+
export class NavigationProvider extends BaseModuleProvider {
|
|
36
|
+
#history;
|
|
37
|
+
#basename;
|
|
38
|
+
#state$;
|
|
39
|
+
#telemetry;
|
|
40
|
+
#event;
|
|
41
|
+
/**
|
|
42
|
+
* Observable stream of navigation state updates.
|
|
43
|
+
* Emits localized paths (with basename removed) for consumers.
|
|
44
|
+
*/
|
|
45
|
+
get state$() {
|
|
46
|
+
return this.#state$;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the basename.
|
|
50
|
+
*/
|
|
51
|
+
get basename() {
|
|
52
|
+
return this.#basename ?? '';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use `history` instead
|
|
56
|
+
*/
|
|
57
|
+
get navigator() {
|
|
58
|
+
this.#telemetry?.trackException({
|
|
59
|
+
name: 'Navigation::navigator.deprecated',
|
|
60
|
+
exception: new Error('navigator is deprecated, use history instead'),
|
|
61
|
+
level: TelemetryLevel.Warning,
|
|
62
|
+
scope: ['navigation', TelemetryScope.Framework],
|
|
63
|
+
});
|
|
64
|
+
return this.#history;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets the history instance.
|
|
68
|
+
*/
|
|
69
|
+
get history() {
|
|
70
|
+
return this.#history;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the current localized path (basename removed).
|
|
74
|
+
*/
|
|
75
|
+
get path() {
|
|
76
|
+
return this._localizePath(this.#history.location);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @param args - Configuration arguments containing module config
|
|
80
|
+
* @throws {Error} If no history is provided in the configuration
|
|
81
|
+
*/
|
|
82
|
+
constructor(args) {
|
|
83
|
+
super(args);
|
|
84
|
+
// Extract configuration values
|
|
85
|
+
const { basename, history, telemetry, eventProvider } = args.config;
|
|
86
|
+
this.#basename = basename;
|
|
87
|
+
this.#event = eventProvider;
|
|
88
|
+
this.#telemetry = telemetry;
|
|
89
|
+
// History is required - validate and track error if missing
|
|
90
|
+
if (!history) {
|
|
91
|
+
this.#telemetry?.trackException({
|
|
92
|
+
name: 'Navigation::history.required',
|
|
93
|
+
exception: new Error('no history provided!'),
|
|
94
|
+
level: TelemetryLevel.Error,
|
|
95
|
+
scope: ['navigation', TelemetryScope.Application],
|
|
96
|
+
});
|
|
97
|
+
throw Error('no history provided!');
|
|
98
|
+
}
|
|
99
|
+
this.#history = history;
|
|
100
|
+
// Create state$ observable that filters for paths within basename scope
|
|
101
|
+
// shareReplay ensures subscribers get the latest value and share the subscription
|
|
102
|
+
this.#state$ = this.#history.state$.pipe(filter((update) => this._isWithinBasenameScope(update.location.pathname)), shareReplay({ bufferSize: 1, refCount: true }));
|
|
103
|
+
this._initialize();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Sets up navigation subscriptions for events and telemetry.
|
|
107
|
+
*
|
|
108
|
+
* Configures subscriptions for:
|
|
109
|
+
* - NavigatedEvent dispatching when navigation changes
|
|
110
|
+
* - Telemetry tracking for navigation actions and events
|
|
111
|
+
* - History disposal cleanup
|
|
112
|
+
*/
|
|
113
|
+
_initialize() {
|
|
114
|
+
// Dispatch NavigatedEvent and track telemetry when navigation changes
|
|
115
|
+
// pairwise() gives us [previous, current] pairs to compare navigation state
|
|
116
|
+
this._addTeardown(this.#state$.pipe(pairwise()).subscribe(([previous, current]) => {
|
|
117
|
+
// emit NavigatedEvent for other modules to listen to when navigation changes
|
|
118
|
+
this.#event?.dispatchEvent(new NavigatedEvent({
|
|
119
|
+
action: current.action,
|
|
120
|
+
current,
|
|
121
|
+
previous,
|
|
122
|
+
}, this));
|
|
123
|
+
// track telemetry for navigation changes
|
|
124
|
+
this.#telemetry?.trackEvent({
|
|
125
|
+
name: 'Navigation::navigated',
|
|
126
|
+
level: TelemetryLevel.Information,
|
|
127
|
+
scope: ['navigation', TelemetryScope.Application],
|
|
128
|
+
properties: {
|
|
129
|
+
action: current.action,
|
|
130
|
+
location: pathToString(current.location),
|
|
131
|
+
previousLocation: pathToString(previous.location),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}));
|
|
135
|
+
// Track all navigation actions for debugging (if telemetry is enabled)
|
|
136
|
+
if (this.#telemetry) {
|
|
137
|
+
this._addTeardown(this.#history.action$.subscribe((action) => {
|
|
138
|
+
this.#telemetry?.trackEvent({
|
|
139
|
+
name: `Navigation::action:${action.type}`,
|
|
140
|
+
level: TelemetryLevel.Debug,
|
|
141
|
+
scope: ['navigation', TelemetryScope.Framework],
|
|
142
|
+
properties: {
|
|
143
|
+
type: action.type,
|
|
144
|
+
action: action,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
// Clean up history instance when provider is disposed
|
|
150
|
+
this._addTeardown(() => this.#history[Symbol.dispose]());
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Creates a router instance from route configuration.
|
|
154
|
+
*
|
|
155
|
+
* @deprecated Use `@equinor/fusion-framework-react-router` instead
|
|
156
|
+
*
|
|
157
|
+
* @param routes - Route configuration objects compatible with industry-standard routers (Remix/React Router)
|
|
158
|
+
* @returns A configured and initialized router instance
|
|
159
|
+
*/
|
|
160
|
+
createRouter(routes) {
|
|
161
|
+
this.#telemetry?.trackEvent({
|
|
162
|
+
name: 'Navigation::createRouter',
|
|
163
|
+
level: TelemetryLevel.Warning,
|
|
164
|
+
scope: ['navigation', 'deprecated', TelemetryScope.Application],
|
|
165
|
+
});
|
|
166
|
+
const router = createRouter({
|
|
167
|
+
basename: this.#basename,
|
|
168
|
+
history: this.#history,
|
|
169
|
+
routes,
|
|
170
|
+
future: {
|
|
171
|
+
v7_prependBasename: true,
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
router.initialize();
|
|
175
|
+
return router;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Creates a localized href string for navigation.
|
|
179
|
+
*
|
|
180
|
+
* @param to - Optional path or location (defaults to current path)
|
|
181
|
+
*/
|
|
182
|
+
createHref(to) {
|
|
183
|
+
return this.#history.createHref(this._createToPath(to ?? this.path));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Creates a full URL object for navigation.
|
|
187
|
+
*
|
|
188
|
+
* @param to - Optional path or location (defaults to current path)
|
|
189
|
+
*/
|
|
190
|
+
createURL(to) {
|
|
191
|
+
return this.#history.createURL(this._createToPath(to ?? this.path));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Pushes a new navigation entry onto the history stack.
|
|
195
|
+
*
|
|
196
|
+
* @param to - Path or location to navigate to (relative to basename)
|
|
197
|
+
* @param state - Optional state to associate with the navigation
|
|
198
|
+
*/
|
|
199
|
+
push(to, state) {
|
|
200
|
+
this.navigate(to, { state });
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Replaces the current history entry with a new one.
|
|
204
|
+
*
|
|
205
|
+
* @param to - Path or location to navigate to (relative to basename)
|
|
206
|
+
* @param state - Optional state to associate with the navigation
|
|
207
|
+
*/
|
|
208
|
+
replace(to, state) {
|
|
209
|
+
this.navigate(to, { replace: true, state });
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Navigate to a location with explicit options.
|
|
213
|
+
*
|
|
214
|
+
* @param to - Optional path or location (defaults to current path)
|
|
215
|
+
* @param options - Optional navigation options
|
|
216
|
+
*/
|
|
217
|
+
navigate(to, options) {
|
|
218
|
+
const { replace = false, state } = options ?? {};
|
|
219
|
+
this.#history.navigate(this._createToPath(to ?? this.path), { replace, state });
|
|
220
|
+
// we need to pop the history to update the notify history listeners
|
|
221
|
+
// Frameworks as react router have their internal state management,
|
|
222
|
+
// so we need to force a pop to notify the framework that the history has changed
|
|
223
|
+
this.#history.pop();
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Checks if a pathname is within the basename scope.
|
|
227
|
+
*/
|
|
228
|
+
_isWithinBasenameScope(pathname) {
|
|
229
|
+
return this.#basename ? pathname.startsWith(this.#basename) : true;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Localizes a path by removing the basename prefix.
|
|
233
|
+
*/
|
|
234
|
+
_localizePath(location) {
|
|
235
|
+
const { pathname, search, hash } = location;
|
|
236
|
+
return {
|
|
237
|
+
pathname: normalizePathname(pathname.replace(this.#basename ?? '', '')),
|
|
238
|
+
search,
|
|
239
|
+
hash,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Creates a full path object from a target location, adding basename prefix.
|
|
244
|
+
*/
|
|
245
|
+
_createToPath(to) {
|
|
246
|
+
// Parse the 'to' parameter into path components
|
|
247
|
+
const pathComponents = typeof to === 'string' ? { pathname: to } : to;
|
|
248
|
+
// Extract path parts, defaulting to current path values
|
|
249
|
+
const rawPathname = pathComponents.pathname ?? this.path.pathname;
|
|
250
|
+
const pathname = normalizePathname(`${this.#basename ?? ''}/${rawPathname}`);
|
|
251
|
+
const search = pathComponents.search ?? this.path.search;
|
|
252
|
+
const hash = pathComponents.hash ?? this.path.hash;
|
|
253
|
+
return { pathname, search, hash };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=NavigationProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationProvider.js","sourceRoot":"","sources":["../../src/NavigationProvider.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,OAAO,EAA4B,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE3E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EACL,kBAAkB,GAEnB,MAAM,2CAA2C,CAAC;AAKnD,OAAO,EACL,cAAc,EACd,cAAc,GAEf,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C;;;;;;;;;;;GAWG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEzF;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,kBACX,SAAQ,kBAA2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AC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrE,CAAC;IAED;;OAEG;IACO,aAAa,CAAC,QAAc;QACpC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;QAC5C,OAAO;YACL,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACvE,MAAM;YACN,IAAI;SACL,CAAC;IACJ,CAAC;IAED;;OAEG;IACO,aAAa,CAAC,EAAM;QAC5B,gDAAgD;QAChD,MAAM,cAAc,GAAG,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAEtE,wDAAwD;QACxD,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAClE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,CAAC;QAC7E,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QACzD,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { module } from './module';
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to enable the navigation module.
|
|
4
|
+
*
|
|
5
|
+
* This is the main entry point for consumers to add navigation capabilities to their
|
|
6
|
+
* framework configuration. It registers the navigation module and allows configuration
|
|
7
|
+
* of basename and other navigation settings.
|
|
8
|
+
*
|
|
9
|
+
* The navigation module provides routing and navigation capabilities compatible with
|
|
10
|
+
* industry-standard routers (Remix/React Router), with support for browser history,
|
|
11
|
+
* hash routing, and memory history.
|
|
12
|
+
*
|
|
13
|
+
* @param configurator - The modules configurator to add navigation to
|
|
14
|
+
* @param basenameOrOptions - Optional basename string or configuration object
|
|
15
|
+
* @param basenameOrOptions.configure - Configuration callback for advanced setup
|
|
16
|
+
* @typeParam TRef - Reference type for module composition
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Simple usage with basename
|
|
21
|
+
* enableNavigation(configurator, '/app');
|
|
22
|
+
*
|
|
23
|
+
* // Advanced configuration
|
|
24
|
+
* enableNavigation(configurator, {
|
|
25
|
+
* configure(config, ref) {
|
|
26
|
+
* config.setBasename('/app');
|
|
27
|
+
* config.setHistory(createHistory('browser'));
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @see {@link NavigationModule} - The navigation module type
|
|
33
|
+
* @see {@link INavigationConfigurator} - Configuration interface
|
|
34
|
+
* @see {@link INavigationProvider} - Provider interface for accessing navigation
|
|
35
|
+
*/
|
|
36
|
+
export const enableNavigation = (
|
|
37
|
+
// biome-ignore lint/suspicious/noExplicitAny: must be any to support all module types
|
|
38
|
+
configurator, basenameOrOptions) => {
|
|
39
|
+
configurator.addConfig({
|
|
40
|
+
module,
|
|
41
|
+
configure(config, ref) {
|
|
42
|
+
if (typeof basenameOrOptions === 'string') {
|
|
43
|
+
config.setBasename(basenameOrOptions);
|
|
44
|
+
}
|
|
45
|
+
else if (typeof basenameOrOptions === 'object' && 'configure' in basenameOrOptions) {
|
|
46
|
+
basenameOrOptions.configure(config, ref);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export default enableNavigation;
|
|
52
|
+
//# sourceMappingURL=enable-navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enable-navigation.js","sourceRoot":"","sources":["../../src/enable-navigation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAyB,MAAM,UAAU,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;AAC9B,sFAAsF;AACtF,YAA4C,EAC5C,iBAIK,EACC,EAAE;IACR,YAAY,CAAC,SAAS,CAAC;QACrB,MAAM;QACN,SAAS,CAAC,MAAM,EAAE,GAAG;YACnB,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;gBAC1C,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;YACxC,CAAC;iBAAM,IAAI,OAAO,iBAAiB,KAAK,QAAQ,IAAI,WAAW,IAAI,iBAAiB,EAAE,CAAC;gBACrF,iBAAiB,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FrameworkEvent } from '@equinor/fusion-framework-module-event';
|
|
2
|
+
/**
|
|
3
|
+
* Event emitted before navigation occurs.
|
|
4
|
+
* Can be canceled by calling `preventDefault()`.
|
|
5
|
+
*/
|
|
6
|
+
export class NavigateEvent extends FrameworkEvent {
|
|
7
|
+
constructor(detail, source) {
|
|
8
|
+
super('onNavigate', {
|
|
9
|
+
detail,
|
|
10
|
+
source,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Event emitted after navigation occurs.
|
|
16
|
+
* Contains the navigation action and location details.
|
|
17
|
+
*/
|
|
18
|
+
export class NavigatedEvent extends FrameworkEvent {
|
|
19
|
+
constructor(detail, source) {
|
|
20
|
+
super('onNavigated', { detail, source });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA2B,MAAM,wCAAwC,CAAC;AAejG;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,cAElC;IACC,YAAY,MAA2B,EAAE,MAA2B;QAClE,KAAK,CAAC,YAAY,EAAE;YAClB,MAAM;YACN,MAAM;SACP,CAAC,CAAC;IACL,CAAC;CACF;AAcD;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,cAEnC;IACC,YAAY,MAA4B,EAAE,MAA2B;QACnE,KAAK,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { NavigationConfigurator } from './
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export { NavigationConfigurator } from './NavigationConfigurator';
|
|
2
|
+
export { module, moduleKey } from './module';
|
|
3
|
+
export { enableNavigation } from './enable-navigation';
|
|
4
|
+
export { NavigationProvider } from './NavigationProvider';
|
|
5
|
+
export { createHistory } from './lib/create-history';
|
|
6
|
+
export { NavigateEvent, NavigatedEvent, } from './events';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAoB,MAAM,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EACL,aAAa,EACb,cAAc,GAGf,MAAM,UAAU,CAAC"}
|