add heading command

This commit is contained in:
Philipp Kühn
2020-04-21 22:36:31 +02:00
parent a057755e42
commit 6b5b30f3fc
4 changed files with 45 additions and 8 deletions

View File

@@ -0,0 +1,30 @@
import { NodeType } from 'prosemirror-model'
import { setBlockType } from 'prosemirror-commands'
import { Editor } from '../Editor'
import nodeIsActive from '../utils/nodeIsActive'
declare module '../Editor' {
interface Editor {
toggleBlockType(type: NodeType, toggleType: NodeType, attrs?: {}): Editor,
}
}
export default function toggleBlockType(
next: Function,
editor: Editor,
type: NodeType,
toggleType: NodeType,
attrs?: {},
): void {
const { view, state } = editor
const isActive = nodeIsActive(state, type, attrs)
if (isActive) {
setBlockType(toggleType)(view.state, view.dispatch)
next()
return
}
setBlockType(type, attrs)(view.state, view.dispatch)
next()
}