svelte-dnd-action 0.9.10 → 0.9.14

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
@@ -189,6 +189,7 @@ If you want to implement your own custom screen-reader alerts, roles and instruc
189
189
  - [Generic List Component (Alternative to Slots)](https://svelte.dev/repl/028674733f67409c94bd52995d5906f1?version=3.31.0)
190
190
  - [Maitaining internal scroll poisition on scrollable dragabble](https://svelte.dev/repl/eb2f5988bd2f46488810606c1fb13392?version=3.29.4)
191
191
  - [Scrabble like board using over a 100 single slot dnd-zones](https://svelte.dev/repl/ed2e138417094281be6db1aef23d7859?version=3.37.0)
192
+ - [Select multiple elements to drag (multi-drag) with mouse or keyboard](https://svelte.dev/repl/c4eb917bb8df42c4b17402a7dda54856?version=3.24.1)
192
193
 
193
194
  - [Fade in/out but without using Svelte transitions](https://svelte.dev/repl/3f1e68203ef140969a8240eba3475a8d?version=3.24.1)
194
195
  - [Nested fade in/out without using Svelte transitions](https://svelte.dev/repl/49b09aedfe0543b4bc8f575c8dbf9a53?version=3.24.1)
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ export interface Options {
27
27
  morphDisabled?: boolean;
28
28
  dropFromOthersDisabled?: boolean;
29
29
  zoneTabIndex?: number; // set the tabindex of the list container when not dragging
30
- dropTargetClasses?: [string];
30
+ dropTargetClasses?: string[];
31
31
  dropTargetStyle?: Record<string, string>;
32
32
  transformDraggedElement?: TransformDraggedElementFunction;
33
33
  autoAriaDisabled?: boolean;
package/dist/index.js CHANGED
@@ -599,6 +599,17 @@
599
599
  dzToShadowIndexToRect = new Map();
600
600
  }
601
601
  resetIndexesCache();
602
+ /**
603
+ * Resets the cache that allows for smarter "would be index" resolution for a specific dropzone, should be called after the zone was scrolled
604
+ * @param {HTMLElement} dz
605
+ */
606
+
607
+ function resetIndexesCacheForDz(dz) {
608
+ printDebug(function () {
609
+ return "resetting indexes cache for dz";
610
+ });
611
+ dzToShadowIndexToRect["delete"](dz);
612
+ }
602
613
  /**
603
614
  * Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
604
615
  * Helpful in order to determine "would be index" more effectively
@@ -931,6 +942,7 @@
931
942
  try {
932
943
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
933
944
  var dz = _step.value;
945
+ if (scrolled) resetIndexesCacheForDz(lastDropZoneFound);
934
946
  var indexObj = findWouldBeIndex(draggedEl, dz);
935
947
 
936
948
  if (indexObj === null) {
@@ -1008,7 +1020,8 @@
1008
1020
 
1009
1021
  function loop() {
1010
1022
  if (mousePosition) {
1011
- scrollIfNeeded$1(mousePosition, document.documentElement);
1023
+ var scrolled = scrollIfNeeded$1(mousePosition, document.documentElement);
1024
+ if (scrolled) resetIndexesCache();
1012
1025
  }
1013
1026
 
1014
1027
  next$1 = window.setTimeout(loop, INTERVAL_MS$1);
@@ -1530,7 +1543,7 @@
1530
1543
  x: c.clientX,
1531
1544
  y: c.clientY
1532
1545
  };
1533
- draggedEl.style.transform = "translate3d(0, ".concat(currentMousePosition.y - dragStartMousePosition.y, "px, 0)");
1546
+ draggedEl.style.transform = "translate3d(".concat(currentMousePosition.x - dragStartMousePosition.x, "px, ").concat(currentMousePosition.y - dragStartMousePosition.y, "px, 0)");
1534
1547
  }
1535
1548
 
1536
1549
  function handleDrop() {
package/dist/index.mjs CHANGED
@@ -593,6 +593,17 @@ function resetIndexesCache() {
593
593
  dzToShadowIndexToRect = new Map();
594
594
  }
595
595
  resetIndexesCache();
596
+ /**
597
+ * Resets the cache that allows for smarter "would be index" resolution for a specific dropzone, should be called after the zone was scrolled
598
+ * @param {HTMLElement} dz
599
+ */
600
+
601
+ function resetIndexesCacheForDz(dz) {
602
+ printDebug(function () {
603
+ return "resetting indexes cache for dz";
604
+ });
605
+ dzToShadowIndexToRect["delete"](dz);
606
+ }
596
607
  /**
597
608
  * Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
598
609
  * Helpful in order to determine "would be index" more effectively
@@ -925,6 +936,7 @@ function observe(draggedEl, dropZones) {
925
936
  try {
926
937
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
927
938
  var dz = _step.value;
939
+ if (scrolled) resetIndexesCacheForDz(lastDropZoneFound);
928
940
  var indexObj = findWouldBeIndex(draggedEl, dz);
929
941
 
930
942
  if (indexObj === null) {
@@ -1002,7 +1014,8 @@ var next$1;
1002
1014
 
1003
1015
  function loop() {
1004
1016
  if (mousePosition) {
1005
- scrollIfNeeded$1(mousePosition, document.documentElement);
1017
+ var scrolled = scrollIfNeeded$1(mousePosition, document.documentElement);
1018
+ if (scrolled) resetIndexesCache();
1006
1019
  }
1007
1020
 
1008
1021
  next$1 = window.setTimeout(loop, INTERVAL_MS$1);
@@ -1524,7 +1537,7 @@ function handleMouseMove(e) {
1524
1537
  x: c.clientX,
1525
1538
  y: c.clientY
1526
1539
  };
1527
- draggedEl.style.transform = "translate3d(0, ".concat(currentMousePosition.y - dragStartMousePosition.y, "px, 0)");
1540
+ draggedEl.style.transform = "translate3d(".concat(currentMousePosition.x - dragStartMousePosition.x, "px, ").concat(currentMousePosition.y - dragStartMousePosition.y, "px, 0)");
1528
1541
  }
1529
1542
 
1530
1543
  function handleDrop() {
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "dist"
41
41
  ],
42
42
  "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 *",
43
- "version": "0.9.10",
43
+ "version": "0.9.14",
44
44
  "repository": {
45
45
  "type": "git",
46
46
  "url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
@@ -12,6 +12,15 @@ export function resetIndexesCache() {
12
12
  }
13
13
  resetIndexesCache();
14
14
 
15
+ /**
16
+ * Resets the cache that allows for smarter "would be index" resolution for a specific dropzone, should be called after the zone was scrolled
17
+ * @param {HTMLElement} dz
18
+ */
19
+ export function resetIndexesCacheForDz(dz) {
20
+ printDebug(() => "resetting indexes cache for dz");
21
+ dzToShadowIndexToRect.delete(dz);
22
+ }
23
+
15
24
  /**
16
25
  * Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
17
26
  * Helpful in order to determine "would be index" more effectively
@@ -1,4 +1,4 @@
1
- import {findWouldBeIndex, resetIndexesCache} from "./listUtil";
1
+ import {findWouldBeIndex, resetIndexesCache, resetIndexesCacheForDz} from "./listUtil";
2
2
  import {findCenterOfElement, isElementOffDocument} from "./intersection";
3
3
  import {
4
4
  dispatchDraggedElementEnteredContainer,
@@ -57,6 +57,7 @@ export function observe(draggedEl, dropZones, intervalMs = INTERVAL_MS) {
57
57
  // this is a simple algorithm, potential improvement: first look at lastDropZoneFound
58
58
  let isDraggedInADropZone = false;
59
59
  for (const dz of dropZonesFromDeepToShallow) {
60
+ if (scrolled) resetIndexesCacheForDz(lastDropZoneFound);
60
61
  const indexObj = findWouldBeIndex(draggedEl, dz);
61
62
  if (indexObj === null) {
62
63
  // it is not inside
@@ -1,5 +1,6 @@
1
1
  import {makeScroller} from "./scroller";
2
2
  import {printDebug} from "../constants";
3
+ import {resetIndexesCache} from "./listUtil";
3
4
 
4
5
  const INTERVAL_MS = 300;
5
6
  let mousePosition;
@@ -18,7 +19,8 @@ let next;
18
19
 
19
20
  function loop() {
20
21
  if (mousePosition) {
21
- scrollIfNeeded(mousePosition, document.documentElement);
22
+ const scrolled = scrollIfNeeded(mousePosition, document.documentElement);
23
+ if (scrolled) resetIndexesCache();
22
24
  }
23
25
  next = window.setTimeout(loop, INTERVAL_MS);
24
26
  }
@@ -214,7 +214,9 @@ function handleMouseMove(e) {
214
214
  e.preventDefault();
215
215
  const c = e.touches ? e.touches[0] : e;
216
216
  currentMousePosition = {x: c.clientX, y: c.clientY};
217
- draggedEl.style.transform = `translate3d(0, ${currentMousePosition.y - dragStartMousePosition.y}px, 0)`;
217
+ draggedEl.style.transform = `translate3d(${currentMousePosition.x - dragStartMousePosition.x}px, ${
218
+ currentMousePosition.y - dragStartMousePosition.y
219
+ }px, 0)`;
218
220
  }
219
221
 
220
222
  function handleDrop() {