@veltdev/slate-velt-comments-staging 1.0.3 → 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
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Update Content feature module.
3
+ * Handles document changes and annotation context updates.
4
+ *
5
+ * Responsibilities:
6
+ * - Detect document changes via doc adapter
7
+ * - Process each change: contentChanged, occurrenceChanged, targetTextNodeIdChanged
8
+ * - Update annotation contexts in Velt SDK
9
+ * - Update marks/nodes via marks adapter
10
+ *
11
+ * Architectural Rules:
12
+ * - NO direct editor or Velt imports (uses adapters)
13
+ * - Orchestrates: doc adapter → velt adapter → marks adapter
14
+ * - All functions use ES6 arrow functions
15
+ * - All imports use path aliases (@/)
16
+ */
17
+ /**
18
+ * Handles content updates when document changes occur.
19
+ * Detects annotation changes and updates Velt contexts accordingly.
20
+ *
21
+ * @param editorId Unique identifier for the editor
22
+ * @param editor The editor instance
23
+ * @param transaction The transaction object
24
+ */
25
+ export declare const handleContentUpdate: (editorId: string, editor: unknown, transaction: unknown) => void;
@@ -1,36 +1,16 @@
1
- import type { CommentAnnotation } from '@veltdev/types';
2
- import type { Editor } from 'slate';
3
- export { SlateVeltComment } from './SlateVeltComment';
4
- export * from './types';
5
- export interface VeltCommentsEditor extends Editor {
6
- }
7
- export interface VeltCommentsEditorOptions {
8
- HistoryEditor?: any;
9
- }
10
- export declare const withVeltComments: <T extends Editor>(editor: T, options?: VeltCommentsEditorOptions) => T & VeltCommentsEditor;
11
- export interface VeltCommentConfig {
12
- context?: unknown;
13
- }
14
- export declare const triggerAddComment: (editor: Editor, config?: VeltCommentConfig) => Promise<void>;
15
- export interface AddCommentRequest {
16
- editorId?: string;
17
- editor: Editor;
18
- context?: unknown;
19
- }
20
1
  /**
21
- * Creates a comment annotation for the currently selected text in the editor
22
- * This function handles the entire flow from getting the selected text to creating
23
- * the actual comment through the Velt service
2
+ * Public API for Editor-Velt Comments integration.
3
+ *
4
+ * This module exports the public API for the v2 implementation.
5
+ * All internal imports use path aliases (@/) for clean dependency management.
6
+ *
7
+ * @module EditorVeltComments
24
8
  */
