@propellerads/table 7.0.1 → 8.1.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,480 @@
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 ie, useState as T } from "react";
5
+ import { clsx as E } from "clsx";
6
+ import { Fragment as D, jsx as O, jsxs as k } from "react/jsx-runtime";
7
+ import './index.css';export * from "@tanstack/react-table";
8
+ // src/cn.ts
9
+ var A = (...e) => E(e), j = 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
+ }), M = b({
28
+ ...j,
29
+ paginatedRowModel: l()
30
+ }), N = x(({ className: e, containerProps: t, ...n }, r) => /* @__PURE__ */ O("div", {
31
+ ...t,
32
+ className: A("table-content", t?.className),
33
+ children: /* @__PURE__ */ O("table", {
34
+ ref: r,
35
+ className: A("table", e),
36
+ ...n
37
+ })
38
+ }));
39
+ N.displayName = "TableRoot";
40
+ var P = x(({ className: e, ...t }, n) => /* @__PURE__ */ O("thead", {
41
+ ref: n,
42
+ className: A("table-header", e),
43
+ ...t
44
+ }));
45
+ P.displayName = "TableHeader";
46
+ var F = x(({ className: e, ...t }, n) => /* @__PURE__ */ O("tbody", {
47
+ ref: n,
48
+ className: A("table-body", e),
49
+ ...t
50
+ }));
51
+ F.displayName = "TableBody";
52
+ var I = x(({ className: e, ...t }, n) => /* @__PURE__ */ O("tfoot", {
53
+ ref: n,
54
+ className: A("table-footer", e),
55
+ ...t
56
+ }));
57
+ I.displayName = "TableFooter";
58
+ var L = x(({ className: e, ...t }, n) => /* @__PURE__ */ O("tr", {
59
+ ref: n,
60
+ className: A("table-row", e),
61
+ ...t
62
+ }));
63
+ L.displayName = "TableRow";
64
+ var R = x(({ className: e, ...t }, n) => /* @__PURE__ */ O("th", {
65
+ ref: n,
66
+ className: A("table-header-cell", e),
67
+ ...t
68
+ }));
69
+ R.displayName = "TableHead";
70
+ var z = x(({ className: e, ...t }, n) => /* @__PURE__ */ O("td", {
71
+ ref: n,
72
+ className: A("table-cell", e),
73
+ ...t
74
+ }));
75
+ z.displayName = "TableCell";
76
+ var B = x(({ className: e, ...t }, n) => /* @__PURE__ */ O("caption", {
77
+ ref: n,
78
+ className: A("table-caption", e),
79
+ ...t
80
+ }));
81
+ B.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 V = (e) => e.column.columnDef.meta?.align, H = (e) => e.column.columnDef.meta?.align, U = {
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
+ }, W = () => typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches, G = (e) => {
87
+ let t = e.join("\0"), [n, r] = T(t), [i, a] = T(e), [o, s] = T([]);
88
+ if (t !== n) {
89
+ let n = W() ? [] : 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
+ }, K = (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__ */ O(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
+ }, q = {
221
122
  Left: "shadow_left",
222
123
  Right: "shadow_right"
223
- }, N = (e, t) => {
124
+ }, ae = (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(q.Left, q.Right), n.add(...t);
127
+ }, J = (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(q.Left), o > c && i.push(q.Right), ae(t, i);
131
+ }, oe = (e, t) => {
132
+ C(() => {
232
133
  let n = !1, r = () => {
233
134
  n ||= (window.requestAnimationFrame(() => {
234
- P(e.current, t.current), n = !1;
135
+ J(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 J(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
+ }, se = 0, ce = 10, Y = (e, t) => typeof e == "function" ? e(t) : e, le = () => /* @__PURE__ */ O("div", { className: "table-placeholder" }), ue = (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
144
+ return Array.isArray(t) ? t : void 0;
145
+ }, de = (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__ */ O(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__ */ O(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
+ }), fe = {
172
+ asc: "ascending",
173
+ desc: "descending"
174
+ }, X = ({ header: e }) => {
175
+ let { column: a } = e, o = d(a.columnDef.header, e.getContext());
176
+ if (!a.getCanSort()) return /* @__PURE__ */ O(D, { children: o });
177
+ let s = a.getIsSorted();
178
+ return /* @__PURE__ */ k("button", {
179
+ type: "button",
180
+ className: "table-sort",
181
+ onClick: () => {
182
+ let { table: t } = e.getContext(), n = a.columnDef.sortDescFirst ?? t.options.sortDescFirst ?? !0;
183
+ t.setSorting([{
184
+ id: a.id,
185
+ desc: s ? s !== "desc" : n
186
+ }]);
335
187
  },
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);
188
+ children: [
189
+ o,
190
+ s === "asc" && /* @__PURE__ */ O(n, {
191
+ size: i.Small,
192
+ color: r.QuietText,
193
+ "aria-hidden": !0
194
+ }),
195
+ s === "desc" && /* @__PURE__ */ O(t, {
196
+ size: i.Small,
197
+ color: r.QuietText,
198
+ "aria-hidden": !0
199
+ })
200
+ ]
201
+ });
202
+ }, pe = (e) => {
203
+ let t = e.column.columnDef.meta?.headerAside?.(e.getContext());
204
+ return t == null ? /* @__PURE__ */ O(X, { header: e }) : /* @__PURE__ */ k("span", {
205
+ className: "table-header-content",
206
+ children: [/* @__PURE__ */ O(X, { header: e }), t]
207
+ });
208
+ }, me = (e) => {
209
+ let { column: t } = e, n = e.getContext().table.store.state.columnSizing;
210
+ return t.columnDef.size !== void 0 || n?.[t.id] !== void 0 ? e.getSize() : void 0;
211
+ }, he = ({ 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: _ }) => {
212
+ let v = ie(null), y = ie(null);
213
+ oe(v, y);
214
+ 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()), T = p?.() ?? {}, E = w ? {
215
+ ...T,
216
+ className: A("table--fixed", T.className),
217
+ style: {
218
+ minWidth: e.getTotalSize(),
219
+ ...T.style
353
220
  }
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, {
221
+ } : T, D = (e) => {
222
+ let t = `table-footer-${e}`;
223
+ return /* @__PURE__ */ O(I, {
224
+ className: t,
225
+ "data-role": t,
226
+ children: ne.map((e) => /* @__PURE__ */ O(L, {
227
+ ..._?.(e),
228
+ children: e.headers.map((e) => /* @__PURE__ */ O(z, {
229
+ colSpan: e.colSpan,
230
+ style: { textAlign: V(e) },
231
+ ...g?.(e),
232
+ children: e.isPlaceholder ? null : d(e.column.columnDef.footer, e.getContext())
233
+ }, e.id))
234
+ }, e.id))
235
+ });
236
+ }, j = !t && u !== void 0, { closing: M, finish: W } = G(j ? x.filter((e) => e.getIsExpanded()).map((e) => e.id) : []), K = (e) => {
237
+ let t = e.getIsExpanded();
238
+ return !j || !t && !M.includes(e.id) ? null : /* @__PURE__ */ O(L, {
239
+ className: A("table-sub-row", !t && "table-sub-row--closing"),
240
+ children: /* @__PURE__ */ O(z, {
241
+ colSpan: C,
242
+ className: "table-cell--sub",
243
+ children: /* @__PURE__ */ O("div", {
244
+ className: "table-sub-panel",
245
+ onTransitionEnd: (n) => {
246
+ !t && n.target === n.currentTarget && W(e.id);
247
+ },
248
+ children: /* @__PURE__ */ O("div", {
249
+ className: "table-sub-panel__content",
250
+ children: /* @__PURE__ */ O("div", {
251
+ className: "table-sub-panel__body",
252
+ children: u?.(e)
253
+ })
254
+ })
255
+ })
256
+ })
257
+ });
258
+ }, q = (e) => {
259
+ let { isDelimiterTd: n, ...r } = t ? {} : f?.(e) ?? {}, i = t ? void 0 : te?.(e);
260
+ if (n) {
261
+ let n = e.getVisibleCells()[0];
262
+ return n ? /* @__PURE__ */ k(re, { children: [/* @__PURE__ */ O(L, {
263
+ ...r,
264
+ ...i,
265
+ children: /* @__PURE__ */ O(z, {
266
+ colSpan: C,
267
+ className: "table-cell--full",
268
+ ...t ? void 0 : h?.(n),
269
+ children: /* @__PURE__ */ O("strong", { children: d(n.column.columnDef.cell, n.getContext()) })
270
+ })
271
+ }), K(e)] }, e.id) : null;
272
+ }
273
+ return /* @__PURE__ */ k(re, { children: [/* @__PURE__ */ O(L, {
274
+ "data-state": !t && e.getIsSelected() ? "selected" : void 0,
275
+ ...r,
276
+ ...i,
277
+ className: A(e.depth > 0 && "table-row--child", r.className, i?.className),
278
+ children: e.getVisibleCells().map((e) => /* @__PURE__ */ O(z, {
279
+ style: { textAlign: H(e) },
280
+ ...t ? void 0 : h?.(e),
281
+ children: d(e.column.columnDef.cell, e.getContext())
282
+ }, e.id))
283
+ }), K(e)] }, e.id);
284
+ };
285
+ return /* @__PURE__ */ k("div", {
402
286
  className: "table-root",
403
287
  children: [
404
- /* @__PURE__ */ y(se, {
405
- $isLoading: !G && p,
406
- className: "table-loading",
407
- children: /* @__PURE__ */ y(ce, { children: m })
288
+ /* @__PURE__ */ O("div", {
289
+ className: A("table-loading", !a && r && "table-loading--active"),
290
+ children: i
408
291
  }),
409
- /* @__PURE__ */ y(le, {
410
- ref: Re,
292
+ /* @__PURE__ */ O("div", {
293
+ ref: y,
411
294
  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}`);
295
+ children: /* @__PURE__ */ k(N, {
296
+ ref: v,
297
+ containerProps: { id: s || void 0 },
298
+ ...E,
299
+ children: [
300
+ l && /* @__PURE__ */ O(B, { children: l }),
301
+ w && /* @__PURE__ */ O("colgroup", { children: S.map((e, t) => /* @__PURE__ */ O("col", { style: { width: t === S.length - 1 ? void 0 : e.getSize() } }, e.id)) }),
302
+ /* @__PURE__ */ O(P, {
303
+ className: "table-head",
304
+ "data-role": "table-head",
305
+ children: b.map((e) => /* @__PURE__ */ O(L, {
306
+ ...m?.(e),
307
+ children: e.headers.map((e) => {
308
+ let t = e.column.getIsSorted();
309
+ return /* @__PURE__ */ k(R, {
310
+ colSpan: e.colSpan,
311
+ "aria-sort": t ? fe[t] : void 0,
312
+ style: {
313
+ width: w ? void 0 : me(e),
314
+ textAlign: V(e)
315
+ },
316
+ ...ee?.(e),
317
+ children: [e.isPlaceholder ? null : pe(e), e.column.getCanResize() && /* @__PURE__ */ O("div", {
318
+ className: "table-resizer",
319
+ "data-resizing": e.column.getIsResizing() || void 0,
320
+ onMouseDown: e.getResizeHandler(),
321
+ onTouchStart: e.getResizeHandler(),
322
+ onClick: (e) => {
323
+ e.preventDefault(), e.stopPropagation();
324
+ },
325
+ "aria-hidden": !0
326
+ })]
327
+ }, e.id);
470
328
  })
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
- })
329
+ }, e.id))
330
+ }),
331
+ o.includes(U.Top) && D(U.Top),
332
+ /* @__PURE__ */ k(F, {
333
+ "data-role": "table-body",
334
+ children: [x.map(q), x.length === 0 && !r && c && /* @__PURE__ */ O(L, { children: /* @__PURE__ */ O(z, {
335
+ colSpan: C,
336
+ className: "table-cell--empty",
337
+ children: c
338
+ }) })]
339
+ }),
340
+ o.includes(U.Bottom) && D(U.Bottom)
341
+ ]
487
342
  })
488
343
  }),
489
- !p && !t.length && xe,
490
- ze
344
+ n
491
345
  ]
492
346
  });
493
- };
494
- export { B as default, R as defaultProps };
347
+ }, ge = (e, { PaginationComponent: t, parentElementId: n = "parent-element", labelPerPage: r = "Show rows", totalItems: i }, a = {}) => {
348
+ if (!t) return null;
349
+ let { pageIndex: o, pageSize: s } = e.state.pagination, c = {
350
+ parentElementId: n,
351
+ labelPerPage: r,
352
+ pageIndex: o,
353
+ perPage: s,
354
+ totalPages: e.getPageCount(),
355
+ totalItems: i ?? e.getRowCount(),
356
+ canNextPage: e.getCanNextPage(),
357
+ canPreviousPage: e.getCanPreviousPage(),
358
+ nextPageHandler: () => e.nextPage(),
359
+ previousPageHandler: () => e.previousPage(),
360
+ setPageSize: (t) => e.setPageSize(t),
361
+ gotoPage: (t) => e.setPageIndex(t),
362
+ ...a
363
+ };
364
+ return /* @__PURE__ */ O(t, { ...c });
365
+ }, Z = ({ table: e, ...t }) => {
366
+ let n = "getPageCount" in e && typeof e.getPageCount == "function";
367
+ return /* @__PURE__ */ O(he, {
368
+ ...t,
369
+ table: e,
370
+ pagination: n ? ge(e, t) : null
371
+ });
372
+ }, _e = (e) => {
373
+ 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 = le, footerPlacement: te, hasDefaultPagination: h = !1, onSelectRowsChange: g, labelPerPage: _, parentElementId: v, tableContentId: y, noDataMessage: b, caption: re, rowSubComponent: x, selectColumnProps: S, getRowPreProps: ie, getTableProps: E, getHeaderGroupProps: D, getHeaderProps: k, getRowProps: A, getCellProps: N, getFooterProps: P, getFooterGroupProps: F, fetchData: I, controlledPagination: L, onSortedChange: R, isEnableRowSelect: z, ...B } = e, V = i ?? {}, H = m && f, U = !!(I && L && Object.keys(L).length > 0);
374
+ if (h && U) throw Error("You have to pass either hasDefaultPagination true boolean prop or pass fetchData callback and controlledPagination data");
375
+ if (U && L?.pageCount === void 0) throw Error("You have to pass pageCount in controlledPagination data");
376
+ let W = U || B.manualPagination === !0, G = h && !W, q = h || W || V.pagination !== void 0, ae = w(() => ({
377
+ ...G ? M : j,
378
+ ...r
379
+ }), [G, r]), [J, oe] = T(a?.sorting ?? []), [fe, X] = T({}), [pe, me] = T({
380
+ pageIndex: se,
381
+ pageSize: ce,
382
+ ...a?.pagination
383
+ }), Z = a?.columnVisibility, [_e, ve] = T(Z ?? {});
384
+ C(() => {
385
+ Z && ve(Z);
386
+ }, [Z]);
387
+ let ye = V.sorting ?? J, be = V.rowSelection ?? fe, xe = V.columnVisibility ?? _e, Se = U && L ? {
388
+ pageIndex: L.pageIndex,
389
+ pageSize: L.pageSize
390
+ } : V.pagination ?? pe, Q = !H && (typeof g == "function" || typeof s == "function" || V.rowSelection !== void 0), Ce = w(() => de(S), [S]), { loadingColumns: we, loadingData: Te } = K(m, f, Se.pageSize, t, ee), Ee = w(() => {
391
+ let e = H ? we ?? [] : t;
392
+ return Q ? [Ce, ...e] : e;
393
+ }, [
394
+ H,
395
+ we,
396
+ t,
397
+ Q,
398
+ Ce
399
+ ]), $ = ne({
400
+ enableSortingRemoval: !1,
401
+ enableMultiSort: !1,
402
+ enableColumnResizing: !0,
403
+ columnResizeMode: "onChange",
404
+ getSubRows: ue,
405
+ getRowCanExpand: (e) => !H && (!!x || e.subRows.length > 0),
406
+ enableRowSelection: z ? (e) => z(e.original) : !0,
407
+ manualSorting: typeof R == "function" || void 0,
408
+ ...B,
409
+ defaultColumn: {
410
+ enableResizing: !1,
411
+ ...B.defaultColumn
412
+ },
413
+ manualPagination: W ? !0 : B.manualPagination,
414
+ pageCount: U ? L?.pageCount : B.pageCount,
415
+ features: ae,
416
+ columns: Ee,
417
+ data: H ? Te : n,
418
+ initialState: a,
419
+ state: {
420
+ ...i,
421
+ sorting: ye,
422
+ rowSelection: be,
423
+ pagination: Se,
424
+ columnVisibility: xe
425
+ },
426
+ onSortingChange: (e) => {
427
+ let t = Y(e, ye);
428
+ V.sorting === void 0 && oe(t), o?.(e), R?.(t);
429
+ },
430
+ onRowSelectionChange: (e) => {
431
+ V.rowSelection === void 0 && X(Y(e, be)), s?.(e);
432
+ },
433
+ onPaginationChange: (e) => {
434
+ let t = Y(e, Se);
435
+ U ? I?.(t) : (V.pagination === void 0 && me(t), c?.(e));
436
+ },
437
+ onColumnVisibilityChange: (e) => {
438
+ V.columnVisibility === void 0 && ve(Y(e, xe)), l?.(e);
439
+ }
440
+ });
441
+ C(() => {
442
+ Q && g && g($.getSelectedRowModel().flatRows.filter((e) => e.getCanSelect()).map((e) => e.original));
443
+ }, [be, Q]);
444
+ let De = {
445
+ totalItems: u,
446
+ PaginationComponent: d,
447
+ labelPerPage: _,
448
+ parentElementId: v
449
+ }, Oe = U && L ? {
450
+ pageIndex: L.pageIndex,
451
+ perPage: L.pageSize,
452
+ canNextPage: L.pageIndex + 1 < L.pageCount,
453
+ canPreviousPage: L.pageIndex > 0,
454
+ ...L.paginationAmount ? { paginationAmount: L.paginationAmount } : {}
455
+ } : {};
456
+ return /* @__PURE__ */ O(he, {
457
+ table: $,
458
+ isPlaceholder: H,
459
+ pagination: q ? ge($, De, Oe) : null,
460
+ isLoading: f,
461
+ loadingMessage: p,
462
+ showLoadingState: m,
463
+ footerPlacement: te,
464
+ tableContentId: y,
465
+ noDataMessage: b,
466
+ caption: re,
467
+ rowSubComponent: x,
468
+ getRowPreProps: ie,
469
+ getTableProps: E,
470
+ getHeaderGroupProps: D,
471
+ getHeaderProps: k,
472
+ getRowProps: A,
473
+ getCellProps: N,
474
+ getFooterProps: P,
475
+ getFooterGroupProps: F
476
+ });
477
+ }, ve = (e) => e.table ? /* @__PURE__ */ O(Z, { ...e }) : /* @__PURE__ */ O(_e, { ...e });
478
+ export { U as FooterPlacement, F as TableBody, B as TableCaption, z as TableCell, X as TableColumnHeader, I as TableFooter, R as TableHead, P as TableHeader, le as TablePlaceholder, N as TableRoot, L as TableRow, de as createSelectionColumn, ve as default, j as tableBaseFeatures, M as tablePaginatedFeatures };
495
479
 
496
480
  //# sourceMappingURL=index.js.map