@open-pioneer/runtime 4.0.0-dev.20250512082657 → 4.0.0-dev.20250516115755
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 +43 -4
- package/CustomElement.d.ts +39 -7
- package/CustomElement.js +12 -329
- package/CustomElement.js.map +1 -1
- package/api.d.ts +28 -2
- package/app/AppInstance.d.ts +53 -0
- package/app/AppInstance.js +270 -0
- package/app/AppInstance.js.map +1 -0
- package/app/gatherConfig.d.ts +7 -0
- package/app/gatherConfig.js +49 -0
- package/app/gatherConfig.js.map +1 -0
- package/app/index.d.ts +1 -0
- package/app/logErrors.d.ts +1 -0
- package/app/logErrors.js +21 -0
- package/app/logErrors.js.map +1 -0
- package/builtin-services/ApplicationContextImpl.d.ts +5 -3
- package/builtin-services/ApplicationContextImpl.js +9 -4
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/dom/index.d.ts +19 -0
- package/dom/index.js +24 -0
- package/dom/index.js.map +1 -0
- package/index.d.ts +1 -1
- package/package.json +4 -4
- package/react-integration/ChakraProvider.d.ts +8 -1
- package/react-integration/ChakraProvider.js +39 -27
- package/react-integration/ChakraProvider.js.map +1 -1
- package/{ErrorScreen.d.ts → react-integration/ErrorScreen.d.ts} +1 -1
- package/react-integration/ErrorScreen.js.map +1 -0
- package/react-integration/ReactIntegration.d.ts +5 -1
- package/react-integration/ReactIntegration.js +7 -1
- package/react-integration/ReactIntegration.js.map +1 -1
- package/ErrorScreen.js.map +0 -1
- /package/{ErrorScreen.js → react-integration/ErrorScreen.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
# @open-pioneer/runtime
|
|
2
2
|
|
|
3
|
-
## 4.0.0-dev.
|
|
3
|
+
## 4.0.0-dev.20250516115755
|
|
4
4
|
|
|
5
5
|
### Major Changes
|
|
6
6
|
|
|
7
7
|
- 9f074d8: Update to Chakra 3.x
|
|
8
|
+
- 53c92ba: Introduce an advanced option to disable the shadow root.
|
|
9
|
+
|
|
10
|
+
By default, trails applications use a shadow root to avoid conflicts (e.g. styles) with other parts of the site where the application may be embedded.
|
|
11
|
+
|
|
12
|
+
Applications that use the entire browser viewport may not need this feature, since there may be no "other" parts that may conflict with the app. In this case, you can disable the shadow root by setting this property to `false`.
|
|
13
|
+
|
|
14
|
+
- New option `advanced.enableShadowRoot`:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createCustomElement } from "@open-pioneer/runtime";
|
|
18
|
+
import * as appMetadata from "open-pioneer:app";
|
|
19
|
+
import { AppUI } from "./AppUI";
|
|
20
|
+
|
|
21
|
+
const element = createCustomElement({
|
|
22
|
+
component: AppUI,
|
|
23
|
+
appMetadata,
|
|
24
|
+
advanced: {
|
|
25
|
+
enableShadowRoot: false
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
customElements.define("no-shadowroot-sample", element);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- **Breaking:** As a consequence, the `ApplicationContext`'s `getShadowRoot()` method will now return `undefined` if the shadow root is disabled (previous: always a `ShadowRoot`):
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const ctx: ApplicationContext = ...; // injected
|
|
36
|
+
const shadowRoot = ctx.getShadowRoot(); // ShadowRoot | undefined
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- New method on the `ApplicationContext` that returns _either_ the `ShadowRoot` _or_ the `Document` (if the shadow root is disabled):
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const ctx: ApplicationContext = ...; // injected
|
|
43
|
+
const root = ctx.getRoot(); // Document | ShadowRoot
|
|
44
|
+
root.getElementById("...") // always works
|
|
45
|
+
```
|
|
46
|
+
|
|
8
47
|
- 9f074d8: **Breaking:** Rename `theme` option of `createCustomElement()` to `chakraSystemConfig`.
|
|
9
48
|
|
|
10
49
|
### Patch Changes
|
|
@@ -12,9 +51,9 @@
|
|
|
12
51
|
- Updated dependencies [9f074d8]
|
|
13
52
|
- Updated dependencies [9f074d8]
|
|
14
53
|
- Updated dependencies [1f4fa84]
|
|
15
|
-
- @open-pioneer/base-theme@4.0.0-dev.
|
|
16
|
-
- @open-pioneer/reactivity@4.0.0-dev.
|
|
17
|
-
- @open-pioneer/core@4.0.0-dev.
|
|
54
|
+
- @open-pioneer/base-theme@4.0.0-dev.20250516115755
|
|
55
|
+
- @open-pioneer/reactivity@4.0.0-dev.20250516115755
|
|
56
|
+
- @open-pioneer/core@4.0.0-dev.20250516115755
|
|
18
57
|
|
|
19
58
|
## 3.1.0
|
|
20
59
|
|
package/CustomElement.d.ts
CHANGED
|
@@ -23,6 +23,16 @@ export interface CustomElementOptions {
|
|
|
23
23
|
* All instances of the web component will share this static configuration.
|
|
24
24
|
*/
|
|
25
25
|
config?: ApplicationConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Chakra styled system object.
|
|
28
|
+
*
|
|
29
|
+
* Used to configure chakra's theme.
|
|
30
|
+
*/
|
|
31
|
+
chakraSystemConfig?: ChakraSystemConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Advanced configuration that alters the behavior of the custom element.
|
|
34
|
+
*/
|
|
35
|
+
advanced?: AdvancedCustomElementOptions;
|
|
26
36
|
/**
|
|
27
37
|
* Function to provide additional application defined configuration parameters.
|
|
28
38
|
*
|
|
@@ -32,12 +42,6 @@ export interface CustomElementOptions {
|
|
|
32
42
|
* Parameters returned by this function take precedence over the ones defined by {@link config}.
|
|
33
43
|
*/
|
|
34
44
|
resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;
|
|
35
|
-
/**
|
|
36
|
-
* Chakra styled system object.
|
|
37
|
-
*
|
|
38
|
-
* Used to configure chakra's theme.
|
|
39
|
-
*/
|
|
40
|
-
chakraSystemConfig?: ChakraSystemConfig;
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
43
47
|
* A context object that is passed to the `resolveProperties` function.
|
|
@@ -87,9 +91,37 @@ export interface ApplicationProperties {
|
|
|
87
91
|
* The interface implemented by web components produced via {@link createCustomElement}.
|
|
88
92
|
*/
|
|
89
93
|
export interface ApplicationElement extends HTMLElement {
|
|
90
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Resolves to the element's API when the application has started.
|
|
96
|
+
*
|
|
97
|
+
* The API exposed by an application can be defined by implementing an {@link ApiExtension}.
|
|
98
|
+
* For more details, open the documentation of the `@open-pioneer/integration` package.
|
|
99
|
+
*/
|
|
91
100
|
when(): Promise<ApiMethods>;
|
|
92
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Advanced configuration that alters the behavior of the custom element.
|
|
104
|
+
*
|
|
105
|
+
* See {@link createCustomElement}.
|
|
106
|
+
*/
|
|
107
|
+
export interface AdvancedCustomElementOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Enables or disables the [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot) inside the application's web component.
|
|
110
|
+
*
|
|
111
|
+
* Default: `true`.
|
|
112
|
+
*
|
|
113
|
+
* By default, trails applications use a shadow root to avoid conflicts (e.g. styles) with other parts of the site where the application may be embedded.
|
|
114
|
+
*
|
|
115
|
+
* Applications that use the entire browser viewport may not need this feature, since there may be no "other" parts that may conflict with the app.
|
|
116
|
+
* In this case, you can disable the shadow root by setting this property to `false`.
|
|
117
|
+
* In general, UI components used by the app (e.g. from Chakra UI) should work just as well when disabling the shadow root.
|
|
118
|
+
* If you notice any problems, please file an issue.
|
|
119
|
+
*
|
|
120
|
+
* If you are developing UI components that are meant to be used in other applications, you should always use a shadow root to
|
|
121
|
+
* ensure that your components work in that setting.
|
|
122
|
+
*/
|
|
123
|
+
enableShadowRoot?: boolean;
|
|
124
|
+
}
|
|
93
125
|
/**
|
|
94
126
|
* The class returned by a call to {@link createCustomElement}.
|
|
95
127
|
*/
|
package/CustomElement.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createElement } from 'react';
|
|
4
|
-
import { createBuiltinPackage, RUNTIME_API_SERVICE, RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE, RUNTIME_AUTO_START } from './builtin-services/index.js';
|
|
1
|
+
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
+
import { AppInstance } from './app/AppInstance.js';
|
|
5
3
|
import { ErrorId } from './errors.js';
|
|
6
|
-
import { MESSAGES_BY_LOCALE, ErrorScreen } from './ErrorScreen.js';
|
|
7
|
-
import { initI18n } from './i18n/AppIntl.js';
|
|
8
|
-
import { createPackageIntl } from './i18n/PackageIntl.js';
|
|
9
|
-
import { getBrowserLocales, I18nConfig } from './i18n/pick.js';
|
|
10
|
-
import { ReactIntegration } from './react-integration/ReactIntegration.js';
|
|
11
|
-
import { createPackages } from './service-layer/PackageRepr.js';
|
|
12
|
-
import { ServiceLayer } from './service-layer/ServiceLayer.js';
|
|
13
4
|
|
|
14
5
|
const LOG = createLogger("runtime:CustomElement");
|
|
15
6
|
function createCustomElement(options) {
|
|
@@ -24,9 +15,14 @@ function createCustomElement(options) {
|
|
|
24
15
|
}
|
|
25
16
|
constructor() {
|
|
26
17
|
super();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
const enableShadowRoot = options.advanced?.enableShadowRoot ?? true;
|
|
19
|
+
if (enableShadowRoot) {
|
|
20
|
+
this.#shadowRoot = this.attachShadow({
|
|
21
|
+
mode: "open"
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
LOG.debug("Creating component instance without shadow root");
|
|
25
|
+
}
|
|
30
26
|
if (import.meta.env.DEV) {
|
|
31
27
|
this.$inspectElementState = () => this.#instance;
|
|
32
28
|
}
|
|
@@ -74,9 +70,9 @@ function createCustomElement(options) {
|
|
|
74
70
|
}, 1);
|
|
75
71
|
}
|
|
76
72
|
#createApplicationInstance(overrides) {
|
|
77
|
-
return new
|
|
73
|
+
return new AppInstance({
|
|
74
|
+
rootNode: this.#shadowRoot ?? document,
|
|
78
75
|
hostElement: this,
|
|
79
|
-
shadowRoot: this.#shadowRoot,
|
|
80
76
|
elementOptions: options,
|
|
81
77
|
overrides,
|
|
82
78
|
restart: this.#triggerReload.bind(this)
|
|
@@ -85,319 +81,6 @@ function createCustomElement(options) {
|
|
|
85
81
|
}
|
|
86
82
|
return PioneerApplication;
|
|
87
83
|
}
|
|
88
|
-
class ApplicationInstance {
|
|
89
|
-
options;
|
|
90
|
-
// Public API
|
|
91
|
-
apiPromise;
|
|
92
|
-
// Present when callers are waiting for the API
|
|
93
|
-
api;
|
|
94
|
-
// Present once started
|
|
95
|
-
state = "not-started";
|
|
96
|
-
appRoot;
|
|
97
|
-
config;
|
|
98
|
-
serviceLayer;
|
|
99
|
-
lifecycleEvents;
|
|
100
|
-
reactIntegration;
|
|
101
|
-
stylesWatch;
|
|
102
|
-
constructor(options) {
|
|
103
|
-
this.options = options;
|
|
104
|
-
}
|
|
105
|
-
start() {
|
|
106
|
-
if (this.state !== "not-started") {
|
|
107
|
-
throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.state}'`);
|
|
108
|
-
}
|
|
109
|
-
this.state = "starting";
|
|
110
|
-
this.startImpl().catch((e) => {
|
|
111
|
-
if (this.state === "destroyed") return;
|
|
112
|
-
logError(e);
|
|
113
|
-
this.reset();
|
|
114
|
-
this.state = "error";
|
|
115
|
-
this.showErrorScreen(e);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
destroy() {
|
|
119
|
-
if (this.state === "destroyed") {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (this.state === "started") {
|
|
123
|
-
try {
|
|
124
|
-
this.triggerApplicationLifecycleEvent("before-stop");
|
|
125
|
-
} catch (e) {
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
this.state = "destroyed";
|
|
129
|
-
this.reset();
|
|
130
|
-
}
|
|
131
|
-
reset() {
|
|
132
|
-
this.apiPromise?.reject(createAbortError());
|
|
133
|
-
this.reactIntegration = destroyResource(this.reactIntegration);
|
|
134
|
-
this.options.shadowRoot.replaceChildren();
|
|
135
|
-
this.appRoot = void 0;
|
|
136
|
-
this.lifecycleEvents = void 0;
|
|
137
|
-
this.serviceLayer = destroyResource(this.serviceLayer);
|
|
138
|
-
this.stylesWatch = destroyResource(this.stylesWatch);
|
|
139
|
-
}
|
|
140
|
-
whenAPI() {
|
|
141
|
-
if (this.api) {
|
|
142
|
-
return Promise.resolve(this.api);
|
|
143
|
-
}
|
|
144
|
-
const apiPromise = this.apiPromise ??= createManualPromise();
|
|
145
|
-
return apiPromise.promise;
|
|
146
|
-
}
|
|
147
|
-
async startImpl() {
|
|
148
|
-
const { shadowRoot, hostElement, elementOptions, overrides } = this.options;
|
|
149
|
-
const config = this.config = await gatherConfig(hostElement, elementOptions, overrides);
|
|
150
|
-
this.checkAbort();
|
|
151
|
-
LOG.debug("Application config is", config);
|
|
152
|
-
const i18n = await initI18n(elementOptions.appMetadata, config.locale);
|
|
153
|
-
this.checkAbort();
|
|
154
|
-
const appRoot = this.appRoot = createAppRoot(i18n.locale);
|
|
155
|
-
shadowRoot.replaceChildren(appRoot);
|
|
156
|
-
const styles = this.initStylesSignal();
|
|
157
|
-
const { serviceLayer, packages } = this.initServiceLayer({
|
|
158
|
-
container: appRoot,
|
|
159
|
-
properties: config.properties,
|
|
160
|
-
i18n
|
|
161
|
-
});
|
|
162
|
-
this.lifecycleEvents = getInternalService(
|
|
163
|
-
serviceLayer,
|
|
164
|
-
RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE
|
|
165
|
-
);
|
|
166
|
-
await this.initAPI(serviceLayer);
|
|
167
|
-
this.checkAbort();
|
|
168
|
-
this.reactIntegration = ReactIntegration.createForApp({
|
|
169
|
-
appRoot,
|
|
170
|
-
rootNode: shadowRoot,
|
|
171
|
-
serviceLayer,
|
|
172
|
-
packages,
|
|
173
|
-
locale: i18n.locale,
|
|
174
|
-
config: elementOptions.chakraSystemConfig,
|
|
175
|
-
styles
|
|
176
|
-
});
|
|
177
|
-
const component = this.options.elementOptions.component ?? emptyComponent;
|
|
178
|
-
this.reactIntegration.render(createElement(component));
|
|
179
|
-
this.state = "started";
|
|
180
|
-
this.triggerApplicationLifecycleEvent("after-start");
|
|
181
|
-
LOG.debug("Application started");
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Returns a signal that contains the application's styles.
|
|
185
|
-
* During development, the signal is updated when the user edits .css files.
|
|
186
|
-
* In production, the signal is static.
|
|
187
|
-
*/
|
|
188
|
-
initStylesSignal() {
|
|
189
|
-
const stylesBox = this.options.elementOptions.appMetadata?.styles;
|
|
190
|
-
if (!stylesBox) {
|
|
191
|
-
return reactive("");
|
|
192
|
-
}
|
|
193
|
-
const signal = reactive(stylesBox.value);
|
|
194
|
-
if (import.meta.hot) {
|
|
195
|
-
this.stylesWatch = stylesBox.on?.("changed", () => {
|
|
196
|
-
signal.value = stylesBox.value;
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
return signal;
|
|
200
|
-
}
|
|
201
|
-
initServiceLayer(config) {
|
|
202
|
-
const { hostElement, shadowRoot, elementOptions, restart } = this.options;
|
|
203
|
-
const { container, properties, i18n } = config;
|
|
204
|
-
const packageMetadata = elementOptions.appMetadata?.packages ?? {};
|
|
205
|
-
const builtinPackage = createBuiltinPackage({
|
|
206
|
-
host: hostElement,
|
|
207
|
-
shadowRoot,
|
|
208
|
-
container,
|
|
209
|
-
locale: i18n.locale,
|
|
210
|
-
supportedLocales: i18n.supportedMessageLocales,
|
|
211
|
-
changeLocale(locale) {
|
|
212
|
-
const supported = i18n.supportedMessageLocales;
|
|
213
|
-
if (locale != null && !i18n.supportsLocale(locale)) {
|
|
214
|
-
throw new Error(
|
|
215
|
-
ErrorId.UNSUPPORTED_LOCALE,
|
|
216
|
-
`Unsupported locale '${locale}' (supported locales: ${supported.join(
|
|
217
|
-
", "
|
|
218
|
-
)}).`
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
restart({ locale });
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
const { serviceLayer, packages } = createServiceLayer({
|
|
225
|
-
packageMetadata,
|
|
226
|
-
builtinPackage,
|
|
227
|
-
properties,
|
|
228
|
-
i18n
|
|
229
|
-
});
|
|
230
|
-
this.serviceLayer = serviceLayer;
|
|
231
|
-
if (LOG.isDebug()) {
|
|
232
|
-
LOG.debug("Launching service layer with packages", Object.fromEntries(packages));
|
|
233
|
-
}
|
|
234
|
-
serviceLayer.start();
|
|
235
|
-
return { serviceLayer, packages };
|
|
236
|
-
}
|
|
237
|
-
async initAPI(serviceLayer) {
|
|
238
|
-
const apiService = getInternalService(serviceLayer, RUNTIME_API_SERVICE);
|
|
239
|
-
try {
|
|
240
|
-
const api = this.api = await apiService.getApi();
|
|
241
|
-
LOG.debug("Application API initialized to", api);
|
|
242
|
-
this.apiPromise?.resolve(api);
|
|
243
|
-
} catch (e) {
|
|
244
|
-
throw new Error(ErrorId.INTERNAL, "Failed to gather the application's API methods.", {
|
|
245
|
-
cause: e
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
triggerApplicationLifecycleEvent(event) {
|
|
250
|
-
this.lifecycleEvents?.emitLifecycleEvent(event);
|
|
251
|
-
}
|
|
252
|
-
checkAbort() {
|
|
253
|
-
if (this.state === "destroyed") {
|
|
254
|
-
throwAbortError();
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
showErrorScreen(error) {
|
|
258
|
-
const { shadowRoot, elementOptions } = this.options;
|
|
259
|
-
const userLocales = getBrowserLocales();
|
|
260
|
-
const i18nConfig = new I18nConfig(Object.keys(MESSAGES_BY_LOCALE));
|
|
261
|
-
const { locale, messageLocale } = i18nConfig.pickSupportedLocale(void 0, userLocales);
|
|
262
|
-
const messages = MESSAGES_BY_LOCALE[messageLocale] ?? MESSAGES_BY_LOCALE["en"];
|
|
263
|
-
const intl = createPackageIntl(locale, messages);
|
|
264
|
-
const appRoot = this.appRoot = createAppRoot(locale);
|
|
265
|
-
appRoot.classList.add("pioneer-root-error-screen");
|
|
266
|
-
shadowRoot.replaceChildren(appRoot);
|
|
267
|
-
const styles = this.initStylesSignal();
|
|
268
|
-
this.reactIntegration = ReactIntegration.createForErrorScreen({
|
|
269
|
-
appRoot,
|
|
270
|
-
rootNode: shadowRoot,
|
|
271
|
-
locale,
|
|
272
|
-
config: elementOptions.chakraSystemConfig,
|
|
273
|
-
styles
|
|
274
|
-
});
|
|
275
|
-
this.reactIntegration.render(createElement(ErrorScreen, { intl, error }));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
function createAppRoot(locale) {
|
|
279
|
-
const container = document.createElement("div");
|
|
280
|
-
container.classList.add("pioneer-root");
|
|
281
|
-
container.style.minHeight = "100%";
|
|
282
|
-
container.style.height = "100%";
|
|
283
|
-
if (locale) {
|
|
284
|
-
container.lang = locale;
|
|
285
|
-
}
|
|
286
|
-
return container;
|
|
287
|
-
}
|
|
288
|
-
function createServiceLayer(config) {
|
|
289
|
-
const { packageMetadata, properties, builtinPackage, i18n } = config;
|
|
290
|
-
let packages;
|
|
291
|
-
try {
|
|
292
|
-
packages = createPackages(packageMetadata ?? {}, i18n, properties);
|
|
293
|
-
} catch (e) {
|
|
294
|
-
throw new Error(ErrorId.INVALID_METADATA, "Failed to parse package metadata.", {
|
|
295
|
-
cause: e
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
{
|
|
299
|
-
const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);
|
|
300
|
-
if (index >= 0) {
|
|
301
|
-
packages.splice(index, 1);
|
|
302
|
-
}
|
|
303
|
-
packages.push(builtinPackage);
|
|
304
|
-
}
|
|
305
|
-
const forcedReferences = [
|
|
306
|
-
{
|
|
307
|
-
interfaceName: RUNTIME_API_SERVICE
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
interfaceName: RUNTIME_AUTO_START,
|
|
314
|
-
all: true
|
|
315
|
-
}
|
|
316
|
-
];
|
|
317
|
-
const serviceLayer = new ServiceLayer(packages, forcedReferences);
|
|
318
|
-
return {
|
|
319
|
-
packages: new Map(packages.map((pkg) => [pkg.name, pkg])),
|
|
320
|
-
serviceLayer
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
function getInternalService(serviceLayer, interfaceName) {
|
|
324
|
-
const result = serviceLayer.getService(
|
|
325
|
-
"@open-pioneer/runtime",
|
|
326
|
-
{
|
|
327
|
-
interfaceName
|
|
328
|
-
},
|
|
329
|
-
{ ignoreDeclarationCheck: true }
|
|
330
|
-
);
|
|
331
|
-
if (result.type !== "found") {
|
|
332
|
-
throw new Error(
|
|
333
|
-
ErrorId.INTERNAL,
|
|
334
|
-
`Failed to find instance of '${interfaceName}' (result type '${result.type}'). This is a builtin service that must be present exactly once.`
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
return result.value.getInstanceOrThrow();
|
|
338
|
-
}
|
|
339
|
-
async function gatherConfig(hostElement, options, overrides) {
|
|
340
|
-
let configs;
|
|
341
|
-
try {
|
|
342
|
-
const staticConfig = options.config ?? {};
|
|
343
|
-
const dynamicConfig = await options.resolveConfig?.({
|
|
344
|
-
hostElement,
|
|
345
|
-
getAttribute(name) {
|
|
346
|
-
return hostElement.getAttribute(name) ?? void 0;
|
|
347
|
-
}
|
|
348
|
-
}) ?? {};
|
|
349
|
-
configs = [staticConfig, dynamicConfig];
|
|
350
|
-
} catch (e) {
|
|
351
|
-
throw new Error(
|
|
352
|
-
ErrorId.CONFIG_RESOLUTION_FAILED,
|
|
353
|
-
"Failed to resolve application properties.",
|
|
354
|
-
{
|
|
355
|
-
cause: e
|
|
356
|
-
}
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
const merged = mergeConfigs(configs);
|
|
360
|
-
if (overrides?.locale) {
|
|
361
|
-
merged.locale = overrides.locale;
|
|
362
|
-
}
|
|
363
|
-
return merged;
|
|
364
|
-
}
|
|
365
|
-
function mergeConfigs(configs) {
|
|
366
|
-
const mergedConfig = Object.assign(
|
|
367
|
-
{
|
|
368
|
-
locale: void 0,
|
|
369
|
-
properties: {}
|
|
370
|
-
},
|
|
371
|
-
...configs
|
|
372
|
-
);
|
|
373
|
-
const mergedProperties = mergedConfig.properties = {};
|
|
374
|
-
for (const config of configs) {
|
|
375
|
-
for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {
|
|
376
|
-
const mergedPackageProps = mergedProperties[packageName] ??= {};
|
|
377
|
-
Object.assign(mergedPackageProps, packageProperties);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return mergedConfig;
|
|
381
|
-
}
|
|
382
|
-
function logError(e) {
|
|
383
|
-
if (e instanceof Error) {
|
|
384
|
-
const chain = getErrorChain(e).reverse();
|
|
385
|
-
if (chain.length === 1) {
|
|
386
|
-
console.error(e);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
let n = 1;
|
|
390
|
-
for (const error of chain) {
|
|
391
|
-
console.error(`#${n}`, error);
|
|
392
|
-
++n;
|
|
393
|
-
}
|
|
394
|
-
} else {
|
|
395
|
-
console.error("Unexpected error", e);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
function emptyComponent() {
|
|
399
|
-
return null;
|
|
400
|
-
}
|
|
401
84
|
|
|
402
85
|
export { createCustomElement };
|
|
403
86
|
//# sourceMappingURL=CustomElement.js.map
|
package/CustomElement.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n getErrorChain,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { ComponentType, createElement } from \"react\";\nimport { ApiMethods, ApiService } from \"./api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START\n} from \"./builtin-services\";\nimport { ApplicationLifecycleEventService } from \"./builtin-services/ApplicationLifecycleEventService\";\nimport { ErrorId } from \"./errors\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"./ErrorScreen\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, I18nConfig, initI18n } from \"./i18n\";\nimport { ApplicationMetadata, PackageMetadata } from \"./metadata\";\nimport { ReactIntegration } from \"./react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"./service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"./service-layer/PackageRepr\";\nimport { ServiceLayer } from \"./service-layer/ServiceLayer\";\nconst LOG = createLogger(\"runtime:CustomElement\");\n\n/**\n * Options for the {@link createCustomElement} function.\n */\nexport interface CustomElementOptions {\n /**\n * Rendered UI component.\n */\n component?: ComponentType<Record<string, string>>;\n\n /**\n * Application metadata (packages, services etc.).\n * This is usually autogenerated by importing the virtual `\"open-pioneer:app\"` module.\n */\n appMetadata?: ApplicationMetadata;\n\n /**\n * Application defined configuration.\n *\n * This option can be used to override default properties of the application's packages.\n *\n * All instances of the web component will share this static configuration.\n */\n config?: ApplicationConfig;\n\n /**\n * Function to provide additional application defined configuration parameters.\n *\n * Compared to {@link config}, this function receives a context object\n * that allows the developer to provide dynamic properties on a per-application instance basis.\n *\n * Parameters returned by this function take precedence over the ones defined by {@link config}.\n */\n resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * The application's host element.\n */\n hostElement: HTMLElement;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Runtime application configuration.\n */\nexport interface ApplicationConfig {\n /**\n * Set this value to a locale string (e.g. \"en\") to for the application's locale.\n * The default behavior is to choose an appropriate locale for the current user based\n * on the browser's settings.\n *\n * The locale must be supported by the application.\n */\n locale?: string | undefined;\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n}\n\n/**\n * Allows the application to override default properties in all packages.\n *\n * Properties are typed when the package contains type definitions for them.\n */\nexport interface ApplicationProperties {\n /**\n * Key: the name of the package.\n * Value: A record of configuration properties (key/value pairs).\n *\n * Properties will override default property values in the package.\n */\n [packageName: string]: Record<string, unknown>;\n}\n\n/**\n * The interface implemented by web components produced via {@link createCustomElement}.\n */\nexport interface ApplicationElement extends HTMLElement {\n /** Resolves to the element's API when the application has started. */\n when(): Promise<ApiMethods>;\n}\n\n/**\n * The class returned by a call to {@link createCustomElement}.\n */\nexport interface ApplicationElementConstructor {\n new (): ApplicationElement;\n}\n\n/**\n * Creates a new custom element class (web component) that can be registered within a DOM.\n *\n * @example\n * ```ts\n * import * as appMetadata from \"open-pioneer:app\";\n *\n * const CustomElementClazz = createCustomElement({\n * component: <div>Hello World!</div>,\n * appMetadata\n * });\n * customElements.define(\"sample-element\", CustomElementClazz);\n * ```\n */\nexport function createCustomElement(options: CustomElementOptions): ApplicationElementConstructor {\n class PioneerApplication extends HTMLElement implements ApplicationElement {\n #shadowRoot: ShadowRoot;\n #instance: ApplicationInstance | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #deferredRestart: any; // A Timer\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n this.#shadowRoot = this.attachShadow({\n mode: \"open\"\n });\n\n if (import.meta.env.DEV) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#instance;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#instance) {\n this.#instance.destroy();\n }\n\n this.#instance = this.#createApplicationInstance();\n this.#instance.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#instance?.destroy();\n this.#instance = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#instance) {\n return Promise.reject(\n new Error(\n ErrorId.NOT_MOUNTED,\n \"Cannot use the application's API because the HTML element has not yet been mounted into the DOM.\"\n )\n );\n }\n\n return this.#instance.whenAPI();\n }\n\n #triggerReload(overrides?: ApplicationOverrides) {\n // Defer the restart operation a tiny bit so calling code does not get surprised by the application's destruction.\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#deferredRestart = setTimeout(() => {\n if (!this.#instance) {\n // disconnectedCallback was called in the meantime\n return;\n }\n\n LOG.debug(\"Restarting application with new options\", overrides);\n this.#instance.destroy();\n this.#instance = this.#createApplicationInstance(overrides);\n this.#instance.start();\n }, 1);\n }\n\n #createApplicationInstance(overrides?: ApplicationOverrides) {\n return new ApplicationInstance({\n hostElement: this,\n shadowRoot: this.#shadowRoot,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n });\n }\n }\n return PioneerApplication;\n}\n\ninterface InstanceOptions {\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** The shadow root inside the host element that contains the rest of the application. */\n shadowRoot: ShadowRoot;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\ninterface ApplicationOverrides {\n locale?: string;\n}\n\ntype ApplicationState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nclass ApplicationInstance {\n private options: InstanceOptions;\n\n // Public API\n private apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n private api: ApiMethods | undefined; // Present once started\n\n private state: ApplicationState = \"not-started\";\n private appRoot: HTMLDivElement | undefined;\n private config: ApplicationConfig | undefined;\n private serviceLayer: ServiceLayer | undefined;\n private lifecycleEvents: ApplicationLifecycleEventService | undefined;\n private reactIntegration: ReactIntegration | undefined;\n\n private stylesWatch: Resource | undefined;\n\n constructor(options: InstanceOptions) {\n this.options = options;\n }\n\n start() {\n if (this.state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.state}'`);\n }\n\n this.state = \"starting\";\n this.startImpl().catch((e) => {\n if (this.state === \"destroyed\") return;\n\n logError(e);\n this.reset();\n this.state = \"error\";\n this.showErrorScreen(e);\n });\n }\n\n destroy() {\n if (this.state === \"destroyed\") {\n return;\n }\n\n // Only call event listener when 'started' was also signalled.\n if (this.state === \"started\") {\n try {\n this.triggerApplicationLifecycleEvent(\"before-stop\");\n } catch (e) {\n void e; // Ignored\n }\n }\n this.state = \"destroyed\";\n this.reset();\n }\n\n private reset() {\n this.apiPromise?.reject(createAbortError());\n this.reactIntegration = destroyResource(this.reactIntegration);\n this.options.shadowRoot.replaceChildren();\n this.appRoot = undefined;\n this.lifecycleEvents = undefined;\n this.serviceLayer = destroyResource(this.serviceLayer);\n this.stylesWatch = destroyResource(this.stylesWatch);\n }\n\n whenAPI(): Promise<ApiMethods> {\n if (this.api) {\n return Promise.resolve(this.api);\n }\n\n const apiPromise = (this.apiPromise ??= createManualPromise());\n return apiPromise.promise;\n }\n\n private async startImpl() {\n const { shadowRoot, hostElement, elementOptions, overrides } = this.options;\n\n // Resolve custom application config\n const config = (this.config = await gatherConfig(hostElement, elementOptions, overrides));\n this.checkAbort();\n LOG.debug(\"Application config is\", config);\n\n // Decide on locale and load i18n messages (if any).\n const i18n = await initI18n(elementOptions.appMetadata, config.locale);\n this.checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.appRoot = createAppRoot(i18n.locale));\n shadowRoot.replaceChildren(appRoot);\n\n const styles = this.initStylesSignal();\n\n // Launch the service layer\n const { serviceLayer, packages } = this.initServiceLayer({\n container: appRoot,\n properties: config.properties,\n i18n\n });\n this.lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n\n await this.initAPI(serviceLayer);\n this.checkAbort();\n\n // Launch react\n this.reactIntegration = ReactIntegration.createForApp({\n appRoot: appRoot,\n rootNode: shadowRoot,\n serviceLayer,\n packages,\n locale: i18n.locale,\n config: elementOptions.chakraSystemConfig,\n styles: styles\n });\n const component = this.options.elementOptions.component ?? emptyComponent;\n this.reactIntegration.render(createElement(component));\n this.state = \"started\";\n\n this.triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n /**\n * Returns a signal that contains the application's styles.\n * During development, the signal is updated when the user edits .css files.\n * In production, the signal is static.\n */\n private initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return reactive(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.stylesWatch = stylesBox.on?.(\"changed\", () => {\n signal.value = stylesBox.value;\n });\n }\n return signal;\n }\n\n private initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n }) {\n const { hostElement, shadowRoot, elementOptions, restart } = this.options;\n const { container, properties, i18n } = config;\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n shadowRoot: shadowRoot,\n container: container,\n locale: i18n.locale,\n supportedLocales: i18n.supportedMessageLocales,\n changeLocale(locale) {\n const supported = i18n.supportedMessageLocales;\n if (locale != null && !i18n.supportsLocale(locale)) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${locale}' (supported locales: ${supported.join(\n \", \"\n )}).`\n );\n }\n restart({ locale });\n }\n });\n const { serviceLayer, packages } = createServiceLayer({\n packageMetadata,\n builtinPackage,\n properties,\n i18n\n });\n this.serviceLayer = serviceLayer;\n\n if (LOG.isDebug()) {\n LOG.debug(\"Launching service layer with packages\", Object.fromEntries(packages));\n }\n serviceLayer.start();\n return { serviceLayer, packages };\n }\n\n private async initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = (this.api = await apiService.getApi());\n LOG.debug(\"Application API initialized to\", api);\n this.apiPromise?.resolve(api);\n } catch (e) {\n throw new Error(ErrorId.INTERNAL, \"Failed to gather the application's API methods.\", {\n cause: e\n });\n }\n }\n\n private triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n private checkAbort() {\n if (this.state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n private showErrorScreen(error: globalThis.Error) {\n const { shadowRoot, elementOptions } = this.options;\n\n const userLocales = getBrowserLocales();\n const i18nConfig = new I18nConfig(Object.keys(MESSAGES_BY_LOCALE));\n const { locale, messageLocale } = i18nConfig.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale, messages);\n\n const appRoot = (this.appRoot = createAppRoot(locale));\n appRoot.classList.add(\"pioneer-root-error-screen\");\n shadowRoot.replaceChildren(appRoot);\n\n const styles = this.initStylesSignal();\n\n this.reactIntegration = ReactIntegration.createForErrorScreen({\n appRoot: appRoot,\n rootNode: shadowRoot,\n locale: locale,\n config: elementOptions.chakraSystemConfig,\n styles\n });\n this.reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\n}\n\nfunction createAppRoot(locale: string) {\n // Setup application root node in the shadow dom\n const container = document.createElement(\"div\");\n container.classList.add(\"pioneer-root\");\n container.style.minHeight = \"100%\";\n container.style.height = \"100%\";\n if (locale) {\n container.lang = locale;\n }\n return container;\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppIntl;\n}) {\n const { packageMetadata, properties, builtinPackage, i18n } = config;\n\n let packages: PackageRepr[];\n try {\n packages = createPackages(packageMetadata ?? {}, i18n, properties);\n } catch (e) {\n throw new Error(ErrorId.INVALID_METADATA, \"Failed to parse package metadata.\", {\n cause: e\n });\n }\n\n // Add builtin services defined within this package.\n {\n const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);\n if (index >= 0) {\n packages.splice(index, 1);\n }\n packages.push(builtinPackage);\n }\n\n // Automatically required references (-> forces services to start)\n const forcedReferences: ReferenceSpec[] = [\n {\n interfaceName: RUNTIME_API_SERVICE\n },\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n },\n {\n interfaceName: RUNTIME_AUTO_START,\n all: true\n }\n ];\n const serviceLayer = new ServiceLayer(packages, forcedReferences);\n return {\n packages: new Map(packages.map((pkg) => [pkg.name, pkg])),\n serviceLayer: serviceLayer\n };\n}\n\nfunction getInternalService<T = unknown>(serviceLayer: ServiceLayer, interfaceName: string) {\n const result = serviceLayer.getService(\n \"@open-pioneer/runtime\",\n {\n interfaceName\n },\n { ignoreDeclarationCheck: true }\n );\n if (result.type !== \"found\") {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find instance of '${interfaceName}' (result type '${result.type}').` +\n ` This is a builtin service that must be present exactly once.`\n );\n }\n\n return result.value.getInstanceOrThrow() as T;\n}\n\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nasync function gatherConfig(\n hostElement: HTMLElement,\n options: CustomElementOptions,\n overrides?: ApplicationOverrides\n) {\n let configs: ApplicationConfig[];\n try {\n const staticConfig = options.config ?? {};\n const dynamicConfig =\n (await options.resolveConfig?.({\n hostElement,\n getAttribute(name) {\n return hostElement.getAttribute(name) ?? undefined;\n }\n })) ?? {};\n\n configs = [staticConfig, dynamicConfig];\n } catch (e) {\n throw new Error(\n ErrorId.CONFIG_RESOLUTION_FAILED,\n \"Failed to resolve application properties.\",\n {\n cause: e\n }\n );\n }\n\n const merged = mergeConfigs(configs);\n if (overrides?.locale) {\n merged.locale = overrides.locale;\n }\n return merged;\n}\n\n/**\n * Merges application configurations into a single object.\n * Properties / config parameters at a later position overwrite properties from earlier ones.\n */\nfunction mergeConfigs(configs: ApplicationConfig[]): Required<ApplicationConfig> {\n // Merge simple values by assigning them in order\n const mergedConfig: Required<ApplicationConfig> = Object.assign(\n {\n locale: undefined,\n properties: {}\n } satisfies ApplicationConfig,\n ...configs\n );\n\n // Deep merge for application properties\n const mergedProperties: ApplicationProperties = (mergedConfig.properties = {});\n for (const config of configs) {\n for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {\n const mergedPackageProps = (mergedProperties[packageName] ??= {});\n Object.assign(mergedPackageProps, packageProperties);\n }\n }\n\n return mergedConfig;\n}\n\nfunction logError(e: unknown) {\n if (e instanceof Error) {\n const chain = getErrorChain(e).reverse();\n if (chain.length === 1) {\n console.error(e);\n return;\n }\n\n let n = 1;\n for (const error of chain) {\n console.error(`#${n}`, error);\n ++n;\n }\n } else {\n console.error(\"Unexpected error\", e);\n }\n}\n\nfunction emptyComponent() {\n return null;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,GAAA,GAAM,aAAa,uBAAuB,CAAA;AA0HzC,SAAS,oBAAoB,OAA8D,EAAA;AAAA,EAC9F,MAAM,2BAA2B,WAA0C,CAAA;AAAA,IACvE,WAAA;AAAA,IACA,SAAA;AAAA;AAAA,IAGA,gBAAA;AAAA;AAAA,IAEA,WAAW,kBAA+B,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A;AAAA;AAGJ,IAAA,IAAI,CAAI,GAAA,CAAA;AACR,IAAA,KAAA,MAAW,SAAS,KAAO,EAAA;AACvB,MAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,EAAI,KAAK,CAAA;AAC5B,MAAE,EAAA,CAAA;AAAA;AACN,GACG,MAAA;AACH,IAAQ,OAAA,CAAA,KAAA,CAAM,oBAAoB,CAAC,CAAA;AAAA;AAE3C;AAEA,SAAS,cAAiB,GAAA;AACtB,EAAO,OAAA,IAAA;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { ComponentType } from \"react\";\nimport { ApiMethods } from \"./api\";\nimport { AppInstance, AppOverrides } from \"./app\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata } from \"./metadata\";\n\n// Imported for typedoc link\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { type ApiExtension } from \"./api\";\n\nconst LOG = createLogger(\"runtime:CustomElement\");\n\n/**\n * Options for the {@link createCustomElement} function.\n */\nexport interface CustomElementOptions {\n /**\n * Rendered UI component.\n */\n component?: ComponentType<Record<string, string>>;\n\n /**\n * Application metadata (packages, services etc.).\n * This is usually autogenerated by importing the virtual `\"open-pioneer:app\"` module.\n */\n appMetadata?: ApplicationMetadata;\n\n /**\n * Application defined configuration.\n *\n * This option can be used to override default properties of the application's packages.\n *\n * All instances of the web component will share this static configuration.\n */\n config?: ApplicationConfig;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n\n /**\n * Advanced configuration that alters the behavior of the custom element.\n */\n advanced?: AdvancedCustomElementOptions;\n\n /**\n * Function to provide additional application defined configuration parameters.\n *\n * Compared to {@link config}, this function receives a context object\n * that allows the developer to provide dynamic properties on a per-application instance basis.\n *\n * Parameters returned by this function take precedence over the ones defined by {@link config}.\n */\n resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * The application's host element.\n */\n hostElement: HTMLElement;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Runtime application configuration.\n */\nexport interface ApplicationConfig {\n /**\n * Set this value to a locale string (e.g. \"en\") to for the application's locale.\n * The default behavior is to choose an appropriate locale for the current user based\n * on the browser's settings.\n *\n * The locale must be supported by the application.\n */\n locale?: string | undefined;\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n}\n\n/**\n * Allows the application to override default properties in all packages.\n *\n * Properties are typed when the package contains type definitions for them.\n */\nexport interface ApplicationProperties {\n /**\n * Key: the name of the package.\n * Value: A record of configuration properties (key/value pairs).\n *\n * Properties will override default property values in the package.\n */\n [packageName: string]: Record<string, unknown>;\n}\n\n/**\n * The interface implemented by web components produced via {@link createCustomElement}.\n */\nexport interface ApplicationElement extends HTMLElement {\n /**\n * Resolves to the element's API when the application has started.\n *\n * The API exposed by an application can be defined by implementing an {@link ApiExtension}.\n * For more details, open the documentation of the `@open-pioneer/integration` package.\n */\n when(): Promise<ApiMethods>;\n}\n\n/**\n * Advanced configuration that alters the behavior of the custom element.\n *\n * See {@link createCustomElement}.\n */\nexport interface AdvancedCustomElementOptions {\n /**\n * Enables or disables the [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot) inside the application's web component.\n *\n * Default: `true`.\n *\n * By default, trails applications use a shadow root to avoid conflicts (e.g. styles) with other parts of the site where the application may be embedded.\n *\n * Applications that use the entire browser viewport may not need this feature, since there may be no \"other\" parts that may conflict with the app.\n * In this case, you can disable the shadow root by setting this property to `false`.\n * In general, UI components used by the app (e.g. from Chakra UI) should work just as well when disabling the shadow root.\n * If you notice any problems, please file an issue.\n *\n * If you are developing UI components that are meant to be used in other applications, you should always use a shadow root to\n * ensure that your components work in that setting.\n */\n enableShadowRoot?: boolean;\n}\n\n/**\n * The class returned by a call to {@link createCustomElement}.\n */\nexport interface ApplicationElementConstructor {\n new (): ApplicationElement;\n}\n\n/**\n * Creates a new custom element class (web component) that can be registered within a DOM.\n *\n * @example\n * ```ts\n * import * as appMetadata from \"open-pioneer:app\";\n *\n * const CustomElementClazz = createCustomElement({\n * component: <div>Hello World!</div>,\n * appMetadata\n * });\n * customElements.define(\"sample-element\", CustomElementClazz);\n * ```\n */\nexport function createCustomElement(options: CustomElementOptions): ApplicationElementConstructor {\n class PioneerApplication extends HTMLElement implements ApplicationElement {\n #shadowRoot: ShadowRoot | undefined;\n #instance: AppInstance | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #deferredRestart: any; // A Timer\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n const enableShadowRoot = options.advanced?.enableShadowRoot ?? true;\n if (enableShadowRoot) {\n this.#shadowRoot = this.attachShadow({\n mode: \"open\"\n });\n } else {\n LOG.debug(\"Creating component instance without shadow root\");\n }\n\n if (import.meta.env.DEV) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#instance;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#instance) {\n this.#instance.destroy();\n }\n\n this.#instance = this.#createApplicationInstance();\n this.#instance.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#instance?.destroy();\n this.#instance = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#instance) {\n return Promise.reject(\n new Error(\n ErrorId.NOT_MOUNTED,\n \"Cannot use the application's API because the HTML element has not yet been mounted into the DOM.\"\n )\n );\n }\n\n return this.#instance.whenAPI();\n }\n\n #triggerReload(overrides?: AppOverrides) {\n // Defer the restart operation a tiny bit so calling code does not get surprised by the application's destruction.\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#deferredRestart = setTimeout(() => {\n if (!this.#instance) {\n // disconnectedCallback was called in the meantime\n return;\n }\n\n LOG.debug(\"Restarting application with new options\", overrides);\n this.#instance.destroy();\n this.#instance = this.#createApplicationInstance(overrides);\n this.#instance.start();\n }, 1);\n }\n\n #createApplicationInstance(overrides?: AppOverrides) {\n return new AppInstance({\n rootNode: this.#shadowRoot ?? document,\n hostElement: this,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n });\n }\n }\n return PioneerApplication;\n}\n"],"names":[],"mappings":";;;;AAcA,MAAM,GAAA,GAAM,aAAa,uBAAuB,CAAA;AA4JzC,SAAS,oBAAoB,OAA8D,EAAA;AAAA,EAC9F,MAAM,2BAA2B,WAA0C,CAAA;AAAA,IACvE,WAAA;AAAA,IACA,SAAA;AAAA;AAAA,IAGA,gBAAA;AAAA;AAAA,IAEA,WAAW,kBAA+B,GAAA;AACtC,MAAA,OAAO,EAAC;AAAA;AACZ,IAEA,WAAc,GAAA;AACV,MAAM,KAAA,EAAA;AAEN,MAAM,MAAA,gBAAA,GAAmB,OAAQ,CAAA,QAAA,EAAU,gBAAoB,IAAA,IAAA;AAC/D,MAAA,IAAI,gBAAkB,EAAA;AAClB,QAAK,IAAA,CAAA,WAAA,GAAc,KAAK,YAAa,CAAA;AAAA,UACjC,IAAM,EAAA;AAAA,SACT,CAAA;AAAA,OACE,MAAA;AACH,QAAA,GAAA,CAAI,MAAM,iDAAiD,CAAA;AAAA;AAG/D,MAAI,IAAA,MAAA,CAAA,IAAA,CAAY,IAAI,GAAK,EAAA;AAErB,QAAC,IAAA,CAAa,oBAAuB,GAAA,MAAM,IAAK,CAAA,SAAA;AAAA;A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AAA,IAAA,CAAK,UAAU,KAAM,EAAA;AAAA,SACtB,CAAC,CAAA;AAAA;AACR,IAEA,2BAA2B,SAA0B,EAAA;AACjD,MAAA,OAAO,IAAI,WAAY,CAAA;AAAA,QACnB,QAAA,EAAU,KAAK,WAAe,IAAA,QAAA;AAAA,QAC9B,WAAa,EAAA,IAAA;AAAA,QACb,cAAgB,EAAA,OAAA;AAAA,QAChB,SAAA;AAAA,QACA,OAAS,EAAA,IAAA,CAAK,cAAe,CAAA,IAAA,CAAK,IAAI;AAAA,OACzC,CAAA;AAAA;AACL;AAEJ,EAAO,OAAA,kBAAA;AACX;;;;"}
|
package/api.d.ts
CHANGED
|
@@ -32,13 +32,39 @@ export interface ApplicationContext extends DeclaredService<"runtime.Application
|
|
|
32
32
|
* This dom node can be accessed by the host site.
|
|
33
33
|
*/
|
|
34
34
|
getHostElement(): HTMLElement;
|
|
35
|
+
/**
|
|
36
|
+
* A root node that resolves to the the shadow root or the site's document.
|
|
37
|
+
*
|
|
38
|
+
* For example:
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* const ctx: ApplicationContext = ...;
|
|
42
|
+
* const node = ctx.getRoot().getElementById("id"); // Correct with or without shadow root.
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
getRoot(): Document | ShadowRoot;
|
|
35
46
|
/**
|
|
36
47
|
* The current web component's shadow root.
|
|
37
48
|
* This shadow root is located inside the host element.
|
|
49
|
+
*
|
|
50
|
+
* NOTE: This method returns undefined if the application does not use a shadow root.
|
|
51
|
+
*
|
|
52
|
+
* See also {@link ApplicationConfig.disableShadowRoot} and {@link getRoot()}.
|
|
38
53
|
*/
|
|
39
|
-
getShadowRoot(): ShadowRoot;
|
|
54
|
+
getShadowRoot(): ShadowRoot | undefined;
|
|
40
55
|
/**
|
|
41
|
-
* The
|
|
56
|
+
* The HTML element containing the rest of the application _inside_ the current web component.
|
|
57
|
+
*
|
|
58
|
+
* This element can be used as a root component to find other dom elements within the same application,
|
|
59
|
+
* for example:
|
|
60
|
+
*
|
|
61
|
+
* ```
|
|
62
|
+
* // Correct:
|
|
63
|
+
* const node = ctx.getApplicationContainer().querySelector('.my-element');
|
|
64
|
+
*
|
|
65
|
+
* // Incorrect because cannot search in shadow roots
|
|
66
|
+
* const node = document.querySelector('.my-element');
|
|
67
|
+
* ```
|
|
42
68
|
*/
|
|
43
69
|
getApplicationContainer(): HTMLElement;
|
|
44
70
|
/**
|