gantt-lib 0.75.0 → 0.75.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.mjs CHANGED
@@ -637,13 +637,13 @@ function computeParentProgress(parentId, tasks) {
637
637
  if (children.length === 0) {
638
638
  return 0;
639
639
  }
640
- const DAY_MS3 = 24 * 60 * 60 * 1e3;
640
+ const DAY_MS4 = 24 * 60 * 60 * 1e3;
641
641
  let totalWeight = 0;
642
642
  let weightedSum = 0;
643
643
  for (const child of children) {
644
644
  const start = new Date(child.startDate).getTime();
645
645
  const end = new Date(child.endDate).getTime();
646
- const duration = (end - start + DAY_MS3) / DAY_MS3;
646
+ const duration = (end - start + DAY_MS4) / DAY_MS4;
647
647
  const progress = child.progress ?? 0;
648
648
  totalWeight += duration;
649
649
  weightedSum += duration * progress;
@@ -738,10 +738,10 @@ function buildTaskRangeFromStart(startDate, duration, businessDays = false, week
738
738
  end: parseDateOnly(addBusinessDays(normalizedStart, duration, weekendPredicate))
739
739
  };
740
740
  }
741
- const DAY_MS3 = 24 * 60 * 60 * 1e3;
741
+ const DAY_MS4 = 24 * 60 * 60 * 1e3;
742
742
  return {
743
743
  start: normalizedStart,
744
- end: new Date(normalizedStart.getTime() + (Math.max(1, duration) - 1) * DAY_MS3)
744
+ end: new Date(normalizedStart.getTime() + (Math.max(1, duration) - 1) * DAY_MS4)
745
745
  };
746
746
  }
747
747
  function buildTaskRangeFromEnd(endDate, duration, businessDays = false, weekendPredicate, snapDirection = -1) {
@@ -752,9 +752,9 @@ function buildTaskRangeFromEnd(endDate, duration, businessDays = false, weekendP
752
752
  end: normalizedEnd
753
753
  };
754
754
  }
755
- const DAY_MS3 = 24 * 60 * 60 * 1e3;
755
+ const DAY_MS4 = 24 * 60 * 60 * 1e3;
756
756
  return {
757
- start: new Date(normalizedEnd.getTime() - (Math.max(1, duration) - 1) * DAY_MS3),
757
+ start: new Date(normalizedEnd.getTime() - (Math.max(1, duration) - 1) * DAY_MS4),
758
758
  end: normalizedEnd
759
759
  };
760
760
  }
@@ -4088,21 +4088,56 @@ var LINK_TYPE_LABELS = {
4088
4088
  SF: "\u041D\u0430\u0447\u0430\u043B\u043E-\u043E\u043A\u043E\u043D\u0447\u0430\u043D\u0438\u0435"
4089
4089
  };
4090
4090
 
4091
+ // src/components/TaskList/defaultTaskDates.ts
4092
+ init_dateUtils();
4093
+ var DAY_MS2 = 24 * 60 * 60 * 1e3;
4094
+ var DEFAULT_TASK_DURATION_DAYS = 5;
4095
+ function toISODate(date) {
4096
+ return date.toISOString().split("T")[0];
4097
+ }
4098
+ function getTodayISODate() {
4099
+ const now = /* @__PURE__ */ new Date();
4100
+ return toISODate(new Date(Date.UTC(
4101
+ now.getUTCFullYear(),
4102
+ now.getUTCMonth(),
4103
+ now.getUTCDate()
4104
+ )));
4105
+ }
4106
+ function buildDefaultTaskDateRange(startDate, {
4107
+ businessDays,
4108
+ defaultTaskDurationDays = DEFAULT_TASK_DURATION_DAYS,
4109
+ weekendPredicate
4110
+ } = {}) {
4111
+ const durationDays = Math.max(1, Math.round(defaultTaskDurationDays));
4112
+ const start = parseUTCDate(startDate);
4113
+ if (businessDays && weekendPredicate) {
4114
+ const range = buildTaskRangeFromStart(start, durationDays, true, weekendPredicate);
4115
+ return {
4116
+ startDate: toISODate(range.start),
4117
+ endDate: toISODate(range.end)
4118
+ };
4119
+ }
4120
+ return {
4121
+ startDate: toISODate(start),
4122
+ endDate: toISODate(new Date(start.getTime() + (durationDays - 1) * DAY_MS2))
4123
+ };
4124
+ }
4125
+
4091
4126
  // src/components/TaskList/TaskListRow.tsx
