@mkt-loitd/react-table-grid-custom 1.2.1 → 1.2.3
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.mts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +285 -58
- package/dist/index.mjs +282 -52
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Dispatch, SetStateAction, Key, ReactNode, JSX, MutableRefObject } from 'react';
|
|
3
3
|
import { ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
4
4
|
export { Column, ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
5
5
|
import { PaginationRootProps } from '@mantine/core';
|
|
@@ -16,6 +16,24 @@ interface IObjectDynamic {
|
|
|
16
16
|
}
|
|
17
17
|
interface ISetConfigPagination$1 extends IPaginationParams$1, IObjectDynamic {
|
|
18
18
|
}
|
|
19
|
+
interface useShowHideColumnParameter<T, SR = unknown> {
|
|
20
|
+
nameLocal?: string;
|
|
21
|
+
/** nếu đầu vào là columns: Functions() thì nên dùng useMemo thì sẽ tối ưu hơn */
|
|
22
|
+
columns: TColumnsTable<T, SR>;
|
|
23
|
+
ignoreColumns?: string[];
|
|
24
|
+
}
|
|
25
|
+
interface useShowHideColumnReturn<T, SR> {
|
|
26
|
+
hiddenColumns: string[];
|
|
27
|
+
setHiddenColumns: Dispatch<SetStateAction<string[]>>;
|
|
28
|
+
columnsTable: TColumnsTable<T, SR>;
|
|
29
|
+
changeHiddenColumn: (key: string | string[]) => void;
|
|
30
|
+
newShowhideColumns: TColumnsTable<T, SR>;
|
|
31
|
+
locationColumns: string[];
|
|
32
|
+
handleFindLocation: (filterColumns: TColumnsTable<T, SR>, locationColumns?: string[]) => TColumnsTable<T, SR>;
|
|
33
|
+
handleChangeLocation?: (arr: string[]) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare const useShowHideColumn: <T, SR = unknown>({ nameLocal, columns, ignoreColumns }: useShowHideColumnParameter<T, SR>) => useShowHideColumnReturn<T, SR>;
|
|
19
37
|
|
|
20
38
|
interface IPaginationText {
|
|
21
39
|
from?: number;
|
|
@@ -41,10 +59,22 @@ interface IReactTableGridCustom<T = unknown, SR = unknown, K extends Key = Key>
|
|
|
41
59
|
fetching?: boolean;
|
|
42
60
|
TableLogo?: string;
|
|
43
61
|
}
|
|
62
|
+
interface refTablePaginationClient extends Required<IPaginationParams> {
|
|
63
|
+
setConfigSearch: Dispatch<SetStateAction<ISetConfigPagination$1>>;
|
|
64
|
+
resetPagition: (conditional?: boolean) => void;
|
|
65
|
+
}
|
|
44
66
|
|
|
45
67
|
type ReactTableGridCustomComponent = <T, SR = unknown, K extends Key = Key>(props: IReactTableGridCustom<T, SR, K>) => JSX.Element;
|
|
46
68
|
declare const ReactTableGridCustom: ReactTableGridCustomComponent;
|
|
47
69
|
|
|
70
|
+
type ReactTableGridCustomPaginationClientComponent = <T, SR = unknown, K extends Key = Key>(props: ReactTableGridCustomPaginationClientProps<T, SR, K>) => JSX.Element;
|
|
71
|
+
interface ReactTableGridCustomPaginationClientProps<T = unknown, SR = unknown, K extends Key = Key> extends IReactTableGridCustom<T, SR, K> {
|
|
72
|
+
initPage?: number;
|
|
73
|
+
initPageSize?: number;
|
|
74
|
+
refTable?: MutableRefObject<refTablePaginationClient | undefined>;
|
|
75
|
+
}
|
|
76
|
+
declare const ReactTableGridCustomPaginationClient: ReactTableGridCustomPaginationClientComponent;
|
|
77
|
+
|
|
48
78
|
interface ContextMenuProps {
|
|
49
79
|
selector: string;
|
|
50
80
|
children?: ReactNode;
|
|
@@ -198,4 +228,4 @@ interface UseShowHideColumnReturn<T, SR> {
|
|
|
198
228
|
handleChangeLocation?: (arr: string[]) => void;
|
|
199
229
|
}
|
|
200
230
|
|
|
201
|
-
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn };
|
|
231
|
+
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, ReactTableGridCustomPaginationClient, type ReactTableGridCustomPaginationClientComponent, type ReactTableGridCustomPaginationClientProps, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn, useShowHideColumn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Dispatch, SetStateAction, Key, ReactNode, JSX, MutableRefObject } from 'react';
|
|
3
3
|
import { ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
4
4
|
export { Column, ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
5
5
|
import { PaginationRootProps } from '@mantine/core';
|
|
@@ -16,6 +16,24 @@ interface IObjectDynamic {
|
|
|
16
16
|
}
|
|
17
17
|
interface ISetConfigPagination$1 extends IPaginationParams$1, IObjectDynamic {
|
|
18
18
|
}
|
|
19
|
+
interface useShowHideColumnParameter<T, SR = unknown> {
|
|
20
|
+
nameLocal?: string;
|
|
21
|
+
/** nếu đầu vào là columns: Functions() thì nên dùng useMemo thì sẽ tối ưu hơn */
|
|
22
|
+
columns: TColumnsTable<T, SR>;
|
|
23
|
+
ignoreColumns?: string[];
|
|
24
|
+
}
|
|
25
|
+
interface useShowHideColumnReturn<T, SR> {
|
|
26
|
+
hiddenColumns: string[];
|
|
27
|
+
setHiddenColumns: Dispatch<SetStateAction<string[]>>;
|
|
28
|
+
columnsTable: TColumnsTable<T, SR>;
|
|
29
|
+
changeHiddenColumn: (key: string | string[]) => void;
|
|
30
|
+
newShowhideColumns: TColumnsTable<T, SR>;
|
|
31
|
+
locationColumns: string[];
|
|
32
|
+
handleFindLocation: (filterColumns: TColumnsTable<T, SR>, locationColumns?: string[]) => TColumnsTable<T, SR>;
|
|
33
|
+
handleChangeLocation?: (arr: string[]) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare const useShowHideColumn: <T, SR = unknown>({ nameLocal, columns, ignoreColumns }: useShowHideColumnParameter<T, SR>) => useShowHideColumnReturn<T, SR>;
|
|
19
37
|
|
|
20
38
|
interface IPaginationText {
|
|
21
39
|
from?: number;
|
|
@@ -41,10 +59,22 @@ interface IReactTableGridCustom<T = unknown, SR = unknown, K extends Key = Key>
|
|
|
41
59
|
fetching?: boolean;
|
|
42
60
|
TableLogo?: string;
|
|
43
61
|
}
|
|
62
|
+
interface refTablePaginationClient extends Required<IPaginationParams> {
|
|
63
|
+
setConfigSearch: Dispatch<SetStateAction<ISetConfigPagination$1>>;
|
|
64
|
+
resetPagition: (conditional?: boolean) => void;
|
|
65
|
+
}
|
|
44
66
|
|
|
45
67
|
type ReactTableGridCustomComponent = <T, SR = unknown, K extends Key = Key>(props: IReactTableGridCustom<T, SR, K>) => JSX.Element;
|
|
46
68
|
declare const ReactTableGridCustom: ReactTableGridCustomComponent;
|
|
47
69
|
|
|
70
|
+
type ReactTableGridCustomPaginationClientComponent = <T, SR = unknown, K extends Key = Key>(props: ReactTableGridCustomPaginationClientProps<T, SR, K>) => JSX.Element;
|
|
71
|
+
interface ReactTableGridCustomPaginationClientProps<T = unknown, SR = unknown, K extends Key = Key> extends IReactTableGridCustom<T, SR, K> {
|
|
72
|
+
initPage?: number;
|
|
73
|
+
initPageSize?: number;
|
|
74
|
+
refTable?: MutableRefObject<refTablePaginationClient | undefined>;
|
|
75
|
+
}
|
|
76
|
+
declare const ReactTableGridCustomPaginationClient: ReactTableGridCustomPaginationClientComponent;
|
|
77
|
+
|
|
48
78
|
interface ContextMenuProps {
|
|
49
79
|
selector: string;
|
|
50
80
|
children?: ReactNode;
|
|
@@ -198,4 +228,4 @@ interface UseShowHideColumnReturn<T, SR> {
|
|
|
198
228
|
handleChangeLocation?: (arr: string[]) => void;
|
|
199
229
|
}
|
|
200
230
|
|
|
201
|
-
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn };
|
|
231
|
+
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, ReactTableGridCustomPaginationClient, type ReactTableGridCustomPaginationClientComponent, type ReactTableGridCustomPaginationClientProps, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn, useShowHideColumn };
|
package/dist/index.js
CHANGED
|
@@ -31,17 +31,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ReactTableGridCustom: () => ReactTableGridCustom,
|
|
34
|
-
|
|
34
|
+
ReactTableGridCustomPaginationClient: () => ReactTableGridCustomPaginationClient,
|
|
35
|
+
TableStyleContextWapper: () => TableStyleContextWapper,
|
|
36
|
+
useShowHideColumn: () => useShowHideColumn
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(index_exports);
|
|
37
39
|
|
|
38
|
-
// src/
|
|
39
|
-
var
|
|
40
|
+
// src/helpers/functions.ts
|
|
41
|
+
var import_idb = require("idb");
|
|
40
42
|
var import_lodash = require("lodash");
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
var import_moment = __toESM(require("moment"));
|
|
44
|
+
var setLocalStore = (key, value) => {
|
|
45
|
+
if (typeof window !== "undefined") {
|
|
46
|
+
localStorage.setItem(key, value);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var getLocalStore = (key) => {
|
|
50
|
+
if (typeof window !== "undefined") {
|
|
51
|
+
return localStorage.getItem(key);
|
|
52
|
+
} else {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var toggleValues = ({ array, value }) => {
|
|
57
|
+
if (array.includes(value)) {
|
|
58
|
+
return array.filter((item) => item !== value);
|
|
59
|
+
} else {
|
|
60
|
+
return [...array, value];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var arrayLocal = (array) => {
|
|
64
|
+
try {
|
|
65
|
+
const data = array ? JSON.parse(array) : [];
|
|
66
|
+
return Array.isArray(data) ? data : [];
|
|
67
|
+
} catch {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
};
|
|
45
71
|
|
|
46
72
|
// src/helpers/table.ts
|
|
47
73
|
var calculatorTotalPage = ({ total = 0, pageSize = 0 }) => {
|
|
@@ -69,12 +95,128 @@ function cn(...inputs) {
|
|
|
69
95
|
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
70
96
|
}
|
|
71
97
|
|
|
72
|
-
// src/hooks/
|
|
98
|
+
// src/hooks/useShowHideColumn.ts
|
|
73
99
|
var import_react = require("react");
|
|
100
|
+
var import_lodash2 = require("lodash");
|
|
101
|
+
|
|
102
|
+
// src/type/table.ts
|
|
103
|
+
function isColumn(column) {
|
|
104
|
+
return "key" in column;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/hooks/useShowHideColumn.ts
|
|
108
|
+
var useShowHideColumn = ({
|
|
109
|
+
nameLocal = "table",
|
|
110
|
+
columns,
|
|
111
|
+
ignoreColumns
|
|
112
|
+
}) => {
|
|
113
|
+
const nameLocalLocation = `${nameLocal}_location`;
|
|
114
|
+
const [locationColumns, setLocationColumns] = (0, import_react.useState)(() => {
|
|
115
|
+
const dataLocal = getLocalStore(nameLocalLocation);
|
|
116
|
+
if (dataLocal) {
|
|
117
|
+
return arrayLocal(dataLocal);
|
|
118
|
+
}
|
|
119
|
+
return [];
|
|
120
|
+
});
|
|
121
|
+
const [hiddenColumns, setHiddenColumns] = (0, import_react.useState)(() => {
|
|
122
|
+
const dataLocal = getLocalStore(nameLocal);
|
|
123
|
+
if (dataLocal) {
|
|
124
|
+
return arrayLocal(dataLocal);
|
|
125
|
+
}
|
|
126
|
+
return [];
|
|
127
|
+
});
|
|
128
|
+
const handleFindLocation = (0, import_react.useCallback)(
|
|
129
|
+
(filterColumns, arrLoctions = locationColumns) => {
|
|
130
|
+
return (arrLoctions == null ? void 0 : arrLoctions.length) > 0 ? arrLoctions == null ? void 0 : arrLoctions.reduce(
|
|
131
|
+
(total, current) => {
|
|
132
|
+
const currentColumns = filterColumns == null ? void 0 : filterColumns.find((item) => {
|
|
133
|
+
const newItem = item;
|
|
134
|
+
return (newItem == null ? void 0 : newItem.key) === current;
|
|
135
|
+
});
|
|
136
|
+
if (currentColumns) {
|
|
137
|
+
total = [...total, currentColumns];
|
|
138
|
+
}
|
|
139
|
+
return total;
|
|
140
|
+
},
|
|
141
|
+
[]
|
|
142
|
+
) : filterColumns;
|
|
143
|
+
},
|
|
144
|
+
[locationColumns]
|
|
145
|
+
);
|
|
146
|
+
const newCloumnKeys = (0, import_react.useMemo)(
|
|
147
|
+
() => columns == null ? void 0 : columns.filter(isColumn).map((column) => column.key),
|
|
148
|
+
[columns]
|
|
149
|
+
);
|
|
150
|
+
const newColumns = (0, import_react.useMemo)(() => {
|
|
151
|
+
var _a;
|
|
152
|
+
const filterColumns = (_a = columns == null ? void 0 : columns.filter((column) => {
|
|
153
|
+
if (!isColumn(column)) return true;
|
|
154
|
+
const key = column.key;
|
|
155
|
+
if (ignoreColumns == null ? void 0 : ignoreColumns.includes(key)) return true;
|
|
156
|
+
if (hiddenColumns == null ? void 0 : hiddenColumns.includes(key)) return false;
|
|
157
|
+
return true;
|
|
158
|
+
})) != null ? _a : [];
|
|
159
|
+
return handleFindLocation(filterColumns);
|
|
160
|
+
}, [columns, hiddenColumns, locationColumns, ignoreColumns]);
|
|
161
|
+
const newShowhideColumns = (0, import_react.useMemo)(() => {
|
|
162
|
+
var _a;
|
|
163
|
+
if (!ignoreColumns) return columns;
|
|
164
|
+
return (_a = columns == null ? void 0 : columns.filter((column) => {
|
|
165
|
+
if (!isColumn(column)) return true;
|
|
166
|
+
return !ignoreColumns.includes(column.key);
|
|
167
|
+
})) != null ? _a : [];
|
|
168
|
+
}, [columns, ignoreColumns]);
|
|
169
|
+
const changeHiddenColumn = (0, import_react.useCallback)(
|
|
170
|
+
(key) => {
|
|
171
|
+
let newData = [...hiddenColumns];
|
|
172
|
+
if (typeof key === "string") {
|
|
173
|
+
newData = toggleValues({
|
|
174
|
+
array: newData,
|
|
175
|
+
value: key
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
newData = key;
|
|
179
|
+
}
|
|
180
|
+
setLocalStore(nameLocal, JSON.stringify(newData));
|
|
181
|
+
setHiddenColumns(newData);
|
|
182
|
+
},
|
|
183
|
+
[hiddenColumns, nameLocalLocation]
|
|
184
|
+
);
|
|
185
|
+
const handleChangeLocation = (0, import_react.useCallback)(
|
|
186
|
+
(key) => {
|
|
187
|
+
let newKey = key;
|
|
188
|
+
newKey = (0, import_lodash2.uniq)([...key, ...newCloumnKeys]);
|
|
189
|
+
setLocationColumns(newKey);
|
|
190
|
+
setLocalStore(nameLocalLocation, JSON.stringify(newKey));
|
|
191
|
+
},
|
|
192
|
+
[newCloumnKeys]
|
|
193
|
+
);
|
|
194
|
+
return {
|
|
195
|
+
hiddenColumns,
|
|
196
|
+
setHiddenColumns,
|
|
197
|
+
columnsTable: newColumns,
|
|
198
|
+
changeHiddenColumn,
|
|
199
|
+
newShowhideColumns,
|
|
200
|
+
locationColumns,
|
|
201
|
+
handleFindLocation,
|
|
202
|
+
handleChangeLocation
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/component/ui/Table/ReactTableGridCustom.tsx
|
|
207
|
+
var import_core = require("@mantine/core");
|
|
208
|
+
var import_lodash3 = require("lodash");
|
|
209
|
+
var import_react3 = require("react");
|
|
210
|
+
var import_react_data_grid = require("react-data-grid");
|
|
211
|
+
var import_styles = require("react-data-grid/lib/styles.css");
|
|
212
|
+
var import_react_i18next2 = require("react-i18next");
|
|
213
|
+
|
|
214
|
+
// src/hooks/useTranslationTable.ts
|
|
215
|
+
var import_react2 = require("react");
|
|
74
216
|
var import_react_i18next = require("react-i18next");
|
|
75
217
|
var useTranslationTable = (column) => {
|
|
76
218
|
const { i18n, t } = (0, import_react_i18next.useTranslation)();
|
|
77
|
-
const columnTranslation = (0,
|
|
219
|
+
const columnTranslation = (0, import_react2.useMemo)(() => {
|
|
78
220
|
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
79
221
|
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
80
222
|
return columnTranslation;
|
|
@@ -173,16 +315,16 @@ var ReactTableGridCustomInner = ({
|
|
|
173
315
|
...spread
|
|
174
316
|
}) => {
|
|
175
317
|
const { t } = (0, import_react_i18next2.useTranslation)();
|
|
176
|
-
const tableRef = (0,
|
|
177
|
-
const [isLoading, setIsLoading] = (0,
|
|
178
|
-
const [containerWidth, setContainerWidth] = (0,
|
|
179
|
-
const [sortColumns, setSortColumns] = (0,
|
|
318
|
+
const tableRef = (0, import_react3.useRef)(null);
|
|
319
|
+
const [isLoading, setIsLoading] = (0, import_react3.useState)(true);
|
|
320
|
+
const [containerWidth, setContainerWidth] = (0, import_react3.useState)(0);
|
|
321
|
+
const [sortColumns, setSortColumns] = (0, import_react3.useState)([]);
|
|
180
322
|
const isSelectRow = selectedRows !== void 0;
|
|
181
|
-
const maxPage = (0,
|
|
323
|
+
const maxPage = (0, import_react3.useMemo)(
|
|
182
324
|
() => !hiddenPagination ? calculatorTotalPage({ total, pageSize }) : 0,
|
|
183
325
|
[pageSize, total, hiddenPagination]
|
|
184
326
|
);
|
|
185
|
-
const toInPagination = (0,
|
|
327
|
+
const toInPagination = (0, import_react3.useMemo)(() => {
|
|
186
328
|
if (!hiddenPaginationText && page && pageSize) {
|
|
187
329
|
const from = STT({ page, pageSize }, 0);
|
|
188
330
|
return {
|
|
@@ -195,7 +337,7 @@ var ReactTableGridCustomInner = ({
|
|
|
195
337
|
const columnTranslation = useTranslationTable_default(
|
|
196
338
|
columns
|
|
197
339
|
);
|
|
198
|
-
const newColumns = (0,
|
|
340
|
+
const newColumns = (0, import_react3.useMemo)(() => {
|
|
199
341
|
let cols = [
|
|
200
342
|
...columnTranslation
|
|
201
343
|
];
|
|
@@ -228,13 +370,13 @@ var ReactTableGridCustomInner = ({
|
|
|
228
370
|
page,
|
|
229
371
|
pageSize
|
|
230
372
|
]);
|
|
231
|
-
const customRowKeyGetter = (0,
|
|
373
|
+
const customRowKeyGetter = (0, import_react3.useCallback)(
|
|
232
374
|
(row) => {
|
|
233
375
|
if (typeof rowKeyGetter === "function") {
|
|
234
376
|
return rowKeyGetter(row);
|
|
235
377
|
}
|
|
236
378
|
if (typeof rowKeyGetter === "string") {
|
|
237
|
-
return (0,
|
|
379
|
+
return (0, import_lodash3.get)(row, rowKeyGetter);
|
|
238
380
|
}
|
|
239
381
|
throw new Error(
|
|
240
382
|
"rowKeyGetter must be a string or a function"
|
|
@@ -242,15 +384,15 @@ var ReactTableGridCustomInner = ({
|
|
|
242
384
|
},
|
|
243
385
|
[rowKeyGetter]
|
|
244
386
|
);
|
|
245
|
-
const sortedRows = (0,
|
|
387
|
+
const sortedRows = (0, import_react3.useMemo)(() => {
|
|
246
388
|
if (!sortColumns.length) return data;
|
|
247
389
|
const { columnKey, direction } = sortColumns[0];
|
|
248
390
|
if (!direction) return data;
|
|
249
391
|
const order = direction === "ASC" ? "asc" : "desc";
|
|
250
392
|
const iteratee = typeof columnKey === "string" ? columnKey : String(columnKey);
|
|
251
|
-
return (0,
|
|
393
|
+
return (0, import_lodash3.orderBy)(data, [iteratee], [order]);
|
|
252
394
|
}, [data, sortColumns]);
|
|
253
|
-
(0,
|
|
395
|
+
(0, import_react3.useEffect)(() => {
|
|
254
396
|
var _a;
|
|
255
397
|
setIsLoading(false);
|
|
256
398
|
if ((_a = tableRef.current) == null ? void 0 : _a.element) {
|
|
@@ -300,20 +442,103 @@ var ReactTableGridCustomInner = ({
|
|
|
300
442
|
}
|
|
301
443
|
);
|
|
302
444
|
};
|
|
303
|
-
var ReactTableGridCustom = (0,
|
|
445
|
+
var ReactTableGridCustom = (0, import_react3.memo)(
|
|
304
446
|
ReactTableGridCustomInner
|
|
305
447
|
);
|
|
306
448
|
|
|
449
|
+
// src/component/ui/Table/ReactTableGridCustomPaginationClient.tsx
|
|
450
|
+
var import_react5 = require("react");
|
|
451
|
+
|
|
452
|
+
// src/hooks/useDataPagingClient.ts
|
|
453
|
+
var import_react4 = require("react");
|
|
454
|
+
var useDataPagingClient = ({ data = [], page, pageSize }) => {
|
|
455
|
+
const newData = (0, import_react4.useMemo)(() => {
|
|
456
|
+
if (page && pageSize) {
|
|
457
|
+
const startIndex = (page - 1) * pageSize;
|
|
458
|
+
return data.slice(startIndex, startIndex + pageSize);
|
|
459
|
+
}
|
|
460
|
+
return data;
|
|
461
|
+
}, [data, page, pageSize]);
|
|
462
|
+
return newData;
|
|
463
|
+
};
|
|
464
|
+
var useDataPagingClient_default = useDataPagingClient;
|
|
465
|
+
|
|
466
|
+
// src/component/ui/Table/ReactTableGridCustomPaginationClient.tsx
|
|
467
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
468
|
+
var ReactTableGridCustomPaginationClientInner = ({
|
|
469
|
+
data,
|
|
470
|
+
initPage = 1,
|
|
471
|
+
initPageSize = 200,
|
|
472
|
+
refTable,
|
|
473
|
+
...spread
|
|
474
|
+
}) => {
|
|
475
|
+
const [configSearch, setConfigSearch] = (0, import_react5.useState)({
|
|
476
|
+
page: initPage,
|
|
477
|
+
pageSize: initPageSize
|
|
478
|
+
});
|
|
479
|
+
const newDataAccount = useDataPagingClient_default({
|
|
480
|
+
data,
|
|
481
|
+
page: configSearch == null ? void 0 : configSearch.page,
|
|
482
|
+
pageSize: configSearch == null ? void 0 : configSearch.pageSize
|
|
483
|
+
});
|
|
484
|
+
const resetPage = (0, import_react5.useCallback)(() => {
|
|
485
|
+
setConfigSearch((prev) => ({
|
|
486
|
+
...prev,
|
|
487
|
+
page: 1
|
|
488
|
+
}));
|
|
489
|
+
}, []);
|
|
490
|
+
(0, import_react5.useImperativeHandle)(
|
|
491
|
+
refTable,
|
|
492
|
+
() => {
|
|
493
|
+
var _a, _b;
|
|
494
|
+
return {
|
|
495
|
+
setConfigSearch,
|
|
496
|
+
page: (_a = configSearch == null ? void 0 : configSearch.page) != null ? _a : initPage,
|
|
497
|
+
pageSize: (_b = configSearch == null ? void 0 : configSearch.pageSize) != null ? _b : initPageSize,
|
|
498
|
+
resetPagition: (conditional = true) => {
|
|
499
|
+
if (conditional && (configSearch == null ? void 0 : configSearch.page) !== 1) {
|
|
500
|
+
resetPage();
|
|
501
|
+
} else {
|
|
502
|
+
resetPage();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
},
|
|
507
|
+
[
|
|
508
|
+
setConfigSearch,
|
|
509
|
+
configSearch == null ? void 0 : configSearch.page,
|
|
510
|
+
configSearch == null ? void 0 : configSearch.pageSize,
|
|
511
|
+
initPage,
|
|
512
|
+
initPageSize,
|
|
513
|
+
resetPage
|
|
514
|
+
]
|
|
515
|
+
);
|
|
516
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
517
|
+
ReactTableGridCustom,
|
|
518
|
+
{
|
|
519
|
+
data: newDataAccount,
|
|
520
|
+
total: data == null ? void 0 : data.length,
|
|
521
|
+
page: configSearch == null ? void 0 : configSearch.page,
|
|
522
|
+
pageSize: configSearch == null ? void 0 : configSearch.pageSize,
|
|
523
|
+
setConfigPagination: setConfigSearch,
|
|
524
|
+
...spread
|
|
525
|
+
}
|
|
526
|
+
);
|
|
527
|
+
};
|
|
528
|
+
var ReactTableGridCustomPaginationClient = (0, import_react5.memo)(
|
|
529
|
+
ReactTableGridCustomPaginationClientInner
|
|
530
|
+
);
|
|
531
|
+
|
|
307
532
|
// src/component/ui/Table/TableStyleContextWapper.tsx
|
|
308
|
-
var
|
|
533
|
+
var import_react10 = require("react");
|
|
309
534
|
|
|
310
535
|
// src/component/ui/ContextMenu/ContextMenu.tsx
|
|
311
|
-
var
|
|
536
|
+
var import_react6 = require("react");
|
|
312
537
|
var import_react_dom = require("react-dom");
|
|
313
|
-
var
|
|
538
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
314
539
|
var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
315
|
-
const menuRef = (0,
|
|
316
|
-
const closeMenu = (0,
|
|
540
|
+
const menuRef = (0, import_react6.useRef)(null);
|
|
541
|
+
const closeMenu = (0, import_react6.useCallback)(() => {
|
|
317
542
|
const contextMenuElem = menuRef.current;
|
|
318
543
|
const elementParent = document.querySelector(selector);
|
|
319
544
|
if (contextMenuElem && contextMenuElem.classList.contains("shadow-menu")) {
|
|
@@ -325,7 +550,7 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
325
550
|
elementParent.style.removeProperty("overflow");
|
|
326
551
|
}
|
|
327
552
|
}, [menuRef.current]);
|
|
328
|
-
(0,
|
|
553
|
+
(0, import_react6.useEffect)(() => {
|
|
329
554
|
const elementParent = document.querySelector(selector);
|
|
330
555
|
if (elementParent) {
|
|
331
556
|
const clickMenu = (e) => {
|
|
@@ -393,7 +618,7 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
393
618
|
};
|
|
394
619
|
}, []);
|
|
395
620
|
return (0, import_react_dom.createPortal)(
|
|
396
|
-
/* @__PURE__ */ (0,
|
|
621
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
397
622
|
"div",
|
|
398
623
|
{
|
|
399
624
|
className: "fixed z-40 w-fit",
|
|
@@ -408,12 +633,12 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
408
633
|
var ContextMenu_default = ContextMenu;
|
|
409
634
|
|
|
410
635
|
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
411
|
-
var
|
|
636
|
+
var import_react9 = require("react");
|
|
412
637
|
|
|
413
638
|
// src/component/ui/ContextMenu/ContextMenuItem.tsx
|
|
414
639
|
var import_react_i18next3 = require("react-i18next");
|
|
415
640
|
var import_md = require("react-icons/md");
|
|
416
|
-
var
|
|
641
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
417
642
|
var ContextMenuItem = ({
|
|
418
643
|
currentValue,
|
|
419
644
|
expandValue,
|
|
@@ -423,7 +648,7 @@ var ContextMenuItem = ({
|
|
|
423
648
|
}) => {
|
|
424
649
|
const { t } = (0, import_react_i18next3.useTranslation)();
|
|
425
650
|
const Icon = currentValue.Icon;
|
|
426
|
-
return /* @__PURE__ */ (0,
|
|
651
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
427
652
|
"div",
|
|
428
653
|
{
|
|
429
654
|
className: `cursor-pointer p-2 flex items-center space-x-2 relative ${show ? "bg-[#555] text-white" : "hover:bg-[#555] hover:text-white"}`,
|
|
@@ -432,9 +657,9 @@ var ContextMenuItem = ({
|
|
|
432
657
|
expandValue && valueClickItem && (currentValue == null ? void 0 : currentValue.onClick) && ((_a = currentValue == null ? void 0 : currentValue.onClick) == null ? void 0 : _a.call(currentValue, valueClickItem, expandValue));
|
|
433
658
|
},
|
|
434
659
|
children: [
|
|
435
|
-
/* @__PURE__ */ (0,
|
|
436
|
-
/* @__PURE__ */ (0,
|
|
437
|
-
isArrow && /* @__PURE__ */ (0,
|
|
660
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { size: 20 }),
|
|
661
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-sm flex-1", children: t(`${currentValue.action}`) }),
|
|
662
|
+
isArrow && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_md.MdKeyboardArrowRight, { size: 20 })
|
|
438
663
|
]
|
|
439
664
|
}
|
|
440
665
|
);
|
|
@@ -442,14 +667,14 @@ var ContextMenuItem = ({
|
|
|
442
667
|
var ContextMenuItem_default = ContextMenuItem;
|
|
443
668
|
|
|
444
669
|
// src/component/ui/ContextMenu/DropdownContextChild.tsx
|
|
445
|
-
var
|
|
446
|
-
var
|
|
447
|
-
var
|
|
670
|
+
var import_react7 = __toESM(require("@tippyjs/react"));
|
|
671
|
+
var import_react8 = require("react");
|
|
672
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
448
673
|
var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
449
|
-
const id = (0,
|
|
450
|
-
const instanceRef = (0,
|
|
451
|
-
return /* @__PURE__ */ (0,
|
|
452
|
-
|
|
674
|
+
const id = (0, import_react8.useId)();
|
|
675
|
+
const instanceRef = (0, import_react8.useRef)(null);
|
|
676
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
677
|
+
import_react7.default,
|
|
453
678
|
{
|
|
454
679
|
theme: "drop-down",
|
|
455
680
|
className: "!bg-transparent !text-inherit !border-r-0 [&>*]:!p-0",
|
|
@@ -460,7 +685,7 @@ var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
|
460
685
|
allowHTML: true,
|
|
461
686
|
content: children,
|
|
462
687
|
...rest,
|
|
463
|
-
children: /* @__PURE__ */ (0,
|
|
688
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
464
689
|
"div",
|
|
465
690
|
{
|
|
466
691
|
id: `div-${id}`,
|
|
@@ -477,16 +702,16 @@ var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
|
477
702
|
var DropdownContextChild_default = DropdownContextChild;
|
|
478
703
|
|
|
479
704
|
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
480
|
-
var
|
|
705
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
481
706
|
var RenderContextMenu = ({
|
|
482
707
|
renderData,
|
|
483
708
|
valueClickItem,
|
|
484
709
|
expandValue = {}
|
|
485
710
|
}) => {
|
|
486
|
-
return /* @__PURE__ */ (0,
|
|
487
|
-
const [isShow, setIsShow] = (0,
|
|
488
|
-
return /* @__PURE__ */ (0,
|
|
489
|
-
!(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ (0,
|
|
711
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "bg-white shadow-submenu p-1 min-w-[250px] border", children: renderData == null ? void 0 : renderData.map((menuAction, index) => {
|
|
712
|
+
const [isShow, setIsShow] = (0, import_react9.useState)(false);
|
|
713
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react9.Fragment, { children: [
|
|
714
|
+
!(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
490
715
|
ContextMenuItem_default,
|
|
491
716
|
{
|
|
492
717
|
currentValue: menuAction,
|
|
@@ -494,7 +719,7 @@ var RenderContextMenu = ({
|
|
|
494
719
|
valueClickItem
|
|
495
720
|
}
|
|
496
721
|
),
|
|
497
|
-
(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ (0,
|
|
722
|
+
(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
498
723
|
DropdownContextChild_default,
|
|
499
724
|
{
|
|
500
725
|
appendTo: "parent",
|
|
@@ -502,7 +727,7 @@ var RenderContextMenu = ({
|
|
|
502
727
|
offset: [0, 5],
|
|
503
728
|
onShow: () => setIsShow(true),
|
|
504
729
|
onHide: () => setIsShow(false),
|
|
505
|
-
button: /* @__PURE__ */ (0,
|
|
730
|
+
button: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
506
731
|
ContextMenuItem_default,
|
|
507
732
|
{
|
|
508
733
|
currentValue: menuAction,
|
|
@@ -512,7 +737,7 @@ var RenderContextMenu = ({
|
|
|
512
737
|
isArrow: true
|
|
513
738
|
}
|
|
514
739
|
),
|
|
515
|
-
children: /* @__PURE__ */ (0,
|
|
740
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "dropdown-context-child absolute -top-[20px] -left-1", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
516
741
|
RenderContextMenu,
|
|
517
742
|
{
|
|
518
743
|
renderData: menuAction == null ? void 0 : menuAction.children,
|
|
@@ -528,26 +753,26 @@ var RenderContextMenu = ({
|
|
|
528
753
|
var RenderContextMenu_default = RenderContextMenu;
|
|
529
754
|
|
|
530
755
|
// src/component/ui/Table/TableStyleContextWapper.tsx
|
|
531
|
-
var
|
|
756
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
532
757
|
var TableStyleContextMenuWapper = ({
|
|
533
758
|
children,
|
|
534
759
|
contextMenuProps,
|
|
535
760
|
clsTablecustom,
|
|
536
761
|
renderContext
|
|
537
762
|
}) => {
|
|
538
|
-
const idWapper = (0,
|
|
539
|
-
return /* @__PURE__ */ (0,
|
|
763
|
+
const idWapper = (0, import_react10.useId)();
|
|
764
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
540
765
|
"div",
|
|
541
766
|
{
|
|
542
767
|
id: `wapper_menu_context-${idWapper}`,
|
|
543
768
|
className: `border border-[#dedede] rounded-xl overflow-hidden bg-white flex-1 h-full flex flex-col min-h-[360px] ${clsTablecustom != null ? clsTablecustom : ""}`,
|
|
544
769
|
children: [
|
|
545
|
-
(renderContext == null ? void 0 : renderContext.renderData) && /* @__PURE__ */ (0,
|
|
770
|
+
(renderContext == null ? void 0 : renderContext.renderData) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
546
771
|
ContextMenu_default,
|
|
547
772
|
{
|
|
548
773
|
selector: `[id="wapper_menu_context-${idWapper}"] .rdg`,
|
|
549
774
|
...contextMenuProps,
|
|
550
|
-
children: /* @__PURE__ */ (0,
|
|
775
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(RenderContextMenu_default, { ...renderContext })
|
|
551
776
|
}
|
|
552
777
|
),
|
|
553
778
|
children
|
|
@@ -555,11 +780,13 @@ var TableStyleContextMenuWapper = ({
|
|
|
555
780
|
}
|
|
556
781
|
);
|
|
557
782
|
};
|
|
558
|
-
var TableStyleContextWapper = (0,
|
|
783
|
+
var TableStyleContextWapper = (0, import_react10.memo)(
|
|
559
784
|
TableStyleContextMenuWapper
|
|
560
785
|
);
|
|
561
786
|
// Annotate the CommonJS export names for ESM import in node:
|
|
562
787
|
0 && (module.exports = {
|
|
563
788
|
ReactTableGridCustom,
|
|
564
|
-
|
|
789
|
+
ReactTableGridCustomPaginationClient,
|
|
790
|
+
TableStyleContextWapper,
|
|
791
|
+
useShowHideColumn
|
|
565
792
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
// src/helpers/functions.ts
|
|
2
|
+
import { deleteDB, openDB } from "idb";
|
|
3
|
+
import { pickBy } from "lodash";
|
|
4
|
+
import moment from "moment";
|
|
5
|
+
var setLocalStore = (key, value) => {
|
|
6
|
+
if (typeof window !== "undefined") {
|
|
7
|
+
localStorage.setItem(key, value);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var getLocalStore = (key) => {
|
|
11
|
+
if (typeof window !== "undefined") {
|
|
12
|
+
return localStorage.getItem(key);
|
|
13
|
+
} else {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var toggleValues = ({ array, value }) => {
|
|
18
|
+
if (array.includes(value)) {
|
|
19
|
+
return array.filter((item) => item !== value);
|
|
20
|
+
} else {
|
|
21
|
+
return [...array, value];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var arrayLocal = (array) => {
|
|
25
|
+
try {
|
|
26
|
+
const data = array ? JSON.parse(array) : [];
|
|
27
|
+
return Array.isArray(data) ? data : [];
|
|
28
|
+
} catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
18
32
|
|
|
19
33
|
// src/helpers/table.ts
|
|
20
34
|
var calculatorTotalPage = ({ total = 0, pageSize = 0 }) => {
|
|
@@ -42,12 +56,138 @@ function cn(...inputs) {
|
|
|
42
56
|
return twMerge(clsx(inputs));
|
|
43
57
|
}
|
|
44
58
|
|
|
59
|
+
// src/hooks/useShowHideColumn.ts
|
|
60
|
+
import { useCallback, useMemo, useState } from "react";
|
|
61
|
+
import { uniq } from "lodash";
|
|
62
|
+
|
|
63
|
+
// src/type/table.ts
|
|
64
|
+
function isColumn(column) {
|
|
65
|
+
return "key" in column;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/hooks/useShowHideColumn.ts
|
|
69
|
+
var useShowHideColumn = ({
|
|
70
|
+
nameLocal = "table",
|
|
71
|
+
columns,
|
|
72
|
+
ignoreColumns
|
|
73
|
+
}) => {
|
|
74
|
+
const nameLocalLocation = `${nameLocal}_location`;
|
|
75
|
+
const [locationColumns, setLocationColumns] = useState(() => {
|
|
76
|
+
const dataLocal = getLocalStore(nameLocalLocation);
|
|
77
|
+
if (dataLocal) {
|
|
78
|
+
return arrayLocal(dataLocal);
|
|
79
|
+
}
|
|
80
|
+
return [];
|
|
81
|
+
});
|
|
82
|
+
const [hiddenColumns, setHiddenColumns] = useState(() => {
|
|
83
|
+
const dataLocal = getLocalStore(nameLocal);
|
|
84
|
+
if (dataLocal) {
|
|
85
|
+
return arrayLocal(dataLocal);
|
|
86
|
+
}
|
|
87
|
+
return [];
|
|
88
|
+
});
|
|
89
|
+
const handleFindLocation = useCallback(
|
|
90
|
+
(filterColumns, arrLoctions = locationColumns) => {
|
|
91
|
+
return (arrLoctions == null ? void 0 : arrLoctions.length) > 0 ? arrLoctions == null ? void 0 : arrLoctions.reduce(
|
|
92
|
+
(total, current) => {
|
|
93
|
+
const currentColumns = filterColumns == null ? void 0 : filterColumns.find((item) => {
|
|
94
|
+
const newItem = item;
|
|
95
|
+
return (newItem == null ? void 0 : newItem.key) === current;
|
|
96
|
+
});
|
|
97
|
+
if (currentColumns) {
|
|
98
|
+
total = [...total, currentColumns];
|
|
99
|
+
}
|
|
100
|
+
return total;
|
|
101
|
+
},
|
|
102
|
+
[]
|
|
103
|
+
) : filterColumns;
|
|
104
|
+
},
|
|
105
|
+
[locationColumns]
|
|
106
|
+
);
|
|
107
|
+
const newCloumnKeys = useMemo(
|
|
108
|
+
() => columns == null ? void 0 : columns.filter(isColumn).map((column) => column.key),
|
|
109
|
+
[columns]
|
|
110
|
+
);
|
|
111
|
+
const newColumns = useMemo(() => {
|
|
112
|
+
var _a;
|
|
113
|
+
const filterColumns = (_a = columns == null ? void 0 : columns.filter((column) => {
|
|
114
|
+
if (!isColumn(column)) return true;
|
|
115
|
+
const key = column.key;
|
|
116
|
+
if (ignoreColumns == null ? void 0 : ignoreColumns.includes(key)) return true;
|
|
117
|
+
if (hiddenColumns == null ? void 0 : hiddenColumns.includes(key)) return false;
|
|
118
|
+
return true;
|
|
119
|
+
})) != null ? _a : [];
|
|
120
|
+
return handleFindLocation(filterColumns);
|
|
121
|
+
}, [columns, hiddenColumns, locationColumns, ignoreColumns]);
|
|
122
|
+
const newShowhideColumns = useMemo(() => {
|
|
123
|
+
var _a;
|
|
124
|
+
if (!ignoreColumns) return columns;
|
|
125
|
+
return (_a = columns == null ? void 0 : columns.filter((column) => {
|
|
126
|
+
if (!isColumn(column)) return true;
|
|
127
|
+
return !ignoreColumns.includes(column.key);
|
|
128
|
+
})) != null ? _a : [];
|
|
129
|
+
}, [columns, ignoreColumns]);
|
|
130
|
+
const changeHiddenColumn = useCallback(
|
|
131
|
+
(key) => {
|
|
132
|
+
let newData = [...hiddenColumns];
|
|
133
|
+
if (typeof key === "string") {
|
|
134
|
+
newData = toggleValues({
|
|
135
|
+
array: newData,
|
|
136
|
+
value: key
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
newData = key;
|
|
140
|
+
}
|
|
141
|
+
setLocalStore(nameLocal, JSON.stringify(newData));
|
|
142
|
+
setHiddenColumns(newData);
|
|
143
|
+
},
|
|
144
|
+
[hiddenColumns, nameLocalLocation]
|
|
145
|
+
);
|
|
146
|
+
const handleChangeLocation = useCallback(
|
|
147
|
+
(key) => {
|
|
148
|
+
let newKey = key;
|
|
149
|
+
newKey = uniq([...key, ...newCloumnKeys]);
|
|
150
|
+
setLocationColumns(newKey);
|
|
151
|
+
setLocalStore(nameLocalLocation, JSON.stringify(newKey));
|
|
152
|
+
},
|
|
153
|
+
[newCloumnKeys]
|
|
154
|
+
);
|
|
155
|
+
return {
|
|
156
|
+
hiddenColumns,
|
|
157
|
+
setHiddenColumns,
|
|
158
|
+
columnsTable: newColumns,
|
|
159
|
+
changeHiddenColumn,
|
|
160
|
+
newShowhideColumns,
|
|
161
|
+
locationColumns,
|
|
162
|
+
handleFindLocation,
|
|
163
|
+
handleChangeLocation
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/component/ui/Table/ReactTableGridCustom.tsx
|
|
168
|
+
import { Checkbox } from "@mantine/core";
|
|
169
|
+
import { get, orderBy } from "lodash";
|
|
170
|
+
import {
|
|
171
|
+
memo,
|
|
172
|
+
useCallback as useCallback2,
|
|
173
|
+
useEffect,
|
|
174
|
+
useMemo as useMemo3,
|
|
175
|
+
useRef,
|
|
176
|
+
useState as useState2
|
|
177
|
+
} from "react";
|
|
178
|
+
import {
|
|
179
|
+
DataGrid,
|
|
180
|
+
SelectColumn
|
|
181
|
+
} from "react-data-grid";
|
|
182
|
+
import "react-data-grid/lib/styles.css";
|
|
183
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
184
|
+
|
|
45
185
|
// src/hooks/useTranslationTable.ts
|
|
46
|
-
import { useMemo } from "react";
|
|
186
|
+
import { useMemo as useMemo2 } from "react";
|
|
47
187
|
import { useTranslation } from "react-i18next";
|
|
48
188
|
var useTranslationTable = (column) => {
|
|
49
189
|
const { i18n, t } = useTranslation();
|
|
50
|
-
const columnTranslation =
|
|
190
|
+
const columnTranslation = useMemo2(() => {
|
|
51
191
|
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
52
192
|
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
53
193
|
return columnTranslation;
|
|
@@ -147,15 +287,15 @@ var ReactTableGridCustomInner = ({
|
|
|
147
287
|
}) => {
|
|
148
288
|
const { t } = useTranslation2();
|
|
149
289
|
const tableRef = useRef(null);
|
|
150
|
-
const [isLoading, setIsLoading] =
|
|
151
|
-
const [containerWidth, setContainerWidth] =
|
|
152
|
-
const [sortColumns, setSortColumns] =
|
|
290
|
+
const [isLoading, setIsLoading] = useState2(true);
|
|
291
|
+
const [containerWidth, setContainerWidth] = useState2(0);
|
|
292
|
+
const [sortColumns, setSortColumns] = useState2([]);
|
|
153
293
|
const isSelectRow = selectedRows !== void 0;
|
|
154
|
-
const maxPage =
|
|
294
|
+
const maxPage = useMemo3(
|
|
155
295
|
() => !hiddenPagination ? calculatorTotalPage({ total, pageSize }) : 0,
|
|
156
296
|
[pageSize, total, hiddenPagination]
|
|
157
297
|
);
|
|
158
|
-
const toInPagination =
|
|
298
|
+
const toInPagination = useMemo3(() => {
|
|
159
299
|
if (!hiddenPaginationText && page && pageSize) {
|
|
160
300
|
const from = STT({ page, pageSize }, 0);
|
|
161
301
|
return {
|
|
@@ -168,7 +308,7 @@ var ReactTableGridCustomInner = ({
|
|
|
168
308
|
const columnTranslation = useTranslationTable_default(
|
|
169
309
|
columns
|
|
170
310
|
);
|
|
171
|
-
const newColumns =
|
|
311
|
+
const newColumns = useMemo3(() => {
|
|
172
312
|
let cols = [
|
|
173
313
|
...columnTranslation
|
|
174
314
|
];
|
|
@@ -201,7 +341,7 @@ var ReactTableGridCustomInner = ({
|
|
|
201
341
|
page,
|
|
202
342
|
pageSize
|
|
203
343
|
]);
|
|
204
|
-
const customRowKeyGetter =
|
|
344
|
+
const customRowKeyGetter = useCallback2(
|
|
205
345
|
(row) => {
|
|
206
346
|
if (typeof rowKeyGetter === "function") {
|
|
207
347
|
return rowKeyGetter(row);
|
|
@@ -215,7 +355,7 @@ var ReactTableGridCustomInner = ({
|
|
|
215
355
|
},
|
|
216
356
|
[rowKeyGetter]
|
|
217
357
|
);
|
|
218
|
-
const sortedRows =
|
|
358
|
+
const sortedRows = useMemo3(() => {
|
|
219
359
|
if (!sortColumns.length) return data;
|
|
220
360
|
const { columnKey, direction } = sortColumns[0];
|
|
221
361
|
if (!direction) return data;
|
|
@@ -277,16 +417,104 @@ var ReactTableGridCustom = memo(
|
|
|
277
417
|
ReactTableGridCustomInner
|
|
278
418
|
);
|
|
279
419
|
|
|
420
|
+
// src/component/ui/Table/ReactTableGridCustomPaginationClient.tsx
|
|
421
|
+
import {
|
|
422
|
+
memo as memo2,
|
|
423
|
+
useCallback as useCallback3,
|
|
424
|
+
useImperativeHandle,
|
|
425
|
+
useState as useState3
|
|
426
|
+
} from "react";
|
|
427
|
+
|
|
428
|
+
// src/hooks/useDataPagingClient.ts
|
|
429
|
+
import { useMemo as useMemo4 } from "react";
|
|
430
|
+
var useDataPagingClient = ({ data = [], page, pageSize }) => {
|
|
431
|
+
const newData = useMemo4(() => {
|
|
432
|
+
if (page && pageSize) {
|
|
433
|
+
const startIndex = (page - 1) * pageSize;
|
|
434
|
+
return data.slice(startIndex, startIndex + pageSize);
|
|
435
|
+
}
|
|
436
|
+
return data;
|
|
437
|
+
}, [data, page, pageSize]);
|
|
438
|
+
return newData;
|
|
439
|
+
};
|
|
440
|
+
var useDataPagingClient_default = useDataPagingClient;
|
|
441
|
+
|
|
442
|
+
// src/component/ui/Table/ReactTableGridCustomPaginationClient.tsx
|
|
443
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
444
|
+
var ReactTableGridCustomPaginationClientInner = ({
|
|
445
|
+
data,
|
|
446
|
+
initPage = 1,
|
|
447
|
+
initPageSize = 200,
|
|
448
|
+
refTable,
|
|
449
|
+
...spread
|
|
450
|
+
}) => {
|
|
451
|
+
const [configSearch, setConfigSearch] = useState3({
|
|
452
|
+
page: initPage,
|
|
453
|
+
pageSize: initPageSize
|
|
454
|
+
});
|
|
455
|
+
const newDataAccount = useDataPagingClient_default({
|
|
456
|
+
data,
|
|
457
|
+
page: configSearch == null ? void 0 : configSearch.page,
|
|
458
|
+
pageSize: configSearch == null ? void 0 : configSearch.pageSize
|
|
459
|
+
});
|
|
460
|
+
const resetPage = useCallback3(() => {
|
|
461
|
+
setConfigSearch((prev) => ({
|
|
462
|
+
...prev,
|
|
463
|
+
page: 1
|
|
464
|
+
}));
|
|
465
|
+
}, []);
|
|
466
|
+
useImperativeHandle(
|
|
467
|
+
refTable,
|
|
468
|
+
() => {
|
|
469
|
+
var _a, _b;
|
|
470
|
+
return {
|
|
471
|
+
setConfigSearch,
|
|
472
|
+
page: (_a = configSearch == null ? void 0 : configSearch.page) != null ? _a : initPage,
|
|
473
|
+
pageSize: (_b = configSearch == null ? void 0 : configSearch.pageSize) != null ? _b : initPageSize,
|
|
474
|
+
resetPagition: (conditional = true) => {
|
|
475
|
+
if (conditional && (configSearch == null ? void 0 : configSearch.page) !== 1) {
|
|
476
|
+
resetPage();
|
|
477
|
+
} else {
|
|
478
|
+
resetPage();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
},
|
|
483
|
+
[
|
|
484
|
+
setConfigSearch,
|
|
485
|
+
configSearch == null ? void 0 : configSearch.page,
|
|
486
|
+
configSearch == null ? void 0 : configSearch.pageSize,
|
|
487
|
+
initPage,
|
|
488
|
+
initPageSize,
|
|
489
|
+
resetPage
|
|
490
|
+
]
|
|
491
|
+
);
|
|
492
|
+
return /* @__PURE__ */ jsx4(
|
|
493
|
+
ReactTableGridCustom,
|
|
494
|
+
{
|
|
495
|
+
data: newDataAccount,
|
|
496
|
+
total: data == null ? void 0 : data.length,
|
|
497
|
+
page: configSearch == null ? void 0 : configSearch.page,
|
|
498
|
+
pageSize: configSearch == null ? void 0 : configSearch.pageSize,
|
|
499
|
+
setConfigPagination: setConfigSearch,
|
|
500
|
+
...spread
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
};
|
|
504
|
+
var ReactTableGridCustomPaginationClient = memo2(
|
|
505
|
+
ReactTableGridCustomPaginationClientInner
|
|
506
|
+
);
|
|
507
|
+
|
|
280
508
|
// src/component/ui/Table/TableStyleContextWapper.tsx
|
|
281
|
-
import { memo as
|
|
509
|
+
import { memo as memo3, useId as useId2 } from "react";
|
|
282
510
|
|
|
283
511
|
// src/component/ui/ContextMenu/ContextMenu.tsx
|
|
284
|
-
import { useCallback as
|
|
512
|
+
import { useCallback as useCallback4, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
285
513
|
import { createPortal } from "react-dom";
|
|
286
|
-
import { jsx as
|
|
514
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
287
515
|
var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
288
516
|
const menuRef = useRef2(null);
|
|
289
|
-
const closeMenu =
|
|
517
|
+
const closeMenu = useCallback4(() => {
|
|
290
518
|
const contextMenuElem = menuRef.current;
|
|
291
519
|
const elementParent = document.querySelector(selector);
|
|
292
520
|
if (contextMenuElem && contextMenuElem.classList.contains("shadow-menu")) {
|
|
@@ -366,7 +594,7 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
366
594
|
};
|
|
367
595
|
}, []);
|
|
368
596
|
return createPortal(
|
|
369
|
-
/* @__PURE__ */
|
|
597
|
+
/* @__PURE__ */ jsx5(
|
|
370
598
|
"div",
|
|
371
599
|
{
|
|
372
600
|
className: "fixed z-40 w-fit",
|
|
@@ -381,12 +609,12 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
381
609
|
var ContextMenu_default = ContextMenu;
|
|
382
610
|
|
|
383
611
|
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
384
|
-
import { Fragment as Fragment2, useState as
|
|
612
|
+
import { Fragment as Fragment2, useState as useState4 } from "react";
|
|
385
613
|
|
|
386
614
|
// src/component/ui/ContextMenu/ContextMenuItem.tsx
|
|
387
615
|
import { useTranslation as useTranslation3 } from "react-i18next";
|
|
388
616
|
import { MdKeyboardArrowRight } from "react-icons/md";
|
|
389
|
-
import { jsx as
|
|
617
|
+
import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
390
618
|
var ContextMenuItem = ({
|
|
391
619
|
currentValue,
|
|
392
620
|
expandValue,
|
|
@@ -405,9 +633,9 @@ var ContextMenuItem = ({
|
|
|
405
633
|
expandValue && valueClickItem && (currentValue == null ? void 0 : currentValue.onClick) && ((_a = currentValue == null ? void 0 : currentValue.onClick) == null ? void 0 : _a.call(currentValue, valueClickItem, expandValue));
|
|
406
634
|
},
|
|
407
635
|
children: [
|
|
408
|
-
/* @__PURE__ */
|
|
409
|
-
/* @__PURE__ */
|
|
410
|
-
isArrow && /* @__PURE__ */
|
|
636
|
+
/* @__PURE__ */ jsx6(Icon, { size: 20 }),
|
|
637
|
+
/* @__PURE__ */ jsx6("span", { className: "text-sm flex-1", children: t(`${currentValue.action}`) }),
|
|
638
|
+
isArrow && /* @__PURE__ */ jsx6(MdKeyboardArrowRight, { size: 20 })
|
|
411
639
|
]
|
|
412
640
|
}
|
|
413
641
|
);
|
|
@@ -417,11 +645,11 @@ var ContextMenuItem_default = ContextMenuItem;
|
|
|
417
645
|
// src/component/ui/ContextMenu/DropdownContextChild.tsx
|
|
418
646
|
import Tippy from "@tippyjs/react";
|
|
419
647
|
import { useId, useRef as useRef3 } from "react";
|
|
420
|
-
import { jsx as
|
|
648
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
421
649
|
var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
422
650
|
const id = useId();
|
|
423
651
|
const instanceRef = useRef3(null);
|
|
424
|
-
return /* @__PURE__ */
|
|
652
|
+
return /* @__PURE__ */ jsx7(
|
|
425
653
|
Tippy,
|
|
426
654
|
{
|
|
427
655
|
theme: "drop-down",
|
|
@@ -433,7 +661,7 @@ var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
|
433
661
|
allowHTML: true,
|
|
434
662
|
content: children,
|
|
435
663
|
...rest,
|
|
436
|
-
children: /* @__PURE__ */
|
|
664
|
+
children: /* @__PURE__ */ jsx7(
|
|
437
665
|
"div",
|
|
438
666
|
{
|
|
439
667
|
id: `div-${id}`,
|
|
@@ -450,16 +678,16 @@ var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
|
450
678
|
var DropdownContextChild_default = DropdownContextChild;
|
|
451
679
|
|
|
452
680
|
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
453
|
-
import { jsx as
|
|
681
|
+
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
454
682
|
var RenderContextMenu = ({
|
|
455
683
|
renderData,
|
|
456
684
|
valueClickItem,
|
|
457
685
|
expandValue = {}
|
|
458
686
|
}) => {
|
|
459
|
-
return /* @__PURE__ */
|
|
460
|
-
const [isShow, setIsShow] =
|
|
687
|
+
return /* @__PURE__ */ jsx8("div", { className: "bg-white shadow-submenu p-1 min-w-[250px] border", children: renderData == null ? void 0 : renderData.map((menuAction, index) => {
|
|
688
|
+
const [isShow, setIsShow] = useState4(false);
|
|
461
689
|
return /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
462
|
-
!(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */
|
|
690
|
+
!(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ jsx8(
|
|
463
691
|
ContextMenuItem_default,
|
|
464
692
|
{
|
|
465
693
|
currentValue: menuAction,
|
|
@@ -467,7 +695,7 @@ var RenderContextMenu = ({
|
|
|
467
695
|
valueClickItem
|
|
468
696
|
}
|
|
469
697
|
),
|
|
470
|
-
(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */
|
|
698
|
+
(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ jsx8(
|
|
471
699
|
DropdownContextChild_default,
|
|
472
700
|
{
|
|
473
701
|
appendTo: "parent",
|
|
@@ -475,7 +703,7 @@ var RenderContextMenu = ({
|
|
|
475
703
|
offset: [0, 5],
|
|
476
704
|
onShow: () => setIsShow(true),
|
|
477
705
|
onHide: () => setIsShow(false),
|
|
478
|
-
button: /* @__PURE__ */
|
|
706
|
+
button: /* @__PURE__ */ jsx8(
|
|
479
707
|
ContextMenuItem_default,
|
|
480
708
|
{
|
|
481
709
|
currentValue: menuAction,
|
|
@@ -485,7 +713,7 @@ var RenderContextMenu = ({
|
|
|
485
713
|
isArrow: true
|
|
486
714
|
}
|
|
487
715
|
),
|
|
488
|
-
children: /* @__PURE__ */
|
|
716
|
+
children: /* @__PURE__ */ jsx8("div", { className: "dropdown-context-child absolute -top-[20px] -left-1", children: /* @__PURE__ */ jsx8(
|
|
489
717
|
RenderContextMenu,
|
|
490
718
|
{
|
|
491
719
|
renderData: menuAction == null ? void 0 : menuAction.children,
|
|
@@ -501,7 +729,7 @@ var RenderContextMenu = ({
|
|
|
501
729
|
var RenderContextMenu_default = RenderContextMenu;
|
|
502
730
|
|
|
503
731
|
// src/component/ui/Table/TableStyleContextWapper.tsx
|
|
504
|
-
import { jsx as
|
|
732
|
+
import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
505
733
|
var TableStyleContextMenuWapper = ({
|
|
506
734
|
children,
|
|
507
735
|
contextMenuProps,
|
|
@@ -515,12 +743,12 @@ var TableStyleContextMenuWapper = ({
|
|
|
515
743
|
id: `wapper_menu_context-${idWapper}`,
|
|
516
744
|
className: `border border-[#dedede] rounded-xl overflow-hidden bg-white flex-1 h-full flex flex-col min-h-[360px] ${clsTablecustom != null ? clsTablecustom : ""}`,
|
|
517
745
|
children: [
|
|
518
|
-
(renderContext == null ? void 0 : renderContext.renderData) && /* @__PURE__ */
|
|
746
|
+
(renderContext == null ? void 0 : renderContext.renderData) && /* @__PURE__ */ jsx9(
|
|
519
747
|
ContextMenu_default,
|
|
520
748
|
{
|
|
521
749
|
selector: `[id="wapper_menu_context-${idWapper}"] .rdg`,
|
|
522
750
|
...contextMenuProps,
|
|
523
|
-
children: /* @__PURE__ */
|
|
751
|
+
children: /* @__PURE__ */ jsx9(RenderContextMenu_default, { ...renderContext })
|
|
524
752
|
}
|
|
525
753
|
),
|
|
526
754
|
children
|
|
@@ -528,10 +756,12 @@ var TableStyleContextMenuWapper = ({
|
|
|
528
756
|
}
|
|
529
757
|
);
|
|
530
758
|
};
|
|
531
|
-
var TableStyleContextWapper =
|
|
759
|
+
var TableStyleContextWapper = memo3(
|
|
532
760
|
TableStyleContextMenuWapper
|
|
533
761
|
);
|
|
534
762
|
export {
|
|
535
763
|
ReactTableGridCustom,
|
|
536
|
-
|
|
764
|
+
ReactTableGridCustomPaginationClient,
|
|
765
|
+
TableStyleContextWapper,
|
|
766
|
+
useShowHideColumn
|
|
537
767
|
};
|