@classic-homes/gantt-core 0.2.0 → 0.3.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/README.md +1 -0
- package/dist/index.cjs +110 -0
- package/dist/index.d.cts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +106 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ model.validate({ type: 'add-dependency', dependency: { id: 'x', from: 'launch',
|
|
|
69
69
|
- `virtualWindow` for row virtualisation, `barGeometry` for task/summary/milestone/baseline rectangles, `hitTestBar`.
|
|
70
70
|
- `routeDependency` + `pathFromPoints` for orthogonal dependency arrows with rounded corners.
|
|
71
71
|
- `createDragSession`, `shiftTask`, `editOperation` turn pointer travel or keyboard nudges into snapped `update-task` operations that keep your data's shape (start + end stays start + end, date-only stays date-only).
|
|
72
|
+
- `rescheduleDates` / `rescheduleOperation` (typed dates/durations, same shape rules), `parseDuration` (`3d`, `4h`, `2w`), `predecessorOperations` (diff a task's incoming links), `indentOperation`, `outdentOperations` and `insertTaskOperation` for form and grid editing.
|
|
72
73
|
- `describeTask`, `describeSchedule`, `ganttTable`, `tableToCsv`, `exportProject`, `importProject`.
|
|
73
74
|
|
|
74
75
|
Subpath exports: `/types`, `/calendar`, `/scheduling`, `/layout`.
|
package/dist/index.cjs
CHANGED
|
@@ -1646,6 +1646,109 @@ function linkOperation(from, to, type = "FS", extra = {}) {
|
|
|
1646
1646
|
dependency: { id: extra.id ?? createId("dep"), from, to, type, ...extra }
|
|
1647
1647
|
};
|
|
1648
1648
|
}
|
|
1649
|
+
function rescheduleDates(ctx, edit) {
|
|
1650
|
+
const { task, calendar: cal, minutesPerDay } = ctx;
|
|
1651
|
+
const byDay = ctx.snap !== "hour";
|
|
1652
|
+
const start = edit.start === void 0 ? task.start : cal.nextWorking(byDay ? startOfDay(edit.start) : edit.start);
|
|
1653
|
+
let finish;
|
|
1654
|
+
if (edit.duration !== void 0) {
|
|
1655
|
+
finish = cal.add(start, Math.max(0, edit.duration) * minutesPerDay);
|
|
1656
|
+
} else if (edit.finish !== void 0) {
|
|
1657
|
+
finish = cal.prevWorking(byDay ? startOfDay(edit.finish) + DAY : edit.finish);
|
|
1658
|
+
} else {
|
|
1659
|
+
finish = task.type === "milestone" ? start : cal.add(start, task.duration);
|
|
1660
|
+
}
|
|
1661
|
+
finish = Math.max(start, finish);
|
|
1662
|
+
return { start, finish, changed: start !== task.start || finish !== task.finish };
|
|
1663
|
+
}
|
|
1664
|
+
function rescheduleOperation(ctx, edit) {
|
|
1665
|
+
const { task, calendar: cal } = ctx;
|
|
1666
|
+
const byDay = ctx.snap !== "hour";
|
|
1667
|
+
const wasMilestone = task.type === "milestone";
|
|
1668
|
+
const preview = rescheduleDates(ctx, edit);
|
|
1669
|
+
const { start, finish } = preview;
|
|
1670
|
+
if (!preview.changed) return null;
|
|
1671
|
+
const moved = start !== task.start;
|
|
1672
|
+
const length = cal.between(start, finish);
|
|
1673
|
+
const resized = length !== task.duration;
|
|
1674
|
+
const c = {
|
|
1675
|
+
...ctx,
|
|
1676
|
+
snap: byDay ? "day" : "hour",
|
|
1677
|
+
task: wasMilestone && length > 0 ? { ...task, type: "task" } : task
|
|
1678
|
+
};
|
|
1679
|
+
const patch = {};
|
|
1680
|
+
if (moved) Object.assign(patch, patchOf(editOperation(c, "move", preview)));
|
|
1681
|
+
if (resized) {
|
|
1682
|
+
if (length === 0) patch.duration = 0;
|
|
1683
|
+
else Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
|
|
1684
|
+
}
|
|
1685
|
+
return Object.keys(patch).length ? { type: "update-task", id: ctx.source.id, patch } : null;
|
|
1686
|
+
}
|
|
1687
|
+
var patchOf = (op) => op?.type === "update-task" ? op.patch : {};
|
|
1688
|
+
function predecessorOperations(taskId, dependencies, drafts) {
|
|
1689
|
+
const existing = dependencies.filter((d) => d.to === taskId);
|
|
1690
|
+
const kept = new Set(drafts.map((d) => d.id).filter(Boolean));
|
|
1691
|
+
const ops = existing.filter((d) => !kept.has(d.id)).map((d) => ({ type: "remove-dependency", id: d.id }));
|
|
1692
|
+
const adds = [];
|
|
1693
|
+
for (const draft of drafts) {
|
|
1694
|
+
const type = draft.type ?? "FS";
|
|
1695
|
+
const lag = draft.lag ?? 0;
|
|
1696
|
+
const prev = draft.id ? existing.find((d) => d.id === draft.id) : void 0;
|
|
1697
|
+
if (!prev) {
|
|
1698
|
+
adds.push(linkOperation(draft.from, taskId, type, lag ? { lag } : {}));
|
|
1699
|
+
continue;
|
|
1700
|
+
}
|
|
1701
|
+
const patch = {};
|
|
1702
|
+
if (prev.from !== draft.from) patch.from = draft.from;
|
|
1703
|
+
if ((prev.type ?? "FS") !== type) patch.type = type;
|
|
1704
|
+
if ((prev.lag ?? 0) !== lag) patch.lag = lag;
|
|
1705
|
+
if (Object.keys(patch).length) ops.push({ type: "update-dependency", id: prev.id, patch });
|
|
1706
|
+
}
|
|
1707
|
+
return [...ops, ...adds];
|
|
1708
|
+
}
|
|
1709
|
+
function parseDuration(text, minutesPerDay = 480) {
|
|
1710
|
+
const m = /^\s*(\d+(?:[.,]\d+)?)\s*([a-z]*)\s*$/i.exec(text);
|
|
1711
|
+
if (!m) return void 0;
|
|
1712
|
+
const n = Number(m[1].replace(",", "."));
|
|
1713
|
+
const unit = m[2].toLowerCase();
|
|
1714
|
+
if (!unit || /^d(ays?)?$/.test(unit)) return n;
|
|
1715
|
+
if (/^h((ou)?rs?)?$/.test(unit)) return round(n * 60 / minutesPerDay);
|
|
1716
|
+
if (/^w((ee)?ks?)?$/.test(unit)) return n * 5;
|
|
1717
|
+
return void 0;
|
|
1718
|
+
}
|
|
1719
|
+
function indentOperation(tasks, id) {
|
|
1720
|
+
const tree = buildTaskTree(tasks);
|
|
1721
|
+
const siblings = tree.children.get(tree.parent.get(id) ?? null) ?? [];
|
|
1722
|
+
const i = siblings.indexOf(id);
|
|
1723
|
+
if (i <= 0) return null;
|
|
1724
|
+
return { type: "update-task", id, patch: { parentId: siblings[i - 1] } };
|
|
1725
|
+
}
|
|
1726
|
+
function outdentOperations(tasks, id) {
|
|
1727
|
+
const tree = buildTaskTree(tasks);
|
|
1728
|
+
const parent = tree.parent.get(id) ?? null;
|
|
1729
|
+
if (parent === null) return [];
|
|
1730
|
+
const grand = tree.parent.get(parent) ?? null;
|
|
1731
|
+
const siblings = tree.children.get(parent) ?? [];
|
|
1732
|
+
const below = siblings.slice(siblings.indexOf(id) + 1);
|
|
1733
|
+
return [
|
|
1734
|
+
{ type: "update-task", id, patch: { parentId: grand ?? void 0 } },
|
|
1735
|
+
...below.map(
|
|
1736
|
+
(s) => ({ type: "update-task", id: s, patch: { parentId: id } })
|
|
1737
|
+
)
|
|
1738
|
+
];
|
|
1739
|
+
}
|
|
1740
|
+
function insertTaskOperation(tasks, afterId, task) {
|
|
1741
|
+
const after = afterId ? tasks.find((t) => t.id === afterId) : void 0;
|
|
1742
|
+
const full = { ...task, id: task.id ?? createId("task") };
|
|
1743
|
+
if (!after) return { type: "add-task", task: full };
|
|
1744
|
+
if (after.parentId) full.parentId = after.parentId;
|
|
1745
|
+
const subtree = /* @__PURE__ */ new Set([after.id, ...descendantsOf(buildTaskTree(tasks), after.id)]);
|
|
1746
|
+
let last = -1;
|
|
1747
|
+
tasks.forEach((t, i) => {
|
|
1748
|
+
if (subtree.has(t.id)) last = i;
|
|
1749
|
+
});
|
|
1750
|
+
return { type: "add-task", task: full, index: last + 1 };
|
|
1751
|
+
}
|
|
1649
1752
|
|
|
1650
1753
|
// src/a11y/index.ts
|
|
1651
1754
|
var DEP_WORDS = {
|
|
@@ -1858,14 +1961,21 @@ exports.formatTime = formatTime;
|
|
|
1858
1961
|
exports.ganttTable = ganttTable;
|
|
1859
1962
|
exports.hitTestBar = hitTestBar;
|
|
1860
1963
|
exports.importProject = importProject;
|
|
1964
|
+
exports.indentOperation = indentOperation;
|
|
1965
|
+
exports.insertTaskOperation = insertTaskOperation;
|
|
1861
1966
|
exports.isAncestor = isAncestor;
|
|
1862
1967
|
exports.isDateOnly = isDateOnly;
|
|
1863
1968
|
exports.leavesOf = leavesOf;
|
|
1864
1969
|
exports.linkOperation = linkOperation;
|
|
1865
1970
|
exports.nonWorkingSpans = nonWorkingSpans;
|
|
1971
|
+
exports.outdentOperations = outdentOperations;
|
|
1972
|
+
exports.parseDuration = parseDuration;
|
|
1866
1973
|
exports.parseTime = parseTime;
|
|
1867
1974
|
exports.pathFromPoints = pathFromPoints;
|
|
1975
|
+
exports.predecessorOperations = predecessorOperations;
|
|
1868
1976
|
exports.progressAt = progressAt;
|
|
1977
|
+
exports.rescheduleDates = rescheduleDates;
|
|
1978
|
+
exports.rescheduleOperation = rescheduleOperation;
|
|
1869
1979
|
exports.routeDependency = routeDependency;
|
|
1870
1980
|
exports.scaleTicks = scaleTicks;
|
|
1871
1981
|
exports.scheduleProject = scheduleProject;
|
package/dist/index.d.cts
CHANGED
|
@@ -139,6 +139,60 @@ declare function dependencyTypeFor(fromSide: LinkSide, toSide: LinkSide): Depend
|
|
|
139
139
|
/** A reasonably unique id for new tasks and dependencies. */
|
|
140
140
|
declare function createId(prefix?: string): string;
|
|
141
141
|
declare function linkOperation(from: string, to: string, type?: DependencyType, extra?: Partial<Omit<GanttDependency, 'from' | 'to' | 'type'>>): GanttOperation;
|
|
142
|
+
/** The `update-task` member of `GanttOperation`. */
|
|
143
|
+
type UpdateTaskOperation = Extract<GanttOperation, {
|
|
144
|
+
type: 'update-task';
|
|
145
|
+
}>;
|
|
146
|
+
interface TaskDateEdit {
|
|
147
|
+
/** New start. With a day (or coarser) snap it names a day: work starts on it. */
|
|
148
|
+
start?: WallTime;
|
|
149
|
+
/** New finish. With a day snap it names the day the work ends on. */
|
|
150
|
+
finish?: WallTime;
|
|
151
|
+
/** New length in working days; wins over `finish` */
|
|
152
|
+
duration?: number;
|
|
153
|
+
}
|
|
154
|
+
/** Dates a form edit resolves to: snapped to working time, finish never before start. */
|
|
155
|
+
declare function rescheduleDates(ctx: EditContext, edit: TaskDateEdit): EditPreview;
|
|
156
|
+
/**
|
|
157
|
+
* The `update-task` operation for dates typed into a form, keeping the
|
|
158
|
+
* consumer's data shape like drags do. Moving the start keeps the length
|
|
159
|
+
* unless a new finish or duration comes with it. Returns null when nothing
|
|
160
|
+
* changes. A finish before the start is clamped to the start.
|
|
161
|
+
*/
|
|
162
|
+
declare function rescheduleOperation(ctx: EditContext, edit: TaskDateEdit): UpdateTaskOperation | null;
|
|
163
|
+
/** A predecessor row in a form. Rows without an `id` are new links. */
|
|
164
|
+
interface PredecessorDraft {
|
|
165
|
+
id?: string;
|
|
166
|
+
from: string;
|
|
167
|
+
type?: DependencyType;
|
|
168
|
+
/** Working days; negative is a lead */
|
|
169
|
+
lag?: number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Operations turning a task's incoming dependencies into `drafts`: removals
|
|
173
|
+
* first, then updates, then additions, so swapping a link never trips the
|
|
174
|
+
* duplicate check.
|
|
175
|
+
*/
|
|
176
|
+
declare function predecessorOperations(taskId: string, dependencies: GanttDependency[], drafts: PredecessorDraft[]): GanttOperation[];
|
|
177
|
+
/**
|
|
178
|
+
* Working days in a typed duration: `3`, `3d`, `1.5 days`, `4h`, `2w`
|
|
179
|
+
* (a week is five working days). Undefined when it doesn't parse.
|
|
180
|
+
*/
|
|
181
|
+
declare function parseDuration(text: string, minutesPerDay?: number): number | undefined;
|
|
182
|
+
/** Make a task the last child of the sibling above it. Null when there is none. */
|
|
183
|
+
declare function indentOperation(tasks: GanttTask[], id: string): UpdateTaskOperation | null;
|
|
184
|
+
/**
|
|
185
|
+
* Move a task up one level, right after its old parent. Like most project
|
|
186
|
+
* tools, the siblings below it become its children, so no row moves.
|
|
187
|
+
*/
|
|
188
|
+
declare function outdentOperations(tasks: GanttTask[], id: string): UpdateTaskOperation[];
|
|
189
|
+
/**
|
|
190
|
+
* Insert a task as the next sibling of `afterId` (after its whole subtree),
|
|
191
|
+
* or at the end when `afterId` is null or unknown.
|
|
192
|
+
*/
|
|
193
|
+
declare function insertTaskOperation(tasks: GanttTask[], afterId: string | null, task: Omit<GanttTask, 'id' | 'parentId'> & {
|
|
194
|
+
id?: string;
|
|
195
|
+
}): GanttOperation;
|
|
142
196
|
|
|
143
197
|
/**
|
|
144
198
|
* Screen-reader text and tabular fallbacks.
|
|
@@ -191,4 +245,4 @@ declare function importProject(input: string | unknown): GanttProjectData;
|
|
|
191
245
|
/** RFC 4180 CSV for a table. */
|
|
192
246
|
declare function tableToCsv(table: GanttTable): string;
|
|
193
247
|
|
|
194
|
-
export { DependencyType, type DescribeOptions, type EditContext, type EditMode, type EditPreview, GanttCalendar, GanttChange, GanttDependency, GanttEditError, type GanttModel, type GanttModelOptions, type GanttModelState, GanttOperation, type GanttProjectData, GanttRow, type GanttTable, type GanttTableColumn, GanttTask, type LinkSide, ScheduleOptions, ScheduleResult, ScheduledTask, type SelectMode, TaskTree, TimeScale, TimeUnit, WallTime, WorkCalendar, createDragSession, createGanttModel, createId, dependencyTypeFor, describeSchedule, describeTask, editOperation, exportProject, flattenTasks, formatDuration, ganttTable, importProject, linkOperation, progressAt, shiftTask, tableToCsv, unitsForDelta };
|
|
248
|
+
export { DependencyType, type DescribeOptions, type EditContext, type EditMode, type EditPreview, GanttCalendar, GanttChange, GanttDependency, GanttEditError, type GanttModel, type GanttModelOptions, type GanttModelState, GanttOperation, type GanttProjectData, GanttRow, type GanttTable, type GanttTableColumn, GanttTask, type LinkSide, type PredecessorDraft, ScheduleOptions, ScheduleResult, ScheduledTask, type SelectMode, type TaskDateEdit, TaskTree, TimeScale, TimeUnit, type UpdateTaskOperation, WallTime, WorkCalendar, createDragSession, createGanttModel, createId, dependencyTypeFor, describeSchedule, describeTask, editOperation, exportProject, flattenTasks, formatDuration, ganttTable, importProject, indentOperation, insertTaskOperation, linkOperation, outdentOperations, parseDuration, predecessorOperations, progressAt, rescheduleDates, rescheduleOperation, shiftTask, tableToCsv, unitsForDelta };
|
package/dist/index.d.ts
CHANGED
|
@@ -139,6 +139,60 @@ declare function dependencyTypeFor(fromSide: LinkSide, toSide: LinkSide): Depend
|
|
|
139
139
|
/** A reasonably unique id for new tasks and dependencies. */
|
|
140
140
|
declare function createId(prefix?: string): string;
|
|
141
141
|
declare function linkOperation(from: string, to: string, type?: DependencyType, extra?: Partial<Omit<GanttDependency, 'from' | 'to' | 'type'>>): GanttOperation;
|
|
142
|
+
/** The `update-task` member of `GanttOperation`. */
|
|
143
|
+
type UpdateTaskOperation = Extract<GanttOperation, {
|
|
144
|
+
type: 'update-task';
|
|
145
|
+
}>;
|
|
146
|
+
interface TaskDateEdit {
|
|
147
|
+
/** New start. With a day (or coarser) snap it names a day: work starts on it. */
|
|
148
|
+
start?: WallTime;
|
|
149
|
+
/** New finish. With a day snap it names the day the work ends on. */
|
|
150
|
+
finish?: WallTime;
|
|
151
|
+
/** New length in working days; wins over `finish` */
|
|
152
|
+
duration?: number;
|
|
153
|
+
}
|
|
154
|
+
/** Dates a form edit resolves to: snapped to working time, finish never before start. */
|
|
155
|
+
declare function rescheduleDates(ctx: EditContext, edit: TaskDateEdit): EditPreview;
|
|
156
|
+
/**
|
|
157
|
+
* The `update-task` operation for dates typed into a form, keeping the
|
|
158
|
+
* consumer's data shape like drags do. Moving the start keeps the length
|
|
159
|
+
* unless a new finish or duration comes with it. Returns null when nothing
|
|
160
|
+
* changes. A finish before the start is clamped to the start.
|
|
161
|
+
*/
|
|
162
|
+
declare function rescheduleOperation(ctx: EditContext, edit: TaskDateEdit): UpdateTaskOperation | null;
|
|
163
|
+
/** A predecessor row in a form. Rows without an `id` are new links. */
|
|
164
|
+
interface PredecessorDraft {
|
|
165
|
+
id?: string;
|
|
166
|
+
from: string;
|
|
167
|
+
type?: DependencyType;
|
|
168
|
+
/** Working days; negative is a lead */
|
|
169
|
+
lag?: number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Operations turning a task's incoming dependencies into `drafts`: removals
|
|
173
|
+
* first, then updates, then additions, so swapping a link never trips the
|
|
174
|
+
* duplicate check.
|
|
175
|
+
*/
|
|
176
|
+
declare function predecessorOperations(taskId: string, dependencies: GanttDependency[], drafts: PredecessorDraft[]): GanttOperation[];
|
|
177
|
+
/**
|
|
178
|
+
* Working days in a typed duration: `3`, `3d`, `1.5 days`, `4h`, `2w`
|
|
179
|
+
* (a week is five working days). Undefined when it doesn't parse.
|
|
180
|
+
*/
|
|
181
|
+
declare function parseDuration(text: string, minutesPerDay?: number): number | undefined;
|
|
182
|
+
/** Make a task the last child of the sibling above it. Null when there is none. */
|
|
183
|
+
declare function indentOperation(tasks: GanttTask[], id: string): UpdateTaskOperation | null;
|
|
184
|
+
/**
|
|
185
|
+
* Move a task up one level, right after its old parent. Like most project
|
|
186
|
+
* tools, the siblings below it become its children, so no row moves.
|
|
187
|
+
*/
|
|
188
|
+
declare function outdentOperations(tasks: GanttTask[], id: string): UpdateTaskOperation[];
|
|
189
|
+
/**
|
|
190
|
+
* Insert a task as the next sibling of `afterId` (after its whole subtree),
|
|
191
|
+
* or at the end when `afterId` is null or unknown.
|
|
192
|
+
*/
|
|
193
|
+
declare function insertTaskOperation(tasks: GanttTask[], afterId: string | null, task: Omit<GanttTask, 'id' | 'parentId'> & {
|
|
194
|
+
id?: string;
|
|
195
|
+
}): GanttOperation;
|
|
142
196
|
|
|
143
197
|
/**
|
|
144
198
|
* Screen-reader text and tabular fallbacks.
|
|
@@ -191,4 +245,4 @@ declare function importProject(input: string | unknown): GanttProjectData;
|
|
|
191
245
|
/** RFC 4180 CSV for a table. */
|
|
192
246
|
declare function tableToCsv(table: GanttTable): string;
|
|
193
247
|
|
|
194
|
-
export { DependencyType, type DescribeOptions, type EditContext, type EditMode, type EditPreview, GanttCalendar, GanttChange, GanttDependency, GanttEditError, type GanttModel, type GanttModelOptions, type GanttModelState, GanttOperation, type GanttProjectData, GanttRow, type GanttTable, type GanttTableColumn, GanttTask, type LinkSide, ScheduleOptions, ScheduleResult, ScheduledTask, type SelectMode, TaskTree, TimeScale, TimeUnit, WallTime, WorkCalendar, createDragSession, createGanttModel, createId, dependencyTypeFor, describeSchedule, describeTask, editOperation, exportProject, flattenTasks, formatDuration, ganttTable, importProject, linkOperation, progressAt, shiftTask, tableToCsv, unitsForDelta };
|
|
248
|
+
export { DependencyType, type DescribeOptions, type EditContext, type EditMode, type EditPreview, GanttCalendar, GanttChange, GanttDependency, GanttEditError, type GanttModel, type GanttModelOptions, type GanttModelState, GanttOperation, type GanttProjectData, GanttRow, type GanttTable, type GanttTableColumn, GanttTask, type LinkSide, type PredecessorDraft, ScheduleOptions, ScheduleResult, ScheduledTask, type SelectMode, type TaskDateEdit, TaskTree, TimeScale, TimeUnit, type UpdateTaskOperation, WallTime, WorkCalendar, createDragSession, createGanttModel, createId, dependencyTypeFor, describeSchedule, describeTask, editOperation, exportProject, flattenTasks, formatDuration, ganttTable, importProject, indentOperation, insertTaskOperation, linkOperation, outdentOperations, parseDuration, predecessorOperations, progressAt, rescheduleDates, rescheduleOperation, shiftTask, tableToCsv, unitsForDelta };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import './chunk-FXPGR372.js';
|
|
2
|
-
import { buildTaskTree, scheduleProject, wouldCreateCycle
|
|
2
|
+
import { buildTaskTree, descendantsOf, scheduleProject, wouldCreateCycle } from './chunk-FVSW2GH6.js';
|
|
3
3
|
export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from './chunk-FVSW2GH6.js';
|
|
4
4
|
export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from './chunk-7OPVG2DP.js';
|
|
5
5
|
import { addUnits } from './chunk-MDRXY4HU.js';
|
|
6
6
|
export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from './chunk-MDRXY4HU.js';
|
|
7
|
-
import { DAY, HOUR, formatTime, parseTime, isDateOnly, createTimeFormatter } from './chunk-LPH2V7XM.js';
|
|
7
|
+
import { DAY, HOUR, formatTime, startOfDay, parseTime, isDateOnly, createTimeFormatter } from './chunk-LPH2V7XM.js';
|
|
8
8
|
export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from './chunk-LPH2V7XM.js';
|
|
9
9
|
|
|
10
10
|
// src/model/tree.ts
|
|
@@ -462,6 +462,109 @@ function linkOperation(from, to, type = "FS", extra = {}) {
|
|
|
462
462
|
dependency: { id: extra.id ?? createId("dep"), from, to, type, ...extra }
|
|
463
463
|
};
|
|
464
464
|
}
|
|
465
|
+
function rescheduleDates(ctx, edit) {
|
|
466
|
+
const { task, calendar: cal, minutesPerDay } = ctx;
|
|
467
|
+
const byDay = ctx.snap !== "hour";
|
|
468
|
+
const start = edit.start === void 0 ? task.start : cal.nextWorking(byDay ? startOfDay(edit.start) : edit.start);
|
|
469
|
+
let finish;
|
|
470
|
+
if (edit.duration !== void 0) {
|
|
471
|
+
finish = cal.add(start, Math.max(0, edit.duration) * minutesPerDay);
|
|
472
|
+
} else if (edit.finish !== void 0) {
|
|
473
|
+
finish = cal.prevWorking(byDay ? startOfDay(edit.finish) + DAY : edit.finish);
|
|
474
|
+
} else {
|
|
475
|
+
finish = task.type === "milestone" ? start : cal.add(start, task.duration);
|
|
476
|
+
}
|
|
477
|
+
finish = Math.max(start, finish);
|
|
478
|
+
return { start, finish, changed: start !== task.start || finish !== task.finish };
|
|
479
|
+
}
|
|
480
|
+
function rescheduleOperation(ctx, edit) {
|
|
481
|
+
const { task, calendar: cal } = ctx;
|
|
482
|
+
const byDay = ctx.snap !== "hour";
|
|
483
|
+
const wasMilestone = task.type === "milestone";
|
|
484
|
+
const preview = rescheduleDates(ctx, edit);
|
|
485
|
+
const { start, finish } = preview;
|
|
486
|
+
if (!preview.changed) return null;
|
|
487
|
+
const moved = start !== task.start;
|
|
488
|
+
const length = cal.between(start, finish);
|
|
489
|
+
const resized = length !== task.duration;
|
|
490
|
+
const c = {
|
|
491
|
+
...ctx,
|
|
492
|
+
snap: byDay ? "day" : "hour",
|
|
493
|
+
task: wasMilestone && length > 0 ? { ...task, type: "task" } : task
|
|
494
|
+
};
|
|
495
|
+
const patch = {};
|
|
496
|
+
if (moved) Object.assign(patch, patchOf(editOperation(c, "move", preview)));
|
|
497
|
+
if (resized) {
|
|
498
|
+
if (length === 0) patch.duration = 0;
|
|
499
|
+
else Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
|
|
500
|
+
}
|
|
501
|
+
return Object.keys(patch).length ? { type: "update-task", id: ctx.source.id, patch } : null;
|
|
502
|
+
}
|
|
503
|
+
var patchOf = (op) => op?.type === "update-task" ? op.patch : {};
|
|
504
|
+
function predecessorOperations(taskId, dependencies, drafts) {
|
|
505
|
+
const existing = dependencies.filter((d) => d.to === taskId);
|
|
506
|
+
const kept = new Set(drafts.map((d) => d.id).filter(Boolean));
|
|
507
|
+
const ops = existing.filter((d) => !kept.has(d.id)).map((d) => ({ type: "remove-dependency", id: d.id }));
|
|
508
|
+
const adds = [];
|
|
509
|
+
for (const draft of drafts) {
|
|
510
|
+
const type = draft.type ?? "FS";
|
|
511
|
+
const lag = draft.lag ?? 0;
|
|
512
|
+
const prev = draft.id ? existing.find((d) => d.id === draft.id) : void 0;
|
|
513
|
+
if (!prev) {
|
|
514
|
+
adds.push(linkOperation(draft.from, taskId, type, lag ? { lag } : {}));
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
const patch = {};
|
|
518
|
+
if (prev.from !== draft.from) patch.from = draft.from;
|
|
519
|
+
if ((prev.type ?? "FS") !== type) patch.type = type;
|
|
520
|
+
if ((prev.lag ?? 0) !== lag) patch.lag = lag;
|
|
521
|
+
if (Object.keys(patch).length) ops.push({ type: "update-dependency", id: prev.id, patch });
|
|
522
|
+
}
|
|
523
|
+
return [...ops, ...adds];
|
|
524
|
+
}
|
|
525
|
+
function parseDuration(text, minutesPerDay = 480) {
|
|
526
|
+
const m = /^\s*(\d+(?:[.,]\d+)?)\s*([a-z]*)\s*$/i.exec(text);
|
|
527
|
+
if (!m) return void 0;
|
|
528
|
+
const n = Number(m[1].replace(",", "."));
|
|
529
|
+
const unit = m[2].toLowerCase();
|
|
530
|
+
if (!unit || /^d(ays?)?$/.test(unit)) return n;
|
|
531
|
+
if (/^h((ou)?rs?)?$/.test(unit)) return round(n * 60 / minutesPerDay);
|
|
532
|
+
if (/^w((ee)?ks?)?$/.test(unit)) return n * 5;
|
|
533
|
+
return void 0;
|
|
534
|
+
}
|
|
535
|
+
function indentOperation(tasks, id) {
|
|
536
|
+
const tree = buildTaskTree(tasks);
|
|
537
|
+
const siblings = tree.children.get(tree.parent.get(id) ?? null) ?? [];
|
|
538
|
+
const i = siblings.indexOf(id);
|
|
539
|
+
if (i <= 0) return null;
|
|
540
|
+
return { type: "update-task", id, patch: { parentId: siblings[i - 1] } };
|
|
541
|
+
}
|
|
542
|
+
function outdentOperations(tasks, id) {
|
|
543
|
+
const tree = buildTaskTree(tasks);
|
|
544
|
+
const parent = tree.parent.get(id) ?? null;
|
|
545
|
+
if (parent === null) return [];
|
|
546
|
+
const grand = tree.parent.get(parent) ?? null;
|
|
547
|
+
const siblings = tree.children.get(parent) ?? [];
|
|
548
|
+
const below = siblings.slice(siblings.indexOf(id) + 1);
|
|
549
|
+
return [
|
|
550
|
+
{ type: "update-task", id, patch: { parentId: grand ?? void 0 } },
|
|
551
|
+
...below.map(
|
|
552
|
+
(s) => ({ type: "update-task", id: s, patch: { parentId: id } })
|
|
553
|
+
)
|
|
554
|
+
];
|
|
555
|
+
}
|
|
556
|
+
function insertTaskOperation(tasks, afterId, task) {
|
|
557
|
+
const after = afterId ? tasks.find((t) => t.id === afterId) : void 0;
|
|
558
|
+
const full = { ...task, id: task.id ?? createId("task") };
|
|
559
|
+
if (!after) return { type: "add-task", task: full };
|
|
560
|
+
if (after.parentId) full.parentId = after.parentId;
|
|
561
|
+
const subtree = /* @__PURE__ */ new Set([after.id, ...descendantsOf(buildTaskTree(tasks), after.id)]);
|
|
562
|
+
let last = -1;
|
|
563
|
+
tasks.forEach((t, i) => {
|
|
564
|
+
if (subtree.has(t.id)) last = i;
|
|
565
|
+
});
|
|
566
|
+
return { type: "add-task", task: full, index: last + 1 };
|
|
567
|
+
}
|
|
465
568
|
|
|
466
569
|
// src/a11y/index.ts
|
|
467
570
|
var DEP_WORDS = {
|
|
@@ -637,4 +740,4 @@ function tableToCsv(table) {
|
|
|
637
740
|
return lines.join("\r\n");
|
|
638
741
|
}
|
|
639
742
|
|
|
640
|
-
export { GanttEditError, createDragSession, createGanttModel, createId, dependencyTypeFor, describeSchedule, describeTask, editOperation, exportProject, flattenTasks, formatDuration, ganttTable, importProject, linkOperation, progressAt, shiftTask, tableToCsv, unitsForDelta };
|
|
743
|
+
export { GanttEditError, createDragSession, createGanttModel, createId, dependencyTypeFor, describeSchedule, describeTask, editOperation, exportProject, flattenTasks, formatDuration, ganttTable, importProject, indentOperation, insertTaskOperation, linkOperation, outdentOperations, parseDuration, predecessorOperations, progressAt, rescheduleDates, rescheduleOperation, shiftTask, tableToCsv, unitsForDelta };
|
package/package.json
CHANGED