@equinor/fusion-framework-react-app 9.0.8 → 10.0.0
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 +85 -14
- package/README.md +176 -99
- package/dist/esm/ag-grid/useTheme.js +7 -0
- package/dist/esm/ag-grid/useTheme.js.map +1 -1
- package/dist/esm/analytics/index.js +8 -0
- package/dist/esm/analytics/index.js.map +1 -1
- package/dist/esm/analytics/useTrackFeature.js +17 -1
- package/dist/esm/analytics/useTrackFeature.js.map +1 -1
- package/dist/esm/apploader/Apploader.js +1 -1
- package/dist/esm/apploader/Apploader.js.map +1 -1
- package/dist/esm/apploader/index.js +8 -0
- package/dist/esm/apploader/index.js.map +1 -1
- package/dist/esm/bookmark/index.js +8 -0
- package/dist/esm/bookmark/index.js.map +1 -1
- package/dist/esm/context/index.js +8 -0
- package/dist/esm/context/index.js.map +1 -1
- package/dist/esm/context/useContextProvider.js +6 -0
- package/dist/esm/context/useContextProvider.js.map +1 -1
- package/dist/esm/context/useCurrentContext.js +14 -0
- package/dist/esm/context/useCurrentContext.js.map +1 -1
- package/dist/esm/create-legacy-app.js +13 -0
- package/dist/esm/create-legacy-app.js.map +1 -1
- package/dist/esm/feature-flag/index.js.map +1 -1
- package/dist/esm/feature-flag/useFeature.js +20 -4
- package/dist/esm/feature-flag/useFeature.js.map +1 -1
- package/dist/esm/framework/index.js +8 -1
- package/dist/esm/framework/index.js.map +1 -1
- package/dist/esm/framework/useFrameworkCurrentContext.js +9 -0
- package/dist/esm/framework/useFrameworkCurrentContext.js.map +1 -1
- package/dist/esm/help-center/useHelpCenter.js +12 -1
- package/dist/esm/help-center/useHelpCenter.js.map +1 -1
- package/dist/esm/http/index.js +9 -0
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/http/selectors.js +10 -0
- package/dist/esm/http/selectors.js.map +1 -0
- package/dist/esm/index.js +16 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/make-component.js +1 -1
- package/dist/esm/make-component.js.map +1 -1
- package/dist/esm/msal/index.js +13 -0
- package/dist/esm/msal/index.js.map +1 -1
- package/dist/esm/msal/useAccessToken.js +15 -3
- package/dist/esm/msal/useAccessToken.js.map +1 -1
- package/dist/esm/msal/useCurrentAccount.js +12 -2
- package/dist/esm/msal/useCurrentAccount.js.map +1 -1
- package/dist/esm/msal/useToken.js +19 -3
- package/dist/esm/msal/useToken.js.map +1 -1
- package/dist/esm/navigation/index.js +8 -0
- package/dist/esm/navigation/index.js.map +1 -1
- package/dist/esm/navigation/useNavigationModule.js +6 -1
- package/dist/esm/navigation/useNavigationModule.js.map +1 -1
- package/dist/esm/navigation/useRouter.js +23 -4
- package/dist/esm/navigation/useRouter.js.map +1 -1
- package/dist/esm/render-app.js +22 -1
- package/dist/esm/render-app.js.map +1 -1
- package/dist/esm/render-component.js +30 -23
- package/dist/esm/render-component.js.map +1 -1
- package/dist/esm/settings/index.js +8 -0
- package/dist/esm/settings/index.js.map +1 -1
- package/dist/esm/useAppModule.js +13 -5
- package/dist/esm/useAppModule.js.map +1 -1
- package/dist/esm/useAppModules.js +9 -3
- package/dist/esm/useAppModules.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/ag-grid/useTheme.d.ts +7 -0
- package/dist/types/analytics/index.d.ts +8 -0
- package/dist/types/analytics/useTrackFeature.d.ts +17 -1
- package/dist/types/apploader/Apploader.d.ts +3 -2
- package/dist/types/apploader/index.d.ts +8 -0
- package/dist/types/bookmark/index.d.ts +8 -0
- package/dist/types/context/index.d.ts +8 -0
- package/dist/types/context/useContextProvider.d.ts +6 -0
- package/dist/types/context/useCurrentContext.d.ts +14 -0
- package/dist/types/create-legacy-app.d.ts +13 -0
- package/dist/types/feature-flag/index.d.ts +8 -0
- package/dist/types/feature-flag/useFeature.d.ts +20 -4
- package/dist/types/framework/index.d.ts +8 -0
- package/dist/types/framework/useFrameworkCurrentContext.d.ts +9 -0
- package/dist/types/help-center/useHelpCenter.d.ts +12 -1
- package/dist/types/http/index.d.ts +9 -0
- package/dist/types/http/selectors.d.ts +9 -0
- package/dist/types/index.d.ts +18 -1
- package/dist/types/make-component.d.ts +15 -0
- package/dist/types/msal/index.d.ts +13 -0
- package/dist/types/msal/useAccessToken.d.ts +15 -3
- package/dist/types/msal/useCurrentAccount.d.ts +12 -2
- package/dist/types/msal/useToken.d.ts +19 -3
- package/dist/types/navigation/index.d.ts +8 -0
- package/dist/types/navigation/useNavigationModule.d.ts +6 -1
- package/dist/types/navigation/useRouter.d.ts +23 -4
- package/dist/types/render-app.d.ts +22 -1
- package/dist/types/render-component.d.ts +16 -1
- package/dist/types/settings/index.d.ts +8 -0
- package/dist/types/useAppModule.d.ts +13 -5
- package/dist/types/useAppModules.d.ts +9 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +35 -27
- package/src/__tests__/render-app.test.tsx +113 -0
- package/src/ag-grid/useTheme.ts +7 -0
- package/src/analytics/index.ts +8 -0
- package/src/analytics/useTrackFeature.ts +17 -1
- package/src/apploader/Apploader.tsx +3 -3
- package/src/apploader/index.ts +8 -0
- package/src/bookmark/index.ts +8 -0
- package/src/context/index.ts +8 -0
- package/src/context/useContextProvider.ts +6 -0
- package/src/context/useCurrentContext.ts +14 -0
- package/src/create-legacy-app.tsx +13 -0
- package/src/feature-flag/index.ts +8 -0
- package/src/feature-flag/useFeature.ts +20 -4
- package/src/framework/index.ts +8 -1
- package/src/framework/useFrameworkCurrentContext.ts +9 -0
- package/src/help-center/useHelpCenter.ts +12 -1
- package/src/http/index.ts +9 -0
- package/src/http/selectors.ts +9 -0
- package/src/index.ts +20 -2
- package/src/make-component.tsx +16 -1
- package/src/msal/index.ts +13 -0
- package/src/msal/useAccessToken.ts +15 -3
- package/src/msal/useCurrentAccount.ts +12 -2
- package/src/msal/useToken.ts +19 -3
- package/src/navigation/index.ts +8 -0
- package/src/navigation/useNavigationModule.ts +6 -1
- package/src/navigation/useRouter.ts +23 -4
- package/src/render-app.ts +22 -1
- package/src/render-component.tsx +36 -27
- package/src/settings/index.ts +8 -0
- package/src/useAppModule.ts +13 -5
- package/src/useAppModules.ts +11 -5
- package/src/version.ts +1 -1
- package/tsconfig.json +1 -1
- package/vitest.config.ts +15 -0
package/src/msal/useToken.ts
CHANGED
|
@@ -5,9 +5,25 @@ import type { AuthenticationResult } from '@equinor/fusion-framework-module-msal
|
|
|
5
5
|
import useAppModule from '../useAppModule';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* React hook that acquires a full MSAL {@link AuthenticationResult} for the
|
|
9
|
+
* requested scopes.
|
|
10
|
+
*
|
|
11
|
+
* The hook attempts silent acquisition first and falls back to an interactive
|
|
12
|
+
* prompt when required by the MSAL provider.
|
|
13
|
+
*
|
|
14
|
+
* @param req - The token request containing the `scopes` to acquire.
|
|
15
|
+
* @param req.scopes - Array of scope strings (e.g. `['User.Read']`).
|
|
16
|
+
* @returns An object with:
|
|
17
|
+
* - `token` – the full {@link AuthenticationResult}, or `undefined` while pending.
|
|
18
|
+
* - `pending` – `true` while the token is being acquired.
|
|
19
|
+
* - `error` – any error encountered during acquisition.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const { token, pending } = useToken({ scopes: ['User.Read'] });
|
|
24
|
+
* if (pending) return <Spinner />;
|
|
25
|
+
* console.log('ID token:', token?.idToken);
|
|
26
|
+
* ```
|
|
11
27
|
*/
|
|
12
28
|
export const useToken = (req: {
|
|
13
29
|
scopes: string[];
|
package/src/navigation/index.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for accessing the Fusion navigation module and creating
|
|
5
|
+
* client-side routers compatible with `react-router`.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { useNavigationModule } from './useNavigationModule';
|
|
2
10
|
export { useRouter } from './useRouter';
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import useAppModule from '../useAppModule';
|
|
2
2
|
import type { INavigationProvider } from '@equinor/fusion-framework-module-navigation';
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* React hook that resolves the application-scoped navigation module provider.
|
|
6
|
+
*
|
|
7
|
+
* @returns The navigation provider instance.
|
|
8
|
+
* @throws If the navigation module has not been enabled for the application.
|
|
9
|
+
*/
|
|
5
10
|
export const useNavigationModule = (): INavigationProvider => useAppModule('navigation');
|
|
@@ -3,10 +3,29 @@ import { useNavigationModule } from './useNavigationModule';
|
|
|
3
3
|
import type { INavigationProvider } from '@equinor/fusion-framework-module-navigation';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* React hook that creates a router instance for client-side navigation.
|
|
7
|
+
*
|
|
8
|
+
* The `routes` argument **must** be static or memoised to avoid re-creating
|
|
9
|
+
* the router on every render.
|
|
10
|
+
*
|
|
11
|
+
* @param routes - An array of route objects compatible with
|
|
12
|
+
* `INavigationProvider.createRouter`.
|
|
13
|
+
* @returns A router instance to pass to `<RouterProvider>`.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://equinor.github.io/fusion-framework/modules/navigation/ | Fusion navigation docs}
|
|
16
|
+
* @see {@link https://reactrouter.com/en/main/routers/create-browser-router | react-router docs}
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { useRouter } from '@equinor/fusion-framework-react-app/navigation';
|
|
21
|
+
* import { RouterProvider } from 'react-router-dom';
|
|
22
|
+
*
|
|
23
|
+
* const routes = [{ path: '/', element: <Home /> }];
|
|
24
|
+
* const App = () => {
|
|
25
|
+
* const router = useRouter(routes);
|
|
26
|
+
* return <RouterProvider router={router} />;
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
10
29
|
*/
|
|
11
30
|
export const useRouter = (
|
|
12
31
|
routes: Parameters<INavigationProvider['createRouter']>[0],
|
package/src/render-app.ts
CHANGED
|
@@ -3,7 +3,28 @@ import { renderComponent, type RenderTeardown } from './render-component';
|
|
|
3
3
|
|
|
4
4
|
import type { ComponentRenderArgs } from './create-component';
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Creates a render function for a Fusion React application.
|
|
8
|
+
*
|
|
9
|
+
* Wraps {@link createComponent} and {@link renderComponent} into a single factory:
|
|
10
|
+
* call the returned function with an `HTMLElement` and `ComponentRenderArgs` to
|
|
11
|
+
* mount the app using React 18's `createRoot` API.
|
|
12
|
+
*
|
|
13
|
+
* @param componentArgs - Arguments forwarded to {@link createComponent} (the React
|
|
14
|
+
* component to render and an optional module-configuration callback).
|
|
15
|
+
* @returns A mount function that accepts a DOM element and render args, and returns
|
|
16
|
+
* a {@link RenderTeardown} callback to unmount the application.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { renderApp } from '@equinor/fusion-framework-react-app';
|
|
21
|
+
* import { App } from './App';
|
|
22
|
+
* import { configure } from './config';
|
|
23
|
+
*
|
|
24
|
+
* export const render = renderApp(App, configure);
|
|
25
|
+
* export default render;
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
7
28
|
export const renderApp = (...componentArgs: Parameters<typeof createComponent>) => {
|
|
8
29
|
const renderer = renderComponent(createComponent(...componentArgs));
|
|
9
30
|
return (el: HTMLElement, args: ComponentRenderArgs): RenderTeardown => {
|
package/src/render-component.tsx
CHANGED
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
import { Suspense, StrictMode } from 'react';
|
|
2
2
|
import type { FunctionComponent } from 'react';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
3
4
|
import type { ComponentRenderArgs, ComponentRenderer } from './create-component';
|
|
4
|
-
import ReactDOM from 'react-dom';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Callback returned after mounting an application; invoke it to unmount and clean
|
|
8
|
+
* up the React root.
|
|
9
|
+
*/
|
|
6
10
|
export type RenderTeardown = VoidFunction;
|
|
7
11
|
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Renders a React component into a DOM element using React 18's `createRoot` API.
|
|
14
|
+
*
|
|
15
|
+
* The component is wrapped in `<StrictMode>` and `<Suspense>` with a basic
|
|
16
|
+
* loading fallback.
|
|
17
|
+
*
|
|
18
|
+
* @param el - The DOM element to render into.
|
|
19
|
+
* @param Component - The React function component to render.
|
|
20
|
+
* @returns A {@link RenderTeardown} callback that unmounts the component.
|
|
21
|
+
*/
|
|
16
22
|
const render = (el: Element, Component: FunctionComponent): RenderTeardown => {
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
const root: Root = createRoot(el);
|
|
24
|
+
root.render(
|
|
19
25
|
<StrictMode>
|
|
20
26
|
<Suspense fallback={<p>loading app</p>}>
|
|
21
27
|
<Component />
|
|
22
28
|
</Suspense>
|
|
23
29
|
</StrictMode>,
|
|
24
|
-
el,
|
|
25
30
|
);
|
|
26
31
|
return () => {
|
|
27
|
-
|
|
28
|
-
ReactDOM.unmountComponentAtNode(el);
|
|
32
|
+
root.unmount();
|
|
29
33
|
};
|
|
30
34
|
};
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Creates a mount function from a {@link ComponentRenderer}.
|
|
38
|
+
*
|
|
39
|
+
* The returned function accepts a target `HTMLElement` and
|
|
40
|
+
* {@link ComponentRenderArgs}, resolves the lazy component via the renderer,
|
|
41
|
+
* and mounts it with React 18's `createRoot`.
|
|
42
|
+
*
|
|
43
|
+
* @param renderer - A {@link ComponentRenderer} that produces a lazy component
|
|
44
|
+
* from Fusion and environment arguments.
|
|
45
|
+
* @returns A function `(el, args) => RenderTeardown` that mounts the app and
|
|
46
|
+
* returns a teardown callback.
|
|
47
|
+
*/
|
|
48
|
+
export const renderComponent = (renderer: ComponentRenderer) => {
|
|
49
|
+
return (el: HTMLElement, args: ComponentRenderArgs): RenderTeardown => {
|
|
50
|
+
const Component = renderer(args.fusion, args.env);
|
|
51
|
+
return render(el, Component);
|
|
52
|
+
};
|
|
53
|
+
};
|
|
45
54
|
|
|
46
55
|
export default renderComponent;
|
package/src/settings/index.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings sub-path entry-point.
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for reading and updating per-application user settings
|
|
5
|
+
* that are persisted by the Fusion platform.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
export { useAppSetting } from './useAppSetting';
|
|
2
10
|
export { useAppSettings } from './useAppSettings';
|
|
3
11
|
|
package/src/useAppModule.ts
CHANGED
|
@@ -9,12 +9,20 @@ import type {
|
|
|
9
9
|
import { useAppModules } from './useAppModules';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* React hook that retrieves a single module instance from the application scope.
|
|
13
13
|
*
|
|
14
|
-
* @template TType - The
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
14
|
+
* @template TType - The concrete module type (e.g. `ContextModule`). Pass
|
|
15
|
+
* `unknown` to infer the type from the key.
|
|
16
|
+
* @template TKey - The string key used to look up the module.
|
|
17
|
+
* @param module - The key identifying the module to retrieve.
|
|
18
|
+
* @returns The resolved module instance.
|
|
19
|
+
* @throws If the requested module is not registered in the application scope.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const auth = useAppModule('auth');
|
|
24
|
+
* auth.acquireAccessToken().then(console.log);
|
|
25
|
+
* ```
|
|
18
26
|
*/
|
|
19
27
|
export function useAppModule<
|
|
20
28
|
TType extends AnyModule | unknown = unknown,
|
package/src/useAppModules.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import type { AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
1
|
+
import type { AppModules, AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
2
2
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
3
|
import { useModules } from '@equinor/fusion-framework-react-module';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* React hook that returns the full set of initialised application-scoped modules.
|
|
7
7
|
*
|
|
8
|
-
* @template T -
|
|
9
|
-
* @returns
|
|
8
|
+
* @template T - Optional array of additional module types beyond the defaults.
|
|
9
|
+
* @returns The {@link AppModulesInstance} containing all registered modules.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const modules = useAppModules();
|
|
14
|
+
* console.log(Object.keys(modules));
|
|
15
|
+
* ```
|
|
10
16
|
*/
|
|
11
17
|
export const useAppModules = <
|
|
12
18
|
T extends Array<AnyModule> | unknown = unknown,
|
|
13
|
-
>(): AppModulesInstance<T> => useModules<
|
|
19
|
+
>(): AppModulesInstance<T> => useModules<AppModules<T>>() as AppModulesInstance<T>;
|
|
14
20
|
|
|
15
21
|
export default useAppModules;
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '10.0.0';
|
package/tsconfig.json
CHANGED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineProject } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
import { name, version } from './package.json';
|
|
4
|
+
|
|
5
|
+
export default defineProject({
|
|
6
|
+
resolve: {
|
|
7
|
+
// @ts-expect-error -- tsconfigPaths is a Vite 8 option; vitest 4.x ships Vite 7 types
|
|
8
|
+
tsconfigPaths: true,
|
|
9
|
+
},
|
|
10
|
+
test: {
|
|
11
|
+
include: ['src/__tests__/**'],
|
|
12
|
+
name: `${name}@${version}`,
|
|
13
|
+
environment: 'happy-dom',
|
|
14
|
+
},
|
|
15
|
+
});
|