@open-pioneer/runtime 4.9.0-dev.20260930055642 → 4.9.0-dev.20261029090037
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -2
- package/CustomElement.d.ts +5 -5
- package/CustomElement.js +1 -3
- package/CustomElement.js.map +1 -1
- package/README.md +14 -6
- package/Service.d.ts +2 -2
- package/Service.js.map +1 -1
- package/_virtual/source-info.js +7 -5
- package/_virtual/source-info.js.map +1 -1
- package/api.d.ts +7 -8
- package/app/AppInstance.js +10 -6
- package/app/AppInstance.js.map +1 -1
- package/app/gatherConfig.d.ts +13 -4
- package/app/gatherConfig.js +23 -12
- package/app/gatherConfig.js.map +1 -1
- package/app/logErrors.js +1 -1
- package/builtin-services/ApplicationContextImpl.js +7 -1
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/builtin-services/{ApplicationLifecycleEventService.d.ts → ApplicationLifecycleEventServiceImpl.d.ts} +1 -1
- package/builtin-services/{ApplicationLifecycleEventService.js → ApplicationLifecycleEventServiceImpl.js} +4 -4
- package/builtin-services/ApplicationLifecycleEventServiceImpl.js.map +1 -0
- package/builtin-services/NumberParserServiceImpl.d.ts +1 -1
- package/builtin-services/NumberParserServiceImpl.js +3 -3
- package/builtin-services/NumberParserServiceImpl.js.map +1 -1
- package/builtin-services/index.js +2 -2
- package/builtin-services/index.js.map +1 -1
- package/dom/index.d.ts +0 -1
- package/dom/index.js +1 -1
- package/dom/index.js.map +1 -1
- package/i18n/AppIntl.d.ts +1 -1
- package/i18n/AppIntl.js +5 -10
- package/i18n/AppIntl.js.map +1 -1
- package/i18n/PackageIntl.js +2 -5
- package/i18n/PackageIntl.js.map +1 -1
- package/metadata/ObservableBox.d.ts +1 -1
- package/metadata/ObservableBox.js.map +1 -1
- package/package.json +8 -8
- package/react-integration/PackageContext.d.ts +1 -1
- package/react-integration/PackageContext.js.map +1 -1
- package/react-integration/hooks.d.ts +4 -4
- package/react-integration/hooks.js +6 -7
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/PackageRepr.d.ts +1 -1
- package/service-layer/PackageRepr.js +1 -1
- package/service-layer/PackageRepr.js.map +1 -1
- package/service-layer/ServiceLayer.d.ts +3 -2
- package/service-layer/ServiceLayer.js +4 -3
- package/service-layer/ServiceLayer.js.map +1 -1
- package/service-layer/ServiceLookup.d.ts +4 -3
- package/service-layer/ServiceLookup.js +3 -3
- package/service-layer/ServiceLookup.js.map +1 -1
- package/service-layer/ServiceRepr.d.ts +2 -2
- package/service-layer/ServiceRepr.js +7 -5
- package/service-layer/ServiceRepr.js.map +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger, deprecated, Error, isAbortError } from '@open-pioneer/core';
|
|
2
|
-
import { sourceId$
|
|
2
|
+
import { sourceId$2 as sourceId } from '../_virtual/source-info.js';
|
|
3
3
|
import { isShadowRoot } from '../dom/index.js';
|
|
4
4
|
import { ErrorId } from '../errors.js';
|
|
5
5
|
import '../i18n/AppIntl.js';
|
|
@@ -59,6 +59,12 @@ class ApplicationContextImpl {
|
|
|
59
59
|
setLocale(locale) {
|
|
60
60
|
setLocaleDeprecationMessage();
|
|
61
61
|
const targetLocale = tryParseLocale(locale);
|
|
62
|
+
if (locale != null && !targetLocale) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
ErrorId.UNSUPPORTED_LOCALE,
|
|
65
|
+
`Unsupported locale '${locale}': not a valid BCP 47 language tag.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
62
68
|
if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {
|
|
63
69
|
const localesList = this.#localeService.supportedMessageLocales.map((l) => l.baseName).join(", ");
|
|
64
70
|
throw new Error(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error, deprecated, isAbortError } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationContext, LocaleService } from \"../api\";\nimport { isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { tryParseLocale } from \"../i18n\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n rootNode: RootNode;\n container: HTMLElement;\n}\n\ninterface ServiceReferences {\n localeService: LocaleService;\n}\n\nexport type ApplicationContextServiceOptions = ServiceOptions<ServiceReferences>;\n\nconst setLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.setLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.changeLocale` instead.\"\n});\nconst getLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.getLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.locale` instead.\"\n});\nconst getSupportedLocalesDeprecationMessage = deprecated({\n name: \"ApplicationContext.getSupportedLocales\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.supportedMessageLocales` instead.\"\n});\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #rootNode: RootNode;\n #container: HTMLElement;\n #localeService: LocaleService;\n\n constructor(\n options: ApplicationContextServiceOptions,\n properties: ApplicationContextProperties\n ) {\n this.#host = properties.host;\n this.#rootNode = properties.rootNode;\n this.#container = properties.container;\n this.#localeService = options.references.localeService;\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getRoot(): RootNode {\n return this.#rootNode;\n }\n\n getShadowRoot(): ShadowRoot | undefined {\n return isShadowRoot(this.#rootNode) ? this.#rootNode : undefined;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getLocale(): string {\n getLocaleDeprecationMessage();\n return this.#localeService.locale.baseName;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n setLocale(locale: string | undefined): void {\n setLocaleDeprecationMessage();\n const targetLocale = tryParseLocale(locale);\n // to be backwards compatible, we check here synchronously\n // same check is done in AppIntl.changeLocale\n if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {\n const localesList = this.#localeService.supportedMessageLocales\n .map((l) => l.baseName)\n .join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${targetLocale.baseName}' (supported locales: ${localesList}).`\n );\n }\n this.#localeService.changeLocale(targetLocale).catch((e) => {\n if (!isAbortError(e)) {\n LOG.error(`Failed to switch locale to '${targetLocale?.baseName}'.`, e);\n }\n });\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getSupportedLocales(): readonly string[] {\n getSupportedLocalesDeprecationMessage();\n return this.#localeService.supportedMessageLocales.map((l) => l.baseName);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAcjC,MAAM,8BAA8B,UAAA,CAAW;AAAA,EAC3C,IAAA,EAAM,8BAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AACD,MAAM,8BAA8B,UAAA,CAAW;AAAA,EAC3C,IAAA,EAAM,8BAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AACD,MAAM,wCAAwC,UAAA,CAAW;AAAA,EACrD,IAAA,EAAM,wCAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AAEM,MAAM,sBAAA,CAAqD;AAAA,EAC9D,KAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EAEA,WAAA,CACI,SACA,UAAA,EACF;AACE,IAAA,IAAA,CAAK,QAAQ,UAAA,CAAW,IAAA;AACxB,IAAA,IAAA,CAAK,YAAY,UAAA,CAAW,QAAA;AAC5B,IAAA,IAAA,CAAK,aAAa,UAAA,CAAW,SAAA;AAC7B,IAAA,IAAA,CAAK,cAAA,GAAiB,QAAQ,UAAA,CAAW,aAAA;AAAA,EAC7C;AAAA,EAEA,cAAA,GAA8B;AAC1B,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EAChB;AAAA,EAEA,OAAA,GAAoB;AAChB,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EAChB;AAAA,EAEA,aAAA,GAAwC;AACpC,IAAA,OAAO,YAAA,CAAa,IAAA,CAAK,SAAS,CAAA,GAAI,KAAK,SAAA,GAAY,MAAA;AAAA,EAC3D;AAAA,EAEA,uBAAA,GAAuC;AACnC,IAAA,OAAO,IAAA,CAAK,UAAA;AAAA,EAChB;AAAA;AAAA,EAGA,SAAA,GAAoB;AAChB,IAAA,2BAAA,EAA4B;AAC5B,IAAA,OAAO,IAAA,CAAK,eAAe,MAAA,CAAO,QAAA;AAAA,EACtC;AAAA;AAAA,EAGA,UAAU,MAAA,EAAkC;AACxC,IAAA,2BAAA,EAA4B;AAC5B,IAAA,MAAM,YAAA,GAAe,eAAe,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"ApplicationContextImpl.js","sources":["ApplicationContextImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error, deprecated, isAbortError } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationContext, LocaleService } from \"../api\";\nimport { isShadowRoot, RootNode } from \"../dom\";\nimport { ErrorId } from \"../errors\";\nimport { tryParseLocale } from \"../i18n\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\nexport interface ApplicationContextProperties {\n host: HTMLElement;\n rootNode: RootNode;\n container: HTMLElement;\n}\n\ninterface ServiceReferences {\n localeService: LocaleService;\n}\n\nexport type ApplicationContextServiceOptions = ServiceOptions<ServiceReferences>;\n\nconst setLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.setLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.changeLocale` instead.\"\n});\nconst getLocaleDeprecationMessage = deprecated({\n name: \"ApplicationContext.getLocale\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.locale` instead.\"\n});\nconst getSupportedLocalesDeprecationMessage = deprecated({\n name: \"ApplicationContext.getSupportedLocales\",\n packageName: \"@open-pioneer/runtime\",\n since: \"v4.7.0\",\n alternative: \"Use `runtime.LocaleService.supportedMessageLocales` instead.\"\n});\n\nexport class ApplicationContextImpl implements ApplicationContext {\n #host: HTMLElement;\n #rootNode: RootNode;\n #container: HTMLElement;\n #localeService: LocaleService;\n\n constructor(\n options: ApplicationContextServiceOptions,\n properties: ApplicationContextProperties\n ) {\n this.#host = properties.host;\n this.#rootNode = properties.rootNode;\n this.#container = properties.container;\n this.#localeService = options.references.localeService;\n }\n\n getHostElement(): HTMLElement {\n return this.#host;\n }\n\n getRoot(): RootNode {\n return this.#rootNode;\n }\n\n getShadowRoot(): ShadowRoot | undefined {\n return isShadowRoot(this.#rootNode) ? this.#rootNode : undefined;\n }\n\n getApplicationContainer(): HTMLElement {\n return this.#container;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getLocale(): string {\n getLocaleDeprecationMessage();\n return this.#localeService.locale.baseName;\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n setLocale(locale: string | undefined): void {\n setLocaleDeprecationMessage();\n const targetLocale = tryParseLocale(locale);\n if (locale != null && !targetLocale) {\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${locale}': not a valid BCP 47 language tag.`\n );\n }\n // to be backwards compatible, we check here synchronously\n // same check is done in AppIntl.changeLocale\n if (targetLocale && !this.#localeService.supportsLocale(targetLocale)) {\n const localesList = this.#localeService.supportedMessageLocales\n .map((l) => l.baseName)\n .join(\", \");\n throw new Error(\n ErrorId.UNSUPPORTED_LOCALE,\n `Unsupported locale '${targetLocale.baseName}' (supported locales: ${localesList}).`\n );\n }\n this.#localeService.changeLocale(targetLocale).catch((e) => {\n if (!isAbortError(e)) {\n LOG.error(`Failed to switch locale to '${targetLocale?.baseName}'.`, e);\n }\n });\n }\n\n /** @deprecated Use `runtime.LocaleService` instead. */\n getSupportedLocales(): readonly string[] {\n getSupportedLocalesDeprecationMessage();\n return this.#localeService.supportedMessageLocales.map((l) => l.baseName);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAWA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAcjC,MAAM,8BAA8B,UAAA,CAAW;AAAA,EAC3C,IAAA,EAAM,8BAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AACD,MAAM,8BAA8B,UAAA,CAAW;AAAA,EAC3C,IAAA,EAAM,8BAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AACD,MAAM,wCAAwC,UAAA,CAAW;AAAA,EACrD,IAAA,EAAM,wCAAA;AAAA,EACN,WAAA,EAAa,uBAAA;AAAA,EACb,KAAA,EAAO,QAAA;AAAA,EACP,WAAA,EAAa;AACjB,CAAC,CAAA;AAEM,MAAM,sBAAA,CAAqD;AAAA,EAC9D,KAAA;AAAA,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AA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,QAAQ,CAAA,CACrB,IAAA,CAAK,IAAI,CAAA;AACd,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,OAAA,CAAQ,kBAAA;AAAA,QACR,CAAA,oBAAA,EAAuB,YAAA,CAAa,QAAQ,CAAA,sBAAA,EAAyB,WAAW,CAAA,EAAA;AAAA,OACpF;AAAA,IACJ;AACA,IAAA,IAAA,CAAK,eAAe,YAAA,CAAa,YAAY,CAAA,CAAE,KAAA,CAAM,CAAC,CAAA,KAAM;AACxD,MAAA,IAAI,CAAC,YAAA,CAAa,CAAC,CAAA,EAAG;AAClB,QAAA,GAAA,CAAI,KAAA,CAAM,CAAA,4BAAA,EAA+B,YAAA,EAAc,QAAQ,MAAM,CAAC,CAAA;AAAA,MAC1E;AAAA,IACJ,CAAC,CAAA;AAAA,EACL;AAAA;AAAA,EAGA,mBAAA,GAAyC;AACrC,IAAA,qCAAA,EAAsC;AACtC,IAAA,OAAO,KAAK,cAAA,CAAe,uBAAA,CAAwB,IAAI,CAAC,CAAA,KAAM,EAAE,QAAQ,CAAA;AAAA,EAC5E;AACJ;;"}
|
|
@@ -3,7 +3,7 @@ import { ServiceOptions } from "../Service";
|
|
|
3
3
|
interface References {
|
|
4
4
|
listeners: ApplicationLifecycleListener[];
|
|
5
5
|
}
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class ApplicationLifecycleEventServiceImpl {
|
|
7
7
|
#private;
|
|
8
8
|
constructor(options: ServiceOptions<References>);
|
|
9
9
|
/** @internal */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createLogger, Error } from '@open-pioneer/core';
|
|
2
|
-
import { sourceId$
|
|
2
|
+
import { sourceId$3 as sourceId } from '../_virtual/source-info.js';
|
|
3
3
|
import { ErrorId } from '../errors.js';
|
|
4
4
|
|
|
5
5
|
const LOG = createLogger(sourceId);
|
|
6
|
-
class
|
|
6
|
+
class ApplicationLifecycleEventServiceImpl {
|
|
7
7
|
#listeners;
|
|
8
8
|
constructor(options) {
|
|
9
9
|
const listeners = options.references.listeners;
|
|
@@ -36,5 +36,5 @@ class ApplicationLifecycleEventService {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export {
|
|
40
|
-
//# sourceMappingURL=
|
|
39
|
+
export { ApplicationLifecycleEventServiceImpl };
|
|
40
|
+
//# sourceMappingURL=ApplicationLifecycleEventServiceImpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApplicationLifecycleEventServiceImpl.js","sources":["ApplicationLifecycleEventServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ApplicationLifecycleListener } from \"../api\";\nimport { ErrorId } from \"../errors\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface References {\n listeners: ApplicationLifecycleListener[];\n}\n\nexport class ApplicationLifecycleEventServiceImpl {\n #listeners: [serviceId: string, listener: ApplicationLifecycleListener][];\n\n constructor(options: ServiceOptions<References>) {\n const listeners = options.references.listeners;\n const listenersMeta = options.referencesMeta.listeners;\n this.#listeners = listeners.map((listener, index) => [\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n listenersMeta[index]!.serviceId,\n listener\n ]);\n }\n\n /** @internal */\n emitLifecycleEvent(event: \"after-start\" | \"before-stop\"): void {\n const methodName = (() => {\n switch (event) {\n case \"after-start\":\n return \"afterApplicationStart\";\n case \"before-stop\":\n return \"beforeApplicationStop\";\n default:\n throw new Error(ErrorId.INTERNAL, `Invalid event '${event}'`);\n }\n })();\n for (const [serviceId, listener] of this.#listeners) {\n try {\n listener[methodName]?.();\n } catch (e) {\n LOG.error(`Unexpected error from application lifecycle listener ${serviceId}`, e);\n }\n }\n }\n}\n"],"names":[],"mappings":";;;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAM1B,MAAM,oCAAA,CAAqC;AAAA,EAC9C,UAAA;AAAA,EAEA,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,SAAA,GAAY,QAAQ,UAAA,CAAW,SAAA;AACrC,IAAA,MAAM,aAAA,GAAgB,QAAQ,cAAA,CAAe,SAAA;AAC7C,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA,CAAU,GAAA,CAAI,CAAC,UAAU,KAAA,KAAU;AAAA;AAAA,MAEjD,aAAA,CAAc,KAAK,CAAA,CAAG,SAAA;AAAA,MACtB;AAAA,KACH,CAAA;AAAA,EACL;AAAA;AAAA,EAGA,mBAAmB,KAAA,EAA4C;AAC3D,IAAA,MAAM,cAAc,MAAM;AACtB,MAAA,QAAQ,KAAA;AAAO,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX,KAAK,aAAA;AACD,UAAA,OAAO,uBAAA;AAAA,QACX;AACI,UAAA,MAAM,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,EAAU,CAAA,eAAA,EAAkB,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA;AACpE,IACJ,CAAA,GAAG;AACH,IAAA,KAAA,MAAW,CAAC,SAAA,EAAW,QAAQ,CAAA,IAAK,KAAK,UAAA,EAAY;AACjD,MAAA,IAAI;AACA,QAAA,QAAA,CAAS,UAAU,CAAA,IAAI;AAAA,MAC3B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,KAAA,CAAM,CAAA,qDAAA,EAAwD,SAAS,CAAA,CAAA,EAAI,CAAC,CAAA;AAAA,MACpF;AAAA,IACJ;AAAA,EACJ;AACJ;;"}
|
|
@@ -6,7 +6,7 @@ interface ServiceReferences {
|
|
|
6
6
|
export type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;
|
|
7
7
|
export declare class NumberParserServiceImpl implements NumberParserService {
|
|
8
8
|
#private;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(options: NumberParserServiceOptions);
|
|
10
10
|
parseNumber(numberString: string): number;
|
|
11
11
|
}
|
|
12
12
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { computed } from '@conterra/reactivity-core';
|
|
2
2
|
import { createLogger, NumberParser } from '@open-pioneer/core';
|
|
3
|
-
import { sourceId$
|
|
3
|
+
import { sourceId$4 as sourceId } from '../_virtual/source-info.js';
|
|
4
4
|
|
|
5
5
|
const LOG = createLogger(sourceId);
|
|
6
6
|
class NumberParserServiceImpl {
|
|
7
7
|
#numberParser;
|
|
8
|
-
constructor(
|
|
9
|
-
const localeService =
|
|
8
|
+
constructor(options) {
|
|
9
|
+
const localeService = options.references.localeService;
|
|
10
10
|
this.#numberParser = computed(() => {
|
|
11
11
|
const tag = localeService.locale.baseName;
|
|
12
12
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { computed, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { createLogger, NumberParser } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LocaleService, NumberParserService } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface ServiceReferences {\n localeService: Pick<LocaleService, \"locale\">;\n}\n\nexport type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;\n\nexport class NumberParserServiceImpl implements NumberParserService {\n #numberParser: ReadonlyReactive<NumberParser>;\n\n constructor(
|
|
1
|
+
{"version":3,"file":"NumberParserServiceImpl.js","sources":["NumberParserServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { computed, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { createLogger, NumberParser } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LocaleService, NumberParserService } from \"../api\";\nimport { ServiceOptions } from \"../Service\";\n\nconst LOG = createLogger(sourceId);\n\ninterface ServiceReferences {\n localeService: Pick<LocaleService, \"locale\">;\n}\n\nexport type NumberParserServiceOptions = ServiceOptions<ServiceReferences>;\n\nexport class NumberParserServiceImpl implements NumberParserService {\n #numberParser: ReadonlyReactive<NumberParser>;\n\n constructor(options: NumberParserServiceOptions) {\n const localeService = options.references.localeService;\n this.#numberParser = computed(() => {\n const tag = localeService.locale.baseName;\n try {\n return new NumberParser(tag);\n } catch (e) {\n LOG.warn(\n `Failed to create NumberParser with locale '${tag}'. Falling back to 'en-US'.`,\n e\n );\n return new NumberParser(\"en-US\");\n }\n });\n }\n\n parseNumber(numberString: string): number {\n return this.#numberParser.value.parse(numberString);\n }\n}\n"],"names":[],"mappings":";;;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAQ1B,MAAM,uBAAA,CAAuD;AAAA,EAChE,aAAA;AAAA,EAEA,YAAY,OAAA,EAAqC;AAC7C,IAAA,MAAM,aAAA,GAAgB,QAAQ,UAAA,CAAW,aAAA;AACzC,IAAA,IAAA,CAAK,aAAA,GAAgB,SAAS,MAAM;AAChC,MAAA,MAAM,GAAA,GAAM,cAAc,MAAA,CAAO,QAAA;AACjC,MAAA,IAAI;AACA,QAAA,OAAO,IAAI,aAAa,GAAG,CAAA;AAAA,MAC/B,SAAS,CAAA,EAAG;AACR,QAAA,GAAA,CAAI,IAAA;AAAA,UACA,8CAA8C,GAAG,CAAA,2BAAA,CAAA;AAAA,UACjD;AAAA,SACJ;AACA,QAAA,OAAO,IAAI,aAAa,OAAO,CAAA;AAAA,MACnC;AAAA,IACJ,CAAC,CAAA;AAAA,EACL;AAAA,EAEA,YAAY,YAAA,EAA8B;AACtC,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,KAAA,CAAM,KAAA,CAAM,YAAY,CAAA;AAAA,EACtD;AACJ;;"}
|
|
@@ -7,7 +7,7 @@ import { PackageRepr } from '../service-layer/PackageRepr.js';
|
|
|
7
7
|
import { ServiceRepr, createFunctionFactory, createConstructorFactory } from '../service-layer/ServiceRepr.js';
|
|
8
8
|
import { ApiServiceImpl } from './ApiServiceImpl.js';
|
|
9
9
|
import { ApplicationContextImpl } from './ApplicationContextImpl.js';
|
|
10
|
-
import {
|
|
10
|
+
import { ApplicationLifecycleEventServiceImpl } from './ApplicationLifecycleEventServiceImpl.js';
|
|
11
11
|
import { LocaleServiceImpl } from './LocaleServiceImpl.js';
|
|
12
12
|
import { NumberParserServiceImpl } from './NumberParserServiceImpl.js';
|
|
13
13
|
import { ThemeServiceImpl } from './ThemeServiceImpl.js';
|
|
@@ -78,7 +78,7 @@ function createBuiltinPackage(properties) {
|
|
|
78
78
|
const lifecycleEventService = new ServiceRepr({
|
|
79
79
|
name: "ApplicationLifecycleEventServiceImpl",
|
|
80
80
|
packageName: RUNTIME_PACKAGE_NAME,
|
|
81
|
-
factory: createConstructorFactory(
|
|
81
|
+
factory: createConstructorFactory(ApplicationLifecycleEventServiceImpl),
|
|
82
82
|
intl: constant(intl),
|
|
83
83
|
interfaces: [
|
|
84
84
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { constant } from \"@conterra/reactivity-core\";\nimport { createEmptyPackageIntl } from \"../i18n\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport {\n createConstructorFactory,\n createFunctionFactory,\n ServiceRepr\n} from \"../service-layer/ServiceRepr\";\nimport { ApiServiceImpl } from \"./ApiServiceImpl\";\nimport {\n ApplicationContextImpl,\n ApplicationContextProperties,\n ApplicationContextServiceOptions\n} from \"./ApplicationContextImpl\";\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { constant } from \"@conterra/reactivity-core\";\nimport { createEmptyPackageIntl } from \"../i18n\";\nimport { PackageRepr } from \"../service-layer/PackageRepr\";\nimport {\n createConstructorFactory,\n createFunctionFactory,\n ServiceRepr\n} from \"../service-layer/ServiceRepr\";\nimport { ApiServiceImpl } from \"./ApiServiceImpl\";\nimport {\n ApplicationContextImpl,\n ApplicationContextProperties,\n ApplicationContextServiceOptions\n} from \"./ApplicationContextImpl\";\nimport { ApplicationLifecycleEventServiceImpl } from \"./ApplicationLifecycleEventServiceImpl\";\nimport { LocaleServiceImpl, LocaleServiceProperties } from \"./LocaleServiceImpl\";\nimport { NumberParserServiceImpl, NumberParserServiceOptions } from \"./NumberParserServiceImpl\";\nimport { ThemeServiceImpl, ThemeServiceProperties } from \"./ThemeServiceImpl\";\n\nexport const RUNTIME_PACKAGE_NAME = \"@open-pioneer/runtime\";\nexport const RUNTIME_API_EXTENSION = \"integration.ApiExtension\";\nexport const RUNTIME_API_SERVICE = \"runtime.ApiService\";\nexport const RUNTIME_APPLICATION_CONTEXT = \"runtime.ApplicationContext\";\nexport const RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE =\n \"runtime.ApplicationLifecycleEventService\";\nexport const RUNTIME_NUMBER_PARSER_SERVICE = \"runtime.NumberParserService\";\nexport const RUNTIME_AUTO_START = \"runtime.AutoStart\";\nexport const RUNTIME_THEME_SERVICE = \"runtime.ThemeService\";\nexport const RUNTIME_LOCALE_SERVICE = \"runtime.LocaleService\";\n\nexport type BuiltinPackageProperties = ApplicationContextProperties &\n ThemeServiceProperties &\n LocaleServiceProperties;\n\n/**\n * Creates the builtin package containing the builtin services.\n *\n * The runtime package should not use services in the `build.config.mjs`\n * for a clean bootstrapping procedure (it will be instantiated without\n * generated application metadata in tests).\n *\n * This function is called as part of the service layer startup.\n * The package produced here is always part of the application.\n */\nexport function createBuiltinPackage(properties: BuiltinPackageProperties): PackageRepr {\n const intl = createEmptyPackageIntl();\n\n const localeService = new ServiceRepr({\n name: \"LocaleServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(() => new LocaleServiceImpl(properties)),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_LOCALE_SERVICE,\n qualifier: \"builtin\"\n }\n ]\n });\n const apiService = new ServiceRepr({\n name: \"ApiServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApiServiceImpl),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_API_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"providers\",\n interfaceName: RUNTIME_API_EXTENSION,\n all: true\n }\n ]\n });\n const appContext = new ServiceRepr({\n name: \"ApplicationContextImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) =>\n new ApplicationContextImpl(options as ApplicationContextServiceOptions, properties)\n ),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"localeService\",\n interfaceName: RUNTIME_LOCALE_SERVICE,\n qualifier: \"builtin\"\n }\n ]\n });\n const lifecycleEventService = new ServiceRepr({\n name: \"ApplicationLifecycleEventServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createConstructorFactory(ApplicationLifecycleEventServiceImpl),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_APPLICATION_LIFECYCLE_EVENT_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"listeners\",\n interfaceName: \"runtime.ApplicationLifecycleListener\",\n all: true\n }\n ]\n });\n const numberParserService = new ServiceRepr({\n name: \"NumberParserServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(\n (options) => new NumberParserServiceImpl(options as NumberParserServiceOptions)\n ),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_NUMBER_PARSER_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"localeService\",\n interfaceName: RUNTIME_LOCALE_SERVICE,\n qualifier: \"builtin\"\n }\n ]\n });\n\n const themeService = new ServiceRepr({\n name: \"ThemeServiceImpl\",\n packageName: RUNTIME_PACKAGE_NAME,\n factory: createFunctionFactory(() => new ThemeServiceImpl(properties)),\n intl: constant(intl),\n interfaces: [\n {\n interfaceName: RUNTIME_THEME_SERVICE,\n qualifier: \"builtin\"\n }\n ],\n dependencies: [\n {\n referenceName: \"applicationContext\",\n interfaceName: RUNTIME_APPLICATION_CONTEXT,\n qualifier: \"builtin\"\n }\n ]\n });\n\n return new PackageRepr({\n name: RUNTIME_PACKAGE_NAME,\n services: [\n apiService,\n appContext,\n lifecycleEventService,\n localeService,\n numberParserService,\n themeService\n ],\n intl: constant(intl)\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAsBO,MAAM,oBAAA,GAAuB;AAC7B,MAAM,qBAAA,GAAwB,0BAAA;AAC9B,MAAM,mBAAA,GAAsB;AAC5B,MAAM,2BAAA,GAA8B,4BAAA;AACpC,MAAM,2CAAA,GACT;AACG,MAAM,6BAAA,GAAgC,6BAAA;AACtC,MAAM,kBAAA,GAAqB;AAC3B,MAAM,qBAAA,GAAwB;AAC9B,MAAM,sBAAA,GAAyB;AAgB/B,SAAS,qBAAqB,UAAA,EAAmD;AACpF,EAAA,MAAM,OAAO,sBAAA,EAAuB;AAEpC,EAAA,MAAM,aAAA,GAAgB,IAAI,WAAA,CAAY;AAAA,IAClC,IAAA,EAAM,mBAAA;AAAA,IACN,WAAA,EAAa,oBAAA;AAAA,IACb,SAAS,qB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,MACV;AAAA,QACI,aAAA,EAAe,oBAAA;AAAA,QACf,aAAA,EAAe,2BAAA;AAAA,QACf,SAAA,EAAW;AAAA;AACf;AACJ,GACH,CAAA;AAED,EAAA,OAAO,IAAI,WAAA,CAAY;AAAA,IACnB,IAAA,EAAM,oBAAA;AAAA,IACN,QAAA,EAAU;AAAA,MACN,UAAA;AAAA,MACA,UAAA;AAAA,MACA,qBAAA;AAAA,MACA,aAAA;AAAA,MACA,mBAAA;AAAA,MACA;AAAA,KACJ;AAAA,IACA,IAAA,EAAM,SAAS,IAAI;AAAA,GACtB,CAAA;AACL;;"}
|
package/dom/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export type RootNode = Document | ShadowRoot;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const APP_ROOT_CLASS = "pioneer-root";
|
|
9
9
|
export declare function isShadowRoot(node: RootNode): node is ShadowRoot;
|
|
10
|
-
export declare function isDocument(node: RootNode): node is Document;
|
|
11
10
|
/**
|
|
12
11
|
* Returns the parent node for <style> elements.
|
|
13
12
|
*/
|
package/dom/index.js
CHANGED
|
@@ -7,7 +7,7 @@ function getStylesRoot(node) {
|
|
|
7
7
|
}
|
|
8
8
|
function createAppRoot() {
|
|
9
9
|
const container = document.createElement("div");
|
|
10
|
-
container.classList.add(
|
|
10
|
+
container.classList.add(APP_ROOT_CLASS);
|
|
11
11
|
container.style.minHeight = "100%";
|
|
12
12
|
container.style.height = "100%";
|
|
13
13
|
return container;
|
package/dom/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * The root node of an application.\n */\nexport type RootNode = Document | ShadowRoot;\n\n/**\n * Class of the <div> that contains the entire application.\n */\nexport const APP_ROOT_CLASS = \"pioneer-root\";\n\nexport function isShadowRoot(node: RootNode): node is ShadowRoot {\n return node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && \"host\" in node;\n}\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * The root node of an application.\n */\nexport type RootNode = Document | ShadowRoot;\n\n/**\n * Class of the <div> that contains the entire application.\n */\nexport const APP_ROOT_CLASS = \"pioneer-root\";\n\nexport function isShadowRoot(node: RootNode): node is ShadowRoot {\n return node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && \"host\" in node;\n}\n\n/**\n * Returns the parent node for <style> elements.\n */\nexport function getStylesRoot(node: RootNode): ShadowRoot | HTMLHeadElement {\n return isShadowRoot(node) ? node : node.head;\n}\n\n/**\n * Creates the node that contains all other application content.\n */\nexport function createAppRoot(): HTMLDivElement {\n // Setup application root node in the shadow dom\n const container = document.createElement(\"div\");\n container.classList.add(APP_ROOT_CLASS);\n container.style.minHeight = \"100%\";\n container.style.height = \"100%\";\n return container;\n}\n\n/**\n * Returns the styles for host element (the web component node).\n */\nexport function getBuiltinStyles(rootNode: RootNode, hostElement: HTMLElement | undefined) {\n // Prevent inheritance of certain css values and normalize to display: block by default.\n // See https://open-wc.org/guides/knowledge/styling/styles-piercing-shadow-dom/\n // NOTE: layer base comes from chakra (used for css resets etc).\n const selector =\n isShadowRoot(rootNode) || !hostElement ? \":host\" : hostElement.tagName.toLowerCase();\n return `@layer base { ${selector} { all: initial; display: block; } }`;\n}\n"],"names":[],"mappings":"AAWO,MAAM,cAAA,GAAiB;AAEvB,SAAS,aAAa,IAAA,EAAoC;AAC7D,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,IAAA,CAAK,sBAAA,IAA0B,MAAA,IAAU,IAAA;AACtE;AAKO,SAAS,cAAc,IAAA,EAA8C;AACxE,EAAA,OAAO,YAAA,CAAa,IAAI,CAAA,GAAI,IAAA,GAAO,IAAA,CAAK,IAAA;AAC5C;AAKO,SAAS,aAAA,GAAgC;AAE5C,EAAA,MAAM,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AAC9C,EAAA,SAAA,CAAU,SAAA,CAAU,IAAI,cAAc,CAAA;AACtC,EAAA,SAAA,CAAU,MAAM,SAAA,GAAY,MAAA;AAC5B,EAAA,SAAA,CAAU,MAAM,MAAA,GAAS,MAAA;AACzB,EAAA,OAAO,SAAA;AACX;AAKO,SAAS,gBAAA,CAAiB,UAAoB,WAAA,EAAsC;AAIvF,EAAA,MAAM,QAAA,GACF,aAAa,QAAQ,CAAA,IAAK,CAAC,WAAA,GAAc,OAAA,GAAU,WAAA,CAAY,OAAA,CAAQ,WAAA,EAAY;AACvF,EAAA,OAAO,iBAAiB,QAAQ,CAAA,oCAAA,CAAA;AACpC;;"}
|
package/i18n/AppIntl.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare class AppIntl {
|
|
|
45
45
|
* Always one of {@link supportedMessageLocales}.
|
|
46
46
|
*/
|
|
47
47
|
get messageLocale(): Intl.Locale;
|
|
48
|
-
/**
|
|
48
|
+
/** Message locales the app supports after applying `restrictSupportedLocales`. */
|
|
49
49
|
get supportedMessageLocales(): Intl.Locale[];
|
|
50
50
|
/** True if reactive locale switching is enabled. */
|
|
51
51
|
get supportsLiveChanges(): boolean;
|
package/i18n/AppIntl.js
CHANGED
|
@@ -100,7 +100,7 @@ class AppIntl {
|
|
|
100
100
|
get messageLocale() {
|
|
101
101
|
return this.#messageLocale.value;
|
|
102
102
|
}
|
|
103
|
-
/**
|
|
103
|
+
/** Message locales the app supports after applying `restrictSupportedLocales`. */
|
|
104
104
|
get supportedMessageLocales() {
|
|
105
105
|
return this.#effectiveSupportedLocales;
|
|
106
106
|
}
|
|
@@ -169,19 +169,14 @@ class AppIntl {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
function filterAvailableLocales(messageLocaleStrings, restrictSupportedLocales) {
|
|
172
|
-
const isRestricted = restrictSupportedLocales != null;
|
|
173
172
|
const localesToSupport = new Set(restrictSupportedLocales ?? messageLocaleStrings);
|
|
174
173
|
const supportedLocales = [];
|
|
175
174
|
for (const l of localesToSupport) {
|
|
176
175
|
if (!messageLocaleStrings.includes(l)) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
LOG.warn(`Locale '${l}' is not included in app metadata locales and will be ignored.`);
|
|
184
|
-
continue;
|
|
176
|
+
throw new Error(
|
|
177
|
+
ErrorId.UNSUPPORTED_LOCALE,
|
|
178
|
+
`Configured supported locale '${l}' is not one of the application's message locales [${messageLocaleStrings.join(", ")}].`
|
|
179
|
+
);
|
|
185
180
|
}
|
|
186
181
|
const locale = tryParseLocale(l);
|
|
187
182
|
if (!locale) {
|
package/i18n/AppIntl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppIntl.js","sources":["AppIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\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;AACtD,IAAA,MAAM,yBAAA,GAA4B,sBAAA;AAAA,MAC9B,oBAAA;AAAA,MACA;AAAA,KACJ;AACA,IAAA,MAAM,cAAc,iBAAA,EAAkB;AACtC,IAAA,MAAM,eAAA,GAAkB,eAAe,YAAY,CAAA;AACnD,IAAA,IAAI,GAAA,CAAI,SAAQ,EAAG;AACf,MAAA,MAAM,eAAA,GAAkB,YAAY,GA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A,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 /** Message locales the app supports after applying `restrictSupportedLocales`. */\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 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 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 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;AA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,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;;"}
|
package/i18n/PackageIntl.js
CHANGED
|
@@ -29,18 +29,15 @@ const RICH_TEXT_TAGS = Object.freeze({
|
|
|
29
29
|
"br": renderTag("br")
|
|
30
30
|
});
|
|
31
31
|
function formatRichMessage(intl, descriptor, values, opts) {
|
|
32
|
-
|
|
32
|
+
const allValues = {
|
|
33
33
|
...RICH_TEXT_TAGS,
|
|
34
34
|
...values
|
|
35
35
|
};
|
|
36
|
-
const chunks = intl.formatMessage(descriptor, preprocessValues(
|
|
36
|
+
const chunks = intl.formatMessage(descriptor, preprocessValues(allValues), opts);
|
|
37
37
|
const nodes = assignKeys(chunks);
|
|
38
38
|
return createElement(Fragment, void 0, ...nodes);
|
|
39
39
|
}
|
|
40
40
|
function preprocessValues(values) {
|
|
41
|
-
if (!values) {
|
|
42
|
-
return void 0;
|
|
43
|
-
}
|
|
44
41
|
const fixedValues = {};
|
|
45
42
|
for (const [key, valueOrFn] of Object.entries(values)) {
|
|
46
43
|
let fixedValue = valueOrFn;
|
package/i18n/PackageIntl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageIntl.js","sources":["PackageIntl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\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
|
|
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 const allValues = {\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(allValues) as any, opts);\n const nodes = assignKeys(chunks);\n return createElement(Fragment, undefined, ...nodes);\n}\n\nfunction preprocessValues(values: Record<string, RichTextValue>) {\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 // Test only, console is fine.\n // oxlint-disable-next-line no-console\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,QAAA,EAAU,UAAU,QAAQ,CAAA;AAAA,EAC5B,GAAA,EAAK,UAAU,GAAG,CAAA;AAAA,EAClB,IAAA,EAAM,UAAU,IAAI,CAAA;AAAA,EACpB,MAAA,EAAQ,UAAU,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,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;AAIA,EAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AACrB,CAAA;;"}
|
|
@@ -10,7 +10,7 @@ export interface ObservableBox<T> {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Returns a boxed value.
|
|
13
|
-
* In development
|
|
13
|
+
* In development mode, the box value can be changed and observed.
|
|
14
14
|
*/
|
|
15
15
|
export declare function createBox<T>(value: T): ObservableBox<T>;
|
|
16
16
|
/** @internal */
|
|
@@ -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\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
|
|
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 mode, 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.9.0-dev.
|
|
4
|
+
"version": "4.9.0-dev.20261029090037",
|
|
5
5
|
"description": "Implements the runtime environment for Open Pioneer Trails apps.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@chakra-ui/react": "^3.37.0",
|
|
18
|
-
"@conterra/reactivity-core": "^0.8.
|
|
18
|
+
"@conterra/reactivity-core": "^0.8.9",
|
|
19
19
|
"@emotion/cache": "^11.14.0",
|
|
20
20
|
"@emotion/react": "^11.14.0",
|
|
21
|
-
"@formatjs/intl": "^6.1.
|
|
21
|
+
"@formatjs/intl": "^6.1.4",
|
|
22
22
|
"@formatjs/intl-localematcher": "^0.9.0",
|
|
23
|
-
"@open-pioneer/base-theme": "4.9.0-dev.
|
|
24
|
-
"@open-pioneer/core": "4.9.0-dev.
|
|
25
|
-
"@open-pioneer/reactivity": "4.9.0-dev.
|
|
26
|
-
"react": "^19.3.
|
|
27
|
-
"react-dom": "^19.3.
|
|
23
|
+
"@open-pioneer/base-theme": "4.9.0-dev.20261029090037",
|
|
24
|
+
"@open-pioneer/core": "4.9.0-dev.20261029090037",
|
|
25
|
+
"@open-pioneer/reactivity": "4.9.0-dev.20261029090037",
|
|
26
|
+
"react": "^19.3.1",
|
|
27
|
+
"react-dom": "^19.3.1"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"directory": "dist",
|
|
@@ -6,7 +6,7 @@ export interface PackageContextMethods {
|
|
|
6
6
|
getServices: (packageName: string, interfaceName: string) => Service[];
|
|
7
7
|
getProperties: (packageName: string) => Readonly<Record<string, unknown>>;
|
|
8
8
|
/**
|
|
9
|
-
* NOTE: Reactive for fine grained i18n changes (during dev for i18n HMR) and for live
|
|
9
|
+
* NOTE: Reactive for fine grained i18n changes (during dev for i18n HMR) and for live locale changes (also in production).
|
|
10
10
|
*/
|
|
11
11
|
getIntl(packageName: string): PackageIntl;
|
|
12
12
|
}
|
|
@@ -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\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
|
|
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 locale 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;;"}
|
|
@@ -11,7 +11,7 @@ export interface UseServiceOptions {
|
|
|
11
11
|
* This is an internal hook that is typically called indirectly via the hook
|
|
12
12
|
* provided from `"open-pioneer:react-hooks"`.
|
|
13
13
|
*
|
|
14
|
-
* @
|
|
14
|
+
* @internal
|
|
15
15
|
*/
|
|
16
16
|
export declare function useServiceInternal<ServiceType = unknown>(packageName: string, interfaceName: InterfaceNameForServiceType<ServiceType>, options?: UseServiceOptions): ServiceType;
|
|
17
17
|
/**
|
|
@@ -21,7 +21,7 @@ export declare function useServiceInternal<ServiceType = unknown>(packageName: s
|
|
|
21
21
|
* This is an internal hook that is typically called indirectly via the hook
|
|
22
22
|
* provided from `"open-pioneer:react-hooks"`.
|
|
23
23
|
*
|
|
24
|
-
* @
|
|
24
|
+
* @internal
|
|
25
25
|
*/
|
|
26
26
|
export declare function useServicesInternal<ServiceType = unknown>(packageName: string, interfaceName: InterfaceNameForServiceType<ServiceType>, options?: UseServiceOptions): ServiceType[];
|
|
27
27
|
/**
|
|
@@ -30,7 +30,7 @@ export declare function useServicesInternal<ServiceType = unknown>(packageName:
|
|
|
30
30
|
* This is an internal hook that is typically called indirectly via the hook
|
|
31
31
|
* provided from `"open-pioneer:react-hooks"`.
|
|
32
32
|
*
|
|
33
|
-
* @
|
|
33
|
+
* @internal
|
|
34
34
|
*/
|
|
35
35
|
export declare function usePropertiesInternal(packageName: string): Readonly<Record<string, unknown>>;
|
|
36
36
|
/**
|
|
@@ -39,6 +39,6 @@ export declare function usePropertiesInternal(packageName: string): Readonly<Rec
|
|
|
39
39
|
* This is an internal hook that is typically called indirectly via the hook
|
|
40
40
|
* provided from `"open-pioneer:react-hooks"`.
|
|
41
41
|
*
|
|
42
|
-
* @
|
|
42
|
+
* @internal
|
|
43
43
|
*/
|
|
44
44
|
export declare function useIntlInternal(packageName: string): PackageIntl;
|
|
@@ -6,13 +6,12 @@ import { PackageContext } from './PackageContext.js';
|
|
|
6
6
|
|
|
7
7
|
function useServiceInternal(packageName, interfaceName, options) {
|
|
8
8
|
const context = useContext(PackageContext);
|
|
9
|
+
const qualifier = options?.qualifier;
|
|
9
10
|
const service = useMemo(
|
|
10
|
-
() => checkContext("useService", context).getService(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
),
|
|
15
|
-
[context, packageName, interfaceName, options]
|
|
11
|
+
() => checkContext("useService", context).getService(packageName, interfaceName, {
|
|
12
|
+
qualifier
|
|
13
|
+
}),
|
|
14
|
+
[context, packageName, interfaceName, qualifier]
|
|
16
15
|
);
|
|
17
16
|
return service;
|
|
18
17
|
}
|
|
@@ -41,7 +40,7 @@ function checkContext(hookName, contextData) {
|
|
|
41
40
|
if (!contextData) {
|
|
42
41
|
throw new Error(
|
|
43
42
|
ErrorId.INTERNAL,
|
|
44
|
-
`
|
|
43
|
+
`Failed to access package context from '${hookName}': react integration was not set up properly.`
|
|
45
44
|
);
|
|
46
45
|
}
|
|
47
46
|
return contextData;
|