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'
|
2021-04-21 15:43:31 +08:00
|
|
|
import { Command, RawCommands } from '../types'
|
2020-12-01 16:11:58 +08:00
|
|
|
import isNodeActive from '../helpers/isNodeActive'
|
2020-11-30 16:42:53 +08:00
|
|
|
import getNodeType from '../helpers/getNodeType'
|
2020-11-18 18:54:18 +08:00
|
|
|
|
2021-02-11 01:05:02 +08:00
|
|
|
declare module '@tiptap/core' {
|
2021-02-17 01:39:37 +08:00
|
|
|
interface Commands {
|
2021-02-16 18:27:58 +08:00
|
|
|
lift: {
|
|
|
|
/**
|
|
|
|
* Removes an existing wrap.
|
|
|
|
*/
|
2021-04-21 15:43:31 +08:00
|
|
|
lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
|
2021-02-16 18:27:58 +08:00
|
|
|
}
|
2021-02-11 01:05:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-17 01:36:37 +08:00
|
|
|
export const lift: RawCommands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
2020-11-18 18:54:18 +08:00
|
|
|
const type = getNodeType(typeOrName, state.schema)
|
2020-12-01 16:11:58 +08:00
|
|
|
const isActive = isNodeActive(state, type, attributes)
|
2020-11-18 18:54:18 +08:00
|
|
|
|
|
|
|
if (!isActive) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-11-18 23:43:27 +08:00
|
|
|
return originalLift(state, dispatch)
|
2020-11-18 18:54:18 +08:00
|
|
|
}
|