@@ -100,10 +100,6 @@ export function getAttachedIeds(
100
100
} ;
101
101
}
102
102
103
- export type ElementEditor = Element & {
104
- element : Element ;
105
- } ;
106
-
107
103
export function cloneSubstationElement (
108
104
editor : BayEditor | VoltageLevelEditor | SubstationEditor
109
105
) : void {
@@ -144,6 +140,11 @@ export function cloneSubstationElement(
144
140
) ;
145
141
}
146
142
143
+ export type ElementEditor = Element & {
144
+ element : Element ;
145
+ } ;
146
+ export type ElementEditorClass < T extends ElementEditor > = new ( ) => T ;
147
+
147
148
/**
148
149
* Moves the element edited by `editor` to the place before the next `Child`
149
150
* editor selected or to the end of the next `Parent` editor selected by mouse
@@ -152,10 +153,14 @@ export function cloneSubstationElement(
152
153
* The move action can be aborted by clicking on something other than a `Child`
153
154
* or `Parent` editor or by hitting the escape key on the keyboard.
154
155
*/
155
- export function startMove < E extends ElementEditor , P extends ElementEditor > (
156
+ export function startMove <
157
+ E extends ElementEditor ,
158
+ C extends ElementEditorClass < ElementEditor > ,
159
+ P extends ElementEditorClass < ElementEditor > >
160
+ (
156
161
editor : E ,
157
- Child : new ( ) => E ,
158
- Parent : new ( ) => P
162
+ childClass : C ,
163
+ parentClasses : P [ ]
159
164
) : void {
160
165
if ( ! editor . element ) return ;
161
166
@@ -179,19 +184,17 @@ export function startMove<E extends ElementEditor, P extends ElementEditor>(
179
184
180
185
if ( e instanceof KeyboardEvent && e . key === 'Escape' ) return ;
181
186
182
- const targetEditor = e
183
- . composedPath ( )
184
- . find ( e => e instanceof Child || e instanceof Parent ) ;
185
-
187
+ const targetEditor = e . composedPath ( )
188
+ . find ( et => et instanceof childClass || checkInstanceOfParentClass ( et , parentClasses ) ) ;
186
189
if ( targetEditor === undefined || targetEditor === editor ) return ;
187
190
188
191
const destination =
189
- targetEditor instanceof Child
192
+ targetEditor instanceof childClass
190
193
? {
191
194
parent : targetEditor . element . parentElement ! ,
192
195
reference : targetEditor . element ,
193
196
}
194
- : { parent : ( < P > targetEditor ) . element , reference : null } ;
197
+ : { parent : ( < E > targetEditor ) . element , reference : null } ;
195
198
196
199
if ( ! destination . parent ) return ;
197
200
@@ -215,6 +218,20 @@ export function startMove<E extends ElementEditor, P extends ElementEditor>(
215
218
window . addEventListener ( 'keydown' , moveToTarget , true ) ;
216
219
}
217
220
221
+ /**
222
+ * Check if the eventTarget that triggered the event is one of the classes that
223
+ * we accepted as target to use to move an element to.
224
+ *
225
+ * @param et - The Event Target.
226
+ * @param classes - The list of Classes which are acceptable.
227
+ */
228
+ function checkInstanceOfParentClass < E extends ElementEditor > (
229
+ et : EventTarget ,
230
+ classes : ElementEditorClass < E > [ ] ) : boolean {
231
+ const targetEditor = classes . find ( clazz => et instanceof clazz ) ;
232
+ return targetEditor !== undefined ;
233
+ }
234
+
218
235
/**
219
236
* Get the correct icon for a specific Conducting Equipment.
220
237
* @param condEq - The Conducting Equipment to search the icon for.
@@ -261,6 +278,14 @@ export const styles = css`
261
278
border-bottom : none;
262
279
}
263
280
281
+ # powertransformercontainer {
282
+ display : grid;
283
+ grid-gap : 12px ;
284
+ padding : 8px 12px 16px ;
285
+ box-sizing : border-box;
286
+ grid-template-columns : repeat (auto-fit, minmax (64px , auto));
287
+ }
288
+
264
289
# iedcontainer {
265
290
display : grid;
266
291
grid-gap : 12px ;
0 commit comments