Giter Site home page Giter Site logo

frontend-collective / react-sortable-tree Goto Github PK

View Code? Open in Web Editor NEW
4.9K 63.0 899.0 15.39 MB

Drag-and-drop sortable component for nested data and hierarchies

Home Page: https://frontend-collective.github.io/react-sortable-tree/

License: MIT License

JavaScript 92.61% CSS 7.39%
tree-data react drag-and-drop hierarchical-data sortable component tree

react-sortable-tree's Introduction

Note on maintenance

This library is not actively maintained. Please find and discuss alternatives here.

React Sortable Tree

NPM version NPM license NPM total downloads NPM monthly downloads Build Status Coverage Status PRs Welcome

A React component for Drag-and-drop sortable representation of hierarchical data. Checkout the Storybook for a demonstration of some basic and advanced features.

Table of Contents

Getting started

Install react-sortable-tree using npm.

# NPM
npm install react-sortable-tree --save

# YARN
yarn add react-sortable-tree

ES6 and CommonJS builds are available with each distribution. For example:

// This only needs to be done once; probably during your application's bootstrapping process.
import 'react-sortable-tree/style.css';

// You can import the default tree with dnd context
import SortableTree from 'react-sortable-tree';

// Or you can import the tree without the dnd context as a named export. eg
import { SortableTreeWithoutDndContext as SortableTree } from 'react-sortable-tree';

// Importing from cjs (default)
import SortableTree from 'react-sortable-tree/dist/index.cjs.js';
import SortableTree from 'react-sortable-tree';

// Importing from esm
import SortableTree from 'react-sortable-tree/dist/index.esm.js';

Usage

import React, { Component } from 'react';
import SortableTree from 'react-sortable-tree';
import 'react-sortable-tree/style.css'; // This only needs to be imported once in your app

export default class Tree extends Component {
  constructor(props) {
    super(props);

    this.state = {
      treeData: [
        { title: 'Chicken', children: [{ title: 'Egg' }] },
        { title: 'Fish', children: [{ title: 'fingerline' }] },
      ],
    };
  }

  render() {
    return (
      <div style={{ height: 400 }}>
        <SortableTree
          treeData={this.state.treeData}
          onChange={treeData => this.setState({ treeData })}
        />
      </div>
    );
  }
}

Props

