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).
Properties
Section titled “Properties”getFolder?
Section titled “getFolder?”
optionalgetFolder?: () =>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.
Returns
Section titled “Returns”string | null
listFiles?
Section titled “listFiles?”
optionallistFiles?: (root) =>Promise<string[]>
The linkable files under root, as root-relative paths (link-target
completion). Absent: file completion offers nothing; heading completion is
unaffected.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<string[]>
onChange?
Section titled “onChange?”
optionalonChange?: (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.
Parameters
Section titled “Parameters”string
isUserEdit
Section titled “isUserEdit”boolean
docPath
Section titled “docPath”string | null
Returns
Section titled “Returns”void
onMoved?
Section titled “onMoved?”
optionalonMoved?: () =>void
The selection, scroll position or document moved (debounced); use it to remember the position.
Returns
Section titled “Returns”void
onOutline?
Section titled “onOutline?”
optionalonOutline?: (outline) =>void
The heading outline changed; null when the view is going away (clear yours).
Parameters
Section titled “Parameters”outline
Section titled “outline”Heading[] | null
Returns
Section titled “Returns”void
onUnsupportedPaste?
Section titled “onUnsupportedPaste?”
optionalonUnsupportedPaste?: (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.
Parameters
Section titled “Parameters”reason
Section titled “reason”"no-save-attachment" | "no-doc-path"
number
Returns
Section titled “Returns”void
openLink?
Section titled “openLink?”
optionalopenLink?: (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.
Parameters
Section titled “Parameters”absPath
Section titled “absPath”string
fragment
Section titled “fragment”string | null
Returns
Section titled “Returns”void
resolveImage?
Section titled “resolveImage?”
optionalresolveImage?: (src) =>string|null
Map an image target as written () 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().
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string | null
saveAttachment?
Section titled “saveAttachment?”
optionalsaveAttachment?: (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.
Parameters
Section titled “Parameters”docPath
Section titled “docPath”string
Uint8Array
string | null
Returns
Section titled “Returns”Promise<string | null>