gantt-lib 0.88.0 → 0.88.2

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
@@ -449,26 +449,19 @@ function getDependencyLag(dep) {
449
449
  return Number.isFinite(dep.lag) ? dep.lag : 0;
450
450
  }
451
451
  function normalizeTaskDependencyLags(task) {
452
- if (!task.dependencies?.length) {
453
- return task;
454
- }
455
- let changed = false;
456
- const dependencies = task.dependencies.map((dep) => {
457
- const lag = getDependencyLag(dep);
458
- const normalizedLag = dep.type === "FS" ? Math.max(0, lag) : lag;
459
- if (normalizedLag === dep.lag) {
460
- return dep;
461
- }
462
- changed = true;
463
- return { ...dep, lag: normalizedLag };
464
- });
465
- return changed ? { ...task, dependencies } : task;
452
+ return task;
466
453
  }
467
454
  function normalizeDependencyLag(linkType, lag, predecessorStart, predecessorEnd, businessDays = false, weekendPredicate) {
468
455
  if (linkType !== "FS") {
469
456
  return lag;
470
457
  }
471
- return Math.max(0, lag);
458
+ const predecessorDuration = getTaskDuration(
459
+ predecessorStart,
460
+ predecessorEnd,
461
+ businessDays,
462
+ weekendPredicate
463
+ );
464
+ return Math.max(-predecessorDuration, lag);
472
465
  }
