This repository was archived by the owner on Nov 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Integrate Wizarding API V3 from OpenEnergyTools to OpenSCD #1630
Open
david-monichi
wants to merge
22
commits into
openscd:main
Choose a base branch
from
david-monichi:feat/wizarding-v3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−44
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
67d707b
Create 0003-extract-plugins.md
david-monichi 0b21ee6
Further ADR improvement
david-monichi 5344448
Added missing link
david-monichi 168a1c2
Improved ADR
david-monichi e7eb37d
Create ADR 0004 for further clarification
david-monichi abdf106
removed svelte dependency
david-monichi f9d42a4
Updated status and agreed procedure
david-monichi 78ed19c
Updated status
david-monichi b886038
Merge branch 'openscd:main' into main
david-monichi 21f6a2b
Merge branch 'openscd:main' into main
david-monichi 47237da
feat: add wizarding V3 support
senzacionale 3de30f5
Merge branch 'main' into feat/wizarding-v3
senzacionale d69a174
Merge branch 'main' into feat/wizarding-v3
senzacionale 45d2499
Merge branch 'main' into feat/wizarding-v3
senzacionale 4b331cd
Merge branch 'main' into feat/wizarding-v3
senzacionale 121d221
Merge branch 'openscd:main' into feat/wizarding-v3
senzacionale 1de3a8d
feat: remove external dependencies
senzacionale ddce08b
Merge branch 'main' into feat/wizarding-v3
senzacionale cefe9b3
Merge branch 'main' into feat/wizarding-v3
senzacionale 0abb92c
Merge branch 'main' into feat/wizarding-v3
senzacionale ad840f1
Merge branch 'main' into feat/wizarding-v3
senzacionale 027d7e6
Merge branch 'main' into feat/wizarding-v3
senzacionale 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
Submodule oscd-publisher
deleted from
afb25a
Submodule oscd-subscriber-later-binding
deleted from
8ad609
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 |
|---|---|---|
| @@ -1,58 +1,127 @@ | ||
| import { | ||
| html, | ||
| state, | ||
| TemplateResult, | ||
| query, | ||
| customElement, | ||
| html, | ||
| LitElement, | ||
| property, | ||
| query, | ||
| state, | ||
| TemplateResult, | ||
| } from 'lit-element'; | ||
| import { WizardEvent, WizardFactory } from '../foundation.js'; | ||
|
|
||
| import '../wizard-dialog.js'; | ||
| import { WizardDialog } from '../wizard-dialog.js'; | ||
| import { CreateWizardRequest, EditWizardRequest } from '../scl-wizarding.js'; | ||
|
|
||
| function adaptV3Wizard(v3Def: unknown): WizardFactory | null { | ||
| const v3 = v3Def as { | ||
| steps: Array<{ | ||
| title: string; | ||
| render: () => TemplateResult; | ||
| }>; | ||
| }; | ||
| if (!v3?.steps?.length) return null; | ||
|
|
||
| return () => | ||
| v3.steps.map(step => ({ | ||
| title: step.title, | ||
| content: [step.render()], | ||
| actions: [ | ||
| { | ||
| label: 'Close', | ||
| icon: 'close', | ||
| action: () => [], | ||
| }, | ||
| ], | ||
| })); | ||
| } | ||
|
|
||
| /** `LitElement` mixin that adds a `workflow` property which [[`Wizard`]]s are | ||
| * queued onto on incoming [[`WizardEvent`]]s, first come first displayed. */ | ||
| @customElement('oscd-wizards') | ||
| export class OscdWizards extends LitElement { | ||
| @property({ | ||
| type: Object, | ||
| }) | ||
| @property({ type: Object }) | ||
| host!: HTMLElement; | ||
|
|
||
| /** FIFO queue of [[`Wizard`]]s to display. */ | ||
| /** FIFO queue of WizardFactories to display */ | ||
| @state() | ||
| workflow: WizardFactory[] = []; | ||
|
|
||
| @query('wizard-dialog') wizardUI!: WizardDialog; | ||
| @query('wizard-dialog') | ||
| wizardUI!: WizardDialog; | ||
|
|
||
| private onWizard(we: WizardEvent) { | ||
| const wizard = we.detail.wizard; | ||
| if (wizard === null) this.workflow.shift(); | ||
| else if (we.detail.subwizard) this.workflow.unshift(wizard); | ||
| else this.workflow.push(wizard); | ||
| private onWizard(event: WizardEvent) { | ||
| const { wizard, subwizard, v3Wizard } = event.detail; | ||
| if (v3Wizard) { | ||
| const adapted = adaptV3Wizard(v3Wizard); | ||
| if (adapted === null) { | ||
| this.workflow.shift(); | ||
| } else if (subwizard) { | ||
| this.workflow.unshift(adapted); | ||
| } else { | ||
| this.workflow.push(adapted); | ||
| } | ||
| } else if (wizard === null) { | ||
| this.workflow.shift(); | ||
| } else if (wizard) { | ||
| if (subwizard) { | ||
| this.workflow.unshift(wizard); | ||
| } else { | ||
| this.workflow.push(wizard); | ||
| } | ||
| } | ||
|
|
||
| this.updateWizards(); | ||
| } | ||
|
|
||
| private onWizardRequest( | ||
| e: CustomEvent<EditWizardRequest | CreateWizardRequest> | ||
| ) { | ||
| const detail = e.detail as (EditWizardRequest | CreateWizardRequest) & { | ||
| wizard?: WizardFactory; | ||
| }; | ||
| if ('wizard' in detail && detail.wizard) { | ||
| const wf = detail.wizard as WizardFactory; | ||
| detail.subWizard ? this.workflow.unshift(wf) : this.workflow.push(wf); | ||
| } else { | ||
| console.log('[oscd-wizards] No wizard provided, skipping...'); | ||
| } | ||
|
|
||
| this.updateWizards(); | ||
| } | ||
|
|
||
| private onCloseWizard() { | ||
| this.workflow.shift(); | ||
| this.updateWizards(); | ||
| } | ||
|
|
||
| private updateWizards() { | ||
| this.requestUpdate('workflow'); | ||
| this.updateComplete.then(() => | ||
| this.wizardUI.updateComplete.then(() => | ||
| this.wizardUI.dialog?.updateComplete.then(() => | ||
| this.wizardUI.dialog?.focus() | ||
| ) | ||
| ) | ||
| ); | ||
| this.updateComplete | ||
| .then(() => this.wizardUI.updateComplete) | ||
| .then(() => this.wizardUI.dialog?.updateComplete) | ||
| .then(() => this.wizardUI.dialog?.focus()); | ||
|
Comment on lines
+99
to
+102
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, thank you for the clean up :) |
||
| } | ||
|
|
||
| connectedCallback() { | ||
| super.connectedCallback(); | ||
|
|
||
| this.host.addEventListener('wizard', this.onWizard.bind(this)); | ||
| this.host.addEventListener('oscd-edit-wizard-request', (e: Event) => | ||
| this.onWizardRequest(e as CustomEvent<EditWizardRequest>) | ||
| ); | ||
| this.host.addEventListener('oscd-create-wizard-request', (e: Event) => | ||
| this.onWizardRequest(e as CustomEvent<CreateWizardRequest>) | ||
| ); | ||
| this.host.addEventListener('oscd-close-wizard', () => this.onCloseWizard()); | ||
| this.host.addEventListener('editor-action', () => | ||
| this.wizardUI.requestUpdate() | ||
| ); | ||
| } | ||
|
|
||
| render(): TemplateResult { | ||
| return html`<slot></slot> | ||
| <wizard-dialog .wizard=${this.workflow[0]?.() ?? []}></wizard-dialog>`; | ||
| return html` | ||
| <slot></slot> | ||
| <wizard-dialog .wizard=${this.workflow[0]?.() ?? []}></wizard-dialog> | ||
| `; | ||
| } | ||
| } | ||
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,45 @@ | ||
| interface WizardRequestBase { | ||
| subWizard?: boolean; | ||
| } | ||
| export interface EditWizardRequest extends WizardRequestBase { | ||
| element: Element; | ||
| } | ||
| export interface CreateWizardRequest extends WizardRequestBase { | ||
| parent: Element; | ||
| tagName: string; | ||
| } | ||
|
|
||
| type CreateWizardEvent = CustomEvent<CreateWizardRequest>; | ||
| type EditWizardEvent = CustomEvent<EditWizardRequest>; | ||
|
|
||
| export function newCreateWizardEvent( | ||
| parent: Element, | ||
| tagName: string, | ||
| subWizard?: boolean, | ||
| eventInitDict?: CustomEventInit<Partial<CreateWizardRequest>> | ||
| ): CreateWizardEvent { | ||
| return new CustomEvent<CreateWizardRequest>('oscd-create-wizard-request', { | ||
| bubbles: true, | ||
| composed: true, | ||
| ...eventInitDict, | ||
| detail: { | ||
| parent, | ||
| tagName, | ||
| subWizard, | ||
| ...eventInitDict?.detail, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export function newEditWizardEvent( | ||
| element: Element, | ||
| subWizard?: boolean, | ||
| eventInitDict?: CustomEventInit<Partial<EditWizardRequest>> | ||
| ): EditWizardEvent { | ||
| return new CustomEvent<EditWizardRequest>('oscd-edit-wizard-request', { | ||
| bubbles: true, | ||
| composed: true, | ||
| ...eventInitDict, | ||
| detail: { element, subWizard, ...eventInitDict?.detail }, | ||
| }); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the small cleanups too :)