@mhamz.01/easyflow-whiteboard 2.122.0 → 2.124.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,3 +1,4 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { FabricObject, Canvas } from "fabric";
|
|
2
3
|
export interface Task {
|
|
3
4
|
id: string;
|
|
@@ -40,6 +41,6 @@ interface CanvasOverlayLayerProps {
|
|
|
40
41
|
fabricCanvas?: React.RefObject<Canvas | null>;
|
|
41
42
|
canvasReady?: boolean;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
export
|
|
44
|
+
declare const _default: React.NamedExoticComponent<CanvasOverlayLayerProps>;
|
|
45
|
+
export default _default;
|
|
45
46
|
//# sourceMappingURL=custom-node-overlay-layer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-node-overlay-layer.d.ts","sourceRoot":"","sources":["../../../src/components/node/custom-node-overlay-layer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"custom-node-overlay-layer.d.ts","sourceRoot":"","sources":["../../../src/components/node/custom-node-overlay-layer.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI9C,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,MAAM,CAAC;IACxC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,UAAU,uBAAuB;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACxC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACzE,qBAAqB,CAAC,EAAE,YAAY,EAAE,CAAC;IACvC,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;;AAaD,wBA6pBG"}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useState, useEffect, useRef } from "react";
|
|
3
|
+
import React, { useState, useEffect, useRef } from "react";
|
|
4
4
|
import TaskNode from "./custom-node";
|
|
5
5
|
import DocumentNode from "./document-node";
|
|
6
6
|
// ─── Component ────────────────────────────────────────────────────────────────
|
|
7
|
-
export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, onDocumentsUpdate, canvasZoom = 1, canvasViewport = { x: 0, y: 0 }, selectionBox = null, selectedCanvasObjects = [], fabricCanvas, }) {
|
|
7
|
+
export default React.memo(function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, onDocumentsUpdate, canvasZoom = 1, canvasViewport = { x: 0, y: 0 }, selectionBox = null, selectedCanvasObjects = [], fabricCanvas, canvasReady: canvasReadyProp = false, }) {
|
|
8
8
|
const [localTasks, setLocalTasks] = useState(tasks);
|
|
9
9
|
const [localDocuments, setLocalDocuments] = useState(documents);
|
|
10
10
|
const [selectedIds, setSelectedIds] = useState(new Set());
|
|
11
11
|
const [dragging, setDragging] = useState(null);
|
|
12
|
-
const [canvasReady, setCanvasReady] = useState(false);
|
|
13
12
|
const nodeClipboardRef = useRef({
|
|
14
13
|
tasks: [],
|
|
15
14
|
documents: [],
|
|
16
15
|
});
|
|
16
|
+
// ── Refs for always-current state (Issue 4) ────────────────────────────────
|
|
17
|
+
const localTasksRef = useRef(localTasks);
|
|
18
|
+
const localDocumentsRef = useRef(localDocuments);
|
|
19
|
+
const selectedIdsRef = useRef(selectedIds);
|
|
20
|
+
localTasksRef.current = localTasks;
|
|
21
|
+
localDocumentsRef.current = localDocuments;
|
|
22
|
+
selectedIdsRef.current = selectedIds;
|
|
17
23
|
const dragStateRef = useRef({
|
|
18
24
|
isDragging: false,
|
|
19
25
|
itemIds: [],
|
|
@@ -23,29 +29,18 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
23
29
|
offsetY: 0,
|
|
24
30
|
});
|
|
25
31
|
const rafIdRef = useRef(null);
|
|
32
|
+
const fabricMoveRafRef = useRef(null); // Issue 7
|
|
26
33
|
const overlayRef = useRef(null);
|
|
27
|
-
const selectedIdsRef = useRef(selectedIds);
|
|
28
|
-
selectedIdsRef.current = selectedIds;
|
|
29
34
|
// ── Sync props → local state ────────────────────────────────────────────────
|
|
30
|
-
useEffect(() => { setLocalTasks(tasks); }, [tasks]);
|
|
31
|
-
useEffect(() => { setLocalDocuments(documents); }, [documents]);
|
|
32
|
-
// effect — polls until fabricCanvas.current is available:
|
|
33
35
|
useEffect(() => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (fabricCanvas?.current) {
|
|
43
|
-
setCanvasReady(true);
|
|
44
|
-
clearInterval(interval);
|
|
45
|
-
}
|
|
46
|
-
}, 50);
|
|
47
|
-
return () => clearInterval(interval);
|
|
48
|
-
}, [fabricCanvas, canvasReady]);
|
|
36
|
+
setLocalTasks(tasks);
|
|
37
|
+
}, [tasks]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
setLocalDocuments(documents);
|
|
40
|
+
}, [documents]);
|
|
41
|
+
// Issue 2: Remove internal canvasReady state and polling — use prop directly
|
|
42
|
+
// No longer needed: const [canvasReady, setCanvasReady] = useState(false);
|
|
43
|
+
// No longer needed: polling useEffect with setInterval
|
|
49
44
|
// ── Event Forwarding (Fixes Zooming on Nodes) ───────────────────────────────
|
|
50
45
|
const handleOverlayWheel = (e) => {
|
|
51
46
|
if (e.ctrlKey || e.metaKey || e.shiftKey) {
|
|
@@ -61,7 +56,7 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
61
56
|
x: nativeEvent.clientX - rect.left,
|
|
62
57
|
y: nativeEvent.clientY - rect.top,
|
|
63
58
|
};
|
|
64
|
-
// We cast to 'any' here because we are manually triggering an internal
|
|
59
|
+
// We cast to 'any' here because we are manually triggering an internal
|
|
65
60
|
// event bus, and Fabric's internal types for .fire() can be overly strict.
|
|
66
61
|
canvas.fire("mouse:wheel", {
|
|
67
62
|
e: nativeEvent,
|
|
@@ -72,6 +67,7 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
72
67
|
e.stopPropagation();
|
|
73
68
|
}
|
|
74
69
|
};
|
|
70
|
+
// Issue 6: Remove canvasZoom from deps — not used in handler
|
|
75
71
|
useEffect(() => {
|
|
76
72
|
const overlayEl = overlayRef.current;
|
|
77
73
|
const canvas = fabricCanvas?.current;
|
|
@@ -106,12 +102,14 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
106
102
|
return () => {
|
|
107
103
|
overlayEl.removeEventListener("wheel", handleGlobalWheel);
|
|
108
104
|
};
|
|
109
|
-
}, [fabricCanvas,
|
|
105
|
+
}, [fabricCanvas, canvasReadyProp]); // Issue 6: removed canvasZoom
|
|
110
106
|
// ── Fabric → Overlay Sync (Fixes Dragging from Fabric area) ──────────────────
|
|
107
|
+
// Issue 5: Remove canvasZoom from deps — not used in handlers
|
|
111
108
|
useEffect(() => {
|
|
112
109
|
const canvas = fabricCanvas?.current;
|
|
113
110
|
if (!canvas)
|
|
114
111
|
return;
|
|
112
|
+
// Issue 7: Throttle handleObjectMoving with rAF gate
|
|
115
113
|
const handleObjectMoving = (e) => {
|
|
116
114
|
const target = e.transform?.target || e.target;
|
|
117
115
|
if (!target)
|
|
@@ -122,10 +120,19 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
122
120
|
target._prevTop = target.top;
|
|
123
121
|
if (deltaX === 0 && deltaY === 0)
|
|
124
122
|
return;
|
|
125
|
-
// ── Read from ref — always fresh, never stale ──
|
|
126
123
|
const sel = selectedIdsRef.current;
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
// Skip if frame already queued
|
|
125
|
+
if (fabricMoveRafRef.current !== null)
|
|
126
|
+
return;
|
|
127
|
+
fabricMoveRafRef.current = requestAnimationFrame(() => {
|
|
128
|
+
fabricMoveRafRef.current = null;
|
|
129
|
+
setLocalTasks((prev) => prev.map((t) => sel.has(t.id)
|
|
130
|
+
? { ...t, x: t.x + deltaX, y: t.y + deltaY }
|
|
131
|
+
: t));
|
|
132
|
+
setLocalDocuments((prev) => prev.map((d) => sel.has(d.id)
|
|
133
|
+
? { ...d, x: d.x + deltaX, y: d.y + deltaY }
|
|
134
|
+
: d));
|
|
135
|
+
});
|
|
129
136
|
};
|
|
130
137
|
const handleMouseDown = (e) => {
|
|
131
138
|
const target = e.target;
|
|
@@ -160,18 +167,17 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
160
167
|
canvas.off("object:moving", handleObjectMoving);
|
|
161
168
|
canvas.off("mouse:down", handleMouseDown);
|
|
162
169
|
canvas.off("selection:cleared", handleSelectionCleared);
|
|
170
|
+
if (fabricMoveRafRef.current !== null) {
|
|
171
|
+
cancelAnimationFrame(fabricMoveRafRef.current);
|
|
172
|
+
}
|
|
163
173
|
};
|
|
164
|
-
|
|
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]);
|
|
174
|
+
}, [fabricCanvas, canvasReadyProp]); // Issue 5: removed canvasZoom
|
|
169
175
|
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
170
176
|
const getItemPosition = (id) => {
|
|
171
|
-
const task =
|
|
177
|
+
const task = localTasksRef.current.find((t) => t.id === id);
|
|
172
178
|
if (task)
|
|
173
179
|
return { x: task.x, y: task.y };
|
|
174
|
-
const doc =
|
|
180
|
+
const doc = localDocumentsRef.current.find((d) => d.id === id);
|
|
175
181
|
if (doc)
|
|
176
182
|
return { x: doc.x, y: doc.y };
|
|
177
183
|
return undefined;
|
|
@@ -193,11 +199,11 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
193
199
|
return;
|
|
194
200
|
// ── O(n) single pass — no sort, no join, no extra allocations ──
|
|
195
201
|
const newSelected = new Set();
|
|
196
|
-
for (const task of
|
|
202
|
+
for (const task of localTasksRef.current) {
|
|
197
203
|
if (isItemInSelectionBox(task.x, task.y, 300, 140, selectionBox))
|
|
198
204
|
newSelected.add(task.id);
|
|
199
205
|
}
|
|
200
|
-
for (const doc of
|
|
206
|
+
for (const doc of localDocumentsRef.current) {
|
|
201
207
|
if (isItemInSelectionBox(doc.x, doc.y, 320, 160, selectionBox))
|
|
202
208
|
newSelected.add(doc.id);
|
|
203
209
|
}
|
|
@@ -215,7 +221,7 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
215
221
|
// ── Drag start (HTML Node side) ──────────────────────────────────────────────
|
|
216
222
|
// Helper to extract coordinates regardless of event type
|
|
217
223
|
const getPointerEvent = (e) => {
|
|
218
|
-
if (
|
|
224
|
+
if ("touches" in e && e.touches.length > 0)
|
|
219
225
|
return e.touches[0];
|
|
220
226
|
return e;
|
|
221
227
|
};
|
|
@@ -231,8 +237,8 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
231
237
|
// 3. Determine which items are being dragged
|
|
232
238
|
// selection update DOES NOT trigger before drag snapshot
|
|
233
239
|
let itemsToDrag;
|
|
234
|
-
if (
|
|
235
|
-
itemsToDrag = Array.from(
|
|
240
|
+
if (selectedIdsRef.current.has(itemId)) {
|
|
241
|
+
itemsToDrag = Array.from(selectedIdsRef.current);
|
|
236
242
|
}
|
|
237
243
|
else {
|
|
238
244
|
itemsToDrag = [itemId];
|
|
@@ -265,7 +271,10 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
265
271
|
// 9. Snapshot starting positions for all selected Fabric objects
|
|
266
272
|
const canvasObjectsStartPos = new Map();
|
|
267
273
|
selectedCanvasObjects.forEach((obj) => {
|
|
268
|
-
canvasObjectsStartPos.set(obj, {
|
|
274
|
+
canvasObjectsStartPos.set(obj, {
|
|
275
|
+
left: obj.left || 0,
|
|
276
|
+
top: obj.top || 0,
|
|
277
|
+
});
|
|
269
278
|
});
|
|
270
279
|
// 10. Commit to the ref for the requestAnimationFrame loop
|
|
271
280
|
dragStateRef.current = {
|
|
@@ -276,7 +285,7 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
276
285
|
offsetX: clickWorldX, // Now stored as World Units
|
|
277
286
|
offsetY: clickWorldY, // Now stored as World Units
|
|
278
287
|
};
|
|
279
|
-
if (!
|
|
288
|
+
if (!selectedIdsRef.current.has(itemId) && dragStateRef.current.itemIds.length === 0) {
|
|
280
289
|
setSelectedIds(new Set([itemId]));
|
|
281
290
|
}
|
|
282
291
|
// 11. Trigger UI states
|
|
@@ -286,10 +295,10 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
286
295
|
document.body.style.touchAction = "none";
|
|
287
296
|
};
|
|
288
297
|
// ── Drag move (HTML Node side) ───────────────────────────────────────────────
|
|
298
|
+
// Issue 3: Remove localTasks/localDocuments from deps — use refs instead
|
|
289
299
|
useEffect(() => {
|
|
290
300
|
if (!dragging)
|
|
291
301
|
return;
|
|
292
|
-
// Inside the useEffect that watches [dragging, localTasks, localDocuments, fabricCanvas]
|
|
293
302
|
const handleMove = (e) => {
|
|
294
303
|
if (!dragStateRef.current.isDragging)
|
|
295
304
|
return;
|
|
@@ -300,7 +309,7 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
300
309
|
if (rafIdRef.current !== null)
|
|
301
310
|
cancelAnimationFrame(rafIdRef.current);
|
|
302
311
|
rafIdRef.current = requestAnimationFrame(() => {
|
|
303
|
-
const { itemIds, startPositions, canvasObjectsStartPos, offsetX, offsetY } = dragStateRef.current;
|
|
312
|
+
const { itemIds, startPositions, canvasObjectsStartPos, offsetX, offsetY, } = dragStateRef.current;
|
|
304
313
|
const canvas = fabricCanvas?.current;
|
|
305
314
|
if (!canvas)
|
|
306
315
|
return;
|
|
@@ -316,33 +325,27 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
316
325
|
// (Current Mouse World - Initial World Offset from Start)
|
|
317
326
|
const deltaX = currentWorldX - offsetX;
|
|
318
327
|
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
328
|
// 5. Calculate the Movement Delta in World Units
|
|
328
329
|
// We compare where the first item started vs where it is now.
|
|
329
330
|
const firstId = itemIds[0];
|
|
330
331
|
const firstStart = startPositions.get(firstId);
|
|
331
332
|
if (!firstStart)
|
|
332
333
|
return;
|
|
333
|
-
// The real problem of task jumps
|
|
334
|
-
// const deltaX = deltaX - firstStart.x;
|
|
335
334
|
// 6. Update HTML Nodes (Batching these into one state update)
|
|
336
|
-
setLocalTasks((prev) => prev.map((t) => itemIds.includes(t.id)
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
335
|
+
setLocalTasks((prev) => prev.map((t) => itemIds.includes(t.id)
|
|
336
|
+
? {
|
|
337
|
+
...t,
|
|
338
|
+
x: (startPositions.get(t.id)?.x ?? t.x) + deltaX,
|
|
339
|
+
y: (startPositions.get(t.id)?.y ?? t.y) + deltaY,
|
|
340
|
+
}
|
|
341
|
+
: t));
|
|
342
|
+
setLocalDocuments((prev) => prev.map((d) => itemIds.includes(d.id)
|
|
343
|
+
? {
|
|
344
|
+
...d,
|
|
345
|
+
x: (startPositions.get(d.id)?.x ?? d.x) + deltaX,
|
|
346
|
+
y: (startPositions.get(d.id)?.y ?? d.y) + deltaY,
|
|
347
|
+
}
|
|
348
|
+
: d));
|
|
346
349
|
// 7. Sync Fabric Objects (Imperative update for performance)
|
|
347
350
|
canvasObjectsStartPos.forEach((startPos, obj) => {
|
|
348
351
|
obj.set({
|
|
@@ -355,6 +358,7 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
355
358
|
canvas.requestRenderAll();
|
|
356
359
|
});
|
|
357
360
|
};
|
|
361
|
+
// Issue 4: Use refs for always-current values
|
|
358
362
|
const handleEnd = () => {
|
|
359
363
|
if (rafIdRef.current !== null)
|
|
360
364
|
cancelAnimationFrame(rafIdRef.current);
|
|
@@ -363,8 +367,8 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
363
367
|
document.body.style.cursor = "";
|
|
364
368
|
document.body.style.userSelect = "";
|
|
365
369
|
document.body.style.touchAction = "";
|
|
366
|
-
onTasksUpdate?.(
|
|
367
|
-
onDocumentsUpdate?.(
|
|
370
|
+
onTasksUpdate?.(localTasksRef.current);
|
|
371
|
+
onDocumentsUpdate?.(localDocumentsRef.current);
|
|
368
372
|
};
|
|
369
373
|
window.addEventListener("mousemove", handleMove, { passive: false });
|
|
370
374
|
window.addEventListener("mouseup", handleEnd);
|
|
@@ -378,7 +382,7 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
378
382
|
window.removeEventListener("touchend", handleEnd);
|
|
379
383
|
window.removeEventListener("touchcancel", handleEnd);
|
|
380
384
|
};
|
|
381
|
-
}, [dragging,
|
|
385
|
+
}, [dragging, fabricCanvas]); // Issue 3: removed localTasks/localDocuments
|
|
382
386
|
// ── Selection, Status, Keyboard Logic ────────────────────────────────────────
|
|
383
387
|
const handleSelect = (id, e) => {
|
|
384
388
|
if (e?.shiftKey || e?.ctrlKey || e?.metaKey) {
|
|
@@ -393,29 +397,36 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
393
397
|
}
|
|
394
398
|
};
|
|
395
399
|
const handleStatusChange = (taskId, newStatus) => {
|
|
396
|
-
const updated =
|
|
400
|
+
const updated = localTasksRef.current.map((t) => t.id === taskId ? { ...t, status: newStatus } : t);
|
|
397
401
|
setLocalTasks(updated);
|
|
398
402
|
onTasksUpdate?.(updated);
|
|
399
403
|
};
|
|
404
|
+
// Issue 9: Use refs and only depend on stable callbacks
|
|
400
405
|
useEffect(() => {
|
|
401
406
|
const handleKeyDown = (e) => {
|
|
402
407
|
// Don't trigger if typing in input
|
|
403
|
-
if (e.target instanceof HTMLInputElement ||
|
|
408
|
+
if (e.target instanceof HTMLInputElement ||
|
|
409
|
+
e.target instanceof HTMLTextAreaElement)
|
|
404
410
|
return;
|
|
405
411
|
// Select All
|
|
406
412
|
if ((e.ctrlKey || e.metaKey) && e.key === "a") {
|
|
407
413
|
e.preventDefault();
|
|
408
|
-
setSelectedIds(new Set([
|
|
414
|
+
setSelectedIds(new Set([
|
|
415
|
+
...localTasksRef.current.map((t) => t.id),
|
|
416
|
+
...localDocumentsRef.current.map((d) => d.id),
|
|
417
|
+
]));
|
|
409
418
|
}
|
|
410
419
|
// Clear selection
|
|
411
420
|
if (e.key === "Escape") {
|
|
412
421
|
setSelectedIds(new Set());
|
|
413
422
|
}
|
|
414
|
-
//
|
|
415
|
-
if ((e.key === "Delete" || e.key === "Backspace") &&
|
|
423
|
+
// Delete selected nodes
|
|
424
|
+
if ((e.key === "Delete" || e.key === "Backspace") &&
|
|
425
|
+
selectedIdsRef.current.size > 0) {
|
|
416
426
|
e.preventDefault();
|
|
417
|
-
const
|
|
418
|
-
const
|
|
427
|
+
const sel = selectedIdsRef.current;
|
|
428
|
+
const updatedTasks = localTasksRef.current.filter((t) => !sel.has(t.id));
|
|
429
|
+
const updatedDocs = localDocumentsRef.current.filter((d) => !sel.has(d.id));
|
|
419
430
|
setLocalTasks(updatedTasks);
|
|
420
431
|
setLocalDocuments(updatedDocs);
|
|
421
432
|
setSelectedIds(new Set());
|
|
@@ -425,14 +436,12 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
425
436
|
};
|
|
426
437
|
window.addEventListener("keydown", handleKeyDown);
|
|
427
438
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
428
|
-
}, [
|
|
439
|
+
}, [onTasksUpdate, onDocumentsUpdate]); // Issue 9: only stable callbacks
|
|
429
440
|
// ── Render helper ────────────────────────────────────────────────────────────
|
|
430
441
|
const renderItem = (id, x, y, children) => {
|
|
431
442
|
const screenX = x * canvasZoom;
|
|
432
443
|
const screenY = y * canvasZoom;
|
|
433
444
|
// 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
445
|
const isDragging = dragging?.itemIds.includes(id);
|
|
437
446
|
return (_jsx("div", { className: "pointer-events-auto absolute", style: {
|
|
438
447
|
left: 0,
|
|
@@ -455,4 +464,19 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
455
464
|
transform: `translate(${canvasViewport.x}px, ${canvasViewport.y}px)`,
|
|
456
465
|
transformOrigin: "top left",
|
|
457
466
|
}, 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
|
-
}
|
|
467
|
+
}, (prev, next) => {
|
|
468
|
+
// Custom comparator — skip re-render if props are equal
|
|
469
|
+
// Return true to skip re-render, false to re-render
|
|
470
|
+
return (prev.tasks === next.tasks &&
|
|
471
|
+
prev.documents === next.documents &&
|
|
472
|
+
prev.canvasZoom === next.canvasZoom &&
|
|
473
|
+
prev.canvasViewport?.x === next.canvasViewport?.x &&
|
|
474
|
+
prev.canvasViewport?.y === next.canvasViewport?.y &&
|
|
475
|
+
prev.selectionBox === next.selectionBox &&
|
|
476
|
+
prev.selectedCanvasObjects === next.selectedCanvasObjects &&
|
|
477
|
+
prev.onTasksUpdate === next.onTasksUpdate &&
|
|
478
|
+
prev.onDocumentsUpdate === next.onDocumentsUpdate &&
|
|
479
|
+
prev.canvasReady === next.canvasReady
|
|
480
|
+
// fabricCanvas ref intentionally omitted — it's stable and doesn't need comparison
|
|
481
|
+
);
|
|
482
|
+
});
|