Skip to content
GitHubDiscord

prosekit/core

ProseKit extension priority.

Enumeration Member Value

lowest

0

low

1

default

2

high

3

highest

4

get mounted(): boolean

Whether the editor is mounted.

get view(): EditorView

The editor view.

get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>

The editor schema.

get state(): EditorState

The editor's current state.

get focused(): boolean

Whether the editor is focused.

get commands(): ExtractCommandActions<E>

All CommandActions defined by the editor.

get nodes(): ExtractNodeActions<E>

All NodeActions defined by the editor.

get marks(): ExtractMarkActions<E>

All MarkActions defined by the editor.

mount(place: undefined | null | HTMLElement): void

Mount the editor to the given HTML element. Pass null or undefined to unmount the editor.

unmount(): void

Unmount the editor. This is equivalent to mount(null).

focus(): void

Focus the editor.

blur(): void

Blur the editor.

use(extension: Extension): VoidFunction

Register an extension to the editor. Return a function to unregister the extension.

updateState(state: EditorState): void

Update the editor's state.

This is an advanced method. Use it only if you have a specific reason to directly manipulate the editor's state.

setContent(content: string | ProseMirrorNode | NodeJSON | HTMLElement, selection?: Selection | "start" | SelectionJSON | "end"): void

Update the editor's document and selection.

getDocJSON(): NodeJSON

Return a JSON object representing the editor's current document.

getDocHTML(options?: getDocHTMLOptions): string

Return a HTML string representing the editor's current document.

exec(command: Command): boolean

Execute the given command. Return true if the command was successfully executed, otherwise false.

canExec(command: Command): boolean

Check if the given command can be executed. Return true if the command can be executed, otherwise false.

type: string | MarkType

The type of the mark to add.

attrs?: null | Attrs

The attributes of the mark to add.

from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.


type: string | MarkType

The type of the mark to expand.


pos?: number

The position to insert the node at. By default it will insert after the current selection.


node?: ProseMirrorNode

The node to insert. Either this or type must be provided.

type?: string | NodeType

The type of the node to insert. Either this or node must be provided.

attrs?: Attrs

When type is provided, the attributes of the node to insert.

pos?: number

The position to insert the node at. By default it will be the anchor position of current selection.


type: string | MarkType

The type of the mark to remove.

attrs?: null | Attrs

If attrs is given, remove precisely the mark with the given attrs. Otherwise, remove all marks of the given type.

from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.


type: string | NodeType

The type of the node to remove.

pos?: number

The document position to start searching node. By default it will be the anchor position of current selection.


type: string | NodeType

attrs?: null | Attrs

from?: number

to?: number


type: string | NodeType | string[] | NodeType[]

The type of node to set the attributes of.

If current node is not of this type, the command will do nothing.

attrs: Attrs

The attributes to set.

pos?: number

The position of the node. Defaults to the position of the wrapping node containing the current selection.


type: string | MarkType

The mark type to toggle.

attrs?: null | Attrs

The optional attributes to set on the mark.

removeWhenPresent?: boolean

Controls whether, when part of the selected range has the mark already and part doesn't, the mark is removed (true) or added (false).

false

enterInlineAtoms?: boolean

Whether the command should act on the content of inline nodes marked as atoms that are completely covered by a selection range.

true


type: string | NodeType

The type of the node to toggle.

attrs?: null | Attrs

The attributes of the node to toggle.


type: string | NodeType

The type of the node to toggle.

attrs?: null | Attrs

The attributes of the node to toggle.


from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.


from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.


type: string | NodeType

The node type to wrap the selected textblock with.

nodeType?: NodeType

Use nodeSpec instead.

attrs?: null | Attrs

Optional attributes to apply to the node.


A function for creating a node with optional attributes and any number of children.

It also has a isActive method for checking if the node is active in the current editor selection.

NodeAction(attrs: null | Attrs, ...children: NodeChild[]): ProseMirrorNode

Creates a node with attributes and any number of children.

NodeAction(...children: NodeChild[]): ProseMirrorNode

Creates a node with any number of children.

isActive: (attrs?: Attrs) => boolean

Checks if the node is active in the current editor selection. If the optional attrs parameter is provided, it will check if the node is active with the given attributes.


