svelte-dnd-action 0.9.21 → 0.9.23
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 +22 -22
- package/dist/index.js +6 -3
- package/dist/index.mjs +6 -3
- package/package.json +4 -1
- package/src/helpers/styler.js +7 -3
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ See full features list below. <br />
|
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
9
|
-
[Play with this example in the REPL](https://svelte.dev/repl/e2ef044af75c4b16b424b8219fb31fd9?version=3
|
|
9
|
+
[Play with this example in the REPL](https://svelte.dev/repl/e2ef044af75c4b16b424b8219fb31fd9?version=3).
|
|
10
10
|
|
|
11
11
|
### Current Status
|
|
12
12
|
|
|
@@ -30,11 +30,11 @@ It is being actively maintained.
|
|
|
30
30
|
### Why a svelte action rather than a higher order component?
|
|
31
31
|
|
|
32
32
|
A custom action allows for a much more elegant API (no slot props thanks god) as well as more control. <br />
|
|
33
|
-
If you prefer a generic dnd list component that accepts different child components as your abstraction, you can very easily wrap this library with one (see [here](https://svelte.dev/repl/028674733f67409c94bd52995d5906f1?version=3
|
|
33
|
+
If you prefer a generic dnd list component that accepts different child components as your abstraction, you can very easily wrap this library with one (see [here](https://svelte.dev/repl/028674733f67409c94bd52995d5906f1?version=3)).
|
|
34
34
|
|
|
35
35
|
### Installation
|
|
36
36
|
|
|
37
|
-
**Pre-requisites**: svelte-3
|
|
37
|
+
**Pre-requisites**: svelte-3 (>=3.23.0)
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
40
|
yarn add -D svelte-dnd-action
|
|
@@ -123,7 +123,7 @@ An options-object with the following attributes:
|
|
|
123
123
|
The action dispatches two custom events:
|
|
124
124
|
|
|
125
125
|
- `consider` - dispatched whenever the dragged element needs to make room for itself in a new position in the items list and when it leaves. The host (your component) is expected to update the items list (you can keep a copy of the original list if you need to)
|
|
126
|
-
- `finalize` - dispatched on the target and origin dnd-zones when the dragged element is dropped into position. This is the event you want to use to [save the items to the server](https://svelte.dev/repl/964fdac31cb9496da9ded35002300abb?version=3
|
|
126
|
+
- `finalize` - dispatched on the target and origin dnd-zones when the dragged element is dropped into position. This is the event you want to use to [save the items to the server](https://svelte.dev/repl/964fdac31cb9496da9ded35002300abb?version=3) for example.
|
|
127
127
|
|
|
128
128
|
The expectation is the same for both event handlers - update the list of items.
|
|
129
129
|
In both cases the payload (within e.detail) is the same: an object with two attributes: `items` and `info`.
|
|
@@ -137,7 +137,7 @@ In both cases the payload (within e.detail) is the same: an object with two attr
|
|
|
137
137
|
You have to listen for both events and update the list of items in order for this library to work correctly.
|
|
138
138
|
|
|
139
139
|
For advanced use-cases (ex: [custom styling for the placeholder element](https://svelte.dev/repl/9c8db8b91b2142d19dcf9bc963a27838?version=3)) you might also need to import `SHADOW_ITEM_MARKER_PROPERTY_NAME`, which marks the placeholder element that is temporarily added to the list the dragged element hovers over.
|
|
140
|
-
For use cases that have recursively nested zones (ex: [crazy nesting](https://svelte.dev/repl/fe8c9eca04f9417a94a8b6041df77139?version=3
|
|
140
|
+
For use cases that have recursively nested zones (ex: [crazy nesting](https://svelte.dev/repl/fe8c9eca04f9417a94a8b6041df77139?version=3)), you might want to import `SHADOW_PLACEHOLDER_ITEM_ID` in order to filter the placeholder out when passing the items in to the nested component.
|
|
141
141
|
If you need to manipulate the dragged element either dynamically (and don't want to use the `transformDraggedElement` option), or statically targeting it or its children with CSS, you can import and use `DRAGGED_ELEMENT_ID`;
|
|
142
142
|
|
|
143
143
|
### Accessibility (beta)
|
|
@@ -156,7 +156,7 @@ For example:
|
|
|
156
156
|
|
|
157
157
|
If you don't provide the aria-labels everything will still work, but the messages to the user will be less informative.
|
|
158
158
|
_Note_: in general you probably want to use semantic-html (ex: `ol` and `li` elements rather than `section` and `div`) but the library is screen readers friendly regardless (or at least that's the goal :)).
|
|
159
|
-
If you want to implement your own custom screen-reader alerts, roles and instructions, you can use the `autoAriaDisabled` options and wire everything up yourself using markup and the `consider` and `finalize` handlers (for example: [unsortable list](https://svelte.dev/repl/e020ea1051dc4ae3ac2b697064f234bc?version=3
|
|
159
|
+
If you want to implement your own custom screen-reader alerts, roles and instructions, you can use the `autoAriaDisabled` options and wire everything up yourself using markup and the `consider` and `finalize` handlers (for example: [unsortable list](https://svelte.dev/repl/e020ea1051dc4ae3ac2b697064f234bc?version=3)).
|
|
160
160
|
|
|
161
161
|
##### Keyboard support
|
|
162
162
|
|
|
@@ -171,28 +171,28 @@ If you want to implement your own custom screen-reader alerts, roles and instruc
|
|
|
171
171
|
|
|
172
172
|
### Examples and Recipes
|
|
173
173
|
|
|
174
|
-
- [Super basic, single list, no animation](https://svelte.dev/repl/bbd709b1a00b453e94658392c97a018a?version=3
|
|
175
|
-
- [Super basic, single list, with animation](https://svelte.dev/repl/3d544791e5c24fd4aa1eb983d749f776?version=3
|
|
176
|
-
- [Multiple dndzones, multiple types](https://svelte.dev/repl/4d23eb3b9e184b90b58f0867010ad258?version=3
|
|
177
|
-
- [Board (nested zones and multiple types), scrolling containers, scrolling page](https://svelte.dev/repl/e2ef044af75c4b16b424b8219fb31fd9?version=3
|
|
174
|
+
- [Super basic, single list, no animation](https://svelte.dev/repl/bbd709b1a00b453e94658392c97a018a?version=3)
|
|
175
|
+
- [Super basic, single list, with animation](https://svelte.dev/repl/3d544791e5c24fd4aa1eb983d749f776?version=3)
|
|
176
|
+
- [Multiple dndzones, multiple types](https://svelte.dev/repl/4d23eb3b9e184b90b58f0867010ad258?version=3)
|
|
177
|
+
- [Board (nested zones and multiple types), scrolling containers, scrolling page](https://svelte.dev/repl/e2ef044af75c4b16b424b8219fb31fd9?version=3)
|
|
178
178
|
- [Selectively enable/disable drag/drop](https://svelte.dev/repl/44c9229556f3456e9883c10fc0aa0ee9?version=3)
|
|
179
|
-
- [Custom active dropzone styling](https://svelte.dev/repl/4ceecc5bae54490b811bd62d4d613e59?version=3
|
|
179
|
+
- [Custom active dropzone styling](https://svelte.dev/repl/4ceecc5bae54490b811bd62d4d613e59?version=3)
|
|
180
180
|
- [Customizing the dragged element](https://svelte.dev/repl/438fca28bb1f4eb1b34eff9dc6a728dc?version=3)
|
|
181
|
-
- [Styling the dragged element](https://svelte.dev/repl/3d8be94b2bbd407c8a706d5054c8df6a?version=3
|
|
181
|
+
- [Styling the dragged element](https://svelte.dev/repl/3d8be94b2bbd407c8a706d5054c8df6a?version=3)
|
|
182
182
|
- [Customizing the placeholder(shadow) element](https://svelte.dev/repl/9c8db8b91b2142d19dcf9bc963a27838?version=3)
|
|
183
183
|
|
|
184
|
-
- [Copy on drag, simple and Dragula like](https://svelte.dev/repl/924b4cc920524065a637fa910fe10193?version=3
|
|
185
|
-
- [Drag handles](https://svelte.dev/repl/4949485c5a8f46e7bdbeb73ed565a9c7?version=3
|
|
186
|
-
- [Interaction (save/get items) with an asynchronous server](https://svelte.dev/repl/964fdac31cb9496da9ded35002300abb?version=3
|
|
187
|
-
- [Unsortable lists with custom aria instructions](https://svelte.dev/repl/e020ea1051dc4ae3ac2b697064f234bc?version=3
|
|
184
|
+
- [Copy on drag, simple and Dragula like](https://svelte.dev/repl/924b4cc920524065a637fa910fe10193?version=3)
|
|
185
|
+
- [Drag handles](https://svelte.dev/repl/4949485c5a8f46e7bdbeb73ed565a9c7?version=3), courtesy of @gleuch
|
|
186
|
+
- [Interaction (save/get items) with an asynchronous server](https://svelte.dev/repl/964fdac31cb9496da9ded35002300abb?version=3)
|
|
187
|
+
- [Unsortable lists with custom aria instructions](https://svelte.dev/repl/e020ea1051dc4ae3ac2b697064f234bc?version=3)
|
|
188
188
|
- [Crazy nesting](https://svelte.dev/repl/fe8c9eca04f9417a94a8b6041df77139?version=3), courtesy of @zahachtah
|
|
189
|
-
- [Generic List Component (Alternative to Slots)](https://svelte.dev/repl/028674733f67409c94bd52995d5906f1?version=3
|
|
190
|
-
- [Maitaining internal scroll poisition on scrollable dragabble](https://svelte.dev/repl/eb2f5988bd2f46488810606c1fb13392?version=3
|
|
191
|
-
- [Scrabble like board using over a 100 single slot dnd-zones](https://svelte.dev/repl/ed2e138417094281be6db1aef23d7859?version=3
|
|
192
|
-
- [Select multiple elements to drag (multi-drag) with mouse or keyboard](https://svelte.dev/repl/c4eb917bb8df42c4b17402a7dda54856?version=3
|
|
189
|
+
- [Generic List Component (Alternative to Slots)](https://svelte.dev/repl/028674733f67409c94bd52995d5906f1?version=3)
|
|
190
|
+
- [Maitaining internal scroll poisition on scrollable dragabble](https://svelte.dev/repl/eb2f5988bd2f46488810606c1fb13392?version=3)
|
|
191
|
+
- [Scrabble like board using over a 100 single slot dnd-zones](https://svelte.dev/repl/ed2e138417094281be6db1aef23d7859?version=3)
|
|
192
|
+
- [Select multiple elements to drag (multi-drag) with mouse or keyboard](https://svelte.dev/repl/c4eb917bb8df42c4b17402a7dda54856?version=3)
|
|
193
193
|
|
|
194
|
-
- [Fade in/out but without using Svelte transitions](https://svelte.dev/repl/3f1e68203ef140969a8240eba3475a8d?version=3
|
|
195
|
-
- [Nested fade in/out without using Svelte transitions](https://svelte.dev/repl/49b09aedfe0543b4bc8f575c8dbf9a53?version=3
|
|
194
|
+
- [Fade in/out but without using Svelte transitions](https://svelte.dev/repl/3f1e68203ef140969a8240eba3475a8d?version=3)
|
|
195
|
+
- [Nested fade in/out without using Svelte transitions](https://svelte.dev/repl/49b09aedfe0543b4bc8f575c8dbf9a53?version=3)
|
|
196
196
|
|
|
197
197
|
### Rules/ assumptions to keep in mind
|
|
198
198
|
|
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
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"rollup-plugin-babel": "^4.3.2",
|
|
27
27
|
"rollup-plugin-copy": "^3.3.0"
|
|
28
28
|
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"svelte": ">=3.23.0"
|
|
31
|
+
},
|
|
29
32
|
"keywords": [
|
|
30
33
|
"svelte",
|
|
31
34
|
"drag and drop",
|
|
@@ -40,7 +43,7 @@
|
|
|
40
43
|
"dist"
|
|
41
44
|
],
|
|
42
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 *",
|
|
43
|
-
"version": "0.9.
|
|
46
|
+
"version": "0.9.23",
|
|
44
47
|
"repository": {
|
|
45
48
|
"type": "git",
|
|
46
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
|
}
|