@veltdev/tiptap-velt-comments
Version:
Tiptap Extension to add Google Docs-style overlay comments to your Tiptap editor. Works with the Velt Collaboration SDK.
74 lines (73 loc) • 2.34 kB
TypeScript
/**
* Render comments feature module.
*
* Purpose: Public API entry point for rendering comment annotations.
* Orchestrates state updates, subscriptions, and delegates to commentRenderer.
*
* Key responsibilities:
* - Update state with new annotations
* - Subscribe to selected annotations from Velt
* - Delegate rendering logic to commentRenderer
*
* Dependencies:
* - adapters/velt.ts (for Velt SDK subscription)
* - adapters/host/doc.ts (for editor setup)
* - core/state.ts (for state management)
* - features/commentRenderer.ts (for rendering logic)
* - types/velt.ts (for CommentAnnotation)
* - utils/console.ts (for logging)
*
* IMPORTANT: This module MUST NOT import editor or Velt types directly.
* All SDK access goes through adapters.
*/
import type { RenderCommentsRequest } from '@/types/common';
/**
* Renders comment annotations as marks in the editor.
*
* This function renders comment annotations as visual marks in the editor.
* It filters annotations for the specific editor and applies marks accordingly.
*
* @param request - Object containing editor, editorId (optional), and commentAnnotations (optional)
*
* @example
* ```typescript
* // Simple usage
* renderComments({ editor });
*
* // With editor ID
* renderComments({ editorId: 'my-editor', editor });
*
* // With annotations
* renderComments({
* editorId: 'my-editor',
* editor,
* commentAnnotations: [
* {
* annotationId: 'ann-123',
* context: {
* textEditorConfig: {
* text: 'Hello world',
* occurrence: 1,
* editorId: 'my-editor'
* }
* }
* }
* ]
* });
* ```
*
* @remarks
* - Only annotations with matching editorId are rendered
* - Automatically subscribes to selected annotations changes
* - Filters out terminal/resolved comments unless they're selected
* - Removes marks when comments become resolved
* - Re-applies marks when resolved comments are selected
*/
export declare const renderComments: ({ editor, editorId, commentAnnotations, }: RenderCommentsRequest) => void;
/**
* Cleans up subscriptions and renderer state for an editor.
* Should be called when editor is destroyed.
*
* @param editorId Unique identifier for the editor
*/
export declare const cleanupRenderComments: (editorId: string) => void;