@@ -20,6 +20,7 @@ function draggy({ target, ...options }: Options) {
20
20
optimistic : true ,
21
21
direction : "vertical" ,
22
22
placement : "any" ,
23
+ loose : true ,
23
24
...options ,
24
25
} ,
25
26
} ;
@@ -57,7 +58,11 @@ function draggy({ target, ...options }: Options) {
57
58
const onMouseUp = ( ev : MouseEvent ) => {
58
59
ev . preventDefault ( ) ;
59
60
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 ) {
61
66
const bool = context . options . onBeforeDrop ( ev , {
62
67
origin : context . origin ,
63
68
zone : context . zone ,
@@ -68,27 +73,31 @@ function draggy({ target, ...options }: Options) {
68
73
}
69
74
}
70
75
76
+ if ( ! context . zone && ! context . options . loose ) {
77
+ context . originZone . insertBefore ( context . origin , context . nextSibling ) ;
78
+ }
79
+
71
80
context . options . onDrop ?.( ev , {
72
81
origin : context . origin ,
73
82
zone : context . zone ,
74
83
} ) ;
75
84
76
- context . shadow ? .remove ( ) ;
85
+ context . shadow . remove ( ) ;
77
86
context . shadow = null ;
78
87
79
- if ( context . multiple && context . zone && context . origin ) {
88
+ if ( context . multiple . length ) {
80
89
for ( let i = 0 ; i < context . multiple . length ; i ++ ) {
81
90
const m = context . multiple [ i ] ;
82
91
if ( ! m || ! m . origin ) return ;
83
- context . zone . insertBefore ( m . origin , context . origin . nextElementSibling ) ;
92
+ context . zone ? .insertBefore ( m . origin , context . origin . nextElementSibling ) ;
84
93
m . origin . style . display = m . style . display ;
85
94
m . origin . classList . remove ( CLASSNAMES . selection ) ;
86
95
}
87
96
88
97
context . multiple = [ ] ;
89
98
}
90
99
91
- context . origin ? .classList . remove ( CLASSNAMES . origin ) ;
100
+ context . origin . classList . remove ( CLASSNAMES . origin ) ;
92
101
context . origin = null ;
93
102
94
103
context . removeMouseMove ?.( ) ;
0 commit comments