gantt-lib 0.19.0 → 0.20.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.d.mts CHANGED
@@ -1,6 +1,205 @@
1
1
  import React$1 from 'react';
2
2
  import * as RadixPopover from '@radix-ui/react-popover';
3
3
 
4
+ /**
5
+ * Parse date string as UTC to prevent DST issues
6
+ * @param date - Date string or Date object
7
+ * @returns Date object representing UTC midnight
8
+ * @throws Error if date string is invalid
9
+ */
10
+ declare const parseUTCDate: (date: string | Date) => Date;
11
+ /**
12
+ * Get all days in the month of given date (UTC)
13
+ * @param date - Reference date (any day in the target month)
14
+ * @returns Array of Date objects for each day in the month
15
+ */
16
+ declare const getMonthDays: (date: Date | string) => Date[];
17
+ /**
18
+ * Calculate day offset from month start (0-based)
19
+ * @param date - The date to calculate offset for
20
+ * @param monthStart - The start of the month as reference
21
+ * @returns Number of days from month start (negative if date is before month start)
22
+ */
23
+ declare const getDayOffset: (date: Date, monthStart: Date) => number;
24
+ /**
25
+ * Check if date is today (local timezone comparison)
26
+ * Uses local time to determine today's date boundary so the result matches
27
+ * the user's timezone rather than UTC (prevents off-by-one errors at midnight).
28
+ * @param date - Date to check
29
+ * @returns True if date is today, false otherwise
30
+ */
31
+ declare const isToday: (date: Date) => boolean;
32
+ /**
33
+ * Check if date is a weekend day (Saturday or Sunday)
34
+ * @param date - Date to check
35
+ * @returns True if date is Saturday (6) or Sunday (0), false otherwise
36
+ */
37
+ declare const isWeekend: (date: Date) => boolean;
38
+ /**
39
+ * Create a UTC-safe key for Set-based date lookup
40
+ * @param date - Date object to create key from
41
+ * @returns String key in "YYYY-M-D" format using UTC date components
42
+ *
43
+ * Example:
44
+ * createDateKey(new Date(Date.UTC(2026, 2, 15))) // "2026-2-15"
45
+ *
46
+ * Note: Uses UTC methods to prevent DST and timezone issues.
47
+ * Month is 0-indexed (0=January, 11=December) per JavaScript Date convention.
48
+ */
49
+ declare const createDateKey: (date: Date) => string;
50
+ /**
51
+ * Configuration for a single custom day
52
+ */
53
+ interface CustomDayConfig {
54
+ /** The date to customize */
55
+ date: Date;
56
+ /** Type of day: 'weekend' marks as weekend, 'workday' marks as workday */
57
+ type: 'weekend' | 'workday';
58
+ }
59
+ /**
60
+ * Configuration for custom day predicate
61
+ */
62
+ interface CustomDayPredicateConfig {
63
+ /** Array of custom day configurations with explicit types */
64
+ customDays?: CustomDayConfig[];
65
+ /** Optional base weekend predicate (checked before customDays overrides) */
66
+ isWeekend?: (date: Date) => boolean;
67
+ }
68
+ /**
69
+ * Create a weekend predicate with unified custom day support
70
+ *
71
+ * Precedence order (highest to lowest):
72
+ * 1. customDays.type='workday' - explicit workday (highest override)
73
+ * 2. customDays.type='weekend' - explicit weekend (override)
74
+ * 3. isWeekend (base predicate) - custom base logic
75
+ * 4. default - Saturday (6) and Sunday (0)
76
+ *
77
+ * @param config - Custom day configuration with array and optional predicate
78
+ * @returns Predicate function (date: Date) => boolean
79
+ *
80
+ * Example:
81
+ * // Simple holidays + working Saturdays
82
+ * const predicate = createCustomDayPredicate({
83
+ * customDays: [
84
+ * { date: new Date(Date.UTC(2026, 2, 15)), type: 'workday' }, // working Saturday
85
+ * { date: new Date(Date.UTC(2026, 0, 1)), type: 'weekend' } // holiday Tuesday
86
+ * ]
87
+ * });
88
+ *
89
+ * // 4-day work week + occasional overrides
90
+ * const predicate2 = createCustomDayPredicate({
91
+ * isWeekend: (date) => {
92
+ * const day = date.getUTCDay();
93
+ * return day === 0 || day === 6 || day === 5; // Sun+Sat+Fri
94
+ * },
95
+ * customDays: [
96
+ * { date: new Date(Date.UTC(2026, 2, 10)), type: 'workday' } // working Friday
97
+ * ]
98
+ * });
99
+ */
100
+ declare const createCustomDayPredicate: (config: CustomDayPredicateConfig) => ((date: Date) => boolean);
101
+ /**
102
+ * Calculate multi-month date range from task dates
103
+ * Expands range to include full months with padding on both ends for drag flexibility
104
+ * Adds 1 month before and 2 months after the task range
105
+ * @param tasks - Array of tasks with startDate and endDate
106
+ * @returns Array of Date objects for all days in the expanded range
107
+ */
108
+ declare const getMultiMonthDays: (tasks: Array<{
109
+ startDate: string | Date;
110
+ endDate: string | Date;
111
+ }>) => Date[];
112
+ /**
113
+ * Calculate month spans within a date range
114
+ * @param dateRange - Array of Date objects representing the full range
115
+ * @returns Array of month span objects with month, days count, and start index
116
+ */
117
+ declare const getMonthSpans: (dateRange: Date[]) => Array<{
118
+ month: Date;
119
+ days: number;
120
+ startIndex: number;
121
+ }>;
122
+ /**
123
+ * Format date as DD.MM (e.g., 25.03 for March 25th)
124
+ * @param date - Date to format
125
+ * @returns Formatted date string in DD.MM format
126
+ */
127
+ declare const formatDateLabel: (date: Date | string) => string;
128
+ /**
129
+ * Return block boundaries for week-view, splitting on month boundaries.
130
+ * Each block represents a column in the week-view header.
131
+ * Blocks are typically 7 days, but split on month boundaries so
132
+ * the first/last block of a month may be smaller.
133
+ *
134
+ * @param days - Array of dates from getMultiMonthDays
135
+ * @returns Array of start dates for each block, with actual block sizes
136
+ */
137
+ interface WeekBlock {
138
+ /** Start date of this block */
139
+ startDate: Date;
140
+ /** Number of days in this block (≤7, splits on month boundaries) */
141
+ days: number;
142
+ }
143
+ /**
144
+ * Split the date range into blocks, primarily 7-day weeks,
145
+ * but splitting blocks on month boundaries for accurate month spans.
146
+ */
147
+ declare const getWeekBlocks: (days: Date[]) => WeekBlock[];
148
+ /**
149
+ * Represents a month span in week-view header row 1.
150
+ * In week-view, the width is calculated from actual day counts,
151
+ * not from a fixed column count.
152
+ */
153
+ interface WeekSpan {
154
+ /** First day of the calendar month (UTC) */
155
+ month: Date;
156
+ /** Total number of days this month occupies across all blocks */
157
+ days: number;
158
+ /** Start index in the blocks array */
159
+ startIndex: number;
160
+ }
161
+ /**
162
+ * Calculate month spans based on week-block boundaries.
163
+ * Groups consecutive blocks that belong to the same month.
164
+ */
165
+ declare const getWeekSpans: (days: Date[]) => WeekSpan[];
166
+ interface MonthBlock {
167
+ /** Первый день месяца (UTC) */
168
+ startDate: Date;
169
+ /** Количество дней в этом месяце внутри dateRange (может быть меньше при обрезке) */
170
+ days: number;
171
+ }
172
+ /**
173
+ * Разбивает dateRange на блоки по месяцам.
174
+ * Каждый блок = один месяц (колонка в строке 2 month-view шапки).
175
+ * Блок на краях может быть неполным если dateRange начинается/заканчивается не с 1-го числа.
176
+ */
177
+ declare const getMonthBlocks: (days: Date[]) => MonthBlock[];
178
+ interface YearSpan {
179
+ /** 1 января года (UTC) */
180
+ year: Date;
181
+ /** Суммарное кол-во дней этого года внутри dateRange */
182
+ days: number;
183
+ /** Начальный индекс в массиве monthBlocks */
184
+ startIndex: number;
185
+ }
186
+ /**
187
+ * Группирует month-блоки по годам.
188
+ * Используется в строке 1 month-view шапки (year label).
189
+ */
190
+ declare const getYearSpans: (days: Date[]) => YearSpan[];
191
+ /**
192
+ * Normalize task dates to ensure startDate is always before or equal to endDate.
193
+ * If dates are swapped (endDate < startDate), they are automatically swapped.
194
+ * @param startDate - Task start date (string or Date)
195
+ * @param endDate - Task end date (string or Date)
196
+ * @returns Object with normalized startDate and endDate as ISO date strings (YYYY-MM-DD)
197
+ */
198
+ declare const normalizeTaskDates: (startDate: string | Date, endDate: string | Date) => {
199
+ startDate: string;
200
+ endDate: string;
201
+ };
202
+
4
203
  /**
5
204
  * Dependency link types following PM standard
6
205
  * - FS (Finish-to-Start): Predecessor must finish before successor starts
@@ -252,11 +451,9 @@ interface GanttChartProps {
252
451
  enableAddTask?: boolean;
253
452
  /** View mode: 'day' renders one column per day, 'week' renders one column per 7 days, 'month' renders one column per month (default: 'day') */
