hi-tm 0.0.2 → 0.0.4
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/components/AutoComplete/AutoCompleteMultiSelect.d.ts +1 -1
- package/dist/components/AutoComplete/AutoCompleteMultiSelect.js +26 -19
- package/dist/components/Cards/AutoComplete&DropDown/GeographyCard.js +2 -2
- package/dist/components/Cards/AutoComplete&DropDown/PersonCard.js +2 -2
- package/dist/components/Cards/AutoComplete&DropDown/SimpleCard.js +2 -2
- package/dist/components/DropDowns/CreatableAutoComplete.d.ts +31 -0
- package/dist/components/DropDowns/CreatableAutoComplete.js +104 -0
- package/dist/components/DropDowns/CreatableDropDown.d.ts +2 -1
- package/dist/components/DropDowns/CreatableDropDown.js +89 -16
- package/dist/components/DropDowns/DropDown.js +5 -5
- package/dist/components/DropDowns/DropDownMultiSelect.js +5 -5
- package/dist/components/Inputs/Buttons/Button.d.ts +3 -3
- package/dist/components/Inputs/Buttons/Button.js +15 -15
- package/dist/components/Inputs/TextInput.d.ts +4 -1
- package/dist/components/Inputs/TextInput.js +23 -6
- package/dist/components/Inputs/Toggle.d.ts +2 -2
- package/dist/components/Inputs/Toggle.js +13 -10
- package/dist/components/Layout/Headers/HeaderLayout.js +20 -24
- package/dist/components/Layout/Sidebar.js +51 -10
- package/dist/components/Table/ModernTable/ModernTable.d.ts +2 -2
- package/dist/components/Table/ModernTable/ModernTable.js +399 -150
- package/dist/components/Table/ModernTable/ModernTableHeader.d.ts +4 -1
- package/dist/components/Table/ModernTable/ModernTableHeader.js +6 -2
- package/dist/components/Table/TableRowCards/TableRowCardChildren.js +19 -19
- package/dist/components/Table/TableRowCards/TableRowCardSimple.js +19 -19
- package/dist/components/Tabs/Tabs.d.ts +5 -3
- package/dist/components/Tabs/Tabs.js +13 -2
- package/dist/components/Wrapper/Modals/DeleteConfirmationModal.d.ts +18 -0
- package/dist/components/Wrapper/Modals/DeleteConfirmationModal.js +68 -0
- package/dist/components/sections/components/Tabs/BreadCrumbs.d.ts +1 -1
- package/dist/components/sections/components/Tabs/BreadCrumbs.js +9 -9
- package/dist/components/sections/components/Tabs/TabsComponent.js +19 -3
- package/dist/helper/formatWithCommas.d.ts +1 -0
- package/dist/helper/formatWithCommas.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/styles/globals.css +198 -180
- package/dist/tailwind-preset.ts +41 -41
- package/dist/types/AutoComplete/CreatableAutoComplete.d.ts +34 -0
- package/dist/types/AutoComplete/CreatableAutoComplete.js +2 -0
- package/dist/types/BreakCrumbTypes.d.ts +2 -0
- package/dist/types/Buttons/PrimaryButton.d.ts +4 -3
- package/dist/types/DropDown/CreatableDropDown.d.ts +10 -3
- package/dist/types/Inputs/TextInputType.d.ts +7 -6
- package/dist/types/Layout/Headers/HeaderLayout.d.ts +1 -0
- package/dist/types/Layout/SidebarType.d.ts +2 -1
- package/dist/types/ModernTable/index.d.ts +27 -7
- package/package.json +1 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
"use client";
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
@@ -7,67 +7,85 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const react_2 = require("react");
|
|
9
9
|
const image_1 = __importDefault(require("next/image"));
|
|
10
|
-
|
|
10
|
+
// Simple Loader component defined inline to avoid import issues
|
|
11
|
+
const Loader = () => {
|
|
12
|
+
return (react_1.default.createElement("div", { className: "flex items-center justify-center" },
|
|
13
|
+
react_1.default.createElement("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-gray-900" })));
|
|
14
|
+
};
|
|
15
|
+
// Helper function to format numbers with commas
|
|
16
|
+
const formatWithCommas = (value) => {
|
|
17
|
+
if (value === undefined || value === null)
|
|
18
|
+
return "";
|
|
19
|
+
const numValue = typeof value === "string" ? Number.parseFloat(value) : value;
|
|
20
|
+
if (isNaN(numValue))
|
|
21
|
+
return value.toString();
|
|
22
|
+
return numValue.toLocaleString();
|
|
23
|
+
};
|
|
11
24
|
// Helper function to handle modal styles
|
|
12
25
|
const modalStyleOperationHandler = (classType) => {
|
|
13
|
-
if (classType ===
|
|
14
|
-
return
|
|
26
|
+
if (classType === "delete") {
|
|
27
|
+
return "hover:bg-red-500/20 text-red-700";
|
|
15
28
|
}
|
|
16
29
|
else {
|
|
17
|
-
return
|
|
30
|
+
return "hover:bg-gray-500/10";
|
|
18
31
|
}
|
|
19
32
|
};
|
|
20
|
-
const ModernTable = ({ rows = [], onEdit,
|
|
33
|
+
const ModernTable = ({ rows = [], onEdit, loadingProps = {
|
|
21
34
|
isLoading: false,
|
|
22
|
-
loadingText:
|
|
23
|
-
loadingIcon: react_1.default.createElement(
|
|
24
|
-
}, onView, onAction, selectable, onSelectionChange, actions, modalActions, noItemFoundProps, selectedItems = [], iconsSRC,
|
|
35
|
+
loadingText: "درحال دریافت اطلاعات",
|
|
36
|
+
loadingIcon: react_1.default.createElement(Loader, null),
|
|
37
|
+
}, onView, onAction, selectable, onSelectionChange, actions, ShowActionModal = true, modalActions, noItemFoundProps, selectedItems = [], iconsSRC,
|
|
25
38
|
// Child row configuration with defaults
|
|
26
39
|
childRowConfig = {
|
|
27
40
|
expandByDefault: false,
|
|
28
|
-
indentSize:
|
|
29
|
-
childRowClass:
|
|
41
|
+
indentSize: "1.5rem",
|
|
42
|
+
childRowClass: "bg-blue-300 bg-opacity-10",
|
|
30
43
|
},
|
|
31
44
|
// Mobile card view configuration props
|
|
32
45
|
mobileCardConfig = {
|
|
33
46
|
enabled: true,
|
|
34
47
|
showFolderIcon: true,
|
|
35
|
-
folderIconPath:
|
|
48
|
+
folderIconPath: "",
|
|
36
49
|
showFavoriteIcon: true,
|
|
37
|
-
favoriteFilledIconPath:
|
|
38
|
-
favoriteOutlineIconPath:
|
|
50
|
+
favoriteFilledIconPath: "/icons/star-filled.svg",
|
|
51
|
+
favoriteOutlineIconPath: "/icons/star-outline.svg",
|
|
39
52
|
showMoreOptions: true,
|
|
40
|
-
moreOptionsIconPath:
|
|
53
|
+
moreOptionsIconPath: "/icons/table/more.svg",
|
|
41
54
|
showAvatars: true,
|
|
42
55
|
maxVisibleAvatars: 2,
|
|
43
56
|
cardStyle: {
|
|
44
|
-
backgroundColor:
|
|
45
|
-
borderRadius:
|
|
46
|
-
shadow:
|
|
47
|
-
border:
|
|
48
|
-
padding:
|
|
49
|
-
marginBottom:
|
|
57
|
+
backgroundColor: "bg-white",
|
|
58
|
+
borderRadius: "rounded-lg",
|
|
59
|
+
shadow: "shadow-sm",
|
|
60
|
+
border: "border border-gray-100",
|
|
61
|
+
padding: "p-4",
|
|
62
|
+
marginBottom: "mb-4",
|
|
50
63
|
},
|
|
51
|
-
gridLayoutClassName:
|
|
52
|
-
}, actionButtonsStyle, gridClassName,
|
|
64
|
+
gridLayoutClassName: "grid-cols-1 sm:grid-cols-2 gap-4",
|
|
65
|
+
}, showModalIcon = true, actionButtonsStyle, gridClassName, isMobileView = false, // Default to false
|
|
66
|
+
mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
|
|
67
|
+
pageIndex = 0, // Default to first page (0-indexed)
|
|
68
|
+
}) => {
|
|
53
69
|
// Track which rows are expanded to show their children
|
|
54
70
|
const [expandedRows, setExpandedRows] = (0, react_2.useState)([]);
|
|
55
71
|
const [activeModal, setActiveModal] = (0, react_2.useState)(null);
|
|
56
72
|
const modalRef = (0, react_2.useRef)(null);
|
|
57
73
|
// Store calculated column widths
|
|
58
|
-
const [columnWidths, setColumnWidths] = (0, react_2.useState)([]);
|
|
59
74
|
const [selectedRows, setSelectedRows] = (0, react_2.useState)(selectedItems || []);
|
|
60
75
|
// Calculate and store column widths based on all rows (parents and children)
|
|
61
76
|
(0, react_2.useEffect)(() => {
|
|
62
77
|
// if (!rows || rows.length === 0) return;
|
|
63
78
|
// Get all rows including children
|
|
64
79
|
const allRows = [];
|
|
65
|
-
// Helper function to recursively collect all rows
|
|
66
|
-
const collectRows = (rowsArray) => {
|
|
80
|
+
// Helper function to recursively collect all rows at any depth
|
|
81
|
+
const collectRows = (rowsArray, level = 0) => {
|
|
67
82
|
rowsArray?.forEach((row) => {
|
|
68
|
-
|
|
83
|
+
// Add level information to the row for proper indentation
|
|
84
|
+
const rowWithLevel = { ...row, level };
|
|
85
|
+
allRows.push(rowWithLevel);
|
|
86
|
+
// Recursively process children at any depth
|
|
69
87
|
if (row.hasChildren && row.childRows && row.childRows.length > 0) {
|
|
70
|
-
collectRows(row.childRows);
|
|
88
|
+
collectRows(row.childRows, level + 1);
|
|
71
89
|
}
|
|
72
90
|
});
|
|
73
91
|
};
|
|
@@ -84,16 +102,17 @@ mobileCardConfig = {
|
|
|
84
102
|
.filter((row) => row.data &&
|
|
85
103
|
row.data[colIndex] &&
|
|
86
104
|
row.data[colIndex].inlineCSS &&
|
|
87
|
-
|
|
105
|
+
"width" in (row.data[colIndex].inlineCSS || {}))
|
|
88
106
|
.map((row) => row.data[colIndex]);
|
|
89
107
|
if (columnsWithWidth.length > 0) {
|
|
90
108
|
// Use the first defined width (could be enhanced to use max/average)
|
|
91
109
|
const firstWidth = columnsWithWidth[0].inlineCSS?.width;
|
|
92
110
|
if (firstWidth) {
|
|
93
|
-
widths[colIndex] =
|
|
111
|
+
widths[colIndex] =
|
|
112
|
+
typeof firstWidth === "string" ? firstWidth : `${firstWidth}px`;
|
|
94
113
|
}
|
|
95
114
|
else {
|
|
96
|
-
widths[colIndex] =
|
|
115
|
+
widths[colIndex] = "auto";
|
|
97
116
|
}
|
|
98
117
|
}
|
|
99
118
|
else {
|
|
@@ -101,7 +120,6 @@ mobileCardConfig = {
|
|
|
101
120
|
widths[colIndex] = `${100 / maxColumns}%`;
|
|
102
121
|
}
|
|
103
122
|
}
|
|
104
|
-
setColumnWidths(widths);
|
|
105
123
|
}, [rows]);
|
|
106
124
|
// Initialize expanded rows if specified in config
|
|
107
125
|
(0, react_2.useEffect)(() => {
|
|
@@ -115,16 +133,17 @@ mobileCardConfig = {
|
|
|
115
133
|
(0, react_2.useEffect)(() => {
|
|
116
134
|
const handleClickOutside = (event) => {
|
|
117
135
|
const target = event.target;
|
|
118
|
-
if (target.closest(
|
|
136
|
+
if (target.closest(".modal-content")) {
|
|
119
137
|
return;
|
|
120
138
|
}
|
|
121
|
-
if (modalRef.current &&
|
|
139
|
+
if (modalRef.current &&
|
|
140
|
+
!modalRef.current.contains(event.target)) {
|
|
122
141
|
setActiveModal(null);
|
|
123
142
|
}
|
|
124
143
|
};
|
|
125
|
-
document.addEventListener(
|
|
144
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
126
145
|
return () => {
|
|
127
|
-
document.removeEventListener(
|
|
146
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
128
147
|
};
|
|
129
148
|
}, []);
|
|
130
149
|
(0, react_2.useEffect)(() => {
|
|
@@ -133,15 +152,11 @@ mobileCardConfig = {
|
|
|
133
152
|
setActiveModal(null);
|
|
134
153
|
}
|
|
135
154
|
};
|
|
136
|
-
window.addEventListener(
|
|
155
|
+
window.addEventListener("scroll", handleScroll, { passive: true });
|
|
137
156
|
return () => {
|
|
138
|
-
window.removeEventListener(
|
|
157
|
+
window.removeEventListener("scroll", handleScroll);
|
|
139
158
|
};
|
|
140
159
|
}, [activeModal]);
|
|
141
|
-
// Remove this problematic useEffect that's causing the infinite loop
|
|
142
|
-
// useEffect(() => {
|
|
143
|
-
// console.log(rows, 'ROws');
|
|
144
|
-
// }, [rows]);
|
|
145
160
|
const [mousePosition, setMousePosition] = (0, react_2.useState)({ x: 0, y: 0 });
|
|
146
161
|
const handleModalToggle = (id, e) => {
|
|
147
162
|
e.stopPropagation();
|
|
@@ -158,115 +173,283 @@ mobileCardConfig = {
|
|
|
158
173
|
};
|
|
159
174
|
const handleRowExpandToggle = (rowId, e) => {
|
|
160
175
|
e.stopPropagation();
|
|
161
|
-
setExpandedRows((prev) => prev.includes(rowId)
|
|
176
|
+
setExpandedRows((prev) => prev.includes(rowId)
|
|
177
|
+
? prev.filter((id) => id !== rowId)
|
|
178
|
+
: [...prev, rowId]);
|
|
162
179
|
};
|
|
163
180
|
const getStatusClass = (statusClass) => {
|
|
164
181
|
switch (statusClass) {
|
|
165
|
-
case
|
|
166
|
-
return
|
|
167
|
-
case
|
|
168
|
-
return
|
|
169
|
-
case
|
|
170
|
-
return
|
|
171
|
-
case
|
|
172
|
-
return
|
|
173
|
-
case
|
|
174
|
-
return
|
|
175
|
-
case
|
|
176
|
-
return
|
|
182
|
+
case "success":
|
|
183
|
+
return "text-[#37935f] px-4 py-2 rounded-lg bg-[#d1f4e0]";
|
|
184
|
+
case "danger":
|
|
185
|
+
return "text-[#d75482] rounded-lg bg-[#fdd0df] px-2 py-2";
|
|
186
|
+
case "warning":
|
|
187
|
+
return "text-yellow-700";
|
|
188
|
+
case "info":
|
|
189
|
+
return "text-blue-700";
|
|
190
|
+
case "primary":
|
|
191
|
+
return "text-[#6b46c1] rounded-lg bg-[#ede9f8] px-4 py-2";
|
|
192
|
+
case "secondary":
|
|
193
|
+
return "text-gray-700";
|
|
177
194
|
default:
|
|
178
|
-
return
|
|
195
|
+
return "";
|
|
179
196
|
}
|
|
180
197
|
};
|
|
181
198
|
const renderCellContent = (item) => {
|
|
182
199
|
switch (item.type) {
|
|
183
|
-
case
|
|
184
|
-
return (react_1.default.createElement("p", { className: `text-xs font-medium w-
|
|
200
|
+
case "status":
|
|
201
|
+
return (react_1.default.createElement("p", { className: `text-xs font-medium w-fit ${item.contentClass} ${getStatusClass(item.statusClass)} ` }, item.value));
|
|
202
|
+
case "price":
|
|
203
|
+
return (react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm w-full truncate ` }, formatWithCommas(item.value)));
|
|
185
204
|
default:
|
|
186
|
-
return (react_1.default.createElement("div", {
|
|
187
|
-
|
|
188
|
-
|
|
205
|
+
return (react_1.default.createElement("div", { onClick: () => {
|
|
206
|
+
if (item.onClick) {
|
|
207
|
+
item.onClick(item.id);
|
|
208
|
+
}
|
|
209
|
+
}, className: "flex items-center gap-2 w-full" }, item.hasImage ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" },
|
|
210
|
+
react_1.default.createElement(image_1.default, { src: item.imageUrl || "/placeholder.svg", alt: item.value?.toString() || "Table item", width: item.imageWidth || 24, height: item.imageHeight || 24, className: `${item.imageClass || "h-6 w-6 object-cover"}` }),
|
|
211
|
+
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))));
|
|
189
212
|
}
|
|
190
213
|
};
|
|
191
214
|
// Update selectedRows when selectedItems prop changes
|
|
192
215
|
(0, react_2.useEffect)(() => {
|
|
193
216
|
setSelectedRows(selectedItems || []);
|
|
194
|
-
}, []);
|
|
217
|
+
}, [selectedItems]);
|
|
195
218
|
// Handle checkbox change for row selection
|
|
219
|
+
// const handleCheckboxChange = (id: number) => {
|
|
220
|
+
// console.log(`Processing ID: ${id}`);
|
|
221
|
+
// // Create a new copy of the current selection
|
|
222
|
+
// let updatedSelection = [...selectedRows];
|
|
223
|
+
// // Check if the row is currently selected
|
|
224
|
+
// const isSelected = updatedSelection.includes(id);
|
|
225
|
+
// console.log(`ID ${id} is currently selected: ${isSelected}`);
|
|
226
|
+
// // Find the item in the rows data
|
|
227
|
+
// const findItemById = (items: TableRowData[] | undefined, itemId: number): TableRowData | null => {
|
|
228
|
+
// if (!items) return null;
|
|
229
|
+
// for (const item of items) {
|
|
230
|
+
// if (item.id === itemId) {
|
|
231
|
+
// return item;
|
|
232
|
+
// }
|
|
233
|
+
// if (item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
234
|
+
// const foundInChildren = findItemById(item.childRows, itemId);
|
|
235
|
+
// if (foundInChildren) return foundInChildren;
|
|
236
|
+
// }
|
|
237
|
+
// }
|
|
238
|
+
// return null;
|
|
239
|
+
// };
|
|
240
|
+
// const item = findItemById(rows!, id);
|
|
241
|
+
// console.log(`Found item for ID ${id}:`, item);
|
|
242
|
+
// if (isSelected) {
|
|
243
|
+
// // DESELECTION LOGIC
|
|
244
|
+
// console.log(`Deselecting ID ${id}`);
|
|
245
|
+
// // Remove the item itself
|
|
246
|
+
// updatedSelection = updatedSelection.filter(itemId => itemId !== id);
|
|
247
|
+
// // If item exists and has children, remove all children too
|
|
248
|
+
// if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
249
|
+
// // Function to collect all descendant IDs
|
|
250
|
+
// const getAllDescendantIds = (items: TableRowData[]): number[] => {
|
|
251
|
+
// let allIds: number[] = [];
|
|
252
|
+
// for (const childItem of items) {
|
|
253
|
+
// allIds.push(childItem.id);
|
|
254
|
+
// if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
|
|
255
|
+
// allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
|
|
256
|
+
// }
|
|
257
|
+
// }
|
|
258
|
+
// return allIds;
|
|
259
|
+
// };
|
|
260
|
+
// const descendantIds = getAllDescendantIds(item.childRows);
|
|
261
|
+
// console.log(`Descendant IDs to remove:`, descendantIds);
|
|
262
|
+
// // Remove all descendant IDs from the selection
|
|
263
|
+
// updatedSelection = updatedSelection.filter(itemId => !descendantIds.includes(itemId));
|
|
264
|
+
// }
|
|
265
|
+
// } else {
|
|
266
|
+
// // SELECTION LOGIC
|
|
267
|
+
// console.log(`Selecting ID ${id}`);
|
|
268
|
+
// // Add the item itself
|
|
269
|
+
// updatedSelection.push(id);
|
|
270
|
+
// // If item exists and has children, add all children too
|
|
271
|
+
// if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
|
|
272
|
+
// // Function to collect all descendant IDs
|
|
273
|
+
// const getAllDescendantIds = (items: TableRowData[]): number[] => {
|
|
274
|
+
// let allIds: number[] = [];
|
|
275
|
+
// for (const childItem of items) {
|
|
276
|
+
// allIds.push(childItem.id);
|
|
277
|
+
// if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
|
|
278
|
+
// allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
|
|
279
|
+
// }
|
|
280
|
+
// }
|
|
281
|
+
// return allIds;
|
|
282
|
+
// };
|
|
283
|
+
// const descendantIds = getAllDescendantIds(item.childRows);
|
|
284
|
+
// console.log(`Descendant IDs to add:`, descendantIds);
|
|
285
|
+
// // Add all descendant IDs to the selection if not already included
|
|
286
|
+
// for (const descendantId of descendantIds) {
|
|
287
|
+
// if (!updatedSelection.includes(descendantId)) {
|
|
288
|
+
// updatedSelection.push(descendantId);
|
|
289
|
+
// }
|
|
290
|
+
// }
|
|
291
|
+
// }
|
|
292
|
+
// }
|
|
293
|
+
// console.log("New selection:", updatedSelection);
|
|
294
|
+
// setSelectedRows(updatedSelection);
|
|
295
|
+
// if (onSelectionChange) {
|
|
296
|
+
// onSelectionChange([...updatedSelection]);
|
|
297
|
+
// }
|
|
298
|
+
// };
|
|
299
|
+
// Function to determine if a row has any descendants selected (not just direct children)
|
|
300
|
+
const isIndeterminate = (rowId) => {
|
|
301
|
+
// Find the row in the data
|
|
302
|
+
const findRow = (rows, id) => {
|
|
303
|
+
if (!rows)
|
|
304
|
+
return null;
|
|
305
|
+
for (const row of rows) {
|
|
306
|
+
if (row.id === id)
|
|
307
|
+
return row;
|
|
308
|
+
if (row.hasChildren && row.childRows) {
|
|
309
|
+
const found = findRow(row.childRows, id);
|
|
310
|
+
if (found)
|
|
311
|
+
return found;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return null;
|
|
315
|
+
};
|
|
316
|
+
const row = findRow(rows, rowId);
|
|
317
|
+
// If row has no children, it can't be indeterminate
|
|
318
|
+
if (!row ||
|
|
319
|
+
!row.hasChildren ||
|
|
320
|
+
!row.childRows ||
|
|
321
|
+
row.childRows.length === 0) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
// Check if the row itself is selected
|
|
325
|
+
const isRowSelected = selectedRows.includes(rowId);
|
|
326
|
+
// Recursively check if any descendant is selected
|
|
327
|
+
const hasSelectedDescendant = (children) => {
|
|
328
|
+
for (const child of children) {
|
|
329
|
+
// If any child is selected
|
|
330
|
+
if (selectedRows.includes(child.id)) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
// Check grandchildren if they exist
|
|
334
|
+
if (child.hasChildren &&
|
|
335
|
+
child.childRows &&
|
|
336
|
+
child.childRows.length > 0) {
|
|
337
|
+
if (hasSelectedDescendant(child.childRows)) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return false;
|
|
343
|
+
};
|
|
344
|
+
// Check if all descendants are selected
|
|
345
|
+
const areAllDescendantsSelected = (children) => {
|
|
346
|
+
for (const child of children) {
|
|
347
|
+
// If any child is not selected
|
|
348
|
+
if (!selectedRows.includes(child.id)) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
// Check grandchildren if they exist
|
|
352
|
+
if (child.hasChildren &&
|
|
353
|
+
child.childRows &&
|
|
354
|
+
child.childRows.length > 0) {
|
|
355
|
+
if (!areAllDescendantsSelected(child.childRows)) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return true;
|
|
361
|
+
};
|
|
362
|
+
const hasAnySelected = hasSelectedDescendant(row.childRows);
|
|
363
|
+
const hasAllSelected = areAllDescendantsSelected(row.childRows);
|
|
364
|
+
// Indeterminate if some but not all descendants are selected
|
|
365
|
+
// Or if the parent is not selected but some children are
|
|
366
|
+
return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
|
|
367
|
+
};
|
|
368
|
+
// Function to check if a row is selected
|
|
369
|
+
const isSelected = (rowId) => {
|
|
370
|
+
return selectedRows.includes(rowId);
|
|
371
|
+
};
|
|
196
372
|
const handleCheckboxChange = (id) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
: [...selectedRows, id];
|
|
200
|
-
setSelectedRows(updatedSelection);
|
|
373
|
+
// Call your existing handleSelectionChange function
|
|
374
|
+
// This will handle the hierarchical selection logic
|
|
201
375
|
if (onSelectionChange) {
|
|
202
|
-
onSelectionChange(
|
|
376
|
+
onSelectionChange(id);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
// Fallback to simple selection if no onSelectionChange is provided
|
|
380
|
+
const updatedSelection = selectedRows.includes(id)
|
|
381
|
+
? selectedRows.filter((rowId) => rowId !== id)
|
|
382
|
+
: [...selectedRows, id];
|
|
383
|
+
setSelectedRows(updatedSelection);
|
|
203
384
|
}
|
|
204
|
-
};
|
|
205
|
-
// Method to check if all items are selected
|
|
206
|
-
const areAllItemsSelected = () => {
|
|
207
|
-
return Boolean(rows && rows.length > 0 && selectedRows.length === rows.length);
|
|
208
385
|
};
|
|
209
386
|
// Extract title and subtitle from row data
|
|
210
387
|
const extractCardData = (row) => {
|
|
211
|
-
let title =
|
|
212
|
-
let subtitle =
|
|
213
|
-
let icon =
|
|
214
|
-
let status =
|
|
215
|
-
let statusClass =
|
|
388
|
+
let title = "";
|
|
389
|
+
let subtitle = "";
|
|
390
|
+
let icon = "";
|
|
391
|
+
let status = "";
|
|
392
|
+
let statusClass = "";
|
|
393
|
+
let price = "";
|
|
216
394
|
if (!row.data)
|
|
217
|
-
return { title, subtitle, icon, status, statusClass };
|
|
395
|
+
return { title, subtitle, icon, status, statusClass, price };
|
|
218
396
|
// Find title (usually first text item)
|
|
219
|
-
const titleItem = row.data.find((item) => item.type ===
|
|
397
|
+
const titleItem = row.data.find((item) => item.type === "text" && item.value);
|
|
220
398
|
if (titleItem) {
|
|
221
399
|
title = titleItem.value;
|
|
222
400
|
}
|
|
223
401
|
else if (row.data.length > 0) {
|
|
224
402
|
// Fallback to first item
|
|
225
|
-
title = String(row.data[0].value ||
|
|
403
|
+
title = String(row.data[0].value || "");
|
|
226
404
|
}
|
|
227
405
|
// Find subtitle (usually size or description)
|
|
228
|
-
const subtitleItem = row.data.find((item) => item.type ===
|
|
406
|
+
const subtitleItem = row.data.find((item) => item.type === "text" && item.isSubtitle);
|
|
229
407
|
if (subtitleItem) {
|
|
230
408
|
subtitle = subtitleItem.value;
|
|
231
409
|
}
|
|
232
410
|
else if (row.data.length > 1) {
|
|
233
411
|
// Fallback to second item
|
|
234
|
-
subtitle = String(row.data[1].value ||
|
|
412
|
+
subtitle = String(row.data[1].value || "");
|
|
235
413
|
}
|
|
236
414
|
// Find status
|
|
237
|
-
const statusItem = row.data.find((item) => item.type ===
|
|
415
|
+
const statusItem = row.data.find((item) => item.type === "status");
|
|
238
416
|
if (statusItem) {
|
|
239
|
-
status = String(statusItem.value ||
|
|
240
|
-
statusClass = statusItem.statusClass ||
|
|
417
|
+
status = String(statusItem.value || "");
|
|
418
|
+
statusClass = statusItem.statusClass || "";
|
|
419
|
+
}
|
|
420
|
+
// Find price (look for item with isPrice flag)
|
|
421
|
+
const priceItem = row.data.find((item) => item.isPrice);
|
|
422
|
+
if (priceItem) {
|
|
423
|
+
price = String(priceItem.value || "");
|
|
241
424
|
}
|
|
242
425
|
// Find icon (usually avatar or image)
|
|
243
426
|
const iconItem = row.data.find((item) => item.hasImage);
|
|
244
427
|
if (iconItem && iconItem.value) {
|
|
245
|
-
icon = String(iconItem.imageUrl ||
|
|
428
|
+
icon = String(iconItem.imageUrl || "");
|
|
246
429
|
}
|
|
247
|
-
return { title, subtitle, icon, status, statusClass };
|
|
430
|
+
return { title, subtitle, icon, status, statusClass, price };
|
|
248
431
|
};
|
|
249
432
|
// Find avatar items in row data
|
|
250
433
|
const findAvatarItems = (row) => {
|
|
251
434
|
if (!row.data)
|
|
252
435
|
return [];
|
|
253
|
-
return row.data.filter((item) => item.type ===
|
|
436
|
+
return row.data.filter((item) => item.type === "avatar" && item.isUserAvatar);
|
|
254
437
|
};
|
|
255
|
-
// Get all rows and their children for mobile view
|
|
438
|
+
// Get all rows and their children for mobile view - updated for multi-level nesting
|
|
256
439
|
const getAllMobileRows = () => {
|
|
257
440
|
const result = [];
|
|
258
|
-
// Helper function to add parent rows and child rows that should be visible
|
|
259
|
-
const processRows = (rows) => {
|
|
441
|
+
// Helper function to add parent rows and child rows that should be visible at any depth
|
|
442
|
+
const processRows = (rows, level = 0) => {
|
|
260
443
|
rows?.forEach((row) => {
|
|
261
|
-
|
|
262
|
-
|
|
444
|
+
// Add level information to the row for proper indentation
|
|
445
|
+
const rowWithLevel = { ...row, level, isChild: level > 0 };
|
|
446
|
+
result.push(rowWithLevel);
|
|
447
|
+
// Add child rows if this row is expanded - recursively check all levels
|
|
263
448
|
if (row.hasChildren &&
|
|
264
449
|
expandedRows.includes(row.id) &&
|
|
265
450
|
row.childRows &&
|
|
266
451
|
row.childRows.length > 0) {
|
|
267
|
-
row.childRows
|
|
268
|
-
result.push(childRow);
|
|
269
|
-
});
|
|
452
|
+
processRows(row.childRows, level + 1);
|
|
270
453
|
}
|
|
271
454
|
});
|
|
272
455
|
};
|
|
@@ -279,34 +462,41 @@ mobileCardConfig = {
|
|
|
279
462
|
const renderMobileCard = (row) => {
|
|
280
463
|
if (!row || !row.data)
|
|
281
464
|
return null;
|
|
282
|
-
const { title, subtitle,
|
|
465
|
+
const { title, subtitle, status, statusClass, price } = extractCardData(row);
|
|
283
466
|
const avatarItems = findAvatarItems(row);
|
|
284
467
|
const isFavorited = row.data.some((item) => item.isFavorite);
|
|
285
468
|
const hasChildren = row.hasChildren && row.childRows && row?.childRows?.length > 0;
|
|
286
|
-
const
|
|
469
|
+
const level = row.level || 0;
|
|
470
|
+
const { cardStyle, showFolderIcon, folderIconPath, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
|
|
471
|
+
// showMoreOptions,
|
|
472
|
+
moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
|
|
287
473
|
// Calculate card classes - add special styling for child cards
|
|
288
474
|
const cardClasses = `
|
|
289
|
-
${cardStyle?.backgroundColor ||
|
|
290
|
-
${cardStyle?.borderRadius ||
|
|
291
|
-
${cardStyle?.shadow ||
|
|
292
|
-
${row.isChild
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
${
|
|
475
|
+
${cardStyle?.backgroundColor || "bg-white"}
|
|
476
|
+
${cardStyle?.borderRadius || "rounded-lg"}
|
|
477
|
+
${cardStyle?.shadow || "shadow-sm"}
|
|
478
|
+
${row.isChild
|
|
479
|
+
? "border-l-4 border-l-blue-300"
|
|
480
|
+
: cardStyle?.border || "border border-gray-100"}
|
|
481
|
+
${cardStyle?.padding || "p-4"}
|
|
482
|
+
${cardStyle?.marginBottom || "mb-4"}
|
|
483
|
+
${row.isChild ? "bg-opacity-90" : ""}
|
|
296
484
|
w-full h-full
|
|
297
485
|
`;
|
|
298
486
|
return (react_1.default.createElement("div", { className: cardClasses },
|
|
299
487
|
react_1.default.createElement("div", { className: "flex items-start gap-2" },
|
|
300
488
|
showFolderIcon && (react_1.default.createElement("div", { className: "mr-3 flex-shrink-0" },
|
|
301
|
-
react_1.default.createElement("div", { className: "w-10 h-10 flex items-center justify-center" },
|
|
302
|
-
react_1.default.createElement(image_1.default, { src:
|
|
489
|
+
react_1.default.createElement("div", { className: "w-10 h-10 flex items-center justify-center" }, row.data &&
|
|
490
|
+
row.data.find((item) => item.hasImage)?.imageUrl ? (react_1.default.createElement(image_1.default, { src: row.data.find((item) => item.hasImage)?.imageUrl ||
|
|
491
|
+
"/placeholder.svg", alt: "folder", width: 40, height: 40, className: "h-full w-full object-cover" })) : (react_1.default.createElement(image_1.default, { src: folderIconPath || "/placeholder.svg", alt: "folder", width: 40, height: 40, className: "text-yellow-400" }))))),
|
|
303
492
|
react_1.default.createElement("div", { className: "flex-1 min-w-0" },
|
|
304
493
|
react_1.default.createElement("div", { className: "flex items-start justify-between" },
|
|
305
494
|
react_1.default.createElement("div", { className: "overflow-hidden" },
|
|
306
495
|
react_1.default.createElement("div", { className: "flex items-center" },
|
|
307
|
-
|
|
496
|
+
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` })),
|
|
308
497
|
react_1.default.createElement("h3", { className: "text-sm font-medium truncate" }, title)),
|
|
309
498
|
react_1.default.createElement("p", { className: "text-xs text-gray-500 mt-1 truncate" }, subtitle),
|
|
499
|
+
price && (react_1.default.createElement("p", { className: "text-sm font-semibold mt-1" }, price)),
|
|
310
500
|
status && (react_1.default.createElement("div", { className: "mt-2" },
|
|
311
501
|
react_1.default.createElement("span", { className: `text-xs font-medium px-2 py-1 rounded-full ${getStatusClass(statusClass)} bg-opacity-10` }, status)))),
|
|
312
502
|
react_1.default.createElement("div", { className: "flex items-center flex-shrink-0 ml-2" },
|
|
@@ -314,25 +504,38 @@ mobileCardConfig = {
|
|
|
314
504
|
e.stopPropagation();
|
|
315
505
|
handleRowExpandToggle(row.id, e);
|
|
316
506
|
}, className: "p-2 hover:bg-gray-100 rounded" },
|
|
317
|
-
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) ?
|
|
507
|
+
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" : ""}` },
|
|
318
508
|
react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))),
|
|
319
509
|
showFavoriteIcon && (react_1.default.createElement("button", { className: "p-2 hover:bg-gray-100 rounded" },
|
|
320
510
|
react_1.default.createElement(image_1.default, { src: isFavorited
|
|
321
|
-
? favoriteFilledIconPath ??
|
|
322
|
-
: favoriteOutlineIconPath ??
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
511
|
+
? favoriteFilledIconPath ?? "/defaultFilledIcon.svg"
|
|
512
|
+
: favoriteOutlineIconPath ?? "/defaultOutlineIcon.svg", alt: "favorite", width: 20, height: 20, className: isFavorited ? "text-yellow-400" : "text-gray-400" }))),
|
|
513
|
+
(typeof mobileCardConfig.showMoreOptions === "function"
|
|
514
|
+
? mobileCardConfig.showMoreOptions(row)
|
|
515
|
+
: mobileCardConfig.showMoreOptions) &&
|
|
516
|
+
modalActions &&
|
|
517
|
+
modalActions.length > 0 &&
|
|
518
|
+
(typeof showModalIcon === "function"
|
|
519
|
+
? showModalIcon(row)
|
|
520
|
+
: showModalIcon) && (react_1.default.createElement("div", { className: "relative" },
|
|
521
|
+
react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: `p-2 hover:bg-gray-100 rounded ${ShowActionModal
|
|
522
|
+
? ""
|
|
523
|
+
: "opacity-50 cursor-not-allowed "} ` },
|
|
524
|
+
react_1.default.createElement(image_1.default, { src: moreOptionsIconPath || "/placeholder.svg", alt: "menu", width: 20, height: 20, className: `${ShowActionModal
|
|
525
|
+
? ""
|
|
526
|
+
: "opacity-50 cursor-not-allowed"}` })),
|
|
527
|
+
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: {
|
|
528
|
+
position: "fixed",
|
|
328
529
|
top: `${mousePosition.y}px`,
|
|
329
530
|
left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `, // Ensure modal stays within screen
|
|
330
531
|
}, onClick: (e) => e.stopPropagation() },
|
|
331
|
-
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" },
|
|
532
|
+
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
|
|
533
|
+
? modalActions(row)
|
|
534
|
+
: 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)))))))))),
|
|
332
535
|
showAvatars && avatarItems.length > 0 && (react_1.default.createElement("div", { className: "flex items-center mt-3" },
|
|
333
536
|
react_1.default.createElement("div", { className: "flex -space-x-2" },
|
|
334
537
|
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" },
|
|
335
|
-
react_1.default.createElement(image_1.default, { src: item.value ||
|
|
538
|
+
react_1.default.createElement(image_1.default, { src: item.value || "/placeholder.svg", alt: "Avatar", width: 24, height: 24, className: "h-full w-full object-cover" })))),
|
|
336
539
|
avatarItems.length > maxVisibleAvatars && (react_1.default.createElement("div", { className: "h-6 w-6 rounded-full bg-gray-200 border border-white flex items-center justify-center text-xs text-gray-600" },
|
|
337
540
|
"+",
|
|
338
541
|
avatarItems.length - maxVisibleAvatars)))))))));
|
|
@@ -342,53 +545,99 @@ mobileCardConfig = {
|
|
|
342
545
|
// Width for the expand/collapse control column
|
|
343
546
|
return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
|
|
344
547
|
react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
|
|
345
|
-
? childRowConfig.childRowClass ||
|
|
548
|
+
? childRowConfig.childRowClass || "bg-blue-300 bg-opacity-10"
|
|
346
549
|
: index % 2 === 0
|
|
347
|
-
?
|
|
348
|
-
:
|
|
550
|
+
? "bg-white"
|
|
551
|
+
: "bg-[#c8cfd8] bg-opacity-[0.08]"} border-b border-solid border-black/15 ${onView ? "cursor-pointer hover:bg-blue-100" : ""} ${row.data?.some((item) => item.type === "avatar")
|
|
552
|
+
? "h-[60px]"
|
|
553
|
+
: "h-14"}`, style: {
|
|
554
|
+
gridTemplateColumns: isMobileView && mobileViewGridClassName
|
|
555
|
+
? mobileViewGridClassName
|
|
556
|
+
: gridClassName || "repeat(auto-fit, minmax(100px, 1fr))",
|
|
557
|
+
}, onClick: () => {
|
|
349
558
|
if (onView) {
|
|
350
559
|
onView(row.id);
|
|
351
560
|
}
|
|
352
561
|
} },
|
|
353
|
-
react_1.default.createElement("div", { className: `flex items-center justify-center gap-2 ${!row.hasChildren &&
|
|
354
|
-
!row.hasChildren && !row.isChild && (react_1.default.createElement("span", { className: "text-xs text-gray-500 font-
|
|
562
|
+
react_1.default.createElement("div", { className: `flex items-center justify-center gap-2 ${!row.hasChildren && "mr-[4px]"}`, style: { width: "55px" } },
|
|
563
|
+
!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)),
|
|
355
564
|
react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
|
|
356
565
|
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" },
|
|
357
|
-
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) ?
|
|
566
|
+
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" : ""}` },
|
|
358
567
|
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 ? (
|
|
359
568
|
// Child row indicator
|
|
360
569
|
react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
|
|
361
|
-
selectable === true && (react_1.default.createElement("div", { className:
|
|
362
|
-
react_1.default.createElement("input", { type: "checkbox", checked:
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
570
|
+
selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
571
|
+
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) => {
|
|
572
|
+
if (el) {
|
|
573
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
574
|
+
}
|
|
575
|
+
} }),
|
|
576
|
+
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" },
|
|
577
|
+
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" }))))))),
|
|
578
|
+
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" ||
|
|
579
|
+
item.type === "operation" ||
|
|
580
|
+
item.type === "text"
|
|
581
|
+
? ""
|
|
582
|
+
: ""}`, style: {
|
|
368
583
|
...item.inlineCSS,
|
|
369
|
-
textAlign: item.textAlign ||
|
|
370
|
-
justifyContent: item.textAlign ===
|
|
371
|
-
?
|
|
372
|
-
: item.textAlign ===
|
|
373
|
-
?
|
|
374
|
-
:
|
|
375
|
-
} },
|
|
376
|
-
|
|
584
|
+
textAlign: item.textAlign || "left",
|
|
585
|
+
justifyContent: item.textAlign === "right"
|
|
586
|
+
? "flex-end"
|
|
587
|
+
: item.textAlign === "center"
|
|
588
|
+
? "center"
|
|
589
|
+
: "flex-start",
|
|
590
|
+
} },
|
|
591
|
+
colIndex === 0 && row.isChild && selectable && (react_1.default.createElement("div", { className: "flex items-center" },
|
|
592
|
+
react_1.default.createElement("div", { style: {
|
|
593
|
+
paddingLeft: `${(row.level || 1) * 7}px`,
|
|
594
|
+
}, className: "flex-shrink-0" }),
|
|
595
|
+
react_1.default.createElement("div", { className: "relative flex items-center justify-center " },
|
|
596
|
+
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) => {
|
|
597
|
+
if (el) {
|
|
598
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
599
|
+
}
|
|
600
|
+
} }),
|
|
601
|
+
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" },
|
|
602
|
+
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" })))))),
|
|
603
|
+
renderCellContent(item)))),
|
|
604
|
+
actions && (react_1.default.createElement("div", { className: `w-24 py-4 flex items-center justify-end text-sm font-medium ${actionButtonsStyle || ""}` },
|
|
377
605
|
react_1.default.createElement("div", { className: "flex items-center justify-center gap-2" },
|
|
378
606
|
onEdit && (react_1.default.createElement("button", { onClick: (e) => {
|
|
379
607
|
e.stopPropagation();
|
|
380
608
|
onEdit(row.id);
|
|
381
609
|
}, className: "p-1 mb-[5px]" },
|
|
382
|
-
react_1.default.createElement(image_1.default, { src: iconsSRC
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
610
|
+
react_1.default.createElement(image_1.default, { src: iconsSRC?.editIcon || "/placeholder.svg", alt: "edit", width: 18, height: 18, className: iconsSRC?.editIconTailwindStyle || "" }))),
|
|
611
|
+
react_1.default.createElement("div", { className: "relative" },
|
|
612
|
+
modalActions &&
|
|
613
|
+
modalActions.length > 0 &&
|
|
614
|
+
(typeof showModalIcon === "function"
|
|
615
|
+
? showModalIcon(row)
|
|
616
|
+
: showModalIcon) ? (react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: "", "data-row-id": row.id },
|
|
617
|
+
react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
|
|
618
|
+
// Render an invisible placeholder to maintain spacing when icon is hidden
|
|
619
|
+
react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
|
|
620
|
+
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: {
|
|
621
|
+
position: "fixed",
|
|
622
|
+
top: (() => {
|
|
623
|
+
// Get all visible rows for the current view
|
|
624
|
+
const allRows = isMobileView
|
|
625
|
+
? getAllMobileRows()
|
|
626
|
+
: rows;
|
|
627
|
+
// Find the index of the current row
|
|
628
|
+
const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
|
|
629
|
+
// Check if this is one of the last 3 rows
|
|
630
|
+
const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
|
|
631
|
+
// If it's one of the last 3 rows, reduce the top position by 100px
|
|
632
|
+
return isLastThreeRows
|
|
633
|
+
? `${mousePosition.y - 110}px`
|
|
634
|
+
: `${mousePosition.y}px`;
|
|
635
|
+
})(),
|
|
389
636
|
left: `${mousePosition.x + 20}px`,
|
|
390
637
|
}, onClick: (e) => e.stopPropagation() },
|
|
391
|
-
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" },
|
|
638
|
+
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
|
|
639
|
+
? modalActions(row)
|
|
640
|
+
: 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))))))))))),
|
|
392
641
|
row.hasChildren &&
|
|
393
642
|
expandedRows.includes(row.id) &&
|
|
394
643
|
row.childRows &&
|
|
@@ -404,8 +653,8 @@ mobileCardConfig = {
|
|
|
404
653
|
}
|
|
405
654
|
// Show no items found if rows are empty or null and not loading
|
|
406
655
|
if (!loadingProps.isLoading && rows?.length === 0) {
|
|
407
|
-
return (react_1.default.createElement("div", { className: "flex flex-col items-center justify-center p-8" }, typeof noItemFoundProps?.imagePath ===
|
|
408
|
-
react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath ||
|
|
656
|
+
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,
|
|
657
|
+
react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath || "/icons/no-data.svg", alt: "No items found", width: 120, height: 120 }),
|
|
409
658
|
react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
|
|
410
659
|
noItemFoundProps?.title,
|
|
411
660
|
" "))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
@@ -415,7 +664,7 @@ mobileCardConfig = {
|
|
|
415
664
|
" ")))));
|
|
416
665
|
}
|
|
417
666
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
418
|
-
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 ?
|
|
419
|
-
react_1.default.createElement("div", { className: `${mobileCardConfig.enabled ?
|
|
667
|
+
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)))))),
|
|
668
|
+
react_1.default.createElement("div", { className: `${mobileCardConfig.enabled ? "hidden lg:block" : ""} w-full` }, rows?.map((row, index) => renderTableRow(row, index, index === rows.length - 1)))));
|
|
420
669
|
};
|
|
421
670
|
exports.default = ModernTable;
|