mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-25 04:19:02 +08:00
refactoring
This commit is contained in:
parent
0f9c705ee0
commit
228ef24424
@ -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
|
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user