A function for applying a mark with optional attributes and any number of children.

It also has a isActive method for checking if the mark is active in the current editor selection.

MarkAction(attrs: null | Attrs, ...children: NodeChild[]): ProseMirrorNode[]

Applies a mark with attributes and any number of children.

MarkAction(...children: NodeChild[]): ProseMirrorNode[]

Applies a mark with any number of children.

isActive: (attrs?: Attrs) => boolean

Checks if the mark is active in the current editor selection. If the optional attrs parameter is provided, it will check if the mark is active with the given attributes.


extension: E

The extension to use when creating the editor.

defaultContent?: string | NodeJSON | HTMLElement

The starting document to use when creating the editor. It can be a ProseMirror node JSON object, a HTML string, or a HTML element instance.

defaultDoc?: NodeJSON

A JSON object representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultHTML?: string | HTMLElement

A HTML element or a HTML string representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultSelection?: SelectionJSON

A JSON object representing the starting selection to use when creating the editor. It's only used when defaultContent is also provided.


defaultContent?: string | NodeJSON | HTMLElement

The starting document to use when creating the editor. It can be a ProseMirror node JSON object, a HTML string, or a HTML element instance.

defaultDoc?: NodeJSON

A JSON object representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultHTML?: string | HTMLElement

A HTML element or a HTML string representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultSelection?: SelectionJSON

A JSON object representing the starting selection to use when creating the editor. It's only used when defaultContent is also provided.


Options for defineHistory.

depth?: number

The amount of history events that are collected before the oldest events are discarded.

200

newGroupDelay?: number

The delay in milliseconds between changes after which a new group should be started.

250


[key: string]: Command


[key: string]: any

Mark specs can include additional properties that can be inspected through MarkType.spec when working with the mark.

name: MarkName

The name of the mark type.

attrs?: { [K in string | number | symbol]: AttrSpec<Attrs[K]> }

The attributes that marks of this type get.

inclusive?: boolean

Whether this mark should be active when the cursor is positioned at its end (or at its start when that is also the start of the parent node). Defaults to true.

excludes?: string

Determines which other marks this mark can coexist with. Should be a space-separated strings naming other marks or groups of marks. When a mark is added to a set, all marks that it excludes are removed in the process. If the set contains any mark that excludes the new mark but is not, itself, excluded by the new mark, the mark can not be added an the set. You can use the value "_" to indicate that the mark excludes all marks in the schema.