4092
4127
  import { Fragment as Fragment2, jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
4093
- var DAY_MS2 = 24 * 60 * 60 * 1e3;
4128
+ var DAY_MS3 = 24 * 60 * 60 * 1e3;
4094
4129
  var LINK_TYPE_ORDER = ["FS", "SS", "FF", "SF"];
4095
4130
  var getInclusiveDurationDays = (startDate, endDate) => {
4096
4131
  const start = parseUTCDate(startDate);
4097
4132
  const end = parseUTCDate(endDate);
4098
4133
  return Math.max(
4099
4134
  1,
4100
- Math.round((end.getTime() - start.getTime()) / DAY_MS2) + 1
4135
+ Math.round((end.getTime() - start.getTime()) / DAY_MS3) + 1
4101
4136
  );
4102
4137
  };
4103
4138
  var getEndDateFromDuration = (startDate, durationDays) => {
4104
4139
  const start = parseUTCDate(startDate);
4105
- return new Date(start.getTime() + (durationDays - 1) * DAY_MS2).toISOString().split("T")[0];
4140
+ return new Date(start.getTime() + (durationDays - 1) * DAY_MS3).toISOString().split("T")[0];
4106
4141
  };
4107
4142
  var TrashIcon = () => /* @__PURE__ */ jsxs9(
4108
4143
  "svg",
@@ -4587,7 +4622,7 @@ var DepChip = ({
4587
4622
  )
4588
4623
  ] });
4589
4624
  };
