tiptap/packages/core/src/utils/getNodeAttrs.ts

22 lines
468 B
TypeScript
Raw Normal View History

2020-04-11 17:45:41 +08:00
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]
})
2020-04-11 19:05:28 +08:00
const node = nodes
.reverse()
.find(nodeItem => nodeItem.type.name === type.name)
2020-04-11 17:45:41 +08:00
if (node) {
return node.attrs
}
return {}
}