Install prosemirror-utils
package from npm:
npm install prosemirror-utils
-
findParentNode
(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → ?{pos: number, node: ProseMirrorNode}
Iterates over parent nodes, returning the first node and its positionpredicate
returns truthy for. -
findParentDomRef
(predicate: fn(node: ProseMirrorNode) → boolean, domAtPos: fn(pos: number) → {node: dom.Node, offset: number}) → fn(selection: Selection) → ?dom.Node
Iterates over parent nodes, returning DOM reference of the first nodepredicate
returns truthy for. -
hasParentNode
(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → boolean
Checks if there's a parent nodepredicate
returns truthy for. -
findParentNodeOfType
(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{node: ProseMirrorNode, pos: number}
Iterates over parent nodes, returning first node of the givennodeType
. -
hasParentNodeOfType
(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → boolean
Checks if there's a parent node of the givennodeType
. -
findParentDomRefOfType
(nodeType: NodeType | [NodeType], domAtPos: fn(pos: number) → {node: dom.Node, offset: number}) → fn(selection: Selection) → ?dom.Node
Iterates over parent nodes, returning DOM reference of the first node of the givennodeType
. -
findSelectedNodeOfType
(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{node: ProseMirrorNode, pos: number}
Returns a node of a givennodeType
if its selected. -
isNodeSelection
(selection: Selection) → boolean
Checks if current selection is a NodeSelection -
findPositionOfNodeBefore
(selection: Selection) → ?number
Returns position of the previous node
-
flatten
(node: ProseMirrorNode, descend: ?boolean = true) → [{node: ProseMirrorNode, pos: number}]
Flattens descendants of a givennode
. Doesn't descend into anode
whendescend
argument isfalse
. Defaults totrue
. -
findChildren
(node: ProseMirrorNode, predicate: fn(node: ProseMirrorNode) → boolean, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]
Iterates over descendants of a givennode
, returning child nodespredicate
returns truthy for. Doesn't descend into anode
whendescend
argument isfalse
. -
findTextNodes
(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]
Returns text nodes of a givennode
. Doesn't descend into anode
whendescend
argument isfalse
. -
findInlineNodes
(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]
Returns inline nodes of a givennode
. Doesn't descend into anode
whendescend
argument isfalse
. -
findBlockNodes
(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]
Returns block descendants of a givennode
. Doesn't descend into anode
whendescend
argument isfalse
. -
findChildrenByAttr
(node: ProseMirrorNode, predicate: fn(attrs: ?Object) → boolean, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]
Iterates over descendants of a givennode
, returning child nodespredicate
returns truthy for. Doesn't descend into anode
whendescend
argument isfalse
. -
findChildrenByType
(node: ProseMirrorNode, nodeType: NodeType, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]
Iterates over descendants of a givennode
, returning child nodes of a givennodeType
. Doesn't descend into anode
whendescend
argument isfalse
. -
findChildrenByMark
(node: ProseMirrorNode, markType: markType, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]
Iterates over descendants of a givennode
, returning child nodes that have a mark of a givenmarkType
. Doesn't descend into anode
whendescend
argument isfalse
. exapmle:findChildrenByMark(paragraph, schema.marks.strong)
-
contains
(node: ProseMirrorNode, nodeType: NodeType) → boolean
Returnstrue
if a givennode
contains nodes of a givennodeType
-
findTable
(selection: Selection) → ?{pos: number, node: ProseMirrorNode}
Iterates over parent nodes, returning the first found table node. -
isCellSelection
(selection: Selection) → boolean
Checks if current selection is a CellSelection -
isColumnSelected
(columnIndex: number) → fn(selection: Selection) → boolean
Checks if entire column at indexcolumnIndex
is selected -
isRowSelected
(rowIndex: number) → fn(selection: Selection) → boolean
Checks if entire row at indexrowIndex
is selected -
isTableSelected
(selection: Selection) → boolean
Checks if entire table is selected -
getCellsInColumn
(columnIndex: number) → fn(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]
Returns an array of cells in a column at indexcolumnIndex
. -
getCellsInRow
(rowIndex: number) → fn(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]
Returns an array of cells in a row at indexrowIndex
. -
getCellsInTable
(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]
Returns an array of all cells in a table. -
selectColumn
(columnIndex: number) → fn(tr: Transaction) → Transaction
Creates a CellSelection on a column atcolumnIndex
. -
selectRow
(rowIndex: number) → fn(tr: Transaction) → Transaction
Creates a CellSelection on a row atrowIndex
. -
selectTable
(selection: Selection) → fn(tr: Transaction) → Transaction
Creates a CellSelection on the entire table. -
emptySelectedCells
(schema: Schema) → fn(tr: Transaction) → Transaction
Clears the content of selected cells. -
addColumnAt
(columnIndex: number) → fn(tr: Transaction) → Transaction
Returns a new transaction that adds a new column atcolumnIndex
. -
addRowAt
(rowIndex: number) → fn(tr: Transaction) → Transaction
Returns a new transaction that adds a new row atrowIndex
. -
removeColumnAt
(columnIndex: number) → fn(tr: Transaction) → Transaction
Returns a new transaction that removes a column atcolumnIndex
. -
removeRowAt
(rowIndex: number) → fn(tr: Transaction) → Transaction
Returns a new transaction that removes a row atrowIndex
. -
removeTable
(tr: Transaction) → Transaction
Returns a new transaction that removes a table if the cursor is inside -
removeSelectedColumns
(tr: Transaction) → Transaction
Returns a new transaction that removes selected columns -
removeSelectedRows
(tr: Transaction) → Transaction
Returns a new transaction that removes selected rows
-
removeParentNodeOfType
(nodeType: NodeType | [NodeType]) → fn(tr: Transaction) → Transaction
Returns a new transaction that removes a node of a givennodeType
. It will return the original transaction if parent node hasn't been found. -
replaceParentNodeOfType
(nodeType: NodeType | [NodeType], content: ProseMirrorNode | Fragment) → fn(tr: Transaction) → Transaction
Returns a new transaction that replaces parent node of a givennodeType
with the givencontent
. It will return the original transaction if parent node hasn't been found, or replacing is not possible. -
removeSelectedNode
(tr: Transaction) → Transaction
Returns a new transaction that removes selected node. It will return the original transaction if current selection is not a NodeSelection -
replaceSelectedNode
(node: ProseMirrorNode) → fn(tr: Transaction) → Transaction
Returns a new transaction that replaces selected node with a givennode
. It will return the original transaction if current selection is not a NodeSelection, or replacing is not possible. -
canInsert
($pos: ResolvedPos, content: ProseMirrorNode | Fragment) → boolean
Checks if a givencontent
can be inserted at the given$pos
-
safeInsert
(content: ProseMirrorNode | Fragment, position: ?number) → fn(tr: Transaction) → Transaction
Returns a new transaction that inserts a givennode
at the current cursor position, or at a givenposition
, if it is allowed by schema. If schema restricts such nesting, it will try to find an appropriate place for a givennode
in the document, looping through parent nodes up until the root document node. If cursor is inside of an empty paragraph at the top level (depth=0), it will try to replace that paragraph with the givencontent
. If insertion is successful and inserted node has content, it will set cursor inside of that content. It will return the original transaction if the place for insertion hasn't been found. -
setParentNodeMarkup
(nodeType: NodeType | [NodeType], type: ?NodeType | null, attrs: ?Object | null, marks: ?[Mark]) → fn(tr: Transaction) → Transaction
Returns a transaction that changes the type, attributes, and/or marks of the parent node of a givennodeType
. -
selectParentNodeOfType
(nodeType: NodeType | [NodeType]) → fn(tr: Transaction) → Transaction
Returns a transaction that sets a NodeSelection on a parent node of a givennodeType
. -
removeNodeBefore
(tr: Transaction) → Transaction
Returns a transaction that deletes previous node from the current selection -
setTextSelection
(position: number) → fn(tr: Transaction) → Transaction
Tries to find a valid cursor selection starting at the givenposition
and returns a new transaction. If a valid cursor position hasn't been found, it will return the original transaction.
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0