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

@keyhole-koro/paper-in-paper

v0.2.0

Published

React library for hierarchical paper tree visualization with drag-and-drop

Downloads

22

Readme

@keyhole-koro/paper-in-paper

ドラッグ&ドロップと展開表現を持つ階層的な paper tree を、React で扱うためのライブラリです。

現在は、ライブラリの再構築に向けて、仕様整理とアーキテクチャ設計を先に固めています。

まず読むべき文書:

現在の位置づけ

現在のコードベースには、動作するプロトタイプ実装があります。 次の段階では、以下を明確に切り分けます。

  • 今のインタラクションモデルが実際にどうなっているか
  • そのうち何が挙動で、何が見た目なのか
  • その挙動を React library の API にどう写像するか

この整理においては、上記ドキュメント群を第一の source of truth とします。

プロトタイプの使い方

npm install @keyhole-koro/paper-in-paper

Basic Usage

import { buildPaperMap, PaperCanvas } from '@keyhole-koro/paper-in-paper';

const papers = [
  { id: 'root', title: 'Root', description: '', content: '', parentId: null, childIds: ['a', 'b'] },
  { id: 'a',    title: 'A',    description: '', content: '', parentId: 'root', childIds: [] },
  { id: 'b',    title: 'B',    description: '', content: '', parentId: 'root', childIds: [] },
];

const paperMap = buildPaperMap(papers);

export default function App() {
  return <PaperCanvas paperMap={paperMap} />;
}

Data Structure

Paper

Each node in the tree is a Paper object:

interface Paper {
  id: PaperId;          // unique string identifier
  title: string;
  description: string;
  content: string;
  parentId: PaperId | null;  // null for the root node
  childIds: PaperId[];
}

The tree must have exactly one root node (parentId: null).

Building a PaperMap

PaperMap is a Map<PaperId, Paper> used internally for O(1) lookups. Use buildPaperMap to create one from an array:

const paperMap = buildPaperMap(papers);

API Reference

Components

PaperCanvas

Main canvas component that renders the paper tree.

<PaperCanvas
  paperMap={paperMap}   // required: Map<PaperId, Paper>
  rootId="root"         // optional: explicit root node ID (auto-detected if omitted)
/>

Data Utilities

buildPaperMap(papers: Paper[]): PaperMap

Converts a Paper[] array into a PaperMap.

findRootId(paperMap: PaperMap): PaperId | null

Returns the ID of the root node (the node with parentId: null), or null if not found.

Expansion State

For use cases where expansion state needs to be managed externally.

Types

interface NodeExpansion {
  openChildIds: PaperId[];      // currently expanded children
  primaryChildId: PaperId | null; // the focused child
}

type ExpansionMap = Map<PaperId, NodeExpansion>;

type ExpansionAction =
  | { type: 'OPEN';        parentId: PaperId; childId: PaperId }
  | { type: 'CLOSE';       parentId: PaperId; childId: PaperId }
  | { type: 'SET_PRIMARY'; parentId: PaperId; childId: PaperId };

Functions

openNode(expansionMap, parentId, childId): ExpansionMap
closeNode(expansionMap, paperMap, parentId, childId): ExpansionMap
setPrimaryNode(expansionMap, parentId, childId): ExpansionMap
expansionReducer(expansionMap, paperMap, action): ExpansionMap

設計方針

再構築の方向性は、概ね次の通りです。

  • controlled な React API を先に定義する
  • UI component の外に純粋な状態遷移を置く
  • role、breadcrumbs、pass-through は selector で導く
  • drag-and-drop は semantic な reorder intent を出す層として扱う

この考え方の詳細は react-architecture-considerations.md にまとめています。

Peer Dependencies

| Package | Version | |---|---| | react | >= 18 | | framer-motion | >= 11 |