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.d.mts CHANGED
@@ -461,6 +461,8 @@ interface GanttModeProps<TTask extends Task = Task> {
461
461
  onUngroupTask?: (taskId: string) => void;
462
462
  /** Enable add task button at bottom of task list (default: true) */
463
463
  enableAddTask?: boolean;
464
+ /** Default duration for newly created tasks, interpreted in the active day mode (default: 5). */
465
+ defaultTaskDurationDays?: number;
464
466
  /** View mode: 'day' renders one column per day, 'week' renders one column per 7 days, 'month' renders one column per month (default: 'day') */
465
467
  viewMode?: 'day' | 'week' | 'month';
466
468
  /** Custom day configurations with explicit type (weekend or workday) */
@@ -726,6 +728,8 @@ interface TaskListProps {
726
728
  editingTaskId?: string | null;
727
729
  /** Enable add task button at bottom of task list (default: true) */
728
730
  enableAddTask?: boolean;
731
+ /** Default duration for newly created tasks, interpreted in the active day mode (default: 5). */
732
+ defaultTaskDurationDays?: number;
729
733
  /** Set of collapsed parent task IDs */
730
734
  collapsedParentIds?: Set<string>;
731
735
  /** Callback when collapse/expand button is clicked */
package/dist/index.d.ts CHANGED
@@ -461,6 +461,8 @@ interface GanttModeProps<TTask extends Task = Task> {
461
461
  onUngroupTask?: (taskId: string) => void;
462
462
  /** Enable add task button at bottom of task list (default: true) */
463
463
  enableAddTask?: boolean;
464
+ /** Default duration for newly created tasks, interpreted in the active day mode (default: 5). */
465
+ defaultTaskDurationDays?: number;
464
466
  /** View mode: 'day' renders one column per day, 'week' renders one column per 7 days, 'month' renders one column per month (default: 'day') */
465
467
  viewMode?: 'day' | 'week' | 'month';
466
468
  /** Custom day configurations with explicit type (weekend or workday) */
@@ -726,6 +728,8 @@ interface TaskListProps {
726
728
  editingTaskId?: string | null;
727
729
  /** Enable add task button at bottom of task list (default: true) */
728
730
  enableAddTask?: boolean;
731
+ /** Default duration for newly created tasks, interpreted in the active day mode (default: 5). */
732
+ defaultTaskDurationDays?: number;
729
733
  /** Set of collapsed parent task IDs */
730
734
  collapsedParentIds?: Set<string>;
731
735
  /** Callback when collapse/expand button is clicked */
package/dist/index.js CHANGED
@@ -758,13 +758,13 @@ function computeParentProgress(parentId, tasks) {
758
758
  if (children.length === 0) {
759
759
  return 0;
760
760
  }
761
- const DAY_MS3 = 24 * 60 * 60 * 1e3;
761
+ const DAY_MS4 = 24 * 60 * 60 * 1e3;
762
762
  let totalWeight = 0;
763
763
  let weightedSum = 0;
764
764
  for (const child of children) {
765
765
  const start = new Date(child.startDate).getTime();
766
766
  const end = new Date(child.endDate).getTime();
767
- const duration = (end - start + DAY_MS3) / DAY_MS3;
767
+ const duration = (end - start + DAY_MS4) / DAY_MS4;
768
768
  const progress = child.progress ?? 0;
769
769
  totalWeight += duration;
770
770
  weightedSum += duration * progress;
@@ -859,10 +859,10 @@ function buildTaskRangeFromStart(startDate, duration, businessDays = false, week
859
859
  end: parseDateOnly(addBusinessDays(normalizedStart, duration, weekendPredicate))
860
860
  };
861
861
  }
862
- const DAY_MS3 = 24 * 60 * 60 * 1e3;
862
+ const DAY_MS4 = 24 * 60 * 60 * 1e3;
863
863
  return {
864
864
  start: normalizedStart,
865
- end: new Date(normalizedStart.getTime() + (Math.max(1, duration) - 1) * DAY_MS3)
865
+ end: new Date(normalizedStart.getTime() + (Math.max(1, duration) - 1) * DAY_MS4)
866
866
  };
867
867
  }
868
868
  function buildTaskRangeFromEnd(endDate, duration, businessDays = false, weekendPredicate, snapDirection = -1) {
@@ -873,9 +873,9 @@ function buildTaskRangeFromEnd(endDate, duration, businessDays = false, weekendP
873
873
  end: normalizedEnd
874
874
  };
875
875
  }
876
- const DAY_MS3 = 24 * 60 * 60 * 1e3;
876
+ const DAY_MS4 = 24 * 60 * 60 * 1e3;
877
877
  return {
878
- start: new Date(normalizedEnd.getTime() - (Math.max(1, duration) - 1) * DAY_MS3),
878
+ start: new Date(normalizedEnd.getTime() - (Math.max(1, duration) - 1) * DAY_MS4),
879
879
  end: normalizedEnd
880
880
  };
881
881
  }
@@ -4185,21 +4185,56 @@ var LINK_TYPE_LABELS = {
4185
4185
  SF: "\u041D\u0430\u0447\u0430\u043B\u043E-\u043E\u043A\u043E\u043D\u0447\u0430\u043D\u0438\u0435"
4186
4186
  };
4187
4187
 
4188
+ // src/components/TaskList/defaultTaskDates.ts
4189
+ init_dateUtils();
4190
+ var DAY_MS2 = 24 * 60 * 60 * 1e3;
4191
+ var DEFAULT_TASK_DURATION_DAYS = 5;
4192
+ function toISODate(date) {
4193
+ return date.toISOString().split("T")[0];
4194
+ }
4195
+ function getTodayISODate() {
4196
+ const now = /* @__PURE__ */ new Date();
4197
+ return toISODate(new Date(Date.UTC(
4198
+ now.getUTCFullYear(),
4199
+ now.getUTCMonth(),
4200
+ now.getUTCDate()
4201
+ )));
4202
+ }
4203
+ function buildDefaultTaskDateRange(startDate, {
4204
+ businessDays,
4205
+ defaultTaskDurationDays = DEFAULT_TASK_DURATION_DAYS,
4206
+ weekendPredicate
4207
+ } = {}) {
4208
+ const durationDays = Math.max(1, Math.round(defaultTaskDurationDays));
4209
+ const start = parseUTCDate(startDate);
4210
+ if (businessDays && weekendPredicate) {
4211
+ const range = buildTaskRangeFromStart(start, durationDays, true, weekendPredicate);
4212
+ return {
4213
+ startDate: toISODate(range.start),
4214
+ endDate: toISODate(range.end)
4215
+ };
4216
+ }
4217
+ return {
4218
+ startDate: toISODate(start),
4219
+ endDate: toISODate(new Date(start.getTime() + (durationDays - 1) * DAY_MS2))
4220
+ };
4221
+ }
4222
+
4188
4223
  // src/components/TaskList/TaskListRow.tsx
4189
4224
  var import_jsx_runtime12 = require("react/jsx-runtime");
4190
- var DAY_MS2 = 24 * 60 * 60 * 1e3;
4225
+ var DAY_MS3 = 24 * 60 * 60 * 1e3;
4191
4226
  var LINK_TYPE_ORDER = ["FS", "SS", "FF", "SF"];
4192
4227
  var getInclusiveDurationDays = (startDate, endDate) => {
4193
4228
  const start = parseUTCDate(startDate);
4194
4229
  const end = parseUTCDate(endDate);
4195
4230
  return Math.max(
4196
4231
  1,
4197
- Math.round((end.getTime() - start.getTime()) / DAY_MS2) + 1
4232
+ Math.round((end.getTime() - start.getTime()) / DAY_MS3) + 1
4198
4233
  );
4199
4234
  };
4200
4235
  var getEndDateFromDuration = (startDate, durationDays) => {
4201
4236
  const start = parseUTCDate(startDate);
4202
- return new Date(start.getTime() + (durationDays - 1) * DAY_MS2).toISOString().split("T")[0];
4237
+ return new Date(start.getTime() + (durationDays - 1) * DAY_MS3).toISOString().split("T")[0];
4203
4238
  };
4204
4239
  var TrashIcon = () => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
4205
4240
  "svg",
@@ -4684,7 +4719,7 @@ var DepChip = ({
4684
4719
  )
4685
4720
  ] });
4686
4721
  };
