gantt-lib 0.22.2 → 0.23.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 CHANGED
@@ -519,6 +519,10 @@ interface GanttChartProps {
519
519
  * Dependencies are still computed on ALL tasks (normalizedTasks).
520
520
  */
521
521
  taskFilter?: TaskPredicate;
522
+ /** Set of collapsed parent task IDs for controlled mode */
523
+ collapsedParentIds?: Set<string>;
524
+ /** Callback when collapse/expand button is clicked (controlled mode) */
525
+ onToggleCollapse?: (parentId: string) => void;
522
526
  }
523
527
  /**
524
528
  * Ref handle type for GanttChart — exposes imperative scroll methods.
@@ -1056,6 +1060,15 @@ declare function removeDependenciesBetweenTasks(taskId1: string, taskId2: string
1056
1060
  * @returns Parent task ID or undefined if task is root or not found
1057
1061
  */
1058
1062
  declare function findParentId(taskId: string, tasks: Task$1[]): string | undefined;
1063
+ /**
1064
+ * Get all descendant tasks of a parent task (transitive closure of children).
1065
+ * Returns all tasks where task.parentId is in the hierarchy of the parent.
1066
+ *
1067
+ * @param parentId - ID of the parent task
1068
+ * @param tasks - All tasks array
1069
+ * @returns Array of descendant tasks (not including the parent itself)
1070
+ */
1071
+ declare function getAllDescendants(parentId: string, tasks: Task$1[]): Task$1[];
1059
1072
  /**
1060
1073
  * Universal cascade engine that propagates a moved task's new position through
1061
1074
  * the entire dependency+hierarchy graph using BFS with change detection.
@@ -1272,4 +1285,4 @@ interface VisibleReorderPosition {
1272
1285
  */
1273
1286
  declare function getVisibleReorderPosition(orderedTasks: TaskLike[], visibleTasks: TaskLike[], movedTaskId: string, originVisibleIndex: number, dropVisibleIndex: number): VisibleReorderPosition | null;
1274
1287
 
