gantt-lib 0.145.1 → 0.146.0

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.
@@ -1182,8 +1182,8 @@ function recalculateProjectSchedule(snapshot, options) {
1182
1182
  }
1183
1183
  }
1184
1184
  const queue = snapshot.filter((task) => (indegree.get(task.id) ?? 0) === 0).map((task) => task.id);
1185
- while (queue.length > 0) {
1186
- const currentId = queue.shift();
1185
+ for (let queueIndex = 0; queueIndex < queue.length; queueIndex++) {
1186
+ const currentId = queue[queueIndex];
1187
1187
  for (const successorId of successorIdsByTask.get(currentId) ?? []) {
1188
1188
  const nextIndegree = (indegree.get(successorId) ?? 0) - 1;
1189
1189
  indegree.set(successorId, nextIndegree);
@@ -1234,7 +1234,13 @@ function recalculateProjectSchedule(snapshot, options) {
1234
1234
  queue.push(successorId);
1235
1235
  }
1236
1236
  }
1237
- const parentsByDepth = snapshot.filter((task) => isTaskParent(task.id, snapshot)).map((task) => {
1237
+ const childrenByParent = /* @__PURE__ */ new Map();
1238
+ for (const task of snapshot) if (task.parentId) {
1239
+ const children = childrenByParent.get(task.parentId) ?? [];
1240
+ children.push(task.id);
1241
+ childrenByParent.set(task.parentId, children);
1242
+ }
1243
+ const parentsByDepth = snapshot.filter((task) => childrenByParent.has(task.id)).map((task) => {
1238
1244
  let depth = 0;
1239
1245
  let current = task.parentId ? workingMap.get(task.parentId) : void 0;
1240
1246
  while (current) {
@@ -1243,17 +1249,21 @@ function recalculateProjectSchedule(snapshot, options) {
1243
1249
  }
1244
1250
  return { taskId: task.id, depth };
1245
1251
  }).sort((left, right) => right.depth - left.depth);
1246
- const workingTasks = () => Array.from(workingMap.values());
1247
1252
  for (const { taskId } of parentsByDepth) {
1248
1253
  const parent = workingMap.get(taskId);
1249
1254
  if (!parent || parent.locked) {
1250
1255
  continue;
1251
1256
  }
1252
- const { startDate, endDate } = computeParentDates(taskId, workingTasks());
1257
+ let startTime = Infinity, endTime = -Infinity;
1258
+ for (const childId of childrenByParent.get(taskId)) {
1259
+ const child = workingMap.get(childId);
1260
+ startTime = Math.min(startTime, new Date(child.startDate).getTime());
1261
+ endTime = Math.max(endTime, new Date(child.endDate).getTime());
1262
+ }
1253
1263
  workingMap.set(taskId, {
1254
1264
  ...parent,
1255
- startDate: toIsoDate(startDate),
1256
- endDate: toIsoDate(endDate)
1265
+ startDate: toIsoDate(new Date(startTime)),
1266
+ endDate: toIsoDate(new Date(endTime))
1257
1267
  });
1258
1268
  }
1259
1269
  return createChangedResult(snapshot, Array.from(workingMap.values()));