Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
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 Nov 5, 2024
0b21ee6
Further ADR improvement
david-monichi Nov 5, 2024
5344448
Added missing link
david-monichi Nov 5, 2024
168a1c2
Improved ADR
david-monichi Nov 5, 2024
e7eb37d
Create ADR 0004 for further clarification
david-monichi Nov 5, 2024
abdf106
removed svelte dependency
david-monichi Nov 19, 2024
f9d42a4
Updated status and agreed procedure
david-monichi Nov 19, 2024
78ed19c
Updated status
david-monichi Nov 19, 2024
b886038
Merge branch 'openscd:main' into main
david-monichi Nov 19, 2024
21f6a2b
Merge branch 'openscd:main' into main
david-monichi Feb 18, 2025
47237da
feat: add wizarding V3 support
senzacionale Feb 24, 2025
3de30f5
Merge branch 'main' into feat/wizarding-v3
senzacionale Feb 25, 2025
d69a174
Merge branch 'main' into feat/wizarding-v3
senzacionale Feb 27, 2025
45d2499
Merge branch 'main' into feat/wizarding-v3
senzacionale Mar 1, 2025
4b331cd
Merge branch 'main' into feat/wizarding-v3
senzacionale Mar 5, 2025
121d221
Merge branch 'openscd:main' into feat/wizarding-v3
senzacionale Mar 27, 2025
1de3a8d
feat: remove external dependencies
senzacionale Mar 27, 2025
ddce08b
Merge branch 'main' into feat/wizarding-v3
senzacionale Mar 30, 2025
cefe9b3
Merge branch 'main' into feat/wizarding-v3
senzacionale Apr 3, 2025
0abb92c
Merge branch 'main' into feat/wizarding-v3
senzacionale Apr 24, 2025
ad840f1
Merge branch 'main' into feat/wizarding-v3
senzacionale May 22, 2025
027d7e6
Merge branch 'main' into feat/wizarding-v3
senzacionale Jun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/external-plugins/oscd-publisher
Submodule oscd-publisher deleted from afb25a
1 change: 0 additions & 1 deletion packages/external-plugins/oscd-subscriber-later-binding
117 changes: 99 additions & 18 deletions packages/openscd/src/Wizarding.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,116 @@
import { html, state, TemplateResult, query } from 'lit-element';
import { html, query, state, TemplateResult } from 'lit-element';
import {
ifImplemented,
LitElementConstructor,
Mixin,
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. */
export type WizardingElement = Mixin<typeof Wizarding>;

export function Wizarding<TBase extends LitElementConstructor>(Base: TBase) {
class WizardingElement extends Base {
/** FIFO queue of [[`Wizard`]]s to display. */
/** FIFO queue of Wizard to display. */
@state()
workflow: WizardFactory[] = [];

@query('wizard-dialog') wizardUI!: WizardDialog;
@query('wizard-dialog')
wizardUI!: WizardDialog;

private onWizard(e: WizardEvent) {
const { wizard, subwizard, v3Wizard } = e.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) {
subwizard ? this.workflow.unshift(wizard) : 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.warn('[WizardingElement] No wizard provided, skipping...');
}
this.updateWizards();
}

private onCloseWizard() {
this.workflow.shift();
this.updateWizards();
}

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 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 +92 to +95
Copy link
Member

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 :)

}

/*constructor(...args: any[]) {
super(...args);

this.addEventListener('wizard', this.onWizard as EventListener);
this.addEventListener('oscd-edit-wizard-request', (e: Event) =>
this.onWizardRequest(e as CustomEvent<EditWizardRequest>)
);
this.addEventListener('oscd-create-wizard-request', (e: Event) =>
this.onWizardRequest(e as CustomEvent<CreateWizardRequest>)
);
this.addEventListener('oscd-close-wizard', () => this.onCloseWizard());
this.addEventListener('editor-action', () =>
this.wizardUI?.requestUpdate()
);
}*/

constructor(...args: any[]) {
super(...args);

Expand All @@ -47,8 +121,15 @@ export function Wizarding<TBase extends LitElementConstructor>(Base: TBase) {
}

render(): TemplateResult {
return html`${ifImplemented(super.render())}
<wizard-dialog .wizard=${this.workflow[0]?.() ?? []}></wizard-dialog>`;
return html`
${ifImplemented(super.render())}
<wizard-dialog
.wizard=${this.workflow[0]?.() ?? []}
@oscd-edit-wizard-request=${this.onWizardRequest}
@oscd-close-wizard=${this.onCloseWizard}
>
</wizard-dialog>
`;
}
}

Expand Down
117 changes: 93 additions & 24 deletions packages/openscd/src/addons/Wizards.ts
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
Copy link
Member

Choose a reason for hiding this comment

The 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>
`;
}
}
1 change: 1 addition & 0 deletions packages/openscd/src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export type WizardFactory = () => Wizard;
export interface WizardDetail {
wizard: WizardFactory | null;
subwizard?: boolean;
v3Wizard?: unknown;
}
export type WizardEvent = CustomEvent<WizardDetail>;
export function newWizardEvent(
Expand Down
45 changes: 45 additions & 0 deletions packages/openscd/src/scl-wizarding.ts
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 },
});
}