Skip to content

Commit 9f414bc

Browse files
committed
patch sortablejs dependency to prevent ignore clicking when using forceFallback.
1 parent 28b976e commit 9f414bc

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

dev/App.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Sortable from "../src";
2-
import { createStore } from "solid-js/store";
2+
import { createStore, reconcile } from "solid-js/store";
33
import { JSX } from "solid-js";
44

55
const App = () => {
@@ -39,7 +39,7 @@ const App = () => {
3939
idField="id"
4040
style={{ "min-height": "30px", background: "darkgray" }}
4141
items={items}
42-
setItems={setItems}
42+
setItems={(items) => setItems(reconcile(items))}
4343
>
4444
{(item) => (
4545
<div style={itemStyles}>
@@ -50,9 +50,13 @@ const App = () => {
5050
<Sortable
5151
group="test"
5252
idField="id"
53-
style={{ "min-height": "30px", background: "darkgray", "margin-top": "102px" }}
53+
style={{
54+
"min-height": "30px",
55+
background: "darkgray",
56+
"margin-top": "102px",
57+
}}
5458
items={items2}
55-
setItems={setItems2}
59+
setItems={(items) => setItems2(reconcile(items))}
5660
>
5761
{(item) => (
5862
<div style={itemStyles}>

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,10 @@
7979
},
8080
"dependencies": {
8181
"sortablejs": "^1.15.6"
82+
},
83+
"pnpm": {
84+
"patchedDependencies": {
85+
86+
}
8287
}
8388
}

patches/[email protected]

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/modular/sortable.esm.js b/modular/sortable.esm.js
2+
index 1adf24dd2c375ef6b655d3effbde01d62dc2d9d7..d8519b78421f33b9df1b42ac5e8a6d184cfb2a2c 100644
3+
--- a/modular/sortable.esm.js
4+
+++ b/modular/sortable.esm.js
5+
@@ -896,7 +896,6 @@ var dragEl,
6+
activeGroup,
7+
putSortable,
8+
awaitingDragStarted = false,
9+
- ignoreNextClick = false,
10+
sortables = [],
11+
tapEvt,
12+
touchEvt,
13+
@@ -1028,18 +1027,7 @@ var documentExists = typeof document !== 'undefined',
14+
}
15+
};
16+
17+
-// #1184 fix - Prevent click event on fallback if dragged but item not changed position
18+
-if (documentExists && !ChromeForAndroid) {
19+
- document.addEventListener('click', function (evt) {
20+
- if (ignoreNextClick) {
21+
- evt.preventDefault();
22+
- evt.stopPropagation && evt.stopPropagation();
23+
- evt.stopImmediatePropagation && evt.stopImmediatePropagation();
24+
- ignoreNextClick = false;
25+
- return false;
26+
- }
27+
- }, true);
28+
-}
29+
+
30+
var nearestEmptyInsertDetectEvent = function nearestEmptyInsertDetectEvent(evt) {
31+
if (dragEl) {
32+
evt = evt.touches ? evt.touches[0] : evt;
33+
@@ -1611,7 +1599,6 @@ Sortable.prototype = /** @lends Sortable.prototype */{
34+
35+
// Set proper drop events
36+
if (fallback) {
37+
- ignoreNextClick = true;
38+
_this._loopId = setInterval(_this._emulateDragOver, 50);
39+
} else {
40+
// Undo what was set in _prepareDragStart before drag started
41+
@@ -1756,7 +1743,6 @@ Sortable.prototype = /** @lends Sortable.prototype */{
42+
if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
43+
return completed(false);
44+
}
45+
- ignoreNextClick = false;
46+
if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
47+
: putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
48+
vertical = this._getDirection(evt, target) === 'vertical';

pnpm-lock.yaml

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export default function Sortable<T>(props: SortableProps<T>) {
200200
id={props.id}
201201
ref={sortableContainerRef}
202202
class={"sortablejs" + (ourProps.class ? ` ${ourProps.class}` : "")}
203+
style={ourProps.style}
203204
>
204205
<For each={ourProps.items}>
205206
{(item, i) => (

0 commit comments

Comments
 (0)