Skip to content

Commit

Permalink
feat: Convert open energy edit events
Browse files Browse the repository at this point in the history
  • Loading branch information
clepski committed Nov 18, 2024
1 parent 9c8380f commit 26c4420
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/openscd/src/addons/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ export class OscdEditor extends LitElement {
}

async handleEditEvent(event: EditEvent) {
/**
* This is a compatibility fix for plugins based on open enegery tools edit events
* beause their edit event look slightly different,
* see https://github.com/OpenEnergyTools/open-scd-core/blob/main/foundation/edit-event-v1.ts for details
*/
if (isOpenEnergyEditEvent(event)) {
event = convertOpenEnergyEditEventToEditEvent(event);
}

const edit = event.detail.edit;
const undoEdit = handleEdit(edit);

Expand Down Expand Up @@ -244,4 +253,14 @@ function handleRemove({ node }: Remove): Insert | [] {
reference,
};
return [];
}
}

function isOpenEnergyEditEvent(event: CustomEvent<unknown>): boolean {
const eventDetail = event.detail as Edit;
return isComplex(eventDetail) || isInsert(eventDetail) || isUpdate(eventDetail) || isRemove(eventDetail);
}

function convertOpenEnergyEditEventToEditEvent(event: CustomEvent<unknown>): EditEvent {
const eventDetail = event.detail as Edit;
return newEditEvent(eventDetail);
}

0 comments on commit 26c4420

Please sign in to comment.