UNPKG

sveltekit-sync

Version:
45 lines (44 loc) 1.31 kB
/** * Selection Tracking Utility * * Automatically tracks text selections and displays selections for other users. */ import type { UsePresenceReturn } from '../hooks/usePresence.svelte.js'; import type { User, Selection } from '../presence.svelte.js'; export interface SelectionTrackingOptions { element: HTMLElement | null; throttle?: number; } export interface SelectionTrackingReturn { selections: Map<string, { user: User; selection: Selection; }>; startTracking(): void; stopTracking(): void; } /** * Track text selections for collaborative editing * * @param presence - The presence hook instance * @param options - Configuration options * @returns Selection tracking API * * @example * ```typescript * const presence = usePresence(channel, currentUser); * const selectionTracking = useSelectionTracking(presence, { * element: editorElement, * throttle: 100 * }); * * selectionTracking.startTracking(); * * // Access selections map * const selections = selectionTracking.selections; * for (const [userId, { user, selection }] of selections) { * highlightSelection(user, selection); * } * ``` */ export declare function useSelectionTracking(presence: UsePresenceReturn<any>, options: SelectionTrackingOptions): SelectionTrackingReturn;