4590
- var toISODate = (value) => {
4625
+ var toISODate2 = (value) => {
4591
4626
  if (value instanceof Date) return value.toISOString().split("T")[0];
4592
4627
  if (typeof value === "string" && value.includes("T"))
4593
4628
  return value.split("T")[0];
@@ -4641,6 +4676,7 @@ var TaskListRow = React9.memo(
4641
4676
  customDays,
4642
4677
  isWeekend: isWeekend3,
4643
4678
  businessDays,
4679
+ defaultTaskDurationDays = DEFAULT_TASK_DURATION_DAYS,
4644
4680
  isFilterMatch = false,
4645
4681
  isFilterHideMode = false,
4646
4682
  resolvedColumns,
@@ -5448,8 +5484,8 @@ var TaskListRow = React9.memo(
5448
5484
  },
5449
5485
  [selectedChip?.successorId, selectedChip?.predecessorId, selectedChip?.linkType, onRemoveDependency, onChipSelect]
5450
5486
  );
5451
- const startDateISO = toISODate(normalizedTask.startDate);
5452
- const endDateISO = editingDuration ? getEndDate(normalizedTask.startDate, durationValue) : toISODate(normalizedTask.endDate);
5487
+ const startDateISO = toISODate2(normalizedTask.startDate);
5488
+ const endDateISO = editingDuration ? getEndDate(normalizedTask.startDate, durationValue) : toISODate2(normalizedTask.endDate);
5453
5489
  const numberCell = /* @__PURE__ */ jsxs9(
5454
5490
  "div",
5455
5491
  {
@@ -5667,26 +5703,16 @@ var TaskListRow = React9.memo(
5667
5703
  className: "gantt-tl-name-action-btn gantt-tl-action-insert",
5668
5704
  onClick: (e) => {
5669
5705
  e.stopPropagation();
5670
- const now = /* @__PURE__ */ new Date();
5671
- const todayISO = new Date(
5672
- Date.UTC(
5673
- now.getUTCFullYear(),
5674
- now.getUTCMonth(),
5675
- now.getUTCDate()
5676
- )
5677
- ).toISOString().split("T")[0];
5678
- const endISO = new Date(
5679
- Date.UTC(
5680
- now.getUTCFullYear(),
5681
- now.getUTCMonth(),
5682
- now.getUTCDate() + 7
5683
- )
5684
- ).toISOString().split("T")[0];
5706
+ const range = buildDefaultTaskDateRange(getTodayISODate(), {
5707
+ businessDays,
5708
+ defaultTaskDurationDays,
5709
+ weekendPredicate
5710
+ });
5685
5711
  const newTask = {
5686
5712
  id: crypto.randomUUID(),
5687
5713
  name: "\u041D\u043E\u0432\u0430\u044F \u0437\u0430\u0434\u0430\u0447\u0430",
5688
- startDate: todayISO,
5689
- endDate: endISO,
5714
+ startDate: range.startDate,
5715
+ endDate: range.endDate,
5690
5716
  parentId: task.parentId
5691
5717
  };
5692
5718
  onInsertAfter(task.id, newTask);
@@ -6515,6 +6541,7 @@ var TaskList = ({
6515
6541
  onReorder,
6516
6542
  editingTaskId: propEditingTaskId,
6517
6543
  enableAddTask = true,
6544
+ defaultTaskDurationDays = DEFAULT_TASK_DURATION_DAYS,
6518
6545
  collapsedParentIds: externalCollapsedParentIds,
6519
6546
  onToggleCollapse: externalOnToggleCollapse,
6520
6547
  onPromoteTask,
@@ -6917,26 +6944,20 @@ var TaskList = ({
6917
6944
  dragTaskIdRef.current = null;
6918
6945
  }, []);
6919
6946
  const handleConfirmNewTask = useCallback5((name) => {
6920
- const now = /* @__PURE__ */ new Date();
6921
- const todayISO = new Date(Date.UTC(
6922
- now.getUTCFullYear(),
6923
- now.getUTCMonth(),
6924
- now.getUTCDate()
6925
- )).toISOString().split("T")[0];
6926
- const endISO = new Date(Date.UTC(
6927
- now.getUTCFullYear(),
6928
- now.getUTCMonth(),
6929
- now.getUTCDate() + 7
6930
- )).toISOString().split("T")[0];
6947
+ const range = buildDefaultTaskDateRange(getTodayISODate(), {
6948
+ businessDays,
6949
+ defaultTaskDurationDays,
6950
+ weekendPredicate
6951
+ });
6931
6952
  const newTask = {
6932
6953
  id: crypto.randomUUID(),
6933
6954
  name,
6934
- startDate: todayISO,
6935
- endDate: endISO
6955
+ startDate: range.startDate,
6956
+ endDate: range.endDate
6936
6957
  };
6937
6958
  onAdd?.(newTask);
6938
6959
  setIsCreating(false);
6939
- }, [onAdd]);
6960
+ }, [businessDays, defaultTaskDurationDays, onAdd, weekendPredicate]);
6940
6961
  const handleCancelNewTask = useCallback5(() => setIsCreating(false), []);
6941
6962
  const findInsertAfterTaskId = useCallback5((anchorTaskId) => {
6942
6963
  const anchorIndex = orderedTasks.findIndex((task) => task.id === anchorTaskId);
@@ -7202,6 +7223,7 @@ var TaskList = ({
7202
7223
  customDays,
7203
7224
  isWeekend: isWeekend3,
7204
7225
  businessDays,
7226
+ defaultTaskDurationDays,
7205
7227
  isFilterMatch: filterMode === "highlight" ? highlightedTaskIds.has(task.id) : false,
7206
7228
  isFilterHideMode: filterMode === "hide" && isFilterActive,
7207
7229
  resolvedColumns,
@@ -8156,6 +8178,7 @@ function TaskGanttChartInner(props, ref) {
8156
8178
  onDemoteTask,
8157
8179
  onUngroupTask,
8158
8180
  enableAddTask = true,
8181
+ defaultTaskDurationDays,
8159
8182
  viewMode = "day",
8160
8183
  customDays,
8161
8184
  isWeekend: isWeekend3,
@@ -8685,6 +8708,7 @@ function TaskGanttChartInner(props, ref) {
8685
8708
  onReorder: handleReorder,
8686
8709
  editingTaskId,
8687
8710
  enableAddTask,
8711
+ defaultTaskDurationDays,
8688
8712
  collapsedParentIds,
8689
8713
  onToggleCollapse: handleToggleCollapse,
8690
8714
  onPromoteTask: onPromoteTask ?? handlePromoteTask,