Skip to content

Commit 8530886

Browse files
authored
Merge pull request #415 from com-pas/chore/sync-upstream-0.42.0
chore: sync upstream 0.42.0
2 parents c928b84 + be8d5df commit 8530886

File tree

17 files changed

+753
-74
lines changed

17 files changed

+753
-74
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"packages/openscd": "0.37.0",
33
"packages/core": "0.1.4",
4-
".": "0.41.0"
4+
".": "0.42.0"
55
}

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [0.42.0](https://github.com/openscd/open-scd/compare/v0.41.0...v0.42.0) (2025-09-15)
4+
5+
6+
### Features
7+
8+
* Add oscd api with plugin state ([#1696](https://github.com/openscd/open-scd/issues/1696)) ([1c457cf](https://github.com/openscd/open-scd/commit/1c457cf02a404a61b7ff09553223091bc5edd1f6))
9+
10+
11+
### Bug Fixes
12+
13+
* Connected AP wizard element order ([#1703](https://github.com/openscd/open-scd/issues/1703)) ([cd3b39a](https://github.com/openscd/open-scd/commit/cd3b39ad45b6ddfc5d8c3641a5c120dd95bb5dd6))
14+
* **Import IED:** Fix order of edits ([#1698](https://github.com/openscd/open-scd/issues/1698)) ([0831fa4](https://github.com/openscd/open-scd/commit/0831fa4e4cde55a21c261b1b4b8b5994868509b0))
15+
* Settings addon translations ([cd3b39a](https://github.com/openscd/open-scd/commit/cd3b39ad45b6ddfc5d8c3641a5c120dd95bb5dd6))
16+
317
## [0.41.0](https://github.com/openscd/open-scd/compare/v0.40.0...v0.41.0) (2025-08-04)
418

519

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ To develop, follow these steps :
3737
1. Install [↗ Node.js](https://nodejs.org/en/download/package-manager)
3838

3939
> [!IMPORTANT]
40-
> `Node.js` version should be set to `20.x.x` as there are incompatibilities with higher version
40+
> `Node.js` version should be set to `18.x.x` as there are incompatibilities with higher version
4141
4242
2. Run `npm ci` in OpenSCD's root folder.
4343

@@ -355,4 +355,4 @@ class MyClass {
355355
private foo = 1;
356356
private bar() {}
357357
}
358-
```
358+
```

docs/core-api/oscd-api.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# OSCD API
2+
3+
Open scd passes an API object as the property `oscdApi` to every plugin. At the moment the API only includes the plugin state API. Here is an example usage in a Lit based plugin.
4+
5+
```
6+
import { OscdApi } from '@openscd/core';
7+
8+
class SomePlugin extends LitElement {
9+
10+
@property()
11+
oscdApi: OscdApi | null = null;
12+
13+
connectedCallback() {
14+
const pluginState = this.oscdApi?.pluginState.getState();
15+
16+
...
17+
}
18+
19+
disconnectedCallback() {
20+
this.oscdApi?.pluginState.setState(someStateObject);
21+
}
22+
}
23+
```
24+
25+
⚠️ Be aware that not every open scd distribution provides this API, so your plugin should have a null check if you want it to be compatible with other distributions.
26+
27+
## Plugin state API
28+
29+
The plugin state API stores an arbitrary object as your plugin's state in memory. Be aware that this state is only persisted during the open scd distribution's runtime and will not be stored in local storage for example.
30+
31+
```
32+
interface PluginStateApi {
33+
setState(state: PluginState | null): void;
34+
35+
getState(): PluginState | null;
36+
37+
updateState(partialState: Partial<PluginState>): void
38+
}
39+
```
40+

packages/compas-open-scd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "compas-open-scd",
3-
"version": "0.41.0-5",
3+
"version": "0.42.0-1",
44
"repository": "https://github.com/openscd/open-scd.git",
55
"description": "OpenSCD CoMPAS Edition",
66
"directory": "packages/compas-open-scd",

packages/compas-open-scd/src/open-scd.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { ActionDetail } from '@material/mwc-list';
3434

3535
import { officialPlugins as builtinPlugins } from '../public/js/plugins.js';
3636
import type { PluginSet, Plugin as CorePlugin } from '@openscd/core';
37+
import { OscdApi } from '@openscd/core';
3738
import { classMap } from 'lit-html/directives/class-map.js';
3839
import {
3940
newConfigurePluginEvent,
@@ -471,6 +472,7 @@ export class OpenSCD extends LitElement {
471472
.nsdoc=${this.nsdoc}
472473
.docs=${this.docs}
473474
.locale=${this.locale}
475+
.oscdApi=${new OscdApi(tag)}
474476
.compasApi=${this.compasApi}
475477
class="${classMap({
476478
plugin: true,

packages/core/api/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PluginStateApi } from './plugin-state-api.js';
2+
3+
export class OscdApi {
4+
public pluginState: PluginStateApi;
5+
6+
constructor(pluginTag: string) {
7+
this.pluginState = new PluginStateApi(pluginTag);
8+
}
9+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
type PluginState = {
2+
[key: string]: unknown
3+
}
4+
5+
export class PluginStateApi {
6+
private static state: { [tag: string]: PluginState | null } = {};
7+
private pluginTag: string;
8+
9+
constructor(tag: string) {
10+
this.pluginTag = tag;
11+
}
12+
13+
public setState(state: PluginState | null): void {
14+
this.setPluginState(state);
15+
}
16+
17+
public getState(): PluginState | null {
18+
return this.getPluginState();
19+
}
20+
21+
public updateState(partialState: Partial<PluginState>): void {
22+
const pluginState = this.getPluginState();
23+
const patchedState = {
24+
...pluginState,
25+
...partialState
26+
};
27+
this.setPluginState(patchedState);
28+
}
29+
30+
private setPluginState(state: PluginState | null): void {
31+
PluginStateApi.state[this.pluginTag] = state;
32+
}
33+
34+
private getPluginState(): PluginState | null {
35+
return PluginStateApi.state[this.pluginTag] ?? null;
36+
}
37+
}

packages/core/foundation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ export function crossProduct<T>(...arrays: T[][]): T[][] {
6666
[[]]
6767
);
6868
}
69+
70+
export { OscdApi } from './api/api.js';

packages/openscd/src/addons/Settings.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
LitElement,
88
css,
99
} from 'lit-element';
10-
import { get, registerTranslateConfig, Strings, use } from 'lit-translate';
10+
import { get, translate, registerTranslateConfig, Strings, use } from 'lit-translate';
1111

1212
import '@material/mwc-button';
1313
import '@material/mwc-dialog';
@@ -204,7 +204,7 @@ export class OscdSettings extends LitElement {
204204
@change="${(evt: Event) => this.uploadNsdocFile(evt)}}"
205205
/>
206206
<mwc-button
207-
label="${get('settings.selectFileButton')}"
207+
label="${translate('settings.selectFileButton')}"
208208
id="selectFileButton"
209209
@click=${() => {
210210
const input = <HTMLInputElement | null>(
@@ -360,39 +360,39 @@ export class OscdSettings extends LitElement {
360360
render(): TemplateResult {
361361
return html`<mwc-dialog
362362
id="settings"
363-
heading="${get('settings.title')}"
363+
heading="${translate('settings.title')}"
364364
@closing=${this.onClosing}
365365
>
366366
<form>
367367
<mwc-select
368368
fixedMenuPosition
369369
id="language"
370370
icon="language"
371-
label="${get('settings.language')}"
371+
label="${translate('settings.language')}"
372372
>
373373
${Object.keys(this.languageConfig.languages).map(
374374
lang =>
375375
html`<mwc-list-item
376376
graphic="icon"
377377
value="${lang}"
378378
?selected=${lang === this.settings.language}
379-
>${get(`settings.languages.${lang}`)}</mwc-list-item
379+
>${translate(`settings.languages.${lang}`)}</mwc-list-item
380380
>`
381381
)}
382382
</mwc-select>
383-
<mwc-formfield label="${get('settings.dark')}">
383+
<mwc-formfield label="${translate('settings.dark')}">
384384
<mwc-switch
385385
id="dark"
386386
?checked=${this.settings.theme === 'dark'}
387387
></mwc-switch>
388388
</mwc-formfield>
389-
<mwc-formfield label="${get('settings.mode')}">
389+
<mwc-formfield label="${translate('settings.mode')}">
390390
<mwc-switch
391391
id="mode"
392392
?checked=${this.settings.mode === 'pro'}
393393
></mwc-switch>
394394
</mwc-formfield>
395-
<mwc-formfield label="${get('settings.showieds')}">
395+
<mwc-formfield label="${translate('settings.showieds')}">
396396
<mwc-switch
397397
id="showieds"
398398
?checked=${this.settings.showieds === 'on'}
@@ -402,7 +402,7 @@ export class OscdSettings extends LitElement {
402402
<wizard-divider></wizard-divider>
403403
${this.nsdUploadButton
404404
? html`<section id="shownsdbutton">
405-
<h3>${get('settings.loadNsdTranslations')}</h3>
405+
<h3>${translate('settings.loadNsdTranslations')}</h3>
406406
${this.renderFileSelect()}
407407
</section>`
408408
: html``}
@@ -413,22 +413,22 @@ export class OscdSettings extends LitElement {
413413
${this.renderNsdocItem('IEC 61850-8-1')}
414414
</mwc-list>
415415
<mwc-button slot="secondaryAction" dialogAction="close">
416-
${get('cancel')}
416+
${translate('cancel')}
417417
</mwc-button>
418418
<mwc-button
419419
style="--mdc-theme-primary: var(--mdc-theme-error)"
420420
slot="secondaryAction"
421421
dialogAction="reset"
422422
>
423-
${get('reset')}
423+
${translate('reset')}
424424
</mwc-button>
425425
<mwc-button
426426
icon="save"
427427
trailingIcon
428428
slot="primaryAction"
429429
dialogAction="save"
430430
>
431-
${get('save')}
431+
${translate('save')}
432432
</mwc-button>
433433
</mwc-dialog>
434434
<slot></slot>

0 commit comments

Comments
 (0)