> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nanoforge.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# @nanoforge-dev/editor-lib

[![NanoForge](https://raw.githubusercontent.com/NanoForge-dev/Engine/main/.github/logo.png)](https://github.com/NanoForge-dev)

[![npm version](https://img.shields.io/npm/v/@nanoforge-dev/editor-lib.svg?maxAge=3600)](https://www.npmjs.com/package/@nanoforge-dev/editor-lib)

[![npm downloads](https://img.shields.io/npm/dt/@nanoforge-dev/editor-lib.svg?maxAge=3600)](https://www.npmjs.com/package/@nanoforge-dev/editor-lib)

[![Tests status](https://github.com/NanoForge-dev/Engine/actions/workflows/tests.yml/badge.svg)](https://github.com/NanoForge-dev/Engine/actions/workflows/tests.yml)

[![Last commit](https://img.shields.io/github/last-commit/NanoForge-dev/Engine.svg?logo=github\&logoColor=ffffff\&path=packages%2Feditor)](https://github.com/NanoForge-dev/Engine/commits/main/packages/editor)

[![Contributors](https://img.shields.io/github/contributors/NanoForge-dev/Engine.svg?maxAge=3600\&logo=github\&logoColor=fff\&color=00c7be)](https://github.com/NanoForge-dev/Engine/graphs/contributors)

## About

`@nanoforge-dev/editor-lib` is the bridge between a running NanoForge application and an external editor host. `EditorLibrary` turns the raw `toEditor`/`fromEditor` event-emitter pair supplied via `RunOptions.editor` into the `Context.editor` facade every other library sees, and handles the pause/resume/step/stop commands, run state reports, frame stats and log forwarding: see the [editor protocol](https://github.com/NanoForge-dev/Engine/blob/main/docs/docs/editor/protocol.mdx).

It also provides `QueuedEventEmitter`, the event emitter an editor host gives a game in `RunOptions.editor`.

## Installation

**Node.js 26 or newer is required.**

```sh theme={null}
npm install @nanoforge-dev/editor-lib
yarn add @nanoforge-dev/editor-lib
pnpm add @nanoforge-dev/editor-lib
bun add @nanoforge-dev/editor-lib
```

## Example usage

Register `EditorLibrary` alongside your other libraries. It does nothing when no editor started the app:

```ts theme={null}
import { EditorLibrary } from "@nanoforge-dev/editor-lib";

app.use(new EditorLibrary());
```

The editor host constructs one `QueuedEventEmitter` per direction and hands both to `RunOptions.editor`:

```ts theme={null}
import { QueuedEventEmitter } from "@nanoforge-dev/editor-lib";

const toEditor = new QueuedEventEmitter(); // engine -> editor
const fromEditor = new QueuedEventEmitter(); // editor -> engine

await app.init({ ...options, editor: { toEditor, fromEditor } });
fromEditor.emit("pause");
```

Libraries talk to the editor through `Context.editor`, `undefined` when no editor started the game:

```ts theme={null}
public override async __run(ctx: Context): Promise<void> {
  ctx.editor?.emit("component-moved", entityId, position);
}
```

One-time editor wiring goes in `__editorInit`, which `EditorLibrary` calls once on every library that has it, when the editor's `welcome` arrives:

```ts theme={null}
import type { EditorAwareLibrary, EditorInitContext } from "@nanoforge-dev/editor-lib";

class MyLibrary extends Library implements EditorAwareLibrary {
  public async __editorInit(ctx: EditorInitContext): Promise<void> {
    ctx.editor.on("hot-reload", (entity, component) => this.apply(entity, component));
  }
}
```

## Links

* [GitHub][source]
* [npm][npm]

## Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
[documentation][documentation].\
See [the contribution guide][contributing] if you'd like to submit a PR.

## Help

If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to ask questions in [discussions][discussions].

[documentation]: https://github.com/NanoForge-dev/Engine

[discussions]: https://github.com/NanoForge-dev/Engine/discussions

[source]: https://github.com/NanoForge-dev/Engine/tree/main/packages/editor

[npm]: https://www.npmjs.com/package/@nanoforge-dev/editor-lib

[contributing]: https://github.com/NanoForge-dev/Engine/blob/main/.github/CONTRIBUTING.md

## Enumerations

* [EditorBridgeCommand](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/enumerations/EditorBridgeCommand.md)
* [EditorBridgeEvent](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/enumerations/EditorBridgeEvent.md)

## Classes

* [EditorLibrary](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/classes/EditorLibrary.md)
* [QueuedEventEmitter](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/classes/QueuedEventEmitter.md)

## Interfaces

* [EditorAwareLibrary](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorAwareLibrary.md)
* [EditorChannels](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorChannels.md)
* [EditorCommandMap](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorCommandMap.md)
* [EditorContextApi](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorContextApi.md)
* [EditorEventMap](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorEventMap.md)
* [EditorFeatures](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorFeatures.md)
* [EditorFrameStats](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorFrameStats.md)
* [EditorHello](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorHello.md)
* [EditorLog](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorLog.md)
* [EditorNetworkStats](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorNetworkStats.md)
* [EditorNetworkTotals](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorNetworkTotals.md)
* [EditorNetworkTrace](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorNetworkTrace.md)
* [EditorTiming](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorTiming.md)
* [EditorWelcome](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorWelcome.md)

## Type Aliases

* [EditorCommand](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/type-aliases/EditorCommand.md)
* [EditorInitContext](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/type-aliases/EditorInitContext.md)
* [EditorLogValue](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/type-aliases/EditorLogValue.md)
* [EditorRunState](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/type-aliases/EditorRunState.md)
* [EditorViewport](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/type-aliases/EditorViewport.md)

## Variables

* [EDITOR\_INIT\_HOOK](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/variables/EDITOR_INIT_HOOK.md)
* [EDITOR\_PROTOCOL\_VERSION](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/variables/EDITOR_PROTOCOL_VERSION.md)
* [EditorCommand](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/variables/EditorCommand.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.