@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.
Files changed (51) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/esm/app/index.js +7 -0
  3. package/dist/esm/app/index.js.map +1 -0
  4. package/dist/esm/app/useApp.js +23 -0
  5. package/dist/esm/app/useApp.js.map +1 -0
  6. package/dist/esm/app/useAppConfig.js +30 -0
  7. package/dist/esm/app/useAppConfig.js.map +1 -0
  8. package/dist/esm/app/useAppEnv.js +9 -0
  9. package/dist/esm/app/useAppEnv.js.map +1 -0
  10. package/dist/esm/app/useApps.js +23 -0
  11. package/dist/esm/app/useApps.js.map +1 -0
  12. package/dist/esm/app/useCurrentApp.js +14 -0
  13. package/dist/esm/app/useCurrentApp.js.map +1 -0
  14. package/dist/esm/app/useCurrentAppChanged.js +8 -0
  15. package/dist/esm/app/useCurrentAppChanged.js.map +1 -0
  16. package/dist/esm/context/index.js +3 -0
  17. package/dist/esm/context/index.js.map +1 -0
  18. package/dist/esm/context/useCurrentContext.js +5 -0
  19. package/dist/esm/context/useCurrentContext.js.map +1 -0
  20. package/dist/esm/hooks/use-framework.js +3 -11
  21. package/dist/esm/hooks/use-framework.js.map +1 -1
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/useFramework.js +15 -0
  25. package/dist/esm/useFramework.js.map +1 -0
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/dist/types/app/index.d.ts +7 -0
  28. package/dist/types/app/useApp.d.ts +7 -0
  29. package/dist/types/app/useAppConfig.d.ts +10 -0
  30. package/dist/types/app/useAppEnv.d.ts +7 -0
  31. package/dist/types/app/useApps.d.ts +7 -0
  32. package/dist/types/app/useCurrentApp.d.ts +5 -0
  33. package/dist/types/app/useCurrentAppChanged.d.ts +3 -0
  34. package/dist/types/context/index.d.ts +2 -0
  35. package/dist/types/context/useCurrentContext.d.ts +5 -0
  36. package/dist/types/index.d.ts +1 -0
  37. package/dist/types/useFramework.d.ts +4 -0
  38. package/package.json +14 -4
  39. package/src/app/index.ts +8 -0
  40. package/src/app/useApp.ts +26 -0
  41. package/src/app/useAppConfig.ts +43 -0
  42. package/src/app/useAppEnv.ts +11 -0
  43. package/src/app/useApps.ts +26 -0
  44. package/src/app/useCurrentApp.ts +19 -0
  45. package/src/app/useCurrentAppChanged.ts +12 -0
  46. package/src/context/index.ts +3 -0
  47. package/src/context/useCurrentContext.ts +6 -0
  48. package/src/hooks/use-framework.ts +9 -16
  49. package/src/index.tsx +2 -0
  50. package/src/useFramework.ts +27 -0
  51. 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,7 @@
1
+ import { AppManifest } from '@equinor/fusion-framework-module-app';
2
+ export declare const useApp: (appKey: string) => {
3
+ value: AppManifest | undefined;
4
+ error: Error | undefined;
5
+ isLoading: boolean;
6
+ };
7
+ export default useApp;
@@ -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,7 @@
1
+ import { AppManifest } from '@equinor/fusion-framework-module-app';
2
+ export declare const useApps: () => {
3
+ value: AppManifest[] | undefined;
4
+ error: Error | undefined;
5
+ isLoading: boolean;
6
+ };
7
+ export default useApps;
@@ -0,0 +1,5 @@
1
+ export declare const useCurrentApp: () => {
2
+ currentApp: import("@equinor/fusion-framework-module-app").AppManifest | undefined;
3
+ setCurrentApp: (appKey: string) => void;
4
+ };
5
+ export default useCurrentApp;
@@ -0,0 +1,3 @@
1
+ import { FrameworkEventMap } from '@equinor/fusion-framework-module-event';
2
+ export declare const useCurrentAppChanged: (cb: (e: FrameworkEventMap['onCurrentAppChanged']) => Promise<void> | void) => void;
3
+ export default useCurrentAppChanged;
@@ -0,0 +1,2 @@
1
+ export * from '@equinor/fusion-framework-react-module-context';
2
+ export { useCurrentContext } from './useCurrentContext';
@@ -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;
@@ -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';
@@ -0,0 +1,4 @@
1
+ import type { Fusion } from '@equinor/fusion-framework';
2
+ import type { AnyModule } from '@equinor/fusion-framework-module';
3
+ export declare const useFramework: <TModules extends AnyModule[] = []>() => Fusion<TModules>;
4
+ export default useFramework;
package/package.json CHANGED
@@ -1,16 +1,24 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-react",
3
- "version": "1.1.0",
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.16",
39
- "@equinor/fusion-framework-react-module-http": "^1.0.14"
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": "3506d6ea39362a9fb2764ac764fe8356fda0de01"
71
+ "gitHead": "21ae1ec0a760c03a0887eced5532de8443274916"
62
72
  }
@@ -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,3 @@
1
+ export * from '@equinor/fusion-framework-react-module-context';
2
+
3
+ export { useCurrentContext } from './useCurrentContext';
@@ -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 { useContext } from 'react';
5
- import { context } from '../context';
4
+ import _useFramework from '../useFramework';
5
+
6
+ // TODO - remove next major!
7
+
6
8
  /**
7
- * @example
9
+ * @deprecated
10
+ *
8
11
  * ```ts
9
- * const useSometing = () => {
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
- 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;
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;
package/tsconfig.json CHANGED
@@ -10,6 +10,15 @@
10
10
  "references": [
11
11
  {
12
12
  "path": "../framework"
13
+ },
14
+ {
15
+ "path": "../module-app"
16
+ },
17
+ {
18
+ "path": "../module-context"
19
+ },
20
+ {
21
+ "path": "../react-module-context"
13
22
  }
14
23
  ],
15
24
  "include": [