mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-01 06:37:51 +08:00
17 lines
509 B
TypeScript
17 lines
509 B
TypeScript
|
import { lift } from 'prosemirror-commands'
|
||
|
import { NodeType } from 'prosemirror-model'
|
||
|
import { Command } from '../types'
|
||
|
import nodeIsActive from '../utils/nodeIsActive'
|
||
|
import getNodeType from '../utils/getNodeType'
|
||
|
|
||
|
export default (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
|
||
|
const type = getNodeType(typeOrName, state.schema)
|
||
|
const isActive = nodeIsActive(state, type, attributes)
|
||
|
|
||
|
if (!isActive) {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return lift(state, dispatch)
|
||
|
}
|