gantt-lib 0.113.1 → 0.114.0

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
@@ -414,8 +414,9 @@ interface PlanFactMatrixProps<TTask extends Task = Task> {
414
414
  visibleRowIndices?: number[];
415
415
  visibleDateIndices?: number[];
416
416
  todayDateIndex?: number;
417
+ isCustomWeekend?: (date: Date) => boolean;
417
418
  }
418
- declare function PlanFactMatrix<TTask extends Task = Task>({ tasks, allTasks, dateRange, dayWidth, rowHeight, headerHeight, bodyMinHeight, selectedTaskId, onTaskSelect, onTasksChange, onCellCommit, highlightedTaskIds, filterMode, visibleRowIndices, visibleDateIndices, todayDateIndex, }: PlanFactMatrixProps<TTask>): react_jsx_runtime.JSX.Element;
419
+ declare function PlanFactMatrix<TTask extends Task = Task>({ tasks, allTasks, dateRange, dayWidth, rowHeight, headerHeight, bodyMinHeight, selectedTaskId, onTaskSelect, onTasksChange, onCellCommit, highlightedTaskIds, filterMode, visibleRowIndices, visibleDateIndices, todayDateIndex, isCustomWeekend, }: PlanFactMatrixProps<TTask>): react_jsx_runtime.JSX.Element;
419
420
 
