@mkt-loitd/react-table-grid-custom 1.1.9 → 1.2.2
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 +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +180 -38
- package/dist/index.mjs +173 -32
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Dispatch, SetStateAction, Key, ReactNode, JSX } from 'react';
|
|
3
3
|
import { ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
4
|
+
export { Column, ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
4
5
|
import { PaginationRootProps } from '@mantine/core';
|
|
5
6
|
import { TFunction } from 'i18next';
|
|
6
7
|
import { UseMutateFunction } from '@tanstack/react-query';
|
|
@@ -15,6 +16,24 @@ interface IObjectDynamic {
|
|
|
15
16
|
}
|
|
16
17
|
interface ISetConfigPagination$1 extends IPaginationParams$1, IObjectDynamic {
|
|
17
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>;
|
|
18
37
|
|
|
19
38
|
interface IPaginationText {
|
|
20
39
|
from?: number;
|
|
@@ -138,7 +157,7 @@ interface IPayloadService {
|
|
|
138
157
|
type IDispatchState<T> = Dispatch<SetStateAction<T>>;
|
|
139
158
|
|
|
140
159
|
interface IExpandValue extends IPayloadService {
|
|
141
|
-
t?: TFunction<any, any> | undefined;
|
|
160
|
+
t?: TFunction<any, any> | undefined | any;
|
|
142
161
|
setConfigSearch?: IDispatchState<ISetConfigPagination>;
|
|
143
162
|
setSelectedRecords?: Dispatch<ReadonlySet<string>>;
|
|
144
163
|
setIsShowEdit?: Dispatch<SetStateAction<boolean>>;
|
|
@@ -197,4 +216,4 @@ interface UseShowHideColumnReturn<T, SR> {
|
|
|
197
216
|
handleChangeLocation?: (arr: string[]) => void;
|
|
198
217
|
}
|
|
199
218
|
|
|
200
|
-
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn };
|
|
219
|
+
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn, useShowHideColumn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Dispatch, SetStateAction, Key, ReactNode, JSX } from 'react';
|
|
3
3
|
import { ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
4
|
+
export { Column, ColumnOrColumnGroup, DataGridProps } from 'react-data-grid';
|
|
4
5
|
import { PaginationRootProps } from '@mantine/core';
|
|
5
6
|
import { TFunction } from 'i18next';
|
|
6
7
|
import { UseMutateFunction } from '@tanstack/react-query';
|
|
@@ -15,6 +16,24 @@ interface IObjectDynamic {
|
|
|
15
16
|
}
|
|
16
17
|
interface ISetConfigPagination$1 extends IPaginationParams$1, IObjectDynamic {
|
|
17
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>;
|
|
18
37
|
|
|
19
38
|
interface IPaginationText {
|
|
20
39
|
from?: number;
|
|
@@ -138,7 +157,7 @@ interface IPayloadService {
|
|
|
138
157
|
type IDispatchState<T> = Dispatch<SetStateAction<T>>;
|
|
139
158
|
|
|
140
159
|
interface IExpandValue extends IPayloadService {
|
|
141
|
-
t?: TFunction<any, any> | undefined;
|
|
160
|
+
t?: TFunction<any, any> | undefined | any;
|
|
142
161
|
setConfigSearch?: IDispatchState<ISetConfigPagination>;
|
|
143
162
|
setSelectedRecords?: Dispatch<ReadonlySet<string>>;
|
|
144
163
|
setIsShowEdit?: Dispatch<SetStateAction<boolean>>;
|
|
@@ -197,4 +216,4 @@ interface UseShowHideColumnReturn<T, SR> {
|
|
|
197
216
|
handleChangeLocation?: (arr: string[]) => void;
|
|
198
217
|
}
|
|
199
218
|
|
|
200
|
-
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn };
|
|
219
|
+
export { type ICalculatorTotalPage, type IPaginationParams, type IReactTableGridCustom, type ISTTParams, type Maybe, ReactTableGridCustom, type TColumnsTable, TableStyleContextWapper, type TableStyleWapperProps, type UseShowHideColumnParameter, type UseShowHideColumnReturn, useShowHideColumn };
|
package/dist/index.js
CHANGED
|
@@ -31,17 +31,42 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ReactTableGridCustom: () => ReactTableGridCustom,
|
|
34
|
-
TableStyleContextWapper: () => TableStyleContextWapper
|
|
34
|
+
TableStyleContextWapper: () => TableStyleContextWapper,
|
|
35
|
+
useShowHideColumn: () => useShowHideColumn
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(index_exports);
|
|
37
38
|
|
|
38
|
-
// src/
|
|
39
|
-
var
|
|
39
|
+
// src/helpers/functions.ts
|
|
40
|
+
var import_idb = require("idb");
|
|
40
41
|
var import_lodash = require("lodash");
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
var import_moment = __toESM(require("moment"));
|
|
43
|
+
var setLocalStore = (key, value) => {
|
|
44
|
+
if (typeof window !== "undefined") {
|
|
45
|
+
localStorage.setItem(key, value);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var getLocalStore = (key) => {
|
|
49
|
+
if (typeof window !== "undefined") {
|
|
50
|
+
return localStorage.getItem(key);
|
|
51
|
+
} else {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var toggleValues = ({ array, value }) => {
|
|
56
|
+
if (array.includes(value)) {
|
|
57
|
+
return array.filter((item) => item !== value);
|
|
58
|
+
} else {
|
|
59
|
+
return [...array, value];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var arrayLocal = (array) => {
|
|
63
|
+
try {
|
|
64
|
+
const data = array ? JSON.parse(array) : [];
|
|
65
|
+
return Array.isArray(data) ? data : [];
|
|
66
|
+
} catch {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
};
|
|
45
70
|
|
|
46
71
|
// src/helpers/table.ts
|
|
47
72
|
var calculatorTotalPage = ({ total = 0, pageSize = 0 }) => {
|
|
@@ -69,12 +94,128 @@ function cn(...inputs) {
|
|
|
69
94
|
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
70
95
|
}
|
|
71
96
|
|
|
72
|
-
// src/hooks/
|
|
97
|
+
// src/hooks/useShowHideColumn.ts
|
|
73
98
|
var import_react = require("react");
|
|
99
|
+
var import_lodash2 = require("lodash");
|
|
100
|
+
|
|
101
|
+
// src/type/table.ts
|
|
102
|
+
function isColumn(column) {
|
|
103
|
+
return "key" in column;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/hooks/useShowHideColumn.ts
|
|
107
|
+
var useShowHideColumn = ({
|
|
108
|
+
nameLocal = "table",
|
|
109
|
+
columns,
|
|
110
|
+
ignoreColumns
|
|
111
|
+
}) => {
|
|
112
|
+
const nameLocalLocation = `${nameLocal}_location`;
|
|
113
|
+
const [locationColumns, setLocationColumns] = (0, import_react.useState)(() => {
|
|
114
|
+
const dataLocal = getLocalStore(nameLocalLocation);
|
|
115
|
+
if (dataLocal) {
|
|
116
|
+
return arrayLocal(dataLocal);
|
|
117
|
+
}
|
|
118
|
+
return [];
|
|
119
|
+
});
|
|
120
|
+
const [hiddenColumns, setHiddenColumns] = (0, import_react.useState)(() => {
|
|
121
|
+
const dataLocal = getLocalStore(nameLocal);
|
|
122
|
+
if (dataLocal) {
|
|
123
|
+
return arrayLocal(dataLocal);
|
|
124
|
+
}
|
|
125
|
+
return [];
|
|
126
|
+
});
|
|
127
|
+
const handleFindLocation = (0, import_react.useCallback)(
|
|
128
|
+
(filterColumns, arrLoctions = locationColumns) => {
|
|
129
|
+
return (arrLoctions == null ? void 0 : arrLoctions.length) > 0 ? arrLoctions == null ? void 0 : arrLoctions.reduce(
|
|
130
|
+
(total, current) => {
|
|
131
|
+
const currentColumns = filterColumns == null ? void 0 : filterColumns.find((item) => {
|
|
132
|
+
const newItem = item;
|
|
133
|
+
return (newItem == null ? void 0 : newItem.key) === current;
|
|
134
|
+
});
|
|
135
|
+
if (currentColumns) {
|
|
136
|
+
total = [...total, currentColumns];
|
|
137
|
+
}
|
|
138
|
+
return total;
|
|
139
|
+
},
|
|
140
|
+
[]
|
|
141
|
+
) : filterColumns;
|
|
142
|
+
},
|
|
143
|
+
[locationColumns]
|
|
144
|
+
);
|
|
145
|
+
const newCloumnKeys = (0, import_react.useMemo)(
|
|
146
|
+
() => columns == null ? void 0 : columns.filter(isColumn).map((column) => column.key),
|
|
147
|
+
[columns]
|
|
148
|
+
);
|
|
149
|
+
const newColumns = (0, import_react.useMemo)(() => {
|
|
150
|
+
var _a;
|
|
151
|
+
const filterColumns = (_a = columns == null ? void 0 : columns.filter((column) => {
|
|
152
|
+
if (!isColumn(column)) return true;
|
|
153
|
+
const key = column.key;
|
|
154
|
+
if (ignoreColumns == null ? void 0 : ignoreColumns.includes(key)) return true;
|
|
155
|
+
if (hiddenColumns == null ? void 0 : hiddenColumns.includes(key)) return false;
|
|
156
|
+
return true;
|
|
157
|
+
})) != null ? _a : [];
|
|
158
|
+
return handleFindLocation(filterColumns);
|
|
159
|
+
}, [columns, hiddenColumns, locationColumns, ignoreColumns]);
|
|
160
|
+
const newShowhideColumns = (0, import_react.useMemo)(() => {
|
|
161
|
+
var _a;
|
|
162
|
+
if (!ignoreColumns) return columns;
|
|
163
|
+
return (_a = columns == null ? void 0 : columns.filter((column) => {
|
|
164
|
+
if (!isColumn(column)) return true;
|
|
165
|
+
return !ignoreColumns.includes(column.key);
|
|
166
|
+
})) != null ? _a : [];
|
|
167
|
+
}, [columns, ignoreColumns]);
|
|
168
|
+
const changeHiddenColumn = (0, import_react.useCallback)(
|
|
169
|
+
(key) => {
|
|
170
|
+
let newData = [...hiddenColumns];
|
|
171
|
+
if (typeof key === "string") {
|
|
172
|
+
newData = toggleValues({
|
|
173
|
+
array: newData,
|
|
174
|
+
value: key
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
newData = key;
|
|
178
|
+
}
|
|
179
|
+
setLocalStore(nameLocal, JSON.stringify(newData));
|
|
180
|
+
setHiddenColumns(newData);
|
|
181
|
+
},
|
|
182
|
+
[hiddenColumns, nameLocalLocation]
|
|
183
|
+
);
|
|
184
|
+
const handleChangeLocation = (0, import_react.useCallback)(
|
|
185
|
+
(key) => {
|
|
186
|
+
let newKey = key;
|
|
187
|
+
newKey = (0, import_lodash2.uniq)([...key, ...newCloumnKeys]);
|
|
188
|
+
setLocationColumns(newKey);
|
|
189
|
+
setLocalStore(nameLocalLocation, JSON.stringify(newKey));
|
|
190
|
+
},
|
|
191
|
+
[newCloumnKeys]
|
|
192
|
+
);
|
|
193
|
+
return {
|
|
194
|
+
hiddenColumns,
|
|
195
|
+
setHiddenColumns,
|
|
196
|
+
columnsTable: newColumns,
|
|
197
|
+
changeHiddenColumn,
|
|
198
|
+
newShowhideColumns,
|
|
199
|
+
locationColumns,
|
|
200
|
+
handleFindLocation,
|
|
201
|
+
handleChangeLocation
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/component/ui/Table/ReactTableGridCustom.tsx
|
|
206
|
+
var import_core = require("@mantine/core");
|
|
207
|
+
var import_lodash3 = require("lodash");
|
|
208
|
+
var import_react3 = require("react");
|
|
209
|
+
var import_react_data_grid = require("react-data-grid");
|
|
210
|
+
var import_styles = require("react-data-grid/lib/styles.css");
|
|
211
|
+
var import_react_i18next2 = require("react-i18next");
|
|
212
|
+
|
|
213
|
+
// src/hooks/useTranslationTable.ts
|
|
214
|
+
var import_react2 = require("react");
|
|
74
215
|
var import_react_i18next = require("react-i18next");
|
|
75
216
|
var useTranslationTable = (column) => {
|
|
76
217
|
const { i18n, t } = (0, import_react_i18next.useTranslation)();
|
|
77
|
-
const columnTranslation = (0,
|
|
218
|
+
const columnTranslation = (0, import_react2.useMemo)(() => {
|
|
78
219
|
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
79
220
|
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
80
221
|
return columnTranslation;
|
|
@@ -173,16 +314,16 @@ var ReactTableGridCustomInner = ({
|
|
|
173
314
|
...spread
|
|
174
315
|
}) => {
|
|
175
316
|
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,
|
|
317
|
+
const tableRef = (0, import_react3.useRef)(null);
|
|
318
|
+
const [isLoading, setIsLoading] = (0, import_react3.useState)(true);
|
|
319
|
+
const [containerWidth, setContainerWidth] = (0, import_react3.useState)(0);
|
|
320
|
+
const [sortColumns, setSortColumns] = (0, import_react3.useState)([]);
|
|
180
321
|
const isSelectRow = selectedRows !== void 0;
|
|
181
|
-
const maxPage = (0,
|
|
322
|
+
const maxPage = (0, import_react3.useMemo)(
|
|
182
323
|
() => !hiddenPagination ? calculatorTotalPage({ total, pageSize }) : 0,
|
|
183
324
|
[pageSize, total, hiddenPagination]
|
|
184
325
|
);
|
|
185
|
-
const toInPagination = (0,
|
|
326
|
+
const toInPagination = (0, import_react3.useMemo)(() => {
|
|
186
327
|
if (!hiddenPaginationText && page && pageSize) {
|
|
187
328
|
const from = STT({ page, pageSize }, 0);
|
|
188
329
|
return {
|
|
@@ -195,7 +336,7 @@ var ReactTableGridCustomInner = ({
|
|
|
195
336
|
const columnTranslation = useTranslationTable_default(
|
|
196
337
|
columns
|
|
197
338
|
);
|
|
198
|
-
const newColumns = (0,
|
|
339
|
+
const newColumns = (0, import_react3.useMemo)(() => {
|
|
199
340
|
let cols = [
|
|
200
341
|
...columnTranslation
|
|
201
342
|
];
|
|
@@ -228,13 +369,13 @@ var ReactTableGridCustomInner = ({
|
|
|
228
369
|
page,
|
|
229
370
|
pageSize
|
|
230
371
|
]);
|
|
231
|
-
const customRowKeyGetter = (0,
|
|
372
|
+
const customRowKeyGetter = (0, import_react3.useCallback)(
|
|
232
373
|
(row) => {
|
|
233
374
|
if (typeof rowKeyGetter === "function") {
|
|
234
375
|
return rowKeyGetter(row);
|
|
235
376
|
}
|
|
236
377
|
if (typeof rowKeyGetter === "string") {
|
|
237
|
-
return (0,
|
|
378
|
+
return (0, import_lodash3.get)(row, rowKeyGetter);
|
|
238
379
|
}
|
|
239
380
|
throw new Error(
|
|
240
381
|
"rowKeyGetter must be a string or a function"
|
|
@@ -242,15 +383,15 @@ var ReactTableGridCustomInner = ({
|
|
|
242
383
|
},
|
|
243
384
|
[rowKeyGetter]
|
|
244
385
|
);
|
|
245
|
-
const sortedRows = (0,
|
|
386
|
+
const sortedRows = (0, import_react3.useMemo)(() => {
|
|
246
387
|
if (!sortColumns.length) return data;
|
|
247
388
|
const { columnKey, direction } = sortColumns[0];
|
|
248
389
|
if (!direction) return data;
|
|
249
390
|
const order = direction === "ASC" ? "asc" : "desc";
|
|
250
391
|
const iteratee = typeof columnKey === "string" ? columnKey : String(columnKey);
|
|
251
|
-
return (0,
|
|
392
|
+
return (0, import_lodash3.orderBy)(data, [iteratee], [order]);
|
|
252
393
|
}, [data, sortColumns]);
|
|
253
|
-
(0,
|
|
394
|
+
(0, import_react3.useEffect)(() => {
|
|
254
395
|
var _a;
|
|
255
396
|
setIsLoading(false);
|
|
256
397
|
if ((_a = tableRef.current) == null ? void 0 : _a.element) {
|
|
@@ -300,20 +441,20 @@ var ReactTableGridCustomInner = ({
|
|
|
300
441
|
}
|
|
301
442
|
);
|
|
302
443
|
};
|
|
303
|
-
var ReactTableGridCustom = (0,
|
|
444
|
+
var ReactTableGridCustom = (0, import_react3.memo)(
|
|
304
445
|
ReactTableGridCustomInner
|
|
305
446
|
);
|
|
306
447
|
|
|
307
448
|
// src/component/ui/Table/TableStyleContextWapper.tsx
|
|
308
|
-
var
|
|
449
|
+
var import_react8 = require("react");
|
|
309
450
|
|
|
310
451
|
// src/component/ui/ContextMenu/ContextMenu.tsx
|
|
311
|
-
var
|
|
452
|
+
var import_react4 = require("react");
|
|
312
453
|
var import_react_dom = require("react-dom");
|
|
313
454
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
314
455
|
var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
315
|
-
const menuRef = (0,
|
|
316
|
-
const closeMenu = (0,
|
|
456
|
+
const menuRef = (0, import_react4.useRef)(null);
|
|
457
|
+
const closeMenu = (0, import_react4.useCallback)(() => {
|
|
317
458
|
const contextMenuElem = menuRef.current;
|
|
318
459
|
const elementParent = document.querySelector(selector);
|
|
319
460
|
if (contextMenuElem && contextMenuElem.classList.contains("shadow-menu")) {
|
|
@@ -325,7 +466,7 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
325
466
|
elementParent.style.removeProperty("overflow");
|
|
326
467
|
}
|
|
327
468
|
}, [menuRef.current]);
|
|
328
|
-
(0,
|
|
469
|
+
(0, import_react4.useEffect)(() => {
|
|
329
470
|
const elementParent = document.querySelector(selector);
|
|
330
471
|
if (elementParent) {
|
|
331
472
|
const clickMenu = (e) => {
|
|
@@ -408,7 +549,7 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
408
549
|
var ContextMenu_default = ContextMenu;
|
|
409
550
|
|
|
410
551
|
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
411
|
-
var
|
|
552
|
+
var import_react7 = require("react");
|
|
412
553
|
|
|
413
554
|
// src/component/ui/ContextMenu/ContextMenuItem.tsx
|
|
414
555
|
var import_react_i18next3 = require("react-i18next");
|
|
@@ -442,14 +583,14 @@ var ContextMenuItem = ({
|
|
|
442
583
|
var ContextMenuItem_default = ContextMenuItem;
|
|
443
584
|
|
|
444
585
|
// src/component/ui/ContextMenu/DropdownContextChild.tsx
|
|
445
|
-
var
|
|
446
|
-
var
|
|
586
|
+
var import_react5 = __toESM(require("@tippyjs/react"));
|
|
587
|
+
var import_react6 = require("react");
|
|
447
588
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
448
589
|
var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
449
|
-
const id = (0,
|
|
450
|
-
const instanceRef = (0,
|
|
590
|
+
const id = (0, import_react6.useId)();
|
|
591
|
+
const instanceRef = (0, import_react6.useRef)(null);
|
|
451
592
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
452
|
-
|
|
593
|
+
import_react5.default,
|
|
453
594
|
{
|
|
454
595
|
theme: "drop-down",
|
|
455
596
|
className: "!bg-transparent !text-inherit !border-r-0 [&>*]:!p-0",
|
|
@@ -484,8 +625,8 @@ var RenderContextMenu = ({
|
|
|
484
625
|
expandValue = {}
|
|
485
626
|
}) => {
|
|
486
627
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "bg-white shadow-submenu p-1 min-w-[250px] border", children: renderData == null ? void 0 : renderData.map((menuAction, index) => {
|
|
487
|
-
const [isShow, setIsShow] = (0,
|
|
488
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
628
|
+
const [isShow, setIsShow] = (0, import_react7.useState)(false);
|
|
629
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react7.Fragment, { children: [
|
|
489
630
|
!(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
490
631
|
ContextMenuItem_default,
|
|
491
632
|
{
|
|
@@ -535,7 +676,7 @@ var TableStyleContextMenuWapper = ({
|
|
|
535
676
|
clsTablecustom,
|
|
536
677
|
renderContext
|
|
537
678
|
}) => {
|
|
538
|
-
const idWapper = (0,
|
|
679
|
+
const idWapper = (0, import_react8.useId)();
|
|
539
680
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
540
681
|
"div",
|
|
541
682
|
{
|
|
@@ -555,11 +696,12 @@ var TableStyleContextMenuWapper = ({
|
|
|
555
696
|
}
|
|
556
697
|
);
|
|
557
698
|
};
|
|
558
|
-
var TableStyleContextWapper = (0,
|
|
699
|
+
var TableStyleContextWapper = (0, import_react8.memo)(
|
|
559
700
|
TableStyleContextMenuWapper
|
|
560
701
|
);
|
|
561
702
|
// Annotate the CommonJS export names for ESM import in node:
|
|
562
703
|
0 && (module.exports = {
|
|
563
704
|
ReactTableGridCustom,
|
|
564
|
-
TableStyleContextWapper
|
|
705
|
+
TableStyleContextWapper,
|
|
706
|
+
useShowHideColumn
|
|
565
707
|
});
|
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;
|
|
@@ -281,12 +421,12 @@ var ReactTableGridCustom = memo(
|
|
|
281
421
|
import { memo as memo2, useId as useId2 } from "react";
|
|
282
422
|
|
|
283
423
|
// src/component/ui/ContextMenu/ContextMenu.tsx
|
|
284
|
-
import { useCallback as
|
|
424
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
285
425
|
import { createPortal } from "react-dom";
|
|
286
426
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
287
427
|
var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
288
428
|
const menuRef = useRef2(null);
|
|
289
|
-
const closeMenu =
|
|
429
|
+
const closeMenu = useCallback3(() => {
|
|
290
430
|
const contextMenuElem = menuRef.current;
|
|
291
431
|
const elementParent = document.querySelector(selector);
|
|
292
432
|
if (contextMenuElem && contextMenuElem.classList.contains("shadow-menu")) {
|
|
@@ -381,7 +521,7 @@ var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
|
381
521
|
var ContextMenu_default = ContextMenu;
|
|
382
522
|
|
|
383
523
|
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
384
|
-
import { Fragment as Fragment2, useState as
|
|
524
|
+
import { Fragment as Fragment2, useState as useState3 } from "react";
|
|
385
525
|
|
|
386
526
|
// src/component/ui/ContextMenu/ContextMenuItem.tsx
|
|
387
527
|
import { useTranslation as useTranslation3 } from "react-i18next";
|
|
@@ -457,7 +597,7 @@ var RenderContextMenu = ({
|
|
|
457
597
|
expandValue = {}
|
|
458
598
|
}) => {
|
|
459
599
|
return /* @__PURE__ */ jsx7("div", { className: "bg-white shadow-submenu p-1 min-w-[250px] border", children: renderData == null ? void 0 : renderData.map((menuAction, index) => {
|
|
460
|
-
const [isShow, setIsShow] =
|
|
600
|
+
const [isShow, setIsShow] = useState3(false);
|
|
461
601
|
return /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
462
602
|
!(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ jsx7(
|
|
463
603
|
ContextMenuItem_default,
|
|
@@ -533,5 +673,6 @@ var TableStyleContextWapper = memo2(
|
|
|
533
673
|
);
|
|
534
674
|
export {
|
|
535
675
|
ReactTableGridCustom,
|
|
536
|
-
TableStyleContextWapper
|
|
676
|
+
TableStyleContextWapper,
|
|
677
|
+
useShowHideColumn
|
|
537
678
|
};
|