@equinor/fusion-framework-react-module 4.0.0 → 4.0.2

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.
@@ -1,6 +1,6 @@
1
1
  import { type LazyExoticComponent, type FunctionComponent } from 'react';
2
2
  import { type ModulesConfigurator, type ModulesInstanceType, type AnyModule } from '@equinor/fusion-framework-module';
3
- type ModuleProviderCreator = <TModules extends Array<AnyModule> = Array<AnyModule>, TRef extends ModulesInstanceType<[AnyModule]> = any>(configurator: ModulesConfigurator<TModules>, modules: TModules, ref?: TRef) => Promise<LazyExoticComponent<FunctionComponent>>;
3
+ type ModuleProviderCreator = <TModules extends Array<AnyModule> = Array<AnyModule>, TRef extends ModulesInstanceType<[AnyModule]> = any>(configurator: ModulesConfigurator<TModules, TRef>, ref?: TRef) => Promise<LazyExoticComponent<FunctionComponent>>;
4
4
  /**
5
5
  * Function for creating a `ModuleProvider` component.
6
6
  *
@@ -10,28 +10,27 @@ type ModuleProviderCreator = <TModules extends Array<AnyModule> = Array<AnyModul
10
10
  * ```ts
11
11
  * import http, { HttpModule } from '@equinor/fusion-framework-module-http';
12
12
  * import msal, { MsalModule } from '@equinor/fusion-framework-module-msal';
13
+ * import { ModulesConfigurator } from '@equinor/fusion-framework-module';
13
14
  * import { createModuleProvider } from '@equinor/fusion-framework-react-module';
14
15
  *
15
- * export default createModuleProvider(
16
- * (config) => {
17
- * config.auth.configureDefault({
18
- * tenantId: 'MY_TENANT_ID',
19
- * clientId: 'MY_CLIENT_ID',
20
- * redirectUri: '/authentication/login-callback',
21
- * });
22
- * config.http.configureClient('foo', {
23
- * baseUri: 'https://foo.bar',
24
- * defaultScopes: ['FOO_CLIENT_ID/.default'],
25
- * });
26
- * },
27
- * [http, msal]
28
- *);
16
+ * const configurator = new ModulesConfigurator([http, msal]);
17
+ * configurator.onConfigured((config) => {
18
+ * config.auth.configureDefault({
19
+ * tenantId: 'MY_TENANT_ID',
20
+ * clientId: 'MY_CLIENT_ID',
21
+ * redirectUri: '/authentication/login-callback',
22
+ * });
23
+ * config.http.configureClient('foo', {
24
+ * baseUri: 'https://foo.bar',
25
+ * defaultScopes: ['FOO_CLIENT_ID/.default'],
26
+ * });
27
+ * });
28
+ *
29
+ * export default createModuleProvider(configurator);
29
30
  * ```
30
- * @param configurator callback for configuring provided modules
31
- * @param modules modules which should be initiated
31
+ * @param configurator configurator for the modules that should be initialized
32
32
  * @param ref optional parent module instance
33
33
  * @returns Suspensive `ModuleProvider`
34
34
  */
35
35
  export declare const createModuleProvider: ModuleProviderCreator;
36
- export declare const ModuleProvider: import("react").Provider<Record<string, unknown>>;
37
- export default ModuleProvider;
36
+ export {};
@@ -1,3 +1,5 @@
1
1
  export type { Modules, ModulesInstanceType, AnyModule, ModulesInstance, } from '@equinor/fusion-framework-module';
