Commands
@blockslides/core / Commands
Interface: Commands<ReturnType>
Defined in: blockslides/packages/core/src/index.ts:25
Type Parameters
ReturnType
ReturnType = any
Properties
blur
blur:
object
Defined in: blockslides/packages/core/src/commands/blur.ts:5
blur()
blur: () =>
ReturnType
Removes focus from the editor.
Returns
ReturnType
Example
editor.commands.blur()
clearContent
clearContent:
object
Defined in: blockslides/packages/core/src/commands/clearContent.ts:5
clearContent()
clearContent: (
emitUpdate?) =>ReturnType
Clear the whole document.
Parameters
emitUpdate?
boolean
Whether to emit an update event.
Default
true
Returns
ReturnType
Example
editor.commands.clearContent()
clearNodes
clearNodes:
object
Defined in: blockslides/packages/core/src/commands/clearNodes.ts:7
clearNodes()
clearNodes: () =>
ReturnType
Normalize nodes to a simple paragraph.
Returns
ReturnType
Example
editor.commands.clearNodes()
command
command:
object
Defined in: blockslides/packages/core/src/commands/command.ts:5
command()
command: (
fn) =>ReturnType
Define a command inline.
Parameters
fn
(props) => boolean
The command function.
Returns
ReturnType
Example
editor.commands.command(({ tr, state }) => {
...
return true
})
createParagraphNear
createParagraphNear:
object
Defined in: blockslides/packages/core/src/commands/createParagraphNear.ts:7
createParagraphNear()
createParagraphNear: () =>
ReturnType
Create a paragraph nearby.
Returns
ReturnType
Example
editor.commands.createParagraphNear()
cut
cut:
object
Defined in: blockslides/packages/core/src/commands/cut.ts:7
cut()
cut: (
range,targetPos) =>ReturnType
Cuts content from a range and inserts it at a given position.
Parameters
range
The range to cut.
from
number
The start position of the range.
to
number
The end position of the range.
targetPos
number
The position to insert the content at.
Returns
ReturnType
Example
editor.commands.cut({ from: 1, to: 3 }, 5)
deleteCurrentNode
deleteCurrentNode:
object
Defined in: blockslides/packages/core/src/commands/deleteCurrentNode.ts:5
deleteCurrentNode()
deleteCurrentNode: () =>
ReturnType
Delete the node that currently has the selection anchor.
Returns
ReturnType
Example
editor.commands.deleteCurrentNode()
deleteNode
deleteNode:
object
Defined in: blockslides/packages/core/src/commands/deleteNode.ts:8
deleteNode()
deleteNode: (
typeOrName) =>ReturnType
Delete a node with a given type or name.
Parameters
typeOrName
The type or name of the node.
string | NodeType
Returns
ReturnType
Example
editor.commands.deleteNode('paragraph')
deleteRange
deleteRange:
object
Defined in: blockslides/packages/core/src/commands/deleteRange.ts:5
deleteRange()
deleteRange: (
range) =>ReturnType
Delete a given range.
Parameters
range
The range to delete.
Returns
ReturnType
Example
editor.commands.deleteRange({ from: 1, to: 3 })
deleteSelection
deleteSelection:
object
Defined in: blockslides/packages/core/src/commands/deleteSelection.ts:7
deleteSelection()
deleteSelection: () =>
ReturnType
Delete the selection, if there is one.
Returns
ReturnType
Example
editor.commands.deleteSelection()
enter
enter:
object
Defined in: blockslides/packages/core/src/commands/enter.ts:5
enter()
enter: () =>
ReturnType
Trigger enter.
Returns
ReturnType
Example
editor.commands.enter()
exitCode
exitCode:
object
Defined in: blockslides/packages/core/src/commands/exitCode.ts:7
exitCode()
exitCode: () =>
ReturnType
Exit from a code block.
Returns
ReturnType
Example
editor.commands.exitCode()
extendMarkRange
extendMarkRange:
object
Defined in: blockslides/packages/core/src/commands/extendMarkRange.ts:10
extendMarkRange()
extendMarkRange: (
typeOrName,attributes?) =>ReturnType
Extends the text selection to the current mark by type or name.
Parameters
typeOrName
The type or name of the mark.
string | MarkType
attributes?
Record<string, any>
The attributes of the mark.
Returns
ReturnType
Examples
editor.commands.extendMarkRange('bold')
editor.commands.extendMarkRange('mention', { userId: "1" })
first
first:
object
Defined in: blockslides/packages/core/src/commands/first.ts:5
first()
first: (
commands) =>ReturnType
Runs one command after the other and stops at the first which returns true.
Parameters
commands
The commands to run.
Command[] | (props) => Command[]
Returns
ReturnType
Example
editor.commands.first([command1, command2])
focus
focus:
object
Defined in: blockslides/packages/core/src/commands/focus.ts:9
focus()
focus: (
position?,options?) =>ReturnType
Focus the editor at the given position.
Parameters
position?
The position to focus at.
options?
Optional options
Default
{ scrollIntoView: true }
scrollIntoView?
boolean
Scroll the focused position into view after focusing
Returns
ReturnType
Examples
editor.commands.focus()
editor.commands.focus(32, { scrollIntoView: false })
forEach
forEach:
object
Defined in: blockslides/packages/core/src/commands/forEach.ts:5
forEach()
forEach: <
T>(items,fn) =>ReturnType
Loop through an array of items.
Type Parameters
T
T
Parameters
items
T[]
fn
(item, props) => boolean
Returns
ReturnType
insertContent
insertContent:
object
Defined in: blockslides/packages/core/src/commands/insertContent.ts:21
insertContent()
insertContent: (
value,options?) =>ReturnType
Insert a node or string of HTML at the current position.
Parameters
value
The ProseMirror content to insert.
Content | Node | Fragment
options?
Optional options
Returns
ReturnType
Examples
editor.commands.insertContent('<h1>Example</h1>')
editor.commands.insertContent('<h1>Example</h1>', { updateSelection: false })
insertContentAt
insertContentAt:
object
Defined in: blockslides/packages/core/src/commands/insertContentAt.ts:37
insertContentAt()
insertContentAt: (
position,value,options?) =>ReturnType
Insert a node or string of HTML at a specific position.
Parameters
position
The position to insert the content at.
number | Range
value
The ProseMirror content to insert.
Content | Node | Fragment
options?
Optional options
Returns
ReturnType
Example
editor.commands.insertContentAt(0, '<h1>Example</h1>')
joinUp
joinUp:
object
Defined in: blockslides/packages/core/src/commands/join.ts:12
joinUp()
joinUp: () =>
ReturnType
Join the selected block or, if there is a text selection, the closest ancestor block of the selection that can be joined, with the sibling above it.
Returns
ReturnType
Example
editor.commands.joinUp()
joinDown
joinDown:
object
Defined in: blockslides/packages/core/src/commands/join.ts:19
joinDown()
joinDown: () =>
ReturnType
Join the selected block, or the closest ancestor of the selection that can be joined, with the sibling after it.
Returns
ReturnType
Example
editor.commands.joinDown()
joinBackward
joinBackward:
object
Defined in: blockslides/packages/core/src/commands/join.ts:26
joinBackward()
joinBackward: () =>
ReturnType
If the selection is empty and at the start of a textblock, try to reduce the distance between that block and the one before it—if there's a block directly before it that can be joined, join them. If not, try to move the selected block closer to the next one in the document structure by lifting it out of its parent or moving it into a parent of the previous block. Will use the view for accurate (bidi-aware) start-of-textblock detection if given.
Returns
ReturnType
Example
editor.commands.joinBackward()
joinForward
joinForward:
object
Defined in: blockslides/packages/core/src/commands/join.ts:35
joinForward()
joinForward: () =>
ReturnType
If the selection is empty and the cursor is at the end of a textblock, try to reduce or remove the boundary between that block and the one after it, either by joining them or by moving the other block closer to this one in the tree structure. Will use the view for accurate start-of-textblock detection if given.
Returns
ReturnType
Example
editor.commands.joinForward()
joinItemBackward
joinItemBackward:
object
Defined in: blockslides/packages/core/src/commands/joinItemBackward.ts:7
joinItemBackward()
joinItemBackward: () =>
ReturnType
Join two items backward.
Returns
ReturnType
Example
editor.commands.joinItemBackward()
joinItemForward
joinItemForward:
object
Defined in: blockslides/packages/core/src/commands/joinItemForward.ts:7
joinItemForward()
joinItemForward: () =>
ReturnType
Join two items Forwards.
Returns
ReturnType
Example
editor.commands.joinItemForward()
joinTextblockBackward
joinTextblockBackward:
object
Defined in: blockslides/packages/core/src/commands/joinTextblockBackward.ts:7
joinTextblockBackward()
joinTextblockBackward: () =>
ReturnType
A more limited form of joinBackward that only tries to join the current textblock to the one before it, if the cursor is at the start of a textblock.
Returns
ReturnType
joinTextblockForward
joinTextblockForward:
object
Defined in: blockslides/packages/core/src/commands/joinTextblockForward.ts:7
joinTextblockForward()
joinTextblockForward: () =>
ReturnType
A more limited form of joinForward that only tries to join the current textblock to the one after it, if the cursor is at the end of a textblock.
Returns
ReturnType
keyboardShortcut
keyboardShortcut:
object
Defined in: blockslides/packages/core/src/commands/keyboardShortcut.ts:61
keyboardShortcut()
keyboardShortcut: (
name) =>ReturnType
Trigger a keyboard shortcut.
Parameters
name
string
The name of the keyboard shortcut.
Returns
ReturnType
Example
editor.commands.keyboardShortcut('Mod-b')
lift
lift:
object
Defined in: blockslides/packages/core/src/commands/lift.ts:10
lift()
lift: (
typeOrName,attributes?) =>ReturnType
Removes an existing wrap if possible lifting the node out of it
Parameters
typeOrName
The type or name of the node.
string | NodeType
attributes?
Record<string, any>
The attributes of the node.
Returns
ReturnType
Examples
editor.commands.lift('paragraph')
editor.commands.lift('heading', { level: 1 })
liftEmptyBlock
liftEmptyBlock:
object
Defined in: blockslides/packages/core/src/commands/liftEmptyBlock.ts:7
liftEmptyBlock()
liftEmptyBlock: () =>
ReturnType
If the cursor is in an empty textblock that can be lifted, lift the block.
Returns
ReturnType
Example
editor.commands.liftEmptyBlock()
liftListItem
liftListItem:
object
Defined in: blockslides/packages/core/src/commands/liftListItem.ts:9
liftListItem()
liftListItem: (
typeOrName) =>ReturnType
Create a command to lift the list item around the selection up into a wrapping list.
Parameters
typeOrName
The type or name of the node.
string | NodeType
Returns
ReturnType
Example
editor.commands.liftListItem('listItem')
newlineInCode
newlineInCode:
object
Defined in: blockslides/packages/core/src/commands/newlineInCode.ts:7
newlineInCode()
newlineInCode: () =>
ReturnType
Add a newline character in code.
Returns
ReturnType
Example
editor.commands.newlineInCode()
resetAttributes
resetAttributes:
object
Defined in: blockslides/packages/core/src/commands/resetAttributes.ts:11
resetAttributes()
resetAttributes: (
typeOrName,attributes) =>ReturnType
Resets some node attributes to the default value.
Parameters
typeOrName
The type or name of the node.
string | NodeType | MarkType
attributes
The attributes of the node to reset.
string | string[]
Returns
ReturnType
Example
editor.commands.resetAttributes('heading', 'level')
scrollIntoView
scrollIntoView:
object
Defined in: blockslides/packages/core/src/commands/scrollIntoView.ts:5
scrollIntoView()
scrollIntoView: () =>
ReturnType
Scroll the selection into view.
Returns
ReturnType
Example
editor.commands.scrollIntoView()
selectAll
selectAll:
object
Defined in: blockslides/packages/core/src/commands/selectAll.ts:7
selectAll()
selectAll: () =>
ReturnType
Select the whole document.
Returns
ReturnType
Example
editor.commands.selectAll()
selectNodeBackward
selectNodeBackward:
object
Defined in: blockslides/packages/core/src/commands/selectNodeBackward.ts:7
selectNodeBackward()
selectNodeBackward: () =>
ReturnType
Select a node backward.
Returns
ReturnType
Example
editor.commands.selectNodeBackward()
selectNodeForward
selectNodeForward:
object
Defined in: blockslides/packages/core/src/commands/selectNodeForward.ts:7
selectNodeForward()
selectNodeForward: () =>
ReturnType
Select a node forward.
Returns
ReturnType
Example
editor.commands.selectNodeForward()
selectParentNode
selectParentNode:
object
Defined in: blockslides/packages/core/src/commands/selectParentNode.ts:7
selectParentNode()
selectParentNode: () =>
ReturnType
Select the parent node.
Returns
ReturnType
Example
editor.commands.selectParentNode()
selectTextblockEnd
selectTextblockEnd:
object
Defined in: blockslides/packages/core/src/commands/selectTextblockEnd.ts:9
selectTextblockEnd()
selectTextblockEnd: () =>
ReturnType
Moves the cursor to the end of current text block.
Returns
ReturnType
Example
editor.commands.selectTextblockEnd()
selectTextblockStart
selectTextblockStart:
object
Defined in: blockslides/packages/core/src/commands/selectTextblockStart.ts:9
selectTextblockStart()
selectTextblockStart: () =>
ReturnType
Moves the cursor to the start of current text block.
Returns
ReturnType
Example
editor.commands.selectTextblockStart()
setContent
setContent:
object
Defined in: blockslides/packages/core/src/commands/setContent.ts:27
setContent()
setContent: (
content,options?) =>ReturnType
Replace the whole document with new content.
Parameters
content
The new content.
Content | Node | Fragment
options?
Options for setContent.
Returns
ReturnType
Example
editor.commands.setContent('<p>Example text</p>')
setMark
setMark:
object
Defined in: blockslides/packages/core/src/commands/setMark.ts:11
setMark()
setMark: (
typeOrName,attributes?) =>ReturnType
Add a mark with new attributes.
Parameters
typeOrName
The mark type or name.
string | MarkType
attributes?
Record<string, any>
Returns
ReturnType
Example
editor.commands.setMark('bold', { level: 1 })
setMeta
setMeta:
object
Defined in: blockslides/packages/core/src/commands/setMeta.ts:7
setMeta()
setMeta: (
key,value) =>ReturnType
Store a metadata property in the current transaction.
Parameters
key
The key of the metadata property.
string | Plugin<any> | PluginKey<any>
value
any
The value to store.
Returns
ReturnType
Example
editor.commands.setMeta('foo', 'bar')
setNode
setNode:
object
Defined in: blockslides/packages/core/src/commands/setNode.ts:9
setNode()
setNode: (
typeOrName,attributes?) =>ReturnType
Replace a given range with a node.
Parameters
typeOrName
The type or name of the node
string | NodeType
attributes?
Record<string, any>
The attributes of the node
Returns
ReturnType
Example
editor.commands.setNode('paragraph')
setNodeSelection
setNodeSelection:
object
Defined in: blockslides/packages/core/src/commands/setNodeSelection.ts:8
setNodeSelection()
setNodeSelection: (
position) =>ReturnType
Creates a NodeSelection.
Parameters
position
number
Position of the node.
Returns
ReturnType
Example
editor.commands.setNodeSelection(10)
setTextSelection
setTextSelection:
object
Defined in: blockslides/packages/core/src/commands/setTextSelection.ts:8
setTextSelection()
setTextSelection: (
position) =>ReturnType
Creates a TextSelection.
Parameters
position
The position of the selection.
number | Range
Returns
ReturnType
Example
editor.commands.setTextSelection(10)
sinkListItem
sinkListItem:
object
Defined in: blockslides/packages/core/src/commands/sinkListItem.ts:9
sinkListItem()
sinkListItem: (
typeOrName) =>ReturnType
Sink the list item down into an inner list.
Parameters
typeOrName
The type or name of the node.
string | NodeType
Returns
ReturnType
Example
editor.commands.sinkListItem('listItem')
splitBlock
splitBlock:
object
Defined in: blockslides/packages/core/src/commands/splitBlock.ts:21
splitBlock()
splitBlock: (
options?) =>ReturnType
Forks a new node from an existing node.
Parameters
options?
keepMarks?
boolean
Keep marks from the previous node.
Returns
ReturnType
Examples
editor.commands.splitBlock()
editor.commands.splitBlock({ keepMarks: true })
splitListItem
splitListItem:
object
Defined in: blockslides/packages/core/src/commands/splitListItem.ts:12
splitListItem()
splitListItem: (
typeOrName,overrideAttrs?) =>ReturnType
Splits one list item into two list items.
Parameters
typeOrName
The type or name of the node.
string | NodeType
overrideAttrs?
Record<string, any>
The attributes to ensure on the new node.
Returns
ReturnType
Example
editor.commands.splitListItem('listItem')
toggleList
toggleList:
object
Defined in: blockslides/packages/core/src/commands/toggleList.ts:62
toggleList()
toggleList: (
listTypeOrName,itemTypeOrName,keepMarks?,attributes?) =>ReturnType
Toggle between different list types.
Parameters
listTypeOrName
The type or name of the list.
string | NodeType
itemTypeOrName
The type or name of the list item.
string | NodeType
keepMarks?
boolean
Keep marks when toggling.
attributes?
Record<string, any>
Attributes for the new list.
Returns
ReturnType
Example
editor.commands.toggleList('bulletList', 'listItem')
toggleMark
toggleMark:
object
Defined in: blockslides/packages/core/src/commands/toggleMark.ts:9
toggleMark()
toggleMark: (
typeOrName,attributes?,options?) =>ReturnType
Toggle a mark on and off.
Parameters
typeOrName
The mark type or name.
string | MarkType
attributes?
Record<string, any>
The attributes of the mark.
options?
extendEmptyMarkRange?
boolean
Removes the mark even across the current selection. Defaults to false.
Returns
ReturnType
Example
editor.commands.toggleMark('bold')
toggleNode
toggleNode:
object
Defined in: blockslides/packages/core/src/commands/toggleNode.ts:9
toggleNode()
toggleNode: (
typeOrName,toggleTypeOrName,attributes?) =>ReturnType
Toggle a node with another node.
Parameters
typeOrName
The type or name of the node.
string | NodeType
toggleTypeOrName
The type or name of the node to toggle.
string | NodeType
attributes?
Record<string, any>
The attributes of the node.
Returns
ReturnType
Example
editor.commands.toggleNode('heading', 'paragraph')
toggleWrap
toggleWrap:
object
Defined in: blockslides/packages/core/src/commands/toggleWrap.ts:9
toggleWrap()
toggleWrap: (
typeOrName,attributes?) =>ReturnType
Wraps nodes in another node, or removes an existing wrap.
Parameters
typeOrName
The type or name of the node.
string | NodeType
attributes?
Record<string, any>
The attributes of the node.
Returns
ReturnType
Example
editor.commands.toggleWrap('blockquote')
undoInputRule
undoInputRule:
object
Defined in: blockslides/packages/core/src/commands/undoInputRule.ts:5
undoInputRule()
undoInputRule: () =>
ReturnType
Undo an input rule.
Returns
ReturnType
Example
editor.commands.undoInputRule()
unsetAllMarks
unsetAllMarks:
object
Defined in: blockslides/packages/core/src/commands/unsetAllMarks.ts:5
unsetAllMarks()
unsetAllMarks: () =>
ReturnType
Remove all marks in the current selection.
Returns
ReturnType
Example
editor.commands.unsetAllMarks()
unsetMark
unsetMark:
object
Defined in: blockslides/packages/core/src/commands/unsetMark.ts:9
unsetMark()
unsetMark: (
typeOrName,options?) =>ReturnType
Remove all marks in the current selection.
Parameters
typeOrName
The mark type or name.
string | MarkType
options?
extendEmptyMarkRange?
boolean
Removes the mark even across the current selection. Defaults to false.
Returns
ReturnType
Example
editor.commands.unsetMark('bold')
updateAttributes
updateAttributes:
object
Defined in: blockslides/packages/core/src/commands/updateAttributes.ts:11
updateAttributes()
updateAttributes: (
typeOrName,attributes) =>ReturnType
Update attributes of a node or mark.
Parameters
typeOrName
The type or name of the node or mark.
string | NodeType | MarkType
attributes
Record<string, any>
The attributes of the node or mark.
Returns
ReturnType
Example
editor.commands.updateAttributes('mention', { userId: "2" })
wrapIn
wrapIn:
object
Defined in: blockslides/packages/core/src/commands/wrapIn.ts:9
wrapIn()
wrapIn: (
typeOrName,attributes?) =>ReturnType
Wraps nodes in another node.
Parameters
typeOrName
The type or name of the node.
string | NodeType
attributes?
Record<string, any>
The attributes of the node.
Returns
ReturnType
Example
editor.commands.wrapIn('blockquote')
wrapInList
wrapInList:
object
Defined in: blockslides/packages/core/src/commands/wrapInList.ts:9
wrapInList()
wrapInList: (
typeOrName,attributes?) =>ReturnType
Wrap a node in a list.
Parameters
typeOrName
The type or name of the node.
string | NodeType
attributes?
Record<string, any>
The attributes of the node.
Returns
ReturnType
Example
editor.commands.wrapInList('bulletList')