Skip to content

Commit 35a4ebb

Browse files
committed
Bump version
1 parent 967ca59 commit 35a4ebb

File tree

4 files changed

+460
-446
lines changed

4 files changed

+460
-446
lines changed

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nosferatu500/react-sortable-tree",
3-
"version": "4.0.0-beta.3",
3+
"version": "4.0.0-beta.4",
44
"description": "Drag-and-drop sortable component for nested data and hierarchies",
55
"main": "./index.js",
66
"types": "./index.d.ts",
@@ -135,14 +135,13 @@
135135
"@babel/plugin-transform-react-jsx": "^7.14.9",
136136
"@babel/preset-env": "^7.15.8",
137137
"@babel/types": "^7.15.6",
138-
"@nosferatu500/theme-file-explorer": "^3.0.9",
139138
"@rollup/plugin-babel": "^5.3.0",
140139
"@rollup/plugin-node-resolve": "^13.0.5",
141140
"@rollup/plugin-typescript": "^8.2.5",
142-
"@storybook/addon-storyshots": "^6.3.11",
143-
"@storybook/addons": "^6.3.11",
144-
"@storybook/react": "^6.3.11",
145-
"@storybook/theming": "^6.3.11",
141+
"@storybook/addon-storyshots": "^6.3.12",
142+
"@storybook/addons": "^6.3.12",
143+
"@storybook/react": "^6.3.12",
144+
"@storybook/theming": "^6.3.12",
146145
"@testing-library/react": "^12.1.2",
147146
"@types/babel-plugin-macros": "^2.8.5",
148147
"@types/enzyme": "^3.10.9",
@@ -162,7 +161,7 @@
162161
"eslint": "^8.0.1",
163162
"eslint-config-prettier": "^8.3.0",
164163
"eslint-plugin-import": "^2.25.2",
165-
"eslint-plugin-jest": "^25.0.5",
164+
"eslint-plugin-jest": "^25.0.6",
166165
"eslint-plugin-prettier": "^4.0.0",
167166
"eslint-plugin-react": "^7.26.1",
168167
"jest": "^27.2.5",

src/react-sortable-tree.tsx

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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'
2626
import { slideRows } from './utils/generic-utils'
2727
import {
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

Comments
 (0)