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