254
453
  viewMode?: 'day' | 'week' | 'month';
255
- /** Custom weekend dates to ADD to default weekends (e.g., holidays) */
256
- weekends?: Date[];
257
- /** Custom workday dates to EXCLUDE from default weekends (e.g., shifted workdays) */
258
- workdays?: Date[];
259
- /** Flexible weekend logic predicate (overrides arrays) */
454
+ /** Custom day configurations with explicit type (weekend or workday) */
455
+ customDays?: CustomDayConfig[];
456
+ /** Optional base weekend predicate (checked before customDays overrides) */
260
457
  isWeekend?: (date: Date) => boolean;
261
458
  }
262
459
  /**
@@ -473,11 +670,9 @@ interface TaskListProps {
473
670
  onPromoteTask?: (taskId: string) => void;
474
671
  /** Callback when task is demoted (parentId set to previous task) */
475
672
  onDemoteTask?: (taskId: string, newParentId: string) => void;
476
- /** Optional custom weekend dates (holidays) for date picker */
477
- weekends?: Date[];
478
- /** Optional custom workday dates - overrides weekends */
479
- workdays?: Date[];
480
- /** Optional predicate for custom weekend logic in date picker */
673
+ /** Custom day configurations for date picker */
674
+ customDays?: CustomDayConfig[];
675
+ /** Optional base weekend predicate for date picker */
481
676
  isWeekend?: (date: Date) => boolean;
