@open-pioneer/runtime 4.7.0-dev.20260713101438 → 4.7.0

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +3 -2
  2. package/CustomElement.js +1 -1
  3. package/CustomElement.js.map +1 -1
  4. package/DeclaredService.d.ts +1 -1
  5. package/DeclaredService.js.map +1 -1
  6. package/Service.js.map +1 -1
  7. package/app/AppInstance.js +2 -2
  8. package/app/AppInstance.js.map +1 -1
  9. package/app/gatherConfig.js.map +1 -1
  10. package/app/logErrors.js.map +1 -1
  11. package/builtin-services/ApiServiceImpl.d.ts +1 -1
  12. package/builtin-services/ApiServiceImpl.js.map +1 -1
  13. package/builtin-services/ApplicationContextImpl.js.map +1 -1
  14. package/builtin-services/ApplicationLifecycleEventService.d.ts +1 -1
  15. package/builtin-services/ApplicationLifecycleEventService.js +1 -1
  16. package/builtin-services/ApplicationLifecycleEventService.js.map +1 -1
  17. package/builtin-services/LocaleServiceImpl.js.map +1 -1
  18. package/builtin-services/NumberParserServiceImpl.js.map +1 -1
  19. package/builtin-services/ThemeServiceImpl.js.map +1 -1
  20. package/builtin-services/index.js.map +1 -1
  21. package/errors.js.map +1 -1
  22. package/i18n/AppIntl.js.map +1 -1
  23. package/i18n/PackageIntl.js.map +1 -1
  24. package/i18n/pick.js.map +1 -1
  25. package/metadata/ObservableBox.js.map +1 -1
  26. package/package.json +9 -9
  27. package/react-integration/ChakraProvider.d.ts +1 -1
  28. package/react-integration/ChakraProvider.js.map +1 -1
  29. package/react-integration/ErrorScreen.js.map +1 -1
  30. package/react-integration/PackageContext.js.map +1 -1
  31. package/react-integration/ReactIntegration.d.ts +1 -1
  32. package/react-integration/ReactIntegration.js.map +1 -1
  33. package/react-integration/hooks.js +1 -1
  34. package/react-integration/hooks.js.map +1 -1
  35. package/service-layer/InterfaceSpec.js.map +1 -1
  36. package/service-layer/PackageRepr.js.map +1 -1
  37. package/service-layer/ServiceLayer.js.map +1 -1
  38. package/service-layer/ServiceLookup.js.map +1 -1
  39. package/service-layer/ServiceRepr.js.map +1 -1
  40. package/service-layer/verifyDependencies.js.map +1 -1
@@ -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,OAAA,GAAU,IAAI,OAAA,CAAQ,OAAO,CAAA;AACnC,IAAA,MAAM,QAAQ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AAK,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,OAAA;AAEJ,IAAA,MAAM,oBAAA,GAAuB,WAAA,EAAa,OAAA,IAAW,EAAC;AACt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BAAkB,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 +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 // eslint-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// eslint-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":";;;AAyHO,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,GAAO,UAAA,CAAW,MAAA,EAAQ,KAAK,CAAA;AACrC,EAAA,IAAA,CAAK,iBAAA,GAAoB,iBAAA,CAAkB,IAAA,CAAK,MAAA,EAAW,IAAI,CAAA;AAC/D,EAAA,OAAO,IAAA;AACX;AAGO,SAAS,sBAAA,CAAuB,SAAS,IAAA,EAAmB;AAC/D,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,EAAE,CAAA;AACvC;AAEA,MAAM,cAAA,GAAiB,OAAO,MAAA,CAAO;AAAA,EACjC,GAAA,EAAK,UAAU,GAAG,CAAA;AAAA,EAClB,QAAA,EAAU,UAAU,QAAQ,CAAA;AAAA,EAC5B,GAAA,EAAK,UAAU,GAAG,CAAA;AAAA,EAClB,IAAA,EAAM,UAAU,IAAI,CAAA;AAAA,EAC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,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;;;;"}
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,GAAO,UAAA,CAAW,MAAA,EAAQ,KAAK,CAAA;AACrC,EAAA,IAAA,CAAK,iBAAA,GAAoB,iBAAA,CAAkB,IAAA,CAAK,MAAA,EAAW,IAAI,CAAA;AAC/D,EAAA,OAAO,IAAA;AACX;AAGO,SAAS,sBAAA,CAAuB,SAAS,IAAA,EAAmB;AAC/D,EAAA,OAAO,iBAAA,CAAkB,MAAA,EAAQ,EAAE,CAAA;AACvC;AAEA,MAAM,cAAA,GAAiB,OAAO,MAAA,CAAO;AAAA,EACjC,GAAA,EAAK,UAAU,GAAG,CAAA;AAAA,EAClB,Q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;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 // eslint-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":";;;;;AAOA,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,E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,SAAA,GACjB,CAAC,MAAA,CAAO,SAAA,CAAU,QAAQ,CAAA;AAChC,EAAA,OAAO,IAAA,CAAK,IAAI,cAAc,CAAA,CAAE,OAAO,CAAC,CAAA,KAAM,CAAC,CAAC,CAAC,CAAA;AACrD;;;;"}
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,EAA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Y,KAAA;AAAA,MAChB;AAAA,IACJ;AACA,IAAA,OAAO,SAAA;AAAA,EACX;AACJ;AAIA,SAAS,aAAA,CAAc,WAAwB,IAAA,EAA2B;AACtE,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,KAAA,MAAW,SAAS,aAAA,EAAe;AAC/B,IAAA,MAAM,CAAA,GAAI,KAAK,KAAK,CAAA;AACpB,IAAA,MAAM,CAAA,GAAI,UAAU,KAAK,CAAA;AACzB,IAAA,IAAI,CAAA,IAAK,CAAA,KAAM,CAAA,EAAG,OAAO,CAAA;AACzB,IAAA,IAAI,CAAA,EAAG,KAAA,EAAA;AAAA,EACX;AACA,EAAA,OAAO,KAAA;AACX;AAMA,SAAS,OAAA,CAAQ,MAAyB,aAAA,EAA0C;AAChF,EAAA,OAAOA,KAAA,CAAa,IAAA,EAAM,aAAA,EAAe,iBAAA,EAAmB;AAAA,IACxD,SAAA,EAAW;AAAA,GACd,CAAA;AACL;AASO,SAAS,iBAAA,GAAmC;AAC/C,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AAC/B,IAAA,OAAO,EAAC;AAAA,EACZ;AACA,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,SAAA,EAAW,MAAA,GACnC,MAAA,CAAO,SAAA,CAAU,SAAA,GACjB,CAAC,MAAA,CAAO,SAAA,CAAU,QAAQ,CAAA;AAChC,EAAA,OAAO,IAAA,CAAK,IAAI,cAAc,CAAA,CAAE,OAAO,CAAC,CAAA,KAAM,CAAC,CAAC,CAAC,CAAA;AACrD;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { reactive, Reactive } from \"@conterra/reactivity-core\";\n\nexport interface ObservableBox<T> {\n /** The current value. Reactive. */\n readonly value: T;\n\n /**\n * Changes the current value.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n setValue?(newValue: T): void;\n}\n\n/**\n * Returns a boxed value.\n * In development node, the box value can be changed and observed.\n */\nexport function createBox<T>(value: T): ObservableBox<T> {\n return new BoxImpl(value);\n}\n\n/** @internal */\nexport function isBox<T>(value: T | ObservableBox<T>): value is ObservableBox<T> {\n return value instanceof BoxImpl;\n}\n\n/** @internal */\nexport function unwrapBox<T>(value: T | ObservableBox<T>): T {\n return isBox(value) ? value.value : value;\n}\n\nclass BoxImpl<T> implements ObservableBox<T> {\n #signal: Reactive<T>;\n\n readonly setValue?: (newValue: T) => void;\n\n constructor(value: T) {\n this.#signal = reactive(value);\n if (import.meta.env.DEV) {\n this.setValue = (newValue) => {\n this.#signal.value = newValue;\n };\n }\n }\n\n get value(): T {\n return this.#signal.value;\n }\n}\n"],"names":[],"mappings":";;AAoBO,SAAS,UAAa,KAAA,EAA4B;AACrD,EAAA,OAAO,IAAI,QAAQ,KAAK,CAAA;AAC5B;AAGO,SAAS,MAAS,KAAA,EAAwD;AAC7E,EAAA,OAAO,KAAA,YAAiB,OAAA;AAC5B;AAGO,SAAS,UAAa,KAAA,EAAgC;AACzD,EAAA,OAAO,KAAA,CAAM,KAAK,CAAA,GAAI,KAAA,CAAM,KAAA,GAAQ,KAAA;AACxC;AAEA,MAAM,OAAA,CAAuC;AAAA,EACzC,OAAA;AAAA,EAES,QAAA;AAAA,EAET,YAAY,KAAA,EAAU;AAClB,IAAA,IAAA,CAAK,OAAA,GAAU,SAAS,KAAK,CAAA;AAC7B,IAAA,IAAI,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AACrB,MAAA,IAAA,CAAK,QAAA,GAAW,CAAC,QAAA,KAAa;AAC1B,QAAA,IAAA,CAAK,QAAQ,KAAA,GAAQ,QAAA;AAAA,MACzB,CAAA;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,IAAI,KAAA,GAAW;AACX,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACxB;AACJ;;;;"}
1
+ {"version":3,"file":"ObservableBox.js","sources":["ObservableBox.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { reactive, Reactive } from \"@conterra/reactivity-core\";\n\nexport interface ObservableBox<T> {\n /** The current value. Reactive. */\n readonly value: T;\n\n /**\n * Changes the current value.\n *\n * Note that this function is only present during development to facilitate hot reloading.\n */\n setValue?(newValue: T): void;\n}\n\n/**\n * Returns a boxed value.\n * In development node, the box value can be changed and observed.\n */\nexport function createBox<T>(value: T): ObservableBox<T> {\n return new BoxImpl(value);\n}\n\n/** @internal */\nexport function isBox<T>(value: T | ObservableBox<T>): value is ObservableBox<T> {\n return value instanceof BoxImpl;\n}\n\n/** @internal */\nexport function unwrapBox<T>(value: T | ObservableBox<T>): T {\n return isBox(value) ? value.value : value;\n}\n\nclass BoxImpl<T> implements ObservableBox<T> {\n #signal: Reactive<T>;\n\n readonly setValue?: (newValue: T) => void;\n\n constructor(value: T) {\n this.#signal = reactive(value);\n if (import.meta.env.DEV) {\n this.setValue = (newValue) => {\n this.#signal.value = newValue;\n };\n }\n }\n\n get value(): T {\n return this.#signal.value;\n }\n}\n"],"names":[],"mappings":";;AAqBO,SAAS,UAAa,KAAA,EAA4B;AACrD,EAAA,OAAO,IAAI,QAAQ,KAAK,CAAA;AAC5B;AAGO,SAAS,MAAS,KAAA,EAAwD;AAC7E,EAAA,OAAO,KAAA,YAAiB,OAAA;AAC5B;AAGO,SAAS,UAAa,KAAA,EAAgC;AACzD,EAAA,OAAO,KAAA,CAAM,KAAK,CAAA,GAAI,KAAA,CAAM,KAAA,GAAQ,KAAA;AACxC;AAEA,MAAM,OAAA,CAAuC;AAAA,EACzC,OAAA;AAAA,EAES,QAAA;AAAA,EAET,YAAY,KAAA,EAAU;AAClB,IAAA,IAAA,CAAK,OAAA,GAAU,SAAS,KAAK,CAAA;AAC7B,IAAA,IAAI,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AACrB,MAAA,IAAA,CAAK,QAAA,GAAW,CAAC,QAAA,KAAa;AAC1B,QAAA,IAAA,CAAK,QAAQ,KAAA,GAAQ,QAAA;AAAA,MACzB,CAAA;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,IAAI,KAAA,GAAW;AACX,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACxB;AACJ;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/runtime",
4
- "version": "4.7.0-dev.20260713101438",
4
+ "version": "4.7.0",
5
5
  "description": "Implements the runtime environment for Open Pioneer Trails apps.",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -14,17 +14,17 @@
14
14
  "directory": "src/packages/runtime"
15
15
  },
