mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 08:47:50 +08:00
24 lines
651 B
TypeScript
24 lines
651 B
TypeScript
|
import { toggleMark as originalToggleMark } from 'prosemirror-commands'
|
||
|
import { MarkType } from 'prosemirror-model'
|
||
|
import { Command } from '../Editor'
|
||
|
import { createExtension } from '../Extension'
|
||
|
import getMarkType from '../utils/getMarkType'
|
||
|
|
||
|
export const ToggleMark = createExtension({
|
||
|
addCommands() {
|
||
|
return {
|
||
|
toggleMark: (typeOrName: string | MarkType): Command => ({ state, dispatch }) => {
|
||
|
const type = getMarkType(typeOrName, state.schema)
|
||
|
|
||
|
return originalToggleMark(type)(state, dispatch)
|
||
|
},
|
||
|
}
|
||
|
},
|
||
|
})
|
||
|
|
||
|
declare module '../Editor' {
|
||
|
interface AllExtensions {
|
||
|
ToggleMark: typeof ToggleMark,
|
||
|
}
|
||
|
}
|