@equinor/fusion-framework-module-navigation 7.0.9-next.0 → 7.0.10
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/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -600
- package/src/NavigateEvent.ts +0 -47
- package/src/NavigatedEvent.ts +0 -35
- package/src/NavigationConfigurator.interface.ts +0 -41
- package/src/NavigationConfigurator.ts +0 -226
- package/src/NavigationProvider.interface.ts +0 -99
- package/src/NavigationProvider.ts +0 -436
- package/src/__tests__/BrowserHistory.test.ts +0 -151
- package/src/__tests__/HashHistory.test.ts +0 -121
- package/src/__tests__/MemoryHistory.test.ts +0 -185
- package/src/__tests__/NavigationProvider.test.ts +0 -302
- package/src/__tests__/ProxyHistory.test.ts +0 -149
- package/src/__tests__/setup.ts +0 -8
- package/src/enable-navigation.ts +0 -60
- package/src/index.ts +0 -51
- package/src/lib/BaseHistory.ts +0 -255
- package/src/lib/BrowserHistory.ts +0 -124
- package/src/lib/BrowserHistoryHashStack.ts +0 -57
- package/src/lib/BrowserHistoryStack.ts +0 -96
- package/src/lib/MemoryHistory.ts +0 -76
- package/src/lib/MemoryHistoryStack.ts +0 -118
- package/src/lib/ProxyHistory.ts +0 -145
- package/src/lib/create-history.ts +0 -58
- package/src/lib/index.ts +0 -33
- package/src/lib/state/actions.ts +0 -108
- package/src/lib/state/check-blockers.ts +0 -52
- package/src/lib/state/create-flow.ts +0 -36
- package/src/lib/state/create-history-reducer.ts +0 -77
- package/src/lib/state/create-store.ts +0 -39
- package/src/lib/state/flow-creators.ts +0 -7
- package/src/lib/state/go.ts +0 -20
- package/src/lib/state/history.state.ts +0 -14
- package/src/lib/state/index.ts +0 -4
- package/src/lib/state/navigate.ts +0 -58
- package/src/lib/state/pop.ts +0 -24
- package/src/lib/state/validate-current-location.ts +0 -33
- package/src/lib/types.ts +0 -190
- package/src/lib/utils/encode-trailing-whitespace.ts +0 -18
- package/src/lib/utils/has-protocol.ts +0 -21
- package/src/lib/utils/index.ts +0 -5
- package/src/lib/utils/path-to-string.ts +0 -24
- package/src/lib/utils/path-to-url.ts +0 -52
- package/src/lib/utils/resolve-browser-location.ts +0 -1
- package/src/lib/utils/resolve-hash-location.ts +0 -26
- package/src/lib/utils/resolve-path.ts +0 -22
- package/src/lib/utils/resolve-window-location.ts +0 -24
- package/src/module.ts +0 -80
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -14
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { resolveWindowLocation } from './resolve-window-location';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Location } from '../types';
|
|
2
|
-
import { resolvePath } from './resolve-path';
|
|
3
|
-
import { resolveWindowLocation } from './resolve-window-location';
|
|
4
|
-
|
|
5
|
-
const resolveState = (target?: { state: unknown }): { state: unknown; key: string } => {
|
|
6
|
-
const { value, key = 'unknown' } =
|
|
7
|
-
(target ?? window.history).state ??
|
|
8
|
-
({} as {
|
|
9
|
-
value: unknown;
|
|
10
|
-
key?: string;
|
|
11
|
-
});
|
|
12
|
-
return { state: value, key };
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Resolves the current location from window.location.hash.
|
|
17
|
-
* @param window - The window object to extract location from.
|
|
18
|
-
* @param target - Optional target object with state.
|
|
19
|
-
* @returns The current hash-based navigation location.
|
|
20
|
-
*/
|
|
21
|
-
export const resolveHashLocation = (window: Window, target?: { state: unknown }): Location => {
|
|
22
|
-
const location = resolveWindowLocation(window, target);
|
|
23
|
-
const { pathname, search, hash } = resolvePath(location.hash?.replace('#', '') ?? '');
|
|
24
|
-
const { state, key } = resolveState(target);
|
|
25
|
-
return { pathname, search, hash, state, key, unstable_mask: undefined };
|
|
26
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
* @param window - The window object to extract location from.
|
|
17
|
-
* @param target - Optional target object with state.
|
|
18
|
-
* @returns The current browser navigation location.
|
|
19
|
-
*/
|
|
20
|
-
export const resolveWindowLocation = (window: Window, target?: { state: unknown }): Location => {
|
|
21
|
-
const { pathname, search, hash } = resolvePath(window.location);
|
|
22
|
-
const { state, key } = resolveState(target);
|
|
23
|
-
return { pathname, search, hash, state, key, unstable_mask: undefined };
|
|
24
|
-
};
|
package/src/module.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
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';
|
|
5
|
-
|
|
6
|
-
import { version } from './version';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Module key identifier for the navigation module.
|
|
10
|
-
*/
|
|
11
|
-
export const moduleKey = 'navigation';
|
|
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
|
-
*/
|
|
30
|
-
export type NavigationModule = Module<
|
|
31
|
-
typeof moduleKey,
|
|
32
|
-
INavigationProvider,
|
|
33
|
-
NavigationConfigurator
|
|
34
|
-
>;
|
|
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
|
-
*/
|
|
45
|
-
export const module: NavigationModule = {
|
|
46
|
-
version: new SemanticVersion(version),
|
|
47
|
-
name: moduleKey,
|
|
48
|
-
/**
|
|
49
|
-
* Creates a new {@link NavigationConfigurator} for the module.
|
|
50
|
-
*
|
|
51
|
-
* @returns A fresh {@link NavigationConfigurator} instance with default settings
|
|
52
|
-
*/
|
|
53
|
-
configure: () => new NavigationConfigurator(),
|
|
54
|
-
/**
|
|
55
|
-
* Initializes the navigation module with validated configuration.
|
|
56
|
-
*
|
|
57
|
-
* @param init - Module initialization arguments containing config and refs
|
|
58
|
-
* @returns A promise that resolves to a configured {@link NavigationProvider}
|
|
59
|
-
*/
|
|
60
|
-
initialize: async (init) => {
|
|
61
|
-
const config = await init.config.createConfigAsync(init);
|
|
62
|
-
return new NavigationProvider({ version, config });
|
|
63
|
-
},
|
|
64
|
-
/**
|
|
65
|
-
* Disposes of the navigation module instance.
|
|
66
|
-
*
|
|
67
|
-
* @param instance - The NavigationProvider instance to dispose
|
|
68
|
-
*/
|
|
69
|
-
dispose({ instance }) {
|
|
70
|
-
instance.dispose();
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export default module;
|
|
75
|
-
|
|
76
|
-
declare module '@equinor/fusion-framework-module' {
|
|
77
|
-
interface Modules {
|
|
78
|
-
navigation: NavigationModule;
|
|
79
|
-
}
|
|
80
|
-
}
|
package/src/version.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "dist/esm",
|
|
5
|
-
"rootDir": "src",
|
|
6
|
-
"declarationDir": "./dist/types"
|
|
7
|
-
},
|
|
8
|
-
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "../module"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"path": "../telemetry"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"path": "../event"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"path": "../../utils/observable"
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
"include": ["src/**/*"],
|
|
23
|
-
"exclude": ["node_modules", "lib", "src/__tests__/**/*"]
|
|
24
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineProject } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
import { name, version } from './package.json' with { type: '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
|
-
});
|