@open-pioneer/runtime 4.7.0-dev.20260625125130 → 4.7.0-dev.20260727091735
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +179 -175
- package/CustomElement.js +1 -1
- package/CustomElement.js.map +1 -1
- package/DeclaredService.d.ts +1 -1
- package/DeclaredService.js.map +1 -1
- package/Service.js.map +1 -1
- package/app/AppInstance.d.ts +3 -28
- package/app/AppInstance.js +104 -96
- package/app/AppInstance.js.map +1 -1
- package/app/gatherConfig.js.map +1 -1
- package/app/logErrors.js.map +1 -1
- package/builtin-services/ApiServiceImpl.d.ts +2 -2
- package/builtin-services/ApiServiceImpl.js +3 -3
- package/builtin-services/ApiServiceImpl.js.map +1 -1
- package/builtin-services/ApplicationContextImpl.js.map +1 -1
- package/builtin-services/ApplicationLifecycleEventService.d.ts +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js +1 -1
- package/builtin-services/ApplicationLifecycleEventService.js.map +1 -1
- package/builtin-services/LocaleServiceImpl.js.map +1 -1
- package/builtin-services/NumberParserServiceImpl.js.map +1 -1
- package/builtin-services/ThemeServiceImpl.js.map +1 -1
- package/builtin-services/index.js.map +1 -1
- package/errors.js.map +1 -1
- package/i18n/AppIntl.js.map +1 -1
- package/i18n/PackageIntl.js.map +1 -1
- package/i18n/pick.js.map +1 -1
- package/metadata/ObservableBox.js.map +1 -1
- package/package.json +9 -9
- package/react-integration/ChakraProvider.d.ts +1 -1
- package/react-integration/ChakraProvider.js.map +1 -1
- package/react-integration/ErrorScreen.js.map +1 -1
- package/react-integration/PackageContext.d.ts +1 -1
- package/react-integration/PackageContext.js.map +1 -1
- package/react-integration/ReactIntegration.d.ts +2 -10
- package/react-integration/ReactIntegration.js +28 -28
- package/react-integration/ReactIntegration.js.map +1 -1
- package/react-integration/hooks.js +6 -10
- package/react-integration/hooks.js.map +1 -1
- package/service-layer/InterfaceSpec.js.map +1 -1
- package/service-layer/PackageRepr.js.map +1 -1
- package/service-layer/ServiceLayer.d.ts +1 -20
- package/service-layer/ServiceLayer.js +39 -39
- package/service-layer/ServiceLayer.js.map +1 -1
- package/service-layer/ServiceLookup.d.ts +1 -3
- package/service-layer/ServiceLookup.js +10 -10
- package/service-layer/ServiceLookup.js.map +1 -1
- package/service-layer/ServiceRepr.d.ts +2 -11
- package/service-layer/ServiceRepr.js +68 -50
- package/service-layer/ServiceRepr.js.map +1 -1
- package/service-layer/verifyDependencies.js +33 -33
- package/service-layer/verifyDependencies.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
# @open-pioneer/runtime
|
|
2
2
|
|
|
3
|
-
## 4.7.0-dev.
|
|
3
|
+
## 4.7.0-dev.20260727091735
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- 278515d: Deprecate the following methods on the `ApplicationContext`: `getLocale`, `setLocale`, `getSupportedLocales()`.
|
|
8
8
|
Use the alternatives provided by the new `LocaleService` instead.
|
|
9
|
-
- e433296: Update Chakra UI to 3.36.
|
|
9
|
+
- e433296: Update Chakra UI to 3.36.1
|
|
10
10
|
- 278515d: Add `runtime.LocaleService` and opt-in reactive locale switching.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
You can opt-in by configuring the property `advanced.enableLiveLocaleChanges` when calling `createCustomElement`.
|
|
13
|
+
Once enabled, locale switches can be done without restarting the application.
|
|
14
|
+
Use `LocaleService.changeLocale` to update the application's locale.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
Also export `parseLocale` and `tryParseLocale` algorithms.
|
|
17
|
+
These can be used to construct a (cleaned up) `Intl.Locale` object from a string.
|
|
18
18
|
|
|
19
19
|
### Patch Changes
|
|
20
20
|
|
|
21
|
+
- 8c277a2: Include service id in deprecation message of 'serviceOptions.intl'.
|
|
22
|
+
- 9d84f1e: Migrated from eslint to oxlint.
|
|
23
|
+
- 78aad9d: Refactor: use private javascript properties instead of typescript private keyword.
|
|
21
24
|
- 7c7e6d1: Refactor equality comparisons using shallow equals from @open-pioneer/core.
|
|
25
|
+
- 8b5c324: Fix 'useIntl' not transporting reactive changes of the intl object in production (e.g. when the locale changes).
|
|
22
26
|
|
|
23
27
|
## 4.6.0
|
|
24
28
|
|
|
@@ -29,15 +33,15 @@
|
|
|
29
33
|
- 05425c6: runtime - Introduce support for ServiceFactories, to provide constructor indirection during service creation
|
|
30
34
|
- 63db133: Support for hot reloading of i18n messages (requires updated vite plugin).
|
|
31
35
|
When i18n messages are updated:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
- React components rerender automatically with new `intl` object returned by `useIntl()`.
|
|
37
|
+
- Services that use the new `serviceOptions.currentIntl` interface also receive a new `intl` object (if they are watching for changes).
|
|
38
|
+
- Services that that still use the deprecated `serviceOptions.intl` interface cause the application to reload instead.
|
|
35
39
|
|
|
36
40
|
### Patch Changes
|
|
37
41
|
|
|
38
42
|
- e6db101: Update to Chakra UI 3.35.0
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
- update to Chakra UI @ 3.35.0, Ark UI @ 5.36.2, Zag JS @ 1.40.0
|
|
44
|
+
- use TooltipProviderProps to override `openDelay` globally (instead of Tooltip snippet)
|
|
41
45
|
|
|
42
46
|
- b092b75: Declare css property `color-scheme` on the application root. This can be used by the browser to render builtin controls differently.
|
|
43
47
|
|
|
@@ -46,9 +50,9 @@
|
|
|
46
50
|
### Minor Changes
|
|
47
51
|
|
|
48
52
|
- 89d743b: Provide `runtime.ThemeService`:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
- Supports switching between color modes `light` and `dark`.
|
|
54
|
+
- Supports changing the chakra theme ("systemConfig") at runtime.
|
|
55
|
+
- Supports reactive access to the preferred (system) color mode.
|
|
52
56
|
|
|
53
57
|
- 89d743b: Support for color modes (light and dark).
|
|
54
58
|
The default color mode remains `light` for backwards compatibility.
|
|
@@ -97,7 +101,7 @@
|
|
|
97
101
|
|
|
98
102
|
- b7a854d: Update dependencies
|
|
99
103
|
- 3881d08: - Update Chakra UI from 3.22.0 to 3.24.2
|
|
100
|
-
|
|
104
|
+
- Update to latest Chakra snippets
|
|
101
105
|
- adf277b: Update dependencies
|
|
102
106
|
|
|
103
107
|
## 4.0.0
|
|
@@ -107,41 +111,41 @@
|
|
|
107
111
|
- 9f074d8: Update to Chakra 3.x
|
|
108
112
|
- 53c92ba: Introduce an advanced option to disable the shadow root.
|
|
109
113
|
|
|
110
|
-
|
|
114
|
+
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.
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
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`.
|
|
117
|
+
- New option `advanced.enableShadowRoot`:
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
```ts
|
|
120
|
+
import { createCustomElement } from "@open-pioneer/runtime";
|
|
121
|
+
import * as appMetadata from "open-pioneer:app";
|
|
122
|
+
import { AppUI } from "./AppUI";
|
|
123
|
+
|
|
124
|
+
const element = createCustomElement({
|
|
125
|
+
component: AppUI,
|
|
126
|
+
appMetadata,
|
|
127
|
+
advanced: {
|
|
128
|
+
enableShadowRoot: false,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
customElements.define("no-shadowroot-sample", element);
|
|
133
|
+
```
|
|
130
134
|
|
|
131
|
-
|
|
135
|
+
- **Breaking:** As a consequence, the `ApplicationContext`'s `getShadowRoot()` method will now return `undefined` if the shadow root is disabled (previous: always a `ShadowRoot`):
|
|
132
136
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
```ts
|
|
138
|
+
const ctx: ApplicationContext = ...; // injected
|
|
139
|
+
const shadowRoot = ctx.getShadowRoot(); // ShadowRoot | undefined
|
|
140
|
+
```
|
|
137
141
|
|
|
138
|
-
|
|
142
|
+
- New method on the `ApplicationContext` that returns _either_ the `ShadowRoot` _or_ the `Document` (if the shadow root is disabled):
|
|
139
143
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
```ts
|
|
145
|
+
const ctx: ApplicationContext = ...; // injected
|
|
146
|
+
const root = ctx.getRoot(); // Document | ShadowRoot
|
|
147
|
+
root.getElementById("...") // always works
|
|
148
|
+
```
|
|
145
149
|
|
|
146
150
|
- 9f074d8: **Breaking:** Rename `theme` option of `createCustomElement()` to `chakraSystemConfig`.
|
|
147
151
|
|
|
@@ -157,54 +161,54 @@
|
|
|
157
161
|
In addition to primitive values, rich text formatting supports react values and custom react tags.
|
|
158
162
|
It always returns a react node, so can only be used in combination with react components.
|
|
159
163
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
164
|
+
_Example with react node as value:_
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
function Example() {
|
|
168
|
+
const intl = useIntl();
|
|
169
|
+
// Given i18n message "Hello, {name}!"
|
|
170
|
+
// replaces 'name' with the given react node:
|
|
171
|
+
const message = intl.formatRichMessage(
|
|
172
|
+
{ id: "foo" },
|
|
173
|
+
{
|
|
174
|
+
name: <FancyUserName />,
|
|
175
|
+
},
|
|
176
|
+
);
|
|
177
|
+
return <Box>{message}</Box>;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
_Example with basic formatting:_
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
function Example() {
|
|
185
|
+
const intl = useIntl();
|
|
186
|
+
// Given i18n message "Hello, <strong>{name}</strong>!"
|
|
187
|
+
// renders with actual <strong> html node:
|
|
188
|
+
return <Box>{intl.formatRichMessage({ id: "foo" }, { name: "User" })}</Box>;
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Note that only a few basic formatting tags are predefined ("b", "strong", "i", "em", "code", "br").
|
|
193
|
+
If you need more advanced tags, you can define your own, see below.
|
|
194
|
+
_Example with custom tag:_
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
function Example() {
|
|
198
|
+
const intl = useIntl();
|
|
199
|
+
// Given i18n message "Open <foo>the door</foo>!",
|
|
200
|
+
// renders 'foo' using the formatter function below:
|
|
201
|
+
const message = intl.formatRichMessage(
|
|
202
|
+
{ id: "foo" },
|
|
203
|
+
{
|
|
204
|
+
foo: (parts) => <FancyTag>{parts}</FancyTag>,
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
return <Box>{message}</Box>;
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
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).
|
|
208
212
|
|
|
209
213
|
### Patch Changes
|
|
210
214
|
|
|
@@ -215,13 +219,13 @@
|
|
|
215
219
|
### Major Changes
|
|
216
220
|
|
|
217
221
|
- 9477e54: Update dependencies
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
- React 19
|
|
223
|
+
- Vite 6
|
|
224
|
+
- FormatJS 3
|
|
225
|
+
- Open Pioneer Build Tools
|
|
226
|
+
- ...
|
|
223
227
|
|
|
224
|
-
|
|
228
|
+
For more details, see https://github.com/open-pioneer/trails-core-packages/pull/81
|
|
225
229
|
|
|
226
230
|
## 2.4.0
|
|
227
231
|
|
|
@@ -262,7 +266,7 @@
|
|
|
262
266
|
### Patch Changes
|
|
263
267
|
|
|
264
268
|
- e945264: Improve error message when metadata is missing (#55)
|
|
265
|
-
|
|
269
|
+
- @open-pioneer/runtime-react-support@1.0.2
|
|
266
270
|
|
|
267
271
|
## 2.1.5
|
|
268
272
|
|
|
@@ -273,16 +277,16 @@
|
|
|
273
277
|
Note that with the current implementation, the application will simply restart with the new locale.
|
|
274
278
|
The application's state will be lost.
|
|
275
279
|
|
|
276
|
-
|
|
280
|
+
Example:
|
|
277
281
|
|
|
278
|
-
|
|
279
|
-
|
|
282
|
+
```ts
|
|
283
|
+
import { ApplicationContext } from "@open-pioneer/runtime";
|
|
280
284
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
285
|
+
const appCtx: ApplicationContext = ...; // injected
|
|
286
|
+
appCtx.setLocale("en-US");
|
|
287
|
+
```
|
|
284
288
|
|
|
285
|
-
|
|
289
|
+
- @open-pioneer/runtime-react-support@1.0.2
|
|
286
290
|
|
|
287
291
|
## 2.1.4
|
|
288
292
|
|
|
@@ -304,7 +308,7 @@
|
|
|
304
308
|
### Patch Changes
|
|
305
309
|
|
|
306
310
|
- f749d96: Add a hint that `DECLARE_SERVICE_INTERFACE` should be imported via `import type`.
|
|
307
|
-
|
|
311
|
+
- @open-pioneer/runtime-react-support@1.0.0
|
|
308
312
|
|
|
309
313
|
## 2.1.0
|
|
310
314
|
|
|
@@ -312,46 +316,46 @@
|
|
|
312
316
|
|
|
313
317
|
- 80cd62d: Improve TypeScript integration for service classes.
|
|
314
318
|
|
|
315
|
-
|
|
316
|
-
|
|
319
|
+
Add a way for a service class to specify its interface name directly.
|
|
320
|
+
Usually services used across package boundaries split their public interface and their implementation such as this:
|
|
317
321
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
322
|
+
```ts
|
|
323
|
+
// Exported from package
|
|
324
|
+
interface MyService extends DeclaredService<"my-package.SomeInterface"> {
|
|
325
|
+
method(): void;
|
|
326
|
+
}
|
|
323
327
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
328
|
+
// In an implementation file, usually private.
|
|
329
|
+
class MyServiceImpl implements MyService {
|
|
330
|
+
method(): void {
|
|
331
|
+
// ...
|
|
329
332
|
}
|
|
330
|
-
|
|
333
|
+
}
|
|
334
|
+
```
|
|
331
335
|
|
|
332
|
-
|
|
333
|
-
|
|
336
|
+
Until now, there was no way for a service class to declare its interface directly.
|
|
337
|
+
This could be convenient within a package, or with a group of tightly coupled packages:
|
|
334
338
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
```ts
|
|
340
|
+
// Error: Type 'MyServiceImpl' has no properties in common with type 'DeclaredService<"my-package.InterfaceName">'.
|
|
341
|
+
class MyServiceImpl implements DeclaredService<"my-package.InterfaceName"> {
|
|
342
|
+
method() {}
|
|
343
|
+
}
|
|
344
|
+
```
|
|
341
345
|
|
|
342
|
-
|
|
346
|
+
From now on, you can write this instead:
|
|
343
347
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
348
|
+
```ts
|
|
349
|
+
class MyServiceImpl {
|
|
350
|
+
// Tells TypeScript which interface name must be used.
|
|
351
|
+
// See documentation of `DECLARE_SERVICE_INTERFACE` for more details.
|
|
352
|
+
declare [DECLARE_SERVICE_INTERFACE]: "my-package.InterfaceName";
|
|
353
|
+
|
|
354
|
+
method(): void {
|
|
355
|
+
// ...
|
|
353
356
|
}
|
|
354
|
-
|
|
357
|
+
}
|
|
358
|
+
```
|
|
355
359
|
|
|
356
360
|
### Patch Changes
|
|
357
361
|
|
|
@@ -371,51 +375,51 @@
|
|
|
371
375
|
- 6f954e3: **Breaking Change**: change how services integrate into TypeScript (fixes #22).
|
|
372
376
|
The old TypeScript integration had unexpected edge cases, see the linked issue.
|
|
373
377
|
|
|
374
|
-
|
|
375
|
-
|
|
378
|
+
NOTE: The changes below have no impact on runtime behavior, but they may trigger TypeScript errors in your code.
|
|
379
|
+
- To register a service's type with TypeScript, one previously used a block such as this:
|
|
376
380
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
381
|
+
```ts
|
|
382
|
+
// OLD! Can be removed
|
|
383
|
+
import "@open-pioneer/runtime";
|
|
384
|
+
declare module "@open-pioneer/runtime" {
|
|
385
|
+
interface ServiceRegistry {
|
|
386
|
+
"http.HttpService": HttpService;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
```
|
|
386
390
|
|
|
387
|
-
|
|
388
|
-
|
|
391
|
+
The new method requires the developer to change the service's declaration.
|
|
392
|
+
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`).
|
|
389
393
|
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
```diff
|
|
395
|
+
+ import { DeclaredService } from "@open-pioneer/runtime";
|
|
392
396
|
|
|
393
|
-
|
|
394
|
-
|
|
397
|
+
- export interface HttpService {
|
|
398
|
+
+ export interface HttpService extends DeclaredService<"http.HttpService"> {
|
|
395
399
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
- import "@open-pioneer/runtime";
|
|
401
|
+
- declare module "@open-pioneer/runtime" {
|
|
402
|
+
- interface ServiceRegistry {
|
|
403
|
+
- "http.HttpService": HttpService;
|
|
404
|
+
- }
|
|
405
|
+
- }
|
|
406
|
+
```
|
|
403
407
|
|
|
404
|
-
|
|
408
|
+
- 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`:
|
|
405
409
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
410
|
+
```diff
|
|
411
|
+
+ import { HttpService } from "@open-pioneer/http";
|
|
412
|
+
- const httpService = useService("http.HttpService");
|
|
413
|
+
+ const httpService = useService<HttpService>("http.HttpService");
|
|
414
|
+
```
|
|
411
415
|
|
|
412
|
-
|
|
416
|
+
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.
|
|
413
417
|
|
|
414
|
-
|
|
418
|
+
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.
|
|
415
419
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
420
|
+
- The types `InterfaceName` and `ServiceType<I>` have been removed. Use explicit service interfaces instead.
|
|
421
|
+
- The interfaces `ServiceRegistry` and `PropertiesRegistry` have been removed as global registration is no longer possible.
|
|
422
|
+
- The type `RawApplicationProperties` has been removed. Use `ApplicationProperties` instead.
|
|
419
423
|
|
|
420
424
|
### Patch Changes
|
|
421
425
|
|
package/CustomElement.js
CHANGED
|
@@ -8,7 +8,7 @@ function createCustomElement(options) {
|
|
|
8
8
|
class PioneerApplication extends HTMLElement {
|
|
9
9
|
#shadowRoot;
|
|
10
10
|
#instance;
|
|
11
|
-
//
|
|
11
|
+
// oxlint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
12
|
#deferredRestart;
|
|
13
13
|
// A Timer
|
|
14
14
|
static get observedAttributes() {
|
package/CustomElement.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport type { ServiceOptions } from \"./Service\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ComponentType } from \"react\";\nimport { type ApiMethods, type ColorModeValue, type ApiExtension } from \"./api\";\nimport { AppInstance } from \"./app\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata } from \"./metadata\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * Options for the {@link createCustomElement} function.\n */\nexport interface CustomElementOptions {\n /**\n * Rendered UI component.\n */\n component?: ComponentType<Record<string, string>>;\n\n /**\n * Application metadata (packages, services etc.).\n * This is usually autogenerated by importing the virtual `\"open-pioneer:app\"` module.\n */\n appMetadata?: ApplicationMetadata;\n\n /**\n * Application defined configuration.\n *\n * This option can be used to override default properties of the application's packages.\n *\n * All instances of the web component will share this static configuration.\n */\n config?: ApplicationConfig;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n\n /**\n * Advanced configuration that alters the behavior of the custom element.\n */\n advanced?: AdvancedCustomElementOptions;\n\n /**\n * Function to provide additional application defined configuration parameters.\n *\n * Compared to {@link config}, this function receives a context object\n * that allows the developer to provide dynamic properties on a per-application instance basis.\n *\n * Parameters returned by this function take precedence over the ones defined by {@link config}.\n */\n resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * The application's host element.\n */\n hostElement: HTMLElement;\n\n /**\n * Defined when the application forcefully restarts with new options.\n */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Application overrides are defined when the is explicitly being restarted with new options.\n *\n * Options set through overrides cannot be overwritten by the `resolveConfig` hook.\n */\nexport interface ApplicationOverrides {\n /**\n * The new application locale.\n */\n locale?: string;\n\n /**\n * The new color mode.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * The new used chakra system config.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n}\n\n/**\n * Runtime application configuration.\n */\nexport interface ApplicationConfig {\n /**\n * Set this value to a locale (BCP-47 string, e.g. `\"en\"`) to set the default message locale of the application.\n *\n * The default behavior is to choose an appropriate locale for the current user based\n * on the browser's settings.\n *\n * This locale should match one of the supported message locales defined by the application's package.\n */\n locale?: string | undefined;\n\n /**\n * The list of locales supported by the application.\n *\n * This allows a further restriction of the locales supported by the application, compared to the ones defined by the application's package.\n * It is not possible to extend the supported locales defined by the package, only to restrict them.\n *\n * If this property is not set, then the application supports all locales defined by the application's package.\n * If the values are not a valid subset of the application package supported locales, then the application will throw an error at startup.\n *\n * An empty array will disable loading of any message bundle.\n */\n supportedLocales?: string[] | undefined;\n\n /**\n * Configures the application's initial color mode.\n *\n * Use `system` to use the user's preferred color mode, derived from the browser or operating system.\n *\n * Default: `light`.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n *\n * NOTE: This setting has priority over {@link CustomElementOptions.chakraSystemConfig}.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n}\n\n/**\n * Allows the application to override default properties in all packages.\n *\n * Properties are typed when the package contains type definitions for them.\n */\nexport interface ApplicationProperties {\n /**\n * Key: the name of the package.\n * Value: A record of configuration properties (key/value pairs).\n *\n * Properties will override default property values in the package.\n */\n [packageName: string]: Record<string, unknown>;\n}\n\n/**\n * The interface implemented by web components produced via {@link createCustomElement}.\n */\nexport interface ApplicationElement extends HTMLElement {\n /**\n * Resolves to the element's API when the application has started.\n *\n * The API exposed by an application can be defined by implementing an {@link ApiExtension}.\n * For more details, open the documentation of the `@open-pioneer/integration` package.\n */\n when(): Promise<ApiMethods>;\n}\n\n/**\n * Advanced configuration that alters the behavior of the custom element.\n *\n * See {@link createCustomElement}.\n */\nexport interface AdvancedCustomElementOptions {\n /**\n * Enables or disables the [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot) inside the application's web component.\n *\n * Default: `true`.\n *\n * 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.\n *\n * 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.\n * In this case, you can disable the shadow root by setting this property to `false`.\n * In general, UI components used by the app (e.g. from Chakra UI) should work just as well when disabling the shadow root.\n * If you notice any problems, please file an issue.\n *\n * If you are developing UI components that are meant to be used in other applications, you should always use a shadow root to\n * ensure that your components work in that setting.\n */\n enableShadowRoot?: boolean;\n\n /**\n * Opts into live locale changes within the running application, without performing a full application restart.\n *\n * Default: `false`.\n *\n * Live locale changes preserve the application's state when the user changes the language.\n * It requires that react components and services in the application handle intl changes correctly (see, for example, {@link ServiceOptions.currentIntl}).\n *\n * Note that this option will become the new default in the next major release,\n * at which point this option will be removed.\n */\n enableLiveLocaleChanges?: boolean;\n}\n\n/**\n * The class returned by a call to {@link createCustomElement}.\n */\nexport interface ApplicationElementConstructor {\n new (): ApplicationElement;\n}\n\n/**\n * Creates a new custom element class (web component) that can be registered within a DOM.\n *\n * @example\n * ```ts\n * import * as appMetadata from \"open-pioneer:app\";\n *\n * const CustomElementClazz = createCustomElement({\n * component: <div>Hello World!</div>,\n * appMetadata\n * });\n * customElements.define(\"sample-element\", CustomElementClazz);\n * ```\n */\nexport function createCustomElement(options: CustomElementOptions): ApplicationElementConstructor {\n class PioneerApplication extends HTMLElement implements ApplicationElement {\n #shadowRoot: ShadowRoot | undefined;\n #instance: AppInstance | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #deferredRestart: any; // A Timer\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n const enableShadowRoot = options.advanced?.enableShadowRoot ?? true;\n if (enableShadowRoot) {\n this.#shadowRoot = this.attachShadow({\n mode: \"open\"\n });\n } else {\n LOG.debug(\"Creating component instance without shadow root\");\n }\n\n if (import.meta.env.DEV) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#instance;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#instance) {\n this.#instance.destroy();\n }\n\n this.#instance = this.#createApplicationInstance();\n this.#instance.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#instance?.destroy();\n this.#instance = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#instance) {\n return Promise.reject(\n new Error(\n ErrorId.NOT_MOUNTED,\n \"Cannot use the application's API because the HTML element has not yet been mounted into the DOM.\"\n )\n );\n }\n\n return this.#instance.whenAPI();\n }\n\n #triggerReload(overrides?: ApplicationOverrides) {\n // Defer the restart operation a tiny bit so calling code does not get surprised by the application's destruction.\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#deferredRestart = setTimeout(() => {\n if (!this.#instance) {\n // disconnectedCallback was called in the meantime\n return;\n }\n\n LOG.debug(\"Restarting application with new options\", overrides);\n this.#instance.destroy();\n this.#instance = this.#createApplicationInstance(overrides);\n this.#instance.start();\n }, 1);\n }\n\n #createApplicationInstance(overrides?: ApplicationOverrides) {\n return new AppInstance({\n rootNode: this.#shadowRoot ?? document,\n hostElement: this,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n });\n }\n }\n return PioneerApplication;\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"CustomElement.js","sources":["CustomElement.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SystemConfig as ChakraSystemConfig } from \"@chakra-ui/react\";\nimport { createLogger, Error } from \"@open-pioneer/core\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { ComponentType } from \"react\";\n// oxlint-disable-next-line @typescript-eslint/no-unused-vars\nimport { type ApiMethods, type ColorModeValue, type ApiExtension } from \"./api\";\nimport { AppInstance } from \"./app\";\nimport { ErrorId } from \"./errors\";\nimport { ApplicationMetadata } from \"./metadata\";\n// oxlint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { ServiceOptions } from \"./Service\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * Options for the {@link createCustomElement} function.\n */\nexport interface CustomElementOptions {\n /**\n * Rendered UI component.\n */\n component?: ComponentType<Record<string, string>>;\n\n /**\n * Application metadata (packages, services etc.).\n * This is usually autogenerated by importing the virtual `\"open-pioneer:app\"` module.\n */\n appMetadata?: ApplicationMetadata;\n\n /**\n * Application defined configuration.\n *\n * This option can be used to override default properties of the application's packages.\n *\n * All instances of the web component will share this static configuration.\n */\n config?: ApplicationConfig;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n\n /**\n * Advanced configuration that alters the behavior of the custom element.\n */\n advanced?: AdvancedCustomElementOptions;\n\n /**\n * Function to provide additional application defined configuration parameters.\n *\n * Compared to {@link config}, this function receives a context object\n * that allows the developer to provide dynamic properties on a per-application instance basis.\n *\n * Parameters returned by this function take precedence over the ones defined by {@link config}.\n */\n resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;\n}\n\n/**\n * A context object that is passed to the `resolveProperties` function.\n */\nexport interface ConfigContext {\n /**\n * The application's host element.\n */\n hostElement: HTMLElement;\n\n /**\n * Defined when the application forcefully restarts with new options.\n */\n overrides: ApplicationOverrides | undefined;\n\n /**\n * Returns an attribute from the application's root node.\n */\n getAttribute(name: string): string | undefined;\n}\n\n/**\n * Application overrides are defined when the is explicitly being restarted with new options.\n *\n * Options set through overrides cannot be overwritten by the `resolveConfig` hook.\n */\nexport interface ApplicationOverrides {\n /**\n * The new application locale.\n */\n locale?: string;\n\n /**\n * The new color mode.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * The new used chakra system config.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n}\n\n/**\n * Runtime application configuration.\n */\nexport interface ApplicationConfig {\n /**\n * Set this value to a locale (BCP-47 string, e.g. `\"en\"`) to set the default message locale of the application.\n *\n * The default behavior is to choose an appropriate locale for the current user based\n * on the browser's settings.\n *\n * This locale should match one of the supported message locales defined by the application's package.\n */\n locale?: string | undefined;\n\n /**\n * The list of locales supported by the application.\n *\n * This allows a further restriction of the locales supported by the application, compared to the ones defined by the application's package.\n * It is not possible to extend the supported locales defined by the package, only to restrict them.\n *\n * If this property is not set, then the application supports all locales defined by the application's package.\n * If the values are not a valid subset of the application package supported locales, then the application will throw an error at startup.\n *\n * An empty array will disable loading of any message bundle.\n */\n supportedLocales?: string[] | undefined;\n\n /**\n * Configures the application's initial color mode.\n *\n * Use `system` to use the user's preferred color mode, derived from the browser or operating system.\n *\n * Default: `light`.\n */\n colorMode?: ColorModeValue | \"system\";\n\n /**\n * Properties specified here will override default properties of the application's packages.\n */\n properties?: ApplicationProperties | undefined;\n\n /**\n * Chakra styled system object.\n *\n * Used to configure chakra's theme.\n *\n * NOTE: This setting has priority over {@link CustomElementOptions.chakraSystemConfig}.\n */\n chakraSystemConfig?: ChakraSystemConfig;\n}\n\n/**\n * Allows the application to override default properties in all packages.\n *\n * Properties are typed when the package contains type definitions for them.\n */\nexport interface ApplicationProperties {\n /**\n * Key: the name of the package.\n * Value: A record of configuration properties (key/value pairs).\n *\n * Properties will override default property values in the package.\n */\n [packageName: string]: Record<string, unknown>;\n}\n\n/**\n * The interface implemented by web components produced via {@link createCustomElement}.\n */\nexport interface ApplicationElement extends HTMLElement {\n /**\n * Resolves to the element's API when the application has started.\n *\n * The API exposed by an application can be defined by implementing an {@link ApiExtension}.\n * For more details, open the documentation of the `@open-pioneer/integration` package.\n */\n when(): Promise<ApiMethods>;\n}\n\n/**\n * Advanced configuration that alters the behavior of the custom element.\n *\n * See {@link createCustomElement}.\n */\nexport interface AdvancedCustomElementOptions {\n /**\n * Enables or disables the [shadow root](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot) inside the application's web component.\n *\n * Default: `true`.\n *\n * 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.\n *\n * 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.\n * In this case, you can disable the shadow root by setting this property to `false`.\n * In general, UI components used by the app (e.g. from Chakra UI) should work just as well when disabling the shadow root.\n * If you notice any problems, please file an issue.\n *\n * If you are developing UI components that are meant to be used in other applications, you should always use a shadow root to\n * ensure that your components work in that setting.\n */\n enableShadowRoot?: boolean;\n\n /**\n * Opts into live locale changes within the running application, without performing a full application restart.\n *\n * Default: `false`.\n *\n * Live locale changes preserve the application's state when the user changes the language.\n * It requires that react components and services in the application handle intl changes correctly (see, for example, {@link ServiceOptions.currentIntl}).\n *\n * Note that this option will become the new default in the next major release,\n * at which point this option will be removed.\n */\n enableLiveLocaleChanges?: boolean;\n}\n\n/**\n * The class returned by a call to {@link createCustomElement}.\n */\nexport interface ApplicationElementConstructor {\n new (): ApplicationElement;\n}\n\n/**\n * Creates a new custom element class (web component) that can be registered within a DOM.\n *\n * @example\n * ```ts\n * import * as appMetadata from \"open-pioneer:app\";\n *\n * const CustomElementClazz = createCustomElement({\n * component: <div>Hello World!</div>,\n * appMetadata\n * });\n * customElements.define(\"sample-element\", CustomElementClazz);\n * ```\n */\nexport function createCustomElement(options: CustomElementOptions): ApplicationElementConstructor {\n class PioneerApplication extends HTMLElement implements ApplicationElement {\n #shadowRoot: ShadowRoot | undefined;\n #instance: AppInstance | undefined;\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n #deferredRestart: any; // A Timer\n\n static get observedAttributes(): string[] {\n return [];\n }\n\n constructor() {\n super();\n\n const enableShadowRoot = options.advanced?.enableShadowRoot ?? true;\n if (enableShadowRoot) {\n this.#shadowRoot = this.attachShadow({\n mode: \"open\"\n });\n } else {\n LOG.debug(\"Creating component instance without shadow root\");\n }\n\n if (import.meta.env.DEV) {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).$inspectElementState = () => this.#instance;\n }\n }\n\n connectedCallback() {\n LOG.debug(\"Launching application\");\n\n if (this.#instance) {\n this.#instance.destroy();\n }\n\n this.#instance = this.#createApplicationInstance();\n this.#instance.start();\n }\n\n disconnectedCallback() {\n LOG.debug(\"Shutting down application\");\n\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#instance?.destroy();\n this.#instance = undefined;\n\n LOG.debug(\"Application destroyed\");\n }\n\n when() {\n if (!this.#instance) {\n return Promise.reject(\n new Error(\n ErrorId.NOT_MOUNTED,\n \"Cannot use the application's API because the HTML element has not yet been mounted into the DOM.\"\n )\n );\n }\n\n return this.#instance.whenAPI();\n }\n\n #triggerReload(overrides?: ApplicationOverrides) {\n // Defer the restart operation a tiny bit so calling code does not get surprised by the application's destruction.\n if (this.#deferredRestart) {\n clearTimeout(this.#deferredRestart);\n }\n this.#deferredRestart = setTimeout(() => {\n if (!this.#instance) {\n // disconnectedCallback was called in the meantime\n return;\n }\n\n LOG.debug(\"Restarting application with new options\", overrides);\n this.#instance.destroy();\n this.#instance = this.#createApplicationInstance(overrides);\n this.#instance.start();\n }, 1);\n }\n\n #createApplicationInstance(overrides?: ApplicationOverrides) {\n return new AppInstance({\n rootNode: this.#shadowRoot ?? document,\n hostElement: this,\n elementOptions: options,\n overrides: overrides,\n restart: this.#triggerReload.bind(this)\n });\n }\n }\n return PioneerApplication;\n}\n"],"names":[],"mappings":";;;;;AAeA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAoO1B,SAAS,oBAAoB,OAAA,EAA8D;AAAA,EAC9F,MAAM,2BAA2B,WAAA,CAA0C;AAAA,IACvE,WAAA;AAAA,IACA,SAAA;AAAA;AAAA,IAGA,gBAAA;AAAA;AAAA,IAEA,WAAW,kBAAA,GAA+B;AACtC,MAAA,OAAO,EAAC;AAAA,IACZ;AAAA,IAEA,WAAA,GAAc;AACV,MAAA,KAAA,EAAM;AAEN,MAAA,MAAM,gBAAA,GAAmB,OAAA,CAAQ,QAAA,EAAU,gBAAA,IAAoB,IAAA;AAC/D,MAAA,IAAI,gBAAA,EAAkB;AAClB,QAAA,IAAA,CAAK,WAAA,GAAc,KAAK,YAAA,CAAa;AAAA,UACjC,IAAA,EAAM;AAAA,SACT,CAAA;AAAA,MACL,CAAA,MAAO;AACH,QAAA,GAAA,CAAI,MAAM,iDAAiD,CAAA;AAAA,MAC/D;AAEA,MAAA,IAAI,MAAA,CAAA,IAAA,CAAY,IAAI,GAAA,EAAK;AAErB,QAAC,IAAA,CAAa,oBAAA,GAAuB,MAAM,IAAA,CAAK,SAAA;AAAA,MACpD;AAAA,IACJ;AAAA,IAEA,iBAAA,GAAoB;AAChB,MAAA,GAAA,CAAI,MAAM,uBAAuB,CAAA;AAEjC,MAAA,IAAI,KAAK,SAAA,EAAW;AAChB,QAAA,IAAA,CAAK,UAAU,OAAA,EAAQ;AAAA,MAC3B;AAEA,MAAA,IAAA,CAAK,SAAA,GAAY,KAAK,0BAAA,EAA2B;AACjD,MAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,IACzB;AAAA,IAEA,oBAAA,GAAuB;AACnB,MAAA,GAAA,CAAI,MAAM,2BAA2B,CAAA;AAErC,MAAA,IAAI,KAAK,gBAAA,EAAkB;AACvB,QAAA,YAAA,CAAa,KAAK,gBAAgB,CAAA;AAAA,MACtC;AACA,MAAA,IAAA,CAAK,WAAW,OAAA,EAAQ;AACxB,MAAA,IAAA,CAAK,SAAA,GAAY,MAAA;AAEjB,MAAA,GAAA,CAAI,MAAM,uBAAuB,CAAA;AAAA,IACrC;AAAA,IAEA,IAAA,GAAO;AACH,MAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AACjB,QAAA,OAAO,OAAA,CAAQ,MAAA;AAAA,UACX,IAAI,KAAA;AAAA,YACA,OAAA,CAAQ,WAAA;AAAA,YACR;AAAA;AACJ,SACJ;AAAA,MACJ;AAEA,MAAA,OAAO,IAAA,CAAK,UAAU,OAAA,EAAQ;AAAA,IAClC;AAAA,IAEA,eAAe,SAAA,EAAkC;AAE7C,MAAA,IAAI,KAAK,gBAAA,EAAkB;AACvB,QAAA,YAAA,CAAa,KAAK,gBAAgB,CAAA;AAAA,MACtC;AACA,MAAA,IAAA,CAAK,gBAAA,GAAmB,WAAW,MAAM;AACrC,QAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AAEjB,UAAA;AAAA,QACJ;AAEA,QAAA,GAAA,CAAI,KAAA,CAAM,2CAA2C,SAAS,CAAA;AAC9D,QAAA,IAAA,CAAK,UAAU,OAAA,EAAQ;AACvB,QAAA,IAAA,CAAK,SAAA,GAAY,IAAA,CAAK,0BAAA,CAA2B,SAAS,CAAA;AAC1D,QAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,MACzB,GAAG,CAAC,CAAA;AAAA,IACR;AAAA,IAEA,2BAA2B,SAAA,EAAkC;AACzD,MAAA,OAAO,IAAI,WAAA,CAAY;AAAA,QACnB,QAAA,EAAU,KAAK,WAAA,IAAe,QAAA;AAAA,QAC9B,WAAA,EAAa,IAAA;AAAA,QACb,cAAA,EAAgB,OAAA;AAAA,QAChB,SAAA;AAAA,QACA,OAAA,EAAS,IAAA,CAAK,cAAA,CAAe,IAAA,CAAK,IAAI;AAAA,OACzC,CAAA;AAAA,IACL;AAAA;AAEJ,EAAA,OAAO,kBAAA;AACX;;;;"}
|
package/DeclaredService.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export { DECLARE_SERVICE_INTERFACE };
|
|
|
63
63
|
* this type will produce the interface name associated with the service type.
|
|
64
64
|
*/
|
|
65
65
|
export type AssociatedInterfaceName<T> = T extends DeclaredService<infer InterfaceName> ? InterfaceName : T extends {
|
|
66
|
-
[DECLARE_SERVICE_INTERFACE]: string & infer InterfaceName;
|
|
66
|
+
[DECLARE_SERVICE_INTERFACE]: string & (infer InterfaceName);
|
|
67
67
|
} ? InterfaceName : never;
|
|
68
68
|
/**
|
|
69
69
|
* This helper type produces the expected `interfaceName` (a string parameter) for the given service type.
|
package/DeclaredService.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeclaredService.js","sources":["DeclaredService.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\ndeclare const INTERNAL_ASSOCIATED_SERVICE_METADATA: unique symbol;\ndeclare const ERROR: unique symbol;\n\n/**\n * Base interface for services that are associated with a well known interface name.\n *\n * By using this base interface, you can ensure that users of your interface use the correct interface name.\n *\n * Note that this interface is a type level marker only.\n * It has no real associated methods or properties and it is not necessary to implement anything\n * to use this interface in a class.\n *\n * @example\n * ```ts\n * // MyLogger should be referenced via \"my-package.Logger\"\n * export interface MyLogger extends DeclaredService<\"my-package.Logger\"> {\n * log(message: string): void;\n * }\n * ```\n *\n * > Note: TypeScript may list the `INTERNAL_ASSOCIATED_SERVICE_METADATA` property\n * > when generating the implementation for an interface extending this type.\n * > You can simply remove the offending line; it is not required (and not possible)\n * > to implement that attribute - it only exists for the compiler.\n */\nexport interface DeclaredService<InterfaceName extends string> {\n /**\n * Internal type-level service metadata.\n *\n * Note: there is no need to implement this symbol attribute.\n * It is optional and only exists for the compiler, never at runtime.\n *\n * @internal\n */\n [INTERNAL_ASSOCIATED_SERVICE_METADATA]?: ServiceMetadata<InterfaceName>;\n}\n\n/**\n * Helper symbol to declare a service's interface name when not using a separate interface.\n *\n * > NOTE: This symbol does not exist at runtime. Declaring a service interface is compile time only!\n * > It should therefore be imported via `import type` (see example below).\n *\n * @example\n *\n * ```ts\n * import { type DECLARE_SERVICE_INTERFACE} from \"@open-pioneer/runtime\";\n *\n * class MyServiceImpl {\n * // Add this line to your class.\n * // It declares (at compile time) that the service class must be used via the given interface name.\n * // Note that the property is not really present at runtime.\n * declare [DECLARE_SERVICE_INTERFACE]: \"my-package.MyInterface\";\n *\n * method(): void {\n * throw new Error(\"Method not implemented.\");\n * }\n * }\n * ```\n */\nconst DECLARE_SERVICE_INTERFACE = Symbol(\"runtime.DECLARE_SERVICE_INTERFACE\");\nexport { DECLARE_SERVICE_INTERFACE };\n\n/**\n * Given a type implementing {@link DeclaredService} or using {@link DECLARE_SERVICE_INTERFACE},\n * this type will produce the interface name associated with the service type.\n */\nexport type AssociatedInterfaceName<T> =\n T extends DeclaredService<infer InterfaceName>\n ? InterfaceName\n : T extends { [DECLARE_SERVICE_INTERFACE]: string & infer InterfaceName }\n ? InterfaceName\n : never;\n\n/**\n * This helper type produces the expected `interfaceName` (a string parameter) for the given service type.\n *\n * 1. If `ServiceType` is `unknown`, it will produce `string` to allow arbitrary parameters.\n * 2. If `ServiceType` implements {@link DeclaredService}, it will enforce the associated interface name.\n * 3. Otherwise, a compile time error is generated.\n */\nexport type InterfaceNameForServiceType<ServiceType> =\n IsUnknown<ServiceType> extends true\n ? string\n : AssociatedInterfaceName<ServiceType> extends never\n ? {\n [ERROR]: \"TypeScript integration was not set up properly for this service. Make sure the service's TypeScript interface extends 'DeclaredService'.\";\n }\n : AssociatedInterfaceName<ServiceType>;\n\n/**\n * @internal\n */\ninterface ServiceMetadata<InterfaceName> {\n interfaceName: InterfaceName;\n}\n\ntype IsUnknown<T> = unknown extends T ? ([T] extends [null] ? false : true) : false;\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeclaredService.js","sources":["DeclaredService.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\ndeclare const INTERNAL_ASSOCIATED_SERVICE_METADATA: unique symbol;\ndeclare const ERROR: unique symbol;\n\n/**\n * Base interface for services that are associated with a well known interface name.\n *\n * By using this base interface, you can ensure that users of your interface use the correct interface name.\n *\n * Note that this interface is a type level marker only.\n * It has no real associated methods or properties and it is not necessary to implement anything\n * to use this interface in a class.\n *\n * @example\n * ```ts\n * // MyLogger should be referenced via \"my-package.Logger\"\n * export interface MyLogger extends DeclaredService<\"my-package.Logger\"> {\n * log(message: string): void;\n * }\n * ```\n *\n * > Note: TypeScript may list the `INTERNAL_ASSOCIATED_SERVICE_METADATA` property\n * > when generating the implementation for an interface extending this type.\n * > You can simply remove the offending line; it is not required (and not possible)\n * > to implement that attribute - it only exists for the compiler.\n */\nexport interface DeclaredService<InterfaceName extends string> {\n /**\n * Internal type-level service metadata.\n *\n * Note: there is no need to implement this symbol attribute.\n * It is optional and only exists for the compiler, never at runtime.\n *\n * @internal\n */\n [INTERNAL_ASSOCIATED_SERVICE_METADATA]?: ServiceMetadata<InterfaceName>;\n}\n\n/**\n * Helper symbol to declare a service's interface name when not using a separate interface.\n *\n * > NOTE: This symbol does not exist at runtime. Declaring a service interface is compile time only!\n * > It should therefore be imported via `import type` (see example below).\n *\n * @example\n *\n * ```ts\n * import { type DECLARE_SERVICE_INTERFACE} from \"@open-pioneer/runtime\";\n *\n * class MyServiceImpl {\n * // Add this line to your class.\n * // It declares (at compile time) that the service class must be used via the given interface name.\n * // Note that the property is not really present at runtime.\n * declare [DECLARE_SERVICE_INTERFACE]: \"my-package.MyInterface\";\n *\n * method(): void {\n * throw new Error(\"Method not implemented.\");\n * }\n * }\n * ```\n */\nconst DECLARE_SERVICE_INTERFACE = Symbol(\"runtime.DECLARE_SERVICE_INTERFACE\");\nexport { DECLARE_SERVICE_INTERFACE };\n\n/**\n * Given a type implementing {@link DeclaredService} or using {@link DECLARE_SERVICE_INTERFACE},\n * this type will produce the interface name associated with the service type.\n */\nexport type AssociatedInterfaceName<T> =\n T extends DeclaredService<infer InterfaceName>\n ? InterfaceName\n : T extends { [DECLARE_SERVICE_INTERFACE]: string & (infer InterfaceName) }\n ? InterfaceName\n : never;\n\n/**\n * This helper type produces the expected `interfaceName` (a string parameter) for the given service type.\n *\n * 1. If `ServiceType` is `unknown`, it will produce `string` to allow arbitrary parameters.\n * 2. If `ServiceType` implements {@link DeclaredService}, it will enforce the associated interface name.\n * 3. Otherwise, a compile time error is generated.\n */\nexport type InterfaceNameForServiceType<ServiceType> =\n IsUnknown<ServiceType> extends true\n ? string\n : AssociatedInterfaceName<ServiceType> extends never\n ? {\n [ERROR]: \"TypeScript integration was not set up properly for this service. Make sure the service's TypeScript interface extends 'DeclaredService'.\";\n }\n : AssociatedInterfaceName<ServiceType>;\n\n/**\n * @internal\n */\ninterface ServiceMetadata<InterfaceName> {\n interfaceName: InterfaceName;\n}\n\ntype IsUnknown<T> = unknown extends T ? ([T] extends [null] ? false : true) : false;\n"],"names":[],"mappings":"AA+DA,MAAM,yBAAA,0BAAmC,mCAAmC;;;;"}
|
package/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sources":["Service.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { PackageIntl } from \"./i18n\";\n\n/** Lifecycle hooks supported by the service interface. */\nexport interface ServiceLifecycleHooks {\n /**\n * Destroys the component.\n * Should clean up all resources used by the component.\n */\n destroy?(): void;\n\n /*\n * Just used so that this interface is not empty.\n * TypeScript would otherwise throw an 'no common properties' error\n * if one tries to implement this interface without providing any\n * lifecycle hooks.\n */\n toString(): string;\n}\n\nexport type Service<Interface extends {} = {}> = ServiceLifecycleHooks & Interface;\n\n/**\n * Represents metadata for an injected reference.\n */\nexport interface ReferenceMeta {\n /**\n * The unique service id of the injected service.\n */\n serviceId: string;\n}\n\n/**\n * Contains metadata about injected references.\n * The key for the reference metadata is the reference's name.\n */\nexport type ReferencesMeta<References extends {}> = {\n //
|
|
1
|
+
{"version":3,"file":"Service.js","sources":["Service.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { PackageIntl } from \"./i18n\";\n\n/** Lifecycle hooks supported by the service interface. */\nexport interface ServiceLifecycleHooks {\n /**\n * Destroys the component.\n * Should clean up all resources used by the component.\n */\n destroy?(): void;\n\n /*\n * Just used so that this interface is not empty.\n * TypeScript would otherwise throw an 'no common properties' error\n * if one tries to implement this interface without providing any\n * lifecycle hooks.\n */\n toString(): string;\n}\n\nexport type Service<Interface extends {} = {}> = ServiceLifecycleHooks & Interface;\n\n/**\n * Represents metadata for an injected reference.\n */\nexport interface ReferenceMeta {\n /**\n * The unique service id of the injected service.\n */\n serviceId: string;\n}\n\n/**\n * Contains metadata about injected references.\n * The key for the reference metadata is the reference's name.\n */\nexport type ReferencesMeta<References extends {}> = {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n [referenceName in keyof References]: References[referenceName] extends any[]\n ? ReferenceMeta[]\n : ReferenceMeta;\n};\n\n/**\n * Options passed to a service's constructor.\n */\nexport type ServiceOptions<References extends {} = {}> = {\n /**\n * References to other services.\n * These are injected by the runtime and match the declared references of the service.\n */\n references: References;\n\n /**\n * Metadata about the injected references.\n * The object contains one entry for every reference injected via `references` (under the same key).\n *\n * If a single service has been injected, `referencesMeta[key]` will be of type {@link ReferenceMeta}.\n * If multiple services have been injected, an array of {@link ReferenceMeta} will be provided instead,\n * where the indices match the order in the injected references array.\n */\n referencesMeta: ReferencesMeta<References>;\n\n /**\n * Configuration properties.\n *\n * Default values are taken from the package's configuration, but these can be overridden\n * by the application.\n */\n properties: Record<string, unknown>;\n\n /**\n * A constant reference to the shared i18n object of the current package.\n *\n * @deprecated use `currentIntl` instead, which is a signal that returns the current i18n object and updates when it changes at runtime. Be aware to implement a watch for yourself\n */\n intl: PackageIntl;\n\n /**\n * A signal that returns the current i18n object of the service's package.\n *\n * The i18n object may change at runtime (for example to implement hot reloading during development,\n * or to implement language changes while the application is running).\n */\n currentIntl: ReadonlyReactive<PackageIntl>;\n};\n\n/**\n * A service constructor returns a service instance when calling `new`.\n */\nexport type ServiceConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): Service<Interface>;\n};\n\n/**\n * A service factory is an object that has a method to create a service instance.\n * The service factory itself can also implement lifecycle hooks, which will be called by the runtime\n * when the factory is destroyed.\n */\nexport type ServiceFactory<Interface extends {} = {}> = {\n /**\n * Method to create a service instance.\n * It is directly called by the runtime after constructing the factory.\n * NOTE: the service.destroy lifecycle hook is not called by the runtime.\n */\n createService(): Interface;\n /**\n * Optional method to destroy a service instance created by this factory.\n * If provided, this method will be called by the runtime when the service instance is destroyed.\n * A factory instance exists per service, this method invocation means that the factory is no longer used by the runtime.\n */\n destroyService?(service: Interface): void;\n};\n\n/**\n * A constructor type for a service factory.\n * The service factory is an object that has a method to create a service instance,\n * this allows for more flexibility in service construction.\n */\nexport type ServiceFactoryConstructor<References extends {} = {}, Interface extends {} = {}> = {\n new (options: ServiceOptions<References>): ServiceFactory<Interface>;\n};\n\n/**\n * Symbol used to detect if a constructor function is a service factory constructor.\n */\nconst IS_SERVICE_FACTORY = Symbol(\"runtime.IS_SERVICE_FACTORY\");\nexport { IS_SERVICE_FACTORY };\n\n/**\n * A service factory constructor must be marked\n * with the `IS_SERVICE_FACTORY` symbol to be recognized by the runtime as such.\n */\nexport type MarkedServiceFactoryConstructor<\n References extends {} = {},\n Interface extends {} = {}\n> = ServiceFactoryConstructor<References, Interface> & {\n [IS_SERVICE_FACTORY]: true;\n};\n\n/**\n * Utility function to mark a constructor as a service factory constructor.\n * @param ctr normal constructor function for a service factory.\n * @returns the same constructor function, but marked with the `IS_SERVICE_FACTORY` symbol so that the runtime recognizes it as a service factory constructor.\n */\nexport function defineServiceFactory(\n ctr: ServiceFactoryConstructor\n): MarkedServiceFactoryConstructor {\n const markedCtr = ctr as MarkedServiceFactoryConstructor;\n markedCtr[IS_SERVICE_FACTORY] = true;\n return markedCtr;\n}\n"],"names":[],"mappings":"AAiIA,MAAM,kBAAA,0BAA4B,4BAA4B;AAmBvD,SAAS,qBACZ,GAAA,EAC+B;AAC/B,EAAA,MAAM,SAAA,GAAY,GAAA;AAClB,EAAA,SAAA,CAAU,kBAAkB,CAAA,GAAI,IAAA;AAChC,EAAA,OAAO,SAAA;AACX;;;;"}
|