fixed lockCameraToFrame selection

This commit is contained in:
Jeff Emmett 2024-12-08 05:07:09 -05:00
parent 1190848222
commit 64d7581e6b
3 changed files with 34 additions and 17 deletions

View File

@ -1,7 +1,7 @@
import { BaseBoxShapeTool } from "tldraw"
export class MarkdownTool extends BaseBoxShapeTool {
static override id = "MarkdownTool"
shapeType = "MarkdownTool"
static override id = "Markdown"
shapeType = "Markdown"
override initial = "idle"
}

View File

@ -10,24 +10,32 @@ import {
revertCamera,
zoomToSelection,
} from "./cameraUtils"
import { useState, useEffect } from "react"
export function CustomContextMenu(props: TLUiContextMenuProps) {
const editor = useEditor()
const selectedShapes = editor.getSelectedShapes()
const selectedIds = editor.getSelectedShapeIds()
const [selectedShapes, setSelectedShapes] = useState<TLShape[]>([])
const [selectedIds, setSelectedIds] = useState<string[]>([])
// Add debug logs
console.log(
"Selected Shapes:",
selectedShapes.map((shape) => ({
id: shape.id,
type: shape.type,
})),
)
console.log(
"Selected Frame:",
selectedShapes.length === 1 && selectedShapes[0].type === "frame",
)
// 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

View File

@ -243,11 +243,20 @@ export class TldrawDurableObject {
server.accept()
// Add error handling
// Add error handling and reconnection logic
server.addEventListener("error", (err) => {
console.error("WebSocket error:", err)
})
server.addEventListener("close", () => {
if (this.roomPromise) {
this.getRoom().then((room) => {
// Update store to ensure all changes are persisted
room.updateStore(() => {})
})
}
})
return new Response(null, {
status: 101,
webSocket: client,