@salmonui/gantt 0.0.0-stage → 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.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -2
  3. package/dist/gantt/Gantt.d.ts +5 -0
  4. package/dist/gantt/Gantt.d.ts.map +1 -0
  5. package/dist/gantt/Gantt.js +516 -0
  6. package/dist/gantt/Gantt.js.map +1 -0
  7. package/dist/gantt/adaptive.d.ts +8 -0
  8. package/dist/gantt/adaptive.d.ts.map +1 -0
  9. package/dist/gantt/adaptive.js +38 -0
  10. package/dist/gantt/adaptive.js.map +1 -0
  11. package/dist/gantt/api.d.ts +9 -0
  12. package/dist/gantt/api.d.ts.map +1 -0
  13. package/dist/gantt/api.js +181 -0
  14. package/dist/gantt/api.js.map +1 -0
  15. package/dist/gantt/chart.d.ts +70 -0
  16. package/dist/gantt/chart.d.ts.map +1 -0
  17. package/dist/gantt/chart.js +580 -0
  18. package/dist/gantt/chart.js.map +1 -0
  19. package/dist/gantt/columns.d.ts +9 -0
  20. package/dist/gantt/columns.d.ts.map +1 -0
  21. package/dist/gantt/columns.js +139 -0
  22. package/dist/gantt/columns.js.map +1 -0
  23. package/dist/gantt/export.d.ts +53 -0
  24. package/dist/gantt/export.d.ts.map +1 -0
  25. package/dist/gantt/export.js +241 -0
  26. package/dist/gantt/export.js.map +1 -0
  27. package/dist/gantt/fields.d.ts +42 -0
  28. package/dist/gantt/fields.d.ts.map +1 -0
  29. package/dist/gantt/fields.js +235 -0
  30. package/dist/gantt/fields.js.map +1 -0
  31. package/dist/gantt/instance.d.ts +214 -0
  32. package/dist/gantt/instance.d.ts.map +1 -0
  33. package/dist/gantt/instance.js +1029 -0
  34. package/dist/gantt/instance.js.map +1 -0
  35. package/dist/gantt/interact.d.ts +7 -0
  36. package/dist/gantt/interact.d.ts.map +1 -0
  37. package/dist/gantt/interact.js +315 -0
  38. package/dist/gantt/interact.js.map +1 -0
  39. package/dist/gantt/loading.d.ts +21 -0
  40. package/dist/gantt/loading.d.ts.map +1 -0
  41. package/dist/gantt/loading.js +81 -0
  42. package/dist/gantt/loading.js.map +1 -0
  43. package/dist/gantt/locale.d.ts +161 -0
  44. package/dist/gantt/locale.d.ts.map +1 -0
  45. package/dist/gantt/locale.js +145 -0
  46. package/dist/gantt/locale.js.map +1 -0
  47. package/dist/gantt/menu-items.d.ts +8 -0
  48. package/dist/gantt/menu-items.d.ts.map +1 -0
  49. package/dist/gantt/menu-items.js +16 -0
  50. package/dist/gantt/menu-items.js.map +1 -0
  51. package/dist/gantt/menu-run.d.ts +5 -0
  52. package/dist/gantt/menu-run.d.ts.map +1 -0
  53. package/dist/gantt/menu-run.js +69 -0
  54. package/dist/gantt/menu-run.js.map +1 -0
  55. package/dist/gantt/modules.d.ts +19 -0
  56. package/dist/gantt/modules.d.ts.map +1 -0
  57. package/dist/gantt/modules.js +8 -0
  58. package/dist/gantt/modules.js.map +1 -0
  59. package/dist/gantt/popups.d.ts +23 -0
  60. package/dist/gantt/popups.d.ts.map +1 -0
  61. package/dist/gantt/popups.js +158 -0
  62. package/dist/gantt/popups.js.map +1 -0
  63. package/dist/gantt/registry-lazy.d.ts +4 -0
  64. package/dist/gantt/registry-lazy.d.ts.map +1 -0
  65. package/dist/gantt/registry-lazy.js +54 -0
  66. package/dist/gantt/registry-lazy.js.map +1 -0
  67. package/dist/gantt/registry-static.d.ts +4 -0
  68. package/dist/gantt/registry-static.d.ts.map +1 -0
  69. package/dist/gantt/registry-static.js +13 -0
  70. package/dist/gantt/registry-static.js.map +1 -0
  71. package/dist/gantt/remote.d.ts +16 -0
  72. package/dist/gantt/remote.d.ts.map +1 -0
  73. package/dist/gantt/remote.js +178 -0
  74. package/dist/gantt/remote.js.map +1 -0
  75. package/dist/gantt/resource-view.d.ts +57 -0
  76. package/dist/gantt/resource-view.d.ts.map +1 -0
  77. package/dist/gantt/resource-view.js +123 -0
  78. package/dist/gantt/resource-view.js.map +1 -0
  79. package/dist/gantt/toolbar.d.ts +11 -0
  80. package/dist/gantt/toolbar.d.ts.map +1 -0
  81. package/dist/gantt/toolbar.js +166 -0
  82. package/dist/gantt/toolbar.js.map +1 -0
  83. package/dist/gantt/tooltip.d.ts +7 -0
  84. package/dist/gantt/tooltip.d.ts.map +1 -0
  85. package/dist/gantt/tooltip.js +180 -0
  86. package/dist/gantt/tooltip.js.map +1 -0
  87. package/dist/gantt/types.d.ts +625 -0
  88. package/dist/gantt/types.d.ts.map +1 -0
  89. package/dist/gantt/types.js +7 -0
  90. package/dist/gantt/types.js.map +1 -0
  91. package/dist/gantt.css +5593 -0
  92. package/dist/gantt.d.ts +6 -0
  93. package/dist/gantt.d.ts.map +1 -0
  94. package/dist/gantt.js +13 -0
  95. package/dist/gantt.js.map +1 -0
  96. package/dist/internal/timeline/project/calendar.d.ts +50 -0
  97. package/dist/internal/timeline/project/calendar.d.ts.map +1 -0
  98. package/dist/internal/timeline/project/calendar.js +312 -0
  99. package/dist/internal/timeline/project/calendar.js.map +1 -0
  100. package/dist/internal/timeline/project/critical.d.ts +34 -0
  101. package/dist/internal/timeline/project/critical.d.ts.map +1 -0
  102. package/dist/internal/timeline/project/critical.js +135 -0
  103. package/dist/internal/timeline/project/critical.js.map +1 -0
  104. package/dist/internal/timeline/project/dependencies.d.ts +16 -0
  105. package/dist/internal/timeline/project/dependencies.d.ts.map +1 -0
  106. package/dist/internal/timeline/project/dependencies.js +87 -0
  107. package/dist/internal/timeline/project/dependencies.js.map +1 -0
  108. package/dist/internal/timeline/project/engine.d.ts +118 -0
  109. package/dist/internal/timeline/project/engine.d.ts.map +1 -0
  110. package/dist/internal/timeline/project/engine.js +1907 -0
  111. package/dist/internal/timeline/project/engine.js.map +1 -0
  112. package/dist/internal/timeline/project/format.d.ts +22 -0
  113. package/dist/internal/timeline/project/format.d.ts.map +1 -0
  114. package/dist/internal/timeline/project/format.js +41 -0
  115. package/dist/internal/timeline/project/format.js.map +1 -0
  116. package/dist/internal/timeline/project/history.d.ts +27 -0
  117. package/dist/internal/timeline/project/history.d.ts.map +1 -0
  118. package/dist/internal/timeline/project/history.js +74 -0
  119. package/dist/internal/timeline/project/history.js.map +1 -0
  120. package/dist/internal/timeline/project/resources.d.ts +26 -0
  121. package/dist/internal/timeline/project/resources.d.ts.map +1 -0
  122. package/dist/internal/timeline/project/resources.js +109 -0
  123. package/dist/internal/timeline/project/resources.js.map +1 -0
  124. package/dist/internal/timeline/project/types.d.ts +99 -0
  125. package/dist/internal/timeline/project/types.d.ts.map +1 -0
  126. package/dist/internal/timeline/project/types.js +6 -0
  127. package/dist/internal/timeline/project/types.js.map +1 -0
  128. package/dist/internal/timeline/scale.d.ts +60 -0
  129. package/dist/internal/timeline/scale.d.ts.map +1 -0
  130. package/dist/internal/timeline/scale.js +156 -0
  131. package/dist/internal/timeline/scale.js.map +1 -0
  132. package/package.json +55 -4
