gantt-lib 0.51.1 → 0.52.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
@@ -1211,6 +1211,22 @@ declare function getAllDescendants(parentId: string, tasks: Task$1[]): Task$1[];
1211
1211
  * @param weekendPredicate - Function that returns true for weekends.
1212
1212
  */
1213
1213
  declare function universalCascade(movedTask: Task$1, newStart: Date, newEnd: Date, allTasks: Task$1[], businessDays?: boolean, weekendPredicate?: (date: Date) => boolean): Task$1[];
1214
+ /**
1215
+ * Пересчитывает даты всех задач при переключении режима рабочих/календарных дней.
1216
+ *
1217
+ * Calendar → Working (toBusinessDays=true):
1218
+ * - duration число сохраняется (10 кал → 10 раб)
1219
+ * - start на выходном → сдвигается на ближайший рабочий
1220
+ * - end пересчитывается через buildTaskRangeFromStart
1221
+ * - каскад зависимостей (расширение может нарушить constraints)
1222
+ *
1223
+ * Working → Calendar (toBusinessDays=false):
1224
+ * - start остаётся как есть
1225
+ * - duration число сохраняется, но теперь считается как календарные дни
1226
+ * - end сдвигается ближе
1227
+ * - каскад НЕ нужен (сжатие не нарушает зависимости)
1228
+ */
1229
+ declare function reflowTasksOnModeSwitch(sourceTasks: Task$1[], toBusinessDays: boolean, weekendPredicate: (date: Date) => boolean): Task$1[];
1214
1230
 
1215
1231
  /**
1216
1232
  * Checks whether a task is behind the expected progress for the current date.
@@ -1400,4 +1416,4 @@ interface VisibleReorderPosition {
1400
1416
  */
1401
1417
  declare function getVisibleReorderPosition(orderedTasks: TaskLike[], visibleTasks: TaskLike[], movedTaskId: string, originVisibleIndex: number, dropVisibleIndex: number): VisibleReorderPosition | null;
1402
1418
 
