Skip to content

Commit 548f63b

Browse files
ca-dStef3stdanyill
authored
fix(editing): use editCount property for change propagation (openscd#1233)
* fix(editing): use editCount property for change propagation --------- Signed-off-by: Stef3st <[email protected]> Co-authored-by: Steffen van den Driest <[email protected]> Co-authored-by: Stef3st <[email protected]> Co-authored-by: danyill <[email protected]>
1 parent 4440bff commit 548f63b

File tree

73 files changed

+995
-128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+995
-128
lines changed

src/Editing.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,6 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
424424

425425
if (!this.doc) return;
426426

427-
const newDoc = document.implementation.createDocument(
428-
this.doc.lookupNamespaceURI(''),
429-
this.doc.documentElement.tagName,
430-
this.doc.doctype
431-
);
432-
433-
// change the document object reference to enable reactive updates
434-
newDoc.documentElement.replaceWith(this.doc.documentElement);
435-
this.doc = newDoc;
436-
437427
await this.updateComplete;
438428
this.dispatchEvent(newValidateEvent());
439429
}

src/Logging.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function getPluginName(src: string): string {
5959
* A mixin adding a `history` property to any `LitElement`, in which
6060
* incoming [[`LogEvent`]]s are logged.
6161
*
62-
* For [[`EditorAction`]] entries, also sets `currentAction` to the index of
62+
* For [[`EditorAction`]] entries, also sets `editCount` to the index of
6363
* the committed action, allowing the user to go to `previousAction` with
6464
* `undo()` if `canUndo` and to go to `nextAction` with `redo()` if `canRedo`.
6565
*
@@ -75,7 +75,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
7575
history: LogEntry[] = [];
7676
/** Index of the last [[`EditorAction`]] applied. */
7777
@property({ type: Number })
78-
currentAction = -1;
78+
editCount = -1;
7979
@property()
8080
diagnoses = new Map<string, IssueDetail[]>();
8181
@internalProperty()
@@ -89,7 +89,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
8989
@query('#issue') issueUI!: Snackbar;
9090

9191
get canUndo(): boolean {
92-
return this.currentAction >= 0;
92+
return this.editCount >= 0;
9393
}
9494
get canRedo(): boolean {
9595
return this.nextAction >= 0;
@@ -98,15 +98,15 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
9898
get previousAction(): number {
9999
if (!this.canUndo) return -1;
100100
return this.history
101-
.slice(0, this.currentAction)
101+
.slice(0, this.editCount)
102102
.map(entry => (entry.kind == 'action' ? true : false))
103103
.lastIndexOf(true);
104104
}
105105
get nextAction(): number {
106106
let index = this.history
107-
.slice(this.currentAction + 1)
107+
.slice(this.editCount + 1)
108108
.findIndex(entry => entry.kind == 'action');
109-
if (index >= 0) index += this.currentAction + 1;
109+
if (index >= 0) index += this.editCount + 1;
110110
return index;
111111
}
112112

@@ -125,25 +125,25 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
125125
if (!this.canUndo) return false;
126126
this.dispatchEvent(
127127
newActionEvent(
128-
invert((<CommitEntry>this.history[this.currentAction]).action)
128+
invert((<CommitEntry>this.history[this.editCount]).action)
129129
)
130130
);
131-
this.currentAction = this.previousAction;
131+
this.editCount = this.previousAction;
132132
return true;
133133
}
134134
redo(): boolean {
135135
if (!this.canRedo) return false;
136136
this.dispatchEvent(
137137
newActionEvent((<CommitEntry>this.history[this.nextAction]).action)
138138
);
139-
this.currentAction = this.nextAction;
139+
this.editCount = this.nextAction;
140140
return true;
141141
}
142142

143143
private onLog(le: LogEvent): void {
144144
if (le.detail.kind === 'reset') {
145145
this.history = [];
146-
this.currentAction = -1;
146+
this.editCount = -1;
147147
return;
148148
}
149149

@@ -156,7 +156,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
156156
if (entry.action.derived) return;
157157
entry.action.derived = true;
158158
if (this.nextAction !== -1) this.history.splice(this.nextAction);
159-
this.currentAction = this.history.length;
159+
this.editCount = this.history.length;
160160
}
161161

162162
this.history.push(entry);
@@ -206,7 +206,7 @@ export function Logging<TBase extends LitElementConstructor>(Base: TBase) {
206206
class="${entry.kind}"
207207
graphic="icon"
208208
?twoline=${!!entry.message}
209-
?activated=${this.currentAction == history.length - index - 1}
209+
?activated=${this.editCount == history.length - index - 1}
210210
>
211211
<span>
212212
<!-- FIXME: replace tt with mwc-chip asap -->

src/Plugging.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ifImplemented, Mixin } from './foundation.js';
2525
import { EditingElement } from './Editing.js';
2626
import { officialPlugins } from '../public/js/plugins.js';
2727
import { Nsdoc } from './foundation/nsdoc.js';
28-
28+
import { LoggingElement } from './Logging.js';
2929
const pluginTags = new Map<string, string>();
3030
/**
3131
* Hashes `uri` using cyrb64 analogous to
@@ -176,9 +176,9 @@ const loadedPlugins = new Set<string>();
176176
/** Mixin that manages Plugins in `localStorage` */
177177
export type PluggingElement = Mixin<typeof Plugging>;
178178

179-
export function Plugging<TBase extends new (...args: any[]) => EditingElement>(
180-
Base: TBase
181-
) {
179+
export function Plugging<
180+
TBase extends new (...args: any[]) => EditingElement & LoggingElement
181+
>(Base: TBase) {
182182
class PluggingElement extends Base {
183183
// DIRTY HACK: will refactored with open-scd-core
184184
nsdoc!: Nsdoc;
@@ -289,6 +289,7 @@ export function Plugging<TBase extends new (...args: any[]) => EditingElement>(
289289
content: staticTagHtml`<${tag}
290290
.doc=${this.doc}
291291
.docName=${this.docName}
292+
.editCount=${this.editCount}
292293
.docId=${this.docId}
293294
.pluginId=${plugin.src}
294295
.nsdoc=${this.nsdoc}

src/editors/Cleanup.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ export default class Cleanup extends LitElement {
1313
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
1414
@property()
1515
doc!: XMLDocument;
16+
@property({ type: Number })
17+
editCount = -1;
1618

1719
render(): TemplateResult {
1820
return html`
1921
<div class="cleanup">
20-
<cleanup-datasets .doc=${this.doc}></cleanup-datasets>
21-
<cleanup-control-blocks .doc=${this.doc}></cleanup-control-blocks>
22-
<cleanup-data-types .doc=${this.doc}></cleanup-data-types>
22+
<cleanup-datasets .editCount=${this.editCount} .doc=${this.doc}></cleanup-datasets>
23+
<cleanup-control-blocks .editCount=${this.editCount} .doc=${this.doc}></cleanup-control-blocks>
24+
<cleanup-data-types .editCount=${this.editCount} .doc=${this.doc}></cleanup-data-types>
2325
</div>
2426
`;
2527
}

src/editors/Communication.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default class CommunicationPlugin extends LitElement {
1717
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
1818
@property()
1919
doc!: XMLDocument;
20+
@property({ type: Number })
21+
editCount = -1;
2022

2123
/**
2224
* Creates the Communication Element and returns the created Element
@@ -37,7 +39,8 @@ export default class CommunicationPlugin extends LitElement {
3739

3840
/** Opens a [[`WizardDialog`]] for creating a new `SubNetwork` element. */
3941
private openCreateSubNetworkWizard(): void {
40-
const parent =this.doc.querySelector(':root > Communication') ||
42+
const parent =
43+
this.doc.querySelector(':root > Communication') ||
4144
this.createCommunication();
4245

4346
this.dispatchEvent(newWizardEvent(createSubNetworkWizard(parent!)));
@@ -68,6 +71,7 @@ export default class CommunicationPlugin extends LitElement {
6871
.map(
6972
subnetwork =>
7073
html`<subnetwork-editor
74+
.editCount=${this.editCount}
7175
.doc=${this.doc}
7276
.element=${subnetwork}
7377
></subnetwork-editor>`

src/editors/GooseSubscriberDataBinding.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import './subscription/later-binding/ext-ref-ln-binding-list.js';
99
export default class GooseSubscribeDataBindingPlugin extends LitElement {
1010
@property({ attribute: false })
1111
doc!: XMLDocument;
12+
@property({ type: Number })
13+
editCount = -1;
1214
@property()
1315
nsdoc!: Nsdoc;
1416

@@ -19,12 +21,14 @@ export default class GooseSubscribeDataBindingPlugin extends LitElement {
1921
class="column"
2022
controlTag="GSEControl"
2123
.includeLaterBinding="${false}"
24+
.editCount=${this.editCount}
2225
.doc="${this.doc}"
2326
>
2427
</fcda-binding-list>
2528
<extref-ln-binding-list
2629
class="column"
2730
controlTag="GSEControl"
31+
.editCount=${this.editCount}
2832
.doc="${this.doc}"
2933
.nsdoc="${this.nsdoc}"
3034
>

src/editors/GooseSubscriberLaterBinding.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import './subscription/later-binding/ext-ref-later-binding-list.js';
77
export default class GooseSubscribeLaterBindingPlugin extends LitElement {
88
@property({ attribute: false })
99
doc!: XMLDocument;
10+
@property({ type: Number })
11+
editCount = -1;
1012

1113
render(): TemplateResult {
1214
return html`<div>
@@ -15,13 +17,13 @@ export default class GooseSubscribeLaterBindingPlugin extends LitElement {
1517
class="column"
1618
controlTag="GSEControl"
1719
.includeLaterBinding="${true}"
18-
.doc="${this.doc}"
20+
.editCount=${this.editCount} .doc="${this.doc}"
1921
>
2022
</fcda-binding-list>
2123
<extref-later-binding-list
2224
class="column"
2325
controlTag="GSEControl"
24-
.doc="${this.doc}"
26+
.editCount=${this.editCount} .doc="${this.doc}"
2527
>
2628
</extref-later-binding-list>
2729
</div>

src/editors/GooseSubscriberMessageBinding.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default class GooseSubscriberMessageBindingPlugin extends LitElement {
2525
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
2626
@property()
2727
doc!: XMLDocument;
28+
@property({ type: Number })
29+
editCount = -1;
2830

2931
@query('#goosePublisherView')
3032
goosePublisherView!: RadioListItem;
@@ -75,14 +77,20 @@ export default class GooseSubscriberMessageBindingPlugin extends LitElement {
7577
</mwc-formfield>
7678
<div class="container">
7779
${view == View.PUBLISHER
78-
? html`<goose-list class="row" .doc=${this.doc}></goose-list>`
80+
? html`<goose-list
81+
class="row"
82+
.editCount=${this.editCount}
83+
.doc=${this.doc}
84+
></goose-list>`
7985
: html`<ied-list
8086
class="row"
87+
.editCount=${this.editCount}
8188
.doc=${this.doc}
8289
serviceType="goose"
8390
></ied-list>`}
8491
<subscriber-list-goose
8592
class="row"
93+
.editCount=${this.editCount}
8694
.doc=${this.doc}
8795
></subscriber-list-goose>
8896
</div>

src/editors/IED.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export default class IedPlugin extends LitElement {
3232
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
3333
@property()
3434
doc!: XMLDocument;
35+
@property({ type: Number })
36+
editCount = -1;
3537

3638
/** All the nsdoc files that are being uploaded via the settings. */
3739
@property()
@@ -175,6 +177,7 @@ export default class IedPlugin extends LitElement {
175177
</div>
176178
177179
<ied-container
180+
.editCount=${this.editCount}
178181
.doc=${this.doc}
179182
.element=${this.selectedIed}
180183
.selectedLNClasses=${this.selectedLNClasses}

0 commit comments

Comments
 (0)