@@ -41,10 +41,10 @@ import { CanvasDefaults } from '../../Canvas/canvas.defaults';
4141import { CanvasNode } from '../../Canvas/canvas.models' ;
4242import { StepToolbar } from '../../Canvas/StepToolbar/StepToolbar' ;
4343import { NodeContextMenuFn } from '../ContextMenu/NodeContextMenu' ;
44- import { GROUP_DRAG_TYPE , NODE_DRAG_TYPE } from '../customComponentUtils' ;
44+ import { getDropTargetContainerClassNames , GROUP_DRAG_TYPE , NODE_DRAG_TYPE } from '../customComponentUtils' ;
4545import { TargetAnchor } from '../target-anchor' ;
4646import { CustomNodeContainer } from './CustomNodeContainer' ;
47- import { checkNodeDropCompatibility , handleValidNodeDrop } from './CustomNodeUtils' ;
47+ import { checkNodeDropCompatibility , getNodeDragAndDropDirection , handleValidNodeDrop } from './CustomNodeUtils' ;
4848
4949type DefaultNodeProps = Parameters < typeof DefaultNode > [ 0 ] ;
5050
@@ -98,6 +98,16 @@ const CustomNodeLabel: FunctionComponent<CustomNodeLabelProps> = ({
9898 </ foreignObject >
9999) ;
100100
101+ function getShouldShowToolbar (
102+ trigger : NodeToolbarTrigger | undefined ,
103+ isGHover : boolean ,
104+ isToolbarHover : boolean ,
105+ selected : boolean | undefined ,
106+ ) : boolean {
107+ const isHoverTrigger = trigger === NodeToolbarTrigger . onHover ;
108+ return isHoverTrigger ? isGHover || isToolbarHover || ! ! selected : ! ! selected ;
109+ }
110+
101111const CustomNodeInner : FunctionComponent < CustomNodeProps > = observer (
102112 ( { element, onContextMenu, onCollapseToggle, selected, onSelect } ) => {
103113 if ( ! isNode ( element ) ) {
@@ -125,10 +135,12 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
125135 CanvasDefaults . HOVER_DELAY_OUT ,
126136 ) ;
127137 const childCount = element . getAllNodeChildren ( ) . length ;
128- const shouldShowToolbar =
129- settingsAdapter . getSettings ( ) . nodeToolbarTrigger === NodeToolbarTrigger . onHover
130- ? isGHover || isToolbarHover || selected
131- : selected ;
138+ const shouldShowToolbar = getShouldShowToolbar (
139+ settingsAdapter . getSettings ( ) . nodeToolbarTrigger ,
140+ isGHover ,
141+ isToolbarHover ,
142+ selected ,
143+ ) ;
132144 const canDragNode = vizNode ?. canDragNode ( ) ?? false ;
133145
134146 const hasSomeInteractions = useMemo (
@@ -158,7 +170,7 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
158170 DragObjectWithType ,
159171 DragSpecOperationType < EditableDragOperationType > ,
160172 GraphElement ,
161- { node : GraphElement | undefined } ,
173+ object ,
162174 GraphElementProps
163175 > = useMemo (
164176 ( ) => ( {
@@ -174,9 +186,6 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
174186 element . getGraph ( ) . layout ( ) ;
175187 }
176188 } ,
177- collect : ( monitor ) => ( {
178- node : monitor . getItem ( ) ,
179- } ) ,
180189 } ) ,
181190 [ canDragNode , element , entitiesContext , nodeInteractionAddonContext ] ,
182191 ) ;
@@ -194,7 +203,7 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
194203 GraphElementProps
195204 > = useMemo (
196205 ( ) => ( {
197- accept : [ NODE_DRAG_TYPE ] ,
206+ accept : [ NODE_DRAG_TYPE , GROUP_DRAG_TYPE ] ,
198207 canDrop : ( item , _monitor , _props ) => {
199208 const targetNode = element ;
200209 const draggedNode = item as Node ;
@@ -226,10 +235,10 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
226235 [ element , vizNode , entitiesContext , catalogModalContext ] ,
227236 ) ;
228237
229- const [ dragNodeProps , dragNodeRef ] = useDragNode ( nodeDragSourceSpec ) ;
238+ const [ , dragNodeRef ] = useDragNode ( nodeDragSourceSpec ) ;
230239 const [ dndDropProps , dndDropRef ] = useDndDrop ( customNodeDropTargetSpec ) ;
231240 const gCombinedRef = useCombineRefs < SVGGElement > ( gHoverRef , dragNodeRef ) ;
232- const isDraggingNode = dragNodeProps . node ?. getId ( ) === element . getId ( ) ;
241+ const isDraggingNode = dndDropProps . dragItem ?. getId ( ) === element . getId ( ) ;
233242 const isDraggingNodeType = dndDropProps . dragItemType === NODE_DRAG_TYPE ;
234243 const isDraggingGroupType = dndDropProps . dragItemType === GROUP_DRAG_TYPE ;
235244 const draggedVizNode = dndDropProps . dragItem ?. getData ( ) . vizNode ;
@@ -249,8 +258,25 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
249258 const toolbarX = ( box . width - toolbarWidth ) / 2 ;
250259 const toolbarY = CanvasDefaults . STEP_TOOLBAR_HEIGHT * - 1 ;
251260
261+ const dropDirection : 'forward' | 'backward' | null =
262+ dndDropProps . droppable && dndDropProps . canDrop && draggedVizNode
263+ ? getNodeDragAndDropDirection ( draggedVizNode , vizNode , false )
264+ : null ;
265+
266+ const showMainNodeContainer = ! dndDropProps . droppable || isDraggingNodeType || ! isDraggingWithinGroup ;
267+ const showLabelWhenDragging =
268+ ( isDraggingNodeType && ! isDraggingNode ) || ( isDraggingGroupType && ! isDraggingWithinGroup ) ;
269+ const showToolbarSection = ! dndDropProps . droppable && shouldShowToolbar && hasSomeInteractions ;
270+ const layerId = isDraggingWithinGroup ? TOP_LAYER : DEFAULT_LAYER ;
271+
272+ const mainContainerClassNames = {
273+ ...getDropTargetContainerClassNames ( 'custom-node__container' , dropDirection , dndDropProps . hover ) ,
274+ [ 'custom-node__container__draggable' ] : canDragNode ,
275+ [ 'custom-node__container__draggedNode' ] : isDraggedNode ,
276+ } ;
277+
252278 return (
253- < Layer id = { isDraggingWithinGroup ? TOP_LAYER : DEFAULT_LAYER } data-lastupdate = { lastUpdate } >
279+ < Layer id = { layerId } data-lastupdate = { lastUpdate } >
254280 < g
255281 ref = { gCombinedRef }
256282 className = "custom-node"
@@ -266,21 +292,14 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
266292 { /** The original node (appears when nothing is dragging, it also acts as the dragged node when node drag action is performed.
267293 * When a group/container is being dragged, the within-group nodes are hidden but the rest of the nodes show this original node.
268294 */ }
269- { ( ! dndDropProps . droppable || isDraggingNodeType || ! isDraggingWithinGroup ) && (
295+ { showMainNodeContainer && (
270296 < CustomNodeContainer
271297 width = { box . width }
272298 height = { box . height }
273299 dataNodelabel = { label }
274- foreignObjectRef = { dndDropRef }
300+ foreignObjectRef = { isDraggingNode ? null : dndDropRef }
275301 dataTestId = { vizNode . id }
276- containerClassNames = { {
277- 'custom-node__container__dropTarget' :
278- dndDropProps . droppable && dndDropProps . canDrop && dndDropProps . hover ,
279- 'custom-node__container__possibleDropTargets' :
280- dndDropProps . canDrop && dndDropProps . droppable && ! dndDropProps . hover ,
281- 'custom-node__container__draggable' : canDragNode ,
282- 'custom-node__container__draggedNode' : isDraggedNode ,
283- } }
302+ containerClassNames = { mainContainerClassNames }
284303 vizNode = { vizNode }
285304 tooltipContent = { tooltipContent }
286305 childCount = { childCount }
@@ -298,9 +317,7 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
298317 dataNodelabel = { label }
299318 transform = { `translate(${ boxXRef . current - box . x } , ${ boxYRef . current - box . y } )` }
300319 dataTestId = { `${ vizNode . id } -dummy` }
301- containerClassNames = { {
302- 'custom-node__container__draggedNode' : isDraggedNode ,
303- } }
320+ containerClassNames = { { 'custom-node__container__draggedNode' : isDraggedNode } }
304321 vizNode = { vizNode }
305322 tooltipContent = { tooltipContent }
306323 childCount = { childCount }
@@ -309,8 +326,9 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
309326 isDisabled = { isDisabled }
310327 />
311328 ) }
329+
312330 { /** This label, appears for the node which are not dragging */ }
313- { label && ( ( isDraggingNodeType && ! isDraggingNode ) || ( isDraggingGroupType && ! isDraggingWithinGroup ) ) && (
331+ { label && showLabelWhenDragging && (
314332 < CustomNodeLabel
315333 label = { label }
316334 doesHaveWarnings = { doesHaveWarnings }
@@ -341,7 +359,7 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
341359 />
342360 ) }
343361
344- { ! dndDropProps . droppable && shouldShowToolbar && hasSomeInteractions && (
362+ { showToolbarSection && (
345363 < Layer id = { TOP_LAYER } >
346364 < foreignObject
347365 ref = { toolbarHoverRef }
0 commit comments