482
677
  }
483
678
  /**
@@ -555,10 +750,6 @@ interface CalendarProps {
555
750
  disabled?: boolean;
556
751
  /** Optional predicate for custom weekend logic (e.g., holidays, shift patterns) */
557
752
  isWeekend?: (date: Date) => boolean;
558
- /** Optional custom weekend dates (holidays) - takes precedence over default weekends */
559
- weekends?: Date[];
560
- /** Optional custom workday dates - overrides both default and custom weekends */
561
- workdays?: Date[];
562
753
  }
563
754
  declare const Calendar: React$1.FC<CalendarProps>;
564
755
 
@@ -577,10 +768,6 @@ interface DatePickerProps {
577
768
  className?: string;
578
769
  /** Whether the picker is disabled */
579
770
  disabled?: boolean;
580
- /** Optional custom weekend dates (holidays) */
581
- weekends?: Date[];
582
- /** Optional custom workday dates - overrides weekends */
583
- workdays?: Date[];
584
771
  /** Optional predicate for custom weekend logic */
585
772
  isWeekend?: (date: Date) => boolean;
586
773
  }
@@ -666,194 +853,6 @@ interface UseTaskDragReturn {
666
853
  */
667
854
  declare const useTaskDrag: (options: UseTaskDragOptions) => UseTaskDragReturn;
668
855
 
669
- /**
670
- * Parse date string as UTC to prevent DST issues
671
- * @param date - Date string or Date object
672
- * @returns Date object representing UTC midnight
673
- * @throws Error if date string is invalid
674
- */
675
- declare const parseUTCDate: (date: string | Date) => Date;
676
- /**
677
- * Get all days in the month of given date (UTC)
678
- * @param date - Reference date (any day in the target month)
679
- * @returns Array of Date objects for each day in the month
680
- */
681
- declare const getMonthDays: (date: Date | string) => Date[];
682
- /**
683
- * Calculate day offset from month start (0-based)
684
- * @param date - The date to calculate offset for
685
- * @param monthStart - The start of the month as reference
686
- * @returns Number of days from month start (negative if date is before month start)
687
- */
688
- declare const getDayOffset: (date: Date, monthStart: Date) => number;
689
- /**
690
- * Check if date is today (local timezone comparison)
691
- * Uses local time to determine today's date boundary so the result matches
692
- * the user's timezone rather than UTC (prevents off-by-one errors at midnight).
693
- * @param date - Date to check
694
- * @returns True if date is today, false otherwise
695
- */
696
- declare const isToday: (date: Date) => boolean;
697
- /**
698
- * Check if date is a weekend day (Saturday or Sunday)
699
- * @param date - Date to check
700
- * @returns True if date is Saturday (6) or Sunday (0), false otherwise
701
- */
702
- declare const isWeekend: (date: Date) => boolean;
703
- /**
704
- * Create a UTC-safe key for Set-based date lookup
705
- * @param date - Date object to create key from
706
- * @returns String key in "YYYY-M-D" format using UTC date components
707
- *
708
- * Example:
709
- * createDateKey(new Date(Date.UTC(2026, 2, 15))) // "2026-2-15"
710
- *
711
- * Note: Uses UTC methods to prevent DST and timezone issues.
712
- * Month is 0-indexed (0=January, 11=December) per JavaScript Date convention.
713
- */
714
- declare const createDateKey: (date: Date) => string;
715
- /**
716
- * Configuration for custom weekend calendar
717
- */
718
- interface WeekendConfig {
719
- /** Array of dates to ADD to default weekends (e.g., holidays) */
720
- weekends?: Date[];
721
- /** Array of dates to EXCLUDE from default weekends (e.g., shifted workdays) */
722
- workdays?: Date[];
723
- /** Custom predicate for flexible weekend logic (overrides arrays) */
724
- isWeekend?: (date: Date) => boolean;
725
- }
726
- /**
727
- * Create a weekend predicate with custom calendar support
728
- *
729
- * Precedence order (highest to lowest):
730
- * 1. isWeekend (custom predicate) - use directly, ignore arrays
731
- * 2. workdays - exclude these dates from default weekends
732
- * 3. weekends - add these dates to default weekends
733
- * 4. default - Saturday (6) and Sunday (0)
734
- *
735
- * @param config - Weekend configuration with optional arrays and predicate
736
- * @returns Predicate function (date: Date) => boolean
737
- *
738
- * Example:
739
- * // Add March 8 as holiday (Monday becomes weekend)
740
- * const predicate = createIsWeekendPredicate({
741
- * weekends: [new Date(Date.UTC(2026, 2, 8))]
742
- * });
743
- *
744
- * // Make March 15 a workday (Saturday becomes workday)
745
- * const predicate2 = createIsWeekendPredicate({
746
- * workdays: [new Date(Date.UTC(2026, 2, 15))]
747
- * });
748
- *
749
- * // Custom shift pattern (Sunday-only weekends)
750
- * const predicate3 = createIsWeekendPredicate({
751
- * isWeekend: (date) => date.getUTCDay() === 0
752
- * });
753
- */
754
- declare const createIsWeekendPredicate: (config: WeekendConfig) => ((date: Date) => boolean);
755
- /**
756
- * Calculate multi-month date range from task dates
757
- * Expands range to include full months with padding on both ends for drag flexibility
758
- * Adds 1 month before and 2 months after the task range
759
- * @param tasks - Array of tasks with startDate and endDate
760
- * @returns Array of Date objects for all days in the expanded range
761
- */
762
- declare const getMultiMonthDays: (tasks: Array<{
763
- startDate: string | Date;
764
- endDate: string | Date;
765
- }>) => Date[];
766
- /**
767
- * Calculate month spans within a date range
768
- * @param dateRange - Array of Date objects representing the full range
769
- * @returns Array of month span objects with month, days count, and start index
770
- */
771
- declare const getMonthSpans: (dateRange: Date[]) => Array<{
772
- month: Date;
773
- days: number;
774
- startIndex: number;
775
- }>;
776
- /**
777
- * Format date as DD.MM (e.g., 25.03 for March 25th)
778
- * @param date - Date to format
779
- * @returns Formatted date string in DD.MM format
780
- */
781
- declare const formatDateLabel: (date: Date | string) => string;
782
- /**
783
- * Return block boundaries for week-view, splitting on month boundaries.
784
- * Each block represents a column in the week-view header.
785
- * Blocks are typically 7 days, but split on month boundaries so
786
- * the first/last block of a month may be smaller.
787
- *
788
- * @param days - Array of dates from getMultiMonthDays
789
- * @returns Array of start dates for each block, with actual block sizes
790
- */
791
- interface WeekBlock {
792
- /** Start date of this block */
793
- startDate: Date;
794
- /** Number of days in this block (≤7, splits on month boundaries) */
795
- days: number;
796
- }
797
- /**
798
- * Split the date range into blocks, primarily 7-day weeks,
799
- * but splitting blocks on month boundaries for accurate month spans.
800
- */
801
- declare const getWeekBlocks: (days: Date[]) => WeekBlock[];
802
- /**
803
- * Represents a month span in week-view header row 1.
804
- * In week-view, the width is calculated from actual day counts,
805
- * not from a fixed column count.
806
- */
807
- interface WeekSpan {
808
- /** First day of the calendar month (UTC) */
809
- month: Date;
810
- /** Total number of days this month occupies across all blocks */
811
- days: number;
812
- /** Start index in the blocks array */
813
- startIndex: number;
814
- }
815
- /**
816
- * Calculate month spans based on week-block boundaries.
817
- * Groups consecutive blocks that belong to the same month.
818
- */
819
- declare const getWeekSpans: (days: Date[]) => WeekSpan[];
820
- interface MonthBlock {
821
- /** Первый день месяца (UTC) */
822
- startDate: Date;
823
- /** Количество дней в этом месяце внутри dateRange (может быть меньше при обрезке) */
824
- days: number;
825
- }
826
- /**
827
- * Разбивает dateRange на блоки по месяцам.
828
- * Каждый блок = один месяц (колонка в строке 2 month-view шапки).
829
- * Блок на краях может быть неполным если dateRange начинается/заканчивается не с 1-го числа.
830
- */
831
- declare const getMonthBlocks: (days: Date[]) => MonthBlock[];
832
- interface YearSpan {
833
- /** 1 января года (UTC) */
834
- year: Date;
835
- /** Суммарное кол-во дней этого года внутри dateRange */
836
- days: number;
837
- /** Начальный индекс в массиве monthBlocks */
838
- startIndex: number;
839
- }
840
- /**
841
- * Группирует month-блоки по годам.
842
- * Используется в строке 1 month-view шапки (year label).
843
- */
844
- declare const getYearSpans: (days: Date[]) => YearSpan[];
845
- /**
846
- * Normalize task dates to ensure startDate is always before or equal to endDate.
847
- * If dates are swapped (endDate < startDate), they are automatically swapped.
848
- * @param startDate - Task start date (string or Date)
849
- * @param endDate - Task end date (string or Date)
850
- * @returns Object with normalized startDate and endDate as ISO date strings (YYYY-MM-DD)
851
- */
852
- declare const normalizeTaskDates: (startDate: string | Date, endDate: string | Date) => {
853
- startDate: string;
854
- endDate: string;
855
- };
856
-
857
856
  /**
858
857
  * Build adjacency list for dependency graph (task -> successors)
859
858
  */
@@ -1199,4 +1198,4 @@ interface VisibleReorderPosition {
1199
1198
  */
1200
1199
  declare function getVisibleReorderPosition(orderedTasks: TaskLike[], visibleTasks: TaskLike[], movedTaskId: string, originVisibleIndex: number, dropVisibleIndex: number): VisibleReorderPosition | null;
1201
1200
 
1202
- 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 MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type WeekendConfig, type YearSpan, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, createDateKey, createIsWeekendPredicate, detectCycles, detectEdgeZone, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, isTaskParent, isToday, isWeekend, normalizeHierarchyTasks, normalizeTaskDates, parseUTCDate, pixelsToDate, recalculateIncomingLags, removeDependenciesBetweenTasks, universalCascade, useTaskDrag, validateDependencies };
1201
+ export { Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, isTaskParent, isToday, isWeekend, normalizeHierarchyTasks, normalizeTaskDates, parseUTCDate, pixelsToDate, recalculateIncomingLags, removeDependenciesBetweenTasks, universalCascade, useTaskDrag, validateDependencies };