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 🙏

© 2026 – Pkg Stats / Ryan Hefner

smart-catalog

v1.0.4

Published

An unopinionated, composable React tree/catalog component with drag-and-drop, inline rename, open/close control, and built-in undo/redo history.

Readme

Smart Catalog

An unopinionated, composable React tree/catalog component with drag-and-drop, inline rename, open/close control, and built-in undo/redo history.

Features

  • Nested tree structure support
  • Open/close (expand/collapse) state with a context
  • Inline rename with your custom editor
  • Undo/redo history with an imperative ref API
  • Pluggable callbacks for move/create/rename and full-tree change events

Installation

npm install smart-catalog

Peer dependencies:

  • react >= 19
  • react-dom >= 19

The library also uses:

  • @dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities
  • react-icons (only for the default arrow icon in Toggle)

Basic Concepts

  • Tree node shape (CatalogItm):
type ID = string | number

interface CatalogItm {
  id: ID
  title: string
  order: number
  children?: CatalogItm[]
}
  • Component: default export Catalog
  • Composition API: Catalog.Group, Catalog.Title, Catalog.Toggle, Catalog.Handle
  • Hooks for customization: useCatalogItem, useCatalogTitle
  • Context-managed state for open nodes and drag-and-drop

Quick Start

import React, { useRef } from 'react'
import Catalog, { type CatalogHandler } from 'smart-catalog'

const initialTree = [
  { id: 1, title: 'Root', order: 0, children: [
    { id: 2, title: 'Child A', order: 0 },
    { id: 3, title: 'Child B', order: 1 },
  ]},
]

export default function Example() {
  const ref = useRef<CatalogHandler>(null)

  return (
    <div>
      <div style={{ display: 'flex', gap: 8, marginBottom: 8 }}>
        <button onClick={() => ref.current?.undo()}>Undo</button>
        <button onClick={() => ref.current?.redo()}>Redo</button>
        <button onClick={() => ref.current?.collapseToggle()}>Toggle All</button>
      </div>

      <Catalog
        ref={ref}
        tree={initialTree}
        defaultOpen={[1]}
        onMove={(id, parentId, order) => {
          // Persist move if needed
        }}
        onRename={(id, name) => {
          // Persist rename if needed
        }}
        onChange={(nextTree) => {
          // Entire tree changed (dnd/create/delete/rename)
        }}
      />
    </div>
  )
}

The default rendering includes a toggle, a title (double-click to edit), and a drag handle. You can fully customize the item layout by providing the item prop (see below).

Custom Item Rendering

Provide a React node via item to control how each item renders. Use the composition API and hooks to wire up behavior:

import Catalog, { useCatalogItem, useCatalogTitle } from 'smart-catalog'

function MyItem() {
  const { hasChildren } = useCatalogItem()
  const { title } = useCatalogTitle() // when inside Title's editor provider
  return (
    <Catalog.Group style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
      <div style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
        <Catalog.Toggle />
        <Catalog.Title />
      </div>
      <Catalog.Handle />
    </Catalog.Group>
  )
}

<Catalog tree={initialTree} item={<MyItem />} />

To enable inline editing, pass an editor to Catalog.Title. You can provide either a React node or a render function. The library ships a minimal input component at CatalogItem/Input which is used in the default view:

import Input from 'smart-catalog/lib/src/components/CatalogItem/Input' // or copy your own input

<Catalog.Title editor={<Input />} />

When an editor node is provided, double-click on the title area toggles edit mode. If you pass a render function, you’ll receive (title, setTitle) => ReactNode and can build a fully custom editor.

Imperative API (Ref)

Attach a ref with type CatalogHandler to call history and UI helpers:

  • undo() / redo() – history navigation for tree edits
  • collapseToggle() – collapse all vs open all (for nodes that have children)
  • Also exposes item operations used internally: handleCreate, handleRename, handleRemove
import { useRef } from 'react'
import Catalog, { type CatalogHandler } from 'smart-catalog'

const ref = useRef<CatalogHandler>(null)

<Catalog ref={ref} tree={initialTree} />

// Later
ref.current?.undo()
ref.current?.redo()
ref.current?.collapseToggle()

Props

Catalog props:

  • tree: CatalogItm[] – the initial tree
  • defaultOpen?: ID[] – node ids that start opened
  • item: ReactNode – optional custom item view; if omitted, a default layout is used
  • onMove?: (id: ID, parent: ID | undefined, order: number) => void – called on drag-and-drop reorder
  • onRename?: (id: ID, name: string) => void – called on rename
  • onChange?: (tree: CatalogItm[]) => void – called whenever the tree changes
  • onOpenAll?: (status: boolean, waiting: boolean) => void – reflects “all opened” status
  • onChangeHistory?: (status: { undo: boolean; redo: boolean }) => void – history availability

Hooks

  • useCatalogItem() – item-level context: { id, status, hasChildren, title, setTitle, parentId, createItem, removeItem }
  • useCatalogTitle() – available within Title’s editor provider: { title, setTitle }

Keyboard and Accessibility

  • Toggle supports Space key to open/close when focused
  • Title enters edit mode on double-click when editor is provided
  • Handle serves as the drag handle; @dnd-kit attributes and listeners are attached

Styling

The library does not impose styles beyond basic inline layout. Use className and style on Group, Title, Toggle, and Handle to style as needed.

TypeScript

  • Types are exported: CatalogHandler, HistoryStatus
  • Node ids can be string | number

Build

npm run build

License

ISC