@equinor/fusion-framework-module-widget 16.0.6 → 16.0.8
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/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +15 -12
- package/CHANGELOG.md +0 -883
- package/src/Widget.ts +0 -403
- package/src/WidgetManifestLoadError.ts +0 -61
- package/src/WidgetModuleConfigurator.ts +0 -96
- package/src/WidgetModuleProvider.ts +0 -233
- package/src/enable-widget-module.ts +0 -35
- package/src/errors/WidgetConfigLoadError.ts +0 -51
- package/src/errors/WidgetScriptModuleError.ts +0 -20
- package/src/events.ts +0 -94
- package/src/index.ts +0 -21
- package/src/module.ts +0 -61
- package/src/state/actions.ts +0 -88
- package/src/state/create-reducer.ts +0 -57
- package/src/state/create-state.ts +0 -33
- package/src/state/flows.ts +0 -123
- package/src/types.ts +0 -203
- package/src/utils.ts +0 -85
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -25
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { catchError, type Observable, Subscription } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import type { ModuleType } from '@equinor/fusion-framework-module';
|
|
4
|
-
import { HttpResponseError } from '@equinor/fusion-framework-module-http';
|
|
5
|
-
import type { EventModule } from '@equinor/fusion-framework-module-event';
|
|
6
|
-
|
|
7
|
-
import { Query } from '@equinor/fusion-query';
|
|
8
|
-
|
|
9
|
-
import type { GetWidgetParameters, WidgetConfig, WidgetManifest } from './types';
|
|
10
|
-
|
|
11
|
-
import type { WidgetModuleConfig } from './WidgetModuleConfigurator';
|
|
12
|
-
import { WidgetManifestLoadError, WidgetConfigLoadError } from './WidgetManifestLoadError';
|
|
13
|
-
import { Widget } from './Widget';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Public interface for the widget module provider.
|
|
17
|
-
*
|
|
18
|
-
* Consumers depend on this interface rather than the concrete
|
|
19
|
-
* {@link WidgetModuleProvider} class, enabling testability and
|
|
20
|
-
* alternative implementations.
|
|
21
|
-
*/
|
|
22
|
-
export interface IWidgetModuleProvider {
|
|
23
|
-
/**
|
|
24
|
-
* Creates a {@link Widget} instance for the given widget key.
|
|
25
|
-
*
|
|
26
|
-
* @param widgetKey - Unique identifier (name) of the widget.
|
|
27
|
-
* @param args - Optional version or tag selector.
|
|
28
|
-
* @returns A new `Widget` ready for initialization.
|
|
29
|
-
*/
|
|
30
|
-
getWidget(
|
|
31
|
-
widgetKey: GetWidgetParameters['widgetKey'],
|
|
32
|
-
args?: GetWidgetParameters['args'],
|
|
33
|
-
): Widget;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Fetches the manifest for a widget as an observable stream.
|
|
37
|
-
*
|
|
38
|
-
* @param widgetKey - Unique identifier (name) of the widget.
|
|
39
|
-
* @param args - Optional version or tag selector.
|
|
40
|
-
* @returns Observable that emits the {@link WidgetManifest}.
|
|
41
|
-
*/
|
|
42
|
-
getWidgetManifest(
|
|
43
|
-
widgetKey: GetWidgetParameters['widgetKey'],
|
|
44
|
-
args?: GetWidgetParameters['args'],
|
|
45
|
-
): Observable<WidgetManifest>;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Fetches the configuration for a widget as an observable stream.
|
|
49
|
-
*
|
|
50
|
-
* @param widgetKey - Unique identifier (name) of the widget.
|
|
51
|
-
* @param args - Optional version or tag selector.
|
|
52
|
-
* @returns Observable that emits the {@link WidgetConfig}.
|
|
53
|
-
*/
|
|
54
|
-
getWidgetConfig(
|
|
55
|
-
widgetKey: GetWidgetParameters['widgetKey'],
|
|
56
|
-
args?: GetWidgetParameters['args'],
|
|
57
|
-
): Observable<WidgetConfig>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Concrete provider that manages widget instances and performs API queries
|
|
62
|
-
* for widget manifests and configurations.
|
|
63
|
-
*
|
|
64
|
-
* Created automatically during module initialization; see {@link module} and
|
|
65
|
-
* {@link enableWidgetModule}.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const widget = provider.getWidget('my-widget');
|
|
70
|
-
* widget.initialize().subscribe(result => { ... });
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export class WidgetModuleProvider implements IWidgetModuleProvider {
|
|
74
|
-
// Private fields
|
|
75
|
-
#subscription = new Subscription();
|
|
76
|
-
#config: WidgetModuleConfig;
|
|
77
|
-
#event?: ModuleType<EventModule>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Creates a new `WidgetModuleProvider`.
|
|
81
|
-
*
|
|
82
|
-
* @param args - Provider dependencies.
|
|
83
|
-
* @param args.config - Resolved {@link WidgetModuleConfig} with HTTP client.
|
|
84
|
-
* @param args.event - Optional event module for dispatching lifecycle events.
|
|
85
|
-
*/
|
|
86
|
-
constructor(args: { config: WidgetModuleConfig; event?: ModuleType<EventModule> }) {
|
|
87
|
-
const { config, event } = args;
|
|
88
|
-
this.#event = event;
|
|
89
|
-
this.#config = config;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Creates a new {@link Widget} instance for the given name.
|
|
94
|
-
*
|
|
95
|
-
* The returned widget has not been initialized yet — call
|
|
96
|
-
* {@link Widget.initialize} to start the lifecycle.
|
|
97
|
-
*
|
|
98
|
-
* @param name - Unique widget name (used as lookup key).
|
|
99
|
-
* @param widgetPrams - Optional version or tag selector.
|
|
100
|
-
* @returns A new `Widget` instance.
|
|
101
|
-
*/
|
|
102
|
-
public getWidget(name: string, widgetPrams?: GetWidgetParameters['args']): Widget {
|
|
103
|
-
return new Widget(
|
|
104
|
-
{ name },
|
|
105
|
-
{ provider: this, event: this.#event, widgetPrams, config: this.#config },
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Fetches the manifest for a widget via the configured HTTP client.
|
|
111
|
-
*
|
|
112
|
-
* @param name - Unique widget name.
|
|
113
|
-
* @param widgetPrams - Optional version or tag selector.
|
|
114
|
-
* @returns Observable that emits the {@link WidgetManifest} and completes.
|
|
115
|
-
* @throws {WidgetManifestLoadError} When the manifest request fails.
|
|
116
|
-
*/
|
|
117
|
-
public getWidgetManifest(
|
|
118
|
-
name: string,
|
|
119
|
-
widgetPrams?: GetWidgetParameters['args'],
|
|
120
|
-
): Observable<WidgetManifest> {
|
|
121
|
-
return this._getWidget(name, widgetPrams);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Fetches the configuration for a widget via the configured HTTP client.
|
|
126
|
-
*
|
|
127
|
-
* @param name - Unique widget name.
|
|
128
|
-
* @param widgetPrams - Optional version or tag selector.
|
|
129
|
-
* @returns Observable that emits the {@link WidgetConfig} and completes.
|
|
130
|
-
* @throws {WidgetConfigLoadError} When the config request fails.
|
|
131
|
-
*/
|
|
132
|
-
public getWidgetConfig(
|
|
133
|
-
name: string,
|
|
134
|
-
widgetPrams?: GetWidgetParameters['args'],
|
|
135
|
-
): Observable<WidgetConfig> {
|
|
136
|
-
return this._getWidgetConfig(name, widgetPrams);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Internal: queries widget config from the API and maps HTTP errors to
|
|
141
|
-
* typed {@link WidgetConfigLoadError} instances.
|
|
142
|
-
*
|
|
143
|
-
* @param widgetKey - Widget identifier.
|
|
144
|
-
* @param args - Optional version or tag selector.
|
|
145
|
-
* @returns Observable emitting the {@link WidgetConfig}.
|
|
146
|
-
* @throws {WidgetManifestLoadError} When the underlying query fails.
|
|
147
|
-
*/
|
|
148
|
-
protected _getWidgetConfig(
|
|
149
|
-
widgetKey: GetWidgetParameters['widgetKey'],
|
|
150
|
-
args?: GetWidgetParameters['args'],
|
|
151
|
-
): Observable<WidgetConfig> {
|
|
152
|
-
const client = new Query(this.#config.client.getWidgetConfig);
|
|
153
|
-
this.#subscription.add(() => client.complete());
|
|
154
|
-
// Execute the query and handle errors
|
|
155
|
-
return Query.extractQueryValue(
|
|
156
|
-
// Map any query failure to a typed `WidgetManifestLoadError`
|
|
157
|
-
client.query({ widgetKey, args }).pipe(
|
|
158
|
-
catchError((err) => {
|
|
159
|
-
// Extract the cause since the error will be a `QueryError`
|
|
160
|
-
const { cause } = err;
|
|
161
|
-
|
|
162
|
-
// Handle specific errors and throw a `GetWidgetManifestError` if applicable
|
|
163
|
-
if (cause instanceof WidgetManifestLoadError) {
|
|
164
|
-
throw cause;
|
|
165
|
-
}
|
|
166
|
-
// Map HTTP failures to a `WidgetManifestLoadError` carrying the response
|
|
167
|
-
if (cause instanceof HttpResponseError) {
|
|
168
|
-
throw WidgetManifestLoadError.fromHttpResponse(cause.response, {
|
|
169
|
-
cause,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
// Throw a generic `GetWidgetManifestError` for unknown errors
|
|
173
|
-
throw new WidgetManifestLoadError('unknown', 'failed to load config', {
|
|
174
|
-
cause,
|
|
175
|
-
});
|
|
176
|
-
}),
|
|
177
|
-
),
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Internal: queries widget manifest from the API and maps HTTP errors to
|
|
183
|
-
* typed {@link WidgetManifestLoadError} instances.
|
|
184
|
-
*
|
|
185
|
-
* @param widgetKey - Widget identifier.
|
|
186
|
-
* @param args - Optional version or tag selector.
|
|
187
|
-
* @returns Observable emitting the {@link WidgetManifest}.
|
|
188
|
-
* @throws {WidgetConfigLoadError} When the underlying query fails.
|
|
189
|
-
*/
|
|
190
|
-
protected _getWidget(
|
|
191
|
-
widgetKey: GetWidgetParameters['widgetKey'],
|
|
192
|
-
args?: GetWidgetParameters['args'],
|
|
193
|
-
): Observable<WidgetManifest> {
|
|
194
|
-
// Create a new query using the configured client
|
|
195
|
-
const client = new Query(this.#config.client.getWidgetManifest);
|
|
196
|
-
this.#subscription.add(() => client.complete());
|
|
197
|
-
|
|
198
|
-
// Execute the query and handle errors
|
|
199
|
-
return Query.extractQueryValue(
|
|
200
|
-
// Map any query failure to a typed `WidgetConfigLoadError`
|
|
201
|
-
client.query({ widgetKey, args }).pipe(
|
|
202
|
-
catchError((err) => {
|
|
203
|
-
// Extract the cause since the error will be a `QueryError`
|
|
204
|
-
const { cause } = err;
|
|
205
|
-
|
|
206
|
-
// Handle specific errors and throw a `GetWidgetConfigError` if applicable
|
|
207
|
-
if (cause instanceof WidgetConfigLoadError) {
|
|
208
|
-
throw cause;
|
|
209
|
-
}
|
|
210
|
-
// Map HTTP failures to a `WidgetConfigLoadError` carrying the response
|
|
211
|
-
if (cause instanceof HttpResponseError) {
|
|
212
|
-
throw WidgetConfigLoadError.fromHttpResponse(cause.response, { cause });
|
|
213
|
-
}
|
|
214
|
-
// Throw a generic `GetWidgetManifestError` for unknown errors
|
|
215
|
-
throw new WidgetConfigLoadError('unknown', 'failed to load config', {
|
|
216
|
-
cause,
|
|
217
|
-
});
|
|
218
|
-
}),
|
|
219
|
-
),
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Disposes all internal query subscriptions.
|
|
225
|
-
*
|
|
226
|
-
* After disposal the provider should not be reused.
|
|
227
|
-
*/
|
|
228
|
-
public dispose() {
|
|
229
|
-
this.#subscription.unsubscribe();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export default WidgetModuleProvider;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
-
|
|
3
|
-
import { module } from './module';
|
|
4
|
-
import type { WidgetModuleConfigBuilderCallback } from './WidgetModuleConfigurator';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Registers the widget module on a Fusion Framework configurator.
|
|
8
|
-
*
|
|
9
|
-
* Call this during framework setup to enable widget loading, manifest
|
|
10
|
-
* resolution, and script import capabilities.
|
|
11
|
-
*
|
|
12
|
-
* @param configurator - The framework modules configurator to register the
|
|
13
|
-
* widget module on.
|
|
14
|
-
* @param builder - Optional callback to customize the
|
|
15
|
-
* {@link WidgetModuleConfigurator} (e.g., set a custom HTTP client).
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { enableWidgetModule } from '@equinor/fusion-framework-module-widget';
|
|
20
|
-
*
|
|
21
|
-
* enableWidgetModule(configurator);
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const enableWidgetModule = (
|
|
25
|
-
// biome-ignore lint/suspicious/noExplicitAny: `IModulesConfigurator<any, any>` widens to accept a configurator for any concrete module set — `unknown` would break assignability of a real configurator instance to this parameter
|
|
26
|
-
configurator: IModulesConfigurator<any, any>,
|
|
27
|
-
builder?: WidgetModuleConfigBuilderCallback,
|
|
28
|
-
): void => {
|
|
29
|
-
configurator.addConfig({
|
|
30
|
-
module,
|
|
31
|
-
configure: (widgetConfigurator) => {
|
|
32
|
-
builder?.(widgetConfigurator);
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { WidgetErrorType } from '../WidgetManifestLoadError.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Error thrown when a widget configuration cannot be loaded from the backend API.
|
|
5
|
-
*
|
|
6
|
-
* Use the static {@link fromHttpResponse} factory to create instances from
|
|
7
|
-
* HTTP responses with appropriate type mapping.
|
|
8
|
-
*/
|
|
9
|
-
export class WidgetConfigLoadError extends Error {
|
|
10
|
-
/**
|
|
11
|
-
* Creates a `WidgetConfigLoadError` from an HTTP `Response`.
|
|
12
|
-
*
|
|
13
|
-
* Maps HTTP 401 to `'unauthorized'`, 404 to `'not_found'`, and all other
|
|
14
|
-
* status codes to `'unknown'`.
|
|
15
|
-
*
|
|
16
|
-
* @param response - The failing HTTP response.
|
|
17
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
18
|
-
* @returns A typed `WidgetConfigLoadError`.
|
|
19
|
-
*/
|
|
20
|
-
static fromHttpResponse(response: Response, options?: ErrorOptions) {
|
|
21
|
-
// Map known status codes to a specific error type, otherwise fall through to 'unknown'
|
|
22
|
-
switch (response.status) {
|
|
23
|
-
case 401:
|
|
24
|
-
return new WidgetConfigLoadError(
|
|
25
|
-
'unauthorized',
|
|
26
|
-
'failed to load widget config, request not authorized',
|
|
27
|
-
options,
|
|
28
|
-
);
|
|
29
|
-
case 404:
|
|
30
|
-
return new WidgetConfigLoadError('not_found', 'widget config not found', options);
|
|
31
|
-
}
|
|
32
|
-
return new WidgetConfigLoadError(
|
|
33
|
-
'unknown',
|
|
34
|
-
`failed to load widget config, status code ${response.status}`,
|
|
35
|
-
options,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @param type - Error category discriminator.
|
|
40
|
-
* @param message - Human-readable error description.
|
|
41
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
42
|
-
*/
|
|
43
|
-
constructor(
|
|
44
|
-
public readonly type: WidgetErrorType,
|
|
45
|
-
message?: string,
|
|
46
|
-
options?: ErrorOptions,
|
|
47
|
-
) {
|
|
48
|
-
super(message, options);
|
|
49
|
-
this.name = 'GetWidgetLoadConfigError';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { WidgetErrorType } from '../WidgetManifestLoadError.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Error thrown when a widget script module cannot be dynamically imported.
|
|
5
|
-
*/
|
|
6
|
-
export class WidgetScriptModuleError extends Error {
|
|
7
|
-
/**
|
|
8
|
-
* @param type - Error category discriminator.
|
|
9
|
-
* @param message - Human-readable error description.
|
|
10
|
-
* @param options - Standard `ErrorOptions` (e.g., `cause`).
|
|
11
|
-
*/
|
|
12
|
-
constructor(
|
|
13
|
-
public readonly type: WidgetErrorType,
|
|
14
|
-
message?: string,
|
|
15
|
-
options?: ErrorOptions,
|
|
16
|
-
) {
|
|
17
|
-
super(message, options);
|
|
18
|
-
this.name = 'WidgetScriptModuleError';
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/events.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
|
-
|
|
3
|
-
import type { Widget } from './Widget';
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
WidgetConfig,
|
|
7
|
-
WidgetManifest,
|
|
8
|
-
WidgetModulesInstance,
|
|
9
|
-
WidgetScriptModule,
|
|
10
|
-
} from './types';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Base event-init shape for all widget lifecycle events.
|
|
14
|
-
*
|
|
15
|
-
* Extends `FrameworkEventInit` with a mandatory `name` field identifying
|
|
16
|
-
* the widget, and sets the event `source` to the originating {@link Widget}
|
|
17
|
-
* instance.
|
|
18
|
-
*
|
|
19
|
-
* @template TDetail - Additional detail properties merged with `{ name: string }`.
|
|
20
|
-
*/
|
|
21
|
-
export type WidgetEventInit<TDetail extends Record<string, unknown> | unknown = unknown> =
|
|
22
|
-
FrameworkEventInit<TDetail & { name: string }, Widget>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Concrete framework-event type for widget lifecycle events.
|
|
26
|
-
*
|
|
27
|
-
* @template TDetail - Additional detail properties.
|
|
28
|
-
*/
|
|
29
|
-
export type WidgetEvent<TDetail extends Record<string, unknown> | unknown = unknown> =
|
|
30
|
-
FrameworkEvent<WidgetEventInit<TDetail>>;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Framework-event type for widget lifecycle failure events.
|
|
34
|
-
*
|
|
35
|
-
* Carries an `error` property in the event detail for error inspection.
|
|
36
|
-
*/
|
|
37
|
-
export type WidgetEventFailure = FrameworkEvent<
|
|
38
|
-
WidgetEventInit<{
|
|
39
|
-
error: WidgetConfig;
|
|
40
|
-
}>
|
|
41
|
-
>;
|
|
42
|
-
|
|
43
|
-
declare module '@equinor/fusion-framework-module-event' {
|
|
44
|
-
interface FrameworkEventMap {
|
|
45
|
-
/** Fired when a widget has finished initializing its framework modules. */
|
|
46
|
-
onWidgetModulesLoaded: WidgetEvent<{
|
|
47
|
-
/** The initialized module instances. */
|
|
48
|
-
modules: WidgetModulesInstance;
|
|
49
|
-
}>;
|
|
50
|
-
|
|
51
|
-
/** Fired when a widget manifest fetch starts. */
|
|
52
|
-
onWidgetManifestLoad: WidgetEvent;
|
|
53
|
-
/** Fired when a widget manifest has been successfully loaded. */
|
|
54
|
-
onWidgetManifestLoaded: WidgetEvent<{
|
|
55
|
-
manifest: WidgetManifest;
|
|
56
|
-
}>;
|
|
57
|
-
/** Fired when a widget manifest fetch fails. */
|
|
58
|
-
onWidgetManifestFailure: WidgetEventFailure;
|
|
59
|
-
|
|
60
|
-
/** Fired when a widget config fetch starts. */
|
|
61
|
-
onWidgetConfigLoad: WidgetEvent;
|
|
62
|
-
/** Fired when a widget config has been successfully loaded. */
|
|
63
|
-
onWidgetConfigLoaded: WidgetEvent<{
|
|
64
|
-
config: WidgetConfig;
|
|
65
|
-
}>;
|
|
66
|
-
/** Fired when a widget config fetch fails. */
|
|
67
|
-
onWidgetConfigFailure: WidgetEventFailure;
|
|
68
|
-
|
|
69
|
-
/** Fired when a widget script import starts. */
|
|
70
|
-
onAWidgetScriptLoad: WidgetEvent;
|
|
71
|
-
/** Fired when a widget script has been successfully imported. */
|
|
72
|
-
onWidgetScriptLoaded: WidgetEvent<{
|
|
73
|
-
script: WidgetScriptModule;
|
|
74
|
-
}>;
|
|
75
|
-
/** Fired when a widget script import fails. */
|
|
76
|
-
onWidgetScriptFailure: WidgetEventFailure;
|
|
77
|
-
|
|
78
|
-
/** Fired before the widget begins loading manifest, config, and script. */
|
|
79
|
-
onWidgetInitialize: WidgetEvent;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Fired after the widget has loaded manifest, config, and script.
|
|
83
|
-
*
|
|
84
|
-
* Not emitted until all loaders have settled (last emission).
|
|
85
|
-
*/
|
|
86
|
-
onWidgetInitialized: WidgetEvent;
|
|
87
|
-
|
|
88
|
-
/** Fired when the widget fails to load manifest, config, or script. */
|
|
89
|
-
onWidgetInitializeFailure: WidgetEventFailure;
|
|
90
|
-
|
|
91
|
-
/** Fired when the widget is disposed (unmounted from the DOM). */
|
|
92
|
-
onWidgetDispose: FrameworkEvent<WidgetEventInit>;
|
|
93
|
-
}
|
|
94
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fusion Framework Widget Module
|
|
3
|
-
*
|
|
4
|
-
* Provides runtime loading, configuration, and lifecycle management for
|
|
5
|
-
* remote widget micro-frontends. Widgets are dynamically fetched, imported,
|
|
6
|
-
* and mounted into a host application.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export { WidgetModuleConfigurator, type WidgetModuleConfig } from './WidgetModuleConfigurator';
|
|
12
|
-
|
|
13
|
-
export { WidgetModuleProvider } from './WidgetModuleProvider';
|
|
14
|
-
|
|
15
|
-
export type { IWidgetModuleProvider } from './WidgetModuleProvider';
|
|
16
|
-
|
|
17
|
-
export * from './types';
|
|
18
|
-
|
|
19
|
-
export { enableWidgetModule } from './enable-widget-module';
|
|
20
|
-
|
|
21
|
-
export { default, type WidgetModule, module, moduleKey } from './module';
|
package/src/module.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Module } from '@equinor/fusion-framework-module';
|
|
2
|
-
import type { ModuleDeps } from './types';
|
|
3
|
-
|
|
4
|
-
import { WidgetModuleConfigurator } from './WidgetModuleConfigurator';
|
|
5
|
-
import { type IWidgetModuleProvider, WidgetModuleProvider } from './WidgetModuleProvider';
|
|
6
|
-
|
|
7
|
-
/** Module registration key used in the Fusion Framework module map. */
|
|
8
|
-
export const moduleKey = 'widget';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Module type definition binding the `'widget'` key to the
|
|
12
|
-
* {@link IWidgetModuleProvider} instance, {@link WidgetModuleConfigurator}
|
|
13
|
-
* configuration builder, and required {@link ModuleDeps}.
|
|
14
|
-
*/
|
|
15
|
-
export type WidgetModule = Module<
|
|
16
|
-
typeof moduleKey,
|
|
17
|
-
IWidgetModuleProvider,
|
|
18
|
-
WidgetModuleConfigurator,
|
|
19
|
-
ModuleDeps
|
|
20
|
-
>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Widget module descriptor.
|
|
24
|
-
*
|
|
25
|
-
* Defines how the widget module is configured, initialized, and disposed
|
|
26
|
-
* within the Fusion Framework module system.
|
|
27
|
-
*
|
|
28
|
-
* - `configure` — creates a fresh {@link WidgetModuleConfigurator}
|
|
29
|
-
* - `initialize` — resolves the config, optionally acquires the event module,
|
|
30
|
-
* and returns a {@link WidgetModuleProvider}
|
|
31
|
-
* - `dispose` — cleans up provider subscriptions
|
|
32
|
-
*/
|
|
33
|
-
export const module: WidgetModule = {
|
|
34
|
-
name: moduleKey,
|
|
35
|
-
configure() {
|
|
36
|
-
const config = new WidgetModuleConfigurator();
|
|
37
|
-
return config;
|
|
38
|
-
},
|
|
39
|
-
initialize: async (args) => {
|
|
40
|
-
const config = await args.config.createConfigAsync(args);
|
|
41
|
-
const event = await args.requireInstance('event').catch(() => undefined);
|
|
42
|
-
return new WidgetModuleProvider({ config, event });
|
|
43
|
-
},
|
|
44
|
-
dispose: (args) => {
|
|
45
|
-
// `args.instance` is typed as the generic module instance, but the module descriptor
|
|
46
|
-
// guarantees it was created as a `WidgetModuleProvider` — safe to cast for disposal.
|
|
47
|
-
(args.instance as unknown as WidgetModuleProvider).dispose();
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default module;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Augments the global Fusion Framework `Modules` interface so that
|
|
55
|
-
* `modules.widget` is typed as {@link WidgetModule}.
|
|
56
|
-
*/
|
|
57
|
-
declare module '@equinor/fusion-framework-module' {
|
|
58
|
-
interface Modules {
|
|
59
|
-
[moduleKey]: WidgetModule;
|
|
60
|
-
}
|
|
61
|
-
}
|
package/src/state/actions.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ActionInstanceMap,
|
|
3
|
-
type ActionTypes,
|
|
4
|
-
createAction,
|
|
5
|
-
createAsyncAction,
|
|
6
|
-
} from '@equinor/fusion-observable';
|
|
7
|
-
import type {
|
|
8
|
-
GetWidgetParameters,
|
|
9
|
-
WidgetConfig,
|
|
10
|
-
WidgetManifest,
|
|
11
|
-
WidgetModulesInstance,
|
|
12
|
-
WidgetScriptModule,
|
|
13
|
-
} from '../types';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Factory that creates all widget state-machine actions.
|
|
17
|
-
*
|
|
18
|
-
* Each action (or async action triplet) drives a specific step in the
|
|
19
|
-
* widget lifecycle: manifest loading, config loading, script import,
|
|
20
|
-
* and initialization.
|
|
21
|
-
*
|
|
22
|
-
* @returns Action creators for the widget state machine.
|
|
23
|
-
*/
|
|
24
|
-
const createActions = () => ({
|
|
25
|
-
/** Sets the manifest in state (optionally merging with existing). */
|
|
26
|
-
setManifest: createAction('set_manifest', (manifest: WidgetManifest, update?: boolean) => ({
|
|
27
|
-
payload: manifest,
|
|
28
|
-
meta: {
|
|
29
|
-
created: Date.now(),
|
|
30
|
-
update,
|
|
31
|
-
},
|
|
32
|
-
})),
|
|
33
|
-
/** Async action triplet for fetching the widget manifest from the API. */
|
|
34
|
-
fetchManifest: createAsyncAction(
|
|
35
|
-
'fetch_manifest',
|
|
36
|
-
(payload: { key: string; args?: GetWidgetParameters['args'] }, update?: boolean) => ({
|
|
37
|
-
payload,
|
|
38
|
-
meta: { update },
|
|
39
|
-
}),
|
|
40
|
-
(manifest: WidgetManifest) => ({ payload: manifest }),
|
|
41
|
-
(error: unknown) => ({ payload: error }),
|
|
42
|
-
),
|
|
43
|
-
/** Sets the widget config in state. */
|
|
44
|
-
setConfig: createAction('set_config', (config: WidgetConfig) => ({ payload: config })),
|
|
45
|
-
/** Async action triplet for fetching the widget config from the API. */
|
|
46
|
-
fetchConfig: createAsyncAction(
|
|
47
|
-
'fetch_config',
|
|
48
|
-
(payload: { key: string; args?: GetWidgetParameters['args'] }, update?: boolean) => ({
|
|
49
|
-
payload,
|
|
50
|
-
meta: { update },
|
|
51
|
-
}),
|
|
52
|
-
(config: WidgetConfig) => ({ payload: config }),
|
|
53
|
-
(error: unknown) => ({ payload: error }),
|
|
54
|
-
),
|
|
55
|
-
/** Sets the dynamically imported widget script module in state. */
|
|
56
|
-
// biome-ignore lint/suspicious/noExplicitAny: module payload widens to accept any script module shape when set
|
|
57
|
-
setModule: createAction('set_module', (module: any) => ({ payload: module })),
|
|
58
|
-
/** Async action triplet for dynamically importing the widget script. */
|
|
59
|
-
importWidget: createAsyncAction(
|
|
60
|
-
'import_widget',
|
|
61
|
-
(entrypoint: string) => ({ payload: entrypoint }),
|
|
62
|
-
(module: WidgetScriptModule) => ({ payload: module }),
|
|
63
|
-
(error: unknown) => ({ payload: error }),
|
|
64
|
-
),
|
|
65
|
-
/** Sets the resolved widget framework-module instances in state. */
|
|
66
|
-
setInstance: createAction('set_instance', (instance: WidgetModulesInstance) => ({
|
|
67
|
-
payload: instance,
|
|
68
|
-
})),
|
|
69
|
-
/** Async action triplet for the overall widget initialization lifecycle. */
|
|
70
|
-
initialize: createAsyncAction(
|
|
71
|
-
'initialize_widget',
|
|
72
|
-
() => ({ payload: null }),
|
|
73
|
-
() => ({ payload: null }),
|
|
74
|
-
(error: unknown) => ({ payload: error }),
|
|
75
|
-
),
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
/** Singleton action creators used by the widget state machine. */
|
|
79
|
-
export const actions = createActions();
|
|
80
|
-
|
|
81
|
-
/** Map of action-creator names to their instance types. */
|
|
82
|
-
export type ActionBuilder = ReturnType<typeof createActions>;
|
|
83
|
-
|
|
84
|
-
/** Map of action types produced by the action builders. */
|
|
85
|
-
export type ActionMap = ActionInstanceMap<ActionBuilder>;
|
|
86
|
-
|
|
87
|
-
/** Union of all action types dispatched in the widget state machine. */
|
|
88
|
-
export type Actions = ActionTypes<typeof actions>;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getBaseType,
|
|
3
|
-
createReducer as makeReducer,
|
|
4
|
-
isCompleteAction,
|
|
5
|
-
isRequestAction,
|
|
6
|
-
} from '@equinor/fusion-observable';
|
|
7
|
-
|
|
8
|
-
import { enableMapSet } from 'immer';
|
|
9
|
-
|
|
10
|
-
enableMapSet();
|
|
11
|
-
|
|
12
|
-
import { type Actions, actions } from './actions';
|
|
13
|
-
import type { WidgetStateInitial, WidgetState } from '../types';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an Immer-powered reducer for the widget state machine.
|
|
17
|
-
*
|
|
18
|
-
* Handles direct state setters (`setManifest`, `setConfig`, `setModule`,
|
|
19
|
-
* `setInstance`) and tracks in-flight async operations via the `status` set.
|
|
20
|
-
*
|
|
21
|
-
* @param value - Initial widget state (without `status`, which is added
|
|
22
|
-
* automatically as an empty `Set`).
|
|
23
|
-
* @returns A reducer function compatible with `FlowSubject`.
|
|
24
|
-
*/
|
|
25
|
-
export const createReducer = (value: WidgetStateInitial) =>
|
|
26
|
-
// Seed the reducer's initial state with an empty in-progress status set.
|
|
27
|
-
makeReducer<WidgetState, Actions>({ ...value, status: new Set() } as WidgetState, (builder) =>
|
|
28
|
-
builder
|
|
29
|
-
.addCase(actions.setManifest, (state, action) => {
|
|
30
|
-
// Merge with existing state when caller requested an update, otherwise replace
|
|
31
|
-
if (action.meta.update) {
|
|
32
|
-
// Shallow-merge the new payload over the existing manifest fields.
|
|
33
|
-
state.manifest = { ...state.manifest, ...action.payload };
|
|
34
|
-
} else {
|
|
35
|
-
state.manifest = action.payload;
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
.addCase(actions.setConfig, (state, action) => {
|
|
39
|
-
state.config = action.payload;
|
|
40
|
-
})
|
|
41
|
-
.addCase(actions.setModule, (state, action) => {
|
|
42
|
-
state.modules = action.payload;
|
|
43
|
-
})
|
|
44
|
-
.addCase(actions.setInstance, (state, action) => {
|
|
45
|
-
state.instance = action.payload;
|
|
46
|
-
})
|
|
47
|
-
/** mark status as loading {{type}} */
|
|
48
|
-
.addMatcher(isRequestAction, (state, action) => {
|
|
49
|
-
state.status.add(getBaseType(action.type));
|
|
50
|
-
})
|
|
51
|
-
/** clear status {{type}} */
|
|
52
|
-
.addMatcher(isCompleteAction, (state, action) => {
|
|
53
|
-
state.status.delete(getBaseType(action.type));
|
|
54
|
-
}),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
export default createReducer;
|