@open-pioneer/runtime 4.7.0-dev.20260624141040 → 4.7.0-dev.20260713101438
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 +14 -1
- package/CustomElement.d.ts +27 -2
- package/CustomElement.js.map +1 -1
- package/_virtual/source-info.js +2 -2
- package/api.d.ts +55 -2
- package/app/AppInstance.d.ts +3 -27
- package/app/AppInstance.js +144 -119
- package/app/AppInstance.js.map +1 -1
- package/app/gatherConfig.js +1 -0
- package/app/gatherConfig.js.map +1 -1
- package/builtin-services/ApiServiceImpl.d.ts +1 -1
- package/builtin-services/ApiServiceImpl.js +3 -3
- package/builtin-services/ApiServiceImpl.js.map +1 -1
- package/builtin-services/ApplicationContextImpl.d.ts +11 -7
- package/builtin-services/ApplicationContextImpl.js +51 -10
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/builtin-services/LocaleServiceImpl.d.ts +18 -0
- package/builtin-services/LocaleServiceImpl.js +29 -0
- package/builtin-services/LocaleServiceImpl.js.map +1 -0
- package/builtin-services/NumberParserServiceImpl.d.ts +8 -3
- package/builtin-services/NumberParserServiceImpl.js +17 -12
- package/builtin-services/NumberParserServiceImpl.js.map +1 -1
- package/builtin-services/index.d.ts +3 -1
- package/builtin-services/index.js +34 -4
- package/builtin-services/index.js.map +1 -1
- package/dom/index.d.ts +1 -1
- package/dom/index.js +1 -4
- package/dom/index.js.map +1 -1
- package/i18n/AppIntl.d.ts +49 -11
- package/i18n/AppIntl.js +205 -87
- package/i18n/AppIntl.js.map +1 -1
- package/i18n/index.d.ts +3 -2
- package/i18n/index.js +2 -1
- package/i18n/index.js.map +1 -1
- package/i18n/intl-locale.d.ts +13 -0
- package/i18n/intl-locale.js +17 -0
- package/i18n/intl-locale.js.map +1 -0
- package/i18n/pick.d.ts +29 -16
- package/i18n/pick.js +78 -51
- package/i18n/pick.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +6 -0
- package/index.js.map +1 -1
- package/package.json +6 -5
- package/react-integration/ChakraProvider.d.ts +1 -1
- package/react-integration/ChakraProvider.js +3 -2
- package/react-integration/ChakraProvider.js.map +1 -1
- package/react-integration/PackageContext.d.ts +1 -1
- package/react-integration/PackageContext.js.map +1 -1
- package/react-integration/ReactIntegration.d.ts +2 -10
- package/react-integration/ReactIntegration.js +28 -28
- package/react-integration/ReactIntegration.js.map +1 -1
- package/react-integration/hooks.js +5 -9
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/ServiceLayer.d.ts +1 -20
- package/service-layer/ServiceLayer.js +39 -39
- package/service-layer/ServiceLayer.js.map +1 -1
- package/service-layer/ServiceLookup.d.ts +1 -3
- package/service-layer/ServiceLookup.js +10 -10
- package/service-layer/ServiceLookup.js.map +1 -1
- package/service-layer/ServiceRepr.d.ts +2 -11
- package/service-layer/ServiceRepr.js +68 -50
- package/service-layer/ServiceRepr.js.map +1 -1
- package/service-layer/verifyDependencies.js +33 -33
- package/service-layer/verifyDependencies.js.map +1 -1
- package/test-support/index.js +2 -1
- package/test-support/index.js.map +1 -1
package/app/AppInstance.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { computed, reactive, effect } from '@conterra/reactivity-core';
|
|
1
|
+
import { watchValue, computed, constant, reactive, effect } from '@conterra/reactivity-core';
|
|
2
2
|
import { createLogger, Error, createAbortError, destroyResource, createManualPromise, throwAbortError } from '@open-pioneer/core';
|
|
3
3
|
import { sourceId$5 as sourceId } from '../_virtual/source-info.js';
|
|
4
4
|
import { createElement } from 'react';
|
|
5
|
-
import { createBuiltinPackage, RUNTIME_THEME_SERVICE, RUNTIME_API_SERVICE, RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE, RUNTIME_AUTO_START } from '../builtin-services/index.js';
|
|
5
|
+
import { createBuiltinPackage, RUNTIME_THEME_SERVICE, RUNTIME_API_SERVICE, RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE, RUNTIME_LOCALE_SERVICE, RUNTIME_AUTO_START } from '../builtin-services/index.js';
|
|
6
6
|
import { DEFAULT_INITIAL_COLOR_MODE } from '../builtin-services/ThemeServiceImpl.js';
|
|
7
7
|
import { isShadowRoot, createAppRoot } from '../dom/index.js';
|
|
8
8
|
import { ErrorId } from '../errors.js';
|
|
9
|
-
import {
|
|
9
|
+
import { AppIntl } from '../i18n/AppIntl.js';
|
|
10
|
+
import { parseLocale } from '../i18n/intl-locale.js';
|
|
10
11
|
import { createPackageIntl } from '../i18n/PackageIntl.js';
|
|
11
|
-
import { getBrowserLocales,
|
|
12
|
+
import { getBrowserLocales, LocalePicker } from '../i18n/pick.js';
|
|
12
13
|
import { MESSAGES_BY_LOCALE, ErrorScreen } from '../react-integration/ErrorScreen.js';
|
|
13
14
|
import { ReactIntegration, EmptyComponent } from '../react-integration/ReactIntegration.js';
|
|
14
15
|
import { createPackages } from '../service-layer/PackageRepr.js';
|
|
@@ -18,119 +19,152 @@ import { logError } from './logErrors.js';
|
|
|
18
19
|
|
|
19
20
|
const LOG = createLogger(sourceId);
|
|
20
21
|
class AppInstance {
|
|
21
|
-
options;
|
|
22
|
+
#options;
|
|
22
23
|
// Public API
|
|
23
|
-
apiPromise;
|
|
24
|
+
#apiPromise;
|
|
24
25
|
// Present when callers are waiting for the API
|
|
25
|
-
api;
|
|
26
|
+
#api;
|
|
26
27
|
// Present once started
|
|
27
|
-
state = "not-started";
|
|
28
|
-
rootNode;
|
|
29
|
-
container;
|
|
28
|
+
#state = "not-started";
|
|
29
|
+
#rootNode;
|
|
30
|
+
#container;
|
|
30
31
|
// parent of .pioneer-root
|
|
31
|
-
|
|
32
|
+
#i18n;
|
|
33
|
+
// Unused on purpose for easier debugging.
|
|
34
|
+
// eslint-disable-next-line no-unused-private-class-members
|
|
35
|
+
#appRoot;
|
|
32
36
|
// .pioneer-root
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// Unused on purpose for easier debugging.
|
|
38
|
+
// eslint-disable-next-line no-unused-private-class-members
|
|
39
|
+
#config;
|
|
40
|
+
#serviceLayer;
|
|
41
|
+
#lifecycleEvents;
|
|
42
|
+
#themeService;
|
|
43
|
+
#reactIntegration;
|
|
44
|
+
#stylesWatch;
|
|
45
|
+
#localeWatch;
|
|
40
46
|
constructor(options) {
|
|
41
|
-
this
|
|
42
|
-
this
|
|
43
|
-
this
|
|
47
|
+
this.#options = options;
|
|
48
|
+
this.#container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;
|
|
49
|
+
this.#rootNode = options.rootNode;
|
|
50
|
+
}
|
|
51
|
+
/** Current lifecycle state. Exposed (read-only) for tests/debugging via `$inspectElementState`. */
|
|
52
|
+
get state() {
|
|
53
|
+
return this.#state;
|
|
44
54
|
}
|
|
45
55
|
start() {
|
|
46
|
-
if (this
|
|
47
|
-
throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this
|
|
56
|
+
if (this.#state !== "not-started") {
|
|
57
|
+
throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.#state}'`);
|
|
48
58
|
}
|
|
49
|
-
this
|
|
50
|
-
this
|
|
51
|
-
if (this
|
|
59
|
+
this.#state = "starting";
|
|
60
|
+
this.#startImpl().catch((e) => {
|
|
61
|
+
if (this.#state === "destroyed") return;
|
|
52
62
|
logError(e);
|
|
53
|
-
this
|
|
54
|
-
this
|
|
55
|
-
this
|
|
63
|
+
this.#reset();
|
|
64
|
+
this.#state = "error";
|
|
65
|
+
this.#showErrorScreen(e);
|
|
56
66
|
});
|
|
57
67
|
}
|
|
58
68
|
destroy() {
|
|
59
|
-
if (this
|
|
69
|
+
if (this.#state === "destroyed") {
|
|
60
70
|
return;
|
|
61
71
|
}
|
|
62
|
-
if (this
|
|
72
|
+
if (this.#state === "started") {
|
|
63
73
|
try {
|
|
64
|
-
this
|
|
74
|
+
this.#triggerApplicationLifecycleEvent("before-stop");
|
|
65
75
|
} catch (e) {
|
|
66
76
|
}
|
|
67
77
|
}
|
|
68
|
-
this
|
|
69
|
-
this
|
|
78
|
+
this.#state = "destroyed";
|
|
79
|
+
this.#reset();
|
|
70
80
|
}
|
|
71
|
-
reset() {
|
|
72
|
-
this
|
|
73
|
-
this
|
|
74
|
-
this
|
|
75
|
-
this
|
|
76
|
-
this
|
|
77
|
-
this
|
|
78
|
-
this
|
|
79
|
-
this
|
|
80
|
-
this
|
|
81
|
+
#reset() {
|
|
82
|
+
this.#apiPromise?.reject(createAbortError());
|
|
83
|
+
this.#reactIntegration = destroyResource(this.#reactIntegration);
|
|
84
|
+
this.#container.replaceChildren();
|
|
85
|
+
this.#appRoot = void 0;
|
|
86
|
+
this.#lifecycleEvents = void 0;
|
|
87
|
+
this.#themeService = void 0;
|
|
88
|
+
this.#i18n = destroyResource(this.#i18n);
|
|
89
|
+
this.#serviceLayer = destroyResource(this.#serviceLayer);
|
|
90
|
+
this.#stylesWatch = destroyResource(this.#stylesWatch);
|
|
91
|
+
this.#localeWatch = destroyResource(this.#localeWatch);
|
|
81
92
|
}
|
|
82
93
|
whenAPI() {
|
|
83
|
-
if (this
|
|
84
|
-
return Promise.resolve(this
|
|
94
|
+
if (this.#api) {
|
|
95
|
+
return Promise.resolve(this.#api);
|
|
85
96
|
}
|
|
86
|
-
const apiPromise = this
|
|
97
|
+
const apiPromise = this.#apiPromise ??= createManualPromise();
|
|
87
98
|
return apiPromise.promise;
|
|
88
99
|
}
|
|
89
|
-
async startImpl() {
|
|
90
|
-
const { hostElement, elementOptions, overrides } = this
|
|
91
|
-
const root = this
|
|
92
|
-
const config = this
|
|
93
|
-
this
|
|
100
|
+
async #startImpl() {
|
|
101
|
+
const { hostElement, elementOptions, overrides } = this.#options;
|
|
102
|
+
const root = this.#rootNode;
|
|
103
|
+
const config = this.#config = await gatherConfig(hostElement, elementOptions, overrides);
|
|
104
|
+
this.#checkAbort();
|
|
94
105
|
LOG.debug("Application config is", config);
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
const enableLiveLocaleChanges = elementOptions.advanced?.enableLiveLocaleChanges ?? false;
|
|
107
|
+
const restartWithLocale = (locale) => {
|
|
108
|
+
const restart = this.#options.restart;
|
|
109
|
+
const themeService2 = this.#themeService;
|
|
110
|
+
const colorMode = themeService2?.colorMode;
|
|
111
|
+
const chakraSystemConfig = themeService2?.systemConfig;
|
|
112
|
+
restart({ locale: locale?.baseName, colorMode, chakraSystemConfig });
|
|
113
|
+
};
|
|
114
|
+
const i18n = this.#i18n = await AppIntl.create({
|
|
115
|
+
appMetadata: elementOptions.appMetadata,
|
|
116
|
+
forcedLocale: config.locale,
|
|
117
|
+
restrictSupportedLocales: config.supportedLocales,
|
|
118
|
+
supportsLiveChanges: enableLiveLocaleChanges,
|
|
119
|
+
restartWithLocale
|
|
120
|
+
});
|
|
121
|
+
this.#checkAbort();
|
|
122
|
+
const appRoot = this.#appRoot = createAppRoot();
|
|
123
|
+
this.#localeWatch = watchValue(
|
|
124
|
+
() => i18n.locale.baseName,
|
|
125
|
+
(locale) => {
|
|
126
|
+
appRoot.lang = locale;
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
immediate: true
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
this.#container.appendChild(appRoot);
|
|
133
|
+
const styles = this.#initStylesSignal();
|
|
134
|
+
const { serviceLayer, packages } = this.#initServiceLayer({
|
|
101
135
|
container: appRoot,
|
|
102
136
|
properties: config.properties,
|
|
103
137
|
i18n,
|
|
104
138
|
initialColorMode: config.colorMode,
|
|
105
139
|
initialSystemConfig: config.chakraSystemConfig
|
|
106
140
|
});
|
|
107
|
-
this
|
|
141
|
+
this.#lifecycleEvents = getInternalService(
|
|
108
142
|
serviceLayer,
|
|
109
143
|
RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE
|
|
110
144
|
);
|
|
111
|
-
const themeService = this
|
|
145
|
+
const themeService = this.#themeService = getInternalService(
|
|
112
146
|
serviceLayer,
|
|
113
147
|
RUNTIME_THEME_SERVICE
|
|
114
148
|
);
|
|
115
|
-
const apiPromise = this
|
|
116
|
-
this
|
|
117
|
-
this
|
|
149
|
+
const apiPromise = this.#initAPI(serviceLayer);
|
|
150
|
+
this.#checkAbort();
|
|
151
|
+
this.#reactIntegration = ReactIntegration.createForApp({
|
|
118
152
|
rootNode: root,
|
|
119
153
|
hostNode: hostElement,
|
|
120
154
|
appRoot,
|
|
121
155
|
serviceLayer,
|
|
122
156
|
packages,
|
|
123
|
-
locale: i18n.locale,
|
|
157
|
+
locale: computed(() => i18n.locale.baseName),
|
|
124
158
|
config: computed(() => themeService.systemConfig),
|
|
125
159
|
styles,
|
|
126
160
|
colorMode: computed(() => themeService.colorMode)
|
|
127
161
|
});
|
|
128
|
-
const component = this
|
|
129
|
-
this
|
|
162
|
+
const component = this.#options.elementOptions.component ?? EmptyComponent;
|
|
163
|
+
this.#reactIntegration.render(createElement(component));
|
|
130
164
|
await apiPromise;
|
|
131
|
-
this
|
|
132
|
-
this
|
|
133
|
-
this
|
|
165
|
+
this.#checkAbort();
|
|
166
|
+
this.#state = "started";
|
|
167
|
+
this.#triggerApplicationLifecycleEvent("after-start");
|
|
134
168
|
LOG.debug("Application started");
|
|
135
169
|
}
|
|
136
170
|
/**
|
|
@@ -138,14 +172,14 @@ class AppInstance {
|
|
|
138
172
|
* During development, the signal is updated when the user edits .css files.
|
|
139
173
|
* In production, the signal is static.
|
|
140
174
|
*/
|
|
141
|
-
initStylesSignal() {
|
|
142
|
-
const stylesBox = this
|
|
175
|
+
#initStylesSignal() {
|
|
176
|
+
const stylesBox = this.#options.elementOptions.appMetadata?.styles;
|
|
143
177
|
if (!stylesBox) {
|
|
144
|
-
return
|
|
178
|
+
return constant("");
|
|
145
179
|
}
|
|
146
180
|
const signal = reactive(stylesBox.value);
|
|
147
181
|
if (import.meta.hot) {
|
|
148
|
-
this
|
|
182
|
+
this.#stylesWatch = effect(
|
|
149
183
|
() => {
|
|
150
184
|
signal.value = stylesBox.value;
|
|
151
185
|
LOG.debug("Application styles changed");
|
|
@@ -155,8 +189,8 @@ class AppInstance {
|
|
|
155
189
|
}
|
|
156
190
|
return signal;
|
|
157
191
|
}
|
|
158
|
-
initServiceLayer(config) {
|
|
159
|
-
const { hostElement, rootNode: shadowRoot, elementOptions
|
|
192
|
+
#initServiceLayer(config) {
|
|
193
|
+
const { hostElement, rootNode: shadowRoot, elementOptions } = this.#options;
|
|
160
194
|
const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;
|
|
161
195
|
const packageMetadata = elementOptions.appMetadata?.packages ?? {};
|
|
162
196
|
const builtinPackage = createBuiltinPackage({
|
|
@@ -165,22 +199,7 @@ class AppInstance {
|
|
|
165
199
|
container,
|
|
166
200
|
initialColorMode,
|
|
167
201
|
initialSystemConfig,
|
|
168
|
-
|
|
169
|
-
supportedLocales: i18n.supportedMessageLocales,
|
|
170
|
-
changeLocale: (locale) => {
|
|
171
|
-
const supported = i18n.supportedMessageLocales;
|
|
172
|
-
if (locale != null && !i18n.supportsLocale(locale)) {
|
|
173
|
-
const supportedLocales = supported.join(", ");
|
|
174
|
-
throw new Error(
|
|
175
|
-
ErrorId.UNSUPPORTED_LOCALE,
|
|
176
|
-
`Unsupported locale '${locale}' (supported locales: ${supportedLocales}).`
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
const themeService = this.themeService;
|
|
180
|
-
const colorMode = themeService?.colorMode;
|
|
181
|
-
const chakraSystemConfig = themeService?.systemConfig;
|
|
182
|
-
restart({ locale, colorMode, chakraSystemConfig });
|
|
183
|
-
}
|
|
202
|
+
appIntl: i18n
|
|
184
203
|
});
|
|
185
204
|
const { serviceLayer, packages } = createServiceLayer({
|
|
186
205
|
packageMetadata,
|
|
@@ -188,21 +207,21 @@ class AppInstance {
|
|
|
188
207
|
properties,
|
|
189
208
|
i18n
|
|
190
209
|
});
|
|
191
|
-
this
|
|
210
|
+
this.#serviceLayer = serviceLayer;
|
|
192
211
|
if (LOG.isDebug()) {
|
|
193
212
|
LOG.debug("Launching service layer with packages", Object.fromEntries(packages));
|
|
194
213
|
}
|
|
195
214
|
serviceLayer.start();
|
|
196
215
|
return { serviceLayer, packages };
|
|
197
216
|
}
|
|
198
|
-
async initAPI(serviceLayer) {
|
|
217
|
+
async #initAPI(serviceLayer) {
|
|
199
218
|
const apiService = getInternalService(serviceLayer, RUNTIME_API_SERVICE);
|
|
200
219
|
try {
|
|
201
220
|
const api = await apiService.getApi();
|
|
202
|
-
this
|
|
203
|
-
this
|
|
221
|
+
this.#checkAbort();
|
|
222
|
+
this.#api = api;
|
|
204
223
|
LOG.debug("Application API initialized to", api);
|
|
205
|
-
this
|
|
224
|
+
this.#apiPromise?.resolve(api);
|
|
206
225
|
} catch (e) {
|
|
207
226
|
const ex = new Error(
|
|
208
227
|
ErrorId.INTERNAL,
|
|
@@ -211,43 +230,46 @@ class AppInstance {
|
|
|
211
230
|
cause: e
|
|
212
231
|
}
|
|
213
232
|
);
|
|
214
|
-
if (!this
|
|
215
|
-
this
|
|
216
|
-
this
|
|
233
|
+
if (!this.#apiPromise) {
|
|
234
|
+
this.#apiPromise = createManualPromise();
|
|
235
|
+
this.#apiPromise.promise.catch(() => {
|
|
217
236
|
});
|
|
218
237
|
}
|
|
219
|
-
this
|
|
238
|
+
this.#apiPromise.reject(ex);
|
|
220
239
|
throw ex;
|
|
221
240
|
}
|
|
222
241
|
}
|
|
223
|
-
triggerApplicationLifecycleEvent(event) {
|
|
224
|
-
this
|
|
242
|
+
#triggerApplicationLifecycleEvent(event) {
|
|
243
|
+
this.#lifecycleEvents?.emitLifecycleEvent(event);
|
|
225
244
|
}
|
|
226
|
-
checkAbort() {
|
|
227
|
-
if (this
|
|
245
|
+
#checkAbort() {
|
|
246
|
+
if (this.#state === "destroyed") {
|
|
228
247
|
throwAbortError();
|
|
229
248
|
}
|
|
230
249
|
}
|
|
231
|
-
showErrorScreen(error) {
|
|
250
|
+
#showErrorScreen(error) {
|
|
232
251
|
const userLocales = getBrowserLocales();
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
const
|
|
252
|
+
const localePicker = new LocalePicker(
|
|
253
|
+
Object.keys(MESSAGES_BY_LOCALE).map((tag) => parseLocale(tag))
|
|
254
|
+
);
|
|
255
|
+
const { locale, messageLocale } = localePicker.pickSupportedLocale(void 0, userLocales);
|
|
256
|
+
const messages = MESSAGES_BY_LOCALE[messageLocale.baseName] ?? MESSAGES_BY_LOCALE["en"];
|
|
257
|
+
const intl = createPackageIntl(locale.baseName, messages);
|
|
258
|
+
const appRoot = this.#appRoot = createAppRoot();
|
|
259
|
+
appRoot.lang = locale.baseName;
|
|
238
260
|
appRoot.classList.add("pioneer-root-error-screen");
|
|
239
|
-
this
|
|
240
|
-
const styles = this
|
|
241
|
-
this
|
|
242
|
-
rootNode: this
|
|
243
|
-
hostNode: this
|
|
261
|
+
this.#container.appendChild(appRoot);
|
|
262
|
+
const styles = this.#initStylesSignal();
|
|
263
|
+
this.#reactIntegration = ReactIntegration.createForErrorScreen({
|
|
264
|
+
rootNode: this.#rootNode,
|
|
265
|
+
hostNode: this.#options.hostElement,
|
|
244
266
|
appRoot,
|
|
245
|
-
locale,
|
|
246
|
-
config:
|
|
267
|
+
locale: constant(locale.baseName),
|
|
268
|
+
config: constant(this.#options.elementOptions.chakraSystemConfig),
|
|
247
269
|
styles,
|
|
248
|
-
colorMode:
|
|
270
|
+
colorMode: constant(DEFAULT_INITIAL_COLOR_MODE)
|
|
249
271
|
});
|
|
250
|
-
this
|
|
272
|
+
this.#reactIntegration.render(createElement(ErrorScreen, { intl, error }));
|
|
251
273
|
}
|
|
252
274
|
}
|
|
253
275
|
function createServiceLayer(config) {
|
|
@@ -274,6 +296,9 @@ function createServiceLayer(config) {
|
|
|
274
296
|
{
|
|
275
297
|
interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE
|
|
276
298
|
},
|
|
299
|
+
{
|
|
300
|
+
interfaceName: RUNTIME_LOCALE_SERVICE
|
|
301
|
+
},
|
|
277
302
|
{
|
|
278
303
|
interfaceName: RUNTIME_THEME_SERVICE
|
|
279
304
|
},
|
package/app/AppInstance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppInstance.js","sources":["AppInstance.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { computed, effect, reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService, ColorModeValue, ThemeService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START,\n RUNTIME_THEME_SERVICE\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport { DEFAULT_INITIAL_COLOR_MODE } from \"../builtin-services/ThemeServiceImpl\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, I18nConfig, initI18n } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\n\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\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\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n private options: AppOptions;\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: AppState = \"not-started\";\n private rootNode: RootNode;\n private container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n private appRoot: HTMLDivElement | undefined; // .pioneer-root\n private config: ApplicationConfig | undefined;\n private i18n: AppIntl | undefined;\n private serviceLayer: ServiceLayer | undefined;\n private lifecycleEvents: ApplicationLifecycleEventService | undefined;\n private themeService: ThemeService | undefined;\n private reactIntegration: ReactIntegration | undefined;\n\n private stylesWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.options = options;\n this.container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.rootNode = options.rootNode;\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.container.replaceChildren();\n this.appRoot = undefined;\n this.lifecycleEvents = undefined;\n this.themeService = undefined;\n this.i18n = destroyResource(this.i18n);\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 { hostElement, elementOptions, overrides } = this.options;\n const root = this.rootNode;\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 = (this.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 this.container.appendChild(appRoot);\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 initialColorMode: config.colorMode,\n initialSystemConfig: config.chakraSystemConfig\n });\n this.lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n const themeService = (this.themeService = getInternalService<ThemeService>(\n serviceLayer,\n RUNTIME_THEME_SERVICE\n ));\n\n // init api, but do not wait for it\n const apiPromise = this.initAPI(serviceLayer);\n this.checkAbort();\n\n // Launch react\n this.reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: i18n.locale,\n config: computed(() => themeService.systemConfig),\n styles,\n colorMode: computed(() => themeService.colorMode)\n });\n const component = this.options.elementOptions.component ?? EmptyComponent;\n this.reactIntegration.render(createElement(component));\n\n // wait for api, to ensure that the \"started\" state is only reached after the API is available.\n // but do not block the react rendering, to allow for a fast Time to Interactive and to show potential errors in the UI even if the API fails.\n await apiPromise;\n this.checkAbort();\n\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 = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n private initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n initialColorMode: ColorModeValue | \"system\" | undefined;\n initialSystemConfig: SystemConfig | undefined;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions, restart } = this.options;\n\n const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n initialColorMode,\n initialSystemConfig,\n locale: i18n.locale,\n supportedLocales: i18n.supportedMessageLocales,\n changeLocale: (locale) => {\n const supported = i18n.supportedMessageLocales;\n if (locale != null && !i18n.supportsLocale(locale)) {\n const supportedLocales = supported.join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${locale}' (supported locales: ${supportedLocales}).`\n );\n }\n\n const themeService = this.themeService;\n const colorMode = themeService?.colorMode;\n const chakraSystemConfig = themeService?.systemConfig;\n restart({ locale, colorMode, chakraSystemConfig });\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 = await apiService.getApi();\n this.checkAbort();\n this.api = api;\n LOG.debug(\"Application API initialized to\", api);\n this.apiPromise?.resolve(api);\n } catch (e) {\n const ex = new Error(\n ErrorId.INTERNAL,\n \"Failed to gather the application's API methods.\",\n {\n cause: e\n }\n );\n if (!this.apiPromise) {\n // no one is waiting yet.\n // keep the error for when they do\n this.apiPromise = createManualPromise();\n // prevent unhandled rejection if no one is waiting for the API\n this.apiPromise.promise.catch(() => {});\n }\n this.apiPromise.reject(ex);\n throw ex;\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 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 this.container.appendChild(appRoot);\n\n const styles = this.initStylesSignal();\n\n this.reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.rootNode,\n hostNode: this.options.hostElement,\n appRoot: appRoot,\n locale: locale,\n config: reactive(this.options.elementOptions.chakraSystemConfig),\n styles,\n colorMode: reactive(DEFAULT_INITIAL_COLOR_MODE)\n });\n this.reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\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_THEME_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"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA6CA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAwB1B,MAAM,WAAA,CAAY;A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,UAAA;AAAA,IACxB,uBAAA;AAAA,IACA;AAAA,MACI;AAAA,KACJ;AAAA,IACA,EAAE,wBAAwB,IAAA;AAAK,GACnC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,aAAa,CAAA,gBAAA,EAAmB,MAAA,CAAO,IAAI,CAAA,gEAAA;AAAA,KAE9E;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;;;"}
|
|
1
|
+
{"version":3,"file":"AppInstance.js","sources":["AppInstance.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n computed,\n constant,\n effect,\n reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService, ColorModeValue, ThemeService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START,\n RUNTIME_LOCALE_SERVICE,\n RUNTIME_THEME_SERVICE\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport { DEFAULT_INITIAL_COLOR_MODE } from \"../builtin-services/ThemeServiceImpl\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, LocalePicker, parseLocale } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\n\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\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\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n #options: AppOptions;\n\n // Public API\n #apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n #api: ApiMethods | undefined; // Present once started\n\n #state: AppState = \"not-started\";\n #rootNode: RootNode;\n #container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n #i18n: AppIntl | undefined;\n\n // Unused on purpose for easier debugging.\n // eslint-disable-next-line no-unused-private-class-members\n #appRoot: HTMLDivElement | undefined; // .pioneer-root\n\n // Unused on purpose for easier debugging.\n // eslint-disable-next-line no-unused-private-class-members\n #config: ApplicationConfig | undefined;\n\n #serviceLayer: ServiceLayer | undefined;\n #lifecycleEvents: ApplicationLifecycleEventService | undefined;\n #themeService: ThemeService | undefined;\n #reactIntegration: ReactIntegration | undefined;\n\n #stylesWatch: Resource | undefined;\n #localeWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.#options = options;\n this.#container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.#rootNode = options.rootNode;\n }\n\n /** Current lifecycle state. Exposed (read-only) for tests/debugging via `$inspectElementState`. */\n get state(): AppState {\n return this.#state;\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 #reset() {\n this.#apiPromise?.reject(createAbortError());\n this.#reactIntegration = destroyResource(this.#reactIntegration);\n this.#container.replaceChildren();\n this.#appRoot = undefined;\n this.#lifecycleEvents = undefined;\n this.#themeService = undefined;\n this.#i18n = destroyResource(this.#i18n);\n this.#serviceLayer = destroyResource(this.#serviceLayer);\n this.#stylesWatch = destroyResource(this.#stylesWatch);\n this.#localeWatch = destroyResource(this.#localeWatch);\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 async #startImpl() {\n const { hostElement, elementOptions, overrides } = this.#options;\n const root = this.#rootNode;\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 // TODO (next major): always true (option can be removed).\n // Currently false by default (needs to be enabled) to preserve backwards compatibility.\n const enableLiveLocaleChanges = elementOptions.advanced?.enableLiveLocaleChanges ?? false;\n\n // TODO (next major): Remove restarting code!\n const restartWithLocale = (locale: Intl.Locale | undefined) => {\n // this code is triggered, when the app calls changeLocale while reactive switching is disabled.\n const restart = this.#options.restart;\n const themeService = this.#themeService;\n const colorMode = themeService?.colorMode;\n const chakraSystemConfig = themeService?.systemConfig;\n restart({ locale: locale?.baseName, colorMode, chakraSystemConfig });\n };\n\n // Decide on locale and load i18n messages (if any).\n const i18n = (this.#i18n = await AppIntl.create({\n appMetadata: elementOptions.appMetadata,\n forcedLocale: config.locale,\n restrictSupportedLocales: config.supportedLocales,\n supportsLiveChanges: enableLiveLocaleChanges,\n restartWithLocale\n }));\n this.#checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.#appRoot = createAppRoot());\n this.#localeWatch = watchValue(\n () => i18n.locale.baseName,\n (locale) => {\n appRoot.lang = locale;\n },\n {\n immediate: true\n }\n );\n this.#container.appendChild(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 initialColorMode: config.colorMode,\n initialSystemConfig: config.chakraSystemConfig\n });\n this.#lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n const themeService = (this.#themeService = getInternalService<ThemeService>(\n serviceLayer,\n RUNTIME_THEME_SERVICE\n ));\n\n // init api, but do not wait for it\n const apiPromise = this.#initAPI(serviceLayer);\n this.#checkAbort();\n\n // Launch react\n this.#reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: computed(() => i18n.locale.baseName),\n config: computed(() => themeService.systemConfig),\n styles,\n colorMode: computed(() => themeService.colorMode)\n });\n const component = this.#options.elementOptions.component ?? EmptyComponent;\n this.#reactIntegration.render(createElement(component));\n\n // wait for api, to ensure that the \"started\" state is only reached after the API is available.\n // but do not block the react rendering, to allow for a fast Time to Interactive and to show potential errors in the UI even if the API fails.\n await apiPromise;\n this.#checkAbort();\n\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 #initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.#options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return constant(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.#stylesWatch = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n #initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n initialColorMode: ColorModeValue | \"system\" | undefined;\n initialSystemConfig: SystemConfig | undefined;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions } = this.#options;\n const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;\n\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n initialColorMode,\n initialSystemConfig,\n appIntl: i18n\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 async #initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = await apiService.getApi();\n this.#checkAbort();\n this.#api = api;\n LOG.debug(\"Application API initialized to\", api);\n this.#apiPromise?.resolve(api);\n } catch (e) {\n const ex = new Error(\n ErrorId.INTERNAL,\n \"Failed to gather the application's API methods.\",\n {\n cause: e\n }\n );\n if (!this.#apiPromise) {\n // no one is waiting yet.\n // keep the error for when they do\n this.#apiPromise = createManualPromise();\n // prevent unhandled rejection if no one is waiting for the API\n this.#apiPromise.promise.catch(() => {});\n }\n this.#apiPromise.reject(ex);\n throw ex;\n }\n }\n\n #triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.#lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n #checkAbort() {\n if (this.#state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n #showErrorScreen(error: globalThis.Error) {\n const userLocales = getBrowserLocales();\n const localePicker = new LocalePicker(\n Object.keys(MESSAGES_BY_LOCALE).map((tag) => parseLocale(tag))\n );\n const { locale, messageLocale } = localePicker.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale.baseName as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale.baseName, messages);\n\n const appRoot = (this.#appRoot = createAppRoot());\n appRoot.lang = locale.baseName;\n appRoot.classList.add(\"pioneer-root-error-screen\");\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n this.#reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.#rootNode,\n hostNode: this.#options.hostElement,\n appRoot: appRoot,\n locale: constant(locale.baseName),\n config: constant(this.#options.elementOptions.chakraSystemConfig),\n styles,\n colorMode: constant(DEFAULT_INITIAL_COLOR_MODE)\n });\n this.#reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\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_LOCALE_SERVICE\n },\n {\n interfaceName: RUNTIME_THEME_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"],"names":["themeService"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAwB1B,MAAM,WAAA,CAAY;AAAA,EACrB,QAAA;AAAA;AAAA,EAGA,WAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EAEA,MAAA,GAAmB,aAAA;AAAA,EACnB,SAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,KAAA;AAAA;AAAA;AAAA,EAIA,QAAA;AAAA;AAAA;AAAA;AAAA,EAIA,OAAA;AAAA,EAEA,aAAA;AAAA,EACA,gBAAA;AAAA,EACA,aAAA;AAAA,EACA,iBAAA;AAAA,EAEA,YAAA;AAAA,EACA,YAAA;AAAA,EAEA,YAA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AAI,QAAA,CAAS,GAAA,CAAI,CAAC,GAAA,KAAQ,CAAC,GAAA,CAAI,IAAA,EAAM,GAAG,CAAC,CAAC,CAAA;AAAA,IACxD;AAAA,GACJ;AACJ;AAEA,SAAS,kBAAA,CAAgC,cAA4B,aAAA,EAAuB;AACxF,EAAA,MAAM,SAAS,YAAA,CAAa,UAAA;AAAA,IACxB,uBAAA;AAAA,IACA;AAAA,MACI;AAAA,KACJ;AAAA,IACA,EAAE,wBAAwB,IAAA;AAAK,GACnC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,aAAa,CAAA,gBAAA,EAAmB,MAAA,CAAO,IAAI,CAAA,gEAAA;AAAA,KAE9E;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;;;"}
|
package/app/gatherConfig.js
CHANGED
package/app/gatherConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gatherConfig.js","sources":["gatherConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\n\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nexport async function gatherConfig(\n hostElement: HTMLElement,\n options: CustomElementOptions,\n overrides?: ApplicationOverrides\n): Promise<Required<ApplicationConfig>> {\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 overrides\n })) ?? {};\n\n configs = [\n {\n chakraSystemConfig: options.chakraSystemConfig\n },\n staticConfig,\n dynamicConfig\n ];\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) {\n if (overrides.locale) {\n merged.locale = overrides.locale;\n }\n if (overrides.colorMode) {\n merged.colorMode = overrides.colorMode;\n }\n if (overrides.chakraSystemConfig) {\n merged.chakraSystemConfig = overrides.chakraSystemConfig;\n }\n }\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 chakraSystemConfig: undefined,\n colorMode: 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"],"names":[],"mappings":";;;AAeA,eAAsB,YAAA,CAClB,WAAA,EACA,OAAA,EACA,SAAA,EACoC;AACpC,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACA,IAAA,MAAM,YAAA,GAAe,OAAA,CAAQ,MAAA,IAAU,EAAC;AACxC,IAAA,MAAM,aAAA,GACD,MAAM,OAAA,CAAQ,aAAA,GAAgB;AAAA,MAC3B,WAAA;AAAA,MACA,aAAa,IAAA,EAAM;AACf,QAAA,OAAO,WAAA,CAAY,YAAA,CAAa,IAAI,CAAA,IAAK,KAAA,CAAA;AAAA,MAC7C,CAAA;AAAA,MACA;AAAA,KACH,KAAM,EAAC;AA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AM,EAAC;AAC/D,MAAA,MAAA,CAAO,MAAA,CAAO,oBAAoB,iBAAiB,CAAA;AAAA,IACvD;AAAA,EACJ;AAEA,EAAA,OAAO,YAAA;AACX;;;;"}
|
|
1
|
+
{"version":3,"file":"gatherConfig.js","sources":["gatherConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\n\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nexport async function gatherConfig(\n hostElement: HTMLElement,\n options: CustomElementOptions,\n overrides?: ApplicationOverrides\n): Promise<Required<ApplicationConfig>> {\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 overrides\n })) ?? {};\n\n configs = [\n {\n chakraSystemConfig: options.chakraSystemConfig\n },\n staticConfig,\n dynamicConfig\n ];\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) {\n if (overrides.locale) {\n merged.locale = overrides.locale;\n }\n if (overrides.colorMode) {\n merged.colorMode = overrides.colorMode;\n }\n if (overrides.chakraSystemConfig) {\n merged.chakraSystemConfig = overrides.chakraSystemConfig;\n }\n }\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 supportedLocales: undefined,\n chakraSystemConfig: undefined,\n colorMode: 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"],"names":[],"mappings":";;;AAeA,eAAsB,YAAA,CAClB,WAAA,EACA,OAAA,EACA,SAAA,EACoC;AACpC,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACA,IAAA,MAAM,YAAA,GAAe,OAAA,CAAQ,MAAA,IAAU,EAAC;AACxC,IAAA,MAAM,aAAA,GACD,MAAM,OAAA,CAAQ,aAAA,GAAgB;AAAA,MAC3B,WAAA;AAAA,MACA,aAAa,IAAA,EAAM;AACf,QAAA,OAAO,WAAA,CAAY,YAAA,CAAa,IAAI,CAAA,IAAK,KAAA,CAAA;AAAA,MAC7C,CAAA;AAAA,MACA;AAAA,KACH,KAAM,EAAC;AAEZ,IAAA,OAAA,GAAU;AAAA,MACN;AAAA,QACI,oBAAoB,OAAA,CAAQ;AAAA,OAChC;AAAA,MACA,YAAA;AAAA,MACA;AAAA,KACJ;AAAA,EACJ,SAAS,CAAA,EAAG;AACR,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,wBAAA;AAAA,MACR,2CAAA;AAAA,MACA;AAAA,QACI,KAAA,EAAO;AAAA;AACX,KACJ;AAAA,EACJ;AAEA,EAAA,MAAM,MAAA,GAAS,aAAa,OAAO,CAAA;AACnC,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,IAAI,UAAU,MAAA,EAAQ;AAClB,MAAA,MAAA,CAAO,SAAS,SAAA,CAAU,MAAA;AAAA,IAC9B;AACA,IAAA,IAAI,UAAU,SAAA,EAAW;AACrB,MAAA,MAAA,CAAO,YAAY,SAAA,CAAU,SAAA;AAAA,IACjC;AACA,IAAA,IAAI,UAAU,kBAAA,EAAoB;AAC9B,MAAA,MAAA,CAAO,qBAAqB,SAAA,CAAU,kBAAA;AAAA,IAC1C;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX;AAMA,SAAS,aAAa,OAAA,EAA2D;AAE7E,EAAA,MAAM,eAA4C,MAAA,CAAO,MAAA;AAAA,IACrD;AAAA,MACI,MAAA,EAAQ,MAAA;AAAA,MACR,gBAAA,EAAkB,MAAA;AAAA,MAClB,kBAAA,EAAoB,MAAA;AAAA,MACpB,SAAA,EAAW,MAAA;AAAA,MACX,YAAY;AAAC,KACjB;AAAA,IACA,GAAG;AAAA,GACP;AAGA,EAAA,MAAM,gBAAA,GAA2C,YAAA,CAAa,UAAA,GAAa,EAAC;AAC5E,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC1B,IAAA,KAAA,MAAW,CAAC,WAAA,EAAa,iBAAiB,CAAA,IAAK,MAAA,CAAO,QAAQ,MAAA,CAAO,UAAA,IAAc,EAAE,CAAA,EAAG;AACpF,MAAA,MAAM,kBAAA,GAAsB,gBAAA,CAAiB,WAAW,CAAA,KAAM,EAAC;AAC/D,MAAA,MAAA,CAAO,MAAA,CAAO,oBAAoB,iBAAiB,CAAA;AAAA,IACvD;AAAA,EACJ;AAEA,EAAA,OAAO,YAAA;AACX;;;;"}
|
|
@@ -2,14 +2,14 @@ import { Error } from '@open-pioneer/core';
|
|
|
2
2
|
import { ErrorId } from '../errors.js';
|
|
3
3
|
|
|
4
4
|
class ApiServiceImpl {
|
|
5
|
-
providers;
|
|
5
|
+
#providers;
|
|
6
6
|
constructor(options) {
|
|
7
7
|
const providers = options.references.providers;
|
|
8
8
|
const meta = options.referencesMeta.providers;
|
|
9
|
-
this
|
|
9
|
+
this.#providers = providers.map((provider, index) => [meta[index].serviceId, provider]);
|
|
10
10
|
}
|
|
11
11
|
async getApi() {
|
|
12
|
-
const promises = this
|
|
12
|
+
const promises = this.#providers.map(async ([serviceId, provider]) => {
|
|
13
13
|
const methods = await provider.getApiMethods();
|
|
14
14
|
const result = {
|
|
15
15
|
serviceId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiServiceImpl.js","sources":["ApiServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ServiceOptions } from \"../Service\";\nimport { ApiExtension, ApiMethod, ApiMethods, ApiService } from \"../api\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\n\ninterface References {\n providers: ApiExtension[];\n}\n\nexport class ApiServiceImpl implements ApiService {\n
|
|
1
|
+
{"version":3,"file":"ApiServiceImpl.js","sources":["ApiServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ServiceOptions } from \"../Service\";\nimport { ApiExtension, ApiMethod, ApiMethods, ApiService } from \"../api\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\n\ninterface References {\n providers: ApiExtension[];\n}\n\nexport class ApiServiceImpl implements ApiService {\n readonly #providers: [serviceId: string, provider: ApiExtension][];\n\n constructor(options: ServiceOptions<References>) {\n const providers = options.references.providers;\n const meta = options.referencesMeta.providers;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#providers = providers.map((provider, index) => [meta[index]!.serviceId, provider]);\n }\n\n async getApi() {\n interface ProviderResult {\n serviceId: string;\n methods: ApiMethods;\n }\n\n const promises = this.#providers.map(async ([serviceId, provider]) => {\n const methods = await provider.getApiMethods();\n const result: ProviderResult = {\n serviceId,\n methods\n };\n return result;\n });\n const providerMethods = await Promise.all(promises);\n\n interface MethodEntry {\n method: ApiMethod;\n serviceId: string;\n }\n\n const methodEntries = new Map<string, MethodEntry>();\n for (const { serviceId, methods } of providerMethods) {\n for (const [methodName, method] of Object.entries(methods)) {\n const existingEntry = methodEntries.get(methodName);\n if (existingEntry) {\n throw new Error(\n ErrorId.DUPLICATE_API_METHODS,\n `Cannot define API method '${methodName}' from '${serviceId}' (method is also defined by '${existingEntry.serviceId}').`\n );\n }\n\n methodEntries.set(methodName, {\n serviceId,\n method\n });\n }\n }\n\n const api: Record<string, ApiMethod> = {};\n for (const [methodName, entry] of methodEntries.entries()) {\n api[methodName] = entry.method;\n }\n return api;\n }\n}\n"],"names":[],"mappings":";;;AAWO,MAAM,cAAA,CAAqC;AAAA,EACrC,UAAA;AAAA,EAET,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,SAAA,GAAY,QAAQ,UAAA,CAAW,SAAA;AACrC,IAAA,MAAM,IAAA,GAAO,QAAQ,cAAA,CAAe,SAAA;AAEpC,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA,CAAU,GAAA,CAAI,CAAC,QAAA,EAAU,KAAA,KAAU,CAAC,IAAA,CAAK,KAAK,CAAA,CAAG,SAAA,EAAW,QAAQ,CAAC,CAAA;AAAA,EAC3F;AAAA,EAEA,MAAM,MAAA,GAAS;AAMX,IAAA,MAAM,QAAA,GAAW,KAAK,UAAA,CAAW,GAAA,CAAI,OAAO,CAAC,SAAA,EAAW,QAAQ,CAAA,KAAM;AAClE,MAAA,MAAM,OAAA,GAAU,MAAM,QAAA,CAAS,aAAA,EAAc;AAC7C,MAAA,MAAM,MAAA,GAAyB;AAAA,QAC3B,SAAA;AAAA,QACA;AAAA,OACJ;AACA,MAAA,OAAO,MAAA;AAAA,IACX,CAAC,CAAA;AACD,IAAA,MAAM,eAAA,GAAkB,MAAM,OAAA,CAAQ,GAAA,CAAI,QAAQ,CAAA;AAOlD,IAAA,MAAM,aAAA,uBAAoB,GAAA,EAAyB;AACnD,IAAA,KAAA,MAAW,EAAE,SAAA,EAAW,OAAA,EAAQ,IAAK,eAAA,EAAiB;AAClD,MAAA,KAAA,MAAW,CAAC,UAAA,EAAY,MAAM,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AACxD,QAAA,MAAM,aAAA,GAAgB,aAAA,CAAc,GAAA,CAAI,UAAU,CAAA;AAClD,QAAA,IAAI,aAAA,EAAe;AACf,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,qBAAA;AAAA,YACR,6BAA6B,UAAU,CAAA,QAAA,EAAW,SAAS,CAAA,8BAAA,EAAiC,cAAc,SAAS,CAAA,GAAA;AAAA,WACvH;AAAA,QACJ;AAEA,QAAA,aAAA,CAAc,IAAI,UAAA,EAAY;AAAA,UAC1B,SAAA;AAAA,UACA;AAAA,SACH,CAAA;AAAA,MACL;AAAA,IACJ;AAEA,IAAA,MAAM,MAAiC,EAAC;AACxC,IAAA,KAAA,MAAW,CAAC,UAAA,EAAY,KAAK,CAAA,IAAK,aAAA,CAAc,SAAQ,EAAG;AACvD,MAAA,GAAA,CAAI,UAAU,IAAI,KAAA,CAAM,MAAA;AAAA,IAC5B;AACA,IAAA,OAAO,GAAA;AAAA,EACX;AACJ;;;;"}
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import { ApplicationContext } from "../api";
|
|
1
|
+
import { ApplicationContext, LocaleService } from "../api";
|
|
2
2
|
import { RootNode } from "../dom";
|
|
3
3
|
import { ServiceOptions } from "../Service";
|
|
4
4
|
export interface ApplicationContextProperties {
|
|
5
5
|
host: HTMLElement;
|
|
6
6
|
rootNode: RootNode;
|
|
7
7
|
container: HTMLElement;
|
|
8
|
-
locale: string;
|
|
9
|
-
supportedLocales: string[];
|
|
10
|
-
/** A callback to change the application's locale is injected by the runtime. */
|
|
11
|
-
changeLocale(locale: string): void;
|
|
12
8
|
}
|
|
9
|
+
interface ServiceReferences {
|
|
10
|
+
localeService: LocaleService;
|
|
11
|
+
}
|
|
12
|
+
export type ApplicationContextServiceOptions = ServiceOptions<ServiceReferences>;
|
|
13
13
|
export declare class ApplicationContextImpl implements ApplicationContext {
|
|
14
14
|
#private;
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(options: ApplicationContextServiceOptions, properties: ApplicationContextProperties);
|
|
16
16
|
getHostElement(): HTMLElement;
|
|
17
17
|
getRoot(): RootNode;
|
|
18
18
|
getShadowRoot(): ShadowRoot | undefined;
|
|
19
19
|
getApplicationContainer(): HTMLElement;
|
|
20
|
+
/** @deprecated Use `runtime.LocaleService` instead. */
|
|
20
21
|
getLocale(): string;
|
|
21
|
-
|
|
22
|
+
/** @deprecated Use `runtime.LocaleService` instead. */
|
|
23
|
+
setLocale(locale: string | undefined): void;
|
|
24
|
+
/** @deprecated Use `runtime.LocaleService` instead. */
|
|
22
25
|
getSupportedLocales(): readonly string[];
|
|
23
26
|
}
|
|
27
|
+
export {};
|