svelte-dnd-action 0.9.41 → 0.9.42
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 +7 -0
- package/dist/index.js +13 -8
- package/dist/index.mjs +13 -8
- package/package.json +1 -1
- package/src/pointerAction.js +14 -8
package/README.md
CHANGED
|
@@ -372,6 +372,13 @@ This is an experimental feature added in version 0.9.29. If you have multiple le
|
|
|
372
372
|
Specifically, it allows nested zones within the shadow element (the placeholder under the dragged element) to register and destroy.
|
|
373
373
|
This is because Svelte calls nested actions before the parent action (opposite to the rendering order).
|
|
374
374
|
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]} `
|
|
375
|
+
Starting with version 0.9.42. if you use the hint make sure to include it in the key you provide in your each block e.g:
|
|
376
|
+
|
|
377
|
+
```sveltehtml
|
|
378
|
+
{#each columnItems as column (`${column._id}${column[SHADOW_ITEM_MARKER_PROPERTY_NAME] ? "_" + column[SHADOW_ITEM_MARKER_PROPERTY_NAME] : ""}`)}
|
|
379
|
+
...
|
|
380
|
+
{/each}
|
|
381
|
+
```
|
|
375
382
|
|
|
376
383
|
#### Simplified Example (just shows where to place the attribute):
|
|
377
384
|
|
package/dist/index.js
CHANGED
|
@@ -1439,7 +1439,7 @@
|
|
|
1439
1439
|
return ["dragged left", e.currentTarget, e.detail];
|
|
1440
1440
|
});
|
|
1441
1441
|
var _dzToConfig$get2 = dzToConfig.get(e.currentTarget),
|
|
1442
|
-
|
|
1442
|
+
originalItems = _dzToConfig$get2.items,
|
|
1443
1443
|
dropFromOthersDisabled = _dzToConfig$get2.dropFromOthersDisabled;
|
|
1444
1444
|
if (dropFromOthersDisabled && e.currentTarget !== originDropZone && e.currentTarget !== shadowElDropZone) {
|
|
1445
1445
|
printDebug(function () {
|
|
@@ -1447,10 +1447,12 @@
|
|
|
1447
1447
|
});
|
|
1448
1448
|
return;
|
|
1449
1449
|
}
|
|
1450
|
+
var items = _toConsumableArray(originalItems);
|
|
1450
1451
|
var shadowElIdx = findShadowElementIdx(items);
|
|
1451
1452
|
if (shadowElIdx !== -1) {
|
|
1452
1453
|
items.splice(shadowElIdx, 1);
|
|
1453
1454
|
}
|
|
1455
|
+
var origShadowDz = shadowElDropZone;
|
|
1454
1456
|
shadowElDropZone = undefined;
|
|
1455
1457
|
var _e$detail = e.detail,
|
|
1456
1458
|
type = _e$detail.type,
|
|
@@ -1461,7 +1463,8 @@
|
|
|
1461
1463
|
});
|
|
1462
1464
|
isDraggedOutsideOfAnyDz = true;
|
|
1463
1465
|
shadowElDropZone = originDropZone;
|
|
1464
|
-
|
|
1466
|
+
// if the last zone it left is the origin dz, we will put it back into items (which we just removed it from)
|
|
1467
|
+
var originZoneItems = origShadowDz === originDropZone ? items : _toConsumableArray(dzToConfig.get(originDropZone).items);
|
|
1465
1468
|
originZoneItems.splice(originIndex, 0, shadowElData);
|
|
1466
1469
|
dispatchConsiderEvent(originDropZone, originZoneItems, {
|
|
1467
1470
|
trigger: TRIGGERS.DRAGGED_LEFT_ALL,
|
|
@@ -1481,7 +1484,7 @@
|
|
|
1481
1484
|
return ["dragged is over index", e.currentTarget, e.detail];
|
|
1482
1485
|
});
|
|
1483
1486
|
var _dzToConfig$get3 = dzToConfig.get(e.currentTarget),
|
|
1484
|
-
|
|
1487
|
+
originalItems = _dzToConfig$get3.items,
|
|
1485
1488
|
dropFromOthersDisabled = _dzToConfig$get3.dropFromOthersDisabled;
|
|
1486
1489
|
if (dropFromOthersDisabled && e.currentTarget !== originDropZone) {
|
|
1487
1490
|
printDebug(function () {
|
|
@@ -1489,6 +1492,7 @@
|
|
|
1489
1492
|
});
|
|
1490
1493
|
return;
|
|
1491
1494
|
}
|
|
1495
|
+
var items = _toConsumableArray(originalItems);
|
|
1492
1496
|
isDraggedOutsideOfAnyDz = false;
|
|
1493
1497
|
var index = e.detail.indexObj.index;
|
|
1494
1498
|
var shadowElIdx = findShadowElementIdx(items);
|
|
@@ -1547,8 +1551,6 @@
|
|
|
1547
1551
|
if (shadowElIdx === -1) {
|
|
1548
1552
|
if (shadowElDropZone === originDropZone) {
|
|
1549
1553
|
shadowElIdx = originIndex;
|
|
1550
|
-
} else if (shadowElDropZone.children.length > 0) {
|
|
1551
|
-
shadowElIdx = shadowElDropZone.children.length - 1;
|
|
1552
1554
|
}
|
|
1553
1555
|
}
|
|
1554
1556
|
items = items.map(function (item) {
|
|
@@ -1572,12 +1574,12 @@
|
|
|
1572
1574
|
if (shadowElIdx !== -1) unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
|
|
1573
1575
|
cleanupPostDrop();
|
|
1574
1576
|
}
|
|
1575
|
-
|
|
1577
|
+
animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
|
|
1576
1578
|
}
|
|
1577
1579
|
|
|
1578
1580
|
// helper function for handleDrop
|
|
1579
1581
|
function animateDraggedToFinalPosition(shadowElIdx, callback) {
|
|
1580
|
-
var shadowElRect = getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]);
|
|
1582
|
+
var shadowElRect = shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]) : getBoundingRectNoTransforms(shadowElDropZone);
|
|
1581
1583
|
var newTransform = {
|
|
1582
1584
|
x: shadowElRect.left - parseFloat(draggedEl.style.left),
|
|
1583
1585
|
y: shadowElRect.top - parseFloat(draggedEl.style.top)
|
|
@@ -1733,9 +1735,10 @@
|
|
|
1733
1735
|
/** @type {ShadowRoot | HTMLDocument | Element } */
|
|
1734
1736
|
var rootNode = originDropZone.closest("dialog") || originDropZone.getRootNode();
|
|
1735
1737
|
var originDropZoneRoot = rootNode.body || rootNode;
|
|
1736
|
-
var
|
|
1738
|
+
var originalItems = config.items,
|
|
1737
1739
|
type = config.type,
|
|
1738
1740
|
centreDraggedOnCursor = config.centreDraggedOnCursor;
|
|
1741
|
+
var items = _toConsumableArray(originalItems);
|
|
1739
1742
|
draggedElData = items[currentIdx];
|
|
1740
1743
|
draggedElType = type;
|
|
1741
1744
|
shadowElData = createShadowElData(draggedElData);
|
|
@@ -1753,6 +1756,8 @@
|
|
|
1753
1756
|
watchDraggedElement();
|
|
1754
1757
|
hideElement(originalDragTarget);
|
|
1755
1758
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
1759
|
+
// after the removal of the original element we can give the shadow element the original item id so that the host zone can find it and render it correctly if it does lookups by id
|
|
1760
|
+
shadowElData[ITEM_ID_KEY] = draggedElData[ITEM_ID_KEY];
|
|
1756
1761
|
} else {
|
|
1757
1762
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
1758
1763
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1433,7 +1433,7 @@ function handleDraggedLeft(e) {
|
|
|
1433
1433
|
return ["dragged left", e.currentTarget, e.detail];
|
|
1434
1434
|
});
|
|
1435
1435
|
var _dzToConfig$get2 = dzToConfig.get(e.currentTarget),
|
|
1436
|
-
|
|
1436
|
+
originalItems = _dzToConfig$get2.items,
|
|
1437
1437
|
dropFromOthersDisabled = _dzToConfig$get2.dropFromOthersDisabled;
|
|
1438
1438
|
if (dropFromOthersDisabled && e.currentTarget !== originDropZone && e.currentTarget !== shadowElDropZone) {
|
|
1439
1439
|
printDebug(function () {
|
|
@@ -1441,10 +1441,12 @@ function handleDraggedLeft(e) {
|
|
|
1441
1441
|
});
|
|
1442
1442
|
return;
|
|
1443
1443
|
}
|
|
1444
|
+
var items = _toConsumableArray(originalItems);
|
|
1444
1445
|
var shadowElIdx = findShadowElementIdx(items);
|
|
1445
1446
|
if (shadowElIdx !== -1) {
|
|
1446
1447
|
items.splice(shadowElIdx, 1);
|
|
1447
1448
|
}
|
|
1449
|
+
var origShadowDz = shadowElDropZone;
|
|
1448
1450
|
shadowElDropZone = undefined;
|
|
1449
1451
|
var _e$detail = e.detail,
|
|
1450
1452
|
type = _e$detail.type,
|
|
@@ -1455,7 +1457,8 @@ function handleDraggedLeft(e) {
|
|
|
1455
1457
|
});
|
|
1456
1458
|
isDraggedOutsideOfAnyDz = true;
|
|
1457
1459
|
shadowElDropZone = originDropZone;
|
|
1458
|
-
|
|
1460
|
+
// if the last zone it left is the origin dz, we will put it back into items (which we just removed it from)
|
|
1461
|
+
var originZoneItems = origShadowDz === originDropZone ? items : _toConsumableArray(dzToConfig.get(originDropZone).items);
|
|
1459
1462
|
originZoneItems.splice(originIndex, 0, shadowElData);
|
|
1460
1463
|
dispatchConsiderEvent(originDropZone, originZoneItems, {
|
|
1461
1464
|
trigger: TRIGGERS.DRAGGED_LEFT_ALL,
|
|
@@ -1475,7 +1478,7 @@ function handleDraggedIsOverIndex(e) {
|
|
|
1475
1478
|
return ["dragged is over index", e.currentTarget, e.detail];
|
|
1476
1479
|
});
|
|
1477
1480
|
var _dzToConfig$get3 = dzToConfig.get(e.currentTarget),
|
|
1478
|
-
|
|
1481
|
+
originalItems = _dzToConfig$get3.items,
|
|
1479
1482
|
dropFromOthersDisabled = _dzToConfig$get3.dropFromOthersDisabled;
|
|
1480
1483
|
if (dropFromOthersDisabled && e.currentTarget !== originDropZone) {
|
|
1481
1484
|
printDebug(function () {
|
|
@@ -1483,6 +1486,7 @@ function handleDraggedIsOverIndex(e) {
|
|
|
1483
1486
|
});
|
|
1484
1487
|
return;
|
|
1485
1488
|
}
|
|
1489
|
+
var items = _toConsumableArray(originalItems);
|
|
1486
1490
|
isDraggedOutsideOfAnyDz = false;
|
|
1487
1491
|
var index = e.detail.indexObj.index;
|
|
1488
1492
|
var shadowElIdx = findShadowElementIdx(items);
|
|
@@ -1541,8 +1545,6 @@ function handleDrop() {
|
|
|
1541
1545
|
if (shadowElIdx === -1) {
|
|
1542
1546
|
if (shadowElDropZone === originDropZone) {
|
|
1543
1547
|
shadowElIdx = originIndex;
|
|
1544
|
-
} else if (shadowElDropZone.children.length > 0) {
|
|
1545
|
-
shadowElIdx = shadowElDropZone.children.length - 1;
|
|
1546
1548
|
}
|
|
1547
1549
|
}
|
|
1548
1550
|
items = items.map(function (item) {
|
|
@@ -1566,12 +1568,12 @@ function handleDrop() {
|
|
|
1566
1568
|
if (shadowElIdx !== -1) unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
|
|
1567
1569
|
cleanupPostDrop();
|
|
1568
1570
|
}
|
|
1569
|
-
|
|
1571
|
+
animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
|
|
1570
1572
|
}
|
|
1571
1573
|
|
|
1572
1574
|
// helper function for handleDrop
|
|
1573
1575
|
function animateDraggedToFinalPosition(shadowElIdx, callback) {
|
|
1574
|
-
var shadowElRect = getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]);
|
|
1576
|
+
var shadowElRect = shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]) : getBoundingRectNoTransforms(shadowElDropZone);
|
|
1575
1577
|
var newTransform = {
|
|
1576
1578
|
x: shadowElRect.left - parseFloat(draggedEl.style.left),
|
|
1577
1579
|
y: shadowElRect.top - parseFloat(draggedEl.style.top)
|
|
@@ -1727,9 +1729,10 @@ function dndzone(node, options) {
|
|
|
1727
1729
|
/** @type {ShadowRoot | HTMLDocument | Element } */
|
|
1728
1730
|
var rootNode = originDropZone.closest("dialog") || originDropZone.getRootNode();
|
|
1729
1731
|
var originDropZoneRoot = rootNode.body || rootNode;
|
|
1730
|
-
var
|
|
1732
|
+
var originalItems = config.items,
|
|
1731
1733
|
type = config.type,
|
|
1732
1734
|
centreDraggedOnCursor = config.centreDraggedOnCursor;
|
|
1735
|
+
var items = _toConsumableArray(originalItems);
|
|
1733
1736
|
draggedElData = items[currentIdx];
|
|
1734
1737
|
draggedElType = type;
|
|
1735
1738
|
shadowElData = createShadowElData(draggedElData);
|
|
@@ -1747,6 +1750,8 @@ function dndzone(node, options) {
|
|
|
1747
1750
|
watchDraggedElement();
|
|
1748
1751
|
hideElement(originalDragTarget);
|
|
1749
1752
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
1753
|
+
// after the removal of the original element we can give the shadow element the original item id so that the host zone can find it and render it correctly if it does lookups by id
|
|
1754
|
+
shadowElData[ITEM_ID_KEY] = draggedElData[ITEM_ID_KEY];
|
|
1750
1755
|
} else {
|
|
1751
1756
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
1752
1757
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-dnd-action",
|
|
3
3
|
"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 *",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.42",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
|
package/src/pointerAction.js
CHANGED
|
@@ -155,15 +155,17 @@ function handleDraggedLeft(e) {
|
|
|
155
155
|
// dealing with a rare race condition on extremely rapid clicking and dropping
|
|
156
156
|
if (!isWorkingOnPreviousDrag) return;
|
|
157
157
|
printDebug(() => ["dragged left", e.currentTarget, e.detail]);
|
|
158
|
-
const {items, dropFromOthersDisabled} = dzToConfig.get(e.currentTarget);
|
|
158
|
+
const {items: originalItems, dropFromOthersDisabled} = dzToConfig.get(e.currentTarget);
|
|
159
159
|
if (dropFromOthersDisabled && e.currentTarget !== originDropZone && e.currentTarget !== shadowElDropZone) {
|
|
160
160
|
printDebug(() => "drop is currently disabled");
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
|
+
const items = [...originalItems];
|
|
163
164
|
const shadowElIdx = findShadowElementIdx(items);
|
|
164
165
|
if (shadowElIdx !== -1) {
|
|
165
166
|
items.splice(shadowElIdx, 1);
|
|
166
167
|
}
|
|
168
|
+
const origShadowDz = shadowElDropZone;
|
|
167
169
|
shadowElDropZone = undefined;
|
|
168
170
|
const {type, theOtherDz} = e.detail;
|
|
169
171
|
if (
|
|
@@ -173,7 +175,8 @@ function handleDraggedLeft(e) {
|
|
|
173
175
|
printDebug(() => "dragged left all, putting shadow element back in the origin dz");
|
|
174
176
|
isDraggedOutsideOfAnyDz = true;
|
|
175
177
|
shadowElDropZone = originDropZone;
|
|
176
|
-
|
|
178
|
+
// if the last zone it left is the origin dz, we will put it back into items (which we just removed it from)
|
|
179
|
+
const originZoneItems = origShadowDz === originDropZone ? items : [...dzToConfig.get(originDropZone).items];
|
|
177
180
|
originZoneItems.splice(originIndex, 0, shadowElData);
|
|
178
181
|
dispatchConsiderEvent(originDropZone, originZoneItems, {
|
|
179
182
|
trigger: TRIGGERS.DRAGGED_LEFT_ALL,
|
|
@@ -190,11 +193,12 @@ function handleDraggedLeft(e) {
|
|
|
190
193
|
}
|
|
191
194
|
function handleDraggedIsOverIndex(e) {
|
|
192
195
|
printDebug(() => ["dragged is over index", e.currentTarget, e.detail]);
|
|
193
|
-
const {items, dropFromOthersDisabled} = dzToConfig.get(e.currentTarget);
|
|
196
|
+
const {items: originalItems, dropFromOthersDisabled} = dzToConfig.get(e.currentTarget);
|
|
194
197
|
if (dropFromOthersDisabled && e.currentTarget !== originDropZone) {
|
|
195
198
|
printDebug(() => "drop is currently disabled");
|
|
196
199
|
return;
|
|
197
200
|
}
|
|
201
|
+
const items = [...originalItems];
|
|
198
202
|
isDraggedOutsideOfAnyDz = false;
|
|
199
203
|
const {index} = e.detail.indexObj;
|
|
200
204
|
const shadowElIdx = findShadowElementIdx(items);
|
|
@@ -242,8 +246,6 @@ function handleDrop() {
|
|
|
242
246
|
if (shadowElIdx === -1) {
|
|
243
247
|
if (shadowElDropZone === originDropZone) {
|
|
244
248
|
shadowElIdx = originIndex;
|
|
245
|
-
} else if (shadowElDropZone.children.length > 0) {
|
|
246
|
-
shadowElIdx = shadowElDropZone.children.length - 1;
|
|
247
249
|
}
|
|
248
250
|
}
|
|
249
251
|
|
|
@@ -266,12 +268,13 @@ function handleDrop() {
|
|
|
266
268
|
if (shadowElIdx !== -1) unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
|
|
267
269
|
cleanupPostDrop();
|
|
268
270
|
}
|
|
269
|
-
|
|
271
|
+
animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
|
|
270
272
|
}
|
|
271
273
|
|
|
272
274
|
// helper function for handleDrop
|
|
273
275
|
function animateDraggedToFinalPosition(shadowElIdx, callback) {
|
|
274
|
-
const shadowElRect =
|
|
276
|
+
const shadowElRect =
|
|
277
|
+
shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]) : getBoundingRectNoTransforms(shadowElDropZone);
|
|
275
278
|
const newTransform = {
|
|
276
279
|
x: shadowElRect.left - parseFloat(draggedEl.style.left),
|
|
277
280
|
y: shadowElRect.top - parseFloat(draggedEl.style.top)
|
|
@@ -400,7 +403,8 @@ export function dndzone(node, options) {
|
|
|
400
403
|
/** @type {ShadowRoot | HTMLDocument | Element } */
|
|
401
404
|
const rootNode = originDropZone.closest("dialog") || originDropZone.getRootNode();
|
|
402
405
|
const originDropZoneRoot = rootNode.body || rootNode;
|
|
403
|
-
const {items, type, centreDraggedOnCursor} = config;
|
|
406
|
+
const {items: originalItems, type, centreDraggedOnCursor} = config;
|
|
407
|
+
const items = [...originalItems];
|
|
404
408
|
draggedElData = items[currentIdx];
|
|
405
409
|
draggedElType = type;
|
|
406
410
|
shadowElData = createShadowElData(draggedElData);
|
|
@@ -418,6 +422,8 @@ export function dndzone(node, options) {
|
|
|
418
422
|
watchDraggedElement();
|
|
419
423
|
hideElement(originalDragTarget);
|
|
420
424
|
originDropZoneRoot.appendChild(originalDragTarget);
|
|
425
|
+
// after the removal of the original element we can give the shadow element the original item id so that the host zone can find it and render it correctly if it does lookups by id
|
|
426
|
+
shadowElData[ITEM_ID_KEY] = draggedElData[ITEM_ID_KEY];
|
|
421
427
|
} else {
|
|
422
428
|
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
423
429
|
}
|