add getNodeAttrs

This commit is contained in:
Philipp Kühn
2020-04-11 11:45:41 +02:00
parent bb742c1db2
commit 303f6b55fe
2 changed files with 24 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { EditorState } from 'prosemirror-state'
import { Node, NodeType } from 'prosemirror-model'
export default function getNodeAttrs(state: EditorState, type: NodeType) {
const { from, to } = state.selection
let nodes: Node[] = []
state.doc.nodesBetween(from, to, node => {
nodes = [...nodes, node]
})
const node = nodes.find(nodeItem => nodeItem.type.name === type.name)
if (node) {
return node.attrs
}
return {}
}