react-virtual-sortable 1.1.2 → 1.1.4

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,2006 +0,0 @@
1
- /*!
2
- * react-virtual-sortable v1.1.2
3
- * open source under the MIT license
4
- * https://github.com/mfuu/react-virtual-sortable#readme
5
- */
6
-
7
- (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
9
- typeof define === 'function' && define.amd ? define(['react'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VirtualList = factory(global.React));
11
- })(this, (function (React) { 'use strict';
12
-
13
- function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () { return e[k]; }
23
- });
24
- }
25
- });
26
- }
27
- n["default"] = e;
28
- return Object.freeze(n);
29
- }
30
-
31
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
-
33
- function _arrayLikeToArray(r, a) {
34
- (null == a || a > r.length) && (a = r.length);
35
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
36
- return n;
37
- }
38
- function _arrayWithHoles(r) {
39
- if (Array.isArray(r)) return r;
40
- }
41
- function _arrayWithoutHoles(r) {
42
- if (Array.isArray(r)) return _arrayLikeToArray(r);
43
- }
44
- function _classCallCheck(a, n) {
45
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
46
- }
47
- function _defineProperties(e, r) {
48
- for (var t = 0; t < r.length; t++) {
49
- var o = r[t];
50
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
51
- }
52
- }
53
- function _createClass(e, r, t) {
54
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
55
- writable: !1
56
- }), e;
57
- }
58
- function _defineProperty(e, r, t) {
59
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
60
- value: t,
61
- enumerable: !0,
62
- configurable: !0,
63
- writable: !0
64
- }) : e[r] = t, e;
65
- }
66
- function _iterableToArray(r) {
67
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
68
- }
69
- function _iterableToArrayLimit(r, l) {
70
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
71
- if (null != t) {
72
- var e,
73
- n,
74
- i,
75
- u,
76
- a = [],
77
- f = !0,
78
- o = !1;
79
- try {
80
- if (i = (t = t.call(r)).next, 0 === l) {
81
- if (Object(t) !== t) return;
82
- f = !1;
83
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
84
- } catch (r) {
85
- o = !0, n = r;
86
- } finally {
87
- try {
88
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
89
- } finally {
90
- if (o) throw n;
91
- }
92
- }
93
- return a;
94
- }
95
- }
96
- function _nonIterableRest() {
97
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
98
- }
99
- function _nonIterableSpread() {
100
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
101
- }
102
- function _slicedToArray(r, e) {
103
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
104
- }
105
- function _toConsumableArray(r) {
106
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
107
- }
108
- function _toPrimitive(t, r) {
109
- if ("object" != typeof t || !t) return t;
110
- var e = t[Symbol.toPrimitive];
111
- if (void 0 !== e) {
112
- var i = e.call(t, r || "default");
113
- if ("object" != typeof i) return i;
114
- throw new TypeError("@@toPrimitive must return a primitive value.");
115
- }
116
- return ("string" === r ? String : Number)(t);
117
- }
118
- function _toPropertyKey(t) {
119
- var i = _toPrimitive(t, "string");
120
- return "symbol" == typeof i ? i : i + "";
121
- }
122
- function _typeof(o) {
123
- "@babel/helpers - typeof";
124
-
125
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
126
- return typeof o;
127
- } : function (o) {
128
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
129
- }, _typeof(o);
130
- }
131
- function _unsupportedIterableToArray(r, a) {
132
- if (r) {
133
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
134
- var t = {}.toString.call(r).slice(8, -1);
135
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
136
- }
137
- }
138
-
139
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
140
-
141
- function getDefaultExportFromCjs (x) {
142
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
143
- }
144
-
145
- var sortableDnd_min = {exports: {}};
146
-
147
- /*!
148
- * sortable-dnd v0.7.1
149
- * open source under the MIT license
150
- * https://github.com/mfuu/sortable-dnd#readme
151
- */
152
- sortableDnd_min.exports;
153
- (function (module, exports) {
154
- !function (t, e) {
155
- module.exports = e() ;
156
- }(commonjsGlobal, function () {
157
-
158
- function t() {
159
- return t = Object.assign ? Object.assign.bind() : function (t) {
160
- for (var e = 1; e < arguments.length; e++) {
161
- var n = arguments[e];
162
- for (var o in n) ({}).hasOwnProperty.call(n, o) && (t[o] = n[o]);
163
- }
164
- return t;
165
- }, t.apply(null, arguments);
166
- }
167
- function e(t) {
168
- return e = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) {
169
- return typeof t;
170
- } : function (t) {
171
- return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
172
- }, e(t);
173
- }
174
- var n = {
175
- capture: !1,
176
- passive: !1
177
- },
178
- o = /\s+/g;
179
- function i(t) {
180
- if ("undefined" != typeof window && window.navigator) return !!navigator.userAgent.match(t);
181
- }
182
- var r = i(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),
183
- a = i(/Edge/i),
184
- l = i(/safari/i) && !i(/chrome/i) && !i(/android/i),
185
- s = function () {
186
- var t = !1;
187
- return document.addEventListener("checkIfSupportPassive", null, {
188
- get passive() {
189
- return t = !0, !0;
190
- }
191
- }), t;
192
- }();
193
- function c(t, e, o) {
194
- window.addEventListener ? t.addEventListener(e, o, !(!s && r) && n) : window.attachEvent ? t.attachEvent("on" + e, o) : t["on" + e] = o;
195
- }
196
- function h(t, e, o) {
197
- window.removeEventListener ? t.removeEventListener(e, o, !(!s && r) && n) : window.detachEvent ? t.detachEvent("on" + e, o) : t["on" + e] = null;
198
- }
199
- function u() {
200
- return document.scrollingElement || document.documentElement;
201
- }
202
- function d(t, e, n) {
203
- if (t.getBoundingClientRect || 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
- n = n || t.parentNode;
207
- do {
208
- if (n && n.getBoundingClientRect) {
209
- var h = n.getBoundingClientRect();
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
- break;
212
- }
213
- } while (n = n.parentNode);
214
- }
215
- return {
216
- top: i,
217
- left: r,
218
- bottom: a,
219
- right: l,
220
- width: c,
221
- height: s
222
- };
223
- }
224
- }
225
- function p(t, e, n, o) {
226
- if (t) {
227
- n = n || document;
228
- do {
229
- if (null != e && (">" === e[0] ? t.parentNode === n && y(t, e) : y(t, e)) || o && t === n) return t;
230
- if (t === n) break;
231
- } while (t = t.parentNode);
232
- return null;
233
- }
234
- }
235
- function f(t, e) {
236
- if (!t || !e) return !1;
237
- if (e.compareDocumentPosition) return !!(16 & e.compareDocumentPosition(t));
238
- if (e.contains && 1 === t.nodeType) return e.contains(t) && e !== t;
239
- for (; t = t.parentNode;) if (t === e) return !0;
240
- return !1;
241
- }
242
- function m(t, e) {
243
- for (var n = t.lastElementChild; n && (n === tt.ghost || "none" === S(n, "display") || e && !y(n, e));) n = n.previousElementSibling;
244
- return n || null;
245
- }
246
- function v(t, e) {
247
- if (!t || !t.parentNode) return -1;
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
- return n;
250
- }
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
- r++;
256
- }
257
- i++;
258
- }
259
- return null;
260
- }
261
- function w(t, e) {
262
- var n = S(t),
263
- o = parseInt(n.width) - parseInt(n.paddingLeft) - parseInt(n.paddingRight) - parseInt(n.borderLeftWidth) - parseInt(n.borderRightWidth),
264
- i = g(t, 0, e),
265
- l = g(t, 1, e),
266
- s = i && S(i),
267
- c = l && S(l),
268
- h = s && parseInt(s.marginLeft) + parseInt(s.marginRight) + d(i).width,
269
- u = c && parseInt(c.marginLeft) + parseInt(c.marginRight) + d(l).width,
270
- p = a || r ? "cssFloat" : "float";
271
- if ("flex" === n.display) return "column" === n.flexDirection || "column-reverse" === n.flexDirection ? "vertical" : "horizontal";
272
- if ("grid" === n.display) return n.gridTemplateColumns.split(" ").length <= 1 ? "vertical" : "horizontal";
273
- if (i && s.float && "none" !== s.float) {
274
- var f = "left" === s.float ? "left" : "right";
275
- return !l || "both" !== c.clear && c.clear !== f ? "horizontal" : "vertical";
276
- }
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
- }
279
- function b(t, e, n) {
280
- if (t && e) if (t.classList) t.classList[n ? "add" : "remove"](e);else {
281
- var i = (" " + t.className + " ").replace(o, " ").replace(" " + e + " ", " ");
282
- t.className = (i + (n ? " " + e : "")).replace(o, " ");
283
- }
284
- }
285
- function y(t, e) {
286
- if (e) {
287
- if (">" === e[0] && (e = e.substring(1)), t) try {
288
- if (t.matches) return t.matches(e);
289
- if (t.msMatchesSelector) return t.msMatchesSelector(e);
290
- if (t.webkitMatchesSelector) return t.webkitMatchesSelector(e);
291
- } catch (t) {
292
- return !1;
293
- }
294
- return !1;
295
- }
296
- }
297
- function S(t, e, n) {
298
- var o = t && t.style;
299
- if (o) {
300
- if (void 0 === n) return document.defaultView && document.defaultView.getComputedStyle ? n = document.defaultView.getComputedStyle(t, "") : t.currentStyle && (n = t.currentStyle), void 0 === e ? n : n[e];
301
- e in o || -1 !== e.indexOf("webkit") || (e = "-webkit-" + e), o[e] = n + ("string" == typeof n ? "" : "px");
302
- }
303
- }
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) {
308
- var n,
309
- o,
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);
311
- return 2 === i ? 1 : 4 === i ? -1 : 0;
312
- }
313
- function E(t) {
314
- void 0 !== t.preventDefault && t.cancelable && t.preventDefault();
315
- }
316
- function I(e) {
317
- var n = e.sortable,
318
- o = e.name,
319
- i = e.evt,
320
- r = n.options[o];
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) {
332
- this.options = t, this.scrollEl = null, this.autoScrollInterval = null;
333
- }
334
- function T(t) {
335
- this.options = t, this.animationStack = [], this.animationCallbackId = null;
336
- }
337
- function N(t, e) {
338
- return Math.sqrt(Math.pow(t.left - e.left, 2) + Math.pow(t.top - e.top, 2));
339
- }
340
- D.prototype = {
341
- nulling: function () {
342
- this.autoScrollInterval && (clearInterval(this.autoScrollInterval), this.autoScrollInterval = null);
343
- },
344
- onStarted: function () {
345
- this.nulling(), this.autoScrollInterval = setInterval(this.autoScroll.bind(this));
346
- },
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;
365
- },
366
- autoScroll: function () {
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);
389
- }
390
- }
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;
395
- }
396
- }, T.prototype = {
397
- collect: function (t) {
398
- if (t) {
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")) {
402
- var u = d(h);
403
- if (!(u.bottom < 0 || u.right < 0)) {
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
- }
421
- l.push({
422
- el: h,
423
- rect: u
424
- });
425
- }
426
- }
427
- }
428
- this.animationStack.push(l);
429
- }
430
- },
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();
463
- },
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);
473
- }
474
- };
475
- var P,
476
- O,
477
- R,
478
- k,
479
- H,
480
- X,
481
- Y,
482
- L,
483
- W,
484
- B,
485
- A,
486
- z,
487
- j,
488
- F,
489
- G,
490
- U,
491
- V,
492
- q,
493
- K,
494
- J,
495
- Q,
496
- Z = [];
497
- function $(t) {
498
- var n,
499
- o,
500
- i,
501
- r = {},
502
- a = t.group;
503
- a && "object" === e(a) || (a = {
504
- name: a,
505
- pull: !0,
506
- put: !0,
507
- revertDrag: !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;
509
- }
510
- function tt(e, n) {
511
- if (!e || !e.nodeType || 1 !== e.nodeType) throw "Sortable-dnd: `el` must be an HTMLElement, not ".concat({}.toString.call(e));
512
- e[M] = this, this.el = e, this.options = n = t({}, n);
513
- var o = {
514
- store: null,
515
- group: "",
516
- handle: null,
517
- draggable: ">*",
518
- sortable: !0,
519
- disabled: !1,
520
- customGhost: null,
521
- lockAxis: "",
522
- direction: "",
523
- animation: 150,
524
- easing: "",
525
- chosenClass: "",
526
- placeholderClass: "",
527
- ghostClass: "",
528
- ghostStyle: {},
529
- ghostContainer: null,
530
- appendToBody: !1,
531
- autoScroll: !0,
532
- scrollThreshold: 55,
533
- scrollSpeed: {
534
- x: 10,
535
- y: 10
536
- },
537
- delay: 0,
538
- delayOnTouchOnly: !1,
539
- swapOnDrop: !0,
540
- removeCloneOnDrop: !0,
541
- dropOnAnimationEnd: !1,
542
- supportTouch: "ontouchstart" in window,
543
- touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
544
- emptyInsertThreshold: -1
545
- };
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);
549
- }
550
- return tt.prototype = {
551
- constructor: tt,
552
- _onDrag: function (t) {
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))));
569
- }
570
- },
571
- _delayedMoveHandler: function (t) {
572
- var e = t.touches ? t.touches[0] : t;
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();
574
- },
575
- _cancelStart: function () {
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);
578
- },
579
- _onStart: function (t, e) {
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,
588
- relative: 0
589
- }, Y = R.cloneNode(!0), tt.dragged = R, tt.clone = Y, tt.active = this, I({
590
- sortable: this,
591
- name: "onChoose",
592
- evt: this._getEventProperties(e)
593
- }), b(R, o.chosenClass, !0), c(q, t ? "touchmove" : "mousemove", this._nearestSortable);
594
- try {
595
- document.selection ? setTimeout(function () {
596
- return document.selection.empty();
597
- }, 0) : window.getSelection().removeAllRanges();
598
- } catch (t) {}
599
- c(document, "selectstart", E), l && S(document.body, "user-select", "none");
600
- },
601
- _onStarted: function () {
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({
604
- sortable: this,
605
- name: "onDrag",
606
- evt: this._getEventProperties(G.event)
607
- }), this.animator.animate(), this.autoScroller.onStarted();
608
- },
609
- _appendGhost: function () {
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({
617
- position: "fixed",
618
- top: i.top,
619
- left: i.left,
620
- width: i.width,
621
- height: i.height,
622
- margin: 0,
623
- zIndex: 1e5,
624
- opacity: "0.8",
625
- overflow: "hidden",
626
- boxSizing: "border-box",
627
- transform: "",
628
- transition: "",
629
- pointerEvents: "none"
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");
636
- }
637
- },
638
- _nearestSortable: function (t) {
639
- E(t);
640
- var e = t.touches && t.touches[0] || t;
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();
646
- var n = this.options.lockAxis,
647
- o = "x" === n ? G.clientX : e.clientX,
648
- i = "y" === n ? G.clientY : e.clientY,
649
- r = document.elementFromPoint(o, i),
650
- a = o - G.clientX,
651
- l = i - G.clientY;
652
- U = {
653
- event: t,
654
- clientX: o,
655
- clientY: i
656
- }, S(L, "transform", "translate3d(".concat(a, "px, ").concat(l, "px, 0)"));
657
- var s,
658
- c,
659
- h,
660
- u = (s = o, c = i, Z.reduce(function (t, e) {
661
- var n = e[M].options.emptyInsertThreshold;
662
- if (null != n) {
663
- var o = d(e),
664
- i = s >= o.left - n && s <= o.right + n,
665
- r = c >= o.top - n && c <= o.bottom + n;
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;
667
- }
668
- }, null));
669
- u && u[M]._onMove(t, r), this.autoScroller.onMove(r, U, u, this.options);
670
- }
671
- },
672
- _allowPut: function () {
673
- var t = this.options.group,
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);
676
- },
677
- _getDirection: function () {
678
- var t = this.options.draggable,
679
- e = this.options.direction;
680
- return e ? C(e, U.event, Y, this) : w(B, t);
681
- },
682
- _allowSwap: function () {
683
- var t = d(k),
684
- e = "vertical" === this._getDirection(),
685
- n = e ? "top" : "left",
686
- o = e ? "bottom" : "right",
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),
692
- c = d(l),
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);
697
- },
698
- _onMove: function (t, e) {
699
- var n = this.el,
700
- o = this.options;
701
- if (!o.disabled && this._allowPut()) {
702
- if (k = p(e, o.draggable, n), I({
703
- sortable: this,
704
- name: "onMove",
705
- evt: this._getEventProperties(t, {
706
- target: k
707
- })
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));
710
- }
711
- },
712
- _onInsert: function (t) {
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,
723
- name: "onChange",
724
- evt: this._getEventProperties(t, {
725
- to: X,
726
- target: R,
727
- newIndex: F,
728
- revertDrag: !0
729
- })
730
- })), o || I({
731
- sortable: l,
732
- name: "onRemove",
733
- evt: this._getEventProperties(t, {
734
- newIndex: -1
735
- })
736
- }), i && n !== R && (J = n, I({
737
- sortable: this,
738
- name: "onChange",
739
- evt: this._getEventProperties(t, {
740
- from: X,
741
- backToOrigin: !0
742
- })
743
- })), i || I({
744
- sortable: this,
745
- name: "onAdd",
746
- evt: this._getEventProperties(t, {
747
- oldIndex: -1
748
- })
749
- }), l.animator.animate(), this.animator.animate(), O = e;
750
- },
751
- _onChange: function (t) {
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({
754
- sortable: this,
755
- name: "onChange",
756
- evt: this._getEventProperties(t)
757
- }), this.animator.animate(), O = e;
758
- },
759
- _onDrop: function (t) {
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();
775
- },
776
- _onEnd: function (e) {
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],
782
- name: "onDrop",
783
- evt: t({}, e, o ? K : {
784
- newIndex: -1
785
- })
786
- }), I({
787
- sortable: P[M],
788
- name: "onDrop",
789
- evt: t({}, e, i ? {} : {
790
- oldIndex: -1
791
- })
792
- }), this._nulling();
793
- },
794
- _getEventProperties: function (e) {
795
- var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
796
- 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;
798
- },
799
- _nulling: function () {
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();
801
- },
802
- destroy: function () {
803
- this._cancelStart(), this._nulling(), h(this.el, "touchstart", this._onDrag), h(this.el, "mousedown", this._onDrag);
804
- var t = Z.indexOf(this.el);
805
- t > -1 && Z.splice(t, 1), this.el[M] = this.animator = this.autoScroller = null;
806
- },
807
- option: function (t, e) {
808
- if (void 0 === e) return this.options[t];
809
- this.options[t] = e, this.animator.options[t] = e, this.autoScroller.options[t] = e, "group" === t && $(this.options);
810
- }
811
- }, tt.utils = {
812
- on: c,
813
- off: h,
814
- css: S,
815
- index: v,
816
- matches: y,
817
- closest: p,
818
- getRect: d,
819
- toggleClass: b,
820
- detectDirection: w
821
- }, tt.get = function (t) {
822
- return t[M];
823
- }, tt.create = function (t, e) {
824
- return new tt(t, e);
825
- }, tt;
826
- });
827
- })(sortableDnd_min, sortableDnd_min.exports);
828
- var sortableDnd_minExports = sortableDnd_min.exports;
829
- var Sortable = /*@__PURE__*/getDefaultExportFromCjs(sortableDnd_minExports);
830
-
831
- function throttle(fn, wait) {
832
- var timer;
833
- var result = function result() {
834
- var _this = this;
835
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
836
- args[_key] = arguments[_key];
837
- }
838
- if (timer) return;
839
- if (wait <= 0) {
840
- fn.apply(this, args);
841
- } else {
842
- timer = setTimeout(function () {
843
- timer = null;
844
- fn.apply(_this, args);
845
- }, wait);
846
- }
847
- };
848
- result['cancel'] = function () {
849
- if (timer) {
850
- clearTimeout(timer);
851
- timer = null;
852
- }
853
- };
854
- return result;
855
- }
856
- function debounce(fn, wait) {
857
- var throttled = throttle(fn, wait);
858
- var result = function result() {
859
- throttled['cancel']();
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);
864
- };
865
- result['cancel'] = function () {
866
- throttled['cancel']();
867
- };
868
- return result;
869
- }
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;
880
- }
881
- function getDataKey(item, dataKey) {
882
- return (!Array.isArray(dataKey) ? dataKey.replace(/\[/g, '.').replace(/\]/g, '.').split('.') : dataKey).reduce(function (o, k) {
883
- return (o || {})[k];
884
- }, item);
885
- }
886
- function elementIsDocumentOrWindow(element) {
887
- return element instanceof Document && element.nodeType === 9 || element instanceof Window;
888
- }
889
-
890
- var Virtual = /*#__PURE__*/function () {
891
- function Virtual(options) {
892
- _classCallCheck(this, Virtual);
893
- this.options = options;
894
- var defaults = {
895
- size: 0,
896
- keeps: 0,
897
- buffer: 0,
898
- wrapper: null,
899
- scroller: null,
900
- direction: 'vertical',
901
- uniqueKeys: [],
902
- debounceTime: null,
903
- throttleTime: null
904
- };
905
- for (var name in defaults) {
906
- !(name in this.options) && (this.options[name] = defaults[name]);
907
- }
908
- this.option('buffer', options.buffer);
909
- this.sizes = new Map(); // store item size
910
- this.sizeType = 'INIT';
911
- this.fixedSize = 0;
912
- this.averageSize = 0;
913
- this.range = {
914
- start: 0,
915
- end: 0,
916
- front: 0,
917
- behind: 0
918
- };
919
- this.offset = 0;
920
- this.direction = 'STATIONARY';
921
- this.updateScrollElement();
922
- this.updateOnScrollFunction();
923
- this.addScrollEventListener();
924
- this.checkIfUpdate(0, options.keeps - 1);
925
- }
926
- return _createClass(Virtual, [{
927
- key: "isFixed",
928
- value: function isFixed() {
929
- return this.sizeType === 'FIXED';
930
- }
931
- }, {
932
- key: "isFront",
933
- value: function isFront() {
934
- return this.direction === 'FRONT';
935
- }
936
- }, {
937
- key: "isBehind",
938
- value: function isBehind() {
939
- return this.direction === 'BEHIND';
940
- }
941
- }, {
942
- key: "isHorizontal",
943
- value: function isHorizontal() {
944
- return this.options.direction === 'horizontal';
945
- }
946
- }, {
947
- key: "getSize",
948
- value: function getSize(key) {
949
- return this.sizes.get(key) || this.getItemSize();
950
- }
951
- }, {
952
- key: "getOffset",
953
- value: function getOffset() {
954
- var offsetKey = this.isHorizontal() ? 'scrollLeft' : 'scrollTop';
955
- return this.scrollEl[offsetKey];
956
- }
957
- }, {
958
- key: "getScrollSize",
959
- value: function getScrollSize() {
960
- var sizeKey = this.isHorizontal() ? 'scrollWidth' : 'scrollHeight';
961
- return this.scrollEl[sizeKey];
962
- }
963
- }, {
964
- key: "getClientSize",
965
- value: function getClientSize() {
966
- var sizeKey = this.isHorizontal() ? 'offsetWidth' : 'offsetHeight';
967
- return this.scrollEl[sizeKey];
968
- }
969
- }, {
970
- key: "scrollToOffset",
971
- value: function scrollToOffset(offset) {
972
- var offsetKey = this.isHorizontal() ? 'scrollLeft' : 'scrollTop';
973
- this.scrollEl[offsetKey] = offset;
974
- }
975
- }, {
976
- key: "scrollToIndex",
977
- value: function scrollToIndex(index) {
978
- var align = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top';
979
- if (index >= this.options.uniqueKeys.length - 1) {
980
- this.scrollToBottom();
981
- return;
982
- }
983
- if (index < 0) {
984
- this.scrollToOffset(0);
985
- return;
986
- }
987
- var offset = this.getOffset();
988
- var clientSize = this.getClientSize();
989
- // calc item position
990
- var itemSize = this.getSize(this.options.uniqueKeys[index]);
991
- var itemTop = this.getOffsetByRange(0, index) + this.getScrollStartOffset();
992
- var itemBottom = itemTop + itemSize;
993
- var viewportTop = offset;
994
- var viewportBottom = offset + clientSize;
995
- if (align === 'auto') {
996
- if (itemTop >= viewportTop && itemBottom <= viewportBottom) {
997
- return;
998
- }
999
- align = itemTop < viewportTop ? 'top' : 'bottom';
1000
- }
1001
- if (align === 'top') {
1002
- this.scrollToOffset(itemTop);
1003
- } else if (align === 'bottom') {
1004
- var targetOffset = Math.max(0, itemBottom - clientSize);
1005
- this.scrollToOffset(targetOffset);
1006
- }
1007
- }
1008
- }, {
1009
- key: "scrollToBottom",
1010
- value: function scrollToBottom() {
1011
- var _this = this;
1012
- var offset = this.getScrollSize();
1013
- this.scrollToOffset(offset);
1014
- // if the bottom is not reached, execute the scroll method again
1015
- setTimeout(function () {
1016
- if (!_this.isReachedBottom()) {
1017
- _this.scrollToBottom();
1018
- }
1019
- }, 5);
1020
- }
1021
- }, {
1022
- key: "isReachedBottom",
1023
- value: function isReachedBottom() {
1024
- return this.getOffset() + this.getClientSize() + 1 >= this.getScrollSize();
1025
- }
1026
- }, {
1027
- key: "option",
1028
- value: function option(key, value) {
1029
- var _this2 = this;
1030
- var oldValue = this.options[key];
1031
- this.options[key] = value;
1032
- if (key === 'buffer') {
1033
- if (value === undefined || value === null) {
1034
- this.buffer = Math.round(this.options.keeps / 3);
1035
- } else {
1036
- this.buffer = value;
1037
- }
1038
- }
1039
- if (key === 'uniqueKeys') {
1040
- this.sizes.forEach(function (_v, k) {
1041
- if (!value.includes(k)) {
1042
- _this2.sizes["delete"](k);
1043
- }
1044
- });
1045
- }
1046
- if (key === 'scroller') {
1047
- oldValue && Sortable.utils.off(oldValue, 'scroll', this.onScroll);
1048
- this.updateScrollElement();
1049
- this.addScrollEventListener();
1050
- }
1051
- }
1052
- }, {
1053
- key: "updateRange",
1054
- value: function updateRange(range) {
1055
- if (range) {
1056
- this.handleUpdate(range.start);
1057
- return;
1058
- }
1059
- var start = this.range.start;
1060
- start = Math.max(start, 0);
1061
- this.handleUpdate(start);
1062
- }
1063
- }, {
1064
- key: "updateItemSize",
1065
- value: function updateItemSize(key, size) {
1066
- if (!size || this.sizes.get(key) === size) {
1067
- return;
1068
- }
1069
- this.sizes.set(key, size);
1070
- if (this.sizeType === 'INIT') {
1071
- this.sizeType = 'FIXED';
1072
- this.fixedSize = size;
1073
- } else if (this.isFixed() && this.fixedSize !== size) {
1074
- this.sizeType = 'DYNAMIC';
1075
- this.fixedSize = 0;
1076
- }
1077
- // calculate the average size only once
1078
- if (!this.averageSize && this.sizeType === 'DYNAMIC' && this.sizes.size === this.options.keeps) {
1079
- this.updateAverageSize();
1080
- }
1081
- }
1082
- }, {
1083
- key: "updateAverageSize",
1084
- value: function updateAverageSize() {
1085
- var total = _toConsumableArray(this.sizes.values()).reduce(function (t, i) {
1086
- return t + i;
1087
- }, 0);
1088
- this.averageSize = Math.round(total / this.sizes.size);
1089
- }
1090
- }, {
1091
- key: "addScrollEventListener",
1092
- value: function addScrollEventListener() {
1093
- if (this.options.scroller) {
1094
- Sortable.utils.on(this.options.scroller, 'scroll', this.onScroll);
1095
- }
1096
- }
1097
- }, {
1098
- key: "removeScrollEventListener",
1099
- value: function removeScrollEventListener() {
1100
- if (this.options.scroller) {
1101
- Sortable.utils.off(this.options.scroller, 'scroll', this.onScroll);
1102
- }
1103
- }
1104
- }, {
1105
- key: "enableScroll",
1106
- value: function enableScroll(scrollable) {
1107
- var scroller = this.options.scroller;
1108
- var eventFn = scrollable ? Sortable.utils.off : Sortable.utils.on;
1109
- var wheelEvent = 'onwheel' in document.createElement('div') ? 'wheel' : 'mousewheel';
1110
- eventFn(scroller, 'DOMMouseScroll', this.preventDefault);
1111
- eventFn(scroller, wheelEvent, this.preventDefault);
1112
- eventFn(scroller, 'touchmove', this.preventDefault);
1113
- eventFn(scroller, 'keydown', this.preventDefaultForKeyDown);
1114
- }
1115
- }, {
1116
- key: "preventDefault",
1117
- value: function preventDefault(e) {
1118
- e.preventDefault();
1119
- }
1120
- }, {
1121
- key: "preventDefaultForKeyDown",
1122
- value: function preventDefaultForKeyDown(e) {
1123
- var keys = {
1124
- 37: 1,
1125
- 38: 1,
1126
- 39: 1,
1127
- 40: 1
1128
- };
1129
- if (keys[e.keyCode]) {
1130
- this.preventDefault(e);
1131
- return false;
1132
- }
1133
- }
1134
- }, {
1135
- key: "updateScrollElement",
1136
- value: function updateScrollElement() {
1137
- var scroller = this.options.scroller;
1138
- if (elementIsDocumentOrWindow(scroller)) {
1139
- var scrollEl = document.scrollingElement || document.documentElement || document.body;
1140
- this.scrollEl = scrollEl;
1141
- } else {
1142
- this.scrollEl = scroller;
1143
- }
1144
- }
1145
- }, {
1146
- key: "updateOnScrollFunction",
1147
- value: function updateOnScrollFunction() {
1148
- var _this3 = this;
1149
- var _this$options = this.options,
1150
- debounceTime = _this$options.debounceTime,
1151
- throttleTime = _this$options.throttleTime;
1152
- if (debounceTime) {
1153
- this.onScroll = debounce(function () {
1154
- return _this3.handleScroll();
1155
- }, debounceTime);
1156
- } else if (throttleTime) {
1157
- this.onScroll = throttle(function () {
1158
- return _this3.handleScroll();
1159
- }, throttleTime);
1160
- } else {
1161
- this.onScroll = function () {
1162
- return _this3.handleScroll();
1163
- };
1164
- }
1165
- }
1166
- }, {
1167
- key: "handleScroll",
1168
- value: function handleScroll() {
1169
- var offset = this.getOffset();
1170
- var clientSize = this.getClientSize();
1171
- var scrollSize = this.getScrollSize();
1172
- if (offset === this.offset) {
1173
- this.direction = 'STATIONARY';
1174
- } else {
1175
- this.direction = offset < this.offset ? 'FRONT' : 'BEHIND';
1176
- }
1177
- this.offset = offset;
1178
- var top = this.isFront() && offset <= 0;
1179
- var bottom = this.isBehind() && clientSize + offset + 1 >= scrollSize;
1180
- this.options.onScroll({
1181
- top: top,
1182
- bottom: bottom,
1183
- offset: offset,
1184
- direction: this.direction
1185
- });
1186
- if (this.isFront()) {
1187
- this.handleScrollFront();
1188
- } else if (this.isBehind()) {
1189
- this.handleScrollBehind();
1190
- }
1191
- }
1192
- }, {
1193
- key: "handleScrollFront",
1194
- value: function handleScrollFront() {
1195
- var scrolls = this.getScrollItems();
1196
- if (scrolls >= this.range.start) {
1197
- return;
1198
- }
1199
- var start = Math.max(scrolls - this.buffer, 0);
1200
- this.checkIfUpdate(start, this.getEndByStart(start));
1201
- }
1202
- }, {
1203
- key: "handleScrollBehind",
1204
- value: function handleScrollBehind() {
1205
- var scrolls = this.getScrollItems();
1206
- if (scrolls < this.range.start + this.buffer) {
1207
- return;
1208
- }
1209
- this.checkIfUpdate(scrolls, this.getEndByStart(scrolls));
1210
- }
1211
- }, {
1212
- key: "getScrollItems",
1213
- value: function getScrollItems() {
1214
- var offset = this.offset - this.getScrollStartOffset();
1215
- if (offset <= 0) {
1216
- return 0;
1217
- }
1218
- if (this.isFixed()) {
1219
- return Math.floor(offset / this.fixedSize);
1220
- }
1221
- var low = 0;
1222
- var high = this.options.uniqueKeys.length;
1223
- var middle = 0;
1224
- var middleOffset = 0;
1225
- while (low <= high) {
1226
- middle = low + Math.floor((high - low) / 2);
1227
- middleOffset = this.getOffsetByRange(0, middle);
1228
- if (middleOffset === offset) {
1229
- return middle;
1230
- } else if (middleOffset < offset) {
1231
- low = middle + 1;
1232
- } else if (middleOffset > offset) {
1233
- high = middle - 1;
1234
- }
1235
- }
1236
- return low > 0 ? --low : 0;
1237
- }
1238
- }, {
1239
- key: "checkIfUpdate",
1240
- value: function checkIfUpdate(start, end) {
1241
- var keeps = this.options.keeps;
1242
- var total = this.options.uniqueKeys.length;
1243
- if (total <= keeps) {
1244
- start = 0;
1245
- } else if (end - start < keeps - 1) {
1246
- start = end - keeps + 1;
1247
- }
1248
- if (this.range.start !== start) {
1249
- this.handleUpdate(start);
1250
- }
1251
- }
1252
- }, {
1253
- key: "handleUpdate",
1254
- value: function handleUpdate(start) {
1255
- var rangeChanged = this.range.start !== start;
1256
- this.range.start = start;
1257
- this.range.end = this.getEndByStart(start);
1258
- this.range.front = this.getFrontOffset();
1259
- this.range.behind = this.getBehindOffset();
1260
- this.options.onUpdate(Object.assign({}, this.range), rangeChanged);
1261
- }
1262
- }, {
1263
- key: "getFrontOffset",
1264
- value: function getFrontOffset() {
1265
- if (this.isFixed()) {
1266
- return this.fixedSize * this.range.start;
1267
- } else {
1268
- return this.getOffsetByRange(0, this.range.start);
1269
- }
1270
- }
1271
- }, {
1272
- key: "getBehindOffset",
1273
- value: function getBehindOffset() {
1274
- var end = this.range.end;
1275
- var last = this.getLastIndex();
1276
- if (this.isFixed()) {
1277
- return (last - end) * this.fixedSize;
1278
- }
1279
- return (last - end) * this.getItemSize();
1280
- }
1281
- }, {
1282
- key: "getOffsetByRange",
1283
- value: function getOffsetByRange(start, end) {
1284
- if (start >= end) {
1285
- return 0;
1286
- }
1287
- var offset = 0;
1288
- for (var i = start; i < end; i++) {
1289
- var size = this.sizes.get(this.options.uniqueKeys[i]);
1290
- offset = offset + (typeof size === 'number' ? size : this.getItemSize());
1291
- }
1292
- return offset;
1293
- }
1294
- }, {
1295
- key: "getEndByStart",
1296
- value: function getEndByStart(start) {
1297
- return Math.min(start + this.options.keeps - 1, this.getLastIndex());
1298
- }
1299
- }, {
1300
- key: "getLastIndex",
1301
- value: function getLastIndex() {
1302
- var _this$options2 = this.options,
1303
- uniqueKeys = _this$options2.uniqueKeys,
1304
- keeps = _this$options2.keeps;
1305
- return uniqueKeys.length > 0 ? uniqueKeys.length - 1 : keeps - 1;
1306
- }
1307
- }, {
1308
- key: "getItemSize",
1309
- value: function getItemSize() {
1310
- return this.isFixed() ? this.fixedSize : this.options.size || this.averageSize;
1311
- }
1312
- }, {
1313
- key: "getScrollStartOffset",
1314
- value: function getScrollStartOffset() {
1315
- var _this$options3 = this.options,
1316
- wrapper = _this$options3.wrapper,
1317
- scroller = _this$options3.scroller;
1318
- if (scroller === wrapper) {
1319
- return 0;
1320
- }
1321
- var offset = 0;
1322
- if (scroller && wrapper) {
1323
- var offsetKey = this.isHorizontal() ? 'left' : 'top';
1324
- var rect = elementIsDocumentOrWindow(scroller) ? Sortable.utils.getRect(wrapper) : Sortable.utils.getRect(wrapper, true, scroller);
1325
- offset = this.offset + rect[offsetKey];
1326
- }
1327
- return offset;
1328
- }
1329
- }]);
1330
- }();
1331
-
1332
- var SortableAttrs = ['delay', 'group', 'handle', 'lockAxis', 'disabled', 'sortable', 'draggable', 'animation', 'autoScroll', 'ghostClass', 'ghostStyle', 'chosenClass', 'scrollSpeed', 'appendToBody', 'ghostContainer', 'scrollThreshold', 'delayOnTouchOnly', 'placeholderClass', 'dropOnAnimationEnd'];
1333
- var VirtualAttrs = ['size', 'keeps', 'buffer', 'scroller', 'direction', 'debounceTime', 'throttleTime'];
1334
- var VirtualSortable = /*#__PURE__*/function () {
1335
- function VirtualSortable(el, options) {
1336
- _classCallCheck(this, VirtualSortable);
1337
- this.el = el;
1338
- this.options = options;
1339
- this.initVirtual();
1340
- this.initSortable();
1341
- }
1342
- return _createClass(VirtualSortable, [{
1343
- key: "destroy",
1344
- value: function destroy() {
1345
- this.virtual.removeScrollEventListener();
1346
- this.sortable.destroy();
1347
- }
1348
- }, {
1349
- key: "option",
1350
- value: function option(key, value) {
1351
- this.options[key] = value;
1352
- if (VirtualAttrs.includes(key) || key === 'uniqueKeys') {
1353
- this.virtual.option(key, value);
1354
- }
1355
- if (SortableAttrs.includes(key)) {
1356
- this.sortable.option(key, value);
1357
- }
1358
- }
1359
- }, {
1360
- key: "call",
1361
- value: function call(method) {
1362
- if (method in this.virtual) {
1363
- var func = this.virtual[method];
1364
- if (typeof func === 'function') {
1365
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1366
- args[_key - 1] = arguments[_key];
1367
- }
1368
- return func.apply(this.virtual, args);
1369
- }
1370
- throw new Error("Property ".concat(String(method), " is not a function on Virtual."));
1371
- } else {
1372
- throw new Error("Method ".concat(String(method), " does not exist on Virtual."));
1373
- }
1374
- }
1375
- // ========================================== virtual ==========================================
1376
- }, {
1377
- key: "initVirtual",
1378
- value: function initVirtual() {
1379
- var _this = this;
1380
- var props = VirtualAttrs.reduce(function (res, key) {
1381
- res[key] = _this.options[key];
1382
- return res;
1383
- }, {});
1384
- this.virtual = new Virtual(Object.assign(Object.assign({}, props), {
1385
- wrapper: this.options.wrapper,
1386
- uniqueKeys: this.options.uniqueKeys,
1387
- onScroll: function onScroll(event) {
1388
- return _this.onScroll(event);
1389
- },
1390
- onUpdate: function onUpdate(range, changed) {
1391
- return _this.onUpdate(range, changed);
1392
- }
1393
- }));
1394
- }
1395
- }, {
1396
- key: "onScroll",
1397
- value: function onScroll(event) {
1398
- this.dispatchEvent('onScroll', event);
1399
- }
1400
- }, {
1401
- key: "onUpdate",
1402
- value: function onUpdate(range, changed) {
1403
- if (this.sortableState === 'dragging' && changed) {
1404
- this.removeDraggedEl = true;
1405
- }
1406
- this.dispatchEvent('onUpdate', range, changed);
1407
- }
1408
- // ========================================== sortable ==========================================
1409
- }, {
1410
- key: "initSortable",
1411
- value: function initSortable() {
1412
- var _this2 = this;
1413
- var props = SortableAttrs.reduce(function (res, key) {
1414
- res[key] = _this2.options[key];
1415
- return res;
1416
- }, {});
1417
- this.sortable = new Sortable(this.el, Object.assign(Object.assign({}, props), {
1418
- emptyInsertThreshold: 0,
1419
- swapOnDrop: false,
1420
- removeCloneOnDrop: function removeCloneOnDrop(event) {
1421
- return event.from === event.to;
1422
- },
1423
- onDrag: function onDrag(event) {
1424
- return _this2.onDrag(event);
1425
- },
1426
- onDrop: function onDrop(event) {
1427
- return _this2.onDrop(event);
1428
- }
1429
- }));
1430
- }
1431
- }, {
1432
- key: "onDrag",
1433
- value: function onDrag(event) {
1434
- this.sortableState = 'dragging';
1435
- var key = event.node.getAttribute('data-key');
1436
- var index = this.getIndex(key);
1437
- // store the dragged item
1438
- this.sortable.option('store', {
1439
- key: key,
1440
- index: index
1441
- });
1442
- this.dispatchEvent('onDrag', {
1443
- key: key,
1444
- index: index,
1445
- event: event
1446
- });
1447
- }
1448
- }, {
1449
- key: "onDrop",
1450
- value: function onDrop(event) {
1451
- var _a, _b;
1452
- var _Sortable$get$option = Sortable.get(event.from).option('store'),
1453
- key = _Sortable$get$option.key,
1454
- index = _Sortable$get$option.index;
1455
- var evt = {
1456
- key: key,
1457
- event: event,
1458
- changed: false,
1459
- oldIndex: index,
1460
- newIndex: index
1461
- };
1462
- if (!(event.from === event.to && event.node === event.target)) {
1463
- var eventProps = this.getEventProperties(evt, event);
1464
- Object.assign(evt, eventProps);
1465
- }
1466
- this.dispatchEvent('onDrop', evt);
1467
- if (event.from === this.el && this.removeDraggedEl) {
1468
- (_a = Sortable.dragged) === null || _a === void 0 ? void 0 : _a.remove();
1469
- }
1470
- if (event.from !== event.to) {
1471
- (_b = Sortable.clone) === null || _b === void 0 ? void 0 : _b.remove();
1472
- }
1473
- this.sortableState = '';
1474
- this.removeDraggedEl = false;
1475
- }
1476
- }, {
1477
- key: "getEventProperties",
1478
- value: function getEventProperties(evt, event) {
1479
- var key = evt.key;
1480
- var index = evt.oldIndex;
1481
- var targetKey = event.target.getAttribute('data-key');
1482
- var newIndex = -1;
1483
- var oldIndex = index;
1484
- // changes position in current list
1485
- if (event.from === event.to) {
1486
- // re-get the dragged element's index
1487
- oldIndex = this.getIndex(key);
1488
- newIndex = this.getIndex(targetKey);
1489
- if (oldIndex < newIndex && event.relative === -1 || oldIndex > newIndex && event.relative === 1) {
1490
- newIndex += event.relative;
1491
- }
1492
- } else {
1493
- // removed from current list
1494
- if (event.from === this.el) {
1495
- oldIndex = this.getIndex(key);
1496
- }
1497
- // added to another list
1498
- if (event.to === this.el) {
1499
- oldIndex = -1;
1500
- newIndex = this.getIndex(targetKey);
1501
- if (event.relative === 0) {
1502
- // added to last
1503
- newIndex = this.options.uniqueKeys.length;
1504
- } else if (event.relative === 1) {
1505
- newIndex += event.relative;
1506
- }
1507
- }
1508
- }
1509
- return {
1510
- changed: event.from !== event.to || newIndex !== oldIndex,
1511
- oldIndex: oldIndex,
1512
- newIndex: newIndex
1513
- };
1514
- }
1515
- }, {
1516
- key: "getIndex",
1517
- value: function getIndex(key) {
1518
- if (key === null || key === undefined) {
1519
- return -1;
1520
- }
1521
- var uniqueKeys = this.options.uniqueKeys;
1522
- for (var i = 0, len = uniqueKeys.length; i < len; i++) {
1523
- if (isEqual(uniqueKeys[i], key)) {
1524
- return i;
1525
- }
1526
- }
1527
- return -1;
1528
- }
1529
- }, {
1530
- key: "dispatchEvent",
1531
- value: function dispatchEvent(name) {
1532
- // call only when the option exists
1533
- if (name in this.options) {
1534
- var func = this.options[name];
1535
- if (typeof func === 'function') {
1536
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1537
- args[_key2 - 1] = arguments[_key2];
1538
- }
1539
- return func.apply(this, args);
1540
- }
1541
- }
1542
- }
1543
- }]);
1544
- }();
1545
-
1546
- function Item(props) {
1547
- var dataKey = props.dataKey,
1548
- horizontal = props.horizontal,
1549
- dragging = props.dragging,
1550
- children = props.children,
1551
- onSizeChange = props.onSizeChange;
1552
- var eleRef = React__namespace.useRef(null);
1553
- React__namespace.useLayoutEffect(function () {
1554
- var observer;
1555
- if ((typeof ResizeObserver === "undefined" ? "undefined" : _typeof(ResizeObserver)) !== undefined) {
1556
- observer = new ResizeObserver(function () {
1557
- var sizeKey = horizontal ? 'offsetWidth' : 'offsetHeight';
1558
- var size = eleRef.current[sizeKey];
1559
- onSizeChange(dataKey, size);
1560
- });
1561
- eleRef.current && (observer === null || observer === void 0 ? void 0 : observer.observe(eleRef.current));
1562
- }
1563
- return function () {
1564
- if (observer) {
1565
- observer.disconnect();
1566
- observer = null;
1567
- }
1568
- };
1569
- }, [eleRef]);
1570
- var itemStyle = React__namespace.useMemo(function () {
1571
- var style = children.props.style || {};
1572
- var isDragging = isEqual(dataKey, dragging);
1573
- return Object.assign(Object.assign({}, style), {
1574
- display: isDragging ? 'none' : ''
1575
- });
1576
- }, [dragging]);
1577
- return /*#__PURE__*/React__namespace.cloneElement(children, {
1578
- 'data-key': dataKey,
1579
- role: 'item',
1580
- ref: eleRef,
1581
- style: itemStyle,
1582
- className: children.props.className
1583
- });
1584
- }
1585
- var Item$1 = /*#__PURE__*/React__namespace.memo(Item);
1586
-
1587
- function useChildren(props) {
1588
- var list = props.list,
1589
- start = props.start,
1590
- end = props.end,
1591
- dataKey = props.dataKey,
1592
- horizontal = props.horizontal,
1593
- dragging = props.dragging,
1594
- children = props.children,
1595
- onSizeChange = props.onSizeChange;
1596
- return React__namespace.useMemo(function () {
1597
- return list.slice(start, end + 1).map(function (item, i) {
1598
- var index = start + i;
1599
- var key = getDataKey(item, dataKey);
1600
- return /*#__PURE__*/React__namespace.createElement(Item$1, {
1601
- key: key,
1602
- dataKey: key,
1603
- dragging: dragging,
1604
- horizontal: horizontal,
1605
- onSizeChange: onSizeChange
1606
- }, typeof children === 'function' ? children(item, index, key) : children);
1607
- });
1608
- }, [list, start, end, dataKey, horizontal, dragging, children]);
1609
- }
1610
-
1611
- function useCombine(states, effect) {
1612
- React__namespace.useEffect(effect, Object.values(states));
1613
- }
1614
-
1615
- var draggingItem;
1616
- function VirtualList(props, ref) {
1617
- var _props$dataKey = props.dataKey,
1618
- dataKey = _props$dataKey === void 0 ? '' : _props$dataKey,
1619
- _props$dataSource = props.dataSource,
1620
- dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
1621
- _props$tableMode = props.tableMode,
1622
- tableMode = _props$tableMode === void 0 ? false : _props$tableMode,
1623
- _props$wrapTag = props.wrapTag,
1624
- wrapTag = _props$wrapTag === void 0 ? 'div' : _props$wrapTag,
1625
- _props$rootTag = props.rootTag,
1626
- rootTag = _props$rootTag === void 0 ? 'div' : _props$rootTag,
1627
- _props$style = props.style,
1628
- style = _props$style === void 0 ? {} : _props$style,
1629
- _props$className = props.className,
1630
- className = _props$className === void 0 ? '' : _props$className,
1631
- _props$wrapStyle = props.wrapStyle,
1632
- wrapStyle = _props$wrapStyle === void 0 ? {} : _props$wrapStyle,
1633
- _props$wrapClass = props.wrapClass,
1634
- wrapClass = _props$wrapClass === void 0 ? '' : _props$wrapClass,
1635
- _props$size = props.size,
1636
- size = _props$size === void 0 ? undefined : _props$size,
1637
- _props$keeps = props.keeps,
1638
- keeps = _props$keeps === void 0 ? 30 : _props$keeps,
1639
- _props$buffer = props.buffer,
1640
- buffer = _props$buffer === void 0 ? undefined : _props$buffer,
1641
- _props$scroller = props.scroller,
1642
- scroller = _props$scroller === void 0 ? undefined : _props$scroller,
1643
- _props$direction = props.direction,
1644
- direction = _props$direction === void 0 ? 'vertical' : _props$direction,
1645
- _props$debounceTime = props.debounceTime,
1646
- debounceTime = _props$debounceTime === void 0 ? 0 : _props$debounceTime,
1647
- _props$throttleTime = props.throttleTime,
1648
- throttleTime = _props$throttleTime === void 0 ? 0 : _props$throttleTime,
1649
- _props$delay = props.delay,
1650
- delay = _props$delay === void 0 ? 0 : _props$delay,
1651
- _props$group = props.group,
1652
- group = _props$group === void 0 ? '' : _props$group,
1653
- _props$handle = props.handle,
1654
- handle = _props$handle === void 0 ? '' : _props$handle,
1655
- _props$lockAxis = props.lockAxis,
1656
- lockAxis = _props$lockAxis === void 0 ? undefined : _props$lockAxis,
1657
- _props$disabled = props.disabled,
1658
- disabled = _props$disabled === void 0 ? false : _props$disabled,
1659
- _props$sortable = props.sortable,
1660
- sortable = _props$sortable === void 0 ? true : _props$sortable,
1661
- _props$draggable = props.draggable,
1662
- draggable = _props$draggable === void 0 ? '[role="item"]' : _props$draggable,
1663
- _props$animation = props.animation,
1664
- animation = _props$animation === void 0 ? 150 : _props$animation,
1665
- _props$autoScroll = props.autoScroll,
1666
- autoScroll = _props$autoScroll === void 0 ? true : _props$autoScroll,
1667
- _props$scrollSpeed = props.scrollSpeed,
1668
- scrollSpeed = _props$scrollSpeed === void 0 ? {
1669
- x: 10,
1670
- y: 10
1671
- } : _props$scrollSpeed,
1672
- _props$ghostClass = props.ghostClass,
1673
- ghostClass = _props$ghostClass === void 0 ? '' : _props$ghostClass,
1674
- _props$ghostStyle = props.ghostStyle,
1675
- ghostStyle = _props$ghostStyle === void 0 ? undefined : _props$ghostStyle,
1676
- _props$chosenClass = props.chosenClass,
1677
- chosenClass = _props$chosenClass === void 0 ? '' : _props$chosenClass,
1678
- _props$placeholderCla = props.placeholderClass,
1679
- placeholderClass = _props$placeholderCla === void 0 ? '' : _props$placeholderCla,
1680
- _props$appendToBody = props.appendToBody,
1681
- appendToBody = _props$appendToBody === void 0 ? false : _props$appendToBody,
1682
- _props$scrollThreshol = props.scrollThreshold,
1683
- scrollThreshold = _props$scrollThreshol === void 0 ? 55 : _props$scrollThreshol,
1684
- _props$delayOnTouchOn = props.delayOnTouchOnly,
1685
- delayOnTouchOnly = _props$delayOnTouchOn === void 0 ? false : _props$delayOnTouchOn,
1686
- _props$dropOnAnimatio = props.dropOnAnimationEnd,
1687
- dropOnAnimationEnd = _props$dropOnAnimatio === void 0 ? true : _props$dropOnAnimatio;
1688
- var _React$useState = React__namespace.useState({
1689
- start: 0,
1690
- end: keeps - 1,
1691
- front: 0,
1692
- behind: 0
1693
- }),
1694
- _React$useState2 = _slicedToArray(_React$useState, 2),
1695
- range = _React$useState2[0],
1696
- setRange = _React$useState2[1];
1697
- var dragging = React__namespace.useRef('');
1698
- var rootElRef = React__namespace.useRef();
1699
- var wrapElRef = React__namespace.useRef();
1700
- /**
1701
- * git item size by data-key
1702
- */
1703
- var getSize = function getSize(key) {
1704
- return VS.current.call('getSize', key);
1705
- };
1706
- /**
1707
- * Get the current scroll height
1708
- */
1709
- var getOffset = function getOffset() {
1710
- return VS.current.call('getOffset');
1711
- };
1712
- /**
1713
- * Get client viewport size
1714
- */
1715
- var getClientSize = function getClientSize() {
1716
- return VS.current.call('getClientSize');
1717
- };
1718
- /**
1719
- * Get all scroll size
1720
- */
1721
- var getScrollSize = function getScrollSize() {
1722
- return VS.current.call('getScrollSize');
1723
- };
1724
- /**
1725
- * Scroll to the specified offset
1726
- */
1727
- var scrollToOffset = function scrollToOffset(offset) {
1728
- VS.current.call('scrollToOffset', offset);
1729
- };
1730
- /**
1731
- * Scroll to the specified index position
1732
- */
1733
- var scrollToIndex = function scrollToIndex(index, align) {
1734
- VS.current.call('scrollToIndex', index, align);
1735
- };
1736
- /**
1737
- * Scroll to the specified data-key position
1738
- */
1739
- var scrollToKey = function scrollToKey(key, align) {
1740
- var index = uniqueKeys.current.indexOf(key);
1741
- if (index > -1) {
1742
- VS.current.call('scrollToIndex', index, align);
1743
- }
1744
- };
1745
- /**
1746
- * Scroll to top of list
1747
- */
1748
- var scrollToTop = function scrollToTop() {
1749
- scrollToOffset(0);
1750
- };
1751
- /**
1752
- * Scroll to bottom of list
1753
- */
1754
- var scrollToBottom = function scrollToBottom() {
1755
- VS.current.call('scrollToBottom');
1756
- };
1757
- React__namespace.useImperativeHandle(ref, function () {
1758
- return {
1759
- getSize: getSize,
1760
- getOffset: getOffset,
1761
- getClientSize: getClientSize,
1762
- getScrollSize: getScrollSize,
1763
- scrollToTop: scrollToTop,
1764
- scrollToKey: scrollToKey,
1765
- scrollToIndex: scrollToIndex,
1766
- scrollToOffset: scrollToOffset,
1767
- scrollToBottom: scrollToBottom
1768
- };
1769
- });
1770
- // ========================================== data source ==========================================
1771
- var list = React__namespace.useRef([]);
1772
- var uniqueKeys = React__namespace.useRef([]);
1773
- var lastListLength = React__namespace.useRef(0);
1774
- var listLengthWhenTopLoading = React__namespace.useRef(0);
1775
- React__namespace.useEffect(function () {
1776
- var _a;
1777
- list.current = dataSource;
1778
- updateUniqueKeys();
1779
- detectRangeChange(lastListLength.current, dataSource.length);
1780
- // if auto scroll to the last offset
1781
- if (listLengthWhenTopLoading.current && props.keepOffset) {
1782
- var index = dataSource.length - listLengthWhenTopLoading.current;
1783
- if (index > 0) {
1784
- (_a = VS.current) === null || _a === void 0 ? void 0 : _a.call('scrollToIndex', index);
1785
- }
1786
- listLengthWhenTopLoading.current = 0;
1787
- }
1788
- lastListLength.current = dataSource.length;
1789
- }, [dataSource]);
1790
- React__namespace.useEffect(function () {
1791
- initVirtualSortable();
1792
- return function () {
1793
- VS.current.destroy();
1794
- };
1795
- }, []);
1796
- var updateUniqueKeys = function updateUniqueKeys() {
1797
- var _a;
1798
- uniqueKeys.current = list.current.map(function (item) {
1799
- return getDataKey(item, dataKey);
1800
- });
1801
- (_a = VS.current) === null || _a === void 0 ? void 0 : _a.option('uniqueKeys', uniqueKeys.current);
1802
- };
1803
- var detectRangeChange = function detectRangeChange(oldListLength, newListLength) {
1804
- var _a, _b;
1805
- if (oldListLength === newListLength) {
1806
- return;
1807
- }
1808
- var newRange = Object.assign({}, range);
1809
- if (oldListLength > keeps && newListLength > oldListLength && newRange.end === oldListLength - 1 && ((_a = VS.current) === null || _a === void 0 ? void 0 : _a.call('isReachedBottom'))) {
1810
- newRange.start++;
1811
- }
1812
- (_b = VS.current) === null || _b === void 0 ? void 0 : _b.call('updateRange', newRange);
1813
- };
1814
- var dispatchEvent = function dispatchEvent(name) {
1815
- var handler = props[name];
1816
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1817
- args[_key - 1] = arguments[_key];
1818
- }
1819
- handler && handler.apply(null, args);
1820
- };
1821
- // ========================================== virtual sortable ==========================================
1822
- var VS = React__namespace.useRef();
1823
- var combinedAttrs = {
1824
- // virtual attrs
1825
- size: size,
1826
- keeps: keeps,
1827
- buffer: buffer,
1828
- scroller: scroller,
1829
- direction: direction,
1830
- debounceTime: debounceTime,
1831
- throttleTime: throttleTime,
1832
- // sortable attrs
1833
- delay: delay,
1834
- group: group,
1835
- handle: handle,
1836
- lockAxis: lockAxis,
1837
- disabled: disabled,
1838
- sortable: sortable,
1839
- draggable: draggable,
1840
- animation: animation,
1841
- autoScroll: autoScroll,
1842
- ghostClass: ghostClass,
1843
- ghostStyle: ghostStyle,
1844
- chosenClass: chosenClass,
1845
- scrollSpeed: scrollSpeed,
1846
- appendToBody: appendToBody,
1847
- scrollThreshold: scrollThreshold,
1848
- delayOnTouchOnly: delayOnTouchOnly,
1849
- placeholderClass: placeholderClass,
1850
- dropOnAnimationEnd: dropOnAnimationEnd
1851
- };
1852
- var initVirtualSortable = function initVirtualSortable() {
1853
- VS.current = new VirtualSortable(rootElRef.current, Object.assign(Object.assign({}, combinedAttrs), {
1854
- wrapper: wrapElRef.current,
1855
- scroller: scroller || rootElRef.current,
1856
- uniqueKeys: uniqueKeys.current,
1857
- ghostContainer: wrapElRef.current,
1858
- onDrag: onDrag,
1859
- onDrop: onDrop,
1860
- onScroll: onScroll,
1861
- onUpdate: onUpdate
1862
- }));
1863
- };
1864
- useCombine(combinedAttrs, function () {
1865
- if (!VS.current) return;
1866
- Object.keys(combinedAttrs).forEach(function (key) {
1867
- if (props[key] !== void 0) {
1868
- VS.current.option(key, props[key]);
1869
- }
1870
- });
1871
- });
1872
- var handleToTop = debounce(function () {
1873
- listLengthWhenTopLoading.current = list.current.length;
1874
- dispatchEvent('onTop');
1875
- }, 50);
1876
- var handleToBottom = debounce(function () {
1877
- dispatchEvent('onBottom');
1878
- }, 50);
1879
- var onScroll = function onScroll(event) {
1880
- listLengthWhenTopLoading.current = 0;
1881
- if (event.top) {
1882
- handleToTop();
1883
- } else if (event.bottom) {
1884
- handleToBottom();
1885
- }
1886
- };
1887
- var onUpdate = function onUpdate(range, changed) {
1888
- setRange(range);
1889
- changed && dispatchEvent('onRangeChange', range);
1890
- };
1891
- var onSizeChange = function onSizeChange(key, size) {
1892
- // ignore changes for dragging element
1893
- if (isEqual(key, dragging.current) || !VS.current) {
1894
- return;
1895
- }
1896
- var sizes = VS.current.virtual.sizes.size;
1897
- VS.current.call('updateItemSize', key, size);
1898
- if (sizes === keeps - 1 && list.current.length > keeps) {
1899
- VS.current.call('updateRange', range);
1900
- }
1901
- };
1902
- var onDrag = function onDrag(event) {
1903
- var _a, _b;
1904
- var key = event.key,
1905
- index = event.index;
1906
- var item = list.current[index];
1907
- dragging.current = key;
1908
- draggingItem = item;
1909
- if (!sortable) {
1910
- (_a = VS.current) === null || _a === void 0 ? void 0 : _a.call('enableScroll', false);
1911
- (_b = VS.current) === null || _b === void 0 ? void 0 : _b.option('autoScroll', false);
1912
- }
1913
- dispatchEvent('onDrag', Object.assign(Object.assign({}, event), {
1914
- item: item
1915
- }));
1916
- };
1917
- var onDrop = function onDrop(event) {
1918
- var item = draggingItem;
1919
- var oldIndex = event.oldIndex,
1920
- newIndex = event.newIndex;
1921
- var oldList = _toConsumableArray(list.current);
1922
- var newList = _toConsumableArray(list.current);
1923
- if (oldIndex === -1) {
1924
- newList.splice(newIndex, 0, item);
1925
- } else if (newIndex === -1) {
1926
- newList.splice(oldIndex, 1);
1927
- } else {
1928
- newList.splice(oldIndex, 1);
1929
- newList.splice(newIndex, 0, item);
1930
- }
1931
- VS.current.call('enableScroll', true);
1932
- VS.current.option('autoScroll', props.autoScroll);
1933
- dragging.current = '';
1934
- dispatchEvent('onDrop', Object.assign(Object.assign({}, event), {
1935
- item: item,
1936
- list: newList,
1937
- oldList: oldList
1938
- }));
1939
- };
1940
- // ========================================== layout ==========================================
1941
- var _React$useMemo = React__namespace.useMemo(function () {
1942
- var front = range.front,
1943
- behind = range.behind;
1944
- var isHorizontal = direction === 'horizontal';
1945
- var overflow = isHorizontal ? 'auto hidden' : 'hidden auto';
1946
- var padding = isHorizontal ? "0px ".concat(behind, "px 0px ").concat(front, "px") : "".concat(front, "px 0px ").concat(behind, "px");
1947
- var rootElStyle = Object.assign(Object.assign({}, style), {
1948
- overflow: tableMode || scroller ? '' : overflow
1949
- });
1950
- var wrapElStyle = Object.assign(Object.assign({}, wrapStyle), {
1951
- padding: tableMode ? '' : padding
1952
- });
1953
- return {
1954
- rootElStyle: rootElStyle,
1955
- wrapElStyle: wrapElStyle
1956
- };
1957
- }, [range, style, wrapStyle, scroller, tableMode, direction]),
1958
- rootElStyle = _React$useMemo.rootElStyle,
1959
- wrapElStyle = _React$useMemo.wrapElStyle;
1960
- var _React$useMemo2 = React__namespace.useMemo(function () {
1961
- var rootElTag = tableMode ? 'table' : wrapTag;
1962
- var wrapElTag = tableMode ? 'tbody' : wrapTag;
1963
- return {
1964
- rootElTag: rootElTag,
1965
- wrapElTag: wrapElTag
1966
- };
1967
- }, [rootTag, wrapTag, tableMode]),
1968
- rootElTag = _React$useMemo2.rootElTag,
1969
- wrapElTag = _React$useMemo2.wrapElTag;
1970
- var listChildren = useChildren({
1971
- list: dataSource,
1972
- start: range.start,
1973
- end: range.end,
1974
- dataKey: dataKey,
1975
- children: props.children,
1976
- dragging: dragging.current,
1977
- horizontal: direction === 'horizontal',
1978
- onSizeChange: onSizeChange
1979
- });
1980
- var TableSpacer = function TableSpacer(offset, key) {
1981
- var offsetKey = direction === 'vertical' ? 'height' : 'width';
1982
- var style = _defineProperty({
1983
- padding: 0,
1984
- border: 0
1985
- }, offsetKey, "".concat(offset, "px"));
1986
- return /*#__PURE__*/React__namespace.createElement("tr", {
1987
- key: key
1988
- }, /*#__PURE__*/React__namespace.createElement("td", {
1989
- style: style
1990
- }));
1991
- };
1992
- return /*#__PURE__*/React__namespace.createElement(rootElTag, {
1993
- ref: rootElRef,
1994
- style: rootElStyle,
1995
- className: className
1996
- }, [props.header, /*#__PURE__*/React__namespace.createElement(wrapElTag, {
1997
- ref: wrapElRef,
1998
- style: wrapElStyle,
1999
- className: wrapClass
2000
- }, [tableMode && TableSpacer(range.front, 'front')].concat(_toConsumableArray(listChildren), [tableMode && TableSpacer(range.behind, 'behind')])), props.footer]);
2001
- }
2002
- var index = /*#__PURE__*/React__namespace.forwardRef(VirtualList);
2003
-
2004
- return index;
2005
-
2006
- }));