@@ -5,13 +5,16 @@ import styles from './tree-node.scss';
5
5
const TreeNode = ( {
6
6
children,
7
7
listIndex,
8
+ swapFrom,
9
+ swapLength,
10
+ swapDepth,
8
11
scaffoldBlockPxWidth,
9
12
lowerSiblingCounts,
10
13
connectDropTarget,
11
14
isOver,
12
15
draggedNode,
13
16
canDrop,
14
- treeIndex : _treeIndex , // Delete from otherProps
17
+ treeIndex,
15
18
getPrevRow : _getPrevRow , // Delete from otherProps
16
19
node : _node , // Delete from otherProps
17
20
path : _path , // Delete from otherProps
@@ -21,7 +24,8 @@ const TreeNode = ({
21
24
} ) => {
22
25
// Construct the scaffold representing the structure of the tree
23
26
const scaffoldBlockCount = lowerSiblingCounts . length ;
24
- const scaffold = lowerSiblingCounts . map ( ( lowerSiblingCount , i ) => {
27
+ const scaffold = [ ] ;
28
+ lowerSiblingCounts . forEach ( ( lowerSiblingCount , i ) => {
25
29
let lineClass = '' ;
26
30
if ( lowerSiblingCount > 0 ) {
27
31
// At this level in the tree, the nodes had sibling nodes further down
@@ -69,13 +73,49 @@ const TreeNode = ({
69
73
lineClass = `${ styles . lineHalfVerticalTop } ${ styles . lineHalfHorizontalRight } ` ;
70
74
}
71
75
72
- return (
76
+ scaffold . push (
73
77
< div
74
78
key = { `pre_${ i } ` }
75
79
style = { { width : scaffoldBlockPxWidth } }
76
80
className = { `${ styles . lineBlock } ${ lineClass } ` }
77
81
/>
78
82
) ;
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
+ }
79
119
} ) ;
80
120
81
121
return connectDropTarget (
@@ -103,6 +143,9 @@ TreeNode.propTypes = {
103
143
treeIndex : PropTypes . number . isRequired ,
104
144
node : PropTypes . object . isRequired ,
105
145
path : PropTypes . arrayOf ( PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ) . isRequired ,
146
+ swapFrom : PropTypes . number ,
147
+ swapDepth : PropTypes . number ,
148
+ swapLength : PropTypes . number ,
106
149
scaffoldBlockPxWidth : PropTypes . number . isRequired ,
107
150
lowerSiblingCounts : PropTypes . array . isRequired ,
108
151
0 commit comments