@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,52 @@
1
+ import type { To } from '../types';
2
+ import { encodeTrailingWhitespace } from './encode-trailing-whitespace';
3
+ import { hasProtocol } from './has-protocol';
4
+ import { pathToString } from './path-to-string';
5
+
6
+ /**
7
+ * Converts a path to a URL object.
8
+ *
9
+ * This utility handles various path formats and converts them to standard URL objects.
10
+ * It supports absolute URLs, relative paths, and path objects with pathname/search/hash.
11
+ *
12
+ * @param path - The target path (string, Path object, or Location object)
13
+ * @param origin - Optional origin URL. Defaults to `window.location.origin` in browser environments,
14
+ * or 'http://localhost' in Node.js environments
15
+ * @returns A URL object for the given path
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * // Absolute URL with custom origin
20
+ * pathToUrl('/users?id=1', 'https://example.com')
21
+ * // URL { href: 'https://example.com/users?id=1', ... }
22
+ *
23
+ * // Complete URL with protocol
24
+ * pathToUrl('https://example.com/users')
25
+ * // URL { href: 'https://example.com/users', ... }
26
+ *
27
+ * // Path object
28
+ * pathToUrl({ pathname: '/users', search: '?id=1' })
29
+ * // URL { href: 'http://localhost/users?id=1', ... }
30
+ *
31
+ * // Browser environment (uses window.location.origin)
32
+ * pathToUrl('/dashboard')
33
+ * // URL { href: 'https://current-site.com/dashboard', ... }
34
+ * ```
35
+ */
36
+ export const pathToUrl = (path: To, origin?: string): URL => {
37
+ // Convert path to string representation
38
+ const pathString = typeof path === 'string' ? encodeTrailingWhitespace(path) : pathToString(path);
39
+
40
+ // If path already has a protocol, it's a complete URL
41
+ if (hasProtocol(pathString)) {
42
+ return new URL(pathString);
43
+ }
44
+
45
+ // Determine the origin to use for relative paths
46
+ const resolvedOrigin =
47
+ origin ??
48
+ (typeof window !== 'undefined' ? window.location?.origin : undefined) ??
49
+ 'http://localhost';
50
+
51
+ return new URL(pathString, resolvedOrigin);
52
+ };
@@ -0,0 +1,60 @@
1
+ import type { Location } from '../types';
2
+ import { resolvePath } from './resolve-path';
3
+
4
+ const resolveState = (target?: { state: unknown }): { state: unknown; key: string } => {
5
+ const { value, key = 'unknown' } =
6
+ (target ?? window.history).state ??
7
+ ({} as {
8
+ value: unknown;
9
+ key?: string;
10
+ });
11
+ return { state: value, key };
12
+ };
13
+
14
+ /**
15
+ * Resolves the current location from window.location.
16
+ *
17
+ * @param window - The window object to extract location from
18
+ * @param target - Optional target object with state
19
+ * @returns The current location with pathname, search, hash, state, and key
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // If window.location is 'https://example.com/users?id=1#section'
24
+ * resolveWindowLocation(window)
25
+ * // { pathname: '/users', search: '?id=1', hash: '#section', state: undefined, key: 'unknown' }
26
+ *
27
+ * resolveWindowLocation(window, { state: { userId: 123 } })
28
+ * // { pathname: '/users', search: '?id=1', hash: '#section', state: { userId: 123 }, key: 'abc123' }
29
+ * ```
30
+ */
31
+ export const resolveWindowLocation = (window: Window, target?: { state: unknown }): Location => {
32
+ const { pathname, search, hash } = resolvePath(window.location);
33
+ const { state, key } = resolveState(target);
34
+ return { pathname, search, hash, state, key };
35
+ };
36
+
37
+ /**
38
+ * Resolves the current location from window.location.hash.
39
+ *
40
+ * @param window - The window object to extract location from
41
+ * @param target - Optional target object with state
42
+ * @returns The current location with pathname, search, hash, state, and key
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // If window.location.hash is '#/users?id=1#section'
47
+ * resolveHashLocation(window)
48
+ * // { pathname: '/users', search: '?id=1', hash: '#section', state: undefined, key: 'unknown' }
49
+ *
50
+ * // If window.location.hash is '#/dashboard'
51
+ * resolveHashLocation(window)
52
+ * // { pathname: '/dashboard', search: '', hash: '', state: undefined, key: 'unknown' }
53
+ * ```
54
+ */
55
+ export const resolveHashLocation = (window: Window, target?: { state: unknown }): Location => {
56
+ const location = resolveWindowLocation(window, target);
57
+ const { pathname, search, hash } = resolvePath(location.hash?.replace('#', '') ?? '');
58
+ const { state, key } = resolveState(target);
59
+ return { pathname, search, hash, state, key };
60
+ };
@@ -0,0 +1,22 @@
1
+ import type { Path, To } from '../types';
2
+ import { pathToUrl } from './path-to-url';
3
+
4
+ /**
5
+ * Resolves a 'to' value into a Path object.
6
+ *
7
+ * @param to - The target path (string, Path object, or Location object)
8
+ * @returns A Path object with the pathname, search, and hash components
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * resolvePath('/users?id=1#section')
13
+ * // { pathname: '/users', search: '?id=1', hash: '#section' }
14
+ *
15
+ * resolvePath({ pathname: '/users', search: 'id=1', hash: 'section' })
16
+ * // { pathname: '/users', search: '?id=1', hash: '#section' }
17
+ * ```
18
+ */
19
+ export const resolvePath = (to: To): Path => {
20
+ const { pathname, search, hash } = pathToUrl(to);
21
+ return { pathname, search, hash };
22
+ };
package/src/module.ts CHANGED
@@ -1,60 +1,76 @@
1
- import {
2
- type IModuleConfigurator,
3
- type IModulesConfigurator,
4
- type Module,
5
- type ModuleConfigType,
6
- type ModuleInstance,
7
- SemanticVersion,
8
- } from '@equinor/fusion-framework-module';
9
- import { type INavigationConfigurator, NavigationConfigurator } from './configurator';
10
- import { createHistory } from './createHistory';
11
- import { type INavigationProvider, NavigationProvider } from './lib';
1
+ import { type Module, SemanticVersion } from '@equinor/fusion-framework-module';
2
+ import { NavigationConfigurator } from './NavigationConfigurator';
3
+ import type { INavigationProvider } from './NavigationProvider.interface';
4
+ import { NavigationProvider } from './NavigationProvider';
12
5
 
