Skip to content

EditorHost

What the editor calls back into, per document: pass it as host to createEditorState. The editor reads each member through the object when it needs it, so you can change the object later without rebuilding the state.

Every member is optional: a capability the host does not provide is switched off quietly (no error, no notice) and the rest of the editor carries on. Window-wide capabilities live in the editor environment (configureEditorEnvironment).

optional getFolder?: () => string | null

The root folder of the user's files, for link-target completion. A getter, read each time completion opens. Null, or absent: completion uses the document's own directory.

string | null


optional listFiles?: (root) => Promise<string[]>

The linkable files under root, as root-relative paths (link-target completion). Absent: file completion offers nothing; heading completion is unaffected.

string

Promise<string[]>


optional onChange?: (doc, isUserEdit, docPath) => void

The document changed; doc is the whole new source. isUserEdit is true for typing, pasting and other user actions, false for programmatic changes (setDoc). docPath is the document the change happened in, so a host that swaps documents can drop a change for one that is no longer shown.

string

boolean

string | null

void


optional onMoved?: () => void

The selection, scroll position or document moved (debounced); use it to remember the position.

void


optional onOutline?: (outline) => void

The heading outline changed; null when the view is going away (clear yours).

Heading[] | null

void


optional onUnsupportedPaste?: (reason, count) => void

Images were pasted or dropped but could not be stored, so nothing was inserted: reason is "no-save-attachment" (no saveAttachment) or "no-doc-path" (the document has no path to store them beside); count is how many images. Only a notice — the editor itself stays silent and the document is unchanged. Use it to tell the user. Absent: nothing happens.

"no-save-attachment" | "no-doc-path"

number

void


optional openLink?: (absPath, fragment) => void

A link to a local file was followed (Cmd/Ctrl+click; a plain click in reading mode): absPath is the target resolved against the document's directory, and fragment its decoded #fragment without the # (other.md#setup → "setup"), or null. The host decides whether the file exists, how to open it and whether to go to the fragment. Absent: local links do nothing.

string

string | null

void


optional resolveImage?: (src) => string | null

Map an image target as written (![](src)) to a URL the page may load, or null to show the source instead. Script-capable URLs are dropped whatever this returns. Absent: only absolute https: images load. It may be called more than once for the same image, so keep it free of side effects; when its answer changes, call editor.refreshImages().

string

string | null


optional saveAttachment?: (docPath, bytes, hint) => Promise<string | null>

Store pasted / dropped image bytes beside docPath. hint is the file's name, or its MIME type. Resolves the document-relative path to link, or null when the save failed (report it yourself); then the editor inserts nothing. Only called when the document has a path. Absent: image paste / drop stores nothing and inserts nothing.

string

Uint8Array

string | null

Promise<string | null>