flexitablesort 1.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.
@@ -0,0 +1,885 @@
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";
6
+ //#region src/Components/TableContainer/styles.tsx
7
+ var g = d.div`
8
+ height: 100%;
9
+
10
+ &, & .table, & .header, & .thead, & .body, & .ibody,
11
+ & .draggable, & .tr, & .th, & .td {
12
+ box-sizing: border-box;
13
+ margin: 0;
14
+ padding: 0;
15
+ }
16
+
17
+ &.is-dragging, &.is-dragging * {
18
+ user-select: none !important;
19
+ -webkit-user-select: none !important;
20
+ }
21
+ `, _ = t(void 0), v = () => {
22
+ let e = a(_);
23
+ if (e === void 0) throw Error("useTable must be used within a TableProvider");
24
+ return e;
25
+ }, y = (e) => {
26
+ let t = u(!1), n = u(!1), r = u(0), a = u(null), o = i((e, i, s) => {
27
+ let c = s === "vertical", l = c ? i.scrollHeight - i.clientHeight : i.scrollWidth - i.clientWidth;
28
+ c ? i.scrollTop += e : i.scrollLeft += e, c && (i.scrollTop >= l || i.scrollTop <= 0) || !c && (i.scrollLeft >= l || i.scrollLeft <= 0) ? a.current !== null && cancelAnimationFrame(a.current) : n.current || t.current ? (a.current = requestAnimationFrame(() => o(e + r.current, i, s)), r.current += e / 1e3) : a.current !== null && cancelAnimationFrame(a.current);
29
+ }, []);
30
+ return {
31
+ startAutoScroll: i((e, i, a) => {
32
+ let s = a === "vertical";
33
+ !n.current && !t.current && (s ? n.current = !0 : t.current = !0, r.current = 0, o(e, i, a));
34
+ }, [o]),
35
+ stopAutoScroll: i(() => {
36
+ n.current = !1, t.current = !1, a.current !== null && cancelAnimationFrame(a.current);
37
+ }, []),
38
+ isAutoScrollingHorizontal: t,
39
+ isAutoScrollingVertical: n,
40
+ BodyScrollHandle: i((t) => {
41
+ e.headerRef?.current && t.currentTarget && (e.headerRef.current.scrollLeft = t.currentTarget.scrollLeft);
42
+ }, [e]),
43
+ HeaderScrollHandle: i((t) => {
44
+ e.bodyRef?.current && t.currentTarget && (e.bodyRef.current.scrollLeft = t.currentTarget.scrollLeft);
45
+ }, [e])
46
+ };
47
+ }, b = (e, t) => {
48
+ let n = e, r = 0, i = t.length - 1;
49
+ for (; r < i;) {
50
+ let e = Math.floor((r + i) / 2), a = t[e];
51
+ if (a.itemTop <= n && n <= a.itemBottom) return n < a.itemTop + a.height / 2 ? +a.index : +a.index + 1;
52
+ n < a.itemTop ? i = e - 1 : r = e + 1;
53
+ }
54
+ return +t[r].index;
55
+ }, x = (e, t) => {
56
+ let n = e, r = 0, i = t.length - 1;
57
+ for (; r < i;) {
58
+ let e = Math.floor((r + i) / 2), a = t[e];
59
+ if (a.itemLeft <= n && n <= a.itemRight) return n < a.itemLeft + a.width / 2 ? +a.index : +a.index + 1;
60
+ n < a.itemLeft ? i = e - 1 : r = e + 1;
61
+ }
62
+ return +t[r].index;
63
+ }, S = (e, t, n) => t !== void 0 && e < t || n !== void 0 && e > n, C = "all 450ms cubic-bezier(0.2, 0, 0, 1)", w = (e, t, n, r, a, s) => {
64
+ let { startAutoScroll: c, stopAutoScroll: l, isAutoScrollingHorizontal: d, isAutoScrollingVertical: f } = y(e), p = u(null), m = u(null), h = u(null), g = u({
65
+ x: 0,
66
+ y: 0
67
+ }), _ = u(null), v = u(null), S = u({
68
+ width: 0,
69
+ height: 0
70
+ }), w = i(() => {
71
+ let t = e.bodyRef.current;
72
+ if (!t) return null;
73
+ let n = t.scrollTop, r = t.getBoundingClientRect().top, i = t.querySelectorAll(".draggable[data-type=\"row\"]"), o = [];
74
+ for (let e = 0; e < i.length; e++) {
75
+ let t = i[e];
76
+ if (t.dataset.index === void 0) continue;
77
+ let a = t.getBoundingClientRect(), s = a.top - r + n;
78
+ o.push({
79
+ height: a.height,
80
+ itemTop: s,
81
+ itemBottom: s + a.height,
82
+ index: t.dataset.index
83
+ });
84
+ }
85
+ let s = a.rowDragRange.start, c = a.rowDragRange.end;
86
+ return (s || c) && (o = o.filter((e) => (!s || e.index >= s) && (!c || e.index < c))), o;
87
+ }, [e.bodyRef, a.rowDragRange]), T = i(() => {
88
+ let t = e.headerRef.current;
89
+ if (!t || !t.children[0]) return null;
90
+ let n = Array.from(t.children[0].children).map((e) => {
91
+ let t = e.getBoundingClientRect();
92
+ return {
93
+ left: t.left,
94
+ width: t.width,
95
+ itemLeft: t.left,
96
+ itemRight: t.left + t.width,
97
+ index: e.dataset.index
98
+ };
99
+ }).filter((e) => e.index !== void 0), r = a.columnDragRange?.start, i = a.columnDragRange?.end;
100
+ return (r !== void 0 || i !== void 0) && (n = n.filter((e) => {
101
+ let t = +e.index;
102
+ return (r === void 0 || t >= r) && (i === void 0 || t < i);
103
+ })), n;
104
+ }, [e.headerRef, a.columnDragRange]), E = i((t, n, r, i) => {
105
+ let a = e.placeholderRef?.current;
106
+ if (!a || !t) {
107
+ a && (a.style.display = "none");
108
+ return;
109
+ }
110
+ let o = S.current, s = t.getBoundingClientRect();
111
+ a.style.display = "block";
112
+ let c = n < r;
113
+ if (i === "row") {
114
+ let e = c ? s.top + s.height - o.height : s.top;
115
+ a.style.top = `${e}px`, a.style.left = `${s.left}px`, a.style.width = `${s.width}px`, a.style.height = `${o.height}px`;
116
+ } else {
117
+ let t = (e.tableRef?.current)?.getBoundingClientRect(), n = c ? s.left + s.width - o.width : s.left;
118
+ a.style.top = `${t?.top ?? s.top}px`, a.style.left = `${n}px`, a.style.width = `${o.width}px`, a.style.height = `${t?.height ?? s.height}px`;
119
+ }
120
+ }, [e.placeholderRef, e.tableRef]), D = i((t, n, r) => {
121
+ if (t === null || n === null) return;
122
+ let i = S.current, a = null;
123
+ if (r === "row") {
124
+ let r = e.bodyRef.current;
125
+ if (!r) return;
126
+ let o = r.querySelectorAll(".draggable[data-type=\"row\"]");
127
+ for (let e = 0; e < o.length; e++) {
128
+ let r = o[e], s = +r.dataset.index, c = r.firstElementChild;
129
+ if (!c) continue;
130
+ let l = "";
131
+ s > t && s <= n ? l = `translateY(-${i.height}px)` : s < t && s >= n && (l = `translateY(${i.height}px)`), c.style.transform = l, c.style.transition = s === t ? "none" : C, s === n ? (r.setAttribute("data-drop-target", "true"), a = r) : r.removeAttribute("data-drop-target");
132
+ }
133
+ } else if (r === "column") {
134
+ let r = e.headerRef.current;
135
+ if (r) {
136
+ let e = r.querySelectorAll(".draggable[data-type=\"column\"]");
137
+ for (let r = 0; r < e.length; r++) {
138
+ let o = e[r], s = +o.dataset.index, c = o.firstElementChild;
139
+ if (!c) continue;
140
+ let l = "";
141
+ s > t && s <= n ? l = `translateX(-${i.width}px)` : s < t && s >= n && (l = `translateX(${i.width}px)`), c.style.transform = l, c.style.transition = s === t ? "none" : C, s === n ? (o.setAttribute("data-drop-target", "true"), a = o) : o.removeAttribute("data-drop-target");
142
+ }
143
+ }
144
+ let o = e.bodyRef.current;
145
+ if (o) {
146
+ let e = o.querySelectorAll(".td[data-col-index]");
147
+ for (let r = 0; r < e.length; r++) {
148
+ let a = e[r], o = +a.dataset.colIndex, s = "";
149
+ 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 = C;
150
+ }
151
+ }
152
+ }
153
+ E(a, t, n, r);
154
+ }, [
155
+ e.bodyRef,
156
+ e.headerRef,
157
+ e.placeholderRef,
158
+ E
159
+ ]), O = i(() => {
160
+ let t = e.placeholderRef?.current;
161
+ t && (t.style.display = "none");
162
+ let n = e.bodyRef.current;
163
+ if (n) {
164
+ let e = n.querySelectorAll(".draggable");
165
+ for (let t = 0; t < e.length; t++) {
166
+ e[t].removeAttribute("data-drop-target");
167
+ let n = e[t].firstElementChild;
168
+ n && (n.style.transform = "", n.style.transition = "");
169
+ }
170
+ let t = n.querySelectorAll(".td[data-col-index]");
171
+ for (let e = 0; e < t.length; e++) t[e].style.transform = "", t[e].style.transition = "";
172
+ }
173
+ let r = e.headerRef.current;
174
+ if (r) {
175
+ let e = r.querySelectorAll(".draggable");
176
+ for (let t = 0; t < e.length; t++) {
177
+ e[t].removeAttribute("data-drop-target");
178
+ let n = e[t].firstElementChild;
179
+ n && (n.style.transform = "", n.style.transition = "");
180
+ }
181
+ }
182
+ }, [e.bodyRef, e.headerRef]), k = i((t) => {
183
+ if (t.target !== t.currentTarget) {
184
+ let r = !1, i = ((e) => {
185
+ for (; e;) {
186
+ if (e.dataset?.dragHandle === "true" && (r = !0), e.dataset?.contextid || e.dataset?.disabled === "true") return null;
187
+ if (e.dataset?.id) return e;
188
+ e = e.parentNode;
189
+ }
190
+ return null;
191
+ })(t.target);
192
+ if (!i || !r && i.querySelector("[data-drag-handle]")) return;
193
+ let a = i.dataset.id, o = +i.dataset.index, s = i.dataset.type;
194
+ h.current = s, _.current = o, v.current = null;
195
+ let c = s === "row" ? e.bodyRef.current.scrollLeft : 0, l = i.getBoundingClientRect();
196
+ S.current = {
197
+ width: l.width,
198
+ height: l.height
199
+ };
200
+ let u = {
201
+ x: 0,
202
+ y: 0
203
+ };
204
+ t.type === "touchstart" ? (u.x = t.touches[0].clientX, u.y = t.touches[0].clientY) : (u.x = t.clientX - l.left - c, u.y = t.clientY - l.top), g.current = u;
205
+ let d = {
206
+ x: l.left + c,
207
+ y: l.top
208
+ };
209
+ s === "row" ? p.current = w() : p.current = T();
210
+ let f = e.bodyRef.current;
211
+ f && (m.current = f.getBoundingClientRect());
212
+ let y = e.cloneRef?.current;
213
+ y && (y.style.transform = `translate(${d.x}px, ${d.y}px)`), requestAnimationFrame(() => {
214
+ n({
215
+ type: "dragStart",
216
+ value: {
217
+ rect: {
218
+ draggedItemHeight: l.height,
219
+ draggedItemWidth: l.width
220
+ },
221
+ dragged: {
222
+ initial: u,
223
+ translate: d,
224
+ draggedID: a,
225
+ isDragging: !0,
226
+ sourceIndex: o
227
+ },
228
+ dragType: s
229
+ }
230
+ }), requestAnimationFrame(() => {
231
+ let t = e.cloneRef?.current, n = e.bodyRef.current;
232
+ if (t && n) {
233
+ if (s === "row") t.scrollLeft = n.scrollLeft;
234
+ else if (s === "column") {
235
+ let e = t.querySelector(".clone-body");
236
+ e && (e.scrollTop = n.scrollTop);
237
+ }
238
+ }
239
+ });
240
+ });
241
+ }
242
+ }, [
243
+ n,
244
+ e,
245
+ w,
246
+ T
247
+ ]), A = i(() => {
248
+ let t = v.current, r = _.current, i = h.current;
249
+ p.current = null, m.current = null;
250
+ let a = e.cloneRef?.current;
251
+ a && (a.style.transform = "translate(0px, 0px)", a.scrollLeft = 0), O(), s && r !== null && t !== null && i && s({
252
+ sourceIndex: r,
253
+ targetIndex: t,
254
+ dragType: i
255
+ }), n({
256
+ type: "dragEnd",
257
+ value: {
258
+ targetIndex: t,
259
+ sourceIndex: r
260
+ }
261
+ }), l(), h.current = null, _.current = null, v.current = null;
262
+ }, [
263
+ n,
264
+ l,
265
+ e.cloneRef,
266
+ O,
267
+ s
268
+ ]), j = i(() => {
269
+ p.current = null, m.current = null;
270
+ let e = _.current, t = v.current, n = h.current;
271
+ e !== null && t !== null && D(e, t, n);
272
+ }, [D]), M = i((t) => {
273
+ t.stopPropagation();
274
+ let n = g.current, i, a;
275
+ t.type === "touchmove" ? (i = t.touches[0].clientX - n.x, a = t.touches[0].clientY - n.y) : (i = t.clientX - n.x, a = t.clientY - n.y);
276
+ let o = e.cloneRef?.current;
277
+ if (o) {
278
+ o.style.transform = `translate(${i}px, ${a}px)`;
279
+ let t = e.bodyRef.current;
280
+ if (t) {
281
+ if (h.current === "row") o.scrollLeft = t.scrollLeft;
282
+ else if (h.current === "column") {
283
+ let e = o.querySelector(".clone-body");
284
+ e && (e.scrollTop = t.scrollTop);
285
+ }
286
+ }
287
+ }
288
+ f.current = !1, d.current = !1;
289
+ let s = e.bodyRef.current;
290
+ if (!s) return;
291
+ let { clientY: u, clientX: y } = t, S = m.current;
292
+ S || (S = s.getBoundingClientRect(), m.current = S);
293
+ let { top: C, bottom: E, left: O, right: k } = S, A = 0, j = h.current || r;
294
+ if (j === "row") {
295
+ let e = s.scrollTop, t = S.top, n = p.current;
296
+ n || (n = w(), p.current = n), n && n.length > 0 && (A = b(u - t + e, n)), u < C + 30 ? (c(-5, s, "vertical"), p.current = null) : u > E - 30 ? (c(5, s, "vertical"), p.current = null) : l();
297
+ } else {
298
+ let e = p.current;
299
+ e || (e = T(), p.current = e), e && e.length > 0 && (A = x(y, e)), y < O + 30 ? (c(-5, s, "horizontal"), p.current = null) : y > k - 30 ? (c(5, s, "horizontal"), p.current = null) : l();
300
+ }
301
+ A !== v.current && (v.current = A, requestAnimationFrame(() => {
302
+ D(_.current, A, j);
303
+ }));
304
+ }, [
305
+ r,
306
+ d,
307
+ f,
308
+ e.bodyRef,
309
+ e.cloneRef,
310
+ w,
311
+ T,
312
+ c,
313
+ l,
314
+ D
315
+ ]), N = i(() => {
316
+ p.current = null, m.current = null;
317
+ let t = e.cloneRef?.current;
318
+ t && (t.style.transform = "translate(0px, 0px)", t.scrollLeft = 0), O(), n({
319
+ type: "dragEnd",
320
+ value: {
321
+ targetIndex: null,
322
+ sourceIndex: null
323
+ }
324
+ }), l(), h.current = null, _.current = null, v.current = null;
325
+ }, [
326
+ n,
327
+ l,
328
+ e.cloneRef,
329
+ O
330
+ ]), P = i((e) => {
331
+ e.key === "Escape" && N();
332
+ }, [N]);
333
+ return o(() => {
334
+ if (t.isDragging) {
335
+ let t = e.bodyRef.current;
336
+ return window.addEventListener("mousemove", M, { passive: !0 }), window.addEventListener("touchmove", M, !1), window.addEventListener("touchend", A, !1), window.addEventListener("mouseup", A, !1), window.addEventListener("keydown", P), t?.addEventListener("scroll", j, { passive: !0 }), () => {
337
+ window.removeEventListener("mousemove", M), window.removeEventListener("touchmove", M, !1), window.removeEventListener("touchend", A, !1), window.removeEventListener("mouseup", A, !1), window.removeEventListener("keydown", P), t?.removeEventListener("scroll", j);
338
+ };
339
+ }
340
+ }, [
341
+ t.isDragging,
342
+ M,
343
+ A,
344
+ N,
345
+ P,
346
+ j,
347
+ e.bodyRef
348
+ ]), { dragStart: k };
349
+ }, T = {
350
+ columnDragRange: {
351
+ start: void 0,
352
+ end: void 0
353
+ },
354
+ rowDragRange: {
355
+ start: void 0,
356
+ end: void 0
357
+ },
358
+ defaultSizing: 50
359
+ };
360
+ function E(e, t) {
361
+ switch (t.type) {
362
+ case "setClone": return {
363
+ ...e,
364
+ clone: t.value
365
+ };
366
+ case "setDragged": return {
367
+ ...e,
368
+ dragged: {
369
+ ...e.dragged,
370
+ ...t.value
371
+ }
372
+ };
373
+ case "setDragType": return {
374
+ ...e,
375
+ dragType: t.value
376
+ };
377
+ case "setRect": return {
378
+ ...e,
379
+ rect: t.value
380
+ };
381
+ case "setTableDimensions": return {
382
+ ...e,
383
+ tableDimensions: t.value
384
+ };
385
+ case "setTableRef": return {
386
+ ...e,
387
+ refs: {
388
+ ...e.refs,
389
+ tableRef: t.value
390
+ }
391
+ };
392
+ case "setBodyRef": return {
393
+ ...e,
394
+ refs: {
395
+ ...e.refs,
396
+ bodyRef: t.value
397
+ }
398
+ };
399
+ case "setHeaderRef": return {
400
+ ...e,
401
+ refs: {
402
+ ...e.refs,
403
+ headerRef: t.value
404
+ }
405
+ };
406
+ case "setCloneRef": return {
407
+ ...e,
408
+ refs: {
409
+ ...e.refs,
410
+ cloneRef: t.value
411
+ }
412
+ };
413
+ case "setPlaceholderRef": return {
414
+ ...e,
415
+ refs: {
416
+ ...e.refs,
417
+ placeholderRef: t.value
418
+ }
419
+ };
420
+ case "setBodyScrollBarWidth": return {
421
+ ...e,
422
+ bodyScrollBarWidth: t.value
423
+ };
424
+ case "setWidths": return {
425
+ ...e,
426
+ widths: t.value
427
+ };
428
+ case "setColumnIds": return {
429
+ ...e,
430
+ columnIds: t.value
431
+ };
432
+ case "setOptions": return {
433
+ ...e,
434
+ options: t.value ?? T
435
+ };
436
+ case "dragStart": return {
437
+ ...e,
438
+ rect: t.value.rect,
439
+ dragged: {
440
+ ...e.dragged,
441
+ ...t.value.dragged
442
+ },
443
+ dragType: t.value.dragType
444
+ };
445
+ case "dragEnd": return {
446
+ ...e,
447
+ clone: null,
448
+ dragged: {
449
+ initial: {
450
+ x: 0,
451
+ y: 0
452
+ },
453
+ translate: {
454
+ x: 0,
455
+ y: 0
456
+ },
457
+ isDragging: !1,
458
+ draggedID: null,
459
+ targetIndex: t.value?.targetIndex ?? null,
460
+ sourceIndex: t.value?.sourceIndex ?? null
461
+ },
462
+ dragType: null,
463
+ rect: {
464
+ draggedItemWidth: 0,
465
+ draggedItemHeight: 0
466
+ }
467
+ };
468
+ default: throw Error(`Unhandled action type: ${t.type}`);
469
+ }
470
+ }
471
+ var D = {
472
+ clone: null,
473
+ dragged: {
474
+ initial: {
475
+ x: 0,
476
+ y: 0
477
+ },
478
+ translate: {
479
+ x: 0,
480
+ y: 0
481
+ },
482
+ isDragging: !1,
483
+ draggedID: null,
484
+ targetIndex: null,
485
+ sourceIndex: null
486
+ },
487
+ dragType: null,
488
+ rect: {
489
+ draggedItemWidth: 0,
490
+ draggedItemHeight: 0
491
+ },
492
+ tableDimensions: {
493
+ height: 0,
494
+ width: 0
495
+ },
496
+ refs: {
497
+ tableRef: null,
498
+ bodyRef: null,
499
+ headerRef: null,
500
+ cloneRef: null,
501
+ placeholderRef: null
502
+ },
503
+ bodyScrollBarWidth: 0,
504
+ options: T,
505
+ widths: [],
506
+ columnIds: []
507
+ }, O = {
508
+ position: "relative",
509
+ display: "flex",
510
+ flexFlow: "column"
511
+ }, k = {
512
+ position: "fixed",
513
+ pointerEvents: "none",
514
+ zIndex: 3,
515
+ top: 0,
516
+ left: 0,
517
+ display: "none"
518
+ }, A = n(({ children: e, className: t, style: n, options: r, onDragEnd: i, renderPlaceholder: a }, d) => {
519
+ let m = u(null), h = u(null), v = u(null);
520
+ s(d, () => m.current, []);
521
+ let [y, b] = l(E, D), x = c(() => ({
522
+ state: y,
523
+ dispatch: b
524
+ }), [y]);
525
+ o(() => {
526
+ b({
527
+ type: "setTableRef",
528
+ value: m
529
+ }), b({
530
+ type: "setCloneRef",
531
+ value: h
532
+ }), b({
533
+ type: "setPlaceholderRef",
534
+ value: v
535
+ });
536
+ }, [m]), o(() => {
537
+ let e = () => {
538
+ m.current && b({
539
+ type: "setTableDimensions",
540
+ value: {
541
+ height: m.current.offsetHeight,
542
+ width: m.current.offsetWidth
543
+ }
544
+ });
545
+ };
546
+ return e(), window.addEventListener("resize", e), () => {
547
+ window.removeEventListener("resize", e);
548
+ };
549
+ }, [m]), o(() => {
550
+ b({
551
+ type: "setOptions",
552
+ value: r
553
+ });
554
+ }, [r]);
555
+ let { dragStart: S } = w(y.refs, y.dragged, b, y.dragType, y.options, i), C = c(() => ({
556
+ position: "fixed",
557
+ zIndex: "5",
558
+ pointerEvents: "none",
559
+ top: 0,
560
+ left: 0,
561
+ display: "flex",
562
+ flexDirection: "column",
563
+ height: y.dragType === "row" ? y.rect.draggedItemHeight : `${y.tableDimensions.height - 20}px`,
564
+ width: y.dragType === "column" ? `${y.rect.draggedItemWidth}px` : `${y.tableDimensions.width - 20}px`,
565
+ overflow: "hidden",
566
+ boxShadow: y.dragged.isDragging ? "0 0 10px 0 rgba(0, 0, 0, 0.1)" : "none"
567
+ }), [
568
+ y.dragType,
569
+ y.dragged.isDragging,
570
+ y.rect.draggedItemHeight,
571
+ y.rect.draggedItemWidth,
572
+ y.tableDimensions.height,
573
+ y.tableDimensions.width
574
+ ]);
575
+ return /* @__PURE__ */ f(_.Provider, {
576
+ value: x,
577
+ children: /* @__PURE__ */ p(g, {
578
+ className: y.dragged.isDragging ? "is-dragging" : "",
579
+ children: [
580
+ /* @__PURE__ */ f("div", {
581
+ id: "portalroot",
582
+ style: C,
583
+ ref: h,
584
+ children: y.clone
585
+ }),
586
+ a && /* @__PURE__ */ f("div", {
587
+ ref: v,
588
+ style: k,
589
+ children: a()
590
+ }),
591
+ /* @__PURE__ */ f("div", {
592
+ "data-contextid": "context",
593
+ ref: m,
594
+ onMouseDown: S,
595
+ onTouchStart: S,
596
+ style: {
597
+ ...O,
598
+ ...n
599
+ },
600
+ className: `table ${t ?? ""}`,
601
+ children: e
602
+ })
603
+ ]
604
+ })
605
+ });
606
+ });
607
+ A.displayName = "TableProvider";
608
+ //#endregion
609
+ //#region src/Components/TableHeader.tsx
610
+ var j = n(({ children: e, style: t, className: n }, r) => {
611
+ let i = u(null), a = r || i, { state: s, dispatch: l } = v();
612
+ o(() => {
613
+ l({
614
+ type: "setHeaderRef",
615
+ value: a
616
+ });
617
+ }, [l, a]);
618
+ let { HeaderScrollHandle: d } = y(s.refs), p = {
619
+ display: "flex",
620
+ flex: "1 0 auto"
621
+ }, m = c(() => ({
622
+ overflow: "hidden",
623
+ display: "flex",
624
+ paddingRight: `${s.bodyScrollBarWidth}px`,
625
+ userSelect: s.dragged.isDragging ? "none" : "auto",
626
+ ...t
627
+ }), [
628
+ s.bodyScrollBarWidth,
629
+ s.dragged.isDragging,
630
+ t
631
+ ]);
632
+ return o(() => {
633
+ a.current && l({
634
+ type: "setWidths",
635
+ value: Array.from(a.current.querySelectorAll(".th")).map((e) => {
636
+ let t = e.getAttribute("data-width");
637
+ return t ? parseInt(t, 10) : null;
638
+ })
639
+ });
640
+ }, [
641
+ e,
642
+ l,
643
+ a
644
+ ]), o(() => {
645
+ a.current && l({
646
+ type: "setColumnIds",
647
+ value: Array.from(a.current.querySelectorAll(".draggable")).map((e) => e.getAttribute("data-id"))
648
+ });
649
+ }, [
650
+ e,
651
+ l,
652
+ a
653
+ ]), /* @__PURE__ */ f("div", {
654
+ className: `header ${n ?? ""}`,
655
+ children: /* @__PURE__ */ f("div", {
656
+ className: "thead",
657
+ style: m,
658
+ "data-droppableid": "header",
659
+ onScroll: d,
660
+ ref: a,
661
+ children: /* @__PURE__ */ f("div", {
662
+ style: p,
663
+ className: "tr",
664
+ children: e
665
+ })
666
+ })
667
+ });
668
+ });
669
+ j.displayName = "TableHeader";
670
+ //#endregion
671
+ //#region src/Components/Draggable.tsx
672
+ var M = r(({ children: t, id: n, index: r, type: i, styles: a = {} }) => {
673
+ let { state: s, dispatch: l } = v(), d = c(() => String(n) === String(s.dragged.draggedID) && s.dragged.isDragging, [
674
+ n,
675
+ s.dragged.draggedID,
676
+ s.dragged.isDragging
677
+ ]), p = c(() => i === "row" ? S(r, s.options.rowDragRange.start, s.options.rowDragRange.end) : S(r, s.options.columnDragRange.start, s.options.columnDragRange.end), [
678
+ r,
679
+ s.options.columnDragRange.end,
680
+ s.options.columnDragRange.start,
681
+ s.options.rowDragRange.end,
682
+ s.options.rowDragRange.start,
683
+ i
684
+ ]), m = u(null), h = u(!1);
685
+ o(() => {
686
+ m.current && (h.current = !!m.current.querySelector("[data-drag-handle]"));
687
+ });
688
+ let g = c(() => ({
689
+ cursor: d ? "-webkit-grabbing" : p || h.current ? "auto" : "-webkit-grab",
690
+ zIndex: d ? 2 : 1,
691
+ opacity: d ? 0 : 1,
692
+ pointerEvents: d ? "none" : "auto",
693
+ display: "flex"
694
+ }), [p, d]), _ = (n) => {
695
+ p || requestAnimationFrame(() => {
696
+ l({
697
+ type: "setClone",
698
+ value: e.cloneElement(t)
699
+ });
700
+ });
701
+ };
702
+ return /* @__PURE__ */ f("div", {
703
+ className: "draggable",
704
+ "data-id": n,
705
+ "data-index": r,
706
+ "data-type": i,
707
+ onMouseDown: _,
708
+ "data-disabled": p ? "true" : "false",
709
+ style: a,
710
+ children: /* @__PURE__ */ f("div", {
711
+ ref: m,
712
+ style: g,
713
+ children: t
714
+ })
715
+ });
716
+ });
717
+ M.displayName = "Draggable";
718
+ //#endregion
719
+ //#region src/Components/ColumnCell.tsx
720
+ var N = r(({ children: e, width: t, style: n, className: r, ...i }) => {
721
+ let { state: a } = v(), o = c(() => t ?? a.options.defaultSizing, [t, a.options.defaultSizing]), s = c(() => ({
722
+ width: `${o}px`,
723
+ flex: `${o} 0 auto`
724
+ }), [o]);
725
+ return /* @__PURE__ */ f(M, {
726
+ ...i,
727
+ styles: s,
728
+ type: "column",
729
+ children: /* @__PURE__ */ f("div", {
730
+ className: `th ${r ?? ""}`,
731
+ "data-width": t,
732
+ style: {
733
+ width: "100%",
734
+ ...n
735
+ },
736
+ children: e
737
+ })
738
+ });
739
+ });
740
+ N.displayName = "ColumnCell";
741
+ //#endregion
742
+ //#region src/Components/TableBody.tsx
743
+ var P = n(({ children: t, style: n, className: r }, i) => {
744
+ let a = u(null);
745
+ s(i, () => a.current, []);
746
+ let { state: l, dispatch: d } = v(), h = c(() => {
747
+ if (l.dragged.sourceIndex === null) return null;
748
+ let n = (t) => {
749
+ let r = [];
750
+ return e.Children.forEach(t, (t) => {
751
+ e.isValidElement(t) && (t.props.id !== void 0 && t.props.index !== void 0 && t.props.children ? r.push(t) : t.props.children && r.push(...n(t.props.children)));
752
+ }), r;
753
+ };
754
+ return n(t).map((t) => {
755
+ 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 }));
756
+ return e.cloneElement(t, {
757
+ ...t.props,
758
+ children: n
759
+ });
760
+ });
761
+ }, [t, l.dragged.sourceIndex]);
762
+ o(() => {
763
+ d({
764
+ type: "setBodyRef",
765
+ value: a
766
+ });
767
+ }, [d, a]);
768
+ let { BodyScrollHandle: g } = y(l.refs), _ = c(() => ({
769
+ overflowX: "auto",
770
+ overflowY: "auto",
771
+ flex: 1,
772
+ userSelect: l.dragged.isDragging ? "none" : "auto",
773
+ ...n
774
+ }), [l.dragged.isDragging, n]);
775
+ o(() => {
776
+ if (a.current) {
777
+ let e = a.current.clientWidth;
778
+ d({
779
+ type: "setBodyScrollBarWidth",
780
+ value: a.current.offsetWidth - e
781
+ });
782
+ }
783
+ }, [d, a]);
784
+ let b = a.current?.scrollHeight ?? 0;
785
+ return /* @__PURE__ */ p(e.Fragment, { children: [l.dragType === "column" && l.refs.cloneRef?.current && m(/* @__PURE__ */ f("div", {
786
+ className: "body clone-body",
787
+ "data-droppableid": "body",
788
+ style: {
789
+ overflow: "hidden",
790
+ flex: 1
791
+ },
792
+ children: /* @__PURE__ */ f("div", {
793
+ className: "rbody",
794
+ style: {
795
+ height: b,
796
+ position: "relative"
797
+ },
798
+ children: h
799
+ })
800
+ }), l.refs.cloneRef.current), /* @__PURE__ */ f("div", {
801
+ className: `body ${r ?? ""}`,
802
+ style: F,
803
+ children: /* @__PURE__ */ f("div", {
804
+ className: "ibody",
805
+ style: _,
806
+ "data-droppableid": "body",
807
+ onScroll: g,
808
+ ref: a,
809
+ children: t
810
+ })
811
+ })] });
812
+ }), F = {
813
+ display: "flex",
814
+ overflow: "hidden",
815
+ flex: 1
816
+ };
817
+ P.displayName = "TableBody";
818
+ //#endregion
819
+ //#region src/Components/BodyRow.tsx
820
+ var I = {
821
+ display: "flex",
822
+ flex: "1 0 auto",
823
+ minHeight: "24px"
824
+ }, L = r(({ children: e, style: t, className: n, ...r }) => {
825
+ let i = c(() => t ? {
826
+ ...I,
827
+ ...t
828
+ } : I, [t]), a = h("tr", n);
829
+ return /* @__PURE__ */ f(M, {
830
+ ...r,
831
+ type: "row",
832
+ children: /* @__PURE__ */ f("div", {
833
+ className: a,
834
+ style: i,
835
+ children: e
836
+ })
837
+ });
838
+ });
839
+ L.displayName = "BodyRow";
840
+ //#endregion
841
+ //#region src/Components/RowCell.tsx
842
+ var R = r(({ children: e, style: t, className: n, isClone: r, ...i }) => {
843
+ let { index: a } = i, { state: o } = v(), s = c(() => o.columnIds[a] ?? "", [o.columnIds, a]), l = c(() => o.widths[a] ?? o.options.defaultSizing, [
844
+ o.widths,
845
+ a,
846
+ o.options.defaultSizing
847
+ ]), u = c(() => r ? !1 : s === o.dragged.draggedID, [
848
+ r,
849
+ s,
850
+ o.dragged.draggedID
851
+ ]), d = c(() => ({
852
+ display: "inline-flex",
853
+ opacity: u ? 0 : 1,
854
+ width: `${l}px`,
855
+ flex: `${l} 0 auto`,
856
+ ...t
857
+ }), [
858
+ u,
859
+ l,
860
+ t
861
+ ]);
862
+ return /* @__PURE__ */ f("div", {
863
+ className: `td ${n ?? ""}`,
864
+ style: d,
865
+ "data-col-index": a,
866
+ children: e
867
+ });
868
+ });
869
+ R.displayName = "RowCell";
870
+ //#endregion
871
+ //#region src/Components/DragHandle.tsx
872
+ var z = r(({ children: e, className: t, style: n }) => /* @__PURE__ */ f("div", {
873
+ "data-drag-handle": "true",
874
+ className: t,
875
+ style: {
876
+ cursor: "-webkit-grab",
877
+ display: "inline-flex",
878
+ alignItems: "center",
879
+ ...n
880
+ },
881
+ children: e
882
+ }));
883
+ z.displayName = "DragHandle";
884
+ //#endregion
885
+ export { L as BodyRow, N as ColumnCell, z as DragHandle, R as RowCell, P as TableBody, A as TableContainer, j as TableHeader, v as useTable };