@@ -22,7 +22,7 @@ import {
22
22
defaultGetNodeKey ,
23
23
defaultSearchMethod ,
24
24
} from './utils/default-handlers'
25
- import DndManager from './utils/dnd-manager'
25
+ import { wrapPlaceholder , wrapSource , wrapTarget } from './utils/dnd-manager'
26
26
import { slideRows } from './utils/generic-utils'
27
27
import {
28
28
memoizedGetDescendantCount ,
@@ -78,20 +78,26 @@ class ReactSortableTree extends Component {
78
78
const { dndType, nodeContentRenderer, treeNodeRenderer, slideRegionSize } =
79
79
mergeTheme ( props )
80
80
81
- this . dndManager = new DndManager ( this )
82
-
83
81
// Wrapping classes for use with react-dnd
84
82
this . treeId = `rst__${ treeIdCounter } `
85
83
treeIdCounter += 1
86
84
this . dndType = dndType || this . treeId
87
- this . nodeContentRenderer = this . dndManager . wrapSource ( nodeContentRenderer )
88
- this . treePlaceholderRenderer =
89
- this . dndManager . wrapPlaceholder ( TreePlaceholder )
90
- this . treeNodeRenderer = this . dndManager . wrapTarget ( treeNodeRenderer )
85
+ this . nodeContentRenderer = wrapSource (
86
+ nodeContentRenderer ,
87
+ this . startDrag ,
88
+ this . endDrag ,
89
+ this . dndType
90
+ )
91
+ this . treePlaceholderRenderer = wrapPlaceholder (
92
+ TreePlaceholder ,
93
+ this . treeId ,
94
+ this . drop ,
95
+ this . dndType
96
+ )
91
97
92
98
// Prepare scroll-on-drag options for this list
93
99
this . scrollZoneVirtualList = ( createScrollingComponent || withScrolling ) (
94
- React . forwardRef ( ( props ) => {
100
+ React . forwardRef ( ( props , ref ) => {
95
101
const { dragDropManager, ...otherProps } = props
96
102
return < Virtuoso ref = { this . listRef } { ...otherProps } />
97
103
} )
@@ -117,6 +123,20 @@ class ReactSortableTree extends Component {
117
123
} ,
118
124
}
119
125
126
+ this . treeNodeRenderer = wrapTarget (
127
+ treeNodeRenderer ,
128
+ this . canNodeHaveChildren ,
129
+ this . treeId ,
130
+ this . props . maxDepth ,
131
+ this . props . canDrop ,
132
+ this . drop ,
133
+ this . dragHover ,
134
+ this . dndType ,
135
+ this . state . draggingTreeData ,
136
+ this . props . treeData ,
137
+ this . props . getNodeKey
138
+ )
139
+
120
140
this . toggleChildrenVisibility = this . toggleChildrenVisibility . bind ( this )
121
141
this . moveNode = this . moveNode . bind ( this )
122
142
this . startDrag = this . startDrag . bind ( this )
@@ -351,7 +371,7 @@ class ReactSortableTree extends Component {
351
371
return newState
352
372
}
353
373
354
- startDrag ( { path } ) {
374
+ startDrag = ( { path } ) => {
355
375
this . setState ( ( prevState ) => {
356
376
const {
357
377
treeData : draggingTreeData ,
@@ -373,11 +393,11 @@ class ReactSortableTree extends Component {
373
393
} )
374
394
}
375
395
376
- dragHover ( {
396
+ dragHover = ( {
377
397
node : draggedNode ,
378
398
depth : draggedDepth ,
379
399
minimumTreeIndex : draggedMinimumTreeIndex ,
380
- } ) {
400
+ } ) => {
381
401
// Ignore this hover if it is at the same position as the last hover
382
402
if (
383
403
this . state . draggedDepth === draggedDepth &&
@@ -421,7 +441,7 @@ class ReactSortableTree extends Component {
421
441
} )
422
442
}
423
443
424
- endDrag ( dropResult ) {
444
+ endDrag = ( dropResult ) => {
425
445
const { instanceProps } = this . state
426
446
427
447
const resetTree = ( ) =>
@@ -476,11 +496,11 @@ class ReactSortableTree extends Component {
476
496
}
477
497
}
478
498
479
- drop ( dropResult ) {
499
+ drop = ( dropResult ) => {
480
500
this . moveNode ( dropResult )
481
501
}
482
502
483
- canNodeHaveChildren ( node ) {
503
+ canNodeHaveChildren = ( node ) => {
484
504
const { canNodeHaveChildren } = this . props
485
505
if ( canNodeHaveChildren ) {
486
506
return canNodeHaveChildren ( node )
0 commit comments