@@ -28,11 +28,9 @@ import {
28
28
useSensors ,
29
29
} from "@dnd-kit/core" ;
30
30
import {
31
- type AnimateLayoutChanges ,
32
31
SortableContext ,
33
32
type SortableContextProps ,
34
33
arrayMove ,
35
- defaultAnimateLayoutChanges ,
36
34
useSortable ,
37
35
verticalListSortingStrategy ,
38
36
} from "@dnd-kit/sortable" ;
@@ -177,8 +175,6 @@ interface KanbanContextValue<T> {
177
175
setActiveId : ( id : UniqueIdentifier | null ) => void ;
178
176
getItemValue : ( item : T ) => UniqueIdentifier ;
179
177
flatCursor : boolean ;
180
- clonedItems : Record < UniqueIdentifier , T [ ] > | null ;
181
- setClonedItems : ( items : Record < UniqueIdentifier , T [ ] > | null ) => void ;
182
178
}
183
179
184
180
const KanbanContext = React . createContext < KanbanContextValue < unknown > | null > (
@@ -228,25 +224,11 @@ function Kanban<T>(props: KanbanProps<T>) {
228
224
} = props ;
229
225
230
226
const [ activeId , setActiveId ] = React . useState < UniqueIdentifier | null > ( null ) ;
231
- const [ clonedItems , setClonedItems ] = React . useState < Record <
232
- UniqueIdentifier ,
233
- T [ ]
234
- > | null > ( null ) ;
235
227
const lastOverIdRef = React . useRef < UniqueIdentifier | null > ( null ) ;
236
- const isMovedToNewContainerRef = React . useRef ( false ) ;
237
-
228
+ const isShiftingRef = React . useRef ( false ) ;
238
229
const sensors = useSensors (
239
- useSensor ( MouseSensor , {
240
- activationConstraint : {
241
- distance : 8 ,
242
- } ,
243
- } ) ,
244
- useSensor ( TouchSensor , {
245
- activationConstraint : {
246
- delay : 100 ,
247
- tolerance : 8 ,
248
- } ,
249
- } ) ,
230
+ useSensor ( MouseSensor ) ,
231
+ useSensor ( TouchSensor ) ,
250
232
useSensor ( KeyboardSensor , {
251
233
coordinateGetter : coordinateGetter ,
252
234
} ) ,
@@ -281,7 +263,7 @@ function Kanban<T>(props: KanbanProps<T>) {
281
263
[ value , getItemValue ] ,
282
264
) ;
283
265
284
- const collisionDetectionStrategy : CollisionDetection = React . useCallback (
266
+ const collisionDetection : CollisionDetection = React . useCallback (
285
267
( args ) => {
286
268
if ( activeId && activeId in value ) {
287
269
return closestCenter ( {
@@ -300,7 +282,7 @@ function Kanban<T>(props: KanbanProps<T>) {
300
282
let overId = getFirstCollision ( intersections , "id" ) ;
301
283
302
284
if ( ! overId ) {
303
- if ( isMovedToNewContainerRef . current ) {
285
+ if ( isShiftingRef . current ) {
304
286
lastOverIdRef . current = activeId ;
305
287
}
306
288
return lastOverIdRef . current ? [ { id : lastOverIdRef . current } ] : [ ] ;
@@ -332,24 +314,6 @@ function Kanban<T>(props: KanbanProps<T>) {
332
314
[ activeId , value , getItemValue ] ,
333
315
) ;
334
316
335
- const onDragStart = React . useCallback (
336
- ( { active } : { active : { id : UniqueIdentifier } } ) => {
337
- setActiveId ( active . id ) ;
338
- setClonedItems ( value ) ;
339
- isMovedToNewContainerRef . current = false ;
340
- } ,
341
- [ value ] ,
342
- ) ;
343
-
344
- const onDragCancel = React . useCallback ( ( ) => {
345
- if ( clonedItems ) {
346
- onValueChange ?.( clonedItems ) ;
347
- }
348
- setActiveId ( null ) ;
349
- setClonedItems ( null ) ;
350
- isMovedToNewContainerRef . current = false ;
351
- } , [ clonedItems , onValueChange ] ) ;
352
-
353
317
const onDragOver = React . useCallback (
354
318
( event : DragOverEvent ) => {
355
319
const { active, over } = event ;
@@ -379,8 +343,6 @@ function Kanban<T>(props: KanbanProps<T>) {
379
343
const activeItem = activeItems [ activeIndex ] ;
380
344
if ( ! activeItem ) return ;
381
345
382
- isMovedToNewContainerRef . current = true ;
383
-
384
346
const updatedItems = {
385
347
...value ,
386
348
[ activeContainer ] : activeItems . filter (
@@ -400,7 +362,6 @@ function Kanban<T>(props: KanbanProps<T>) {
400
362
401
363
if ( ! over ) {
402
364
setActiveId ( null ) ;
403
- isMovedToNewContainerRef . current = false ;
404
365
return ;
405
366
}
406
367
@@ -409,15 +370,13 @@ function Kanban<T>(props: KanbanProps<T>) {
409
370
410
371
if ( ! activeContainer || ! overContainer ) {
411
372
setActiveId ( null ) ;
412
- isMovedToNewContainerRef . current = false ;
413
373
return ;
414
374
}
415
375
416
376
if ( activeContainer === overContainer ) {
417
377
const items = value [ activeContainer ] ;
418
378
if ( ! items ) {
419
379
setActiveId ( null ) ;
420
- isMovedToNewContainerRef . current = false ;
421
380
return ;
422
381
}
423
382
@@ -440,7 +399,6 @@ function Kanban<T>(props: KanbanProps<T>) {
440
399
}
441
400
442
401
setActiveId ( null ) ;
443
- isMovedToNewContainerRef . current = false ;
444
402
onMove ?.( event ) ;
445
403
} ,
446
404
[ value , getContainer , getItemValue , onValueChange , onMove ] ,
@@ -457,8 +415,6 @@ function Kanban<T>(props: KanbanProps<T>) {
457
415
setActiveId,
458
416
getItemValue,
459
417
flatCursor,
460
- clonedItems,
461
- setClonedItems,
462
418
} ) ,
463
419
[
464
420
id ,
@@ -469,7 +425,6 @@ function Kanban<T>(props: KanbanProps<T>) {
469
425
orientation ,
470
426
getItemValue ,
471
427
flatCursor ,
472
- clonedItems ,
473
428
] ,
474
429
) ;
475
430
@@ -479,19 +434,23 @@ function Kanban<T>(props: KanbanProps<T>) {
479
434
id = { id }
480
435
modifiers = { modifiers }
481
436
sensors = { sensorsProp ?? sensors }
482
- collisionDetection = { collisionDetectionStrategy }
437
+ collisionDetection = { collisionDetection }
483
438
measuring = { {
484
439
droppable : {
485
440
strategy : MeasuringStrategy . Always ,
486
441
} ,
487
442
} }
488
- onDragStart = { composeEventHandlers ( kanbanProps . onDragStart , onDragStart ) }
443
+ onDragStart = { composeEventHandlers (
444
+ kanbanProps . onDragStart ,
445
+ ( { active } ) => {
446
+ setActiveId ( active . id ) ;
447
+ } ,
448
+ ) }
489
449
onDragOver = { composeEventHandlers ( kanbanProps . onDragOver , onDragOver ) }
490
450
onDragEnd = { composeEventHandlers ( kanbanProps . onDragEnd , onDragEnd ) }
491
- onDragCancel = { composeEventHandlers (
492
- kanbanProps . onDragCancel ,
493
- onDragCancel ,
494
- ) }
451
+ onDragCancel = { composeEventHandlers ( kanbanProps . onDragCancel , ( ) => {
452
+ setActiveId ( null ) ;
453
+ } ) }
495
454
{ ...kanbanProps }
496
455
/>
497
456
</ KanbanContext . Provider >
0 commit comments