gantt-lib 0.8.0 → 0.9.1
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/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +35 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -244,6 +244,10 @@ interface GanttChartProps {
|
|
|
244
244
|
onInsertAfter?: (taskId: string, newTask: Task) => void;
|
|
245
245
|
/** Callback when tasks are reordered via drag in the task list */
|
|
246
246
|
onReorder?: (tasks: Task[], movedTaskId?: string, inferredParentId?: string) => void;
|
|
247
|
+
/** Callback when a task is promoted (parentId removed). If not provided, default internal logic is used. */
|
|
248
|
+
onPromoteTask?: (taskId: string) => void;
|
|
249
|
+
/** Callback when a task is demoted (parentId set). If not provided, default internal logic is used. */
|
|
250
|
+
onDemoteTask?: (taskId: string, newParentId: string) => void;
|
|
247
251
|
/** Enable add task button at bottom of task list (default: true) */
|
|
248
252
|
enableAddTask?: boolean;
|
|
249
253
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,10 @@ interface GanttChartProps {
|
|
|
244
244
|
onInsertAfter?: (taskId: string, newTask: Task) => void;
|
|
245
245
|
/** Callback when tasks are reordered via drag in the task list */
|
|
246
246
|
onReorder?: (tasks: Task[], movedTaskId?: string, inferredParentId?: string) => void;
|
|
247
|
+
/** Callback when a task is promoted (parentId removed). If not provided, default internal logic is used. */
|
|
248
|
+
onPromoteTask?: (taskId: string) => void;
|
|
249
|
+
/** Callback when a task is demoted (parentId set). If not provided, default internal logic is used. */
|
|
250
|
+
onDemoteTask?: (taskId: string, newParentId: string) => void;
|
|
247
251
|
/** Enable add task button at bottom of task list (default: true) */
|
|
248
252
|
enableAddTask?: boolean;
|
|
249
253
|
}
|
package/dist/index.js
CHANGED
|
@@ -3824,6 +3824,8 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
3824
3824
|
onDelete,
|
|
3825
3825
|
onInsertAfter,
|
|
3826
3826
|
onReorder,
|
|
3827
|
+
onPromoteTask,
|
|
3828
|
+
onDemoteTask,
|
|
3827
3829
|
enableAddTask = true
|
|
3828
3830
|
}, ref) => {
|
|
3829
3831
|
const scrollContainerRef = (0, import_react13.useRef)(null);
|
|
@@ -3979,31 +3981,29 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
3979
3981
|
});
|
|
3980
3982
|
const additionalParentUpdates = [];
|
|
3981
3983
|
parentIdsToUpdate.forEach((parentId) => {
|
|
3984
|
+
const parentTask = tasks.find((t) => t.id === parentId);
|
|
3985
|
+
if (!parentTask) return;
|
|
3982
3986
|
if (parentId === updatedTask.id) {
|
|
3983
|
-
const
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
+
const newProgress2 = computeParentProgress(parentId, tasks.map((t) => changedTasks.get(t.id) ?? t));
|
|
3988
|
+
const parentInCascaded = cascadedTasks.find((t) => t.id === parentId);
|
|
3989
|
+
if (parentInCascaded) {
|
|
3990
|
+
parentInCascaded.progress = newProgress2;
|
|
3987
3991
|
}
|
|
3988
3992
|
return;
|
|
3989
3993
|
}
|
|
3990
|
-
const
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
progress: newProgress
|
|
4000
|
-
});
|
|
4001
|
-
}
|
|
3994
|
+
const tempTasks = tasks.map((t) => changedTasks.get(t.id) ?? t);
|
|
3995
|
+
const newDates = computeParentDates(parentId, tempTasks);
|
|
3996
|
+
const newProgress = computeParentProgress(parentId, tempTasks);
|
|
3997
|
+
additionalParentUpdates.push({
|
|
3998
|
+
...parentTask,
|
|
3999
|
+
startDate: newDates.startDate.toISOString().split("T")[0],
|
|
4000
|
+
endDate: newDates.endDate.toISOString().split("T")[0],
|
|
4001
|
+
progress: newProgress
|
|
4002
|
+
});
|
|
4002
4003
|
});
|
|
4003
4004
|
onTasksChange?.([...cascadedTasks, ...additionalParentUpdates]);
|
|
4004
|
-
onCascade?.(cascadedTasks);
|
|
4005
4005
|
}
|
|
4006
|
-
}, [tasks, onTasksChange, disableConstraints,
|
|
4006
|
+
}, [tasks, onTasksChange, disableConstraints, editingTaskId]);
|
|
4007
4007
|
const handleDelete = (0, import_react13.useCallback)((taskId) => {
|
|
4008
4008
|
const toDelete = /* @__PURE__ */ new Set([taskId]);
|
|
4009
4009
|
function collectDescendants(parentId) {
|
|
@@ -4127,7 +4127,10 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
4127
4127
|
const tempTasks = tasks.map((t) => cascadeMap.get(t.id) ?? t);
|
|
4128
4128
|
if (parentId === draggedTaskId) {
|
|
4129
4129
|
const newProgress2 = computeParentProgress(parentId, tempTasks);
|
|
4130
|
-
|
|
4130
|
+
const parentInCascaded = cascadedTasks.find((t) => t.id === parentId);
|
|
4131
|
+
if (parentInCascaded) {
|
|
4132
|
+
parentInCascaded.progress = newProgress2;
|
|
4133
|
+
}
|
|
4131
4134
|
return;
|
|
4132
4135
|
}
|
|
4133
4136
|
const newDates = computeParentDates(parentId, tempTasks);
|
|
@@ -4140,8 +4143,7 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
4140
4143
|
});
|
|
4141
4144
|
});
|
|
4142
4145
|
onTasksChange?.([...cascadedTasks, ...additionalParentUpdates]);
|
|
4143
|
-
|
|
4144
|
-
}, [tasks, onTasksChange, onCascade]);
|
|
4146
|
+
}, [tasks, onTasksChange]);
|
|
4145
4147
|
const handleTaskSelect = (0, import_react13.useCallback)((taskId) => {
|
|
4146
4148
|
setSelectedTaskId(taskId);
|
|
4147
4149
|
}, []);
|
|
@@ -4157,6 +4159,10 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
4157
4159
|
});
|
|
4158
4160
|
}, []);
|
|
4159
4161
|
const handlePromoteTask = (0, import_react13.useCallback)((taskId) => {
|
|
4162
|
+
if (onPromoteTask) {
|
|
4163
|
+
onPromoteTask(taskId);
|
|
4164
|
+
return;
|
|
4165
|
+
}
|
|
4160
4166
|
const taskToPromote = tasks.find((t) => t.id === taskId);
|
|
4161
4167
|
if (!taskToPromote || !taskToPromote.parentId) {
|
|
4162
4168
|
return;
|
|
@@ -4181,8 +4187,12 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
4181
4187
|
...tasks.filter((t) => t.id !== taskId).slice(lastSiblingIndex.index + 1)
|
|
4182
4188
|
]);
|
|
4183
4189
|
onTasksChange?.(reorderedTasks);
|
|
4184
|
-
}, [tasks, onTasksChange]);
|
|
4190
|
+
}, [tasks, onTasksChange, onPromoteTask]);
|
|
4185
4191
|
const handleDemoteTask = (0, import_react13.useCallback)((taskId, newParentId) => {
|
|
4192
|
+
if (onDemoteTask) {
|
|
4193
|
+
onDemoteTask(taskId, newParentId);
|
|
4194
|
+
return;
|
|
4195
|
+
}
|
|
4186
4196
|
const wouldCreateCircular = (targetId, parentId, tasks2) => {
|
|
4187
4197
|
if (targetId === parentId) return true;
|
|
4188
4198
|
const descendants = /* @__PURE__ */ new Set();
|
|
@@ -4214,7 +4224,7 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
4214
4224
|
progress: parentProgress
|
|
4215
4225
|
};
|
|
4216
4226
|
onTasksChange?.([updatedDemotedTask, updatedParentTask]);
|
|
4217
|
-
}, [tasks, onTasksChange]);
|
|
4227
|
+
}, [tasks, onTasksChange, onDemoteTask]);
|
|
4218
4228
|
const panStateRef = (0, import_react13.useRef)(null);
|
|
4219
4229
|
const handlePanStart = (0, import_react13.useCallback)((e) => {
|
|
4220
4230
|
if (e.button !== 0) return;
|
|
@@ -4291,8 +4301,8 @@ var GanttChart = (0, import_react13.forwardRef)(({
|
|
|
4291
4301
|
enableAddTask,
|
|
4292
4302
|
collapsedParentIds,
|
|
4293
4303
|
onToggleCollapse: handleToggleCollapse,
|
|
4294
|
-
onPromoteTask: handlePromoteTask,
|
|
4295
|
-
onDemoteTask: handleDemoteTask
|
|
4304
|
+
onPromoteTask: onPromoteTask ?? handlePromoteTask,
|
|
4305
|
+
onDemoteTask: onDemoteTask ?? handleDemoteTask
|
|
4296
4306
|
}
|
|
4297
4307
|
),
|
|
4298
4308
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { style: { minWidth: `${gridWidth}px`, flex: 1 }, children: [
|