rename setBlockType to setNode

This commit is contained in:
Philipp Kühn
2020-11-20 23:56:41 +01:00
parent c433428fba
commit 540b0656f3
7 changed files with 20 additions and 20 deletions

View File

@@ -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)
}

View 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)
}

View File

@@ -12,8 +12,8 @@ export const toggleBlockType = (typeOrName: string | NodeType, toggleTypeOrName:
const isActive = nodeIsActive(state, type, attrs)
if (isActive) {
return commands.setBlockType(toggleType)
return commands.setNode(toggleType)
}
return commands.setBlockType(type, attrs)
return commands.setNode(type, attrs)
}

View File

@@ -15,9 +15,9 @@ import * as resetNodeAttributes from '../commands/resetNodeAttributes'
import * as scrollIntoView from '../commands/scrollIntoView'
import * as selectAll from '../commands/selectAll'
import * as selectParentNode from '../commands/selectParentNode'
import * as setBlockType from '../commands/setBlockType'
import * as setContent from '../commands/setContent'
import * as setMark from '../commands/setMark'
import * as setNode from '../commands/setNode'
import * as sinkListItem from '../commands/sinkListItem'
import * as splitBlock from '../commands/splitBlock'
import * as splitListItem from '../commands/splitListItem'
@@ -50,9 +50,9 @@ export const Commands = Extension.create({
...scrollIntoView,
...selectAll,
...selectParentNode,
...setBlockType,
...setContent,
...setMark,
...setNode,
...sinkListItem,
...splitBlock,
...splitListItem,