hi-tm 0.10.5 → 0.10.6
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.
|
@@ -377,46 +377,37 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
377
377
|
// );
|
|
378
378
|
// };
|
|
379
379
|
const isIndeterminate = (rowId) => {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
380
|
+
// ذخیره نتایج برای هر ردیف تا دوباره محاسبه نشه
|
|
381
|
+
const memo = new Map();
|
|
382
|
+
const checkIndeterminate = (row) => {
|
|
383
|
+
if (!row.childRows?.length)
|
|
384
|
+
return false;
|
|
385
|
+
if (memo.has(row.id))
|
|
386
|
+
return memo.get(row.id);
|
|
387
|
+
let total = 0;
|
|
388
|
+
let selected = 0;
|
|
389
|
+
for (const child of row.childRows) {
|
|
390
|
+
total += 1;
|
|
391
|
+
if (selectedRows.includes(child.id))
|
|
392
|
+
selected += 1;
|
|
393
|
+
// بررسی بازگشتی فرزندان
|
|
394
|
+
if (child.childRows?.length) {
|
|
395
|
+
const childIndeterminate = checkIndeterminate(child);
|
|
396
|
+
if (childIndeterminate) {
|
|
397
|
+
// اگر هر descendant indeterminate بود، خود row هم indeterminate است
|
|
398
|
+
memo.set(row.id, true);
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
389
401
|
}
|
|
390
402
|
}
|
|
403
|
+
const isIndet = selected > 0 && selected < total;
|
|
404
|
+
memo.set(row.id, isIndet);
|
|
405
|
+
return isIndet;
|
|
391
406
|
};
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
!row.childRows ||
|
|
397
|
-
row.childRows.length === 0) {
|
|
398
|
-
return false; // اگر child ندارد
|
|
399
|
-
}
|
|
400
|
-
const selectedSet = new Set(selectedRows); // lookup سریع
|
|
401
|
-
let hasAnySelected = false;
|
|
402
|
-
let hasAllSelected = true;
|
|
403
|
-
const stack = [...row.childRows];
|
|
404
|
-
while (stack.length > 0) {
|
|
405
|
-
const current = stack.pop();
|
|
406
|
-
if (selectedSet.has(current.id)) {
|
|
407
|
-
hasAnySelected = true;
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
hasAllSelected = false;
|
|
411
|
-
}
|
|
412
|
-
if (current.hasChildren &&
|
|
413
|
-
current.childRows &&
|
|
414
|
-
current.childRows.length > 0) {
|
|
415
|
-
stack.push(...current.childRows);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
const isRowSelected = selectedSet.has(rowId);
|
|
419
|
-
return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
|
|
407
|
+
const row = rows?.find((r) => r.id === rowId);
|
|
408
|
+
if (!row)
|
|
409
|
+
return false;
|
|
410
|
+
return checkIndeterminate(row);
|
|
420
411
|
};
|
|
421
412
|
// Function to check if a row is selected
|
|
422
413
|
const isSelected = (rowId) => {
|