@alwith/module-file-tree

中文文档
0.6.0发布于 2026/11/03SEE LICENSE IN LICENSETypeScriptES Module构建来源已验证近 30 天下载 1891

A standalone file tree. It depends on @alwith/module-fs and does not import the editor package.

原始使用文档
文档目录4 节
  1. Included behavior
  2. Explorer UI and host adapters
  3. Desktop implementation provenance
  4. Source alignment

@alwith/module-file-tree

A standalone file tree. It depends on @alwith/module-fs and does not import the editor package.

import { createFileTreeController, FileTree } from "@alwith/module-file-tree"
import "@alwith/module-file-tree/styles.css"
const tree = createFileTreeController({ fs, root: "/project", reportError })
await tree.refresh()
<FileTree controller={tree} onOpenFile={openFile} requestName={requestName}
  confirmDelete={confirmDelete} onError={reportError} />
// On workspace disposal:
tree.dispose()

/core exports the React-free controller, snapshots, rows and PartialOperationError. The root entry exports React UI and all core types. Import CSS once in the host.

Included behavior

Directory-first sorting, lazy expansion, virtual rows, filtering loaded entries (including collapsed descendants), hidden-file toggle, multi/range selection, keyboard navigation, create/rename/delete, copy/cut/paste and internal drag-to-directory. The native adapter applies gitignore filtering. Filter is explicitly limited to loaded entries; it is not a recursive search index.

requestName and confirmDelete are asynchronous host dialogs. Return null/false to cancel. onOpenFile can open a preview, editor, external application or any host action. renderDecoration adds per-row metadata. All strings are replaceable using FileTreeLabels; CSS consumes semantic host theme tokens.

expanded and onExpandedChange let a host persist view state. The host owns workspace/session selection. The controller never loads global settings or subscribes to a global app store.

Mutations use the shared FS instance and therefore its guards. Passing one FS instance to tree and editor is the standard composition; the tree remains unaware of editor internals. A batch stops on the first failure and reports completed paths plus the failed path. Copying uses Desktop-style incremented copy names. Moving preflights all destination conflicts before touching sources. Cut-paste replacement requires the host confirmReplace callback and rechecks target versions after confirmation; removing the target uses FS mutation guards. A batch is not an OS transaction: later I/O failures report completed items; replacements remove an approved target before moving its source. Filesystem notifications are coalesced before refreshing the loaded tree.

See examples/files/tree-only.tsx for a consumer that imports no editor package.

Explorer UI and host adapters

The toolbar exposes search, creation, refresh, collapse and view preferences. Rows use 22px height, file-type icons, inline rename, range selection, keyboard navigation and context menus. Cmd/Ctrl+F filters names and relative path fragments; Enter/Shift+Enter moves between matches and Escape closes search. Cmd/Ctrl+A, C/X/V operate on the focused tree. Rename and delete use the row context menu, as in Desktop.

activePath reveals an editor selection through lazy ancestor expansion. onReveal, onCopyPath, onImport, and requestMoveDestination are host capabilities. onPinFile, renderIcon, renderDecoration, and renderActions integrate richer editor, icon, Git and application behavior without importing the host. explorerLabels supplements the original labels without breaking existing consumers. OS drag-drop registration, native consent, file pickers and persistence stay in the host. Cloud authorization, synchronization, sharing and sidebar pinning are application features and are not bundled into the local file tree.

Desktop implementation provenance

The visual resolver, icon associations, pointer-drag hook and floating drag preview are extracted from Desktop's file-visual.ts, use-tree-drag.ts and drag-preview.tsx. Icons are bundled locally; the default vscode-icons collection is pinned to Desktop's 1.2.86 version. isDark selects light/dark mappings and iconTheme selects vscode-icons, catppuccin-latte, catppuccin-mocha or material-icon-theme. The host supplies its theme setting; no global settings store is imported. Codicons provide the toolbar and expand/collapse symbols.

TanStack Virtual renders 22px rows with Desktop's 8px nesting increment. The project root is an expandable row. Collapse All keeps the project root expanded. Pointer drag uses Desktop's 5px threshold and floating preview, avoiding HTML5 drag events that are unreliable in WKWebView. Drops are limited to the tree's viewport and reject moves into the source or its descendants.

The build validates emitted icon mappings to detect accidental rewriting of ordinary strings by the ESM module-path transformer.

explorerControl replaces the toolbar title with host content. collapsed keeps that control visible while hiding the tree and its remaining toolbar actions. The host controls the collapsed container width and the toggle state.

Source alignment

desktop-provenance.json records the Desktop source hashes at extraction. filter-tree.ts, copy-name.ts and move-plan.ts preserve their original algorithms; their Desktop test suites are copied with only runner/import changes. use-tree-keyboard.ts preserves Desktop navigation and injects store access. The UI click handler follows Explorer.handleItemClick; the local context menu follows TreeItem root exclusions, single-row deletion and multi-row copying.

Host adapters replace global stores, native calls and notifications. The keyboard hook additionally handles an empty list without indexing a missing node. Existing FS guards still protect dirty documents and workspace boundaries. The requested right-side layout, Explorer icon toggle and subtle scrollbars are intentional UI differences. Cloud actions require the cloud host; they are not simulated locally.

版本与发布记录

@alwith/module-file-tree 共发布 9 个版本,首次发布于 2026/10/22;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.0latest2026/11/034 天前
0.5.22026/11/035 天前
0.5.12026/11/035 天前
0.5.02026/10/309 天前
0.1.0-rc.24next2026/10/299 天前
0.1.0-rc.232026/10/2613 天前

关于 @alwith/module-file-tree 的常见问题

@alwith/module-file-tree 是什么?

A standalone file tree. It depends on @alwith/module-fs and does not import the editor package.

如何安装 @alwith/module-file-tree?

在项目目录运行 npm install @alwith/module-file-tree,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.3.1)、react-dom(^19.3.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alwith/module-file-tree 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alwith/module-file-tree 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alwith/module-file-tree 可以商用吗?

@alwith/module-file-tree 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@alwith/module-file-tree 的下载量有多少?

根据 npm 官方下载统计,@alwith/module-file-tree 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,891 次,日均约 63 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alwith/module-file-tree 还在维护吗?

最新版本 0.6.0 发布于 2026/11/03(4 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/10/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。