@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.
Files changed (68) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +94 -4
  3. package/dist/DataTable.d.ts +1 -1
  4. package/dist/DataTableCell.d.ts +6 -2
  5. package/dist/DataTableCols.d.ts +1 -1
  6. package/dist/DataTableContext.d.ts +10 -0
  7. package/dist/DataTableProvider.d.ts +12 -0
  8. package/dist/DataTableTH.d.ts +1 -1
  9. package/dist/SortableTable.d.ts +1 -1
  10. package/dist/SortableTableHead.d.ts +1 -1
  11. package/dist/SortableTableHeadWrapper.d.ts +9 -0
  12. package/dist/SortableTableTH.d.ts +1 -1
  13. package/dist/StandaloneDataTable.d.ts +6 -0
  14. package/dist/StandaloneDataTableRow.d.ts +9 -0
  15. package/dist/StandaloneSortHelper.d.ts +5 -0
  16. package/dist/StandaloneSortableTable.d.ts +6 -0
  17. package/dist/Table.d.ts +5 -4
  18. package/dist/index.cjs.js +4 -8
  19. package/dist/index.cjs.js.map +1 -1
  20. package/dist/index.d.ts +12 -8
  21. package/dist/index.es.js +239 -198
  22. package/dist/index.es.js.map +1 -1
  23. package/dist/types.d.ts +4 -3
  24. package/dist/useField.d.ts +6 -0
  25. package/dist/useTableContext.d.ts +2 -0
  26. package/dist/useTableFields.d.ts +9 -0
  27. package/dist/useTableSort.d.ts +9 -0
  28. package/package.json +3 -3
  29. package/src/DataTable.tsx +34 -11
  30. package/src/DataTableCell.tsx +33 -28
  31. package/src/DataTableCols.tsx +11 -18
  32. package/src/DataTableContext.ts +13 -0
  33. package/src/DataTableHead.tsx +6 -7
  34. package/src/DataTableProvider.tsx +62 -0
  35. package/src/DataTableRow.tsx +8 -7
  36. package/src/DataTableTBody.tsx +1 -3
  37. package/src/DataTableTH.tsx +4 -3
  38. package/src/RowsPerPage.tsx +2 -4
  39. package/src/SortableTable.tsx +36 -12
  40. package/src/SortableTableHead.tsx +9 -9
  41. package/src/SortableTableHeadWrapper.tsx +20 -0
  42. package/src/SortableTableTH.tsx +4 -4
  43. package/src/StandaloneDataTable.tsx +16 -0
  44. package/src/StandaloneDataTableRow.tsx +42 -0
  45. package/src/StandaloneSortHelper.tsx +15 -0
  46. package/src/StandaloneSortableTable.tsx +21 -0
  47. package/src/Table.tsx +49 -44
  48. package/src/TablePagination.tsx +1 -3
  49. package/src/index.tsx +21 -15
  50. package/src/types.ts +127 -126
  51. package/src/useField.ts +19 -0
  52. package/src/useTableContext.ts +10 -0
  53. package/src/useTableFields.ts +20 -0
  54. package/src/useTableSort.ts +20 -0
  55. package/test/Main.tsx +37 -0
  56. package/test/TableColumnsHandler.tsx +9 -9
  57. package/test/TestTable.tsx +51 -46
  58. package/test/data.ts +232 -232
  59. package/test/index.tsx +11 -11
  60. package/test/tableFields.tsx +11 -3
  61. package/test/utils.ts +19 -0
  62. package/tsconfig.json +1 -0
  63. package/dist/DataTableWithContext.d.ts +0 -2
  64. package/dist/SortableTableWithContext.d.ts +0 -2
  65. package/dist/TableProvider.d.ts +0 -17
  66. package/src/DataTableWithContext.tsx +0 -41
  67. package/src/SortableTableWithContext.tsx +0 -44
  68. package/src/TableProvider.tsx +0 -77
