create frame shortcut dropdown on context menu
This commit is contained in:
parent
93f8122420
commit
d8bc094b45
|
|
@ -1,6 +1,11 @@
|
||||||
import { TldrawUiMenuItem, TLShape } from "tldraw"
|
import {
|
||||||
|
Editor,
|
||||||
|
TldrawUiMenuActionItem,
|
||||||
|
TldrawUiMenuItem,
|
||||||
|
TldrawUiMenuSubmenu,
|
||||||
|
TLShape,
|
||||||
|
} from "tldraw"
|
||||||
import { TldrawUiMenuGroup } from "tldraw"
|
import { TldrawUiMenuGroup } from "tldraw"
|
||||||
import { DefaultContextMenuContent } from "tldraw"
|
|
||||||
import { DefaultContextMenu } from "tldraw"
|
import { DefaultContextMenu } from "tldraw"
|
||||||
import { TLUiContextMenuProps, useEditor } from "tldraw"
|
import { TLUiContextMenuProps, useEditor } from "tldraw"
|
||||||
import {
|
import {
|
||||||
|
|
@ -12,6 +17,17 @@ import {
|
||||||
} from "./cameraUtils"
|
} from "./cameraUtils"
|
||||||
import { useState, useEffect } from "react"
|
import { useState, useEffect } from "react"
|
||||||
import { saveToPdf } from "../utils/pdfUtils"
|
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) {
|
export function CustomContextMenu(props: TLUiContextMenuProps) {
|
||||||
const editor = useEditor()
|
const editor = useEditor()
|
||||||
|
|
@ -53,7 +69,7 @@ export function CustomContextMenu(props: TLUiContextMenuProps) {
|
||||||
id="zoom-to-selection"
|
id="zoom-to-selection"
|
||||||
label="Zoom to Selection"
|
label="Zoom to Selection"
|
||||||
icon="zoom-in"
|
icon="zoom-in"
|
||||||
kbd="alt +z"
|
kbd="z"
|
||||||
disabled={!hasSelection}
|
disabled={!hasSelection}
|
||||||
onSelect={() => zoomToSelection(editor)}
|
onSelect={() => zoomToSelection(editor)}
|
||||||
/>
|
/>
|
||||||
|
|
@ -61,7 +77,7 @@ export function CustomContextMenu(props: TLUiContextMenuProps) {
|
||||||
id="copy-link-to-current-view"
|
id="copy-link-to-current-view"
|
||||||
label="Copy Link to Current View"
|
label="Copy Link to Current View"
|
||||||
icon="link"
|
icon="link"
|
||||||
kbd="alt+s"
|
kbd="alt+c"
|
||||||
onSelect={() => copyLinkToCurrentView(editor)}
|
onSelect={() => copyLinkToCurrentView(editor)}
|
||||||
/>
|
/>
|
||||||
<TldrawUiMenuItem
|
<TldrawUiMenuItem
|
||||||
|
|
@ -137,7 +153,27 @@ export function CustomContextMenu(props: TLUiContextMenuProps) {
|
||||||
onSelect={() => lockCameraToFrame(editor)}
|
onSelect={() => lockCameraToFrame(editor)}
|
||||||
/>
|
/>
|
||||||
</TldrawUiMenuGroup>
|
</TldrawUiMenuGroup>
|
||||||
<DefaultContextMenuContent />
|
|
||||||
|
<TldrawUiMenuGroup id="frames-list">
|
||||||
|
<TldrawUiMenuSubmenu id="frames-dropdown" label="Shortcut to Frames">
|
||||||
|
{getAllFrames(editor).map((frame) => (
|
||||||
|
<TldrawUiMenuItem
|
||||||
|
key={frame.id}
|
||||||
|
id={`frame-${frame.id}`}
|
||||||
|
label={frame.title}
|
||||||
|
onSelect={() => {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</TldrawUiMenuSubmenu>
|
||||||
|
</TldrawUiMenuGroup>
|
||||||
</DefaultContextMenu>
|
</DefaultContextMenu>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue