Comments (8)
Are there any plans to add this feature?
from react-sortable-tree.
In startDrag
, remove all selected nodes from the tree, not just the one. This method produces the tree with all the dragged nodes removed, which will serve as a base when adding the nodes in at different spots during hover.
In dragHover
, we insert the node at the appropriate location in the tree. Currently the insertNode
tree util function only handles one node insert at a time, so you might want to modify the method to handle node array inserts as well as single node inserts. This applies to the moveNode
method as well (move node is the one that finally sets the data in place after dropping the element).
Also inside the dragHover
method, we do some row swapping so we can show the tree with the dragged nodes cut in like so:
See, this tree structure doesn't naturally occur when it shows exactly where the nodes end up. They end up going where the blue arrow points, but keeping the nodes in places results in a smoother dragging experience. To make this possible, I do row swapping, so every visible child of the dragged node gets moved right below the main dragged node. To make this work with multiple nodes, you'll need to calculate the number of visible children for each node, and probably do each swap independently. Something like:
+-O--AA
|
+-O--BB
| |
| +-O--CC
| | |
| | +-O--DD
| |
| +-O--EE
|
+-O--FF
Here, if you wanted to move CC and FF to the root level by
clicking both and dragging to the left at the height of CC,
you would end up with something like:
+-O--AA
|
+-O--BB
| |
##########
+-O--CC
| |
| +-O--DD
|
+-O--FF
##########
|
+-O--EE
(area between the pound signs is the dragged content)
I know this is a lot... if you're feeling at all discouraged, know I'm thankful for you just reading this far ;)
The next big area is inside drag-and-drop-utils.js
. You'll need to change the methods in here to handle multiple dragged nodes. An easy way to spot relevant areas is to look for draggedNode
. You'll need to alter the node
prop in react-sortable-tree.js
to change the reference from the single node to the multiple selected nodes.
You'll need to consider all the dragged nodes in the calculations against maxDepth
.
Finally (as far as I can tell), in node-renderer-default.js
, you'll need to check all of the dragged nodes to see if the node rendered is a child of one of them. This info is used to make child nodes semitransparent while dragging.
from react-sortable-tree.
Making the drag-and-drop ghost (/hovering thing) look like your image would be quite challenging, if not impossible, with the native drag-and-drop API. However, the other parts are feasible, like the movement of multiple things. The UI would probably need some tweaking to make it more obvious that such an action is possible (or currently happening).
I can understand the reasoning behind this feature, and if someone wants to make it I would support them and point them towards the relevant areas of the code.
from react-sortable-tree.
I'm no expert- but I'd like to contribute by giving it a try. Point me in the right direction
from react-sortable-tree.
@fritz-c wow! I did read all that, a few times over. I've had a poke around and didn't get very far with success. I am very new to react but my attempts were using this.state, and trying to assingn a keystroke to it. But no luck. Will this be a feature planned for later development?
from react-sortable-tree.
I don't have a roadmap drawn up for the development of this component, and will probably just be doing bug fixes in the near future. That being said, I think it's far from being perfect and could use improvements like the one you're talking about here. I'll leave this issue open and add a "Help Wanted" tag, and poll for the demand for this feature for now.
If you're new to React, working on this component might be a good chance to learn, but I wouldn't rush into it too quick. With a bit more time working with React on normal projects, I think you'll get the hang of it and have a much easier time looking through the code here.
from react-sortable-tree.
@steventebrinke I'm currently a little busy with work. Feel free to submit a PR
from react-sortable-tree.
@steventebrinke was a PR submitted for this?
from react-sortable-tree.
Related Issues (20)
- How to use props with redux ? HOT 1
- React version dependency issue HOT 5
- how to make search nodes only starting from one node which we clicked ?
- Is it possible to make the react sortable tree ui less big with a setting : sm, md, bg ?
- React dnd upgrade HOT 2
- How to customize move handler? 🤔 HOT 2
- div is fadeout when drag
- Insert node at specific index under parent node.Iindex HOT 1
- It is possible to use a node as ReactRef() ? HOT 1
- Give Children another label/property name
- Failed to minify the code error HOT 2
- getTreeFromFlatData set rootKey as null
- Support multiple dragging
- Option to snap automatically to nearest possible level HOT 1
- Support React 18 HOT 1
- new child is added to the parent when collapsing the parent HOT 1
- Using the react-sortable-tree in react 18 HOT 4
- is it possible to display the tree as a vertical tree diagram?
- About maintenance of this library
- Could not resolve dependency: React 18 with [email protected] HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-sortable-tree.