tiptap/packages/core/src/utils/getNodeAttrs.ts
Philipp Kühn 1e7231286d fix bug
2020-04-11 14:17:31 +02:00

22 lines
475 B
TypeScript

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
.reverse()
.find(nodeItem => nodeItem.type.name === type.name)
if (node) {
return { ...node.attrs }
}
return {}
}