@open-pioneer/runtime 4.7.0-dev.20260713101438 → 4.7.0-dev.20260727091735
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 +176 -175
- package/CustomElement.js +1 -1
- package/CustomElement.js.map +1 -1
- package/DeclaredService.d.ts +1 -1
- package/DeclaredService.js.map +1 -1
- package/Service.js.map +1 -1
- package/app/AppInstance.js +2 -2
- package/app/AppInstance.js.map +1 -1
- package/app/gatherConfig.js.map +1 -1
- package/app/logErrors.js.map +1 -1
- package/builtin-services/ApiServiceImpl.d.ts +1 -1
- package/builtin-services/ApiServiceImpl.js.map +1 -1
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/builtin-services/ApplicationLifecycleEventService.d.ts +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js.map +1 -1
- package/builtin-services/LocaleServiceImpl.js.map +1 -1
- package/builtin-services/NumberParserServiceImpl.js.map +1 -1
- package/builtin-services/ThemeServiceImpl.js.map +1 -1
- package/builtin-services/index.js.map +1 -1
- package/errors.js.map +1 -1
- package/i18n/AppIntl.js.map +1 -1
- package/i18n/PackageIntl.js.map +1 -1
- package/i18n/pick.js.map +1 -1
- package/metadata/ObservableBox.js.map +1 -1
- package/package.json +9 -9
- package/react-integration/ChakraProvider.d.ts +1 -1
- package/react-integration/ChakraProvider.js.map +1 -1
- package/react-integration/ErrorScreen.js.map +1 -1
- package/react-integration/PackageContext.js.map +1 -1
- package/react-integration/ReactIntegration.d.ts +1 -1
- package/react-integration/ReactIntegration.js.map +1 -1
- package/react-integration/hooks.js +1 -1
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/InterfaceSpec.js.map +1 -1
- package/service-layer/PackageRepr.js.map +1 -1
- package/service-layer/ServiceLayer.js.map +1 -1
- package/service-layer/ServiceLookup.js.map +1 -1
- package/service-layer/ServiceRepr.js.map +1 -1
- package/service-layer/verifyDependencies.js.map +1 -1
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 {\n computed,\n constant,\n effect,\n reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService, ColorModeValue, ThemeService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START,\n RUNTIME_LOCALE_SERVICE,\n RUNTIME_THEME_SERVICE\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport { DEFAULT_INITIAL_COLOR_MODE } from \"../builtin-services/ThemeServiceImpl\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, LocalePicker, parseLocale } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\n\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n #options: AppOptions;\n\n // Public API\n #apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n #api: ApiMethods | undefined; // Present once started\n\n #state: AppState = \"not-started\";\n #rootNode: RootNode;\n #container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n #i18n: AppIntl | undefined;\n\n // Unused on purpose for easier debugging.\n // eslint-disable-next-line no-unused-private-class-members\n #appRoot: HTMLDivElement | undefined; // .pioneer-root\n\n // Unused on purpose for easier debugging.\n // eslint-disable-next-line no-unused-private-class-members\n #config: ApplicationConfig | undefined;\n\n #serviceLayer: ServiceLayer | undefined;\n #lifecycleEvents: ApplicationLifecycleEventService | undefined;\n #themeService: ThemeService | undefined;\n #reactIntegration: ReactIntegration | undefined;\n\n #stylesWatch: Resource | undefined;\n #localeWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.#options = options;\n this.#container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.#rootNode = options.rootNode;\n }\n\n /** Current lifecycle state. Exposed (read-only) for tests/debugging via `$inspectElementState`. */\n get state(): AppState {\n return this.#state;\n }\n\n start() {\n if (this.#state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.#state}'`);\n }\n\n this.#state = \"starting\";\n this.#startImpl().catch((e) => {\n if (this.#state === \"destroyed\") return;\n\n logError(e);\n this.#reset();\n this.#state = \"error\";\n this.#showErrorScreen(e);\n });\n }\n\n destroy() {\n if (this.#state === \"destroyed\") {\n return;\n }\n\n // Only call event listener when 'started' was also signalled.\n if (this.#state === \"started\") {\n try {\n this.#triggerApplicationLifecycleEvent(\"before-stop\");\n } catch (e) {\n void e; // Ignored\n }\n }\n this.#state = \"destroyed\";\n this.#reset();\n }\n\n #reset() {\n this.#apiPromise?.reject(createAbortError());\n this.#reactIntegration = destroyResource(this.#reactIntegration);\n this.#container.replaceChildren();\n this.#appRoot = undefined;\n this.#lifecycleEvents = undefined;\n this.#themeService = undefined;\n this.#i18n = destroyResource(this.#i18n);\n this.#serviceLayer = destroyResource(this.#serviceLayer);\n this.#stylesWatch = destroyResource(this.#stylesWatch);\n this.#localeWatch = destroyResource(this.#localeWatch);\n }\n\n whenAPI(): Promise<ApiMethods> {\n if (this.#api) {\n return Promise.resolve(this.#api);\n }\n\n const apiPromise = (this.#apiPromise ??= createManualPromise());\n return apiPromise.promise;\n }\n\n async #startImpl() {\n const { hostElement, elementOptions, overrides } = this.#options;\n const root = this.#rootNode;\n\n // Resolve custom application config\n const config = (this.#config = await gatherConfig(hostElement, elementOptions, overrides));\n this.#checkAbort();\n LOG.debug(\"Application config is\", config);\n\n // TODO (next major): always true (option can be removed).\n // Currently false by default (needs to be enabled) to preserve backwards compatibility.\n const enableLiveLocaleChanges = elementOptions.advanced?.enableLiveLocaleChanges ?? false;\n\n // TODO (next major): Remove restarting code!\n const restartWithLocale = (locale: Intl.Locale | undefined) => {\n // this code is triggered, when the app calls changeLocale while reactive switching is disabled.\n const restart = this.#options.restart;\n const themeService = this.#themeService;\n const colorMode = themeService?.colorMode;\n const chakraSystemConfig = themeService?.systemConfig;\n restart({ locale: locale?.baseName, colorMode, chakraSystemConfig });\n };\n\n // Decide on locale and load i18n messages (if any).\n const i18n = (this.#i18n = await AppIntl.create({\n appMetadata: elementOptions.appMetadata,\n forcedLocale: config.locale,\n restrictSupportedLocales: config.supportedLocales,\n supportsLiveChanges: enableLiveLocaleChanges,\n restartWithLocale\n }));\n this.#checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.#appRoot = createAppRoot());\n this.#localeWatch = watchValue(\n () => i18n.locale.baseName,\n (locale) => {\n appRoot.lang = locale;\n },\n {\n immediate: true\n }\n );\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n // Launch the service layer\n const { serviceLayer, packages } = this.#initServiceLayer({\n container: appRoot,\n properties: config.properties,\n i18n,\n initialColorMode: config.colorMode,\n initialSystemConfig: config.chakraSystemConfig\n });\n this.#lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n const themeService = (this.#themeService = getInternalService<ThemeService>(\n serviceLayer,\n RUNTIME_THEME_SERVICE\n ));\n\n // init api, but do not wait for it\n const apiPromise = this.#initAPI(serviceLayer);\n this.#checkAbort();\n\n // Launch react\n this.#reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: computed(() => i18n.locale.baseName),\n config: computed(() => themeService.systemConfig),\n styles,\n colorMode: computed(() => themeService.colorMode)\n });\n const component = this.#options.elementOptions.component ?? EmptyComponent;\n this.#reactIntegration.render(createElement(component));\n\n // wait for api, to ensure that the \"started\" state is only reached after the API is available.\n // but do not block the react rendering, to allow for a fast Time to Interactive and to show potential errors in the UI even if the API fails.\n await apiPromise;\n this.#checkAbort();\n\n this.#state = \"started\";\n\n this.#triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n /**\n * Returns a signal that contains the application's styles.\n * During development, the signal is updated when the user edits .css files.\n * In production, the signal is static.\n */\n #initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.#options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return constant(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.#stylesWatch = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n #initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n initialColorMode: ColorModeValue | \"system\" | undefined;\n initialSystemConfig: SystemConfig | undefined;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions } = this.#options;\n const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;\n\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n initialColorMode,\n initialSystemConfig,\n appIntl: i18n\n });\n const { serviceLayer, packages } = createServiceLayer({\n packageMetadata,\n builtinPackage,\n properties,\n i18n\n });\n this.#serviceLayer = serviceLayer;\n\n if (LOG.isDebug()) {\n LOG.debug(\"Launching service layer with packages\", Object.fromEntries(packages));\n }\n serviceLayer.start();\n return { serviceLayer, packages };\n }\n\n async #initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = await apiService.getApi();\n this.#checkAbort();\n this.#api = api;\n LOG.debug(\"Application API initialized to\", api);\n this.#apiPromise?.resolve(api);\n } catch (e) {\n const ex = new Error(\n ErrorId.INTERNAL,\n \"Failed to gather the application's API methods.\",\n {\n cause: e\n }\n );\n if (!this.#apiPromise) {\n // no one is waiting yet.\n // keep the error for when they do\n this.#apiPromise = createManualPromise();\n // prevent unhandled rejection if no one is waiting for the API\n this.#apiPromise.promise.catch(() => {});\n }\n this.#apiPromise.reject(ex);\n throw ex;\n }\n }\n\n #triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.#lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n #checkAbort() {\n if (this.#state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n #showErrorScreen(error: globalThis.Error) {\n const userLocales = getBrowserLocales();\n const localePicker = new LocalePicker(\n Object.keys(MESSAGES_BY_LOCALE).map((tag) => parseLocale(tag))\n );\n const { locale, messageLocale } = localePicker.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale.baseName as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale.baseName, messages);\n\n const appRoot = (this.#appRoot = createAppRoot());\n appRoot.lang = locale.baseName;\n appRoot.classList.add(\"pioneer-root-error-screen\");\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n this.#reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.#rootNode,\n hostNode: this.#options.hostElement,\n appRoot: appRoot,\n locale: constant(locale.baseName),\n config: constant(this.#options.elementOptions.chakraSystemConfig),\n styles,\n colorMode: constant(DEFAULT_INITIAL_COLOR_MODE)\n });\n this.#reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppIntl;\n}) {\n const { packageMetadata, properties, builtinPackage, i18n } = config;\n\n let packages: PackageRepr[];\n try {\n packages = createPackages(packageMetadata ?? {}, i18n, properties);\n } catch (e) {\n throw new Error(ErrorId.INVALID_METADATA, \"Failed to parse package metadata.\", {\n cause: e\n });\n }\n\n // Add builtin services defined within this package.\n {\n const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);\n if (index >= 0) {\n packages.splice(index, 1);\n }\n packages.push(builtinPackage);\n }\n\n // Automatically required references (-> forces services to start)\n const forcedReferences: ReferenceSpec[] = [\n {\n interfaceName: RUNTIME_API_SERVICE\n },\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n },\n {\n interfaceName: RUNTIME_LOCALE_SERVICE\n },\n {\n interfaceName: RUNTIME_THEME_SERVICE\n },\n {\n interfaceName: RUNTIME_AUTO_START,\n all: true\n }\n ];\n const serviceLayer = new ServiceLayer(packages, forcedReferences);\n return {\n packages: new Map(packages.map((pkg) => [pkg.name, pkg])),\n serviceLayer: serviceLayer\n };\n}\n\nfunction getInternalService<T = unknown>(serviceLayer: ServiceLayer, interfaceName: string) {\n const result = serviceLayer.getService(\n \"@open-pioneer/runtime\",\n {\n interfaceName\n },\n { ignoreDeclarationCheck: true }\n );\n if (result.type !== \"found\") {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find instance of '${interfaceName}' (result type '${result.type}').` +\n ` This is a builtin service that must be present exactly once.`\n );\n }\n\n return result.value.getInstanceOrThrow() as T;\n}\n"],"names":["themeService"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAwB1B,MAAM,WAAA,CAAY;AAAA,EACrB,QAAA;AAAA;AAAA,EAGA,WAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EAEA,MAAA,GAAmB,aAAA;AAAA,EACnB,SAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,KAAA;AAAA;AAAA;AAAA,EAIA,QAAA;AAAA;AAAA;AAAA;AAAA,EAIA,OAAA;AAAA,EAEA,aAAA;AAAA,EACA,gBAAA;AAAA,EACA,aAAA;AAAA,EACA,iBAAA;AAAA,EAEA,YAAA;AAAA,EACA,YAAA;AAAA,EAEA,YAAY,OAAA,EAAqB;AAC7B,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAChB,IAAA,IAAA,CAAK,aAAa,YAAA,CAAa,OAAA,CAAQ,QAAQ,CAAA,GAAI,OAAA,CAAQ,WAAW,OAAA,CAAQ,WAAA;AAC9E,IAAA,IAAA,CAAK,YAAY,OAAA,CAAQ,QAAA;AAAA,EAC7B;AAAA;AAAA,EAGA,IAAI,KAAA,GAAkB;AAClB,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EAChB;AAAA,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,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\n\nimport { SystemConfig } from \"@chakra-ui/react\";\nimport {\n computed,\n constant,\n effect,\n reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport {\n createAbortError,\n createLogger,\n createManualPromise,\n destroyResource,\n Error,\n ManualPromise,\n Resource,\n throwAbortError\n} from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { createElement } from \"react\";\nimport { ApiMethods, ApiService, ColorModeValue, ThemeService } from \"../api\";\nimport {\n createBuiltinPackage,\n RUNTIME_API_SERVICE,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n RUNTIME_AUTO_START,\n RUNTIME_LOCALE_SERVICE,\n RUNTIME_THEME_SERVICE\n} from \"../builtin-services\";\nimport { ApplicationLifecycleEventService } from \"../builtin-services/ApplicationLifecycleEventService\";\nimport { DEFAULT_INITIAL_COLOR_MODE } from \"../builtin-services/ThemeServiceImpl\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { createAppRoot, isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, createPackageIntl, getBrowserLocales, LocalePicker, parseLocale } from \"../i18n\";\nimport { PackageMetadata } from \"../metadata\";\nimport { ErrorScreen, MESSAGES_BY_LOCALE } from \"../react-integration/ErrorScreen\";\nimport { EmptyComponent, ReactIntegration } from \"../react-integration/ReactIntegration\";\nimport { ReferenceSpec } from \"../service-layer/InterfaceSpec\";\nimport { createPackages, PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { gatherConfig } from \"./gatherConfig\";\nimport { logError } from \"./logErrors\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface AppOptions {\n /** The root node that contains the application. */\n rootNode: RootNode;\n\n /** The HTML element that embeds the application. */\n hostElement: HTMLElement;\n\n /** Trails options for the application. */\n elementOptions: CustomElementOptions;\n\n /** These have higher priority than the options in `elementOptions`. */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * A callback to restart the application with new options.\n * Currently only used for reloading with a certain locale.\n */\n restart: (overrides?: ApplicationOverrides) => void;\n}\n\nexport type AppState = \"not-started\" | \"starting\" | \"started\" | \"destroyed\" | \"error\";\n\nexport class AppInstance {\n #options: AppOptions;\n\n // Public API\n #apiPromise: ManualPromise<ApiMethods> | undefined; // Present when callers are waiting for the API\n #api: ApiMethods | undefined; // Present once started\n\n #state: AppState = \"not-started\";\n #rootNode: RootNode;\n #container: HTMLElement | ShadowRoot; // parent of .pioneer-root\n #i18n: AppIntl | undefined;\n\n // Unused on purpose for easier debugging.\n // oxlint-disable-next-line no-unused-private-class-members\n #appRoot: HTMLDivElement | undefined; // .pioneer-root\n\n // Unused on purpose for easier debugging.\n // oxlint-disable-next-line no-unused-private-class-members\n #config: ApplicationConfig | undefined;\n\n #serviceLayer: ServiceLayer | undefined;\n #lifecycleEvents: ApplicationLifecycleEventService | undefined;\n #themeService: ThemeService | undefined;\n #reactIntegration: ReactIntegration | undefined;\n\n #stylesWatch: Resource | undefined;\n #localeWatch: Resource | undefined;\n\n constructor(options: AppOptions) {\n this.#options = options;\n this.#container = isShadowRoot(options.rootNode) ? options.rootNode : options.hostElement;\n this.#rootNode = options.rootNode;\n }\n\n /** Current lifecycle state. Exposed (read-only) for tests/debugging via `$inspectElementState`. */\n get state(): AppState {\n return this.#state;\n }\n\n start() {\n if (this.#state !== \"not-started\") {\n throw new Error(ErrorId.INTERNAL, `Cannot start element in state '${this.#state}'`);\n }\n\n this.#state = \"starting\";\n this.#startImpl().catch((e) => {\n if (this.#state === \"destroyed\") return;\n\n logError(e);\n this.#reset();\n this.#state = \"error\";\n this.#showErrorScreen(e);\n });\n }\n\n destroy() {\n if (this.#state === \"destroyed\") {\n return;\n }\n\n // Only call event listener when 'started' was also signalled.\n if (this.#state === \"started\") {\n try {\n this.#triggerApplicationLifecycleEvent(\"before-stop\");\n } catch (e) {\n void e; // Ignored\n }\n }\n this.#state = \"destroyed\";\n this.#reset();\n }\n\n #reset() {\n this.#apiPromise?.reject(createAbortError());\n this.#reactIntegration = destroyResource(this.#reactIntegration);\n this.#container.replaceChildren();\n this.#appRoot = undefined;\n this.#lifecycleEvents = undefined;\n this.#themeService = undefined;\n this.#i18n = destroyResource(this.#i18n);\n this.#serviceLayer = destroyResource(this.#serviceLayer);\n this.#stylesWatch = destroyResource(this.#stylesWatch);\n this.#localeWatch = destroyResource(this.#localeWatch);\n }\n\n whenAPI(): Promise<ApiMethods> {\n if (this.#api) {\n return Promise.resolve(this.#api);\n }\n\n const apiPromise = (this.#apiPromise ??= createManualPromise());\n return apiPromise.promise;\n }\n\n async #startImpl() {\n const { hostElement, elementOptions, overrides } = this.#options;\n const root = this.#rootNode;\n\n // Resolve custom application config\n const config = (this.#config = await gatherConfig(hostElement, elementOptions, overrides));\n this.#checkAbort();\n LOG.debug(\"Application config is\", config);\n\n // TODO (next major): always true (option can be removed).\n // Currently false by default (needs to be enabled) to preserve backwards compatibility.\n const enableLiveLocaleChanges = elementOptions.advanced?.enableLiveLocaleChanges ?? false;\n\n // TODO (next major): Remove restarting code!\n const restartWithLocale = (locale: Intl.Locale | undefined) => {\n // this code is triggered, when the app calls changeLocale while reactive switching is disabled.\n const restart = this.#options.restart;\n const themeService = this.#themeService;\n const colorMode = themeService?.colorMode;\n const chakraSystemConfig = themeService?.systemConfig;\n restart({ locale: locale?.baseName, colorMode, chakraSystemConfig });\n };\n\n // Decide on locale and load i18n messages (if any).\n const i18n = (this.#i18n = await AppIntl.create({\n appMetadata: elementOptions.appMetadata,\n forcedLocale: config.locale,\n restrictSupportedLocales: config.supportedLocales,\n supportsLiveChanges: enableLiveLocaleChanges,\n restartWithLocale\n }));\n this.#checkAbort();\n\n // Setup application root node in the shadow dom\n const appRoot = (this.#appRoot = createAppRoot());\n this.#localeWatch = watchValue(\n () => i18n.locale.baseName,\n (locale) => {\n appRoot.lang = locale;\n },\n {\n immediate: true\n }\n );\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n // Launch the service layer\n const { serviceLayer, packages } = this.#initServiceLayer({\n container: appRoot,\n properties: config.properties,\n i18n,\n initialColorMode: config.colorMode,\n initialSystemConfig: config.chakraSystemConfig\n });\n this.#lifecycleEvents = getInternalService<ApplicationLifecycleEventService>(\n serviceLayer,\n RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n );\n const themeService = (this.#themeService = getInternalService<ThemeService>(\n serviceLayer,\n RUNTIME_THEME_SERVICE\n ));\n\n // init api, but do not wait for it\n const apiPromise = this.#initAPI(serviceLayer);\n this.#checkAbort();\n\n // Launch react\n this.#reactIntegration = ReactIntegration.createForApp({\n rootNode: root,\n hostNode: hostElement,\n appRoot: appRoot,\n serviceLayer,\n packages,\n locale: computed(() => i18n.locale.baseName),\n config: computed(() => themeService.systemConfig),\n styles,\n colorMode: computed(() => themeService.colorMode)\n });\n const component = this.#options.elementOptions.component ?? EmptyComponent;\n this.#reactIntegration.render(createElement(component));\n\n // wait for api, to ensure that the \"started\" state is only reached after the API is available.\n // but do not block the react rendering, to allow for a fast Time to Interactive and to show potential errors in the UI even if the API fails.\n await apiPromise;\n this.#checkAbort();\n\n this.#state = \"started\";\n\n this.#triggerApplicationLifecycleEvent(\"after-start\");\n LOG.debug(\"Application started\");\n }\n\n /**\n * Returns a signal that contains the application's styles.\n * During development, the signal is updated when the user edits .css files.\n * In production, the signal is static.\n */\n #initStylesSignal(): ReadonlyReactive<string> {\n const stylesBox = this.#options.elementOptions.appMetadata?.styles;\n if (!stylesBox) {\n return constant(\"\");\n }\n\n const signal = reactive(stylesBox.value);\n if (import.meta.hot) {\n this.#stylesWatch = effect(\n () => {\n signal.value = stylesBox.value;\n LOG.debug(\"Application styles changed\");\n },\n { dispatch: \"sync\" }\n );\n }\n return signal;\n }\n\n #initServiceLayer(config: {\n container: HTMLDivElement;\n properties: ApplicationProperties;\n i18n: AppIntl;\n initialColorMode: ColorModeValue | \"system\" | undefined;\n initialSystemConfig: SystemConfig | undefined;\n }) {\n const { hostElement, rootNode: shadowRoot, elementOptions } = this.#options;\n const { container, properties, i18n, initialColorMode, initialSystemConfig } = config;\n\n const packageMetadata = elementOptions.appMetadata?.packages ?? {};\n const builtinPackage = createBuiltinPackage({\n host: hostElement,\n rootNode: shadowRoot,\n container: container,\n initialColorMode,\n initialSystemConfig,\n appIntl: i18n\n });\n const { serviceLayer, packages } = createServiceLayer({\n packageMetadata,\n builtinPackage,\n properties,\n i18n\n });\n this.#serviceLayer = serviceLayer;\n\n if (LOG.isDebug()) {\n LOG.debug(\"Launching service layer with packages\", Object.fromEntries(packages));\n }\n serviceLayer.start();\n return { serviceLayer, packages };\n }\n\n async #initAPI(serviceLayer: ServiceLayer) {\n const apiService = getInternalService<ApiService>(serviceLayer, RUNTIME_API_SERVICE);\n try {\n const api = await apiService.getApi();\n this.#checkAbort();\n this.#api = api;\n LOG.debug(\"Application API initialized to\", api);\n this.#apiPromise?.resolve(api);\n } catch (e) {\n const ex = new Error(\n ErrorId.INTERNAL,\n \"Failed to gather the application's API methods.\",\n {\n cause: e\n }\n );\n if (!this.#apiPromise) {\n // no one is waiting yet.\n // keep the error for when they do\n this.#apiPromise = createManualPromise();\n // prevent unhandled rejection if no one is waiting for the API\n this.#apiPromise.promise.catch(() => {});\n }\n this.#apiPromise.reject(ex);\n throw ex;\n }\n }\n\n #triggerApplicationLifecycleEvent(event: \"after-start\" | \"before-stop\") {\n this.#lifecycleEvents?.emitLifecycleEvent(event);\n }\n\n #checkAbort() {\n if (this.#state === \"destroyed\") {\n throwAbortError();\n }\n }\n\n #showErrorScreen(error: globalThis.Error) {\n const userLocales = getBrowserLocales();\n const localePicker = new LocalePicker(\n Object.keys(MESSAGES_BY_LOCALE).map((tag) => parseLocale(tag))\n );\n const { locale, messageLocale } = localePicker.pickSupportedLocale(undefined, userLocales);\n const messages =\n MESSAGES_BY_LOCALE[messageLocale.baseName as keyof typeof MESSAGES_BY_LOCALE] ??\n MESSAGES_BY_LOCALE[\"en\"];\n const intl = createPackageIntl(locale.baseName, messages);\n\n const appRoot = (this.#appRoot = createAppRoot());\n appRoot.lang = locale.baseName;\n appRoot.classList.add(\"pioneer-root-error-screen\");\n this.#container.appendChild(appRoot);\n\n const styles = this.#initStylesSignal();\n\n this.#reactIntegration = ReactIntegration.createForErrorScreen({\n rootNode: this.#rootNode,\n hostNode: this.#options.hostElement,\n appRoot: appRoot,\n locale: constant(locale.baseName),\n config: constant(this.#options.elementOptions.chakraSystemConfig),\n styles,\n colorMode: constant(DEFAULT_INITIAL_COLOR_MODE)\n });\n this.#reactIntegration.render(createElement(ErrorScreen, { intl, error }));\n }\n}\n\nfunction createServiceLayer(config: {\n packageMetadata: Record<string, PackageMetadata> | undefined;\n properties: ApplicationProperties;\n builtinPackage: PackageRepr;\n i18n: AppIntl;\n}) {\n const { packageMetadata, properties, builtinPackage, i18n } = config;\n\n let packages: PackageRepr[];\n try {\n packages = createPackages(packageMetadata ?? {}, i18n, properties);\n } catch (e) {\n throw new Error(ErrorId.INVALID_METADATA, \"Failed to parse package metadata.\", {\n cause: e\n });\n }\n\n // Add builtin services defined within this package.\n {\n const index = packages.findIndex((pkg) => pkg.name === builtinPackage.name);\n if (index >= 0) {\n packages.splice(index, 1);\n }\n packages.push(builtinPackage);\n }\n\n // Automatically required references (-> forces services to start)\n const forcedReferences: ReferenceSpec[] = [\n {\n interfaceName: RUNTIME_API_SERVICE\n },\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE\n },\n {\n interfaceName: RUNTIME_LOCALE_SERVICE\n },\n {\n interfaceName: RUNTIME_THEME_SERVICE\n },\n {\n interfaceName: RUNTIME_AUTO_START,\n all: true\n }\n ];\n const serviceLayer = new ServiceLayer(packages, forcedReferences);\n return {\n packages: new Map(packages.map((pkg) => [pkg.name, pkg])),\n serviceLayer: serviceLayer\n };\n}\n\nfunction getInternalService<T = unknown>(serviceLayer: ServiceLayer, interfaceName: string) {\n const result = serviceLayer.getService(\n \"@open-pioneer/runtime\",\n {\n interfaceName\n },\n { ignoreDeclarationCheck: true }\n );\n if (result.type !== \"found\") {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to find instance of '${interfaceName}' (result type '${result.type}').` +\n ` This is a builtin service that must be present exactly once.`\n );\n }\n\n return result.value.getInstanceOrThrow() as T;\n}\n"],"names":["themeService"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAwB1B,MAAM,WAAA,CAAY;AAAA,EACrB,QAAA;AAAA;AAAA,EAGA,WAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EAEA,MAAA,GAAmB,aAAA;AAAA,EACnB,SAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,KAAA;AAAA;AAAA;AAAA,EAIA,QAAA;AAAA;AAAA;AAAA;AAAA,EAIA,OAAA;AAAA,EAEA,aAAA;AAAA,EACA,gBAAA;AAAA,EACA,aAAA;AAAA,EACA,iBAAA;AAAA,EAEA,YAAA;AAAA,EACA,YAAA;AAAA,EAEA,YAAY,OAAA,EAAqB;AAC7B,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAChB,IAAA,IAAA,CAAK,aAAa,YAAA,CAAa,OAAA,CAA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xD;AAAA,GACJ;AACJ;AAEA,SAAS,kBAAA,CAAgC,cAA4B,aAAA,EAAuB;AACxF,EAAA,MAAM,SAAS,YAAA,CAAa,UAAA;AAAA,IACxB,uBAAA;AAAA,IACA;AAAA,MACI;AAAA,KACJ;AAAA,IACA,EAAE,wBAAwB,IAAA;AAAK,GACnC;AACA,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,aAAa,CAAA,gBAAA,EAAmB,MAAA,CAAO,IAAI,CAAA,gEAAA;AAAA,KAE9E;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA,CAAO,MAAM,kBAAA,EAAmB;AAC3C;;;;"}
|
package/app/gatherConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gatherConfig.js","sources":["gatherConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\n\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nexport async function gatherConfig(\n hostElement: HTMLElement,\n options: CustomElementOptions,\n overrides?: ApplicationOverrides\n): Promise<Required<ApplicationConfig>> {\n let configs: ApplicationConfig[];\n try {\n const staticConfig = options.config ?? {};\n const dynamicConfig =\n (await options.resolveConfig?.({\n hostElement,\n getAttribute(name) {\n return hostElement.getAttribute(name) ?? undefined;\n },\n overrides\n })) ?? {};\n\n configs = [\n {\n chakraSystemConfig: options.chakraSystemConfig\n },\n staticConfig,\n dynamicConfig\n ];\n } catch (e) {\n throw new Error(\n ErrorId.CONFIG_RESOLUTION_FAILED,\n \"Failed to resolve application properties.\",\n {\n cause: e\n }\n );\n }\n\n const merged = mergeConfigs(configs);\n if (overrides) {\n if (overrides.locale) {\n merged.locale = overrides.locale;\n }\n if (overrides.colorMode) {\n merged.colorMode = overrides.colorMode;\n }\n if (overrides.chakraSystemConfig) {\n merged.chakraSystemConfig = overrides.chakraSystemConfig;\n }\n }\n\n return merged;\n}\n\n/**\n * Merges application configurations into a single object.\n * Properties / config parameters at a later position overwrite properties from earlier ones.\n */\nfunction mergeConfigs(configs: ApplicationConfig[]): Required<ApplicationConfig> {\n // Merge simple values by assigning them in order\n const mergedConfig: Required<ApplicationConfig> = Object.assign(\n {\n locale: undefined,\n supportedLocales: undefined,\n chakraSystemConfig: undefined,\n colorMode: undefined,\n properties: {}\n } satisfies ApplicationConfig,\n ...configs\n );\n\n // Deep merge for application properties\n const mergedProperties: ApplicationProperties = (mergedConfig.properties = {});\n for (const config of configs) {\n for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {\n const mergedPackageProps = (mergedProperties[packageName] ??= {});\n Object.assign(mergedPackageProps, packageProperties);\n }\n }\n\n return mergedConfig;\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"gatherConfig.js","sources":["gatherConfig.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport {\n ApplicationConfig,\n ApplicationOverrides,\n ApplicationProperties,\n CustomElementOptions\n} from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\n\n/**\n * Gathers application properties by reading them from the options object\n * and by (optionally) invoking the `resolveProperties` hook.\n */\nexport async function gatherConfig(\n hostElement: HTMLElement,\n options: CustomElementOptions,\n overrides?: ApplicationOverrides\n): Promise<Required<ApplicationConfig>> {\n let configs: ApplicationConfig[];\n try {\n const staticConfig = options.config ?? {};\n const dynamicConfig =\n (await options.resolveConfig?.({\n hostElement,\n getAttribute(name) {\n return hostElement.getAttribute(name) ?? undefined;\n },\n overrides\n })) ?? {};\n\n configs = [\n {\n chakraSystemConfig: options.chakraSystemConfig\n },\n staticConfig,\n dynamicConfig\n ];\n } catch (e) {\n throw new Error(\n ErrorId.CONFIG_RESOLUTION_FAILED,\n \"Failed to resolve application properties.\",\n {\n cause: e\n }\n );\n }\n\n const merged = mergeConfigs(configs);\n if (overrides) {\n if (overrides.locale) {\n merged.locale = overrides.locale;\n }\n if (overrides.colorMode) {\n merged.colorMode = overrides.colorMode;\n }\n if (overrides.chakraSystemConfig) {\n merged.chakraSystemConfig = overrides.chakraSystemConfig;\n }\n }\n\n return merged;\n}\n\n/**\n * Merges application configurations into a single object.\n * Properties / config parameters at a later position overwrite properties from earlier ones.\n */\nfunction mergeConfigs(configs: ApplicationConfig[]): Required<ApplicationConfig> {\n // Merge simple values by assigning them in order\n const mergedConfig: Required<ApplicationConfig> = Object.assign(\n {\n locale: undefined,\n supportedLocales: undefined,\n chakraSystemConfig: undefined,\n colorMode: undefined,\n properties: {}\n } satisfies ApplicationConfig,\n ...configs\n );\n\n // Deep merge for application properties\n const mergedProperties: ApplicationProperties = (mergedConfig.properties = {});\n for (const config of configs) {\n for (const [packageName, packageProperties] of Object.entries(config.properties ?? {})) {\n const mergedPackageProps = (mergedProperties[packageName] ??= {});\n Object.assign(mergedPackageProps, packageProperties);\n }\n }\n\n return mergedConfig;\n}\n"],"names":[],"mappings":";;;AAgBA,eAAsB,YAAA,CAClB,WAAA,EACA,OAAA,EACA,SAAA,EACoC;AACpC,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACA,IAAA,MAAM,YAAA,GAAe,OAAA,CAAQ,MAAA,IAAU,EAAC;AACxC,IAAA,MAAM,aAAA,GACD,MAAM,OAAA,CAAQ,aAAA,GAAgB;AAAA,MAC3B,WAAA;AAAA,MACA,aAAa,IAAA,EAAM;AACf,QAAA,OAAO,WAAA,CAAY,YAAA,CAAa,IAAI,CAAA,IAAK,KAA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AAO,UAAA,IAAc,EAAE,CAAA,EAAG;AACpF,MAAA,MAAM,kBAAA,GAAsB,gBAAA,CAAiB,WAAW,CAAA,KAAM,EAAC;AAC/D,MAAA,MAAA,CAAO,MAAA,CAAO,oBAAoB,iBAAiB,CAAA;AAAA,IACvD;AAAA,EACJ;AAEA,EAAA,OAAO,YAAA;AACX;;;;"}
|
package/app/logErrors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logErrors.js","sources":["logErrors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { getErrorChain } from \"@open-pioneer/core\";\n\nexport function logError(e: unknown) {\n if (e instanceof Error) {\n const chain = getErrorChain(e).reverse();\n if (chain.length === 1) {\n console.error(e);\n return;\n }\n\n let n = 1;\n for (const error of chain) {\n console.error(`#${n}`, error);\n ++n;\n }\n } else {\n console.error(\"Unexpected error\", e);\n }\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"logErrors.js","sources":["logErrors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getErrorChain } from \"@open-pioneer/core\";\n\nexport function logError(e: unknown) {\n if (e instanceof Error) {\n const chain = getErrorChain(e).reverse();\n if (chain.length === 1) {\n console.error(e);\n return;\n }\n\n let n = 1;\n for (const error of chain) {\n console.error(`#${n}`, error);\n ++n;\n }\n } else {\n console.error(\"Unexpected error\", e);\n }\n}\n"],"names":[],"mappings":";;AAKO,SAAS,SAAS,CAAA,EAAY;AACjC,EAAA,IAAI,aAAa,KAAA,EAAO;AACpB,IAAA,MAAM,KAAA,GAAQ,aAAA,CAAc,CAAC,CAAA,CAAE,OAAA,EAAQ;AACvC,IAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACpB,MAAA,OAAA,CAAQ,MAAM,CAAC,CAAA;AACf,MAAA;AAAA,IACJ;AAEA,IAAA,IAAI,CAAA,GAAI,CAAA;AACR,IAAA,KAAA,MAAW,SAAS,KAAA,EAAO;AACvB,MAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,EAAI,KAAK,CAAA;AAC5B,MAAA,EAAE,CAAA;AAAA,IACN;AAAA,EACJ,CAAA,MAAO;AACH,IAAA,OAAA,CAAQ,KAAA,CAAM,oBAAoB,CAAC,CAAA;AAAA,EACvC;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiServiceImpl.js","sources":["ApiServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"ApiServiceImpl.js","sources":["ApiServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport { ApiExtension, ApiMethod, ApiMethods, ApiService } from \"../api\";\nimport { ErrorId } from \"../errors\";\nimport { ServiceOptions } from \"../Service\";\n\ninterface References {\n providers: ApiExtension[];\n}\n\nexport class ApiServiceImpl implements ApiService {\n readonly #providers: [serviceId: string, provider: ApiExtension][];\n\n constructor(options: ServiceOptions<References>) {\n const providers = options.references.providers;\n const meta = options.referencesMeta.providers;\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#providers = providers.map((provider, index) => [meta[index]!.serviceId, provider]);\n }\n\n async getApi() {\n interface ProviderResult {\n serviceId: string;\n methods: ApiMethods;\n }\n\n const promises = this.#providers.map(async ([serviceId, provider]) => {\n const methods = await provider.getApiMethods();\n const result: ProviderResult = {\n serviceId,\n methods\n };\n return result;\n });\n const providerMethods = await Promise.all(promises);\n\n interface MethodEntry {\n method: ApiMethod;\n serviceId: string;\n }\n\n const methodEntries = new Map<string, MethodEntry>();\n for (const { serviceId, methods } of providerMethods) {\n for (const [methodName, method] of Object.entries(methods)) {\n const existingEntry = methodEntries.get(methodName);\n if (existingEntry) {\n throw new Error(\n ErrorId.DUPLICATE_API_METHODS,\n `Cannot define API method '${methodName}' from '${serviceId}' (method is also defined by '${existingEntry.serviceId}').`\n );\n }\n\n methodEntries.set(methodName, {\n serviceId,\n method\n });\n }\n }\n\n const api: Record<string, ApiMethod> = {};\n for (const [methodName, entry] of methodEntries.entries()) {\n api[methodName] = entry.method;\n }\n return api;\n }\n}\n"],"names":[],"mappings":";;;AAYO,MAAM,cAAA,CAAqC;AAAA,EACrC,UAAA;AAAA,EAET,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,SAAA,GAAY,QAAQ,UAAA,CAAW,SAAA;AACrC,IAAA,MAAM,IAAA,GAAO,QAAQ,cAAA,CAAe,SAAA;AAEpC,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA,CAAU,GAAA,CAAI,CAAC,QAAA,EAAU,KAAA,KAAU,CAAC,IAAA,CAAK,KAAK,CAAA,CAAG,SAAA,EAAW,QAAQ,CAAC,CAAA;AAAA,EAC3F;AAAA,EAEA,MAAM,MAAA,GAAS;AAMX,IAAA,MAAM,QAAA,GAAW,KAAK,UAAA,CAAW,GAAA,CAAI,OAAO,CAAC,SAAA,EAAW,QAAQ,CAAA,KAAM;AAClE,MAAA,MAAM,OAAA,GAAU,MAAM,QAAA,CAAS,aAAA,EAAc;AAC7C,MAAA,MAAM,MAAA,GAAyB;AAAA,QAC3B,SAAA;AAAA,QACA;AAAA,OACJ;AACA,MAAA,OAAO,MAAA;AAAA,IACX,CAAC,CAAA;AACD,IAAA,MAAM,eAAA,GAAkB,MAAM,OAAA,CAAQ,GAAA,CAAI,QAAQ,CAAA;AAOlD,IAAA,MAAM,aAAA,uBAAoB,GAAA,EAAyB;AACnD,IAAA,KAAA,MAAW,EAAE,SAAA,EAAW,OAAA,EAAQ,IAAK,eAAA,EAAiB;AAClD,MAAA,KAAA,MAAW,CAAC,UAAA,EAAY,MAAM,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AACxD,QAAA,MAAM,aAAA,GAAgB,aAAA,CAAc,GAAA,CAAI,UAAU,CAAA;AAClD,QAAA,IAAI,aAAA,EAAe;AACf,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,qBAAA;AAAA,YACR,6BAA6B,UAAU,CAAA,QAAA,EAAW,SAAS,CAAA,8BAAA,EAAiC,cAAc,SAAS,CAAA,GAAA;AAAA,WACvH;AAAA,QACJ;AAEA,QAAA,aAAA,CAAc,IAAI,UAAA,EAAY;AAAA,UAC1B,SAAA;AAAA,UACA;AAAA,SACH,CAAA;AAAA,MACL;AAAA,IACJ;AAEA,IAAA,MAAM,MAAiC,EAAC;AACxC,IAAA,KAAA,MAAW,CAAC,UAAA,EAAY,KAAK,CAAA,IAAK,aAAA,CAAc,SAAQ,EAAG;AACvD,MAAA,GAAA,CAAI,UAAU,IAAI,KAAA,CAAM,MAAA;AAAA,IAC5B;AACA,IAAA,OAAO,GAAA;AAAA,EACX;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger, Error, deprecated, isAbortError } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationContext, LocaleService } from \"../api\";\nimport { isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { tryParseLocale } from \"../i18n\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n rootNode: RootNode;\n container: HTMLElement;\n}\n\ninterface ServiceReferences {\n localeService: LocaleService;\n}\n\nexport type ApplicationContextServiceOptions = ServiceOptions<ServiceReferences>;\n\nconst setLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.setLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.changeLocale` instead.\"\n});\nconst getLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.getLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.locale` instead.\"\n});\nconst getSupportedLocalesDeprecationMessage = deprecated({\n name: \"ApplicationContext.getSupportedLocales\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.supportedMessageLocales` instead.\"\n});\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #rootNode: RootNode;\n #container: HTMLElement;\n #localeService: LocaleService;\n\n constructor(\n options: ApplicationContextServiceOptions,\n properties: ApplicationContextProperties\n ) {\n this.#host = properties.host;\n this.#rootNode = properties.rootNode;\n this.#container = properties.container;\n this.#localeService = options.references.localeService;\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getRoot(): RootNode {\n return this.#rootNode;\n }\n\n getShadowRoot(): ShadowRoot | undefined {\n return isShadowRoot(this.#rootNode) ? this.#rootNode : undefined;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getLocale(): string {\n getLocaleDeprecationMessage();\n return this.#localeService.locale.baseName;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n setLocale(locale: string | undefined): void {\n setLocaleDeprecationMessage();\n const targetLocale = tryParseLocale(locale);\n // to be backwards compatible, we check here synchronously\n // same check is done in AppIntl.changeLocale\n if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {\n const localesList = this.#localeService.supportedMessageLocales\n .map((l) => l.baseName)\n .join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${targetLocale.baseName}' (supported locales: ${localesList}).`\n );\n }\n this.#localeService.changeLocale(targetLocale).catch((e) => {\n if (!isAbortError(e)) {\n LOG.error(`Failed to switch locale to '${targetLocale?.baseName}'.`, e);\n }\n });\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getSupportedLocales(): readonly string[] {\n getSupportedLocalesDeprecationMessage();\n return this.#localeService.supportedMessageLocales.map((l) => l.baseName);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error, deprecated, isAbortError } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationContext, LocaleService } from \"../api\";\nimport { isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { tryParseLocale } from \"../i18n\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n rootNode: RootNode;\n container: HTMLElement;\n}\n\ninterface ServiceReferences {\n localeService: LocaleService;\n}\n\nexport type ApplicationContextServiceOptions = ServiceOptions<ServiceReferences>;\n\nconst setLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.setLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.changeLocale` instead.\"\n});\nconst getLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.getLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.locale` instead.\"\n});\nconst getSupportedLocalesDeprecationMessage = deprecated({\n name: \"ApplicationContext.getSupportedLocales\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.supportedMessageLocales` instead.\"\n});\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #rootNode: RootNode;\n #container: HTMLElement;\n #localeService: LocaleService;\n\n constructor(\n options: ApplicationContextServiceOptions,\n properties: ApplicationContextProperties\n ) {\n this.#host = properties.host;\n this.#rootNode = properties.rootNode;\n this.#container = properties.container;\n this.#localeService = options.references.localeService;\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getRoot(): RootNode {\n return this.#rootNode;\n }\n\n getShadowRoot(): ShadowRoot | undefined {\n return isShadowRoot(this.#rootNode) ? this.#rootNode : undefined;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getLocale(): string {\n getLocaleDeprecationMessage();\n return this.#localeService.locale.baseName;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n setLocale(locale: string | undefined): void {\n setLocaleDeprecationMessage();\n const targetLocale = tryParseLocale(locale);\n // to be backwards compatible, we check here synchronously\n // same check is done in AppIntl.changeLocale\n if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {\n const localesList = this.#localeService.supportedMessageLocales\n .map((l) => l.baseName)\n .join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${targetLocale.baseName}' (supported locales: ${localesList}).`\n );\n }\n this.#localeService.changeLocale(targetLocale).catch((e) => {\n if (!isAbortError(e)) {\n LOG.error(`Failed to switch locale to '${targetLocale?.baseName}'.`, e);\n }\n });\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getSupportedLocales(): readonly string[] {\n getSupportedLocalesDeprecationMessage();\n return this.#localeService.supportedMessageLocales.map((l) => l.baseName);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAcjC,MAA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A,EAA4B;AAC5B,IAAA,OAAO,IAAA,CAAK,eAAe,MAAA,CAAO,QAAA;AAAA,EACtC;AAAA;AAAA,EAGA,UAAU,MAAA,EAAkC;AACxC,IAAA,2BAAA,EAA4B;AAC5B,IAAA,MAAM,YAAA,GAAe,eAAe,MAAM,CAAA;AAG1C,IAAA,IAAI,gBAAgB,CAAC,IAAA,CAAK,cAAA,CAAe,cAAA,CAAe,YAAY,CAAA,EAAG;AACnE,MAAA,MAAM,WAAA,GAAc,IAAA,CAAK,cAAA,CAAe,uBAAA,CACnC,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,QAAQ,CAAA,CACrB,IAAA,CAAK,IAAI,CAAA;AACd,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,kBAAA;AAAA,QACR,CAAA,oBAAA,EAAuB,YAAA,CAAa,QAAQ,CAAA,sBAAA,EAAyB,WAAW,CAAA,EAAA;AAAA,OACpF;AAAA,IACJ;AACA,IAAA,IAAA,CAAK,eAAe,YAAA,CAAa,YAAY,CAAA,CAAE,KAAA,CAAM,CAAC,CAAA,KAAM;AACxD,MAAA,IAAI,CAAC,YAAA,CAAa,CAAC,CAAA,EAAG;AAClB,QAAA,GAAA,CAAI,KAAA,CAAM,CAAA,4BAAA,EAA+B,YAAA,EAAc,QAAQ,MAAM,CAAC,CAAA;AAAA,MAC1E;AAAA,IACJ,CAAC,CAAA;AAAA,EACL;AAAA;AAAA,EAGA,mBAAA,GAAyC;AACrC,IAAA,qCAAA,EAAsC;AACtC,IAAA,OAAO,KAAK,cAAA,CAAe,uBAAA,CAAwB,IAAI,CAAC,CAAA,KAAM,EAAE,QAAQ,CAAA;AAAA,EAC5E;AACJ;;;;"}
|
|
@@ -9,7 +9,7 @@ class ApplicationLifecycleEventService {
|
|
|
9
9
|
const listeners = options.references.listeners;
|
|
10
10
|
const listenersMeta = options.referencesMeta.listeners;
|
|
11
11
|
this.#listeners = listeners.map((listener, index) => [
|
|
12
|
-
//
|
|
12
|
+
// oxlint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
13
13
|
listenersMeta[index].serviceId,
|
|
14
14
|
listener
|
|
15
15
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApplicationLifecycleEventService.js","sources":["ApplicationLifecycleEventService.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 {
|
|
1
|
+
{"version":3,"file":"ApplicationLifecycleEventService.js","sources":["ApplicationLifecycleEventService.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationLifecycleListener } from \"../api\";\nimport { ErrorId } from \"../errors\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface References {\n listeners: ApplicationLifecycleListener[];\n}\n\nexport class ApplicationLifecycleEventService {\n #listeners: [serviceId: string, listener: ApplicationLifecycleListener][];\n\n constructor(options: ServiceOptions<References>) {\n const listeners = options.references.listeners;\n const listenersMeta = options.referencesMeta.listeners;\n this.#listeners = listeners.map((listener, index) => [\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n listenersMeta[index]!.serviceId,\n listener\n ]);\n }\n\n /** @internal */\n emitLifecycleEvent(event: \"after-start\" | \"before-stop\"): void {\n const methodName = (() => {\n switch (event) {\n case \"after-start\":\n return \"afterApplicationStart\";\n case \"before-stop\":\n return \"beforeApplicationStop\";\n default:\n throw new Error(ErrorId.INTERNAL, `Invalid event '${event}'`);\n }\n })();\n for (const [serviceId, listener] of this.#listeners) {\n try {\n listener[methodName]?.();\n } catch (e) {\n LOG.error(`Unexpected error from application lifecycle listener ${serviceId}`, e);\n }\n }\n }\n}\n"],"names":[],"mappings":";;;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAM1B,MAAM,gCAAA,CAAiC;AAAA,EAC1C,UAAA;AAAA,EAEA,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,SAAA,GAAY,QAAQ,UAAA,CAAW,SAAA;AACrC,IAAA,MAAM,aAAA,GAAgB,QAAQ,cAAA,CAAe,SAAA;AAC7C,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA,CAAU,GAAA,CAAI,CAAC,UAAU,KAAA,KAAU;AAAA;AAAA,MAEjD,aAAA,CAAc,KAAK,CAAA,CAAG,SAAA;AAAA,MACtB;AAAA,KACH,CAAA;AAAA,EACL;AAAA;AAAA,EAGA,mBAAmB,KAAA,EAA4C;AAC3D,IAAA,MAAM,cAAc,MAAM;AACtB,MAAA,QAAQ,KAAA;AAAO,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX;AACI,UAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,EAAU,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA;AACpE,IACJ,CAAA,GAAG;AACH,IAAA,KAAA,MAAW,CAAC,SAAA,EAAW,QAAQ,CAAA,IAAK,KAAK,UAAA,EAAY;AACjD,MAAA,IAAI;AACA,QAAA,QAAA,CAAS,UAAU,CAAA,IAAI;AAAA,MAC3B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,KAAA,CAAM,CAAA,qDAAA,EAAwD,SAAS,CAAA,CAAA,EAAI,CAAC,CAAA;AAAA,MACpF;AAAA,IACJ;AAAA,EACJ;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocaleServiceImpl.js","sources":["LocaleServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { type LocaleService } from \"../api\";\nimport { AppIntl } from \"../i18n\";\n\nexport interface LocaleServiceProperties {\n appIntl: AppIntl;\n}\n\n/**\n * Implementation of the `runtime.LocaleService` builtin service.\n */\nexport class LocaleServiceImpl implements LocaleService {\n // this is the source of truth.\n // Carries the real reactive state.\n #appIntl: AppIntl;\n\n constructor(properties: LocaleServiceProperties) {\n this.#appIntl = properties.appIntl;\n }\n\n get locale(): Intl.Locale {\n return this.#appIntl.locale;\n }\n\n get messageLocale(): Intl.Locale {\n return this.#appIntl.messageLocale;\n }\n\n get supportedMessageLocales(): readonly Intl.Locale[] {\n return this.#appIntl.supportedMessageLocales;\n }\n\n get supportsLiveChanges(): boolean {\n return this.#appIntl.supportsLiveChanges;\n }\n\n changeLocale(targetLocale: Intl.Locale | undefined): Promise<void> {\n return this.#appIntl.changeLocale(targetLocale);\n }\n\n supportsLocale(locale: Intl.Locale): boolean {\n return this.#appIntl.supportsLocale(locale);\n }\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LocaleServiceImpl.js","sources":["LocaleServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { type LocaleService } from \"../api\";\nimport { AppIntl } from \"../i18n\";\n\nexport interface LocaleServiceProperties {\n appIntl: AppIntl;\n}\n\n/**\n * Implementation of the `runtime.LocaleService` builtin service.\n */\nexport class LocaleServiceImpl implements LocaleService {\n // this is the source of truth.\n // Carries the real reactive state.\n #appIntl: AppIntl;\n\n constructor(properties: LocaleServiceProperties) {\n this.#appIntl = properties.appIntl;\n }\n\n get locale(): Intl.Locale {\n return this.#appIntl.locale;\n }\n\n get messageLocale(): Intl.Locale {\n return this.#appIntl.messageLocale;\n }\n\n get supportedMessageLocales(): readonly Intl.Locale[] {\n return this.#appIntl.supportedMessageLocales;\n }\n\n get supportsLiveChanges(): boolean {\n return this.#appIntl.supportsLiveChanges;\n }\n\n changeLocale(targetLocale: Intl.Locale | undefined): Promise<void> {\n return this.#appIntl.changeLocale(targetLocale);\n }\n\n supportsLocale(locale: Intl.Locale): boolean {\n return this.#appIntl.supportsLocale(locale);\n }\n}\n"],"names":[],"mappings":"AAaO,MAAM,iBAAA,CAA2C;AAAA;AAAA;AAAA,EAGpD,QAAA;AAAA,EAEA,YAAY,UAAA,EAAqC;AAC7C,IAAA,IAAA,CAAK,WAAW,UAAA,CAAW,OAAA;AAAA,EAC/B;AAAA,EAEA,IAAI,MAAA,GAAsB;AACtB,IAAA,OAAO,KAAK,QAAA,CAAS,MAAA;AAAA,EACzB;AAAA,EAEA,IAAI,aAAA,GAA6B;AAC7B,IAAA,OAAO,KAAK,QAAA,CAAS,aAAA;AAAA,EACzB;AAAA,EAEA,IAAI,uBAAA,GAAkD;AAClD,IAAA,OAAO,KAAK,QAAA,CAAS,uBAAA;AAAA,EACzB;AAAA,EAEA,IAAI,mBAAA,GAA+B;AAC/B,IAAA,OAAO,KAAK,QAAA,CAAS,mBAAA;AAAA,EACzB;AAAA,EAEA,aAAa,YAAA,EAAsD;AAC/D,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,YAAA,CAAa,YAAY,CAAA;AAAA,EAClD;AAAA,EAEA,eAAe,MAAA,EAA8B;AACzC,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,cAAA,CAAe,MAAM,CAAA;AAAA,EAC9C;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { computed, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { createLogger, NumberParser } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LocaleService, NumberParserService } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface ServiceReferences {\n localeService: Pick<LocaleService, \"locale\">;\n}\n\nexport type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;\n\nexport class NumberParserServiceImpl implements NumberParserService {\n #numberParser: ReadonlyReactive<NumberParser>;\n\n constructor(_serviceOptions: NumberParserServiceOptions) {\n const localeService = _serviceOptions.references.localeService;\n this.#numberParser = computed(() => {\n // reactive\n const tag = localeService.locale.baseName;\n try {\n return new NumberParser(tag);\n } catch (e) {\n LOG.warn(\n `Failed to create NumberParser with locale '${tag}'. Falling back to 'en-US'.`,\n e\n );\n return new NumberParser(\"en-US\");\n }\n });\n }\n\n parseNumber(numberString: string): number {\n return this.#numberParser.value.parse(numberString);\n }\n}\n"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { computed, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { createLogger, NumberParser } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LocaleService, NumberParserService } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface ServiceReferences {\n localeService: Pick<LocaleService, \"locale\">;\n}\n\nexport type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;\n\nexport class NumberParserServiceImpl implements NumberParserService {\n #numberParser: ReadonlyReactive<NumberParser>;\n\n constructor(_serviceOptions: NumberParserServiceOptions) {\n const localeService = _serviceOptions.references.localeService;\n this.#numberParser = computed(() => {\n // reactive\n const tag = localeService.locale.baseName;\n try {\n return new NumberParser(tag);\n } catch (e) {\n LOG.warn(\n `Failed to create NumberParser with locale '${tag}'. Falling back to 'en-US'.`,\n e\n );\n return new NumberParser(\"en-US\");\n }\n });\n }\n\n parseNumber(numberString: string): number {\n return this.#numberParser.value.parse(numberString);\n }\n}\n"],"names":[],"mappings":";;;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAQ1B,MAAM,uBAAA,CAAuD;AAAA,EAChE,aAAA;AAAA,EAEA,YAAY,eAAA,EAA6C;AACrD,IAAA,MAAM,aAAA,GAAgB,gBAAgB,UAAA,CAAW,aAAA;AACjD,IAAA,IAAA,CAAK,aAAA,GAAgB,SAAS,MAAM;AAEhC,MAAA,MAAM,GAAA,GAAM,cAAc,MAAA,CAAO,QAAA;AACjC,MAAA,IAAI;AACA,QAAA,OAAO,IAAI,aAAa,GAAG,CAAA;AAAA,MAC/B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,IAAA;AAAA,UACA,8CAA8C,GAAG,CAAA,2BAAA,CAAA;AAAA,UACjD;AAAA,SACJ;AACA,QAAA,OAAO,IAAI,aAAa,OAAO,CAAA;AAAA,MACnC;AAAA,IACJ,CAAC,CAAA;AAAA,EACL;AAAA,EAEA,YAAY,YAAA,EAA8B;AACtC,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,KAAA,CAAM,KAAA,CAAM,YAAY,CAAA;AAAA,EACtD;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeServiceImpl.js","sources":["ThemeServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { type SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { computed, reactive, ReadonlyReactive, synchronized } from \"@conterra/reactivity-core\";\nimport {\n type ChakraSystemConfigSupplier,\n type ColorModeValue,\n type ColorModeValueSupplier,\n type ThemeService\n} from \"../api\";\n\nexport const DEFAULT_INITIAL_COLOR_MODE: ColorModeValue = \"light\";\n\nexport interface ThemeServiceProperties {\n initialColorMode?: ColorModeValue | \"system\";\n initialSystemConfig?: ChakraSystemConfig;\n}\n\nexport class ThemeServiceImpl implements ThemeService {\n #systemColorMode = reactiveSystemColorMode();\n\n #colorModeSource = reactive<ColorModeValueSupplier>(() => DEFAULT_INITIAL_COLOR_MODE);\n #colorMode = computed<ColorModeValue>(\n () => this.#colorModeSource.value() ?? DEFAULT_INITIAL_COLOR_MODE\n );\n\n #systemConfigSource = reactive<ChakraSystemConfigSupplier>(() => undefined);\n #systemConfig = computed<ChakraSystemConfig | undefined>(\n () => this.#systemConfigSource.value() ?? undefined\n );\n\n constructor({ initialSystemConfig, initialColorMode }: ThemeServiceProperties) {\n this.setColorMode(initialColorMode ?? DEFAULT_INITIAL_COLOR_MODE);\n if (initialSystemConfig) {\n this.setSystemConfig(initialSystemConfig);\n }\n }\n\n get systemColorMode(): ColorModeValue {\n return this.#systemColorMode.value;\n }\n\n get colorMode(): ColorModeValue {\n return this.#colorMode.value;\n }\n\n setColorMode(value: ColorModeValue | \"system\" | ColorModeValueSupplier): void {\n if (typeof value === \"function\") {\n this.#colorModeSource.value = value;\n } else if (value === \"system\") {\n this.#colorModeSource.value = () => this.#systemColorMode.value;\n } else {\n this.#colorModeSource.value = () => value;\n }\n }\n\n get systemConfig(): ChakraSystemConfig | undefined {\n return this.#systemConfig.value;\n }\n\n setSystemConfig(value: ChakraSystemConfig | ChakraSystemConfigSupplier | undefined): void {\n if (typeof value === \"function\") {\n this.#systemConfigSource.value = value;\n } else {\n this.#systemConfigSource.value = () => value;\n }\n }\n}\n\nfunction reactiveSystemColorMode(): ReadonlyReactive<ColorModeValue> {\n if (typeof window === \"undefined\" || typeof window.matchMedia !== \"function\") {\n return reactive(\"light\");\n }\n\n const query = window.matchMedia(\"(prefers-color-scheme: dark)\");\n return synchronized(\n () => (query.matches ? \"dark\" : \"light\"),\n (onChange) => {\n const listener = () => onChange();\n query.addEventListener(\"change\", listener);\n return () => query.removeEventListener(\"change\", listener);\n }\n );\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"ThemeServiceImpl.js","sources":["ThemeServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { type SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { computed, reactive, ReadonlyReactive, synchronized } from \"@conterra/reactivity-core\";\nimport {\n type ChakraSystemConfigSupplier,\n type ColorModeValue,\n type ColorModeValueSupplier,\n type ThemeService\n} from \"../api\";\n\nexport const DEFAULT_INITIAL_COLOR_MODE: ColorModeValue = \"light\";\n\nexport interface ThemeServiceProperties {\n initialColorMode?: ColorModeValue | \"system\";\n initialSystemConfig?: ChakraSystemConfig;\n}\n\nexport class ThemeServiceImpl implements ThemeService {\n #systemColorMode = reactiveSystemColorMode();\n\n #colorModeSource = reactive<ColorModeValueSupplier>(() => DEFAULT_INITIAL_COLOR_MODE);\n #colorMode = computed<ColorModeValue>(\n () => this.#colorModeSource.value() ?? DEFAULT_INITIAL_COLOR_MODE\n );\n\n #systemConfigSource = reactive<ChakraSystemConfigSupplier>(() => undefined);\n #systemConfig = computed<ChakraSystemConfig | undefined>(\n () => this.#systemConfigSource.value() ?? undefined\n );\n\n constructor({ initialSystemConfig, initialColorMode }: ThemeServiceProperties) {\n this.setColorMode(initialColorMode ?? DEFAULT_INITIAL_COLOR_MODE);\n if (initialSystemConfig) {\n this.setSystemConfig(initialSystemConfig);\n }\n }\n\n get systemColorMode(): ColorModeValue {\n return this.#systemColorMode.value;\n }\n\n get colorMode(): ColorModeValue {\n return this.#colorMode.value;\n }\n\n setColorMode(value: ColorModeValue | \"system\" | ColorModeValueSupplier): void {\n if (typeof value === \"function\") {\n this.#colorModeSource.value = value;\n } else if (value === \"system\") {\n this.#colorModeSource.value = () => this.#systemColorMode.value;\n } else {\n this.#colorModeSource.value = () => value;\n }\n }\n\n get systemConfig(): ChakraSystemConfig | undefined {\n return this.#systemConfig.value;\n }\n\n setSystemConfig(value: ChakraSystemConfig | ChakraSystemConfigSupplier | undefined): void {\n if (typeof value === \"function\") {\n this.#systemConfigSource.value = value;\n } else {\n this.#systemConfigSource.value = () => value;\n }\n }\n}\n\nfunction reactiveSystemColorMode(): ReadonlyReactive<ColorModeValue> {\n if (typeof window === \"undefined\" || typeof window.matchMedia !== \"function\") {\n return reactive(\"light\");\n }\n\n const query = window.matchMedia(\"(prefers-color-scheme: dark)\");\n return synchronized(\n () => (query.matches ? \"dark\" : \"light\"),\n (onChange) => {\n const listener = () => onChange();\n query.addEventListener(\"change\", listener);\n return () => query.removeEventListener(\"change\", listener);\n }\n );\n}\n"],"names":[],"mappings":";;AAYO,MAAM,0BAAA,GAA6C;AAOnD,MAAM,gBAAA,CAAyC;AAAA,EAClD,mBAAmB,uBAAA,EAAwB;AAAA,EAE3C,gBAAA,GAAmB,QAAA,CAAiC,MAAM,0BAA0B,CAAA;AAAA,EACpF,UAAA,GAAa,QAAA;AAAA,IACT,MAAM,IAAA,CAAK,gBAAA,CAAiB,KAAA,EAAM,IAAK;AAAA,GAC3C;AAAA,EAEA,mBAAA,GAAsB,QAAA,CAAqC,MAAM,MAAS,CAAA;AAAA,EAC1E,aAAA,GAAgB,QAAA;AAAA,IACZ,MAAM,IAAA,CAAK,mBAAA,CAAoB,KAAA,EAAM,IAAK;AAAA,GAC9C;AAAA,EAEA,WAAA,CAAY,EAAE,mBAAA,EAAqB,gBAAA,EAAiB,EAA2B;AAC3E,IAAA,IAAA,CAAK,YAAA,CAAa,oBAAoB,0BAA0B,CAAA;AAChE,IAAA,IAAI,mBAAA,EAAqB;AACrB,MAAA,IAAA,CAAK,gBAAgB,mBAAmB,CAAA;AAAA,IAC5C;AAAA,EACJ;AAAA,EAEA,IAAI,eAAA,GAAkC;AAClC,IAAA,OAAO,KAAK,gBAAA,CAAiB,KAAA;AAAA,EACjC;AAAA,EAEA,IAAI,SAAA,GAA4B;AAC5B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CAAM,mBAAA,CAAoB,QAAA,EAAU,QAAQ,CAAA;AAAA,IAC7D;AAAA,GACJ;AACJ;;;;"}
|
|
@@ -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 { 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 {\n ApplicationContextImpl,\n ApplicationContextProperties,\n ApplicationContextServiceOptions\n} from \"./ApplicationContextImpl\";\nimport { ApplicationLifecycleEventService } from \"./ApplicationLifecycleEventService\";\nimport { LocaleServiceImpl, LocaleServiceProperties } from \"./LocaleServiceImpl\";\nimport { NumberParserServiceImpl, NumberParserServiceOptions } 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\";\nexport const RUNTIME_LOCALE_SERVICE = \"runtime.LocaleService\";\n\nexport type BuiltinPackageProperties = ApplicationContextProperties &\n ThemeServiceProperties &\n LocaleServiceProperties;\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\n const localeService = new ServiceRepr({\n name: \"LocaleServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(() => new LocaleServiceImpl(properties)),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_LOCALE_SERVICE,\n qualifier: \"builtin\"\n }\n ]\n });\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) =>\n new ApplicationContextImpl(options as ApplicationContextServiceOptions, properties)\n ),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"localeService\",\n interfaceName: RUNTIME_LOCALE_SERVICE,\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 as NumberParserServiceOptions)\n ),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_NUMBER_PARSER_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"localeService\",\n interfaceName: RUNTIME_LOCALE_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 localeService,\n numberParserService,\n themeService\n ],\n intl: constant(intl)\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
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\n\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 {\n ApplicationContextImpl,\n ApplicationContextProperties,\n ApplicationContextServiceOptions\n} from \"./ApplicationContextImpl\";\nimport { ApplicationLifecycleEventService } from \"./ApplicationLifecycleEventService\";\nimport { LocaleServiceImpl, LocaleServiceProperties } from \"./LocaleServiceImpl\";\nimport { NumberParserServiceImpl, NumberParserServiceOptions } 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\";\nexport const RUNTIME_LOCALE_SERVICE = \"runtime.LocaleService\";\n\nexport type BuiltinPackageProperties = ApplicationContextProperties &\n ThemeServiceProperties &\n LocaleServiceProperties;\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\n const localeService = new ServiceRepr({\n name: \"LocaleServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(() => new LocaleServiceImpl(properties)),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_LOCALE_SERVICE,\n qualifier: \"builtin\"\n }\n ]\n });\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) =>\n new ApplicationContextImpl(options as ApplicationContextServiceOptions, properties)\n ),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"localeService\",\n interfaceName: RUNTIME_LOCALE_SERVICE,\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 as NumberParserServiceOptions)\n ),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_NUMBER_PARSER_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"localeService\",\n interfaceName: RUNTIME_LOCALE_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 localeService,\n numberParserService,\n themeService\n ],\n intl: constant(intl)\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAsBO,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,MAAM,sBAAA,GAAyB;AAgB/B,SAAS,qBAAqB,UAAA,EAAmD;AACpF,EAAA,MAAM,OAAO,sBAAA,EAAuB;AAEpC,EAAA,MAAM,aAAA,GAAgB,IAAI,WAAA,CAAY;AAAA,IAClC,IAAA,EAAM,mBAAA;AAAA,IACN,WAAA,EAAa,oBAAA;AAAA,IACb,SAAS,qBAAA,CAAsB,MAAM,IAAI,iBAAA,CAAkB,UAAU,CAAC,CAAA;AAAA,IACtE,IAAA,EAAM,SAAS,IAAI,CAAA;AAAA,IACnB,UAAA,EAAY;AAAA,MACR;AAAA,QACI,aAAA,EAAe,sBAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf;AACJ,GACH,CAAA;AACD,EAAA,MAAM,UAAA,GAAa,IAAI,WAAA,CAAY;AAAA,IAC/B,IAAA,EAAM,gBAAA;AAAA,IACN,WAAA,EAAa,oBAAA;AAAA,IACb,OAAA,EAAS,yBAAyB,cAAc,CAAA;AAAA,IAChD,IAAA,EAAM,SAAS,IAAI,CAAA;AAAA,IACnB,UAAA,EAAY;AAAA,MACR;AAAA,QACI,aAAA,EAAe,mBAAA;AAAA,QACf,SA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AAA,IACb,OAAA,EAAS,qBAAA;AAAA,MACL,CAAC,OAAA,KAAY,IAAI,uBAAA,CAAwB,OAAqC;AAAA,KAClF;AAAA,IACA,IAAA,EAAM,SAAS,IAAI,CAAA;AAAA,IACnB,UAAA,EAAY;AAAA,MACR;AAAA,QACI,aAAA,EAAe,6BAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf,KACJ;AAAA,IACA,YAAA,EAAc;AAAA,MACV;AAAA,QACI,aAAA,EAAe,eAAA;AAAA,QACf,aAAA,EAAe,sBAAA;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,aAAA;AAAA,MACA,mBAAA;AAAA,MACA;AAAA,KACJ;AAAA,IACA,IAAA,EAAM,SAAS,IAAI;AAAA,GACtB,CAAA;AACL;;;;"}
|
package/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sources":["errors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nexport enum ErrorId {\n // Problems with application metadata\n INVALID_METADATA = \"runtime:invalid-metadata\",\n INVALID_PROPERTY_NAME = \"runtime:invalid-property-name\",\n REQUIRED_PROPERTY = \"runtime:required-property\",\n\n // Application lifecycle\n NOT_MOUNTED = \"runtime:element-not-mounted\",\n UNSUPPORTED_LOCALE = \"runtime:unsupported-locale\",\n CONFIG_RESOLUTION_FAILED = \"runtime:config-resolution-failed\",\n INVALID_STATE = \"runtime:invalid-state\",\n\n // Service layer\n INTERFACE_NOT_FOUND = \"runtime:interface-not-found\",\n AMBIGUOUS_DEPENDENCY = \"runtime:ambiguous-dependency\",\n UNDECLARED_DEPENDENCY = \"runtime:undeclared-dependency\",\n MISSING_PACKAGE = \"runtime:missing-package\",\n SERVICE_CONSTRUCTION_FAILED = \"runtime:service-construction-failed\",\n SERVICE_DESTRUCTION_FAILED = \"runtime:service-destruction-failed\",\n DUPLICATE_INTERFACE = \"runtime:duplicate-interface\",\n DEPENDENCY_CYCLE = \"runtime:dependency-cycle\",\n\n // Web component API\n DUPLICATE_API_METHODS = \"runtime:duplicate-api-methods\",\n\n // Internal\n INTERNAL = \"runtime:internal-error\"\n}\n"],"names":["ErrorId"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["errors.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nexport enum ErrorId {\n // Problems with application metadata\n INVALID_METADATA = \"runtime:invalid-metadata\",\n INVALID_PROPERTY_NAME = \"runtime:invalid-property-name\",\n REQUIRED_PROPERTY = \"runtime:required-property\",\n\n // Application lifecycle\n NOT_MOUNTED = \"runtime:element-not-mounted\",\n UNSUPPORTED_LOCALE = \"runtime:unsupported-locale\",\n CONFIG_RESOLUTION_FAILED = \"runtime:config-resolution-failed\",\n INVALID_STATE = \"runtime:invalid-state\",\n\n // Service layer\n INTERFACE_NOT_FOUND = \"runtime:interface-not-found\",\n AMBIGUOUS_DEPENDENCY = \"runtime:ambiguous-dependency\",\n UNDECLARED_DEPENDENCY = \"runtime:undeclared-dependency\",\n MISSING_PACKAGE = \"runtime:missing-package\",\n SERVICE_CONSTRUCTION_FAILED = \"runtime:service-construction-failed\",\n SERVICE_DESTRUCTION_FAILED = \"runtime:service-destruction-failed\",\n DUPLICATE_INTERFACE = \"runtime:duplicate-interface\",\n DEPENDENCY_CYCLE = \"runtime:dependency-cycle\",\n\n // Web component API\n DUPLICATE_API_METHODS = \"runtime:duplicate-api-methods\",\n\n // Internal\n INTERNAL = \"runtime:internal-error\"\n}\n"],"names":["ErrorId"],"mappings":"AAGO,IAAK,OAAA,qBAAAA,QAAAA,KAAL;AAEH,EAAAA,SAAA,kBAAA,CAAA,GAAmB,0BAAA;AACnB,EAAAA,SAAA,uBAAA,CAAA,GAAwB,+BAAA;AACxB,EAAAA,SAAA,mBAAA,CAAA,GAAoB,2BAAA;AAGpB,EAAAA,SAAA,aAAA,CAAA,GAAc,6BAAA;AACd,EAAAA,SAAA,oBAAA,CAAA,GAAqB,4BAAA;AACrB,EAAAA,SAAA,0BAAA,CAAA,GAA2B,kCAAA;AAC3B,EAAAA,SAAA,eAAA,CAAA,GAAgB,uBAAA;AAGhB,EAAAA,SAAA,qBAAA,CAAA,GAAsB,6BAAA;AACtB,EAAAA,SAAA,sBAAA,CAAA,GAAuB,8BAAA;AACvB,EAAAA,SAAA,uBAAA,CAAA,GAAwB,+BAAA;AACxB,EAAAA,SAAA,iBAAA,CAAA,GAAkB,yBAAA;AAClB,EAAAA,SAAA,6BAAA,CAAA,GAA8B,qCAAA;AAC9B,EAAAA,SAAA,4BAAA,CAAA,GAA6B,oCAAA;AAC7B,EAAAA,SAAA,qBAAA,CAAA,GAAsB,6BAAA;AACtB,EAAAA,SAAA,kBAAA,CAAA,GAAmB,0BAAA;AAGnB,EAAAA,SAAA,uBAAA,CAAA,GAAwB,+BAAA;AAGxB,EAAAA,SAAA,UAAA,CAAA,GAAW,wBAAA;AA1BH,EAAA,OAAAA,QAAAA;AAAA,CAAA,EAAA,OAAA,IAAA,EAAA;;;;"}
|
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 {\n batch,\n computed,\n constant,\n reactive,\n Reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport {\n createLogger,\n destroyResource,\n Error,\n Resource,\n shallowEqual,\n throwAbortError\n} 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 { tryParseLocale } from \"./intl-locale\";\nimport { createPackageIntl, PackageIntl } from \"./PackageIntl\";\nimport { LocalePicker, getBrowserLocales } from \"./pick\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * Options for {@link AppIntl.create}.\n */\nexport interface I18nOptions {\n // build metadata\n appMetadata: ApplicationMetadata | undefined;\n\n // locale override (e.g. from config or URL param)\n forcedLocale?: string | undefined;\n\n /**\n * Restriction on supported locales.\n * If provided, only these locales are considered for locale picking and switching.\n * If not provided, all locales from app metadata are supported.\n */\n restrictSupportedLocales?: readonly string[];\n\n /**\n * If true, locale switching via {@link AppIntl.changeLocale} is supported and\n * applied in place (locale, messageLocale and PackageIntl instances become reactive).\n *\n * If false (default), {@link AppIntl.changeLocale} triggers an application\n * restart via {@link restartWithLocale}.\n */\n supportsLiveChanges?: boolean;\n\n /** hook given by AppInstance to trigger restart of the application. Called by changeLocale when reactive switching is OFF. */\n restartWithLocale(locale: Intl.Locale | undefined): void;\n}\n\n/**\n * Represents i18n info for the entire application.\n * Not exposed to user code.\n *\n * @internal\n */\nexport class AppIntl {\n /**\n * Initializes the application's locale and fetches the appropriate i18n messages.\n */\n static async create(options: I18nOptions): Promise<AppIntl> {\n const appIntl = new AppIntl(options);\n await appIntl.#loadInitialMessages();\n return appIntl;\n }\n\n readonly #appMetadata: ApplicationMetadata | undefined;\n readonly #effectiveSupportedLocales: Intl.Locale[];\n readonly #userLocales: Intl.Locale[];\n readonly #localePicker: LocalePicker;\n readonly #supportsLiveChanges: boolean;\n readonly #restartWithLocale: (locale: Intl.Locale | undefined) => void;\n\n // Messages are reactive: they can change if the locale changes at runtime\n // or if the developer edits i18n files on disk during development.\n readonly #messages: Reactive<MessagesRecord>;\n\n // Locale and messageLocale support reactive changes if `supportsLiveChanges` is enabled.\n readonly #locale: Reactive<Intl.Locale>;\n readonly #messageLocale: Reactive<Intl.Locale>;\n\n /** During dev: watch for changes of the loadMessage function. */\n #hmrWatch: Resource | undefined;\n\n /** Monotonic counter to discard outdated changeLocale results. */\n #changeLocaleSeq = 0;\n\n private constructor(options: I18nOptions) {\n const {\n appMetadata,\n forcedLocale,\n restrictSupportedLocales,\n supportsLiveChanges = false,\n restartWithLocale\n } = options;\n\n const messageLocaleStrings = appMetadata?.locales ?? [];\n const effectiveSupportedLocales = filterAvailableLocales(\n messageLocaleStrings,\n restrictSupportedLocales\n );\n const userLocales = getBrowserLocales();\n const preferredLocale = tryParseLocale(forcedLocale);\n if (LOG.isDebug()) {\n const userLocalesList = userLocales.map((l) => l.baseName).join(\", \");\n const appLocalesList = messageLocaleStrings.join(\", \");\n const effectiveLocalesList = effectiveSupportedLocales\n .map((l) => l.baseName)\n .join(\", \");\n LOG.debug(\n `Attempting to pick locale for user (locales: ${userLocalesList}) from app (locales: ${appLocalesList}; ` +\n `restricted to ${effectiveLocalesList}) [forcedLocale=${preferredLocale?.baseName}].`\n );\n }\n\n const localePicker = new LocalePicker(effectiveSupportedLocales);\n const { locale: initialLocale, messageLocale: initialMessageLocale } =\n localePicker.pickSupportedLocale(preferredLocale, userLocales);\n\n if (LOG.isDebug()) {\n LOG.debug(\n `Using locale '${initialLocale.baseName}' with messages from locale '${initialMessageLocale.baseName}'.`\n );\n }\n\n this.#appMetadata = appMetadata;\n this.#effectiveSupportedLocales = effectiveSupportedLocales;\n this.#userLocales = userLocales;\n this.#localePicker = localePicker;\n this.#supportsLiveChanges = supportsLiveChanges;\n this.#restartWithLocale = restartWithLocale;\n\n // Initially empty; populated by #loadInitialMessages() before the instance is handed out.\n this.#messages = reactive<MessagesRecord>({});\n this.#locale = reactive(initialLocale);\n this.#messageLocale = reactive(initialMessageLocale);\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 if (import.meta.hot) {\n this.#hmrWatch = watchValue(\n () =>\n this.#appMetadata?.loadMessages\n ? unwrapBox(this.#appMetadata.loadMessages)\n : undefined,\n (loader) => {\n if (!loader) {\n return;\n }\n this.#applyHotUpdate(loader).catch((e) => {\n LOG.error(`Failed to load messages after hot reload`, e);\n });\n }\n );\n }\n }\n\n destroy(): void {\n this.#hmrWatch = destroyResource(this.#hmrWatch);\n }\n\n /** Locale for Intl formatting. */\n get locale(): Intl.Locale {\n return this.#locale.value;\n }\n\n /**\n * The locale of the currently loaded message bundle.\n * Always one of {@link supportedMessageLocales}.\n */\n get messageLocale(): Intl.Locale {\n return this.#messageLocale.value;\n }\n\n /** Supported locales from app metadata. */\n get supportedMessageLocales(): Intl.Locale[] {\n return this.#effectiveSupportedLocales;\n }\n\n /** True if reactive locale switching is enabled. */\n get supportsLiveChanges(): boolean {\n return this.#supportsLiveChanges;\n }\n\n /** True iff `locale` best-fits a supported bundle. */\n supportsLocale(locale: Intl.Locale): boolean {\n return this.#localePicker.supportsLocale(locale);\n }\n\n /**\n * Switches to `locale`. Best-fit match; throws `UNSUPPORTED_LOCALE` on no match.\n */\n async changeLocale(targetLocale: Intl.Locale | undefined): Promise<void> {\n const { locale: nextLocale, messageLocale: nextMessageLocale } =\n this.#localePicker.pickSupportedLocale(targetLocale, this.#userLocales);\n if (!this.#supportsLiveChanges) {\n //NOTE: it is important for restarts to ensure the input value (targetLocale) is passed to restartWithLocale, not the best-fit value (nextLocale).\n this.#restartWithLocale(targetLocale);\n return;\n }\n const seq = ++this.#changeLocaleSeq;\n const newMessages = await loadMessagesSafely(this.#appMetadata, nextMessageLocale);\n if (seq !== this.#changeLocaleSeq) {\n // Superseded by a newer call.\n throwAbortError();\n }\n\n batch(() => {\n this.#messages.value = newMessages;\n this.#locale.value = nextLocale;\n this.#messageLocale.value = nextMessageLocale;\n });\n if (LOG.isDebug()) {\n LOG.debug(\n `Locale switched: locale='${nextLocale.baseName}', messageLocale='${nextMessageLocale.baseName}'.`\n );\n }\n }\n\n /** Given the package name, constructs a package i18n instance. */\n createPackageI18n(packageName: string): ReadonlyReactive<PackageIntl> {\n //NOTE: locale instead of messageLocale is intentional,\n // to ensure that number formatting is still according to the current locale\n const makeIntl = (packageMessages: Record<string, string>) =>\n createPackageIntl(this.#locale.value.baseName, packageMessages);\n\n if (import.meta.hot || this.#supportsLiveChanges) {\n const packageMessages = computed(() => this.#messages.value[packageName] ?? {}, {\n equal: shallowEqual\n });\n\n let firstCall = true;\n return computed(() => {\n if (!firstCall) {\n LOG.info(\"Updating i18n messages of package\", packageName);\n }\n firstCall = false;\n return makeIntl(packageMessages.value);\n });\n }\n return constant(makeIntl(this.#messages.value[packageName] ?? {}));\n }\n\n /** Loads the initial message bundle for the picked locale. Called once, from {@link create}. */\n async #loadInitialMessages(): Promise<void> {\n this.#messages.value = await loadMessagesSafely(\n this.#appMetadata,\n this.#messageLocale.value\n );\n }\n\n async #applyHotUpdate(loader: MessageLoader): Promise<void> {\n const newMessages = (await loader(this.#messageLocale.value.baseName)) ?? {};\n LOG.debug(\"Applying new i18n messages\", newMessages);\n this.#messages.value = newMessages;\n }\n}\n\nfunction filterAvailableLocales(\n // locales from app metadata\n messageLocaleStrings: readonly string[],\n // optional restriction on supported locales, must be subset of messageLocaleStrings\n restrictSupportedLocales: readonly string[] | undefined\n): Intl.Locale[] {\n //NOTE: the set preserves the order of 'restrictSupportedLocales', this is relevant and intentional.\n const isRestricted = restrictSupportedLocales != null;\n const localesToSupport = new Set(restrictSupportedLocales ?? messageLocaleStrings);\n const supportedLocales: Intl.Locale[] = [];\n for (const l of localesToSupport) {\n if (!messageLocaleStrings.includes(l)) {\n // 'supportedLocales' may only restrict the locales defined by the application, not extend them.\n // A value outside the application's message locales is a configuration error.\n if (isRestricted) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Configured supported locale '${l}' is not one of the application's message locales [${messageLocaleStrings.join(\", \")}].`\n );\n }\n LOG.warn(`Locale '${l}' is not included in app metadata locales and will be ignored.`);\n continue;\n }\n const locale = tryParseLocale(l);\n if (!locale) {\n LOG.warn(\n `Locale '${l}' from app metadata is not a valid BCP 47 tag and will be ignored.`\n );\n continue;\n }\n supportedLocales.push(locale);\n }\n if (supportedLocales.length === 0) {\n LOG.debug(\n `No valid supported locales found. Locale picking and switching will be unavailable.`\n );\n }\n return supportedLocales;\n}\n\nasync function loadMessagesSafely(\n appMetadata: ApplicationMetadata | undefined,\n messageLocale: Intl.Locale\n): Promise<MessagesRecord> {\n const messageLocales = appMetadata?.locales ?? [];\n if (!appMetadata?.loadMessages || !messageLocales.includes(messageLocale.baseName)) {\n return {};\n }\n\n try {\n const loader = unwrapBox(appMetadata.loadMessages);\n const messagesRecord = (await loader(messageLocale.baseName)) ?? {};\n return messagesRecord;\n } catch (e) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to load messages for locale '${messageLocale.baseName}'.`,\n {\n cause: e\n }\n );\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AA2BA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAsC1B,MAAM,OAAA,CAAQ;AAAA;AAAA;AAAA;AAAA,EAIjB,aAAa,OAAO,OAAA,EAAwC;AACxD,IAAA,MAAM,O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AA;AAAA,OAChB;AACA,MAAA;AAAA,IACJ;AACA,IAAA,gBAAA,CAAiB,KAAK,MAAM,CAAA;AAAA,EAChC;AACA,EAAA,IAAI,gBAAA,CAAiB,WAAW,CAAA,EAAG;AAC/B,IAAA,GAAA,CAAI,KAAA;AAAA,MACA,CAAA,mFAAA;AAAA,KACJ;AAAA,EACJ;AACA,EAAA,OAAO,gBAAA;AACX;AAEA,eAAe,kBAAA,CACX,aACA,aAAA,EACuB;AACvB,EAAA,MAAM,cAAA,GAAiB,WAAA,EAAa,OAAA,IAAW,EAAC;AAChD,EAAA,IAAI,CAAC,aAAa,YAAA,IAAgB,CAAC,eAAe,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA,EAAG;AAChF,IAAA,OAAO,EAAC;AAAA,EACZ;AAEA,EAAA,IAAI;AACA,IAAA,MAAM,MAAA,GAAS,SAAA,CAAU,WAAA,CAAY,YAAY,CAAA;AACjD,IAAA,MAAM,iBAAkB,MAAM,MAAA,CAAO,aAAA,CAAc,QAAQ,KAAM,EAAC;AAClE,IAAA,OAAO,cAAA;AAAA,EACX,SAAS,CAAA,EAAG;AACR,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,oCAAA,EAAuC,cAAc,QAAQ,CAAA,EAAA,CAAA;AAAA,MAC7D;AAAA,QACI,KAAA,EAAO;AAAA;AACX,KACJ;AAAA,EACJ;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"AppIntl.js","sources":["AppIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n batch,\n computed,\n constant,\n reactive,\n Reactive,\n ReadonlyReactive,\n watchValue\n} from \"@conterra/reactivity-core\";\nimport {\n createLogger,\n destroyResource,\n Error,\n Resource,\n shallowEqual,\n throwAbortError\n} 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 { tryParseLocale } from \"./intl-locale\";\nimport { createPackageIntl, PackageIntl } from \"./PackageIntl\";\nimport { LocalePicker, getBrowserLocales } from \"./pick\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * Options for {@link AppIntl.create}.\n */\nexport interface I18nOptions {\n // build metadata\n appMetadata: ApplicationMetadata | undefined;\n\n // locale override (e.g. from config or URL param)\n forcedLocale?: string | undefined;\n\n /**\n * Restriction on supported locales.\n * If provided, only these locales are considered for locale picking and switching.\n * If not provided, all locales from app metadata are supported.\n */\n restrictSupportedLocales?: readonly string[];\n\n /**\n * If true, locale switching via {@link AppIntl.changeLocale} is supported and\n * applied in place (locale, messageLocale and PackageIntl instances become reactive).\n *\n * If false (default), {@link AppIntl.changeLocale} triggers an application\n * restart via {@link restartWithLocale}.\n */\n supportsLiveChanges?: boolean;\n\n /** hook given by AppInstance to trigger restart of the application. Called by changeLocale when reactive switching is OFF. */\n restartWithLocale(locale: Intl.Locale | undefined): void;\n}\n\n/**\n * Represents i18n info for the entire application.\n * Not exposed to user code.\n *\n * @internal\n */\nexport class AppIntl {\n /**\n * Initializes the application's locale and fetches the appropriate i18n messages.\n */\n static async create(options: I18nOptions): Promise<AppIntl> {\n const appIntl = new AppIntl(options);\n await appIntl.#loadInitialMessages();\n return appIntl;\n }\n\n readonly #appMetadata: ApplicationMetadata | undefined;\n readonly #effectiveSupportedLocales: Intl.Locale[];\n readonly #userLocales: Intl.Locale[];\n readonly #localePicker: LocalePicker;\n readonly #supportsLiveChanges: boolean;\n readonly #restartWithLocale: (locale: Intl.Locale | undefined) => void;\n\n // Messages are reactive: they can change if the locale changes at runtime\n // or if the developer edits i18n files on disk during development.\n readonly #messages: Reactive<MessagesRecord>;\n\n // Locale and messageLocale support reactive changes if `supportsLiveChanges` is enabled.\n readonly #locale: Reactive<Intl.Locale>;\n readonly #messageLocale: Reactive<Intl.Locale>;\n\n /** During dev: watch for changes of the loadMessage function. */\n #hmrWatch: Resource | undefined;\n\n /** Monotonic counter to discard outdated changeLocale results. */\n #changeLocaleSeq = 0;\n\n private constructor(options: I18nOptions) {\n const {\n appMetadata,\n forcedLocale,\n restrictSupportedLocales,\n supportsLiveChanges = false,\n restartWithLocale\n } = options;\n\n const messageLocaleStrings = appMetadata?.locales ?? [];\n const effectiveSupportedLocales = filterAvailableLocales(\n messageLocaleStrings,\n restrictSupportedLocales\n );\n const userLocales = getBrowserLocales();\n const preferredLocale = tryParseLocale(forcedLocale);\n if (LOG.isDebug()) {\n const userLocalesList = userLocales.map((l) => l.baseName).join(\", \");\n const appLocalesList = messageLocaleStrings.join(\", \");\n const effectiveLocalesList = effectiveSupportedLocales\n .map((l) => l.baseName)\n .join(\", \");\n LOG.debug(\n `Attempting to pick locale for user (locales: ${userLocalesList}) from app (locales: ${appLocalesList}; ` +\n `restricted to ${effectiveLocalesList}) [forcedLocale=${preferredLocale?.baseName}].`\n );\n }\n\n const localePicker = new LocalePicker(effectiveSupportedLocales);\n const { locale: initialLocale, messageLocale: initialMessageLocale } =\n localePicker.pickSupportedLocale(preferredLocale, userLocales);\n\n if (LOG.isDebug()) {\n LOG.debug(\n `Using locale '${initialLocale.baseName}' with messages from locale '${initialMessageLocale.baseName}'.`\n );\n }\n\n this.#appMetadata = appMetadata;\n this.#effectiveSupportedLocales = effectiveSupportedLocales;\n this.#userLocales = userLocales;\n this.#localePicker = localePicker;\n this.#supportsLiveChanges = supportsLiveChanges;\n this.#restartWithLocale = restartWithLocale;\n\n // Initially empty; populated by #loadInitialMessages() before the instance is handed out.\n this.#messages = reactive<MessagesRecord>({});\n this.#locale = reactive(initialLocale);\n this.#messageLocale = reactive(initialMessageLocale);\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 if (import.meta.hot) {\n this.#hmrWatch = watchValue(\n () =>\n this.#appMetadata?.loadMessages\n ? unwrapBox(this.#appMetadata.loadMessages)\n : undefined,\n (loader) => {\n if (!loader) {\n return;\n }\n this.#applyHotUpdate(loader).catch((e) => {\n LOG.error(`Failed to load messages after hot reload`, e);\n });\n }\n );\n }\n }\n\n destroy(): void {\n this.#hmrWatch = destroyResource(this.#hmrWatch);\n }\n\n /** Locale for Intl formatting. */\n get locale(): Intl.Locale {\n return this.#locale.value;\n }\n\n /**\n * The locale of the currently loaded message bundle.\n * Always one of {@link supportedMessageLocales}.\n */\n get messageLocale(): Intl.Locale {\n return this.#messageLocale.value;\n }\n\n /** Supported locales from app metadata. */\n get supportedMessageLocales(): Intl.Locale[] {\n return this.#effectiveSupportedLocales;\n }\n\n /** True if reactive locale switching is enabled. */\n get supportsLiveChanges(): boolean {\n return this.#supportsLiveChanges;\n }\n\n /** True iff `locale` best-fits a supported bundle. */\n supportsLocale(locale: Intl.Locale): boolean {\n return this.#localePicker.supportsLocale(locale);\n }\n\n /**\n * Switches to `locale`. Best-fit match; throws `UNSUPPORTED_LOCALE` on no match.\n */\n async changeLocale(targetLocale: Intl.Locale | undefined): Promise<void> {\n const { locale: nextLocale, messageLocale: nextMessageLocale } =\n this.#localePicker.pickSupportedLocale(targetLocale, this.#userLocales);\n if (!this.#supportsLiveChanges) {\n //NOTE: it is important for restarts to ensure the input value (targetLocale) is passed to restartWithLocale, not the best-fit value (nextLocale).\n this.#restartWithLocale(targetLocale);\n return;\n }\n const seq = ++this.#changeLocaleSeq;\n const newMessages = await loadMessagesSafely(this.#appMetadata, nextMessageLocale);\n if (seq !== this.#changeLocaleSeq) {\n // Superseded by a newer call.\n throwAbortError();\n }\n\n batch(() => {\n this.#messages.value = newMessages;\n this.#locale.value = nextLocale;\n this.#messageLocale.value = nextMessageLocale;\n });\n if (LOG.isDebug()) {\n LOG.debug(\n `Locale switched: locale='${nextLocale.baseName}', messageLocale='${nextMessageLocale.baseName}'.`\n );\n }\n }\n\n /** Given the package name, constructs a package i18n instance. */\n createPackageI18n(packageName: string): ReadonlyReactive<PackageIntl> {\n //NOTE: locale instead of messageLocale is intentional,\n // to ensure that number formatting is still according to the current locale\n const makeIntl = (packageMessages: Record<string, string>) =>\n createPackageIntl(this.#locale.value.baseName, packageMessages);\n\n if (import.meta.hot || this.#supportsLiveChanges) {\n const packageMessages = computed(() => this.#messages.value[packageName] ?? {}, {\n equal: shallowEqual\n });\n\n let firstCall = true;\n return computed(() => {\n if (!firstCall) {\n LOG.info(\"Updating i18n messages of package\", packageName);\n }\n firstCall = false;\n return makeIntl(packageMessages.value);\n });\n }\n return constant(makeIntl(this.#messages.value[packageName] ?? {}));\n }\n\n /** Loads the initial message bundle for the picked locale. Called once, from {@link create}. */\n async #loadInitialMessages(): Promise<void> {\n this.#messages.value = await loadMessagesSafely(\n this.#appMetadata,\n this.#messageLocale.value\n );\n }\n\n async #applyHotUpdate(loader: MessageLoader): Promise<void> {\n const newMessages = (await loader(this.#messageLocale.value.baseName)) ?? {};\n LOG.debug(\"Applying new i18n messages\", newMessages);\n this.#messages.value = newMessages;\n }\n}\n\nfunction filterAvailableLocales(\n // locales from app metadata\n messageLocaleStrings: readonly string[],\n // optional restriction on supported locales, must be subset of messageLocaleStrings\n restrictSupportedLocales: readonly string[] | undefined\n): Intl.Locale[] {\n //NOTE: the set preserves the order of 'restrictSupportedLocales', this is relevant and intentional.\n const isRestricted = restrictSupportedLocales != null;\n const localesToSupport = new Set(restrictSupportedLocales ?? messageLocaleStrings);\n const supportedLocales: Intl.Locale[] = [];\n for (const l of localesToSupport) {\n if (!messageLocaleStrings.includes(l)) {\n // 'supportedLocales' may only restrict the locales defined by the application, not extend them.\n // A value outside the application's message locales is a configuration error.\n if (isRestricted) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Configured supported locale '${l}' is not one of the application's message locales [${messageLocaleStrings.join(\", \")}].`\n );\n }\n LOG.warn(`Locale '${l}' is not included in app metadata locales and will be ignored.`);\n continue;\n }\n const locale = tryParseLocale(l);\n if (!locale) {\n LOG.warn(\n `Locale '${l}' from app metadata is not a valid BCP 47 tag and will be ignored.`\n );\n continue;\n }\n supportedLocales.push(locale);\n }\n if (supportedLocales.length === 0) {\n LOG.debug(\n `No valid supported locales found. Locale picking and switching will be unavailable.`\n );\n }\n return supportedLocales;\n}\n\nasync function loadMessagesSafely(\n appMetadata: ApplicationMetadata | undefined,\n messageLocale: Intl.Locale\n): Promise<MessagesRecord> {\n const messageLocales = appMetadata?.locales ?? [];\n if (!appMetadata?.loadMessages || !messageLocales.includes(messageLocale.baseName)) {\n return {};\n }\n\n try {\n const loader = unwrapBox(appMetadata.loadMessages);\n const messagesRecord = (await loader(messageLocale.baseName)) ?? {};\n return messagesRecord;\n } catch (e) {\n throw new Error(\n ErrorId.INTERNAL,\n `Failed to load messages for locale '${messageLocale.baseName}'.`,\n {\n cause: e\n }\n );\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AA4BA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAsC1B,MAAM,OAAA,CAAQ;AAAA;AAAA;AAAA;AAAA,EAIjB,aAAa,OAAO,OAAA,EAAwC;AACxD,IAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAAQ,OAAO,CAAA;AACnC,IAAA,MAAM,QAAQ,oBAAA,EAAqB;AACnC,IAAA,OAAO,OAAA;AAAA,EACX;AAAA,EAES,YAAA;AAAA,EACA,0BAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,oBAAA;AAAA,EACA,kBAAA;AAAA;AAAA;AAAA,EAIA,SAAA;AAAA;AAAA,EAGA,OAAA;AAAA,EACA,cAAA;AAAA;AAAA,EAGT,SAAA;AAAA;AAAA,EAGA,gBAAA,GAAmB,CAAA;AAAA,EAEX,YAAY,OAAA,EAAsB;AACtC,IAAA,MAAM;AAAA,MACF,WAAA;AAAA,MACA,YAAA;AAAA,MACA,wBAAA;AAAA,MACA,mBAAA,GAAsB,KAAA;AAAA,MACtB;AAAA,KACJ,GAAI,O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AAM,MAAA,GAAS,SAAA,CAAU,WAAA,CAAY,YAAY,CAAA;AACjD,IAAA,MAAM,iBAAkB,MAAM,MAAA,CAAO,aAAA,CAAc,QAAQ,KAAM,EAAC;AAClE,IAAA,OAAO,cAAA;AAAA,EACX,SAAS,CAAA,EAAG;AACR,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,CAAA,oCAAA,EAAuC,cAAc,QAAQ,CAAA,EAAA,CAAA;AAAA,MAC7D;AAAA,QACI,KAAA,EAAO;AAAA;AACX,KACJ;AAAA,EACJ;AACJ;;;;"}
|
package/i18n/PackageIntl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageIntl.js","sources":["PackageIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n createIntl,\n createIntlCache,\n IntlConfig,\n IntlErrorCode,\n IntlFormatters,\n IntlShape,\n MessageDescriptor,\n OnErrorFn\n} from \"@formatjs/intl\";\nimport {\n type FormatXMLElementFn,\n type Options as IntlMessageFormatOptions,\n type PrimitiveType\n} from \"intl-messageformat\"; // not a dependency, this is a dependency of formatjs\nimport { Children, createElement, Fragment, isValidElement, ReactNode } from \"react\";\n\ntype BaseIntl = Pick<IntlShape, \"locale\" | \"timeZone\"> &\n Omit<IntlFormatters<string>, \"formatMessage\">;\n\n/**\n * Gives access to the package's i18n messages for the current locale.\n *\n * See also https://formatjs.io/docs/intl\n */\nexport type PackageIntl = BaseIntl & PackageIntlExtensions;\n\n/**\n * Trails specific extensions to FormatJS' intl API.\n */\nexport interface PackageIntlExtensions {\n /**\n * Formats a message with the given descriptor and values.\n *\n * This is a method directly implemented by FormatJS see\n * - [Documentation](<https://formatjs.github.io/docs/intl/#formatmessage>)\n * - {@link IntlShape.formatMessage | Base Implementation}\n *\n * The typings here make the signature a little bit stricter: only primitive values\n * are allowed for formatting.\n *\n * If you need rich text (react) formatting, see {@link PackageIntlExtensions.formatRichMessage}.\n */\n formatMessage(\n this: void,\n descriptor: MessageDescriptor,\n values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>,\n opts?: IntlMessageFormatOptions\n ): string;\n\n /**\n * Similar to `formatMessage()`, but supports _rich text formatting_.\n *\n * React nodes are supported as input values, and custom tags can be implemented as react components.\n * Note that the output is always a single react node.\n *\n * *Example with react node as value:*\n *\n * ```tsx\n * function Example() {\n * const intl = useIntl();\n * // Given i18n message \"Hello, {name}!\"\n * // replaces 'name' with the given react node:\n * const message = intl.formatRichMessage({ id: \"foo\"}, {\n * name: <FancyUserName />\n * });\n * return <Box>{message}</Box>;\n * }\n * ```\n *\n * *Example with basic formatting:*\n *\n * ```tsx\n * function Example() {\n * const intl = useIntl();\n * // Given i18n message \"Hello, <strong>{name}</strong>!\"\n * // renders with actual <strong> html node:\n * return <Box>{intl.formatRichMessage({ id: \"foo\"}, { name: \"User\" })}</Box>;\n * }\n * ```\n *\n * Note that only a few basic formatting tags are predefined (\"b\", \"strong\", \"i\", \"em\", \"code\", \"br\").\n * If you need more advanced tags, you can define your own, see below.\n *\n * *Example with custom tag:*\n *\n * ```tsx\n * function Example() {\n * const intl = useIntl();\n * // Given i18n message \"Open <foo>the door</foo>!\",\n * // renders 'foo' using the formatter function below:\n * const message = intl.formatRichMessage({ id: \"foo\"}, {\n * foo: (parts) => <FancyTag>{parts}</FancyTag>\n * });\n * return <Box>{message}</Box>;\n * }\n * ```\n */\n formatRichMessage: (\n descriptor: MessageDescriptor,\n values?: Record<string, RichTextValue>,\n opts?: IntlMessageFormatOptions\n ) => ReactNode;\n}\n\n/**\n * Value types supported when rendering rich text messages.\n * Primitive values (or single react nodes) are used for normal values.\n * Functions are used to define how tags should be rendered.\n *\n * See {@link PackageIntlExtensions.formatRichMessage}\n */\nexport type RichTextValue = PrimitiveType | ReactNode | FormatXMLElementFn<ReactNode>;\n\n/**\n * Creates a package intl instance with the given locale and messages.\n *\n * @internal\n */\nexport function createPackageIntl(\n locale: string,\n messages: Record<string, string>,\n options?: {\n /** Used during testing to suppress console messages. */\n suppressNotFoundError?: boolean;\n\n /** Also used during testing */\n defaultLocale?: string;\n }\n): PackageIntl {\n const cache = createIntlCache();\n const config: IntlConfig = {\n locale,\n messages\n };\n if (options?.suppressNotFoundError) {\n config.onError = ignoreMissingTranslationError;\n }\n if (options?.defaultLocale) {\n config.defaultLocale = options.defaultLocale;\n }\n\n const intl = createIntl(config, cache) as unknown as PackageIntl;\n intl.formatRichMessage = formatRichMessage.bind(undefined, intl);\n return intl;\n}\n\n/** Creates an empty i18n instance, e.g. for tests. */\nexport function createEmptyPackageIntl(locale = \"en\"): PackageIntl {\n return createPackageIntl(locale, {});\n}\n\nconst RICH_TEXT_TAGS = Object.freeze({\n \"b\": renderTag(\"b\"),\n \"strong\": renderTag(\"strong\"),\n \"i\": renderTag(\"i\"),\n \"em\": renderTag(\"em\"),\n \"code\": renderTag(\"code\"),\n \"br\": renderTag(\"br\")\n});\n\nfunction formatRichMessage(\n intl: PackageIntl,\n descriptor: MessageDescriptor,\n values: Record<string, RichTextValue> | undefined,\n opts: IntlMessageFormatOptions | undefined\n): ReactNode {\n values = {\n ...RICH_TEXT_TAGS,\n ...values\n };\n\n //
|
|
1
|
+
{"version":3,"file":"PackageIntl.js","sources":["PackageIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n createIntl,\n createIntlCache,\n IntlConfig,\n IntlErrorCode,\n IntlFormatters,\n IntlShape,\n MessageDescriptor,\n OnErrorFn\n} from \"@formatjs/intl\";\nimport {\n type FormatXMLElementFn,\n type Options as IntlMessageFormatOptions,\n type PrimitiveType\n} from \"intl-messageformat\"; // not a dependency, this is a dependency of formatjs\nimport { Children, createElement, Fragment, isValidElement, ReactNode } from \"react\";\n\ntype BaseIntl = Pick<IntlShape, \"locale\" | \"timeZone\"> &\n Omit<IntlFormatters<string>, \"formatMessage\">;\n\n/**\n * Gives access to the package's i18n messages for the current locale.\n *\n * See also https://formatjs.io/docs/intl\n */\nexport type PackageIntl = BaseIntl & PackageIntlExtensions;\n\n/**\n * Trails specific extensions to FormatJS' intl API.\n */\nexport interface PackageIntlExtensions {\n /**\n * Formats a message with the given descriptor and values.\n *\n * This is a method directly implemented by FormatJS see\n * - [Documentation](<https://formatjs.github.io/docs/intl/#formatmessage>)\n * - {@link IntlShape.formatMessage | Base Implementation}\n *\n * The typings here make the signature a little bit stricter: only primitive values\n * are allowed for formatting.\n *\n * If you need rich text (react) formatting, see {@link PackageIntlExtensions.formatRichMessage}.\n */\n formatMessage(\n this: void,\n descriptor: MessageDescriptor,\n values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>,\n opts?: IntlMessageFormatOptions\n ): string;\n\n /**\n * Similar to `formatMessage()`, but supports _rich text formatting_.\n *\n * React nodes are supported as input values, and custom tags can be implemented as react components.\n * Note that the output is always a single react node.\n *\n * *Example with react node as value:*\n *\n * ```tsx\n * function Example() {\n * const intl = useIntl();\n * // Given i18n message \"Hello, {name}!\"\n * // replaces 'name' with the given react node:\n * const message = intl.formatRichMessage({ id: \"foo\"}, {\n * name: <FancyUserName />\n * });\n * return <Box>{message}</Box>;\n * }\n * ```\n *\n * *Example with basic formatting:*\n *\n * ```tsx\n * function Example() {\n * const intl = useIntl();\n * // Given i18n message \"Hello, <strong>{name}</strong>!\"\n * // renders with actual <strong> html node:\n * return <Box>{intl.formatRichMessage({ id: \"foo\"}, { name: \"User\" })}</Box>;\n * }\n * ```\n *\n * Note that only a few basic formatting tags are predefined (\"b\", \"strong\", \"i\", \"em\", \"code\", \"br\").\n * If you need more advanced tags, you can define your own, see below.\n *\n * *Example with custom tag:*\n *\n * ```tsx\n * function Example() {\n * const intl = useIntl();\n * // Given i18n message \"Open <foo>the door</foo>!\",\n * // renders 'foo' using the formatter function below:\n * const message = intl.formatRichMessage({ id: \"foo\"}, {\n * foo: (parts) => <FancyTag>{parts}</FancyTag>\n * });\n * return <Box>{message}</Box>;\n * }\n * ```\n */\n formatRichMessage: (\n descriptor: MessageDescriptor,\n values?: Record<string, RichTextValue>,\n opts?: IntlMessageFormatOptions\n ) => ReactNode;\n}\n\n/**\n * Value types supported when rendering rich text messages.\n * Primitive values (or single react nodes) are used for normal values.\n * Functions are used to define how tags should be rendered.\n *\n * See {@link PackageIntlExtensions.formatRichMessage}\n */\nexport type RichTextValue = PrimitiveType | ReactNode | FormatXMLElementFn<ReactNode>;\n\n/**\n * Creates a package intl instance with the given locale and messages.\n *\n * @internal\n */\nexport function createPackageIntl(\n locale: string,\n messages: Record<string, string>,\n options?: {\n /** Used during testing to suppress console messages. */\n suppressNotFoundError?: boolean;\n\n /** Also used during testing */\n defaultLocale?: string;\n }\n): PackageIntl {\n const cache = createIntlCache();\n const config: IntlConfig = {\n locale,\n messages\n };\n if (options?.suppressNotFoundError) {\n config.onError = ignoreMissingTranslationError;\n }\n if (options?.defaultLocale) {\n config.defaultLocale = options.defaultLocale;\n }\n\n const intl = createIntl(config, cache) as unknown as PackageIntl;\n intl.formatRichMessage = formatRichMessage.bind(undefined, intl);\n return intl;\n}\n\n/** Creates an empty i18n instance, e.g. for tests. */\nexport function createEmptyPackageIntl(locale = \"en\"): PackageIntl {\n return createPackageIntl(locale, {});\n}\n\nconst RICH_TEXT_TAGS = Object.freeze({\n \"b\": renderTag(\"b\"),\n \"strong\": renderTag(\"strong\"),\n \"i\": renderTag(\"i\"),\n \"em\": renderTag(\"em\"),\n \"code\": renderTag(\"code\"),\n \"br\": renderTag(\"br\")\n});\n\nfunction formatRichMessage(\n intl: PackageIntl,\n descriptor: MessageDescriptor,\n values: Record<string, RichTextValue> | undefined,\n opts: IntlMessageFormatOptions | undefined\n): ReactNode {\n values = {\n ...RICH_TEXT_TAGS,\n ...values\n };\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const chunks: any = intl.formatMessage(descriptor, preprocessValues(values) as any, opts);\n const nodes = assignKeys(chunks);\n return createElement(Fragment, undefined, ...nodes);\n}\n\nfunction preprocessValues(values: Record<string, RichTextValue> | undefined) {\n if (!values) {\n return undefined;\n }\n\n const fixedValues: Record<string, RichTextValue> = {};\n for (const [key, valueOrFn] of Object.entries(values)) {\n let fixedValue = valueOrFn;\n if (typeof valueOrFn === \"function\") {\n fixedValue = (parts) => valueOrFn(assignKeys(parts));\n }\n fixedValues[key] = fixedValue;\n }\n return fixedValues;\n}\n\nfunction renderTag(tag: string): FormatXMLElementFn<ReactNode> {\n return function renderRichTag(parts) {\n return createElement(tag, undefined, ...parts);\n };\n}\n\n// Seems to be required to get rid of \"key\" warnings.\n// See https://github.com/formatjs/formatjs/pull/4895/files\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction assignKeys(chunks: any): any[] {\n const nodes = Children.map(chunks, assignKey) ?? [];\n return Children.toArray(nodes);\n}\n\nconst ANY_KEY = { key: 42 };\n\nfunction assignKey(reactNode: React.ReactNode) {\n return isValidElement(reactNode) ? createElement(Fragment, ANY_KEY, reactNode) : reactNode;\n}\n\n/** Hides missing translation errors during tests */\nconst ignoreMissingTranslationError: OnErrorFn = (err) => {\n if (err.code === IntlErrorCode.MISSING_TRANSLATION) {\n return;\n }\n\n console.error(err);\n};\n"],"names":[],"mappings":";;;AA0HO,SAAS,iBAAA,CACZ,MAAA,EACA,QAAA,EACA,OAAA,EAOW;AACX,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,MAAM,MAAA,GAAqB;AAAA,IACvB,MAAA;AAAA,IACA;AAAA,GACJ;AACA,EAAA,IAAI,SAAS,qBAAA,EAAuB;AAChC,IAAA,MAAA,CAAO,OAAA,GAAU,6BAAA;AAAA,EACrB;AACA,EAAA,IAAI,SAAS,aAAA,EAAe;AACxB,IAAA,MAAA,CAAO,gBAAgB,OAAA,CAAQ,aAAA;AAAA,EACnC;AAEA,EAAA,MAAM,IAAA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I,OAAO,cAAc,UAAA,EAAY;AACjC,MAAA,UAAA,GAAa,CAAC,KAAA,KAAU,SAAA,CAAU,UAAA,CAAW,KAAK,CAAC,CAAA;AAAA,IACvD;AACA,IAAA,WAAA,CAAY,GAAG,CAAA,GAAI,UAAA;AAAA,EACvB;AACA,EAAA,OAAO,WAAA;AACX;AAEA,SAAS,UAAU,GAAA,EAA4C;AAC3D,EAAA,OAAO,SAAS,cAAc,KAAA,EAAO;AACjC,IAAA,OAAO,aAAA,CAAc,GAAA,EAAK,MAAA,EAAW,GAAG,KAAK,CAAA;AAAA,EACjD,CAAA;AACJ;AAKA,SAAS,WAAW,MAAA,EAAoB;AACpC,EAAA,MAAM,QAAQ,QAAA,CAAS,GAAA,CAAI,MAAA,EAAQ,SAAS,KAAK,EAAC;AAClD,EAAA,OAAO,QAAA,CAAS,QAAQ,KAAK,CAAA;AACjC;AAEA,MAAM,OAAA,GAAU,EAAE,GAAA,EAAK,EAAA,EAAG;AAE1B,SAAS,UAAU,SAAA,EAA4B;AAC3C,EAAA,OAAO,eAAe,SAAS,CAAA,GAAI,cAAc,QAAA,EAAU,OAAA,EAAS,SAAS,CAAA,GAAI,SAAA;AACrF;AAGA,MAAM,6BAAA,GAA2C,CAAC,GAAA,KAAQ;AACtD,EAAA,IAAI,GAAA,CAAI,IAAA,KAAS,aAAA,CAAc,mBAAA,EAAqB;AAChD,IAAA;AAAA,EACJ;AAEA,EAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AACrB,CAAA;;;;"}
|
package/i18n/pick.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.js","sources":["pick.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { match as bestFitMatch } from \"@formatjs/intl-localematcher\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { parseLocale, tryParseLocale } from \"./intl-locale\";\n\nconst NO_MATCH_SENTINEL = \"qaa-x-no-match\";\n\nconst LOCALE_FIELDS = [\"language\", \"script\", \"region\"] as const;\n\n/**\n * Result of {@link LocalePicker.pickSupportedLocale}.\n */\nexport interface LocalePickResult {\n /**\n * The actual locale (e.g. `de-DE`) used for number/date formatting.\n */\n locale: Intl.Locale;\n\n /**\n * The locale of the matched message bundle (e.g. `de`).\n */\n messageLocale: Intl.Locale;\n}\n\n/**\n * Picks a locale for an application based on the locales it supports\n * and the locales requested by a user.\n */\nexport class LocalePicker {\n #supportedLocales: readonly Intl.Locale[];\n #supportedTags: readonly string[];\n\n /**\n * @param supportedLocales Locales the app has i18n messages for (e.g. `\"en\"`, `\"de\"`, `\"de-CH\"`).\n * May be empty; in that case the picker behaves as if a single `\"en\"`\n * supported locale were configured.\n */\n constructor(supportedLocales: ReadonlyArray<Intl.Locale>) {\n this.#supportedLocales =\n supportedLocales.length > 0 ? supportedLocales : [parseLocale(\"en\")];\n this.#supportedTags = this.#supportedLocales.map((l) => l.baseName);\n }\n\n /**\n * Picks the locale to use during application startup or for a runtime locale switch.\n *\n * @param preferredLocale Optional preferred (forced) locale.\n * @param userLocales Locales requested by the user's browser, in priority order.\n */\n pickSupportedLocale(\n preferredLocale: Intl.Locale | undefined,\n userLocales: Intl.Locale[]\n ): LocalePickResult {\n const messageLocale = this.#pickMessageLocale(preferredLocale, userLocales);\n const base = preferredLocale ?? messageLocale;\n const locale = this.#pickFormattingLocale(base, userLocales);\n return { locale, messageLocale };\n }\n\n /**\n * Returns `true` if the given locale is accepted by\n * {@link pickSupportedLocale}.\n */\n supportsLocale(locale: Intl.Locale): boolean {\n return bestFit([locale.baseName], this.#supportedTags) !== NO_MATCH_SENTINEL;\n }\n\n #pickMessageLocale(\n preferred: Intl.Locale | undefined,\n browserLocales: Intl.Locale[]\n ): Intl.Locale {\n const candidates = preferred ? [preferred] : browserLocales;\n // #supportedLocales is guaranteed non-empty (see constructor).\n //
|
|
1
|
+
{"version":3,"file":"pick.js","sources":["pick.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { match as bestFitMatch } from \"@formatjs/intl-localematcher\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ErrorId } from \"../errors\";\nimport { parseLocale, tryParseLocale } from \"./intl-locale\";\n\nconst NO_MATCH_SENTINEL = \"qaa-x-no-match\";\n\nconst LOCALE_FIELDS = [\"language\", \"script\", \"region\"] as const;\n\n/**\n * Result of {@link LocalePicker.pickSupportedLocale}.\n */\nexport interface LocalePickResult {\n /**\n * The actual locale (e.g. `de-DE`) used for number/date formatting.\n */\n locale: Intl.Locale;\n\n /**\n * The locale of the matched message bundle (e.g. `de`).\n */\n messageLocale: Intl.Locale;\n}\n\n/**\n * Picks a locale for an application based on the locales it supports\n * and the locales requested by a user.\n */\nexport class LocalePicker {\n #supportedLocales: readonly Intl.Locale[];\n #supportedTags: readonly string[];\n\n /**\n * @param supportedLocales Locales the app has i18n messages for (e.g. `\"en\"`, `\"de\"`, `\"de-CH\"`).\n * May be empty; in that case the picker behaves as if a single `\"en\"`\n * supported locale were configured.\n */\n constructor(supportedLocales: ReadonlyArray<Intl.Locale>) {\n this.#supportedLocales =\n supportedLocales.length > 0 ? supportedLocales : [parseLocale(\"en\")];\n this.#supportedTags = this.#supportedLocales.map((l) => l.baseName);\n }\n\n /**\n * Picks the locale to use during application startup or for a runtime locale switch.\n *\n * @param preferredLocale Optional preferred (forced) locale.\n * @param userLocales Locales requested by the user's browser, in priority order.\n */\n pickSupportedLocale(\n preferredLocale: Intl.Locale | undefined,\n userLocales: Intl.Locale[]\n ): LocalePickResult {\n const messageLocale = this.#pickMessageLocale(preferredLocale, userLocales);\n const base = preferredLocale ?? messageLocale;\n const locale = this.#pickFormattingLocale(base, userLocales);\n return { locale, messageLocale };\n }\n\n /**\n * Returns `true` if the given locale is accepted by\n * {@link pickSupportedLocale}.\n */\n supportsLocale(locale: Intl.Locale): boolean {\n return bestFit([locale.baseName], this.#supportedTags) !== NO_MATCH_SENTINEL;\n }\n\n #pickMessageLocale(\n preferred: Intl.Locale | undefined,\n browserLocales: Intl.Locale[]\n ): Intl.Locale {\n const candidates = preferred ? [preferred] : browserLocales;\n // #supportedLocales is guaranteed non-empty (see constructor).\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n const firstSupported = this.#supportedLocales[0]!;\n if (candidates.length === 0) {\n return firstSupported;\n }\n\n const match = bestFit(\n candidates.map((l) => l.baseName),\n this.#supportedTags\n );\n if (match !== NO_MATCH_SENTINEL) {\n return parseLocale(match);\n }\n if (preferred) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${preferred.baseName}' (supported locales: ${this.#supportedTags.join(\", \")}).`\n );\n }\n return firstSupported;\n }\n\n #pickFormattingLocale(base: Intl.Locale, userLocales: Intl.Locale[]): Intl.Locale {\n let candidate = base;\n let bestScore = equalityScore(candidate, base);\n // try to find a more specific locale from the user's browser locales\n for (const userLocale of userLocales) {\n const score = equalityScore(userLocale, base);\n if (score > bestScore) {\n candidate = userLocale;\n bestScore = score;\n }\n }\n return candidate;\n }\n}\n\n// Higher score means the candidate shares more fields with the base locale\n// without contradicting any field defined on the base.\nfunction equalityScore(candidate: Intl.Locale, base: Intl.Locale): number {\n let score = 0;\n for (const field of LOCALE_FIELDS) {\n const b = base[field];\n const c = candidate[field];\n if (b && c !== b) return 0;\n if (c) score++;\n }\n return score;\n}\n\n/**\n * Runs the CLDR best-fit matcher and returns either a supported tag or\n * {@link NO_MATCH_SENTINEL} when no real match exists.\n */\nfunction bestFit(tags: readonly string[], supportedTags: readonly string[]): string {\n return bestFitMatch(tags, supportedTags, NO_MATCH_SENTINEL, {\n algorithm: \"best fit\"\n });\n}\n\n/**\n * Returns the locales currently preferred by the user's browser, in order of preference.\n *\n * See also https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages\n *\n * Invalid entries (which should not occur in practice) are silently dropped.\n */\nexport function getBrowserLocales(): Intl.Locale[] {\n if (typeof window === \"undefined\") {\n return [];\n }\n const tags = window.navigator.languages?.length\n ? window.navigator.languages\n : [window.navigator.language];\n return tags.map(tryParseLocale).filter((l) => !!l);\n}\n"],"names":["bestFitMatch"],"mappings":";;;;;AAQA,MAAM,iBAAA,GAAoB,gBAAA;AAE1B,MAAM,aAAA,GAAgB,CAAC,UAAA,EAAY,QAAA,EAAU,QAAQ,CAAA;AAqB9C,MAAM,YAAA,CAAa;AAAA,EACtB,iBAAA;AAAA,EACA,cAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,gBAAA,EAA8C;AACtD,IAAA,IAAA,CAAK,iBAAA,GACD,iBAAiB,MAAA,GAAS,CAAA,GAAI,mBAAmB,CAAC,WAAA,CAAY,IAAI,CAAC,CAAA;AACvE,IAAA,IAAA,CAAK,iBAAiB,IAAA,CAAK,iBAAA,CAAkB,IAAI,CAAC,CAAA,KAAM,EAAE,QAAQ,CAAA;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,mBAAA,CACI,iBACA,WAAA,EACgB;AAChB,IAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,kBAAA,CAAmB,eAAA,EAAiB,WAAW,CAAA;AAC1E,IAAA,MAAM,OAAO,eAAA,IAAmB,aAAA;AAChC,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,qBAAA,CAAsB,IAAA,EAAM,WAAW,CAAA;AAC3D,IAAA,OAAO,EAAE,QAAQ,aAAA,EAAc;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAe,MAAA,EAA8B;AACzC,IAAA,OAAO,QAAQ,CAAC,MAAA,CAAO,QAAQ,CAAA,EAAG,IAAA,CAAK,cAAc,CAAA,KAAM,iBAAA;AAAA,EAC/D;AAAA,EAEA,kBAAA,CACI,WACA,cAAA,EACW;AACX,IAAA,MAAM,UAAA,G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