Skip to content

Commit 97b4608

Browse files
committed
chore: switch from editor.commit to dispatch newEditEventV2
Release-As: 0.0.1
1 parent feecf3b commit 97b4608

File tree

4 files changed

+47
-82
lines changed

4 files changed

+47
-82
lines changed

components/OscdEditorTemplateTextfield.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { property, query, state } from 'lit/decorators.js';
33

44
import { MdSwitch } from '@scopedelement/material-web/switch/MdSwtich.js';
55
import { MdMenu } from '@scopedelement/material-web/menu/MdMenu.js';
6-
import { MdOutlinedButton } from '@scopedelement/material-web/button/MdOutlinedButton.js';
76
import { MdIconButton } from '@scopedelement/material-web/iconbutton/MdIconButton.js';
87
import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';
98
import { MdOutlinedField } from '@scopedelement/material-web/field/MdOutlinedField.js';
@@ -15,7 +14,6 @@ export class OscdEditorTemplateTextfield extends ScopedElementsMixin(
1514
) {
1615
static scopedElements = {
1716
'md-outlined-field': MdOutlinedField,
18-
'md-button': MdOutlinedButton,
1917
'md-icon-button': MdIconButton,
2018
'md-menu': MdMenu,
2119
'md-switch': MdSwitch,

custom-elements.json

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@
4040
"text": "object"
4141
},
4242
"static": true,
43-
"default": "{ 'md-outline-button': MdOutlinedButton, 'md-filled-icon-button': MdFilledIconButton, 'md-icon': MdIcon, 'action-list': ActionList, 'oscd-editor-template-textfield': OscdEditorTemplateTextfield, 'oscd-edit-dialog': OscdEditDialog, }"
44-
},
45-
{
46-
"kind": "field",
47-
"name": "editor",
48-
"type": {
49-
"text": "Transactor<EditV2>"
50-
},
51-
"attribute": "editor"
43+
"default": "{ 'md-text-button': MdTextButton, 'md-filled-icon-button': MdFilledIconButton, 'md-icon': MdIcon, 'action-list': ActionList, 'oscd-editor-template-textfield': OscdEditorTemplateTextfield, 'oscd-edit-dialog': OscdEditDialog, }"
5244
},
5345
{
5446
"kind": "field",
@@ -67,14 +59,7 @@
6759
},
6860
{
6961
"kind": "field",
70-
"name": "docs",
71-
"type": {
72-
"text": "Record<string, XMLDocument>"
73-
}
74-
},
75-
{
76-
"kind": "field",
77-
"name": "editCount",
62+
"name": "docVersion",
7863
"type": {
7964
"text": "unknown"
8065
}
@@ -393,15 +378,6 @@
393378
}
394379
}
395380
],
396-
"attributes": [
397-
{
398-
"name": "editor",
399-
"type": {
400-
"text": "Transactor<EditV2>"
401-
},
402-
"fieldName": "editor"
403-
}
404-
],
405381
"mixins": [
406382
{
407383
"name": "ScopedElementsMixin",
@@ -442,7 +418,7 @@
442418
"text": "object"
443419
},
444420
"static": true,
445-
"default": "{ 'md-outlined-field': MdOutlinedField, 'md-button': MdOutlinedButton, 'md-icon-button': MdIconButton, 'md-menu': MdMenu, 'md-switch': MdSwitch, 'md-list-item': MdListItem, }"
421+
"default": "{ 'md-outlined-field': MdOutlinedField, 'md-icon-button': MdIconButton, 'md-menu': MdMenu, 'md-switch': MdSwitch, 'md-list-item': MdListItem, }"
446422
},
447423
{
448424
"kind": "field",

oscd-editor-template.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ describe('oscd-editor-template', () => {
2121

2222
beforeEach(async () => {
2323
plugin = await fixture(html`<oscd-editor-template></oscd-editor-template>`);
24-
plugin.docs = {
25-
'test.scd': sclDoc,
26-
};
2724
plugin.doc = sclDoc;
2825
plugin.docName = 'test.scd';
2926
});

oscd-editor-template.ts

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { property, query, queryAll, state } from 'lit/decorators.js';
33
import { classMap } from 'lit/directives/class-map.js';
44

55
import { styles } from './foundation.js';
6-
import { EditV2, Transactor } from '@omicronenergy/oscd-api';
6+
import { EditV2 } from '@omicronenergy/oscd-api';
77
import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';
8-
import { MdOutlinedButton } from '@scopedelement/material-web/button/MdOutlinedButton.js';
8+
import { MdTextButton } from '@scopedelement/material-web/button/MdTextButton.js';
99
import { MdFilledIconButton } from '@scopedelement/material-web/iconbutton/MdFilledIconButton.js';
1010
import { MdIcon } from '@scopedelement/material-web/icon/MdIcon.js';
1111
import { OscdEditorTemplateTextfield } from './components/OscdEditorTemplateTextfield.js';
@@ -15,21 +15,20 @@ import type {
1515
CreateWizard,
1616
EditWizard,
1717
} from '@omicronenergy/oscd-edit-dialog/OscdEditDialog.js';
18+
import { newEditEventV2 } from '@omicronenergy/oscd-api/utils.js';
1819

1920
/** An editor [[`plugin`]] for editing the `DataTypeTemplates` section. */
2021
export default class OscdEditorTemplate extends ScopedElementsMixin(
2122
LitElement,
2223
) {
2324
static scopedElements = {
24-
'md-outline-button': MdOutlinedButton,
25+
'md-text-button': MdTextButton,
2526
'md-filled-icon-button': MdFilledIconButton,
2627
'md-icon': MdIcon,
2728
'action-list': ActionList,
2829
'oscd-editor-template-textfield': OscdEditorTemplateTextfield,
2930
'oscd-edit-dialog': OscdEditDialog,
3031
};
31-
@property({ type: Object })
32-
editor!: Transactor<EditV2>;
3332

3433
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
3534
@property({ attribute: false })
@@ -39,10 +38,7 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
3938
docName!: string;
4039

4140
@property({ attribute: false })
42-
docs!: Record<string, XMLDocument>;
43-
44-
@property({ attribute: false })
45-
editCount!: unknown;
41+
docVersion!: unknown;
4642

4743
@state()
4844
selectedLNodeType: Element | null | undefined = undefined;
@@ -129,7 +125,7 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
129125
);
130126
}
131127

132-
this.editor.commit(actions);
128+
this.dispatchEvent(newEditEventV2(actions));
133129
this.onLNodeTypeInputChange();
134130
}
135131

@@ -181,7 +177,7 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
181177
);
182178
}
183179

