@veltdev/plate-comments-react 1.0.0

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 (49) hide show
  1. package/README.md +59 -0
  2. package/cjs/index.js +2 -0
  3. package/cjs/index.js.map +1 -0
  4. package/cjs/types/adapters/host/doc.d.ts +69 -0
  5. package/cjs/types/adapters/host/marks.d.ts +51 -0
  6. package/cjs/types/adapters/host/storage.d.ts +36 -0
  7. package/cjs/types/adapters/velt.d.ts +50 -0
  8. package/cjs/types/constants/common.d.ts +62 -0
  9. package/cjs/types/core/ExtensionComponent.d.ts +13 -0
  10. package/cjs/types/core/extension.d.ts +50 -0
  11. package/cjs/types/core/registry.d.ts +52 -0
  12. package/cjs/types/core/state.d.ts +80 -0
  13. package/cjs/types/features/addComment.d.ts +63 -0
  14. package/cjs/types/features/commentRenderer.d.ts +46 -0
  15. package/cjs/types/features/renderComments.d.ts +73 -0
  16. package/cjs/types/features/updateContent.d.ts +20 -0
  17. package/cjs/types/index.d.ts +16 -0
  18. package/cjs/types/types/common.d.ts +54 -0
  19. package/cjs/types/types/host.d.ts +74 -0
  20. package/cjs/types/types/state.d.ts +28 -0
  21. package/cjs/types/types/velt.d.ts +23 -0
  22. package/cjs/types/utils/common.d.ts +80 -0
  23. package/cjs/types/utils/console.d.ts +10 -0
  24. package/cjs/types/utils/serializer.d.ts +20 -0
  25. package/esm/index.js +2 -0
  26. package/esm/index.js.map +1 -0
  27. package/esm/types/adapters/host/doc.d.ts +69 -0
  28. package/esm/types/adapters/host/marks.d.ts +51 -0
  29. package/esm/types/adapters/host/storage.d.ts +36 -0
  30. package/esm/types/adapters/velt.d.ts +50 -0
  31. package/esm/types/constants/common.d.ts +62 -0
  32. package/esm/types/core/ExtensionComponent.d.ts +13 -0
  33. package/esm/types/core/extension.d.ts +50 -0
  34. package/esm/types/core/registry.d.ts +52 -0
  35. package/esm/types/core/state.d.ts +80 -0
  36. package/esm/types/features/addComment.d.ts +63 -0
  37. package/esm/types/features/commentRenderer.d.ts +46 -0
  38. package/esm/types/features/renderComments.d.ts +73 -0
  39. package/esm/types/features/updateContent.d.ts +20 -0
  40. package/esm/types/index.d.ts +16 -0
  41. package/esm/types/types/common.d.ts +54 -0
  42. package/esm/types/types/host.d.ts +74 -0
  43. package/esm/types/types/state.d.ts +28 -0
  44. package/esm/types/types/velt.d.ts +23 -0
  45. package/esm/types/utils/common.d.ts +80 -0
  46. package/esm/types/utils/console.d.ts +10 -0
  47. package/esm/types/utils/serializer.d.ts +20 -0
  48. package/index.d.ts +291 -0
  49. package/package.json +28 -0
