gantt-lib 0.0.7 → 0.0.9

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
@@ -717,6 +717,7 @@ function handleGlobalMouseMove(e) {
717
717
  const dayWidth2 = globalActiveDrag.dayWidth;
718
718
  const monthStart = globalActiveDrag.monthStart;
719
719
  for (const chainTask of activeChain) {
720
+ if (chainTask.locked) continue;
720
721
  const chainStart = new Date(chainTask.startDate);
721
722
  const chainEnd = new Date(chainTask.endDate);
722
723
  const chainStartOffset = Math.round(
@@ -796,6 +797,7 @@ var useTaskDrag = (options) => {
796
797
  onCascade
797
798
  } = options;
798
799
  const isOwnerRef = useRef(false);
800
+ const locked = options.locked ?? false;
799
801
  const [isDragging, setIsDragging] = useState(false);
800
802
  const [dragMode, setDragMode] = useState(null);
801
803
  const [currentLeft, setCurrentLeft] = useState(0);
@@ -901,7 +903,7 @@ var useTaskDrag = (options) => {
901
903
  dependencies: recalculateIncomingLags(draggedTaskData, newStartDate, newEndDate, allTasks)
902
904
  }
903
905
  },
904
- ...chainForCompletion.map((chainTask) => {
906
+ ...chainForCompletion.filter((chainTask) => !chainTask.locked).map((chainTask) => {
905
907
  const origStart = new Date(chainTask.startDate);
906
908
  const origEnd = new Date(chainTask.endDate);
907
909
  const newStart = new Date(Date.UTC(
@@ -951,6 +953,7 @@ var useTaskDrag = (options) => {
951
953
  };
952
954
  }, []);
953
955
  const handleMouseDown = useCallback((e) => {
956
+ if (locked) return;
954
957
  const target = e.currentTarget;
955
958
  const edgeZone = detectEdgeZone(e.clientX, target, edgeZoneWidth);
956
959
  let mode = null;
@@ -1005,13 +1008,14 @@ var useTaskDrag = (options) => {
1005
1008
  cascadeChainEnd: !disableConstraints ? getTransitiveCascadeChain(taskId, allTasks, ["FS", "FF"]) : [],
1006
1009
  onCascadeProgress
1007
1010
  };
1008
- }, [edgeZoneWidth, currentLeft, currentWidth, dayWidth, monthStart, taskId, onDragStateChange, handleProgress, handleComplete, handleCancel, allTasks, disableConstraints, onCascadeProgress, onCascade]);
1011
+ }, [edgeZoneWidth, currentLeft, currentWidth, dayWidth, monthStart, taskId, onDragStateChange, handleProgress, handleComplete, handleCancel, allTasks, disableConstraints, onCascadeProgress, onCascade, locked]);
1009
1012
  const getCursorStyle = useCallback(() => {
1013
+ if (locked) return "not-allowed";
1010
1014
  if (isDragging) {
1011
1015
  return "grabbing";
1012
1016
  }
1013
1017
  return "grab";
1014
- }, [isDragging]);
1018
+ }, [locked, isDragging]);
1015
1019
  return {
1016
1020
  isDragging,
1017
1021
  dragMode,
@@ -1030,10 +1034,11 @@ var useTaskDrag = (options) => {
1030
1034
  // src/components/TaskRow/TaskRow.tsx
1031
1035
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1032
1036
  var arePropsEqual = (prevProps, nextProps) => {
1033
- return prevProps.task.id === nextProps.task.id && prevProps.task.name === nextProps.task.name && prevProps.task.startDate === nextProps.task.startDate && prevProps.task.endDate === nextProps.task.endDate && prevProps.task.color === nextProps.task.color && prevProps.task.progress === nextProps.task.progress && prevProps.task.accepted === nextProps.task.accepted && prevProps.monthStart.getTime() === nextProps.monthStart.getTime() && prevProps.dayWidth === nextProps.dayWidth && prevProps.rowHeight === nextProps.rowHeight && prevProps.overridePosition?.left === nextProps.overridePosition?.left && prevProps.overridePosition?.width === nextProps.overridePosition?.width && prevProps.allTasks === nextProps.allTasks && prevProps.disableConstraints === nextProps.disableConstraints;
1037
+ return prevProps.task.id === nextProps.task.id && prevProps.task.name === nextProps.task.name && prevProps.task.startDate === nextProps.task.startDate && prevProps.task.endDate === nextProps.task.endDate && prevProps.task.color === nextProps.task.color && prevProps.task.progress === nextProps.task.progress && prevProps.task.accepted === nextProps.task.accepted && prevProps.monthStart.getTime() === nextProps.monthStart.getTime() && prevProps.dayWidth === nextProps.dayWidth && prevProps.rowHeight === nextProps.rowHeight && prevProps.overridePosition?.left === nextProps.overridePosition?.left && prevProps.overridePosition?.width === nextProps.overridePosition?.width && prevProps.allTasks === nextProps.allTasks && prevProps.disableConstraints === nextProps.disableConstraints && prevProps.task.locked === nextProps.task.locked && prevProps.task.divider === nextProps.task.divider;
1034
1038
  };
1035
1039
  var TaskRow = React2.memo(
1036
- ({ task, monthStart, dayWidth, rowHeight, onChange, onDragStateChange, rowIndex, allTasks, enableAutoSchedule, disableConstraints, overridePosition, onCascadeProgress, onCascade }) => {
1040
+ ({ task, monthStart, dayWidth, rowHeight, onChange, onDragStateChange, rowIndex, allTasks, enableAutoSchedule, disableConstraints, overridePosition, onCascadeProgress, onCascade, divider }) => {
1041
+ const { divider: taskDivider } = task;
1037
1042
  const taskStartDate = useMemo2(() => parseUTCDate(task.startDate), [task.startDate]);
1038
1043
  const taskEndDate = useMemo2(() => parseUTCDate(task.endDate), [task.endDate]);
1039
1044
  const { left, width } = useMemo2(
@@ -1049,7 +1054,8 @@ var TaskRow = React2.memo(
1049
1054
  if (progressWidth === 100) {
1050
1055
  return task.accepted ? "var(--gantt-progress-accepted, #22c55e)" : "var(--gantt-progress-completed, #fbbf24)";
1051
1056
  }
1052
- return task.color ? `color-mix(in srgb, ${task.color} 40%, black)` : "var(--gantt-progress-color, rgba(0, 0, 0, 0.2))";
1057
+ const baseColor = task.color || "var(--gantt-task-bar-default-color)";
1058
+ return `color-mix(in srgb, ${baseColor} 40%, black)`;
1053
1059
  }, [progressWidth, task.accepted, task.color]);
1054
1060
  const handleDragEnd = (result) => {
1055
1061
  const updatedTask = {
@@ -1079,6 +1085,7 @@ var TaskRow = React2.memo(
1079
1085
  rowIndex,
1080
1086
  enableAutoSchedule,
1081
1087
  disableConstraints,
1088
+ locked: task.locked,
1082
1089
  onCascadeProgress,
1083
1090
  onCascade
1084
1091
  });
@@ -1093,81 +1100,106 @@ var TaskRow = React2.memo(
1093
1100
  ) + 1;
1094
1101
  const estimatedTextWidth = durationDays >= 10 ? 76 : 62;
1095
1102
  const showProgressInside = progressWidth > 0 && displayWidth > estimatedTextWidth;
1096
- return /* @__PURE__ */ jsx2(
1103
+ return /* @__PURE__ */ jsxs2(
1097
1104
  "div",
1098
1105
  {
1099
1106
  className: "gantt-tr-row",
1100
1107
  style: { height: `${rowHeight}px` },
1101
- children: /* @__PURE__ */ jsxs2("div", { className: "gantt-tr-taskContainer", children: [
1102
- /* @__PURE__ */ jsxs2(
1103
- "div",
1104
- {
1105
- "data-taskbar": true,
1106
- className: `gantt-tr-taskBar ${isDragging ? "gantt-tr-dragging" : ""}`,
1107
- style: {
1108
- left: `${displayLeft}px`,
1109
- width: `${displayWidth}px`,
1110
- backgroundColor: barColor,
1111
- height: "var(--gantt-task-bar-height)",
1112
- cursor: dragHandleProps.style.cursor,
1113
- userSelect: dragHandleProps.style.userSelect
1114
- },
1115
- onMouseDown: dragHandleProps.onMouseDown,
1116
- children: [
1117
- progressWidth > 0 && /* @__PURE__ */ jsx2(
1118
- "div",
1119
- {
1120
- className: "gantt-tr-progressBar",
1121
- style: {
1122
- width: `${progressWidth}%`,
1123
- backgroundColor: progressColor
1108
+ children: [
1109
+ taskDivider === "top" && /* @__PURE__ */ jsx2("div", { className: "gantt-tr-divider gantt-tr-divider-top" }),
1110
+ /* @__PURE__ */ jsxs2("div", { className: "gantt-tr-taskContainer", children: [
1111
+ /* @__PURE__ */ jsxs2(
1112
+ "div",
1113
+ {
1114
+ "data-taskbar": true,
1115
+ className: `gantt-tr-taskBar ${isDragging ? "gantt-tr-dragging" : ""} ${task.locked ? "gantt-tr-locked" : ""}`,
1116
+ style: {
1117
+ left: `${displayLeft}px`,
1118
+ width: `${displayWidth}px`,
1119
+ backgroundColor: barColor,
1120
+ height: "var(--gantt-task-bar-height)",
1121
+ cursor: dragHandleProps.style.cursor,
1122
+ userSelect: dragHandleProps.style.userSelect
1123
+ },
1124
+ onMouseDown: dragHandleProps.onMouseDown,
1125
+ children: [
1126
+ progressWidth > 0 && /* @__PURE__ */ jsx2(
1127
+ "div",
1128
+ {
1129
+ className: "gantt-tr-progressBar",
1130
+ style: {
1131
+ width: `${progressWidth}%`,
1132
+ backgroundColor: progressColor
1133
+ }
1124
1134
  }
1125
- }
1126
- ),
1127
- /* @__PURE__ */ jsx2("div", { className: "gantt-tr-resizeHandle gantt-tr-resizeHandleLeft" }),
1128
- /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-taskDuration", children: [
1129
- durationDays,
1130
- " \u0434"
1131
- ] }),
1132
- progressWidth > 0 && showProgressInside && /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-progressText", children: [
1133
- progressWidth,
1134
- "%"
1135
- ] }),
1136
- /* @__PURE__ */ jsx2("div", { className: "gantt-tr-resizeHandle gantt-tr-resizeHandleRight" })
1137
- ]
1138
- }
1139
- ),
1140
- /* @__PURE__ */ jsx2(
1141
- "div",
1142
- {
1143
- className: "gantt-tr-leftLabels",
1144
- style: {
1145
- left: `${displayLeft}px`
1146
- },
1147
- children: /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-dateLabel gantt-tr-dateLabelLeft", children: [
1148
- startDateLabel,
1149
- "\u2013",
1150
- endDateLabel
1151
- ] })
1152
- }
1153
- ),
1154
- /* @__PURE__ */ jsxs2(
1155
- "div",
1156
- {
1157
- className: "gantt-tr-rightLabels",
1158
- style: {
1159
- left: `${displayLeft + displayWidth}px`
1160
- },
1161
- children: [
1162
- progressWidth > 0 && !showProgressInside && /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-externalProgress", children: [
1163
- progressWidth,
1164
- "%"
1165
- ] }),
1166
- /* @__PURE__ */ jsx2("span", { className: "gantt-tr-externalTaskName", children: task.name })
1167
- ]
1168
- }
1169
- )
1170
- ] })
1135
+ ),
1136
+ /* @__PURE__ */ jsx2("div", { className: "gantt-tr-resizeHandle gantt-tr-resizeHandleLeft" }),
1137
+ /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-taskDuration", children: [
1138
+ durationDays,
1139
+ " \u0434"
1140
+ ] }),
1141
+ progressWidth > 0 && showProgressInside && /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-progressText", children: [
1142
+ progressWidth,
1143
+ "%"
1144
+ ] }),
1145
+ /* @__PURE__ */ jsx2("div", { className: "gantt-tr-resizeHandle gantt-tr-resizeHandleRight" })
1146
+ ]
1147
+ }
1148
+ ),
1149
+ /* @__PURE__ */ jsx2(
1150
+ "div",
1151
+ {
1152
+ className: `gantt-tr-leftLabels ${task.locked ? "gantt-tr-leftLabels-locked" : ""}`,
1153
+ style: {
1154
+ left: `${displayLeft}px`
1155
+ },
1156
+ children: /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-dateLabel gantt-tr-dateLabelLeft", children: [
1157
+ startDateLabel,
1158
+ "\u2013",
1159
+ endDateLabel
1160
+ ] })
1161
+ }
1162
+ ),
1163
+ task.locked && /* @__PURE__ */ jsx2(
1164
+ "svg",
1165
+ {
1166
+ className: "gantt-tr-lockIcon",
1167
+ style: {
1168
+ position: "absolute",
1169
+ left: `${displayLeft - 16}px`,
1170
+ top: "50%",
1171
+ transform: "translateY(-50%)",
1172
+ width: "12px",
1173
+ height: "12px",
1174
+ color: "#444",
1175
+ pointerEvents: "none"
1176
+ },
1177
+ viewBox: "0 0 24 24",
1178
+ fill: "currentColor",
1179
+ "aria-label": "Locked",
1180
+ "aria-hidden": "false",
1181
+ children: /* @__PURE__ */ jsx2("path", { d: "M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zM12 17c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z" })
1182
+ }
1183
+ ),
1184
+ /* @__PURE__ */ jsxs2(
1185
+ "div",
1186
+ {
1187
+ className: "gantt-tr-rightLabels",
1188
+ style: {
1189
+ left: `${displayLeft + displayWidth}px`
1190
+ },
1191
+ children: [
1192
+ progressWidth > 0 && !showProgressInside && /* @__PURE__ */ jsxs2("span", { className: "gantt-tr-externalProgress", children: [
1193
+ progressWidth,
1194
+ "%"
1195
+ ] }),
1196
+ /* @__PURE__ */ jsx2("span", { className: "gantt-tr-externalTaskName", children: task.name })
1197
+ ]
1198
+ }
1199
+ )
1200
+ ] }),
1201
+ taskDivider === "bottom" && /* @__PURE__ */ jsx2("div", { className: "gantt-tr-divider gantt-tr-divider-bottom" })
1202
+ ]
1171
1203
  }
1172
1204
  );
1173
1205
  },