gantt-task-react-powern 0.6.27 → 0.6.29

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.
@@ -49,5 +49,6 @@ export declare type TaskListProps = {
49
49
  }>;
50
50
  containerWidth?: number;
51
51
  innerScrollRef?: React.RefObject<HTMLDivElement>;
52
+ horizontalContainerRef?: React.RefObject<HTMLDivElement>;
52
53
  } & EventOption;
53
54
  export declare const TaskList: React.FC<TaskListProps>;
package/dist/index.js CHANGED
@@ -898,8 +898,26 @@ var TaskList = function TaskList(_ref) {
898
898
  taskLabelRenderer = _ref.taskLabelRenderer,
899
899
  onMultiSelect = _ref.onMultiSelect,
900
900
  containerWidth = _ref.containerWidth,
901
- innerScrollRef = _ref.innerScrollRef;
902
- var horizontalContainerRef = React.useRef(null);
901
+ innerScrollRef = _ref.innerScrollRef,
902
+ externalHorizontalContainerRef = _ref.horizontalContainerRef;
903
+ var internalHorizontalContainerRef = React.useRef(null);
904
+ var horizontalContainerRef = externalHorizontalContainerRef != null ? externalHorizontalContainerRef : internalHorizontalContainerRef;
905
+ var headerScrollRef = React.useRef(null);
906
+ React.useEffect(function () {
907
+ var rowsEl = horizontalContainerRef.current;
908
+ if (!rowsEl) return;
909
+
910
+ var onScroll = function onScroll() {
911
+ if (headerScrollRef.current) {
912
+ headerScrollRef.current.scrollLeft = rowsEl.scrollLeft;
913
+ }
914
+ };
915
+
916
+ rowsEl.addEventListener("scroll", onScroll);
917
+ return function () {
918
+ return rowsEl.removeEventListener("scroll", onScroll);
919
+ };
920
+ }, [horizontalContainerRef]);
903
921
 
904
922
  var _useState = React.useState([]),
905
923
  selectedTasks = _useState[0],
@@ -1086,9 +1104,14 @@ var TaskList = function TaskList(_ref) {
1086
1104
  ref: innerScrollRef,
1087
1105
  className: styles$4.hideScrollbar,
1088
1106
  style: {
1089
- overflowX: "auto"
1107
+ overflowX: "hidden"
1108
+ }
1109
+ }, React__default.createElement("div", {
1110
+ ref: headerScrollRef,
1111
+ style: {
1112
+ overflow: "hidden"
1090
1113
  }
1091
- }, React__default.createElement(TaskListHeader, Object.assign({}, headerProps)), React__default.createElement("div", {
1114
+ }, React__default.createElement(TaskListHeader, Object.assign({}, headerProps))), React__default.createElement("div", {
1092
1115
  ref: horizontalContainerRef,
1093
1116
  className: horizontalContainerClass,
1094
1117
  style: ganttHeight ? {
@@ -1116,13 +1139,21 @@ function toDateString(date) {
1116
1139
  }
1117
1140
 
1118
1141
  function isHoliday(date, cal) {
1119
- return cal.holidays.includes(toDateString(date));
1142
+ if (cal.holidays && cal.holidays.length > 0) {
1143
+ return cal.holidays.includes(toDateString(date));
1144
+ } else {
1145
+ return false;
1146
+ }
1120
1147
  }
1121
1148
  function isOffDay(date, cal) {
1122
- return cal.off_days.includes(date.getDay()) || isHoliday(date, cal);
1149
+ if (cal.off_days && cal.off_days.length > 0) {
1150
+ return cal.off_days.includes(date.getDay()) || isHoliday(date, cal);
1151
+ } else {
1152
+ return false;
1153
+ }
1123
1154
  }
1124
1155
  function getShiftsForDay(date, cal) {
1125
- if (isOffDay(date, cal)) return [];
1156
+ if (isOffDay(date, cal) || !cal.shifts) return [];
1126
1157
  return cal.shifts.map(function (_ref) {
1127
1158
  var s = _ref[0],
1128
1159
  e = _ref[1];
@@ -1348,6 +1379,7 @@ var GridBody = function GridBody(_ref) {
1348
1379
  });
1349
1380
  var rowBackgrounds = [];
1350
1381
  var rowLines = [];
1382
+ var rowOverlays = [];
1351
1383
  rowLines.push(React__default.createElement("line", {
1352
1384
  key: "top-line",
1353
1385
  x1: 0,
@@ -1356,6 +1388,7 @@ var GridBody = function GridBody(_ref) {
1356
1388
  y2: visibleStartY,
1357
1389
  className: styles$5.gridRowLine
1358
1390
  }));
1391
+ var showPerRowOffDays = viewMode !== exports.ViewMode.Month && viewMode !== exports.ViewMode.Quarter;
1359
1392
 
1360
1393
  for (var _iterator = _createForOfIteratorHelperLoose(items), _step; !(_step = _iterator()).done;) {
1361
1394
  var vi = _step.value;
@@ -1380,6 +1413,63 @@ var GridBody = function GridBody(_ref) {
1380
1413
  y2: y + rowHeight,
1381
1414
  className: styles$5.gridRowLine
1382
1415
  }));
1416
+
1417
+ if (showPerRowOffDays) {
1418
+ var rowEven = vi.index % 2 === 1;
1419
+ var rowFill = isMilestone ? "#e6e4e4" : scheduleType === "lookAhead" ? "#fff" : rowEven ? "#f5f5f5" : "#fff";
1420
+ rowOverlays.push(React__default.createElement("rect", {
1421
+ key: "row-clean-" + vi.key,
1422
+ x: 0,
1423
+ y: y,
1424
+ width: svgWidth,
1425
+ height: rowHeight,
1426
+ fill: rowFill
1427
+ }));
1428
+ var cal = task.calender;
1429
+
1430
+ if (cal) {
1431
+ for (var _i = 0, _x = 0; _i < dates.length; _i++, _x += columnWidth) {
1432
+ var _dates2;
1433
+
1434
+ var _pEnd = (_dates2 = dates[_i + 1]) != null ? _dates2 : addToDate(dates[_i], 1, "day");
1435
+
1436
+ var _periodMs = _pEnd.getTime() - dates[_i].getTime();
1437
+
1438
+ if (_periodMs <= 0) continue;
1439
+
1440
+ var _cursor = new Date(dates[_i]);
1441
+
1442
+ _cursor.setHours(0, 0, 0, 0);
1443
+
1444
+ while (_cursor.getTime() < _pEnd.getTime()) {
1445
+ if (isOffDay(_cursor, cal)) {
1446
+ var _ds = _cursor.getTime() - dates[_i].getTime();
1447
+
1448
+ var _de = _ds + 86400000;
1449
+
1450
+ var _startFrac = Math.max(0, _ds) / _periodMs;
1451
+
1452
+ var _endFrac = Math.min(_periodMs, _de) / _periodMs;
1453
+
1454
+ var _rw = (_endFrac - _startFrac) * columnWidth;
1455
+
1456
+ if (_rw > 0.5) {
1457
+ rowOverlays.push(React__default.createElement("rect", {
1458
+ key: "row-offday-" + vi.key + "-" + _cursor.getTime(),
1459
+ x: rtl ? _x + columnWidth - (_startFrac * columnWidth + _rw) : _x + _startFrac * columnWidth,
1460
+ y: y,
1461
+ width: _rw,
1462
+ height: rowHeight,
1463
+ fill: weekendColor
1464
+ }));
1465
+ }
1466
+ }
1467
+
1468
+ _cursor.setDate(_cursor.getDate() + 1);
1469
+ }
1470
+ }
1471
+ }
1472
+ }
1383
1473
  }
1384
1474
 
1385
1475
  return React__default.createElement("g", {
@@ -1391,6 +1481,8 @@ var GridBody = function GridBody(_ref) {
1391
1481
  }, rowLines), React__default.createElement("g", {
1392
1482
  className: "offdays"
1393
1483
  }, offDayRects), React__default.createElement("g", {
1484
+ className: "rowOverlays"
1485
+ }, rowOverlays), React__default.createElement("g", {
1394
1486
  className: "ticks"
1395
1487
  }, tickLines), React__default.createElement("g", {
1396
1488
  className: "today"
@@ -3725,8 +3817,6 @@ var HorizontalScroll = function HorizontalScroll(_ref) {
3725
3817
  };
3726
3818
 
3727
3819
  var Gantt = function Gantt(_ref) {
3728
- var _tasks$find$calender, _tasks$find;
3729
-
3730
3820
  var tasks = _ref.tasks,
3731
3821
  _ref$leafTasks = _ref.leafTasks,
3732
3822
  leafTasks = _ref$leafTasks === void 0 ? [] : _ref$leafTasks,
@@ -3817,9 +3907,6 @@ var Gantt = function Gantt(_ref) {
3817
3907
  projectCalendar = _ref.projectCalendar,
3818
3908
  onCalendarError = _ref.onCalendarError,
3819
3909
  sliderTime = _ref.sliderTime;
3820
- var effectiveCalendar = (_tasks$find$calender = (_tasks$find = tasks.find(function (t) {
3821
- return t.calender;
3822
- })) === null || _tasks$find === void 0 ? void 0 : _tasks$find.calender) != null ? _tasks$find$calender : projectCalendar;
3823
3910
  var wrapperRef = React.useRef(null);
3824
3911
  var taskListRef = React.useRef(null);
3825
3912
  var isDraggingTable = React.useRef(false);
@@ -3832,6 +3919,7 @@ var Gantt = function Gantt(_ref) {
3832
3919
  setTableContainerWidth = _useState[1];
3833
3920
 
3834
3921
  var tableInnerScrollRef = React.useRef(null);
3922
+ var tableHorizontalContainerRef = React.useRef(null);
3835
3923
  var tableHScrollRef = React.useRef(null);
3836
3924
 
3837
3925
  var _useState2 = React.useState(0),
@@ -3867,18 +3955,20 @@ var Gantt = function Gantt(_ref) {
3867
3955
  setTaskListWidth = _useState5[1];
3868
3956
 
3869
3957
  React.useEffect(function () {
3870
- if (tableInnerScrollRef.current) {
3958
+ if (tableHorizontalContainerRef.current) {
3959
+ setTableScrollableWidth(tableHorizontalContainerRef.current.scrollWidth);
3960
+ } else if (tableInnerScrollRef.current) {
3871
3961
  setTableScrollableWidth(tableInnerScrollRef.current.scrollWidth);
3872
3962
  }
3873
3963
  }, [taskListWidth, listCellWidth]);
3874
3964
 
3875
3965
  var handleTableResizeMouseDown = function handleTableResizeMouseDown(e) {
3876
- var _taskListRef$current$, _taskListRef$current, _tableInnerScrollRef$, _tableInnerScrollRef$2, _wrapperRef$current$o, _wrapperRef$current;
3966
+ var _taskListRef$current$, _taskListRef$current, _ref2, _tableHorizontalConta, _tableHorizontalConta2, _tableInnerScrollRef$, _wrapperRef$current$o, _wrapperRef$current;
3877
3967
 
3878
3968
  isDraggingTable.current = true;
3879
3969
  dragStartX.current = e.clientX;
3880
3970
  dragStartWidth.current = tableContainerWidth != null ? tableContainerWidth : (_taskListRef$current$ = (_taskListRef$current = taskListRef.current) === null || _taskListRef$current === void 0 ? void 0 : _taskListRef$current.offsetWidth) != null ? _taskListRef$current$ : 0;
3881
- dragMaxWidth.current = (_tableInnerScrollRef$ = (_tableInnerScrollRef$2 = tableInnerScrollRef.current) === null || _tableInnerScrollRef$2 === void 0 ? void 0 : _tableInnerScrollRef$2.scrollWidth) != null ? _tableInnerScrollRef$ : Math.max(100, ((_wrapperRef$current$o = (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.offsetWidth) != null ? _wrapperRef$current$o : Infinity) - 200);
3971
+ dragMaxWidth.current = (_ref2 = (_tableHorizontalConta = (_tableHorizontalConta2 = tableHorizontalContainerRef.current) === null || _tableHorizontalConta2 === void 0 ? void 0 : _tableHorizontalConta2.scrollWidth) != null ? _tableHorizontalConta : (_tableInnerScrollRef$ = tableInnerScrollRef.current) === null || _tableInnerScrollRef$ === void 0 ? void 0 : _tableInnerScrollRef$.scrollWidth) != null ? _ref2 : Math.max(100, ((_wrapperRef$current$o = (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.offsetWidth) != null ? _wrapperRef$current$o : Infinity) - 200);
3882
3972
  e.preventDefault();
3883
3973
  };
3884
3974
 
@@ -3996,13 +4086,13 @@ var Gantt = function Gantt(_ref) {
3996
4086
  }
3997
4087
 
3998
4088
  debounceRef.current = setTimeout(function () {
3999
- var _effectiveCalendar$qu;
4089
+ var _projectCalendar$quar;
4000
4090
 
4001
4091
  var filteredTasks;
4002
4092
  filteredTasks = removeHiddenTasks(tasks);
4003
4093
  filteredTasks = filteredTasks.sort(sortTasks);
4004
4094
 
4005
- var _ganttDateRange2 = ganttDateRange(filteredTasks, viewMode, preStepsCount, (_effectiveCalendar$qu = effectiveCalendar === null || effectiveCalendar === void 0 ? void 0 : effectiveCalendar.quarter_start) != null ? _effectiveCalendar$qu : 0),
4095
+ var _ganttDateRange2 = ganttDateRange(filteredTasks, viewMode, preStepsCount, (_projectCalendar$quar = projectCalendar === null || projectCalendar === void 0 ? void 0 : projectCalendar.quarter_start) != null ? _projectCalendar$quar : 0),
4006
4096
  startDateRange = _ganttDateRange2[0],
4007
4097
  endDateRange = _ganttDateRange2[1];
4008
4098
 
@@ -4041,7 +4131,7 @@ var Gantt = function Gantt(_ref) {
4041
4131
  setBarTasks(convertToBarTasks(filteredTasks, newDates, effectiveColumnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor));
4042
4132
  setIsProcessing(false);
4043
4133
  }, delayToRender);
4044
- }, [tasks, viewMode, preStepsCount, rowHeight, barCornerRadius, taskHeight, handleWidth, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor, rtl, shouldNotShowLoadingOverlay, effectiveColumnWidth, effectiveCalendar]);
4134
+ }, [tasks, viewMode, preStepsCount, rowHeight, barCornerRadius, taskHeight, handleWidth, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor, rtl, shouldNotShowLoadingOverlay, effectiveColumnWidth, projectCalendar]);
4045
4135
  React.useEffect(function () {
4046
4136
  return function () {
4047
4137
  clearTimeout(debounceRef.current);
@@ -4313,7 +4403,7 @@ var Gantt = function Gantt(_ref) {
4313
4403
  rtl: rtl,
4314
4404
  visibleStartY: visibleStartY,
4315
4405
  visibleEndY: visibleEndY,
4316
- projectCalendar: effectiveCalendar,
4406
+ projectCalendar: projectCalendar,
4317
4407
  viewMode: viewMode
4318
4408
  };
4319
4409
  var calendarProps = {
@@ -4325,7 +4415,7 @@ var Gantt = function Gantt(_ref) {
4325
4415
  fontFamily: fontFamily,
4326
4416
  fontSize: fontSize,
4327
4417
  rtl: rtl,
4328
- projectCalendar: effectiveCalendar
4418
+ projectCalendar: projectCalendar
4329
4419
  };
4330
4420
  var barProps = {
4331
4421
  tasks: barTasks,
@@ -4352,7 +4442,7 @@ var Gantt = function Gantt(_ref) {
4352
4442
  onClick: onClick,
4353
4443
  onDelete: onDelete,
4354
4444
  onCalendarError: onCalendarError,
4355
- projectCalendar: effectiveCalendar,
4445
+ projectCalendar: projectCalendar,
4356
4446
  visibleStartY: visibleStartY,
4357
4447
  visibleEndY: visibleEndY,
4358
4448
  sliderTime: sliderTime
@@ -4385,7 +4475,8 @@ var Gantt = function Gantt(_ref) {
4385
4475
  taskLabelRenderer: taskLabelRenderer,
4386
4476
  onMultiSelect: onMultiSelect,
4387
4477
  containerWidth: tableContainerWidth != null ? tableContainerWidth : undefined,
4388
- innerScrollRef: tableInnerScrollRef
4478
+ innerScrollRef: tableInnerScrollRef,
4479
+ horizontalContainerRef: tableHorizontalContainerRef
4389
4480
  };
4390
4481
  return React__default.createElement("div", {
4391
4482
  style: {
@@ -4481,8 +4572,8 @@ var Gantt = function Gantt(_ref) {
4481
4572
  flexShrink: 0
4482
4573
  },
4483
4574
  onScroll: function onScroll(e) {
4484
- if (tableInnerScrollRef.current) {
4485
- tableInnerScrollRef.current.scrollLeft = e.currentTarget.scrollLeft;
4575
+ if (tableHorizontalContainerRef.current) {
4576
+ tableHorizontalContainerRef.current.scrollLeft = e.currentTarget.scrollLeft;
4486
4577
  }
4487
4578
  }
4488
4579
  }, React__default.createElement("div", {