UNPKG

realtimecursor

Version:

Real-time collaboration system with cursor tracking and approval workflow

103 lines (102 loc) 2.46 kB
export interface CursorPosition { x: number; y: number; textPosition?: number; } export interface UserInfo { id: string; name: string; color?: string; } export interface CollaboratorInfo { id: string; name: string; color: string; socketId: string; } export interface RealtimeCursorOptions { apiUrl: string; socketUrl?: string; projectId: string; user: UserInfo; token?: string; } export interface CursorUpdateData { socketId: string; user: UserInfo; x: number; y: number; textPosition?: number; } export interface ContentUpdateData { content: string; user: UserInfo; cursorPosition?: number; } export interface CursorPositionUpdateData { socketId: string; textPosition: number; user: UserInfo; } export declare class RealtimeCursor { private socket; options: RealtimeCursorOptions; private collaborators; private cursors; private typingUsers; constructor(options: RealtimeCursorOptions); /** * Connect to the real-time cursor service */ connect(): void; /** * Disconnect from the real-time cursor service */ disconnect(): void; /** * Update cursor position */ updateCursor(position: CursorPosition): void; /** * Update cursor position in text */ updateCursorPosition(textPosition: number): void; /** * Update content */ updateContent(content: string, cursorPosition?: number): void; /** * Set typing indicator */ setTyping(isTyping: boolean): void; /** * Register event handlers */ private setupEventListeners; /** * Get random color for cursor */ private getRandomColor; /** * Get current collaborators */ getCollaborators(): CollaboratorInfo[]; /** * Get current cursors */ getCursors(): Record<string, any>; /** * Get typing users */ getTypingUsers(): string[]; onCollaboratorsChange?: (collaborators: CollaboratorInfo[]) => void; onUserJoined?: (user: CollaboratorInfo) => void; onUserLeft?: (data: { socketId: string; }) => void; onContentUpdate?: (data: ContentUpdateData) => void; onCursorUpdate?: (data: CursorUpdateData) => void; onCursorPositionUpdate?: (data: CursorPositionUpdateData) => void; onTypingStatusChange?: (typingUserIds: string[]) => void; } export default RealtimeCursor;