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'
|
2020-11-30 16:42:53 +08:00
|
|
|
import nodeIsActive from '../helpers/nodeIsActive'
|
|
|
|
import getNodeType from '../helpers/getNodeType'
|
2020-11-18 18:54:18 +08:00
|
|
|
|
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
|
|
|
}
|