@classic-homes/gantt-core 0.3.2 → 0.3.3

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.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-742OJYSO.js';
3
- export { ancestorsOf, buildOrderingGraph, buildTaskTree, descendantsOf, edgeKey, findCycle, isAncestor, leavesOf, scheduleProject, taskDaySpan, topoSort, wouldCreateCycle } from './chunk-742OJYSO.js';
4
- export { CONTINUOUS_CALENDAR, STANDARD_CALENDAR, STANDARD_CALENDAR_ID, compileCalendar, compileCalendars, nonWorkingSpans } from './chunk-3GIZDFDV.js';
5
- import { addUnits } from './chunk-MDRXY4HU.js';
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, startOfDay, parseTime, isDateOnly, createTimeFormatter } from './chunk-LPH2V7XM.js';
8
- export { DAY, HOUR, MINUTE, createTimeFormatter, dayIndex, formatTime, isDateOnly, parseTime, startOfDay, toLocalDate, tryParseTime, weekday } from './chunk-LPH2V7XM.js';
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 walk = (parentId, prefix, level, visible) => {
16
- const kids = tree.children.get(parentId) ?? [];
17
- kids.forEach((id, i) => {
18
- const code = prefix ? `${prefix}.${i + 1}` : String(i + 1);
19
- wbs.set(id, code);
20
- const hasChildren = (tree.children.get(id)?.length ?? 0) > 0;
21
- const expanded = hasChildren && isExpanded(id);
22
- if (visible) {
23
- rows.push({
24
- id,
25
- task: byId.get(id),
26
- index: rows.length,
27
- level,
28
- wbs: code,
29
- hasChildren,
30
- expanded,
31
- parentId
32
- });
33
- }
34
- if (hasChildren) walk(id, code, level + 1, visible && expanded);
35
- });
36
- };
37
- walk(null, "", 1, true);
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 (removedDeps.includes(d)) inverse.push({ type: "add-dependency", dependency: d, index });
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) => !removedDeps.includes(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, calendars, scheduleOptions);
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
- const { rows, wbs } = flattenTasks(data.tasks, (id) => !collapsed.has(id));
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 = run(data);
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 } = applyAll(data, ops);
258
- undoStack.push({ label, forward: ops, inverse });
259
- if (undoStack.length > historyLimit) undoStack = undoStack.slice(-historyLimit);
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
- applyAll(data, asArray(operations));
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 run(applyAll(data, asArray(operations)).data);
371
+ return prepare(asArray(operations)).schedule;
273
372
  },
274
373
  undo() {
275
- const entry = undoStack.pop();
374
+ const entry = undoStack[undoStack.length - 1];
276
375
  if (!entry) return null;
277
- const { data: next } = applyAll(data, entry.inverse);
376
+ const nextSchedule = run(entry.before);
377
+ undoStack.pop();
278
378
  redoStack.push(entry);
279
- return commit(next, "undo", entry.inverse, entry.label);
379
+ return commit(entry.before, "undo", entry.inverse, entry.label, nextSchedule);
280
380
  },
281
381
  redo() {
282
- const entry = redoStack.pop();
382
+ const entry = redoStack[redoStack.length - 1];
283
383
  if (!entry) return null;
284
- const { data: next, inverse } = applyAll(data, entry.forward);
285
- undoStack.push({ ...entry, inverse });
286
- return commit(next, "redo", entry.forward, entry.label);
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
- data = {
390
+ const candidate = {
290
391
  tasks: next.tasks ?? data.tasks,
291
392
  dependencies: next.dependencies ?? data.dependencies
292
393
  };
293
- if (next.calendars) calendars = next.calendars;
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 = run(data);
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 = run(data);
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, { dateOnly: true });
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 && !isMilestone) patch.end = fmt(preview.finish, source.end, true);
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: patch.start };
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: formatTime(preview.finish) };
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) patch.duration = 0;
504
- else Object.assign(patch, patchOf(editOperation(c, "resize-end", preview)));
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)) return round(n * 60 / minutesPerDay);
537
- if (/^w((ee)?ks?)?$/.test(unit)) return n * 5;
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,25 @@ 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 = formatTime(s.start);
696
- if (s.type !== "milestone" && t.duration === void 0) out.end = formatTime(s.finish);
820
+ out.start = serialiseTime(s.start);
821
+ if (s.type !== "milestone" && t.duration === void 0) out.end = serialiseTime(s.finish);
697
822
  }
698
- for (const [k, v] of Object.entries(out))
699
- if (v instanceof Date)
700
- out[k] = formatTime(parseTime(v));
701
- return out;
823
+ return serialiseWallDates(out);
702
824
  }),
703
825
  dependencies,
704
826
  calendars: calendars.length ? calendars : void 0
705
827
  };
706
828
  }
829
+ var serialiseTime = (time) => time % MINUTE === 0 ? formatTime(time) : new Date(time).toISOString().slice(0, -1);
830
+ function serialiseWallDates(value) {
831
+ if (value instanceof Date) return serialiseTime(parseTime(value));
832
+ if (Array.isArray(value)) return value.map(serialiseWallDates);
833
+ if (value && typeof value === "object")
834
+ return Object.fromEntries(
835
+ Object.entries(value).map(([key, item]) => [key, serialiseWallDates(item)])
836
+ );
837
+ return value;
838
+ }
707
839
  function importProject(input) {
708
840
  const data = typeof input === "string" ? JSON.parse(input) : input;
709
841
  if (!data || typeof data !== "object") throw new TypeError("Project must be an object");
@@ -737,7 +869,8 @@ function importProject(input) {
737
869
  }
738
870
  function tableToCsv(table) {
739
871
  const cell = (v) => {
740
- const s = v === void 0 || v === null ? "" : String(v);
872
+ const raw = v === void 0 || v === null ? "" : String(v);
873
+ const s = /^[\s]*[=+@-]/.test(raw) ? `'${raw}` : raw;
741
874
  return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
742
875
  };
743
876
  const lines = [table.columns.map((c) => cell(c.header)).join(",")];
@@ -1,2 +1,2 @@
1
- export { ZOOM_LEVELS, ZOOM_PRESETS, addUnits, barGeometry, createTimeScale, floorUnit, hitTestBar, pathFromPoints, routeDependency, scaleTicks, snapToUnit, timelineRange, virtualWindow } from '../chunk-MDRXY4HU.js';
2
- import '../chunk-LPH2V7XM.js';
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';