@veltdev/slate-velt-comments-staging 1.0.4 → 5.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/cjs/index.js +1 -1
  2. package/cjs/index.js.map +1 -1
  3. package/cjs/types/adapters/host/doc.d.ts +86 -0
  4. package/cjs/types/adapters/host/marks.d.ts +51 -0
  5. package/cjs/types/adapters/host/storage.d.ts +38 -0
  6. package/cjs/types/adapters/velt.d.ts +50 -0
  7. package/cjs/types/constants/common.d.ts +58 -0
  8. package/cjs/types/core/ExtensionComponent.d.ts +13 -0
  9. package/cjs/types/core/extension.d.ts +54 -0
  10. package/cjs/types/core/registry.d.ts +52 -0
  11. package/cjs/types/core/state.d.ts +80 -0
  12. package/cjs/types/features/addComment.d.ts +63 -0
  13. package/cjs/types/features/commentRenderer.d.ts +46 -0
  14. package/cjs/types/features/renderComments.d.ts +73 -0
  15. package/cjs/types/features/updateContent.d.ts +25 -0
  16. package/cjs/types/index.d.ts +14 -34
  17. package/cjs/types/types/common.d.ts +54 -0
  18. package/cjs/types/types/host.d.ts +65 -0
  19. package/cjs/types/types/state.d.ts +28 -0
  20. package/cjs/types/types/velt.d.ts +23 -0
  21. package/cjs/types/utils/common.d.ts +80 -0
  22. package/cjs/types/utils/console.d.ts +25 -0
  23. package/cjs/types/utils/serializer.d.ts +20 -0
  24. package/esm/index.js +1 -1
  25. package/esm/index.js.map +1 -1
  26. package/esm/types/adapters/host/doc.d.ts +86 -0
  27. package/esm/types/adapters/host/marks.d.ts +51 -0
  28. package/esm/types/adapters/host/storage.d.ts +38 -0
  29. package/esm/types/adapters/velt.d.ts +50 -0
  30. package/esm/types/constants/common.d.ts +58 -0
  31. package/esm/types/core/ExtensionComponent.d.ts +13 -0
  32. package/esm/types/core/extension.d.ts +54 -0
  33. package/esm/types/core/registry.d.ts +52 -0
  34. package/esm/types/core/state.d.ts +80 -0
  35. package/esm/types/features/addComment.d.ts +63 -0
  36. package/esm/types/features/commentRenderer.d.ts +46 -0
  37. package/esm/types/features/renderComments.d.ts +73 -0
  38. package/esm/types/features/updateContent.d.ts +25 -0
  39. package/esm/types/index.d.ts +14 -34
  40. package/esm/types/types/common.d.ts +54 -0
  41. package/esm/types/types/host.d.ts +65 -0
  42. package/esm/types/types/state.d.ts +28 -0
  43. package/esm/types/types/velt.d.ts +23 -0
  44. package/esm/types/utils/common.d.ts +80 -0
  45. package/esm/types/utils/console.d.ts +25 -0
  46. package/esm/types/utils/serializer.d.ts +20 -0
  47. package/index.d.ts +268 -34
  48. package/package.json +1 -1
  49. package/cjs/types/SlateVeltComment.d.ts +0 -6
  50. package/cjs/types/constants.d.ts +0 -9
  51. package/cjs/types/editor.d.ts +0 -72
  52. package/cjs/types/plugin.d.ts +0 -17
  53. package/cjs/types/store.d.ts +0 -36
  54. package/cjs/types/types.d.ts +0 -14
  55. package/cjs/types/velt.d.ts +0 -21
  56. package/esm/types/SlateVeltComment.d.ts +0 -6
  57. package/esm/types/constants.d.ts +0 -9
  58. package/esm/types/editor.d.ts +0 -72
  59. package/esm/types/plugin.d.ts +0 -17
  60. package/esm/types/store.d.ts +0 -36
  61. package/esm/types/types.d.ts +0 -14
  62. package/esm/types/velt.d.ts +0 -21
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Host editor document operations adapter.
3
+ * This is the ONLY place where editor-specific types may be imported.
4
+ *
5
+ * Responsibilities:
6
+ * - Extract selection context from editor
7
+ * - Find text occurrences in document
8
+ * - Detect document changes for annotations
9
+ * - Get editor ID from DOM
10
+ *
11
+ * Architectural Rules:
12
+ * - MAY import editor-specific types (Editor, Node, Range, etc.)
13
+ * - MUST NOT import Velt SDK types
14
+ * - Uses pure utilities from utils/common.ts where possible
15
+ */
16
+ import { Editor } from 'slate';
17
+ import type { AnnotationChange, OccurrenceMatch, SelectionContext } from '@/types/host';
18
+ /**
19
+ * Gets editor ID from editor instance by traversing DOM.
20
+ * Returns null if editor ID attribute not found.
21
+ */
22
+ export declare const getEditorId: (editor: Editor) => string | null;
23
+ /**
24
+ * Gets current selection context from editor with full details.
25
+ * Returns null if no selection or selection is collapsed.
26
+ */
27
+ export declare const getCurrentSelectionContext: (editor: Editor) => SelectionContext | null;
28
+ /**
29
+ * Finds occurrence index of selected text in the document.
30
+ * Returns 1-based occurrence index, or 0 if not found.
31
+ */
32
+ export declare const findOccurrenceIndex: (editor: Editor, text: string, targetTextNodeId?: string) => number;
33
+ /**
34
+ * Finds all text occurrences in the document.
35
+ * Returns array of ranges matching the search text.
36
+ */
37
+ export declare const findTextOccurrences: (editor: Editor, text: string, targetTextNodeId?: string, occurrence?: number) => OccurrenceMatch[];
38
+ /**
39
+ * Finds parent node with ID attribute for current selection.
40
+ * Returns HTMLElement with ID, or null if not found.
41
+ */
42
+ export declare const findParentNodeWithId: (editor: Editor) => HTMLElement | null;
43
+ /**
44
+ * Function type for getting annotation data.
45
+ */
46
+ type GetAnnotationDataFn = (id: string) => {
47
+ annotation: unknown;
48
+ originalText: string;
49
+ originalOccurrence: number;
50
+ targetTextNodeId: string;
51
+ } | null;
52
+ /**
53
+ * Detects document changes for annotations.
54
+ * Compares current document state with stored annotation data.
55
+ */
56
+ export declare const detectDocumentChanges: (editor: Editor, transaction: unknown, markType: string | undefined, getAnnotationData: GetAnnotationDataFn) => Map<string, AnnotationChange>;
57
+ /**
58
+ * Ensures editor is set up (registered and document listeners configured).
59
+ * This is a unified adapter function that handles both registration and setup.
60
+ *
61
+ * @param editorId Optional editor ID (will be resolved from editor if not provided)
62
+ * @param editor The editor instance (typed as unknown to avoid importing editor types in feature modules)
63
+ * @returns Object with editorId string
64
+ *
65
+ * @remarks
66
+ * - This function abstracts editor-specific setup logic
67
+ * - For Slate, just resolves editor ID (document listeners are handled by extension)
68
+ * - Fails silently if setup fails
69
+ */
70
+ export declare const ensureEditorSetup: (editorId: string | undefined, editor: unknown) => {
71
+ editorId: string;
72
+ };
73
+ /**
74
+ * Resets the editor selection by focusing the editor.
75
+ * Uses Slate's selection API to reset selection/focus after comment operations.
76
+ *
77
+ * @param editor The editor instance (typed as unknown to avoid importing editor types in feature modules)
78
+ * @returns void
79
+ *
80
+ * @remarks
81
+ * - This function abstracts editor-specific selection reset logic
82
+ * - For Slate, selection reset is handled by the editor itself
83
+ * - Fails silently if reset fails
84
+ */
85
+ export declare const resetEditorSelection: (editor: unknown) => void;
86
+ export {};
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Host editor marks/nodes operations adapter.
3
+ * This is the ONLY place where editor-specific mark/node operations may be implemented.
4
+ *
5
+ * Responsibilities:
6
+ * - Apply comment marks/nodes to editor
7
+ * - Remove comment marks/nodes from editor
8
+ * - Update marks/nodes when document changes
9
+ *
10
+ * Architectural Rules:
11
+ * - MAY import editor-specific types (Editor, Element, Transforms, etc.)
12
+ * - MUST NOT import Velt SDK types
13
+ * - Handles editor-specific mark/node application logic
14
+ */
15
+ import { Editor } from 'slate';
16
+ import type { AnnotationChange } from '@/types/host';
17
+ /**
18
+ * Sets the history editor instance (called from extension).
19
+ */
20
+ export declare const setHistoryEditor: (historyEditor: {
21
+ withoutSaving?: (editor: Editor, fn: () => void) => void;
22
+ } | null) => void;
23
+ /**
24
+ * Gets the history editor instance.
25
+ */
26
+ export declare const getHistoryEditor: () => {
27
+ withoutSaving?: (editor: Editor, fn: () => void) => void;
28
+ } | null;
29
+ /**
30
+ * Applies annotation mark/node by finding text occurrence and wrapping it.
31
+ * This is the main entry point for applying marks.
32
+ *
33
+ * @param editor The editor instance (typed as unknown to avoid importing editor types in feature modules)
34
+ * @param textToSearch The text to search for
35
+ * @param occurrence The occurrence number (1-based)
36
+ * @param annotationId The annotation ID to mark
37
+ * @param multiThreadAnnotationId Optional multi-thread annotation ID
38
+ * @param targetElementId Optional target element ID to scope the search
39
+ * @returns True if mark was successfully applied, false otherwise
40
+ */
41
+ export declare const applyAnnotationMarkByText: (editor: unknown, textToSearch: string, occurrence: number, annotationId: string, multiThreadAnnotationId: string | undefined, targetElementId?: string) => boolean;
42
+ /**
43
+ * Removes annotation mark/node from editor by annotation ID.
44
+ * Finds all nodes with matching annotationId and unwraps them.
45
+ */
46
+ export declare const removeAnnotationMark: (editor: Editor, annotationId: string) => boolean;
47
+ /**
48
+ * Updates marks/nodes based on document changes.
49
+ * Removes old marks and applies new ones at updated positions.
50
+ */
51
+ export declare const updateMarks: (editor: Editor, changes: Map<string, AnnotationChange>) => void;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Storage adapter for editor-specific storage access.
3
+ *
4
+ * Purpose: Abstracts away editor-specific storage patterns.
5
+ * This allows the codebase to be more generic and reusable across different editor implementations.
6
+ *
7
+ * Key responsibilities:
8
+ * - Get persistVeltMarks setting (for Slate, checks extension config)
9
+ * - Determine if marks should be applied
10
+ *
11
+ * Dependencies:
12
+ * - slate (ONLY place allowed to import Editor types for storage access)
13
+ */
14
+ import type { Editor } from 'slate';
15
+ /**
16
+ * Gets persistVeltMarks setting from storage.
17
+ * For Slate, checks the extension config from registry.
18
+ *
19
+ * @param editor The editor instance
20
+ * @param storageKey The storage key (unused for Slate, kept for API compatibility)
21
+ * @returns persistVeltMarks boolean value (defaults to true)
22
+ */
23
+ export declare const getPersistVeltMarks: (editor: Editor, storageKey?: string) => boolean;
24
+ /**
25
+ * Determines if marks should be applied based on persistVeltMarks setting.
26
+ * This is a unified adapter function that abstracts the mark application logic.
27
+ *
28
+ * @param editor The editor instance (typed as unknown to avoid importing editor types in feature modules)
29
+ * @param storageKey The storage key (default: 'slateVeltComments')
30
+ * @returns boolean indicating if marks should be applied
31
+ *
32
+ * @remarks
33
+ * - For TipTap: checks persistVeltMarks setting (apply if FALSE)
34
+ * - For Lexical: always returns true (always apply marks)
35
+ * - For Slate: checks persistVeltMarks setting (apply if FALSE)
36
+ * - Defaults to true if storage is unavailable
37
+ */
38
+ export declare const shouldApplyMark: (editor: unknown, storageKey?: string) => boolean;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Velt SDK adapter.
3
+ * This is the ONLY place where @veltdev/types may be imported or window.Velt accessed.
4
+ *
5
+ * Responsibilities:
6
+ * - Wrap all Velt SDK calls with error handling
7
+ * - Provide high-level async functions for SDK operations
8
+ * - Manage singleton subscription pattern
9
+ *
10
+ * Architectural Rules:
11
+ * - MAY import @veltdev/types
12
+ * - MAY access window.Velt
13
+ * - MUST wrap all SDK calls in try-catch
14
+ * - MUST NOT import editor types
15
+ */
16
+ import type { CommentAnnotationContext } from '@/types/common';
17
+ import type { CommentAnnotation, CommentElement, Location, UnsubscribeFn } from '@/types/velt';
18
+ /**
19
+ * Gets Velt comment element from SDK.
20
+ * Returns null if SDK is not available.
21
+ */
22
+ export declare const getCommentElement: () => CommentElement | null;
23
+ /**
24
+ * Adds a comment via Velt SDK.
25
+ * Returns the created annotation, or null on failure.
26
+ */
27
+ export declare const addVeltComment: (params: {
28
+ context: CommentAnnotationContext;
29
+ location?: Location;
30
+ }) => Promise<{
31
+ annotation: CommentAnnotation;
32
+ } | null>;
33
+ /**
34
+ * Updates annotation context in Velt SDK.
35
+ */
36
+ export declare const updateAnnotationContext: (annotationId: string, context: CommentAnnotationContext) => void;
37
+ /**
38
+ * Subscribes to selected annotations from Velt SDK.
39
+ * Uses singleton pattern to avoid multiple subscriptions.
40
+ * Returns unsubscribe function.
41
+ *
42
+ * Matches Tiptap's signature: callback receives Set<string> of selected annotation IDs.
43
+ */
44
+ export declare const subscribeToSelectedAnnotations: (callback: (selectedIds: Set<string>) => void, editorId: string) => UnsubscribeFn;
45
+ /**
46
+ * Attempts to set up the selected comments subscription if not already done.
47
+ * This should be called when we know the Velt SDK is ready.
48
+ * Returns true if subscription is now active.
49
+ */
50
+ export declare const ensureSelectedCommentsSubscription: () => boolean;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Shared constants for Slate-Velt Comments integration
3
+ *
4
+ * This module contains all magic strings and configuration constants
5
+ * used across the application.
6
+ */
7
+ export declare const Constants: {
8
+ /**
9
+ * DOM attribute names used for editor identification and location tracking.
10
+ */
11
+ readonly ATTRIBUTES: {
12
+ readonly EDITOR_ID: "data-editor-id";
13
+ readonly LOCATION_ID: "data-velt-location-id";
14
+ readonly ANNOTATION_ID: "annotation-id";
15
+ readonly MULTI_THREAD_ANNOTATION_ID: "multi-thread-annotation-id";
16
+ };
17
+ /**
18
+ * Element types used in the editor's document model.
19
+ */
20
+ readonly ELEMENT_TYPE: {
21
+ readonly VELT_COMMENT: "veltComment";
22
+ };
23
+ /**
24
+ * Mark/extension name constant.
25
+ * Generic constant name, value is Slate-specific for this package.
26
+ */
27
+ readonly MARK_NAME: "veltComment";
28
+ /**
29
+ * Storage key constant.
30
+ * Generic constant name, value is Slate-specific for this package.
31
+ */
32
+ readonly STORAGE_KEY: "slateVeltComments";
33
+ /**
34
+ * Default extension name for error messages.
35
+ */
36
+ readonly DEFAULT_EXTENSION_NAME: "VeltComments";
37
+ /**
38
+ * Default editor ID used when no editor ID is provided.
39
+ * Uses '__default__' to avoid collision with user-provided values.
40
+ */
41
+ readonly DEFAULT_EDITOR_ID: "__default__";
42
+ /**
43
+ * Terminal status type for resolved/closed comments.
44
+ */
45
+ readonly STATUS_TERMINAL: "terminal";
46
+ /**
47
+ * Log prefix for console messages.
48
+ */
49
+ readonly LOG_PREFIX: "SlateVeltComments: ";
50
+ /**
51
+ * Session storage key for debug mode.
52
+ */
53
+ readonly DEBUG_MODE_KEY: "debugMode";
54
+ /**
55
+ * Session storage key for forced debug mode.
56
+ */
57
+ readonly FORCE_DEBUG_MODE_KEY: "forceDebugMode";
58
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * React component for rendering Velt comment elements in Slate editor.
3
+ * This component renders the <velt-comment-text> custom element.
4
+ *
5
+ * Note: velt-comment-text is an inline element, so it should only contain text nodes
6
+ * or other inline elements, never block elements like <p>.
7
+ */
8
+ import React from 'react';
9
+ import type { RenderElementProps } from 'slate-react';
10
+ import type { VeltCommentsElement } from '@/types/host';
11
+ export declare const SlateVeltComment: (props: Omit<RenderElementProps, "element"> & {
12
+ element: VeltCommentsElement;
13
+ }) => React.ReactElement;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Core extension module.
3
+ * This module creates the editor extension that wires everything together.
4
+ *
5
+ * Responsibilities:
6
+ * - Create extension factory function
7
+ * - Wire features into editor lifecycle hooks
8
+ * - Register editor in registry
9
+ * - Handle cleanup on editor destruction
10
+ *
11
+ * Architectural Rules:
12
+ * - This module MAY import editor types (it's the extension entry point)
13
+ * - It delegates to features and adapters for actual work
14
+ */
15
+ import type { Editor } from 'slate';
16
+ import type { ExtensionConfig } from '@/types/common';
17
+ /**
18
+ * Extension configuration interface.
19
+ * Matches legacy VeltCommentsEditorOptions.
20
+ */
21
+ export interface VeltCommentsExtensionConfig extends ExtensionConfig {
22
+ HistoryEditor?: unknown;
23
+ }
24
+ /**
25
+ * Wraps the editor with Velt Comments functionality.
26
+ *
27
+ * This is the main entry point that enhances the editor with comment functionality.
28
+ * It enhances the editor by:
29
+ * - Overriding isInline and isVoid methods to handle comment elements
30
+ * - Setting up onChange handler to detect and process document changes
31
+ * - Registering the editor in the registry for state management
32
+ *
33
+ * @param editor - The Slate editor instance to enhance
34
+ * @param config - Optional extension configuration including HistoryEditor and editorId
35
+ * @returns Enhanced editor with Velt comments functionality
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // Standard Slate plugin pattern
40
+ * const editor = withVeltComments(withReact(createEditor()));
41
+ *
42
+ * // With configuration
43
+ * const editor = withVeltComments(withReact(createEditor()), {
44
+ * HistoryEditor: myHistoryEditor,
45
+ * editorId: 'my-editor'
46
+ * });
47
+ * ```
48
+ *
49
+ * @remarks
50
+ * - Follows standard Slate plugin pattern (like withReact, withHistory)
51
+ * - Only processes text-related operations to avoid unnecessary updates
52
+ * - Registers editor with default editorId if not provided
53
+ */
54
+ export declare const withVeltComments: <T extends Editor>(editor: T, config?: VeltCommentsExtensionConfig) => T;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Core registry module.
3
+ *
4
+ * Purpose: Maintains a registry mapping editorId → editor context.
5
+ * Replaces the singleton pattern from legacy Plugin class with a proper registry.
6
+ *
7
+ * Key responsibilities:
8
+ * - Register editor instances with their configuration
9
+ * - Retrieve editor contexts by ID
10
+ * - Unregister editors when they're destroyed
11
+ * - Extract editor IDs from editor instances
12
+ *
13
+ * Dependencies: types/common.ts, core/state.ts, adapters/host/doc.ts
14
+ */
15
+ import type { EditorContext, ExtensionConfig } from '@/types/common';
16
+ /**
17
+ * Registers an editor instance in the registry.
18
+ * Creates initial state for the editor.
19
+ *
20
+ * @param editorId Unique identifier for the editor
21
+ * @param editor The editor instance
22
+ * @param config Extension configuration options
23
+ * @returns EditorContext for the registered editor
24
+ */
25
+ export declare const registerEditor: <TEditor = unknown>(editorId: string, editor: TEditor, config?: ExtensionConfig) => EditorContext<TEditor>;
26
+ /**
27
+ * Retrieves the editor context for a given editor ID.
28
+ *
29
+ * @param editorId Unique identifier for the editor
30
+ * @returns EditorContext or null if not found
31
+ */
32
+ export declare const getEditorContext: <TEditor = unknown>(editorId: string) => EditorContext<TEditor> | null;
33
+ /**
34
+ * Unregisters an editor from the registry and cleans up its state.
35
+ *
36
+ * @param editorId Unique identifier for the editor
37
+ */
38
+ export declare const unregisterEditor: (editorId: string) => void;
39
+ /**
40
+ * Extracts the editor ID from an editor instance.
41
+ * Checks editor storage first, then DOM attributes.
42
+ *
43
+ * @param editor The editor instance
44
+ * @returns Editor ID or null if not found
45
+ */
46
+ export declare const getEditorIdFromEditor: (editor: unknown) => string | null;
47
+ /**
48
+ * Gets all registered editor IDs.
49
+ *
50
+ * @returns Array of editor IDs
51
+ */
52
+ export declare const getAllEditorIds: () => string[];
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Core state management module.
3
+ *
4
+ * Purpose: Single source of truth for annotation state per editor.
5
+ * This module manages annotation data and selected annotations for each editor instance.
6
+ *
7
+ * Key responsibilities:
8
+ * - Create and manage per-editor annotation state
9
+ * - CRUD operations for annotations
10
+ * - Track selected annotations
11
+ * - Ensure state isolation between editor instances
12
+ *
13
+ * Dependencies: types/state.ts, types/common.ts
14
+ */
15
+ import type { AnnotationData, AnnotationState } from '@/types/state';
16
+ import type { CommentAnnotation } from '@/types/velt';
17
+ /**
18
+ * Creates a new annotation state for an editor instance.
19
+ *
20
+ * @param editorId Unique identifier for the editor
21
+ * @returns New AnnotationState instance
22
+ */
23
+ export declare const createAnnotationState: (editorId: string) => AnnotationState;
24
+ /**
25
+ * Updates annotations in state from Velt SDK data.
26
+ * Converts CommentAnnotation[] to AnnotationData[] and stores them.
27
+ *
28
+ * @param editorId Unique identifier for the editor
29
+ * @param annotations Array of CommentAnnotation from Velt SDK
30
+ */
31
+ export declare const updateAnnotations: (editorId: string, annotations: CommentAnnotation[]) => void;
32
+ /**
33
+ * Retrieves a single annotation by ID.
34
+ *
35
+ * @param editorId Unique identifier for the editor
36
+ * @param annotationId The annotation ID to retrieve
37
+ * @returns AnnotationData or null if not found
38
+ */
39
+ export declare const getAnnotation: (editorId: string, annotationId: string) => AnnotationData | null;
40
+ /**
41
+ * Removes an annotation from state.
42
+ *
43
+ * @param editorId Unique identifier for the editor
44
+ * @param annotationId The annotation ID to remove
45
+ */
46
+ export declare const removeAnnotation: (editorId: string, annotationId: string) => void;
47
+ /**
48
+ * Gets the set of selected annotation IDs for an editor.
49
+ *
50
+ * @param editorId Unique identifier for the editor
51
+ * @returns Set of selected annotation IDs
52
+ */
53
+ export declare const getSelectedAnnotations: (editorId: string) => Set<string>;
54
+ /**
55
+ * Updates the set of selected annotation IDs for an editor.
56
+ *
57
+ * @param editorId Unique identifier for the editor
58
+ * @param selectedIds Set of selected annotation IDs
59
+ */
60
+ export declare const setSelectedAnnotations: (editorId: string, selectedIds: Set<string>) => void;
61
+ /**
62
+ * Gets all annotations for an editor.
63
+ *
64
+ * @param editorId Unique identifier for the editor
65
+ * @returns Map of annotation ID to AnnotationData
66
+ */
67
+ export declare const getAllAnnotations: (editorId: string) => Map<string, AnnotationData>;
68
+ /**
69
+ * Gets all comment annotations for an editor (with status field).
70
+ *
71
+ * @param editorId Unique identifier for the editor
72
+ * @returns Array of CommentAnnotation with status field
73
+ */
74
+ export declare const getCommentAnnotations: (editorId: string) => CommentAnnotation[];
75
+ /**
76
+ * Clears all state for an editor (used during cleanup).
77
+ *
78
+ * @param editorId Unique identifier for the editor
79
+ */
80
+ export declare const clearState: (editorId: string) => void;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Add comment feature module.
3
+ *
4
+ * Purpose: End-to-end add comment orchestration.
5
+ * Orchestrates adapters and core to implement the add comment flow.
6
+ *
7
+ * Key responsibilities:
8
+ * - Get Velt comment element
9
+ * - Extract selection context from editor
10
+ * - Create comment via Velt SDK
11
+ * - Apply mark to editor document
12
+ * - Update state with annotation data
13
+ *
14
+ * Dependencies:
15
+ * - adapters/velt.ts (for Velt SDK calls)
16
+ * - adapters/host/doc.ts (for selection extraction, editor setup, and selection reset)
17
+ * - adapters/host/marks.ts (for mark application)
18
+ * - adapters/host/storage.ts (for mark application configuration)
19
+ * - core/state.ts (for state updates)
20
+ * - types/common.ts (for CommentAnnotationContext)
21
+ *
22
+ * IMPORTANT: This module MUST NOT import editor or Velt types directly.
23
+ * All SDK access goes through adapters.
24
+ */
25
+ import type { AddCommentRequest } from '@/types/common';
26
+ /**
27
+ * Adds a comment to the currently selected text in the editor.
28
+ *
29
+ * This is the main entry point for adding comments. It handles:
30
+ * - Extracting selection context from the editor
31
+ * - Creating the comment via Velt SDK
32
+ * - Applying marks to the editor if configured
33
+ * - Updating state with annotation data
34
+ *
35
+ * @param request - Object containing editorId (optional), editor, and context (optional)
36
+ * @returns Promise that resolves when the comment is added (or fails silently)
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Simple usage
41
+ * await addComment({ editor });
42
+ *
43
+ * // With editor ID
44
+ * await addComment({ editorId: 'my-editor', editor });
45
+ *
46
+ * // With custom context
47
+ * await addComment({
48
+ * editorId: 'my-editor',
49
+ * editor,
50
+ * context: {
51
+ * userId: 'user123',
52
+ * metadata: { source: 'web-app' }
53
+ * }
54
+ * });
55
+ * ```
56
+ *
57
+ * @remarks
58
+ * - Requires text to be selected in the editor
59
+ * - Requires Velt SDK to be available (window.Velt)
60
+ * - Marks are only applied if persistVeltMarks is FALSE in extension config (matching legacy behavior)
61
+ * - Fails silently if Velt SDK is unavailable or selection is invalid
62
+ */
63
+ export declare function addComment({ editorId, editor, context: clientContext, }: AddCommentRequest): Promise<void>;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Comment renderer module.
3
+ *
4
+ * Purpose: Handle filtering, comparison, and mark updates for comment annotations.
5
+ * This module manages the rendering state and applies marks based on resolved/selected status.
6
+ *
7
+ * Key responsibilities:
8
+ * - Filter annotations based on status (terminal/resolved) and selected state
9
+ * - Compare previous vs current filtered annotations to detect removals
10
+ * - Remove marks for annotations that should no longer be shown
11
+ * - Re-apply marks for all filtered annotations
12
+ *
13
+ * Dependencies:
14
+ * - core/state.ts (for reading annotations and selected state)
15
+ * - adapters/host/doc.ts (for finding text occurrences)
16
+ * - adapters/host/marks.ts (for applying/removing marks)
17
+ * - types/velt.ts (for CommentAnnotation)
18
+ *
19
+ * IMPORTANT: This module MUST NOT import editor or Velt types directly.
20
+ * All SDK access goes through adapters.
21
+ */
22
+ import type { CommentAnnotation } from '@/types/velt';
23
+ /**
24
+ * Updates comments for an editor by filtering, comparing, removing, and re-applying marks.
25
+ * This is the core rendering logic that handles resolved comment filtering.
26
+ *
27
+ * @param editorId Unique identifier for the editor
28
+ * @param editor The editor instance
29
+ * @param annotations All CommentAnnotation from Velt SDK (with status)
30
+ */
31
+ export declare const updateComments: (editorId: string, editor: unknown, annotations: CommentAnnotation[]) => void;
32
+ /**
33
+ * Updates comments when selected annotations change.
34
+ * Re-reads annotations from state and triggers re-rendering.
35
+ *
36
+ * @param editorId Unique identifier for the editor
37
+ * @param selectedIds Set of selected annotation IDs (already updated in state)
38
+ */
39
+ export declare const updateSelection: (editorId: string, selectedIds: Set<string>) => void;
40
+ /**
41
+ * Cleans up renderer store for an editor.
42
+ * Should be called when editor is destroyed.
43
+ *
44
+ * @param editorId Unique identifier for the editor
45
+ */
46
+ export declare const cleanupRenderer: (editorId: string) => void;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Render comments feature module.
3
+ *
4
+ * Purpose: Public API entry point for rendering comment annotations.
5
+ * Orchestrates state updates, subscriptions, and delegates to commentRenderer.
6
+ *
7
+ * Key responsibilities:
8
+ * - Update state with new annotations
9
+ * - Subscribe to selected annotations from Velt
10
+ * - Delegate rendering logic to commentRenderer
11
+ *
12
+ * Dependencies:
13
+ * - adapters/velt.ts (for Velt SDK subscription)
14
+ * - adapters/host/doc.ts (for editor setup)
15
+ * - core/state.ts (for state management)
16
+ * - core/registry.ts (for editor ID extraction)
17
+ * - features/commentRenderer.ts (for rendering logic)
18
+ * - types/velt.ts (for CommentAnnotation)
19
+ *
20
+ * IMPORTANT: This module MUST NOT import editor or Velt types directly.
21
+ * All SDK access goes through adapters.
22
+ */
23
+ import type { RenderCommentsRequest } from '@/types/common';
24
+ /**
25
+ * Renders comment annotations as marks in the editor.
26
+ *
27
+ * This function renders comment annotations as visual marks in the editor.
28
+ * It filters annotations for the specific editor and applies marks accordingly.
29
+ *
30
+ * @param request - Object containing editor, editorId (optional), and commentAnnotations (optional)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Simple usage
35
+ * renderComments({ editor });
36
+ *
37
+ * // With editor ID
38
+ * renderComments({ editorId: 'my-editor', editor });
39
+ *
40
+ * // With annotations
41
+ * renderComments({
42
+ * editorId: 'my-editor',
43
+ * editor,
44
+ * commentAnnotations: [
45
+ * {
46
+ * annotationId: 'ann-123',
47
+ * context: {
48
+ * textEditorConfig: {
49
+ * text: 'Hello world',
50
+ * occurrence: 1,
51
+ * editorId: 'my-editor'
52
+ * }
53
+ * }
54
+ * }
55
+ * ]
56
+ * });
57
+ * ```
58
+ *
59
+ * @remarks
60
+ * - Only annotations with matching editorId are rendered
61
+ * - Automatically subscribes to selected annotations changes
62
+ * - Filters out terminal/resolved comments unless they're selected
63
+ * - Removes marks when comments become resolved
64
+ * - Re-applies marks when resolved comments are selected
65
+ */
66
+ export declare const renderComments: ({ editor, editorId, commentAnnotations, }: RenderCommentsRequest) => void;
67
+ /**
68
+ * Cleans up subscriptions and renderer state for an editor.
69
+ * Should be called when editor is destroyed.
70
+ *
71
+ * @param editorId Unique identifier for the editor
72
+ */
73
+ export declare const cleanupRenderComments: (editorId: string) => void;