flexitablesort 1.1.8 → 1.1.11

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/dist/index.es.js CHANGED
@@ -1,15 +1,21 @@
1
- import e, { createContext as t, forwardRef as n, memo as r, useCallback as i, useContext as a, useEffect as o, useImperativeHandle as s, useMemo as c, useReducer as l, useRef as u } from "react";
2
- import d from "styled-components";
3
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
4
- import { createPortal as m } from "react-dom";
5
- import h from "classnames";
1
+ import e, { createContext as t, forwardRef as n, memo as r, useCallback as i, useContext as a, useEffect as o, useImperativeHandle as s, useLayoutEffect as c, useMemo as l, useReducer as u, useRef as d, useState as f } from "react";
2
+ import p from "styled-components";
3
+ import { createPortal as m, flushSync as h } from "react-dom";
4
+ import { jsx as g, jsxs as _ } from "react/jsx-runtime";
5
+ import v from "classnames";
6
6
  //#region src/Components/TableContainer/styles.tsx
7
- var g = d.div`
7
+ var y = p.div`
8
8
  height: 100%;
9
9
 
10
10
  /* Structural elements: full reset */
11
- &, & .table, & .header, & .thead, & .body, & .ibody,
12
- & .draggable, & .tr {
11
+ &,
12
+ & .table,
13
+ & .header,
14
+ & .thead,
15
+ & .body,
16
+ & .ibody,
17
+ & .draggable,
18
+ & .tr {
13
19
  box-sizing: border-box;
14
20
  margin: 0;
15
21
  padding: 0;
@@ -17,93 +23,109 @@ var g = d.div`
17
23
 
18
24
  /* User-facing cells: only box-sizing reset — no padding/margin override
19
25
  so className and styled-components can customize freely */
20
- & .th, & .td {
26
+ & .th,
27
+ & .td {
21
28
  box-sizing: border-box;
22
29
  }
23
30
 
24
- &.is-dragging, &.is-dragging * {
31
+ &.is-dragging,
32
+ &.is-dragging * {
33
+ cursor: -webkit-grabbing !important;
34
+ cursor: grabbing !important;
25
35
  user-select: none !important;
26
36
  -webkit-user-select: none !important;
37
+ -webkit-touch-callout: none !important;
27
38
  }
28
- `, _ = t(void 0), v = () => {
29
- let e = a(_);
39
+
40
+ /* When a DragHandle exists, only the handle shows grab cursor */
41
+ &:not(.is-dragging) .draggable:has([data-drag-handle]) > div {
42
+ cursor: default !important;
43
+ }
44
+ &:not(.is-dragging) [data-drag-handle] {
45
+ cursor: -webkit-grab;
46
+ cursor: grab;
47
+ }
48
+ `, b = t(void 0), x = () => {
49
+ let e = a(b);
30
50
  if (e === void 0) throw Error("useTable must be used within a TableProvider");
31
51
  return e;
32
- }, y = 30, b = (e) => {
33
- let t = u(!1), n = u(!1), r = u(0), a = u(null), o = u({
52
+ }, S = 30, C = (e) => {
53
+ let { headerRef: t, bodyRef: n } = e, r = d(null), a = d(!1), s = d(!1), c = d(0), l = d(null), u = d({
34
54
  x: 0,
35
55
  y: 0
36
- }), s = u(null), c = i((e) => {
37
- s.current = e;
38
- }, []), l = i(() => {
39
- n.current = !1, t.current = !1, a.current !== null && (cancelAnimationFrame(a.current), a.current = null);
40
- }, []), d = i((e, i, c) => {
41
- let l = c === "vertical", u = l ? n : t;
42
- if (!u.current) return;
43
- let f = s.current;
44
- if (f) {
45
- let e = o.current;
46
- if (l) {
47
- let t = e.y < f.top + y, n = e.y > f.bottom - y;
56
+ }), f = d(null), p = i((e) => {
57
+ f.current = e;
58
+ }, []), m = i(() => {
59
+ s.current = !1, a.current = !1, l.current !== null && (cancelAnimationFrame(l.current), l.current = null);
60
+ }, []), h = i((e, t, n) => {
61
+ let i = n === "vertical", o = i ? s : a;
62
+ if (!o.current) return;
63
+ let d = f.current;
64
+ if (d) {
65
+ let e = u.current;
66
+ if (i) {
67
+ let t = e.y < d.top + S, n = e.y > d.bottom - S;
48
68
  if (!t && !n) {
49
- u.current = !1;
69
+ o.current = !1;
50
70
  return;
51
71
  }
52
72
  } else {
53
- let t = e.x < f.left + y, n = e.x > f.right - y;
73
+ let t = e.x < d.left + S, n = e.x > d.right - S;
54
74
  if (!t && !n) {
55
- u.current = !1;
75
+ o.current = !1;
56
76
  return;
57
77
  }
58
78
  }
59
79
  }
60
- let p = l ? i.scrollHeight - i.clientHeight : i.scrollWidth - i.clientWidth;
61
- l ? i.scrollTop += e : i.scrollLeft += e;
62
- let m = l ? i.scrollTop : i.scrollLeft;
80
+ let p = i ? t.scrollHeight - t.clientHeight : t.scrollWidth - t.clientWidth;
81
+ i ? t.scrollTop += e : t.scrollLeft += e;
82
+ let m = i ? t.scrollTop : t.scrollLeft;
63
83
  if (m >= p || m <= 0) {
64
- u.current = !1;
84
+ o.current = !1;
65
85
  return;
66
86
  }
67
- r.current += e / 1e3, a.current = requestAnimationFrame(() => d(e + r.current, i, c));
87
+ c.current += e / 1e3, l.current = requestAnimationFrame(() => r.current?.(e + c.current, t, n));
68
88
  }, []);
69
- return {
70
- startAutoScroll: i((e, i, o) => {
71
- let s = o === "vertical" ? n : t;
72
- s.current || (s.current = !0, r.current = 0, a.current = requestAnimationFrame(() => d(e, i, o)));
73
- }, [d]),
74
- stopAutoScroll: l,
75
- setContainerRect: c,
76
- isAutoScrollingVertical: n,
77
- isAutoScrollingHorizontal: t,
78
- pointerRef: o,
79
- BodyScrollHandle: i((t) => {
80
- e.headerRef?.current && t.currentTarget && (e.headerRef.current.scrollLeft = t.currentTarget.scrollLeft);
81
- }, [e]),
82
- HeaderScrollHandle: i((t) => {
83
- e.bodyRef?.current && t.currentTarget && (e.bodyRef.current.scrollLeft = t.currentTarget.scrollLeft);
84
- }, [e])
89
+ return o(() => {
90
+ r.current = h;
91
+ }, [h]), {
92
+ startAutoScroll: i((e, t, n) => {
93
+ let r = n === "vertical" ? s : a;
94
+ r.current || (r.current = !0, c.current = 0, l.current = requestAnimationFrame(() => h(e, t, n)));
95
+ }, [h]),
96
+ stopAutoScroll: m,
97
+ setContainerRect: p,
98
+ isAutoScrollingVertical: s,
99
+ isAutoScrollingHorizontal: a,
100
+ pointerRef: u,
101
+ BodyScrollHandle: i((e) => {
102
+ t?.current && e.currentTarget && (t.current.scrollLeft = e.currentTarget.scrollLeft);
103
+ }, [t]),
104
+ HeaderScrollHandle: i((e) => {
105
+ n?.current && e.currentTarget && (n.current.scrollLeft = e.currentTarget.scrollLeft);
106
+ }, [n])
85
107
  };
86
- }, x = 300, S = 8;
87
- function C(e, t, n, r) {
88
- let a = u(null), o = u({
108
+ }, w = 300, T = 8;
109
+ function E(e, t, n, r) {
110
+ let a = d(null), o = d({
89
111
  x: 0,
90
112
  y: 0
91
- }), s = u(null), c = u(!1), l = u(null), d = i(() => {
113
+ }), s = d(null), c = d(!1), l = d(null), u = i(() => {
92
114
  a.current &&= (clearTimeout(a.current), null), s.current = null, l.current &&= (l.current(), null);
93
115
  }, []);
94
116
  return {
95
117
  touchStart: i((i) => {
96
118
  if (i.target === i.currentTarget) return;
97
- let u = i.target, f = !1;
98
- for (; u && !(u.dataset?.contextid || u.dataset?.disabled === "true");) {
99
- if (u.dataset?.id) {
119
+ let d = i.target, f = !1;
120
+ for (; d && !(d.dataset?.contextid || d.dataset?.disabled === "true");) {
121
+ if (d.dataset?.id) {
100
122
  f = !0;
101
123
  break;
102
124
  }
103
- u = u.parentNode;
125
+ d = d.parentNode;
104
126
  }
105
127
  if (!f) return;
106
- d(), c.current = !0;
128
+ u(), c.current = !0, window.getSelection()?.removeAllRanges();
107
129
  let p = i.touches[0];
108
130
  o.current = {
109
131
  x: p.clientX,
@@ -111,7 +133,9 @@ function C(e, t, n, r) {
111
133
  }, s.current = i;
112
134
  let m = e.tableRef?.current;
113
135
  if (!m) return;
114
- let h = !1, g = !1, _ = p.clientY, v = p.clientX, y = (t) => {
136
+ let h = !1, g = !1, _ = p.clientY, v = p.clientX, y = (e) => e.preventDefault();
137
+ document.addEventListener("selectstart", y);
138
+ let b = (t) => {
115
139
  t.preventDefault();
116
140
  let n = t.touches[0];
117
141
  if (g) {
@@ -120,35 +144,35 @@ function C(e, t, n, r) {
120
144
  } else if (h) r(n.clientX, n.clientY);
121
145
  else {
122
146
  let e = n.clientX - o.current.x, t = n.clientY - o.current.y;
123
- (Math.abs(e) > S || Math.abs(t) > S) && (a.current &&= (clearTimeout(a.current), null), s.current = null, g = !0, _ = n.clientY, v = n.clientX);
147
+ (Math.abs(e) > T || Math.abs(t) > T) && (a.current &&= (clearTimeout(a.current), null), s.current = null, g = !0, _ = n.clientY, v = n.clientX);
124
148
  }
125
- }, b = () => {
126
- h ? (C(), n()) : (d(), setTimeout(() => {
149
+ }, x = () => {
150
+ h ? (S(), n()) : (u(), setTimeout(() => {
127
151
  c.current = !1;
128
152
  }, 400));
129
- }, C = () => {
130
- m.removeEventListener("touchmove", y), m.removeEventListener("touchend", b), m.removeEventListener("touchcancel", b), l.current = null;
153
+ }, S = () => {
154
+ m.removeEventListener("touchmove", b), m.removeEventListener("touchend", x), m.removeEventListener("touchcancel", x), document.removeEventListener("selectstart", y), l.current = null;
131
155
  };
132
- m.addEventListener("touchmove", y, { passive: !1 }), m.addEventListener("touchend", b, !1), m.addEventListener("touchcancel", b, !1), l.current = C, a.current = setTimeout(() => {
156
+ m.addEventListener("touchmove", b, { passive: !1 }), m.addEventListener("touchend", x, !1), m.addEventListener("touchcancel", x, !1), l.current = S, a.current = setTimeout(() => {
133
157
  a.current = null, h = !0;
134
158
  let e = s.current;
135
159
  s.current = null, e && t(e, p.clientX, p.clientY);
136
- }, x);
160
+ }, w);
137
161
  }, [
138
162
  t,
139
163
  n,
140
164
  r,
141
- d,
165
+ u,
142
166
  e.tableRef?.current,
143
167
  e.bodyRef?.current
144
168
  ]),
145
- cancelLongPress: d,
169
+ cancelLongPress: u,
146
170
  isTouchActiveRef: c
147
171
  };
148
172
  }
149
173
  //#endregion
150
174
  //#region src/Components/utils.ts
151
- var w = (e, t) => {
175
+ var D = (e, t) => {
152
176
  let n = e, r = 0, i = t.length - 1;
153
177
  for (; r < i;) {
154
178
  let e = Math.floor((r + i) / 2), a = t[e];
@@ -156,7 +180,7 @@ var w = (e, t) => {
156
180
  n < a.itemTop ? i = e - 1 : r = e + 1;
157
181
  }
158
182
  return +t[r].index;
159
- }, T = (e, t) => {
183
+ }, O = (e, t) => {
160
184
  let n = e, r = 0, i = t.length - 1;
161
185
  for (; r < i;) {
162
186
  let e = Math.floor((r + i) / 2), a = t[e];
@@ -164,17 +188,20 @@ var w = (e, t) => {
164
188
  n < a.itemLeft ? i = e - 1 : r = e + 1;
165
189
  }
166
190
  return +t[r].index;
167
- }, E = (e, t, n) => t !== void 0 && e < t || n !== void 0 && e > n, D = "all 450ms cubic-bezier(0.2, 0, 0, 1)", O = (e, t, n, r, a, s) => {
168
- let { startAutoScroll: c, stopAutoScroll: l, setContainerRect: d, pointerRef: f } = b(e), p = u(null), m = u(null), h = u(null), g = u({
191
+ }, k = (e, t, n) => {
192
+ let r = Number(e);
193
+ return t !== void 0 && r < t || n !== void 0 && r > n;
194
+ }, A = "transform 450ms cubic-bezier(0.2, 0, 0, 1)", j = 200, M = (e, t, n, r, a, s) => {
195
+ let { startAutoScroll: l, stopAutoScroll: u, setContainerRect: f, pointerRef: p } = C(e), m = d(null), g = d(null), _ = d(null), v = d({
169
196
  x: 0,
170
197
  y: 0
171
- }), _ = u(null), v = u(null), y = u({
198
+ }), y = d(null), b = d(null), x = d({
172
199
  width: 0,
173
200
  height: 0
174
- }), x = u({
201
+ }), S = d({
175
202
  x: 0,
176
203
  y: 0
177
- }), S = i(() => {
204
+ }), w = d(!1), T = i(() => {
178
205
  let t = e.bodyRef?.current;
179
206
  if (!t) return null;
180
207
  let n = t.scrollTop, r = t.getBoundingClientRect().top, i = t.querySelectorAll(".draggable[data-type=\"row\"]"), o = [];
@@ -191,7 +218,7 @@ var w = (e, t) => {
191
218
  }
192
219
  let { start: s, end: c } = a.rowDragRange;
193
220
  return (s || c) && (o = o.filter((e) => (!s || +e.index >= s) && (!c || +e.index < c))), o;
194
- }, [e.bodyRef, a.rowDragRange]), E = i(() => {
221
+ }, [e.bodyRef, a.rowDragRange]), k = i(() => {
195
222
  let t = e.headerRef?.current;
196
223
  if (!t || !t.children[0]) return null;
197
224
  let n = Array.from(t.children[0].children).map((e) => {
@@ -208,24 +235,24 @@ var w = (e, t) => {
208
235
  let t = +e.index;
209
236
  return (r === void 0 || t >= r) && (i === void 0 || t < i);
210
237
  })), n;
211
- }, [e.headerRef, a.columnDragRange]), O = i((t, n, r, i) => {
238
+ }, [e.headerRef, a.columnDragRange]), M = i((t, n, r, i) => {
212
239
  let a = e.placeholderRef?.current;
213
240
  if (!a || !t) {
214
241
  a && (a.style.display = "none");
215
242
  return;
216
243
  }
217
- let o = y.current, s = t.getBoundingClientRect(), c = e.tableRef?.current?.getBoundingClientRect(), l = (n ?? 0) < (r ?? 0);
244
+ let o = x.current, s = t.getBoundingClientRect(), c = e.tableRef?.current?.getBoundingClientRect(), l = (n ?? 0) < (r ?? 0);
218
245
  a.style.display = "block", i === "row" ? (a.style.top = `${l ? s.top + s.height - o.height : s.top}px`, a.style.left = `${c?.left ?? s.left}px`, a.style.width = `${c?.width ?? s.width}px`, a.style.height = `${o.height}px`) : (a.style.top = `${c?.top ?? s.top}px`, a.style.left = `${l ? s.left + s.width - o.width : s.left}px`, a.style.width = `${o.width}px`, a.style.height = `${c?.height ?? s.height}px`);
219
- }, [e.placeholderRef, e.tableRef]), k = i((t, n, r) => {
246
+ }, [e.placeholderRef, e.tableRef]), N = i((t, n, r) => {
220
247
  if (t === null || n === null) return;
221
- let i = y.current, a = null, o = (e, r, i, o) => {
248
+ let i = x.current, a = null, o = (e, r, i, o) => {
222
249
  if (!e) return;
223
250
  let s = e.querySelectorAll(r);
224
251
  for (let e = 0; e < s.length; e++) {
225
252
  let r = s[e], c = +r.dataset.index, l = r.firstElementChild;
226
253
  if (!l) continue;
227
254
  let u = "";
228
- c > t && c <= n ? u = `translate${i}(-${o}px)` : c < t && c >= n && (u = `translate${i}(${o}px)`), l.style.transform = u, l.style.transition = c === t ? "none" : D, c === n ? (r.setAttribute("data-drop-target", "true"), a = r) : r.removeAttribute("data-drop-target");
255
+ c > t && c <= n ? u = `translate${i}(-${o}px)` : c < t && c >= n && (u = `translate${i}(${o}px)`), l.style.transform = u, l.style.transition = c === t ? "none" : A, c === n ? (r.setAttribute("data-drop-target", "true"), a = r) : r.removeAttribute("data-drop-target");
229
256
  }
230
257
  };
231
258
  if (r === "row") o(e.bodyRef?.current ?? null, ".draggable[data-type=\"row\"]", "Y", i.height);
@@ -236,16 +263,16 @@ var w = (e, t) => {
236
263
  let e = r.querySelectorAll(".td[data-col-index]");
237
264
  for (let r = 0; r < e.length; r++) {
238
265
  let a = e[r], o = +a.dataset.colIndex, s = "";
239
- o > t && o <= n ? s = `translateX(-${i.width}px)` : o < t && o >= n && (s = `translateX(${i.width}px)`), a.style.transform = s, a.style.transition = D;
266
+ o > t && o <= n ? s = `translateX(-${i.width}px)` : o < t && o >= n && (s = `translateX(${i.width}px)`), a.style.transform = s, a.style.transition = A;
240
267
  }
241
268
  }
242
269
  }
243
- O(a, t, n, r);
270
+ M(a, t, n, r);
244
271
  }, [
245
272
  e.bodyRef,
246
273
  e.headerRef,
247
- O
248
- ]), A = i(() => {
274
+ M
275
+ ]), P = i(() => {
249
276
  let t = e.placeholderRef?.current;
250
277
  t && (t.style.display = "none");
251
278
  for (let t of [e.bodyRef?.current, e.headerRef?.current]) {
@@ -254,19 +281,19 @@ var w = (e, t) => {
254
281
  for (let t = 0; t < e.length; t++) {
255
282
  e[t].removeAttribute("data-drop-target");
256
283
  let n = e[t].firstElementChild;
257
- n && (n.style.transform = "", n.style.transition = "");
284
+ n && (n.style.transition = "none", n.style.transform = "");
258
285
  }
259
286
  }
260
287
  let n = e.bodyRef?.current;
261
288
  if (n) {
262
289
  let e = n.querySelectorAll(".td[data-col-index]");
263
- for (let t = 0; t < e.length; t++) e[t].style.transform = "", e[t].style.transition = "";
290
+ for (let t = 0; t < e.length; t++) e[t].style.transition = "none", e[t].style.transform = "";
264
291
  }
265
292
  }, [
266
293
  e.bodyRef,
267
294
  e.headerRef,
268
295
  e.placeholderRef
269
- ]), j = (e) => {
296
+ ]), F = (e) => {
270
297
  let t = e, n = !1;
271
298
  for (; t;) {
272
299
  if (t.dataset?.dragHandle === "true" && (n = !0), t.dataset?.contextid || t.dataset?.disabled === "true") return null;
@@ -277,46 +304,46 @@ var w = (e, t) => {
277
304
  t = t.parentNode;
278
305
  }
279
306
  return null;
280
- }, M = i((t, r, i) => {
281
- let a = j(t.target);
307
+ }, I = i((t, r, i) => {
308
+ let a = F(t.target);
282
309
  if (!a) return;
283
310
  let { element: o, foundHandle: s } = a;
284
311
  if (!s && o.querySelector("[data-drag-handle]")) return;
285
- let c = o.dataset.id, l = +o.dataset.index, u = o.dataset.type, b = t.type === "touchstart";
286
- h.current = u, _.current = l, v.current = null, b && o.dispatchEvent(new PointerEvent("pointerdown", {
312
+ let c = o.dataset.id, l = +o.dataset.index, u = o.dataset.type, d = t.type === "touchstart";
313
+ _.current = u ?? null, y.current = l, b.current = null, w.current = !1, d && o.dispatchEvent(new PointerEvent("pointerdown", {
287
314
  bubbles: !0,
288
315
  pointerType: "mouse"
289
316
  }));
290
- let C = u === "row" ? e.bodyRef?.current?.scrollLeft ?? 0 : 0, w = o.getBoundingClientRect();
291
- y.current = {
292
- width: w.width,
293
- height: w.height
317
+ let h = u === "row" ? e.bodyRef?.current?.scrollLeft ?? 0 : 0, C = o.getBoundingClientRect();
318
+ x.current = {
319
+ width: C.width,
320
+ height: C.height
294
321
  };
295
- let T = {
296
- x: r - w.left - C,
297
- y: i - w.top
322
+ let E = {
323
+ x: r - C.left - h,
324
+ y: i - C.top
298
325
  };
299
- g.current = T, x.current = {
326
+ v.current = E, S.current = {
300
327
  x: r,
301
328
  y: i
302
- }, f.current = {
329
+ }, p.current = {
303
330
  x: r,
304
331
  y: i
305
332
  };
306
333
  let D = {
307
- x: w.left + C,
308
- y: w.top
334
+ x: C.left + h,
335
+ y: C.top
309
336
  };
310
- p.current = u === "row" ? S() : E();
337
+ m.current = u === "row" ? T() : k();
311
338
  let O = e.bodyRef?.current;
312
339
  if (O) {
313
340
  let e = O.getBoundingClientRect();
314
- m.current = e, d(e);
341
+ g.current = e, f(e);
315
342
  }
316
- let k = e.tableRef?.current;
317
- k && (k.style.touchAction = "none");
318
- let A = e.cloneRef?.current;
319
- A && (A.style.transform = `translate(${D.x}px, ${D.y}px)`);
343
+ let A = e.tableRef?.current;
344
+ A && (A.style.touchAction = "none");
345
+ let j = e.cloneRef?.current;
346
+ j && (j.style.transform = `translate(${D.x}px, ${D.y}px)`);
320
347
  let M = e.tableRef?.current;
321
348
  M && n({
322
349
  type: "setTableDimensions",
@@ -328,17 +355,17 @@ var w = (e, t) => {
328
355
  type: "dragStart",
329
356
  value: {
330
357
  rect: {
331
- draggedItemHeight: w.height,
332
- draggedItemWidth: w.width
358
+ draggedItemHeight: C.height,
359
+ draggedItemWidth: C.width
333
360
  },
334
361
  dragged: {
335
- initial: T,
362
+ initial: E,
336
363
  translate: D,
337
- draggedID: c,
364
+ draggedID: c ?? null,
338
365
  isDragging: !0,
339
366
  sourceIndex: l
340
367
  },
341
- dragType: u
368
+ dragType: u ?? null
342
369
  }
343
370
  });
344
371
  let N = () => {
@@ -355,48 +382,65 @@ var w = (e, t) => {
355
382
  }, [
356
383
  n,
357
384
  e,
358
- S,
359
- E,
360
- f,
361
- d
362
- ]), N = i(() => {
363
- I(), setTimeout(() => {
364
- L.current = !1;
365
- }, 400);
366
- let t = v.current, r = _.current, i = h.current, a = e.bodyRef?.current, o = a?.scrollTop ?? 0, c = a?.scrollLeft ?? 0;
367
- p.current = null, m.current = null;
368
- let u = e.cloneRef?.current;
369
- u && (u.style.transform = "translate(0px, 0px)", u.scrollLeft = 0);
370
- let d = e.tableRef?.current;
371
- d && (d.style.touchAction = ""), A(), s && r !== null && t !== null && (i === "row" || i === "column") && s({
372
- sourceIndex: r,
373
- targetIndex: t,
374
- dragType: i
375
- }), n({
376
- type: "dragEnd",
377
- value: {
378
- targetIndex: t,
379
- sourceIndex: r
380
- }
381
- }), l(), a && (a.scrollTop = o, a.scrollLeft = c, requestAnimationFrame(() => {
382
- a.scrollTop = o, a.scrollLeft = c;
383
- })), h.current = null, _.current = null, v.current = null;
385
+ T,
386
+ k,
387
+ p,
388
+ f
389
+ ]), L = i((t, r, i, a, o) => {
390
+ let c = e.cloneRef?.current;
391
+ c && (c.style.visibility = "hidden");
392
+ let l = e.tableRef?.current;
393
+ l && (l.style.touchAction = ""), h(() => {
394
+ s && t !== null && r !== null && (i === "row" || i === "column") && s({
395
+ sourceIndex: t,
396
+ targetIndex: r,
397
+ dragType: i
398
+ }), n({
399
+ type: "dragEnd",
400
+ value: {
401
+ targetIndex: r,
402
+ sourceIndex: t
403
+ }
404
+ });
405
+ }), P();
406
+ let u = e.bodyRef?.current;
407
+ u && (u.scrollTop = a, u.scrollLeft = o, requestAnimationFrame(() => {
408
+ u.scrollTop = a, u.scrollLeft = o;
409
+ }));
384
410
  }, [
385
411
  n,
386
- l,
387
412
  e.bodyRef,
388
413
  e.cloneRef,
389
414
  e.tableRef,
390
- A,
415
+ P,
391
416
  s
392
- ]), P = u(() => {}), { touchStart: F, cancelLongPress: I, isTouchActiveRef: L } = C(e, M, N, (e, t) => P.current(e, t)), R = i((e) => {
393
- e.target !== e.currentTarget && (L.current || M(e, e.clientX, e.clientY));
394
- }, [M, L]), z = i((t, n) => {
395
- let i = g.current;
396
- x.current = {
417
+ ]), R = i(() => {
418
+ if (w.current) return;
419
+ w.current = !0, V(), setTimeout(() => {
420
+ H.current = !1;
421
+ }, 400);
422
+ let t = b.current, n = y.current, r = _.current, i = e.bodyRef?.current, a = i?.scrollTop ?? 0, o = i?.scrollLeft ?? 0;
423
+ m.current = null, g.current = null, u(), _.current = null, y.current = null, b.current = null;
424
+ let s = e.cloneRef?.current, c = e.placeholderRef?.current;
425
+ if (s && c && c.style.display !== "none") {
426
+ let e = parseFloat(c.style.left) || 0, i = parseFloat(c.style.top) || 0;
427
+ s.style.transition = `transform ${j}ms cubic-bezier(0.2, 0, 0, 1)`, s.style.transform = `translate(${e}px, ${i}px)`, setTimeout(() => L(n, t, r, a, o), j);
428
+ } else L(n, t, r, a, o);
429
+ }, [
430
+ u,
431
+ e.bodyRef,
432
+ e.placeholderRef,
433
+ e.cloneRef,
434
+ L
435
+ ]), z = d(() => {}), { touchStart: B, cancelLongPress: V, isTouchActiveRef: H } = E(e, I, R, (e, t) => z.current(e, t)), U = i((e) => {
436
+ e.target !== e.currentTarget && (H.current || I(e, e.clientX, e.clientY));
437
+ }, [I, H]), W = i((t, n) => {
438
+ if (w.current) return;
439
+ let i = v.current;
440
+ S.current = {
397
441
  x: t,
398
442
  y: n
399
- }, f.current = {
443
+ }, p.current = {
400
444
  x: t,
401
445
  y: n
402
446
  };
@@ -404,7 +448,7 @@ var w = (e, t) => {
404
448
  if (a) {
405
449
  a.style.transform = `translate(${t - i.x}px, ${n - i.y}px)`;
406
450
  let r = e.bodyRef?.current;
407
- if (r) if (h.current === "row") a.scrollLeft = r.scrollLeft;
451
+ if (r) if (_.current === "row") a.scrollLeft = r.scrollLeft;
408
452
  else {
409
453
  let e = a.querySelector(".clone-body");
410
454
  e && (e.scrollTop = r.scrollTop);
@@ -412,47 +456,56 @@ var w = (e, t) => {
412
456
  }
413
457
  let o = e.bodyRef?.current;
414
458
  if (!o) return;
415
- let s = m.current;
416
- s || (s = o.getBoundingClientRect(), m.current = s);
417
- let u = 0, d = h.current || r;
418
- d === "row" ? n < s.top + 30 ? (c(-5, o, "vertical"), p.current = null) : n > s.bottom - 30 ? (c(5, o, "vertical"), p.current = null) : l() : t < s.left + 30 ? (c(-5, o, "horizontal"), p.current = null) : t > s.right - 30 ? (c(5, o, "horizontal"), p.current = null) : l();
419
- let y;
420
- d === "row" ? (y = S(), p.current = y, y && y.length > 0 && (u = w(n - s.top + o.scrollTop, y))) : (y = E(), p.current = y, y && y.length > 0 && (u = T(t, y))), u !== v.current && (v.current = u, requestAnimationFrame(() => k(_.current, u, d)));
459
+ let s = g.current;
460
+ s || (s = o.getBoundingClientRect(), g.current = s);
461
+ let c = 0, d = _.current || r;
462
+ d === "row" ? n < s.top + 30 ? (l(-5, o, "vertical"), m.current = null) : n > s.bottom - 30 ? (l(5, o, "vertical"), m.current = null) : u() : t < s.left + 30 ? (l(-5, o, "horizontal"), m.current = null) : t > s.right - 30 ? (l(5, o, "horizontal"), m.current = null) : u();
463
+ let f;
464
+ d === "row" ? (f = T(), m.current = f, f && f.length > 0 && (c = D(n - s.top + o.scrollTop, f))) : (f = k(), m.current = f, f && f.length > 0 && (c = O(t, f))), c !== b.current && (b.current = c, requestAnimationFrame(() => N(y.current, c, d)));
421
465
  }, [
422
466
  r,
423
467
  e.bodyRef,
424
468
  e.cloneRef,
425
- S,
426
- E,
427
- c,
428
- l,
469
+ T,
429
470
  k,
430
- f
471
+ l,
472
+ u,
473
+ N,
474
+ p
431
475
  ]);
432
- P.current = z;
433
- let B = i(() => {
434
- I(), p.current = null, m.current = null;
476
+ z.current = W;
477
+ let G = i(() => {
478
+ V(), m.current = null, g.current = null;
435
479
  let t = e.cloneRef?.current;
436
- t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0);
480
+ t && (t.style.visibility = "hidden");
437
481
  let r = e.tableRef?.current;
438
- r && (r.style.touchAction = ""), A(), n({
482
+ r && (r.style.touchAction = ""), n({
439
483
  type: "dragEnd",
440
484
  value: {
441
485
  targetIndex: null,
442
486
  sourceIndex: null
443
487
  }
444
- }), l(), h.current = null, _.current = null, v.current = null;
488
+ }), u(), _.current = null, y.current = null, b.current = null;
445
489
  }, [
446
490
  n,
447
- l,
491
+ u,
448
492
  e.cloneRef,
449
493
  e.tableRef,
450
- A,
451
- I
452
- ]), V = i((e) => {
453
- e.key === "Escape" && B();
454
- }, [B]);
455
- return o(() => {
494
+ V
495
+ ]), K = i((e) => {
496
+ e.key === "Escape" && G();
497
+ }, [G]);
498
+ return c(() => {
499
+ if (!t.isDragging) {
500
+ P();
501
+ let t = e.cloneRef?.current;
502
+ t && (t.style.transition = "", t.style.transform = "translate(0px, 0px)", t.style.visibility = "", t.scrollLeft = 0);
503
+ }
504
+ }, [
505
+ t.isDragging,
506
+ P,
507
+ e.cloneRef
508
+ ]), o(() => {
456
509
  let t = e.bodyRef?.current;
457
510
  return t && (t.style.touchAction = "none"), () => {
458
511
  t && (t.style.touchAction = "");
@@ -460,23 +513,23 @@ var w = (e, t) => {
460
513
  }, [e.bodyRef]), o(() => {
461
514
  if (!t.isDragging) return;
462
515
  let e = (e) => {
463
- z(e.clientX, e.clientY);
516
+ W(e.clientX, e.clientY);
464
517
  }, n = () => {
465
- N();
518
+ R();
466
519
  };
467
- return window.addEventListener("pointermove", e), window.addEventListener("pointerup", n), window.addEventListener("pointercancel", n), window.addEventListener("keydown", V), () => {
468
- window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", n), window.removeEventListener("keydown", V);
520
+ return window.addEventListener("pointermove", e), window.addEventListener("pointerup", n), window.addEventListener("pointercancel", n), window.addEventListener("keydown", K), () => {
521
+ window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", n), window.removeEventListener("keydown", K);
469
522
  };
470
523
  }, [
471
524
  t.isDragging,
472
- z,
473
- N,
474
- V
525
+ W,
526
+ R,
527
+ K
475
528
  ]), {
476
- dragStart: R,
477
- touchStart: F
529
+ dragStart: U,
530
+ touchStart: B
478
531
  };
479
- }, k = {
532
+ }, N = {
480
533
  columnDragRange: {
481
534
  start: void 0,
482
535
  end: void 0
@@ -487,7 +540,7 @@ var w = (e, t) => {
487
540
  },
488
541
  defaultSizing: 50
489
542
  };
490
- function A(e, t) {
543
+ function P(e, t) {
491
544
  switch (t.type) {
492
545
  case "setClone": return {
493
546
  ...e,
@@ -504,47 +557,15 @@ function A(e, t) {
504
557
  ...e,
505
558
  dragType: t.value
506
559
  };
507
- case "setRect": return {
508
- ...e,
509
- rect: t.value
510
- };
511
560
  case "setTableDimensions": return {
512
561
  ...e,
513
562
  tableDimensions: t.value
514
563
  };
515
- case "setTableRef": return {
516
- ...e,
517
- refs: {
518
- ...e.refs,
519
- tableRef: t.value
520
- }
521
- };
522
- case "setBodyRef": return {
564
+ case "setRef": return {
523
565
  ...e,
524
566
  refs: {
525
567
  ...e.refs,
526
- bodyRef: t.value
527
- }
528
- };
529
- case "setHeaderRef": return {
530
- ...e,
531
- refs: {
532
- ...e.refs,
533
- headerRef: t.value
534
- }
535
- };
536
- case "setCloneRef": return {
537
- ...e,
538
- refs: {
539
- ...e.refs,
540
- cloneRef: t.value
541
- }
542
- };
543
- case "setPlaceholderRef": return {
544
- ...e,
545
- refs: {
546
- ...e.refs,
547
- placeholderRef: t.value
568
+ [t.refName]: t.value
548
569
  }
549
570
  };
550
571
  case "setBodyScrollBarWidth": return {
@@ -561,7 +582,10 @@ function A(e, t) {
561
582
  };
562
583
  case "setOptions": return {
563
584
  ...e,
564
- options: t.value ?? k
585
+ options: {
586
+ ...e.options,
587
+ ...t.value
588
+ }
565
589
  };
566
590
  case "dragStart": return {
567
591
  ...e,
@@ -595,10 +619,10 @@ function A(e, t) {
595
619
  draggedItemHeight: 0
596
620
  }
597
621
  };
598
- default: throw Error(`Unhandled action type: ${t.type}`);
622
+ default: throw Error("Unhandled action");
599
623
  }
600
624
  }
601
- var j = {
625
+ var F = {
602
626
  clone: null,
603
627
  dragged: {
604
628
  initial: {
@@ -624,65 +648,68 @@ var j = {
624
648
  width: 0
625
649
  },
626
650
  refs: {
627
- tableRef: null,
628
- bodyRef: null,
629
- headerRef: null,
630
- cloneRef: null,
631
- placeholderRef: null
651
+ tableRef: { current: null },
652
+ bodyRef: { current: null },
653
+ headerRef: { current: null },
654
+ cloneRef: { current: null },
655
+ placeholderRef: { current: null }
632
656
  },
633
657
  bodyScrollBarWidth: 0,
634
- options: k,
658
+ options: N,
635
659
  widths: [],
636
660
  columnIds: []
637
- }, M = {
661
+ }, I = {
638
662
  position: "relative",
639
663
  display: "flex",
640
664
  flexFlow: "column"
641
- }, N = {
665
+ }, L = {
642
666
  position: "fixed",
643
667
  pointerEvents: "none",
644
668
  zIndex: 3,
645
669
  top: 0,
646
670
  left: 0,
647
671
  display: "none"
648
- }, P = n(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: a }, d) => {
649
- let m = u(null), h = u(null), v = u(null);
650
- s(d, () => m.current, []);
651
- let [y, b] = l(A, j), x = c(() => ({
652
- state: y,
653
- dispatch: b
654
- }), [y]);
672
+ }, R = n(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: a }, c) => {
673
+ let f = d(null), p = d(null), m = d(null);
674
+ s(c, () => f.current, []);
675
+ let [h, v] = u(P, F), x = l(() => ({
676
+ state: h,
677
+ dispatch: v
678
+ }), [h]);
655
679
  o(() => {
656
- b({
657
- type: "setTableRef",
680
+ v({
681
+ type: "setRef",
682
+ refName: "tableRef",
683
+ value: f
684
+ }), v({
685
+ type: "setRef",
686
+ refName: "cloneRef",
687
+ value: p
688
+ }), v({
689
+ type: "setRef",
690
+ refName: "placeholderRef",
658
691
  value: m
659
- }), b({
660
- type: "setCloneRef",
661
- value: h
662
- }), b({
663
- type: "setPlaceholderRef",
664
- value: v
665
692
  });
666
- }, [m]), o(() => {
693
+ }, [f]), o(() => {
667
694
  let e = () => {
668
- m.current && b({
695
+ f.current && v({
669
696
  type: "setTableDimensions",
670
697
  value: {
671
- height: m.current.offsetHeight,
672
- width: m.current.offsetWidth
698
+ height: f.current.offsetHeight,
699
+ width: f.current.offsetWidth
673
700
  }
674
701
  });
675
702
  };
676
703
  return e(), window.addEventListener("resize", e), () => {
677
704
  window.removeEventListener("resize", e);
678
705
  };
679
- }, [m]), o(() => {
680
- b({
706
+ }, [f]), o(() => {
707
+ r && v({
681
708
  type: "setOptions",
682
709
  value: r
683
710
  });
684
711
  }, [r]);
685
- let { dragStart: S, touchStart: C } = O(y.refs, y.dragged, b, y.dragType, y.options, i), w = c(() => ({
712
+ let { dragStart: S, touchStart: C } = M(h.refs, h.dragged, v, h.dragType, h.options, i), w = l(() => ({
686
713
  position: "fixed",
687
714
  zIndex: "5",
688
715
  pointerEvents: "none",
@@ -690,50 +717,53 @@ var j = {
690
717
  left: 0,
691
718
  display: "flex",
692
719
  flexDirection: "column",
693
- height: y.dragType === "row" ? y.rect.draggedItemHeight : `${y.tableDimensions.height}px`,
694
- width: y.dragType === "column" ? `${y.rect.draggedItemWidth}px` : `${y.tableDimensions.width}px`,
720
+ height: h.dragType === "row" ? h.rect.draggedItemHeight : `${h.tableDimensions.height}px`,
721
+ width: h.dragType === "column" ? `${h.rect.draggedItemWidth}px` : `${h.tableDimensions.width}px`,
695
722
  overflow: "hidden",
696
- boxShadow: y.dragged.isDragging ? "0 0 10px 0 rgba(0, 0, 0, 0.1)" : "none"
723
+ boxShadow: h.dragged.isDragging ? "0 0 10px 0 rgba(0, 0, 0, 0.1)" : "none"
697
724
  }), [
698
- y.dragType,
699
- y.dragged.isDragging,
700
- y.rect.draggedItemHeight,
701
- y.rect.draggedItemWidth,
702
- y.tableDimensions.height,
703
- y.tableDimensions.width
725
+ h.dragType,
726
+ h.dragged.isDragging,
727
+ h.rect.draggedItemHeight,
728
+ h.rect.draggedItemWidth,
729
+ h.tableDimensions.height,
730
+ h.tableDimensions.width
704
731
  ]);
705
- return /* @__PURE__ */ f(_.Provider, {
732
+ return /* @__PURE__ */ g(b.Provider, {
706
733
  value: x,
707
- children: /* @__PURE__ */ p(g, {
708
- className: y.dragged.isDragging ? "is-dragging" : "",
734
+ children: /* @__PURE__ */ _(y, {
735
+ className: h.dragged.isDragging ? "is-dragging" : "",
709
736
  children: [
710
- /* @__PURE__ */ f("div", {
737
+ /* @__PURE__ */ g("div", {
711
738
  id: "portalroot",
712
739
  style: {
713
740
  ...w,
714
- visibility: y.dragged.isDragging ? "visible" : "hidden"
741
+ visibility: h.dragged.isDragging ? "visible" : "hidden"
715
742
  },
716
- ref: h,
717
- children: /* @__PURE__ */ f("div", {
743
+ ref: p,
744
+ children: /* @__PURE__ */ g("div", {
718
745
  style: {
719
746
  flexShrink: 0,
720
747
  order: -1
721
748
  },
722
- children: y.clone
749
+ children: h.clone
723
750
  })
724
751
  }),
725
- a && /* @__PURE__ */ f("div", {
726
- ref: v,
727
- style: N,
728
- children: a()
752
+ /* @__PURE__ */ g("div", {
753
+ ref: m,
754
+ style: L,
755
+ children: a ? a() : /* @__PURE__ */ g("div", { style: {
756
+ width: "100%",
757
+ height: "100%"
758
+ } })
729
759
  }),
730
- /* @__PURE__ */ f("div", {
760
+ /* @__PURE__ */ g("div", {
731
761
  "data-contextid": "context",
732
- ref: m,
762
+ ref: f,
733
763
  onMouseDown: S,
734
764
  onTouchStart: C,
735
765
  style: {
736
- ...M,
766
+ ...I,
737
767
  ...n
738
768
  },
739
769
  className: `table ${t ?? ""}`,
@@ -743,129 +773,142 @@ var j = {
743
773
  })
744
774
  });
745
775
  });
746
- P.displayName = "TableProvider";
776
+ R.displayName = "TableProvider";
747
777
  //#endregion
748
778
  //#region src/Components/TableHeader.tsx
749
- var F = n(({ children: e, style: t, className: n }, r) => {
750
- let i = u(null), a = r || i, { state: s, dispatch: l } = v();
779
+ var z = n(({ children: e, style: t, className: n }, r) => {
780
+ let a = d(null), s = r || a, { state: u, dispatch: f } = x(), p = i((e) => "current" in e ? e.current : null, []);
751
781
  o(() => {
752
- l({
753
- type: "setHeaderRef",
782
+ a.current && f({
783
+ type: "setRef",
784
+ refName: "headerRef",
754
785
  value: a
755
786
  });
756
- }, [l, a]);
757
- let { HeaderScrollHandle: d } = b(s.refs), p = {
787
+ }, [f]);
788
+ let { HeaderScrollHandle: m } = C(u.refs), h = {
758
789
  display: "flex",
759
790
  flex: "1 0 auto"
760
- }, m = c(() => ({
791
+ }, _ = l(() => ({
761
792
  overflow: "hidden",
762
793
  display: "flex",
763
- paddingRight: `${s.bodyScrollBarWidth}px`,
764
- userSelect: s.dragged.isDragging ? "none" : "auto",
794
+ paddingRight: `${u.bodyScrollBarWidth}px`,
795
+ userSelect: u.dragged.isDragging ? "none" : "auto",
765
796
  ...t
766
797
  }), [
767
- s.bodyScrollBarWidth,
768
- s.dragged.isDragging,
798
+ u.bodyScrollBarWidth,
799
+ u.dragged.isDragging,
769
800
  t
770
801
  ]);
771
- return o(() => {
772
- a.current && l({
802
+ return c(() => {
803
+ let e = p(s);
804
+ e && f({
773
805
  type: "setWidths",
774
- value: Array.from(a.current.querySelectorAll(".th")).map((e) => {
806
+ value: Array.from(e.querySelectorAll(".th")).map((e) => {
775
807
  let t = e.getAttribute("data-width");
776
- return t ? parseInt(t, 10) : null;
808
+ return t ? parseInt(t, 10) : 0;
777
809
  })
778
810
  });
779
811
  }, [
780
812
  e,
781
- l,
782
- a
783
- ]), o(() => {
784
- a.current && l({
813
+ f,
814
+ p,
815
+ s
816
+ ]), c(() => {
817
+ let e = p(s);
818
+ e && f({
785
819
  type: "setColumnIds",
786
- value: Array.from(a.current.querySelectorAll(".draggable")).map((e) => e.getAttribute("data-id"))
820
+ value: Array.from(e.querySelectorAll(".draggable")).map((e) => e.getAttribute("data-id") || "")
787
821
  });
788
822
  }, [
789
823
  e,
790
- l,
791
- a
792
- ]), /* @__PURE__ */ f("div", {
824
+ f,
825
+ p,
826
+ s
827
+ ]), /* @__PURE__ */ g("div", {
793
828
  className: `header ${n ?? ""}`,
794
- children: /* @__PURE__ */ f("div", {
829
+ children: /* @__PURE__ */ g("div", {
795
830
  className: "thead",
796
- style: m,
831
+ style: _,
797
832
  "data-droppableid": "header",
798
- onScroll: d,
799
- ref: a,
800
- children: /* @__PURE__ */ f("div", {
801
- style: p,
833
+ onScroll: m,
834
+ ref: s,
835
+ children: /* @__PURE__ */ g("div", {
836
+ style: h,
802
837
  className: "tr",
803
838
  children: e
804
839
  })
805
840
  })
806
841
  });
807
842
  });
808
- F.displayName = "TableHeader";
843
+ z.displayName = "TableHeader";
809
844
  //#endregion
810
845
  //#region src/Components/Draggable.tsx
811
- var I = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
812
- let { state: s, dispatch: l } = v(), d = c(() => String(n) === String(s.dragged.draggedID) && s.dragged.isDragging, [
846
+ var B = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
847
+ let { state: s, dispatch: c } = x(), u = l(() => String(n) === String(s.dragged.draggedID) && s.dragged.isDragging, [
813
848
  n,
814
849
  s.dragged.draggedID,
815
850
  s.dragged.isDragging
816
- ]), p = c(() => i === "row" ? E(r, s.options.rowDragRange.start, s.options.rowDragRange.end) : E(r, s.options.columnDragRange.start, s.options.columnDragRange.end), [
851
+ ]), f = l(() => i === "row" ? k(r, s.options.rowDragRange.start, s.options.rowDragRange.end) : k(r, s.options.columnDragRange.start, s.options.columnDragRange.end), [
817
852
  r,
818
853
  s.options.columnDragRange.end,
819
854
  s.options.columnDragRange.start,
820
855
  s.options.rowDragRange.end,
821
856
  s.options.rowDragRange.start,
822
857
  i
823
- ]), m = u(null), h = u(!1);
858
+ ]), p = d(null), m = d(!1);
824
859
  o(() => {
825
- m.current && (h.current = !!m.current.querySelector("[data-drag-handle]"));
826
- });
827
- let g = c(() => ({
828
- cursor: d ? "-webkit-grabbing" : p || h.current ? "auto" : "-webkit-grab",
829
- zIndex: d ? 2 : 1,
830
- opacity: d ? 0 : 1,
831
- pointerEvents: d ? "none" : "auto",
860
+ m.current = !!p.current?.querySelector("[data-drag-handle]");
861
+ }, [t]);
862
+ let h = l(() => ({
863
+ cursor: u ? "-webkit-grabbing" : f ? "auto" : "-webkit-grab",
864
+ zIndex: u ? 2 : 1,
865
+ opacity: u ? 0 : 1,
866
+ pointerEvents: u ? "none" : "auto",
832
867
  display: "flex"
833
- }), [p, d]), _ = (n) => {
834
- n.pointerType !== "touch" && (p || requestAnimationFrame(() => {
835
- l({
868
+ }), [f, u]);
869
+ o(() => {
870
+ p.current && p.current.querySelector("[data-drag-handle]") && (p.current.style.cursor = "auto");
871
+ }, [
872
+ t,
873
+ f,
874
+ u
875
+ ]);
876
+ let _ = (n) => {
877
+ n.pointerType !== "touch" && (f || m.current && !n.target.closest("[data-drag-handle]") || requestAnimationFrame(() => {
878
+ c({
836
879
  type: "setClone",
837
880
  value: e.cloneElement(t)
838
881
  });
839
882
  }));
840
883
  };
841
- return /* @__PURE__ */ f("div", {
884
+ return /* @__PURE__ */ g("div", {
842
885
  className: "draggable",
843
886
  "data-id": n,
844
887
  "data-index": r,
845
888
  "data-type": i,
846
889
  onPointerDown: _,
847
- "data-disabled": p ? "true" : "false",
890
+ "data-disabled": f ? "true" : "false",
848
891
  style: a,
849
- children: /* @__PURE__ */ f("div", {
850
- ref: m,
851
- style: g,
892
+ children: /* @__PURE__ */ g("div", {
893
+ ref: p,
894
+ style: h,
852
895
  children: t
853
896
  })
854
897
  });
855
898
  });
856
- I.displayName = "Draggable";
899
+ B.displayName = "Draggable";
857
900
  //#endregion
858
901
  //#region src/Components/ColumnCell.tsx
859
- var L = r(({ children: e, width: t, style: n, className: r, ...i }) => {
860
- let { state: a } = v(), o = c(() => t ?? a.options.defaultSizing, [t, a.options.defaultSizing]), s = c(() => ({
902
+ var V = r(({ children: e, width: t, style: n, className: r, ...i }) => {
903
+ let { state: a } = x(), o = l(() => t ?? a.options.defaultSizing, [t, a.options.defaultSizing]), s = l(() => ({
861
904
  width: `${o}px`,
862
905
  flex: `${o} 0 auto`
863
906
  }), [o]);
864
- return /* @__PURE__ */ f(I, {
907
+ return /* @__PURE__ */ g(B, {
865
908
  ...i,
866
909
  styles: s,
867
910
  type: "column",
868
- children: /* @__PURE__ */ f("div", {
911
+ children: /* @__PURE__ */ g("div", {
869
912
  className: `th ${r ?? ""}`,
870
913
  "data-width": t,
871
914
  style: {
@@ -876,14 +919,18 @@ var L = r(({ children: e, width: t, style: n, className: r, ...i }) => {
876
919
  })
877
920
  });
878
921
  });
879
- L.displayName = "ColumnCell";
922
+ V.displayName = "ColumnCell";
880
923
  //#endregion
881
924
  //#region src/Components/TableBody.tsx
882
- var R = n(({ children: t, style: n, className: r }, i) => {
883
- let a = u(null);
884
- s(i, () => a.current, []);
885
- let { state: l, dispatch: d } = v(), h = c(() => {
886
- if (l.dragged.sourceIndex === null) return null;
925
+ var H = {
926
+ display: "flex",
927
+ overflow: "hidden",
928
+ flex: 1
929
+ }, U = n(({ children: t, style: n, className: r }, i) => {
930
+ let [a, u] = f(0), p = d(null);
931
+ s(i, () => p.current, []);
932
+ let { state: h, dispatch: v } = x(), y = l(() => {
933
+ if (h.dragged.sourceIndex === null) return null;
887
934
  let n = (t) => {
888
935
  let r = [];
889
936
  return e.Children.forEach(t, (t) => {
@@ -891,124 +938,121 @@ var R = n(({ children: t, style: n, className: r }, i) => {
891
938
  }), r;
892
939
  };
893
940
  return n(t).map((t) => {
894
- let n = e.Children.toArray(t.props.children).filter((t) => e.isValidElement(t) && String(t.props.index) === String(l.dragged.sourceIndex)).map((t) => e.cloneElement(t, { isClone: !0 }));
941
+ let n = e.Children.toArray(t.props.children).filter((t) => e.isValidElement(t) && String(t.props.index) === String(h.dragged.sourceIndex)).map((t) => e.cloneElement(t, {
942
+ key: t.props.index,
943
+ isClone: !0
944
+ }));
895
945
  return e.cloneElement(t, {
946
+ key: t.props.id,
896
947
  ...t.props,
897
948
  children: n
898
949
  });
899
950
  });
900
- }, [t, l.dragged.sourceIndex]);
951
+ }, [t, h.dragged.sourceIndex]);
901
952
  o(() => {
902
- d({
903
- type: "setBodyRef",
904
- value: a
953
+ v({
954
+ type: "setRef",
955
+ refName: "bodyRef",
956
+ value: p
905
957
  });
906
- }, [d, a]);
907
- let { BodyScrollHandle: g } = b(l.refs), _ = c(() => ({
958
+ }, [v, p]);
959
+ let { BodyScrollHandle: b } = C(h.refs), S = l(() => ({
908
960
  overflowX: "auto",
909
961
  overflowY: "auto",
910
962
  flex: 1,
911
- userSelect: l.dragged.isDragging ? "none" : "auto",
963
+ userSelect: h.dragged.isDragging ? "none" : "auto",
912
964
  ...n
913
- }), [l.dragged.isDragging, n]);
914
- o(() => {
915
- if (a.current) {
916
- let e = a.current.clientWidth;
917
- d({
965
+ }), [h.dragged.isDragging, n]);
966
+ return o(() => {
967
+ if (p.current) {
968
+ let e = p.current.clientWidth;
969
+ v({
918
970
  type: "setBodyScrollBarWidth",
919
- value: a.current.offsetWidth - e
971
+ value: p.current.offsetWidth - e
920
972
  });
921
973
  }
922
- }, [d, a]);
923
- let y = a.current?.scrollHeight ?? 0;
924
- return /* @__PURE__ */ p(e.Fragment, { children: [l.dragType === "column" && l.refs.cloneRef?.current && m(/* @__PURE__ */ f("div", {
974
+ }, [v, p]), c(() => {
975
+ p.current && u(p.current.scrollHeight);
976
+ }, [p, t]), /* @__PURE__ */ _(e.Fragment, { children: [h.dragType === "column" && h.refs.cloneRef?.current && m(/* @__PURE__ */ g("div", {
925
977
  className: "body clone-body",
926
978
  "data-droppableid": "body",
927
979
  style: {
928
980
  overflow: "hidden",
929
981
  flex: 1
930
982
  },
931
- children: /* @__PURE__ */ f("div", {
983
+ children: /* @__PURE__ */ g("div", {
932
984
  className: "rbody",
933
985
  style: {
934
- height: y,
986
+ height: a,
935
987
  position: "relative"
936
988
  },
937
- children: h
989
+ children: y && e.Children.toArray(y)
938
990
  })
939
- }), l.refs.cloneRef.current), /* @__PURE__ */ f("div", {
991
+ }), h.refs.cloneRef.current), /* @__PURE__ */ g("div", {
940
992
  className: `body ${r ?? ""}`,
941
- style: z,
942
- children: /* @__PURE__ */ f("div", {
993
+ style: H,
994
+ children: /* @__PURE__ */ g("div", {
943
995
  className: "ibody",
944
- style: _,
996
+ style: S,
945
997
  "data-droppableid": "body",
946
- onScroll: g,
947
- ref: a,
998
+ onScroll: b,
999
+ ref: p,
948
1000
  children: t
949
1001
  })
950
1002
  })] });
951
- }), z = {
952
- display: "flex",
953
- overflow: "hidden",
954
- flex: 1
955
- };
956
- R.displayName = "TableBody";
957
- //#endregion
958
- //#region src/Components/BodyRow.tsx
959
- var B = {
1003
+ }), W = {
960
1004
  display: "flex",
961
1005
  flex: "1 0 auto",
962
1006
  minHeight: "24px"
963
- }, V = r(({ children: e, style: t, className: n, ...r }) => {
964
- let i = c(() => t ? {
965
- ...B,
1007
+ }, G = r(({ children: e, style: t, className: n, ...r }) => {
1008
+ let i = l(() => t ? {
1009
+ ...W,
966
1010
  ...t
967
- } : B, [t]), a = h("tr", n);
968
- return /* @__PURE__ */ f(I, {
1011
+ } : W, [t]), a = v("tr", n);
1012
+ return /* @__PURE__ */ g(B, {
969
1013
  ...r,
970
1014
  type: "row",
971
- children: /* @__PURE__ */ f("div", {
1015
+ children: /* @__PURE__ */ g("div", {
972
1016
  className: a,
973
1017
  style: i,
974
1018
  children: e
975
1019
  })
976
1020
  });
977
1021
  });
978
- V.displayName = "BodyRow";
1022
+ G.displayName = "BodyRow";
979
1023
  //#endregion
980
1024
  //#region src/Components/RowCell.tsx
981
- var H = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
982
- let { index: a } = i, { state: o } = v(), s = c(() => o.columnIds[a] ?? "", [o.columnIds, a]), l = c(() => o.widths[a] ?? o.options.defaultSizing, [
1025
+ var K = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
1026
+ let { index: a } = i, { state: o } = x(), s = l(() => o.columnIds[a] ?? "", [o.columnIds, a]), c = l(() => o.widths[a] ?? o.options.defaultSizing, [
983
1027
  o.widths,
984
1028
  a,
985
1029
  o.options.defaultSizing
986
- ]), u = c(() => r ? !1 : s === o.dragged.draggedID, [
1030
+ ]), u = l(() => r ? !1 : s === o.dragged.draggedID, [
987
1031
  r,
988
1032
  s,
989
1033
  o.dragged.draggedID
990
- ]), d = c(() => ({
1034
+ ]), d = l(() => ({
991
1035
  display: "inline-flex",
992
1036
  opacity: u ? 0 : 1,
993
- width: `${l}px`,
994
- flex: `${l} 0 auto`,
1037
+ width: `${c}px`,
1038
+ flex: `${c} 0 auto`,
995
1039
  ...t
996
1040
  }), [
997
1041
  u,
998
- l,
1042
+ c,
999
1043
  t
1000
1044
  ]);
1001
- return /* @__PURE__ */ f("div", {
1045
+ return /* @__PURE__ */ g("div", {
1002
1046
  className: `td ${n ?? ""}`,
1003
1047
  style: d,
1004
1048
  "data-col-index": a,
1005
1049
  children: e
1006
1050
  });
1007
1051
  });
1008
- H.displayName = "RowCell";
1052
+ K.displayName = "RowCell";
1009
1053
  //#endregion
1010
1054
  //#region src/Components/DragHandle.tsx
1011
- var U = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div", {
1055
+ var q = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ g("div", {
1012
1056
  "data-drag-handle": "true",
1013
1057
  className: t,
1014
1058
  style: {
@@ -1019,6 +1063,6 @@ var U = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div",
1019
1063
  },
1020
1064
  children: e
1021
1065
  }));
1022
- U.displayName = "DragHandle";
1066
+ q.displayName = "DragHandle";
1023
1067
  //#endregion
1024
- export { V as BodyRow, L as ColumnCell, U as DragHandle, H as RowCell, R as TableBody, P as TableContainer, F as TableHeader, v as useTable };
1068
+ export { G as BodyRow, V as ColumnCell, q as DragHandle, K as RowCell, U as TableBody, R as TableContainer, z as TableHeader, x as useTable };