Prop Type
Description
treeData
(required)
object[] Tree data with the following keys:
title is the primary label for the node.
subtitle is a secondary label for the node.
expanded shows children of the node if true, or hides them if false. Defaults to false.
children is an array of child nodes belonging to the node.
Example: [{title: 'main', subtitle: 'sub'}, { title: 'value2', expanded: true, children: [{ title: 'value3') }] }]
onChange
(required)
func Called whenever tree data changed. Just like with React input elements, you have to update your own component's data to see the changes reflected.
( treeData: object[] ): void
getNodeKey
(recommended)
func Specify the unique key used to identify each node and generate the path array passed in callbacks. With a setting of getNodeKey={({ node }) => node.id}, for example, in callbacks this will let you easily determine that the node with an id of 35 is (or has just become) a child of the node with an id of 12, which is a child of ... and so on. It uses defaultGetNodeKey by default, which returns the index in the tree (omitting hidden nodes).
({ node: object, treeIndex: number }): string or number
generateNodeProps func Generate an object with additional props to be passed to the node renderer. Use this for adding buttons via the buttons key, or additional style / className settings.
({ node: object, path: number[] or string[], treeIndex: number, lowerSiblingCounts: number[], isSearchMatch: bool, isSearchFocus: bool }): object
onMoveNode func Called after node move operation.
({ treeData: object[], node: object, nextParentNode: object, prevPath: number[] or string[], prevTreeIndex: number, nextPath: number[] or string[], nextTreeIndex: number }): void
onVisibilityToggle func Called after children nodes collapsed or expanded.
({ treeData: object[], node: object, expanded: bool, path: number[] or string[] }): void
onDragStateChanged func Called when a drag is initiated or ended.
({ isDragging: bool, draggedNode: object }): void
maxDepth number Maximum depth nodes can be inserted at. Defaults to infinite.
rowDirection string Adds row direction support if set to 'rtl' Defaults to 'ltr'.
canDrag func or bool Return false from callback to prevent node from dragging, by hiding the drag handle. Set prop to false to disable dragging on all nodes. Defaults to true.
({ node: object, path: number[] or string[], treeIndex: number, lowerSiblingCounts: number[], isSearchMatch: bool, isSearchFocus: bool }): bool
canDrop func Return false to prevent node from dropping in the given location.
({ node: object, prevPath: number[] or string[], prevParent: object, prevTreeIndex: number, nextPath: number[] or string[], nextParent: object, nextTreeIndex: number }): bool
canNodeHaveChildren func Function to determine whether a node can have children, useful for preventing hover preview when you have a canDrop condition. Default is set to a function that returns true. Functions should be of type (node): bool.
theme object Set an all-in-one packaged appearance for the tree. See the Themes section for more information.
searchMethod func The method used to search nodes. Defaults to defaultSearchMethod, which uses the searchQuery string to search for nodes with matching title or subtitle values. NOTE: Changing searchMethod will not update the search, but changing the searchQuery will.
({ node: object, path: number[] or string[], treeIndex: number, searchQuery: any }): bool
searchQuery string or any Used by the searchMethod to highlight and scroll to matched nodes. Should be a string for the default searchMethod, but can be anything when using a custom search. Defaults to null.
searchFocusOffset number Outline the <searchFocusOffset>th node and scroll to it.
onlyExpandSearchedNodes boolean Only expand the nodes that match searches. Collapses all other nodes. Defaults to false.
searchFinishCallback func Get the nodes that match the search criteria. Used for counting total matches, etc.
(matches: { node: object, path: number[] or string[], treeIndex: number }[]): void
dndType string String value used by react-dnd (see overview at the link) for dropTargets and dragSources types. If not set explicitly, a default value is applied by react-sortable-tree for you for its internal use. NOTE: Must be explicitly set and the same value used in order for correct functioning of external nodes
shouldCopyOnOutsideDrop func or bool Return true, or a callback returning true, and dropping nodes to react-dnd drop targets outside of the tree will not remove them from the tree. Defaults to false.
({ node: object, prevPath: number[] or string[], prevTreeIndex: number, }): bool
reactVirtualizedListProps object Custom properties to hand to the internal react-virtualized List
style object Style applied to the container wrapping the tree (style defaults to {height: '100%'})
innerStyle object Style applied to the inner, scrollable container (for padding, etc.)
className string Class name for the container wrapping the tree
rowHeight number or func Used by react-sortable-tree. Defaults to 62. Either a fixed row height (number) or a function that returns the height of a row given its index: ({ treeIndex: number, node: object, path: number[] or string[] }): number
slideRegionSize number Size in px of the region near the edges that initiates scrolling on dragover. Defaults to 100.
scaffoldBlockPxWidth number The width of the blocks containing the lines representing the structure of the tree. Defaults to 44.
isVirtualized bool Set to false to disable virtualization. Defaults to true. NOTE: Auto-scrolling while dragging, and scrolling to the searchFocusOffset will be disabled.
nodeContentRenderer any Override the default component (NodeRendererDefault) for rendering nodes (but keep the scaffolding generator). This is a last resort for customization - most custom styling should be able to be solved with generateNodeProps, a theme or CSS rules. If you must use it, is best to copy the component in node-renderer-default.js to use as a base, and customize as needed.
placeholderRenderer any Override the default placeholder component (PlaceholderRendererDefault) which is displayed when the tree is empty. This is an advanced option, and in most cases should probably be solved with a theme or custom CSS instead.

Data Helper Functions

