svelte-dnd-action 0.9.22 → 0.9.24
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 +12 -1
- package/dist/index.js +6 -3
- package/dist/index.mjs +6 -3
- package/package.json +1 -1
- package/src/helpers/styler.js +7 -3
package/README.md
CHANGED
|
@@ -233,7 +233,7 @@ setDebugMode(true);
|
|
|
233
233
|
### Typescript
|
|
234
234
|
|
|
235
235
|
If you are using Typescript, you will need to add the following block to your `global.d.ts` (at least until [this svelte issue](https://github.com/sveltejs/language-tools/issues/431) is resolved):
|
|
236
|
-
|
|
236
|
+
#### Svelte 3 or below
|
|
237
237
|
```typescript
|
|
238
238
|
declare type Item = import('svelte-dnd-action').Item;
|
|
239
239
|
declare type DndEvent<ItemType = Item> = import('svelte-dnd-action').DndEvent<ItemType>;
|
|
@@ -245,6 +245,17 @@ declare namespace svelte.JSX {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
```
|
|
248
|
+
#### Svelte 4:
|
|
249
|
+
```typescript
|
|
250
|
+
declare type Item = import('svelte-dnd-action').Item;
|
|
251
|
+
declare type DndEvent<ItemType = Item> = import('svelte-dnd-action').DndEvent<ItemType>;
|
|
252
|
+
declare namespace svelteHTML {
|
|
253
|
+
interface HTMLAttributes<T> {
|
|
254
|
+
'on:consider'?: (event: CustomEvent<DndEvent<ItemType>> & { target: EventTarget & T }) => void;
|
|
255
|
+
'on:finalize'?: (event: CustomEvent<DndEvent<ItemType>> & { target: EventTarget & T }) => void;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
248
259
|
|
|
249
260
|
You may need to edit `tsconfig.json` to include `global.d.ts` if it doesn't already: "include": ["src/**/*", "global.d.ts"].
|
|
250
261
|
Then you will be able to use the library with type safety as follows (Typescript gurus out there, improvements are welcome :smile:):
|
package/dist/index.js
CHANGED
|
@@ -1062,8 +1062,9 @@
|
|
|
1062
1062
|
left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
|
|
1063
1063
|
top: (currentMouseY - draggedElRect.top) / draggedElRect.height
|
|
1064
1064
|
};
|
|
1065
|
-
|
|
1066
|
-
draggedEl.style.
|
|
1065
|
+
// The lines below are commented out because of issue 454 - seems like these rect values take time to update when in grid layout, therefore this gets copied from the computed styles now
|
|
1066
|
+
// draggedEl.style.height = `${newRect.height}px`;
|
|
1067
|
+
// draggedEl.style.width = `${newRect.width}px`;
|
|
1067
1068
|
draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
|
|
1068
1069
|
draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
|
|
1069
1070
|
}
|
|
@@ -1076,7 +1077,9 @@
|
|
|
1076
1077
|
function copyStylesFromTo(copyFromEl, copyToEl) {
|
|
1077
1078
|
var computedStyle = window.getComputedStyle(copyFromEl);
|
|
1078
1079
|
Array.from(computedStyle).filter(function (s) {
|
|
1079
|
-
return s.startsWith("background") || s.startsWith("padding") || s.startsWith("font") || s.startsWith("text") || s.startsWith("align") || s.startsWith("justify") || s.startsWith("display") || s.startsWith("flex") || s.startsWith("border") || s === "opacity" || s === "color" || s === "list-style-type"
|
|
1080
|
+
return s.startsWith("background") || s.startsWith("padding") || s.startsWith("font") || s.startsWith("text") || s.startsWith("align") || s.startsWith("justify") || s.startsWith("display") || s.startsWith("flex") || s.startsWith("border") || s === "opacity" || s === "color" || s === "list-style-type" ||
|
|
1081
|
+
// copying with and height to make up for rect update timing issues in some browsers
|
|
1082
|
+
s === "width" || s === "height";
|
|
1080
1083
|
}).forEach(function (s) {
|
|
1081
1084
|
return copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s));
|
|
1082
1085
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1056,8 +1056,9 @@ function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, curre
|
|
|
1056
1056
|
left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
|
|
1057
1057
|
top: (currentMouseY - draggedElRect.top) / draggedElRect.height
|
|
1058
1058
|
};
|
|
1059
|
-
|
|
1060
|
-
draggedEl.style.
|
|
1059
|
+
// The lines below are commented out because of issue 454 - seems like these rect values take time to update when in grid layout, therefore this gets copied from the computed styles now
|
|
1060
|
+
// draggedEl.style.height = `${newRect.height}px`;
|
|
1061
|
+
// draggedEl.style.width = `${newRect.width}px`;
|
|
1061
1062
|
draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
|
|
1062
1063
|
draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
|
|
1063
1064
|
}
|
|
@@ -1070,7 +1071,9 @@ function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, curre
|
|
|
1070
1071
|
function copyStylesFromTo(copyFromEl, copyToEl) {
|
|
1071
1072
|
var computedStyle = window.getComputedStyle(copyFromEl);
|
|
1072
1073
|
Array.from(computedStyle).filter(function (s) {
|
|
1073
|
-
return s.startsWith("background") || s.startsWith("padding") || s.startsWith("font") || s.startsWith("text") || s.startsWith("align") || s.startsWith("justify") || s.startsWith("display") || s.startsWith("flex") || s.startsWith("border") || s === "opacity" || s === "color" || s === "list-style-type"
|
|
1074
|
+
return s.startsWith("background") || s.startsWith("padding") || s.startsWith("font") || s.startsWith("text") || s.startsWith("align") || s.startsWith("justify") || s.startsWith("display") || s.startsWith("flex") || s.startsWith("border") || s === "opacity" || s === "color" || s === "list-style-type" ||
|
|
1075
|
+
// copying with and height to make up for rect update timing issues in some browsers
|
|
1076
|
+
s === "width" || s === "height";
|
|
1074
1077
|
}).forEach(function (s) {
|
|
1075
1078
|
return copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s));
|
|
1076
1079
|
});
|
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dist"
|
|
44
44
|
],
|
|
45
45
|
"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 *",
|
|
46
|
-
"version": "0.9.
|
|
46
|
+
"version": "0.9.24",
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|
|
49
49
|
"url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
|
package/src/helpers/styler.js
CHANGED
|
@@ -77,8 +77,9 @@ export function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX
|
|
|
77
77
|
left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
|
|
78
78
|
top: (currentMouseY - draggedElRect.top) / draggedElRect.height
|
|
79
79
|
};
|
|
80
|
-
|
|
81
|
-
draggedEl.style.
|
|
80
|
+
// The lines below are commented out because of issue 454 - seems like these rect values take time to update when in grid layout, therefore this gets copied from the computed styles now
|
|
81
|
+
// draggedEl.style.height = `${newRect.height}px`;
|
|
82
|
+
// draggedEl.style.width = `${newRect.width}px`;
|
|
82
83
|
draggedEl.style.left = `${parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange}px`;
|
|
83
84
|
draggedEl.style.top = `${parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange}px`;
|
|
84
85
|
}
|
|
@@ -104,7 +105,10 @@ function copyStylesFromTo(copyFromEl, copyToEl) {
|
|
|
104
105
|
s.startsWith("border") ||
|
|
105
106
|
s === "opacity" ||
|
|
106
107
|
s === "color" ||
|
|
107
|
-
s === "list-style-type"
|
|
108
|
+
s === "list-style-type" ||
|
|
109
|
+
// copying with and height to make up for rect update timing issues in some browsers
|
|
110
|
+
s === "width" ||
|
|
111
|
+
s === "height"
|
|
108
112
|
)
|
|
109
113
|
.forEach(s => copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s)));
|
|
110
114
|
}
|