svelte-dnd-action 0.9.72 → 0.9.73

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
@@ -1186,6 +1186,21 @@
1186
1186
  function trs(property) {
1187
1187
  return "".concat(property, " ").concat(TRANSITION_DURATION_SECONDS, "s ease");
1188
1188
  }
1189
+
1190
+ /**
1191
+ * Adds the size transitions after the dragged element's initial styles have been applied.
1192
+ * This normally happens in a timeout to avoid a browser rendering bug, but a synchronous
1193
+ * first morph can happen before that timeout and needs the transitions immediately.
1194
+ * @param {HTMLElement} draggedEl
1195
+ */
1196
+ function ensureMorphSizeTransitions(draggedEl) {
1197
+ var transitionProperties = draggedEl.style.transitionProperty.split(",").map(function (property) {
1198
+ return property.trim();
1199
+ });
1200
+ if (transitionProperties.includes("all")) return;
1201
+ if (!transitionProperties.includes("width")) draggedEl.style.transition += ", ".concat(trs("width"));
1202
+ if (!transitionProperties.includes("height")) draggedEl.style.transition += ", ".concat(trs("height"));
1203
+ }
1189
1204
  /**
1190
1205
  * clones the given element and applies proper styles and transitions to the dragged element
1191
1206
  * @param {HTMLElement} originalElement
@@ -1219,7 +1234,7 @@
1219
1234
  draggedEl.style.transition = "".concat(trs("top"), ", ").concat(trs("left"), ", ").concat(trs("background-color"), ", ").concat(trs("opacity"), ", ").concat(trs("color"), " ");
1220
1235
  // this is a workaround for a strange browser bug that causes the right border to disappear when all the transitions are added at the same time
1221
1236
  window.setTimeout(function () {
1222
- return draggedEl.style.transition += ", ".concat(trs("width"), ", ").concat(trs("height"));
1237
+ return ensureMorphSizeTransitions(draggedEl);
1223
1238
  }, 0);
1224
1239
  draggedEl.style.zIndex = "9999";
1225
1240
  draggedEl.style.cursor = "grabbing";
@@ -1242,22 +1257,26 @@
1242
1257
  * @param {number} currentMouseY
1243
1258
  */