Need a hand turning your flat data into nested tree data? Want to perform add/remove operations on the tree data without creating your own recursive function? Check out the helper functions exported from tree-data-utils.js.

  • getTreeFromFlatData: Convert flat data (like that from a database) into nested tree data.
  • getFlatDataFromTree: Convert tree data back to flat data.
  • addNodeUnderParent: Add a node under the parent node at the given path.
  • removeNode: For a given path, get the node at that path, treeIndex, and the treeData with that node removed.
  • removeNodeAtPath: For a given path, remove the node and return the treeData.
  • changeNodeAtPath: Modify the node object at the given path.
  • map: Perform a change on every node in the tree.
  • walk: Visit every node in the tree in order.
  • getDescendantCount: Count how many descendants this node has.
  • getVisibleNodeCount: Count how many visible descendants this node has.
  • getVisibleNodeInfoAtIndex: Get the th visible node in the tree data.
  • toggleExpandedForAll: Expand or close every node in the tree.
  • getNodeAtPath: Get the node at the input path.
  • insertNode: Insert the input node at the specified depth and minimumTreeIndex.
  • find: Find nodes matching a search query in the tree.
  • isDescendant: Check if a node is a descendant of another node.
  • getDepth: Get the longest path in the tree.

Themes

Using the theme prop along with an imported theme module, you can easily override the default appearance with another standard one.

Featured themes

File Explorer Theme Full Node Drag Theme MINIMAL THEME
File Explorer Full Node Drag Minimalistic theme inspired from MATERIAL UI
react-sortable-tree-theme-file-explorer react-sortable-tree-theme-full-node-drag react-sortable-tree-theme-minimal
Github | NPM Github | NPM Github | NPM

Help Wanted - As the themes feature has just been enabled, there are very few (only two at the time of this writing) theme modules available. If you've customized the appearance of your tree to be especially cool or easy to use, I would be happy to feature it in this readme with a link to the Github repo and NPM page if you convert it to a theme. You can use my file explorer theme repo as a template to plug in your own stuff.

Browser Compatibility

Browser Works?
Chrome Yes
Firefox Yes
Safari Yes
IE 11 Yes

Troubleshooting

If it throws "TypeError: fn is not a function" errors in production

This issue may be related to an ongoing incompatibility between UglifyJS and Webpack's behavior. See an explanation at create-react-app#2376.

The simplest way to mitigate this issue is by adding comparisons: false to your Uglify config as seen here: https://github.com/facebookincubator/create-react-app/pull/2379/files

If it doesn't work with other components that use react-dnd

react-dnd only allows for one DragDropContext at a time (see: react-dnd/react-dnd#186). To get around this, you can import the context-less tree component via SortableTreeWithoutDndContext.

// before
import SortableTree from 'react-sortable-tree';

// after
import { SortableTreeWithoutDndContext as SortableTree } from 'react-sortable-tree';

Contributing

Please read the Code of Conduct. I actively welcome pull requests :)

After cloning the repository and running yarn install inside, you can use the following commands to develop and build the project.

# Starts a webpack dev server that hosts a demo page with the component.
# It uses react-hot-loader so changes are reflected on save.
yarn start

# Start the storybook, which has several different examples to play with.
# Also hot-reloaded.
yarn run storybook

# Runs the library tests
yarn test

# Lints the code with eslint
yarn run lint

# Lints and builds the code, placing the result in the dist directory.
# This build is necessary to reflect changes if you're
#  `npm link`-ed to this repository from another local project.
yarn run build

Pull requests are welcome!

License

MIT

react-sortable-tree's People

Contributors

bpneal avatar dependabot-preview[bot] avatar dependabot[bot] avatar dolezel avatar dotku avatar ephemera avatar fritz-c avatar gabiaxel avatar hannah avatar hgalexx avatar ksaxberg avatar kserjey avatar lifejuggler avatar manuelmager avatar matheusmatos avatar megaboich avatar mottox2 avatar mziserman avatar quigleyj-mavenomics avatar sgoll avatar sheile avatar shorif2000 avatar simperfit avatar sphire avatar stephenc222 avatar tdyp avatar tiff avatar weirdozzz avatar wombleton avatar wuweiweiwu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-sortable-tree's Issues

Export ReactSortableTree

Hey fritz-c

Thanks very much for the great module! I had been looking for something like this for long.

I wanted to check with you if you mind exporting ReactSortableTree.

This is needed to get around react-dnd/react-dnd#186. In my case I'm using ctxhou/react-tabtab on the same page along with react-sortable-tree, and it throws this error.

If ReactSortableTree is exported I think I can pass in a custom DragDropContext as described in readme of react-tabtab .

