mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-22 08:07:50 +08:00
e97630c639
* Require .js endings * add extension alias for cypress to resolve ts files with js endings
26 lines
599 B
TypeScript
26 lines
599 B
TypeScript
import { Node, NodeType } from '@tiptap/pm/model'
|
|
import { EditorState } from '@tiptap/pm/state'
|
|
|
|
import { getNodeType } from './getNodeType.js'
|
|
|
|
export function getNodeAttributes(
|
|
state: EditorState,
|
|
typeOrName: string | NodeType,
|
|
): Record<string, any> {
|
|
const type = getNodeType(typeOrName, state.schema)
|
|
const { from, to } = state.selection
|
|
const nodes: Node[] = []
|
|
|
|
state.doc.nodesBetween(from, to, node => {
|
|
nodes.push(node)
|
|
})
|
|
|
|
const node = nodes.reverse().find(nodeItem => nodeItem.type.name === type.name)
|
|
|
|
if (!node) {
|
|
return {}
|
|
}
|
|
|
|
return { ...node.attrs }
|
|
}
|