UNPKG

claritykit-svelte

Version:

A comprehensive Svelte component library focused on accessibility, ADHD-optimized design, developer experience, and full SSR compatibility

254 lines 7.14 kB
/** * Hocuspocus Provider for Block-Level Collaborative Editing * * Provides real-time synchronization between clients through Hocuspocus server * with enhanced collaboration features, authentication, and conflict resolution. * * Replaces the custom YjsWebSocketProvider with Hocuspocus for better * collaboration infrastructure and enterprise-grade features. */ import { HocuspocusProvider } from '@hocuspocus/provider'; import * as Y from 'yjs'; import type { ProviderConfig, UserInfo, ConnectionState, CursorPosition, SelectionRange, AwarenessState, CollaborationStats } from './types'; export interface HocuspocusConfig extends ProviderConfig { token?: string; parameters?: Record<string, any>; onAuthenticated?: (data: any) => void; onAuthenticationFailed?: (data: any) => void; onStateless?: (payload: any) => void; forceSyncInterval?: number; quiet?: boolean; preserveConnection?: boolean; tokenRefreshCallback?: () => Promise<string>; retryAuthOnFailure?: boolean; maxAuthRetries?: number; enableAdvancedMessaging?: boolean; connectionTimeout?: number; syncTimeout?: number; enableMetrics?: boolean; customHeaders?: Record<string, string>; } export declare class HocuspocusCollaborationProvider { private config; private providers; private documents; private connectionStates; private reconnectAttempts; private listeners; private authRetryAttempts; private connectionTimeouts; private syncTimeouts; private metrics; private messageQueue; userId: string; userInfo: UserInfo; isOnline: boolean; constructor(config: HocuspocusConfig); /** * Connect to a block's collaborative session using Hocuspocus with enhanced features */ connectToBlock(blockId: string, options?: Partial<HocuspocusConfig>): Promise<HocuspocusProvider>; /** * Disconnect from a block's collaborative session */ disconnectFromBlock(blockId: string): void; /** * Get the Y.Doc for a specific block */ getDocument(blockId: string): Y.Doc | undefined; /** * Get the Hocuspocus provider for a specific block */ getProvider(blockId: string): HocuspocusProvider | undefined; /** * Get connection state for a block */ getConnectionState(blockId: string): ConnectionState; /** * Update user awareness information */ updateAwareness(blockId: string, updates: Partial<AwarenessState>): void; /** * Set cursor position for a block */ setCursor(blockId: string, cursor: CursorPosition): void; /** * Set selection range for a block */ setSelection(blockId: string, selection: SelectionRange): void; /** * Get all connected users for a block */ getConnectedUsers(blockId: string): UserInfo[]; /** * Send a stateless message to other clients with enhanced features */ sendStatelessMessage(blockId: string, payload: any, options?: { priority?: 'low' | 'normal' | 'high'; reliable?: boolean; targetUsers?: string[]; messageId?: string; }): void; /** * Send user activity update */ sendUserActivity(blockId: string, activity: { type: 'typing' | 'idle' | 'active' | 'away'; data?: any; }): void; /** * Send document event */ sendDocumentEvent(blockId: string, event: { type: 'edit' | 'save' | 'export' | 'share'; data?: any; }): void; /** * Send collaboration metric */ sendCollaborationMetric(blockId: string, metric: string, value: any): void; /** * Generate unique message ID */ private generateMessageId; /** * Collaborative undo functionality */ undoCollaborative(blockId: string): boolean; /** * Collaborative redo functionality */ redoCollaborative(blockId: string): boolean; /** * Get undo/redo state for a block */ getUndoRedoState(blockId: string): { canUndo: boolean; canRedo: boolean; }; /** * Enable offline support for a block */ enableOfflineSupport(blockId: string): void; /** * Load offline changes for a block */ loadOfflineChanges(blockId: string): boolean; /** * Clear offline data for a block */ clearOfflineData(blockId: string): void; /** * Force synchronization for a block */ forceSync(blockId: string): void; /** * Setup enhanced event listeners for a block's provider and document */ private setupEnhancedBlockEventListeners; /** * Handle automatic reconnection for a block */ private handleReconnection; /** * Setup network connectivity listeners */ private setupNetworkListeners; private _networkListeners?; /** * Get enhanced statistics about all connections */ getStats(): CollaborationStats; /** * Get detailed metrics for a specific block */ getBlockStats(blockId: string): any; /** * Disconnect from all blocks and cleanup all resources */ destroy(): void; /** * Simple event emitter implementation */ emit(event: string, data?: any): void; on(event: string, callback: Function): void; off(event: string, callback: Function): void; /** * Enhanced authentication handling */ private getValidToken; /** * Check if JWT token is expired */ private isTokenExpired; /** * Handle successful authentication */ private handleAuthenticated; /** * Handle authentication failure with retry logic */ private handleAuthenticationFailed; /** * Handle stateless messages with advanced processing */ private handleStatelessMessage; /** * Process advanced stateless messages */ private processAdvancedMessage; /** * Handle user activity messages */ private handleUserActivity; /** * Handle document event messages */ private handleDocumentEvent; /** * Handle collaboration metrics */ private handleCollaborationMetric; /** * Handle presence updates */ private handlePresenceUpdate; /** * Queue messages for later processing */ private queueMessage; /** * Handle connection timeout */ private handleConnectionTimeout; /** * Initialize performance monitoring */ private setupPerformanceMonitoring; /** * Initialize metrics for a block */ private initializeBlockMetrics; /** * Update block metrics */ private updateBlockMetrics; /** * Reconnect to a specific block */ private reconnectBlock; /** * Clean up resources for a block */ private cleanupBlockResources; /** * Generate a unique user ID */ private generateUserId; /** * Generate a random user color */ private generateUserColor; } export default HocuspocusCollaborationProvider; //# sourceMappingURL=HocuspocusProvider.d.ts.map