hi-tm 0.11.6 → 0.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -300,93 +300,15 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
300
300
|
// }
|
|
301
301
|
// };
|
|
302
302
|
// Function to determine if a row has any descendants selected (not just direct children)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// const findRow = (
|
|
306
|
-
// rows: TableRowData[] | undefined,
|
|
307
|
-
// id: number
|
|
308
|
-
// ): TableRowData | null => {
|
|
309
|
-
// if (!rows) return null;
|
|
310
|
-
// for (const row of rows) {
|
|
311
|
-
// if (row.id === id) return row;
|
|
312
|
-
// if (row.hasChildren && row.childRows) {
|
|
313
|
-
// const found = findRow(row.childRows, id);
|
|
314
|
-
// if (found) return found;
|
|
315
|
-
// }
|
|
316
|
-
// }
|
|
317
|
-
// return null;
|
|
318
|
-
// };
|
|
319
|
-
// const row = findRow(rows!, rowId);
|
|
320
|
-
// // If row has no children, it can't be indeterminate
|
|
321
|
-
// if (
|
|
322
|
-
// !row ||
|
|
323
|
-
// !row.hasChildren ||
|
|
324
|
-
// !row.childRows ||
|
|
325
|
-
// row.childRows.length === 0
|
|
326
|
-
// ) {
|
|
327
|
-
// return false;
|
|
328
|
-
// }
|
|
329
|
-
// // Check if the row itself is selected
|
|
330
|
-
// const isRowSelected = selectedRows.includes(rowId);
|
|
331
|
-
// // Recursively check if any descendant is selected
|
|
332
|
-
// const hasSelectedDescendant = (children: TableRowData[]): boolean => {
|
|
333
|
-
// for (const child of children) {
|
|
334
|
-
// // If any child is selected
|
|
335
|
-
// if (selectedRows.includes(child.id)) {
|
|
336
|
-
// return true;
|
|
337
|
-
// }
|
|
338
|
-
// // Check grandchildren if they exist
|
|
339
|
-
// if (
|
|
340
|
-
// child.hasChildren &&
|
|
341
|
-
// child.childRows &&
|
|
342
|
-
// child.childRows.length > 0
|
|
343
|
-
// ) {
|
|
344
|
-
// if (hasSelectedDescendant(child.childRows)) {
|
|
345
|
-
// return true;
|
|
346
|
-
// }
|
|
347
|
-
// }
|
|
348
|
-
// }
|
|
349
|
-
// return false;
|
|
350
|
-
// };
|
|
351
|
-
// // Check if all descendants are selected
|
|
352
|
-
// const areAllDescendantsSelected = (children: TableRowData[]): boolean => {
|
|
353
|
-
// for (const child of children) {
|
|
354
|
-
// // If any child is not selected
|
|
355
|
-
// if (!selectedRows.includes(child.id)) {
|
|
356
|
-
// return false;
|
|
357
|
-
// }
|
|
358
|
-
// // Check grandchildren if they exist
|
|
359
|
-
// if (
|
|
360
|
-
// child.hasChildren &&
|
|
361
|
-
// child.childRows &&
|
|
362
|
-
// child.childRows.length > 0
|
|
363
|
-
// ) {
|
|
364
|
-
// if (!areAllDescendantsSelected(child.childRows)) {
|
|
365
|
-
// return false;
|
|
366
|
-
// }
|
|
367
|
-
// }
|
|
368
|
-
// }
|
|
369
|
-
// return true;
|
|
370
|
-
// };
|
|
371
|
-
// const hasAnySelected = hasSelectedDescendant(row.childRows);
|
|
372
|
-
// const hasAllSelected = areAllDescendantsSelected(row.childRows);
|
|
373
|
-
// // Indeterminate if some but not all descendants are selected
|
|
374
|
-
// // Or if the parent is not selected but some children are
|
|
375
|
-
// return (
|
|
376
|
-
// (hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected)
|
|
377
|
-
// );
|
|
378
|
-
// };
|
|
379
|
-
const isIndeterminate = (rowId, rows, selectedRows) => {
|
|
380
|
-
// تبدیل selectedRows به Set برای دسترسی سریع
|
|
381
|
-
const selectedSet = new Set(selectedRows);
|
|
382
|
-
// تابع پیدا کردن ردیف (بازگشتی)
|
|
303
|
+
const isIndeterminate = (rowId) => {
|
|
304
|
+
// Find the row in the data
|
|
383
305
|
const findRow = (rows, id) => {
|
|
384
306
|
if (!rows)
|
|
385
307
|
return null;
|
|
386
308
|
for (const row of rows) {
|
|
387
309
|
if (row.id === id)
|
|
388
310
|
return row;
|
|
389
|
-
if (row.hasChildren && row.childRows
|
|
311
|
+
if (row.hasChildren && row.childRows) {
|
|
390
312
|
const found = findRow(row.childRows, id);
|
|
391
313
|
if (found)
|
|
392
314
|
return found;
|
|
@@ -395,56 +317,117 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
395
317
|
return null;
|
|
396
318
|
};
|
|
397
319
|
const row = findRow(rows, rowId);
|
|
398
|
-
|
|
399
|
-
|
|
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) {
|
|
400
325
|
return false;
|
|
401
326
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
let allSelected = true;
|
|
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) => {
|
|
407
331
|
for (const child of children) {
|
|
408
|
-
|
|
409
|
-
if (
|
|
410
|
-
|
|
332
|
+
// If any child is selected
|
|
333
|
+
if (selectedRows.includes(child.id)) {
|
|
334
|
+
return true;
|
|
411
335
|
}
|
|
412
|
-
|
|
413
|
-
|
|
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
|
+
}
|
|
414
343
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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
|
+
}
|
|
421
361
|
}
|
|
422
|
-
// بهینهسازی: اگر هم anySelected و هم allSelected مشخص شدن
|
|
423
|
-
// دیگه نیاز نیست ادامه بدیم
|
|
424
|
-
if (anySelected && !allSelected)
|
|
425
|
-
break;
|
|
426
362
|
}
|
|
427
|
-
return
|
|
363
|
+
return true;
|
|
428
364
|
};
|
|
429
|
-
const
|
|
430
|
-
|
|
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));
|
|
431
370
|
};
|
|
432
371
|
// Function to check if a row is selected
|
|
433
372
|
const isSelected = (rowId) => {
|
|
434
373
|
return selectedRows.includes(rowId);
|
|
435
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
|
+
// };
|
|
436
388
|
const handleCheckboxChange = (id) => {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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)));
|
|
441
420
|
}
|
|
442
421
|
else {
|
|
443
|
-
//
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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);
|
|
448
431
|
}
|
|
449
432
|
};
|
|
450
433
|
// Extract title and subtitle from row data
|
|
@@ -556,7 +539,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
556
539
|
react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
557
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) => {
|
|
558
541
|
if (el) {
|
|
559
|
-
el.indeterminate = isIndeterminate(row.id
|
|
542
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
560
543
|
}
|
|
561
544
|
} })))),
|
|
562
545
|
react_1.default.createElement("div", { className: "flex-1 min-w-0" },
|
|
@@ -640,10 +623,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
640
623
|
selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
641
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) => {
|
|
642
625
|
if (el) {
|
|
643
|
-
el.indeterminate = isIndeterminate(row.id
|
|
626
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
644
627
|
}
|
|
645
628
|
} }),
|
|
646
|
-
isIndeterminate(row.id
|
|
629
|
+
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" },
|
|
647
630
|
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" }))))))),
|
|
648
631
|
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" ||
|
|
649
632
|
item.type === "operation" ||
|
|
@@ -665,10 +648,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
665
648
|
react_1.default.createElement("div", { className: "relative flex items-center justify-center " },
|
|
666
649
|
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) => {
|
|
667
650
|
if (el) {
|
|
668
|
-
el.indeterminate = isIndeterminate(row.id
|
|
651
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
669
652
|
}
|
|
670
653
|
} }),
|
|
671
|
-
isIndeterminate(row.id
|
|
654
|
+
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" },
|
|
672
655
|
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" })))))),
|
|
673
656
|
renderCellContent(item)))),
|
|
674
657
|
actions && (react_1.default.createElement("div", { className: `w-24 py-4 flex items-center justify-end text-sm font-medium ${actionButtonsStyle || ""}` },
|