What is the best way to render Tree using custom Tree Object JSON

Hi,
I am having the Tree Data in this format. (eg. {name: ..., users: [ ... ]})

[ { 'id': '1', 'name': 'Value1', 'users': [ { 'name': 'Value2',  }, { 'name': 'Value3', 'users': [ { 'name': 'Value4',  } ] }, { 'name': 'Value4', 'users': [ { 'name': 'Value5',  } ] }, { 'name': 'Value5',  }, { 'name': 'Value6', 'users': [ { 'name': 'Value7',  } ] } ] } ]

What is the best way to convert it into required TreeData format?
(like: {title: ..., children:[ ... ]}))

Can we use nodeRenderer to achieve this?

Thanks
Anil

No auto-scroll on drag

Excluding Google Chrome, which scrolls elements when you drag child elements inside them, no browsers move the screen when you drag the element near the outer edge.

preventing some children from being parents

Just evaluating this to see if it will work for my situation. Is there any way I can prevent some children from being parents? Also, can I supply metadata beyond title, subtitle, etc. Can I have different types of nodes that render differently?

Mobile/touch friendly

Hi Fritz,

This looks fantastic! This doesn't seem to work with touch devices (I'm using Safari and Chrome on mobile).

Is there a way to do this or is this something that may happen in the future? Thanks

Cannot resolve module 'react/lib/ReactMount'

affected by this issue:

gaearon/react-hot-loader#417

> npm start

> [email protected] start /Users/rngadam/EIC/src/react-sortable-tree
> cross-env NODE_ENV=development webpack-dev-server --hot --inline --config webpack.config.dev.babel.js

 http://localhost:3001/
webpack result is served from /
content is served from build
webpack: wait until bundle finished: /
webpack: wait until bundle finished: /
Time: 6296ms

ERROR in ./src/examples/basicExample/app.js
Module not found: Error: Cannot resolve module 'react/lib/ReactMount' in /Users/rngadam/EIC/src/react-sortable-tree/src/examples/basicExample
 @ ./src/examples/basicExample/app.js 1:318-349
[...many more similar errors...] 

I tried updating to react-hot-loader 3.x but was not successful.

WORKAROUND: modify node_modules/react-hot-loader/index.js from:

'ReactMount = require("react/lib/ReactMount"),'

to

'ReactMount = require("react-dom/lib/ReactMount"),'

Allow for better visual customization

Hi, thank you for your plugin, it looks really cool.

One thing I noticed is, it puts a lot of styles as inline styles and thus I'm unable to style the tree to my needs. I want to hide lines and change the height of the row, but with the inline styles in place, I'm unable to do so.

Do you have any recommendation?

Thank you,
Ondrej

markup

Disable dragging of nodes

Hello,

Thank you for that awesome component. I realize I can maintain the state of my tree if I simply do not update the state on change, but is it possible to disable the dragging of nodes?

rowHeight problem

Hi, I have a problem with your plugin when I send the function like rowHeight props. I investigated that problem in https://github.com/fritz-c/react-sortable-tree/blob/master/src/react-sortable-tree.js#L360 when you send this props like estimatedRowSize props.
And in react-virtualized package I found next code:

export default class List extends Component {
  static propTypes = {
    /**
     * Used to estimate the total height of a List before all of its rows have actually been measured.
     * The estimated total height is adjusted as rows are rendered.
     */
    estimatedRowSize: PropTypes.number.isRequired,

    /**
     * Either a fixed row height (number) or a function that returns the height of a row given its index.
     * ({ index: number }): number
     */
    rowHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.func]).isRequired,

So rowHeight can be a function but estimatedRowSize don't.
Can you fix this? Looks like you need to send some const value to estimatedRowSize props in react-sortable-tree.js#L360 against rowHeight. For example you can send 64 * rows.length and it will work great

Replacing 'path' with own identifier

Hi,

I am trying to user a different 'identified' on my JSON to sort and view my data.

My data has a key taglevel which I would like to user as substitute for path 0, 1. The logic would have to create an integer to make it fit without your framework.

I've had a long look in your basicExample/app.js and but my attempts have been unsuccessful.

