hi-tm 0.11.4 → 0.11.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.
|
@@ -300,15 +300,93 @@ 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
|
-
const isIndeterminate = (rowId) => {
|
|
304
|
-
|
|
303
|
+
// const isIndeterminate = (rowId: number): boolean => {
|
|
304
|
+
// // Find the row in the data
|
|
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
|
+
// تابع پیدا کردن ردیف (بازگشتی)
|
|
305
383
|
const findRow = (rows, id) => {
|
|
306
384
|
if (!rows)
|
|
307
385
|
return null;
|
|
308
386
|
for (const row of rows) {
|
|
309
387
|
if (row.id === id)
|
|
310
388
|
return row;
|
|
311
|
-
if (row.hasChildren && row.childRows) {
|
|
389
|
+
if (row.hasChildren && row.childRows?.length) {
|
|
312
390
|
const found = findRow(row.childRows, id);
|
|
313
391
|
if (found)
|
|
314
392
|
return found;
|
|
@@ -317,56 +395,39 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
317
395
|
return null;
|
|
318
396
|
};
|
|
319
397
|
const row = findRow(rows, rowId);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
!row.hasChildren ||
|
|
323
|
-
!row.childRows ||
|
|
324
|
-
row.childRows.length === 0) {
|
|
398
|
+
if (!row || !row.hasChildren || !row.childRows?.length) {
|
|
399
|
+
// ردیف بچه نداره → اصلا indeterminate نمیشه
|
|
325
400
|
return false;
|
|
326
401
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
402
|
+
const isRowSelected = selectedSet.has(rowId);
|
|
403
|
+
// چک کردن بچهها
|
|
404
|
+
const checkChildren = (children) => {
|
|
405
|
+
let anySelected = false;
|
|
406
|
+
let allSelected = true;
|
|
331
407
|
for (const child of children) {
|
|
332
|
-
|
|
333
|
-
if (
|
|
334
|
-
|
|
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
|
-
}
|
|
408
|
+
const isSelected = selectedSet.has(child.id);
|
|
409
|
+
if (isSelected) {
|
|
410
|
+
anySelected = true;
|
|
343
411
|
}
|
|
344
|
-
|
|
345
|
-
|
|
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;
|
|
412
|
+
else {
|
|
413
|
+
allSelected = false;
|
|
353
414
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (!
|
|
359
|
-
|
|
360
|
-
}
|
|
415
|
+
if (child.hasChildren && child.childRows?.length) {
|
|
416
|
+
const { any, all } = checkChildren(child.childRows);
|
|
417
|
+
if (any)
|
|
418
|
+
anySelected = true;
|
|
419
|
+
if (!all)
|
|
420
|
+
allSelected = false;
|
|
361
421
|
}
|
|
422
|
+
// بهینهسازی: اگر هم anySelected و هم allSelected مشخص شدن
|
|
423
|
+
// دیگه نیاز نیست ادامه بدیم
|
|
424
|
+
if (anySelected && !allSelected)
|
|
425
|
+
break;
|
|
362
426
|
}
|
|
363
|
-
return
|
|
427
|
+
return { any: anySelected, all: allSelected };
|
|
364
428
|
};
|
|
365
|
-
const
|
|
366
|
-
|
|
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));
|
|
429
|
+
const { any, all } = checkChildren(row.childRows);
|
|
430
|
+
return (any && !all) || (!isRowSelected && any);
|
|
370
431
|
};
|
|
371
432
|
// Function to check if a row is selected
|
|
372
433
|
const isSelected = (rowId) => {
|
|
@@ -495,7 +556,7 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
495
556
|
react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
496
557
|
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) => {
|
|
497
558
|
if (el) {
|
|
498
|
-
el.indeterminate = isIndeterminate(row.id);
|
|
559
|
+
el.indeterminate = isIndeterminate(row.id, rows, selectedRows);
|
|
499
560
|
}
|
|
500
561
|
} })))),
|
|
501
562
|
react_1.default.createElement("div", { className: "flex-1 min-w-0" },
|
|
@@ -579,10 +640,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
579
640
|
selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
|
|
580
641
|
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) => {
|
|
581
642
|
if (el) {
|
|
582
|
-
el.indeterminate = isIndeterminate(row.id);
|
|
643
|
+
el.indeterminate = isIndeterminate(row.id, rows, selectedRows);
|
|
583
644
|
}
|
|
584
645
|
} }),
|
|
585
|
-
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" },
|
|
646
|
+
isIndeterminate(row.id, rows, selectedRows) ? (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" },
|
|
586
647
|
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" }))))))),
|
|
587
648
|
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" ||
|
|
588
649
|
item.type === "operation" ||
|
|
@@ -604,10 +665,10 @@ pageIndex = 0, // Default to first page (0-indexed)
|
|
|
604
665
|
react_1.default.createElement("div", { className: "relative flex items-center justify-center " },
|
|
605
666
|
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) => {
|
|
606
667
|
if (el) {
|
|
607
|
-
el.indeterminate = isIndeterminate(row.id);
|
|
668
|
+
el.indeterminate = isIndeterminate(row.id, rows, selectedRows);
|
|
608
669
|
}
|
|
609
670
|
} }),
|
|
610
|
-
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" },
|
|
671
|
+
isIndeterminate(row.id, rows, selectedRows) ? (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" },
|
|
611
672
|
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" })))))),
|
|
612
673
|
renderCellContent(item)))),
|
|
613
674
|
actions && (react_1.default.createElement("div", { className: `w-24 py-4 flex items-center justify-end text-sm font-medium ${actionButtonsStyle || ""}` },
|