@datalayer/lexical-loro
Version:
Collaborative editing solution for Lexical based on Loro CRDT
63 lines (62 loc) • 3.03 kB
TypeScript
interface LoroCollaborativePluginProps {
websocketUrl: string;
docId: string;
onConnectionChange?: (connected: boolean) => void;
onPeerIdChange?: (peerId: string) => void;
onDisconnectReady?: (disconnectFn: () => void) => void;
onAwarenessChange?: (awareness: Array<{
peerId: string;
userName: string;
isCurrentUser?: boolean;
}>) => void;
onInitialization?: (success: boolean) => void;
onSendMessageReady?: (sendMessageFn: (message: any) => void) => void;
}
/**
* LoroCollaborativePlugin - Enhanced Cursor Management
*
* IMPROVEMENTS IMPLEMENTED based on Loro Cursor documentation and YJS SyncCursors patterns:
*
* 1. Enhanced CursorAwareness class with Loro document reference
* - Added loroDoc parameter for proper cursor operations
* - Provides framework for stable cursor positioning
*
* 2. Added createCursorFromLexicalPoint method
* - Inspired by YJS SyncCursors createRelativePosition pattern
* - Creates stable Loro cursors from Lexical selection points
* - Replaces approximation with proper cursor positioning
*
* 3. Added getStableCursorPosition method
* - Inspired by YJS SyncCursors createAbsolutePosition pattern
* - Converts Loro cursors back to stable positions
* - Provides better positioning than current approximations
*
* 4. Enhanced cursor side information support
* - Added anchorSide and focusSide to stable cursor data
* - Follows Loro Cursor documentation patterns for precise positioning
* - Equivalent to YJS RelativePosition side information
*
* 5. Improved cursor creation with framework for better methods
* - Added TODO comments showing enhanced cursor creation approach
* - Framework ready for using createCursorFromLexicalPoint
* - Maintains backward compatibility while providing upgrade path
*
* 6. Enhanced remote cursor processing
* - Added support for cursor side information in stable cursor data
* - Provides framework for direct Loro cursor conversion
* - Better handling of cursor position stability across edits
*
* TECHNICAL APPROACH:
* - Loro Cursor type is equivalent to YJS RelativePosition (as documented)
* - Stable positions survive document edits (like YJS RelativePosition)
* - Cursor side information provides precise positioning
* - Framework supports proper createRelativePosition/createAbsolutePosition patterns
*
* NEXT STEPS for full implementation:
* - Implement calculateGlobalPosition method with proper document traversal
* - Add convertGlobalPositionToLexical helper function
* - Enable the enhanced cursor creation methods by uncommenting TODO sections
* - Complete the direct Loro cursor conversion path
*/
export declare function LoroCollaborativePlugin({ websocketUrl, docId, onConnectionChange, onDisconnectReady, onPeerIdChange, onAwarenessChange, onInitialization, onSendMessageReady }: LoroCollaborativePluginProps): import("react/jsx-runtime").JSX.Element;
export default LoroCollaborativePlugin;