25
- export declare const addComment: ({ editorId, editor, context: clientContext, }: AddCommentRequest) => Promise<void>;
26
- export declare function highlightComments(editor: Editor, commentAnnotations: CommentAnnotation[], editorId?: string): void;
27
- export interface RenderCommentsRequest {
28
- editor: Editor;
29
- editorId?: string;
30
- commentAnnotations?: CommentAnnotation[];
31
- }
32
- export declare const renderComments: ({ editor, editorId, commentAnnotations }: RenderCommentsRequest) => void;
33
- export declare const onSlateValueChange: ({ editor, editorId, }: {
34
- editor: Editor;
35
- editorId?: string;
36
- }) => void;
9
+ export { withVeltComments } from '@/core/extension';
10
+ export type { VeltCommentsExtensionConfig } from '@/core/extension';
11
+ export { addComment } from '@/features/addComment';
12
+ export { renderComments } from '@/features/renderComments';
13
+ export { exportJSONWithoutComments } from '@/utils/serializer';
14
+ export { SlateVeltComment } 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
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Editor-specific type definitions.
3
+ * This is the ONLY place where editor-specific types may be defined.
4
+ */
5
+ import type { Descendant, Editor } from 'slate';
6
+ import type { AnnotationData } from '@/types/state';
7
+ /**
8
+ * Extended Editor interface with Velt comments functionality.
9
+ */
10
+ export interface VeltCommentsEditor extends Editor {
11
+ }
12
+ /**
13
+ * Velt comment element type for the editor.
14
+ * This represents a comment annotation node/element in the editor's document model.
15
+ */
16
+ export type VeltCommentsElement = {
17
+ type: 'veltComment';
18
+ children: Descendant[];
19
+ annotationId?: string;
20
+ multiThreadAnnotationId?: string;
21
+ };
22
+ /**
23
+ * Selection context extracted from editor.
24
+ */
25
+ export interface SelectionContext {
26
+ text: string;
27
+ from: number;
28
+ to: number;
29
+ occurrence: number;
30
+ targetTextNodeId?: string;
31
+ locationId?: string;
32
+ }
33
+ /**
34
+ * Occurrence match result.
35
+ */
36
+ export interface OccurrenceMatch {
37
+ index: number;
38
+ start: number;
39
+ end: number;
40
+ text: string;
41
+ }
42
+ /**
43
+ * Represents a detected change to an annotation during document editing.
44
+ */
45
+ export interface AnnotationChange {
46
+ annotationId: string;
47
+ multiThreadAnnotationId?: string;
48
+ originalText: string;
49
+ currentText: string;
50
+ originalOccurrence: number;
51
+ currentOccurrence: number;
52
+ originalTargetTextNodeId: string;
53
+ newTargetTextNodeId: string;
54
+ annotation: AnnotationData;
55
+ contentChanged: boolean;
56
+ occurrenceChanged: boolean;
57
+ targetTextNodeIdChanged: boolean;
58
+ }
59
+ /**
60
+ * Document change event data.
61
+ */
62
+ export interface DocumentChangeEvent {
63
+ editorId: string;
64
+ changes: Map<string, AnnotationChange>;
65
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * State management type definitions.
3
+ * These types represent the internal state structure for managing annotations.
4
+ */
5
+ import type { CommentAnnotationContext } from '@/types/common';
6
+ import type { CommentAnnotation } from '@/types/velt';
7
+ /**
8
+ * Represents a single annotation with its associated data and position.
9
+ */
10
+ export interface AnnotationData {
11
+ annotationId: string;
12
+ multiThreadAnnotationId?: string;
13
+ context: CommentAnnotationContext;
14
+ position?: {
15
+ from: number;
16
+ to: number;
17
+ };
18
+ }
19
+ /**
20
+ * Annotation state per editor instance.
21
+ * Stores both simplified AnnotationData[] for core logic and full CommentAnnotation[] for rendering.
22
+ */
23
+ export interface AnnotationState {
24
+ editorId: string;
25
+ annotations: Map<string, AnnotationData>;
26
+ commentAnnotations: CommentAnnotation[];
27
+ selectedAnnotations: Set<string>;
28
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Velt SDK type definitions.
3
+ * This is the ONLY place where @veltdev/types may be imported.
4
+ */
5
+ import type { CommentAnnotation, Location, Velt } from '@veltdev/types';
6
+ export type { CommentAnnotation, Location, Velt };
7
+ /**
8
+ * Comment element from Velt SDK.
9
+ */
10
+ export type CommentElement = {
11
+ addManualComment: (params: {
12
+ context: unknown;
13
+ location?: Location;
14
+ }) => Promise<CommentAnnotation | null>;
15
+ updateContext: (annotationId: string, context: unknown) => void;
16
+ getSelectedComments?: () => {
17
+ subscribe: (callback: (comments: CommentAnnotation[]) => void) => () => void;
18
+ };
19
+ };
20
+ /**
21
+ * Unsubscribe function for Velt SDK subscriptions.
22
+ */
23
+ export type UnsubscribeFn = () => void;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Pure utility functions with zero side effects.
3
+ * These functions contain algorithmic logic extracted from legacy code.
4
+ *
5
+ * IMPORTANT: This module MUST NOT import any external SDKs or have side effects.
6
+ * All functions must be pure: input → output, deterministic, no mutations.
7
+ */
8
+ /**
9
+ * Computes the KMP (Knuth-Morris-Pratt) failure function (LPS array).
10
+ * This is used for efficient pattern matching in text search.
11
+ *
12
+ * @param pattern The pattern string to compute the failure function for
13
+ * @returns Longest proper prefix array (LPS array)
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const lps = computeKMPTable("abcabc");
18
+ * // Returns: [0, 0, 0, 1, 2, 3]
19
+ * ```
20
+ */
21
+ export declare const computeKMPTable: (pattern: string) => number[];
22
+ /**
23
+ * Finds all occurrences of a pattern in text using the KMP algorithm.
24
+ *
25
+ * @param text The text to search in
26
+ * @param pattern The pattern to search for
27
+ * @param startPos Starting position offset (default: 0)
28
+ * @param maxOccurrences Maximum number of occurrences to find (optional)
29
+ * @returns Array of start positions (0-based indices in the text)
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const positions = kmpSearch("abcabcabc", "abc", 0, 2);
34
+ * // Returns: [0, 3] (first 2 occurrences)
35
+ * ```
36
+ */
37
+ export declare const kmpSearch: (text: string, pattern: string, startPos?: number, maxOccurrences?: number) => number[];
38
+ /**
39
+ * Maps text positions in a combined string back to document positions.
40
+ * Used when searching across multiple text nodes that have been concatenated.
41
+ *
42
+ * @param textNodes Array of text nodes with their document positions
43
+ * @param textPositions Positions in the combined text (from kmpSearch)
44
+ * @param patternLength Length of the pattern being searched for
45
+ * @returns Array of { from, to } ranges in document coordinates
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const textNodes = [
50
+ * { text: "Hello ", pos: 0 },
51
+ * { text: "World", pos: 6 }
52
+ * ];
53
+ * const positions = [0]; // Found at start of combined text
54
+ * const ranges = mapTextPositionsToDocument(textNodes, positions, 5);
55
+ * // Returns: [{ from: 0, to: 5 }]
56
+ * ```
57
+ */
58
+ export declare const mapTextPositionsToDocument: (textNodes: Array<{
59
+ text: string;
60
+ pos: number;
61
+ }>, textPositions: number[], patternLength: number) => Array<{
62
+ from: number;
63
+ to: number;
64
+ }>;
65
+ /**
66
+ * Compares two maps for equality.
67
+ * Checks if both maps have the same size and identical key-value pairs.
68
+ *
69
+ * @param map1 First map to compare
70
+ * @param map2 Second map to compare
71
+ * @returns True if maps are equal, false otherwise
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const map1 = new Map([['a', true], ['b', false]]);
76
+ * const map2 = new Map([['a', true], ['b', false]]);
77
+ * areMapsEqual(map1, map2); // Returns: true
78
+ * ```
79
+ */
80
+ export declare const areMapsEqual: <K, V>(map1: Map<K, V>, map2: Map<K, V>) => boolean;
@@ -0,0 +1,25 @@
1
+ export declare class Console {
2
+ static log: {
3
+ (...data: any[]): void;
4
+ (message?: any, ...optionalParams: any[]): void;
5
+ };
6
+ static warn: {
7
+ (...data: any[]): void;
8
+ (message?: any, ...optionalParams: any[]): void;
9
+ };
10
+ static error: {
11
+ (...data: any[]): void;
12
+ (message?: any, ...optionalParams: any[]): void;
13
+ };
14
+ static debug: {
15
+ (...data: any[]): void;
16
+ (message?: any, ...optionalParams: any[]): void;
17
+ };
18
+ static info: {
19
+ (...data: any[]): void;
20
+ (message?: any, ...optionalParams: any[]): void;
21
+ };
22
+ static logsEnabled: boolean;
23
+ static catch: (message: string, error?: unknown) => void;
24
+ static showLogs(): boolean;
25
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Serializer utilities for Slate editor content
3
+ *
4
+ * This module provides utilities for serializing Slate editor content,
5
+ * particularly for removing comment nodes from serialized JSON.
6
+ *
7
+ * Use this when persisting editor content to remove Velt comment elements
8
+ * while preserving the original text content.
9
+ */
10
+ import type { Descendant } from 'slate';
11
+ /**
12
+ * Export JSON without comment nodes.
13
+ *
14
+ * This function takes Slate editor content and removes all comment nodes,
15
+ * unwrapping their children and merging adjacent text nodes with same formatting.
16
+ *
17
+ * @param content - Slate editor content (Descendant[])
18
+ * @returns Serialized content without comment nodes
19
+ */
20
+ export declare const exportJSONWithoutComments: (content: Descendant[]) => Descendant[];