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