@@ -105,7 +105,23 @@ export default class Sortable extends Draggable {
105
105
* @return {Number }
106
106
*/
107
107
index ( element ) {
108
- return this . getDraggableElementsForContainer ( element . parentNode ) . indexOf ( element ) ;
108
+ return this . getSortableElementsForContainer ( element . parentNode ) . indexOf ( element ) ;
109
+ }
110
+
111
+ /**
112
+ * Returns sortable elements for a given container, excluding the mirror and
113
+ * original source element if present
114
+ * @param {HTMLElement } container
115
+ * @return {HTMLElement[] }
116
+ */
117
+ getSortableElementsForContainer ( container ) {
118
+ const allSortableElements = container . querySelectorAll ( this . options . draggable ) ;
119
+
120
+ return [ ...allSortableElements ] . filter ( ( childElement ) => {
121
+ return (
122
+ childElement !== this . originalSource && childElement !== this . mirror && childElement . parentNode === container
123
+ ) ;
124
+ } ) ;
109
125
}
110
126
111
127
/**
@@ -156,7 +172,7 @@ export default class Sortable extends Draggable {
156
172
return ;
157
173
}
158
174
159
- const children = this . getDraggableElementsForContainer ( overContainer ) ;
175
+ const children = this . getSortableElementsForContainer ( overContainer ) ;
160
176
const moves = move ( { source, over, overContainer, children} ) ;
161
177
162
178
if ( ! moves ) {
@@ -252,7 +268,7 @@ function index(element) {
252
268
function move ( { source, over, overContainer, children} ) {
253
269
const emptyOverContainer = ! children . length ;
254
270
const differentContainer = source . parentNode !== overContainer ;
255
- const sameContainer = over && ! differentContainer ;
271
+ const sameContainer = over && source . parentNode === over . parentNode ;
256
272
257
273
if ( emptyOverContainer ) {
258
274
return moveInsideEmptyContainer ( source , overContainer ) ;
0 commit comments