mantine-gantt 0.6.1 → 0.7.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 +43 -166
- package/dist/cjs/Gantt/DependencyLinks.cjs +10 -5
- package/dist/cjs/Gantt/DependencyLinks.cjs.map +1 -1
- package/dist/cjs/Gantt/Gantt.cjs +91 -56
- package/dist/cjs/Gantt/Gantt.cjs.map +1 -1
- package/dist/cjs/Gantt/TaskBar.cjs +13 -19
- package/dist/cjs/Gantt/TaskBar.cjs.map +1 -1
- package/dist/cjs/Gantt/TaskList.cjs +5 -5
- package/dist/cjs/Gantt/TaskList.cjs.map +1 -1
- package/dist/cjs/Gantt/TimelineGrid.cjs +2 -1
- package/dist/cjs/Gantt/TimelineGrid.cjs.map +1 -1
- package/dist/cjs/Gantt/TimelineHeader.cjs +4 -4
- package/dist/cjs/Gantt/TimelineHeader.cjs.map +1 -1
- package/dist/cjs/Gantt/use-gantt-drag.cjs +22 -19
- package/dist/cjs/Gantt/use-gantt-drag.cjs.map +1 -1
- package/dist/cjs/Gantt/utils.cjs +71 -28
- package/dist/cjs/Gantt/utils.cjs.map +1 -1
- package/dist/esm/Gantt/DependencyLinks.mjs +11 -6
- package/dist/esm/Gantt/DependencyLinks.mjs.map +1 -1
- package/dist/esm/Gantt/Gantt.mjs +93 -58
- package/dist/esm/Gantt/Gantt.mjs.map +1 -1
- package/dist/esm/Gantt/TaskBar.mjs +14 -20
- package/dist/esm/Gantt/TaskBar.mjs.map +1 -1
- package/dist/esm/Gantt/TaskList.mjs +5 -5
- package/dist/esm/Gantt/TaskList.mjs.map +1 -1
- package/dist/esm/Gantt/TimelineGrid.mjs +2 -1
- package/dist/esm/Gantt/TimelineGrid.mjs.map +1 -1
- package/dist/esm/Gantt/TimelineHeader.mjs +4 -4
- package/dist/esm/Gantt/TimelineHeader.mjs.map +1 -1
- package/dist/esm/Gantt/use-gantt-drag.mjs +22 -19
- package/dist/esm/Gantt/use-gantt-drag.mjs.map +1 -1
- package/dist/esm/Gantt/utils.mjs +71 -29
- package/dist/esm/Gantt/utils.mjs.map +1 -1
- package/dist/types/Gantt/DependencyLinks.d.ts +2 -4
- package/dist/types/Gantt/TaskList.d.ts +2 -4
- package/dist/types/Gantt/TimelineGrid.d.ts +2 -4
- package/dist/types/Gantt/TimelineHeader.d.ts +5 -5
- package/dist/types/Gantt/types.d.ts +4 -2
- package/dist/types/Gantt/utils.d.ts +13 -5
- package/package.json +3 -4
package/dist/cjs/Gantt/Gantt.cjs
CHANGED
|
@@ -15,7 +15,9 @@ 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 PAN_CAPTURE_DISTANCE = 3;
|
|
18
19
|
const MIN_TIMELINE_WIDTH = 240;
|
|
20
|
+
const UNMEASURED_VIEWPORT_HEIGHT = 1200;
|
|
19
21
|
const EMPTY_CRITICAL = /* @__PURE__ */ new Set();
|
|
20
22
|
const FLEX_COLUMN_WIDTH = 200;
|
|
21
23
|
const FLEX_COLUMN_MIN_WIDTH = 100;
|
|
@@ -50,7 +52,7 @@ const varsResolver = core.createVarsResolver(
|
|
|
50
52
|
}
|
|
51
53
|
})
|
|
52
54
|
);
|
|
53
|
-
const Gantt = core.factory((_props
|
|
55
|
+
const Gantt = core.factory((_props) => {
|
|
54
56
|
const props = core.useProps("Gantt", defaultProps, _props);
|
|
55
57
|
const theme = core.useMantineTheme();
|
|
56
58
|
const {
|
|
@@ -96,6 +98,7 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
96
98
|
workingDays,
|
|
97
99
|
onColumnWidthChange,
|
|
98
100
|
showDragLabel,
|
|
101
|
+
ref,
|
|
99
102
|
...others
|
|
100
103
|
} = props;
|
|
101
104
|
const [zoomWidth, setZoomWidth] = React.useState(null);
|
|
@@ -114,6 +117,12 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
114
117
|
attributes,
|
|
115
118
|
varsResolver
|
|
116
119
|
});
|
|
120
|
+
const getStylesRef = React.useRef(getStyles);
|
|
121
|
+
getStylesRef.current = getStyles;
|
|
122
|
+
const stableGetStyles = React.useCallback(
|
|
123
|
+
(...args) => getStylesRef.current(...args),
|
|
124
|
+
[classNames, styles, unstyled, vars, attributes, theme]
|
|
125
|
+
);
|
|
117
126
|
const effectiveColumnWidth = React.useMemo(() => {
|
|
118
127
|
switch (viewMode) {
|
|
119
128
|
case "month":
|
|
@@ -128,12 +137,13 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
128
137
|
}
|
|
129
138
|
}, [viewMode, baseColumnWidth]);
|
|
130
139
|
const calendar = workingDays ? isNonWorkingDay ?? utils.isWeekend : void 0;
|
|
131
|
-
const [tasks,
|
|
140
|
+
const [tasks, setTasksUnstable] = hooks.useUncontrolled({
|
|
132
141
|
value: tasksProp,
|
|
133
142
|
defaultValue: defaultTasks,
|
|
134
143
|
finalValue: [],
|
|
135
144
|
onChange: onTasksChange
|
|
136
145
|
});
|
|
146
|
+
const setTasks = hooks.useCallbackRef(setTasksUnstable);
|
|
137
147
|
const [collapsedIds, setCollapsedIds] = React.useState(() => {
|
|
138
148
|
if (!defaultExpandedIds) {
|
|
139
149
|
return /* @__PURE__ */ new Set();
|
|
@@ -170,12 +180,17 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
170
180
|
const [viewport, setViewport] = React.useState({ width: 0, height: 0 });
|
|
171
181
|
const [scrollTop, setScrollTop] = React.useState(0);
|
|
172
182
|
const [narrow, setNarrow] = React.useState(false);
|
|
173
|
-
const [collapsedChoice,
|
|
183
|
+
const [collapsedChoice, setCollapsedChoiceUnstable] = hooks.useUncontrolled({
|
|
174
184
|
value: taskListCollapsed,
|
|
175
185
|
defaultValue: defaultTaskListCollapsed,
|
|
176
186
|
onChange: onTaskListCollapsedChange
|
|
177
187
|
});
|
|
188
|
+
const setCollapsedChoice = hooks.useCallbackRef(setCollapsedChoiceUnstable);
|
|
178
189
|
const listCollapsed = collapsedChoice ?? narrow;
|
|
190
|
+
const toggleListCollapsed = React.useCallback(
|
|
191
|
+
() => setCollapsedChoice(!listCollapsed),
|
|
192
|
+
[listCollapsed, setCollapsedChoice]
|
|
193
|
+
);
|
|
179
194
|
const listWidth = resolveTaskListWidth(taskListWidth, columns);
|
|
180
195
|
const timelineBodyRef = React.useRef(null);
|
|
181
196
|
const taskListBodyRef = React.useRef(null);
|
|
@@ -235,10 +250,18 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
235
250
|
}, [calculatedBounds, active, tasks, effectiveColumnWidth, calendar]);
|
|
236
251
|
const fillDays = effectiveColumnWidth > 0 ? Math.ceil(viewport.width / effectiveColumnWidth) : 0;
|
|
237
252
|
const totalDays = Math.max(bounds.end.diff(bounds.start, "day") + 1, fillDays);
|
|
238
|
-
const displayEnd =
|
|
253
|
+
const displayEnd = React.useMemo(
|
|
254
|
+
() => bounds.start.add(totalDays - 1, "day"),
|
|
255
|
+
[bounds.start, totalDays]
|
|
256
|
+
);
|
|
239
257
|
const timelineWidth = totalDays * effectiveColumnWidth;
|
|
240
|
-
const [firstRow, lastRow] = utils.visibleRowRange(
|
|
241
|
-
|
|
258
|
+
const [firstRow, lastRow] = utils.visibleRowRange(
|
|
259
|
+
scrollTop,
|
|
260
|
+
viewport.height || UNMEASURED_VIEWPORT_HEIGHT,
|
|
261
|
+
rowHeight,
|
|
262
|
+
rows.length
|
|
263
|
+
);
|
|
264
|
+
const visibleRows = React.useMemo(() => rows.slice(firstRow, lastRow), [rows, firstRow, lastRow]);
|
|
242
265
|
const handleTimelineScroll = React.useCallback(() => {
|
|
243
266
|
const body = timelineBodyRef.current;
|
|
244
267
|
if (!body) {
|
|
@@ -250,14 +273,14 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
250
273
|
if (timelineHeaderRef.current) {
|
|
251
274
|
timelineHeaderRef.current.scrollLeft = body.scrollLeft;
|
|
252
275
|
}
|
|
253
|
-
setScrollTop(body.scrollTop);
|
|
254
|
-
}, []);
|
|
276
|
+
setScrollTop(Math.floor(body.scrollTop / rowHeight) * rowHeight);
|
|
277
|
+
}, [rowHeight]);
|
|
255
278
|
const handleTaskListScroll = React.useCallback(() => {
|
|
256
279
|
if (taskListBodyRef.current && timelineBodyRef.current) {
|
|
257
280
|
timelineBodyRef.current.scrollTop = taskListBodyRef.current.scrollTop;
|
|
258
281
|
}
|
|
259
282
|
}, []);
|
|
260
|
-
React.
|
|
283
|
+
React.useLayoutEffect(() => {
|
|
261
284
|
const node = timelineBodyRef.current;
|
|
262
285
|
const root = rootRef.current;
|
|
263
286
|
if (!node || !root) {
|
|
@@ -361,6 +384,18 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
361
384
|
body.scrollTop += speed(pan.top - pan.y);
|
|
362
385
|
pan.raf = requestAnimationFrame(autoScrollTick);
|
|
363
386
|
}, []);
|
|
387
|
+
const handlePanEnd = React.useCallback(function end() {
|
|
388
|
+
document.removeEventListener("pointerup", end);
|
|
389
|
+
document.removeEventListener("pointercancel", end);
|
|
390
|
+
if (panRef.current?.raf !== null && panRef.current?.raf !== void 0) {
|
|
391
|
+
cancelAnimationFrame(panRef.current.raf);
|
|
392
|
+
}
|
|
393
|
+
panRef.current = null;
|
|
394
|
+
document.body.style.userSelect = "";
|
|
395
|
+
if (timelineBodyRef.current) {
|
|
396
|
+
timelineBodyRef.current.style.cursor = "";
|
|
397
|
+
}
|
|
398
|
+
}, []);
|
|
364
399
|
const handlePanStart = React.useCallback(
|
|
365
400
|
(e) => {
|
|
366
401
|
const body = timelineBodyRef.current;
|
|
@@ -369,22 +404,28 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
369
404
|
}
|
|
370
405
|
e.preventDefault();
|
|
371
406
|
const auto = e.button === 1;
|
|
372
|
-
panRef.current =
|
|
407
|
+
panRef.current = {
|
|
373
408
|
x: e.clientX,
|
|
374
409
|
y: e.clientY,
|
|
375
|
-
left: body.scrollLeft,
|
|
376
|
-
top: body.scrollTop,
|
|
410
|
+
left: auto ? e.clientX : body.scrollLeft,
|
|
411
|
+
top: auto ? e.clientY : body.scrollTop,
|
|
377
412
|
auto,
|
|
378
|
-
raf: null
|
|
413
|
+
raf: null,
|
|
414
|
+
pointerId: e.pointerId,
|
|
415
|
+
captured: auto
|
|
379
416
|
};
|
|
380
|
-
|
|
417
|
+
if (auto) {
|
|
418
|
+
body.setPointerCapture?.(e.pointerId);
|
|
419
|
+
}
|
|
381
420
|
body.style.cursor = auto ? "all-scroll" : "grabbing";
|
|
382
421
|
document.body.style.userSelect = "none";
|
|
422
|
+
document.addEventListener("pointerup", handlePanEnd);
|
|
423
|
+
document.addEventListener("pointercancel", handlePanEnd);
|
|
383
424
|
if (auto) {
|
|
384
425
|
panRef.current.raf = requestAnimationFrame(autoScrollTick);
|
|
385
426
|
}
|
|
386
427
|
},
|
|
387
|
-
[autoScrollTick]
|
|
428
|
+
[autoScrollTick, handlePanEnd]
|
|
388
429
|
);
|
|
389
430
|
const handlePanMove = React.useCallback((e) => {
|
|
390
431
|
const pan = panRef.current;
|
|
@@ -397,19 +438,13 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
397
438
|
pan.top = e.clientY;
|
|
398
439
|
return;
|
|
399
440
|
}
|
|
441
|
+
if (!pan.captured && Math.hypot(e.clientX - pan.x, e.clientY - pan.y) >= PAN_CAPTURE_DISTANCE) {
|
|
442
|
+
pan.captured = true;
|
|
443
|
+
body.setPointerCapture?.(pan.pointerId);
|
|
444
|
+
}
|
|
400
445
|
body.scrollLeft = pan.left - (e.clientX - pan.x);
|
|
401
446
|
body.scrollTop = pan.top - (e.clientY - pan.y);
|
|
402
447
|
}, []);
|
|
403
|
-
const handlePanEnd = React.useCallback(() => {
|
|
404
|
-
if (panRef.current?.raf !== null && panRef.current?.raf !== void 0) {
|
|
405
|
-
cancelAnimationFrame(panRef.current.raf);
|
|
406
|
-
}
|
|
407
|
-
panRef.current = null;
|
|
408
|
-
document.body.style.userSelect = "";
|
|
409
|
-
if (timelineBodyRef.current) {
|
|
410
|
-
timelineBodyRef.current.style.cursor = "";
|
|
411
|
-
}
|
|
412
|
-
}, []);
|
|
413
448
|
React.useEffect(() => handlePanEnd, [handlePanEnd]);
|
|
414
449
|
const prevStartRef = React.useRef(bounds.start);
|
|
415
450
|
React.useLayoutEffect(() => {
|
|
@@ -441,14 +476,14 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
441
476
|
}, [active, rows, bounds.start, effectiveColumnWidth, rowHeight]);
|
|
442
477
|
const today = dayjs();
|
|
443
478
|
const todayPosition = utils.dateToPixel(today, bounds.start, effectiveColumnWidth);
|
|
444
|
-
const showTodayLine = showTodayMarker && today.
|
|
479
|
+
const showTodayLine = showTodayMarker && !today.isBefore(bounds.start, "day") && !today.isAfter(displayEnd, "day");
|
|
445
480
|
return /* @__PURE__ */ React.createElement(core.Box, { ref: mergedRootRef, ...getStyles("root"), ...others }, /* @__PURE__ */ React.createElement(
|
|
446
481
|
TaskList.TaskList,
|
|
447
482
|
{
|
|
448
483
|
rows: visibleRows,
|
|
449
484
|
columns,
|
|
450
485
|
locale,
|
|
451
|
-
getStyles,
|
|
486
|
+
getStyles: stableGetStyles,
|
|
452
487
|
bodyRef: taskListBodyRef,
|
|
453
488
|
onScroll: handleTaskListScroll,
|
|
454
489
|
collapsedIds,
|
|
@@ -457,7 +492,7 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
457
492
|
contentHeight: rows.length * rowHeight,
|
|
458
493
|
selectedTaskId,
|
|
459
494
|
collapsed: listCollapsed,
|
|
460
|
-
onToggleCollapsed:
|
|
495
|
+
onToggleCollapsed: toggleListCollapsed
|
|
461
496
|
}
|
|
462
497
|
), /* @__PURE__ */ React.createElement("div", { ...getStyles("timeline") }, /* @__PURE__ */ React.createElement("div", { ...getStyles("timelineHeader"), ref: timelineHeaderRef }, /* @__PURE__ */ React.createElement(
|
|
463
498
|
TimelineHeader.TimelineHeader,
|
|
@@ -465,10 +500,11 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
465
500
|
startDate: bounds.start,
|
|
466
501
|
endDate: displayEnd,
|
|
467
502
|
columnWidth: effectiveColumnWidth,
|
|
468
|
-
getStyles,
|
|
503
|
+
getStyles: stableGetStyles,
|
|
469
504
|
totalWidth: timelineWidth,
|
|
470
505
|
viewMode,
|
|
471
506
|
weekStart,
|
|
507
|
+
today: today.format("YYYY-MM-DD"),
|
|
472
508
|
locale,
|
|
473
509
|
isNonWorkingDay
|
|
474
510
|
}
|
|
@@ -479,16 +515,15 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
479
515
|
ref: timelineBodyRef,
|
|
480
516
|
onScroll: handleTimelineScroll,
|
|
481
517
|
onPointerDown: handlePanStart,
|
|
482
|
-
onPointerMove: handlePanMove
|
|
483
|
-
onPointerUp: handlePanEnd,
|
|
484
|
-
onPointerCancel: handlePanEnd
|
|
518
|
+
onPointerMove: handlePanMove
|
|
485
519
|
},
|
|
486
520
|
/* @__PURE__ */ React.createElement(
|
|
487
521
|
"div",
|
|
488
522
|
{
|
|
489
|
-
...getStyles("timelineContent"
|
|
490
|
-
|
|
491
|
-
|
|
523
|
+
...getStyles("timelineContent", {
|
|
524
|
+
style: { width: timelineWidth, height: rows.length * rowHeight }
|
|
525
|
+
}),
|
|
526
|
+
ref: timelineContentRef
|
|
492
527
|
},
|
|
493
528
|
/* @__PURE__ */ React.createElement(
|
|
494
529
|
TimelineGrid.TimelineGrid,
|
|
@@ -498,14 +533,14 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
498
533
|
columnWidth: effectiveColumnWidth,
|
|
499
534
|
rowCount: rows.length,
|
|
500
535
|
rowHeight,
|
|
501
|
-
getStyles,
|
|
536
|
+
getStyles: stableGetStyles,
|
|
502
537
|
viewMode,
|
|
503
538
|
weekStart,
|
|
504
539
|
isNonWorkingDay
|
|
505
540
|
}
|
|
506
541
|
),
|
|
507
542
|
showTodayLine && /* @__PURE__ */ React.createElement("div", { ...getStyles("todayLine", { style: { left: todayPosition } }) }),
|
|
508
|
-
markers?.map((marker) => {
|
|
543
|
+
markers?.map((marker, index) => {
|
|
509
544
|
const date = dayjs(marker.date);
|
|
510
545
|
if (date.isBefore(bounds.start) || date.isAfter(displayEnd)) {
|
|
511
546
|
return null;
|
|
@@ -513,7 +548,7 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
513
548
|
return /* @__PURE__ */ React.createElement(
|
|
514
549
|
"div",
|
|
515
550
|
{
|
|
516
|
-
key:
|
|
551
|
+
key: index,
|
|
517
552
|
...getStyles("marker", {
|
|
518
553
|
style: {
|
|
519
554
|
left: utils.dateToPixel(date, bounds.start, effectiveColumnWidth),
|
|
@@ -531,10 +566,9 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
531
566
|
"div",
|
|
532
567
|
{
|
|
533
568
|
key: task.id,
|
|
534
|
-
...getStyles("timelineRow"),
|
|
569
|
+
...getStyles("timelineRow", { style: { top: index * rowHeight } }),
|
|
535
570
|
"data-first": index === Math.floor(scrollTop / rowHeight) || void 0,
|
|
536
|
-
title: showTitle ? task.label : void 0
|
|
537
|
-
style: { top: index * rowHeight }
|
|
571
|
+
title: showTitle ? task.label : void 0
|
|
538
572
|
},
|
|
539
573
|
/* @__PURE__ */ React.createElement(
|
|
540
574
|
TaskBar.TaskBar,
|
|
@@ -542,7 +576,7 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
542
576
|
task,
|
|
543
577
|
startDate: bounds.start,
|
|
544
578
|
columnWidth: effectiveColumnWidth,
|
|
545
|
-
getStyles,
|
|
579
|
+
getStyles: stableGetStyles,
|
|
546
580
|
span: row.span,
|
|
547
581
|
isNonWorkingDay: calendar,
|
|
548
582
|
isSummary: row.hasChildren,
|
|
@@ -565,19 +599,20 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
565
599
|
showBaselines && task.baseline && /* @__PURE__ */ React.createElement(
|
|
566
600
|
"div",
|
|
567
601
|
{
|
|
568
|
-
...getStyles("baselineBar"
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}
|
|
602
|
+
...getStyles("baselineBar", {
|
|
603
|
+
style: {
|
|
604
|
+
left: utils.dateToPixel(
|
|
605
|
+
task.baseline.startDate,
|
|
606
|
+
bounds.start,
|
|
607
|
+
effectiveColumnWidth
|
|
608
|
+
),
|
|
609
|
+
width: utils.durationToPixels(
|
|
610
|
+
utils.getTaskSpan(task.baseline.startDate, task.baseline.duration, calendar),
|
|
611
|
+
effectiveColumnWidth
|
|
612
|
+
)
|
|
613
|
+
}
|
|
614
|
+
}),
|
|
615
|
+
"data-task-id": task.id
|
|
581
616
|
}
|
|
582
617
|
)
|
|
583
618
|
);
|
|
@@ -589,7 +624,7 @@ const Gantt = core.factory((_props, ref) => {
|
|
|
589
624
|
startDate: bounds.start,
|
|
590
625
|
columnWidth: effectiveColumnWidth,
|
|
591
626
|
rowHeight,
|
|
592
|
-
getStyles,
|
|
627
|
+
getStyles: stableGetStyles,
|
|
593
628
|
activeDragId: active && active.type !== "link" ? active.taskId : null,
|
|
594
629
|
activeDragType: active && active.type !== "link" ? active.type : null,
|
|
595
630
|
dragDelta: active && active.type !== "link" ? active.deltaX : 0,
|