Skip to content

Commit 8f876df

Browse files
committed
chore: revert
1 parent 4ecbc99 commit 8f876df

File tree

1 file changed

+15
-56
lines changed

1 file changed

+15
-56
lines changed

docs/registry/default/ui/kanban.tsx

+15-56
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ import {
2828
useSensors,
2929
} from "@dnd-kit/core";
3030
import {
31-
type AnimateLayoutChanges,
3231
SortableContext,
3332
type SortableContextProps,
3433
arrayMove,
35-
defaultAnimateLayoutChanges,
3634
useSortable,
3735
verticalListSortingStrategy,
3836
} from "@dnd-kit/sortable";
@@ -177,8 +175,6 @@ interface KanbanContextValue<T> {
177175
setActiveId: (id: UniqueIdentifier | null) => void;
178176
getItemValue: (item: T) => UniqueIdentifier;
179177
flatCursor: boolean;
180-
clonedItems: Record<UniqueIdentifier, T[]> | null;
181-
setClonedItems: (items: Record<UniqueIdentifier, T[]> | null) => void;
182178
}
183179

184180
const KanbanContext = React.createContext<KanbanContextValue<unknown> | null>(
@@ -228,25 +224,11 @@ function Kanban<T>(props: KanbanProps<T>) {
228224
} = props;
229225

230226
const [activeId, setActiveId] = React.useState<UniqueIdentifier | null>(null);
231-
const [clonedItems, setClonedItems] = React.useState<Record<
232-
UniqueIdentifier,
233-
T[]
234-
> | null>(null);
235227
const lastOverIdRef = React.useRef<UniqueIdentifier | null>(null);
236-
const isMovedToNewContainerRef = React.useRef(false);
237-
228+
const isShiftingRef = React.useRef(false);
238229
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),
250232
useSensor(KeyboardSensor, {
251233
coordinateGetter: coordinateGetter,
252234
}),
@@ -281,7 +263,7 @@ function Kanban<T>(props: KanbanProps<T>) {
281263
[value, getItemValue],
282264
);
283265

284-
const collisionDetectionStrategy: CollisionDetection = React.useCallback(
266+
const collisionDetection: CollisionDetection = React.useCallback(
285267
(args) => {
286268
if (activeId && activeId in value) {
287269
return closestCenter({
@@ -300,7 +282,7 @@ function Kanban<T>(props: KanbanProps<T>) {
300282
let overId = getFirstCollision(intersections, "id");
301283

302284
if (!overId) {
303-
if (isMovedToNewContainerRef.current) {
285+
if (isShiftingRef.current) {
304286
lastOverIdRef.current = activeId;
305287
}
306288
return lastOverIdRef.current ? [{ id: lastOverIdRef.current }] : [];
@@ -332,24 +314,6 @@ function Kanban<T>(props: KanbanProps<T>) {
332314
[activeId, value, getItemValue],
333315
);
334316

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-
353317
const onDragOver = React.useCallback(
354318
(event: DragOverEvent) => {
355319
const { active, over } = event;
@@ -379,8 +343,6 @@ function Kanban<T>(props: KanbanProps<T>) {
379343
const activeItem = activeItems[activeIndex];
380344
if (!activeItem) return;
381345

382-
isMovedToNewContainerRef.current = true;
383-
384346
const updatedItems = {
385347
...value,
386348
[activeContainer]: activeItems.filter(
@@ -400,7 +362,6 @@ function Kanban<T>(props: KanbanProps<T>) {
400362

401363
if (!over) {
402364
setActiveId(null);
403-
isMovedToNewContainerRef.current = false;
404365
return;
405366
}
406367

@@ -409,15 +370,13 @@ function Kanban<T>(props: KanbanProps<T>) {
409370

410371
if (!activeContainer || !overContainer) {
411372
setActiveId(null);
412-
isMovedToNewContainerRef.current = false;
413373
return;
414374
}
415375

416376
if (activeContainer === overContainer) {
417377
const items = value[activeContainer];
418378
if (!items) {
419379
setActiveId(null);
420-
isMovedToNewContainerRef.current = false;
421380
return;
422381
}
423382

@@ -440,7 +399,6 @@ function Kanban<T>(props: KanbanProps<T>) {
440399
}
441400

442401
setActiveId(null);
443-
isMovedToNewContainerRef.current = false;
444402
onMove?.(event);
445403
},
446404
[value, getContainer, getItemValue, onValueChange, onMove],
@@ -457,8 +415,6 @@ function Kanban<T>(props: KanbanProps<T>) {
457415
setActiveId,
458416
getItemValue,
459417
flatCursor,
460-
clonedItems,
461-
setClonedItems,
462418
}),
463419
[
464420
id,
@@ -469,7 +425,6 @@ function Kanban<T>(props: KanbanProps<T>) {
469425
orientation,
470426
getItemValue,
471427
flatCursor,
472-
clonedItems,
473428
],
474429
);
475430

@@ -479,19 +434,23 @@ function Kanban<T>(props: KanbanProps<T>) {
479434
id={id}
480435
modifiers={modifiers}
481436
sensors={sensorsProp ?? sensors}
482-
collisionDetection={collisionDetectionStrategy}
437+
collisionDetection={collisionDetection}
483438
measuring={{
484439
droppable: {
485440
strategy: MeasuringStrategy.Always,
486441
},
487442
}}
488-
onDragStart={composeEventHandlers(kanbanProps.onDragStart, onDragStart)}
443+
onDragStart={composeEventHandlers(
444+
kanbanProps.onDragStart,
445+
({ active }) => {
446+
setActiveId(active.id);
447+
},
448+
)}
489449
onDragOver={composeEventHandlers(kanbanProps.onDragOver, onDragOver)}
490450
onDragEnd={composeEventHandlers(kanbanProps.onDragEnd, onDragEnd)}
491-
onDragCancel={composeEventHandlers(
492-
kanbanProps.onDragCancel,
493-
onDragCancel,
494-
)}
451+
onDragCancel={composeEventHandlers(kanbanProps.onDragCancel, () => {
452+
setActiveId(null);
453+
})}
495454
{...kanbanProps}
496455
/>
497456
</KanbanContext.Provider>

0 commit comments

Comments
 (0)