@fr0st/ui-sortable 3.0.0 → 3.0.1
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 +96 -83
- package/dist/frost-ui-sortable.esm.js +25 -16
- package/dist/frost-ui-sortable.esm.js.map +1 -1
- package/dist/frost-ui-sortable.esm.min.js +1 -1
- package/dist/frost-ui-sortable.esm.min.js.map +1 -1
- package/dist/frost-ui-sortable.js +25 -16
- package/dist/frost-ui-sortable.js.map +1 -1
- package/dist/frost-ui-sortable.min.js +1 -1
- package/dist/frost-ui-sortable.min.js.map +1 -1
- package/package.json +7 -7
- package/src/helpers.js +3 -3
- package/src/sortable.js +34 -24
package/src/sortable.js
CHANGED
|
@@ -59,6 +59,7 @@ export default class Sortable extends BaseComponent {
|
|
|
59
59
|
#currentSortable;
|
|
60
60
|
#dragging;
|
|
61
61
|
#enabled;
|
|
62
|
+
#initialCursorNodes = [];
|
|
62
63
|
#pos;
|
|
63
64
|
#scrollFrame;
|
|
64
65
|
#selector;
|
|
@@ -73,15 +74,22 @@ export default class Sortable extends BaseComponent {
|
|
|
73
74
|
constructor(node, options) {
|
|
74
75
|
super(node, options);
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
try {
|
|
78
|
+
this.#selector = this.options.handle ?
|
|
79
|
+
`:is(${this.options.items}) :is(${this.options.handle})` :
|
|
80
|
+
this.options.items;
|
|
81
|
+
|
|
82
|
+
this.#dragging = false;
|
|
83
|
+
this.#enabled = !this.options.disabled;
|
|
84
|
+
|
|
85
|
+
this.#initialCursorNodes = $.find(this.#selector, this.node);
|
|
86
|
+
setCursor(this.#initialCursorNodes, this.options.cursor);
|
|
87
|
+
this.#events();
|
|
88
|
+
this.#initialCursorNodes = null;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
this.dispose();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
/**
|
|
@@ -99,7 +107,7 @@ export default class Sortable extends BaseComponent {
|
|
|
99
107
|
|
|
100
108
|
$.removeEventDelegate(this.node, 'mousedown.ui.sortable touchstart.ui.sortable');
|
|
101
109
|
$.removeEvent(this.node, 'receive.ui.sortable');
|
|
102
|
-
resetCursor($.find(this.#selector, this.node));
|
|
110
|
+
resetCursor(this.#initialCursorNodes ?? $.find(this.#selector, this.node));
|
|
103
111
|
|
|
104
112
|
if (this.#target && this.options.helperClass) {
|
|
105
113
|
$.removeClass(this.#target, this.options.helperClass);
|
|
@@ -107,6 +115,8 @@ export default class Sortable extends BaseComponent {
|
|
|
107
115
|
|
|
108
116
|
this.#resetDrag();
|
|
109
117
|
|
|
118
|
+
this.#initialCursorNodes = null;
|
|
119
|
+
|
|
110
120
|
super.dispose();
|
|
111
121
|
}
|
|
112
122
|
|
|
@@ -183,16 +193,16 @@ export default class Sortable extends BaseComponent {
|
|
|
183
193
|
* Attaches events for the Sortable.
|
|
184
194
|
*/
|
|
185
195
|
#events() {
|
|
186
|
-
const downEvent = (
|
|
196
|
+
const downEvent = (event) => {
|
|
187
197
|
const cancelled = this.options.cancel &&
|
|
188
198
|
(
|
|
189
|
-
$.is(
|
|
190
|
-
$.is(
|
|
191
|
-
$.closest(
|
|
199
|
+
$.is(event.target, this.options.cancel) ||
|
|
200
|
+
$.is(event.currentTarget, this.options.cancel) ||
|
|
201
|
+
$.closest(event.target, this.options.cancel, this.node).length
|
|
192
202
|
);
|
|
193
203
|
|
|
194
204
|
if (
|
|
195
|
-
|
|
205
|
+
event.button ||
|
|
196
206
|
!this.#enabled ||
|
|
197
207
|
cancelled ||
|
|
198
208
|
$.getDataset(this.node, 'uiDragging')
|
|
@@ -201,21 +211,21 @@ export default class Sortable extends BaseComponent {
|
|
|
201
211
|
}
|
|
202
212
|
|
|
203
213
|
this.#target = this.options.handle ?
|
|
204
|
-
this.items().find((node) => $.hasDescendent(node,
|
|
205
|
-
|
|
214
|
+
this.items().find((node) => $.hasDescendent(node, event.currentTarget)) :
|
|
215
|
+
event.currentTarget;
|
|
206
216
|
|
|
207
217
|
if (!this.#target) {
|
|
208
218
|
return false;
|
|
209
219
|
}
|
|
210
220
|
};
|
|
211
221
|
|
|
212
|
-
const moveEvent = (
|
|
222
|
+
const moveEvent = (event) => {
|
|
213
223
|
if (!this.node || !this.#target) {
|
|
214
224
|
return;
|
|
215
225
|
}
|
|
216
226
|
|
|
217
227
|
const previousPos = this.#pos;
|
|
218
|
-
this.#pos = getPosition(
|
|
228
|
+
this.#pos = getPosition(event);
|
|
219
229
|
const deltaX = previousPos ?
|
|
220
230
|
this.#pos.x - previousPos.x :
|
|
221
231
|
0;
|
|
@@ -255,7 +265,7 @@ export default class Sortable extends BaseComponent {
|
|
|
255
265
|
this.#scheduleScroll();
|
|
256
266
|
};
|
|
257
267
|
|
|
258
|
-
const upEvent = (
|
|
268
|
+
const upEvent = (event) => {
|
|
259
269
|
if (!this.node) {
|
|
260
270
|
return;
|
|
261
271
|
}
|
|
@@ -265,8 +275,8 @@ export default class Sortable extends BaseComponent {
|
|
|
265
275
|
return;
|
|
266
276
|
}
|
|
267
277
|
|
|
268
|
-
if (
|
|
269
|
-
|
|
278
|
+
if (event.type === 'mouseup') {
|
|
279
|
+
event.preventDefault();
|
|
270
280
|
}
|
|
271
281
|
|
|
272
282
|
const source = this.node;
|
|
@@ -314,7 +324,7 @@ export default class Sortable extends BaseComponent {
|
|
|
314
324
|
dragEvent,
|
|
315
325
|
);
|
|
316
326
|
|
|
317
|
-
$.addEvent(this.node, 'receive.ui.sortable', (
|
|
327
|
+
$.addEvent(this.node, 'receive.ui.sortable', () => {
|
|
318
328
|
setCursor($.find(this.#selector, this.node), this.options.cursor);
|
|
319
329
|
});
|
|
320
330
|
}
|
|
@@ -353,7 +363,7 @@ export default class Sortable extends BaseComponent {
|
|
|
353
363
|
return;
|
|
354
364
|
}
|
|
355
365
|
|
|
356
|
-
this.#scrollFrame = window.requestAnimationFrame((
|
|
366
|
+
this.#scrollFrame = window.requestAnimationFrame(() => {
|
|
357
367
|
this.#checkScroll();
|
|
358
368
|
});
|
|
359
369
|
}
|