@open-pioneer/runtime 4.6.0-dev.20260421085858 → 4.6.0-dev.20260518093554
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 +12 -1
- package/Service.d.ts +11 -1
- package/Service.js.map +1 -1
- package/app/AppInstance.d.ts +1 -0
- package/app/AppInstance.js +3 -1
- package/app/AppInstance.js.map +1 -1
- package/builtin-services/index.js +8 -7
- package/builtin-services/index.js.map +1 -1
- package/i18n/AppIntl.d.ts +3 -1
- package/i18n/AppIntl.js +83 -6
- package/i18n/AppIntl.js.map +1 -1
- package/metadata/ObservableBox.d.ts +4 -0
- package/metadata/ObservableBox.js +7 -1
- package/metadata/ObservableBox.js.map +1 -1
- package/metadata/index.d.ts +8 -1
- package/package.json +12 -9
- package/react-integration/ChakraProvider.js +1 -0
- package/react-integration/ChakraProvider.js.map +1 -1
- package/react-integration/PackageContext.d.ts +3 -0
- package/react-integration/PackageContext.js.map +1 -1
- package/react-integration/ReactIntegration.js +1 -1
- package/react-integration/ReactIntegration.js.map +1 -1
- package/react-integration/hooks.js +11 -1
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/PackageRepr.d.ts +5 -4
- package/service-layer/PackageRepr.js +3 -3
- package/service-layer/PackageRepr.js.map +1 -1
- package/service-layer/ServiceRepr.d.ts +8 -5
- package/service-layer/ServiceRepr.js +50 -2
- package/service-layer/ServiceRepr.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
# @open-pioneer/runtime
|
|
2
2
|
|
|
3
|
-
## 4.6.0-dev.
|
|
3
|
+
## 4.6.0-dev.20260518093554
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
+
- 63db133: Deprecate `serviceOptions.intl`. Use `serviceOptions.currentIntl` instead.
|
|
8
|
+
The new interface supports updating `intl` messages at runtime.
|
|
7
9
|
- 05425c6: runtime - Introduce support for ServiceFactories, to provide constructor indirection during service creation
|
|
10
|
+
- 63db133: Support for hot reloading of i18n messages (requires updated vite plugin).
|
|
11
|
+
When i18n messages are updated:
|
|
12
|
+
- React components rerender automatically with new `intl` object returned by `useIntl()`.
|
|
13
|
+
- Services that use the new `serviceOptions.currentIntl` interface also receive a new `intl` object (if they are watching for changes).
|
|
14
|
+
- Services that that still use the deprecated `serviceOptions.intl` interface cause the application to reload instead.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- b092b75: Declare css property `color-scheme` on the application root. This can be used by the browser to render builtin controls differently.
|
|
8
19
|
|
|
9
20
|
## 4.5.0
|
|
10
21
|
|
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`.
|
package/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sources":["Service.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { PackageIntl } from \"./i18n\";\n\n/** Lifecycle hooks supported by the service interface. */\nexport interface ServiceLifecycleHooks {\n /**\n * Destroys the component.\n * Should clean up all resources used by the component.\n */\n destroy?(): void;\n\n /*\n * Just used so that this interface is not empty.\n * TypeScript would otherwise throw an 'no common properties' error\n * if one tries to implement this interface without providing any\n * lifecycle hooks.\n */\n toString(): string;\n}\n\nexport type Service<Interface extends {} = {}> = ServiceLifecycleHooks & Interface;\n\n/**\n * Represents metadata for an injected reference.\n */\nexport interface ReferenceMeta {\n /**\n * The unique service id of the injected service.\n */\n serviceId: string;\n}\n\n/**\n * Contains metadata about injected references.\n * The key for the reference metadata is the reference's name.\n */\nexport type ReferencesMeta<References extends {}> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]: References[referenceName] extends any[]\n ? ReferenceMeta[]\n : ReferenceMeta;\n};\n\n/**\n * Options passed to a service's constructor.\n */\nexport type ServiceOptions<References extends {} = {}> = {\n /**\n * References to other services.\n * These are injected by the runtime and match the declared references of the service.\n */\n references: References;\n\n /**\n * Metadata about the injected references.\n * The object contains one entry for every reference injected via `references` (under the same key).\n *\n * If a single service has been injected, `referencesMeta[key]` will be of type {@link ReferenceMeta}.\n * If multiple services have been injected, an array of {@link ReferenceMeta} will be provided instead,\n * where the indices match the order in the injected references array.\n */\n referencesMeta: ReferencesMeta<References>;\n\n /**\n * Configuration properties.\n *\n * Default values are taken from the package's configuration, but these can be overridden\n * by the application.\n */\n properties: Record<string, unknown>;\n\n /**\n * A reference to the shared i18n object of the current package.\n */\n intl: PackageIntl;\n};\n\n/**\n * A service constructor returns a service instance when calling `new`.\n */\nexport type ServiceConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): Service<Interface>;\n};\n\n/**\n * A service factory is an object that has a method to create a service instance.\n * The service factory itself can also implement lifecycle hooks, which will be called by the runtime\n * when the factory is destroyed.\n */\nexport type ServiceFactory<Interface extends {} = {}> = {\n /**\n * Method to create a service instance.\n * It is directly called by the runtime after constructing the factory.\n * NOTE: the service.destroy lifecycle hook is not called by the runtime.\n */\n createService(): Interface;\n /**\n * Optional method to destroy a service instance created by this factory.\n * If provided, this method will be called by the runtime when the service instance is destroyed.\n * A factory instance exists per service, this method invocation means that the factory is no longer used by the runtime.\n */\n destroyService?(service: Interface): void;\n};\n\n/**\n * A constructor type for a service factory.\n * The service factory is an object that has a method to create a service instance,\n * this allows for more flexibility in service construction.\n */\nexport type ServiceFactoryConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): ServiceFactory<Interface>;\n};\n\n/**\n * Symbol used to detect if a constructor function is a service factory constructor.\n */\nconst IS_SERVICE_FACTORY = Symbol(\"runtime.IS_SERVICE_FACTORY\");\nexport { IS_SERVICE_FACTORY };\n\n/**\n * A service factory constructor must be marked\n * with the `IS_SERVICE_FACTORY` symbol to be recognized by the runtime as such.\n */\nexport type MarkedServiceFactoryConstructor<\n References extends {} = {},\n Interface extends {} = {}\n> = ServiceFactoryConstructor<References, Interface> & {\n [IS_SERVICE_FACTORY]: true;\n};\n\n/**\n * Utility function to mark a constructor as a service factory constructor.\n * @param ctr normal constructor function for a service factory.\n * @returns the same constructor function, but marked with the `IS_SERVICE_FACTORY` symbol so that the runtime recognizes it as a service factory constructor.\n */\nexport function defineServiceFactory(\n ctr: ServiceFactoryConstructor\n): MarkedServiceFactoryConstructor {\n const markedCtr = ctr as MarkedServiceFactoryConstructor;\n markedCtr[IS_SERVICE_FACTORY] = true;\n return markedCtr;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Service.js","sources":["Service.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 { PackageIntl } from \"./i18n\";\n\n/** Lifecycle hooks supported by the service interface. */\nexport interface ServiceLifecycleHooks {\n /**\n * Destroys the component.\n * Should clean up all resources used by the component.\n */\n destroy?(): void;\n\n /*\n * Just used so that this interface is not empty.\n * TypeScript would otherwise throw an 'no common properties' error\n * if one tries to implement this interface without providing any\n * lifecycle hooks.\n */\n toString(): string;\n}\n\nexport type Service<Interface extends {} = {}> = ServiceLifecycleHooks & Interface;\n\n/**\n * Represents metadata for an injected reference.\n */\nexport interface ReferenceMeta {\n /**\n * The unique service id of the injected service.\n */\n serviceId: string;\n}\n\n/**\n * Contains metadata about injected references.\n * The key for the reference metadata is the reference's name.\n */\nexport type ReferencesMeta<References extends {}> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]: References[referenceName] extends any[]\n ? ReferenceMeta[]\n : ReferenceMeta;\n};\n\n/**\n * Options passed to a service's constructor.\n */\nexport type ServiceOptions<References extends {} = {}> = {\n /**\n * References to other services.\n * These are injected by the runtime and match the declared references of the service.\n */\n references: References;\n\n /**\n * Metadata about the injected references.\n * The object contains one entry for every reference injected via `references` (under the same key).\n *\n * If a single service has been injected, `referencesMeta[key]` will be of type {@link ReferenceMeta}.\n * If multiple services have been injected, an array of {@link ReferenceMeta} will be provided instead,\n * where the indices match the order in the injected references array.\n */\n referencesMeta: ReferencesMeta<References>;\n\n /**\n * Configuration properties.\n *\n * Default values are taken from the package's configuration, but these can be overridden\n * by the application.\n */\n properties: Record<string, unknown>;\n\n /**\n * A constant reference to the shared i18n object of the current package.\n *\n * @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\n */\n intl: PackageIntl;\n\n /**\n * A signal that returns the current i18n object of the service's package.\n *\n * The i18n object may change at runtime (for example to implement hot reloading during development,\n * or to implement language changes while the application is running).\n */\n currentIntl: ReadonlyReactive<PackageIntl>;\n};\n\n/**\n * A service constructor returns a service instance when calling `new`.\n */\nexport type ServiceConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): Service<Interface>;\n};\n\n/**\n * A service factory is an object that has a method to create a service instance.\n * The service factory itself can also implement lifecycle hooks, which will be called by the runtime\n * when the factory is destroyed.\n */\nexport type ServiceFactory<Interface extends {} = {}> = {\n /**\n * Method to create a service instance.\n * It is directly called by the runtime after constructing the factory.\n * NOTE: the service.destroy lifecycle hook is not called by the runtime.\n */\n createService(): Interface;\n /**\n * Optional method to destroy a service instance created by this factory.\n * If provided, this method will be called by the runtime when the service instance is destroyed.\n * A factory instance exists per service, this method invocation means that the factory is no longer used by the runtime.\n */\n destroyService?(service: Interface): void;\n};\n\n/**\n * A constructor type for a service factory.\n * The service factory is an object that has a method to create a service instance,\n * this allows for more flexibility in service construction.\n */\nexport type ServiceFactoryConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): ServiceFactory<Interface>;\n};\n\n/**\n * Symbol used to detect if a constructor function is a service factory constructor.\n */\nconst IS_SERVICE_FACTORY = Symbol(\"runtime.IS_SERVICE_FACTORY\");\nexport { IS_SERVICE_FACTORY };\n\n/**\n * A service factory constructor must be marked\n * with the `IS_SERVICE_FACTORY` symbol to be recognized by the runtime as such.\n */\nexport type MarkedServiceFactoryConstructor<\n References extends {} = {},\n Interface extends {} = {}\n> = ServiceFactoryConstructor<References, Interface> & {\n [IS_SERVICE_FACTORY]: true;\n};\n\n/**\n * Utility function to mark a constructor as a service factory constructor.\n * @param ctr normal constructor function for a service factory.\n * @returns the same constructor function, but marked with the `IS_SERVICE_FACTORY` symbol so that the runtime recognizes it as a service factory constructor.\n */\nexport function defineServiceFactory(\n ctr: ServiceFactoryConstructor\n): MarkedServiceFactoryConstructor {\n const markedCtr = ctr as MarkedServiceFactoryConstructor;\n markedCtr[IS_SERVICE_FACTORY] = true;\n return markedCtr;\n}\n"],"names":[],"mappings":"AAgIA,MAAM,kBAAA,0BAA4B,4BAA4B;AAmBvD,SAAS,qBACZ,GAAA,EAC+B;AAC/B,EAAA,MAAM,SAAA,GAAY,GAAA;AAClB,EAAA,SAAA,CAAU,kBAAkB,CAAA,GAAI,IAAA;AAChC,EAAA,OAAO,SAAA;AACX;;;;"}
|
package/app/AppInstance.d.ts
CHANGED
package/app/AppInstance.js
CHANGED
|
@@ -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);
|
package/app/AppInstance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppInstance.js","sources":["AppInstance.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { computed, effect, reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService, ColorModeValue, ThemeService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START,\n RUNTIME_THEME_SERVICE\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport { DEFAULT_INITIAL_COLOR_MODE } from \"../builtin-services/ThemeServiceImpl\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, I18nConfig, initI18n } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\n\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n private options: AppOptions;\n\n // Public API\n private apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n private api: ApiMethods | undefined; // Present once started\n\n private state: AppState = \"not-started\";\n private rootNode: RootNode;\n private container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n private appRoot: HTMLDivElement | undefined; // .pioneer-root\n private config: ApplicationConfig | undefined;\n private 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,OAA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AA,QAAA,CAAS,MAAA,CAAO,OAAO,CAAC,CAAA;AAAA,IAC5B;AACA,IAAA,QAAA,CAAS,KAAK,cAAc,CAAA;AAAA,EAChC;AAGA,EAAA,MAAM,gBAAA,GAAoC;AAAA,IACtC;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe;AAAA,KACnB;AAAA,IACA;AAAA,MACI,aAAA,EAAe,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;;;;"}
|
|
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;AAC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,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { constant } from '@conterra/reactivity-core';
|
|
1
2
|
import '../i18n/AppIntl.js';
|
|
2
3
|
import { createEmptyPackageIntl } from '../i18n/PackageIntl.js';
|
|
3
4
|
import '../i18n/pick.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
|
|
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:
|
|
27
|
+
intl: constant(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:
|
|
48
|
+
intl: constant(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:
|
|
60
|
+
intl: constant(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:
|
|
81
|
+
intl: constant(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:
|
|
93
|
+
intl: constant(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:
|
|
117
|
+
intl: constant(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
|
|
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 { constant } from \"@conterra/reactivity-core\";\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 intl = createEmptyPackageIntl();\n const apiService = new ServiceRepr({\n name: \"ApiServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApiServiceImpl),\n intl: constant(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: constant(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: constant(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: constant(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: constant(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: constant(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,WAA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A,EAAM,yBAAA;AAAA,IACN,WAAA,EAAa,oBAAA;AAAA,IACb,OAAA,EAAS,qBAAA;AAAA,MACL,CAAC,OAAA,KAAY,IAAI,uBAAA,CAAwB,OAAA,EAAS,WAAW,MAAM;AAAA,KACvE;AAAA,IACA,IAAA,EAAM,SAAS,IAAI,CAAA;AAAA,IACnB,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,SAAS,IAAI,CAAA;AAAA,IACnB,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,SAAS,IAAI;AAAA,GACtB,CAAA;AACL;;;;"}
|
package/i18n/AppIntl.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ReadonlyReactive } from "@conterra/reactivity-core";
|
|
1
2
|
import { ApplicationMetadata } from "../metadata";
|
|
2
3
|
import { PackageIntl } from "./PackageIntl";
|
|
3
4
|
/**
|
|
@@ -5,6 +6,7 @@ import { PackageIntl } from "./PackageIntl";
|
|
|
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,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { reactive, watchValue, computed, constant } from '@conterra/reactivity-core';
|
|
2
|
+
import { createLogger, Error, destroyResource } from '@open-pioneer/core';
|
|
2
3
|
import { sourceId$1 as sourceId } from '../_virtual/source-info.js';
|
|
3
4
|
import { ErrorId } from '../errors.js';
|
|
5
|
+
import { unwrapBox } from '../metadata/ObservableBox.js';
|
|
4
6
|
import { createPackageIntl } from './PackageIntl.js';
|
|
5
7
|
import { getBrowserLocales, I18nConfig } from './pick.js';
|
|
6
8
|
|
|
@@ -22,10 +24,22 @@ async function initI18n(appMetadata, forcedLocale) {
|
|
|
22
24
|
if (LOG.isDebug()) {
|
|
23
25
|
LOG.debug(`Using locale '${locale}' with messages from locale '${messageLocale}'.`);
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
if (messageLocales.includes(messageLocale)) {
|
|
27
|
+
const messages = reactive({});
|
|
28
|
+
if (appMetadata?.loadMessages && messageLocales.includes(messageLocale)) {
|
|
27
29
|
try {
|
|
28
|
-
|
|
30
|
+
const loader = unwrapBox(appMetadata.loadMessages);
|
|
31
|
+
const messagesRecord = await loader(messageLocale);
|
|
32
|
+
if (messagesRecord) {
|
|
33
|
+
messages.value = messagesRecord;
|
|
34
|
+
} else {
|
|
35
|
+
messages.value = {};
|
|
36
|
+
console.warn(
|
|
37
|
+
`I18n messages couldn't be loaded. Check if your runtimeMeta version is not set to 1.0.0.`
|
|
38
|
+
);
|
|
39
|
+
if (LOG.isDebug()) {
|
|
40
|
+
LOG.debug(`appMetadata.loadMessages doesn't support signal value'.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
29
43
|
} catch (e) {
|
|
30
44
|
throw new Error(
|
|
31
45
|
ErrorId.INTERNAL,
|
|
@@ -36,18 +50,81 @@ async function initI18n(appMetadata, forcedLocale) {
|
|
|
36
50
|
);
|
|
37
51
|
}
|
|
38
52
|
}
|
|
53
|
+
let hmrWatch;
|
|
54
|
+
if (import.meta.hot) {
|
|
55
|
+
const handleHotUpdate = async (loader) => {
|
|
56
|
+
const newMessages = await loader?.(messageLocale) ?? {};
|
|
57
|
+
LOG.debug("Applying new i18n messages", newMessages);
|
|
58
|
+
messages.value = newMessages;
|
|
59
|
+
};
|
|
60
|
+
hmrWatch = watchValue(
|
|
61
|
+
() => appMetadata?.loadMessages ? unwrapBox(appMetadata.loadMessages) : void 0,
|
|
62
|
+
(loader) => {
|
|
63
|
+
if (!loader) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
handleHotUpdate(loader).catch((e) => {
|
|
67
|
+
LOG.error(`Failed to load messages after hot reload`, e);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
39
72
|
return {
|
|
40
73
|
locale,
|
|
41
74
|
supportedMessageLocales: messageLocales,
|
|
75
|
+
destroy() {
|
|
76
|
+
hmrWatch = destroyResource(hmrWatch);
|
|
77
|
+
},
|
|
42
78
|
supportsLocale(locale2) {
|
|
43
79
|
return i18nConfig.supportsLocale(locale2);
|
|
44
80
|
},
|
|
45
81
|
createPackageI18n(packageName) {
|
|
46
|
-
|
|
47
|
-
|
|
82
|
+
if (import.meta.hot) {
|
|
83
|
+
const packageMessages = computed(() => messages.value[packageName] ?? {}, {
|
|
84
|
+
equal: shallowRecordEquals
|
|
85
|
+
});
|
|
86
|
+
let firstCall = true;
|
|
87
|
+
const packageIntl = computed(() => {
|
|
88
|
+
if (!firstCall) {
|
|
89
|
+
LOG.info("Updating i18n messages of package", packageName);
|
|
90
|
+
}
|
|
91
|
+
firstCall = false;
|
|
92
|
+
return createPackageIntl(locale, packageMessages.value);
|
|
93
|
+
});
|
|
94
|
+
return packageIntl;
|
|
95
|
+
} else {
|
|
96
|
+
const packageMessages = messages.value[packageName] ?? {};
|
|
97
|
+
const packageIntl = createPackageIntl(locale, packageMessages);
|
|
98
|
+
return constant(packageIntl);
|
|
99
|
+
}
|
|
48
100
|
}
|
|
49
101
|
};
|
|
50
102
|
}
|
|
103
|
+
function shallowRecordEquals(a, b) {
|
|
104
|
+
const keysA = new Set(Object.keys(a));
|
|
105
|
+
const keysB = new Set(Object.keys(b));
|
|
106
|
+
if (keysA.size !== keysB.size) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
for (const k of keysA) {
|
|
110
|
+
if (!keysB.has(k)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (const k of keysB) {
|
|
115
|
+
if (!keysA.has(k)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const k of keysA) {
|
|
120
|
+
const va = a[k];
|
|
121
|
+
const vb = b[k];
|
|
122
|
+
if (va !== vb) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
51
128
|
|
|
52
129
|
export { initI18n };
|
|
53
130
|
//# sourceMappingURL=AppIntl.js.map
|
package/i18n/AppIntl.js.map
CHANGED
|
@@ -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
|
|
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 {\n computed,\n constant,\n reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport { createLogger, destroyResource, Error, Resource } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ErrorId } from \"../errors\";\nimport { ApplicationMetadata, MessageLoader, MessagesRecord } from \"../metadata\";\nimport { unwrapBox } from \"../metadata/ObservableBox\";\nimport { createPackageIntl, PackageIntl } from \"./PackageIntl\";\nimport { getBrowserLocales, I18nConfig } from \"./pick\";\n\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 constant(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":";;;;;;;;AAiBA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAyBjC,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,gDAAg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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;;;;"}
|
package/metadata/index.d.ts
CHANGED
|
@@ -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 (the function is replaced to indicate a reload event for i18n messages).
|
|
30
|
+
*
|
|
27
31
|
* @returns A record of packageName -> (messageId, messageTemplate) entries.
|
|
28
32
|
*/
|
|
29
|
-
loadMessages?:
|
|
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.6.0-dev.
|
|
4
|
+
"version": "4.6.0-dev.20260518093554",
|
|
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.
|
|
18
|
-
"@formatjs/intl": "^4.1.
|
|
17
|
+
"@conterra/reactivity-core": "^0.8.5",
|
|
18
|
+
"@formatjs/intl": "^4.1.11",
|
|
19
19
|
"@chakra-ui/react": "^3.34.0",
|
|
20
20
|
"@emotion/cache": "^11.14.0",
|
|
21
21
|
"@emotion/react": "^11.14.0",
|
|
22
|
-
"react": "^19.2.
|
|
23
|
-
"react-dom": "^19.2.
|
|
24
|
-
"@open-pioneer/core": "4.6.0-dev.
|
|
25
|
-
"@open-pioneer/
|
|
26
|
-
"@open-pioneer/
|
|
22
|
+
"react": "^19.2.6",
|
|
23
|
+
"react-dom": "^19.2.6",
|
|
24
|
+
"@open-pioneer/core": "4.6.0-dev.20260518093554",
|
|
25
|
+
"@open-pioneer/reactivity": "4.6.0-dev.20260518093554",
|
|
26
|
+
"@open-pioneer/base-theme": "4.6.0-dev.20260518093554"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
"./package.json": "./package.json",
|
|
@@ -53,6 +53,9 @@
|
|
|
53
53
|
"references": []
|
|
54
54
|
},
|
|
55
55
|
"properties": [],
|
|
56
|
-
"
|
|
56
|
+
"runtimeMeta": {
|
|
57
|
+
"metadataVersion": "1.1.0"
|
|
58
|
+
},
|
|
59
|
+
"packageFormatVersion": "1.0.1"
|
|
57
60
|
}
|
|
58
61
|
}
|
|
@@ -41,6 +41,7 @@ const CustomChakraProvider = ({
|
|
|
41
41
|
const classes = appRoot.classList;
|
|
42
42
|
classes.toggle("light", effectiveColorMode === "light");
|
|
43
43
|
classes.toggle("dark", effectiveColorMode === "dark");
|
|
44
|
+
appRoot.style.colorScheme = effectiveColorMode;
|
|
44
45
|
}, [appRoot, effectiveColorMode]);
|
|
45
46
|
const cache = useEmotionCache(rootNode);
|
|
46
47
|
return cache && /* @__PURE__ */ jsx(CacheProvider, { value: cache, children: /* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChakraProvider.js","sources":["ChakraProvider.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n ChakraProvider,\n createSystem,\n defaultConfig,\n defineConfig,\n EnvironmentProvider,\n LocaleProvider,\n mergeConfigs,\n SystemConfig,\n SystemStyleObject\n} from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport createCache, { EmotionCache } from \"@emotion/cache\";\nimport { CacheProvider, Global } from \"@emotion/react\";\nimport { config as defaultTrailsConfig } from \"@open-pioneer/base-theme\";\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FC, PropsWithChildren, useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { APP_ROOT_CLASS, getBuiltinStyles, getStylesRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { ColorModeValue } from \"../api\";\n\n/** @internal */\nexport type CustomChakraProviderProps = PropsWithChildren<{\n /**\n * Document root node.\n */\n rootNode: RootNode;\n\n /**\n * Web component root.\n *\n * NOTE: undefined for test support only.\n */\n hostNode?: HTMLElement;\n\n /**\n * Application container (react's render target).\n */\n appRoot: HTMLElement;\n\n /**\n * Chakra system config (can be used to provide custom theme).\n */\n config?: ReadonlyReactive<SystemConfig | undefined>;\n\n /**\n * Application locale for chakra's `LocaleProvider`.\n */\n locale?: string;\n\n /**\n * Custom color mode value.\n */\n colorMode: ReadonlyReactive<ColorModeValue>;\n\n /**\n * Custom CSS used by the application.\n */\n styles?: ReadonlyReactive<string>;\n}>;\n\nconst APP_ROOT_CSS = `.${APP_ROOT_CLASS}`;\n\n/**\n * Wraps the entire react application and configures chakra-ui (styling etc.).\n *\n * Exported so it can be used from the test-utils package.\n *\n * @internal\n */\nexport const CustomChakraProvider: FC<CustomChakraProviderProps> = ({\n rootNode,\n appRoot,\n hostNode,\n children,\n config,\n locale = \"en-US\",\n colorMode,\n styles\n}) => {\n /*\n Setup chakra integration:\n\n 1. Mount styles into the shadow root via emotion\n 2. Use chakra's EnvironmentProvider to tell it about the shadow root context\n 3. Setup global styles correctly (selectors etc.) via chakra's system object\n 4. Render the rest of the application\n */\n\n const systemConfig = useReactiveSnapshot(() => config?.value ?? defaultTrailsConfig, [config]);\n\n const system = useMemo(() => {\n const mergedConfig = mergeConfigs(defaultConfig, systemConfig);\n return createSystem(\n mergedConfig,\n\n // https://www.chakra-ui.com/docs/get-started/environments/shadow-dom\n defineConfig({\n preflight: {\n scope: APP_ROOT_CSS\n },\n cssVarsRoot: APP_ROOT_CSS,\n conditions: redirectLightCondition(mergedConfig.conditions),\n globalCss: redirectHtmlProps(mergedConfig.globalCss)\n })\n );\n }, [systemConfig]);\n\n const effectiveColorMode = useReactiveSnapshot(() => colorMode.value, [colorMode]);\n\n useLayoutEffect(() => {\n const classes = appRoot.classList;\n classes.toggle(\"light\", effectiveColorMode === \"light\");\n classes.toggle(\"dark\", effectiveColorMode === \"dark\");\n }, [appRoot, effectiveColorMode]);\n\n const cache = useEmotionCache(rootNode);\n return (\n cache && (\n <CacheProvider value={cache}>\n <EnvironmentProvider\n value={rootNode}\n // Patched property\n portalNode={appRoot}\n >\n <LocaleProvider locale={locale}>\n <ChakraProvider value={system}>\n <GlobalStyles rootNode={rootNode} hostNode={hostNode} styles={styles} />\n {children}\n </ChakraProvider>\n </LocaleProvider>\n </EnvironmentProvider>\n </CacheProvider>\n )\n );\n};\n\nfunction GlobalStyles(props: {\n rootNode: RootNode;\n hostNode: HTMLElement | undefined;\n styles: ReadonlyReactive<string> | undefined;\n}) {\n const { rootNode, hostNode, styles } = props;\n const builtinStyles = useMemo(() => {\n const css = getBuiltinStyles(rootNode, hostNode);\n return <Global styles={css} />;\n }, [rootNode, hostNode]);\n const appStyles = useReactiveSnapshot(() => {\n const css = styles?.value;\n return css && <Global styles={css} />;\n }, [styles]);\n return (\n <>\n {builtinStyles}\n {appStyles}\n </>\n );\n}\n\nfunction redirectHtmlProps(\n css: Record<string, SystemStyleObject> | undefined\n): Record<string, SystemStyleObject> {\n const { html, ...rest } = css ?? {};\n if (!html) {\n throw new Error(ErrorId.INTERNAL, \"Expected global rules on html element.\");\n }\n // Take default html styles and apply them to the host element instead\n return {\n ...rest,\n [APP_ROOT_CSS]: html\n };\n}\n\nfunction redirectLightCondition(\n conditions: Record<string, unknown> | undefined\n): Record<string, unknown> {\n // Make sure light mode tokens are applied\n return {\n ...conditions,\n // Before: \":root &, .light &\"\n light: `${APP_ROOT_CSS} &, .light &`\n };\n}\n\nfunction useEmotionCache(rootNode: RootNode): EmotionCache | undefined {\n const stylesRoot = useMemo(() => getStylesRoot(rootNode), [rootNode]);\n\n const [cache, setCache] = useState<EmotionCache | undefined>();\n useEffect(() => {\n const cache = createCache({\n key: \"css\",\n container: stylesRoot\n });\n\n // Disable useless warnings like `The pseudo class \":nth-child\" is potentially unsafe when doing server-side rendering. Try changing it to \":nth-of-type\".`\n // See: https://github.com/emotion-js/emotion/issues/1105#issuecomment-557726922\n cache.compat = true;\n\n setCache(cache);\n return () => {\n setCache(undefined);\n for (const tag of cache.sheet.tags) {\n tag.remove();\n }\n };\n }, [stylesRoot]);\n return cache;\n}\n"],"names":["config","defaultTrailsConfig","cache"],"mappings":";;;;;;;;;;;AAgEA,MAAM,YAAA,GAAe,IAAI,cAAc,CAAA,CAAA;AAShC,MAAM,uBAAsD,CAAC;AAAA,EAChE,QAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,UACAA,QAAA;AAAA,EACA,MAAA,GAAS,OAAA;AAAA,EACT,SAAA;AAAA,EACA;AACJ,CAAA,KAAM;AAUF,EAAA,MAAM,YAAA,GAAe,oBAAoB,MAAMA,QAAA,EAAQ,SAASC,MAAA,EAAqB,CAACD,QAAM,CAAC,CAAA;AAE7F,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAM;AACzB,IAAA,MAAM,YAAA,GAAe,YAAA,CAAa,aAAA,EAAe,YAAY,CAAA;AAC7D,IAAA,OAAO,YAAA;AAAA,MACH,YAAA;AAAA;AAAA,MAGA,YAAA,CAAa;AAAA,QACT,SAAA,EAAW;AAAA,UACP,KAAA,EAAO;AAAA,SACX;AAAA,QACA,WAAA,EAAa,YAAA;AAAA,QACb,UAAA,EAAY,sBAAA,CAAuB,YAAA,CAAa,UAAU,CAAA;AAAA,QAC1D,SAAA,EAAW,iBAAA,CAAkB,YAAA,CAAa,SAAS;AAAA,OACtD;AAAA,KACL;AAAA,EACJ,CAAA,EAAG,CAAC,YAAY,CAAC,CAAA;AAEjB,EAAA,MAAM,qBAAqB,mBAAA,CAAoB,MAAM,UAAU,KAAA,EAAO,CAAC,SAAS,CAAC,CAAA;AAEjF,EAAA,eAAA,CAAgB,MAAM;AAClB,IAAA,MAAM,UAAU,OAAA,CAAQ,SAAA;AACxB,IAAA,OAAA,CAAQ,MAAA,CAAO,OAAA,EAAS,kBAAA,KAAuB,OAAO,CAAA;AACtD,IAAA,OAAA,CAAQ,MAAA,CAAO,MAAA,EAAQ,kBAAA,KAAuB,MAAM,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"ChakraProvider.js","sources":["ChakraProvider.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n ChakraProvider,\n createSystem,\n defaultConfig,\n defineConfig,\n EnvironmentProvider,\n LocaleProvider,\n mergeConfigs,\n SystemConfig,\n SystemStyleObject\n} from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport createCache, { EmotionCache } from \"@emotion/cache\";\nimport { CacheProvider, Global } from \"@emotion/react\";\nimport { config as defaultTrailsConfig } from \"@open-pioneer/base-theme\";\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FC, PropsWithChildren, useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { APP_ROOT_CLASS, getBuiltinStyles, getStylesRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { ColorModeValue } from \"../api\";\n\n/** @internal */\nexport type CustomChakraProviderProps = PropsWithChildren<{\n /**\n * Document root node.\n */\n rootNode: RootNode;\n\n /**\n * Web component root.\n *\n * NOTE: undefined for test support only.\n */\n hostNode?: HTMLElement;\n\n /**\n * Application container (react's render target).\n */\n appRoot: HTMLElement;\n\n /**\n * Chakra system config (can be used to provide custom theme).\n */\n config?: ReadonlyReactive<SystemConfig | undefined>;\n\n /**\n * Application locale for chakra's `LocaleProvider`.\n */\n locale?: string;\n\n /**\n * Custom color mode value.\n */\n colorMode: ReadonlyReactive<ColorModeValue>;\n\n /**\n * Custom CSS used by the application.\n */\n styles?: ReadonlyReactive<string>;\n}>;\n\nconst APP_ROOT_CSS = `.${APP_ROOT_CLASS}`;\n\n/**\n * Wraps the entire react application and configures chakra-ui (styling etc.).\n *\n * Exported so it can be used from the test-utils package.\n *\n * @internal\n */\nexport const CustomChakraProvider: FC<CustomChakraProviderProps> = ({\n rootNode,\n appRoot,\n hostNode,\n children,\n config,\n locale = \"en-US\",\n colorMode,\n styles\n}) => {\n /*\n Setup chakra integration:\n\n 1. Mount styles into the shadow root via emotion\n 2. Use chakra's EnvironmentProvider to tell it about the shadow root context\n 3. Setup global styles correctly (selectors etc.) via chakra's system object\n 4. Render the rest of the application\n */\n\n const systemConfig = useReactiveSnapshot(() => config?.value ?? defaultTrailsConfig, [config]);\n\n const system = useMemo(() => {\n const mergedConfig = mergeConfigs(defaultConfig, systemConfig);\n return createSystem(\n mergedConfig,\n\n // https://www.chakra-ui.com/docs/get-started/environments/shadow-dom\n defineConfig({\n preflight: {\n scope: APP_ROOT_CSS\n },\n cssVarsRoot: APP_ROOT_CSS,\n conditions: redirectLightCondition(mergedConfig.conditions),\n globalCss: redirectHtmlProps(mergedConfig.globalCss)\n })\n );\n }, [systemConfig]);\n\n const effectiveColorMode = useReactiveSnapshot(() => colorMode.value, [colorMode]);\n\n useLayoutEffect(() => {\n const classes = appRoot.classList;\n classes.toggle(\"light\", effectiveColorMode === \"light\");\n classes.toggle(\"dark\", effectiveColorMode === \"dark\");\n appRoot.style.colorScheme = effectiveColorMode;\n }, [appRoot, effectiveColorMode]);\n\n const cache = useEmotionCache(rootNode);\n return (\n cache && (\n <CacheProvider value={cache}>\n <EnvironmentProvider\n value={rootNode}\n // Patched property\n portalNode={appRoot}\n >\n <LocaleProvider locale={locale}>\n <ChakraProvider value={system}>\n <GlobalStyles rootNode={rootNode} hostNode={hostNode} styles={styles} />\n {children}\n </ChakraProvider>\n </LocaleProvider>\n </EnvironmentProvider>\n </CacheProvider>\n )\n );\n};\n\nfunction GlobalStyles(props: {\n rootNode: RootNode;\n hostNode: HTMLElement | undefined;\n styles: ReadonlyReactive<string> | undefined;\n}) {\n const { rootNode, hostNode, styles } = props;\n const builtinStyles = useMemo(() => {\n const css = getBuiltinStyles(rootNode, hostNode);\n return <Global styles={css} />;\n }, [rootNode, hostNode]);\n const appStyles = useReactiveSnapshot(() => {\n const css = styles?.value;\n return css && <Global styles={css} />;\n }, [styles]);\n return (\n <>\n {builtinStyles}\n {appStyles}\n </>\n );\n}\n\nfunction redirectHtmlProps(\n css: Record<string, SystemStyleObject> | undefined\n): Record<string, SystemStyleObject> {\n const { html, ...rest } = css ?? {};\n if (!html) {\n throw new Error(ErrorId.INTERNAL, \"Expected global rules on html element.\");\n }\n // Take default html styles and apply them to the host element instead\n return {\n ...rest,\n [APP_ROOT_CSS]: html\n };\n}\n\nfunction redirectLightCondition(\n conditions: Record<string, unknown> | undefined\n): Record<string, unknown> {\n // Make sure light mode tokens are applied\n return {\n ...conditions,\n // Before: \":root &, .light &\"\n light: `${APP_ROOT_CSS} &, .light &`\n };\n}\n\nfunction useEmotionCache(rootNode: RootNode): EmotionCache | undefined {\n const stylesRoot = useMemo(() => getStylesRoot(rootNode), [rootNode]);\n\n const [cache, setCache] = useState<EmotionCache | undefined>();\n useEffect(() => {\n const cache = createCache({\n key: \"css\",\n container: stylesRoot\n });\n\n // Disable useless warnings like `The pseudo class \":nth-child\" is potentially unsafe when doing server-side rendering. Try changing it to \":nth-of-type\".`\n // See: https://github.com/emotion-js/emotion/issues/1105#issuecomment-557726922\n cache.compat = true;\n\n setCache(cache);\n return () => {\n setCache(undefined);\n for (const tag of cache.sheet.tags) {\n tag.remove();\n }\n };\n }, [styles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 -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":";;
|
|
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,OA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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,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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,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
|
-
|
|
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
|
|
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 {
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
|
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 {
|
|
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,GAAkB,mBAAA,CAAoB,IAAA,EAAM,UAAA,EAAY,gBAAgB,CAAA;AAC9E,IAAA,MAAM,WAAW,MAAA,CAAO,OAAA,CAAQ,KAAK,QAAA,IAAY,EAAE,CAAA,CAAE,GAAA;AAAA,MACjD,CAAC,CAACA,KAAAA,EAAM,WAAW,CAAA,KAAM;AACrB,QAAA,IAAIA,KAAAA,KAAS,YAAY,IAAA,EAAM;AAC3B,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,gBAAA;AAAA,YACR;AAAA,WACJ;AAAA,QACJ;AACA,QAAA,OAAO,YAAY,MAAA,CAAO,IAAA,CAAK,IAAA,EAAM,WAAA,EAAa,MAAM,eAAe,CAAA;AAAA,MAC3E;AAAA,KACJ;AACA,IAAA,MAAM,YAAA,GAAe,IAAA,CAAK,EAAA,EAAI,UAAA,EAAY,GAAA,CAAI,CAAC,GAAA,KAAQ,k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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
|
-
import { Service, ServiceConstructor, ServiceOptions
|
|
4
|
+
import { MarkedServiceFactoryConstructor, 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;
|
|
@@ -14,7 +15,7 @@ export interface ServiceReprOptions {
|
|
|
14
15
|
name: string;
|
|
15
16
|
packageName: string;
|
|
16
17
|
factory: ServiceInstanceFactory;
|
|
17
|
-
intl: PackageIntl
|
|
18
|
+
intl: ReadonlyReactive<PackageIntl>;
|
|
18
19
|
dependencies?: ServiceDependency[];
|
|
19
20
|
interfaces?: InterfaceSpec[];
|
|
20
21
|
properties?: Record<string, unknown>;
|
|
@@ -24,7 +25,7 @@ export interface ServiceReprOptions {
|
|
|
24
25
|
* `this.instance` is the actual service instance (when constructed).
|
|
25
26
|
*/
|
|
26
27
|
export declare class ServiceRepr {
|
|
27
|
-
static create(packageName: string, data: ServiceMetadata, intl: PackageIntl
|
|
28
|
+
static create(packageName: string, data: ServiceMetadata, intl: ReadonlyReactive<PackageIntl>, properties?: Record<string, unknown>): ServiceRepr;
|
|
28
29
|
/** Unique id of this service. Contains the package name and the service name. */
|
|
29
30
|
readonly id: string;
|
|
30
31
|
/** Name of this service in it's package. */
|
|
@@ -32,7 +33,7 @@ export declare class ServiceRepr {
|
|
|
32
33
|
/** Name of the parent package. */
|
|
33
34
|
readonly packageName: string;
|
|
34
35
|
/** Locale-dependant i18n messages. */
|
|
35
|
-
readonly intl: PackageIntl
|
|
36
|
+
readonly intl: ReadonlyReactive<PackageIntl>;
|
|
36
37
|
/** Service properties made available via the service's constructor. */
|
|
37
38
|
readonly properties: Readonly<Record<string, unknown>>;
|
|
38
39
|
/** Dependencies required by the service constructor. */
|
|
@@ -47,6 +48,8 @@ export declare class ServiceRepr {
|
|
|
47
48
|
private _state;
|
|
48
49
|
/** Service instance, once constructed. */
|
|
49
50
|
private _instance;
|
|
51
|
+
/** Used in dev mode only. */
|
|
52
|
+
private _hmrState;
|
|
50
53
|
constructor(options: ServiceReprOptions);
|
|
51
54
|
/** Returns the current service instance or undefined if the service has not been constructed. */
|
|
52
55
|
get instance(): Service | undefined;
|
|
@@ -1,8 +1,16 @@
|
|
|
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
4
|
import { IS_SERVICE_FACTORY } from '../Service.js';
|
|
3
|
-
import { Error } from '@open-pioneer/core';
|
|
4
5
|
import { parseReferenceSpec } from './InterfaceSpec.js';
|
|
5
6
|
|
|
7
|
+
const LOG = createLogger("runtime:ServiceRepr");
|
|
8
|
+
const intlDeprecation = deprecated({
|
|
9
|
+
name: "ServiceOptions.intl",
|
|
10
|
+
packageName: "@open-pioneer/runtime",
|
|
11
|
+
since: "4.5.1",
|
|
12
|
+
alternative: "use currentIntl instead and watch for changes where appropriate"
|
|
13
|
+
});
|
|
6
14
|
class ServiceRepr {
|
|
7
15
|
static create(packageName, data, intl, properties) {
|
|
8
16
|
const clazz = data.clazz;
|
|
@@ -54,6 +62,8 @@ class ServiceRepr {
|
|
|
54
62
|
_state = "not-constructed";
|
|
55
63
|
/** Service instance, once constructed. */
|
|
56
64
|
_instance = void 0;
|
|
65
|
+
/** Used in dev mode only. */
|
|
66
|
+
_hmrState = void 0;
|
|
57
67
|
constructor(options) {
|
|
58
68
|
const {
|
|
59
69
|
name,
|
|
@@ -128,11 +138,20 @@ class ServiceRepr {
|
|
|
128
138
|
"Inconsistent state: service is not being constructed."
|
|
129
139
|
);
|
|
130
140
|
}
|
|
141
|
+
const intl = this.intl;
|
|
142
|
+
const hmrState = this._hmrState = /* @__PURE__ */ createHmrState(this.id, intl);
|
|
131
143
|
try {
|
|
132
144
|
this._instance = this.factory.create({
|
|
133
145
|
...options,
|
|
134
146
|
properties: this.properties,
|
|
135
|
-
intl
|
|
147
|
+
get intl() {
|
|
148
|
+
intlDeprecation();
|
|
149
|
+
if (import.meta.hot) {
|
|
150
|
+
hmrState?.onIntlUsed();
|
|
151
|
+
}
|
|
152
|
+
return intl.value;
|
|
153
|
+
},
|
|
154
|
+
currentIntl: this.intl
|
|
136
155
|
});
|
|
137
156
|
this._state = "constructed";
|
|
138
157
|
this._useCount = 1;
|
|
@@ -149,6 +168,7 @@ class ServiceRepr {
|
|
|
149
168
|
if (this._instance) {
|
|
150
169
|
try {
|
|
151
170
|
this.factory.destroy(this._instance);
|
|
171
|
+
this._hmrState = destroyResource(this._hmrState);
|
|
152
172
|
} catch (e) {
|
|
153
173
|
throw new Error(
|
|
154
174
|
ErrorId.SERVICE_DESTRUCTION_FAILED,
|
|
@@ -195,6 +215,7 @@ class ServiceFactoryInstanceFactory {
|
|
|
195
215
|
constructor(_facClazz) {
|
|
196
216
|
this._facClazz = _facClazz;
|
|
197
217
|
}
|
|
218
|
+
_facClazz;
|
|
198
219
|
_fac = void 0;
|
|
199
220
|
create(options) {
|
|
200
221
|
const fac = new this._facClazz(options);
|
|
@@ -224,6 +245,33 @@ function createFunctionFactory(create) {
|
|
|
224
245
|
}
|
|
225
246
|
};
|
|
226
247
|
}
|
|
248
|
+
function createHmrState(serviceId, intl) {
|
|
249
|
+
let hmrState;
|
|
250
|
+
if (import.meta.hot) {
|
|
251
|
+
let intlWatch = void 0;
|
|
252
|
+
hmrState = {
|
|
253
|
+
destroy() {
|
|
254
|
+
intlWatch = destroyResource(intlWatch);
|
|
255
|
+
},
|
|
256
|
+
onIntlUsed() {
|
|
257
|
+
if (intlWatch) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
intlWatch = watchValue(
|
|
261
|
+
() => intl.value,
|
|
262
|
+
(_newIntl, _, context) => {
|
|
263
|
+
LOG.warn(
|
|
264
|
+
`Service ${serviceId} has used the deprecated 'intl' option but messages have changed. Hot reloading of intl changes is only implemented with 'currentIntl'. Triggering full reload.`
|
|
265
|
+
);
|
|
266
|
+
context.destroy();
|
|
267
|
+
window.location.reload();
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return hmrState;
|
|
274
|
+
}
|
|
227
275
|
const SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;
|
|
228
276
|
function isValidServiceName(name) {
|
|
229
277
|
return SERVICE_NAME_REGEX.test(name);
|
|
@@ -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 {\n Service,\n ServiceConstructor,\n ServiceOptions,\n IS_SERVICE_FACTORY,\n ServiceFactory,\n MarkedServiceFactoryConstructor\n} 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 ServiceInstanceFactory {\n create(options: ServiceOptions): Service;\n destroy(srv: Service): void;\n}\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceInstanceFactory;\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 = createConstructorFactory(clazz);\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: ServiceInstanceFactory;\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 = this.factory.create({\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.factory.destroy(this._instance);\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> | MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n // check if factory is a service factory constructor (has the IS_SERVICE_FACTORY symbol)\n if (IS_SERVICE_FACTORY in clazz) {\n return createFactoryForServiceFactory(clazz);\n }\n // Is a regular service constructor\n return {\n create(options: ServiceOptions<T>) {\n return new clazz(options);\n },\n destroy(instance: Service<T>) {\n instance.destroy?.();\n }\n };\n}\n\nexport function createFactoryForServiceFactory<T extends {}>(\n facClazz: MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n return new ServiceFactoryInstanceFactory(facClazz);\n}\n\nclass ServiceFactoryInstanceFactory<T extends {}> implements ServiceInstanceFactory {\n private _fac: ServiceFactory | undefined = undefined;\n\n constructor(private _facClazz: MarkedServiceFactoryConstructor<T>) {}\n\n create(options: ServiceOptions<T>) {\n const fac = new this._facClazz(options);\n const instance = fac.createService();\n this._fac = fac;\n return instance;\n }\n\n destroy(srv: Service) {\n if (!this._fac) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service factory instance is not present.\"\n );\n }\n try {\n this._fac.destroyService?.(srv);\n } finally {\n this._fac = undefined;\n }\n }\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): ServiceInstanceFactory {\n return {\n create,\n destroy(srv) {\n srv.destroy?.();\n }\n };\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;AAuCO,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,UACH,aAAA,EAAeA,KAAAA;AAAA,UACf,GAAG,mBAAmB,iBAAiB;AAAA,SAC3C;AAAA,MACJ;AAAA,KACJ;AACA,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,QAAA,EAAU,GAAA,CAAmB,CAAC,CAAA,KAAM;AACxD,MAAA,OAAO;AAAA,QACH,eAAe,CAAA,CAAE,IAAA;AAAA,QACjB,WAAW,CAAA,CAAE;AAAA,OACjB;AAAA,IACJ,CAAC,CAAA;AACD,IAAA,MAAM,OAAA,GAAU,yBAAyB,KAAK,CAAA;AAC9C,IAAA,OAAO,IAAI,WAAA,CAAY;AAAA,MACnB,IAAA;AAAA,MACA,WAAA;AAAA,MACA,OAAA;AAAA,MACA,IAAA;AAAA,MACA,YAAA;AAAA,MACA,UAAA;AAAA,MACA;AAAA,KACH,CAAA;AAAA,EACL;AAAA;AAAA,EAGS,EAAA;AAAA;AAAA,EAGA,IAAA;AAAA;AAAA,EAGA,WAAA;AAAA;AAAA,EAGA,IAAA;AAAA;AAAA,EAGA,UAAA;AAAA;AAAA,EAGA,YAAA;AAAA;AAAA,EAGA,UAAA;AAAA;AAAA,EAGD,SAAA,GAAY,CAAA;AAAA;A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OAAO,OAAA,EAA4B;AAC/B,IAAA,MAAM,GAAA,GAAM,IAAI,IAAA,CAAK,SAAA,CAAU,OAAO,CAAA;AACtC,IAAA,MAAM,QAAA,GAAW,IAAI,aAAA,EAAc;AACnC,IAAA,IAAA,CAAK,IAAA,GAAO,GAAA;AACZ,IAAA,OAAO,QAAA;AAAA,EACX;AAAA,EAEA,QAAQ,GAAA,EAAc;AAClB,IAAA,IAAI,CAAC,KAAK,IAAA,EAAM;AACZ,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,QAAA;AAAA,QACR;AAAA,OACJ;AAAA,IACJ;AACA,IAAA,IAAI;AACA,MAAA,IAAA,CAAK,IAAA,CAAK,iBAAiB,GAAG,CAAA;AAAA,IAClC,CAAA,SAAE;AACE,MAAA,IAAA,CAAK,IAAA,GAAO,MAAA;AAAA,IAChB;AAAA,EACJ;AACJ;AAEO,SAAS,sBACZ,MAAA,EACsB;AACtB,EAAA,OAAO;AAAA,IACH,MAAA;AAAA,IACA,QAAQ,GAAA,EAAK;AACT,MAAA,GAAA,CAAI,OAAA,IAAU;AAAA,IAClB;AAAA,GACJ;AACJ;AAEA,MAAM,kBAAA,GAAqB,gBAAA;AAE3B,SAAS,mBAAmB,IAAA,EAAc;AACtC,EAAA,OAAO,kBAAA,CAAmB,KAAK,IAAI,CAAA;AACvC;;;;"}
|
|
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 {\n IS_SERVICE_FACTORY,\n MarkedServiceFactoryConstructor,\n Service,\n ServiceConstructor,\n ServiceFactory,\n ServiceOptions\n} 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 ServiceInstanceFactory {\n create(options: ServiceOptions): Service;\n destroy(srv: Service): void;\n}\n\nexport interface ServiceReprOptions {\n name: string;\n packageName: string;\n factory: ServiceInstanceFactory;\n intl: ReadonlyReactive<PackageIntl>;\n dependencies?: ServiceDependency[];\n interfaces?: InterfaceSpec[];\n properties?: Record<string, unknown>;\n}\n\ninterface HmrState extends Resource {\n /** Called when usage of `serviceOptions.intl` is detected at runtime. */\n onIntlUsed(): void;\n}\n\nconst intlDeprecation = deprecated({\n name: \"ServiceOptions.intl\",\n packageName: \"@open-pioneer/runtime\",\n since: \"4.5.1\",\n alternative: \"use currentIntl instead and watch for changes where appropriate\"\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 = createConstructorFactory(clazz);\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: ServiceInstanceFactory;\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 intl = this.intl;\n const hmrState = (this._hmrState = /*#__PURE__*/ createHmrState(this.id, intl));\n try {\n this._instance = this.factory.create({\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.factory.destroy(this._instance);\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> | MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n // check if factory is a service factory constructor (has the IS_SERVICE_FACTORY symbol)\n if (IS_SERVICE_FACTORY in clazz) {\n return createFactoryForServiceFactory(clazz);\n }\n // Is a regular service constructor\n return {\n create(options: ServiceOptions<T>) {\n return new clazz(options);\n },\n destroy(instance: Service<T>) {\n instance.destroy?.();\n }\n };\n}\n\nexport function createFactoryForServiceFactory<T extends {}>(\n facClazz: MarkedServiceFactoryConstructor<T>\n): ServiceInstanceFactory {\n return new ServiceFactoryInstanceFactory(facClazz);\n}\n\nclass ServiceFactoryInstanceFactory<T extends {}> implements ServiceInstanceFactory {\n private _fac: ServiceFactory | undefined = undefined;\n\n constructor(private _facClazz: MarkedServiceFactoryConstructor<T>) {}\n\n create(options: ServiceOptions<T>) {\n const fac = new this._facClazz(options);\n const instance = fac.createService();\n this._fac = fac;\n return instance;\n }\n\n destroy(srv: Service) {\n if (!this._fac) {\n throw new Error(\n ErrorId.INTERNAL,\n \"Inconsistent state: service factory instance is not present.\"\n );\n }\n try {\n this._fac.destroyService?.(srv);\n } finally {\n this._fac = undefined;\n }\n }\n}\n\nexport function createFunctionFactory(\n create: (options: ServiceOptions) => Service\n): ServiceInstanceFactory {\n return {\n create,\n destroy(srv) {\n srv.destroy?.();\n }\n };\n}\n\n/**\n * Triggers a full page reload if:\n *\n * - We are in development mode (import.meta.hot) AND\n * - The service uses the deprecated `intl` option AND\n * - The messages changes due to a HMR event\n */\nfunction createHmrState(\n serviceId: string,\n intl: ReadonlyReactive<PackageIntl>\n): HmrState | undefined {\n let hmrState: HmrState | undefined;\n if (import.meta.hot) {\n let intlWatch: Resource | undefined = undefined;\n 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 ${serviceId} has used the deprecated 'intl' option but messages have changed.` +\n ` Hot reloading of intl changes is only implemented ` +\n ` with 'currentIntl'.` +\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 return hmrState;\n}\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9_-]+$/i;\n\nfunction isValidServiceName(name: string) {\n return SERVICE_NAME_REGEX.test(name);\n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