import { Node as ProseMirrorNode } from 'prosemirror-model'; import { Editor } from '../../core/Editor.js'; import { BlockNodeAddress, BlockNodeType, NodeAddress, NodeType } from '@superdoc/document-api'; /** A block-level node found during document traversal, with its position and resolved identity. */ export type BlockCandidate = { node: ProseMirrorNode; pos: number; end: number; nodeType: BlockNodeType; nodeId: string; }; /** * Positional index of all block-level nodes in the document. * * Built by {@link buildBlockIndex}. The index is a snapshot — it must be * rebuilt after any document mutation. */ export type BlockIndex = { candidates: BlockCandidate[]; byId: Map; ambiguous: ReadonlySet; }; type TraversalPath = readonly number[]; /** * Returns `true` if `nodeType` is a block-level type supported by the adapter index. * * @param nodeType - A node type string (block, inline, or the literal `'text'`). * @returns Whether the type is a supported {@link BlockNodeType}. */ export declare function isSupportedNodeType(nodeType: NodeType | 'text'): nodeType is BlockNodeType; /** * Extracts the heading level (1–6) from an OOXML styleId string. * * @param styleId - A paragraph styleId (e.g. `"Heading1"`, `"heading 3"`). * @returns The heading level, or `undefined` if the styleId is not a heading. */ export declare function getHeadingLevel(styleId?: string | null): number | undefined; export declare function mapBlockNodeType(node: ProseMirrorNode): BlockNodeType | undefined; /** * Resolves the public document-api nodeId for a block-level ProseMirror node. * * ID resolution strategy varies by block family: * - **Paragraphs**: paraId → sdBlockId → deterministic fallback * - **Tables/cells**: legacy attrs → non-volatile sdBlockId → deterministic fallback * - **Other blocks**: blockId → id → paraId → uuid → sdBlockId * * @param node - The ProseMirror node. * @param pos - Absolute document position of the node. * @param nodeType - The mapped block node type. * @param path - Optional traversal path for deterministic fallback IDs. * @returns The resolved nodeId, or `undefined` if none could be determined. */ export declare function resolveBlockNodeId(node: ProseMirrorNode, pos: number, nodeType: BlockNodeType, path?: TraversalPath): string | undefined; /** * Converts a {@link BlockCandidate} into a stable {@link NodeAddress}. * * @param candidate - The block candidate to convert. * @returns A block-kind node address. */ export declare function toBlockAddress(candidate: BlockCandidate): BlockNodeAddress; /** * Walks the editor document and builds a positional index of all recognised * block-level nodes. * * The returned index is a **snapshot** tied to the current document state. * It must be rebuilt after any transaction that mutates the document. * * @param editor - The editor whose document will be indexed. * @returns A {@link BlockIndex} containing ordered candidates and a lookup map. */ export declare function buildBlockIndex(editor: Editor): BlockIndex; /** * Looks up a block candidate by its {@link NodeAddress}. * * @param index - The block index to search. * @param address - The address to resolve. Non-block addresses return `undefined`. * @returns The matching candidate, or `undefined` if not found. */ export declare function findBlockById(index: BlockIndex, address: NodeAddress): BlockCandidate | undefined; /** * Looks up a block candidate by its {@link BlockNodeAddress}, throwing * a precise error for missing or ambiguous targets. * * @param index - The block index to search. * @param address - The block node address to resolve. * @returns The matching candidate. * @throws {DocumentApiAdapterError} `TARGET_NOT_FOUND` if no candidate matches. * @throws {DocumentApiAdapterError} `AMBIGUOUS_TARGET` if multiple candidates share the key. */ export declare function findBlockByIdStrict(index: BlockIndex, address: BlockNodeAddress): BlockCandidate; /** * Resolves a nodeId against alias entries in the block index (e.g., sdBlockId * registered as an alias for a deterministic primary ID). * * @param index - The block index to search. * @param nodeId - The node ID to resolve via alias lookup. * @returns The single matching candidate, or `undefined` if no alias matches. * @throws {DocumentApiAdapterError} `AMBIGUOUS_TARGET` when multiple blocks share the alias. */ export declare function resolveBlockAlias(index: BlockIndex, nodeId: string): BlockCandidate | undefined; /** * Finds a block candidate by raw nodeId without requiring a nodeType. * * Falls back to alias resolution when no primary match exists. * * @param index - The block index to search. * @param nodeId - The node ID to resolve. * @returns The single matching candidate. * @throws {DocumentApiAdapterError} `TARGET_NOT_FOUND` if no candidate matches. * @throws {DocumentApiAdapterError} `AMBIGUOUS_TARGET` if more than one candidate matches. */ export declare function findBlockByNodeIdOnly(index: BlockIndex, nodeId: string): BlockCandidate; /** * Returns true for block candidates that accept inline text content. */ export declare function isTextBlockCandidate(candidate: BlockCandidate): boolean; /** * Finds a block candidate whose range contains the given position. * * Note: nested blocks (e.g. table > row > cell > paragraph) produce overlapping * candidates. This returns whichever the binary search lands on first, not * necessarily the innermost. This is sufficient for resolving a containing block * for match context but callers needing the most specific block should filter further. */ export declare function findBlockByPos(index: BlockIndex, pos: number): BlockCandidate | undefined; export {}; //# sourceMappingURL=node-address-resolver.d.ts.map