13
6
  import { version } from './version';
14
7
 
8
+ /**
9
+ * Module key identifier for the navigation module.
10
+ */
15
11
  export const moduleKey = 'navigation';
16
12
 
13
+ /**
14
+ * Type definition for the navigation module.
15
+ *
16
+ * This is the main type definition for the navigation module. It represents the complete
17
+ * module structure with its key identifier, provider interface, and configurator class.
18
+ *
19
+ * The navigation module provides routing and navigation capabilities compatible with
20
+ * industry-standard routers (Remix/React Router), with support for browser history,
21
+ * hash routing, and memory history. It integrates with the Fusion Framework module
22
+ * system and provides a {@link INavigationProvider} instance that can be used to
23
+ * access navigation functionality.
24
+ *
25
+ * @see {@link INavigationProvider} - The provider interface for accessing navigation
26
+ * @see {@link NavigationConfigurator} - The configurator class for setting up navigation
27
+ * @see {@link enableNavigation} - Helper function to enable the navigation module
28
+ * @see {@link module} - The module implementation instance
29
+ */
17
30
  export type NavigationModule = Module<
18
31
  typeof moduleKey,
19
32
  INavigationProvider,
20
- INavigationConfigurator
33
+ NavigationConfigurator
21
34
  >;
22
35
 