package/dist/index.es.js CHANGED
@@ -1,56 +1,53 @@
1
- import { jsx as l, jsxs as p } from "react/jsx-runtime";
2
- import A, { createContext as B, useState as V, useCallback as v, useMemo as W, useContext as g, createElement as G, useId as I } from "react";
3
- import x from "@emotion/styled";
4
- const N = B(null);
5
- function S({ children: t, initialFields: a = [] }) {
6
- const [e, n] = V(a), s = v((o) => {
7
- n(o);
8
- }, []), c = v((o, u) => {
9
- const b = e.map((d) => d.id === o ? { ...d, ...u } : d);
10
- n(b);
11
- }, [e]), i = v((o) => e.find((u) => u.id === o), [e]), r = W(
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: e,
14
- setFields: s,
15
- updateField: c,
16
- getField: i
25
+ fields: n,
26
+ setFields: c,
27
+ sort: r,
28
+ setSort: o,
29
+ getField: d,
30
+ updateField: u
17
31
  }),
18
- [e, s, c, i]
32
+ [n, c, r, o, u, d]
19
33
  );
20
- return /* @__PURE__ */ l(N.Provider, { value: r, children: t });
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
- function H(t) {
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 = H(t[a])) && (n && (n += " "), n += 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 m() {
50
- for (var t, a, e = 0, n = "", s = arguments.length; e < s; e++) (t = arguments[e]) && (a = H(t)) && (n && (n += " "), n += 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 D = x.table`
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
- `, F = A.forwardRef(
66
- function({
67
- sticky: a,
68
- responsive: e,
69
- children: n,
70
- className: s,
71
- ...c
72
- }, i) {
73
- if (e) {
74
- const r = m(s, {
75
- "table-responsive": e === !0,
76
- [`table-responsive-${e}`]: e !== !0
77
- });
78
- return /* @__PURE__ */ l("div", { className: r, children: /* @__PURE__ */ l(D, { ref: i, ...c, children: n }) });
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
- const s = m({ [`text-${t.align}`]: !!t.align }, a);
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 R({ ...t }) {
94
- const a = y();
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: m(
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
- R.displayName = "DataTableHead";
108
- function L({
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: c,
122
+ keyField: r,
115
123
  rowClassName: i,
116
- renderRow: r,
124
+ renderRow: c,
117
125
  onSelectRow: o,
118
126
  selected: u,
119
- tableHeadProps: b,
120
- children: d,
121
- tfoot: f,
127
+ tableHeadProps: d,
128
+ children: b,
129
+ tfoot: m,
122
130
  ...h
123
131
  }) {
124
- const T = m("table", t, {
132
+ const N = p("table", t, {
125
133
  [`table-${a}`]: !!a
126
134
  });
127
- return /* @__PURE__ */ p(F, { sticky: n, responsive: e, className: T, ...h, children: [
135
+ return /* @__PURE__ */ f(P, { sticky: n, responsive: e, className: N, ...h, children: [
128
136
  /* @__PURE__ */ l(k, {}),
129
- /* @__PURE__ */ l(R, { ...b }),
137
+ /* @__PURE__ */ l(j, { ...d }),
130
138
  !!s.length && /* @__PURE__ */ l(
131
- $,
139
+ D,
132
140
  {
133
141
  data: s,
134
- keyField: c,
142
+ keyField: r,
135
143
  rowClassName: i,
136
- renderRow: r,
144
+ renderRow: c,
137
145
  onSelectRow: o,
138
146
  selected: u
139
147
  }
140
148
  ),
141
- d,
142
- f
149
+ b,
150
+ m
143
151
  ] });
144
152
  }
145
- function q({
153
+ R.displayName = "DataTable";
154
+ function O({
146
155
  fields: t,
147
156
  ...a
148
157
  }) {
149
- return /* @__PURE__ */ l(S, { initialFields: t, children: /* @__PURE__ */ l(L, { ...a }) });
158
+ return /* @__PURE__ */ l(x, { initialFields: t, children: /* @__PURE__ */ l(R, { ...a }) });
150
159
  }
151
- q.displayName = "DataTable";
152
- function K({ field: t, row: a, className: e, as: n, ...s }) {
153
- const c = m(
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 G(
169
+ return L(
159
170
  n ?? t.as ?? "td",
160
171
  {
161
- className: c,
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
- function w({
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: c,
188
+ onClick: r,
177
189
  ...i
178
190
  }) {
179
- const r = y(), o = (b) => {
180
- c?.(n, b);
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: m({ "table-active": e }, t, u),
198
+ className: p({ "table-active": e }, t, u),
187
199
  onClick: o,
188
200
  ...i,
189
- children: r.map((b, d) => /* @__PURE__ */ l(K, { field: b, row: n }, b?.id ?? d))
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
- w.displayName = "DataTableRow";
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: c = "",
212
+ selected: r = "",
201
213
  children: i,
202
- ...r
214
+ ...c
203
215
  }) {
204
- return /* @__PURE__ */ p("tbody", { ...r, children: [
216
+ return /* @__PURE__ */ f("tbody", { ...c, children: [
205
217
  t.map((o) => {
206
- const u = String(typeof a == "function" ? a(o) : o[a]), b = typeof c == "function" ? c(o) : u === c;
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
- w,
220
+ W,
209
221
  {
210
222
  onClick: s,
211
223
  rowClassName: e,
212
224
  row: o,
213
- selected: b
225
+ selected: d
214
226
  },
215
227
  u
216
228
  );
@@ -218,21 +230,21 @@ function $({
218
230
  i
219
231
  ] });
220
232
  }
221
- $.displayName = "DataTableTBody";
222
- const O = (t) => {
233
+ D.displayName = "DataTableTBody";
234
+ function $() {
235
+ const t = S(y);
223
236
  if (!t)
224
- return "flex-start";
225
- switch (t) {
226
- case "end":
227
- return "flex-end";
228
- default:
229
- return "center";
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) => O(t.align)};
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 j({
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: c, ...i } = t.thProps ?? {}, r = m(
271
+ const { className: r, ...i } = t.thProps ?? {}, c = p(
258
272
  n,
259
- c,
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: m("sortable", r), scope: "col", onClick: o, children: /* @__PURE__ */ p(Q, { sorted: a, align: t.align, children: [
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: m("me-1 sort-icon", u) })
283
+ /* @__PURE__ */ l("div", { className: p("me-1 sort-icon", u) })
270
284
  ] }) });
271
285
  }
272
- j.displayName = "SortableTableTH";
273
- function E({
274
- currentSort: t,
275
- onChangeSort: a
286
+ _.displayName = "SortableTableTH";
287
+ function A({
288
+ onChangeSort: t
276
289
  }) {
277
- const e = y(), { field: n, ascending: s } = t;
278
- return /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { children: e.map((c, i) => /* @__PURE__ */ l(
279
- j,
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: c,
282
- sorted: n === c.field,
283
- ascending: s,
284
- className: m(
285
- typeof c.className == "function" ? { [`text-${c.align}`]: !!c.align } : c.className
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: a
300
+ onClick: t
288
301
  },
289
- i
302
+ s
290
303
  )) }) });
291
304
  }
292
- E.displayName = "SortableTableHead";
293
- function U({
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: c,
319
+ keyField: r,
300
320
  rowClassName: i,
301
- renderRow: r,
321
+ renderRow: c,
302
322
  onSelectRow: o,
303
323
  selected: u,
304
- tableHeadProps: b,
305
- children: d,
306
- tfoot: f,
307
- currentSort: h,
308
- onChangeSort: T,
309
- ...P
324
+ tableHeadProps: d,
325
+ children: b,
326
+ tfoot: m,
327
+ onChangeSort: h,
328
+ ...N
310
329
  }) {
311
- const _ = m("table", t, {
330
+ const T = p("table", t, {
312
331
  [`table-${a}`]: !!a
313
332
  });
314
- return /* @__PURE__ */ p(F, { className: _, responsive: e, sticky: n, ...P, children: [
333
+ return /* @__PURE__ */ f(P, { className: T, responsive: e, sticky: n, ...N, children: [
315
334
  /* @__PURE__ */ l(k, {}),
316
- /* @__PURE__ */ l(E, { currentSort: h, onChangeSort: T, ...b }),
335
+ /* @__PURE__ */ l(B, { onChangeSort: h, ...d }),
317
336
  !!s.length && /* @__PURE__ */ l(
318
- $,
337
+ D,
319
338
  {
320
339
  data: s,
321
- keyField: c,
340
+ keyField: r,
322
341
  rowClassName: i,
323
- renderRow: r,
342
+ renderRow: c,
324
343
  onSelectRow: o,
325
344
  selected: u
326
345
  }
327
346
  ),
328
- d,
329
- f
347
+ b,
348
+ m
330
349
  ] });
331
350
  }
332
- function X({
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
- ...a
360
+ currentSort: a,
361
+ ...e
335
362
  }) {
336
- return /* @__PURE__ */ l(S, { initialFields: t, children: /* @__PURE__ */ l(U, { ...a }) });
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
- X.displayName = "SortableTable";
339
- const Y = [10, 25, 50, 100, 250, 500, 1e3];
340
- function M({
368
+ Y.displayName = "StandaloneSortableTable";
369
+ const Z = [10, 25, 50, 100, 250, 500, 1e3];
370
+ function G({
341
371
  value: t,
342
- pageValues: a = Y,
372
+ pageValues: a = Z,
343
373
  size: e,
344
374
  label: n,
345
375
  className: s,
346
- onChange: c,
376
+ onChange: r,
347
377
  ...i
348
378
  }) {
349
- const r = I(), o = (d) => c(Number(d.target.value)), u = s ?? m("form-select", { [`form-select-${e}`]: !!e }), b = m("input-group", {
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__ */ p("div", { className: b, children: [
353
- /* @__PURE__ */ l("label", { className: "input-group-text", htmlFor: r, children: n ?? "Rows" }),
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: r,
388
+ id: c,
359
389
  value: t,
360
390
  onChange: o,
361
391
  ...i,
362
- children: a.map((d) => /* @__PURE__ */ l("option", { value: d, children: d }, d))
392
+ children: a.map((b) => /* @__PURE__ */ l("option", { value: b, children: b }, b))
363
393
  }
364
394
  )
365
395
  ] }, t);
366
396
  }
367
- M.displayName = "RowsPerPage";
368
- function Z({
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: c,
404
+ showFirst: r,
375
405
  showLast: i,
376
- className: r,
406
+ className: c,
377
407
  rowsPerPageProps: o,
378
408
  ...u
379
409
  }) {
380
- const b = n === 0 ? 0 : t * a + 1, d = Math.min(t * a + a, n), f = a === 0 ? 0 : Math.floor((n - 1) / a), h = m("btn btn-link", { [`btn-${s}`]: !!s });
381
- return /* @__PURE__ */ p("div", { className: m("row g-3 justify-content-end", r), ...u, children: [
382
- !!o && /* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */ l(M, { ...o, value: a, size: s }) }),
383
- /* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */ p("div", { className: "row g-3 flex-nowrap align-items-baseline", children: [
384
- /* @__PURE__ */ p("div", { className: "col-auto", children: [
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
- c && /* @__PURE__ */ l("div", { className: "col-auto", children: /* @__PURE__ */ l(
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 >= f,
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 >= f,
426
- onClick: () => e(f),
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
- Z.displayname = "TablePagination";
435
- const z = x.col`
436
- &.col-collapsed {
437
- visibility: collapse;
438
- }
439
- `;
464
+ z.displayname = "TablePagination";
440
465
  function k() {
441
- const t = y();
442
- return /* @__PURE__ */ l("colgroup", { children: t.map((a, e) => /* @__PURE__ */ l(
443
- z,
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: m(a.colClassName, { "col-collapsed": a.collapse }),
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
- q as DataTable,
493
+ O as DataTable,
454
494
  k as DataTableCols,
455
- S as DataTableProvider,
456
- w as DataTableRow,
457
- $ as DataTableTBody,
495
+ y as DataTableContext,
496
+ x as DataTableProvider,
497
+ W as DataTableRow,
498
+ D as DataTableTBody,
458
499
  C as DataTableTH,
459
- L as DataTableWithContext,
460
- M as RowsPerPage,
461
- X as SortableTable,
462
- E as SortableTableHead,
463
- j as SortableTableTH,
464
- U as SortableTableWithContext,
465
- Z as TablePagination,
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 useHasTableFieldsContext,
468
- J as useTableContext,
469
- y as useTableFields
508
+ lt as useTableContext,
509
+ v as useTableFields,
510
+ $ as useTableSort
470
511
  };
471
512
  //# sourceMappingURL=index.es.js.map