tiptap/packages/core/src/helpers/findChildren.ts

18 lines
422 B
TypeScript
Raw Normal View History

2021-04-03 05:53:04 +08:00
import { Node as ProseMirrorNode } from 'prosemirror-model'
2021-05-17 17:29:41 +08:00
import { Predicate, NodeWithPos } from '../types'
2021-04-03 05:53:04 +08:00
export default function findChildren(node: ProseMirrorNode, predicate: Predicate): NodeWithPos[] {
const nodesWithPos: NodeWithPos[] = []
node.descendants((child, pos) => {
if (predicate(child)) {
nodesWithPos.push({
node: child,
pos,
})
}
})
return nodesWithPos
}