@open-pioneer/runtime 4.5.0 → 4.6.0-dev-i18n.20260518080633

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @open-pioneer/runtime
2
2
 
3
+ ## 4.6.0-dev-i18n.20260518080633
4
+
5
+ ### Minor Changes
6
+
7
+ - 47fa6bd: Deprecate `serviceOptions.intl`. Use `serviceOptions.currentIntl` instead.
8
+ The new interface supports updating `intl` messages at runtime.
9
+ - f3f3de7: Support for hot reloading of i18n messages (requires updated vite plugin).
10
+ When i18n messages are updated:
11
+ - React components rerender automatically with new `intl` object returned by `useIntl()`.
12
+ - Services that use the new `serviceOptions.currentIntl` interface also receive a new `intl` object (if they are watching for changes).
13
+ - Services that that still use the deprecated `serviceOptions.intl` interface cause the application to reload instead.
14
+
3
15
  ## 4.5.0
4
16
 
5
17
  ### Minor Changes
package/Service.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ReadonlyReactive } from "@conterra/reactivity-core";
1
2
  import { PackageIntl } from "./i18n";
2
3
  /** Lifecycle hooks supported by the service interface. */
3
4
  export interface ServiceLifecycleHooks {
@@ -51,9 +52,18 @@ export type ServiceOptions<References extends {} = {}> = {
51
52
  */
52
53
  properties: Record<string, unknown>;
53
54
  /**
54
- * A reference to the shared i18n object of the current package.
55
+ * A constant reference to the shared i18n object of the current package.
56
+ *
57
+ * @deprecated use `currentIntl` instead, which is a signal that returns the current i18n object and updates when it changes at runtime. Be aware to implement a watch for yourself
55
58
  */
56
59
  intl: PackageIntl;
60
+ /**
61
+ * A signal that returns the current i18n object of the service's package.
62
+ *
63
+ * The i18n object may change at runtime (for example to implement hot reloading during development,
64
+ * or to implement language changes while the application is running).
65
+ */
66
+ currentIntl: ReadonlyReactive<PackageIntl>;
57
67
  };
58
68
  /**
59
69
  * A service constructor returns a service instance when calling `new`.
@@ -26,6 +26,7 @@ export declare class AppInstance {
26
26
  private container;
27
27
  private appRoot;
28
28
  private config;
29
+ private i18n;
29
30
  private serviceLayer;
30
31
  private lifecycleEvents;
31
32
  private themeService;
@@ -31,6 +31,7 @@ class AppInstance {
31
31
  appRoot;
32
32
  // .pioneer-root
33
33
  config;
34
+ i18n;
34
35
  serviceLayer;
35
36
  lifecycleEvents;
36
37
  themeService;
@@ -74,6 +75,7 @@ class AppInstance {
74
75
  this.appRoot = void 0;
75
76
  this.lifecycleEvents = void 0;
76
77
  this.themeService = void 0;
78
+ this.i18n = destroyResource(this.i18n);
77
79
  this.serviceLayer = destroyResource(this.serviceLayer);
78
80
  this.stylesWatch = destroyResource(this.stylesWatch);
79
81
  }
@@ -90,7 +92,7 @@ class AppInstance {
90
92
  const config = this.config = await gatherConfig(hostElement, elementOptions, overrides);
91
93
  this.checkAbort();
92
94
  LOG.debug("Application config is", config);
93
- const i18n = await initI18n(elementOptions.appMetadata, config.locale);
95
+ const i18n = this.i18n = await initI18n(elementOptions.appMetadata, config.locale);
94
96
  this.checkAbort();
95
97
  const appRoot = this.appRoot = createAppRoot(i18n.locale);
96
98
  this.container.appendChild(appRoot);
@@ -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 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.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 = 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,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,GA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AAA,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;;;;"}
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,UAA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AA,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,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;;;;"}
@@ -3,6 +3,7 @@ import { createEmptyPackageIntl } from '../i18n/PackageIntl.js';
3
3
  import '../i18n/pick.js';
4
4
  import { PackageRepr } from '../service-layer/PackageRepr.js';
5
5
  import { ServiceRepr, createConstructorFactory, createFunctionFactory } from '../service-layer/ServiceRepr.js';
6
+ import { reactiveConstant } from '../utils/reactive-constant.js';
6
7
  import { ApiServiceImpl } from './ApiServiceImpl.js';
7
8
  import { ApplicationContextImpl } from './ApplicationContextImpl.js';
8
9
  import { ApplicationLifecycleEventService } from './ApplicationLifecycleEventService.js';
@@ -18,12 +19,12 @@ const RUNTIME_NUMBER_PARSER_SERVICE = "runtime.NumberParserService";
18
19
  const RUNTIME_AUTO_START = "runtime.AutoStart";
19
20
  const RUNTIME_THEME_SERVICE = "runtime.ThemeService";
20
21
  function createBuiltinPackage(properties) {
21
- const i18n = createEmptyPackageIntl();
22
+ const intl = createEmptyPackageIntl();
22
23
  const apiService = new ServiceRepr({
23
24
  name: "ApiServiceImpl",
24
25
  packageName: RUNTIME_PACKAGE_NAME,
25
26
  factory: createConstructorFactory(ApiServiceImpl),
26
- intl: i18n,
27
+ intl: reactiveConstant(intl),
27
28
  interfaces: [
28
29
  {
29
30
  interfaceName: RUNTIME_API_SERVICE,
@@ -44,7 +45,7 @@ function createBuiltinPackage(properties) {
44
45
  factory: createFunctionFactory(
45
46
  (options) => new ApplicationContextImpl(options, properties)
46
47
  ),
47
- intl: i18n,
48
+ intl: reactiveConstant(intl),
48
49
  interfaces: [
49
50
  {
50
51
  interfaceName: RUNTIME_APPLICATION_CONTEXT,
@@ -56,7 +57,7 @@ function createBuiltinPackage(properties) {
56
57
  name: "ApplicationLifecycleEventServiceImpl",
57
58
  packageName: RUNTIME_PACKAGE_NAME,
58
59
  factory: createConstructorFactory(ApplicationLifecycleEventService),
59
- intl: i18n,
60
+ intl: reactiveConstant(intl),
60
61
  interfaces: [
61
62
  {
62
63
  interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,
@@ -77,7 +78,7 @@ function createBuiltinPackage(properties) {
77
78
  factory: createFunctionFactory(
78
79
  (options) => new NumberParserServiceImpl(options, properties.locale)
79
80
  ),
80
- intl: i18n,
81
+ intl: reactiveConstant(intl),
81
82
  interfaces: [
82
83
  {
83
84
  interfaceName: RUNTIME_NUMBER_PARSER_SERVICE,
@@ -89,7 +90,7 @@ function createBuiltinPackage(properties) {
89
90
  name: "ThemeServiceImpl",
90
91
  packageName: RUNTIME_PACKAGE_NAME,
91
92
  factory: createFunctionFactory(() => new ThemeServiceImpl(properties)),
92
- intl: i18n,
93
+ intl: reactiveConstant(intl),
93
94
  interfaces: [
94
95
  {
95
96
  interfaceName: RUNTIME_THEME_SERVICE,
@@ -113,7 +114,7 @@ function createBuiltinPackage(properties) {
113
114
  numberParserService,
114
115
  themeService
115
116
  ],
116
- intl: i18n
117
+ intl: reactiveConstant(intl)
117
118
  });
118
119
  }
119
120
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createEmptyPackageIntl } from \"../i18n\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport {\n createConstructorFactory,\n createFunctionFactory,\n ServiceRepr\n} from \"../service-layer/ServiceRepr\";\nimport { ApiServiceImpl } from \"./ApiServiceImpl\";\nimport { ApplicationContextImpl, ApplicationContextProperties } from \"./ApplicationContextImpl\";\nimport { ApplicationLifecycleEventService } from \"./ApplicationLifecycleEventService\";\nimport { NumberParserServiceImpl } from \"./NumberParserServiceImpl\";\nimport { ThemeServiceImpl, ThemeServiceProperties } from \"./ThemeServiceImpl\";\n\nexport const RUNTIME_PACKAGE_NAME = \"@open-pioneer/runtime\";\nexport const RUNTIME_API_EXTENSION = \"integration.ApiExtension\";\nexport const RUNTIME_API_SERVICE = \"runtime.ApiService\";\nexport const RUNTIME_APPLICATION_CONTEXT = \"runtime.ApplicationContext\";\nexport const RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE =\n \"runtime.ApplicationLifecycleEventService\";\nexport const RUNTIME_NUMBER_PARSER_SERVICE = \"runtime.NumberParserService\";\nexport const RUNTIME_AUTO_START = \"runtime.AutoStart\";\nexport const RUNTIME_THEME_SERVICE = \"runtime.ThemeService\";\n\nexport type BuiltinPackageProperties = ApplicationContextProperties & ThemeServiceProperties;\n\n/**\n * Creates the builtin package containing the builtin services.\n *\n * The runtime package should not use services in the `build.config.mjs`\n * for a clean bootstrapping procedure (it will be instantiated without\n * generated application metadata in tests).\n *\n * This function is called as part of the service layer startup.\n * The package produced here is always part of the application.\n */\nexport function createBuiltinPackage(properties: BuiltinPackageProperties): PackageRepr {\n const i18n = createEmptyPackageIntl();\n const apiService = new ServiceRepr({\n name: \"ApiServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApiServiceImpl),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_API_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"providers\",\n interfaceName: RUNTIME_API_EXTENSION,\n all: true\n }\n ]\n });\n const appContext = new ServiceRepr({\n name: \"ApplicationContextImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) => new ApplicationContextImpl(options, properties)\n ),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ]\n });\n const lifecycleEventService = new ServiceRepr({\n name: \"ApplicationLifecycleEventServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApplicationLifecycleEventService),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"listeners\",\n interfaceName: \"runtime.ApplicationLifecycleListener\",\n all: true\n }\n ]\n });\n const numberParserService = new ServiceRepr({\n name: \"NumberParserServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) => new NumberParserServiceImpl(options, properties.locale)\n ),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_NUMBER_PARSER_SERVICE,\n qualifier: \"builtin\"\n }\n ]\n });\n\n const themeService = new ServiceRepr({\n name: \"ThemeServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(() => new ThemeServiceImpl(properties)),\n intl: i18n,\n interfaces: [\n {\n interfaceName: RUNTIME_THEME_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"applicationContext\",\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ]\n });\n\n return new PackageRepr({\n name: RUNTIME_PACKAGE_NAME,\n services: [\n apiService,\n appContext,\n lifecycleEventService,\n numberParserService,\n themeService\n ],\n intl: i18n\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAeO,MAAM,oBAAA,GAAuB;AAC7B,MAAM,qBAAA,GAAwB,0BAAA;AAC9B,MAAM,mBAAA,GAAsB;AAC5B,MAAM,2BAAA,GAA8B,4BAAA;AACpC,MAAM,2CAAA,GACT;AACG,MAAM,6BAAA,GAAgC,6BAAA;AACtC,MAAM,kBAAA,GAAqB;AAC3B,MAAM,qBAAA,GAAwB;AAc9B,SAAS,qBAAqB,UAAA,EAAmD;AACpF,EAAA,MAAM,OAAO,sBAAA,EAAuB;AACpC,EAAA,MAAM,UAAA,GAAa,IAAI,WAAA,CAAY;AAAA,IAC/B,IAAA,EAAM,gBAAA;AAAA,IACN,WAAA,EAAa,oBAAA;AAAA,IACb,OAAA,EAAS,yBAAyB,cAAc,CAAA;AAAA,IAChD,IAAA,EAAM,IAAA;AAAA,IACN,UAAA,EAAY;AAAA,MACR;AAAA,QACI,aAAA,EAAe,mBAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf,KACJ;AAAA,IACA,YAAA,EAAc;AAAA,MACV;AAAA,QACI,aAAA,EAAe,WAAA;AAAA,QACf,aAAA,EAAe,qBAAA;AAAA,QACf,GAAA,EAAK;AAAA;AACT;AACJ,GACH,CAAA;AACD,EAAA,MAAM,UAAA,GAAa,IAAI,WAAA,CAAY;AAAA,IAC/B,IAAA,EAAM,wBAAA;AAAA,IACN,WAAA,E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AU,CAAC,CAAA;AAAA,IACrE,IAAA,EAAM,IAAA;AAAA,IACN,UAAA,EAAY;AAAA,MACR;AAAA,QACI,aAAA,EAAe,qBAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf,KACJ;AAAA,IACA,YAAA,EAAc;AAAA,MACV;AAAA,QACI,aAAA,EAAe,oBAAA;AAAA,QACf,aAAA,EAAe,2BAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf;AACJ,GACH,CAAA;AAED,EAAA,OAAO,IAAI,WAAA,CAAY;AAAA,IACnB,IAAA,EAAM,oBAAA;AAAA,IACN,QAAA,EAAU;AAAA,MACN,UAAA;AAAA,MACA,UAAA;AAAA,MACA,qBAAA;AAAA,MACA,mBAAA;AAAA,MACA;AAAA,KACJ;AAAA,IACA,IAAA,EAAM;AAAA,GACT,CAAA;AACL;;;;"}
1
+ {"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createEmptyPackageIntl } from \"../i18n\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport {\n createConstructorFactory,\n createFunctionFactory,\n ServiceRepr\n} from \"../service-layer/ServiceRepr\";\nimport { reactiveConstant } from \"../utils/reactive-constant\";\nimport { ApiServiceImpl } from \"./ApiServiceImpl\";\nimport { ApplicationContextImpl, ApplicationContextProperties } from \"./ApplicationContextImpl\";\nimport { ApplicationLifecycleEventService } from \"./ApplicationLifecycleEventService\";\nimport { NumberParserServiceImpl } from \"./NumberParserServiceImpl\";\nimport { ThemeServiceImpl, ThemeServiceProperties } from \"./ThemeServiceImpl\";\n\nexport const RUNTIME_PACKAGE_NAME = \"@open-pioneer/runtime\";\nexport const RUNTIME_API_EXTENSION = \"integration.ApiExtension\";\nexport const RUNTIME_API_SERVICE = \"runtime.ApiService\";\nexport const RUNTIME_APPLICATION_CONTEXT = \"runtime.ApplicationContext\";\nexport const RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE =\n \"runtime.ApplicationLifecycleEventService\";\nexport const RUNTIME_NUMBER_PARSER_SERVICE = \"runtime.NumberParserService\";\nexport const RUNTIME_AUTO_START = \"runtime.AutoStart\";\nexport const RUNTIME_THEME_SERVICE = \"runtime.ThemeService\";\n\nexport type BuiltinPackageProperties = ApplicationContextProperties & ThemeServiceProperties;\n\n/**\n * Creates the builtin package containing the builtin services.\n *\n * The runtime package should not use services in the `build.config.mjs`\n * for a clean bootstrapping procedure (it will be instantiated without\n * generated application metadata in tests).\n *\n * This function is called as part of the service layer startup.\n * The package produced here is always part of the application.\n */\nexport function createBuiltinPackage(properties: BuiltinPackageProperties): PackageRepr {\n const intl = createEmptyPackageIntl();\n const apiService = new ServiceRepr({\n name: \"ApiServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApiServiceImpl),\n intl: reactiveConstant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_API_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"providers\",\n interfaceName: RUNTIME_API_EXTENSION,\n all: true\n }\n ]\n });\n const appContext = new ServiceRepr({\n name: \"ApplicationContextImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) => new ApplicationContextImpl(options, properties)\n ),\n intl: reactiveConstant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ]\n });\n const lifecycleEventService = new ServiceRepr({\n name: \"ApplicationLifecycleEventServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApplicationLifecycleEventService),\n intl: reactiveConstant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"listeners\",\n interfaceName: \"runtime.ApplicationLifecycleListener\",\n all: true\n }\n ]\n });\n const numberParserService = new ServiceRepr({\n name: \"NumberParserServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) => new NumberParserServiceImpl(options, properties.locale)\n ),\n intl: reactiveConstant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_NUMBER_PARSER_SERVICE,\n qualifier: \"builtin\"\n }\n ]\n });\n\n const themeService = new ServiceRepr({\n name: \"ThemeServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(() => new ThemeServiceImpl(properties)),\n intl: reactiveConstant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_THEME_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"applicationContext\",\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ]\n });\n\n return new PackageRepr({\n name: RUNTIME_PACKAGE_NAME,\n services: [\n apiService,\n appContext,\n lifecycleEventService,\n numberParserService,\n themeService\n ],\n intl: reactiveConstant(intl)\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAgBO,MAAM,oBAAA,GAAuB;AAC7B,MAAM,qBAAA,GAAwB,0BAAA;AAC9B,MAAM,mBAAA,GAAsB;AAC5B,MAAM,2BAAA,GAA8B,4BAAA;AACpC,MAAM,2CAAA,GACT;AACG,MAAM,6BAAA,GAAgC,6BAAA;AACtC,MAAM,kBAAA,GAAqB;AAC3B,MAAM,qBAAA,GAAwB;AAc9B,SAAS,qBAAqB,UAAA,EAAmD;AACpF,EAAA,MAAM,OAAO,sBAAA,EAAuB;AACpC,EAAA,MAAM,UAAA,GAAa,IAAI,WAAA,CAAY;AAAA,IAC/B,IAAA,EAAM,gBAAA;AAAA,IACN,WAAA,EAAa,oBAAA;AAAA,IACb,OAAA,EAAS,yBAAyB,cAAc,CAAA;AAAA,IAChD,IAAA,EAAM,iBAAiB,IAAI,CAAA;AAAA,IAC3B,UAAA,EAAY;AAAA,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,OAAA,EAAS,WAAW,MAAM;AAAA,KACvE;AAAA,IACA,IAAA,EAAM,iBAAiB,IAAI,CAAA;AAAA,IAC3B,UAAA,EAAY;AAAA,MACR;AAAA,QACI,aAAA,EAAe,6BAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf;AACJ,GACH,CAAA;AAED,EAAA,MAAM,YAAA,GAAe,IAAI,WAAA,CAAY;AAAA,IACjC,IAAA,EAAM,kBAAA;AAAA,IACN,WAAA,EAAa,oBAAA;AAAA,IACb,SAAS,qBAAA,CAAsB,MAAM,IAAI,gBAAA,CAAiB,UAAU,CAAC,CAAA;AAAA,IACrE,IAAA,EAAM,iBAAiB,IAAI,CAAA;AAAA,IAC3B,UAAA,EAAY;AAAA,MACR;AAAA,QACI,aAAA,EAAe,qBAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf,KACJ;AAAA,IACA,YAAA,EAAc;AAAA,MACV;AAAA,QACI,aAAA,EAAe,oBAAA;AAAA,QACf,aAAA,EAAe,2BAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf;AACJ,GACH,CAAA;AAED,EAAA,OAAO,IAAI,WAAA,CAAY;AAAA,IACnB,IAAA,EAAM,oBAAA;AAAA,IACN,QAAA,EAAU;AAAA,MACN,UAAA;AAAA,MACA,UAAA;AAAA,MACA,qBAAA;AAAA,MACA,mBAAA;AAAA,MACA;AAAA,KACJ;AAAA,IACA,IAAA,EAAM,iBAAiB,IAAI;AAAA,GAC9B,CAAA;AACL;;;;"}
package/i18n/AppIntl.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { ApplicationMetadata } from "../metadata";
2
2
  import { PackageIntl } from "./PackageIntl";
3
+ import { ReadonlyReactive } from "@conterra/reactivity-core";
3
4
  /**
4
5
  * Represents i18n info for the entire application.
5
6
  * Currently not exposed to user code.
6
7
  */
7
8
  export interface AppIntl {
9
+ destroy(): void;
8
10
  /** Chosen locale */
9
11
  readonly locale: string;
10
12
  /** Supported locales from app metadata. */
@@ -12,7 +14,7 @@ export interface AppIntl {
12
14
  /** True if the locale can be used in this application (i.e. if there are any messages). */
13
15
  supportsLocale(locale: string): boolean;
14
16
  /** Given the package name, constructs a package i18n instance. */
15
- createPackageI18n(packageName: string): PackageIntl;
17
+ createPackageI18n(packageName: string): ReadonlyReactive<PackageIntl>;
16
18
  }
17
19
  /**
18
20
  * Initializes the application's locale and fetches the appropriate i18n messages.
package/i18n/AppIntl.js CHANGED
@@ -1,8 +1,11 @@
1
- import { createLogger, Error } from '@open-pioneer/core';
2
1
  import { sourceId$1 as sourceId } from '../_virtual/source-info.js';
2
+ import { createLogger, Error, destroyResource } from '@open-pioneer/core';
3
3
  import { ErrorId } from '../errors.js';
4
4
  import { createPackageIntl } from './PackageIntl.js';
5
5
  import { getBrowserLocales, I18nConfig } from './pick.js';
6
+ import { reactive, watchValue, computed } from '@conterra/reactivity-core';
7
+ import { unwrapBox } from '../metadata/ObservableBox.js';
8
+ import { reactiveConstant } from '../utils/reactive-constant.js';
6
9
 
7
10
  const LOG = createLogger(sourceId);
8
11
  async function initI18n(appMetadata, forcedLocale) {
@@ -22,10 +25,22 @@ async function initI18n(appMetadata, forcedLocale) {
22
25
  if (LOG.isDebug()) {
23
26
  LOG.debug(`Using locale '${locale}' with messages from locale '${messageLocale}'.`);
24
27
  }
25
- let messages;
26
- if (messageLocales.includes(messageLocale)) {
28
+ const messages = reactive({});
29
+ if (appMetadata?.loadMessages && messageLocales.includes(messageLocale)) {
27
30
  try {
28
- messages = await appMetadata?.loadMessages?.(messageLocale) ?? {};
31
+ const loader = unwrapBox(appMetadata.loadMessages);
32
+ const messagesRecord = await loader(messageLocale);
33
+ if (messagesRecord) {
34
+ messages.value = messagesRecord;
35
+ } else {
36
+ messages.value = {};
37
+ console.warn(
38
+ `I18n messages couldn't be loaded. Check if your runtimeMeta version is not set to 1.0.0.`
39
+ );
40
+ if (LOG.isDebug()) {
41
+ LOG.debug(`appMetadata.loadMessages doesn't support signal value'.`);
42
+ }
43
+ }
29
44
  } catch (e) {
30
45
  throw new Error(
31
46
  ErrorId.INTERNAL,
@@ -36,18 +51,81 @@ async function initI18n(appMetadata, forcedLocale) {
36
51
  );
37
52
  }
38
53
  }
54
+ let hmrWatch;
55
+ if (import.meta.hot) {
56
+ const handleHotUpdate = async (loader) => {
57
+ const newMessages = await loader?.(messageLocale) ?? {};
58
+ LOG.debug("Applying new i18n messages", newMessages);
59
+ messages.value = newMessages;
60
+ };
61
+ hmrWatch = watchValue(
62
+ () => appMetadata?.loadMessages ? unwrapBox(appMetadata.loadMessages) : void 0,
63
+ (loader) => {
64
+ if (!loader) {
65
+ return;
66
+ }
67
+ handleHotUpdate(loader).catch((e) => {
68
+ LOG.error(`Failed to load messages after hot reload`, e);
69
+ });
70
+ }
71
+ );
72
+ }
39
73
  return {
40
74
  locale,
41
75
  supportedMessageLocales: messageLocales,
76
+ destroy() {
77
+ hmrWatch = destroyResource(hmrWatch);
78
+ },
42
79
  supportsLocale(locale2) {
43
80
  return i18nConfig.supportsLocale(locale2);
44
81
  },
45
82
  createPackageI18n(packageName) {
46
- const packageMessage = messages?.[packageName] ?? {};
47
- return createPackageIntl(locale, packageMessage);
83
+ if (import.meta.hot) {
84
+ const packageMessages = computed(() => messages.value[packageName] ?? {}, {
85
+ equal: shallowRecordEquals
86
+ });
87
+ let firstCall = true;
88
+ const packageIntl = computed(() => {
89
+ if (!firstCall) {
90
+ LOG.info("Updating i18n messages of package", packageName);
91
+ }
92
+ firstCall = false;
93
+ return createPackageIntl(locale, packageMessages.value);
94
+ });
95
+ return packageIntl;
96
+ } else {
97
+ const packageMessages = messages.value[packageName] ?? {};
98
+ const packageIntl = createPackageIntl(locale, packageMessages);
99
+ return reactiveConstant(packageIntl);
100
+ }
48
101
  }
49
102
  };
50
103
  }
104
+ function shallowRecordEquals(a, b) {
105
+ const keysA = new Set(Object.keys(a));
106
+ const keysB = new Set(Object.keys(b));
107
+ if (keysA.size !== keysB.size) {
108
+ return false;
109
+ }
110
+ for (const k of keysA) {
111
+ if (!keysB.has(k)) {
112
+ return false;
113
+ }
114
+ }
115
+ for (const k of keysB) {
116
+ if (!keysA.has(k)) {
117
+ return false;
118
+ }
119
+ }
120
+ for (const k of keysA) {
121
+ const va = a[k];
122
+ const vb = b[k];
123
+ if (va !== vb) {
124
+ return false;
125
+ }
126
+ }
127
+ return true;
128
+ }
51
129
 
52
130
  export { initI18n };
53
131
  //# sourceMappingURL=AppIntl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppIntl.js","sources":["AppIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ErrorId } from \"../errors\";\nimport { ApplicationMetadata } from \"../metadata\";\nimport { createPackageIntl, PackageIntl } from \"./PackageIntl\";\nimport { getBrowserLocales, I18nConfig } from \"./pick\";\nconst LOG = createLogger(sourceId);\n\n/**\n * Represents i18n info for the entire application.\n * Currently not exposed to user code.\n */\nexport interface AppIntl {\n /** Chosen locale */\n readonly locale: string;\n\n /** Supported locales from app metadata. */\n readonly supportedMessageLocales: string[];\n\n /** True if the locale can be used in this application (i.e. if there are any messages). */\n supportsLocale(locale: string): boolean;\n\n /** Given the package name, constructs a package i18n instance. */\n createPackageI18n(packageName: string): PackageIntl;\n}\n\n/**\n * Initializes the application's locale and fetches the appropriate i18n messages.\n */\nexport async function initI18n(\n appMetadata: ApplicationMetadata | undefined,\n forcedLocale: string | undefined\n): Promise<AppIntl> {\n const messageLocales = appMetadata?.locales ?? [];\n const userLocales = getBrowserLocales();\n if (LOG.isDebug()) {\n LOG.debug(\n `Attempting to pick locale for user (locales: ${userLocales.join(\n \", \"\n )}) from app (supported locales: ${messageLocales.join(\n \", \"\n )}) [forcedLocale=${forcedLocale}].`\n );\n }\n\n const i18nConfig = new I18nConfig(messageLocales);\n const { locale, messageLocale } = i18nConfig.pickSupportedLocale(forcedLocale, userLocales);\n\n if (LOG.isDebug()) {\n LOG.debug(`Using locale '${locale}' with messages from locale '${messageLocale}'.`);\n }\n\n let messages: Record<string, Record<string, string>>;\n if (messageLocales.includes(messageLocale)) {\n try {\n messages = (await appMetadata?.loadMessages?.(messageLocale)) ?? {};\n } catch (e) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to load messages for locale '${messageLocale}'.`,\n {\n cause: e\n }\n );\n }\n }\n return {\n locale,\n supportedMessageLocales: messageLocales,\n supportsLocale(locale) {\n return i18nConfig.supportsLocale(locale);\n },\n createPackageI18n(packageName) {\n const packageMessage = messages?.[packageName] ?? {};\n return createPackageIntl(locale, packageMessage);\n }\n };\n}\n"],"names":["locale"],"mappings":";;;;;;AAQA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAuBjC,eAAsB,QAAA,CAClB,aACA,YAAA,EACgB;AAChB,EAAA,MAAM,cAAA,GAAiB,WAAA,EAAa,OAAA,IAAW,EAAC;AAChD,EAAA,MAAM,cAAc,iBAAA,EAAkB;AACtC,EAAA,IAAI,GAAA,CAAI,SAAQ,EAAG;AACf,IAAA,GAAA,CAAI,KAAA;AAAA,MACA,gDAAgD,WAAA,CAAY,IAAA;AAAA,QACxD;AAAA,OACH,kCAAkC,cAAA,CAAe,IAAA;AAAA,QAC9C;AAAA,OACH,mBAAmB,YAAY,CAAA,EAAA;AAAA,KACpC;AAAA,EACJ;AAEA,EAAA,MAAM,UAAA,GAAa,IAAI,UAAA,CAAW,cAAc,CAAA;AAChD,EAAA,MAAM,EAAE,MAAA,EAAQ,aAAA,KAAkB,UAAA,CAAW,mBAAA,CAAoB,cAAc,WAAW,CAAA;AAE1F,EAAA,IAAI,GAAA,CAAI,SAAQ,EAAG;AACf,IAAA,GAAA,CAAI,KAAA,CAAM,CAAA,cAAA,EAAiB,MAAM,CAAA,6BAAA,EAAgC,aAAa,CAAA,EAAA,CAAI,CAAA;AAAA,EACtF;AAEA,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI,cAAA,CAAe,QAAA,CAAS,aAAa,CAAA,EAAG;AACxC,IAAA,IAAI;AACA,MAAA,QAAA,GAAY,MAAM,WAAA,EAAa,YAAA,GAAe,aAAa,KAAM,EAAC;AAAA,IACtE,SAAS,CAAA,EAAG;AACR,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,QAAA;AAAA,QACR,uCAAuC,aAAa,CAAA,EAAA,CAAA;AAAA,QACpD;AAAA,UACI,KAAA,EAAO;AAAA;AACX,OACJ;AAAA,IACJ;AAAA,EACJ;AACA,EAAA,OAAO;AAAA,IACH,MAAA;AAAA,IACA,uBAAA,EAAyB,cAAA;AAAA,IACzB,eAAeA,OAAAA,EAAQ;AACnB,MAAA,OAAO,UAAA,CAAW,eAAeA,OAAM,CAAA;AAAA,IAC3C,CAAA;AAAA,IACA,kBAAkB,WAAA,EAAa;AAC3B,MAAA,MAAM,cAAA,GAAiB,QAAA,GAAW,WAAW,CAAA,IAAK,EAAC;AACnD,MAAA,OAAO,iBAAA,CAAkB,QAAQ,cAAc,CAAA;AAAA,IACnD;AAAA,GACJ;AACJ;;;;"}
1
+ {"version":3,"file":"AppIntl.js","sources":["AppIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createLogger, destroyResource, Error, Resource } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { ApplicationMetadata, MessageLoader, MessagesRecord } from \"../metadata\";\nimport { createPackageIntl, PackageIntl } from \"./PackageIntl\";\nimport { getBrowserLocales, I18nConfig } from \"./pick\";\nimport { computed, reactive, ReadonlyReactive, watchValue } from \"@conterra/reactivity-core\";\nimport { unwrapBox } from \"../metadata/ObservableBox\";\nimport { reactiveConstant } from \"../utils/reactive-constant\";\nconst LOG = createLogger(sourceId);\n\n/**\n * Represents i18n info for the entire application.\n * Currently not exposed to user code.\n */\nexport interface AppIntl {\n destroy(): void;\n\n /** Chosen locale */\n readonly locale: string;\n\n /** Supported locales from app metadata. */\n readonly supportedMessageLocales: string[];\n\n /** True if the locale can be used in this application (i.e. if there are any messages). */\n supportsLocale(locale: string): boolean;\n\n /** Given the package name, constructs a package i18n instance. */\n createPackageI18n(packageName: string): ReadonlyReactive<PackageIntl>;\n}\n\n/**\n * Initializes the application's locale and fetches the appropriate i18n messages.\n */\nexport async function initI18n(\n appMetadata: ApplicationMetadata | undefined,\n forcedLocale: string | undefined\n): Promise<AppIntl> {\n const messageLocales = appMetadata?.locales ?? [];\n const userLocales = getBrowserLocales();\n if (LOG.isDebug()) {\n LOG.debug(\n `Attempting to pick locale for user (locales: ${userLocales.join(\n \", \"\n )}) from app (supported locales: ${messageLocales.join(\n \", \"\n )}) [forcedLocale=${forcedLocale}].`\n );\n }\n\n const i18nConfig = new I18nConfig(messageLocales);\n const { locale, messageLocale } = i18nConfig.pickSupportedLocale(forcedLocale, userLocales);\n\n if (LOG.isDebug()) {\n LOG.debug(`Using locale '${locale}' with messages from locale '${messageLocale}'.`);\n }\n\n const messages = reactive<MessagesRecord>({});\n\n // Initial load of i18n messages.\n // During development, i18n messages are also loaded when they change on disk (see below).\n if (appMetadata?.loadMessages && messageLocales.includes(messageLocale)) {\n try {\n const loader = unwrapBox(appMetadata.loadMessages);\n const messagesRecord = await loader(messageLocale);\n if (messagesRecord) {\n messages.value = messagesRecord;\n } else {\n messages.value = {};\n console.warn(\n `I18n messages couldn't be loaded. Check if your runtimeMeta version is not set to 1.0.0.`\n );\n if (LOG.isDebug()) {\n LOG.debug(`appMetadata.loadMessages doesn't support signal value'.`);\n }\n }\n } catch (e) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to load messages for locale '${messageLocale}'.`,\n {\n cause: e\n }\n );\n }\n }\n\n // During dev: watch for changes of the loadMessage function\n // and fetch new I18N messages if the user edited any i18n file.\n let hmrWatch: Resource | undefined;\n if (import.meta.hot) {\n const handleHotUpdate = async (loader: MessageLoader) => {\n const newMessages = (await loader?.(messageLocale)) ?? {};\n LOG.debug(\"Applying new i18n messages\", newMessages);\n messages.value = newMessages;\n };\n\n hmrWatch = watchValue(\n () => (appMetadata?.loadMessages ? unwrapBox(appMetadata.loadMessages) : undefined),\n (loader) => {\n if (!loader) {\n return;\n }\n handleHotUpdate(loader).catch((e) => {\n LOG.error(`Failed to load messages after hot reload`, e);\n });\n }\n );\n }\n\n return {\n locale,\n supportedMessageLocales: messageLocales,\n destroy() {\n hmrWatch = destroyResource(hmrWatch);\n },\n supportsLocale(locale) {\n return i18nConfig.supportsLocale(locale);\n },\n createPackageI18n(packageName) {\n if (import.meta.hot) {\n const packageMessages = computed(() => messages.value[packageName] ?? {}, {\n equal: shallowRecordEquals\n });\n\n let firstCall = true;\n const packageIntl = computed(() => {\n if (!firstCall) {\n LOG.info(\"Updating i18n messages of package\", packageName);\n }\n firstCall = false;\n return createPackageIntl(locale, packageMessages.value);\n });\n return packageIntl;\n } else {\n const packageMessages = messages.value[packageName] ?? {};\n const packageIntl = createPackageIntl(locale, packageMessages);\n return reactiveConstant(packageIntl);\n }\n }\n };\n}\n\n// TODO: Move into @open-pioneer/core; consider using a third party lib\nfunction shallowRecordEquals(a: Record<string, unknown>, b: Record<string, unknown>) {\n const keysA = new Set(Object.keys(a));\n const keysB = new Set(Object.keys(b));\n if (keysA.size !== keysB.size) {\n return false;\n }\n for (const k of keysA) {\n if (!keysB.has(k)) {\n return false;\n }\n }\n for (const k of keysB) {\n if (!keysA.has(k)) {\n return false;\n }\n }\n\n for (const k of keysA) {\n const va = a[k];\n const vb = b[k];\n if (va !== vb) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["locale"],"mappings":";;;;;;;;;AAWA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAyBjC,eAAsB,QAAA,CAClB,aACA,YAAA,EACgB;AAChB,EAAA,MAAM,cAAA,GAAiB,WAAA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CAAC,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,EAAG;AACf,MAAA,OAAO,KAAA;AAAA,IACX;AAAA,EACJ;AAEA,EAAA,KAAA,MAAW,KAAK,KAAA,EAAO;AACnB,IAAA,MAAM,EAAA,GAAK,EAAE,CAAC,CAAA;AACd,IAAA,MAAM,EAAA,GAAK,EAAE,CAAC,CAAA;AACd,IAAA,IAAI,OAAO,EAAA,EAAI;AACX,MAAA,OAAO,KAAA;AAAA,IACX;AAAA,EACJ;AAEA,EAAA,OAAO,IAAA;AACX;;;;"}
@@ -13,3 +13,7 @@ export interface ObservableBox<T> {
13
13
  * In development node, the box value can be changed and observed.
14
14
  */
15
15
  export declare function createBox<T>(value: T): ObservableBox<T>;
16
+ /** @internal */
17
+ export declare function isBox<T>(value: T | ObservableBox<T>): value is ObservableBox<T>;
18
+ /** @internal */
19
+ export declare function unwrapBox<T>(value: T | ObservableBox<T>): T;
@@ -9,6 +9,12 @@ function createBox(value) {
9
9
  };
10
10
  }
11
11
  }
12
+ function isBox(value) {
13
+ return value instanceof BoxImpl;
14
+ }
15
+ function unwrapBox(value) {
16
+ return isBox(value) ? value.value : value;
17
+ }
12
18
  class BoxImpl {
13
19
  #signal;
14
20
  constructor(value) {
@@ -22,5 +28,5 @@ class BoxImpl {
22
28
  }
23
29
  }
24
30
 
25
- export { createBox };
31
+ export { createBox, unwrapBox };
26
32
  //# sourceMappingURL=ObservableBox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { reactive, Reactive } from \"@conterra/reactivity-core\";\n\nexport interface ObservableBox<T> {\n /** The current value. Reactive. */\n readonly value: T;\n\n /**\n * Changes the current value.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n setValue?(newValue: T): void;\n}\n\n/**\n * Returns a boxed value.\n * In development node, the box value can be changed and observed.\n */\nexport function createBox<T>(value: T): ObservableBox<T> {\n if (import.meta.env.DEV) {\n return new BoxImpl(value);\n } else {\n return {\n value\n };\n }\n}\n\nclass BoxImpl<T> implements Required<ObservableBox<T>> {\n #signal: Reactive<T>;\n\n constructor(value: T) {\n this.#signal = reactive(value);\n }\n\n get value(): T {\n return this.#signal.value;\n }\n\n setValue(newValue: T): void {\n this.#signal.value = newValue;\n }\n}\n"],"names":[],"mappings":";;AAoBO,SAAS,UAAa,KAAA,EAA4B;AACrD,EAAA,IAAI,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AACrB,IAAA,OAAO,IAAI,QAAQ,KAAK,CAAA;AAAA,EAC5B,CAAA,MAAO;AACH,IAAA,OAAO;AAAA,MACH;AAAA,KACJ;AAAA,EACJ;AACJ;AAEA,MAAM,OAAA,CAAiD;AAAA,EACnD,OAAA;AAAA,EAEA,YAAY,KAAA,EAAU;AAClB,IAAA,IAAA,CAAK,OAAA,GAAU,SAAS,KAAK,CAAA;AAAA,EACjC;AAAA,EAEA,IAAI,KAAA,GAAW;AACX,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACxB;AAAA,EAEA,SAAS,QAAA,EAAmB;AACxB,IAAA,IAAA,CAAK,QAAQ,KAAA,GAAQ,QAAA;AAAA,EACzB;AACJ;;;;"}
1
+ {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { reactive, Reactive } from \"@conterra/reactivity-core\";\n\nexport interface ObservableBox<T> {\n /** The current value. Reactive. */\n readonly value: T;\n\n /**\n * Changes the current value.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n setValue?(newValue: T): void;\n}\n\n/**\n * Returns a boxed value.\n * In development node, the box value can be changed and observed.\n */\nexport function createBox<T>(value: T): ObservableBox<T> {\n if (import.meta.env.DEV) {\n return new BoxImpl(value);\n } else {\n return {\n value\n };\n }\n}\n\n/** @internal */\nexport function isBox<T>(value: T | ObservableBox<T>): value is ObservableBox<T> {\n return value instanceof BoxImpl;\n}\n\n/** @internal */\nexport function unwrapBox<T>(value: T | ObservableBox<T>): T {\n return isBox(value) ? value.value : value;\n}\n\nclass BoxImpl<T> implements Required<ObservableBox<T>> {\n #signal: Reactive<T>;\n\n constructor(value: T) {\n this.#signal = reactive(value);\n }\n\n get value(): T {\n return this.#signal.value;\n }\n\n setValue(newValue: T): void {\n this.#signal.value = newValue;\n }\n}\n"],"names":[],"mappings":";;AAoBO,SAAS,UAAa,KAAA,EAA4B;AACrD,EAAA,IAAI,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AACrB,IAAA,OAAO,IAAI,QAAQ,KAAK,CAAA;AAAA,EAC5B,CAAA,MAAO;AACH,IAAA,OAAO;AAAA,MACH;AAAA,KACJ;AAAA,EACJ;AACJ;AAGO,SAAS,MAAS,KAAA,EAAwD;AAC7E,EAAA,OAAO,KAAA,YAAiB,OAAA;AAC5B;AAGO,SAAS,UAAa,KAAA,EAAgC;AACzD,EAAA,OAAO,KAAA,CAAM,KAAK,CAAA,GAAI,KAAA,CAAM,KAAA,GAAQ,KAAA;AACxC;AAEA,MAAM,OAAA,CAAiD;AAAA,EACnD,OAAA;AAAA,EAEA,YAAY,KAAA,EAAU;AAClB,IAAA,IAAA,CAAK,OAAA,GAAU,SAAS,KAAK,CAAA;AAAA,EACjC;AAAA,EAEA,IAAI,KAAA,GAAW;AACX,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACxB;AAAA,EAEA,SAAS,QAAA,EAAmB;AACxB,IAAA,IAAA,CAAK,QAAQ,KAAA,GAAQ,QAAA;AAAA,EACzB;AACJ;;;;"}
@@ -24,10 +24,17 @@ export interface ApplicationMetadata {
24
24
  locales?: string[];
25
25
  /**
26
26
  * Loads messages for the given locale.
27
+ *
28
+ * >NOTE: Previously (before runtime metadata version 1.1.0), this was a plain function;
29
+ * >then a plain function in a box.
30
+ *
27
31
  * @returns A record of packageName -> (messageId, messageTemplate) entries.
28
32
  */
29
- loadMessages?: (locale: string) => Promise<Record<string, Record<string, string>>>;
33
+ loadMessages?: MessageLoader | ObservableBox<MessageLoader>;
30
34
  }
35
+ export type MessageLoader = (locale: string) => Promise<MessagesRecord>;
36
+ /** Package name -> Message ID -> Message text (FormatJS Syntax) */
37
+ export type MessagesRecord = Record<string, Record<string, string>>;
31
38
  /**
32
39
  * Describes a package to the runtime.
33
40
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/runtime",
4
- "version": "4.5.0",
4
+ "version": "4.6.0-dev-i18n.20260518080633",
5
5
  "description": "Implements the runtime environment for Open Pioneer Trails apps.",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -14,16 +14,16 @@
14
14
  "directory": "src/packages/runtime"
15
15
  },
16
16
  "dependencies": {
17
- "@conterra/reactivity-core": "^0.8.1",
18
- "@formatjs/intl": "^4.1.4",
17
+ "@conterra/reactivity-core": "^0.8.2",
18
+ "@formatjs/intl": "^4.1.5",
19
19
  "@chakra-ui/react": "^3.34.0",
20
20
  "@emotion/cache": "^11.14.0",
21
21
  "@emotion/react": "^11.14.0",
22
22
  "react": "^19.2.4",
23
23
  "react-dom": "^19.2.4",
24
- "@open-pioneer/core": "4.5.0",
25
- "@open-pioneer/reactivity": "4.5.0",
26
- "@open-pioneer/base-theme": "4.5.0"
24
+ "@open-pioneer/base-theme": "4.6.0-dev-i18n.20260518080633",
25
+ "@open-pioneer/core": "4.6.0-dev-i18n.20260518080633",
26
+ "@open-pioneer/reactivity": "4.6.0-dev-i18n.20260518080633"
27
27
  },
28
28
  "exports": {
29
29
  "./package.json": "./package.json",
@@ -53,6 +53,9 @@
53
53
  "references": []
54
54
  },
55
55
  "properties": [],
56
- "packageFormatVersion": "1.0.0"
56
+ "runtimeMeta": {
57
+ "metadataVersion": "1.1.0"
58
+ },
59
+ "packageFormatVersion": "1.0.1"
57
60
  }
58
61
  }
@@ -5,6 +5,9 @@ export interface PackageContextMethods {
5
5
  getService: (packageName: string, interfaceName: string, options: UseServiceOptions) => Service;
6
6
  getServices: (packageName: string, interfaceName: string) => Service[];
7
7
  getProperties: (packageName: string) => Readonly<Record<string, unknown>>;
8
+ /**
9
+ * NOTE: This is reactive during development for hot reloading support.
10
+ */
8
11
  getIntl(packageName: string): PackageIntl;
9
12
  }
10
13
  export declare const PackageContext: import("react").Context<PackageContextMethods | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"PackageContext.js","sources":["PackageContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createContext } from \"react\";\nimport type { PackageIntl } from \"../i18n\";\nimport type { Service } from \"../Service\";\nimport type { UseServiceOptions } from \"./hooks\";\n\nexport interface PackageContextMethods {\n getService: (packageName: string, interfaceName: string, options: UseServiceOptions) => Service;\n getServices: (packageName: string, interfaceName: string) => Service[];\n getProperties: (packageName: string) => Readonly<Record<string, unknown>>;\n getIntl(packageName: string): PackageIntl;\n}\n\nexport const PackageContext = createContext<PackageContextMethods | null>(null);\n"],"names":[],"mappings":";;AAcO,MAAM,cAAA,GAAiB,cAA4C,IAAI;;;;"}
1
+ {"version":3,"file":"PackageContext.js","sources":["PackageContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createContext } from \"react\";\nimport type { PackageIntl } from \"../i18n\";\nimport type { Service } from \"../Service\";\nimport type { UseServiceOptions } from \"./hooks\";\n\nexport interface PackageContextMethods {\n getService: (packageName: string, interfaceName: string, options: UseServiceOptions) => Service;\n getServices: (packageName: string, interfaceName: string) => Service[];\n getProperties: (packageName: string) => Readonly<Record<string, unknown>>;\n\n /**\n * NOTE: This is reactive during development for hot reloading support.\n */\n getIntl(packageName: string): PackageIntl;\n}\n\nexport const PackageContext = createContext<PackageContextMethods | null>(null);\n"],"names":[],"mappings":";;AAkBO,MAAM,cAAA,GAAiB,cAA4C,IAAI;;;;"}
@@ -136,7 +136,7 @@ function createPackageContext(serviceLayer, packages) {
136
136
  return getPackage(packageName).properties;
137
137
  },
138
138
  getIntl: (packageName) => {
139
- return getPackage(packageName).intl;
139
+ return getPackage(packageName).intl.value;
140
140
  }
141
141
  };
142
142
  return packageContext;
@@ -1 +1 @@
1
- {"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { ColorModeValue } from \"../api\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: string;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n private rootNode: RootNode;\n private hostNode: HTMLElement;\n private appRoot: HTMLDivElement;\n private reactRoot: Root;\n private packageContext: PackageContextMethods;\n private locale: string;\n private chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n private styles: ReadonlyReactive<string>;\n private colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.rootNode = options.rootNode;\n this.hostNode = options.hostNode;\n this.appRoot = options.appRoot;\n this.reactRoot = createRoot(options.appRoot);\n this.chakraConfig = options.config;\n this.packageContext = options.packageContext;\n this.locale = options.locale;\n this.styles = options.styles;\n this.colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.rootNode}\n hostNode={this.hostNode}\n appRoot={this.appRoot}\n config={this.chakraConfig}\n locale={this.locale}\n styles={this.styles}\n colorMode={this.colorMode}\n >\n <PackageContext.Provider value={this.packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA8BO,MAAM,gBAAA,CAAiB;AAAA,EAClB,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EAER,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YAAA,EAAc,QAAQ,CAAA;AAClE,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEA,OAAO,qBACH,OAAA,EACF;AACE,IAAA,MAAM,aAAa,MAAM;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,aAAA,EAAe,8CAA8C,CAAA;AAAA,IACzF,CAAA;AACA,IAAA,MAAM,cAAA,GAAwC;AAAA,MAC1C,OAAA,EAAS,UAAA;AAAA,MACT,aAAA,EAAe,UAAA;AAAA,MACf,UAAA,EAAY,UAAA;AAAA,MACZ,WAAA,EAAa;AAAA,KACjB;AACA,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEQ,YACJ,OAAA,EAGF;AACE,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AACxB,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AACxB,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,OAAA;AACvB,IAAA,IAAA,CAAK,SAAA,GAAY,UAAA,CAAW,OAAA,CAAQ,OAAO,CAAA;AAC3C,IAAA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AsB,aAAa,aAAa;AAAA,WACpD;AAAA;AACR,IACJ,CAAA;AAAA,IACA,WAAA,EAAa,CAAC,WAAA,EAAa,aAAA,KAAkB;AACzC,MAAA,MAAM,MAAA,GAAS,YAAA,CAAa,WAAA,CAAY,WAAA,EAAa,aAAa,CAAA;AAClE,MAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,QAAA,OAAO,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,WAAA,KAAgB,WAAA,CAAY,oBAAoB,CAAA;AAAA,MAC7E;AAEA,MAAA,QAAQ,OAAO,IAAA;AAAM,QACjB,KAAK,YAAA;AACD,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,qBAAA;AAAA,YACR,CAAA,SAAA,EAAY,WAAW,CAAA,2EAAA,EAA8E,aAAa,CAAA,qFAAA;AAAA,WAEtH;AAAA,QACJ,KAAK,iBAAA;AACD,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,eAAA;AAAA,YACR,qBAAA,CAAsB,aAAa,aAAa;AAAA,WACpD;AAAA;AACR,IACJ,CAAA;AAAA,IACA,aAAA,EAAe,CAAC,WAAA,KAAgB;AAC5B,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,UAAA;AAAA,IACnC,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,WAAA,KAAgB;AACtB,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,IAAA;AAAA,IACnC;AAAA,GACJ;AACA,EAAA,OAAO,cAAA;AACX;AAEA,SAAS,qBAAA,CAAsB,aAAqB,aAAA,EAAuB;AACvE,EAAA,OACI,CAAA,SAAA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
1
+ {"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { ColorModeValue } from \"../api\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: string;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n private rootNode: RootNode;\n private hostNode: HTMLElement;\n private appRoot: HTMLDivElement;\n private reactRoot: Root;\n private packageContext: PackageContextMethods;\n private locale: string;\n private chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n private styles: ReadonlyReactive<string>;\n private colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.rootNode = options.rootNode;\n this.hostNode = options.hostNode;\n this.appRoot = options.appRoot;\n this.reactRoot = createRoot(options.appRoot);\n this.chakraConfig = options.config;\n this.packageContext = options.packageContext;\n this.locale = options.locale;\n this.styles = options.styles;\n this.colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.rootNode}\n hostNode={this.hostNode}\n appRoot={this.appRoot}\n config={this.chakraConfig}\n locale={this.locale}\n styles={this.styles}\n colorMode={this.colorMode}\n >\n <PackageContext.Provider value={this.packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl.value;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA8BO,MAAM,gBAAA,CAAiB;AAAA,EAClB,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EAER,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YA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;AAAA,YACR,CAAA,SAAA,EAAY,WAAW,CAAA,2EAAA,EAA8E,aAAa,CAAA,qFAAA;AAAA,WAEtH;AAAA,QACJ,KAAK,iBAAA;AACD,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,eAAA;AAAA,YACR,qBAAA,CAAsB,aAAa,aAAa;AAAA,WACpD;AAAA;AACR,IACJ,CAAA;AAAA,IACA,aAAA,EAAe,CAAC,WAAA,KAAgB;AAC5B,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,UAAA;AAAA,IACnC,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,WAAA,KAAgB;AACtB,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,IAAA,CAAK,KAAA;AAAA,IACxC;AAAA,GACJ;AACA,EAAA,OAAO,cAAA;AACX;AAEA,SAAS,qBAAA,CAAsB,aAAqB,aAAA,EAAuB;AACvE,EAAA,OACI,CAAA,SAAA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
@@ -2,6 +2,7 @@ import { Error } from '@open-pioneer/core';
2
2
  import { useContext, useMemo } from 'react';
3
3
  import { ErrorId } from '../errors.js';
4
4
  import { PackageContext } from './PackageContext.js';
5
+ import { useReactiveSnapshot } from '@open-pioneer/reactivity';
5
6
 
6
7
  function useServiceInternal(packageName, interfaceName, options) {
7
8
  const context = useContext(PackageContext);
@@ -29,7 +30,16 @@ function usePropertiesInternal(packageName) {
29
30
  }
30
31
  function useIntlInternal(packageName) {
31
32
  const context = useContext(PackageContext);
32
- return checkContext("useIntl", context).getIntl(packageName);
33
+ const contextData = checkContext("useIntl", context);
34
+ if (import.meta.hot) {
35
+ const intl = useReactiveSnapshot(
36
+ () => contextData.getIntl(packageName),
37
+ [packageName, contextData]
38
+ );
39
+ return intl;
40
+ } else {
41
+ return contextData.getIntl(packageName);
42
+ }
33
43
  }
34
44
  function checkContext(hookName, contextData) {
35
45
  if (!contextData) {
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sources":["hooks.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 { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n return checkContext(\"useIntl\", context).getIntl(packageName);\n}\n\nfunction checkContext(\n hookName: string,\n contextData: PackageContextMethods | null\n): PackageContextMethods {\n if (!contextData) {\n throw new Error(\n ErrorId.INTERNAL,\n `\"Failed to access package context from '${hookName}': react integration was not set up properly.`\n );\n }\n return contextData;\n}\n"],"names":[],"mappings":";;;;;AA+CO,SAAS,kBAAA,CACZ,WAAA,EAEA,aAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,OAAA,GAAU,OAAA;AAAA,IACZ,MACI,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA,CAAE,UAAA;AAAA,MAChC,WAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAW;AAAC,KAChB;AAAA,IACJ,CAAC,OAAA,EAAS,WAAA,EAAa,aAAA,EAAe,OAAO;AAAA,GACjD;AACA,EAAA,OAAO,OAAA;AACX;AAiBO,SAAS,mBAAA,CAAoB,aAAqB,aAAA,EAA+B;AACpF,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,OAAA;AAAA,IACb,MAAM,YAAA,CAAa,aAAA,EAAe,OAAO,CAAA,CAAE,WAAA,CAAY,aAAa,aAAa,CAAA;AAAA,IACjF,CAAC,OAAA,EAAS,WAAA,EAAa,aAAa;AAAA,GACxC;AACA,EAAA,OAAO,QAAA;AACX;AAUO,SAAS,sBAAsB,WAAA,EAAwD;AAC1F,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,OAAO,YAAA,CAAa,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,WAAW,CAAA;AAC3E;AAUO,SAAS,gBAAgB,WAAA,EAAkC;AAC9D,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,OAAO,YAAA,CAAa,SAAA,EAAW,OAAO,CAAA,CAAE,QAAQ,WAAW,CAAA;AAC/D;AAEA,SAAS,YAAA,CACL,UACA,WAAA,EACqB;AACrB,EAAA,IAAI,CAAC,WAAA,EAAa;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,2CAA2C,QAAQ,CAAA,6CAAA;AAAA,KACvD;AAAA,EACJ;AACA,EAAA,OAAO,WAAA;AACX;;;;"}
1
+ {"version":3,"file":"hooks.js","sources":["hooks.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 { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n const contextData = checkContext(\"useIntl\", context);\n\n if (import.meta.hot) {\n // Only reactive during dev\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const intl = useReactiveSnapshot(\n () => contextData.getIntl(packageName),\n [packageName, contextData]\n );\n return intl;\n } else {\n // Not reactive in production code\n return contextData.getIntl(packageName);\n }\n}\n\nfunction checkContext(\n hookName: string,\n contextData: PackageContextMethods | null\n): PackageContextMethods {\n if (!contextData) {\n throw new Error(\n ErrorId.INTERNAL,\n `\"Failed to access package context from '${hookName}': react integration was not set up properly.`\n );\n }\n return contextData;\n}\n"],"names":[],"mappings":";;;;;;AAgDO,SAAS,kBAAA,CACZ,WAAA,EAEA,aAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,OAAA,GAAU,OAAA;AAAA,IACZ,MACI,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA,CAAE,UAAA;AAAA,MAChC,WAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAW;AAAC,KAChB;AAAA,IACJ,CAAC,OAAA,EAAS,WAAA,EAAa,aAAA,EAAe,OAAO;AAAA,GACjD;AACA,EAAA,OAAO,OAAA;AACX;AAiBO,SAAS,mBAAA,CAAoB,aAAqB,aAAA,EAA+B;AACpF,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,OAAA;AAAA,IACb,MAAM,YAAA,CAAa,aAAA,EAAe,OAAO,CAAA,CAAE,WAAA,CAAY,aAAa,aAAa,CAAA;AAAA,IACjF,CAAC,OAAA,EAAS,WAAA,EAAa,aAAa;AAAA,GACxC;AACA,EAAA,OAAO,QAAA;AACX;AAUO,SAAS,sBAAsB,WAAA,EAAwD;AAC1F,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,OAAO,YAAA,CAAa,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,WAAW,CAAA;AAC3E;AAUO,SAAS,gBAAgB,WAAA,EAAkC;AAC9D,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,YAAA,CAAa,SAAA,EAAW,OAAO,CAAA;AAEnD,EAAA,IAAI,YAAY,GAAA,EAAK;AAGjB,IAAA,MAAM,IAAA,GAAO,mBAAA;AAAA,MACT,MAAM,WAAA,CAAY,OAAA,CAAQ,WAAW,CAAA;AAAA,MACrC,CAAC,aAAa,WAAW;AAAA,KAC7B;AACA,IAAA,OAAO,IAAA;AAAA,EACX,CAAA,MAAO;AAEH,IAAA,OAAO,WAAA,CAAY,QAAQ,WAAW,CAAA;AAAA,EAC1C;AACJ;AAEA,SAAS,YAAA,CACL,UACA,WAAA,EACqB;AACrB,EAAA,IAAI,CAAC,WAAA,EAAa;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,2CAA2C,QAAQ,CAAA,6CAAA;AAAA,KACvD;AAAA,EACJ;AACA,EAAA,OAAO,WAAA;AACX;;;;"}
@@ -1,17 +1,18 @@
1
+ import { ReadonlyReactive } from "@conterra/reactivity-core";
1
2
  import { ApplicationProperties } from "../CustomElement";
2
- import { PackageIntl, AppIntl } from "../i18n";
3
+ import { AppIntl, PackageIntl } from "../i18n";
3
4
  import { PackageMetadata } from "../metadata";
4
5
  import { ReferenceSpec } from "./InterfaceSpec";
5
6
  import { ServiceRepr } from "./ServiceRepr";
6
7
  export interface PackageReprOptions {
7
8
  name: string;
8
- intl: PackageIntl;
9
+ intl: ReadonlyReactive<PackageIntl>;
9
10
  services?: ServiceRepr[];
10
11
  uiReferences?: ReferenceSpec[];
11
12
  properties?: Record<string, unknown>;
12
13
  }
13
14
  export declare class PackageRepr {
14
- static create(data: PackageMetadata, i18n: PackageIntl, customProperties?: Record<string, unknown>): PackageRepr;
15
+ static create(data: PackageMetadata, intl: ReadonlyReactive<PackageIntl>, customProperties?: Record<string, unknown>): PackageRepr;
15
16
  /** Package name */
16
17
  readonly name: string;
17
18
  /** Services defined by the package */
@@ -21,7 +22,7 @@ export declare class PackageRepr {
21
22
  /** Resolved (perhaps customized) package properties. */
22
23
  readonly properties: Readonly<Record<string, unknown>>;
23
24
  /** Locale-dependant i18n messages. */
24
- readonly intl: PackageIntl;
25
+ readonly intl: ReadonlyReactive<PackageIntl>;
25
26
  constructor(options: PackageReprOptions);
26
27
  }
27
28
  export declare function createPackages(packages: Record<string, PackageMetadata>, i18n: AppIntl, customProperties?: ApplicationProperties): PackageRepr[];
@@ -4,7 +4,7 @@ import { parseReferenceSpec } from './InterfaceSpec.js';
4
4
  import { ServiceRepr } from './ServiceRepr.js';
5
5
 
6
6
  class PackageRepr {
7
- static create(data, i18n, customProperties) {
7
+ static create(data, intl, customProperties) {
8
8
  const name = data.name;
9
9
  const properties = data.properties ?? {};
10
10
  const finalProperties = customizeProperties(name, properties, customProperties);
@@ -16,7 +16,7 @@ class PackageRepr {
16
16
  "Invalid metadata: service name mismatch."
17
17
  );
18
18
  }
19
- return ServiceRepr.create(data.name, serviceData, i18n, finalProperties);
19
+ return ServiceRepr.create(data.name, serviceData, intl, finalProperties);
20
20
  }
21
21
  );
22
22
  const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];
@@ -25,7 +25,7 @@ class PackageRepr {
25
25
  services,
26
26
  uiReferences,
27
27
  properties: finalProperties,
28
- intl: i18n
28
+ intl
29
29
  });
30
30
  }
31
31
  /** Package name */
@@ -1 +1 @@
1
- {"version":3,"file":"PackageRepr.js","sources":["PackageRepr.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 { ApplicationProperties } from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl, AppIntl } from \"../i18n\";\nimport { PackageMetadata, PropertyMetadata } from \"../metadata\";\nimport { parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface PackageReprOptions {\n name: string;\n intl: PackageIntl;\n services?: ServiceRepr[];\n uiReferences?: ReferenceSpec[];\n properties?: Record<string, unknown>;\n}\n\nexport class PackageRepr {\n static create(\n data: PackageMetadata,\n i18n: PackageIntl,\n customProperties?: Record<string, unknown>\n ): PackageRepr {\n const name = data.name;\n const properties = data.properties ?? {};\n const finalProperties = customizeProperties(name, properties, customProperties);\n const services = Object.entries(data.services ?? {}).map<ServiceRepr>(\n ([name, serviceData]) => {\n if (name !== serviceData.name) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"Invalid metadata: service name mismatch.\"\n );\n }\n return ServiceRepr.create(data.name, serviceData, i18n, finalProperties);\n }\n );\n const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];\n return new PackageRepr({\n name,\n services,\n uiReferences,\n properties: finalProperties,\n intl: i18n\n });\n }\n\n /** Package name */\n readonly name: string;\n\n /** Services defined by the package */\n readonly services: readonly ServiceRepr[];\n\n /** Interfaces required by UI components. */\n readonly uiReferences: readonly Readonly<ReferenceSpec>[];\n\n /** Resolved (perhaps customized) package properties. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Locale-dependant i18n messages. */\n readonly intl: PackageIntl;\n\n constructor(options: PackageReprOptions) {\n const name = options.name;\n if (!isValidPackageName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid package name: '${name}'.`);\n }\n\n this.name = name;\n this.services = options.services ?? [];\n this.uiReferences = options.uiReferences ?? [];\n this.properties = options.properties ?? {};\n this.intl = options.intl;\n }\n}\n\nexport function createPackages(\n packages: Record<string, PackageMetadata>,\n i18n: AppIntl,\n customProperties?: ApplicationProperties\n) {\n return Object.entries(packages).map<PackageRepr>(([name, packageMetadata]) => {\n if (name !== packageMetadata.name) {\n throw new Error(ErrorId.INVALID_METADATA, \"Invalid metadata: package name mismatch.\");\n }\n\n const packageI18n = i18n.createPackageI18n(name);\n return PackageRepr.create(packageMetadata, packageI18n, customProperties?.[name]);\n });\n}\n\n/**\n * Merges the declared properties of the package with the application-defined\n * custom properties.\n */\nfunction customizeProperties(\n packageName: string,\n properties: Record<string, PropertyMetadata>,\n customProperties: Record<string, unknown> = {}\n) {\n const merged: Record<string, unknown> = {};\n const required: string[] = [];\n for (const [key, propertyMetadata] of Object.entries(properties)) {\n merged[key] = propertyMetadata.value;\n if (propertyMetadata.required) {\n required.push(key);\n }\n }\n\n for (const [key, value] of Object.entries(customProperties)) {\n if (!hasProperty(merged, key)) {\n throw new Error(\n ErrorId.INVALID_PROPERTY_NAME,\n `Unexpected property name '${key}' for package '${packageName}': the property does not exist.`\n );\n }\n merged[key] = value;\n }\n\n for (const key of required) {\n const value = merged[key];\n if (value == null) {\n throw new Error(\n ErrorId.REQUIRED_PROPERTY,\n `Package '${packageName}' requires the property '${key}' to be initialized to a non-null value.`\n );\n }\n }\n\n return merged;\n}\n\nconst HAS_PROP = Object.prototype.hasOwnProperty;\n\nfunction hasProperty(object: unknown, key: string) {\n return HAS_PROP.call(object, key);\n}\n\n// http://json.schemastore.org/package\nconst NAME_REGEX = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/;\n\nfunction isValidPackageName(name: string): boolean {\n return NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;AAkBO,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,IAAA,EACA,IAAA,EACA,gBAAA,EACW;AACX,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AA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AA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,gBAAgB,CAAA,EAAG;AACzD,IAAA,IAAI,CAAC,WAAA,CAAY,MAAA,EAAQ,GAAG,CAAA,EAAG;AAC3B,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,qBAAA;AAAA,QACR,CAAA,0BAAA,EAA6B,GAAG,CAAA,eAAA,EAAkB,WAAW,CAAA,+BAAA;AAAA,OACjE;AAAA,IACJ;AACA,IAAA,MAAA,CAAO,GAAG,CAAA,GAAI,KAAA;AAAA,EAClB;AAEA,EAAA,KAAA,MAAW,OAAO,QAAA,EAAU;AACxB,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,SAAS,IAAA,EAAM;AACf,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,iBAAA;AAAA,QACR,CAAA,SAAA,EAAY,WAAW,CAAA,yBAAA,EAA4B,GAAG,CAAA,wCAAA;AAAA,OAC1D;AAAA,IACJ;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX;AAEA,MAAM,QAAA,GAAW,OAAO,SAAA,CAAU,cAAA;AAElC,SAAS,WAAA,CAAY,QAAiB,GAAA,EAAa;AAC/C,EAAA,OAAO,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AACpC;AAGA,MAAM,UAAA,GAAa,4DAAA;AAEnB,SAAS,mBAAmB,IAAA,EAAuB;AAC/C,EAAA,OAAO,UAAA,CAAW,KAAK,IAAI,CAAA;AAC/B;;;;"}
1
+ {"version":3,"file":"PackageRepr.js","sources":["PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ApplicationProperties } from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, PackageIntl } from \"../i18n\";\nimport { PackageMetadata, PropertyMetadata } from \"../metadata\";\nimport { parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface PackageReprOptions {\n name: string;\n intl: ReadonlyReactive<PackageIntl>;\n services?: ServiceRepr[];\n uiReferences?: ReferenceSpec[];\n properties?: Record<string, unknown>;\n}\n\nexport class PackageRepr {\n static create(\n data: PackageMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n customProperties?: Record<string, unknown>\n ): PackageRepr {\n const name = data.name;\n const properties = data.properties ?? {};\n const finalProperties = customizeProperties(name, properties, customProperties);\n const services = Object.entries(data.services ?? {}).map<ServiceRepr>(\n ([name, serviceData]) => {\n if (name !== serviceData.name) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"Invalid metadata: service name mismatch.\"\n );\n }\n return ServiceRepr.create(data.name, serviceData, intl, finalProperties);\n }\n );\n const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];\n return new PackageRepr({\n name,\n services,\n uiReferences,\n properties: finalProperties,\n intl: intl\n });\n }\n\n /** Package name */\n readonly name: string;\n\n /** Services defined by the package */\n readonly services: readonly ServiceRepr[];\n\n /** Interfaces required by UI components. */\n readonly uiReferences: readonly Readonly<ReferenceSpec>[];\n\n /** Resolved (perhaps customized) package properties. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n constructor(options: PackageReprOptions) {\n const name = options.name;\n if (!isValidPackageName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid package name: '${name}'.`);\n }\n\n this.name = name;\n this.services = options.services ?? [];\n this.uiReferences = options.uiReferences ?? [];\n this.properties = options.properties ?? {};\n this.intl = options.intl;\n }\n}\n\nexport function createPackages(\n packages: Record<string, PackageMetadata>,\n i18n: AppIntl,\n customProperties?: ApplicationProperties\n) {\n return Object.entries(packages).map<PackageRepr>(([name, packageMetadata]) => {\n if (name !== packageMetadata.name) {\n throw new Error(ErrorId.INVALID_METADATA, \"Invalid metadata: package name mismatch.\");\n }\n\n const packageI18n = i18n.createPackageI18n(name);\n return PackageRepr.create(packageMetadata, packageI18n, customProperties?.[name]);\n });\n}\n\n/**\n * Merges the declared properties of the package with the application-defined\n * custom properties.\n */\nfunction customizeProperties(\n packageName: string,\n properties: Record<string, PropertyMetadata>,\n customProperties: Record<string, unknown> = {}\n) {\n const merged: Record<string, unknown> = {};\n const required: string[] = [];\n for (const [key, propertyMetadata] of Object.entries(properties)) {\n merged[key] = propertyMetadata.value;\n if (propertyMetadata.required) {\n required.push(key);\n }\n }\n\n for (const [key, value] of Object.entries(customProperties)) {\n if (!hasProperty(merged, key)) {\n throw new Error(\n ErrorId.INVALID_PROPERTY_NAME,\n `Unexpected property name '${key}' for package '${packageName}': the property does not exist.`\n );\n }\n merged[key] = value;\n }\n\n for (const key of required) {\n const value = merged[key];\n if (value == null) {\n throw new Error(\n ErrorId.REQUIRED_PROPERTY,\n `Package '${packageName}' requires the property '${key}' to be initialized to a non-null value.`\n );\n }\n }\n\n return merged;\n}\n\nconst HAS_PROP = Object.prototype.hasOwnProperty;\n\nfunction hasProperty(object: unknown, key: string) {\n return HAS_PROP.call(object, key);\n}\n\n// http://json.schemastore.org/package\nconst NAME_REGEX = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/;\n\nfunction isValidPackageName(name: string): boolean {\n return NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;AAmBO,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,IAAA,EACA,IAAA,EACA,gBAAA,EACW;AACX,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAClB,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,UAAA,IAAc,EAAC;AACvC,IAAA,MAAM,eAAA,GA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,IAAI,CAAC,WAAA,CAAY,MAAA,EAAQ,GAAG,CAAA,EAAG;AAC3B,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,qBAAA;AAAA,QACR,CAAA,0BAAA,EAA6B,GAAG,CAAA,eAAA,EAAkB,WAAW,CAAA,+BAAA;AAAA,OACjE;AAAA,IACJ;AACA,IAAA,MAAA,CAAO,GAAG,CAAA,GAAI,KAAA;AAAA,EAClB;AAEA,EAAA,KAAA,MAAW,OAAO,QAAA,EAAU;AACxB,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,SAAS,IAAA,EAAM;AACf,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,iBAAA;AAAA,QACR,CAAA,SAAA,EAAY,WAAW,CAAA,yBAAA,EAA4B,GAAG,CAAA,wCAAA;AAAA,OAC1D;AAAA,IACJ;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX;AAEA,MAAM,QAAA,GAAW,OAAO,SAAA,CAAU,cAAA;AAElC,SAAS,WAAA,CAAY,QAAiB,GAAA,EAAa;AAC/C,EAAA,OAAO,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AACpC;AAGA,MAAM,UAAA,GAAa,4DAAA;AAEnB,SAAS,mBAAmB,IAAA,EAAuB;AAC/C,EAAA,OAAO,UAAA,CAAW,KAAK,IAAI,CAAA;AAC/B;;;;"}
@@ -1,7 +1,8 @@
1
+ import { ReadonlyReactive } from "@conterra/reactivity-core";
2
+ import { PackageIntl } from "../i18n";
1
3
  import { ServiceMetadata } from "../metadata";
2
4
  import { Service, ServiceConstructor, ServiceOptions } from "../Service";
3
5
  import { InterfaceSpec, ReferenceSpec } from "./InterfaceSpec";
4
- import { PackageIntl } from "../i18n";
5
6
  export type ServiceState = "not-constructed" | "constructing" | "constructed" | "destroyed";
6
7
  export type ServiceDependency = ReferenceSpec & {
7
8
  referenceName: string;
@@ -19,7 +20,7 @@ export interface ServiceReprOptions {
19
20
  name: string;
20
21
  packageName: string;
21
22
  factory: ServiceFactory;
22
- intl: PackageIntl;
23
+ intl: ReadonlyReactive<PackageIntl>;
23
24
  dependencies?: ServiceDependency[];
24
25
  interfaces?: InterfaceSpec[];
25
26
  properties?: Record<string, unknown>;
@@ -29,7 +30,7 @@ export interface ServiceReprOptions {
29
30
  * `this.instance` is the actual service instance (when constructed).
30
31
  */
31
32
  export declare class ServiceRepr {
32
- static create(packageName: string, data: ServiceMetadata, intl: PackageIntl, properties?: Record<string, unknown>): ServiceRepr;
33
+ static create(packageName: string, data: ServiceMetadata, intl: ReadonlyReactive<PackageIntl>, properties?: Record<string, unknown>): ServiceRepr;
33
34
  /** Unique id of this service. Contains the package name and the service name. */
34
35
  readonly id: string;
35
36
  /** Name of this service in it's package. */
@@ -37,7 +38,7 @@ export declare class ServiceRepr {
37
38
  /** Name of the parent package. */
38
39
  readonly packageName: string;
39
40
  /** Locale-dependant i18n messages. */
40
- readonly intl: PackageIntl;
41
+ readonly intl: ReadonlyReactive<PackageIntl>;
41
42
  /** Service properties made available via the service's constructor. */
42
43
  readonly properties: Readonly<Record<string, unknown>>;
43
44
  /** Dependencies required by the service constructor. */
@@ -52,6 +53,8 @@ export declare class ServiceRepr {
52
53
  private _state;
53
54
  /** Service instance, once constructed. */
54
55
  private _instance;
56
+ /** Used in dev mode only. */
57
+ private _hmrState;
55
58
  constructor(options: ServiceReprOptions);
56
59
  /** Returns the current service instance or undefined if the service has not been constructed. */
57
60
  get instance(): Service | undefined;
@@ -1,7 +1,15 @@
1
+ import { watchValue } from '@conterra/reactivity-core';
2
+ import { createLogger, deprecated, Error, destroyResource } from '@open-pioneer/core';
1
3
  import { ErrorId } from '../errors.js';
2
- import { Error } from '@open-pioneer/core';
3
4
  import { parseReferenceSpec } from './InterfaceSpec.js';
4
5
 
6
+ const LOG = createLogger("runtime:ServiceRepr");
7
+ const intlDeprecation = deprecated({
8
+ name: "intl",
9
+ packageName: "@open-pioneer/runtime",
10
+ since: "4.5.1",
11
+ alternative: "use currentIntl instead. Keep in mind to watch for changes in the received object."
12
+ });
5
13
  class ServiceRepr {
6
14
  static create(packageName, data, intl, properties) {
7
15
  const clazz = data.clazz;
@@ -56,6 +64,8 @@ class ServiceRepr {
56
64
  _state = "not-constructed";
57
65
  /** Service instance, once constructed. */
58
66
  _instance = void 0;
67
+ /** Used in dev mode only. */
68
+ _hmrState = void 0;
59
69
  constructor(options) {
60
70
  const {
61
71
  name,
@@ -130,11 +140,44 @@ class ServiceRepr {
130
140
  "Inconsistent state: service is not being constructed."
131
141
  );
132
142
  }
143
+ const id = this.id;
144
+ const intl = this.intl;
145
+ let hmrState;
146
+ if (import.meta.hot) {
147
+ let intlWatch = void 0;
148
+ hmrState = this._hmrState = {
149
+ destroy() {
150
+ intlWatch = destroyResource(intlWatch);
151
+ },
152
+ onIntlUsed() {
153
+ if (intlWatch) {
154
+ return;
155
+ }
156
+ intlWatch = watchValue(
157
+ () => intl.value,
158
+ (_newIntl, _, context) => {
159
+ LOG.warn(
160
+ `Service ${id} has used 'intl' but intl has changed. Hot reloading of intl changes is only implemented with "currentIntl". Consider to change your implementation. Triggering full reload.`
161
+ );
162
+ context.destroy();
163
+ window.location.reload();
164
+ }
165
+ );
166
+ }
167
+ };
168
+ }
133
169
  try {
134
170
  this._instance = createService(this.factory, {
135
171
  ...options,
136
172
  properties: this.properties,
137
- intl: this.intl
173
+ get intl() {
174
+ intlDeprecation();
175
+ if (import.meta.hot) {
176
+ hmrState?.onIntlUsed();
177
+ }
178
+ return intl.value;
179
+ },
180
+ currentIntl: this.intl
138
181
  });
139
182
  this._state = "constructed";
140
183
  this._useCount = 1;
@@ -151,6 +194,7 @@ class ServiceRepr {
151
194
  if (this._instance) {
152
195
  try {
153
196
  this._instance.destroy?.();
197
+ this._hmrState = destroyResource(this._hmrState);
154
198
  } catch (e) {
155
199
  throw new Error(
156
200
  ErrorId.SERVICE_DESTRUCTION_FAILED,
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceRepr.js","sources":["ServiceRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ErrorId } from \"../errors\";\nimport { ServiceMetadata } from \"../metadata\";\nimport { Service, ServiceConstructor, ServiceOptions } from \"../Service\";\nimport { Error } from \"@open-pioneer/core\";\nimport { InterfaceSpec, parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { PackageIntl } from \"../i18n\";\n\nexport type ServiceState = \"not-constructed\" | \"constructing\" | \"constructed\" | \"destroyed\";\n\nexport type ServiceDependency = ReferenceSpec & { referenceName: string };\n\nexport interface ConstructorFactory {\n type: \"class\";\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n clazz: ServiceConstructor<any>;\n}\n\nexport interface FunctionFactory {\n type: \"function\";\n create: (options: ServiceOptions) => Service;\n}\n\nexport type ServiceFactory = ConstructorFactory | FunctionFactory;\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceFactory;\n intl: PackageIntl;\n dependencies?: ServiceDependency[];\n interfaces?: InterfaceSpec[];\n properties?: Record<string, unknown>;\n}\n\n/**\n * Represents metadata and state of a service in the runtime.\n * `this.instance` is the actual service instance (when constructed).\n */\nexport class ServiceRepr {\n static create(\n packageName: string,\n data: ServiceMetadata,\n intl: PackageIntl,\n properties?: Record<string, unknown>\n ): ServiceRepr {\n const clazz = data.clazz;\n const name = data.name;\n const dependencies = Object.entries(data.references ?? {}).map(\n ([name, referenceMetadata]) => {\n return {\n referenceName: name,\n ...parseReferenceSpec(referenceMetadata)\n };\n }\n );\n const interfaces = data.provides?.map<InterfaceSpec>((i) => {\n return {\n interfaceName: i.name,\n qualifier: i.qualifier\n };\n });\n const factory: ConstructorFactory = {\n type: \"class\",\n clazz\n };\n return new ServiceRepr({\n name,\n packageName,\n factory,\n intl,\n dependencies,\n interfaces,\n properties\n });\n }\n\n /** Unique id of this service. Contains the package name and the service name. */\n readonly id: string;\n\n /** Name of this service in it's package. */\n readonly name: string;\n\n /** Name of the parent package. */\n readonly packageName: string;\n\n /** Locale-dependant i18n messages. */\n readonly intl: PackageIntl;\n\n /** Service properties made available via the service's constructor. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Dependencies required by the service constructor. */\n readonly dependencies: readonly ServiceDependency[];\n\n /** Interfaces provided by the service. */\n readonly interfaces: readonly Readonly<InterfaceSpec>[];\n\n /** Number of references to this service. */\n private _useCount = 0;\n\n /** Service factory to construct an instance. */\n private factory: ServiceFactory;\n\n /** Current state of this service. \"constructed\" -> instance is available. */\n private _state: ServiceState = \"not-constructed\";\n\n /** Service instance, once constructed. */\n private _instance: Service | undefined = undefined;\n\n constructor(options: ServiceReprOptions) {\n const {\n name,\n packageName,\n factory,\n intl,\n dependencies = [],\n interfaces = [],\n properties = {}\n } = options;\n if (!isValidServiceName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid service name: '${name}'.`);\n }\n\n this.id = `${packageName}::${name}`;\n this.name = name;\n this.packageName = packageName;\n this.factory = factory;\n this.intl = intl;\n this.dependencies = dependencies;\n this.interfaces = interfaces;\n this.properties = properties;\n }\n\n /** Returns the current service instance or undefined if the service has not been constructed. */\n get instance(): Service | undefined {\n return this._instance;\n }\n\n /** Returns the current state of the service. */\n get state() {\n return this._state;\n }\n\n /** Returns the current reference count. */\n get useCount() {\n return this._useCount;\n }\n\n /**\n * Same as `instance`, but throws when the instance has not been constructed.\n */\n getInstanceOrThrow() {\n const instance = this._instance;\n if (!instance) {\n throw new Error(ErrorId.INTERNAL, \"Expected service instance to be present.\");\n }\n return instance;\n }\n\n /**\n * Called before `create()` to place the service into the `constructing` state,\n * which is currently used to detect cycles.\n */\n beforeCreate() {\n if (this._state === \"not-constructed\") {\n this._state = \"constructing\";\n } else {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is already under construction.\"\n );\n }\n }\n\n /**\n * Instantiates the service by invoking the service constructor\n * with the given `options`.\n *\n * The service's use count is initialized to `1`, so every `create()`\n * should be paired with a `removeRef()`.\n *\n * `destroy()` can be invoked once the final `removeRef()` has returned zero.\n */\n create(options: Pick<ServiceOptions, \"references\" | \"referencesMeta\">) {\n if (this._state !== \"constructing\" || this.instance !== undefined) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is not being constructed.\"\n );\n }\n try {\n this._instance = createService(this.factory, {\n ...options,\n properties: this.properties,\n intl: this.intl\n });\n this._state = \"constructed\";\n this._useCount = 1;\n return this._instance;\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_CONSTRUCTION_FAILED,\n `Failed to create service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n\n destroy() {\n if (this._instance) {\n try {\n this._instance.destroy?.();\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_DESTRUCTION_FAILED,\n `Failed to destroy service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n this._instance = undefined;\n this._state = \"destroyed\";\n }\n\n /**\n * Adds a use to the service's use count.\n * References to a service are tracked: it should only be destroyed when it is no longer being used.\n */\n addRef() {\n return (this._useCount += 1);\n }\n\n /**\n * Removes a use from the service's use count.\n * Returns the new use count.\n */\n removeRef() {\n return (this._useCount -= 1);\n }\n}\n\nexport function createConstructorFactory<T extends {}>(\n clazz: ServiceConstructor<T>\n): ConstructorFactory {\n return { type: \"class\", clazz };\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): FunctionFactory {\n return { type: \"function\", create };\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n\nfunction createService(factory: ServiceFactory, options: ServiceOptions) {\n switch (factory.type) {\n case \"class\":\n return new factory.clazz(options);\n case \"function\":\n return factory.create(options);\n }\n}\n"],"names":["name"],"mappings":";;;;AAwCO,MAAM,WAAA,CAAY;AAAA,EACrB,OA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A;AAAA,UACN,OAAA,CAAQ,0BAAA;AAAA,UACR,CAAA,oCAAA,EAAuC,KAAK,EAAE,CAAA,EAAA,CAAA;AAAA,UAC9C,EAAE,OAAO,CAAA;AAAE,SACf;AAAA,MACJ;AAAA,IACJ;AACA,IAAA,IAAA,CAAK,SAAA,GAAY,MAAA;AACjB,IAAA,IAAA,CAAK,MAAA,GAAS,WAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAA,GAAS;AACL,IAAA,OAAQ,KAAK,SAAA,IAAa,CAAA;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA,GAAY;AACR,IAAA,OAAQ,KAAK,SAAA,IAAa,CAAA;AAAA,EAC9B;AACJ;AAEO,SAAS,yBACZ,KAAA,EACkB;AAClB,EAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAM;AAClC;AAEO,SAAS,sBACZ,MAAA,EACe;AACf,EAAA,OAAO,EAAE,IAAA,EAAM,UAAA,EAAY,MAAA,EAAO;AACtC;AAEA,MAAM,kBAAA,GAAqB,gBAAA;AAE3B,SAAS,mBAAmB,IAAA,EAAc;AACtC,EAAA,OAAO,kBAAA,CAAmB,KAAK,IAAI,CAAA;AACvC;AAEA,SAAS,aAAA,CAAc,SAAyB,OAAA,EAAyB;AACrE,EAAA,QAAQ,QAAQ,IAAA;AAAM,IAClB,KAAK,OAAA;AACD,MAAA,OAAO,IAAI,OAAA,CAAQ,KAAA,CAAM,OAAO,CAAA;AAAA,IACpC,KAAK,UAAA;AACD,MAAA,OAAO,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA;AAEzC;;;;"}
1
+ {"version":3,"file":"ServiceRepr.js","sources":["ServiceRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive, watchValue } from \"@conterra/reactivity-core\";\nimport { createLogger, deprecated, destroyResource, Error, Resource } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { ServiceMetadata } from \"../metadata\";\nimport { Service, ServiceConstructor, ServiceOptions } from \"../Service\";\nimport { InterfaceSpec, parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\n\nconst LOG = createLogger(\"runtime:ServiceRepr\");\n\nexport type ServiceState = \"not-constructed\" | \"constructing\" | \"constructed\" | \"destroyed\";\n\nexport type ServiceDependency = ReferenceSpec & { referenceName: string };\n\nexport interface ConstructorFactory {\n type: \"class\";\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n clazz: ServiceConstructor<any>;\n}\n\nexport interface FunctionFactory {\n type: \"function\";\n create: (options: ServiceOptions) => Service;\n}\n\nexport type ServiceFactory = ConstructorFactory | FunctionFactory;\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceFactory;\n intl: ReadonlyReactive<PackageIntl>;\n dependencies?: ServiceDependency[];\n interfaces?: InterfaceSpec[];\n properties?: Record<string, unknown>;\n}\n\ninterface HmrState extends Resource {\n onIntlUsed(): void;\n}\n\nconst intlDeprecation = deprecated({\n name: \"intl\",\n packageName: \"@open-pioneer/runtime\",\n since: \"4.5.1\",\n alternative:\n \"use currentIntl instead. Keep in mind to watch for changes in the received object.\"\n});\n\n/**\n * Represents metadata and state of a service in the runtime.\n * `this.instance` is the actual service instance (when constructed).\n */\nexport class ServiceRepr {\n static create(\n packageName: string,\n data: ServiceMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n properties?: Record<string, unknown>\n ): ServiceRepr {\n const clazz = data.clazz;\n const name = data.name;\n const dependencies = Object.entries(data.references ?? {}).map(\n ([name, referenceMetadata]) => {\n return {\n referenceName: name,\n ...parseReferenceSpec(referenceMetadata)\n };\n }\n );\n const interfaces = data.provides?.map<InterfaceSpec>((i) => {\n return {\n interfaceName: i.name,\n qualifier: i.qualifier\n };\n });\n const factory: ConstructorFactory = {\n type: \"class\",\n clazz\n };\n return new ServiceRepr({\n name,\n packageName,\n factory,\n intl,\n dependencies,\n interfaces,\n properties\n });\n }\n\n /** Unique id of this service. Contains the package name and the service name. */\n readonly id: string;\n\n /** Name of this service in it's package. */\n readonly name: string;\n\n /** Name of the parent package. */\n readonly packageName: string;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n /** Service properties made available via the service's constructor. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Dependencies required by the service constructor. */\n readonly dependencies: readonly ServiceDependency[];\n\n /** Interfaces provided by the service. */\n readonly interfaces: readonly Readonly<InterfaceSpec>[];\n\n /** Number of references to this service. */\n private _useCount = 0;\n\n /** Service factory to construct an instance. */\n private factory: ServiceFactory;\n\n /** Current state of this service. \"constructed\" -> instance is available. */\n private _state: ServiceState = \"not-constructed\";\n\n /** Service instance, once constructed. */\n private _instance: Service | undefined = undefined;\n\n /** Used in dev mode only. */\n private _hmrState: HmrState | undefined = undefined;\n\n constructor(options: ServiceReprOptions) {\n const {\n name,\n packageName,\n factory,\n intl,\n dependencies = [],\n interfaces = [],\n properties = {}\n } = options;\n if (!isValidServiceName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid service name: '${name}'.`);\n }\n\n this.id = `${packageName}::${name}`;\n this.name = name;\n this.packageName = packageName;\n this.factory = factory;\n this.intl = intl;\n this.dependencies = dependencies;\n this.interfaces = interfaces;\n this.properties = properties;\n }\n\n /** Returns the current service instance or undefined if the service has not been constructed. */\n get instance(): Service | undefined {\n return this._instance;\n }\n\n /** Returns the current state of the service. */\n get state() {\n return this._state;\n }\n\n /** Returns the current reference count. */\n get useCount() {\n return this._useCount;\n }\n\n /**\n * Same as `instance`, but throws when the instance has not been constructed.\n */\n getInstanceOrThrow() {\n const instance = this._instance;\n if (!instance) {\n throw new Error(ErrorId.INTERNAL, \"Expected service instance to be present.\");\n }\n return instance;\n }\n\n /**\n * Called before `create()` to place the service into the `constructing` state,\n * which is currently used to detect cycles.\n */\n beforeCreate() {\n if (this._state === \"not-constructed\") {\n this._state = \"constructing\";\n } else {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is already under construction.\"\n );\n }\n }\n\n /**\n * Instantiates the service by invoking the service constructor\n * with the given `options`.\n *\n * The service's use count is initialized to `1`, so every `create()`\n * should be paired with a `removeRef()`.\n *\n * `destroy()` can be invoked once the final `removeRef()` has returned zero.\n */\n create(options: Pick<ServiceOptions, \"references\" | \"referencesMeta\">) {\n if (this._state !== \"constructing\" || this.instance !== undefined) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service is not being constructed.\"\n );\n }\n\n const id = this.id;\n const intl = this.intl;\n\n let hmrState: HmrState | undefined;\n if (import.meta.hot) {\n let intlWatch: Resource | undefined = undefined;\n hmrState = this._hmrState = {\n destroy() {\n intlWatch = destroyResource(intlWatch);\n },\n\n onIntlUsed() {\n if (intlWatch) {\n return;\n }\n\n intlWatch = watchValue(\n () => intl.value,\n (_newIntl, _, context) => {\n LOG.warn(\n `Service ${id} has used 'intl' but intl has changed.` +\n ` Hot reloading of intl changes is only implemented ` +\n ` with \"currentIntl\". Consider to change your implementation.` +\n ` Triggering full reload.`\n );\n context.destroy();\n\n // TODO: Figure out a cleaner way to force vite to reload the application\n // https://github.com/open-pioneer/trails-core-packages/issues/164\n window.location.reload();\n }\n );\n }\n };\n }\n\n try {\n this._instance = createService(this.factory, {\n ...options,\n properties: this.properties,\n get intl() {\n intlDeprecation();\n if (import.meta.hot) {\n hmrState?.onIntlUsed();\n }\n return intl.value;\n },\n currentIntl: this.intl\n });\n this._state = \"constructed\";\n this._useCount = 1;\n return this._instance;\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_CONSTRUCTION_FAILED,\n `Failed to create service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n\n destroy() {\n if (this._instance) {\n try {\n this._instance.destroy?.();\n this._hmrState = destroyResource(this._hmrState);\n } catch (e) {\n throw new Error(\n ErrorId.SERVICE_DESTRUCTION_FAILED,\n `Failed to destroy service instance '${this.id}'.`,\n { cause: e }\n );\n }\n }\n this._instance = undefined;\n this._state = \"destroyed\";\n }\n\n /**\n * Adds a use to the service's use count.\n * References to a service are tracked: it should only be destroyed when it is no longer being used.\n */\n addRef() {\n return (this._useCount += 1);\n }\n\n /**\n * Removes a use from the service's use count.\n * Returns the new use count.\n */\n removeRef() {\n return (this._useCount -= 1);\n }\n}\n\nexport function createConstructorFactory<T extends {}>(\n clazz: ServiceConstructor<T>\n): ConstructorFactory {\n return { type: \"class\", clazz };\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): FunctionFactory {\n return { type: \"function\", create };\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n\nfunction createService(factory: ServiceFactory, options: ServiceOptions) {\n switch (factory.type) {\n case \"class\":\n return new factory.clazz(options);\n case \"function\":\n return factory.create(options);\n }\n}\n"],"names":["name"],"mappings":";;;;;AAUA,MAAM,GAAA,GAAM,aAAa,qBAAqB,CAAA;AAiC9C,MAAM,kBAAkB,UAAA,CAAW;AAAA,EAC/B,IAAA,EAAM,MAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,OAAA;AAAA,EACP,WAAA,EACI;AACR,CAAC,CAAA;AAMM,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,WAAA,EACA,IAAA,EACA,MACA,UAAA,EACW;AACX,IAAA,MAAM,QAAQ,IAAA,CAAK,KAAA;AACnB,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAClB,IAAA,MAAM,eAAe,MAAA,CAAO,OAAA,CAAQ,KAAK,UAAA,IAAc,EAAE,CAAA,CAAE,GAAA;AAAA,MACvD,CAAC,CAACA,KAAAA,EAAM,iBAAiB,CAAA,KAAM;AAC3B,QAAA,OAAO;AAAA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OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAM;AAClC;AAEO,SAAS,sBACZ,MAAA,EACe;AACf,EAAA,OAAO,EAAE,IAAA,EAAM,UAAA,EAAY,MAAA,EAAO;AACtC;AAEA,MAAM,kBAAA,GAAqB,gBAAA;AAE3B,SAAS,mBAAmB,IAAA,EAAc;AACtC,EAAA,OAAO,kBAAA,CAAmB,KAAK,IAAI,CAAA;AACvC;AAEA,SAAS,aAAA,CAAc,SAAyB,OAAA,EAAyB;AACrE,EAAA,QAAQ,QAAQ,IAAA;AAAM,IAClB,KAAK,OAAA;AACD,MAAA,OAAO,IAAI,OAAA,CAAQ,KAAA,CAAM,OAAO,CAAA;AAAA,IACpC,KAAK,UAAA;AACD,MAAA,OAAO,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA;AAEzC;;;;"}
@@ -0,0 +1,2 @@
1
+ import { ReadonlyReactive } from "@conterra/reactivity-core";
2
+ export declare function reactiveConstant<T>(value: T): ReadonlyReactive<T>;
@@ -0,0 +1,8 @@
1
+ import { reactive } from '@conterra/reactivity-core';
2
+
3
+ function reactiveConstant(value) {
4
+ return reactive(value);
5
+ }
6
+
7
+ export { reactiveConstant };
8
+ //# sourceMappingURL=reactive-constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive-constant.js","sources":["reactive-constant.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\n\n// TODO: Remove if https://github.com/conterra/reactivity/issues/77 is available\nexport function reactiveConstant<T>(value: T): ReadonlyReactive<T> {\n return reactive(value);\n}\n"],"names":[],"mappings":";;AAKO,SAAS,iBAAoB,KAAA,EAA+B;AAC/D,EAAA,OAAO,SAAS,KAAK,CAAA;AACzB;;;;"}