@chumsinc/sortable-tables 2.2.0 → 3.0.1
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/CHANGELOG.md +31 -1
- package/README.md +94 -4
- package/dist/DataTable.d.ts +1 -1
- package/dist/DataTableCell.d.ts +6 -2
- package/dist/DataTableCols.d.ts +1 -1
- package/dist/DataTableContext.d.ts +10 -0
- package/dist/DataTableProvider.d.ts +12 -0
- package/dist/DataTableTH.d.ts +1 -1
- package/dist/SortableTable.d.ts +1 -1
- package/dist/SortableTableHead.d.ts +1 -1
- package/dist/SortableTableHeadWrapper.d.ts +9 -0
- package/dist/SortableTableTH.d.ts +1 -1
- package/dist/StandaloneDataTable.d.ts +6 -0
- package/dist/StandaloneDataTableRow.d.ts +9 -0
- package/dist/StandaloneSortHelper.d.ts +5 -0
- package/dist/StandaloneSortableTable.d.ts +6 -0
- package/dist/Table.d.ts +5 -4
- package/dist/index.cjs.js +4 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.es.js +239 -198
- package/dist/index.es.js.map +1 -1
- package/dist/types.d.ts +4 -3
- package/dist/useField.d.ts +6 -0
- package/dist/useTableContext.d.ts +2 -0
- package/dist/useTableFields.d.ts +9 -0
- package/dist/useTableSort.d.ts +9 -0
- package/package.json +3 -3
- package/src/DataTable.tsx +34 -11
- package/src/DataTableCell.tsx +33 -28
- package/src/DataTableCols.tsx +11 -18
- package/src/DataTableContext.ts +13 -0
- package/src/DataTableHead.tsx +6 -7
- package/src/DataTableProvider.tsx +62 -0
- package/src/DataTableRow.tsx +8 -7
- package/src/DataTableTBody.tsx +1 -3
- package/src/DataTableTH.tsx +4 -3
- package/src/RowsPerPage.tsx +2 -4
- package/src/SortableTable.tsx +36 -12
- package/src/SortableTableHead.tsx +9 -9
- package/src/SortableTableHeadWrapper.tsx +20 -0
- package/src/SortableTableTH.tsx +4 -4
- package/src/StandaloneDataTable.tsx +16 -0
- package/src/StandaloneDataTableRow.tsx +42 -0
- package/src/StandaloneSortHelper.tsx +15 -0
- package/src/StandaloneSortableTable.tsx +21 -0
- package/src/Table.tsx +49 -44
- package/src/TablePagination.tsx +1 -3
- package/src/index.tsx +21 -15
- package/src/types.ts +127 -126
- package/src/useField.ts +19 -0
- package/src/useTableContext.ts +10 -0
- package/src/useTableFields.ts +20 -0
- package/src/useTableSort.ts +20 -0
- package/test/Main.tsx +37 -0
- package/test/TableColumnsHandler.tsx +9 -9
- package/test/TestTable.tsx +51 -46
- package/test/data.ts +232 -232
- package/test/index.tsx +11 -11
- package/test/tableFields.tsx +11 -3
- package/test/utils.ts +19 -0
- package/tsconfig.json +1 -0
- package/dist/DataTableWithContext.d.ts +0 -2
- package/dist/SortableTableWithContext.d.ts +0 -2
- package/dist/TableProvider.d.ts +0 -17
- package/src/DataTableWithContext.tsx +0 -41
- package/src/SortableTableWithContext.tsx +0 -44
- package/src/TableProvider.tsx +0 -77
package/dist/index.es.js
CHANGED
|
@@ -1,56 +1,53 @@
|
|
|
1
|
-
import { jsx as l, jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { jsx as l, jsxs as f } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as I, useState as H, useCallback as g, useMemo as J, useContext as S, createElement as L, useEffect as q, useId as K } from "react";
|
|
3
|
+
import F from "@emotion/styled";
|
|
4
|
+
const y = I(null);
|
|
5
|
+
function x({
|
|
6
|
+
children: t,
|
|
7
|
+
initialFields: a = [],
|
|
8
|
+
initialSort: e = null
|
|
9
|
+
}) {
|
|
10
|
+
const [n, s] = H(a), [r, i] = H(e), c = g(
|
|
11
|
+
(m) => {
|
|
12
|
+
s(m);
|
|
13
|
+
},
|
|
14
|
+
[]
|
|
15
|
+
), o = g(
|
|
16
|
+
(m) => {
|
|
17
|
+
i(m);
|
|
18
|
+
},
|
|
19
|
+
[]
|
|
20
|
+
), u = g((m, h) => {
|
|
21
|
+
const N = n.map((T) => T.id === m ? { ...T, ...h } : T);
|
|
22
|
+
s(N);
|
|
23
|
+
}, [n]), d = g((m) => n.find((h) => h.id === m), [n]), b = J(
|
|
12
24
|
() => ({
|
|
13
|
-
fields:
|
|
14
|
-
setFields:
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
fields: n,
|
|
26
|
+
setFields: c,
|
|
27
|
+
sort: r,
|
|
28
|
+
setSort: o,
|
|
29
|
+
getField: d,
|
|
30
|
+
updateField: u
|
|
17
31
|
}),
|
|
18
|
-
[
|
|
32
|
+
[n, c, r, o, u, d]
|
|
19
33
|
);
|
|
20
|
-
return /* @__PURE__ */ l(
|
|
21
|
-
}
|
|
22
|
-
function J() {
|
|
23
|
-
const t = g(N);
|
|
24
|
-
if (!t)
|
|
25
|
-
throw new Error("useTableContext must be used within a FieldsProvider");
|
|
26
|
-
return t;
|
|
27
|
-
}
|
|
28
|
-
function y() {
|
|
29
|
-
return J().fields;
|
|
30
|
-
}
|
|
31
|
-
function nt(t) {
|
|
32
|
-
const a = g(N);
|
|
33
|
-
if (!a)
|
|
34
|
-
throw new Error("useTableContext must be used within a FieldsProvider");
|
|
35
|
-
return a.fields.find((n) => n.id === t) ?? null;
|
|
36
|
-
}
|
|
37
|
-
function lt() {
|
|
38
|
-
return g(N) !== null;
|
|
34
|
+
return /* @__PURE__ */ l(y.Provider, { value: b, children: t });
|
|
39
35
|
}
|
|
40
|
-
|
|
36
|
+
x.displayName = "DataTableProvider";
|
|
37
|
+
function E(t) {
|
|
41
38
|
var a, e, n = "";
|
|
42
39
|
if (typeof t == "string" || typeof t == "number") n += t;
|
|
43
40
|
else if (typeof t == "object") if (Array.isArray(t)) {
|
|
44
41
|
var s = t.length;
|
|
45
|
-
for (a = 0; a < s; a++) t[a] && (e =
|
|
42
|
+
for (a = 0; a < s; a++) t[a] && (e = E(t[a])) && (n && (n += " "), n += e);
|
|
46
43
|
} else for (e in t) t[e] && (n && (n += " "), n += e);
|
|
47
44
|
return n;
|
|
48
45
|
}
|
|
49
|
-
function
|
|
50
|
-
for (var t, a, e = 0, n = "", s = arguments.length; e < s; e++) (t = arguments[e]) && (a =
|
|
46
|
+
function p() {
|
|
47
|
+
for (var t, a, e = 0, n = "", s = arguments.length; e < s; e++) (t = arguments[e]) && (a = E(t)) && (n && (n += " "), n += a);
|
|
51
48
|
return n;
|
|
52
49
|
}
|
|
53
|
-
const
|
|
50
|
+
const w = F.table`
|
|
54
51
|
--table-sticky-top: ${(t) => t.sticky ? "0" : void 0};
|
|
55
52
|
|
|
56
53
|
thead {
|
|
@@ -62,103 +59,117 @@ const D = x.table`
|
|
|
62
59
|
background: ${(t) => t.sticky ? "linear-gradient(var(--bs-table-bg) 75%, rgba(var(--bs-secondary-bg-rgb), 0.9))" : "unset"};
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
return /* @__PURE__ */ l(D, { className: s, sticky: a, ref: i, ...c, children: n });
|
|
62
|
+
`;
|
|
63
|
+
function P({
|
|
64
|
+
sticky: t,
|
|
65
|
+
responsive: a,
|
|
66
|
+
children: e,
|
|
67
|
+
className: n,
|
|
68
|
+
ref: s,
|
|
69
|
+
...r
|
|
70
|
+
}) {
|
|
71
|
+
if (a) {
|
|
72
|
+
const i = p(n, {
|
|
73
|
+
"table-responsive": a === !0,
|
|
74
|
+
[`table-responsive-${a}`]: a !== !0
|
|
75
|
+
});
|
|
76
|
+
return /* @__PURE__ */ l("div", { className: i, children: /* @__PURE__ */ l(w, { ref: s, ...r, children: e }) });
|
|
81
77
|
}
|
|
82
|
-
);
|
|
78
|
+
return /* @__PURE__ */ l(w, { className: n, sticky: t, ref: s, ...r, children: e });
|
|
79
|
+
}
|
|
83
80
|
function C({
|
|
84
81
|
field: t,
|
|
85
82
|
className: a,
|
|
86
83
|
children: e,
|
|
87
84
|
...n
|
|
88
85
|
}) {
|
|
89
|
-
|
|
86
|
+
if (t.visible === !1)
|
|
87
|
+
return null;
|
|
88
|
+
const s = p({ [`text-${t.align}`]: !!t.align }, a);
|
|
90
89
|
return /* @__PURE__ */ l("th", { className: s, scope: "col", ...n, children: e ?? t.title });
|
|
91
90
|
}
|
|
92
91
|
C.displayName = "DataTableTH";
|
|
93
|
-
function
|
|
94
|
-
const
|
|
92
|
+
function v() {
|
|
93
|
+
const t = S(y);
|
|
94
|
+
if (!t)
|
|
95
|
+
throw new Error("useTableContext must be used within a DataTableProvider");
|
|
96
|
+
return [
|
|
97
|
+
t.fields,
|
|
98
|
+
t.setFields
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
function j({ ...t }) {
|
|
102
|
+
const [a] = v();
|
|
95
103
|
return /* @__PURE__ */ l("thead", { ...t, children: /* @__PURE__ */ l("tr", { children: a.map((e, n) => /* @__PURE__ */ l(
|
|
96
104
|
C,
|
|
97
105
|
{
|
|
98
106
|
...e.thProps,
|
|
99
107
|
field: e,
|
|
100
|
-
className:
|
|
108
|
+
className: p(
|
|
101
109
|
typeof e.className == "function" ? { [`text-${e.align}`]: !!e.align } : e.className
|
|
102
110
|
)
|
|
103
111
|
},
|
|
104
|
-
e.id ?? n
|
|
112
|
+
String(e.id ?? n)
|
|
105
113
|
)) }) });
|
|
106
114
|
}
|
|
107
|
-
|
|
108
|
-
function
|
|
115
|
+
j.displayName = "DataTableHead";
|
|
116
|
+
function R({
|
|
109
117
|
className: t,
|
|
110
118
|
size: a,
|
|
111
119
|
responsive: e,
|
|
112
120
|
sticky: n,
|
|
113
121
|
data: s,
|
|
114
|
-
keyField:
|
|
122
|
+
keyField: r,
|
|
115
123
|
rowClassName: i,
|
|
116
|
-
renderRow:
|
|
124
|
+
renderRow: c,
|
|
117
125
|
onSelectRow: o,
|
|
118
126
|
selected: u,
|
|
119
|
-
tableHeadProps:
|
|
120
|
-
children:
|
|
121
|
-
tfoot:
|
|
127
|
+
tableHeadProps: d,
|
|
128
|
+
children: b,
|
|
129
|
+
tfoot: m,
|
|
122
130
|
...h
|
|
123
131
|
}) {
|
|
124
|
-
const
|
|
132
|
+
const N = p("table", t, {
|
|
125
133
|
[`table-${a}`]: !!a
|
|
126
134
|
});
|
|
127
|
-
return /* @__PURE__ */
|
|
135
|
+
return /* @__PURE__ */ f(P, { sticky: n, responsive: e, className: N, ...h, children: [
|
|
128
136
|
/* @__PURE__ */ l(k, {}),
|
|
129
|
-
/* @__PURE__ */ l(
|
|
137
|
+
/* @__PURE__ */ l(j, { ...d }),
|
|
130
138
|
!!s.length && /* @__PURE__ */ l(
|
|
131
|
-
|
|
139
|
+
D,
|
|
132
140
|
{
|
|
133
141
|
data: s,
|
|
134
|
-
keyField:
|
|
142
|
+
keyField: r,
|
|
135
143
|
rowClassName: i,
|
|
136
|
-
renderRow:
|
|
144
|
+
renderRow: c,
|
|
137
145
|
onSelectRow: o,
|
|
138
146
|
selected: u
|
|
139
147
|
}
|
|
140
148
|
),
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
b,
|
|
150
|
+
m
|
|
143
151
|
] });
|
|
144
152
|
}
|
|
145
|
-
|
|
153
|
+
R.displayName = "DataTable";
|
|
154
|
+
function O({
|
|
146
155
|
fields: t,
|
|
147
156
|
...a
|
|
148
157
|
}) {
|
|
149
|
-
return /* @__PURE__ */ l(
|
|
158
|
+
return /* @__PURE__ */ l(x, { initialFields: t, children: /* @__PURE__ */ l(R, { ...a }) });
|
|
150
159
|
}
|
|
151
|
-
|
|
152
|
-
function
|
|
153
|
-
|
|
160
|
+
O.displayName = "StandaloneDataTable";
|
|
161
|
+
function M({ field: t, row: a, className: e, as: n, ...s }) {
|
|
162
|
+
if (t.visible === !1)
|
|
163
|
+
return null;
|
|
164
|
+
const r = p(
|
|
154
165
|
{ [`text-${t.align}`]: !!t.align },
|
|
155
166
|
e,
|
|
156
167
|
typeof t.className == "function" ? t.className(a) : t.className
|
|
157
168
|
);
|
|
158
|
-
return
|
|
169
|
+
return L(
|
|
159
170
|
n ?? t.as ?? "td",
|
|
160
171
|
{
|
|
161
|
-
className:
|
|
172
|
+
className: r,
|
|
162
173
|
scope: (n ?? t.as) === "th" ? "row" : void 0,
|
|
163
174
|
colSpan: t.colSpan,
|
|
164
175
|
...t.cellProps,
|
|
@@ -167,50 +178,51 @@ function K({ field: t, row: a, className: e, as: n, ...s }) {
|
|
|
167
178
|
a[t.field] === void 0 && !t.render ? null : typeof t.render == "function" ? t.render(a) : a[t.field]
|
|
168
179
|
);
|
|
169
180
|
}
|
|
170
|
-
|
|
181
|
+
M.displayName = "DataTableCell";
|
|
182
|
+
function W({
|
|
171
183
|
className: t,
|
|
172
184
|
rowClassName: a,
|
|
173
185
|
selected: e,
|
|
174
186
|
row: n,
|
|
175
187
|
trRef: s,
|
|
176
|
-
onClick:
|
|
188
|
+
onClick: r,
|
|
177
189
|
...i
|
|
178
190
|
}) {
|
|
179
|
-
const
|
|
180
|
-
|
|
191
|
+
const [c] = v(), o = (d) => {
|
|
192
|
+
r?.(n, d);
|
|
181
193
|
}, u = typeof a == "function" ? a(n) : a;
|
|
182
194
|
return n ? /* @__PURE__ */ l(
|
|
183
195
|
"tr",
|
|
184
196
|
{
|
|
185
197
|
ref: s,
|
|
186
|
-
className:
|
|
198
|
+
className: p({ "table-active": e }, t, u),
|
|
187
199
|
onClick: o,
|
|
188
200
|
...i,
|
|
189
|
-
children:
|
|
201
|
+
children: c.map((d, b) => /* @__PURE__ */ l(M, { field: d, row: n }, String(d?.id ?? b)))
|
|
190
202
|
}
|
|
191
203
|
) : null;
|
|
192
204
|
}
|
|
193
|
-
|
|
194
|
-
function
|
|
205
|
+
W.displayName = "DataTableRow";
|
|
206
|
+
function D({
|
|
195
207
|
data: t,
|
|
196
208
|
keyField: a,
|
|
197
209
|
rowClassName: e,
|
|
198
210
|
renderRow: n,
|
|
199
211
|
onSelectRow: s,
|
|
200
|
-
selected:
|
|
212
|
+
selected: r = "",
|
|
201
213
|
children: i,
|
|
202
|
-
...
|
|
214
|
+
...c
|
|
203
215
|
}) {
|
|
204
|
-
return /* @__PURE__ */
|
|
216
|
+
return /* @__PURE__ */ f("tbody", { ...c, children: [
|
|
205
217
|
t.map((o) => {
|
|
206
|
-
const u = String(typeof a == "function" ? a(o) : o[a]),
|
|
218
|
+
const u = String(typeof a == "function" ? a(o) : o[a]), d = typeof r == "function" ? r(o) : u === r;
|
|
207
219
|
return n ? n(o) : /* @__PURE__ */ l(
|
|
208
|
-
|
|
220
|
+
W,
|
|
209
221
|
{
|
|
210
222
|
onClick: s,
|
|
211
223
|
rowClassName: e,
|
|
212
224
|
row: o,
|
|
213
|
-
selected:
|
|
225
|
+
selected: d
|
|
214
226
|
},
|
|
215
227
|
u
|
|
216
228
|
);
|
|
@@ -218,21 +230,21 @@ function $({
|
|
|
218
230
|
i
|
|
219
231
|
] });
|
|
220
232
|
}
|
|
221
|
-
|
|
222
|
-
|
|
233
|
+
D.displayName = "DataTableTBody";
|
|
234
|
+
function $() {
|
|
235
|
+
const t = S(y);
|
|
223
236
|
if (!t)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}, Q = x.div`
|
|
237
|
+
throw new Error("useTableSort must be used within a DataTableProvider");
|
|
238
|
+
return [
|
|
239
|
+
t.sort,
|
|
240
|
+
t.setSort
|
|
241
|
+
];
|
|
242
|
+
}
|
|
243
|
+
const Q = (t) => t ? t === "end" ? "flex-end" : "center" : "flex-start", U = F.div`
|
|
232
244
|
display: flex;
|
|
233
245
|
width: 100%;
|
|
234
246
|
flex-direction: ${(t) => t.align === "end" ? "row-reverse" : "row"};
|
|
235
|
-
justify-content: ${(t) =>
|
|
247
|
+
justify-content: ${(t) => Q(t.align)};
|
|
236
248
|
|
|
237
249
|
.sort-icon {
|
|
238
250
|
flex-grow: ${(t) => t.align === "end" ? "1" : "0"};
|
|
@@ -245,18 +257,20 @@ const O = (t) => {
|
|
|
245
257
|
transition: opacity 0.2s;
|
|
246
258
|
}
|
|
247
259
|
`;
|
|
248
|
-
function
|
|
260
|
+
function _({
|
|
249
261
|
field: t,
|
|
250
262
|
sorted: a,
|
|
251
263
|
ascending: e,
|
|
252
264
|
className: n,
|
|
253
265
|
onClick: s
|
|
254
266
|
}) {
|
|
267
|
+
if (t.visible === !1)
|
|
268
|
+
return null;
|
|
255
269
|
if (!t.sortable)
|
|
256
270
|
return /* @__PURE__ */ l(C, { field: t, className: n });
|
|
257
|
-
const { className:
|
|
271
|
+
const { className: r, ...i } = t.thProps ?? {}, c = p(
|
|
258
272
|
n,
|
|
259
|
-
|
|
273
|
+
r,
|
|
260
274
|
{ [`text-${t.align}`]: !!t.align }
|
|
261
275
|
), o = () => {
|
|
262
276
|
s({ field: t.field, ascending: a ? !e : !0 });
|
|
@@ -264,131 +278,147 @@ function j({
|
|
|
264
278
|
"bi-arrow-down": e,
|
|
265
279
|
"bi-arrow-up": !e
|
|
266
280
|
};
|
|
267
|
-
return /* @__PURE__ */ l("th", { ...i, className:
|
|
281
|
+
return /* @__PURE__ */ l("th", { ...i, className: p("sortable", c), scope: "col", onClick: o, children: /* @__PURE__ */ f(U, { sorted: a, align: t.align, children: [
|
|
268
282
|
/* @__PURE__ */ l("div", { className: "field-title", children: t.title }),
|
|
269
|
-
/* @__PURE__ */ l("div", { className:
|
|
283
|
+
/* @__PURE__ */ l("div", { className: p("me-1 sort-icon", u) })
|
|
270
284
|
] }) });
|
|
271
285
|
}
|
|
272
|
-
|
|
273
|
-
function
|
|
274
|
-
|
|
275
|
-
onChangeSort: a
|
|
286
|
+
_.displayName = "SortableTableTH";
|
|
287
|
+
function A({
|
|
288
|
+
onChangeSort: t
|
|
276
289
|
}) {
|
|
277
|
-
const
|
|
278
|
-
return /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { children:
|
|
279
|
-
|
|
290
|
+
const [a] = v(), [e] = $();
|
|
291
|
+
return /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { children: a.map((n, s) => /* @__PURE__ */ l(
|
|
292
|
+
_,
|
|
280
293
|
{
|
|
281
|
-
field:
|
|
282
|
-
sorted:
|
|
283
|
-
ascending:
|
|
284
|
-
className:
|
|
285
|
-
typeof
|
|
294
|
+
field: n,
|
|
295
|
+
sorted: e?.field === n.field,
|
|
296
|
+
ascending: e?.ascending,
|
|
297
|
+
className: p(
|
|
298
|
+
typeof n.className == "function" ? { [`text-${n.align}`]: !!n.align } : n.className
|
|
286
299
|
),
|
|
287
|
-
onClick:
|
|
300
|
+
onClick: t
|
|
288
301
|
},
|
|
289
|
-
|
|
302
|
+
s
|
|
290
303
|
)) }) });
|
|
291
304
|
}
|
|
292
|
-
|
|
293
|
-
function
|
|
305
|
+
A.displayName = "SortableTableHead";
|
|
306
|
+
function B({
|
|
307
|
+
onChangeSort: t
|
|
308
|
+
}) {
|
|
309
|
+
const [a] = v(), [e] = $();
|
|
310
|
+
return /* @__PURE__ */ l(A, { fields: a, currentSort: e, onChangeSort: t });
|
|
311
|
+
}
|
|
312
|
+
B.displayName = "SortableTableHeadWrapper";
|
|
313
|
+
function V({
|
|
294
314
|
className: t,
|
|
295
315
|
size: a,
|
|
296
316
|
responsive: e,
|
|
297
317
|
sticky: n,
|
|
298
318
|
data: s,
|
|
299
|
-
keyField:
|
|
319
|
+
keyField: r,
|
|
300
320
|
rowClassName: i,
|
|
301
|
-
renderRow:
|
|
321
|
+
renderRow: c,
|
|
302
322
|
onSelectRow: o,
|
|
303
323
|
selected: u,
|
|
304
|
-
tableHeadProps:
|
|
305
|
-
children:
|
|
306
|
-
tfoot:
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
...P
|
|
324
|
+
tableHeadProps: d,
|
|
325
|
+
children: b,
|
|
326
|
+
tfoot: m,
|
|
327
|
+
onChangeSort: h,
|
|
328
|
+
...N
|
|
310
329
|
}) {
|
|
311
|
-
const
|
|
330
|
+
const T = p("table", t, {
|
|
312
331
|
[`table-${a}`]: !!a
|
|
313
332
|
});
|
|
314
|
-
return /* @__PURE__ */
|
|
333
|
+
return /* @__PURE__ */ f(P, { className: T, responsive: e, sticky: n, ...N, children: [
|
|
315
334
|
/* @__PURE__ */ l(k, {}),
|
|
316
|
-
/* @__PURE__ */ l(
|
|
335
|
+
/* @__PURE__ */ l(B, { onChangeSort: h, ...d }),
|
|
317
336
|
!!s.length && /* @__PURE__ */ l(
|
|
318
|
-
|
|
337
|
+
D,
|
|
319
338
|
{
|
|
320
339
|
data: s,
|
|
321
|
-
keyField:
|
|
340
|
+
keyField: r,
|
|
322
341
|
rowClassName: i,
|
|
323
|
-
renderRow:
|
|
342
|
+
renderRow: c,
|
|
324
343
|
onSelectRow: o,
|
|
325
344
|
selected: u
|
|
326
345
|
}
|
|
327
346
|
),
|
|
328
|
-
|
|
329
|
-
|
|
347
|
+
b,
|
|
348
|
+
m
|
|
330
349
|
] });
|
|
331
350
|
}
|
|
332
|
-
|
|
351
|
+
V.displayName = "SortableTable";
|
|
352
|
+
function X({ nextSort: t }) {
|
|
353
|
+
const [, a] = $();
|
|
354
|
+
return q(() => {
|
|
355
|
+
console.log("setNextSort", t), a(t);
|
|
356
|
+
}, [t, a]), null;
|
|
357
|
+
}
|
|
358
|
+
function Y({
|
|
333
359
|
fields: t,
|
|
334
|
-
|
|
360
|
+
currentSort: a,
|
|
361
|
+
...e
|
|
335
362
|
}) {
|
|
336
|
-
return /* @__PURE__ */
|
|
363
|
+
return /* @__PURE__ */ f(x, { initialFields: t, initialSort: a, children: [
|
|
364
|
+
/* @__PURE__ */ l(X, { nextSort: a }),
|
|
365
|
+
/* @__PURE__ */ l(V, { ...e })
|
|
366
|
+
] });
|
|
337
367
|
}
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
function
|
|
368
|
+
Y.displayName = "StandaloneSortableTable";
|
|
369
|
+
const Z = [10, 25, 50, 100, 250, 500, 1e3];
|
|
370
|
+
function G({
|
|
341
371
|
value: t,
|
|
342
|
-
pageValues: a =
|
|
372
|
+
pageValues: a = Z,
|
|
343
373
|
size: e,
|
|
344
374
|
label: n,
|
|
345
375
|
className: s,
|
|
346
|
-
onChange:
|
|
376
|
+
onChange: r,
|
|
347
377
|
...i
|
|
348
378
|
}) {
|
|
349
|
-
const
|
|
379
|
+
const c = K(), o = (b) => r(Number(b.target.value)), u = s ?? p("form-select", { [`form-select-${e}`]: !!e }), d = p("input-group", {
|
|
350
380
|
[`input-group-${e}`]: !!e
|
|
351
381
|
});
|
|
352
|
-
return /* @__PURE__ */
|
|
353
|
-
/* @__PURE__ */ l("label", { className: "input-group-text", htmlFor:
|
|
382
|
+
return /* @__PURE__ */ f("div", { className: d, children: [
|
|
383
|
+
/* @__PURE__ */ l("label", { className: "input-group-text", htmlFor: c, children: n ?? "Rows" }),
|
|
354
384
|
/* @__PURE__ */ l(
|
|
355
385
|
"select",
|
|
356
386
|
{
|
|
357
387
|
className: u,
|
|
358
|
-
id:
|
|
388
|
+
id: c,
|
|
359
389
|
value: t,
|
|
360
390
|
onChange: o,
|
|
361
391
|
...i,
|
|
362
|
-
children: a.map((
|
|
392
|
+
children: a.map((b) => /* @__PURE__ */ l("option", { value: b, children: b }, b))
|
|
363
393
|
}
|
|
364
394
|
)
|
|
365
395
|
] }, t);
|
|
366
396
|
}
|
|
367
|
-
|
|
368
|
-
function
|
|
397
|
+
G.displayName = "RowsPerPage";
|
|
398
|
+
function z({
|
|
369
399
|
page: t,
|
|
370
400
|
rowsPerPage: a,
|
|
371
401
|
onChangePage: e,
|
|
372
402
|
count: n,
|
|
373
403
|
size: s,
|
|
374
|
-
showFirst:
|
|
404
|
+
showFirst: r,
|
|
375
405
|
showLast: i,
|
|
376
|
-
className:
|
|
406
|
+
className: c,
|
|
377
407
|
rowsPerPageProps: o,
|
|
378
408
|
...u
|
|
379
409
|
}) {
|
|
380
|
-
const
|
|
381
|
-
return /* @__PURE__ */
|
|
382
|
-
!!o && /* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */ l(
|
|
383
|
-
/* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */
|
|
384
|
-
/* @__PURE__ */
|
|
385
|
-
b,
|
|
386
|
-
"-",
|
|
410
|
+
const d = n === 0 ? 0 : t * a + 1, b = Math.min(t * a + a, n), m = a === 0 ? 0 : Math.floor((n - 1) / a), h = p("btn btn-link", { [`btn-${s}`]: !!s });
|
|
411
|
+
return /* @__PURE__ */ f("div", { className: p("row g-3 justify-content-end", c), ...u, children: [
|
|
412
|
+
!!o && /* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */ l(G, { ...o, value: a, size: s }) }),
|
|
413
|
+
/* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */ f("div", { className: "row g-3 flex-nowrap align-items-baseline", children: [
|
|
414
|
+
/* @__PURE__ */ f("div", { className: "col-auto", children: [
|
|
387
415
|
d,
|
|
416
|
+
"-",
|
|
417
|
+
b,
|
|
388
418
|
" of ",
|
|
389
419
|
n
|
|
390
420
|
] }),
|
|
391
|
-
|
|
421
|
+
r && /* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */ l(
|
|
392
422
|
"button",
|
|
393
423
|
{
|
|
394
424
|
className: h,
|
|
@@ -412,7 +442,7 @@ function Z({
|
|
|
412
442
|
"button",
|
|
413
443
|
{
|
|
414
444
|
className: h,
|
|
415
|
-
disabled: t >=
|
|
445
|
+
disabled: t >= m,
|
|
416
446
|
onClick: () => e(t + 1),
|
|
417
447
|
"aria-label": "Next page",
|
|
418
448
|
children: /* @__PURE__ */ l("span", { className: "bi-chevron-right", "aria-hidden": "true" })
|
|
@@ -422,8 +452,8 @@ function Z({
|
|
|
422
452
|
"button",
|
|
423
453
|
{
|
|
424
454
|
className: h,
|
|
425
|
-
disabled: t >=
|
|
426
|
-
onClick: () => e(
|
|
455
|
+
disabled: t >= m,
|
|
456
|
+
onClick: () => e(m),
|
|
427
457
|
"aria-label": "Last page",
|
|
428
458
|
children: /* @__PURE__ */ l("span", { className: "bi-chevron-bar-right", "aria-hidden": "true" })
|
|
429
459
|
}
|
|
@@ -431,41 +461,52 @@ function Z({
|
|
|
431
461
|
] }) })
|
|
432
462
|
] });
|
|
433
463
|
}
|
|
434
|
-
|
|
435
|
-
const z = x.col`
|
|
436
|
-
&.col-collapsed {
|
|
437
|
-
visibility: collapse;
|
|
438
|
-
}
|
|
439
|
-
`;
|
|
464
|
+
z.displayname = "TablePagination";
|
|
440
465
|
function k() {
|
|
441
|
-
const t =
|
|
442
|
-
return /* @__PURE__ */ l("colgroup", { children: t.map((a, e) => /* @__PURE__ */ l(
|
|
443
|
-
|
|
466
|
+
const [t] = v();
|
|
467
|
+
return /* @__PURE__ */ l("colgroup", { children: t.filter((a) => a.visible !== !1).map((a, e) => /* @__PURE__ */ l(
|
|
468
|
+
"col",
|
|
444
469
|
{
|
|
445
|
-
className:
|
|
470
|
+
className: a.colClassName,
|
|
446
471
|
span: a.colSpan ?? 1
|
|
447
472
|
},
|
|
448
473
|
e
|
|
449
474
|
)) });
|
|
450
475
|
}
|
|
451
476
|
k.displayName = "DataTableCols";
|
|
477
|
+
function nt(t) {
|
|
478
|
+
const a = S(y);
|
|
479
|
+
if (!a)
|
|
480
|
+
throw new Error("useField must be used within a DataTableProvider");
|
|
481
|
+
return [
|
|
482
|
+
a.fields.find((e) => e.id === t) ?? null,
|
|
483
|
+
a.updateField
|
|
484
|
+
];
|
|
485
|
+
}
|
|
486
|
+
function lt() {
|
|
487
|
+
const t = S(y);
|
|
488
|
+
if (!t)
|
|
489
|
+
throw new Error("useTableContext must be used within a DataTableProvider");
|
|
490
|
+
return t;
|
|
491
|
+
}
|
|
452
492
|
export {
|
|
453
|
-
|
|
493
|
+
O as DataTable,
|
|
454
494
|
k as DataTableCols,
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
495
|
+
y as DataTableContext,
|
|
496
|
+
x as DataTableProvider,
|
|
497
|
+
W as DataTableRow,
|
|
498
|
+
D as DataTableTBody,
|
|
458
499
|
C as DataTableTH,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
500
|
+
R as DataTableWithContext,
|
|
501
|
+
G as RowsPerPage,
|
|
502
|
+
V as SortableTable,
|
|
503
|
+
A as SortableTableHead,
|
|
504
|
+
_ as SortableTableTH,
|
|
505
|
+
Y as StandaloneSortableTable,
|
|
506
|
+
z as TablePagination,
|
|
466
507
|
nt as useField,
|
|
467
|
-
lt as
|
|
468
|
-
|
|
469
|
-
|
|
508
|
+
lt as useTableContext,
|
|
509
|
+
v as useTableFields,
|
|
510
|
+
$ as useTableSort
|
|
470
511
|
};
|
|
471
512
|
//# sourceMappingURL=index.es.js.map
|