@equinor/fusion-framework-react-module-context 7.0.0 → 7.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.
- package/CHANGELOG.md +15 -0
- package/README.md +81 -0
- package/dist/esm/index.js +13 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useCurrentContext.js +7 -10
- package/dist/esm/useCurrentContext.js.map +1 -1
- package/dist/esm/useModuleCurrentContext.js +12 -0
- package/dist/esm/useModuleCurrentContext.js.map +1 -0
- package/dist/esm/useModuleQueryContext.js +15 -0
- package/dist/esm/useModuleQueryContext.js.map +1 -0
- package/dist/esm/useQueryContext.js +8 -6
- package/dist/esm/useQueryContext.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +13 -2
- package/dist/types/useCurrentContext.d.ts +6 -8
- package/dist/types/useModuleCurrentContext.d.ts +8 -0
- package/dist/types/useModuleQueryContext.d.ts +14 -0
- package/dist/types/useQueryContext.d.ts +8 -8
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -6
- package/src/index.ts +13 -2
- package/src/useCurrentContext.ts +9 -13
- package/src/useModuleCurrentContext.ts +15 -0
- package/src/useModuleQueryContext.ts +17 -0
- package/src/useQueryContext.ts +9 -11
- package/src/version.ts +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React integration for the Fusion context module.
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for reading the current context ({@link useCurrentContext},
|
|
5
|
+
* {@link useModuleCurrentContext}) and querying available contexts
|
|
6
|
+
* ({@link useQueryContext}, {@link useModuleQueryContext}).
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
1
10
|
export { enableContext, ContextModule, ContextItem, ContextItemType, IContextProvider, IContextModuleConfigurator, } from '@equinor/fusion-framework-module-context';
|
|
2
11
|
export { FusionContextSearchError } from '@equinor/fusion-framework-module-context/errors.js';
|
|
3
|
-
export { useCurrentContext
|
|
4
|
-
export {
|
|
12
|
+
export { useCurrentContext } from './useCurrentContext';
|
|
13
|
+
export { useModuleCurrentContext } from './useModuleCurrentContext';
|
|
14
|
+
export { useQueryContext } from './useQueryContext';
|
|
15
|
+
export { useModuleQueryContext } from './useModuleQueryContext';
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { ContextItem } from '@equinor/fusion-framework-module-context';
|
|
2
|
-
import {
|
|
3
|
-
export declare const useCurrentContext: (provider: IContextProvider) => {
|
|
4
|
-
currentContext: ContextItem | null | undefined;
|
|
5
|
-
setCurrentContext: (entry?: ContextItem | string | null) => void | Promise<ContextItem<Record<string, unknown>> | null>;
|
|
6
|
-
};
|
|
2
|
+
import type { IContextProvider } from '@equinor/fusion-framework-module-context';
|
|
7
3
|
/**
|
|
8
|
-
*
|
|
4
|
+
* Hook for observing and updating the framework's current context.
|
|
5
|
+
*
|
|
6
|
+
* @param provider - The context provider to observe and update
|
|
7
|
+
* @returns The current context and a setter that clears, sets by id, or sets it directly
|
|
9
8
|
*/
|
|
10
|
-
export declare const
|
|
9
|
+
export declare const useCurrentContext: (provider: IContextProvider) => {
|
|
11
10
|
currentContext: ContextItem | null | undefined;
|
|
12
11
|
setCurrentContext: (entry?: ContextItem | string | null) => void | Promise<ContextItem<Record<string, unknown>> | null>;
|
|
13
12
|
};
|
|
14
|
-
export default useModuleCurrentContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* uses context provider from closes module provider
|
|
3
|
+
*/
|
|
4
|
+
export declare const useModuleCurrentContext: () => {
|
|
5
|
+
currentContext: import("@equinor/fusion-framework-module-context").ContextItem | null | undefined;
|
|
6
|
+
setCurrentContext: (entry?: import("@equinor/fusion-framework-module-context").ContextItem | string | null) => void | Promise<import("@equinor/fusion-framework-module-context").ContextItem<Record<string, unknown>> | null>;
|
|
7
|
+
};
|
|
8
|
+
export default useModuleCurrentContext;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for querying the context module's context items, resolving the provider from the
|
|
3
|
+
* framework automatically.
|
|
4
|
+
*
|
|
5
|
+
* @param options - Optional query options, such as a debounce delay in milliseconds
|
|
6
|
+
* @returns The current query result, whether a query is in progress, and a function to trigger a new query
|
|
7
|
+
*/
|
|
8
|
+
export declare const useModuleQueryContext: (options?: {
|
|
9
|
+
debounce?: number;
|
|
10
|
+
}) => {
|
|
11
|
+
value: import("@equinor/fusion-framework-module-context").ContextItem[] | undefined;
|
|
12
|
+
querying: boolean;
|
|
13
|
+
query: (search: string) => void;
|
|
14
|
+
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IContextProvider } from '@equinor/fusion-framework-module-context';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for querying context items via the given context provider, debouncing calls.
|
|
4
|
+
*
|
|
5
|
+
* @param provider - The context provider used to perform the query
|
|
6
|
+
* @param options - Optional query options, such as a debounce delay in milliseconds
|
|
7
|
+
* @returns The current query result, whether a query is in progress, and a function to trigger a new query
|
|
8
|
+
*/
|
|
2
9
|
export declare const useQueryContext: (provider: IContextProvider, options?: {
|
|
3
10
|
debounce?: number;
|
|
4
11
|
}) => {
|
|
@@ -6,10 +13,3 @@ export declare const useQueryContext: (provider: IContextProvider, options?: {
|
|
|
6
13
|
querying: boolean;
|
|
7
14
|
query: (search: string) => void;
|
|
8
15
|
};
|
|
9
|
-
export declare const useModuleQueryContext: (options?: {
|
|
10
|
-
debounce?: number;
|
|
11
|
-
}) => {
|
|
12
|
-
value: import("@equinor/fusion-framework-module-context").ContextItem[] | undefined;
|
|
13
|
-
querying: boolean;
|
|
14
|
-
query: (search: string) => void;
|
|
15
|
-
};
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "7.0.
|
|
1
|
+
export declare const version = "7.0.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-react-module-context",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"directory": "packages/react/modules/context"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@equinor/fusion-framework-module-context": "^8.0.
|
|
26
|
-
"@equinor/fusion-framework-react-module": "^4.0.
|
|
27
|
-
"@equinor/fusion-
|
|
28
|
-
"@equinor/fusion-
|
|
25
|
+
"@equinor/fusion-framework-module-context": "^8.0.1",
|
|
26
|
+
"@equinor/fusion-framework-react-module": "^4.0.2",
|
|
27
|
+
"@equinor/fusion-observable": "^9.1.1",
|
|
28
|
+
"@equinor/fusion-query": "^7.0.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/react": "^19.2.7",
|
|
32
32
|
"@types/react-dom": "^19.2.3",
|
|
33
33
|
"react": "^19.2.1",
|
|
34
34
|
"react-dom": "^19.2.1",
|
|
35
|
-
"typescript": "^
|
|
35
|
+
"typescript": "^7.0.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@types/react": "^18.0.0 || ^19.0.0",
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React integration for the Fusion context module.
|
|
3
|
+
*
|
|
4
|
+
* Provides hooks for reading the current context ({@link useCurrentContext},
|
|
5
|
+
* {@link useModuleCurrentContext}) and querying available contexts
|
|
6
|
+
* ({@link useQueryContext}, {@link useModuleQueryContext}).
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
1
10
|
export {
|
|
2
11
|
enableContext,
|
|
3
12
|
ContextModule,
|
|
@@ -8,5 +17,7 @@ export {
|
|
|
8
17
|
} from '@equinor/fusion-framework-module-context';
|
|
9
18
|
export { FusionContextSearchError } from '@equinor/fusion-framework-module-context/errors.js';
|
|
10
19
|
|
|
11
|
-
export { useCurrentContext
|
|
12
|
-
export {
|
|
20
|
+
export { useCurrentContext } from './useCurrentContext';
|
|
21
|
+
export { useModuleCurrentContext } from './useModuleCurrentContext';
|
|
22
|
+
export { useQueryContext } from './useQueryContext';
|
|
23
|
+
export { useModuleQueryContext } from './useModuleQueryContext';
|
package/src/useCurrentContext.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import type { ContextItem
|
|
2
|
-
import {
|
|
3
|
-
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
1
|
+
import type { ContextItem } from '@equinor/fusion-framework-module-context';
|
|
2
|
+
import type { IContextProvider } from '@equinor/fusion-framework-module-context';
|
|
4
3
|
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
5
4
|
import { useCallback, useMemo } from 'react';
|
|
6
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Hook for observing and updating the framework's current context.
|
|
8
|
+
*
|
|
9
|
+
* @param provider - The context provider to observe and update
|
|
10
|
+
* @returns The current context and a setter that clears, sets by id, or sets it directly
|
|
11
|
+
*/
|
|
7
12
|
export const useCurrentContext = (provider: IContextProvider) => {
|
|
8
13
|
const currentContext$ = useMemo(() => provider.currentContext$, [provider]);
|
|
9
14
|
const { value: currentContext } = useObservableState(currentContext$, {
|
|
@@ -11,6 +16,7 @@ export const useCurrentContext = (provider: IContextProvider) => {
|
|
|
11
16
|
});
|
|
12
17
|
const setCurrentContext = useCallback(
|
|
13
18
|
(entry?: ContextItem | string | null) => {
|
|
19
|
+
// Clear the current context when no entry is provided
|
|
14
20
|
if (!entry) {
|
|
15
21
|
return provider.clearCurrentContext();
|
|
16
22
|
} else if (typeof entry === 'string') {
|
|
@@ -22,13 +28,3 @@ export const useCurrentContext = (provider: IContextProvider) => {
|
|
|
22
28
|
);
|
|
23
29
|
return { currentContext, setCurrentContext };
|
|
24
30
|
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* uses context provider from closes module provider
|
|
28
|
-
*/
|
|
29
|
-
export const useModuleCurrentContext = () => {
|
|
30
|
-
const provider = useModule<ContextModule>(contextModuleKey);
|
|
31
|
-
return useCurrentContext(provider);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default useModuleCurrentContext;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContextModule } from '@equinor/fusion-framework-module-context';
|
|
2
|
+
import { contextModuleKey } from '@equinor/fusion-framework-module-context';
|
|
3
|
+
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
4
|
+
|
|
5
|
+
import { useCurrentContext } from './useCurrentContext.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* uses context provider from closes module provider
|
|
9
|
+
*/
|
|
10
|
+
export const useModuleCurrentContext = () => {
|
|
11
|
+
const provider = useModule<ContextModule>(contextModuleKey);
|
|
12
|
+
return useCurrentContext(provider);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default useModuleCurrentContext;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ContextModule } from '@equinor/fusion-framework-module-context';
|
|
2
|
+
import { contextModuleKey } from '@equinor/fusion-framework-module-context';
|
|
3
|
+
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
4
|
+
|
|
5
|
+
import { useQueryContext } from './useQueryContext.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook for querying the context module's context items, resolving the provider from the
|
|
9
|
+
* framework automatically.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Optional query options, such as a debounce delay in milliseconds
|
|
12
|
+
* @returns The current query result, whether a query is in progress, and a function to trigger a new query
|
|
13
|
+
*/
|
|
14
|
+
export const useModuleQueryContext = (options?: { debounce?: number }) => {
|
|
15
|
+
const provider = useModule<ContextModule>(contextModuleKey);
|
|
16
|
+
return useQueryContext(provider, options);
|
|
17
|
+
};
|
package/src/useQueryContext.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ContextModule,
|
|
3
|
-
contextModuleKey,
|
|
4
|
-
type IContextProvider,
|
|
5
|
-
} from '@equinor/fusion-framework-module-context';
|
|
6
|
-
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
1
|
+
import type { IContextProvider } from '@equinor/fusion-framework-module-context';
|
|
7
2
|
import { useObservableState, useDebounce } from '@equinor/fusion-observable/react';
|
|
8
3
|
import { useMemo } from 'react';
|
|
9
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Hook for querying context items via the given context provider, debouncing calls.
|
|
7
|
+
*
|
|
8
|
+
* @param provider - The context provider used to perform the query
|
|
9
|
+
* @param options - Optional query options, such as a debounce delay in milliseconds
|
|
10
|
+
* @returns The current query result, whether a query is in progress, and a function to trigger a new query
|
|
11
|
+
*/
|
|
10
12
|
export const useQueryContext = (provider: IContextProvider, options?: { debounce?: number }) => {
|
|
13
|
+
// Layer caller-supplied options on top of the default debounce delay
|
|
11
14
|
const args = Object.assign({}, { debounce: 500 }, options);
|
|
12
15
|
const searchFn = useMemo(() => provider.queryContext.bind(provider), [provider]);
|
|
13
16
|
const { idle, next, value$ } = useDebounce(searchFn, args);
|
|
14
17
|
const { value } = useObservableState(value$);
|
|
15
18
|
return { value, querying: !idle, query: next };
|
|
16
19
|
};
|
|
17
|
-
|
|
18
|
-
export const useModuleQueryContext = (options?: { debounce?: number }) => {
|
|
19
|
-
const provider = useModule<ContextModule>(contextModuleKey);
|
|
20
|
-
return useQueryContext(provider, options);
|
|
21
|
-
};
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '7.0.
|
|
2
|
+
export const version = '7.0.2';
|