36
+ /**
37
+ * Navigation module implementation.
38
+ * Provides routing and navigation capabilities compatible with industry-standard routers (Remix/React Router).
39
+ *
40
+ * @remarks
41
+ * - Uses BaseConfigBuilder pattern with Zod validation
42
+ * - Basename must match the URL path prefix where your app is served
43
+ * - The router requires URL pathname to start with the basename
44
+ */
23
45
  export const module: NavigationModule = {
24
46
  version: new SemanticVersion(version),
25
47
  name: moduleKey,
26
- configure: (ref?: ModuleInstance) => {
27
- const configurator = new NavigationConfigurator();
28
- if (ref?.navigation) {
29
- configurator.history = ref.navigation.navigator;
30
- }
31
- return configurator;
32
- },
33
- initialize: ({ config }) => {
34
- config.history ??= createHistory();
48
+ /**
49
+ * Configures the navigation module.
50
+ *
51
+ * @returns A new NavigationConfigurator instance
52
+ */
53
+ configure: () => new NavigationConfigurator(),
54
+ /**
55
+ * Initializes the navigation module with validated configuration.
56
+ *
57
+ * @param init - Module initialization arguments
58
+ * @returns A Promise that resolves to a new NavigationProvider instance
59
+ */
60
+ initialize: async (init) => {
61
+ const config = await init.config.createConfigAsync(init);
35
62
  return new NavigationProvider({ version, config });
36
63
  },
64
+ /**
65
+ * Disposes of the navigation module instance.
66
+ *
67
+ * @param instance - The NavigationProvider instance to dispose
68
+ */
37
69
  dispose({ instance }) {
38
70
  instance.dispose();
39
71
  },
40
72
  };
41
73
 
42
- export const enableNavigation = <TRef = unknown>(
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- configurator: IModulesConfigurator<any, any>,
45
- basenameOrOptions?: string | Omit<IModuleConfigurator<NavigationModule, TRef>, 'module'>,
46
- ): void => {
47
- const options =
48
- typeof basenameOrOptions === 'string'
49
- ? {
50
- configure: (config: ModuleConfigType<NavigationModule>) => {
51
- config.basename = basenameOrOptions;
52
- },
53
- }
54
- : basenameOrOptions;
55
- configurator.addConfig({ module, ...options });
56
- };
57
-
58
74
  export default module;
59
75
 
60
76
  declare module '@equinor/fusion-framework-module' {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '6.0.1';
2
+ export const version = '7.0.0-next.2';
package/tsconfig.json CHANGED
@@ -8,8 +8,17 @@
8
8
  "references": [
9
9
  {
10
10
  "path": "../module"
11
+ },
12
+ {
13
+ "path": "../telemetry"
14
+ },
15
+ {
16
+ "path": "../event"
17
+ },
18
+ {
19
+ "path": "../../utils/observable"
11
20
  }
12
21
  ],
13
22
  "include": ["src/**/*"],
14
- "exclude": ["node_modules", "lib"]
23
+ "exclude": ["node_modules", "lib", "src/__tests__/**/*"]
15
24
  }
@@ -0,0 +1,14 @@
1
+ import { defineProject } from 'vitest/config';
2
+
3
+ import { name, version } from './package.json';
4
+
5
+ export default defineProject({
6
+ test: {
7
+ include: ['src/__tests__/**/*.test.ts'],
8
+ name: `${name}@${version}`,
9
+ environment: 'jsdom',
10
+ globals: true,
11
+ setupFiles: ['./src/__tests__/setup.ts'],
12
+ testTimeout: 1000,
13
+ },
14
+ });
@@ -1,5 +0,0 @@
1
- export class NavigationConfigurator {
2
- history;
3
- basename;
4
- }
5
- //# sourceMappingURL=configurator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configurator.js","sourceRoot":"","sources":["../../src/configurator.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,sBAAsB;IAC1B,OAAO,CAAW;IAClB,QAAQ,CAAU;CAC1B"}
@@ -1,18 +0,0 @@
1
- import { createBrowserHistory, createHashHistory, createMemoryHistory } from '@remix-run/router';
2
- export const createHistory = (type) => {
3
- switch (type) {
4
- case 'hash':
5
- return createHashHistory({ v5Compat: true });
6
- case 'memory':
7
- return createMemoryHistory({ v5Compat: true });
8
- case 'browser':
9
- return createBrowserHistory({
10
- v5Compat: true,
11
- });
12
- default: {
13
- console.warn(`Unknown history type: ${type}. Using browser history as default.`);
14
- return createHistory('browser');
15
- }
16
- }
17
- };
18
- //# sourceMappingURL=createHistory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createHistory.js","sourceRoot":"","sources":["../../src/createHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAKjG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAkB,EAAW,EAAE;IAC3D,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,iBAAiB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,KAAK,QAAQ;YACX,OAAO,mBAAmB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,KAAK,SAAS;YACZ,OAAO,oBAAoB,CAAC;gBAC1B,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;QACL,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,CAAC,IAAI,CAAC,yBAAyB,IAAI,qCAAqC,CAAC,CAAC;YACjF,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=INavigationProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"INavigationProvider.js","sourceRoot":"","sources":["../../../../src/lib/provider/INavigationProvider.ts"],"names":[],"mappings":""}
@@ -1,82 +0,0 @@
1
- import { createRouter } from '@remix-run/router';
2
- import { filter, map } from 'rxjs/operators';
3
- import { BaseModuleProvider, } from '@equinor/fusion-framework-module/provider';
4
- import { Navigator } from '../../navigator';
5
- const normalizePathname = (path) => path.replace(/\/+/g, '/');
6
- export class NavigationProvider extends BaseModuleProvider {
7
- #navigator;
8
- #basePathname;
9
- get state$() {
10
- return this.#navigator.pipe(
11
- /** only push navigation state if the path is within the basename scope */
12
- filter((event) => this.#basePathname ? event.location.pathname.startsWith(this.#basePathname) : true),
13
- /** map path to localized path */
14
- map(({ action, location }) => ({
15
- action,
16
- location: this._localizePath(location),
17
- })));
18
- }
19
- get navigator() {
20
- return this.#navigator;
21
- }
22
- get path() {
23
- return this._localizePath(this.navigator.location);
24
- }
25
- constructor(args) {
26
- super(args);
27
- const { basename, history } = args.config;
28
- this.#basePathname = basename;
29
- if (!history) {
30
- throw Error('no history provided!');
31
- }
32
- this.#navigator = new Navigator({
33
- basename,
34
- history,
35
- });
36
- this._addTeardown(() => this.#navigator.dispose());
37
- }
38
- createRouter(routes) {
39
- const history = this.#navigator;
40
- console.debug('NavigationProvider::createRouter', routes);
41
- const router = createRouter({
42
- basename: history.basename,
43
- history,
44
- routes,
45
- future: {
46
- v7_prependBasename: true,
47
- },
48
- });
49
- router.initialize();
50
- return router;
51
- }
52
- createHref(to) {
53
- return this.#navigator.createHref(this._createToPath(to ?? this.path));
54
- }
55
- createURL(to) {
56
- return this.#navigator.createURL(this._createToPath(to ?? this.path));
57
- }
58
- push(to, state) {
59
- this.#navigator.push(this._createToPath(to), state);
60
- }
61
- replace(to, state) {
62
- this.#navigator.replace(this._createToPath(to), state);
63
- }
64
- _localizePath(location) {
65
- const { pathname, search, hash } = location;
66
- return {
67
- // TODO make better check
68
- pathname: normalizePathname(pathname.replace(this.#basePathname ?? '', '')),
69
- search,
70
- hash,
71
- };
72
- }
73
- _createToPath(to) {
74
- const { pathname, search, hash } = typeof to === 'string' ? { pathname: to, search: undefined, hash: undefined } : to;
75
- return {
76
- pathname: normalizePathname([this.#basePathname, pathname === '/' ? undefined : pathname].filter((x) => !!x).join('/')),
77
- search,
78
- hash,
79
- };
80
- }
81
- }
82
- //# sourceMappingURL=NavigationProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NavigationProvider.js","sourceRoot":"","sources":["../../../../src/lib/provider/NavigationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,YAAY,EAAsB,MAAM,mBAAmB,CAAC;AAE/F,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EACL,kBAAkB,GAEnB,MAAM,2CAA2C,CAAC;AAKnD,OAAO,EAAE,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAE7D,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEtE,MAAM,OAAO,kBACX,SAAQ,kBAA2C;IAGnD,UAAU,CAAa;IACvB,aAAa,CAAU;IAEvB,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI;QACzB,0EAA0E;QAC1E,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CACf,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CACnF;QACD,iCAAiC;QACjC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;YAC7B,MAAM;YACN,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC;SACvC,CAAC,CAAC,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ACJ,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export { NavigationProvider } from './NavigationProvider';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/provider/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,158 +0,0 @@
1
- import { BehaviorSubject, Observable, Subscription } from 'rxjs';
2
- /**
3
- * Type guard to check if a given 'to' parameter is a Location object.
4
- * @param to - The object to check.
5
- * @returns True if 'to' is a Location object, false otherwise.
6
- */
7
- const isLocation = (to) => typeof to === 'object' && 'key' in to;
8
- /**
9
- * Class representing a navigator that manages navigation and history state.
10
- */
11
- export class Navigator extends Observable {
12
- #history;
13
- #baseName;
14
- #origin = window.location.origin;
15
- #subscriptions = new Subscription();
16
- #state;
17
- #logger;
18
- /**
19
- * Gets the basename of the navigator.
20
- */
21
- get basename() {
22
- return this.#baseName;
23
- }
24
- /**
25
- * Gets the origin of the navigator.
26
- */
27
- get origin() {
28
- return this.#origin;
29
- }
30
- /**
31
- * Gets the current navigation state as an observable.
32
- */
33
- get state() {
34
- return this.#state.asObservable();
35
- }
36
- /**
37
- * Gets the current navigation state value.
38
- */
39
- get value() {
40
- return this.#state.value;
41
- }
42
- /**
43
- * Gets the current location from the navigation state.
44
- */
45
- get location() {
46
- return this.value.location;
47
- }
48
- /**
49
- * Gets the current action from the navigation state.
50
- */
51
- get action() {
52
- return this.value.action;
53
- }
54
- /**
55
- * Navigator constructor.
56
- * @param args - Configuration options for the navigator.
57
- */
58
- constructor(args) {
59
- super((subscriber) => this.#state.subscribe(subscriber));
60
- const { basename, history } = args;
61
- this.#logger = args.logger || console;
62
- this.#baseName = basename;
63
- this.#history = history;
64
- this.#state = new BehaviorSubject({
65
- action: this.#history.action,
66
- location: this.#history.location,
67
- delta: null,
68
- });
69
- this.#subscriptions.add(this.#history.listen((update) => {
70
- // Prevent duplicate state updates.
71
- if (update.location.key !== this.#state.value.location.key) {
72
- this.#state.next(update);
73
- }
74
- }));
75
- }
76
- /**
77
- * Encodes a location into a path string.
78
- * @param to - The location to encode.
79
- * @returns The encoded path string.
80
- */
81
- encodeLocation(to) {
82
- return this.#history.encodeLocation(to);
83
- }
84
- /**
85
- * Subscribes to navigation updates.
86
- * @param listener - The listener function to receive updates.
87
- * @returns A function to unsubscribe the listener.
88
- */
89
- listen(listener) {
90
- const subscription = this.#state.subscribe(listener);
91
- this.#logger.debug('Navigator::listen', listener);
92
- return () => {
93
- this.#logger.debug('Navigator::listen[unsubscribe]', listener);
94
- return subscription.unsubscribe();
95
- };
96
- }
97
- /**
98
- * Creates a URL string for a given location.
99
- * @param to - The location to create a URL for.
100
- * @returns The created URL string.
101
- */
102
- createHref(to) {
103
- return this.#history.createHref(to);
104
- }
105
- /**
106
- * Navigates to a specific history entry by its relative position to the current entry.
107
- * @param delta - The relative position to move in the history stack.
108
- */
109
- go(delta) {
110
- this.#history.go(delta);
111
- }
112
- /**
113
- * Pushes a new entry onto the history stack.
114
- * @param to - The location or URL to navigate to.
115
- * @param state - Optional state to associate with the navigation.
116
- */
117
- push(to, state) {
118
- const skip = isLocation(to) && this._isDuplicateLocation(to);
119
- if (!skip) {
120
- this.#history.push(to, state);
121
- }
122
- }
123
- /**
124
- * Replaces the current history entry with a new one.
125
- * @param to - The location or URL to navigate to.
126
- * @param state - Optional state to associate with the navigation.
127
- */
128
- replace(to, state) {
129
- const skip = isLocation(to) && this._isDuplicateLocation(to);
130
- if (!skip) {
131
- this.#history.replace(to, state);
132
- }
133
- }
134
- /**
135
- * Creates a full URL for a given location.
136
- * @param to - The location to create a URL for.
137
- * @returns The created URL object.
138
- */
139
- createURL(to) {
140
- return this.#history.createURL(to);
141
- }
142
- /**
143
- * Checks if a given location is a duplicate of the current location.
144
- * @param location - The location to check.
145
- * @returns True if the location is a duplicate, false otherwise.
146
- */
147
- _isDuplicateLocation(location) {
148
- // TODO: might check if there are changes in the URL compared to the current location.
149
- return location.key === this.#state.value.location.key;
150
- }
151
- /**
152
- * Disposes of the navigator by unsubscribing from all subscriptions.
153
- */
154
- dispose() {
155
- this.#subscriptions.unsubscribe();
156
- }
157
- }
158
- //# sourceMappingURL=navigator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"navigator.js","sourceRoot":"","sources":["../../src/navigator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAkBjE;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,EAAM,EAAkB,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,KAAK,IAAI,EAAE,CAAC;AAErF;;GAEG;AACH,MAAM,OAAO,SACX,SAAQ,UAAa;IAGrB,QAAQ,CAAU;IAClB,SAAS,CAAU;IACnB,OAAO,GAAY,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC1C,cAAc,GAAG,IAAI,YAAY,EAAE,CAAC;IACpC,MAAM,CAAqB;IAE3B,OAAO,CAAiB;IAExB;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,YAAY,IAMX;QACC,KAAK,C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,EAAE,CAAC;IACpC,CAAC;CACF"}
package/dist/esm/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- import type { History } from '@remix-run/router';
2
- export interface INavigationConfigurator {
3
- basename?: string;
4
- history?: History;
5
- }
6
- export declare class NavigationConfigurator implements INavigationConfigurator {
7
- history?: History;
8
- basename?: string;
9
- }
@@ -1,4 +0,0 @@
1
- import type { History } from '@remix-run/router';
2
- type HistoryType = 'browser' | 'hash' | 'memory';
3
- export declare const createHistory: (type?: HistoryType) => History;
4
- export {};
@@ -1,38 +0,0 @@
1
- import type { Action, AgnosticRouteObject, Path, Router, To } from '@remix-run/router';
2
- import type { INavigator } from '../../navigator';
3
- import type { Observable } from 'rxjs';
4
- import type { IModuleProvider } from '@equinor/fusion-framework-module';
5
- export interface INavigationProvider extends IModuleProvider {
6
- /**
7
- * Observer navigation changes, will return localized paths
8
- */
9
- readonly state$: Observable<{
10
- action: Action;
11
- location: Path;
12
- }>;
13
- /**
14
- * Localized current path
15
- */
16
- readonly path: Path;
17
- /**
18
- * History controller
19
- */
20
- readonly navigator: INavigator;
21
- createRouter(routes: AgnosticRouteObject[]): Router;
22
- /**
23
- * Create a localized pathname
24
- */
25
- createHref(to?: To): string;
26
- /**
27
- * Create a localized URL
28
- */
29
- createURL(to?: To): URL;
30
- /**
31
- * Execute a relative `push` navigation
32
- */
33
- push(to: To, state?: unknown): void;
34
- /**
35
- * Execute a relative `replace` navigation
36
- */
37
- replace(to: To, state?: unknown): void;
38
- }