gantt-lib 0.1.0 → 0.1.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
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/components/GanttChart/GanttChart.tsx
4
- import { useMemo as useMemo8, useCallback as useCallback6, useRef as useRef4, useState as useState5, useEffect as useEffect4 } from "react";
4
+ import { useMemo as useMemo8, useCallback as useCallback6, useRef as useRef4, useState as useState5, useEffect as useEffect4, useImperativeHandle, forwardRef } from "react";
5
5
 
6
6
  // src/utils/dateUtils.ts
7
7
  var parseUTCDate = (date) => {
@@ -1277,15 +1277,11 @@ var TodayIndicator = ({ monthStart, dayWidth }) => {
1277
1277
  today.getMonth(),
1278
1278
  today.getDate()
1279
1279
  ));
1280
- const isInMonth = useMemo3(() => {
1281
- return todayLocal.getUTCFullYear() === monthStart.getUTCFullYear() && todayLocal.getUTCMonth() === monthStart.getUTCMonth();
1282
- }, [monthStart, todayLocal]);
1283
1280
  const position = useMemo3(() => {
1284
- if (!isInMonth) return null;
1285
1281
  const offset = getDayOffset(todayLocal, monthStart);
1286
1282
  return Math.round(offset * dayWidth);
1287
- }, [isInMonth, monthStart, dayWidth, todayLocal]);
1288
- if (!isInMonth || position === null) {
1283
+ }, [monthStart, dayWidth, todayLocal]);
1284
+ if (isNaN(position)) {
1289
1285
  return null;
1290
1286
  }
1291
1287
  return /* @__PURE__ */ jsx3(
@@ -1654,7 +1650,7 @@ import {
1654
1650
  subMonths,
1655
1651
  isSameDay,
1656
1652
  getDay,
1657
- isToday as isToday3,
1653
+ isToday as isToday2,
1658
1654
  isWeekend as isWeekend2,
1659
1655
  isBefore,
1660
1656
  startOfDay
@@ -1664,9 +1660,9 @@ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1664
1660
  function getDayClassName(day, selected) {
1665
1661
  const classes = ["gantt-day-btn"];
1666
1662
  if (selected && isSameDay(day, selected)) classes.push("selected");
1667
- if (isToday3(day)) classes.push("today");
1663
+ if (isToday2(day)) classes.push("today");
1668
1664
  if (isWeekend2(day)) classes.push("weekend");
1669
- if (isBefore(day, startOfDay(/* @__PURE__ */ new Date())) && !isToday3(day)) classes.push("past");
1665
+ if (isBefore(day, startOfDay(/* @__PURE__ */ new Date())) && !isToday2(day)) classes.push("past");
1670
1666
  return classes.join(" ");
1671
1667
  }
1672
1668
  var Calendar = ({
@@ -2037,12 +2033,12 @@ var TaskList = ({
2037
2033
 
2038
2034
  // src/components/GanttChart/GanttChart.tsx
2039
2035
  import { jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
2040
- var GanttChart = ({
2036
+ var GanttChart = forwardRef(({
2041
2037
  tasks,
2042
2038
  dayWidth = 40,
2043
2039
  rowHeight = 40,
2044
2040
  headerHeight = 40,
2045
- containerHeight = 600,
2041
+ containerHeight,
2046
2042
  onChange,
2047
2043
  onValidateDependencies,
2048
2044
  enableAutoSchedule,
@@ -2051,7 +2047,7 @@ var GanttChart = ({
2051
2047
  showTaskList = false,
2052
2048
  taskListWidth = 520,
2053
2049
  disableTaskNameEditing = false
2054
- }) => {
2050
+ }, ref) => {
2055
2051
  const scrollContainerRef = useRef4(null);
2056
2052
  const [selectedTaskId, setSelectedTaskId] = useState5(null);
2057
2053
  const dateRange = useMemo8(() => getMultiMonthDays(tasks), [tasks]);
@@ -2077,6 +2073,37 @@ var GanttChart = ({
2077
2073
  const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2078
2074
  return dateRange.some((day) => day.getTime() === today.getTime());
2079
2075
  }, [dateRange]);
2076
+ useEffect4(() => {
2077
+ const container = scrollContainerRef.current;
2078
+ if (!container || dateRange.length === 0) return;
2079
+ const now = /* @__PURE__ */ new Date();
2080
+ const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2081
+ const todayIndex = dateRange.findIndex((day) => day.getTime() === today.getTime());
2082
+ if (todayIndex === -1) return;
2083
+ const todayOffset = todayIndex * dayWidth;
2084
+ const containerWidth = container.clientWidth;
2085
+ const scrollLeft = Math.round(todayOffset - containerWidth / 2 + dayWidth / 2);
2086
+ container.scrollLeft = Math.max(0, scrollLeft);
2087
+ }, []);
2088
+ const scrollToToday = useCallback6(() => {
2089
+ const container = scrollContainerRef.current;
2090
+ if (!container || dateRange.length === 0) return;
2091
+ const now = /* @__PURE__ */ new Date();
2092
+ const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2093
+ const todayIndex = dateRange.findIndex((day) => day.getTime() === today.getTime());
2094
+ if (todayIndex === -1) return;
2095
+ const todayOffset = todayIndex * dayWidth;
2096
+ const containerWidth = container.clientWidth;
2097
+ const scrollLeft = Math.round(todayOffset - containerWidth / 2 + dayWidth / 2);
2098
+ container.scrollLeft = Math.max(0, scrollLeft);
2099
+ }, [dateRange, dayWidth]);
2100
+ useImperativeHandle(
2101
+ ref,
2102
+ () => ({
2103
+ scrollToToday
2104
+ }),
2105
+ [scrollToToday]
2106
+ );
2080
2107
  const [dragGuideLines, setDragGuideLines] = useState5(null);
2081
2108
  const [draggedTaskOverride, setDraggedTaskOverride] = useState5(null);
2082
2109
  useEffect4(() => {
@@ -2180,7 +2207,7 @@ var GanttChart = ({
2180
2207
  {
2181
2208
  ref: scrollContainerRef,
2182
2209
  className: "gantt-scrollContainer",
2183
- style: { height: `${containerHeight}px`, cursor: "grab" },
2210
+ style: { height: containerHeight ?? "auto", cursor: "grab" },
2184
2211
  onMouseDown: handlePanStart,
2185
2212
  children: /* @__PURE__ */ jsxs10("div", { className: "gantt-scrollContent", children: [
2186
2213
  /* @__PURE__ */ jsx13(
@@ -2279,7 +2306,8 @@ var GanttChart = ({
2279
2306
  ] })
2280
2307
  }
2281
2308
  ) });
2282
- };
2309
+ });
2310
+ GanttChart.displayName = "GanttChart";
2283
2311
 
2284
2312
  // src/components/ui/Button.tsx
2285
2313
  import React12 from "react";