diff --git a/src/canvasManager.ts b/src/canvasManager.ts-obsolete similarity index 94% rename from src/canvasManager.ts rename to src/canvasManager.ts-obsolete index 9e9fafd..64ee93f 100644 --- a/src/canvasManager.ts +++ b/src/canvasManager.ts-obsolete @@ -1,5 +1,5 @@ -import { Circle } from './shapes/Circle'; -import { Triangle } from './shapes/Triangle'; +import { Circle } from './shapes/Circle.ts-obsolete'; +import { Triangle } from './shapes/Triangle.ts-obsolete'; import { Shape, Patch, CircleShape, TriangleShape } from './types'; // Main function to handle both initial render and updates of shapes @@ -28,6 +28,7 @@ export function createOrUpdateShapes( // Process each patch to update, add, or remove shapes patches.forEach(patch => { + console.log('Processing patch:', patch); // Debug log if (patch.path[0] === 'shapes') { if (patch.action === 'put') { // Handle shape addition or update diff --git a/src/components/Canvas.svelte b/src/components/Canvas.svelte index c0cca46..b7abff2 100644 --- a/src/components/Canvas.svelte +++ b/src/components/Canvas.svelte @@ -22,7 +22,9 @@ } | null>(null); // Automerge document subscription + // This is called once $effect(() => { + console.log('Subscribing to document changes'); // Debug log const doc = handle.docSync(); if (doc) { shapes = doc.shapes; @@ -31,6 +33,8 @@ handle.on("change", ({ doc }) => { if (doc) { + console.log('Document changed:', doc.shapes); // Debug log + // TODO: would it make sense to use patches here to have fine grained reactivity ? shapes = doc.shapes; } }); @@ -75,19 +79,7 @@ id="shapesCanvas" viewBox="0 0 800 600" role="presentation" - onmousemove={(e) => { - if (!draggedShape) return; - - const svg = document.getElementById("shapesCanvas") as SVGSVGElement; - if (!svg) return; - - const point = svg.createSVGPoint(); - point.x = e.clientX; - point.y = e.clientY; - const { x, y } = point.matrixTransform(svg.getScreenCTM()!.inverse()); - - updateDocWithShapeMove(draggedShape.id, x, y); - }} + onmousemove={(e) => {handleDragMove(e) }} onmouseup={() => draggedShape = null} > {#each shapes as shape (shape.id)} diff --git a/src/components/shapes/Circle.svelte b/src/components/shapes/Circle.svelte index 623090f..41bb489 100644 --- a/src/components/shapes/Circle.svelte +++ b/src/components/shapes/Circle.svelte @@ -1,12 +1,5 @@