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

20 lines
575 B
TypeScript
Raw Normal View History

2020-11-18 23:43:27 +08:00
import { lift as originalLift } from 'prosemirror-commands'
2020-11-18 18:54:18 +08:00
import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import nodeIsActive from '../utils/nodeIsActive'
import getNodeType from '../utils/getNodeType'
2020-11-18 23:43:27 +08:00
/**
* Removes an existing wrap.
*/
export const lift = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => {
2020-11-18 18:54:18 +08:00
const type = getNodeType(typeOrName, state.schema)
const isActive = nodeIsActive(state, type, attributes)
if (!isActive) {
return false
}
2020-11-18 23:43:27 +08:00
return originalLift(state, dispatch)
2020-11-18 18:54:18 +08:00
}