split helpers and utilities
This commit is contained in:
23
packages/core/src/helpers/getNodeAttributes.ts
Normal file
23
packages/core/src/helpers/getNodeAttributes.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
import { Node, NodeType } from 'prosemirror-model'
|
||||
import getNodeType from './getNodeType'
|
||||
|
||||
export default function getNodeAttributes(state: EditorState, typeOrName: string | NodeType) {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
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 {}
|
||||
}
|
||||
Reference in New Issue
Block a user