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