gantt-lib 0.6.1 → 0.6.2
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.
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +35 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -521,6 +521,25 @@ function flattenHierarchy(tasks) {
|
|
|
521
521
|
}
|
|
522
522
|
return result;
|
|
523
523
|
}
|
|
524
|
+
function normalizeHierarchyTasks(tasks) {
|
|
525
|
+
const orderedTasks = flattenHierarchy(tasks).map((task) => ({ ...task }));
|
|
526
|
+
for (const task of [...orderedTasks].reverse()) {
|
|
527
|
+
if (!isTaskParent(task.id, orderedTasks)) continue;
|
|
528
|
+
const { startDate, endDate } = computeParentDates(task.id, orderedTasks);
|
|
529
|
+
const progress = computeParentProgress(task.id, orderedTasks);
|
|
530
|
+
const normalizedStartDate = startDate.toISOString().split("T")[0];
|
|
531
|
+
const normalizedEndDate = endDate.toISOString().split("T")[0];
|
|
532
|
+
const parentIndex = orderedTasks.findIndex((candidate) => candidate.id === task.id);
|
|
533
|
+
if (parentIndex === -1) continue;
|
|
534
|
+
orderedTasks[parentIndex] = {
|
|
535
|
+
...orderedTasks[parentIndex],
|
|
536
|
+
startDate: normalizedStartDate,
|
|
537
|
+
endDate: normalizedEndDate,
|
|
538
|
+
progress
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
return orderedTasks;
|
|
542
|
+
}
|
|
524
543
|
|
|
525
544
|
// src/components/TimeScaleHeader/TimeScaleHeader.tsx
|
|
526
545
|
import { useMemo } from "react";
|
|
@@ -3110,7 +3129,7 @@ var TaskList = ({
|
|
|
3110
3129
|
return next;
|
|
3111
3130
|
});
|
|
3112
3131
|
}, []);
|
|
3113
|
-
const orderedTasks = useMemo8(() =>
|
|
3132
|
+
const orderedTasks = useMemo8(() => normalizeHierarchyTasks(tasks), [tasks]);
|
|
3114
3133
|
const visibleTasks = useMemo8(() => {
|
|
3115
3134
|
return orderedTasks.filter((task) => {
|
|
3116
3135
|
if (!task.parentId) return true;
|
|
@@ -3521,21 +3540,21 @@ var GanttChart = forwardRef(({
|
|
|
3521
3540
|
const [selectedChip, setSelectedChip] = useState7(null);
|
|
3522
3541
|
const [collapsedParentIds, setCollapsedParentIds] = useState7(/* @__PURE__ */ new Set());
|
|
3523
3542
|
const [editingTaskId, setEditingTaskId] = useState7(null);
|
|
3524
|
-
const
|
|
3543
|
+
const normalizedTasks = useMemo9(() => normalizeHierarchyTasks(tasks), [tasks]);
|
|
3544
|
+
const dateRange = useMemo9(() => getMultiMonthDays(normalizedTasks), [normalizedTasks]);
|
|
3525
3545
|
const [validationResult, setValidationResult] = useState7(null);
|
|
3526
3546
|
const [cascadeOverrides, setCascadeOverrides] = useState7(/* @__PURE__ */ new Map());
|
|
3527
3547
|
const gridWidth = useMemo9(
|
|
3528
3548
|
() => Math.round(dateRange.length * dayWidth),
|
|
3529
3549
|
[dateRange.length, dayWidth]
|
|
3530
3550
|
);
|
|
3531
|
-
const orderedTasks = useMemo9(() => flattenHierarchy(tasks), [tasks]);
|
|
3532
3551
|
const filteredTasks = useMemo9(() => {
|
|
3533
|
-
return
|
|
3552
|
+
return normalizedTasks.filter((task) => {
|
|
3534
3553
|
if (!task.parentId) return true;
|
|
3535
3554
|
const parentCollapsed = collapsedParentIds.has(task.parentId);
|
|
3536
3555
|
return !parentCollapsed;
|
|
3537
3556
|
});
|
|
3538
|
-
}, [
|
|
3557
|
+
}, [normalizedTasks, collapsedParentIds]);
|
|
3539
3558
|
const totalGridHeight = useMemo9(
|
|
3540
3559
|
() => filteredTasks.length * rowHeight,
|
|
3541
3560
|
[filteredTasks.length, rowHeight]
|
|
@@ -3781,9 +3800,9 @@ var GanttChart = forwardRef(({
|
|
|
3781
3800
|
updatedCount: updated.length
|
|
3782
3801
|
});
|
|
3783
3802
|
console.log("=== GANTT CHART handleReorder END ===\n");
|
|
3784
|
-
return
|
|
3803
|
+
return normalizeHierarchyTasks(updated);
|
|
3785
3804
|
});
|
|
3786
|
-
onReorder?.(
|
|
3805
|
+
onReorder?.(normalizeHierarchyTasks(reorderedTasks), movedTaskId, inferredParentId);
|
|
3787
3806
|
}, [onChange, onReorder]);
|
|
3788
3807
|
const dependencyOverrides = useMemo9(() => {
|
|
3789
3808
|
const map = new Map(cascadeOverrides);
|
|
@@ -3850,13 +3869,13 @@ var GanttChart = forwardRef(({
|
|
|
3850
3869
|
const parentId = taskToPromote.parentId;
|
|
3851
3870
|
const siblings = currentTasks.filter((t) => t.parentId === parentId);
|
|
3852
3871
|
if (siblings.length <= 1) {
|
|
3853
|
-
return
|
|
3872
|
+
return normalizeHierarchyTasks(currentTasks.map(
|
|
3854
3873
|
(t) => t.id === taskId ? { ...t, parentId: void 0 } : t
|
|
3855
3874
|
));
|
|
3856
3875
|
}
|
|
3857
3876
|
const lastSiblingIndex = currentTasks.map((t, i) => ({ task: t, index: i })).filter(({ task }) => task.parentId === parentId).sort((a, b) => b.index - a.index)[0];
|
|
3858
3877
|
if (!lastSiblingIndex) {
|
|
3859
|
-
return
|
|
3878
|
+
return normalizeHierarchyTasks(currentTasks.map(
|
|
3860
3879
|
(t) => t.id === taskId ? { ...t, parentId: void 0 } : t
|
|
3861
3880
|
));
|
|
3862
3881
|
}
|
|
@@ -3868,7 +3887,7 @@ var GanttChart = forwardRef(({
|
|
|
3868
3887
|
promotedTask,
|
|
3869
3888
|
...withoutPromotedTask.slice(insertIndex)
|
|
3870
3889
|
];
|
|
3871
|
-
return
|
|
3890
|
+
return normalizeHierarchyTasks(newTasks);
|
|
3872
3891
|
});
|
|
3873
3892
|
}, [onChange]);
|
|
3874
3893
|
const handleDemoteTask = useCallback6((taskId, newParentId) => {
|
|
@@ -3901,7 +3920,7 @@ var GanttChart = forwardRef(({
|
|
|
3901
3920
|
updatedTasks = updatedTasks.map(
|
|
3902
3921
|
(t) => t.id === newParentId ? { ...t, startDate: parentDates.startDate.toISOString().split("T")[0], endDate: parentDates.endDate.toISOString().split("T")[0], progress: parentProgress } : t
|
|
3903
3922
|
);
|
|
3904
|
-
return
|
|
3923
|
+
return normalizeHierarchyTasks(updatedTasks);
|
|
3905
3924
|
});
|
|
3906
3925
|
}, [onChange]);
|
|
3907
3926
|
const panStateRef = useRef6(null);
|
|
@@ -3959,7 +3978,7 @@ var GanttChart = forwardRef(({
|
|
|
3959
3978
|
/* @__PURE__ */ jsx15(
|
|
3960
3979
|
TaskList,
|
|
3961
3980
|
{
|
|
3962
|
-
tasks:
|
|
3981
|
+
tasks: normalizedTasks,
|
|
3963
3982
|
rowHeight,
|
|
3964
3983
|
headerHeight,
|
|
3965
3984
|
taskListWidth,
|
|
@@ -4014,7 +4033,7 @@ var GanttChart = forwardRef(({
|
|
|
4014
4033
|
DependencyLines_default,
|
|
4015
4034
|
{
|
|
4016
4035
|
tasks: filteredTasks,
|
|
4017
|
-
allTasks:
|
|
4036
|
+
allTasks: normalizedTasks,
|
|
4018
4037
|
collapsedParentIds,
|
|
4019
4038
|
monthStart,
|
|
4020
4039
|
dayWidth,
|
|
@@ -4052,7 +4071,7 @@ var GanttChart = forwardRef(({
|
|
|
4052
4071
|
}
|
|
4053
4072
|
},
|
|
4054
4073
|
rowIndex: index,
|
|
4055
|
-
allTasks:
|
|
4074
|
+
allTasks: normalizedTasks,
|
|
4056
4075
|
enableAutoSchedule: enableAutoSchedule ?? false,
|
|
4057
4076
|
disableConstraints: disableConstraints ?? false,
|
|
4058
4077
|
overridePosition: cascadeOverrides.get(task.id),
|
|
@@ -4132,6 +4151,7 @@ export {
|
|
|
4132
4151
|
isTaskParent,
|
|
4133
4152
|
isToday,
|
|
4134
4153
|
isWeekend,
|
|
4154
|
+
normalizeHierarchyTasks,
|
|
4135
4155
|
parseUTCDate,
|
|
4136
4156
|
pixelsToDate,
|
|
4137
4157
|
recalculateIncomingLags,
|