@hlang-tech/editor-react

中文文档
0.1.1发布于 2026/11/01MITTypeScriptESM + CJS

React bindings of the Lumen editor for hlang: hooks that connect @hlang-org/editor-core to React Flow.

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. How the binding works
  4. Hooks
  5. License

hlang editor-react

@hlang-tech/editor-react

React bindings for Lumen, the hlang visual editor. The hooks connect a headless @hlang-tech/editor-core to React Flow. This package adds no styling; the design system is @hlang-tech/editor-ui.

npm license

Status: 0.x, in active development. The API can change in any minor release.

Install

npm install @hlang-tech/editor-react @hlang-tech/editor-core @xyflow/react react react-dom

The same build is published as @hlang-org/editor-react. Peer dependencies: react and react-dom 18 or later, @xyflow/react 12.

Usage

import { ReactFlow, ReactFlowProvider } from '@xyflow/react';
import '@xyflow/react/dist/style.css';
import { createEditorCore } from '@hlang-tech/editor-core';
import { useHlangFlow } from '@hlang-tech/editor-react';

const core = createEditorCore();
// register node descriptors and add nodes...

function Canvas() {
  const flow = useHlangFlow(core);
  return <ReactFlow {...flow} fitView />;
}

export function Editor() {
  return (
    <ReactFlowProvider>
      <Canvas />
    </ReactFlowProvider>
  );
}

useHlangFlow returns nodes, edges, onNodesChange, onEdgesChange, onConnect, and isValidConnection. Spread them into <ReactFlow>.

How the binding works

  • Direction. An output (O) port is a React Flow source / sourceHandle; an input (I) port is a target / targetHandle. isValidConnection asks the core's validator, so invalid links are refused while dragging.
  • Commands. Connecting, deleting, moving, and renaming are executed as core commands, so every canvas edit can be undone.
  • Dragging. Positions update locally while a node is dragged, and one move command is committed when the drag ends. Undo and redo move nodes on the canvas.
  • Subscriptions. Hooks read the core through useSyncExternalStore and re-render only when the relevant core events fire.

Hooks

HookReturns
useHlangFlow(core)Props for <ReactFlow>, as above.
useGraphSync(core)The current nodes and edges of the model.
useConnect(core), useIsValidConnection(core)The connect handler and the validation callback.
useNodeChanges, useEdgeChangesReact Flow change handlers that commit to the core.
useHistory(core)canUndo, canRedo, undo, redo.
useSelection(core)Selected node and edge ids, with selection setters.
useViewState(core)Hidden and locked node flags, with setters and toggles.
useClipboard(core)Copy, cut, paste, and duplicate of the selection, including the system clipboard.
useRename(core)Rename a node through a command.
useDiagnostics(core)The core's edit-time diagnostics, also grouped by node.
useReconnect(core)Move an edge endpoint to another port, and find the edge under a dragged node for drop-to-insert.

EditorProvider and useEditor share one core through React context. The mapping helpers toRFNode, toRFEdge, endpointsFromConnection, and findPort are exported for custom bindings.

Source and documentation: github.com/hlang-tech/hlang.

License

MIT

版本与发布记录

@hlang-tech/editor-react 共发布 3 个版本,首次发布于 2026/11/01;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.1.1latest2026/11/012 天前
0.1.02026/11/012 天前
0.0.0-stage2026/11/012 天前

关于 @hlang-tech/editor-react 的常见问题

@hlang-tech/editor-react 是什么?

Lumen编辑器的hlang: hooks的React绑定,这些hook连接@hlang-org/editor-core到React Flow。

如何安装 @hlang-tech/editor-react?

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

@hlang-tech/editor-react 支持 TypeScript 吗?

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

@hlang-tech/editor-react 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@hlang-tech/editor-react 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@hlang-tech/editor-react 可以商用吗?

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

@hlang-tech/editor-react 还在维护吗?

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