@equinor/fusion-framework-react-app 0.8.0 → 1.0.1
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 +50 -0
- package/dist/esm/create-component.js +21 -0
- package/dist/esm/create-component.js.map +1 -0
- package/dist/esm/create-legacy-app.js +4 -4
- package/dist/esm/create-legacy-app.js.map +1 -1
- package/dist/esm/index.js +4 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/render-app.js +10 -0
- package/dist/esm/render-app.js.map +1 -0
- package/dist/esm/render-component.js +26 -0
- package/dist/esm/render-component.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/create-component.d.ts +20 -0
- package/dist/types/create-legacy-app.d.ts +2 -2
- package/dist/types/index.d.ts +5 -4
- package/dist/types/render-app.d.ts +5 -0
- package/dist/types/render-component.d.ts +4 -0
- package/dist/types/useAppModule.d.ts +1 -1
- package/package.json +8 -8
- package/src/{create-app.tsx → create-component.tsx} +37 -27
- package/src/create-legacy-app.tsx +5 -6
- package/src/index.ts +4 -5
- package/src/render-app.ts +13 -0
- package/src/render-component.tsx +48 -0
- package/yarn-error.log +13173 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Fusion } from '@equinor/fusion-framework-react';
|
|
3
|
+
import type { AppManifest, AppModuleInitiator, AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
4
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
5
|
+
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
6
|
+
export declare type ComponentRenderArgs<TFusion extends Fusion = Fusion, TManifest extends AppManifest = AppManifest> = {
|
|
7
|
+
fusion: TFusion;
|
|
8
|
+
env: TManifest;
|
|
9
|
+
};
|
|
10
|
+
export declare type ComponentRenderer<TFusion extends Fusion = Fusion, TManifest extends AppManifest = AppManifest> = (args: ComponentRenderArgs<TFusion, TManifest>) => React.LazyExoticComponent<React.ComponentType>;
|
|
11
|
+
export declare const createComponent: <TModules extends AnyModule[], TRef extends Fusion<[]> = Fusion<[]>, TManifest extends AppManifest = AppManifest>(Component: React.ComponentType, configure?: AppModuleInitiator<TModules, TRef, TManifest> | undefined) => ComponentRenderer<TRef, TManifest>;
|
|
12
|
+
declare module '@equinor/fusion-framework-module-event' {
|
|
13
|
+
interface FrameworkEventMap {
|
|
14
|
+
onReactAppLoaded: FrameworkEvent<FrameworkEventInit<{
|
|
15
|
+
modules: AppModulesInstance;
|
|
16
|
+
fusion: Fusion;
|
|
17
|
+
}, React.ComponentType>>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export default createComponent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
|
-
import type {
|
|
4
|
-
export declare const createLegacyApp: <TModules extends AnyModule[]>(Component: React.ComponentType, configure?:
|
|
3
|
+
import type { AppModuleInitiator } from '@equinor/fusion-framework-app';
|
|
4
|
+
export declare const createLegacyApp: <TModules extends AnyModule[]>(Component: React.ComponentType, configure?: AppModuleInitiator<TModules, import("@equinor/fusion-framework").Fusion<[]>, import("@equinor/fusion-framework-app").AppManifest> | undefined) => () => JSX.Element;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { AppConfigurator, AppConfigCallback, AppModules, AppModulesInstance, AppManifest, } from '@equinor/fusion-framework-app';
|
|
1
|
+
export type { AppConfigurator, AppModules, AppModulesInstance, AppManifest, } from '@equinor/fusion-framework-app';
|
|
3
2
|
export { useAppModule } from './useAppModule';
|
|
4
3
|
export { useAppModules } from './useAppModules';
|
|
5
|
-
export {
|
|
4
|
+
export { renderApp } from './render-app';
|
|
5
|
+
export { createComponent } from './create-component';
|
|
6
|
+
export { renderComponent } from './render-component';
|
|
6
7
|
export { createLegacyApp } from './create-legacy-app';
|
|
7
|
-
export { default } from './
|
|
8
|
+
export { default } from './render-app';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RenderTeardown } from './render-component';
|
|
3
|
+
import type { ComponentRenderArgs } from './create-component';
|
|
4
|
+
export declare const renderApp: (Component: import("react").ComponentType<{}>, configure?: import("@equinor/fusion-framework-app").AppModuleInitiator<import("@equinor/fusion-framework-module").AnyModule[], import("@equinor/fusion-framework").Fusion<[]>, import("@equinor/fusion-framework-app").AppManifest> | undefined) => (el: HTMLElement, args: ComponentRenderArgs) => RenderTeardown;
|
|
5
|
+
export default renderApp;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ComponentRenderArgs, ComponentRenderer } from 'create-component';
|
|
2
|
+
export declare type RenderTeardown = VoidFunction;
|
|
3
|
+
export declare const renderComponent: (renderer: ComponentRenderer) => (el: HTMLElement, args: ComponentRenderArgs) => RenderTeardown;
|
|
4
|
+
export default renderComponent;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
2
|
-
export declare const useAppModule: <TKey extends
|
|
2
|
+
export declare const useAppModule: <TKey extends "event" | "http" | "auth" | "dispose">(module: TKey) => AppModulesInstance<[]>[TKey];
|
|
3
3
|
export default useAppModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-react-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"directory": "packages/react"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@equinor/fusion-framework-app": "^0.
|
|
43
|
-
"@equinor/fusion-framework-module": "^0.
|
|
44
|
-
"@equinor/fusion-framework-module-event": "^0.1
|
|
45
|
-
"@equinor/fusion-framework-module-msal": "^0.
|
|
46
|
-
"@equinor/fusion-framework-react": "^0.
|
|
47
|
-
"@equinor/fusion-framework-react-module-app-config": "^0.1
|
|
42
|
+
"@equinor/fusion-framework-app": "^1.0.1",
|
|
43
|
+
"@equinor/fusion-framework-module": "^1.0.1",
|
|
44
|
+
"@equinor/fusion-framework-module-event": "^1.0.1",
|
|
45
|
+
"@equinor/fusion-framework-module-msal": "^1.0.1",
|
|
46
|
+
"@equinor/fusion-framework-react": "^1.0.1",
|
|
47
|
+
"@equinor/fusion-framework-react-module-app-config": "^1.0.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/react": "^17.0.11",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"optional": true
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "92331edc3d412391fbb33d322e7cf8769b57534e"
|
|
70
70
|
}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import { lazy } from 'react';
|
|
1
|
+
import React, { lazy } from 'react';
|
|
2
2
|
|
|
3
3
|
import { FrameworkProvider } from '@equinor/fusion-framework-react';
|
|
4
4
|
import type { Fusion } from '@equinor/fusion-framework-react';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
6
|
+
import { initAppModules } from '@equinor/fusion-framework-app';
|
|
7
|
+
import type {
|
|
8
|
+
AppManifest,
|
|
9
|
+
AppModuleInitiator,
|
|
10
|
+
AppModulesInstance,
|
|
11
|
+
} from '@equinor/fusion-framework-app';
|
|
8
12
|
|
|
9
|
-
import type { AnyModule
|
|
13
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
10
14
|
|
|
11
15
|
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
12
16
|
|
|
13
17
|
import { ModuleProvider as AppModuleProvider } from '@equinor/fusion-framework-react-module';
|
|
14
18
|
|
|
19
|
+
export type ComponentRenderArgs<
|
|
20
|
+
TFusion extends Fusion = Fusion,
|
|
21
|
+
TManifest extends AppManifest = AppManifest
|
|
22
|
+
> = { fusion: TFusion; env: TManifest };
|
|
23
|
+
export type ComponentRenderer<
|
|
24
|
+
TFusion extends Fusion = Fusion,
|
|
25
|
+
TManifest extends AppManifest = AppManifest
|
|
26
|
+
> = (
|
|
27
|
+
args: ComponentRenderArgs<TFusion, TManifest>
|
|
28
|
+
) => React.LazyExoticComponent<React.ComponentType>;
|
|
29
|
+
|
|
15
30
|
/**
|
|
16
31
|
* Creates an lazy loading Component which configures modules
|
|
17
32
|
* and provides context to framework and configured modules
|
|
@@ -61,33 +76,31 @@ import { ModuleProvider as AppModuleProvider } from '@equinor/fusion-framework-r
|
|
|
61
76
|
* @param configure - Callback for configuring application
|
|
62
77
|
* @param modules - required modules for application
|
|
63
78
|
*/
|
|
64
|
-
export const
|
|
65
|
-
<
|
|
79
|
+
export const createComponent =
|
|
80
|
+
<
|
|
81
|
+
TModules extends Array<AnyModule>,
|
|
82
|
+
TRef extends Fusion = Fusion,
|
|
83
|
+
TManifest extends AppManifest = AppManifest
|
|
84
|
+
>(
|
|
66
85
|
Component: React.ComponentType,
|
|
67
|
-
configure?:
|
|
68
|
-
|
|
69
|
-
) =>
|
|
70
|
-
(fusion: Fusion, env: AppManifest): React.LazyExoticComponent<React.ComponentType> =>
|
|
86
|
+
configure?: AppModuleInitiator<TModules, TRef, TManifest>
|
|
87
|
+
): ComponentRenderer<TRef, TManifest> =>
|
|
88
|
+
({ fusion, env }) =>
|
|
71
89
|
lazy(async () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const appInitiator = initializeAppModules(configurator, modules ?? []);
|
|
90
|
+
const init = initAppModules(configure);
|
|
91
|
+
const modules = (await init({
|
|
92
|
+
fusion,
|
|
93
|
+
manifest: env,
|
|
94
|
+
})) as unknown as AppModulesInstance;
|
|
81
95
|
|
|
82
|
-
|
|
83
|
-
appModules.event.dispatchEvent('onReactAppLoaded', {
|
|
96
|
+
modules.event.dispatchEvent('onReactAppLoaded', {
|
|
84
97
|
detail: { modules, fusion },
|
|
85
98
|
source: Component,
|
|
86
99
|
});
|
|
87
100
|
return {
|
|
88
101
|
default: () => (
|
|
89
102
|
<FrameworkProvider value={fusion}>
|
|
90
|
-
<AppModuleProvider value={
|
|
103
|
+
<AppModuleProvider value={modules}>
|
|
91
104
|
<Component />
|
|
92
105
|
</AppModuleProvider>
|
|
93
106
|
</FrameworkProvider>
|
|
@@ -98,12 +111,9 @@ export const createApp =
|
|
|
98
111
|
declare module '@equinor/fusion-framework-module-event' {
|
|
99
112
|
interface FrameworkEventMap {
|
|
100
113
|
onReactAppLoaded: FrameworkEvent<
|
|
101
|
-
FrameworkEventInit<
|
|
102
|
-
{ modules: ModulesInstanceType<AppModules>; fusion: Fusion },
|
|
103
|
-
React.ComponentType
|
|
104
|
-
>
|
|
114
|
+
FrameworkEventInit<{ modules: AppModulesInstance; fusion: Fusion }, React.ComponentType>
|
|
105
115
|
>;
|
|
106
116
|
}
|
|
107
117
|
}
|
|
108
118
|
|
|
109
|
-
export default
|
|
119
|
+
export default createComponent;
|
|
@@ -3,20 +3,19 @@ import { Suspense, useMemo } from 'react';
|
|
|
3
3
|
import { useFramework } from '@equinor/fusion-framework-react/hooks';
|
|
4
4
|
|
|
5
5
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
6
|
-
import type {
|
|
6
|
+
import type { AppModuleInitiator } from '@equinor/fusion-framework-app';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { createComponent } from './create-component';
|
|
9
9
|
|
|
10
10
|
export const createLegacyApp = <TModules extends Array<AnyModule>>(
|
|
11
11
|
Component: React.ComponentType,
|
|
12
|
-
configure?:
|
|
13
|
-
modules?: TModules
|
|
12
|
+
configure?: AppModuleInitiator<TModules>
|
|
14
13
|
) => {
|
|
15
14
|
return (): JSX.Element => {
|
|
16
15
|
const fusion = useFramework();
|
|
17
16
|
const RenderComponent = useMemo(() => {
|
|
18
|
-
const creator =
|
|
19
|
-
return creator(fusion, { name: '' });
|
|
17
|
+
const creator = createComponent(Component, configure);
|
|
18
|
+
return creator({ fusion, env: { name: 'legacy' } });
|
|
20
19
|
}, []);
|
|
21
20
|
return (
|
|
22
21
|
<Suspense fallback={<p>loading app</p>}>
|
package/src/index.ts
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export { appModules } from '@equinor/fusion-framework-app';
|
|
7
|
-
|
|
8
6
|
export type {
|
|
9
7
|
AppConfigurator,
|
|
10
|
-
AppConfigCallback,
|
|
11
8
|
AppModules,
|
|
12
9
|
AppModulesInstance,
|
|
13
10
|
AppManifest,
|
|
@@ -16,7 +13,9 @@ export type {
|
|
|
16
13
|
export { useAppModule } from './useAppModule';
|
|
17
14
|
export { useAppModules } from './useAppModules';
|
|
18
15
|
|
|
19
|
-
export {
|
|
16
|
+
export { renderApp } from './render-app';
|
|
17
|
+
export { createComponent } from './create-component';
|
|
18
|
+
export { renderComponent } from './render-component';
|
|
20
19
|
export { createLegacyApp } from './create-legacy-app';
|
|
21
20
|
|
|
22
|
-
export { default } from './
|
|
21
|
+
export { default } from './render-app';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createComponent } from './create-component';
|
|
2
|
+
import { renderComponent, RenderTeardown } from './render-component';
|
|
3
|
+
|
|
4
|
+
import type { ComponentRenderArgs } from './create-component';
|
|
5
|
+
|
|
6
|
+
export const renderApp = (...componentArgs: Parameters<typeof createComponent>) => {
|
|
7
|
+
const renderer = renderComponent(createComponent(...componentArgs));
|
|
8
|
+
return (el: HTMLElement, args: ComponentRenderArgs): RenderTeardown => {
|
|
9
|
+
return renderer(el, args);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default renderApp;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { createRoot } from 'react-dom/client';
|
|
9
|
+
|
|
10
|
+
export type RenderTeardown = VoidFunction;
|
|
11
|
+
|
|
12
|
+
export const renderComponent = (renderer: ComponentRenderer) => {
|
|
13
|
+
return (el: HTMLElement, args: ComponentRenderArgs): RenderTeardown => {
|
|
14
|
+
const Component = renderer(args);
|
|
15
|
+
const renderFn = createRoot ? render : renderLegacy;
|
|
16
|
+
return renderFn(el, Component);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const renderLegacy = (el: Element, Component: FunctionComponent): RenderTeardown => {
|
|
21
|
+
ReactDOM.render(
|
|
22
|
+
<StrictMode>
|
|
23
|
+
<Suspense fallback={<p>loading app</p>}>
|
|
24
|
+
<Component />
|
|
25
|
+
</Suspense>
|
|
26
|
+
</StrictMode>,
|
|
27
|
+
el
|
|
28
|
+
);
|
|
29
|
+
return () => {
|
|
30
|
+
ReactDOM.unmountComponentAtNode(el);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const render = (el: Element, Component: FunctionComponent): RenderTeardown => {
|
|
35
|
+
const root = createRoot(el);
|
|
36
|
+
root.render(
|
|
37
|
+
<StrictMode>
|
|
38
|
+
<Suspense fallback={<p>loading app</p>}>
|
|
39
|
+
<Component />
|
|
40
|
+
</Suspense>
|
|
41
|
+
</StrictMode>
|
|
42
|
+
);
|
|
43
|
+
return () => {
|
|
44
|
+
root.unmount();
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default renderComponent;
|