From 77e81fde38f9ec4c13375b7607446721546fb744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Hendrik=20M=C3=BCller?= <44469195+kolibril13@users.noreply.github.com> Date: Wed, 17 Apr 2024 21:52:05 +0200 Subject: [PATCH] hello world on event --- src/App.jsx | 146 ++++++++++------------------------------------------ 1 file changed, 28 insertions(+), 118 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 5fc58c2..a9805bf 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,132 +1,42 @@ -import { useState, useEffect } from "react"; -import { Tldraw, createShapeId } from "tldraw"; +import { useCallback, useState } from "react"; +import { Tldraw } from "tldraw"; import "tldraw/tldraw.css"; -const overrides = { - //[a] - actions(_editor, actions) { - actions["delete"].kbd = "x"; - return actions; - }, - //[b] - tools(_editor, tools) { - tools["hand"].kbd = "g"; - tools["select"].kbd = "tab"; - tools["draw"].kbd = "tab"; - return tools; - }, -}; +export default function CanvasEventsExample() { + const [events, setEvents] = useState([]); -export default function App() { - // State for the x-coordinate of the rectangle - const [xCoordinate, setXCoordinate] = useState(350); - const [editorInstance, setEditorInstance] = useState(null); - - const handleMount = (editor) => { - setEditorInstance(editor); // Store the editor instance for later use - - // Initially create two rectangles and an arrow between them - const rectangleId1 = createShapeId("rectangle1"); - const rectangleId2 = createShapeId("rectangle2"); - const arrowId = createShapeId("arrow"); - - // Create the blue rectangle, yellow rectangle, and the arrow - editor.createShapes([ - { - id: rectangleId1, - type: "geo", - x: xCoordinate, - y: 300, - props: { - geo: "rectangle", - w: 150, - h: 75, - dash: "draw", - color: "blue", - size: "m", - }, - }, - { - id: rectangleId2, - type: "geo", - x: 500, - y: 500, - props: { - geo: "rectangle", - w: 100, - h: 100, - dash: "draw", - color: "yellow", - size: "m", - }, - }, - { - id: arrowId, - type: "arrow", - props: { - start: { - type: "binding", - boundShapeId: rectangleId1, - normalizedAnchor: { x: 0.5, y: 0.5 }, - isExact: false, - isPrecise: true, - }, - end: { - type: "binding", - boundShapeId: rectangleId2, - normalizedAnchor: { x: 0.5, y: 0.5 }, - isExact: false, - isPrecise: true, - }, - }, - }, - ]); - }; - - // Update the first rectangle's position when the xCoordinate state changes - useEffect(() => { - if (editorInstance) { - editorInstance.updateShapes([ - { - id: createShapeId("rectangle1"), - x: xCoordinate, - }, - ]); - } - }, [xCoordinate, editorInstance]); + const handleEvent = useCallback((data) => { + setEvents((events) => { + let newEvents = "hello world" + return newEvents; + }); + }, []); return ( - <> -