import { TldrawUiMenuItem, TLShape } from "tldraw" import { TldrawUiMenuGroup } from "tldraw" import { DefaultContextMenuContent } from "tldraw" import { DefaultContextMenu } from "tldraw" import { TLUiContextMenuProps, useEditor } from "tldraw" import { cameraHistory, copyLinkToCurrentView, lockCameraToFrame, revertCamera, zoomToSelection, } from "./cameraUtils" import { useState, useEffect } from "react" export function CustomContextMenu(props: TLUiContextMenuProps) { const editor = useEditor() const [selectedShapes, setSelectedShapes] = useState([]) const [selectedIds, setSelectedIds] = useState([]) // Update selection state more frequently useEffect(() => { const updateSelection = () => { setSelectedShapes(editor.getSelectedShapes()) setSelectedIds(editor.getSelectedShapeIds()) } // Initial update updateSelection() // Subscribe to selection changes const unsubscribe = editor.addListener("change", updateSelection) return () => { if (typeof unsubscribe === "function") { ;(unsubscribe as () => void)() } } }, [editor]) const hasSelection = selectedIds.length > 0 const hasCameraHistory = cameraHistory.length > 0 // Check if exactly one frame is selected const hasFrameSelected = selectedShapes.length === 1 && selectedShapes[0].type === "frame" return ( {/* Camera Controls Group */} zoomToSelection(editor)} /> copyLinkToCurrentView(editor)} /> revertCamera(editor)} /> {/* Creation Tools Group */} { editor.setCurrentTool("VideoChat") }} /> { editor.setCurrentTool("ChatBox") }} /> { editor.setCurrentTool("Embed") }} /> { editor.setCurrentTool("Markdown") }} /> {/* Frame Controls */} lockCameraToFrame(editor)} /> ) }