tiptap/packages/core/src/utils/markHasAttributes.ts
2020-11-06 00:13:18 +01:00

19 lines
540 B
TypeScript

import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import getMarkAttrs from './getMarkAttrs'
import { AnyObject } from '../types'
import isEmptyObject from './isEmptyObject'
export default function markHasAttributes(state: EditorState, type: MarkType, attributes: AnyObject) {
if (isEmptyObject(attributes)) {
return true
}
const originalAttrs = getMarkAttrs(state, type)
return !!Object
.keys(attributes)
.filter(key => attributes[key] === originalAttrs[key])
.length
}