svelte-dnd-action 0.9.37 → 0.9.39

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 CHANGED
@@ -183,6 +183,7 @@ If you want to implement your own custom screen-reader alerts, roles and instruc
183
183
  - [Customizing the placeholder(shadow) element](https://svelte.dev/repl/9c8db8b91b2142d19dcf9bc963a27838?version=3)
184
184
 
185
185
  - [Copy on drag, simple and Dragula like](https://svelte.dev/repl/924b4cc920524065a637fa910fe10193?version=3)
186
+ - [Copy on drop and a drop area with a single slot](https://svelte.dev/repl/b4e120c45c3e48e49a0d637f0cf097d9?version=3)
186
187
  - [Drag handles](https://svelte.dev/repl/4949485c5a8f46e7bdbeb73ed565a9c7?version=3), courtesy of @gleuch
187
188
  - [Interaction (save/get items) with an asynchronous server](https://svelte.dev/repl/964fdac31cb9496da9ded35002300abb?version=3)
188
189
  - [Unsortable lists with custom aria instructions](https://svelte.dev/repl/e020ea1051dc4ae3ac2b697064f234bc?version=3)
@@ -280,6 +281,21 @@ declare namespace svelteHTML {
280
281
  ```
281
282
 
282
283
  You may need to edit `tsconfig.json` to include `global.d.ts` if it doesn't already: "include": ["src/**/*", "global.d.ts"].
284
+
285
+ > Note: If you are using Sveltekit you should use `svelte.config.js` to modify the generated `tsconfig.json` rather than adding the `include` element to the root `tsconfig.json`. Adding `include` to the root file will cause issues because it will [override](https://www.typescriptlang.org/tsconfig#extends) the `include` array defined in `.svelte-kit/tsconfig.json`. Example:
286
+ > ```javascript
287
+ > const config = {
288
+ > kit: {
289
+ > typescript: {
290
+ > config(config) {
291
+ > // This path is relative to the ".svelte-kit" folder
292
+ > config.include.push('../global.d.ts');
293
+ > },
294
+ > },
295
+ > },
296
+ > };
297
+ > ```
298
+
283
299
  Then you will be able to use the library with type safety as follows (Typescript gurus out there, improvements are welcome :smile:):
284
300
 
285
301
  ```html
package/dist/index.js CHANGED
@@ -1344,6 +1344,10 @@
1344
1344
  return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME];
1345
1345
  });
1346
1346
  }
1347
+ function createShadowElData(draggedElData) {
1348
+ var _objectSpread2$1;
1349
+ return _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));
1350
+ }
1347
1351
 
1348
1352
  /* custom drag-events handlers */
1349
1353
  function handleDraggedEntered(e) {
@@ -1406,7 +1410,9 @@
1406
1410
  return;
1407
1411
  }
1408
1412
  var shadowElIdx = findShadowElementIdx(items);
1409
- var shadowItem = items.splice(shadowElIdx, 1)[0];
1413
+ if (shadowElIdx !== -1) {
1414
+ items.splice(shadowElIdx, 1);
1415
+ }
1410
1416
  shadowElDropZone = undefined;
1411
1417
  var _e$detail = e.detail,
1412
1418
  type = _e$detail.type,
@@ -1418,7 +1424,7 @@
1418
1424
  isDraggedOutsideOfAnyDz = true;
1419
1425
  shadowElDropZone = originDropZone;
1420
1426
  var originZoneItems = dzToConfig.get(originDropZone).items;
1421
- originZoneItems.splice(originIndex, 0, shadowItem);
1427
+ originZoneItems.splice(originIndex, 0, shadowElData);
1422
1428
  dispatchConsiderEvent(originDropZone, originZoneItems, {
1423
1429
  trigger: TRIGGERS.DRAGGED_LEFT_ALL,
1424
1430
  id: draggedElData[ITEM_ID_KEY],
@@ -1448,7 +1454,9 @@
1448
1454
  isDraggedOutsideOfAnyDz = false;
1449
1455
  var index = e.detail.indexObj.index;
1450
1456
  var shadowElIdx = findShadowElementIdx(items);
1451
- items.splice(shadowElIdx, 1);
1457
+ if (shadowElIdx !== -1) {
1458
+ items.splice(shadowElIdx, 1);
1459
+ }
1452
1460
  items.splice(index, 0, shadowElData);
1453
1461
  dispatchConsiderEvent(e.currentTarget, items, {
1454
1462
  trigger: TRIGGERS.DRAGGED_OVER_INDEX,
@@ -1498,7 +1506,13 @@
1498
1506
  });
1499
1507
  var shadowElIdx = findShadowElementIdx(items);
1500
1508
  // the handler might remove the shadow element, ex: dragula like copy on drag
1501
- if (shadowElIdx === -1) shadowElIdx = originIndex;
1509
+ if (shadowElIdx === -1) {
1510
+ if (shadowElDropZone === originDropZone) {
1511
+ shadowElIdx = originIndex;
1512
+ } else if (shadowElDropZone.children.length > 0) {
1513
+ shadowElIdx = shadowElDropZone.children.length - 1;
1514
+ }
1515
+ }
1502
1516
  items = items.map(function (item) {
1503
1517
  return item[SHADOW_ITEM_MARKER_PROPERTY_NAME] ? draggedElData : item;
1504
1518
  });
@@ -1517,10 +1531,10 @@
1517
1531
  source: SOURCES.POINTER
1518
1532
  });
1519
1533
  }
