rename setBlockType to setNode
This commit is contained in:
@@ -110,7 +110,7 @@ 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. |
|
||||||
| .setBlockType() | Replace a given range with a node. |
|
| .setNode() | Replace a given range with a node. |
|
||||||
| .setMark() | Add a mark with new attributes. |
|
| .setMark() | Add a mark with new attributes. |
|
||||||
| .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. |
|
| .toggleBlockType() | Toggle a node with another node. |
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import { NodeType } from 'prosemirror-model'
|
|
||||||
import { setBlockType as originalSetBlockType } from 'prosemirror-commands'
|
|
||||||
import { Command } from '../types'
|
|
||||||
import getNodeType from '../utils/getNodeType'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace a given range with a node.
|
|
||||||
*/
|
|
||||||
export const setBlockType = (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => {
|
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
|
||||||
|
|
||||||
return originalSetBlockType(type, attrs)(state, dispatch)
|
|
||||||
}
|
|
||||||
13
packages/core/src/commands/setNode.ts
Normal file
13
packages/core/src/commands/setNode.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { NodeType } from 'prosemirror-model'
|
||||||
|
import { setBlockType } from 'prosemirror-commands'
|
||||||
|
import { Command } from '../types'
|
||||||
|
import getNodeType from '../utils/getNodeType'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace a given range with a node.
|
||||||
|
*/
|
||||||
|
export const setNode = (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => {
|
||||||
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
|
|
||||||
|
return setBlockType(type, attrs)(state, dispatch)
|
||||||
|
}
|
||||||
@@ -12,8 +12,8 @@ export const toggleBlockType = (typeOrName: string | NodeType, toggleTypeOrName:
|
|||||||
const isActive = nodeIsActive(state, type, attrs)
|
const isActive = nodeIsActive(state, type, attrs)
|
||||||
|
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
return commands.setBlockType(toggleType)
|
return commands.setNode(toggleType)
|
||||||
}
|
}
|
||||||
|
|
||||||
return commands.setBlockType(type, attrs)
|
return commands.setNode(type, attrs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import * as resetNodeAttributes from '../commands/resetNodeAttributes'
|
|||||||
import * as scrollIntoView from '../commands/scrollIntoView'
|
import * as scrollIntoView from '../commands/scrollIntoView'
|
||||||
import * as selectAll from '../commands/selectAll'
|
import * as selectAll from '../commands/selectAll'
|
||||||
import * as selectParentNode from '../commands/selectParentNode'
|
import * as selectParentNode from '../commands/selectParentNode'
|
||||||
import * as setBlockType from '../commands/setBlockType'
|
|
||||||
import * as setContent from '../commands/setContent'
|
import * as setContent from '../commands/setContent'
|
||||||
import * as setMark from '../commands/setMark'
|
import * as setMark from '../commands/setMark'
|
||||||
|
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'
|
||||||
@@ -50,9 +50,9 @@ export const Commands = Extension.create({
|
|||||||
...scrollIntoView,
|
...scrollIntoView,
|
||||||
...selectAll,
|
...selectAll,
|
||||||
...selectParentNode,
|
...selectParentNode,
|
||||||
...setBlockType,
|
|
||||||
...setContent,
|
...setContent,
|
||||||
...setMark,
|
...setMark,
|
||||||
|
...setNode,
|
||||||
...sinkListItem,
|
...sinkListItem,
|
||||||
...splitBlock,
|
...splitBlock,
|
||||||
...splitListItem,
|
...splitListItem,
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ const CodeBlock = Node.create({
|
|||||||
* Set a code block
|
* Set a code block
|
||||||
*/
|
*/
|
||||||
setCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => {
|
setCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => {
|
||||||
return commands.setBlockType('codeBlock', attributes)
|
return commands.setNode('codeBlock', attributes)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Toggle a code block
|
* Toggle a code block
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const Heading = Node.create({
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return commands.setBlockType('heading', attributes)
|
return commands.setNode('heading', attributes)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Toggle a heading node
|
* Toggle a heading node
|
||||||
|
|||||||
Reference in New Issue
Block a user