svelte-dnd-action 0.9.51 → 0.9.53

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
@@ -356,11 +356,13 @@
356
356
  /**
357
357
  * Gets the bounding rect but removes transforms (ex: flip animation)
358
358
  * @param {HTMLElement} el
359
+ * @param {boolean} [onlyVisible] - use the visible rect defaults to true
359
360
  * @return {{top: number, left: number, bottom: number, right: number}}
360
361
  */
361
362
  function getBoundingRectNoTransforms(el) {
363
+ var onlyVisible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
362
364
  var ta;
363
- var rect = el.getBoundingClientRect();
365
+ var rect = onlyVisible ? getVisibleRectRecursive(el) : el.getBoundingClientRect();
364
366
  var style = getComputedStyle(el);
365
367
  var tx = style.transform;
366
368
  if (tx) {
@@ -507,6 +509,54 @@
507
509
  var rect = getAbsoluteRect(el);
508
510
  return rect.right < 0 || rect.left > document.documentElement.scrollWidth || rect.bottom < 0 || rect.top > document.documentElement.scrollHeight;
509
511
  }
512
+ function getVisibleRectRecursive(element) {
513
+ var rect = element.getBoundingClientRect();
514
+ var visibleRect = {
515
+ top: rect.top,
516
+ bottom: rect.bottom,
517
+ left: rect.left,
518
+ right: rect.right
519
+ };
520
+
521
+ // Traverse up the DOM hierarchy, checking for scrollable ancestors
522
+ var parent = element.parentElement;
523
+ while (parent && parent !== document.body) {
524
+ var parentRect = parent.getBoundingClientRect();
525
+
526
+ // Check if the parent has a scrollable overflow
527
+ var overflowY = window.getComputedStyle(parent).overflowY;
528
+ var overflowX = window.getComputedStyle(parent).overflowX;
529
+ var isScrollableY = overflowY === "scroll" || overflowY === "auto";
530
+ var isScrollableX = overflowX === "scroll" || overflowX === "auto";
531
+
532
+ // Constrain the visible area to the parent's visible area
533
+ if (isScrollableY) {
534
+ visibleRect.top = Math.max(visibleRect.top, parentRect.top);
535
+ visibleRect.bottom = Math.min(visibleRect.bottom, parentRect.bottom);
536
+ }
537
+ if (isScrollableX) {
538
+ visibleRect.left = Math.max(visibleRect.left, parentRect.left);
539
+ visibleRect.right = Math.min(visibleRect.right, parentRect.right);
540
+ }
541
+ parent = parent.parentElement;
542
+ }
543
+
544
+ // Finally, constrain the visible rect to the viewport
545
+ visibleRect.top = Math.max(visibleRect.top, 0);
546
+ visibleRect.bottom = Math.min(visibleRect.bottom, window.innerHeight);
547
+ visibleRect.left = Math.max(visibleRect.left, 0);
548
+ visibleRect.right = Math.min(visibleRect.right, window.innerWidth);
549
+
550
+ // Return the visible rectangle, ensuring that all values are valid
551
+ return {
552
+ top: visibleRect.top,
553
+ bottom: visibleRect.bottom,
554
+ left: visibleRect.left,
555
+ right: visibleRect.right,
556
+ width: Math.max(0, visibleRect.right - visibleRect.left),
557
+ height: Math.max(0, visibleRect.bottom - visibleRect.top)
558
+ };
559
+ }
510
560
 
511
561
  var dzToShadowIndexToRect;
512
562
 
@@ -1382,8 +1432,11 @@
1382
1432
  _iterator2.f();
1383
1433
  }
1384
1434
  window.removeEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop$1);
1385
- multiScroller.destroy();
1386
- multiScroller = undefined;
1435
+ // ensuring multiScroller is not already destroyed before destroying
1436
+ if (multiScroller) {
1437
+ multiScroller.destroy();
1438
+ multiScroller = undefined;
1439
+ }
1387
1440
  unobserve();
1388
1441
  }