@@ -0,0 +1,580 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The Gantt chart pane. It draws
4
+ // exactly the rows of the grid pane's visible row model in the grid's
5
+ // rendered window: the window
6
+ // and row offsets come from `api.getViewport()` / `api.getRowOffsets()`, a
7
+ // grid scroll moves the chart rows with one transform write (no React), and
8
+ // React re-renders only when the rendered window, the row model or the
9
+ // horizontal window changes. Before the grid mounts (server, hydration) the
10
+ // chart renders the grid's deterministic initial range.
11
+ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
12
+ import { DAY } from '@salmonui/core/internal/timeline/axis';
13
+ import { tierCells, xOf } from '../internal/timeline/scale.js';
14
+ import { GRID_PARENT_FIELD } from './fields.js';
15
+ import { formatDeps } from './instance.js';
16
+ import { peekGanttModules } from '#gantt-modules';
17
+ const fixedMetrics = (count, h) => ({
18
+ count,
19
+ totalHeight: count * h,
20
+ offsetOf: (i) => i * h,
21
+ heightOf: () => h,
22
+ indexAt: (o) => Math.max(0, Math.min(count - 1, Math.floor(o / h))),
23
+ });
24
+ /** Visible rows before the grid mounts: tree order with collapsed subtrees removed (the grid's own rule). */
25
+ function initialVisible(g) {
26
+ const p = g.props;
27
+ const expandedField = g.fields.expanded;
28
+ const collapsedAll = p.defaultExpanded === 'none' || p.defaultExpanded === false;
29
+ const hidden = new Set();
30
+ const out = [];
31
+ for (const row of g.gridRows) {
32
+ const r = row;
33
+ const key = g.keyOf(row);
34
+ const parent = r[GRID_PARENT_FIELD];
35
+ if (parent !== null && parent !== undefined && hidden.has(String(parent))) {
36
+ hidden.add(key);
37
+ continue;
38
+ }
39
+ out.push(row);
40
+ const flag = r[expandedField];
41
+ if (typeof flag === 'boolean' ? !flag : collapsedAll)
42
+ hidden.add(key);
43
+ }
44
+ return out;
45
+ }
46
+ /** Store of the rendered window, fed by the grid's viewport subscription. */
47
+ export class ChartViewport {
48
+ g;
49
+ window = null;
50
+ listeners = new Set();
51
+ rowsEl = null;
52
+ off = null;
53
+ top = 0;
54
+ written = '';
55
+ constructor(g) {
56
+ this.g = g;
57
+ }
58
+ subscribe = (l) => {
59
+ this.listeners.add(l);
60
+ return () => this.listeners.delete(l);
61
+ };
62
+ get = () => {
63
+ if (this.window)
64
+ return this.window;
65
+ return this.initial();
66
+ };
67
+ /** The deterministic server / first-render window (grid `initialRows`, fixed row height). */
68
+ initialCache = null;
69
+ initial() {
70
+ const g = this.g;
71
+ if (this.initialCache?.version === g.version)
72
+ return this.initialCache.value;
73
+ const rows = initialVisible(g);
74
+ const h = g.props.rowHeight ?? 36;
75
+ const value = { start: 0, end: Math.min(rows.length, g.props.initialRows ?? 20), rows, metrics: fixedMetrics(rows.length, h) };
76
+ this.initialCache = { version: g.version, value };
77
+ return value;
78
+ }
79
+ attach() {
80
+ const api = this.g.gridApi;
81
+ if (!api || this.off)
82
+ return;
83
+ this.off = api.subscribeViewport(this.onViewport);
84
+ this.onViewport();
85
+ }
86
+ detach() {
87
+ this.off?.();
88
+ this.off = null;
89
+ }
90
+ /** Grid scroll or layout change: a transform write, or a new window for React when the rows changed. */
91
+ onViewport = () => {
92
+ const api = this.g.gridApi;
93
+ if (!api)
94
+ return;
95
+ const vp = api.getViewport();
96
+ const metrics = api.getRowOffsets();
97
+ const rows = api.getVisibleRows();
98
+ const w = this.window;
99
+ // The grid's rendered range (with overscan): every grid row has its bar (aria-describedby).
100
+ const start = Math.min(vp.rows.overscanStart, metrics.count);
101
+ const end = Math.min(vp.rows.overscanEnd, metrics.count);
102
+ this.top = vp.top;
103
+ // Rows the grid loaded itself (remote `data`, lazy children) join the engine.
104
+ const g = this.g;
105
+ if ((!w || w.rows !== rows) && (g.props.loadChildren || !Array.isArray(g.props.data))) {
106
+ const fresh = rows.filter((r) => !g.engine.getTask(g.idOf(r)));
107
+ if (fresh.length)
108
+ g.adoptRemoteRows(fresh, (r) => {
109
+ const p = api.getTreeRow(g.idOf(r))?.parentId;
110
+ return p === null || p === undefined ? null : String(p);
111
+ });
112
+ g.remote?.confirm(rows);
113
+ }
114
+ if (!w || w.start !== start || w.end !== end || w.metrics !== metrics || w.rows !== rows) {
115
+ this.window = { start, end, rows, metrics };
116
+ for (const l of this.listeners)
117
+ l();
118
+ }
119
+ this.apply();
120
+ };
121
+ /** Writes the rows transform for the current scroll offset. */
122
+ apply() {
123
+ const el = this.rowsEl;
124
+ const w = this.window;
125
+ if (!el || !w)
126
+ return;
127
+ const value = `translateY(${w.metrics.offsetOf(w.start) - this.top}px)`;
128
+ if (value !== this.written) {
129
+ el.style.transform = value;
130
+ this.written = value;
131
+ }
132
+ }
133
+ resetWritten() {
134
+ this.written = '';
135
+ }
136
+ }
137
+ // ---------------------------------------------------------------------------
138
+ // Formatting
139
+ // ---------------------------------------------------------------------------
140
+ const TOP_FORMATS = {
141
+ year: { year: 'numeric' },
142
+ month: { month: 'short', year: 'numeric' },
143
+ week: { month: 'short', day: 'numeric', year: 'numeric' },
144
+ day: { weekday: 'short', month: 'short', day: 'numeric' },
145
+ hour: { month: 'short', day: 'numeric', hour: 'numeric' },
146
+ minute: { hour: 'numeric', minute: '2-digit' },
147
+ };
148
+ const BOTTOM_FORMATS = {
149
+ year: { year: 'numeric' },
150
+ month: { month: 'short' },
151
+ week: { month: 'short', day: 'numeric' },
152
+ day: { weekday: 'narrow' },
153
+ hour: { hour: 'numeric' },
154
+ minute: { minute: '2-digit' },
155
+ };
156
+ /** `Intl` options of a CLDR skeleton (`'yMMMd'`) or a style (`'short'`); null for a pattern. */
157
+ function skeletonOf(f) {
158
+ if (/^(short|medium|long|full)$/.test(f))
159
+ return { dateStyle: f };
160
+ if (!/^[yMdEHhms]+$/.test(f))
161
+ return null;
162
+ const o = {};
163
+ for (const run of f.match(/(.)\1*/g) ?? []) {
164
+ const n = run.length;
165
+ const num = n === 2 ? '2-digit' : 'numeric';
166
+ const c = run[0];
167
+ if (c === 'y')
168
+ o['year'] = num;
169
+ else if (c === 'M')
170
+ o['month'] = n <= 2 ? num : n === 3 ? 'short' : n === 4 ? 'long' : 'narrow';
171
+ else if (c === 'd')
172
+ o['day'] = num;
173
+ else if (c === 'E')
174
+ o['weekday'] = n === 4 ? 'long' : 'short';
175
+ else if (c === 'm')
176
+ o['minute'] = num;
177
+ else if (c === 's')
178
+ o['second'] = num;
179
+ else {
180
+ o['hour'] = num;
181
+ o['hourCycle'] = c === 'H' ? 'h23' : 'h12';
182
+ }
183
+ }
184
+ return o;
185
+ }
186
+ /** Formatters of wall ms (the scale's `Date.UTC` numbers, so always formatted in UTC). */
187
+ export function createFormatters(locale, dateFormat) {
188
+ const cache = new Map();
189
+ const fmt = (o) => {
190
+ const key = JSON.stringify(o);
191
+ let f = cache.get(key);
192
+ if (!f) {
193
+ try {
194
+ f = new Intl.DateTimeFormat(locale, { ...o, timeZone: 'UTC' });
195
+ }
196
+ catch {
197
+ f = new Intl.DateTimeFormat('en-US', { ...o, timeZone: 'UTC' });
198
+ }
199
+ cache.set(key, f);
200
+ }
201
+ return f;
202
+ };
203
+ // A skeleton or style string (`'yMMMd'`, `'short'`) formats the chart text too; a pattern formats the grid columns only.
204
+ const dateOptions = (typeof dateFormat === 'object' ? dateFormat : dateFormat ? skeletonOf(dateFormat) : null) ?? { year: 'numeric', month: 'short', day: 'numeric' };
205
+ return {
206
+ tier: (wall, tier, spec, format) => {
207
+ if (!format && spec.unit === 'minute' && tier === 'bottom')
208
+ return String(new Date(wall).getUTCMinutes()).padStart(2, '0');
209
+ return fmt(format ?? (tier === 'top' ? TOP_FORMATS : BOTTOM_FORMATS)[spec.unit]).format(wall);
210
+ },
211
+ date: (wall) => fmt(dateOptions).format(wall),
212
+ full: (wall) => fmt({ year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' }).format(wall),
213
+ };
214
+ }
215
+ /** Horizontal window in px: changes only when the scroll crosses half a viewport. */
216
+ function useHorizontalWindow(g, scrollEl, scaleWidth) {
217
+ const [chunk, setChunk] = useState({ from: 0, to: 1600 });
218
+ useEffect(() => {
219
+ const el = scrollEl;
220
+ if (!el)
221
+ return;
222
+ let frame = 0;
223
+ let scrolled = false;
224
+ const read = () => {
225
+ frame = 0;
226
+ const width = el.clientWidth || 800;
227
+ const left = Math.abs(el.scrollLeft);
228
+ const size = Math.max(200, width / 2);
229
+ const from = Math.max(0, Math.floor((left - width) / size) * size);
230
+ const to = Math.min(scaleWidth, from + width * 3 + size);
231
+ setChunk((c) => (c.from === from && c.to === to ? c : { from, to }));
232
+ // Infinite timeline: extend at the edges a user scroll reaches (not on mount or after a rescale).
233
+ if (g.props.timeline?.infinite && scrolled) {
234
+ scrolled = false;
235
+ if (left < 2)
236
+ g.extendTimeline('start');
237
+ else if (left + width >= el.scrollWidth - 2)
238
+ g.extendTimeline('end');
239
+ }
240
+ };
241
+ const schedule = () => {
242
+ if (!frame)
243
+ frame = requestAnimationFrame(read);
244
+ };
245
+ const onScroll = () => {
246
+ scrolled = true;
247
+ schedule();
248
+ };
249
+ read();
250
+ el.addEventListener('scroll', onScroll, { passive: true });
251
+ const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : null;
252
+ ro?.observe(el);
253
+ return () => {
254
+ el.removeEventListener('scroll', onScroll);
255
+ ro?.disconnect();
256
+ if (frame)
257
+ cancelAnimationFrame(frame);
258
+ };
259
+ }, [g, scrollEl, scaleWidth]);
260
+ return chunk;
261
+ }
262
+ function tierOf(spec, fallback) {
263
+ if (!fallback)
264
+ return null;
265
+ return { spec: fallback, tier: spec ?? null };
266
+ }
267
+ function Tiers({ g, scale, from, to, formatters, height }) {
268
+ const t = g.props.timeline;
269
+ const top = tierOf(t?.topTier, scale.level.top);
270
+ const bottom = tierOf(t?.bottomTier, scale.level.bottom);
271
+ const rows = [top && { key: 'top', ...top }, bottom && { key: 'bottom', ...bottom }].filter(Boolean);
272
+ const rowHeight = height / Math.max(1, rows.length);
273
+ const tooltips = t?.tooltips !== false;
274
+ return (_jsx("div", { className: "salmon-gantt__timeline", "aria-hidden": "true", style: { height, width: scale.width }, children: rows.map((r) => (_jsx("div", { className: "salmon-gantt__tier", "data-tier": r.key, style: { height: rowHeight }, children: tierCells(scale, r.spec, from, to).map((c) => {
275
+ const text = formatters.tier(c.start, r.key, r.spec, r.tier?.format);
276
+ const ctx = { tier: r.key, date: new Date(c.start), unit: r.spec.unit, width: c.width, text };
277
+ const render = r.tier?.render ?? t?.renderCell;
278
+ return (_jsx("div", { className: "salmon-gantt__tier-cell", "data-unit": r.spec.unit, title: tooltips ? formatters.full(c.start) : undefined, style: { insetInlineStart: c.x, width: c.width }, children: render ? render(ctx) : text }, c.start));
279
+ }) }, r.key))) }));
280
+ }
281
+ /** Weekend and holiday shading and markers in the horizontal window. */
282
+ function Background({ g, scale, from, to }) {
283
+ const p = g.props;
284
+ const items = [];
285
+ const fine = scale.level.bottom.unit === 'day' || scale.level.bottom.unit === 'hour' || scale.level.bottom.unit === 'minute';
286
+ if (p.highlightWeekends && fine) {
287
+ const cal = g.engine.calendarOf(null);
288
+ const first = Math.floor((scale.start + from / scale.pxPerMs) / DAY);
289
+ const last = Math.ceil((scale.start + to / scale.pxPerMs) / DAY);
290
+ for (let d = first; d <= last && d - first < 2000; d++) {
291
+ const wd = (((d + 4) % 7) + 7) % 7;
292
+ if (wd !== 0 && wd !== 6 && cal.isWorkingDay(d))
293
+ continue;
294
+ if (wd !== 0 && wd !== 6)
295
+ continue;
296
+ const x = xOf(scale, d * DAY);
297
+ items.push(_jsx("div", { className: "salmon-gantt__weekend", style: { insetInlineStart: x, width: DAY * scale.pxPerMs } }, `w${d}`));
298
+ }
299
+ }
300
+ for (const [i, h] of (p.holidays ?? []).entries()) {
301
+ const s = g.wall(h.start);
302
+ if (s === null)
303
+ continue;
304
+ const e = (g.wall(h.end ?? h.start) ?? s) + DAY;
305
+ const x = xOf(scale, Math.floor(s / DAY) * DAY);
306
+ const w = (Math.floor(e / DAY) * DAY - Math.floor(s / DAY) * DAY) * scale.pxPerMs;
307
+ if (x + w < from || x > to)
308
+ continue;
309
+ items.push(_jsx("div", { className: h.className ? `salmon-gantt__holiday ${h.className}` : 'salmon-gantt__holiday', style: { insetInlineStart: x, width: Math.max(1, w) }, children: h.label ? _jsx("span", { className: "salmon-gantt__holiday-label", children: h.label }) : null }, `h${i}`));
310
+ }
311
+ for (const [i, m] of (p.markers ?? []).entries()) {
312
+ const w = g.wall(m.date);
313
+ if (w === null)
314
+ continue;
315
+ const x = xOf(scale, w);
316
+ if (x < from || x > to)
317
+ continue;
318
+ items.push(_jsx("div", { className: m.className ? `salmon-gantt__marker ${m.className}` : 'salmon-gantt__marker', style: { insetInlineStart: x }, children: m.label ? _jsx("span", { className: "salmon-gantt__marker-label", children: m.label }) : null }, `m${i}`));
319
+ }
320
+ return _jsx("div", { className: "salmon-gantt__background", "aria-hidden": "true", children: items });
321
+ }
322
+ export function barOf(scale, s) {
323
+ if (s.start === null || s.end === null)
324
+ return null;
325
+ const x = xOf(scale, s.start);
326
+ return { x, width: Math.max(s.milestone ? 0 : 2, xOf(scale, s.end) - x) };
327
+ }
328
+ function labelValue(label, ctx) {
329
+ if (label === undefined)
330
+ return null;
331
+ if (typeof label === 'function')
332
+ return label(ctx);
333
+ const v = ctx.task[label];
334
+ return v === null || v === undefined ? null : String(v);
335
+ }
336
+ const ChartRow = memo(function ChartRow({ g, view, scale, selected, critical, formatters, version: _version }) {
337
+ const p = g.props;
338
+ const { schedule: s, row } = view;
339
+ const f = g.fields;
340
+ const r = row;
341
+ const box = barOf(scale, s);
342
+ const taskbarHeight = Math.min(view.height - 4, p.taskbarHeight ?? Math.round((p.rowHeight ?? 36) * 0.6));
343
+ const barTop = Math.round((view.height - taskbarHeight) / 2) - (p.baselines ? 3 : 0);
344
+ const editable = g.editable() && (typeof p.editing !== 'object' || p.editing.taskbar !== false);
345
+ const title = String(r[f.title] ?? '');
346
+ const startText = s.start === null ? '' : formatters.date(s.start);
347
+ const endText = s.end === null ? '' : formatters.date(s.end);
348
+ const ctx = {
349
+ task: row,
350
+ info: g.info(view.id),
351
+ start: s.start === null ? null : g.date(s.start),
352
+ end: s.end === null ? null : g.date(s.end),
353
+ progress: s.progress,
354
+ width: box?.width ?? 0,
355
+ critical,
356
+ selected,
357
+ };
358
+ const extra = p.getTaskbarProps?.(ctx);
359
+ const deps = g.engine.getTask(view.id)?.predecessors ?? [];
360
+ let aria = s.unscheduled || !box
361
+ ? g.text('unscheduledLabel', { title })
362
+ : s.milestone
363
+ ? g.text('milestoneLabel', { title, start: startText })
364
+ : g.text(s.parent ? 'parentLabel' : 'taskbarLabel', { title, start: startText, end: endText, progress: Math.round(s.progress) });
365
+ const list = formatDeps(deps);
366
+ if (deps.length)
367
+ aria = g.text('dependentLabel', { label: aria, dependsOn: g.text('dependsOn', { list }), list });
368
+ if (critical)
369
+ aria = g.text('criticalLabel', { label: aria, critical: g.text('critical') });
370
+ const userClass = typeof r[f.className] === 'string' ? r[f.className] : '';
371
+ const cls = (base) => [base, userClass, extra?.className].filter(Boolean).join(' ');
372
+ const dataAttrs = {};
373
+ if (extra)
374
+ for (const k of Object.keys(extra))
375
+ if (k.startsWith('data-'))
376
+ dataAttrs[k] = extra[k];
377
+ // Over-allocation: a task bar of a resource group inside an over-allocated range.
378
+ const rv = peekGanttModules().resources;
379
+ const over = view.group && p.overAllocation && rv ? rv.resourceRowModel(g, view.group).over : null;
380
+ const overAllocated = !!over && s.start !== null && s.end !== null && over.some((x) => s.start < x.end && s.end > x.start);
381
+ const multi = p.multiTaskbar && rv && view.collapsed && s.parent ? g.engine.getTasks().filter((t) => t.parentId === view.id).map((t) => t.id) : null;
382
+ const state = {
383
+ 'data-over-allocated': overAllocated || undefined,
384
+ 'data-multi': multi ? '' : undefined,
385
+ 'data-critical': critical || undefined,
386
+ 'data-manual': s.manual || undefined,
387
+ 'data-selected': selected || undefined,
388
+ 'data-parent': s.parent || undefined,
389
+ 'data-editable': editable || undefined,
390
+ ...dataAttrs,
391
+ };
392
+ const barStyle = { top: barTop, height: taskbarHeight, ...extra?.style };
393
+ let bar = null;
394
+ if (s.unscheduled || !box) {
395
+ const x = xOf(scale, g.projectRange().start);
396
+ bar = _jsx("div", { className: cls('salmon-gantt__taskbar salmon-gantt__unscheduled'), "data-part": "taskbar", "data-unscheduled": "", role: "img", "aria-label": aria, id: `${g.props.id ?? 'gantt'}-bar-${view.key}`, style: { ...barStyle, insetInlineStart: x, width: scale.level.unitWidth } });
397
+ }
398
+ else if (s.milestone) {
399
+ const size = taskbarHeight;
400
+ bar = (_jsxs("div", { className: cls('salmon-gantt__milestone'), "data-part": "milestone", role: "img", "aria-label": aria, ...state, "data-template": p.renderMilestone ? '' : undefined, id: `${g.props.id ?? 'gantt'}-bar-${view.key}`, style: { ...barStyle, insetInlineStart: box.x - size / 2, width: size, height: size }, children: [p.renderMilestone ? p.renderMilestone(ctx) : null, editable ? _jsx("span", { className: "salmon-gantt__connector-point", "data-end": "end", "aria-hidden": "true" }) : null] }));
401
+ }
402
+ else if (s.parent) {
403
+ const rollup = s.manual && s.rollupStart !== null && s.rollupEnd !== null ? { x: xOf(scale, s.rollupStart), w: xOf(scale, s.rollupEnd) - xOf(scale, s.rollupStart) } : null;
404
+ bar = (_jsxs(_Fragment, { children: [rollup ? _jsx("div", { className: "salmon-gantt__rollup", "aria-hidden": "true", style: { top: barTop + taskbarHeight, insetInlineStart: rollup.x, width: Math.max(2, rollup.w) } }) : null, _jsxs("div", { className: cls('salmon-gantt__taskbar salmon-gantt__summary'), "data-part": "taskbar", role: "img", "aria-label": aria, ...state, "data-template": p.renderParentTaskbar && !multi ? '' : undefined, id: `${g.props.id ?? 'gantt'}-bar-${view.key}`, style: { ...barStyle, insetInlineStart: box.x, width: box.width }, children: [multi ? null : p.renderParentTaskbar ? (p.renderParentTaskbar(ctx)) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "salmon-gantt__progress", style: { width: `${s.progress}%` } }), p.labels?.inside ? _jsx("span", { className: "salmon-gantt__label", "data-side": "inside", children: labelValue(p.labels.inside, ctx) }) : null] })), editable && s.manual ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "salmon-gantt__handle", "data-handle": "start", "aria-hidden": "true" }), _jsx("span", { className: "salmon-gantt__handle", "data-handle": "end", "aria-hidden": "true" })] })) : null] }), multi && rv ? _jsx(rv.MultiBars, { g: g, scale: scale, ids: multi, lanes: null, top: barTop, height: taskbarHeight, laneHeight: 0, over: [] }) : null] }));
405
+ }
406
+ else {
407
+ const segments = s.segments && s.segments.length > 1 ? s.segments : null;
408
+ bar = (_jsxs("div", { className: cls('salmon-gantt__taskbar'), "data-part": "taskbar", role: "img", "aria-label": aria, ...state, "data-split": segments ? '' : undefined, "data-template": p.renderTaskbar ? '' : undefined, id: `${g.props.id ?? 'gantt'}-bar-${view.key}`, style: { ...barStyle, insetInlineStart: box.x, width: box.width }, children: [p.renderTaskbar ? (p.renderTaskbar(ctx)) : segments ? (segments.map((seg, i) => {
409
+ const sx = xOf(scale, seg.start) - box.x;
410
+ const sw = Math.max(2, xOf(scale, seg.end) - xOf(scale, seg.start));
411
+ const next = segments[i + 1];
412
+ return (_jsxs("span", { className: "salmon-gantt__segment-wrap", children: [_jsx("span", { className: "salmon-gantt__segment", "data-segment": i, style: { insetInlineStart: sx, width: sw }, children: editable ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "salmon-gantt__handle", "data-handle": "start", "data-segment": i, "aria-hidden": "true" }), _jsx("span", { className: "salmon-gantt__handle", "data-handle": "end", "data-segment": i, "aria-hidden": "true" })] })) : null }), next ? _jsx("span", { className: "salmon-gantt__segment-gap", style: { insetInlineStart: sx + sw, width: Math.max(0, xOf(scale, next.start) - xOf(scale, seg.end)) } }) : null] }, seg.start));
413
+ })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "salmon-gantt__progress", style: { width: `${s.progress}%` } }), p.labels?.inside ? _jsx("span", { className: "salmon-gantt__label", "data-side": "inside", children: labelValue(p.labels.inside, ctx) }) : null] })), editable ? (_jsxs(_Fragment, { children: [segments ? null : (_jsxs(_Fragment, { children: [_jsx("span", { className: "salmon-gantt__handle", "data-handle": "start", "aria-hidden": "true" }), _jsx("span", { className: "salmon-gantt__handle", "data-handle": "end", "aria-hidden": "true" }), _jsx("span", { className: "salmon-gantt__progress-handle", "aria-hidden": "true", style: { insetInlineStart: `${s.progress}%` } })] })), _jsx("span", { className: "salmon-gantt__connector-point", "data-end": "start", "aria-hidden": "true" }), _jsx("span", { className: "salmon-gantt__connector-point", "data-end": "end", "aria-hidden": "true" })] })) : null] }));
414
+ }
415
+ // Baseline.
416
+ let baseline = null;
417
+ if (p.baselines) {
418
+ const t = g.engine.getTask(view.id);
419
+ const bs = t?.baselineStart ?? null;
420
+ const be = t?.baselineEnd ?? bs;
421
+ if (bs !== null && be !== null) {
422
+ const bx = xOf(scale, bs);
423
+ const bw = xOf(scale, be) - bx;
424
+ baseline = p.renderBaseline ? (_jsx("div", { className: "salmon-gantt__baseline", "data-part": "baseline", style: { insetInlineStart: bx, width: Math.max(2, bw), top: barTop + taskbarHeight + 2 }, children: p.renderBaseline(ctx) })) : (_jsx("div", { className: "salmon-gantt__baseline", "data-part": "baseline", "data-milestone": bw <= 0 || undefined, "aria-hidden": "true", style: { insetInlineStart: bw <= 0 ? bx - 5 : bx, width: bw <= 0 ? 10 : bw, top: barTop + taskbarHeight + 2 } }));
425
+ }
426
+ }
427
+ // Labels and indicators.
428
+ const startLabel = box && p.labels?.start ? labelValue(p.labels.start, ctx) : null;
429
+ const endLabel = box && p.labels?.end ? labelValue(p.labels.end, ctx) : null;
430
+ const indicators = r[f.indicators] ?? null;
431
+ const rowClass = s.parent ? 'salmon-gantt__row salmon-gantt__row--parent' : 'salmon-gantt__row';
432
+ // A remote write in flight.
433
+ const pending = g.pending.has(view.id);
434
+ return (_jsxs("div", { className: rowClass, "data-task-id": view.id, "data-row-key": view.key, "data-resource": view.group, "data-row-index": view.index, "data-pending": pending || undefined, style: { top: view.top, height: view.height, opacity: pending ? 0.6 : undefined }, children: [baseline, bar, startLabel !== null && box ? (_jsx("span", { className: "salmon-gantt__label", "data-side": "start", style: { insetInlineEnd: `calc(100% - ${box.x - (s.milestone ? taskbarHeight / 2 : 0) - 4}px)`, top: barTop, lineHeight: `${taskbarHeight}px` }, children: startLabel })) : null, endLabel !== null && box ? (_jsx("span", { className: "salmon-gantt__label", "data-side": "end", style: { insetInlineStart: box.x + box.width + (s.milestone ? taskbarHeight / 2 : 0) + 4, top: barTop, lineHeight: `${taskbarHeight}px` }, children: endLabel })) : null, indicators?.map((ind, i) => {
435
+ const w = g.wall(ind.date);
436
+ if (w === null)
437
+ return null;
438
+ return (_jsxs("span", { className: ind.className ? `salmon-gantt__indicator ${ind.className}` : 'salmon-gantt__indicator', title: ind.tooltip, style: { insetInlineStart: xOf(scale, w), top: barTop }, children: [ind.icon ?? _jsx("span", { className: "salmon-gantt__indicator-dot", "aria-hidden": "true" }), ind.label ? _jsx("span", { className: "salmon-gantt__indicator-label", children: ind.label }) : null] }, i));
439
+ })] }));
440
+ });
441
+ /** Orthogonal connector path between two bars. */
442
+ export function connectorPath(x1, y1, fromEnd, x2, y2, toStart, rowGap) {
443
+ const g = 10;
444
+ const out = fromEnd ? 1 : -1;
445
+ const dir = toStart ? 1 : -1;
446
+ const a = x1 + out * g;
447
+ const b = x2 - dir * g;
448
+ let d;
449
+ if (out === dir && (dir === 1 ? b >= a : b <= a))
450
+ d = `M${x1} ${y1}H${a}V${y2}H${x2}`;
451
+ else if (out !== dir) {
452
+ const xm = out === -1 ? Math.min(a, b) : Math.max(a, b);
453
+ d = `M${x1} ${y1}H${xm}V${y2}H${x2}`;
454
+ }
455
+ else {
456
+ const ym = y1 + (y2 >= y1 ? rowGap : -rowGap);
457
+ d = `M${x1} ${y1}H${a}V${ym}H${b}V${y2}H${x2}`;
458
+ }
459
+ const arrow = `M${x2} ${y2}l${-dir * 6} -4v8z`;
460
+ return { d, arrow };
461
+ }
462
+ function Connectors({ g, views, window: w, scale, from, to, indexOf }) {
463
+ const base = w.metrics.offsetOf(w.start);
464
+ const paths = [];
465
+ const p = g.props;
466
+ const taskbarHeight = (h) => Math.min(h - 4, p.taskbarHeight ?? Math.round((p.rowHeight ?? 36) * 0.6));
467
+ const width = p.connectorWidth ?? 1;
468
+ const edge = (s, end) => {
469
+ const box = barOf(scale, s);
470
+ if (!box)
471
+ return null;
472
+ if (s.milestone) {
473
+ const half = taskbarHeight(p.rowHeight ?? 36) / 2;
474
+ return end ? box.x + half : box.x - half;
475
+ }
476
+ return end ? box.x + box.width : box.x;
477
+ };
478
+ const drawn = new Set();
479
+ const draw = (fromId, toId, dep) => {
480
+ const key = `${fromId}>${toId}`;
481
+ if (drawn.has(key))
482
+ return;
483
+ drawn.add(key);
484
+ const fi = indexOf.get(fromId);
485
+ const ti = indexOf.get(toId);
486
+ if (fi === undefined || ti === undefined)
487
+ return;
488
+ const fs = g.engine.getSchedule(fromId);
489
+ const ts = g.engine.getSchedule(toId);
490
+ if (!fs || !ts)
491
+ return;
492
+ const fromEnd = dep.type === 'fs' || dep.type === 'ff';
493
+ const toStart = dep.type === 'fs' || dep.type === 'ss';
494
+ const x1 = edge(fs, fromEnd);
495
+ const x2 = edge(ts, !toStart);
496
+ if (x1 === null || x2 === null)
497
+ return;
498
+ if (Math.max(x1, x2) < from - 200 || Math.min(x1, x2) > to + 200)
499
+ return;
500
+ const y1 = w.metrics.offsetOf(fi) - base + w.metrics.heightOf(fi) / 2;
501
+ const y2 = w.metrics.offsetOf(ti) - base + w.metrics.heightOf(ti) / 2;
502
+ const { d, arrow } = connectorPath(x1, y1, fromEnd, x2, y2, toStart, w.metrics.heightOf(fi) / 2);
503
+ const critical = !!g.critical?.has(fromId) && !!g.critical?.has(toId);
504
+ paths.push(_jsxs("g", { className: "salmon-gantt__connector", "data-part": "connector", "data-from": fromId, "data-to": toId, "data-type": dep.type, "data-critical": critical || undefined, children: [_jsx("path", { d: d, fill: "none", strokeWidth: width }), _jsx("path", { d: arrow, className: "salmon-gantt__connector-arrow" }), _jsx("path", { d: d, fill: "none", className: "salmon-gantt__connector-hit", strokeWidth: 8 })] }, key));
505
+ };
506
+ for (const v of views) {
507
+ const t = g.engine.getTask(v.id);
508
+ for (const dep of t?.predecessors ?? [])
509
+ draw(dep.id, v.id, dep);
510
+ }
511
+ // Links from rendered predecessors to successors outside the window.
512
+ for (const v of views) {
513
+ for (const succ of g.engine.successorsOf?.(v.id) ?? []) {
514
+ const dep = g.engine.getTask(succ)?.predecessors?.find((d) => d.id === v.id);
515
+ if (dep)
516
+ draw(v.id, succ, dep);
517
+ }
518
+ }
519
+ const height = w.metrics.offsetOf(w.end) - base;
520
+ return (_jsx("svg", { className: "salmon-gantt__connectors", "aria-hidden": "true", width: scale.width, height: Math.max(1, height), style: { width: scale.width, height: Math.max(1, height) }, children: paths }));
521
+ }
522
+ export function GanttChart(props) {
523
+ const { g, version, viewport, formatters, headerHeight } = props;
524
+ const w = useSyncExternalStore(viewport.subscribe, viewport.get, viewport.get);
525
+ const [scrollEl, setScrollEl] = useState(null);
526
+ const scale = g.scale;
527
+ const { from, to } = useHorizontalWindow(g, scrollEl, scale.width);
528
+ const rowsRef = useCallback((el) => {
529
+ viewport.rowsEl = el;
530
+ viewport.resetWritten();
531
+ viewport.apply();
532
+ }, [viewport]);
533
+ useLayoutEffect(() => {
534
+ viewport.apply();
535
+ });
536
+ const scrollRef = useCallback((el) => {
537
+ g.chartScroll = el;
538
+ setScrollEl(el);
539
+ }, [g]);
540
+ const indexOf = useMemo(() => {
541
+ const m = new Map();
542
+ w.rows.forEach((r, i) => {
543
+ const id = g.taskIdOf(r);
544
+ if (id !== null && !m.has(id))
545
+ m.set(id, i);
546
+ });
547
+ return m;
548
+ }, [w.rows, g]);
549
+ const views = [];
550
+ const resourceViews = [];
551
+ const ResourceRow = peekGanttModules().resources?.ResourceChartRow;
552
+ const base = w.metrics.offsetOf(w.start);
553
+ // Skeleton rows under lazy parents whose children load (loading.tsx).
554
+ const sk = g.loadingParents.size ? (peekGanttModules().loading?.skeletonRows(g, w, scale) ?? null) : null;
555
+ for (let i = w.start; i < w.end; i++) {
556
+ const row = w.rows[i];
557
+ if (row === undefined)
558
+ continue;
559
+ const key = g.keyOf(row);
560
+ const next = w.rows[i + 1];
561
+ const collapsed = next === undefined || String(next[GRID_PARENT_FIELD]) !== key;
562
+ const top = w.metrics.offsetOf(i) - base + (sk ? sk.shift(i) : 0);
563
+ const height = w.metrics.heightOf(i);
564
+ const id = g.taskIdOf(row);
565
+ if (id === null) {
566
+ const resource = g.groupOf(row) ?? '';
567
+ resourceViews.push({ key, resource, title: String(row[g.fields.title] ?? ''), index: i, top, height, collapsed });
568
+ continue;
569
+ }
570
+ const schedule = g.engine.getSchedule(id);
571
+ if (!schedule)
572
+ continue;
573
+ // The grid row object may be a stale copy; the chart reads the current one.
574
+ views.push({ id, key, group: g.groupOf(row), row: g.getRow(id) ?? row, index: i, top, height, schedule, collapsed: schedule.parent && collapsed });
575
+ }
576
+ return (_jsxs("div", { className: "salmon-gantt__chart", ref: (el) => void (g.chartRoot = el), onPointerDown: props.onPointerDown, onContextMenu: props.onContextMenu, onDoubleClick: props.onDoubleClick, onClick: props.onClick, onKeyDown: props.onKeyDown, children: [_jsx("div", { className: "salmon-gantt__chart-scroll", ref: scrollRef, tabIndex: 0, role: "group", "aria-label": g.text('chart'), children: _jsxs("div", { className: "salmon-gantt__chart-inner", style: { width: scale.width }, children: [_jsx(Tiers, { g: g, scale: scale, from: from, to: to, formatters: formatters, height: headerHeight }), _jsxs("div", { className: "salmon-gantt__chart-body", children: [_jsx(Background, { g: g, scale: scale, from: from, to: to }), _jsxs("div", { className: "salmon-gantt__rows", ref: rowsRef, children: [_jsx(Connectors, { g: g, views: views, window: w, scale: scale, from: from, to: to, indexOf: indexOf }), ResourceRow
577
+ ? resourceViews.map((v) => _jsx(ResourceRow, { g: g, view: v, scale: scale, selected: props.selectedIds.has(v.key), version: version }, v.key))
578
+ : null, views.map((v) => (_jsx(ChartRow, { g: g, view: v, scale: scale, selected: props.selectedIds.has(v.key), critical: !!g.critical?.has(v.id), formatters: formatters, version: version }, v.key))), sk?.nodes] })] })] }) }), props.overlay] }));
579
+ }
580
+ //# sourceMappingURL=chart.js.map