MCPcopy
hub / github.com/frontend-collective/react-sortable-tree

github.com/frontend-collective/react-sortable-tree @v2.8.0 sqlite

repository ↗ · DeepWiki ↗ · release v2.8.0 ↗
159 symbols 314 edges 45 files 3 documented · 2%
README

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 (



        <SortableTree
          treeData={this.state.treeData}
          onChange={treeData => this.setState({ treeData })}
        />



    );
  }
}

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.

`(

Core symbols most depended-on inside this repo

changeNodeAtPath
called by 23
src/utils/tree-data-utils.js
insertNode
called by 21
src/utils/tree-data-utils.js
addNodeUnderParent
called by 17
src/utils/tree-data-utils.js
find
called by 13
src/utils/tree-data-utils.js
slideRows
called by 11
src/utils/generic-utils.js
getDescendantCount
called by 9
src/utils/tree-data-utils.js
getVisibleNodeInfoAtIndex
called by 9
src/utils/tree-data-utils.js
getNodeAtPath
called by 9
src/utils/tree-data-utils.js

Shape

Function 79
Method 41
Class 39

Languages

TypeScript100%

Modules by API surface

src/utils/tree-data-utils.js24 symbols
src/utils/dnd-manager.js21 symbols
src/react-sortable-tree.js20 symbols
stories/drag-out-to-remove.js8 symbols
stories/search.js6 symbols
stories/only-expand-searched-node.js6 symbols
stories/external-node.js6 symbols
stories/can-drop.js5 symbols
stories/touch-support.js4 symbols
stories/themes.js4 symbols
stories/rtl-support.js4 symbols
stories/childless-nodes.js4 symbols

Dependencies from manifests, versioned

@babel/cli7.7.0 · 1×
@babel/core7.7.2 · 1×
@babel/plugin-transform-modules-commonjs7.1.0 · 1×
@babel/preset-env7.7.1 · 1×
@babel/preset-react7.7.0 · 1×
@storybook/addon-storyshots5.2.6 · 1×
@storybook/addons5.3.17 · 1×
@storybook/react5.2.6 · 1×
@storybook/theming5.3.17 · 1×
autoprefixer9.7.1 · 1×
babel-core7.0.0-bridge.0 · 1×
babel-eslint10.0.3 · 1×

For agents

$ claude mcp add react-sortable-tree \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact