/** * Public and internal types for suggestion mode. */ /** What a suggestion proposes. */ export type SuggestionKind = 'insertion' | 'deletion' | 'replacement' | 'format-add' | 'format-remove'; /** A tracked formatting change (bold, italic, …). */ export interface FormatOp { markName: string; attrs: Record; op: 'add' | 'remove'; } /** Attributes of the wrapper mark. */ export interface SuggestionMarkAttrs { /** Cluster id while the edit is pending (`pending:`); kept after commit. */ pendingId: string; /** Velt target id once committed (`velt-tiptap:`); null while pending. */ targetId: string | null; formatOp: FormatOp | null; userId: string | null; color: string; timestamp: number; } /** The author of new suggestions (resolved from the signed-in Velt user). */ export interface SuggestionAuthor { userId: string; color: string; } /** Passed to the `summary` option to build the text of a suggestion's first comment. */ export interface SuggestionSummaryInput { kind: SuggestionKind; /** Text the suggestion removes (deletion / replacement) or the formatted text (format changes). */ oldText: string; /** Text the suggestion adds (insertion / replacement). Empty for format changes. */ newText: string; /** The format mark, for format changes. */ markName?: string; } /** Why a commit to Velt did not happen. */ export interface SuggestionErrorContext { stage: 'commit' | 'apply'; targetId?: string; kind?: SuggestionKind; } /** Options of the `TiptapVeltSuggestions` extension. */ export interface TiptapVeltSuggestionsOptions { /** Idle time (ms) after the last edit before pending edits are committed. Default 2000. */ debounceMs: number; /** Also commit when the editor loses focus. Default true. */ commitOnBlur: boolean; /** Also commit edits in other blocks when the caret moves to another block. Default true. */ commitOnBlockChange: boolean; /** * Format marks tracked as suggestions while suggesting. `false` turns format tracking off. * Default: bold, italic, underline, strike (not `code`: Tiptap's inline code cannot carry other marks). */ trackFormats: readonly string[] | false; /** Builds the text of the suggestion's first comment. Default: an English one-liner. */ summary: ((input: SuggestionSummaryInput) => string) | null; /** Colour of an author's suggestions. Default: a stable colour from the user id. */ getAuthorColor: ((userId: string) => string) | null; /** Called when a suggestion could not be committed or applied. */ onError: ((error: unknown, context: SuggestionErrorContext) => void) | null; /** Inject the default styles (CSS variables `--velt-suggestion-color`). Default true. */ injectCSS: boolean; }