packages/editor)Owner: ED1 (wave 3; WP-E before). ADRs 0008 (undo), 0013 (engine), 0007 (drag preview via presence), 0002. Contracts: DocSession, Gesture, MountEditor in shared/src/session.ts.
packages/editor/src/ runs on a DocSession (ADRs 0008, 0024, 0501, 0502). Every document change is session.commit(ops) or a Gesture; undo/redo are the session’s (own transactions only).
editor.ts (Editor): wiring only. Session and page switch, engine, camera, render loop, selection (engine bitset), hover, presence (cursor, viewport, selection, drag, tool), remote drag slots, and the stable public API the panels, the shell and tools/bench call (setTool, setSelection, setBoundsField, setColor, addSite, runBenchmark, …). Pointer events are routed: pointer-down to the active tool’s handler, then move/up/cancel to the handler of the current drag kind.tools/: one module per tool-map row.
types.ts: Tool, Drag (the in-progress interaction, a tagged union), ToolHandler (down, cursor), DragHandler (move, up, cancel(escape)).move.ts: click / shift-click select, marquee, move drag (alt = duplicate, one gesture), resize handles, line endpoint drags. Moves and resizes preview on the GPU (Editor.setXf: engine xf + presence drag) and commit SET ops on pointer-up.hand.ts (H, Space, middle button), shape.ts (rect/ellipse/polygon/star/line/arrow and frame: a CREATE gesture, 100x100 on click), pencil.ts (CREATE PATH gesture, points while drawing). New layers go into the frame under the start point, in its coordinate space.text.ts (T): text tool and in-place editing (TextEdit, ADR 0520). It uses a hidden IME-safe textarea, with caret, selection and navigation from text/layout.ts (the engine’s line layout). Each edit is one gesture of SET {text, w, h, x, y}, measured with @linorahq/doc/text (ADR 0014).move.ts also handles frames (ADR 0521):
RectQuery kept for the drag, ADR 0508);index.ts: the registry (TOOLS by tool id, DRAGS by drag kind).frames.ts (FrameIndex): top-level frames as an Int32Array (labels, label clicks, frameAt for draw / drop targets).text/layout.ts: caret, selection rectangles, click-to-index, sizing (measureBox) and alignment anchoring for the edited text node only.commands.ts (Commands): undo/redo, select all, delete, duplicate, clipboard (private doc, fresh ids per paste), nudge, z-order (zOrderOps), bounds/rotation/style edits.
setTextProp). W/H typed for a text switch it to auto height / fixed.setClipContent, setFrameSize (box only) and addFrame (preset screens right of the others); FRAME_PRESETS.keymap.ts: shortcuts (inputs, textareas and contenteditable keep their keys).bench.ts: view / transform / tour benchmarks (unchanged behaviour). generate.ts: @linorahq/doc/gen blocks committed as CREATE_BULK on top of the page with contiguous ids, not undoable (a 5M-node inverse would stay in the undo stack); clear canvas.geometry.ts: pure doc math.
reparentOps: fractional keys between the target’s neighbours, paint order preserved).nKeysBetween).overlay.ts: selection box, handles, size label, marquee, text hover box, and the collaboration layer: remote cursors (eased, name label, agent badge) and remote selection outlines in the peer’s color, moved by the peer’s live drag. Peers’ drags render through the engine’s remote slots (Editor.syncRemote, up to four at once).store.ts: framework-free panel state for the React shell. Stores with subscribe/getSnapshot (useSyncExternalStore), immutable snapshots replaced only on change, notified at most once per frame:
ui, tool, view, history, perf (4 Hz);selection: selected-node properties, including text (style, null = mixed) and frame (clip, size);layers: an index-based layer tree. Rows are an Int32Array of handles, names are produced per visible row, and rows are maintained only while subscribed. Drag and drop goes through dragSet / dropPlace / drop (one commit of reparentOps), and isScreen marks top-level frames.mount.ts: mountEditor({ stage, session }) returns { editor, setSession, getViewport, setViewport, destroy } and sets window.editor (tools/bench). It loads the bundled Inter (@linorahq/doc/fonts/*) for the atlas.session.onReload the editor drops interaction state (an open text edit is committed) and the engine rebuilds from the new doc.Editor.on, returns an unsubscribe): camera, usercamera (wheel, pan, zoom keys/buttons, fit: the shell stops following a peer), escape, selection, tool.PRESENCE_VIEW_MARGIN (they stop being relayed there, ADR 0203).node tools/bench/parity.ts (harness and --app web) passed 44/44 states and 44/44 identical screenshots against 7e799f3.Editor.bulkOps. It is switched on once the engine’s ChangeSet.transforms handling (EN2) is on main.packages/editor/src/
editor.ts wiring: session, engine, camera, render loop hooks, selection (local state)
tools/ move (select, marquee, drag, alt-dup, resize, endpoint, drop into frames), hand, shape
(rect/ellipse/line/arrow/polygon/star/frame), pencil, text (+ in-place editing)
frames.ts top-level frame index (labels, draw / drop targets)
text/layout.ts caret / selection / hit layout of the edited text (engine line layout)
commands.ts delete, duplicate, clipboard, nudge, z-order, bounds/rotation/style edits -> ops
keymap.ts shortcuts (unchanged)
overlay.ts selection/handles/marquee + remote cursors, remote selections, agent badges
bench.ts scripted benchmarks (unchanged behaviour)
index.ts mountEditor(stage, session): EditorHandle
The target layout above is implemented (wave 3, ED1). Remaining target items: bulk TRANSFORM / SET_GEOMETRY commits (ADR 0103) and engine clip content (EN2).
Rules: every change to the document is session.commit(ops) or a Gesture. Tools never touch engine buffers except through the existing GPU preview (xf) during drags. Selection, hover, camera and tool are local UI state (selection is mirrored to presence).
Every editor capability maps to ops and to an MCP tool (agents can do everything a person can).
| Editor feature (today) | Ops | MCP tool |
|---|---|---|
| Rect / Ellipse / Polygon / Star / Line / Arrow tool (drag, click = 100x100) | Gesture: CREATE, then SET x/y/w/h (rotation for lines) | create_nodes |
| Pencil | Gesture: CREATE PATH, SET points (sent at <= 10 Hz while drawing) | create_nodes (points) |
| Move drag (selection) | none during drag (GPU preview + presence drag); pointer-up: SET x/y per node |
transform_nodes (translate/moveTo) |
| Alt-drag duplicate | CREATE_BULK of copies + SET x/y | duplicate_nodes |
| Resize handles (shift = keep ratio, alt = from center) | pointer-up: SET x/y/w/h (lines: endpoints) | transform_nodes (scale + anchor) |
| Line endpoint drag | Gesture: SET x/y/w/rotation | update_nodes (x1,y1,x2,y2) |
| Arrow-key nudge (shift = 10) | SET x/y | transform_nodes (translate) |
| Delete / Cut | DELETE | delete_nodes |
| Duplicate (Cmd+D), Copy/Paste (into the selected frame) | CREATE_BULK (encodeSubtrees, fresh ids, offset) |
duplicate_nodes |
| Bring forward / backward / front / back | SET PARENT_INDEX (new keys) | arrange_nodes (order) |
| Select all, click/shift select, marquee | local selection + presence | find_nodes, set_selection |
| Properties: X/Y/W/H | SET x/y/w/h | update_nodes, transform_nodes |
| Rotation | SET rotation | update_nodes, transform_nodes (rotate) |
| Corner radius, opacity, stroke width | SET cornerRadius / opacity / strokeWidth | update_nodes |
| Fill / stroke color (picker drag = one undo step) | Gesture: SET fill/stroke | update_nodes |
| Undo / Redo | commit inverse batches (own only) | undo, redo |
| Zoom, fit, pan, hand tool | local camera; viewport in presence | render (region), get_peers (viewports) |
| Generate website / random shapes (perf panel) | CREATE_BULK blocks from packages/doc/gen |
dev only |
| Clear canvas | DELETE of root children | delete_nodes |
| Text tool: click = auto width, drag = fixed width (T) | Gesture: CREATE TEXT, then SET text + w/h/x/y per keystroke (one undo step) | create_nodes (text) |
| Edit text in place (double-click, Enter), font size / weight / line height / alignment / sizing | Gesture or commit: SET text / font props + re-measured w/h/x/y | update_nodes |
| Frame tool (F / A), drawn frames adopt enclosed layers; presets | Gesture: CREATE FRAME (+ SET PARENT_INDEX/x/y of adopted layers); commit: CREATE FRAME (preset) | create_nodes |
| Resize a frame (handles: content kept; panel W/H, presets) | Gesture: SET frame x/y/w/h (+ children x/y); commit: SET w/h | update_nodes |
| Clip content | SET clipContent | update_nodes |
| Draw into a frame / drop into or out of a frame (move drag) | CREATE with the frame as parent / SET PARENT_INDEX + x/y/rotation (page placement kept) | create_nodes (parent), arrange_nodes |
| Layers panel drag and drop (reorder, reparent into frames and groups, multi-select) | SET PARENT_INDEX (+ x/y/rotation when the parent changes) | arrange_nodes |
Remote cursors (interpolated, name label, agent badge), remote selection outlines in the peer’s color, remote drag previews (engine remote-xf slots), avatars in the top bar (web app). Overlay drawing costs O(visible peers) per rendered frame.
Drags remain GPU-only; ops are produced once per gesture end or per frame (gestures); remote changes reach the engine through the change feed, never synchronously. Every change passes the interleaved perf gate (npm run bench, ADR 0015) and the memory gate (npm run bench -- --memory, ADR 0024).
All rows above implemented against DocSession (tested with createLocalSession and two-session sync tests); undo/redo bit-exact; remote cursors/selections/drag previews visible; bench parity; 10K remote SETs <= 4 ms.
test/text-layout.test.ts. Browser checks passed:
test/reparent.test.ts. Browser checks passed:
bulkOps on by default (waits for EN2’s ChangeSet.transforms on main; tested against EN2’s working tree: moves, nudges, resize, undo).