add Commands interface

This commit is contained in:
Philipp Kühn
2021-02-10 09:59:35 +01:00
parent 0ed368e9f4
commit 290ff76e37
100 changed files with 695 additions and 487 deletions

View File

@@ -1,12 +1,12 @@
import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import { AnyObject, Command, Commands } from '../types'
import getMarkType from '../helpers/getMarkType'
import isMarkActive from '../helpers/isMarkActive'
/**
* Toggle a mark on and off.
*/
export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, commands }) => {
export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
const type = getMarkType(typeOrName, state.schema)
const isActive = isMarkActive(state, type, attributes)
@@ -16,3 +16,9 @@ export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Comm
return commands.setMark(type, attributes)
}
declare module '@tiptap/core' {
interface Commands {
toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
}
}