flexitablesort 1.1.9 → 1.1.12

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