@mhamz.01/easyflow-whiteboard 2.85.0 → 2.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,545 +1,458 @@
1
- "use strict";
2
- // "use client";
3
- // import { useState, useEffect, useRef } from "react";
4
- // import { FabricObject, Canvas } from "fabric";
5
- // import TaskNode from "./custom-node";
6
- // import DocumentNode from "./document-node";
7
- // // ─── Interfaces ───────────────────────────────────────────────────────────────
8
- // // THIS LAYER HAS ISSUE RELATED TO JUMP OF HTML NODES DURING DRAG/ZOOM
9
- // // THIS NEED TO BE FIXED BEFORE ANY OTHER FEATURES ARE ADDED TO THIS COMPONENT
10
- // export interface Task {
11
- // id: string;
12
- // title: string;
13
- // status: "todo" | "in-progress" | "done";
14
- // x: number;
15
- // y: number;
16
- // assignee?: string;
17
- // project?: string;
18
- // priority?: "low" | "medium" | "high";
19
- // dueDate?: string;
20
- // }
21
- // export interface Document {
22
- // id: string;
23
- // title: string;
24
- // project: string;
25
- // breadcrumb?: string[];
26
- // preview: string;
27
- // updatedAt?: string;
28
- // x: number;
29
- // y: number;
30
- // }
31
- // interface CanvasOverlayLayerProps {
32
- // tasks: Task[];
33
- // documents: Document[];
34
- // onTasksUpdate?: (tasks: Task[]) => void;
35
- // onDocumentsUpdate?: (documents: Document[]) => void;
36
- // canvasZoom?: number;
37
- // canvasViewport?: { x: number; y: number };
38
- // selectionBox?: { x1: number; y1: number; x2: number; y2: number } | null;
39
- // selectedCanvasObjects?: FabricObject[];
40
- // fabricCanvas?: React.RefObject<Canvas | null>;
41
- // canvasReady?: boolean;
42
- // }
43
- // interface DragState {
44
- // isDragging: boolean;
45
- // itemIds: string[];
46
- // startPositions: Map<string, { x: number; y: number }>;
47
- // canvasObjectsStartPos: Map<FabricObject, { left: number; top: number }>;
48
- // offsetX: number;
49
- // offsetY: number;
50
- // }
51
- // // ─── Component ────────────────────────────────────────────────────────────────
52
- // export default function CanvasOverlayLayer({
53
- // tasks,
54
- // documents,
55
- // onTasksUpdate,
56
- // onDocumentsUpdate,
57
- // canvasZoom = 1,
58
- // canvasViewport = { x: 0, y: 0 },
59
- // selectionBox = null,
60
- // selectedCanvasObjects = [],
61
- // fabricCanvas,
62
- // }: CanvasOverlayLayerProps) {
63
- // const [localTasks, setLocalTasks] = useState<Task[]>(tasks);
64
- // const [localDocuments, setLocalDocuments] = useState<Document[]>(documents);
65
- // const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
66
- // const [dragging, setDragging] = useState<{ itemIds: string[] } | null>(null);
67
- // const [canvasReady, setCanvasReady] = useState(false);
68
- // const nodeClipboardRef = useRef<{ tasks: Task[]; documents: Document[] }>({
69
- // tasks: [],
70
- // documents: [],
71
- // });
72
- // const dragStateRef = useRef<DragState>({
73
- // isDragging: false,
74
- // itemIds: [],
75
- // startPositions: new Map(),
76
- // canvasObjectsStartPos: new Map(),
77
- // offsetX: 0,
78
- // offsetY: 0,
79
- // });
80
- // const rafIdRef = useRef<number | null>(null);
81
- // const overlayRef = useRef<HTMLDivElement>(null);
82
- // const selectedIdsRef = useRef<Set<string>>(selectedIds);
83
- // selectedIdsRef.current = selectedIds;
84
- // // ── Sync props local state ────────────────────────────────────────────────
85
- // useEffect(() => { setLocalTasks(tasks); }, [tasks]);
86
- // useEffect(() => { setLocalDocuments(documents); }, [documents]);
87
- // // effect — polls until fabricCanvas.current is available:
88
- // useEffect(() => {
89
- // if (canvasReady) return;
90
- // if (fabricCanvas?.current) {
91
- // setCanvasReady(true);
92
- // return;
93
- // }
94
- // // Poll every 50ms until canvas is ready (only needed on first load)
95
- // const interval = setInterval(() => {
96
- // if (fabricCanvas?.current) {
97
- // setCanvasReady(true);
98
- // clearInterval(interval);
99
- // }
100
- // }, 50);
101
- // return () => clearInterval(interval);
102
- // }, [fabricCanvas, canvasReady]);
103
- // // ── Event Forwarding (Fixes Zooming on Nodes) ───────────────────────────────
104
- // const handleOverlayWheel = (e: React.WheelEvent) => {
105
- // if (e.ctrlKey || e.metaKey || e.shiftKey) {
106
- // const canvas = fabricCanvas?.current;
107
- // if (!canvas) return;
108
- // const nativeEvent = e.nativeEvent;
109
- // // getScenePoint handles the transformation from screen to canvas space
110
- // const scenePoint = canvas.getScenePoint(nativeEvent);
111
- // // Viewport point is simply the mouse position relative to the canvas element
112
- // const rect = canvas.getElement().getBoundingClientRect();
113
- // const viewportPoint = {
114
- // x: nativeEvent.clientX - rect.left,
115
- // y: nativeEvent.clientY - rect.top,
116
- // };
117
- // // We cast to 'any' here because we are manually triggering an internal
118
- // // event bus, and Fabric's internal types for .fire() can be overly strict.
119
- // canvas.fire("mouse:wheel", {
120
- // e: nativeEvent,
121
- // scenePoint,
122
- // viewportPoint,
123
- // } as any);
124
- // e.preventDefault();
125
- // e.stopPropagation();
126
- // }
127
- // };
128
- // useEffect(() => {
129
- // const overlayEl = overlayRef.current;
130
- // const canvas = fabricCanvas?.current;
131
- // if (!overlayEl || !canvas) return;
132
- // const handleGlobalWheel = (e: WheelEvent) => {
133
- // // Check if the user is hovering over an element that has pointer-events: auto
134
- // // (meaning they are hovering over a Task or Document)
135
- // const target = e.target as HTMLElement;
136
- // const isOverNode = target !== overlayEl;
137
- // if ((e.ctrlKey || e.metaKey) && isOverNode) {
138
- // // 1. Prevent Browser Zoom immediately
139
- // e.preventDefault();
140
- // e.stopPropagation();
141
- // // 2. Calculate coordinates for Fabric
142
- // const scenePoint = canvas.getScenePoint(e);
143
- // const rect = canvas.getElement().getBoundingClientRect();
144
- // const viewportPoint = {
145
- // x: e.clientX - rect.left,
146
- // y: e.clientY - rect.top,
147
- // };
148
- // // 3. Manually fire the event into Fabric
149
- // canvas.fire("mouse:wheel", {
150
- // e: e,
151
- // scenePoint,
152
- // viewportPoint,
153
- // } as any);
154
- // }
155
- // };
156
- // // CRITICAL: { passive: false } allows us to cancel the browser's zoom
157
- // overlayEl.addEventListener("wheel", handleGlobalWheel, { passive: false });
158
- // return () => {
159
- // overlayEl.removeEventListener("wheel", handleGlobalWheel);
160
- // };
161
- // }, [fabricCanvas, canvasZoom ,canvasReady]); // Re-bind when zoom changes to keep closure fresh
162
- // // ── Fabric → Overlay Sync (Fixes Dragging from Fabric area) ──────────────────
163
- // useEffect(() => {
164
- // const canvas = fabricCanvas?.current;
165
- // if (!canvas) return;
166
- // const handleObjectMoving = (e: any) => {
167
- // const target = e.transform?.target || e.target;
168
- // if (!target) return;
169
- // const deltaX = target.left - (target._prevLeft ?? target.left);
170
- // const deltaY = target.top - (target._prevTop ?? target.top);
171
- // target._prevLeft = target.left;
172
- // target._prevTop = target.top;
173
- // if (deltaX === 0 && deltaY === 0) return;
174
- // // ── Read from ref always fresh, never stale ──
175
- // const sel = selectedIdsRef.current;
176
- // setLocalTasks((prev) =>
177
- // prev.map((t) => sel.has(t.id) ? { ...t, x: t.x + deltaX, y: t.y + deltaY } : t)
178
- // );
179
- // setLocalDocuments((prev) =>
180
- // prev.map((d) => sel.has(d.id) ? { ...d, x: d.x + deltaX, y: d.y + deltaY } : d)
181
- // );
182
- // };
183
- // const handleMouseDown = (e: any) => {
184
- // const target = e.target;
185
- // if (target) {
186
- // target._prevLeft = target.left;
187
- // target._prevTop = target.top;
188
- // }
189
- // if (!target) {
190
- // setSelectedIds(new Set());
191
- // return;
192
- // }
193
- // // At zoom=1 with identity VPT, getActiveObject() can return null before
194
- // // Fabric updates _activeObject. Use e.transform as the primary check
195
- // // it is populated by Fabric's hit-test regardless of zoom level.
196
- // const transformTarget = e.transform?.target;
197
- // const activeObject = canvas.getActiveObject();
198
- // const activeObjects = canvas.getActiveObjects();
199
- // const isPartOfActiveSelection =
200
- // transformTarget === target || // most reliable — direct from event
201
- // activeObject === target || // selection box group
202
- // activeObjects.includes(target); // individual object in multi-select
203
- // if (!isPartOfActiveSelection) {
204
- // setSelectedIds(new Set());
205
- // }
206
- // };
207
- // const handleSelectionCleared = () => {
208
- // setSelectedIds(new Set());
209
- // };
210
- // canvas.on("object:moving", handleObjectMoving);
211
- // canvas.on("mouse:down", handleMouseDown);
212
- // canvas.on("selection:cleared", handleSelectionCleared);
213
- // return () => {
214
- // canvas.off("object:moving", handleObjectMoving);
215
- // canvas.off("mouse:down", handleMouseDown);
216
- // canvas.off("selection:cleared", handleSelectionCleared);
217
- // };
218
- // // ── selectedIds REMOVED from deps read via selectedIdsRef instead ──────
219
- // // Having selectedIds here caused the effect to re-register on every selection
220
- // // change, creating a new closure each time. The second drag captured a stale
221
- // // or empty selectedIds from the closure at re-registration time.
222
- // }, [canvasZoom, fabricCanvas ,canvasReady]);
223
- // // ── Helpers ─────────────────────────────────────────────────────────────────
224
- // const getItemPosition = (id: string): { x: number; y: number } | undefined => {
225
- // const task = localTasks.find((t) => t.id === id);
226
- // if (task) return { x: task.x, y: task.y };
227
- // const doc = localDocuments.find((d) => d.id === id);
228
- // if (doc) return { x: doc.x, y: doc.y };
229
- // return undefined;
230
- // };
231
- // const isItemInSelectionBox = (
232
- // x: number,
233
- // y: number,
234
- // width: number,
235
- // height: number,
236
- // box: { x1: number; y1: number; x2: number; y2: number }
237
- // ) => {
238
- // const itemX1 = x * canvasZoom + canvasViewport.x;
239
- // const itemY1 = y * canvasZoom + canvasViewport.y;
240
- // const itemX2 = itemX1 + width * canvasZoom;
241
- // const itemY2 = itemY1 + height * canvasZoom;
242
- // const boxX1 = Math.min(box.x1, box.x2);
243
- // const boxY1 = Math.min(box.y1, box.y2);
244
- // const boxX2 = Math.max(box.x1, box.x2);
245
- // const boxY2 = Math.max(box.y1, box.y2);
246
- // return !(boxX2 < itemX1 || boxX1 > itemX2 || boxY2 < itemY1 || boxY1 > itemY2);
247
- // };
248
- // // ── Selection box detection ──────────────────────────────────────────────────
249
- // useEffect(() => {
250
- // if (!selectionBox) return;
251
- // // ── O(n) single pass — no sort, no join, no extra allocations ──
252
- // const newSelected = new Set<string>();
253
- // for (const task of localTasks) {
254
- // if (isItemInSelectionBox(task.x, task.y, 300, 140, selectionBox))
255
- // newSelected.add(task.id);
256
- // }
257
- // for (const doc of localDocuments) {
258
- // if (isItemInSelectionBox(doc.x, doc.y, 320, 160, selectionBox))
259
- // newSelected.add(doc.id);
260
- // }
261
- // // ── O(n) equality check: size first (fast path), then membership ──
262
- // setSelectedIds((prev) => {
263
- // if (prev.size !== newSelected.size) return newSelected;
264
- // for (const id of newSelected) {
265
- // if (!prev.has(id)) return newSelected; // found a difference, swap
266
- // }
267
- // return prev; // identical — return same reference, no re-render
268
- // });
269
- // }, [selectionBox, localTasks, localDocuments, canvasZoom, canvasViewport]);
270
- // // ── Drag start (HTML Node side) ──────────────────────────────────────────────
271
- // // Helper to extract coordinates regardless of event type
272
- // const getPointerEvent = (e: React.MouseEvent | React.TouchEvent | MouseEvent | TouchEvent) => {
273
- // if ('touches' in e && e.touches.length > 0) return e.touches[0];
274
- // return e as { clientX: number; clientY: number };
275
- // };
276
- // const handleDragStart = (itemId: string, e: React.MouseEvent | React.TouchEvent) => {
277
- // // 1. Safety check for the Fabric instance
278
- // const canvas = fabricCanvas?.current;
279
- // if (!canvas) return;
280
- // // 2. Normalize the event (Touch vs Mouse)
281
- // if (e.cancelable) e.preventDefault();
282
- // const pointer = getPointerEvent(e);
283
- // // 3. Determine which items are being dragged
284
- // // selection update DOES NOT trigger before drag snapshot
285
- // let itemsToDrag: string[];
286
- // if (selectedIds.has(itemId)) {
287
- // itemsToDrag = Array.from(selectedIds);
288
- // } else {
289
- // itemsToDrag = [itemId];
290
- // }
291
- // // 4. Capture current World Transform (Zoom & Pan)
292
- // // We read directly from the canvas to ensure zero-frame lag
293
- // const vpt = canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
294
- // const liveZoom = vpt[0];
295
- // const liveVpX = vpt[4];
296
- // const liveVpY = vpt[5];
297
- // // 5. Convert the Click Position from Screen Pixels to World Units
298
- // const clickWorldX = (pointer.clientX - liveVpX) / liveZoom;
299
- // const clickWorldY = (pointer.clientY - liveVpY) / liveZoom;
300
- // // 6. Get the clicked item's current World Position
301
- // const clickedPos = getItemPosition(itemId);
302
- // if (!clickedPos) return;
303
- // // 7. Calculate the Offset in WORLD UNITS
304
- // // This is the distance from the mouse to the node's top-left in the infinite grid.
305
- // // This value remains constant even if you zoom during the drag.
306
- // const worldOffsetX = clickWorldX - clickedPos.x;
307
- // const worldOffsetY = clickWorldY - clickedPos.y;
308
- // // 8. Snapshot starting positions for all selected HTML nodes
309
- // const startPositions = new Map<string, { x: number; y: number }>();
310
- // itemsToDrag.forEach((id) => {
311
- // const pos = getItemPosition(id);
312
- // if (pos) startPositions.set(id, pos);
313
- // });
314
- // // 9. Snapshot starting positions for all selected Fabric objects
315
- // const canvasObjectsStartPos = new Map<FabricObject, { left: number; top: number }>();
316
- // selectedCanvasObjects.forEach((obj) => {
317
- // canvasObjectsStartPos.set(obj, { left: obj.left || 0, top: obj.top || 0 });
318
- // });
319
- // // 10. Commit to the ref for the requestAnimationFrame loop
320
- // dragStateRef.current = {
321
- // isDragging: true,
322
- // itemIds: itemsToDrag,
323
- // startPositions,
324
- // canvasObjectsStartPos,
325
- // offsetX: clickWorldX, // Now stored as World Units
326
- // offsetY: clickWorldY, // Now stored as World Units
327
- // };
328
- // if (!selectedIds.has(itemId) && dragStateRef.current.itemIds.length === 0) {
329
- // setSelectedIds(new Set([itemId]));
330
- // }
331
- // // 11. Trigger UI states
332
- // setDragging({ itemIds: itemsToDrag });
333
- // document.body.style.cursor = "grabbing";
334
- // document.body.style.userSelect = "none";
335
- // document.body.style.touchAction = "none";
336
- // };
337
- // // ── Drag move (HTML Node side) ───────────────────────────────────────────────
338
- // useEffect(() => {
339
- // if (!dragging) return;
340
- // // Inside the useEffect that watches [dragging, localTasks, localDocuments, fabricCanvas]
341
- // const handleMove = (e: MouseEvent | TouchEvent) => {
342
- // if (!dragStateRef.current.isDragging) return;
343
- // if (e.cancelable) e.preventDefault();
344
- // const pointer = getPointerEvent(e);
345
- // // 1. Throttle updates using requestAnimationFrame for 120Hz/144Hz screen support
346
- // if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current);
347
- // rafIdRef.current = requestAnimationFrame(() => {
348
- // const { itemIds, startPositions, canvasObjectsStartPos, offsetX, offsetY } = dragStateRef.current;
349
- // const canvas = fabricCanvas?.current;
350
- // if (!canvas) return;
351
- // // 2. Read the "Source of Truth" transform from the canvas
352
- // const vpt = canvas.viewportTransform!;
353
- // const liveZoom = vpt[0]; // Scale
354
- // const liveVpX = vpt[4]; // Pan X
355
- // const liveVpY = vpt[5]; // Pan Y
356
- // // 3. Convert current Mouse Screen Position → World Position
357
- // const currentWorldX = (pointer.clientX - liveVpX) / liveZoom;
358
- // const currentWorldY = (pointer.clientY - liveVpY) / liveZoom;
359
- // // 4. Calculate where the "Anchor" node should be in World Units
360
- // // (Current Mouse World - Initial World Offset from Start)
361
- // const deltaX = currentWorldX - offsetX;
362
- // const deltaY = currentWorldY - offsetY;
363
- // if (itemIds.length > 0) {
364
- // console.groupCollapsed(`Dragging Node: ${itemIds[0]}`);
365
- // console.log("Screen Mouse:", { x: pointer.clientX, y: pointer.clientY });
366
- // console.log("World Mouse:", { x: currentWorldX.toFixed(2), y: currentWorldY.toFixed(2) });
367
- // console.log("Canvas Zoom:", liveZoom.toFixed(2));
368
- // console.log("New Node Pos:", { x: deltaX.toFixed(2), y: deltaY.toFixed(2) });
369
- // console.groupEnd();
370
- // }
371
- // // 5. Calculate the Movement Delta in World Units
372
- // // We compare where the first item started vs where it is now.
373
- // const firstId = itemIds[0];
374
- // const firstStart = startPositions.get(firstId);
375
- // if (!firstStart) return;
376
- // // The real problem of task jumps
377
- // // const deltaX = deltaX - firstStart.x;
378
- // // 6. Update HTML Nodes (Batching these into one state update)
379
- // setLocalTasks((prev) =>
380
- // prev.map((t) => itemIds.includes(t.id) ? {
381
- // ...t,
382
- // x: (startPositions.get(t.id)?.x ?? t.x) + deltaX,
383
- // y: (startPositions.get(t.id)?.y ?? t.y) + deltaY,
384
- // } : t)
385
- // );
386
- // setLocalDocuments((prev) =>
387
- // prev.map((d) => itemIds.includes(d.id) ? {
388
- // ...d,
389
- // x: (startPositions.get(d.id)?.x ?? d.x) + deltaX,
390
- // y: (startPositions.get(d.id)?.y ?? d.y) + deltaY,
391
- // } : d)
392
- // );
393
- // // 7. Sync Fabric Objects (Imperative update for performance)
394
- // canvasObjectsStartPos.forEach((startPos, obj) => {
395
- // obj.set({
396
- // left: startPos.left + deltaX,
397
- // top: startPos.top + deltaY,
398
- // });
399
- // obj.setCoords(); // Required for selection/intersection accuracy
400
- // });
401
- // // 8. Single render call for all Fabric changes
402
- // canvas.requestRenderAll();
403
- // });
404
- // };
405
- // const handleEnd = () => {
406
- // if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current);
407
- // dragStateRef.current.isDragging = false;
408
- // setDragging(null);
409
- // document.body.style.cursor = "";
410
- // document.body.style.userSelect = "";
411
- // document.body.style.touchAction = "";
412
- // onTasksUpdate?.(localTasks);
413
- // onDocumentsUpdate?.(localDocuments);
414
- // };
415
- // window.addEventListener("mousemove", handleMove, { passive: false });
416
- // window.addEventListener("mouseup", handleEnd);
417
- // window.addEventListener("touchmove", handleMove, { passive: false });
418
- // window.addEventListener("touchend", handleEnd);
419
- // window.addEventListener("touchcancel", handleEnd);
420
- // return () => {
421
- // window.removeEventListener("mousemove", handleMove);
422
- // window.removeEventListener("mouseup", handleEnd);
423
- // window.removeEventListener("touchmove", handleMove);
424
- // window.removeEventListener("touchend", handleEnd);
425
- // window.removeEventListener("touchcancel", handleEnd);
426
- // };
427
- // }, [dragging, localTasks, localDocuments, fabricCanvas]);
428
- // // ── Selection, Status, Keyboard Logic ────────────────────────────────────────
429
- // const handleSelect = (id: string, e?: React.MouseEvent) => {
430
- // if (e?.shiftKey || e?.ctrlKey || e?.metaKey) {
431
- // setSelectedIds((prev) => {
432
- // const next = new Set(prev);
433
- // next.has(id) ? next.delete(id) : next.add(id);
434
- // return next;
435
- // });
436
- // } else {
437
- // setSelectedIds(new Set([id]));
438
- // }
439
- // };
440
- // const handleStatusChange = (taskId: string, newStatus: "todo" | "in-progress" | "done") => {
441
- // const updated = localTasks.map((t) => (t.id === taskId ? { ...t, status: newStatus } : t));
442
- // setLocalTasks(updated);
443
- // onTasksUpdate?.(updated);
444
- // };
445
- // useEffect(() => {
446
- // const handleKeyDown = (e: KeyboardEvent) => {
447
- // // Don't trigger if typing in input
448
- // if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) return;
449
- // // Select All
450
- // if ((e.ctrlKey || e.metaKey) && e.key === "a") {
451
- // e.preventDefault();
452
- // setSelectedIds(new Set([...localTasks.map((t) => t.id), ...localDocuments.map((d) => d.id)]));
453
- // }
454
- // // Clear selection
455
- // if (e.key === "Escape") {
456
- // setSelectedIds(new Set());
457
- // }
458
- // // ← ADD THIS: Delete selected nodes
459
- // if ((e.key === "Delete" || e.key === "Backspace") && selectedIds.size > 0) {
460
- // e.preventDefault();
461
- // const updatedTasks = localTasks.filter((t) => !selectedIds.has(t.id));
462
- // const updatedDocs = localDocuments.filter((d) => !selectedIds.has(d.id));
463
- // setLocalTasks(updatedTasks);
464
- // setLocalDocuments(updatedDocs);
465
- // setSelectedIds(new Set());
466
- // onTasksUpdate?.(updatedTasks);
467
- // onDocumentsUpdate?.(updatedDocs);
468
- // }
469
- // };
470
- // window.addEventListener("keydown", handleKeyDown);
471
- // return () => window.removeEventListener("keydown", handleKeyDown);
472
- // }, [localTasks, localDocuments, selectedIds, onTasksUpdate, onDocumentsUpdate]);
473
- // // ── Render helper ────────────────────────────────────────────────────────────
474
- // const renderItem = (id: string, x: number, y: number, children: React.ReactNode) => {
475
- // const screenX = x * canvasZoom;
476
- // const screenY = y * canvasZoom;
477
- // // 1. Detect if the user is interacting with the canvas at all
478
- // // 'dragging' is your existing state.
479
- // // You might want to pass 'isZooming' or 'isPanning' from your main canvas component here.
480
- // const isDragging = dragging?.itemIds.includes(id);
481
- // return (
482
- // <div
483
- // key={id}
484
- // className="pointer-events-auto absolute"
485
- // style={{
486
- // left: 0,
487
- // top: 0,
488
- // // 2. Use translate3d for GPU performance
489
- // transform: `translate3d(${screenX}px, ${screenY}px, 0) scale(${canvasZoom})`,
490
- // transformOrigin: "top left",
491
- // // 3. THE FIX: Remove transition entirely during any viewport change
492
- // // Any 'ease' during zoom causes the "shaking" behavior.
493
- // transition: "none",
494
- // // 4. Optimization
495
- // willChange: "transform",
496
- // zIndex: isDragging ? 1000 : 1,
497
- // }}
498
- // >
499
- // {children}
500
- // </div>
501
- // );
502
- // };
503
- // return (
504
- // <div
505
- // ref={overlayRef}
506
- // className="absolute inset-0 pointer-events-none"
507
- // style={{ zIndex: 50 }}
508
- // onWheel={handleOverlayWheel}
509
- // onClick={(e) => {
510
- // if (e.target === e.currentTarget) setSelectedIds(new Set());
511
- // }}
512
- // >
513
- // <div
514
- // className="absolute top-0 left-0 pointer-events-none"
515
- // style={{
516
- // transform: `translate(${canvasViewport.x}px, ${canvasViewport.y}px)`,
517
- // transformOrigin: "top left",
518
- // }}
519
- // >
520
- // {localTasks.map((task) =>
521
- // renderItem(task.id, task.x, task.y,
522
- // <TaskNode
523
- // {...task}
524
- // isSelected={selectedIds.has(task.id)}
525
- // onSelect={handleSelect}
526
- // onDragStart={handleDragStart}
527
- // onStatusChange={handleStatusChange}
528
- // zoom={1}
529
- // />
530
- // )
531
- // )}
532
- // {localDocuments.map((doc) =>
533
- // renderItem(doc.id, doc.x, doc.y,
534
- // <DocumentNode
535
- // {...doc}
536
- // isSelected={selectedIds.has(doc.id)}
537
- // onSelect={handleSelect}
538
- // onDragStart={handleDragStart}
539
- // />
540
- // )
541
- // )}
542
- // </div>
543
- // </div>
544
- // );
545
- // }
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState, useEffect, useRef } from "react";
4
+ import TaskNode from "./custom-node";
5
+ import DocumentNode from "./document-node";
6
+ // ─── Component ────────────────────────────────────────────────────────────────
7
+ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, onDocumentsUpdate, canvasZoom = 1, canvasViewport = { x: 0, y: 0 }, selectionBox = null, selectedCanvasObjects = [], fabricCanvas, }) {
8
+ const [localTasks, setLocalTasks] = useState(tasks);
9
+ const [localDocuments, setLocalDocuments] = useState(documents);
10
+ const [selectedIds, setSelectedIds] = useState(new Set());
11
+ const [dragging, setDragging] = useState(null);
12
+ const [canvasReady, setCanvasReady] = useState(false);
13
+ const nodeClipboardRef = useRef({
14
+ tasks: [],
15
+ documents: [],
16
+ });
17
+ const dragStateRef = useRef({
18
+ isDragging: false,
19
+ itemIds: [],
20
+ startPositions: new Map(),
21
+ canvasObjectsStartPos: new Map(),
22
+ offsetX: 0,
23
+ offsetY: 0,
24
+ });
25
+ const rafIdRef = useRef(null);
26
+ const overlayRef = useRef(null);
27
+ const selectedIdsRef = useRef(selectedIds);
28
+ selectedIdsRef.current = selectedIds;
29
+ // ── Sync props → local state ────────────────────────────────────────────────
30
+ useEffect(() => { setLocalTasks(tasks); }, [tasks]);
31
+ useEffect(() => { setLocalDocuments(documents); }, [documents]);
32
+ // effect — polls until fabricCanvas.current is available:
33
+ useEffect(() => {
34
+ if (canvasReady)
35
+ return;
36
+ if (fabricCanvas?.current) {
37
+ setCanvasReady(true);
38
+ return;
39
+ }
40
+ // Poll every 50ms until canvas is ready (only needed on first load)
41
+ const interval = setInterval(() => {
42
+ if (fabricCanvas?.current) {
43
+ setCanvasReady(true);
44
+ clearInterval(interval);
45
+ }
46
+ }, 50);
47
+ return () => clearInterval(interval);
48
+ }, [fabricCanvas, canvasReady]);
49
+ // ── Event Forwarding (Fixes Zooming on Nodes) ───────────────────────────────
50
+ const handleOverlayWheel = (e) => {
51
+ if (e.ctrlKey || e.metaKey || e.shiftKey) {
52
+ const canvas = fabricCanvas?.current;
53
+ if (!canvas)
54
+ return;
55
+ const nativeEvent = e.nativeEvent;
56
+ // getScenePoint handles the transformation from screen to canvas space
57
+ const scenePoint = canvas.getScenePoint(nativeEvent);
58
+ // Viewport point is simply the mouse position relative to the canvas element
59
+ const rect = canvas.getElement().getBoundingClientRect();
60
+ const viewportPoint = {
61
+ x: nativeEvent.clientX - rect.left,
62
+ y: nativeEvent.clientY - rect.top,
63
+ };
64
+ // We cast to 'any' here because we are manually triggering an internal
65
+ // event bus, and Fabric's internal types for .fire() can be overly strict.
66
+ canvas.fire("mouse:wheel", {
67
+ e: nativeEvent,
68
+ scenePoint,
69
+ viewportPoint,
70
+ });
71
+ e.preventDefault();
72
+ e.stopPropagation();
73
+ }
74
+ };
75
+ useEffect(() => {
76
+ const overlayEl = overlayRef.current;
77
+ const canvas = fabricCanvas?.current;
78
+ if (!overlayEl || !canvas)
79
+ return;
80
+ const handleGlobalWheel = (e) => {
81
+ // Check if the user is hovering over an element that has pointer-events: auto
82
+ // (meaning they are hovering over a Task or Document)
83
+ const target = e.target;
84
+ const isOverNode = target !== overlayEl;
85
+ if ((e.ctrlKey || e.metaKey) && isOverNode) {
86
+ // 1. Prevent Browser Zoom immediately
87
+ e.preventDefault();
88
+ e.stopPropagation();
89
+ // 2. Calculate coordinates for Fabric
90
+ const scenePoint = canvas.getScenePoint(e);
91
+ const rect = canvas.getElement().getBoundingClientRect();
92
+ const viewportPoint = {
93
+ x: e.clientX - rect.left,
94
+ y: e.clientY - rect.top,
95
+ };
96
+ // 3. Manually fire the event into Fabric
97
+ canvas.fire("mouse:wheel", {
98
+ e: e,
99
+ scenePoint,
100
+ viewportPoint,
101
+ });
102
+ }
103
+ };
104
+ // CRITICAL: { passive: false } allows us to cancel the browser's zoom
105
+ overlayEl.addEventListener("wheel", handleGlobalWheel, { passive: false });
106
+ return () => {
107
+ overlayEl.removeEventListener("wheel", handleGlobalWheel);
108
+ };
109
+ }, [fabricCanvas, canvasZoom, canvasReady]); // Re-bind when zoom changes to keep closure fresh
110
+ // ── Fabric → Overlay Sync (Fixes Dragging from Fabric area) ──────────────────
111
+ useEffect(() => {
112
+ const canvas = fabricCanvas?.current;
113
+ if (!canvas)
114
+ return;
115
+ const handleObjectMoving = (e) => {
116
+ const target = e.transform?.target || e.target;
117
+ if (!target)
118
+ return;
119
+ const deltaX = target.left - (target._prevLeft ?? target.left);
120
+ const deltaY = target.top - (target._prevTop ?? target.top);
121
+ target._prevLeft = target.left;
122
+ target._prevTop = target.top;
123
+ if (deltaX === 0 && deltaY === 0)
124
+ return;
125
+ // ── Read from ref — always fresh, never stale ──
126
+ const sel = selectedIdsRef.current;
127
+ setLocalTasks((prev) => prev.map((t) => sel.has(t.id) ? { ...t, x: t.x + deltaX, y: t.y + deltaY } : t));
128
+ setLocalDocuments((prev) => prev.map((d) => sel.has(d.id) ? { ...d, x: d.x + deltaX, y: d.y + deltaY } : d));
129
+ };
130
+ const handleMouseDown = (e) => {
131
+ const target = e.target;
132
+ if (target) {
133
+ target._prevLeft = target.left;
134
+ target._prevTop = target.top;
135
+ }
136
+ if (!target) {
137
+ setSelectedIds(new Set());
138
+ return;
139
+ }
140
+ // At zoom=1 with identity VPT, getActiveObject() can return null before
141
+ // Fabric updates _activeObject. Use e.transform as the primary check —
142
+ // it is populated by Fabric's hit-test regardless of zoom level.
143
+ const transformTarget = e.transform?.target;
144
+ const activeObject = canvas.getActiveObject();
145
+ const activeObjects = canvas.getActiveObjects();
146
+ const isPartOfActiveSelection = transformTarget === target || // most reliable — direct from event
147
+ activeObject === target || // selection box group
148
+ activeObjects.includes(target); // individual object in multi-select
149
+ if (!isPartOfActiveSelection) {
150
+ setSelectedIds(new Set());
151
+ }
152
+ };
153
+ const handleSelectionCleared = () => {
154
+ setSelectedIds(new Set());
155
+ };
156
+ canvas.on("object:moving", handleObjectMoving);
157
+ canvas.on("mouse:down", handleMouseDown);
158
+ canvas.on("selection:cleared", handleSelectionCleared);
159
+ return () => {
160
+ canvas.off("object:moving", handleObjectMoving);
161
+ canvas.off("mouse:down", handleMouseDown);
162
+ canvas.off("selection:cleared", handleSelectionCleared);
163
+ };
164
+ // ── selectedIds REMOVED from deps — read via selectedIdsRef instead ──────
165
+ // Having selectedIds here caused the effect to re-register on every selection
166
+ // change, creating a new closure each time. The second drag captured a stale
167
+ // or empty selectedIds from the closure at re-registration time.
168
+ }, [canvasZoom, fabricCanvas, canvasReady]);
169
+ // ── Helpers ─────────────────────────────────────────────────────────────────
170
+ const getItemPosition = (id) => {
171
+ const task = localTasks.find((t) => t.id === id);
172
+ if (task)
173
+ return { x: task.x, y: task.y };
174
+ const doc = localDocuments.find((d) => d.id === id);
175
+ if (doc)
176
+ return { x: doc.x, y: doc.y };
177
+ return undefined;
178
+ };
179
+ const isItemInSelectionBox = (x, y, width, height, box) => {
180
+ const itemX1 = x * canvasZoom + canvasViewport.x;
181
+ const itemY1 = y * canvasZoom + canvasViewport.y;
182
+ const itemX2 = itemX1 + width * canvasZoom;
183
+ const itemY2 = itemY1 + height * canvasZoom;
184
+ const boxX1 = Math.min(box.x1, box.x2);
185
+ const boxY1 = Math.min(box.y1, box.y2);
186
+ const boxX2 = Math.max(box.x1, box.x2);
187
+ const boxY2 = Math.max(box.y1, box.y2);
188
+ return !(boxX2 < itemX1 || boxX1 > itemX2 || boxY2 < itemY1 || boxY1 > itemY2);
189
+ };
190
+ // ── Selection box detection ──────────────────────────────────────────────────
191
+ useEffect(() => {
192
+ if (!selectionBox)
193
+ return;
194
+ // ── O(n) single pass no sort, no join, no extra allocations ──
195
+ const newSelected = new Set();
196
+ for (const task of localTasks) {
197
+ if (isItemInSelectionBox(task.x, task.y, 300, 140, selectionBox))
198
+ newSelected.add(task.id);
199
+ }
200
+ for (const doc of localDocuments) {
201
+ if (isItemInSelectionBox(doc.x, doc.y, 320, 160, selectionBox))
202
+ newSelected.add(doc.id);
203
+ }
204
+ // ── O(n) equality check: size first (fast path), then membership ──
205
+ setSelectedIds((prev) => {
206
+ if (prev.size !== newSelected.size)
207
+ return newSelected;
208
+ for (const id of newSelected) {
209
+ if (!prev.has(id))
210
+ return newSelected; // found a difference, swap
211
+ }
212
+ return prev; // identical — return same reference, no re-render
213
+ });
214
+ }, [selectionBox, localTasks, localDocuments, canvasZoom, canvasViewport]);
215
+ // ── Drag start (HTML Node side) ──────────────────────────────────────────────
216
+ // Helper to extract coordinates regardless of event type
217
+ const getPointerEvent = (e) => {
218
+ if ('touches' in e && e.touches.length > 0)
219
+ return e.touches[0];
220
+ return e;
221
+ };
222
+ const handleDragStart = (itemId, e) => {
223
+ // 1. Safety check for the Fabric instance
224
+ const canvas = fabricCanvas?.current;
225
+ if (!canvas)
226
+ return;
227
+ // 2. Normalize the event (Touch vs Mouse)
228
+ if (e.cancelable)
229
+ e.preventDefault();
230
+ const pointer = getPointerEvent(e);
231
+ // 3. Determine which items are being dragged
232
+ // selection update DOES NOT trigger before drag snapshot
233
+ let itemsToDrag;
234
+ if (selectedIds.has(itemId)) {
235
+ itemsToDrag = Array.from(selectedIds);
236
+ }
237
+ else {
238
+ itemsToDrag = [itemId];
239
+ }
240
+ // 4. Capture current World Transform (Zoom & Pan)
241
+ // We read directly from the canvas to ensure zero-frame lag
242
+ const vpt = canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
243
+ const liveZoom = vpt[0];
244
+ const liveVpX = vpt[4];
245
+ const liveVpY = vpt[5];
246
+ // 5. Convert the Click Position from Screen Pixels to World Units
247
+ const clickWorldX = (pointer.clientX - liveVpX) / liveZoom;
248
+ const clickWorldY = (pointer.clientY - liveVpY) / liveZoom;
249
+ // 6. Get the clicked item's current World Position
250
+ const clickedPos = getItemPosition(itemId);
251
+ if (!clickedPos)
252
+ return;
253
+ // 7. Calculate the Offset in WORLD UNITS
254
+ // This is the distance from the mouse to the node's top-left in the infinite grid.
255
+ // This value remains constant even if you zoom during the drag.
256
+ const worldOffsetX = clickWorldX - clickedPos.x;
257
+ const worldOffsetY = clickWorldY - clickedPos.y;
258
+ // 8. Snapshot starting positions for all selected HTML nodes
259
+ const startPositions = new Map();
260
+ itemsToDrag.forEach((id) => {
261
+ const pos = getItemPosition(id);
262
+ if (pos)
263
+ startPositions.set(id, pos);
264
+ });
265
+ // 9. Snapshot starting positions for all selected Fabric objects
266
+ const canvasObjectsStartPos = new Map();
267
+ selectedCanvasObjects.forEach((obj) => {
268
+ canvasObjectsStartPos.set(obj, { left: obj.left || 0, top: obj.top || 0 });
269
+ });
270
+ // 10. Commit to the ref for the requestAnimationFrame loop
271
+ dragStateRef.current = {
272
+ isDragging: true,
273
+ itemIds: itemsToDrag,
274
+ startPositions,
275
+ canvasObjectsStartPos,
276
+ offsetX: clickWorldX, // Now stored as World Units
277
+ offsetY: clickWorldY, // Now stored as World Units
278
+ };
279
+ if (!selectedIds.has(itemId) && dragStateRef.current.itemIds.length === 0) {
280
+ setSelectedIds(new Set([itemId]));
281
+ }
282
+ // 11. Trigger UI states
283
+ setDragging({ itemIds: itemsToDrag });
284
+ document.body.style.cursor = "grabbing";
285
+ document.body.style.userSelect = "none";
286
+ document.body.style.touchAction = "none";
287
+ };
288
+ // ── Drag move (HTML Node side) ───────────────────────────────────────────────
289
+ useEffect(() => {
290
+ if (!dragging)
291
+ return;
292
+ // Inside the useEffect that watches [dragging, localTasks, localDocuments, fabricCanvas]
293
+ const handleMove = (e) => {
294
+ if (!dragStateRef.current.isDragging)
295
+ return;
296
+ if (e.cancelable)
297
+ e.preventDefault();
298
+ const pointer = getPointerEvent(e);
299
+ // 1. Throttle updates using requestAnimationFrame for 120Hz/144Hz screen support
300
+ if (rafIdRef.current !== null)
301
+ cancelAnimationFrame(rafIdRef.current);
302
+ rafIdRef.current = requestAnimationFrame(() => {
303
+ const { itemIds, startPositions, canvasObjectsStartPos, offsetX, offsetY } = dragStateRef.current;
304
+ const canvas = fabricCanvas?.current;
305
+ if (!canvas)
306
+ return;
307
+ // 2. Read the "Source of Truth" transform from the canvas
308
+ const vpt = canvas.viewportTransform;
309
+ const liveZoom = vpt[0]; // Scale
310
+ const liveVpX = vpt[4]; // Pan X
311
+ const liveVpY = vpt[5]; // Pan Y
312
+ // 3. Convert current Mouse Screen Position → World Position
313
+ const currentWorldX = (pointer.clientX - liveVpX) / liveZoom;
314
+ const currentWorldY = (pointer.clientY - liveVpY) / liveZoom;
315
+ // 4. Calculate where the "Anchor" node should be in World Units
316
+ // (Current Mouse World - Initial World Offset from Start)
317
+ const deltaX = currentWorldX - offsetX;
318
+ const deltaY = currentWorldY - offsetY;
319
+ if (itemIds.length > 0) {
320
+ console.groupCollapsed(`Dragging Node: ${itemIds[0]}`);
321
+ console.log("Screen Mouse:", { x: pointer.clientX, y: pointer.clientY });
322
+ console.log("World Mouse:", { x: currentWorldX.toFixed(2), y: currentWorldY.toFixed(2) });
323
+ console.log("Canvas Zoom:", liveZoom.toFixed(2));
324
+ console.log("New Node Pos:", { x: deltaX.toFixed(2), y: deltaY.toFixed(2) });
325
+ console.groupEnd();
326
+ }
327
+ // 5. Calculate the Movement Delta in World Units
328
+ // We compare where the first item started vs where it is now.
329
+ const firstId = itemIds[0];
330
+ const firstStart = startPositions.get(firstId);
331
+ if (!firstStart)
332
+ return;
333
+ // The real problem of task jumps
334
+ // const deltaX = deltaX - firstStart.x;
335
+ // 6. Update HTML Nodes (Batching these into one state update)
336
+ setLocalTasks((prev) => prev.map((t) => itemIds.includes(t.id) ? {
337
+ ...t,
338
+ x: (startPositions.get(t.id)?.x ?? t.x) + deltaX,
339
+ y: (startPositions.get(t.id)?.y ?? t.y) + deltaY,
340
+ } : t));
341
+ setLocalDocuments((prev) => prev.map((d) => itemIds.includes(d.id) ? {
342
+ ...d,
343
+ x: (startPositions.get(d.id)?.x ?? d.x) + deltaX,
344
+ y: (startPositions.get(d.id)?.y ?? d.y) + deltaY,
345
+ } : d));
346
+ // 7. Sync Fabric Objects (Imperative update for performance)
347
+ canvasObjectsStartPos.forEach((startPos, obj) => {
348
+ obj.set({
349
+ left: startPos.left + deltaX,
350
+ top: startPos.top + deltaY,
351
+ });
352
+ obj.setCoords(); // Required for selection/intersection accuracy
353
+ });
354
+ // 8. Single render call for all Fabric changes
355
+ canvas.requestRenderAll();
356
+ });
357
+ };
358
+ const handleEnd = () => {
359
+ if (rafIdRef.current !== null)
360
+ cancelAnimationFrame(rafIdRef.current);
361
+ dragStateRef.current.isDragging = false;
362
+ setDragging(null);
363
+ document.body.style.cursor = "";
364
+ document.body.style.userSelect = "";
365
+ document.body.style.touchAction = "";
366
+ onTasksUpdate?.(localTasks);
367
+ onDocumentsUpdate?.(localDocuments);
368
+ };
369
+ window.addEventListener("mousemove", handleMove, { passive: false });
370
+ window.addEventListener("mouseup", handleEnd);
371
+ window.addEventListener("touchmove", handleMove, { passive: false });
372
+ window.addEventListener("touchend", handleEnd);
373
+ window.addEventListener("touchcancel", handleEnd);
374
+ return () => {
375
+ window.removeEventListener("mousemove", handleMove);
376
+ window.removeEventListener("mouseup", handleEnd);
377
+ window.removeEventListener("touchmove", handleMove);
378
+ window.removeEventListener("touchend", handleEnd);
379
+ window.removeEventListener("touchcancel", handleEnd);
380
+ };
381
+ }, [dragging, localTasks, localDocuments, fabricCanvas]);
382
+ // ── Selection, Status, Keyboard Logic ────────────────────────────────────────
383
+ const handleSelect = (id, e) => {
384
+ if (e?.shiftKey || e?.ctrlKey || e?.metaKey) {
385
+ setSelectedIds((prev) => {
386
+ const next = new Set(prev);
387
+ next.has(id) ? next.delete(id) : next.add(id);
388
+ return next;
389
+ });
390
+ }
391
+ else {
392
+ setSelectedIds(new Set([id]));
393
+ }
394
+ };
395
+ const handleStatusChange = (taskId, newStatus) => {
396
+ const updated = localTasks.map((t) => (t.id === taskId ? { ...t, status: newStatus } : t));
397
+ setLocalTasks(updated);
398
+ onTasksUpdate?.(updated);
399
+ };
400
+ useEffect(() => {
401
+ const handleKeyDown = (e) => {
402
+ // Don't trigger if typing in input
403
+ if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement)
404
+ return;
405
+ // Select All
406
+ if ((e.ctrlKey || e.metaKey) && e.key === "a") {
407
+ e.preventDefault();
408
+ setSelectedIds(new Set([...localTasks.map((t) => t.id), ...localDocuments.map((d) => d.id)]));
409
+ }
410
+ // Clear selection
411
+ if (e.key === "Escape") {
412
+ setSelectedIds(new Set());
413
+ }
414
+ // ← ADD THIS: Delete selected nodes
415
+ if ((e.key === "Delete" || e.key === "Backspace") && selectedIds.size > 0) {
416
+ e.preventDefault();
417
+ const updatedTasks = localTasks.filter((t) => !selectedIds.has(t.id));
418
+ const updatedDocs = localDocuments.filter((d) => !selectedIds.has(d.id));
419
+ setLocalTasks(updatedTasks);
420
+ setLocalDocuments(updatedDocs);
421
+ setSelectedIds(new Set());
422
+ onTasksUpdate?.(updatedTasks);
423
+ onDocumentsUpdate?.(updatedDocs);
424
+ }
425
+ };
426
+ window.addEventListener("keydown", handleKeyDown);
427
+ return () => window.removeEventListener("keydown", handleKeyDown);
428
+ }, [localTasks, localDocuments, selectedIds, onTasksUpdate, onDocumentsUpdate]);
429
+ // ── Render helper ────────────────────────────────────────────────────────────
430
+ const renderItem = (id, x, y, children) => {
431
+ const screenX = x * canvasZoom;
432
+ const screenY = y * canvasZoom;
433
+ // 1. Detect if the user is interacting with the canvas at all
434
+ // 'dragging' is your existing state.
435
+ // You might want to pass 'isZooming' or 'isPanning' from your main canvas component here.
436
+ const isDragging = dragging?.itemIds.includes(id);
437
+ return (_jsx("div", { className: "pointer-events-auto absolute", style: {
438
+ left: 0,
439
+ top: 0,
440
+ // 2. Use translate3d for GPU performance
441
+ transform: `translate3d(${screenX}px, ${screenY}px, 0) scale(${canvasZoom})`,
442
+ transformOrigin: "top left",
443
+ // 3. THE FIX: Remove transition entirely during any viewport change
444
+ // Any 'ease' during zoom causes the "shaking" behavior.
445
+ transition: "none",
446
+ // 4. Optimization
447
+ willChange: "transform",
448
+ zIndex: isDragging ? 1000 : 1,
449
+ }, children: children }, id));
450
+ };
451
+ return (_jsx("div", { ref: overlayRef, className: "absolute inset-0 pointer-events-none", style: { zIndex: 50 }, onWheel: handleOverlayWheel, onClick: (e) => {
452
+ if (e.target === e.currentTarget)
453
+ setSelectedIds(new Set());
454
+ }, children: _jsxs("div", { className: "absolute top-0 left-0 pointer-events-none", style: {
455
+ transform: `translate(${canvasViewport.x}px, ${canvasViewport.y}px)`,
456
+ transformOrigin: "top left",
457
+ }, children: [localTasks.map((task) => renderItem(task.id, task.x, task.y, _jsx(TaskNode, { ...task, isSelected: selectedIds.has(task.id), onSelect: handleSelect, onDragStart: handleDragStart, onStatusChange: handleStatusChange, zoom: 1 }))), localDocuments.map((doc) => renderItem(doc.id, doc.x, doc.y, _jsx(DocumentNode, { ...doc, isSelected: selectedIds.has(doc.id), onSelect: handleSelect, onDragStart: handleDragStart })))] }) }));
458
+ }