forked from openscd/open-scd
-
Notifications
You must be signed in to change notification settings - Fork 4
chore: sync upstream 0.42.0 #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c457cf
feat: Add oscd api with plugin state (#1696)
clepski 0831fa4
fix(Import IED): Fix order of edits (#1698)
clepski 9ea65ec
doc: Explain that node version 18 is needed, not version 20 (#1663)
Tamriel cd3b39a
fix: Connected AP wizard element order (#1703)
clepski 4311e94
chore(main): release 0.42.0 (#1697)
github-actions[bot] fb90603
Merge remote-tracking branch 'upstream/main' into chore/sync-upstream…
noraeb 0083cf9
chore: update package.json version to 0.42.0-1
noraeb be8d5df
chore: copy changes to compas-open-scd/open-scd.ts
noraeb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"packages/openscd": "0.37.0", | ||
"packages/core": "0.1.4", | ||
".": "0.41.0" | ||
".": "0.42.0" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# OSCD API | ||
|
||
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. | ||
|
||
``` | ||
import { OscdApi } from '@openscd/core'; | ||
|
||
class SomePlugin extends LitElement { | ||
|
||
@property() | ||
oscdApi: OscdApi | null = null; | ||
|
||
connectedCallback() { | ||
const pluginState = this.oscdApi?.pluginState.getState(); | ||
|
||
... | ||
} | ||
|
||
disconnectedCallback() { | ||
this.oscdApi?.pluginState.setState(someStateObject); | ||
} | ||
} | ||
``` | ||
|
||
⚠️ 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. | ||
|
||
## Plugin state API | ||
|
||
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. | ||
|
||
``` | ||
interface PluginStateApi { | ||
setState(state: PluginState | null): void; | ||
|
||
getState(): PluginState | null; | ||
|
||
updateState(partialState: Partial<PluginState>): void | ||
} | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { PluginStateApi } from './plugin-state-api.js'; | ||
|
||
export class OscdApi { | ||
public pluginState: PluginStateApi; | ||
|
||
constructor(pluginTag: string) { | ||
this.pluginState = new PluginStateApi(pluginTag); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
type PluginState = { | ||
[key: string]: unknown | ||
} | ||
|
||
export class PluginStateApi { | ||
private static state: { [tag: string]: PluginState | null } = {}; | ||
private pluginTag: string; | ||
|
||
constructor(tag: string) { | ||
this.pluginTag = tag; | ||
} | ||
|
||
public setState(state: PluginState | null): void { | ||
this.setPluginState(state); | ||
} | ||
|
||
public getState(): PluginState | null { | ||
return this.getPluginState(); | ||
} | ||
|
||
public updateState(partialState: Partial<PluginState>): void { | ||
const pluginState = this.getPluginState(); | ||
const patchedState = { | ||
...pluginState, | ||
...partialState | ||
}; | ||
this.setPluginState(patchedState); | ||
} | ||
|
||
private setPluginState(state: PluginState | null): void { | ||
PluginStateApi.state[this.pluginTag] = state; | ||
} | ||
|
||
private getPluginState(): PluginState | null { | ||
return PluginStateApi.state[this.pluginTag] ?? null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,3 +66,5 @@ export function crossProduct<T>(...arrays: T[][]): T[][] { | |
[[]] | ||
); | ||
} | ||
|
||
export { OscdApi } from './api/api.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.