@equinor/fusion-framework-react-module-context 7.0.0 → 7.0.1
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 +6 -0
- package/README.md +81 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +9 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -5
- package/src/index.ts +9 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
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,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 { enableContext, } from '@equinor/fusion-framework-module-context';
|
|
2
11
|
export { FusionContextSearchError } from '@equinor/fusion-framework-module-context/errors.js';
|
|
3
12
|
export { useCurrentContext, useModuleCurrentContext } from './useCurrentContext';
|
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,qBAAqB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
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,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/esm/version.js
CHANGED