react-table-dnd 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +256 -0
- package/dist/Components/BodyRow.d.ts +9 -0
- package/dist/Components/ColumnCell.d.ts +9 -0
- package/dist/Components/DragHandle.d.ts +8 -0
- package/dist/Components/Draggable.d.ts +12 -0
- package/dist/Components/RowCell.d.ts +11 -0
- package/dist/Components/TableBody.d.ts +8 -0
- package/dist/Components/TableContainer/index.d.ts +15 -0
- package/dist/Components/TableContainer/store.d.ts +7 -0
- package/dist/Components/TableContainer/styles.d.ts +7 -0
- package/dist/Components/TableContainer/useTable.d.ts +9 -0
- package/dist/Components/TableHeader.d.ts +8 -0
- package/dist/Components/index.d.ts +11 -0
- package/dist/Components/utils.d.ts +5 -0
- package/dist/hooks/types.d.ts +125 -0
- package/dist/hooks/useAutoScroll.d.ts +15 -0
- package/dist/hooks/useDragContextEvents.d.ts +7 -0
- package/dist/hooks/useDropTarget.d.ts +13 -0
- package/dist/hooks/useIndexMaps.d.ts +15 -0
- package/dist/hooks/useLongPress.d.ts +14 -0
- package/dist/hooks/useShiftTransforms.d.ts +16 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +1236 -0
- package/dist/react-table-dnd.css +2 -0
- package/package.json +93 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,1236 @@
|
|
|
1
|
+
import { createContext as e, forwardRef as t, memo as n, useCallback as r, useContext as i, useEffect as a, useImperativeHandle as o, useLayoutEffect as s, useMemo as c, useRef as l, useState as u } from "react";
|
|
2
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
3
|
+
import { flushSync as p } from "react-dom";
|
|
4
|
+
import m from "classnames";
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var h = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), g = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
7
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
8
|
+
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
9
|
+
}), _ = ({ children: e, className: t }) => /* @__PURE__ */ d("div", {
|
|
10
|
+
"data-flexitable-root": "",
|
|
11
|
+
className: t ?? "",
|
|
12
|
+
children: e
|
|
13
|
+
}), v = /* @__PURE__ */ h(((e) => {
|
|
14
|
+
var t = g("react");
|
|
15
|
+
function n(e, t) {
|
|
16
|
+
return e === t && (e !== 0 || 1 / e == 1 / t) || e !== e && t !== t;
|
|
17
|
+
}
|
|
18
|
+
var r = typeof Object.is == "function" ? Object.is : n, i = t.useState, a = t.useEffect, o = t.useLayoutEffect, s = t.useDebugValue;
|
|
19
|
+
function c(e, t) {
|
|
20
|
+
var n = t(), r = i({ inst: {
|
|
21
|
+
value: n,
|
|
22
|
+
getSnapshot: t
|
|
23
|
+
} }), c = r[0].inst, u = r[1];
|
|
24
|
+
return o(function() {
|
|
25
|
+
c.value = n, c.getSnapshot = t, l(c) && u({ inst: c });
|
|
26
|
+
}, [
|
|
27
|
+
e,
|
|
28
|
+
n,
|
|
29
|
+
t
|
|
30
|
+
]), a(function() {
|
|
31
|
+
return l(c) && u({ inst: c }), e(function() {
|
|
32
|
+
l(c) && u({ inst: c });
|
|
33
|
+
});
|
|
34
|
+
}, [e]), s(n), n;
|
|
35
|
+
}
|
|
36
|
+
function l(e) {
|
|
37
|
+
var t = e.getSnapshot;
|
|
38
|
+
e = e.value;
|
|
39
|
+
try {
|
|
40
|
+
var n = t();
|
|
41
|
+
return !r(e, n);
|
|
42
|
+
} catch {
|
|
43
|
+
return !0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function u(e, t) {
|
|
47
|
+
return t();
|
|
48
|
+
}
|
|
49
|
+
var d = typeof window > "u" || window.document === void 0 || window.document.createElement === void 0 ? u : c;
|
|
50
|
+
e.useSyncExternalStore = t.useSyncExternalStore === void 0 ? d : t.useSyncExternalStore;
|
|
51
|
+
})), y = /* @__PURE__ */ h(((e) => {
|
|
52
|
+
process.env.NODE_ENV !== "production" && (function() {
|
|
53
|
+
function t(e, t) {
|
|
54
|
+
return e === t && (e !== 0 || 1 / e == 1 / t) || e !== e && t !== t;
|
|
55
|
+
}
|
|
56
|
+
function n(e, t) {
|
|
57
|
+
d || a.startTransition === void 0 || (d = !0, console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
|
|
58
|
+
var n = t();
|
|
59
|
+
if (!f) {
|
|
60
|
+
var i = t();
|
|
61
|
+
o(n, i) || (console.error("The result of getSnapshot should be cached to avoid an infinite loop"), f = !0);
|
|
62
|
+
}
|
|
63
|
+
i = s({ inst: {
|
|
64
|
+
value: n,
|
|
65
|
+
getSnapshot: t
|
|
66
|
+
} });
|
|
67
|
+
var p = i[0].inst, m = i[1];
|
|
68
|
+
return l(function() {
|
|
69
|
+
p.value = n, p.getSnapshot = t, r(p) && m({ inst: p });
|
|
70
|
+
}, [
|
|
71
|
+
e,
|
|
72
|
+
n,
|
|
73
|
+
t
|
|
74
|
+
]), c(function() {
|
|
75
|
+
return r(p) && m({ inst: p }), e(function() {
|
|
76
|
+
r(p) && m({ inst: p });
|
|
77
|
+
});
|
|
78
|
+
}, [e]), u(n), n;
|
|
79
|
+
}
|
|
80
|
+
function r(e) {
|
|
81
|
+
var t = e.getSnapshot;
|
|
82
|
+
e = e.value;
|
|
83
|
+
try {
|
|
84
|
+
var n = t();
|
|
85
|
+
return !o(e, n);
|
|
86
|
+
} catch {
|
|
87
|
+
return !0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function i(e, t) {
|
|
91
|
+
return t();
|
|
92
|
+
}
|
|
93
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
94
|
+
var a = g("react"), o = typeof Object.is == "function" ? Object.is : t, s = a.useState, c = a.useEffect, l = a.useLayoutEffect, u = a.useDebugValue, d = !1, f = !1, p = typeof window > "u" || window.document === void 0 || window.document.createElement === void 0 ? i : n;
|
|
95
|
+
e.useSyncExternalStore = a.useSyncExternalStore === void 0 ? p : a.useSyncExternalStore, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
96
|
+
})();
|
|
97
|
+
})), b = (/* @__PURE__ */ h(((e, t) => {
|
|
98
|
+
process.env.NODE_ENV === "production" ? t.exports = v() : t.exports = y();
|
|
99
|
+
})))(), x = e(null), S = (e) => {
|
|
100
|
+
let t = i(x);
|
|
101
|
+
if (!t) throw Error("useTableStore must be used within TableProvider");
|
|
102
|
+
return (0, b.useSyncExternalStore)(t.subscribe, () => e(t.getState()));
|
|
103
|
+
}, C = () => {
|
|
104
|
+
let e = i(x);
|
|
105
|
+
if (!e) throw Error("useTableDispatch must be used within TableProvider");
|
|
106
|
+
return e.dispatch;
|
|
107
|
+
}, w = () => {
|
|
108
|
+
let e = i(x);
|
|
109
|
+
if (!e) throw Error("useTable must be used within a TableProvider");
|
|
110
|
+
return {
|
|
111
|
+
state: (0, b.useSyncExternalStore)(e.subscribe, e.getState),
|
|
112
|
+
dispatch: e.dispatch
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/Components/TableContainer/store.ts
|
|
117
|
+
function T(e, t) {
|
|
118
|
+
let n = t, r = /* @__PURE__ */ new Set();
|
|
119
|
+
return {
|
|
120
|
+
getState: () => n,
|
|
121
|
+
dispatch(t) {
|
|
122
|
+
n = e(n, t), r.forEach((e) => e());
|
|
123
|
+
},
|
|
124
|
+
subscribe(e) {
|
|
125
|
+
return r.add(e), () => {
|
|
126
|
+
r.delete(e);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/hooks/useAutoScroll.ts
|
|
133
|
+
var E = 30, D = (e) => {
|
|
134
|
+
let { headerRef: t, bodyRef: n } = e, i = l(null), o = l(t), s = l(!1), c = l(!1), u = l(0), d = l(null), f = l({
|
|
135
|
+
x: 0,
|
|
136
|
+
y: 0
|
|
137
|
+
}), p = l(null), m = r((e) => {
|
|
138
|
+
p.current = e;
|
|
139
|
+
}, []), h = r(() => {
|
|
140
|
+
c.current = !1, s.current = !1, d.current !== null && (cancelAnimationFrame(d.current), d.current = null);
|
|
141
|
+
}, []), g = r((e, t, n) => {
|
|
142
|
+
let r = n === "vertical", a = r ? c : s;
|
|
143
|
+
if (!a.current) return;
|
|
144
|
+
let l = p.current;
|
|
145
|
+
if (l) {
|
|
146
|
+
let e = f.current;
|
|
147
|
+
if (r) {
|
|
148
|
+
let t = e.y < l.top + E, n = e.y > l.bottom - E;
|
|
149
|
+
if (!t && !n) {
|
|
150
|
+
a.current = !1;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
let t = e.x < l.left + E, n = e.x > l.right - E;
|
|
155
|
+
if (!t && !n) {
|
|
156
|
+
a.current = !1;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let m = r ? t.scrollHeight - t.clientHeight : t.scrollWidth - t.clientWidth;
|
|
162
|
+
if (r) t.scrollTop += e;
|
|
163
|
+
else {
|
|
164
|
+
t.scrollLeft += e;
|
|
165
|
+
let n = o.current;
|
|
166
|
+
n?.current && (n.current.scrollLeft = t.scrollLeft);
|
|
167
|
+
}
|
|
168
|
+
let h = r ? t.scrollTop : t.scrollLeft;
|
|
169
|
+
if (h >= m || h <= 0) {
|
|
170
|
+
a.current = !1;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
u.current += e / 1e3, d.current = requestAnimationFrame(() => i.current?.(e + u.current, t, n));
|
|
174
|
+
}, []);
|
|
175
|
+
return a(() => {
|
|
176
|
+
i.current = g;
|
|
177
|
+
}, [g]), {
|
|
178
|
+
startAutoScroll: r((e, t, n) => {
|
|
179
|
+
let r = n === "vertical" ? c : s;
|
|
180
|
+
r.current || (r.current = !0, u.current = 0, d.current = requestAnimationFrame(() => g(e, t, n)));
|
|
181
|
+
}, [g]),
|
|
182
|
+
stopAutoScroll: h,
|
|
183
|
+
setContainerRect: m,
|
|
184
|
+
isAutoScrollingVertical: c,
|
|
185
|
+
isAutoScrollingHorizontal: s,
|
|
186
|
+
pointerRef: f,
|
|
187
|
+
BodyScrollHandle: r((e) => {
|
|
188
|
+
t?.current && e.currentTarget && (t.current.scrollLeft = e.currentTarget.scrollLeft);
|
|
189
|
+
}, [t]),
|
|
190
|
+
HeaderScrollHandle: r((e) => {
|
|
191
|
+
n?.current && e.currentTarget && (n.current.scrollLeft = e.currentTarget.scrollLeft);
|
|
192
|
+
}, [n])
|
|
193
|
+
};
|
|
194
|
+
}, O = 300, k = 8, A = .92, j = .5;
|
|
195
|
+
function M(e, t, n, i) {
|
|
196
|
+
let a = l(null), o = l({
|
|
197
|
+
x: 0,
|
|
198
|
+
y: 0
|
|
199
|
+
}), s = l(null), c = l(!1), u = l(null), d = l(null), f = r(() => {
|
|
200
|
+
d.current !== null && (cancelAnimationFrame(d.current), d.current = null);
|
|
201
|
+
}, []), p = r(() => {
|
|
202
|
+
a.current &&= (clearTimeout(a.current), null), s.current = null, u.current &&= (u.current(), null);
|
|
203
|
+
}, []);
|
|
204
|
+
return {
|
|
205
|
+
touchStart: r((r) => {
|
|
206
|
+
if (r.target === r.currentTarget) return;
|
|
207
|
+
let l = r.target, m = !1;
|
|
208
|
+
for (; l && !(l.dataset?.contextid || l.dataset?.disabled === "true");) {
|
|
209
|
+
if (l.dataset?.id) {
|
|
210
|
+
m = !0;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
l = l.parentNode;
|
|
214
|
+
}
|
|
215
|
+
if (!m) return;
|
|
216
|
+
f(), p(), c.current = !0, window.getSelection()?.removeAllRanges();
|
|
217
|
+
let h = r.touches[0];
|
|
218
|
+
o.current = {
|
|
219
|
+
x: h.clientX,
|
|
220
|
+
y: h.clientY
|
|
221
|
+
}, s.current = r;
|
|
222
|
+
let g = e.tableRef?.current;
|
|
223
|
+
if (!g) return;
|
|
224
|
+
let _ = !1, v = !1, y = h.clientY, b = h.clientX, x = 0, S = 0, C = Date.now(), w = (e) => e.preventDefault();
|
|
225
|
+
document.addEventListener("selectstart", w);
|
|
226
|
+
let T = ((t) => {
|
|
227
|
+
let n = e.bodyRef?.current, r = t;
|
|
228
|
+
for (; r && r !== n;) {
|
|
229
|
+
let e = window.getComputedStyle(r), t = e.overflowY, n = e.overflowX, i = (t === "auto" || t === "scroll") && r.scrollHeight > r.clientHeight, a = (n === "auto" || n === "scroll") && r.scrollWidth > r.clientWidth;
|
|
230
|
+
if (i || a) return r;
|
|
231
|
+
r = r.parentElement;
|
|
232
|
+
}
|
|
233
|
+
return n ?? document.body;
|
|
234
|
+
})(r.target), E = (t) => {
|
|
235
|
+
t.preventDefault();
|
|
236
|
+
let n = t.touches[0], r = Date.now(), c = Math.max(r - C, 1);
|
|
237
|
+
if (C = r, v) {
|
|
238
|
+
let t = n.clientY - y, r = n.clientX - b;
|
|
239
|
+
if (T) {
|
|
240
|
+
let n = e.bodyRef?.current, i = t > 0 && T.scrollTop <= 0, a = t < 0 && T.scrollTop + T.clientHeight >= T.scrollHeight - 1, o = r > 0 && T.scrollLeft <= 0, s = r < 0 && T.scrollLeft + T.clientWidth >= T.scrollWidth - 1, c = i || a, l = o || s;
|
|
241
|
+
T === n ? (T.scrollTop -= t, T.scrollLeft -= r) : (l || (T.scrollLeft -= r), c || (T.scrollTop -= t), n && (c && (n.scrollTop -= t), l && (n.scrollLeft -= r)));
|
|
242
|
+
}
|
|
243
|
+
x = -t / c * 16, S = -r / c * 16, y = n.clientY, b = n.clientX;
|
|
244
|
+
} else if (_) i(n.clientX, n.clientY);
|
|
245
|
+
else {
|
|
246
|
+
let e = n.clientX - o.current.x, t = n.clientY - o.current.y;
|
|
247
|
+
(Math.abs(e) > k || Math.abs(t) > k) && (a.current &&= (clearTimeout(a.current), null), s.current = null, v = !0, y = n.clientY, b = n.clientX, x = 0, S = 0, C = Date.now());
|
|
248
|
+
}
|
|
249
|
+
}, D = () => {
|
|
250
|
+
if (_) M(), n();
|
|
251
|
+
else {
|
|
252
|
+
if (p(), v && T && (Math.abs(x) > j || Math.abs(S) > j)) {
|
|
253
|
+
let e = T, t = () => {
|
|
254
|
+
x *= A, S *= A, e.scrollTop += x, e.scrollLeft += S, Math.abs(x) > j || Math.abs(S) > j ? d.current = requestAnimationFrame(t) : d.current = null;
|
|
255
|
+
};
|
|
256
|
+
d.current = requestAnimationFrame(t);
|
|
257
|
+
}
|
|
258
|
+
setTimeout(() => {
|
|
259
|
+
c.current = !1;
|
|
260
|
+
}, 400);
|
|
261
|
+
}
|
|
262
|
+
}, M = () => {
|
|
263
|
+
g.removeEventListener("touchmove", E), g.removeEventListener("touchend", D), g.removeEventListener("touchcancel", D), document.removeEventListener("selectstart", w), u.current = null;
|
|
264
|
+
};
|
|
265
|
+
g.addEventListener("touchmove", E, { passive: !1 }), g.addEventListener("touchend", D, !1), g.addEventListener("touchcancel", D, !1), u.current = M, a.current = setTimeout(() => {
|
|
266
|
+
a.current = null, _ = !0;
|
|
267
|
+
let e = s.current;
|
|
268
|
+
s.current = null, e && t(e, h.clientX, h.clientY);
|
|
269
|
+
}, O);
|
|
270
|
+
}, [
|
|
271
|
+
t,
|
|
272
|
+
n,
|
|
273
|
+
i,
|
|
274
|
+
p,
|
|
275
|
+
f,
|
|
276
|
+
e.tableRef?.current,
|
|
277
|
+
e.bodyRef?.current
|
|
278
|
+
]),
|
|
279
|
+
cancelLongPress: p,
|
|
280
|
+
isTouchActiveRef: c
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/hooks/useShiftTransforms.ts
|
|
285
|
+
var N = "transform 450ms cubic-bezier(0.2, 0, 0, 1)", ee = (e, t, n, i) => {
|
|
286
|
+
let a = l({
|
|
287
|
+
width: 0,
|
|
288
|
+
height: 0
|
|
289
|
+
}), o = l(null), s = l(/* @__PURE__ */ new Set()), c = l(/* @__PURE__ */ new Set()), u = l(/* @__PURE__ */ new Map()), d = r((t, n, r, i) => {
|
|
290
|
+
let o = e.placeholderRef?.current;
|
|
291
|
+
if (!o || !t) {
|
|
292
|
+
o && (o.style.display = "none");
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
let s = a.current, c = t.getBoundingClientRect(), l = e.tableRef?.current?.getBoundingClientRect(), u = (n ?? 0) < (r ?? 0);
|
|
296
|
+
o.style.display = "block", i === "row" ? (o.style.top = `${u ? c.top + c.height - s.height : c.top}px`, o.style.left = `${l?.left ?? c.left}px`, o.style.width = `${l?.width ?? c.width}px`, o.style.height = `${s.height}px`) : (o.style.top = `${l?.top ?? c.top}px`, o.style.left = `${u ? c.left + c.width - s.width : c.left}px`, o.style.width = `${s.width}px`, o.style.height = `${l?.height ?? c.height}px`);
|
|
297
|
+
}, [e.placeholderRef, e.tableRef]);
|
|
298
|
+
return {
|
|
299
|
+
applyShiftTransforms: r((e, r, l) => {
|
|
300
|
+
if (e === null || r === null) return;
|
|
301
|
+
let f = a.current, p = o.current, m = p === null, h = m ? -Infinity : Math.min(p, r, e) - 1, g = m ? Infinity : Math.max(p, r, e) + 1, _ = null, v = (l === "row" ? t.current : n.current).get(r);
|
|
302
|
+
v && (_ = v.outer), d(_, e, r, l);
|
|
303
|
+
let y = (t, n, i) => {
|
|
304
|
+
let a = (t, a, o) => {
|
|
305
|
+
let c = "";
|
|
306
|
+
t > e && t <= r ? c = `translate${n}(-${i}px)` : t < e && t >= r && (c = `translate${n}(${i}px)`), o.style.transform = c, o.style.transition = t === e ? "none" : N, c && s.current.add(o), t === r ? a.setAttribute("data-drop-target", "true") : a.removeAttribute("data-drop-target");
|
|
307
|
+
};
|
|
308
|
+
if (m) for (let [e, { outer: n, inner: r }] of t) a(e, n, r);
|
|
309
|
+
else for (let e = h; e <= g; e++) {
|
|
310
|
+
let n = t.get(e);
|
|
311
|
+
n && a(e, n.outer, n.inner);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
if (l === "row") y(t.current, "Y", f.height);
|
|
315
|
+
else if (l === "column") {
|
|
316
|
+
y(n.current, "X", f.width);
|
|
317
|
+
let t = i.current, a = u.current, o = (t, n, i) => {
|
|
318
|
+
let o = "";
|
|
319
|
+
t > e && t <= r ? o = `translateX(-${f.width}px)` : t < e && t >= r && (o = `translateX(${f.width}px)`);
|
|
320
|
+
for (let e of n) a.get(e) !== o && (e.style.transform = o, i && (e.style.transition = N), a.set(e, o), o && c.current.add(e));
|
|
321
|
+
};
|
|
322
|
+
if (m) for (let [e, n] of t) o(e, n, !0);
|
|
323
|
+
else for (let e = h; e <= g; e++) {
|
|
324
|
+
let n = t.get(e);
|
|
325
|
+
n && o(e, n, !1);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
o.current = r;
|
|
329
|
+
}, [
|
|
330
|
+
d,
|
|
331
|
+
t,
|
|
332
|
+
n,
|
|
333
|
+
i
|
|
334
|
+
]),
|
|
335
|
+
clearShiftTransforms: r(() => {
|
|
336
|
+
let t = e.placeholderRef?.current;
|
|
337
|
+
t && (t.style.display = "none");
|
|
338
|
+
for (let e of s.current) {
|
|
339
|
+
e.style.transition = "none", e.style.transform = "";
|
|
340
|
+
let t = e.parentElement;
|
|
341
|
+
t && t.removeAttribute("data-drop-target");
|
|
342
|
+
}
|
|
343
|
+
s.current.clear();
|
|
344
|
+
for (let e of c.current) e.style.transition = "none", e.style.transform = "";
|
|
345
|
+
c.current.clear(), u.current.clear(), o.current = null;
|
|
346
|
+
}, [e.placeholderRef]),
|
|
347
|
+
prevTargetIndexRef: o,
|
|
348
|
+
draggedSizeRef: a
|
|
349
|
+
};
|
|
350
|
+
}, te = (e) => {
|
|
351
|
+
let t = l(/* @__PURE__ */ new Map()), n = l(/* @__PURE__ */ new Map()), i = l(/* @__PURE__ */ new Map()), a = l(!1), o = r(() => {
|
|
352
|
+
t.current.clear(), n.current.clear(), i.current.clear();
|
|
353
|
+
}, []), s = r((e) => {
|
|
354
|
+
t.current.clear();
|
|
355
|
+
let n = e.querySelectorAll(".draggable[data-type=\"row\"]");
|
|
356
|
+
for (let e = 0; e < n.length; e++) {
|
|
357
|
+
let r = n[e], i = r.dataset.index;
|
|
358
|
+
if (i === void 0) continue;
|
|
359
|
+
let a = r.firstElementChild;
|
|
360
|
+
a && t.current.set(+i, {
|
|
361
|
+
outer: r,
|
|
362
|
+
inner: a
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}, []), c = r((e) => {
|
|
366
|
+
n.current.clear();
|
|
367
|
+
let t = e.querySelectorAll(".draggable[data-type=\"column\"]");
|
|
368
|
+
for (let e = 0; e < t.length; e++) {
|
|
369
|
+
let r = t[e], i = r.dataset.index;
|
|
370
|
+
if (i === void 0) continue;
|
|
371
|
+
let a = r.firstElementChild;
|
|
372
|
+
a && n.current.set(+i, {
|
|
373
|
+
outer: r,
|
|
374
|
+
inner: a
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}, []), u = r((e) => {
|
|
378
|
+
i.current.clear();
|
|
379
|
+
let t = e.querySelectorAll(".td[data-col-index]");
|
|
380
|
+
for (let e = 0; e < t.length; e++) {
|
|
381
|
+
let n = t[e], r = +n.dataset.colIndex;
|
|
382
|
+
i.current.has(r) || i.current.set(r, []), i.current.get(r).push(n);
|
|
383
|
+
}
|
|
384
|
+
}, []);
|
|
385
|
+
return {
|
|
386
|
+
rowIndexMapRef: t,
|
|
387
|
+
colIndexMapRef: n,
|
|
388
|
+
cellIndexMapRef: i,
|
|
389
|
+
mapStaleRef: a,
|
|
390
|
+
buildMaps: r((t, n) => {
|
|
391
|
+
if (o(), n) {
|
|
392
|
+
if (t === "row") s(n);
|
|
393
|
+
else if (t === "column") {
|
|
394
|
+
let t = e.headerRef?.current;
|
|
395
|
+
t && c(t), u(n);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}, [
|
|
399
|
+
e.headerRef,
|
|
400
|
+
o,
|
|
401
|
+
s,
|
|
402
|
+
c,
|
|
403
|
+
u
|
|
404
|
+
]),
|
|
405
|
+
rebuildRowMap: r((e) => {
|
|
406
|
+
a.current = !1, s(e);
|
|
407
|
+
}, [s]),
|
|
408
|
+
rebuildColumnMaps: r((e, t) => {
|
|
409
|
+
a.current = !1, t && c(t), u(e);
|
|
410
|
+
}, [c, u]),
|
|
411
|
+
checkStaleness: r(() => {
|
|
412
|
+
if (!a.current) {
|
|
413
|
+
if (t.current.size > 0) {
|
|
414
|
+
let e = t.current.values().next().value;
|
|
415
|
+
if (e && !e.outer.isConnected) {
|
|
416
|
+
a.current = !0;
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (n.current.size > 0) {
|
|
421
|
+
let e = n.current.values().next().value;
|
|
422
|
+
e && !e.outer.isConnected && (a.current = !0);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}, []),
|
|
426
|
+
clearMaps: o
|
|
427
|
+
};
|
|
428
|
+
}, P = (e, t) => {
|
|
429
|
+
let n = e, r = 0, i = t.length - 1;
|
|
430
|
+
for (; r < i;) {
|
|
431
|
+
let e = Math.floor((r + i) / 2), a = t[e];
|
|
432
|
+
if (a.itemTop <= n && n <= a.itemBottom) return n < a.itemTop + a.height / 2 ? +a.index : +a.index + 1;
|
|
433
|
+
n < a.itemTop ? i = e - 1 : r = e + 1;
|
|
434
|
+
}
|
|
435
|
+
return +t[r].index;
|
|
436
|
+
}, F = (e, t) => {
|
|
437
|
+
let n = e, r = 0, i = t.length - 1;
|
|
438
|
+
for (; r < i;) {
|
|
439
|
+
let e = Math.floor((r + i) / 2), a = t[e];
|
|
440
|
+
if (a.itemLeft <= n && n <= a.itemRight) return n < a.itemLeft + a.width / 2 ? +a.index : +a.index + 1;
|
|
441
|
+
n < a.itemLeft ? i = e - 1 : r = e + 1;
|
|
442
|
+
}
|
|
443
|
+
return +t[r].index;
|
|
444
|
+
};
|
|
445
|
+
function ne(e, t, n) {
|
|
446
|
+
let r = n.getBoundingClientRect();
|
|
447
|
+
return e > r.left + n.clientWidth || t > r.top + n.clientHeight;
|
|
448
|
+
}
|
|
449
|
+
var I = (e, t, n) => {
|
|
450
|
+
let r = Number(e);
|
|
451
|
+
return t !== void 0 && r < t || n !== void 0 && r > n;
|
|
452
|
+
}, re = (e, t) => {
|
|
453
|
+
let n = l(null), i = l(null), a = r(() => {
|
|
454
|
+
let n = e.bodyRef?.current;
|
|
455
|
+
if (!n) return null;
|
|
456
|
+
let r = n.scrollTop, i = n.getBoundingClientRect().top, a = n.querySelectorAll(".draggable[data-type=\"row\"]"), o = [];
|
|
457
|
+
for (let e = 0; e < a.length; e++) {
|
|
458
|
+
let t = a[e];
|
|
459
|
+
if (t.dataset.index === void 0) continue;
|
|
460
|
+
let n = t.getBoundingClientRect(), s = n.top - i + r;
|
|
461
|
+
o.push({
|
|
462
|
+
height: n.height,
|
|
463
|
+
itemTop: s,
|
|
464
|
+
itemBottom: s + n.height,
|
|
465
|
+
index: t.dataset.index
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
let { start: s, end: c } = t.rowDragRange;
|
|
469
|
+
return (s || c) && (o = o.filter((e) => (!s || +e.index >= s) && (!c || +e.index <= c))), o;
|
|
470
|
+
}, [e.bodyRef, t.rowDragRange]), o = r(() => {
|
|
471
|
+
let n = e.headerRef?.current;
|
|
472
|
+
if (!n || !n.children[0]) return null;
|
|
473
|
+
let r = Array.from(n.children[0].children).map((e) => {
|
|
474
|
+
let t = e.getBoundingClientRect();
|
|
475
|
+
return {
|
|
476
|
+
left: t.left,
|
|
477
|
+
width: t.width,
|
|
478
|
+
itemLeft: t.left,
|
|
479
|
+
itemRight: t.left + t.width,
|
|
480
|
+
index: e.dataset.index
|
|
481
|
+
};
|
|
482
|
+
}).filter((e) => e.index !== void 0), { start: i, end: a } = t.columnDragRange ?? {};
|
|
483
|
+
return (i !== void 0 || a !== void 0) && (r = r.filter((e) => {
|
|
484
|
+
let t = +e.index;
|
|
485
|
+
return (i === void 0 || t >= i) && (a === void 0 || t <= a);
|
|
486
|
+
})), r;
|
|
487
|
+
}, [e.headerRef, t.columnDragRange]);
|
|
488
|
+
return {
|
|
489
|
+
computeRowItems: a,
|
|
490
|
+
computeColumnItems: o,
|
|
491
|
+
resolveDropIndex: r((e, t, r, i, s, c, l) => {
|
|
492
|
+
let u;
|
|
493
|
+
if (r === "row") {
|
|
494
|
+
if (u = n.current, u || (u = a(), n.current = u), u && u.length > 0) return P(t - c.y + l.height / 2 - i.top + s, u);
|
|
495
|
+
} else if (u = n.current, u || (u = o(), n.current = u), u && u.length > 0) return F(e - c.x + l.width / 2, u);
|
|
496
|
+
return 0;
|
|
497
|
+
}, [a, o]),
|
|
498
|
+
cachedItemsRef: n,
|
|
499
|
+
cachedContainerRef: i
|
|
500
|
+
};
|
|
501
|
+
}, L = 200, R = 30, z = 5;
|
|
502
|
+
function ie(e) {
|
|
503
|
+
let t = e, n = !1;
|
|
504
|
+
for (; t;) {
|
|
505
|
+
if (t.dataset?.dragHandle === "true" && (n = !0), t.dataset?.contextid || t.dataset?.disabled === "true") return null;
|
|
506
|
+
if (t.dataset?.id) return {
|
|
507
|
+
element: t,
|
|
508
|
+
foundHandle: n
|
|
509
|
+
};
|
|
510
|
+
t = t.parentNode;
|
|
511
|
+
}
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
var B = (e, t, n, i, o, c) => {
|
|
515
|
+
let { startAutoScroll: u, stopAutoScroll: d, setContainerRect: f, pointerRef: m, isAutoScrollingVertical: h, isAutoScrollingHorizontal: g } = D(e), _ = te(e), { rowIndexMapRef: v, colIndexMapRef: y, cellIndexMapRef: b, mapStaleRef: x } = _, { applyShiftTransforms: S, clearShiftTransforms: C, prevTargetIndexRef: w, draggedSizeRef: T } = ee(e, v, y, b), E = re(e, o), { resolveDropIndex: O, cachedItemsRef: k, cachedContainerRef: A } = E, j = l(null), N = l({
|
|
516
|
+
x: 0,
|
|
517
|
+
y: 0
|
|
518
|
+
}), P = l(null), F = l(null), I = l(!1), B = l(!1), V = l(null), H = l(null), U = l([]), W = r((t, r, i) => {
|
|
519
|
+
let a = ie(t.target);
|
|
520
|
+
if (!a) return;
|
|
521
|
+
let { element: o, foundHandle: s } = a;
|
|
522
|
+
if (!s && o.querySelector("[data-drag-handle]")) return;
|
|
523
|
+
let c = o.dataset.id, l = +o.dataset.index, u = o.dataset.type;
|
|
524
|
+
j.current = u ?? null, P.current = l, F.current = null, V.current = null, U.current = [], w.current = null, I.current = !1;
|
|
525
|
+
let d = u === "row" ? e.bodyRef?.current?.scrollLeft ?? 0 : 0, p = o.getBoundingClientRect();
|
|
526
|
+
T.current = {
|
|
527
|
+
width: p.width,
|
|
528
|
+
height: p.height
|
|
529
|
+
};
|
|
530
|
+
let h = {
|
|
531
|
+
x: r - p.left - d,
|
|
532
|
+
y: i - p.top
|
|
533
|
+
};
|
|
534
|
+
N.current = h, m.current = {
|
|
535
|
+
x: r,
|
|
536
|
+
y: i
|
|
537
|
+
};
|
|
538
|
+
let g = {
|
|
539
|
+
x: p.left + d,
|
|
540
|
+
y: p.top
|
|
541
|
+
};
|
|
542
|
+
k.current = u === "row" ? E.computeRowItems() : E.computeColumnItems();
|
|
543
|
+
let v = e.bodyRef?.current;
|
|
544
|
+
v && (A.current = v.getBoundingClientRect(), f(A.current)), _.buildMaps(u, v ?? null);
|
|
545
|
+
let y = e.tableRef?.current;
|
|
546
|
+
y && (y.style.touchAction = "none");
|
|
547
|
+
let b = o.firstElementChild;
|
|
548
|
+
b && (b.style.opacity = "0", b.style.pointerEvents = "none", b.style.zIndex = "2", b.style.cursor = "-webkit-grabbing"), H.current = b;
|
|
549
|
+
let x = e.cloneRef?.current;
|
|
550
|
+
if (x) {
|
|
551
|
+
if (x.innerHTML = "", x.style.transform = `translate(${g.x}px, ${g.y}px)`, B.current = (v?.querySelector("[data-type=\"row\"]"))?.style.position === "absolute", u === "row") {
|
|
552
|
+
let e = o.firstElementChild?.firstElementChild;
|
|
553
|
+
e && x.appendChild(e.cloneNode(!0));
|
|
554
|
+
} else if (u === "column" && v) {
|
|
555
|
+
let e = String(l), t = o.querySelector(".th");
|
|
556
|
+
if (t) {
|
|
557
|
+
let e = document.createElement("div");
|
|
558
|
+
e.style.flexShrink = "0", e.style.order = "-1", e.appendChild(t.cloneNode(!0)), x.appendChild(e);
|
|
559
|
+
}
|
|
560
|
+
let n = document.createElement("div");
|
|
561
|
+
n.style.flex = "1";
|
|
562
|
+
let r = document.createElement("div");
|
|
563
|
+
r.className = "rbody", r.style.height = `${v.scrollHeight}px`, r.style.position = "relative", v.querySelectorAll("[data-type=\"row\"]").forEach((t) => {
|
|
564
|
+
let n = t.cloneNode(!0);
|
|
565
|
+
if (B.current) {
|
|
566
|
+
let t = n.querySelector(".tr");
|
|
567
|
+
if (t) {
|
|
568
|
+
let n = t.querySelector(`[data-col-index="${e}"]`);
|
|
569
|
+
for (; t.firstChild;) t.removeChild(t.firstChild);
|
|
570
|
+
n && t.appendChild(n);
|
|
571
|
+
}
|
|
572
|
+
} else n.querySelectorAll("[data-col-index]").forEach((t) => {
|
|
573
|
+
t.getAttribute("data-col-index") !== e && t.remove();
|
|
574
|
+
});
|
|
575
|
+
r.appendChild(n);
|
|
576
|
+
}), n.appendChild(r), B.current ? (n.style.overflow = "auto", n.style.scrollbarWidth = "none", n.className = "clone-body-strip") : n.style.overflow = "hidden", x.appendChild(n), V.current = n, U.current = [], v.querySelectorAll(`[data-col-index="${e}"]`).forEach((e) => {
|
|
577
|
+
e.style.opacity = "0", U.current.push(e);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
n({
|
|
582
|
+
type: "dragStart",
|
|
583
|
+
value: {
|
|
584
|
+
rect: {
|
|
585
|
+
draggedItemHeight: p.height,
|
|
586
|
+
draggedItemWidth: p.width
|
|
587
|
+
},
|
|
588
|
+
dragged: {
|
|
589
|
+
initial: h,
|
|
590
|
+
translate: g,
|
|
591
|
+
draggedID: c ?? null,
|
|
592
|
+
isDragging: !0,
|
|
593
|
+
sourceIndex: l
|
|
594
|
+
},
|
|
595
|
+
dragType: u ?? null,
|
|
596
|
+
tableDimensions: {
|
|
597
|
+
height: (e.tableRef?.current?.offsetHeight ?? 0) - (v ? v.offsetHeight - v.clientHeight : 0),
|
|
598
|
+
width: (e.tableRef?.current?.offsetWidth ?? 0) - (v ? v.offsetWidth - v.clientWidth : 0)
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
let S = v?.scrollLeft ?? 0, C = v?.scrollTop ?? 0;
|
|
603
|
+
requestAnimationFrame(() => {
|
|
604
|
+
let t = e.cloneRef?.current;
|
|
605
|
+
t && (u === "row" ? t.scrollLeft = S : V.current && (V.current.scrollTop = C));
|
|
606
|
+
});
|
|
607
|
+
}, [
|
|
608
|
+
n,
|
|
609
|
+
e,
|
|
610
|
+
m,
|
|
611
|
+
f,
|
|
612
|
+
E,
|
|
613
|
+
_,
|
|
614
|
+
k,
|
|
615
|
+
A,
|
|
616
|
+
T,
|
|
617
|
+
w
|
|
618
|
+
]), G = r((t, r, i, a, o) => {
|
|
619
|
+
let s = e.cloneRef?.current;
|
|
620
|
+
s && (s.style.visibility = "hidden"), H.current &&= (H.current.style.opacity = "", H.current.style.pointerEvents = "", H.current.style.zIndex = "", H.current.style.cursor = "", null), U.current.forEach((e) => {
|
|
621
|
+
e.style.opacity = "";
|
|
622
|
+
}), U.current = [];
|
|
623
|
+
let l = e.tableRef?.current;
|
|
624
|
+
l && (l.style.touchAction = ""), p(() => {
|
|
625
|
+
c && t !== null && r !== null && (i === "row" || i === "column") && c({
|
|
626
|
+
sourceIndex: t,
|
|
627
|
+
targetIndex: r,
|
|
628
|
+
dragType: i
|
|
629
|
+
}), n({
|
|
630
|
+
type: "dragEnd",
|
|
631
|
+
value: {
|
|
632
|
+
targetIndex: r,
|
|
633
|
+
sourceIndex: t
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
}), C();
|
|
637
|
+
let u = e.bodyRef?.current;
|
|
638
|
+
u && (u.scrollTop = a, u.scrollLeft = o, requestAnimationFrame(() => {
|
|
639
|
+
u.scrollTop = a, u.scrollLeft = o;
|
|
640
|
+
}));
|
|
641
|
+
}, [
|
|
642
|
+
n,
|
|
643
|
+
e.bodyRef,
|
|
644
|
+
e.cloneRef,
|
|
645
|
+
e.tableRef,
|
|
646
|
+
C,
|
|
647
|
+
c
|
|
648
|
+
]), K = r(() => {
|
|
649
|
+
if (I.current) return;
|
|
650
|
+
I.current = !0, Y(), setTimeout(() => {
|
|
651
|
+
X.current = !1;
|
|
652
|
+
}, 400);
|
|
653
|
+
let t = F.current, n = P.current, r = j.current, i = e.bodyRef?.current, a = i?.scrollTop ?? 0, o = i?.scrollLeft ?? 0;
|
|
654
|
+
k.current = null, A.current = null, d(), j.current = null, P.current = null, F.current = null;
|
|
655
|
+
let s = e.cloneRef?.current, c = e.placeholderRef?.current;
|
|
656
|
+
if (s && c && c.style.display !== "none") {
|
|
657
|
+
let e = parseFloat(c.style.left) || 0, i = parseFloat(c.style.top) || 0;
|
|
658
|
+
s.style.transition = `transform ${L}ms cubic-bezier(0.2, 0, 0, 1)`, s.style.transform = `translate(${e}px, ${i}px)`, setTimeout(() => G(n, t, r, a, o), L);
|
|
659
|
+
} else G(n, t, r, a, o);
|
|
660
|
+
}, [
|
|
661
|
+
d,
|
|
662
|
+
e.bodyRef,
|
|
663
|
+
e.placeholderRef,
|
|
664
|
+
e.cloneRef,
|
|
665
|
+
G
|
|
666
|
+
]), q = l(() => {}), { touchStart: J, cancelLongPress: Y, isTouchActiveRef: X } = M(e, W, K, (e, t) => q.current(e, t)), Z = r((e) => {
|
|
667
|
+
e.button === 0 && e.target !== e.currentTarget && (X.current || ne(e.clientX, e.clientY, e.target) || W(e, e.clientX, e.clientY));
|
|
668
|
+
}, [W, X]), Q = r((t, n) => {
|
|
669
|
+
if (I.current) return;
|
|
670
|
+
let r = N.current;
|
|
671
|
+
m.current.x = t, m.current.y = n;
|
|
672
|
+
let a = e.bodyRef?.current;
|
|
673
|
+
if (!a) return;
|
|
674
|
+
let o = A.current;
|
|
675
|
+
(!o || x.current) && (o = a.getBoundingClientRect(), A.current = o);
|
|
676
|
+
let s = a.scrollLeft, c = a.scrollTop, l = e.cloneRef?.current;
|
|
677
|
+
l && (l.style.transform = `translate(${t - r.x}px, ${n - r.y}px)`, j.current === "row" ? l.scrollLeft = s : V.current && (V.current.scrollTop = c));
|
|
678
|
+
let f = j.current || i;
|
|
679
|
+
if (B.current && _.checkStaleness(), x.current && (k.current = null, F.current = null, w.current = null, B.current ? f === "row" ? _.rebuildRowMap(a) : _.rebuildColumnMaps(a, e.headerRef?.current ?? null) : x.current = !1), f === "row") if (n < o.top + R) u(-z, a, "vertical"), x.current = !0;
|
|
680
|
+
else if (n > o.bottom - R) u(z, a, "vertical"), x.current = !0;
|
|
681
|
+
else {
|
|
682
|
+
let t = h.current;
|
|
683
|
+
d(), t && requestAnimationFrame(() => {
|
|
684
|
+
let t = e.bodyRef?.current;
|
|
685
|
+
if (!t) return;
|
|
686
|
+
B.current && _.rebuildRowMap(t), k.current = null;
|
|
687
|
+
let n = t.getBoundingClientRect();
|
|
688
|
+
A.current = n;
|
|
689
|
+
let r = O(m.current.x, m.current.y, "row", n, t.scrollTop, N.current, T.current);
|
|
690
|
+
F.current = r, w.current = null, S(P.current, r, "row");
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
else if (t < o.left + R) u(-z, a, "horizontal"), x.current = !0;
|
|
694
|
+
else if (t > o.right - R) u(z, a, "horizontal"), x.current = !0;
|
|
695
|
+
else {
|
|
696
|
+
let t = g.current;
|
|
697
|
+
d(), t && requestAnimationFrame(() => {
|
|
698
|
+
let t = e.bodyRef?.current;
|
|
699
|
+
if (!t) return;
|
|
700
|
+
B.current && _.rebuildColumnMaps(t, e.headerRef?.current ?? null), k.current = null;
|
|
701
|
+
let n = t.getBoundingClientRect();
|
|
702
|
+
A.current = n;
|
|
703
|
+
let r = O(m.current.x, m.current.y, "column", n, t.scrollTop, N.current, T.current);
|
|
704
|
+
F.current = r, w.current = null, S(P.current, r, "column");
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
let p = O(t, n, f, o, c, r, T.current);
|
|
708
|
+
p !== F.current && (F.current = p, requestAnimationFrame(() => S(P.current, p, f)));
|
|
709
|
+
}, [
|
|
710
|
+
m,
|
|
711
|
+
e.bodyRef,
|
|
712
|
+
e.cloneRef,
|
|
713
|
+
e.headerRef,
|
|
714
|
+
i,
|
|
715
|
+
u,
|
|
716
|
+
d,
|
|
717
|
+
h,
|
|
718
|
+
g,
|
|
719
|
+
_,
|
|
720
|
+
O,
|
|
721
|
+
S,
|
|
722
|
+
k,
|
|
723
|
+
A,
|
|
724
|
+
x,
|
|
725
|
+
w,
|
|
726
|
+
T
|
|
727
|
+
]);
|
|
728
|
+
q.current = Q;
|
|
729
|
+
let $ = r(() => {
|
|
730
|
+
Y(), k.current = null, A.current = null;
|
|
731
|
+
let t = e.cloneRef?.current;
|
|
732
|
+
t && (t.style.visibility = "hidden");
|
|
733
|
+
let r = e.tableRef?.current;
|
|
734
|
+
r && (r.style.touchAction = ""), n({
|
|
735
|
+
type: "dragEnd",
|
|
736
|
+
value: {
|
|
737
|
+
targetIndex: null,
|
|
738
|
+
sourceIndex: null
|
|
739
|
+
}
|
|
740
|
+
}), d(), C(), j.current = null, P.current = null, F.current = null;
|
|
741
|
+
}, [
|
|
742
|
+
Y,
|
|
743
|
+
k,
|
|
744
|
+
A,
|
|
745
|
+
e.cloneRef,
|
|
746
|
+
e.tableRef,
|
|
747
|
+
n,
|
|
748
|
+
d,
|
|
749
|
+
C
|
|
750
|
+
]);
|
|
751
|
+
return s(() => {
|
|
752
|
+
if (!t.isDragging) {
|
|
753
|
+
C();
|
|
754
|
+
let t = e.cloneRef?.current;
|
|
755
|
+
t && (t.style.transition = "", t.style.transform = "translate(0px, 0px)", t.style.visibility = "", t.scrollLeft = 0, t.innerHTML = "");
|
|
756
|
+
}
|
|
757
|
+
}, [
|
|
758
|
+
t.isDragging,
|
|
759
|
+
C,
|
|
760
|
+
e.cloneRef
|
|
761
|
+
]), a(() => {
|
|
762
|
+
if (!t.isDragging) return;
|
|
763
|
+
let e = 0, n = 0, r = !1, i = (t) => {
|
|
764
|
+
e = t.clientX, n = t.clientY, r || (r = !0, requestAnimationFrame(() => {
|
|
765
|
+
r = !1, Q(e, n);
|
|
766
|
+
}));
|
|
767
|
+
}, a = () => K(), o = (e) => {
|
|
768
|
+
e.key === "Escape" && $();
|
|
769
|
+
};
|
|
770
|
+
return window.addEventListener("pointermove", i), window.addEventListener("pointerup", a), window.addEventListener("pointercancel", a), window.addEventListener("keydown", o), () => {
|
|
771
|
+
window.removeEventListener("pointermove", i), window.removeEventListener("pointerup", a), window.removeEventListener("pointercancel", a), window.removeEventListener("keydown", o);
|
|
772
|
+
};
|
|
773
|
+
}, [
|
|
774
|
+
t.isDragging,
|
|
775
|
+
Q,
|
|
776
|
+
K,
|
|
777
|
+
$
|
|
778
|
+
]), {
|
|
779
|
+
dragStart: Z,
|
|
780
|
+
touchStart: J
|
|
781
|
+
};
|
|
782
|
+
}, V = {
|
|
783
|
+
columnDragRange: {
|
|
784
|
+
start: void 0,
|
|
785
|
+
end: void 0
|
|
786
|
+
},
|
|
787
|
+
rowDragRange: {
|
|
788
|
+
start: void 0,
|
|
789
|
+
end: void 0
|
|
790
|
+
},
|
|
791
|
+
defaultSizing: 50
|
|
792
|
+
};
|
|
793
|
+
function H(e, t) {
|
|
794
|
+
switch (t.type) {
|
|
795
|
+
case "setDragged": return {
|
|
796
|
+
...e,
|
|
797
|
+
dragged: {
|
|
798
|
+
...e.dragged,
|
|
799
|
+
...t.value
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
case "setDragType": return {
|
|
803
|
+
...e,
|
|
804
|
+
dragType: t.value
|
|
805
|
+
};
|
|
806
|
+
case "setTableDimensions": return {
|
|
807
|
+
...e,
|
|
808
|
+
tableDimensions: t.value
|
|
809
|
+
};
|
|
810
|
+
case "setRef": return {
|
|
811
|
+
...e,
|
|
812
|
+
refs: {
|
|
813
|
+
...e.refs,
|
|
814
|
+
[t.refName]: t.value
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
case "setBodyScrollBarWidth": return {
|
|
818
|
+
...e,
|
|
819
|
+
bodyScrollBarWidth: t.value
|
|
820
|
+
};
|
|
821
|
+
case "setWidths": return {
|
|
822
|
+
...e,
|
|
823
|
+
widths: t.value
|
|
824
|
+
};
|
|
825
|
+
case "setColumnIds": return {
|
|
826
|
+
...e,
|
|
827
|
+
columnIds: t.value
|
|
828
|
+
};
|
|
829
|
+
case "setOptions": return {
|
|
830
|
+
...e,
|
|
831
|
+
options: {
|
|
832
|
+
...e.options,
|
|
833
|
+
...t.value
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
case "dragStart": return {
|
|
837
|
+
...e,
|
|
838
|
+
rect: t.value.rect,
|
|
839
|
+
dragged: {
|
|
840
|
+
...e.dragged,
|
|
841
|
+
...t.value.dragged
|
|
842
|
+
},
|
|
843
|
+
dragType: t.value.dragType,
|
|
844
|
+
tableDimensions: t.value.tableDimensions
|
|
845
|
+
};
|
|
846
|
+
case "dragEnd": return {
|
|
847
|
+
...e,
|
|
848
|
+
dragged: {
|
|
849
|
+
initial: {
|
|
850
|
+
x: 0,
|
|
851
|
+
y: 0
|
|
852
|
+
},
|
|
853
|
+
translate: {
|
|
854
|
+
x: 0,
|
|
855
|
+
y: 0
|
|
856
|
+
},
|
|
857
|
+
isDragging: !1,
|
|
858
|
+
draggedID: null,
|
|
859
|
+
targetIndex: t.value?.targetIndex ?? null,
|
|
860
|
+
sourceIndex: t.value?.sourceIndex ?? null
|
|
861
|
+
},
|
|
862
|
+
dragType: null,
|
|
863
|
+
rect: {
|
|
864
|
+
draggedItemWidth: 0,
|
|
865
|
+
draggedItemHeight: 0
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
default: throw Error("Unhandled action");
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
var U = {
|
|
872
|
+
dragged: {
|
|
873
|
+
initial: {
|
|
874
|
+
x: 0,
|
|
875
|
+
y: 0
|
|
876
|
+
},
|
|
877
|
+
translate: {
|
|
878
|
+
x: 0,
|
|
879
|
+
y: 0
|
|
880
|
+
},
|
|
881
|
+
isDragging: !1,
|
|
882
|
+
draggedID: null,
|
|
883
|
+
targetIndex: null,
|
|
884
|
+
sourceIndex: null
|
|
885
|
+
},
|
|
886
|
+
dragType: null,
|
|
887
|
+
rect: {
|
|
888
|
+
draggedItemWidth: 0,
|
|
889
|
+
draggedItemHeight: 0
|
|
890
|
+
},
|
|
891
|
+
tableDimensions: {
|
|
892
|
+
height: 0,
|
|
893
|
+
width: 0
|
|
894
|
+
},
|
|
895
|
+
refs: {
|
|
896
|
+
tableRef: { current: null },
|
|
897
|
+
bodyRef: { current: null },
|
|
898
|
+
headerRef: { current: null },
|
|
899
|
+
cloneRef: { current: null },
|
|
900
|
+
placeholderRef: { current: null }
|
|
901
|
+
},
|
|
902
|
+
bodyScrollBarWidth: 0,
|
|
903
|
+
options: V,
|
|
904
|
+
widths: [],
|
|
905
|
+
columnIds: []
|
|
906
|
+
}, W = {
|
|
907
|
+
position: "relative",
|
|
908
|
+
display: "flex",
|
|
909
|
+
flexFlow: "column"
|
|
910
|
+
}, G = {
|
|
911
|
+
position: "fixed",
|
|
912
|
+
pointerEvents: "none",
|
|
913
|
+
zIndex: 3,
|
|
914
|
+
top: 0,
|
|
915
|
+
left: 0,
|
|
916
|
+
display: "none"
|
|
917
|
+
}, K = t(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: s }, p) => {
|
|
918
|
+
let m = l(null), h = l(null), g = l(null);
|
|
919
|
+
o(p, () => m.current, []);
|
|
920
|
+
let [v] = u(() => T(H, U)), y = (0, b.useSyncExternalStore)(v.subscribe, v.getState), S = v.dispatch;
|
|
921
|
+
a(() => {
|
|
922
|
+
S({
|
|
923
|
+
type: "setRef",
|
|
924
|
+
refName: "tableRef",
|
|
925
|
+
value: m
|
|
926
|
+
}), S({
|
|
927
|
+
type: "setRef",
|
|
928
|
+
refName: "cloneRef",
|
|
929
|
+
value: h
|
|
930
|
+
}), S({
|
|
931
|
+
type: "setRef",
|
|
932
|
+
refName: "placeholderRef",
|
|
933
|
+
value: g
|
|
934
|
+
});
|
|
935
|
+
}, [m, S]), a(() => {
|
|
936
|
+
let e = () => {
|
|
937
|
+
m.current && S({
|
|
938
|
+
type: "setTableDimensions",
|
|
939
|
+
value: {
|
|
940
|
+
height: m.current.offsetHeight,
|
|
941
|
+
width: m.current.offsetWidth
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
};
|
|
945
|
+
return e(), window.addEventListener("resize", e), () => {
|
|
946
|
+
window.removeEventListener("resize", e);
|
|
947
|
+
};
|
|
948
|
+
}, [m, S]), a(() => {
|
|
949
|
+
r && S({
|
|
950
|
+
type: "setOptions",
|
|
951
|
+
value: r
|
|
952
|
+
});
|
|
953
|
+
}, [r, S]);
|
|
954
|
+
let { dragStart: C, touchStart: w } = B(y.refs, y.dragged, S, y.dragType, y.options, i), E = c(() => ({
|
|
955
|
+
position: "fixed",
|
|
956
|
+
zIndex: "5",
|
|
957
|
+
pointerEvents: "none",
|
|
958
|
+
top: 0,
|
|
959
|
+
left: 0,
|
|
960
|
+
display: "flex",
|
|
961
|
+
flexDirection: "column",
|
|
962
|
+
height: y.dragType === "row" ? y.rect.draggedItemHeight : `${y.tableDimensions.height}px`,
|
|
963
|
+
width: y.dragType === "column" ? `${y.rect.draggedItemWidth}px` : `${y.tableDimensions.width}px`,
|
|
964
|
+
overflow: "scroll",
|
|
965
|
+
scrollbarWidth: "none",
|
|
966
|
+
boxShadow: y.dragged.isDragging ? "0 0 10px 0 rgba(0, 0, 0, 0.1)" : "none"
|
|
967
|
+
}), [
|
|
968
|
+
y.dragType,
|
|
969
|
+
y.dragged.isDragging,
|
|
970
|
+
y.rect.draggedItemHeight,
|
|
971
|
+
y.rect.draggedItemWidth,
|
|
972
|
+
y.tableDimensions.height,
|
|
973
|
+
y.tableDimensions.width
|
|
974
|
+
]);
|
|
975
|
+
return /* @__PURE__ */ d(x.Provider, {
|
|
976
|
+
value: v,
|
|
977
|
+
children: /* @__PURE__ */ f(_, {
|
|
978
|
+
className: y.dragged.isDragging ? "is-dragging" : "",
|
|
979
|
+
children: [
|
|
980
|
+
/* @__PURE__ */ d("div", {
|
|
981
|
+
id: "portalroot",
|
|
982
|
+
style: {
|
|
983
|
+
...E,
|
|
984
|
+
visibility: y.dragged.isDragging ? "visible" : "hidden"
|
|
985
|
+
},
|
|
986
|
+
ref: h
|
|
987
|
+
}),
|
|
988
|
+
/* @__PURE__ */ d("div", {
|
|
989
|
+
ref: g,
|
|
990
|
+
style: G,
|
|
991
|
+
children: s ? s() : /* @__PURE__ */ d("div", { style: {
|
|
992
|
+
width: "100%",
|
|
993
|
+
height: "100%"
|
|
994
|
+
} })
|
|
995
|
+
}),
|
|
996
|
+
/* @__PURE__ */ d("div", {
|
|
997
|
+
"data-contextid": "context",
|
|
998
|
+
ref: m,
|
|
999
|
+
onMouseDown: C,
|
|
1000
|
+
onTouchStart: w,
|
|
1001
|
+
style: {
|
|
1002
|
+
...W,
|
|
1003
|
+
...n
|
|
1004
|
+
},
|
|
1005
|
+
className: `table ${t ?? ""}`,
|
|
1006
|
+
children: e
|
|
1007
|
+
})
|
|
1008
|
+
]
|
|
1009
|
+
})
|
|
1010
|
+
});
|
|
1011
|
+
});
|
|
1012
|
+
K.displayName = "TableProvider";
|
|
1013
|
+
//#endregion
|
|
1014
|
+
//#region src/Components/TableHeader.tsx
|
|
1015
|
+
var q = t(({ children: e, style: t, className: n }, i) => {
|
|
1016
|
+
let o = l(null), u = i || o, f = S((e) => e.bodyScrollBarWidth), p = S((e) => e.dragged.isDragging), m = S((e) => e.refs), h = C(), g = r((e) => "current" in e ? e.current : null, []);
|
|
1017
|
+
a(() => {
|
|
1018
|
+
o.current && h({
|
|
1019
|
+
type: "setRef",
|
|
1020
|
+
refName: "headerRef",
|
|
1021
|
+
value: o
|
|
1022
|
+
});
|
|
1023
|
+
}, [h]);
|
|
1024
|
+
let { HeaderScrollHandle: _ } = D(m), v = {
|
|
1025
|
+
display: "flex",
|
|
1026
|
+
flex: "1 0 auto"
|
|
1027
|
+
}, y = c(() => ({
|
|
1028
|
+
overflowX: "scroll",
|
|
1029
|
+
overflowY: "clip",
|
|
1030
|
+
scrollbarWidth: "none",
|
|
1031
|
+
display: "flex",
|
|
1032
|
+
paddingRight: `${f}px`,
|
|
1033
|
+
userSelect: p ? "none" : "auto",
|
|
1034
|
+
...t
|
|
1035
|
+
}), [
|
|
1036
|
+
f,
|
|
1037
|
+
p,
|
|
1038
|
+
t
|
|
1039
|
+
]);
|
|
1040
|
+
return s(() => {
|
|
1041
|
+
let e = g(u);
|
|
1042
|
+
e && h({
|
|
1043
|
+
type: "setWidths",
|
|
1044
|
+
value: Array.from(e.querySelectorAll(".th")).map((e) => {
|
|
1045
|
+
let t = e.getAttribute("data-width");
|
|
1046
|
+
return t ? parseInt(t, 10) : 0;
|
|
1047
|
+
})
|
|
1048
|
+
});
|
|
1049
|
+
}, [
|
|
1050
|
+
e,
|
|
1051
|
+
h,
|
|
1052
|
+
g,
|
|
1053
|
+
u
|
|
1054
|
+
]), s(() => {
|
|
1055
|
+
let e = g(u);
|
|
1056
|
+
e && h({
|
|
1057
|
+
type: "setColumnIds",
|
|
1058
|
+
value: Array.from(e.querySelectorAll(".draggable")).map((e) => e.getAttribute("data-id") || "")
|
|
1059
|
+
});
|
|
1060
|
+
}, [
|
|
1061
|
+
e,
|
|
1062
|
+
h,
|
|
1063
|
+
g,
|
|
1064
|
+
u
|
|
1065
|
+
]), /* @__PURE__ */ d("div", {
|
|
1066
|
+
className: `header ${n ?? ""}`,
|
|
1067
|
+
children: /* @__PURE__ */ d("div", {
|
|
1068
|
+
className: "thead",
|
|
1069
|
+
style: y,
|
|
1070
|
+
"data-droppableid": "header",
|
|
1071
|
+
onScroll: _,
|
|
1072
|
+
ref: u,
|
|
1073
|
+
children: /* @__PURE__ */ d("div", {
|
|
1074
|
+
style: v,
|
|
1075
|
+
className: "tr",
|
|
1076
|
+
children: e
|
|
1077
|
+
})
|
|
1078
|
+
})
|
|
1079
|
+
});
|
|
1080
|
+
});
|
|
1081
|
+
q.displayName = "TableHeader";
|
|
1082
|
+
//#endregion
|
|
1083
|
+
//#region src/Components/Draggable.tsx
|
|
1084
|
+
var J = n(({ children: e, id: t, index: n, type: r, styles: i = {} }) => {
|
|
1085
|
+
let o = S((e) => e.options.rowDragRange), s = S((e) => e.options.columnDragRange), u = c(() => r === "row" ? I(n, o.start, o.end) : I(n, s.start, s.end), [
|
|
1086
|
+
n,
|
|
1087
|
+
s.end,
|
|
1088
|
+
s.start,
|
|
1089
|
+
o.end,
|
|
1090
|
+
o.start,
|
|
1091
|
+
r
|
|
1092
|
+
]), f = l(null), p = c(() => ({
|
|
1093
|
+
cursor: u ? "auto" : "-webkit-grab",
|
|
1094
|
+
display: "flex"
|
|
1095
|
+
}), [u]);
|
|
1096
|
+
return a(() => {
|
|
1097
|
+
f.current && f.current.querySelector("[data-drag-handle]") && (f.current.style.cursor = "auto");
|
|
1098
|
+
}, [e, u]), /* @__PURE__ */ d("div", {
|
|
1099
|
+
className: "draggable",
|
|
1100
|
+
"data-id": t,
|
|
1101
|
+
"data-index": n,
|
|
1102
|
+
"data-type": r,
|
|
1103
|
+
"data-disabled": u ? "true" : "false",
|
|
1104
|
+
style: i,
|
|
1105
|
+
children: /* @__PURE__ */ d("div", {
|
|
1106
|
+
ref: f,
|
|
1107
|
+
style: p,
|
|
1108
|
+
children: e
|
|
1109
|
+
})
|
|
1110
|
+
});
|
|
1111
|
+
});
|
|
1112
|
+
J.displayName = "Draggable";
|
|
1113
|
+
//#endregion
|
|
1114
|
+
//#region src/Components/ColumnCell.tsx
|
|
1115
|
+
var Y = n(({ children: e, style: t, className: n, ...r }) => {
|
|
1116
|
+
let i = S((e) => e.options.defaultSizing), { width: a, flex: o, ...s } = t ?? {}, l = c(() => a === void 0 ? i : typeof a == "number" ? a : parseFloat(String(a)) || i, [a, i]), u = c(() => ({
|
|
1117
|
+
width: `${l}px`,
|
|
1118
|
+
flex: o === void 0 ? `${l} 0 auto` : o
|
|
1119
|
+
}), [l, o]);
|
|
1120
|
+
return /* @__PURE__ */ d(J, {
|
|
1121
|
+
...r,
|
|
1122
|
+
styles: u,
|
|
1123
|
+
type: "column",
|
|
1124
|
+
children: /* @__PURE__ */ d("div", {
|
|
1125
|
+
className: `th ${n ?? ""}`,
|
|
1126
|
+
"data-width": l,
|
|
1127
|
+
style: {
|
|
1128
|
+
width: "100%",
|
|
1129
|
+
...s
|
|
1130
|
+
},
|
|
1131
|
+
children: e
|
|
1132
|
+
})
|
|
1133
|
+
});
|
|
1134
|
+
});
|
|
1135
|
+
Y.displayName = "ColumnCell";
|
|
1136
|
+
//#endregion
|
|
1137
|
+
//#region src/Components/TableBody.tsx
|
|
1138
|
+
var X = {
|
|
1139
|
+
display: "flex",
|
|
1140
|
+
overflow: "hidden",
|
|
1141
|
+
flex: 1
|
|
1142
|
+
}, Z = t(({ children: e, style: t, className: n }, r) => {
|
|
1143
|
+
let i = l(null);
|
|
1144
|
+
o(r, () => i.current, []);
|
|
1145
|
+
let s = S((e) => e.dragged.isDragging), u = S((e) => e.refs), f = C();
|
|
1146
|
+
a(() => {
|
|
1147
|
+
f({
|
|
1148
|
+
type: "setRef",
|
|
1149
|
+
refName: "bodyRef",
|
|
1150
|
+
value: i
|
|
1151
|
+
});
|
|
1152
|
+
}, [f, i]);
|
|
1153
|
+
let { BodyScrollHandle: p } = D(u), m = c(() => ({
|
|
1154
|
+
overflowX: "auto",
|
|
1155
|
+
overflowY: "auto",
|
|
1156
|
+
flex: 1,
|
|
1157
|
+
userSelect: s ? "none" : "auto",
|
|
1158
|
+
...t
|
|
1159
|
+
}), [s, t]);
|
|
1160
|
+
return a(() => {
|
|
1161
|
+
if (i.current) {
|
|
1162
|
+
let e = i.current.clientWidth;
|
|
1163
|
+
f({
|
|
1164
|
+
type: "setBodyScrollBarWidth",
|
|
1165
|
+
value: i.current.offsetWidth - e
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
}, [f, i]), /* @__PURE__ */ d("div", {
|
|
1169
|
+
className: `body ${n ?? ""}`,
|
|
1170
|
+
style: X,
|
|
1171
|
+
children: /* @__PURE__ */ d("div", {
|
|
1172
|
+
className: "ibody",
|
|
1173
|
+
style: m,
|
|
1174
|
+
"data-droppableid": "body",
|
|
1175
|
+
onScroll: p,
|
|
1176
|
+
ref: i,
|
|
1177
|
+
children: e
|
|
1178
|
+
})
|
|
1179
|
+
});
|
|
1180
|
+
}), Q = {
|
|
1181
|
+
display: "flex",
|
|
1182
|
+
flex: "1 0 auto",
|
|
1183
|
+
minHeight: "24px"
|
|
1184
|
+
}, $ = n(({ children: e, style: t, className: n, ...r }) => {
|
|
1185
|
+
let i = c(() => t ? {
|
|
1186
|
+
...Q,
|
|
1187
|
+
...t
|
|
1188
|
+
} : Q, [t]), a = m("tr", n);
|
|
1189
|
+
return /* @__PURE__ */ d(J, {
|
|
1190
|
+
...r,
|
|
1191
|
+
type: "row",
|
|
1192
|
+
children: /* @__PURE__ */ d("div", {
|
|
1193
|
+
className: a,
|
|
1194
|
+
style: i,
|
|
1195
|
+
children: e
|
|
1196
|
+
})
|
|
1197
|
+
});
|
|
1198
|
+
});
|
|
1199
|
+
$.displayName = "BodyRow";
|
|
1200
|
+
//#endregion
|
|
1201
|
+
//#region src/Components/RowCell.tsx
|
|
1202
|
+
var ae = n(({ children: e, style: t, className: n, ...r }) => {
|
|
1203
|
+
let { index: i } = r, a = S((e) => e.widths), o = S((e) => e.options.defaultSizing), s = c(() => a[i] ?? o, [
|
|
1204
|
+
a,
|
|
1205
|
+
i,
|
|
1206
|
+
o
|
|
1207
|
+
]), l = c(() => ({
|
|
1208
|
+
display: "inline-flex",
|
|
1209
|
+
width: `${s}px`,
|
|
1210
|
+
flex: `${s} 0 auto`,
|
|
1211
|
+
...t
|
|
1212
|
+
}), [s, t]);
|
|
1213
|
+
return /* @__PURE__ */ d("div", {
|
|
1214
|
+
className: `td ${n ?? ""}`,
|
|
1215
|
+
style: l,
|
|
1216
|
+
"data-col-index": i,
|
|
1217
|
+
children: e
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
ae.displayName = "RowCell";
|
|
1221
|
+
//#endregion
|
|
1222
|
+
//#region src/Components/DragHandle.tsx
|
|
1223
|
+
var oe = n(({ children: e, className: t, style: n }) => /* @__PURE__ */ d("div", {
|
|
1224
|
+
"data-drag-handle": "true",
|
|
1225
|
+
className: t,
|
|
1226
|
+
style: {
|
|
1227
|
+
cursor: "-webkit-grab",
|
|
1228
|
+
display: "inline-flex",
|
|
1229
|
+
alignItems: "center",
|
|
1230
|
+
...n
|
|
1231
|
+
},
|
|
1232
|
+
children: e
|
|
1233
|
+
}));
|
|
1234
|
+
oe.displayName = "DragHandle";
|
|
1235
|
+
//#endregion
|
|
1236
|
+
export { $ as BodyRow, Y as ColumnCell, oe as DragHandle, ae as RowCell, Z as TableBody, K as TableContainer, q as TableHeader, w as useTable, C as useTableDispatch, S as useTableStore };
|