1403
- export { type BuiltInTaskListColumnId, Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListColumn, type TaskListColumnContext, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, addBusinessDays, alignToWorkingDay, and, buildAdjacencyList, buildTaskRangeFromEnd, buildTaskRangeFromStart, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, clampTaskRangeForIncomingFS, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, formatDateRangeLabel, getAllDependencyEdges, getAllDescendants, getBusinessDaysCount, getChildren, getCursorForPosition, getDayOffset, getDependencyLag, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTaskDuration, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, moveTaskRange, nameContains, normalizeDependencyLag, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, removeDependenciesBetweenTasks, subtractBusinessDays, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
1419
+ export { type BuiltInTaskListColumnId, Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListColumn, type TaskListColumnContext, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, addBusinessDays, alignToWorkingDay, and, buildAdjacencyList, buildTaskRangeFromEnd, buildTaskRangeFromStart, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, clampTaskRangeForIncomingFS, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, formatDateRangeLabel, getAllDependencyEdges, getAllDescendants, getBusinessDaysCount, getChildren, getCursorForPosition, getDayOffset, getDependencyLag, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTaskDuration, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, moveTaskRange, nameContains, normalizeDependencyLag, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, reflowTasksOnModeSwitch, removeDependenciesBetweenTasks, subtractBusinessDays, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
package/dist/index.d.ts CHANGED
@@ -1211,6 +1211,22 @@ declare function getAllDescendants(parentId: string, tasks: Task$1[]): Task$1[];
1211
1211
  * @param weekendPredicate - Function that returns true for weekends.
1212
1212
  */
1213
1213
  declare function universalCascade(movedTask: Task$1, newStart: Date, newEnd: Date, allTasks: Task$1[], businessDays?: boolean, weekendPredicate?: (date: Date) => boolean): Task$1[];
1214
+ /**
1215
+ * Пересчитывает даты всех задач при переключении режима рабочих/календарных дней.
1216
+ *
1217
+ * Calendar → Working (toBusinessDays=true):
1218
+ * - duration число сохраняется (10 кал → 10 раб)
1219
+ * - start на выходном → сдвигается на ближайший рабочий
1220
+ * - end пересчитывается через buildTaskRangeFromStart
1221
+ * - каскад зависимостей (расширение может нарушить constraints)
1222
+ *
1223
+ * Working → Calendar (toBusinessDays=false):
1224
+ * - start остаётся как есть
1225
+ * - duration число сохраняется, но теперь считается как календарные дни
1226
+ * - end сдвигается ближе
1227
+ * - каскад НЕ нужен (сжатие не нарушает зависимости)
1228
+ */
1229
+ declare function reflowTasksOnModeSwitch(sourceTasks: Task$1[], toBusinessDays: boolean, weekendPredicate: (date: Date) => boolean): Task$1[];
1214
1230
 
1215
1231
  /**
1216
1232
  * Checks whether a task is behind the expected progress for the current date.
@@ -1400,4 +1416,4 @@ interface VisibleReorderPosition {
1400
1416
  */
1401
1417
  declare function getVisibleReorderPosition(orderedTasks: TaskLike[], visibleTasks: TaskLike[], movedTaskId: string, originVisibleIndex: number, dropVisibleIndex: number): VisibleReorderPosition | null;
1402
1418
 
1403
- export { type BuiltInTaskListColumnId, Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListColumn, type TaskListColumnContext, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, addBusinessDays, alignToWorkingDay, and, buildAdjacencyList, buildTaskRangeFromEnd, buildTaskRangeFromStart, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, clampTaskRangeForIncomingFS, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, formatDateRangeLabel, getAllDependencyEdges, getAllDescendants, getBusinessDaysCount, getChildren, getCursorForPosition, getDayOffset, getDependencyLag, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTaskDuration, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, moveTaskRange, nameContains, normalizeDependencyLag, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, removeDependenciesBetweenTasks, subtractBusinessDays, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
1419
+ export { type BuiltInTaskListColumnId, Button, type ButtonProps, Calendar, type CalendarProps, type CustomDayConfig, type CustomDayPredicateConfig, DatePicker, type DatePickerProps, DragGuideLines, GanttChart, type GanttChartHandle, type GanttChartProps, type GanttDateRange, GridBackground, type GridConfig, type GridLine, Input, type InputProps, type MonthBlock, type MonthSpan, Popover, PopoverContent, type PopoverContentProps, type PopoverProps, PopoverTrigger, type Task, type TaskBarGeometry, type TaskDependency, TaskList, type TaskListColumn, type TaskListColumnContext, type TaskListProps, type TaskPredicate, TaskRow, TimeScaleHeader, TodayIndicator, type VisibleReorderPosition, type WeekBlock, type WeekSpan, type WeekendBlock, type YearSpan, addBusinessDays, alignToWorkingDay, and, buildAdjacencyList, buildTaskRangeFromEnd, buildTaskRangeFromStart, calculateBezierPath, calculateDependencyPath, calculateGridLines, calculateGridWidth, calculateMonthGridLines, calculateOrthogonalPath, calculateSuccessorDate, calculateTaskBar, calculateWeekGridLines, calculateWeekendBlocks, cascadeByLinks, clampTaskRangeForIncomingFS, computeLagFromDates, computeParentDates, computeParentProgress, createCustomDayPredicate, createDateKey, detectCycles, detectEdgeZone, expired, findParentId, flattenHierarchy, formatDateLabel, formatDateRangeLabel, getAllDependencyEdges, getAllDescendants, getBusinessDaysCount, getChildren, getCursorForPosition, getDayOffset, getDependencyLag, getMonthBlocks, getMonthDays, getMonthSpans, getMultiMonthDays, getSuccessorChain, getTaskDuration, getTransitiveCascadeChain, getVisibleReorderPosition, getWeekBlocks, getWeekSpans, getYearSpans, inDateRange, isTaskExpired, isTaskParent, isToday, isWeekend, moveTaskRange, nameContains, normalizeDependencyLag, normalizeHierarchyTasks, normalizeTaskDates, not, or, parseUTCDate, pixelsToDate, progressInRange, recalculateIncomingLags, reflowTasksOnModeSwitch, removeDependenciesBetweenTasks, subtractBusinessDays, universalCascade, useTaskDrag, validateDependencies, withoutDeps };
package/dist/index.js CHANGED
@@ -507,6 +507,7 @@ __export(index_exports, {
507
507
  pixelsToDate: () => pixelsToDate,
508
508
  progressInRange: () => progressInRange,
509
509
  recalculateIncomingLags: () => recalculateIncomingLags,
510
+ reflowTasksOnModeSwitch: () => reflowTasksOnModeSwitch,
510
511
  removeDependenciesBetweenTasks: () => removeDependenciesBetweenTasks,
511
512
  subtractBusinessDays: () => subtractBusinessDays,
512
513
  universalCascade: () => universalCascade,
@@ -1228,6 +1229,45 @@ function universalCascade(movedTask, newStart, newEnd, allTasks, businessDays =
1228
1229
  }
1229
1230
  return Array.from(resultMap.values());
1230
1231
  }
1232
+ function reflowTasksOnModeSwitch(sourceTasks, toBusinessDays, weekendPredicate) {
1233
+ const fromBusinessDays = !toBusinessDays;
1234
+ let tasks = sourceTasks.map((t) => ({ ...t }));
1235
+ const toISO = (d) => d.toISOString().split("T")[0];
1236
+ for (const task of tasks) {
1237
+ if (isTaskParent(task.id, tasks)) continue;
1238
+ const start = normalizeUTCDate(/* @__PURE__ */ new Date(`${task.startDate}T00:00:00.000Z`));
1239
+ const duration = getTaskDuration(task.startDate, task.endDate, fromBusinessDays, weekendPredicate);
1240
+ let range;
1241
+ if (toBusinessDays) {
1242
+ const alignedStart = alignToWorkingDay(start, 1, weekendPredicate);
1243
+ range = buildTaskRangeFromStart(alignedStart, duration, true, weekendPredicate);
1244
+ } else {
1245
+ range = buildTaskRangeFromStart(start, duration, false);
1246
+ }
1247
+ task.startDate = toISO(range.start);
1248
+ task.endDate = toISO(range.end);
1249
+ }
1250
+ for (const task of tasks) {
1251
+ if (!isTaskParent(task.id, tasks)) continue;
1252
+ const { startDate, endDate } = computeParentDates(task.id, tasks);
1253
+ task.startDate = toISO(startDate);
1254
+ task.endDate = toISO(endDate);
1255
+ }
1256
+ if (toBusinessDays) {
1257
+ const rootSeeds = tasks.filter(
1258
+ (t) => !t.parentId && (!t.dependencies || t.dependencies.length === 0)
1259
+ );
1260
+ for (const seed of rootSeeds) {
1261
+ const current = tasks.find((t) => t.id === seed.id);
1262
+ const start = /* @__PURE__ */ new Date(`${current.startDate}T00:00:00.000Z`);
1263
+ const end = /* @__PURE__ */ new Date(`${current.endDate}T00:00:00.000Z`);
1264
+ const cascaded = universalCascade(current, start, end, tasks, toBusinessDays, weekendPredicate);
1265
+ const updates = new Map(cascaded.map((t) => [t.id, t]));
1266
+ tasks = tasks.map((t) => updates.get(t.id) ?? t);
1267
+ }
1268
+ }
1269
+ return tasks;
1270
+ }
1231
1271
 
1232
1272
  // src/utils/hierarchyOrder.ts
1233
1273
  init_dateUtils();
@@ -7110,6 +7150,7 @@ var nameContains = (substring, caseSensitive = false) => (task) => {
7110
7150
  pixelsToDate,
7111
7151
  progressInRange,
7112
7152
  recalculateIncomingLags,
7153
+ reflowTasksOnModeSwitch,
7113
7154
  removeDependenciesBetweenTasks,
7114
7155
  subtractBusinessDays,
7115
7156
  universalCascade,