@propellerads/table 7.0.1 → 8.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/dist/index.js CHANGED
@@ -1,496 +1,471 @@
1
- import { ArrowDown as e, ArrowUp as t, Color as n, Size as r } from "@propellerads/icon";
2
- import i from "@propellerads/checkbox";
3
- import { Fragment as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
4
- import { flexRender as u, getCoreRowModel as ee, getExpandedRowModel as te, getPaginationRowModel as ne, getSortedRowModel as re, useReactTable as ie } from "@tanstack/react-table";
5
- import d, { css as f, keyframes as p } from "styled-components";
6
- import { black as m, fontNormal as ae, gray80 as h, gray95 as g, spacing as _, white as v } from "@propellerads/stylevariables";
7
- import { jsx as y, jsxs as b } from "react/jsx-runtime";
1
+ import e from "@propellerads/checkbox";
2
+ import { ArrowDown as t, ArrowUp as n, Color as r, Size as i } from "@propellerads/icon";
3
+ import { columnResizingFeature as a, columnSizingFeature as o, columnVisibilityFeature as s, createExpandedRowModel as c, createPaginatedRowModel as l, createSortedRowModel as u, flexRender as d, rowExpandingFeature as f, rowPaginationFeature as p, rowSelectionFeature as m, rowSortingFeature as ee, sortFn_alphanumeric as te, sortFn_alphanumericCaseSensitive as h, sortFn_basic as g, sortFn_datetime as _, sortFn_text as v, sortFn_textCaseSensitive as y, tableFeatures as b, useTable as ne } from "@tanstack/react-table";
4
+ import { Fragment as re, forwardRef as x, useCallback as S, useEffect as C, useMemo as w, useRef as T, useState as E } from "react";
5
+ import { clsx as D } from "clsx";
6
+ import { Fragment as O, jsx as k, jsxs as A } from "react/jsx-runtime";
7
+ import './index.css';export * from "@tanstack/react-table";
8
+ // src/cn.ts
9
+ var j = (...e) => D(e), M = b({
10
+ rowSortingFeature: ee,
11
+ rowSelectionFeature: m,
12
+ rowExpandingFeature: f,
13
+ rowPaginationFeature: p,
14
+ columnVisibilityFeature: s,
15
+ columnSizingFeature: o,
16
+ columnResizingFeature: a,
17
+ sortedRowModel: u(),
18
+ expandedRowModel: c(),
19
+ sortFns: {
20
+ alphanumeric: te,
21
+ alphanumericCaseSensitive: h,
22
+ basic: g,
23
+ datetime: _,
24
+ text: v,
25
+ textCaseSensitive: y
26
+ }
27
+ }), N = b({
28
+ ...M,
29
+ paginatedRowModel: l()
30
+ }), P = x(({ className: e, containerProps: t, ...n }, r) => /* @__PURE__ */ k("div", {
31
+ ...t,
32
+ className: j("table-content", t?.className),
33
+ children: /* @__PURE__ */ k("table", {
34
+ ref: r,
35
+ className: j("table", e),
36
+ ...n
37
+ })
38
+ }));
39
+ P.displayName = "TableRoot";
40
+ var F = x(({ className: e, ...t }, n) => /* @__PURE__ */ k("thead", {
41
+ ref: n,
42
+ className: j("table-header", e),
43
+ ...t
44
+ }));
45
+ F.displayName = "TableHeader";
46
+ var I = x(({ className: e, ...t }, n) => /* @__PURE__ */ k("tbody", {
47
+ ref: n,
48
+ className: j("table-body", e),
49
+ ...t
50
+ }));
51
+ I.displayName = "TableBody";
52
+ var L = x(({ className: e, ...t }, n) => /* @__PURE__ */ k("tfoot", {
53
+ ref: n,
54
+ className: j("table-footer", e),
55
+ ...t
56
+ }));
57
+ L.displayName = "TableFooter";
58
+ var R = x(({ className: e, ...t }, n) => /* @__PURE__ */ k("tr", {
59
+ ref: n,
60
+ className: j("table-row", e),
61
+ ...t
62
+ }));
63
+ R.displayName = "TableRow";
64
+ var z = x(({ className: e, ...t }, n) => /* @__PURE__ */ k("th", {
65
+ ref: n,
66
+ className: j("table-header-cell", e),
67
+ ...t
68
+ }));
69
+ z.displayName = "TableHead";
70
+ var B = x(({ className: e, ...t }, n) => /* @__PURE__ */ k("td", {
71
+ ref: n,
72
+ className: j("table-cell", e),
73
+ ...t
74
+ }));
75
+ B.displayName = "TableCell";
76
+ var V = x(({ className: e, ...t }, n) => /* @__PURE__ */ k("caption", {
77
+ ref: n,
78
+ className: j("table-caption", e),
79
+ ...t
80
+ }));
81
+ V.displayName = "TableCaption";
8
82
  // src/propsGetter.tsx
9
- var x = (e) => e.column.columnDef.meta?.align, oe = (e) => e.column.columnDef.meta?.align, S = p`
10
- from {
11
- background-position-x: 0;
12
- }
13
- 50% {
14
- background-position-x: 100%;
15
- }
16
- 100% {
17
- background-position-x: 0;
18
- }
19
- `, se = d.div`
20
- display: block;
21
- position: absolute;
22
- left: 0;
23
- right: 0;
24
- top: 0;
25
- bottom: 0;
26
- background: rgba(255, 255, 255, 0.8);
27
- transition: all 0.3s ease;
28
- z-index: -1;
29
- opacity: 0;
30
- pointer-events: none;
31
-
32
- ${({ $isLoading: e }) => e && f`
33
- opacity: 1;
34
- z-index: 2;
35
- pointer-events: all;
36
- `}
37
- `, ce = d.div`
38
- position: absolute;
39
- display: block;
40
- text-align: center;
41
- width: 100%;
42
- top: 50%;
43
- left: 0;
44
- color: rgba(0, 0, 0, 0.6);
45
- transform: translateY(-52%);
46
- transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
47
- `, le = d.div`
48
- position: relative;
49
- overflow: hidden;
50
-
51
- &::before {
52
- bottom: 10px;
53
- content: '';
54
- opacity: 0;
55
- pointer-events: none;
56
- position: absolute;
57
- width: 10px;
58
- height: 100%;
59
- top: 0;
60
- left: -10px;
61
- box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.2);
62
- transition: 0.3s opacity;
63
- }
64
-
65
- &::after {
66
- bottom: 10px;
67
- content: '';
68
- opacity: 0;
69
- pointer-events: none;
70
- width: 10px;
71
- height: 100%;
72
- position: absolute;
73
- top: 0;
74
- right: -10px;
75
- box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.2);
76
- transition: 0.3s opacity;
77
- }
78
-
79
- &.shadow_left {
80
- &::before {
81
- opacity: 1 !important;
82
- }
83
- }
84
-
85
- &.shadow_right {
86
- &::after {
87
- opacity: 1 !important;
88
- }
89
- }
90
- `, ue = d.div`
91
- font-size: ${ae}px;
92
- position: relative;
93
- display: flex;
94
- flex-direction: column;
95
- border: 0;
96
- `, de = d.div`
97
- display: block;
98
- max-width: 100%;
99
- overflow-x: scroll;
100
- overflow-y: hidden;
101
- `, fe = d.div`
102
- flex: auto 1;
103
- display: flex;
104
- flex-direction: column;
105
- align-items: stretch;
106
- border-collapse: collapse;
107
- `, C = d.div`
108
- display: inline-flex;
109
- `, w = d.div`
110
- flex: ${({ $size: e }) => e ?? 1} 0 auto;
111
- width: ${({ $size: e }) => e ?? 50}px;
112
- min-width: 0;
113
- white-space: nowrap;
114
- text-overflow: ellipsis;
115
- line-height: 1.3rem;
116
- padding: 7px 4px;
117
- overflow: hidden;
118
-
119
- ${({ $align: e }) => e && f`
120
- text-align: ${e};
121
- `}
122
- `, T = d.div`
123
- width: 100%;
124
- height: ${_ * 4}px;
125
- background: linear-gradient(to left, ${g}, ${v}, ${g});
126
- background-size: 200% 200%;
127
- animation: ${S} 1.6s linear infinite;
128
- `, E = d.div`
129
- flex: ${({ $size: e }) => e ?? 1} 0 auto;
130
- width: ${({ $size: e }) => e ?? 50}px;
131
- min-width: 0;
132
- padding: 0 4px;
133
- line-height: normal;
134
- position: relative;
135
- transition: box-shadow 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0s;
136
- color: rgb(0, 0, 0);
137
- font-weight: 500;
138
- outline: none;
139
-
140
- ${({ $align: e }) => e && f`
141
- text-align: ${e};
142
- `}
143
- `, pe = d.div`
144
- flex: 1 0 auto;
145
- display: flex;
146
- flex-direction: column;
147
- user-select: none;
148
-
149
- ${E}, ${w} {
150
- padding: 0 4px;
151
- line-height: normal;
152
- position: relative;
153
- transition: box-shadow 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
154
- color: ${m};
155
- font-weight: 500;
156
- outline: none;
157
- }
158
- `, D = d.div`
159
- display: flex;
160
- flex: 1 0 auto;
161
- box-shadow: inset 0 -1px 0 0 ${g};
162
- min-width: 100%;
163
- width: max-content;
164
- `, O = d.div`
165
- display: flex;
166
- flex: 1 0 auto;
167
- min-width: 0;
168
- padding: 0;
169
- align-items: center;
170
- `, me = d.div`
171
- border-top: 1px solid ${h};
172
- margin-top: ${_ * 2}px;
173
- min-width: 100%;
174
- width: max-content;
175
- `, k = d.div`
176
- background: ${g};
177
- flex: 1 0 auto;
178
- display: flex;
179
- flex-direction: column;
180
- `, A = d.div`
181
- display: inline-block;
182
- position: absolute;
183
- right: 5px;
184
- top: 0;
185
- z-index: 1;
186
- touch-action: none;
187
-
188
- &:after {
189
- content: '↔';
190
- position: absolute;
191
- right: 0;
192
- top: 0;
193
- }
194
- `, j = {
83
+ var H = (e) => e.column.columnDef.meta?.align, U = (e) => e.column.columnDef.meta?.align, W = {
195
84
  Top: "top",
196
85
  Bottom: "bottom"
197
- }, he = (e, t, n, r, i) => ({
198
- loadingColumns: s(() => e && t ? r.map((e) => ({
199
- ...e,
200
- cell: () => /* @__PURE__ */ y(i, {})
201
- })) : [], [
202
- r,
203
- t,
204
- e
205
- ]),
206
- loadingData: s(() => {
207
- if (e && t && r && r.length > 0) {
208
- let e = {}, t = [];
86
+ }, G = () => typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches, K = (e) => {
87
+ let t = e.join("\0"), [n, r] = E(t), [i, a] = E(e), [o, s] = E([]);
88
+ if (t !== n) {
89
+ let n = G() ? [] : i.filter((t) => !e.includes(t));
90
+ r(t), a(e), s((t) => [...t.filter((t) => !e.includes(t)), ...n]);
91
+ }
92
+ return {
93
+ closing: o,
94
+ finish: S((e) => {
95
+ s((t) => t.filter((t) => t !== e));
96
+ }, [])
97
+ };
98
+ }, q = (e, t, n, r, i) => {
99
+ let a = e && t;
100
+ return {
101
+ loadingColumns: w(() => a ? r.map((e) => ({
102
+ ...e,
103
+ enableSorting: !1,
104
+ cell: () => /* @__PURE__ */ k(i, {})
105
+ })) : [], [
106
+ r,
107
+ a,
108
+ i
109
+ ]),
110
+ loadingData: w(() => {
111
+ if (!a || r.length === 0) return [];
112
+ let e = {};
209
113
  for (let t = 0; t < r.length; t += 1) e[`empty_${t}`] = "";
210
- for (let r = 0; r < n; r += 1) t.push(e);
211
- return t;
212
- }
213
- return [];
214
- }, [
215
- r,
216
- t,
217
- n,
218
- e
219
- ])
220
- }), M = {
114
+ return Array.from({ length: n }, () => e);
115
+ }, [
116
+ r,
117
+ a,
118
+ n
119
+ ])
120
+ };
121
+ }, J = {
221
122
  Left: "shadow_left",
222
123
  Right: "shadow_right"
223
- }, N = (e, t) => {
124
+ }, ie = (e, t) => {
224
125
  let { classList: n } = e;
225
- n.remove(M.Left, M.Right), n.add(...t);
226
- }, P = (e, t) => {
126
+ n.remove(J.Left, J.Right), n.add(...t);
127
+ }, Y = (e, t) => {
227
128
  if (!e || !t) return;
228
129
  let n = e.getBoundingClientRect(), r = t.getBoundingClientRect(), i = [], a = Math.floor(n.left), o = Math.floor(n.right), s = Math.floor(r.left), c = Math.floor(r.right);
229
- a < s && i.push(M.Left), o > c && i.push(M.Right), N(t, i);
230
- }, ge = (e, t) => {
231
- o(() => {
130
+ a < s && i.push(J.Left), o > c && i.push(J.Right), ie(t, i);
131
+ }, ae = (e, t) => {
132
+ C(() => {
232
133
  let n = !1, r = () => {
233
134
  n ||= (window.requestAnimationFrame(() => {
234
- P(e.current, t.current), n = !1;
135
+ Y(e.current, t.current), n = !1;
235
136
  }), !0);
236
137
  };
237
- return P(e.current, t.current), e?.current?.addEventListener("mousewheel", r), window.addEventListener("resize", r), () => {
138
+ return Y(e.current, t.current), e?.current?.addEventListener("mousewheel", r), window.addEventListener("resize", r), () => {
238
139
  e?.current?.removeEventListener("mousewheel", r), window.removeEventListener("resize", r);
239
140
  };
240
141
  }, [e.current, t.current]);
241
- }, F = () => !0, I = {}, L = () => ({}), _e = (e) => {
142
+ }, oe = 0, se = 10, X = (e, t) => typeof e == "function" ? e(t) : e, ce = () => /* @__PURE__ */ k("div", { className: "table-placeholder" }), le = (e) => {
242
143
  let { subRows: t } = e;
243
- if (Array.isArray(t)) return t;
244
- }, R = {
245
- hasDefaultPagination: !1,
246
- isLoading: !1,
247
- footerPlacement: [],
248
- loadingMessage: "loading...",
249
- labelPerPage: "Show rows",
250
- parentElementId: "parent-element",
251
- tableContentId: "",
252
- showLoadingState: !1,
253
- LoadingCellComponent: T,
254
- getRowPreProps: L,
255
- isEnableRowSelect: F,
256
- selectColumnProps: I,
257
- noDataMessage: ""
258
- }, ve = 0, z = 10, ye = (i) => {
259
- let a = i.column.getIsSorted(), o = u(i.column.columnDef.header, i.getContext());
260
- return a === "desc" ? /* @__PURE__ */ b(C, { children: [o, /* @__PURE__ */ y(t, {
261
- size: r.Small,
262
- color: n.GrayDark
263
- })] }) : a === "asc" ? /* @__PURE__ */ b(C, { children: [o, /* @__PURE__ */ y(e, {
264
- size: r.Small,
265
- color: n.GrayDark
266
- })] }) : o;
267
- }, be = (e) => e.column.getCanResize() ? /* @__PURE__ */ y(A, {
268
- onMouseDown: e.getResizeHandler(),
269
- onTouchStart: e.getResizeHandler(),
270
- onClick: (e) => {
271
- e.preventDefault(), e.stopPropagation();
272
- }
273
- }) : null, B = ({ columns: e, data: t, totalItems: n, fetchData: r, controlledPagination: d, initialState: f, isLoading: p = R.isLoading, loadingMessage: m = R.loadingMessage, labelPerPage: ae = R.labelPerPage, footerPlacement: h = R.footerPlacement, onSortedChange: g, hasDefaultPagination: _ = R.hasDefaultPagination, onSelectRowsChange: v, parentElementId: S = R.parentElementId, tableContentId: C = R.tableContentId, LoadingCellComponent: T = R.LoadingCellComponent, PaginationComponent: A, getRowPreProps: M = L, getRowId: N, getSubRows: P = _e, getTableProps: F, getHeaderGroupProps: I, getHeaderProps: B, getRowProps: V, getCellProps: H, getFooterProps: U, getFooterGroupProps: W, showLoadingState: G = R.showLoadingState, noDataMessage: xe = R.noDataMessage, rowSubComponent: K, isEnableRowSelect: q = R.isEnableRowSelect, selectColumnProps: Se = R.selectColumnProps }) => {
274
- let J = s(() => e, [e]), Y = G && p, X = !Y && typeof v == "function", Ce = typeof g == "function", Z = !!(r && d && Object.keys(d).length > 0);
275
- if (_ && Z) throw Error("You have to pass either hasDefaultPagination true boolean prop or pass fetchData callback and controlledPagination data");
276
- if (Z && d?.pageCount === void 0) throw Error("You have to pass pageCount in controlledPagination data");
277
- let [we, Te] = l([]), [Ee, De] = l({}), [Oe, ke] = l({
278
- pageIndex: ve,
279
- pageSize: z
280
- }), [Ae, je] = l(f?.columnVisibility ?? {});
281
- o(() => {
282
- f?.columnVisibility && je(f.columnVisibility);
283
- }, [f?.columnVisibility]);
284
- let Q = s(() => ({
285
- id: "selection",
286
- enableSorting: !1,
287
- header: ({ table: e }) => {
288
- let t = e.getRowModel().rows.map((e) => e.original).filter(q).length === 0;
289
- return /* @__PURE__ */ y(i, {
290
- onChange: e.toggleAllPageRowsSelected,
291
- isChecked: e.getIsAllPageRowsSelected(),
292
- isIndeterminate: e.getIsSomePageRowsSelected(),
293
- isDisabled: t,
294
- "aria-label": "Select all rows"
295
- });
296
- },
297
- cell: ({ row: e }) => {
298
- let t = q(e.original);
299
- return /* @__PURE__ */ y(i, {
300
- onChange: e.toggleSelected,
301
- isDisabled: !t,
302
- isChecked: t && e.getIsSelected(),
303
- "aria-label": "Select row"
304
- });
305
- },
306
- ...Se
307
- }), [q, Se]), { loadingColumns: Me, loadingData: Ne } = he(G, p, Z ? d?.pageSize ?? z : Oe.pageSize, J, T), Pe = s(() => {
308
- let e = Y ? Me ?? [] : J;
309
- return X ? [Q, ...e] : e;
310
- }, [
311
- Y,
312
- Me,
313
- J,
314
- X,
315
- Q
316
- ]), Fe = Y ? Ne : t, Ie = Z && d ? {
317
- pageIndex: d.pageIndex,
318
- pageSize: d.pageSize
319
- } : Oe, $ = ie({
320
- columns: Pe,
321
- data: Fe,
322
- getCoreRowModel: ee(),
323
- getSortedRowModel: re(),
324
- getExpandedRowModel: te(),
325
- ..._ || Z ? { getPaginationRowModel: ne() } : {},
326
- enableRowSelection: X ? (e) => q(e.original) : !1,
327
- getRowCanExpand: (e) => !Y && (!!K || e.subRows.length > 0),
328
- getRowId: N,
329
- getSubRows: P,
330
- state: {
331
- sorting: we,
332
- rowSelection: Ee,
333
- pagination: Ie,
334
- columnVisibility: Ae
335
- },
336
- onSortingChange: Te,
337
- onRowSelectionChange: De,
338
- onPaginationChange: Z ? void 0 : ke,
339
- onColumnVisibilityChange: je,
340
- manualSorting: Ce,
341
- manualPagination: Z ? !0 : void 0,
342
- pageCount: Z ? d?.pageCount : void 0,
343
- enableSortingRemoval: !1,
344
- enableMultiSort: !1,
345
- enableColumnResizing: !0,
346
- columnResizeMode: "onChange",
347
- defaultColumn: { enableResizing: !1 }
348
- }), Le = c(null), Re = c(null);
349
- ge(Le, Re), o(() => {
350
- if (X) {
351
- let e = $.getSelectedRowModel().flatRows.map((e) => e.original).filter(q);
352
- v?.(e);
144
+ return Array.isArray(t) ? t : void 0;
145
+ }, ue = (t = {}) => ({
146
+ id: "selection",
147
+ size: 40,
148
+ enableSorting: !1,
149
+ enableHiding: !1,
150
+ enableResizing: !1,
151
+ header: ({ table: t }) => {
152
+ let n = t.getRowModel().rows, r = t.getIsAllPageRowsSelected();
153
+ return /* @__PURE__ */ k(e, {
154
+ isChecked: r,
155
+ isIndeterminate: t.getIsSomePageRowsSelected() && !r,
156
+ isDisabled: n.every((e) => !e.getCanSelect()),
157
+ onChange: (e) => t.toggleAllPageRowsSelected(e),
158
+ "aria-label": "Select all rows"
159
+ });
160
+ },
161
+ cell: ({ row: t }) => {
162
+ let n = t.getCanSelect();
163
+ return /* @__PURE__ */ k(e, {
164
+ isChecked: n && t.getIsSelected(),
165
+ isDisabled: !n,
166
+ onChange: (e) => t.toggleSelected(e),
167
+ "aria-label": "Select row"
168
+ });
169
+ },
170
+ ...t
171
+ }), de = {
172
+ asc: "ascending",
173
+ desc: "descending"
174
+ }, Z = ({ header: e }) => {
175
+ let { column: a } = e, o = d(a.columnDef.header, e.getContext());
176
+ if (!a.getCanSort()) return /* @__PURE__ */ k(O, { children: o });
177
+ let s = a.getIsSorted();
178
+ return /* @__PURE__ */ A("button", {
179
+ type: "button",
180
+ className: "table-sort",
181
+ onClick: () => e.getContext().table.setSorting([{
182
+ id: a.id,
183
+ desc: s !== "desc"
184
+ }]),
185
+ children: [
186
+ o,
187
+ s === "asc" && /* @__PURE__ */ k(n, {
188
+ size: i.Small,
189
+ color: r.QuietText,
190
+ "aria-hidden": !0
191
+ }),
192
+ s === "desc" && /* @__PURE__ */ k(t, {
193
+ size: i.Small,
194
+ color: r.QuietText,
195
+ "aria-hidden": !0
196
+ })
197
+ ]
198
+ });
199
+ }, fe = (e) => {
200
+ let { column: t } = e, n = e.getContext().table.store.state.columnSizing;
201
+ return t.columnDef.size !== void 0 || n?.[t.id] !== void 0 ? e.getSize() : void 0;
202
+ }, pe = ({ table: e, isPlaceholder: t = !1, pagination: n, isLoading: r = !1, loadingMessage: i = "loading...", showLoadingState: a = !1, footerPlacement: o = [], tableContentId: s, noDataMessage: c, caption: l, rowSubComponent: u, getRowPreProps: f, getTableProps: p, getHeaderGroupProps: m, getHeaderProps: ee, getRowProps: te, getCellProps: h, getFooterProps: g, getFooterGroupProps: _ }) => {
203
+ let v = T(null), y = T(null);
204
+ ae(v, y);
205
+ let b = e.getHeaderGroups(), ne = e.getFooterGroups(), x = e.getRowModel().rows, S = e.getVisibleLeafColumns(), C = Math.max(S.length, 1), w = S.some((e) => e.getCanResize()), E = p?.() ?? {}, D = w ? {
206
+ ...E,
207
+ className: j("table--fixed", E.className),
208
+ style: {
209
+ minWidth: e.getTotalSize(),
210
+ ...E.style
353
211
  }
354
- }, [Ee, X]);
355
- let ze = null;
356
- if (Z || _) {
357
- let { pageIndex: e, pageSize: i } = $.getState().pagination, a = {
358
- setPageSize: $.setPageSize,
359
- gotoPage: $.setPageIndex,
360
- canNextPage: $.getCanNextPage(),
361
- canPreviousPage: $.getCanPreviousPage(),
362
- parentElementId: S,
363
- labelPerPage: ae,
364
- pageIndex: e,
365
- previousPageHandler: $.previousPage,
366
- nextPageHandler: $.nextPage,
367
- totalPages: $.getPageCount(),
368
- perPage: i,
369
- totalItems: n ?? t.length
370
- };
371
- Z && d && (a.canNextPage = d.pageIndex + 1 !== a.totalPages, a.canPreviousPage = d.pageIndex !== 0, a.pageIndex = d.pageIndex, a.perPage = d.pageSize, a.setPageSize = (e) => {
372
- r?.({
373
- pageIndex: d.pageIndex,
374
- pageSize: e
375
- });
376
- }, a.gotoPage = (e) => {
377
- r?.({
378
- pageIndex: e,
379
- pageSize: d.pageSize
380
- });
381
- }, a.nextPageHandler = () => {
382
- r?.({
383
- pageIndex: d.pageIndex + 1,
384
- pageSize: d.pageSize
385
- });
386
- }, a.previousPageHandler = () => {
387
- r?.({
388
- pageIndex: d.pageIndex - 1,
389
- pageSize: d.pageSize
390
- });
391
- }, d.paginationAmount && (a.paginationAmount = d.paginationAmount)), ze = A ? /* @__PURE__ */ y(A, { ...a }) : null;
392
- }
393
- let Be = (e) => {
394
- if (!e.column.getCanSort()) return;
395
- let t = e.column.getIsSorted(), n = [{
396
- id: e.column.id,
397
- desc: t !== "desc"
398
- }];
399
- Ce && g?.(n), Te(n);
400
- }, Ve = $.getHeaderGroups(), He = $.getFooterGroups(), Ue = $.getRowModel().rows;
401
- return /* @__PURE__ */ b(ue, {
212
+ } : E, O = (e) => {
213
+ let t = e === W.Top ? I : L, n = `table-footer-${e}`;
214
+ return /* @__PURE__ */ k(t, {
215
+ className: j("table-footer", n),
216
+ "data-role": n,
217
+ children: ne.map((e) => /* @__PURE__ */ k(R, {
218
+ ..._?.(e),
219
+ children: e.headers.map((e) => /* @__PURE__ */ k(B, {
220
+ colSpan: e.colSpan,
221
+ style: { textAlign: H(e) },
222
+ ...g?.(e),
223
+ children: e.isPlaceholder ? null : d(e.column.columnDef.footer, e.getContext())
224
+ }, e.id))
225
+ }, e.id))
226
+ });
227
+ }, M = !t && u !== void 0, { closing: N, finish: G } = K(M ? x.filter((e) => e.getIsExpanded()).map((e) => e.id) : []), q = (e) => {
228
+ let t = e.getIsExpanded();
229
+ return !M || !t && !N.includes(e.id) ? null : /* @__PURE__ */ k(R, {
230
+ className: j("table-sub-row", !t && "table-sub-row--closing"),
231
+ children: /* @__PURE__ */ k(B, {
232
+ colSpan: C,
233
+ className: "table-cell--sub",
234
+ children: /* @__PURE__ */ k("div", {
235
+ className: "table-sub-panel",
236
+ onTransitionEnd: (n) => {
237
+ !t && n.target === n.currentTarget && G(e.id);
238
+ },
239
+ children: /* @__PURE__ */ k("div", {
240
+ className: "table-sub-panel__content",
241
+ children: /* @__PURE__ */ k("div", {
242
+ className: "table-sub-panel__body",
243
+ children: u?.(e)
244
+ })
245
+ })
246
+ })
247
+ })
248
+ });
249
+ }, J = (e) => {
250
+ let { isDelimiterTd: n, ...r } = t ? {} : f?.(e) ?? {}, i = t ? void 0 : te?.(e);
251
+ if (n) {
252
+ let n = e.getVisibleCells()[0];
253
+ return n ? /* @__PURE__ */ A(re, { children: [/* @__PURE__ */ k(R, {
254
+ ...r,
255
+ ...i,
256
+ children: /* @__PURE__ */ k(B, {
257
+ colSpan: C,
258
+ className: "table-cell--full",
259
+ ...t ? void 0 : h?.(n),
260
+ children: /* @__PURE__ */ k("strong", { children: d(n.column.columnDef.cell, n.getContext()) })
261
+ })
262
+ }), q(e)] }, e.id) : null;
263
+ }
264
+ return /* @__PURE__ */ A(re, { children: [/* @__PURE__ */ k(R, {
265
+ "data-state": !t && e.getIsSelected() ? "selected" : void 0,
266
+ ...r,
267
+ ...i,
268
+ className: j(e.depth > 0 && "table-row--child", r.className, i?.className),
269
+ children: e.getVisibleCells().map((e) => /* @__PURE__ */ k(B, {
270
+ style: { textAlign: U(e) },
271
+ ...t ? void 0 : h?.(e),
272
+ children: d(e.column.columnDef.cell, e.getContext())
273
+ }, e.id))
274
+ }), q(e)] }, e.id);
275
+ };
276
+ return /* @__PURE__ */ A("div", {
402
277
  className: "table-root",
403
278
  children: [
404
- /* @__PURE__ */ y(se, {
405
- $isLoading: !G && p,
406
- className: "table-loading",
407
- children: /* @__PURE__ */ y(ce, { children: m })
279
+ /* @__PURE__ */ k("div", {
280
+ className: j("table-loading", !a && r && "table-loading--active"),
281
+ children: i
408
282
  }),
409
- /* @__PURE__ */ y(le, {
410
- ref: Re,
283
+ /* @__PURE__ */ k("div", {
284
+ ref: y,
411
285
  className: "table-wrapper",
412
- children: /* @__PURE__ */ y(de, {
413
- id: C,
414
- className: "table-content",
415
- children: /* @__PURE__ */ b(fe, {
416
- ...F?.(),
417
- ref: Le,
418
- children: [
419
- /* @__PURE__ */ y(pe, {
420
- className: "table-head",
421
- "data-role": "table-head",
422
- children: Ve.map((e) => /* @__PURE__ */ y(O, {
423
- ...I?.(e),
424
- children: e.headers.map((e) => /* @__PURE__ */ b(E, {
425
- $size: e.getSize(),
426
- onClick: () => Be(e),
427
- ...B?.(e),
428
- children: [e.isPlaceholder ? null : ye(e), be(e)]
429
- }, e.id))
430
- }, e.id))
431
- }),
432
- h.includes(j.Top) && /* @__PURE__ */ y(k, {
433
- className: "table-footer-top",
434
- "data-role": "table-footer-top",
435
- children: He.map((e) => /* @__PURE__ */ y(O, {
436
- ...W?.(e),
437
- children: e.headers.map((e) => /* @__PURE__ */ y(w, {
438
- $size: e.getSize(),
439
- $align: x(e),
440
- ...U?.(e),
441
- children: e.isPlaceholder ? null : u(e.column.columnDef.footer, e.getContext())
442
- }, e.id))
443
- }, e.id))
444
- }),
445
- /* @__PURE__ */ y(me, {
446
- className: "table-body",
447
- "data-role": "table-body",
448
- children: Ue.map((e) => {
449
- let { isDelimiterTd: t } = Y ? L() : M(e);
450
- if (t) {
451
- let t = e.getVisibleCells()[0];
452
- return t ? /* @__PURE__ */ b(a, { children: [/* @__PURE__ */ y(D, { children: /* @__PURE__ */ y(O, {
453
- ...Y ? void 0 : V?.(e),
454
- children: /* @__PURE__ */ y(w, {
455
- style: { flex: "1 0 0%" },
456
- ...Y ? void 0 : H?.(t),
457
- children: /* @__PURE__ */ y("strong", { children: u(t.column.columnDef.cell, t.getContext()) })
458
- })
459
- }) }), !Y && e.getIsExpanded() && K && K(e)] }, `group_${e.index}`) : null;
460
- }
461
- return /* @__PURE__ */ b(a, { children: [/* @__PURE__ */ y(D, { children: /* @__PURE__ */ y(O, {
462
- ...Y ? void 0 : V?.(e),
463
- children: e.getVisibleCells().map((e) => /* @__PURE__ */ y(w, {
464
- $size: e.column.getSize(),
465
- $align: oe(e),
466
- ...Y ? void 0 : H?.(e),
467
- children: u(e.column.columnDef.cell, e.getContext())
468
- }, e.id))
469
- }) }), !Y && e.getIsExpanded() && K && K(e)] }, `group_${e.index}`);
286
+ children: /* @__PURE__ */ A(P, {
287
+ ref: v,
288
+ containerProps: { id: s || void 0 },
289
+ ...D,
290
+ children: [
291
+ l && /* @__PURE__ */ k(V, { children: l }),
292
+ w && /* @__PURE__ */ k("colgroup", { children: S.map((e, t) => /* @__PURE__ */ k("col", { style: { width: t === S.length - 1 ? void 0 : e.getSize() } }, e.id)) }),
293
+ /* @__PURE__ */ k(F, {
294
+ className: "table-head",
295
+ "data-role": "table-head",
296
+ children: b.map((e) => /* @__PURE__ */ k(R, {
297
+ ...m?.(e),
298
+ children: e.headers.map((e) => {
299
+ let t = e.column.getIsSorted();
300
+ return /* @__PURE__ */ A(z, {
301
+ colSpan: e.colSpan,
302
+ "aria-sort": t ? de[t] : void 0,
303
+ style: {
304
+ width: w ? void 0 : fe(e),
305
+ textAlign: H(e)
306
+ },
307
+ ...ee?.(e),
308
+ children: [e.isPlaceholder ? null : /* @__PURE__ */ k(Z, { header: e }), e.column.getCanResize() && /* @__PURE__ */ k("div", {
309
+ className: "table-resizer",
310
+ "data-resizing": e.column.getIsResizing() || void 0,
311
+ onMouseDown: e.getResizeHandler(),
312
+ onTouchStart: e.getResizeHandler(),
313
+ onClick: (e) => {
314
+ e.preventDefault(), e.stopPropagation();
315
+ },
316
+ "aria-hidden": !0
317
+ })]
318
+ }, e.id);
470
319
  })
471
- }),
472
- h.includes(j.Bottom) && /* @__PURE__ */ y(k, {
473
- className: "table-footer-bottom",
474
- "data-role": "table-footer-bottom",
475
- children: He.map((e) => /* @__PURE__ */ y(O, {
476
- ...W?.(e),
477
- children: e.headers.map((e) => /* @__PURE__ */ y(w, {
478
- $size: e.getSize(),
479
- $align: x(e),
480
- ...U?.(e),
481
- children: e.isPlaceholder ? null : u(e.column.columnDef.footer, e.getContext())
482
- }, e.id))
483
- }, e.id))
484
- })
485
- ]
486
- })
320
+ }, e.id))
321
+ }),
322
+ o.includes(W.Top) && O(W.Top),
323
+ /* @__PURE__ */ A(I, {
324
+ "data-role": "table-body",
325
+ children: [x.map(J), x.length === 0 && !r && c && /* @__PURE__ */ k(R, { children: /* @__PURE__ */ k(B, {
326
+ colSpan: C,
327
+ className: "table-cell--empty",
328
+ children: c
329
+ }) })]
330
+ }),
331
+ o.includes(W.Bottom) && O(W.Bottom)
332
+ ]
487
333
  })
488
334
  }),
489
- !p && !t.length && xe,
490
- ze
335
+ n
491
336
  ]
492
337
  });
493
- };
494
- export { B as default, R as defaultProps };
338
+ }, me = (e, { PaginationComponent: t, parentElementId: n = "parent-element", labelPerPage: r = "Show rows", totalItems: i }, a = {}) => {
339
+ if (!t) return null;
340
+ let { pageIndex: o, pageSize: s } = e.state.pagination, c = {
341
+ parentElementId: n,
342
+ labelPerPage: r,
343
+ pageIndex: o,
344
+ perPage: s,
345
+ totalPages: e.getPageCount(),
346
+ totalItems: i ?? e.getRowCount(),
347
+ canNextPage: e.getCanNextPage(),
348
+ canPreviousPage: e.getCanPreviousPage(),
349
+ nextPageHandler: () => e.nextPage(),
350
+ previousPageHandler: () => e.previousPage(),
351
+ setPageSize: (t) => e.setPageSize(t),
352
+ gotoPage: (t) => e.setPageIndex(t),
353
+ ...a
354
+ };
355
+ return /* @__PURE__ */ k(t, { ...c });
356
+ }, he = ({ table: e, ...t }) => {
357
+ let n = "getPageCount" in e && typeof e.getPageCount == "function";
358
+ return /* @__PURE__ */ k(pe, {
359
+ ...t,
360
+ table: e,
361
+ pagination: n ? me(e, t) : null
362
+ });
363
+ }, Q = (e) => {
364
+ let { columns: t, data: n, features: r, state: i, initialState: a, onSortingChange: o, onRowSelectionChange: s, onPaginationChange: c, onColumnVisibilityChange: l, totalItems: u, PaginationComponent: d, isLoading: f = !1, loadingMessage: p, showLoadingState: m = !1, LoadingCellComponent: ee = ce, footerPlacement: te, hasDefaultPagination: h = !1, onSelectRowsChange: g, labelPerPage: _, parentElementId: v, tableContentId: y, noDataMessage: b, caption: re, rowSubComponent: x, selectColumnProps: S, getRowPreProps: T, getTableProps: D, getHeaderGroupProps: O, getHeaderProps: A, getRowProps: j, getCellProps: P, getFooterProps: F, getFooterGroupProps: I, fetchData: L, controlledPagination: R, onSortedChange: z, isEnableRowSelect: B, ...V } = e, H = i ?? {}, U = m && f, W = !!(L && R && Object.keys(R).length > 0);
365
+ if (h && W) throw Error("You have to pass either hasDefaultPagination true boolean prop or pass fetchData callback and controlledPagination data");
366
+ if (W && R?.pageCount === void 0) throw Error("You have to pass pageCount in controlledPagination data");
367
+ let G = W || V.manualPagination === !0, K = h && !G, J = h || G || H.pagination !== void 0, ie = w(() => ({
368
+ ...K ? N : M,
369
+ ...r
370
+ }), [K, r]), [Y, ae] = E(a?.sorting ?? []), [de, Z] = E({}), [fe, he] = E({
371
+ pageIndex: oe,
372
+ pageSize: se,
373
+ ...a?.pagination
374
+ }), Q = a?.columnVisibility, [ge, _e] = E(Q ?? {});
375
+ C(() => {
376
+ Q && _e(Q);
377
+ }, [Q]);
378
+ let ve = H.sorting ?? Y, ye = H.rowSelection ?? de, be = H.columnVisibility ?? ge, xe = W && R ? {
379
+ pageIndex: R.pageIndex,
380
+ pageSize: R.pageSize
381
+ } : H.pagination ?? fe, $ = !U && (typeof g == "function" || typeof s == "function" || H.rowSelection !== void 0), Se = w(() => ue(S), [S]), { loadingColumns: Ce, loadingData: we } = q(m, f, xe.pageSize, t, ee), Te = w(() => {
382
+ let e = U ? Ce ?? [] : t;
383
+ return $ ? [Se, ...e] : e;
384
+ }, [
385
+ U,
386
+ Ce,
387
+ t,
388
+ $,
389
+ Se
390
+ ]), Ee = ne({
391
+ enableSortingRemoval: !1,
392
+ enableMultiSort: !1,
393
+ enableColumnResizing: !0,
394
+ columnResizeMode: "onChange",
395
+ getSubRows: le,
396
+ getRowCanExpand: (e) => !U && (!!x || e.subRows.length > 0),
397
+ enableRowSelection: B ? (e) => B(e.original) : !0,
398
+ manualSorting: typeof z == "function" || void 0,
399
+ ...V,
400
+ defaultColumn: {
401
+ enableResizing: !1,
402
+ ...V.defaultColumn
403
+ },
404
+ manualPagination: G ? !0 : V.manualPagination,
405
+ pageCount: W ? R?.pageCount : V.pageCount,
406
+ features: ie,
407
+ columns: Te,
408
+ data: U ? we : n,
409
+ initialState: a,
410
+ state: {
411
+ ...i,
412
+ sorting: ve,
413
+ rowSelection: ye,
414
+ pagination: xe,
415
+ columnVisibility: be
416
+ },
417
+ onSortingChange: (e) => {
418
+ let t = X(e, ve);
419
+ H.sorting === void 0 && ae(t), o?.(e), z?.(t);
420
+ },
421
+ onRowSelectionChange: (e) => {
422
+ H.rowSelection === void 0 && Z(X(e, ye)), s?.(e);
423
+ },
424
+ onPaginationChange: (e) => {
425
+ let t = X(e, xe);
426
+ W ? L?.(t) : (H.pagination === void 0 && he(t), c?.(e));
427
+ },
428
+ onColumnVisibilityChange: (e) => {
429
+ H.columnVisibility === void 0 && _e(X(e, be)), l?.(e);
430
+ }
431
+ });
432
+ C(() => {
433
+ $ && g && g(Ee.getSelectedRowModel().flatRows.filter((e) => e.getCanSelect()).map((e) => e.original));
434
+ }, [ye, $]);
435
+ let De = {
436
+ totalItems: u,
437
+ PaginationComponent: d,
438
+ labelPerPage: _,
439
+ parentElementId: v
440
+ }, Oe = W && R ? {
441
+ pageIndex: R.pageIndex,
442
+ perPage: R.pageSize,
443
+ canNextPage: R.pageIndex + 1 < R.pageCount,
444
+ canPreviousPage: R.pageIndex > 0,
445
+ ...R.paginationAmount ? { paginationAmount: R.paginationAmount } : {}
446
+ } : {};
447
+ return /* @__PURE__ */ k(pe, {
448
+ table: Ee,
449
+ isPlaceholder: U,
450
+ pagination: J ? me(Ee, De, Oe) : null,
451
+ isLoading: f,
452
+ loadingMessage: p,
453
+ showLoadingState: m,
454
+ footerPlacement: te,
455
+ tableContentId: y,
456
+ noDataMessage: b,
457
+ caption: re,
458
+ rowSubComponent: x,
459
+ getRowPreProps: T,
460
+ getTableProps: D,
461
+ getHeaderGroupProps: O,
462
+ getHeaderProps: A,
463
+ getRowProps: j,
464
+ getCellProps: P,
465
+ getFooterProps: F,
466
+ getFooterGroupProps: I
467
+ });
468
+ }, ge = (e) => e.table ? /* @__PURE__ */ k(he, { ...e }) : /* @__PURE__ */ k(Q, { ...e });
469
+ export { W as FooterPlacement, I as TableBody, V as TableCaption, B as TableCell, Z as TableColumnHeader, L as TableFooter, z as TableHead, F as TableHeader, ce as TablePlaceholder, P as TableRoot, R as TableRow, ue as createSelectionColumn, ge as default, M as tableBaseFeatures, N as tablePaginatedFeatures };
495
470
 
496
471
  //# sourceMappingURL=index.js.map