@veltdev/lexical-velt-comments 4.5.2-beta.2 → 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.
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/types/src/adapters/host/doc.d.ts +97 -0
- package/cjs/types/src/adapters/host/marks.d.ts +89 -0
- package/cjs/types/src/adapters/host/storage.d.ts +37 -0
- package/cjs/types/src/adapters/velt.d.ts +55 -0
- package/cjs/types/src/constants/common.d.ts +67 -0
- package/cjs/types/src/core/extension.d.ts +40 -0
- package/cjs/types/src/core/registry.d.ts +71 -0
- package/cjs/types/src/core/state.d.ts +86 -0
- package/cjs/types/src/features/addComment.d.ts +63 -0
- package/cjs/types/src/features/commentRenderer.d.ts +46 -0
- package/cjs/types/src/features/renderComments.d.ts +73 -0
- package/cjs/types/src/features/updateContent.d.ts +32 -0
- package/cjs/types/src/index.d.ts +26 -0
- package/cjs/types/src/types/common.d.ts +72 -0
- package/cjs/types/src/types/host.d.ts +65 -0
- package/cjs/types/src/types/state.d.ts +28 -0
- package/cjs/types/src/types/velt.d.ts +6 -0
- package/cjs/types/src/utils/common.d.ts +56 -0
- package/cjs/types/src/utils/console.d.ts +37 -0
- package/cjs/types/src/utils/host.d.ts +44 -0
- package/cjs/types/src/utils/serializer.d.ts +19 -0
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/types/src/adapters/host/doc.d.ts +97 -0
- package/esm/types/src/adapters/host/marks.d.ts +89 -0
- package/esm/types/src/adapters/host/storage.d.ts +37 -0
- package/esm/types/src/adapters/velt.d.ts +55 -0
- package/esm/types/src/constants/common.d.ts +67 -0
- package/esm/types/src/core/extension.d.ts +40 -0
- package/esm/types/src/core/registry.d.ts +71 -0
- package/esm/types/src/core/state.d.ts +86 -0
- package/esm/types/src/features/addComment.d.ts +63 -0
- package/esm/types/src/features/commentRenderer.d.ts +46 -0
- package/esm/types/src/features/renderComments.d.ts +73 -0
- package/esm/types/src/features/updateContent.d.ts +32 -0
- package/esm/types/src/index.d.ts +26 -0
- package/esm/types/src/types/common.d.ts +72 -0
- package/esm/types/src/types/host.d.ts +65 -0
- package/esm/types/src/types/state.d.ts +28 -0
- package/esm/types/src/types/velt.d.ts +6 -0
- package/esm/types/src/utils/common.d.ts +56 -0
- package/esm/types/src/utils/console.d.ts +37 -0
- package/esm/types/src/utils/host.d.ts +44 -0
- package/esm/types/src/utils/serializer.d.ts +19 -0
- package/index.d.ts +275 -26
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -0
- package/cjs/types/comment-node.d.ts +0 -23
- package/cjs/types/constants.d.ts +0 -6
- package/cjs/types/editor.d.ts +0 -166
- package/cjs/types/index.d.ts +0 -24
- package/cjs/types/plugin.d.ts +0 -14
- package/cjs/types/serializer.d.ts +0 -5
- package/cjs/types/store.d.ts +0 -39
- package/cjs/types/types.d.ts +0 -40
- package/cjs/types/utility.d.ts +0 -122
- package/cjs/types/velt.d.ts +0 -21
- package/esm/types/comment-node.d.ts +0 -23
- package/esm/types/constants.d.ts +0 -6
- package/esm/types/editor.d.ts +0 -166
- package/esm/types/index.d.ts +0 -24
- package/esm/types/plugin.d.ts +0 -14
- package/esm/types/serializer.d.ts +0 -5
- package/esm/types/store.d.ts +0 -39
- package/esm/types/types.d.ts +0 -40
- package/esm/types/utility.d.ts +0 -122
- package/esm/types/velt.d.ts +0 -21
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexical document adapter
|
|
3
|
+
*
|
|
4
|
+
* This module bridges Lexical's document model with the core system's needs.
|
|
5
|
+
* It handles selection extraction, occurrence finding, and document change tracking.
|
|
6
|
+
*
|
|
7
|
+
* CRITICAL: This is ONE of ONLY TWO places where Lexical types may be imported.
|
|
8
|
+
* The other is types/host.ts.
|
|
9
|
+
*
|
|
10
|
+
* Migrated from src/editor.ts EditorService selection and occurrence logic.
|
|
11
|
+
*/
|
|
12
|
+
import { type LexicalEditor } from 'lexical';
|
|
13
|
+
import type { AnnotationChange, DocumentChangeEvent, OccurrenceMatch, SelectionContext } from '@/types/host';
|
|
14
|
+
import type { AnnotationData } from '@/types/state';
|
|
15
|
+
/**
|
|
16
|
+
* Get current selection context from editor
|
|
17
|
+
*
|
|
18
|
+
* @param editor - Lexical editor instance
|
|
19
|
+
* @returns SelectionContext with text and position info, or null if no selection
|
|
20
|
+
*/
|
|
21
|
+
export declare const getCurrentSelectionContext: (editor: LexicalEditor) => SelectionContext | null;
|
|
22
|
+
/**
|
|
23
|
+
* Find all occurrences of text in document (by text only)
|
|
24
|
+
* Helper function that doesn't require full SelectionContext
|
|
25
|
+
*
|
|
26
|
+
* @param editor - Lexical editor instance
|
|
27
|
+
* @param text - Text to search for
|
|
28
|
+
* @returns Array of occurrence matches
|
|
29
|
+
*/
|
|
30
|
+
export declare const findOccurrencesByText: (editor: LexicalEditor, text: string) => OccurrenceMatch[];
|
|
31
|
+
/**
|
|
32
|
+
* Find all occurrences of selected text in document
|
|
33
|
+
*
|
|
34
|
+
* @param editor - Lexical editor instance
|
|
35
|
+
* @param context - Selection context to find occurrences for
|
|
36
|
+
* @returns Array of occurrence matches
|
|
37
|
+
*/
|
|
38
|
+
export declare const findOccurrences: (editor: LexicalEditor, context: SelectionContext) => OccurrenceMatch[];
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to document changes
|
|
41
|
+
*
|
|
42
|
+
* @param editor - Lexical editor instance
|
|
43
|
+
* @param callback - Function called when document changes
|
|
44
|
+
* @returns Unsubscribe function
|
|
45
|
+
*/
|
|
46
|
+
export declare const subscribeToDocumentChanges: (editor: LexicalEditor, callback: (event: DocumentChangeEvent) => void) => (() => void);
|
|
47
|
+
/**
|
|
48
|
+
* Get document text content
|
|
49
|
+
*
|
|
50
|
+
* @param editor - Lexical editor instance
|
|
51
|
+
* @returns Full document text
|
|
52
|
+
*/
|
|
53
|
+
export declare const getDocumentText: (editor: LexicalEditor) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Map position through document changes
|
|
56
|
+
*
|
|
57
|
+
* @param oldPos - Original position
|
|
58
|
+
* @param changes - Document change event
|
|
59
|
+
* @returns New position or null if position no longer exists
|
|
60
|
+
*/
|
|
61
|
+
export declare const mapPositionThroughChanges: (oldPos: number, changes: DocumentChangeEvent) => number | null;
|
|
62
|
+
/**
|
|
63
|
+
* Get editor ID from Lexical editor instance
|
|
64
|
+
*
|
|
65
|
+
* Checks editor config namespace first, then falls back to DOM attributes.
|
|
66
|
+
*
|
|
67
|
+
* @param editor - Lexical editor instance
|
|
68
|
+
* @returns Editor ID string or null if not found
|
|
69
|
+
*/
|
|
70
|
+
export declare const getEditorId: (editor: LexicalEditor) => string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Resets the editor selection by focusing the editor.
|
|
73
|
+
* Uses Lexical's focus API to reset selection/focus after comment operations.
|
|
74
|
+
*
|
|
75
|
+
* @param editor The editor instance (typed as unknown to avoid importing editor types in feature modules)
|
|
76
|
+
* @returns void
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* - This function abstracts editor-specific selection reset logic
|
|
80
|
+
* - For Lexical, uses the focus API: `editor.focus()`
|
|
81
|
+
* - Fails silently if focus API is unavailable
|
|
82
|
+
*/
|
|
83
|
+
export declare const resetEditorSelection: (editor: unknown) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Detect document changes by collecting CommentNodes and analyzing them
|
|
86
|
+
* Similar to Tiptap's detectDocumentChanges and old Lexical's onTransaction logic
|
|
87
|
+
*
|
|
88
|
+
* @param editor - Lexical editor instance
|
|
89
|
+
* @param getAnnotationData - Function to get annotation data from state
|
|
90
|
+
* @returns Map of annotation ID to AnnotationChange
|
|
91
|
+
*/
|
|
92
|
+
export declare const detectDocumentChanges: (editor: LexicalEditor, getAnnotationData: (annotationId: string) => {
|
|
93
|
+
annotation: AnnotationData;
|
|
94
|
+
originalText: string;
|
|
95
|
+
originalOccurrence: number;
|
|
96
|
+
targetTextNodeId: string;
|
|
97
|
+
} | null) => Map<string, AnnotationChange>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexical comment marks adapter
|
|
3
|
+
*
|
|
4
|
+
* This module manages visual representation of annotations in the editor.
|
|
5
|
+
* It handles creating, updating, and removing CommentNodes (Lexical's equivalent of marks).
|
|
6
|
+
*
|
|
7
|
+
* CRITICAL: This is ONE of ONLY TWO places where Lexical types may be imported.
|
|
8
|
+
* The other is types/host.ts.
|
|
9
|
+
*
|
|
10
|
+
* Migrated from src/editor.ts EditorService comment node operations.
|
|
11
|
+
*/
|
|
12
|
+
import { ElementNode, type EditorConfig, type LexicalEditor, type LexicalNode, type NodeKey, type SerializedElementNode, type Spread } from 'lexical';
|
|
13
|
+
import { Constants } from '@/constants/common';
|
|
14
|
+
import type { AnnotationChange } from '@/types/host';
|
|
15
|
+
import type { AnnotationData } from '@/types/state';
|
|
16
|
+
/**
|
|
17
|
+
* CommentNode - Lexical node for representing comment annotations
|
|
18
|
+
* Migrated from src/comment-node.ts
|
|
19
|
+
*/
|
|
20
|
+
type SerializedCommentNode = Spread<{
|
|
21
|
+
annotationId?: string;
|
|
22
|
+
multiThreadAnnotationId?: string;
|
|
23
|
+
type: typeof Constants.NODE_TYPE;
|
|
24
|
+
version: 1;
|
|
25
|
+
}, SerializedElementNode>;
|
|
26
|
+
export declare class CommentNode extends ElementNode {
|
|
27
|
+
__annotationId?: string;
|
|
28
|
+
__multiThreadAnnotationId?: string;
|
|
29
|
+
static getType(): string;
|
|
30
|
+
static clone(node: CommentNode): CommentNode;
|
|
31
|
+
constructor(annotationId?: string, multiThreadAnnotationId?: string, key?: NodeKey);
|
|
32
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
33
|
+
updateDOM(_prevNode: CommentNode, _dom: HTMLElement, _config: EditorConfig): boolean;
|
|
34
|
+
static importJSON(serializedNode: SerializedCommentNode): CommentNode;
|
|
35
|
+
exportJSON(): SerializedCommentNode;
|
|
36
|
+
isInline(): boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare const $createCommentNode: (annotationId?: string, multiThreadAnnotationId?: string) => CommentNode;
|
|
39
|
+
export declare const $isCommentNode: (node: LexicalNode | null | undefined) => node is CommentNode;
|
|
40
|
+
/**
|
|
41
|
+
* Applies an annotation mark to the editor document at the specified position.
|
|
42
|
+
* This is a unified adapter function that matches TipTap's signature.
|
|
43
|
+
*
|
|
44
|
+
* @param editor The editor instance (typed as unknown to avoid importing editor types in feature modules)
|
|
45
|
+
* @param annotationId The annotation ID to mark
|
|
46
|
+
* @param multiThreadAnnotationId Optional multi-thread annotation ID
|
|
47
|
+
* @param from Start position of the mark
|
|
48
|
+
* @param to End position of the mark
|
|
49
|
+
* @returns True if mark was successfully applied, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
export declare const applyAnnotationMark: (editor: unknown, annotationId: string, multiThreadAnnotationId: string | undefined, from: number, to: number, occurrence?: number) => boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Apply comment marks (CommentNodes) for a set of annotations
|
|
54
|
+
*
|
|
55
|
+
* @param editor - Lexical editor instance
|
|
56
|
+
* @param annotations - Annotations to render as comment marks
|
|
57
|
+
*/
|
|
58
|
+
export declare const applyAnnotationMarks: (editor: LexicalEditor, annotations: AnnotationData[]) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Remove comment marks (CommentNodes) for specific annotation IDs
|
|
61
|
+
*
|
|
62
|
+
* @param editor - Lexical editor instance
|
|
63
|
+
* @param annotationIds - Array of annotation IDs to remove
|
|
64
|
+
*/
|
|
65
|
+
export declare const removeAnnotationMarks: (editor: LexicalEditor, annotationIds: string[]) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Update comment marks efficiently
|
|
68
|
+
* Uses diff-based updates to minimize DOM changes
|
|
69
|
+
*
|
|
70
|
+
* @param editor - Lexical editor instance
|
|
71
|
+
* @param annotations - Updated annotations
|
|
72
|
+
*/
|
|
73
|
+
export declare const updateAnnotationMarks: (editor: LexicalEditor, annotations: AnnotationData[]) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Clear all annotation comment marks from editor
|
|
76
|
+
*
|
|
77
|
+
* @param editor - Lexical editor instance
|
|
78
|
+
*/
|
|
79
|
+
export declare const clearAllAnnotationMarks: (editor: LexicalEditor) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Updates marks based on annotation changes.
|
|
82
|
+
* Currently a no-op: mark updates are handled through applyAnnotationMarks
|
|
83
|
+
* called from handleContentUpdate after state is updated.
|
|
84
|
+
*
|
|
85
|
+
* @param editor The Lexical editor instance
|
|
86
|
+
* @param changes Map of annotation ID to AnnotationChange
|
|
87
|
+
*/
|
|
88
|
+
export declare const updateMarks: (editor: LexicalEditor, changes: Map<string, AnnotationChange>) => void;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
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 Lexical, always returns true - marks are always applied)
|
|
9
|
+
* - Determine if marks should be applied
|
|
10
|
+
*
|
|
11
|
+
* Dependencies:
|
|
12
|
+
* - lexical (ONLY place allowed to import LexicalEditor types for storage access)
|
|
13
|
+
*/
|
|
14
|
+
import type { LexicalEditor } from 'lexical';
|
|
15
|
+
/**
|
|
16
|
+
* Gets persistVeltMarks setting from storage.
|
|
17
|
+
* For Lexical, marks are always applied, so this always returns true.
|
|
18
|
+
*
|
|
19
|
+
* @param editor The editor instance
|
|
20
|
+
* @param storageKey The storage key (unused for Lexical, kept for API compatibility)
|
|
21
|
+
* @returns persistVeltMarks boolean value (always true for Lexical)
|
|
22
|
+
*/
|
|
23
|
+
export declare const getPersistVeltMarks: (editor: LexicalEditor, 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: 'lexicalVeltComments')
|
|
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
|
+
* - Defaults to true if storage is unavailable
|
|
36
|
+
*/
|
|
37
|
+
export declare const shouldApplyMark: (editor: unknown, storageKey?: string) => boolean;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Velt SDK adapter.
|
|
3
|
+
*
|
|
4
|
+
* Purpose: High-level Velt SDK wrapper with comprehensive error handling.
|
|
5
|
+
* This is the ONLY place where @veltdev/types and window.Velt may be accessed.
|
|
6
|
+
*
|
|
7
|
+
* Key responsibilities:
|
|
8
|
+
* - Wrap all Velt SDK calls with error handling
|
|
9
|
+
* - Provide clean interface for features layer
|
|
10
|
+
* - Handle SDK unavailability gracefully
|
|
11
|
+
* - Manage subscriptions to Velt events
|
|
12
|
+
*
|
|
13
|
+
* Dependencies:
|
|
14
|
+
* - @veltdev/types (ONLY place allowed to import Velt types)
|
|
15
|
+
* - types/common.ts (for CommentAnnotationContext)
|
|
16
|
+
* - types/velt.ts (for re-exported Velt types)
|
|
17
|
+
*/
|
|
18
|
+
import type { CommentElement, CommentAnnotation, Location } from '@veltdev/types';
|
|
19
|
+
import type { CommentAnnotationContext } from '@/types/common';
|
|
20
|
+
/**
|
|
21
|
+
* Gets the Velt comment element from the SDK.
|
|
22
|
+
* Returns null if SDK is unavailable or comment element cannot be accessed.
|
|
23
|
+
*
|
|
24
|
+
* @returns CommentElement or null if unavailable
|
|
25
|
+
*/
|
|
26
|
+
export declare const getCommentElement: () => CommentElement | null;
|
|
27
|
+
/**
|
|
28
|
+
* Adds a comment via the Velt SDK.
|
|
29
|
+
*
|
|
30
|
+
* @param params Object containing context and optional location
|
|
31
|
+
* @returns Promise resolving to CommentAnnotation or null if failed
|
|
32
|
+
*/
|
|
33
|
+
export declare const addVeltComment: (params: {
|
|
34
|
+
context: CommentAnnotationContext;
|
|
35
|
+
location?: Location;
|
|
36
|
+
}) => Promise<{
|
|
37
|
+
annotation: CommentAnnotation | null;
|
|
38
|
+
result: unknown;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Updates the context of an existing annotation in the Velt SDK.
|
|
42
|
+
*
|
|
43
|
+
* @param annotationId The annotation ID to update
|
|
44
|
+
* @param context The new context to set
|
|
45
|
+
*/
|
|
46
|
+
export declare const updateAnnotationContext: (annotationId: string, context: CommentAnnotationContext) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Subscribes to changes in selected annotations from the Velt SDK.
|
|
49
|
+
* Returns an unsubscribe function.
|
|
50
|
+
*
|
|
51
|
+
* @param callback Function called when selected annotations change
|
|
52
|
+
* @param subscriberId Optional unique ID for this subscriber
|
|
53
|
+
* @returns Unsubscribe function
|
|
54
|
+
*/
|
|
55
|
+
export declare const subscribeToSelectedAnnotations: (callback: (selectedIds: Set<string>) => void, subscriberId?: string) => (() => void);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared constants for Lexical-Velt Comments integration
|
|
3
|
+
*
|
|
4
|
+
* This module contains all magic strings and configuration constants
|
|
5
|
+
* used across the application. Migrated from src/constants.ts
|
|
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
|
+
* Mark/extension name constant.
|
|
19
|
+
* Generic constant name, value is Lexical-specific for this package.
|
|
20
|
+
*/
|
|
21
|
+
readonly MARK_NAME: "lexicalVeltComments";
|
|
22
|
+
/**
|
|
23
|
+
* Storage key constant.
|
|
24
|
+
* Generic constant name, value is Lexical-specific for this package.
|
|
25
|
+
*/
|
|
26
|
+
readonly STORAGE_KEY: "lexicalVeltComments";
|
|
27
|
+
/**
|
|
28
|
+
* Custom element tag name for comment nodes.
|
|
29
|
+
* CRITICAL: Must be 'velt-comment-text' to match Tiptap/Lexical/Slate implementations.
|
|
30
|
+
*/
|
|
31
|
+
readonly TAG_NAME: "velt-comment-text";
|
|
32
|
+
/**
|
|
33
|
+
* Default extension name for error messages.
|
|
34
|
+
*/
|
|
35
|
+
readonly DEFAULT_EXTENSION_NAME: "VeltComments";
|
|
36
|
+
/**
|
|
37
|
+
* Lexical node type name for comment nodes.
|
|
38
|
+
* Lexical-specific constant for CommentNode type.
|
|
39
|
+
*/
|
|
40
|
+
readonly NODE_TYPE: "comment";
|
|
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: "LexicalVeltComments: ";
|
|
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
|
+
/**
|
|
63
|
+
* Block-level node types in Lexical that should have newline breaks after them.
|
|
64
|
+
* Used for text content collection and block boundary detection.
|
|
65
|
+
*/
|
|
66
|
+
readonly BLOCK_TYPES: readonly ["paragraph", "heading", "listitem", "quote", "code"];
|
|
67
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core extension module.
|
|
3
|
+
*
|
|
4
|
+
* Purpose: Manages document change listeners and editor setup for Lexical editors.
|
|
5
|
+
* This module handles the lifecycle of document change subscriptions.
|
|
6
|
+
*
|
|
7
|
+
* Key responsibilities:
|
|
8
|
+
* - Set up document change listeners for editors
|
|
9
|
+
* - Wire up document change handler to updateContent feature
|
|
10
|
+
* - Manage document change listener lifecycle
|
|
11
|
+
* - Orchestrate editor setup (registration + listeners)
|
|
12
|
+
*
|
|
13
|
+
* Dependencies: adapters/host/doc.ts, features/updateContent.ts, core/registry.ts
|
|
14
|
+
*/
|
|
15
|
+
import type { LexicalEditor } from 'lexical';
|
|
16
|
+
/**
|
|
17
|
+
* Ensures document change listeners are set up for an editor.
|
|
18
|
+
* This is called by lazy registration (addComment/renderComments) to ensure content updates work.
|
|
19
|
+
*
|
|
20
|
+
* @param editorId Editor identifier
|
|
21
|
+
* @param editor Lexical editor instance
|
|
22
|
+
* @returns true if listeners were set up (or already existed), false if setup failed
|
|
23
|
+
*/
|
|
24
|
+
export declare const ensureDocumentChangeListeners: (editorId: string, editor: LexicalEditor) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Ensures editor is set up (registered and document listeners configured).
|
|
27
|
+
* This is a unified orchestration function that handles both registration and setup.
|
|
28
|
+
*
|
|
29
|
+
* @param editorId Optional editor ID (will be resolved from editor if not provided)
|
|
30
|
+
* @param editor The editor instance (typed as unknown to avoid importing editor types in feature modules)
|
|
31
|
+
* @returns Object with editorId string
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* - This function abstracts editor-specific setup logic
|
|
35
|
+
* - For Lexical, ensures editor is registered and document change listeners are set up
|
|
36
|
+
* - Fails silently if setup fails
|
|
37
|
+
*/
|
|
38
|
+
export declare const ensureEditorSetup: (editorId: string | undefined, editor: unknown) => {
|
|
39
|
+
editorId: string;
|
|
40
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
* CRITICAL: This module must NOT import Lexical or Velt types directly.
|
|
14
|
+
* It uses adapter interfaces from types/* instead.
|
|
15
|
+
*
|
|
16
|
+
* CRITICAL: This module is PURE registry logic - no document change listeners,
|
|
17
|
+
* no feature imports, no adapter imports. Document change handling belongs in extension.ts.
|
|
18
|
+
*
|
|
19
|
+
* Dependencies: types/common.ts, core/state.ts, adapters/host/doc.ts
|
|
20
|
+
*/
|
|
21
|
+
import type { EditorContext, ExtensionConfig } from '@/types/common';
|
|
22
|
+
/**
|
|
23
|
+
* Registers an editor instance in the registry.
|
|
24
|
+
* Creates initial state for the editor.
|
|
25
|
+
*
|
|
26
|
+
* @param editorId Unique identifier for the editor
|
|
27
|
+
* @param editor The editor instance
|
|
28
|
+
* @param config Extension configuration options
|
|
29
|
+
* @returns EditorContext for the registered editor
|
|
30
|
+
*/
|
|
31
|
+
export declare const registerEditor: <TEditor = unknown>(editorId: string, editor: TEditor, config?: ExtensionConfig) => EditorContext<TEditor>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the editor context for a given editor ID.
|
|
34
|
+
*
|
|
35
|
+
* @param editorId Unique identifier for the editor
|
|
36
|
+
* @returns EditorContext or null if not found
|
|
37
|
+
*/
|
|
38
|
+
export declare const getEditorContext: <TEditor = unknown>(editorId: string) => EditorContext<TEditor> | null;
|
|
39
|
+
/**
|
|
40
|
+
* Unregisters an editor from the registry and cleans up its state.
|
|
41
|
+
*
|
|
42
|
+
* @param editorId Unique identifier for the editor
|
|
43
|
+
*/
|
|
44
|
+
export declare const unregisterEditor: (editorId: string) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Ensures an editor is registered (lazy registration helper).
|
|
47
|
+
* Gets existing registration if available, creates new if not found.
|
|
48
|
+
*
|
|
49
|
+
* NOTE: This does NOT set up document change listeners - that belongs in extension.ts.
|
|
50
|
+
* This is pure registry logic only.
|
|
51
|
+
*
|
|
52
|
+
* @param editorId Editor identifier (optional, will be resolved from editor if not provided)
|
|
53
|
+
* @param editor Editor instance
|
|
54
|
+
* @param config Optional configuration
|
|
55
|
+
* @returns EditorContext
|
|
56
|
+
*/
|
|
57
|
+
export declare const ensureEditorRegistered: <TEditor = unknown>(editorId: string | undefined, editor: TEditor, config?: ExtensionConfig) => EditorContext<TEditor>;
|
|
58
|
+
/**
|
|
59
|
+
* Extracts the editor ID from an editor instance.
|
|
60
|
+
* Checks editor storage first, then DOM attributes.
|
|
61
|
+
*
|
|
62
|
+
* @param editor The editor instance
|
|
63
|
+
* @returns Editor ID or null if not found
|
|
64
|
+
*/
|
|
65
|
+
export declare const getEditorIdFromEditor: (editor: unknown) => string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Gets all registered editor IDs.
|
|
68
|
+
*
|
|
69
|
+
* @returns Array of editor IDs
|
|
70
|
+
*/
|
|
71
|
+
export declare const getAllEditorIds: () => string[];
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
* CRITICAL: This module must NOT import Lexical or Velt types.
|
|
14
|
+
* It only depends on types/*, constants/*, and utils/*.
|
|
15
|
+
*/
|
|
16
|
+
import type { AnnotationData, AnnotationState } from '@/types/state';
|
|
17
|
+
import type { CommentAnnotation } from '@/types/velt';
|
|
18
|
+
/**
|
|
19
|
+
* Create a new annotation state for an editor
|
|
20
|
+
*
|
|
21
|
+
* @param editorId - Unique identifier for the editor instance
|
|
22
|
+
* @returns New AnnotationState instance
|
|
23
|
+
*/
|
|
24
|
+
export declare const createAnnotationState: (editorId: string) => AnnotationState;
|
|
25
|
+
/**
|
|
26
|
+
* Updates annotations in state from Velt SDK data.
|
|
27
|
+
* Converts CommentAnnotation[] to AnnotationData[] and stores them.
|
|
28
|
+
*
|
|
29
|
+
* This matches Tiptap's pattern where conversion happens in updateAnnotations,
|
|
30
|
+
* not in the feature module (renderComments).
|
|
31
|
+
*
|
|
32
|
+
* @param editorId Unique identifier for the editor
|
|
33
|
+
* @param annotations Array of CommentAnnotation from Velt SDK
|
|
34
|
+
*/
|
|
35
|
+
export declare const updateAnnotations: (editorId: string, annotations: CommentAnnotation[]) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Gets all annotations for an editor.
|
|
38
|
+
*
|
|
39
|
+
* @param editorId Unique identifier for the editor
|
|
40
|
+
* @returns Map of annotation ID to AnnotationData
|
|
41
|
+
*/
|
|
42
|
+
export declare const getAllAnnotations: (editorId: string) => Map<string, AnnotationData>;
|
|
43
|
+
/**
|
|
44
|
+
* Get a specific annotation by ID
|
|
45
|
+
*
|
|
46
|
+
* @param editorId - Editor identifier
|
|
47
|
+
* @param annotationId - Annotation ID
|
|
48
|
+
* @returns Annotation or null if not found
|
|
49
|
+
*/
|
|
50
|
+
export declare const getAnnotation: (editorId: string, annotationId: string) => AnnotationData | null;
|
|
51
|
+
/**
|
|
52
|
+
* Remove a specific annotation
|
|
53
|
+
*
|
|
54
|
+
* @param editorId - Editor identifier
|
|
55
|
+
* @param annotationId - Annotation ID to remove
|
|
56
|
+
*/
|
|
57
|
+
export declare const removeAnnotation: (editorId: string, annotationId: string) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Clears all state for an editor (used during cleanup).
|
|
60
|
+
* Matches Tiptap's clearState function signature.
|
|
61
|
+
*
|
|
62
|
+
* @param editorId Unique identifier for the editor
|
|
63
|
+
*/
|
|
64
|
+
export declare const clearState: (editorId: string) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the set of selected annotation IDs for an editor.
|
|
67
|
+
*
|
|
68
|
+
* @param editorId - Unique identifier for the editor
|
|
69
|
+
* @returns Set of selected annotation IDs
|
|
70
|
+
*/
|
|
71
|
+
export declare const getSelectedAnnotations: (editorId: string) => Set<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Updates the set of selected annotation IDs for an editor.
|
|
74
|
+
*
|
|
75
|
+
* @param editorId - Unique identifier for the editor
|
|
76
|
+
* @param selectedIds - Set of selected annotation IDs
|
|
77
|
+
*/
|
|
78
|
+
export declare const setSelectedAnnotations: (editorId: string, selectedIds: Set<string>) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Get all comment annotations (with status) for an editor.
|
|
81
|
+
* Returns the full CommentAnnotation[] array stored in state.
|
|
82
|
+
*
|
|
83
|
+
* @param editorId Unique identifier for the editor
|
|
84
|
+
* @returns Array of CommentAnnotation with status field, or empty array if none
|
|
85
|
+
*/
|
|
86
|
+
export declare const getCommentAnnotations: (editorId: string) => CommentAnnotation[];
|
|
@@ -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/marks.ts (for applying/removing marks)
|
|
16
|
+
* - types/velt.ts (for CommentAnnotation)
|
|
17
|
+
* - types/state.ts (for AnnotationData)
|
|
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;
|