1389
1442
  function findShadowElementIdx(items) {
@@ -1592,7 +1645,7 @@
1592
1645
 
1593
1646
  // helper function for handleDrop
1594
1647
  function animateDraggedToFinalPosition(shadowElIdx, callback) {
1595
- var shadowElRect = shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]) : getBoundingRectNoTransforms(shadowElDropZone);
1648
+ var shadowElRect = shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx], false) : getBoundingRectNoTransforms(shadowElDropZone, false);
1596
1649
  var newTransform = {
1597
1650
  x: shadowElRect.left - parseFloat(draggedEl.style.left),
1598
1651
  y: shadowElRect.top - parseFloat(draggedEl.style.top)
package/dist/index.mjs CHANGED
@@ -350,11 +350,13 @@ function setDebugMode(isDebug) {
350
350
  /**
351
351
  * Gets the bounding rect but removes transforms (ex: flip animation)
352
352
  * @param {HTMLElement} el
353
+ * @param {boolean} [onlyVisible] - use the visible rect defaults to true
353
354
  * @return {{top: number, left: number, bottom: number, right: number}}
354
355
  */
355
356
  function getBoundingRectNoTransforms(el) {
357
+ var onlyVisible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
356
358
  var ta;
357
- var rect = el.getBoundingClientRect();
359
+ var rect = onlyVisible ? getVisibleRectRecursive(el) : el.getBoundingClientRect();
358
360
  var style = getComputedStyle(el);
359
361
  var tx = style.transform;
360
362
  if (tx) {
@@ -501,6 +503,54 @@ function isElementOffDocument(el) {
501
503
  var rect = getAbsoluteRect(el);
502
504
  return rect.right < 0 || rect.left > document.documentElement.scrollWidth || rect.bottom < 0 || rect.top > document.documentElement.scrollHeight;
503
505
  }
506
+ function getVisibleRectRecursive(element) {
507
+ var rect = element.getBoundingClientRect();
508
+ var visibleRect = {
509
+ top: rect.top,
510
+ bottom: rect.bottom,
511
+ left: rect.left,
512
+ right: rect.right
513
+ };
514
+
515
+ // Traverse up the DOM hierarchy, checking for scrollable ancestors
516
+ var parent = element.parentElement;
517
+ while (parent && parent !== document.body) {
518
+ var parentRect = parent.getBoundingClientRect();
519
+
520
+ // Check if the parent has a scrollable overflow
521
+ var overflowY = window.getComputedStyle(parent).overflowY;
522
+ var overflowX = window.getComputedStyle(parent).overflowX;
523
+ var isScrollableY = overflowY === "scroll" || overflowY === "auto";
524
+ var isScrollableX = overflowX === "scroll" || overflowX === "auto";
525
+
526
+ // Constrain the visible area to the parent's visible area
527
+ if (isScrollableY) {
528
+ visibleRect.top = Math.max(visibleRect.top, parentRect.top);
529
+ visibleRect.bottom = Math.min(visibleRect.bottom, parentRect.bottom);
530
+ }
531
+ if (isScrollableX) {
532
+ visibleRect.left = Math.max(visibleRect.left, parentRect.left);
533
+ visibleRect.right = Math.min(visibleRect.right, parentRect.right);
534
+ }
535
+ parent = parent.parentElement;
536
+ }
537
+
538
+ // Finally, constrain the visible rect to the viewport
539
+ visibleRect.top = Math.max(visibleRect.top, 0);
540
+ visibleRect.bottom = Math.min(visibleRect.bottom, window.innerHeight);
541
+ visibleRect.left = Math.max(visibleRect.left, 0);
542
+ visibleRect.right = Math.min(visibleRect.right, window.innerWidth);
543
+
544
+ // Return the visible rectangle, ensuring that all values are valid
545
+ return {
546
+ top: visibleRect.top,
547
+ bottom: visibleRect.bottom,
548
+ left: visibleRect.left,
549
+ right: visibleRect.right,
550
+ width: Math.max(0, visibleRect.right - visibleRect.left),
551
+ height: Math.max(0, visibleRect.bottom - visibleRect.top)
552
+ };
553
+ }
504
554
 
505
555
  var dzToShadowIndexToRect;
506
556
 
@@ -1376,8 +1426,11 @@ function unWatchDraggedElement() {
1376
1426
  _iterator2.f();
1377
1427
  }
1378
1428
  window.removeEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop$1);
1379
- multiScroller.destroy();
1380
- multiScroller = undefined;
1429
+ // ensuring multiScroller is not already destroyed before destroying
1430
+ if (multiScroller) {
1431
+ multiScroller.destroy();
1432
+ multiScroller = undefined;
1433
+ }
1381
1434
  unobserve();
1382
1435
  }
1383
1436
  function findShadowElementIdx(items) {
@@ -1586,7 +1639,7 @@ function handleDrop$1() {
1586
1639
 
1587
1640
  // helper function for handleDrop
1588
1641
  function animateDraggedToFinalPosition(shadowElIdx, callback) {
1589
- var shadowElRect = shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]) : getBoundingRectNoTransforms(shadowElDropZone);
1642
+ var shadowElRect = shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx], false) : getBoundingRectNoTransforms(shadowElDropZone, false);
1590
1643
  var newTransform = {
1591
1644
  x: shadowElRect.left - parseFloat(draggedEl.style.left),
1592
1645
  y: shadowElRect.top - parseFloat(draggedEl.style.top)
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.51",
4
+ "version": "0.9.53",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
@@ -3,11 +3,12 @@
3
3
  /**
4
4
  * Gets the bounding rect but removes transforms (ex: flip animation)
5
5
  * @param {HTMLElement} el
6
+ * @param {boolean} [onlyVisible] - use the visible rect defaults to true
6
7
  * @return {{top: number, left: number, bottom: number, right: number}}
7
8
  */
8
- export function getBoundingRectNoTransforms(el) {
9
+ export function getBoundingRectNoTransforms(el, onlyVisible = true) {
9
10
  let ta;
10
- const rect = el.getBoundingClientRect();
11
+ const rect = onlyVisible ? getVisibleRectRecursive(el) : el.getBoundingClientRect();
11
12
  const style = getComputedStyle(el);
12
13
  const tx = style.transform;
13
14
 
@@ -156,3 +157,53 @@ export function isElementOffDocument(el) {
156
157
  const rect = getAbsoluteRect(el);
157
158
  return rect.right < 0 || rect.left > document.documentElement.scrollWidth || rect.bottom < 0 || rect.top > document.documentElement.scrollHeight;
158
159
  }
160
+
161
+ function getVisibleRectRecursive(element) {
162
+ let rect = element.getBoundingClientRect();
163
+ let visibleRect = {
164
+ top: rect.top,
165
+ bottom: rect.bottom,
166
+ left: rect.left,
167
+ right: rect.right
168
+ };
169
+
170
+ // Traverse up the DOM hierarchy, checking for scrollable ancestors
171
+ let parent = element.parentElement;
172
+ while (parent && parent !== document.body) {
173
+ let parentRect = parent.getBoundingClientRect();
174
+
175
+ // Check if the parent has a scrollable overflow
176
+ const overflowY = window.getComputedStyle(parent).overflowY;
177
+ const overflowX = window.getComputedStyle(parent).overflowX;
178
+ const isScrollableY = overflowY === "scroll" || overflowY === "auto";
179
+ const isScrollableX = overflowX === "scroll" || overflowX === "auto";
180
+
181
+ // Constrain the visible area to the parent's visible area
182
+ if (isScrollableY) {
183
+ visibleRect.top = Math.max(visibleRect.top, parentRect.top);
184
+ visibleRect.bottom = Math.min(visibleRect.bottom, parentRect.bottom);
185
+ }
186
+ if (isScrollableX) {
187
+ visibleRect.left = Math.max(visibleRect.left, parentRect.left);
188
+ visibleRect.right = Math.min(visibleRect.right, parentRect.right);
189
+ }
190
+
191
+ parent = parent.parentElement;
192
+ }
193
+
194
+ // Finally, constrain the visible rect to the viewport
195
+ visibleRect.top = Math.max(visibleRect.top, 0);
196
+ visibleRect.bottom = Math.min(visibleRect.bottom, window.innerHeight);
197
+ visibleRect.left = Math.max(visibleRect.left, 0);
198
+ visibleRect.right = Math.min(visibleRect.right, window.innerWidth);
199
+
200
+ // Return the visible rectangle, ensuring that all values are valid
201
+ return {
202
+ top: visibleRect.top,
203
+ bottom: visibleRect.bottom,
204
+ left: visibleRect.left,
205
+ right: visibleRect.right,
206
+ width: Math.max(0, visibleRect.right - visibleRect.left),
207
+ height: Math.max(0, visibleRect.bottom - visibleRect.top)
208
+ };
209
+ }
@@ -113,8 +113,11 @@ function unWatchDraggedElement() {
113
113
  dz.removeEventListener(DRAGGED_OVER_INDEX_EVENT_NAME, handleDraggedIsOverIndex);
114
114
  }
115
115
  window.removeEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop);
116
- multiScroller.destroy();
117
- multiScroller = undefined;
116
+ // ensuring multiScroller is not already destroyed before destroying
117
+ if(multiScroller) {
118
+ multiScroller.destroy();
119
+ multiScroller = undefined;
120
+ }
118
121
  unobserve();
119
122
  }
120
123
 
@@ -281,7 +284,9 @@ function handleDrop() {
281
284
  // helper function for handleDrop
282
285
  function animateDraggedToFinalPosition(shadowElIdx, callback) {
283
286
  const shadowElRect =
284
- shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]) : getBoundingRectNoTransforms(shadowElDropZone);
287
+ shadowElIdx > -1
288
+ ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx], false)
289
+ : getBoundingRectNoTransforms(shadowElDropZone, false);
285
290
  const newTransform = {
286
291
  x: shadowElRect.left - parseFloat(draggedEl.style.left),
287
292
  y: shadowElRect.top - parseFloat(draggedEl.style.top)