@equinor/fusion-framework-react-module-context 7.0.3-next.0 → 7.0.4

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/src/index.ts DELETED
@@ -1,23 +0,0 @@
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
- */
10
- export {
11
- enableContext,
12
- ContextModule,
13
- ContextItem,
14
- ContextItemType,
15
- IContextProvider,
16
- IContextModuleConfigurator,
17
- } from '@equinor/fusion-framework-module-context';
18
- export { FusionContextSearchError } from '@equinor/fusion-framework-module-context/errors.js';
19
-
20
- export { useCurrentContext } from './useCurrentContext';
21
- export { useModuleCurrentContext } from './useModuleCurrentContext';
22
- export { useQueryContext } from './useQueryContext';
23
- export { useModuleQueryContext } from './useModuleQueryContext';
@@ -1,30 +0,0 @@
1
- import type { ContextItem } from '@equinor/fusion-framework-module-context';
2
- import type { IContextProvider } from '@equinor/fusion-framework-module-context';
3
- import { useObservableState } from '@equinor/fusion-observable/react';
4
- import { useCallback, useMemo } from 'react';
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
- */
12
- export const useCurrentContext = (provider: IContextProvider) => {
13
- const currentContext$ = useMemo(() => provider.currentContext$, [provider]);
14
- const { value: currentContext } = useObservableState(currentContext$, {
15
- initial: provider.currentContext,
16
- });
17
- const setCurrentContext = useCallback(
18
- (entry?: ContextItem | string | null) => {
19
- // Clear the current context when no entry is provided
20
- if (!entry) {
21
- return provider.clearCurrentContext();
22
- } else if (typeof entry === 'string') {
23
- return provider.setCurrentContextByIdAsync(entry);
24
- }
25
- return provider.setCurrentContextAsync(entry);
26
- },
27
- [provider],
28
- );
29
- return { currentContext, setCurrentContext };
30
- };
@@ -1,15 +0,0 @@
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;
@@ -1,17 +0,0 @@
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
- };
@@ -1,19 +0,0 @@
1
- import type { IContextProvider } from '@equinor/fusion-framework-module-context';
2
- import { useObservableState, useDebounce } from '@equinor/fusion-observable/react';
3
- import { useMemo } from 'react';
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
- */
12
- export const useQueryContext = (provider: IContextProvider, options?: { debounce?: number }) => {
13
- // Layer caller-supplied options on top of the default debounce delay
14
- const args = Object.assign({}, { debounce: 500 }, options);
15
- const searchFn = useMemo(() => provider.queryContext.bind(provider), [provider]);
16
- const { idle, next, value$ } = useDebounce(searchFn, args);
17
- const { value } = useObservableState(value$);
18
- return { value, querying: !idle, query: next };
19
- };
package/src/version.ts DELETED
@@ -1,2 +0,0 @@
1
- // Generated by genversion.
2
- export const version = '7.0.3-next.0';
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.react.json",
3
- "compilerOptions": {
4
- "outDir": "dist/esm",
5
- "rootDir": "src",
6
- "declarationDir": "./dist/types"
7
- },
8
- "references": [
9
- {
10
- "path": "../../../utils/query"
11
- },
12
- {
13
- "path": "../../../modules/context"
14
- },
15
- {
16
- "path": "../module"
17
- }
18
- ],
19
- "include": ["src/**/*"],
20
- "exclude": ["node_modules", "lib"]
21
- }