mantine-gantt 0.6.0 → 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 +121 -60
- 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 -19
- package/dist/cjs/Gantt/TaskBar.cjs.map +1 -1
- package/dist/cjs/Gantt/TaskList.cjs +30 -10
- 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 +76 -23
- 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 +123 -62
- 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 +14 -20
- package/dist/esm/Gantt/TaskBar.mjs.map +1 -1
- package/dist/esm/Gantt/TaskList.mjs +30 -10
- 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 +76 -23
- 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/styles.css +2 -2
- package/dist/styles.layer.css +2 -2
- package/dist/types/Gantt/DependencyLinks.d.ts +2 -4
- package/dist/types/Gantt/TaskList.d.ts +4 -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 +18 -3
- package/dist/types/Gantt/utils.d.ts +13 -5
- package/package.json +3 -4
package/dist/cjs/Gantt/utils.cjs
CHANGED
|
@@ -39,6 +39,19 @@ function barAnchors(task, timelineStart, columnWidth, rowHeight) {
|
|
|
39
39
|
}
|
|
40
40
|
return { left, right: left + durationToPixels(task.duration, columnWidth) };
|
|
41
41
|
}
|
|
42
|
+
function dragEdges(edges, type, deltaX, columnWidth) {
|
|
43
|
+
const { left, right } = edges;
|
|
44
|
+
if (type === "move") {
|
|
45
|
+
return { left: left + deltaX, right: right + deltaX };
|
|
46
|
+
}
|
|
47
|
+
if (type === "resize-end") {
|
|
48
|
+
return { left, right: Math.max(left + columnWidth, right + deltaX) };
|
|
49
|
+
}
|
|
50
|
+
if (type === "resize-start") {
|
|
51
|
+
return { left: Math.min(left + deltaX, right - columnWidth), right };
|
|
52
|
+
}
|
|
53
|
+
return edges;
|
|
54
|
+
}
|
|
42
55
|
function isWeekend(date) {
|
|
43
56
|
const day = date.getDay();
|
|
44
57
|
return day === 0 || day === 6;
|
|
@@ -62,7 +75,7 @@ function startOfWeek(date, weekStart = 1) {
|
|
|
62
75
|
function generateWeekHeaders(startDate, endDate, weekStart = 1, locale = "en") {
|
|
63
76
|
const weeks = [];
|
|
64
77
|
let current = startOfWeek(startDate, weekStart);
|
|
65
|
-
while (current.isBefore(endDate)) {
|
|
78
|
+
while (current.isBefore(endDate) || current.isSame(endDate, "day")) {
|
|
66
79
|
const weekEnd = current.add(6, "day").endOf("day");
|
|
67
80
|
const actualEnd = weekEnd.isAfter(endDate) ? endDate : weekEnd;
|
|
68
81
|
const actualStart = current.isBefore(startDate) ? startDate : current;
|
|
@@ -86,36 +99,34 @@ function calculateTimelineBounds(tasks, startDate, endDate, padding = 7, isNonWo
|
|
|
86
99
|
return { start: normalize(startDate), end: normalize(endDate) };
|
|
87
100
|
}
|
|
88
101
|
if (tasks.length === 0) {
|
|
89
|
-
const today = dayjs();
|
|
102
|
+
const today = dayjs().startOf("day");
|
|
90
103
|
return {
|
|
91
104
|
start: startDate ? normalize(startDate) : today.subtract(padding, "day"),
|
|
92
105
|
end: endDate ? normalize(endDate) : today.add(30 + padding, "day")
|
|
93
106
|
};
|
|
94
107
|
}
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
const parents = new Set(
|
|
109
|
+
buildTaskTree(tasks, /* @__PURE__ */ new Set()).filter((row) => row.hasChildren).map((row) => row.task.id)
|
|
110
|
+
);
|
|
111
|
+
const spans = [];
|
|
97
112
|
tasks.forEach((task) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (taskStart.isBefore(earliest)) {
|
|
101
|
-
earliest = taskStart;
|
|
102
|
-
}
|
|
103
|
-
if (taskEnd.isAfter(latest)) {
|
|
104
|
-
latest = taskEnd;
|
|
113
|
+
if (!parents.has(task.id)) {
|
|
114
|
+
spans.push([task.startDate, task.duration]);
|
|
105
115
|
}
|
|
106
116
|
if (task.baseline) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
spans.push([task.baseline.startDate, task.baseline.duration]);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
let earliest = dayjs(spans[0][0]);
|
|
121
|
+
let latest = getTaskEndDate(spans[0][0], spans[0][1], isNonWorkingDay);
|
|
122
|
+
spans.forEach(([start, duration]) => {
|
|
123
|
+
const spanStart = dayjs(start);
|
|
124
|
+
const spanEnd = getTaskEndDate(start, duration, isNonWorkingDay);
|
|
125
|
+
if (spanStart.isBefore(earliest)) {
|
|
126
|
+
earliest = spanStart;
|
|
127
|
+
}
|
|
128
|
+
if (spanEnd.isAfter(latest)) {
|
|
129
|
+
latest = spanEnd;
|
|
119
130
|
}
|
|
120
131
|
});
|
|
121
132
|
return {
|
|
@@ -389,16 +400,38 @@ function buildSuccessorMap(tasks) {
|
|
|
389
400
|
}
|
|
390
401
|
function applyAutoSchedule(tasks, movedTaskId, isNonWorkingDay) {
|
|
391
402
|
const byId = new Map(tasks.map((t) => [t.id, t]));
|
|
392
|
-
const successors = buildSuccessorMap(tasks);
|
|
393
403
|
const next = new Map(byId);
|
|
404
|
+
const parents = new Set(
|
|
405
|
+
buildTaskTree(tasks, /* @__PURE__ */ new Set()).filter((row) => row.hasChildren).map((row) => row.task.id)
|
|
406
|
+
);
|
|
407
|
+
const isAncestor = (ancestorId, id) => {
|
|
408
|
+
for (let p = byId.get(id)?.parentId; p && parents.has(p); p = byId.get(p)?.parentId) {
|
|
409
|
+
if (p === ancestorId) {
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return false;
|
|
414
|
+
};
|
|
415
|
+
const edges = buildSuccessorMap(tasks);
|
|
416
|
+
edges.forEach(
|
|
417
|
+
(succs, id) => edges.set(
|
|
418
|
+
id,
|
|
419
|
+
succs.filter((s) => !isAncestor(id, s))
|
|
420
|
+
)
|
|
421
|
+
);
|
|
422
|
+
tasks.forEach((t) => {
|
|
423
|
+
if (t.parentId && parents.has(t.parentId)) {
|
|
424
|
+
edges.set(t.id, [...edges.get(t.id) ?? [], t.parentId]);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
394
427
|
const indegree = /* @__PURE__ */ new Map();
|
|
395
|
-
|
|
428
|
+
edges.forEach((succs) => succs.forEach((s) => indegree.set(s, (indegree.get(s) ?? 0) + 1)));
|
|
396
429
|
const queue = tasks.filter((t) => !indegree.has(t.id)).map((t) => t.id);
|
|
397
430
|
const order = [];
|
|
398
431
|
while (queue.length > 0) {
|
|
399
432
|
const id = queue.shift();
|
|
400
433
|
order.push(id);
|
|
401
|
-
for (const succ of
|
|
434
|
+
for (const succ of edges.get(id) ?? []) {
|
|
402
435
|
const d = (indegree.get(succ) ?? 0) - 1;
|
|
403
436
|
indegree.set(succ, d);
|
|
404
437
|
if (d === 0) {
|
|
@@ -406,16 +439,25 @@ function applyAutoSchedule(tasks, movedTaskId, isNonWorkingDay) {
|
|
|
406
439
|
}
|
|
407
440
|
}
|
|
408
441
|
}
|
|
442
|
+
const schedule = (id) => {
|
|
443
|
+
if (!parents.has(id)) {
|
|
444
|
+
return next.get(id);
|
|
445
|
+
}
|
|
446
|
+
const row = buildTaskTree([...next.values()], /* @__PURE__ */ new Set(), isNonWorkingDay).find(
|
|
447
|
+
(r) => r.task.id === id
|
|
448
|
+
);
|
|
449
|
+
return row && getEffectiveTask(row);
|
|
450
|
+
};
|
|
409
451
|
let changed = false;
|
|
410
452
|
for (const id of order) {
|
|
411
453
|
const task = next.get(id);
|
|
412
|
-
if (!task) {
|
|
454
|
+
if (!task || parents.has(id)) {
|
|
413
455
|
continue;
|
|
414
456
|
}
|
|
415
457
|
let earliestStart = null;
|
|
416
458
|
for (const raw of task.dependencies ?? []) {
|
|
417
459
|
const { taskId, type, lag } = normalizeDependency(raw);
|
|
418
|
-
const dep =
|
|
460
|
+
const dep = isAncestor(taskId, id) ? void 0 : schedule(taskId);
|
|
419
461
|
if (!dep) {
|
|
420
462
|
continue;
|
|
421
463
|
}
|
|
@@ -457,6 +499,7 @@ exports.buildSuccessorMap = buildSuccessorMap;
|
|
|
457
499
|
exports.buildTaskTree = buildTaskTree;
|
|
458
500
|
exports.calculateTimelineBounds = calculateTimelineBounds;
|
|
459
501
|
exports.dateToPixel = dateToPixel;
|
|
502
|
+
exports.dragEdges = dragEdges;
|
|
460
503
|
exports.durationToPixels = durationToPixels;
|
|
461
504
|
exports.formatDate = formatDate;
|
|
462
505
|
exports.formatTaskDate = formatTaskDate;
|