svelte-dnd-action 0.9.16 → 0.9.19
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 +29 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +158 -83
- package/dist/index.mjs +158 -83
- package/package.json +1 -1
- package/src/helpers/styler.js +3 -2
- package/src/helpers/svelteNodeClone.js +35 -0
- package/src/pointerAction.js +29 -5
package/README.md
CHANGED
|
@@ -285,6 +285,35 @@ Then you will be able to use the library with type safety as follows (Typescript
|
|
|
285
285
|
</section>
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
+
#### Custom types with `DndEvent<T>`
|
|
289
|
+
|
|
290
|
+
You can use generics to set the type of `items` you are expecting in `DndEvent`. Simply add a type to it like so: `DndEvent<Dog>`. For example:
|
|
291
|
+
|
|
292
|
+
```html
|
|
293
|
+
<script lang="ts">
|
|
294
|
+
import {dndzone} from "svelte-dnd-action";
|
|
295
|
+
import {flip} from "svelte/animate";
|
|
296
|
+
|
|
297
|
+
interface Dog {
|
|
298
|
+
id: number;
|
|
299
|
+
name: string;
|
|
300
|
+
breed: string;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function handleSort(e: CustomEvent<DndEvent<Dog>>) {
|
|
304
|
+
//e.detail.items now evaluates to type Dog.
|
|
305
|
+
items = e.detail.items;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
let items: Dog[] = [
|
|
309
|
+
{ id: 1, name: 'Fido', breed: 'bulldog' },
|
|
310
|
+
{ id: 2, name: 'Spot', breed: 'labrador' },
|
|
311
|
+
{ id: 3, name: 'Jacky', breed: 'golden retriever' }
|
|
312
|
+
];
|
|
313
|
+
</script>
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
|
|
288
317
|
### Contributing [](https://github.com/isaacHagoel/svelte-dnd-action/issues)
|
|
289
318
|
|
|
290
319
|
There is still quite a lot to do. If you'd like to contribute please get in touch (raise an issue or comment on an existing one).
|
package/dist/index.d.ts
CHANGED
|
@@ -70,8 +70,8 @@ export interface DndEventInfo {
|
|
|
70
70
|
source: SOURCES; // the type of interaction that the user used to perform the dnd operation
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export type DndEvent = {
|
|
74
|
-
items:
|
|
73
|
+
export type DndEvent<T = Item> = {
|
|
74
|
+
items: T[];
|
|
75
75
|
info: DndEventInfo;
|
|
76
76
|
};
|
|
77
77
|
|
package/dist/index.js
CHANGED
|
@@ -4,20 +4,40 @@
|
|
|
4
4
|
(global = global || self, factory(global.DndAction = {}));
|
|
5
5
|
}(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
|
|
7
|
+
function ownKeys(object, enumerableOnly) {
|
|
8
|
+
var keys = Object.keys(object);
|
|
9
9
|
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
if (Object.getOwnPropertySymbols) {
|
|
11
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
12
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
13
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
14
|
+
})), keys.push.apply(keys, symbols);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return keys;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _objectSpread2(target) {
|
|
21
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
22
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
23
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
24
|
+
_defineProperty(target, key, source[key]);
|
|
25
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
26
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
27
|
+
});
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
return
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _typeof(obj) {
|
|
34
|
+
"@babel/helpers - typeof";
|
|
35
|
+
|
|
36
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
37
|
+
return typeof obj;
|
|
38
|
+
} : function (obj) {
|
|
39
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
40
|
+
}, _typeof(obj);
|
|
21
41
|
}
|
|
22
42
|
|
|
23
43
|
function _defineProperty(obj, key, value) {
|
|
@@ -35,40 +55,6 @@
|
|
|
35
55
|
return obj;
|
|
36
56
|
}
|
|
37
57
|
|
|
38
|
-
function ownKeys(object, enumerableOnly) {
|
|
39
|
-
var keys = Object.keys(object);
|
|
40
|
-
|
|
41
|
-
if (Object.getOwnPropertySymbols) {
|
|
42
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
43
|
-
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
44
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
45
|
-
});
|
|
46
|
-
keys.push.apply(keys, symbols);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return keys;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function _objectSpread2(target) {
|
|
53
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
54
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
55
|
-
|
|
56
|
-
if (i % 2) {
|
|
57
|
-
ownKeys(Object(source), true).forEach(function (key) {
|
|
58
|
-
_defineProperty(target, key, source[key]);
|
|
59
|
-
});
|
|
60
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
61
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
62
|
-
} else {
|
|
63
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
64
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return target;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
58
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
73
59
|
if (source == null) return {};
|
|
74
60
|
var target = {};
|
|
@@ -122,18 +108,21 @@
|
|
|
122
108
|
}
|
|
123
109
|
|
|
124
110
|
function _iterableToArray(iter) {
|
|
125
|
-
if (typeof Symbol !== "undefined" && Symbol.iterator
|
|
111
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
126
112
|
}
|
|
127
113
|
|
|
128
114
|
function _iterableToArrayLimit(arr, i) {
|
|
129
|
-
|
|
115
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
116
|
+
|
|
117
|
+
if (_i == null) return;
|
|
130
118
|
var _arr = [];
|
|
131
119
|
var _n = true;
|
|
132
120
|
var _d = false;
|
|
133
|
-
|
|
121
|
+
|
|
122
|
+
var _s, _e;
|
|
134
123
|
|
|
135
124
|
try {
|
|
136
|
-
for (
|
|
125
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
137
126
|
_arr.push(_s.value);
|
|
138
127
|
|
|
139
128
|
if (i && _arr.length === i) break;
|
|
@@ -178,9 +167,9 @@
|
|
|
178
167
|
}
|
|
179
168
|
|
|
180
169
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
181
|
-
var it;
|
|
170
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
182
171
|
|
|
183
|
-
if (
|
|
172
|
+
if (!it) {
|
|
184
173
|
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
185
174
|
if (it) o = it;
|
|
186
175
|
var i = 0;
|
|
@@ -213,7 +202,7 @@
|
|
|
213
202
|
err;
|
|
214
203
|
return {
|
|
215
204
|
s: function () {
|
|
216
|
-
it =
|
|
205
|
+
it = it.call(o);
|
|
217
206
|
},
|
|
218
207
|
n: function () {
|
|
219
208
|
var step = it.next();
|
|
@@ -1054,6 +1043,54 @@
|
|
|
1054
1043
|
resetScrolling$1();
|
|
1055
1044
|
}
|
|
1056
1045
|
|
|
1046
|
+
/**
|
|
1047
|
+
* Fixes svelte issue when cloning node containing (or being) <select> which will loose it's value.
|
|
1048
|
+
* Since svelte manages select value internally.
|
|
1049
|
+
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
1050
|
+
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
1051
|
+
*
|
|
1052
|
+
* @param {HTMLElement} el
|
|
1053
|
+
* @returns
|
|
1054
|
+
*/
|
|
1055
|
+
function svelteNodeClone(el) {
|
|
1056
|
+
var cloned = el.cloneNode(true);
|
|
1057
|
+
var values = [];
|
|
1058
|
+
var elIsSelect = el.tagName === "SELECT";
|
|
1059
|
+
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll('select'));
|
|
1060
|
+
|
|
1061
|
+
var _iterator = _createForOfIteratorHelper(selects),
|
|
1062
|
+
_step;
|
|
1063
|
+
|
|
1064
|
+
try {
|
|
1065
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1066
|
+
var _select = _step.value;
|
|
1067
|
+
values.push(_select.value);
|
|
1068
|
+
}
|
|
1069
|
+
} catch (err) {
|
|
1070
|
+
_iterator.e(err);
|
|
1071
|
+
} finally {
|
|
1072
|
+
_iterator.f();
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
if (selects.length <= 0) {
|
|
1076
|
+
return cloned;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll('select'));
|
|
1080
|
+
|
|
1081
|
+
for (var i = 0; i < clonedSelects.length; i++) {
|
|
1082
|
+
var select = clonedSelects[i];
|
|
1083
|
+
var value = values[i];
|
|
1084
|
+
var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
|
|
1085
|
+
|
|
1086
|
+
if (optionEl) {
|
|
1087
|
+
optionEl.setAttribute('selected', true);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
return cloned;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1057
1094
|
var TRANSITION_DURATION_SECONDS = 0.2;
|
|
1058
1095
|
/**
|
|
1059
1096
|
* private helper function - creates a transition string for a property
|
|
@@ -1074,7 +1111,7 @@
|
|
|
1074
1111
|
|
|
1075
1112
|
function createDraggedElementFrom(originalElement, positionCenterOnXY) {
|
|
1076
1113
|
var rect = originalElement.getBoundingClientRect();
|
|
1077
|
-
var draggedEl = originalElement
|
|
1114
|
+
var draggedEl = svelteNodeClone(originalElement);
|
|
1078
1115
|
copyStylesFromTo(originalElement, draggedEl);
|
|
1079
1116
|
draggedEl.id = DRAGGED_ELEMENT_ID;
|
|
1080
1117
|
draggedEl.style.position = "fixed";
|
|
@@ -1187,7 +1224,7 @@
|
|
|
1187
1224
|
* @param {HTMLElement} dragTarget
|
|
1188
1225
|
*/
|
|
1189
1226
|
|
|
1190
|
-
function
|
|
1227
|
+
function hideElement(dragTarget) {
|
|
1191
1228
|
dragTarget.style.display = "none";
|
|
1192
1229
|
dragTarget.style.position = "fixed";
|
|
1193
1230
|
dragTarget.style.zIndex = "-5";
|
|
@@ -1290,7 +1327,8 @@
|
|
|
1290
1327
|
var isWorkingOnPreviousDrag = false;
|
|
1291
1328
|
var finalizingPreviousDrag = false;
|
|
1292
1329
|
var unlockOriginDzMinDimensions;
|
|
1293
|
-
var isDraggedOutsideOfAnyDz = false;
|
|
1330
|
+
var isDraggedOutsideOfAnyDz = false;
|
|
1331
|
+
var scheduledForRemovalAfterDrop = []; // a map from type to a set of drop-zones
|
|
1294
1332
|
|
|
1295
1333
|
var typeToDropZones = new Map(); // important - this is needed because otherwise the config that would be used for everyone is the config of the element that created the event listeners
|
|
1296
1334
|
|
|
@@ -1626,12 +1664,37 @@
|
|
|
1626
1664
|
draggedEl.style.transform = "translate3d(".concat(newTransform.x, "px, ").concat(newTransform.y, "px, 0)");
|
|
1627
1665
|
window.setTimeout(callback, dropAnimationDurationMs);
|
|
1628
1666
|
}
|
|
1667
|
+
|
|
1668
|
+
function scheduleDZForRemovalAfterDrop(dz, destroy) {
|
|
1669
|
+
scheduledForRemovalAfterDrop.push({
|
|
1670
|
+
dz: dz,
|
|
1671
|
+
destroy: destroy
|
|
1672
|
+
});
|
|
1673
|
+
window.requestAnimationFrame(function () {
|
|
1674
|
+
hideElement(dz);
|
|
1675
|
+
document.body.appendChild(dz);
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1629
1678
|
/* cleanup */
|
|
1630
1679
|
|
|
1631
1680
|
|
|
1632
1681
|
function cleanupPostDrop() {
|
|
1633
1682
|
draggedEl.remove();
|
|
1634
1683
|
originalDragTarget.remove();
|
|
1684
|
+
|
|
1685
|
+
if (scheduledForRemovalAfterDrop.length) {
|
|
1686
|
+
printDebug(function () {
|
|
1687
|
+
return ["will destroy zones that were removed during drag", scheduledForRemovalAfterDrop];
|
|
1688
|
+
});
|
|
1689
|
+
scheduledForRemovalAfterDrop.forEach(function (_ref) {
|
|
1690
|
+
var dz = _ref.dz,
|
|
1691
|
+
destroy = _ref.destroy;
|
|
1692
|
+
destroy();
|
|
1693
|
+
dz.remove();
|
|
1694
|
+
});
|
|
1695
|
+
scheduledForRemovalAfterDrop = [];
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1635
1698
|
draggedEl = undefined;
|
|
1636
1699
|
originalDragTarget = undefined;
|
|
1637
1700
|
draggedElData = undefined;
|
|
@@ -1779,7 +1842,7 @@
|
|
|
1779
1842
|
|
|
1780
1843
|
draggedEl.focus();
|
|
1781
1844
|
watchDraggedElement();
|
|
1782
|
-
|
|
1845
|
+
hideElement(originalDragTarget);
|
|
1783
1846
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
1784
1847
|
} else {
|
|
1785
1848
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
@@ -1818,27 +1881,27 @@
|
|
|
1818
1881
|
});
|
|
1819
1882
|
}
|
|
1820
1883
|
|
|
1821
|
-
function configure(
|
|
1822
|
-
var
|
|
1823
|
-
items =
|
|
1824
|
-
|
|
1825
|
-
dropAnimationDurationMs =
|
|
1826
|
-
|
|
1827
|
-
newType =
|
|
1828
|
-
|
|
1829
|
-
dragDisabled =
|
|
1830
|
-
|
|
1831
|
-
morphDisabled =
|
|
1832
|
-
|
|
1833
|
-
dropFromOthersDisabled =
|
|
1834
|
-
|
|
1835
|
-
dropTargetStyle =
|
|
1836
|
-
|
|
1837
|
-
dropTargetClasses =
|
|
1838
|
-
|
|
1839
|
-
transformDraggedElement =
|
|
1840
|
-
|
|
1841
|
-
centreDraggedOnCursor =
|
|
1884
|
+
function configure(_ref2) {
|
|
1885
|
+
var _ref2$items = _ref2.items,
|
|
1886
|
+
items = _ref2$items === void 0 ? undefined : _ref2$items,
|
|
1887
|
+
_ref2$flipDurationMs = _ref2.flipDurationMs,
|
|
1888
|
+
dropAnimationDurationMs = _ref2$flipDurationMs === void 0 ? 0 : _ref2$flipDurationMs,
|
|
1889
|
+
_ref2$type = _ref2.type,
|
|
1890
|
+
newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE : _ref2$type,
|
|
1891
|
+
_ref2$dragDisabled = _ref2.dragDisabled,
|
|
1892
|
+
dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled,
|
|
1893
|
+
_ref2$morphDisabled = _ref2.morphDisabled,
|
|
1894
|
+
morphDisabled = _ref2$morphDisabled === void 0 ? false : _ref2$morphDisabled,
|
|
1895
|
+
_ref2$dropFromOthersD = _ref2.dropFromOthersDisabled,
|
|
1896
|
+
dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD,
|
|
1897
|
+
_ref2$dropTargetStyle = _ref2.dropTargetStyle,
|
|
1898
|
+
dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE : _ref2$dropTargetStyle,
|
|
1899
|
+
_ref2$dropTargetClass = _ref2.dropTargetClasses,
|
|
1900
|
+
dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass,
|
|
1901
|
+
_ref2$transformDragge = _ref2.transformDraggedElement,
|
|
1902
|
+
transformDraggedElement = _ref2$transformDragge === void 0 ? function () {} : _ref2$transformDragge,
|
|
1903
|
+
_ref2$centreDraggedOn = _ref2.centreDraggedOnCursor,
|
|
1904
|
+
centreDraggedOnCursor = _ref2$centreDraggedOn === void 0 ? false : _ref2$centreDraggedOn;
|
|
1842
1905
|
config.dropAnimationDurationMs = dropAnimationDurationMs;
|
|
1843
1906
|
|
|
1844
1907
|
if (config.type && newType !== config.type) {
|
|
@@ -1941,11 +2004,22 @@
|
|
|
1941
2004
|
configure(newOptions);
|
|
1942
2005
|
},
|
|
1943
2006
|
destroy: function destroy() {
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
2007
|
+
function destroyDz() {
|
|
2008
|
+
printDebug(function () {
|
|
2009
|
+
return "pointer dndzone will destroy";
|
|
2010
|
+
});
|
|
2011
|
+
unregisterDropZone(node, dzToConfig.get(node).type);
|
|
2012
|
+
dzToConfig["delete"](node);
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
if (isWorkingOnPreviousDrag) {
|
|
2016
|
+
printDebug(function () {
|
|
2017
|
+
return "pointer dndzone will be scheduled for destruction";
|
|
2018
|
+
});
|
|
2019
|
+
scheduleDZForRemovalAfterDrop(node, destroyDz);
|
|
2020
|
+
} else {
|
|
2021
|
+
destroyDz();
|
|
2022
|
+
}
|
|
1949
2023
|
}
|
|
1950
2024
|
};
|
|
1951
2025
|
}
|
|
@@ -2527,6 +2601,7 @@
|
|
|
2527
2601
|
return handles;
|
|
2528
2602
|
}
|
|
2529
2603
|
|
|
2604
|
+
var _excluded = ["items", "flipDurationMs", "type", "dragDisabled", "morphDisabled", "dropFromOthersDisabled", "zoneTabIndex", "dropTargetStyle", "dropTargetClasses", "transformDraggedElement", "autoAriaDisabled", "centreDraggedOnCursor"];
|
|
2530
2605
|
/**
|
|
2531
2606
|
* A custom action to turn any container to a dnd zone and all of its direct children to draggables
|
|
2532
2607
|
* Supports mouse, touch and keyboard interactions.
|
|
@@ -2580,7 +2655,7 @@
|
|
|
2580
2655
|
transformDraggedElement = options.transformDraggedElement,
|
|
2581
2656
|
autoAriaDisabled = options.autoAriaDisabled,
|
|
2582
2657
|
centreDraggedOnCursor = options.centreDraggedOnCursor,
|
|
2583
|
-
rest = _objectWithoutProperties(options,
|
|
2658
|
+
rest = _objectWithoutProperties(options, _excluded);
|
|
2584
2659
|
/*eslint-enable*/
|
|
2585
2660
|
|
|
2586
2661
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,37 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
1
|
+
function ownKeys(object, enumerableOnly) {
|
|
2
|
+
var keys = Object.keys(object);
|
|
3
3
|
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
if (Object.getOwnPropertySymbols) {
|
|
5
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
6
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
7
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
8
|
+
})), keys.push.apply(keys, symbols);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return keys;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function _objectSpread2(target) {
|
|
15
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
16
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
17
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
18
|
+
_defineProperty(target, key, source[key]);
|
|
19
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
20
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
21
|
+
});
|
|
12
22
|
}
|
|
13
23
|
|
|
14
|
-
return
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function _typeof(obj) {
|
|
28
|
+
"@babel/helpers - typeof";
|
|
29
|
+
|
|
30
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
31
|
+
return typeof obj;
|
|
32
|
+
} : function (obj) {
|
|
33
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
34
|
+
}, _typeof(obj);
|
|
15
35
|
}
|
|
16
36
|
|
|
17
37
|
function _defineProperty(obj, key, value) {
|
|
@@ -29,40 +49,6 @@ function _defineProperty(obj, key, value) {
|
|
|
29
49
|
return obj;
|
|
30
50
|
}
|
|
31
51
|
|
|
32
|
-
function ownKeys(object, enumerableOnly) {
|
|
33
|
-
var keys = Object.keys(object);
|
|
34
|
-
|
|
35
|
-
if (Object.getOwnPropertySymbols) {
|
|
36
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
37
|
-
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
38
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
39
|
-
});
|
|
40
|
-
keys.push.apply(keys, symbols);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return keys;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function _objectSpread2(target) {
|
|
47
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
48
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
49
|
-
|
|
50
|
-
if (i % 2) {
|
|
51
|
-
ownKeys(Object(source), true).forEach(function (key) {
|
|
52
|
-
_defineProperty(target, key, source[key]);
|
|
53
|
-
});
|
|
54
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
55
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
56
|
-
} else {
|
|
57
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
58
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return target;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
52
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
67
53
|
if (source == null) return {};
|
|
68
54
|
var target = {};
|
|
@@ -116,18 +102,21 @@ function _arrayWithHoles(arr) {
|
|
|
116
102
|
}
|
|
117
103
|
|
|
118
104
|
function _iterableToArray(iter) {
|
|
119
|
-
if (typeof Symbol !== "undefined" && Symbol.iterator
|
|
105
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
120
106
|
}
|
|
121
107
|
|
|
122
108
|
function _iterableToArrayLimit(arr, i) {
|
|
123
|
-
|
|
109
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
110
|
+
|
|
111
|
+
if (_i == null) return;
|
|
124
112
|
var _arr = [];
|
|
125
113
|
var _n = true;
|
|
126
114
|
var _d = false;
|
|
127
|
-
|
|
115
|
+
|
|
116
|
+
var _s, _e;
|
|
128
117
|
|
|
129
118
|
try {
|
|
130
|
-
for (
|
|
119
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
131
120
|
_arr.push(_s.value);
|
|
132
121
|
|
|
133
122
|
if (i && _arr.length === i) break;
|
|
@@ -172,9 +161,9 @@ function _nonIterableRest() {
|
|
|
172
161
|
}
|
|
173
162
|
|
|
174
163
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
175
|
-
var it;
|
|
164
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
176
165
|
|
|
177
|
-
if (
|
|
166
|
+
if (!it) {
|
|
178
167
|
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
179
168
|
if (it) o = it;
|
|
180
169
|
var i = 0;
|
|
@@ -207,7 +196,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
207
196
|
err;
|
|
208
197
|
return {
|
|
209
198
|
s: function () {
|
|
210
|
-
it =
|
|
199
|
+
it = it.call(o);
|
|
211
200
|
},
|
|
212
201
|
n: function () {
|
|
213
202
|
var step = it.next();
|
|
@@ -1048,6 +1037,54 @@ function disarmWindowScroller() {
|
|
|
1048
1037
|
resetScrolling$1();
|
|
1049
1038
|
}
|
|
1050
1039
|
|
|
1040
|
+
/**
|
|
1041
|
+
* Fixes svelte issue when cloning node containing (or being) <select> which will loose it's value.
|
|
1042
|
+
* Since svelte manages select value internally.
|
|
1043
|
+
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
1044
|
+
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
1045
|
+
*
|
|
1046
|
+
* @param {HTMLElement} el
|
|
1047
|
+
* @returns
|
|
1048
|
+
*/
|
|
1049
|
+
function svelteNodeClone(el) {
|
|
1050
|
+
var cloned = el.cloneNode(true);
|
|
1051
|
+
var values = [];
|
|
1052
|
+
var elIsSelect = el.tagName === "SELECT";
|
|
1053
|
+
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll('select'));
|
|
1054
|
+
|
|
1055
|
+
var _iterator = _createForOfIteratorHelper(selects),
|
|
1056
|
+
_step;
|
|
1057
|
+
|
|
1058
|
+
try {
|
|
1059
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1060
|
+
var _select = _step.value;
|
|
1061
|
+
values.push(_select.value);
|
|
1062
|
+
}
|
|
1063
|
+
} catch (err) {
|
|
1064
|
+
_iterator.e(err);
|
|
1065
|
+
} finally {
|
|
1066
|
+
_iterator.f();
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
if (selects.length <= 0) {
|
|
1070
|
+
return cloned;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll('select'));
|
|
1074
|
+
|
|
1075
|
+
for (var i = 0; i < clonedSelects.length; i++) {
|
|
1076
|
+
var select = clonedSelects[i];
|
|
1077
|
+
var value = values[i];
|
|
1078
|
+
var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
|
|
1079
|
+
|
|
1080
|
+
if (optionEl) {
|
|
1081
|
+
optionEl.setAttribute('selected', true);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
return cloned;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1051
1088
|
var TRANSITION_DURATION_SECONDS = 0.2;
|
|
1052
1089
|
/**
|
|
1053
1090
|
* private helper function - creates a transition string for a property
|
|
@@ -1068,7 +1105,7 @@ function trs(property) {
|
|
|
1068
1105
|
|
|
1069
1106
|
function createDraggedElementFrom(originalElement, positionCenterOnXY) {
|
|
1070
1107
|
var rect = originalElement.getBoundingClientRect();
|
|
1071
|
-
var draggedEl = originalElement
|
|
1108
|
+
var draggedEl = svelteNodeClone(originalElement);
|
|
1072
1109
|
copyStylesFromTo(originalElement, draggedEl);
|
|
1073
1110
|
draggedEl.id = DRAGGED_ELEMENT_ID;
|
|
1074
1111
|
draggedEl.style.position = "fixed";
|
|
@@ -1181,7 +1218,7 @@ function styleDraggable(draggableEl, dragDisabled) {
|
|
|
1181
1218
|
* @param {HTMLElement} dragTarget
|
|
1182
1219
|
*/
|
|
1183
1220
|
|
|
1184
|
-
function
|
|
1221
|
+
function hideElement(dragTarget) {
|
|
1185
1222
|
dragTarget.style.display = "none";
|
|
1186
1223
|
dragTarget.style.position = "fixed";
|
|
1187
1224
|
dragTarget.style.zIndex = "-5";
|
|
@@ -1284,7 +1321,8 @@ var currentMousePosition;
|
|
|
1284
1321
|
var isWorkingOnPreviousDrag = false;
|
|
1285
1322
|
var finalizingPreviousDrag = false;
|
|
1286
1323
|
var unlockOriginDzMinDimensions;
|
|
1287
|
-
var isDraggedOutsideOfAnyDz = false;
|
|
1324
|
+
var isDraggedOutsideOfAnyDz = false;
|
|
1325
|
+
var scheduledForRemovalAfterDrop = []; // a map from type to a set of drop-zones
|
|
1288
1326
|
|
|
1289
1327
|
var typeToDropZones = new Map(); // important - this is needed because otherwise the config that would be used for everyone is the config of the element that created the event listeners
|
|
1290
1328
|
|
|
@@ -1620,12 +1658,37 @@ function animateDraggedToFinalPosition(shadowElIdx, callback) {
|
|
|
1620
1658
|
draggedEl.style.transform = "translate3d(".concat(newTransform.x, "px, ").concat(newTransform.y, "px, 0)");
|
|
1621
1659
|
window.setTimeout(callback, dropAnimationDurationMs);
|
|
1622
1660
|
}
|
|
1661
|
+
|
|
1662
|
+
function scheduleDZForRemovalAfterDrop(dz, destroy) {
|
|
1663
|
+
scheduledForRemovalAfterDrop.push({
|
|
1664
|
+
dz: dz,
|
|
1665
|
+
destroy: destroy
|
|
1666
|
+
});
|
|
1667
|
+
window.requestAnimationFrame(function () {
|
|
1668
|
+
hideElement(dz);
|
|
1669
|
+
document.body.appendChild(dz);
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1623
1672
|
/* cleanup */
|
|
1624
1673
|
|
|
1625
1674
|
|
|
1626
1675
|
function cleanupPostDrop() {
|
|
1627
1676
|
draggedEl.remove();
|
|
1628
1677
|
originalDragTarget.remove();
|
|
1678
|
+
|
|
1679
|
+
if (scheduledForRemovalAfterDrop.length) {
|
|
1680
|
+
printDebug(function () {
|
|
1681
|
+
return ["will destroy zones that were removed during drag", scheduledForRemovalAfterDrop];
|
|
1682
|
+
});
|
|
1683
|
+
scheduledForRemovalAfterDrop.forEach(function (_ref) {
|
|
1684
|
+
var dz = _ref.dz,
|
|
1685
|
+
destroy = _ref.destroy;
|
|
1686
|
+
destroy();
|
|
1687
|
+
dz.remove();
|
|
1688
|
+
});
|
|
1689
|
+
scheduledForRemovalAfterDrop = [];
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1629
1692
|
draggedEl = undefined;
|
|
1630
1693
|
originalDragTarget = undefined;
|
|
1631
1694
|
draggedElData = undefined;
|
|
@@ -1773,7 +1836,7 @@ function dndzone(node, options) {
|
|
|
1773
1836
|
|
|
1774
1837
|
draggedEl.focus();
|
|
1775
1838
|
watchDraggedElement();
|
|
1776
|
-
|
|
1839
|
+
hideElement(originalDragTarget);
|
|
1777
1840
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
1778
1841
|
} else {
|
|
1779
1842
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
@@ -1812,27 +1875,27 @@ function dndzone(node, options) {
|
|
|
1812
1875
|
});
|
|
1813
1876
|
}
|
|
1814
1877
|
|
|
1815
|
-
function configure(
|
|
1816
|
-
var
|
|
1817
|
-
items =
|
|
1818
|
-
|
|
1819
|
-
dropAnimationDurationMs =
|
|
1820
|
-
|
|
1821
|
-
newType =
|
|
1822
|
-
|
|
1823
|
-
dragDisabled =
|
|
1824
|
-
|
|
1825
|
-
morphDisabled =
|
|
1826
|
-
|
|
1827
|
-
dropFromOthersDisabled =
|
|
1828
|
-
|
|
1829
|
-
dropTargetStyle =
|
|
1830
|
-
|
|
1831
|
-
dropTargetClasses =
|
|
1832
|
-
|
|
1833
|
-
transformDraggedElement =
|
|
1834
|
-
|
|
1835
|
-
centreDraggedOnCursor =
|
|
1878
|
+
function configure(_ref2) {
|
|
1879
|
+
var _ref2$items = _ref2.items,
|
|
1880
|
+
items = _ref2$items === void 0 ? undefined : _ref2$items,
|
|
1881
|
+
_ref2$flipDurationMs = _ref2.flipDurationMs,
|
|
1882
|
+
dropAnimationDurationMs = _ref2$flipDurationMs === void 0 ? 0 : _ref2$flipDurationMs,
|
|
1883
|
+
_ref2$type = _ref2.type,
|
|
1884
|
+
newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE : _ref2$type,
|
|
1885
|
+
_ref2$dragDisabled = _ref2.dragDisabled,
|
|
1886
|
+
dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled,
|
|
1887
|
+
_ref2$morphDisabled = _ref2.morphDisabled,
|
|
1888
|
+
morphDisabled = _ref2$morphDisabled === void 0 ? false : _ref2$morphDisabled,
|
|
1889
|
+
_ref2$dropFromOthersD = _ref2.dropFromOthersDisabled,
|
|
1890
|
+
dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD,
|
|
1891
|
+
_ref2$dropTargetStyle = _ref2.dropTargetStyle,
|
|
1892
|
+
dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE : _ref2$dropTargetStyle,
|
|
1893
|
+
_ref2$dropTargetClass = _ref2.dropTargetClasses,
|
|
1894
|
+
dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass,
|
|
1895
|
+
_ref2$transformDragge = _ref2.transformDraggedElement,
|
|
1896
|
+
transformDraggedElement = _ref2$transformDragge === void 0 ? function () {} : _ref2$transformDragge,
|
|
1897
|
+
_ref2$centreDraggedOn = _ref2.centreDraggedOnCursor,
|
|
1898
|
+
centreDraggedOnCursor = _ref2$centreDraggedOn === void 0 ? false : _ref2$centreDraggedOn;
|
|
1836
1899
|
config.dropAnimationDurationMs = dropAnimationDurationMs;
|
|
1837
1900
|
|
|
1838
1901
|
if (config.type && newType !== config.type) {
|
|
@@ -1935,11 +1998,22 @@ function dndzone(node, options) {
|
|
|
1935
1998
|
configure(newOptions);
|
|
1936
1999
|
},
|
|
1937
2000
|
destroy: function destroy() {
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
2001
|
+
function destroyDz() {
|
|
2002
|
+
printDebug(function () {
|
|
2003
|
+
return "pointer dndzone will destroy";
|
|
2004
|
+
});
|
|
2005
|
+
unregisterDropZone(node, dzToConfig.get(node).type);
|
|
2006
|
+
dzToConfig["delete"](node);
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
if (isWorkingOnPreviousDrag) {
|
|
2010
|
+
printDebug(function () {
|
|
2011
|
+
return "pointer dndzone will be scheduled for destruction";
|
|
2012
|
+
});
|
|
2013
|
+
scheduleDZForRemovalAfterDrop(node, destroyDz);
|
|
2014
|
+
} else {
|
|
2015
|
+
destroyDz();
|
|
2016
|
+
}
|
|
1943
2017
|
}
|
|
1944
2018
|
};
|
|
1945
2019
|
}
|
|
@@ -2521,6 +2595,7 @@ function dndzone$1(node, options) {
|
|
|
2521
2595
|
return handles;
|
|
2522
2596
|
}
|
|
2523
2597
|
|
|
2598
|
+
var _excluded = ["items", "flipDurationMs", "type", "dragDisabled", "morphDisabled", "dropFromOthersDisabled", "zoneTabIndex", "dropTargetStyle", "dropTargetClasses", "transformDraggedElement", "autoAriaDisabled", "centreDraggedOnCursor"];
|
|
2524
2599
|
/**
|
|
2525
2600
|
* A custom action to turn any container to a dnd zone and all of its direct children to draggables
|
|
2526
2601
|
* Supports mouse, touch and keyboard interactions.
|
|
@@ -2574,7 +2649,7 @@ function validateOptions(options) {
|
|
|
2574
2649
|
transformDraggedElement = options.transformDraggedElement,
|
|
2575
2650
|
autoAriaDisabled = options.autoAriaDisabled,
|
|
2576
2651
|
centreDraggedOnCursor = options.centreDraggedOnCursor,
|
|
2577
|
-
rest = _objectWithoutProperties(options,
|
|
2652
|
+
rest = _objectWithoutProperties(options, _excluded);
|
|
2578
2653
|
/*eslint-enable*/
|
|
2579
2654
|
|
|
2580
2655
|
|
package/package.json
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"description": "*An awesome drag and drop library for Svelte 3 (not using the browser's built-in dnd, thanks god): Rich animations, nested containers, touch support and more *",
|
|
43
|
-
"version": "0.9.
|
|
43
|
+
"version": "0.9.19",
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
46
|
"url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
|
package/src/helpers/styler.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {SHADOW_ELEMENT_ATTRIBUTE_NAME, DRAGGED_ELEMENT_ID} from "../constants";
|
|
2
2
|
import {findCenter} from "./intersection";
|
|
3
|
+
import { svelteNodeClone } from "./svelteNodeClone";
|
|
3
4
|
|
|
4
5
|
const TRANSITION_DURATION_SECONDS = 0.2;
|
|
5
6
|
|
|
@@ -19,7 +20,7 @@ function trs(property) {
|
|
|
19
20
|
*/
|
|
20
21
|
export function createDraggedElementFrom(originalElement, positionCenterOnXY) {
|
|
21
22
|
const rect = originalElement.getBoundingClientRect();
|
|
22
|
-
const draggedEl = originalElement
|
|
23
|
+
const draggedEl = svelteNodeClone(originalElement);
|
|
23
24
|
copyStylesFromTo(originalElement, draggedEl);
|
|
24
25
|
draggedEl.id = DRAGGED_ELEMENT_ID;
|
|
25
26
|
draggedEl.style.position = "fixed";
|
|
@@ -135,7 +136,7 @@ export function styleDraggable(draggableEl, dragDisabled) {
|
|
|
135
136
|
* Hides the provided element so that it can stay in the dom without interrupting
|
|
136
137
|
* @param {HTMLElement} dragTarget
|
|
137
138
|
*/
|
|
138
|
-
export function
|
|
139
|
+
export function hideElement(dragTarget) {
|
|
139
140
|
dragTarget.style.display = "none";
|
|
140
141
|
dragTarget.style.position = "fixed";
|
|
141
142
|
dragTarget.style.zIndex = "-5";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixes svelte issue when cloning node containing (or being) <select> which will loose it's value.
|
|
3
|
+
* Since svelte manages select value internally.
|
|
4
|
+
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
5
|
+
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
6
|
+
*
|
|
7
|
+
* @param {HTMLElement} el
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function svelteNodeClone(el) {
|
|
11
|
+
const cloned = el.cloneNode(true);
|
|
12
|
+
|
|
13
|
+
const values = [];
|
|
14
|
+
const elIsSelect = el.tagName === "SELECT";
|
|
15
|
+
const selects = elIsSelect ? [el] : [...el.querySelectorAll('select')];
|
|
16
|
+
for (const select of selects) {
|
|
17
|
+
values.push(select.value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (selects.length <= 0) {
|
|
21
|
+
return cloned;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const clonedSelects = elIsSelect ? [cloned] : [...cloned.querySelectorAll('select')];
|
|
25
|
+
for (let i = 0; i < clonedSelects.length; i++) {
|
|
26
|
+
const select = clonedSelects[i];
|
|
27
|
+
const value = values[i];
|
|
28
|
+
const optionEl = select.querySelector(`option[value="${value}"`);
|
|
29
|
+
if (optionEl) {
|
|
30
|
+
optionEl.setAttribute('selected', true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return cloned;
|
|
35
|
+
}
|
package/src/pointerAction.js
CHANGED
|
@@ -13,7 +13,7 @@ import {armWindowScroller, disarmWindowScroller} from "./helpers/windowScroller"
|
|
|
13
13
|
import {
|
|
14
14
|
createDraggedElementFrom,
|
|
15
15
|
decorateShadowEl,
|
|
16
|
-
|
|
16
|
+
hideElement,
|
|
17
17
|
morphDraggedElementToBeLike,
|
|
18
18
|
moveDraggedElementToWasDroppedState,
|
|
19
19
|
preventShrinking,
|
|
@@ -55,6 +55,7 @@ let isWorkingOnPreviousDrag = false;
|
|
|
55
55
|
let finalizingPreviousDrag = false;
|
|
56
56
|
let unlockOriginDzMinDimensions;
|
|
57
57
|
let isDraggedOutsideOfAnyDz = false;
|
|
58
|
+
let scheduledForRemovalAfterDrop = [];
|
|
58
59
|
|
|
59
60
|
// a map from type to a set of drop-zones
|
|
60
61
|
const typeToDropZones = new Map();
|
|
@@ -280,10 +281,25 @@ function animateDraggedToFinalPosition(shadowElIdx, callback) {
|
|
|
280
281
|
window.setTimeout(callback, dropAnimationDurationMs);
|
|
281
282
|
}
|
|
282
283
|
|
|
284
|
+
function scheduleDZForRemovalAfterDrop(dz, destroy) {
|
|
285
|
+
scheduledForRemovalAfterDrop.push({dz, destroy});
|
|
286
|
+
window.requestAnimationFrame(() => {
|
|
287
|
+
hideElement(dz);
|
|
288
|
+
document.body.appendChild(dz);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
283
291
|
/* cleanup */
|
|
284
292
|
function cleanupPostDrop() {
|
|
285
293
|
draggedEl.remove();
|
|
286
294
|
originalDragTarget.remove();
|
|
295
|
+
if (scheduledForRemovalAfterDrop.length) {
|
|
296
|
+
printDebug(() => ["will destroy zones that were removed during drag", scheduledForRemovalAfterDrop]);
|
|
297
|
+
scheduledForRemovalAfterDrop.forEach(({dz, destroy}) => {
|
|
298
|
+
destroy();
|
|
299
|
+
dz.remove();
|
|
300
|
+
})
|
|
301
|
+
scheduledForRemovalAfterDrop = [];
|
|
302
|
+
}
|
|
287
303
|
draggedEl = undefined;
|
|
288
304
|
originalDragTarget = undefined;
|
|
289
305
|
draggedElData = undefined;
|
|
@@ -398,7 +414,7 @@ export function dndzone(node, options) {
|
|
|
398
414
|
// to prevent the outline from disappearing
|
|
399
415
|
draggedEl.focus();
|
|
400
416
|
watchDraggedElement();
|
|
401
|
-
|
|
417
|
+
hideElement(originalDragTarget);
|
|
402
418
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
403
419
|
} else {
|
|
404
420
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
@@ -529,9 +545,17 @@ export function dndzone(node, options) {
|
|
|
529
545
|
configure(newOptions);
|
|
530
546
|
},
|
|
531
547
|
destroy: () => {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
548
|
+
function destroyDz() {
|
|
549
|
+
printDebug(() => "pointer dndzone will destroy");
|
|
550
|
+
unregisterDropZone(node, dzToConfig.get(node).type);
|
|
551
|
+
dzToConfig.delete(node);
|
|
552
|
+
}
|
|
553
|
+
if (isWorkingOnPreviousDrag) {
|
|
554
|
+
printDebug(() => "pointer dndzone will be scheduled for destruction");
|
|
555
|
+
scheduleDZForRemovalAfterDrop(node, destroyDz);
|
|
556
|
+
} else {
|
|
557
|
+
destroyDz();
|
|
558
|
+
}
|
|
535
559
|
}
|
|
536
560
|
};
|
|
537
561
|
}
|