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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@asup/tree-of-nodes

v2.0.3

Published

REACT Typescript Treeview component

Downloads

107

Readme

npm size npm bundle size License: MIT

@asup/tree-of-notes

REACT treeview, because I couldn't quite find what I wanted.

Works with/needs bootstrap, react-bootstrap, react-bootstrap-icons. Uses a context menu to facilitate Add/Rename/Remove actions.

Installation

# with npm
npm install @asup/tree-of-nodes

Tree-of-nodes Usage

import { iNodeUpdate, TreeNodeData, TreeOfNodes } from '@asup/tree-of-nodes';
import '@asup/tree-of-nodes/dist/style.css';

... inside REACT component

<TreeOfNodes<T>
  id: string;
  nodeList: TreeNodeData<T>[];
  roots: Key[];
  multiSelect?: boolean;
  selectedIds?: Key | Key[];
  handleSelect?: (ret: Key | Key []) => void;
  onAdd?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;
  onRemove?: (childId: Key) => Promise<iNodeUpdate>;
  onRename?: (childId: Key, newName: string) => Promise<iNodeUpdate>;
  canRemoveRoot?: boolean;
  canRenameRoot?: boolean;
  canAddChildren?: boolean;
  canRemoveChildren?: boolean;
  canRenameChildren?: boolean;
  nodeHighlight?: string;
  textHighlight?: string;
  />

The component expects a list of nodes of type TreeNodeData<T> with unique React.Keys.

Properties

| Prop | Description | Default | | :---------------- | :---------------------------------------------------------------------------------------------- | :----------------: | | id | HTML id attribute | | | nodeList | Array of node data | | | roots | One or more node Keys to use as the root of the tree | | | multiSelect | Allow selection of more than 1 id | false | | selectedIds | Currently selected list | | | handleSelect | Function called when a node is clicked (selected), this should be used to update the selectedId | () => {return;} | | onAdd | Function called when a new node is added, this should be used to update the nodeList | | | onRemove | Function called when a node is removed, this should be used to update the nodeList | | | onRename | Function called when a node is renamed, this should be used to update the nodeList | | | canRemoveRoot | Allows removal of a root node in combination with specification of onRemove function | false | | canRenameRoot | Allows renaming of a root node in combination with specification of onRename function | false | | canAddChildren | Allows addition of children in combination with specification of onAdd function | false | | canRemoveChildren | Allows renaming of non-root nodes in combination with specification of onRemove function | false | | canRenameChildren | Allows renaming of non-root nodes in combination with specification of onRename function | false | | nodeHighlight | Selected node highlight colour | red | | textHighlight | Selected text highlight colour | rgba(255,0,0,0.2 | | spellCheck | Use/disable browser spell check | 'true' |

TreeNodeData

Required format for list of nodes, includes a holder for any type of data, which is there specified in the TreeOfNodes specification.

export type TreeNodeData<T> = {
  id: Key;
  label: string;
  parentId?: Key;
  data: T;
};

iNodeUpdate

Use this format to return from update functions.

export interface iNodeUpdate {
  success: boolean;
  ErrorText?: string;
}

Handling clicks

Context menu clicks on a node will result in a context menu being displayed with "Add", "Rename" and "Delete" options being displayed.

Clicks on an expander will either expand or close the node's clidren

Clicks on a name will select that item

Clicks on a checkbox will select that item and all its descendents.

Single item selection

To handle one (and only one) item being selected, it is suggested to use these base options

  <TreeOfNodes<T>
    id={'...'}
    nodeList={[...]}
    roots={[...]}
    selected={selected}
    handleSelect={async (i) => {
      setSelected([i]);
    }}
  />

Multiple item selection

To handle multiple selections, it is suggested to use these base options

  <TreeOfNodes<T>
    id={'...'}
    nodeList={[...]}
    roots={[...]}
    showCheckBox
    selected={selected}
    handleSelect={async (i) => {
      if (Array.isArray(i)) {
        setSelected(
          selected.includes(i[0])
            ? selected.filter((s) => !i.includes(s))
            : [...selected, ...i.filter((n) => !selected.includes(n))],
        );
      } else {
        setSelected(
          selected.includes(i) ? selected.filter((s) => s !== i) : [...selected, i],
        );
      }
    }}
  />