import type { Editor } from '@tiptap/react'; import { Extension } from '@tiptap/core'; /** * Comments on a selection, drawn where they are, from Katerina's Leaf prototype * (9 October), with a run, whole blocks and changed words added for LEAF-7. * * A comment's place is the one SPEC §13.6 gives it: a run of blocks, and the * words where the selection starts and where it ends as a quote. Words inside * one block are quoted whole; a selection across blocks quotes its start in * the first block and its end in the last; a selection of whole blocks quotes * nothing and is about the blocks. Nothing is written into the document: the * highlight is a decoration, so a save never carries it. * * Three places a comment can be in, as `@estiva-app/protocol`'s * `resolveCommentAnchor` reads them: * - **resolved** — its words are found (drawn on them), or it quotes none * (drawn on its whole blocks); * - **reworded** — its blocks are there and its words are not: nothing is * drawn, and the comment stands beside its first block; * - **detached** — none of its blocks is left. * * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-comment-remembers-where-its-selection-starts-and-ends.md */ /** The words a comment quotes: §13.6's `quote` tag. */ export interface CommentQuote { /** The selection's words in one block, or its first words when it runs across blocks. */ start: string; /** Its last words, in the run's last block. Absent: `start` is the whole selection. */ end?: string; /** A few characters before `start`, only when the words repeat in their block. */ prefix?: string; /** A few characters after the end, only when the words repeat in their block. */ suffix?: string; } /** One comment's place: the blocks it is anchored to and the words it is about. */ export interface CommentAnchor { /** The thread's id. Clicks report it; `active` names it. */ id: string; /** The run: the §13.3 block ids the comment's `block` tag lists, in order. */ blocks: readonly string[]; /** The words, as they were when the comment was written. Absent: the whole blocks. */ quote?: CommentQuote; } /** Where a comment is now, in document positions. */ export type CommentPlace = /** Drawn: on its words (`words`), or on its whole blocks. */ { state: 'resolved'; from: number; to: number; words: boolean; } /** Its blocks (`from`–`to`) are there, its words are not. Draw nothing; show the quote as the commenter's. */ | { state: 'reworded'; from: number; to: number; } /** None of its blocks is left. */ | { state: 'detached'; }; declare module '@tiptap/core' { interface EditorEvents { /** A comment's highlight was clicked: `editor.on('commentSelect', ({ id }) => …)`. */ commentSelect: { id: string; }; } } export interface CommentHighlightsOptions { /** A highlight was clicked: the thread to show. Or listen for the editor's `commentSelect`. */ onSelect: ((id: string) => void) | null; } /** The extension an editor registers to draw comments where they are. */ export declare const CommentHighlights: Extension; /** Draw these comments, `active` the one being read. */ export declare function setCommentAnchors(editor: Editor, anchors: readonly CommentAnchor[], active?: string | null): void; /** Where a comment is now: on its words or blocks, beside its blocks with its words gone, or detached. */ export declare function commentPlace(editor: Editor, anchor: CommentAnchor): CommentPlace; /** * What a comment's card stands beside: its drawn highlight, or — its words * gone — its first block. Null when it is detached. */ export declare function commentElement(editor: Editor, anchor: CommentAnchor): HTMLElement | null; /** A quote in one line, as a card says it: its start and end words around an ellipsis. */ export declare function quoteText(quote: CommentQuote): string; /** What a comment on the selection would carry: its run, and its words unless it covers whole blocks. */ export interface SelectionAnchor { blocks: string[]; quote?: CommentQuote; } /** * The anchor a comment on the selection carries, as §13.6 writes it: the * selected blocks, and the selected words in one block or the words where it * starts and ends across several. No quote when whole blocks are selected. * Null when nothing is selected or a selected block has no id. */ export declare function anchorOfSelection(editor: Editor): SelectionAnchor | null; //# sourceMappingURL=CommentHighlights.d.ts.map