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.mjs CHANGED
@@ -692,6 +692,21 @@ function findParentId(taskId, tasks) {
692
692
  const task = tasks.find((t) => t.id === taskId);
693
693
  return task?.parentId;
694
694
  }
695
+ function getAllDescendants(parentId, tasks) {
696
+ const descendants = [];
697
+ const visited = /* @__PURE__ */ new Set();
698
+ function collectChildren(taskId) {
699
+ if (visited.has(taskId)) return;
700
+ visited.add(taskId);
701
+ const children = getChildren(taskId, tasks);
702
+ for (const child of children) {
703
+ descendants.push(child);
704
+ collectChildren(child.id);
705
+ }
706
+ }
707
+ collectChildren(parentId);
708
+ return descendants;
709
+ }
695
710
  var DAY_MS = 24 * 60 * 60 * 1e3;
696
711
  function universalCascade(movedTask, newStart, newEnd, allTasks) {
697
712
  const taskById = new Map(allTasks.map((t) => [t.id, t]));
@@ -4325,7 +4340,7 @@ var NewTaskRow = ({ rowHeight, onConfirm, onCancel }) => {
4325
4340
  import { jsx as jsx14, jsxs as jsxs11 } from "react/jsx-runtime";
4326
4341
  var LINK_TYPE_ORDER = ["FS", "SS", "FF", "SF"];
4327
4342
  var MIN_TASK_LIST_WIDTH = 640;
4328
- function getAllDescendants(parentId, tasks) {
4343
+ function getAllDescendants2(parentId, tasks) {
4329
4344
  const descendants = [];
4330
4345
  const visited = /* @__PURE__ */ new Set();
4331
4346
  function collectChildren(taskId) {
@@ -4582,7 +4597,7 @@ var TaskList = ({
4582
4597
  }
4583
4598
  const draggedTask = orderedTasks.find((t) => t.id === draggedTaskId);
4584
4599
  if (!draggedTask) return true;
4585
- const descendants = getAllDescendants(draggedTaskId, orderedTasks);
4600
+ const descendants = getAllDescendants2(draggedTaskId, orderedTasks);
4586
4601
  const descendantIds = new Set(descendants.map((d) => d.id));
4587
4602
  if (descendantIds.has(dropTarget.id)) {
4588
4603
  return false;
@@ -4652,7 +4667,7 @@ var TaskList = ({
4652
4667
  let subtree;
4653
4668
  let subtreeCount;
4654
4669
  if (hasChildren) {
4655
- const descendants = getAllDescendants(moved.id, orderedTasks);
4670
+ const descendants = getAllDescendants2(moved.id, orderedTasks);
4656
4671
  subtree = [moved, ...descendants];
4657
4672
  subtreeCount = subtree.length;
4658
4673
  } else {
@@ -4931,13 +4946,16 @@ var GanttChart = forwardRef(({
4931
4946
  viewMode = "day",
4932
4947
  customDays,
4933
4948
  isWeekend: isWeekend3,
4934
- taskFilter
4949
+ taskFilter,
4950
+ collapsedParentIds: externalCollapsedParentIds,
4951
+ onToggleCollapse: externalOnToggleCollapse
4935
4952
  }, ref) => {
4936
4953
  const scrollContainerRef = useRef7(null);
4937
4954
  const [selectedTaskId, setSelectedTaskId] = useState7(null);
4938
4955
  const [taskListHasRightShadow, setTaskListHasRightShadow] = useState7(false);
4939
4956
  const [selectedChip, setSelectedChip] = useState7(null);
4940
- const [collapsedParentIds, setCollapsedParentIds] = useState7(/* @__PURE__ */ new Set());
4957
+ const [internalCollapsedParentIds, setInternalCollapsedParentIds] = useState7(/* @__PURE__ */ new Set());
4958
+ const collapsedParentIds = externalCollapsedParentIds ?? internalCollapsedParentIds;
4941
4959
  const [editingTaskId, setEditingTaskId] = useState7(null);
4942
4960
  const normalizedTasks = useMemo9(() => normalizeHierarchyTasks(tasks), [tasks]);
4943
4961
  const isCustomWeekend = useMemo9(
@@ -5162,8 +5180,8 @@ var GanttChart = forwardRef(({
5162
5180
  const handleTaskSelect = useCallback6((taskId) => {
5163
5181
  setSelectedTaskId(taskId);
5164
5182
  }, []);
5165
- const handleToggleCollapse = useCallback6((parentId) => {
5166
- setCollapsedParentIds((prev) => {
5183
+ const handleToggleCollapse = externalOnToggleCollapse ?? useCallback6((parentId) => {
5184
+ setInternalCollapsedParentIds((prev) => {
5167
5185
  const next = new Set(prev);
5168
5186
  if (next.has(parentId)) {
5169
5187
  next.delete(parentId);
@@ -5174,14 +5192,18 @@ var GanttChart = forwardRef(({
5174
5192
  });
5175
5193
  }, []);
5176
5194
  const allParentIds = useMemo9(() => {
5177
- return new Set(normalizedTasks.filter((t) => t.parentId).map((t) => t.parentId).filter((id) => id));
5195
+ return new Set(
5196
+ normalizedTasks.filter((t) => isTaskParent(t.id, normalizedTasks)).map((t) => t.id)
5197
+ );
5178
5198
  }, [normalizedTasks]);
5179
5199
  const handleCollapseAll = useCallback6(() => {
5180
- setCollapsedParentIds(allParentIds);
5181
- }, [allParentIds]);
5200
+ if (externalCollapsedParentIds) return;
5201
+ setInternalCollapsedParentIds(allParentIds);
5202
+ }, [allParentIds, externalCollapsedParentIds]);
5182
5203
  const handleExpandAll = useCallback6(() => {
5183
- setCollapsedParentIds(/* @__PURE__ */ new Set());
5184
- }, []);
5204
+ if (externalCollapsedParentIds) return;
5205
+ setInternalCollapsedParentIds(/* @__PURE__ */ new Set());
5206
+ }, [externalCollapsedParentIds]);
5185
5207
  useImperativeHandle(
5186
5208
  ref,
5187
5209
  () => ({
@@ -5535,6 +5557,7 @@ export {
5535
5557
  flattenHierarchy,
5536
5558
  formatDateLabel,
5537
5559
  getAllDependencyEdges,
5560
+ getAllDescendants,
5538
5561
  getChildren,
5539
5562
  getCursorForPosition,
5540
5563
  getDayOffset,