Configuration
createEditor(config) accepts one configuration object. The public configuration is intentionally small: holder and plugins are required; every extension is an immutable v2 definition created by a factory.
Public shape
interface EditorConfig {
holder: HTMLElement
plugins: readonly BlockPluginDefinition[]
inlinePlugins?: readonly InlinePluginDefinition[]
inlineTools?: readonly InlineTool[]
data?: EditorOutputData
defaultBlock?: string
placeholder?: string
readOnly?: boolean
autofocus?: boolean
injectStyles?: boolean
contentStyles?: readonly string[]
theme?: string
minHeight?: number
locale?: Record<string, unknown>
changeDebounceMs?: number
historyMaxStack?: number
historyMaxBytes?: number
historyCoalesceMs?: number
dragThreshold?: number
toolboxFilterThreshold?: number
mobileBreakpoint?: number
blockInsertAnimationMs?: number
blockMoveAnimationMs?: number
blockRemoveAnimationMs?: number
onReady?: (editor: IEditor) => void | Promise<void>
onChange?: (document: EditorOutputData) => void | Promise<void>
onValidationError?: (issue: EditorValidationIssue) => void | Promise<void>
onDiagnostic?: (diagnostic: EditorDiagnostic) => void | Promise<void>
diagnosticThresholds?: Partial<DiagnosticThresholds>
}Options
| Option | Required | Default | Meaning |
|---|---|---|---|
holder | yes | — | DOM element owned by this editor instance. A live holder cannot be claimed by a second editor. |
plugins | yes | — | Non-empty array of immutable BlockPluginDefinition values. Block type values must be unique. |
inlinePlugins | no | [] | Immutable InlinePluginDefinition values for persistent inline widgets. |
inlineTools | no | [] | Formatting-tool objects shown by the inline toolbar. |
data | no | empty default block | Initial versioned document. Input is cloned and normalized at the ownership boundary. |
defaultBlock | no | paragraph when registered, otherwise first block definition | Type used for an empty document and generic structural editing. |
placeholder | no | extension/localized default | Editor-level placeholder exposed to the default block runtime. |
readOnly | no | false | Initial interaction authority. User/native/clipboard/plugin persistence and undo/redo are disabled; host document commands remain available. |
autofocus | no | false | Focus the first editable field after successful creation. |
injectStyles | no | true | Acquire core and registered definition styles through the shared style registry. |
contentStyles | no | [] | Application-owned CSS text for rich text, derived author views, Raw and HTML Carousel content. Copied once; independent of automatic UI style injection. |
theme | no | graphite | Non-empty theme identifier. The built-in palettes are graphite, light, and dark. Style any custom oe-theme-* class in the host. |
minHeight | no | CSS default | Finite non-negative minimum editor height in pixels. |
locale | no | built-in English | Flat message dictionary used by core and definitions. |
changeDebounceMs | no | 250 | Delay before the detached onChange snapshot is delivered. |
historyMaxStack | no | 100 | Maximum number of undo records retained by operation-based history. |
historyMaxBytes | no | omitted | Optional positive safe integer: retained history record size in UTF-8 JSON bytes, across undo and redo. Oldest whole actions are evicted on a new edit; the newest whole action is always kept, even when oversized. Omit to retain count-only behavior. |
historyCoalesceMs | no | 300 | Maximum idle interval for grouping consecutive native edits in one undo step. |
dragThreshold | no | 5 | Pointer movement in pixels required before block dragging starts. |
toolboxFilterThreshold | no | 7 | Show toolbox search only when the registered item count exceeds this value. |
mobileBreakpoint | no | 768 | Viewport width in pixels below which core toolbar/toolbox use mobile mode. |
blockInsertAnimationMs | no | 350 | New-block projection animation duration; 0 disables it. |
blockMoveAnimationMs | no | 200 | FLIP movement animation duration; 0 disables it. |
blockRemoveAnimationMs | no | 350 | Safe removal-slot collapse duration; removed plugin DOM is detached synchronously. |
onReady | no | omitted | Observer invoked after successful composition. Callback failures do not invalidate the editor. |
onChange | no | omitted | Debounced observer receiving a detached saved document after canonical commits. |
onValidationError | no | omitted | Content-free observer for rejected current-format input. Observer failures are isolated. |
onDiagnostic | no | omitted | Content-free operational diagnostics; callback failures are isolated. |
diagnosticThresholds | no | no slow-operation thresholds | Optional non-negative thresholds for command/save/render/paste diagnostics. |
Plugin definitions
Register factory results, not mutable class instances:
import { createEditor } from '@shelamkoff/rector'
import { createParagraphPlugin } from '@shelamkoff/rector/plugins/paragraph'
import { createQuotePlugin } from '@shelamkoff/rector/plugins/quote'
const editor = createEditor({
holder,
plugins: [
createParagraphPlugin(),
createQuotePlugin(),
],
defaultBlock: 'paragraph',
})A definition may be reused by multiple editor instances. Per-editor state belongs to the runtime returned by setup(); per-block state belongs to the BlockInstance returned by that runtime.
Inline-tool preset
Core does not statically install the complete inline-tool set. Import createDefaultInlineTools from @shelamkoff/rector/preset and pass the result through inlineTools when the standard preset is wanted. Individual tools remain available from their dedicated subpath exports.
The preset accepts a translation port separately from the editor's locale. Use the same dictionary for both so tooltips and action panels follow the selected language:
import ru from '@shelamkoff/rector/locale/ru'
import { createDefaultInlineTools } from '@shelamkoff/rector/preset'
const inlineTools = createDefaultInlineTools({ i18n: { t: key => ru[key] ?? key } })
// Pass { locale: ru, inlineTools } to createEditor with your other options.Initial document and version policy
data accepts only the current explicit 2.0.0 document envelope. Every serialized block and inline widget must carry its exact current dataVersion; known types with missing, older, or future versions are rejected before projection. An unregistered type with valid current-envelope metadata remains inert and can round-trip without executing extension code.
The removed validationMode, documentVersionPolicy, and migrations options are rejected when supplied. See Document format for the canonical boundary.
Read-only and layout
editor.setReadOnly(true) changes interaction authority without creating a document history entry. Definition instances receive the transition through setReadOnly(). Core controllers stop structural keyboard commands, paste, drag, settings mutations, inline commands, undo and redo. Host calls to render(), clear(), and editor.blocks.* mutations remain available; their history is retained, while canUndo/canRedo stay false until read-only is disabled.
Use minHeight only for the editor shell. mobileBreakpoint drives the core mobile-mode class instead of a duplicate hard-coded media-query contract. Structural animations live in the projection layer and are automatically suppressed by prefers-reduced-motion. Extension layout belongs in extension styles.
Callbacks
onValidationError reports one immutable, content-free issue after failed document preparation unwinds. Its required reason is invalid-input, unsupported-document-version, unsupported-data-version, or invalid-data; optional blockId, inlineId and type come only from already validated identities. Classification follows the failing boundary, regardless of exception wording. Schema exceptions retain their identity; primitive schema throws can be wrapped with cause. Allocator and projection failures do not become validation notices.
Committed queries remain available inside this observer. Synchronous document writes, selection/focus/current-block changes, destruction, protected DOM callbacks and task creation are denied before effects. A queued command can run after the invocation unwinds. The same restriction applies while schemas, input accessors and other synchronous extension values are being prepared. Ordinary user update producers retain supported nested commands; an entered nested command failure aborts its outer transaction even when caught, including throw null and other falsy values.
onReady, onChange, onValidationError, and onDiagnostic are observers, not transaction hooks. Synchronous throws and rejected Promises are contained consistently. Rector isolates observer failures from canonical state. Diagnostics never contain document or plugin payload data.
onChange is scheduled only after committed document mutations and receives a detached document. A newer commit can supersede an older pending notification.
Style ownership
With injectStyles: true, core and extension style URLs are reference-counted per owning document. With false, Rector acquires no definition styles; the host must import the required CSS itself.
Per-extension factories may also expose an injectStyles: false option where documented, but editor-level injectStyles: false is the global manual-style mode.