2020-03-30 06:15:20 +08:00
|
|
|
import { findParentNode, findSelectedNodeOfType } from 'prosemirror-utils'
|
|
|
|
import { EditorState } from 'prosemirror-state'
|
|
|
|
import { Node, NodeType } from 'prosemirror-model'
|
|
|
|
|
|
|
|
export default function nodeIsActive(state: EditorState, type: NodeType, attrs = {}) {
|
|
|
|
const predicate = (node: Node) => node.type === type
|
|
|
|
const node = findSelectedNodeOfType(type)(state.selection)
|
|
|
|
|| findParentNode(predicate)(state.selection)
|
|
|
|
|
|
|
|
if (!Object.keys(attrs).length || !node) {
|
|
|
|
return !!node
|
|
|
|
}
|
|
|
|
|
2020-04-23 01:01:39 +08:00
|
|
|
return node.node.hasMarkup(type, { ...node.node.attrs, ...attrs })
|
2020-03-30 06:15:20 +08:00
|
|
|
}
|