473
466
  function computeLagFromDates(linkType, predStart, predEnd, succStart, succEnd, businessDays = false, weekendPredicate) {
474
467
  const pS = Date.UTC(predStart.getUTCFullYear(), predStart.getUTCMonth(), predStart.getUTCDate());
@@ -727,11 +720,17 @@ function clampTaskRangeForIncomingFS(task, proposedStart, proposedEnd, allTasks,
727
720
  continue;
728
721
  }
729
722
  const { predStart: predecessorStart, predEnd: predecessorEnd } = normalizePredecessorDates(predecessor, parseDateOnly);
723
+ const predecessorDuration = getTaskDuration(
724
+ predecessorStart,
725
+ predecessorEnd,
726
+ businessDays,
727
+ weekendPredicate
728
+ );
730
729
  const candidateMinStart = calculateSuccessorDate(
731
730
  predecessorStart,
732
731
  predecessorEnd,
733
732
  "FS",
734
- 0,
733
+ -predecessorDuration,
735
734
  businessDays,
736
735
  weekendPredicate
737
736
  );
@@ -7632,6 +7631,43 @@ var layoutResourceTimelineItems = (resources, options) => {
7632
7631
 
7633
7632
  // src/hooks/useResourceItemDrag.ts
7634
7633
  import { useCallback as useCallback6, useEffect as useEffect7, useRef as useRef7, useState as useState7 } from "react";
7634
+ var RESOURCE_CURSOR_STYLE_ID = "gantt-resource-global-drag-cursor-style";
7635
+ function ensureResourceGlobalCursorStyle() {
7636
+ if (typeof document === "undefined") return;
7637
+ if (document.getElementById(RESOURCE_CURSOR_STYLE_ID)) return;
7638
+ const style = document.createElement("style");
7639
+ style.id = RESOURCE_CURSOR_STYLE_ID;
7640
+ style.textContent = `
7641
+ html.gantt-resource-global-cursor-grabbing,
7642
+ html.gantt-resource-global-cursor-grabbing *,
7643
+ html.gantt-resource-global-cursor-grabbing *::before,
7644
+ html.gantt-resource-global-cursor-grabbing *::after {
7645
+ cursor: grabbing !important;
7646
+ }
7647
+
7648
+ html.gantt-resource-global-cursor-resize,
7649
+ html.gantt-resource-global-cursor-resize *,
7650
+ html.gantt-resource-global-cursor-resize *::before,
7651
+ html.gantt-resource-global-cursor-resize *::after {
7652
+ cursor: ew-resize !important;
7653
+ }
7654
+ `;
7655
+ document.head.appendChild(style);
7656
+ }
7657
+ function applyResourceGlobalCursor(cursor) {
7658
+ if (typeof document === "undefined") return;
7659
+ ensureResourceGlobalCursorStyle();
7660
+ document.documentElement.classList.remove("gantt-resource-global-cursor-grabbing", "gantt-resource-global-cursor-resize");
7661
+ document.documentElement.classList.add(cursor === "grabbing" ? "gantt-resource-global-cursor-grabbing" : "gantt-resource-global-cursor-resize");
7662
+ document.body.style.cursor = cursor;
7663
+ document.documentElement.style.cursor = cursor;
7664
+ }
7665
+ function clearResourceGlobalCursor() {
7666
+ if (typeof document === "undefined") return;
7667
+ document.documentElement.classList.remove("gantt-resource-global-cursor-grabbing", "gantt-resource-global-cursor-resize");
7668
+ document.body.style.cursor = "";
7669
+ document.documentElement.style.cursor = "";
7670
+ }
7635
7671
  var snapToDay = (pixels, dayWidth) => {
7636
7672
  return Math.round(pixels / dayWidth) * dayWidth;
7637
7673
  };
@@ -7697,6 +7733,7 @@ var resolveTargetResource = (rows, clientY, gridTop) => {
7697
7733
  var useResourceItemDrag = ({
7698
7734
  dayWidth,
7699
7735
  monthStart,
7736
+ viewMode = "day",
7700
7737
  rows,
7701
7738
  gridElementRef,
7702
7739
  readonly,
@@ -7724,6 +7761,7 @@ var useResourceItemDrag = ({
7724
7761
  }, []);
7725
7762
  const cancelDrag2 = useCallback6(() => {
7726
7763
  clearRaf();
7764
+ clearResourceGlobalCursor();
7727
7765
  activeDragRef.current = null;
7728
7766
  setPreview(null);
7729
7767
  }, [clearRaf]);
@@ -7772,6 +7810,7 @@ var useResourceItemDrag = ({
7772
7810
  return;
7773
7811
  }
7774
7812
  clearRaf();
7813
+ clearResourceGlobalCursor();
7775
7814
  activeDragRef.current = null;
7776
7815
  setPreview(null);
7777
7816
  const gridTop = gridElementRef?.current?.getBoundingClientRect().top ?? 0;
@@ -7804,8 +7843,10 @@ var useResourceItemDrag = ({
7804
7843
  return;
7805
7844
  }
7806
7845
  const target = event.target;
7807
- const mode = target.closest(".gantt-resourceTimeline-resizeHandleStart") ? "resize-start" : target.closest(".gantt-resourceTimeline-resizeHandleEnd") ? "resize-end" : "move";
7846
+ const isSingleDayItem = viewMode === "day" && layoutItem.width <= dayWidth;
7847
+ const mode = isSingleDayItem ? "move" : target.closest(".gantt-resourceTimeline-resizeHandleStart") ? "resize-start" : target.closest(".gantt-resourceTimeline-resizeHandleEnd") ? "resize-end" : "move";
7808
7848
  event.preventDefault();
7849
+ applyResourceGlobalCursor(mode === "move" ? "grabbing" : "ew-resize");
7809
7850
  activeDragRef.current = {
7810
7851
  item: layoutItem.item,
7811
7852
  itemId: layoutItem.itemId,
@@ -7834,7 +7875,7 @@ var useResourceItemDrag = ({
7834
7875
  startDate: layoutItem.startDate,
7835
7876
  endDate: layoutItem.endDate
7836
7877
  });
7837
- }, [businessDays, dayWidth, monthStart, readonly, weekendPredicate]);
7878
+ }, [businessDays, dayWidth, monthStart, readonly, weekendPredicate, viewMode]);
7838
7879
  return {
7839
7880
  preview,
7840
7881
  startDrag,
@@ -8595,6 +8636,7 @@ function ResourceTimelineChart({
8595
8636
  const { preview, startDrag } = useResourceItemDrag({
8596
8637
  dayWidth,
8597
8638
  monthStart,
8639
+ viewMode,
8598
8640
  rows: displayLayout.rows,
8599
8641
  gridElementRef: gridRef,
8600
8642
  readonly,
@@ -8910,10 +8952,12 @@ function ResourceTimelineChart({
8910
8952
  (resourceItems) => resourceItems.map((layoutItem) => {
8911
8953
  const customClassName = getItemClassName?.(layoutItem.item);
8912
8954
  const isDraggingItem = preview?.itemId === layoutItem.itemId;
8955
+ const isSingleDayMoveOnlyItem = viewMode === "day" && layoutItem.width <= dayWidth;
8913
8956
  const hasItemMenu = Boolean(onResourceItemMenuClick);
8914
8957
  const isActiveItem = activeResourceItemId === layoutItem.itemId;
8915
8958
  const className = [
8916
8959
  "gantt-resourceTimeline-item",
8960
+ isSingleDayMoveOnlyItem && "gantt-resourceTimeline-itemMoveOnly",
8917
8961
  hasItemMenu && "gantt-resourceTimeline-itemHasMenu",
8918
8962
  isActiveItem && "gantt-resourceTimeline-itemActive",
8919
8963
  isDraggingItem && "gantt-resourceTimeline-itemDragging",