gantt-lib 0.146.0 → 0.146.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/README.md +4 -0
- package/dist/core/scheduling/index.d.mts +1 -1
- package/dist/core/scheduling/index.d.ts +1 -1
- package/dist/core/scheduling/index.js +199 -19
- package/dist/core/scheduling/index.js.map +1 -1
- package/dist/core/scheduling/index.mjs +199 -19
- package/dist/core/scheduling/index.mjs.map +1 -1
- package/dist/{index-Cue-aV4x.d.mts → index-r9kDy05N.d.mts} +6 -3
- package/dist/{index-Cue-aV4x.d.ts → index-r9kDy05N.d.ts} +6 -3
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +242 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +242 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1335,6 +1335,7 @@ function clampTaskRangeForIncomingFS(task, proposedStart, proposedEnd, allTasks,
|
|
|
1335
1335
|
}
|
|
1336
1336
|
function recalculateIncomingLags(task, newStartDate, newEndDate, allTasks, businessDays = false, weekendPredicate, taskById) {
|
|
1337
1337
|
if (!task.dependencies) return [];
|
|
1338
|
+
if (task.fixedStartDate || task.fixedEndDate) return task.dependencies;
|
|
1338
1339
|
return task.dependencies.map((dep) => {
|
|
1339
1340
|
const predecessor = taskById?.get(dep.taskId) ?? allTasks.find((candidate) => candidate.id === dep.taskId);
|
|
1340
1341
|
if (!predecessor) {
|
|
@@ -1358,6 +1359,53 @@ function recalculateIncomingLags(task, newStartDate, newEndDate, allTasks, busin
|
|
|
1358
1359
|
});
|
|
1359
1360
|
}
|
|
1360
1361
|
|
|
1362
|
+
// src/core/scheduling/fixedDates.ts
|
|
1363
|
+
function resolveFixedDates(task, range, parent, businessDays = false, weekendPredicate, preserveDuration = true) {
|
|
1364
|
+
for (const value of [task.fixedStartDate, task.fixedEndDate]) {
|
|
1365
|
+
if (value && (!/^\d{4}-\d{2}-\d{2}$/.test(value) || Number.isNaN(Date.parse(value)) || new Date(value).toISOString().slice(0, 10) !== value)) {
|
|
1366
|
+
throw new Error(`Invalid fixed date on task ${task.id}`);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
const fixedStart = task.fixedStartDate ? parseDateOnly(task.fixedStartDate) : void 0;
|
|
1370
|
+
const fixedEnd = task.fixedEndDate ? parseDateOnly(task.fixedEndDate) : void 0;
|
|
1371
|
+
if (!fixedStart && !fixedEnd) return range;
|
|
1372
|
+
if (fixedStart && fixedEnd && (fixedStart > fixedEnd || task.type === "milestone" && +fixedStart !== +fixedEnd)) {
|
|
1373
|
+
throw new Error(`Fixed dates conflict on task ${task.id}`);
|
|
1374
|
+
}
|
|
1375
|
+
if (task.type === "milestone") {
|
|
1376
|
+
const date = fixedStart ?? fixedEnd;
|
|
1377
|
+
return { start: date, end: date };
|
|
1378
|
+
}
|
|
1379
|
+
if (fixedStart && fixedEnd) return { start: fixedStart, end: fixedEnd };
|
|
1380
|
+
if (!parent && preserveDuration) {
|
|
1381
|
+
const duration = getTaskDuration(task.startDate, task.endDate, businessDays, weekendPredicate);
|
|
1382
|
+
if (fixedStart) return { start: fixedStart, end: buildTaskRangeFromStart(fixedStart, duration, businessDays, weekendPredicate).end };
|
|
1383
|
+
return { start: buildTaskRangeFromEnd(fixedEnd, duration, businessDays, weekendPredicate).start, end: fixedEnd };
|
|
1384
|
+
}
|
|
1385
|
+
if (fixedStart) return { start: fixedStart, end: range.end < fixedStart ? fixedStart : range.end };
|
|
1386
|
+
return { start: range.start > fixedEnd ? fixedEnd : range.start, end: fixedEnd };
|
|
1387
|
+
}
|
|
1388
|
+
function resolveParentFixedDates(task, range, getTask, businessDays = false, weekendPredicate) {
|
|
1389
|
+
if (!task.fixedStartDate && !task.fixedEndDate) return range;
|
|
1390
|
+
let { start, end } = range;
|
|
1391
|
+
for (const dep of task.dependencies ?? []) {
|
|
1392
|
+
const targetStart = dep.type === "FS" || dep.type === "SS";
|
|
1393
|
+
if (targetStart ? task.fixedStartDate : task.fixedEndDate) continue;
|
|
1394
|
+
const predecessor = getTask(dep.taskId);
|
|
1395
|
+
if (!predecessor) continue;
|
|
1396
|
+
const anchor = predecessor.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : void 0;
|
|
1397
|
+
const { predStart, predEnd } = normalizePredecessorDates({
|
|
1398
|
+
...predecessor,
|
|
1399
|
+
startDate: anchor ?? predecessor.fixedStartDate ?? predecessor.startDate,
|
|
1400
|
+
endDate: anchor ?? predecessor.fixedEndDate ?? predecessor.endDate
|
|
1401
|
+
}, parseDateOnly);
|
|
1402
|
+
const date = calculateSuccessorDate(predStart, predEnd, dep.type, getDependencyLag(dep), businessDays, weekendPredicate, task.type);
|
|
1403
|
+
if (targetStart && date > start) start = date;
|
|
1404
|
+
if (!targetStart && date > end) end = date;
|
|
1405
|
+
}
|
|
1406
|
+
return resolveFixedDates(task, { start, end }, true, businessDays, weekendPredicate);
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1361
1409
|
// src/core/scheduling/cascade.ts
|
|
1362
1410
|
function parseCascadeDateInput(date) {
|
|
1363
1411
|
if (date instanceof Date) {
|
|
@@ -1546,8 +1594,11 @@ function getTransitiveCascadeChain(changedTaskId, allTasks, firstLevelLinkTypes)
|
|
|
1546
1594
|
}
|
|
1547
1595
|
return chain;
|
|
1548
1596
|
}
|
|
1549
|
-
function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays = false, weekendPredicate, context = createCascadeContext(allTasks)) {
|
|
1597
|
+
function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays = false, weekendPredicate, context = createCascadeContext(allTasks), rootIsRollup = false) {
|
|
1550
1598
|
const { childrenByParentId, dependentsByPredecessorId, taskById } = context;
|
|
1599
|
+
const originalMovedTask = taskById.get(movedTask.id) ?? movedTask;
|
|
1600
|
+
const sameDelta = +newStart - +parseDateOnly(originalMovedTask.startDate) === +newEnd - +parseDateOnly(originalMovedTask.endDate);
|
|
1601
|
+
({ start: newStart, end: newEnd } = resolveFixedDates(originalMovedTask, { start: newStart, end: newEnd }, childrenByParentId.has(movedTask.id), businessDays, weekendPredicate, sameDelta));
|
|
1551
1602
|
const normalizedMovedTask = normalizeTaskDependencyLags({
|
|
1552
1603
|
...movedTask,
|
|
1553
1604
|
startDate: newStart.toISOString().split("T")[0],
|
|
@@ -1560,7 +1611,12 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1560
1611
|
updatedDates.set(movedTask.id, { start: newStart, end: newEnd });
|
|
1561
1612
|
const resultMap = /* @__PURE__ */ new Map();
|
|
1562
1613
|
resultMap.set(movedTask.id, normalizedMovedTask);
|
|
1563
|
-
const
|
|
1614
|
+
const getCurrentTask = (id) => {
|
|
1615
|
+
const task = taskById.get(id);
|
|
1616
|
+
const range = updatedDates.get(id);
|
|
1617
|
+
return task && range ? { ...task, startDate: range.start, endDate: range.end } : task;
|
|
1618
|
+
};
|
|
1619
|
+
const queue = [[movedTask.id, rootIsRollup ? "parent-recalc" : "direct"]];
|
|
1564
1620
|
const childShifted = /* @__PURE__ */ new Set();
|
|
1565
1621
|
let iterations = 0;
|
|
1566
1622
|
const MAX_ITERATIONS = allTasks.length * 3;
|
|
@@ -1569,7 +1625,7 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1569
1625
|
const [currentId, arrivalMode] = queue.shift();
|
|
1570
1626
|
const { start: currStart, end: currEnd } = updatedDates.get(currentId);
|
|
1571
1627
|
const currentOriginal = taskById.get(currentId);
|
|
1572
|
-
if (arrivalMode !== "parent-recalc") {
|
|
1628
|
+
if (arrivalMode !== "parent-recalc" && !(arrivalMode === "dependency" && (currentOriginal.fixedStartDate || currentOriginal.fixedEndDate))) {
|
|
1573
1629
|
const children = childrenByParentId.get(currentId) ?? [];
|
|
1574
1630
|
for (const child of children) {
|
|
1575
1631
|
if (childShifted.has(child.id) || child.locked) continue;
|
|
@@ -1598,6 +1654,7 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1598
1654
|
childNewStart = new Date(childOrigStart.getTime() + startDeltaMs);
|
|
1599
1655
|
childNewEnd = new Date(childOrigEnd.getTime() + endDeltaMs);
|
|
1600
1656
|
}
|
|
1657
|
+
({ start: childNewStart, end: childNewEnd } = resolveFixedDates(child, { start: childNewStart, end: childNewEnd }, childrenByParentId.has(child.id), businessDays, weekendPredicate));
|
|
1601
1658
|
const prev = updatedDates.get(child.id);
|
|
1602
1659
|
if (prev && prev.start.getTime() === childNewStart.getTime() && prev.end.getTime() === childNewEnd.getTime()) {
|
|
1603
1660
|
continue;
|
|
@@ -1628,8 +1685,10 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1628
1685
|
if (updatedDates.has(sib.id)) return updatedDates.get(sib.id);
|
|
1629
1686
|
return { start: new Date(sib.startDate), end: new Date(sib.endDate) };
|
|
1630
1687
|
});
|
|
1631
|
-
const minStart
|
|
1632
|
-
|
|
1688
|
+
const { start: minStart, end: maxEnd } = resolveParentFixedDates(parent, {
|
|
1689
|
+
start: new Date(Math.min(...siblingPositions.map((p) => p.start.getTime()))),
|
|
1690
|
+
end: new Date(Math.max(...siblingPositions.map((p) => p.end.getTime())))
|
|
1691
|
+
}, getCurrentTask, businessDays, weekendPredicate);
|
|
1633
1692
|
const prev = updatedDates.get(parentId);
|
|
1634
1693
|
if (!prev || prev.start.getTime() !== minStart.getTime() || prev.end.getTime() !== maxEnd.getTime()) {
|
|
1635
1694
|
updatedDates.set(parentId, { start: minStart, end: maxEnd });
|
|
@@ -1685,6 +1744,15 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1685
1744
|
weekendPredicate
|
|
1686
1745
|
));
|
|
1687
1746
|
}
|
|
1747
|
+
const dependentChildren = childrenByParentId.get(task.id);
|
|
1748
|
+
if (dependentChildren?.length && (task.fixedStartDate || task.fixedEndDate)) {
|
|
1749
|
+
const positions = dependentChildren.map((child) => updatedDates.get(child.id) ?? { start: parseDateOnly(child.startDate), end: parseDateOnly(child.endDate) });
|
|
1750
|
+
({ start: succNewStart, end: succNewEnd } = resolveParentFixedDates(task, {
|
|
1751
|
+
start: new Date(Math.min(...positions.map((position) => +position.start))),
|
|
1752
|
+
end: new Date(Math.max(...positions.map((position) => +position.end)))
|
|
1753
|
+
}, getCurrentTask, businessDays, weekendPredicate));
|
|
1754
|
+
}
|
|
1755
|
+
({ start: succNewStart, end: succNewEnd } = resolveFixedDates(task, { start: succNewStart, end: succNewEnd }, !!dependentChildren?.length, businessDays, weekendPredicate));
|
|
1688
1756
|
const prev = updatedDates.get(task.id);
|
|
1689
1757
|
if (prev && prev.start.getTime() === succNewStart.getTime() && prev.end.getTime() === succNewEnd.getTime()) {
|
|
1690
1758
|
continue;
|
|
@@ -1714,22 +1782,23 @@ function getChildren(parentId, tasks) {
|
|
|
1714
1782
|
function isTaskParent(taskId, tasks) {
|
|
1715
1783
|
return tasks.some((t) => t.parentId === taskId);
|
|
1716
1784
|
}
|
|
1717
|
-
function computeParentDates(parentId, tasks) {
|
|
1785
|
+
function computeParentDates(parentId, tasks, businessDays = false, weekendPredicate) {
|
|
1718
1786
|
const children = getChildren(parentId, tasks);
|
|
1719
1787
|
if (children.length === 0) {
|
|
1720
|
-
const
|
|
1721
|
-
const start =
|
|
1722
|
-
const end =
|
|
1723
|
-
|
|
1788
|
+
const parent2 = tasks.find((t) => t.id === parentId);
|
|
1789
|
+
const start = parent2 ? new Date(parent2.startDate) : /* @__PURE__ */ new Date();
|
|
1790
|
+
const end = parent2 ? new Date(parent2.endDate) : /* @__PURE__ */ new Date();
|
|
1791
|
+
const range2 = parent2 ? resolveFixedDates(parent2, { start, end }, false) : { start, end };
|
|
1792
|
+
return { startDate: range2.start, endDate: range2.end };
|
|
1724
1793
|
}
|
|
1725
1794
|
const startDates = children.map((c) => new Date(c.startDate));
|
|
1726
1795
|
const endDates = children.map((c) => new Date(c.endDate));
|
|
1727
1796
|
const minTime = Math.min(...startDates.map((d) => d.getTime()));
|
|
1728
1797
|
const maxTime = Math.max(...endDates.map((d) => d.getTime()));
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
};
|
|
1798
|
+
const parent = tasks.find((t) => t.id === parentId);
|
|
1799
|
+
const range = { start: new Date(minTime), end: new Date(maxTime) };
|
|
1800
|
+
const resolved = parent ? resolveParentFixedDates(parent, range, (id) => tasks.find((task) => task.id === id), businessDays, weekendPredicate) : range;
|
|
1801
|
+
return { startDate: resolved.start, endDate: resolved.end };
|
|
1733
1802
|
}
|
|
1734
1803
|
function computeParentProgress(parentId, tasks) {
|
|
1735
1804
|
const children = getChildren(parentId, tasks);
|
|
@@ -1860,13 +1929,14 @@ function moveTaskWithCascade(taskId, newStart, snapshot, options) {
|
|
|
1860
1929
|
}
|
|
1861
1930
|
const businessDays = options?.businessDays ?? false;
|
|
1862
1931
|
const weekendPredicate = options?.weekendPredicate;
|
|
1863
|
-
|
|
1932
|
+
let newRange = moveTaskRange(
|
|
1864
1933
|
task.startDate,
|
|
1865
1934
|
task.endDate,
|
|
1866
1935
|
newStart,
|
|
1867
1936
|
businessDays,
|
|
1868
1937
|
weekendPredicate
|
|
1869
1938
|
);
|
|
1939
|
+
newRange = resolveFixedDates(task, newRange, snapshot.some((t) => t.parentId === task.id), businessDays, weekendPredicate);
|
|
1870
1940
|
const updatedDependencies = recalculateIncomingLags(
|
|
1871
1941
|
task,
|
|
1872
1942
|
newRange.start,
|
|
@@ -1921,6 +1991,7 @@ function resizeTaskWithCascade(taskId, anchor, newDate, snapshot, options) {
|
|
|
1921
1991
|
} else {
|
|
1922
1992
|
newRange = { start: newDate, end: originalEnd };
|
|
1923
1993
|
}
|
|
1994
|
+
newRange = resolveFixedDates(task, newRange, snapshot.some((t) => t.parentId === task.id), businessDays, weekendPredicate, false);
|
|
1924
1995
|
const updatedDependencies = recalculateIncomingLags(
|
|
1925
1996
|
task,
|
|
1926
1997
|
newRange.start,
|
|
@@ -2011,6 +2082,14 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
|
|
|
2011
2082
|
changedIds: [task.id]
|
|
2012
2083
|
};
|
|
2013
2084
|
}
|
|
2085
|
+
const fixedParent = !!(task.fixedStartDate || task.fixedEndDate) && snapshot.some((t) => t.parentId === task.id);
|
|
2086
|
+
if (fixedParent) {
|
|
2087
|
+
const rollup = computeParentDates(task.id, snapshot, businessDays, weekendPredicate);
|
|
2088
|
+
constrainedStart = rollup.startDate;
|
|
2089
|
+
constrainedEnd = rollup.endDate;
|
|
2090
|
+
} else {
|
|
2091
|
+
({ start: constrainedStart, end: constrainedEnd } = resolveFixedDates(task, { start: constrainedStart, end: constrainedEnd }, false, businessDays, weekendPredicate));
|
|
2092
|
+
}
|
|
2014
2093
|
const updatedDependencies = recalculateIncomingLags(
|
|
2015
2094
|
task,
|
|
2016
2095
|
constrainedStart,
|
|
@@ -2037,7 +2116,9 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
|
|
|
2037
2116
|
constrainedEnd,
|
|
2038
2117
|
snapshot,
|
|
2039
2118
|
businessDays,
|
|
2040
|
-
weekendPredicate
|
|
2119
|
+
weekendPredicate,
|
|
2120
|
+
void 0,
|
|
2121
|
+
fixedParent
|
|
2041
2122
|
);
|
|
2042
2123
|
const resultMap = /* @__PURE__ */ new Map();
|
|
2043
2124
|
resultMap.set(recalculatedTask.id, recalculatedTask);
|
|
@@ -2051,6 +2132,100 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
|
|
|
2051
2132
|
};
|
|
2052
2133
|
}
|
|
2053
2134
|
function recalculateProjectSchedule(snapshot, options) {
|
|
2135
|
+
if (snapshot.some((task) => task.fixedStartDate || task.fixedEndDate)) {
|
|
2136
|
+
return recalculateFixedComponents(snapshot, options);
|
|
2137
|
+
}
|
|
2138
|
+
return recalculateProjectScheduleLegacy(snapshot, options);
|
|
2139
|
+
}
|
|
2140
|
+
function recalculateFixedComponents(snapshot, options) {
|
|
2141
|
+
const businessDays = options?.businessDays ?? false;
|
|
2142
|
+
const weekendPredicate = options?.weekendPredicate;
|
|
2143
|
+
const initial = new Map(snapshot.map((task) => [task.id, task]));
|
|
2144
|
+
const next = new Map(snapshot.map((task) => [task.id, task]));
|
|
2145
|
+
const children = /* @__PURE__ */ new Map();
|
|
2146
|
+
const outgoing = new Map(snapshot.map((task) => [task.id, /* @__PURE__ */ new Set()]));
|
|
2147
|
+
const neighbours = new Map(snapshot.map((task) => [task.id, /* @__PURE__ */ new Set()]));
|
|
2148
|
+
const connect = (from, to, ordered = true) => {
|
|
2149
|
+
if (!initial.has(from) || !initial.has(to)) return;
|
|
2150
|
+
if (ordered) outgoing.get(from).add(to);
|
|
2151
|
+
neighbours.get(from).add(to);
|
|
2152
|
+
neighbours.get(to).add(from);
|
|
2153
|
+
};
|
|
2154
|
+
for (const task of snapshot) {
|
|
2155
|
+
if (task.parentId && initial.has(task.parentId)) {
|
|
2156
|
+
const list = children.get(task.parentId) ?? [];
|
|
2157
|
+
list.push(task.id);
|
|
2158
|
+
children.set(task.parentId, list);
|
|
2159
|
+
connect(task.id, task.parentId);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
for (const task of snapshot) {
|
|
2163
|
+
for (const dependency of task.dependencies ?? []) {
|
|
2164
|
+
const predecessor = initial.get(dependency.taskId);
|
|
2165
|
+
const fixedSource = predecessor?.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : dependency.type === "FS" || dependency.type === "FF" ? predecessor?.fixedEndDate : predecessor?.fixedStartDate;
|
|
2166
|
+
const targetFixed = dependency.type === "FS" || dependency.type === "SS" ? task.fixedStartDate : task.fixedEndDate;
|
|
2167
|
+
const derivedParent = children.has(task.id) && !task.fixedStartDate && !task.fixedEndDate;
|
|
2168
|
+
connect(dependency.taskId, task.id, !fixedSource && !targetFixed && !derivedParent);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
const affected = new Set(snapshot.filter((task) => task.fixedStartDate || task.fixedEndDate).map((task) => task.id));
|
|
2172
|
+
const pending = [...affected];
|
|
2173
|
+
for (let i = 0; i < pending.length; i++) {
|
|
2174
|
+
for (const id of neighbours.get(pending[i])) if (!affected.has(id)) {
|
|
2175
|
+
affected.add(id);
|
|
2176
|
+
pending.push(id);
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
const indegree = new Map([...affected].map((id) => [id, 0]));
|
|
2180
|
+
for (const id of affected) for (const successor of outgoing.get(id)) {
|
|
2181
|
+
indegree.set(successor, indegree.get(successor) + 1);
|
|
2182
|
+
}
|
|
2183
|
+
const queue = [...affected].filter((id) => indegree.get(id) === 0);
|
|
2184
|
+
for (let i = 0; i < queue.length; i++) {
|
|
2185
|
+
const id = queue[i];
|
|
2186
|
+
const task = next.get(id);
|
|
2187
|
+
const childIds = children.get(id);
|
|
2188
|
+
if (!task.locked) {
|
|
2189
|
+
let range = { start: parseDateOnly(task.startDate), end: parseDateOnly(task.endDate) };
|
|
2190
|
+
if (childIds?.length) {
|
|
2191
|
+
range = {
|
|
2192
|
+
start: new Date(Math.min(...childIds.map((child) => +parseDateOnly(next.get(child).startDate)))),
|
|
2193
|
+
end: new Date(Math.max(...childIds.map((child) => +parseDateOnly(next.get(child).endDate))))
|
|
2194
|
+
};
|
|
2195
|
+
range = resolveParentFixedDates(task, range, (key) => next.get(key), businessDays, weekendPredicate);
|
|
2196
|
+
} else if (task.dependencies?.length) {
|
|
2197
|
+
const duration = getTaskDuration(task.startDate, task.endDate, businessDays, weekendPredicate);
|
|
2198
|
+
let selected;
|
|
2199
|
+
for (const dependency of task.dependencies) {
|
|
2200
|
+
const predecessor = next.get(dependency.taskId);
|
|
2201
|
+
if (!predecessor) continue;
|
|
2202
|
+
const milestoneAnchor = predecessor.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : void 0;
|
|
2203
|
+
const { predStart, predEnd } = normalizePredecessorDates({
|
|
2204
|
+
...predecessor,
|
|
2205
|
+
startDate: milestoneAnchor ?? predecessor.fixedStartDate ?? predecessor.startDate,
|
|
2206
|
+
endDate: milestoneAnchor ?? predecessor.fixedEndDate ?? predecessor.endDate
|
|
2207
|
+
}, parseDateOnly);
|
|
2208
|
+
const date = calculateSuccessorDate(predStart, predEnd, dependency.type, getDependencyLag(dependency), businessDays, weekendPredicate, task.type);
|
|
2209
|
+
const candidate = dependency.type === "FS" || dependency.type === "SS" ? buildTaskRangeFromStart(date, duration, businessDays, weekendPredicate) : buildTaskRangeFromEnd(date, duration, businessDays, weekendPredicate);
|
|
2210
|
+
if (!selected || candidate.start > selected.start || +candidate.start === +selected.start && candidate.end > selected.end) selected = candidate;
|
|
2211
|
+
}
|
|
2212
|
+
if (selected) range = selected;
|
|
2213
|
+
}
|
|
2214
|
+
range = resolveFixedDates(task, range, !!childIds?.length, businessDays, weekendPredicate);
|
|
2215
|
+
next.set(id, { ...task, startDate: toIsoDate(range.start), endDate: toIsoDate(range.end) });
|
|
2216
|
+
}
|
|
2217
|
+
for (const successor of outgoing.get(id)) {
|
|
2218
|
+
indegree.set(successor, indegree.get(successor) - 1);
|
|
2219
|
+
if (indegree.get(successor) === 0) queue.push(successor);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
if (queue.length !== affected.size) throw new Error("Fixed date schedule contains a hierarchy/dependency cycle");
|
|
2223
|
+
for (const task of recalculateProjectScheduleLegacy(snapshot, options).changedTasks) {
|
|
2224
|
+
if (!affected.has(task.id)) next.set(task.id, task);
|
|
2225
|
+
}
|
|
2226
|
+
return createChangedResult(snapshot, [...next.values()]);
|
|
2227
|
+
}
|
|
2228
|
+
function recalculateProjectScheduleLegacy(snapshot, options) {
|
|
2054
2229
|
const businessDays = options?.businessDays ?? false;
|
|
2055
2230
|
const weekendPredicate = options?.weekendPredicate;
|
|
2056
2231
|
const workingMap = new Map(snapshot.map((task) => [task.id, { ...task }]));
|
|
@@ -2174,12 +2349,13 @@ function reflowTasksOnModeSwitch(sourceTasks, toBusinessDays, weekendPredicate)
|
|
|
2174
2349
|
true,
|
|
2175
2350
|
weekendPredicate
|
|
2176
2351
|
) : buildTaskRangeFromStart(start, duration, false);
|
|
2177
|
-
|
|
2178
|
-
task.
|
|
2352
|
+
const resolved = resolveFixedDates(task, range, false, toBusinessDays, weekendPredicate);
|
|
2353
|
+
task.startDate = toISO(resolved.start);
|
|
2354
|
+
task.endDate = toISO(resolved.end);
|
|
2179
2355
|
}
|
|
2180
2356
|
for (const task of tasks) {
|
|
2181
2357
|
if (!isTaskParent(task.id, tasks)) continue;
|
|
2182
|
-
const { startDate, endDate } = computeParentDates(task.id, tasks);
|
|
2358
|
+
const { startDate, endDate } = computeParentDates(task.id, tasks, toBusinessDays, weekendPredicate);
|
|
2183
2359
|
task.startDate = toISO(startDate);
|
|
2184
2360
|
task.endDate = toISO(endDate);
|
|
2185
2361
|
}
|
|
@@ -3367,6 +3543,10 @@ function scaleTaskSubtreeDuration(parentId, targetDuration, snapshot, options) {
|
|
|
3367
3543
|
const { context: ctx, space } = built;
|
|
3368
3544
|
const solved = solveScale(ctx, space, targetDuration);
|
|
3369
3545
|
const finalTasks = buildFinalTasks(ctx, solved.state, solved.layout, space);
|
|
3546
|
+
const fixedConflicts = [...finalTasks.values()].filter((task) => task.fixedStartDate && isoOfTaskDate(task.startDate) !== task.fixedStartDate || task.fixedEndDate && isoOfTaskDate(task.endDate) !== task.fixedEndDate);
|
|
3547
|
+
if (fixedConflicts.length) {
|
|
3548
|
+
return scaleFailure("FIXED_DATE_CONFLICT", fixedConflicts.map((task) => task.id));
|
|
3549
|
+
}
|
|
3370
3550
|
const externalPolicy = resolvedOptions.externalDependencyPolicy ?? "subtree-only";
|
|
3371
3551
|
let externalChanged = [];
|
|
3372
3552
|
if (externalPolicy === "subtree-only") {
|
|
@@ -3456,16 +3636,22 @@ function flattenHierarchy(tasks) {
|
|
|
3456
3636
|
}
|
|
3457
3637
|
return result;
|
|
3458
3638
|
}
|
|
3459
|
-
function normalizeHierarchyTasks(tasks) {
|
|
3639
|
+
function normalizeHierarchyTasks(tasks, businessDays = false, weekendPredicate) {
|
|
3640
|
+
const parentIds = new Set(tasks.map((task) => task.parentId).filter(Boolean));
|
|
3460
3641
|
const orderedTasks = flattenHierarchy(tasks).map((task) => {
|
|
3461
3642
|
const bounds = activityBounds(task.activities);
|
|
3462
3643
|
const { startDate, endDate } = normalizeTaskDates(
|
|
3463
3644
|
bounds?.startDate ?? task.startDate,
|
|
3464
3645
|
bounds?.endDate ?? task.endDate
|
|
3465
3646
|
);
|
|
3466
|
-
|
|
3647
|
+
if (!task.fixedStartDate && !task.fixedEndDate) {
|
|
3648
|
+
return { ...task, startDate, endDate };
|
|
3649
|
+
}
|
|
3650
|
+
const range = resolveFixedDates(task, { start: new Date(startDate), end: new Date(endDate) }, parentIds.has(task.id));
|
|
3651
|
+
return { ...task, startDate: range.start.toISOString().slice(0, 10), endDate: range.end.toISOString().slice(0, 10) };
|
|
3467
3652
|
});
|
|
3468
3653
|
const childrenByParent = /* @__PURE__ */ new Map();
|
|
3654
|
+
const taskIndex = new Map(orderedTasks.map((task, index) => [task.id, index]));
|
|
3469
3655
|
for (let index = 0; index < orderedTasks.length; index++) {
|
|
3470
3656
|
const parentId = orderedTasks[index].parentId;
|
|
3471
3657
|
if (!parentId) continue;
|
|
@@ -3491,10 +3677,14 @@ function normalizeHierarchyTasks(tasks) {
|
|
|
3491
3677
|
totalWeight += duration;
|
|
3492
3678
|
weightedProgress += duration * (child.progress ?? 0);
|
|
3493
3679
|
}
|
|
3680
|
+
const range = resolveParentFixedDates(orderedTasks[index], { start: new Date(minStart), end: new Date(maxEnd) }, (id) => {
|
|
3681
|
+
const predecessorIndex = taskIndex.get(id);
|
|
3682
|
+
return predecessorIndex === void 0 ? void 0 : orderedTasks[predecessorIndex];
|
|
3683
|
+
}, businessDays, weekendPredicate);
|
|
3494
3684
|
orderedTasks[index] = {
|
|
3495
3685
|
...orderedTasks[index],
|
|
3496
|
-
startDate:
|
|
3497
|
-
endDate:
|
|
3686
|
+
startDate: range.start.toISOString().split("T")[0],
|
|
3687
|
+
endDate: range.end.toISOString().split("T")[0],
|
|
3498
3688
|
progress: orderedTasks[index].progressAggregation === "manual" ? orderedTasks[index].progress : totalWeight === 0 ? 0 : Math.round(weightedProgress / totalWeight * 10) / 10
|
|
3499
3689
|
};
|
|
3500
3690
|
}
|
|
@@ -3789,6 +3979,10 @@ import { useEffect, useRef, useState, useCallback } from "react";
|
|
|
3789
3979
|
|
|
3790
3980
|
// src/adapters/scheduling/drag.ts
|
|
3791
3981
|
function resolveDateRangeFromPixels(mode, left, width, monthStart, dayWidth, task, businessDays, weekendPredicate) {
|
|
3982
|
+
const range = resolveDateRangeFromPixelsRaw(mode, left, width, monthStart, dayWidth, task, businessDays, weekendPredicate);
|
|
3983
|
+
return resolveFixedDates(task, range, false, businessDays, weekendPredicate, mode === "move");
|
|
3984
|
+
}
|
|
3985
|
+
function resolveDateRangeFromPixelsRaw(mode, left, width, monthStart, dayWidth, task, businessDays, weekendPredicate) {
|
|
3792
3986
|
const dayOffset = Math.round(left / dayWidth);
|
|
3793
3987
|
const rawStartDate = new Date(Date.UTC(
|
|
3794
3988
|
monthStart.getUTCFullYear(),
|
|
@@ -3843,10 +4037,10 @@ function resolveDateRangeFromPixels(mode, left, width, monthStart, dayWidth, tas
|
|
|
3843
4037
|
return buildTaskRangeFromEnd(fixedEnd, duration, true, weekendPredicate);
|
|
3844
4038
|
}
|
|
3845
4039
|
function clampDateRangeForIncomingFS(task, range, allTasks, mode, businessDays, weekendPredicate, taskById) {
|
|
3846
|
-
if (mode === "resize-right") {
|
|
4040
|
+
if (mode === "resize-right" || task.fixedStartDate || task.type === "milestone" && task.fixedEndDate) {
|
|
3847
4041
|
return range;
|
|
3848
4042
|
}
|
|
3849
|
-
|
|
4043
|
+
const clamped = clampTaskRangeForIncomingFS(
|
|
3850
4044
|
task,
|
|
3851
4045
|
range.start,
|
|
3852
4046
|
range.end,
|
|
@@ -3855,6 +4049,7 @@ function clampDateRangeForIncomingFS(task, range, allTasks, mode, businessDays,
|
|
|
3855
4049
|
weekendPredicate,
|
|
3856
4050
|
taskById
|
|
3857
4051
|
);
|
|
4052
|
+
return resolveFixedDates(task, clamped, false, businessDays, weekendPredicate, mode === "move");
|
|
3858
4053
|
}
|
|
3859
4054
|
|
|
3860
4055
|
// src/hooks/useTaskDrag.ts
|
|
@@ -4009,7 +4204,7 @@ function handleGlobalMouseMove(e) {
|
|
|
4009
4204
|
const { dayWidth: dw, monthStart: mStart } = activeDrag;
|
|
4010
4205
|
const previewRange = resolveDragRangeForInteraction(activeDrag, draggedTask, mode, newLeft, newWidth);
|
|
4011
4206
|
const anchor = mode === "resize-left" ? "end" : "start";
|
|
4012
|
-
const parentRange = computeParentDates(activeDrag.taskId, allTasks);
|
|
4207
|
+
const parentRange = computeParentDates(activeDrag.taskId, allTasks, activeDrag.businessDays, activeDrag.weekendPredicate);
|
|
4013
4208
|
const targetDuration = Math.max(1, getTaskDuration(
|
|
4014
4209
|
anchor === "start" ? parentRange.startDate : previewRange.start,
|
|
4015
4210
|
anchor === "start" ? previewRange.end : parentRange.endDate,
|
|
@@ -4345,7 +4540,7 @@ var useTaskDrag = (options) => {
|
|
|
4345
4540
|
});
|
|
4346
4541
|
} else if (currentTask && isTaskParent(taskId, allTasks)) {
|
|
4347
4542
|
const anchor = finalMode === "resize-left" ? "end" : "start";
|
|
4348
|
-
const parentRange = computeParentDates(taskId, allTasks);
|
|
4543
|
+
const parentRange = computeParentDates(taskId, allTasks, businessDays, weekendPredicate);
|
|
4349
4544
|
const targetDuration = getTaskDuration(
|
|
4350
4545
|
anchor === "start" ? parentRange.startDate : newStartDate,
|
|
4351
4546
|
anchor === "start" ? newEndDate : parentRange.endDate,
|
|
@@ -6282,6 +6477,7 @@ var DependencyLines = React6.memo(({
|
|
|
6282
6477
|
const positionedTaskIds = Array.from(taskPositions.keys());
|
|
6283
6478
|
const renderedTaskIdSet = new Set(geometryTasks.map((t) => t.id));
|
|
6284
6479
|
const lines2 = [];
|
|
6480
|
+
const renderedEdgeKeys = /* @__PURE__ */ new Set();
|
|
6285
6481
|
for (const successorId of positionedTaskIds) {
|
|
6286
6482
|
const successorTaskForEdges = taskMap.get(successorId);
|
|
6287
6483
|
if (!successorTaskForEdges?.dependencies?.length) {
|
|
@@ -6298,6 +6494,9 @@ var DependencyLines = React6.memo(({
|
|
|
6298
6494
|
type: dependency.type,
|
|
6299
6495
|
lag: dependency.lag ?? 0
|
|
6300
6496
|
};
|
|
6497
|
+
const renderKey = JSON.stringify([edge.predecessorId, edge.successorId, edge.type, edge.lag]);
|
|
6498
|
+
if (renderedEdgeKeys.has(renderKey)) continue;
|
|
6499
|
+
renderedEdgeKeys.add(renderKey);
|
|
6301
6500
|
const predecessor = taskPositions.get(edge.predecessorId);
|
|
6302
6501
|
const successor = taskPositions.get(edge.successorId);
|
|
6303
6502
|
const predecessorIndex = taskIndices.get(edge.predecessorId);
|
|
@@ -6358,6 +6557,7 @@ var DependencyLines = React6.memo(({
|
|
|
6358
6557
|
);
|
|
6359
6558
|
lines2.push({
|
|
6360
6559
|
id: `${edge.predecessorId}-${edge.successorId}-${edge.type}`,
|
|
6560
|
+
renderKey,
|
|
6361
6561
|
predecessorId: edge.predecessorId,
|
|
6362
6562
|
successorId: edge.successorId,
|
|
6363
6563
|
linkType: edge.type,
|
|
@@ -6506,7 +6706,7 @@ var DependencyLines = React6.memo(({
|
|
|
6506
6706
|
onLineLeave: handleLineLeave,
|
|
6507
6707
|
onDependencyClick
|
|
6508
6708
|
},
|
|
6509
|
-
line.
|
|
6709
|
+
line.renderKey
|
|
6510
6710
|
);
|
|
6511
6711
|
})
|
|
6512
6712
|
]
|
|
@@ -10242,13 +10442,13 @@ var TaskList = ({
|
|
|
10242
10442
|
return next;
|
|
10243
10443
|
});
|
|
10244
10444
|
}, []);
|
|
10245
|
-
const orderedTasks = useMemo10(() => {
|
|
10246
|
-
return normalizeHierarchyTasks(tasks);
|
|
10247
|
-
}, [tasks]);
|
|
10248
10445
|
const weekendPredicate = useMemo10(
|
|
10249
10446
|
() => createCustomDayPredicate({ customDays, isWeekend: isWeekend3 }),
|
|
10250
10447
|
[customDays, isWeekend3]
|
|
10251
10448
|
);
|
|
10449
|
+
const orderedTasks = useMemo10(() => {
|
|
10450
|
+
return normalizeHierarchyTasks(tasks, businessDays, weekendPredicate);
|
|
10451
|
+
}, [tasks, businessDays, weekendPredicate]);
|
|
10252
10452
|
const visibleTasks = useMemo10(() => {
|
|
10253
10453
|
const parentMap = new Map(orderedTasks.map((t) => [t.id, t.parentId]));
|
|
10254
10454
|
function isAnyAncestorCollapsed(parentId) {
|
|
@@ -15557,8 +15757,12 @@ function TaskGanttChartInner(props, ref) {
|
|
|
15557
15757
|
() => rowContentLines === 0 && !isPlanFactMode ? rowHeight : Math.max(rowHeight, 10 + resolvedRowContentLines * 18),
|
|
15558
15758
|
[isPlanFactMode, resolvedRowContentLines, rowContentLines, rowHeight]
|
|
15559
15759
|
);
|
|
15760
|
+
const isCustomWeekend = useMemo14(
|
|
15761
|
+
() => createCustomDayPredicate({ customDays, isWeekend: isWeekend3 }),
|
|
15762
|
+
[customDays, isWeekend3]
|
|
15763
|
+
);
|
|
15560
15764
|
const normalizedTasks = useMemo14(() => {
|
|
15561
|
-
const ordered = normalizeHierarchyTasks(tasks);
|
|
15765
|
+
const ordered = normalizeHierarchyTasks(tasks, businessDays, isCustomWeekend);
|
|
15562
15766
|
const ranges = /* @__PURE__ */ new Map();
|
|
15563
15767
|
for (const task of ordered) {
|
|
15564
15768
|
if (!task.parentId) continue;
|
|
@@ -15571,14 +15775,14 @@ function TaskGanttChartInner(props, ref) {
|
|
|
15571
15775
|
});
|
|
15572
15776
|
}
|
|
15573
15777
|
return ordered.map((task) => {
|
|
15574
|
-
const range = task.composite ? ranges.get(task.id) : void 0;
|
|
15778
|
+
const range = task.composite && !task.fixedStartDate && !task.fixedEndDate ? ranges.get(task.id) : void 0;
|
|
15575
15779
|
return range ? {
|
|
15576
15780
|
...task,
|
|
15577
15781
|
startDate: new Date(range.start).toISOString().slice(0, 10),
|
|
15578
15782
|
endDate: new Date(range.end).toISOString().slice(0, 10)
|
|
15579
15783
|
} : task;
|
|
15580
15784
|
});
|
|
15581
|
-
}, [tasks]);
|
|
15785
|
+
}, [tasks, businessDays, isCustomWeekend]);
|
|
15582
15786
|
const collapsedParentIds = useMemo14(() => {
|
|
15583
15787
|
if (externalCollapsedParentIds) return externalCollapsedParentIds;
|
|
15584
15788
|
const ids = new Set(internalCollapsedParentIds);
|
|
@@ -15598,10 +15802,6 @@ function TaskGanttChartInner(props, ref) {
|
|
|
15598
15802
|
if (controlledScheduleChanged || previewTasksById.size === 0) return normalizedTasks;
|
|
15599
15803
|
return normalizedTasks.map((task) => previewTasksById.get(task.id) ?? task);
|
|
15600
15804
|
}, [controlledScheduleChanged, normalizedTasks, previewTasksById]);
|
|
15601
|
-
const isCustomWeekend = useMemo14(
|
|
15602
|
-
() => createCustomDayPredicate({ customDays, isWeekend: isWeekend3 }),
|
|
15603
|
-
[customDays, isWeekend3]
|
|
15604
|
-
);
|
|
15605
15805
|
const criticalTaskIds = useMemo14(() => {
|
|
15606
15806
|
if (!criticalPathMode) return /* @__PURE__ */ new Set();
|
|
15607
15807
|
const leafCritical = computeCriticalPath(previewNormalizedTasks, {
|
|
@@ -16131,13 +16331,13 @@ function TaskGanttChartInner(props, ref) {
|
|
|
16131
16331
|
...task,
|
|
16132
16332
|
sortOrder: index
|
|
16133
16333
|
}));
|
|
16134
|
-
const normalized = normalizeHierarchyTasks(orderedForCallback);
|
|
16334
|
+
const normalized = normalizeHierarchyTasks(orderedForCallback, businessDays, isCustomWeekend);
|
|
16135
16335
|
if (onReorder) {
|
|
16136
16336
|
onReorder(normalized, movedTaskId, inferredParentId);
|
|
16137
16337
|
return;
|
|
16138
16338
|
}
|
|
16139
16339
|
onTasksChange?.(normalized);
|
|
16140
|
-
}, [onTasksChange, onReorder]);
|
|
16340
|
+
}, [onTasksChange, onReorder, businessDays, isCustomWeekend]);
|
|
16141
16341
|
const dependencyOverrides = useMemo14(() => {
|
|
16142
16342
|
if (controlledScheduleChanged) return /* @__PURE__ */ new Map();
|
|
16143
16343
|
const map = new Map(cascadeOverrides);
|
|
@@ -16449,9 +16649,9 @@ function TaskGanttChartInner(props, ref) {
|
|
|
16449
16649
|
...tasksWithoutPromoted.slice(0, insertIndex),
|
|
16450
16650
|
promotedTask,
|
|
16451
16651
|
...tasksWithoutPromoted.slice(insertIndex)
|
|
16452
|
-
]);
|
|
16652
|
+
], businessDays, isCustomWeekend);
|
|
16453
16653
|
onTasksChange?.(reorderedTasks);
|
|
16454
|
-
}, [tasks, onTasksChange, onPromoteTask]);
|
|
16654
|
+
}, [tasks, onTasksChange, onPromoteTask, businessDays, isCustomWeekend]);
|
|
16455
16655
|
const handleDemoteTask = useCallback11((taskId, newParentId) => {
|
|
16456
16656
|
if (onDemoteTask) {
|
|
16457
16657
|
onDemoteTask(taskId, newParentId);
|