@hlang-org/editor-core

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

Headless core of the Lumen editor for hlang: graph model, reversible commands, validation, diagnostics, and IGraph serialization. No React, no DOM.

原始使用文档
文档目录10 节
  1. Install
  2. Usage
  3. Running the graph
  4. The editor core
  5. Commands
  6. Diagnostics
  7. Utilities
  8. Dependency injection
  9. Related packages
  10. License

hlang editor-core

@hlang-org/editor-core

The headless core of Lumen, the hlang visual editor. It holds the graph being edited, changes it only through reversible commands, validates connections, reports edit-time diagnostics, and serializes to IGraph. It has no React, no DOM, and no RxJS in its public API, so it runs in any JavaScript environment and in plain unit tests.

npm license

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

Install

npm install @hlang-org/editor-core

The same build is published as @hlang-tech/editor-core. ESM and CommonJS builds with type declarations.

Usage

import { createEditorCore, AddNodeCommand, ConnectCommand } from '@hlang-org/editor-core';
import type { NodeDescriptor } from '@hlang-org/editor-core';

const DTO = { name: 'DTO', kind: 'interface' } as const;
const numbers: NodeDescriptor = {
  code: 'numbers',
  kind: 'R',
  displayName: 'Numbers',
  group: 'sources',
  ports: [
    { id: 'out', direction: 'O', name: 'out', dataType: DTO, isError: false },
    { id: '@node/error', direction: 'O', name: 'error', dataType: DTO, isError: true },
  ],
  defaultParams: { count: 3 },
  runtimeResource: 'my-nodes/numbers',
};

const core = createEditorCore();
core.registry.register(numbers);

const node = core.registry.createNode('numbers', { x: 0, y: 0 });
core.commands.execute(new AddNodeCommand(node));
core.history.undo();
core.history.redo();

const graph = core.serialization.toIGraph(core.model); // IGraph

Running the graph

Pass a graph runner to enable execution. InterpreterGraphRunner runs the graph with @hlang-org/interpreter:

import { Flow } from '@hlang-org/runtime';
import { NodeRegistry } from '@hlang-org/interpreter';
import { createEditorCore, InterpreterGraphRunner } from '@hlang-org/editor-core';

const runtimeNodes = new NodeRegistry().register('numbers', Numbers);
const core = createEditorCore({ graphRunner: new InterpreterGraphRunner(runtimeNodes, () => new Flow()) });

const handle = core.execution?.run(core.model);
handle?.dispose();

The editor core

createEditorCore(options?) returns an EditorCore with these services:

MemberResponsibility
modelThe graph being edited: nodes, edges, positions, parameters.
commandsThe only way to change the model. execute(command) validates, applies, and records the command.
historyundo(), redo(), canUndo(), canRedo(), and transact(label, fn) to group commands into one step.
selectionSelected nodes and edges. Not serialized.
viewStateHidden and locked flags per node. Not serialized.
registryNode descriptors (code, kind, ports, default parameters) and createNode.
validatorConnection rules: output to input, no self-connections, no duplicates, compatible port types. Transform cycles are allowed.
diagnosticsEdit-time problems, recomputed on change.
serializationtoIGraph(model) and fromIGraph(graph).
eventsA typed event bus: nodeAdded, nodeRemoved, nodeChanged, edgeAdded, edgeRemoved, selectionChanged, viewStateChanged, historyChanged.
executionPresent when a graphRunner is supplied.

Options: idGenerator (deterministic ids, for tests) and graphRunner.

Commands

AddNodeCommand, RemoveNodeCommand (also removes and restores incident edges), ConnectCommand, DisconnectCommand, MoveNodeCommand, UpdateParamsCommand, RenameNodeCommand, SetHiddenCommand, SetLockedCommand. Every command has an inverse, so every edit can be undone. A rejected command returns { ok: false, error } and is not recorded.

Diagnostics

CodeSeverityMeaning
bad-connectionerrorAn edge breaks a connection rule.
no-source-rooterrorThe graph has nodes but no Readable node to run.
unregistered-codeerrorA node's code is not in the registry.
type-mismatchwarningAn edge links incompatible port types.
dead-sourcewarningA Readable output feeds nothing.
dangling-inputwarningA Transform input is not connected.
sink-no-upstreamwarningA Writable input is not connected.

Utilities

  • cloneNodesWithEdges copies a selection with its internal edges, for copy and paste.
  • planInsertOnEdge and distanceToSegment support dropping a node onto an edge.
  • GraphTopology, TopologyIndex, layoutLayered, and layoutGrouped analyze connected components and compute layered layouts.

Dependency injection

Services are resolved through a small dependency-injection container in the style of VS Code (createDecorator, ServiceCollection, InstantiationService). It has no runtime dependencies and needs no reflect-metadata. Use it to replace a service in a custom container.

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

License

MIT

版本与发布记录

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

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

关于 @hlang-org/editor-core 的常见问题

@hlang-org/editor-core 是什么?

Lumen编辑器的无头核心:图形模型、可逆命令、验证、诊断和IGraph序列化。没有React,就没有DOM。

如何安装 @hlang-org/editor-core?

在项目目录运行 npm install @hlang-org/editor-core,或使用 pnpm add / yarn add / bun add。

@hlang-org/editor-core 支持 TypeScript 吗?

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

@hlang-org/editor-core 支持 ESM 还是 CommonJS?

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

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

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

@hlang-org/editor-core 可以商用吗?

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

@hlang-org/editor-core 还在维护吗?

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