ct-gantt-core 1.0.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.
@@ -0,0 +1,235 @@
1
+ type ViewMode = "day" | "week" | "month" | "quarter" | "year";
2
+ type LinkType = "FS" | "SS" | "FF" | "SF";
3
+ type LagUnit = "calendar" | "working";
4
+ type Result<T> = {
5
+ ok: true;
6
+ data: T;
7
+ } | {
8
+ ok: false;
9
+ error: GanttError;
10
+ };
11
+ interface GanttError {
12
+ code: "CYCLE_DEPENDENCY" | "INVALID_DATE" | "MISSING_TASK" | "ORPHAN_DEPENDENCY" | "INVALID_DEPENDENCY";
13
+ message: string;
14
+ details?: unknown;
15
+ }
16
+ interface DateRange {
17
+ start: string | Date;
18
+ end: string | Date;
19
+ progress?: number;
20
+ }
21
+ interface Dependency {
22
+ id?: string;
23
+ predecessorId: string;
24
+ type: LinkType;
25
+ lag: number;
26
+ lagUnit: LagUnit;
27
+ }
28
+ interface GanttTask {
29
+ id: string;
30
+ name: string;
31
+ type: "task" | "milestone" | "summary";
32
+ plan: DateRange;
33
+ actual: Required<DateRange>;
34
+ dependencies?: Dependency[];
35
+ parentId?: string | null;
36
+ color?: string;
37
+ planColor?: string;
38
+ calendarId?: string;
39
+ resources?: string[];
40
+ segments?: Array<{
41
+ start: string | Date;
42
+ end: string | Date;
43
+ }>;
44
+ constraint?: {
45
+ type: "SNET" | "SNLT" | "MSO" | "MFO" | "ASAP" | "ALAP";
46
+ date?: string | Date;
47
+ };
48
+ schedulingMode?: "auto" | "manual";
49
+ duration?: number;
50
+ custom?: Record<string, unknown>;
51
+ }
52
+ interface GanttMarker {
53
+ id: string;
54
+ name: string;
55
+ date: string | Date;
56
+ color?: string;
57
+ }
58
+ interface GanttEditorField {
59
+ key: string;
60
+ label: string;
61
+ visible?: boolean;
62
+ editable?: boolean;
63
+ type?: "text" | "number" | "date" | "select";
64
+ options?: Array<{
65
+ label: string;
66
+ value: string | number;
67
+ }>;
68
+ placeholder?: string;
69
+ }
70
+ interface CustomColumn {
71
+ key: string;
72
+ label: string;
73
+ width?: number;
74
+ visible?: boolean;
75
+ align?: "left" | "center" | "right";
76
+ editable?: boolean;
77
+ type?: "text" | "number" | "date" | "select";
78
+ options?: Array<{
79
+ label: string;
80
+ value: string | number;
81
+ }>;
82
+ placeholder?: string;
83
+ editor?: Omit<GanttEditorField, "key" | "label">;
84
+ formatter?: (value: unknown, task: GanttTask) => string;
85
+ cellClass?: string | ((task: GanttTask) => string);
86
+ cellStyle?: Record<string, string | number> | ((task: GanttTask) => Record<string, string | number>);
87
+ render?: (task: GanttTask) => {
88
+ text: string;
89
+ className?: string;
90
+ };
91
+ }
92
+ interface GanttConfig {
93
+ viewMode: ViewMode;
94
+ rowHeight: number;
95
+ columnWidth: number;
96
+ headerHeight: number;
97
+ taskListWidth: number;
98
+ width?: string | number;
99
+ height?: string | number;
100
+ locale: string;
101
+ firstDayOfWeek: 0 | 1;
102
+ dateFormat: string;
103
+ customColumns?: CustomColumn[];
104
+ columns?: CustomColumn[];
105
+ editorFields?: GanttEditorField[];
106
+ columnWidths?: Partial<Record<ViewMode, number>>;
107
+ theme?: "light" | "dark" | string;
108
+ visibleRange?: {
109
+ start: string | Date;
110
+ end: string | Date;
111
+ };
112
+ showPlanBar?: boolean;
113
+ showActualBar?: boolean;
114
+ showTimelineWhenEmpty?: boolean;
115
+ builtInTaskEditor?: boolean;
116
+ builtInMarkerEditor?: boolean;
117
+ editablePlan?: boolean;
118
+ editableActual?: boolean;
119
+ enableLinkCreation?: boolean;
120
+ showLinkRejectionNotice?: boolean;
121
+ virtualScroll?: boolean;
122
+ taskColors?: {
123
+ task?: string;
124
+ summary?: string;
125
+ milestone?: string;
126
+ plan?: string;
127
+ progress?: string;
128
+ };
129
+ autoSchedule?: boolean;
130
+ editable?: boolean;
131
+ }
132
+ interface GanttLink {
133
+ id: string;
134
+ sourceId: string;
135
+ targetId: string;
136
+ type: LinkType;
137
+ lag?: number;
138
+ lagUnit?: LagUnit;
139
+ }
140
+ interface TaskLayout {
141
+ taskId: string;
142
+ rowIndex: number;
143
+ left: number;
144
+ width: number;
145
+ top: number;
146
+ depth: number;
147
+ isCritical: boolean;
148
+ }
149
+ interface FlatTask {
150
+ task: GanttTask;
151
+ depth: number;
152
+ rowIndex: number;
153
+ hasChildren: boolean;
154
+ collapsed: boolean;
155
+ }
156
+ interface Calendar {
157
+ id: string;
158
+ workingDays: number[];
159
+ holidays: string[];
160
+ hours: [number, number][];
161
+ }
162
+ interface TimeScale {
163
+ start: Date;
164
+ end: Date;
165
+ left: number;
166
+ width: number;
167
+ }
168
+ interface Viewport {
169
+ scrollTop: number;
170
+ scrollLeft: number;
171
+ clientWidth: number;
172
+ clientHeight: number;
173
+ dpr: number;
174
+ }
175
+ interface AffectedTasks {
176
+ changed: Array<{
177
+ taskId: string;
178
+ actualStart: string | Date;
179
+ actualEnd: string | Date;
180
+ rowIndex: number;
181
+ }>;
182
+ conflicts: Array<{
183
+ taskId: string;
184
+ constraintType: string;
185
+ message: string;
186
+ }>;
187
+ }
188
+ interface PatchTask {
189
+ planStart?: string | Date;
190
+ planEnd?: string | Date;
191
+ actualStart?: string | Date;
192
+ actualEnd?: string | Date;
193
+ progress?: number;
194
+ name?: string;
195
+ type?: GanttTask["type"];
196
+ parentId?: string | null;
197
+ color?: string;
198
+ planColor?: string;
199
+ duration?: number;
200
+ schedulingMode?: "auto" | "manual";
201
+ resources?: string[];
202
+ calendarId?: string;
203
+ custom?: Record<string, unknown>;
204
+ }
205
+ declare const defaultConfig: GanttConfig;
206
+
207
+ declare function checkCyclicDependency(links: GanttLink[]): {
208
+ hasCycle: boolean;
209
+ cyclePath?: string[];
210
+ };
211
+
212
+ declare function normalizeLinks(tasks: GanttTask[], standaloneLinks?: GanttLink[]): GanttLink[];
213
+
214
+ declare function flattenTasks(tasks: GanttTask[], collapsedIds?: Set<string>): FlatTask[];
215
+
216
+ declare function computeTimeScale(start: Date, end: Date, viewMode: ViewMode, columnWidth: number, firstDayOfWeek: 0 | 1): TimeScale[];
217
+
218
+ declare function computeLayout(tasks: GanttTask[], links: GanttLink[], config: Partial<GanttConfig>, collapsedIds?: Set<string>, viewport?: Viewport): Result<TaskLayout[]>;
219
+
220
+ declare function computeImpact(taskId: string, patch: PatchTask, tasks: GanttTask[], links: GanttLink[], config: Partial<GanttConfig>): Result<AffectedTasks>;
221
+
222
+ declare function scheduleByDependencies(tasks: GanttTask[], links: GanttLink[]): Result<GanttTask[]>;
223
+ declare function shiftTask(task: GanttTask, start: string | Date): GanttTask;
224
+
225
+ declare const DAY_MS: number;
226
+ declare function toDate(value: string | Date): Date;
227
+ declare function startOfDay(date: Date): Date;
228
+ declare function addDays(date: string | Date, days: number): Date;
229
+ declare function diffDays(start: string | Date, end: string | Date): number;
230
+ declare function inclusiveDays(start: string | Date, end: string | Date): number;
231
+ declare function isValidDate(value: string | Date): boolean;
232
+ declare function formatDate(date: string | Date): string;
233
+ declare function resultInvalidDate<T>(message: string, details?: unknown): Result<T>;
234
+
235
+ export { type AffectedTasks, type Calendar, type CustomColumn, DAY_MS, type DateRange, type Dependency, type FlatTask, type GanttConfig, type GanttEditorField, type GanttError, type GanttLink, type GanttMarker, type GanttTask, type LagUnit, type LinkType, type PatchTask, type Result, type TaskLayout, type TimeScale, type ViewMode, type Viewport, addDays, checkCyclicDependency, computeImpact, computeLayout, computeTimeScale, defaultConfig, diffDays, flattenTasks, formatDate, inclusiveDays, isValidDate, normalizeLinks, resultInvalidDate, scheduleByDependencies, shiftTask, startOfDay, toDate };
@@ -0,0 +1,235 @@
1
+ type ViewMode = "day" | "week" | "month" | "quarter" | "year";
2
+ type LinkType = "FS" | "SS" | "FF" | "SF";
3
+ type LagUnit = "calendar" | "working";
4
+ type Result<T> = {
5
+ ok: true;
6
+ data: T;
7
+ } | {
8
+ ok: false;
9
+ error: GanttError;
10
+ };
11
+ interface GanttError {
12
+ code: "CYCLE_DEPENDENCY" | "INVALID_DATE" | "MISSING_TASK" | "ORPHAN_DEPENDENCY" | "INVALID_DEPENDENCY";
13
+ message: string;
14
+ details?: unknown;
15
+ }
16
+ interface DateRange {
17
+ start: string | Date;
18
+ end: string | Date;
19
+ progress?: number;
20
+ }
21
+ interface Dependency {
22
+ id?: string;
23
+ predecessorId: string;
24
+ type: LinkType;
25
+ lag: number;
26
+ lagUnit: LagUnit;
27
+ }
28
+ interface GanttTask {
29
+ id: string;
30
+ name: string;
31
+ type: "task" | "milestone" | "summary";
32
+ plan: DateRange;
33
+ actual: Required<DateRange>;
34
+ dependencies?: Dependency[];
35
+ parentId?: string | null;
36
+ color?: string;
37
+ planColor?: string;
38
+ calendarId?: string;
39
+ resources?: string[];
40
+ segments?: Array<{
41
+ start: string | Date;
42
+ end: string | Date;
43
+ }>;
44
+ constraint?: {
45
+ type: "SNET" | "SNLT" | "MSO" | "MFO" | "ASAP" | "ALAP";
46
+ date?: string | Date;
47
+ };
48
+ schedulingMode?: "auto" | "manual";
49
+ duration?: number;
50
+ custom?: Record<string, unknown>;
51
+ }
52
+ interface GanttMarker {
53
+ id: string;
54
+ name: string;
55
+ date: string | Date;
56
+ color?: string;
57
+ }
58
+ interface GanttEditorField {
59
+ key: string;
60
+ label: string;
61
+ visible?: boolean;
62
+ editable?: boolean;
63
+ type?: "text" | "number" | "date" | "select";
64
+ options?: Array<{
65
+ label: string;
66
+ value: string | number;
67
+ }>;
68
+ placeholder?: string;
69
+ }
70
+ interface CustomColumn {
71
+ key: string;
72
+ label: string;
73
+ width?: number;
74
+ visible?: boolean;
75
+ align?: "left" | "center" | "right";
76
+ editable?: boolean;
77
+ type?: "text" | "number" | "date" | "select";
78
+ options?: Array<{
79
+ label: string;
80
+ value: string | number;
81
+ }>;
82
+ placeholder?: string;
83
+ editor?: Omit<GanttEditorField, "key" | "label">;
84
+ formatter?: (value: unknown, task: GanttTask) => string;
85
+ cellClass?: string | ((task: GanttTask) => string);
86
+ cellStyle?: Record<string, string | number> | ((task: GanttTask) => Record<string, string | number>);
87
+ render?: (task: GanttTask) => {
88
+ text: string;
89
+ className?: string;
90
+ };
91
+ }
92
+ interface GanttConfig {
93
+ viewMode: ViewMode;
94
+ rowHeight: number;
95
+ columnWidth: number;
96
+ headerHeight: number;
97
+ taskListWidth: number;
98
+ width?: string | number;
99
+ height?: string | number;
100
+ locale: string;
101
+ firstDayOfWeek: 0 | 1;
102
+ dateFormat: string;
103
+ customColumns?: CustomColumn[];
104
+ columns?: CustomColumn[];
105
+ editorFields?: GanttEditorField[];
106
+ columnWidths?: Partial<Record<ViewMode, number>>;
107
+ theme?: "light" | "dark" | string;
108
+ visibleRange?: {
109
+ start: string | Date;
110
+ end: string | Date;
111
+ };
112
+ showPlanBar?: boolean;
113
+ showActualBar?: boolean;
114
+ showTimelineWhenEmpty?: boolean;
115
+ builtInTaskEditor?: boolean;
116
+ builtInMarkerEditor?: boolean;
117
+ editablePlan?: boolean;
118
+ editableActual?: boolean;
119
+ enableLinkCreation?: boolean;
120
+ showLinkRejectionNotice?: boolean;
121
+ virtualScroll?: boolean;
122
+ taskColors?: {
123
+ task?: string;
124
+ summary?: string;
125
+ milestone?: string;
126
+ plan?: string;
127
+ progress?: string;
128
+ };
129
+ autoSchedule?: boolean;
130
+ editable?: boolean;
131
+ }
132
+ interface GanttLink {
133
+ id: string;
134
+ sourceId: string;
135
+ targetId: string;
136
+ type: LinkType;
137
+ lag?: number;
138
+ lagUnit?: LagUnit;
139
+ }
140
+ interface TaskLayout {
141
+ taskId: string;
142
+ rowIndex: number;
143
+ left: number;
144
+ width: number;
145
+ top: number;
146
+ depth: number;
147
+ isCritical: boolean;
148
+ }
149
+ interface FlatTask {
150
+ task: GanttTask;
151
+ depth: number;
152
+ rowIndex: number;
153
+ hasChildren: boolean;
154
+ collapsed: boolean;
155
+ }
156
+ interface Calendar {
157
+ id: string;
158
+ workingDays: number[];
159
+ holidays: string[];
160
+ hours: [number, number][];
161
+ }
162
+ interface TimeScale {
163
+ start: Date;
164
+ end: Date;
165
+ left: number;
166
+ width: number;
167
+ }
168
+ interface Viewport {
169
+ scrollTop: number;
170
+ scrollLeft: number;
171
+ clientWidth: number;
172
+ clientHeight: number;
173
+ dpr: number;
174
+ }
175
+ interface AffectedTasks {
176
+ changed: Array<{
177
+ taskId: string;
178
+ actualStart: string | Date;
179
+ actualEnd: string | Date;
180
+ rowIndex: number;
181
+ }>;
182
+ conflicts: Array<{
183
+ taskId: string;
184
+ constraintType: string;
185
+ message: string;
186
+ }>;
187
+ }
188
+ interface PatchTask {
189
+ planStart?: string | Date;
190
+ planEnd?: string | Date;
191
+ actualStart?: string | Date;
192
+ actualEnd?: string | Date;
193
+ progress?: number;
194
+ name?: string;
195
+ type?: GanttTask["type"];
196
+ parentId?: string | null;
197
+ color?: string;
198
+ planColor?: string;
199
+ duration?: number;
200
+ schedulingMode?: "auto" | "manual";
201
+ resources?: string[];
202
+ calendarId?: string;
203
+ custom?: Record<string, unknown>;
204
+ }
205
+ declare const defaultConfig: GanttConfig;
206
+
207
+ declare function checkCyclicDependency(links: GanttLink[]): {
208
+ hasCycle: boolean;
209
+ cyclePath?: string[];
210
+ };
211
+
212
+ declare function normalizeLinks(tasks: GanttTask[], standaloneLinks?: GanttLink[]): GanttLink[];
213
+
214
+ declare function flattenTasks(tasks: GanttTask[], collapsedIds?: Set<string>): FlatTask[];
215
+
216
+ declare function computeTimeScale(start: Date, end: Date, viewMode: ViewMode, columnWidth: number, firstDayOfWeek: 0 | 1): TimeScale[];
217
+
218
+ declare function computeLayout(tasks: GanttTask[], links: GanttLink[], config: Partial<GanttConfig>, collapsedIds?: Set<string>, viewport?: Viewport): Result<TaskLayout[]>;
219
+
220
+ declare function computeImpact(taskId: string, patch: PatchTask, tasks: GanttTask[], links: GanttLink[], config: Partial<GanttConfig>): Result<AffectedTasks>;
221
+
222
+ declare function scheduleByDependencies(tasks: GanttTask[], links: GanttLink[]): Result<GanttTask[]>;
223
+ declare function shiftTask(task: GanttTask, start: string | Date): GanttTask;
224
+
225
+ declare const DAY_MS: number;
226
+ declare function toDate(value: string | Date): Date;
227
+ declare function startOfDay(date: Date): Date;
228
+ declare function addDays(date: string | Date, days: number): Date;
229
+ declare function diffDays(start: string | Date, end: string | Date): number;
230
+ declare function inclusiveDays(start: string | Date, end: string | Date): number;
231
+ declare function isValidDate(value: string | Date): boolean;
232
+ declare function formatDate(date: string | Date): string;
233
+ declare function resultInvalidDate<T>(message: string, details?: unknown): Result<T>;
234
+
235
+ export { type AffectedTasks, type Calendar, type CustomColumn, DAY_MS, type DateRange, type Dependency, type FlatTask, type GanttConfig, type GanttEditorField, type GanttError, type GanttLink, type GanttMarker, type GanttTask, type LagUnit, type LinkType, type PatchTask, type Result, type TaskLayout, type TimeScale, type ViewMode, type Viewport, addDays, checkCyclicDependency, computeImpact, computeLayout, computeTimeScale, defaultConfig, diffDays, flattenTasks, formatDate, inclusiveDays, isValidDate, normalizeLinks, resultInvalidDate, scheduleByDependencies, shiftTask, startOfDay, toDate };