@jaeungkim/gantt-chart 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +60 -101
- package/dist/components/GanttBar.d.ts +23 -0
- package/dist/components/GanttChartHeader.d.ts +17 -0
- package/dist/components/GanttDependencyArrows.d.ts +15 -0
- package/dist/components/GanttDragGuides.d.ts +9 -0
- package/dist/components/GanttGridSplitter.d.ts +14 -0
- package/dist/components/GanttMarkers.d.ts +18 -0
- package/dist/components/GanttTaskGrid.d.ts +42 -0
- package/dist/components/ScaleSelector.d.ts +11 -0
- package/dist/constants/gantt.d.ts +47 -0
- package/dist/core/calendar.d.ts +45 -0
- package/dist/core/criticalPath.d.ts +67 -0
- package/dist/core/dates.d.ts +32 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/scheduling.d.ts +104 -0
- package/dist/core/tree.d.ts +42 -0
- package/dist/core/types.d.ts +76 -0
- package/dist/gantt-chart.css +1 -1
- package/dist/hooks/useGanttBarDrag.d.ts +35 -0
- package/dist/hooks/useGanttDrawCreate.d.ts +31 -0
- package/dist/hooks/useGanttExportApi.d.ts +30 -0
- package/dist/hooks/useGanttHistoryApi.d.ts +28 -0
- package/dist/hooks/useGanttLinkDrag.d.ts +31 -0
- package/dist/hooks/useGanttProgressDrag.d.ts +16 -0
- package/dist/hooks/useGanttRowDrag.d.ts +33 -0
- package/dist/hooks/useGanttScrollApi.d.ts +63 -0
- package/dist/hooks/useGanttSelectors.d.ts +23 -0
- package/dist/hooks/useGanttVirtualization.d.ts +32 -0
- package/dist/hooks/useResolvedTheme.d.ts +15 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -51
- package/dist/index.js +5819 -0
- package/dist/pages/Gantt.d.ts +306 -0
- package/dist/stores/context.d.ts +10 -0
- package/dist/stores/store.d.ts +118 -0
- package/dist/types/gantt.d.ts +283 -0
- package/dist/types/task.d.ts +111 -0
- package/dist/utils/a11y.d.ts +141 -0
- package/dist/utils/arrowPath.d.ts +66 -0
- package/dist/utils/dependency.d.ts +42 -0
- package/dist/utils/grouping.d.ts +81 -0
- package/dist/utils/headerUtils.d.ts +6 -0
- package/dist/utils/history.d.ts +56 -0
- package/dist/utils/i18n.d.ts +16 -0
- package/dist/utils/mutation.d.ts +47 -0
- package/dist/utils/pngExport.d.ts +67 -0
- package/dist/utils/pointerGesture.d.ts +31 -0
- package/dist/utils/rowDrag.d.ts +69 -0
- package/dist/utils/timeline.d.ts +161 -0
- package/dist/utils/transformData.d.ts +15 -0
- package/dist/utils/viewport.d.ts +95 -0
- package/package.json +47 -32
- package/dist/index.cjs.js +0 -4
- package/dist/index.es.js +0 -2357
- package/dist/readmeImg.png +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Dayjs } from 'dayjs';
|
|
3
|
+
import { GanttTaskDraft } from '../hooks/useGanttDrawCreate';
|
|
4
|
+
import { GanttDependencyChange } from '../hooks/useGanttLinkDrag';
|
|
5
|
+
import { GanttHandle } from '../hooks/useGanttScrollApi';
|
|
6
|
+
import { GanttBarRenderer, GanttBeforeChangeHandler, GanttColumn, GanttDateRange, GanttFormatOverrides, GanttGroupBy, GanttHeaderCellRenderer, GanttMarker, GanttRangeBand, GanttReorderChange, GanttScaleKey, GanttTheme, GanttTooltipRenderer } from '../types/gantt';
|
|
7
|
+
import { Task, TaskTransformed } from '../types/task';
|
|
8
|
+
import { SchedulingPolicy } from 'core';
|
|
9
|
+
export interface GanttProps {
|
|
10
|
+
/**
|
|
11
|
+
* Task data array
|
|
12
|
+
*
|
|
13
|
+
* Only reflected in the chart when the contents actually change. When the
|
|
14
|
+
* parent passes the same data as a new array (an inline literal, a
|
|
15
|
+
* non-memoized map, and so on) the update is ignored, so an edit you just
|
|
16
|
+
* made by dragging is not reverted. Passing an empty array clears the chart.
|
|
17
|
+
*/
|
|
18
|
+
tasks?: Task[];
|
|
19
|
+
/** Callback invoked when tasks change */
|
|
20
|
+
onTasksChange?: (updatedTasks: Task[]) => void;
|
|
21
|
+
/** Chart height (px or a CSS value) */
|
|
22
|
+
height?: number | string;
|
|
23
|
+
/** Chart width (px or a CSS value) */
|
|
24
|
+
width?: number | string;
|
|
25
|
+
/** Theme setting - 'light', 'dark', or 'system' */
|
|
26
|
+
theme?: GanttTheme;
|
|
27
|
+
/**
|
|
28
|
+
* Initial scale
|
|
29
|
+
*
|
|
30
|
+
* A seed value that only applies when the session has no user selection
|
|
31
|
+
* stored (sessionStorage). Once the user changes the scale, that choice is
|
|
32
|
+
* saved and wins on remount, and prop changes after mount are ignored
|
|
33
|
+
* (the usual `default*` prop convention).
|
|
34
|
+
*/
|
|
35
|
+
defaultScale?: GanttScaleKey;
|
|
36
|
+
/** Additional CSS class name */
|
|
37
|
+
className?: string;
|
|
38
|
+
/** Whether to shade weekends/holidays (default true) */
|
|
39
|
+
showNonWorkingDays?: boolean;
|
|
40
|
+
/** Holiday list (ISO date strings, e.g. '2026-01-01') */
|
|
41
|
+
holidays?: string[];
|
|
42
|
+
/** Custom non-working-day predicate - replaces the default weekend/holiday check when given */
|
|
43
|
+
isNonWorkingDay?: (date: Dayjs) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* sessionStorage key the scale selection is stored under (default `"gantt-scale"`)
|
|
46
|
+
*
|
|
47
|
+
* With more than one chart on a page, give them different keys so each
|
|
48
|
+
* remembers its own scale. Sharing one key means the last change made
|
|
49
|
+
* applies to both.
|
|
50
|
+
*/
|
|
51
|
+
storageKey?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Position to scroll to once, after the first render
|
|
54
|
+
*
|
|
55
|
+
* `"today"` moves to today, a date string to that date. Later data updates
|
|
56
|
+
* do not touch the scroll position.
|
|
57
|
+
*/
|
|
58
|
+
initialScrollTo?: "today" | string;
|
|
59
|
+
/** Blocks moving, resizing and progress dragging on every task */
|
|
60
|
+
readOnly?: boolean;
|
|
61
|
+
/** Allows/blocks moving bars (default true) - beats `readOnly` */
|
|
62
|
+
allowMove?: boolean;
|
|
63
|
+
/** Allows/blocks resizing bars (default true) - beats `readOnly` */
|
|
64
|
+
allowResize?: boolean;
|
|
65
|
+
/** Allows/blocks dragging the progress handle (default true) - beats `readOnly` */
|
|
66
|
+
allowProgressChange?: boolean;
|
|
67
|
+
/** Earliest date any bar may be dragged to (ISO string) - a task's own `minDate` wins */
|
|
68
|
+
minDate?: string;
|
|
69
|
+
/** Latest date any bar may be dragged to (ISO string) - a task's own `maxDate` wins */
|
|
70
|
+
maxDate?: string;
|
|
71
|
+
/** Pins the timeline to start here (ISO string) instead of fitting to the tasks */
|
|
72
|
+
visibleStart?: string;
|
|
73
|
+
/** Pins the timeline to end here (ISO string) instead of fitting to the tasks */
|
|
74
|
+
visibleEnd?: string;
|
|
75
|
+
/**
|
|
76
|
+
* BCP 47 locale tag for every date label, e.g. `"ko-KR"`
|
|
77
|
+
*
|
|
78
|
+
* Month and day names, header labels and drag tooltips are rendered with
|
|
79
|
+
* `Intl.DateTimeFormat` (no locale packages to install). Left out, the chart keeps
|
|
80
|
+
* its built-in English labels. An unusable tag falls back to those and warns once.
|
|
81
|
+
*/
|
|
82
|
+
locale?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Per-scale label overrides - `{ quarter: { header: (d) => ... } }`
|
|
85
|
+
*
|
|
86
|
+
* Each scale takes `tick` (bottom row), `header` (top row) and `tooltip` (drag
|
|
87
|
+
* tooltip and guides); whatever is left out keeps the locale's label. Overrides win
|
|
88
|
+
* over `locale`. The `Dayjs` handed in is in UTC mode.
|
|
89
|
+
*/
|
|
90
|
+
formats?: GanttFormatOverrides;
|
|
91
|
+
/**
|
|
92
|
+
* First day of the week, 0 = Sunday .. 6 = Saturday
|
|
93
|
+
*
|
|
94
|
+
* Set it to group the week scale's top header by week starting on that day, instead
|
|
95
|
+
* of by month. Left out, week grouping is off and the header is unchanged.
|
|
96
|
+
*/
|
|
97
|
+
firstDayOfWeek?: number;
|
|
98
|
+
/**
|
|
99
|
+
* Whether to show the task list pane on the left
|
|
100
|
+
*
|
|
101
|
+
* Omitted, the pane appears only when `columns` is given - with neither, the chart
|
|
102
|
+
* renders exactly the timeline it does today.
|
|
103
|
+
*/
|
|
104
|
+
showTaskList?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Column definitions for the task list (default: Name / Start / End)
|
|
107
|
+
*
|
|
108
|
+
* Every header label and cell body comes from here. The first column is the tree
|
|
109
|
+
* column, so indentation and the expander toggle attach to it.
|
|
110
|
+
*/
|
|
111
|
+
columns?: GanttColumn[];
|
|
112
|
+
/**
|
|
113
|
+
* Whether to use the parentId hierarchy (default false)
|
|
114
|
+
*
|
|
115
|
+
* With it on, depth comes from the parentId chain rather than from sequence, and a row
|
|
116
|
+
* with children becomes a summary row: its start/end are recomputed from the children
|
|
117
|
+
* (min..max), dragging its bar moves the whole subtree, and a missing progress is rolled
|
|
118
|
+
* up from the children weighted by duration. Row order itself still comes from
|
|
119
|
+
* `sequence`, hierarchy or not.
|
|
120
|
+
*/
|
|
121
|
+
hierarchy?: boolean;
|
|
122
|
+
/** Ids of collapsed parents (controlled - given, this value is what the chart shows) */
|
|
123
|
+
collapsedIds?: string[];
|
|
124
|
+
/** Initial collapsed list (uncontrolled seed; later changes are ignored) */
|
|
125
|
+
defaultCollapsedIds?: string[];
|
|
126
|
+
/** Called whenever the collapsed state changes - in controlled and uncontrolled mode alike */
|
|
127
|
+
onCollapsedChange?: (collapsedIds: string[]) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Groups the rows into swimlanes - a task field name, or an accessor returning
|
|
130
|
+
* the group value
|
|
131
|
+
*
|
|
132
|
+
* Each group gets a header row and its tasks are indented one level below it.
|
|
133
|
+
* With `hierarchy` on, grouping decides the top level and the parentId nesting
|
|
134
|
+
* is kept inside each group: a task's group is read off its root ancestor, so a
|
|
135
|
+
* subtree is never split across two groups. Group headers collapse through the
|
|
136
|
+
* same `collapsedIds` list, under the id `group:<value>`.
|
|
137
|
+
*/
|
|
138
|
+
groupBy?: GanttGroupBy;
|
|
139
|
+
/** Header label for tasks whose group value is missing (default `"Ungrouped"`) */
|
|
140
|
+
ungroupedLabel?: string;
|
|
141
|
+
/** Allows/blocks drawing dependencies between bars (default true) - beats `readOnly` */
|
|
142
|
+
allowLinkCreate?: boolean;
|
|
143
|
+
/** Allows/blocks selecting and deleting dependency arrows (default true) - beats `readOnly` */
|
|
144
|
+
allowLinkDelete?: boolean;
|
|
145
|
+
/** Allows/blocks drawing a new task on empty row space (default true) - beats `readOnly` */
|
|
146
|
+
allowTaskCreate?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Called with the link the user drew, before it is applied
|
|
149
|
+
*
|
|
150
|
+
* Return false to reject it. Self-links, duplicates and cycles are rejected by the
|
|
151
|
+
* chart during the drag and never reach this callback.
|
|
152
|
+
*/
|
|
153
|
+
onDependencyCreate?: (change: GanttDependencyChange) => boolean | void;
|
|
154
|
+
/** Called with the arrow the user asked to remove, before it is applied - return false to keep it */
|
|
155
|
+
onDependencyDelete?: (change: GanttDependencyChange) => boolean | void;
|
|
156
|
+
/**
|
|
157
|
+
* Called with the range drawn on empty row space, snapped to the current scale
|
|
158
|
+
*
|
|
159
|
+
* The chart adds nothing on its own: the host creates the task (or does not) and passes
|
|
160
|
+
* the new `tasks` array back in.
|
|
161
|
+
*/
|
|
162
|
+
onTaskCreate?: (draft: GanttTaskDraft) => void;
|
|
163
|
+
/** Fires when a bar or a task-list row is clicked (not after a drag) */
|
|
164
|
+
onTaskClick?: (task: TaskTransformed, event: React.MouseEvent) => void;
|
|
165
|
+
/** Fires on a double click. The two clicks that make it up still fire `onTaskClick` */
|
|
166
|
+
onTaskDoubleClick?: (task: TaskTransformed, event: React.MouseEvent) => void;
|
|
167
|
+
/**
|
|
168
|
+
* Fires when the selection changes - null when the empty timeline is clicked
|
|
169
|
+
*
|
|
170
|
+
* Passing it turns selection on: the selected bar and its task-list row are highlighted.
|
|
171
|
+
*/
|
|
172
|
+
onTaskSelect?: (task: TaskTransformed | null) => void;
|
|
173
|
+
/**
|
|
174
|
+
* Whether clicking selects a row
|
|
175
|
+
*
|
|
176
|
+
* Omitted, selection is on only when `onTaskSelect` is given - pass `true` for the
|
|
177
|
+
* highlight without a callback, `false` to turn it off entirely.
|
|
178
|
+
*/
|
|
179
|
+
selectable?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Runs before a move, resize or progress change is written, and can cancel it
|
|
182
|
+
*
|
|
183
|
+
* Returning `false`, a promise resolving to `false`, or a rejected promise rolls the bar
|
|
184
|
+
* back to where the gesture started. Anything else commits and `onTasksChange` follows.
|
|
185
|
+
* While the promise is pending the bar stays where it was dropped, so a server round trip
|
|
186
|
+
* never blocks the UI - and if the user starts another gesture on that bar in the
|
|
187
|
+
* meantime, the late answer is dropped rather than fighting the newer one.
|
|
188
|
+
*/
|
|
189
|
+
onBeforeTaskChange?: GanttBeforeChangeHandler;
|
|
190
|
+
/** Replaces the default bar node entirely - gets the task, its layout, and the handlers to spread */
|
|
191
|
+
renderBar?: GanttBarRenderer;
|
|
192
|
+
/** Replaces the default tooltip node entirely - used for hover and for drag alike */
|
|
193
|
+
renderTooltip?: GanttTooltipRenderer;
|
|
194
|
+
/** Replaces a timeline header cell entirely - both header rows go through it */
|
|
195
|
+
renderHeaderCell?: GanttHeaderCellRenderer;
|
|
196
|
+
/** Hover and drag tooltips (default true) - `false` suppresses both */
|
|
197
|
+
showTooltip?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* How many undo steps to keep (default 100)
|
|
200
|
+
*
|
|
201
|
+
* One completed gesture is one step, however many bars it moved. 0 turns undo off.
|
|
202
|
+
*/
|
|
203
|
+
historyLimit?: number;
|
|
204
|
+
/**
|
|
205
|
+
* Labelled vertical lines at given dates - deadlines, releases, freezes
|
|
206
|
+
*
|
|
207
|
+
* The built-in today line is one of these, so a marker is styled exactly the way it is:
|
|
208
|
+
* a `color`, a `className`, or the `--gantt-marker` variable.
|
|
209
|
+
*/
|
|
210
|
+
markers?: GanttMarker[];
|
|
211
|
+
/** Shaded bands covering a date range - sprints, phases, blackout windows */
|
|
212
|
+
rangeBands?: GanttRangeBand[];
|
|
213
|
+
/**
|
|
214
|
+
* Whether Ctrl/Cmd + wheel steps through the scale ladder (default false)
|
|
215
|
+
*
|
|
216
|
+
* The date under the cursor stays put across the change. Plain wheel keeps scrolling
|
|
217
|
+
* vertically and Shift+wheel horizontally either way.
|
|
218
|
+
*/
|
|
219
|
+
zoomOnWheel?: boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Whether scrolling or dragging past an end grows the rendered range (default false)
|
|
222
|
+
*
|
|
223
|
+
* Off, the timeline covers the tasks plus a fixed buffer and stops there. On, it extends
|
|
224
|
+
* by about a viewport at a time as either end is approached, and what is on screen stays
|
|
225
|
+
* where it is.
|
|
226
|
+
*/
|
|
227
|
+
infiniteScroll?: boolean;
|
|
228
|
+
/** Called whenever the rendered timeline range changes - the hook for lazy-loading tasks */
|
|
229
|
+
onRangeChange?: (range: GanttDateRange) => void;
|
|
230
|
+
/** Whether a bar drag reaching a viewport edge scrolls the timeline (default true) */
|
|
231
|
+
autoScrollOnDrag?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* How a move propagates to the dragged task's successors (default `"off"`)
|
|
234
|
+
*
|
|
235
|
+
* - `"off"` - nothing propagates. A chart that passes no policy behaves exactly as before.
|
|
236
|
+
* - `"shift-on-overlap"` - a successor is pushed later only when the link would break,
|
|
237
|
+
* and is never pulled earlier.
|
|
238
|
+
* - `"maintain-gap"` - a successor sits at its earliest legal date, following the
|
|
239
|
+
* predecessor in both directions, so the gap stays equal to the link's `lag`.
|
|
240
|
+
*
|
|
241
|
+
* Successors are previewed live during the drag and committed in a single
|
|
242
|
+
* `onTasksChange` call on drop. Tasks marked `manuallyScheduled` are never moved.
|
|
243
|
+
*/
|
|
244
|
+
schedulingPolicy?: SchedulingPolicy;
|
|
245
|
+
/**
|
|
246
|
+
* Called with the ids caught in a dependency cycle
|
|
247
|
+
*
|
|
248
|
+
* The engine never follows a cycle - those tasks are left where they are and the rest of
|
|
249
|
+
* the project still schedules. Use `canLink` from the core to keep cycles out of the data
|
|
250
|
+
* in the first place.
|
|
251
|
+
*/
|
|
252
|
+
onSchedulingCycle?: (taskIds: string[]) => void;
|
|
253
|
+
/**
|
|
254
|
+
* Route every date calculation through a working-day calendar (default false)
|
|
255
|
+
*
|
|
256
|
+
* On, durations, drag results and dependency lag all skip non-working days; bars still
|
|
257
|
+
* span them visually but the days do not count. The calendar is built from the same
|
|
258
|
+
* `holidays` / `isNonWorkingDay` configuration that shades the timeline, so what is
|
|
259
|
+
* shaded and what is skipped cannot drift apart.
|
|
260
|
+
*/
|
|
261
|
+
workingCalendar?: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Compute the critical path and highlight it (default false)
|
|
264
|
+
*
|
|
265
|
+
* Adds a `critical` class to zero-slack bars and to the links along the chain, and fills
|
|
266
|
+
* in the read-only `totalSlack` / `freeSlack` / early / late fields on every task so a
|
|
267
|
+
* `columns` renderer can show them. Tasks at 100% progress are never critical.
|
|
268
|
+
*/
|
|
269
|
+
criticalPath?: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Replaces the default baseline bar
|
|
272
|
+
*
|
|
273
|
+
* Called only for tasks that carry `baselineStart`. Return whatever you like - the
|
|
274
|
+
* element is positioned by the row, not by the renderer.
|
|
275
|
+
*/
|
|
276
|
+
renderBaseline?: (task: TaskTransformed) => ReactNode;
|
|
277
|
+
/**
|
|
278
|
+
* Whether a task list row can be dragged to reorder and re-parent (default false)
|
|
279
|
+
*
|
|
280
|
+
* Vertical drag moves the row among its siblings; horizontal offset indents or outdents it
|
|
281
|
+
* the way an outliner does, and dropping onto the middle of a row makes that row the parent.
|
|
282
|
+
* A drop that would put a row inside its own subtree is marked invalid during the drag and
|
|
283
|
+
* does nothing on release.
|
|
284
|
+
*
|
|
285
|
+
* Follows the same guards as a bar move: a row is draggable only where
|
|
286
|
+
* `resolveTaskInteraction` says the task can move, so `readOnly` (or `allowMove: false`, on
|
|
287
|
+
* the chart or on the task) blocks it.
|
|
288
|
+
*/
|
|
289
|
+
allowRowReorder?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Called when a row drag is released on a legal target, before anything is committed
|
|
292
|
+
*
|
|
293
|
+
* Returning `false` cancels the drop - the chart stays as it was and `onTasksChange` does
|
|
294
|
+
* not fire. Otherwise the chart updates and `onTasksChange` fires once with the same array.
|
|
295
|
+
*/
|
|
296
|
+
onReorder?: (change: GanttReorderChange) => void | boolean;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Gantt chart component
|
|
300
|
+
*
|
|
301
|
+
* Creates a store per instance and hands it down through context.
|
|
302
|
+
* (With a module singleton, two charts on one page would share state and
|
|
303
|
+
* overwrite each other)
|
|
304
|
+
*/
|
|
305
|
+
declare const Gantt: import('react').ForwardRefExoticComponent<GanttProps & import('react').RefAttributes<GanttHandle>>;
|
|
306
|
+
export default Gantt;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GanttState, GanttStoreApi } from './store';
|
|
2
|
+
/** Passes the per-instance store down to child components */
|
|
3
|
+
export declare const GanttStoreContext: import('react').Context<import('zustand').StoreApi<GanttState> | null>;
|
|
4
|
+
/** Subscribes to this instance's store */
|
|
5
|
+
export declare function useGanttStore<T>(selector: (state: GanttState) => T): T;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the store API without subscribing (for getState/setState inside event handlers)
|
|
8
|
+
* Must not be used to read values during render - use useGanttStore for that.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useGanttStoreApi(): GanttStoreApi;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { GanttBottomRowCell, GanttDragOffset, GanttLocaleOptions, GanttScaleKey } from '../types/gantt';
|
|
2
|
+
import { Task, TaskTransformed } from '../types/task';
|
|
3
|
+
import { HistoryStack } from '../utils/history';
|
|
4
|
+
import { LinkAnchor, LinkRejection } from '../utils/dependency';
|
|
5
|
+
import { MutationGate } from '../utils/mutation';
|
|
6
|
+
/** Default key the scale selection is persisted under for the session */
|
|
7
|
+
export declare const DEFAULT_SCALE_STORAGE_KEY = "gantt-scale";
|
|
8
|
+
/**
|
|
9
|
+
* Reads the scale saved for the session - null when nothing is stored or session
|
|
10
|
+
* storage cannot be reached
|
|
11
|
+
*
|
|
12
|
+
* Must be called only after mount, never at module load time.
|
|
13
|
+
* (So a bare import does not touch sessionStorage under SSR, and so the first render
|
|
14
|
+
* matches the server's and creates no hydration mismatch)
|
|
15
|
+
*/
|
|
16
|
+
export declare function readPersistedScale(storageKey?: string): GanttScaleKey | null;
|
|
17
|
+
/**
|
|
18
|
+
* Live state of a dependency drag
|
|
19
|
+
*
|
|
20
|
+
* Coordinates are px in the timeline content's space (the same one bars are positioned
|
|
21
|
+
* in), so the preview line can be drawn straight into the arrow SVG.
|
|
22
|
+
*/
|
|
23
|
+
export interface GanttLinkDraft {
|
|
24
|
+
/** Task the drag started on - it becomes the predecessor */
|
|
25
|
+
fromTaskId: string;
|
|
26
|
+
fromAnchor: LinkAnchor;
|
|
27
|
+
fromX: number;
|
|
28
|
+
fromY: number;
|
|
29
|
+
/** Current pointer position */
|
|
30
|
+
toX: number;
|
|
31
|
+
toY: number;
|
|
32
|
+
/** Task under the pointer, null over empty space */
|
|
33
|
+
hoverTaskId: string | null;
|
|
34
|
+
hoverAnchor: LinkAnchor | null;
|
|
35
|
+
/** Why the hovered task cannot be linked - null when the drop would be accepted */
|
|
36
|
+
rejection: LinkRejection | null;
|
|
37
|
+
}
|
|
38
|
+
/** Identifies one dependency: the successor that owns it and the predecessor it points at */
|
|
39
|
+
export interface GanttDependencyRef {
|
|
40
|
+
sourceId: string;
|
|
41
|
+
targetId: string;
|
|
42
|
+
}
|
|
43
|
+
export interface GanttState {
|
|
44
|
+
rawTasks: Task[];
|
|
45
|
+
bottomRowCells: GanttBottomRowCell[];
|
|
46
|
+
selectedScale: GanttScaleKey;
|
|
47
|
+
currentTask: TaskTransformed | null;
|
|
48
|
+
dragOffsets: Record<string, GanttDragOffset>;
|
|
49
|
+
transformedTasks: TaskTransformed[];
|
|
50
|
+
/**
|
|
51
|
+
* While true, virtualization is bypassed and every row, bar, arrow and header
|
|
52
|
+
* cell is rendered at once.
|
|
53
|
+
*
|
|
54
|
+
* Only `exportToPng` turns this on, for the frames it takes to capture the
|
|
55
|
+
* chart - a capture of the virtualized DOM would be a picture of the visible
|
|
56
|
+
* slice with blank space around it.
|
|
57
|
+
*/
|
|
58
|
+
exportMode: boolean;
|
|
59
|
+
/** Locale and label formats - undefined means the built-in English labels */
|
|
60
|
+
localeOptions: GanttLocaleOptions | undefined;
|
|
61
|
+
/** Undo/redo steps, one entry per completed gesture */
|
|
62
|
+
history: HistoryStack;
|
|
63
|
+
/** How many undo steps are kept */
|
|
64
|
+
historyLimit: number;
|
|
65
|
+
/** Dependency drag in progress - null when none is running */
|
|
66
|
+
linkDraft: GanttLinkDraft | null;
|
|
67
|
+
/** Arrow the user clicked, so Delete knows what to remove */
|
|
68
|
+
selectedDependency: GanttDependencyRef | null;
|
|
69
|
+
/** The selected row, or null - drives the highlight on the bar and on its grid row */
|
|
70
|
+
selectedTaskId: string | null;
|
|
71
|
+
/** Ids whose bar is animating back after a vetoed change */
|
|
72
|
+
revertingIds: string[];
|
|
73
|
+
/** Guards before-change handlers that are still in flight (created once, never replaced) */
|
|
74
|
+
mutationGate: MutationGate;
|
|
75
|
+
setSelectedScale: (scale: GanttScaleKey) => void;
|
|
76
|
+
setExportMode: (exportMode: boolean) => void;
|
|
77
|
+
setLocaleOptions: (options: GanttLocaleOptions | undefined) => void;
|
|
78
|
+
setCurrentTask: (task: TaskTransformed | null) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Replaces the task data without touching the history
|
|
81
|
+
*
|
|
82
|
+
* A user gesture must go through `commitTasks` instead, or it will not be undoable.
|
|
83
|
+
*/
|
|
84
|
+
setSelectedTaskId: (taskId: string | null) => void;
|
|
85
|
+
beginRevert: (ids: string[]) => void;
|
|
86
|
+
endRevert: (ids: string[]) => void;
|
|
87
|
+
setRawTasks: (rawTasks: Task[]) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Commits the result of one gesture and records a single undo step for it,
|
|
90
|
+
* however many tasks it touched
|
|
91
|
+
*/
|
|
92
|
+
commitTasks: (rawTasks: Task[]) => void;
|
|
93
|
+
/** Applies the `tasks` prop - a genuine change clears the history, an echo is ignored */
|
|
94
|
+
syncTasksFromProps: (rawTasks: Task[]) => void;
|
|
95
|
+
setHistoryLimit: (limit: number) => void;
|
|
96
|
+
/** Reverts the newest step and returns the resulting tasks, or null when there is none */
|
|
97
|
+
undo: () => Task[] | null;
|
|
98
|
+
/** Replays the newest undone step and returns the resulting tasks, or null when there is none */
|
|
99
|
+
redo: () => Task[] | null;
|
|
100
|
+
setBottomRowCells: (cells: GanttBottomRowCell[]) => void;
|
|
101
|
+
setTransformedTasks: (tasks: TaskTransformed[]) => void;
|
|
102
|
+
/** Update several tasks' offsets at once - dragging a summary bar moves its whole subtree */
|
|
103
|
+
setDragOffsets: (offsets: Record<string, GanttDragOffset>) => void;
|
|
104
|
+
clearDragOffsets: (ids: string[]) => void;
|
|
105
|
+
clearAllDragOffsets: () => void;
|
|
106
|
+
setLinkDraft: (draft: GanttLinkDraft | null) => void;
|
|
107
|
+
setSelectedDependency: (dependency: GanttDependencyRef | null) => void;
|
|
108
|
+
getCurrentDragOffset: (taskId: string) => GanttDragOffset | null;
|
|
109
|
+
getTotalWidth: () => number;
|
|
110
|
+
}
|
|
111
|
+
export type GanttStoreApi = ReturnType<typeof createGanttStore>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates one store per Gantt instance.
|
|
114
|
+
*
|
|
115
|
+
* With a module-scope singleton, two charts on one page would share task, scale
|
|
116
|
+
* and drag state and overwrite each other.
|
|
117
|
+
*/
|
|
118
|
+
export declare function createGanttStore(storageKey?: string): import('zustand').StoreApi<GanttState>;
|