@@ -0,0 +1,36 @@
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 Plate, checks plugin options via registry)
9
+ * - Determine if marks should be applied
10
+ *
11
+ * Dependencies:
12
+ * - @platejs/core/react (ONLY place allowed to import PlateEditor for storage access)
13
+ */
14
+ import type { PlateEditor } from '@platejs/core/react';
15
+ /**
16
+ * Gets persistVeltMarks setting from storage.
17
+ * For Plate, checks the plugin config from registry.
18
+ *
19
+ * @param editor The editor instance
20
+ * @param storageKey The storage key (unused for Plate, kept for API compatibility)
21
+ * @returns persistVeltMarks boolean value (defaults to true)
22
+ */
23
+ export declare const getPersistVeltMarks: (editor: PlateEditor, 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: 'plateVeltComments')
30
+ * @returns boolean indicating if marks should be applied
31
+ *
32
+ * @remarks
33
+ * - For Plate: checks persistVeltMarks setting (apply if FALSE)
34
+ * - Defaults to true if storage is unavailable
35
+ */
36
+ 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
+ * 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,62 @@
1
+ /**
2
+ * Shared constants for Plate-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 Plate-specific for this package.
26
+ */
27
+ readonly MARK_NAME: "veltComment";
28
+ /**
29
+ * Plugin key for Plate.js plugin system.
30
+ */
31
+ readonly PLUGIN_KEY: "veltComments";
32
+ /**
33
+ * Storage key constant.
34
+ * Generic constant name, value is Plate-specific for this package.
35
+ */
36
+ readonly STORAGE_KEY: "plateVeltComments";
37
+ /**
38
+ * Default extension name for error messages.
39
+ */
40
+ readonly DEFAULT_EXTENSION_NAME: "VeltComments";
41
+ /**
42
+ * Default editor ID used when no editor ID is provided.
43
+ * Uses '__default__' to avoid collision with user-provided values.
44
+ */
45
+ readonly DEFAULT_EDITOR_ID: "__default__";
46
+ /**
47
+ * Terminal status type for resolved/closed comments.
48
+ */
49
+ readonly STATUS_TERMINAL: "terminal";
50
+ /**
51
+ * Log prefix for console messages.
52
+ */
53
+ readonly LOG_PREFIX: "PlateVeltComments: ";
54
+ /**
55
+ * Session storage key for debug mode.
56
+ */
57
+ readonly DEBUG_MODE_KEY: "debugMode";
58
+ /**
59
+ * Session storage key for forced debug mode.
60
+ */
61
+ readonly FORCE_DEBUG_MODE_KEY: "forceDebugMode";
62
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * React component for rendering Velt comment elements in Plate 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 PlateVeltComment: (props: Omit<RenderElementProps, "element"> & {
12
+ element: VeltCommentsElement;
13
+ }) => React.ReactElement;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Core extension module for Plate.js.
3
+ * This module creates the Plate plugin that wires everything together.
4
+ *
5
+ * Responsibilities:
6
+ * - Create plugin using Plate's createPlatePlugin
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 Plate types (it's the extension entry point)
13
+ * - It delegates to features and adapters for actual work
14
+ *
15
+ * KEY DIFFERENCE FROM SLATE:
16
+ * - Slate uses HOC pattern: withVeltComments(editor)
17
+ * - Plate uses plugin pattern: createPlatePlugin({ key, node, handlers })
18
+ */
19
+ import type { VeltCommentsPluginConfig } from '@/types/host';
20
+ /**
21
+ * VeltCommentsPlugin - Plate.js plugin for Velt Comments integration.
22
+ *
23
+ * This is the main entry point that enhances the editor with comment functionality.
24
+ * It creates an inline element type for comment highlighting and sets up
25
+ * change detection for updating comment positions.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { usePlateEditor } from '@platejs/core/react';
30
+ * import { VeltCommentsPlugin } from '@veltdev/plate-comments-react';
31
+ *
32
+ * const editor = usePlateEditor({
33
+ * plugins: [VeltCommentsPlugin],
34
+ * });
35
+ *
36
+ * // With configuration
37
+ * const editor = usePlateEditor({
38
+ * plugins: [
39
+ * VeltCommentsPlugin.configure({
40
+ * options: { editorId: 'my-editor' }
41
+ * })
42
+ * ],
43
+ * });
44
+ * ```
45
+ */
46
+ export declare const VeltCommentsPlugin: any;
47
+ /**
48
+ * Export plugin configuration type for external use.
49
+ */
50
+ export type { VeltCommentsPluginConfig };
@@ -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 plugin 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;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Update content feature module.
3
+ *
4
+ * Handles document content changes and updates annotation positions.
5
+ * Called when text changes are detected in the editor.
6
+ *
7
+ * Dependencies:
8
+ * - adapters/host/doc.ts (document operations)
9
+ * - adapters/velt.ts (Velt SDK operations)
10
+ * - core/state.ts (state management)
11
+ */
12
+ /**
13
+ * Handles content updates in the editor.
14
+ * Detects changes to annotations and updates their positions/contexts.
15
+ *
16
+ * @param editorId The editor ID
17
+ * @param editor The editor instance
18
+ * @param transaction The transaction/operation that triggered the update
19
+ */
20
+ export declare const handleContentUpdate: (editorId: string, editor: unknown, transaction: unknown) => void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Public API for Plate-Velt Comments integration.
3
+ *
4
+ * This module exports the public API for the Plate.js Velt Comments extension.
5
+ * All internal imports use path aliases (@/) for clean dependency management.
6
+ *
7
+ * @module PlateVeltComments
8
+ */
9
+ export { VeltCommentsPlugin } from '@/core/extension';
10
+ export type { VeltCommentsPluginConfig } from '@/core/extension';
11
+ export { addComment } from '@/features/addComment';
12
+ export { renderComments, cleanupRenderComments } from '@/features/renderComments';
13
+ export { exportJSONWithoutComments } from '@/utils/serializer';
14
+ export { PlateVeltComment } from '@/core/ExtensionComponent';
15
+ export type { AddCommentRequest, CommentAnnotationContext, RenderCommentsRequest } from '@/types/common';
16
+ export type { VeltCommentsEditor, VeltCommentsElement } from '@/types/host';
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Common type definitions shared across the entire codebase.
3
+ * These types are SDK-agnostic and represent domain concepts.
4
+ */
5
+ import type { CommentAnnotation } from '@/types/velt';
6
+ /**
7
+ * Context object for comment annotations.
8
+ * Contains text editor configuration and any additional context data.
9
+ */
10
+ export interface CommentAnnotationContext {
11
+ textEditorConfig?: {
12
+ text: string;
13
+ occurrence: number;
14
+ editorId?: string;
15
+ targetTextNodeId?: string;
16
+ };
17
+ [key: string]: unknown;
18
+ }
19
+ /**
20
+ * Request interface for addComment function.
21
+ * Matches legacy AddCommentRequest interface.
22
+ */
23
+ export interface AddCommentRequest {
24
+ editorId?: string;
25
+ editor: unknown;
26
+ context?: unknown;
27
+ }
28
+ /**
29
+ * Request interface for renderComments function.
30
+ * Matches legacy RenderCommentsRequest interface.
31
+ */
32
+ export interface RenderCommentsRequest {
33
+ editor: unknown;
34
+ editorId?: string;
35
+ commentAnnotations?: CommentAnnotation[];
36
+ }
37
+ /**
38
+ * Extension configuration for registry.
39
+ */
40
+ export interface ExtensionConfig {
41
+ persistVeltMarks?: boolean;
42
+ editorId?: string;
43
+ HistoryEditor?: unknown;
44
+ [key: string]: unknown;
45
+ }
46
+ /**
47
+ * Editor context containing editor instance and related state.
48
+ * Note: Editor type is generic to avoid importing editor types here.
49
+ */
50
+ export interface EditorContext<TEditor = unknown> {
51
+ editorId: string;
52
+ editor: TEditor;
53
+ config: ExtensionConfig;
54
+ }