Skip to content

Commit 5d60def

Browse files
committed
fix(sortable): set external original index to -1, so spillTarget.drop can recognise them
1 parent 86308da commit 5d60def

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

packages/sortable/src/directives/external.directive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class SkyhookSortableExternal<Data> implements OnChanges, OnDestroy {
2424
@Input('ssExternal') spec!: SortableSpec<Data>;
2525

2626
/** This source has beginDrag and endDrag implemented in line with what ssRender does.
27-
*
27+
*
2828
* You must, like ssRender, attach it with [dragSource] somewhere.
2929
*/
3030
public source: DragSource<DraggedItem<Data>>;
@@ -42,9 +42,9 @@ export class SkyhookSortableExternal<Data> implements OnChanges, OnDestroy {
4242
return {
4343
type: this.spec.type,
4444
data: this.spec.createData(),
45-
hover: { index: 0, listId: EXTERNAL_LIST_ID },
45+
hover: { index: -1, listId: EXTERNAL_LIST_ID },
4646
isInternal: false,
47-
index: 0,
47+
index: -1,
4848
listId: EXTERNAL_LIST_ID,
4949
size: this.size(),
5050
}

packages/sortable/src/spillTarget.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ export const spillTarget = <Data>(
1616
config: SpillConfiguration<Data>,
1717
): DropTarget<DraggedItem<Data>> => {
1818

19-
const mutate = (item: DraggedItem<Data>) => {
20-
item.hover = { listId: SPILLED_LIST_ID, index: 0 };
19+
const mutate = (item: DraggedItem<Data> | null) => {
20+
if (!item) return null;
21+
item.hover = { listId: SPILLED_LIST_ID, index: -1 };
2122
return { ...item };
2223
}
2324

2425
const hover$ = new Subject<DraggedItem<Data> | null>();
2526

2627
const target = dnd.dropTarget<DraggedItem<Data>>(types, {
27-
hover: config.hover && (monitor => {
28+
hover: monitor => {
2829
if (monitor.canDrop() && monitor.isOver({ shallow: true })) {
29-
hover$.next(monitor.getItem());
30+
const item = mutate(monitor.getItem());
31+
hover$.next(item);
3032
} else {
3133
hover$.next(null);
3234
}
33-
}),
35+
},
3436
drop: config.drop && (monitor => {
35-
const item = monitor.getItem();
36-
if (config.drop && item && !monitor.didDrop()) {
37-
config.drop(mutate(item));
37+
const item = mutate(monitor.getItem());
38+
if (!monitor.didDrop()) {
39+
config.drop && item && config.drop(item);
3840
}
3941
}) || undefined
4042
});
@@ -43,7 +45,7 @@ export const spillTarget = <Data>(
4345
.pipe(distinctUntilChanged(), filter(a => !!a));
4446

4547
const subs = spilled$.subscribe((item) => {
46-
config.hover && item && config.hover(mutate(item));
48+
config.hover && item && config.hover(item);
4749
});
4850

4951
target.add(subs);

0 commit comments

Comments
 (0)