@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 7.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 80c3e4a: Internal: added a missing intent comment for object-merge logic; no public API changes.
|
|
8
|
+
- 80c3e4a: Internal: add intent comment to the `useCurrentContext` control-flow statement to satisfy the `require-intent-comment/flow` lint rule. No functional change.
|
|
9
|
+
- 80c3e4a: Internal: add missing TSDoc comments to `useCurrentContext`, `useModuleQueryContext`, and `useQueryContext` to satisfy the `require-hook-tsdoc` lint rule. No functional change.
|
|
10
|
+
- 80c3e4a: Internal: split multi-export files into one export per file and convert pure interop re-exports to `export { X } from 'y'` syntax, per `fusion-lint`'s `single-export-per-file` rule. Also removed `modules/event/src/EventProvider.tsx`, a fully dead duplicate of `eventContext.ts`/`useEventProvider.ts`/`useModulesEventProvider.ts` with no remaining consumers. No behavior changes.
|
|
11
|
+
|
|
12
|
+
## 7.0.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 86a0599: Clarify the React context module README by documenting all package exports and linking to the existing app-scoped context wrapper documentation.
|
|
17
|
+
|
|
3
18
|
## 7.0.0
|
|
4
19
|
|
|
5
20
|
### Major Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @equinor/fusion-framework-react-module-context
|
|
2
|
+
|
|
3
|
+
React hooks for the Fusion context module. Provides hooks to read the current context, set context, and query available contexts from React components.
|
|
4
|
+
|
|
5
|
+
**Import:**
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { useCurrentContext, useQueryContext, enableContext } from '@equinor/fusion-framework-react-module-context';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
| Export | Type | Description |
|
|
14
|
+
| --------------------------- | -------- | -------------------------------------------------------------- |
|
|
15
|
+
| `useCurrentContext` | Hook | Read and set the current context (requires a provider argument) |
|
|
16
|
+
| `useModuleCurrentContext` | Hook | Read and set the current context from the closest module scope |
|
|
17
|
+
| `useQueryContext` | Hook | Search available contexts with debounce (requires a provider) |
|
|
18
|
+
| `useModuleQueryContext` | Hook | Search available contexts from the closest module scope |
|
|
19
|
+
| `enableContext` | Function | Enable the context module in a configurator |
|
|
20
|
+
| `ContextModule` | Type | Context module type definition |
|
|
21
|
+
| `ContextItem` | Type | A single context entry (project, facility, etc.) |
|
|
22
|
+
| `ContextItemType` | Type | Context item type discriminator |
|
|
23
|
+
| `IContextProvider` | Type | Context provider interface |
|
|
24
|
+
| `IContextModuleConfigurator` | Type | Configurator interface for enabling the context module |
|
|
25
|
+
| `FusionContextSearchError` | Error | Error thrown when context search fails |
|
|
26
|
+
|
|
27
|
+
## This Package vs `react-app/context`
|
|
28
|
+
|
|
29
|
+
| Scenario | Import from |
|
|
30
|
+
| --------------------------------------- | ---------------------------------------------------- |
|
|
31
|
+
| Building a Fusion app (most common) | `@equinor/fusion-framework-react-app/context` |
|
|
32
|
+
| Building a reusable library or module | `@equinor/fusion-framework-react-module-context` |
|
|
33
|
+
| Building a portal or host application | `@equinor/fusion-framework-react-module-context` |
|
|
34
|
+
|
|
35
|
+
The `react-app/context` sub-path wraps these hooks with app-scoped convenience. Use this package directly when building framework-level code or shared libraries that need explicit provider injection.
|
|
36
|
+
|
|
37
|
+
## useCurrentContext / useModuleCurrentContext
|
|
38
|
+
|
|
39
|
+
Returns the currently selected context and a setter function.
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { useModuleCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
43
|
+
|
|
44
|
+
const ContextInfo = () => {
|
|
45
|
+
const { currentContext, setCurrentContext } = useModuleCurrentContext();
|
|
46
|
+
|
|
47
|
+
if (!currentContext) return <p>No context selected</p>;
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
<p>{currentContext.title}</p>
|
|
52
|
+
<button onClick={() => setCurrentContext(null)}>Clear</button>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## useQueryContext / useModuleQueryContext
|
|
59
|
+
|
|
60
|
+
Search for available contexts with built-in debounce (default 500ms).
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { useModuleQueryContext } from '@equinor/fusion-framework-react-module-context';
|
|
64
|
+
|
|
65
|
+
const ContextSearch = () => {
|
|
66
|
+
const { value: results, querying, query } = useModuleQueryContext();
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<input onChange={(e) => query(e.target.value)} placeholder="Search contexts…" />
|
|
71
|
+
{querying && <span>Searching…</span>}
|
|
72
|
+
<ul>{results?.map((ctx) => <li key={ctx.id}>{ctx.title}</li>)}</ul>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Related
|
|
79
|
+
|
|
80
|
+
- [`@equinor/fusion-framework-module-context`](../../modules/context/README.md) — the underlying context module
|
|
81
|
+
- [`@equinor/fusion-framework-react-app/context`](../../app/README.md#context) — app-developer-facing wrapper
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
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, } 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';
|
|
5
16
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAMd,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAE9F,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,aAAa,GAMd,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAE9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { contextModuleKey } from '@equinor/fusion-framework-module-context';
|
|
2
|
-
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
3
1
|
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
4
2
|
import { useCallback, useMemo } from 'react';
|
|
3
|
+
/**
|
|
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
|
|
8
|
+
*/
|
|
5
9
|
export const useCurrentContext = (provider) => {
|
|
6
10
|
const currentContext$ = useMemo(() => provider.currentContext$, [provider]);
|
|
7
11
|
const { value: currentContext } = useObservableState(currentContext$, {
|
|
8
12
|
initial: provider.currentContext,
|
|
9
13
|
});
|
|
10
14
|
const setCurrentContext = useCallback((entry) => {
|
|
15
|
+
// Clear the current context when no entry is provided
|
|
11
16
|
if (!entry) {
|
|
12
17
|
return provider.clearCurrentContext();
|
|
13
18
|
}
|
|
@@ -18,12 +23,4 @@ export const useCurrentContext = (provider) => {
|
|
|
18
23
|
}, [provider]);
|
|
19
24
|
return { currentContext, setCurrentContext };
|
|
20
25
|
};
|
|
21
|
-
/**
|
|
22
|
-
* uses context provider from closes module provider
|
|
23
|
-
*/
|
|
24
|
-
export const useModuleCurrentContext = () => {
|
|
25
|
-
const provider = useModule(contextModuleKey);
|
|
26
|
-
return useCurrentContext(provider);
|
|
27
|
-
};
|
|
28
|
-
export default useModuleCurrentContext;
|
|
29
26
|
//# sourceMappingURL=useCurrentContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentContext.js","sourceRoot":"","sources":["../../src/useCurrentContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCurrentContext.js","sourceRoot":"","sources":["../../src/useCurrentContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAA0B,EAAE,EAAE;IAC9D,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5E,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,kBAAkB,CAAC,eAAe,EAAE;QACpE,OAAO,EAAE,QAAQ,CAAC,cAAc;KACjC,CAAC,CAAC;IACH,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,KAAmC,EAAE,EAAE;QACtC,sDAAsD;QACtD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,QAAQ,CAAC,mBAAmB,EAAE,CAAC;QACxC,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,QAAQ,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,QAAQ,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IACF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC;AAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { contextModuleKey } from '@equinor/fusion-framework-module-context';
|
|
2
|
+
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
3
|
+
import { useCurrentContext } from './useCurrentContext.js';
|
|
4
|
+
/**
|
|
5
|
+
* uses context provider from closes module provider
|
|
6
|
+
*/
|
|
7
|
+
export const useModuleCurrentContext = () => {
|
|
8
|
+
const provider = useModule(contextModuleKey);
|
|
9
|
+
return useCurrentContext(provider);
|
|
10
|
+
};
|
|
11
|
+
export default useModuleCurrentContext;
|
|
12
|
+
//# sourceMappingURL=useModuleCurrentContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModuleCurrentContext.js","sourceRoot":"","sources":["../../src/useModuleCurrentContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,QAAQ,GAAG,SAAS,CAAgB,gBAAgB,CAAC,CAAC;IAC5D,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { contextModuleKey } from '@equinor/fusion-framework-module-context';
|
|
2
|
+
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
3
|
+
import { useQueryContext } from './useQueryContext.js';
|
|
4
|
+
/**
|
|
5
|
+
* Hook for querying the context module's context items, resolving the provider from the
|
|
6
|
+
* framework automatically.
|
|
7
|
+
*
|
|
8
|
+
* @param options - Optional query options, such as a debounce delay in milliseconds
|
|
9
|
+
* @returns The current query result, whether a query is in progress, and a function to trigger a new query
|
|
10
|
+
*/
|
|
11
|
+
export const useModuleQueryContext = (options) => {
|
|
12
|
+
const provider = useModule(contextModuleKey);
|
|
13
|
+
return useQueryContext(provider, options);
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=useModuleQueryContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModuleQueryContext.js","sourceRoot":"","sources":["../../src/useModuleQueryContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAA+B,EAAE,EAAE;IACvE,MAAM,QAAQ,GAAG,SAAS,CAAgB,gBAAgB,CAAC,CAAC;IAC5D,OAAO,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { contextModuleKey, } from '@equinor/fusion-framework-module-context';
|
|
2
|
-
import { useModule } from '@equinor/fusion-framework-react-module';
|
|
3
1
|
import { useObservableState, useDebounce } from '@equinor/fusion-observable/react';
|
|
4
2
|
import { useMemo } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for querying context items via the given context provider, debouncing calls.
|
|
5
|
+
*
|
|
6
|
+
* @param provider - The context provider used to perform the query
|
|
7
|
+
* @param options - Optional query options, such as a debounce delay in milliseconds
|
|
8
|
+
* @returns The current query result, whether a query is in progress, and a function to trigger a new query
|
|
9
|
+
*/
|
|
5
10
|
export const useQueryContext = (provider, options) => {
|
|
11
|
+
// Layer caller-supplied options on top of the default debounce delay
|
|
6
12
|
const args = Object.assign({}, { debounce: 500 }, options);
|
|
7
13
|
const searchFn = useMemo(() => provider.queryContext.bind(provider), [provider]);
|
|
8
14
|
const { idle, next, value$ } = useDebounce(searchFn, args);
|
|
9
15
|
const { value } = useObservableState(value$);
|
|
10
16
|
return { value, querying: !idle, query: next };
|
|
11
17
|
};
|
|
12
|
-
export const useModuleQueryContext = (options) => {
|
|
13
|
-
const provider = useModule(contextModuleKey);
|
|
14
|
-
return useQueryContext(provider, options);
|
|
15
|
-
};
|
|
16
18
|
//# sourceMappingURL=useQueryContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryContext.js","sourceRoot":"","sources":["../../src/useQueryContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useQueryContext.js","sourceRoot":"","sources":["../../src/useQueryContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAA0B,EAAE,OAA+B,EAAE,EAAE;IAC7F,qEAAqE;IACrE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3D,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACjD,CAAC,CAAC"}
|
package/dist/esm/version.js
CHANGED