@equinor/fusion-framework-react-app 0.0.0-next-20230915111233
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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +1031 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/esm/bookmark/index.js +3 -0
- package/dist/esm/bookmark/index.js.map +1 -0
- package/dist/esm/bookmark/useBookmark.js +4 -0
- package/dist/esm/bookmark/useBookmark.js.map +1 -0
- package/dist/esm/bookmark/useCurrentBookmark.js +4 -0
- package/dist/esm/bookmark/useCurrentBookmark.js.map +1 -0
- package/dist/esm/context/index.js +5 -0
- package/dist/esm/context/index.js.map +1 -0
- package/dist/esm/context/useContextProvider.js +4 -0
- package/dist/esm/context/useContextProvider.js.map +1 -0
- package/dist/esm/context/useCurrentContext.js +5 -0
- package/dist/esm/context/useCurrentContext.js.map +1 -0
- package/dist/esm/create-component.js +30 -0
- package/dist/esm/create-component.js.map +1 -0
- package/dist/esm/create-legacy-app.js +21 -0
- package/dist/esm/create-legacy-app.js.map +1 -0
- package/dist/esm/framework/index.js +3 -0
- package/dist/esm/framework/index.js.map +1 -0
- package/dist/esm/framework/useFrameworkCurrentContext.js +5 -0
- package/dist/esm/framework/useFrameworkCurrentContext.js.map +1 -0
- package/dist/esm/http/index.js +2 -0
- package/dist/esm/http/index.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/make-component.js +28 -0
- package/dist/esm/make-component.js.map +1 -0
- package/dist/esm/navigation/index.js +3 -0
- package/dist/esm/navigation/index.js.map +1 -0
- package/dist/esm/navigation/useNavigationModule.js +3 -0
- package/dist/esm/navigation/useNavigationModule.js.map +1 -0
- package/dist/esm/navigation/useRouter.js +7 -0
- package/dist/esm/navigation/useRouter.js.map +1 -0
- package/dist/esm/render-app.js +10 -0
- package/dist/esm/render-app.js.map +1 -0
- package/dist/esm/render-component.js +17 -0
- package/dist/esm/render-component.js.map +1 -0
- package/dist/esm/useAppModule.js +10 -0
- package/dist/esm/useAppModule.js.map +1 -0
- package/dist/esm/useAppModules.js +4 -0
- package/dist/esm/useAppModules.js.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/bookmark/index.d.ts +3 -0
- package/dist/types/bookmark/useBookmark.d.ts +2 -0
- package/dist/types/bookmark/useCurrentBookmark.d.ts +3 -0
- package/dist/types/context/index.d.ts +4 -0
- package/dist/types/context/useContextProvider.d.ts +2 -0
- package/dist/types/context/useCurrentContext.d.ts +5 -0
- package/dist/types/create-component.d.ts +21 -0
- package/dist/types/create-legacy-app.d.ts +4 -0
- package/dist/types/framework/index.d.ts +2 -0
- package/dist/types/framework/useFrameworkCurrentContext.d.ts +5 -0
- package/dist/types/http/index.d.ts +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/make-component.d.ts +24 -0
- package/dist/types/navigation/index.d.ts +2 -0
- package/dist/types/navigation/useNavigationModule.d.ts +2 -0
- package/dist/types/navigation/useRouter.d.ts +2 -0
- package/dist/types/render-app.d.ts +5 -0
- package/dist/types/render-component.d.ts +4 -0
- package/dist/types/useAppModule.d.ts +4 -0
- package/dist/types/useAppModules.d.ts +3 -0
- package/dist/types/version.d.ts +1 -0
- package/package.json +89 -0
- package/src/bookmark/index.ts +4 -0
- package/src/bookmark/useBookmark.ts +21 -0
- package/src/bookmark/useCurrentBookmark.ts +21 -0
- package/src/context/index.ts +6 -0
- package/src/context/useContextProvider.ts +6 -0
- package/src/context/useCurrentContext.ts +6 -0
- package/src/create-component.tsx +114 -0
- package/src/create-legacy-app.tsx +35 -0
- package/src/framework/index.ts +7 -0
- package/src/framework/useFrameworkCurrentContext.ts +6 -0
- package/src/http/index.ts +1 -0
- package/src/index.ts +30 -0
- package/src/make-component.tsx +74 -0
- package/src/navigation/index.ts +2 -0
- package/src/navigation/useNavigationModule.ts +5 -0
- package/src/navigation/useRouter.ts +16 -0
- package/src/render-app.ts +14 -0
- package/src/render-component.tsx +46 -0
- package/src/useAppModule.ts +31 -0
- package/src/useAppModules.ts +9 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ComponentRenderArgs, ComponentRenderer } from './create-component';
|
|
2
|
+
export type RenderTeardown = VoidFunction;
|
|
3
|
+
export declare const renderComponent: (renderer: ComponentRenderer) => (el: HTMLElement, args: ComponentRenderArgs) => RenderTeardown;
|
|
4
|
+
export default renderComponent;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AppModules, AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
2
|
+
import { AnyModule, ModuleKey, ModuleType, ModuleTypes } from '@equinor/fusion-framework-module';
|
|
3
|
+
export declare const useAppModule: <TType extends unknown = unknown, TKey extends string = ModuleKey<ModuleTypes<AppModules<[TType]>>>>(module: TKey) => TType extends AnyModule ? ModuleType<TType> : AppModulesInstance[Extract<"event", TKey> | Extract<"http", TKey> | Extract<"auth", TKey> | Extract<"dispose", TKey>];
|
|
4
|
+
export default useAppModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "4.1.6";
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/fusion-framework-react-app",
|
|
3
|
+
"version": "0.0.0-next-20230915111233",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/esm/index.js",
|
|
8
|
+
"./bookmark": "./dist/esm/bookmark/index.js",
|
|
9
|
+
"./context": "./dist/esm/context/index.js",
|
|
10
|
+
"./framework": "./dist/esm/framework/index.js",
|
|
11
|
+
"./http": "./dist/esm/http/index.js",
|
|
12
|
+
"./navigation": "./dist/esm/navigation/index.js"
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
"*": {
|
|
17
|
+
"bookmark": [
|
|
18
|
+
"dist/types/bookmark/index.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"context": [
|
|
21
|
+
"dist/types/context/index.d.ts"
|
|
22
|
+
],
|
|
23
|
+
"framework": [
|
|
24
|
+
"dist/types/framework/index.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"http": [
|
|
27
|
+
"dist/types/http/index.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"navigation": [
|
|
30
|
+
"dist/types/navigation/index.d.ts"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"keywords": [],
|
|
35
|
+
"author": "",
|
|
36
|
+
"license": "ISC",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/equinor/fusion-framework.git",
|
|
43
|
+
"directory": "packages/react"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@equinor/fusion-framework-app": "^0.0.0-next-20230915111233",
|
|
47
|
+
"@equinor/fusion-framework-module": "^4.2.4",
|
|
48
|
+
"@equinor/fusion-framework-react": "^0.0.0-next-20230915111233",
|
|
49
|
+
"@equinor/fusion-framework-module-navigation": "^3.0.5",
|
|
50
|
+
"@equinor/fusion-framework-module-app": "^0.0.0-next-20230915111233",
|
|
51
|
+
"@equinor/fusion-framework-react-module-http": "^0.0.0-next-20230915111233",
|
|
52
|
+
"@equinor/fusion-framework-react-module": "^3.0.5"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/react": "^18.2.20",
|
|
56
|
+
"@types/react-dom": "^18.2.7",
|
|
57
|
+
"react": "^18.2.0",
|
|
58
|
+
"react-dom": "^18.2.0",
|
|
59
|
+
"typescript": "^5.1.3",
|
|
60
|
+
"@equinor/fusion-framework-module-event": "^4.0.5",
|
|
61
|
+
"@equinor/fusion-framework-react-module-bookmark": "^0.0.0-next-20230915111233",
|
|
62
|
+
"@equinor/fusion-framework-react-module-context": "^0.0.0-next-20230915111233"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@types/react": "^17.0.0 || ^18.0.0",
|
|
66
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
67
|
+
"react-dom": "^17.0.0 || ^18.0.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"@equinor/fusion-framework-react-module-context": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"@equinor/fusion-framework-module-navigation": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"@equinor/fusion-framework-react-module-bookmark": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"@types/react": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"react-dom": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"scripts": {
|
|
87
|
+
"build": "tsc -b"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useBookmark as _useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* For application development the useCurrentBookmark should be sufficient enough
|
|
5
|
+
*
|
|
6
|
+
* Functionality provided here is:
|
|
7
|
+
* - addBookmarkCreator
|
|
8
|
+
* - getAllBookmarks
|
|
9
|
+
* - createBookmark
|
|
10
|
+
* - updateBookmark
|
|
11
|
+
* - deleteBookmarkById
|
|
12
|
+
* - setCurrentBookmark
|
|
13
|
+
* - currentBookmark
|
|
14
|
+
* - bookmarks,
|
|
15
|
+
*
|
|
16
|
+
* @template TData - Current applications bookmark type
|
|
17
|
+
* @return {*} {Bookmarks<TData>} the full api fro handling bookmarks
|
|
18
|
+
*/
|
|
19
|
+
export const useBookmark = <TData>() => _useBookmark<TData>();
|
|
20
|
+
|
|
21
|
+
export default useBookmark;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreateBookMarkFn,
|
|
3
|
+
useCurrentBookmark as _useCurrentBookmark,
|
|
4
|
+
} from '@equinor/fusion-framework-react-module-bookmark';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* By providing a CreateBookMarkFn bookmarks is enabled for the current application.
|
|
8
|
+
*
|
|
9
|
+
* @template TData - Type of data stored in bookmark
|
|
10
|
+
* @param {CreateBookMarkFn<TData>} [createBookmarkState] - Function for creating bookmark payload, this function should be wrapped in useCallback
|
|
11
|
+
*
|
|
12
|
+
* ```TS
|
|
13
|
+
* // Example
|
|
14
|
+
* const { currentBookmark } = useCurrentBookmark(useCallback(()=> someState, [someState]))
|
|
15
|
+
* ```
|
|
16
|
+
* @return {*} {CurrentBookmark<TData>}
|
|
17
|
+
*/
|
|
18
|
+
export const useCurrentBookmark = <TData>(createBookmarkState?: CreateBookMarkFn<TData>) =>
|
|
19
|
+
_useCurrentBookmark(createBookmarkState);
|
|
20
|
+
|
|
21
|
+
export default useCurrentBookmark;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from '@equinor/fusion-framework-react-module-context';
|
|
2
|
+
|
|
3
|
+
export { useContextProvider } from './useContextProvider';
|
|
4
|
+
export { useCurrentContext } from './useCurrentContext';
|
|
5
|
+
|
|
6
|
+
export { useFrameworkCurrentContext } from '../framework/useFrameworkCurrentContext';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useCurrentContext as _useCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
2
|
+
import useContextProvider from './useContextProvider';
|
|
3
|
+
|
|
4
|
+
export const useCurrentContext = () => _useCurrentContext(useContextProvider());
|
|
5
|
+
|
|
6
|
+
export default useCurrentContext;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import React, { lazy } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FrameworkProvider } from '@equinor/fusion-framework-react';
|
|
4
|
+
import type { Fusion } from '@equinor/fusion-framework-react';
|
|
5
|
+
|
|
6
|
+
import { AppEnv, configureModules } from '@equinor/fusion-framework-app';
|
|
7
|
+
import type { AppModuleInitiator, AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
8
|
+
|
|
9
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
10
|
+
|
|
11
|
+
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
12
|
+
|
|
13
|
+
import { ModuleProvider as AppModuleProvider } from '@equinor/fusion-framework-react-module';
|
|
14
|
+
|
|
15
|
+
export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
|
|
16
|
+
fusion: TFusion;
|
|
17
|
+
env: TEnv;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ComponentRenderer<TFusion extends Fusion = Fusion, TEnv = AppEnv> = (
|
|
21
|
+
fusion: TFusion,
|
|
22
|
+
env: TEnv,
|
|
23
|
+
) => React.LazyExoticComponent<React.ComponentType>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated
|
|
27
|
+
* Creates an lazy loading Component which configures modules
|
|
28
|
+
* and provides context to framework and configured modules
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
* ```mermaid
|
|
32
|
+
* sequenceDiagram
|
|
33
|
+
* App ->>+Framework: createApp
|
|
34
|
+
* Framework->>-Framework: initializeModules
|
|
35
|
+
* Framework->>App: configure(modules, framework, args)
|
|
36
|
+
* App-->Framework: await configuration
|
|
37
|
+
* Framework->>App: React.LazyExoticComponent
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* const configCallback: AppConfigurator = (configurator) => {
|
|
43
|
+
* configurator.http.configureClient(
|
|
44
|
+
* 'bar', {
|
|
45
|
+
* baseUri: 'https://somewhere-test.com',
|
|
46
|
+
* defaultScopes: ['foo/.default']
|
|
47
|
+
* }
|
|
48
|
+
* );
|
|
49
|
+
* };
|
|
50
|
+
*
|
|
51
|
+
* export const App = () => {
|
|
52
|
+
* const client = useHttpClient('bar');
|
|
53
|
+
* const [foo, setFoo] = useState('no value');
|
|
54
|
+
* const onClick = useCallback(() => {
|
|
55
|
+
* client.fetchAsync('api').then(x => x.json).then(setFoo);
|
|
56
|
+
* }, [client]);
|
|
57
|
+
* return <Button onClick={onClick}>{foo}</Button>
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* export const render = createApp(App, configCallback);
|
|
61
|
+
*
|
|
62
|
+
* export default render;
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
*
|
|
66
|
+
* __Exposed providers__
|
|
67
|
+
* @see {@link @equinor/fusion-framework-react.FrameworkProvider | FrameworkProvider}
|
|
68
|
+
* @see {@link ModuleProvider | ModuleProvider}
|
|
69
|
+
*
|
|
70
|
+
* @template TModules module types included in configuration.
|
|
71
|
+
* @param Component - React component to render
|
|
72
|
+
* @param configure - Callback for configuring application
|
|
73
|
+
* @param modules - required modules for application
|
|
74
|
+
*/
|
|
75
|
+
export const createComponent =
|
|
76
|
+
<TModules extends Array<AnyModule>, TRef extends Fusion = Fusion, TEnv extends AppEnv = AppEnv>(
|
|
77
|
+
Component: React.ElementType,
|
|
78
|
+
configure?: AppModuleInitiator<TModules, TRef, TEnv>,
|
|
79
|
+
): ComponentRenderer<TRef, TEnv> =>
|
|
80
|
+
(fusion, env) =>
|
|
81
|
+
lazy(async () => {
|
|
82
|
+
const init = configureModules<TModules, TRef, TEnv>(configure);
|
|
83
|
+
const modules = (await init({
|
|
84
|
+
fusion,
|
|
85
|
+
env,
|
|
86
|
+
})) as unknown as AppModulesInstance;
|
|
87
|
+
|
|
88
|
+
modules.event.dispatchEvent('onReactAppLoaded', {
|
|
89
|
+
detail: { modules, fusion },
|
|
90
|
+
source: Component,
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
default: () => (
|
|
94
|
+
<FrameworkProvider value={fusion}>
|
|
95
|
+
<AppModuleProvider value={modules}>
|
|
96
|
+
{/* TODO */}
|
|
97
|
+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment*/}
|
|
98
|
+
{/* @ts-ignore */}
|
|
99
|
+
<Component />
|
|
100
|
+
</AppModuleProvider>
|
|
101
|
+
</FrameworkProvider>
|
|
102
|
+
),
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
declare module '@equinor/fusion-framework-module-event' {
|
|
107
|
+
interface FrameworkEventMap {
|
|
108
|
+
onReactAppLoaded: FrameworkEvent<
|
|
109
|
+
FrameworkEventInit<{ modules: AppModulesInstance; fusion: Fusion }, React.ComponentType>
|
|
110
|
+
>;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default createComponent;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Suspense, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
4
|
+
|
|
5
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
6
|
+
import type { AppEnv, AppModuleInitiator } from '@equinor/fusion-framework-app';
|
|
7
|
+
|
|
8
|
+
import { createComponent } from './create-component';
|
|
9
|
+
import { AppModule } from '@equinor/fusion-framework-module-app';
|
|
10
|
+
|
|
11
|
+
export const createLegacyApp = <TModules extends Array<AnyModule>>(
|
|
12
|
+
Component: React.ElementType,
|
|
13
|
+
configure?: AppModuleInitiator<TModules>,
|
|
14
|
+
) => {
|
|
15
|
+
const LegacyComponent = (): JSX.Element => {
|
|
16
|
+
const fusion = useFramework<[AppModule]>();
|
|
17
|
+
const RenderComponent = useMemo(() => {
|
|
18
|
+
const creator = createComponent(Component, configure);
|
|
19
|
+
// @eikeland
|
|
20
|
+
// TODO - recheck when legacy fusion-cli is updated!
|
|
21
|
+
const appProvider = fusion.modules.app;
|
|
22
|
+
if (appProvider?.current) {
|
|
23
|
+
const { config, manifest } = appProvider.current;
|
|
24
|
+
return creator(fusion, { config, manifest } as unknown as AppEnv);
|
|
25
|
+
}
|
|
26
|
+
return creator(fusion, {} as unknown as AppEnv);
|
|
27
|
+
}, [fusion]);
|
|
28
|
+
return (
|
|
29
|
+
<Suspense fallback={<p>loading app</p>}>
|
|
30
|
+
<RenderComponent />
|
|
31
|
+
</Suspense>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
return LegacyComponent;
|
|
35
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
2
|
+
import { useCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
3
|
+
|
|
4
|
+
export const useFrameworkCurrentContext = () => useCurrentContext(useFramework().modules.context);
|
|
5
|
+
|
|
6
|
+
export default useFrameworkCurrentContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@equinor/fusion-framework-react-module-http';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [[include:react-app/README.MD]]
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type {
|
|
7
|
+
AppConfig,
|
|
8
|
+
AppEnv,
|
|
9
|
+
AppModuleInitiator,
|
|
10
|
+
AppModules,
|
|
11
|
+
AppModulesInstance,
|
|
12
|
+
AppManifest,
|
|
13
|
+
IAppConfigurator,
|
|
14
|
+
} from '@equinor/fusion-framework-app';
|
|
15
|
+
|
|
16
|
+
export { useAppModule } from './useAppModule';
|
|
17
|
+
export { useAppModules } from './useAppModules';
|
|
18
|
+
|
|
19
|
+
export { makeComponent, ComponentRenderArgs } from './make-component';
|
|
20
|
+
|
|
21
|
+
export { createLegacyApp } from './create-legacy-app';
|
|
22
|
+
|
|
23
|
+
// TODO deprecate
|
|
24
|
+
export { renderApp } from './render-app';
|
|
25
|
+
export { createComponent } from './create-component';
|
|
26
|
+
export { renderComponent } from './render-component';
|
|
27
|
+
|
|
28
|
+
export type { ComponentRenderer } from './create-component';
|
|
29
|
+
|
|
30
|
+
export { default } from './render-app';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { lazy } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FrameworkProvider } from '@equinor/fusion-framework-react';
|
|
4
|
+
import type { Fusion } from '@equinor/fusion-framework-react';
|
|
5
|
+
|
|
6
|
+
import { AppEnv, configureModules } from '@equinor/fusion-framework-app';
|
|
7
|
+
import type { AppModuleInitiator, AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
8
|
+
|
|
9
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
10
|
+
|
|
11
|
+
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
12
|
+
|
|
13
|
+
import { ModuleProvider as AppModuleProvider } from '@equinor/fusion-framework-react-module';
|
|
14
|
+
|
|
15
|
+
export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
|
|
16
|
+
fusion: TFusion;
|
|
17
|
+
env: TEnv;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ComponentRenderer<TFusion extends Fusion = Fusion, TEnv = AppEnv> = (
|
|
21
|
+
fusion: TFusion,
|
|
22
|
+
env: TEnv,
|
|
23
|
+
) => React.LazyExoticComponent<React.ComponentType>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates an lazy loading Component which configures modules
|
|
27
|
+
* and provides context to framework and configured modules
|
|
28
|
+
*
|
|
29
|
+
* __Exposed providers__
|
|
30
|
+
* @see {@link @equinor/fusion-framework-react.FrameworkProvider | FrameworkProvider}
|
|
31
|
+
* @see {@link ModuleProvider | ModuleProvider}
|
|
32
|
+
*
|
|
33
|
+
* @template TModules module types included in configuration.
|
|
34
|
+
* @param Component - React component to render
|
|
35
|
+
* @param configure - Callback for configuring application
|
|
36
|
+
* @param modules - required modules for application
|
|
37
|
+
*/
|
|
38
|
+
export const makeComponent = <
|
|
39
|
+
TModules extends Array<AnyModule>,
|
|
40
|
+
TRef extends Fusion = Fusion,
|
|
41
|
+
TEnv extends AppEnv = AppEnv,
|
|
42
|
+
>(
|
|
43
|
+
Component: React.ReactNode,
|
|
44
|
+
args: { fusion: TRef; env: TEnv },
|
|
45
|
+
configure?: AppModuleInitiator<TModules, TRef, TEnv>,
|
|
46
|
+
) =>
|
|
47
|
+
lazy(async () => {
|
|
48
|
+
const init = configureModules<TModules, TRef, TEnv>(configure);
|
|
49
|
+
const modules = (await init(args)) as unknown as AppModulesInstance;
|
|
50
|
+
|
|
51
|
+
const { fusion } = args;
|
|
52
|
+
|
|
53
|
+
modules.event.dispatchEvent('onReactAppLoaded', {
|
|
54
|
+
detail: { modules, fusion },
|
|
55
|
+
source: Component,
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
default: () => (
|
|
59
|
+
<FrameworkProvider value={fusion}>
|
|
60
|
+
<AppModuleProvider value={modules}>{Component}</AppModuleProvider>
|
|
61
|
+
</FrameworkProvider>
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
declare module '@equinor/fusion-framework-module-event' {
|
|
67
|
+
interface FrameworkEventMap {
|
|
68
|
+
onReactAppLoaded: FrameworkEvent<
|
|
69
|
+
FrameworkEventInit<{ modules: AppModulesInstance; fusion: Fusion }, React.ComponentType>
|
|
70
|
+
>;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default makeComponent;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import useAppModule from '../useAppModule';
|
|
2
|
+
import { INavigationProvider } from '@equinor/fusion-framework-module-navigation';
|
|
3
|
+
|
|
4
|
+
/** hook for getting the navigation provider (if enabled!) */
|
|
5
|
+
export const useNavigationModule = (): INavigationProvider => useAppModule('navigation');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useNavigationModule } from './useNavigationModule';
|
|
3
|
+
import { type INavigationProvider } from '@equinor/fusion-framework-module-navigation';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* create a router for react routing
|
|
7
|
+
* @see {@link [docs](https://equinor.github.io/fusion-framework/modules/navigation/)}
|
|
8
|
+
* @see {@link [react-router](https://reactrouter.com/en/main/routers/create-browser-router)}
|
|
9
|
+
* @param routes router objects __(must be static | memorized)__
|
|
10
|
+
*/
|
|
11
|
+
export const useRouter = (
|
|
12
|
+
routes: Parameters<INavigationProvider['createRouter']>[0],
|
|
13
|
+
): ReturnType<INavigationProvider['createRouter']> => {
|
|
14
|
+
const provider = useNavigationModule();
|
|
15
|
+
return useMemo(() => provider.createRouter(routes), [provider, routes]);
|
|
16
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createComponent } from './create-component';
|
|
2
|
+
import { renderComponent, RenderTeardown } from './render-component';
|
|
3
|
+
|
|
4
|
+
import type { ComponentRenderArgs } from './create-component';
|
|
5
|
+
|
|
6
|
+
/** @deprecated */
|
|
7
|
+
export const renderApp = (...componentArgs: Parameters<typeof createComponent>) => {
|
|
8
|
+
const renderer = renderComponent(createComponent(...componentArgs));
|
|
9
|
+
return (el: HTMLElement, args: ComponentRenderArgs): RenderTeardown => {
|
|
10
|
+
return renderer(el, args);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default renderApp;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Suspense, StrictMode } from 'react';
|
|
2
|
+
import type { FunctionComponent } from 'react';
|
|
3
|
+
import type { ComponentRenderArgs, ComponentRenderer } from './create-component';
|
|
4
|
+
import ReactDOM from 'react-dom';
|
|
5
|
+
|
|
6
|
+
export type RenderTeardown = VoidFunction;
|
|
7
|
+
|
|
8
|
+
/** @deprecated */
|
|
9
|
+
export const renderComponent = (renderer: ComponentRenderer) => {
|
|
10
|
+
return (el: HTMLElement, args: ComponentRenderArgs): RenderTeardown => {
|
|
11
|
+
const Component = renderer(args.fusion, args.env);
|
|
12
|
+
return render(el, Component);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const render = (el: Element, Component: FunctionComponent): RenderTeardown => {
|
|
17
|
+
// eslint-disable-next-line react/no-deprecated
|
|
18
|
+
ReactDOM.render(
|
|
19
|
+
<StrictMode>
|
|
20
|
+
<Suspense fallback={<p>loading app</p>}>
|
|
21
|
+
<Component />
|
|
22
|
+
</Suspense>
|
|
23
|
+
</StrictMode>,
|
|
24
|
+
el,
|
|
25
|
+
);
|
|
26
|
+
return () => {
|
|
27
|
+
// eslint-disable-next-line react/no-deprecated
|
|
28
|
+
ReactDOM.unmountComponentAtNode(el);
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// const render = (el: Element, Component: FunctionComponent): RenderTeardown => {
|
|
33
|
+
// const root = createRoot(el);
|
|
34
|
+
// root.render(
|
|
35
|
+
// <StrictMode>
|
|
36
|
+
// <Suspense fallback={<p>loading app</p>}>
|
|
37
|
+
// <Component />
|
|
38
|
+
// </Suspense>
|
|
39
|
+
// </StrictMode>
|
|
40
|
+
// );
|
|
41
|
+
// return () => {
|
|
42
|
+
// root.unmount();
|
|
43
|
+
// };
|
|
44
|
+
// };
|
|
45
|
+
|
|
46
|
+
export default renderComponent;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AppModules, AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
2
|
+
import { AnyModule, ModuleKey, ModuleType, ModuleTypes } from '@equinor/fusion-framework-module';
|
|
3
|
+
import { useAppModules } from './useAppModules';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* hook for getting a module from the application scope
|
|
7
|
+
*
|
|
8
|
+
* @template TType type of the module
|
|
9
|
+
*
|
|
10
|
+
* @param module name of the module, provide TType if not registered
|
|
11
|
+
*
|
|
12
|
+
* @returns provider of the module
|
|
13
|
+
*/
|
|
14
|
+
export const useAppModule = <
|
|
15
|
+
TType extends AnyModule | unknown = unknown,
|
|
16
|
+
TKey extends string = ModuleKey<ModuleTypes<AppModules<[TType]>>>,
|
|
17
|
+
>(
|
|
18
|
+
module: TKey,
|
|
19
|
+
): TType extends AnyModule
|
|
20
|
+
? ModuleType<TType>
|
|
21
|
+
: AppModulesInstance[Extract<keyof AppModulesInstance, TKey>] => {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
const appModule = useAppModules()[module];
|
|
25
|
+
if (!appModule) {
|
|
26
|
+
throw Error(`the requested module [${module}] is not included in the app scope`);
|
|
27
|
+
}
|
|
28
|
+
return appModule;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default useAppModule;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
2
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
|
+
import { useModules } from '@equinor/fusion-framework-react-module';
|
|
4
|
+
|
|
5
|
+
export const useAppModules = <
|
|
6
|
+
T extends Array<AnyModule> | unknown = unknown,
|
|
7
|
+
>(): AppModulesInstance<T> => useModules<AppModulesInstance<T>>();
|
|
8
|
+
|
|
9
|
+
export default useAppModules;
|
package/src/version.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig.react.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist/esm",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"declarationDir": "./dist/types",
|
|
7
|
+
"paths": {
|
|
8
|
+
"react": [ "./node_modules/@types/react" ],
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
"references": [
|
|
12
|
+
|
|
13
|
+
{
|
|
14
|
+
"path": "../../app"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../framework"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../modules/module"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "../modules/http"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../modules/context"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "../modules/bookmark"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"path": "../../modules/navigation"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"include": [
|
|
36
|
+
"src/**/*"
|
|
37
|
+
],
|
|
38
|
+
"exclude": [
|
|
39
|
+
"node_modules",
|
|
40
|
+
"lib"
|
|
41
|
+
]
|
|
42
|
+
}
|