gantt-lib 0.0.4 → 0.0.6
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/README.md +8 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +280 -55
- package/dist/index.d.ts +280 -55
- package/dist/index.js +574 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +564 -67
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +51 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,139 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Dependency link types following PM standard
|
|
5
|
+
* - FS (Finish-to-Start): Predecessor must finish before successor starts
|
|
6
|
+
* - SS (Start-to-Start): Predecessor must start before successor starts
|
|
7
|
+
* - FF (Finish-to-Finish): Predecessor must finish before successor finishes
|
|
8
|
+
* - SF (Start-to-Finish): Predecessor must start before successor finishes
|
|
9
|
+
*/
|
|
10
|
+
type LinkType = 'FS' | 'SS' | 'FF' | 'SF';
|
|
11
|
+
/**
|
|
12
|
+
* Single dependency relationship (predecessor link)
|
|
13
|
+
*/
|
|
14
|
+
interface TaskDependency$1 {
|
|
15
|
+
/** ID of the predecessor task */
|
|
16
|
+
taskId: string;
|
|
17
|
+
/** Type of link: FS (finish-to-start), SS, FF, SF */
|
|
18
|
+
type: LinkType;
|
|
19
|
+
/** Lag in days (positive or negative integer, default: 0) */
|
|
20
|
+
lag?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error or warning from dependency validation
|
|
24
|
+
*/
|
|
25
|
+
interface DependencyError {
|
|
26
|
+
/** Type of error */
|
|
27
|
+
type: 'cycle' | 'constraint' | 'missing-task';
|
|
28
|
+
/** ID of the task with the error */
|
|
29
|
+
taskId: string;
|
|
30
|
+
/** Human-readable error message */
|
|
31
|
+
message: string;
|
|
32
|
+
/** Related task IDs (e.g., cycle path, referenced tasks) */
|
|
33
|
+
relatedTaskIds?: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Result of dependency validation
|
|
37
|
+
*/
|
|
38
|
+
interface ValidationResult {
|
|
39
|
+
/** True if no errors found */
|
|
40
|
+
isValid: boolean;
|
|
41
|
+
/** Array of errors/warnings (empty if valid) */
|
|
42
|
+
errors: DependencyError[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Task data structure for Gantt chart
|
|
46
|
+
*/
|
|
47
|
+
interface Task$1 {
|
|
48
|
+
/** Unique identifier for the task */
|
|
49
|
+
id: string;
|
|
50
|
+
/** Display name of the task */
|
|
51
|
+
name: string;
|
|
52
|
+
/** Task start date (ISO string or Date object) */
|
|
53
|
+
startDate: string | Date;
|
|
54
|
+
/** Task end date (ISO string or Date object) */
|
|
55
|
+
endDate: string | Date;
|
|
56
|
+
/** Optional color for task bar visualization */
|
|
57
|
+
color?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Optional progress value from 0-100
|
|
60
|
+
* - Decimal values are allowed and rounded to nearest integer for display
|
|
61
|
+
* - Values are clamped to 0-100 range
|
|
62
|
+
* - Undefined or 0 means no progress is displayed
|
|
63
|
+
* - Progress is visual-only, no user interaction
|
|
64
|
+
*/
|
|
65
|
+
progress?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Optional flag indicating if task is accepted
|
|
68
|
+
* - Only meaningful when progress is 100%
|
|
69
|
+
* - Affects the color of the progress bar (green for accepted, yellow for completed)
|
|
70
|
+
*/
|
|
71
|
+
accepted?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Optional array of predecessor dependencies
|
|
74
|
+
* Each dependency specifies a predecessor task, link type, and optional lag
|
|
75
|
+
*/
|
|
76
|
+
dependencies?: TaskDependency$1[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Date range for Gantt chart display
|
|
80
|
+
*/
|
|
81
|
+
interface GanttDateRange {
|
|
82
|
+
/** Start date of the visible range */
|
|
83
|
+
start: Date;
|
|
84
|
+
/** End date of the visible range */
|
|
85
|
+
end: Date;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Task bar positioning and dimensions
|
|
89
|
+
*/
|
|
90
|
+
interface TaskBarGeometry {
|
|
91
|
+
/** Left position in pixels */
|
|
92
|
+
left: number;
|
|
93
|
+
/** Width in pixels */
|
|
94
|
+
width: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Grid configuration for layout calculations
|
|
98
|
+
*/
|
|
99
|
+
interface GridConfig {
|
|
100
|
+
/** Width of each day column in pixels */
|
|
101
|
+
dayWidth: number;
|
|
102
|
+
/** Height of each task row in pixels */
|
|
103
|
+
rowHeight: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Represents a month span in the calendar header
|
|
107
|
+
*/
|
|
108
|
+
interface MonthSpan {
|
|
109
|
+
/** First day of the month (UTC) */
|
|
110
|
+
month: Date;
|
|
111
|
+
/** Number of days this month spans in the visible range */
|
|
112
|
+
days: number;
|
|
113
|
+
/** Start index in the date range array */
|
|
114
|
+
startIndex: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Represents a vertical grid line
|
|
118
|
+
*/
|
|
119
|
+
interface GridLine {
|
|
120
|
+
/** X position in pixels */
|
|
121
|
+
x: number;
|
|
122
|
+
/** True if this line is at the start of a month */
|
|
123
|
+
isMonthStart: boolean;
|
|
124
|
+
/** True if this line is at the start of a week (Monday) */
|
|
125
|
+
isWeekStart: boolean;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Represents a weekend background block
|
|
129
|
+
*/
|
|
130
|
+
interface WeekendBlock {
|
|
131
|
+
/** Left position in pixels */
|
|
132
|
+
left: number;
|
|
133
|
+
/** Width in pixels */
|
|
134
|
+
width: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
3
137
|
/**
|
|
4
138
|
* Task data structure for Gantt chart
|
|
5
139
|
*/
|
|
@@ -14,6 +148,38 @@ interface Task {
|
|
|
14
148
|
endDate: string | Date;
|
|
15
149
|
/** Optional color for task bar visualization */
|
|
16
150
|
color?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Optional progress value from 0-100
|
|
153
|
+
* - Decimal values are allowed and rounded to nearest integer for display
|
|
154
|
+
* - Values are clamped to 0-100 range
|
|
155
|
+
* - Undefined or 0 means no progress is displayed
|
|
156
|
+
* - Progress is visual-only, no user interaction
|
|
157
|
+
*/
|
|
158
|
+
progress?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Optional flag indicating if task is accepted
|
|
161
|
+
* - Only meaningful when progress is 100%
|
|
162
|
+
* - Affects the color of the progress bar (green for accepted, yellow for completed)
|
|
163
|
+
*/
|
|
164
|
+
accepted?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Optional array of task dependencies
|
|
167
|
+
* - Each dependency references a predecessor task by ID
|
|
168
|
+
* - Supports 4 link types: FS (finish-to-start), SS (start-to-start), FF (finish-to-finish), SF (start-to-finish)
|
|
169
|
+
* - Lag is optional and defaults to 0 (positive = delay, negative = overlap)
|
|
170
|
+
*/
|
|
171
|
+
dependencies?: TaskDependency[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Task dependency definition
|
|
175
|
+
*/
|
|
176
|
+
interface TaskDependency {
|
|
177
|
+
/** ID of the predecessor task */
|
|
178
|
+
taskId: string;
|
|
179
|
+
/** Link type: FS, SS, FF, or SF */
|
|
180
|
+
type: 'FS' | 'SS' | 'FF' | 'SF';
|
|
181
|
+
/** Optional lag in days (default: 0) */
|
|
182
|
+
lag?: number;
|
|
17
183
|
}
|
|
18
184
|
interface GanttChartProps {
|
|
19
185
|
/** Array of tasks to display */
|
|
@@ -28,6 +194,14 @@ interface GanttChartProps {
|
|
|
28
194
|
containerHeight?: number;
|
|
29
195
|
/** Callback when tasks are modified via drag/resize. Can receive either the new tasks array or a functional updater. */
|
|
30
196
|
onChange?: (tasks: Task[] | ((currentTasks: Task[]) => Task[])) => void;
|
|
197
|
+
/** Optional callback for dependency validation results */
|
|
198
|
+
onValidateDependencies?: (result: ValidationResult) => void;
|
|
199
|
+
/** Enable automatic shifting of dependent tasks when predecessor moves (default: false) */
|
|
200
|
+
enableAutoSchedule?: boolean;
|
|
201
|
+
/** Disable dependency constraint checking during drag (default: false) */
|
|
202
|
+
disableConstraints?: boolean;
|
|
203
|
+
/** Called when a cascade drag completes; receives all shifted tasks (including dragged task) in hard mode */
|
|
204
|
+
onCascade?: (tasks: Task[]) => void;
|
|
31
205
|
}
|
|
32
206
|
/**
|
|
33
207
|
* GanttChart component - displays tasks on a monthly timeline with Excel-like styling
|
|
@@ -65,6 +239,26 @@ interface TaskRowProps {
|
|
|
65
239
|
left: number;
|
|
66
240
|
width: number;
|
|
67
241
|
}) => void;
|
|
242
|
+
/** Index of the task row (used for dependency rendering) */
|
|
243
|
+
rowIndex?: number;
|
|
244
|
+
/** All tasks in the chart (used for dependency validation) */
|
|
245
|
+
allTasks?: Task[];
|
|
246
|
+
/** Whether auto-scheduling is enabled */
|
|
247
|
+
enableAutoSchedule?: boolean;
|
|
248
|
+
/** Whether to disable constraint checking during drag */
|
|
249
|
+
disableConstraints?: boolean;
|
|
250
|
+
/** Position override for cascade preview — when set, overrides both static and drag position */
|
|
251
|
+
overridePosition?: {
|
|
252
|
+
left: number;
|
|
253
|
+
width: number;
|
|
254
|
+
};
|
|
255
|
+
/** Called each RAF during cascade drag with override positions for non-dragged chain tasks */
|
|
256
|
+
onCascadeProgress?: (overrides: Map<string, {
|
|
257
|
+
left: number;
|
|
258
|
+
width: number;
|
|
259
|
+
}>) => void;
|
|
260
|
+
/** Called when cascade drag completes; receives all shifted tasks including dragged task */
|
|
261
|
+
onCascade?: (tasks: Task[]) => void;
|
|
68
262
|
}
|
|
69
263
|
/**
|
|
70
264
|
* TaskRow component - renders a single task row with a task bar
|
|
@@ -154,6 +348,7 @@ interface UseTaskDragOptions {
|
|
|
154
348
|
id: string;
|
|
155
349
|
startDate: Date;
|
|
156
350
|
endDate: Date;
|
|
351
|
+
updatedDependencies?: Task$1['dependencies'];
|
|
157
352
|
}) => void;
|
|
158
353
|
/** Callback for drag state changes (for parent components to render guide lines) */
|
|
159
354
|
onDragStateChange?: (state: {
|
|
@@ -164,6 +359,21 @@ interface UseTaskDragOptions {
|
|
|
164
359
|
}) => void;
|
|
165
360
|
/** Width of edge zones for resize detection (default: 12px) */
|
|
166
361
|
edgeZoneWidth?: number;
|
|
362
|
+
/** Array of all tasks for dependency validation */
|
|
363
|
+
allTasks?: Task$1[];
|
|
364
|
+
/** Row index of this task (for task lookup) */
|
|
365
|
+
rowIndex?: number;
|
|
366
|
+
/** Enable automatic scheduling of dependent tasks */
|
|
367
|
+
enableAutoSchedule?: boolean;
|
|
368
|
+
/** When true, dependency constraint checking is skipped during drag (default: false) */
|
|
369
|
+
disableConstraints?: boolean;
|
|
370
|
+
/** Callback for real-time cascade preview — called each RAF with non-dragged chain member positions */
|
|
371
|
+
onCascadeProgress?: (overrides: Map<string, {
|
|
372
|
+
left: number;
|
|
373
|
+
width: number;
|
|
374
|
+
}>) => void;
|
|
375
|
+
/** Callback when cascade completes — receives all shifted tasks including dragged task */
|
|
376
|
+
onCascade?: (tasks: Task$1[]) => void;
|
|
167
377
|
}
|
|
168
378
|
/**
|
|
169
379
|
* Return value from useTaskDrag hook
|
|
@@ -251,6 +461,52 @@ declare const getMonthSpans: (dateRange: Date[]) => Array<{
|
|
|
251
461
|
*/
|
|
252
462
|
declare const formatDateLabel: (date: Date | string) => string;
|
|
253
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Build adjacency list for dependency graph (task -> successors)
|
|
466
|
+
*/
|
|
467
|
+
declare function buildAdjacencyList(tasks: Task$1[]): Map<string, string[]>;
|
|
468
|
+
/**
|
|
469
|
+
* Detect circular dependencies using depth-first search
|
|
470
|
+
*/
|
|
471
|
+
declare function detectCycles(tasks: Task$1[]): {
|
|
472
|
+
hasCycle: boolean;
|
|
473
|
+
cyclePath?: string[];
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Calculate successor date based on predecessor dates, link type, and lag
|
|
477
|
+
*
|
|
478
|
+
* Link type semantics:
|
|
479
|
+
* - FS: Successor start = Predecessor end + lag
|
|
480
|
+
* - SS: Successor start = Predecessor start + lag
|
|
481
|
+
* - FF: Successor end = Predecessor end + lag
|
|
482
|
+
* - SF: Successor end = Predecessor start + lag
|
|
483
|
+
*/
|
|
484
|
+
declare function calculateSuccessorDate(predecessorStart: Date, predecessorEnd: Date, linkType: LinkType, lag?: number): Date;
|
|
485
|
+
/**
|
|
486
|
+
* Validate all dependencies in the task list
|
|
487
|
+
*/
|
|
488
|
+
declare function validateDependencies(tasks: Task$1[]): ValidationResult;
|
|
489
|
+
/**
|
|
490
|
+
* Get all FS successor tasks of a dragged task using BFS (FS edges only, Phase 7).
|
|
491
|
+
*
|
|
492
|
+
* Returns tasks in breadth-first order (direct successors first, then their successors).
|
|
493
|
+
* The dragged task itself is NOT included in the returned array.
|
|
494
|
+
*
|
|
495
|
+
* The visited set prevents infinite loops in case of cycles (cycle detection already
|
|
496
|
+
* prevents cycles in valid data, but the guard adds safety during cascade computation).
|
|
497
|
+
*/
|
|
498
|
+
declare function getSuccessorChain(draggedTaskId: string, allTasks: Task$1[]): Task$1[];
|
|
499
|
+
/**
|
|
500
|
+
* Get all dependency edges for rendering
|
|
501
|
+
* Returns array of { predecessorId, successorId, type, lag }
|
|
502
|
+
*/
|
|
503
|
+
declare function getAllDependencyEdges(tasks: Task$1[]): Array<{
|
|
504
|
+
predecessorId: string;
|
|
505
|
+
successorId: string;
|
|
506
|
+
type: LinkType;
|
|
507
|
+
lag: number;
|
|
508
|
+
}>;
|
|
509
|
+
|
|
254
510
|
/**
|
|
255
511
|
* Calculate task bar positioning and dimensions
|
|
256
512
|
* @param taskStartDate - Start date of the task
|
|
@@ -313,64 +569,33 @@ declare const calculateWeekendBlocks: (dateRange: Date[], dayWidth: number) => A
|
|
|
313
569
|
left: number;
|
|
314
570
|
width: number;
|
|
315
571
|
}>;
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Date range for Gantt chart display
|
|
319
|
-
*/
|
|
320
|
-
interface GanttDateRange {
|
|
321
|
-
/** Start date of the visible range */
|
|
322
|
-
start: Date;
|
|
323
|
-
/** End date of the visible range */
|
|
324
|
-
end: Date;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Task bar positioning and dimensions
|
|
328
|
-
*/
|
|
329
|
-
interface TaskBarGeometry {
|
|
330
|
-
/** Left position in pixels */
|
|
331
|
-
left: number;
|
|
332
|
-
/** Width in pixels */
|
|
333
|
-
width: number;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Grid configuration for layout calculations
|
|
337
|
-
*/
|
|
338
|
-
interface GridConfig {
|
|
339
|
-
/** Width of each day column in pixels */
|
|
340
|
-
dayWidth: number;
|
|
341
|
-
/** Height of each task row in pixels */
|
|
342
|
-
rowHeight: number;
|
|
343
|
-
}
|
|
344
572
|
/**
|
|
345
|
-
*
|
|
573
|
+
* Calculate SVG cubic Bezier curve path for dependency lines
|
|
574
|
+
* @param from - Start point {x, y} (right edge of predecessor)
|
|
575
|
+
* @param to - End point {x, y} (left edge of successor)
|
|
576
|
+
* @returns SVG path string for cubic Bezier curve
|
|
346
577
|
*/
|
|
347
|
-
|
|
348
|
-
/** First day of the month (UTC) */
|
|
349
|
-
month: Date;
|
|
350
|
-
/** Number of days this month spans in the visible range */
|
|
351
|
-
days: number;
|
|
352
|
-
/** Start index in the date range array */
|
|
353
|
-
startIndex: number;
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Represents a vertical grid line
|
|
357
|
-
*/
|
|
358
|
-
interface GridLine {
|
|
359
|
-
/** X position in pixels */
|
|
578
|
+
declare const calculateBezierPath: (from: {
|
|
360
579
|
x: number;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
580
|
+
y: number;
|
|
581
|
+
}, to: {
|
|
582
|
+
x: number;
|
|
583
|
+
y: number;
|
|
584
|
+
}) => string;
|
|
366
585
|
/**
|
|
367
|
-
*
|
|
586
|
+
* Calculate SVG Г-shaped (L-shaped) path for FS dependency lines.
|
|
587
|
+
* Goes vertically from the right edge of the predecessor bar, then horizontally
|
|
588
|
+
* to the left edge of the successor bar. Supports negative lag (overlap).
|
|
589
|
+
* @param from - Start point {x, y} (right edge of predecessor, vertical center)
|
|
590
|
+
* @param to - End point {x, y} (left edge of successor, vertical center)
|
|
591
|
+
* @returns SVG path string
|
|
368
592
|
*/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
593
|
+
declare const calculateOrthogonalPath: (from: {
|
|
594
|
+
x: number;
|
|
595
|
+
y: number;
|
|
596
|
+
}, to: {
|
|
597
|
+
x: number;
|
|
598
|
+
y: number;
|
|
599
|
+
}) => string;
|
|
375
600
|
|
|
376
|
-
export { DragGuideLines, GanttChart, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, type MonthSpan, type Task, type TaskBarGeometry, TaskRow, TimeScaleHeader, TodayIndicator, type WeekendBlock, calculateGridLines, calculateGridWidth, calculateTaskBar, calculateWeekendBlocks, detectEdgeZone, formatDateLabel, getCursorForPosition, getDayOffset, getMonthDays, getMonthSpans, getMultiMonthDays, isToday, isWeekend, parseUTCDate, pixelsToDate, useTaskDrag };
|
|
601
|
+
export { DragGuideLines, GanttChart, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, type MonthSpan, type Task, type TaskBarGeometry, type TaskDependency, TaskRow, TimeScaleHeader, TodayIndicator, type WeekendBlock, buildAdjacencyList, calculateBezierPath, calculateGridLines, calculateGridWidth, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekendBlocks, detectCycles, detectEdgeZone, formatDateLabel, getAllDependencyEdges, getCursorForPosition, getDayOffset, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, isToday, isWeekend, parseUTCDate, pixelsToDate, useTaskDrag, validateDependencies };
|