16
16
  "dependencies": {
17
+ "@chakra-ui/react": "^3.36.1",
17
18
  "@conterra/reactivity-core": "^0.8.6",
18
- "@formatjs/intl": "^4.1.15",
19
- "@formatjs/intl-localematcher": "^0.8.11",
20
- "@chakra-ui/react": "^3.36.0",
21
19
  "@emotion/cache": "^11.14.0",
22
20
  "@emotion/react": "^11.14.0",
23
- "react": "^19.2.7",
24
- "react-dom": "^19.2.7",
25
- "@open-pioneer/base-theme": "4.7.0-dev.20260713101438",
26
- "@open-pioneer/core": "4.7.0-dev.20260713101438",
27
- "@open-pioneer/reactivity": "4.7.0-dev.20260713101438"
21
+ "@formatjs/intl": "^4.1.17",
22
+ "@formatjs/intl-localematcher": "^0.8.13",
23
+ "react": "^19.2.8",
24
+ "react-dom": "^19.2.8",
25
+ "@open-pioneer/base-theme": "4.7.0",
26
+ "@open-pioneer/core": "4.7.0",
27
+ "@open-pioneer/reactivity": "4.7.0"
28
28
  },
29
29
  "exports": {
30
30
  "./package.json": "./package.json",
@@ -1,8 +1,8 @@
1
1
  import { SystemConfig } from "@chakra-ui/react";
2
2
  import { ReadonlyReactive } from "@conterra/reactivity-core";
3
3
  import { FC, PropsWithChildren } from "react";
4
- import { RootNode } from "../dom";
5
4
  import { ColorModeValue } from "../api";
5
+ import { RootNode } from "../dom";
6
6
  /** @internal */
7
7
  export type CustomChakraProviderProps = PropsWithChildren<{
8
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ChakraProvider.js","sources":["ChakraProvider.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n ChakraProvider,\n createSystem,\n defaultConfig,\n defineConfig,\n EnvironmentProvider,\n LocaleProvider,\n mergeConfigs,\n SystemConfig,\n SystemStyleObject\n} from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport createCache, { EmotionCache } from \"@emotion/cache\";\nimport { CacheProvider, Global } from \"@emotion/react\";\nimport { config as defaultTrailsConfig } from \"@open-pioneer/base-theme\";\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FC, PropsWithChildren, useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { APP_ROOT_CLASS, getBuiltinStyles, getStylesRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { ColorModeValue } from \"../api\";\n\n/** @internal */\nexport type CustomChakraProviderProps = PropsWithChildren<{\n /**\n * Document root node.\n */\n rootNode: RootNode;\n\n /**\n * Web component root.\n *\n * NOTE: undefined for test support only.\n */\n hostNode?: HTMLElement;\n\n /**\n * Application container (react's render target).\n */\n appRoot: HTMLElement;\n\n /**\n * Chakra system config (can be used to provide custom theme).\n */\n config?: ReadonlyReactive<SystemConfig | undefined>;\n\n /**\n * Application locale for chakra's `LocaleProvider`.\n */\n locale?: ReadonlyReactive<string>;\n\n /**\n * Custom color mode value.\n */\n colorMode: ReadonlyReactive<ColorModeValue>;\n\n /**\n * Custom CSS used by the application.\n */\n styles?: ReadonlyReactive<string>;\n}>;\n\nconst APP_ROOT_CSS = `.${APP_ROOT_CLASS}`;\n\n/**\n * Wraps the entire react application and configures chakra-ui (styling etc.).\n *\n * Exported so it can be used from the test-utils package.\n *\n * @internal\n */\nexport const CustomChakraProvider: FC<CustomChakraProviderProps> = ({\n rootNode,\n appRoot,\n hostNode,\n children,\n config,\n locale,\n colorMode,\n styles\n}) => {\n /*\n Setup chakra integration:\n\n 1. Mount styles into the shadow root via emotion\n 2. Use chakra's EnvironmentProvider to tell it about the shadow root context\n 3. Setup global styles correctly (selectors etc.) via chakra's system object\n 4. Render the rest of the application\n */\n\n const systemConfig = useReactiveSnapshot(() => config?.value ?? defaultTrailsConfig, [config]);\n const effectiveLocale = useReactiveSnapshot(() => locale?.value ?? \"en-US\", [locale]);\n\n const system = useMemo(() => {\n const mergedConfig = mergeConfigs(defaultConfig, systemConfig);\n return createSystem(\n mergedConfig,\n\n // https://www.chakra-ui.com/docs/get-started/environments/shadow-dom\n defineConfig({\n preflight: {\n scope: APP_ROOT_CSS\n },\n cssVarsRoot: APP_ROOT_CSS,\n conditions: redirectLightCondition(mergedConfig.conditions),\n globalCss: redirectHtmlProps(mergedConfig.globalCss)\n })\n );\n }, [systemConfig]);\n\n const effectiveColorMode = useReactiveSnapshot(() => colorMode.value, [colorMode]);\n\n useLayoutEffect(() => {\n const classes = appRoot.classList;\n classes.toggle(\"light\", effectiveColorMode === \"light\");\n classes.toggle(\"dark\", effectiveColorMode === \"dark\");\n appRoot.style.colorScheme = effectiveColorMode;\n }, [appRoot, effectiveColorMode]);\n\n const cache = useEmotionCache(rootNode);\n return (\n cache && (\n <CacheProvider value={cache}>\n <EnvironmentProvider\n value={rootNode}\n // Patched property\n portalNode={appRoot}\n >\n <LocaleProvider locale={effectiveLocale}>\n <ChakraProvider value={system}>\n <GlobalStyles rootNode={rootNode} hostNode={hostNode} styles={styles} />\n {children}\n </ChakraProvider>\n </LocaleProvider>\n </EnvironmentProvider>\n </CacheProvider>\n )\n );\n};\n\nfunction GlobalStyles(props: {\n rootNode: RootNode;\n hostNode: HTMLElement | undefined;\n styles: ReadonlyReactive<string> | undefined;\n}) {\n const { rootNode, hostNode, styles } = props;\n const builtinStyles = useMemo(() => {\n const css = getBuiltinStyles(rootNode, hostNode);\n return <Global styles={css} />;\n }, [rootNode, hostNode]);\n const appStyles = useReactiveSnapshot(() => {\n const css = styles?.value;\n return css && <Global styles={css} />;\n }, [styles]);\n return (\n <>\n {builtinStyles}\n {appStyles}\n </>\n );\n}\n\nfunction redirectHtmlProps(\n css: Record<string, SystemStyleObject> | undefined\n): Record<string, SystemStyleObject> {\n const { html, ...rest } = css ?? {};\n if (!html) {\n throw new Error(ErrorId.INTERNAL, \"Expected global rules on html element.\");\n }\n // Take default html styles and apply them to the host element instead\n return {\n ...rest,\n [APP_ROOT_CSS]: html\n };\n}\n\nfunction redirectLightCondition(\n conditions: Record<string, unknown> | undefined\n): Record<string, unknown> {\n // Make sure light mode tokens are applied\n return {\n ...conditions,\n // Before: \":root &, .light &\"\n light: `${APP_ROOT_CSS} &, .light &`\n };\n}\n\nfunction useEmotionCache(rootNode: RootNode): EmotionCache | undefined {\n const stylesRoot = useMemo(() => getStylesRoot(rootNode), [rootNode]);\n\n const [cache, setCache] = useState<EmotionCache | undefined>();\n useEffect(() => {\n const cache = createCache({\n key: \"css\",\n container: stylesRoot\n });\n\n // Disable useless warnings like `The pseudo class \":nth-child\" is potentially unsafe when doing server-side rendering. Try changing it to \":nth-of-type\".`\n // See: https://github.com/emotion-js/emotion/issues/1105#issuecomment-557726922\n cache.compat = true;\n\n setCache(cache);\n return () => {\n setCache(undefined);\n for (const tag of cache.sheet.tags) {\n tag.remove();\n }\n };\n }, [stylesRoot]);\n return cache;\n}\n"],"names":["config","defaultTrailsConfig","cache"],"mappings":";;;;;;;;;;;AAgEA,MAAM,YAAA,GAAe,IAAI,cAAc,CAAA,CAAA;AAShC,MAAM,uBAAsD,CAAC;AAAA,EAChE,QAAA;AAAA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rightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ChakraProvider,\n createSystem,\n defaultConfig,\n defineConfig,\n EnvironmentProvider,\n LocaleProvider,\n mergeConfigs,\n SystemConfig,\n SystemStyleObject\n} from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport createCache, { EmotionCache } from \"@emotion/cache\";\nimport { CacheProvider, Global } from \"@emotion/react\";\nimport { config as defaultTrailsConfig } from \"@open-pioneer/base-theme\";\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { FC, PropsWithChildren, useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { ColorModeValue } from \"../api\";\nimport { APP_ROOT_CLASS, getBuiltinStyles, getStylesRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\n\n/** @internal */\nexport type CustomChakraProviderProps = PropsWithChildren<{\n /**\n * Document root node.\n */\n rootNode: RootNode;\n\n /**\n * Web component root.\n *\n * NOTE: undefined for test support only.\n */\n hostNode?: HTMLElement;\n\n /**\n * Application container (react's render target).\n */\n appRoot: HTMLElement;\n\n /**\n * Chakra system config (can be used to provide custom theme).\n */\n config?: ReadonlyReactive<SystemConfig | undefined>;\n\n /**\n * Application locale for chakra's `LocaleProvider`.\n */\n locale?: ReadonlyReactive<string>;\n\n /**\n * Custom color mode value.\n */\n colorMode: ReadonlyReactive<ColorModeValue>;\n\n /**\n * Custom CSS used by the application.\n */\n styles?: ReadonlyReactive<string>;\n}>;\n\nconst APP_ROOT_CSS = `.${APP_ROOT_CLASS}`;\n\n/**\n * Wraps the entire react application and configures chakra-ui (styling etc.).\n *\n * Exported so it can be used from the test-utils package.\n *\n * @internal\n */\nexport const CustomChakraProvider: FC<CustomChakraProviderProps> = ({\n rootNode,\n appRoot,\n hostNode,\n children,\n config,\n locale,\n colorMode,\n styles\n}) => {\n /*\n Setup chakra integration:\n\n 1. Mount styles into the shadow root via emotion\n 2. Use chakra's EnvironmentProvider to tell it about the shadow root context\n 3. Setup global styles correctly (selectors etc.) via chakra's system object\n 4. Render the rest of the application\n */\n\n const systemConfig = useReactiveSnapshot(() => config?.value ?? defaultTrailsConfig, [config]);\n const effectiveLocale = useReactiveSnapshot(() => locale?.value ?? \"en-US\", [locale]);\n\n const system = useMemo(() => {\n const mergedConfig = mergeConfigs(defaultConfig, systemConfig);\n return createSystem(\n mergedConfig,\n\n // https://www.chakra-ui.com/docs/get-started/environments/shadow-dom\n defineConfig({\n preflight: {\n scope: APP_ROOT_CSS\n },\n cssVarsRoot: APP_ROOT_CSS,\n conditions: redirectLightCondition(mergedConfig.conditions),\n globalCss: redirectHtmlProps(mergedConfig.globalCss)\n })\n );\n }, [systemConfig]);\n\n const effectiveColorMode = useReactiveSnapshot(() => colorMode.value, [colorMode]);\n\n useLayoutEffect(() => {\n const classes = appRoot.classList;\n classes.toggle(\"light\", effectiveColorMode === \"light\");\n classes.toggle(\"dark\", effectiveColorMode === \"dark\");\n appRoot.style.colorScheme = effectiveColorMode;\n }, [appRoot, effectiveColorMode]);\n\n const cache = useEmotionCache(rootNode);\n return (\n cache && (\n <CacheProvider value={cache}>\n <EnvironmentProvider\n value={rootNode}\n // Patched property\n portalNode={appRoot}\n >\n <LocaleProvider locale={effectiveLocale}>\n <ChakraProvider value={system}>\n <GlobalStyles rootNode={rootNode} hostNode={hostNode} styles={styles} />\n {children}\n </ChakraProvider>\n </LocaleProvider>\n </EnvironmentProvider>\n </CacheProvider>\n )\n );\n};\n\nfunction GlobalStyles(props: {\n rootNode: RootNode;\n hostNode: HTMLElement | undefined;\n styles: ReadonlyReactive<string> | undefined;\n}) {\n const { rootNode, hostNode, styles } = props;\n const builtinStyles = useMemo(() => {\n const css = getBuiltinStyles(rootNode, hostNode);\n return <Global styles={css} />;\n }, [rootNode, hostNode]);\n const appStyles = useReactiveSnapshot(() => {\n const css = styles?.value;\n return css && <Global styles={css} />;\n }, [styles]);\n return (\n <>\n {builtinStyles}\n {appStyles}\n </>\n );\n}\n\nfunction redirectHtmlProps(\n css: Record<string, SystemStyleObject> | undefined\n): Record<string, SystemStyleObject> {\n const { html, ...rest } = css ?? {};\n if (!html) {\n throw new Error(ErrorId.INTERNAL, \"Expected global rules on html element.\");\n }\n // Take default html styles and apply them to the host element instead\n return {\n ...rest,\n [APP_ROOT_CSS]: html\n };\n}\n\nfunction redirectLightCondition(\n conditions: Record<string, unknown> | undefined\n): Record<string, unknown> {\n // Make sure light mode tokens are applied\n return {\n ...conditions,\n // Before: \":root &, .light &\"\n light: `${APP_ROOT_CSS} &, .light &`\n };\n}\n\nfunction useEmotionCache(rootNode: RootNode): EmotionCache | undefined {\n const stylesRoot = useMemo(() => getStylesRoot(rootNode), [rootNode]);\n\n const [cache, setCache] = useState<EmotionCache | undefined>();\n useEffect(() => {\n const cache = createCache({\n key: \"css\",\n container: stylesRoot\n });\n\n // Disable useless warnings like `The pseudo class \":nth-child\" is potentially unsafe when doing server-side rendering. Try changing it to \":nth-of-type\".`\n // See: https://github.com/emotion-js/emotion/issues/1105#issuecomment-557726922\n cache.compat = true;\n\n setCache(cache);\n return () => {\n setCache(undefined);\n for (const tag of cache.sheet.tags) {\n tag.remove();\n }\n };\n }, [stylesRoot]);\n return cache;\n}\n"],"names":["config","defaultTrailsConfig","cache"],"mappings":";;;;;;;;;;;AAiEA,MAAM,YAAA,GAAe,IAAI,cAAc,CAAA,CAAA;AAShC,MAAM,uBAAsD,CAAC;AAAA,EAChE,QAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,UACAA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA;AACJ,CAAA,KAAM;AAUF,EAAA,MAAM,YAAA,GAAe,oBAAoB,MAAMA,QAAA,EAAQ,SAASC,MAAA,EAAqB,CAACD,QAAM,CAAC,CAAA;AAC7F,EAAA,MAAM,eAAA,GAAkB,oBAAo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AAA;AAAA,IACH,CAAC,YAAY,GAAG;AAAA,GACpB;AACJ;AAEA,SAAS,uBACL,UAAA,EACuB;AAEvB,EAAA,OAAO;AAAA,IACH,GAAG,UAAA;AAAA;AAAA,IAEH,KAAA,EAAO,GAAG,YAAY,CAAA,YAAA;AAAA,GAC1B;AACJ;AAEA,SAAS,gBAAgB,QAAA,EAA8C;AACnE,EAAA,MAAM,UAAA,GAAa,QAAQ,MAAM,aAAA,CAAc,QAAQ,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEpE,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,QAAA,EAAmC;AAC7D,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,MAAME,SAAQ,WAAA,CAAY;AAAA,MACtB,GAAA,EAAK,KAAA;AAAA,MACL,SAAA,EAAW;AAAA,KACd,CAAA;AAID,IAAAA,OAAM,MAAA,GAAS,IAAA;AAEf,IAAA,QAAA,CAASA,MAAK,CAAA;AACd,IAAA,OAAO,MAAM;AACT,MAAA,QAAA,CAAS,MAAS,CAAA;AAClB,MAAA,KAAA,MAAW,GAAA,IAAOA,MAAAA,CAAM,KAAA,CAAM,IAAA,EAAM;AAChC,QAAA,GAAA,CAAI,MAAA,EAAO;AAAA,MACf;AAAA,IACJ,CAAA;AAAA,EACJ,CAAA,EAAG,CAAC,UAAU,CAAC,CAAA;AACf,EAAA,OAAO,KAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorScreen.js","sources":["ErrorScreen.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Alert, Box, Heading, Text, VStack } from \"@chakra-ui/react\";\nimport { PackageIntl } from \"../i18n\";\n\nconst MESSAGES_DE = {\n \"title\": \"Anwendungsstart fehlgeschlagen\",\n \"alertTitle\": \"Fehler\",\n \"alertDescription\": \"Leider ist beim Start der Anwendung ein Fehler aufgetreten.\",\n\n \"details.title\": \"Fehlerdetails\",\n \"details.inspect\": \"Konsole öffnen, um weitere Details zu sehen.\",\n \"details.errorMessage\": \"Fehler: {message}\"\n};\n\nconst MESSAGES_EN = {\n \"title\": \"Application start failed\",\n \"alertTitle\": \"Error\",\n \"alertDescription\": \"Unfortunately an error occurred during application start.\",\n\n \"details.title\": \"Error details\",\n \"details.inspect\": \"Inspect the console to see more details.\",\n \"details.errorMessage\": \"Error: {message}\"\n};\n\nexport const MESSAGES_BY_LOCALE: Record<\"en\" | \"de\", Record<string, string>> = {\n \"en\": MESSAGES_EN,\n \"de\": MESSAGES_DE\n};\n\nexport function ErrorScreen(props: { intl: PackageIntl; error: Error }) {\n const intl = props.intl;\n return (\n <VStack padding={4} width=\"100%\" height=\"100%\" minWidth=\"350px\" minHeight=\"150px\">\n <Heading>{intl.formatMessage({ id: \"title\" })}</Heading>\n <Alert.Root status=\"error\" size=\"lg\" maxWidth={550} borderRadius=\"4px\" mt={2}>\n <Alert.Indicator />\n <Alert.Content>\n <Alert.Title fontWeight=\"bold\">\n {intl.formatMessage({ id: \"alertTitle\" })}\n </Alert.Title>\n <Alert.Description>\n {intl.formatMessage({ id: \"alertDescription\" })}\n </Alert.Description>\n </Alert.Content>\n </Alert.Root>\n\n {import.meta.env.DEV && (\n <Box\n className=\"error-details\"\n mt={4}\n p={2}\n maxWidth=\"100%\"\n border={\"dotted 2px\"}\n borderColor={\"red.600\"}\n borderRadius={\"4px\"}\n >\n <Text color={\"red.600\"} fontWeight={\"bold\"}>\n {intl.formatMessage({ id: \"details.title\" }) + \":\"}\n </Text>\n <ErrorRenderer {...props} />\n </Box>\n )}\n </VStack>\n );\n}\n\n/**\n * Renders a single error instance.\n */\nfunction ErrorRenderer(props: { error: Error; intl: PackageIntl }) {\n const { error, intl } = props;\n const message = error?.message || \"Unknown\";\n const stackTrace = error?.stack;\n const stackTraceDisplay = stackTrace && (\n <>\n <Box\n p=\"2\"\n mt={1}\n mb={3}\n maxHeight=\"500px\"\n whiteSpace=\"pre\"\n wordBreak=\"keep-all\"\n overflow=\"auto\"\n border=\"1px solid grey\"\n borderRadius=\"4px\"\n color=\"gray.700\"\n fontSize=\"12px\"\n fontFamily=\"monospace\"\n >\n {stackTrace}\n </Box>\n {intl.formatMessage({ id: \"details.inspect\" })}\n </>\n );\n return (\n <Box p={2} className={\"error-screen-stack-trace\"}>\n <Text fontStyle={\"italic\"}>\n {intl.formatMessage({ id: \"details.errorMessage\" }, { message })}\n </Text>\n {stackTraceDisplay}\n </Box>\n );\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,WAAA,GAAc;AAAA,EAChB,OAAA,EAAS,gCAAA;AAAA,EACT,YAAA,EAAc,QAAA;AAAA,EACd,kBAAA,EAAoB,6DAAA;AAAA,EAEpB,eAAA,EAAiB,eAAA;AAAA,EACjB,iBAAA,EAAmB,iDAAA;AAAA,EACnB,sBAAA,EAAwB;AAC5B,CAAA;AAEA,MAAM,WAAA,GAAc;AAAA,EAChB,OAAA,EAAS,0BAAA;AAAA,EACT,YAAA,EAAc,OAAA;AAAA,EACd,kBAAA,EAAoB,2DAAA;AAAA,EAEpB,eAAA,EAAiB,eAAA;AAAA,EACjB,iBAAA,EAAmB,0CAAA;AAAA,EACnB,sBAAA,EAAwB;AAC5B,CAAA;AAEO,MAAM,kBAAA,GAAkE;AAAA,EAC3E,IAAA,EAAM,WAAA;AAAA,EACN,IAAA,EAAM;AACV;AAEO,SAAS,YAAY,KAAA,EAA4C;AACpE,EAAA,MAAM,OAAO,KAAA,CAAM,IAAA;AACnB,EAAA,uBACI,IAAA,CAAC,MAAA,EAAA,EAAO,OAAA,EAAS,CAAA,EAAG,KAAA,EAAM,MAAA,EAAO,MAAA,EAAO,MAAA,EAAO,QAAA,EAAS,OAAA,EAAQ,SAAA,EAAU,OAAA,EACtE,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,WAAS,QAAA,EAAA,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI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sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Alert, Box, Heading, Text, VStack } from \"@chakra-ui/react\";\nimport { PackageIntl } from \"../i18n\";\n\nconst MESSAGES_DE = {\n \"title\": \"Anwendungsstart fehlgeschlagen\",\n \"alertTitle\": \"Fehler\",\n \"alertDescription\": \"Leider ist beim Start der Anwendung ein Fehler aufgetreten.\",\n\n \"details.title\": \"Fehlerdetails\",\n \"details.inspect\": \"Konsole öffnen, um weitere Details zu sehen.\",\n \"details.errorMessage\": \"Fehler: {message}\"\n};\n\nconst MESSAGES_EN = {\n \"title\": \"Application start failed\",\n \"alertTitle\": \"Error\",\n \"alertDescription\": \"Unfortunately an error occurred during application start.\",\n\n \"details.title\": \"Error details\",\n \"details.inspect\": \"Inspect the console to see more details.\",\n \"details.errorMessage\": \"Error: {message}\"\n};\n\nexport const MESSAGES_BY_LOCALE: Record<\"en\" | \"de\", Record<string, string>> = {\n \"en\": MESSAGES_EN,\n \"de\": MESSAGES_DE\n};\n\nexport function ErrorScreen(props: { intl: PackageIntl; error: Error }) {\n const intl = props.intl;\n return (\n <VStack padding={4} width=\"100%\" height=\"100%\" minWidth=\"350px\" minHeight=\"150px\">\n <Heading>{intl.formatMessage({ id: \"title\" })}</Heading>\n <Alert.Root status=\"error\" size=\"lg\" maxWidth={550} borderRadius=\"4px\" mt={2}>\n <Alert.Indicator />\n <Alert.Content>\n <Alert.Title fontWeight=\"bold\">\n {intl.formatMessage({ id: \"alertTitle\" })}\n </Alert.Title>\n <Alert.Description>\n {intl.formatMessage({ id: \"alertDescription\" })}\n </Alert.Description>\n </Alert.Content>\n </Alert.Root>\n\n {import.meta.env.DEV && (\n <Box\n className=\"error-details\"\n mt={4}\n p={2}\n maxWidth=\"100%\"\n border={\"dotted 2px\"}\n borderColor={\"red.600\"}\n borderRadius={\"4px\"}\n >\n <Text color={\"red.600\"} fontWeight={\"bold\"}>\n {intl.formatMessage({ id: \"details.title\" }) + \":\"}\n </Text>\n <ErrorRenderer {...props} />\n </Box>\n )}\n </VStack>\n );\n}\n\n/**\n * Renders a single error instance.\n */\nfunction ErrorRenderer(props: { error: Error; intl: PackageIntl }) {\n const { error, intl } = props;\n const message = error?.message || \"Unknown\";\n const stackTrace = error?.stack;\n const stackTraceDisplay = stackTrace && (\n <>\n <Box\n p=\"2\"\n mt={1}\n mb={3}\n maxHeight=\"500px\"\n whiteSpace=\"pre\"\n wordBreak=\"keep-all\"\n overflow=\"auto\"\n border=\"1px solid grey\"\n borderRadius=\"4px\"\n color=\"gray.700\"\n fontSize=\"12px\"\n fontFamily=\"monospace\"\n >\n {stackTrace}\n </Box>\n {intl.formatMessage({ id: \"details.inspect\" })}\n </>\n );\n return (\n <Box p={2} className={\"error-screen-stack-trace\"}>\n <Text fontStyle={\"italic\"}>\n {intl.formatMessage({ id: \"details.errorMessage\" }, { message })}\n </Text>\n {stackTraceDisplay}\n </Box>\n );\n}\n"],"names":[],"mappings":";;;AAMA,MAAM,WAAA,GAAc;AAAA,EAChB,OAAA,EAAS,gCAAA;AAAA,EACT,YAAA,EAAc,QAAA;AAAA,EACd,kBAAA,EAAoB,6DAAA;AAAA,EAEpB,eAAA,EAAiB,eAAA;AAAA,EACjB,iBAAA,EAAmB,iDAAA;AAAA,EACnB,sBAAA,EAAwB;AAC5B,CAAA;AAEA,MAAM,WAAA,GAAc;AAAA,EAChB,OAAA,EAAS,0BAAA;AAAA,EACT,YAAA,EAAc,OAAA;AAAA,EACd,kBAAA,EAAoB,2DAAA;AAAA,EAEpB,eAAA,EAAiB,eAAA;AAAA,EACjB,iBAAA,EAAmB,0CAAA;AAAA,EACnB,sBAAA,EAAwB;AAC5B,CAAA;AAEO,MAAM,kBAAA,GAAkE;AAAA,EAC3E,IAAA,EAAM,WAAA;AAAA,EACN,IAAA,EAAM;AACV;AAEO,SAAS,YAAY,KAAA,EAA4C;AACpE,EAAA,MAAM,OAAO,KAAA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AAA;AAAA,oBAAA,GAAA,CAAC,IAAA,EAAA,EAAK,SAAA,EAAW,QAAA,EACZ,QAAA,EAAA,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,sBAAA,EAAuB,EAAG,EAAE,OAAA,EAAS,CAAA,EACnE,CAAA;AAAA,IACC;AAAA,GAAA,EACL,CAAA;AAER;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PackageContext.js","sources":["PackageContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createContext } from \"react\";\nimport type { PackageIntl } from \"../i18n\";\nimport type { Service } from \"../Service\";\nimport type { UseServiceOptions } from \"./hooks\";\n\nexport interface PackageContextMethods {\n getService: (packageName: string, interfaceName: string, options: UseServiceOptions) => Service;\n getServices: (packageName: string, interfaceName: string) => Service[];\n getProperties: (packageName: string) => Readonly<Record<string, unknown>>;\n\n /**\n * NOTE: Reactive for fine grained i18n changes (during dev for i18n HMR) and for live local changes (also in production).\n */\n getIntl(packageName: string): PackageIntl;\n}\n\nexport const PackageContext = createContext<PackageContextMethods | null>(null);\n"],"names":[],"mappings":";;AAkBO,MAAM,cAAA,GAAiB,cAA4C,IAAI;;;;"}
1
+ {"version":3,"file":"PackageContext.js","sources":["PackageContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from \"react\";\nimport type { PackageIntl } from \"../i18n\";\nimport type { Service } from \"../Service\";\nimport type { UseServiceOptions } from \"./hooks\";\n\nexport interface PackageContextMethods {\n getService: (packageName: string, interfaceName: string, options: UseServiceOptions) => Service;\n getServices: (packageName: string, interfaceName: string) => Service[];\n getProperties: (packageName: string) => Readonly<Record<string, unknown>>;\n\n /**\n * NOTE: Reactive for fine grained i18n changes (during dev for i18n HMR) and for live local changes (also in production).\n */\n getIntl(packageName: string): PackageIntl;\n}\n\nexport const PackageContext = createContext<PackageContextMethods | null>(null);\n"],"names":[],"mappings":";;AAmBO,MAAM,cAAA,GAAiB,cAA4C,IAAI;;;;"}
@@ -1,10 +1,10 @@
1
1
  import { SystemConfig } from "@chakra-ui/react";
