sortablejs 1.15.2 → 1.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/Sortable.js +65 -41
- package/Sortable.min.js +2 -2
- package/modular/sortable.complete.esm.js +65 -41
- package/modular/sortable.core.esm.js +65 -41
- package/modular/sortable.esm.js +65 -41
- package/package.json +3 -2
- package/src/Animation.js +175 -0
- package/src/BrowserInfo.js +12 -0
- package/src/EventDispatcher.js +57 -0
- package/src/PluginManager.js +94 -0
- package/src/Sortable.js +2024 -0
- package/src/utils.js +595 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**!
|
|
2
|
-
* Sortable 1.15.
|
|
2
|
+
* Sortable 1.15.4
|
|
3
3
|
* @author RubaXa <trash@rubaxa.org>
|
|
4
4
|
* @author owenm <owen23355@gmail.com>
|
|
5
5
|
* @license MIT
|
|
@@ -128,7 +128,7 @@ function _nonIterableSpread() {
|
|
|
128
128
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
var version = "1.15.
|
|
131
|
+
var version = "1.15.4";
|
|
132
132
|
|
|
133
133
|
function userAgent(pattern) {
|
|
134
134
|
if (typeof window !== 'undefined' && window.navigator) {
|
|
@@ -1232,7 +1232,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1232
1232
|
pluginEvent('filter', _this, {
|
|
1233
1233
|
evt: evt
|
|
1234
1234
|
});
|
|
1235
|
-
preventOnFilter && evt.
|
|
1235
|
+
preventOnFilter && evt.preventDefault();
|
|
1236
1236
|
return; // cancel dnd
|
|
1237
1237
|
}
|
|
1238
1238
|
} else if (filter) {
|
|
@@ -1254,7 +1254,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1254
1254
|
}
|
|
1255
1255
|
});
|
|
1256
1256
|
if (filter) {
|
|
1257
|
-
preventOnFilter && evt.
|
|
1257
|
+
preventOnFilter && evt.preventDefault();
|
|
1258
1258
|
return; // cancel dnd
|
|
1259
1259
|
}
|
|
1260
1260
|
}
|
|
@@ -1326,9 +1326,15 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1326
1326
|
on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
|
|
1327
1327
|
on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
|
|
1328
1328
|
on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1329
|
+
if (options.supportPointer) {
|
|
1330
|
+
on(ownerDocument, 'pointerup', _this._onDrop);
|
|
1331
|
+
// Native D&D triggers pointercancel
|
|
1332
|
+
!this.nativeDraggable && on(ownerDocument, 'pointercancel', _this._onDrop);
|
|
1333
|
+
} else {
|
|
1334
|
+
on(ownerDocument, 'mouseup', _this._onDrop);
|
|
1335
|
+
on(ownerDocument, 'touchend', _this._onDrop);
|
|
1336
|
+
on(ownerDocument, 'touchcancel', _this._onDrop);
|
|
1337
|
+
}
|
|
1332
1338
|
|
|
1333
1339
|
// Make dragEl draggable (must be before delay for FireFox)
|
|
1334
1340
|
if (FireFox && this.nativeDraggable) {
|
|
@@ -1348,9 +1354,14 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1348
1354
|
// If the user moves the pointer or let go the click or touch
|
|
1349
1355
|
// before the delay has been reached:
|
|
1350
1356
|
// disable the delayed drag
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1357
|
+
if (options.supportPointer) {
|
|
1358
|
+
on(ownerDocument, 'pointerup', _this._disableDelayedDrag);
|
|
1359
|
+
on(ownerDocument, 'pointercancel', _this._disableDelayedDrag);
|
|
1360
|
+
} else {
|
|
1361
|
+
on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
|
|
1362
|
+
on(ownerDocument, 'touchend', _this._disableDelayedDrag);
|
|
1363
|
+
on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
|
|
1364
|
+
}
|
|
1354
1365
|
on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
|
|
1355
1366
|
on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
|
|
1356
1367
|
options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
|
|
@@ -1376,6 +1387,8 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1376
1387
|
off(ownerDocument, 'mouseup', this._disableDelayedDrag);
|
|
1377
1388
|
off(ownerDocument, 'touchend', this._disableDelayedDrag);
|
|
1378
1389
|
off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
|
|
1390
|
+
off(ownerDocument, 'pointerup', this._disableDelayedDrag);
|
|
1391
|
+
off(ownerDocument, 'pointercancel', this._disableDelayedDrag);
|
|
1379
1392
|
off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
|
|
1380
1393
|
off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
|
|
1381
1394
|
off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
|
|
@@ -1395,14 +1408,13 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1395
1408
|
on(rootEl, 'dragstart', this._onDragStart);
|
|
1396
1409
|
}
|
|
1397
1410
|
try {
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
_nextTick(function () {
|
|
1411
|
+
_nextTick(function () {
|
|
1412
|
+
if (document.selection) {
|
|
1401
1413
|
document.selection.empty();
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1414
|
+
} else {
|
|
1415
|
+
window.getSelection().removeAllRanges();
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1406
1418
|
} catch (err) {}
|
|
1407
1419
|
},
|
|
1408
1420
|
_dragStarted: function _dragStarted(fallback, evt) {
|
|
@@ -1461,7 +1473,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1461
1473
|
}
|
|
1462
1474
|
target = parent; // store last element
|
|
1463
1475
|
}
|
|
1464
|
-
/* jshint boss:true */ while (parent = parent
|
|
1476
|
+
/* jshint boss:true */ while (parent = getParentOrHost(parent));
|
|
1465
1477
|
}
|
|
1466
1478
|
_unhideGhostForTarget();
|
|
1467
1479
|
}
|
|
@@ -1889,6 +1901,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1889
1901
|
off(ownerDocument, 'mouseup', this._onDrop);
|
|
1890
1902
|
off(ownerDocument, 'touchend', this._onDrop);
|
|
1891
1903
|
off(ownerDocument, 'pointerup', this._onDrop);
|
|
1904
|
+
off(ownerDocument, 'pointercancel', this._onDrop);
|
|
1892
1905
|
off(ownerDocument, 'touchcancel', this._onDrop);
|
|
1893
1906
|
off(document, 'selectstart', this);
|
|
1894
1907
|
},
|
|
@@ -2367,7 +2380,8 @@ Sortable.utils = {
|
|
|
2367
2380
|
nextTick: _nextTick,
|
|
2368
2381
|
cancelNextTick: _cancelNextTick,
|
|
2369
2382
|
detectDirection: _detectDirection,
|
|
2370
|
-
getChild: getChild
|
|
2383
|
+
getChild: getChild,
|
|
2384
|
+
expando: expando
|
|
2371
2385
|
};
|
|
2372
2386
|
|
|
2373
2387
|
/**
|
|
@@ -3079,28 +3093,38 @@ function MultiDragPlugin() {
|
|
|
3079
3093
|
var lastIndex = index(lastMultiDragSelect),
|
|
3080
3094
|
currentIndex = index(dragEl$1);
|
|
3081
3095
|
if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3096
|
+
(function () {
|
|
3097
|
+
// Must include lastMultiDragSelect (select it), in case modified selection from no selection
|
|
3098
|
+
// (but previous selection existed)
|
|
3099
|
+
var n, i;
|
|
3100
|
+
if (currentIndex > lastIndex) {
|
|
3101
|
+
i = lastIndex;
|
|
3102
|
+
n = currentIndex;
|
|
3103
|
+
} else {
|
|
3104
|
+
i = currentIndex;
|
|
3105
|
+
n = lastIndex + 1;
|
|
3106
|
+
}
|
|
3107
|
+
var filter = options.filter;
|
|
3108
|
+
for (; i < n; i++) {
|
|
3109
|
+
if (~multiDragElements.indexOf(children[i])) continue;
|
|
3110
|
+
// Check if element is draggable
|
|
3111
|
+
if (!closest(children[i], options.draggable, parentEl, false)) continue;
|
|
3112
|
+
// Check if element is filtered
|
|
3113
|
+
var filtered = filter && (typeof filter === 'function' ? filter.call(sortable, evt, children[i], sortable) : filter.split(',').some(function (criteria) {
|
|
3114
|
+
return closest(children[i], criteria.trim(), parentEl, false);
|
|
3115
|
+
}));
|
|
3116
|
+
if (filtered) continue;
|
|
3117
|
+
toggleClass(children[i], options.selectedClass, true);
|
|
3118
|
+
multiDragElements.push(children[i]);
|
|
3119
|
+
dispatchEvent({
|
|
3120
|
+
sortable: sortable,
|
|
3121
|
+
rootEl: rootEl,
|
|
3122
|
+
name: 'select',
|
|
3123
|
+
targetEl: children[i],
|
|
3124
|
+
originalEvent: evt
|
|
3125
|
+
});
|
|
3126
|
+
}
|
|
3127
|
+
})();
|
|
3104
3128
|
}
|
|
3105
3129
|
} else {
|
|
3106
3130
|
lastMultiDragSelect = dragEl$1;
|
package/modular/sortable.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**!
|
|
2
|
-
* Sortable 1.15.
|
|
2
|
+
* Sortable 1.15.4
|
|
3
3
|
* @author RubaXa <trash@rubaxa.org>
|
|
4
4
|
* @author owenm <owen23355@gmail.com>
|
|
5
5
|
* @license MIT
|
|
@@ -128,7 +128,7 @@ function _nonIterableSpread() {
|
|
|
128
128
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
var version = "1.15.
|
|
131
|
+
var version = "1.15.4";
|
|
132
132
|
|
|
133
133
|
function userAgent(pattern) {
|
|
134
134
|
if (typeof window !== 'undefined' && window.navigator) {
|
|
@@ -1232,7 +1232,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1232
1232
|
pluginEvent('filter', _this, {
|
|
1233
1233
|
evt: evt
|
|
1234
1234
|
});
|
|
1235
|
-
preventOnFilter && evt.
|
|
1235
|
+
preventOnFilter && evt.preventDefault();
|
|
1236
1236
|
return; // cancel dnd
|
|
1237
1237
|
}
|
|
1238
1238
|
} else if (filter) {
|
|
@@ -1254,7 +1254,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1254
1254
|
}
|
|
1255
1255
|
});
|
|
1256
1256
|
if (filter) {
|
|
1257
|
-
preventOnFilter && evt.
|
|
1257
|
+
preventOnFilter && evt.preventDefault();
|
|
1258
1258
|
return; // cancel dnd
|
|
1259
1259
|
}
|
|
1260
1260
|
}
|
|
@@ -1326,9 +1326,15 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1326
1326
|
on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
|
|
1327
1327
|
on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
|
|
1328
1328
|
on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1329
|
+
if (options.supportPointer) {
|
|
1330
|
+
on(ownerDocument, 'pointerup', _this._onDrop);
|
|
1331
|
+
// Native D&D triggers pointercancel
|
|
1332
|
+
!this.nativeDraggable && on(ownerDocument, 'pointercancel', _this._onDrop);
|
|
1333
|
+
} else {
|
|
1334
|
+
on(ownerDocument, 'mouseup', _this._onDrop);
|
|
1335
|
+
on(ownerDocument, 'touchend', _this._onDrop);
|
|
1336
|
+
on(ownerDocument, 'touchcancel', _this._onDrop);
|
|
1337
|
+
}
|
|
1332
1338
|
|
|
1333
1339
|
// Make dragEl draggable (must be before delay for FireFox)
|
|
1334
1340
|
if (FireFox && this.nativeDraggable) {
|
|
@@ -1348,9 +1354,14 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1348
1354
|
// If the user moves the pointer or let go the click or touch
|
|
1349
1355
|
// before the delay has been reached:
|
|
1350
1356
|
// disable the delayed drag
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1357
|
+
if (options.supportPointer) {
|
|
1358
|
+
on(ownerDocument, 'pointerup', _this._disableDelayedDrag);
|
|
1359
|
+
on(ownerDocument, 'pointercancel', _this._disableDelayedDrag);
|
|
1360
|
+
} else {
|
|
1361
|
+
on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
|
|
1362
|
+
on(ownerDocument, 'touchend', _this._disableDelayedDrag);
|
|
1363
|
+
on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
|
|
1364
|
+
}
|
|
1354
1365
|
on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
|
|
1355
1366
|
on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
|
|
1356
1367
|
options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
|
|
@@ -1376,6 +1387,8 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1376
1387
|
off(ownerDocument, 'mouseup', this._disableDelayedDrag);
|
|
1377
1388
|
off(ownerDocument, 'touchend', this._disableDelayedDrag);
|
|
1378
1389
|
off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
|
|
1390
|
+
off(ownerDocument, 'pointerup', this._disableDelayedDrag);
|
|
1391
|
+
off(ownerDocument, 'pointercancel', this._disableDelayedDrag);
|
|
1379
1392
|
off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
|
|
1380
1393
|
off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
|
|
1381
1394
|
off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
|
|
@@ -1395,14 +1408,13 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1395
1408
|
on(rootEl, 'dragstart', this._onDragStart);
|
|
1396
1409
|
}
|
|
1397
1410
|
try {
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
_nextTick(function () {
|
|
1411
|
+
_nextTick(function () {
|
|
1412
|
+
if (document.selection) {
|
|
1401
1413
|
document.selection.empty();
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1414
|
+
} else {
|
|
1415
|
+
window.getSelection().removeAllRanges();
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1406
1418
|
} catch (err) {}
|
|
1407
1419
|
},
|
|
1408
1420
|
_dragStarted: function _dragStarted(fallback, evt) {
|
|
@@ -1461,7 +1473,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1461
1473
|
}
|
|
1462
1474
|
target = parent; // store last element
|
|
1463
1475
|
}
|
|
1464
|
-
/* jshint boss:true */ while (parent = parent
|
|
1476
|
+
/* jshint boss:true */ while (parent = getParentOrHost(parent));
|
|
1465
1477
|
}
|
|
1466
1478
|
_unhideGhostForTarget();
|
|
1467
1479
|
}
|
|
@@ -1889,6 +1901,7 @@ Sortable.prototype = /** @lends Sortable.prototype */{
|
|
|
1889
1901
|
off(ownerDocument, 'mouseup', this._onDrop);
|
|
1890
1902
|
off(ownerDocument, 'touchend', this._onDrop);
|
|
1891
1903
|
off(ownerDocument, 'pointerup', this._onDrop);
|
|
1904
|
+
off(ownerDocument, 'pointercancel', this._onDrop);
|
|
1892
1905
|
off(ownerDocument, 'touchcancel', this._onDrop);
|
|
1893
1906
|
off(document, 'selectstart', this);
|
|
1894
1907
|
},
|
|
@@ -2367,7 +2380,8 @@ Sortable.utils = {
|
|
|
2367
2380
|
nextTick: _nextTick,
|
|
2368
2381
|
cancelNextTick: _cancelNextTick,
|
|
2369
2382
|
detectDirection: _detectDirection,
|
|
2370
|
-
getChild: getChild
|
|
2383
|
+
getChild: getChild,
|
|
2384
|
+
expando: expando
|
|
2371
2385
|
};
|
|
2372
2386
|
|
|
2373
2387
|
/**
|
|
@@ -3078,28 +3092,38 @@ function MultiDragPlugin() {
|
|
|
3078
3092
|
var lastIndex = index(lastMultiDragSelect),
|
|
3079
3093
|
currentIndex = index(dragEl$1);
|
|
3080
3094
|
if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3095
|
+
(function () {
|
|
3096
|
+
// Must include lastMultiDragSelect (select it), in case modified selection from no selection
|
|
3097
|
+
// (but previous selection existed)
|
|
3098
|
+
var n, i;
|
|
3099
|
+
if (currentIndex > lastIndex) {
|
|
3100
|
+
i = lastIndex;
|
|
3101
|
+
n = currentIndex;
|
|
3102
|
+
} else {
|
|
3103
|
+
i = currentIndex;
|
|
3104
|
+
n = lastIndex + 1;
|
|
3105
|
+
}
|
|
3106
|
+
var filter = options.filter;
|
|
3107
|
+
for (; i < n; i++) {
|
|
3108
|
+
if (~multiDragElements.indexOf(children[i])) continue;
|
|
3109
|
+
// Check if element is draggable
|
|
3110
|
+
if (!closest(children[i], options.draggable, parentEl, false)) continue;
|
|
3111
|
+
// Check if element is filtered
|
|
3112
|
+
var filtered = filter && (typeof filter === 'function' ? filter.call(sortable, evt, children[i], sortable) : filter.split(',').some(function (criteria) {
|
|
3113
|
+
return closest(children[i], criteria.trim(), parentEl, false);
|
|
3114
|
+
}));
|
|
3115
|
+
if (filtered) continue;
|
|
3116
|
+
toggleClass(children[i], options.selectedClass, true);
|
|
3117
|
+
multiDragElements.push(children[i]);
|
|
3118
|
+
dispatchEvent({
|
|
3119
|
+
sortable: sortable,
|
|
3120
|
+
rootEl: rootEl,
|
|
3121
|
+
name: 'select',
|
|
3122
|
+
targetEl: children[i],
|
|
3123
|
+
originalEvent: evt
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
3126
|
+
})();
|
|
3103
3127
|
}
|
|
3104
3128
|
} else {
|
|
3105
3129
|
lastMultiDragSelect = dragEl$1;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sortablejs",
|
|
3
3
|
"exportName": "Sortable",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.4",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@babel/core": "^7.4.4",
|
|
7
7
|
"@babel/plugin-transform-object-assign": "^7.2.0",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"files": [
|
|
40
40
|
"Sortable.js",
|
|
41
41
|
"Sortable.min.js",
|
|
42
|
-
"modular/"
|
|
42
|
+
"modular/",
|
|
43
|
+
"src/"
|
|
43
44
|
],
|
|
44
45
|
"keywords": [
|
|
45
46
|
"sortable",
|
package/src/Animation.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { getRect, css, matrix, isRectEqual, indexOfObject } from './utils.js';
|
|
2
|
+
import Sortable from './Sortable.js';
|
|
3
|
+
|
|
4
|
+
export default function AnimationStateManager() {
|
|
5
|
+
let animationStates = [],
|
|
6
|
+
animationCallbackId;
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
captureAnimationState() {
|
|
10
|
+
animationStates = [];
|
|
11
|
+
if (!this.options.animation) return;
|
|
12
|
+
let children = [].slice.call(this.el.children);
|
|
13
|
+
|
|
14
|
+
children.forEach(child => {
|
|
15
|
+
if (css(child, 'display') === 'none' || child === Sortable.ghost) return;
|
|
16
|
+
animationStates.push({
|
|
17
|
+
target: child,
|
|
18
|
+
rect: getRect(child)
|
|
19
|
+
});
|
|
20
|
+
let fromRect = { ...animationStates[animationStates.length - 1].rect };
|
|
21
|
+
|
|
22
|
+
// If animating: compensate for current animation
|
|
23
|
+
if (child.thisAnimationDuration) {
|
|
24
|
+
let childMatrix = matrix(child, true);
|
|
25
|
+
if (childMatrix) {
|
|
26
|
+
fromRect.top -= childMatrix.f;
|
|
27
|
+
fromRect.left -= childMatrix.e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
child.fromRect = fromRect;
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
addAnimationState(state) {
|
|
36
|
+
animationStates.push(state);
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
removeAnimationState(target) {
|
|
40
|
+
animationStates.splice(indexOfObject(animationStates, { target }), 1);
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
animateAll(callback) {
|
|
44
|
+
if (!this.options.animation) {
|
|
45
|
+
clearTimeout(animationCallbackId);
|
|
46
|
+
if (typeof(callback) === 'function') callback();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let animating = false,
|
|
51
|
+
animationTime = 0;
|
|
52
|
+
|
|
53
|
+
animationStates.forEach((state) => {
|
|
54
|
+
let time = 0,
|
|
55
|
+
animatingThis = false,
|
|
56
|
+
target = state.target,
|
|
57
|
+
fromRect = target.fromRect,
|
|
58
|
+
toRect = getRect(target),
|
|
59
|
+
prevFromRect = target.prevFromRect,
|
|
60
|
+
prevToRect = target.prevToRect,
|
|
61
|
+
animatingRect = state.rect,
|
|
62
|
+
targetMatrix = matrix(target, true);
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if (targetMatrix) {
|
|
66
|
+
// Compensate for current animation
|
|
67
|
+
toRect.top -= targetMatrix.f;
|
|
68
|
+
toRect.left -= targetMatrix.e;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
target.toRect = toRect;
|
|
72
|
+
|
|
73
|
+
if (target.thisAnimationDuration) {
|
|
74
|
+
// Could also check if animatingRect is between fromRect and toRect
|
|
75
|
+
if (
|
|
76
|
+
isRectEqual(prevFromRect, toRect) &&
|
|
77
|
+
!isRectEqual(fromRect, toRect) &&
|
|
78
|
+
// Make sure animatingRect is on line between toRect & fromRect
|
|
79
|
+
(animatingRect.top - toRect.top) /
|
|
80
|
+
(animatingRect.left - toRect.left) ===
|
|
81
|
+
(fromRect.top - toRect.top) /
|
|
82
|
+
(fromRect.left - toRect.left)
|
|
83
|
+
) {
|
|
84
|
+
// If returning to same place as started from animation and on same axis
|
|
85
|
+
time = calculateRealTime(animatingRect, prevFromRect, prevToRect, this.options);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// if fromRect != toRect: animate
|
|
90
|
+
if (!isRectEqual(toRect, fromRect)) {
|
|
91
|
+
target.prevFromRect = fromRect;
|
|
92
|
+
target.prevToRect = toRect;
|
|
93
|
+
|
|
94
|
+
if (!time) {
|
|
95
|
+
time = this.options.animation;
|
|
96
|
+
}
|
|
97
|
+
this.animate(
|
|
98
|
+
target,
|
|
99
|
+
animatingRect,
|
|
100
|
+
toRect,
|
|
101
|
+
time
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (time) {
|
|
106
|
+
animating = true;
|
|
107
|
+
animationTime = Math.max(animationTime, time);
|
|
108
|
+
clearTimeout(target.animationResetTimer);
|
|
109
|
+
target.animationResetTimer = setTimeout(function() {
|
|
110
|
+
target.animationTime = 0;
|
|
111
|
+
target.prevFromRect = null;
|
|
112
|
+
target.fromRect = null;
|
|
113
|
+
target.prevToRect = null;
|
|
114
|
+
target.thisAnimationDuration = null;
|
|
115
|
+
}, time);
|
|
116
|
+
target.thisAnimationDuration = time;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
clearTimeout(animationCallbackId);
|
|
122
|
+
if (!animating) {
|
|
123
|
+
if (typeof(callback) === 'function') callback();
|
|
124
|
+
} else {
|
|
125
|
+
animationCallbackId = setTimeout(function() {
|
|
126
|
+
if (typeof(callback) === 'function') callback();
|
|
127
|
+
}, animationTime);
|
|
128
|
+
}
|
|
129
|
+
animationStates = [];
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
animate(target, currentRect, toRect, duration) {
|
|
133
|
+
if (duration) {
|
|
134
|
+
css(target, 'transition', '');
|
|
135
|
+
css(target, 'transform', '');
|
|
136
|
+
let elMatrix = matrix(this.el),
|
|
137
|
+
scaleX = elMatrix && elMatrix.a,
|
|
138
|
+
scaleY = elMatrix && elMatrix.d,
|
|
139
|
+
translateX = (currentRect.left - toRect.left) / (scaleX || 1),
|
|
140
|
+
translateY = (currentRect.top - toRect.top) / (scaleY || 1);
|
|
141
|
+
|
|
142
|
+
target.animatingX = !!translateX;
|
|
143
|
+
target.animatingY = !!translateY;
|
|
144
|
+
|
|
145
|
+
css(target, 'transform', 'translate3d(' + translateX + 'px,' + translateY + 'px,0)');
|
|
146
|
+
|
|
147
|
+
this.forRepaintDummy = repaint(target); // repaint
|
|
148
|
+
|
|
149
|
+
css(target, 'transition', 'transform ' + duration + 'ms' + (this.options.easing ? ' ' + this.options.easing : ''));
|
|
150
|
+
css(target, 'transform', 'translate3d(0,0,0)');
|
|
151
|
+
(typeof target.animated === 'number') && clearTimeout(target.animated);
|
|
152
|
+
target.animated = setTimeout(function () {
|
|
153
|
+
css(target, 'transition', '');
|
|
154
|
+
css(target, 'transform', '');
|
|
155
|
+
target.animated = false;
|
|
156
|
+
|
|
157
|
+
target.animatingX = false;
|
|
158
|
+
target.animatingY = false;
|
|
159
|
+
}, duration);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function repaint(target) {
|
|
166
|
+
return target.offsetWidth;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
function calculateRealTime(animatingRect, fromRect, toRect, options) {
|
|
171
|
+
return (
|
|
172
|
+
Math.sqrt(Math.pow(fromRect.top - animatingRect.top, 2) + Math.pow(fromRect.left - animatingRect.left, 2)) /
|
|
173
|
+
Math.sqrt(Math.pow(fromRect.top - toRect.top, 2) + Math.pow(fromRect.left - toRect.left, 2))
|
|
174
|
+
) * options.animation;
|
|
175
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function userAgent(pattern) {
|
|
2
|
+
if (typeof window !== 'undefined' && window.navigator) {
|
|
3
|
+
return !!/*@__PURE__*/navigator.userAgent.match(pattern);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
|
|
8
|
+
export const Edge = userAgent(/Edge/i);
|
|
9
|
+
export const FireFox = userAgent(/firefox/i);
|
|
10
|
+
export const Safari = userAgent(/safari/i) && !userAgent(/chrome/i) && !userAgent(/android/i);
|
|
11
|
+
export const IOS = userAgent(/iP(ad|od|hone)/i);
|
|
12
|
+
export const ChromeForAndroid = userAgent(/chrome/i) && userAgent(/android/i);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IE11OrLess, Edge } from './BrowserInfo.js';
|
|
2
|
+
import { expando } from './utils.js';
|
|
3
|
+
import PluginManager from './PluginManager.js';
|
|
4
|
+
|
|
5
|
+
export default function dispatchEvent(
|
|
6
|
+
{
|
|
7
|
+
sortable, rootEl, name,
|
|
8
|
+
targetEl, cloneEl, toEl, fromEl,
|
|
9
|
+
oldIndex, newIndex,
|
|
10
|
+
oldDraggableIndex, newDraggableIndex,
|
|
11
|
+
originalEvent, putSortable, extraEventProperties
|
|
12
|
+
}
|
|
13
|
+
) {
|
|
14
|
+
sortable = (sortable || (rootEl && rootEl[expando]));
|
|
15
|
+
if (!sortable) return;
|
|
16
|
+
|
|
17
|
+
let evt,
|
|
18
|
+
options = sortable.options,
|
|
19
|
+
onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
|
|
20
|
+
// Support for new CustomEvent feature
|
|
21
|
+
if (window.CustomEvent && !IE11OrLess && !Edge) {
|
|
22
|
+
evt = new CustomEvent(name, {
|
|
23
|
+
bubbles: true,
|
|
24
|
+
cancelable: true
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
evt = document.createEvent('Event');
|
|
28
|
+
evt.initEvent(name, true, true);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
evt.to = toEl || rootEl;
|
|
32
|
+
evt.from = fromEl || rootEl;
|
|
33
|
+
evt.item = targetEl || rootEl;
|
|
34
|
+
evt.clone = cloneEl;
|
|
35
|
+
|
|
36
|
+
evt.oldIndex = oldIndex;
|
|
37
|
+
evt.newIndex = newIndex;
|
|
38
|
+
|
|
39
|
+
evt.oldDraggableIndex = oldDraggableIndex;
|
|
40
|
+
evt.newDraggableIndex = newDraggableIndex;
|
|
41
|
+
|
|
42
|
+
evt.originalEvent = originalEvent;
|
|
43
|
+
evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
|
|
44
|
+
|
|
45
|
+
let allEventProperties = { ...extraEventProperties, ...PluginManager.getEventProperties(name, sortable) };
|
|
46
|
+
for (let option in allEventProperties) {
|
|
47
|
+
evt[option] = allEventProperties[option];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (rootEl) {
|
|
51
|
+
rootEl.dispatchEvent(evt);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (options[onName]) {
|
|
55
|
+
options[onName].call(sortable, evt);
|
|
56
|
+
}
|
|
57
|
+
}
|