import { Editor, TldrawUiMenuActionItem, TldrawUiMenuItem, TldrawUiMenuSubmenu, TLGeoShape, TLShape, useDefaultHelpers, } from "tldraw" import { TldrawUiMenuGroup } from "tldraw" import { DefaultContextMenu, DefaultContextMenuContent } from "tldraw" import { TLUiContextMenuProps, useEditor } from "tldraw" import { cameraHistory, } from "./cameraUtils" import { useState, useEffect } from "react" import { saveToPdf } from "../utils/pdfUtils" import { TLFrameShape } from "tldraw" import { searchText } from "../utils/searchUtils" import { llm } from "../utils/llmUtils" import { getEdge } from "@/propagators/tlgraph" import { getCustomActions } from './overrides' import { overrides } from './overrides' const getAllFrames = (editor: Editor) => { return editor .getCurrentPageShapes() .filter((shape): shape is TLFrameShape => shape.type === "frame") .map((frame) => ({ id: frame.id, title: frame.props.name || "Untitled Frame", })) } export function CustomContextMenu(props: TLUiContextMenuProps) { const editor = useEditor() const helpers = useDefaultHelpers() const tools = overrides.tools?.(editor, {}, helpers) ?? {} const customActions = getCustomActions(editor) 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 //TO DO: Fix camera history for camera revert return ( {/* Camera Controls Group */} {/* Creation Tools Group */} {/* Frame Controls */} {getAllFrames(editor).map((frame) => ( { const shape = editor.getShape(frame.id) if (shape) { editor.zoomToBounds(editor.getShapePageBounds(shape)!, { animation: { duration: 400, easing: (t) => t * (2 - t) }, }) editor.select(frame.id) } }} /> ))} {/* TODO: FIX & IMPLEMENT BROADCASTING*/} {/* { editor.markHistoryStoppingPoint('start-broadcast') editor.updateInstanceState({ isBroadcasting: true }) const url = new URL(window.location.href) url.searchParams.set("followId", editor.user.getId()) window.history.replaceState(null, "", url.toString()) }} /> { editor.markHistoryStoppingPoint('stop-broadcast') editor.updateInstanceState({ isBroadcasting: false }) editor.stopFollowingUser() const url = new URL(window.location.href) url.searchParams.delete("followId") window.history.replaceState(null, "", url.toString()) }} /> */} searchText(editor)} /> ) }