hi-tm 0.11.8 → 0.12.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,11 +1,43 @@
|
|
|
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
|
+
})();
|
|
3
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
38
|
};
|
|
6
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const react_1 =
|
|
8
|
-
const react_2 = require("react");
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
9
41
|
const image_1 = __importDefault(require("next/image"));
|
|
10
42
|
const SafeImage_1 = __importDefault(require("../../../elements/SafeImage"));
|
|
11
43
|
// Simple Loader component defined inline to avoid import issues
|
|
@@ -68,62 +100,81 @@ mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
|
|
|
68
100
|
pageIndex = 0, // Default to first page (0-indexed)
|
|
69
101
|
}) => {
|
|
70
102
|
// Track which rows are expanded to show their children
|
|
71
|
-
const [expandedRows, setExpandedRows] = (0,
|
|
72
|
-
const [activeModal, setActiveModal] = (0,
|
|
73
|
-
const modalRef = (0,
|
|
103
|
+
const [expandedRows, setExpandedRows] = (0, react_1.useState)([]);
|
|
104
|
+
const [activeModal, setActiveModal] = (0, react_1.useState)(null);
|
|
105
|
+
const modalRef = (0, react_1.useRef)(null);
|
|
74
106
|
// Store calculated column widths
|
|
75
|
-
const [selectedRows, setSelectedRows] = (0,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
const [selectedRows, setSelectedRows] = (0, react_1.useState)(selectedItems || []);
|
|
108
|
+
const [mousePosition, setMousePosition] = (0, react_1.useState)({ x: 0, y: 0 });
|
|
109
|
+
// --- Optimized Maps ---
|
|
110
|
+
const { rowsMap, descendantsMap } = (0, react_1.useMemo)(() => {
|
|
111
|
+
const rowsMap = new Map();
|
|
112
|
+
const descendantsMap = new Map();
|
|
113
|
+
const buildMaps = (rows) => {
|
|
114
|
+
rows?.forEach((row) => {
|
|
115
|
+
rowsMap.set(row.id, row);
|
|
116
|
+
const descendantIds = [];
|
|
117
|
+
const collectDescendants = (children) => {
|
|
118
|
+
children.forEach((child) => {
|
|
119
|
+
descendantIds.push(child.id);
|
|
120
|
+
if (child.hasChildren && child.childRows) {
|
|
121
|
+
collectDescendants(child.childRows);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
if (row.hasChildren && row.childRows) {
|
|
126
|
+
collectDescendants(row.childRows);
|
|
90
127
|
}
|
|
128
|
+
descendantsMap.set(row.id, descendantIds);
|
|
91
129
|
});
|
|
92
130
|
};
|
|
93
|
-
|
|
94
|
-
|
|
131
|
+
buildMaps(rows);
|
|
132
|
+
return { rowsMap, descendantsMap };
|
|
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;
|
|
95
148
|
}
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
}
|
|
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
|
+
const handleCheckboxChange = (id) => {
|
|
156
|
+
const row = findRowById(id);
|
|
157
|
+
if (!row)
|
|
158
|
+
return;
|
|
159
|
+
const descendantIds = getAllDescendantIds(id);
|
|
160
|
+
const updatedSelection = [...selectedRows];
|
|
161
|
+
if (selectedRows.includes(id)) {
|
|
162
|
+
const idsToRemove = [id, ...descendantIds];
|
|
163
|
+
setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
|
|
123
164
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
165
|
+
else {
|
|
166
|
+
const idsToAdd = [id, ...descendantIds];
|
|
167
|
+
setSelectedRows([
|
|
168
|
+
...updatedSelection,
|
|
169
|
+
...idsToAdd.filter((i) => !updatedSelection.includes(i)),
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
if (onSelectionChange) {
|
|
173
|
+
onSelectionChange(id);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
// --- Effects ---
|
|
177
|
+
(0, react_1.useEffect)(() => {
|
|
127
178
|
if (childRowConfig.expandByDefault && rows) {
|
|
128
179
|
const parentIds = rows
|
|
129
180
|
.filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
|
|
@@ -131,7 +182,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
131
182
|
setExpandedRows(parentIds);
|
|
132
183
|
}
|
|
133
184
|
}, [rows, childRowConfig.expandByDefault]);
|
|
134
|
-
(0,
|
|
185
|
+
(0, react_1.useEffect)(() => {
|
|
135
186
|
const handleClickOutside = (event) => {
|
|
136
187
|
const target = event.target;
|
|
137
188
|
if (target.closest(".modal-content")) {
|
|
@@ -147,7 +198,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
147
198
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
148
199
|
};
|
|
149
200
|
}, []);
|
|
150
|
-
(0,
|
|
201
|
+
(0, react_1.useEffect)(() => {
|
|
151
202
|
const handleScroll = () => {
|
|
152
203
|
if (activeModal !== null) {
|
|
153
204
|
setActiveModal(null);
|
|
@@ -158,7 +209,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
158
209
|
window.removeEventListener("scroll", handleScroll);
|
|
159
210
|
};
|
|
160
211
|
}, [activeModal]);
|
|
161
|
-
|
|
212
|
+
(0, react_1.useEffect)(() => {
|
|
213
|
+
setSelectedRows(selectedItems || []);
|
|
214
|
+
}, [selectedItems]);
|
|
215
|
+
// --- Handlers ---
|
|
162
216
|
const handleModalToggle = (id, e) => {
|
|
163
217
|
e.stopPropagation();
|
|
164
218
|
e.preventDefault();
|
|
@@ -214,227 +268,6 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
214
268
|
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))));
|
|
215
269
|
}
|
|
216
270
|
};
|
|
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 [isProcessingSelection, setIsProcessingSelection] = (0, react_2.useState)(false);
|
|
389
|
-
const handleCheckboxChange = (id) => {
|
|
390
|
-
setIsProcessingSelection(true); // شروع پردازش
|
|
391
|
-
setTimeout(() => {
|
|
392
|
-
// شبیهسازی پردازش سنگین یا async
|
|
393
|
-
const findRowById = (rows, targetId) => {
|
|
394
|
-
for (const row of rows) {
|
|
395
|
-
if (row.id === targetId)
|
|
396
|
-
return row;
|
|
397
|
-
if (row.hasChildren && row.childRows) {
|
|
398
|
-
const found = findRowById(row.childRows, targetId);
|
|
399
|
-
if (found)
|
|
400
|
-
return found;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return null;
|
|
404
|
-
};
|
|
405
|
-
const getAllDescendantIds = (row) => {
|
|
406
|
-
let ids = [];
|
|
407
|
-
if (row.hasChildren && row.childRows) {
|
|
408
|
-
for (const child of row.childRows) {
|
|
409
|
-
ids.push(child.id);
|
|
410
|
-
ids = [...ids, ...getAllDescendantIds(child)];
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return ids;
|
|
414
|
-
};
|
|
415
|
-
const updatedSelection = [...selectedRows];
|
|
416
|
-
const row = findRowById(rows, id);
|
|
417
|
-
if (!row)
|
|
418
|
-
return;
|
|
419
|
-
const descendantIds = getAllDescendantIds(row);
|
|
420
|
-
if (selectedRows.includes(id)) {
|
|
421
|
-
const idsToRemove = [id, ...descendantIds];
|
|
422
|
-
setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
const idsToAdd = [id, ...descendantIds];
|
|
426
|
-
setSelectedRows([
|
|
427
|
-
...updatedSelection,
|
|
428
|
-
...idsToAdd.filter((i) => !updatedSelection.includes(i)),
|
|
429
|
-
]);
|
|
430
|
-
}
|
|
431
|
-
if (onSelectionChange) {
|
|
432
|
-
onSelectionChange(id);
|
|
433
|
-
}
|
|
434
|
-
setIsProcessingSelection(false); // پایان پردازش
|
|
435
|
-
}, 50); // مقدار کوتاه برای شبیهسازی async
|
|
436
|
-
};
|
|
437
|
-
// Extract title and subtitle from row data
|
|
438
271
|
const extractCardData = (row) => {
|
|
439
272
|
let title = "";
|
|
440
273
|
let subtitle = "";
|
|
@@ -444,58 +277,46 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
444
277
|
let price = "";
|
|
445
278
|
if (!row.data)
|
|
446
279
|
return { title, subtitle, icon, status, statusClass, price };
|
|
447
|
-
// Find title (usually first text item)
|
|
448
280
|
const titleItem = row.data.find((item) => item.type === "text" && item.value);
|
|
449
281
|
if (titleItem) {
|
|
450
282
|
title = titleItem.value;
|
|
451
283
|
}
|
|
452
284
|
else if (row.data.length > 0) {
|
|
453
|
-
// Fallback to first item
|
|
454
285
|
title = String(row.data[0].value || "");
|
|
455
286
|
}
|
|
456
|
-
// Find subtitle (usually size or description)
|
|
457
287
|
const subtitleItem = row.data.find((item) => item.type === "text" && item.isSubtitle);
|
|
458
288
|
if (subtitleItem) {
|
|
459
289
|
subtitle = subtitleItem.value;
|
|
460
290
|
}
|
|
461
291
|
else if (row.data.length > 1) {
|
|
462
|
-
// Fallback to second item
|
|
463
292
|
subtitle = String(row.data[1].value || "");
|
|
464
293
|
}
|
|
465
|
-
// Find status
|
|
466
294
|
const statusItem = row.data.find((item) => item.type === "status");
|
|
467
295
|
if (statusItem) {
|
|
468
296
|
status = String(statusItem.value || "");
|
|
469
297
|
statusClass = statusItem.statusClass || "";
|
|
470
298
|
}
|
|
471
|
-
// Find price (look for item with isPrice flag)
|
|
472
299
|
const priceItem = row.data.find((item) => item.isPrice);
|
|
473
300
|
if (priceItem) {
|
|
474
301
|
price = String(priceItem.value || "");
|
|
475
302
|
}
|
|
476
|
-
// Find icon (usually avatar or image)
|
|
477
303
|
const iconItem = row.data.find((item) => item.hasImage);
|
|
478
304
|
if (iconItem && iconItem.value) {
|
|
479
305
|
icon = String(iconItem.imageUrl || "");
|
|
480
306
|
}
|
|
481
307
|
return { title, subtitle, icon, status, statusClass, price };
|
|
482
308
|
};
|
|
483
|
-
// Find avatar items in row data
|
|
484
309
|
const findAvatarItems = (row) => {
|
|
485
310
|
if (!row.data)
|
|
486
311
|
return [];
|
|
487
312
|
return row.data.filter((item) => item.type === "avatar" && item.isUserAvatar);
|
|
488
313
|
};
|
|
489
|
-
// Get all rows and their children for mobile view - updated for multi-level nesting
|
|
490
314
|
const getAllMobileRows = () => {
|
|
491
315
|
const result = [];
|
|
492
|
-
// Helper function to add parent rows and child rows that should be visible at any depth
|
|
493
316
|
const processRows = (rows, level = 0) => {
|
|
494
317
|
rows?.forEach((row) => {
|
|
495
|
-
// Add level information to the row for proper indentation
|
|
496
318
|
const rowWithLevel = { ...row, level, isChild: level > 0 };
|
|
497
319
|
result.push(rowWithLevel);
|
|
498
|
-
// Add child rows if this row is expanded - recursively check all levels
|
|
499
320
|
if (row.hasChildren &&
|
|
500
321
|
expandedRows.includes(row.id) &&
|
|
501
322
|
row.childRows &&
|
|
@@ -509,7 +330,6 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
509
330
|
}
|
|
510
331
|
return result;
|
|
511
332
|
};
|
|
512
|
-
// Mobile card view
|
|
513
333
|
const renderMobileCard = (row) => {
|
|
514
334
|
if (!row || !row.data)
|
|
515
335
|
return null;
|
|
@@ -518,10 +338,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
518
338
|
const isFavorited = row.data.some((item) => item.isFavorite);
|
|
519
339
|
const hasChildren = row.hasChildren && row.childRows && row?.childRows?.length > 0;
|
|
520
340
|
const level = row.level || 0;
|
|
521
|
-
const { cardStyle, showFolderIcon, folderIconPath,
|
|
522
|
-
// showMoreOptions,
|
|
523
|
-
moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
|
|
524
|
-
// Calculate card classes - add special styling for child cards
|
|
341
|
+
const { cardStyle, showFolderIcon, folderIconPath, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath, moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
|
|
525
342
|
const cardClasses = `
|
|
526
343
|
${cardStyle?.backgroundColor || "bg-white"}
|
|
527
344
|
${cardStyle?.borderRadius || "rounded-lg"}
|
|
@@ -540,14 +357,12 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
540
357
|
react_1.default.createElement("div", { className: "w-10 h-10 flex items-center justify-center" }, row.data &&
|
|
541
358
|
row.data.find((item) => item.hasImage)?.imageUrl ? (react_1.default.createElement(image_1.default, { src: row.data.find((item) => item.hasImage)?.imageUrl ||
|
|
542
359
|
"/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" }))))),
|
|
543
|
-
react_1.default.createElement("div", null,
|
|
360
|
+
react_1.default.createElement("div", null, selectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
544
361
|
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) => {
|
|
545
362
|
if (el) {
|
|
546
363
|
el.indeterminate = isIndeterminate(row.id);
|
|
547
364
|
}
|
|
548
365
|
} })))),
|
|
549
|
-
isProcessingSelection && (react_1.default.createElement("div", { className: "absolute inset-0 flex items-center justify-center bg-white/50 z-50" },
|
|
550
|
-
react_1.default.createElement(Loader, null))),
|
|
551
366
|
react_1.default.createElement("div", { className: "flex-1 min-w-0" },
|
|
552
367
|
react_1.default.createElement("div", { className: "flex items-start justify-between" },
|
|
553
368
|
react_1.default.createElement("div", { className: "overflow-hidden" },
|
|
@@ -586,7 +401,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
586
401
|
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: {
|
|
587
402
|
position: "fixed",
|
|
588
403
|
top: `${mousePosition.y}px`,
|
|
589
|
-
left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `,
|
|
404
|
+
left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `,
|
|
590
405
|
}, onClick: (e) => e.stopPropagation() },
|
|
591
406
|
react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
|
|
592
407
|
? modalActions(row)
|
|
@@ -599,9 +414,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
599
414
|
"+",
|
|
600
415
|
avatarItems.length - maxVisibleAvatars)))))))));
|
|
601
416
|
};
|
|
602
|
-
// Render a single table row (parent or child)
|
|
603
417
|
const renderTableRow = (row, index, isLastRow) => {
|
|
604
|
-
// Width for the expand/collapse control column
|
|
605
418
|
return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
|
|
606
419
|
react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
|
|
607
420
|
? childRowConfig.childRowClass || "bg-blue-300 bg-opacity-10"
|
|
@@ -623,9 +436,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
623
436
|
react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
|
|
624
437
|
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" },
|
|
625
438
|
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" : ""}` },
|
|
626
|
-
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 ? (
|
|
627
|
-
// Child row indicator
|
|
628
|
-
react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
|
|
439
|
+
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 ? (react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
|
|
629
440
|
selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
630
441
|
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) => {
|
|
631
442
|
if (el) {
|
|
@@ -673,21 +484,15 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
673
484
|
(typeof showModalIcon === "function"
|
|
674
485
|
? showModalIcon(row)
|
|
675
486
|
: showModalIcon) ? (react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: "", "data-row-id": row.id },
|
|
676
|
-
react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
|
|
677
|
-
// Render an invisible placeholder to maintain spacing when icon is hidden
|
|
678
|
-
react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
|
|
487
|
+
react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
|
|
679
488
|
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: {
|
|
680
489
|
position: "fixed",
|
|
681
490
|
top: (() => {
|
|
682
|
-
// Get all visible rows for the current view
|
|
683
491
|
const allRows = isMobileView
|
|
684
492
|
? getAllMobileRows()
|
|
685
493
|
: rows;
|
|
686
|
-
// Find the index of the current row
|
|
687
494
|
const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
|
|
688
|
-
// Check if this is one of the last 3 rows
|
|
689
495
|
const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
|
|
690
|
-
// If it's one of the last 3 rows, reduce the top position by 100px
|
|
691
496
|
return isLastThreeRows
|
|
692
497
|
? `${mousePosition.y - 110}px`
|
|
693
498
|
: `${mousePosition.y}px`;
|
|
@@ -702,15 +507,12 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
702
507
|
row.childRows &&
|
|
703
508
|
row.childRows.map((childRow, childIndex) => renderTableRow(childRow, childIndex, childIndex === row.childRows.length - 1 && isLastRow))));
|
|
704
509
|
};
|
|
705
|
-
// Prepare all mobile rows
|
|
706
510
|
const mobileRows = getAllMobileRows();
|
|
707
|
-
// Show loading state if loading is true
|
|
708
511
|
if (loadingProps.isLoading) {
|
|
709
512
|
return (react_1.default.createElement("div", { className: "w-full flex justify-center items-center py-8 gap-3" },
|
|
710
513
|
loadingProps.loadingIcon,
|
|
711
514
|
loadingProps.loadingText && loadingProps.loadingText));
|
|
712
515
|
}
|
|
713
|
-
// Show no items found if rows are empty or null and not loading
|
|
714
516
|
if (!loadingProps.isLoading && rows?.length === 0) {
|
|
715
517
|
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,
|
|
716
518
|
react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath || "/icons/no-data.svg", alt: "No items found", width: 120, height: 120 }),
|