For the case of my data- the position (vertically) is not important. Only the indentation is important (ie how far 'in').

Does that make sense?

Can you give me some guidance?

{
        "title": "Into the Wild",
        "tag": [
            {
                "name": "Movie",
                "taglevel": 1,
                "id": 1
            },
            {
                "name": "Adventure",
                "taglevel": 2,
                "id": 30
            },
            {
                "name": "Book",
                "taglevel": 1,
                "id": 2
            }
        ],
        "info": []
    },
    {
        "title": "Karate Kid",
        "tag": [
            {
                "name": "Movie",
                "taglevel": 1,
                "id": 1
            },
            {
                "name": "Blockbuster",
                "taglevel": 2,
                "id": 29
            },
            {
                "name": "Kids",
                "taglevel": 3,
                "id": 4
            }
        ],
        "info": []
    },
        {
        "title": "The Alchemist",
        "tag": [
            {
                "name": "Book",
                "taglevel": 1,
                "id": 2
            },
            {
                "name": "Adventure",
                "taglevel": 2,
                "id": 30
            },
            {
                "name": "Classic",
                "taglevel": 2,
                "id": 4
            },
            {
                "name": "Words",
                "taglevel": 4,
                "id": 4
            }
        ],
        "info": []
    }

Modifying treeData in state does not trigger an onChange or other event.

Adding a node to the treeData outside of the component and modifying state. I'd like it to trigger a event to know that data has changed. It takes expanding/collapsing or moving an item for the UI to reflect this.

Ideally this should happen when state changes (treeData). Am I doing something dumb? Do I have to explicitly trigger an event?

Any help appreciated, thanks.

Port to React Native

Would it theoretically possible to port this to React Native?
What would be the steps?
Thank you.

Configure the tree to size itself according to its contents (disable virtualization?)

As far as I can tell, it's impossible to configure the tree to size itself according to its contents. It always requires a fixed height container. That, of course, makes sense when the tree is virtualized.

I would like to get a tree that sizes itself to its contents and when the content overflows the page, then the page scrollbars appear. As I understand it, I need to eviscerate the virtualization functionality. Is there a better way, like a switch or something?

Multiple tree sharing data

Hi,

is it possible to have 2 trees, one being a source (for example 40 non nested "nodes"), and other being destination where source nodes could be dragged into and added (copy) dynamically? Is this something possible by default or needs additional implementation?

Regards

add new nodes from a list

Hi, I've a small project where I've a list of items and I need than they can be dragged for build a tree..like

item1
item2
item3
item4

drag to create

item2
  |
    item1
     |
      item2
      item3
        |
        item4
        item1

do you think than this could be possible using react-sortable-tree?

thank you so much

onMoveNode doesn't seem to pass treeIndex or path.

Capturing an onMoveNode event so I can send an ajax call. I was expecting { treeData, node, treeIndex, path } but only see treeData and node coming in. It's therefore difficult to determine the parent and I'd rather not have to do another search for a match by an id. Let me know if I am missing something!

[Question] How can I use the path info when I am in onMoveNode

Hi @fritz-c ,
Nice package. I am trying to get a destination index for the node in onMoveNode function, as readme says, I can get a treeData, an index, a path, and the node it self as parameters when I call onMoveNode function. My problem is I try to get the node position I moved to, for example treeData[0].children[1].children[3] is the new position of the node, so I want something like [0, 1, 3] to let me find the node in the new treeData. The path in the onMoveNode is including tree expanded node like [8, 13, 20]. Is there anyway I can omitting both hidden nodes and expanded nodes to create path?

Thank you!

Hide non-matching items in search

From #8:

Another quick question. With the search function- is it possible that it "Hides" items which don't match the search? This could be a clean way to arrange similar items?

path in removeNode

I try remove my Node, how I can get path in my case?

