react-virtual-sortable 1.0.3 → 1.1.0

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * react-virtual-sortable v1.0.3
2
+ * react-virtual-sortable v1.1.0
3
3
  * open source under the MIT license
4
4
  * https://github.com/mfuu/react-virtual-sortable#readme
5
5
  */
@@ -145,7 +145,7 @@
145
145
  var sortableDnd_min = {exports: {}};
146
146
 
147
147
  /*!
148
- * sortable-dnd v0.6.23
148
+ * sortable-dnd v0.7.1
149
149
  * open source under the MIT license
150
150
  * https://github.com/mfuu/sortable-dnd#readme
151
151
  */
@@ -180,9 +180,9 @@
180
180
  if ("undefined" != typeof window && window.navigator) return !!navigator.userAgent.match(t);
181
181
  }
182
182
  var r = i(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),
183
- s = i(/Edge/i),
183
+ a = i(/Edge/i),
184
184
  l = i(/safari/i) && !i(/chrome/i) && !i(/android/i),
185
- a = function () {
185
+ s = function () {
186
186
  var t = !1;
187
187
  return document.addEventListener("checkIfSupportPassive", null, {
188
188
  get passive() {
@@ -191,23 +191,23 @@
191
191
  }), t;
192
192
  }();
193
193
  function c(t, e, o) {
194
- window.addEventListener ? t.addEventListener(e, o, !(!a && r) && n) : window.attachEvent ? t.attachEvent("on" + e, o) : t["on" + e] = o;
194
+ window.addEventListener ? t.addEventListener(e, o, !(!s && r) && n) : window.attachEvent ? t.attachEvent("on" + e, o) : t["on" + e] = o;
195
195
  }
196
196
  function h(t, e, o) {
197
- window.removeEventListener ? t.removeEventListener(e, o, !(!a && r) && n) : window.detachEvent ? t.detachEvent("on" + e, o) : t["on" + e] = null;
197
+ window.removeEventListener ? t.removeEventListener(e, o, !(!s && r) && n) : window.detachEvent ? t.detachEvent("on" + e, o) : t["on" + e] = null;
198
198
  }
199
199
  function u() {
200
200
  return document.scrollingElement || document.documentElement;
201
201
  }
202
202
  function d(t, e, n) {
203
203
  if (t.getBoundingClientRect || t === window) {
204
- var o, i, r, s, l, a, c;
205
- if (t !== window && t.parentNode && t !== u() ? (i = (o = t.getBoundingClientRect()).top, r = o.left, s = o.bottom, l = o.right, a = o.height, c = o.width) : (i = 0, r = 0, s = window.innerHeight, l = window.innerWidth, a = window.innerHeight, c = window.innerWidth), e && t !== window) {
204
+ var o, i, r, a, l, s, c;
205
+ if (t !== window && t.parentNode && t !== u() ? (i = (o = t.getBoundingClientRect()).top, r = o.left, a = o.bottom, l = o.right, s = o.height, c = o.width) : (i = 0, r = 0, a = window.innerHeight, l = window.innerWidth, s = window.innerHeight, c = window.innerWidth), e && t !== window) {
206
206
  n = n || t.parentNode;
207
207
  do {
208
208
  if (n && n.getBoundingClientRect) {
209
209
  var h = n.getBoundingClientRect();
210
- i -= h.top + parseInt(S(n, "border-top-width")), r -= h.left + parseInt(S(n, "border-left-width")), s = i + o.height, l = r + o.width;
210
+ i -= h.top + parseInt(S(n, "border-top-width")), r -= h.left + parseInt(S(n, "border-left-width")), a = i + o.height, l = r + o.width;
211
211
  break;
212
212
  }
213
213
  } while (n = n.parentNode);
@@ -215,10 +215,10 @@
215
215
  return {
216
216
  top: i,
217
217
  left: r,
218
- bottom: s,
218
+ bottom: a,
219
219
  right: l,
220
220
  width: c,
221
- height: a
221
+ height: s
222
222
  };
223
223
  }
224
224
  }
@@ -226,7 +226,7 @@
226
226
  if (t) {
227
227
  n = n || document;
228
228
  do {
229
- if (null != e && (">" === e[0] ? t.parentNode === n && b(t, e) : b(t, e)) || o && t === n) return t;
229
+ if (null != e && (">" === e[0] ? t.parentNode === n && y(t, e) : y(t, e)) || o && t === n) return t;
230
230
  if (t === n) break;
231
231
  } while (t = t.parentNode);
232
232
  return null;
@@ -240,49 +240,49 @@
240
240
  return !1;
241
241
  }
242
242
  function m(t, e) {
243
- for (var n = t.lastElementChild; n && (n === ot.ghost || "none" === S(n, "display") || e && !b(n, e));) n = n.previousElementSibling;
243
+ for (var n = t.lastElementChild; n && (n === tt.ghost || "none" === S(n, "display") || e && !y(n, e));) n = n.previousElementSibling;
244
244
  return n || null;
245
245
  }
246
- function g(t, e) {
246
+ function v(t, e) {
247
247
  if (!t || !t.parentNode) return -1;
248
- for (var n = 0; t = t.previousElementSibling;) "TEMPLATE" === t.nodeName.toUpperCase() || e && !b(t, e) || "none" === S(t, "display") || n++;
248
+ for (var n = 0; t = t.previousElementSibling;) t === tt.ghost || "TEMPLATE" === t.nodeName.toUpperCase() || "none" === S(t, "display") || e && !y(t, e) || n++;
249
249
  return n;
250
250
  }
251
- function v(t, e, n, o) {
252
- for (var i = 0, r = 0, s = t.children; i < s.length;) {
253
- if (s[i] !== ot.ghost && "none" !== S(s[i], "display") && p(s[i], n, t, !1) && (o || s[i] !== ot.dragged)) {
254
- if (r === e) return s[i];
251
+ function g(t, e, n, o) {
252
+ for (var i = 0, r = 0, a = t.children; i < a.length;) {
253
+ if (a[i] !== tt.ghost && "none" !== S(a[i], "display") && p(a[i], n, t, !1) && (o || a[i] !== tt.dragged)) {
254
+ if (r === e) return a[i];
255
255
  r++;
256
256
  }
257
257
  i++;
258
258
  }
259
259
  return null;
260
260
  }
261
- function y(t, e) {
261
+ function w(t, e) {
262
262
  var n = S(t),
263
263
  o = parseInt(n.width) - parseInt(n.paddingLeft) - parseInt(n.paddingRight) - parseInt(n.borderLeftWidth) - parseInt(n.borderRightWidth),
264
- i = v(t, 0, e),
265
- l = v(t, 1, e),
266
- a = i && S(i),
264
+ i = g(t, 0, e),
265
+ l = g(t, 1, e),
266
+ s = i && S(i),
267
267
  c = l && S(l),
268
- h = a && parseInt(a.marginLeft) + parseInt(a.marginRight) + d(i).width,
268
+ h = s && parseInt(s.marginLeft) + parseInt(s.marginRight) + d(i).width,
269
269
  u = c && parseInt(c.marginLeft) + parseInt(c.marginRight) + d(l).width,
270
- p = s || r ? "cssFloat" : "float";
270
+ p = a || r ? "cssFloat" : "float";
271
271
  if ("flex" === n.display) return "column" === n.flexDirection || "column-reverse" === n.flexDirection ? "vertical" : "horizontal";
272
272
  if ("grid" === n.display) return n.gridTemplateColumns.split(" ").length <= 1 ? "vertical" : "horizontal";
273
- if (i && a.float && "none" !== a.float) {
274
- var f = "left" === a.float ? "left" : "right";
273
+ if (i && s.float && "none" !== s.float) {
274
+ var f = "left" === s.float ? "left" : "right";
275
275
  return !l || "both" !== c.clear && c.clear !== f ? "horizontal" : "vertical";
276
276
  }
277
- return i && ("block" === a.display || "flex" === a.display || "table" === a.display || "grid" === a.display || h >= o && "none" === n[p] || l && "none" === n[p] && h + u > o) ? "vertical" : "horizontal";
277
+ return i && ("block" === s.display || "flex" === s.display || "table" === s.display || "grid" === s.display || h >= o && "none" === n[p] || l && "none" === n[p] && h + u > o) ? "vertical" : "horizontal";
278
278
  }
279
- function w(t, e, n) {
279
+ function b(t, e, n) {
280
280
  if (t && e) if (t.classList) t.classList[n ? "add" : "remove"](e);else {
281
281
  var i = (" " + t.className + " ").replace(o, " ").replace(" " + e + " ", " ");
282
282
  t.className = (i + (n ? " " + e : "")).replace(o, " ");
283
283
  }
284
284
  }
285
- function b(t, e) {
285
+ function y(t, e) {
286
286
  if (e) {
287
287
  if (">" === e[0] && (e = e.substring(1)), t) try {
288
288
  if (t.matches) return t.matches(e);
@@ -302,90 +302,122 @@
302
302
  }
303
303
  }
304
304
  function _(t, e) {
305
+ return Math.round(t.top) === Math.round(e.top) && Math.round(t.left) === Math.round(e.left) && Math.round(t.height) === Math.round(e.height) && Math.round(t.width) === Math.round(e.width);
306
+ }
307
+ function x(t, e) {
305
308
  var n,
306
309
  o,
307
310
  i = (o = e, (n = t).compareDocumentPosition ? n.compareDocumentPosition(o) : n.contains ? (n != o && n.contains(o) && 16) + (n != o && o.contains(n) && 8) + (n.sourceIndex >= 0 && o.sourceIndex >= 0 ? (n.sourceIndex < o.sourceIndex && 4) + (n.sourceIndex > o.sourceIndex && 2) : 1) : 0);
308
311
  return 2 === i ? 1 : 4 === i ? -1 : 0;
309
312
  }
310
- function x(t) {
313
+ function E(t) {
311
314
  void 0 !== t.preventDefault && t.cancelable && t.preventDefault();
312
315
  }
313
- function C(e) {
316
+ function I(e) {
314
317
  var n = e.sortable,
315
318
  o = e.name,
316
319
  i = e.evt,
317
320
  r = n.options[o];
318
- "function" == typeof r && r(t({}, i));
319
- }
320
- !function () {
321
- if ("undefined" == typeof window || "undefined" == typeof document) return "";
322
- var t = window.getComputedStyle(document.documentElement, "") || ["-moz-hidden-iframe"];
323
- (Array.prototype.slice.call(t).join("").match(/-(moz|webkit|ms)-/) || "" === t.OLink && ["", "o"])[1];
324
- }();
325
- var D,
326
- E,
327
- I,
328
- M = "Sortable" + Date.now();
329
- function T(t) {
321
+ if ("function" == typeof r) return r(t({}, i));
322
+ }
323
+ function C(t) {
324
+ if ("function" == typeof t) {
325
+ for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++) n[o - 1] = arguments[o];
326
+ return t.apply(void 0, n);
327
+ }
328
+ return t;
329
+ }
330
+ var M = "Sortable" + Date.now();
331
+ function D(t) {
330
332
  this.options = t, this.scrollEl = null, this.autoScrollInterval = null;
331
333
  }
332
- function N(t) {
333
- this.options = t, this.stack = [];
334
+ function T(t) {
335
+ this.options = t, this.animationStack = [], this.animationCallbackId = null;
334
336
  }
335
- function P(t) {
336
- this.options = t || {}, this.selects = [];
337
+ function N(t, e) {
338
+ return Math.sqrt(Math.pow(t.left - e.left, 2) + Math.pow(t.top - e.top, 2));
337
339
  }
338
- T.prototype = {
340
+ D.prototype = {
339
341
  nulling: function () {
340
342
  this.autoScrollInterval && (clearInterval(this.autoScrollInterval), this.autoScrollInterval = null);
341
343
  },
342
344
  onStarted: function () {
343
- var t = this;
344
- this.nulling(), this.autoScrollInterval = setInterval(function () {
345
- t.autoScroll();
346
- });
345
+ this.nulling(), this.autoScrollInterval = setInterval(this.autoScroll.bind(this));
347
346
  },
348
- onMove: function (t, e, n) {
349
- this.options = n, this.scrollEl = t, this.moveEvent = e;
347
+ onMove: function (t, e, n, o) {
348
+ var i = n ? n[M].options : o;
349
+ !n || i.autoScroll ? (this.options = i, this.scrollEl = function (t, e) {
350
+ if (!t || !t.getBoundingClientRect) return u();
351
+ var n = t,
352
+ o = !1;
353
+ do {
354
+ if (n.clientWidth < n.scrollWidth || n.clientHeight < n.scrollHeight) {
355
+ var i = S(n);
356
+ if (n.clientWidth < n.scrollWidth && ("auto" == i.overflowX || "scroll" == i.overflowX) || n.clientHeight < n.scrollHeight && ("auto" == i.overflowY || "scroll" == i.overflowY)) {
357
+ if (!n.getBoundingClientRect || n === document.body) return u();
358
+ if (o || e) return n;
359
+ o = !0;
360
+ }
361
+ }
362
+ } while (n = n.parentNode);
363
+ return u();
364
+ }(t, !0), this.moveEvent = e) : this.scrollEl = null;
350
365
  },
351
366
  autoScroll: function () {
352
- var t = this.moveEvent,
353
- e = this.scrollEl;
354
- if (e && void 0 !== t.clientX && void 0 !== t.clientY) {
355
- var n = d(e);
356
- if (n) {
357
- var o = t.clientX,
358
- i = t.clientY,
359
- r = n.top,
360
- s = n.right,
361
- l = n.bottom,
362
- a = n.left,
363
- c = n.height,
364
- h = n.width;
365
- if (!(i < r || o > s || i > l || o < a)) {
366
- var u = this.options,
367
- p = u.scrollThreshold,
368
- f = u.scrollSpeed,
369
- m = e.scrollTop,
370
- g = e.scrollLeft,
371
- v = e.scrollHeight,
372
- y = m > 0 && i >= r && i <= r + p,
373
- w = g + h < e.scrollWidth && o <= s && o >= s - p,
374
- b = m + c < v && i <= l && i >= l - p;
375
- g > 0 && o >= a && o <= a + p && (e.scrollLeft += Math.floor(Math.max(-1, (o - a) / p - 1) * f.x)), w && (e.scrollLeft += Math.ceil(Math.min(1, (o - s) / p + 1) * f.x)), y && (e.scrollTop += Math.floor(Math.max(-1, (i - r) / p - 1) * f.y)), b && (e.scrollTop += Math.ceil(Math.min(1, (i - l) / p + 1) * f.y));
367
+ var t = this.options,
368
+ e = this.moveEvent,
369
+ n = this.scrollEl,
370
+ o = t.scrollThreshold,
371
+ i = t.scrollSpeed;
372
+ if (n && void 0 !== e.clientX && void 0 !== e.clientY) {
373
+ var r = d(n);
374
+ if (r) {
375
+ var a = e.clientX,
376
+ l = e.clientY,
377
+ s = r.top,
378
+ c = r.right,
379
+ h = r.bottom,
380
+ u = r.left,
381
+ p = r.height,
382
+ f = r.width;
383
+ if (!(l < s || a > c || l > h || a < u)) {
384
+ var m = n.scrollTop,
385
+ v = n.scrollLeft,
386
+ g = n.scrollHeight,
387
+ w = n.scrollWidth;
388
+ n.scrollLeft += this.getScrollOffset(a, u, c, o, i.x, v, w, f), n.scrollTop += this.getScrollOffset(l, s, h, o, i.y, m, g, p);
376
389
  }
377
390
  }
378
391
  }
392
+ },
393
+ getScrollOffset: function (t, e, n, o, i, r, a, l) {
394
+ return r > 0 && t >= e && t <= e + o ? Math.max(-1, (t - e) / o - 1) * i : r + l < a && t <= n && t >= n - o ? Math.min(1, (t - n) / o + 1) * i : 0;
379
395
  }
380
- }, N.prototype = {
396
+ }, T.prototype = {
381
397
  collect: function (t) {
382
398
  if (t) {
383
- for (var e = d(t), n = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth, o = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, i = Math.min(e.right, n), r = Math.min(e.bottom, o), s = Array.prototype.slice.call(t.children), l = [], a = 0, c = s.length; a <= c; a++) {
384
- var h = s[a];
385
- if (h && h !== ot.ghost && "none" !== S(h, "display")) {
399
+ for (var e = d(t), n = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth, o = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, i = Math.min(e.right, n), r = Math.min(e.bottom, o), a = Array.prototype.slice.call(t.children), l = [], s = 0, c = a.length; s < c; s++) {
400
+ var h = a[s];
401
+ if (h !== tt.ghost && "none" !== S(h, "display")) {
386
402
  var u = d(h);
387
403
  if (!(u.bottom < 0 || u.right < 0)) {
388
- if (u.top - u.height > r || u.left - u.width > i) break;
404
+ if (0 === l.length && h.previousElementSibling) {
405
+ var p = h.previousElementSibling;
406
+ do {
407
+ if (p && p !== tt.ghost && "none" !== S(p, "display")) break;
408
+ } while (p = p.previousElementSibling);
409
+ p && l.push({
410
+ el: p,
411
+ rect: d(p)
412
+ });
413
+ }
414
+ if (u.top - u.height > r || u.left - u.width > i) {
415
+ l.push({
416
+ el: h,
417
+ rect: u
418
+ });
419
+ break;
420
+ }
389
421
  l.push({
390
422
  el: h,
391
423
  rect: u
@@ -393,179 +425,109 @@
393
425
  }
394
426
  }
395
427
  }
396
- this.stack.push(l);
397
- }
398
- },
399
- animate: function () {
400
- var t = this.stack.pop();
401
- if (t && this.options.animation) for (var e = 0, n = t.length; e < n; e++) {
402
- var o = t[e],
403
- i = o.el,
404
- r = o.rect;
405
- this.execute(i, r);
406
- }
407
- },
408
- execute: function (t, e) {
409
- var n = d(t);
410
- if (n.top !== e.top || n.left !== e.left) {
411
- var o = e.left - n.left,
412
- i = e.top - n.top;
413
- S(t, "transition", ""), S(t, "transform", "translate3d(".concat(o, "px, ").concat(i, "px, 0)")), this.repaintDummy = function (t) {
414
- return t.offsetWidth;
415
- }(t);
416
- var r = this.options,
417
- s = r.animation,
418
- l = r.easing;
419
- S(t, "transition", "transform ".concat(s, "ms ").concat(l ? " " + l : "")), S(t, "transform", "translate3d(0px, 0px, 0px)"), "number" == typeof t.animated && clearTimeout(t.animated), t.animated = setTimeout(function () {
420
- S(t, "transition", ""), S(t, "transform", ""), t.animated = null;
421
- }, s);
422
- }
423
- }
424
- }, P.prototype = {
425
- eventProperties: function () {
426
- return {
427
- nodes: D || [],
428
- clones: E || []
429
- };
430
- },
431
- isActive: function () {
432
- return !!D;
433
- },
434
- nulling: function () {
435
- D = E = I = null;
436
- },
437
- select: function (t) {
438
- w(t, this.options.selectedClass, !0), this.selects.push(t), this.selects.sort(function (t, e) {
439
- return _(t, e);
440
- });
441
- },
442
- deselect: function (t) {
443
- var e = this.selects.indexOf(t);
444
- e > -1 && (w(t, this.options.selectedClass, !1), this.selects.splice(e, 1));
445
- },
446
- useSelectHandle: function (t, e) {
447
- var n = this.options.selectHandle;
448
- return !!(I = "function" == typeof n && n(t) || "string" == typeof n && b(e, n));
449
- },
450
- onChoose: function () {
451
- !this.options.multiple || 0 === this.selects.length || this.selects.indexOf(ot.dragged) < 0 || (this.selects.sort(function (t, e) {
452
- return _(t, e);
453
- }), D = this.selects, this.toggleChosenClass(!0));
454
- },
455
- onDrop: function (t, e, n) {
456
- if (D) {
457
- var o = ot.dragged,
458
- i = ot.clone,
459
- r = D.indexOf(o);
460
- t !== e && n ? (S(i, "display", "none"), this.toggleVisible(!0), E = D.map(function (t) {
461
- return t.cloneNode(!0);
462
- }), this.sortElements(E, r, i)) : this.sortElements(D, r, i), t !== e && (e[M].multiplayer.toggleSelected(E || D, "add"), !n && t[M].multiplayer.toggleSelected(D, "remove"));
428
+ this.animationStack.push(l);
463
429
  }
464
430
  },
465
- onSelect: function (t, e, n, o) {
466
- var i = this.options,
467
- r = i.multiple,
468
- s = i.selectHandle;
469
- if (r && (s && I || !s && !n)) {
470
- var l = this.selects.indexOf(e);
471
- w(e, this.options.selectedClass, l < 0);
472
- var a = {
473
- from: o.el,
474
- event: t,
475
- node: e,
476
- index: g(e)
477
- };
478
- l < 0 ? (this.selects.push(e), C({
479
- sortable: o,
480
- name: "onSelect",
481
- evt: a
482
- })) : (this.selects.splice(l, 1), C({
483
- sortable: o,
484
- name: "onDeselect",
485
- evt: a
486
- })), this.selects.sort(function (t, e) {
487
- return _(t, e);
488
- });
489
- }
490
- },
491
- toggleChosenClass: function (t) {
492
- if (D) for (var e = 0, n = D.length; e < n; e++) w(D[e], this.options.chosenClass, t);
493
- },
494
- toggleVisible: function (t) {
495
- if (D) for (var e = 0, n = D.length; e < n; e++) D[e] != ot.dragged && S(D[e], "display", t ? "" : "none");
496
- },
497
- toggleSelected: function (t, e) {
498
- var n = this;
499
- "add" === e ? t.forEach(function (t) {
500
- return n.selects.push(t);
501
- }) : this.selects = this.selects.filter(function (e) {
502
- return t.indexOf(e) < 0;
503
- });
431
+ animate: function (t) {
432
+ var e = this,
433
+ n = this.animationStack.pop(),
434
+ o = this.options.animation;
435
+ if (!n || !o) return clearTimeout(this.animationCallbackId), void ("function" == typeof t && t());
436
+ var i = 0;
437
+ n.forEach(function (t) {
438
+ var n = 0,
439
+ r = t.el,
440
+ a = d(r),
441
+ l = t.rect,
442
+ s = r.prevToRect,
443
+ c = r.prevFromRect;
444
+ if (r.animating && c && s && _(l, a)) {
445
+ var h = function (t, e) {
446
+ var n = "";
447
+ if ("string" == typeof t) n = t;else do {
448
+ var o = S(t, "transform");
449
+ o && "none" !== o && (n = o + " " + n);
450
+ } while (!e && (t = t.parentNode));
451
+ var i = window.DOMMatrix || window.WebKitCSSMatrix || window.CSSMatrix || window.MSCSSMatrix;
452
+ return i && new i(n);
453
+ }(r, !0);
454
+ if (h) n = N({
455
+ top: a.top - h.f,
456
+ left: a.left - h.e
457
+ }, a) / N(c, s) * o;
458
+ }
459
+ _(l, a) || (r.prevFromRect = l, r.prevToRect = a, n || (n = o), e.execute(r, l, a, n)), n && (i = Math.max(i, n));
460
+ }), clearTimeout(this.animationCallbackId), i ? this.animationCallbackId = setTimeout(function () {
461
+ "function" == typeof t && t();
462
+ }, i) : "function" == typeof t && t();
504
463
  },
505
- sortElements: function (t, e, n) {
506
- for (var o = 0, i = t.length; o < i; o++) if (S(t[o], "display", ""), o < e) n.parentNode.insertBefore(t[o], n);else {
507
- var r = o > 0 ? t[o - 1] : n;
508
- n.parentNode.insertBefore(t[o], r.nextSibling);
509
- }
464
+ execute: function (t, e, n, o) {
465
+ var i = this.options.easing || "",
466
+ r = e.left - n.left,
467
+ a = e.top - n.top;
468
+ S(t, "transition", ""), S(t, "transform", "translate3d(".concat(r, "px, ").concat(a, "px, 0)")), this.repaintDummy = function (t) {
469
+ return t.offsetWidth;
470
+ }(t), S(t, "transition", "transform ".concat(o, "ms ").concat(i)), S(t, "transform", "translate3d(0px, 0px, 0px)"), "number" == typeof t.animating && clearTimeout(t.animating), t.animating = setTimeout(function () {
471
+ S(t, "transition", ""), S(t, "transform", ""), t.prevFromRect = null, t.prevToRect = null, t.animating = null;
472
+ }, o);
510
473
  }
511
474
  };
512
- var O,
513
- H,
475
+ var P,
476
+ O,
477
+ R,
514
478
  k,
515
- L,
479
+ H,
516
480
  X,
517
481
  Y,
518
- B,
519
- R,
482
+ L,
520
483
  W,
484
+ B,
521
485
  A,
522
486
  z,
523
- V,
524
487
  j,
488
+ F,
525
489
  G,
526
490
  U,
527
- F,
491
+ V,
528
492
  q,
529
- J,
530
493
  K,
494
+ J,
531
495
  Q,
532
- Z,
533
- $,
534
- tt = [];
535
- function et(t) {
496
+ Z = [];
497
+ function $(t) {
536
498
  var n,
537
499
  o,
538
500
  i,
539
501
  r = {},
540
- s = t.group;
541
- s && "object" === e(s) || (s = {
542
- name: s,
502
+ a = t.group;
503
+ a && "object" === e(a) || (a = {
504
+ name: a,
543
505
  pull: !0,
544
506
  put: !0,
545
507
  revertDrag: !0
546
- }), r.name = s.name, r.pull = null === (n = s.pull) || void 0 === n || n, r.put = null === (o = s.put) || void 0 === o || o, r.revertDrag = null === (i = s.revertDrag) || void 0 === i || i, t.group = r;
547
- }
548
- function nt(t) {
549
- var e = F || U;
550
- return !(void 0 !== t.clientX && void 0 !== t.clientY && Math.abs(t.clientX - e.clientX) <= 0 && Math.abs(t.clientY - e.clientY) <= 0);
508
+ }), r.name = a.name, r.pull = null === (n = a.pull) || void 0 === n || n, r.put = null === (o = a.put) || void 0 === o || o, r.revertDrag = null === (i = a.revertDrag) || void 0 === i || i, t.group = r;
551
509
  }
552
- function ot(e, n) {
510
+ function tt(e, n) {
553
511
  if (!e || !e.nodeType || 1 !== e.nodeType) throw "Sortable-dnd: `el` must be an HTMLElement, not ".concat({}.toString.call(e));
554
512
  e[M] = this, this.el = e, this.options = n = t({}, n);
555
513
  var o = {
556
514
  store: null,
557
515
  group: "",
558
516
  handle: null,
517
+ draggable: ">*",
559
518
  sortable: !0,
560
519
  disabled: !1,
561
- multiple: !1,
520
+ customGhost: null,
562
521
  lockAxis: "",
563
522
  direction: "",
564
523
  animation: 150,
565
524
  easing: "",
566
- draggable: ">*",
567
- selectHandle: null,
568
- customGhost: null,
525
+ chosenClass: "",
526
+ placeholderClass: "",
527
+ ghostClass: "",
528
+ ghostStyle: {},
529
+ ghostContainer: null,
530
+ appendToBody: !1,
569
531
  autoScroll: !0,
570
532
  scrollThreshold: 55,
571
533
  scrollSpeed: {
@@ -574,102 +536,89 @@
574
536
  },
575
537
  delay: 0,
576
538
  delayOnTouchOnly: !1,
577
- touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
578
- ghostClass: "",
579
- ghostStyle: {},
580
- chosenClass: "",
581
- selectedClass: "",
582
- placeholderClass: "",
583
539
  swapOnDrop: !0,
584
540
  removeCloneOnDrop: !0,
585
- fallbackOnBody: !1,
541
+ dropOnAnimationEnd: !1,
586
542
  supportTouch: "ontouchstart" in window,
543
+ touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
587
544
  emptyInsertThreshold: -1
588
545
  };
589
- for (var i in o) !(i in this.options) && (this.options[i] = o[i]);
590
- for (var r in et(n), this) "_" === r.charAt(0) && "function" == typeof this[r] && (this[r] = this[r].bind(this));
591
- c(e, this.options.supportTouch ? "touchstart" : "mousedown", this._onDrag), this.autoScroller = new T(this.options), this.multiplayer = new P(this.options), this.animator = new N(this.options), tt.push(e);
546
+ for (var i in o) !(i in n) && (n[i] = o[i]);
547
+ for (var r in $(n), this) "_" === r.charAt(0) && "function" == typeof this[r] && (this[r] = this[r].bind(this));
548
+ c(e, n.supportTouch ? "touchstart" : "mousedown", this._onDrag), this.autoScroller = new D(n), this.animator = new T(n), Z.push(e);
592
549
  }
593
- return ot.prototype = {
594
- constructor: ot,
550
+ return tt.prototype = {
551
+ constructor: tt,
595
552
  _onDrag: function (t) {
596
- var e = this;
597
- if (!k && !this.options.disabled && this.options.group.pull && (!/mousedown|pointerdown/.test(t.type) || 0 === t.button)) {
598
- var n = t.touches && t.touches[0],
599
- o = (n || t).target;
600
- if (!l || !o || "SELECT" !== o.tagName.toUpperCase()) {
601
- var i = p(o, this.options.draggable, this.el);
602
- if (i && !i.animated && (U = {
603
- event: t,
604
- clientX: (n || t).clientX,
605
- clientY: (n || t).clientY
606
- }, k = i, c(Q = n ? k : document, "mouseup", this._onDrop), c(Q, "touchend", this._onDrop), c(Q, "touchcancel", this._onDrop), !this.multiplayer.useSelectHandle(t, o))) {
607
- var a = this.options.handle;
608
- if (("function" != typeof a || a(t)) && ("string" != typeof a || p(o, a, k))) {
609
- var h = this.options,
610
- u = h.delay,
611
- d = h.delayOnTouchOnly;
612
- !u || d && !n || s || r ? this._onStart(n, t) : (c(this.el.ownerDocument, "touchmove", this._delayMoveHandler), c(this.el.ownerDocument, "mousemove", this._delayMoveHandler), c(this.el.ownerDocument, "mouseup", this._cancelStart), c(this.el.ownerDocument, "touchend", this._cancelStart), c(this.el.ownerDocument, "touchcancel", this._cancelStart), $ = setTimeout(function () {
613
- return e._onStart(n, t);
614
- }, u)), c(document, "selectstart", x), l && S(document.body, "user-select", "none");
615
- }
616
- }
617
- }
553
+ var e = this,
554
+ n = this.el,
555
+ o = this.options,
556
+ i = o.handle,
557
+ s = t.touches && t.touches[0],
558
+ h = (s || t).target,
559
+ u = n.ownerDocument;
560
+ if (!R && !o.disabled && o.group.pull && !(/mousedown|pointerdown/.test(t.type) && 0 !== t.button || l && h && "SELECT" === h.tagName.toUpperCase())) {
561
+ var d = p(h, o.draggable, n);
562
+ d && !d.animating && (G = {
563
+ event: t,
564
+ clientX: (s || t).clientX,
565
+ clientY: (s || t).clientY
566
+ }, R = d, c(q = s ? R : document, "mouseup", this._onDrop), c(q, "touchend", this._onDrop), c(q, "touchcancel", this._onDrop), "function" == typeof i && !i(t) || "string" == typeof i && !p(h, i, R) || (!o.delay || o.delayOnTouchOnly && !s || a || r ? this._onStart(s, t) : (c(u, "touchmove", this._delayedMoveHandler), c(u, "mousemove", this._delayedMoveHandler), c(u, "mouseup", this._cancelStart), c(u, "touchend", this._cancelStart), c(u, "touchcancel", this._cancelStart), this._dragStartTimer = setTimeout(function () {
567
+ return e._onStart(s, t);
568
+ }, o.delay))));
618
569
  }
619
570
  },
620
- _delayMoveHandler: function (t) {
571
+ _delayedMoveHandler: function (t) {
621
572
  var e = t.touches ? t.touches[0] : t;
622
- Math.max(Math.abs(e.clientX - U.clientX), Math.abs(e.clientY - U.clientY)) >= Math.floor(this.options.touchStartThreshold / (window.devicePixelRatio || 1)) && this._cancelStart();
573
+ Math.max(Math.abs(e.clientX - G.clientX), Math.abs(e.clientY - G.clientY)) >= Math.floor(this.options.touchStartThreshold / (window.devicePixelRatio || 1)) && this._cancelStart();
623
574
  },
624
575
  _cancelStart: function () {
625
- clearTimeout($), h(this.el.ownerDocument, "touchmove", this._delayMoveHandler), h(this.el.ownerDocument, "mousemove", this._delayMoveHandler), h(this.el.ownerDocument, "mouseup", this._cancelStart), h(this.el.ownerDocument, "touchend", this._cancelStart), h(this.el.ownerDocument, "touchcancel", this._cancelStart), h(document, "selectstart", x), l && S(document.body, "user-select", "");
576
+ var t = this.el.ownerDocument;
577
+ clearTimeout(this._dragStartTimer), h(t, "touchmove", this._delayedMoveHandler), h(t, "mousemove", this._delayedMoveHandler), h(t, "mouseup", this._cancelStart), h(t, "touchend", this._cancelStart), h(t, "touchcancel", this._cancelStart);
626
578
  },
627
579
  _onStart: function (t, e) {
628
- x(e);
629
- var n = g(k);
630
- O = this.el, H = this.el, W = k, V = n, j = n, G = n, J = {
631
- to: this.el,
632
- target: k,
633
- newIndex: n,
580
+ E(e);
581
+ var n = this.el,
582
+ o = this.options,
583
+ i = v(R);
584
+ z = i, j = i, F = i, P = n, O = n, X = n, W = R, B = R.parentNode, A = o.group.pull, J = R, K = {
585
+ to: n,
586
+ target: R,
587
+ newIndex: i,
634
588
  relative: 0
635
- }, K = k, R = this.el, Y = k.cloneNode(!0), A = k.parentNode, z = this.options.group.pull, ot.clone = Y, ot.active = this, ot.dragged = k, this.multiplayer.onChoose(), w(k, this.options.chosenClass, !0), C({
589
+ }, Y = R.cloneNode(!0), tt.dragged = R, tt.clone = Y, tt.active = this, I({
636
590
  sortable: this,
637
591
  name: "onChoose",
638
592
  evt: this._getEventProperties(e)
639
- }), c(Q, t ? "touchmove" : "mousemove", this._nearestSortable);
593
+ }), b(R, o.chosenClass, !0), c(q, t ? "touchmove" : "mousemove", this._nearestSortable);
640
594
  try {
641
595
  document.selection ? setTimeout(function () {
642
596
  return document.selection.empty();
643
597
  }, 0) : window.getSelection().removeAllRanges();
644
598
  } catch (t) {}
599
+ c(document, "selectstart", E), l && S(document.body, "user-select", "none");
645
600
  },
646
601
  _onStarted: function () {
647
- this.animator.collect(A), w(Y, this.options.chosenClass, !0), w(Y, this.options.placeholderClass, !0), this._appendGhost(), this.multiplayer.toggleVisible(!1), S(k, "display", "none"), k.parentNode.insertBefore(Y, k), C({
602
+ var t = this.options;
603
+ this.animator.collect(B), this._appendGhost(), b(Y, t.chosenClass, !0), b(Y, t.placeholderClass, !0), R.parentNode.insertBefore(Y, R), S(R, "display", "none"), I({
648
604
  sortable: this,
649
605
  name: "onDrag",
650
- evt: this._getEventProperties(U.event)
606
+ evt: this._getEventProperties(G.event)
651
607
  }), this.animator.animate(), this.autoScroller.onStarted();
652
608
  },
653
- _getGhostElement: function () {
654
- var t = this.options.customGhost;
655
- if ("function" == typeof t) {
656
- var e = this.multiplayer.selects;
657
- return t(this.multiplayer.isActive() ? e : [k]);
658
- }
659
- return k;
660
- },
661
609
  _appendGhost: function () {
662
- if (!B) {
663
- var e = this.options.fallbackOnBody ? document.body : this.el,
664
- n = this._getGhostElement();
665
- w(B = n.cloneNode(!0), this.options.ghostClass, !0);
666
- var o = d(k),
667
- i = t({
610
+ if (!L) {
611
+ var e = this.options,
612
+ n = e.appendToBody ? document.body : C(e.ghostContainer, this) || this.el,
613
+ o = C(e.customGhost, Y) || Y;
614
+ b(L = o.cloneNode(!0), e.ghostClass, !0);
615
+ var i = d(R),
616
+ r = t({
668
617
  position: "fixed",
669
- top: o.top,
670
- left: o.left,
671
- width: o.width,
672
- height: o.height,
618
+ top: i.top,
619
+ left: i.left,
620
+ width: i.width,
621
+ height: i.height,
673
622
  margin: 0,
674
623
  zIndex: 1e5,
675
624
  opacity: "0.8",
@@ -678,224 +627,206 @@
678
627
  transform: "",
679
628
  transition: "",
680
629
  pointerEvents: "none"
681
- }, this.options.ghostStyle);
682
- for (var r in i) S(B, r, i[r]);
683
- ot.ghost = B, e.appendChild(B);
684
- var s = (U.clientX - o.left) / parseInt(B.style.width) * 100,
685
- l = (U.clientY - o.top) / parseInt(B.style.height) * 100;
686
- S(B, "transform-origin", "".concat(s, "% ").concat(l, "%")), S(B, "will-change", "transform");
630
+ }, e.ghostStyle);
631
+ for (var a in r) S(L, a, r[a]);
632
+ tt.ghost = L, n.appendChild(L);
633
+ var l = (G.clientX - i.left) / parseInt(L.style.width) * 100,
634
+ s = (G.clientY - i.top) / parseInt(L.style.height) * 100;
635
+ S(L, "transform-origin", "".concat(l, "% ").concat(s, "%")), S(L, "will-change", "transform");
687
636
  }
688
637
  },
689
638
  _nearestSortable: function (t) {
690
- x(t);
639
+ E(t);
691
640
  var e = t.touches && t.touches[0] || t;
692
- if (k && nt(e)) {
693
- !F && this._onStarted();
641
+ if (R && function (t) {
642
+ var e = U || G;
643
+ return !(void 0 !== t.clientX && void 0 !== t.clientY && Math.abs(t.clientX - e.clientX) <= 0 && Math.abs(t.clientY - e.clientY) <= 0);
644
+ }(e)) {
645
+ !U && this._onStarted();
694
646
  var n = this.options.lockAxis,
695
- o = "x" === n ? U.clientX : e.clientX,
696
- i = "y" === n ? U.clientY : e.clientY,
647
+ o = "x" === n ? G.clientX : e.clientX,
648
+ i = "y" === n ? G.clientY : e.clientY,
697
649
  r = document.elementFromPoint(o, i),
698
- s = o - U.clientX,
699
- l = i - U.clientY;
700
- F = {
650
+ a = o - G.clientX,
651
+ l = i - G.clientY;
652
+ U = {
701
653
  event: t,
702
654
  clientX: o,
703
655
  clientY: i
704
- }, S(B, "transform", "translate3d(".concat(s, "px, ").concat(l, "px, 0)"));
705
- var a,
656
+ }, S(L, "transform", "translate3d(".concat(a, "px, ").concat(l, "px, 0)"));
657
+ var s,
706
658
  c,
707
659
  h,
708
- p = (a = o, c = i, tt.reduce(function (t, e) {
660
+ u = (s = o, c = i, Z.reduce(function (t, e) {
709
661
  var n = e[M].options.emptyInsertThreshold;
710
662
  if (null != n) {
711
663
  var o = d(e),
712
- i = a >= o.left - n && a <= o.right + n,
664
+ i = s >= o.left - n && s <= o.right + n,
713
665
  r = c >= o.top - n && c <= o.bottom + n;
714
666
  return i && r && (!h || h && o.left >= h.left && o.right <= h.right && o.top >= h.top && o.bottom <= h.bottom) && (t = e, h = o), t;
715
667
  }
716
668
  }, null));
717
- p && p[M]._onMove(t, r);
718
- var f = p ? p[M].options : null,
719
- m = null;
720
- (!p || f.autoScroll) && U && F && (m = function (t, e) {
721
- if (!t || !t.getBoundingClientRect) return u();
722
- var n = t,
723
- o = !1;
724
- do {
725
- if (n.clientWidth < n.scrollWidth || n.clientHeight < n.scrollHeight) {
726
- var i = S(n);
727
- if (n.clientWidth < n.scrollWidth && ("auto" == i.overflowX || "scroll" == i.overflowX) || n.clientHeight < n.scrollHeight && ("auto" == i.overflowY || "scroll" == i.overflowY)) {
728
- if (!n.getBoundingClientRect || n === document.body) return u();
729
- if (o || e) return n;
730
- o = !0;
731
- }
732
- }
733
- } while (n = n.parentNode);
734
- return u();
735
- }(r, !0)), this.autoScroller.onMove(m, F, f || this.options);
669
+ u && u[M]._onMove(t, r), this.autoScroller.onMove(r, U, u, this.options);
736
670
  }
737
671
  },
738
672
  _allowPut: function () {
739
- if (R === this.el) return !0;
740
- if (!this.options.group.put) return !1;
741
673
  var t = this.options.group,
742
- e = t.name,
743
- n = t.put,
744
- o = R[M].options.group;
745
- return n.join && n.indexOf(o.name) > -1 || o.name && e && o.name === e;
674
+ e = X[M].options.group;
675
+ return this.el === X || !!t.put && (t.put.join && t.put.indexOf(e.name) > -1 || e.name && t.name && e.name === t.name);
746
676
  },
747
677
  _getDirection: function () {
748
- var t = this.options,
749
- e = t.draggable,
750
- n = t.direction;
751
- return n ? "function" == typeof n ? n.call(F.event, Y, this) : n : y(A, e);
678
+ var t = this.options.draggable,
679
+ e = this.options.direction;
680
+ return e ? C(e, U.event, Y, this) : w(B, t);
752
681
  },
753
682
  _allowSwap: function () {
754
- var t = d(L),
683
+ var t = d(k),
755
684
  e = "vertical" === this._getDirection(),
756
685
  n = e ? "top" : "left",
757
686
  o = e ? "bottom" : "right",
758
- i = L[e ? "offsetHeight" : "offsetWidth"],
759
- r = e ? F.clientY : F.clientX,
760
- s = r >= t[n] && r < t[o] - i / 2 ? -1 : 1,
761
- l = v(A, 0, this.options.draggable),
762
- a = m(A),
687
+ i = k[e ? "offsetHeight" : "offsetWidth"],
688
+ r = e ? U.clientY : U.clientX,
689
+ a = r >= t[n] && r < t[o] - i / 2 ? -1 : 1,
690
+ l = g(B, 0, this.options.draggable),
691
+ s = m(B),
763
692
  c = d(l),
764
- h = d(a);
765
- if (L === A || f(A, L)) return Y === l && r < c[n] ? (X = L, !0) : Y === a && r > h[o] && (X = L.nextSibling, !0);
766
- var u = _(Y, L);
767
- return X = u < 0 ? L.nextSibling : L, q !== L ? (Z = s, !0) : Z !== s && (Z = s, s < 0 ? u > 0 : u < 0);
693
+ h = d(s);
694
+ if (k === B || f(B, k)) return Y === l && r < c[n] ? (H = k, !0) : Y === s && r > h[o] && (H = k.nextSibling, !0);
695
+ var u = x(Y, k);
696
+ return H = u < 0 ? k.nextSibling : k, V !== k ? (Q = a, !0) : Q !== a && (Q = a, a < 0 ? u > 0 : u < 0);
768
697
  },
769
698
  _onMove: function (t, e) {
770
- if (!this.options.disabled && this._allowPut()) {
771
- if (L = p(e, this.options.draggable, this.el), C({
699
+ var n = this.el,
700
+ o = this.options;
701
+ if (!o.disabled && this._allowPut()) {
702
+ if (k = p(e, o.draggable, n), I({
772
703
  sortable: this,
773
704
  name: "onMove",
774
705
  evt: this._getEventProperties(t, {
775
- target: L
706
+ target: k
776
707
  })
777
- }), this.options.sortable || this.el !== R) return this.el === H || e !== this.el && m(this.el) ? void (L && !L.animated && !f(L, Y) && this._allowSwap() && (L !== Y && X !== Y ? (this.el !== H ? this._onInsert(t) : L !== k && this._onChange(t), q = L) : q = L)) : (L = q = null, void this._onInsert(t));
778
- H !== R && (L = q = k, Z = 0, this._onInsert(t));
708
+ }), o.sortable || n !== X) return n === O || e !== n && m(n) ? void (k && !k.animating && !f(k, Y) && this._allowSwap() && (k !== Y && H !== Y ? (n !== O ? this._onInsert(t) : k !== R && this._onChange(t), V = k) : V = k)) : (k = V = null, void this._onInsert(t));
709
+ O !== X && (k = V = R, Q = 0, this._onInsert(t));
779
710
  }
780
711
  },
781
712
  _onInsert: function (t) {
782
- var e = L || Y,
783
- n = "clone" === z && this.el !== R && H === R,
784
- o = "clone" === z && this.el === R && H !== R,
785
- i = f(L, document),
786
- r = L === k && !i,
787
- s = H[M],
788
- l = R[M];
789
- O = this.el, V = g(Y), W = e, A = i ? L.parentNode : this.el, s.animator.collect(Y.parentNode), this.animator.collect(A), n && (J.target = K, J.newIndex = V, J.relative = K === k ? 0 : _(Y, K), S(k, "display", ""), l.multiplayer.toggleVisible(!0), l.options.group.revertDrag || Y.parentNode.insertBefore(k, Y)), o && (V = g(k), S(k, "display", "none"), this.multiplayer.toggleVisible(!1)), S(Y, "display", r ? "none" : ""), L && i ? A.insertBefore(Y, Z < 0 ? L : L.nextSibling) : A.appendChild(Y), j = r ? G : g(Y), n && l.options.group.revertDrag && (J.target = k, J.newIndex = G, J.relative = 0, C({
790
- sortable: l,
713
+ var e = this.el,
714
+ n = k || Y,
715
+ o = "clone" === A && e !== X && O === X,
716
+ i = "clone" === A && e === X && O !== X,
717
+ r = f(k, document),
718
+ a = k === R && !r,
719
+ l = O[M],
720
+ s = X[M];
721
+ P = e, z = v(Y), W = n, B = r ? k.parentNode : e, l.animator.collect(Y.parentNode), this.animator.collect(B), o && (K.target = J, K.newIndex = z, K.relative = J === R ? 0 : x(Y, J), S(R, "display", ""), s.options.group.revertDrag || Y.parentNode.insertBefore(R, Y)), i && (z = v(R), S(R, "display", "none")), S(Y, "display", a ? "none" : ""), k && r ? B.insertBefore(Y, Q < 0 ? k : k.nextSibling) : B.appendChild(Y), j = a ? F : v(Y), o && s.options.group.revertDrag && (K.target = R, K.newIndex = F, K.relative = 0, I({
722
+ sortable: s,
791
723
  name: "onChange",
792
724
  evt: this._getEventProperties(t, {
793
- to: R,
794
- target: k,
795
- newIndex: G,
725
+ to: X,
726
+ target: R,
727
+ newIndex: F,
796
728
  revertDrag: !0
797
729
  })
798
- })), n || C({
799
- sortable: s,
730
+ })), o || I({
731
+ sortable: l,
800
732
  name: "onRemove",
801
733
  evt: this._getEventProperties(t, {
802
734
  newIndex: -1
803
735
  })
804
- }), o && e !== k && (K = e, C({
736
+ }), i && n !== R && (J = n, I({
805
737
  sortable: this,
806
738
  name: "onChange",
807
739
  evt: this._getEventProperties(t, {
808
- from: R,
740
+ from: X,
809
741
  backToOrigin: !0
810
742
  })
811
- })), o || C({
743
+ })), i || I({
812
744
  sortable: this,
813
745
  name: "onAdd",
814
746
  evt: this._getEventProperties(t, {
815
747
  oldIndex: -1
816
748
  })
817
- }), s.animator.animate(), this.animator.animate(), H = this.el;
749
+ }), l.animator.animate(), this.animator.animate(), O = e;
818
750
  },
819
751
  _onChange: function (t) {
820
- this.animator.collect(A), V = g(Y), A = L.parentNode, W = L, this.el === R && (K = L), A.insertBefore(Y, X), j = g(Y), C({
752
+ var e = this.el;
753
+ this.animator.collect(B), z = v(Y), B = k.parentNode, W = k, e === X && (J = k), B.insertBefore(Y, H), j = v(Y), I({
821
754
  sortable: this,
822
755
  name: "onChange",
823
756
  evt: this._getEventProperties(t)
824
- }), this.animator.animate(), H = this.el;
757
+ }), this.animator.animate(), O = e;
825
758
  },
826
759
  _onDrop: function (t) {
827
- this._cancelStart(), h(Q, "touchmove", this._nearestSortable), h(Q, "mousemove", this._nearestSortable), h(Q, "mouseup", this._onDrop), h(Q, "touchend", this._onDrop), h(Q, "touchcancel", this._onDrop), R && (H = R, V = G, W === Y && (W = k), this.animator.collect(A), this.multiplayer.toggleChosenClass(!1), w(k, this.options.chosenClass, !1), C({
828
- sortable: this,
829
- name: "onUnchoose",
830
- evt: this._getEventProperties(t)
831
- }), F && this._onEnd(t), !F && this.animator.animate()), !nt(t.changedTouches ? t.changedTouches[0] : t) && this.multiplayer.onSelect(t, k, R, this), B && B.parentNode && B.parentNode.removeChild(B), this._nulling();
760
+ var e = this,
761
+ n = this.options;
762
+ if (this._cancelStart(), h(q, "touchmove", this._nearestSortable), h(q, "mousemove", this._nearestSortable), h(q, "mouseup", this._onDrop), h(q, "touchend", this._onDrop), h(q, "touchcancel", this._onDrop), h(document, "selectstart", E), l && S(document.body, "user-select", ""), L && L.parentNode && L.parentNode.removeChild(L), X) {
763
+ if (O = X, z = F, W === Y && (W = R), b(R, n.chosenClass, !1), I({
764
+ sortable: this,
765
+ name: "onUnchoose",
766
+ evt: this._getEventProperties(t)
767
+ }), U) {
768
+ this.animator.collect(B), b(Y, n.chosenClass, !1), b(Y, n.placeholderClass, !1);
769
+ var o = this._getEventProperties(t);
770
+ !n.dropOnAnimationEnd && this._onEnd(o), this.animator.animate(function () {
771
+ n.dropOnAnimationEnd && e._onEnd(o);
772
+ });
773
+ } else this._nulling();
774
+ } else this._nulling();
832
775
  },
833
776
  _onEnd: function (e) {
834
- w(Y, this.options.chosenClass, !1), w(Y, this.options.placeholderClass, !1);
835
- var n = "clone" === z;
836
- this.multiplayer.onDrop(H, O, n);
837
- var o = this._getEventProperties(e),
838
- i = this.options,
839
- r = i.swapOnDrop,
840
- s = i.removeCloneOnDrop;
841
- n && H !== O || !("function" == typeof r ? r(o) : r) || A.insertBefore(k, Y), n && H !== O && !this.multiplayer.isActive() || !("function" == typeof s ? s(o) : s) || Y && Y.parentNode && Y.parentNode.removeChild(Y), S(k, "display", ""), this.animator.animate(), H !== O && C({
842
- sortable: H[M],
777
+ var n = this.options,
778
+ o = "clone" === A,
779
+ i = O === P;
780
+ o && !i || !C(n.swapOnDrop, e) || B.insertBefore(R, Y), o && !i || !C(n.removeCloneOnDrop, e) || Y && Y.parentNode && Y.parentNode.removeChild(Y), S(R, "display", ""), O !== P && I({
781
+ sortable: O[M],
843
782
  name: "onDrop",
844
- evt: t({}, o, n ? J : {
783
+ evt: t({}, e, o ? K : {
845
784
  newIndex: -1
846
785
  })
847
- }), C({
848
- sortable: O[M],
786
+ }), I({
787
+ sortable: P[M],
849
788
  name: "onDrop",
850
- evt: t({}, o, H === O ? {} : {
789
+ evt: t({}, e, i ? {} : {
851
790
  oldIndex: -1
852
791
  })
853
- });
792
+ }), this._nulling();
854
793
  },
855
794
  _getEventProperties: function (e) {
856
795
  var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
857
796
  o = {};
858
- return o.event = e, o.to = O, o.from = H, o.node = k, o.clone = Y, o.target = W, o.oldIndex = V, o.newIndex = j, o.pullMode = z, t(o, this.multiplayer.eventProperties(), n), o.relative = W === k ? 0 : _(Y, W), o;
797
+ return o.event = e, o.to = P, o.from = O, o.node = R, o.clone = Y, o.target = W, o.oldIndex = z, o.newIndex = j, o.pullMode = A, t(o, n), o.relative = W === R ? 0 : x(Y, W), o;
859
798
  },
860
799
  _nulling: function () {
861
- O = H = k = L = X = Y = B = R = W = A = z = V = j = G = U = F = q = J = K = Q = Z = $ = ot.clone = ot.ghost = ot.active = ot.dragged = null, this.multiplayer.nulling(), this.autoScroller.nulling();
800
+ P = O = R = k = H = X = Y = L = W = B = A = z = j = F = G = U = V = q = K = J = Q = tt.clone = tt.ghost = tt.active = tt.dragged = null, this.autoScroller.nulling();
862
801
  },
863
802
  destroy: function () {
864
803
  this._cancelStart(), this._nulling(), h(this.el, "touchstart", this._onDrag), h(this.el, "mousedown", this._onDrag);
865
- var t = tt.indexOf(this.el);
866
- t > -1 && tt.splice(t, 1), this.el[M] = this.animator = this.multiplayer = this.autoScroller = null;
804
+ var t = Z.indexOf(this.el);
805
+ t > -1 && Z.splice(t, 1), this.el[M] = this.animator = this.autoScroller = null;
867
806
  },
868
807
  option: function (t, e) {
869
808
  if (void 0 === e) return this.options[t];
870
- this.options[t] = e, this.animator.options[t] = e, this.multiplayer.options[t] = e, this.autoScroller.options[t] = e, "group" === t && et(this.options);
871
- },
872
- select: function (t) {
873
- this.multiplayer.select(t);
874
- },
875
- deselect: function (t) {
876
- this.multiplayer.deselect(t);
877
- },
878
- getSelectedElements: function () {
879
- return this.multiplayer.selects;
809
+ this.options[t] = e, this.animator.options[t] = e, this.autoScroller.options[t] = e, "group" === t && $(this.options);
880
810
  }
881
- }, ot.utils = {
811
+ }, tt.utils = {
882
812
  on: c,
883
813
  off: h,
884
814
  css: S,
885
- index: g,
815
+ index: v,
816
+ matches: y,
886
817
  closest: p,
887
818
  getRect: d,
888
- toggleClass: w,
889
- detectDirection: y
890
- }, ot.get = function (t) {
819
+ toggleClass: b,
820
+ detectDirection: w
821
+ }, tt.get = function (t) {
891
822
  return t[M];
892
- }, ot.create = function (t, e) {
893
- return new ot(t, e);
894
- }, ot;
823
+ }, tt.create = function (t, e) {
824
+ return new tt(t, e);
825
+ }, tt;
895
826
  });
896
827
  })(sortableDnd_min, sortableDnd_min.exports);
897
828
  var sortableDnd_minExports = sortableDnd_min.exports;
898
- var Dnd = /*@__PURE__*/getDefaultExportFromCjs(sortableDnd_minExports);
829
+ var Sortable = /*@__PURE__*/getDefaultExportFromCjs(sortableDnd_minExports);
899
830
 
900
831
  function throttle(fn, wait) {
901
832
  var timer;
@@ -926,15 +857,26 @@
926
857
  var throttled = throttle(fn, wait);
927
858
  var result = function result() {
928
859
  throttled['cancel']();
929
- throttled.apply(this, arguments);
860
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
861
+ args[_key2] = arguments[_key2];
862
+ }
863
+ throttled.apply(this, args);
930
864
  };
931
865
  result['cancel'] = function () {
932
866
  throttled['cancel']();
933
867
  };
934
868
  return result;
935
869
  }
936
- function isSameValue(a, b) {
937
- return a === 0 ? a === b : a == b;
870
+ function isEqual(a, b) {
871
+ // 0 & -0
872
+ if (a === 0 && b === 0) {
873
+ return 1 / a === 1 / b;
874
+ }
875
+ // NaN
876
+ if (Number.isNaN(a) && Number.isNaN(b)) {
877
+ return true;
878
+ }
879
+ return a == b;
938
880
  }
939
881
  function getDataKey(item, dataKey) {
940
882
  return (!Array.isArray(dataKey) ? dataKey.replace(/\[/g, '.').replace(/\]/g, '.').split('.') : dataKey).reduce(function (o, k) {
@@ -945,186 +887,6 @@
945
887
  return element instanceof Document && element.nodeType === 9 || element instanceof Window;
946
888
  }
947
889
 
948
- var SortableAttrs = ['delay', 'group', 'handle', 'lockAxis', 'disabled', 'sortable', 'draggable', 'animation', 'autoScroll', 'ghostClass', 'ghostStyle', 'chosenClass', 'scrollSpeed', 'fallbackOnBody', 'scrollThreshold', 'delayOnTouchOnly', 'placeholderClass'];
949
- var Sortable = /*#__PURE__*/function () {
950
- function Sortable(el, options) {
951
- _classCallCheck(this, Sortable);
952
- this.el = el;
953
- this.options = options;
954
- this.rangeChanged = false;
955
- this.installSortable();
956
- }
957
- _createClass(Sortable, [{
958
- key: "destroy",
959
- value: function destroy() {
960
- this.sortable.destroy();
961
- this.rangeChanged = false;
962
- }
963
- }, {
964
- key: "option",
965
- value: function option(key, value) {
966
- this.options[key] = value;
967
- if (SortableAttrs.includes(key)) {
968
- this.sortable.option(key, value);
969
- }
970
- }
971
- }, {
972
- key: "installSortable",
973
- value: function installSortable() {
974
- var _this = this;
975
- var props = SortableAttrs.reduce(function (res, key) {
976
- res[key] = _this.options[key];
977
- return res;
978
- }, {});
979
- this.sortable = new Dnd(this.el, Object.assign(Object.assign({}, props), {
980
- emptyInsertThreshold: 0,
981
- swapOnDrop: function swapOnDrop(event) {
982
- return event.from === event.to;
983
- },
984
- removeCloneOnDrop: function removeCloneOnDrop(event) {
985
- return event.from === event.to;
986
- },
987
- onDrag: function onDrag(event) {
988
- return _this.onDrag(event);
989
- },
990
- onDrop: function onDrop(event) {
991
- return _this.onDrop(event);
992
- },
993
- onChoose: function onChoose(event) {
994
- return _this.onChoose(event);
995
- },
996
- onUnchoose: function onUnchoose(event) {
997
- return _this.onUnchoose(event);
998
- }
999
- }));
1000
- }
1001
- }, {
1002
- key: "onChoose",
1003
- value: function onChoose(event) {
1004
- this.dispatchEvent('onChoose', event);
1005
- }
1006
- }, {
1007
- key: "onUnchoose",
1008
- value: function onUnchoose(event) {
1009
- this.dispatchEvent('onUnchoose', event);
1010
- }
1011
- }, {
1012
- key: "onDrag",
1013
- value: function onDrag(event) {
1014
- var dataKey = event.node.getAttribute('data-key');
1015
- var index = this.getIndex(dataKey);
1016
- var item = this.options.list[index];
1017
- var key = this.options.uniqueKeys[index];
1018
- // store the dragged item
1019
- this.sortable.option('store', {
1020
- item: item,
1021
- key: key,
1022
- index: index
1023
- });
1024
- this.dispatchEvent('onDrag', {
1025
- item: item,
1026
- key: key,
1027
- index: index,
1028
- event: event
1029
- });
1030
- }
1031
- }, {
1032
- key: "onDrop",
1033
- value: function onDrop(event) {
1034
- var _a, _b, _c;
1035
- var _ref = (_a = Dnd.get(event.from)) === null || _a === void 0 ? void 0 : _a.option('store'),
1036
- item = _ref.item,
1037
- key = _ref.key,
1038
- index = _ref.index;
1039
- var list = this.options.list;
1040
- var params = {
1041
- key: key,
1042
- item: item,
1043
- list: list,
1044
- event: event,
1045
- changed: false,
1046
- oldList: _toConsumableArray(list),
1047
- oldIndex: index,
1048
- newIndex: index
1049
- };
1050
- if (!(event.from === event.to && event.node === event.target)) {
1051
- this.handleDropEvent(event, params, index);
1052
- }
1053
- this.dispatchEvent('onDrop', params);
1054
- if (event.from === this.el && this.rangeChanged) {
1055
- (_b = Dnd.dragged) === null || _b === void 0 ? void 0 : _b.remove();
1056
- }
1057
- if (event.from !== event.to) {
1058
- (_c = Dnd.clone) === null || _c === void 0 ? void 0 : _c.remove();
1059
- }
1060
- this.rangeChanged = false;
1061
- }
1062
- }, {
1063
- key: "handleDropEvent",
1064
- value: function handleDropEvent(event, params, index) {
1065
- var targetKey = event.target.getAttribute('data-key');
1066
- var newIndex = -1;
1067
- var oldIndex = index;
1068
- // changes position in current list
1069
- if (event.from === event.to) {
1070
- // re-get the dragged element's index
1071
- oldIndex = this.getIndex(params.key);
1072
- newIndex = this.getIndex(targetKey);
1073
- if (oldIndex < newIndex && event.relative === -1 || oldIndex > newIndex && event.relative === 1) {
1074
- newIndex += event.relative;
1075
- }
1076
- if (newIndex !== oldIndex) {
1077
- params.list.splice(oldIndex, 1);
1078
- params.list.splice(newIndex, 0, params.item);
1079
- }
1080
- } else {
1081
- // remove from
1082
- if (event.from === this.el) {
1083
- oldIndex = this.getIndex(params.key);
1084
- params.list.splice(oldIndex, 1);
1085
- }
1086
- // added to
1087
- if (event.to === this.el) {
1088
- oldIndex = -1;
1089
- newIndex = this.getIndex(targetKey);
1090
- if (event.relative === 0) {
1091
- // added to last
1092
- newIndex = params.list.length;
1093
- } else if (event.relative === 1) {
1094
- newIndex += event.relative;
1095
- }
1096
- params.list.splice(newIndex, 0, params.item);
1097
- }
1098
- }
1099
- params.changed = event.from !== event.to || newIndex !== oldIndex;
1100
- params.oldIndex = oldIndex;
1101
- params.newIndex = newIndex;
1102
- }
1103
- }, {
1104
- key: "getIndex",
1105
- value: function getIndex(key) {
1106
- if (key === null || key === undefined) {
1107
- return -1;
1108
- }
1109
- var uniqueKeys = this.options.uniqueKeys;
1110
- for (var i = 0, len = uniqueKeys.length; i < len; i++) {
1111
- if (isSameValue(uniqueKeys[i], key)) {
1112
- return i;
1113
- }
1114
- }
1115
- return -1;
1116
- }
1117
- }, {
1118
- key: "dispatchEvent",
1119
- value: function dispatchEvent(name, params) {
1120
- var cb = this.options[name];
1121
- cb && cb(params);
1122
- }
1123
- }]);
1124
- return Sortable;
1125
- }();
1126
-
1127
- var VirtualAttrs = ['size', 'keeps', 'scroller', 'direction', 'debounceTime', 'throttleTime'];
1128
890
  var Virtual = /*#__PURE__*/function () {
1129
891
  function Virtual(options) {
1130
892
  _classCallCheck(this, Virtual);
@@ -1160,7 +922,7 @@
1160
922
  this.addScrollEventListener();
1161
923
  this.checkIfUpdate(0, options.keeps - 1);
1162
924
  }
1163
- _createClass(Virtual, [{
925
+ return _createClass(Virtual, [{
1164
926
  key: "isFixed",
1165
927
  value: function isFixed() {
1166
928
  return this.sizeType === 'FIXED';
@@ -1212,12 +974,34 @@
1212
974
  }, {
1213
975
  key: "scrollToIndex",
1214
976
  value: function scrollToIndex(index) {
977
+ var align = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top';
1215
978
  if (index >= this.options.uniqueKeys.length - 1) {
1216
979
  this.scrollToBottom();
1217
- } else {
1218
- var indexOffset = this.getOffsetByRange(0, index);
1219
- var startOffset = this.getScrollStartOffset();
1220
- this.scrollToOffset(indexOffset + startOffset);
980
+ return;
981
+ }
982
+ if (index < 0) {
983
+ this.scrollToOffset(0);
984
+ return;
985
+ }
986
+ var offset = this.getOffset();
987
+ var clientSize = this.getClientSize();
988
+ // calc item position
989
+ var itemSize = this.getSize(this.options.uniqueKeys[index]);
990
+ var itemTop = this.getOffsetByRange(0, index) + this.getScrollStartOffset();
991
+ var itemBottom = itemTop + itemSize;
992
+ var viewportTop = offset;
993
+ var viewportBottom = offset + clientSize;
994
+ if (align === 'auto') {
995
+ if (itemTop >= viewportTop && itemBottom <= viewportBottom) {
996
+ return;
997
+ }
998
+ align = itemTop < viewportTop ? 'top' : 'bottom';
999
+ }
1000
+ if (align === 'top') {
1001
+ this.scrollToOffset(itemTop);
1002
+ } else if (align === 'bottom') {
1003
+ var targetOffset = Math.max(0, itemBottom - clientSize);
1004
+ this.scrollToOffset(targetOffset);
1221
1005
  }
1222
1006
  }
1223
1007
  }, {
@@ -1228,14 +1012,16 @@
1228
1012
  this.scrollToOffset(offset);
1229
1013
  // if the bottom is not reached, execute the scroll method again
1230
1014
  setTimeout(function () {
1231
- var clientSize = _this.getClientSize();
1232
- var scrollSize = _this.getScrollSize();
1233
- var scrollOffset = _this.getOffset();
1234
- if (scrollOffset + clientSize + 1 < scrollSize) {
1015
+ if (!_this.isReachedBottom()) {
1235
1016
  _this.scrollToBottom();
1236
1017
  }
1237
1018
  }, 5);
1238
1019
  }
1020
+ }, {
1021
+ key: "isReachedBottom",
1022
+ value: function isReachedBottom() {
1023
+ return this.getOffset() + this.getClientSize() + 1 >= this.getScrollSize();
1024
+ }
1239
1025
  }, {
1240
1026
  key: "option",
1241
1027
  value: function option(key, value) {
@@ -1250,7 +1036,7 @@
1250
1036
  });
1251
1037
  }
1252
1038
  if (key === 'scroller') {
1253
- oldValue && Dnd.utils.off(oldValue, 'scroll', this.onScroll);
1039
+ oldValue && Sortable.utils.off(oldValue, 'scroll', this.onScroll);
1254
1040
  this.updateScrollElement();
1255
1041
  this.addScrollEventListener();
1256
1042
  }
@@ -1267,8 +1053,8 @@
1267
1053
  this.handleUpdate(start);
1268
1054
  }
1269
1055
  }, {
1270
- key: "onItemResized",
1271
- value: function onItemResized(key, size) {
1056
+ key: "updateItemSize",
1057
+ value: function updateItemSize(key, size) {
1272
1058
  if (!size || this.sizes.get(key) === size) {
1273
1059
  return;
1274
1060
  }
@@ -1297,21 +1083,21 @@
1297
1083
  key: "addScrollEventListener",
1298
1084
  value: function addScrollEventListener() {
1299
1085
  if (this.options.scroller) {
1300
- Dnd.utils.on(this.options.scroller, 'scroll', this.onScroll);
1086
+ Sortable.utils.on(this.options.scroller, 'scroll', this.onScroll);
1301
1087
  }
1302
1088
  }
1303
1089
  }, {
1304
1090
  key: "removeScrollEventListener",
1305
1091
  value: function removeScrollEventListener() {
1306
1092
  if (this.options.scroller) {
1307
- Dnd.utils.off(this.options.scroller, 'scroll', this.onScroll);
1093
+ Sortable.utils.off(this.options.scroller, 'scroll', this.onScroll);
1308
1094
  }
1309
1095
  }
1310
1096
  }, {
1311
1097
  key: "enableScroll",
1312
1098
  value: function enableScroll(scrollable) {
1313
1099
  var scroller = this.options.scroller;
1314
- var eventFn = scrollable ? Dnd.utils.off : Dnd.utils.on;
1100
+ var eventFn = scrollable ? Sortable.utils.off : Sortable.utils.on;
1315
1101
  var wheelEvent = 'onwheel' in document.createElement('div') ? 'wheel' : 'mousewheel';
1316
1102
  eventFn(scroller, 'DOMMouseScroll', this.preventDefault);
1317
1103
  eventFn(scroller, wheelEvent, this.preventDefault);
@@ -1458,11 +1244,12 @@
1458
1244
  }, {
1459
1245
  key: "handleUpdate",
1460
1246
  value: function handleUpdate(start) {
1247
+ var rangeChanged = this.range.start !== start;
1461
1248
  this.range.start = start;
1462
1249
  this.range.end = this.getEndByStart(start);
1463
1250
  this.range.front = this.getFrontOffset();
1464
1251
  this.range.behind = this.getBehindOffset();
1465
- this.options.onUpdate(Object.assign({}, this.range));
1252
+ this.options.onUpdate(Object.assign({}, this.range), rangeChanged);
1466
1253
  }
1467
1254
  }, {
1468
1255
  key: "getFrontOffset",
@@ -1526,20 +1313,234 @@
1526
1313
  var offset = 0;
1527
1314
  if (scroller && wrapper) {
1528
1315
  var offsetKey = this.isHorizontal() ? 'left' : 'top';
1529
- var rect = elementIsDocumentOrWindow(scroller) ? Dnd.utils.getRect(wrapper) : Dnd.utils.getRect(wrapper, true, scroller);
1316
+ var rect = elementIsDocumentOrWindow(scroller) ? Sortable.utils.getRect(wrapper) : Sortable.utils.getRect(wrapper, true, scroller);
1530
1317
  offset = this.offset + rect[offsetKey];
1531
1318
  }
1532
1319
  return offset;
1533
1320
  }
1534
1321
  }]);
1535
- return Virtual;
1322
+ }();
1323
+
1324
+ var SortableAttrs = ['delay', 'group', 'handle', 'lockAxis', 'disabled', 'sortable', 'draggable', 'animation', 'autoScroll', 'ghostClass', 'ghostStyle', 'chosenClass', 'scrollSpeed', 'appendToBody', 'ghostContainer', 'scrollThreshold', 'delayOnTouchOnly', 'placeholderClass', 'dropOnAnimationEnd'];
1325
+ var VirtualAttrs = ['size', 'keeps', 'scroller', 'direction', 'uniqueKeys', 'debounceTime', 'throttleTime'];
1326
+ var VirtualSortable = /*#__PURE__*/function () {
1327
+ function VirtualSortable(el, options) {
1328
+ _classCallCheck(this, VirtualSortable);
1329
+ this.el = el;
1330
+ this.options = options;
1331
+ this.initVirtual();
1332
+ this.initSortable();
1333
+ }
1334
+ return _createClass(VirtualSortable, [{
1335
+ key: "destroy",
1336
+ value: function destroy() {
1337
+ this.virtual.removeScrollEventListener();
1338
+ this.sortable.destroy();
1339
+ }
1340
+ }, {
1341
+ key: "option",
1342
+ value: function option(key, value) {
1343
+ this.options[key] = value;
1344
+ if (VirtualAttrs.includes(key)) {
1345
+ this.virtual.option(key, value);
1346
+ }
1347
+ if (SortableAttrs.includes(key)) {
1348
+ this.sortable.option(key, value);
1349
+ }
1350
+ }
1351
+ }, {
1352
+ key: "call",
1353
+ value: function call(method) {
1354
+ if (method in this.virtual) {
1355
+ var func = this.virtual[method];
1356
+ if (typeof func === 'function') {
1357
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1358
+ args[_key - 1] = arguments[_key];
1359
+ }
1360
+ return func.apply(this.virtual, args);
1361
+ }
1362
+ throw new Error("Property ".concat(String(method), " is not a function on Virtual."));
1363
+ } else {
1364
+ throw new Error("Method ".concat(String(method), " does not exist on Virtual."));
1365
+ }
1366
+ }
1367
+ // ========================================== virtual ==========================================
1368
+ }, {
1369
+ key: "initVirtual",
1370
+ value: function initVirtual() {
1371
+ var _this = this;
1372
+ var props = VirtualAttrs.reduce(function (res, key) {
1373
+ res[key] = _this.options[key];
1374
+ return res;
1375
+ }, {});
1376
+ this.virtual = new Virtual(Object.assign(Object.assign({}, props), {
1377
+ buffer: this.options.buffer,
1378
+ wrapper: this.options.wrapper,
1379
+ scroller: this.options.scroller,
1380
+ uniqueKeys: this.options.uniqueKeys,
1381
+ onScroll: function onScroll(event) {
1382
+ return _this.onScroll(event);
1383
+ },
1384
+ onUpdate: function onUpdate(range, changed) {
1385
+ return _this.onUpdate(range, changed);
1386
+ }
1387
+ }));
1388
+ }
1389
+ }, {
1390
+ key: "onScroll",
1391
+ value: function onScroll(event) {
1392
+ this.dispatchEvent('onScroll', event);
1393
+ }
1394
+ }, {
1395
+ key: "onUpdate",
1396
+ value: function onUpdate(range, changed) {
1397
+ if (this.sortableState === 'dragging' && changed) {
1398
+ this.removeDraggedEl = true;
1399
+ }
1400
+ this.dispatchEvent('onUpdate', range, changed);
1401
+ }
1402
+ // ========================================== sortable ==========================================
1403
+ }, {
1404
+ key: "initSortable",
1405
+ value: function initSortable() {
1406
+ var _this2 = this;
1407
+ var props = SortableAttrs.reduce(function (res, key) {
1408
+ res[key] = _this2.options[key];
1409
+ return res;
1410
+ }, {});
1411
+ this.sortable = new Sortable(this.el, Object.assign(Object.assign({}, props), {
1412
+ emptyInsertThreshold: 0,
1413
+ swapOnDrop: false,
1414
+ removeCloneOnDrop: function removeCloneOnDrop(event) {
1415
+ return event.from === event.to;
1416
+ },
1417
+ onDrag: function onDrag(event) {
1418
+ return _this2.onDrag(event);
1419
+ },
1420
+ onDrop: function onDrop(event) {
1421
+ return _this2.onDrop(event);
1422
+ }
1423
+ }));
1424
+ }
1425
+ }, {
1426
+ key: "onDrag",
1427
+ value: function onDrag(event) {
1428
+ this.sortableState = 'dragging';
1429
+ var key = event.node.getAttribute('data-key');
1430
+ var index = this.getIndex(key);
1431
+ // store the dragged item
1432
+ this.sortable.option('store', {
1433
+ key: key,
1434
+ index: index
1435
+ });
1436
+ this.dispatchEvent('onDrag', {
1437
+ key: key,
1438
+ index: index,
1439
+ event: event
1440
+ });
1441
+ }
1442
+ }, {
1443
+ key: "onDrop",
1444
+ value: function onDrop(event) {
1445
+ var _a, _b;
1446
+ var _Sortable$get$option = Sortable.get(event.from).option('store'),
1447
+ key = _Sortable$get$option.key,
1448
+ index = _Sortable$get$option.index;
1449
+ var evt = {
1450
+ key: key,
1451
+ event: event,
1452
+ changed: false,
1453
+ oldIndex: index,
1454
+ newIndex: index
1455
+ };
1456
+ if (!(event.from === event.to && event.node === event.target)) {
1457
+ var eventProps = this.getEventProperties(evt, event);
1458
+ Object.assign(evt, eventProps);
1459
+ }
1460
+ this.dispatchEvent('onDrop', evt);
1461
+ if (event.from === this.el && this.removeDraggedEl) {
1462
+ (_a = Sortable.dragged) === null || _a === void 0 ? void 0 : _a.remove();
1463
+ }
1464
+ if (event.from !== event.to) {
1465
+ (_b = Sortable.clone) === null || _b === void 0 ? void 0 : _b.remove();
1466
+ }
1467
+ this.sortableState = '';
1468
+ this.removeDraggedEl = false;
1469
+ }
1470
+ }, {
1471
+ key: "getEventProperties",
1472
+ value: function getEventProperties(evt, event) {
1473
+ var key = evt.key;
1474
+ var index = evt.oldIndex;
1475
+ var targetKey = event.target.getAttribute('data-key');
1476
+ var newIndex = -1;
1477
+ var oldIndex = index;
1478
+ // changes position in current list
1479
+ if (event.from === event.to) {
1480
+ // re-get the dragged element's index
1481
+ oldIndex = this.getIndex(key);
1482
+ newIndex = this.getIndex(targetKey);
1483
+ if (oldIndex < newIndex && event.relative === -1 || oldIndex > newIndex && event.relative === 1) {
1484
+ newIndex += event.relative;
1485
+ }
1486
+ } else {
1487
+ // removed from current list
1488
+ if (event.from === this.el) {
1489
+ oldIndex = this.getIndex(key);
1490
+ }
1491
+ // added to another list
1492
+ if (event.to === this.el) {
1493
+ oldIndex = -1;
1494
+ newIndex = this.getIndex(targetKey);
1495
+ if (event.relative === 0) {
1496
+ // added to last
1497
+ newIndex = this.options.uniqueKeys.length;
1498
+ } else if (event.relative === 1) {
1499
+ newIndex += event.relative;
1500
+ }
1501
+ }
1502
+ }
1503
+ return {
1504
+ changed: event.from !== event.to || newIndex !== oldIndex,
1505
+ oldIndex: oldIndex,
1506
+ newIndex: newIndex
1507
+ };
1508
+ }
1509
+ }, {
1510
+ key: "getIndex",
1511
+ value: function getIndex(key) {
1512
+ if (key === null || key === undefined) {
1513
+ return -1;
1514
+ }
1515
+ var uniqueKeys = this.options.uniqueKeys;
1516
+ for (var i = 0, len = uniqueKeys.length; i < len; i++) {
1517
+ if (isEqual(uniqueKeys[i], key)) {
1518
+ return i;
1519
+ }
1520
+ }
1521
+ return -1;
1522
+ }
1523
+ }, {
1524
+ key: "dispatchEvent",
1525
+ value: function dispatchEvent(name) {
1526
+ // call only when the option exists
1527
+ if (name in this.options) {
1528
+ var func = this.options[name];
1529
+ if (typeof func === 'function') {
1530
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1531
+ args[_key2 - 1] = arguments[_key2];
1532
+ }
1533
+ return func.apply(this, args);
1534
+ }
1535
+ }
1536
+ }
1537
+ }]);
1536
1538
  }();
1537
1539
 
1538
1540
  function Item(props) {
1539
1541
  var dataKey = props.dataKey,
1540
- sizeKey = props.sizeKey,
1542
+ horizontal = props.horizontal,
1541
1543
  dragging = props.dragging,
1542
- chosenKey = props.chosenKey,
1543
1544
  children = props.children,
1544
1545
  onSizeChange = props.onSizeChange;
1545
1546
  var eleRef = React__namespace.useRef(null);
@@ -1547,6 +1548,7 @@
1547
1548
  var observer;
1548
1549
  if ((typeof ResizeObserver === "undefined" ? "undefined" : _typeof(ResizeObserver)) !== undefined) {
1549
1550
  observer = new ResizeObserver(function () {
1551
+ var sizeKey = horizontal ? 'offsetWidth' : 'offsetHeight';
1550
1552
  var size = eleRef.current[sizeKey];
1551
1553
  onSizeChange(dataKey, size);
1552
1554
  });
@@ -1561,14 +1563,11 @@
1561
1563
  }, [eleRef]);
1562
1564
  var itemStyle = React__namespace.useMemo(function () {
1563
1565
  var style = children.props.style || {};
1564
- var isChosen = isSameValue(dataKey, chosenKey);
1565
- if (dragging && isChosen) {
1566
- return Object.assign(style, {
1567
- display: 'none'
1568
- });
1569
- }
1570
- return style;
1571
- }, [chosenKey, dragging]);
1566
+ var isDragging = isEqual(dataKey, dragging);
1567
+ return Object.assign(Object.assign({}, style), {
1568
+ display: isDragging ? 'none' : ''
1569
+ });
1570
+ }, [dragging]);
1572
1571
  return /*#__PURE__*/React__namespace.cloneElement(children, {
1573
1572
  'data-key': dataKey,
1574
1573
  role: 'item',
@@ -1584,35 +1583,30 @@
1584
1583
  start = props.start,
1585
1584
  end = props.end,
1586
1585
  dataKey = props.dataKey,
1587
- sizeKey = props.sizeKey,
1586
+ horizontal = props.horizontal,
1588
1587
  dragging = props.dragging,
1589
- chosenKey = props.chosenKey,
1590
1588
  children = props.children,
1591
1589
  onSizeChange = props.onSizeChange;
1592
- return list.slice(start, end + 1).map(function (item, i) {
1593
- var index = start + i;
1594
- var key = getDataKey(item, dataKey);
1595
- return /*#__PURE__*/React__namespace.createElement(Item$1, {
1596
- key: key,
1597
- dataKey: key,
1598
- sizeKey: sizeKey,
1599
- dragging: dragging,
1600
- chosenKey: chosenKey,
1601
- onSizeChange: onSizeChange
1602
- }, typeof children === 'function' ? children(item, index, key) : children);
1603
- });
1590
+ return React__namespace.useMemo(function () {
1591
+ return list.slice(start, end + 1).map(function (item, i) {
1592
+ var index = start + i;
1593
+ var key = getDataKey(item, dataKey);
1594
+ return /*#__PURE__*/React__namespace.createElement(Item$1, {
1595
+ key: key,
1596
+ dataKey: key,
1597
+ dragging: dragging,
1598
+ horizontal: horizontal,
1599
+ onSizeChange: onSizeChange
1600
+ }, typeof children === 'function' ? children(item, index, key) : children);
1601
+ });
1602
+ }, [list, start, end, dataKey, horizontal, dragging, children]);
1604
1603
  }
1605
1604
 
1606
1605
  function useCombine(states, effect) {
1607
1606
  React__namespace.useEffect(effect, Object.values(states));
1608
1607
  }
1609
1608
 
1610
- var Emits = {
1611
- drag: 'onDrag',
1612
- drop: 'onDrop',
1613
- top: 'onTop',
1614
- bottom: 'onBottom'
1615
- };
1609
+ var draggingItem;
1616
1610
  function VirtualList(props, ref) {
1617
1611
  var _props$dataKey = props.dataKey,
1618
1612
  dataKey = _props$dataKey === void 0 ? '' : _props$dataKey,
@@ -1675,12 +1669,14 @@
1675
1669
  chosenClass = _props$chosenClass === void 0 ? '' : _props$chosenClass,
1676
1670
  _props$placeholderCla = props.placeholderClass,
1677
1671
  placeholderClass = _props$placeholderCla === void 0 ? '' : _props$placeholderCla,
1678
- _props$fallbackOnBody = props.fallbackOnBody,
1679
- fallbackOnBody = _props$fallbackOnBody === void 0 ? false : _props$fallbackOnBody,
1672
+ _props$appendToBody = props.appendToBody,
1673
+ appendToBody = _props$appendToBody === void 0 ? false : _props$appendToBody,
1680
1674
  _props$scrollThreshol = props.scrollThreshold,
1681
1675
  scrollThreshold = _props$scrollThreshol === void 0 ? 55 : _props$scrollThreshol,
1682
1676
  _props$delayOnTouchOn = props.delayOnTouchOnly,
1683
- delayOnTouchOnly = _props$delayOnTouchOn === void 0 ? false : _props$delayOnTouchOn;
1677
+ delayOnTouchOnly = _props$delayOnTouchOn === void 0 ? false : _props$delayOnTouchOn,
1678
+ _props$dropOnAnimatio = props.dropOnAnimationEnd,
1679
+ dropOnAnimationEnd = _props$dropOnAnimatio === void 0 ? true : _props$dropOnAnimatio;
1684
1680
  var _React$useState = React__namespace.useState({
1685
1681
  start: 0,
1686
1682
  end: keeps - 1,
@@ -1690,57 +1686,52 @@
1690
1686
  _React$useState2 = _slicedToArray(_React$useState, 2),
1691
1687
  range = _React$useState2[0],
1692
1688
  setRange = _React$useState2[1];
1693
- var dragging = React__namespace.useRef(false);
1694
- var chosenKey = React__namespace.useRef('');
1695
- var uniqueKeys = React__namespace.useRef([]);
1696
- var rootRef = React__namespace.useRef();
1697
- var wrapRef = React__namespace.useRef();
1689
+ var dragging = React__namespace.useRef('');
1690
+ var rootElRef = React__namespace.useRef();
1691
+ var wrapElRef = React__namespace.useRef();
1698
1692
  /**
1699
1693
  * git item size by data-key
1700
1694
  */
1701
1695
  var getSize = function getSize(key) {
1702
- return virtualRef.current.getSize(key);
1696
+ return VS.current.call('getSize', key);
1703
1697
  };
1704
1698
  /**
1705
1699
  * Get the current scroll height
1706
1700
  */
1707
1701
  var getOffset = function getOffset() {
1708
- return virtualRef.current.getOffset();
1702
+ return VS.current.call('getOffset');
1709
1703
  };
1710
1704
  /**
1711
1705
  * Get client viewport size
1712
1706
  */
1713
1707
  var getClientSize = function getClientSize() {
1714
- return virtualRef.current.getClientSize();
1708
+ return VS.current.call('getClientSize');
1715
1709
  };
1716
1710
  /**
1717
1711
  * Get all scroll size
1718
1712
  */
1719
1713
  var getScrollSize = function getScrollSize() {
1720
- return virtualRef.current.getScrollSize();
1714
+ return VS.current.call('getScrollSize');
1721
1715
  };
1722
1716
  /**
1723
1717
  * Scroll to the specified offset
1724
1718
  */
1725
1719
  var scrollToOffset = function scrollToOffset(offset) {
1726
- var _a;
1727
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.scrollToOffset(offset);
1720
+ VS.current.call('scrollToOffset', offset);
1728
1721
  };
1729
1722
  /**
1730
1723
  * Scroll to the specified index position
1731
1724
  */
1732
- var scrollToIndex = function scrollToIndex(index) {
1733
- var _a;
1734
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.scrollToIndex(index);
1725
+ var scrollToIndex = function scrollToIndex(index, align) {
1726
+ VS.current.call('scrollToIndex', index, align);
1735
1727
  };
1736
1728
  /**
1737
1729
  * Scroll to the specified data-key position
1738
1730
  */
1739
- var scrollToKey = function scrollToKey(key) {
1740
- var _a;
1731
+ var scrollToKey = function scrollToKey(key, align) {
1741
1732
  var index = uniqueKeys.current.indexOf(key);
1742
1733
  if (index > -1) {
1743
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.scrollToIndex(index);
1734
+ VS.current.call('scrollToIndex', index, align);
1744
1735
  }
1745
1736
  };
1746
1737
  /**
@@ -1753,8 +1744,7 @@
1753
1744
  * Scroll to bottom of list
1754
1745
  */
1755
1746
  var scrollToBottom = function scrollToBottom() {
1756
- var _a;
1757
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.scrollToBottom();
1747
+ VS.current.call('scrollToBottom');
1758
1748
  };
1759
1749
  React__namespace.useImperativeHandle(ref, function () {
1760
1750
  return {
@@ -1769,85 +1759,68 @@
1769
1759
  scrollToBottom: scrollToBottom
1770
1760
  };
1771
1761
  });
1762
+ // ========================================== data source ==========================================
1763
+ var list = React__namespace.useRef([]);
1764
+ var uniqueKeys = React__namespace.useRef([]);
1765
+ var lastListLength = React__namespace.useRef(0);
1766
+ var listLengthWhenTopLoading = React__namespace.useRef(0);
1767
+ React__namespace.useEffect(function () {
1768
+ var _a;
1769
+ list.current = dataSource;
1770
+ updateUniqueKeys();
1771
+ detectRangeChange(lastListLength.current, dataSource.length);
1772
+ // if auto scroll to the last offset
1773
+ if (listLengthWhenTopLoading.current && props.keepOffset) {
1774
+ var index = dataSource.length - listLengthWhenTopLoading.current;
1775
+ if (index > 0) {
1776
+ (_a = VS.current) === null || _a === void 0 ? void 0 : _a.call('scrollToIndex', index);
1777
+ }
1778
+ listLengthWhenTopLoading.current = 0;
1779
+ }
1780
+ lastListLength.current = dataSource.length;
1781
+ }, [dataSource]);
1772
1782
  React__namespace.useEffect(function () {
1773
- installVirtual();
1774
- installSortable();
1783
+ initVirtualSortable();
1775
1784
  return function () {
1776
- var _a, _b;
1777
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.removeScrollEventListener();
1778
- (_b = sortableRef.current) === null || _b === void 0 ? void 0 : _b.destroy();
1785
+ VS.current.destroy();
1779
1786
  };
1780
1787
  }, []);
1781
- // ========================================== use virtual ==========================================
1782
- var topLoading = React__namespace.useRef(false);
1783
- var virtualRef = React__namespace.useRef();
1784
- var virtualCombinedStates = {
1785
- size: size,
1786
- keeps: keeps,
1787
- scroller: scroller,
1788
- direction: direction,
1789
- debounceTime: debounceTime,
1790
- throttleTime: throttleTime
1791
- };
1792
- var handleToTop = debounce(function () {
1793
- var _a;
1794
- topLoading.current = true;
1795
- (_a = props[Emits.top]) === null || _a === void 0 ? void 0 : _a.call(props);
1796
- }, 50);
1797
- var handleToBottom = debounce(function () {
1788
+ var updateUniqueKeys = function updateUniqueKeys() {
1798
1789
  var _a;
1799
- (_a = props[Emits.bottom]) === null || _a === void 0 ? void 0 : _a.call(props);
1800
- }, 50);
1801
- var onScroll = function onScroll(event) {
1802
- topLoading.current = false;
1803
- if (event.top) {
1804
- handleToTop();
1805
- } else if (event.bottom) {
1806
- handleToBottom();
1807
- }
1808
- };
1809
- var onUpdate = function onUpdate(range) {
1810
- setRange(function (current) {
1811
- if (sortableRef.current && dragging.current && range.start !== current.start) {
1812
- sortableRef.current.rangeChanged = true;
1813
- }
1814
- return range;
1790
+ uniqueKeys.current = list.current.map(function (item) {
1791
+ return getDataKey(item, dataKey);
1815
1792
  });
1793
+ (_a = VS.current) === null || _a === void 0 ? void 0 : _a.option('uniqueKeys', uniqueKeys.current);
1816
1794
  };
1817
- var installVirtual = function installVirtual() {
1818
- virtualRef.current = new Virtual(Object.assign(Object.assign({}, virtualCombinedStates), {
1819
- buffer: Math.round(keeps / 3),
1820
- wrapper: wrapRef.current,
1821
- scroller: scroller || rootRef.current,
1822
- uniqueKeys: uniqueKeys.current,
1823
- onScroll: onScroll,
1824
- onUpdate: onUpdate
1825
- }));
1795
+ var detectRangeChange = function detectRangeChange(oldListLength, newListLength) {
1796
+ var _a, _b;
1797
+ if (oldListLength === newListLength) {
1798
+ return;
1799
+ }
1800
+ var newRange = Object.assign({}, range);
1801
+ if (oldListLength > keeps && newListLength > oldListLength && newRange.end === oldListLength - 1 && ((_a = VS.current) === null || _a === void 0 ? void 0 : _a.call('isReachedBottom'))) {
1802
+ newRange.start++;
1803
+ }
1804
+ (_b = VS.current) === null || _b === void 0 ? void 0 : _b.call('updateRange', newRange);
1826
1805
  };
1827
- useCombine(virtualCombinedStates, function () {
1828
- VirtualAttrs.forEach(function (key) {
1829
- var _a;
1830
- if (props[key] !== undefined) {
1831
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.option(key, props[key]);
1832
- }
1833
- });
1834
- });
1835
- var lastLength = React__namespace.useRef(0);
1836
- React__namespace.useEffect(function () {
1837
- var _a;
1838
- // if auto scroll to the last offset
1839
- if (lastLength.current && topLoading.current && props.keepOffset) {
1840
- var index = Math.abs(dataSource.length - lastLength.current);
1841
- if (index > 0) {
1842
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.scrollToIndex(index);
1843
- }
1844
- topLoading.current = false;
1806
+ var dispatchEvent = function dispatchEvent(name) {
1807
+ var handler = props[name];
1808
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1809
+ args[_key - 1] = arguments[_key];
1845
1810
  }
1846
- lastLength.current = dataSource.length;
1847
- }, [dataSource]);
1848
- // ========================================== use dnd ==========================================
1849
- var sortableRef = React__namespace.useRef();
1850
- var sortableCombinedStates = {
1811
+ handler && handler.apply(null, args);
1812
+ };
1813
+ // ========================================== virtual sortable ==========================================
1814
+ var VS = React__namespace.useRef();
1815
+ var combinedAttrs = {
1816
+ // virtual attrs
1817
+ size: size,
1818
+ keeps: keeps,
1819
+ scroller: scroller,
1820
+ direction: direction,
1821
+ debounceTime: debounceTime,
1822
+ throttleTime: throttleTime,
1823
+ // sortable attrs
1851
1824
  delay: delay,
1852
1825
  group: group,
1853
1826
  handle: handle,
@@ -1861,142 +1834,139 @@
1861
1834
  ghostStyle: ghostStyle,
1862
1835
  chosenClass: chosenClass,
1863
1836
  scrollSpeed: scrollSpeed,
1864
- fallbackOnBody: fallbackOnBody,
1837
+ appendToBody: appendToBody,
1865
1838
  scrollThreshold: scrollThreshold,
1866
1839
  delayOnTouchOnly: delayOnTouchOnly,
1867
- placeholderClass: placeholderClass
1868
- };
1869
- var onChoose = function onChoose(event) {
1870
- chosenKey.current = event.node.getAttribute('data-key');
1840
+ placeholderClass: placeholderClass,
1841
+ dropOnAnimationEnd: dropOnAnimationEnd
1871
1842
  };
1872
- var onUnchoose = function onUnchoose() {
1873
- chosenKey.current = '';
1874
- };
1875
- var onDrag = function onDrag(event) {
1876
- var _a, _b, _c;
1877
- dragging.current = true;
1878
- if (!sortable) {
1879
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.enableScroll(false);
1880
- (_b = sortableRef.current) === null || _b === void 0 ? void 0 : _b.option('autoScroll', false);
1881
- }
1882
- (_c = props[Emits.drag]) === null || _c === void 0 ? void 0 : _c.call(props, event);
1883
- };
1884
- var onDrop = function onDrop(event) {
1885
- var _a, _b, _c;
1886
- dragging.current = false;
1887
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.enableScroll(true);
1888
- (_b = sortableRef.current) === null || _b === void 0 ? void 0 : _b.option('autoScroll', props.autoScroll);
1889
- var params = Object.assign(Object.assign({}, event), {
1890
- list: _toConsumableArray(event.list)
1891
- });
1892
- (_c = props[Emits.drop]) === null || _c === void 0 ? void 0 : _c.call(props, params);
1893
- };
1894
- var installSortable = function installSortable() {
1895
- sortableRef.current = new Sortable(rootRef.current, Object.assign(Object.assign({}, sortableCombinedStates), {
1896
- list: dataSource,
1843
+ var initVirtualSortable = function initVirtualSortable() {
1844
+ VS.current = new VirtualSortable(rootElRef.current, Object.assign(Object.assign({}, combinedAttrs), {
1845
+ buffer: Math.round(keeps / 3),
1846
+ wrapper: wrapElRef.current,
1847
+ scroller: scroller || rootElRef.current,
1897
1848
  uniqueKeys: uniqueKeys.current,
1849
+ ghostContainer: wrapElRef.current,
1898
1850
  onDrag: onDrag,
1899
1851
  onDrop: onDrop,
1900
- onChoose: onChoose,
1901
- onUnchoose: onUnchoose
1852
+ onScroll: onScroll,
1853
+ onUpdate: onUpdate
1902
1854
  }));
1903
1855
  };
1904
- useCombine(sortableCombinedStates, function () {
1905
- SortableAttrs.forEach(function (key) {
1906
- var _a;
1907
- if (props[key] !== undefined) {
1908
- (_a = sortableRef.current) === null || _a === void 0 ? void 0 : _a.option(key, props[key]);
1856
+ useCombine(combinedAttrs, function () {
1857
+ if (!VS.current) return;
1858
+ Object.keys(combinedAttrs).forEach(function (key) {
1859
+ if (props[key] !== void 0) {
1860
+ VS.current.option(key, props[key]);
1909
1861
  }
1910
1862
  });
1911
1863
  });
1912
- // ========================================== layout ==========================================
1913
- var list = React__namespace.useRef([]);
1914
- React__namespace.useEffect(function () {
1915
- var _a;
1916
- updateUniqueKeys();
1917
- updateRange(list.current, dataSource);
1918
- list.current = dataSource;
1919
- (_a = sortableRef.current) === null || _a === void 0 ? void 0 : _a.option('list', dataSource);
1920
- }, [dataSource]);
1921
- var updateUniqueKeys = function updateUniqueKeys() {
1922
- var _a, _b;
1923
- uniqueKeys.current = dataSource.map(function (item) {
1924
- return getDataKey(item, dataKey);
1925
- });
1926
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.option('uniqueKeys', uniqueKeys.current);
1927
- (_b = sortableRef.current) === null || _b === void 0 ? void 0 : _b.option('uniqueKeys', uniqueKeys.current);
1928
- };
1929
- var updateRange = function updateRange(oldList, newList) {
1930
- var _a;
1931
- if (!oldList.length && !newList.length) {
1932
- return;
1933
- }
1934
- if (oldList.length === newList.length) {
1935
- return;
1936
- }
1937
- var newRange = Object.assign({}, range);
1938
- if (oldList.length > keeps && newList.length > oldList.length && newRange.end === oldList.length - 1 && scrolledToBottom()) {
1939
- newRange.start++;
1864
+ var handleToTop = debounce(function () {
1865
+ listLengthWhenTopLoading.current = list.current.length;
1866
+ dispatchEvent('onTop');
1867
+ }, 50);
1868
+ var handleToBottom = debounce(function () {
1869
+ dispatchEvent('onBottom');
1870
+ }, 50);
1871
+ var onScroll = function onScroll(event) {
1872
+ listLengthWhenTopLoading.current = 0;
1873
+ if (event.top) {
1874
+ handleToTop();
1875
+ } else if (event.bottom) {
1876
+ handleToBottom();
1940
1877
  }
1941
- (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.updateRange(newRange);
1942
1878
  };
1943
- var scrolledToBottom = function scrolledToBottom() {
1944
- var offset = getOffset();
1945
- var clientSize = getClientSize();
1946
- var scrollSize = getScrollSize();
1947
- return offset + clientSize + 1 >= scrollSize;
1879
+ var onUpdate = function onUpdate(range, changed) {
1880
+ setRange(range);
1881
+ changed && dispatchEvent('onRangeChange', range);
1948
1882
  };
1949
1883
  var onSizeChange = function onSizeChange(key, size) {
1950
- var _a, _b;
1951
1884
  // ignore changes for dragging element
1952
- if (isSameValue(key, chosenKey.current)) {
1885
+ if (isEqual(key, dragging.current) || !VS.current) {
1953
1886
  return;
1954
1887
  }
1955
- var sizes = (_a = virtualRef.current) === null || _a === void 0 ? void 0 : _a.sizes.size;
1956
- (_b = virtualRef.current) === null || _b === void 0 ? void 0 : _b.onItemResized(key, size);
1957
- if (sizes === keeps - 1 && dataSource.length > keeps) {
1958
- virtualRef.current.updateRange(Object.assign({}, range));
1888
+ var sizes = VS.current.virtual.sizes.size;
1889
+ VS.current.call('updateItemSize', key, size);
1890
+ if (sizes === keeps - 1 && list.current.length > keeps) {
1891
+ VS.current.call('updateRange', range);
1959
1892
  }
1960
1893
  };
1894
+ var onDrag = function onDrag(event) {
1895
+ var _a, _b;
1896
+ var key = event.key,
1897
+ index = event.index;
1898
+ var item = list.current[index];
1899
+ dragging.current = key;
1900
+ draggingItem = item;
1901
+ if (!sortable) {
1902
+ (_a = VS.current) === null || _a === void 0 ? void 0 : _a.call('enableScroll', false);
1903
+ (_b = VS.current) === null || _b === void 0 ? void 0 : _b.option('autoScroll', false);
1904
+ }
1905
+ dispatchEvent('onDrag', Object.assign(Object.assign({}, event), {
1906
+ item: item
1907
+ }));
1908
+ };
1909
+ var onDrop = function onDrop(event) {
1910
+ var item = draggingItem;
1911
+ var oldIndex = event.oldIndex,
1912
+ newIndex = event.newIndex;
1913
+ var oldList = _toConsumableArray(list.current);
1914
+ var newList = _toConsumableArray(list.current);
1915
+ if (oldIndex === -1) {
1916
+ newList.splice(newIndex, 0, item);
1917
+ } else if (newIndex === -1) {
1918
+ newList.splice(oldIndex, 1);
1919
+ } else {
1920
+ newList.splice(oldIndex, 1);
1921
+ newList.splice(newIndex, 0, item);
1922
+ }
1923
+ VS.current.call('enableScroll', true);
1924
+ VS.current.option('autoScroll', props.autoScroll);
1925
+ dragging.current = '';
1926
+ dispatchEvent('onDrop', Object.assign(Object.assign({}, event), {
1927
+ item: item,
1928
+ list: newList,
1929
+ oldList: oldList
1930
+ }));
1931
+ };
1932
+ // ========================================== layout ==========================================
1961
1933
  var _React$useMemo = React__namespace.useMemo(function () {
1962
1934
  var front = range.front,
1963
1935
  behind = range.behind;
1964
- var isHorizontal = direction !== 'vertical';
1965
- var overflowStyle = isHorizontal ? 'auto hidden' : 'hidden auto';
1936
+ var isHorizontal = direction === 'horizontal';
1937
+ var overflow = isHorizontal ? 'auto hidden' : 'hidden auto';
1966
1938
  var padding = isHorizontal ? "0px ".concat(behind, "px 0px ").concat(front, "px") : "".concat(front, "px 0px ").concat(behind, "px");
1967
- var containerStyle = Object.assign(Object.assign({}, style), {
1968
- overflow: tableMode || scroller ? '' : overflowStyle
1939
+ var rootElStyle = Object.assign(Object.assign({}, style), {
1940
+ overflow: tableMode || scroller ? '' : overflow
1969
1941
  });
1970
- var wrapperStyle = Object.assign(Object.assign({}, wrapStyle), {
1942
+ var wrapElStyle = Object.assign(Object.assign({}, wrapStyle), {
1971
1943
  padding: tableMode ? '' : padding
1972
1944
  });
1973
- var itemSizeKey = isHorizontal ? 'offsetWidth' : 'offsetHeight';
1974
1945
  return {
1975
- containerStyle: containerStyle,
1976
- wrapperStyle: wrapperStyle,
1977
- itemSizeKey: itemSizeKey
1946
+ rootElStyle: rootElStyle,
1947
+ wrapElStyle: wrapElStyle
1978
1948
  };
1979
1949
  }, [range, style, wrapStyle, scroller, tableMode, direction]),
1980
- containerStyle = _React$useMemo.containerStyle,
1981
- wrapperStyle = _React$useMemo.wrapperStyle,
1982
- itemSizeKey = _React$useMemo.itemSizeKey;
1950
+ rootElStyle = _React$useMemo.rootElStyle,
1951
+ wrapElStyle = _React$useMemo.wrapElStyle;
1983
1952
  var _React$useMemo2 = React__namespace.useMemo(function () {
1984
- var container = tableMode ? 'table' : wrapTag;
1985
- var wrapper = tableMode ? 'tbody' : wrapTag;
1986
- return [container, wrapper];
1953
+ var rootElTag = tableMode ? 'table' : wrapTag;
1954
+ var wrapElTag = tableMode ? 'tbody' : wrapTag;
1955
+ return {
1956
+ rootElTag: rootElTag,
1957
+ wrapElTag: wrapElTag
1958
+ };
1987
1959
  }, [rootTag, wrapTag, tableMode]),
1988
- _React$useMemo3 = _slicedToArray(_React$useMemo2, 2),
1989
- containerTag = _React$useMemo3[0],
1990
- wrapperTage = _React$useMemo3[1];
1960
+ rootElTag = _React$useMemo2.rootElTag,
1961
+ wrapElTag = _React$useMemo2.wrapElTag;
1991
1962
  var listChildren = useChildren({
1992
1963
  list: dataSource,
1993
1964
  start: range.start,
1994
1965
  end: range.end,
1995
1966
  dataKey: dataKey,
1996
- sizeKey: itemSizeKey,
1997
1967
  children: props.children,
1998
1968
  dragging: dragging.current,
1999
- chosenKey: chosenKey.current,
1969
+ horizontal: direction === 'horizontal',
2000
1970
  onSizeChange: onSizeChange
2001
1971
  });
2002
1972
  var TableSpacer = function TableSpacer(offset, key) {
@@ -2011,16 +1981,15 @@
2011
1981
  style: style
2012
1982
  }));
2013
1983
  };
2014
- return /*#__PURE__*/React__namespace.createElement(containerTag, {
2015
- ref: rootRef,
2016
- style: containerStyle,
1984
+ return /*#__PURE__*/React__namespace.createElement(rootElTag, {
1985
+ ref: rootElRef,
1986
+ style: rootElStyle,
2017
1987
  className: className
2018
- }, [props.header, /*#__PURE__*/React__namespace.createElement(wrapperTage, {
2019
- ref: wrapRef,
2020
- key: 'virtual-table-wrap',
2021
- style: wrapperStyle,
1988
+ }, [props.header, /*#__PURE__*/React__namespace.createElement(wrapElTag, {
1989
+ ref: wrapElRef,
1990
+ style: wrapElStyle,
2022
1991
  className: wrapClass
2023
- }, [tableMode && TableSpacer(range.front, 'virtual-table-front')].concat(_toConsumableArray(listChildren), [tableMode && TableSpacer(range.behind, 'virtual-table-behind')])), props.footer]);
1992
+ }, [tableMode && TableSpacer(range.front, 'front')].concat(_toConsumableArray(listChildren), [tableMode && TableSpacer(range.behind, 'behind')])), props.footer]);
2024
1993
  }
2025
1994
  var index = /*#__PURE__*/React__namespace.forwardRef(VirtualList);
2026
1995