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.js
CHANGED
|
@@ -1498,6 +1498,7 @@ function clampTaskRangeForIncomingFS(task, proposedStart, proposedEnd, allTasks,
|
|
|
1498
1498
|
}
|
|
1499
1499
|
function recalculateIncomingLags(task, newStartDate, newEndDate, allTasks, businessDays = false, weekendPredicate, taskById) {
|
|
1500
1500
|
if (!task.dependencies) return [];
|
|
1501
|
+
if (task.fixedStartDate || task.fixedEndDate) return task.dependencies;
|
|
1501
1502
|
return task.dependencies.map((dep) => {
|
|
1502
1503
|
const predecessor = taskById?.get(dep.taskId) ?? allTasks.find((candidate) => candidate.id === dep.taskId);
|
|
1503
1504
|
if (!predecessor) {
|
|
@@ -1521,6 +1522,53 @@ function recalculateIncomingLags(task, newStartDate, newEndDate, allTasks, busin
|
|
|
1521
1522
|
});
|
|
1522
1523
|
}
|
|
1523
1524
|
|
|
1525
|
+
// src/core/scheduling/fixedDates.ts
|
|
1526
|
+
function resolveFixedDates(task, range, parent, businessDays = false, weekendPredicate, preserveDuration = true) {
|
|
1527
|
+
for (const value of [task.fixedStartDate, task.fixedEndDate]) {
|
|
1528
|
+
if (value && (!/^\d{4}-\d{2}-\d{2}$/.test(value) || Number.isNaN(Date.parse(value)) || new Date(value).toISOString().slice(0, 10) !== value)) {
|
|
1529
|
+
throw new Error(`Invalid fixed date on task ${task.id}`);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
const fixedStart = task.fixedStartDate ? parseDateOnly(task.fixedStartDate) : void 0;
|
|
1533
|
+
const fixedEnd = task.fixedEndDate ? parseDateOnly(task.fixedEndDate) : void 0;
|
|
1534
|
+
if (!fixedStart && !fixedEnd) return range;
|
|
1535
|
+
if (fixedStart && fixedEnd && (fixedStart > fixedEnd || task.type === "milestone" && +fixedStart !== +fixedEnd)) {
|
|
1536
|
+
throw new Error(`Fixed dates conflict on task ${task.id}`);
|
|
1537
|
+
}
|
|
1538
|
+
if (task.type === "milestone") {
|
|
1539
|
+
const date = fixedStart ?? fixedEnd;
|
|
1540
|
+
return { start: date, end: date };
|
|
1541
|
+
}
|
|
1542
|
+
if (fixedStart && fixedEnd) return { start: fixedStart, end: fixedEnd };
|
|
1543
|
+
if (!parent && preserveDuration) {
|
|
1544
|
+
const duration = getTaskDuration(task.startDate, task.endDate, businessDays, weekendPredicate);
|
|
1545
|
+
if (fixedStart) return { start: fixedStart, end: buildTaskRangeFromStart(fixedStart, duration, businessDays, weekendPredicate).end };
|
|
1546
|
+
return { start: buildTaskRangeFromEnd(fixedEnd, duration, businessDays, weekendPredicate).start, end: fixedEnd };
|
|
1547
|
+
}
|
|
1548
|
+
if (fixedStart) return { start: fixedStart, end: range.end < fixedStart ? fixedStart : range.end };
|
|
1549
|
+
return { start: range.start > fixedEnd ? fixedEnd : range.start, end: fixedEnd };
|
|
1550
|
+
}
|
|
1551
|
+
function resolveParentFixedDates(task, range, getTask, businessDays = false, weekendPredicate) {
|
|
1552
|
+
if (!task.fixedStartDate && !task.fixedEndDate) return range;
|
|
1553
|
+
let { start, end } = range;
|
|
1554
|
+
for (const dep of task.dependencies ?? []) {
|
|
1555
|
+
const targetStart = dep.type === "FS" || dep.type === "SS";
|
|
1556
|
+
if (targetStart ? task.fixedStartDate : task.fixedEndDate) continue;
|
|
1557
|
+
const predecessor = getTask(dep.taskId);
|
|
1558
|
+
if (!predecessor) continue;
|
|
1559
|
+
const anchor = predecessor.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : void 0;
|
|
1560
|
+
const { predStart, predEnd } = normalizePredecessorDates({
|
|
1561
|
+
...predecessor,
|
|
1562
|
+
startDate: anchor ?? predecessor.fixedStartDate ?? predecessor.startDate,
|
|
1563
|
+
endDate: anchor ?? predecessor.fixedEndDate ?? predecessor.endDate
|
|
1564
|
+
}, parseDateOnly);
|
|
1565
|
+
const date = calculateSuccessorDate(predStart, predEnd, dep.type, getDependencyLag(dep), businessDays, weekendPredicate, task.type);
|
|
1566
|
+
if (targetStart && date > start) start = date;
|
|
1567
|
+
if (!targetStart && date > end) end = date;
|
|
1568
|
+
}
|
|
1569
|
+
return resolveFixedDates(task, { start, end }, true, businessDays, weekendPredicate);
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1524
1572
|
// src/core/scheduling/cascade.ts
|
|
1525
1573
|
function parseCascadeDateInput(date) {
|
|
1526
1574
|
if (date instanceof Date) {
|
|
@@ -1709,8 +1757,11 @@ function getTransitiveCascadeChain(changedTaskId, allTasks, firstLevelLinkTypes)
|
|
|
1709
1757
|
}
|
|
1710
1758
|
return chain;
|
|
1711
1759
|
}
|
|
1712
|
-
function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays = false, weekendPredicate, context = createCascadeContext(allTasks)) {
|
|
1760
|
+
function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays = false, weekendPredicate, context = createCascadeContext(allTasks), rootIsRollup = false) {
|
|
1713
1761
|
const { childrenByParentId, dependentsByPredecessorId, taskById } = context;
|
|
1762
|
+
const originalMovedTask = taskById.get(movedTask.id) ?? movedTask;
|
|
1763
|
+
const sameDelta = +newStart - +parseDateOnly(originalMovedTask.startDate) === +newEnd - +parseDateOnly(originalMovedTask.endDate);
|
|
1764
|
+
({ start: newStart, end: newEnd } = resolveFixedDates(originalMovedTask, { start: newStart, end: newEnd }, childrenByParentId.has(movedTask.id), businessDays, weekendPredicate, sameDelta));
|
|
1714
1765
|
const normalizedMovedTask = normalizeTaskDependencyLags({
|
|
1715
1766
|
...movedTask,
|
|
1716
1767
|
startDate: newStart.toISOString().split("T")[0],
|
|
@@ -1723,7 +1774,12 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1723
1774
|
updatedDates.set(movedTask.id, { start: newStart, end: newEnd });
|
|
1724
1775
|
const resultMap = /* @__PURE__ */ new Map();
|
|
1725
1776
|
resultMap.set(movedTask.id, normalizedMovedTask);
|
|
1726
|
-
const
|
|
1777
|
+
const getCurrentTask = (id) => {
|
|
1778
|
+
const task = taskById.get(id);
|
|
1779
|
+
const range = updatedDates.get(id);
|
|
1780
|
+
return task && range ? { ...task, startDate: range.start, endDate: range.end } : task;
|
|
1781
|
+
};
|
|
1782
|
+
const queue = [[movedTask.id, rootIsRollup ? "parent-recalc" : "direct"]];
|
|
1727
1783
|
const childShifted = /* @__PURE__ */ new Set();
|
|
1728
1784
|
let iterations = 0;
|
|
1729
1785
|
const MAX_ITERATIONS = allTasks.length * 3;
|
|
@@ -1732,7 +1788,7 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1732
1788
|
const [currentId, arrivalMode] = queue.shift();
|
|
1733
1789
|
const { start: currStart, end: currEnd } = updatedDates.get(currentId);
|
|
1734
1790
|
const currentOriginal = taskById.get(currentId);
|
|
1735
|
-
if (arrivalMode !== "parent-recalc") {
|
|
1791
|
+
if (arrivalMode !== "parent-recalc" && !(arrivalMode === "dependency" && (currentOriginal.fixedStartDate || currentOriginal.fixedEndDate))) {
|
|
1736
1792
|
const children = childrenByParentId.get(currentId) ?? [];
|
|
1737
1793
|
for (const child of children) {
|
|
1738
1794
|
if (childShifted.has(child.id) || child.locked) continue;
|
|
@@ -1761,6 +1817,7 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1761
1817
|
childNewStart = new Date(childOrigStart.getTime() + startDeltaMs);
|
|
1762
1818
|
childNewEnd = new Date(childOrigEnd.getTime() + endDeltaMs);
|
|
1763
1819
|
}
|
|
1820
|
+
({ start: childNewStart, end: childNewEnd } = resolveFixedDates(child, { start: childNewStart, end: childNewEnd }, childrenByParentId.has(child.id), businessDays, weekendPredicate));
|
|
1764
1821
|
const prev = updatedDates.get(child.id);
|
|
1765
1822
|
if (prev && prev.start.getTime() === childNewStart.getTime() && prev.end.getTime() === childNewEnd.getTime()) {
|
|
1766
1823
|
continue;
|
|
@@ -1791,8 +1848,10 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1791
1848
|
if (updatedDates.has(sib.id)) return updatedDates.get(sib.id);
|
|
1792
1849
|
return { start: new Date(sib.startDate), end: new Date(sib.endDate) };
|
|
1793
1850
|
});
|
|
1794
|
-
const minStart
|
|
1795
|
-
|
|
1851
|
+
const { start: minStart, end: maxEnd } = resolveParentFixedDates(parent, {
|
|
1852
|
+
start: new Date(Math.min(...siblingPositions.map((p) => p.start.getTime()))),
|
|
1853
|
+
end: new Date(Math.max(...siblingPositions.map((p) => p.end.getTime())))
|
|
1854
|
+
}, getCurrentTask, businessDays, weekendPredicate);
|
|
1796
1855
|
const prev = updatedDates.get(parentId);
|
|
1797
1856
|
if (!prev || prev.start.getTime() !== minStart.getTime() || prev.end.getTime() !== maxEnd.getTime()) {
|
|
1798
1857
|
updatedDates.set(parentId, { start: minStart, end: maxEnd });
|
|
@@ -1848,6 +1907,15 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
|
|
|
1848
1907
|
weekendPredicate
|
|
1849
1908
|
));
|
|
1850
1909
|
}
|
|
1910
|
+
const dependentChildren = childrenByParentId.get(task.id);
|
|
1911
|
+
if (dependentChildren?.length && (task.fixedStartDate || task.fixedEndDate)) {
|
|
1912
|
+
const positions = dependentChildren.map((child) => updatedDates.get(child.id) ?? { start: parseDateOnly(child.startDate), end: parseDateOnly(child.endDate) });
|
|
1913
|
+
({ start: succNewStart, end: succNewEnd } = resolveParentFixedDates(task, {
|
|
1914
|
+
start: new Date(Math.min(...positions.map((position) => +position.start))),
|
|
1915
|
+
end: new Date(Math.max(...positions.map((position) => +position.end)))
|
|
1916
|
+
}, getCurrentTask, businessDays, weekendPredicate));
|
|
1917
|
+
}
|
|
1918
|
+
({ start: succNewStart, end: succNewEnd } = resolveFixedDates(task, { start: succNewStart, end: succNewEnd }, !!dependentChildren?.length, businessDays, weekendPredicate));
|
|
1851
1919
|
const prev = updatedDates.get(task.id);
|
|
1852
1920
|
if (prev && prev.start.getTime() === succNewStart.getTime() && prev.end.getTime() === succNewEnd.getTime()) {
|
|
1853
1921
|
continue;
|
|
@@ -1877,22 +1945,23 @@ function getChildren(parentId, tasks) {
|
|
|
1877
1945
|
function isTaskParent(taskId, tasks) {
|
|
1878
1946
|
return tasks.some((t) => t.parentId === taskId);
|
|
1879
1947
|
}
|
|
1880
|
-
function computeParentDates(parentId, tasks) {
|
|
1948
|
+
function computeParentDates(parentId, tasks, businessDays = false, weekendPredicate) {
|
|
1881
1949
|
const children = getChildren(parentId, tasks);
|
|
1882
1950
|
if (children.length === 0) {
|
|
1883
|
-
const
|
|
1884
|
-
const start =
|
|
1885
|
-
const end =
|
|
1886
|
-
|
|
1951
|
+
const parent2 = tasks.find((t) => t.id === parentId);
|
|
1952
|
+
const start = parent2 ? new Date(parent2.startDate) : /* @__PURE__ */ new Date();
|
|
1953
|
+
const end = parent2 ? new Date(parent2.endDate) : /* @__PURE__ */ new Date();
|
|
1954
|
+
const range2 = parent2 ? resolveFixedDates(parent2, { start, end }, false) : { start, end };
|
|
1955
|
+
return { startDate: range2.start, endDate: range2.end };
|
|
1887
1956
|
}
|
|
1888
1957
|
const startDates = children.map((c) => new Date(c.startDate));
|
|
1889
1958
|
const endDates = children.map((c) => new Date(c.endDate));
|
|
1890
1959
|
const minTime = Math.min(...startDates.map((d) => d.getTime()));
|
|
1891
1960
|
const maxTime = Math.max(...endDates.map((d) => d.getTime()));
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
};
|
|
1961
|
+
const parent = tasks.find((t) => t.id === parentId);
|
|
1962
|
+
const range = { start: new Date(minTime), end: new Date(maxTime) };
|
|
1963
|
+
const resolved = parent ? resolveParentFixedDates(parent, range, (id) => tasks.find((task) => task.id === id), businessDays, weekendPredicate) : range;
|
|
1964
|
+
return { startDate: resolved.start, endDate: resolved.end };
|
|
1896
1965
|
}
|
|
1897
1966
|
function computeParentProgress(parentId, tasks) {
|
|
1898
1967
|
const children = getChildren(parentId, tasks);
|
|
@@ -2023,13 +2092,14 @@ function moveTaskWithCascade(taskId, newStart, snapshot, options) {
|
|
|
2023
2092
|
}
|
|
2024
2093
|
const businessDays = options?.businessDays ?? false;
|
|
2025
2094
|
const weekendPredicate = options?.weekendPredicate;
|
|
2026
|
-
|
|
2095
|
+
let newRange = moveTaskRange(
|
|
2027
2096
|
task.startDate,
|
|
2028
2097
|
task.endDate,
|
|
2029
2098
|
newStart,
|
|
2030
2099
|
businessDays,
|
|
2031
2100
|
weekendPredicate
|
|
2032
2101
|
);
|
|
2102
|
+
newRange = resolveFixedDates(task, newRange, snapshot.some((t) => t.parentId === task.id), businessDays, weekendPredicate);
|
|
2033
2103
|
const updatedDependencies = recalculateIncomingLags(
|
|
2034
2104
|
task,
|
|
2035
2105
|
newRange.start,
|
|
@@ -2084,6 +2154,7 @@ function resizeTaskWithCascade(taskId, anchor, newDate, snapshot, options) {
|
|
|
2084
2154
|
} else {
|
|
2085
2155
|
newRange = { start: newDate, end: originalEnd };
|
|
2086
2156
|
}
|
|
2157
|
+
newRange = resolveFixedDates(task, newRange, snapshot.some((t) => t.parentId === task.id), businessDays, weekendPredicate, false);
|
|
2087
2158
|
const updatedDependencies = recalculateIncomingLags(
|
|
2088
2159
|
task,
|
|
2089
2160
|
newRange.start,
|
|
@@ -2174,6 +2245,14 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
|
|
|
2174
2245
|
changedIds: [task.id]
|
|
2175
2246
|
};
|
|
2176
2247
|
}
|
|
2248
|
+
const fixedParent = !!(task.fixedStartDate || task.fixedEndDate) && snapshot.some((t) => t.parentId === task.id);
|
|
2249
|
+
if (fixedParent) {
|
|
2250
|
+
const rollup = computeParentDates(task.id, snapshot, businessDays, weekendPredicate);
|
|
2251
|
+
constrainedStart = rollup.startDate;
|
|
2252
|
+
constrainedEnd = rollup.endDate;
|
|
2253
|
+
} else {
|
|
2254
|
+
({ start: constrainedStart, end: constrainedEnd } = resolveFixedDates(task, { start: constrainedStart, end: constrainedEnd }, false, businessDays, weekendPredicate));
|
|
2255
|
+
}
|
|
2177
2256
|
const updatedDependencies = recalculateIncomingLags(
|
|
2178
2257
|
task,
|
|
2179
2258
|
constrainedStart,
|
|
@@ -2200,7 +2279,9 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
|
|
|
2200
2279
|
constrainedEnd,
|
|
2201
2280
|
snapshot,
|
|
2202
2281
|
businessDays,
|
|
2203
|
-
weekendPredicate
|
|
2282
|
+
weekendPredicate,
|
|
2283
|
+
void 0,
|
|
2284
|
+
fixedParent
|
|
2204
2285
|
);
|
|
2205
2286
|
const resultMap = /* @__PURE__ */ new Map();
|
|
2206
2287
|
resultMap.set(recalculatedTask.id, recalculatedTask);
|
|
@@ -2214,6 +2295,100 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
|
|
|
2214
2295
|
};
|
|
2215
2296
|
}
|
|
2216
2297
|
function recalculateProjectSchedule(snapshot, options) {
|
|
2298
|
+
if (snapshot.some((task) => task.fixedStartDate || task.fixedEndDate)) {
|
|
2299
|
+
return recalculateFixedComponents(snapshot, options);
|
|
2300
|
+
}
|
|
2301
|
+
return recalculateProjectScheduleLegacy(snapshot, options);
|
|
2302
|
+
}
|
|
2303
|
+
function recalculateFixedComponents(snapshot, options) {
|
|
2304
|
+
const businessDays = options?.businessDays ?? false;
|
|
2305
|
+
const weekendPredicate = options?.weekendPredicate;
|
|
2306
|
+
const initial = new Map(snapshot.map((task) => [task.id, task]));
|
|
2307
|
+
const next = new Map(snapshot.map((task) => [task.id, task]));
|
|
2308
|
+
const children = /* @__PURE__ */ new Map();
|
|
2309
|
+
const outgoing = new Map(snapshot.map((task) => [task.id, /* @__PURE__ */ new Set()]));
|
|
2310
|
+
const neighbours = new Map(snapshot.map((task) => [task.id, /* @__PURE__ */ new Set()]));
|
|
2311
|
+
const connect = (from, to, ordered = true) => {
|
|
2312
|
+
if (!initial.has(from) || !initial.has(to)) return;
|
|
2313
|
+
if (ordered) outgoing.get(from).add(to);
|
|
2314
|
+
neighbours.get(from).add(to);
|
|
2315
|
+
neighbours.get(to).add(from);
|
|
2316
|
+
};
|
|
2317
|
+
for (const task of snapshot) {
|
|
2318
|
+
if (task.parentId && initial.has(task.parentId)) {
|
|
2319
|
+
const list = children.get(task.parentId) ?? [];
|
|
2320
|
+
list.push(task.id);
|
|
2321
|
+
children.set(task.parentId, list);
|
|
2322
|
+
connect(task.id, task.parentId);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
for (const task of snapshot) {
|
|
2326
|
+
for (const dependency of task.dependencies ?? []) {
|
|
2327
|
+
const predecessor = initial.get(dependency.taskId);
|
|
2328
|
+
const fixedSource = predecessor?.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : dependency.type === "FS" || dependency.type === "FF" ? predecessor?.fixedEndDate : predecessor?.fixedStartDate;
|
|
2329
|
+
const targetFixed = dependency.type === "FS" || dependency.type === "SS" ? task.fixedStartDate : task.fixedEndDate;
|
|
2330
|
+
const derivedParent = children.has(task.id) && !task.fixedStartDate && !task.fixedEndDate;
|
|
2331
|
+
connect(dependency.taskId, task.id, !fixedSource && !targetFixed && !derivedParent);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
const affected = new Set(snapshot.filter((task) => task.fixedStartDate || task.fixedEndDate).map((task) => task.id));
|
|
2335
|
+
const pending = [...affected];
|
|
2336
|
+
for (let i = 0; i < pending.length; i++) {
|
|
2337
|
+
for (const id of neighbours.get(pending[i])) if (!affected.has(id)) {
|
|
2338
|
+
affected.add(id);
|
|
2339
|
+
pending.push(id);
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
const indegree = new Map([...affected].map((id) => [id, 0]));
|
|
2343
|
+
for (const id of affected) for (const successor of outgoing.get(id)) {
|
|
2344
|
+
indegree.set(successor, indegree.get(successor) + 1);
|
|
2345
|
+
}
|
|
2346
|
+
const queue = [...affected].filter((id) => indegree.get(id) === 0);
|
|
2347
|
+
for (let i = 0; i < queue.length; i++) {
|
|
2348
|
+
const id = queue[i];
|
|
2349
|
+
const task = next.get(id);
|
|
2350
|
+
const childIds = children.get(id);
|
|
2351
|
+
if (!task.locked) {
|
|
2352
|
+
let range = { start: parseDateOnly(task.startDate), end: parseDateOnly(task.endDate) };
|
|
2353
|
+
if (childIds?.length) {
|
|
2354
|
+
range = {
|
|
2355
|
+
start: new Date(Math.min(...childIds.map((child) => +parseDateOnly(next.get(child).startDate)))),
|
|
2356
|
+
end: new Date(Math.max(...childIds.map((child) => +parseDateOnly(next.get(child).endDate))))
|
|
2357
|
+
};
|
|
2358
|
+
range = resolveParentFixedDates(task, range, (key) => next.get(key), businessDays, weekendPredicate);
|
|
2359
|
+
} else if (task.dependencies?.length) {
|
|
2360
|
+
const duration = getTaskDuration(task.startDate, task.endDate, businessDays, weekendPredicate);
|
|
2361
|
+
let selected;
|
|
2362
|
+
for (const dependency of task.dependencies) {
|
|
2363
|
+
const predecessor = next.get(dependency.taskId);
|
|
2364
|
+
if (!predecessor) continue;
|
|
2365
|
+
const milestoneAnchor = predecessor.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : void 0;
|
|
2366
|
+
const { predStart, predEnd } = normalizePredecessorDates({
|
|
2367
|
+
...predecessor,
|
|
2368
|
+
startDate: milestoneAnchor ?? predecessor.fixedStartDate ?? predecessor.startDate,
|
|
2369
|
+
endDate: milestoneAnchor ?? predecessor.fixedEndDate ?? predecessor.endDate
|
|
2370
|
+
}, parseDateOnly);
|
|
2371
|
+
const date = calculateSuccessorDate(predStart, predEnd, dependency.type, getDependencyLag(dependency), businessDays, weekendPredicate, task.type);
|
|
2372
|
+
const candidate = dependency.type === "FS" || dependency.type === "SS" ? buildTaskRangeFromStart(date, duration, businessDays, weekendPredicate) : buildTaskRangeFromEnd(date, duration, businessDays, weekendPredicate);
|
|
2373
|
+
if (!selected || candidate.start > selected.start || +candidate.start === +selected.start && candidate.end > selected.end) selected = candidate;
|
|
2374
|
+
}
|
|
2375
|
+
if (selected) range = selected;
|
|
2376
|
+
}
|
|
2377
|
+
range = resolveFixedDates(task, range, !!childIds?.length, businessDays, weekendPredicate);
|
|
2378
|
+
next.set(id, { ...task, startDate: toIsoDate(range.start), endDate: toIsoDate(range.end) });
|
|
2379
|
+
}
|
|
2380
|
+
for (const successor of outgoing.get(id)) {
|
|
2381
|
+
indegree.set(successor, indegree.get(successor) - 1);
|
|
2382
|
+
if (indegree.get(successor) === 0) queue.push(successor);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
if (queue.length !== affected.size) throw new Error("Fixed date schedule contains a hierarchy/dependency cycle");
|
|
2386
|
+
for (const task of recalculateProjectScheduleLegacy(snapshot, options).changedTasks) {
|
|
2387
|
+
if (!affected.has(task.id)) next.set(task.id, task);
|
|
2388
|
+
}
|
|
2389
|
+
return createChangedResult(snapshot, [...next.values()]);
|
|
2390
|
+
}
|
|
2391
|
+
function recalculateProjectScheduleLegacy(snapshot, options) {
|
|
2217
2392
|
const businessDays = options?.businessDays ?? false;
|
|
2218
2393
|
const weekendPredicate = options?.weekendPredicate;
|
|
2219
2394
|
const workingMap = new Map(snapshot.map((task) => [task.id, { ...task }]));
|
|
@@ -2337,12 +2512,13 @@ function reflowTasksOnModeSwitch(sourceTasks, toBusinessDays, weekendPredicate)
|
|
|
2337
2512
|
true,
|
|
2338
2513
|
weekendPredicate
|
|
2339
2514
|
) : buildTaskRangeFromStart(start, duration, false);
|
|
2340
|
-
|
|
2341
|
-
task.
|
|
2515
|
+
const resolved = resolveFixedDates(task, range, false, toBusinessDays, weekendPredicate);
|
|
2516
|
+
task.startDate = toISO(resolved.start);
|
|
2517
|
+
task.endDate = toISO(resolved.end);
|
|
2342
2518
|
}
|
|
2343
2519
|
for (const task of tasks) {
|
|
2344
2520
|
if (!isTaskParent(task.id, tasks)) continue;
|
|
2345
|
-
const { startDate, endDate } = computeParentDates(task.id, tasks);
|
|
2521
|
+
const { startDate, endDate } = computeParentDates(task.id, tasks, toBusinessDays, weekendPredicate);
|
|
2346
2522
|
task.startDate = toISO(startDate);
|
|
2347
2523
|
task.endDate = toISO(endDate);
|
|
2348
2524
|
}
|
|
@@ -3530,6 +3706,10 @@ function scaleTaskSubtreeDuration(parentId, targetDuration, snapshot, options) {
|
|
|
3530
3706
|
const { context: ctx, space } = built;
|
|
3531
3707
|
const solved = solveScale(ctx, space, targetDuration);
|
|
3532
3708
|
const finalTasks = buildFinalTasks(ctx, solved.state, solved.layout, space);
|
|
3709
|
+
const fixedConflicts = [...finalTasks.values()].filter((task) => task.fixedStartDate && isoOfTaskDate(task.startDate) !== task.fixedStartDate || task.fixedEndDate && isoOfTaskDate(task.endDate) !== task.fixedEndDate);
|
|
3710
|
+
if (fixedConflicts.length) {
|
|
3711
|
+
return scaleFailure("FIXED_DATE_CONFLICT", fixedConflicts.map((task) => task.id));
|
|
3712
|
+
}
|
|
3533
3713
|
const externalPolicy = resolvedOptions.externalDependencyPolicy ?? "subtree-only";
|
|
3534
3714
|
let externalChanged = [];
|
|
3535
3715
|
if (externalPolicy === "subtree-only") {
|
|
@@ -3619,16 +3799,22 @@ function flattenHierarchy(tasks) {
|
|
|
3619
3799
|
}
|
|
3620
3800
|
return result;
|
|
3621
3801
|
}
|
|
3622
|
-
function normalizeHierarchyTasks(tasks) {
|
|
3802
|
+
function normalizeHierarchyTasks(tasks, businessDays = false, weekendPredicate) {
|
|
3803
|
+
const parentIds = new Set(tasks.map((task) => task.parentId).filter(Boolean));
|
|
3623
3804
|
const orderedTasks = flattenHierarchy(tasks).map((task) => {
|
|
3624
3805
|
const bounds = activityBounds(task.activities);
|
|
3625
3806
|
const { startDate, endDate } = normalizeTaskDates(
|
|
3626
3807
|
bounds?.startDate ?? task.startDate,
|
|
3627
3808
|
bounds?.endDate ?? task.endDate
|
|
3628
3809
|
);
|
|
3629
|
-
|
|
3810
|
+
if (!task.fixedStartDate && !task.fixedEndDate) {
|
|
3811
|
+
return { ...task, startDate, endDate };
|
|
3812
|
+
}
|
|
3813
|
+
const range = resolveFixedDates(task, { start: new Date(startDate), end: new Date(endDate) }, parentIds.has(task.id));
|
|
3814
|
+
return { ...task, startDate: range.start.toISOString().slice(0, 10), endDate: range.end.toISOString().slice(0, 10) };
|
|
3630
3815
|
});
|
|
3631
3816
|
const childrenByParent = /* @__PURE__ */ new Map();
|
|
3817
|
+
const taskIndex = new Map(orderedTasks.map((task, index) => [task.id, index]));
|
|
3632
3818
|
for (let index = 0; index < orderedTasks.length; index++) {
|
|
3633
3819
|
const parentId = orderedTasks[index].parentId;
|
|
3634
3820
|
if (!parentId) continue;
|
|
@@ -3654,10 +3840,14 @@ function normalizeHierarchyTasks(tasks) {
|
|
|
3654
3840
|
totalWeight += duration;
|
|
3655
3841
|
weightedProgress += duration * (child.progress ?? 0);
|
|
3656
3842
|
}
|
|
3843
|
+
const range = resolveParentFixedDates(orderedTasks[index], { start: new Date(minStart), end: new Date(maxEnd) }, (id) => {
|
|
3844
|
+
const predecessorIndex = taskIndex.get(id);
|
|
3845
|
+
return predecessorIndex === void 0 ? void 0 : orderedTasks[predecessorIndex];
|
|
3846
|
+
}, businessDays, weekendPredicate);
|
|
3657
3847
|
orderedTasks[index] = {
|
|
3658
3848
|
...orderedTasks[index],
|
|
3659
|
-
startDate:
|
|
3660
|
-
endDate:
|
|
3849
|
+
startDate: range.start.toISOString().split("T")[0],
|
|
3850
|
+
endDate: range.end.toISOString().split("T")[0],
|
|
3661
3851
|
progress: orderedTasks[index].progressAggregation === "manual" ? orderedTasks[index].progress : totalWeight === 0 ? 0 : Math.round(weightedProgress / totalWeight * 10) / 10
|
|
3662
3852
|
};
|
|
3663
3853
|
}
|
|
@@ -3952,6 +4142,10 @@ var import_react2 = require("react");
|
|
|
3952
4142
|
|
|
3953
4143
|
// src/adapters/scheduling/drag.ts
|
|
3954
4144
|
function resolveDateRangeFromPixels(mode, left, width, monthStart, dayWidth, task, businessDays, weekendPredicate) {
|
|
4145
|
+
const range = resolveDateRangeFromPixelsRaw(mode, left, width, monthStart, dayWidth, task, businessDays, weekendPredicate);
|
|
4146
|
+
return resolveFixedDates(task, range, false, businessDays, weekendPredicate, mode === "move");
|
|
4147
|
+
}
|
|
4148
|
+
function resolveDateRangeFromPixelsRaw(mode, left, width, monthStart, dayWidth, task, businessDays, weekendPredicate) {
|
|
3955
4149
|
const dayOffset = Math.round(left / dayWidth);
|
|
3956
4150
|
const rawStartDate = new Date(Date.UTC(
|
|
3957
4151
|
monthStart.getUTCFullYear(),
|
|
@@ -4006,10 +4200,10 @@ function resolveDateRangeFromPixels(mode, left, width, monthStart, dayWidth, tas
|
|
|
4006
4200
|
return buildTaskRangeFromEnd(fixedEnd, duration, true, weekendPredicate);
|
|
4007
4201
|
}
|
|
4008
4202
|
function clampDateRangeForIncomingFS(task, range, allTasks, mode, businessDays, weekendPredicate, taskById) {
|
|
4009
|
-
if (mode === "resize-right") {
|
|
4203
|
+
if (mode === "resize-right" || task.fixedStartDate || task.type === "milestone" && task.fixedEndDate) {
|
|
4010
4204
|
return range;
|
|
4011
4205
|
}
|
|
4012
|
-
|
|
4206
|
+
const clamped = clampTaskRangeForIncomingFS(
|
|
4013
4207
|
task,
|
|
4014
4208
|
range.start,
|
|
4015
4209
|
range.end,
|
|
@@ -4018,6 +4212,7 @@ function clampDateRangeForIncomingFS(task, range, allTasks, mode, businessDays,
|
|
|
4018
4212
|
weekendPredicate,
|
|
4019
4213
|
taskById
|
|
4020
4214
|
);
|
|
4215
|
+
return resolveFixedDates(task, clamped, false, businessDays, weekendPredicate, mode === "move");
|
|
4021
4216
|
}
|
|
4022
4217
|
|
|
4023
4218
|
// src/hooks/useTaskDrag.ts
|
|
@@ -4172,7 +4367,7 @@ function handleGlobalMouseMove(e) {
|
|
|
4172
4367
|
const { dayWidth: dw, monthStart: mStart } = activeDrag;
|
|
4173
4368
|
const previewRange = resolveDragRangeForInteraction(activeDrag, draggedTask, mode, newLeft, newWidth);
|
|
4174
4369
|
const anchor = mode === "resize-left" ? "end" : "start";
|
|
4175
|
-
const parentRange = computeParentDates(activeDrag.taskId, allTasks);
|
|
4370
|
+
const parentRange = computeParentDates(activeDrag.taskId, allTasks, activeDrag.businessDays, activeDrag.weekendPredicate);
|
|
4176
4371
|
const targetDuration = Math.max(1, getTaskDuration(
|
|
4177
4372
|
anchor === "start" ? parentRange.startDate : previewRange.start,
|
|
4178
4373
|
anchor === "start" ? previewRange.end : parentRange.endDate,
|
|
@@ -4508,7 +4703,7 @@ var useTaskDrag = (options) => {
|
|
|
4508
4703
|
});
|
|
4509
4704
|
} else if (currentTask && isTaskParent(taskId, allTasks)) {
|
|
4510
4705
|
const anchor = finalMode === "resize-left" ? "end" : "start";
|
|
4511
|
-
const parentRange = computeParentDates(taskId, allTasks);
|
|
4706
|
+
const parentRange = computeParentDates(taskId, allTasks, businessDays, weekendPredicate);
|
|
4512
4707
|
const targetDuration = getTaskDuration(
|
|
4513
4708
|
anchor === "start" ? parentRange.startDate : newStartDate,
|
|
4514
4709
|
anchor === "start" ? newEndDate : parentRange.endDate,
|
|
@@ -6445,6 +6640,7 @@ var DependencyLines = import_react7.default.memo(({
|
|
|
6445
6640
|
const positionedTaskIds = Array.from(taskPositions.keys());
|
|
6446
6641
|
const renderedTaskIdSet = new Set(geometryTasks.map((t) => t.id));
|
|
6447
6642
|
const lines2 = [];
|
|
6643
|
+
const renderedEdgeKeys = /* @__PURE__ */ new Set();
|
|
6448
6644
|
for (const successorId of positionedTaskIds) {
|
|
6449
6645
|
const successorTaskForEdges = taskMap.get(successorId);
|
|
6450
6646
|
if (!successorTaskForEdges?.dependencies?.length) {
|
|
@@ -6461,6 +6657,9 @@ var DependencyLines = import_react7.default.memo(({
|
|
|
6461
6657
|
type: dependency.type,
|
|
6462
6658
|
lag: dependency.lag ?? 0
|
|
6463
6659
|
};
|
|
6660
|
+
const renderKey = JSON.stringify([edge.predecessorId, edge.successorId, edge.type, edge.lag]);
|
|
6661
|
+
if (renderedEdgeKeys.has(renderKey)) continue;
|
|
6662
|
+
renderedEdgeKeys.add(renderKey);
|
|
6464
6663
|
const predecessor = taskPositions.get(edge.predecessorId);
|
|
6465
6664
|
const successor = taskPositions.get(edge.successorId);
|
|
6466
6665
|
const predecessorIndex = taskIndices.get(edge.predecessorId);
|
|
@@ -6521,6 +6720,7 @@ var DependencyLines = import_react7.default.memo(({
|
|
|
6521
6720
|
);
|
|
6522
6721
|
lines2.push({
|
|
6523
6722
|
id: `${edge.predecessorId}-${edge.successorId}-${edge.type}`,
|
|
6723
|
+
renderKey,
|
|
6524
6724
|
predecessorId: edge.predecessorId,
|
|
6525
6725
|
successorId: edge.successorId,
|
|
6526
6726
|
linkType: edge.type,
|
|
@@ -6669,7 +6869,7 @@ var DependencyLines = import_react7.default.memo(({
|
|
|
6669
6869
|
onLineLeave: handleLineLeave,
|
|
6670
6870
|
onDependencyClick
|
|
6671
6871
|
},
|
|
6672
|
-
line.
|
|
6872
|
+
line.renderKey
|
|
6673
6873
|
);
|
|
6674
6874
|
})
|
|
6675
6875
|
]
|
|
@@ -10381,13 +10581,13 @@ var TaskList = ({
|
|
|
10381
10581
|
return next;
|
|
10382
10582
|
});
|
|
10383
10583
|
}, []);
|
|
10384
|
-
const orderedTasks = (0, import_react15.useMemo)(() => {
|
|
10385
|
-
return normalizeHierarchyTasks(tasks);
|
|
10386
|
-
}, [tasks]);
|
|
10387
10584
|
const weekendPredicate = (0, import_react15.useMemo)(
|
|
10388
10585
|
() => createCustomDayPredicate({ customDays, isWeekend: isWeekend3 }),
|
|
10389
10586
|
[customDays, isWeekend3]
|
|
10390
10587
|
);
|
|
10588
|
+
const orderedTasks = (0, import_react15.useMemo)(() => {
|
|
10589
|
+
return normalizeHierarchyTasks(tasks, businessDays, weekendPredicate);
|
|
10590
|
+
}, [tasks, businessDays, weekendPredicate]);
|
|
10391
10591
|
const visibleTasks = (0, import_react15.useMemo)(() => {
|
|
10392
10592
|
const parentMap = new Map(orderedTasks.map((t) => [t.id, t.parentId]));
|
|
10393
10593
|
function isAnyAncestorCollapsed(parentId) {
|
|
@@ -15696,8 +15896,12 @@ function TaskGanttChartInner(props, ref) {
|
|
|
15696
15896
|
() => rowContentLines === 0 && !isPlanFactMode ? rowHeight : Math.max(rowHeight, 10 + resolvedRowContentLines * 18),
|
|
15697
15897
|
[isPlanFactMode, resolvedRowContentLines, rowContentLines, rowHeight]
|
|
15698
15898
|
);
|
|
15899
|
+
const isCustomWeekend = (0, import_react20.useMemo)(
|
|
15900
|
+
() => createCustomDayPredicate({ customDays, isWeekend: isWeekend3 }),
|
|
15901
|
+
[customDays, isWeekend3]
|
|
15902
|
+
);
|
|
15699
15903
|
const normalizedTasks = (0, import_react20.useMemo)(() => {
|
|
15700
|
-
const ordered = normalizeHierarchyTasks(tasks);
|
|
15904
|
+
const ordered = normalizeHierarchyTasks(tasks, businessDays, isCustomWeekend);
|
|
15701
15905
|
const ranges = /* @__PURE__ */ new Map();
|
|
15702
15906
|
for (const task of ordered) {
|
|
15703
15907
|
if (!task.parentId) continue;
|
|
@@ -15710,14 +15914,14 @@ function TaskGanttChartInner(props, ref) {
|
|
|
15710
15914
|
});
|
|
15711
15915
|
}
|
|
15712
15916
|
return ordered.map((task) => {
|
|
15713
|
-
const range = task.composite ? ranges.get(task.id) : void 0;
|
|
15917
|
+
const range = task.composite && !task.fixedStartDate && !task.fixedEndDate ? ranges.get(task.id) : void 0;
|
|
15714
15918
|
return range ? {
|
|
15715
15919
|
...task,
|
|
15716
15920
|
startDate: new Date(range.start).toISOString().slice(0, 10),
|
|
15717
15921
|
endDate: new Date(range.end).toISOString().slice(0, 10)
|
|
15718
15922
|
} : task;
|
|
15719
15923
|
});
|
|
15720
|
-
}, [tasks]);
|
|
15924
|
+
}, [tasks, businessDays, isCustomWeekend]);
|
|
15721
15925
|
const collapsedParentIds = (0, import_react20.useMemo)(() => {
|
|
15722
15926
|
if (externalCollapsedParentIds) return externalCollapsedParentIds;
|
|
15723
15927
|
const ids = new Set(internalCollapsedParentIds);
|
|
@@ -15737,10 +15941,6 @@ function TaskGanttChartInner(props, ref) {
|
|
|
15737
15941
|
if (controlledScheduleChanged || previewTasksById.size === 0) return normalizedTasks;
|
|
15738
15942
|
return normalizedTasks.map((task) => previewTasksById.get(task.id) ?? task);
|
|
15739
15943
|
}, [controlledScheduleChanged, normalizedTasks, previewTasksById]);
|
|
15740
|
-
const isCustomWeekend = (0, import_react20.useMemo)(
|
|
15741
|
-
() => createCustomDayPredicate({ customDays, isWeekend: isWeekend3 }),
|
|
15742
|
-
[customDays, isWeekend3]
|
|
15743
|
-
);
|
|
15744
15944
|
const criticalTaskIds = (0, import_react20.useMemo)(() => {
|
|
15745
15945
|
if (!criticalPathMode) return /* @__PURE__ */ new Set();
|
|
15746
15946
|
const leafCritical = computeCriticalPath(previewNormalizedTasks, {
|
|
@@ -16270,13 +16470,13 @@ function TaskGanttChartInner(props, ref) {
|
|
|
16270
16470
|
...task,
|
|
16271
16471
|
sortOrder: index
|
|
16272
16472
|
}));
|
|
16273
|
-
const normalized = normalizeHierarchyTasks(orderedForCallback);
|
|
16473
|
+
const normalized = normalizeHierarchyTasks(orderedForCallback, businessDays, isCustomWeekend);
|
|
16274
16474
|
if (onReorder) {
|
|
16275
16475
|
onReorder(normalized, movedTaskId, inferredParentId);
|
|
16276
16476
|
return;
|
|
16277
16477
|
}
|
|
16278
16478
|
onTasksChange?.(normalized);
|
|
16279
|
-
}, [onTasksChange, onReorder]);
|
|
16479
|
+
}, [onTasksChange, onReorder, businessDays, isCustomWeekend]);
|
|
16280
16480
|
const dependencyOverrides = (0, import_react20.useMemo)(() => {
|
|
16281
16481
|
if (controlledScheduleChanged) return /* @__PURE__ */ new Map();
|
|
16282
16482
|
const map = new Map(cascadeOverrides);
|
|
@@ -16588,9 +16788,9 @@ function TaskGanttChartInner(props, ref) {
|
|
|
16588
16788
|
...tasksWithoutPromoted.slice(0, insertIndex),
|
|
16589
16789
|
promotedTask,
|
|
16590
16790
|
...tasksWithoutPromoted.slice(insertIndex)
|
|
16591
|
-
]);
|
|
16791
|
+
], businessDays, isCustomWeekend);
|
|
16592
16792
|
onTasksChange?.(reorderedTasks);
|
|
16593
|
-
}, [tasks, onTasksChange, onPromoteTask]);
|
|
16793
|
+
}, [tasks, onTasksChange, onPromoteTask, businessDays, isCustomWeekend]);
|
|
16594
16794
|
const handleDemoteTask = (0, import_react20.useCallback)((taskId, newParentId) => {
|
|
16595
16795
|
if (onDemoteTask) {
|
|
16596
16796
|
onDemoteTask(taskId, newParentId);
|