export default class TreeVera extends Component {
    constructor(props) {
        super(props);
        this.updateTreeData = this.updateTreeData.bind(this);
        this.removeNode = this.removeNode.bind(this);
        this.state = {
            treeData: [{
                title: (<div>
                        <input />
                        <button onClick={this.removeNode}>remove</button>
                    </div>),
            }]
        };
    }
    removeNode(e){
        this.setState({
               treeData: removeNodeAtPath({
                   treeData: this.state.treeData,
                   path: ????,
                   getNodeKey: ({node: TreeNode, treeIndex: number}) => {
                       console.log(number);
                       return number;
                   },
                   ignoreCollapsed: false,
               })
        })
    }
    updateTreeData(treeData) {
        this.setState({ treeData });
    }
    render() {
        return (
            <div style={{ height: 600 }}>
                <SortableTree
                    treeData={this.state.treeData}
                    onChange={this.updateTreeData}
                />
            </div>
        );
    }
}

`canDrop` API

The component needs an api to control where certain nodes can be dropped in the tree.

Git example not working

We are using the example code below from your main doc. It seems to throw the following errors. Any ideas what we are missing?

Cheers,
Mike

import SortableTree from 'react-sortable-tree';

export default class BluePrint extends Component {
    constructor(props) {
        super(props);

        this.state = {
            treeData: [{ title: 'Chicken', children: [ { title: 'Egg' } ] }],
        };
    }