Defaults to only being exclusive with marks of the same type. You can set it to an empty string (or any string not containing the mark's own name) to allow multiple marks of a given type to coexist (as long as they have different attributes).

group?: string

The group or space-separated groups to which this mark belongs.

spanning?: boolean

Determines whether marks of this type can span multiple adjacent nodes when serialized to DOM/HTML. Defaults to true.

code?: boolean

Marks the content of this span as being code, which causes some commands and extensions to treat it differently.

toDOM?: (mark: Mark, inline: boolean) => DOMOutputSpec

Defines the default way marks of this type should be serialized to DOM/HTML. When the resulting spec contains a hole, that is where the marked content is placed. Otherwise, it is appended to the top node.

parseDOM?: readonly ParseRule[]

Associates DOM parser information with this mark (see the corresponding node spec field). The mark field in the rules is implied.


MarkAttrOptions<MarkName, AttrName, AttrType>

Section titled “MarkAttrOptions<MarkName, AttrName, AttrType>”

type: MarkName

The name of the mark type.

attr: AttrName

The name of the attribute.

toDOM?: (value: AttrType) => undefined | null | [string, string]

Returns the attribute key and value to be set on the HTML element.

If the returned key is "style", the value is a string of CSS properties and will be prepended to the existing style attribute on the DOM node.

parseDOM?: (node: HTMLElement) => AttrType

Parses the attribute value from the DOM.

default?: AttrType

The default value for this attribute, to use when no explicit value is provided. Attributes that have no default must be provided whenever a node or mark of a type that has them is created.

validate?: string | (value: unknown) => void

A function or type name used to validate values of this attribute. This will be used when deserializing the attribute from JSON, and when running Node.check. When a function, it should raise an exception if the value isn't of the expected type or shape. When a string, it should be a |-separated string of primitive types ("number", "string", "boolean", "null", and "undefined"), and the library will raise an error when the value is not one of those types.


name: string

constructor: MarkViewConstructor


[key: string]: any

Node specs may include arbitrary properties that can be read by other code via NodeType.spec.

name: NodeName

The name of the node type.

topNode?: boolean

Whether this is the top-level node type. Only one node type can be the top-level node type in a schema.

attrs?: { [key in string | number | symbol]: AttrSpec<Attrs[key]> }

The attributes that nodes of this type get.

disableDropCursor?: boolean | (view: EditorView, pos: object, event: DragEvent) => boolean

content?: string

The content expression for this node, as described in the schema guide. When not given, the node does not allow any content.

marks?: string

The marks that are allowed inside of this node. May be a space-separated string referring to mark names or groups, "_" to explicitly allow all marks, or "" to disallow marks. When not given, nodes with inline content default to allowing all marks, other nodes default to not allowing marks.

group?: string

The group or space-separated groups to which this node belongs, which can be referred to in the content expressions for the schema.

inline?: boolean

Should be set to true for inline nodes. (Implied for text nodes.)

atom?: boolean

Can be set to true to indicate that, though this isn't a leaf node, it doesn't have directly editable content and should be treated as a single unit in the view.

selectable?: boolean

Controls whether nodes of this type can be selected as a node selection. Defaults to true for non-text nodes.

draggable?: boolean

Determines whether nodes of this type can be dragged without being selected. Defaults to false.

code?: boolean

Can be used to indicate that this node contains code, which causes some commands to behave differently.

whitespace?: "pre" | "normal"

Controls way whitespace in this a node is parsed. The default is "normal", which causes the DOM parser to collapse whitespace in normal mode, and normalize it (replacing newlines and such with spaces) otherwise. "pre" causes the parser to preserve spaces inside the node. When this option isn't given, but code is true, whitespace will default to "pre". Note that this option doesn't influence the way the node is rendered—that should be handled by toDOM and/or styling.

definingAsContext?: boolean

Determines whether this node is considered an important parent node during replace operations (such as paste). Non-defining (the default) nodes get dropped when their entire content is replaced, whereas defining nodes persist and wrap the inserted content.

definingForContent?: boolean

In inserted content the defining parents of the content are preserved when possible. Typically, non-default-paragraph textblock types, and possibly list items, are marked as defining.

defining?: boolean

When enabled, enables both definingAsContext and definingForContent.

isolating?: boolean

When enabled (default is false), the sides of nodes of this type count as boundaries that regular editing operations, like backspacing or lifting, won't cross. An example of a node that should probably have this enabled is a table cell.

toDOM?: (node: ProseMirrorNode) => DOMOutputSpec

Defines the default way a node of this type should be serialized to DOM/HTML (as used by DOMSerializer.fromSchema). Should return a DOM node or an array structure that describes one, with an optional number zero (“hole”) in it to indicate where the node's content should be inserted.

For text nodes, the default is to create a text DOM node. Though it is possible to create a serializer where text is rendered differently, this is not supported inside the editor, so you shouldn't override that in your text node spec.

parseDOM?: readonly TagParseRule[]

Associates DOM parser information with this node, which can be used by DOMParser.fromSchema to automatically derive a parser. The node field in the rules is implied (the name of this node will be filled in automatically). If you supply your own parser, you do not need to also specify parsing rules in your schema.

toDebugString?: (node: ProseMirrorNode) => string

Defines the default way a node of this type should be serialized to a string representation for debugging (e.g. in error messages).

leafText?: (node: ProseMirrorNode) => string

Defines the default way a leaf node of this type should be serialized to a string (as used by Node.textBetween and Node.textContent).

linebreakReplacement?: boolean

A single inline node in a schema can be set to be a linebreak equivalent. When converting between block types that support the node and block types that don't but have whitespace set to "pre", setBlockType will convert between newline characters to or from linebreak nodes as appropriate.


NodeAttrOptions<NodeName, AttrName, AttrType>

Section titled “NodeAttrOptions<NodeName, AttrName, AttrType>”

type: NodeName

The name of the node type.

attr: AttrName

The name of the attribute.

splittable?: boolean

Whether the attribute should be kept when the node is split. Set it to true if you want to inherit the attribute from the previous node when splitting the node by pressing Enter.

undefined

toDOM?: (value: AttrType) => undefined | null | [string, string]

Returns the attribute key and value to be set on the HTML element.

If the returned key is "style", the value is a string of CSS properties and will be prepended to the existing style attribute on the DOM node.

parseDOM?: (node: HTMLElement) => AttrType

Parses the attribute value from the DOM.

default?: AttrType

The default value for this attribute, to use when no explicit value is provided. Attributes that have no default must be provided whenever a node or mark of a type that has them is created.

validate?: string | (value: unknown) => void

A function or type name used to validate values of this attribute. This will be used when deserializing the attribute from JSON, and when running Node.check. When a function, it should raise an exception if the value isn't of the expected type or shape. When a string, it should be a |-separated string of primitive types ("number", "string", "boolean", "null", and "undefined"), and the library will raise an error when the value is not one of those types.


name: string

constructor: NodeViewConstructor


get reducer(): FacetReducer<Input, Output>


A function to apply a command to the editor. It will return true if the command was applied, and false otherwise.

It also has a canExec method to check if the command can be applied.

CommandAction(...args: Args): boolean

Execute the current command. Return true if the command was successfully executed, otherwise false.

canExec(...args: Args): boolean

Check if the current command can be executed. Return true if the command can be executed, otherwise false.

canApply(...args: Args): boolean

An alias for canExec.

Use canExec instead.


extension: Extension<ExtensionTyping<any, any, any>> | Extension<ExtensionTyping<any, any, any>>[]

priority?: Priority

schema: null | Schema<any, any>

The schema that this extension represents.


A JSON representation of the prosemirror node.

type: string

marks?: object[]

text?: string

content?: NodeJSON[]

attrs?: Record<string, any>


A JSON representation of the prosemirror selection.

anchor: number

head: number

type: string


A JSON representation of the prosemirror state.

doc: NodeJSON

The main ProseMirror doc.

selection: SelectionJSON

The current selection.


A JSON representation of the prosemirror step.

[x: string]: unknown

stepType: string

The type of the step.


node: ProseMirrorNode

The closest parent node that satisfies the predicate.

pos: number

The position directly before the node.

start: number

The position at the start of the node.

depth: number

The depth of the node.


DOMParser?: typeof DOMParser

preserveWhitespace?: boolean | "full"

By default, whitespace is collapsed as per HTML's rules. Pass true to preserve whitespace, but normalize newlines to spaces, and "full" to preserve whitespace entirely.

findPositions?: object[]

When given, the parser will, beside parsing the content, record the document positions of the given DOM positions. It will do so by writing to the objects, adding a pos property that holds the document position. DOM positions that are not in the parsed content will not be written to.

from?: number

The child node index to start parsing from.

to?: number

The child node index to stop parsing at.

topNode?: ProseMirrorNode

By default, the content is parsed into the schema's default top node type. You can pass this option to use the type and attributes from a different node as the top container.

topMatch?: ContentMatch

Provide the starting content match that content parsed into the top node is matched against.

context?: ResolvedPos

A set of additional nodes to count as context when parsing, above the given top node.


DOMSerializer?: object


document?: Document

The Document object to use for DOM operations. If not provided, defaults to the current browser's document object. Useful for server-side rendering or testing environments.


schema: Schema

The editor schema to use.

type NodeChild = ProseMirrorNode | string | NodeChild[]

Available children parameters for NodeAction and MarkAction.


type NodeBuilder = NodeAction

Use type NodeAction instead.


type MarkBuilder = MarkAction

Use type MarkAction instead.


type DocChangeHandler = (view: EditorView, prevState: EditorState) => void

A function that is called when the editor document is changed.


type DOMEventHandler<Event> = (view: EditorView, event: DOMEventMap[Event]) => boolean | void

A function to handle the events fired on the editable DOM element. Returns true to indicate that it handled the given event. you are responsible for calling preventDefault yourself (or not, if you want to allow the default behavior).


type KeyDownHandler = (view: EditorView, event: KeyboardEvent) => boolean | void


type KeyPressHandler = (view: EditorView, event: KeyboardEvent) => boolean | void


type TextInputHandler = (view: EditorView, from: number, to: number, text: string) => boolean | void


type ClickOnHandler = (view: EditorView, pos: number, node: ProseMirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void


type ClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void


type DoubleClickOnHandler = (view: EditorView, pos: number, node: ProseMirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void


type DoubleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void


type TripleClickOnHandler = (view: EditorView, pos: number, node: ProseMirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void


type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void


type PasteHandler = (view: EditorView, event: ClipboardEvent, slice: Slice) => boolean | void


type DropHandler = (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void


type ScrollToSelectionHandler = (view: EditorView) => boolean


type FocusChangeHandler = (hasFocus: boolean) => void

A function that is called when the editor gains or loses focus.


type MountHandler = (view: EditorView) => void

A function that is called when the editor view is mounted.


type UpdateHandler = (view: EditorView, prevState: EditorState) => void

A function that is called when the editor state is updated.


type UnmountHandler = () => void

A function that is called when the editor view is unmounted.


type AnyAttrs = Attrs

An object holding the attributes of a node.


type AttrSpec<AttrType> = { default?: AttrType; validate?: string | (value: unknown) => void; }

default?: AttrType

The default value for this attribute, to use when no explicit value is provided. Attributes that have no default must be provided whenever a node or mark of a type that has them is created.

validate?: string | (value: unknown) => void

A function or type name used to validate values of this attribute. This will be used when deserializing the attribute from JSON, and when running Node.check. When a function, it should raise an exception if the value isn't of the expected type or shape. When a string, it should be a |-separated string of primitive types ("number", "string", "boolean", "null", and "undefined"), and the library will raise an error when the value is not one of those types.


type ExtractNodes<E> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>["Nodes"]>>


type ExtractMarks<E> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>["Marks"]>>


type ExtractCommandCreators<E> = ToCommandCreators<ExtractCommands<E>>


type ExtractCommandActions<E> = ToCommandAction<ExtractCommands<E>>

Extracts the CommandActions from an extension type.


type ExtractNodeActions<E> = ToNodeAction<ExtractNodes<E>>

Extracts the NodeActions from an extension type.


type ExtractMarkActions<E> = ToMarkAction<ExtractMarks<E>>

Extracts the MarkActions from an extension type.


type ExtractCommandAppliers<E> = ExtractCommandActions<E>

Use ExtractCommandActions instead.

const canUseRegexLookbehind: () => boolean


const clsx: (...args: (string | boolean | null | undefined)[]) => string = clsxLite

A utility for constructing className strings conditionally.

It is a re-export of clsx/lite with stricter types.

function addMark(options: AddMarkOptions): Command

Returns a command that adds the given mark with the given attributes.


function expandMark(options: ExpandMarkOptions): Command

Expands the selection to include the entire mark at the current position.


function insertDefaultBlock(options?: InsertDefaultBlockOptions): Command

Returns a command that inserts a default block after current selection or at the given position.


function insertNode(options: InsertNodeOptions): Command

Returns a command that inserts the given node at the current selection or at the given position.


function removeMark(options: RemoveMarkOptions): Command

Returns a command that removes the given mark.


function removeNode(options: RemoveNodeOptions): Command

Returns a command to remove the nearest ancestor node of a specific type from the current position.


function setBlockType(options: SetBlockTypeOptions): Command

Returns a command that tries to set the selected textblocks to the given node type with the given attributes.


function setNodeAttrs(options: SetNodeAttrsOptions): Command

Returns a command that set the attributes of the current node.


function toggleMark(options: ToggleMarkOptions): Command

Returns a command that toggles the given mark with the given attributes.


function toggleNode(options: ToggleNodeOptions): Command

Returns a command that set the selected textblocks to the given node type with the given attributes.


function toggleWrap(options: ToggleWrapOptions): Command

Toggle between wrapping an inactive node with the provided node type, and lifting it up into its parent.


function unsetBlockType(options?: UnsetBlockTypeOptions): Command

Returns a command that set the type of all textblocks between the given range to the default type (usually paragraph).


function unsetMark(options?: UnsetMarkOptions): Command

Returns a command that removes all marks.


function wrap(options: WrapOptions): Command

Returns a command that wraps the selected textblock with the given node type.


function createEditor<E>(options: EditorOptions<E>): Editor<E>


function union<E>(...exts: E): Union<E>

Merges multiple extensions into one. You can pass multiple extensions as arguments or a single array containing multiple extensions.

If no extensions are provided.

function defineFancyNodes() {
  return union(
    defineFancyParagraph(),
    defineFancyHeading(),
  )
}
function defineFancyNodes() {
  return union([
    defineFancyParagraph(),
    defineFancyHeading(),
  ])
}

function union<E>(exts: E): Union<E>

Merges multiple extensions into one. You can pass multiple extensions as arguments or a single array containing multiple extensions.

If no extensions are provided.

function defineFancyNodes() {
  return union(
    defineFancyParagraph(),
    defineFancyHeading(),
  )
}
function defineFancyNodes() {
  return union([
    defineFancyParagraph(),
    defineFancyHeading(),
  ])
}

function withPriority<T>(extension: T, priority: Priority): T

Return an new extension with the given priority.

import { Priority, withPriority } from 'prosekit/core'

const extension = withPriority(defineMyExtension(), Priority.high)

function defineCommands<T>(commands: T): Extension<{ Commands: { [K in string | number | symbol]: Parameters<T[K]> }; }>


function defineBaseCommands(): BaseCommandsExtension

Add some base commands


function defineDefaultState(options: DefaultStateOptions): PlainExtension

Define a default state for the editor.


function defineDoc(): DocExtension

Use the following import instead:

import { defineDoc } from 'prosekit/extensions/doc'

function defineDocChangeHandler(handler: DocChangeHandler): PlainExtension

Registers a event handler that is called when the editor document is changed.


function defineDOMEventHandler<Event>(event: Event, handler: DOMEventHandler<Event>): PlainExtension

Register a new event handler for the given event type.


function defineKeyDownHandler(handler: KeyDownHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown


function defineKeyPressHandler(handler: KeyPressHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyPress


function defineTextInputHandler(handler: TextInputHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleTextInput


function defineClickOnHandler(handler: ClickOnHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleClickOn


function defineClickHandler(handler: ClickHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleClick


function defineDoubleClickOnHandler(handler: DoubleClickOnHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClickOn


function defineDoubleClickHandler(handler: DoubleClickHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClick


function defineTripleClickOnHandler(handler: TripleClickOnHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClickOn


function defineTripleClickHandler(handler: TripleClickHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClick


function definePasteHandler(handler: PasteHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste


function defineDropHandler(handler: DropHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleDrop


function defineScrollToSelectionHandler(handler: ScrollToSelectionHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleScrollToSelection


function defineFocusChangeHandler(handler: FocusChangeHandler): PlainExtension

Registers a event handler that is called when the editor gains or loses focus.


function defineMountHandler(handler: MountHandler): PlainExtension

Registers a event handler that is called when the editor view is mounted.


function defineUpdateHandler(handler: UpdateHandler): PlainExtension

Registers a event handler that is called when the editor state is updated.


function defineUnmountHandler(handler: UnmountHandler): PlainExtension

Registers a event handler that is called when the editor view is unmounted.


function defineHistory(options: HistoryOptions): HistoryExtension

Add undo/redo history to the editor.


function defineBaseKeymap(options?: object): PlainExtension

Defines some basic key bindings.


function defineKeymap(keymap: Keymap): PlainExtension


function defineMarkSpec<Mark, Attrs>(options: MarkSpecOptions<Mark, Attrs>): Extension<{ Marks: { [K in string]: Attrs }; }>


function defineMarkAttr<MarkType, AttrName, AttrType>(options: MarkAttrOptions<MarkType, AttrName, AttrType>): Extension<{ Marks: { [K in string]: AttrType }; }>


function defineMarkView(options: MarkViewOptions): Extension


function defineNodeSpec<Node, Attrs>(options: NodeSpecOptions<Node, Attrs>): Extension<{ Nodes: { [K in string]: Attrs }; }>

Defines a node type.


function defineNodeAttr<NodeType, AttrName, AttrType>(options: NodeAttrOptions<NodeType, AttrName, AttrType>): Extension<{ Nodes: { [K in string]: { [K in string]: AttrType } }; }>

Defines an attribute for a node type.


function defineNodeView(options: NodeViewOptions): Extension


function defineParagraph(): ParagraphSpecExtension

Defines a paragraph node spec as the highest priority, because it should be the default block node for most cases.

Use the following import instead:

import { defineParagraph } from 'prosekit/extensions/paragraph'

function definePlugin(plugin: ProseMirrorPlugin<any> | ProseMirrorPlugin<any>[] | (context: object) => ProseMirrorPlugin<any> | ProseMirrorPlugin<any>[]): PlainExtension

Adds a ProseMirror plugin to the editor.


function defineText(): TextExtension

Use the following import instead:

import { defineText } from 'prosekit/extensions/text'

function findParentNodeOfType(type: string | NodeType, $pos: ResolvedPos): undefined | FindParentNodeResult

Finds the closest parent node that matches the given node type.


function findParentNode(predicate: (node: ProseMirrorNode) => boolean, $pos: ResolvedPos): undefined | FindParentNodeResult

Find the closest parent node that satisfies the predicate.


function jsonFromState(state: EditorState): StateJSON

Return a JSON object representing this state.

const state = editor.state
const json = jsonFromState(state)

function stateFromJSON(json: StateJSON, options: JSONParserOptions): EditorState

Parse a JSON object to a ProseMirror state.

const json = { state: { type: 'doc', content: [{ type: 'paragraph' }], selection: { type: 'text', from: 1, to: 1 } } }
const state = stateFromJSON(json, { schema: editor.schema })

function jsonFromNode(node: ProseMirrorNode): NodeJSON

Return a JSON object representing this node.

const node = editor.state.doc
const json = jsonFromNode(node)

function nodeFromJSON(json: NodeJSON, options: JSONParserOptions): ProseMirrorNode

Parse a JSON object to a ProseMirror node.

const json = { type: 'doc', content: [{ type: 'paragraph' }] }
const node = nodeFromJSON(json, { schema: editor.schema })

function nodeFromElement(element: Node, options: DOMParserOptions & JSONParserOptions): ProseMirrorNode

Parse a HTML element to a ProseMirror node.

const element = document.getElementById('content')
const node = nodeFromElement(element, { schema: editor.schema })

function elementFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): HTMLElement

Serialize a ProseMirror node to a HTML element.

const node = editor.state.doc
const element = elementFromNode(node)

function nodeFromHTML(html: string, options: DOMParserOptions & JSONParserOptions & DOMDocumentOptions): ProseMirrorNode

Parse a HTML string to a ProseMirror node.

const html = '<p>Hello, world!</p>'
const node = nodeFromHTML(html, { schema: editor.schema })

function htmlFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): string

Serialize a ProseMirror node to a HTML string

const node = document.getElementById('content')
const html = htmlFromNode(node)

function elementFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): HTMLElement

Parse a ProseMirror document JSON object to a HTML element.

const json = { type: 'doc', content: [{ type: 'paragraph' }] }
const element = elementFromJSON(json, { schema: editor.schema })

function jsonFromHTML(html: string, options: DOMDocumentOptions & DOMParserOptions & JSONParserOptions): NodeJSON

Parse a HTML string to a ProseMirror document JSON object.

const html = '<p>Hello, world!</p>'
const json = jsonFromHTML(html, { schema: editor.schema })

function htmlFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): string

Parse a ProseMirror document JSON object to a HTML string.

const json = { type: 'doc', content: [{ type: 'paragraph' }] }
const html = htmlFromJSON(json, { schema: editor.schema })

function setSelectionAround(tr: Transaction, pos: number): void


function isProseMirrorNode(value: unknown): value is ProseMirrorNode

Checks if the given object is a ProseMirrorNode instance.


function isMark(value: unknown): value is Mark

Checks if the given object is a Mark instance.


function isFragment(value: unknown): value is ProseMirrorFragment

Checks if the given object is a Fragment instance.


function isSlice(value: unknown): value is Slice

Checks if the given object is a Slice instance.


function isSelection(value: unknown): value is Selection

Checks if the given object is a Selection instance.


function isTextSelection(value: Selection): value is TextSelection

Checks if the given object is a TextSelection instance.


function isNodeSelection(value: Selection): value is NodeSelection

Checks if the given object is a NodeSelection instance.


function isAllSelection(value: Selection): value is AllSelection

Checks if the given object is a AllSelection instance.