gantt-lib 0.88.2 → 0.90.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.
package/dist/index.mjs CHANGED
@@ -5027,10 +5027,13 @@ var TaskListRow = React9.memo(
5027
5027
  }
5028
5028
  const clampedValue = Math.max(0, Math.min(100, progressValue));
5029
5029
  if ((clampedValue === 100 || clampedValue === 0) && isTaskParent(task.id, allTasks)) {
5030
- const children = getChildren(task.id, allTasks);
5030
+ const descendants = getAllDescendants(task.id, allTasks);
5031
5031
  const updatedTasks = [
5032
5032
  { ...task, progress: clampedValue },
5033
- ...children.map((child) => ({ ...child, progress: clampedValue }))
5033
+ ...descendants.map((descendant) => ({
5034
+ ...descendant,
5035
+ progress: clampedValue
5036
+ }))
5034
5037
  ];
5035
5038
  onTasksChange?.(updatedTasks);
5036
5039
  } else {
@@ -5053,11 +5056,11 @@ var TaskListRow = React9.memo(
5053
5056
  progressConfirmedRef.current = true;
5054
5057
  const clampedValue = Math.max(0, Math.min(100, progressValue));
5055
5058
  if ((clampedValue === 100 || clampedValue === 0) && isTaskParent(task.id, allTasks)) {
5056
- const children = getChildren(task.id, allTasks);
5059
+ const descendants = getAllDescendants(task.id, allTasks);
5057
5060
  const updatedTasks = [
5058
5061
  { ...task, progress: clampedValue },
5059
- ...children.map((child) => ({
5060
- ...child,
5062
+ ...descendants.map((descendant) => ({
5063
+ ...descendant,
5061
5064
  progress: clampedValue
5062
5065
  }))
5063
5066
  ];
@@ -5264,16 +5267,9 @@ var TaskListRow = React9.memo(
5264
5267
  const handleApplyColor = useCallback4(
5265
5268
  (color) => {
5266
5269
  if (!onTasksChange) return;
5267
- const descendantIds = /* @__PURE__ */ new Set();
5268
- if (isParent) {
5269
- const stack = getChildren(task.id, allTasks);
5270
- while (stack.length > 0) {
5271
- const current = stack.shift();
5272
- if (!current || descendantIds.has(current.id)) continue;
5273
- descendantIds.add(current.id);
5274
- stack.push(...getChildren(current.id, allTasks));
5275
- }
5276
- }
5270
+ const descendantIds = new Set(
5271
+ isParent ? getAllDescendants(task.id, allTasks).map((descendant) => descendant.id) : []
5272
+ );
5277
5273
  const updatedTasks = [
5278
5274
  { ...task, color },
5279
5275
  ...allTasks.filter((candidate) => descendantIds.has(candidate.id)).map((candidate) => ({ ...candidate, color }))
@@ -9507,6 +9503,7 @@ function TaskGanttChartInner(props, ref) {
9507
9503
  const containerRef = useRef9(null);
9508
9504
  const scrollContainerRef = useRef9(null);
9509
9505
  const scrollContentRef = useRef9(null);
9506
+ const clearSelectedTaskTimeoutRef = useRef9(null);
9510
9507
  const [selectedTaskId, setSelectedTaskId] = useState9(null);
9511
9508
  const [taskListHasRightShadow, setTaskListHasRightShadow] = useState9(false);
9512
9509
  const [selectedChip, setSelectedChip] = useState9(null);
@@ -9518,7 +9515,17 @@ function TaskGanttChartInner(props, ref) {
9518
9515
  () => createCustomDayPredicate({ customDays, isWeekend: isWeekend3 }),
9519
9516
  [customDays, isWeekend3]
9520
9517
  );
9521
- const dateRange = useMemo10(() => getMultiMonthDays(normalizedTasks), [normalizedTasks]);
9518
+ const dateRangeTasks = useMemo10(() => {
9519
+ if (!showBaseline) {
9520
+ return normalizedTasks;
9521
+ }
9522
+ return normalizedTasks.map((task) => ({
9523
+ ...task,
9524
+ startDate: task.baselineStartDate && parseUTCDate(task.baselineStartDate).getTime() < parseUTCDate(task.startDate).getTime() ? task.baselineStartDate : task.startDate,
9525
+ endDate: task.baselineEndDate && parseUTCDate(task.baselineEndDate).getTime() > parseUTCDate(task.endDate).getTime() ? task.baselineEndDate : task.endDate
9526
+ }));
9527
+ }, [normalizedTasks, showBaseline]);
9528
+ const dateRange = useMemo10(() => getMultiMonthDays(dateRangeTasks), [dateRangeTasks]);
9522
9529
  const [validationResult, setValidationResult] = useState9(null);
9523
9530
  const [cascadeOverrides, setCascadeOverrides] = useState9(/* @__PURE__ */ new Map());
9524
9531
  const gridWidth = useMemo10(
@@ -9626,7 +9633,7 @@ function TaskGanttChartInner(props, ref) {
9626
9633
  const scrollLeft = Math.round(taskOffset - dayWidth * 2);
9627
9634
  container.scrollTo({ left: Math.max(0, scrollLeft), behavior: "smooth" });
9628
9635
  }, [tasks, dateRange, dayWidth]);
9629
- const scrollToRow = useCallback8((taskId) => {
9636
+ const scrollToRow = useCallback8((taskId, options = {}) => {
9630
9637
  const container = scrollContainerRef.current;
9631
9638
  if (!container) return;
9632
9639
  const task = tasks.find((t) => t.id === taskId);
@@ -9635,8 +9642,25 @@ function TaskGanttChartInner(props, ref) {
9635
9642
  if (rowIndex === -1) return;
9636
9643
  const paddedRowIndex = Math.max(0, rowIndex - SCROLL_TO_ROW_CONTEXT_ROWS);
9637
9644
  const scrollTop = Math.max(0, rowHeight * paddedRowIndex);
9638
- setSelectedTaskId(taskId);
9639
- container.scrollTo({ top: scrollTop, behavior: "smooth" });
9645
+ const {
9646
+ select = true,
9647
+ behavior = "smooth",
9648
+ clearSelectionAfterMs
9649
+ } = options;
9650
+ if (clearSelectedTaskTimeoutRef.current !== null) {
9651
+ window.clearTimeout(clearSelectedTaskTimeoutRef.current);
9652
+ clearSelectedTaskTimeoutRef.current = null;
9653
+ }
9654
+ if (select) {
9655
+ setSelectedTaskId(taskId);
9656
+ if (typeof clearSelectionAfterMs === "number" && clearSelectionAfterMs >= 0) {
9657
+ clearSelectedTaskTimeoutRef.current = window.setTimeout(() => {
9658
+ setSelectedTaskId((current) => current === taskId ? null : current);
9659
+ clearSelectedTaskTimeoutRef.current = null;
9660
+ }, clearSelectionAfterMs);
9661
+ }
9662
+ }
9663
+ container.scrollTo({ top: scrollTop, behavior });
9640
9664
  }, [tasks, visibleTasks, rowHeight]);
9641
9665
  const [dragGuideLines, setDragGuideLines] = useState9(null);
9642
9666
  const [draggedTaskOverride, setDraggedTaskOverride] = useState9(null);
@@ -9646,6 +9670,11 @@ function TaskGanttChartInner(props, ref) {
9646
9670
  setValidationResult(result);
9647
9671
  onValidateDependencies?.(result);
9648
9672
  }, [tasks, onValidateDependencies]);
9673
+ useEffect9(() => () => {
9674
+ if (clearSelectedTaskTimeoutRef.current !== null) {
9675
+ window.clearTimeout(clearSelectedTaskTimeoutRef.current);
9676
+ }
9677
+ }, []);
9649
9678
  const handleTaskChange = useCallback8((updatedTasks) => {
9650
9679
  const updatedTask = updatedTasks[0];
9651
9680
  if (!updatedTask) return;
@@ -9964,7 +9993,6 @@ function TaskGanttChartInner(props, ref) {
9964
9993
  if (!hasDirectChildren) return;
9965
9994
  const changedTasks = [];
9966
9995
  for (const task of tasks) {
9967
- if (task.id === taskId) continue;
9968
9996
  const nextParentId = task.parentId === taskId ? parentTask.parentId : task.parentId;
9969
9997
  const nextDependencies = task.dependencies?.filter((dep) => dep.taskId !== taskId);
9970
9998
  if (nextParentId !== task.parentId || nextDependencies?.length !== task.dependencies?.length) {
@@ -9978,8 +10006,7 @@ function TaskGanttChartInner(props, ref) {
9978
10006
  if (changedTasks.length > 0) {
9979
10007
  onTasksChange?.(changedTasks);
9980
10008
  }
9981
- onDelete?.(taskId);
9982
- }, [tasks, onTasksChange, onDelete, onUngroupTask]);
10009
+ }, [tasks, onTasksChange, onUngroupTask]);
9983
10010
  const panStateRef = useRef9(null);
9984
10011
  const handlePanStart = useCallback8((e) => {
9985
10012
  if (e.button !== 0) return;