184-
this.editor.commit(actions);
180+
this.dispatchEvent(newEditEventV2(actions));
185181
this.onDOTypeInputChange();
186182
}
187183

@@ -233,7 +229,7 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
233229
);
234230
}
235231

236-
this.editor.commit(actions);
232+
this.dispatchEvent(newEditEventV2(actions));
237233
this.onDATypeInputChange();
238234
}
239235

@@ -285,22 +281,22 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
285281
);
286282
}
287283

288-
this.editor.commit(actions);
284+
this.dispatchEvent(newEditEventV2(actions));
289285
this.onEnumTypeInputChange();
290286
}
291287

292288
async handleCreateElement(createWizard: CreateWizard) {
293289
const edits = await this.editDialog?.create(createWizard);
294290
if (edits) {
295-
this.editor.commit(edits);
291+
this.dispatchEvent(newEditEventV2(edits));
296292
this.requestUpdate();
297293
}
298294
}
299295

300296
async handleEditElement(editWizard: EditWizard) {
301297
const edits = await this.editDialog?.edit(editWizard);
302298
if (edits) {
303-
this.editor.commit(edits);
299+
this.dispatchEvent(newEditEventV2(edits));
304300
this.requestUpdate();
305301
}
306302
}
@@ -399,24 +395,23 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
399395
@input="${this.onEnumTypeInputChange}"
400396
></oscd-editor-template-textfield>
401397
<div class="save">
402-
<md-button
403-
icon="save"
404-
label="Save"
398+
<md-text-button
405399
?disabled=${!this.enumTypeDiff}
406400
@click="${this.onSaveEnumType}"
407-
></md-button>
401+
><md-icon slot="icon">save</md-icon>Save</md-text-button
402+
>
408403
</div>
409404
<hr color="lightgrey" />
410405
<div class="add">
411-
<md-button
412-
icon="playlist_add"
413-
label="Add EnumVal"
406+
<md-text-button
414407
@click=${() =>
415408
this.handleCreateElement({
416409
parent: this.selectedEnumType!,
417410
tagName: 'EnumVal',
418411
})}
419-
></md-button>
412+
><md-icon slot="icon">playlist_add</md-icon>Add
413+
EnumVal</md-text-button
414+
>
420415
</div>
421416
<action-list
422417
.items=${items}
@@ -532,24 +527,23 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
532527
@input="${this.onDATypeInputChange}"
533528
></oscd-editor-template-textfield>
534529
<div class="save">
535-
<md-button
536-
icon="save"
537-
label="Save"
530+
<md-text-button
538531
?disabled=${!this.daTypeDiff}
539532
@click="${this.onSaveDAType}"
540-
></md-button>
533+
><md-icon slot="icon">save</md-icon>Save</md-text-button
534+
>
541535
</div>
542536
<hr color="lightgrey" />
543537
<div class="add">
544-
<md-button
545-
icon="playlist_add"
546-
label="Add Data Attribute"
538+
<md-text-button
547539
@click=${() =>
548540
this.handleCreateElement({
549541
parent: this.selectedDAType!,
550542
tagName: 'BDA',
551543
})}
552-
></md-button>
544+
><md-icon slot="icon">playlist_add</md-icon>Add Data
545+
Attribute</md-text-button
546+
>
553547
</div>
554548
<action-list
555549
.items=${items}
@@ -675,33 +669,34 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
675669
@input="${this.onDOTypeInputChange}"
676670
></oscd-editor-template-textfield>
677671
<div class="save">
678-
<md-button
679-
icon="save"
680-
label="Save"
672+
<md-text-button
681673
?disabled=${!this.doTypeDiff}
682674
@click="${this.onSaveDOType}"
683-
></md-button>
675+
><md-icon slot="icon">save</md-icon>Save</md-text-button
676+
>
684677
</div>
685678
<hr color="lightgrey" />
686679
<div class="add">
687-
<md-button
680+
<md-text-button
688681
icon="playlist_add"
689682
label="Add Data Object"
690683
@click="${() =>
691684
this.handleCreateElement({
692685
parent: this.selectedDOType!,
693686
tagName: 'SDO',
694687
})}"
695-
></md-button>
696-
<md-button
697-
icon="playlist_add"
698-
label="Add Data Attribute"
688+
><md-icon slot="icon">playlist_add</md-icon>Add Data
689+
Object</md-text-button
690+
>
691+
<md-text-button
699692
@click="${() =>
700693
this.handleCreateElement({
701694
parent: this.selectedDOType!,
702695
tagName: 'DA',
703696
})}"
704-
></md-button>
697+
><md-icon slot="icon">playlist_add</md-icon>Add Data
698+
Attribute</md-text-button
699+
>
705700
</div>
706701
<action-list
707702
.items=${items}
@@ -822,24 +817,23 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
822817
@input="${this.onLNodeTypeInputChange}"
823818
></oscd-editor-template-textfield>
824819
<div class="save">
825-
<md-button
826-
icon="save"
827-
label="Save"
820+
<md-text-button
828821
?disabled=${!this.lNodeTypeDiff}
829822
@click="${this.onSaveLNodeType}"
830-
></md-button>
823+
><md-icon slot="icon">save</md-icon>Save</md-text-button
824+
>
831825
</div>
832826
<hr color="lightgrey" />
833827
<div class="add">
834-
<md-button
835-
icon="playlist_add"
836-
label="Add Data Object"
828+
<md-text-button
837829
@click=${() =>
838830
this.handleCreateElement({
839831
parent: this.selectedLNodeType!,
840832
tagName: 'DO',
841833
})}
842-
></md-button>
834+
><md-icon slot="icon">playlist_add</md-icon>Add Data
835+
Object</md-text-button
836+
>
843837
</div>
844838
<action-list
845839
.items=${items}
@@ -960,7 +954,7 @@ export default class OscdEditorTemplate extends ScopedElementsMixin(
960954
justify-content: flex-end;
961955
}
962956
963-
div.save > md-button {
957+
div.save > md-text-button {
964958
margin: 10px;
965959
}
966960

0 commit comments

Comments
 (0)