svelte-dnd-action 0.9.74 → 0.9.75

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;
@@ -2660,13 +2680,22 @@
2660
2680
  node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE);
2661
2681
  }
2662
2682
  dzToConfig.set(node, config);
2683
+ var itemMovedToThisZone = false;
2663
2684
  if (isDragging) {
2664
- node.tabIndex = node === focusedDz || focusedItem.contains(node) || config.dropFromOthersDisabled || focusedDz && config.type !== dzToConfig.get(focusedDz).type ? -1 : 0;
2685
+ itemMovedToThisZone = config.type === draggedItemType && config.items.some(function (item) {
2686
+ return item[ITEM_ID_KEY] === focusedItemId;
2687
+ }) && node !== focusedDz;
2688
+ if (itemMovedToThisZone) {
2689
+ focusedDz = node;
2690
+ focusedDzLabel = node.getAttribute("aria-label") || "";
2691
+ }
2692
+ node.tabIndex = getActiveDragTabIndex(node, config);
2665
2693
  } else {
2666
2694
  node.tabIndex = config.zoneTabIndex;
2667
2695
  }
2668
2696
  node.addEventListener("focus", handleZoneFocus);
2669
2697
  var _loop = function _loop(i) {
2698
+ var _config$items$i;
2670
2699
  var draggableEl = node.children[i];
2671
2700
  allDragTargets.add(draggableEl);
2672
2701
  draggableEl.tabIndex = isDragging ? -1 : config.zoneItemTabIndex;
@@ -2681,7 +2710,7 @@
2681
2710
  draggableEl.addEventListener("click", handleClick);
2682
2711
  elToFocusListeners.set(draggableEl, handleClick);
2683
2712
  }
2684
- if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
2713
+ 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
2714
  printDebug(function () {
2686
2715
  return ["focusing on", {
2687
2716
  i: i,
@@ -2698,6 +2727,11 @@
2698
2727
  for (var i = 0; i < node.children.length; i++) {
2699
2728
  _loop(i);
2700
2729
  }
2730
+ if (itemMovedToThisZone) {
2731
+ // Nested actions are configured before their parent action. Refresh only
2732
+ // after focusedItem points at the replacement so nested zones stay untabbable.
2733
+ refreshActiveDragTabIndices();
2734
+ }
2701
2735
  }
2702
2736
  configure(options);
2703
2737
  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;
@@ -2654,13 +2674,22 @@ function dndzone$1(node, options) {
2654
2674
  node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE);
2655
2675
  }
2656
2676
  dzToConfig.set(node, config);
2677
+ var itemMovedToThisZone = false;
2657
2678
  if (isDragging) {
2658
- node.tabIndex = node === focusedDz || focusedItem.contains(node) || config.dropFromOthersDisabled || focusedDz && config.type !== dzToConfig.get(focusedDz).type ? -1 : 0;
2679
+ itemMovedToThisZone = config.type === draggedItemType && config.items.some(function (item) {
2680
+ return item[ITEM_ID_KEY] === focusedItemId;
2681
+ }) && node !== focusedDz;
2682
+ if (itemMovedToThisZone) {
2683
+ focusedDz = node;
2684
+ focusedDzLabel = node.getAttribute("aria-label") || "";
2685
+ }
2686
+ node.tabIndex = getActiveDragTabIndex(node, config);
2659
2687
  } else {
2660
2688
  node.tabIndex = config.zoneTabIndex;
2661
2689
  }
2662
2690
  node.addEventListener("focus", handleZoneFocus);
2663
2691
  var _loop = function _loop(i) {
2692
+ var _config$items$i;
2664
2693
  var draggableEl = node.children[i];
2665
2694
  allDragTargets.add(draggableEl);
2666
2695
  draggableEl.tabIndex = isDragging ? -1 : config.zoneItemTabIndex;
@@ -2675,7 +2704,7 @@ function dndzone$1(node, options) {
2675
2704
  draggableEl.addEventListener("click", handleClick);
2676
2705
  elToFocusListeners.set(draggableEl, handleClick);
2677
2706
  }
2678
- if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
2707
+ 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
2708
  printDebug(function () {
2680
2709
  return ["focusing on", {
2681
2710
  i: i,
@@ -2692,6 +2721,11 @@ function dndzone$1(node, options) {
2692
2721
  for (var i = 0; i < node.children.length; i++) {
2693
2722
  _loop(i);
2694
2723
  }
2724
+ if (itemMovedToThisZone) {
2725
+ // Nested actions are configured before their parent action. Refresh only
2726
+ // after focusedItem points at the replacement so nested zones stay untabbable.
2727
+ refreshActiveDragTabIndices();
2728
+ }
2695
2729
  }
2696
2730
  configure(options);
2697
2731
  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.75",
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);
@@ -315,14 +335,15 @@ export function dndzone(node, options) {
315
335
  }
316
336
  dzToConfig.set(node, config);
317
337
 
338
+ let itemMovedToThisZone = false;
318
339
  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;
340
+ itemMovedToThisZone =
341
+ config.type === draggedItemType && config.items.some(item => item[ITEM_ID_KEY] === focusedItemId) && node !== focusedDz;
342
+ if (itemMovedToThisZone) {
343
+ focusedDz = node;
344
+ focusedDzLabel = node.getAttribute("aria-label") || "";
345
+ }
346
+ node.tabIndex = getActiveDragTabIndex(node, config);
326
347
  } else {
327
348
  node.tabIndex = config.zoneTabIndex;
328
349
  }
@@ -344,7 +365,7 @@ export function dndzone(node, options) {
344
365
  draggableEl.addEventListener("click", handleClick);
345
366
  elToFocusListeners.set(draggableEl, handleClick);
346
367
  }
347
- if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
368
+ if (isDragging && config.type === draggedItemType && config.items[i]?.[ITEM_ID_KEY] === focusedItemId) {
348
369
  printDebug(() => ["focusing on", {i, focusedItemId}]);
349
370
  // if it is a nested dropzone, it was re-rendered and we need to refresh our pointer
350
371
  focusedItem = draggableEl;
@@ -353,6 +374,11 @@ export function dndzone(node, options) {
353
374
  draggableEl.focus();
354
375
  }
355
376
  }
377
+ if (itemMovedToThisZone) {
378
+ // Nested actions are configured before their parent action. Refresh only
379
+ // after focusedItem points at the replacement so nested zones stay untabbable.
380
+ refreshActiveDragTabIndices();
381
+ }
356
382
  }
357
383
  configure(options);
358
384