gantt-lib 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1180,7 +1180,6 @@ var TaskRow = import_react3.default.memo(
1180
1180
  if (!highlightExpiredTasks) return false;
1181
1181
  const now = /* @__PURE__ */ new Date();
1182
1182
  const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
1183
- const tomorrow = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 1));
1184
1183
  const taskStart = parseUTCDate(task.startDate);
1185
1184
  const taskEnd = parseUTCDate(task.endDate);
1186
1185
  const actualProgress = task.progress ?? 0;
@@ -1188,12 +1187,11 @@ var TaskRow = import_react3.default.memo(
1188
1187
  return false;
1189
1188
  }
1190
1189
  const msPerDay = 1e3 * 60 * 60 * 24;
1191
- const taskDuration = taskEnd.getTime() - taskStart.getTime() + msPerDay;
1192
- const isTaskEndingTodayOrTomorrow = today.getUTCFullYear() === taskEnd.getUTCFullYear() && today.getUTCMonth() === taskEnd.getUTCMonth() && today.getUTCDate() === taskEnd.getUTCDate() || tomorrow.getUTCFullYear() === taskEnd.getUTCFullYear() && tomorrow.getUTCMonth() === taskEnd.getUTCMonth() && tomorrow.getUTCDate() === taskEnd.getUTCDate();
1193
- const elapsedCutoff = isTaskEndingTodayOrTomorrow ? new Date(today.getTime() - msPerDay) : today;
1194
- const daysFromStart = elapsedCutoff.getTime() - taskStart.getTime();
1195
- const todayPosition = Math.min(100, Math.max(0, daysFromStart / taskDuration * 100));
1196
- return actualProgress < todayPosition;
1190
+ const duration = taskEnd.getTime() - taskStart.getTime() + msPerDay;
1191
+ const elapsedFromToday = today.getTime() - taskStart.getTime();
1192
+ const elapsed = Math.min(Math.max(0, elapsedFromToday), duration);
1193
+ const expected = elapsed / duration * 100;
1194
+ return actualProgress < expected;
1197
1195
  }, [task.startDate, task.endDate, task.progress, highlightExpiredTasks]);
1198
1196
  const { left, width } = (0, import_react3.useMemo)(
1199
1197
  () => calculateTaskBar(taskStartDate, taskEndDate, monthStart, dayWidth),
@@ -2657,18 +2655,51 @@ var GanttChart = (0, import_react12.forwardRef)(({
2657
2655
  const newStart = new Date(updatedTask.startDate);
2658
2656
  const newEnd = new Date(updatedTask.endDate);
2659
2657
  const datesChanged = origStart.getTime() !== newStart.getTime() || origEnd.getTime() !== newEnd.getTime();
2660
- if (!datesChanged || disableConstraints) {
2658
+ const now = /* @__PURE__ */ new Date();
2659
+ const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2660
+ const msPerDay = 1e3 * 60 * 60 * 24;
2661
+ let tasksToProcess;
2662
+ let cascadedTasksForCallback = [];
2663
+ if (!datesChanged) {
2661
2664
  onChange?.((currentTasks) => currentTasks.map((t) => t.id === updatedTask.id ? updatedTask : t));
2662
2665
  return;
2663
2666
  }
2664
- const cascadedTask = updatedTask;
2665
- const cascadedChain = cascadeByLinks(updatedTask.id, newStart, newEnd, tasks);
2666
- const allCascaded = [cascadedTask, ...cascadedChain];
2667
- onChange?.((currentTasks) => {
2668
- const m = new Map(allCascaded.map((t) => [t.id, t]));
2669
- return currentTasks.map((t) => m.get(t.id) ?? t);
2670
- });
2671
- onCascade?.(allCascaded);
2667
+ if (disableConstraints) {
2668
+ tasksToProcess = [updatedTask];
2669
+ cascadedTasksForCallback = [updatedTask];
2670
+ } else {
2671
+ const cascadedTask = updatedTask;
2672
+ const cascadedChain = cascadeByLinks(updatedTask.id, newStart, newEnd, tasks);
2673
+ tasksToProcess = [cascadedTask, ...cascadedChain];
2674
+ cascadedTasksForCallback = tasksToProcess;
2675
+ }
2676
+ console.log("[GanttChart handleTaskChange] IsExpired calculation:");
2677
+ for (const t of tasksToProcess) {
2678
+ const taskStart = new Date(t.startDate);
2679
+ const taskEnd = new Date(t.endDate);
2680
+ const actualProgress = t.progress ?? 0;
2681
+ if (actualProgress >= 100) {
2682
+ console.log(` [${t.id}] START=${t.startDate} END=${t.endDate} TODAY=${today.toISOString().split("T")[0]} PROGRESS=${actualProgress}% EXPECTED=N/A (completed) EXPIRED=NO`);
2683
+ continue;
2684
+ }
2685
+ const duration = taskEnd.getTime() - taskStart.getTime() + msPerDay;
2686
+ const elapsedFromToday = today.getTime() - taskStart.getTime();
2687
+ const elapsed = Math.min(Math.max(0, elapsedFromToday), duration);
2688
+ const expectedProgress = Math.min(100, Math.max(0, elapsed / duration * 100));
2689
+ const isExpired = actualProgress < expectedProgress;
2690
+ const durationDays = Math.round(duration / msPerDay);
2691
+ const elapsedDays = Math.round(elapsed / msPerDay);
2692
+ console.log(` [${t.id}] START=${t.startDate} END=${t.endDate} TODAY=${today.toISOString().split("T")[0]} PROGRESS=${actualProgress}% DURATION=${durationDays}d ELAPSED=${elapsedDays}d EXPECTED=${expectedProgress.toFixed(1)}% EXPIRED=${isExpired ? "YES" : "NO"}`);
2693
+ }
2694
+ if (disableConstraints) {
2695
+ onChange?.((currentTasks) => currentTasks.map((t) => t.id === updatedTask.id ? updatedTask : t));
2696
+ } else {
2697
+ onChange?.((currentTasks) => {
2698
+ const m = new Map(cascadedTasksForCallback.map((t) => [t.id, t]));
2699
+ return currentTasks.map((t) => m.get(t.id) ?? t);
2700
+ });
2701
+ onCascade?.(cascadedTasksForCallback);
2702
+ }
2672
2703
  }, [tasks, onChange, disableConstraints, onCascade]);
2673
2704
  const dependencyOverrides = (0, import_react12.useMemo)(() => {
2674
2705
  const map = new Map(cascadeOverrides);