import { useEffect, useState } from "react" import { useEditor } from "tldraw" import { onFocusLockChange, unlockCameraFocus, getFocusLockedShapeId, } from "./cameraUtils" import type { TLShapeId } from "tldraw" export function FocusLockIndicator() { const editor = useEditor() const [isLocked, setIsLocked] = useState(false) const [shapeName, setShapeName] = useState("") useEffect(() => { const unsubscribe = onFocusLockChange((locked, shapeId) => { setIsLocked(locked) if (locked && shapeId) { // Try to get a name for the shape const shape = editor.getShape(shapeId) if (shape) { // Check for common name properties const name = (shape.props as any)?.name || (shape.props as any)?.title || (shape.meta as any)?.name || shape.type setShapeName(name) } } else { setShapeName("") } }) return () => { unsubscribe() } }, [editor]) if (!isLocked) return null return (
Focused on:{" "} {shapeName || "Shape"} (Press Esc)
) }