Files
tiptap/packages/core/src/helpers/findChildren.ts
2021-05-17 11:29:41 +02:00

18 lines
422 B
TypeScript

import { Node as ProseMirrorNode } from 'prosemirror-model'
import { Predicate, NodeWithPos } from '../types'
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
}