@open-pioneer/runtime 4.6.0 → 4.7.0-dev-locale-service.20260609154822
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/CustomElement.d.ts +28 -2
- package/CustomElement.js +1 -1
- package/CustomElement.js.map +1 -1
- package/_virtual/source-info.js +7 -5
- package/_virtual/source-info.js.map +1 -1
- package/api.d.ts +71 -0
- package/api.js +4 -1
- package/api.js.map +1 -1
- package/app/AppInstance.js +38 -33
- package/app/AppInstance.js.map +1 -1
- package/app/gatherConfig.js +1 -0
- package/app/gatherConfig.js.map +1 -1
- package/builtin-services/ApplicationContextImpl.d.ts +11 -7
- package/builtin-services/ApplicationContextImpl.js +28 -11
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js +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 +18 -13
- package/builtin-services/NumberParserServiceImpl.js.map +1 -1
- package/builtin-services/index.d.ts +3 -1
- package/builtin-services/index.js +32 -3
- package/builtin-services/index.js.map +1 -1
- package/i18n/AppIntl.d.ts +43 -5
- package/i18n/AppIntl.js +140 -52
- package/i18n/AppIntl.js.map +1 -1
- package/i18n/Locale.d.ts +92 -0
- package/i18n/Locale.js +179 -0
- package/i18n/Locale.js.map +1 -0
- package/i18n/index.d.ts +2 -1
- package/i18n/pick.d.ts +24 -16
- package/i18n/pick.js +92 -38
- package/i18n/pick.js.map +1 -1
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/react-integration/ChakraProvider.d.ts +3 -2
- package/react-integration/ChakraProvider.js +3 -2
- package/react-integration/ChakraProvider.js.map +1 -1
- package/react-integration/ReactIntegration.d.ts +1 -1
- package/react-integration/ReactIntegration.js.map +1 -1
- package/service-layer/ServiceLayer.js +1 -1
package/CHANGELOG.md
CHANGED
package/CustomElement.d.ts
CHANGED
|
@@ -84,13 +84,24 @@ export interface ApplicationOverrides {
|
|
|
84
84
|
*/
|
|
85
85
|
export interface ApplicationConfig {
|
|
86
86
|
/**
|
|
87
|
-
* Set this value to a locale string
|
|
87
|
+
* Set this value to a locale (BCP-47 string, e.g. `"en"`) to set the default message locale of the application.
|
|
88
|
+
*
|
|
88
89
|
* The default behavior is to choose an appropriate locale for the current user based
|
|
89
90
|
* on the browser's settings.
|
|
90
91
|
*
|
|
91
|
-
*
|
|
92
|
+
* This locale should match one of the supported message locales defined by the application's package.
|
|
92
93
|
*/
|
|
93
94
|
locale?: string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* The list of locales supported by the application.
|
|
97
|
+
*
|
|
98
|
+
* This allows a further restriction of the locales supported by the application, compared to the ones defined by the application's package.
|
|
99
|
+
* It is not possible to extend the supported locales defined by the package, only to restrict them.
|
|
100
|
+
* If this property is not set, then the application supports all locales defined by the build.config.mjs of the application's package.
|
|
101
|
+
* If the values are not a valid subset of the application package supported locales, then the application will throw an error at startup.
|
|
102
|
+
* An empty array will disable loading of any message bundle.
|
|
103
|
+
*/
|
|
104
|
+
supportedLocales?: string[] | undefined;
|
|
94
105
|
/**
|
|
95
106
|
* Configures the application's initial color mode.
|
|
96
107
|
*
|
|
@@ -160,6 +171,21 @@ export interface AdvancedCustomElementOptions {
|
|
|
160
171
|
* ensure that your components work in that setting.
|
|
161
172
|
*/
|
|
162
173
|
enableShadowRoot?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* If `true`, calls to `runtime.LocaleService.setLocale` apply the new locale
|
|
176
|
+
* in place: the new message bundle is loaded first, then `locale`,
|
|
177
|
+
* `messageLocale` and all `PackageIntl` instances are updated atomically
|
|
178
|
+
* — without restarting the application.
|
|
179
|
+
*
|
|
180
|
+
* If `false` (default), `setLocale` triggers a full application restart
|
|
181
|
+
* with the new locale (legacy behavior).
|
|
182
|
+
*
|
|
183
|
+
* Reactive switching avoids the cost of a restart but requires that all
|
|
184
|
+
* UI code reads i18n through reactive APIs (e.g. `useIntl`,
|
|
185
|
+
* `useReactiveSnapshot`). Components that capture `intl` or `locale` once
|
|
186
|
+
* at construction time will not pick up the change.
|
|
187
|
+
*/
|
|
188
|
+
enableLocaleReactiveSwitching?: boolean;
|
|
163
189
|
}
|
|
164
190
|
/**
|
|
165
191
|
* The class returned by a call to {@link createCustomElement}.
|
package/CustomElement.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
-
import { sourceId$
|
|
2
|
+
import { sourceId$7 as sourceId } from './_virtual/source-info.js';
|
|
3
3
|
import { AppInstance } from './app/AppInstance.js';
|
|
4
4
|
import { ErrorId } from './errors.js';
|
|
5
5
|
|
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 { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ComponentType } from \"react\";\nimport { type ApiMethods, type ColorModeValue, type ApiExtension } from \"./api\";\nimport { AppInstance } from \"./app\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata } from \"./metadata\";\n\nconst LOG = createLogger(sourceId);\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 * Defined when the application forcefully restarts with new options.\n */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Application overrides are defined when the is explicitly being restarted with new options.\n *\n * Options set through overrides cannot be overwritten by the `resolveConfig` hook.\n */\nexport interface ApplicationOverrides {\n /**\n * The new application locale.\n */\n locale?: string;\n\n /**\n * The new color mode.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * The new used chakra system config.\n */\n chakraSystemConfig?: ChakraSystemConfig;\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 * Configures the application's initial color mode.\n *\n * Use `system` to use the user's preferred color mode, derived from the browser or operating system.\n *\n * Default: `light`.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n *\n * NOTE: This setting has priority over {@link CustomElementOptions.chakraSystemConfig}.\n */\n chakraSystemConfig?: ChakraSystemConfig;\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?: 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 AppInstance({\n rootNode: this.#shadowRoot ?? document,\n hostElement: this,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n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|
|
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 { sourceId } from \"open-pioneer:source-info\";\nimport { ComponentType } from \"react\";\nimport { type ApiMethods, type ColorModeValue, type ApiExtension } from \"./api\";\nimport { AppInstance } from \"./app\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata } from \"./metadata\";\n\nconst LOG = createLogger(sourceId);\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 * Defined when the application forcefully restarts with new options.\n */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Application overrides are defined when the is explicitly being restarted with new options.\n *\n * Options set through overrides cannot be overwritten by the `resolveConfig` hook.\n */\nexport interface ApplicationOverrides {\n /**\n * The new application locale.\n */\n locale?: string;\n\n /**\n * The new color mode.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * The new used chakra system config.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n}\n\n/**\n * Runtime application configuration.\n */\nexport interface ApplicationConfig {\n /**\n * Set this value to a locale (BCP-47 string, e.g. `\"en\"`) to set the default message locale of the application.\n *\n * The default behavior is to choose an appropriate locale for the current user based\n * on the browser's settings.\n *\n * This locale should match one of the supported message locales defined by the application's package.\n */\n locale?: string | undefined;\n\n /**\n * The list of locales supported by the application.\n *\n * This allows a further restriction of the locales supported by the application, compared to the ones defined by the application's package.\n * It is not possible to extend the supported locales defined by the package, only to restrict them.\n * If this property is not set, then the application supports all locales defined by the build.config.mjs of the application's package.\n * If the values are not a valid subset of the application package supported locales, then the application will throw an error at startup.\n * An empty array will disable loading of any message bundle.\n */\n supportedLocales?: string[] | undefined;\n\n /**\n * Configures the application's initial color mode.\n *\n * Use `system` to use the user's preferred color mode, derived from the browser or operating system.\n *\n * Default: `light`.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n *\n * NOTE: This setting has priority over {@link CustomElementOptions.chakraSystemConfig}.\n */\n chakraSystemConfig?: ChakraSystemConfig;\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 * If `true`, calls to `runtime.LocaleService.setLocale` apply the new locale\n * in place: the new message bundle is loaded first, then `locale`,\n * `messageLocale` and all `PackageIntl` instances are updated atomically\n * — without restarting the application.\n *\n * If `false` (default), `setLocale` triggers a full application restart\n * with the new locale (legacy behavior).\n *\n * Reactive switching avoids the cost of a restart but requires that all\n * UI code reads i18n through reactive APIs (e.g. `useIntl`,\n * `useReactiveSnapshot`). Components that capture `intl` or `locale` once\n * at construction time will not pick up the change.\n */\n enableLocaleReactiveSwitching?: 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?: 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 AppInstance({\n rootNode: this.#shadowRoot ?? document,\n hostElement: this,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n });\n }\n }\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/source-info.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
const sourceId$
|
|
1
|
+
const sourceId$7 = "@open-pioneer/runtime/i18n/AppIntl";
|
|
2
2
|
|
|
3
|
-
const sourceId$
|
|
3
|
+
const sourceId$6 = "@open-pioneer/runtime/i18n/pick";
|
|
4
4
|
|
|
5
|
-
const sourceId$
|
|
5
|
+
const sourceId$5 = "@open-pioneer/runtime/CustomElement";
|
|
6
6
|
|
|
7
|
-
const sourceId$
|
|
7
|
+
const sourceId$4 = "@open-pioneer/runtime/app/AppInstance";
|
|
8
|
+
|
|
9
|
+
const sourceId$3 = "@open-pioneer/runtime/builtin-services/ApplicationContextImpl";
|
|
8
10
|
|
|
9
11
|
const sourceId$2 = "@open-pioneer/runtime/builtin-services/ApplicationLifecycleEventService";
|
|
10
12
|
|
|
@@ -12,5 +14,5 @@ const sourceId$1 = "@open-pioneer/runtime/builtin-services/NumberParserServiceIm
|
|
|
12
14
|
|
|
13
15
|
const sourceId = "@open-pioneer/runtime/service-layer/ServiceLayer";
|
|
14
16
|
|
|
15
|
-
export { sourceId$
|
|
17
|
+
export { sourceId$6 as sourceId, sourceId$7 as sourceId$1, sourceId$3 as sourceId$2, sourceId$2 as sourceId$3, sourceId$1 as sourceId$4, sourceId as sourceId$5, sourceId$4 as sourceId$6, sourceId$5 as sourceId$7 };
|
|
16
18
|
//# sourceMappingURL=source-info.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
package/api.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type SystemConfig as ChakraSystemConfig } from "@chakra-ui/react";
|
|
2
2
|
import { type DeclaredService } from "./DeclaredService";
|
|
3
|
+
import { type Locale } from "./i18n";
|
|
4
|
+
export { Locale } from "./i18n";
|
|
3
5
|
export type ApiMethod = (...args: any[]) => any;
|
|
4
6
|
/**
|
|
5
7
|
* A record of exposed functions.
|
|
@@ -72,6 +74,8 @@ export interface ApplicationContext extends DeclaredService<"runtime.Application
|
|
|
72
74
|
* Returns the current locale of the application.
|
|
73
75
|
*
|
|
74
76
|
* E.g. `"de-DE"`
|
|
77
|
+
*
|
|
78
|
+
* @deprecated Use {@link LocaleService.locale} instead.
|
|
75
79
|
*/
|
|
76
80
|
getLocale(): string;
|
|
77
81
|
/**
|
|
@@ -81,6 +85,8 @@ export interface ApplicationContext extends DeclaredService<"runtime.Application
|
|
|
81
85
|
*
|
|
82
86
|
* > NOTE: This method will currently trigger a full restart of the application.
|
|
83
87
|
* > Altering the locale on the fly is possible in theory but has not been implemented yet.
|
|
88
|
+
*
|
|
89
|
+
* @deprecated Use {@link LocaleService.setLocale} instead.
|
|
84
90
|
*/
|
|
85
91
|
setLocale(locale: string | undefined): void;
|
|
86
92
|
/**
|
|
@@ -88,9 +94,74 @@ export interface ApplicationContext extends DeclaredService<"runtime.Application
|
|
|
88
94
|
* the locales that have associated i18n messages.
|
|
89
95
|
*
|
|
90
96
|
* For example: `["de", "en"]`
|
|
97
|
+
* @deprecated Use {@link LocaleService.supportedMessageLocales} instead.
|
|
91
98
|
*/
|
|
92
99
|
getSupportedLocales(): readonly string[];
|
|
93
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* A service to inspect and control the application's active locale.
|
|
103
|
+
*
|
|
104
|
+
* The properties `locale` and `messageLocale` are reactive (powered by
|
|
105
|
+
* `@conterra/reactivity-core`) and can be observed with `useReactiveSnapshot`
|
|
106
|
+
* inside React components.
|
|
107
|
+
*
|
|
108
|
+
* ### `locale` vs `messageLocale`
|
|
109
|
+
*
|
|
110
|
+
* - {@link locale} is the locale used for `Intl`-based formatting
|
|
111
|
+
* (numbers, dates, relative time, ...). It tracks the user's preferred locale
|
|
112
|
+
* precisely, e.g. `de-AT`.
|
|
113
|
+
* - {@link messageLocale} is the locale of the currently loaded message bundle.
|
|
114
|
+
* It is always one of {@link supportedMessageLocales}, e.g. `de`. A language
|
|
115
|
+
* toggler should use this value to highlight the active button.
|
|
116
|
+
*
|
|
117
|
+
* ### Reactive switching
|
|
118
|
+
*
|
|
119
|
+
* By default, {@link setLocale} triggers a full application restart. When the
|
|
120
|
+
* application opts in by setting `enableLocaleReactiveSwitching` in the
|
|
121
|
+
* {@link AdvancedCustomElementOptions}, the locale is updated in place: the new
|
|
122
|
+
* message bundle is loaded first, then `locale`, `messageLocale` and all
|
|
123
|
+
* `PackageIntl` instances are updated atomically.
|
|
124
|
+
*
|
|
125
|
+
* Watching `messageLocale` is therefore the canonical way to detect that a
|
|
126
|
+
* locale switch has fully completed (the value updates only after the new
|
|
127
|
+
* messages have loaded).
|
|
128
|
+
*/
|
|
129
|
+
export interface LocaleService extends DeclaredService<"runtime.LocaleService"> {
|
|
130
|
+
/**
|
|
131
|
+
* Reactive: the active locale used for Intl-based formatting.
|
|
132
|
+
* This locale may not match any of the supported message locales,
|
|
133
|
+
* but it always tracks the user's preferred locale as closely as possible (e.g. `de-AT` instead of `de` if `de-AT` is supported).
|
|
134
|
+
*/
|
|
135
|
+
readonly locale: Locale;
|
|
136
|
+
/**
|
|
137
|
+
* Reactive: the active message bundle locale.
|
|
138
|
+
* If supportedMessageLocales is empty, this falls back to `en`.
|
|
139
|
+
*/
|
|
140
|
+
readonly messageLocale: Locale;
|
|
141
|
+
/**
|
|
142
|
+
* Locales for which the application has translated messages.
|
|
143
|
+
* This list may be empty, if the application has no message bundles.
|
|
144
|
+
*/
|
|
145
|
+
readonly supportedMessageLocales: readonly Locale[];
|
|
146
|
+
/**
|
|
147
|
+
* Read-only mirror of the resolved reactive-switching setting,
|
|
148
|
+
* see {@link AdvancedCustomElementOptions.enableLocaleReactiveSwitching}.
|
|
149
|
+
*/
|
|
150
|
+
readonly isReactiveSwitching: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Switches to the given locale.
|
|
153
|
+
*
|
|
154
|
+
* - Pass a {@link Locale} or `undefined` to re-pick from the user's browser
|
|
155
|
+
* preference.
|
|
156
|
+
* - In reactive-switching mode the change applies in place. Otherwise the
|
|
157
|
+
* application restarts.
|
|
158
|
+
*/
|
|
159
|
+
setLocale(locale: Locale | undefined): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Returns `true` if it is supported by the application and useable in setLocale.
|
|
162
|
+
*/
|
|
163
|
+
supportsLocale(locale: Locale): boolean;
|
|
164
|
+
}
|
|
94
165
|
/**
|
|
95
166
|
* Implementing this interface allows a service to be notified on certain
|
|
96
167
|
* application-wide lifecycle events.
|
package/api.js
CHANGED
package/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"api.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
package/app/AppInstance.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { computed, reactive, effect } from '@conterra/reactivity-core';
|
|
1
|
+
import { computed, constant, reactive, effect } from '@conterra/reactivity-core';
|
|
2
2
|
import { createLogger, Error, createAbortError, destroyResource, createManualPromise, throwAbortError } from '@open-pioneer/core';
|
|
3
|
-
import { sourceId$
|
|
3
|
+
import { sourceId$6 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
9
|
import { initI18n } from '../i18n/AppIntl.js';
|
|
10
|
+
import { Locale } from '../i18n/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';
|
|
@@ -92,9 +93,23 @@ class AppInstance {
|
|
|
92
93
|
const config = this.config = await gatherConfig(hostElement, elementOptions, overrides);
|
|
93
94
|
this.checkAbort();
|
|
94
95
|
LOG.debug("Application config is", config);
|
|
95
|
-
const
|
|
96
|
+
const reactiveSwitching = elementOptions.advanced?.enableLocaleReactiveSwitching ?? false;
|
|
97
|
+
const restartWithLocale = (locale) => {
|
|
98
|
+
const restart = this.options.restart;
|
|
99
|
+
const themeService2 = this.themeService;
|
|
100
|
+
const colorMode = themeService2?.colorMode;
|
|
101
|
+
const chakraSystemConfig = themeService2?.systemConfig;
|
|
102
|
+
restart({ locale: locale?.tag, colorMode, chakraSystemConfig });
|
|
103
|
+
};
|
|
104
|
+
const i18n = this.i18n = await initI18n({
|
|
105
|
+
appMetadata: elementOptions.appMetadata,
|
|
106
|
+
forcedLocale: config.locale,
|
|
107
|
+
restrictSupportedLocales: config.supportedLocales,
|
|
108
|
+
reactiveSwitching,
|
|
109
|
+
restartWithLocale
|
|
110
|
+
});
|
|
96
111
|
this.checkAbort();
|
|
97
|
-
const appRoot = this.appRoot = createAppRoot(i18n.locale);
|
|
112
|
+
const appRoot = this.appRoot = createAppRoot(i18n.locale.tag);
|
|
98
113
|
this.container.appendChild(appRoot);
|
|
99
114
|
const styles = this.initStylesSignal();
|
|
100
115
|
const { serviceLayer, packages } = this.initServiceLayer({
|
|
@@ -120,7 +135,7 @@ class AppInstance {
|
|
|
120
135
|
appRoot,
|
|
121
136
|
serviceLayer,
|
|
122
137
|
packages,
|
|
123
|
-
locale: i18n.locale,
|
|
138
|
+
locale: computed(() => i18n.locale.tag),
|
|
124
139
|
config: computed(() => themeService.systemConfig),
|
|
125
140
|
styles,
|
|
126
141
|
colorMode: computed(() => themeService.colorMode)
|
|
@@ -141,7 +156,7 @@ class AppInstance {
|
|
|
141
156
|
initStylesSignal() {
|
|
142
157
|
const stylesBox = this.options.elementOptions.appMetadata?.styles;
|
|
143
158
|
if (!stylesBox) {
|
|
144
|
-
return
|
|
159
|
+
return constant("");
|
|
145
160
|
}
|
|
146
161
|
const signal = reactive(stylesBox.value);
|
|
147
162
|
if (import.meta.hot) {
|
|
@@ -156,7 +171,7 @@ class AppInstance {
|
|
|
156
171
|
return signal;
|
|
157
172
|
}
|
|
158
173
|
initServiceLayer(config) {
|
|
159
|
-
const { hostElement, rootNode: shadowRoot, elementOptions
|
|
174
|
+
const { hostElement, rootNode: shadowRoot, elementOptions } = this.options;
|
|
160
175
|
const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;
|
|
161
176
|
const packageMetadata = elementOptions.appMetadata?.packages ?? {};
|
|
162
177
|
const builtinPackage = createBuiltinPackage({
|
|
@@ -165,22 +180,7 @@ class AppInstance {
|
|
|
165
180
|
container,
|
|
166
181
|
initialColorMode,
|
|
167
182
|
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
|
-
}
|
|
183
|
+
appIntl: i18n
|
|
184
184
|
});
|
|
185
185
|
const { serviceLayer, packages } = createServiceLayer({
|
|
186
186
|
packageMetadata,
|
|
@@ -230,11 +230,13 @@ class AppInstance {
|
|
|
230
230
|
}
|
|
231
231
|
showErrorScreen(error) {
|
|
232
232
|
const userLocales = getBrowserLocales();
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
const
|
|
233
|
+
const localePicker = new LocalePicker(
|
|
234
|
+
Object.keys(MESSAGES_BY_LOCALE).map((tag) => Locale.parse(tag))
|
|
235
|
+
);
|
|
236
|
+
const { locale, messageLocale } = localePicker.pickSupportedLocale(void 0, userLocales);
|
|
237
|
+
const messages = MESSAGES_BY_LOCALE[messageLocale.tag] ?? MESSAGES_BY_LOCALE["en"];
|
|
238
|
+
const intl = createPackageIntl(locale.tag, messages);
|
|
239
|
+
const appRoot = this.appRoot = createAppRoot(locale.tag);
|
|
238
240
|
appRoot.classList.add("pioneer-root-error-screen");
|
|
239
241
|
this.container.appendChild(appRoot);
|
|
240
242
|
const styles = this.initStylesSignal();
|
|
@@ -242,10 +244,10 @@ class AppInstance {
|
|
|
242
244
|
rootNode: this.rootNode,
|
|
243
245
|
hostNode: this.options.hostElement,
|
|
244
246
|
appRoot,
|
|
245
|
-
locale,
|
|
246
|
-
config:
|
|
247
|
+
locale: constant(locale.tag),
|
|
248
|
+
config: constant(this.options.elementOptions.chakraSystemConfig),
|
|
247
249
|
styles,
|
|
248
|
-
colorMode:
|
|
250
|
+
colorMode: constant(DEFAULT_INITIAL_COLOR_MODE)
|
|
249
251
|
});
|
|
250
252
|
this.reactIntegration.render(createElement(ErrorScreen, { intl, error }));
|
|
251
253
|
}
|
|
@@ -274,6 +276,9 @@ function createServiceLayer(config) {
|
|
|
274
276
|
{
|
|
275
277
|
interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE
|
|
276
278
|
},
|
|
279
|
+
{
|
|
280
|
+
interfaceName: RUNTIME_LOCALE_SERVICE
|
|
281
|
+
},
|
|
277
282
|
{
|
|
278
283
|
interfaceName: RUNTIME_THEME_SERVICE
|
|
279
284
|
},
|
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;AAAA,EACb,OAAA;AAAA;AAAA,EAGA,UAAA;AAAA;AAAA,EACA,GAAA;AAAA;AAAA,EAEA,KAAA,GAAkB,aAAA;AAAA,EAClB,QAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,OAAA;AAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,gBAAA;AAAA,EAEA,WAAA;AAAA,EAER,YAAY,OAAA,EAAqB;AAC7B,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,YAAY,YAAA,CAAa,OAAA,CAAQ,QAAQ,CAAA,GAAI,OAAA,CAAQ,WAAW,OAAA,CAAQ,WAAA;AAC7E,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AAAA,EAC5B;AAAA,EAEA,KAAA,GAAQ;AACJ,IAAA,IAAI,IAAA,CAAK,UAAU,aAAA,EAAe;AAC9B,MAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,UAAU,CAAA,+BAAA,EAAkC,IAAA,CAAK,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA,IACrF;AAEA,IAAA,IAAA,CAAK,KAAA,GAAQ,UAAA;AACb,IAAA,IAAA,CAAK,SAAA,EAAU,CAAE,KAAA,CAAM,CAAC,CAAA,KAAM;AAC1B,MAAA,IAAI,IAAA,CAAK,UAAU,WAAA,EAAa;AAEhC,MAAA,QAAA,CAAS,CAAC,CAAA;AACV,MAAA,IAAA,CAAK,KAAA,EAAM;AACX,MAAA,IAAA,CAAK,KAAA,GAAQ,OAAA;AACb,MAAA,IAAA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AS,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;;;;"}
|
|
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, constant, 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_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 {\n AppIntl,\n createPackageIntl,\n getBrowserLocales,\n LocalePicker,\n initI18n,\n Locale\n} 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 const reactiveSwitching = elementOptions.advanced?.enableLocaleReactiveSwitching ?? false;\n\n const restartWithLocale = (locale: Locale | undefined) => {\n // this code is triggered, when the app calls setLocale 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?.tag, colorMode, chakraSystemConfig });\n };\n\n // Decide on locale and load i18n messages (if any).\n const i18n = (this.i18n = await initI18n({\n appMetadata: elementOptions.appMetadata,\n forcedLocale: config.locale,\n restrictSupportedLocales: config.supportedLocales,\n reactiveSwitching,\n restartWithLocale\n }));\n this.checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.appRoot = createAppRoot(i18n.locale.tag));\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: computed(() => i18n.locale.tag),\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 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 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 } = 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 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 localePicker = new LocalePicker(\n Object.keys(MESSAGES_BY_LOCALE).map((tag) => Locale.parse(tag))\n );\n const { locale, messageLocale } = localePicker.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale.tag as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale.tag, messages);\n\n const appRoot = (this.appRoot = createAppRoot(locale.tag));\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.tag),\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,EACb,OAAA;AAAA;AAAA,EAGA,UAAA;AAAA;AAAA,EACA,GAAA;AAAA;AAAA,EAEA,KAAA,GAAkB,aAAA;AAAA,EAClB,QAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,OAAA;AAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,gBAAA;AAAA,EAEA,WAAA;AAAA,EAER,YAAY,OAAA,EAAqB;AAC7B,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,YAAY,YAAA,CAAa,OAAA,CAAQ,QAAQ,CAAA,GAAI,OAAA,CAAQ,WAAW,OAAA,CAAQ,WAAA;AAC7E,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AAAA,EAC5B;AAAA,EAEA,KAAA,GAAQ;AACJ,IAAA,IAAI,IAAA,CAAK,UAAU,aAAA,EAAe;AAC9B,MAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,UAAU,CAAA,+BAA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IAAA,QAAA,CAAS,KAAK,cAAc,CAAA;AAAA,EAChC;AAGA,EAAA,MAAM,gBAAA,GAAoC;AAAA,IACtC;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe,kBAAA;AAAA,MACf,GAAA,EAAK;AAAA;AACT,GACJ;AACA,EAAA,MAAM,YAAA,GAAe,IAAI,YAAA,CAAa,QAAA,EAAU,gBAAgB,CAAA;AAChE,EAAA,OAAO;AAAA,IACH,QAAA,EAAU,IAAI,GAAA,CAAI,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] ??=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C,MAAA,CAAO,MAAA;AAAA,IACrD;AAAA,MACI,MAAA,EAAQ,MAAA;AAAA,MACR,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;;;;"}
|
|
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,OA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MAAA,CAAO,MAAA,CAAO,oBAAoB,iBAAiB,CAAA;AAAA,IACvD;AAAA,EACJ;AAEA,EAAA,OAAO,YAAA;AACX;;;;"}
|
|
@@ -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 {};
|