Skip to content

Commit 9824920

Browse files
committed
feat: update sortable
1 parent 654dc59 commit 9824920

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

docs/registry/default/ui/kanban.tsx

+18-18
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const KANBAN_ERROR = {
5454

5555
interface KanbanContextValue<T> {
5656
id: string;
57-
value: Record<UniqueIdentifier, T[]>;
57+
items: Record<UniqueIdentifier, T[]>;
5858
activeId: UniqueIdentifier | null;
5959
setActiveId: (id: UniqueIdentifier | null) => void;
6060
getItemValue: (item: T) => UniqueIdentifier;
@@ -98,7 +98,7 @@ function Kanban<T>(props: KanbanProps<T>) {
9898
const [activeId, setActiveId] = React.useState<UniqueIdentifier | null>(null);
9999
const lastOverId = React.useRef<UniqueIdentifier | null>(null);
100100
const recentlyMovedToNewContainer = React.useRef(false);
101-
const [clonedColumns, setClonedColumns] = React.useState<Record<
101+
const [clonedItems, setClonedItems] = React.useState<Record<
102102
UniqueIdentifier,
103103
T[]
104104
> | null>(null);
@@ -128,7 +128,7 @@ function Kanban<T>(props: KanbanProps<T>) {
128128
const contextValue = React.useMemo<KanbanContextValue<T>>(
129129
() => ({
130130
id,
131-
value,
131+
items: value,
132132
activeId,
133133
setActiveId,
134134
getItemValue,
@@ -223,7 +223,7 @@ function Kanban<T>(props: KanbanProps<T>) {
223223
}}
224224
onDragStart={composeEventHandlers(kanbanProps.onDragStart, (event) => {
225225
setActiveId(event.active.id);
226-
setClonedColumns(value);
226+
setClonedItems(value);
227227
})}
228228
onDragOver={composeEventHandlers(kanbanProps.onDragOver, (event) => {
229229
const { active, over } = event;
@@ -294,7 +294,7 @@ function Kanban<T>(props: KanbanProps<T>) {
294294

295295
if (!over) {
296296
setActiveId(null);
297-
setClonedColumns(null);
297+
setClonedItems(null);
298298
return;
299299
}
300300

@@ -303,7 +303,7 @@ function Kanban<T>(props: KanbanProps<T>) {
303303

304304
if (!activeContainer || !overContainer) {
305305
setActiveId(null);
306-
setClonedColumns(null);
306+
setClonedItems(null);
307307
return;
308308
}
309309

@@ -312,7 +312,7 @@ function Kanban<T>(props: KanbanProps<T>) {
312312

313313
if (!activeItems || !overItems) {
314314
setActiveId(null);
315-
setClonedColumns(null);
315+
setClonedItems(null);
316316
return;
317317
}
318318

@@ -333,14 +333,14 @@ function Kanban<T>(props: KanbanProps<T>) {
333333

334334
if (!activeColumn || !overColumn) {
335335
setActiveId(null);
336-
setClonedColumns(null);
336+
setClonedItems(null);
337337
return;
338338
}
339339

340340
const [movedItem] = activeColumn.splice(activeIndex, 1);
341341
if (!movedItem) {
342342
setActiveId(null);
343-
setClonedColumns(null);
343+
setClonedItems(null);
344344
return;
345345
}
346346

@@ -351,7 +351,7 @@ function Kanban<T>(props: KanbanProps<T>) {
351351
const items = value[activeContainer];
352352
if (!items) {
353353
setActiveId(null);
354-
setClonedColumns(null);
354+
setClonedItems(null);
355355
return;
356356
}
357357

@@ -370,7 +370,7 @@ function Kanban<T>(props: KanbanProps<T>) {
370370
const columnItems = newColumns[activeContainer];
371371
if (!columnItems) {
372372
setActiveId(null);
373-
setClonedColumns(null);
373+
setClonedItems(null);
374374
return;
375375
}
376376
newColumns[activeContainer] = arrayMove(
@@ -383,14 +383,14 @@ function Kanban<T>(props: KanbanProps<T>) {
383383
}
384384
}
385385
setActiveId(null);
386-
setClonedColumns(null);
386+
setClonedItems(null);
387387
})}
388388
onDragCancel={composeEventHandlers(kanbanProps.onDragCancel, () => {
389-
if (clonedColumns) {
390-
onValueChange?.(clonedColumns);
389+
if (clonedItems) {
390+
onValueChange?.(clonedItems);
391391
}
392392
setActiveId(null);
393-
setClonedColumns(null);
393+
setClonedItems(null);
394394
})}
395395
{...kanbanProps}
396396
/>
@@ -446,7 +446,7 @@ const KanbanColumn = React.forwardRef<HTMLDivElement, KanbanColumnProps>(
446446
}
447447

448448
const ColumnSlot = asChild ? Slot : "div";
449-
const items = context.value[value] ?? [];
449+
const items = context.items[value] ?? [];
450450

451451
return (
452452
<SortableContext
@@ -649,17 +649,17 @@ const ItemGrip = KanbanItemGrip;
649649
const Overlay = KanbanOverlay;
650650

651651
export {
652+
Root,
652653
Board,
653654
Column,
654655
Item,
655656
ItemGrip,
657+
Overlay,
656658
//
657659
Kanban,
658660
KanbanBoard,
659661
KanbanColumn,
660662
KanbanItem,
661663
KanbanItemGrip,
662664
KanbanOverlay,
663-
Overlay,
664-
Root,
665665
};

docs/registry/default/ui/sortable.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,18 @@ function Sortable<T>(props: SortableProps<T>) {
178178
id={id}
179179
modifiers={modifiers ?? config.modifiers}
180180
sensors={sensorsProp ?? sensors}
181-
onDragStart={composeEventHandlers(sortableProps.onDragStart, (event) =>
182-
setActiveId(event.active.id),
181+
onDragStart={composeEventHandlers(
182+
sortableProps.onDragStart,
183+
({ active }) => setActiveId(active.id),
183184
)}
184185
onDragEnd={composeEventHandlers(sortableProps.onDragEnd, (event) => {
185-
if (event.over && event.active.id !== event.over?.id) {
186+
const { active, over } = event;
187+
if (over && active.id !== over?.id) {
186188
const activeIndex = value.findIndex(
187-
(item) => getItemValue(item) === event.active.id,
189+
(item) => getItemValue(item) === active.id,
188190
);
189191
const overIndex = value.findIndex(
190-
(item) => getItemValue(item) === event.active.id,
192+
(item) => getItemValue(item) === over.id,
191193
);
192194

193195
if (onMove) {

0 commit comments

Comments
 (0)