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

19 lines
415 B
TypeScript
Raw Normal View History

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