@equinor/fusion-framework-react 1.1.0 → 1.3.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 +21 -0
- package/dist/esm/app/index.js +7 -0
- package/dist/esm/app/index.js.map +1 -0
- package/dist/esm/app/useApp.js +23 -0
- package/dist/esm/app/useApp.js.map +1 -0
- package/dist/esm/app/useAppConfig.js +30 -0
- package/dist/esm/app/useAppConfig.js.map +1 -0
- package/dist/esm/app/useAppEnv.js +9 -0
- package/dist/esm/app/useAppEnv.js.map +1 -0
- package/dist/esm/app/useApps.js +23 -0
- package/dist/esm/app/useApps.js.map +1 -0
- package/dist/esm/app/useCurrentApp.js +14 -0
- package/dist/esm/app/useCurrentApp.js.map +1 -0
- package/dist/esm/app/useCurrentAppChanged.js +8 -0
- package/dist/esm/app/useCurrentAppChanged.js.map +1 -0
- package/dist/esm/context/index.js +3 -0
- package/dist/esm/context/index.js.map +1 -0
- package/dist/esm/context/useCurrentContext.js +5 -0
- package/dist/esm/context/useCurrentContext.js.map +1 -0
- package/dist/esm/hooks/use-framework.js +3 -11
- package/dist/esm/hooks/use-framework.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useFramework.js +15 -0
- package/dist/esm/useFramework.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/app/index.d.ts +7 -0
- package/dist/types/app/useApp.d.ts +7 -0
- package/dist/types/app/useAppConfig.d.ts +10 -0
- package/dist/types/app/useAppEnv.d.ts +7 -0
- package/dist/types/app/useApps.d.ts +7 -0
- package/dist/types/app/useCurrentApp.d.ts +5 -0
- package/dist/types/app/useCurrentAppChanged.d.ts +3 -0
- package/dist/types/context/index.d.ts +2 -0
- package/dist/types/context/useCurrentContext.d.ts +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/useFramework.d.ts +4 -0
- package/package.json +14 -4
- package/src/app/index.ts +8 -0
- package/src/app/useApp.ts +26 -0
- package/src/app/useAppConfig.ts +43 -0
- package/src/app/useAppEnv.ts +11 -0
- package/src/app/useApps.ts +26 -0
- package/src/app/useCurrentApp.ts +19 -0
- package/src/app/useCurrentAppChanged.ts +12 -0
- package/src/context/index.ts +3 -0
- package/src/context/useCurrentContext.ts +6 -0
- package/src/hooks/use-framework.ts +9 -16
- package/src/index.tsx +2 -0
- package/src/useFramework.ts +27 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { AppConfig, AppManifest, AppType } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
export { useApp } from './useApp';
|
|
3
|
+
export { useApps } from './useApps';
|
|
4
|
+
export { useCurrentApp } from './useCurrentApp';
|
|
5
|
+
export { useCurrentAppChanged } from './useCurrentAppChanged';
|
|
6
|
+
export { useAppConfig } from './useAppConfig';
|
|
7
|
+
export { useAppEnv } from './useAppEnv';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AppConfig } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
declare type UseAppConfigState<TType> = {
|
|
3
|
+
value?: AppConfig<TType>;
|
|
4
|
+
error?: Error;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const useAppConfig: <TType>(args: {
|
|
8
|
+
appKey: string | undefined;
|
|
9
|
+
}) => UseAppConfigState<TType>;
|
|
10
|
+
export default useAppConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useApp } from './useApp';
|
|
2
|
+
export declare const useAppEnv: (appKey: string) => {
|
|
3
|
+
manifest: import("@equinor/fusion-framework-module-app").AppManifest | undefined;
|
|
4
|
+
config: import("@equinor/fusion-framework-module-app").AppConfig<unknown> | undefined;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
};
|
|
7
|
+
export default useApp;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const useCurrentContext: () => {
|
|
2
|
+
currentContext: import("@equinor/fusion-framework-react-module-context").ContextItem<Record<string, unknown>> | undefined;
|
|
3
|
+
setCurrentContext: (entry: import("@equinor/fusion-framework-react-module-context").ContextItem<Record<string, unknown>>) => void;
|
|
4
|
+
};
|
|
5
|
+
export default useCurrentContext;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export type { Fusion } from '@equinor/fusion-framework';
|
|
|
2
2
|
export { FusionConfigurator } from '@equinor/fusion-framework';
|
|
3
3
|
export { createFrameworkProvider } from './create-framework-provider';
|
|
4
4
|
export { FrameworkProvider } from './context';
|
|
5
|
+
export { useFramework } from './useFramework';
|
|
5
6
|
export { default, Framework } from './Framework';
|
package/package.json
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/esm/index.js",
|
|
8
|
+
"./app": "./dist/esm/app/index.js",
|
|
9
|
+
"./context": "./dist/esm/context/index.js",
|
|
8
10
|
"./hooks": "./dist/esm/hooks/index.js",
|
|
9
11
|
"./http": "./dist/esm/http/index.js"
|
|
10
12
|
},
|
|
11
13
|
"types": "dist/types/index.d.ts",
|
|
12
14
|
"typesVersions": {
|
|
13
15
|
"*": {
|
|
16
|
+
"app": [
|
|
17
|
+
"dist/types/app/index.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"context": [
|
|
20
|
+
"dist/types/context/index.d.ts"
|
|
21
|
+
],
|
|
14
22
|
"hooks": [
|
|
15
23
|
"dist/types/hooks/index.d.ts"
|
|
16
24
|
],
|
|
@@ -35,8 +43,10 @@
|
|
|
35
43
|
"directory": "packages/react"
|
|
36
44
|
},
|
|
37
45
|
"dependencies": {
|
|
38
|
-
"@equinor/fusion-framework": "^4.0
|
|
39
|
-
"@equinor/fusion-framework-react-module-
|
|
46
|
+
"@equinor/fusion-framework": "^4.2.0",
|
|
47
|
+
"@equinor/fusion-framework-react-module-context": "^0.1.0",
|
|
48
|
+
"@equinor/fusion-framework-react-module-http": "^1.0.15",
|
|
49
|
+
"rxjs": "^7.5.7"
|
|
40
50
|
},
|
|
41
51
|
"devDependencies": {
|
|
42
52
|
"@types/react": "^17.0.11",
|
|
@@ -58,5 +68,5 @@
|
|
|
58
68
|
"optional": true
|
|
59
69
|
}
|
|
60
70
|
},
|
|
61
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "21ae1ec0a760c03a0887eced5532de8443274916"
|
|
62
72
|
}
|
package/src/app/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { AppConfig, AppManifest, AppType } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
|
|
3
|
+
export { useApp } from './useApp';
|
|
4
|
+
export { useApps } from './useApps';
|
|
5
|
+
export { useCurrentApp } from './useCurrentApp';
|
|
6
|
+
export { useCurrentAppChanged } from './useCurrentAppChanged';
|
|
7
|
+
export { useAppConfig } from './useAppConfig';
|
|
8
|
+
export { useAppEnv } from './useAppEnv';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { AppManifest } from '@equinor/fusion-framework-module-app';
|
|
3
|
+
import { useFramework } from '../hooks';
|
|
4
|
+
|
|
5
|
+
export const useApp = (appKey: string) => {
|
|
6
|
+
const provider = useFramework().modules.app;
|
|
7
|
+
const [value, setValue] = useState<AppManifest | undefined>(undefined);
|
|
8
|
+
const [error, setError] = useState<Error | undefined>();
|
|
9
|
+
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setIsLoading(true);
|
|
13
|
+
const request = provider.getApp(appKey).subscribe({
|
|
14
|
+
next: (value) => setValue(value),
|
|
15
|
+
error: (err) => setError(err),
|
|
16
|
+
complete: () => setIsLoading(false),
|
|
17
|
+
});
|
|
18
|
+
return () => {
|
|
19
|
+
setIsLoading(false);
|
|
20
|
+
request.unsubscribe();
|
|
21
|
+
};
|
|
22
|
+
}, [provider, setValue, setError, setIsLoading, appKey]);
|
|
23
|
+
return { value, error, isLoading };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default useApp;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { AppConfig } from '@equinor/fusion-framework-module-app';
|
|
3
|
+
|
|
4
|
+
import { useFramework } from '../hooks';
|
|
5
|
+
|
|
6
|
+
type UseAppConfigState<TType> = {
|
|
7
|
+
value?: AppConfig<TType>;
|
|
8
|
+
error?: Error;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const useAppConfig = <TType>(args: {
|
|
13
|
+
appKey: string | undefined;
|
|
14
|
+
}): UseAppConfigState<TType> => {
|
|
15
|
+
const { appKey } = args;
|
|
16
|
+
const provider = useFramework().modules.app;
|
|
17
|
+
const [value, setValue] = useState<AppConfig<TType> | undefined>();
|
|
18
|
+
const [error, setError] = useState<Error | undefined>();
|
|
19
|
+
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setValue(undefined);
|
|
23
|
+
}, [setValue, appKey]);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!appKey) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
setIsLoading(true);
|
|
30
|
+
const request = provider.getAppConfig<TType>(appKey).subscribe({
|
|
31
|
+
next: (value) => setValue(value),
|
|
32
|
+
error: (err) => setError(err),
|
|
33
|
+
complete: () => setIsLoading(false),
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
setIsLoading(false);
|
|
37
|
+
request.unsubscribe();
|
|
38
|
+
};
|
|
39
|
+
}, [provider, setValue, setError, setIsLoading, appKey]);
|
|
40
|
+
return { value, error, isLoading };
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default useAppConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useApp } from './useApp';
|
|
2
|
+
import { useAppConfig } from './useAppConfig';
|
|
3
|
+
|
|
4
|
+
export const useAppEnv = (appKey: string) => {
|
|
5
|
+
const { value: manifest, isLoading: manifestLoading } = useApp(appKey);
|
|
6
|
+
const { value: config, isLoading: configLoading } = useAppConfig({ appKey });
|
|
7
|
+
|
|
8
|
+
return { manifest, config, isLoading: manifestLoading || configLoading };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default useApp;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AppManifest } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useFramework } from '../hooks';
|
|
4
|
+
|
|
5
|
+
export const useApps = () => {
|
|
6
|
+
const provider = useFramework().modules.app;
|
|
7
|
+
const [value, setValue] = useState<AppManifest[] | undefined>(undefined);
|
|
8
|
+
const [error, setError] = useState<Error | undefined>();
|
|
9
|
+
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setIsLoading(true);
|
|
13
|
+
const request = provider.getAllApps().subscribe({
|
|
14
|
+
next: (value) => setValue(value),
|
|
15
|
+
error: (err) => setError(err),
|
|
16
|
+
complete: () => setIsLoading(false),
|
|
17
|
+
});
|
|
18
|
+
return () => {
|
|
19
|
+
setIsLoading(false);
|
|
20
|
+
request.unsubscribe();
|
|
21
|
+
};
|
|
22
|
+
}, [provider, setValue, setError, setIsLoading]);
|
|
23
|
+
return { value, error, isLoading };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default useApps;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useFramework } from '../hooks/use-framework';
|
|
5
|
+
|
|
6
|
+
export const useCurrentApp = () => {
|
|
7
|
+
const provider = useFramework().modules.app;
|
|
8
|
+
const currentApp = useObservableState(provider.current$);
|
|
9
|
+
const setCurrentApp = useCallback(
|
|
10
|
+
(appKey: string) => provider.setCurrentApp(appKey),
|
|
11
|
+
[provider]
|
|
12
|
+
);
|
|
13
|
+
return {
|
|
14
|
+
currentApp,
|
|
15
|
+
setCurrentApp,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default useCurrentApp;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FrameworkEventMap } from '@equinor/fusion-framework-module-event';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useFramework } from '../hooks/use-framework';
|
|
4
|
+
|
|
5
|
+
export const useCurrentAppChanged = (
|
|
6
|
+
cb: (e: FrameworkEventMap['onCurrentAppChanged']) => Promise<void> | void
|
|
7
|
+
) => {
|
|
8
|
+
const { event } = useFramework().modules;
|
|
9
|
+
useEffect(() => event.addEventListener('onCurrentAppChanged', cb), [event, cb]);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default useCurrentAppChanged;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useCurrentContext as _useCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
2
|
+
import { useFramework } from '../useFramework';
|
|
3
|
+
|
|
4
|
+
export const useCurrentContext = () => _useCurrentContext(useFramework().modules.context);
|
|
5
|
+
|
|
6
|
+
export default useCurrentContext;
|
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
import type { Fusion } from '@equinor/fusion-framework';
|
|
2
2
|
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import _useFramework from '../useFramework';
|
|
5
|
+
|
|
6
|
+
// TODO - remove next major!
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
|
-
* @
|
|
9
|
+
* @deprecated
|
|
10
|
+
*
|
|
8
11
|
* ```ts
|
|
9
|
-
*
|
|
10
|
-
* const fusion = useFramework();
|
|
11
|
-
* return fusion.something;
|
|
12
|
-
* }
|
|
12
|
+
* import { useFramework } from '@equinor/fusion-framework';
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export const useFramework = <TModules extends Array<AnyModule> = []>(): Fusion<TModules> => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.warn('could not locate fusion in context!');
|
|
19
|
-
}
|
|
20
|
-
framework ??= window.Fusion;
|
|
21
|
-
if (!framework) {
|
|
22
|
-
console.error('Could not load framework, might not be initiated?');
|
|
23
|
-
}
|
|
24
|
-
return framework;
|
|
16
|
+
console.warn('@deprecated', 'import { useFramework } from @equinor/fusion-framework');
|
|
17
|
+
return _useFramework();
|
|
25
18
|
};
|
package/src/index.tsx
CHANGED
|
@@ -9,4 +9,6 @@ export { FusionConfigurator } from '@equinor/fusion-framework';
|
|
|
9
9
|
export { createFrameworkProvider } from './create-framework-provider';
|
|
10
10
|
export { FrameworkProvider } from './context';
|
|
11
11
|
|
|
12
|
+
export { useFramework } from './useFramework';
|
|
13
|
+
|
|
12
14
|
export { default, Framework } from './Framework';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Fusion } from '@equinor/fusion-framework';
|
|
2
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
|
+
|
|
4
|
+
import { useContext } from 'react';
|
|
5
|
+
import { context } from './context';
|
|
6
|
+
/**
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const useSometing = () => {
|
|
10
|
+
* const fusion = useFramework();
|
|
11
|
+
* return fusion.something;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const useFramework = <TModules extends Array<AnyModule> = []>(): Fusion<TModules> => {
|
|
16
|
+
let framework = useContext(context);
|
|
17
|
+
if (!framework) {
|
|
18
|
+
console.warn('could not locate fusion in context!');
|
|
19
|
+
}
|
|
20
|
+
framework ??= window.Fusion;
|
|
21
|
+
if (!framework) {
|
|
22
|
+
console.error('Could not load framework, might not be initiated?');
|
|
23
|
+
}
|
|
24
|
+
return framework;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default useFramework;
|