svelte-dnd-action 0.9.28 → 0.9.29
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 +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -24
- package/dist/index.mjs +26 -24
- package/package.json +2 -2
- package/src/action.js +17 -1
- package/src/constants.js +2 -1
- package/src/pointerAction.js +8 -19
package/README.md
CHANGED
|
@@ -347,6 +347,32 @@ You can use generics to set the type of `items` you are expecting in `DndEvent`.
|
|
|
347
347
|
</script>
|
|
348
348
|
```
|
|
349
349
|
|
|
350
|
+
### Nested Zones Optional Optimization (experimental)
|
|
351
|
+
|
|
352
|
+
This is an experimental feature added in version 0.9.29. If you have multiple levels of nesting, the lib might do unnecessary work when dragging an element that has nested zones inside.
|
|
353
|
+
Specifically, it allows nested zones within the shadow element (the placeholder under the dragged element) to register and destroy.
|
|
354
|
+
This is because Svelte calls nested actions before the parent action (opposite to the rendering order).
|
|
355
|
+
You can use a data attribute **on the items** to help the lib prevent this: `data-is-dnd-shadow-item-hint={item[SHADOW_ITEM_MARKER_PROPERTY_NAME]} `
|
|
356
|
+
|
|
357
|
+
#### Simplified Example (just shows where to place the attribute):
|
|
358
|
+
|
|
359
|
+
```html
|
|
360
|
+
<script>
|
|
361
|
+
import {dndzone, SHADOW_ITEM_MARKER_PROPERTY_NAME} from 'svelte-dnd-action';
|
|
362
|
+
let items = [];
|
|
363
|
+
</script>
|
|
364
|
+
<section>
|
|
365
|
+
<div use:dndzone={{items}} on:consider={e => items = e.detail.items} on:finalize={e => items = e.detail.items}>
|
|
366
|
+
{#each items as item (item.id)}
|
|
367
|
+
<div data-is-dnd-shadow-item-hint={item[SHADOW_ITEM_MARKER_PROPERTY_NAME]}>
|
|
368
|
+
<h1>{item.title}</h1>
|
|
369
|
+
<!--more nested zones go here, can include the attribute on their items as demonstrated above-->
|
|
370
|
+
</div>
|
|
371
|
+
{/each}
|
|
372
|
+
</div>
|
|
373
|
+
</section>
|
|
374
|
+
```
|
|
375
|
+
|
|
350
376
|
### Contributing [](https://github.com/isaacHagoel/svelte-dnd-action/issues)
|
|
351
377
|
|
|
352
378
|
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
|
@@ -78,6 +78,7 @@ export type DndEvent<T = Item> = {
|
|
|
78
78
|
export declare const SHADOW_ITEM_MARKER_PROPERTY_NAME: "isDndShadowItem";
|
|
79
79
|
export declare const SHADOW_PLACEHOLDER_ITEM_ID: "id:dnd-shadow-placeholder-0000";
|
|
80
80
|
export declare const DRAGGED_ELEMENT_ID: "dnd-action-dragged-el";
|
|
81
|
+
export declare const SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-hint";
|
|
81
82
|
|
|
82
83
|
/**
|
|
83
84
|
* Allows the user to show/hide console debug output
|
package/dist/index.js
CHANGED
|
@@ -294,7 +294,8 @@
|
|
|
294
294
|
KEYBOARD: "keyboard"
|
|
295
295
|
};
|
|
296
296
|
var SHADOW_ITEM_MARKER_PROPERTY_NAME = "isDndShadowItem";
|
|
297
|
-
var SHADOW_ELEMENT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item";
|
|
297
|
+
var SHADOW_ELEMENT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-internal";
|
|
298
|
+
var SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-hint";
|
|
298
299
|
var SHADOW_PLACEHOLDER_ITEM_ID = "id:dnd-shadow-placeholder-0000";
|
|
299
300
|
var DRAGGED_ELEMENT_ID = "dnd-action-dragged-el";
|
|
300
301
|
var ITEM_ID_KEY = "id";
|
|
@@ -1229,6 +1230,7 @@
|
|
|
1229
1230
|
var DEFAULT_DROP_TARGET_STYLE = {
|
|
1230
1231
|
outline: "rgba(255, 255, 102, 0.7) solid 2px"
|
|
1231
1232
|
};
|
|
1233
|
+
var ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE = "data-is-dnd-original-dragged-item";
|
|
1232
1234
|
var originalDragTarget;
|
|
1233
1235
|
var draggedEl;
|
|
1234
1236
|
var draggedElData;
|
|
@@ -1324,17 +1326,9 @@
|
|
|
1324
1326
|
window.removeEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop);
|
|
1325
1327
|
unobserve();
|
|
1326
1328
|
}
|
|
1327
|
-
|
|
1328
|
-
// finds the initial placeholder that is placed there on drag start
|
|
1329
|
-
function findShadowPlaceHolderIdx(items) {
|
|
1330
|
-
return items.findIndex(function (item) {
|
|
1331
|
-
return item[ITEM_ID_KEY] === SHADOW_PLACEHOLDER_ITEM_ID;
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
1329
|
function findShadowElementIdx(items) {
|
|
1335
|
-
// checking that the id is not the placeholder's for Dragula like usecases
|
|
1336
1330
|
return items.findIndex(function (item) {
|
|
1337
|
-
return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME]
|
|
1331
|
+
return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME];
|
|
1338
1332
|
});
|
|
1339
1333
|
}
|
|
1340
1334
|
|
|
@@ -1370,15 +1364,6 @@
|
|
|
1370
1364
|
id: draggedElData[ITEM_ID_KEY],
|
|
1371
1365
|
source: SOURCES.POINTER
|
|
1372
1366
|
});
|
|
1373
|
-
} else {
|
|
1374
|
-
var shadowPlaceHolderIdx = findShadowPlaceHolderIdx(items);
|
|
1375
|
-
if (shadowPlaceHolderIdx !== -1) {
|
|
1376
|
-
// only happens right after drag start, on the first drag entered event
|
|
1377
|
-
printDebug(function () {
|
|
1378
|
-
return "removing placeholder item from origin dz";
|
|
1379
|
-
});
|
|
1380
|
-
items.splice(shadowPlaceHolderIdx, 1);
|
|
1381
|
-
}
|
|
1382
1367
|
}
|
|
1383
1368
|
var _e$detail$indexObj = e.detail.indexObj,
|
|
1384
1369
|
index = _e$detail$indexObj.index,
|
|
@@ -1671,6 +1656,7 @@
|
|
|
1671
1656
|
addMaybeListeners();
|
|
1672
1657
|
}
|
|
1673
1658
|
function handleDragStart() {
|
|
1659
|
+
var _objectSpread2$1;
|
|
1674
1660
|
printDebug(function () {
|
|
1675
1661
|
return ["drag start config: ".concat(toString(config)), originalDragTarget];
|
|
1676
1662
|
});
|
|
@@ -1688,12 +1674,12 @@
|
|
|
1688
1674
|
centreDraggedOnCursor = config.centreDraggedOnCursor;
|
|
1689
1675
|
draggedElData = _objectSpread2({}, items[currentIdx]);
|
|
1690
1676
|
draggedElType = type;
|
|
1691
|
-
shadowElData = _objectSpread2(_objectSpread2({}, draggedElData), {},
|
|
1692
|
-
// The initial shadow element. We need a different id at first in order to avoid conflicts and timing issues
|
|
1693
|
-
var placeHolderElData = _objectSpread2(_objectSpread2({}, shadowElData), {}, _defineProperty({}, ITEM_ID_KEY, SHADOW_PLACEHOLDER_ITEM_ID));
|
|
1677
|
+
shadowElData = _objectSpread2(_objectSpread2({}, draggedElData), {}, (_objectSpread2$1 = {}, _defineProperty(_objectSpread2$1, SHADOW_ITEM_MARKER_PROPERTY_NAME, true), _defineProperty(_objectSpread2$1, ITEM_ID_KEY, SHADOW_PLACEHOLDER_ITEM_ID), _objectSpread2$1));
|
|
1694
1678
|
|
|
1695
1679
|
// creating the draggable element
|
|
1696
1680
|
draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);
|
|
1681
|
+
originalDragTarget.setAttribute(ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE, true);
|
|
1682
|
+
|
|
1697
1683
|
// We will keep the original dom node in the dom because touch events keep firing on it, we want to re-add it after the framework removes it
|
|
1698
1684
|
function keepOriginalElementInDom() {
|
|
1699
1685
|
if (!draggedEl.parentElement) {
|
|
@@ -1717,7 +1703,7 @@
|
|
|
1717
1703
|
});
|
|
1718
1704
|
|
|
1719
1705
|
// removing the original element by removing its data entry
|
|
1720
|
-
items.splice(currentIdx, 1,
|
|
1706
|
+
items.splice(currentIdx, 1, shadowElData);
|
|
1721
1707
|
unlockOriginDzMinDimensions = preventShrinking(originDropZone);
|
|
1722
1708
|
dispatchConsiderEvent(originDropZone, items, {
|
|
1723
1709
|
trigger: TRIGGERS.DRAG_STARTED,
|
|
@@ -1852,7 +1838,7 @@
|
|
|
1852
1838
|
unregisterDropZone(node, dzToConfig.get(node).type);
|
|
1853
1839
|
dzToConfig["delete"](node);
|
|
1854
1840
|
}
|
|
1855
|
-
if (isWorkingOnPreviousDrag) {
|
|
1841
|
+
if (isWorkingOnPreviousDrag && !node.closest("[".concat(ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE, "]"))) {
|
|
1856
1842
|
printDebug(function () {
|
|
1857
1843
|
return "pointer dndzone will be scheduled for destruction";
|
|
1858
1844
|
});
|
|
@@ -2382,6 +2368,12 @@
|
|
|
2382
2368
|
* @return {{update: function, destroy: function}}
|
|
2383
2369
|
*/
|
|
2384
2370
|
function dndzone$2(node, options) {
|
|
2371
|
+
if (shouldIgnoreZone(node)) {
|
|
2372
|
+
return {
|
|
2373
|
+
update: function update() {},
|
|
2374
|
+
destroy: function destroy() {}
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2385
2377
|
validateOptions(options);
|
|
2386
2378
|
var pointerZone = dndzone(node, options);
|
|
2387
2379
|
var keyboardZone = dndzone$1(node, options);
|
|
@@ -2397,6 +2389,16 @@
|
|
|
2397
2389
|
}
|
|
2398
2390
|
};
|
|
2399
2391
|
}
|
|
2392
|
+
|
|
2393
|
+
/**
|
|
2394
|
+
* If the user marked something in the ancestry of our node as shadow element, we can ignore it
|
|
2395
|
+
* We need the user to mark it for us because svelte updates the action from deep to shallow (but renders top down)
|
|
2396
|
+
* @param {HTMLElement} node
|
|
2397
|
+
* @return {boolean}
|
|
2398
|
+
*/
|
|
2399
|
+
function shouldIgnoreZone(node) {
|
|
2400
|
+
return !!node.closest("[".concat(SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME, "=\"true\"]"));
|
|
2401
|
+
}
|
|
2400
2402
|
function validateOptions(options) {
|
|
2401
2403
|
/*eslint-disable*/
|
|
2402
2404
|
var items = options.items,
|
package/dist/index.mjs
CHANGED
|
@@ -288,7 +288,8 @@ var SOURCES = {
|
|
|
288
288
|
KEYBOARD: "keyboard"
|
|
289
289
|
};
|
|
290
290
|
var SHADOW_ITEM_MARKER_PROPERTY_NAME = "isDndShadowItem";
|
|
291
|
-
var SHADOW_ELEMENT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item";
|
|
291
|
+
var SHADOW_ELEMENT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-internal";
|
|
292
|
+
var SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-hint";
|
|
292
293
|
var SHADOW_PLACEHOLDER_ITEM_ID = "id:dnd-shadow-placeholder-0000";
|
|
293
294
|
var DRAGGED_ELEMENT_ID = "dnd-action-dragged-el";
|
|
294
295
|
var ITEM_ID_KEY = "id";
|
|
@@ -1223,6 +1224,7 @@ var MIN_MOVEMENT_BEFORE_DRAG_START_PX = 3;
|
|
|
1223
1224
|
var DEFAULT_DROP_TARGET_STYLE = {
|
|
1224
1225
|
outline: "rgba(255, 255, 102, 0.7) solid 2px"
|
|
1225
1226
|
};
|
|
1227
|
+
var ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE = "data-is-dnd-original-dragged-item";
|
|
1226
1228
|
var originalDragTarget;
|
|
1227
1229
|
var draggedEl;
|
|
1228
1230
|
var draggedElData;
|
|
@@ -1318,17 +1320,9 @@ function unWatchDraggedElement() {
|
|
|
1318
1320
|
window.removeEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop);
|
|
1319
1321
|
unobserve();
|
|
1320
1322
|
}
|
|
1321
|
-
|
|
1322
|
-
// finds the initial placeholder that is placed there on drag start
|
|
1323
|
-
function findShadowPlaceHolderIdx(items) {
|
|
1324
|
-
return items.findIndex(function (item) {
|
|
1325
|
-
return item[ITEM_ID_KEY] === SHADOW_PLACEHOLDER_ITEM_ID;
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
1323
|
function findShadowElementIdx(items) {
|
|
1329
|
-
// checking that the id is not the placeholder's for Dragula like usecases
|
|
1330
1324
|
return items.findIndex(function (item) {
|
|
1331
|
-
return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME]
|
|
1325
|
+
return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME];
|
|
1332
1326
|
});
|
|
1333
1327
|
}
|
|
1334
1328
|
|
|
@@ -1364,15 +1358,6 @@ function handleDraggedEntered(e) {
|
|
|
1364
1358
|
id: draggedElData[ITEM_ID_KEY],
|
|
1365
1359
|
source: SOURCES.POINTER
|
|
1366
1360
|
});
|
|
1367
|
-
} else {
|
|
1368
|
-
var shadowPlaceHolderIdx = findShadowPlaceHolderIdx(items);
|
|
1369
|
-
if (shadowPlaceHolderIdx !== -1) {
|
|
1370
|
-
// only happens right after drag start, on the first drag entered event
|
|
1371
|
-
printDebug(function () {
|
|
1372
|
-
return "removing placeholder item from origin dz";
|
|
1373
|
-
});
|
|
1374
|
-
items.splice(shadowPlaceHolderIdx, 1);
|
|
1375
|
-
}
|
|
1376
1361
|
}
|
|
1377
1362
|
var _e$detail$indexObj = e.detail.indexObj,
|
|
1378
1363
|
index = _e$detail$indexObj.index,
|
|
@@ -1665,6 +1650,7 @@ function dndzone(node, options) {
|
|
|
1665
1650
|
addMaybeListeners();
|
|
1666
1651
|
}
|
|
1667
1652
|
function handleDragStart() {
|
|
1653
|
+
var _objectSpread2$1;
|
|
1668
1654
|
printDebug(function () {
|
|
1669
1655
|
return ["drag start config: ".concat(toString(config)), originalDragTarget];
|
|
1670
1656
|
});
|
|
@@ -1682,12 +1668,12 @@ function dndzone(node, options) {
|
|
|
1682
1668
|
centreDraggedOnCursor = config.centreDraggedOnCursor;
|
|
1683
1669
|
draggedElData = _objectSpread2({}, items[currentIdx]);
|
|
1684
1670
|
draggedElType = type;
|
|
1685
|
-
shadowElData = _objectSpread2(_objectSpread2({}, draggedElData), {},
|
|
1686
|
-
// The initial shadow element. We need a different id at first in order to avoid conflicts and timing issues
|
|
1687
|
-
var placeHolderElData = _objectSpread2(_objectSpread2({}, shadowElData), {}, _defineProperty({}, ITEM_ID_KEY, SHADOW_PLACEHOLDER_ITEM_ID));
|
|
1671
|
+
shadowElData = _objectSpread2(_objectSpread2({}, draggedElData), {}, (_objectSpread2$1 = {}, _defineProperty(_objectSpread2$1, SHADOW_ITEM_MARKER_PROPERTY_NAME, true), _defineProperty(_objectSpread2$1, ITEM_ID_KEY, SHADOW_PLACEHOLDER_ITEM_ID), _objectSpread2$1));
|
|
1688
1672
|
|
|
1689
1673
|
// creating the draggable element
|
|
1690
1674
|
draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);
|
|
1675
|
+
originalDragTarget.setAttribute(ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE, true);
|
|
1676
|
+
|
|
1691
1677
|
// We will keep the original dom node in the dom because touch events keep firing on it, we want to re-add it after the framework removes it
|
|
1692
1678
|
function keepOriginalElementInDom() {
|
|
1693
1679
|
if (!draggedEl.parentElement) {
|
|
@@ -1711,7 +1697,7 @@ function dndzone(node, options) {
|
|
|
1711
1697
|
});
|
|
1712
1698
|
|
|
1713
1699
|
// removing the original element by removing its data entry
|
|
1714
|
-
items.splice(currentIdx, 1,
|
|
1700
|
+
items.splice(currentIdx, 1, shadowElData);
|
|
1715
1701
|
unlockOriginDzMinDimensions = preventShrinking(originDropZone);
|
|
1716
1702
|
dispatchConsiderEvent(originDropZone, items, {
|
|
1717
1703
|
trigger: TRIGGERS.DRAG_STARTED,
|
|
@@ -1846,7 +1832,7 @@ function dndzone(node, options) {
|
|
|
1846
1832
|
unregisterDropZone(node, dzToConfig.get(node).type);
|
|
1847
1833
|
dzToConfig["delete"](node);
|
|
1848
1834
|
}
|
|
1849
|
-
if (isWorkingOnPreviousDrag) {
|
|
1835
|
+
if (isWorkingOnPreviousDrag && !node.closest("[".concat(ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE, "]"))) {
|
|
1850
1836
|
printDebug(function () {
|
|
1851
1837
|
return "pointer dndzone will be scheduled for destruction";
|
|
1852
1838
|
});
|
|
@@ -2376,6 +2362,12 @@ var _excluded = ["items", "flipDurationMs", "type", "dragDisabled", "morphDisabl
|
|
|
2376
2362
|
* @return {{update: function, destroy: function}}
|
|
2377
2363
|
*/
|
|
2378
2364
|
function dndzone$2(node, options) {
|
|
2365
|
+
if (shouldIgnoreZone(node)) {
|
|
2366
|
+
return {
|
|
2367
|
+
update: function update() {},
|
|
2368
|
+
destroy: function destroy() {}
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2379
2371
|
validateOptions(options);
|
|
2380
2372
|
var pointerZone = dndzone(node, options);
|
|
2381
2373
|
var keyboardZone = dndzone$1(node, options);
|
|
@@ -2391,6 +2383,16 @@ function dndzone$2(node, options) {
|
|
|
2391
2383
|
}
|
|
2392
2384
|
};
|
|
2393
2385
|
}
|
|
2386
|
+
|
|
2387
|
+
/**
|
|
2388
|
+
* If the user marked something in the ancestry of our node as shadow element, we can ignore it
|
|
2389
|
+
* We need the user to mark it for us because svelte updates the action from deep to shallow (but renders top down)
|
|
2390
|
+
* @param {HTMLElement} node
|
|
2391
|
+
* @return {boolean}
|
|
2392
|
+
*/
|
|
2393
|
+
function shouldIgnoreZone(node) {
|
|
2394
|
+
return !!node.closest("[".concat(SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME, "=\"true\"]"));
|
|
2395
|
+
}
|
|
2394
2396
|
function validateOptions(options) {
|
|
2395
2397
|
/*eslint-disable*/
|
|
2396
2398
|
var items = options.items,
|
package/package.json
CHANGED
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"src",
|
|
43
43
|
"dist"
|
|
44
44
|
],
|
|
45
|
-
"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 *",
|
|
46
|
-
"version": "0.9.
|
|
45
|
+
"description": "*An awesome drag and drop library for Svelte 3 and 4 (not using the browser's built-in dnd, thanks god): Rich animations, nested containers, touch support and more *",
|
|
46
|
+
"version": "0.9.29",
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|
|
49
49
|
"url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
|
package/src/action.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {dndzone as pointerDndZone} from "./pointerAction";
|
|
2
2
|
import {dndzone as keyboardDndZone} from "./keyboardAction";
|
|
3
|
-
import {ITEM_ID_KEY} from "./constants";
|
|
3
|
+
import {ITEM_ID_KEY, SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME} from "./constants";
|
|
4
4
|
import {toString} from "./helpers/util";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -25,6 +25,12 @@ import {toString} from "./helpers/util";
|
|
|
25
25
|
* @return {{update: function, destroy: function}}
|
|
26
26
|
*/
|
|
27
27
|
export function dndzone(node, options) {
|
|
28
|
+
if (shouldIgnoreZone(node)) {
|
|
29
|
+
return {
|
|
30
|
+
update: () => {},
|
|
31
|
+
destroy: () => {}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
28
34
|
validateOptions(options);
|
|
29
35
|
const pointerZone = pointerDndZone(node, options);
|
|
30
36
|
const keyboardZone = keyboardDndZone(node, options);
|
|
@@ -41,6 +47,16 @@ export function dndzone(node, options) {
|
|
|
41
47
|
};
|
|
42
48
|
}
|
|
43
49
|
|
|
50
|
+
/**
|
|
51
|
+
* If the user marked something in the ancestry of our node as shadow element, we can ignore it
|
|
52
|
+
* We need the user to mark it for us because svelte updates the action from deep to shallow (but renders top down)
|
|
53
|
+
* @param {HTMLElement} node
|
|
54
|
+
* @return {boolean}
|
|
55
|
+
*/
|
|
56
|
+
function shouldIgnoreZone(node) {
|
|
57
|
+
return !!node.closest(`[${SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME}="true"]`);
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
function validateOptions(options) {
|
|
45
61
|
/*eslint-disable*/
|
|
46
62
|
const {
|
package/src/constants.js
CHANGED
|
@@ -19,7 +19,8 @@ export const SOURCES = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const SHADOW_ITEM_MARKER_PROPERTY_NAME = "isDndShadowItem";
|
|
22
|
-
export const SHADOW_ELEMENT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item";
|
|
22
|
+
export const SHADOW_ELEMENT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-internal";
|
|
23
|
+
export const SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-hint";
|
|
23
24
|
export const SHADOW_PLACEHOLDER_ITEM_ID = "id:dnd-shadow-placeholder-0000";
|
|
24
25
|
export const DRAGGED_ELEMENT_ID = "dnd-action-dragged-el";
|
|
25
26
|
|
package/src/pointerAction.js
CHANGED
|
@@ -40,6 +40,7 @@ const MIN_MOVEMENT_BEFORE_DRAG_START_PX = 3;
|
|
|
40
40
|
const DEFAULT_DROP_TARGET_STYLE = {
|
|
41
41
|
outline: "rgba(255, 255, 102, 0.7) solid 2px"
|
|
42
42
|
};
|
|
43
|
+
const ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE = "data-is-dnd-original-dragged-item";
|
|
43
44
|
|
|
44
45
|
let originalDragTarget;
|
|
45
46
|
let draggedEl;
|
|
@@ -114,13 +115,8 @@ function unWatchDraggedElement() {
|
|
|
114
115
|
unobserve();
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
// finds the initial placeholder that is placed there on drag start
|
|
118
|
-
function findShadowPlaceHolderIdx(items) {
|
|
119
|
-
return items.findIndex(item => item[ITEM_ID_KEY] === SHADOW_PLACEHOLDER_ITEM_ID);
|
|
120
|
-
}
|
|
121
118
|
function findShadowElementIdx(items) {
|
|
122
|
-
|
|
123
|
-
return items.findIndex(item => !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME] && item[ITEM_ID_KEY] !== SHADOW_PLACEHOLDER_ITEM_ID);
|
|
119
|
+
return items.findIndex(item => !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME]);
|
|
124
120
|
}
|
|
125
121
|
|
|
126
122
|
/* custom drag-events handlers */
|
|
@@ -144,15 +140,7 @@ function handleDraggedEntered(e) {
|
|
|
144
140
|
id: draggedElData[ITEM_ID_KEY],
|
|
145
141
|
source: SOURCES.POINTER
|
|
146
142
|
});
|
|
147
|
-
} else {
|
|
148
|
-
const shadowPlaceHolderIdx = findShadowPlaceHolderIdx(items);
|
|
149
|
-
if (shadowPlaceHolderIdx !== -1) {
|
|
150
|
-
// only happens right after drag start, on the first drag entered event
|
|
151
|
-
printDebug(() => "removing placeholder item from origin dz");
|
|
152
|
-
items.splice(shadowPlaceHolderIdx, 1);
|
|
153
|
-
}
|
|
154
143
|
}
|
|
155
|
-
|
|
156
144
|
const {index, isProximityBased} = e.detail.indexObj;
|
|
157
145
|
const shadowElIdx = isProximityBased && index === e.currentTarget.children.length - 1 ? index + 1 : index;
|
|
158
146
|
shadowElDropZone = e.currentTarget;
|
|
@@ -245,6 +233,7 @@ function handleDrop() {
|
|
|
245
233
|
let shadowElIdx = findShadowElementIdx(items);
|
|
246
234
|
// the handler might remove the shadow element, ex: dragula like copy on drag
|
|
247
235
|
if (shadowElIdx === -1) shadowElIdx = originIndex;
|
|
236
|
+
|
|
248
237
|
items = items.map(item => (item[SHADOW_ITEM_MARKER_PROPERTY_NAME] ? draggedElData : item));
|
|
249
238
|
function finalizeWithinZone() {
|
|
250
239
|
unlockOriginDzMinDimensions();
|
|
@@ -401,12 +390,12 @@ export function dndzone(node, options) {
|
|
|
401
390
|
const {items, type, centreDraggedOnCursor} = config;
|
|
402
391
|
draggedElData = {...items[currentIdx]};
|
|
403
392
|
draggedElType = type;
|
|
404
|
-
shadowElData = {...draggedElData, [SHADOW_ITEM_MARKER_PROPERTY_NAME]: true};
|
|
405
|
-
// The initial shadow element. We need a different id at first in order to avoid conflicts and timing issues
|
|
406
|
-
const placeHolderElData = {...shadowElData, [ITEM_ID_KEY]: SHADOW_PLACEHOLDER_ITEM_ID};
|
|
393
|
+
shadowElData = {...draggedElData, [SHADOW_ITEM_MARKER_PROPERTY_NAME]: true, [ITEM_ID_KEY]: SHADOW_PLACEHOLDER_ITEM_ID};
|
|
407
394
|
|
|
408
395
|
// creating the draggable element
|
|
409
396
|
draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);
|
|
397
|
+
originalDragTarget.setAttribute(ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE, true);
|
|
398
|
+
|
|
410
399
|
// We will keep the original dom node in the dom because touch events keep firing on it, we want to re-add it after the framework removes it
|
|
411
400
|
function keepOriginalElementInDom() {
|
|
412
401
|
if (!draggedEl.parentElement) {
|
|
@@ -429,7 +418,7 @@ export function dndzone(node, options) {
|
|
|
429
418
|
);
|
|
430
419
|
|
|
431
420
|
// removing the original element by removing its data entry
|
|
432
|
-
items.splice(currentIdx, 1,
|
|
421
|
+
items.splice(currentIdx, 1, shadowElData);
|
|
433
422
|
unlockOriginDzMinDimensions = preventShrinking(originDropZone);
|
|
434
423
|
|
|
435
424
|
dispatchConsiderEvent(originDropZone, items, {trigger: TRIGGERS.DRAG_STARTED, id: draggedElData[ITEM_ID_KEY], source: SOURCES.POINTER});
|
|
@@ -549,7 +538,7 @@ export function dndzone(node, options) {
|
|
|
549
538
|
unregisterDropZone(node, dzToConfig.get(node).type);
|
|
550
539
|
dzToConfig.delete(node);
|
|
551
540
|
}
|
|
552
|
-
if (isWorkingOnPreviousDrag) {
|
|
541
|
+
if (isWorkingOnPreviousDrag && !node.closest(`[${ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE}]`)) {
|
|
553
542
|
printDebug(() => "pointer dndzone will be scheduled for destruction");
|
|
554
543
|
scheduleDZForRemovalAfterDrop(node, destroyDz);
|
|
555
544
|
} else {
|