Skip to content

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 ​

ts
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 ​

OptionRequiredDefaultMeaning
holderyes—DOM element owned by this editor instance. A live holder cannot be claimed by a second editor.
pluginsyes—Non-empty array of immutable BlockPluginDefinition values. Block type values must be unique.
inlinePluginsno[]Immutable InlinePluginDefinition values for persistent inline widgets.
inlineToolsno[]Formatting-tool objects shown by the inline toolbar.
datanoempty default blockInitial versioned document. Input is cloned and normalized at the ownership boundary.
defaultBlocknoparagraph when registered, otherwise first block definitionType used for an empty document and generic structural editing.
placeholdernoextension/localized defaultEditor-level placeholder exposed to the default block runtime.
readOnlynofalseInitial interaction authority. User/native/clipboard/plugin persistence and undo/redo are disabled; host document commands remain available.
autofocusnofalseFocus the first editable field after successful creation.
injectStylesnotrueAcquire core and registered definition styles through the shared style registry.
contentStylesno[]Application-owned CSS text for rich text, derived author views, Raw and HTML Carousel content. Copied once; independent of automatic UI style injection.
themenographiteNon-empty theme identifier. The built-in palettes are graphite, light, and dark. Style any custom oe-theme-* class in the host.
minHeightnoCSS defaultFinite non-negative minimum editor height in pixels.
localenobuilt-in EnglishFlat message dictionary used by core and definitions.
changeDebounceMsno250Delay before the detached onChange snapshot is delivered.
historyMaxStackno100Maximum number of undo records retained by operation-based history.
historyMaxBytesnoomittedOptional 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.
historyCoalesceMsno300Maximum idle interval for grouping consecutive native edits in one undo step.
dragThresholdno5Pointer movement in pixels required before block dragging starts.
toolboxFilterThresholdno7Show toolbox search only when the registered item count exceeds this value.
mobileBreakpointno768Viewport width in pixels below which core toolbar/toolbox use mobile mode.
blockInsertAnimationMsno350New-block projection animation duration; 0 disables it.
blockMoveAnimationMsno200FLIP movement animation duration; 0 disables it.
blockRemoveAnimationMsno350Safe removal-slot collapse duration; removed plugin DOM is detached synchronously.
onReadynoomittedObserver invoked after successful composition. Callback failures do not invalidate the editor.
onChangenoomittedDebounced observer receiving a detached saved document after canonical commits.
onValidationErrornoomittedContent-free observer for rejected current-format input. Observer failures are isolated.
onDiagnosticnoomittedContent-free operational diagnostics; callback failures are isolated.
diagnosticThresholdsnono slow-operation thresholdsOptional non-negative thresholds for command/save/render/paste diagnostics.

Plugin definitions ​

Register factory results, not mutable class instances:

js
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:

js
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.

Rector is released under the MIT License.