Giter Club home page Giter Club logo

react-dnd-treeview's People

Contributors

magnushiie 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-dnd-treeview's Issues

Can't add a child node to a leaf

In your example, remove B1 & B2, then nothing can be added to B, nor any other leaf node - dragging onto a leaf not can only make it a sibling.

Documentation available?

Hi @magnushiie,

I was wondering whether there is a documentation of how to use your component. I find the working example very interesting but have problems developing my own application as I am not using TypeScript. Therefore, I will appreciate it, if you can provide me with any documentation and help.

Thanks in advance,
Marius

No start-script in Package.json

Docs say cd example && npm install && npm start but there is no start-script, so it errs at:
npm ERR! missing script: start

Customization

Thanks for the wonderful plugin.. i am trying to use this in my mobile app and it working in touch devices too when i change backend. I would like to use this as a listview and like to know how to customize the styles.

Is there any way i can customize the insert target styles and other things?

Error with TreeView Component without typescript syntax

Hello,

I am trying to use TreeView component without TypeScript syntax. But I have an error with my custom component in ES6 (PostCategoryList.js). Thanks in advance for your help.

import styles from './PostsCategories.css';
import React from 'react';
import * as Immutable from 'immutable';
import HTML5Backend from 'react-dnd-html5-backend';
import { DragDropContext } from 'react-dnd';
import { TreeView } from 'react-dnd-treeview';

const recursivelyUpdateList = (
  list,
  parentNode,
  listUpdateFunc,
  nodeUpdateFunc
) => {
  const mappedItems = list.items.map(
    item => recursivelyUpdateNode(item, listUpdateFunc, nodeUpdateFunc)
  );
  if (!Immutable.is(mappedItems, list.items)) {
    list = Object.assign({}, list, {
      items: mappedItems,
    });
  }
  return listUpdateFunc(list, parentNode);
};

const recursivelyUpdateNode = (
  node,
  listUpdateFunc,
  nodeUpdateFunc) => {
  const updateChildren = node.children
    ? recursivelyUpdateList(node.children, node, listUpdateFunc, nodeUpdateFunc)
    : node.children;
  if (updateChildren !== node.children) {
    node = Object.assign({}, node, {
      children: updateChildren,
    });
  }
  return nodeUpdateFunc(node);
};

class PostCategoryList extends React.Component {
  constructor(props, context) {
    super(props, context);
    this.state = {
      rootNodes: {
        items: [{
          id: 'A',
          title: 'A',
          children: {
            items: [{
              id: 'A1',
              title: 'A1'
            },
            {
              id: 'A2',
              title: 'A2'
            },
            {
              id: 'A3',
              title: 'A3'
            }]
          },
        },
        {
          id: 'B',
          title: 'B',
          children: {
            items: [{
              id: 'B1',
              title: 'B1'
            },
            {
              id: 'B2',
              title: 'B2'
            }]
          },
        },
        {
          id: 'C',
          title: 'C',
          children: {
            items: [{
              id: 'C1',
              title: 'C1',
              children: {
                items: [{
                  id: 'C1x',
                  title: 'C1x'
                },
                {
                  id: 'C1y',
                  title: 'C1y'
                },
                {
                  id: 'C1z',
                  title: 'C1z'
                },
                {
                  id: 'C1zz',
                  title: 'C1zz'
                },
                {
                  id: 'C1zzz',
                  title: 'C1zzz'
                }]
              }
            }]
          }
        }]
      }
    };

    this.renderNode = this.renderNode.bind(this);
    this.handleMoveNode = this.handleMoveNode.bind(this);
  }

  setStateWithLog(newState) {
    console.log("new state: ", newState);
    this.setState(newState);
  }

  handleMoveNode(args) {
    this.setState(Object.assign({}, this.state, {
      rootNodes: recursivelyUpdateList(
        this.state.rootNodes,
        null,
        (list, parentNode) =>
          parentNode === args.newParentNode && parentNode === args.oldParentNode
            ? Object.assign({}, list, {
              items:
              list.items
                .insert(args.newParentChildIndex, args.node)
                .remove(args.oldParentChildIndex + (args.newParentChildIndex < args.oldParentChildIndex ? 1 : 0))
            })
            : parentNode === args.newParentNode
              ? Object.assign({}, list, {
                items: list.items.insert(args.newParentChildIndex, args.node)
              })
              : parentNode === args.oldParentNode
                ? Object.assign({}, list, {
                  items: list.items.remove(args.oldParentChildIndex)
                })
                : list,
        item => item
      ),
    }));
  }

  handleToggleCollapse(node) {
    this.setStateWithLog(Object.assign({}, this.state, {
      rootNodes: recursivelyUpdateList(
        this.state.rootNodes,
        null,
        (list, parentNode) => list,
        item => item === node ? Object.assign({}, item, {
          isCollapsed: !item.isCollapsed,
        }) : item
      ),
    }));
  }

  renderNode(node) {
    return (
      <div className={ styles.nodeItem }>
        { !node.children || node.children.items.isEmpty()
          ? null
          : <a
            style={{ fontSize: '0.5em', verticalAlign: 'middle' }}
            onClick={ () => this.handleToggleCollapse(node) }
            >
            {node.isCollapsed ? '⊕' : '⊖'}
          </a>
        }
        Node: { node.title }
      </div>
    );
  }

  render() {
    return (
      <div className={styles.categoriesListing}>
        <TreeView
          rootNodes={ this.state.rootNodes }
          classNames={ styles }
          renderNode={ this.renderNode }
          onMoveNode={ this.handleMoveNode }
        />
      </div>
    );
  }
}

export default DragDropContext(HTML5Backend)(PostCategoryList);

Remove dependency to Immutable.js

I started experimenting with this library as it essentially offers exactly what I need. Could you consider removing Immutable.js as a dependency given that it's not really needed but and should be up to the consumer of the library to opt-in? Looking at my webpack stats, it seems to add 139KB which is non-trivial given that it's adding no benefit for me.

FR: prevent node dragging

Hi,

It would be great to implement "isDraggable" prop in the node to prevent unnecessary drags.
The usual case is to let user select text in child inputs by mouse.

Thanks.

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.