mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-08 12:27:59 +08:00
23 lines
473 B
TypeScript
23 lines
473 B
TypeScript
|
import { Node as ProseMirrorNode } from 'prosemirror-model'
|
||
|
import { Predicate } from '../types'
|
||
|
|
||
|
type NodeWithPos = {
|
||
|
node: ProseMirrorNode,
|
||
|
pos: number,
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|