1520
- unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
1534
+ if (shadowElIdx !== -1) unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
1521
1535
  cleanupPostDrop();
1522
1536
  }
1523
- animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
1537
+ if (shadowElIdx !== -1) animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
1524
1538
  }
1525
1539
 
1526
1540
  // helper function for handleDrop
@@ -1669,7 +1683,6 @@
1669
1683
  addMaybeListeners();
1670
1684
  }
1671
1685
  function handleDragStart() {
1672
- var _objectSpread2$1;
1673
1686
  printDebug(function () {
1674
1687
  return ["drag start config: ".concat(toString(config)), originalDragTarget];
1675
1688
  });
@@ -1687,7 +1700,7 @@
1687
1700
  centreDraggedOnCursor = config.centreDraggedOnCursor;
1688
1701
  draggedElData = items[currentIdx];
1689
1702
  draggedElType = type;
1690
- 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));
1703
+ shadowElData = createShadowElData(draggedElData);
1691
1704
 
1692
1705
  // creating the draggable element
1693
1706
  draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);
package/dist/index.mjs CHANGED
@@ -1338,6 +1338,10 @@ function findShadowElementIdx(items) {
1338
1338
  return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME];
1339
1339
  });
1340
1340
  }
1341
+ function createShadowElData(draggedElData) {
1342
+ var _objectSpread2$1;
1343
+ return _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));
1344
+ }
1341
1345
 
1342
1346
  /* custom drag-events handlers */
