Skip to content

Commit 4e9d4e3

Browse files
committed
Separating selectedElement and draggedElement, some renaming
Signed-off-by: Florian Dupuy <[email protected]>
1 parent c38b378 commit 4e9d4e3

File tree

2 files changed

+112
-112
lines changed

2 files changed

+112
-112
lines changed

src/components/network-area-diagram-viewer/diagram-utils.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export function getConverterStationPolyline(
204204
return getFormattedPolyline(points[0], null, points[1]);
205205
}
206206

207-
// get the drabbable element, if present,
207+
// get the draggable element, if present,
208208
// from the element selected using the mouse
209209
export function getDraggableFrom(element: SVGElement): SVGElement | undefined {
210210
if (isDraggable(element)) {
@@ -214,12 +214,30 @@ export function getDraggableFrom(element: SVGElement): SVGElement | undefined {
214214
}
215215
}
216216

217+
// get the selectable element, if present,
218+
// from the element selected using the mouse
219+
export function getSelectableFrom(element: SVGElement): SVGElement | undefined {
220+
if (isSelectable(element)) {
221+
return element;
222+
} else if (element.parentElement) {
223+
return getSelectableFrom(element.parentNode as SVGElement);
224+
}
225+
}
226+
217227
function isDraggable(element: SVGElement): boolean {
218228
return (
219229
hasId(element) && element.parentNode != null && classIsContainerOfDraggables(element.parentNode as SVGElement)
220230
);
221231
}
222232

233+
function isSelectable(element: SVGElement): boolean {
234+
return (
235+
hasId(element) &&
236+
element.parentNode != null &&
237+
(element.parentNode as SVGElement).classList.contains('nad-vl-nodes')
238+
);
239+
}
240+
223241
function hasId(element: SVGElement): boolean {
224242
return typeof element.id != 'undefined' && element.id != '';
225243
}
@@ -398,9 +416,9 @@ export function getEdgeNameAngle(point1: Point, point2: Point): number {
398416
}
399417

400418
// check if a DOM element is a text node
401-
export function isTextNode(element: SVGGraphicsElement | null): boolean | undefined {
419+
export function isTextNode(element: SVGGraphicsElement | null): boolean {
402420
return (
403-
element != null && element.parentElement != null && element.parentElement?.classList.contains('nad-text-nodes')
421+
element != null && element.parentElement != null && element.parentElement.classList.contains('nad-text-nodes')
404422
);
405423
}
406424

0 commit comments

Comments
 (0)