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