2020-10-05 23:12:57 +08:00
|
|
|
import { EditorState } from 'prosemirror-state'
|
|
|
|
import { MarkType } from 'prosemirror-model'
|
|
|
|
import getMarkAttrs from './getMarkAttrs'
|
2020-10-28 18:52:10 +08:00
|
|
|
import { AnyObject } from '../types'
|
2020-11-06 07:13:18 +08:00
|
|
|
import isEmptyObject from './isEmptyObject'
|
|
|
|
|
|
|
|
export default function markHasAttributes(state: EditorState, type: MarkType, attributes: AnyObject) {
|
|
|
|
if (isEmptyObject(attributes)) {
|
|
|
|
return true
|
|
|
|
}
|
2020-10-05 23:12:57 +08:00
|
|
|
|
2020-10-28 18:52:10 +08:00
|
|
|
const originalAttrs = getMarkAttrs(state, type)
|
2020-10-08 09:44:18 +08:00
|
|
|
|
2020-10-28 18:52:10 +08:00
|
|
|
return !!Object
|
2020-11-06 07:13:18 +08:00
|
|
|
.keys(attributes)
|
|
|
|
.filter(key => attributes[key] === originalAttrs[key])
|
2020-10-28 18:52:10 +08:00
|
|
|
.length
|
2020-10-05 23:12:57 +08:00
|
|
|
}
|