mantine-gantt 0.1.0 → 0.3.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/README.md +57 -17
- package/dist/cjs/Gantt/DependencyLinks.cjs +60 -19
- package/dist/cjs/Gantt/DependencyLinks.cjs.map +1 -1
- package/dist/cjs/Gantt/Gantt.cjs +227 -270
- package/dist/cjs/Gantt/Gantt.cjs.map +1 -1
- package/dist/cjs/Gantt/Gantt.module.css.cjs +1 -1
- package/dist/cjs/Gantt/TaskBar.cjs +43 -100
- package/dist/cjs/Gantt/TaskBar.cjs.map +1 -1
- package/dist/cjs/Gantt/TaskList.cjs +73 -2
- package/dist/cjs/Gantt/TaskList.cjs.map +1 -1
- package/dist/cjs/Gantt/TimelineGrid.cjs +4 -3
- package/dist/cjs/Gantt/TimelineGrid.cjs.map +1 -1
- package/dist/cjs/Gantt/TimelineHeader.cjs +6 -2
- package/dist/cjs/Gantt/TimelineHeader.cjs.map +1 -1
- package/dist/cjs/Gantt/use-gantt-drag.cjs +244 -0
- package/dist/cjs/Gantt/use-gantt-drag.cjs.map +1 -0
- package/dist/cjs/Gantt/utils.cjs +224 -11
- package/dist/cjs/Gantt/utils.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/Gantt/DependencyLinks.mjs +61 -20
- package/dist/esm/Gantt/DependencyLinks.mjs.map +1 -1
- package/dist/esm/Gantt/Gantt.mjs +231 -274
- package/dist/esm/Gantt/Gantt.mjs.map +1 -1
- package/dist/esm/Gantt/Gantt.module.css.mjs +1 -1
- package/dist/esm/Gantt/TaskBar.mjs +44 -101
- package/dist/esm/Gantt/TaskBar.mjs.map +1 -1
- package/dist/esm/Gantt/TaskList.mjs +74 -4
- package/dist/esm/Gantt/TaskList.mjs.map +1 -1
- package/dist/esm/Gantt/TimelineGrid.mjs +4 -3
- package/dist/esm/Gantt/TimelineGrid.mjs.map +1 -1
- package/dist/esm/Gantt/TimelineHeader.mjs +6 -2
- package/dist/esm/Gantt/TimelineHeader.mjs.map +1 -1
- package/dist/esm/Gantt/use-gantt-drag.mjs +242 -0
- package/dist/esm/Gantt/use-gantt-drag.mjs.map +1 -0
- package/dist/esm/Gantt/utils.mjs +219 -12
- package/dist/esm/Gantt/utils.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/styles.css +5 -1
- package/dist/styles.layer.css +5 -1
- package/dist/types/Gantt/DependencyLinks.d.ts +17 -3
- package/dist/types/Gantt/TaskBar.d.ts +15 -7
- package/dist/types/Gantt/TaskList.d.ts +12 -3
- package/dist/types/Gantt/TimelineGrid.d.ts +2 -1
- package/dist/types/Gantt/TimelineHeader.d.ts +2 -1
- package/dist/types/Gantt/index.d.ts +2 -2
- package/dist/types/Gantt/types.d.ts +78 -14
- package/dist/types/Gantt/use-gantt-drag.d.ts +47 -0
- package/dist/types/Gantt/utils.d.ts +41 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -3
package/dist/esm/Gantt/Gantt.mjs
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import React, { useMemo, useState,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { createVarsResolver, factory, useProps, useStyles, Box } from '@mantine/core';
|
|
3
|
+
import React, { useMemo, useState, useCallback, useRef, useEffect, useLayoutEffect } from 'react';
|
|
4
|
+
import { createVarsResolver, getThemeColor, factory, useProps, useStyles, Box, VisuallyHidden } from '@mantine/core';
|
|
5
|
+
import { useUncontrolled } from '@mantine/hooks';
|
|
7
6
|
import { DependencyLinks } from './DependencyLinks.mjs';
|
|
8
7
|
import { TaskBar } from './TaskBar.mjs';
|
|
9
|
-
import { TaskList } from './TaskList.mjs';
|
|
8
|
+
import { defaultColumns, TaskList } from './TaskList.mjs';
|
|
10
9
|
import { TimelineGrid } from './TimelineGrid.mjs';
|
|
11
10
|
import { TimelineHeader } from './TimelineHeader.mjs';
|
|
12
|
-
import {
|
|
11
|
+
import { useGanttDrag } from './use-gantt-drag.mjs';
|
|
12
|
+
import { buildTaskTree, getCriticalPath, calculateTimelineBounds, visibleRowRange, dateToPixel, durationToPixels, getEffectiveTask } from './utils.mjs';
|
|
13
13
|
import classes from './Gantt.module.css.mjs';
|
|
14
14
|
|
|
15
15
|
const DRAG_BUFFER_DAYS = 30;
|
|
16
|
+
const EMPTY_CRITICAL = /* @__PURE__ */ new Set();
|
|
17
|
+
const FLEX_COLUMN_WIDTH = 200;
|
|
18
|
+
function autoTaskListWidth(columns = defaultColumns) {
|
|
19
|
+
return columns.reduce((sum, col) => sum + (col.width ?? FLEX_COLUMN_WIDTH), 0);
|
|
20
|
+
}
|
|
16
21
|
const defaultProps = {
|
|
17
22
|
columnWidth: 40,
|
|
18
23
|
rowHeight: 44,
|
|
19
|
-
taskListWidth: 320,
|
|
20
24
|
showTitle: false,
|
|
21
25
|
showTodayMarker: true,
|
|
22
|
-
viewMode: "day"
|
|
26
|
+
viewMode: "day",
|
|
27
|
+
weekStart: 1,
|
|
28
|
+
highlightCriticalPath: false,
|
|
29
|
+
criticalPathColor: "red",
|
|
30
|
+
showBaselines: true
|
|
23
31
|
};
|
|
24
32
|
const varsResolver = createVarsResolver(
|
|
25
|
-
(
|
|
33
|
+
(theme, { columnWidth, rowHeight, taskListWidth, columns, criticalPathColor }) => ({
|
|
26
34
|
root: {
|
|
27
35
|
"--gantt-column-width": `${columnWidth}px`,
|
|
28
36
|
"--gantt-row-height": `${rowHeight}px`,
|
|
29
37
|
"--gantt-header-height": "50px",
|
|
30
|
-
"--gantt-task-list-width": `${taskListWidth}px
|
|
38
|
+
"--gantt-task-list-width": `${taskListWidth ?? autoTaskListWidth(columns)}px`,
|
|
39
|
+
"--gantt-critical-color": getThemeColor(criticalPathColor, theme)
|
|
31
40
|
}
|
|
32
41
|
})
|
|
33
42
|
);
|
|
@@ -40,18 +49,28 @@ const Gantt = factory((_props, ref) => {
|
|
|
40
49
|
styles,
|
|
41
50
|
unstyled,
|
|
42
51
|
vars,
|
|
43
|
-
|
|
52
|
+
attributes,
|
|
53
|
+
tasks: tasksProp,
|
|
54
|
+
defaultTasks,
|
|
55
|
+
onTasksChange,
|
|
56
|
+
columns,
|
|
44
57
|
onTaskUpdate,
|
|
45
58
|
onTaskClick,
|
|
46
59
|
onLinkCreate,
|
|
47
|
-
columnWidth,
|
|
48
|
-
rowHeight,
|
|
60
|
+
columnWidth = 40,
|
|
61
|
+
rowHeight = 44,
|
|
49
62
|
taskListWidth,
|
|
50
63
|
showTitle,
|
|
51
64
|
showTodayMarker,
|
|
52
65
|
startDate,
|
|
53
66
|
endDate,
|
|
54
|
-
viewMode,
|
|
67
|
+
viewMode = "day",
|
|
68
|
+
weekStart = 1,
|
|
69
|
+
highlightCriticalPath,
|
|
70
|
+
criticalPathColor,
|
|
71
|
+
showBaselines,
|
|
72
|
+
defaultExpandedIds,
|
|
73
|
+
onToggleExpand,
|
|
55
74
|
...others
|
|
56
75
|
} = props;
|
|
57
76
|
const getStyles = useStyles({
|
|
@@ -64,6 +83,7 @@ const Gantt = factory((_props, ref) => {
|
|
|
64
83
|
styles,
|
|
65
84
|
unstyled,
|
|
66
85
|
vars,
|
|
86
|
+
attributes,
|
|
67
87
|
varsResolver
|
|
68
88
|
});
|
|
69
89
|
const effectiveColumnWidth = useMemo(() => {
|
|
@@ -76,54 +96,89 @@ const Gantt = factory((_props, ref) => {
|
|
|
76
96
|
// Each day is 1/2nd, min 14px
|
|
77
97
|
case "day":
|
|
78
98
|
default:
|
|
79
|
-
return columnWidth;
|
|
99
|
+
return Math.max(columnWidth, 1);
|
|
80
100
|
}
|
|
81
101
|
}, [viewMode, columnWidth]);
|
|
82
|
-
const [tasks, setTasks] =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
const [tasks, setTasks] = useUncontrolled({
|
|
103
|
+
value: tasksProp,
|
|
104
|
+
defaultValue: defaultTasks,
|
|
105
|
+
finalValue: [],
|
|
106
|
+
onChange: onTasksChange
|
|
107
|
+
});
|
|
108
|
+
const [collapsedIds, setCollapsedIds] = useState(() => {
|
|
109
|
+
if (!defaultExpandedIds) {
|
|
110
|
+
return /* @__PURE__ */ new Set();
|
|
111
|
+
}
|
|
112
|
+
const expanded = new Set(defaultExpandedIds);
|
|
113
|
+
return new Set(
|
|
114
|
+
buildTaskTree(tasksProp ?? defaultTasks ?? [], /* @__PURE__ */ new Set()).filter((row) => row.hasChildren && !expanded.has(row.task.id)).map((row) => row.task.id)
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
const toggleExpand = useCallback(
|
|
118
|
+
(taskId) => {
|
|
119
|
+
onToggleExpand?.(taskId, collapsedIds.has(taskId));
|
|
120
|
+
setCollapsedIds((prev) => {
|
|
121
|
+
const next = new Set(prev);
|
|
122
|
+
if (next.has(taskId)) {
|
|
123
|
+
next.delete(taskId);
|
|
124
|
+
} else {
|
|
125
|
+
next.add(taskId);
|
|
126
|
+
}
|
|
127
|
+
return next;
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
[onToggleExpand, collapsedIds]
|
|
131
|
+
);
|
|
132
|
+
const rows = useMemo(() => buildTaskTree(tasks, collapsedIds), [tasks, collapsedIds]);
|
|
133
|
+
const criticalIds = useMemo(
|
|
134
|
+
() => highlightCriticalPath ? getCriticalPath(tasks) : EMPTY_CRITICAL,
|
|
135
|
+
[highlightCriticalPath, tasks]
|
|
136
|
+
);
|
|
137
|
+
const [announcement, setAnnouncement] = useState("");
|
|
138
|
+
const [viewport, setViewport] = useState({ width: 0, height: 0 });
|
|
139
|
+
const [scrollTop, setScrollTop] = useState(0);
|
|
140
|
+
const timelineBodyRef = useRef(null);
|
|
141
|
+
const taskListBodyRef = useRef(null);
|
|
142
|
+
const timelineHeaderRef = useRef(null);
|
|
143
|
+
const timelineContentRef = useRef(null);
|
|
144
|
+
const drag = useGanttDrag({
|
|
145
|
+
tasks,
|
|
146
|
+
commitTasks: setTasks,
|
|
147
|
+
columnWidth: effectiveColumnWidth,
|
|
148
|
+
bodyRef: timelineBodyRef,
|
|
149
|
+
contentRef: timelineContentRef,
|
|
150
|
+
onTaskUpdate,
|
|
151
|
+
onLinkCreate,
|
|
152
|
+
announce: setAnnouncement
|
|
153
|
+
});
|
|
154
|
+
const active = drag.state;
|
|
87
155
|
const calculatedBounds = useMemo(
|
|
88
156
|
() => calculateTimelineBounds(tasks, startDate, endDate),
|
|
89
157
|
[tasks, startDate, endDate]
|
|
90
158
|
);
|
|
91
159
|
const stableBoundsRef = useRef(calculatedBounds);
|
|
92
|
-
if (!
|
|
160
|
+
if (!active) {
|
|
93
161
|
stableBoundsRef.current = calculatedBounds;
|
|
94
162
|
}
|
|
95
|
-
|
|
96
|
-
|
|
163
|
+
let bounds = stableBoundsRef.current;
|
|
164
|
+
if (active && active.type !== "link") {
|
|
165
|
+
const task = tasks.find((t) => t.id === active.taskId);
|
|
166
|
+
if (task) {
|
|
167
|
+
const startDay = dayjs(task.startDate).diff(bounds.start, "day");
|
|
168
|
+
const barEndDay = startDay + task.duration + Math.round(active.deltaX / effectiveColumnWidth);
|
|
169
|
+
const needed = bounds.start.add(barEndDay + DRAG_BUFFER_DAYS, "day");
|
|
170
|
+
if (needed.isAfter(bounds.end)) {
|
|
171
|
+
bounds = { start: bounds.start, end: needed };
|
|
172
|
+
stableBoundsRef.current = bounds;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const fillDays = effectiveColumnWidth > 0 ? Math.ceil(viewport.width / effectiveColumnWidth) : 0;
|
|
97
177
|
const totalDays = Math.max(bounds.end.diff(bounds.start, "day") + 1, fillDays);
|
|
98
178
|
const displayEnd = bounds.start.add(totalDays - 1, "day");
|
|
99
179
|
const timelineWidth = totalDays * effectiveColumnWidth;
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const timelineHeaderRef = useRef(null);
|
|
103
|
-
const timelineContentRef = useRef(null);
|
|
104
|
-
const [moveLeft, setMoveLeft] = useState(null);
|
|
105
|
-
const moveInfoRef = useRef(
|
|
106
|
-
null
|
|
107
|
-
);
|
|
108
|
-
const lastClientXRef = useRef(0);
|
|
109
|
-
const moveDayIndexRef = useRef(0);
|
|
110
|
-
const recomputeMove = useCallback(() => {
|
|
111
|
-
const info = moveInfoRef.current;
|
|
112
|
-
const content = timelineContentRef.current;
|
|
113
|
-
if (!info || !content) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const rect = content.getBoundingClientRect();
|
|
117
|
-
const pointerContentX = lastClientXRef.current - rect.left;
|
|
118
|
-
const dayIndex = Math.round((pointerContentX - info.grabOffsetX) / effectiveColumnWidth);
|
|
119
|
-
const start = stableBoundsRef.current.start;
|
|
120
|
-
const neededEndDay = dayIndex + info.duration + DRAG_BUFFER_DAYS;
|
|
121
|
-
if (neededEndDay > stableBoundsRef.current.end.diff(start, "day")) {
|
|
122
|
-
stableBoundsRef.current = { start, end: start.add(neededEndDay, "day") };
|
|
123
|
-
}
|
|
124
|
-
moveDayIndexRef.current = dayIndex;
|
|
125
|
-
setMoveLeft(dayIndex * effectiveColumnWidth);
|
|
126
|
-
}, [effectiveColumnWidth]);
|
|
180
|
+
const [firstRow, lastRow] = visibleRowRange(scrollTop, viewport.height, rowHeight, rows.length);
|
|
181
|
+
const visibleRows = rows.slice(firstRow, lastRow);
|
|
127
182
|
const handleTimelineScroll = useCallback(() => {
|
|
128
183
|
if (timelineBodyRef.current && taskListBodyRef.current) {
|
|
129
184
|
taskListBodyRef.current.scrollTop = timelineBodyRef.current.scrollTop;
|
|
@@ -131,32 +186,20 @@ const Gantt = factory((_props, ref) => {
|
|
|
131
186
|
if (timelineBodyRef.current && timelineHeaderRef.current) {
|
|
132
187
|
timelineHeaderRef.current.scrollLeft = timelineBodyRef.current.scrollLeft;
|
|
133
188
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
}, [recomputeMove]);
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (activeDragType !== "move" || !activeDragId) {
|
|
140
|
-
return void 0;
|
|
141
|
-
}
|
|
142
|
-
const onPointerMove = (e) => {
|
|
143
|
-
lastClientXRef.current = e.clientX;
|
|
144
|
-
recomputeMove();
|
|
145
|
-
};
|
|
146
|
-
window.addEventListener("pointermove", onPointerMove);
|
|
147
|
-
return () => window.removeEventListener("pointermove", onPointerMove);
|
|
148
|
-
}, [activeDragId, activeDragType, recomputeMove]);
|
|
189
|
+
setScrollTop(timelineBodyRef.current?.scrollTop ?? 0);
|
|
190
|
+
}, []);
|
|
149
191
|
useEffect(() => {
|
|
150
192
|
const node = timelineBodyRef.current;
|
|
151
193
|
if (!node) {
|
|
152
194
|
return void 0;
|
|
153
195
|
}
|
|
154
|
-
|
|
196
|
+
setViewport({ width: node.clientWidth, height: node.clientHeight });
|
|
155
197
|
if (typeof ResizeObserver === "undefined") {
|
|
156
198
|
return void 0;
|
|
157
199
|
}
|
|
158
200
|
const observer = new ResizeObserver((entries) => {
|
|
159
|
-
|
|
201
|
+
const { width, height } = entries[0].contentRect;
|
|
202
|
+
setViewport({ width, height });
|
|
160
203
|
});
|
|
161
204
|
observer.observe(node);
|
|
162
205
|
return () => observer.disconnect();
|
|
@@ -166,6 +209,34 @@ const Gantt = factory((_props, ref) => {
|
|
|
166
209
|
timelineBodyRef.current.scrollTop = taskListBodyRef.current.scrollTop;
|
|
167
210
|
}
|
|
168
211
|
}, []);
|
|
212
|
+
const panRef = useRef(null);
|
|
213
|
+
const handlePanStart = useCallback((e) => {
|
|
214
|
+
const body = timelineBodyRef.current;
|
|
215
|
+
if (e.pointerType !== "mouse" || !body) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
e.preventDefault();
|
|
219
|
+
panRef.current = { x: e.clientX, y: e.clientY, left: body.scrollLeft, top: body.scrollTop };
|
|
220
|
+
body.setPointerCapture?.(e.pointerId);
|
|
221
|
+
body.style.cursor = "grabbing";
|
|
222
|
+
document.body.style.userSelect = "none";
|
|
223
|
+
}, []);
|
|
224
|
+
const handlePanMove = useCallback((e) => {
|
|
225
|
+
const pan = panRef.current;
|
|
226
|
+
const body = timelineBodyRef.current;
|
|
227
|
+
if (!pan || !body) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
body.scrollLeft = pan.left - (e.clientX - pan.x);
|
|
231
|
+
body.scrollTop = pan.top - (e.clientY - pan.y);
|
|
232
|
+
}, []);
|
|
233
|
+
const handlePanEnd = useCallback(() => {
|
|
234
|
+
panRef.current = null;
|
|
235
|
+
document.body.style.userSelect = "";
|
|
236
|
+
if (timelineBodyRef.current) {
|
|
237
|
+
timelineBodyRef.current.style.cursor = "";
|
|
238
|
+
}
|
|
239
|
+
}, []);
|
|
169
240
|
const prevStartRef = useRef(bounds.start);
|
|
170
241
|
useLayoutEffect(() => {
|
|
171
242
|
const prev = prevStartRef.current;
|
|
@@ -181,168 +252,34 @@ const Gantt = factory((_props, ref) => {
|
|
|
181
252
|
prevStartRef.current = bounds.start;
|
|
182
253
|
}
|
|
183
254
|
});
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const content = timelineContentRef.current;
|
|
198
|
-
const pe = event.activatorEvent;
|
|
199
|
-
if (task && content && typeof pe?.clientX === "number") {
|
|
200
|
-
const baseLeft = dateToPixel(
|
|
201
|
-
task.startDate,
|
|
202
|
-
stableBoundsRef.current.start,
|
|
203
|
-
effectiveColumnWidth
|
|
204
|
-
);
|
|
205
|
-
const rect = content.getBoundingClientRect();
|
|
206
|
-
lastClientXRef.current = pe.clientX;
|
|
207
|
-
moveInfoRef.current = {
|
|
208
|
-
taskId: data.taskId,
|
|
209
|
-
grabOffsetX: pe.clientX - rect.left - baseLeft,
|
|
210
|
-
duration: task.duration
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
setMoveLeft(null);
|
|
214
|
-
}
|
|
215
|
-
if (data.type !== "link") {
|
|
216
|
-
stableBoundsRef.current = {
|
|
217
|
-
start: calculatedBounds.start,
|
|
218
|
-
end: calculatedBounds.end.add(DRAG_BUFFER_DAYS, "day")
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
setActiveDragId(data.taskId);
|
|
222
|
-
setActiveDragType(data.type);
|
|
223
|
-
setDragDelta(0);
|
|
224
|
-
},
|
|
225
|
-
[calculatedBounds, tasks, effectiveColumnWidth]
|
|
226
|
-
);
|
|
227
|
-
const handleDragMove = useCallback(
|
|
228
|
-
(event) => {
|
|
229
|
-
const snappedDelta = snapToGrid(event.delta.x, effectiveColumnWidth);
|
|
230
|
-
setDragDelta(snappedDelta);
|
|
231
|
-
},
|
|
232
|
-
[effectiveColumnWidth]
|
|
233
|
-
);
|
|
234
|
-
const handleDragEnd = useCallback(
|
|
235
|
-
(event) => {
|
|
236
|
-
const { active, over, delta } = event;
|
|
237
|
-
const data = active.data.current;
|
|
238
|
-
if (data.type === "link") {
|
|
239
|
-
if (over) {
|
|
240
|
-
const overData = over.data.current;
|
|
241
|
-
if (overData && overData.taskId !== data.taskId) {
|
|
242
|
-
const fromTaskId = data.taskId;
|
|
243
|
-
const toTaskId = overData.taskId;
|
|
244
|
-
setTasks(
|
|
245
|
-
(currentTasks) => currentTasks.map((task) => {
|
|
246
|
-
if (task.id !== toTaskId) {
|
|
247
|
-
return task;
|
|
248
|
-
}
|
|
249
|
-
const deps = task.dependencies || [];
|
|
250
|
-
if (deps.includes(fromTaskId)) {
|
|
251
|
-
return task;
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
...task,
|
|
255
|
-
dependencies: [...deps, fromTaskId]
|
|
256
|
-
};
|
|
257
|
-
})
|
|
258
|
-
);
|
|
259
|
-
if (onLinkCreate) {
|
|
260
|
-
onLinkCreate(fromTaskId, toTaskId);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
setActiveDragId(null);
|
|
265
|
-
setActiveDragType(null);
|
|
266
|
-
setDragDelta(0);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
if (data.type === "move") {
|
|
270
|
-
const newStart = stableBoundsRef.current.start.add(moveDayIndexRef.current, "day");
|
|
271
|
-
const current = tasks.find((t) => t.id === data.taskId);
|
|
272
|
-
const changed = !current || !dayjs(current.startDate).isSame(newStart, "day");
|
|
273
|
-
flushSync(() => {
|
|
274
|
-
if (changed) {
|
|
275
|
-
setTasks((currentTasks) => {
|
|
276
|
-
const updatedTasks = currentTasks.map(
|
|
277
|
-
(task) => task.id === data.taskId ? { ...task, startDate: newStart.format("YYYY-MM-DD") } : task
|
|
278
|
-
);
|
|
279
|
-
const updatedTask = updatedTasks.find((t) => t.id === data.taskId);
|
|
280
|
-
if (updatedTask && onTaskUpdate) {
|
|
281
|
-
onTaskUpdate(updatedTask);
|
|
282
|
-
}
|
|
283
|
-
return updatedTasks;
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
moveInfoRef.current = null;
|
|
287
|
-
setMoveLeft(null);
|
|
288
|
-
setActiveDragId(null);
|
|
289
|
-
setActiveDragType(null);
|
|
290
|
-
setDragDelta(0);
|
|
291
|
-
});
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const snappedDelta = snapToGrid(delta.x, effectiveColumnWidth);
|
|
295
|
-
const daysDelta = Math.round(snappedDelta / effectiveColumnWidth);
|
|
296
|
-
if (daysDelta !== 0) {
|
|
297
|
-
flushSync(() => {
|
|
298
|
-
setTasks((currentTasks) => {
|
|
299
|
-
const updatedTasks = currentTasks.map((task) => {
|
|
300
|
-
if (task.id !== data.taskId) {
|
|
301
|
-
return task;
|
|
302
|
-
}
|
|
303
|
-
if (data.type === "resize-end") {
|
|
304
|
-
const newDuration2 = Math.max(1, task.duration + daysDelta);
|
|
305
|
-
return {
|
|
306
|
-
...task,
|
|
307
|
-
duration: newDuration2
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
const newDuration = Math.max(1, task.duration - daysDelta);
|
|
311
|
-
const newStartDate = dayjs(task.startDate).add(daysDelta, "day");
|
|
312
|
-
return {
|
|
313
|
-
...task,
|
|
314
|
-
startDate: newStartDate.format("YYYY-MM-DD"),
|
|
315
|
-
duration: newDuration
|
|
316
|
-
};
|
|
317
|
-
});
|
|
318
|
-
const updatedTask = updatedTasks.find((t) => t.id === data.taskId);
|
|
319
|
-
if (updatedTask && onTaskUpdate) {
|
|
320
|
-
onTaskUpdate(updatedTask);
|
|
321
|
-
}
|
|
322
|
-
return updatedTasks;
|
|
323
|
-
});
|
|
324
|
-
setActiveDragId(null);
|
|
325
|
-
setActiveDragType(null);
|
|
326
|
-
setDragDelta(0);
|
|
327
|
-
});
|
|
328
|
-
} else {
|
|
329
|
-
setActiveDragId(null);
|
|
330
|
-
setActiveDragType(null);
|
|
331
|
-
setDragDelta(0);
|
|
332
|
-
}
|
|
333
|
-
},
|
|
334
|
-
[effectiveColumnWidth, onTaskUpdate, onLinkCreate, tasks]
|
|
335
|
-
);
|
|
255
|
+
const linkPreview = useMemo(() => {
|
|
256
|
+
if (active?.type !== "link" || !active.linkCursor) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const srcIndex = rows.findIndex((r) => r.task.id === active.taskId);
|
|
260
|
+
if (srcIndex === -1) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const src = rows[srcIndex];
|
|
264
|
+
const x1 = dateToPixel(src.startDate, bounds.start, effectiveColumnWidth) + durationToPixels(src.duration, effectiveColumnWidth);
|
|
265
|
+
const y1 = srcIndex * rowHeight + rowHeight / 2;
|
|
266
|
+
return { x1, y1, x2: active.linkCursor.x, y2: active.linkCursor.y };
|
|
267
|
+
}, [active, rows, bounds.start, effectiveColumnWidth, rowHeight]);
|
|
336
268
|
const today = dayjs();
|
|
337
269
|
const todayPosition = dateToPixel(today, bounds.start, effectiveColumnWidth);
|
|
338
270
|
const showTodayLine = showTodayMarker && today.isAfter(bounds.start) && today.isBefore(displayEnd);
|
|
339
271
|
return /* @__PURE__ */ React.createElement(Box, { ref, ...getStyles("root"), ...others }, /* @__PURE__ */ React.createElement(
|
|
340
272
|
TaskList,
|
|
341
273
|
{
|
|
342
|
-
|
|
274
|
+
rows: visibleRows,
|
|
275
|
+
columns,
|
|
343
276
|
getStyles,
|
|
344
277
|
bodyRef: taskListBodyRef,
|
|
345
|
-
onScroll: handleTaskListScroll
|
|
278
|
+
onScroll: handleTaskListScroll,
|
|
279
|
+
collapsedIds,
|
|
280
|
+
onToggleExpand: toggleExpand,
|
|
281
|
+
offsetTop: firstRow * rowHeight,
|
|
282
|
+
contentHeight: rows.length * rowHeight
|
|
346
283
|
}
|
|
347
284
|
), /* @__PURE__ */ React.createElement("div", { ...getStyles("timeline") }, /* @__PURE__ */ React.createElement("div", { ...getStyles("timelineHeader"), ref: timelineHeaderRef }, /* @__PURE__ */ React.createElement(
|
|
348
285
|
TimelineHeader,
|
|
@@ -352,22 +289,26 @@ const Gantt = factory((_props, ref) => {
|
|
|
352
289
|
columnWidth: effectiveColumnWidth,
|
|
353
290
|
getStyles,
|
|
354
291
|
totalWidth: timelineWidth,
|
|
355
|
-
viewMode
|
|
292
|
+
viewMode,
|
|
293
|
+
weekStart
|
|
356
294
|
}
|
|
357
295
|
)), /* @__PURE__ */ React.createElement(
|
|
358
|
-
|
|
296
|
+
"div",
|
|
359
297
|
{
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
298
|
+
...getStyles("timelineBody"),
|
|
299
|
+
ref: timelineBodyRef,
|
|
300
|
+
onScroll: handleTimelineScroll,
|
|
301
|
+
onPointerDown: handlePanStart,
|
|
302
|
+
onPointerMove: handlePanMove,
|
|
303
|
+
onPointerUp: handlePanEnd,
|
|
304
|
+
onPointerCancel: handlePanEnd
|
|
364
305
|
},
|
|
365
|
-
/* @__PURE__ */ React.createElement(
|
|
306
|
+
/* @__PURE__ */ React.createElement(
|
|
366
307
|
"div",
|
|
367
308
|
{
|
|
368
309
|
...getStyles("timelineContent"),
|
|
369
310
|
ref: timelineContentRef,
|
|
370
|
-
style: { width: timelineWidth, height:
|
|
311
|
+
style: { width: timelineWidth, height: rows.length * rowHeight }
|
|
371
312
|
},
|
|
372
313
|
/* @__PURE__ */ React.createElement(
|
|
373
314
|
TimelineGrid,
|
|
@@ -375,65 +316,81 @@ const Gantt = factory((_props, ref) => {
|
|
|
375
316
|
startDate: bounds.start,
|
|
376
317
|
endDate: displayEnd,
|
|
377
318
|
columnWidth: effectiveColumnWidth,
|
|
378
|
-
rowCount:
|
|
319
|
+
rowCount: rows.length,
|
|
379
320
|
rowHeight,
|
|
380
321
|
getStyles,
|
|
381
|
-
viewMode
|
|
322
|
+
viewMode,
|
|
323
|
+
weekStart
|
|
382
324
|
}
|
|
383
325
|
),
|
|
384
|
-
showTodayLine && /* @__PURE__ */ React.createElement("div", {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
title: showTitle ? task.label : void 0,
|
|
391
|
-
style: { top: index * rowHeight }
|
|
392
|
-
},
|
|
393
|
-
/* @__PURE__ */ React.createElement(
|
|
394
|
-
TaskBar,
|
|
326
|
+
showTodayLine && /* @__PURE__ */ React.createElement("div", { ...getStyles("todayLine", { style: { left: todayPosition } }) }),
|
|
327
|
+
visibleRows.map((row, i) => {
|
|
328
|
+
const index = firstRow + i;
|
|
329
|
+
const task = getEffectiveTask(row);
|
|
330
|
+
return /* @__PURE__ */ React.createElement(
|
|
331
|
+
"div",
|
|
395
332
|
{
|
|
396
|
-
key:
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
333
|
+
key: task.id,
|
|
334
|
+
...getStyles("timelineRow"),
|
|
335
|
+
title: showTitle ? task.label : void 0,
|
|
336
|
+
style: { top: index * rowHeight }
|
|
337
|
+
},
|
|
338
|
+
/* @__PURE__ */ React.createElement(
|
|
339
|
+
TaskBar,
|
|
340
|
+
{
|
|
341
|
+
key: `taskbar-${task.id}`,
|
|
342
|
+
task,
|
|
343
|
+
startDate: bounds.start,
|
|
344
|
+
columnWidth: effectiveColumnWidth,
|
|
345
|
+
getStyles,
|
|
346
|
+
isSummary: row.hasChildren,
|
|
347
|
+
isDragging: active?.taskId === task.id && active.type !== "link",
|
|
348
|
+
isLinkTarget: active?.type === "link" && active.dropTargetId === task.id,
|
|
349
|
+
dragType: active?.taskId === task.id ? active.type : null,
|
|
350
|
+
dragDeltaX: active?.taskId === task.id ? active.deltaX : 0,
|
|
351
|
+
startDrag: drag.startDrag,
|
|
352
|
+
didDrag: drag.didDrag,
|
|
353
|
+
nudge: drag.nudge,
|
|
354
|
+
onClick: () => onTaskClick?.(task),
|
|
355
|
+
isCritical: criticalIds.has(task.id)
|
|
356
|
+
}
|
|
357
|
+
),
|
|
358
|
+
showBaselines && task.baseline && /* @__PURE__ */ React.createElement(
|
|
359
|
+
"div",
|
|
360
|
+
{
|
|
361
|
+
...getStyles("baselineBar"),
|
|
362
|
+
"data-task-id": task.id,
|
|
363
|
+
style: {
|
|
364
|
+
left: dateToPixel(
|
|
365
|
+
task.baseline.startDate,
|
|
366
|
+
bounds.start,
|
|
367
|
+
effectiveColumnWidth
|
|
368
|
+
),
|
|
369
|
+
width: durationToPixels(task.baseline.duration, effectiveColumnWidth)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
)
|
|
373
|
+
);
|
|
374
|
+
}),
|
|
409
375
|
/* @__PURE__ */ React.createElement(
|
|
410
376
|
DependencyLinks,
|
|
411
377
|
{
|
|
412
|
-
|
|
378
|
+
rows,
|
|
413
379
|
startDate: bounds.start,
|
|
414
380
|
columnWidth: effectiveColumnWidth,
|
|
415
381
|
rowHeight,
|
|
416
382
|
getStyles,
|
|
417
|
-
activeDragId,
|
|
418
|
-
activeDragType,
|
|
419
|
-
dragDelta
|
|
383
|
+
activeDragId: active && active.type !== "link" ? active.taskId : null,
|
|
384
|
+
activeDragType: active && active.type !== "link" ? active.type : null,
|
|
385
|
+
dragDelta: active && active.type !== "link" ? active.deltaX : 0,
|
|
386
|
+
linkPreview,
|
|
387
|
+
criticalIds,
|
|
388
|
+
firstRow,
|
|
389
|
+
lastRow
|
|
420
390
|
}
|
|
421
391
|
)
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
"div",
|
|
425
|
-
{
|
|
426
|
-
style: {
|
|
427
|
-
width: 16,
|
|
428
|
-
height: 16,
|
|
429
|
-
borderRadius: "50%",
|
|
430
|
-
backgroundColor: "var(--mantine-primary-color-filled)",
|
|
431
|
-
border: "2px solid white",
|
|
432
|
-
boxShadow: "0 2px 8px rgba(0,0,0,0.3)"
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
))
|
|
436
|
-
)));
|
|
392
|
+
)
|
|
393
|
+
)), /* @__PURE__ */ React.createElement(VisuallyHidden, { "aria-live": "polite" }, announcement));
|
|
437
394
|
});
|
|
438
395
|
Gantt.displayName = "Gantt";
|
|
439
396
|
Gantt.classes = classes;
|