@@ -22,7 +22,7 @@ import {
2222 defaultGetNodeKey ,
2323 defaultSearchMethod ,
2424} from './utils/default-handlers'
25- import DndManager from './utils/dnd-manager'
25+ import { wrapPlaceholder , wrapSource , wrapTarget } from './utils/dnd-manager'
2626import { slideRows } from './utils/generic-utils'
2727import {
2828 memoizedGetDescendantCount ,
@@ -78,20 +78,26 @@ class ReactSortableTree extends Component {
7878 const { dndType, nodeContentRenderer, treeNodeRenderer, slideRegionSize } =
7979 mergeTheme ( props )
8080
81- this . dndManager = new DndManager ( this )
82-
8381 // Wrapping classes for use with react-dnd
8482 this . treeId = `rst__${ treeIdCounter } `
8583 treeIdCounter += 1
8684 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+ )
9197
9298 // Prepare scroll-on-drag options for this list
9399 this . scrollZoneVirtualList = ( createScrollingComponent || withScrolling ) (
94- React . forwardRef ( ( props ) => {
100+ React . forwardRef ( ( props , ref ) => {
95101 const { dragDropManager, ...otherProps } = props
96102 return < Virtuoso ref = { this . listRef } { ...otherProps } />
97103 } )
@@ -117,6 +123,20 @@ class ReactSortableTree extends Component {
117123 } ,
118124 }
119125
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+
120140 this . toggleChildrenVisibility = this . toggleChildrenVisibility . bind ( this )
121141 this . moveNode = this . moveNode . bind ( this )
122142 this . startDrag = this . startDrag . bind ( this )
@@ -351,7 +371,7 @@ class ReactSortableTree extends Component {
351371 return newState
352372 }
353373
354- startDrag ( { path } ) {
374+ startDrag = ( { path } ) => {
355375 this . setState ( ( prevState ) => {
356376 const {
357377 treeData : draggingTreeData ,
@@ -373,11 +393,11 @@ class ReactSortableTree extends Component {
373393 } )
374394 }
375395
376- dragHover ( {
396+ dragHover = ( {
377397 node : draggedNode ,
378398 depth : draggedDepth ,
379399 minimumTreeIndex : draggedMinimumTreeIndex ,
380- } ) {
400+ } ) => {
381401 // Ignore this hover if it is at the same position as the last hover
382402 if (
383403 this . state . draggedDepth === draggedDepth &&
@@ -421,7 +441,7 @@ class ReactSortableTree extends Component {
421441 } )
422442 }
423443
424- endDrag ( dropResult ) {
444+ endDrag = ( dropResult ) => {
425445 const { instanceProps } = this . state
426446
427447 const resetTree = ( ) =>
@@ -476,11 +496,11 @@ class ReactSortableTree extends Component {
476496 }
477497 }
478498
479- drop ( dropResult ) {
499+ drop = ( dropResult ) => {
480500 this . moveNode ( dropResult )
481501 }
482502
483- canNodeHaveChildren ( node ) {
503+ canNodeHaveChildren = ( node ) => {
484504 const { canNodeHaveChildren } = this . props
485505 if ( canNodeHaveChildren ) {
486506 return canNodeHaveChildren ( node )
0 commit comments