@hone-ui/editor

中文文档
0.2.0发布于 2026/11/01MITTypeScriptES Module

Dev-only visual editor: overlay, panel and source rewriter.

原始使用文档
文档目录3 节
  1. Use
  2. Package contents
  3. Develop

@hone-ui/editor

Dev-only visual editor for @hone-ui/react apps. It reads the data-hn-source attributes the @hone-ui/sx plugin stamps in dev, and writes edits back to the source files.

Use

import { DevEditor } from '@hone-ui/editor';

// once, near the root
<DevEditor />;

In development, Alt+Shift+E turns edit mode on. Hover outlines the nearest component, a click selects it and opens the panel. While edit mode is on, the page ignores clicks and other pointer input. Escape closes the panel, and a second Escape leaves edit mode. Selects and switches save to the source file 150 ms after a change. Text and number fields save when you press Enter, press Escape or leave the field, so a typed value is one write and one undo step. An arrow-key or spinner step on a number field saves after 150 ms, like a select. The dev server's own hot reload repaints the page. DevEditor renders null unless process.env.NODE_ENV === 'development'.

The sx section lists each key of a static sx object. Spacing keys and borderRadius get number fields, color keys a select of palette paths plus free text, and a responsive object one field per breakpoint. You can add and remove keys. An sx that is not an object literal, and any spread, computed key or non-literal value, shows read-only.

The panel lives in a shadow root on <html>, with the Minimal look's CSS inlined, so app CSS never reaches it. Props written as expressions show read-only with a "set in code" note, and local wrapper components show read-only entries.

Ctrl+Z undoes the last save and Ctrl+Shift+Z (or Ctrl+Y) redoes it, wherever focus is except inside a textarea or a field in your own app. The endpoint returns the reverse ops with every save, so undo works for any op. One history covers every element until you leave edit mode. Undo reverses the newest edit anywhere and selects the element it changed. A save that moves lines tells the panel where, so the history of other elements stays correct. When the file changed underneath the panel (a 409), the panel reloads the element, shows a message and clears its history. If the element disappears after a save, the panel closes.

The docs page "Visual editor" covers setup for Vite and Next.js. An AI guide ships at @hone-ui/editor/ai/DevEditor.md.

Package contents

  • @hone-ui/editor: DevEditor and the edit protocol types (Op, SourceResponse, EditRequest, and so on).
  • @hone-ui/editor/server: applyEdit, readElement and reverseOps, which rewrite and read one JSX element with exact-range edits and compute the ops that undo an edit, and createEditorHandler, a plain Node (req, res, next) handler for GET /source and POST /edit. It answers only loopback peers. The Vite plugin in @hone-ui/sx mounts it at /__hone/editor, and withSx serves it from a loopback port for Next, with crossOrigin: true. A dev server inside Docker with published ports gets a 403, because its connections arrive from the bridge address, not from loopback.

Develop

pnpm test runs the rewriter tests in Node and the panel tests in Chromium. pnpm test:e2e starts the Vite playground on a free port, drives it with headless Chromium and restores the file it edits. Build the workspace first (pnpm build), because the playground uses built packages.

The panel's CSS is generated by scripts/build-panel-css.mjs from the built @hone-ui/react package. It runs before build, lint, typecheck and test.

The panel uses a native select for string unions. React Aria's Select popover does portal into the shadow root, but option clicks with a real pointer do not register there yet.

版本与发布记录

@hone-ui/editor 共发布 5 个版本,首次发布于 2026/10/22;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.2.0latest2026/11/012 天前
0.0.0-canary-20261101045435canary2026/11/012 天前
0.1.02026/10/2410 天前
0.0.0-canary-202610221552062026/10/2211 天前
0.0.0-stage2026/10/2211 天前

关于 @hone-ui/editor 的常见问题

@hone-ui/editor 是什么?

开发专用的可视化编辑器:覆盖,面板和源代码重写器。

如何安装 @hone-ui/editor?

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

@hone-ui/editor 支持 TypeScript 吗?

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

@hone-ui/editor 支持 ESM 还是 CommonJS?

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

@hone-ui/editor 可以商用吗?

@hone-ui/editor 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@hone-ui/editor 还在维护吗?

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