({ textareaRef }: CursorGhostProps)
| 65 | // ─── CursorGhost ───────────────────────────────────────────────────────────── |
| 66 | |
| 67 | export function CursorGhost({ textareaRef }: CursorGhostProps) { |
| 68 | const ctx = useCollaborationContextOptional(); |
| 69 | const [rendered, setRendered] = useState<RenderedCursor[]>([]); |
| 70 | |
| 71 | useEffect(() => { |
| 72 | if (!ctx || !textareaRef.current) return; |
| 73 | const textarea = textareaRef.current; |
| 74 | const { presence, otherUsers } = ctx; |
| 75 | |
| 76 | const next: RenderedCursor[] = []; |
| 77 | for (const user of otherUsers) { |
| 78 | const cursor = presence.cursors.get(user.id); |
| 79 | if (!cursor) continue; |
| 80 | try { |
| 81 | const pos = measureCursorPosition(textarea, cursor.position); |
| 82 | next.push({ user, cursor, ...pos }); |
| 83 | } catch { |
| 84 | // ignore measurement errors |
| 85 | } |
| 86 | } |
| 87 | setRendered(next); |
| 88 | }); |
| 89 | |
| 90 | if (!ctx || rendered.length === 0) return null; |
| 91 | |
| 92 | return ( |
| 93 | <div className="pointer-events-none absolute inset-0 overflow-hidden"> |
| 94 | <AnimatePresence> |
| 95 | {rendered.map(({ user, top, left }) => ( |
| 96 | <motion.div |
| 97 | key={user.id} |
| 98 | initial={{ opacity: 0 }} |
| 99 | animate={{ opacity: 1 }} |
| 100 | exit={{ opacity: 0 }} |
| 101 | transition={{ duration: 0.15 }} |
| 102 | className="absolute flex flex-col items-start" |
| 103 | style={{ top, left }} |
| 104 | > |
| 105 | {/* Cursor caret */} |
| 106 | <div |
| 107 | className="w-0.5 h-4" |
| 108 | style={{ backgroundColor: user.color }} |
| 109 | /> |
| 110 | {/* Name tag */} |
| 111 | <div |
| 112 | className="px-1 py-0.5 rounded text-[9px] font-semibold text-white whitespace-nowrap" |
| 113 | style={{ backgroundColor: user.color }} |
| 114 | > |
| 115 | {user.name} |
| 116 | </div> |
| 117 | </motion.div> |
| 118 | ))} |
| 119 | </AnimatePresence> |
| 120 | </div> |
| 121 | ); |
| 122 | } |
nothing calls this directly
no test coverage detected