rename toggleNode to toggleBlockType

This commit is contained in:
Philipp Kühn
2020-09-24 22:27:17 +02:00
parent 2d0c5eb737
commit 570e67b085
8 changed files with 10 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ editor.chain().focus().bold().run()
| .replaceWithNode() | Replace a given range with a node. | | .replaceWithNode() | Replace a given range with a node. |
| .selectParentNode() | Select the parent node. | | .selectParentNode() | Select the parent node. |
| .toggleMark() | Toggle a mark on and off. | | .toggleMark() | Toggle a mark on and off. |
| .toggleNode() | Toggle a node with another node. | | .toggleBlockType() | Toggle a node with another node. |
| .updateMark() | Update a mark with new attributes. | | .updateMark() | Update a mark with new attributes. |
### Selection ### Selection

View File

@@ -47,7 +47,7 @@ import Paragraph from '@tiptap/extension-paragraph'
const CustomParagraph = Paragraph() const CustomParagraph = Paragraph()
.commands(() => ({ .commands(() => ({
paragraph: () => ({ commands }) => { paragraph: () => ({ commands }) => {
return commands.toggleNode(name, 'paragraph') return commands.toggleBlockType(name, 'paragraph')
}, },
})) }))
.create() .create()

View File

@@ -14,7 +14,7 @@ export { selectParentNode } from './selectParentNode'
export { setContent } from './setContent' export { setContent } from './setContent'
export { sinkListItem } from './sinkListItem' export { sinkListItem } from './sinkListItem'
export { splitListItem } from './splitListItem' export { splitListItem } from './splitListItem'
export { toggleBlockType } from './toggleBlockType'
export { toggleList } from './toggleList' export { toggleList } from './toggleList'
export { toggleMark } from './toggleMark' export { toggleMark } from './toggleMark'
export { toggleNode } from './toggleNode'
export { updateMark } from './updateMark' export { updateMark } from './updateMark'

View File

@@ -4,7 +4,7 @@ import { Command } from '../Editor'
import nodeIsActive from '../utils/nodeIsActive' import nodeIsActive from '../utils/nodeIsActive'
import getNodeType from '../utils/getNodeType' import getNodeType from '../utils/getNodeType'
type ToggleNodeCommand = ( type ToggleBlockTypeCommand = (
typeOrName: string | NodeType, typeOrName: string | NodeType,
toggleType: string | NodeType, toggleType: string | NodeType,
attrs?: {} attrs?: {}
@@ -12,11 +12,11 @@ type ToggleNodeCommand = (
declare module '../Editor' { declare module '../Editor' {
interface Commands { interface Commands {
toggleNode: ToggleNodeCommand, toggleBlockType: ToggleBlockTypeCommand,
} }
} }
export const toggleNode: ToggleNodeCommand = (typeOrName, toggleTypeOrName, attrs = {}) => ({ state, dispatch }) => { export const toggleBlockType: ToggleBlockTypeCommand = (typeOrName, toggleTypeOrName, attrs = {}) => ({ state, dispatch }) => {
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

@@ -25,7 +25,7 @@ export default new Node()
})) }))
.commands(({ name }) => ({ .commands(({ name }) => ({
[name]: attrs => ({ commands }) => { [name]: attrs => ({ commands }) => {
return commands.toggleNode(name, 'paragraph', attrs) return commands.toggleBlockType(name, 'paragraph', attrs)
}, },
})) }))
.keys(({ editor }) => ({ .keys(({ editor }) => ({

View File

@@ -25,7 +25,7 @@ export default new Node()
})) }))
.commands(({ name }) => ({ .commands(({ name }) => ({
codeBlock: attrs => ({ commands }) => { codeBlock: attrs => ({ commands }) => {
return commands.toggleNode(name, 'paragraph', attrs) return commands.toggleBlockType(name, 'paragraph', attrs)
}, },
})) }))
.keys(({ editor }) => ({ .keys(({ editor }) => ({

View File

@@ -39,7 +39,7 @@ export default new Node<HeadingOptions>()
})) }))
.commands(({ name }) => ({ .commands(({ name }) => ({
[name]: attrs => ({ commands }) => { [name]: attrs => ({ commands }) => {
return commands.toggleNode(name, 'paragraph', attrs) return commands.toggleBlockType(name, 'paragraph', attrs)
}, },
})) }))
// TODO: Keyboard Shortcuts // TODO: Keyboard Shortcuts

View File

@@ -20,7 +20,7 @@ export default new Node()
})) }))
.commands(({ name }) => ({ .commands(({ name }) => ({
[name]: () => ({ commands }) => { [name]: () => ({ commands }) => {
return commands.toggleNode(name, 'paragraph') return commands.toggleBlockType(name, 'paragraph')
}, },
})) }))
.keys(({ editor }) => ({ .keys(({ editor }) => ({