@quickbuilder.io/editor-runtime
v1.0.0
Published
Owned document-backed authoring runtime for Quick Builder
Readme
Quick Builder Editor Runtime
@quickbuilder.io/editor-runtime is the owned authoring engine for Quick Builder.
It operates only on the canonical quickbuilder.document version 1 envelope
from @quickbuilder.io/document.
The package is headless. It owns document interaction, not editor chrome, icons, motion, product controls, or a second visual language. Visible builder UI must consume the owning Quick Builder design-system, icons, animation, and capability packages.
commands.renameNode(nodeId, displayName, label?) renames a layer through the
canonical document command. Resolved node selectors return the saved display
name; component identity, rendering props, and node IDs do not change. Rename
participates in mutation authorization, persistence, transactions and undo/redo.
commands.updateNodeProps merges an object update into the existing props by
default. A draft callback saves the resulting props, including any keys it
deletes. An explicit mode overrides either default.
By default, commands.duplicateNode and commands.duplicateNodes place each
copy after its source. When the source occupies a named slot, the copy appends
to the parent's regular children and the original stays in its slot.
Core contract
The root entry point owns:
- immutable canonical documents and bounded deterministic undo/redo history;
- atomic transactions and named insert, fragment, single/batch duplicate, move, single/batch remove, property, rename, visibility, primary/additive selection, hover, and drag commands;
- canonical component-name resolution and fail-closed canvas policies;
- immutable component descriptors, JSON-safe defaults, and metadata;
- node inspection, DOM registration, subscriptions, and deterministic internal document serialization.
frameworkAdapterSupport explicitly advertises the React adapter and marks Vue,
Preact, Qwik, Astro, Svelte, Solid and Web Components unsupported.
Framework runtime dependencies are optional peers; importing the
neutral root does not load React. The React implementation lives in
src/frameworks/react and publishes its reactFrameworkAdapter contract through
the existing /react entry point.
All mutation paths, including low-level transactions, enforce the same
component registry, delete/move/drop policies, and canonical JSON requirements.
Products can supply authorizeMutation to enforce live permissions or
collaboration locks at the final runtime boundary; only an exact true permits
a local command, replacement, undo, or redo. Authoritative remote merges bypass
this local gate so read-only collaborators continue receiving server state.
The request includes the current document and validated prospective
nextDocument. The runtime computes the prospective state without committing
history, so a rejected mutation changes neither the document nor undo/redo.
EditorRuntimeSnapshot.revision advances only when the canonical document
changes. Selection, hover, drag, enabled state, resolver changes, and DOM refs
publish snapshots without scheduling persistence work through that revision.
Observer failures are isolated after a commit so one persistence callback or
subscriber cannot block later subscribers or make a completed mutation appear
to have failed. Products can route those failures through onObserverError.
mergeRemoteDocument does not perform conflict resolution. Its input must
already be merged by the collaboration owner. Applying that authoritative
snapshot rebases local undo/redo history, does not echo through the local
onDocumentChange callback, and remains available when the runtime is
read-only. This prevents local Undo from reverting another participant's work.
Persistence boundary
selectors.serialize() returns the internal quickbuilder.document envelope.
It is not the persisted page payload. Page persistence and collaboration must
use @quickbuilder.io/document to emit the exact Craft-compatible top-level
ROOT node map, then the platform compresses that wire once with LZUTF8 Base64.
The runtime does not compress, auto-detect, or decode persistence formats.
This package intentionally has no compatibility decoder. Historical editor documents must be converted by a separately versioned migration before they are loaded.
React adapter
@quickbuilder.io/editor-runtime/react adds EditorProvider, the recursive
canvas renderer, named slots, node/runtime hooks, declarative JSON-safe fragment
creation, focused-canvas keyboard commands, and native pointer drag/drop bindings. It
does not render intrinsic HTML or builder chrome.
palette.getPendingFragment(), consumePendingFragment(), and
clearPendingFragment() let a product-owned drop surface perform its own
authorization and geometry checks while retaining a single canonical palette
drag transaction. consumePendingFragment() transfers ownership exactly once.
Drag sources and product drop surfaces must use the exported
EDITOR_PALETTE_FRAGMENT_DRAG_MIME and EDITOR_NODE_DRAG_MIME constants; the
runtime does not recognize native text payloads or application-defined aliases.
bindings.dropTarget(element, { resolveIndex }) lets a product return a final
child insertion index from its own geometry. The index must be a nonnegative
integer within the target's child range; invalid explicit placement fails before
mutation with INVALID_DROP_PLACEMENT. For a move within the same parent, the
range excludes the moving child because the index describes its final position.
Palette inserts and node moves use the same commands, policies and
single undo transaction. Omit the callback for documented append placement.
Disabled palette controls and a disabled runtime never begin palette drags.
Read-only targets do not accept dragover or drop.
During browser-protected dragover, the engine checks owned MIME types against
the active session; the drop still requires an exact payload and matching session.
EditorProvider.document, historyLimit, and clientId initialize one runtime
instance. Change the provider key when switching document identity, or apply an
authorized external snapshot with replaceDocument/mergeRemoteDocument.
resolver, enabled, onDocumentChange, and onObserverError stay synchronized
after mount.
When a resolver removes a component or restricts the children it accepts, the
runtime keeps the consecutive Undo and Redo steps that still produce valid
documents. An explicit empty policy.accepts list prevents all child inserts.
Replacing the current document resets selection and history. An identical
replacement preserves its revision and skips the persistence notification.
EditorElement accepts registered editor components and canonical JSON through
its props field. Intrinsic elements, event-handler props, opaque objects, and
mixed primitive/editor-node child order are rejected rather than inferred.
useEditorRuntime(selector) subscribes only to the selected value and uses
shallow field equality by default; callers can provide an exact equality
function. useEditorRuntime() without a selector intentionally returns the
full reactive snapshot.
Nested selection and drag sources keep the nearest authored node as their owner; native ancestor bindings do not consume pointer events belonging to a nested product wrapper or resize/toolbar control. Draggable ancestors do not overwrite a child's canonical MIME payload or active source. When a draggable product wrapper differs from the registered authored root, the browser drag preview uses that root and the pointer's offset within it, excluding the wrapper's floating toolbar and resize controls.
Native browser drag/drop is a pointer enhancement, not the only accessible authoring path. Builder chrome must expose keyboard-operable insert, move, duplicate, and delete actions through runtime commands. The canvas adapter provides focus selection, Escape, Delete/Backspace, duplicate, and undo/redo keyboard behavior scoped to the focused canvas. Embedded form controls, toolbars, menus and dialogs retain their keyboard interactions, including during input-method composition.
Validation
npm run typecheck --prefix packages/editor-runtime
npm test --prefix packages/editor-runtime
npm run build --prefix packages/editor-runtime
npm run pack:dry-run --prefix packages/editor-runtime
npm run validate:package --prefix packages/editor-runtimevalidate:package checks source ownership, types, behavior, then the actual packed
ESM/CommonJS imports and declarations. prepublishOnly runs that certification
against a clean build.
