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 CHANGED
@@ -285,6 +285,8 @@ interface Task {
285
285
  name: string;
286
286
  startDate: string | Date;
287
287
  endDate: string | Date;
288
+ fixedStartDate?: string | null; // YYYY-MM-DD; omit or null for automatic start
289
+ fixedEndDate?: string | null; // YYYY-MM-DD; omit or null for automatic end
288
290
  baselineStartDate?: string | Date;
289
291
  baselineEndDate?: string | Date;
290
292
  type?: 'task' | 'milestone';
@@ -303,6 +305,8 @@ interface Task {
303
305
 
304
306
  Tasks accept ISO strings or `Date` objects, but internal calculations are UTC-safe. Milestones use `type: 'milestone'`. Hierarchy uses `parentId`. Locked tasks cannot be dragged or edited.
305
307
 
308
+ Fixed dates independently anchor each boundary during scheduling. Parent boundaries without an anchor follow their children and applicable incoming constraints; children may extend outside fixed boundaries. A milestone has one date. Inverted fixed dates are rejected, as are subtree scaling results that would move an anchor (`FIXED_DATE_CONFLICT`). Existing tasks without fixed dates retain their existing behavior.
309
+
306
310
  ### Dependencies
307
311
 
308
312
  Tasks can have dependencies on predecessor tasks using 4 link types following PM standards:
@@ -1,2 +1,2 @@
1
- export { an as CascadeContext, C as CriticalPathOptions, D as DAY_MS, i as DependencyError, L as LinkType, q as ScaleTaskSubtreeAnchor, r as ScaleTaskSubtreeErrorCode, s as ScaleTaskSubtreeExternalPolicy, t as ScaleTaskSubtreeOptions, S as ScaleTaskSubtreeResult, u as ScaleTaskSubtreeWarning, ao as ScheduleCommandOptions, ap as ScheduleCommandResult, aq as ScheduleDependency, ar as ScheduleTask, as as ScheduleTaskUpdate, T as Task, at as TaskDependency, V as ValidationResult, au as addBusinessDays, x as alignToWorkingDay, y as areTasksHierarchicallyRelated, z as buildAdjacencyList, E as buildTaskRangeFromEnd, F as buildTaskRangeFromStart, H as calculateSuccessorDate, I as cascadeByLinks, av as cascadeTaskProgress, J as clampTaskRangeForIncomingFS, K as computeCriticalPath, N as computeLagFromDates, O as computeParentDates, P as computeParentProgress, aw as createCascadeContext, Q as detectCycles, U as extendCriticalIdsToParents, X as findParentId, Y as getAllDependencyEdges, Z as getAllDescendants, _ as getBusinessDayOffset, ax as getBusinessDaysCount, $ as getChildren, a0 as getDependencyLag, a1 as getSuccessorChain, a2 as getTaskDuration, a3 as getTransitiveCascadeChain, a4 as isAncestorTask, a5 as isTaskParent, a6 as moveTaskRange, a7 as moveTaskWithCascade, a8 as normalizeDependencyLag, a9 as normalizePredecessorDates, aa as normalizeTaskDependencyLags, ab as normalizeUTCDate, ac as parseDateOnly, ad as recalculateIncomingLags, ae as recalculateProjectSchedule, af as recalculateTaskFromDependencies, ag as reflowTasksOnModeSwitch, ah as removeDependenciesBetweenTasks, ai as resizeTaskWithCascade, aj as scaleTaskSubtreeDuration, ak as shiftBusinessDayOffset, ay as subtractBusinessDays, al as universalCascade, am as validateDependencies } from '../../index-Cue-aV4x.mjs';
1
+ export { an as CascadeContext, C as CriticalPathOptions, D as DAY_MS, i as DependencyError, L as LinkType, q as ScaleTaskSubtreeAnchor, r as ScaleTaskSubtreeErrorCode, s as ScaleTaskSubtreeExternalPolicy, t as ScaleTaskSubtreeOptions, S as ScaleTaskSubtreeResult, u as ScaleTaskSubtreeWarning, ao as ScheduleCommandOptions, ap as ScheduleCommandResult, aq as ScheduleDependency, ar as ScheduleTask, as as ScheduleTaskUpdate, T as Task, at as TaskDependency, V as ValidationResult, au as addBusinessDays, x as alignToWorkingDay, y as areTasksHierarchicallyRelated, z as buildAdjacencyList, E as buildTaskRangeFromEnd, F as buildTaskRangeFromStart, H as calculateSuccessorDate, I as cascadeByLinks, av as cascadeTaskProgress, J as clampTaskRangeForIncomingFS, K as computeCriticalPath, N as computeLagFromDates, O as computeParentDates, P as computeParentProgress, aw as createCascadeContext, Q as detectCycles, U as extendCriticalIdsToParents, X as findParentId, Y as getAllDependencyEdges, Z as getAllDescendants, _ as getBusinessDayOffset, ax as getBusinessDaysCount, $ as getChildren, a0 as getDependencyLag, a1 as getSuccessorChain, a2 as getTaskDuration, a3 as getTransitiveCascadeChain, a4 as isAncestorTask, a5 as isTaskParent, a6 as moveTaskRange, a7 as moveTaskWithCascade, a8 as normalizeDependencyLag, a9 as normalizePredecessorDates, aa as normalizeTaskDependencyLags, ab as normalizeUTCDate, ac as parseDateOnly, ad as recalculateIncomingLags, ae as recalculateProjectSchedule, af as recalculateTaskFromDependencies, ag as reflowTasksOnModeSwitch, ah as removeDependenciesBetweenTasks, ai as resizeTaskWithCascade, aj as scaleTaskSubtreeDuration, ak as shiftBusinessDayOffset, ay as subtractBusinessDays, al as universalCascade, am as validateDependencies } from '../../index-r9kDy05N.mjs';
2
2
  import 'react';
@@ -1,2 +1,2 @@
1
- export { an as CascadeContext, C as CriticalPathOptions, D as DAY_MS, i as DependencyError, L as LinkType, q as ScaleTaskSubtreeAnchor, r as ScaleTaskSubtreeErrorCode, s as ScaleTaskSubtreeExternalPolicy, t as ScaleTaskSubtreeOptions, S as ScaleTaskSubtreeResult, u as ScaleTaskSubtreeWarning, ao as ScheduleCommandOptions, ap as ScheduleCommandResult, aq as ScheduleDependency, ar as ScheduleTask, as as ScheduleTaskUpdate, T as Task, at as TaskDependency, V as ValidationResult, au as addBusinessDays, x as alignToWorkingDay, y as areTasksHierarchicallyRelated, z as buildAdjacencyList, E as buildTaskRangeFromEnd, F as buildTaskRangeFromStart, H as calculateSuccessorDate, I as cascadeByLinks, av as cascadeTaskProgress, J as clampTaskRangeForIncomingFS, K as computeCriticalPath, N as computeLagFromDates, O as computeParentDates, P as computeParentProgress, aw as createCascadeContext, Q as detectCycles, U as extendCriticalIdsToParents, X as findParentId, Y as getAllDependencyEdges, Z as getAllDescendants, _ as getBusinessDayOffset, ax as getBusinessDaysCount, $ as getChildren, a0 as getDependencyLag, a1 as getSuccessorChain, a2 as getTaskDuration, a3 as getTransitiveCascadeChain, a4 as isAncestorTask, a5 as isTaskParent, a6 as moveTaskRange, a7 as moveTaskWithCascade, a8 as normalizeDependencyLag, a9 as normalizePredecessorDates, aa as normalizeTaskDependencyLags, ab as normalizeUTCDate, ac as parseDateOnly, ad as recalculateIncomingLags, ae as recalculateProjectSchedule, af as recalculateTaskFromDependencies, ag as reflowTasksOnModeSwitch, ah as removeDependenciesBetweenTasks, ai as resizeTaskWithCascade, aj as scaleTaskSubtreeDuration, ak as shiftBusinessDayOffset, ay as subtractBusinessDays, al as universalCascade, am as validateDependencies } from '../../index-Cue-aV4x.js';
1
+ export { an as CascadeContext, C as CriticalPathOptions, D as DAY_MS, i as DependencyError, L as LinkType, q as ScaleTaskSubtreeAnchor, r as ScaleTaskSubtreeErrorCode, s as ScaleTaskSubtreeExternalPolicy, t as ScaleTaskSubtreeOptions, S as ScaleTaskSubtreeResult, u as ScaleTaskSubtreeWarning, ao as ScheduleCommandOptions, ap as ScheduleCommandResult, aq as ScheduleDependency, ar as ScheduleTask, as as ScheduleTaskUpdate, T as Task, at as TaskDependency, V as ValidationResult, au as addBusinessDays, x as alignToWorkingDay, y as areTasksHierarchicallyRelated, z as buildAdjacencyList, E as buildTaskRangeFromEnd, F as buildTaskRangeFromStart, H as calculateSuccessorDate, I as cascadeByLinks, av as cascadeTaskProgress, J as clampTaskRangeForIncomingFS, K as computeCriticalPath, N as computeLagFromDates, O as computeParentDates, P as computeParentProgress, aw as createCascadeContext, Q as detectCycles, U as extendCriticalIdsToParents, X as findParentId, Y as getAllDependencyEdges, Z as getAllDescendants, _ as getBusinessDayOffset, ax as getBusinessDaysCount, $ as getChildren, a0 as getDependencyLag, a1 as getSuccessorChain, a2 as getTaskDuration, a3 as getTransitiveCascadeChain, a4 as isAncestorTask, a5 as isTaskParent, a6 as moveTaskRange, a7 as moveTaskWithCascade, a8 as normalizeDependencyLag, a9 as normalizePredecessorDates, aa as normalizeTaskDependencyLags, ab as normalizeUTCDate, ac as parseDateOnly, ad as recalculateIncomingLags, ae as recalculateProjectSchedule, af as recalculateTaskFromDependencies, ag as reflowTasksOnModeSwitch, ah as removeDependenciesBetweenTasks, ai as resizeTaskWithCascade, aj as scaleTaskSubtreeDuration, ak as shiftBusinessDayOffset, ay as subtractBusinessDays, al as universalCascade, am as validateDependencies } from '../../index-r9kDy05N.js';
2
2
  import 'react';
@@ -520,6 +520,7 @@ function clampTaskRangeForIncomingFS(task, proposedStart, proposedEnd, allTasks,
520
520
  }
521
521
  function recalculateIncomingLags(task, newStartDate, newEndDate, allTasks, businessDays = false, weekendPredicate, taskById) {
522
522
  if (!task.dependencies) return [];
523
+ if (task.fixedStartDate || task.fixedEndDate) return task.dependencies;
523
524
  return task.dependencies.map((dep) => {
524
525
  const predecessor = taskById?.get(dep.taskId) ?? allTasks.find((candidate) => candidate.id === dep.taskId);
525
526
  if (!predecessor) {
@@ -543,6 +544,53 @@ function recalculateIncomingLags(task, newStartDate, newEndDate, allTasks, busin
543
544
  });
544
545
  }
545
546
 
547
+ // src/core/scheduling/fixedDates.ts
548
+ function resolveFixedDates(task, range, parent, businessDays = false, weekendPredicate, preserveDuration = true) {
549
+ for (const value of [task.fixedStartDate, task.fixedEndDate]) {
550
+ if (value && (!/^\d{4}-\d{2}-\d{2}$/.test(value) || Number.isNaN(Date.parse(value)) || new Date(value).toISOString().slice(0, 10) !== value)) {
551
+ throw new Error(`Invalid fixed date on task ${task.id}`);
552
+ }
553
+ }
554
+ const fixedStart = task.fixedStartDate ? parseDateOnly(task.fixedStartDate) : void 0;
555
+ const fixedEnd = task.fixedEndDate ? parseDateOnly(task.fixedEndDate) : void 0;
556
+ if (!fixedStart && !fixedEnd) return range;
557
+ if (fixedStart && fixedEnd && (fixedStart > fixedEnd || task.type === "milestone" && +fixedStart !== +fixedEnd)) {
558
+ throw new Error(`Fixed dates conflict on task ${task.id}`);
559
+ }
560
+ if (task.type === "milestone") {
561
+ const date = fixedStart ?? fixedEnd;
562
+ return { start: date, end: date };
563
+ }
564
+ if (fixedStart && fixedEnd) return { start: fixedStart, end: fixedEnd };
565
+ if (!parent && preserveDuration) {
566
+ const duration = getTaskDuration(task.startDate, task.endDate, businessDays, weekendPredicate);
567
+ if (fixedStart) return { start: fixedStart, end: buildTaskRangeFromStart(fixedStart, duration, businessDays, weekendPredicate).end };
568
+ return { start: buildTaskRangeFromEnd(fixedEnd, duration, businessDays, weekendPredicate).start, end: fixedEnd };
569
+ }
570
+ if (fixedStart) return { start: fixedStart, end: range.end < fixedStart ? fixedStart : range.end };
571
+ return { start: range.start > fixedEnd ? fixedEnd : range.start, end: fixedEnd };
572
+ }
573
+ function resolveParentFixedDates(task, range, getTask, businessDays = false, weekendPredicate) {
574
+ if (!task.fixedStartDate && !task.fixedEndDate) return range;
575
+ let { start, end } = range;
576
+ for (const dep of task.dependencies ?? []) {
577
+ const targetStart = dep.type === "FS" || dep.type === "SS";
578
+ if (targetStart ? task.fixedStartDate : task.fixedEndDate) continue;
579
+ const predecessor = getTask(dep.taskId);
580
+ if (!predecessor) continue;
581
+ const anchor = predecessor.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : void 0;
582
+ const { predStart, predEnd } = normalizePredecessorDates({
583
+ ...predecessor,
584
+ startDate: anchor ?? predecessor.fixedStartDate ?? predecessor.startDate,
585
+ endDate: anchor ?? predecessor.fixedEndDate ?? predecessor.endDate
586
+ }, parseDateOnly);
587
+ const date = calculateSuccessorDate(predStart, predEnd, dep.type, getDependencyLag(dep), businessDays, weekendPredicate, task.type);
588
+ if (targetStart && date > start) start = date;
589
+ if (!targetStart && date > end) end = date;
590
+ }
591
+ return resolveFixedDates(task, { start, end }, true, businessDays, weekendPredicate);
592
+ }
593
+
546
594
  // src/core/scheduling/cascade.ts
547
595
  function parseCascadeDateInput(date) {
548
596
  if (date instanceof Date) {
@@ -731,8 +779,11 @@ function getTransitiveCascadeChain(changedTaskId, allTasks, firstLevelLinkTypes)
731
779
  }
732
780
  return chain;
733
781
  }
734
- function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays = false, weekendPredicate, context = createCascadeContext(allTasks)) {
782
+ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays = false, weekendPredicate, context = createCascadeContext(allTasks), rootIsRollup = false) {
735
783
  const { childrenByParentId, dependentsByPredecessorId, taskById } = context;
784
+ const originalMovedTask = taskById.get(movedTask.id) ?? movedTask;
785
+ const sameDelta = +newStart - +parseDateOnly(originalMovedTask.startDate) === +newEnd - +parseDateOnly(originalMovedTask.endDate);
786
+ ({ start: newStart, end: newEnd } = resolveFixedDates(originalMovedTask, { start: newStart, end: newEnd }, childrenByParentId.has(movedTask.id), businessDays, weekendPredicate, sameDelta));
736
787
  const normalizedMovedTask = normalizeTaskDependencyLags({
737
788
  ...movedTask,
738
789
  startDate: newStart.toISOString().split("T")[0],
@@ -745,7 +796,12 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
745
796
  updatedDates.set(movedTask.id, { start: newStart, end: newEnd });
746
797
  const resultMap = /* @__PURE__ */ new Map();
747
798
  resultMap.set(movedTask.id, normalizedMovedTask);
748
- const queue = [[movedTask.id, "direct"]];
799
+ const getCurrentTask = (id) => {
800
+ const task = taskById.get(id);
801
+ const range = updatedDates.get(id);
802
+ return task && range ? { ...task, startDate: range.start, endDate: range.end } : task;
803
+ };
804
+ const queue = [[movedTask.id, rootIsRollup ? "parent-recalc" : "direct"]];
749
805
  const childShifted = /* @__PURE__ */ new Set();
750
806
  let iterations = 0;
751
807
  const MAX_ITERATIONS = allTasks.length * 3;
@@ -754,7 +810,7 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
754
810
  const [currentId, arrivalMode] = queue.shift();
755
811
  const { start: currStart, end: currEnd } = updatedDates.get(currentId);
756
812
  const currentOriginal = taskById.get(currentId);
757
- if (arrivalMode !== "parent-recalc") {
813
+ if (arrivalMode !== "parent-recalc" && !(arrivalMode === "dependency" && (currentOriginal.fixedStartDate || currentOriginal.fixedEndDate))) {
758
814
  const children = childrenByParentId.get(currentId) ?? [];
759
815
  for (const child of children) {
760
816
  if (childShifted.has(child.id) || child.locked) continue;
@@ -783,6 +839,7 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
783
839
  childNewStart = new Date(childOrigStart.getTime() + startDeltaMs);
784
840
  childNewEnd = new Date(childOrigEnd.getTime() + endDeltaMs);
785
841
  }
842
+ ({ start: childNewStart, end: childNewEnd } = resolveFixedDates(child, { start: childNewStart, end: childNewEnd }, childrenByParentId.has(child.id), businessDays, weekendPredicate));
786
843
  const prev = updatedDates.get(child.id);
787
844
  if (prev && prev.start.getTime() === childNewStart.getTime() && prev.end.getTime() === childNewEnd.getTime()) {
788
845
  continue;
@@ -813,8 +870,10 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
813
870
  if (updatedDates.has(sib.id)) return updatedDates.get(sib.id);
814
871
  return { start: new Date(sib.startDate), end: new Date(sib.endDate) };
815
872
  });
816
- const minStart = new Date(Math.min(...siblingPositions.map((p) => p.start.getTime())));
817
- const maxEnd = new Date(Math.max(...siblingPositions.map((p) => p.end.getTime())));
873
+ const { start: minStart, end: maxEnd } = resolveParentFixedDates(parent, {
874
+ start: new Date(Math.min(...siblingPositions.map((p) => p.start.getTime()))),
875
+ end: new Date(Math.max(...siblingPositions.map((p) => p.end.getTime())))
876
+ }, getCurrentTask, businessDays, weekendPredicate);
818
877
  const prev = updatedDates.get(parentId);
819
878
  if (!prev || prev.start.getTime() !== minStart.getTime() || prev.end.getTime() !== maxEnd.getTime()) {
820
879
  updatedDates.set(parentId, { start: minStart, end: maxEnd });
@@ -870,6 +929,15 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
870
929
  weekendPredicate
871
930
  ));
872
931
  }
932
+ const dependentChildren = childrenByParentId.get(task.id);
933
+ if (dependentChildren?.length && (task.fixedStartDate || task.fixedEndDate)) {
934
+ const positions = dependentChildren.map((child) => updatedDates.get(child.id) ?? { start: parseDateOnly(child.startDate), end: parseDateOnly(child.endDate) });
935
+ ({ start: succNewStart, end: succNewEnd } = resolveParentFixedDates(task, {
936
+ start: new Date(Math.min(...positions.map((position) => +position.start))),
937
+ end: new Date(Math.max(...positions.map((position) => +position.end)))
938
+ }, getCurrentTask, businessDays, weekendPredicate));
939
+ }
940
+ ({ start: succNewStart, end: succNewEnd } = resolveFixedDates(task, { start: succNewStart, end: succNewEnd }, !!dependentChildren?.length, businessDays, weekendPredicate));
873
941
  const prev = updatedDates.get(task.id);
874
942
  if (prev && prev.start.getTime() === succNewStart.getTime() && prev.end.getTime() === succNewEnd.getTime()) {
875
943
  continue;
@@ -899,22 +967,23 @@ function getChildren(parentId, tasks) {
899
967
  function isTaskParent(taskId, tasks) {
900
968
  return tasks.some((t) => t.parentId === taskId);
901
969
  }
902
- function computeParentDates(parentId, tasks) {
970
+ function computeParentDates(parentId, tasks, businessDays = false, weekendPredicate) {
903
971
  const children = getChildren(parentId, tasks);
904
972
  if (children.length === 0) {
905
- const parent = tasks.find((t) => t.id === parentId);
906
- const start = parent ? new Date(parent.startDate) : /* @__PURE__ */ new Date();
907
- const end = parent ? new Date(parent.endDate) : /* @__PURE__ */ new Date();
908
- return { startDate: start, endDate: end };
973
+ const parent2 = tasks.find((t) => t.id === parentId);
974
+ const start = parent2 ? new Date(parent2.startDate) : /* @__PURE__ */ new Date();
975
+ const end = parent2 ? new Date(parent2.endDate) : /* @__PURE__ */ new Date();
976
+ const range2 = parent2 ? resolveFixedDates(parent2, { start, end }, false) : { start, end };
977
+ return { startDate: range2.start, endDate: range2.end };
909
978
  }
910
979
  const startDates = children.map((c) => new Date(c.startDate));
911
980
  const endDates = children.map((c) => new Date(c.endDate));
912
981
  const minTime = Math.min(...startDates.map((d) => d.getTime()));
913
982
  const maxTime = Math.max(...endDates.map((d) => d.getTime()));
914
- return {
915
- startDate: new Date(minTime),
916
- endDate: new Date(maxTime)
917
- };
983
+ const parent = tasks.find((t) => t.id === parentId);
984
+ const range = { start: new Date(minTime), end: new Date(maxTime) };
985
+ const resolved = parent ? resolveParentFixedDates(parent, range, (id) => tasks.find((task) => task.id === id), businessDays, weekendPredicate) : range;
986
+ return { startDate: resolved.start, endDate: resolved.end };
918
987
  }
919
988
  function computeParentProgress(parentId, tasks) {
920
989
  const children = getChildren(parentId, tasks);
@@ -1045,13 +1114,14 @@ function moveTaskWithCascade(taskId, newStart, snapshot, options) {
1045
1114
  }
1046
1115
  const businessDays = options?.businessDays ?? false;
1047
1116
  const weekendPredicate = options?.weekendPredicate;
1048
- const newRange = moveTaskRange(
1117
+ let newRange = moveTaskRange(
1049
1118
  task.startDate,
1050
1119
  task.endDate,
1051
1120
  newStart,
1052
1121
  businessDays,
1053
1122
  weekendPredicate
1054
1123
  );
1124
+ newRange = resolveFixedDates(task, newRange, snapshot.some((t) => t.parentId === task.id), businessDays, weekendPredicate);
1055
1125
  const updatedDependencies = recalculateIncomingLags(
1056
1126
  task,
1057
1127
  newRange.start,
@@ -1106,6 +1176,7 @@ function resizeTaskWithCascade(taskId, anchor, newDate, snapshot, options) {
1106
1176
  } else {
1107
1177
  newRange = { start: newDate, end: originalEnd };
1108
1178
  }
1179
+ newRange = resolveFixedDates(task, newRange, snapshot.some((t) => t.parentId === task.id), businessDays, weekendPredicate, false);
1109
1180
  const updatedDependencies = recalculateIncomingLags(
1110
1181
  task,
1111
1182
  newRange.start,
@@ -1196,6 +1267,14 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
1196
1267
  changedIds: [task.id]
1197
1268
  };
1198
1269
  }
1270
+ const fixedParent = !!(task.fixedStartDate || task.fixedEndDate) && snapshot.some((t) => t.parentId === task.id);
1271
+ if (fixedParent) {
1272
+ const rollup = computeParentDates(task.id, snapshot, businessDays, weekendPredicate);
1273
+ constrainedStart = rollup.startDate;
1274
+ constrainedEnd = rollup.endDate;
1275
+ } else {
1276
+ ({ start: constrainedStart, end: constrainedEnd } = resolveFixedDates(task, { start: constrainedStart, end: constrainedEnd }, false, businessDays, weekendPredicate));
1277
+ }
1199
1278
  const updatedDependencies = recalculateIncomingLags(
1200
1279
  task,
1201
1280
  constrainedStart,
@@ -1222,7 +1301,9 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
1222
1301
  constrainedEnd,
1223
1302
  snapshot,
1224
1303
  businessDays,
1225
- weekendPredicate
1304
+ weekendPredicate,
1305
+ void 0,
1306
+ fixedParent
1226
1307
  );
1227
1308
  const resultMap = /* @__PURE__ */ new Map();
1228
1309
  resultMap.set(recalculatedTask.id, recalculatedTask);
@@ -1236,6 +1317,100 @@ function recalculateTaskFromDependencies(taskId, snapshot, options) {
1236
1317
  };
1237
1318
  }
1238
1319
  function recalculateProjectSchedule(snapshot, options) {
1320
+ if (snapshot.some((task) => task.fixedStartDate || task.fixedEndDate)) {
1321
+ return recalculateFixedComponents(snapshot, options);
1322
+ }
1323
+ return recalculateProjectScheduleLegacy(snapshot, options);
1324
+ }
1325
+ function recalculateFixedComponents(snapshot, options) {
1326
+ const businessDays = options?.businessDays ?? false;
1327
+ const weekendPredicate = options?.weekendPredicate;
1328
+ const initial = new Map(snapshot.map((task) => [task.id, task]));
1329
+ const next = new Map(snapshot.map((task) => [task.id, task]));
1330
+ const children = /* @__PURE__ */ new Map();
1331
+ const outgoing = new Map(snapshot.map((task) => [task.id, /* @__PURE__ */ new Set()]));
1332
+ const neighbours = new Map(snapshot.map((task) => [task.id, /* @__PURE__ */ new Set()]));
1333
+ const connect = (from, to, ordered = true) => {
1334
+ if (!initial.has(from) || !initial.has(to)) return;
1335
+ if (ordered) outgoing.get(from).add(to);
1336
+ neighbours.get(from).add(to);
1337
+ neighbours.get(to).add(from);
1338
+ };
1339
+ for (const task of snapshot) {
1340
+ if (task.parentId && initial.has(task.parentId)) {
1341
+ const list = children.get(task.parentId) ?? [];
1342
+ list.push(task.id);
1343
+ children.set(task.parentId, list);
1344
+ connect(task.id, task.parentId);
1345
+ }
1346
+ }
1347
+ for (const task of snapshot) {
1348
+ for (const dependency of task.dependencies ?? []) {
1349
+ const predecessor = initial.get(dependency.taskId);
1350
+ const fixedSource = predecessor?.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : dependency.type === "FS" || dependency.type === "FF" ? predecessor?.fixedEndDate : predecessor?.fixedStartDate;
1351
+ const targetFixed = dependency.type === "FS" || dependency.type === "SS" ? task.fixedStartDate : task.fixedEndDate;
1352
+ const derivedParent = children.has(task.id) && !task.fixedStartDate && !task.fixedEndDate;
1353
+ connect(dependency.taskId, task.id, !fixedSource && !targetFixed && !derivedParent);
1354
+ }
1355
+ }
1356
+ const affected = new Set(snapshot.filter((task) => task.fixedStartDate || task.fixedEndDate).map((task) => task.id));
1357
+ const pending = [...affected];
1358
+ for (let i = 0; i < pending.length; i++) {
1359
+ for (const id of neighbours.get(pending[i])) if (!affected.has(id)) {
1360
+ affected.add(id);
1361
+ pending.push(id);
1362
+ }
1363
+ }
1364
+ const indegree = new Map([...affected].map((id) => [id, 0]));
1365
+ for (const id of affected) for (const successor of outgoing.get(id)) {
1366
+ indegree.set(successor, indegree.get(successor) + 1);
1367
+ }
1368
+ const queue = [...affected].filter((id) => indegree.get(id) === 0);
1369
+ for (let i = 0; i < queue.length; i++) {
1370
+ const id = queue[i];
1371
+ const task = next.get(id);
1372
+ const childIds = children.get(id);
1373
+ if (!task.locked) {
1374
+ let range = { start: parseDateOnly(task.startDate), end: parseDateOnly(task.endDate) };
1375
+ if (childIds?.length) {
1376
+ range = {
1377
+ start: new Date(Math.min(...childIds.map((child) => +parseDateOnly(next.get(child).startDate)))),
1378
+ end: new Date(Math.max(...childIds.map((child) => +parseDateOnly(next.get(child).endDate))))
1379
+ };
1380
+ range = resolveParentFixedDates(task, range, (key) => next.get(key), businessDays, weekendPredicate);
1381
+ } else if (task.dependencies?.length) {
1382
+ const duration = getTaskDuration(task.startDate, task.endDate, businessDays, weekendPredicate);
1383
+ let selected;
1384
+ for (const dependency of task.dependencies) {
1385
+ const predecessor = next.get(dependency.taskId);
1386
+ if (!predecessor) continue;
1387
+ const milestoneAnchor = predecessor.type === "milestone" ? predecessor.fixedStartDate ?? predecessor.fixedEndDate : void 0;
1388
+ const { predStart, predEnd } = normalizePredecessorDates({
1389
+ ...predecessor,
1390
+ startDate: milestoneAnchor ?? predecessor.fixedStartDate ?? predecessor.startDate,
1391
+ endDate: milestoneAnchor ?? predecessor.fixedEndDate ?? predecessor.endDate
1392
+ }, parseDateOnly);
1393
+ const date = calculateSuccessorDate(predStart, predEnd, dependency.type, getDependencyLag(dependency), businessDays, weekendPredicate, task.type);
1394
+ const candidate = dependency.type === "FS" || dependency.type === "SS" ? buildTaskRangeFromStart(date, duration, businessDays, weekendPredicate) : buildTaskRangeFromEnd(date, duration, businessDays, weekendPredicate);
1395
+ if (!selected || candidate.start > selected.start || +candidate.start === +selected.start && candidate.end > selected.end) selected = candidate;
1396
+ }
1397
+ if (selected) range = selected;
1398
+ }
1399
+ range = resolveFixedDates(task, range, !!childIds?.length, businessDays, weekendPredicate);
1400
+ next.set(id, { ...task, startDate: toIsoDate(range.start), endDate: toIsoDate(range.end) });
1401
+ }
1402
+ for (const successor of outgoing.get(id)) {
1403
+ indegree.set(successor, indegree.get(successor) - 1);
1404
+ if (indegree.get(successor) === 0) queue.push(successor);
1405
+ }
1406
+ }
1407
+ if (queue.length !== affected.size) throw new Error("Fixed date schedule contains a hierarchy/dependency cycle");
1408
+ for (const task of recalculateProjectScheduleLegacy(snapshot, options).changedTasks) {
1409
+ if (!affected.has(task.id)) next.set(task.id, task);
1410
+ }
1411
+ return createChangedResult(snapshot, [...next.values()]);
1412
+ }
1413
+ function recalculateProjectScheduleLegacy(snapshot, options) {
1239
1414
  const businessDays = options?.businessDays ?? false;
1240
1415
  const weekendPredicate = options?.weekendPredicate;
1241
1416
  const workingMap = new Map(snapshot.map((task) => [task.id, { ...task }]));
@@ -1359,12 +1534,13 @@ function reflowTasksOnModeSwitch(sourceTasks, toBusinessDays, weekendPredicate)
1359
1534
  true,
1360
1535
  weekendPredicate
1361
1536
  ) : buildTaskRangeFromStart(start, duration, false);
1362
- task.startDate = toISO(range.start);
1363
- task.endDate = toISO(range.end);
1537
+ const resolved = resolveFixedDates(task, range, false, toBusinessDays, weekendPredicate);
1538
+ task.startDate = toISO(resolved.start);
1539
+ task.endDate = toISO(resolved.end);
1364
1540
  }
1365
1541
  for (const task of tasks) {
1366
1542
  if (!isTaskParent(task.id, tasks)) continue;
1367
- const { startDate, endDate } = computeParentDates(task.id, tasks);
1543
+ const { startDate, endDate } = computeParentDates(task.id, tasks, toBusinessDays, weekendPredicate);
1368
1544
  task.startDate = toISO(startDate);
1369
1545
  task.endDate = toISO(endDate);
1370
1546
  }
@@ -2552,6 +2728,10 @@ function scaleTaskSubtreeDuration(parentId, targetDuration, snapshot, options) {
2552
2728
  const { context: ctx, space } = built;
2553
2729
  const solved = solveScale(ctx, space, targetDuration);
2554
2730
  const finalTasks = buildFinalTasks(ctx, solved.state, solved.layout, space);
2731
+ const fixedConflicts = [...finalTasks.values()].filter((task) => task.fixedStartDate && isoOfTaskDate(task.startDate) !== task.fixedStartDate || task.fixedEndDate && isoOfTaskDate(task.endDate) !== task.fixedEndDate);
2732
+ if (fixedConflicts.length) {
2733
+ return scaleFailure("FIXED_DATE_CONFLICT", fixedConflicts.map((task) => task.id));
2734
+ }
2555
2735
  const externalPolicy = resolvedOptions.externalDependencyPolicy ?? "subtree-only";
2556
2736
  let externalChanged = [];
2557
2737
  if (externalPolicy === "subtree-only") {