@equinor/fusion-framework-module-widget 14.0.2-next.0 → 15.0.0
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 +30 -24
- package/README.md +171 -0
- package/dist/esm/Widget.js +91 -27
- package/dist/esm/Widget.js.map +1 -1
- package/dist/esm/WidgetModuleConfigurator.js +31 -15
- package/dist/esm/WidgetModuleConfigurator.js.map +1 -1
- package/dist/esm/WidgetModuleProvider.js +52 -20
- package/dist/esm/WidgetModuleProvider.js.map +1 -1
- package/dist/esm/enable-widget-module.js +16 -2
- package/dist/esm/enable-widget-module.js.map +1 -1
- package/dist/esm/errors.js +50 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +12 -0
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/state/actions.js +18 -3
- package/dist/esm/state/actions.js.map +1 -1
- package/dist/esm/state/create-reducer.js +10 -0
- package/dist/esm/state/create-reducer.js.map +1 -1
- package/dist/esm/state/create-state.js +12 -0
- package/dist/esm/state/create-state.js.map +1 -1
- package/dist/esm/state/flows.js +22 -0
- package/dist/esm/state/flows.js.map +1 -1
- package/dist/esm/utils.js +29 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Widget.d.ts +91 -25
- package/dist/types/WidgetModuleConfigurator.d.ts +44 -10
- package/dist/types/WidgetModuleProvider.d.ts +80 -20
- package/dist/types/enable-widget-module.d.ts +16 -2
- package/dist/types/errors.d.ts +57 -0
- package/dist/types/events.d.ts +37 -17
- package/dist/types/index.d.ts +11 -2
- package/dist/types/module.d.ts +21 -0
- package/dist/types/state/actions.d.ts +29 -4
- package/dist/types/state/create-reducer.d.ts +10 -0
- package/dist/types/state/create-state.d.ts +12 -0
- package/dist/types/state/flows.d.ts +22 -0
- package/dist/types/types.d.ts +82 -15
- package/dist/types/utils.d.ts +29 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +13 -13
- package/src/Widget.ts +94 -27
- package/src/WidgetModuleConfigurator.ts +44 -17
- package/src/WidgetModuleProvider.ts +82 -20
- package/src/enable-widget-module.ts +16 -2
- package/src/errors.ts +57 -0
- package/src/events.ts +36 -17
- package/src/index.ts +12 -2
- package/src/module.ts +21 -0
- package/src/state/actions.ts +21 -3
- package/src/state/create-reducer.ts +10 -0
- package/src/state/create-state.ts +12 -0
- package/src/state/flows.ts +22 -0
- package/src/types.ts +88 -16
- package/src/utils.ts +29 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 15.0.0
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- abffa53: Major version bump for Fusion Framework React 19 release.
|
|
8
|
+
|
|
9
|
+
All packages are bumped to the next major version as part of the React 19 upgrade. This release drops support for React versions below 18 and includes breaking changes across the framework.
|
|
10
|
+
|
|
11
|
+
**Breaking changes:**
|
|
12
|
+
- Peer dependencies now require React 18 or 19 (`^18.0.0 || ^19.0.0`)
|
|
13
|
+
- React Router upgraded from v6 to v7
|
|
14
|
+
- Navigation module refactored with new history API
|
|
15
|
+
- `renderComponent` and `renderApp` now use `createRoot` API
|
|
16
|
+
|
|
17
|
+
**Migration:**
|
|
18
|
+
- Update your React version to 18.0.0 or higher before upgrading
|
|
19
|
+
- Replace `NavigationProvider.createRouter()` with `@equinor/fusion-framework-react-router`
|
|
20
|
+
- See individual package changelogs for package-specific migration steps
|
|
6
21
|
|
|
7
|
-
|
|
22
|
+
### Patch Changes
|
|
8
23
|
|
|
9
|
-
- Updated dependencies [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- @equinor/fusion-framework-module
|
|
24
|
+
- Updated dependencies [abffa53]
|
|
25
|
+
- Updated dependencies [abffa53]
|
|
26
|
+
- Updated dependencies [abffa53]
|
|
27
|
+
- Updated dependencies [abffa53]
|
|
28
|
+
- Updated dependencies [abffa53]
|
|
29
|
+
- Updated dependencies [8f30948]
|
|
30
|
+
- @equinor/fusion-framework-module@6.0.0
|
|
31
|
+
- @equinor/fusion-framework-module-event@6.0.0
|
|
32
|
+
- @equinor/fusion-framework-module-http@8.0.0
|
|
33
|
+
- @equinor/fusion-framework-module-service-discovery@10.0.0
|
|
34
|
+
- @equinor/fusion-observable@9.0.0
|
|
35
|
+
- @equinor/fusion-query@7.0.0
|
|
16
36
|
|
|
17
37
|
## 14.0.1
|
|
18
38
|
|
|
@@ -42,20 +62,6 @@
|
|
|
42
62
|
- Updated dependencies [[`1f5a8e4`](https://github.com/equinor/fusion-framework/commit/1f5a8e475ea30fa1e0f32c7dab885a5a42c50bba)]:
|
|
43
63
|
- @equinor/fusion-framework-module-event@5.0.0
|
|
44
64
|
|
|
45
|
-
## 12.0.4-next.0
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- [#3820](https://github.com/equinor/fusion-framework/pull/3820) [`265bb76`](https://github.com/equinor/fusion-framework/commit/265bb767249989eeb1971e83f3fba94879e0813b) Thanks [@odinr](https://github.com/odinr)! - relase next
|
|
50
|
-
|
|
51
|
-
- Updated dependencies [[`265bb76`](https://github.com/equinor/fusion-framework/commit/265bb767249989eeb1971e83f3fba94879e0813b), [`d252b0d`](https://github.com/equinor/fusion-framework/commit/d252b0d442b7c8c1b50bf2768cf9ecbbb55a76f8), [`9f7597e`](https://github.com/equinor/fusion-framework/commit/9f7597ee237ef069dc24cbe39c73b5b26db157dd), [`75c068f`](https://github.com/equinor/fusion-framework/commit/75c068fea13c32435ac26bd9043cc156482bfaf1)]:
|
|
52
|
-
- @equinor/fusion-observable@9.0.0-next.0
|
|
53
|
-
- @equinor/fusion-query@7.0.0-next.0
|
|
54
|
-
- @equinor/fusion-framework-module-event@4.4.1-next.0
|
|
55
|
-
- @equinor/fusion-framework-module-http@7.0.6-next.0
|
|
56
|
-
- @equinor/fusion-framework-module@5.0.6-next.0
|
|
57
|
-
- @equinor/fusion-framework-module-service-discovery@9.0.5-next.0
|
|
58
|
-
|
|
59
65
|
## 12.0.3
|
|
60
66
|
|
|
61
67
|
### Patch Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# @equinor/fusion-framework-module-widget
|
|
2
|
+
|
|
3
|
+
Fusion Framework module for loading, managing, and rendering **widgets** — self-contained UI micro-frontends that can be dynamically fetched, configured, and mounted into a host application.
|
|
4
|
+
|
|
5
|
+
## When to use this module
|
|
6
|
+
|
|
7
|
+
Use this module when your application needs to:
|
|
8
|
+
|
|
9
|
+
- Load remote widget manifests and scripts at runtime
|
|
10
|
+
- Render isolated micro-frontend widgets inside a host app
|
|
11
|
+
- Manage widget lifecycle (initialize → load manifest → import script → render → dispose)
|
|
12
|
+
- React to widget lifecycle events via the Fusion event system
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
pnpm add @equinor/fusion-framework-module-widget
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Peer dependencies
|
|
21
|
+
|
|
22
|
+
The module requires these Fusion Framework modules as peer dependencies:
|
|
23
|
+
|
|
24
|
+
| Package | Required |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `@equinor/fusion-framework-module` | **yes** |
|
|
27
|
+
| `@equinor/fusion-framework-module-event` | optional |
|
|
28
|
+
| `@equinor/fusion-framework-module-http` | optional |
|
|
29
|
+
| `@equinor/fusion-framework-module-service-discovery` | optional |
|
|
30
|
+
|
|
31
|
+
## Key concepts
|
|
32
|
+
|
|
33
|
+
### Widget lifecycle
|
|
34
|
+
|
|
35
|
+
A widget moves through the following states:
|
|
36
|
+
|
|
37
|
+
1. **Create** — `getWidget(name)` creates a `Widget` instance with initial state
|
|
38
|
+
2. **Load manifest** — fetches the widget manifest (name, version, entry point, asset path)
|
|
39
|
+
3. **Import script** — dynamically imports the widget's JavaScript entry point
|
|
40
|
+
4. **Initialize** — combines manifest + script (+ optional config) and emits the result
|
|
41
|
+
5. **Render** — the imported script module exposes render functions (`renderWidget`, `render`, etc.)
|
|
42
|
+
6. **Dispose** — cleans up subscriptions and resources
|
|
43
|
+
|
|
44
|
+
### Architecture
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
enableWidgetModule()
|
|
48
|
+
└─► WidgetModuleConfigurator (configure HTTP client, endpoints)
|
|
49
|
+
└─► WidgetModuleProvider (create and manage Widget instances)
|
|
50
|
+
└─► Widget (manifest, script, config, state machine)
|
|
51
|
+
└─► state/ (actions, reducer, flows — RxJS-based)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- **`WidgetModuleConfigurator`** — configures the HTTP client used to fetch widget manifests and configs from the backend API
|
|
55
|
+
- **`WidgetModuleProvider`** — implements `IWidgetModuleProvider` and serves as the entry point for creating `Widget` instances
|
|
56
|
+
- **`Widget`** — manages a single widget's full lifecycle using an RxJS-based state machine (`FlowSubject`)
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
59
|
+
|
|
60
|
+
### Enable the module
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { enableWidgetModule } from '@equinor/fusion-framework-module-widget';
|
|
64
|
+
|
|
65
|
+
// In your framework configuration callback:
|
|
66
|
+
enableWidgetModule(configurator);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Customize the HTTP client
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
enableWidgetModule(configurator, (widgetConfigurator) => {
|
|
73
|
+
widgetConfigurator.setClient(async (client) => {
|
|
74
|
+
// Return a custom IClient implementation
|
|
75
|
+
return myCustomClient;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Retrieve and initialize a widget
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const provider = modules.widget; // IWidgetModuleProvider
|
|
84
|
+
|
|
85
|
+
// Create a widget instance
|
|
86
|
+
const widget = provider.getWidget('my-widget');
|
|
87
|
+
|
|
88
|
+
// Initialize: loads manifest, imports script, prepares config
|
|
89
|
+
widget.initialize().subscribe({
|
|
90
|
+
next: ({ manifest, script, config }) => {
|
|
91
|
+
// Mount the widget into a DOM element
|
|
92
|
+
const cleanup = script.renderWidget(hostElement, { fusion, env: { manifest } });
|
|
93
|
+
},
|
|
94
|
+
error: (err) => console.error('Widget initialization failed', err),
|
|
95
|
+
complete: () => console.log('Widget ready'),
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Observe manifest or config individually
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// Stream the manifest
|
|
103
|
+
provider.getWidgetManifest('my-widget').subscribe((manifest) => {
|
|
104
|
+
console.log('Manifest:', manifest);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Stream the config
|
|
108
|
+
provider.getWidgetConfig('my-widget').subscribe((config) => {
|
|
109
|
+
console.log('Config:', config);
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Exported entry points
|
|
114
|
+
|
|
115
|
+
| Export path | Description |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `@equinor/fusion-framework-module-widget` | Main entry — module definition, configurator, provider, types, and `enableWidgetModule` |
|
|
118
|
+
| `@equinor/fusion-framework-module-widget/errors.js` | Error classes: `WidgetManifestLoadError`, `WidgetConfigLoadError`, `WidgetScriptModuleError` |
|
|
119
|
+
|
|
120
|
+
## Events
|
|
121
|
+
|
|
122
|
+
When the optional `@equinor/fusion-framework-module-event` peer dependency is available, the module dispatches lifecycle events on the framework event bus:
|
|
123
|
+
|
|
124
|
+
| Event | Fired when |
|
|
125
|
+
|---|---|
|
|
126
|
+
| `onWidgetManifestLoad` | Manifest fetch starts |
|
|
127
|
+
| `onWidgetManifestLoaded` | Manifest fetch succeeds |
|
|
128
|
+
| `onWidgetManifestFailure` | Manifest fetch fails |
|
|
129
|
+
| `onWidgetScriptLoad` | Script import starts |
|
|
130
|
+
| `onWidgetScriptLoaded` | Script import succeeds |
|
|
131
|
+
| `onWidgetScriptFailure` | Script import fails |
|
|
132
|
+
| `onWidgetInitialize` | Widget initialization starts |
|
|
133
|
+
| `onWidgetInitialized` | Widget initialization completes |
|
|
134
|
+
| `onWidgetInitializeFailure` | Widget initialization fails |
|
|
135
|
+
| `onWidgetDispose` | Widget is disposed |
|
|
136
|
+
|
|
137
|
+
## Error handling
|
|
138
|
+
|
|
139
|
+
The module provides typed error classes for HTTP-level failures:
|
|
140
|
+
|
|
141
|
+
- **`WidgetManifestLoadError`** — manifest fetch failed (maps 401 → `unauthorized`, 404 → `not_found`)
|
|
142
|
+
- **`WidgetConfigLoadError`** — config fetch failed (same HTTP status mapping)
|
|
143
|
+
- **`WidgetScriptModuleError`** — script import failed
|
|
144
|
+
|
|
145
|
+
Each error carries a `type` discriminator (`'not_found' | 'unauthorized' | 'unknown'`) for programmatic branching.
|
|
146
|
+
|
|
147
|
+
## API reference
|
|
148
|
+
|
|
149
|
+
### `enableWidgetModule(configurator, builder?)`
|
|
150
|
+
|
|
151
|
+
Registers the widget module on a framework configurator. Accepts an optional builder callback to customize the `WidgetModuleConfigurator`.
|
|
152
|
+
|
|
153
|
+
### `WidgetModuleProvider` / `IWidgetModuleProvider`
|
|
154
|
+
|
|
155
|
+
- `getWidget(name, args?)` — creates a `Widget` instance
|
|
156
|
+
- `getWidgetManifest(name, args?)` — returns `Observable<WidgetManifest>`
|
|
157
|
+
- `getWidgetConfig(name, args?)` — returns `Observable<WidgetConfig>`
|
|
158
|
+
- `dispose()` — cleans up all query subscriptions
|
|
159
|
+
|
|
160
|
+
### `Widget`
|
|
161
|
+
|
|
162
|
+
- `state` — current `WidgetState` snapshot
|
|
163
|
+
- `initialize()` — returns `Observable<{ manifest, script, config }>`
|
|
164
|
+
- `getManifest(force?)` — returns `Observable<WidgetManifest>`
|
|
165
|
+
- `getConfig(force?)` — returns `Observable<WidgetConfig>`
|
|
166
|
+
- `getWidgetModule(force?)` — returns `Observable<WidgetScriptModule>`
|
|
167
|
+
- `getWidgetModuleAsync(allowCache?)` — returns `Promise<WidgetScriptModule>`
|
|
168
|
+
- `loadManifest(update?)` — dispatches manifest fetch action
|
|
169
|
+
- `loadConfig(update?)` — dispatches config fetch action
|
|
170
|
+
- `updateManifest(manifest, replace?)` — sets manifest in state
|
|
171
|
+
- `dispose()` — unsubscribes all internal subscriptions
|
package/dist/esm/Widget.js
CHANGED
|
@@ -2,21 +2,50 @@ import { actions } from './state/actions';
|
|
|
2
2
|
import { createState } from './state/create-state';
|
|
3
3
|
import { Observable, Subscription, combineLatest, firstValueFrom, lastValueFrom, of } from 'rxjs';
|
|
4
4
|
import './events';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Manages the full lifecycle of a single Fusion widget.
|
|
7
|
+
*
|
|
8
|
+
* A `Widget` encapsulates fetching its manifest, dynamically importing its
|
|
9
|
+
* script entry point, loading configuration, and emitting lifecycle events.
|
|
10
|
+
* Internally it uses an RxJS-based `FlowSubject` state machine driven by
|
|
11
|
+
* actions and flows defined in the `state/` directory.
|
|
12
|
+
*
|
|
13
|
+
* Create instances via {@link WidgetModuleProvider.getWidget} rather than
|
|
14
|
+
* constructing directly.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const widget = provider.getWidget('my-widget');
|
|
19
|
+
* widget.initialize().subscribe(({ manifest, script }) => {
|
|
20
|
+
* script.renderWidget(el, { fusion, env: { manifest } });
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
6
24
|
export class Widget {
|
|
7
25
|
#state;
|
|
26
|
+
/** Human-readable widget name used as the lookup key for manifest and config. */
|
|
8
27
|
name;
|
|
28
|
+
/** Module-level HTTP client configuration used to resolve asset URLs. */
|
|
9
29
|
config;
|
|
30
|
+
/** Optional version or tag parameters forwarded to manifest/config endpoints. */
|
|
10
31
|
widgetPrams;
|
|
11
32
|
#subscription = new Subscription();
|
|
12
|
-
|
|
33
|
+
/** Current snapshot of the widget's internal state (manifest, config, modules, status). */
|
|
13
34
|
get state() {
|
|
14
35
|
return this.#state.value;
|
|
15
36
|
}
|
|
16
37
|
/**
|
|
17
|
-
* Constructs a new Widget instance.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
38
|
+
* Constructs a new `Widget` instance.
|
|
39
|
+
*
|
|
40
|
+
* Prefer using {@link WidgetModuleProvider.getWidget} instead of calling
|
|
41
|
+
* this constructor directly.
|
|
42
|
+
*
|
|
43
|
+
* @param value - Initial widget state (at minimum, the widget `name`).
|
|
44
|
+
* @param args - Dependencies required by the widget.
|
|
45
|
+
* @param args.provider - The owning {@link WidgetModuleProvider}.
|
|
46
|
+
* @param args.config - Optional module-level HTTP client configuration.
|
|
47
|
+
* @param args.event - Optional event module for dispatching lifecycle events.
|
|
48
|
+
* @param args.widgetPrams - Optional version/tag selector for the widget.
|
|
20
49
|
*/
|
|
21
50
|
constructor(value, args) {
|
|
22
51
|
this.name = value.name;
|
|
@@ -87,9 +116,15 @@ export class Widget {
|
|
|
87
116
|
});
|
|
88
117
|
}
|
|
89
118
|
/**
|
|
90
|
-
* Retrieves the manifest
|
|
91
|
-
*
|
|
92
|
-
*
|
|
119
|
+
* Retrieves the widget manifest as an observable stream.
|
|
120
|
+
*
|
|
121
|
+
* If the manifest is already cached in state it is emitted immediately.
|
|
122
|
+
* When `force_refresh` is `true`, a new fetch is dispatched regardless of
|
|
123
|
+
* cache status.
|
|
124
|
+
*
|
|
125
|
+
* @param force_refresh - When `true`, re-fetches the manifest even if cached.
|
|
126
|
+
* @returns Observable that emits the {@link WidgetManifest} and completes.
|
|
127
|
+
* @throws {Error} When the manifest fetch fails (wraps the underlying cause).
|
|
93
128
|
*/
|
|
94
129
|
getManifest(force_refresh = false) {
|
|
95
130
|
return new Observable((subscriber) => {
|
|
@@ -115,9 +150,14 @@ export class Widget {
|
|
|
115
150
|
});
|
|
116
151
|
}
|
|
117
152
|
/**
|
|
118
|
-
* Retrieves the configuration
|
|
119
|
-
*
|
|
120
|
-
*
|
|
153
|
+
* Retrieves the widget configuration as an observable stream.
|
|
154
|
+
*
|
|
155
|
+
* Returns the cached config immediately when available. Set `force_refresh`
|
|
156
|
+
* to `true` to force a new fetch from the backend API.
|
|
157
|
+
*
|
|
158
|
+
* @param force_refresh - When `true`, re-fetches the config even if cached.
|
|
159
|
+
* @returns Observable that emits the {@link WidgetConfig} and completes.
|
|
160
|
+
* @throws {Error} When the config fetch fails (wraps the underlying cause).
|
|
121
161
|
*/
|
|
122
162
|
getConfig(force_refresh = false) {
|
|
123
163
|
return new Observable((subscriber) => {
|
|
@@ -144,23 +184,33 @@ export class Widget {
|
|
|
144
184
|
});
|
|
145
185
|
}
|
|
146
186
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
187
|
+
* Dispatches a config fetch action into the state machine.
|
|
188
|
+
*
|
|
189
|
+
* @param update - When `true`, merges the fetched config with existing state
|
|
190
|
+
* instead of replacing it.
|
|
149
191
|
*/
|
|
150
192
|
loadConfig(update) {
|
|
151
193
|
this.#state.next(actions.fetchConfig({ key: this.name, ...this.widgetPrams }, update));
|
|
152
194
|
}
|
|
153
195
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
196
|
+
* Dispatches a manifest fetch action into the state machine.
|
|
197
|
+
*
|
|
198
|
+
* @param update - When `true`, merges the fetched manifest with existing
|
|
199
|
+
* state instead of replacing it.
|
|
156
200
|
*/
|
|
157
201
|
loadManifest(update) {
|
|
158
202
|
this.#state.next(actions.fetchManifest({ key: this.name, ...this.widgetPrams }, update));
|
|
159
203
|
}
|
|
160
204
|
/**
|
|
161
|
-
* Retrieves the widget module as an observable stream.
|
|
162
|
-
*
|
|
163
|
-
*
|
|
205
|
+
* Retrieves the widget's script module as an observable stream.
|
|
206
|
+
*
|
|
207
|
+
* Resolves the manifest first, builds the full import URL from the asset
|
|
208
|
+
* path and entry point, then dynamically imports the script. The imported
|
|
209
|
+
* module is cached in state for subsequent calls.
|
|
210
|
+
*
|
|
211
|
+
* @param force_refresh - When `true`, re-imports the script even if cached.
|
|
212
|
+
* @returns Observable that emits the {@link WidgetScriptModule} and completes.
|
|
213
|
+
* @throws {Error} When the script import fails (wraps the underlying cause).
|
|
164
214
|
*/
|
|
165
215
|
getWidgetModule(force_refresh = false) {
|
|
166
216
|
return new Observable((subscriber) => {
|
|
@@ -192,8 +242,12 @@ export class Widget {
|
|
|
192
242
|
});
|
|
193
243
|
}
|
|
194
244
|
/**
|
|
195
|
-
* Initializes the widget
|
|
196
|
-
*
|
|
245
|
+
* Initializes the widget by loading the manifest, importing the script, and
|
|
246
|
+
* preparing configuration. Emits a combined result when all resources are ready.
|
|
247
|
+
*
|
|
248
|
+
* @returns Observable that emits `{ manifest, script, config }` and completes
|
|
249
|
+
* once all resources have been resolved.
|
|
250
|
+
* @throws {Error} When any initialization step fails.
|
|
197
251
|
*/
|
|
198
252
|
initialize() {
|
|
199
253
|
return new Observable((observer) => {
|
|
@@ -223,24 +277,34 @@ export class Widget {
|
|
|
223
277
|
});
|
|
224
278
|
}
|
|
225
279
|
/**
|
|
226
|
-
* Retrieves the widget module
|
|
227
|
-
*
|
|
228
|
-
*
|
|
280
|
+
* Retrieves the widget script module as a `Promise`.
|
|
281
|
+
*
|
|
282
|
+
* When `allow_cache` is `true` (default), resolves with the first emitted
|
|
283
|
+
* value (which may be cached). When `false`, waits for the last emission
|
|
284
|
+
* after a forced refresh.
|
|
285
|
+
*
|
|
286
|
+
* @param allow_cache - When `true`, uses `firstValueFrom`; when `false`,
|
|
287
|
+
* uses `lastValueFrom` after forcing a re-import.
|
|
288
|
+
* @returns Promise that resolves with the {@link WidgetScriptModule}.
|
|
229
289
|
*/
|
|
230
290
|
getWidgetModuleAsync(allow_cache = true) {
|
|
231
291
|
const operator = allow_cache ? firstValueFrom : lastValueFrom;
|
|
232
292
|
return operator(this.getWidgetModule(!allow_cache));
|
|
233
293
|
}
|
|
234
294
|
/**
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
* @param
|
|
295
|
+
* Replaces or merges the widget manifest in state.
|
|
296
|
+
*
|
|
297
|
+
* @param manifest - The new or partial manifest to set.
|
|
298
|
+
* @param replace - When `false` (default), the new manifest is merged with
|
|
299
|
+
* the existing one. Pass explicit `false` to merge, or omit to merge.
|
|
238
300
|
*/
|
|
239
301
|
updateManifest(manifest, replace) {
|
|
240
302
|
this.#state.next(actions.setManifest(manifest, !replace));
|
|
241
303
|
}
|
|
242
304
|
/**
|
|
243
|
-
* Disposes of the widget by unsubscribing from
|
|
305
|
+
* Disposes of the widget by unsubscribing from all internal subscriptions.
|
|
306
|
+
*
|
|
307
|
+
* After disposal the widget instance should not be reused.
|
|
244
308
|
*/
|
|
245
309
|
dispose() {
|
|
246
310
|
this.#subscription.unsubscribe();
|
package/dist/esm/Widget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Widget.js","sourceRoot":"","sources":["../../src/Widget.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAIlG,OAAO,UAAU,CAAC;AAElB
|
|
1
|
+
{"version":3,"file":"Widget.js","sourceRoot":"","sources":["../../src/Widget.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,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AC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;oBAC/C,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACtB,CAAC;aACF,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD;;;;;;;;;;OAUG;IACI,oBAAoB,CAAC,WAAW,GAAG,IAAI;QAC5C,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC;QAC9D,OAAO,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;IACtD,CAAC;IACD;;;;;;OAMG;IACI,cAAc,CAAC,QAAwB,EAAE,OAAe;QAC7D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACI,OAAO;QACZ,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -1,21 +1,38 @@
|
|
|
1
1
|
import { BaseConfigBuilder } from '@equinor/fusion-framework-module';
|
|
2
2
|
import { createDefaultClient } from './utils';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Configuration builder for the widget module.
|
|
5
|
+
*
|
|
6
|
+
* Extends `BaseConfigBuilder` to produce a {@link WidgetModuleConfig}. If no
|
|
7
|
+
* custom client is provided via {@link setClient}, a default HTTP client is
|
|
8
|
+
* created from the `apps` service-discovery endpoint.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* enableWidgetModule(configurator, (builder) => {
|
|
13
|
+
* builder.setClient(async () => myCustomClient);
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
4
17
|
export class WidgetModuleConfigurator extends BaseConfigBuilder {
|
|
5
|
-
|
|
18
|
+
/** Default cache expiration time in milliseconds (1 minute). */
|
|
6
19
|
defaultExpireTime = 1 * 60 * 1000;
|
|
7
20
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
21
|
+
* Registers a custom {@link IClient} factory for the widget module.
|
|
22
|
+
*
|
|
23
|
+
* @param cb - Callback that receives config-builder args and returns an
|
|
24
|
+
* `IClient` instance (or a `Promise` thereof).
|
|
10
25
|
*/
|
|
11
26
|
setClient(cb) {
|
|
12
27
|
this._set('client', cb);
|
|
13
28
|
}
|
|
14
29
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
30
|
+
* Creates an HTTP client by resolving the `apps` client from the HTTP module
|
|
31
|
+
* or falling back to service discovery.
|
|
32
|
+
*
|
|
33
|
+
* @param clientId - Registered HTTP client identifier (typically `'apps'`).
|
|
34
|
+
* @param init - Framework config-builder callback args providing module instances.
|
|
35
|
+
* @returns An `IHttpClient` instance for widget API calls.
|
|
19
36
|
*/
|
|
20
37
|
async _createHttpClient(clientId, init) {
|
|
21
38
|
const http = await init.requireInstance('http');
|
|
@@ -29,19 +46,18 @@ export class WidgetModuleConfigurator extends BaseConfigBuilder {
|
|
|
29
46
|
}
|
|
30
47
|
}
|
|
31
48
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
49
|
+
* Finalizes the configuration by creating the default HTTP client when no
|
|
50
|
+
* custom client has been set.
|
|
51
|
+
*
|
|
52
|
+
* @param config - Partial configuration accumulated by builder callbacks.
|
|
53
|
+
* @param _init - Framework config-builder callback args.
|
|
54
|
+
* @returns The fully resolved {@link WidgetModuleConfig}.
|
|
36
55
|
*/
|
|
37
56
|
async _processConfig(config, _init) {
|
|
38
|
-
// Create an HTTP client using the specified client ID and initialization parameters
|
|
39
57
|
const httpClient = await this._createHttpClient('apps', _init);
|
|
40
|
-
// If the configuration does not have a client, use the default client
|
|
41
58
|
if (!config.client) {
|
|
42
59
|
config.client = createDefaultClient(httpClient);
|
|
43
60
|
}
|
|
44
|
-
// Return the processed configuration as a WidgetModuleConfig object
|
|
45
61
|
return config;
|
|
46
62
|
}
|
|
47
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WidgetModuleConfigurator.js","sourceRoot":"","sources":["../../src/WidgetModuleConfigurator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA8B,MAAM,kCAAkC,CAAC;AAEjG,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"WidgetModuleConfigurator.js","sourceRoot":"","sources":["../../src/WidgetModuleConfigurator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA8B,MAAM,kCAAkC,CAAC;AAEjG,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAwB9C;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,wBAAyB,SAAQ,iBAAqC;IACjF,gEAAgE;IAChE,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAElC;;;;;OAKG;IACI,SAAS,CAAC,EAAkC;QACjD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,iBAAiB,CAAC,QAAgB,EAAE,IAA+B;QAC/E,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAEhD,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,oCAAoC;YACpC,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;YACxE,OAAO,MAAM,gBAAgB,CAAC,YAAY,CAAC,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