mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-11 06:44:30 +08:00
16 lines
541 B
TypeScript
16 lines
541 B
TypeScript
|
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
|
||
|
}
|
||
|
|
||
|
return node.node.hasMarkup(type, attrs)
|
||
|
}
|