Skip to content

Commit

Permalink
[2608] Improve the placement of handles on the left and right side of…
Browse files Browse the repository at this point in the history
… nodes

Make sure the "virtual" handles added after the real ones are not
considered by the flexbox on the container.

Bug: #2608
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid committed Nov 21, 2023
1 parent 8aed8c3 commit 7d0ac8b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ The new implementation of `IEditService`, named `ComposedEditService`, tries fir
- https://github.com/eclipse-sirius/sirius-web/issues/2235[#2235] [diagram] Reduce the amount of code in DiagramRenderer
- https://github.com/eclipse-sirius/sirius-web/issues/2572[#2572] [diagram] Each edges now have a dedicated handle.
- https://github.com/eclipse-sirius/sirius-web/issues/2584[#2584] [diagram] Add feedback during edge creation.
- https://github.com/eclipse-sirius/sirius-web/issues/2608[#2608] [diagram] Improve the placement of handles on the left and right side of nodes so that they are properly centered.

== v2023.10.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ const borderHandlesStyle = (position: Position): React.CSSProperties => {
return style;
};

const handleStyle = (theme: Theme, position: Position, isEdgeSelected: boolean): React.CSSProperties => {
const handleStyle = (
theme: Theme,
position: Position,
isEdgeSelected: boolean,
isVirtualHandle: boolean
): React.CSSProperties => {
const style: React.CSSProperties = {
position: 'relative',
transform: 'none',
Expand All @@ -72,6 +77,10 @@ const handleStyle = (theme: Theme, position: Position, isEdgeSelected: boolean):
style.opacity = 1;
style.outline = `${theme.palette.primary.main} solid 1px`;
}
if (isVirtualHandle) {
style.position = 'absolute';
style.display = 'none';
}
return style;
};

Expand All @@ -96,22 +105,30 @@ export const ConnectionHandles = ({ connectionHandles }: ConnectionHandlesProps)
return (
<>
{Object.values(Position).map((position) => {
const currentSideHandles = connectionHandles.filter(
(connectionHandle) => connectionHandle.position === position
);
return (
<div style={borderHandlesStyle(position)} key={position}>
{connectionHandles
.filter((connectionHandle) => connectionHandle.position === position)
.map((connectionHandle) => {
return (
<Handle
id={connectionHandle.id ?? ''}
style={handleStyle(theme, connectionHandle.position, isHandleSelected(connectionHandle))}
type={connectionHandle.type}
position={connectionHandle.position}
key={connectionHandle.id}
isConnectable={true}
/>
);
})}
{currentSideHandles.map((connectionHandle, index) => {
const isVirtualHandle =
(position === Position.Left || position === Position.Right) && index === currentSideHandles.length - 1;
return (
<Handle
id={connectionHandle.id ?? ''}
style={handleStyle(
theme,
connectionHandle.position,
isHandleSelected(connectionHandle),
isVirtualHandle
)}
type={connectionHandle.type}
position={connectionHandle.position}
key={connectionHandle.id}
isConnectable={true}
/>
);
})}
</div>
);
})}
Expand Down

0 comments on commit 7d0ac8b

Please sign in to comment.