@thepocman/gantt-task-react 1.0.31 → 1.0.34

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.
@@ -1,11 +1,13 @@
1
1
  import type { MouseEvent } from "react";
2
2
  import React from "react";
3
3
  import { GanttRelationEvent } from "../../types/gantt-task-actions";
4
- import { BarMoveAction, ChildOutOfParentWarnings, ColorStyles, DateExtremity, Distances, FixPosition, RelationKind, Task, TaskOrEmpty } from "../../types/public-types";
4
+ import { BarMoveAction, ChildOutOfParentWarnings, ColorStyles, DateExtremity, Distances, FixPosition, RelationKind, RowIndexToTasksMap, Task, TaskOrEmpty, TaskToRowIndexMap } from "../../types/public-types";
5
5
  export type TaskItemProps = {
6
6
  children?: React.ReactNode;
7
7
  getTaskGlobalIndexByRef: (task: Task) => number;
8
8
  hasChildren: boolean;
9
+ rowIndexToTasksMap: RowIndexToTasksMap;
10
+ taskToRowIndexMap: TaskToRowIndexMap;
9
11
  hasDependencyWarning: boolean;
10
12
  progressWidth: number;
11
13
  progressX: number;
@@ -4228,6 +4228,7 @@ const TaskListTableDefaultInner = ({
4228
4228
  if (taskIndex) {
4229
4229
  [depth, indexStr] = taskIndex;
4230
4230
  }
4231
+ console.log("colors :>> ", colors);
4231
4232
  renderList.push(
4232
4233
  /* @__PURE__ */ jsx(
4233
4234
  TaskListTableRow,
@@ -4814,7 +4815,6 @@ const Calendar = ({
4814
4815
  );
4815
4816
  const dayOfMonth = date.getDate();
4816
4817
  const prevDate = getDate(i2 - 1);
4817
- console.log("testing center :>> ", additionalLeftSpace + columnWidth * i2 + ticks * columnWidth * 0.5);
4818
4818
  if (!isUnknownDates && dayOfMonth !== prevDate.getDate()) {
4819
4819
  const topValue = renderTopHeaderByDate(date);
4820
4820
  topValues2.push(
@@ -5013,7 +5013,6 @@ const GridBodyInner = ({
5013
5013
  startColumnIndex
5014
5014
  )) {
5015
5015
  const x3 = additionalLeftSpace + columnWidth * i2;
5016
- console.log("drawing divider at x:", x3, "for index:", i2, "date:", currentDate);
5017
5016
  dividers.push(
5018
5017
  /* @__PURE__ */ jsx(
5019
5018
  "line",
@@ -5578,10 +5577,35 @@ const RelationLine = ({
5578
5577
  }
5579
5578
  );
5580
5579
  };
5581
- const hoverVisibleWrapper = "_hoverVisibleWrapper_11ld1_1";
5582
- const wrapper = "_wrapper_11ld1_1";
5583
- const mainPath = "_mainPath_11ld1_17";
5584
- const clickZone = "_clickZone_11ld1_35";
5580
+ const truncateText = (text, maxWidth, textElement) => {
5581
+ if (!textElement)
5582
+ return text;
5583
+ textElement.textContent = text;
5584
+ const fullWidth = textElement.getBBox().width;
5585
+ if (fullWidth <= maxWidth) {
5586
+ return text;
5587
+ }
5588
+ let start = 0;
5589
+ let end = text.length;
5590
+ let result = text;
5591
+ while (start <= end) {
5592
+ const mid = Math.floor((start + end) / 2);
5593
+ const truncated = text.substring(0, mid);
5594
+ textElement.textContent = truncated;
5595
+ const truncatedWidth = textElement.getBBox().width;
5596
+ if (truncatedWidth <= maxWidth) {
5597
+ result = truncated;
5598
+ start = mid + 1;
5599
+ } else {
5600
+ end = mid - 1;
5601
+ }
5602
+ }
5603
+ return result;
5604
+ };
5605
+ const hoverVisibleWrapper = "_hoverVisibleWrapper_8hbnp_1";
5606
+ const wrapper = "_wrapper_8hbnp_1";
5607
+ const mainPath = "_mainPath_8hbnp_17";
5608
+ const clickZone = "_clickZone_8hbnp_35";
5585
5609
  const styles$4 = {
5586
5610
  hoverVisibleWrapper,
5587
5611
  wrapper,
@@ -6273,8 +6297,8 @@ const Milestone = ({
6273
6297
  }
6274
6298
  );
6275
6299
  };
6276
- const barLabel = "_barLabel_y0tyg_1";
6277
- const barLabelOutside = "_barLabelOutside_y0tyg_25";
6300
+ const barLabel = "_barLabel_7emdt_1";
6301
+ const barLabelOutside = "_barLabelOutside_7emdt_25";
6278
6302
  const style = {
6279
6303
  barLabel,
6280
6304
  barLabelOutside
@@ -6351,6 +6375,7 @@ const TaskWarningInner = ({
6351
6375
  };
6352
6376
  const TaskWarning = memo(TaskWarningInner);
6353
6377
  const TaskItemInner = (props) => {
6378
+ var _a, _b, _c;
6354
6379
  const {
6355
6380
  childOutOfParentWarnings,
6356
6381
  colorStyles: stylesProp,
@@ -6380,6 +6405,8 @@ const TaskItemInner = (props) => {
6380
6405
  selectTaskOnMouseDown,
6381
6406
  setTooltipTask,
6382
6407
  enableTaskGrouping,
6408
+ taskToRowIndexMap,
6409
+ rowIndexToTasksMap,
6383
6410
  task,
6384
6411
  task: { styles: taskStyles },
6385
6412
  taskHalfHeight,
@@ -6432,6 +6459,11 @@ const TaskItemInner = (props) => {
6432
6459
  const globalIndex = getTaskGlobalIndexByRef(task);
6433
6460
  fixEndPosition(task, end.date, globalIndex);
6434
6461
  }, [task, fixEndPosition, outOfParentWarnings, getTaskGlobalIndexByRef]);
6462
+ const taskRowIndex = (_a = taskToRowIndexMap == null ? void 0 : taskToRowIndexMap.get(task.comparisonLevel ?? 1)) == null ? void 0 : _a.get(task.id);
6463
+ if (taskRowIndex === void 0)
6464
+ return null;
6465
+ const isSharedRow = (((_c = (_b = rowIndexToTasksMap == null ? void 0 : rowIndexToTasksMap.get(task.comparisonLevel ?? 1)) == null ? void 0 : _b.get(taskRowIndex)) == null ? void 0 : _c.length) ?? 0) > 1;
6466
+ const isInCollapsedGroup = !!enableTaskGrouping && isSharedRow;
6435
6467
  const handleClick = useCallback(
6436
6468
  (event) => {
6437
6469
  if (onClick) {
@@ -6465,6 +6497,8 @@ const TaskItemInner = (props) => {
6465
6497
  }, [onRelationStart, rtl, task]);
6466
6498
  const textRef = useRef(null);
6467
6499
  const [isTextInside, setIsTextInside] = useState(true);
6500
+ const [truncatedText, setTruncatedText] = useState(task.name);
6501
+ console.log("truncatedText", truncatedText);
6468
6502
  const taskItem = useMemo(() => {
6469
6503
  const isFromStartRelationAuthorized = authorizedRelations.includes("startToStart") || authorizedRelations.includes("startToEnd");
6470
6504
  const isFromEndRelationAuthorized = authorizedRelations.includes("endToEnd") || authorizedRelations.includes("endToStart");
@@ -6547,10 +6581,15 @@ const TaskItemInner = (props) => {
6547
6581
  width
6548
6582
  ]);
6549
6583
  useEffect(() => {
6550
- if (textRef.current) {
6584
+ if (!textRef.current)
6585
+ return;
6586
+ if (isInCollapsedGroup) {
6587
+ const truncated = truncateText(task.name, width - 10, textRef.current);
6588
+ setTruncatedText(truncated);
6589
+ } else {
6551
6590
  setIsTextInside(textRef.current.getBBox().width < width);
6552
6591
  }
6553
- }, [textRef, width]);
6592
+ }, [isInCollapsedGroup, task.name, width]);
6554
6593
  const x3 = useMemo(() => {
6555
6594
  if (isTextInside) {
6556
6595
  return x1 + width * 0.5;
@@ -6560,6 +6599,9 @@ const TaskItemInner = (props) => {
6560
6599
  }
6561
6600
  return x1 + width + arrowIndent * 1.2;
6562
6601
  }, [x1, width, isTextInside, rtl, arrowIndent]);
6602
+ const textForRender = isInCollapsedGroup ? "" : task.name;
6603
+ console.log("testForRender", textForRender);
6604
+ const xForRender = isInCollapsedGroup ? x1 + width * 0.5 : x3;
6563
6605
  const onMouseDown = useCallback(
6564
6606
  (event) => {
6565
6607
  selectTaskOnMouseDown(task.id, event);
@@ -6603,11 +6645,11 @@ const TaskItemInner = (props) => {
6603
6645
  "text",
6604
6646
  {
6605
6647
  fill: barLabelFill,
6606
- x: x3,
6648
+ x: xForRender,
6607
6649
  y: taskYOffset + taskHeight * 0.5,
6608
6650
  className: isTextInside ? style.barLabel : style.barLabel && style.barLabelOutside,
6609
6651
  ref: textRef,
6610
- children: enableTaskGrouping ? isTextInside ? task.name : "" : task.name
6652
+ children: textForRender
6611
6653
  }
6612
6654
  ),
6613
6655
  (outOfParentWarnings || hasDependencyWarning) && /* @__PURE__ */ jsx(
@@ -6776,6 +6818,9 @@ const TaskGanttContent = ({
6776
6818
  children: /* @__PURE__ */ jsx(
6777
6819
  TaskItem,
6778
6820
  {
6821
+ enableTaskGrouping,
6822
+ taskToRowIndexMap,
6823
+ rowIndexToTasksMap,
6779
6824
  getTaskGlobalIndexByRef,
6780
6825
  hasChildren: checkHasChildren(task, childTasksMap),
6781
6826
  hasDependencyWarning: taskToHasDependencyWarningMap ? checkTaskHasDependencyWarning(task, taskToHasDependencyWarningMap) : false,
@@ -6808,8 +6853,7 @@ const TaskGanttContent = ({
6808
6853
  fixStartPosition,
6809
6854
  fixEndPosition,
6810
6855
  handleDeleteTasks,
6811
- colorStyles,
6812
- enableTaskGrouping
6856
+ colorStyles
6813
6857
  }
6814
6858
  )
6815
6859
  },
@@ -4241,6 +4241,7 @@
4241
4241
  if (taskIndex) {
4242
4242
  [depth, indexStr] = taskIndex;
4243
4243
  }
4244
+ console.log("colors :>> ", colors);
4244
4245
  renderList.push(
4245
4246
  /* @__PURE__ */ jsxRuntime.jsx(
4246
4247
  TaskListTableRow,
@@ -4827,7 +4828,6 @@
4827
4828
  );
4828
4829
  const dayOfMonth = date.getDate();
4829
4830
  const prevDate = getDate(i - 1);
4830
- console.log("testing center :>> ", additionalLeftSpace + columnWidth * i + ticks * columnWidth * 0.5);
4831
4831
  if (!isUnknownDates && dayOfMonth !== prevDate.getDate()) {
4832
4832
  const topValue = renderTopHeaderByDate(date);
4833
4833
  topValues2.push(
@@ -5026,7 +5026,6 @@
5026
5026
  startColumnIndex
5027
5027
  )) {
5028
5028
  const x2 = additionalLeftSpace + columnWidth * i;
5029
- console.log("drawing divider at x:", x2, "for index:", i, "date:", currentDate);
5030
5029
  dividers.push(
5031
5030
  /* @__PURE__ */ jsxRuntime.jsx(
5032
5031
  "line",
@@ -5591,10 +5590,35 @@
5591
5590
  }
5592
5591
  );
5593
5592
  };
5594
- const hoverVisibleWrapper = "_hoverVisibleWrapper_11ld1_1";
5595
- const wrapper = "_wrapper_11ld1_1";
5596
- const mainPath = "_mainPath_11ld1_17";
5597
- const clickZone = "_clickZone_11ld1_35";
5593
+ const truncateText = (text, maxWidth, textElement) => {
5594
+ if (!textElement)
5595
+ return text;
5596
+ textElement.textContent = text;
5597
+ const fullWidth = textElement.getBBox().width;
5598
+ if (fullWidth <= maxWidth) {
5599
+ return text;
5600
+ }
5601
+ let start = 0;
5602
+ let end = text.length;
5603
+ let result = text;
5604
+ while (start <= end) {
5605
+ const mid = Math.floor((start + end) / 2);
5606
+ const truncated = text.substring(0, mid);
5607
+ textElement.textContent = truncated;
5608
+ const truncatedWidth = textElement.getBBox().width;
5609
+ if (truncatedWidth <= maxWidth) {
5610
+ result = truncated;
5611
+ start = mid + 1;
5612
+ } else {
5613
+ end = mid - 1;
5614
+ }
5615
+ }
5616
+ return result;
5617
+ };
5618
+ const hoverVisibleWrapper = "_hoverVisibleWrapper_8hbnp_1";
5619
+ const wrapper = "_wrapper_8hbnp_1";
5620
+ const mainPath = "_mainPath_8hbnp_17";
5621
+ const clickZone = "_clickZone_8hbnp_35";
5598
5622
  const styles$4 = {
5599
5623
  hoverVisibleWrapper,
5600
5624
  wrapper,
@@ -6286,8 +6310,8 @@
6286
6310
  }
6287
6311
  );
6288
6312
  };
6289
- const barLabel = "_barLabel_y0tyg_1";
6290
- const barLabelOutside = "_barLabelOutside_y0tyg_25";
6313
+ const barLabel = "_barLabel_7emdt_1";
6314
+ const barLabelOutside = "_barLabelOutside_7emdt_25";
6291
6315
  const style = {
6292
6316
  barLabel,
6293
6317
  barLabelOutside
@@ -6364,6 +6388,7 @@
6364
6388
  };
6365
6389
  const TaskWarning = React.memo(TaskWarningInner);
6366
6390
  const TaskItemInner = (props) => {
6391
+ var _a, _b, _c;
6367
6392
  const {
6368
6393
  childOutOfParentWarnings,
6369
6394
  colorStyles: stylesProp,
@@ -6393,6 +6418,8 @@
6393
6418
  selectTaskOnMouseDown,
6394
6419
  setTooltipTask,
6395
6420
  enableTaskGrouping,
6421
+ taskToRowIndexMap,
6422
+ rowIndexToTasksMap,
6396
6423
  task,
6397
6424
  task: { styles: taskStyles },
6398
6425
  taskHalfHeight,
@@ -6445,6 +6472,11 @@
6445
6472
  const globalIndex = getTaskGlobalIndexByRef(task);
6446
6473
  fixEndPosition(task, end.date, globalIndex);
6447
6474
  }, [task, fixEndPosition, outOfParentWarnings, getTaskGlobalIndexByRef]);
6475
+ const taskRowIndex = (_a = taskToRowIndexMap == null ? void 0 : taskToRowIndexMap.get(task.comparisonLevel ?? 1)) == null ? void 0 : _a.get(task.id);
6476
+ if (taskRowIndex === void 0)
6477
+ return null;
6478
+ const isSharedRow = (((_c = (_b = rowIndexToTasksMap == null ? void 0 : rowIndexToTasksMap.get(task.comparisonLevel ?? 1)) == null ? void 0 : _b.get(taskRowIndex)) == null ? void 0 : _c.length) ?? 0) > 1;
6479
+ const isInCollapsedGroup = !!enableTaskGrouping && isSharedRow;
6448
6480
  const handleClick = React.useCallback(
6449
6481
  (event) => {
6450
6482
  if (onClick) {
@@ -6478,6 +6510,8 @@
6478
6510
  }, [onRelationStart, rtl, task]);
6479
6511
  const textRef = React.useRef(null);
6480
6512
  const [isTextInside, setIsTextInside] = React.useState(true);
6513
+ const [truncatedText, setTruncatedText] = React.useState(task.name);
6514
+ console.log("truncatedText", truncatedText);
6481
6515
  const taskItem = React.useMemo(() => {
6482
6516
  const isFromStartRelationAuthorized = authorizedRelations.includes("startToStart") || authorizedRelations.includes("startToEnd");
6483
6517
  const isFromEndRelationAuthorized = authorizedRelations.includes("endToEnd") || authorizedRelations.includes("endToStart");
@@ -6560,10 +6594,15 @@
6560
6594
  width
6561
6595
  ]);
6562
6596
  React.useEffect(() => {
6563
- if (textRef.current) {
6597
+ if (!textRef.current)
6598
+ return;
6599
+ if (isInCollapsedGroup) {
6600
+ const truncated = truncateText(task.name, width - 10, textRef.current);
6601
+ setTruncatedText(truncated);
6602
+ } else {
6564
6603
  setIsTextInside(textRef.current.getBBox().width < width);
6565
6604
  }
6566
- }, [textRef, width]);
6605
+ }, [isInCollapsedGroup, task.name, width]);
6567
6606
  const x3 = React.useMemo(() => {
6568
6607
  if (isTextInside) {
6569
6608
  return x1 + width * 0.5;
@@ -6573,6 +6612,9 @@
6573
6612
  }
6574
6613
  return x1 + width + arrowIndent * 1.2;
6575
6614
  }, [x1, width, isTextInside, rtl, arrowIndent]);
6615
+ const textForRender = isInCollapsedGroup ? "" : task.name;
6616
+ console.log("testForRender", textForRender);
6617
+ const xForRender = isInCollapsedGroup ? x1 + width * 0.5 : x3;
6576
6618
  const onMouseDown = React.useCallback(
6577
6619
  (event) => {
6578
6620
  selectTaskOnMouseDown(task.id, event);
@@ -6616,11 +6658,11 @@
6616
6658
  "text",
6617
6659
  {
6618
6660
  fill: barLabelFill,
6619
- x: x3,
6661
+ x: xForRender,
6620
6662
  y: taskYOffset + taskHeight * 0.5,
6621
6663
  className: isTextInside ? style.barLabel : style.barLabel && style.barLabelOutside,
6622
6664
  ref: textRef,
6623
- children: enableTaskGrouping ? isTextInside ? task.name : "" : task.name
6665
+ children: textForRender
6624
6666
  }
6625
6667
  ),
6626
6668
  (outOfParentWarnings || hasDependencyWarning) && /* @__PURE__ */ jsxRuntime.jsx(
@@ -6789,6 +6831,9 @@
6789
6831
  children: /* @__PURE__ */ jsxRuntime.jsx(
6790
6832
  TaskItem,
6791
6833
  {
6834
+ enableTaskGrouping,
6835
+ taskToRowIndexMap,
6836
+ rowIndexToTasksMap,
6792
6837
  getTaskGlobalIndexByRef,
6793
6838
  hasChildren: checkHasChildren(task, childTasksMap),
6794
6839
  hasDependencyWarning: taskToHasDependencyWarningMap ? checkTaskHasDependencyWarning(task, taskToHasDependencyWarningMap) : false,
@@ -6821,8 +6866,7 @@
6821
6866
  fixStartPosition,
6822
6867
  fixEndPosition,
6823
6868
  handleDeleteTasks,
6824
- colorStyles,
6825
- enableTaskGrouping
6869
+ colorStyles
6826
6870
  }
6827
6871
  )
6828
6872
  },
@@ -0,0 +1 @@
1
+ export declare const truncateText: (text: string, maxWidth: number, textElement: SVGTextElement | null) => string;
package/dist/style.css CHANGED
@@ -440,28 +440,27 @@
440
440
  stroke-width: 2;
441
441
  stroke-dasharray: 4;
442
442
  }
443
- ._hoverVisibleWrapper_11ld1_1:hover ._wrapper_11ld1_1 {
443
+ ._hoverVisibleWrapper_8hbnp_1:hover ._wrapper_8hbnp_1 {
444
444
  display: initial;
445
445
  }
446
446
 
447
- ._wrapper_11ld1_1 {
447
+ ._wrapper_8hbnp_1 {
448
448
  cursor: pointer;
449
449
  }
450
450
 
451
- ._wrapper_11ld1_1:hover ._mainPath_11ld1_17 {
451
+ ._wrapper_8hbnp_1:hover ._mainPath_8hbnp_17 {
452
452
  filter: drop-shadow(0px 0px 2px rgba(0, 0, 0, .7));
453
453
  }
454
454
 
455
- ._mainPath_11ld1_17 {
455
+ ._mainPath_8hbnp_17 {
456
456
  fill: none;
457
457
  stroke-width: 1.5px;
458
458
  }
459
459
 
460
- ._clickZone_11ld1_35 {
460
+ ._clickZone_8hbnp_35 {
461
461
  fill: transparent;
462
462
  stroke: transparent;
463
- }
464
- ._barWrapper_1kg71_1 {
463
+ }._barWrapper_1kg71_1 {
465
464
  cursor: pointer;
466
465
  outline: none;
467
466
  }
@@ -521,7 +520,7 @@
521
520
  ._milestoneBackground_vcirf_11 {
522
521
  user-select: none;
523
522
  }
524
- ._barLabel_y0tyg_1 {
523
+ ._barLabel_7emdt_1 {
525
524
  text-anchor: middle;
526
525
  font-weight: lighter;
527
526
  dominant-baseline: central;
@@ -533,7 +532,7 @@
533
532
  pointer-events: none;
534
533
  }
535
534
 
536
- ._barLabelOutside_y0tyg_25 {
535
+ ._barLabelOutside_7emdt_25 {
537
536
  text-anchor: start;
538
537
  -webkit-touch-callout: none;
539
538
  -webkit-user-select: none;
@@ -541,8 +540,7 @@
541
540
  -ms-user-select: none;
542
541
  user-select: none;
543
542
  pointer-events: none;
544
- }
545
- ._menuOption_z7pb4_1 {
543
+ }._menuOption_z7pb4_1 {
546
544
  display: flex;
547
545
  align-items: center;
548
546
  gap: 5px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thepocman/gantt-task-react",
3
- "version": "1.0.31",
3
+ "version": "1.0.34",
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",