gantt-lib 0.121.0 → 0.121.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
@@ -10701,12 +10701,38 @@ function areRangeBoundsEqual(left, right) {
10701
10701
  if (!left || !right) return false;
10702
10702
  return left.fromDateIndex === right.fromDateIndex && left.toDateIndex === right.toDateIndex && left.fromSubrowIndex === right.fromSubrowIndex && left.toSubrowIndex === right.toSubrowIndex;
10703
10703
  }
10704
+ function getRenderedDateWindow(dateRange, renderedDateIndices) {
10705
+ if (dateRange.length === 0 || renderedDateIndices.length === 0) {
10706
+ return {
10707
+ startIndex: 0,
10708
+ days: []
10709
+ };
10710
+ }
10711
+ let startIndex = dateRange.length - 1;
10712
+ let endIndex = 0;
10713
+ for (const dateIndex of renderedDateIndices) {
10714
+ if (dateIndex < 0 || dateIndex >= dateRange.length) continue;
10715
+ startIndex = Math.min(startIndex, dateIndex);
10716
+ endIndex = Math.max(endIndex, dateIndex);
10717
+ }
10718
+ if (startIndex > endIndex) {
10719
+ return {
10720
+ startIndex: 0,
10721
+ days: []
10722
+ };
10723
+ }
10724
+ return {
10725
+ startIndex,
10726
+ days: dateRange.slice(startIndex, endIndex + 1)
10727
+ };
10728
+ }
10704
10729
  function PlanFactRowInner({
10705
10730
  task,
10706
10731
  rowIndex,
10707
10732
  dateRange,
10708
10733
  dateKeys,
10709
10734
  renderedDateIndices,
10735
+ totalWidth,
10710
10736
  rowHeight,
10711
10737
  subrowHeight,
10712
10738
  dayWidth,
@@ -10749,8 +10775,8 @@ function PlanFactRowInner({
10749
10775
  ),
10750
10776
  style: {
10751
10777
  top: `${rowIndex * rowHeight}px`,
10778
+ width: `${totalWidth}px`,
10752
10779
  height: `${rowHeight}px`,
10753
- gridTemplateColumns: `repeat(${dateRange.length}, ${dayWidth}px)`,
10754
10780
  ["--gantt-pf-today-left"]: todayDateIndex !== void 0 && todayDateIndex >= 0 ? `${todayDateIndex * dayWidth}px` : void 0
10755
10781
  },
10756
10782
  onClick: () => onTaskSelect?.(task.id),
@@ -10799,8 +10825,9 @@ function PlanFactRowInner({
10799
10825
  isParent && "gantt-pf-cell-readonly"
10800
10826
  ),
10801
10827
  style: {
10802
- gridColumn: dateIndex + 1,
10803
- gridRow: kind === "plan" ? 1 : 2,
10828
+ left: `${dateIndex * dayWidth}px`,
10829
+ top: kind === "plan" ? 0 : `${subrowHeight}px`,
10830
+ width: `${dayWidth}px`,
10804
10831
  height: `${subrowHeight}px`
10805
10832
  },
10806
10833
  tabIndex: isParent ? -1 : 0,
@@ -10937,7 +10964,7 @@ function PlanFactRowInner({
10937
10964
  function arePlanFactRowsEqual(previous, next) {
10938
10965
  const previousRangeTouchesRow = doesRangeTouchRow(previous.renderedRangeBounds, previous.rowIndex);
10939
10966
  const nextRangeTouchesRow = doesRangeTouchRow(next.renderedRangeBounds, next.rowIndex);
10940
- return previous.task === next.task && previous.rowIndex === next.rowIndex && previous.dateRange === next.dateRange && previous.dateKeys === next.dateKeys && previous.renderedDateIndices === next.renderedDateIndices && previous.rowHeight === next.rowHeight && previous.subrowHeight === next.subrowHeight && previous.dayWidth === next.dayWidth && previous.plannedRange === next.plannedRange && previous.todayDateIndex === next.todayDateIndex && previous.isParent === next.isParent && previous.isHighlighted === next.isHighlighted && previous.selectedTaskId === previous.task.id === (next.selectedTaskId === next.task.id) && getCellSignatureForTask(previous.activeCell, previous.task.id) === getCellSignatureForTask(next.activeCell, next.task.id) && getEditingCellSignatureForTask(previous.editingCell, previous.task.id) === getEditingCellSignatureForTask(next.editingCell, next.task.id) && getRangeAnchorSignatureForTask(previous.selectedRange, previous.task.id) === getRangeAnchorSignatureForTask(next.selectedRange, next.task.id) && previousRangeTouchesRow === nextRangeTouchesRow && (!nextRangeTouchesRow || areRangeBoundsEqual(previous.renderedRangeBounds, next.renderedRangeBounds));
10967
+ return previous.task === next.task && previous.rowIndex === next.rowIndex && previous.dateRange === next.dateRange && previous.dateKeys === next.dateKeys && previous.renderedDateIndices === next.renderedDateIndices && previous.totalWidth === next.totalWidth && previous.rowHeight === next.rowHeight && previous.subrowHeight === next.subrowHeight && previous.dayWidth === next.dayWidth && previous.plannedRange === next.plannedRange && previous.todayDateIndex === next.todayDateIndex && previous.isParent === next.isParent && previous.isHighlighted === next.isHighlighted && previous.selectedTaskId === previous.task.id === (next.selectedTaskId === next.task.id) && getCellSignatureForTask(previous.activeCell, previous.task.id) === getCellSignatureForTask(next.activeCell, next.task.id) && getEditingCellSignatureForTask(previous.editingCell, previous.task.id) === getEditingCellSignatureForTask(next.editingCell, next.task.id) && getRangeAnchorSignatureForTask(previous.selectedRange, previous.task.id) === getRangeAnchorSignatureForTask(next.selectedRange, next.task.id) && previousRangeTouchesRow === nextRangeTouchesRow && (!nextRangeTouchesRow || areRangeBoundsEqual(previous.renderedRangeBounds, next.renderedRangeBounds));
10941
10968
  }
10942
10969
  var PlanFactRow = React15.memo(PlanFactRowInner, arePlanFactRowsEqual);
10943
10970
  function PlanFactMatrix({
@@ -10989,6 +11016,10 @@ function PlanFactMatrix({
10989
11016
  return ids;
10990
11017
  }, [allTasks]);
10991
11018
  const dateKeys = useMemo12(() => dateRange.map(formatDateKey), [dateRange]);
11019
+ const renderedDateWindow = useMemo12(
11020
+ () => getRenderedDateWindow(dateRange, renderedDateIndices),
11021
+ [dateRange, renderedDateIndices]
11022
+ );
10992
11023
  const dateRangeStartMs = dateRange[0] ? getDateOnlyMs(dateRange[0]) : 0;
10993
11024
  const taskIndexById = useMemo12(() => {
10994
11025
  const indexById = /* @__PURE__ */ new Map();
@@ -11431,16 +11462,26 @@ function PlanFactMatrix({
11431
11462
  children: [
11432
11463
  /* @__PURE__ */ jsxs14("div", { className: "gantt-pf-header", style: { width: `${totalWidth}px`, height: `${headerHeight}px` }, children: [
11433
11464
  /* @__PURE__ */ jsx18(
11434
- TimeScaleHeader_default,
11465
+ "div",
11435
11466
  {
11436
- days: dateRange,
11437
- dayWidth,
11438
- headerHeight: headerHeight - 1,
11439
- viewMode: "day",
11440
- isCustomWeekend
11467
+ className: "gantt-pf-dateWindow",
11468
+ style: {
11469
+ left: `${renderedDateWindow.startIndex * dayWidth}px`,
11470
+ width: `${renderedDateWindow.days.length * dayWidth}px`
11471
+ },
11472
+ children: /* @__PURE__ */ jsx18(
11473
+ TimeScaleHeader_default,
11474
+ {
11475
+ days: renderedDateWindow.days,
11476
+ dayWidth,
11477
+ headerHeight: headerHeight - 1,
11478
+ viewMode: "day",
11479
+ isCustomWeekend
11480
+ }
11481
+ )
11441
11482
  }
11442
11483
  ),
11443
- todayDateIndex !== void 0 && todayDateIndex >= 0 && /* @__PURE__ */ jsx18(
11484
+ todayDateIndex !== void 0 && todayDateIndex >= renderedDateWindow.startIndex && todayDateIndex < renderedDateWindow.startIndex + renderedDateWindow.days.length && /* @__PURE__ */ jsx18(
11444
11485
  "span",
11445
11486
  {
11446
11487
  className: "gantt-pf-headerTodayLine",
@@ -11475,14 +11516,24 @@ function PlanFactMatrix({
11475
11516
  },
11476
11517
  children: [
11477
11518
  /* @__PURE__ */ jsx18(
11478
- GridBackground_default,
11519
+ "div",
11479
11520
  {
11480
- dateRange,
11481
- dayWidth,
11482
- totalHeight: tasks.length * rowHeight,
11483
- viewMode: "day",
11484
- isCustomWeekend,
11485
- showGridLines: false
11521
+ className: "gantt-pf-dateWindow gantt-pf-dateWindow-body",
11522
+ style: {
11523
+ left: `${renderedDateWindow.startIndex * dayWidth}px`,
11524
+ width: `${renderedDateWindow.days.length * dayWidth}px`
11525
+ },
11526
+ children: /* @__PURE__ */ jsx18(
11527
+ GridBackground_default,
11528
+ {
11529
+ dateRange: renderedDateWindow.days,
11530
+ dayWidth,
11531
+ totalHeight: tasks.length * rowHeight,
11532
+ viewMode: "day",
11533
+ isCustomWeekend,
11534
+ showGridLines: false
11535
+ }
11536
+ )
11486
11537
  }
11487
11538
  ),
11488
11539
  renderedRowIndices.map((rowIndex) => {
@@ -11498,6 +11549,7 @@ function PlanFactMatrix({
11498
11549
  dateRange,
11499
11550
  dateKeys,
11500
11551
  renderedDateIndices,
11552
+ totalWidth,
11501
11553
  rowHeight,
11502
11554
  subrowHeight,
11503
11555
  dayWidth,
@@ -11965,6 +12017,8 @@ var SCROLL_TO_ROW_CONTEXT_ROWS = 2;
11965
12017
  var TASK_ROW_OVERSCAN = 8;
11966
12018
  var PLAN_FACT_COLUMN_OVERSCAN = 24;
11967
12019
  var PLAN_FACT_COLUMN_WINDOW_STEP = 14;
12020
+ var DEFAULT_INITIAL_VIEWPORT_HEIGHT = 768;
12021
+ var DEFAULT_PLAN_FACT_COLUMN_WINDOW = PLAN_FACT_COLUMN_OVERSCAN + PLAN_FACT_COLUMN_WINDOW_STEP;
11968
12022
  function getInitialScrollViewportHeight(containerHeight, headerHeight) {
11969
12023
  if (containerHeight === void 0) {
11970
12024
  return 0;
@@ -11972,18 +12026,15 @@ function getInitialScrollViewportHeight(containerHeight, headerHeight) {
11972
12026
  if (typeof containerHeight === "number") {
11973
12027
  return Math.max(0, containerHeight - headerHeight);
11974
12028
  }
11975
- if (typeof window === "undefined") {
11976
- return 0;
11977
- }
11978
12029
  const dynamicViewportMatch = containerHeight.match(/^([\d.]+)dvh$/);
11979
12030
  if (dynamicViewportMatch) {
11980
12031
  const ratio = Number(dynamicViewportMatch[1]);
11981
- return Number.isFinite(ratio) ? Math.max(0, window.innerHeight * (ratio / 100) - headerHeight) : 0;
12032
+ return Number.isFinite(ratio) ? Math.max(0, DEFAULT_INITIAL_VIEWPORT_HEIGHT * (ratio / 100) - headerHeight) : 0;
11982
12033
  }
11983
12034
  const viewportMatch = containerHeight.match(/^([\d.]+)vh$/);
11984
12035
  if (viewportMatch) {
11985
12036
  const ratio = Number(viewportMatch[1]);
11986
- return Number.isFinite(ratio) ? Math.max(0, window.innerHeight * (ratio / 100) - headerHeight) : 0;
12037
+ return Number.isFinite(ratio) ? Math.max(0, DEFAULT_INITIAL_VIEWPORT_HEIGHT * (ratio / 100) - headerHeight) : 0;
11987
12038
  }
11988
12039
  const pixelMatch = containerHeight.match(/^([\d.]+)px$/);
11989
12040
  if (pixelMatch) {
@@ -12180,7 +12231,7 @@ function TaskGanttChartInner(props, ref) {
12180
12231
  viewportHeight: getInitialScrollViewportHeight(containerHeight, headerHeight + 1)
12181
12232
  }));
12182
12233
  const [forceFullRenderForPrint, setForceFullRenderForPrint] = useState11(false);
12183
- const [planFactDateWindow, setPlanFactDateWindow] = useState11(null);
12234
+ const [planFactDateWindow, setPlanFactDateWindow] = useState11({ start: 0, end: 0 });
12184
12235
  const [selectedChip, setSelectedChip] = useState11(null);
12185
12236
  const [activeTimelineTooltip, setActiveTimelineTooltip] = useState11(null);
12186
12237
  const [internalCollapsedParentIds, setInternalCollapsedParentIds] = useState11(/* @__PURE__ */ new Set());
@@ -12331,7 +12382,7 @@ function TaskGanttChartInner(props, ref) {
12331
12382
  );
12332
12383
  setPlanFactDateWindow((previous) => {
12333
12384
  if (!isPlanFactMode || dateRange.length === 0 || nextViewportWidth <= 0) {
12334
- return previous === null ? previous : null;
12385
+ return previous;
12335
12386
  }
12336
12387
  const firstVisibleColumn = Math.max(0, Math.floor(nextChartScrollLeft / dayWidth));
12337
12388
  const visibleColumnCount = Math.max(1, Math.ceil(nextViewportWidth / dayWidth));
@@ -12621,12 +12672,13 @@ function TaskGanttChartInner(props, ref) {
12621
12672
  if (forceFullRenderForPrint) {
12622
12673
  return void 0;
12623
12674
  }
12624
- if (!isPlanFactMode || dateRange.length === 0 || !planFactDateWindow) {
12675
+ if (!isPlanFactMode || dateRange.length === 0) {
12625
12676
  return void 0;
12626
12677
  }
12678
+ const window2 = planFactDateWindow;
12627
12679
  return Array.from(
12628
- { length: planFactDateWindow.end - planFactDateWindow.start + 1 },
12629
- (_, index) => planFactDateWindow.start + index
12680
+ { length: window2.end - window2.start + 1 },
12681
+ (_, index) => window2.start + index
12630
12682
  );
12631
12683
  }, [dateRange.length, forceFullRenderForPrint, isPlanFactMode, planFactDateWindow]);
12632
12684
  const renderedChartTasks = useMemo13(