@classic-homes/gantt-core 0.3.2 → 0.3.4
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/calendar/index.cjs +19 -19
- package/dist/calendar/index.js +2 -2
- package/dist/{chunk-LPH2V7XM.js → chunk-FV63P7UY.js} +19 -19
- package/dist/{chunk-742OJYSO.js → chunk-INRQCGC4.js} +93 -51
- package/dist/{chunk-MDRXY4HU.js → chunk-JS3ZLEZJ.js} +1 -1
- package/dist/{chunk-3GIZDFDV.js → chunk-LQGY5EOM.js} +1 -1
- package/dist/index.cjs +324 -134
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +221 -73
- package/dist/layout/index.js +2 -2
- package/dist/scheduling/index.cjs +106 -60
- package/dist/scheduling/index.js +3 -3
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -32,7 +32,7 @@ interface GanttModelOptions {
|
|
|
32
32
|
schedule?: ScheduleOptions;
|
|
33
33
|
/** Collapsed summaries. Everything is expanded by default. */
|
|
34
34
|
collapsed?: Iterable<string>;
|
|
35
|
-
/** Maximum undo steps (default 100) */
|
|
35
|
+
/** Maximum undo steps (default 100); 0 disables history. */
|
|
36
36
|
historyLimit?: number;
|
|
37
37
|
}
|
|
38
38
|
interface GanttModelState {
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ interface GanttModelOptions {
|
|
|
32
32
|
schedule?: ScheduleOptions;
|
|
33
33
|
/** Collapsed summaries. Everything is expanded by default. */
|
|
34
34
|
collapsed?: Iterable<string>;
|
|
35
|
-
/** Maximum undo steps (default 100) */
|
|
35
|
+
/** Maximum undo steps (default 100); 0 disables history. */
|
|
36
36
|
historyLimit?: number;
|
|
37
37
|
}
|
|
38
38
|
interface GanttModelState {
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,61 @@
|
|
|
1
1
|
import './chunk-FXPGR372.js';
|
|
2
|
-
import { buildTaskTree, descendantsOf, scheduleProject, wouldCreateCycle } from './chunk-
|
|
3
|
-
export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from './chunk-
|
|
4
|
-
export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from './chunk-
|
|
5
|
-
import { addUnits } from './chunk-
|
|
6
|
-
export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from './chunk-
|
|
7
|
-
import { DAY, HOUR,
|
|
8
|
-
export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from './chunk-
|
|
2
|
+
import { buildTaskTree, descendantsOf, scheduleProject, wouldCreateCycle } from './chunk-INRQCGC4.js';
|
|
3
|
+
export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from './chunk-INRQCGC4.js';
|
|
4
|
+
export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from './chunk-LQGY5EOM.js';
|
|
5
|
+
import { addUnits } from './chunk-JS3ZLEZJ.js';
|
|
6
|
+
export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from './chunk-JS3ZLEZJ.js';
|
|
7
|
+
import { DAY, HOUR, startOfDay, MINUTE, formatTime, parseTime, toLocalDate, isDateOnly, createTimeFormatter } from './chunk-FV63P7UY.js';
|
|
8
|
+
export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from './chunk-FV63P7UY.js';
|
|
9
9
|
|
|
10
10
|
// src/model/tree.ts
|
|
11
11
|
function flattenTasks(tasks, isExpanded, tree = buildTaskTree(tasks)) {
|
|
12
12
|
const byId = new Map(tasks.map((t) => [t.id, t]));
|
|
13
13
|
const rows = [];
|
|
14
14
|
const wbs = /* @__PURE__ */ new Map();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
const stack = [
|
|
16
|
+
{
|
|
17
|
+
parentId: null,
|
|
18
|
+
prefix: "",
|
|
19
|
+
level: 1,
|
|
20
|
+
visible: true,
|
|
21
|
+
kids: tree.children.get(null) ?? [],
|
|
22
|
+
index: 0
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
while (stack.length) {
|
|
26
|
+
const frame = stack[stack.length - 1];
|
|
27
|
+
if (frame.index >= frame.kids.length) {
|
|
28
|
+
stack.pop();
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const i = frame.index++;
|
|
32
|
+
const id = frame.kids[i];
|
|
33
|
+
const code = frame.prefix ? `${frame.prefix}.${i + 1}` : String(i + 1);
|
|
34
|
+
wbs.set(id, code);
|
|
35
|
+
const kids = tree.children.get(id) ?? [];
|
|
36
|
+
const hasChildren = kids.length > 0;
|
|
37
|
+
const expanded = hasChildren && isExpanded(id);
|
|
38
|
+
if (frame.visible)
|
|
39
|
+
rows.push({
|
|
40
|
+
id,
|
|
41
|
+
task: byId.get(id),
|
|
42
|
+
index: rows.length,
|
|
43
|
+
level: frame.level,
|
|
44
|
+
wbs: code,
|
|
45
|
+
hasChildren,
|
|
46
|
+
expanded,
|
|
47
|
+
parentId: frame.parentId
|
|
48
|
+
});
|
|
49
|
+
if (hasChildren)
|
|
50
|
+
stack.push({
|
|
51
|
+
parentId: id,
|
|
52
|
+
prefix: code,
|
|
53
|
+
level: frame.level + 1,
|
|
54
|
+
visible: frame.visible && expanded,
|
|
55
|
+
kids,
|
|
56
|
+
index: 0
|
|
57
|
+
});
|
|
58
|
+
}
|
|
38
59
|
return { rows, wbs };
|
|
39
60
|
}
|
|
40
61
|
|
|
@@ -52,13 +73,29 @@ function applyOperation(data, op) {
|
|
|
52
73
|
const fail = (msg) => {
|
|
53
74
|
throw new GanttEditError(msg, op);
|
|
54
75
|
};
|
|
76
|
+
const tree = buildTaskTree(tasks);
|
|
77
|
+
const protectedIds = /* @__PURE__ */ new Set();
|
|
78
|
+
const protectedStack = tasks.filter((t) => t.readonly).map((t) => t.id);
|
|
79
|
+
while (protectedStack.length) {
|
|
80
|
+
const id = protectedStack.pop();
|
|
81
|
+
if (protectedIds.has(id)) continue;
|
|
82
|
+
protectedIds.add(id);
|
|
83
|
+
for (const child of tree.children.get(id) ?? []) protectedStack.push(child);
|
|
84
|
+
}
|
|
85
|
+
const writable = (id) => {
|
|
86
|
+
if (id != null && protectedIds.has(id)) fail(`Task "${id}" is read-only`);
|
|
87
|
+
};
|
|
55
88
|
switch (op.type) {
|
|
56
89
|
case "update-task": {
|
|
57
90
|
const i = tasks.findIndex((t) => t.id === op.id);
|
|
58
91
|
if (i < 0) fail(`Unknown task "${op.id}"`);
|
|
59
92
|
const prev = tasks[i];
|
|
93
|
+
writable(op.id);
|
|
94
|
+
writable(op.patch.parentId);
|
|
95
|
+
if ("parentId" in op.patch && op.patch.parentId !== prev.parentId) {
|
|
96
|
+
for (const id of descendantsOf(tree, op.id)) writable(id);
|
|
97
|
+
}
|
|
60
98
|
if ("parentId" in op.patch && op.patch.parentId) {
|
|
61
|
-
const tree = buildTaskTree(tasks);
|
|
62
99
|
if (op.patch.parentId === op.id || descendantsOf(tree, op.id).includes(op.patch.parentId)) {
|
|
63
100
|
fail("A task cannot be moved under itself");
|
|
64
101
|
}
|
|
@@ -82,6 +119,7 @@ function applyOperation(data, op) {
|
|
|
82
119
|
case "add-task": {
|
|
83
120
|
if (!op.task.id) fail("Task needs an id");
|
|
84
121
|
if (tasks.some((t) => t.id === op.task.id)) fail(`Task "${op.task.id}" already exists`);
|
|
122
|
+
writable(op.task.parentId);
|
|
85
123
|
const copy = tasks.slice();
|
|
86
124
|
const index = op.index === void 0 ? copy.length : Math.max(0, Math.min(op.index, copy.length));
|
|
87
125
|
copy.splice(index, 0, op.task);
|
|
@@ -93,26 +131,34 @@ function applyOperation(data, op) {
|
|
|
93
131
|
case "remove-task": {
|
|
94
132
|
const i = tasks.findIndex((t) => t.id === op.id);
|
|
95
133
|
if (i < 0) fail(`Unknown task "${op.id}"`);
|
|
96
|
-
const tree = buildTaskTree(tasks);
|
|
97
134
|
const doomed = /* @__PURE__ */ new Set([op.id, ...descendantsOf(tree, op.id)]);
|
|
135
|
+
for (const id of doomed) writable(id);
|
|
136
|
+
for (const d of dependencies) {
|
|
137
|
+
if (doomed.has(d.from) || doomed.has(d.to)) {
|
|
138
|
+
writable(d.from);
|
|
139
|
+
writable(d.to);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
98
142
|
const inverse = [];
|
|
99
143
|
tasks.forEach((t, index) => {
|
|
100
144
|
if (doomed.has(t.id)) inverse.push({ type: "add-task", task: t, index });
|
|
101
145
|
});
|
|
102
|
-
const removedDeps = dependencies.filter((d) => doomed.has(d.from) || doomed.has(d.to));
|
|
103
146
|
dependencies.forEach((d, index) => {
|
|
104
|
-
if (
|
|
147
|
+
if (doomed.has(d.from) || doomed.has(d.to))
|
|
148
|
+
inverse.push({ type: "add-dependency", dependency: d, index });
|
|
105
149
|
});
|
|
106
150
|
return {
|
|
107
151
|
data: {
|
|
108
152
|
tasks: tasks.filter((t) => !doomed.has(t.id)),
|
|
109
|
-
dependencies: dependencies.filter((d) => !
|
|
153
|
+
dependencies: dependencies.filter((d) => !doomed.has(d.from) && !doomed.has(d.to))
|
|
110
154
|
},
|
|
111
155
|
inverse
|
|
112
156
|
};
|
|
113
157
|
}
|
|
114
158
|
case "add-dependency": {
|
|
115
159
|
const d = op.dependency;
|
|
160
|
+
writable(d.from);
|
|
161
|
+
writable(d.to);
|
|
116
162
|
if (!d.id) fail("Dependency needs an id");
|
|
117
163
|
if (dependencies.some((x) => x.id === d.id)) fail(`Dependency "${d.id}" already exists`);
|
|
118
164
|
if (!tasks.some((t) => t.id === d.from) || !tasks.some((t) => t.id === d.to)) {
|
|
@@ -134,7 +180,14 @@ function applyOperation(data, op) {
|
|
|
134
180
|
const i = dependencies.findIndex((d) => d.id === op.id);
|
|
135
181
|
if (i < 0) fail(`Unknown dependency "${op.id}"`);
|
|
136
182
|
const prev = dependencies[i];
|
|
183
|
+
writable(prev.from);
|
|
184
|
+
writable(prev.to);
|
|
137
185
|
const next = { ...prev, ...op.patch };
|
|
186
|
+
writable(next.from);
|
|
187
|
+
writable(next.to);
|
|
188
|
+
for (const [k, v] of Object.entries(op.patch)) {
|
|
189
|
+
if (v === void 0) delete next[k];
|
|
190
|
+
}
|
|
138
191
|
if (next.from !== prev.from || next.to !== prev.to) {
|
|
139
192
|
const others = dependencies.filter((_, j) => j !== i);
|
|
140
193
|
if (wouldCreateCycle(tasks, others, next.from, next.to))
|
|
@@ -153,6 +206,8 @@ function applyOperation(data, op) {
|
|
|
153
206
|
case "remove-dependency": {
|
|
154
207
|
const index = dependencies.findIndex((d) => d.id === op.id);
|
|
155
208
|
if (index < 0) fail(`Unknown dependency "${op.id}"`);
|
|
209
|
+
writable(dependencies[index].from);
|
|
210
|
+
writable(dependencies[index].to);
|
|
156
211
|
return {
|
|
157
212
|
data: { tasks, dependencies: dependencies.filter((d) => d.id !== op.id) },
|
|
158
213
|
inverse: [{ type: "add-dependency", dependency: dependencies[index], index }]
|
|
@@ -191,19 +246,61 @@ function createGanttModel(options) {
|
|
|
191
246
|
let calendars = options.calendars ?? [];
|
|
192
247
|
let scheduleOptions = options.schedule ?? {};
|
|
193
248
|
const historyLimit = options.historyLimit ?? 100;
|
|
249
|
+
if (!Number.isSafeInteger(historyLimit) || historyLimit < 0)
|
|
250
|
+
throw new RangeError("historyLimit must be a nonnegative integer");
|
|
194
251
|
const collapsed = new Set(options.collapsed ?? []);
|
|
195
252
|
let selection = /* @__PURE__ */ new Set();
|
|
196
253
|
let focusedId = null;
|
|
197
254
|
let undoStack = [];
|
|
198
255
|
let redoStack = [];
|
|
199
256
|
let version = 0;
|
|
200
|
-
const run = (d) => scheduleProject(d.tasks, d.dependencies,
|
|
257
|
+
const run = (d, c = calendars, o = scheduleOptions) => scheduleProject(d.tasks, d.dependencies, c, o);
|
|
258
|
+
const prepare = (operations) => {
|
|
259
|
+
try {
|
|
260
|
+
const candidate = applyAll(data, operations);
|
|
261
|
+
for (const task of candidate.data.tasks) {
|
|
262
|
+
if (!task.id || typeof task.name !== "string") throw new Error("Task needs an id and name");
|
|
263
|
+
if (task.duration !== void 0 && (!Number.isFinite(task.duration) || task.duration < 0))
|
|
264
|
+
throw new Error(`Task "${task.id}" needs a finite, nonnegative duration`);
|
|
265
|
+
if (task.progress !== void 0 && (!Number.isFinite(task.progress) || task.progress < 0 || task.progress > 100))
|
|
266
|
+
throw new Error(`Task "${task.id}" progress must be between 0 and 100`);
|
|
267
|
+
}
|
|
268
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
269
|
+
for (const dep of candidate.data.dependencies) {
|
|
270
|
+
if (!dep.id) throw new Error("Dependency needs an id");
|
|
271
|
+
if (dep.type !== void 0 && !["FS", "SS", "FF", "SF"].includes(dep.type))
|
|
272
|
+
throw new Error("Unknown dependency type");
|
|
273
|
+
if (dep.lag !== void 0 && !Number.isFinite(dep.lag))
|
|
274
|
+
throw new Error("Dependency needs a finite lag");
|
|
275
|
+
const pair = JSON.stringify([dep.from, dep.to]);
|
|
276
|
+
if (pairs.has(pair)) throw new Error("These tasks are already linked");
|
|
277
|
+
pairs.add(pair);
|
|
278
|
+
}
|
|
279
|
+
const result = run(candidate.data);
|
|
280
|
+
const invalid = result.conflicts.find(
|
|
281
|
+
(c) => c.kind === "cycle" || c.kind === "invalid-dependency"
|
|
282
|
+
);
|
|
283
|
+
if (invalid) throw new Error(invalid.message);
|
|
284
|
+
return { ...candidate, schedule: result };
|
|
285
|
+
} catch (err) {
|
|
286
|
+
if (err instanceof GanttEditError || !operations.length) throw err;
|
|
287
|
+
throw new GanttEditError(err instanceof Error ? err.message : String(err), operations[0]);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
201
290
|
let schedule = run(data);
|
|
291
|
+
let flattenedTasks;
|
|
292
|
+
let flattened;
|
|
293
|
+
let rowsDirty = true;
|
|
202
294
|
let state = build();
|
|
203
295
|
const listeners = /* @__PURE__ */ new Set();
|
|
204
296
|
const changeListeners = /* @__PURE__ */ new Set();
|
|
205
297
|
function build() {
|
|
206
|
-
|
|
298
|
+
if (rowsDirty || flattenedTasks !== data.tasks) {
|
|
299
|
+
flattened = flattenTasks(data.tasks, (id) => !collapsed.has(id));
|
|
300
|
+
flattenedTasks = data.tasks;
|
|
301
|
+
rowsDirty = false;
|
|
302
|
+
}
|
|
303
|
+
const { rows, wbs } = flattened;
|
|
207
304
|
return {
|
|
208
305
|
tasks: data.tasks,
|
|
209
306
|
dependencies: data.dependencies,
|
|
@@ -222,10 +319,10 @@ function createGanttModel(options) {
|
|
|
222
319
|
state = build();
|
|
223
320
|
for (const l of listeners) l(state);
|
|
224
321
|
}
|
|
225
|
-
function commit(next, source, operations, label) {
|
|
322
|
+
function commit(next, source, operations, label, nextSchedule) {
|
|
226
323
|
const before = schedule;
|
|
227
324
|
data = next;
|
|
228
|
-
schedule =
|
|
325
|
+
schedule = nextSchedule;
|
|
229
326
|
const ids = new Set(data.tasks.map((t) => t.id));
|
|
230
327
|
selection = new Set([...selection].filter((id) => ids.has(id)));
|
|
231
328
|
if (focusedId !== null && !ids.has(focusedId)) focusedId = null;
|
|
@@ -254,72 +351,85 @@ function createGanttModel(options) {
|
|
|
254
351
|
},
|
|
255
352
|
apply(operations, label) {
|
|
256
353
|
const ops = asArray(operations);
|
|
257
|
-
const { data: next, inverse } =
|
|
258
|
-
|
|
259
|
-
|
|
354
|
+
const { data: next, inverse, schedule: nextSchedule } = prepare(ops);
|
|
355
|
+
if (historyLimit > 0) {
|
|
356
|
+
undoStack.push({ label, forward: ops, inverse, before: data, after: next });
|
|
357
|
+
if (undoStack.length > historyLimit) undoStack = undoStack.slice(-historyLimit);
|
|
358
|
+
}
|
|
260
359
|
redoStack = [];
|
|
261
|
-
return commit(next, "edit", ops, label);
|
|
360
|
+
return commit(next, "edit", ops, label, nextSchedule);
|
|
262
361
|
},
|
|
263
362
|
validate(operations) {
|
|
264
363
|
try {
|
|
265
|
-
|
|
364
|
+
prepare(asArray(operations));
|
|
266
365
|
return null;
|
|
267
366
|
} catch (e) {
|
|
268
367
|
return e instanceof Error ? e.message : String(e);
|
|
269
368
|
}
|
|
270
369
|
},
|
|
271
370
|
preview(operations) {
|
|
272
|
-
return
|
|
371
|
+
return prepare(asArray(operations)).schedule;
|
|
273
372
|
},
|
|
274
373
|
undo() {
|
|
275
|
-
const entry = undoStack.
|
|
374
|
+
const entry = undoStack[undoStack.length - 1];
|
|
276
375
|
if (!entry) return null;
|
|
277
|
-
const
|
|
376
|
+
const nextSchedule = run(entry.before);
|
|
377
|
+
undoStack.pop();
|
|
278
378
|
redoStack.push(entry);
|
|
279
|
-
return commit(
|
|
379
|
+
return commit(entry.before, "undo", entry.inverse, entry.label, nextSchedule);
|
|
280
380
|
},
|
|
281
381
|
redo() {
|
|
282
|
-
const entry = redoStack.
|
|
382
|
+
const entry = redoStack[redoStack.length - 1];
|
|
283
383
|
if (!entry) return null;
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
384
|
+
const nextSchedule = run(entry.after);
|
|
385
|
+
redoStack.pop();
|
|
386
|
+
undoStack.push(entry);
|
|
387
|
+
return commit(entry.after, "redo", entry.forward, entry.label, nextSchedule);
|
|
287
388
|
},
|
|
288
389
|
setData(next) {
|
|
289
|
-
|
|
390
|
+
const candidate = {
|
|
290
391
|
tasks: next.tasks ?? data.tasks,
|
|
291
392
|
dependencies: next.dependencies ?? data.dependencies
|
|
292
393
|
};
|
|
293
|
-
|
|
394
|
+
const nextCalendars = next.calendars ?? calendars;
|
|
395
|
+
const nextSchedule = run(candidate, nextCalendars);
|
|
396
|
+
data = candidate;
|
|
397
|
+
rowsDirty = true;
|
|
398
|
+
calendars = nextCalendars;
|
|
294
399
|
undoStack = [];
|
|
295
400
|
redoStack = [];
|
|
296
|
-
schedule =
|
|
401
|
+
schedule = nextSchedule;
|
|
297
402
|
const ids = new Set(data.tasks.map((t) => t.id));
|
|
298
403
|
selection = new Set([...selection].filter((id) => ids.has(id)));
|
|
299
404
|
if (focusedId !== null && !ids.has(focusedId)) focusedId = null;
|
|
300
405
|
emit();
|
|
301
406
|
},
|
|
302
407
|
setScheduleOptions(next) {
|
|
408
|
+
const nextSchedule = run(data, calendars, next);
|
|
303
409
|
scheduleOptions = next;
|
|
304
|
-
schedule =
|
|
410
|
+
schedule = nextSchedule;
|
|
305
411
|
emit();
|
|
306
412
|
},
|
|
307
413
|
toggle(id) {
|
|
414
|
+
rowsDirty = true;
|
|
308
415
|
if (collapsed.has(id)) collapsed.delete(id);
|
|
309
416
|
else collapsed.add(id);
|
|
310
417
|
emit();
|
|
311
418
|
},
|
|
312
419
|
setExpanded(id, expanded) {
|
|
313
420
|
if (expanded === !collapsed.has(id)) return;
|
|
421
|
+
rowsDirty = true;
|
|
314
422
|
if (expanded) collapsed.delete(id);
|
|
315
423
|
else collapsed.add(id);
|
|
316
424
|
emit();
|
|
317
425
|
},
|
|
318
426
|
expandAll() {
|
|
427
|
+
rowsDirty = true;
|
|
319
428
|
collapsed.clear();
|
|
320
429
|
emit();
|
|
321
430
|
},
|
|
322
431
|
collapseAll() {
|
|
432
|
+
rowsDirty = true;
|
|
323
433
|
const tree = buildTaskTree(data.tasks);
|
|
324
434
|
for (const t of data.tasks) if (tree.children.get(t.id)?.length) collapsed.add(t.id);
|
|
325
435
|
emit();
|
|
@@ -404,8 +514,12 @@ function editOperation(ctx, mode, preview) {
|
|
|
404
514
|
const { source, calendar: cal, minutesPerDay, snap } = ctx;
|
|
405
515
|
const coarse = snap !== "hour";
|
|
406
516
|
const fmt = (t, original, isFinish) => {
|
|
517
|
+
if (original instanceof Date) return toLocalDate(t);
|
|
518
|
+
if (typeof original === "number") return t;
|
|
407
519
|
if (coarse && original !== void 0 && isDateOnly(original)) {
|
|
408
|
-
return formatTime(isFinish && t % DAY === 0 ? t - 1 : t, {
|
|
520
|
+
return formatTime(isFinish && preview.start !== preview.finish && t % DAY === 0 ? t - 1 : t, {
|
|
521
|
+
dateOnly: true
|
|
522
|
+
});
|
|
409
523
|
}
|
|
410
524
|
return formatTime(t);
|
|
411
525
|
};
|
|
@@ -414,7 +528,7 @@ function editOperation(ctx, mode, preview) {
|
|
|
414
528
|
const isMilestone = ctx.task.type === "milestone";
|
|
415
529
|
if (mode === "move" || isMilestone) {
|
|
416
530
|
patch.start = fmt(preview.start, source.start, false);
|
|
417
|
-
if (usesEnd
|
|
531
|
+
if (usesEnd) patch.end = fmt(preview.finish, source.end, true);
|
|
418
532
|
} else if (mode === "resize-end") {
|
|
419
533
|
if (usesEnd) patch.end = fmt(preview.finish, source.end, true);
|
|
420
534
|
else patch.duration = round(cal.between(preview.start, preview.finish) / minutesPerDay);
|
|
@@ -425,9 +539,9 @@ function editOperation(ctx, mode, preview) {
|
|
|
425
539
|
}
|
|
426
540
|
const c = source.constraint;
|
|
427
541
|
if (c && (c.type === "SNET" || c.type === "MSO") && patch.start !== void 0) {
|
|
428
|
-
patch.constraint = { ...c, date:
|
|
542
|
+
patch.constraint = { ...c, date: fmt(preview.start, c.date, false) };
|
|
429
543
|
} else if (c && (c.type === "FNET" || c.type === "MFO") && (patch.start !== void 0 || patch.end !== void 0 || patch.duration !== void 0)) {
|
|
430
|
-
patch.constraint = { ...c, date:
|
|
544
|
+
patch.constraint = { ...c, date: fmt(preview.finish, c.date, true) };
|
|
431
545
|
}
|
|
432
546
|
return { type: "update-task", id: source.id, patch };
|
|
433
547
|
}
|
|
@@ -500,8 +614,14 @@ function rescheduleOperation(ctx, edit) {
|
|
|
500
614
|
const patch = {};
|
|
501
615
|
if (moved) Object.assign(patch, patchOf(editOperation(c, "move", preview)));
|
|
502
616
|
if (resized) {
|
|
503
|
-
if (length === 0
|
|
504
|
-
|
|
617
|
+
if (length === 0 && ctx.source.duration === void 0 && ctx.source.end !== void 0) {
|
|
618
|
+
Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
|
|
619
|
+
patch.type = "milestone";
|
|
620
|
+
} else {
|
|
621
|
+
Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
|
|
622
|
+
if (length === 0) patch.duration = 0;
|
|
623
|
+
}
|
|
624
|
+
if (length > 0 && ctx.source.type === "milestone") patch.type = "task";
|
|
505
625
|
}
|
|
506
626
|
return Object.keys(patch).length ? { type: "update-task", id: ctx.source.id, patch } : null;
|
|
507
627
|
}
|
|
@@ -531,10 +651,15 @@ function parseDuration(text, minutesPerDay = 480) {
|
|
|
531
651
|
const m = /^\s*(\d+(?:[.,]\d+)?)\s*([a-z]*)\s*$/i.exec(text);
|
|
532
652
|
if (!m) return void 0;
|
|
533
653
|
const n = Number(m[1].replace(",", "."));
|
|
654
|
+
if (!Number.isFinite(n) || !Number.isFinite(minutesPerDay) || minutesPerDay <= 0)
|
|
655
|
+
return void 0;
|
|
534
656
|
const unit = m[2].toLowerCase();
|
|
535
657
|
if (!unit || /^d(ays?)?$/.test(unit)) return n;
|
|
536
|
-
if (/^h((ou)?rs?)?$/.test(unit))
|
|
537
|
-
|
|
658
|
+
if (/^h((ou)?rs?)?$/.test(unit)) {
|
|
659
|
+
const days = round(n * 60 / minutesPerDay);
|
|
660
|
+
return Number.isFinite(days) ? days : void 0;
|
|
661
|
+
}
|
|
662
|
+
if (/^w((ee)?ks?)?$/.test(unit)) return Number.isFinite(n * 5) ? n * 5 : void 0;
|
|
538
663
|
return void 0;
|
|
539
664
|
}
|
|
540
665
|
function indentOperation(tasks, id) {
|
|
@@ -692,18 +817,40 @@ function exportProject(tasks, dependencies, calendars = [], schedule) {
|
|
|
692
817
|
const s = schedule?.tasks.get(t.id);
|
|
693
818
|
const out = { ...t };
|
|
694
819
|
if (s) {
|
|
695
|
-
out.start =
|
|
696
|
-
if (s.type !== "milestone" && t.duration === void 0) out.end =
|
|
820
|
+
out.start = serialiseTime(s.start);
|
|
821
|
+
if (s.type !== "milestone" && t.duration === void 0) out.end = serialiseTime(s.finish);
|
|
697
822
|
}
|
|
698
|
-
|
|
699
|
-
if (v instanceof Date)
|
|
700
|
-
out[k] = formatTime(parseTime(v));
|
|
701
|
-
return out;
|
|
823
|
+
return serialiseWallDates(out);
|
|
702
824
|
}),
|
|
703
|
-
dependencies,
|
|
704
|
-
calendars: calendars.length ? calendars : void 0
|
|
825
|
+
dependencies: dependencies.map((d) => serialiseWallDates(d)),
|
|
826
|
+
calendars: calendars.length ? calendars.map(serialiseCalendar) : void 0
|
|
705
827
|
};
|
|
706
828
|
}
|
|
829
|
+
var serialiseTime = (time) => time % MINUTE === 0 ? formatTime(time) : new Date(time).toISOString().slice(0, -1);
|
|
830
|
+
var serialiseDay = (value) => value instanceof Date ? formatTime(parseTime(value), { dateOnly: true }) : value;
|
|
831
|
+
function serialiseCalendar(calendar) {
|
|
832
|
+
const { exceptions, ...rest } = calendar;
|
|
833
|
+
const out = serialiseWallDates(rest);
|
|
834
|
+
if (Array.isArray(exceptions)) {
|
|
835
|
+
out.exceptions = exceptions.map((ex) => {
|
|
836
|
+
const day = { ...ex, date: serialiseDay(ex.date) };
|
|
837
|
+
if ("end" in ex) day.end = serialiseDay(ex.end);
|
|
838
|
+
return serialiseWallDates(day);
|
|
839
|
+
});
|
|
840
|
+
} else if ("exceptions" in calendar) {
|
|
841
|
+
out.exceptions = exceptions;
|
|
842
|
+
}
|
|
843
|
+
return out;
|
|
844
|
+
}
|
|
845
|
+
function serialiseWallDates(value) {
|
|
846
|
+
if (value instanceof Date) return serialiseTime(parseTime(value));
|
|
847
|
+
if (Array.isArray(value)) return value.map(serialiseWallDates);
|
|
848
|
+
if (value && typeof value === "object")
|
|
849
|
+
return Object.fromEntries(
|
|
850
|
+
Object.entries(value).map(([key, item]) => [key, serialiseWallDates(item)])
|
|
851
|
+
);
|
|
852
|
+
return value;
|
|
853
|
+
}
|
|
707
854
|
function importProject(input) {
|
|
708
855
|
const data = typeof input === "string" ? JSON.parse(input) : input;
|
|
709
856
|
if (!data || typeof data !== "object") throw new TypeError("Project must be an object");
|
|
@@ -737,7 +884,8 @@ function importProject(input) {
|
|
|
737
884
|
}
|
|
738
885
|
function tableToCsv(table) {
|
|
739
886
|
const cell = (v) => {
|
|
740
|
-
const
|
|
887
|
+
const raw = v === void 0 || v === null ? "" : String(v);
|
|
888
|
+
const s = /^[\s]*[=+@-]/.test(raw) ? `'${raw}` : raw;
|
|
741
889
|
return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
742
890
|
};
|
|
743
891
|
const lines = [table.columns.map((c) => cell(c.header)).join(",")];
|
package/dist/layout/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from '../chunk-JS3ZLEZJ.js';
|
|
2
|
+
import '../chunk-FV63P7UY.js';
|