@veltdev/slate-velt-comments-staging 1.0.4 → 1.0.5

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
package/index.d.ts CHANGED
@@ -1,57 +1,291 @@
1
+ import { Editor, Descendant } from 'slate';
1
2
  import { CommentAnnotation } from '@veltdev/types';
2
- import { Descendant, Editor } from 'slate';
3
3
  import React from 'react';
4
4
  import { RenderElementProps } from 'slate-react';
5
5
 
6
- type VeltCommentsElement = {
7
- type: 'veltComment';
8
- children: Descendant[];
9
- annotationId?: string;
10
- };
11
- type CommentAnnotationContext = {
6
+ /**
7
+ * Common type definitions shared across the entire codebase.
8
+ * These types are SDK-agnostic and represent domain concepts.
9
+ */
10
+
11
+ /**
12
+ * Context object for comment annotations.
13
+ * Contains text editor configuration and any additional context data.
14
+ */
15
+ interface CommentAnnotationContext {
12
16
  textEditorConfig?: {
13
17
  text: string;
14
18
  occurrence: number;
15
19
  editorId?: string;
16
20
  targetTextNodeId?: string;
17
21
  };
18
- } & Record<string, unknown>;
19
-
20
- declare const SlateVeltComment: (props: Omit<RenderElementProps, "element"> & {
21
- element: VeltCommentsElement;
22
- }) => React.JSX.Element;
23
-
24
- interface VeltCommentsEditor extends Editor {
25
- }
26
- interface VeltCommentsEditorOptions {
27
- HistoryEditor?: any;
28
- }
29
- declare const withVeltComments: <T extends Editor>(editor: T, options?: VeltCommentsEditorOptions) => T & VeltCommentsEditor;
30
- interface VeltCommentConfig {
31
- context?: unknown;
22
+ [key: string]: unknown;
32
23
  }
33
- declare const triggerAddComment: (editor: Editor, config?: VeltCommentConfig) => Promise<void>;
24
+ /**
25
+ * Request interface for addComment function.
26
+ * Matches legacy AddCommentRequest interface.
27
+ */
34
28
  interface AddCommentRequest {
35
29
  editorId?: string;
36
- editor: Editor;
30
+ editor: unknown;
37
31
  context?: unknown;
38
32
  }
39
33
  /**
40
- * Creates a comment annotation for the currently selected text in the editor
41
- * This function handles the entire flow from getting the selected text to creating
42
- * the actual comment through the Velt service
34
+ * Request interface for renderComments function.
35
+ * Matches legacy RenderCommentsRequest interface.
43
36
  */
44
- declare const addComment: ({ editorId, editor, context: clientContext, }: AddCommentRequest) => Promise<void>;
45
- declare function highlightComments(editor: Editor, commentAnnotations: CommentAnnotation[], editorId?: string): void;
46
37
  interface RenderCommentsRequest {
47
- editor: Editor;
38
+ editor: unknown;
48
39
  editorId?: string;
49
40
  commentAnnotations?: CommentAnnotation[];
50
41
  }
51
- declare const renderComments: ({ editor, editorId, commentAnnotations }: RenderCommentsRequest) => void;
52
- declare const onSlateValueChange: ({ editor, editorId, }: {
53
- editor: Editor;
42
+ /**
43
+ * Extension configuration for registry.
44
+ */
45
+ interface ExtensionConfig {
46
+ persistVeltMarks?: boolean;
54
47
  editorId?: string;
55
- }) => void;
48
+ HistoryEditor?: unknown;
49
+ [key: string]: unknown;
50
+ }
51
+
52
+ /**
53
+ * Core extension module.
54
+ * This module creates the editor extension that wires everything together.
55
+ *
56
+ * Responsibilities:
57
+ * - Create extension factory function
58
+ * - Wire features into editor lifecycle hooks
59
+ * - Register editor in registry
60
+ * - Handle cleanup on editor destruction
61
+ *
62
+ * Architectural Rules:
63
+ * - This module MAY import editor types (it's the extension entry point)
64
+ * - It delegates to features and adapters for actual work
65
+ */
66
+
67
+ /**
68
+ * Extension configuration interface.
69
+ * Matches legacy VeltCommentsEditorOptions.
70
+ */
71
+ interface VeltCommentsExtensionConfig extends ExtensionConfig {
72
+ HistoryEditor?: unknown;
73
+ }
74
+ /**
75
+ * Wraps the editor with Velt Comments functionality.
76
+ *
77
+ * This is the main entry point that enhances the editor with comment functionality.
78
+ * It enhances the editor by:
79
+ * - Overriding isInline and isVoid methods to handle comment elements
80
+ * - Setting up onChange handler to detect and process document changes
81
+ * - Registering the editor in the registry for state management
82
+ *
83
+ * @param editor - The Slate editor instance to enhance
84
+ * @param config - Optional extension configuration including HistoryEditor and editorId
85
+ * @returns Enhanced editor with Velt comments functionality
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Standard Slate plugin pattern
90
+ * const editor = withVeltComments(withReact(createEditor()));
91
+ *
92
+ * // With configuration
93
+ * const editor = withVeltComments(withReact(createEditor()), {
94
+ * HistoryEditor: myHistoryEditor,
95
+ * editorId: 'my-editor'
96
+ * });
97
+ * ```
98
+ *
99
+ * @remarks
100
+ * - Follows standard Slate plugin pattern (like withReact, withHistory)
101
+ * - Only processes text-related operations to avoid unnecessary updates
102
+ * - Registers editor with default editorId if not provided
103
+ */
104
+ declare const withVeltComments: <T extends Editor>(editor: T, config?: VeltCommentsExtensionConfig) => T;
105
+
106
+ /**
107
+ * Add comment feature module.
108
+ *
109
+ * Purpose: End-to-end add comment orchestration.
110
+ * Orchestrates adapters and core to implement the add comment flow.
111
+ *
112
+ * Key responsibilities:
113
+ * - Get Velt comment element
114
+ * - Extract selection context from editor
115
+ * - Create comment via Velt SDK
116
+ * - Apply mark to editor document
117
+ * - Update state with annotation data
118
+ *
119
+ * Dependencies:
120
+ * - adapters/velt.ts (for Velt SDK calls)
121
+ * - adapters/host/doc.ts (for selection extraction, editor setup, and selection reset)
122
+ * - adapters/host/marks.ts (for mark application)
123
+ * - adapters/host/storage.ts (for mark application configuration)
124
+ * - core/state.ts (for state updates)
125
+ * - types/common.ts (for CommentAnnotationContext)
126
+ *
127
+ * IMPORTANT: This module MUST NOT import editor or Velt types directly.
128
+ * All SDK access goes through adapters.
129
+ */
130
+
131
+ /**
132
+ * Adds a comment to the currently selected text in the editor.
133
+ *
134
+ * This is the main entry point for adding comments. It handles:
135
+ * - Extracting selection context from the editor
136
+ * - Creating the comment via Velt SDK
137
+ * - Applying marks to the editor if configured
138
+ * - Updating state with annotation data
139
+ *
140
+ * @param request - Object containing editorId (optional), editor, and context (optional)
141
+ * @returns Promise that resolves when the comment is added (or fails silently)
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * // Simple usage
146
+ * await addComment({ editor });
147
+ *
148
+ * // With editor ID
149
+ * await addComment({ editorId: 'my-editor', editor });
150
+ *
151
+ * // With custom context
152
+ * await addComment({
153
+ * editorId: 'my-editor',
154
+ * editor,
155
+ * context: {
156
+ * userId: 'user123',
157
+ * metadata: { source: 'web-app' }
158
+ * }
159
+ * });
160
+ * ```
161
+ *
162
+ * @remarks
163
+ * - Requires text to be selected in the editor
164
+ * - Requires Velt SDK to be available (window.Velt)
165
+ * - Marks are only applied if persistVeltMarks is FALSE in extension config (matching legacy behavior)
166
+ * - Fails silently if Velt SDK is unavailable or selection is invalid
167
+ */
168
+ declare function addComment({ editorId, editor, context: clientContext, }: AddCommentRequest): Promise<void>;
169
+
170
+ /**
171
+ * Render comments feature module.
172
+ *
173
+ * Purpose: Public API entry point for rendering comment annotations.
174
+ * Orchestrates state updates, subscriptions, and delegates to commentRenderer.
175
+ *
176
+ * Key responsibilities:
177
+ * - Update state with new annotations
178
+ * - Subscribe to selected annotations from Velt
179
+ * - Delegate rendering logic to commentRenderer
180
+ *
181
+ * Dependencies:
182
+ * - adapters/velt.ts (for Velt SDK subscription)
183
+ * - adapters/host/doc.ts (for editor setup)
184
+ * - core/state.ts (for state management)
185
+ * - core/registry.ts (for editor ID extraction)
186
+ * - features/commentRenderer.ts (for rendering logic)
187
+ * - types/velt.ts (for CommentAnnotation)
188
+ *
189
+ * IMPORTANT: This module MUST NOT import editor or Velt types directly.
190
+ * All SDK access goes through adapters.
191
+ */
192
+
193
+ /**
194
+ * Renders comment annotations as marks in the editor.
195
+ *
196
+ * This function renders comment annotations as visual marks in the editor.
197
+ * It filters annotations for the specific editor and applies marks accordingly.
198
+ *
199
+ * @param request - Object containing editor, editorId (optional), and commentAnnotations (optional)
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * // Simple usage
204
+ * renderComments({ editor });
205
+ *
206
+ * // With editor ID
207
+ * renderComments({ editorId: 'my-editor', editor });
208
+ *
209
+ * // With annotations
210
+ * renderComments({
211
+ * editorId: 'my-editor',
212
+ * editor,
213
+ * commentAnnotations: [
214
+ * {
215
+ * annotationId: 'ann-123',
216
+ * context: {
217
+ * textEditorConfig: {
218
+ * text: 'Hello world',
219
+ * occurrence: 1,
220
+ * editorId: 'my-editor'
221
+ * }
222
+ * }
223
+ * }
224
+ * ]
225
+ * });
226
+ * ```
227
+ *
228
+ * @remarks
229
+ * - Only annotations with matching editorId are rendered
230
+ * - Automatically subscribes to selected annotations changes
231
+ * - Filters out terminal/resolved comments unless they're selected
232
+ * - Removes marks when comments become resolved
233
+ * - Re-applies marks when resolved comments are selected
234
+ */
235
+ declare const renderComments: ({ editor, editorId, commentAnnotations, }: RenderCommentsRequest) => void;
236
+
237
+ /**
238
+ * Serializer utilities for Slate editor content
239
+ *
240
+ * This module provides utilities for serializing Slate editor content,
241
+ * particularly for removing comment nodes from serialized JSON.
242
+ *
243
+ * Use this when persisting editor content to remove Velt comment elements
244
+ * while preserving the original text content.
245
+ */
246
+
247
+ /**
248
+ * Export JSON without comment nodes.
249
+ *
250
+ * This function takes Slate editor content and removes all comment nodes,
251
+ * unwrapping their children and merging adjacent text nodes with same formatting.
252
+ *
253
+ * @param content - Slate editor content (Descendant[])
254
+ * @returns Serialized content without comment nodes
255
+ */
256
+ declare const exportJSONWithoutComments: (content: Descendant[]) => Descendant[];
257
+
258
+ /**
259
+ * Editor-specific type definitions.
260
+ * This is the ONLY place where editor-specific types may be defined.
261
+ */
262
+
263
+ /**
264
+ * Extended Editor interface with Velt comments functionality.
265
+ */
266
+ interface VeltCommentsEditor extends Editor {
267
+ }
268
+ /**
269
+ * Velt comment element type for the editor.
270
+ * This represents a comment annotation node/element in the editor's document model.
271
+ */
272
+ type VeltCommentsElement = {
273
+ type: 'veltComment';
274
+ children: Descendant[];
275
+ annotationId?: string;
276
+ multiThreadAnnotationId?: string;
277
+ };
278
+
279
+ /**
280
+ * React component for rendering Velt comment elements in Slate editor.
281
+ * This component renders the <velt-comment-text> custom element.
282
+ *
283
+ * Note: velt-comment-text is an inline element, so it should only contain text nodes
284
+ * or other inline elements, never block elements like <p>.
285
+ */
286
+
287
+ declare const SlateVeltComment: (props: Omit<RenderElementProps, "element"> & {
288
+ element: VeltCommentsElement;
289
+ }) => React.ReactElement;
56
290
 
57
- export { AddCommentRequest, CommentAnnotationContext, RenderCommentsRequest, SlateVeltComment, VeltCommentConfig, VeltCommentsEditor, VeltCommentsEditorOptions, VeltCommentsElement, addComment, highlightComments, onSlateValueChange, renderComments, triggerAddComment, withVeltComments };
291
+ export { AddCommentRequest, CommentAnnotationContext, RenderCommentsRequest, SlateVeltComment, VeltCommentsEditor, VeltCommentsElement, VeltCommentsExtensionConfig, addComment, exportJSONWithoutComments, renderComments, withVeltComments };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltdev/slate-velt-comments-staging",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Slate Extension to add Google Docs-style overlay comments to your Slate editor. Works with the Velt Collaboration SDK.",
5
5
  "homepage": "https://velt.dev",
6
6
  "keywords": [
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- import type { RenderElementProps } from 'slate-react';
3
- import type { VeltCommentsElement } from './types';
4
- export declare const SlateVeltComment: (props: Omit<RenderElementProps, "element"> & {
5
- element: VeltCommentsElement;
6
- }) => React.JSX.Element;
@@ -1,9 +0,0 @@
1
- export declare const Constants: {
2
- ATTRIBUTES: {
3
- EDITOR_ID: string;
4
- LOCATION_ID: string;
5
- };
6
- ELEMENT_TYPE: {
7
- VELT_COMMENT: string;
8
- };
9
- };
@@ -1,72 +0,0 @@
1
- import type { CommentAnnotation } from '@veltdev/types';
2
- import { Editor, Element as SlateElement } from 'slate';
3
- import type { Plugin } from './plugin';
4
- /**
5
- * Interface for tracking annotation changes during a transaction
6
- */
7
- export interface AnnotationChange {
8
- annotationId: string;
9
- multiThreadAnnotationId?: string;
10
- originalText: string;
11
- currentText: string;
12
- originalOccurrence: number;
13
- currentOccurrence: number;
14
- originalTargetTextNodeId: string | undefined;
15
- newTargetTextNodeId: string | undefined;
16
- annotation: CommentAnnotation;
17
- contentChanged: boolean;
18
- occurrenceChanged: boolean;
19
- targetTextNodeIdChanged: boolean;
20
- }
21
- export declare class EditorService {
22
- plugin: Plugin;
23
- private static HistoryEditor?;
24
- constructor(plugin: Plugin);
25
- static setHistoryEditor: (historyEditor: any) => void;
26
- static getHistoryEditor: () => any;
27
- static getEditorId: (editor: Editor) => string | null;
28
- static isVeltCommentText: (element: SlateElement) => boolean;
29
- getSelectedText: (editor: Editor) => string | null;
30
- /**
31
- * Finds occurrences of a given text within a specified element or text
32
- * @param {Object} options - Configuration options for occurrence search
33
- * @param {string} options.searchText - The text to search for
34
- * @param {SlateElement|string} [options.scopeElement] - DOM element or text to search within
35
- * @param {number} [options.startOffset] - Optional starting offset for the search
36
- * @param {boolean} [options.caseSensitive] - Whether the search should be case-sensitive
37
- * @returns {Object} Occurrence details
38
- */
39
- private findOccurrenceOfText;
40
- findOccurrenceOfSelectedText: (editor: Editor, scopeElement?: HTMLElement) => number | null | undefined;
41
- private findAllMatches;
42
- findParentNodeWithIdForSelection: (editor: Editor) => HTMLElement | null;
43
- private findParentNodeWithId;
44
- removeVeltCommentFromEditor: (editor: Editor, annotationId: string) => boolean;
45
- highlightTextWithVeltComment: (editor: Editor, annotation: CommentAnnotation) => void;
46
- getEditorTextContent: (editor: Editor) => string;
47
- onSlateValueChange: ({ editor }: {
48
- editor: Editor;
49
- }) => void;
50
- private collectDocumentAnnotations;
51
- private processAnnotationChanges;
52
- /**
53
- * Updates the Velt comment element with new annotation data
54
- */
55
- private updateVeltComments;
56
- private isElementInEditor;
57
- private traverseNodesForText;
58
- private collectSubtreeText;
59
- private findTextOccurrence;
60
- private injectTag;
61
- /**
62
- * Find all occurrences of a specific text in the editor
63
- * @param {Editor} editor - The Slate.js editor instance
64
- * @param {string} searchText - The text to search for
65
- * @param {boolean} [caseSensitive=true] - Whether the search should be case-sensitive
66
- * @param {Node} [containerNode] - Optional container node to limit the search scope (if provided, only searches within this node)
67
- * @param {Path} [containerPath] - Optional path of the container node (will be calculated if not provided)
68
- * @returns {Array} Array of occurrence details
69
- */
70
- private findAllTextOccurrences;
71
- private findTextOccurrenceOfNode;
72
- }
@@ -1,17 +0,0 @@
1
- import type { Editor } from 'slate';
2
- import { EditorService } from './editor';
3
- import { StoreService } from './store';
4
- export declare class Plugin {
5
- editorId: string;
6
- editor: Editor | undefined;
7
- editorService: EditorService;
8
- storeService: StoreService;
9
- previousEditorTextContent: string;
10
- constructor(editorId: string, editor?: Editor);
11
- static getInstance(config?: {
12
- editorId?: string | null;
13
- editor?: Editor;
14
- }): Plugin;
15
- getPreviousEditorTextContent(): string;
16
- setPreviousEditorTextContent(textContent: string): void;
17
- }
@@ -1,36 +0,0 @@
1
- import type { CommentAnnotation } from '@veltdev/types';
2
- import type { Editor } from 'slate';
3
- import type { Plugin } from './plugin';
4
- type GlobalStore = {
5
- editor?: Editor | null;
6
- comments?: CommentAnnotation[];
7
- filteredComments?: CommentAnnotation[];
8
- selectedCommentsMap?: Map<string, boolean>;
9
- };
10
- /**
11
- * Interface for annotation store entry
12
- */
13
- interface AnnotationStoreEntry {
14
- annotation: CommentAnnotation;
15
- }
16
- export declare class StoreService {
17
- static storeInstanceMap: Map<string, StoreService>;
18
- plugin: Plugin;
19
- isSubscribed: boolean;
20
- globalStore: GlobalStore;
21
- globalAnnotationStore: Map<string, AnnotationStoreEntry>;
22
- /**
23
- * Helper to get and set annotations with debug messages
24
- */
25
- annotationStore: {
26
- get: (id: string) => AnnotationStoreEntry | undefined;
27
- set: (id: string, data: AnnotationStoreEntry) => void;
28
- getAll: () => Map<string, AnnotationStoreEntry>;
29
- clear: () => void;
30
- remove: (id: string) => void;
31
- };
32
- constructor(plugin: Plugin);
33
- updateGlobalStore: (store: GlobalStore) => void;
34
- highlightCommentsFromGlobalStore: () => void;
35
- }
36
- export {};
@@ -1,14 +0,0 @@
1
- import type { Descendant } from 'slate';
2
- export type VeltCommentsElement = {
3
- type: 'veltComment';
4
- children: Descendant[];
5
- annotationId?: string;
6
- };
7
- export type CommentAnnotationContext = {
8
- textEditorConfig?: {
9
- text: string;
10
- occurrence: number;
11
- editorId?: string;
12
- targetTextNodeId?: string;
13
- };
14
- } & Record<string, unknown>;
@@ -1,21 +0,0 @@
1
- import type { Location } from '@veltdev/types';
2
- import type { CommentAnnotationContext } from './types';
3
- export declare class VeltService {
4
- static selectedCommentsMap: Map<string, boolean>;
5
- static subscribers: Map<string, (selectedCommentsMap: Map<string, boolean>) => void>;
6
- static isSubscribed: boolean;
7
- static getCommentElement: () => import("@veltdev/types").CommentElement | null;
8
- static addManualComment: ({ context, location, }: {
9
- context: CommentAnnotationContext;
10
- location?: Location;
11
- }) => Promise<any>;
12
- static updateContext: ({ annotationId, context, }: {
13
- annotationId: string;
14
- context: CommentAnnotationContext;
15
- }) => Promise<any> | undefined;
16
- static subscribeToSelectedCommentsMap: (id: string, subscriber: (selectedCommentsMap: Map<string, boolean>) => void) => void;
17
- static unsubscribeFromSelectedCommentsMap: (id: string) => void;
18
- static catchError: (message: string, otherProperties?: any) => void;
19
- static subscribeToSelectedAnnotationsMapSingleton: () => Map<any, any> | undefined;
20
- private static updateSelectedCommentsMap;
21
- }
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- import type { RenderElementProps } from 'slate-react';
3
- import type { VeltCommentsElement } from './types';
4
- export declare const SlateVeltComment: (props: Omit<RenderElementProps, "element"> & {
5
- element: VeltCommentsElement;
6
- }) => React.JSX.Element;
@@ -1,9 +0,0 @@
1
- export declare const Constants: {
2
- ATTRIBUTES: {
3
- EDITOR_ID: string;
4
- LOCATION_ID: string;
5
- };
6
- ELEMENT_TYPE: {
7
- VELT_COMMENT: string;
8
- };
9
- };
@@ -1,72 +0,0 @@
1
- import type { CommentAnnotation } from '@veltdev/types';
2
- import { Editor, Element as SlateElement } from 'slate';
3
- import type { Plugin } from './plugin';
4
- /**
5
- * Interface for tracking annotation changes during a transaction
6
- */
7
- export interface AnnotationChange {
8
- annotationId: string;
9
- multiThreadAnnotationId?: string;
10
- originalText: string;
11
- currentText: string;
12
- originalOccurrence: number;
13
- currentOccurrence: number;
14
- originalTargetTextNodeId: string | undefined;
15
- newTargetTextNodeId: string | undefined;
16
- annotation: CommentAnnotation;
17
- contentChanged: boolean;
18
- occurrenceChanged: boolean;
19
- targetTextNodeIdChanged: boolean;
20
- }
21
- export declare class EditorService {
22
- plugin: Plugin;
23
- private static HistoryEditor?;
24
- constructor(plugin: Plugin);
25
- static setHistoryEditor: (historyEditor: any) => void;
26
- static getHistoryEditor: () => any;
27
- static getEditorId: (editor: Editor) => string | null;
28
- static isVeltCommentText: (element: SlateElement) => boolean;
29
- getSelectedText: (editor: Editor) => string | null;
30
- /**
31
- * Finds occurrences of a given text within a specified element or text
32
- * @param {Object} options - Configuration options for occurrence search
33
- * @param {string} options.searchText - The text to search for
34
- * @param {SlateElement|string} [options.scopeElement] - DOM element or text to search within
35
- * @param {number} [options.startOffset] - Optional starting offset for the search
36
- * @param {boolean} [options.caseSensitive] - Whether the search should be case-sensitive
37
- * @returns {Object} Occurrence details
38
- */
39
- private findOccurrenceOfText;
40
- findOccurrenceOfSelectedText: (editor: Editor, scopeElement?: HTMLElement) => number | null | undefined;
41
- private findAllMatches;
42
- findParentNodeWithIdForSelection: (editor: Editor) => HTMLElement | null;
43
- private findParentNodeWithId;
44
- removeVeltCommentFromEditor: (editor: Editor, annotationId: string) => boolean;
45
- highlightTextWithVeltComment: (editor: Editor, annotation: CommentAnnotation) => void;
46
- getEditorTextContent: (editor: Editor) => string;
47
- onSlateValueChange: ({ editor }: {
48
- editor: Editor;
49
- }) => void;
50
- private collectDocumentAnnotations;
51
- private processAnnotationChanges;
52
- /**
53
- * Updates the Velt comment element with new annotation data
54
- */
55
- private updateVeltComments;
56
- private isElementInEditor;
57
- private traverseNodesForText;
58
- private collectSubtreeText;
59
- private findTextOccurrence;
60
- private injectTag;
61
- /**
62
- * Find all occurrences of a specific text in the editor
63
- * @param {Editor} editor - The Slate.js editor instance
64
- * @param {string} searchText - The text to search for
65
- * @param {boolean} [caseSensitive=true] - Whether the search should be case-sensitive
66
- * @param {Node} [containerNode] - Optional container node to limit the search scope (if provided, only searches within this node)
67
- * @param {Path} [containerPath] - Optional path of the container node (will be calculated if not provided)
68
- * @returns {Array} Array of occurrence details
69
- */
70
- private findAllTextOccurrences;
71
- private findTextOccurrenceOfNode;
72
- }
@@ -1,17 +0,0 @@
1
- import type { Editor } from 'slate';
2
- import { EditorService } from './editor';
3
- import { StoreService } from './store';
4
- export declare class Plugin {
5
- editorId: string;
6
- editor: Editor | undefined;
7
- editorService: EditorService;
8
- storeService: StoreService;
9
- previousEditorTextContent: string;
10
- constructor(editorId: string, editor?: Editor);
11
- static getInstance(config?: {
12
- editorId?: string | null;
13
- editor?: Editor;
14
- }): Plugin;
15
- getPreviousEditorTextContent(): string;
16
- setPreviousEditorTextContent(textContent: string): void;
17
- }
@@ -1,36 +0,0 @@
1
- import type { CommentAnnotation } from '@veltdev/types';
2
- import type { Editor } from 'slate';
3
- import type { Plugin } from './plugin';
4
- type GlobalStore = {
5
- editor?: Editor | null;
6
- comments?: CommentAnnotation[];
7
- filteredComments?: CommentAnnotation[];
8
- selectedCommentsMap?: Map<string, boolean>;
9
- };
10
- /**
11
- * Interface for annotation store entry
12
- */
13
- interface AnnotationStoreEntry {
14
- annotation: CommentAnnotation;
15
- }
16
- export declare class StoreService {
17
- static storeInstanceMap: Map<string, StoreService>;
18
- plugin: Plugin;
19
- isSubscribed: boolean;
20
- globalStore: GlobalStore;
21
- globalAnnotationStore: Map<string, AnnotationStoreEntry>;
22
- /**
23
- * Helper to get and set annotations with debug messages
24
- */
25
- annotationStore: {
26
- get: (id: string) => AnnotationStoreEntry | undefined;
27
- set: (id: string, data: AnnotationStoreEntry) => void;
28
- getAll: () => Map<string, AnnotationStoreEntry>;
29
- clear: () => void;
30
- remove: (id: string) => void;
31
- };
32
- constructor(plugin: Plugin);
33
- updateGlobalStore: (store: GlobalStore) => void;
34
- highlightCommentsFromGlobalStore: () => void;
35
- }
36
- export {};
@@ -1,14 +0,0 @@
1
- import type { Descendant } from 'slate';
2
- export type VeltCommentsElement = {
3
- type: 'veltComment';
4
- children: Descendant[];
5
- annotationId?: string;
6
- };
7
- export type CommentAnnotationContext = {
8
- textEditorConfig?: {
9
- text: string;
10
- occurrence: number;
11
- editorId?: string;
12
- targetTextNodeId?: string;
13
- };
14
- } & Record<string, unknown>;