@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NuLL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ # @salmonui/gantt
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Gantt chart for Salmon UI on the Data Grid: dependencies, critical path, baselines, resources and undo history.
4
+
5
+ ```sh
6
+ npm install @salmonui/gantt @salmonui/core react react-dom
7
+ ```
8
+
9
+ `react` and `react-dom` `>=19` are peer dependencies. ESM only.
10
+ Every `@salmonui/*` package of an application must resolve to the same
11
+ version (they are released together and exact-pinned to each other);
12
+ `@salmonui/core` warns in development when a second copy loads.
13
+
14
+ ```tsx
15
+ import { Gantt } from '@salmonui/gantt';
16
+ ```
17
+
18
+ Import the theme stylesheet once per application, then the
19
+ package stylesheet,
20
+ after the stylesheets of the components it renders from other packages:
21
+
22
+ ```tsx
23
+ import '@salmonui/core/styles.css'; // the theme, once per application
24
+ import '@salmonui/buttons/button/styles.css';
25
+ import '@salmonui/buttons/menu/styles.css';
26
+ import '@salmonui/calendars/date-picker/styles.css';
27
+ import '@salmonui/data-grid/styles.css';
28
+ import '@salmonui/layout/splitter/styles.css';
29
+ import '@salmonui/overlays/dialog/styles.css';
30
+ import '@salmonui/overlays/tooltip/styles.css';
31
+ import '@salmonui/gantt/styles.css';
32
+ ```
33
+
34
+ Public entry points:
35
+
36
+ - `@salmonui/gantt`
37
+
38
+ ## Documentation
39
+
40
+ - Gantt: <https://salmonui.dev/docs/calendars/gantt>
41
+
42
+ ## License
43
+
44
+ MIT
@@ -0,0 +1,5 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { GanttApi, GanttProps } from './types.js';
3
+ export declare function Gantt<Row = Record<string, unknown>>(props: GanttProps<Row>): ReactNode;
4
+ export type { GanttApi };
5
+ //# sourceMappingURL=Gantt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Gantt.d.ts","sourceRoot":"","sources":["../../src/gantt/Gantt.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAoJ,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAmBzL,OAAO,KAAK,EAAE,QAAQ,EAAqF,UAAU,EAA8C,MAAM,YAAY,CAAC;AA2DtL,wBAAgB,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,SAAS,CAOtF;AA4hBD,YAAY,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,516 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Gantt. The grid pane is `DataGrid` in tree mode composed only
4
+ // through its public extension points (row model, scroll sync, row height); the chart pane draws the same
5
+ // rendered window. State follows the Data Grid model: one instance created
6
+ // from the initial props and synced in a layout effect, React reading it
7
+ // through `useSyncExternalStore`, before / after events, `ref` receiving the
8
+ // `GanttApi` (the grid's `DataGridApi` plus the Gantt methods). Dialogs,
9
+ // menus and export are lazy chunks.
10
+ import { Suspense, use, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
11
+ import { peekGanttModules, readGanttModules } from '#gantt-modules';
12
+ import { DataGrid } from '@salmonui/data-grid';
13
+ import { gridEvent } from '@salmonui/core/internal/events';
14
+ import { pinCalendar } from '@salmonui/core/internal/dates/index';
15
+ import { useHydrated } from '@salmonui/core/internal/hydrated';
16
+ import { useLocale, useLocaleText } from '@salmonui/core/internal/locale';
17
+ import { Splitter } from '@salmonui/layout/splitter';
18
+ import { buildColumns } from './columns.js';
19
+ import { ChartViewport, createFormatters, GanttChart } from './chart.js';
20
+ import { GRID_PARENT_FIELD } from './fields.js';
21
+ import { GanttInstance } from './instance.js';
22
+ import { createGanttApi } from './api.js';
23
+ import { CONTEXT_ITEMS, contextItemsOf } from './menu-items.js';
24
+ const loadPopups = () => import('./popups.js');
25
+ // Taskbar editing is a chunk requested right after mount (the chart is visible before it can be dragged).
26
+ const loadInteract = () => import('./interact.js');
27
+ const cx = (...parts) => parts.filter(Boolean).join(' ');
28
+ const loadTooltip = () => import('./tooltip.js');
29
+ /** Lazy module, requested when idle after mount and at once when needed. */
30
+ function useLazy(load, needed, enabled = true) {
31
+ const [module, setModule] = useState(null);
32
+ useEffect(() => {
33
+ if (module || !enabled)
34
+ return;
35
+ let live = true;
36
+ const fetch = () => void load().then((m) => live && setModule(() => m));
37
+ let id = null;
38
+ if (needed)
39
+ fetch();
40
+ else
41
+ id = setTimeout(fetch, 1500);
42
+ return () => {
43
+ live = false;
44
+ if (id)
45
+ clearTimeout(id);
46
+ };
47
+ }, [load, needed, module, enabled]);
48
+ return module;
49
+ }
50
+ /** `#gantt-modules` the props render with (modules.ts). */
51
+ function neededModules(props) {
52
+ const out = [];
53
+ if (props.resourceView || props.multiTaskbar)
54
+ out.push('resources');
55
+ if (props.toolbar?.length)
56
+ out.push('toolbar');
57
+ if (props.criticalPath)
58
+ out.push('critical');
59
+ if (props.adaptive)
60
+ out.push('adaptive');
61
+ if (props.loadingIndicator === 'skeleton' || props.loadChildren)
62
+ out.push('loading');
63
+ // A writable remote source.
64
+ if (typeof props.data?.write === 'function')
65
+ out.push('remote');
66
+ return out;
67
+ }
68
+ /** Waits for the render modules: never on the server (static registry); in the browser hydration keeps the server HTML until they load. */
69
+ function GanttGate(props) {
70
+ // The nearest LocaleProvider resolves here: every Gantt part (instance, columns, popups, export) reads `props`.
71
+ // Gregorian unless `-u-ca-` names another calendar: the grid, the chart and the editors agree.
72
+ const ownLocale = useLocale(props.locale);
73
+ const locale = useMemo(() => ownLocale && pinCalendar(ownLocale), [ownLocale]);
74
+ const localeText = useLocaleText('gantt', props.localeText);
75
+ const needed = neededModules(props);
76
+ if (needed.length) {
77
+ const got = readGanttModules(needed);
78
+ if ('then' in got)
79
+ use(got);
80
+ }
81
+ return _jsx(GanttBody, { ...props, ...{ locale, localeText } });
82
+ }
83
+ export function Gantt(props) {
84
+ const pending = _jsx("div", { id: props.id, className: cx('salmon-gantt', props.className), style: { ...props.style, height: props.height ?? 450, ...(props.width !== undefined ? { width: props.width } : {}) }, "data-salmon-pending": "", "aria-busy": "true" });
85
+ return (_jsx(Suspense, { fallback: pending, children: _jsx(GanttGate, { ...props }) }));
86
+ }
87
+ function GanttBody(props) {
88
+ const Toolbar = peekGanttModules().toolbar?.GanttToolbar;
89
+ const [g] = useState(() => new GanttInstance(props));
90
+ useLayoutEffect(() => {
91
+ g.syncProps(props);
92
+ });
93
+ const version = useSyncExternalStore(g.subscribe, g.getVersion, g.getVersion);
94
+ const [viewport] = useState(() => new ChartViewport(g));
95
+ const hydrated = useHydrated();
96
+ const locale = props.locale ?? 'en-US';
97
+ const formatters = useMemo(() => createFormatters(locale, props.dateFormat), [locale, props.dateFormat]);
98
+ const [selected, setSelected] = useState(() => new Set());
99
+ const [gridReady, setGridReady] = useState(false);
100
+ const [popup, setPopup] = useState(null);
101
+ const [splitterSize, setSplitterSize] = useState(null);
102
+ const rootRef = useRef(null);
103
+ // `ref`: the grid API plus the Gantt methods.
104
+ const api = useMemo(() => createGanttApi(g, { setSplitterSize, openMenu: () => { } }), [g]);
105
+ useLayoutEffect(() => {
106
+ g.api = api;
107
+ g.formatters = formatters;
108
+ }, [g, api, formatters]);
109
+ useImperativeHandle(props.ref, () => api, [api]);
110
+ const readyFired = useRef(false);
111
+ useEffect(() => {
112
+ if (gridReady && !readyFired.current) {
113
+ readyFired.current = true;
114
+ g.props.onReady?.(api);
115
+ }
116
+ }, [gridReady, api, g]);
117
+ const gridRef = useCallback((gridApi) => {
118
+ g.gridApi = gridApi;
119
+ if (gridApi) {
120
+ viewport.attach();
121
+ setGridReady(true);
122
+ }
123
+ else
124
+ viewport.detach();
125
+ }, [g, viewport]);
126
+ useEffect(() => () => {
127
+ viewport.detach();
128
+ // Unmount aborts the remote writes in flight.
129
+ g.remote?.abort();
130
+ }, [viewport, g]);
131
+ // Undo history: attached after mount, again when the `undo` options change.
132
+ const undoKey = props.undo ? JSON.stringify(props.undo === true ? {} : props.undo) : '';
133
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `undoKey` stands for the options.
134
+ useEffect(() => g.setupHistory(g.props.undo), [g, undoKey]);
135
+ const needPopups = g.dialog !== null || g.conflict !== null || popup !== null;
136
+ const popups = useLazy(loadPopups, needPopups);
137
+ const interact = useLazy(loadInteract, g.editable());
138
+ const tooltip = useLazy(loadTooltip, false, !!props.tooltip);
139
+ // Columns: rebuilt when a column-shaping prop changes; cell values read the live engine.
140
+ const fine = g.level.bottom.unit === 'hour' || g.level.bottom.unit === 'minute';
141
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `fine` and the listed props shape the columns.
142
+ // `g.adopted`: remote rows joined the engine, their date cells re-read the computed dates.
143
+ const columns = useMemo(() => buildColumns(g, props), [g, props.columns, props.wbs, props.dateFormat, props.localeText, props.inlineNotes, props.resources, props.locale, props.timeZone, fine, g.adopted]);
144
+ const editing = props.readOnly || props.editing === false ? null : typeof props.editing === 'object' ? props.editing : {};
145
+ const editMode = editing?.mode ?? 'auto';
146
+ const gridEditing = useMemo(() => editing
147
+ ? {
148
+ mode: editMode === 'auto' ? 'cell' : editMode === 'dialog' ? 'cell' : editMode,
149
+ edit: editing.edit ?? true,
150
+ add: editing.add ?? true,
151
+ delete: editing.delete ?? true,
152
+ confirmDelete: editing.confirmDelete ?? false,
153
+ editOnDoubleClick: editMode !== 'dialog',
154
+ }
155
+ : undefined,
156
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the editing object identity is the input.
157
+ [props.editing, props.readOnly]);
158
+ // Grid edits reschedule through the engine.
159
+ const onSave = useCallback((event) => {
160
+ g.props.onSave?.(event);
161
+ if (event.status !== 'applied' && event.status !== 'partial')
162
+ return;
163
+ const batch = event.rows();
164
+ for (const changed of batch.changedRecords) {
165
+ const id = g.idOf(changed);
166
+ const row = changed;
167
+ const current = g.getRow(id);
168
+ if (!current)
169
+ continue;
170
+ const diff = {};
171
+ for (const k of Object.keys(row)) {
172
+ if (k === GRID_PARENT_FIELD)
173
+ continue;
174
+ const a = row[k];
175
+ const b = current[k];
176
+ if (a instanceof Date && b instanceof Date ? a.getTime() !== b.getTime() : a !== b)
177
+ diff[k] = a;
178
+ }
179
+ if (Object.keys(diff).length)
180
+ g.updateFields(id, diff, 'keyboard', 'edit');
181
+ }
182
+ if (batch.deletedRecords.length)
183
+ g.deleteTasks(batch.deletedRecords.map((d) => g.idOf(d)), 'keyboard');
184
+ for (const added of batch.addedRecords)
185
+ if (!g.getRow(g.idOf(added)))
186
+ g.addTask(added, { position: 'bottom' }, 'keyboard');
187
+ }, [g]);
188
+ const onSelectionChange = useCallback((event) => {
189
+ g.props.onSelectionChange?.(event);
190
+ const ids = new Set((g.gridApi?.getSelectedRowIds() ?? []).map(String));
191
+ setSelected(ids);
192
+ // Scroll the chart to the selected task (`focusTaskOnSelect`).
193
+ const first = [...ids][0];
194
+ const task = first === undefined ? null : g.taskIdOfKey(first);
195
+ if (task !== null && g.props.focusTaskOnSelect !== false && event.source !== 'pointer') {
196
+ const s = g.engine.getSchedule(task);
197
+ const el = g.chartScroll;
198
+ if (s?.start != null && el) {
199
+ const x = (s.start - g.scale.start) * g.scale.pxPerMs;
200
+ const left = Math.abs(el.scrollLeft);
201
+ if (x < left || x > left + el.clientWidth - 40)
202
+ g.setScrollLeft(Math.max(0, x - 40));
203
+ }
204
+ }
205
+ }, [g]);
206
+ // Context menu of the grid pane: Gantt items as Data Grid custom items.
207
+ const contextMenu = useMemo(() => (props.contextMenu ? contextItemsOf(g, props.contextMenu === true ? CONTEXT_ITEMS : props.contextMenu) : undefined), [g, props.contextMenu]);
208
+ const onContextMenuItemClick = useCallback((event) => {
209
+ const id = event.rowIds[0] !== undefined ? g.taskIdOfKey(String(event.rowIds[0])) : null;
210
+ const e = gridEvent('contextMenuItemClick', event.source, { item: event.item.id, taskId: id, task: id ? (g.getRow(id) ?? null) : null });
211
+ g.props.onContextMenuItemClick?.(e);
212
+ if (e.defaultPrevented)
213
+ return;
214
+ void loadPopups().then((m) => m.runContextItem(g, event.item.id, id, event.source));
215
+ }, [g]);
216
+ const getRowProps = useCallback((row, index, ctx) => {
217
+ const base = g.props.getRowProps?.(row, index, ctx);
218
+ return { ...base, 'aria-describedby': `${g.props.id ?? 'gantt'}-bar-${g.keyOf(row)}` };
219
+ }, [g]);
220
+ // Row drag: a drop on a task row moves the tasks in the engine, which reschedules them; the grid gets the new rows.
221
+ const onBeforeRowDrop = useCallback((e) => {
222
+ g.props.onBeforeRowDrop?.(e);
223
+ const target = e.targetRowId === null ? null : String(e.targetRowId);
224
+ if (e.defaultPrevented || !e.valid || !e.position || target === null || !g.engine.getTask(target))
225
+ return;
226
+ e.preventDefault();
227
+ const ids = e.rowIds.map(String);
228
+ const position = e.position === 'into' ? 'child' : e.position === 'before' ? 'above' : 'below';
229
+ if (g.run('move', ids, e.source, () => g.engine.move(ids, target, position)).status === 'applied')
230
+ g.props.onRowDrop?.(e);
231
+ }, [g]);
232
+ // Chart pointer: taskbar drag, click selects, double click edits.
233
+ const onChartPointerDown = useCallback((e) => {
234
+ if (e.button !== 0)
235
+ return;
236
+ if (interact?.startTaskbarDrag(g, e.nativeEvent, formatters))
237
+ e.stopPropagation();
238
+ }, [g, formatters, interact]);
239
+ const onChartClick = useCallback((e) => {
240
+ const target = e.target;
241
+ const rowEl = target.closest('.salmon-gantt__row');
242
+ const key = rowEl?.dataset['rowKey'];
243
+ if (!key)
244
+ return;
245
+ const id = rowEl.dataset['taskId'];
246
+ const part = target.closest('[data-part]')?.dataset['part'];
247
+ if (id && part && g.props.onTaskbarClick) {
248
+ const s = g.engine.getSchedule(id);
249
+ const kind = part === 'milestone' ? 'milestone' : part === 'baseline' ? 'baseline' : s?.parent ? 'parent' : 'taskbar';
250
+ const ev = gridEvent('taskbarClick', 'pointer', { taskId: id, task: g.getRow(id), target: kind });
251
+ g.props.onTaskbarClick(ev);
252
+ if (ev.defaultPrevented)
253
+ return;
254
+ }
255
+ if (g.props.selection !== false)
256
+ g.gridApi?.selectRows([key], e.ctrlKey || e.metaKey ? { mode: 'toggle' } : undefined);
257
+ }, [g]);
258
+ const onChartDoubleClick = useCallback((e) => {
259
+ const id = e.target.closest('.salmon-gantt__row')?.dataset['taskId'];
260
+ if (!id || !g.editable())
261
+ return;
262
+ const mode = typeof g.props.editing === 'object' ? (g.props.editing.mode ?? 'auto') : 'auto';
263
+ if (mode === 'auto' || mode === 'dialog')
264
+ api.openEditDialog(id);
265
+ }, [g, api]);
266
+ const onChartContextMenu = useCallback((e) => {
267
+ if (!g.props.contextMenu)
268
+ return;
269
+ const id = e.target.closest('.salmon-gantt__row')?.dataset['taskId'] ?? null;
270
+ if (g.props.onBeforeContextMenuOpen) {
271
+ const ev = gridEvent('beforeContextMenuOpen', 'pointer', { pane: 'chart', taskId: id, task: id ? (g.getRow(id) ?? null) : null });
272
+ g.props.onBeforeContextMenuOpen(ev);
273
+ if (ev.defaultPrevented)
274
+ return;
275
+ }
276
+ e.preventDefault();
277
+ if (id)
278
+ g.gridApi?.selectRows([id]);
279
+ setPopup({ kind: 'menu', x: e.clientX, y: e.clientY, taskId: id, items: (contextMenu ?? []).filter((i) => typeof i === 'object' && i.id.startsWith('gantt:')) });
280
+ }, [g, contextMenu]);
281
+ // Vertical wheel over the chart scrolls the grid (scroll sync); Ctrl+wheel zooms.
282
+ const chartPaneRef = useRef(null);
283
+ useEffect(() => {
284
+ const el = chartPaneRef.current;
285
+ if (!el)
286
+ return;
287
+ let pending = 0;
288
+ const onWheel = (e) => {
289
+ if (e.ctrlKey || e.metaKey) {
290
+ e.preventDefault();
291
+ pending += e.deltaY;
292
+ if (Math.abs(pending) >= 40) {
293
+ if (pending < 0)
294
+ api.zoomIn();
295
+ else
296
+ api.zoomOut();
297
+ pending = 0;
298
+ }
299
+ return;
300
+ }
301
+ if (Math.abs(e.deltaY) <= Math.abs(e.deltaX) || e.shiftKey)
302
+ return;
303
+ const grid = g.gridApi;
304
+ if (!grid)
305
+ return;
306
+ e.preventDefault();
307
+ grid.scrollTo({ top: grid.getViewport().top + e.deltaY * (e.deltaMode === 1 ? 36 : 1) });
308
+ };
309
+ el.addEventListener('wheel', onWheel, { passive: false });
310
+ return () => el.removeEventListener('wheel', onWheel);
311
+ }, [g, api]);
312
+ // `onChartPointerMove`: the date and task under the pointer, at most once per animation frame.
313
+ const pointerMove = props.onChartPointerMove !== undefined;
314
+ useEffect(() => {
315
+ const el = rootRef.current;
316
+ if (!el || !pointerMove)
317
+ return;
318
+ let frame = 0;
319
+ let last = null;
320
+ const run = () => {
321
+ frame = 0;
322
+ const inner = g.chartRoot?.querySelector('.salmon-gantt__chart-inner');
323
+ if (!last || !inner)
324
+ return;
325
+ const r = inner.getBoundingClientRect();
326
+ const x = g.isRtl() ? r.right - last.clientX : last.clientX - r.left;
327
+ const id = last.target.closest?.('.salmon-gantt__row')?.dataset['taskId'] ?? null;
328
+ const date = g.date(g.scale.start + x / g.scale.pxPerMs);
329
+ g.props.onChartPointerMove?.(gridEvent('chartPointerMove', last.pointerType === 'touch' ? 'touch' : 'pointer', { date, taskId: id, task: id ? (g.getRow(id) ?? null) : null }));
330
+ };
331
+ const onMove = (e) => {
332
+ if (!e.target.closest?.('.salmon-gantt__chart-body'))
333
+ return;
334
+ last = e;
335
+ if (!frame)
336
+ frame = requestAnimationFrame(run);
337
+ };
338
+ el.addEventListener('pointermove', onMove, { passive: true });
339
+ return () => {
340
+ el.removeEventListener('pointermove', onMove);
341
+ if (frame)
342
+ cancelAnimationFrame(frame);
343
+ };
344
+ }, [g, pointerMove]);
345
+ // Keyboard: Gantt shortcuts on the root, the grid keeps its own model.
346
+ const onKeyDown = useCallback((e) => {
347
+ const mod = e.ctrlKey || e.metaKey;
348
+ const target = e.target;
349
+ if (target.closest('input, textarea, [contenteditable="true"], [role="dialog"]'))
350
+ return;
351
+ const id = g.selectedId();
352
+ if (mod && !e.shiftKey && e.key.toLowerCase() === 'z' && g.history) {
353
+ e.preventDefault();
354
+ api.undo();
355
+ }
356
+ else if (mod && (e.key.toLowerCase() === 'y' || (e.shiftKey && e.key.toLowerCase() === 'z')) && g.history) {
357
+ e.preventDefault();
358
+ api.redo();
359
+ }
360
+ else if (e.altKey && e.shiftKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft') && id && g.editable()) {
361
+ e.preventDefault();
362
+ const rtl = g.isRtl();
363
+ if ((e.key === 'ArrowRight') !== rtl)
364
+ api.indent([id]);
365
+ else
366
+ api.outdent([id]);
367
+ }
368
+ else if (e.key === 'F6') {
369
+ e.preventDefault();
370
+ const chart = g.chartRoot?.querySelector('.salmon-gantt__chart-scroll');
371
+ if (chart && !chart.contains(target))
372
+ chart.focus();
373
+ else
374
+ g.gridApi?.focus();
375
+ }
376
+ else if (target.classList.contains('salmon-gantt__chart-scroll')) {
377
+ // Chart pane keys: scroll the timeline, move between tasks, open the editor.
378
+ const el = target;
379
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
380
+ e.preventDefault();
381
+ el.scrollLeft += (e.key === 'ArrowRight' ? 1 : -1) * (mod ? el.clientWidth : g.scale.level.unitWidth);
382
+ }
383
+ else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
384
+ e.preventDefault();
385
+ const rows = g.visibleRows();
386
+ const sel = g.gridApi?.getSelectedRowIds()[0];
387
+ const at = sel !== undefined ? rows.findIndex((r) => g.keyOf(r) === String(sel)) : -1;
388
+ const next = rows[Math.max(0, Math.min(rows.length - 1, at + (e.key === 'ArrowDown' ? 1 : -1)))];
389
+ if (next) {
390
+ const nid = g.keyOf(next);
391
+ g.gridApi?.selectRows([nid]);
392
+ g.gridApi?.scrollToRow(nid);
393
+ }
394
+ }
395
+ else if (e.key === 'Enter' && id && g.editable()) {
396
+ e.preventDefault();
397
+ api.openEditDialog(id);
398
+ }
399
+ else if ((e.key === '+' || e.key === '=') && mod) {
400
+ e.preventDefault();
401
+ api.zoomIn();
402
+ }
403
+ else if (e.key === '-' && mod) {
404
+ e.preventDefault();
405
+ api.zoomOut();
406
+ }
407
+ }
408
+ }, [g, api]);
409
+ // Gantt keys inside the grid pane run before the grid's own bindings.
410
+ const onGridKeyDown = useCallback((ctx) => {
411
+ g.props.onKeyDown?.(ctx);
412
+ const e = ctx.nativeEvent;
413
+ const mod = e.ctrlKey || e.metaKey;
414
+ const id = ctx.rowId === null ? null : String(ctx.rowId);
415
+ if (e.altKey && e.shiftKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft') && id && g.editable() && ctx.context !== 'header') {
416
+ ctx.preventDefault();
417
+ e.preventDefault();
418
+ if ((e.key === 'ArrowRight') !== g.isRtl())
419
+ api.indent([id]);
420
+ else
421
+ api.outdent([id]);
422
+ }
423
+ else if (g.history && mod && (e.key.toLowerCase() === 'z' || e.key.toLowerCase() === 'y')) {
424
+ ctx.preventDefault();
425
+ e.preventDefault();
426
+ if (e.key.toLowerCase() === 'y' || e.shiftKey)
427
+ api.redo();
428
+ else
429
+ api.undo();
430
+ }
431
+ }, [g, api]);
432
+ // Splitter.
433
+ const splitterEvent = (type, position) => gridEvent(type, 'pointer', { position });
434
+ const panes = props.panes ?? 'both';
435
+ const gridDefault = props.splitter?.position ?? (props.splitter?.columnIndex !== undefined ? columnsWidth(columns, props.splitter.columnIndex) : '40%');
436
+ const sizes = splitterSize === null ? undefined : { grid: splitterSize };
437
+ const gridDefaultSize = gridDefault;
438
+ const headerHeight = 2 * 28;
439
+ // The chart timeline follows the grid header's height (a filter bar or stacked headers make it taller).
440
+ const [gridHeader, setGridHeader] = useState(headerHeight);
441
+ useEffect(() => {
442
+ const el = gridReady ? g.gridApi?.element?.querySelector('.salmon-data-grid-header') : null;
443
+ if (!el || typeof ResizeObserver !== 'function')
444
+ return;
445
+ const ro = new ResizeObserver(() => setGridHeader(Math.round(el.getBoundingClientRect().height) || headerHeight));
446
+ ro.observe(el);
447
+ return () => ro.disconnect();
448
+ }, [g, gridReady]);
449
+ const rowHeight = props.rowHeight ?? 36;
450
+ // Adaptive (adaptive.tsx): one pane at a time; `{ breakpoint }` flips `g.narrow` after mount.
451
+ const mods = peekGanttModules();
452
+ const PaneSwitch = props.adaptive ? mods.adaptive?.GanttPaneSwitch : undefined;
453
+ const compact = !!PaneSwitch && (props.adaptive === true || g.narrow);
454
+ const pane = g.pane;
455
+ // Loading skeleton (loading.tsx): the chart mirrors the grid's skeleton.
456
+ const Loading = props.loadingIndicator === 'skeleton' ? mods.loading?.ChartLoading : undefined;
457
+ const root = { ...props.style, height: props.height ?? 450, ...(props.width !== undefined ? { width: props.width } : {}) };
458
+ const local = Array.isArray(props.data);
459
+ const treeOptions = useMemo(() => ({
460
+ // Local data: the flat rows the Gantt writes; a source: the rows' own parent field.
461
+ parentIdField: local ? GRID_PARENT_FIELD : g.fields.parentId,
462
+ expandedField: g.fields.expanded,
463
+ column: props.treeColumn ?? g.fields.title,
464
+ defaultExpanded: props.defaultExpanded === 'none' || props.defaultExpanded === false ? false : true,
465
+ ...(props.treeFilterMode ? { filterMode: props.treeFilterMode } : {}),
466
+ ...(props.hasChildrenField ? { hasChildrenField: props.hasChildrenField } : {}),
467
+ // The chart's skeleton row follows the lazy parents that load (the `loading` module is loaded with `loadChildren`).
468
+ ...(props.loadChildren ? { loadChildren: (ctx) => peekGanttModules().loading.trackChildren(g, ctx) } : {}),
469
+ }), [g, local, props.treeColumn, props.defaultExpanded, props.treeFilterMode, props.hasChildrenField, props.loadChildren]);
470
+ // Grid-pane props passed through unchanged (GGRID rows).
471
+ const { data: _data, taskFields: _tf, columns: _c, treeColumn: _tc, defaultExpanded: _de, treeFilterMode: _tf2, hasChildrenField: _h, loadChildren: _lc, contextMenu: _cm, onContextMenuItemClick: _oc, onBeforeContextMenuOpen: _ob, onSave: _os, onSelectionChange: _osc, getRowProps: _grp, rowHeight: _rh, getRowHeight, height: _he, width: _w, className, style: _st, id, dir, locale: _lo, timeZone, ref: _ref, onReady: _or, toolbar, ...rest } = props;
472
+ // Lanes of resource rows grow the row through the shared row-height extension point.
473
+ const lanes = !!props.resourceView && !!props.multiTaskbar && props.taskbarOverlap === false;
474
+ const laneHeight = useCallback((row) => {
475
+ const resource = g.taskIdOf(row) === null ? g.groupOf(row) : undefined;
476
+ const h = resource !== undefined ? (peekGanttModules().resources?.resourceRowHeight(g, resource) ?? null) : null;
477
+ return h ?? g.props.getRowHeight?.(row) ?? g.props.rowHeight ?? 36;
478
+ }, [g]);
479
+ const rowHeightOf = lanes ? laneHeight : getRowHeight;
480
+ const gridProps = {};
481
+ for (const k of GRID_PASS_THROUGH)
482
+ if (rest[k] !== undefined)
483
+ gridProps[k] = rest[k];
484
+ const gridPane = (_jsx("div", { className: compact && pane === 'chart' ? 'salmon-gantt__grid-pane salmon-gantt__hidden-grid' : 'salmon-gantt__grid-pane', children: _jsx(DataGrid, { ...gridProps, ref: gridRef, data: Array.isArray(props.data) ? g.gridRows : props.data, columns: columns, getRowId: g.keyOf, tree: treeOptions, height: "100%", rowHeight: rowHeight, ...(rowHeightOf ? { getRowHeight: rowHeightOf } : {}), headerHeight: headerHeight, locale: locale, ...(timeZone ? { timeZone } : {}), ...(dir ? { dir } : {}), ...(gridEditing ? { editing: gridEditing } : {}), ...(contextMenu ? { contextMenu, onContextMenuItemClick } : {}), ...(props.exportWriters?.excel ? { exportWriters: { excel: props.exportWriters.excel } } : {}), onSave: onSave, onKeyDown: onGridKeyDown, onSelectionChange: onSelectionChange, onBeforeRowDrop: onBeforeRowDrop, getRowProps: getRowProps, ...(props.localeText?.grid ? { localeText: props.localeText.grid } : {}), "aria-label": props['aria-label'] ?? g.text('label') }) }));
485
+ const chartPane = (_jsx("div", { className: "salmon-gantt__chart-pane", ref: chartPaneRef, children: _jsx(GanttChart, { g: g, version: version, viewport: viewport, formatters: formatters, headerHeight: gridHeader, hydrated: hydrated, selectedIds: selected, onPointerDown: onChartPointerDown, onClick: onChartClick, onDoubleClick: onChartDoubleClick, onContextMenu: onChartContextMenu, overlay: Loading ? _jsx(Loading, { g: g, ready: gridReady, headerHeight: gridHeader }) : null }) }));
486
+ return (_jsxs("div", { ref: rootRef, id: id, className: cx('salmon-gantt', className), style: root, dir: dir === 'auto' ? undefined : dir, "data-critical-path": props.criticalPath || undefined, "data-loading": g.loading || undefined, "data-adaptive": compact || undefined, "aria-busy": g.loading || undefined, onKeyDown: onKeyDown, children: [toolbar?.length && Toolbar ? _jsx(Toolbar, { g: g, api: api, items: toolbar }) : null, PaneSwitch ? _jsx(PaneSwitch, { g: g, root: rootRef, compact: compact }) : null, _jsx("div", { className: "salmon-gantt__panes", "data-panes": compact ? pane : panes, children: compact ? (_jsxs(_Fragment, { children: [gridPane, pane === 'chart' ? chartPane : null] })) : panes === 'both' ? (_jsx(Splitter, { className: "salmon-gantt__splitter", ...(sizes ? { sizes } : { defaultSizes: { grid: gridDefaultSize } }), onResizeStart: () => g.props.onSplitterResizeStart?.(splitterEvent('splitterResizeStart', paneWidth(rootRef.current))), onResize: (s) => g.props.onSplitterResize?.(splitterEvent('splitterResize', s['grid'] ?? 0)), onSizesChange: (s) => {
487
+ const pos = s['grid'];
488
+ if (pos !== undefined)
489
+ setSplitterSize(pos);
490
+ g.splitterPosition = typeof pos === 'number' ? pos : paneWidth(rootRef.current);
491
+ g.props.onSplitterResizeEnd?.(splitterEvent('splitterResizeEnd', g.splitterPosition));
492
+ }, localeText: { separatorLabel: g.text('splitter') }, panes: [
493
+ { id: 'grid', content: gridPane, minSize: props.splitter?.minSize ?? 0 },
494
+ { id: 'chart', content: chartPane, minSize: props.splitter?.minSize ?? 0 },
495
+ ] })) : panes === 'grid' ? (gridPane) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "salmon-gantt__hidden-grid", children: gridPane }), chartPane] })) }), popups ? _jsx(popups.GanttPopups, { g: g, api: api, version: version, menu: popup, onCloseMenu: () => setPopup(null), formatters: formatters }) : null, tooltip && props.tooltip && hydrated ? _jsx(tooltip.GanttTooltip, { g: g, formatters: formatters }) : null] }));
496
+ }
497
+ /** Width of the first `n` columns (splitter `columnIndex`). */
498
+ function columnsWidth(columns, n) {
499
+ let w = 0;
500
+ for (let i = 0; i <= n && i < columns.length; i++) {
501
+ const c = columns[i]?.width;
502
+ w += typeof c === 'number' ? c : 160;
503
+ }
504
+ return w + 2;
505
+ }
506
+ const paneWidth = (root) => root?.querySelector('.salmon-gantt__grid-pane')?.getBoundingClientRect().width ?? 0;
507
+ /** Props given to the grid pane unchanged (`GanttGridProps`). */
508
+ const GRID_PASS_THROUGH = [
509
+ 'sorting', 'onBeforeSortChange', 'onSortChange', 'filtering', 'onBeforeFilterChange', 'onFilterChange', 'search', 'onBeforeSearchChange', 'onSearchChange',
510
+ 'selection', 'onBeforeSelectionChange', 'columnMenu', 'renderContextMenu', 'reorderable', 'onBeforeColumnReorder', 'onColumnReorder', 'resizable', 'resizeMode',
511
+ 'onColumnResizeStart', 'onColumnResize', 'onColumnResizeEnd', 'columnChooser', 'onBeforeColumnVisibilityChange', 'onColumnVisibilityChange', 'gridLines',
512
+ 'highlightOnHover', 'striped', 'textWrap', 'overflow', 'getCellProps', 'rowClassName', 'renderEmpty', 'loadingIndicator', 'onViewChange', 'onRowDoubleClick',
513
+ 'onRowClick', 'onCellClick', 'rowDrag', 'onRowDrop', 'onRowDragStart', 'onRowDrag', 'onBeforeTreeToggle', 'onTreeToggle', 'onBeforeEditStart',
514
+ 'onBeforeCellValueChange', 'onBeforeSave', 'keyBindings', 'virtualization', 'initialRows', 'currency', 'icons', 'features',
515
+ ];
516
+ //# sourceMappingURL=Gantt.js.map