mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-23 01:43:10 +08:00
d70e8a70b6
* refactor(core): add jsdocs to utilitiy functions * refactor(core): add jsdocs to more utility functions
17 lines
638 B
TypeScript
17 lines
638 B
TypeScript
import { Selection } from '@tiptap/pm/state'
|
|
|
|
import { Predicate } from '../types.js'
|
|
import { findParentNodeClosestToPos } from './findParentNodeClosestToPos.js'
|
|
|
|
/**
|
|
* Finds the closest parent node to the current selection that matches a predicate.
|
|
* @param predicate The predicate to match
|
|
* @returns A command that finds the closest parent node to the current selection that matches the predicate
|
|
* @example ```js
|
|
* findParentNode(node => node.type.name === 'paragraph')
|
|
* ```
|
|
*/
|
|
export function findParentNode(predicate: Predicate) {
|
|
return (selection: Selection) => findParentNodeClosestToPos(selection.$from, predicate)
|
|
}
|