replace toggleBlockType with toggleNode(

This commit is contained in:
Philipp Kühn
2020-11-21 00:00:57 +01:00
parent 540b0656f3
commit 8f6ae0e69e
7 changed files with 9 additions and 9 deletions

View File

@@ -110,11 +110,11 @@ Have a look at all of the core commands listed below. They should give you a goo
| .extendMarkRange() | Extends the text selection to the current mark. | | .extendMarkRange() | Extends the text selection to the current mark. |
| .resetNodeAttributes() | Resets all node attributes to the default value. | | .resetNodeAttributes() | Resets all node attributes to the default value. |
| .selectParentNode() | Select the parent node. | | .selectParentNode() | Select the parent node. |
| .setNode() | Replace a given range with a node. |
| .setMark() | Add a mark with new attributes. | | .setMark() | Add a mark with new attributes. |
| .setNode() | Replace a given range with a node. |
| .splitBlock() | Forks a new node from an existing node. | | .splitBlock() | Forks a new node from an existing node. |
| .toggleBlockType() | Toggle a node with another node. |
| .toggleMark() | Toggle a mark on and off. | | .toggleMark() | Toggle a mark on and off. |
| .toggleNode() | Toggle a node with another node. |
| .toggleWrap() | Wraps nodes in another node, or removes an existing wrap. | | .toggleWrap() | Wraps nodes in another node, or removes an existing wrap. |
| .unsetMark() | Remove a mark in the current selection. | | .unsetMark() | Remove a mark in the current selection. |
| .unsetMarks() | Remove all marks in the current selection. | | .unsetMarks() | Remove all marks in the current selection. |

View File

@@ -275,7 +275,7 @@ const CustomParagraph = Paragraph.extend({
addCommands() { addCommands() {
return { return {
paragraph: () => ({ commands }) => { paragraph: () => ({ commands }) => {
return commands.toggleBlockType('paragraph', 'paragraph') return commands.toggleNode('paragraph', 'paragraph')
}, },
} }
}, },

View File

@@ -6,7 +6,7 @@ import getNodeType from '../utils/getNodeType'
/** /**
* Toggle a node with another node. * Toggle a node with another node.
*/ */
export const toggleBlockType = (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attrs = {}): Command => ({ state, commands }) => { export const toggleNode = (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attrs = {}): Command => ({ state, commands }) => {
const type = getNodeType(typeOrName, state.schema) const type = getNodeType(typeOrName, state.schema)
const toggleType = getNodeType(toggleTypeOrName, state.schema) const toggleType = getNodeType(toggleTypeOrName, state.schema)
const isActive = nodeIsActive(state, type, attrs) const isActive = nodeIsActive(state, type, attrs)

View File

@@ -21,9 +21,9 @@ import * as setNode from '../commands/setNode'
import * as sinkListItem from '../commands/sinkListItem' import * as sinkListItem from '../commands/sinkListItem'
import * as splitBlock from '../commands/splitBlock' import * as splitBlock from '../commands/splitBlock'
import * as splitListItem from '../commands/splitListItem' import * as splitListItem from '../commands/splitListItem'
import * as toggleBlockType from '../commands/toggleBlockType'
import * as toggleList from '../commands/toggleList' import * as toggleList from '../commands/toggleList'
import * as toggleMark from '../commands/toggleMark' import * as toggleMark from '../commands/toggleMark'
import * as toggleNode from '../commands/toggleNode'
import * as toggleWrap from '../commands/toggleWrap' import * as toggleWrap from '../commands/toggleWrap'
import * as unsetMark from '../commands/unsetMark' import * as unsetMark from '../commands/unsetMark'
import * as unsetMarks from '../commands/unsetMarks' import * as unsetMarks from '../commands/unsetMarks'
@@ -56,9 +56,9 @@ export const Commands = Extension.create({
...sinkListItem, ...sinkListItem,
...splitBlock, ...splitBlock,
...splitListItem, ...splitListItem,
...toggleBlockType,
...toggleList, ...toggleList,
...toggleMark, ...toggleMark,
...toggleNode,
...toggleWrap, ...toggleWrap,
...unsetMark, ...unsetMark,
...unsetMarks, ...unsetMarks,

View File

@@ -84,7 +84,7 @@ const CodeBlock = Node.create({
* Toggle a code block * Toggle a code block
*/ */
toggleCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => { toggleCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => {
return commands.toggleBlockType('codeBlock', 'paragraph', attributes) return commands.toggleNode('codeBlock', 'paragraph', attributes)
}, },
} }
}, },

View File

@@ -70,7 +70,7 @@ const Heading = Node.create({
return false return false
} }
return commands.toggleBlockType('heading', 'paragraph', attributes) return commands.toggleNode('heading', 'paragraph', attributes)
}, },
} }
}, },

View File

@@ -33,7 +33,7 @@ const Paragraph = Node.create({
* Toggle a paragraph * Toggle a paragraph
*/ */
setParagraph: (): Command => ({ commands }) => { setParagraph: (): Command => ({ commands }) => {
return commands.toggleBlockType('paragraph', 'paragraph') return commands.toggleNode('paragraph', 'paragraph')
}, },
} }
}, },