hi-tm 0.11.6 → 0.11.8
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,57 +317,122 @@ 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
|
+
// };
|
|
388
|
+
const [isProcessingSelection, setIsProcessingSelection] = (0, react_2.useState)(false);
|
|
436
389
|
const handleCheckboxChange = (id) => {
|
|
437
|
-
//
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
|
449
436
|
};
|
|
450
437
|
// Extract title and subtitle from row data
|
|
451
438
|
const extractCardData = (row) => {
|
|
@@ -556,9 +543,11 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
556
543
|
react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
557
544
|
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
545
|
if (el) {
|
|
559
|
-
el.indeterminate = isIndeterminate(row.id
|
|
546
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
560
547
|
}
|
|
561
548
|
} })))),
|
|
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))),
|
|
562
551
|
react_1.default.createElement("div", { className: "flex-1 min-w-0" },
|
|
563
552
|
react_1.default.createElement("div", { className: "flex items-start justify-between" },
|
|
564
553
|
react_1.default.createElement("div", { className: "overflow-hidden" },
|
|
@@ -640,10 +629,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
640
629
|
selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
641
630
|
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
631
|
if (el) {
|
|
643
|
-
el.indeterminate = isIndeterminate(row.id
|
|
632
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
644
633
|
}
|
|
645
634
|
} }),
|
|
646
|
-
isIndeterminate(row.id
|
|
635
|
+
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
636
|
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
637
|
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
638
|
item.type === "operation" ||
|
|
@@ -665,10 +654,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
665
654
|
react_1.default.createElement("div", { className: "relative flex items-center justify-center " },
|
|
666
655
|
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
656
|
if (el) {
|
|
668
|
-
el.indeterminate = isIndeterminate(row.id
|
|
657
|
+
el.indeterminate = isIndeterminate(row.id);
|
|
669
658
|
}
|
|
670
659
|
} }),
|
|
671
|
-
isIndeterminate(row.id
|
|
660
|
+
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
661
|
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
662
|
renderCellContent(item)))),
|
|
674
663
|
actions && (react_1.default.createElement("div", { className: `w-24 py-4 flex items-center justify-end text-sm font-medium ${actionButtonsStyle || ""}` },
|