@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/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
- this.#selector = this.options.handle ?
77
- `:is(${this.options.items}) :is(${this.options.handle})` :
78
- this.options.items;
79
-
80
- this.#dragging = false;
81
- this.#enabled = !this.options.disabled;
82
-
83
- setCursor($.find(this.#selector, this.node), this.options.cursor);
84
- this.#events();
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 = (e) => {
196
+ const downEvent = (event) => {
187
197
  const cancelled = this.options.cancel &&
188
198
  (
189
- $.is(e.target, this.options.cancel) ||
190
- $.is(e.currentTarget, this.options.cancel) ||
191
- $.closest(e.target, this.options.cancel, this.node).length
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
- e.button ||
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, e.currentTarget)) :
205
- e.currentTarget;
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 = (e) => {
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(e);
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 = (e) => {
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 (e.type === 'mouseup') {
269
- e.preventDefault();
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
  }