gantt-lib 0.1.0 → 0.1.1

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.d.mts CHANGED
@@ -245,7 +245,9 @@ interface GanttChartProps {
245
245
  * />
246
246
  * ```
247
247
  */
248
- declare const GanttChart: React$1.FC<GanttChartProps>;
248
+ declare const GanttChart: React$1.ForwardRefExoticComponent<GanttChartProps & React$1.RefAttributes<{
249
+ scrollToToday: () => void;
250
+ }>>;
249
251
 
250
252
  interface TaskRowProps {
251
253
  /** Task data to render */
package/dist/index.d.ts CHANGED
@@ -245,7 +245,9 @@ interface GanttChartProps {
245
245
  * />
246
246
  * ```
247
247
  */
248
- declare const GanttChart: React$1.FC<GanttChartProps>;
248
+ declare const GanttChart: React$1.ForwardRefExoticComponent<GanttChartProps & React$1.RefAttributes<{
249
+ scrollToToday: () => void;
250
+ }>>;
249
251
 
250
252
  interface TaskRowProps {
251
253
  /** Task data to render */
package/dist/index.js CHANGED
@@ -2095,7 +2095,7 @@ var TaskList = ({
2095
2095
 
2096
2096
  // src/components/GanttChart/GanttChart.tsx
2097
2097
  var import_jsx_runtime13 = require("react/jsx-runtime");
2098
- var GanttChart = ({
2098
+ var GanttChart = (0, import_react12.forwardRef)(({
2099
2099
  tasks,
2100
2100
  dayWidth = 40,
2101
2101
  rowHeight = 40,
@@ -2109,7 +2109,7 @@ var GanttChart = ({
2109
2109
  showTaskList = false,
2110
2110
  taskListWidth = 520,
2111
2111
  disableTaskNameEditing = false
2112
- }) => {
2112
+ }, ref) => {
2113
2113
  const scrollContainerRef = (0, import_react12.useRef)(null);
2114
2114
  const [selectedTaskId, setSelectedTaskId] = (0, import_react12.useState)(null);
2115
2115
  const dateRange = (0, import_react12.useMemo)(() => getMultiMonthDays(tasks), [tasks]);
@@ -2135,6 +2135,37 @@ var GanttChart = ({
2135
2135
  const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2136
2136
  return dateRange.some((day) => day.getTime() === today.getTime());
2137
2137
  }, [dateRange]);
2138
+ (0, import_react12.useEffect)(() => {
2139
+ const container = scrollContainerRef.current;
2140
+ if (!container || dateRange.length === 0) return;
2141
+ const now = /* @__PURE__ */ new Date();
2142
+ const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2143
+ const todayIndex = dateRange.findIndex((day) => day.getTime() === today.getTime());
2144
+ if (todayIndex === -1) return;
2145
+ const todayOffset = todayIndex * dayWidth;
2146
+ const containerWidth = container.clientWidth;
2147
+ const scrollLeft = Math.round(todayOffset - containerWidth / 2 + dayWidth / 2);
2148
+ container.scrollLeft = Math.max(0, scrollLeft);
2149
+ }, []);
2150
+ const scrollToToday = (0, import_react12.useCallback)(() => {
2151
+ const container = scrollContainerRef.current;
2152
+ if (!container || dateRange.length === 0) return;
2153
+ const now = /* @__PURE__ */ new Date();
2154
+ const today = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
2155
+ const todayIndex = dateRange.findIndex((day) => day.getTime() === today.getTime());
2156
+ if (todayIndex === -1) return;
2157
+ const todayOffset = todayIndex * dayWidth;
2158
+ const containerWidth = container.clientWidth;
2159
+ const scrollLeft = Math.round(todayOffset - containerWidth / 2 + dayWidth / 2);
2160
+ container.scrollLeft = Math.max(0, scrollLeft);
2161
+ }, [dateRange, dayWidth]);
2162
+ (0, import_react12.useImperativeHandle)(
2163
+ ref,
2164
+ () => ({
2165
+ scrollToToday
2166
+ }),
2167
+ [scrollToToday]
2168
+ );
2138
2169
  const [dragGuideLines, setDragGuideLines] = (0, import_react12.useState)(null);
2139
2170
  const [draggedTaskOverride, setDraggedTaskOverride] = (0, import_react12.useState)(null);
2140
2171
  (0, import_react12.useEffect)(() => {
@@ -2337,7 +2368,8 @@ var GanttChart = ({
2337
2368
  ] })
2338
2369
  }
2339
2370
  ) });
2340
- };
2371
+ });
2372
+ GanttChart.displayName = "GanttChart";
2341
2373
 
2342
2374
  // src/components/ui/Button.tsx
2343
2375
  var import_react13 = __toESM(require("react"));