svelte-dnd-action 0.9.17 → 0.9.20
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 +36 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +109 -82
- package/dist/index.mjs +109 -82
- package/package.json +1 -1
- package/src/helpers/styler.js +1 -1
- package/src/pointerAction.js +29 -5
package/README.md
CHANGED
|
@@ -235,13 +235,15 @@ setDebugMode(true);
|
|
|
235
235
|
If you are using Typescript, you will need to add the following block to your `global.d.ts` (at least until [this svelte issue](https://github.com/sveltejs/language-tools/issues/431) is resolved):
|
|
236
236
|
|
|
237
237
|
```typescript
|
|
238
|
-
declare type
|
|
238
|
+
declare type Item = import('svelte-dnd-action').Item;
|
|
239
|
+
declare type DndEvent<ItemType = Item> = import('svelte-dnd-action').DndEvent<ItemType>;
|
|
239
240
|
declare namespace svelte.JSX {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
interface HTMLAttributes<T> {
|
|
242
|
+
onconsider?: (event: CustomEvent<DndEvent<ItemType>> & { target: EventTarget & T }) => void;
|
|
243
|
+
onfinalize?: (event: CustomEvent<DndEvent<ItemType>> & { target: EventTarget & T }) => void;
|
|
244
|
+
}
|
|
244
245
|
}
|
|
246
|
+
|
|
245
247
|
```
|
|
246
248
|
|
|
247
249
|
You may need to edit `tsconfig.json` to include `global.d.ts` if it doesn't already: "include": ["src/**/*", "global.d.ts"].
|
|
@@ -285,6 +287,35 @@ Then you will be able to use the library with type safety as follows (Typescript
|
|
|
285
287
|
</section>
|
|
286
288
|
```
|
|
287
289
|
|
|
290
|
+
#### Custom types with `DndEvent<T>`
|
|
291
|
+
|
|
292
|
+
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:
|
|
293
|
+
|
|
294
|
+
```html
|
|
295
|
+
<script lang="ts">
|
|
296
|
+
import {dndzone} from "svelte-dnd-action";
|
|
297
|
+
import {flip} from "svelte/animate";
|
|
298
|
+
|
|
299
|
+
interface Dog {
|
|
300
|
+
id: number;
|
|
301
|
+
name: string;
|
|
302
|
+
breed: string;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function handleSort(e: CustomEvent<DndEvent<Dog>>) {
|
|
306
|
+
//e.detail.items now evaluates to type Dog.
|
|
307
|
+
items = e.detail.items;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
let items: Dog[] = [
|
|
311
|
+
{ id: 1, name: 'Fido', breed: 'bulldog' },
|
|
312
|
+
{ id: 2, name: 'Spot', breed: 'labrador' },
|
|
313
|
+
{ id: 3, name: 'Jacky', breed: 'golden retriever' }
|
|
314
|
+
];
|
|
315
|
+
</script>
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
|
|
288
319
|
### Contributing [](https://github.com/isaacHagoel/svelte-dnd-action/issues)
|
|
289
320
|
|
|
290
321
|
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
|
-
_typeof = function (obj) {
|
|
16
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
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);
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
return
|
|
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
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
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();
|
|
@@ -1235,7 +1224,7 @@
|
|
|
1235
1224
|
* @param {HTMLElement} dragTarget
|
|
1236
1225
|
*/
|
|
1237
1226
|
|
|
1238
|
-
function
|
|
1227
|
+
function hideElement(dragTarget) {
|
|
1239
1228
|
dragTarget.style.display = "none";
|
|
1240
1229
|
dragTarget.style.position = "fixed";
|
|
1241
1230
|
dragTarget.style.zIndex = "-5";
|
|
@@ -1338,7 +1327,8 @@
|
|
|
1338
1327
|
var isWorkingOnPreviousDrag = false;
|
|
1339
1328
|
var finalizingPreviousDrag = false;
|
|
1340
1329
|
var unlockOriginDzMinDimensions;
|
|
1341
|
-
var isDraggedOutsideOfAnyDz = false;
|
|
1330
|
+
var isDraggedOutsideOfAnyDz = false;
|
|
1331
|
+
var scheduledForRemovalAfterDrop = []; // a map from type to a set of drop-zones
|
|
1342
1332
|
|
|
1343
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
|
|
1344
1334
|
|
|
@@ -1674,12 +1664,37 @@
|
|
|
1674
1664
|
draggedEl.style.transform = "translate3d(".concat(newTransform.x, "px, ").concat(newTransform.y, "px, 0)");
|
|
1675
1665
|
window.setTimeout(callback, dropAnimationDurationMs);
|
|
1676
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
|
+
}
|
|
1677
1678
|
/* cleanup */
|
|
1678
1679
|
|
|
1679
1680
|
|
|
1680
1681
|
function cleanupPostDrop() {
|
|
1681
1682
|
draggedEl.remove();
|
|
1682
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
|
+
|
|
1683
1698
|
draggedEl = undefined;
|
|
1684
1699
|
originalDragTarget = undefined;
|
|
1685
1700
|
draggedElData = undefined;
|
|
@@ -1827,7 +1842,7 @@
|
|
|
1827
1842
|
|
|
1828
1843
|
draggedEl.focus();
|
|
1829
1844
|
watchDraggedElement();
|
|
1830
|
-
|
|
1845
|
+
hideElement(originalDragTarget);
|
|
1831
1846
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
1832
1847
|
} else {
|
|
1833
1848
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
@@ -1866,27 +1881,27 @@
|
|
|
1866
1881
|
});
|
|
1867
1882
|
}
|
|
1868
1883
|
|
|
1869
|
-
function configure(
|
|
1870
|
-
var
|
|
1871
|
-
items =
|
|
1872
|
-
|
|
1873
|
-
dropAnimationDurationMs =
|
|
1874
|
-
|
|
1875
|
-
newType =
|
|
1876
|
-
|
|
1877
|
-
dragDisabled =
|
|
1878
|
-
|
|
1879
|
-
morphDisabled =
|
|
1880
|
-
|
|
1881
|
-
dropFromOthersDisabled =
|
|
1882
|
-
|
|
1883
|
-
dropTargetStyle =
|
|
1884
|
-
|
|
1885
|
-
dropTargetClasses =
|
|
1886
|
-
|
|
1887
|
-
transformDraggedElement =
|
|
1888
|
-
|
|
1889
|
-
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;
|
|
1890
1905
|
config.dropAnimationDurationMs = dropAnimationDurationMs;
|
|
1891
1906
|
|
|
1892
1907
|
if (config.type && newType !== config.type) {
|
|
@@ -1989,11 +2004,22 @@
|
|
|
1989
2004
|
configure(newOptions);
|
|
1990
2005
|
},
|
|
1991
2006
|
destroy: function destroy() {
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
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
|
+
}
|
|
1997
2023
|
}
|
|
1998
2024
|
};
|
|
1999
2025
|
}
|
|
@@ -2575,6 +2601,7 @@
|
|
|
2575
2601
|
return handles;
|
|
2576
2602
|
}
|
|
2577
2603
|
|
|
2604
|
+
var _excluded = ["items", "flipDurationMs", "type", "dragDisabled", "morphDisabled", "dropFromOthersDisabled", "zoneTabIndex", "dropTargetStyle", "dropTargetClasses", "transformDraggedElement", "autoAriaDisabled", "centreDraggedOnCursor"];
|
|
2578
2605
|
/**
|
|
2579
2606
|
* A custom action to turn any container to a dnd zone and all of its direct children to draggables
|
|
2580
2607
|
* Supports mouse, touch and keyboard interactions.
|
|
@@ -2628,7 +2655,7 @@
|
|
|
2628
2655
|
transformDraggedElement = options.transformDraggedElement,
|
|
2629
2656
|
autoAriaDisabled = options.autoAriaDisabled,
|
|
2630
2657
|
centreDraggedOnCursor = options.centreDraggedOnCursor,
|
|
2631
|
-
rest = _objectWithoutProperties(options,
|
|
2658
|
+
rest = _objectWithoutProperties(options, _excluded);
|
|
2632
2659
|
/*eslint-enable*/
|
|
2633
2660
|
|
|
2634
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
|
-
_typeof = function (obj) {
|
|
10
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
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);
|
|
12
9
|
}
|
|
13
10
|
|
|
14
|
-
return
|
|
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
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
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();
|
|
@@ -1229,7 +1218,7 @@ function styleDraggable(draggableEl, dragDisabled) {
|
|
|
1229
1218
|
* @param {HTMLElement} dragTarget
|
|
1230
1219
|
*/
|
|
1231
1220
|
|
|
1232
|
-
function
|
|
1221
|
+
function hideElement(dragTarget) {
|
|
1233
1222
|
dragTarget.style.display = "none";
|
|
1234
1223
|
dragTarget.style.position = "fixed";
|
|
1235
1224
|
dragTarget.style.zIndex = "-5";
|
|
@@ -1332,7 +1321,8 @@ var currentMousePosition;
|
|
|
1332
1321
|
var isWorkingOnPreviousDrag = false;
|
|
1333
1322
|
var finalizingPreviousDrag = false;
|
|
1334
1323
|
var unlockOriginDzMinDimensions;
|
|
1335
|
-
var isDraggedOutsideOfAnyDz = false;
|
|
1324
|
+
var isDraggedOutsideOfAnyDz = false;
|
|
1325
|
+
var scheduledForRemovalAfterDrop = []; // a map from type to a set of drop-zones
|
|
1336
1326
|
|
|
1337
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
|
|
1338
1328
|
|
|
@@ -1668,12 +1658,37 @@ function animateDraggedToFinalPosition(shadowElIdx, callback) {
|
|
|
1668
1658
|
draggedEl.style.transform = "translate3d(".concat(newTransform.x, "px, ").concat(newTransform.y, "px, 0)");
|
|
1669
1659
|
window.setTimeout(callback, dropAnimationDurationMs);
|
|
1670
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
|
+
}
|
|
1671
1672
|
/* cleanup */
|
|
1672
1673
|
|
|
1673
1674
|
|
|
1674
1675
|
function cleanupPostDrop() {
|
|
1675
1676
|
draggedEl.remove();
|
|
1676
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
|
+
|
|
1677
1692
|
draggedEl = undefined;
|
|
1678
1693
|
originalDragTarget = undefined;
|
|
1679
1694
|
draggedElData = undefined;
|
|
@@ -1821,7 +1836,7 @@ function dndzone(node, options) {
|
|
|
1821
1836
|
|
|
1822
1837
|
draggedEl.focus();
|
|
1823
1838
|
watchDraggedElement();
|
|
1824
|
-
|
|
1839
|
+
hideElement(originalDragTarget);
|
|
1825
1840
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
1826
1841
|
} else {
|
|
1827
1842
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
@@ -1860,27 +1875,27 @@ function dndzone(node, options) {
|
|
|
1860
1875
|
});
|
|
1861
1876
|
}
|
|
1862
1877
|
|
|
1863
|
-
function configure(
|
|
1864
|
-
var
|
|
1865
|
-
items =
|
|
1866
|
-
|
|
1867
|
-
dropAnimationDurationMs =
|
|
1868
|
-
|
|
1869
|
-
newType =
|
|
1870
|
-
|
|
1871
|
-
dragDisabled =
|
|
1872
|
-
|
|
1873
|
-
morphDisabled =
|
|
1874
|
-
|
|
1875
|
-
dropFromOthersDisabled =
|
|
1876
|
-
|
|
1877
|
-
dropTargetStyle =
|
|
1878
|
-
|
|
1879
|
-
dropTargetClasses =
|
|
1880
|
-
|
|
1881
|
-
transformDraggedElement =
|
|
1882
|
-
|
|
1883
|
-
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;
|
|
1884
1899
|
config.dropAnimationDurationMs = dropAnimationDurationMs;
|
|
1885
1900
|
|
|
1886
1901
|
if (config.type && newType !== config.type) {
|
|
@@ -1983,11 +1998,22 @@ function dndzone(node, options) {
|
|
|
1983
1998
|
configure(newOptions);
|
|
1984
1999
|
},
|
|
1985
2000
|
destroy: function destroy() {
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
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
|
+
}
|
|
1991
2017
|
}
|
|
1992
2018
|
};
|
|
1993
2019
|
}
|
|
@@ -2569,6 +2595,7 @@ function dndzone$1(node, options) {
|
|
|
2569
2595
|
return handles;
|
|
2570
2596
|
}
|
|
2571
2597
|
|
|
2598
|
+
var _excluded = ["items", "flipDurationMs", "type", "dragDisabled", "morphDisabled", "dropFromOthersDisabled", "zoneTabIndex", "dropTargetStyle", "dropTargetClasses", "transformDraggedElement", "autoAriaDisabled", "centreDraggedOnCursor"];
|
|
2572
2599
|
/**
|
|
2573
2600
|
* A custom action to turn any container to a dnd zone and all of its direct children to draggables
|
|
2574
2601
|
* Supports mouse, touch and keyboard interactions.
|
|
@@ -2622,7 +2649,7 @@ function validateOptions(options) {
|
|
|
2622
2649
|
transformDraggedElement = options.transformDraggedElement,
|
|
2623
2650
|
autoAriaDisabled = options.autoAriaDisabled,
|
|
2624
2651
|
centreDraggedOnCursor = options.centreDraggedOnCursor,
|
|
2625
|
-
rest = _objectWithoutProperties(options,
|
|
2652
|
+
rest = _objectWithoutProperties(options, _excluded);
|
|
2626
2653
|
/*eslint-enable*/
|
|
2627
2654
|
|
|
2628
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.20",
|
|
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
|
@@ -136,7 +136,7 @@ export function styleDraggable(draggableEl, dragDisabled) {
|
|
|
136
136
|
* Hides the provided element so that it can stay in the dom without interrupting
|
|
137
137
|
* @param {HTMLElement} dragTarget
|
|
138
138
|
*/
|
|
139
|
-
export function
|
|
139
|
+
export function hideElement(dragTarget) {
|
|
140
140
|
dragTarget.style.display = "none";
|
|
141
141
|
dragTarget.style.position = "fixed";
|
|
142
142
|
dragTarget.style.zIndex = "-5";
|
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
|
}
|