@mkt-loitd/react-table-grid-custom 1.0.2 → 1.0.7
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/README.md +95 -115
- package/dist/index.css +97 -0
- package/dist/index.d.mts +134 -5
- package/dist/index.d.ts +134 -5
- package/dist/index.js +385 -233
- package/dist/index.mjs +378 -227
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,17 +17,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
23
|
-
ReactTableGridCustom: () => ReactTableGridCustom
|
|
33
|
+
ReactTableGridCustom: () => ReactTableGridCustom,
|
|
34
|
+
TableStyleContextWapper: () => TableStyleContextWapper
|
|
24
35
|
});
|
|
25
36
|
module.exports = __toCommonJS(index_exports);
|
|
26
37
|
|
|
27
38
|
// src/ReactTableGridCustom.tsx
|
|
28
|
-
var
|
|
39
|
+
var import_core = require("@mantine/core");
|
|
40
|
+
var import_lodash = require("lodash");
|
|
41
|
+
var import_react2 = require("react");
|
|
42
|
+
var import_react_data_grid = require("react-data-grid");
|
|
43
|
+
var import_styles = require("react-data-grid/lib/styles.css");
|
|
44
|
+
var import_react_i18next2 = require("react-i18next");
|
|
29
45
|
|
|
30
46
|
// src/helpers/table.ts
|
|
31
47
|
var calculatorTotalPage = ({ total = 0, pageSize = 0 }) => {
|
|
@@ -53,65 +69,20 @@ function cn(...inputs) {
|
|
|
53
69
|
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
54
70
|
}
|
|
55
71
|
|
|
56
|
-
// src/
|
|
57
|
-
var import_lodash = require("lodash");
|
|
58
|
-
var import_react3 = require("react");
|
|
59
|
-
var import_react_data_grid = require("react-data-grid");
|
|
60
|
-
var import_styles = require("react-data-grid/lib/styles.css");
|
|
61
|
-
var import_react_i18next2 = require("react-i18next");
|
|
62
|
-
|
|
63
|
-
// src/component/ComboboxCustom.tsx
|
|
64
|
-
var import_core = require("@mantine/core");
|
|
72
|
+
// src/hooks/useTranslationTable.ts
|
|
65
73
|
var import_react = require("react");
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
import_core.Combobox.Option,
|
|
74
|
-
{
|
|
75
|
-
className: "page_size-table",
|
|
76
|
-
value: item,
|
|
77
|
-
disabled: item === value,
|
|
78
|
-
children: item
|
|
79
|
-
},
|
|
80
|
-
item
|
|
81
|
-
));
|
|
82
|
-
}, [options, value]);
|
|
83
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
84
|
-
import_core.Combobox,
|
|
85
|
-
{
|
|
86
|
-
size: "sm",
|
|
87
|
-
store: combobox,
|
|
88
|
-
onOptionSubmit: (val) => {
|
|
89
|
-
onChange && onChange(val);
|
|
90
|
-
combobox.closeDropdown();
|
|
91
|
-
},
|
|
92
|
-
children: [
|
|
93
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Combobox.Target, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
94
|
-
import_core.InputBase,
|
|
95
|
-
{
|
|
96
|
-
component: "button",
|
|
97
|
-
type: "button",
|
|
98
|
-
pointer: true,
|
|
99
|
-
rightSectionPointerEvents: "none",
|
|
100
|
-
onClick: () => combobox.toggleDropdown(),
|
|
101
|
-
className: "w-[70px]",
|
|
102
|
-
classNames: { input: "custom_input_table" },
|
|
103
|
-
children: value || /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Input.Placeholder, { children: "Pick value" })
|
|
104
|
-
}
|
|
105
|
-
) }),
|
|
106
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Combobox.Dropdown, { className: "w-[70px]", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Combobox.Options, { children: newOptions }) })
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
);
|
|
74
|
+
var import_react_i18next = require("react-i18next");
|
|
75
|
+
var useTranslationTable = (column) => {
|
|
76
|
+
const { i18n, t } = (0, import_react_i18next.useTranslation)();
|
|
77
|
+
const columnTranslation = (0, import_react.useMemo)(() => {
|
|
78
|
+
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
79
|
+
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
80
|
+
return columnTranslation;
|
|
110
81
|
};
|
|
111
|
-
var
|
|
82
|
+
var useTranslationTable_default = useTranslationTable;
|
|
112
83
|
|
|
113
84
|
// src/component/Icons.tsx
|
|
114
|
-
var
|
|
85
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
115
86
|
var LoadingIcon = ({
|
|
116
87
|
isSpin = false,
|
|
117
88
|
h = 30,
|
|
@@ -119,7 +90,7 @@ var LoadingIcon = ({
|
|
|
119
90
|
size = 30,
|
|
120
91
|
className
|
|
121
92
|
}) => {
|
|
122
|
-
return /* @__PURE__ */ (0,
|
|
93
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
123
94
|
"svg",
|
|
124
95
|
{
|
|
125
96
|
className: `${isSpin ? "animate-spin" : ""} ${className != null ? className : ""}`,
|
|
@@ -130,7 +101,7 @@ var LoadingIcon = ({
|
|
|
130
101
|
height: size || h,
|
|
131
102
|
fill: "currentColor",
|
|
132
103
|
"aria-hidden": "true",
|
|
133
|
-
children: /* @__PURE__ */ (0,
|
|
104
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 00-94.3-139.9 437.71 437.71 0 00-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z" })
|
|
134
105
|
}
|
|
135
106
|
);
|
|
136
107
|
};
|
|
@@ -140,7 +111,7 @@ var ArrowIcon = ({
|
|
|
140
111
|
size,
|
|
141
112
|
className
|
|
142
113
|
}) => {
|
|
143
|
-
return /* @__PURE__ */ (0,
|
|
114
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
144
115
|
"svg",
|
|
145
116
|
{
|
|
146
117
|
className,
|
|
@@ -151,7 +122,7 @@ var ArrowIcon = ({
|
|
|
151
122
|
height: size != null ? size : h,
|
|
152
123
|
width: size != null ? size : w,
|
|
153
124
|
xmlns: "http://www.w3.org/2000/svg",
|
|
154
|
-
children: /* @__PURE__ */ (0,
|
|
125
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
155
126
|
"path",
|
|
156
127
|
{
|
|
157
128
|
fillRule: "evenodd",
|
|
@@ -163,35 +134,23 @@ var ArrowIcon = ({
|
|
|
163
134
|
};
|
|
164
135
|
|
|
165
136
|
// src/component/RenderSortStatus.tsx
|
|
166
|
-
var
|
|
137
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
167
138
|
var RenderSortStatus = ({ sortDirection, priority }) => {
|
|
168
|
-
return /* @__PURE__ */ (0,
|
|
169
|
-
sortDirection !== void 0 && /* @__PURE__ */ (0,
|
|
139
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
140
|
+
sortDirection !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
170
141
|
ArrowIcon,
|
|
171
142
|
{
|
|
172
143
|
className: cn(sortDirection === "DESC" && "-rotate-180", "transition-transform"),
|
|
173
144
|
size: 20
|
|
174
145
|
}
|
|
175
146
|
),
|
|
176
|
-
/* @__PURE__ */ (0,
|
|
147
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: priority })
|
|
177
148
|
] });
|
|
178
149
|
};
|
|
179
150
|
var RenderSortStatus_default = RenderSortStatus;
|
|
180
151
|
|
|
181
|
-
// src/hooks/useTranslationTable.ts
|
|
182
|
-
var import_react2 = require("react");
|
|
183
|
-
var import_react_i18next = require("react-i18next");
|
|
184
|
-
var useTranslationTable = (column) => {
|
|
185
|
-
const { i18n, t } = (0, import_react_i18next.useTranslation)();
|
|
186
|
-
const columnTranslation = (0, import_react2.useMemo)(() => {
|
|
187
|
-
return column.map((item) => ({ ...item, name: t(`${item == null ? void 0 : item.name}`) }));
|
|
188
|
-
}, [i18n == null ? void 0 : i18n.language, column]);
|
|
189
|
-
return columnTranslation;
|
|
190
|
-
};
|
|
191
|
-
var useTranslationTable_default = useTranslationTable;
|
|
192
|
-
|
|
193
152
|
// src/ReactTableGridCustom.tsx
|
|
194
|
-
var
|
|
153
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
195
154
|
var ReactTableGridCustomInner = ({
|
|
196
155
|
classNamePaginationTable,
|
|
197
156
|
classNameWapperTable,
|
|
@@ -214,200 +173,393 @@ var ReactTableGridCustomInner = ({
|
|
|
214
173
|
...spread
|
|
215
174
|
}) => {
|
|
216
175
|
const { t } = (0, import_react_i18next2.useTranslation)();
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
const [containerWidth, setContainerWidth] = (0,
|
|
220
|
-
const [sortColumns, setSortColumns] = (0,
|
|
176
|
+
const tableRef = (0, import_react2.useRef)(null);
|
|
177
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
178
|
+
const [containerWidth, setContainerWidth] = (0, import_react2.useState)(0);
|
|
179
|
+
const [sortColumns, setSortColumns] = (0, import_react2.useState)([]);
|
|
221
180
|
const isSelectRow = selectedRows !== void 0;
|
|
222
|
-
const maxPage = (0,
|
|
223
|
-
() => !hiddenPagination ? calculatorTotalPage({
|
|
224
|
-
total,
|
|
225
|
-
pageSize
|
|
226
|
-
}) : 0,
|
|
181
|
+
const maxPage = (0, import_react2.useMemo)(
|
|
182
|
+
() => !hiddenPagination ? calculatorTotalPage({ total, pageSize }) : 0,
|
|
227
183
|
[pageSize, total, hiddenPagination]
|
|
228
184
|
);
|
|
229
|
-
const toInPagination = (0,
|
|
230
|
-
|
|
231
|
-
from
|
|
232
|
-
to: 0
|
|
233
|
-
};
|
|
234
|
-
if (!hiddenPaginationText && pageSize && page) {
|
|
235
|
-
const from = STT(
|
|
236
|
-
{
|
|
237
|
-
page,
|
|
238
|
-
pageSize
|
|
239
|
-
},
|
|
240
|
-
0
|
|
241
|
-
);
|
|
185
|
+
const toInPagination = (0, import_react2.useMemo)(() => {
|
|
186
|
+
if (!hiddenPaginationText && page && pageSize) {
|
|
187
|
+
const from = STT({ page, pageSize }, 0);
|
|
242
188
|
return {
|
|
243
189
|
from,
|
|
244
|
-
to: maxPage === page ? total : page * pageSize
|
|
190
|
+
to: maxPage === page ? total != null ? total : 0 : page * pageSize
|
|
245
191
|
};
|
|
246
192
|
}
|
|
247
|
-
return
|
|
248
|
-
}, [
|
|
249
|
-
const columnTranslation = useTranslationTable_default(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
newCol.width = 200;
|
|
265
|
-
return newCol;
|
|
266
|
-
});
|
|
267
|
-
const totalMaxWidth = columnsCustom.reduce((sum, col) => {
|
|
268
|
-
var _a;
|
|
269
|
-
return sum + ("width" in col ? Number((_a = col == null ? void 0 : col.width) != null ? _a : 200) : 0);
|
|
270
|
-
}, 0);
|
|
271
|
-
if (totalMaxWidth < adjustedContainerWidth && columnsCustom.length > 0) {
|
|
272
|
-
const evenWidth = Math.floor(adjustedContainerWidth / columnsCustom.length);
|
|
273
|
-
columnsCustom = columnsCustom.map((col) => {
|
|
274
|
-
const newCol = { ...col };
|
|
275
|
-
delete newCol.maxWidth;
|
|
276
|
-
newCol.width = evenWidth;
|
|
277
|
-
return newCol;
|
|
278
|
-
});
|
|
279
|
-
}
|
|
193
|
+
return { from: 0, to: 0 };
|
|
194
|
+
}, [page, pageSize, hiddenPaginationText, maxPage, total]);
|
|
195
|
+
const columnTranslation = useTranslationTable_default(
|
|
196
|
+
columns
|
|
197
|
+
);
|
|
198
|
+
const newColumns = (0, import_react2.useMemo)(() => {
|
|
199
|
+
let cols = [
|
|
200
|
+
...columnTranslation
|
|
201
|
+
];
|
|
202
|
+
const adjustedWidth = containerWidth - 45;
|
|
203
|
+
cols = cols.map(
|
|
204
|
+
(col) => "key" in col ? {
|
|
205
|
+
...col,
|
|
206
|
+
width: 200,
|
|
207
|
+
maxWidth: void 0
|
|
208
|
+
} : col
|
|
209
|
+
);
|
|
280
210
|
if (isSelectRow) {
|
|
281
|
-
|
|
211
|
+
cols.unshift(import_react_data_grid.SelectColumn);
|
|
282
212
|
}
|
|
283
|
-
if (!hiddenSTT
|
|
284
|
-
|
|
213
|
+
if (!hiddenSTT) {
|
|
214
|
+
const sttColumn = {
|
|
285
215
|
key: "index",
|
|
286
216
|
name: "STT",
|
|
287
217
|
width: 80,
|
|
288
218
|
renderCell: ({ rowIdx }) => STT({ page, pageSize }, rowIdx)
|
|
289
|
-
}
|
|
219
|
+
};
|
|
220
|
+
cols.unshift(sttColumn);
|
|
290
221
|
}
|
|
291
|
-
return
|
|
292
|
-
}, [
|
|
293
|
-
|
|
294
|
-
|
|
222
|
+
return cols;
|
|
223
|
+
}, [
|
|
224
|
+
columnTranslation,
|
|
225
|
+
containerWidth,
|
|
226
|
+
hiddenSTT,
|
|
227
|
+
isSelectRow,
|
|
228
|
+
page,
|
|
229
|
+
pageSize
|
|
230
|
+
]);
|
|
231
|
+
const customRowKeyGetter = (0, import_react2.useCallback)(
|
|
232
|
+
(row) => {
|
|
295
233
|
if (typeof rowKeyGetter === "function") {
|
|
296
234
|
return rowKeyGetter(row);
|
|
297
235
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}, [rowKeyGetter]);
|
|
301
|
-
const handlePageChange = (0, import_react3.useCallback)(
|
|
302
|
-
(page2) => {
|
|
303
|
-
if (onChange) {
|
|
304
|
-
onChange(page2);
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
if (setConfigPagination) {
|
|
308
|
-
setConfigPagination((prev) => ({ ...prev, page: page2 }));
|
|
236
|
+
if (typeof rowKeyGetter === "string") {
|
|
237
|
+
return (0, import_lodash.get)(row, rowKeyGetter);
|
|
309
238
|
}
|
|
239
|
+
throw new Error(
|
|
240
|
+
"rowKeyGetter must be a string or a function"
|
|
241
|
+
);
|
|
310
242
|
},
|
|
311
|
-
[
|
|
243
|
+
[rowKeyGetter]
|
|
312
244
|
);
|
|
313
|
-
const sortedRows = (0,
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
|
|
245
|
+
const sortedRows = (0, import_react2.useMemo)(() => {
|
|
246
|
+
if (!sortColumns.length) return data;
|
|
247
|
+
const { columnKey, direction } = sortColumns[0];
|
|
248
|
+
if (!direction) return data;
|
|
249
|
+
const order = direction === "ASC" ? "asc" : "desc";
|
|
250
|
+
const iteratee = typeof columnKey === "string" ? columnKey : String(columnKey);
|
|
251
|
+
return (0, import_lodash.orderBy)(data, [iteratee], [order]);
|
|
319
252
|
}, [data, sortColumns]);
|
|
320
|
-
(0,
|
|
321
|
-
|
|
322
|
-
|
|
253
|
+
(0, import_react2.useEffect)(() => {
|
|
254
|
+
var _a;
|
|
255
|
+
setIsLoading(false);
|
|
256
|
+
if ((_a = tableRef.current) == null ? void 0 : _a.element) {
|
|
257
|
+
setContainerWidth(tableRef.current.element.offsetWidth);
|
|
323
258
|
}
|
|
324
|
-
}, [
|
|
325
|
-
return /* @__PURE__ */ (0,
|
|
259
|
+
}, []);
|
|
260
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
326
261
|
"div",
|
|
327
262
|
{
|
|
328
263
|
className: cn(
|
|
329
|
-
"wapper_table flex
|
|
264
|
+
"wapper_table flex flex-col h-full min-h-0",
|
|
330
265
|
classNameWapperTable
|
|
331
266
|
),
|
|
332
267
|
children: [
|
|
333
|
-
/* @__PURE__ */ (0,
|
|
334
|
-
|
|
335
|
-
import_react_data_grid.DataGrid,
|
|
336
|
-
{
|
|
337
|
-
ref: tableRef,
|
|
338
|
-
"aria-rowcount": sortedRows == null ? void 0 : sortedRows.length,
|
|
339
|
-
selectedRows,
|
|
340
|
-
rows: sortedRows,
|
|
341
|
-
rowKeyGetter: rowKeyGetter && isSelectRow ? customRowKeyGetter : void 0,
|
|
342
|
-
columns: newColumns,
|
|
343
|
-
renderers: {
|
|
344
|
-
renderSortStatus: RenderSortStatus_default,
|
|
345
|
-
renderCheckbox({ onChange: onChange2, checked, ...spread2 }) {
|
|
346
|
-
const handleChange = (e) => {
|
|
347
|
-
onChange2(e.target.checked, e.nativeEvent.shiftKey);
|
|
348
|
-
};
|
|
349
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core2.Checkbox, { color: "indigo", checked: !!checked, onChange: handleChange, ...spread2 });
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
className: "fill-grid flex-1 h-full min-h-0",
|
|
353
|
-
defaultColumnOptions: {
|
|
354
|
-
// minWidth: 200,
|
|
355
|
-
// maxWidth: 200,
|
|
356
|
-
renderCell: ({ column, row }) => {
|
|
357
|
-
const value = (0, import_lodash.get)(row, column.key);
|
|
358
|
-
return [null, void 0, ""].includes(value) ? "-" : value;
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
sortColumns,
|
|
362
|
-
onSortColumnsChange: setSortColumns,
|
|
363
|
-
...spread
|
|
364
|
-
}
|
|
365
|
-
),
|
|
366
|
-
total === 0 && TableLogo && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "no_result absolute left-1/2 top-1/2 -translate-y-1/2 -translate-x-1/2 select-none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex flex-col justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { src: TableLogo, alt: "", className: "size-32" }) }) })
|
|
367
|
-
] }),
|
|
368
|
-
!hiddenPagination && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
369
|
-
"div",
|
|
268
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
269
|
+
import_react_data_grid.DataGrid,
|
|
370
270
|
{
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
271
|
+
ref: tableRef,
|
|
272
|
+
rows: sortedRows,
|
|
273
|
+
columns: newColumns,
|
|
274
|
+
selectedRows,
|
|
275
|
+
rowKeyGetter: isSelectRow ? customRowKeyGetter : void 0,
|
|
276
|
+
sortColumns,
|
|
277
|
+
onSortColumnsChange: setSortColumns,
|
|
278
|
+
renderers: {
|
|
279
|
+
renderSortStatus: RenderSortStatus_default,
|
|
280
|
+
renderCheckbox({ onChange: onChange2, checked, ...props }) {
|
|
281
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
282
|
+
import_core.Checkbox,
|
|
283
|
+
{
|
|
284
|
+
...props,
|
|
285
|
+
checked: !!checked,
|
|
286
|
+
onChange: (e) => {
|
|
287
|
+
const nativeEvent = e.nativeEvent;
|
|
288
|
+
const shiftKey = nativeEvent instanceof MouseEvent ? nativeEvent.shiftKey : false;
|
|
289
|
+
onChange2(e.target.checked, shiftKey);
|
|
385
290
|
}
|
|
386
291
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
{
|
|
392
|
-
color: "indigo",
|
|
393
|
-
total: maxPage,
|
|
394
|
-
size: "sm",
|
|
395
|
-
value: page,
|
|
396
|
-
onChange: handlePageChange
|
|
397
|
-
}
|
|
398
|
-
)
|
|
399
|
-
]
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
...spread
|
|
400
296
|
}
|
|
401
297
|
),
|
|
402
|
-
(fetching || isLoading) && /* @__PURE__ */ (0,
|
|
298
|
+
(fetching || isLoading) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LoadingIcon, { isSpin: true }) })
|
|
403
299
|
]
|
|
404
300
|
}
|
|
405
301
|
);
|
|
406
302
|
};
|
|
407
|
-
var ReactTableGridCustom = (0,
|
|
303
|
+
var ReactTableGridCustom = (0, import_react2.memo)(
|
|
408
304
|
ReactTableGridCustomInner
|
|
409
305
|
);
|
|
306
|
+
|
|
307
|
+
// src/component/TableStyleContextWapper.tsx
|
|
308
|
+
var import_react7 = require("react");
|
|
309
|
+
|
|
310
|
+
// src/component/ui/ContextMenu/ContextMenu.tsx
|
|
311
|
+
var import_react3 = require("react");
|
|
312
|
+
var import_react_dom = require("react-dom");
|
|
313
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
314
|
+
var ContextMenu = ({ selector, children, zIndex = 40 }) => {
|
|
315
|
+
const menuRef = (0, import_react3.useRef)(null);
|
|
316
|
+
const closeMenu = (0, import_react3.useCallback)(() => {
|
|
317
|
+
const contextMenuElem = menuRef.current;
|
|
318
|
+
const elementParent = document.querySelector(selector);
|
|
319
|
+
if (contextMenuElem && contextMenuElem.classList.contains("shadow-menu")) {
|
|
320
|
+
contextMenuElem.classList.remove("shadow-menu");
|
|
321
|
+
contextMenuElem.style.opacity = "0";
|
|
322
|
+
contextMenuElem.style.visibility = "hidden";
|
|
323
|
+
}
|
|
324
|
+
if (elementParent) {
|
|
325
|
+
elementParent.style.removeProperty("overflow");
|
|
326
|
+
}
|
|
327
|
+
}, [menuRef.current]);
|
|
328
|
+
(0, import_react3.useEffect)(() => {
|
|
329
|
+
const elementParent = document.querySelector(selector);
|
|
330
|
+
if (elementParent) {
|
|
331
|
+
const clickMenu = (e) => {
|
|
332
|
+
const contextMenuElem = menuRef.current;
|
|
333
|
+
if (contextMenuElem) {
|
|
334
|
+
contextMenuElem.style.opacity = "1";
|
|
335
|
+
contextMenuElem.style.visibility = "visible";
|
|
336
|
+
const { width: widthContextMenu, height: heightContextMenu } = contextMenuElem.getBoundingClientRect();
|
|
337
|
+
elementParent.style.overflow = "hidden";
|
|
338
|
+
const maxWidth = window.innerWidth;
|
|
339
|
+
const maxHeight = window.innerHeight;
|
|
340
|
+
const remainingLeft = maxWidth - e.clientX;
|
|
341
|
+
const isLeft = remainingLeft >= widthContextMenu;
|
|
342
|
+
const showTop = heightContextMenu + e.clientY <= maxHeight;
|
|
343
|
+
const showBottom = e.clientY - heightContextMenu >= 0;
|
|
344
|
+
const isCenter = !(showTop || showBottom);
|
|
345
|
+
isCenter;
|
|
346
|
+
const styleOrigin = {
|
|
347
|
+
x: "left",
|
|
348
|
+
y: "top"
|
|
349
|
+
};
|
|
350
|
+
if (isLeft) {
|
|
351
|
+
contextMenuElem.style.left = `${e.clientX}px`;
|
|
352
|
+
styleOrigin.x = "left";
|
|
353
|
+
} else {
|
|
354
|
+
contextMenuElem.style.left = `${e.clientX - widthContextMenu}px`;
|
|
355
|
+
styleOrigin.x = "right";
|
|
356
|
+
}
|
|
357
|
+
if (showTop) {
|
|
358
|
+
contextMenuElem.style.top = `${e.clientY}px`;
|
|
359
|
+
styleOrigin.y = "top";
|
|
360
|
+
} else if (showBottom) {
|
|
361
|
+
contextMenuElem.style.top = `${e.clientY - heightContextMenu}px`;
|
|
362
|
+
styleOrigin.y = "bottom";
|
|
363
|
+
} else {
|
|
364
|
+
const HalfHeight = heightContextMenu / 2;
|
|
365
|
+
const calculatorTop = HalfHeight + e.clientY;
|
|
366
|
+
const showTopCenter = calculatorTop <= maxHeight;
|
|
367
|
+
const calculatorBottom = e.clientY - HalfHeight;
|
|
368
|
+
const showBottom2 = calculatorBottom >= 0;
|
|
369
|
+
let topNew = calculatorBottom;
|
|
370
|
+
if (!showBottom2 && showTopCenter) {
|
|
371
|
+
topNew = topNew - calculatorBottom;
|
|
372
|
+
} else if (!showTopCenter && showBottom2) {
|
|
373
|
+
const ts = calculatorTop - maxHeight;
|
|
374
|
+
topNew = topNew - ts;
|
|
375
|
+
}
|
|
376
|
+
contextMenuElem.style.top = `${topNew}px`;
|
|
377
|
+
styleOrigin.y = "center";
|
|
378
|
+
}
|
|
379
|
+
contextMenuElem.style.transformOrigin = `${styleOrigin.y} ${styleOrigin.x}`;
|
|
380
|
+
if (!contextMenuElem.classList.contains("shadow-menu")) {
|
|
381
|
+
contextMenuElem.classList.add("shadow-menu");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
elementParent.addEventListener("contextmenu", clickMenu);
|
|
386
|
+
window.addEventListener("click", closeMenu);
|
|
387
|
+
return () => {
|
|
388
|
+
elementParent.removeEventListener("contextmenu", clickMenu);
|
|
389
|
+
window.removeEventListener("click", closeMenu);
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
return () => {
|
|
393
|
+
};
|
|
394
|
+
}, []);
|
|
395
|
+
return (0, import_react_dom.createPortal)(
|
|
396
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
397
|
+
"div",
|
|
398
|
+
{
|
|
399
|
+
className: "fixed z-40 w-fit",
|
|
400
|
+
ref: menuRef,
|
|
401
|
+
style: { opacity: 0, visibility: "hidden", zIndex },
|
|
402
|
+
children
|
|
403
|
+
}
|
|
404
|
+
),
|
|
405
|
+
document.body
|
|
406
|
+
);
|
|
407
|
+
};
|
|
408
|
+
var ContextMenu_default = ContextMenu;
|
|
409
|
+
|
|
410
|
+
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
411
|
+
var import_react6 = require("react");
|
|
412
|
+
|
|
413
|
+
// src/component/ui/ContextMenu/ContextMenuItem.tsx
|
|
414
|
+
var import_react_i18next3 = require("react-i18next");
|
|
415
|
+
var import_md = require("react-icons/md");
|
|
416
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
417
|
+
var ContextMenuItem = ({
|
|
418
|
+
currentValue,
|
|
419
|
+
expandValue,
|
|
420
|
+
valueClickItem,
|
|
421
|
+
show,
|
|
422
|
+
isArrow
|
|
423
|
+
}) => {
|
|
424
|
+
const { t } = (0, import_react_i18next3.useTranslation)();
|
|
425
|
+
const Icon = currentValue.Icon;
|
|
426
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
427
|
+
"div",
|
|
428
|
+
{
|
|
429
|
+
className: `cursor-pointer p-2 flex items-center space-x-2 relative ${show ? "bg-[#555] text-white" : "hover:bg-[#555] hover:text-white"}`,
|
|
430
|
+
onClick: () => {
|
|
431
|
+
var _a;
|
|
432
|
+
expandValue && valueClickItem && (currentValue == null ? void 0 : currentValue.onClick) && ((_a = currentValue == null ? void 0 : currentValue.onClick) == null ? void 0 : _a.call(currentValue, valueClickItem, expandValue));
|
|
433
|
+
},
|
|
434
|
+
children: [
|
|
435
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { size: 20 }),
|
|
436
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm flex-1", children: t(`${currentValue.action}`) }),
|
|
437
|
+
isArrow && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_md.MdKeyboardArrowRight, { size: 20 })
|
|
438
|
+
]
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
};
|
|
442
|
+
var ContextMenuItem_default = ContextMenuItem;
|
|
443
|
+
|
|
444
|
+
// src/component/ui/ContextMenu/DropdownContextChild.tsx
|
|
445
|
+
var import_react4 = __toESM(require("@tippyjs/react"));
|
|
446
|
+
var import_react5 = require("react");
|
|
447
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
448
|
+
var DropdownContextChild = ({ button, children, ...rest }) => {
|
|
449
|
+
const id = (0, import_react5.useId)();
|
|
450
|
+
const instanceRef = (0, import_react5.useRef)(null);
|
|
451
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
452
|
+
import_react4.default,
|
|
453
|
+
{
|
|
454
|
+
theme: "drop-down",
|
|
455
|
+
className: "!bg-transparent !text-inherit !border-r-0 [&>*]:!p-0",
|
|
456
|
+
appendTo: document.body,
|
|
457
|
+
arrow: false,
|
|
458
|
+
placement: "auto",
|
|
459
|
+
interactive: true,
|
|
460
|
+
allowHTML: true,
|
|
461
|
+
content: children,
|
|
462
|
+
...rest,
|
|
463
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
464
|
+
"div",
|
|
465
|
+
{
|
|
466
|
+
id: `div-${id}`,
|
|
467
|
+
onClick: () => {
|
|
468
|
+
var _a;
|
|
469
|
+
(_a = instanceRef == null ? void 0 : instanceRef.current) == null ? void 0 : _a.show();
|
|
470
|
+
},
|
|
471
|
+
children: button
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
}
|
|
475
|
+
);
|
|
476
|
+
};
|
|
477
|
+
var DropdownContextChild_default = DropdownContextChild;
|
|
478
|
+
|
|
479
|
+
// src/component/ui/ContextMenu/RenderContextMenu.tsx
|
|
480
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
481
|
+
var RenderContextMenu = ({
|
|
482
|
+
renderData,
|
|
483
|
+
valueClickItem,
|
|
484
|
+
expandValue = {}
|
|
485
|
+
}) => {
|
|
486
|
+
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, import_react6.useState)(false);
|
|
488
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react6.Fragment, { children: [
|
|
489
|
+
!(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
490
|
+
ContextMenuItem_default,
|
|
491
|
+
{
|
|
492
|
+
currentValue: menuAction,
|
|
493
|
+
expandValue,
|
|
494
|
+
valueClickItem
|
|
495
|
+
}
|
|
496
|
+
),
|
|
497
|
+
(menuAction == null ? void 0 : menuAction.children) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
498
|
+
DropdownContextChild_default,
|
|
499
|
+
{
|
|
500
|
+
appendTo: "parent",
|
|
501
|
+
placement: "right",
|
|
502
|
+
offset: [0, 5],
|
|
503
|
+
onShow: () => setIsShow(true),
|
|
504
|
+
onHide: () => setIsShow(false),
|
|
505
|
+
button: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
506
|
+
ContextMenuItem_default,
|
|
507
|
+
{
|
|
508
|
+
currentValue: menuAction,
|
|
509
|
+
expandValue,
|
|
510
|
+
valueClickItem,
|
|
511
|
+
show: isShow,
|
|
512
|
+
isArrow: true
|
|
513
|
+
}
|
|
514
|
+
),
|
|
515
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "dropdown-context-child absolute -top-[20px] -left-1", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
516
|
+
RenderContextMenu,
|
|
517
|
+
{
|
|
518
|
+
renderData: menuAction == null ? void 0 : menuAction.children,
|
|
519
|
+
expandValue,
|
|
520
|
+
valueClickItem
|
|
521
|
+
}
|
|
522
|
+
) })
|
|
523
|
+
}
|
|
524
|
+
)
|
|
525
|
+
] }, index);
|
|
526
|
+
}) });
|
|
527
|
+
};
|
|
528
|
+
var RenderContextMenu_default = RenderContextMenu;
|
|
529
|
+
|
|
530
|
+
// src/component/TableStyleContextWapper.tsx
|
|
531
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
532
|
+
var TableStyleContextMenuWapper = ({
|
|
533
|
+
children,
|
|
534
|
+
contextMenuProps,
|
|
535
|
+
clsTablecustom,
|
|
536
|
+
renderContext
|
|
537
|
+
}) => {
|
|
538
|
+
const idWapper = (0, import_react7.useId)();
|
|
539
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
540
|
+
"div",
|
|
541
|
+
{
|
|
542
|
+
id: `wapper_menu_context-${idWapper}`,
|
|
543
|
+
className: `border border-[#dedede] rounded-xl overflow-hidden bg-white flex-1 h-full flex flex-col min-h-[360px] ${clsTablecustom != null ? clsTablecustom : ""}`,
|
|
544
|
+
children: [
|
|
545
|
+
(renderContext == null ? void 0 : renderContext.renderData) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
546
|
+
ContextMenu_default,
|
|
547
|
+
{
|
|
548
|
+
selector: `[id="wapper_menu_context-${idWapper}"] .rdg`,
|
|
549
|
+
...contextMenuProps,
|
|
550
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(RenderContextMenu_default, { ...renderContext })
|
|
551
|
+
}
|
|
552
|
+
),
|
|
553
|
+
children
|
|
554
|
+
]
|
|
555
|
+
}
|
|
556
|
+
);
|
|
557
|
+
};
|
|
558
|
+
var TableStyleContextWapper = (0, import_react7.memo)(
|
|
559
|
+
TableStyleContextMenuWapper
|
|
560
|
+
);
|
|
410
561
|
// Annotate the CommonJS export names for ESM import in node:
|
|
411
562
|
0 && (module.exports = {
|
|
412
|
-
ReactTableGridCustom
|
|
563
|
+
ReactTableGridCustom,
|
|
564
|
+
TableStyleContextWapper
|
|
413
565
|
});
|