Skip to content

Interface: Editor ​

An editor instance, created by createEditor().

Properties ​

PropertyModifierTypeDescription
isEmptyreadonlybooleanWhether the document is a single empty text block.
pmreadonly{ schema: Schema; state: EditorState; view: EditorView | null; }Direct access to ProseMirror. Not a stable API: it may change in any minor release.
pm.schemareadonlySchemaThe schema built from the extensions.
pm.statereadonlyEditorStateThe current state.
pm.viewreadonlyEditorView | nullThe view, or null while not mounted.

Methods ​

blur() ​

ts
blur(): void;

Remove focus from the editable area.

Returns ​

void


can() ​

ts
can(command): boolean;

Check whether a command applies, without running it.

Parameters ​

ParameterType
commandCommand

Returns ​

boolean


destroy() ​

ts
destroy(): void;

Release everything. The editor cannot be used afterwards.

Returns ​

void


enable() ​

ts
enable(source): Promise<void>;

Add behaviour (commands' keymaps, input rules, plugins) from more extensions to the running editor, typically loaded on demand. The document, undo history and selection are kept. Their nodes and marks must already be in the schema: pass the schema extension (e.g. advancedSchema()) to createEditor(). Extensions already added are skipped.

Parameters ​

ParameterType
sourceEditorEnableSource

Returns ​

Promise<void>

Example ​

ts
await editor.enable(() => import('@writeon/advanced'))

focus() ​

ts
focus(position?): void;

Focus the editable area, optionally moving the cursor to the start or end. Does nothing when not mounted.

Parameters ​

ParameterType
position?"start" | "end"

Returns ​

void


getJSON() ​

ts
getJSON(): DocJSON;

The document in the JSON format, stamped with the current schemaVersion.

Returns ​

DocJSON


getSnapshot() ​

ts
getSnapshot(): EditorSnapshot;

Current state for rendering UI. Returns the same frozen object until the state changes.

Returns ​

EditorSnapshot


isActive() ​

ts
isActive(name, attrs?): boolean;

Whether a mark or node (optionally with matching attrs) is active at the selection.

Parameters ​

ParameterType
namestring
attrs?Record<string, unknown>

Returns ​

boolean


mount() ​

ts
mount(element): void;

Attach to a DOM element. Document and history are kept across mount/unmount. Throws if already mounted.

Parameters ​

ParameterType
elementHTMLElement

Returns ​

void


run() ​

ts
run(command): boolean;

Run a command. Returns false when it does not apply.

Parameters ​

ParameterType
commandCommand

Returns ​

boolean


setContent() ​

ts
setContent(doc, options?): void;

Replace the document. Not added to undo history unless addToHistory is true.

Parameters ​

ParameterType
docDocJSON
options?{ addToHistory?: boolean; }
options.addToHistory?boolean

Returns ​

void


setEditable() ​

ts
setEditable(editable): void;

Switch between editable and read-only.

Parameters ​

ParameterType
editableboolean

Returns ​

void


subscribe() ​

ts
subscribe(listener): () => void;

Listen for state changes. Calls are batched per microtask. Returns an unsubscribe function.

Parameters ​

ParameterType
listener() => void

Returns ​

() => void


transaction() ​

ts
transaction(fn): boolean;

Run several commands as one undo step. If any command returns false, nothing is applied and the result is false.

Parameters ​

ParameterType
fn(tx) => void

Returns ​

boolean


unmount() ​

ts
unmount(): void;

Detach from the DOM. Does nothing when not mounted.

Returns ​

void