2
2
  import { ReadonlyReactive } from "@conterra/reactivity-core";
3
3
  import { ReactNode } from "react";
4
+ import { ColorModeValue } from "../api";
4
5
  import { RootNode } from "../dom";
5
6
  import { PackageRepr } from "../service-layer/PackageRepr";
6
7
  import { ServiceLayer } from "../service-layer/ServiceLayer";
7
- import { ColorModeValue } from "../api";
8
8
  export interface ReactIntegrationOptions {
9
9
  rootNode: RootNode;
10
10
  hostNode: HTMLElement;
@@ -1 +1 @@
1
- {"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig, TooltipPropsProvider } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { ColorModeValue } from \"../api\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: ReadonlyReactive<string>;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n #rootNode: RootNode;\n #hostNode: HTMLElement;\n #appRoot: HTMLDivElement;\n #reactRoot: Root;\n #packageContext: PackageContextMethods;\n #locale: ReadonlyReactive<string>;\n #chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n #styles: ReadonlyReactive<string>;\n #colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.#rootNode = options.rootNode;\n this.#hostNode = options.hostNode;\n this.#appRoot = options.appRoot;\n this.#reactRoot = createRoot(options.appRoot);\n this.#chakraConfig = options.config;\n this.#packageContext = options.packageContext;\n this.#locale = options.locale;\n this.#styles = options.styles;\n this.#colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.#reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.#rootNode}\n hostNode={this.#hostNode}\n appRoot={this.#appRoot}\n config={this.#chakraConfig}\n locale={this.#locale}\n styles={this.#styles}\n colorMode={this.#colorMode}\n >\n {/*TooltipPropsProvider sets shorter `openDelay` for globally all Tooltips (500 ms instead of 1000 ms)*/}\n <TooltipPropsProvider value={{ openDelay: 500 }}>\n <PackageContext.Provider value={this.#packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </TooltipPropsProvider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.#reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl.value;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BO,MAAM,gBAAA,CAAiB;AAAA,EAC1B,SAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,aAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAEA,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YAAA,EAAc,QAAQ,CAAA;AAClE,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEA,OAAO,qBACH,OAAA,EACF;AACE,IAAA,MAAM,aAAa,MAAM;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,aAAA,EAAe,8CAA8C,CAAA;AAAA,IACzF,CAAA;AACA,IAAA,MAAM,cAAA,GAAwC;AAAA,MAC1C,OAAA,EAAS,UAAA;AAAA,MACT,aAAA,EAAe,UAAA;AAAA,MACf,UAAA,EAAY,UAAA;AAAA,MACZ,WAAA,EAAa;AAAA,KACjB;AACA,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAA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S,CAAC,WAAA,KAAgB;AACtB,MAAA,OAAO,UAAA,CAAW,WAAW,CAAA,CAAE,IAAA,CAAK,KAAA;AAAA,IACxC;AAAA,GACJ;AACA,EAAA,OAAO,cAAA;AACX;AAEA,SAAS,qBAAA,CAAsB,aAAqB,aAAA,EAAuB;AACvE,EAAA,OACI,CAAA,SAAA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
1
+ {"version":3,"file":"ReactIntegration.js","sources":["ReactIntegration.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SystemConfig, TooltipPropsProvider } from \"@chakra-ui/react\";\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ReactNode, StrictMode } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport { ColorModeValue } from \"../api\";\nimport { RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { InterfaceSpec, renderInterfaceSpec } from \"../service-layer/InterfaceSpec\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport { ServiceLayer } from \"../service-layer/ServiceLayer\";\nimport { renderAmbiguousServiceChoices } from \"../service-layer/ServiceLookup\";\nimport { CustomChakraProvider } from \"./ChakraProvider\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\n\nexport interface ReactIntegrationOptions {\n rootNode: RootNode;\n hostNode: HTMLElement;\n appRoot: HTMLDivElement;\n packages: Map<string, PackageRepr>;\n serviceLayer: ServiceLayer;\n\n locale: ReadonlyReactive<string>;\n config?: ReadonlyReactive<SystemConfig | undefined>;\n styles: ReadonlyReactive<string>;\n colorMode: ReadonlyReactive<ColorModeValue>;\n}\n\nexport class ReactIntegration {\n #rootNode: RootNode;\n #hostNode: HTMLElement;\n #appRoot: HTMLDivElement;\n #reactRoot: Root;\n #packageContext: PackageContextMethods;\n #locale: ReadonlyReactive<string>;\n #chakraConfig?: ReadonlyReactive<SystemConfig | undefined>;\n #styles: ReadonlyReactive<string>;\n #colorMode: ReadonlyReactive<ColorModeValue>;\n\n static createForApp(options: ReactIntegrationOptions): ReactIntegration {\n const { serviceLayer, packages } = options;\n const packageContext = createPackageContext(serviceLayer, packages);\n return new ReactIntegration({ ...options, packageContext });\n }\n\n static createForErrorScreen(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\">\n ) {\n const throwError = () => {\n throw new Error(ErrorId.INVALID_STATE, \"Hook cannot be used within the error screen.\");\n };\n const packageContext: PackageContextMethods = {\n getIntl: throwError,\n getProperties: throwError,\n getService: throwError,\n getServices: throwError\n };\n return new ReactIntegration({ ...options, packageContext });\n }\n\n private constructor(\n options: Omit<ReactIntegrationOptions, \"serviceLayer\" | \"packages\"> & {\n packageContext: PackageContextMethods;\n }\n ) {\n this.#rootNode = options.rootNode;\n this.#hostNode = options.hostNode;\n this.#appRoot = options.appRoot;\n this.#reactRoot = createRoot(options.appRoot);\n this.#chakraConfig = options.config;\n this.#packageContext = options.packageContext;\n this.#locale = options.locale;\n this.#styles = options.styles;\n this.#colorMode = options.colorMode;\n }\n\n render(contentNode: ReactNode) {\n this.#reactRoot.render(\n <StrictMode>\n <CustomChakraProvider\n rootNode={this.#rootNode}\n hostNode={this.#hostNode}\n appRoot={this.#appRoot}\n config={this.#chakraConfig}\n locale={this.#locale}\n styles={this.#styles}\n colorMode={this.#colorMode}\n >\n {/*TooltipPropsProvider sets shorter `openDelay` for globally all Tooltips (500 ms instead of 1000 ms)*/}\n <TooltipPropsProvider value={{ openDelay: 500 }}>\n <PackageContext.Provider value={this.#packageContext}>\n {contentNode}\n </PackageContext.Provider>\n </TooltipPropsProvider>\n </CustomChakraProvider>\n </StrictMode>\n );\n }\n\n destroy() {\n this.#reactRoot.unmount();\n }\n}\n\nexport function EmptyComponent(): ReactNode {\n return null;\n}\n\nfunction createPackageContext(\n serviceLayer: ServiceLayer,\n packages: Map<string, PackageRepr>\n): PackageContextMethods {\n const getPackage = (packageName: string): PackageRepr => {\n const pkg = packages.get(packageName);\n if (!pkg) {\n throw new Error(\n ErrorId.INTERNAL,\n `Package '${packageName}' was not found in application.`\n );\n }\n return pkg;\n };\n\n const packageContext: PackageContextMethods = {\n getService: (packageName, interfaceName, options) => {\n const spec: InterfaceSpec = { interfaceName, ...options };\n const result = serviceLayer.getService(packageName, spec);\n if (result.type === \"found\") {\n return result.value.getInstanceOrThrow();\n }\n\n const renderedSpec = renderInterfaceSpec(spec);\n switch (result.type) {\n case \"unimplemented\":\n throw new Error(\n ErrorId.INTERFACE_NOT_FOUND,\n `The UI of package '${packageName}' requested the unimplemented interface ${renderedSpec}.`\n );\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on interface ${renderedSpec}.` +\n ` Add the dependency to the package configuration or remove the usage.`\n );\n case \"ambiguous\": {\n const renderedChoices = renderAmbiguousServiceChoices(result.choices);\n throw new Error(\n ErrorId.AMBIGUOUS_DEPENDENCY,\n `The UI of package '${packageName}' requires the ambiguous interface ${renderedSpec}.` +\n ` Possible choices are: ${renderedChoices}.`\n );\n }\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getServices: (packageName, interfaceName) => {\n const result = serviceLayer.getServices(packageName, interfaceName);\n if (result.type === \"found\") {\n return result.value.map((serviceRepr) => serviceRepr.getInstanceOrThrow());\n }\n\n switch (result.type) {\n case \"undeclared\":\n throw new Error(\n ErrorId.UNDECLARED_DEPENDENCY,\n `Package '${packageName}' did not declare an UI dependency on all services implementing interface '${interfaceName}'.` +\n ` Add the dependency (\"all\": true) to the package configuration or remove the usage.`\n );\n case \"unknown-package\":\n throw new Error(\n ErrorId.MISSING_PACKAGE,\n missingPackageMessage(packageName, interfaceName)\n );\n }\n },\n getProperties: (packageName) => {\n return getPackage(packageName).properties;\n },\n getIntl: (packageName) => {\n return getPackage(packageName).intl.value;\n }\n };\n return packageContext;\n}\n\nfunction missingPackageMessage(packageName: string, interfaceName: string) {\n return (\n `Package '${packageName}' was not found in the application's metadata while it attempted to reference the interface '${interfaceName}'. ` +\n `Check that the dependency is declared correctly in the packages that use '${packageName}'.`\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA+BO,MAAM,gBAAA,CAAiB;AAAA,EAC1B,SAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,aAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EAEA,OAAO,aAAa,OAAA,EAAoD;AACpE,IAAA,MAAM,EAAE,YAAA,EAAc,QAAA,EAAS,GAAI,OAAA;AACnC,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,YAAA,EAAc,QAAQ,CAAA;AAClE,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEA,OAAO,qBACH,OAAA,EACF;AACE,IAAA,MAAM,aAAa,MAAM;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,aAAA,EAAe,8CAA8C,CAAA;AAAA,IACzF,CAAA;AACA,IAAA,MAAM,cAAA,GAAwC;AAAA,MAC1C,OAAA,EAAS,UAAA;AAAA,MACT,aAAA,EAAe,UAAA;AAAA,MACf,UAAA,EAAY,UAAA;AAAA,MACZ,WAAA,EAAa;AAAA,KACjB;AACA,IAAA,OAAO,IAAI,gBAAA,CAAiB,EAAE,GAAG,OAAA,EAAS,gBAAgB,CAAA;AAAA,EAC9D;AAAA,EAEQ,YACJ,OAAA,EAGF;AACE,IAAA,IAAA,CAAK,YAAY,OAAA,CAAQ,QAAA;AACzB,IAAA,IAAA,CAAK,YAAY,OAAA,CAAQ,QA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AA,CAAsB,aAAqB,aAAA,EAAuB;AACvE,EAAA,OACI,CAAA,SAAA,EAAY,WAAW,CAAA,6FAAA,EAAgG,aAAa,gFACvD,WAAW,CAAA,EAAA,CAAA;AAEhG;;;;"}
@@ -1,8 +1,8 @@
1
1
  import { Error } from '@open-pioneer/core';
2
+ import { useReactiveSnapshot } from '@open-pioneer/reactivity';
2
3
  import { useContext, useMemo } from 'react';
3
4
  import { ErrorId } from '../errors.js';
4
5
  import { PackageContext } from './PackageContext.js';
5
- import { useReactiveSnapshot } from '@open-pioneer/reactivity';
6
6
 
7
7
  function useServiceInternal(packageName, interfaceName, options) {
8
8
  const context = useContext(PackageContext);
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Error } from \"@open-pioneer/core\";\nimport { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n const contextData = checkContext(\"useIntl\", context);\n const intl = useReactiveSnapshot(\n () => contextData.getIntl(packageName),\n [packageName, contextData]\n );\n return intl;\n}\n\nfunction checkContext(\n hookName: string,\n contextData: PackageContextMethods | null\n): PackageContextMethods {\n if (!contextData) {\n throw new Error(\n ErrorId.INTERNAL,\n `\"Failed to access package context from '${hookName}': react integration was not set up properly.`\n );\n }\n return contextData;\n}\n"],"names":[],"mappings":";;;;;;AAgDO,SAAS,kBAAA,CACZ,WAAA,EAEA,aAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,OAAA,GAAU,OAAA;AAAA,IACZ,MACI,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA,CAAE,UAAA;AAAA,MAChC,WAAA;AAAA,MACA,aAAA;AAAA,MACA,WAAW;AAAC,KAChB;AAAA,IACJ,CAAC,OAAA,EAAS,WAAA,EAAa,aAAA,EAAe,OAAO;AAAA,GACjD;AACA,EAAA,OAAO,OAAA;AACX;AAiBO,SAAS,mBAAA,CAAoB,aAAqB,aAAA,EAA+B;AACpF,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,OAAA;AAAA,IACb,MAAM,YAAA,CAAa,aAAA,EAAe,OAAO,CAAA,CAAE,WAAA,CAAY,aAAa,aAAa,CAAA;AAAA,IACjF,CAAC,OAAA,EAAS,WAAA,EAAa,aAAa;AAAA,GACxC;AACA,EAAA,OAAO,QAAA;AACX;AAUO,SAAS,sBAAsB,WAAA,EAAwD;AAC1F,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,OAAO,YAAA,CAAa,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,WAAW,CAAA;AAC3E;AAUO,SAAS,gBAAgB,WAAA,EAAkC;AAC9D,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,YAAA,CAAa,SAAA,EAAW,OAAO,CAAA;AACnD,EAAA,MAAM,IAAA,GAAO,mBAAA;AAAA,IACT,MAAM,WAAA,CAAY,OAAA,CAAQ,WAAW,CAAA;AAAA,IACrC,CAAC,aAAa,WAAW;AAAA,GAC7B;AACA,EAAA,OAAO,IAAA;AACX;AAEA,SAAS,YAAA,CACL,UACA,WAAA,EACqB;AACrB,EAAA,IAAI,CAAC,WAAA,EAAa;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,QAAA;AAAA,MACR,2CAA2C,QAAQ,CAAA,6CAAA;AAAA,KACvD;AAAA,EACJ;AACA,EAAA,OAAO,WAAA;AACX;;;;"}
1
+ {"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Error } from \"@open-pioneer/core\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { useContext, useMemo } from \"react\";\nimport { InterfaceNameForServiceType } from \"../DeclaredService\";\nimport { ErrorId } from \"../errors\";\nimport { PackageIntl } from \"../i18n\";\nimport { PackageContext, PackageContextMethods } from \"./PackageContext\";\n\n/*\n\n IMPORTANT\n =========\n\n The functions in this file are part of the public API, although they should not be called directly.\n They are imported by code generated during separate package compilation generation via:\n\n import { hookName } from '@open-pioneer/runtime/react-integration'\n\n They are also imported by the vite plugin during development and when building an application.\n\n The matching exports are in the neighboring `index.ts`.\n The interfaces of these hooks must remain stable so that already published packages can continue to work in the future.\n\n See also the implementation of @open-pioneer/build-package.\n\n*/\n\nexport interface UseServiceOptions {\n /** An additional qualifier to disambiguate service instances that implement the same interface. */\n qualifier?: string;\n}\n\n/**\n * Returns a service that implements the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServiceInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType;\nexport function useServiceInternal(\n packageName: string,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n interfaceName: any,\n options?: UseServiceOptions\n): unknown {\n const context = useContext(PackageContext);\n const service = useMemo(\n () =>\n checkContext(\"useService\", context).getService(\n packageName,\n interfaceName,\n options ?? {}\n ),\n [context, packageName, interfaceName, options]\n );\n return service;\n}\n\n/**\n * Returns all services that implement the given interface.\n * Receives the package name of the importing package as a string.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useServicesInternal<ServiceType = unknown>(\n packageName: string,\n interfaceName: InterfaceNameForServiceType<ServiceType>,\n options?: UseServiceOptions\n): ServiceType[];\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useServicesInternal(packageName: string, interfaceName: any): unknown[] {\n const context = useContext(PackageContext);\n const services = useMemo(\n () => checkContext(\"useServices\", context).getServices(packageName, interfaceName),\n [context, packageName, interfaceName]\n );\n return services;\n}\n\n/**\n * Returns the properties for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>> {\n const context = useContext(PackageContext);\n return checkContext(\"useProperties\", context).getProperties(packageName);\n}\n\n/**\n * Returns the i18n object for the given package.\n *\n * This is an internal hook that is typically called indirectly via the hook\n * provided from `\"open-pioneer:react-hooks\"`.\n *\n * @private\n */\nexport function useIntlInternal(packageName: string): PackageIntl {\n const context = useContext(PackageContext);\n const contextData = checkContext(\"useIntl\", context);\n const intl = useReactiveSnapshot(\n () => contextData.getIntl(packageName),\n [packageName, contextData]\n );\n return intl;\n}\n\nfunction checkContext(\n hookName: string,\n contextData: PackageContextMethods | null\n): PackageContextMethods {\n if (!contextData) {\n throw new Error(\n ErrorId.INTERNAL,\n `\"Failed to access package context from '${hookName}': react integration was not set up properly.`\n );\n }\n return contextData;\n}\n"],"names":[],"mappings":";;;;;;AAiDO,SAAS,kBAAA,CACZ,WAAA,EAEA,aAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,OAAA,GAAU,WAAW,cAA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CAAA;AAAA,KACvD;AAAA,EACJ;AACA,EAAA,OAAO,WAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"InterfaceSpec.js","sources":["InterfaceSpec.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 { ErrorId } from \"../errors\";\nimport { InterfaceReferenceMetadata } from \"../metadata\";\n\n/**\n * Describes the implementation of an interface.\n */\nexport interface InterfaceSpec {\n interfaceName: string;\n qualifier?: string | undefined;\n}\n\nexport function renderInterfaceSpec({ interfaceName, qualifier }: InterfaceSpec): string {\n return `'${interfaceName}'` + (qualifier ? ` (qualifier: '${qualifier}')` : \"\");\n}\n\nexport interface SingleImplementationSpec extends InterfaceSpec {\n all?: undefined;\n}\n\nexport interface AllImplementationsSpec extends Pick<InterfaceSpec, \"interfaceName\"> {\n all: true;\n}\n\n/**\n * Describes a reference to one or more implementations of an interface.\n */\nexport type ReferenceSpec = SingleImplementationSpec | AllImplementationsSpec;\n\nexport function parseReferenceSpec(metadata: InterfaceReferenceMetadata): ReferenceSpec {\n if (!metadata) {\n throw new Error(ErrorId.INVALID_METADATA, \"Missing reference metadata.\");\n }\n if (metadata.all && metadata.qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"References can't use 'qualifier' and 'all' properties at the same time.\"\n );\n }\n if (metadata.all) {\n return {\n all: true,\n interfaceName: metadata.name\n };\n }\n return {\n interfaceName: metadata.name,\n qualifier: metadata.qualifier\n };\n}\n\nexport function isSingleImplementationSpec(spec: ReferenceSpec): spec is SingleImplementationSpec {\n return !spec.all;\n}\n\nexport function isAllImplementationsSpec(spec: ReferenceSpec): spec is AllImplementationsSpec {\n return spec.all === true;\n}\n"],"names":[],"mappings":";;;AAcO,SAAS,mBAAA,CAAoB,EAAE,aAAA,EAAe,SAAA,EAAU,EAA0B;AACrF,EAAA,OAAO,IAAI,aAAa,CAAA,CAAA,CAAA,IAAO,SAAA,GAAY,CAAA,cAAA,EAAiB,SAAS,CAAA,EAAA,CAAA,GAAO,EAAA,CAAA;AAChF;AAeO,SAAS,mBAAmB,QAAA,EAAqD;AACpF,EAAA,IAAI,CAAC,QAAA,EAAU;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,gBAAA,EAAkB,6BAA6B,CAAA;AAAA,EAC3E;AACA,EAAA,IAAI,QAAA,CAAS,GAAA,IAAO,QAAA,CAAS,SAAA,EAAW;AACpC,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,gBAAA;AAAA,MACR;AAAA,KACJ;AAAA,EACJ;AACA,EAAA,IAAI,SAAS,GAAA,EAAK;AACd,IAAA,OAAO;AAAA,MACH,GAAA,EAAK,IAAA;AAAA,MACL,eAAe,QAAA,CAAS;AAAA,KAC5B;AAAA,EACJ;AACA,EAAA,OAAO;AAAA,IACH,eAAe,QAAA,CAAS,IAAA;AAAA,IACxB,WAAW,QAAA,CAAS;AAAA,GACxB;AACJ;AAEO,SAAS,2BAA2B,IAAA,EAAuD;AAC9F,EAAA,OAAO,CAAC,IAAA,CAAK,GAAA;AACjB;AAEO,SAAS,yBAAyB,IAAA,EAAqD;AAC1F,EAAA,OAAO,KAAK,GAAA,KAAQ,IAAA;AACxB;;;;"}
1
+ {"version":3,"file":"InterfaceSpec.js","sources":["InterfaceSpec.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 { ErrorId } from \"../errors\";\nimport { InterfaceReferenceMetadata } from \"../metadata\";\n\n/**\n * Describes the implementation of an interface.\n */\nexport interface InterfaceSpec {\n interfaceName: string;\n qualifier?: string | undefined;\n}\n\nexport function renderInterfaceSpec({ interfaceName, qualifier }: InterfaceSpec): string {\n return `'${interfaceName}'` + (qualifier ? ` (qualifier: '${qualifier}')` : \"\");\n}\n\nexport interface SingleImplementationSpec extends InterfaceSpec {\n all?: undefined;\n}\n\nexport interface AllImplementationsSpec extends Pick<InterfaceSpec, \"interfaceName\"> {\n all: true;\n}\n\n/**\n * Describes a reference to one or more implementations of an interface.\n */\nexport type ReferenceSpec = SingleImplementationSpec | AllImplementationsSpec;\n\nexport function parseReferenceSpec(metadata: InterfaceReferenceMetadata): ReferenceSpec {\n if (!metadata) {\n throw new Error(ErrorId.INVALID_METADATA, \"Missing reference metadata.\");\n }\n if (metadata.all && metadata.qualifier) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"References can't use 'qualifier' and 'all' properties at the same time.\"\n );\n }\n if (metadata.all) {\n return {\n all: true,\n interfaceName: metadata.name\n };\n }\n return {\n interfaceName: metadata.name,\n qualifier: metadata.qualifier\n };\n}\n\nexport function isSingleImplementationSpec(spec: ReferenceSpec): spec is SingleImplementationSpec {\n return !spec.all;\n}\n\nexport function isAllImplementationsSpec(spec: ReferenceSpec): spec is AllImplementationsSpec {\n return spec.all === true;\n}\n"],"names":[],"mappings":";;;AAeO,SAAS,mBAAA,CAAoB,EAAE,aAAA,EAAe,SAAA,EAAU,EAA0B;AACrF,EAAA,OAAO,IAAI,aAAa,CAAA,CAAA,CAAA,IAAO,SAAA,GAAY,CAAA,cAAA,EAAiB,SAAS,CAAA,EAAA,CAAA,GAAO,EAAA,CAAA;AAChF;AAeO,SAAS,mBAAmB,QAAA,EAAqD;AACpF,EAAA,IAAI,CAAC,QAAA,EAAU;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,gBAAA,EAAkB,6BAA6B,CAAA;AAAA,EAC3E;AACA,EAAA,IAAI,QAAA,CAAS,GAAA,IAAO,QAAA,CAAS,SAAA,EAAW;AACpC,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,OAAA,CAAQ,gBAAA;AAAA,MACR;AAAA,KACJ;AAAA,EACJ;AACA,EAAA,IAAI,SAAS,GAAA,EAAK;AACd,IAAA,OAAO;AAAA,MACH,GAAA,EAAK,IAAA;AAAA,MACL,eAAe,QAAA,CAAS;AAAA,KAC5B;AAAA,EACJ;AACA,EAAA,OAAO;AAAA,IACH,eAAe,QAAA,CAAS,IAAA;AAAA,IACxB,WAAW,QAAA,CAAS;AAAA,GACxB;AACJ;AAEO,SAAS,2BAA2B,IAAA,EAAuD;AAC9F,EAAA,OAAO,CAAC,IAAA,CAAK,GAAA;AACjB;AAEO,SAAS,yBAAyB,IAAA,EAAqD;AAC1F,EAAA,OAAO,KAAK,GAAA,KAAQ,IAAA;AACxB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PackageRepr.js","sources":["PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ApplicationProperties } from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, PackageIntl } from \"../i18n\";\nimport { PackageMetadata, PropertyMetadata } from \"../metadata\";\nimport { parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface PackageReprOptions {\n name: string;\n intl: ReadonlyReactive<PackageIntl>;\n services?: ServiceRepr[];\n uiReferences?: ReferenceSpec[];\n properties?: Record<string, unknown>;\n}\n\nexport class PackageRepr {\n static create(\n data: PackageMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n customProperties?: Record<string, unknown>\n ): PackageRepr {\n const name = data.name;\n const properties = data.properties ?? {};\n const finalProperties = customizeProperties(name, properties, customProperties);\n const services = Object.entries(data.services ?? {}).map<ServiceRepr>(\n ([name, serviceData]) => {\n if (name !== serviceData.name) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"Invalid metadata: service name mismatch.\"\n );\n }\n return ServiceRepr.create(data.name, serviceData, intl, finalProperties);\n }\n );\n const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];\n return new PackageRepr({\n name,\n services,\n uiReferences,\n properties: finalProperties,\n intl: intl\n });\n }\n\n /** Package name */\n readonly name: string;\n\n /** Services defined by the package */\n readonly services: readonly ServiceRepr[];\n\n /** Interfaces required by UI components. */\n readonly uiReferences: readonly Readonly<ReferenceSpec>[];\n\n /** Resolved (perhaps customized) package properties. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n constructor(options: PackageReprOptions) {\n const name = options.name;\n if (!isValidPackageName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid package name: '${name}'.`);\n }\n\n this.name = name;\n this.services = options.services ?? [];\n this.uiReferences = options.uiReferences ?? [];\n this.properties = options.properties ?? {};\n this.intl = options.intl;\n }\n}\n\nexport function createPackages(\n packages: Record<string, PackageMetadata>,\n i18n: AppIntl,\n customProperties?: ApplicationProperties\n) {\n return Object.entries(packages).map<PackageRepr>(([name, packageMetadata]) => {\n if (name !== packageMetadata.name) {\n throw new Error(ErrorId.INVALID_METADATA, \"Invalid metadata: package name mismatch.\");\n }\n\n const packageI18n = i18n.createPackageI18n(name);\n return PackageRepr.create(packageMetadata, packageI18n, customProperties?.[name]);\n });\n}\n\n/**\n * Merges the declared properties of the package with the application-defined\n * custom properties.\n */\nfunction customizeProperties(\n packageName: string,\n properties: Record<string, PropertyMetadata>,\n customProperties: Record<string, unknown> = {}\n) {\n const merged: Record<string, unknown> = {};\n const required: string[] = [];\n for (const [key, propertyMetadata] of Object.entries(properties)) {\n merged[key] = propertyMetadata.value;\n if (propertyMetadata.required) {\n required.push(key);\n }\n }\n\n for (const [key, value] of Object.entries(customProperties)) {\n if (!hasProperty(merged, key)) {\n throw new Error(\n ErrorId.INVALID_PROPERTY_NAME,\n `Unexpected property name '${key}' for package '${packageName}': the property does not exist.`\n );\n }\n merged[key] = value;\n }\n\n for (const key of required) {\n const value = merged[key];\n if (value == null) {\n throw new Error(\n ErrorId.REQUIRED_PROPERTY,\n `Package '${packageName}' requires the property '${key}' to be initialized to a non-null value.`\n );\n }\n }\n\n return merged;\n}\n\nconst HAS_PROP = Object.prototype.hasOwnProperty;\n\nfunction hasProperty(object: unknown, key: string) {\n return HAS_PROP.call(object, key);\n}\n\n// http://json.schemastore.org/package\nconst NAME_REGEX = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/;\n\nfunction isValidPackageName(name: string): boolean {\n return NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;AAmBO,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,IAAA,EACA,IAAA,EACA,gBAAA,EACW;AACX,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAClB,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,UAAA,IAAc,EAAC;AACvC,IAAA,MAAM,eAAA,GAAkB,mBAAA,CAAoB,IAAA,EAAM,UAAA,EAAY,gBAAgB,CAAA;AAC9E,IAAA,MAAM,WAAW,MAAA,CAAO,OAAA,CAAQ,KAAK,QAAA,IAAY,EAAE,CAAA,CAAE,GAAA;AAAA,MACjD,CAAC,CAACA,KAAAA,EAAM,WAAW,CAAA,KAAM;AACrB,QAAA,IAAIA,KAAAA,KAAS,YAAY,IAAA,EAAM;AAC3B,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,gBAAA;AAAA,YACR;AAAA,WACJ;AAAA,QACJ;AACA,QAAA,OAAO,YAAY,MAAA,CAAO,IAAA,CAAK,IAAA,EAAM,WAAA,EAAa,MAAM,eAAe,CAAA;AAAA,MAC3E;AAAA,KACJ;AACA,IAAA,MAAM,YAAA,GAAe,IAAA,CAAK,EAAA,EAAI,UAAA,EAAY,GAAA,CAAI,CAAC,GAAA,KAAQ,kBAAA,CAAmB,GAAG,CAAC,CAAA,IAAK,EAAC;AAC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,MAAM,QAAA,GAAW,OAAO,SAAA,CAAU,cAAA;AAElC,SAAS,WAAA,CAAY,QAAiB,GAAA,EAAa;AAC/C,EAAA,OAAO,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA;AACpC;AAGA,MAAM,UAAA,GAAa,4DAAA;AAEnB,SAAS,mBAAmB,IAAA,EAAuB;AAC/C,EAAA,OAAO,UAAA,CAAW,KAAK,IAAI,CAAA;AAC/B;;;;"}
1
+ {"version":3,"file":"PackageRepr.js","sources":["PackageRepr.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { Error } from \"@open-pioneer/core\";\nimport { ApplicationProperties } from \"../CustomElement\";\nimport { ErrorId } from \"../errors\";\nimport { AppIntl, PackageIntl } from \"../i18n\";\nimport { PackageMetadata, PropertyMetadata } from \"../metadata\";\nimport { parseReferenceSpec, ReferenceSpec } from \"./InterfaceSpec\";\nimport { ServiceRepr } from \"./ServiceRepr\";\n\nexport interface PackageReprOptions {\n name: string;\n intl: ReadonlyReactive<PackageIntl>;\n services?: ServiceRepr[];\n uiReferences?: ReferenceSpec[];\n properties?: Record<string, unknown>;\n}\n\nexport class PackageRepr {\n static create(\n data: PackageMetadata,\n intl: ReadonlyReactive<PackageIntl>,\n customProperties?: Record<string, unknown>\n ): PackageRepr {\n const name = data.name;\n const properties = data.properties ?? {};\n const finalProperties = customizeProperties(name, properties, customProperties);\n const services = Object.entries(data.services ?? {}).map<ServiceRepr>(\n ([name, serviceData]) => {\n if (name !== serviceData.name) {\n throw new Error(\n ErrorId.INVALID_METADATA,\n \"Invalid metadata: service name mismatch.\"\n );\n }\n return ServiceRepr.create(data.name, serviceData, intl, finalProperties);\n }\n );\n const uiReferences = data.ui?.references?.map((ref) => parseReferenceSpec(ref)) ?? [];\n return new PackageRepr({\n name,\n services,\n uiReferences,\n properties: finalProperties,\n intl: intl\n });\n }\n\n /** Package name */\n readonly name: string;\n\n /** Services defined by the package */\n readonly services: readonly ServiceRepr[];\n\n /** Interfaces required by UI components. */\n readonly uiReferences: readonly Readonly<ReferenceSpec>[];\n\n /** Resolved (perhaps customized) package properties. */\n readonly properties: Readonly<Record<string, unknown>>;\n\n /** Locale-dependant i18n messages. */\n readonly intl: ReadonlyReactive<PackageIntl>;\n\n constructor(options: PackageReprOptions) {\n const name = options.name;\n if (!isValidPackageName(name)) {\n throw new Error(ErrorId.INTERNAL, `Invalid package name: '${name}'.`);\n }\n\n this.name = name;\n this.services = options.services ?? [];\n this.uiReferences = options.uiReferences ?? [];\n this.properties = options.properties ?? {};\n this.intl = options.intl;\n }\n}\n\nexport function createPackages(\n packages: Record<string, PackageMetadata>,\n i18n: AppIntl,\n customProperties?: ApplicationProperties\n) {\n return Object.entries(packages).map<PackageRepr>(([name, packageMetadata]) => {\n if (name !== packageMetadata.name) {\n throw new Error(ErrorId.INVALID_METADATA, \"Invalid metadata: package name mismatch.\");\n }\n\n const packageI18n = i18n.createPackageI18n(name);\n return PackageRepr.create(packageMetadata, packageI18n, customProperties?.[name]);\n });\n}\n\n/**\n * Merges the declared properties of the package with the application-defined\n * custom properties.\n */\nfunction customizeProperties(\n packageName: string,\n properties: Record<string, PropertyMetadata>,\n customProperties: Record<string, unknown> = {}\n) {\n const merged: Record<string, unknown> = {};\n const required: string[] = [];\n for (const [key, propertyMetadata] of Object.entries(properties)) {\n merged[key] = propertyMetadata.value;\n if (propertyMetadata.required) {\n required.push(key);\n }\n }\n\n for (const [key, value] of Object.entries(customProperties)) {\n if (!hasProperty(merged, key)) {\n throw new Error(\n ErrorId.INVALID_PROPERTY_NAME,\n `Unexpected property name '${key}' for package '${packageName}': the property does not exist.`\n );\n }\n merged[key] = value;\n }\n\n for (const key of required) {\n const value = merged[key];\n if (value == null) {\n throw new Error(\n ErrorId.REQUIRED_PROPERTY,\n `Package '${packageName}' requires the property '${key}' to be initialized to a non-null value.`\n );\n }\n }\n\n return merged;\n}\n\nconst HAS_PROP = Object.prototype.hasOwnProperty;\n\nfunction hasProperty(object: unknown, key: string) {\n return HAS_PROP.call(object, key);\n}\n\n// http://json.schemastore.org/package\nconst NAME_REGEX = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/;\n\nfunction isValidPackageName(name: string): boolean {\n return NAME_REGEX.test(name);\n}\n"],"names":["name"],"mappings":";;;;;AAoBO,MAAM,WAAA,CAAY;AAAA,EACrB,OAAO,MAAA,CACH,IAAA,EACA,IAAA,EACA,gBAAA,EACW;AACX,IAAA,MAAM,OAAO,IAAA,CAAK,IAAA;AAClB,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,UAAA,IAAc,EAAC;AACvC,IAAA,MAAM,eAAA,GAAkB,mBAAA,CAAoB,IAAA,EAAM,UAAA,EAAY,gBAAgB,CAAA;AAC9E,IAAA,MAAM,WAAW,MAAA,CAAO,OAAA,CAAQ,KAAK,QAAA,IAAY,EAAE,CAAA,CAAE,GAAA;AAAA,MACjD,CAAC,CAACA,KAAAA,EAAM,WAAW,CAAA,KAAM;AACrB,QAAA,IAAIA,KAAAA,KAAS,YAAY,IAAA,EAAM;AAC3B,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,OAAA,CAAQ,gBAAA;AAAA,YACR;AAAA,WACJ;AAAA,QACJ;AACA,QAAA,OAAO,YAAY,MAAA,CAAO,IAAA,CAAK,IAAA,EAAM,WAAA,EAAa,MAAM,eAAe,CAAA;AAAA,MAC3E;AAAA,KACJ;AACA,IAAA,MAAM,YAAA,GAAe,IAAA,CAAK,EAAA,EAAI,UAAA,EAAY,GAAA,CAAI,CAAC,GAAA,KAAQ,kBAAA,CAAmB,GAAG,CAAC,CAAA,IAAK,EAAC;AACpF,IAAA,OAAO,IAAI,WAAA,CAAY;AAAA,MACnB,IAAA;AAAA,MACA,QAAA;AAAA,MACA,YAAA;AAAA,MAC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