refactoring

This commit is contained in:
Philipp Kühn
2021-04-02 23:53:04 +02:00
parent dd505d2773
commit 6757813fd0
3 changed files with 29 additions and 27 deletions

View 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
}

View File

@@ -12,6 +12,9 @@ export { default as markPasteRule } from './pasteRules/markPasteRule'
export { default as callOrReturn } from './utilities/callOrReturn'
export { default as mergeAttributes } from './utilities/mergeAttributes'
export { default as findChildren } from './helpers/findChildren'
export { default as findParentNode } from './helpers/findParentNode'
export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos'
export { default as generateHTML } from './helpers/generateHTML'
export { default as getSchema } from './helpers/getSchema'
export { default as getHTMLFromFragment } from './helpers/getHTMLFromFragment'
@@ -22,7 +25,6 @@ export { default as isNodeActive } from './helpers/isNodeActive'
export { default as isNodeEmpty } from './helpers/isNodeEmpty'
export { default as isNodeSelection } from './helpers/isNodeSelection'
export { default as isTextSelection } from './helpers/isTextSelection'
export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos'
export interface Commands {}