lytc / react-sortly Goto Github PK
View Code? Open in Web Editor NEWReact nested sortable component
Home Page: https://lytc.github.io/react-sortly
React nested sortable component
Home Page: https://lytc.github.io/react-sortly
Great library!
I'm trying to create a list that only allows one level of nesting. I've tried setting maxDepth
to 0, 1 and 2 each each value seems to allow for an infinite level of nesting. Is there a working example using maxDepth
?
Hi, may you please provide code for your examples https://lytc.github.io/react-sortly/#/examples
I want create Multiple Tree, as in your example here https://lytc.github.io/react-sortly/#/examples/multiple-tree
but I can't do it without example code ((
I have set the maxDepth on 1. So I can make a structure of that's only two layers deep. But when I'm able to drag two layers deep on a second layer so the structure is three layers deep. and that's not what I want...
Hi there,
Frist off - I'm loving Sortly. I'm making use of it in a Meteor app I'm hacking together as a prof of concept.
One thing I'm having a problem with though. My itemRenderer renders multiple times, even with no prop changes and I was wondering if you could help cast a little light on things....
I've tried to use React.memo with a custom equal function, but even with that, and equal props, I still get the problem (I noted that in one of your examples, you used Reac.memo, and I'm assuming the same problem exists in that too).
I think it all comes down to the hooks. I'm using useDrag and useDrop hooks. I think they always return different functions, and therefore cause a re-render. Not sure if they need to work like this or if there is some tweak I can make to prevent it. I'm not massively familiar with React or even Javascript (part of the reason I'm making my app is to learn).
Any thoughts?
Hello, really this is very light weight and it's amazing . Is there any UMD build !?
Im encountering this error when trying to test my project if I have sortly enabled
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
C:\Workspaces\myProject\frontend\node_modules\react-sortly\lib\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Sortly from './Sortly';
^^^^^^
As DND package is updated (and since this one imports *
dnd version), the sample usage is no longer working. DND package does not export DragDropContext
.
@lytc is this package still supported?
This feature will be useful when adding elements to the state without first sending them to the server to obtain a unique identifier
Seems like there is a wrong documentation for the convert util function, I tried to use it and it didn't work, e.g:
const items = [
{id: 1, parentId: null, index: 0, name: "Categories"},
{id: 2, parentId: null, index: 1, name: "Brand"},
{id: 3, parentId: 1, index: 0, name: "Bags"},
{id: 4, parentId: 1, index: 1, name: "Mugs"},
{id: 5, parentId: 1, index: 2, name: "Clothing"},
{id: 8, parentId: 2, index: 0, name: "Ruby"},
{id: 9, parentId: 2, index: 1, name: "Apache"},
{id: 10, parentId: 2, index: 2, name: "Spree"},
{id: 11, parentId: 2, index: 3, name: "Rails"}
];
const convertedItems = convert(items);
The result for convertedItems
is an empty array.
Solution
The thing is that the database data must not have null
as a parentId
for the first level items.
The data must look something like this:
const items = [
{id: 1, parentId: 0, index: 0, name: "Categories"},
{id: 2, parentId: 0, index: 1, name: "Brand"},
{id: 3, parentId: 1, index: 0, name: "Bags"},
{id: 4, parentId: 1, index: 1, name: "Mugs"},
{id: 5, parentId: 1, index: 2, name: "Clothing"},
{id: 8, parentId: 2, index: 0, name: "Ruby"},
{id: 9, parentId: 2, index: 1, name: "Apache"},
{id: 10, parentId: 2, index: 2, name: "Spree"},
{id: 11, parentId: 2, index: 3, name: "Rails"}
];
demo example is wrong HTML5Backend doesn't export as default need to be use between the curly brackets. Second issue appeared saying drop is not a function shortly library not working properly and demo examples are thrown errors
Invariant Violation: useDrag::spec.begin was deprecated in v14. Replace spec.begin() with spec.item(). (see more here - https://react-dnd.github.io/react-dnd/docs/api/use-drag)
"react": "^18.2.0",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-sortly": "^3.0.4",
Hi there!
We're interested in using react-sortly for a project, it looks like a nice wrapper around react-dnd. However, I'm worried there's no LICENSE on the project (other than in package.json). Can you clarify what the license is for this code? Thanks!
besides that it looks really nice and smooth, I like it
With ES-6 react-dnd shows error for export, had to edit build files to get it working.
Changed react-dnd to react-dnd-cjs
It seems that this has a functionality issue that renders it unusable for my use scenario:
If you have several depth elements and you try to move them back and forth, it will only allow you to move the last element with a certain depth. So If I have a scenario like the attached printscreen, it will only allow me to move element number 3, and not 1 and 2.
Is this the way it should work?
Current behaviour:
Selecting any element disables scrolling ability. Only possibility now is to find that sweet spot on bottom and top of the screen but thats sometimes very hard/unusable for example with few nested set items dragging
Expected behaviour:
Ability to use scroll or up/down arrow while dragging.
My solution:
i was looking around for this feature and only thread i found was react-dnd/react-dnd#553
Im lookin on to that.
As you figured I run unit tests using jest and enzyme.
Problem is that item renderer isn't triggered even, when component is mounted. So I can't make tests against rendered item.
FYI, I'm not writing tests for this lib. I'm writing tests in my own project, where react-sortly is used inside some components.
Hi there,
I've run into a bit of an issue with my app when it comes to longer lists - horrible lag! Nothing to do with react-sortly, it's just that the list I'm rendering has some quite heavy items in it.
I was wondering if you could add some virtualisation to Sortly?
I've had a play with virtualising my list (Virtuoso) and it makes my longer lists that were taking 2seconds to mount/dismount as good as instant!
Unfortunately, I can't get Sortly and Virtuoso to play nice together, so in my tests, I removed Sortly. But if virtualisation could be built-in, this would be a massive improvement.
Any thoughts?
Is it possible to support React from version 17?
currently react-sortly needs a peer Dependency of react@"^16.10.1".
This keeps us from using your package.
Kind regards
I think it will be a great feature if a tree node with children can be collapsed the same way it can be expanded.
I am trying to restrict the nesting so that items at the top level and one level below can only be sorted. Furthermore for deeper nested items (path.length > 1) it should not be possible to drop them as first or second level item. To accomplish that I use the onMove handler to check the dragged items path against it's original items path. The handler looks something like this:
const onMove = (newItems, dragIndex, newIndex) => {
const draggedItem = newItems[newIndex];
const originalItem = items.find(({ id }) => id === draggedItem.id);
if (!originalItem) {
return false; // Just to assure originalItem was found...
}
const originalNestingLevel = originalItem.path.length;
const newNestingLevel = draggedItem.path.length;
// Prevent changing the nesting for items with path.length <= 1
if (originalNestingLevel <= 1 && originalNestingLevel !== newNestingLevel) {
return false;
}
// Prevent changing the nesting for items with path.length > 1
// to path.length <= 1
if (originalNestingLevel > 1 && newNestingLevel <= 1) {
return false;
}
return true;
};
The sort only part works perfectly fine.
The nesting part also works fine when items at the second level (path.length = 1) have children. However if they don't have any children it is not possible to drag a deeper nested item from another second level item below this childless item for some reason.
Do you have any ideas how to solve this problem?
Thanks in advance and thanks for this awesome component.
I was looking ages for nested dnd.
As of Feb 7, this repository has been marked read-only since it got merged into react-dnd (see
react-dnd/react-dnd-html5-backend@1d7573c)
Apparently some of the dependencies are not being resolved correctly when using yarn.
I had to install immutability-helper
and use-debounce
manually to get sortly to work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.