hi-tm 0.12.4 → 0.12.5
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,43 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
5
|
};
|
|
39
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
const react_1 =
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_2 = require("react");
|
|
41
9
|
const image_1 = __importDefault(require("next/image"));
|
|
42
10
|
const SafeImage_1 = __importDefault(require("../../../elements/SafeImage"));
|
|
43
11
|
// Simple Loader component defined inline to avoid import issues
|
|
@@ -100,89 +68,62 @@ mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
|
|
|
100
68
|
pageIndex = 0, // Default to first page (0-indexed)
|
|
101
69
|
}) => {
|
|
102
70
|
// Track which rows are expanded to show their children
|
|
103
|
-
const [expandedRows, setExpandedRows] = (0,
|
|
104
|
-
const [activeModal, setActiveModal] = (0,
|
|
105
|
-
const modalRef = (0,
|
|
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);
|
|
106
74
|
// Store calculated column widths
|
|
107
|
-
const [selectedRows, setSelectedRows] = (0,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
if (row.hasChildren && row.childRows) {
|
|
126
|
-
collectDescendants(row.childRows);
|
|
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);
|
|
127
90
|
}
|
|
128
|
-
descendantsMap.set(row.id, descendantIds);
|
|
129
91
|
});
|
|
130
92
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}, [rows]);
|
|
134
|
-
// --- Optimized Functions ---
|
|
135
|
-
const findRowById = (id) => {
|
|
136
|
-
return rowsMap.get(id) || null;
|
|
137
|
-
};
|
|
138
|
-
const getAllDescendantIds = (id) => {
|
|
139
|
-
return descendantsMap.get(id) || [];
|
|
140
|
-
};
|
|
141
|
-
const isSelected = (rowId) => {
|
|
142
|
-
return selectedRows.includes(rowId);
|
|
143
|
-
};
|
|
144
|
-
const isIndeterminate = (rowId) => {
|
|
145
|
-
const row = rowsMap.get(rowId);
|
|
146
|
-
if (!row || !row.hasChildren || !descendantsMap.has(rowId)) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
const descendantIds = descendantsMap.get(rowId) || [];
|
|
150
|
-
const isRowSelected = selectedRows.includes(rowId);
|
|
151
|
-
const hasAnySelected = descendantIds.some((id) => selectedRows.includes(id));
|
|
152
|
-
const hasAllSelected = descendantIds.every((id) => selectedRows.includes(id));
|
|
153
|
-
return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
|
|
154
|
-
};
|
|
155
|
-
(0, react_1.useEffect)(() => {
|
|
156
|
-
console.time("isIndeterminate-all-rows"); // شروع اندازهگیری زمان کل
|
|
157
|
-
// اجرای تابع برای همه رکوردها
|
|
158
|
-
rows?.forEach((row) => {
|
|
159
|
-
isIndeterminate(row.id);
|
|
160
|
-
});
|
|
161
|
-
console.timeEnd("isIndeterminate-all-rows"); // پایان اندازهگیری زمان کل
|
|
162
|
-
}, [rows, selectedRows]); // وابستگیها: تغییر در دادهها یا انتخابها
|
|
163
|
-
const handleCheckboxChange = (id) => {
|
|
164
|
-
const row = findRowById(id);
|
|
165
|
-
if (!row)
|
|
166
|
-
return;
|
|
167
|
-
const descendantIds = getAllDescendantIds(id);
|
|
168
|
-
const updatedSelection = [...selectedRows];
|
|
169
|
-
if (selectedRows.includes(id)) {
|
|
170
|
-
const idsToRemove = [id, ...descendantIds];
|
|
171
|
-
setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
const idsToAdd = [id, ...descendantIds];
|
|
175
|
-
setSelectedRows([
|
|
176
|
-
...updatedSelection,
|
|
177
|
-
...idsToAdd.filter((i) => !updatedSelection.includes(i)),
|
|
178
|
-
]);
|
|
93
|
+
if (rows) {
|
|
94
|
+
collectRows(rows);
|
|
179
95
|
}
|
|
180
|
-
|
|
181
|
-
|
|
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}%`;
|
|
122
|
+
}
|
|
182
123
|
}
|
|
183
|
-
};
|
|
184
|
-
//
|
|
185
|
-
(0,
|
|
124
|
+
}, [rows]);
|
|
125
|
+
// Initialize expanded rows if specified in config
|
|
126
|
+
(0, react_2.useEffect)(() => {
|
|
186
127
|
if (childRowConfig.expandByDefault && rows) {
|
|
187
128
|
const parentIds = rows
|
|
188
129
|
.filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
|
|
@@ -190,7 +131,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
190
131
|
setExpandedRows(parentIds);
|
|
191
132
|
}
|
|
192
133
|
}, [rows, childRowConfig.expandByDefault]);
|
|
193
|
-
(0,
|
|
134
|
+
(0, react_2.useEffect)(() => {
|
|
194
135
|
const handleClickOutside = (event) => {
|
|
195
136
|
const target = event.target;
|
|
196
137
|
if (target.closest(".modal-content")) {
|
|
@@ -206,7 +147,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
206
147
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
207
148
|
};
|
|
208
149
|
}, []);
|
|
209
|
-
(0,
|
|
150
|
+
(0, react_2.useEffect)(() => {
|
|
210
151
|
const handleScroll = () => {
|
|
211
152
|
if (activeModal !== null) {
|
|
212
153
|
setActiveModal(null);
|
|
@@ -217,10 +158,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
217
158
|
window.removeEventListener("scroll", handleScroll);
|
|
218
159
|
};
|
|
219
160
|
}, [activeModal]);
|
|
220
|
-
(0,
|
|
221
|
-
setSelectedRows(selectedItems || []);
|
|
222
|
-
}, [selectedItems]);
|
|
223
|
-
// --- Handlers ---
|
|
161
|
+
const [mousePosition, setMousePosition] = (0, react_2.useState)({ x: 0, y: 0 });
|
|
224
162
|
const handleModalToggle = (id, e) => {
|
|
225
163
|
e.stopPropagation();
|
|
226
164
|
e.preventDefault();
|
|
@@ -276,6 +214,223 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
276
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))));
|
|
277
215
|
}
|
|
278
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) => {
|
|
304
|
+
// Find the row in the data
|
|
305
|
+
const findRow = (rows, id) => {
|
|
306
|
+
if (!rows)
|
|
307
|
+
return null;
|
|
308
|
+
for (const row of rows) {
|
|
309
|
+
if (row.id === id)
|
|
310
|
+
return row;
|
|
311
|
+
if (row.hasChildren && row.childRows) {
|
|
312
|
+
const found = findRow(row.childRows, id);
|
|
313
|
+
if (found)
|
|
314
|
+
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 (!row ||
|
|
322
|
+
!row.hasChildren ||
|
|
323
|
+
!row.childRows ||
|
|
324
|
+
row.childRows.length === 0) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
// Check if the row itself is selected
|
|
328
|
+
const isRowSelected = selectedRows.includes(rowId);
|
|
329
|
+
// Recursively check if any descendant is selected
|
|
330
|
+
const hasSelectedDescendant = (children) => {
|
|
331
|
+
for (const child of children) {
|
|
332
|
+
// If any child is selected
|
|
333
|
+
if (selectedRows.includes(child.id)) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
// Check grandchildren if they exist
|
|
337
|
+
if (child.hasChildren &&
|
|
338
|
+
child.childRows &&
|
|
339
|
+
child.childRows.length > 0) {
|
|
340
|
+
if (hasSelectedDescendant(child.childRows)) {
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
};
|
|
347
|
+
// Check if all descendants are selected
|
|
348
|
+
const areAllDescendantsSelected = (children) => {
|
|
349
|
+
for (const child of children) {
|
|
350
|
+
// If any child is not selected
|
|
351
|
+
if (!selectedRows.includes(child.id)) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
// Check grandchildren if they exist
|
|
355
|
+
if (child.hasChildren &&
|
|
356
|
+
child.childRows &&
|
|
357
|
+
child.childRows.length > 0) {
|
|
358
|
+
if (!areAllDescendantsSelected(child.childRows)) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return true;
|
|
364
|
+
};
|
|
365
|
+
const hasAnySelected = hasSelectedDescendant(row.childRows);
|
|
366
|
+
const hasAllSelected = areAllDescendantsSelected(row.childRows);
|
|
367
|
+
// Indeterminate if some but not all descendants are selected
|
|
368
|
+
// Or if the parent is not selected but some children are
|
|
369
|
+
return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
|
|
370
|
+
};
|
|
371
|
+
// Function to check if a row is selected
|
|
372
|
+
const isSelected = (rowId) => {
|
|
373
|
+
return selectedRows.includes(rowId);
|
|
374
|
+
};
|
|
375
|
+
// const handleCheckboxChange = (id: number) => {
|
|
376
|
+
// // Call your existing handleSelectionChange function
|
|
377
|
+
// // This will handle the hierarchical selection logic
|
|
378
|
+
// if (onSelectionChange) {
|
|
379
|
+
// onSelectionChange(id);
|
|
380
|
+
// } else {
|
|
381
|
+
// // Fallback to simple selection if no onSelectionChange is provided
|
|
382
|
+
// const updatedSelection = selectedRows.includes(id)
|
|
383
|
+
// ? selectedRows.filter((rowId) => rowId !== id)
|
|
384
|
+
// : [...selectedRows, id];
|
|
385
|
+
// setSelectedRows(updatedSelection);
|
|
386
|
+
// }
|
|
387
|
+
// };
|
|
388
|
+
const handleCheckboxChange = (id) => {
|
|
389
|
+
const findRowById = (rows, targetId) => {
|
|
390
|
+
for (const row of rows) {
|
|
391
|
+
if (row.id === targetId)
|
|
392
|
+
return row;
|
|
393
|
+
if (row.hasChildren && row.childRows) {
|
|
394
|
+
const found = findRowById(row.childRows, targetId);
|
|
395
|
+
if (found)
|
|
396
|
+
return found;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return null;
|
|
400
|
+
};
|
|
401
|
+
const getAllDescendantIds = (row) => {
|
|
402
|
+
let ids = [];
|
|
403
|
+
if (row.hasChildren && row.childRows) {
|
|
404
|
+
for (const child of row.childRows) {
|
|
405
|
+
ids.push(child.id);
|
|
406
|
+
ids = [...ids, ...getAllDescendantIds(child)];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return ids;
|
|
410
|
+
};
|
|
411
|
+
const updatedSelection = [...selectedRows];
|
|
412
|
+
const row = findRowById(rows, id);
|
|
413
|
+
if (!row)
|
|
414
|
+
return;
|
|
415
|
+
const descendantIds = getAllDescendantIds(row);
|
|
416
|
+
if (selectedRows.includes(id)) {
|
|
417
|
+
// Remove parent + all descendants
|
|
418
|
+
const idsToRemove = [id, ...descendantIds];
|
|
419
|
+
setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
// Add parent + all descendants
|
|
423
|
+
const idsToAdd = [id, ...descendantIds];
|
|
424
|
+
setSelectedRows([
|
|
425
|
+
...updatedSelection,
|
|
426
|
+
...idsToAdd.filter((i) => !updatedSelection.includes(i)),
|
|
427
|
+
]);
|
|
428
|
+
}
|
|
429
|
+
if (onSelectionChange) {
|
|
430
|
+
onSelectionChange(id);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
// Extract title and subtitle from row data
|
|
279
434
|
const extractCardData = (row) => {
|
|
280
435
|
let title = "";
|
|
281
436
|
let subtitle = "";
|
|
@@ -285,46 +440,58 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
285
440
|
let price = "";
|
|
286
441
|
if (!row.data)
|
|
287
442
|
return { title, subtitle, icon, status, statusClass, price };
|
|
443
|
+
// Find title (usually first text item)
|
|
288
444
|
const titleItem = row.data.find((item) => item.type === "text" && item.value);
|
|
289
445
|
if (titleItem) {
|
|
290
446
|
title = titleItem.value;
|
|
291
447
|
}
|
|
292
448
|
else if (row.data.length > 0) {
|
|
449
|
+
// Fallback to first item
|
|
293
450
|
title = String(row.data[0].value || "");
|
|
294
451
|
}
|
|
452
|
+
// Find subtitle (usually size or description)
|
|
295
453
|
const subtitleItem = row.data.find((item) => item.type === "text" && item.isSubtitle);
|
|
296
454
|
if (subtitleItem) {
|
|
297
455
|
subtitle = subtitleItem.value;
|
|
298
456
|
}
|
|
299
457
|
else if (row.data.length > 1) {
|
|
458
|
+
// Fallback to second item
|
|
300
459
|
subtitle = String(row.data[1].value || "");
|
|
301
460
|
}
|
|
461
|
+
// Find status
|
|
302
462
|
const statusItem = row.data.find((item) => item.type === "status");
|
|
303
463
|
if (statusItem) {
|
|
304
464
|
status = String(statusItem.value || "");
|
|
305
465
|
statusClass = statusItem.statusClass || "";
|
|
306
466
|
}
|
|
467
|
+
// Find price (look for item with isPrice flag)
|
|
307
468
|
const priceItem = row.data.find((item) => item.isPrice);
|
|
308
469
|
if (priceItem) {
|
|
309
470
|
price = String(priceItem.value || "");
|
|
310
471
|
}
|
|
472
|
+
// Find icon (usually avatar or image)
|
|
311
473
|
const iconItem = row.data.find((item) => item.hasImage);
|
|
312
474
|
if (iconItem && iconItem.value) {
|
|
313
475
|
icon = String(iconItem.imageUrl || "");
|
|
314
476
|
}
|
|
315
477
|
return { title, subtitle, icon, status, statusClass, price };
|
|
316
478
|
};
|
|
479
|
+
// Find avatar items in row data
|
|
317
480
|
const findAvatarItems = (row) => {
|
|
318
481
|
if (!row.data)
|
|
319
482
|
return [];
|
|
320
483
|
return row.data.filter((item) => item.type === "avatar" && item.isUserAvatar);
|
|
321
484
|
};
|
|
485
|
+
// Get all rows and their children for mobile view - updated for multi-level nesting
|
|
322
486
|
const getAllMobileRows = () => {
|
|
323
487
|
const result = [];
|
|
488
|
+
// Helper function to add parent rows and child rows that should be visible at any depth
|
|
324
489
|
const processRows = (rows, level = 0) => {
|
|
325
490
|
rows?.forEach((row) => {
|
|
491
|
+
// Add level information to the row for proper indentation
|
|
326
492
|
const rowWithLevel = { ...row, level, isChild: level > 0 };
|
|
327
493
|
result.push(rowWithLevel);
|
|
494
|
+
// Add child rows if this row is expanded - recursively check all levels
|
|
328
495
|
if (row.hasChildren &&
|
|
329
496
|
expandedRows.includes(row.id) &&
|
|
330
497
|
row.childRows &&
|
|
@@ -338,6 +505,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
338
505
|
}
|
|
339
506
|
return result;
|
|
340
507
|
};
|
|
508
|
+
// Mobile card view
|
|
341
509
|
const renderMobileCard = (row) => {
|
|
342
510
|
if (!row || !row.data)
|
|
343
511
|
return null;
|
|
@@ -346,7 +514,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
346
514
|
const isFavorited = row.data.some((item) => item.isFavorite);
|
|
347
515
|
const hasChildren = row.hasChildren && row.childRows && row?.childRows?.length > 0;
|
|
348
516
|
const level = row.level || 0;
|
|
349
|
-
const { cardStyle, showFolderIcon, folderIconPath, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
|
|
517
|
+
const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
|
|
518
|
+
// showMoreOptions,
|
|
519
|
+
moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
|
|
520
|
+
// Calculate card classes - add special styling for child cards
|
|
350
521
|
const cardClasses = `
|
|
351
522
|
${cardStyle?.backgroundColor || "bg-white"}
|
|
352
523
|
${cardStyle?.borderRadius || "rounded-lg"}
|
|
@@ -365,7 +536,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
365
536
|
react_1.default.createElement("div", { className: "w-10 h-10 flex items-center justify-center" }, row.data &&
|
|
366
537
|
row.data.find((item) => item.hasImage)?.imageUrl ? (react_1.default.createElement(image_1.default, { src: row.data.find((item) => item.hasImage)?.imageUrl ||
|
|
367
538
|
"/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" }))))),
|
|
368
|
-
react_1.default.createElement("div", null,
|
|
539
|
+
react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
369
540
|
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) => {
|
|
370
541
|
if (el) {
|
|
371
542
|
el.indeterminate = isIndeterminate(row.id);
|
|
@@ -409,7 +580,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
409
580
|
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: {
|
|
410
581
|
position: "fixed",
|
|
411
582
|
top: `${mousePosition.y}px`,
|
|
412
|
-
left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `,
|
|
583
|
+
left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `, // Ensure modal stays within screen
|
|
413
584
|
}, onClick: (e) => e.stopPropagation() },
|
|
414
585
|
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
|
|
415
586
|
? modalActions(row)
|
|
@@ -422,7 +593,9 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
422
593
|
"+",
|
|
423
594
|
avatarItems.length - maxVisibleAvatars)))))))));
|
|
424
595
|
};
|
|
596
|
+
// Render a single table row (parent or child)
|
|
425
597
|
const renderTableRow = (row, index, isLastRow) => {
|
|
598
|
+
// Width for the expand/collapse control column
|
|
426
599
|
return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
|
|
427
600
|
react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
|
|
428
601
|
? childRowConfig.childRowClass || "bg-blue-300 bg-opacity-10"
|
|
@@ -444,7 +617,9 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
444
617
|
react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
|
|
445
618
|
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" },
|
|
446
619
|
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" : ""}` },
|
|
447
|
-
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 ? (
|
|
620
|
+
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 ? (
|
|
621
|
+
// Child row indicator
|
|
622
|
+
react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
|
|
448
623
|
selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
449
624
|
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) => {
|
|
450
625
|
if (el) {
|
|
@@ -492,15 +667,21 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
492
667
|
(typeof showModalIcon === "function"
|
|
493
668
|
? showModalIcon(row)
|
|
494
669
|
: showModalIcon) ? (react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: "", "data-row-id": row.id },
|
|
495
|
-
react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
|
|
670
|
+
react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
|
|
671
|
+
// Render an invisible placeholder to maintain spacing when icon is hidden
|
|
672
|
+
react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
|
|
496
673
|
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: {
|
|
497
674
|
position: "fixed",
|
|
498
675
|
top: (() => {
|
|
676
|
+
// Get all visible rows for the current view
|
|
499
677
|
const allRows = isMobileView
|
|
500
678
|
? getAllMobileRows()
|
|
501
679
|
: rows;
|
|
680
|
+
// Find the index of the current row
|
|
502
681
|
const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
|
|
682
|
+
// Check if this is one of the last 3 rows
|
|
503
683
|
const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
|
|
684
|
+
// If it's one of the last 3 rows, reduce the top position by 100px
|
|
504
685
|
return isLastThreeRows
|
|
505
686
|
? `${mousePosition.y - 110}px`
|
|
506
687
|
: `${mousePosition.y}px`;
|
|
@@ -515,12 +696,15 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
515
696
|
row.childRows &&
|
|
516
697
|
row.childRows.map((childRow, childIndex) => renderTableRow(childRow, childIndex, childIndex === row.childRows.length - 1 && isLastRow))));
|
|
517
698
|
};
|
|
699
|
+
// Prepare all mobile rows
|
|
518
700
|
const mobileRows = getAllMobileRows();
|
|
701
|
+
// Show loading state if loading is true
|
|
519
702
|
if (loadingProps.isLoading) {
|
|
520
703
|
return (react_1.default.createElement("div", { className: "w-full flex justify-center items-center py-8 gap-3" },
|
|
521
704
|
loadingProps.loadingIcon,
|
|
522
705
|
loadingProps.loadingText && loadingProps.loadingText));
|
|
523
706
|
}
|
|
707
|
+
// Show no items found if rows are empty or null and not loading
|
|
524
708
|
if (!loadingProps.isLoading && rows?.length === 0) {
|
|
525
709
|
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,
|
|
526
710
|
react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath || "/icons/no-data.svg", alt: "No items found", width: 120, height: 120 }),
|