hi-tm 0.10.8 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,46 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
"use client";
|
|
35
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
5
|
};
|
|
38
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const react_1 =
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_2 = require("react");
|
|
40
9
|
const image_1 = __importDefault(require("next/image"));
|
|
41
10
|
const SafeImage_1 = __importDefault(require("../../../elements/SafeImage"));
|
|
42
|
-
|
|
43
|
-
|
|
11
|
+
// Simple Loader component defined inline to avoid import issues
|
|
12
|
+
const Loader = () => {
|
|
13
|
+
return (react_1.default.createElement("div", { className: "flex items-center justify-center" },
|
|
14
|
+
react_1.default.createElement("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-gray-900" })));
|
|
15
|
+
};
|
|
16
|
+
// Helper function to format numbers with commas
|
|
44
17
|
const formatWithCommas = (value) => {
|
|
45
18
|
if (value === undefined || value === null)
|
|
46
19
|
return "";
|
|
@@ -49,48 +22,28 @@ const formatWithCommas = (value) => {
|
|
|
49
22
|
return value.toString();
|
|
50
23
|
return numValue.toLocaleString();
|
|
51
24
|
};
|
|
25
|
+
// Helper function to handle modal styles
|
|
52
26
|
const modalStyleOperationHandler = (classType) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
: "hover:bg-gray-500/10";
|
|
56
|
-
};
|
|
57
|
-
// تابع برای محاسبه تمام IDهای فرزندان یک ردیف
|
|
58
|
-
const getDescendantIds = (row) => {
|
|
59
|
-
let ids = [];
|
|
60
|
-
if (row.hasChildren && row.childRows) {
|
|
61
|
-
row.childRows.forEach((child) => {
|
|
62
|
-
ids.push(child.id);
|
|
63
|
-
if (child.hasChildren && child.childRows) {
|
|
64
|
-
ids = [...ids, ...getDescendantIds(child)];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
27
|
+
if (classType === "delete") {
|
|
28
|
+
return "hover:bg-red-500/20 text-red-700";
|
|
67
29
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// تابع بهینهشده isIndeterminate
|
|
71
|
-
const isIndeterminate = (rowId, rows, selectedRowsSet, descendantIdsMap) => {
|
|
72
|
-
const row = rows?.find((r) => r.id === rowId);
|
|
73
|
-
if (!row ||
|
|
74
|
-
!row.hasChildren ||
|
|
75
|
-
!row.childRows ||
|
|
76
|
-
row.childRows.length === 0) {
|
|
77
|
-
return false;
|
|
30
|
+
else {
|
|
31
|
+
return "hover:bg-gray-500/10";
|
|
78
32
|
}
|
|
79
|
-
const descendantIds = descendantIdsMap[rowId] || [];
|
|
80
|
-
const selectedCount = descendantIds.filter((id) => selectedRowsSet.has(id)).length;
|
|
81
|
-
const isRowSelected = selectedRowsSet.has(rowId);
|
|
82
|
-
return ((selectedCount > 0 && selectedCount < descendantIds.length) ||
|
|
83
|
-
(!isRowSelected && selectedCount > 0));
|
|
84
33
|
};
|
|
85
|
-
const ModernTable = ({ rows = [],
|
|
34
|
+
const ModernTable = ({ rows = [], onEdit, loadingProps = {
|
|
86
35
|
isLoading: false,
|
|
87
36
|
loadingText: "درحال دریافت اطلاعات",
|
|
88
37
|
loadingIcon: react_1.default.createElement(Loader, null),
|
|
89
|
-
},
|
|
38
|
+
}, onView, onAction, selectable, onSelectionChange, actions, ShowActionModal = true, modalActions, noItemFoundProps, selectedItems = [], iconsSRC,
|
|
39
|
+
// Child row configuration with defaults
|
|
40
|
+
childRowConfig = {
|
|
90
41
|
expandByDefault: false,
|
|
91
42
|
indentSize: "1.5rem",
|
|
92
43
|
childRowClass: "bg-blue-300 bg-opacity-10",
|
|
93
|
-
},
|
|
44
|
+
},
|
|
45
|
+
// Mobile card view configuration props
|
|
46
|
+
mobileCardConfig = {
|
|
94
47
|
enabled: true,
|
|
95
48
|
showFolderIcon: true,
|
|
96
49
|
folderIconPath: "",
|
|
@@ -110,71 +63,102 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
110
63
|
marginBottom: "mb-4",
|
|
111
64
|
},
|
|
112
65
|
gridLayoutClassName: "grid-cols-1 sm:grid-cols-2 gap-4",
|
|
113
|
-
}, showModalIcon = true, actionButtonsStyle, gridClassName, isMobileView = false,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const [
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
//
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
row.childRows.
|
|
136
|
-
|
|
137
|
-
}
|
|
66
|
+
}, showModalIcon = true, actionButtonsStyle, gridClassName, isMobileView = false, // Default to false
|
|
67
|
+
mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
|
|
68
|
+
pageIndex = 0, // Default to first page (0-indexed)
|
|
69
|
+
}) => {
|
|
70
|
+
// Track which rows are expanded to show their children
|
|
71
|
+
const [expandedRows, setExpandedRows] = (0, react_2.useState)([]);
|
|
72
|
+
const [activeModal, setActiveModal] = (0, react_2.useState)(null);
|
|
73
|
+
const modalRef = (0, react_2.useRef)(null);
|
|
74
|
+
// Store calculated column widths
|
|
75
|
+
const [selectedRows, setSelectedRows] = (0, react_2.useState)(selectedItems || []);
|
|
76
|
+
// Calculate and store column widths based on all rows (parents and children)
|
|
77
|
+
(0, react_2.useEffect)(() => {
|
|
78
|
+
// if (!rows || rows.length === 0) return;
|
|
79
|
+
// Get all rows including children
|
|
80
|
+
const allRows = [];
|
|
81
|
+
// Helper function to recursively collect all rows at any depth
|
|
82
|
+
const collectRows = (rowsArray, level = 0) => {
|
|
83
|
+
rowsArray?.forEach((row) => {
|
|
84
|
+
// Add level information to the row for proper indentation
|
|
85
|
+
const rowWithLevel = { ...row, level };
|
|
86
|
+
allRows.push(rowWithLevel);
|
|
87
|
+
// Recursively process children at any depth
|
|
88
|
+
if (row.hasChildren && row.childRows && row.childRows.length > 0) {
|
|
89
|
+
collectRows(row.childRows, level + 1);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
if (rows) {
|
|
94
|
+
collectRows(rows);
|
|
95
|
+
}
|
|
96
|
+
// Find the maximum number of columns
|
|
97
|
+
const maxColumns = Math.max(...allRows.map((row) => (row.data ? row.data.length : 0)));
|
|
98
|
+
// Calculate the width for each column
|
|
99
|
+
const widths = [];
|
|
100
|
+
for (let colIndex = 0; colIndex < maxColumns; colIndex++) {
|
|
101
|
+
// Check if any row has a defined width for this column
|
|
102
|
+
const columnsWithWidth = allRows
|
|
103
|
+
.filter((row) => row.data &&
|
|
104
|
+
row.data[colIndex] &&
|
|
105
|
+
row.data[colIndex].inlineCSS &&
|
|
106
|
+
"width" in (row.data[colIndex].inlineCSS || {}))
|
|
107
|
+
.map((row) => row.data[colIndex]);
|
|
108
|
+
if (columnsWithWidth.length > 0) {
|
|
109
|
+
// Use the first defined width (could be enhanced to use max/average)
|
|
110
|
+
const firstWidth = columnsWithWidth[0].inlineCSS?.width;
|
|
111
|
+
if (firstWidth) {
|
|
112
|
+
widths[colIndex] =
|
|
113
|
+
typeof firstWidth === "string" ? firstWidth : `${firstWidth}px`;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
widths[colIndex] = "auto";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// If no defined width, set a responsive width
|
|
121
|
+
widths[colIndex] = `${100 / maxColumns}%`;
|
|
138
122
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
123
|
+
}
|
|
124
|
+
}, [rows]);
|
|
125
|
+
// Initialize expanded rows if specified in config
|
|
126
|
+
(0, react_2.useEffect)(() => {
|
|
127
|
+
if (childRowConfig.expandByDefault && rows) {
|
|
128
|
+
const parentIds = rows
|
|
129
|
+
.filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
|
|
130
|
+
.map((row) => row.id);
|
|
131
|
+
setExpandedRows(parentIds);
|
|
132
|
+
}
|
|
133
|
+
}, [rows, childRowConfig.expandByDefault]);
|
|
134
|
+
(0, react_2.useEffect)(() => {
|
|
144
135
|
const handleClickOutside = (event) => {
|
|
145
136
|
const target = event.target;
|
|
146
|
-
if (target.closest(".modal-content"))
|
|
137
|
+
if (target.closest(".modal-content")) {
|
|
147
138
|
return;
|
|
139
|
+
}
|
|
148
140
|
if (modalRef.current &&
|
|
149
141
|
!modalRef.current.contains(event.target)) {
|
|
150
142
|
setActiveModal(null);
|
|
151
143
|
}
|
|
152
144
|
};
|
|
153
145
|
document.addEventListener("mousedown", handleClickOutside);
|
|
154
|
-
return () =>
|
|
146
|
+
return () => {
|
|
147
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
148
|
+
};
|
|
155
149
|
}, []);
|
|
156
|
-
|
|
157
|
-
(0, react_1.useEffect)(() => {
|
|
150
|
+
(0, react_2.useEffect)(() => {
|
|
158
151
|
const handleScroll = () => {
|
|
159
|
-
if (activeModal !== null)
|
|
152
|
+
if (activeModal !== null) {
|
|
160
153
|
setActiveModal(null);
|
|
154
|
+
}
|
|
161
155
|
};
|
|
162
156
|
window.addEventListener("scroll", handleScroll, { passive: true });
|
|
163
|
-
return () =>
|
|
157
|
+
return () => {
|
|
158
|
+
window.removeEventListener("scroll", handleScroll);
|
|
159
|
+
};
|
|
164
160
|
}, [activeModal]);
|
|
165
|
-
|
|
166
|
-
(0, react_1.useEffect)(() => {
|
|
167
|
-
setSelectedRows(selectedItems || []);
|
|
168
|
-
}, [selectedItems]);
|
|
169
|
-
// مدیریت گسترش ردیفها
|
|
170
|
-
(0, react_1.useEffect)(() => {
|
|
171
|
-
if (childRowConfig.expandByDefault && rows) {
|
|
172
|
-
const parentIds = rows
|
|
173
|
-
.filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
|
|
174
|
-
.map((row) => row.id);
|
|
175
|
-
setExpandedRows(parentIds);
|
|
176
|
-
}
|
|
177
|
-
}, [rows, childRowConfig.expandByDefault]);
|
|
161
|
+
const [mousePosition, setMousePosition] = (0, react_2.useState)({ x: 0, y: 0 });
|
|
178
162
|
const handleModalToggle = (id, e) => {
|
|
179
163
|
e.stopPropagation();
|
|
180
164
|
e.preventDefault();
|
|
@@ -184,8 +168,9 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
184
168
|
const handleActionClick = (actionId, rowId, e) => {
|
|
185
169
|
e.stopPropagation();
|
|
186
170
|
setActiveModal(null);
|
|
187
|
-
if (onAction)
|
|
171
|
+
if (onAction) {
|
|
188
172
|
onAction(actionId, rowId);
|
|
173
|
+
}
|
|
189
174
|
};
|
|
190
175
|
const handleRowExpandToggle = (rowId, e) => {
|
|
191
176
|
e.stopPropagation();
|
|
@@ -193,20 +178,6 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
193
178
|
? prev.filter((id) => id !== rowId)
|
|
194
179
|
: [...prev, rowId]);
|
|
195
180
|
};
|
|
196
|
-
const handleCheckboxChange = (id) => {
|
|
197
|
-
if (onSelectionChange) {
|
|
198
|
-
onSelectionChange(id);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
const updatedSelection = selectedRows.includes(id)
|
|
202
|
-
? selectedRows.filter((rowId) => rowId !== id)
|
|
203
|
-
: [...selectedRows, id];
|
|
204
|
-
setSelectedRows(updatedSelection);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
const isSelected = (rowId) => {
|
|
208
|
-
return selectedRowsSet.has(rowId);
|
|
209
|
-
};
|
|
210
181
|
const getStatusClass = (statusClass) => {
|
|
211
182
|
switch (statusClass) {
|
|
212
183
|
case "success":
|
|
@@ -232,11 +203,239 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
232
203
|
case "price":
|
|
233
204
|
return (react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm w-full truncate ` }, formatWithCommas(item.value)));
|
|
234
205
|
default:
|
|
235
|
-
return (react_1.default.createElement("div", { onClick: () =>
|
|
236
|
-
|
|
206
|
+
return (react_1.default.createElement("div", { onClick: () => {
|
|
207
|
+
if (item.onClick) {
|
|
208
|
+
item.onClick(item.id);
|
|
209
|
+
}
|
|
210
|
+
}, className: "flex items-center gap-2 w-full" }, item.hasImage && item.imageUrl !== null ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" },
|
|
211
|
+
react_1.default.createElement(SafeImage_1.default, { src: ((item.imageUrl !== null || item.imageUrl !== "") &&
|
|
212
|
+
item.imageUrl) ||
|
|
213
|
+
"/defaultImage.jpg", alt: item.value?.toString() || "Table item", width: item.imageWidth || 24, height: item.imageHeight || 24, className: item.imageClass || "h-6 w-6 object-cover" }),
|
|
237
214
|
react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm w-full truncate ` }, item.value))) : (react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm mr-[5px] w-full truncate`, title: item.value?.toString() || "" }, item.value))));
|
|
238
215
|
}
|
|
239
216
|
};
|
|
217
|
+
// Update selectedRows when selectedItems prop changes
|
|
218
|
+
(0, react_2.useEffect)(() => {
|
|
219
|
+
setSelectedRows(selectedItems || []);
|
|
220
|
+
}, [selectedItems]);
|
|
221
|
+
// Handle checkbox change for row selection
|
|
222
|
+
// const handleCheckboxChange = (id: number) => {
|
|
223
|
+
// console.log(`Processing ID: ${id}`);
|
|
224
|
+
// // Create a new copy of the current selection
|
|
225
|
+
// let updatedSelection = [...selectedRows];
|
|
226
|
+
// // Check if the row is currently selected
|
|
227
|
+
// const isSelected = updatedSelection.includes(id);
|
|
228
|
+
// console.log(`ID ${id} is currently selected: ${isSelected}`);
|
|
229
|
+
// // Find the item in the rows data
|
|
230
|
+
// const findItemById = (items: TableRowData[] | undefined, itemId: number): TableRowData | null => {
|
|
231
|
+
// if (!items) return null;
|
|
232
|
+
// for (const item of items) {
|
|
233
|
+
// if (item.id === itemId) {
|
|
234
|
+
// return item;
|
|
235
|
+
// }
|
|
236
|
+
// if (item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
237
|
+
// const foundInChildren = findItemById(item.childRows, itemId);
|
|
238
|
+
// if (foundInChildren) return foundInChildren;
|
|
239
|
+
// }
|
|
240
|
+
// }
|
|
241
|
+
// return null;
|
|
242
|
+
// };
|
|
243
|
+
// const item = findItemById(rows!, id);
|
|
244
|
+
// console.log(`Found item for ID ${id}:`, item);
|
|
245
|
+
// if (isSelected) {
|
|
246
|
+
// // DESELECTION LOGIC
|
|
247
|
+
// console.log(`Deselecting ID ${id}`);
|
|
248
|
+
// // Remove the item itself
|
|
249
|
+
// updatedSelection = updatedSelection.filter(itemId => itemId !== id);
|
|
250
|
+
// // If item exists and has children, remove all children too
|
|
251
|
+
// if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
252
|
+
// // Function to collect all descendant IDs
|
|
253
|
+
// const getAllDescendantIds = (items: TableRowData[]): number[] => {
|
|
254
|
+
// let allIds: number[] = [];
|
|
255
|
+
// for (const childItem of items) {
|
|
256
|
+
// allIds.push(childItem.id);
|
|
257
|
+
// if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
|
|
258
|
+
// allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
|
|
259
|
+
// }
|
|
260
|
+
// }
|
|
261
|
+
// return allIds;
|
|
262
|
+
// };
|
|
263
|
+
// const descendantIds = getAllDescendantIds(item.childRows);
|
|
264
|
+
// console.log(`Descendant IDs to remove:`, descendantIds);
|
|
265
|
+
// // Remove all descendant IDs from the selection
|
|
266
|
+
// updatedSelection = updatedSelection.filter(itemId => !descendantIds.includes(itemId));
|
|
267
|
+
// }
|
|
268
|
+
// } else {
|
|
269
|
+
// // SELECTION LOGIC
|
|
270
|
+
// console.log(`Selecting ID ${id}`);
|
|
271
|
+
// // Add the item itself
|
|
272
|
+
// updatedSelection.push(id);
|
|
273
|
+
// // If item exists and has children, add all children too
|
|
274
|
+
// if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
275
|
+
// // Function to collect all descendant IDs
|
|
276
|
+
// const getAllDescendantIds = (items: TableRowData[]): number[] => {
|
|
277
|
+
// let allIds: number[] = [];
|
|
278
|
+
// for (const childItem of items) {
|
|
279
|
+
// allIds.push(childItem.id);
|
|
280
|
+
// if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
|
|
281
|
+
// allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
|
|
282
|
+
// }
|
|
283
|
+
// }
|
|
284
|
+
// return allIds;
|
|
285
|
+
// };
|
|
286
|
+
// const descendantIds = getAllDescendantIds(item.childRows);
|
|
287
|
+
// console.log(`Descendant IDs to add:`, descendantIds);
|
|
288
|
+
// // Add all descendant IDs to the selection if not already included
|
|
289
|
+
// for (const descendantId of descendantIds) {
|
|
290
|
+
// if (!updatedSelection.includes(descendantId)) {
|
|
291
|
+
// updatedSelection.push(descendantId);
|
|
292
|
+
// }
|
|
293
|
+
// }
|
|
294
|
+
// }
|
|
295
|
+
// }
|
|
296
|
+
// console.log("New selection:", updatedSelection);
|
|
297
|
+
// setSelectedRows(updatedSelection);
|
|
298
|
+
// if (onSelectionChange) {
|
|
299
|
+
// onSelectionChange([...updatedSelection]);
|
|
300
|
+
// }
|
|
301
|
+
// };
|
|
302
|
+
// Function to determine if a row has any descendants selected (not just direct children)
|
|
303
|
+
// const isIndeterminate = (rowId: number): boolean => {
|
|
304
|
+
// // Find the row in the data
|
|
305
|
+
// const findRow = (
|
|
306
|
+
// rows: TableRowData[] | undefined,
|
|
307
|
+
// id: number
|
|
308
|
+
// ): TableRowData | null => {
|
|
309
|
+
// if (!rows) return null;
|
|
310
|
+
// for (const row of rows) {
|
|
311
|
+
// if (row.id === id) return row;
|
|
312
|
+
// if (row.hasChildren && row.childRows) {
|
|
313
|
+
// const found = findRow(row.childRows, id);
|
|
314
|
+
// if (found) return found;
|
|
315
|
+
// }
|
|
316
|
+
// }
|
|
317
|
+
// return null;
|
|
318
|
+
// };
|
|
319
|
+
// const row = findRow(rows!, rowId);
|
|
320
|
+
// // If row has no children, it can't be indeterminate
|
|
321
|
+
// if (
|
|
322
|
+
// !row ||
|
|
323
|
+
// !row.hasChildren ||
|
|
324
|
+
// !row.childRows ||
|
|
325
|
+
// row.childRows.length === 0
|
|
326
|
+
// ) {
|
|
327
|
+
// return false;
|
|
328
|
+
// }
|
|
329
|
+
// // Check if the row itself is selected
|
|
330
|
+
// const isRowSelected = selectedRows.includes(rowId);
|
|
331
|
+
// // Recursively check if any descendant is selected
|
|
332
|
+
// const hasSelectedDescendant = (children: TableRowData[]): boolean => {
|
|
333
|
+
// for (const child of children) {
|
|
334
|
+
// // If any child is selected
|
|
335
|
+
// if (selectedRows.includes(child.id)) {
|
|
336
|
+
// return true;
|
|
337
|
+
// }
|
|
338
|
+
// // Check grandchildren if they exist
|
|
339
|
+
// if (
|
|
340
|
+
// child.hasChildren &&
|
|
341
|
+
// child.childRows &&
|
|
342
|
+
// child.childRows.length > 0
|
|
343
|
+
// ) {
|
|
344
|
+
// if (hasSelectedDescendant(child.childRows)) {
|
|
345
|
+
// return true;
|
|
346
|
+
// }
|
|
347
|
+
// }
|
|
348
|
+
// }
|
|
349
|
+
// return false;
|
|
350
|
+
// };
|
|
351
|
+
// // Check if all descendants are selected
|
|
352
|
+
// const areAllDescendantsSelected = (children: TableRowData[]): boolean => {
|
|
353
|
+
// for (const child of children) {
|
|
354
|
+
// // If any child is not selected
|
|
355
|
+
// if (!selectedRows.includes(child.id)) {
|
|
356
|
+
// return false;
|
|
357
|
+
// }
|
|
358
|
+
// // Check grandchildren if they exist
|
|
359
|
+
// if (
|
|
360
|
+
// child.hasChildren &&
|
|
361
|
+
// child.childRows &&
|
|
362
|
+
// child.childRows.length > 0
|
|
363
|
+
// ) {
|
|
364
|
+
// if (!areAllDescendantsSelected(child.childRows)) {
|
|
365
|
+
// return false;
|
|
366
|
+
// }
|
|
367
|
+
// }
|
|
368
|
+
// }
|
|
369
|
+
// return true;
|
|
370
|
+
// };
|
|
371
|
+
// const hasAnySelected = hasSelectedDescendant(row.childRows);
|
|
372
|
+
// const hasAllSelected = areAllDescendantsSelected(row.childRows);
|
|
373
|
+
// // Indeterminate if some but not all descendants are selected
|
|
374
|
+
// // Or if the parent is not selected but some children are
|
|
375
|
+
// return (
|
|
376
|
+
// (hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected)
|
|
377
|
+
// );
|
|
378
|
+
// };
|
|
379
|
+
const isIndeterminate = (rowId) => {
|
|
380
|
+
const findRow = (rows, id) => {
|
|
381
|
+
if (!rows)
|
|
382
|
+
return { row: null, path: [] };
|
|
383
|
+
for (const row of rows) {
|
|
384
|
+
if (row.id === id)
|
|
385
|
+
return { row, path: [row] };
|
|
386
|
+
if (row.hasChildren && row.childRows) {
|
|
387
|
+
const found = findRow(row.childRows, id);
|
|
388
|
+
if (found.row)
|
|
389
|
+
return { row: found.row, path: [row, ...found.path] };
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return { row: null, path: [] };
|
|
393
|
+
};
|
|
394
|
+
const { row, path } = findRow(rows, rowId);
|
|
395
|
+
if (!row ||
|
|
396
|
+
!row.hasChildren ||
|
|
397
|
+
!row.childRows ||
|
|
398
|
+
row.childRows.length === 0) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
const isRowSelected = selectedRows.includes(rowId);
|
|
402
|
+
// پیمایش یکباره برای بررسی وضعیت فرزندان
|
|
403
|
+
let hasAnySelected = false;
|
|
404
|
+
let hasAllSelected = true;
|
|
405
|
+
const checkDescendants = (children) => {
|
|
406
|
+
for (const child of children) {
|
|
407
|
+
const childSelected = selectedRows.includes(child.id);
|
|
408
|
+
if (childSelected)
|
|
409
|
+
hasAnySelected = true;
|
|
410
|
+
else
|
|
411
|
+
hasAllSelected = false;
|
|
412
|
+
if (child.hasChildren && child.childRows) {
|
|
413
|
+
checkDescendants(child.childRows);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
checkDescendants(row.childRows);
|
|
418
|
+
return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
|
|
419
|
+
};
|
|
420
|
+
// Function to check if a row is selected
|
|
421
|
+
const isSelected = (rowId) => {
|
|
422
|
+
return selectedRows.includes(rowId);
|
|
423
|
+
};
|
|
424
|
+
const handleCheckboxChange = (id) => {
|
|
425
|
+
// Call your existing handleSelectionChange function
|
|
426
|
+
// This will handle the hierarchical selection logic
|
|
427
|
+
if (onSelectionChange) {
|
|
428
|
+
onSelectionChange(id);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
// Fallback to simple selection if no onSelectionChange is provided
|
|
432
|
+
const updatedSelection = selectedRows.includes(id)
|
|
433
|
+
? selectedRows.filter((rowId) => rowId !== id)
|
|
434
|
+
: [...selectedRows, id];
|
|
435
|
+
setSelectedRows(updatedSelection);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
// Extract title and subtitle from row data
|
|
240
439
|
const extractCardData = (row) => {
|
|
241
440
|
let title = "";
|
|
242
441
|
let subtitle = "";
|
|
@@ -246,46 +445,58 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
246
445
|
let price = "";
|
|
247
446
|
if (!row.data)
|
|
248
447
|
return { title, subtitle, icon, status, statusClass, price };
|
|
448
|
+
// Find title (usually first text item)
|
|
249
449
|
const titleItem = row.data.find((item) => item.type === "text" && item.value);
|
|
250
450
|
if (titleItem) {
|
|
251
451
|
title = titleItem.value;
|
|
252
452
|
}
|
|
253
453
|
else if (row.data.length > 0) {
|
|
454
|
+
// Fallback to first item
|
|
254
455
|
title = String(row.data[0].value || "");
|
|
255
456
|
}
|
|
457
|
+
// Find subtitle (usually size or description)
|
|
256
458
|
const subtitleItem = row.data.find((item) => item.type === "text" && item.isSubtitle);
|
|
257
459
|
if (subtitleItem) {
|
|
258
460
|
subtitle = subtitleItem.value;
|
|
259
461
|
}
|
|
260
462
|
else if (row.data.length > 1) {
|
|
463
|
+
// Fallback to second item
|
|
261
464
|
subtitle = String(row.data[1].value || "");
|
|
262
465
|
}
|
|
466
|
+
// Find status
|
|
263
467
|
const statusItem = row.data.find((item) => item.type === "status");
|
|
264
468
|
if (statusItem) {
|
|
265
469
|
status = String(statusItem.value || "");
|
|
266
470
|
statusClass = statusItem.statusClass || "";
|
|
267
471
|
}
|
|
472
|
+
// Find price (look for item with isPrice flag)
|
|
268
473
|
const priceItem = row.data.find((item) => item.isPrice);
|
|
269
474
|
if (priceItem) {
|
|
270
475
|
price = String(priceItem.value || "");
|
|
271
476
|
}
|
|
477
|
+
// Find icon (usually avatar or image)
|
|
272
478
|
const iconItem = row.data.find((item) => item.hasImage);
|
|
273
479
|
if (iconItem && iconItem.value) {
|
|
274
480
|
icon = String(iconItem.imageUrl || "");
|
|
275
481
|
}
|
|
276
482
|
return { title, subtitle, icon, status, statusClass, price };
|
|
277
483
|
};
|
|
484
|
+
// Find avatar items in row data
|
|
278
485
|
const findAvatarItems = (row) => {
|
|
279
486
|
if (!row.data)
|
|
280
487
|
return [];
|
|
281
488
|
return row.data.filter((item) => item.type === "avatar" && item.isUserAvatar);
|
|
282
489
|
};
|
|
490
|
+
// Get all rows and their children for mobile view - updated for multi-level nesting
|
|
283
491
|
const getAllMobileRows = () => {
|
|
284
492
|
const result = [];
|
|
493
|
+
// Helper function to add parent rows and child rows that should be visible at any depth
|
|
285
494
|
const processRows = (rows, level = 0) => {
|
|
286
495
|
rows?.forEach((row) => {
|
|
496
|
+
// Add level information to the row for proper indentation
|
|
287
497
|
const rowWithLevel = { ...row, level, isChild: level > 0 };
|
|
288
498
|
result.push(rowWithLevel);
|
|
499
|
+
// Add child rows if this row is expanded - recursively check all levels
|
|
289
500
|
if (row.hasChildren &&
|
|
290
501
|
expandedRows.includes(row.id) &&
|
|
291
502
|
row.childRows &&
|
|
@@ -294,10 +505,12 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
294
505
|
}
|
|
295
506
|
});
|
|
296
507
|
};
|
|
297
|
-
if (rows)
|
|
508
|
+
if (rows) {
|
|
298
509
|
processRows(rows);
|
|
510
|
+
}
|
|
299
511
|
return result;
|
|
300
512
|
};
|
|
513
|
+
// Mobile card view
|
|
301
514
|
const renderMobileCard = (row) => {
|
|
302
515
|
if (!row || !row.data)
|
|
303
516
|
return null;
|
|
@@ -306,7 +519,10 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
306
519
|
const isFavorited = row.data.some((item) => item.isFavorite);
|
|
307
520
|
const hasChildren = row.hasChildren && row.childRows && row?.childRows?.length > 0;
|
|
308
521
|
const level = row.level || 0;
|
|
309
|
-
const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
|
|
522
|
+
const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
|
|
523
|
+
// showMoreOptions,
|
|
524
|
+
moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
|
|
525
|
+
// Calculate card classes - add special styling for child cards
|
|
310
526
|
const cardClasses = `
|
|
311
527
|
${cardStyle?.backgroundColor || "bg-white"}
|
|
312
528
|
${cardStyle?.borderRadius || "rounded-lg"}
|
|
@@ -328,7 +544,7 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
328
544
|
react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
329
545
|
react_1.default.createElement("input", { type: "checkbox", checked: isSelected(row.id), onChange: () => handleCheckboxChange(row.id), className: "peer h-5 w-5 mr-2 cursor-pointer appearance-none rounded-md border-2 border-gray-300 transition-all checked:border-blue-500 checked:bg-blue-500 hover:border-blue-500", onClick: (e) => e.stopPropagation(), ref: (el) => {
|
|
330
546
|
if (el) {
|
|
331
|
-
el.indeterminate =
|
|
547
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
332
548
|
}
|
|
333
549
|
} })))),
|
|
334
550
|
react_1.default.createElement("div", { className: "flex-1 min-w-0" },
|
|
@@ -338,37 +554,42 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
338
554
|
level > 0 && (react_1.default.createElement("div", { className: `h-2 w-2 rounded-full bg-blue-${Math.min(400 + level * 100, 900)} mr-2 flex-shrink-0` })),
|
|
339
555
|
react_1.default.createElement("h3", { className: "text-sm font-medium truncate" }, title)),
|
|
340
556
|
react_1.default.createElement("p", { className: "text-xs text-gray-500 mt-1 truncate" }, subtitle),
|
|
341
|
-
price && react_1.default.createElement("p", { className: "text-sm font-semibold
|
|
557
|
+
price && (react_1.default.createElement("p", { className: "text-sm font-semibold mt-1" }, price)),
|
|
342
558
|
status && (react_1.default.createElement("div", { className: "mt-2" },
|
|
343
559
|
react_1.default.createElement("span", { className: `text-xs font-medium px-2 py-1 rounded-full ${getStatusClass(statusClass)} bg-opacity-10` }, status)))),
|
|
344
560
|
react_1.default.createElement("div", { className: "flex items-center flex-shrink-0 ml-2" },
|
|
345
|
-
hasChildren && (react_1.default.createElement("button", { onClick: (e) =>
|
|
561
|
+
hasChildren && (react_1.default.createElement("button", { onClick: (e) => {
|
|
562
|
+
e.stopPropagation();
|
|
563
|
+
handleRowExpandToggle(row.id, e);
|
|
564
|
+
}, className: "p-2 hover:bg-gray-100 rounded" },
|
|
346
565
|
react_1.default.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: `transition-transform ${expandedRows.includes(row.id) ? "rotate-90" : ""}` },
|
|
347
566
|
react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))),
|
|
348
567
|
showFavoriteIcon && (react_1.default.createElement("button", { className: "p-2 hover:bg-gray-100 rounded" },
|
|
349
568
|
react_1.default.createElement(image_1.default, { src: isFavorited
|
|
350
569
|
? favoriteFilledIconPath ?? "/defaultFilledIcon.svg"
|
|
351
570
|
: favoriteOutlineIconPath ?? "/defaultOutlineIcon.svg", alt: "favorite", width: 20, height: 20, className: isFavorited ? "text-yellow-400" : "text-gray-400" }))),
|
|
352
|
-
(typeof showMoreOptions === "function"
|
|
353
|
-
? showMoreOptions(row)
|
|
354
|
-
: showMoreOptions) &&
|
|
571
|
+
(typeof mobileCardConfig.showMoreOptions === "function"
|
|
572
|
+
? mobileCardConfig.showMoreOptions(row)
|
|
573
|
+
: mobileCardConfig.showMoreOptions) &&
|
|
355
574
|
modalActions &&
|
|
356
575
|
modalActions.length > 0 &&
|
|
357
576
|
(typeof showModalIcon === "function"
|
|
358
577
|
? showModalIcon(row)
|
|
359
578
|
: showModalIcon) && (react_1.default.createElement("div", { className: "relative" },
|
|
360
|
-
react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: `p-2 hover:bg-gray-100 rounded ${ShowActionModal
|
|
579
|
+
react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: `p-2 hover:bg-gray-100 rounded ${ShowActionModal
|
|
580
|
+
? ""
|
|
581
|
+
: "opacity-50 cursor-not-allowed "} ` },
|
|
361
582
|
react_1.default.createElement(image_1.default, { src: moreOptionsIconPath || "/placeholder.svg", alt: "menu", width: 20, height: 20, className: `${ShowActionModal
|
|
362
583
|
? ""
|
|
363
584
|
: "opacity-50 cursor-not-allowed"}` })),
|
|
364
585
|
ShowActionModal && activeModal === row.id && (react_1.default.createElement("div", { ref: modalRef, className: "modal-content fixed z-[9999] w-40 rounded-md bg-white shadow-lg", style: {
|
|
365
586
|
position: "fixed",
|
|
366
587
|
top: `${mousePosition.y}px`,
|
|
367
|
-
left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80)
|
|
588
|
+
left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `, // Ensure modal stays within screen
|
|
368
589
|
}, onClick: (e) => e.stopPropagation() },
|
|
369
590
|
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
|
|
370
591
|
? modalActions(row)
|
|
371
|
-
: modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full customTransition ${modalStyleOperationHandler(action.class)} ${action.tailwindClassName || ""}` }, action.text)))))))))),
|
|
592
|
+
: modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full customTransition ${modalStyleOperationHandler(action.class)} ${action.tailwindClassName || ""} ` }, action.text)))))))))),
|
|
372
593
|
showAvatars && avatarItems.length > 0 && (react_1.default.createElement("div", { className: "flex items-center mt-3" },
|
|
373
594
|
react_1.default.createElement("div", { className: "flex -space-x-2" },
|
|
374
595
|
avatarItems.slice(0, maxVisibleAvatars).map((item, idx) => (react_1.default.createElement("div", { key: idx, className: "h-6 w-6 rounded-full border border-white overflow-hidden" },
|
|
@@ -377,7 +598,9 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
377
598
|
"+",
|
|
378
599
|
avatarItems.length - maxVisibleAvatars)))))))));
|
|
379
600
|
};
|
|
601
|
+
// Render a single table row (parent or child)
|
|
380
602
|
const renderTableRow = (row, index, isLastRow) => {
|
|
603
|
+
// Width for the expand/collapse control column
|
|
381
604
|
return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
|
|
382
605
|
react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
|
|
383
606
|
? childRowConfig.childRowClass || "bg-blue-300 bg-opacity-10"
|
|
@@ -389,20 +612,26 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
389
612
|
gridTemplateColumns: isMobileView && mobileViewGridClassName
|
|
390
613
|
? mobileViewGridClassName
|
|
391
614
|
: gridClassName || "repeat(auto-fit, minmax(100px, 1fr))",
|
|
392
|
-
}, onClick: () =>
|
|
615
|
+
}, onClick: () => {
|
|
616
|
+
if (onView) {
|
|
617
|
+
onView(row.id);
|
|
618
|
+
}
|
|
619
|
+
} },
|
|
393
620
|
react_1.default.createElement("div", { className: `flex items-center justify-center gap-2 ${!row.hasChildren && "mr-[4px]"}`, style: { width: "55px" } },
|
|
394
|
-
!row.hasChildren && !row.isChild && (react_1.default.createElement("span", { className: "text-xs text-gray-500 font-semibold flex-shrink-0 mr-1" }, ((pageIndex || 1) - 1) * (itemsPerPage || 10) + index + 1)),
|
|
621
|
+
!row.hasChildren && !row.isChild && (react_1.default.createElement("span", { className: "text-xs text-gray-500 font-semibold flex-shrink-0 mr-1 " }, ((pageIndex || 1) - 1) * (itemsPerPage || 10) + index + 1)),
|
|
395
622
|
react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
|
|
396
623
|
row.hasChildren && row.childRows && row.childRows?.length > 0 ? (react_1.default.createElement("button", { onClick: (e) => handleRowExpandToggle(row.id, e), className: "transition-transform duration-200 flex-shrink-0" },
|
|
397
624
|
react_1.default.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: `transition-transform ${expandedRows.includes(row.id) ? "-rotate-90" : ""}` },
|
|
398
|
-
react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))) : row.isChild ? (
|
|
625
|
+
react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))) : row.isChild ? (
|
|
626
|
+
// Child row indicator
|
|
627
|
+
react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
|
|
399
628
|
selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
400
629
|
react_1.default.createElement("input", { type: "checkbox", checked: isSelected(row.id), onChange: () => handleCheckboxChange(row.id), className: "peer h-5 w-5 cursor-pointer appearance-none rounded-md border-2 border-gray-300 transition-all checked:border-blue-500 checked:bg-blue-500 hover:border-blue-500", onClick: (e) => e.stopPropagation(), ref: (el) => {
|
|
401
630
|
if (el) {
|
|
402
|
-
el.indeterminate =
|
|
631
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
403
632
|
}
|
|
404
633
|
} }),
|
|
405
|
-
|
|
634
|
+
isIndeterminate(row.id) ? (react_1.default.createElement("div", { className: "pointer-events-none absolute left-[5px] top-[9px] w-2.5 h-0.5 bg-blue-500" })) : (react_1.default.createElement("svg", { className: "pointer-events-none absolute left-[5px] top-[5px] h-2.5 w-2.5 fill-white opacity-0 transition-opacity peer-checked:opacity-100", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" },
|
|
406
635
|
react_1.default.createElement("path", { d: "M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z" }))))))),
|
|
407
636
|
row?.data?.map((item, colIndex) => (react_1.default.createElement("div", { key: `${item.id}-${colIndex}`, className: `h-full select-none text-xs font-medium min-w-0 flex items-center ${item.type === "avatar" ||
|
|
408
637
|
item.type === "operation" ||
|
|
@@ -418,14 +647,16 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
418
647
|
: "flex-start",
|
|
419
648
|
} },
|
|
420
649
|
colIndex === 0 && row.isChild && selectable && (react_1.default.createElement("div", { className: "flex items-center" },
|
|
421
|
-
react_1.default.createElement("div", { style: {
|
|
422
|
-
|
|
650
|
+
react_1.default.createElement("div", { style: {
|
|
651
|
+
paddingLeft: `${(row.level || 1) * 7}px`,
|
|
652
|
+
}, className: "flex-shrink-0" }),
|
|
653
|
+
react_1.default.createElement("div", { className: "relative flex items-center justify-center " },
|
|
423
654
|
react_1.default.createElement("input", { type: "checkbox", checked: isSelected(row.id), onChange: () => handleCheckboxChange(row.id), className: "peer h-5 w-5 cursor-pointer appearance-none rounded-md border-2 border-gray-300 transition-all checked:border-blue-500 checked:bg-blue-500 hover:border-blue-500", onClick: (e) => e.stopPropagation(), ref: (el) => {
|
|
424
655
|
if (el) {
|
|
425
|
-
el.indeterminate =
|
|
656
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
426
657
|
}
|
|
427
658
|
} }),
|
|
428
|
-
|
|
659
|
+
isIndeterminate(row.id) ? (react_1.default.createElement("div", { className: "pointer-events-none absolute left-[5px] top-[9px] w-2.5 h-0.5 bg-blue-500" })) : (react_1.default.createElement("svg", { className: "pointer-events-none absolute left-[5px] top-[5px] h-2.5 w-2.5 fill-white opacity-0 transition-opacity peer-checked:opacity-100", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" },
|
|
429
660
|
react_1.default.createElement("path", { d: "M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z" })))))),
|
|
430
661
|
renderCellContent(item)))),
|
|
431
662
|
actions && (react_1.default.createElement("div", { className: `w-24 py-4 flex items-center justify-end text-sm font-medium ${actionButtonsStyle || ""}` },
|
|
@@ -441,15 +672,21 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
441
672
|
(typeof showModalIcon === "function"
|
|
442
673
|
? showModalIcon(row)
|
|
443
674
|
: showModalIcon) ? (react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: "", "data-row-id": row.id },
|
|
444
|
-
react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
|
|
675
|
+
react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
|
|
676
|
+
// Render an invisible placeholder to maintain spacing when icon is hidden
|
|
677
|
+
react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
|
|
445
678
|
ShowActionModal && activeModal === row.id && (react_1.default.createElement("div", { ref: modalRef, className: "modal-content fixed z-[9999] w-40 rounded-md bg-white shadow-lg", style: {
|
|
446
679
|
position: "fixed",
|
|
447
680
|
top: (() => {
|
|
681
|
+
// Get all visible rows for the current view
|
|
448
682
|
const allRows = isMobileView
|
|
449
683
|
? getAllMobileRows()
|
|
450
684
|
: rows;
|
|
685
|
+
// Find the index of the current row
|
|
451
686
|
const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
|
|
687
|
+
// Check if this is one of the last 3 rows
|
|
452
688
|
const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
|
|
689
|
+
// If it's one of the last 3 rows, reduce the top position by 100px
|
|
453
690
|
return isLastThreeRows
|
|
454
691
|
? `${mousePosition.y - 110}px`
|
|
455
692
|
: `${mousePosition.y}px`;
|
|
@@ -458,24 +695,31 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
|
|
|
458
695
|
}, onClick: (e) => e.stopPropagation() },
|
|
459
696
|
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
|
|
460
697
|
? modalActions(row)
|
|
461
|
-
: modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full cursor-pointer ${modalStyleOperationHandler(action.class)} ${action.tailwindClassName || ""}` }, action.text))))))))))),
|
|
698
|
+
: modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full cursor-pointer ${modalStyleOperationHandler(action.class)} customTransition ${action.tailwindClassName || ""} ` }, action.text))))))))))),
|
|
462
699
|
row.hasChildren &&
|
|
463
700
|
expandedRows.includes(row.id) &&
|
|
464
701
|
row.childRows &&
|
|
465
702
|
row.childRows.map((childRow, childIndex) => renderTableRow(childRow, childIndex, childIndex === row.childRows.length - 1 && isLastRow))));
|
|
466
703
|
};
|
|
704
|
+
// Prepare all mobile rows
|
|
467
705
|
const mobileRows = getAllMobileRows();
|
|
706
|
+
// Show loading state if loading is true
|
|
468
707
|
if (loadingProps.isLoading) {
|
|
469
708
|
return (react_1.default.createElement("div", { className: "w-full flex justify-center items-center py-8 gap-3" },
|
|
470
709
|
loadingProps.loadingIcon,
|
|
471
710
|
loadingProps.loadingText && loadingProps.loadingText));
|
|
472
711
|
}
|
|
712
|
+
// Show no items found if rows are empty or null and not loading
|
|
473
713
|
if (!loadingProps.isLoading && rows?.length === 0) {
|
|
474
714
|
return (react_1.default.createElement("div", { className: "flex flex-col items-center justify-center p-8" }, typeof noItemFoundProps?.imagePath === "string" ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
475
715
|
react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath || "/icons/no-data.svg", alt: "No items found", width: 120, height: 120 }),
|
|
476
|
-
react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
|
|
716
|
+
react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
|
|
717
|
+
noItemFoundProps?.title,
|
|
718
|
+
" "))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
477
719
|
noItemFoundProps?.imagePath,
|
|
478
|
-
react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
|
|
720
|
+
react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
|
|
721
|
+
noItemFoundProps?.title,
|
|
722
|
+
" ")))));
|
|
479
723
|
}
|
|
480
724
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
481
725
|
mobileCardConfig.enabled && (react_1.default.createElement("div", { className: `lg:hidden grid ${mobileCardConfig.gridLayoutClassName}` }, mobileRows.map((row) => (react_1.default.createElement("div", { key: `mobile-grid-item-${row.id}`, className: `col-span-1 ${row.isChild ? "pl-2" : ""}` }, renderMobileCard(row)))))),
|