Interface: Editor
An editor instance, created by createEditor().
Properties
Methods
blur()
blur(): void;Remove focus from the editable area.
Returns
void
can()
can(command): boolean;Check whether a command applies, without running it.
Parameters
| Parameter | Type |
|---|---|
command | Command |
Returns
boolean
destroy()
destroy(): void;Release everything. The editor cannot be used afterwards.
Returns
void
enable()
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
| Parameter | Type |
|---|---|
source | EditorEnableSource |
Returns
Promise<void>
Example
await editor.enable(() => import('@writeon/advanced'))focus()
focus(position?): void;Focus the editable area, optionally moving the cursor to the start or end. Does nothing when not mounted.
Parameters
| Parameter | Type |
|---|---|
position? | "start" | "end" |
Returns
void
getJSON()
getJSON(): DocJSON;The document in the JSON format, stamped with the current schemaVersion.
Returns
getSnapshot()
getSnapshot(): EditorSnapshot;Current state for rendering UI. Returns the same frozen object until the state changes.
Returns
isActive()
isActive(name, attrs?): boolean;Whether a mark or node (optionally with matching attrs) is active at the selection.
Parameters
| Parameter | Type |
|---|---|
name | string |
attrs? | Record<string, unknown> |
Returns
boolean
mount()
mount(element): void;Attach to a DOM element. Document and history are kept across mount/unmount. Throws if already mounted.
Parameters
| Parameter | Type |
|---|---|
element | HTMLElement |
Returns
void
run()
run(command): boolean;Run a command. Returns false when it does not apply.
Parameters
| Parameter | Type |
|---|---|
command | Command |
Returns
boolean
setContent()
setContent(doc, options?): void;Replace the document. Not added to undo history unless addToHistory is true.
Parameters
| Parameter | Type |
|---|---|
doc | DocJSON |
options? | { addToHistory?: boolean; } |
options.addToHistory? | boolean |
Returns
void
setEditable()
setEditable(editable): void;Switch between editable and read-only.
Parameters
| Parameter | Type |
|---|---|
editable | boolean |
Returns
void
subscribe()
subscribe(listener): () => void;Listen for state changes. Calls are batched per microtask. Returns an unsubscribe function.
Parameters
| Parameter | Type |
|---|---|
listener | () => void |
Returns
() => void
transaction()
transaction(fn): boolean;Run several commands as one undo step. If any command returns false, nothing is applied and the result is false.
Parameters
| Parameter | Type |
|---|---|
fn | (tx) => void |
Returns
boolean
unmount()
unmount(): void;Detach from the DOM. Does nothing when not mounted.
Returns
void