1275
- export { Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, and, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, nameContains, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, removeDependenciesBetweenTasks, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
1288
+ export { Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, and, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getAllDescendants, getChildren, getCursorForPosition, getDayOffset, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, nameContains, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, removeDependenciesBetweenTasks, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
package/dist/index.d.ts CHANGED
@@ -519,6 +519,10 @@ interface GanttChartProps {
519
519
  * Dependencies are still computed on ALL tasks (normalizedTasks).
520
520
  */
521
521
  taskFilter?: TaskPredicate;
522
+ /** Set of collapsed parent task IDs for controlled mode */
523
+ collapsedParentIds?: Set<string>;
524
+ /** Callback when collapse/expand button is clicked (controlled mode) */
525
+ onToggleCollapse?: (parentId: string) => void;
522
526
  }
523
527
  /**
524
528
  * Ref handle type for GanttChart — exposes imperative scroll methods.
@@ -1056,6 +1060,15 @@ declare function removeDependenciesBetweenTasks(taskId1: string, taskId2: string
1056
1060
  * @returns Parent task ID or undefined if task is root or not found
1057
1061
  */
1058
1062
  declare function findParentId(taskId: string, tasks: Task$1[]): string | undefined;
1063
+ /**
1064
+ * Get all descendant tasks of a parent task (transitive closure of children).
1065
+ * Returns all tasks where task.parentId is in the hierarchy of the parent.
1066
+ *
1067
+ * @param parentId - ID of the parent task
1068
+ * @param tasks - All tasks array
1069
+ * @returns Array of descendant tasks (not including the parent itself)
1070
+ */
1071
+ declare function getAllDescendants(parentId: string, tasks: Task$1[]): Task$1[];
1059
1072
  /**
1060
1073
  * Universal cascade engine that propagates a moved task's new position through
1061
1074
  * the entire dependency+hierarchy graph using BFS with change detection.
@@ -1272,4 +1285,4 @@ interface VisibleReorderPosition {
1272
1285
  */
1273
1286
  declare function getVisibleReorderPosition(orderedTasks: TaskLike[], visibleTasks: TaskLike[], movedTaskId: string, originVisibleIndex: number, dropVisibleIndex: number): VisibleReorderPosition | null;
1274
1287
 
1275
- export { Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, and, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getChildren, getCursorForPosition, getDayOffset, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, nameContains, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, removeDependenciesBetweenTasks, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
1288
+ export { Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, and, buildAdjacencyList, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, getAllDependencyEdges, getAllDescendants, getChildren, getCursorForPosition, getDayOffset, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, nameContains, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, removeDependenciesBetweenTasks, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
package/dist/index.js CHANGED
@@ -387,6 +387,7 @@ __export(index_exports, {
387
387
  flattenHierarchy: () => flattenHierarchy,
388
388
  formatDateLabel: () => formatDateLabel,
389
389
  getAllDependencyEdges: () => getAllDependencyEdges,
390
+ getAllDescendants: () => getAllDescendants,
390
391
  getChildren: () => getChildren,
391
392
  getCursorForPosition: () => getCursorForPosition,
392
393
  getDayOffset: () => getDayOffset,
@@ -780,6 +781,21 @@ function findParentId(taskId, tasks) {
780
781
  const task = tasks.find((t) => t.id === taskId);
781
782
  return task?.parentId;
782
783
  }
784
+ function getAllDescendants(parentId, tasks) {
785
+ const descendants = [];
786
+ const visited = /* @__PURE__ */ new Set();
787
+ function collectChildren(taskId) {
788
+ if (visited.has(taskId)) return;
789
+ visited.add(taskId);
790
+ const children = getChildren(taskId, tasks);
791
+ for (const child of children) {
792
+ descendants.push(child);
793
+ collectChildren(child.id);
794
+ }
795
+ }
796
+ collectChildren(parentId);
797
+ return descendants;
798
+ }
783
799
  var DAY_MS = 24 * 60 * 60 * 1e3;
784
800
  function universalCascade(movedTask, newStart, newEnd, allTasks) {
785
801
  const taskById = new Map(allTasks.map((t) => [t.id, t]));
@@ -4389,7 +4405,7 @@ var NewTaskRow = ({ rowHeight, onConfirm, onCancel }) => {
4389
4405
  var import_jsx_runtime14 = require("react/jsx-runtime");
4390
4406
  var LINK_TYPE_ORDER = ["FS", "SS", "FF", "SF"];
4391
4407
  var MIN_TASK_LIST_WIDTH = 640;
4392
- function getAllDescendants(parentId, tasks) {
4408
+ function getAllDescendants2(parentId, tasks) {
4393
4409
  const descendants = [];
4394
4410
  const visited = /* @__PURE__ */ new Set();
4395
4411
  function collectChildren(taskId) {
@@ -4646,7 +4662,7 @@ var TaskList = ({
4646
4662
  }
4647
4663
  const draggedTask = orderedTasks.find((t) => t.id === draggedTaskId);
4648
4664
  if (!draggedTask) return true;
4649
- const descendants = getAllDescendants(draggedTaskId, orderedTasks);
4665
+ const descendants = getAllDescendants2(draggedTaskId, orderedTasks);
4650
4666
  const descendantIds = new Set(descendants.map((d) => d.id));
4651
4667
  if (descendantIds.has(dropTarget.id)) {
4652
4668
  return false;
@@ -4716,7 +4732,7 @@ var TaskList = ({
4716
4732
  let subtree;
4717
4733
  let subtreeCount;
4718
4734
  if (hasChildren) {
4719
- const descendants = getAllDescendants(moved.id, orderedTasks);
4735
+ const descendants = getAllDescendants2(moved.id, orderedTasks);
4720
4736
  subtree = [moved, ...descendants];
4721
4737
  subtreeCount = subtree.length;
4722
4738
  } else {
@@ -4995,13 +5011,16 @@ var GanttChart = (0, import_react13.forwardRef)(({
4995
5011
  viewMode = "day",
4996
5012
  customDays,
4997
5013
  isWeekend: isWeekend3,
4998
- taskFilter
5014
+ taskFilter,
5015
+ collapsedParentIds: externalCollapsedParentIds,
5016
+ onToggleCollapse: externalOnToggleCollapse
4999
5017
  }, ref) => {
5000
5018
  const scrollContainerRef = (0, import_react13.useRef)(null);
5001
5019
  const [selectedTaskId, setSelectedTaskId] = (0, import_react13.useState)(null);
5002
5020
  const [taskListHasRightShadow, setTaskListHasRightShadow] = (0, import_react13.useState)(false);
5003
5021
  const [selectedChip, setSelectedChip] = (0, import_react13.useState)(null);
5004
- const [collapsedParentIds, setCollapsedParentIds] = (0, import_react13.useState)(/* @__PURE__ */ new Set());
5022
+ const [internalCollapsedParentIds, setInternalCollapsedParentIds] = (0, import_react13.useState)(/* @__PURE__ */ new Set());
5023
+ const collapsedParentIds = externalCollapsedParentIds ?? internalCollapsedParentIds;
5005
5024
  const [editingTaskId, setEditingTaskId] = (0, import_react13.useState)(null);
5006
5025
  const normalizedTasks = (0, import_react13.useMemo)(() => normalizeHierarchyTasks(tasks), [tasks]);
5007
5026
  const isCustomWeekend = (0, import_react13.useMemo)(
@@ -5226,8 +5245,8 @@ var GanttChart = (0, import_react13.forwardRef)(({
5226
5245
  const handleTaskSelect = (0, import_react13.useCallback)((taskId) => {
5227
5246
  setSelectedTaskId(taskId);
5228
5247
  }, []);
5229
- const handleToggleCollapse = (0, import_react13.useCallback)((parentId) => {
5230
- setCollapsedParentIds((prev) => {
5248
+ const handleToggleCollapse = externalOnToggleCollapse ?? (0, import_react13.useCallback)((parentId) => {
5249
+ setInternalCollapsedParentIds((prev) => {
5231
5250
  const next = new Set(prev);
5232
5251
  if (next.has(parentId)) {
5233
5252
  next.delete(parentId);
@@ -5238,14 +5257,18 @@ var GanttChart = (0, import_react13.forwardRef)(({
5238
5257
  });
5239
5258
  }, []);
5240
5259
  const allParentIds = (0, import_react13.useMemo)(() => {
5241
- return new Set(normalizedTasks.filter((t) => t.parentId).map((t) => t.parentId).filter((id) => id));
5260
+ return new Set(
5261
+ normalizedTasks.filter((t) => isTaskParent(t.id, normalizedTasks)).map((t) => t.id)
5262
+ );
5242
5263
  }, [normalizedTasks]);
5243
5264
  const handleCollapseAll = (0, import_react13.useCallback)(() => {
5244
- setCollapsedParentIds(allParentIds);
5245
- }, [allParentIds]);
5265
+ if (externalCollapsedParentIds) return;
5266
+ setInternalCollapsedParentIds(allParentIds);
5267
+ }, [allParentIds, externalCollapsedParentIds]);
5246
5268
  const handleExpandAll = (0, import_react13.useCallback)(() => {
5247
- setCollapsedParentIds(/* @__PURE__ */ new Set());
5248
- }, []);
5269
+ if (externalCollapsedParentIds) return;
5270
+ setInternalCollapsedParentIds(/* @__PURE__ */ new Set());
5271
+ }, [externalCollapsedParentIds]);
5249
5272
  (0, import_react13.useImperativeHandle)(
5250
5273
  ref,
5251
5274
  () => ({
@@ -5600,6 +5623,7 @@ var nameContains = (substring, caseSensitive = false) => (task) => {
5600
5623
  flattenHierarchy,
5601
5624
  formatDateLabel,
5602
5625
  getAllDependencyEdges,
5626
+ getAllDescendants,
5603
5627
  getChildren,
5604
5628
  getCursorForPosition,
5605
5629
  getDayOffset,