1343
1347
  function handleDraggedEntered(e) {
@@ -1400,7 +1404,9 @@ function handleDraggedLeft(e) {
1400
1404
  return;
1401
1405
  }
1402
1406
  var shadowElIdx = findShadowElementIdx(items);
1403
- var shadowItem = items.splice(shadowElIdx, 1)[0];
1407
+ if (shadowElIdx !== -1) {
1408
+ items.splice(shadowElIdx, 1);
1409
+ }
1404
1410
  shadowElDropZone = undefined;
1405
1411
  var _e$detail = e.detail,
1406
1412
  type = _e$detail.type,
@@ -1412,7 +1418,7 @@ function handleDraggedLeft(e) {
1412
1418
  isDraggedOutsideOfAnyDz = true;
1413
1419
  shadowElDropZone = originDropZone;
1414
1420
  var originZoneItems = dzToConfig.get(originDropZone).items;
1415
- originZoneItems.splice(originIndex, 0, shadowItem);
1421
+ originZoneItems.splice(originIndex, 0, shadowElData);
1416
1422
  dispatchConsiderEvent(originDropZone, originZoneItems, {
1417
1423
  trigger: TRIGGERS.DRAGGED_LEFT_ALL,
1418
1424
  id: draggedElData[ITEM_ID_KEY],
@@ -1442,7 +1448,9 @@ function handleDraggedIsOverIndex(e) {
1442
1448
  isDraggedOutsideOfAnyDz = false;
1443
1449
  var index = e.detail.indexObj.index;
1444
1450
  var shadowElIdx = findShadowElementIdx(items);
1445
- items.splice(shadowElIdx, 1);
1451
+ if (shadowElIdx !== -1) {
1452
+ items.splice(shadowElIdx, 1);
1453
+ }
1446
1454
  items.splice(index, 0, shadowElData);
1447
1455
  dispatchConsiderEvent(e.currentTarget, items, {
1448
1456
  trigger: TRIGGERS.DRAGGED_OVER_INDEX,
@@ -1492,7 +1500,13 @@ function handleDrop() {
1492
1500
  });
1493
1501
  var shadowElIdx = findShadowElementIdx(items);
1494
1502
  // the handler might remove the shadow element, ex: dragula like copy on drag
1495
- if (shadowElIdx === -1) shadowElIdx = originIndex;
1503
+ if (shadowElIdx === -1) {
1504
+ if (shadowElDropZone === originDropZone) {
1505
+ shadowElIdx = originIndex;
1506
+ } else if (shadowElDropZone.children.length > 0) {
1507
+ shadowElIdx = shadowElDropZone.children.length - 1;
1508
+ }
1509
+ }
1496
1510
  items = items.map(function (item) {
1497
1511
  return item[SHADOW_ITEM_MARKER_PROPERTY_NAME] ? draggedElData : item;
1498
1512
  });
@@ -1511,10 +1525,10 @@ function handleDrop() {
1511
1525
  source: SOURCES.POINTER
1512
1526
  });
1513
1527
  }
1514
- unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
1528
+ if (shadowElIdx !== -1) unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
1515
1529
  cleanupPostDrop();
1516
1530
  }
1517
- animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
1531
+ if (shadowElIdx !== -1) animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
1518
1532
  }
1519
1533
 
1520
1534
  // helper function for handleDrop
@@ -1663,7 +1677,6 @@ function dndzone(node, options) {
1663
1677
  addMaybeListeners();
1664
1678
  }
1665
1679
  function handleDragStart() {
1666
- var _objectSpread2$1;
1667
1680
  printDebug(function () {
1668
1681
  return ["drag start config: ".concat(toString(config)), originalDragTarget];
1669
1682
  });
@@ -1681,7 +1694,7 @@ function dndzone(node, options) {
1681
1694
  centreDraggedOnCursor = config.centreDraggedOnCursor;
1682
1695
  draggedElData = items[currentIdx];
1683
1696
  draggedElType = type;
1684
- 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));
1697
+ shadowElData = createShadowElData(draggedElData);
1685
1698
 
1686
1699
  // creating the draggable element
1687
1700
  draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);
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.37",
4
+ "version": "0.9.39",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
@@ -117,6 +117,9 @@ function unWatchDraggedElement() {
117
117
  function findShadowElementIdx(items) {
118
118
  return items.findIndex(item => !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME]);
119
119
  }
120
+ function createShadowElData(draggedElData) {
121
+ return {...draggedElData, [SHADOW_ITEM_MARKER_PROPERTY_NAME]: true, [ITEM_ID_KEY]: SHADOW_PLACEHOLDER_ITEM_ID};
122
+ }
120
123
 
121
124
  /* custom drag-events handlers */
122
125
  function handleDraggedEntered(e) {
@@ -157,7 +160,9 @@ function handleDraggedLeft(e) {
157
160
  return;
158
161
  }
159
162
  const shadowElIdx = findShadowElementIdx(items);
160
- const shadowItem = items.splice(shadowElIdx, 1)[0];
163
+ if (shadowElIdx !== -1) {
164
+ items.splice(shadowElIdx, 1);
165
+ }
161
166
  shadowElDropZone = undefined;
162
167
  const {type, theOtherDz} = e.detail;
163
168
  if (
@@ -168,7 +173,7 @@ function handleDraggedLeft(e) {
168
173
  isDraggedOutsideOfAnyDz = true;
169
174
  shadowElDropZone = originDropZone;
170
175
  const originZoneItems = dzToConfig.get(originDropZone).items;
171
- originZoneItems.splice(originIndex, 0, shadowItem);
176
+ originZoneItems.splice(originIndex, 0, shadowElData);
172
177
  dispatchConsiderEvent(originDropZone, originZoneItems, {
173
178
  trigger: TRIGGERS.DRAGGED_LEFT_ALL,
174
179
  id: draggedElData[ITEM_ID_KEY],
@@ -192,7 +197,9 @@ function handleDraggedIsOverIndex(e) {
192
197
  isDraggedOutsideOfAnyDz = false;
193
198
  const {index} = e.detail.indexObj;
194
199
  const shadowElIdx = findShadowElementIdx(items);
195
- items.splice(shadowElIdx, 1);
200
+ if (shadowElIdx !== -1) {
201
+ items.splice(shadowElIdx, 1);
202
+ }
196
203
  items.splice(index, 0, shadowElData);
197
204
  dispatchConsiderEvent(e.currentTarget, items, {trigger: TRIGGERS.DRAGGED_OVER_INDEX, id: draggedElData[ITEM_ID_KEY], source: SOURCES.POINTER});
198
205
  }
@@ -231,7 +238,13 @@ function handleDrop() {
231
238
  );
232
239
  let shadowElIdx = findShadowElementIdx(items);
233
240
  // the handler might remove the shadow element, ex: dragula like copy on drag
234
- if (shadowElIdx === -1) shadowElIdx = originIndex;
241
+ if (shadowElIdx === -1) {
242
+ if (shadowElDropZone === originDropZone) {
243
+ shadowElIdx = originIndex;
244
+ } else if (shadowElDropZone.children.length > 0) {
245
+ shadowElIdx = shadowElDropZone.children.length - 1;
246
+ }
247
+ }
235
248
 
236
249
  items = items.map(item => (item[SHADOW_ITEM_MARKER_PROPERTY_NAME] ? draggedElData : item));
237
250
  function finalizeWithinZone() {
@@ -249,10 +262,10 @@ function handleDrop() {
249
262
  source: SOURCES.POINTER
250
263
  });
251
264
  }
252
- unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
265
+ if (shadowElIdx !== -1) unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
253
266
  cleanupPostDrop();
254
267
  }
255
- animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
268
+ if (shadowElIdx !== -1) animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
256
269
  }
257
270
 
258
271
  // helper function for handleDrop
@@ -389,7 +402,7 @@ export function dndzone(node, options) {
389
402
  const {items, type, centreDraggedOnCursor} = config;
390
403
  draggedElData = items[currentIdx];
391
404
  draggedElType = type;
392
- shadowElData = {...draggedElData, [SHADOW_ITEM_MARKER_PROPERTY_NAME]: true, [ITEM_ID_KEY]: SHADOW_PLACEHOLDER_ITEM_ID};
405
+ shadowElData = createShadowElData(draggedElData);
393
406
 
394
407
  // creating the draggable element
395
408
  draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);