mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 08:47:50 +08:00
20 lines
448 B
TypeScript
20 lines
448 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.find(nodeItem => nodeItem.type.name === type.name)
|
|
|
|
if (node) {
|
|
return node.attrs
|
|
}
|
|
|
|
return {}
|
|
}
|