Skip to content

Commit a9bad36

Browse files
fix(Pluggin/Hosting): allow using own dialogs in menu plugins (openscd#843)
* fix(Pluggin/Hosting): allocate menu plugin content next to its list item * fix(open-scd): snapshots * fix(Hosting): hack to make sure menu plugins not triggering run
1 parent 4c663d0 commit a9bad36

File tree

4 files changed

+49
-30
lines changed

4 files changed

+49
-30
lines changed

src/Hosting.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function Hosting<
7373
newPendingStateEvent(
7474
(<MenuPlugin>(
7575
(<unknown>(
76-
(<List>ae.target).items[ae.detail.index].lastElementChild
76+
(<List>ae.target).items[ae.detail.index].nextElementSibling
7777
))
7878
)).run()
7979
)
@@ -94,7 +94,7 @@ export function Hosting<
9494
newPendingStateEvent(
9595
(<MenuPlugin>(
9696
(<unknown>(
97-
(<List>ae.target).items[ae.detail.index].lastElementChild
97+
(<List>ae.target).items[ae.detail.index].nextElementSibling
9898
))
9999
)).run()
100100
)
@@ -115,7 +115,7 @@ export function Hosting<
115115
newPendingStateEvent(
116116
(<MenuPlugin>(
117117
(<unknown>(
118-
(<List>ae.target).items[ae.detail.index].lastElementChild
118+
(<List>ae.target).items[ae.detail.index].nextElementSibling
119119
))
120120
)).run()
121121
)
@@ -139,7 +139,7 @@ export function Hosting<
139139
newPendingStateEvent(
140140
(<Validator>(
141141
(<unknown>(
142-
(<List>ae.target).items[ae.detail.index].lastElementChild
142+
(<List>ae.target).items[ae.detail.index].nextElementSibling
143143
))
144144
)).validate()
145145
)
@@ -224,7 +224,7 @@ export function Hosting<
224224
.querySelector('mwc-list')!
225225
.items.filter(item => item.className === 'validator')
226226
.map(item =>
227-
(<Validator>(<unknown>item.lastElementChild)).validate()
227+
(<Validator>(<unknown>item.nextElementSibling)).validate()
228228
)
229229
).then();
230230
this.dispatchEvent(newPendingStateEvent(this.validated));
@@ -245,8 +245,8 @@ export function Hosting<
245245
${me.hint
246246
? html`<span slot="secondary"><tt>${me.hint}</tt></span>`
247247
: ''}
248-
${me.content ?? ''}
249248
</mwc-list-item>
249+
${me.content ?? ''}
250250
`;
251251
}
252252

@@ -280,10 +280,14 @@ export function Hosting<
280280
: ''}
281281
<mwc-list
282282
wrapFocus
283-
@action=${(ae: CustomEvent<ActionDetail>) =>
284-
(<MenuItem>(
285-
this.menu.filter(item => item !== 'divider')[ae.detail.index]
286-
))?.action?.(ae)}
283+
@action=${(ae: CustomEvent<ActionDetail>) => {
284+
//FIXME: dirty hack to be fixed in open-scd-core
285+
// if clause not neccassary when oscd... compenents in open-scd not list
286+
if (ae.target instanceof List)
287+
(<MenuItem>(
288+
this.menu.filter(item => item !== 'divider')[ae.detail.index]
289+
))?.action?.(ae);
290+
}}
287291
>
288292
${this.menu.map(this.renderMenuItem)}
289293
</mwc-list>

src/Plugging.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { html, query, TemplateResult } from 'lit-element';
2+
import { classMap } from 'lit-html/directives/class-map';
23
import { translate } from 'lit-translate';
34

45
import '@material/mwc-button';
@@ -291,6 +292,12 @@ export function Plugging<TBase extends new (...args: any[]) => EditingElement>(
291292
.docId=${this.docId}
292293
.pluginId=${plugin.src}
293294
.nsdoc=${this.nsdoc}
295+
class="${classMap({
296+
plugin: true,
297+
menu: plugin.kind === 'menu',
298+
validator: plugin.kind === 'validator',
299+
editor: plugin.kind === 'editor',
300+
})}"
294301
></${tag}>`,
295302
};
296303
}

