mantine-gantt 0.2.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 +48 -18
- package/dist/cjs/Gantt/DependencyLinks.cjs.map +1 -1
- package/dist/cjs/Gantt/Gantt.cjs +139 -52
- 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 +13 -8
- package/dist/cjs/Gantt/TaskBar.cjs.map +1 -1
- package/dist/cjs/Gantt/TaskList.cjs +57 -14
- 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 +54 -53
- package/dist/cjs/Gantt/use-gantt-drag.cjs.map +1 -1
- 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 +49 -19
- package/dist/esm/Gantt/DependencyLinks.mjs.map +1 -1
- package/dist/esm/Gantt/Gantt.mjs +143 -56
- 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 +13 -8
- package/dist/esm/Gantt/TaskBar.mjs.map +1 -1
- package/dist/esm/Gantt/TaskList.mjs +58 -16
- 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 +55 -54
- package/dist/esm/Gantt/use-gantt-drag.mjs.map +1 -1
- 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 +9 -3
- package/dist/types/Gantt/TaskBar.d.ts +5 -1
- package/dist/types/Gantt/TaskList.d.ts +11 -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 +1 -1
- package/dist/types/Gantt/types.d.ts +66 -8
- package/dist/types/Gantt/use-gantt-drag.d.ts +2 -1
- package/dist/types/Gantt/utils.d.ts +41 -2
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/Gantt/Gantt.cjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
var dayjs = require('dayjs');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var core = require('@mantine/core');
|
|
7
|
+
var hooks = require('@mantine/hooks');
|
|
7
8
|
var DependencyLinks = require('./DependencyLinks.cjs');
|
|
8
9
|
var TaskBar = require('./TaskBar.cjs');
|
|
9
10
|
var TaskList = require('./TaskList.cjs');
|
|
@@ -14,21 +15,30 @@ var utils = require('./utils.cjs');
|
|
|
14
15
|
var Gantt_module = require('./Gantt.module.css.cjs');
|
|
15
16
|
|
|
16
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
|
+
}
|
|
17
23
|
const defaultProps = {
|
|
18
24
|
columnWidth: 40,
|
|
19
25
|
rowHeight: 44,
|
|
20
|
-
taskListWidth: 320,
|
|
21
26
|
showTitle: false,
|
|
22
27
|
showTodayMarker: true,
|
|
23
|
-
viewMode: "day"
|
|
28
|
+
viewMode: "day",
|
|
29
|
+
weekStart: 1,
|
|
30
|
+
highlightCriticalPath: false,
|
|
31
|
+
criticalPathColor: "red",
|
|
32
|
+
showBaselines: true
|
|
24
33
|
};
|
|
25
34
|
const varsResolver = core.createVarsResolver(
|
|
26
|
-
(
|
|
35
|
+
(theme, { columnWidth, rowHeight, taskListWidth, columns, criticalPathColor }) => ({
|
|
27
36
|
root: {
|
|
28
37
|
"--gantt-column-width": `${columnWidth}px`,
|
|
29
38
|
"--gantt-row-height": `${rowHeight}px`,
|
|
30
39
|
"--gantt-header-height": "50px",
|
|
31
|
-
"--gantt-task-list-width": `${taskListWidth}px
|
|
40
|
+
"--gantt-task-list-width": `${taskListWidth ?? autoTaskListWidth(columns)}px`,
|
|
41
|
+
"--gantt-critical-color": core.getThemeColor(criticalPathColor, theme)
|
|
32
42
|
}
|
|
33
43
|
})
|
|
34
44
|
);
|
|
@@ -42,19 +52,27 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
42
52
|
unstyled,
|
|
43
53
|
vars,
|
|
44
54
|
attributes,
|
|
45
|
-
tasks:
|
|
55
|
+
tasks: tasksProp,
|
|
56
|
+
defaultTasks,
|
|
57
|
+
onTasksChange,
|
|
46
58
|
columns,
|
|
47
59
|
onTaskUpdate,
|
|
48
60
|
onTaskClick,
|
|
49
61
|
onLinkCreate,
|
|
50
|
-
columnWidth,
|
|
51
|
-
rowHeight,
|
|
62
|
+
columnWidth = 40,
|
|
63
|
+
rowHeight = 44,
|
|
52
64
|
taskListWidth,
|
|
53
65
|
showTitle,
|
|
54
66
|
showTodayMarker,
|
|
55
67
|
startDate,
|
|
56
68
|
endDate,
|
|
57
|
-
viewMode,
|
|
69
|
+
viewMode = "day",
|
|
70
|
+
weekStart = 1,
|
|
71
|
+
highlightCriticalPath,
|
|
72
|
+
criticalPathColor,
|
|
73
|
+
showBaselines,
|
|
74
|
+
defaultExpandedIds,
|
|
75
|
+
onToggleExpand,
|
|
58
76
|
...others
|
|
59
77
|
} = props;
|
|
60
78
|
const getStyles = core.useStyles({
|
|
@@ -80,19 +98,54 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
80
98
|
// Each day is 1/2nd, min 14px
|
|
81
99
|
case "day":
|
|
82
100
|
default:
|
|
83
|
-
return columnWidth;
|
|
101
|
+
return Math.max(columnWidth, 1);
|
|
84
102
|
}
|
|
85
103
|
}, [viewMode, columnWidth]);
|
|
86
|
-
const [tasks, setTasks] =
|
|
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
|
+
);
|
|
87
139
|
const [announcement, setAnnouncement] = React.useState("");
|
|
88
|
-
const [
|
|
140
|
+
const [viewport, setViewport] = React.useState({ width: 0, height: 0 });
|
|
141
|
+
const [scrollTop, setScrollTop] = React.useState(0);
|
|
89
142
|
const timelineBodyRef = React.useRef(null);
|
|
90
143
|
const taskListBodyRef = React.useRef(null);
|
|
91
144
|
const timelineHeaderRef = React.useRef(null);
|
|
92
145
|
const timelineContentRef = React.useRef(null);
|
|
93
146
|
const drag = useGanttDrag.useGanttDrag({
|
|
94
147
|
tasks,
|
|
95
|
-
setTasks,
|
|
148
|
+
commitTasks: setTasks,
|
|
96
149
|
columnWidth: effectiveColumnWidth,
|
|
97
150
|
bodyRef: timelineBodyRef,
|
|
98
151
|
contentRef: timelineContentRef,
|
|
@@ -122,10 +175,12 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
122
175
|
}
|
|
123
176
|
}
|
|
124
177
|
}
|
|
125
|
-
const fillDays = effectiveColumnWidth > 0 ? Math.ceil(
|
|
178
|
+
const fillDays = effectiveColumnWidth > 0 ? Math.ceil(viewport.width / effectiveColumnWidth) : 0;
|
|
126
179
|
const totalDays = Math.max(bounds.end.diff(bounds.start, "day") + 1, fillDays);
|
|
127
180
|
const displayEnd = bounds.start.add(totalDays - 1, "day");
|
|
128
181
|
const timelineWidth = totalDays * 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,18 +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
|
}
|
|
191
|
+
setScrollTop(timelineBodyRef.current?.scrollTop ?? 0);
|
|
136
192
|
}, []);
|
|
137
193
|
React.useEffect(() => {
|
|
138
194
|
const node = timelineBodyRef.current;
|
|
139
195
|
if (!node) {
|
|
140
196
|
return void 0;
|
|
141
197
|
}
|
|
142
|
-
|
|
198
|
+
setViewport({ width: node.clientWidth, height: node.clientHeight });
|
|
143
199
|
if (typeof ResizeObserver === "undefined") {
|
|
144
200
|
return void 0;
|
|
145
201
|
}
|
|
146
202
|
const observer = new ResizeObserver((entries) => {
|
|
147
|
-
|
|
203
|
+
const { width, height } = entries[0].contentRect;
|
|
204
|
+
setViewport({ width, height });
|
|
148
205
|
});
|
|
149
206
|
observer.observe(node);
|
|
150
207
|
return () => observer.disconnect();
|
|
@@ -201,26 +258,30 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
201
258
|
if (active?.type !== "link" || !active.linkCursor) {
|
|
202
259
|
return null;
|
|
203
260
|
}
|
|
204
|
-
const srcIndex =
|
|
261
|
+
const srcIndex = rows.findIndex((r) => r.task.id === active.taskId);
|
|
205
262
|
if (srcIndex === -1) {
|
|
206
263
|
return null;
|
|
207
264
|
}
|
|
208
|
-
const src =
|
|
265
|
+
const src = rows[srcIndex];
|
|
209
266
|
const x1 = utils.dateToPixel(src.startDate, bounds.start, effectiveColumnWidth) + utils.durationToPixels(src.duration, effectiveColumnWidth);
|
|
210
267
|
const y1 = srcIndex * rowHeight + rowHeight / 2;
|
|
211
268
|
return { x1, y1, x2: active.linkCursor.x, y2: active.linkCursor.y };
|
|
212
|
-
}, [active,
|
|
269
|
+
}, [active, rows, bounds.start, effectiveColumnWidth, rowHeight]);
|
|
213
270
|
const today = dayjs();
|
|
214
271
|
const todayPosition = utils.dateToPixel(today, bounds.start, effectiveColumnWidth);
|
|
215
272
|
const showTodayLine = showTodayMarker && today.isAfter(bounds.start) && today.isBefore(displayEnd);
|
|
216
273
|
return /* @__PURE__ */ React.createElement(core.Box, { ref, ...getStyles("root"), ...others }, /* @__PURE__ */ React.createElement(
|
|
217
274
|
TaskList.TaskList,
|
|
218
275
|
{
|
|
219
|
-
|
|
276
|
+
rows: visibleRows,
|
|
220
277
|
columns,
|
|
221
278
|
getStyles,
|
|
222
279
|
bodyRef: taskListBodyRef,
|
|
223
|
-
onScroll: handleTaskListScroll
|
|
280
|
+
onScroll: handleTaskListScroll,
|
|
281
|
+
collapsedIds,
|
|
282
|
+
onToggleExpand: toggleExpand,
|
|
283
|
+
offsetTop: firstRow * rowHeight,
|
|
284
|
+
contentHeight: rows.length * rowHeight
|
|
224
285
|
}
|
|
225
286
|
), /* @__PURE__ */ React.createElement("div", { ...getStyles("timeline") }, /* @__PURE__ */ React.createElement("div", { ...getStyles("timelineHeader"), ref: timelineHeaderRef }, /* @__PURE__ */ React.createElement(
|
|
226
287
|
TimelineHeader.TimelineHeader,
|
|
@@ -230,7 +291,8 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
230
291
|
columnWidth: effectiveColumnWidth,
|
|
231
292
|
getStyles,
|
|
232
293
|
totalWidth: timelineWidth,
|
|
233
|
-
viewMode
|
|
294
|
+
viewMode,
|
|
295
|
+
weekStart
|
|
234
296
|
}
|
|
235
297
|
)), /* @__PURE__ */ React.createElement(
|
|
236
298
|
"div",
|
|
@@ -248,7 +310,7 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
248
310
|
{
|
|
249
311
|
...getStyles("timelineContent"),
|
|
250
312
|
ref: timelineContentRef,
|
|
251
|
-
style: { width: timelineWidth, height:
|
|
313
|
+
style: { width: timelineWidth, height: rows.length * rowHeight }
|
|
252
314
|
},
|
|
253
315
|
/* @__PURE__ */ React.createElement(
|
|
254
316
|
TimelineGrid.TimelineGrid,
|
|
@@ -256,44 +318,66 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
256
318
|
startDate: bounds.start,
|
|
257
319
|
endDate: displayEnd,
|
|
258
320
|
columnWidth: effectiveColumnWidth,
|
|
259
|
-
rowCount:
|
|
321
|
+
rowCount: rows.length,
|
|
260
322
|
rowHeight,
|
|
261
323
|
getStyles,
|
|
262
|
-
viewMode
|
|
324
|
+
viewMode,
|
|
325
|
+
weekStart
|
|
263
326
|
}
|
|
264
327
|
),
|
|
265
328
|
showTodayLine && /* @__PURE__ */ React.createElement("div", { ...getStyles("todayLine", { style: { left: todayPosition } }) }),
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
title: showTitle ? task.label : void 0,
|
|
272
|
-
style: { top: index * rowHeight }
|
|
273
|
-
},
|
|
274
|
-
/* @__PURE__ */ React.createElement(
|
|
275
|
-
TaskBar.TaskBar,
|
|
329
|
+
visibleRows.map((row, i) => {
|
|
330
|
+
const index = firstRow + i;
|
|
331
|
+
const task = utils.getEffectiveTask(row);
|
|
332
|
+
return /* @__PURE__ */ React.createElement(
|
|
333
|
+
"div",
|
|
276
334
|
{
|
|
277
|
-
key:
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
+
}),
|
|
293
377
|
/* @__PURE__ */ React.createElement(
|
|
294
378
|
DependencyLinks.DependencyLinks,
|
|
295
379
|
{
|
|
296
|
-
|
|
380
|
+
rows,
|
|
297
381
|
startDate: bounds.start,
|
|
298
382
|
columnWidth: effectiveColumnWidth,
|
|
299
383
|
rowHeight,
|
|
@@ -301,7 +385,10 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
301
385
|
activeDragId: active && active.type !== "link" ? active.taskId : null,
|
|
302
386
|
activeDragType: active && active.type !== "link" ? active.type : null,
|
|
303
387
|
dragDelta: active && active.type !== "link" ? active.deltaX : 0,
|
|
304
|
-
linkPreview
|
|
388
|
+
linkPreview,
|
|
389
|
+
criticalIds,
|
|
390
|
+
firstRow,
|
|
391
|
+
lastRow
|
|
305
392
|
}
|
|
306
393
|
)
|
|
307
394
|
)
|