@@ -5,13 +5,16 @@ import styles from './tree-node.scss';
55const TreeNode = ( {
66 children,
77 listIndex,
8+ swapFrom,
9+ swapLength,
10+ swapDepth,
811 scaffoldBlockPxWidth,
912 lowerSiblingCounts,
1013 connectDropTarget,
1114 isOver,
1215 draggedNode,
1316 canDrop,
14- treeIndex : _treeIndex , // Delete from otherProps
17+ treeIndex,
1518 getPrevRow : _getPrevRow , // Delete from otherProps
1619 node : _node , // Delete from otherProps
1720 path : _path , // Delete from otherProps
@@ -21,7 +24,8 @@ const TreeNode = ({
2124} ) => {
2225 // Construct the scaffold representing the structure of the tree
2326 const scaffoldBlockCount = lowerSiblingCounts . length ;
24- const scaffold = lowerSiblingCounts . map ( ( lowerSiblingCount , i ) => {
27+ const scaffold = [ ] ;
28+ lowerSiblingCounts . forEach ( ( lowerSiblingCount , i ) => {
2529 let lineClass = '' ;
2630 if ( lowerSiblingCount > 0 ) {
2731 // At this level in the tree, the nodes had sibling nodes further down
@@ -69,13 +73,49 @@ const TreeNode = ({
6973 lineClass = `${ styles . lineHalfVerticalTop } ${ styles . lineHalfHorizontalRight } ` ;
7074 }
7175
72- return (
76+ scaffold . push (
7377 < div
7478 key = { `pre_${ i } ` }
7579 style = { { width : scaffoldBlockPxWidth } }
7680 className = { `${ styles . lineBlock } ${ lineClass } ` }
7781 />
7882 ) ;
83+
84+ if ( treeIndex !== listIndex ) {
85+ // This row has been shifted
86+ let highlightLineClass = '' ;
87+ if ( i === swapDepth ) {
88+ // This block is at the depth of the line pointing to the new destination
89+
90+ if ( listIndex === swapFrom + swapLength - 1 ) {
91+ // This block is on the bottom (target) line
92+ highlightLineClass = styles . highlightBottomLeftCorner ;
93+ } else if ( treeIndex === swapFrom ) {
94+ // This block is on the top (source) line
95+ highlightLineClass = styles . highlightTopLeftCorner ;
96+ } else {
97+ // This block is between the bottom and top
98+ highlightLineClass = styles . highlightLineVertical ;
99+ }
100+ } else if ( i === swapDepth + 1 && listIndex === swapFrom + swapLength - 1 ) {
101+ // This block points at the target block (where the row will go when released)
102+ highlightLineClass = styles . highlightArrow ;
103+ }
104+
105+ // Add the highlight line block if it met one of the conditions above
106+ if ( highlightLineClass ) {
107+ scaffold . push (
108+ < div
109+ key = { `highlight_${ i } ` }
110+ style = { {
111+ width : scaffoldBlockPxWidth ,
112+ left : scaffoldBlockPxWidth * i ,
113+ } }
114+ className = { `${ styles . absoluteLineBlock } ${ highlightLineClass } ` }
115+ />
116+ ) ;
117+ }
118+ }
79119 } ) ;
80120
81121 return connectDropTarget (
@@ -103,6 +143,9 @@ TreeNode.propTypes = {
103143 treeIndex : PropTypes . number . isRequired ,
104144 node : PropTypes . object . isRequired ,
105145 path : PropTypes . arrayOf ( PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ) . isRequired ,
146+ swapFrom : PropTypes . number ,
147+ swapDepth : PropTypes . number ,
148+ swapLength : PropTypes . number ,
106149 scaffoldBlockPxWidth : PropTypes . number . isRequired ,
107150 lowerSiblingCounts : PropTypes . array . isRequired ,
108151
0 commit comments