this repo has no description
at main 34 lines 770 B view raw
1import { Node } from '@tiptap/pm/model'; 2 3export type NodeStackEntry = { 4 node: Node; 5 depth: number; 6 start: number; 7 end: number; 8}; 9 10/** 11 * Returns the stack of nodes at the given position. 12 * @param doc - The document node. 13 * @param pos - The position to get the node stack for. 14 * @returns An array of NodeStackEntry objects representing the node stack. 15 */ 16export function getNodeStack(doc: Node, pos: number): NodeStackEntry[] { 17 const $pos = doc.resolve(pos); 18 const stack: NodeStackEntry[] = []; 19 20 for (let depth = 0; depth <= $pos.depth; depth++) { 21 const node = $pos.node(depth); 22 const start = $pos.start(depth); 23 const end = $pos.end(depth); 24 25 stack.push({ 26 node, 27 depth, 28 start, 29 end, 30 }); 31 } 32 33 return stack; 34}