refactoring
This commit is contained in:
22
packages/core/src/helpers/findChildren.ts
Normal file
22
packages/core/src/helpers/findChildren.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user