4687
- var toISODate = (value) => {
4722
+ var toISODate2 = (value) => {
4688
4723
  if (value instanceof Date) return value.toISOString().split("T")[0];
4689
4724
  if (typeof value === "string" && value.includes("T"))
4690
4725
  return value.split("T")[0];
@@ -4738,6 +4773,7 @@ var TaskListRow = import_react10.default.memo(
4738
4773
  customDays,
4739
4774
  isWeekend: isWeekend3,
4740
4775
  businessDays,
4776
+ defaultTaskDurationDays = DEFAULT_TASK_DURATION_DAYS,
4741
4777
  isFilterMatch = false,
4742
4778
  isFilterHideMode = false,
4743
4779
  resolvedColumns,
@@ -5545,8 +5581,8 @@ var TaskListRow = import_react10.default.memo(
5545
5581
  },
5546
5582
  [selectedChip?.successorId, selectedChip?.predecessorId, selectedChip?.linkType, onRemoveDependency, onChipSelect]
5547
5583
  );
5548
- const startDateISO = toISODate(normalizedTask.startDate);
5549
- const endDateISO = editingDuration ? getEndDate(normalizedTask.startDate, durationValue) : toISODate(normalizedTask.endDate);
5584
+ const startDateISO = toISODate2(normalizedTask.startDate);
5585
+ const endDateISO = editingDuration ? getEndDate(normalizedTask.startDate, durationValue) : toISODate2(normalizedTask.endDate);
5550
5586
  const numberCell = /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
5551
5587
  "div",
5552
5588
  {
@@ -5764,26 +5800,16 @@ var TaskListRow = import_react10.default.memo(
5764
5800
  className: "gantt-tl-name-action-btn gantt-tl-action-insert",
5765
5801
  onClick: (e) => {
5766
5802
  e.stopPropagation();
5767
- const now = /* @__PURE__ */ new Date();
5768
- const todayISO = new Date(
5769
- Date.UTC(
5770
- now.getUTCFullYear(),
5771
- now.getUTCMonth(),
5772
- now.getUTCDate()
5773
- )
5774
- ).toISOString().split("T")[0];
5775
- const endISO = new Date(
5776
- Date.UTC(
5777
- now.getUTCFullYear(),
5778
- now.getUTCMonth(),
5779
- now.getUTCDate() + 7
5780
- )
5781
- ).toISOString().split("T")[0];
5803
+ const range = buildDefaultTaskDateRange(getTodayISODate(), {
5804
+ businessDays,
5805
+ defaultTaskDurationDays,
5806
+ weekendPredicate
5807
+ });
5782
5808
  const newTask = {
5783
5809
  id: crypto.randomUUID(),
5784
5810
  name: "\u041D\u043E\u0432\u0430\u044F \u0437\u0430\u0434\u0430\u0447\u0430",
5785
- startDate: todayISO,
5786
- endDate: endISO,
5811
+ startDate: range.startDate,
5812
+ endDate: range.endDate,
5787
5813
  parentId: task.parentId
5788
5814
  };
5789
5815
  onInsertAfter(task.id, newTask);
@@ -6612,6 +6638,7 @@ var TaskList = ({
6612
6638
  onReorder,
6613
6639
  editingTaskId: propEditingTaskId,
6614
6640
  enableAddTask = true,
6641
+ defaultTaskDurationDays = DEFAULT_TASK_DURATION_DAYS,
6615
6642
  collapsedParentIds: externalCollapsedParentIds,
6616
6643
  onToggleCollapse: externalOnToggleCollapse,
6617
6644
  onPromoteTask,
@@ -7014,26 +7041,20 @@ var TaskList = ({
7014
7041
  dragTaskIdRef.current = null;
7015
7042
  }, []);
7016
7043
  const handleConfirmNewTask = (0, import_react12.useCallback)((name) => {
7017
- const now = /* @__PURE__ */ new Date();
7018
- const todayISO = new Date(Date.UTC(
7019
- now.getUTCFullYear(),
7020
- now.getUTCMonth(),
7021
- now.getUTCDate()
7022
- )).toISOString().split("T")[0];
7023
- const endISO = new Date(Date.UTC(
7024
- now.getUTCFullYear(),
7025
- now.getUTCMonth(),
7026
- now.getUTCDate() + 7
7027
- )).toISOString().split("T")[0];
7044
+ const range = buildDefaultTaskDateRange(getTodayISODate(), {
7045
+ businessDays,
7046
+ defaultTaskDurationDays,
7047
+ weekendPredicate
7048
+ });
7028
7049
  const newTask = {
7029
7050
  id: crypto.randomUUID(),
7030
7051
  name,
7031
- startDate: todayISO,
7032
- endDate: endISO
7052
+ startDate: range.startDate,
7053
+ endDate: range.endDate
7033
7054
  };
7034
7055
  onAdd?.(newTask);
7035
7056
  setIsCreating(false);
7036
- }, [onAdd]);
7057
+ }, [businessDays, defaultTaskDurationDays, onAdd, weekendPredicate]);
7037
7058
  const handleCancelNewTask = (0, import_react12.useCallback)(() => setIsCreating(false), []);
7038
7059
  const findInsertAfterTaskId = (0, import_react12.useCallback)((anchorTaskId) => {
7039
7060
  const anchorIndex = orderedTasks.findIndex((task) => task.id === anchorTaskId);
@@ -7299,6 +7320,7 @@ var TaskList = ({
7299
7320
  customDays,
7300
7321
  isWeekend: isWeekend3,
7301
7322
  businessDays,
7323
+ defaultTaskDurationDays,
7302
7324
  isFilterMatch: filterMode === "highlight" ? highlightedTaskIds.has(task.id) : false,
7303
7325
  isFilterHideMode: filterMode === "hide" && isFilterActive,
7304
7326
  resolvedColumns,
@@ -8253,6 +8275,7 @@ function TaskGanttChartInner(props, ref) {
8253
8275
  onDemoteTask,
8254
8276
  onUngroupTask,
8255
8277
  enableAddTask = true,
8278
+ defaultTaskDurationDays,
8256
8279
  viewMode = "day",
8257
8280
  customDays,
8258
8281
  isWeekend: isWeekend3,
@@ -8782,6 +8805,7 @@ function TaskGanttChartInner(props, ref) {
8782
8805
  onReorder: handleReorder,
8783
8806
  editingTaskId,
8784
8807
  enableAddTask,
8808
+ defaultTaskDurationDays,
8785
8809
  collapsedParentIds,
8786
8810
  onToggleCollapse: handleToggleCollapse,
8787
8811
  onPromoteTask: onPromoteTask ?? handlePromoteTask,