@open-pioneer/runtime 4.9.0 → 4.10.0-dev.20261119090001
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 +184 -177
- package/i18n/pick.js +14 -2
- package/i18n/pick.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @open-pioneer/runtime
|
|
2
2
|
|
|
3
|
+
## 4.10.0-dev.20261119090001
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 57b5b4f: Enable trusted publishing for this package.
|
|
8
|
+
- 93d2a9f: Update dependencies
|
|
9
|
+
|
|
3
10
|
## 4.9.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
|
@@ -9,10 +16,10 @@
|
|
|
9
16
|
### Patch Changes
|
|
10
17
|
|
|
11
18
|
- 6b160f3: Fix a set of smaller issues:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
- `element.when()` rejects with an abort error when the app failed to start, also when it is called after the failure. Previously such a call returned a promise that never settled.
|
|
20
|
+
- The deprecated `ApplicationContext.setLocale()` throws `runtime:unsupported-locale` again for a string that is not a valid BCP 47 tag, instead of silently switching to automatic locale selection.
|
|
21
|
+
- `useService()` no longer repeats the service lookup on every render when an options object is passed inline.
|
|
22
|
+
- The development-only intl watch of a service is released when the service constructor throws, and the `AppIntl` instance is released when the app is destroyed during startup.
|
|
16
23
|
|
|
17
24
|
- 42ca366: Update dependencies
|
|
18
25
|
- 7053566: An `undefined` value returned from `resolveConfig()` (for example `locale`) no longer overrides the default value of `config`.
|
|
@@ -36,12 +43,12 @@
|
|
|
36
43
|
- e433296: Update Chakra UI to 3.36.1
|
|
37
44
|
- 278515d: Add `runtime.LocaleService` and opt-in reactive locale switching.
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
You can opt-in by configuring the property `advanced.enableLiveLocaleChanges` when calling `createCustomElement`.
|
|
47
|
+
Once enabled, locale switches can be done without restarting the application.
|
|
48
|
+
Use `LocaleService.changeLocale` to update the application's locale.
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
Also export `parseLocale` and `tryParseLocale` algorithms.
|
|
51
|
+
These can be used to construct a (cleaned up) `Intl.Locale` object from a string.
|
|
45
52
|
|
|
46
53
|
### Patch Changes
|
|
47
54
|
|
|
@@ -60,15 +67,15 @@
|
|
|
60
67
|
- 05425c6: runtime - Introduce support for ServiceFactories, to provide constructor indirection during service creation
|
|
61
68
|
- 63db133: Support for hot reloading of i18n messages (requires updated vite plugin).
|
|
62
69
|
When i18n messages are updated:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
- React components rerender automatically with new `intl` object returned by `useIntl()`.
|
|
71
|
+
- Services that use the new `serviceOptions.currentIntl` interface also receive a new `intl` object (if they are watching for changes).
|
|
72
|
+
- Services that that still use the deprecated `serviceOptions.intl` interface cause the application to reload instead.
|
|
66
73
|
|
|
67
74
|
### Patch Changes
|
|
68
75
|
|
|
69
76
|
- e6db101: Update to Chakra UI 3.35.0
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
- update to Chakra UI @ 3.35.0, Ark UI @ 5.36.2, Zag JS @ 1.40.0
|
|
78
|
+
- use TooltipProviderProps to override `openDelay` globally (instead of Tooltip snippet)
|
|
72
79
|
|
|
73
80
|
- b092b75: Declare css property `color-scheme` on the application root. This can be used by the browser to render builtin controls differently.
|
|
74
81
|
|
|
@@ -77,9 +84,9 @@
|
|
|
77
84
|
### Minor Changes
|
|
78
85
|
|
|
79
86
|
- 89d743b: Provide `runtime.ThemeService`:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
- Supports switching between color modes `light` and `dark`.
|
|
88
|
+
- Supports changing the chakra theme ("systemConfig") at runtime.
|
|
89
|
+
- Supports reactive access to the preferred (system) color mode.
|
|
83
90
|
|
|
84
91
|
- 89d743b: Support for color modes (light and dark).
|
|
85
92
|
The default color mode remains `light` for backwards compatibility.
|
|
@@ -128,7 +135,7 @@
|
|
|
128
135
|
|
|
129
136
|
- b7a854d: Update dependencies
|
|
130
137
|
- 3881d08: - Update Chakra UI from 3.22.0 to 3.24.2
|
|
131
|
-
|
|
138
|
+
- Update to latest Chakra snippets
|
|
132
139
|
- adf277b: Update dependencies
|
|
133
140
|
|
|
134
141
|
## 4.0.0
|
|
@@ -138,41 +145,41 @@
|
|
|
138
145
|
- 9f074d8: Update to Chakra 3.x
|
|
139
146
|
- 53c92ba: Introduce an advanced option to disable the shadow root.
|
|
140
147
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
Applications that use the entire browser viewport may not need this feature, since there may be no "other" parts that may conflict with the app. In this case, you can disable the shadow root by setting this property to `false`.
|
|
144
|
-
- New option `advanced.enableShadowRoot`:
|
|
148
|
+
By default, trails applications use a shadow root to avoid conflicts (e.g. styles) with other parts of the site where the application may be embedded.
|
|
145
149
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
import * as appMetadata from "open-pioneer:app";
|
|
149
|
-
import { AppUI } from "./AppUI";
|
|
150
|
+
Applications that use the entire browser viewport may not need this feature, since there may be no "other" parts that may conflict with the app. In this case, you can disable the shadow root by setting this property to `false`.
|
|
151
|
+
- New option `advanced.enableShadowRoot`:
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
```ts
|
|
154
|
+
import { createCustomElement } from "@open-pioneer/runtime";
|
|
155
|
+
import * as appMetadata from "open-pioneer:app";
|
|
156
|
+
import { AppUI } from "./AppUI";
|
|
157
|
+
|
|
158
|
+
const element = createCustomElement({
|
|
159
|
+
component: AppUI,
|
|
160
|
+
appMetadata,
|
|
161
|
+
advanced: {
|
|
162
|
+
enableShadowRoot: false,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
customElements.define("no-shadowroot-sample", element);
|
|
167
|
+
```
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
- **Breaking:** As a consequence, the `ApplicationContext`'s `getShadowRoot()` method will now return `undefined` if the shadow root is disabled (previous: always a `ShadowRoot`):
|
|
163
170
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
```ts
|
|
172
|
+
const ctx: ApplicationContext = ...; // injected
|
|
173
|
+
const shadowRoot = ctx.getShadowRoot(); // ShadowRoot | undefined
|
|
174
|
+
```
|
|
168
175
|
|
|
169
|
-
|
|
176
|
+
- New method on the `ApplicationContext` that returns _either_ the `ShadowRoot` _or_ the `Document` (if the shadow root is disabled):
|
|
170
177
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
```ts
|
|
179
|
+
const ctx: ApplicationContext = ...; // injected
|
|
180
|
+
const root = ctx.getRoot(); // Document | ShadowRoot
|
|
181
|
+
root.getElementById("...") // always works
|
|
182
|
+
```
|
|
176
183
|
|
|
177
184
|
- 9f074d8: **Breaking:** Rename `theme` option of `createCustomElement()` to `chakraSystemConfig`.
|
|
178
185
|
|
|
@@ -188,54 +195,54 @@
|
|
|
188
195
|
In addition to primitive values, rich text formatting supports react values and custom react tags.
|
|
189
196
|
It always returns a react node, so can only be used in combination with react components.
|
|
190
197
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
198
|
+
_Example with react node as value:_
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
function Example() {
|
|
202
|
+
const intl = useIntl();
|
|
203
|
+
// Given i18n message "Hello, {name}!"
|
|
204
|
+
// replaces 'name' with the given react node:
|
|
205
|
+
const message = intl.formatRichMessage(
|
|
206
|
+
{ id: "foo" },
|
|
207
|
+
{
|
|
208
|
+
name: <FancyUserName />,
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
return <Box>{message}</Box>;
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
_Example with basic formatting:_
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
function Example() {
|
|
219
|
+
const intl = useIntl();
|
|
220
|
+
// Given i18n message "Hello, <strong>{name}</strong>!"
|
|
221
|
+
// renders with actual <strong> html node:
|
|
222
|
+
return <Box>{intl.formatRichMessage({ id: "foo" }, { name: "User" })}</Box>;
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Note that only a few basic formatting tags are predefined ("b", "strong", "i", "em", "code", "br").
|
|
227
|
+
If you need more advanced tags, you can define your own, see below.
|
|
228
|
+
_Example with custom tag:_
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
function Example() {
|
|
232
|
+
const intl = useIntl();
|
|
233
|
+
// Given i18n message "Open <foo>the door</foo>!",
|
|
234
|
+
// renders 'foo' using the formatter function below:
|
|
235
|
+
const message = intl.formatRichMessage(
|
|
236
|
+
{ id: "foo" },
|
|
237
|
+
{
|
|
238
|
+
foo: (parts) => <FancyTag>{parts}</FancyTag>,
|
|
239
|
+
},
|
|
240
|
+
);
|
|
241
|
+
return <Box>{message}</Box>;
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The TypeScript signature for the `intl.formatMessage()` function has been made a little bit stricter compared with FormatJS: only primitive values are allowed for the `values` argument (this should not affect users in practice).
|
|
239
246
|
|
|
240
247
|
### Patch Changes
|
|
241
248
|
|
|
@@ -246,13 +253,13 @@
|
|
|
246
253
|
### Major Changes
|
|
247
254
|
|
|
248
255
|
- 9477e54: Update dependencies
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
256
|
+
- React 19
|
|
257
|
+
- Vite 6
|
|
258
|
+
- FormatJS 3
|
|
259
|
+
- Open Pioneer Build Tools
|
|
260
|
+
- ...
|
|
254
261
|
|
|
255
|
-
|
|
262
|
+
For more details, see https://github.com/open-pioneer/trails-core-packages/pull/81
|
|
256
263
|
|
|
257
264
|
## 2.4.0
|
|
258
265
|
|
|
@@ -293,7 +300,7 @@
|
|
|
293
300
|
### Patch Changes
|
|
294
301
|
|
|
295
302
|
- e945264: Improve error message when metadata is missing (#55)
|
|
296
|
-
|
|
303
|
+
- @open-pioneer/runtime-react-support@1.0.2
|
|
297
304
|
|
|
298
305
|
## 2.1.5
|
|
299
306
|
|
|
@@ -304,16 +311,16 @@
|
|
|
304
311
|
Note that with the current implementation, the application will simply restart with the new locale.
|
|
305
312
|
The application's state will be lost.
|
|
306
313
|
|
|
307
|
-
|
|
314
|
+
Example:
|
|
308
315
|
|
|
309
|
-
|
|
310
|
-
|
|
316
|
+
```ts
|
|
317
|
+
import { ApplicationContext } from "@open-pioneer/runtime";
|
|
311
318
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
319
|
+
const appCtx: ApplicationContext = ...; // injected
|
|
320
|
+
appCtx.setLocale("en-US");
|
|
321
|
+
```
|
|
315
322
|
|
|
316
|
-
|
|
323
|
+
- @open-pioneer/runtime-react-support@1.0.2
|
|
317
324
|
|
|
318
325
|
## 2.1.4
|
|
319
326
|
|
|
@@ -335,7 +342,7 @@
|
|
|
335
342
|
### Patch Changes
|
|
336
343
|
|
|
337
344
|
- f749d96: Add a hint that `DECLARE_SERVICE_INTERFACE` should be imported via `import type`.
|
|
338
|
-
|
|
345
|
+
- @open-pioneer/runtime-react-support@1.0.0
|
|
339
346
|
|
|
340
347
|
## 2.1.0
|
|
341
348
|
|
|
@@ -343,46 +350,46 @@
|
|
|
343
350
|
|
|
344
351
|
- 80cd62d: Improve TypeScript integration for service classes.
|
|
345
352
|
|
|
346
|
-
|
|
347
|
-
|
|
353
|
+
Add a way for a service class to specify its interface name directly.
|
|
354
|
+
Usually services used across package boundaries split their public interface and their implementation such as this:
|
|
348
355
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
356
|
+
```ts
|
|
357
|
+
// Exported from package
|
|
358
|
+
interface MyService extends DeclaredService<"my-package.SomeInterface"> {
|
|
359
|
+
method(): void;
|
|
360
|
+
}
|
|
354
361
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
362
|
+
// In an implementation file, usually private.
|
|
363
|
+
class MyServiceImpl implements MyService {
|
|
364
|
+
method(): void {
|
|
365
|
+
// ...
|
|
360
366
|
}
|
|
361
|
-
|
|
367
|
+
}
|
|
368
|
+
```
|
|
362
369
|
|
|
363
|
-
|
|
364
|
-
|
|
370
|
+
Until now, there was no way for a service class to declare its interface directly.
|
|
371
|
+
This could be convenient within a package, or with a group of tightly coupled packages:
|
|
365
372
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
373
|
+
```ts
|
|
374
|
+
// Error: Type 'MyServiceImpl' has no properties in common with type 'DeclaredService<"my-package.InterfaceName">'.
|
|
375
|
+
class MyServiceImpl implements DeclaredService<"my-package.InterfaceName"> {
|
|
376
|
+
method() {}
|
|
377
|
+
}
|
|
378
|
+
```
|
|
372
379
|
|
|
373
|
-
|
|
380
|
+
From now on, you can write this instead:
|
|
374
381
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
382
|
+
```ts
|
|
383
|
+
class MyServiceImpl {
|
|
384
|
+
// Tells TypeScript which interface name must be used.
|
|
385
|
+
// See documentation of `DECLARE_SERVICE_INTERFACE` for more details.
|
|
386
|
+
declare [DECLARE_SERVICE_INTERFACE]: "my-package.InterfaceName";
|
|
387
|
+
|
|
388
|
+
method(): void {
|
|
389
|
+
// ...
|
|
384
390
|
}
|
|
385
|
-
|
|
391
|
+
}
|
|
392
|
+
```
|
|
386
393
|
|
|
387
394
|
### Patch Changes
|
|
388
395
|
|
|
@@ -402,51 +409,51 @@
|
|
|
402
409
|
- 6f954e3: **Breaking Change**: change how services integrate into TypeScript (fixes #22).
|
|
403
410
|
The old TypeScript integration had unexpected edge cases, see the linked issue.
|
|
404
411
|
|
|
405
|
-
|
|
406
|
-
|
|
412
|
+
NOTE: The changes below have no impact on runtime behavior, but they may trigger TypeScript errors in your code.
|
|
413
|
+
- To register a service's type with TypeScript, one previously used a block such as this:
|
|
407
414
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
415
|
+
```ts
|
|
416
|
+
// OLD! Can be removed
|
|
417
|
+
import "@open-pioneer/runtime";
|
|
418
|
+
declare module "@open-pioneer/runtime" {
|
|
419
|
+
interface ServiceRegistry {
|
|
420
|
+
"http.HttpService": HttpService;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
```
|
|
417
424
|
|
|
418
|
-
|
|
419
|
-
|
|
425
|
+
The new method requires the developer to change the service's declaration.
|
|
426
|
+
Simply add `extends DeclaredService<"SERVICE_ID">` to your service interface, where `SERVICE_ID` should match the service's interface name (`"provides"` in `build.config.mjs`).
|
|
420
427
|
|
|
421
|
-
|
|
422
|
-
|
|
428
|
+
```diff
|
|
429
|
+
+ import { DeclaredService } from "@open-pioneer/runtime";
|
|
423
430
|
|
|
424
|
-
|
|
425
|
-
|
|
431
|
+
- export interface HttpService {
|
|
432
|
+
+ export interface HttpService extends DeclaredService<"http.HttpService"> {
|
|
426
433
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
+
- import "@open-pioneer/runtime";
|
|
435
|
+
- declare module "@open-pioneer/runtime" {
|
|
436
|
+
- interface ServiceRegistry {
|
|
437
|
+
- "http.HttpService": HttpService;
|
|
438
|
+
- }
|
|
439
|
+
- }
|
|
440
|
+
```
|
|
434
441
|
|
|
435
|
-
|
|
442
|
+
- To use a service from React code (i.e. `useService` and `useServices`), you must now use the explicit service type in the hook's generic parameter list. Otherwise the hook will simply return `unknown`:
|
|
436
443
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
444
|
+
```diff
|
|
445
|
+
+ import { HttpService } from "@open-pioneer/http";
|
|
446
|
+
- const httpService = useService("http.HttpService");
|
|
447
|
+
+ const httpService = useService<HttpService>("http.HttpService");
|
|
448
|
+
```
|
|
442
449
|
|
|
443
|
-
|
|
450
|
+
This change was necessary to fix an issue where the global registration of the service interface (and its association with the string constant) was not available.
|
|
444
451
|
|
|
445
|
-
|
|
452
|
+
The system will still check that the provided string matches the string constant used in the service's declaration (`DeclaredService<...>`), so type safety is preserved.
|
|
446
453
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
454
|
+
- The types `InterfaceName` and `ServiceType<I>` have been removed. Use explicit service interfaces instead.
|
|
455
|
+
- The interfaces `ServiceRegistry` and `PropertiesRegistry` have been removed as global registration is no longer possible.
|
|
456
|
+
- The type `RawApplicationProperties` has been removed. Use `ApplicationProperties` instead.
|
|
450
457
|
|
|
451
458
|
### Patch Changes
|
|
452
459
|
|
package/i18n/pick.js
CHANGED
|
@@ -80,10 +80,22 @@ function equalityScore(candidate, base) {
|
|
|
80
80
|
}
|
|
81
81
|
return score;
|
|
82
82
|
}
|
|
83
|
-
function bestFit(
|
|
84
|
-
|
|
83
|
+
function bestFit(userTags, supportedTags) {
|
|
84
|
+
const match$1 = match(userTags, supportedTags, NO_MATCH_SENTINEL, {
|
|
85
85
|
algorithm: "best fit"
|
|
86
86
|
});
|
|
87
|
+
if (match$1 === NO_MATCH_SENTINEL) {
|
|
88
|
+
return match$1;
|
|
89
|
+
}
|
|
90
|
+
const exactMatch = userTags.find(
|
|
91
|
+
(tag) => supportedTags.includes(tag) && sameIgnoringVariants(tag, match$1)
|
|
92
|
+
);
|
|
93
|
+
return exactMatch ?? match$1;
|
|
94
|
+
}
|
|
95
|
+
function sameIgnoringVariants(tagA, tagB) {
|
|
96
|
+
const a = parseLocale(tagA);
|
|
97
|
+
const b = parseLocale(tagB);
|
|
98
|
+
return LOCALE_FIELDS.every((field) => a[field] === b[field]);
|
|
87
99
|
}
|
|
88
100
|
function getBrowserLocales() {
|
|
89
101
|
if (typeof window === "undefined") {
|
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\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(
|
|
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(userTags: readonly string[], supportedTags: readonly string[]): string {\n const match = bestFitMatch(userTags, supportedTags, NO_MATCH_SENTINEL, {\n algorithm: \"best fit\"\n });\n if (match === NO_MATCH_SENTINEL) {\n return match;\n }\n\n // The matcher ignores variant subtags: `de` and `de-simple` treated as equal.\n // This lookup ensures that an exact match in our supported tags wins.\n const exactMatch = userTags.find(\n (tag) => supportedTags.includes(tag) && sameIgnoringVariants(tag, match)\n );\n return exactMatch ?? match;\n}\n\nfunction sameIgnoringVariants(tagA: string, tagB: string): boolean {\n const a = parseLocale(tagA);\n const b = parseLocale(tagB);\n return LOCALE_FIELDS.every((field) => a[field] === b[field]);\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":["match","bestFitMatch"],"mappings":";;;;;AAQA,MAAM,iBA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|
-
"version": "4.
|
|
4
|
+
"version": "4.10.0-dev.20261119090001",
|
|
5
5
|
"description": "Implements the runtime environment for Open Pioneer Trails apps.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"directory": "src/packages/runtime"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@chakra-ui/react": "^3.
|
|
17
|
+
"@chakra-ui/react": "^3.38.0",
|
|
18
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.
|
|
22
|
-
"@formatjs/intl-localematcher": "^0.
|
|
23
|
-
"@open-pioneer/base-theme": "4.
|
|
24
|
-
"@open-pioneer/core": "4.
|
|
25
|
-
"@open-pioneer/reactivity": "4.
|
|
21
|
+
"@formatjs/intl": "^6.1.5",
|
|
22
|
+
"@formatjs/intl-localematcher": "^0.10.1",
|
|
23
|
+
"@open-pioneer/base-theme": "4.10.0-dev.20261119090001",
|
|
24
|
+
"@open-pioneer/core": "4.10.0-dev.20261119090001",
|
|
25
|
+
"@open-pioneer/reactivity": "4.10.0-dev.20261119090001",
|
|
26
26
|
"react": "^19.3.1",
|
|
27
27
|
"react-dom": "^19.3.1"
|
|
28
28
|
},
|