tiptap/packages/core/src/commands/lift.ts

17 lines
509 B
TypeScript
Raw Normal View History

2020-11-18 18:54:18 +08:00
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)
}