svelte-dnd-action 0.9.74 → 0.9.76

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/dist/index.js CHANGED
@@ -2387,6 +2387,25 @@
2387
2387
  handleDrop();
2388
2388
  }
2389
2389
  }
2390
+ function getActiveDragTabIndex(dropZoneEl, config) {
2391
+ return dropZoneEl === focusedDz || focusedItem.contains(dropZoneEl) || config.dropFromOthersDisabled || config.type !== draggedItemType ? -1 : 0;
2392
+ }
2393
+ function refreshActiveDragTabIndices() {
2394
+ dzToConfig.forEach(function (config, dropZoneEl) {
2395
+ dropZoneEl.tabIndex = getActiveDragTabIndex(dropZoneEl, config);
2396
+ });
2397
+ }
2398
+ function grabIsAlive() {
2399
+ var focusedConfig = dzToConfig.get(focusedDz);
2400
+ if (focusedConfig !== null && focusedConfig !== void 0 && focusedConfig.items.some(function (item) {
2401
+ return item[ITEM_ID_KEY] === focusedItemId;
2402
+ })) return true;
2403
+ printDebug(function () {
2404
+ return "dragged item is gone, dropping";
2405
+ });
2406
+ handleDrop();
2407
+ return false;
2408
+ }
2390
2409
  function handleZoneFocus(e) {
2391
2410
  printDebug(function () {
2392
2411
  return "zone focus";
@@ -2394,6 +2413,7 @@
2394
2413
  if (!isDragging) return;
2395
2414
  var newlyFocusedDz = e.currentTarget;
2396
2415
  if (newlyFocusedDz === focusedDz) return;
2416
+ if (!grabIsAlive()) return;
2397
2417
  focusedDzLabel = newlyFocusedDz.getAttribute("aria-label") || "";
2398
2418
  var _dzToConfig$get = dzToConfig.get(focusedDz),
2399
2419
  originItems = _dzToConfig$get.items;
@@ -2582,6 +2602,7 @@
2582
2602
  });
2583
2603
  setCurrentFocusedItem(e.currentTarget);
2584
2604
  focusedDz = node;
2605
+ focusedDzLabel = node.getAttribute("aria-label") || "";
2585
2606
  draggedItemType = config.type;
2586
2607
  isDragging = true;
2587
2608
  var dropTargets = Array.from(typeToDropZones.get(config.type)).filter(function (dz) {
@@ -2660,13 +2681,22 @@
2660
2681
  node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE);
2661
2682
  }
2662
2683
  dzToConfig.set(node, config);
2684
+ var itemMovedToThisZone = false;
2663
2685
  if (isDragging) {
2664
- node.tabIndex = node === focusedDz || focusedItem.contains(node) || config.dropFromOthersDisabled || focusedDz && config.type !== dzToConfig.get(focusedDz).type ? -1 : 0;
2686
+ itemMovedToThisZone = config.type === draggedItemType && config.items.some(function (item) {
2687
+ return item[ITEM_ID_KEY] === focusedItemId;
2688
+ }) && node !== focusedDz;
2689
+ if (itemMovedToThisZone) {
2690
+ focusedDz = node;
2691
+ focusedDzLabel = node.getAttribute("aria-label") || "";
2692
+ }
2693
+ node.tabIndex = getActiveDragTabIndex(node, config);
2665
2694
  } else {
2666
2695
  node.tabIndex = config.zoneTabIndex;
2667
2696
  }
2668
2697
  node.addEventListener("focus", handleZoneFocus);
2669
2698
  var _loop = function _loop(i) {
2699
+ var _config$items$i;
2670
2700
  var draggableEl = node.children[i];
2671
2701
  allDragTargets.add(draggableEl);
2672
2702
  draggableEl.tabIndex = isDragging ? -1 : config.zoneItemTabIndex;
@@ -2681,7 +2711,7 @@
2681
2711
  draggableEl.addEventListener("click", handleClick);
2682
2712
  elToFocusListeners.set(draggableEl, handleClick);
2683
2713
  }
2684
- if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
2714
+ if (isDragging && config.type === draggedItemType && ((_config$items$i = config.items[i]) === null || _config$items$i === void 0 ? void 0 : _config$items$i[ITEM_ID_KEY]) === focusedItemId) {
2685
2715
  printDebug(function () {
2686
2716
  return ["focusing on", {
2687
2717
  i: i,
@@ -2698,6 +2728,11 @@
2698
2728
  for (var i = 0; i < node.children.length; i++) {
2699
2729
  _loop(i);
2700
2730
  }
2731
+ if (itemMovedToThisZone) {
2732
+ // Nested actions are configured before their parent action. Refresh only
2733
+ // after focusedItem points at the replacement so nested zones stay untabbable.
2734
+ refreshActiveDragTabIndices();
2735
+ }
2701
2736
  }
2702
2737
  configure(options);
2703
2738
  var handles = {
package/dist/index.mjs CHANGED
@@ -2381,6 +2381,25 @@ function globalClickHandler() {
2381
2381
  handleDrop();
2382
2382
  }
2383
2383
  }
2384
+ function getActiveDragTabIndex(dropZoneEl, config) {
2385
+ return dropZoneEl === focusedDz || focusedItem.contains(dropZoneEl) || config.dropFromOthersDisabled || config.type !== draggedItemType ? -1 : 0;
2386
+ }
2387
+ function refreshActiveDragTabIndices() {
2388
+ dzToConfig.forEach(function (config, dropZoneEl) {
2389
+ dropZoneEl.tabIndex = getActiveDragTabIndex(dropZoneEl, config);
2390
+ });
2391
+ }
2392
+ function grabIsAlive() {
2393
+ var focusedConfig = dzToConfig.get(focusedDz);
2394
+ if (focusedConfig !== null && focusedConfig !== void 0 && focusedConfig.items.some(function (item) {
2395
+ return item[ITEM_ID_KEY] === focusedItemId;
2396
+ })) return true;
2397
+ printDebug(function () {
2398
+ return "dragged item is gone, dropping";
2399
+ });
2400
+ handleDrop();
2401
+ return false;
2402
+ }
2384
2403
  function handleZoneFocus(e) {
2385
2404
  printDebug(function () {
2386
2405
  return "zone focus";
@@ -2388,6 +2407,7 @@ function handleZoneFocus(e) {
2388
2407
  if (!isDragging) return;
2389
2408
  var newlyFocusedDz = e.currentTarget;
2390
2409
  if (newlyFocusedDz === focusedDz) return;
2410
+ if (!grabIsAlive()) return;
2391
2411
  focusedDzLabel = newlyFocusedDz.getAttribute("aria-label") || "";
2392
2412
  var _dzToConfig$get = dzToConfig.get(focusedDz),
2393
2413
  originItems = _dzToConfig$get.items;
@@ -2576,6 +2596,7 @@ function dndzone$1(node, options) {
2576
2596
  });
2577
2597
  setCurrentFocusedItem(e.currentTarget);
2578
2598
  focusedDz = node;
2599
+ focusedDzLabel = node.getAttribute("aria-label") || "";
2579
2600
  draggedItemType = config.type;
2580
2601
  isDragging = true;
2581
2602
  var dropTargets = Array.from(typeToDropZones.get(config.type)).filter(function (dz) {
@@ -2654,13 +2675,22 @@ function dndzone$1(node, options) {
2654
2675
  node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE);
2655
2676
  }
2656
2677
  dzToConfig.set(node, config);
2678
+ var itemMovedToThisZone = false;
2657
2679
  if (isDragging) {
2658
- node.tabIndex = node === focusedDz || focusedItem.contains(node) || config.dropFromOthersDisabled || focusedDz && config.type !== dzToConfig.get(focusedDz).type ? -1 : 0;
2680
+ itemMovedToThisZone = config.type === draggedItemType && config.items.some(function (item) {
2681
+ return item[ITEM_ID_KEY] === focusedItemId;
2682
+ }) && node !== focusedDz;
2683
+ if (itemMovedToThisZone) {
2684
+ focusedDz = node;
2685
+ focusedDzLabel = node.getAttribute("aria-label") || "";
2686
+ }
2687
+ node.tabIndex = getActiveDragTabIndex(node, config);
2659
2688
  } else {
2660
2689
  node.tabIndex = config.zoneTabIndex;
2661
2690
  }
2662
2691
  node.addEventListener("focus", handleZoneFocus);
2663
2692
  var _loop = function _loop(i) {
2693
+ var _config$items$i;
2664
2694
  var draggableEl = node.children[i];
2665
2695
  allDragTargets.add(draggableEl);
2666
2696
  draggableEl.tabIndex = isDragging ? -1 : config.zoneItemTabIndex;
@@ -2675,7 +2705,7 @@ function dndzone$1(node, options) {
2675
2705
  draggableEl.addEventListener("click", handleClick);
2676
2706
  elToFocusListeners.set(draggableEl, handleClick);
2677
2707
  }
2678
- if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
2708
+ if (isDragging && config.type === draggedItemType && ((_config$items$i = config.items[i]) === null || _config$items$i === void 0 ? void 0 : _config$items$i[ITEM_ID_KEY]) === focusedItemId) {
2679
2709
  printDebug(function () {
2680
2710
  return ["focusing on", {
2681
2711
  i: i,
@@ -2692,6 +2722,11 @@ function dndzone$1(node, options) {
2692
2722
  for (var i = 0; i < node.children.length; i++) {
2693
2723
  _loop(i);
2694
2724
  }
2725
+ if (itemMovedToThisZone) {
2726
+ // Nested actions are configured before their parent action. Refresh only
2727
+ // after focusedItem points at the replacement so nested zones stay untabbable.
2728
+ refreshActiveDragTabIndices();
2729
+ }
2695
2730
  }
2696
2731
  configure(options);
2697
2732
  var handles = {
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.74",
4
+ "version": "0.9.76",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
@@ -42,7 +42,7 @@
42
42
  "@babel/preset-env": "^7.9.6",
43
43
  "@rollup/plugin-node-resolve": "^6.0.0",
44
44
  "babel-jest": "^26.0.1",
45
- "cypress": "^4.5.0",
45
+ "cypress": "15.18.1",
46
46
  "eslint": "^7.11.0",
47
47
  "husky": "^4.3.0",
48
48
  "lint-staged": "^10.5.1",
@@ -86,12 +86,32 @@ function globalClickHandler() {
86
86
  }
87
87
  }
88
88
 
89
+ function getActiveDragTabIndex(dropZoneEl, config) {
90
+ return dropZoneEl === focusedDz || focusedItem.contains(dropZoneEl) || config.dropFromOthersDisabled || config.type !== draggedItemType ? -1 : 0;
91
+ }
92
+
93
+ function refreshActiveDragTabIndices() {
94
+ dzToConfig.forEach((config, dropZoneEl) => {
95
+ dropZoneEl.tabIndex = getActiveDragTabIndex(dropZoneEl, config);
96
+ });
97
+ }
98
+
99
+ function grabIsAlive() {
100
+ const focusedConfig = dzToConfig.get(focusedDz);
101
+ if (focusedConfig?.items.some(item => item[ITEM_ID_KEY] === focusedItemId)) return true;
102
+ printDebug(() => "dragged item is gone, dropping");
103
+ handleDrop();
104
+ return false;
105
+ }
106
+
89
107
  function handleZoneFocus(e) {
90
108
  printDebug(() => "zone focus");
91
109
  if (!isDragging) return;
92
110
  const newlyFocusedDz = e.currentTarget;
93
111
  if (newlyFocusedDz === focusedDz) return;
94
112
 
113
+ if (!grabIsAlive()) return;
114
+
95
115
  focusedDzLabel = newlyFocusedDz.getAttribute("aria-label") || "";
96
116
  const {items: originItems} = dzToConfig.get(focusedDz);
97
117
  const originItem = originItems.find(item => item[ITEM_ID_KEY] === focusedItemId);
@@ -249,6 +269,7 @@ export function dndzone(node, options) {
249
269
  printDebug(() => "drag start");
250
270
  setCurrentFocusedItem(e.currentTarget);
251
271
  focusedDz = node;
272
+ focusedDzLabel = node.getAttribute("aria-label") || "";
252
273
  draggedItemType = config.type;
253
274
  isDragging = true;
254
275
  const dropTargets = Array.from(typeToDropZones.get(config.type)).filter(dz => dz === focusedDz || !dzToConfig.get(dz).dropFromOthersDisabled);
@@ -315,14 +336,15 @@ export function dndzone(node, options) {
315
336
  }
316
337
  dzToConfig.set(node, config);
317
338
 
339
+ let itemMovedToThisZone = false;
318
340
  if (isDragging) {
319
- node.tabIndex =
320
- node === focusedDz ||
321
- focusedItem.contains(node) ||
322
- config.dropFromOthersDisabled ||
323
- (focusedDz && config.type !== dzToConfig.get(focusedDz).type)
324
- ? -1
325
- : 0;
341
+ itemMovedToThisZone =
342
+ config.type === draggedItemType && config.items.some(item => item[ITEM_ID_KEY] === focusedItemId) && node !== focusedDz;
343
+ if (itemMovedToThisZone) {
344
+ focusedDz = node;
345
+ focusedDzLabel = node.getAttribute("aria-label") || "";
346
+ }
347
+ node.tabIndex = getActiveDragTabIndex(node, config);
326
348
  } else {
327
349
  node.tabIndex = config.zoneTabIndex;
328
350
  }
@@ -344,7 +366,7 @@ export function dndzone(node, options) {
344
366
  draggableEl.addEventListener("click", handleClick);
345
367
  elToFocusListeners.set(draggableEl, handleClick);
346
368
  }
347
- if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
369
+ if (isDragging && config.type === draggedItemType && config.items[i]?.[ITEM_ID_KEY] === focusedItemId) {
348
370
  printDebug(() => ["focusing on", {i, focusedItemId}]);
349
371
  // if it is a nested dropzone, it was re-rendered and we need to refresh our pointer
350
372
  focusedItem = draggableEl;
@@ -353,6 +375,11 @@ export function dndzone(node, options) {
353
375
  draggableEl.focus();
354
376
  }
355
377
  }
378
+ if (itemMovedToThisZone) {
379
+ // Nested actions are configured before their parent action. Refresh only
380
+ // after focusedItem points at the replacement so nested zones stay untabbable.
381
+ refreshActiveDragTabIndices();
382
+ }
356
383
  }
357
384
  configure(options);
358
385