From d8bc094b4534b591ece2c8c46a3552276a06df63 Mon Sep 17 00:00:00 2001 From: Jeff Emmett <46964190+Jeff-Emmett@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:02:56 -0500 Subject: [PATCH] create frame shortcut dropdown on context menu --- src/ui/CustomContextMenu.tsx | 46 ++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/ui/CustomContextMenu.tsx b/src/ui/CustomContextMenu.tsx index e5f4e3c..67374c4 100644 --- a/src/ui/CustomContextMenu.tsx +++ b/src/ui/CustomContextMenu.tsx @@ -1,6 +1,11 @@ -import { TldrawUiMenuItem, TLShape } from "tldraw" +import { + Editor, + TldrawUiMenuActionItem, + TldrawUiMenuItem, + TldrawUiMenuSubmenu, + TLShape, +} from "tldraw" import { TldrawUiMenuGroup } from "tldraw" -import { DefaultContextMenuContent } from "tldraw" import { DefaultContextMenu } from "tldraw" import { TLUiContextMenuProps, useEditor } from "tldraw" import { @@ -12,6 +17,17 @@ import { } from "./cameraUtils" import { useState, useEffect } from "react" import { saveToPdf } from "../utils/pdfUtils" +import { TLFrameShape } from "tldraw" + +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() @@ -53,7 +69,7 @@ export function CustomContextMenu(props: TLUiContextMenuProps) { id="zoom-to-selection" label="Zoom to Selection" icon="zoom-in" - kbd="alt +z" + kbd="z" disabled={!hasSelection} onSelect={() => zoomToSelection(editor)} /> @@ -61,7 +77,7 @@ export function CustomContextMenu(props: TLUiContextMenuProps) { id="copy-link-to-current-view" label="Copy Link to Current View" icon="link" - kbd="alt+s" + kbd="alt+c" onSelect={() => copyLinkToCurrentView(editor)} /> lockCameraToFrame(editor)} /> - + + + + {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) + } + }} + /> + ))} + + ) }