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
|
||||
}
|
||||
@@ -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 {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user