420
421
  /**
421
422
  * Task data structure for Gantt chart
package/dist/index.d.ts CHANGED
@@ -414,8 +414,9 @@ interface PlanFactMatrixProps<TTask extends Task = Task> {
414
414
  visibleRowIndices?: number[];
415
415
  visibleDateIndices?: number[];
416
416
  todayDateIndex?: number;
417
+ isCustomWeekend?: (date: Date) => boolean;
417
418
  }
418
- declare function PlanFactMatrix<TTask extends Task = Task>({ tasks, allTasks, dateRange, dayWidth, rowHeight, headerHeight, bodyMinHeight, selectedTaskId, onTaskSelect, onTasksChange, onCellCommit, highlightedTaskIds, filterMode, visibleRowIndices, visibleDateIndices, todayDateIndex, }: PlanFactMatrixProps<TTask>): react_jsx_runtime.JSX.Element;
419
+ declare function PlanFactMatrix<TTask extends Task = Task>({ tasks, allTasks, dateRange, dayWidth, rowHeight, headerHeight, bodyMinHeight, selectedTaskId, onTaskSelect, onTasksChange, onCellCommit, highlightedTaskIds, filterMode, visibleRowIndices, visibleDateIndices, todayDateIndex, isCustomWeekend, }: PlanFactMatrixProps<TTask>): react_jsx_runtime.JSX.Element;
419
420
 
420
421
  /**
421
422
  * Task data structure for Gantt chart
package/dist/index.js CHANGED
@@ -10979,7 +10979,8 @@ function PlanFactMatrix({
10979
10979
  filterMode = "highlight",
10980
10980
  visibleRowIndices,
10981
10981
  visibleDateIndices,
10982
- todayDateIndex
10982
+ todayDateIndex,
10983
+ isCustomWeekend
10983
10984
  }) {
10984
10985
  const [activeCell, setActiveCell] = (0, import_react17.useState)(null);
10985
10986
  const [editingCell, setEditingCell] = (0, import_react17.useState)(null);
@@ -11458,7 +11459,8 @@ function PlanFactMatrix({
11458
11459
  days: dateRange,
11459
11460
  dayWidth,
11460
11461
  headerHeight: headerHeight - 1,
11461
- viewMode: "day"
11462
+ viewMode: "day",
11463
+ isCustomWeekend
11462
11464
  }
11463
11465
  ),
11464
11466
  todayDateIndex !== void 0 && todayDateIndex >= 0 && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
@@ -11484,7 +11486,7 @@ function PlanFactMatrix({
11484
11486
  },
11485
11487
  `month-separator-${dateIndex}`
11486
11488
  )) }),
11487
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
11489
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
11488
11490
  "div",
11489
11491
  {
11490
11492
  ref: bodyRef,
@@ -11494,52 +11496,65 @@ function PlanFactMatrix({
11494
11496
  minHeight: bodyMinHeight,
11495
11497
  width: `${totalWidth}px`
11496
11498
  },
11497
- children: renderedRowIndices.map((rowIndex) => {
11498
- const task = tasks[rowIndex];
11499
- if (!task) return null;
11500
- const isParent = parentTaskIds.has(task.id);
11501
- const isHighlighted = filterMode === "highlight" && !!highlightedTaskIds?.has(task.id);
11502
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
11503
- PlanFactRow,
11499
+ children: [
11500
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
11501
+ GridBackground_default,
11504
11502
  {
11505
- task,
11506
- rowIndex,
11507
11503
  dateRange,
11508
- dateKeys,
11509
- renderedDateIndices,
11510
- rowHeight,
11511
- subrowHeight,
11512
11504
  dayWidth,
11513
- plannedRange: plannedRangeByTaskId.get(task.id) ?? null,
11514
- todayDateIndex,
11515
- isParent,
11516
- isHighlighted,
11517
- selectedTaskId,
11518
- activeCell,
11519
- editingCell,
11520
- selectedRange,
11521
- renderedRangeBounds,
11522
- didDragSelectRef,
11523
- isSelectingRef,
11524
- isFillDraggingRef,
11525
- onTaskSelect,
11526
- selectSingleCell,
11527
- queueHoverCellUpdate,
11528
- setActiveCell,
11529
- setEditingCell,
11530
- setFillRange,
11531
- clearSelectedCells,
11532
- commitCell,
11533
- commitSelectedCells,
11534
- moveActiveCell,
11535
- extendSelectedRange,
11536
- focusCell,
11537
- showOverflowTooltip,
11538
- hideOverflowTooltip
11539
- },
11540
- task.id
11541
- );
11542
- })
11505
+ totalHeight: tasks.length * rowHeight,
11506
+ viewMode: "day",
11507
+ isCustomWeekend,
11508
+ showGridLines: false
11509
+ }
11510
+ ),
11511
+ renderedRowIndices.map((rowIndex) => {
11512
+ const task = tasks[rowIndex];
11513
+ if (!task) return null;
11514
+ const isParent = parentTaskIds.has(task.id);
11515
+ const isHighlighted = filterMode === "highlight" && !!highlightedTaskIds?.has(task.id);
11516
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
11517
+ PlanFactRow,
11518
+ {
11519
+ task,
11520
+ rowIndex,
11521
+ dateRange,
11522
+ dateKeys,
11523
+ renderedDateIndices,
11524
+ rowHeight,
11525
+ subrowHeight,
11526
+ dayWidth,
11527
+ plannedRange: plannedRangeByTaskId.get(task.id) ?? null,
11528
+ todayDateIndex,
11529
+ isParent,
11530
+ isHighlighted,
11531
+ selectedTaskId,
11532
+ activeCell,
11533
+ editingCell,
11534
+ selectedRange,
11535
+ renderedRangeBounds,
11536
+ didDragSelectRef,
11537
+ isSelectingRef,
11538
+ isFillDraggingRef,
11539
+ onTaskSelect,
11540
+ selectSingleCell,
11541
+ queueHoverCellUpdate,
11542
+ setActiveCell,
11543
+ setEditingCell,
11544
+ setFillRange,
11545
+ clearSelectedCells,
11546
+ commitCell,
11547
+ commitSelectedCells,
11548
+ moveActiveCell,
11549
+ extendSelectedRange,
11550
+ focusCell,
11551
+ showOverflowTooltip,
11552
+ hideOverflowTooltip
11553
+ },
11554
+ task.id
11555
+ );
11556
+ })
11557
+ ]
11543
11558
  }
11544
11559
  ),
11545
11560
  overflowTooltip && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
@@ -11973,6 +11988,17 @@ var SCROLL_TO_ROW_CONTEXT_ROWS = 2;
11973
11988
  var TASK_ROW_OVERSCAN = 8;
11974
11989
  var PLAN_FACT_COLUMN_OVERSCAN = 24;
11975
11990
  var PLAN_FACT_COLUMN_WINDOW_STEP = 14;
11991
+ function waitForNextPaint2(win) {
11992
+ return new Promise((resolve) => {
11993
+ if (typeof win.requestAnimationFrame === "function") {
11994
+ win.requestAnimationFrame(() => {
11995
+ win.requestAnimationFrame(() => resolve());
11996
+ });
11997
+ return;
11998
+ }
11999
+ win.setTimeout(() => resolve(), 50);
12000
+ });
12001
+ }
11976
12002
  function getFullMonthDays(tasks) {
11977
12003
  if (!tasks || tasks.length === 0) {
11978
12004
  return getMultiMonthDays(tasks);
@@ -12121,9 +12147,9 @@ function TaskGanttChartInner(props, ref) {
12121
12147
  } = props;
12122
12148
  const dayWidth = !isTableMatrixMode ? props.dayWidth ?? 40 : 40;
12123
12149
  const viewMode = !isTableMatrixMode && !isPlanFactMode ? props.viewMode ?? "day" : "day";
12124
- const customDays = !isTableMatrixMode && !isPlanFactMode ? props.customDays : void 0;
12125
- const isWeekend3 = !isTableMatrixMode && !isPlanFactMode ? props.isWeekend : void 0;
12126
- const businessDays = !isTableMatrixMode && !isPlanFactMode ? props.businessDays ?? true : true;
12150
+ const customDays = !isTableMatrixMode ? props.customDays : void 0;
12151
+ const isWeekend3 = !isTableMatrixMode ? props.isWeekend : void 0;
12152
+ const businessDays = !isTableMatrixMode ? props.businessDays ?? true : true;
12127
12153
  const matrixColumns = isTableMatrixMode ? props.matrixColumns : [];
12128
12154
  const matrixColumnGroups = isTableMatrixMode ? props.matrixColumnGroups : void 0;
12129
12155
  const onMatrixCellClick = isTableMatrixMode ? props.onMatrixCellClick : void 0;
@@ -12144,6 +12170,7 @@ function TaskGanttChartInner(props, ref) {
12144
12170
  const [taskListHasRightShadow, setTaskListHasRightShadow] = (0, import_react18.useState)(false);
12145
12171
  const [internalTaskDateChangeMode, setInternalTaskDateChangeMode] = (0, import_react18.useState)("preserve-duration");
12146
12172
  const [scrollViewport, setScrollViewport] = (0, import_react18.useState)({ scrollTop: 0, viewportHeight: 0 });
12173
+ const [forceFullRenderForPrint, setForceFullRenderForPrint] = (0, import_react18.useState)(false);
12147
12174
  const [planFactDateWindow, setPlanFactDateWindow] = (0, import_react18.useState)(null);
12148
12175
  const [selectedChip, setSelectedChip] = (0, import_react18.useState)(null);
12149
12176
  const [activeTimelineTooltip, setActiveTimelineTooltip] = (0, import_react18.useState)(null);
@@ -12555,6 +12582,9 @@ function TaskGanttChartInner(props, ref) {
12555
12582
  if (totalTasks === 0) {
12556
12583
  return [];
12557
12584
  }
12585
+ if (forceFullRenderForPrint) {
12586
+ return Array.from({ length: totalTasks }, (_, index) => index);
12587
+ }
12558
12588
  if (scrollViewport.viewportHeight <= 0) {
12559
12589
  return Array.from({ length: totalTasks }, (_, index) => index);
12560
12590
  }
@@ -12575,8 +12605,11 @@ function TaskGanttChartInner(props, ref) {
12575
12605
  }
12576
12606
  }
12577
12607
  return Array.from(indices).sort((left, right) => left - right);
12578
- }, [effectiveRowHeight, forcedRenderedTaskIds, scrollViewport, visibleTaskIndexMap, visibleTasks.length]);
12608
+ }, [effectiveRowHeight, forceFullRenderForPrint, forcedRenderedTaskIds, scrollViewport, visibleTaskIndexMap, visibleTasks.length]);
12579
12609
  const visiblePlanFactDateIndices = (0, import_react18.useMemo)(() => {
12610
+ if (forceFullRenderForPrint) {
12611
+ return void 0;
12612
+ }
12580
12613
  if (!isPlanFactMode || dateRange.length === 0 || !planFactDateWindow) {
12581
12614
  return void 0;
12582
12615
  }
@@ -12584,7 +12617,7 @@ function TaskGanttChartInner(props, ref) {
12584
12617
  { length: planFactDateWindow.end - planFactDateWindow.start + 1 },
12585
12618
  (_, index) => planFactDateWindow.start + index
12586
12619
  );
12587
- }, [dateRange.length, isPlanFactMode, planFactDateWindow]);
12620
+ }, [dateRange.length, forceFullRenderForPrint, isPlanFactMode, planFactDateWindow]);
12588
12621
  const renderedChartTasks = (0, import_react18.useMemo)(
12589
12622
  () => visibleTaskWindowIndices.map((index) => {
12590
12623
  const task = previewVisibleTasks[index];
@@ -12672,8 +12705,7 @@ function TaskGanttChartInner(props, ref) {
12672
12705
  }, [externalCollapsedParentIds]);
12673
12706
  const exportToPdf = (0, import_react18.useCallback)(async (options) => {
12674
12707
  const sourceContainer = containerRef.current;
12675
- const sourceContent = scrollContentRef.current;
12676
- if (!sourceContainer || !sourceContent || typeof window === "undefined" || typeof document === "undefined") {
12708
+ if (!sourceContainer || typeof window === "undefined" || typeof document === "undefined") {
12677
12709
  return;
12678
12710
  }
12679
12711
  const includeTaskList = options?.includeTaskList ?? showTaskList;
@@ -12681,31 +12713,46 @@ function TaskGanttChartInner(props, ref) {
12681
12713
  if (!includeTaskList && !includeChart) {
12682
12714
  return;
12683
12715
  }
12684
- const printContent = sourceContent.cloneNode(true);
12685
- const taskListClone = printContent.querySelector(".gantt-tl-overlay");
12686
- const chartClone = printContent.querySelector(".gantt-chartSurface");
12687
- if (includeTaskList) {
12688
- taskListClone?.classList.remove("gantt-tl-hidden", "gantt-tl-overlay-shadowed");
12689
- } else {
12690
- taskListClone?.remove();
12716
+ const shouldForceFullRender = !isTableMatrixMode;
12717
+ try {
12718
+ if (shouldForceFullRender) {
12719
+ setForceFullRenderForPrint(true);
12720
+ await waitForNextPaint2(window);
12721
+ }
12722
+ const sourceContent = scrollContentRef.current;
12723
+ if (!sourceContent) {
12724
+ return;
12725
+ }
12726
+ const printContent = sourceContent.cloneNode(true);
12727
+ const taskListClone = printContent.querySelector(".gantt-tl-overlay");
12728
+ const chartClone = printContent.querySelector(".gantt-chartSurface");
12729
+ if (includeTaskList) {
12730
+ taskListClone?.classList.remove("gantt-tl-hidden", "gantt-tl-overlay-shadowed");
12731
+ } else {
12732
+ taskListClone?.remove();
12733
+ }
12734
+ if (includeChart) {
12735
+ chartClone?.classList.remove("gantt-chart-hidden");
12736
+ if (chartClone) chartClone.style.display = "";
12737
+ } else {
12738
+ chartClone?.remove();
12739
+ }
12740
+ await printGanttChart({
12741
+ sourceDocument: document,
12742
+ sourceContainer,
12743
+ printContent,
12744
+ header: options?.header,
12745
+ documentTitle: options?.documentTitle,
12746
+ title: options?.title,
12747
+ fileName: options?.fileName,
12748
+ orientation: options?.orientation
12749
+ });
12750
+ } finally {
12751
+ if (shouldForceFullRender) {
12752
+ setForceFullRenderForPrint(false);
12753
+ }
12691
12754
  }
12692
- if (includeChart) {
12693
- chartClone?.classList.remove("gantt-chart-hidden");
12694
- if (chartClone) chartClone.style.display = "";
12695
- } else {
12696
- chartClone?.remove();
12697
- }
12698
- await printGanttChart({
12699
- sourceDocument: document,
12700
- sourceContainer,
12701
- printContent,
12702
- header: options?.header,
12703
- documentTitle: options?.documentTitle,
12704
- title: options?.title,
12705
- fileName: options?.fileName,
12706
- orientation: options?.orientation
12707
- });
12708
- }, [showTaskList, showChart]);
12755
+ }, [isTableMatrixMode, showTaskList, showChart]);
12709
12756
  (0, import_react18.useImperativeHandle)(
12710
12757
  ref,
12711
12758
  () => ({
@@ -13013,7 +13060,8 @@ function TaskGanttChartInner(props, ref) {
13013
13060
  filterMode,
13014
13061
  visibleRowIndices: visibleTaskWindowIndices,
13015
13062
  visibleDateIndices: visiblePlanFactDateIndices,
13016
- todayDateIndex: todayInRange ? todayIndex : void 0
13063
+ todayDateIndex: todayInRange ? todayIndex : void 0,
13064
+ isCustomWeekend
13017
13065
  }
13018
13066
  ) : /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
13019
13067
  /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(