2
- export { ModuleProvider, createModuleProvider } from './ModuleProvider.js';
3
- export { useModules, useModule } from './useModules.js';
2
+ export { createModuleProvider } from './create-module-provider.js';
3
+ export { ModuleProvider } from './module-provider.js';
4
+ export { useModules } from './useModules.js';
5
+ export { useModule } from './useModule.js';
@@ -0,0 +1,2 @@
1
+ export declare const ModuleProvider: import("react").Provider<Record<string, unknown>>;
2
+ export default ModuleProvider;
@@ -0,0 +1,22 @@
1
+ import type { AnyModule, ModuleKey, Modules, ModuleType } from '@equinor/fusion-framework-module';
2
+ /**
3
+ * Hook for accessing a single module instance from the current context scope.
4
+ *
5
+ * Convenience hook that retrieves a single module by its key/name. This is useful
6
+ * when you only need one module and want to avoid destructuring from `useModules`.
7
+ *
8
+ * @template T - The type of the module to retrieve. Defaults to any module from the available `Modules`.
9
+ * @template TKey - The string key/name of the module. Automatically inferred from `T` when possible.
10
+ * @param key - The name/key of the module to retrieve from the context.
11
+ * @returns The initialized instance of the requested module, with proper type inference.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Get a specific module by name
16
+ * const navigation = useModule('navigation');
17
+ *
18
+ * // With explicit type
19
+ * const navigation = useModule<NavigationModule>('navigation');
20
+ * ```
21
+ */
22
+ export declare const useModule: <T extends AnyModule = Modules[keyof Modules], TKey extends string = ModuleKey<T>>(key: TKey) => ModuleType<TKey extends keyof Modules ? Modules[TKey] : T>;
@@ -1,4 +1,4 @@
1
- import type { AnyModule, ModuleKey, Modules, ModulesInstanceType, ModuleType } from '@equinor/fusion-framework-module';
1
+ import type { AnyModule, Modules, ModulesInstanceType } from '@equinor/fusion-framework-module';
2
2
  /**
3
3
  * Hook for accessing module instances from the current context scope.
4
4
  *
@@ -19,25 +19,4 @@ import type { AnyModule, ModuleKey, Modules, ModulesInstanceType, ModuleType } f
19
19
  * ```
20
20
  */
21
21
  export declare const useModules: <TModules extends Array<AnyModule> | Record<string, AnyModule> = Modules>() => ModulesInstanceType<TModules>;
22
- /**
23
- * Hook for accessing a single module instance from the current context scope.
24
- *
25
- * Convenience hook that retrieves a single module by its key/name. This is useful
26
- * when you only need one module and want to avoid destructuring from `useModules`.
27
- *
28
- * @template T - The type of the module to retrieve. Defaults to any module from the available `Modules`.
29
- * @template TKey - The string key/name of the module. Automatically inferred from `T` when possible.
30
- * @param key - The name/key of the module to retrieve from the context.
31
- * @returns The initialized instance of the requested module, with proper type inference.
32
- *
33
- * @example
34
- * ```ts
35
- * // Get a specific module by name
36
- * const navigation = useModule('navigation');
37
- *
38
- * // With explicit type
39
- * const navigation = useModule<NavigationModule>('navigation');
40
- * ```
41
- */
42
- export declare const useModule: <T extends AnyModule = Modules[keyof Modules], TKey extends string = ModuleKey<T>>(key: TKey) => ModuleType<TKey extends keyof Modules ? Modules[TKey] : T>;
43
22
  export default useModules;
@@ -1 +1 @@
1
- export declare const version = "4.0.0";
1
+ export declare const version = "4.0.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-react-module",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/esm/index.js",
6
6
  "exports": {
@@ -26,14 +26,14 @@
26
26
  "directory": "packages/react/modules/module"
27
27
  },