    render() {
        return (
            <div style={{ height: 400 }}>
                <SortableTree
                    treeData={this.state.treeData}
                    onChange={treeData => this.setState({ treeData })}
                />
            </div>
        );
    }
}```



ERROR in /Users/mikepriest//react-sortable-tree/dist/umd/react-sortable-tree.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-sortable-tree/dist/umd
@ /Users/mikepriest/
/react-sortable-tree/dist/umd/react-sortable-tree.js 2:87-103

ERROR in /Users/mikepriest//react-dnd-scrollzone/lib/index.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-dnd-scrollzone/lib
@ /Users/mikepriest/
/react-dnd-scrollzone/lib/index.js 16:13-29

ERROR in /Users/mikepriest//react-dnd-scrollzone/lib/index.js
Module not found: Error: Cannot resolve module 'react-dom' in /Users/mikepriest/node_modules/react-dnd-scrollzone/lib
@ /Users/mikepriest/
/react-dnd-scrollzone/lib/index.js 20:16-36

ERROR in /Users/mikepriest//react-dnd/lib/DragDropContext.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-dnd/lib
@ /Users/mikepriest/
/react-dnd/lib/DragDropContext.js 19:13-29

ERROR in /Users/mikepriest//react-dnd/lib/DragLayer.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-dnd/lib
@ /Users/mikepriest/
/react-dnd/lib/DragLayer.js 19:13-29

ERROR in /Users/mikepriest//react-dnd/lib/decorateHandler.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-dnd/lib
@ /Users/mikepriest/
/react-dnd/lib/decorateHandler.js 17:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/ArrowKeyStepper
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js 9:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/ArrowKeyStepper
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js 13:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/AutoSizer/AutoSizer.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/AutoSizer
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/AutoSizer/AutoSizer.js 9:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/AutoSizer/AutoSizer.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/AutoSizer
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/AutoSizer/AutoSizer.js 13:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/CellMeasurer/CellMeasurer.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/CellMeasurer
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/CellMeasurer/CellMeasurer.js 9:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/CellMeasurer/CellMeasurer.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/CellMeasurer
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/CellMeasurer/CellMeasurer.js 13:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/CellMeasurer/CellMeasurer.js
Module not found: Error: Cannot resolve module 'react-dom' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/CellMeasurer
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/CellMeasurer/CellMeasurer.js 17:16-36

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Collection/Collection.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Collection
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Collection/Collection.js 11:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Collection/Collection.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Collection
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Collection/Collection.js 27:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Table/Table.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Table
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Table/Table.js 19:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Table/Table.js
Module not found: Error: Cannot resolve module 'react-dom' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Table
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Table/Table.js 23:16-36

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Table/Table.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Table
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Table/Table.js 25:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Table/defaultHeaderRenderer.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Table
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Table/defaultHeaderRenderer.js 8:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Table/defaultRowRenderer.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Table
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Table/defaultRowRenderer.js 11:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Table/Column.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Table
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Table/Column.js 7:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Table/SortIndicator.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Table
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Table/SortIndicator.js 8:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/ColumnSizer/ColumnSizer.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/ColumnSizer
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/ColumnSizer/ColumnSizer.js 9:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/ColumnSizer/ColumnSizer.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/ColumnSizer
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/ColumnSizer/ColumnSizer.js 11:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/InfiniteLoader/InfiniteLoader.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/InfiniteLoader
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/InfiniteLoader/InfiniteLoader.js 13:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/InfiniteLoader/InfiniteLoader.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/InfiniteLoader
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/InfiniteLoader/InfiniteLoader.js 15:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/List/List.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/List
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/List/List.js 15:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/List/List.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/List
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/List/List.js 23:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/MultiGrid/MultiGrid.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/MultiGrid
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/MultiGrid/MultiGrid.js 11:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/MultiGrid/MultiGrid.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/MultiGrid
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/MultiGrid/MultiGrid.js 15:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Grid/Grid.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Grid
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Grid/Grid.js 12:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Grid/Grid.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Grid
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Grid/Grid.js 40:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/ScrollSync/ScrollSync.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/ScrollSync
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/ScrollSync/ScrollSync.js 9:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/ScrollSync/ScrollSync.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/ScrollSync
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/ScrollSync/ScrollSync.js 11:33-72

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/WindowScroller/WindowScroller.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/WindowScroller
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/WindowScroller/WindowScroller.js 9:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/WindowScroller/WindowScroller.js
Module not found: Error: Cannot resolve module 'react-dom' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/WindowScroller
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/WindowScroller/WindowScroller.js 11:16-36

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/WindowScroller/WindowScroller.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/WindowScroller
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/WindowScroller/WindowScroller.js 15:33-72

ERROR in /Users/mikepriest//react-dnd/lib/wrapConnectorHooks.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-dnd/lib
@ /Users/mikepriest/
/react-dnd/lib/wrapConnectorHooks.js 12:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Collection/CollectionView.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Collection
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Collection/CollectionView.js 11:13-29

ERROR in /Users/mikepriest//react-virtualized/dist/commonjs/Collection/CollectionView.js
Module not found: Error: Cannot resolve module 'react-addons-shallow-compare' in /Users/mikepriest/node_modules/react-virtualized/dist/commonjs/Collection
@ /Users/mikepriest/
/react-virtualized/dist/commonjs/Collection/CollectionView.js 27:33-72

ERROR in /Users/mikepriest//react-dnd/lib/utils/cloneWithRef.js
Module not found: Error: Cannot resolve module 'react' in /Users/mikepriest/node_modules/react-dnd/lib/utils
@ /Users/mikepriest/
/react-dnd/lib/utils/cloneWithRef.js 12:13-29

Disabling move node

Hi I would like to ask if I can if I can disable the moving node functionality for a tree. Also for button how can I add one, as the api does not state clearly how to do so.

[Question] Move multiple items at once (similar to CRTL + Click)

Hi,

I've had a poke around the repo, and wasn't able to determine how possible this might be.

I feel it would be incredibly useful if it was possible to click multiple nodes at once and move them. It wouldn't matter which nodes they came from, as they'd all transport into the same "level".

I created a screenshot to help explain.

Is this feasible?

Thanks

2016-10-27 at 12 09 28 pm

[Bugfix](Hover): Errors on hover

When you want to drag & drop a node with children and you hover the children you have a lot of errors on the console

-- 1
------2
-----------3

If you drag 2 and hover 3, it will throw

I made a PR for that: #41

Consistency of method return type (removeNodeAtPath)

Maybe not a bug but an idea.
I'm looking at https://github.com/fritz-c/react-sortable-tree/blob/master/src/utils/tree-data-utils.js
Most methods that manipulate the tree return associative arrays.
Except these:
removeNodeAtPath - {Object} changedTreeData
getNodeAtPath
getTreeFromFlatData {Object[]} treeData
insertNode - returns associative array but it is not documented

I was trying to set the state after manipulation but insertNode and removeNodeAtPath return different object types. So it took a while to realize it should be:
setState(insertNode(...))
and
setState({treeData:removeNodeAtPath(...)})
Thanks.

Problematic issue regarding sorting parents and child elements

Dear friends

I have noticed that every node can be moved to anyone.

But I need to make such way that parent node can be moved through the parent nodes(not into child nodes),

And the same for child nodes. Child nodes can be moved at the level of child nodes, no meter in which parent they are in. They can be moved from one parent child level into another parent's child nodes level.

How to lock dragging of element to its depth only?

Hi!

I have pretty nested structure in the project, simplified version looks something like this:

+block 1
--questions
----question 1
----question 2
----question 3
--answers
----answer 1
----answer 2
----answer 3

and so on.

So would be great to specify drag zone to move questions within its container only (block 1 -> questions). Could you point me where to look in order to add such feature?

Thanks.

Access to path in onMoveNode

Is there any way to access the path of a node in the onMoveNode callback? My specific use case is when a node is moved I want to know its new parent and not sure of the easiest way to do this with the existing API. I could traverse the treeData manually to find the node's new parent but I was hoping with the existing API this can be done easily - just having trouble figuring out how.

Appreciate any help and thanks so much for this excellent component.

EDIT: it is very easy to just traverse the tree and find the parent, so I would just remove this issue - I can't seem to figure out how though...Perhaps only @fritz-c can do so. Sorry about this.

Customization

Is there a way to highlight some branch(es) of tree programmaticaly?

Could u provide an example using reactVirtualizedListProps

I want to use react-sortable-tree with list in material-ui, so I think it's best to use props reactVirtualizedListProps. But when I mostly copied code here ,and put it into my page, it failed(No error happened in console but no effect either, the code I copied is ok if I just rendered it somewhere in that page).
Sorry my code is mess, I don't think it's great to put it here :(.
And an example using reactVirtualizedListProps will help me a lot, thanks.

How to get `parentKey` to add new node

Hi,
First of all I really like your implemented stuff, it saves my lot of time. So thanks for implementing this sortable tree, but it would be more better if you can make the documentation more descriptive.
Because I am having issue while using the Data Helper Functions. I am trying to use the addNodeUnderParent(treeData, newNode, parentKey) but dont know how to get the parentKey.

Also I did not the use of getNodeKey parameter, so can you please explain these thing with some example.

Actually I am pretty new for React. So please help me to get out of it.

@fritz-c can you please look into it.

Thanks

Not render without container with fixed height

I wanna render in page without fixed height and use main page scrolling.

<div style={{ height: 50 }}>
                    <SortableTree
                        treeData={treeData}
                        onChange={this.updateTreeData}
                        onMoveNode={({ node, treeIndex, path }) =>
                                console.debug( // eslint-disable-line no-console
                                    'node:', node,
                                    'treeIndex:', treeIndex,
                                    'path:', path,
                                )
                            }
                        rowHeight={20}
                        maxDepth={2}
                    />
                </div>

If i remove <div style={{ height: 50 }}> -> nothing visible.
Why?

Problems with HTML5 Backend

Hi everyone,

i start using React Sortable Tree and i get error "Cannot have two HTML5 backends at the same time.".. I am using it with React DnD so i think that both components use react-dnd-html5-backend so there is a problem. Does someone know how to solve it? Thanks.

Highlight the selected node ?

This is a great component ^_^.

Is there a way to get notified when a node is selected by a mouse click and highlight the selected node?

Fix appearance in IE 9

I had the styles working well in IE 9 (which cannot use flexbox) until a short while ago, when something apparently broke it.

Question: Rerender tree when I add/delete a node

Hi @fritz-c,
I met an issue here, my code can work fine on drag, collapse, expand. I set treeData to read this.state.treeData. My issue is when I add/delete a node in treeData and set treeData to use new treeData by call this.setState({treeData: newTreeData}). I can see when render, the state is already changed. But the tree won't update until I collapse the parent and expand again, then the node will add/remove. Did I missed anything here? I tried to call forceUpdate() at setState's callback, but no lucky here.
Thanks.

Support Multiple SortableTrees on one Page

Current implementation does not elegantly handle multiple SortableTrees to be on the same page.

Dragging an item from one list to another causes serious problems, by deleting items in the other tree.

We need to be able to name the SortableTree. That name should be added to the drag type, to prevent items from one tree being dragged to other trees.

sortabletreebug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.