Files
tiptap/packages/core/src/commands/lift.ts
2021-02-16 18:36:37 +01:00

28 lines
777 B
TypeScript

import { lift as originalLift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands, AnyObject } from '../types'
import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface AllCommands {
lift: {
/**
* Removes an existing wrap.
*/
lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const lift: RawCommands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
const isActive = isNodeActive(state, type, attributes)
if (!isActive) {
return false
}
return originalLift(state, dispatch)
}