28
28
  "dependencies": {
29
- "@equinor/fusion-framework-module": "^6.0.0"
29
+ "@equinor/fusion-framework-module": "^6.1.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/react": "^19.2.7",
33
33
  "@types/react-dom": "^19.2.3",
34
34
  "react": "^19.2.1",
35
35
  "react-dom": "^19.2.1",
36
- "typescript": "^5.9.3"
36
+ "typescript": "^7.0.2"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@types/react": "^18.0.0 || ^19.0.0",
@@ -14,15 +14,14 @@ import {
14
14
  type AnyModule,
15
15
  } from '@equinor/fusion-framework-module';
16
16
 
17
- import moduleContext from './context.js';
17
+ import { ModuleProvider } from './module-provider.js';
18
18
 
19
19
  type ModuleProviderCreator = <
20
20
  TModules extends Array<AnyModule> = Array<AnyModule>,
21
21
  // biome-ignore lint/suspicious/noExplicitAny: Default type parameter for module instance reference
22
22
  TRef extends ModulesInstanceType<[AnyModule]> = any,
23
23
  >(
24
- configurator: ModulesConfigurator<TModules>,
25
- modules: TModules,
24
+ configurator: ModulesConfigurator<TModules, TRef>,
26
25
  ref?: TRef,
27
26
  ) => Promise<LazyExoticComponent<FunctionComponent>>;
28
27
 
@@ -35,25 +34,25 @@ type ModuleProviderCreator = <
35
34
  * ```ts
36
35
  * import http, { HttpModule } from '@equinor/fusion-framework-module-http';
37
36
  * import msal, { MsalModule } from '@equinor/fusion-framework-module-msal';
37
+ * import { ModulesConfigurator } from '@equinor/fusion-framework-module';
38
38
  * import { createModuleProvider } from '@equinor/fusion-framework-react-module';
39
39
  *
40
- * export default createModuleProvider(
41
- * (config) => {
42
- * config.auth.configureDefault({
43
- * tenantId: 'MY_TENANT_ID',
44
- * clientId: 'MY_CLIENT_ID',
45
- * redirectUri: '/authentication/login-callback',
46
- * });
47
- * config.http.configureClient('foo', {
48
- * baseUri: 'https://foo.bar',
49
- * defaultScopes: ['FOO_CLIENT_ID/.default'],
50
- * });
51
- * },
52
- * [http, msal]
53
- *);
40
+ * const configurator = new ModulesConfigurator([http, msal]);
41
+ * configurator.onConfigured((config) => {
42
+ * config.auth.configureDefault({
43
+ * tenantId: 'MY_TENANT_ID',
44
+ * clientId: 'MY_CLIENT_ID',
45
+ * redirectUri: '/authentication/login-callback',
46
+ * });
47
+ * config.http.configureClient('foo', {
48
+ * baseUri: 'https://foo.bar',
49
+ * defaultScopes: ['FOO_CLIENT_ID/.default'],
50
+ * });
51
+ * });
52
+ *
53
+ * export default createModuleProvider(configurator);
54
54
  * ```
55
- * @param configurator callback for configuring provided modules
56
- * @param modules modules which should be initiated
55
+ * @param configurator configurator for the modules that should be initialized
57
56
  * @param ref optional parent module instance
58
57
  * @returns Suspensive `ModuleProvider`
59
58
  */
@@ -62,7 +61,7 @@ export const createModuleProvider: ModuleProviderCreator = async <
62
61
  // biome-ignore lint/suspicious/noExplicitAny: Default type parameter for module instance reference
63
62
  TRef extends ModulesInstanceType<[AnyModule]> = any,
64
63
  >(
65
- configurator: ModulesConfigurator<TModules>,
64
+ configurator: ModulesConfigurator<TModules, TRef>,
66
65
  ref?: TRef,
67
66
  ): Promise<LazyExoticComponent<FunctionComponent>> => {
68
67
  const Component = lazy(async () => {
@@ -77,7 +76,3 @@ export const createModuleProvider: ModuleProviderCreator = async <
77
76
  });
78
77
  return Component;
79
78
  };
80
-
81
- export const ModuleProvider = moduleContext.Provider;
82
-
83
- export default ModuleProvider;
package/src/index.ts CHANGED
@@ -5,5 +5,7 @@ export type {
5
5
  ModulesInstance,
6
6
  } from '@equinor/fusion-framework-module';
7
7
 
8
- export { ModuleProvider, createModuleProvider } from './ModuleProvider.js';
9
- export { useModules, useModule } from './useModules.js';
8
+ export { createModuleProvider } from './create-module-provider.js';
9
+ export { ModuleProvider } from './module-provider.js';
10
+ export { useModules } from './useModules.js';
11
+ export { useModule } from './useModule.js';
@@ -0,0 +1,5 @@
1
+ import moduleContext from './module-context.js';
2
+
3
+ export const ModuleProvider = moduleContext.Provider;
4
+
5
+ export default ModuleProvider;
@@ -0,0 +1,35 @@
1
+ import type { AnyModule, ModuleKey, Modules, ModuleType } from '@equinor/fusion-framework-module';
2
+
3
+ import { useModules } from './useModules.js';
4
+
5
+ /**
6
+ * Hook for accessing a single module instance from the current context scope.
7
+ *
8
+ * Convenience hook that retrieves a single module by its key/name. This is useful
9
+ * when you only need one module and want to avoid destructuring from `useModules`.
10
+ *
11
+ * @template T - The type of the module to retrieve. Defaults to any module from the available `Modules`.
12
+ * @template TKey - The string key/name of the module. Automatically inferred from `T` when possible.
13
+ * @param key - The name/key of the module to retrieve from the context.
14
+ * @returns The initialized instance of the requested module, with proper type inference.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * // Get a specific module by name
19
+ * const navigation = useModule('navigation');
20
+ *
21
+ * // With explicit type
22
+ * const navigation = useModule<NavigationModule>('navigation');
23
+ * ```
24
+ */
25
+ export const useModule = <
26
+ T extends AnyModule = Modules[keyof Modules],
27
+ TKey extends string = ModuleKey<T>,
28
+ >(
29
+ key: TKey,
30
+ ): ModuleType<TKey extends keyof Modules ? Modules[TKey] : T> => {
31
+ const modules = useModules<Record<string, AnyModule>>();
32
+ return (modules as Record<string, unknown>)[key] as ModuleType<
33
+ TKey extends keyof Modules ? Modules[TKey] : T
34
+ >;
35
+ };
package/src/useModules.ts CHANGED
@@ -1,13 +1,7 @@
1
- import type {
2
- AnyModule,
3
- ModuleKey,
4
- Modules,
5
- ModulesInstanceType,
6
- ModuleType,
7
- } from '@equinor/fusion-framework-module';
1
+ import type { AnyModule, Modules, ModulesInstanceType } from '@equinor/fusion-framework-module';
8
2
  import { useContext } from 'react';
9
3
 
10
- import { moduleContext } from './context.js';
4
+ import { moduleContext } from './module-context.js';
11
5
 
12
6
  /**
13
7
  * Hook for accessing module instances from the current context scope.
@@ -32,36 +26,4 @@ export const useModules = <
32
26
  TModules extends Array<AnyModule> | Record<string, AnyModule> = Modules,
33
27
  >(): ModulesInstanceType<TModules> => useContext(moduleContext) as ModulesInstanceType<TModules>;
34
28
 
35
- /**
36
- * Hook for accessing a single module instance from the current context scope.
37
- *
38
- * Convenience hook that retrieves a single module by its key/name. This is useful
39
- * when you only need one module and want to avoid destructuring from `useModules`.
40
- *
41
- * @template T - The type of the module to retrieve. Defaults to any module from the available `Modules`.
42
- * @template TKey - The string key/name of the module. Automatically inferred from `T` when possible.
43
- * @param key - The name/key of the module to retrieve from the context.
44
- * @returns The initialized instance of the requested module, with proper type inference.
45
- *
46
- * @example
47
- * ```ts
48
- * // Get a specific module by name
49
- * const navigation = useModule('navigation');
50
- *
51
- * // With explicit type
52
- * const navigation = useModule<NavigationModule>('navigation');
53
- * ```
54
- */
55
- export const useModule = <
56
- T extends AnyModule = Modules[keyof Modules],
57
- TKey extends string = ModuleKey<T>,
58
- >(
59
- key: TKey,
60
- ): ModuleType<TKey extends keyof Modules ? Modules[TKey] : T> => {
61
- const modules = useModules<Record<string, AnyModule>>();
62
- return (modules as Record<string, unknown>)[key] as ModuleType<
63
- TKey extends keyof Modules ? Modules[TKey] : T
64
- >;
65
- };
66
-
67
29
  export default useModules;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '4.0.0';
2
+ export const version = '4.0.2';
@@ -1 +0,0 @@
1
- {"version":3,"file":"ModuleProvider.js","sourceRoot":"","sources":["../../src/ModuleProvider.tsx"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,OAAO,EACL,IAAI,EACJ,SAAS,GAIV,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,iBAAiB,GAIlB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,aAAa,MAAM,cAAc,CAAC;AAYzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B,KAAK,EAK9D,YAA2C,EAC3C,GAAU,EACuC,EAAE;IACnD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE;QAChC,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,iBAAiB,CAAiB,YAAY,EAAE,GAAG,CAAC,CAAC;QAC5F,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,QAAQ,EAA4B,EAAE,EAAE;gBAClD,wGAAwG;gBACxG,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACrC,OAAO,KAAC,cAAc,IAAC,KAAK,EAAE,QAAQ,YAAG,QAAQ,GAAkB,CAAC;YACtE,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC;AAErD,eAAe,cAAc,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAA0B,EAAE,CAAC,CAAC;AAExE,eAAe,aAAa,CAAC"}
File without changes