@mhamz.01/easyflow-whiteboard 2.80.0 → 2.81.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.
- package/dist/components/node/custom-node-overlay-fix.d.ts.map +1 -1
- package/dist/components/node/custom-node-overlay-fix.js +6 -0
- package/dist/components/node/custom-node-overlay-layer.d.ts +0 -44
- package/dist/components/node/custom-node-overlay-layer.d.ts.map +1 -1
- package/dist/components/node/custom-node-overlay-layer.js +545 -458
- package/dist/components/node/hooks/useWheelZoom.d.ts +5 -1
- package/dist/components/node/hooks/useWheelZoom.d.ts.map +1 -1
- package/dist/components/node/hooks/useWheelZoom.js +21 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-node-overlay-fix.d.ts","sourceRoot":"","sources":["../../../src/components/node/custom-node-overlay-fix.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAkB,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAQhF,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,KAAK,EACL,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,UAAc,EACd,cAA+B,EAC/B,YAAmB,EACnB,qBAA0B,EAC1B,YAAY,GACb,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"custom-node-overlay-fix.d.ts","sourceRoot":"","sources":["../../../src/components/node/custom-node-overlay-fix.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAkB,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAQhF,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,KAAK,EACL,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,UAAc,EACd,cAA+B,EAC/B,YAAmB,EACnB,qBAA0B,EAC1B,YAAY,GACb,EAAE,uBAAuB,2CA0SzB"}
|
|
@@ -11,6 +11,8 @@ import { useCanvasReady } from "./hooks/useCanvasReady";
|
|
|
11
11
|
import { useNodeSync } from "./hooks/useNodeSync";
|
|
12
12
|
export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, onDocumentsUpdate, canvasZoom = 1, canvasViewport = { x: 0, y: 0 }, selectionBox = null, selectedCanvasObjects = [], fabricCanvas, }) {
|
|
13
13
|
// ─── State Management ──────────────────────────────────────────────────
|
|
14
|
+
const [liveViewport, setLiveViewport] = useState(canvasViewport);
|
|
15
|
+
const [liveZoom, setLiveZoom] = useState(canvasZoom);
|
|
14
16
|
const [localTasks, setLocalTasks] = useState(tasks);
|
|
15
17
|
const [localDocuments, setLocalDocuments] = useState(documents);
|
|
16
18
|
const [selectedIds, setSelectedIds] = useState(new Set());
|
|
@@ -24,6 +26,10 @@ export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, on
|
|
|
24
26
|
fabricCanvas,
|
|
25
27
|
canvasZoom,
|
|
26
28
|
canvasReady,
|
|
29
|
+
onViewportChange: useCallback((viewport, zoom) => {
|
|
30
|
+
setLiveViewport(viewport);
|
|
31
|
+
setLiveZoom(zoom);
|
|
32
|
+
}, []),
|
|
27
33
|
});
|
|
28
34
|
const { dragStateRef: dragRef, rafIdRef, getPointerEvent, getViewportTransform, handleDragStart: handleDragStartHook, handleDragMove: handleDragMoveHook, handleDragEnd: handleDragEndHook, } = useNodeDrag({
|
|
29
35
|
selectedIds,
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
import { FabricObject, Canvas } from "fabric";
|
|
2
|
-
export interface Task {
|
|
3
|
-
id: string;
|
|
4
|
-
title: string;
|
|
5
|
-
status: "todo" | "in-progress" | "done";
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
assignee?: string;
|
|
9
|
-
project?: string;
|
|
10
|
-
priority?: "low" | "medium" | "high";
|
|
11
|
-
dueDate?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface Document {
|
|
14
|
-
id: string;
|
|
15
|
-
title: string;
|
|
16
|
-
project: string;
|
|
17
|
-
breadcrumb?: string[];
|
|
18
|
-
preview: string;
|
|
19
|
-
updatedAt?: string;
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
}
|
|
23
|
-
interface CanvasOverlayLayerProps {
|
|
24
|
-
tasks: Task[];
|
|
25
|
-
documents: Document[];
|
|
26
|
-
onTasksUpdate?: (tasks: Task[]) => void;
|
|
27
|
-
onDocumentsUpdate?: (documents: Document[]) => void;
|
|
28
|
-
canvasZoom?: number;
|
|
29
|
-
canvasViewport?: {
|
|
30
|
-
x: number;
|
|
31
|
-
y: number;
|
|
32
|
-
};
|
|
33
|
-
selectionBox?: {
|
|
34
|
-
x1: number;
|
|
35
|
-
y1: number;
|
|
36
|
-
x2: number;
|
|
37
|
-
y2: number;
|
|
38
|
-
} | null;
|
|
39
|
-
selectedCanvasObjects?: FabricObject[];
|
|
40
|
-
fabricCanvas?: React.RefObject<Canvas | null>;
|
|
41
|
-
canvasReady?: boolean;
|
|
42
|
-
}
|
|
43
|
-
export default function CanvasOverlayLayer({ tasks, documents, onTasksUpdate, onDocumentsUpdate, canvasZoom, canvasViewport, selectionBox, selectedCanvasObjects, fabricCanvas, }: CanvasOverlayLayerProps): import("react/jsx-runtime").JSX.Element;
|
|
44
|
-
export {};
|
|
45
1
|
//# 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":""}
|
|
@@ -1,458 +1,545 @@
|
|
|
1
|
-
"use
|
|
2
|
-
|
|
3
|
-
import { useState, useEffect, useRef } from "react";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
+
// }
|
|
@@ -4,8 +4,12 @@ interface UseWheelZoomProps {
|
|
|
4
4
|
fabricCanvas?: React.RefObject<Canvas | null>;
|
|
5
5
|
canvasZoom?: number;
|
|
6
6
|
canvasReady?: boolean;
|
|
7
|
+
onViewportChange: (viewport: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
}, zoom: number) => void;
|
|
7
11
|
}
|
|
8
|
-
export declare function useWheelZoom({ overlayRef, fabricCanvas, canvasZoom, canvasReady, }: UseWheelZoomProps): {
|
|
12
|
+
export declare function useWheelZoom({ overlayRef, fabricCanvas, canvasZoom, canvasReady, onViewportChange, }: UseWheelZoomProps): {
|
|
9
13
|
handleOverlayWheel: (e: React.WheelEvent) => void;
|
|
10
14
|
};
|
|
11
15
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWheelZoom.d.ts","sourceRoot":"","sources":["../../../../src/components/node/hooks/useWheelZoom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,UAAU,iBAAiB;IACvB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACrD,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useWheelZoom.d.ts","sourceRoot":"","sources":["../../../../src/components/node/hooks/useWheelZoom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,UAAU,iBAAiB;IACvB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACrD,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,EAAE,CAAC,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9E;AAED,wBAAgB,YAAY,CAAC,EAC3B,UAAU,EACV,YAAY,EACZ,UAAc,EACd,WAAmB,EACnB,gBAAgB,GACjB,EAAE,iBAAiB;4BAEa,KAAK,CAAC,UAAU;EAqFhD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
|
-
export function useWheelZoom({ overlayRef, fabricCanvas, canvasZoom = 1, canvasReady = false, }) {
|
|
2
|
+
export function useWheelZoom({ overlayRef, fabricCanvas, canvasZoom = 1, canvasReady = false, onViewportChange, }) {
|
|
3
3
|
// React event handler for overlay wheel
|
|
4
4
|
const handleOverlayWheel = (e) => {
|
|
5
5
|
if (e.ctrlKey || e.metaKey || e.shiftKey) {
|
|
@@ -22,6 +22,26 @@ export function useWheelZoom({ overlayRef, fabricCanvas, canvasZoom = 1, canvasR
|
|
|
22
22
|
e.stopPropagation();
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const canvas = fabricCanvas?.current;
|
|
27
|
+
if (!canvas || !canvasReady)
|
|
28
|
+
return;
|
|
29
|
+
// THE FIX: Listen to Fabric's internal render loop
|
|
30
|
+
// This fires immediately after Fabric moves, reducing the lag time
|
|
31
|
+
const syncViewport = () => {
|
|
32
|
+
const vpt = canvas.viewportTransform;
|
|
33
|
+
if (vpt) {
|
|
34
|
+
onViewportChange({ x: vpt[4], y: vpt[5] }, // Pan position
|
|
35
|
+
canvas.getZoom() // Zoom level
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
// Use 'after:render' for the tightest possible sync
|
|
40
|
+
canvas.on("after:render", syncViewport);
|
|
41
|
+
return () => {
|
|
42
|
+
canvas.off("after:render", syncViewport);
|
|
43
|
+
};
|
|
44
|
+
}, [fabricCanvas, canvasReady, onViewportChange]);
|
|
25
45
|
// Global wheel event for hovering over nodes
|
|
26
46
|
useEffect(() => {
|
|
27
47
|
const overlayEl = overlayRef.current;
|