tiptap/packages/core/src/utils/markHasAttributes.ts

20 lines
663 B
TypeScript
Raw Normal View History

2020-10-05 23:12:57 +08:00
import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import getMarkAttrs from './getMarkAttrs'
2020-10-12 23:58:30 +08:00
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: { [key: string]: any }): boolean {
// @ts-ignore
if (attrs === undefined || Object.keys(attrs).length === 0) {
2020-10-08 09:44:18 +08:00
return true
}
const originalAttrs: { [key: string]: any } = getMarkAttrs(state, type)
2020-10-12 23:58:30 +08:00
// @ts-ignore
2020-10-08 09:44:18 +08:00
return Object.keys(attrs).filter((key: string) => {
2020-10-12 23:58:30 +08:00
// @ts-ignore
console.log(attrs[key], originalAttrs[key], attrs[key] === originalAttrs[key])
2020-10-08 09:44:18 +08:00
return attrs[key] === originalAttrs[key]
}).length
2020-10-05 23:12:57 +08:00
}