@termaxjs/editor
v0.2.1
Published
Next-generation lightweight code editor for React — a modern alternative to CodeMirror and Monaco
Readme
@termaxjs/editor
Next-generation, high-performance code editor for React and Web: a lightweight modern alternative to CodeMirror 6 and Monaco Editor.
pnpm add @termaxjs/editor
# or npm install @termaxjs/editorModular Subpath Exports
@termaxjs/editor provides modular subpath imports so you only import what you need:
// 1. Ready-to-use React Editor Component
import { TermaxEditor } from "@termaxjs/editor";
// 2. Headless React Hooks & Context
import { useEditor, useBufferRange, useCursors } from "@termaxjs/editor/react";
// 3. Canvas & GPU WebGL Viewport Renderer
import { CanvasViewportRenderer, WebGLGlyphAtlas } from "@termaxjs/editor/canvas";
// 4. Core Headless State & Math Data Structures
import { PieceTable, EditorState, DecorationSet } from "@termaxjs/editor/core";
// 5. Host Runtime Adapters
import { InMemoryEditorAdapter, WasmEditorAdapter } from "@termaxjs/editor/adapter";Quickstart
import React, { useState } from "react";
import { TermaxEditor } from "@termaxjs/editor";
export function CodeEditor() {
const [code, setCode] = useState("const greeting = 'Hello from Termax!';");
return (
<div style={{ height: "500px", width: "100%" }}>
<TermaxEditor
defaultValue={code}
language="typescript"
rendererMode="canvas" // "canvas" (default) or "dom"
minimap={{ enabled: true, side: "right", width: 80 }}
lineNumbers={true}
onChange={(val) => setCode(val)}
/>
</div>
);
}Props Reference
adapter— AnyIEditorHostAdapter(WASM worker, Tauri IPC, or in-memory). Omit for pure in-memory editing.filePath— Automatically detects language and keys the adapter buffer.rendererMode—"canvas"(GPU accelerated immediate mode) or"dom"(virtualized DOM).readOnly— Disables all mutations (useful for large files or preview mode).onSnapshot— Fires when the adapter buffer snapshot opens.diagnostics,languageAdapter— LSP-backed diagnostics and completions from the host.
Accessibility Contract
- The offscreen textarea is the keyboard and screen-reader interface (labeled with the current line position); the visual line surface is
aria-hidden. - Completions follow the listbox pattern driven from the textarea (arrows cycle, Enter/Tab accepts, Escape dismisses) with
aria-activedescendant. - Find/replace is a labeled dialog with a live-region match counter; fold gutter entries and the minimap scrubber are keyboard-operable.
Performance & Rendering
- Sub-millisecond Typing Latency: 206 µs per edit with in-place chunk coalescing.
- Virtualized Viewport: Only visible lines (+ overscan) are rendered.
- Canvas / WebGL Engine: Zero DOM layout thrashing and zero
contenteditablebrowser bugs.
