@thepocman/gantt-task-react 1.0.9 → 1.0.11

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.
@@ -2,13 +2,14 @@ import type { MouseEvent } from "react";
2
2
  import React from "react";
3
3
  import type { OptimizedListParams } from "../../helpers/use-optimized-list";
4
4
  import { GanttRelationEvent } from "../../types/gantt-task-actions";
5
- import { BarMoveAction, ChildByLevelMap, ChildOutOfParentWarnings, ColorStyles, CriticalPaths, DateExtremity, DependencyMap, DependentMap, Distances, FixPosition, GlobalRowIndexToTaskMap, RelationKind, Task, TaskContextualPaletteProps, TaskCoordinates, TaskDependencyContextualPaletteProps, TaskOrEmpty, TaskToHasDependencyWarningMap } from "../../types/public-types";
5
+ import { BarMoveAction, ChildByLevelMap, ChildOutOfParentWarnings, ColorStyles, CriticalPaths, DateExtremity, DependencyMap, DependentMap, Distances, FixPosition, GlobalRowIndexToTaskMap, RelationKind, Task, TaskContextualPaletteProps, TaskCoordinates, TaskDependencyContextualPaletteProps, TaskOrEmpty, TaskToHasDependencyWarningMap, TaskToRowIndexMap } from "../../types/public-types";
6
6
  export type TaskGanttContentProps = {
7
7
  authorizedRelations: RelationKind[];
8
8
  additionalLeftSpace: number;
9
9
  additionalRightSpace: number;
10
10
  childOutOfParentWarnings: ChildOutOfParentWarnings | null;
11
11
  childTasksMap: ChildByLevelMap;
12
+ taskToRowIndexMap: TaskToRowIndexMap;
12
13
  colorStyles: ColorStyles;
13
14
  comparisonLevels: number;
14
15
  criticalPaths: CriticalPaths | null;
@@ -6424,9 +6424,11 @@ const TaskGanttContent = ({
6424
6424
  taskYOffset,
6425
6425
  taskHeight,
6426
6426
  taskHalfHeight,
6427
- visibleTasksMirror
6427
+ visibleTasksMirror,
6428
+ taskToRowIndexMap
6428
6429
  }) => {
6429
6430
  const [renderedTasks, renderedArrows, renderedSelectedTasks] = useMemo(() => {
6431
+ var _a;
6430
6432
  if (!renderedRowIndexes) {
6431
6433
  return [null, null, null];
6432
6434
  }
@@ -6445,19 +6447,23 @@ const TaskGanttContent = ({
6445
6447
  const { comparisonLevel = 1, id: taskId } = task;
6446
6448
  if (selectedIdsMirror[taskId] && !addedSelectedTasks[taskId]) {
6447
6449
  addedSelectedTasks[taskId] = true;
6448
- selectedTasksRes.push(
6449
- /* @__PURE__ */ jsx(
6450
- "rect",
6451
- {
6452
- x: 0,
6453
- y: Math.floor(index2 / comparisonLevels) * fullRowHeight,
6454
- width: "100%",
6455
- height: fullRowHeight,
6456
- fill: colorStyles.selectedTaskBackgroundColor
6457
- },
6458
- taskId
6459
- )
6460
- );
6450
+ const rowIndex = (_a = taskToRowIndexMap.get(comparisonLevel)) == null ? void 0 : _a.get(taskId);
6451
+ if (typeof rowIndex === "number") {
6452
+ const y3 = rowIndex * fullRowHeight;
6453
+ selectedTasksRes.push(
6454
+ /* @__PURE__ */ jsx(
6455
+ "rect",
6456
+ {
6457
+ x: 0,
6458
+ y: y3,
6459
+ width: "100%",
6460
+ height: fullRowHeight,
6461
+ fill: colorStyles.selectedTaskBackgroundColor
6462
+ },
6463
+ `selected-${taskId}`
6464
+ )
6465
+ );
6466
+ }
6461
6467
  }
6462
6468
  if (comparisonLevel > comparisonLevels) {
6463
6469
  continue;
@@ -11602,7 +11608,6 @@ const Gantt = ({
11602
11608
  () => collectVisibleTasks(childTasksMap, rootTasksMap, enableTaskGrouping),
11603
11609
  [childTasksMap, rootTasksMap]
11604
11610
  );
11605
- console.log("Visible Task IDs:", visibleTasks.map((t2) => t2.id));
11606
11611
  const tasksMap = useMemo(() => getTasksMap(tasks), [tasks]);
11607
11612
  const checkTaskIdExists = useCallback(
11608
11613
  (newId, comparisonLevel = 1) => {
@@ -11678,11 +11683,27 @@ const Gantt = ({
11678
11683
  () => (distances.rowHeight - taskHeight) / 2,
11679
11684
  [distances, taskHeight]
11680
11685
  );
11686
+ const [taskToRowIndexMap, rowIndexToTaskMap, mapGlobalRowIndexToTask, rowIndexToTasksMap] = useMemo(
11687
+ () => enableTaskGrouping ? getMapTaskToRowIndexWithGrouping(visibleTasks, comparisonLevels, true) : getMapTaskToRowIndex(visibleTasks, comparisonLevels),
11688
+ [visibleTasks, comparisonLevels, enableTaskGrouping]
11689
+ );
11681
11690
  const taskHalfHeight = useMemo(
11682
11691
  () => Math.round(taskHeight / 2),
11683
11692
  [taskHeight]
11684
11693
  );
11685
11694
  const maxLevelLength = useMemo(() => {
11695
+ if (enableTaskGrouping) {
11696
+ let totalHeightInRows = 0;
11697
+ for (const [_, rowMap] of rowIndexToTasksMap) {
11698
+ for (const [_2, tasksInRow] of rowMap) {
11699
+ const maxStack = tasksInRow.length;
11700
+ const stackedHeight = maxStack * (taskHeight + 2);
11701
+ const rowsNeeded = Math.ceil(stackedHeight / fullRowHeight);
11702
+ totalHeightInRows += rowsNeeded;
11703
+ }
11704
+ }
11705
+ return Math.max(totalHeightInRows, 1);
11706
+ }
11686
11707
  let maxLength = 0;
11687
11708
  const countByLevel = {};
11688
11709
  visibleTasks.forEach(({ comparisonLevel = 1 }) => {
@@ -11695,15 +11716,19 @@ const Gantt = ({
11695
11716
  }
11696
11717
  });
11697
11718
  return maxLength;
11698
- }, [visibleTasks, comparisonLevels]);
11699
- const ganttFullHeight = useMemo(
11700
- () => maxLevelLength * fullRowHeight,
11701
- [maxLevelLength, fullRowHeight]
11702
- );
11703
- const [taskToRowIndexMap, rowIndexToTaskMap, mapGlobalRowIndexToTask, rowIndexToTasksMap] = useMemo(
11704
- () => enableTaskGrouping ? getMapTaskToRowIndexWithGrouping(visibleTasks, comparisonLevels, true) : getMapTaskToRowIndex(visibleTasks, comparisonLevels),
11705
- [visibleTasks, comparisonLevels, enableTaskGrouping]
11706
- );
11719
+ }, [visibleTasks, comparisonLevels, enableTaskGrouping, rowIndexToTasksMap, fullRowHeight, taskHeight]);
11720
+ const ganttFullHeight = useMemo(() => {
11721
+ if (enableTaskGrouping) {
11722
+ let totalRows = 0;
11723
+ for (const [, taskMap] of rowIndexToTasksMap) {
11724
+ for (const [, tasks2] of taskMap) {
11725
+ totalRows += tasks2.length;
11726
+ }
11727
+ }
11728
+ return Math.max(totalRows, 1) * fullRowHeight;
11729
+ }
11730
+ return maxLevelLength * fullRowHeight;
11731
+ }, [enableTaskGrouping, rowIndexToTasksMap, maxLevelLength, fullRowHeight]);
11707
11732
  const {
11708
11733
  checkHasCopyTasks,
11709
11734
  checkHasCutTasks,
@@ -11976,8 +12001,6 @@ const Gantt = ({
11976
12001
  };
11977
12002
  const handleExpanderClick = useCallback(
11978
12003
  (clickedTask) => {
11979
- console.log(`Task ${clickedTask.id} hideChildren changed from ${clickedTask.hideChildren} to ${!clickedTask.hideChildren}`);
11980
- console.log("Task types:", tasks.map((task) => `${task.id}: ${task.type}`));
11981
12004
  if (onChangeExpandState) {
11982
12005
  onChangeExpandState({
11983
12006
  ...clickedTask,
@@ -6437,9 +6437,11 @@
6437
6437
  taskYOffset,
6438
6438
  taskHeight,
6439
6439
  taskHalfHeight,
6440
- visibleTasksMirror
6440
+ visibleTasksMirror,
6441
+ taskToRowIndexMap
6441
6442
  }) => {
6442
6443
  const [renderedTasks, renderedArrows, renderedSelectedTasks] = React.useMemo(() => {
6444
+ var _a;
6443
6445
  if (!renderedRowIndexes) {
6444
6446
  return [null, null, null];
6445
6447
  }
@@ -6458,19 +6460,23 @@
6458
6460
  const { comparisonLevel = 1, id: taskId } = task;
6459
6461
  if (selectedIdsMirror[taskId] && !addedSelectedTasks[taskId]) {
6460
6462
  addedSelectedTasks[taskId] = true;
6461
- selectedTasksRes.push(
6462
- /* @__PURE__ */ jsxRuntime.jsx(
6463
- "rect",
6464
- {
6465
- x: 0,
6466
- y: Math.floor(index2 / comparisonLevels) * fullRowHeight,
6467
- width: "100%",
6468
- height: fullRowHeight,
6469
- fill: colorStyles.selectedTaskBackgroundColor
6470
- },
6471
- taskId
6472
- )
6473
- );
6463
+ const rowIndex = (_a = taskToRowIndexMap.get(comparisonLevel)) == null ? void 0 : _a.get(taskId);
6464
+ if (typeof rowIndex === "number") {
6465
+ const y = rowIndex * fullRowHeight;
6466
+ selectedTasksRes.push(
6467
+ /* @__PURE__ */ jsxRuntime.jsx(
6468
+ "rect",
6469
+ {
6470
+ x: 0,
6471
+ y,
6472
+ width: "100%",
6473
+ height: fullRowHeight,
6474
+ fill: colorStyles.selectedTaskBackgroundColor
6475
+ },
6476
+ `selected-${taskId}`
6477
+ )
6478
+ );
6479
+ }
6474
6480
  }
6475
6481
  if (comparisonLevel > comparisonLevels) {
6476
6482
  continue;
@@ -11615,7 +11621,6 @@
11615
11621
  () => collectVisibleTasks(childTasksMap, rootTasksMap, enableTaskGrouping),
11616
11622
  [childTasksMap, rootTasksMap]
11617
11623
  );
11618
- console.log("Visible Task IDs:", visibleTasks.map((t) => t.id));
11619
11624
  const tasksMap = React.useMemo(() => getTasksMap(tasks), [tasks]);
11620
11625
  const checkTaskIdExists = React.useCallback(
11621
11626
  (newId, comparisonLevel = 1) => {
@@ -11691,11 +11696,27 @@
11691
11696
  () => (distances.rowHeight - taskHeight) / 2,
11692
11697
  [distances, taskHeight]
11693
11698
  );
11699
+ const [taskToRowIndexMap, rowIndexToTaskMap, mapGlobalRowIndexToTask, rowIndexToTasksMap] = React.useMemo(
11700
+ () => enableTaskGrouping ? getMapTaskToRowIndexWithGrouping(visibleTasks, comparisonLevels, true) : getMapTaskToRowIndex(visibleTasks, comparisonLevels),
11701
+ [visibleTasks, comparisonLevels, enableTaskGrouping]
11702
+ );
11694
11703
  const taskHalfHeight = React.useMemo(
11695
11704
  () => Math.round(taskHeight / 2),
11696
11705
  [taskHeight]
11697
11706
  );
11698
11707
  const maxLevelLength = React.useMemo(() => {
11708
+ if (enableTaskGrouping) {
11709
+ let totalHeightInRows = 0;
11710
+ for (const [_, rowMap] of rowIndexToTasksMap) {
11711
+ for (const [_2, tasksInRow] of rowMap) {
11712
+ const maxStack = tasksInRow.length;
11713
+ const stackedHeight = maxStack * (taskHeight + 2);
11714
+ const rowsNeeded = Math.ceil(stackedHeight / fullRowHeight);
11715
+ totalHeightInRows += rowsNeeded;
11716
+ }
11717
+ }
11718
+ return Math.max(totalHeightInRows, 1);
11719
+ }
11699
11720
  let maxLength = 0;
11700
11721
  const countByLevel = {};
11701
11722
  visibleTasks.forEach(({ comparisonLevel = 1 }) => {
@@ -11708,15 +11729,19 @@
11708
11729
  }
11709
11730
  });
11710
11731
  return maxLength;
11711
- }, [visibleTasks, comparisonLevels]);
11712
- const ganttFullHeight = React.useMemo(
11713
- () => maxLevelLength * fullRowHeight,
11714
- [maxLevelLength, fullRowHeight]
11715
- );
11716
- const [taskToRowIndexMap, rowIndexToTaskMap, mapGlobalRowIndexToTask, rowIndexToTasksMap] = React.useMemo(
11717
- () => enableTaskGrouping ? getMapTaskToRowIndexWithGrouping(visibleTasks, comparisonLevels, true) : getMapTaskToRowIndex(visibleTasks, comparisonLevels),
11718
- [visibleTasks, comparisonLevels, enableTaskGrouping]
11719
- );
11732
+ }, [visibleTasks, comparisonLevels, enableTaskGrouping, rowIndexToTasksMap, fullRowHeight, taskHeight]);
11733
+ const ganttFullHeight = React.useMemo(() => {
11734
+ if (enableTaskGrouping) {
11735
+ let totalRows = 0;
11736
+ for (const [, taskMap] of rowIndexToTasksMap) {
11737
+ for (const [, tasks2] of taskMap) {
11738
+ totalRows += tasks2.length;
11739
+ }
11740
+ }
11741
+ return Math.max(totalRows, 1) * fullRowHeight;
11742
+ }
11743
+ return maxLevelLength * fullRowHeight;
11744
+ }, [enableTaskGrouping, rowIndexToTasksMap, maxLevelLength, fullRowHeight]);
11720
11745
  const {
11721
11746
  checkHasCopyTasks,
11722
11747
  checkHasCutTasks,
@@ -11989,8 +12014,6 @@
11989
12014
  };
11990
12015
  const handleExpanderClick = React.useCallback(
11991
12016
  (clickedTask) => {
11992
- console.log(`Task ${clickedTask.id} hideChildren changed from ${clickedTask.hideChildren} to ${!clickedTask.hideChildren}`);
11993
- console.log("Task types:", tasks.map((task) => `${task.id}: ${task.type}`));
11994
12017
  if (onChangeExpandState) {
11995
12018
  onChangeExpandState({
11996
12019
  ...clickedTask,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thepocman/gantt-task-react",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Fork of gantt-task-react with support for grouped tasks on a single row when collapsed",
5
5
  "author": "Adrian Bueno <adrianlbueno@users.noreply.github.com>",
6
6
  "homepage": "https://github.com/adrianlbueno/gantt-task-react#readme",