@krosoft/react 0.0.228 → 0.0.230
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/DataTable-DYp_uFEn.js +638 -0
- package/dist/{SearchInput-Y-iBtCCc.js → SearchInput-Dkvaei9K.js} +38 -38
- package/dist/{TableFilter-CJrFjUod.js → TableFilter-BXD7Es8j.js} +1 -1
- package/dist/components/core/filters/index.js +1 -1
- package/dist/components/core/index.js +67 -62
- package/dist/components/core/inputs/index.js +1 -1
- package/dist/components/core/table/DataTable.d.ts +2 -1
- package/dist/components/core/table/DataTable.d.ts.map +1 -1
- package/dist/components/core/table/TableBody.d.ts +3 -1
- package/dist/components/core/table/TableBody.d.ts.map +1 -1
- package/dist/components/core/table/TableHeader.d.ts +5 -1
- package/dist/components/core/table/TableHeader.d.ts.map +1 -1
- package/dist/components/core/table/columnAlignment.d.ts +13 -0
- package/dist/components/core/table/columnAlignment.d.ts.map +1 -0
- package/dist/components/core/table/fixedColumns.d.ts +19 -0
- package/dist/components/core/table/fixedColumns.d.ts.map +1 -0
- package/dist/components/core/table/index.d.ts +2 -0
- package/dist/components/core/table/index.d.ts.map +1 -1
- package/dist/components/core/table/index.js +13 -8
- package/dist/components/index.js +189 -184
- package/dist/hooks/index.js +11 -10
- package/dist/hooks/ui/index.d.ts +2 -0
- package/dist/hooks/ui/index.d.ts.map +1 -1
- package/dist/hooks/ui/index.js +16 -15
- package/dist/hooks/ui/useFixedColumns.d.ts +23 -0
- package/dist/hooks/ui/useFixedColumns.d.ts.map +1 -0
- package/dist/types/ColumnDef.d.ts +2 -0
- package/dist/types/ColumnDef.d.ts.map +1 -1
- package/dist/useFixedColumns-CKZyu4PD.js +161 -0
- package/package.json +1 -1
- package/dist/DataTable-DSrsTb_t.js +0 -553
- package/dist/useDataTable-CxcA5S-s.js +0 -126
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { useState as f, useRef as b, useMemo as W, useCallback as m, useLayoutEffect as ye } from "react";
|
|
2
|
+
function Pe({
|
|
3
|
+
data: s,
|
|
4
|
+
columns: r,
|
|
5
|
+
getRowId: S,
|
|
6
|
+
defaultPageSize: g,
|
|
7
|
+
actions: i,
|
|
8
|
+
bulkActions: c,
|
|
9
|
+
columnVisibility: l = !0,
|
|
10
|
+
totalRows: a,
|
|
11
|
+
currentPage: V,
|
|
12
|
+
pageSize: u,
|
|
13
|
+
onPageChange: O,
|
|
14
|
+
onPageSizeChange: C,
|
|
15
|
+
sortColumn: k,
|
|
16
|
+
sortDirection: R,
|
|
17
|
+
onSortChange: h
|
|
18
|
+
}) {
|
|
19
|
+
var ee;
|
|
20
|
+
const [te, ne] = f(((ee = r.find((e) => e.sortable === !0)) == null ? void 0 : ee.key) ?? null), p = k !== void 0 ? k : te, [re, se] = f("asc"), v = R ?? re, [D, E] = f([]), [w, oe] = f(new Set(r.filter((e) => e.defaultVisible !== !1).map((e) => e.key))), [I, ie] = f(r.map((e) => e.key)), [T, ce] = f(r.reduce((e, t) => ({ ...e, [t.key]: t.minWidth ?? 100 }), {})), [le, U] = f(1), P = V ?? le, [ae, ue] = f(g), x = u ?? ae, de = b(null), X = b(null), G = b(0), H = b(0), y = b(null), J = b(null), N = i !== void 0 && i.length > 0, Q = c !== void 0 && c.length > 0, j = W(() => I.map((e) => r.find((t) => t.key === e)).filter((e) => e !== void 0), [I, r]), Y = W(() => j.filter((e) => w.has(e.key)), [j, w]), fe = Y.length + (Q ? 1 : 0) + (N || l ? 1 : 0), Z = a ?? s.length, q = Math.max(1, Math.ceil(Z / x)), _ = P > q ? q : P, M = Z === 0 ? 0 : (_ - 1) * x, B = a !== void 0 ? Math.min(M + s.length, a) : Math.min(M + x, s.length), z = m(
|
|
21
|
+
(e) => {
|
|
22
|
+
O ? O(e) : U(e);
|
|
23
|
+
},
|
|
24
|
+
[O]
|
|
25
|
+
), $ = m(
|
|
26
|
+
(e) => {
|
|
27
|
+
C ? C(e) : (ue(e), U(1));
|
|
28
|
+
},
|
|
29
|
+
[C]
|
|
30
|
+
), ge = m(
|
|
31
|
+
(e) => {
|
|
32
|
+
const t = typeof e == "function" ? e(P) : e;
|
|
33
|
+
z(t);
|
|
34
|
+
},
|
|
35
|
+
[P, z]
|
|
36
|
+
), he = m(
|
|
37
|
+
(e) => {
|
|
38
|
+
const t = typeof e == "function" ? e(x) : e;
|
|
39
|
+
$(t);
|
|
40
|
+
},
|
|
41
|
+
[x, $]
|
|
42
|
+
), pe = m(
|
|
43
|
+
(e) => {
|
|
44
|
+
const t = r.find((o) => o.key === e);
|
|
45
|
+
if ((t == null ? void 0 : t.sortable) !== !0) return;
|
|
46
|
+
let n = "asc";
|
|
47
|
+
p === e && (n = v === "asc" ? "desc" : "asc"), h ? h(e, n) : (ne(e), se(n), z(1));
|
|
48
|
+
},
|
|
49
|
+
[r, p, v, h, z]
|
|
50
|
+
), L = m((e) => {
|
|
51
|
+
const t = X.current;
|
|
52
|
+
if (t === null) return;
|
|
53
|
+
const n = e.clientX - G.current, o = Math.max(80, H.current + n);
|
|
54
|
+
ce((d) => ({
|
|
55
|
+
...d,
|
|
56
|
+
[t]: o
|
|
57
|
+
}));
|
|
58
|
+
}, []), K = m(
|
|
59
|
+
function e() {
|
|
60
|
+
X.current = null, document.removeEventListener("mousemove", L), document.removeEventListener("mouseup", e);
|
|
61
|
+
},
|
|
62
|
+
[L]
|
|
63
|
+
), me = m(
|
|
64
|
+
(e, t) => {
|
|
65
|
+
e.preventDefault(), e.stopPropagation(), X.current = t, G.current = e.clientX, H.current = T[t], document.addEventListener("mousemove", L), document.addEventListener("mouseup", K);
|
|
66
|
+
},
|
|
67
|
+
[T, L, K]
|
|
68
|
+
), ve = (e, t) => {
|
|
69
|
+
y.current = t, e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/html", t);
|
|
70
|
+
}, Se = (e, t) => {
|
|
71
|
+
e.preventDefault(), e.dataTransfer.dropEffect = "move", J.current = t;
|
|
72
|
+
}, Ce = (e, t) => {
|
|
73
|
+
if (e.preventDefault(), y.current === null || y.current === t) return;
|
|
74
|
+
const n = [...I], o = n.indexOf(y.current), d = n.indexOf(t);
|
|
75
|
+
n.splice(o, 1), n.splice(d, 0, y.current), ie(n), y.current = null, J.current = null;
|
|
76
|
+
}, F = W(() => h !== void 0 ? s : [...s].sort((e, t) => {
|
|
77
|
+
if (p === null) return 0;
|
|
78
|
+
const n = r.find((A) => A.key === p), o = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(e) : e[p], d = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(t) : t[p];
|
|
79
|
+
if (typeof o == "string" && typeof d == "string") {
|
|
80
|
+
const A = o.localeCompare(d);
|
|
81
|
+
return v === "asc" ? A : -A;
|
|
82
|
+
}
|
|
83
|
+
return o === d ? 0 : o == null ? 1 : d == null ? -1 : o < d ? v === "asc" ? -1 : 1 : o > d ? v === "asc" ? 1 : -1 : 0;
|
|
84
|
+
}), [s, p, v, r, h]), xe = W(() => a !== void 0 ? F : F.slice(M, B), [F, M, B, a]);
|
|
85
|
+
return {
|
|
86
|
+
sortColumn: p,
|
|
87
|
+
sortDirection: v,
|
|
88
|
+
selectedRows: D,
|
|
89
|
+
setSelectedRows: E,
|
|
90
|
+
visibleColumns: w,
|
|
91
|
+
columnWidths: T,
|
|
92
|
+
currentPage: P,
|
|
93
|
+
setCurrentPage: ge,
|
|
94
|
+
pageSize: x,
|
|
95
|
+
setPageSize: he,
|
|
96
|
+
totalPages: q,
|
|
97
|
+
safeCurrentPage: _,
|
|
98
|
+
startIndex: M,
|
|
99
|
+
endIndex: B,
|
|
100
|
+
tableRef: de,
|
|
101
|
+
hasActions: N,
|
|
102
|
+
hasBulkActions: Q,
|
|
103
|
+
orderedColumns: j,
|
|
104
|
+
visibleColumnsArray: Y,
|
|
105
|
+
colSpanCount: fe,
|
|
106
|
+
paginatedData: xe,
|
|
107
|
+
handleSort: pe,
|
|
108
|
+
handleMouseDown: me,
|
|
109
|
+
handleDragStart: ve,
|
|
110
|
+
handleDragOver: Se,
|
|
111
|
+
handleDrop: Ce,
|
|
112
|
+
toggleColumnVisibility: (e) => {
|
|
113
|
+
const t = new Set(w);
|
|
114
|
+
t.has(e) ? t.delete(e) : t.add(e), oe(t);
|
|
115
|
+
},
|
|
116
|
+
toggleRowSelection: (e) => {
|
|
117
|
+
D.includes(e) ? E(D.filter((t) => t !== e)) : E([...D, e]);
|
|
118
|
+
},
|
|
119
|
+
toggleSelectAll: () => {
|
|
120
|
+
D.length === s.length ? E([]) : E(s.map((e) => S(e)));
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const be = (s, r) => {
|
|
125
|
+
const S = Object.keys(s);
|
|
126
|
+
return S.length !== Object.keys(r).length ? !1 : S.every((g) => {
|
|
127
|
+
const i = s[g], c = r[g];
|
|
128
|
+
return i.side === (c == null ? void 0 : c.side) && i.offset === c.offset && i.isEdge === c.isEdge;
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
function Me(s) {
|
|
132
|
+
const [r, S] = f({});
|
|
133
|
+
return ye(() => {
|
|
134
|
+
const g = s.current;
|
|
135
|
+
if (!g) return;
|
|
136
|
+
let i = [];
|
|
137
|
+
const c = () => {
|
|
138
|
+
i = Array.from(g.querySelectorAll("thead th[data-fixed-side]"));
|
|
139
|
+
const a = {}, V = (u, O) => {
|
|
140
|
+
let C = 0;
|
|
141
|
+
u.forEach((k, R) => {
|
|
142
|
+
const h = k.dataset.columnKey;
|
|
143
|
+
h !== void 0 && (a[h] = { side: O, offset: C, isEdge: R === u.length - 1 }, C += k.getBoundingClientRect().width);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
V(
|
|
147
|
+
i.filter((u) => u.dataset.fixedSide === "left"),
|
|
148
|
+
"left"
|
|
149
|
+
), V(i.filter((u) => u.dataset.fixedSide === "right").reverse(), "right"), S((u) => be(u, a) ? u : a);
|
|
150
|
+
};
|
|
151
|
+
c();
|
|
152
|
+
const l = typeof ResizeObserver > "u" ? null : new ResizeObserver(c);
|
|
153
|
+
return l == null || l.observe(g), i.forEach((a) => l == null ? void 0 : l.observe(a)), () => {
|
|
154
|
+
l == null || l.disconnect();
|
|
155
|
+
};
|
|
156
|
+
}), r;
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
Me as a,
|
|
160
|
+
Pe as u
|
|
161
|
+
};
|