1244
1259
  function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, currentMouseY) {
1260
+ ensureMorphSizeTransitions(draggedEl);
1245
1261
  copyStylesFromTo(copyFromEl, draggedEl);
1246
1262
  var newRect = copyFromEl.getBoundingClientRect();
1247
1263
  var draggedElRect = draggedEl.getBoundingClientRect();
1264
+ var draggedElComputedStyle = window.getComputedStyle(draggedEl);
1265
+ var currentLeft = parseFloat(draggedElComputedStyle.left);
1266
+ var currentTop = parseFloat(draggedElComputedStyle.top);
1248
1267
  var widthChange = newRect.width - draggedElRect.width;
1249
1268
  var heightChange = newRect.height - draggedElRect.height;
1250
1269
  if (widthChange || heightChange) {
1251
1270
  var relativeDistanceOfMousePointerFromDraggedSides = {
1252
- left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
1253
- top: (currentMouseY - draggedElRect.top) / draggedElRect.height
1271
+ left: draggedElRect.width ? (currentMouseX - draggedElRect.left) / draggedElRect.width : 0,
1272
+ top: draggedElRect.height ? (currentMouseY - draggedElRect.top) / draggedElRect.height : 0
1254
1273
  };
1255
1274
  if (!getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT)) {
1256
1275
  draggedEl.style.height = "".concat(newRect.height, "px");
1257
1276
  draggedEl.style.width = "".concat(newRect.width, "px");
1258
1277
  }
1259
- draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
1260
- draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
1278
+ draggedEl.style.left = "".concat(currentLeft - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
1279
+ draggedEl.style.top = "".concat(currentTop - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
1261
1280
  }
1262
1281
  }
1263
1282
 
package/dist/index.mjs CHANGED
@@ -1180,6 +1180,21 @@ var TRANSITION_DURATION_SECONDS = 0.2;
1180
1180
  function trs(property) {
1181
1181
  return "".concat(property, " ").concat(TRANSITION_DURATION_SECONDS, "s ease");
1182
1182
  }
1183
+
1184
+ /**
1185
+ * Adds the size transitions after the dragged element's initial styles have been applied.
1186
+ * This normally happens in a timeout to avoid a browser rendering bug, but a synchronous
1187
+ * first morph can happen before that timeout and needs the transitions immediately.
1188
+ * @param {HTMLElement} draggedEl
1189
+ */
1190
+ function ensureMorphSizeTransitions(draggedEl) {
1191
+ var transitionProperties = draggedEl.style.transitionProperty.split(",").map(function (property) {
1192
+ return property.trim();
1193
+ });
1194
+ if (transitionProperties.includes("all")) return;
1195
+ if (!transitionProperties.includes("width")) draggedEl.style.transition += ", ".concat(trs("width"));
1196
+ if (!transitionProperties.includes("height")) draggedEl.style.transition += ", ".concat(trs("height"));
1197
+ }
1183
1198
  /**
1184
1199
  * clones the given element and applies proper styles and transitions to the dragged element
1185
1200
  * @param {HTMLElement} originalElement
@@ -1213,7 +1228,7 @@ function createDraggedElementFrom(originalElement, positionCenterOnXY) {
1213
1228
  draggedEl.style.transition = "".concat(trs("top"), ", ").concat(trs("left"), ", ").concat(trs("background-color"), ", ").concat(trs("opacity"), ", ").concat(trs("color"), " ");
1214
1229
  // this is a workaround for a strange browser bug that causes the right border to disappear when all the transitions are added at the same time
1215
1230
  window.setTimeout(function () {
1216
- return draggedEl.style.transition += ", ".concat(trs("width"), ", ").concat(trs("height"));
1231
+ return ensureMorphSizeTransitions(draggedEl);
1217
1232
  }, 0);
1218
1233
  draggedEl.style.zIndex = "9999";
1219
1234
  draggedEl.style.cursor = "grabbing";
@@ -1236,22 +1251,26 @@ function moveDraggedElementToWasDroppedState(draggedEl) {
1236
1251
  * @param {number} currentMouseY
1237
1252
  */
1238
1253
  function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, currentMouseY) {
1254
+ ensureMorphSizeTransitions(draggedEl);
1239
1255
  copyStylesFromTo(copyFromEl, draggedEl);
1240
1256
  var newRect = copyFromEl.getBoundingClientRect();
1241
1257
  var draggedElRect = draggedEl.getBoundingClientRect();
1258
+ var draggedElComputedStyle = window.getComputedStyle(draggedEl);
1259
+ var currentLeft = parseFloat(draggedElComputedStyle.left);
1260
+ var currentTop = parseFloat(draggedElComputedStyle.top);
1242
1261
  var widthChange = newRect.width - draggedElRect.width;
1243
1262
  var heightChange = newRect.height - draggedElRect.height;
1244
1263
  if (widthChange || heightChange) {
1245
1264
  var relativeDistanceOfMousePointerFromDraggedSides = {
1246
- left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
1247
- top: (currentMouseY - draggedElRect.top) / draggedElRect.height
1265
+ left: draggedElRect.width ? (currentMouseX - draggedElRect.left) / draggedElRect.width : 0,
1266
+ top: draggedElRect.height ? (currentMouseY - draggedElRect.top) / draggedElRect.height : 0
1248
1267
  };
1249
1268
  if (!getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT)) {
1250
1269
  draggedEl.style.height = "".concat(newRect.height, "px");
1251
1270
  draggedEl.style.width = "".concat(newRect.width, "px");
1252
1271
  }
1253
- draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
1254
- draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
1272
+ draggedEl.style.left = "".concat(currentLeft - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
1273
+ draggedEl.style.top = "".concat(currentTop - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
1255
1274
  }
1256
1275
  }
1257
1276
 
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.72",
4
+ "version": "0.9.73",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
@@ -13,6 +13,19 @@ const TRANSITION_DURATION_SECONDS = 0.2;
13
13
  function trs(property) {
14
14
  return `${property} ${TRANSITION_DURATION_SECONDS}s ease`;
15
15
  }
16
+
17
+ /**
18
+ * Adds the size transitions after the dragged element's initial styles have been applied.
19
+ * This normally happens in a timeout to avoid a browser rendering bug, but a synchronous
20
+ * first morph can happen before that timeout and needs the transitions immediately.
21
+ * @param {HTMLElement} draggedEl
22
+ */
23
+ function ensureMorphSizeTransitions(draggedEl) {
24
+ const transitionProperties = draggedEl.style.transitionProperty.split(",").map(property => property.trim());
25
+ if (transitionProperties.includes("all")) return;
26
+ if (!transitionProperties.includes("width")) draggedEl.style.transition += `, ${trs("width")}`;
27
+ if (!transitionProperties.includes("height")) draggedEl.style.transition += `, ${trs("height")}`;
28
+ }
16
29
  /**
17
30
  * clones the given element and applies proper styles and transitions to the dragged element
18
31
  * @param {HTMLElement} originalElement
@@ -45,7 +58,7 @@ export function createDraggedElementFrom(originalElement, positionCenterOnXY) {
45
58
  draggedEl.style.width = `${rect.width}px`;
46
59
  draggedEl.style.transition = `${trs("top")}, ${trs("left")}, ${trs("background-color")}, ${trs("opacity")}, ${trs("color")} `;
47
60
  // this is a workaround for a strange browser bug that causes the right border to disappear when all the transitions are added at the same time
48
- window.setTimeout(() => (draggedEl.style.transition += `, ${trs("width")}, ${trs("height")}`), 0);
61
+ window.setTimeout(() => ensureMorphSizeTransitions(draggedEl), 0);
49
62
  draggedEl.style.zIndex = "9999";
50
63
  draggedEl.style.cursor = "grabbing";
51
64
 
@@ -68,22 +81,26 @@ export function moveDraggedElementToWasDroppedState(draggedEl) {
68
81
  * @param {number} currentMouseY
69
82
  */
70
83
  export function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, currentMouseY) {
84
+ ensureMorphSizeTransitions(draggedEl);
71
85
  copyStylesFromTo(copyFromEl, draggedEl);
72
86
  const newRect = copyFromEl.getBoundingClientRect();
73
87
  const draggedElRect = draggedEl.getBoundingClientRect();
88
+ const draggedElComputedStyle = window.getComputedStyle(draggedEl);
89
+ const currentLeft = parseFloat(draggedElComputedStyle.left);
90
+ const currentTop = parseFloat(draggedElComputedStyle.top);
74
91
  const widthChange = newRect.width - draggedElRect.width;
75
92
  const heightChange = newRect.height - draggedElRect.height;
76
93
  if (widthChange || heightChange) {
77
94
  const relativeDistanceOfMousePointerFromDraggedSides = {
78
- left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
79
- top: (currentMouseY - draggedElRect.top) / draggedElRect.height
95
+ left: draggedElRect.width ? (currentMouseX - draggedElRect.left) / draggedElRect.width : 0,
96
+ top: draggedElRect.height ? (currentMouseY - draggedElRect.top) / draggedElRect.height : 0
80
97
  };
81
98
  if (!getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT)) {
82
99
  draggedEl.style.height = `${newRect.height}px`;
83
100
  draggedEl.style.width = `${newRect.width}px`;
84
101
  }
85
- draggedEl.style.left = `${parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange}px`;
86
- draggedEl.style.top = `${parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange}px`;
102
+ draggedEl.style.left = `${currentLeft - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange}px`;
103
+ draggedEl.style.top = `${currentTop - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange}px`;
87
104
  }
88
105
  }
89
106