src/open-scd.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,13 @@ export class OpenSCD extends Hosting(
170170
margin-left: -30px;
171171
font-family: 'Roboto', sans-serif;
172172
}
173+
174+
.plugin.menu {
175+
display: flex;
176+
}
177+
178+
.plugin.validator {
179+
display: flex;
180+
}
173181
`;
174182
}

test/integration/__snapshots__/open-scd.test.snap.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ snapshots["open-scd looks like its snapshot"] =
3232
<span>
3333
Open project
3434
</span>
35-
<oscd-plugina2b400fc5f053cb1>
36-
</oscd-plugina2b400fc5f053cb1>
3735
</mwc-list-item>
36+
<oscd-plugina2b400fc5f053cb1 class="plugin">
37+
</oscd-plugina2b400fc5f053cb1>
3838
<mwc-list-item
3939
aria-disabled="false"
4040
class="top"
@@ -49,9 +49,9 @@ snapshots["open-scd looks like its snapshot"] =
4949
<span>
5050
New project
5151
</span>
52-
<oscd-plugin679d81826289fb9a>
53-
</oscd-plugin679d81826289fb9a>
5452
</mwc-list-item>
53+
<oscd-plugin679d81826289fb9a class="plugin">
54+
</oscd-plugin679d81826289fb9a>
5555
<mwc-list-item
5656
aria-disabled="true"
5757
class="top"
@@ -67,9 +67,9 @@ snapshots["open-scd looks like its snapshot"] =
6767
<span>
6868
Save project
6969
</span>
70-
<oscd-plugin1cb4a5367ff1f6a1>
71-
</oscd-plugin1cb4a5367ff1f6a1>
7270
</mwc-list-item>
71+
<oscd-plugin1cb4a5367ff1f6a1 class="plugin">
72+
</oscd-plugin1cb4a5367ff1f6a1>
7373
<li
7474
divider=""
7575
padded=""
@@ -123,9 +123,9 @@ snapshots["open-scd looks like its snapshot"] =
123123
<span>
124124
Validate Schema
125125
</span>
126-
<oscd-plugin3aa68346726da1cd>
127-
</oscd-plugin3aa68346726da1cd>
128126
</mwc-list-item>
127+
<oscd-plugin3aa68346726da1cd class="plugin">
128+
</oscd-plugin3aa68346726da1cd>
129129
<mwc-list-item
130130
aria-disabled="true"
131131
class="validator"
@@ -141,9 +141,9 @@ snapshots["open-scd looks like its snapshot"] =
141141
<span>
142142
Validate Templates
143143
</span>
144-
<oscd-plugin186320cdd626e422>
145-
</oscd-plugin186320cdd626e422>
146144
</mwc-list-item>
145+
<oscd-plugin186320cdd626e422 class="plugin">
146+
</oscd-plugin186320cdd626e422>
147147
<mwc-list-item
148148
aria-disabled="false"
149149
class="static"
@@ -195,9 +195,9 @@ snapshots["open-scd looks like its snapshot"] =
195195
<span>
196196
Import IEDs
197197
</span>
198-
<oscd-plugin4fed39e69404009b>
199-
</oscd-plugin4fed39e69404009b>
200198
</mwc-list-item>
199+
<oscd-plugin4fed39e69404009b class="plugin">
200+
</oscd-plugin4fed39e69404009b>
201201
<mwc-list-item
202202
aria-disabled="true"
203203
class="middle"
@@ -213,9 +213,9 @@ snapshots["open-scd looks like its snapshot"] =
213213
<span>
214214
Subscriber Update
215215
</span>
216-
<oscd-plugin90bf5c90b69b347b>
217-
</oscd-plugin90bf5c90b69b347b>
218216
</mwc-list-item>
217+
<oscd-plugin90bf5c90b69b347b class="plugin">
218+
</oscd-plugin90bf5c90b69b347b>
219219
<mwc-list-item
220220
aria-disabled="true"
221221
class="middle"
@@ -231,9 +231,9 @@ snapshots["open-scd looks like its snapshot"] =
231231
<span>
232232
Merge Project
233233
</span>
234-
<oscd-plugin2b4693cc19da2446>
235-
</oscd-plugin2b4693cc19da2446>
236234
</mwc-list-item>
235+
<oscd-plugin2b4693cc19da2446 class="plugin">
236+
</oscd-plugin2b4693cc19da2446>
237237
<mwc-list-item
238238
aria-disabled="true"
239239
class="middle"
@@ -249,9 +249,9 @@ snapshots["open-scd looks like its snapshot"] =
249249
<span>
250250
Update Substation
251251
</span>
252-
<oscd-plugin2a662bacb120083f>
253-
</oscd-plugin2a662bacb120083f>
254252
</mwc-list-item>
253+
<oscd-plugin2a662bacb120083f class="plugin">
254+
</oscd-plugin2a662bacb120083f>
255255
<li
256256
divider=""
257257
padded=""
@@ -287,9 +287,9 @@ snapshots["open-scd looks like its snapshot"] =
287287
<span>
288288
Help
289289
</span>
290-
<oscd-plugin48ab1a46d409bed9>
291-
</oscd-plugin48ab1a46d409bed9>
292290
</mwc-list-item>
291+
<oscd-plugin48ab1a46d409bed9 class="plugin">
292+
</oscd-plugin48ab1a46d409bed9>
293293
<li
294294
divider=""
295295
padded=""

0 commit comments

Comments
 (0)