npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

what-a-drag

v3.8.0

Published

A Drag and drop tree library designed with customization and usability in mind

Downloads

47

Readme

What-a-drag

A React Drag and drop tree library designed with customization and usuability in mind with added support for rendering and drag and dropping large lists.

Installation

npm install what-a-drag@latest --save

#Get started ######Tree data structure Tree is defined by a normalized data structure, where rootId defines the id of the root node and items map contains all the nodes indexed by their id. Child relationship is defined in the children field of parent in form of list of id's.

######Data attribute:

Any consumer data should be defined in the data attribute of item, e.g. title, color, selection etc.

######State handling: This data structure is the single source of truth. After any interaction the consumer's responsibility to execute the mutation on the tree, which will be passed down in props to refresh the rendered tree. A few utils functions (mutateTree, moveItemOnTree) are provided in order to help you make those changes easily and in a efficient way.

######Performance / Side-effects: We put some effort into optimizing rendering based on reference equality. We only re-render an Item if it's reference changed or moved on the tree.

######Events: onDragEnd function will be triggered at the end of re-ordering. it provides the necessary information as TreePosition to change the tree. ######Example type TreePosition = { parentId: ItemId, index: number, };

    onDragEnd = (source: TreePosition, destination: ?TreePosition) => {
      const { tree } = this.state;
    
      if (!destination) {
        return;
      }
      const newTree = moveItemOnTree(tree, source, destination);
      this.setState({
        tree: newTree,
      });
    };
    
    

Types & Tree Structure

export type ChildItem = string;

export type ItemId = string;

export interface TreeItemData {
    id: string;
    [key: string]: any;
}

export interface TreeItem {
    id: string;
    isExpanded: boolean;
    hasChildren: boolean;
    data: TreeItemData;
    children: ChildItem[];
}

export interface TreeData {
    rootId: string;
    items: { [key: string]: TreeItem };
}

####renderitem

  renderItem = ({
    item,
    onCollapse,
    onExpand 
  }: RenderItemParams) => {
    return (
      <div
      >
        <div>{item.id}</div>
        <div>{item.data ? item.data.title : ''}</div>
      </div>
    );
  };

##Expand & Collapse onExpand and onCollapse functions are triggered when there is a need to change the state of a parent. This is the right time to trigger requests to load the subtree or flip the isExpanded attribute to show the already loaded children nodes.

####Example

onExpand = (itemId: ItemId) => {
  const { tree }: State = this.state;
  this.setState({
    tree: mutateTree(tree, itemId, { isExpanded: true }),
  });
};

renderPlaceholder

Allows the consumer to specify a placeholder item for when a dragged item is being hovered over an item in the tree

renderPlaceholder({ item, isDraggingOver, isDragging }){
    return (
        <div>
            {isDraggingOver?'Dragging over':'Not dragging over'}
        </div>
    );
}

DraggableList

The exported component from what-a-drag which needs to be rendered with the tree data .

###Example

    import { DraggableList } from 'what-a-drag'
    
    <Draggable
         tree={treeData}
         renderItem={renderItem}
         renderPlaceholder={placeholderToRender}
         onExpand={onExpand}
         onCollapse={onCollapse}
         onDragEnd={onDragEnd} 
         height={500}
         itemSize={50}
         width={'100%'}
     />