gantt-lib 0.7.0 → 0.7.1

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.d.mts CHANGED
@@ -678,6 +678,17 @@ declare const getMonthSpans: (dateRange: Date[]) => Array<{
678
678
  * @returns Formatted date string in DD.MM format
679
679
  */
680
680
  declare const formatDateLabel: (date: Date | string) => string;
681
+ /**
682
+ * Normalize task dates to ensure startDate is always before or equal to endDate.
683
+ * If dates are swapped (endDate < startDate), they are automatically swapped.
684
+ * @param startDate - Task start date (string or Date)
685
+ * @param endDate - Task end date (string or Date)
686
+ * @returns Object with normalized startDate and endDate as ISO date strings (YYYY-MM-DD)
687
+ */
688
+ declare const normalizeTaskDates: (startDate: string | Date, endDate: string | Date) => {
689
+ startDate: string;
690
+ endDate: string;
691
+ };
681
692
 
682
693
  /**
683
694
  * Build adjacency list for dependency graph (task -> successors)
@@ -936,6 +947,7 @@ declare function flattenHierarchy<T extends Task$1>(tasks: T[]): T[];
936
947
  * Normalize hierarchy-aware display fields.
937
948
  * Parent task dates and progress are always recomputed from children,
938
949
  * taking precedence over any hardcoded parent values from the input.
950
+ * Also normalizes task dates to ensure startDate is always before or equal to endDate.
939
951
  */
940
952
  declare function normalizeHierarchyTasks<T extends Task$1>(tasks: T[]): T[];
941
953
 
@@ -952,4 +964,4 @@ interface VisibleReorderPosition {
952
964
  */
953
965
  declare function getVisibleReorderPosition(orderedTasks: TaskLike[], visibleTasks: TaskLike[], movedTaskId: string, originVisibleIndex: number, dropVisibleIndex: number): VisibleReorderPosition | null;
954
966
 
955
- export { Button, type ButtonProps, Calendar, type CalendarProps, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekendBlock, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, detectCycles, detectEdgeZone, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, isTaskParent, isToday, isWeekend, normalizeHierarchyTasks, parseUTCDate, pixelsToDate, recalculateIncomingLags, removeDependenciesBetweenTasks, useTaskDrag, validateDependencies };
967
+ export { Button, type ButtonProps, Calendar, type CalendarProps, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekendBlock, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, detectCycles, detectEdgeZone, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, isTaskParent, isToday, isWeekend, normalizeHierarchyTasks, normalizeTaskDates, parseUTCDate, pixelsToDate, recalculateIncomingLags, removeDependenciesBetweenTasks, useTaskDrag, validateDependencies };
package/dist/index.d.ts CHANGED
@@ -678,6 +678,17 @@ declare const getMonthSpans: (dateRange: Date[]) => Array<{
678
678
  * @returns Formatted date string in DD.MM format
679
679
  */
680
680
  declare const formatDateLabel: (date: Date | string) => string;
681
+ /**
682
+ * Normalize task dates to ensure startDate is always before or equal to endDate.
683
+ * If dates are swapped (endDate < startDate), they are automatically swapped.
684
+ * @param startDate - Task start date (string or Date)
685
+ * @param endDate - Task end date (string or Date)
686
+ * @returns Object with normalized startDate and endDate as ISO date strings (YYYY-MM-DD)
687
+ */
688
+ declare const normalizeTaskDates: (startDate: string | Date, endDate: string | Date) => {
689
+ startDate: string;
690
+ endDate: string;
691
+ };
681
692
 
682
693
  /**
683
694
  * Build adjacency list for dependency graph (task -> successors)
@@ -936,6 +947,7 @@ declare function flattenHierarchy<T extends Task$1>(tasks: T[]): T[];
936
947
  * Normalize hierarchy-aware display fields.
937
948
  * Parent task dates and progress are always recomputed from children,
938
949
  * taking precedence over any hardcoded parent values from the input.
950
+ * Also normalizes task dates to ensure startDate is always before or equal to endDate.
939
951
  */
940
952
  declare function normalizeHierarchyTasks<T extends Task$1>(tasks: T[]): T[];
941
953
 
@@ -952,4 +964,4 @@ interface VisibleReorderPosition {
952
964
  */
953
965
  declare function getVisibleReorderPosition(orderedTasks: TaskLike[], visibleTasks: TaskLike[], movedTaskId: string, originVisibleIndex: number, dropVisibleIndex: number): VisibleReorderPosition | null;
954
966
 
955
- export { Button, type ButtonProps, Calendar, type CalendarProps, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekendBlock, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, detectCycles, detectEdgeZone, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, isTaskParent, isToday, isWeekend, normalizeHierarchyTasks, parseUTCDate, pixelsToDate, recalculateIncomingLags, removeDependenciesBetweenTasks, useTaskDrag, validateDependencies };
967
+ export { Button, type ButtonProps, Calendar, type CalendarProps, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekendBlock, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, detectCycles, detectEdgeZone, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, isTaskParent, isToday, isWeekend, normalizeHierarchyTasks, normalizeTaskDates, parseUTCDate, pixelsToDate, recalculateIncomingLags, removeDependenciesBetweenTasks, useTaskDrag, validateDependencies };
package/dist/index.js CHANGED
@@ -77,6 +77,7 @@ __export(index_exports, {
77
77
  isToday: () => isToday,
78
78
  isWeekend: () => isWeekend,
79
79
  normalizeHierarchyTasks: () => normalizeHierarchyTasks,
80
+ normalizeTaskDates: () => normalizeTaskDates,
80
81
  parseUTCDate: () => parseUTCDate,
81
82
  pixelsToDate: () => pixelsToDate,
82
83
  recalculateIncomingLags: () => recalculateIncomingLags,
@@ -228,6 +229,20 @@ var formatDateLabel = (date) => {
228
229
  const month = String(parsed.getUTCMonth() + 1).padStart(2, "0");
229
230
  return `${day}.${month}`;
230
231
  };
232
+ var normalizeTaskDates = (startDate, endDate) => {
233
+ const start = parseUTCDate(startDate);
234
+ const end = parseUTCDate(endDate);
235
+ if (end.getTime() < start.getTime()) {
236
+ return {
237
+ startDate: end.toISOString().split("T")[0],
238
+ endDate: start.toISOString().split("T")[0]
239
+ };
240
+ }
241
+ return {
242
+ startDate: start.toISOString().split("T")[0],
243
+ endDate: end.toISOString().split("T")[0]
244
+ };
245
+ };
231
246
 
232
247
  // src/utils/dependencyUtils.ts
233
248
  function buildAdjacencyList(tasks) {
@@ -608,7 +623,10 @@ function flattenHierarchy(tasks) {
608
623
  return result;
609
624
  }
610
625
  function normalizeHierarchyTasks(tasks) {
611
- const orderedTasks = flattenHierarchy(tasks).map((task) => ({ ...task }));
626
+ const orderedTasks = flattenHierarchy(tasks).map((task) => {
627
+ const { startDate, endDate } = normalizeTaskDates(task.startDate, task.endDate);
628
+ return { ...task, startDate, endDate };
629
+ });
612
630
  for (const task of [...orderedTasks].reverse()) {
613
631
  if (!isTaskParent(task.id, orderedTasks)) continue;
614
632
  const { startDate, endDate } = computeParentDates(task.id, orderedTasks);
@@ -2861,7 +2879,11 @@ var TaskListRow = import_react10.default.memo(
2861
2879
  const durationMs = origEnd.getTime() - origStart.getTime();
2862
2880
  const newStart = /* @__PURE__ */ new Date(newDateISO + "T00:00:00Z");
2863
2881
  const newEnd = new Date(newStart.getTime() + durationMs);
2864
- onTaskChange?.({ ...task, startDate: newDateISO, endDate: newEnd.toISOString().split("T")[0] });
2882
+ const { startDate: normalizedStart, endDate: normalizedEnd } = normalizeTaskDates(
2883
+ newDateISO,
2884
+ newEnd.toISOString().split("T")[0]
2885
+ );
2886
+ onTaskChange?.({ ...task, startDate: normalizedStart, endDate: normalizedEnd });
2865
2887
  }, [task, onTaskChange]);
2866
2888
  const handleEndDateChange = (0, import_react10.useCallback)((newDateISO) => {
2867
2889
  if (!newDateISO) return;
@@ -2870,7 +2892,11 @@ var TaskListRow = import_react10.default.memo(
2870
2892
  const durationMs = origEnd.getTime() - origStart.getTime();
2871
2893
  const newEnd = /* @__PURE__ */ new Date(newDateISO + "T00:00:00Z");
2872
2894
  const newStart = new Date(newEnd.getTime() - durationMs);
2873
- onTaskChange?.({ ...task, startDate: newStart.toISOString().split("T")[0], endDate: newDateISO });
2895
+ const { startDate: normalizedStart, endDate: normalizedEnd } = normalizeTaskDates(
2896
+ newStart.toISOString().split("T")[0],
2897
+ newDateISO
2898
+ );
2899
+ onTaskChange?.({ ...task, startDate: normalizedStart, endDate: normalizedEnd });
2874
2900
  }, [task, onTaskChange]);
2875
2901
  const handleRowClickInternal = (0, import_react10.useCallback)(() => {
2876
2902
  onRowClick?.(task.id);
@@ -4433,6 +4459,7 @@ Button.displayName = "Button";
4433
4459
  isToday,
4434
4460
  isWeekend,
4435
4461
  normalizeHierarchyTasks,
4462
+ normalizeTaskDates,
4436
4463
  parseUTCDate,
4437
4464
  pixelsToDate,
4438
4465
  recalculateIncomingLags,