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.mjs CHANGED
@@ -1103,7 +1103,6 @@ var TaskRow = React2.memo(
1103
1103
  if (!highlightExpiredTasks) return false;
1104
1104
  const now = /* @__PURE__ */ new Date();
1105
1105
  const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
1106
- const tomorrow = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 1));
1107
1106
  const taskStart = parseUTCDate(task.startDate);
1108
1107
  const taskEnd = parseUTCDate(task.endDate);
1109
1108
  const actualProgress = task.progress ?? 0;
@@ -1111,12 +1110,11 @@ var TaskRow = React2.memo(
1111
1110
  return false;
1112
1111
  }
1113
1112
  const msPerDay = 1e3 * 60 * 60 * 24;
1114
- const taskDuration = taskEnd.getTime() - taskStart.getTime() + msPerDay;
1115
- 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();
1116
- const elapsedCutoff = isTaskEndingTodayOrTomorrow ? new Date(today.getTime() - msPerDay) : today;
1117
- const daysFromStart = elapsedCutoff.getTime() - taskStart.getTime();
1118
- const todayPosition = Math.min(100, Math.max(0, daysFromStart / taskDuration * 100));
1119
- return actualProgress < todayPosition;
1113
+ const duration = taskEnd.getTime() - taskStart.getTime() + msPerDay;
1114
+ const elapsedFromToday = today.getTime() - taskStart.getTime();
1115
+ const elapsed = Math.min(Math.max(0, elapsedFromToday), duration);
1116
+ const expected = elapsed / duration * 100;
1117
+ return actualProgress < expected;
1120
1118
  }, [task.startDate, task.endDate, task.progress, highlightExpiredTasks]);
1121
1119
  const { left, width } = useMemo2(
1122
1120
  () => calculateTaskBar(taskStartDate, taskEndDate, monthStart, dayWidth),
@@ -2598,18 +2596,51 @@ var GanttChart = forwardRef(({
2598
2596
  const newStart = new Date(updatedTask.startDate);
2599
2597
  const newEnd = new Date(updatedTask.endDate);
2600
2598
  const datesChanged = origStart.getTime() !== newStart.getTime() || origEnd.getTime() !== newEnd.getTime();
2601
- if (!datesChanged || disableConstraints) {
2599
+ const now = /* @__PURE__ */ new Date();
2600
+ const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2601
+ const msPerDay = 1e3 * 60 * 60 * 24;
2602
+ let tasksToProcess;
2603
+ let cascadedTasksForCallback = [];
2604
+ if (!datesChanged) {
2602
2605
  onChange?.((currentTasks) => currentTasks.map((t) => t.id === updatedTask.id ? updatedTask : t));
2603
2606
  return;
2604
2607
  }
2605
- const cascadedTask = updatedTask;
2606
- const cascadedChain = cascadeByLinks(updatedTask.id, newStart, newEnd, tasks);
2607
- const allCascaded = [cascadedTask, ...cascadedChain];
2608
- onChange?.((currentTasks) => {
2609
- const m = new Map(allCascaded.map((t) => [t.id, t]));
2610
- return currentTasks.map((t) => m.get(t.id) ?? t);
2611
- });
2612
- onCascade?.(allCascaded);
2608
+ if (disableConstraints) {
2609
+ tasksToProcess = [updatedTask];
2610
+ cascadedTasksForCallback = [updatedTask];
2611
+ } else {
2612
+ const cascadedTask = updatedTask;
2613
+ const cascadedChain = cascadeByLinks(updatedTask.id, newStart, newEnd, tasks);
2614
+ tasksToProcess = [cascadedTask, ...cascadedChain];
2615
+ cascadedTasksForCallback = tasksToProcess;
2616
+ }
2617
+ console.log("[GanttChart handleTaskChange] IsExpired calculation:");
2618
+ for (const t of tasksToProcess) {
2619
+ const taskStart = new Date(t.startDate);
2620
+ const taskEnd = new Date(t.endDate);
2621
+ const actualProgress = t.progress ?? 0;
2622
+ if (actualProgress >= 100) {
2623
+ console.log(` [${t.id}] START=${t.startDate} END=${t.endDate} TODAY=${today.toISOString().split("T")[0]} PROGRESS=${actualProgress}% EXPECTED=N/A (completed) EXPIRED=NO`);
2624
+ continue;
2625
+ }
2626
+ const duration = taskEnd.getTime() - taskStart.getTime() + msPerDay;
2627
+ const elapsedFromToday = today.getTime() - taskStart.getTime();
2628
+ const elapsed = Math.min(Math.max(0, elapsedFromToday), duration);
2629
+ const expectedProgress = Math.min(100, Math.max(0, elapsed / duration * 100));
2630
+ const isExpired = actualProgress < expectedProgress;
2631
+ const durationDays = Math.round(duration / msPerDay);
2632
+ const elapsedDays = Math.round(elapsed / msPerDay);
2633
+ 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"}`);
2634
+ }
2635
+ if (disableConstraints) {
2636
+ onChange?.((currentTasks) => currentTasks.map((t) => t.id === updatedTask.id ? updatedTask : t));
2637
+ } else {
2638
+ onChange?.((currentTasks) => {
2639
+ const m = new Map(cascadedTasksForCallback.map((t) => [t.id, t]));
2640
+ return currentTasks.map((t) => m.get(t.id) ?? t);
2641
+ });
2642
+ onCascade?.(cascadedTasksForCallback);
2643
+ }
2613
2644
  }, [tasks, onChange, disableConstraints, onCascade]);
2614
2645
  const dependencyOverrides = useMemo9(() => {
2615
2646
  const map = new Map(cascadeOverrides);