Skip to content

Commit 0eb8773

Browse files
committed
fix: take options.loose into consideration
1 parent 564b43d commit 0eb8773

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/main.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function draggy({ target, ...options }: Options) {
2020
optimistic: true,
2121
direction: "vertical",
2222
placement: "any",
23+
loose: true,
2324
...options,
2425
},
2526
};
@@ -57,7 +58,11 @@ function draggy({ target, ...options }: Options) {
5758
const onMouseUp = (ev: MouseEvent) => {
5859
ev.preventDefault();
5960

60-
if (context.options.onBeforeDrop && context.originZone && context.origin) {
61+
if (!context.origin || !context.originZone || !context.shadow) {
62+
return;
63+
}
64+
65+
if (context.options.onBeforeDrop) {
6166
const bool = context.options.onBeforeDrop(ev, {
6267
origin: context.origin,
6368
zone: context.zone,
@@ -68,27 +73,31 @@ function draggy({ target, ...options }: Options) {
6873
}
6974
}
7075

76+
if (!context.zone && !context.options.loose) {
77+
context.originZone.insertBefore(context.origin, context.nextSibling);
78+
}
79+
7180
context.options.onDrop?.(ev, {
7281
origin: context.origin,
7382
zone: context.zone,
7483
});
7584

76-
context.shadow?.remove();
85+
context.shadow.remove();
7786
context.shadow = null;
7887

79-
if (context.multiple && context.zone && context.origin) {
88+
if (context.multiple.length) {
8089
for (let i = 0; i < context.multiple.length; i++) {
8190
const m = context.multiple[i];
8291
if (!m || !m.origin) return;
83-
context.zone.insertBefore(m.origin, context.origin.nextElementSibling);
92+
context.zone?.insertBefore(m.origin, context.origin.nextElementSibling);
8493
m.origin.style.display = m.style.display;
8594
m.origin.classList.remove(CLASSNAMES.selection);
8695
}
8796

8897
context.multiple = [];
8998
}
9099

91-
context.origin?.classList.remove(CLASSNAMES.origin);
100+
context.origin.classList.remove(CLASSNAMES.origin);
92101
context.origin = null;
93102

94103
context.removeMouseMove?.();

0 commit comments

Comments
 (0)