refactoring

This commit is contained in:
Hans Pagel 2020-10-28 11:52:10 +01:00
parent 0f9c705ee0
commit 228ef24424
2 changed files with 8 additions and 10 deletions

View File

@ -1,15 +1,13 @@
import { EditorState } from 'prosemirror-state' import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model' import { MarkType } from 'prosemirror-model'
import getMarkAttrs from './getMarkAttrs' import getMarkAttrs from './getMarkAttrs'
import { AnyObject } from '../types'
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: { [key: string]: any }): boolean { export default function markHasAttributes(state: EditorState, type: MarkType, attrs: AnyObject) {
if (attrs === undefined || Object.keys(attrs).length === 0) { const originalAttrs = getMarkAttrs(state, type)
return true
} return !!Object
.keys(attrs)
const originalAttrs: { [key: string]: any } = getMarkAttrs(state, type) .filter(key => attrs[key] === originalAttrs[key])
.length
return Object.keys(attrs).filter((key: string) => {
return attrs[key] === originalAttrs[key]
}).length > 0
} }

View File

@ -2,7 +2,7 @@ import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model' import { MarkType } from 'prosemirror-model'
import markHasAttributes from './markHasAttributes' import markHasAttributes from './markHasAttributes'
export default function markIsActive(state: EditorState, type: MarkType, attrs?: {}) { export default function markIsActive(state: EditorState, type: MarkType, attrs = {}) {
const { const {
from, from,
$from, $from,