@m3ui-vue/m3ui-vue 1.2.2 → 1.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 (235) hide show
  1. package/dist/API.md +2776 -351
  2. package/dist/MButton-CuNzpoxm.js +172 -0
  3. package/dist/MButton-CuNzpoxm.js.map +1 -0
  4. package/dist/MDialog-HxEL-m58.js +173 -0
  5. package/dist/MDialog-HxEL-m58.js.map +1 -0
  6. package/dist/MIconButton-DoNotQ9v.js +282 -0
  7. package/dist/MIconButton-DoNotQ9v.js.map +1 -0
  8. package/dist/MListItem-DnPtv-hY.js +824 -0
  9. package/dist/MListItem-DnPtv-hY.js.map +1 -0
  10. package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
  11. package/dist/MLoadingIndicator-BQMNX6Dx.js.map +1 -0
  12. package/dist/MMenuItem-Bih0h4-n.js +604 -0
  13. package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
  14. package/dist/MProgressBar-BCoruxA-.js +184 -0
  15. package/dist/MProgressBar-BCoruxA-.js.map +1 -0
  16. package/dist/MSeekBar-LURE1Ah7.js +435 -0
  17. package/dist/MSeekBar-LURE1Ah7.js.map +1 -0
  18. package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
  19. package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
  20. package/dist/MSlider-_J4IS2_z.js +691 -0
  21. package/dist/MSlider-_J4IS2_z.js.map +1 -0
  22. package/dist/MSpinner-BhkMYKOM.js +65 -0
  23. package/dist/MSpinner-BhkMYKOM.js.map +1 -0
  24. package/dist/MTextField-CkzwNBWS.js +296 -0
  25. package/dist/MTextField-CkzwNBWS.js.map +1 -0
  26. package/dist/MTooltip-B67ZDSGp.js +756 -0
  27. package/dist/MTooltip-B67ZDSGp.js.map +1 -0
  28. package/dist/_storageKeys-CYXsUBwK.js +18 -0
  29. package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
  30. package/dist/_useEscapeStack-CjndQhqg.js +19 -0
  31. package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
  32. package/dist/api.json +1 -1
  33. package/dist/chart.js +1 -1
  34. package/dist/code-editor.js +1 -1
  35. package/dist/components/MAudioPlayer.vue.d.ts +115 -0
  36. package/dist/components/MBadge.vue.d.ts +1 -1
  37. package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
  38. package/dist/components/MBox.vue.d.ts +1 -1
  39. package/dist/components/MButton.vue.d.ts +1 -1
  40. package/dist/components/MConfirmDialog.vue.d.ts +1 -1
  41. package/dist/components/MCopyButton.vue.d.ts +2 -2
  42. package/dist/components/MDataTable.vue.d.ts +2 -2
  43. package/dist/components/MDialog.vue.d.ts +2 -2
  44. package/dist/components/MDivider.vue.d.ts +1 -1
  45. package/dist/components/MDragHandle.vue.d.ts +1 -1
  46. package/dist/components/MDrawCanvas.vue.d.ts +148 -0
  47. package/dist/components/MDrawLayers.vue.d.ts +3 -0
  48. package/dist/components/MDrawToolbar.vue.d.ts +34 -0
  49. package/dist/components/MExportButton.vue.d.ts +1 -1
  50. package/dist/components/MFab.vue.d.ts +2 -2
  51. package/dist/components/MFabMenu.vue.d.ts +2 -2
  52. package/dist/components/MFixed.vue.d.ts +1 -1
  53. package/dist/components/MFlex.vue.d.ts +2 -2
  54. package/dist/components/MFloorPlan.vue.d.ts +160 -0
  55. package/dist/components/MFlow.vue.d.ts +305 -0
  56. package/dist/components/MFlowControls.vue.d.ts +33 -0
  57. package/dist/components/MFlowHandle.vue.d.ts +16 -0
  58. package/dist/components/MFlowMinimap.vue.d.ts +22 -0
  59. package/dist/components/MFlowNode.vue.d.ts +35 -0
  60. package/dist/components/MGantt.vue.d.ts +141 -0
  61. package/dist/components/MGanttControls.vue.d.ts +32 -0
  62. package/dist/components/MIconButton.vue.d.ts +3 -1
  63. package/dist/components/MImageCropper.vue.d.ts +110 -0
  64. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  65. package/dist/components/MLightbox.vue.d.ts +2 -2
  66. package/dist/components/MList.vue.d.ts +1 -1
  67. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  68. package/dist/components/MMapControl.vue.d.ts +1 -1
  69. package/dist/components/MMapSearch.vue.d.ts +1 -1
  70. package/dist/components/MMaskField.vue.d.ts +12 -1
  71. package/dist/components/MMenu.vue.d.ts +1 -1
  72. package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
  73. package/dist/components/MNumberField.vue.d.ts +11 -2
  74. package/dist/components/MPdfViewer.vue.d.ts +174 -0
  75. package/dist/components/MPullToRefresh.vue.d.ts +1 -1
  76. package/dist/components/MResourceTimeline.vue.d.ts +149 -0
  77. package/dist/components/MScheduler.vue.d.ts +3 -3
  78. package/dist/components/MScheme.vue.d.ts +1 -1
  79. package/dist/components/MSearchField.vue.d.ts +1 -1
  80. package/dist/components/MSeekBar.vue.d.ts +1 -1
  81. package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
  82. package/dist/components/MSkeleton.vue.d.ts +1 -1
  83. package/dist/components/MSlider.vue.d.ts +2 -2
  84. package/dist/components/MSparkline.vue.d.ts +1 -1
  85. package/dist/components/MSplitter.vue.d.ts +1 -1
  86. package/dist/components/MStack.vue.d.ts +2 -2
  87. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  88. package/dist/components/MSwitch.vue.d.ts +1 -1
  89. package/dist/components/MTable.vue.d.ts +1 -1
  90. package/dist/components/MTagInput.vue.d.ts +12 -1
  91. package/dist/components/MTextField.vue.d.ts +13 -2
  92. package/dist/components/MToolbar.vue.d.ts +1 -1
  93. package/dist/components/MTree.vue.d.ts +2 -2
  94. package/dist/components/MVideoPlayer.vue.d.ts +253 -0
  95. package/dist/components/MVirtualTable.vue.d.ts +1 -1
  96. package/dist/components/MWindow.vue.d.ts +3 -3
  97. package/dist/components/_MFlowEdge.vue.d.ts +9 -0
  98. package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
  99. package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
  100. package/dist/components/_MPdfPage.vue.d.ts +76 -0
  101. package/dist/components/_MTimeBackground.vue.d.ts +14 -0
  102. package/dist/components/_MTimeHeader.vue.d.ts +20 -0
  103. package/dist/composables/_flowPanel.d.ts +2 -0
  104. package/dist/composables/_flowSlot.d.ts +5 -0
  105. package/dist/composables/_ganttTime.d.ts +41 -0
  106. package/dist/composables/_useTimeAxis.d.ts +90 -0
  107. package/dist/composables/drawGeometry.d.ts +119 -0
  108. package/dist/composables/flowFormats.d.ts +79 -0
  109. package/dist/composables/flowLayout.d.ts +45 -0
  110. package/dist/composables/flowPaths.d.ts +53 -0
  111. package/dist/composables/ganttFormats.d.ts +52 -0
  112. package/dist/composables/ganttSchedule.d.ts +99 -0
  113. package/dist/composables/useDrawing.d.ts +44 -0
  114. package/dist/composables/useFlow.d.ts +266 -0
  115. package/dist/composables/useGantt.d.ts +87 -0
  116. package/dist/composables/useLocale.d.ts +163 -0
  117. package/dist/composables/useMediaPlayer.d.ts +101 -0
  118. package/dist/composables/usePdf.d.ts +119 -0
  119. package/dist/composables/useResourceTimeline.d.ts +70 -0
  120. package/dist/draw.d.ts +7 -0
  121. package/dist/draw.js +1700 -0
  122. package/dist/draw.js.map +1 -0
  123. package/dist/flow.d.ts +14 -0
  124. package/dist/flow.js +3542 -0
  125. package/dist/flow.js.map +1 -0
  126. package/dist/flowPaths-CUc6X373.js +161 -0
  127. package/dist/flowPaths-CUc6X373.js.map +1 -0
  128. package/dist/gantt.d.ts +12 -0
  129. package/dist/gantt.js +3575 -0
  130. package/dist/gantt.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/locales/index.js +1148 -7
  133. package/dist/locales/index.js.map +1 -1
  134. package/dist/m3ui-vue.css +1 -1
  135. package/dist/m3ui.js +7286 -7654
  136. package/dist/m3ui.js.map +1 -1
  137. package/dist/map.js +113 -108
  138. package/dist/map.js.map +1 -1
  139. package/dist/media.d.ts +5 -0
  140. package/dist/media.js +1311 -0
  141. package/dist/media.js.map +1 -0
  142. package/dist/pdf.d.ts +4 -0
  143. package/dist/pdf.js +1871 -0
  144. package/dist/pdf.js.map +1 -0
  145. package/dist/rich-text-editor.js +28 -26
  146. package/dist/rich-text-editor.js.map +1 -1
  147. package/dist/styles.css +1 -1
  148. package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
  149. package/dist/useLocale-BpGxplLV.js.map +1 -0
  150. package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
  151. package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
  152. package/package.json +29 -5
  153. package/src/__tests__/MAudioPlayer.test.ts +75 -0
  154. package/src/__tests__/MDrawCanvas.test.ts +110 -0
  155. package/src/__tests__/MFloorPlan.test.ts +97 -0
  156. package/src/__tests__/MFlow.test.ts +575 -0
  157. package/src/__tests__/MGantt.test.ts +130 -0
  158. package/src/__tests__/MImageCropper.test.ts +89 -0
  159. package/src/__tests__/MPdfViewer.test.ts +235 -0
  160. package/src/__tests__/MResourceTimeline.test.ts +102 -0
  161. package/src/__tests__/MVideoPlayer.test.ts +201 -0
  162. package/src/__tests__/drawGeometry.test.ts +58 -0
  163. package/src/__tests__/fieldExpose.test.ts +30 -0
  164. package/src/__tests__/flowFormats.test.ts +185 -0
  165. package/src/__tests__/flowLayout.test.ts +113 -0
  166. package/src/__tests__/ganttFormats.test.ts +76 -0
  167. package/src/__tests__/ganttSchedule.test.ts +136 -0
  168. package/src/__tests__/pdfMock.ts +83 -0
  169. package/src/__tests__/useMediaPlayer.test.ts +182 -0
  170. package/src/__tests__/usePdf.test.ts +102 -0
  171. package/src/components/MAudioPlayer.vue +319 -0
  172. package/src/components/MDrawCanvas.vue +813 -0
  173. package/src/components/MDrawLayers.vue +114 -0
  174. package/src/components/MDrawToolbar.vue +171 -0
  175. package/src/components/MFloorPlan.vue +581 -0
  176. package/src/components/MFlow.vue +2049 -0
  177. package/src/components/MFlowControls.vue +110 -0
  178. package/src/components/MFlowHandle.vue +60 -0
  179. package/src/components/MFlowMinimap.vue +134 -0
  180. package/src/components/MFlowNode.vue +98 -0
  181. package/src/components/MGantt.vue +1609 -0
  182. package/src/components/MGanttControls.vue +77 -0
  183. package/src/components/MIconButton.vue +3 -1
  184. package/src/components/MImageCropper.vue +507 -0
  185. package/src/components/MMaskField.vue +13 -0
  186. package/src/components/MNumberField.vue +13 -0
  187. package/src/components/MPdfViewer.vue +1269 -0
  188. package/src/components/MResourceTimeline.vue +1020 -0
  189. package/src/components/MTagInput.vue +13 -0
  190. package/src/components/MTextField.vue +16 -0
  191. package/src/components/MVideoPlayer.vue +839 -0
  192. package/src/components/_MFlowEdge.vue +100 -0
  193. package/src/components/_MFlowEdgeLabel.vue +56 -0
  194. package/src/components/_MFlowNodeShell.vue +111 -0
  195. package/src/components/_MPdfPage.vue +456 -0
  196. package/src/components/_MTimeBackground.vue +16 -0
  197. package/src/components/_MTimeHeader.vue +31 -0
  198. package/src/composables/_flowPanel.ts +13 -0
  199. package/src/composables/_flowSlot.ts +6 -0
  200. package/src/composables/_ganttTime.ts +200 -0
  201. package/src/composables/_useTimeAxis.ts +224 -0
  202. package/src/composables/drawGeometry.ts +405 -0
  203. package/src/composables/flowFormats.ts +916 -0
  204. package/src/composables/flowLayout.ts +297 -0
  205. package/src/composables/flowPaths.ts +239 -0
  206. package/src/composables/ganttFormats.ts +366 -0
  207. package/src/composables/ganttSchedule.ts +403 -0
  208. package/src/composables/useDrawing.ts +53 -0
  209. package/src/composables/useFlow.ts +250 -0
  210. package/src/composables/useGantt.ts +92 -0
  211. package/src/composables/useLocale.ts +328 -0
  212. package/src/composables/useMediaPlayer.ts +406 -0
  213. package/src/composables/usePdf.ts +456 -0
  214. package/src/composables/useResourceTimeline.ts +76 -0
  215. package/src/draw.ts +25 -0
  216. package/src/flow.ts +26 -0
  217. package/src/gantt.ts +12 -0
  218. package/src/index.ts +4 -0
  219. package/src/locales/de.ts +163 -0
  220. package/src/locales/es.ts +163 -0
  221. package/src/locales/fr.ts +163 -0
  222. package/src/locales/ja.ts +163 -0
  223. package/src/locales/ko.ts +163 -0
  224. package/src/locales/pt.ts +163 -0
  225. package/src/locales/zh.ts +163 -0
  226. package/src/media.ts +5 -0
  227. package/src/pdf.ts +15 -0
  228. package/dist/MMenuItem-D4Gx_l3F.js +0 -929
  229. package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
  230. package/dist/MSlider-Dx_S3vJ9.js +0 -1506
  231. package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
  232. package/dist/MTextField-Bz8JIsnl.js +0 -633
  233. package/dist/MTextField-Bz8JIsnl.js.map +0 -1
  234. package/dist/useLocale-JYxDDeXC.js.map +0 -1
  235. package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
@@ -0,0 +1,1609 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A Gantt chart: a task list (a tree, with columns) beside a timeline of bars you drag to move, pull at the ends to
4
+ * resize, and join with dependencies. Not an M3 spec component: M3 parts (containers, state layers, motion) on the
5
+ * layout planning tools share (MS Project, GanttProject, Frappe Gantt).
6
+ *
7
+ * Tasks are a `v-model` of plain objects (`GanttTask`): dates as `YYYY-MM-DD` (whole days) or datetimes, `progress`,
8
+ * `parentId` for summaries (their dates roll up), `dependencies` (finish-to-start, start-to-start, finish-to-finish,
9
+ * start-to-finish, with a lag), milestones and a baseline. The zoom runs from hours to years (`v-model:scale`,
10
+ * Ctrl + wheel, a pinch); the timeline scrolls both ways, rows and columns rendered only near the view.
11
+ *
12
+ * Editing: drag a bar to move it (with a mouse, or a short press with a finger), its ends to resize it, the
13
+ * triangle under it to set the progress, the dots at its ends onto another bar to make a dependency (which end you
14
+ * leave and reach picks the type); click or tap a dependency for its × to remove it (or Delete). A summary moves
15
+ * with its tasks; selected bars move together. With
16
+ * `schedule="auto"` the tasks that depend on one follow it. Rows reorder by dragging them in the list (onto the
17
+ * middle of a row to put it inside). Every edit is undoable (Ctrl+Z / Ctrl+Shift+Z).
18
+ *
19
+ * Keyboard (in the list): arrows move and expand/collapse, Alt + ←/→ moves the task a step, Alt + Shift + ←/→
20
+ * changes its end, Alt + ↑/↓ reorders it, Ctrl + ] / [ indents and outdents it, F2 renames, Enter opens it
21
+ * (`task-dblclick`), Delete deletes.
22
+ *
23
+ * @slot default Above the chart: MGanttControls, filters of yours. Props: `{ gantt }`
24
+ * @slot bar A bar's content instead of its label. Props: `{ task, selected, critical }`
25
+ * @slot cell-<key> A cell of that column. Props: `{ task, value }`
26
+ * @slot tooltip The card shown over a hovered or dragged bar. Props: `{ task, slack }`
27
+ * @slot empty Shown while there are no tasks
28
+ * @event task-click / task-dblclick / task-contextmenu `(task, event)`
29
+ * @event link A dependency was drawn: `{ from, to, type }` (it's also added to the task)
30
+ * @event unlink A dependency was removed: `{ from, to }`
31
+ * @event change A drag or a key changed tasks: `{ tasks, kind }` with the changed tasks and `'move' | 'resize' | 'progress' | 'reorder' | 'rename'`
32
+ * @event delete Tasks were deleted: `{ tasks }`
33
+ */
34
+ import { computed, nextTick, onBeforeUnmount, onBeforeUpdate, onMounted, onUpdated, provide, ref, shallowRef, toRaw, useSlots, watch } from 'vue'
35
+ import { GANTT_KEY, TIMELINE_CONTROLS_KEY, type GanttColumn, type GanttContext, type GanttScale } from '../composables/useGantt'
36
+ import {
37
+ criticalPath as computeCritical,
38
+ isMilestone,
39
+ normalizeDependency,
40
+ rollupSummaries,
41
+ scheduleTasks,
42
+ spanDates,
43
+ summaryIds,
44
+ taskDays,
45
+ taskSpan,
46
+ type GanttCalendar,
47
+ type GanttDependency,
48
+ type GanttScheduleOptions,
49
+ type GanttTask,
50
+ } from '../composables/ganttSchedule'
51
+ import { DAY, addDays, daysBetween, defaultSnap, formatDate, parseDate, snapTime } from '../composables/_ganttTime'
52
+ import { arrowPath } from '../composables/flowPaths'
53
+ import { playSamples, prefersReducedMotion, sampleSpring } from '../composables/_springAnimation'
54
+ import { useLocale } from '../composables/useLocale'
55
+ import { useTimeAxis } from '../composables/_useTimeAxis'
56
+ import MTimeHeader from './_MTimeHeader.vue'
57
+ import MTimeBackground from './_MTimeBackground.vue'
58
+
59
+ const props = withDefaults(defineProps<{
60
+ tasks?: GanttTask[]
61
+ /** The zoom as a named level; `v-model:scale` follows Ctrl + wheel, pinches and MGanttControls */
62
+ scale?: GanttScale
63
+ /** The starting zoom in px per day, between the named levels (instead of `scale`'s) */
64
+ pxPerDay?: number
65
+ /** Selected task ids (`v-model:selection`) */
66
+ selection?: string[]
67
+ /** Ids of tasks whose children are hidden (`v-model:collapsed`) */
68
+ collapsed?: string[]
69
+ /** The task list's columns (default name, start and duration); `[]` hides the list */
70
+ columns?: GanttColumn[]
71
+ /** The task list's width, px (`v-model:grid-width`; drag its edge) */
72
+ gridWidth?: number
73
+ rowHeight?: number
74
+ /** No editing: drag, resize, link, reorder, rename and delete off */
75
+ readonly?: boolean
76
+ /** `'auto'`: tasks that depend on a moved one follow it (`scheduleTasks` in push mode) */
77
+ schedule?: 'manual' | 'auto'
78
+ /** Working days: shaded when they aren't, and counted by `schedule="auto"` (default Monday to Friday, no holidays) */
79
+ calendar?: GanttCalendar
80
+ /** Highlights the tasks and dependencies whose delay delays the end */
81
+ criticalPath?: boolean
82
+ /** Draws each task's `baselineStart`/`baselineEnd` under it */
83
+ baselines?: boolean
84
+ /** Today, for the line across the timeline (default now; `null` hides it) */
85
+ today?: string | null
86
+ /** Minutes a datetime task snaps to (default by zoom); date-only tasks always snap to days */
87
+ snap?: number
88
+ weekStartsOn?: 0 | 1
89
+ /** Zoom bounds, px per day */
90
+ minPxPerDay?: number
91
+ maxPxPerDay?: number
92
+ /** Locale for dates (Intl); default the app's */
93
+ locale?: string
94
+ /** Accessible name */
95
+ label?: string
96
+ /** Asked before deleting; return false (or a promise of it) to keep them */
97
+ beforeDelete?: (tasks: GanttTask[]) => boolean | Promise<boolean>
98
+ }>(), {
99
+ tasks: () => [],
100
+ scale: 'day',
101
+ rowHeight: 40,
102
+ readonly: false,
103
+ schedule: 'manual',
104
+ criticalPath: false,
105
+ baselines: false,
106
+ weekStartsOn: 1,
107
+ minPxPerDay: 0.15,
108
+ maxPxPerDay: 2400,
109
+ })
110
+
111
+ const emit = defineEmits<{
112
+ 'update:tasks': [GanttTask[]]
113
+ 'update:scale': [GanttScale]
114
+ 'update:selection': [string[]]
115
+ 'update:collapsed': [string[]]
116
+ 'update:gridWidth': [number]
117
+ 'task-click': [GanttTask, MouseEvent]
118
+ 'task-dblclick': [GanttTask, MouseEvent | KeyboardEvent]
119
+ 'task-contextmenu': [GanttTask, MouseEvent]
120
+ link: [{ from: string; to: string; type: NonNullable<GanttDependency['type']> }]
121
+ unlink: [{ from: string; to: string }]
122
+ change: [{ tasks: GanttTask[]; kind: 'move' | 'resize' | 'progress' | 'reorder' | 'rename' }]
123
+ delete: [{ tasks: GanttTask[] }]
124
+ }>()
125
+
126
+ const slots = useSlots()
127
+ const locale = useLocale()
128
+ const lang = computed(() => props.locale ?? (locale.lang === 'en' ? undefined : locale.lang))
129
+
130
+ // ── Tasks, history ────────────────────────────────────────────────────────────────────────────────────────
131
+ // What was last emitted, so a parent without v-model still sees its edits
132
+ const current = shallowRef<GanttTask[]>(props.tasks)
133
+ watch(() => props.tasks, (t) => { current.value = t })
134
+ const preview = shallowRef<GanttTask[] | null>(null)
135
+ const rolled = computed(() => rollupSummaries(toRaw(current.value)))
136
+ const shown = computed(() => preview.value ?? rolled.value)
137
+
138
+ const past: GanttTask[][] = []
139
+ const future: GanttTask[][] = []
140
+ const historyTick = ref(0)
141
+ function emitTasks(next: GanttTask[]) {
142
+ current.value = next
143
+ emit('update:tasks', next)
144
+ }
145
+ function commit(next: GanttTask[]) {
146
+ next = rollupSummaries(next)
147
+ if (next === rolled.value) return
148
+ past.push(toRaw(current.value))
149
+ if (past.length > 100) past.shift()
150
+ future.length = 0
151
+ historyTick.value++
152
+ emitTasks(next)
153
+ }
154
+ function undo() {
155
+ const prev = past.pop()
156
+ if (!prev) return
157
+ future.push(toRaw(current.value))
158
+ historyTick.value++
159
+ emitTasks(prev)
160
+ }
161
+ function redo() {
162
+ const next = future.pop()
163
+ if (!next) return
164
+ past.push(toRaw(current.value))
165
+ historyTick.value++
166
+ emitTasks(next)
167
+ }
168
+ const canUndo = computed(() => (historyTick.value, past.length > 0))
169
+ const canRedo = computed(() => (historyTick.value, future.length > 0))
170
+
171
+ const byId = computed(() => new Map(shown.value.map((t) => [t.id, t])))
172
+ const sums = computed(() => summaryIds(shown.value))
173
+ const childrenOf = computed(() => {
174
+ const m = new Map<string | undefined, GanttTask[]>()
175
+ for (const t of shown.value) {
176
+ const p = t.parentId && byId.value.has(t.parentId) ? t.parentId : undefined
177
+ ;(m.get(p) ?? m.set(p, []).get(p)!).push(t)
178
+ }
179
+ return m
180
+ })
181
+ function descendants(id: string, out: string[] = [], depth = 0): string[] {
182
+ if (depth > 100) return out
183
+ for (const c of childrenOf.value.get(id) ?? []) {
184
+ out.push(c.id)
185
+ descendants(c.id, out, depth + 1)
186
+ }
187
+ return out
188
+ }
189
+
190
+ // ── Selection and folding ─────────────────────────────────────────────────────────────────────────────────
191
+ const selected = ref<string[]>(props.selection ?? [])
192
+ watch(() => props.selection, (s) => { if (s) selected.value = s })
193
+ const selectedSet = computed(() => new Set(selected.value))
194
+ function setSelection(ids: string[]) {
195
+ const ok = ids.filter((id) => byId.value.get(id)?.selectable !== false)
196
+ selected.value = ok
197
+ emit('update:selection', ok)
198
+ }
199
+ const folded = ref<string[]>(props.collapsed ?? [])
200
+ watch(() => props.collapsed, (c) => { if (c) folded.value = c })
201
+ const foldedSet = computed(() => new Set(folded.value))
202
+ function setFolded(ids: string[]) {
203
+ folded.value = ids
204
+ emit('update:collapsed', ids)
205
+ }
206
+ function toggle(id: string, expanded?: boolean) {
207
+ const open = expanded ?? foldedSet.value.has(id)
208
+ setFolded(open ? folded.value.filter((x) => x !== id) : [...folded.value, id])
209
+ }
210
+
211
+ // The rows, in tree order, without what's folded away
212
+ const rows = computed(() => {
213
+ const out: { task: GanttTask; depth: number; parent: boolean }[] = []
214
+ const walk = (p: string | undefined, depth: number) => {
215
+ for (const t of childrenOf.value.get(p) ?? []) {
216
+ const kids = childrenOf.value.has(t.id)
217
+ out.push({ task: t, depth, parent: kids })
218
+ if (kids && !foldedSet.value.has(t.id) && depth < 100) walk(t.id, depth + 1)
219
+ }
220
+ }
221
+ walk(undefined, 0)
222
+ return out
223
+ })
224
+ const rowIndex = computed(() => new Map(rows.value.map((r, i) => [r.task.id, i])))
225
+
226
+ // ── Zoom and time ↔ px ────────────────────────────────────────────────────────────────────────────────────
227
+ const scroller = ref<HTMLElement>()
228
+ const headerHeight = 56
229
+ const defaultColumns = computed<GanttColumn[]>(() => [
230
+ { key: 'name', label: locale.ganttTask },
231
+ { key: 'start', label: locale.ganttStart, width: 96 },
232
+ { key: 'duration', label: locale.ganttDuration, width: 80, align: 'end' },
233
+ ])
234
+ const columnList = computed(() => props.columns ?? defaultColumns.value)
235
+ const showGrid = computed(() => columnList.value.length > 0)
236
+ const gridW = ref(props.gridWidth ?? 320)
237
+ watch(() => props.gridWidth, (w) => { if (w !== undefined) gridW.value = w })
238
+ const listWidth = computed(() => (showGrid.value ? gridW.value : 0))
239
+
240
+ const extent = computed(() => {
241
+ let min = Infinity
242
+ let max = -Infinity
243
+ for (const t of shown.value) {
244
+ const s = taskSpan(t)
245
+ if (!Number.isFinite(s.start)) continue
246
+ min = Math.min(min, s.start)
247
+ max = Math.max(max, s.end)
248
+ if (props.baselines && t.baselineStart) {
249
+ const b = taskSpan({ start: t.baselineStart, end: t.baselineEnd, type: t.type })
250
+ if (Number.isFinite(b.start)) { min = Math.min(min, b.start); max = Math.max(max, b.end) }
251
+ }
252
+ }
253
+ if (!Number.isFinite(min)) min = max = props.today ? parseDate(props.today) : Date.now()
254
+ return { min, max }
255
+ })
256
+ const axis = useTimeAxis({
257
+ scroller,
258
+ listWidth,
259
+ headerHeight,
260
+ extent,
261
+ scale: () => props.scale,
262
+ pxPerDay: () => props.pxPerDay,
263
+ minPxPerDay: () => props.minPxPerDay,
264
+ maxPxPerDay: () => props.maxPxPerDay,
265
+ weekStartsOn: () => props.weekStartsOn,
266
+ lang,
267
+ quarterLabel: () => locale.ganttQuarter,
268
+ today: () => props.today,
269
+ calendar: () => props.calendar,
270
+ onScale: (s) => emit('update:scale', s),
271
+ onPinch: () => { if (gesture) onCancel({ pointerId: gesture.id } as PointerEvent) },
272
+ })
273
+ const { ppd, view, timelineView, origin, timelineWidth, todayMs, xOf, timeAt, zoomIn, zoomOut, setScale, scrollToDate, topCells, bottomCells, offTimes } = axis
274
+ const scaleNow = axis.scaleNow
275
+
276
+ function scrollToTask(id: string) {
277
+ let t = byId.value.get(id)
278
+ // Unfold what hides it
279
+ const hidden: string[] = []
280
+ for (let p = t?.parentId; p && byId.value.has(p); p = byId.value.get(p)!.parentId) if (foldedSet.value.has(p)) hidden.push(p)
281
+ if (hidden.length) setFolded(folded.value.filter((f) => !hidden.includes(f)))
282
+ nextTick(() => {
283
+ t = byId.value.get(id)
284
+ const i = rowIndex.value.get(id)
285
+ if (!t || i === undefined || !scroller.value) return
286
+ const s = taskSpan(t)
287
+ const top = i * props.rowHeight
288
+ const el = scroller.value
289
+ let y = el.scrollTop
290
+ const body = el.clientHeight - headerHeight
291
+ if (top < y) y = top
292
+ else if (top + props.rowHeight > y + body) y = top + props.rowHeight - body
293
+ let x = el.scrollLeft
294
+ const bx = xOf(s.start)
295
+ if (bx < x || bx > x + timelineView.value - 40) x = Math.max(0, bx - 48)
296
+ el.scrollTo({ left: x, top: y, behavior: prefersReducedMotion() ? 'auto' : 'smooth' })
297
+ })
298
+ }
299
+
300
+ // ── Rows in view ──────────────────────────────────────────────────────────────────────────────────────────
301
+ const OVERSCAN = 6
302
+ const firstRow = computed(() => Math.max(0, Math.floor(view.value.top / props.rowHeight) - OVERSCAN))
303
+ const lastRow = computed(() => Math.min(rows.value.length, Math.ceil((view.value.top + view.value.height) / props.rowHeight) + OVERSCAN))
304
+ const visibleRows = computed(() => rows.value.slice(firstRow.value, lastRow.value).map((r, i) => ({ ...r, index: firstRow.value + i })))
305
+ const bodyHeight = computed(() => Math.max(rows.value.length * props.rowHeight, view.value.height - headerHeight))
306
+
307
+ // ── Bars: geometry, springs ───────────────────────────────────────────────────────────────────────────────
308
+ const barH = computed(() => Math.round(props.rowHeight * 0.6))
309
+ const critical = computed(() => (props.criticalPath ? computeCritical(shown.value, { calendar: props.calendar }) : null))
310
+ const criticalPathInfo = computed(() => critical.value ?? computeCritical(shown.value, { calendar: props.calendar }))
311
+ const criticalSet = computed(() => new Set(critical.value?.tasks ?? []))
312
+ const criticalLinks = computed(() => new Set(critical.value?.dependencies ?? []))
313
+
314
+ type Geo = { x: number; w: number }
315
+ const geometry = computed(() => {
316
+ const m = new Map<string, Geo>()
317
+ for (const t of shown.value) {
318
+ const s = taskSpan(t)
319
+ if (!Number.isFinite(s.start)) continue
320
+ m.set(t.id, { x: xOf(s.start), w: isMilestone(t) ? 0 : Math.max(2, xOf(s.end) - xOf(s.start)) })
321
+ }
322
+ return m
323
+ })
324
+ const springs = new Map<string, { x: number; w: number; vx: number; vw: number; tx: number; tw: number }>()
325
+ const barEls = new Map<string, HTMLElement>()
326
+ const linkEls = new Map<string, SVGGElement>()
327
+ let springRaf = 0
328
+ let lastZoom = { ppd: ppd.value, origin: origin.value }
329
+ watch(geometry, (g) => {
330
+ // A zoom or a moved origin redraws everything where it is; anything else springs there
331
+ const instant = lastZoom.ppd !== ppd.value || lastZoom.origin !== origin.value || prefersReducedMotion()
332
+ lastZoom = { ppd: ppd.value, origin: origin.value }
333
+ let animate = false
334
+ for (const [id, t] of g) {
335
+ const s = springs.get(id)
336
+ if (!s || instant) {
337
+ springs.set(id, { x: t.x, w: t.w, vx: 0, vw: 0, tx: t.x, tw: t.w })
338
+ continue
339
+ }
340
+ if (s.tx !== t.x || s.tw !== t.w) { s.tx = t.x; s.tw = t.w; animate = true }
341
+ }
342
+ for (const id of springs.keys()) if (!g.has(id)) springs.delete(id)
343
+ if (animate) startSprings()
344
+ else writeAll()
345
+ }, { immediate: true, flush: 'post' })
346
+ function startSprings() {
347
+ if (springRaf) return
348
+ let last = performance.now()
349
+ const step = (now: number) => {
350
+ let dt = Math.min((now - last) / 1000, 1 / 30)
351
+ last = now
352
+ let moving = false
353
+ while (dt > 0) {
354
+ const h = Math.min(dt, 0.004)
355
+ for (const s of springs.values()) {
356
+ if (s.x === s.tx && s.w === s.tw && !s.vx && !s.vw) continue
357
+ s.vx += (-700 * (s.x - s.tx) - 2 * 0.9 * Math.sqrt(700) * s.vx) * h
358
+ s.x += s.vx * h
359
+ s.vw += (-700 * (s.w - s.tw) - 2 * 0.9 * Math.sqrt(700) * s.vw) * h
360
+ s.w += s.vw * h
361
+ }
362
+ dt -= h
363
+ }
364
+ for (const s of springs.values()) {
365
+ if (Math.abs(s.x - s.tx) < 0.3 && Math.abs(s.vx) < 2 && Math.abs(s.w - s.tw) < 0.3 && Math.abs(s.vw) < 2) {
366
+ s.x = s.tx; s.w = s.tw; s.vx = 0; s.vw = 0
367
+ } else moving = true
368
+ }
369
+ writeAll()
370
+ springRaf = moving ? requestAnimationFrame(step) : 0
371
+ }
372
+ springRaf = requestAnimationFrame(step)
373
+ }
374
+ function writeBar(id: string, el: HTMLElement) {
375
+ const s = springs.get(id)
376
+ if (!s) return
377
+ el.style.transform = `translateX(${s.x}px)`
378
+ el.style.width = `${s.w}px`
379
+ }
380
+ function writeAll() {
381
+ for (const [id, el] of barEls) writeBar(id, el)
382
+ for (const [key, el] of linkEls) writeLink(key, el)
383
+ }
384
+ function bindBar(id: string, el: unknown) {
385
+ if (el instanceof HTMLElement) {
386
+ barEls.set(id, el)
387
+ writeBar(id, el)
388
+ } else barEls.delete(id)
389
+ }
390
+ // The bar's span right now (sprung), for links and hit tests
391
+ const liveGeo = (id: string): Geo | undefined => springs.get(id) ?? geometry.value.get(id)
392
+
393
+ // ── Dependencies ──────────────────────────────────────────────────────────────────────────────────────────
394
+ interface LinkInfo { key: string; from: string; to: string; type: NonNullable<GanttDependency['type']>; lag: number }
395
+ const links = computed(() => {
396
+ const out: LinkInfo[] = []
397
+ for (const t of shown.value) {
398
+ for (const raw of t.dependencies ?? []) {
399
+ const d = normalizeDependency(raw)
400
+ if (byId.value.has(d.id)) out.push({ key: `${d.id}>${t.id}`, from: d.id, to: t.id, type: d.type, lag: d.lag })
401
+ }
402
+ }
403
+ return out
404
+ })
405
+ // A link to or from a folded task is drawn from its nearest visible summary
406
+ function visibleRowOf(id: string): number | undefined {
407
+ let t = byId.value.get(id)
408
+ for (let i = 0; t && i < 100; i++) {
409
+ const r = rowIndex.value.get(t.id)
410
+ if (r !== undefined) return r
411
+ t = t.parentId ? byId.value.get(t.parentId) : undefined
412
+ }
413
+ return undefined
414
+ }
415
+ const visibleLinks = computed(() => {
416
+ const top = firstRow.value
417
+ const bottom = lastRow.value
418
+ return links.value.filter((l) => {
419
+ const a = visibleRowOf(l.from)
420
+ const b = visibleRowOf(l.to)
421
+ if (a === undefined || b === undefined || a === b) return false
422
+ return Math.min(a, b) <= bottom && Math.max(a, b) >= top
423
+ })
424
+ })
425
+ const GAP = 10
426
+ function linkPoints(l: LinkInfo): [number, number][] | null {
427
+ const ra = visibleRowOf(l.from)
428
+ const rb = visibleRowOf(l.to)
429
+ if (ra === undefined || rb === undefined) return null
430
+ // A folded task's links start and end at the row that shows it
431
+ const p = liveGeo(rows.value[ra]!.task.id)
432
+ const s = liveGeo(rows.value[rb]!.task.id)
433
+ if (!p || !s) return null
434
+ const rh = props.rowHeight
435
+ const y1 = ra * rh + rh / 2
436
+ const y2 = rb * rh + rh / 2
437
+ const fromEnd = l.type === 'FS' || l.type === 'FF'
438
+ const toStart = l.type === 'FS' || l.type === 'SS'
439
+ // Milestones are diamonds: links touch their points
440
+ const half = (g: Geo) => (g.w ? 0 : barH.value * 0.4)
441
+ const x1 = fromEnd ? p.x + p.w + half(p) : p.x - half(p)
442
+ const x2 = toStart ? s.x - half(s) : s.x + s.w + half(s)
443
+ const a = x1 + (fromEnd ? GAP : -GAP)
444
+ const b = x2 + (toStart ? -GAP : GAP)
445
+ const direct = toStart ? a <= b : a >= b
446
+ if (direct) return [[x1, y1], [a, y1], [a, y2], [x2, y2]]
447
+ const ym = y2 > y1 ? rb * rh : (rb + 1) * rh
448
+ return [[x1, y1], [a, y1], [a, ym], [b, ym], [b, y2], [x2, y2]]
449
+ }
450
+ function roundedPath(pts: [number, number][], r = 6): string {
451
+ let d = `M${pts[0]![0]},${pts[0]![1]}`
452
+ for (let i = 1; i < pts.length - 1; i++) {
453
+ const [px, py] = pts[i - 1]!
454
+ const [x, y] = pts[i]!
455
+ const [nx, ny] = pts[i + 1]!
456
+ const l1 = Math.hypot(x - px, y - py)
457
+ const l2 = Math.hypot(nx - x, ny - y)
458
+ const k = Math.min(r, l1 / 2, l2 / 2)
459
+ if (k < 0.5) { d += ` L${x},${y}`; continue }
460
+ const ax = x - ((x - px) / l1) * k
461
+ const ay = y - ((y - py) / l1) * k
462
+ const bx = x + ((nx - x) / l2) * k
463
+ const by = y + ((ny - y) / l2) * k
464
+ d += ` L${ax},${ay} Q${x},${y} ${bx},${by}`
465
+ }
466
+ const [lx, ly] = pts.at(-1)!
467
+ return `${d} L${lx},${ly}`
468
+ }
469
+ function writeLink(key: string, g: SVGGElement) {
470
+ const l = links.value.find((x) => x.key === key)
471
+ const pts = l && linkPoints(l)
472
+ if (!pts) return
473
+ const d = roundedPath(pts)
474
+ const [x2, y2] = pts.at(-1)!
475
+ const toStart = l!.type === 'FS' || l!.type === 'SS'
476
+ const paths = g.querySelectorAll('path')
477
+ paths[0]?.setAttribute('d', d)
478
+ paths[1]?.setAttribute('d', d)
479
+ paths[2]?.setAttribute('d', arrowPath(x2, y2, toStart ? 0 : Math.PI, 7, true))
480
+ }
481
+ function bindLink(key: string, el: unknown) {
482
+ if (el instanceof SVGGElement) {
483
+ linkEls.set(key, el)
484
+ writeLink(key, el)
485
+ } else linkEls.delete(key)
486
+ }
487
+ const selectedLink = ref<string | null>(null)
488
+ const selectedLinkMid = computed(() => {
489
+ const l = links.value.find((x) => x.key === selectedLink.value)
490
+ const pts = l && linkPoints(l)
491
+ if (!pts) return null
492
+ const i = Math.floor((pts.length - 1) / 2)
493
+ return { x: (pts[i]![0] + pts[i + 1]![0]) / 2, y: (pts[i]![1] + pts[i + 1]![1]) / 2 }
494
+ })
495
+ function unlink(from: string, to: string) {
496
+ const t = current.value.find((x) => x.id === to)
497
+ if (!t?.dependencies?.some((d) => normalizeDependency(d).id === from)) return
498
+ commit(current.value.map((x) => (x.id === to ? { ...x, dependencies: x.dependencies!.filter((d) => normalizeDependency(d).id !== from) } : x)))
499
+ if (selectedLink.value === `${from}>${to}`) selectedLink.value = null
500
+ emit('unlink', { from, to })
501
+ announce(locale.ganttUnlink)
502
+ }
503
+ // Whether `a` already waits on `b`, through any chain
504
+ function dependsOn(a: string, b: string): boolean {
505
+ const seen = new Set<string>()
506
+ const stack = [a]
507
+ while (stack.length) {
508
+ const id = stack.pop()!
509
+ if (id === b) return true
510
+ if (seen.has(id)) continue
511
+ seen.add(id)
512
+ for (const d of byId.value.get(id)?.dependencies ?? []) stack.push(normalizeDependency(d).id)
513
+ }
514
+ return false
515
+ }
516
+ function canLink(from: string, to: string) {
517
+ if (from === to || props.readonly) return false
518
+ const a = byId.value.get(from)
519
+ const b = byId.value.get(to)
520
+ if (!a || !b || a.linkable === false || b.linkable === false) return false
521
+ // Not within its own family, not twice, not in a circle
522
+ if (descendants(from).includes(to) || descendants(to).includes(from)) return false
523
+ if (b.dependencies?.some((d) => normalizeDependency(d).id === from)) return false
524
+ return !dependsOn(from, to)
525
+ }
526
+ function link(from: string, to: string, type: NonNullable<GanttDependency['type']> = 'FS', lag = 0) {
527
+ if (!canLink(from, to)) return
528
+ const dep: string | GanttDependency = type === 'FS' && !lag ? from : { id: from, type, ...(lag ? { lag } : {}) }
529
+ let next = current.value.map((x) => (x.id === to ? { ...x, dependencies: [...(x.dependencies ?? []), dep] } : x))
530
+ if (props.schedule === 'auto') next = scheduleTasks(next, scheduleOptions())
531
+ commit(next)
532
+ emit('link', { from, to, type })
533
+ announce(locale.ganttLinked.replace('{from}', byId.value.get(from)?.name ?? from).replace('{to}', byId.value.get(to)?.name ?? to))
534
+ }
535
+ const scheduleOptions = (): GanttScheduleOptions => ({ calendar: props.calendar ? props.calendar : undefined })
536
+
537
+ // ── Editing API ───────────────────────────────────────────────────────────────────────────────────────────
538
+ function addTasks(tasks: GanttTask | GanttTask[], opts: { after?: string } = {}) {
539
+ const list = Array.isArray(tasks) ? tasks : [tasks]
540
+ const next = [...current.value]
541
+ let at = opts.after ? next.findIndex((t) => t.id === opts.after) : -1
542
+ if (at >= 0) {
543
+ // After its subtree
544
+ const sub = new Set(descendants(opts.after!))
545
+ while (at + 1 < next.length && sub.has(next[at + 1]!.id)) at++
546
+ next.splice(at + 1, 0, ...list)
547
+ } else next.push(...list)
548
+ commit(next)
549
+ }
550
+ function updateTask(id: string, patch: Partial<GanttTask> | ((t: GanttTask) => GanttTask)) {
551
+ let next = current.value.map((t) => (t.id === id ? (typeof patch === 'function' ? patch(t) : { ...t, ...patch }) : t))
552
+ if (props.schedule === 'auto') next = scheduleTasks(next, scheduleOptions())
553
+ commit(next)
554
+ }
555
+ async function removeTasks(ids: string[]) {
556
+ const gone = new Set<string>()
557
+ for (const id of ids) {
558
+ const t = byId.value.get(id)
559
+ if (!t || t.deletable === false) continue
560
+ gone.add(id)
561
+ for (const d of descendants(id)) gone.add(d)
562
+ }
563
+ if (!gone.size) return
564
+ const removed = current.value.filter((t) => gone.has(t.id))
565
+ if (props.beforeDelete && !(await props.beforeDelete(removed))) return
566
+ commit(current.value
567
+ .filter((t) => !gone.has(t.id))
568
+ .map((t) => (t.dependencies?.some((d) => gone.has(normalizeDependency(d).id)) ? { ...t, dependencies: t.dependencies.filter((d) => !gone.has(normalizeDependency(d).id)) } : t)))
569
+ setSelection(selected.value.filter((id) => !gone.has(id)))
570
+ emit('delete', { tasks: removed })
571
+ announce(locale.ganttDeleted.replace('{count}', String(removed.length)))
572
+ }
573
+ function runSchedule(options?: GanttScheduleOptions) {
574
+ commit(scheduleTasks(current.value, { ...scheduleOptions(), ...options }))
575
+ }
576
+ function dateAt(clientX: number) {
577
+ const r = scroller.value?.getBoundingClientRect()
578
+ const x = clientX - (r?.left ?? 0) - listWidth.value + view.value.left
579
+ return formatDate(snapTime(timeAt(x), 1440), true)
580
+ }
581
+
582
+ // ── Pointer gestures on the timeline ──────────────────────────────────────────────────────────────────────
583
+ type Part = 'body' | 'start' | 'end' | 'progress' | 'link-start' | 'link-end'
584
+ type Gesture =
585
+ | { kind: 'bar'; part: Part; id: number; taskId: string; sx: number; sy: number; sl: number; touch: boolean; active: boolean; spans: Map<string, { start: number; end: number }>; moving: string[] }
586
+ | { kind: 'pan'; id: number; sx: number; sy: number; sl: number; st: number; moved: boolean }
587
+ | { kind: 'row'; id: number; taskId: string; sx: number; sy: number; st: number; touch: boolean; active: boolean }
588
+ | { kind: 'split'; id: number; sx: number; w: number }
589
+ let gesture: Gesture | null = null
590
+ let pressTimer: ReturnType<typeof setTimeout> | undefined
591
+ const dragging = ref<{ taskId: string; part: Part } | null>(null)
592
+ const linkDraft = ref<{ from: string; fromEnd: boolean; x: number; y: number; target: string | null; targetEnd: boolean; valid: boolean } | null>(null)
593
+ const rowDrop = ref<{ taskId: string; target: string; where: 'before' | 'after' | 'inside' } | null>(null)
594
+ const pointer = { x: 0, y: 0 }
595
+
596
+ function contentPoint(clientX: number, clientY: number) {
597
+ const r = scroller.value!.getBoundingClientRect()
598
+ return { x: clientX - r.left - listWidth.value + scroller.value!.scrollLeft, y: clientY - r.top - headerHeight + scroller.value!.scrollTop }
599
+ }
600
+ const isControl = (t: EventTarget | null) => t instanceof Element && !!t.closest('input, textarea, select, button, a, [contenteditable], [data-gantt-action]')
601
+
602
+ function onBarDown(e: PointerEvent, task: GanttTask, part: Part) {
603
+ if (e.button !== 0 || isControl(e.target)) return
604
+ if (props.readonly && part !== 'body') return
605
+ e.stopPropagation()
606
+ const touch = e.pointerType === 'touch'
607
+ gesture = { kind: 'bar', part, id: e.pointerId, taskId: task.id, sx: e.clientX, sy: e.clientY, sl: scroller.value!.scrollLeft, touch, active: false, spans: new Map(), moving: [] }
608
+ addWindow()
609
+ // A finger scrolls unless it holds still a moment first; handles take it at once
610
+ if (touch && part === 'body') pressTimer = setTimeout(() => activate(e), 250)
611
+ else if (touch) activate(e)
612
+ }
613
+ function onPaneDown(e: PointerEvent) {
614
+ if (e.button !== 0 || e.pointerType === 'touch' || isControl(e.target)) return
615
+ gesture = { kind: 'pan', id: e.pointerId, sx: e.clientX, sy: e.clientY, sl: scroller.value!.scrollLeft, st: scroller.value!.scrollTop, moved: false }
616
+ addWindow()
617
+ }
618
+ function onRowDown(e: PointerEvent, task: GanttTask) {
619
+ if (e.button !== 0 || isControl(e.target) || props.readonly || editing.value) return
620
+ const touch = e.pointerType === 'touch'
621
+ gesture = { kind: 'row', id: e.pointerId, taskId: task.id, sx: e.clientX, sy: e.clientY, st: scroller.value!.scrollTop, touch, active: false }
622
+ addWindow()
623
+ if (touch) pressTimer = setTimeout(() => activate(e), 350)
624
+ }
625
+ function onSplitDown(e: PointerEvent) {
626
+ if (e.button !== 0) return
627
+ e.preventDefault()
628
+ gesture = { kind: 'split', id: e.pointerId, sx: e.clientX, w: gridW.value }
629
+ addWindow()
630
+ }
631
+ function addWindow() {
632
+ window.addEventListener('pointermove', onMove)
633
+ window.addEventListener('pointerup', onUp)
634
+ window.addEventListener('pointercancel', onCancel)
635
+ }
636
+ function removeWindow() {
637
+ window.removeEventListener('pointermove', onMove)
638
+ window.removeEventListener('pointerup', onUp)
639
+ window.removeEventListener('pointercancel', onCancel)
640
+ clearTimeout(pressTimer)
641
+ document.body.style.userSelect = ''
642
+ }
643
+
644
+ function activate(e: PointerEvent) {
645
+ const g = gesture
646
+ if (!g || (g.kind !== 'bar' && g.kind !== 'row') || g.active) return
647
+ const t = byId.value.get(g.taskId)
648
+ if (!t) return
649
+ if (g.kind === 'bar') {
650
+ if (g.part === 'body' && (props.readonly || t.draggable === false)) return
651
+ if ((g.part === 'start' || g.part === 'end') && t.resizable === false) return
652
+ if ((g.part === 'link-start' || g.part === 'link-end') && t.linkable === false) return
653
+ g.active = true
654
+ // What moves: the task (or the selection, if it's in it), summaries with all their tasks
655
+ const roots = g.part === 'body' && selectedSet.value.has(t.id) ? selected.value : [t.id]
656
+ const moving = new Set<string>()
657
+ for (const id of roots) {
658
+ const r = byId.value.get(id)
659
+ if (!r || r.draggable === false) continue
660
+ moving.add(id)
661
+ for (const d of descendants(id)) moving.add(d)
662
+ }
663
+ g.moving = g.part === 'body' ? [...moving] : [t.id]
664
+ for (const id of g.moving) {
665
+ const s = taskSpan(byId.value.get(id)!)
666
+ g.spans.set(id, { start: s.start, end: s.end })
667
+ }
668
+ if (!selectedSet.value.has(t.id)) setSelection([t.id])
669
+ dragging.value = { taskId: t.id, part: g.part }
670
+ if (g.part === 'link-start' || g.part === 'link-end') {
671
+ const p = contentPoint(e.clientX, e.clientY)
672
+ linkDraft.value = { from: t.id, fromEnd: g.part === 'link-end', x: p.x, y: p.y, target: null, targetEnd: false, valid: false }
673
+ }
674
+ } else {
675
+ g.active = true
676
+ dragging.value = { taskId: t.id, part: 'body' }
677
+ }
678
+ if (g.touch) navigator.vibrate?.(10)
679
+ document.body.style.userSelect = 'none'
680
+ startAutoScroll()
681
+ }
682
+
683
+ function onMove(e: PointerEvent) {
684
+ const g = gesture
685
+ if (!g || g.id !== e.pointerId) return
686
+ pointer.x = e.clientX
687
+ pointer.y = e.clientY
688
+ if (g.kind === 'split') {
689
+ const w = Math.round(Math.min(Math.max(120, g.w + e.clientX - g.sx), Math.max(160, view.value.width - 80)))
690
+ gridW.value = w
691
+ emit('update:gridWidth', w)
692
+ return
693
+ }
694
+ if (g.kind === 'pan') {
695
+ const dx = e.clientX - g.sx
696
+ const dy = e.clientY - g.sy
697
+ if (!g.moved && Math.hypot(dx, dy) < 4) return
698
+ g.moved = true
699
+ scroller.value!.scrollLeft = g.sl - dx
700
+ scroller.value!.scrollTop = g.st - dy
701
+ return
702
+ }
703
+ if (!g.active) {
704
+ const d = Math.hypot(e.clientX - g.sx, e.clientY - g.sy)
705
+ if (g.touch) {
706
+ // Moving before the press is long enough: it's a scroll
707
+ if (d > 8) { gesture = null; removeWindow() }
708
+ return
709
+ }
710
+ if (d < 4) return
711
+ activate(e)
712
+ if (!g.active) return
713
+ }
714
+ dragTo(e.clientX, e.clientY)
715
+ }
716
+
717
+ function snapStep(t: GanttTask) {
718
+ return taskSpan(t).dateOnly ? 1440 : (props.snap ?? defaultSnap(ppd.value))
719
+ }
720
+ function dragTo(clientX: number, clientY: number) {
721
+ const g = gesture
722
+ if (!g || (g.kind !== 'bar' && g.kind !== 'row') || !g.active) return
723
+ if (g.kind === 'row') return dragRow(clientY)
724
+ const p = contentPoint(clientX, clientY)
725
+ const dx = clientX - g.sx + (scroller.value!.scrollLeft - g.sl)
726
+ const dt = (dx / ppd.value) * DAY
727
+ const lead = byId.value.get(g.taskId)!
728
+ const base = rolled.value
729
+ if (g.part === 'link-start' || g.part === 'link-end') {
730
+ const hit = barAt(clientX, clientY)
731
+ const target = hit && hit !== g.taskId ? hit : null
732
+ const geo = target ? liveGeo(target) : undefined
733
+ const targetEnd = !!geo && p.x > geo.x + geo.w / 2
734
+ linkDraft.value = { from: g.taskId, fromEnd: g.part === 'link-end', x: p.x, y: p.y, target, targetEnd, valid: !!target && canLink(g.taskId, target) }
735
+ return
736
+ }
737
+ const patched = new Map<string, GanttTask>()
738
+ if (g.part === 'progress') {
739
+ const s = g.spans.get(g.taskId)!
740
+ const x0 = xOf(s.start)
741
+ const w = Math.max(1, xOf(s.end) - x0)
742
+ const progress = Math.round(Math.min(100, Math.max(0, ((p.x - x0) / w) * 100)))
743
+ patched.set(g.taskId, { ...lead, progress })
744
+ } else if (g.part === 'body') {
745
+ // The lead task snaps; the rest move by the same amount
746
+ const s0 = g.spans.get(g.taskId)!
747
+ const step = snapStep(lead)
748
+ const snapped = snapTime(s0.start + dt, step)
749
+ const days = taskSpan(lead).dateOnly ? daysBetween(s0.start, snapped) : 0
750
+ const shift = snapped - s0.start
751
+ for (const id of g.moving) {
752
+ const t = base.find((x) => x.id === id)
753
+ const s = g.spans.get(id)
754
+ if (!t || !s || (sums.value.has(id) && childrenOf.value.has(id))) continue
755
+ const dateOnly = taskSpan(t).dateOnly
756
+ const ns = dateOnly ? addDays(s.start, days || Math.round(shift / DAY)) : s.start + shift
757
+ const ne = dateOnly ? addDays(s.end, days || Math.round(shift / DAY)) : s.end + shift
758
+ patched.set(id, { ...t, ...spanDates(t, ns, ne) })
759
+ }
760
+ } else {
761
+ const s0 = g.spans.get(g.taskId)!
762
+ const step = snapStep(lead)
763
+ const min = taskSpan(lead).dateOnly ? DAY : step * 60_000
764
+ if (g.part === 'start') {
765
+ const ns = Math.min(snapTime(s0.start + dt, step), s0.end - min)
766
+ patched.set(g.taskId, { ...lead, ...spanDates(lead, ns, s0.end) })
767
+ } else {
768
+ const ne = Math.max(snapTime(s0.end + dt, step), s0.start + min)
769
+ patched.set(g.taskId, { ...lead, ...spanDates(lead, s0.start, ne) })
770
+ }
771
+ }
772
+ let next = base.map((t) => patched.get(t.id) ?? t)
773
+ if (props.schedule === 'auto' && g.part !== 'progress') next = scheduleTasks(next, scheduleOptions())
774
+ preview.value = rollupSummaries(next)
775
+ }
776
+ function barAt(clientX: number, clientY: number): string | null {
777
+ const el = document.elementFromPoint?.(clientX, clientY)
778
+ const bar = el?.closest('[data-gantt-task]')
779
+ if (bar) return bar.getAttribute('data-gantt-task')
780
+ // Anywhere on a row also counts
781
+ const p = contentPoint(clientX, clientY)
782
+ const r = rows.value[Math.floor(p.y / props.rowHeight)]
783
+ return r?.task.id ?? null
784
+ }
785
+
786
+ function dragRow(clientY: number) {
787
+ const g = gesture as Extract<Gesture, { kind: 'row' }>
788
+ const r = scroller.value!.getBoundingClientRect()
789
+ const y = clientY - r.top - headerHeight + scroller.value!.scrollTop
790
+ const i = Math.max(0, Math.min(rows.value.length - 1, Math.floor(y / props.rowHeight)))
791
+ const target = rows.value[i]!.task
792
+ const f = y / props.rowHeight - i
793
+ const blocked = target.id === g.taskId || descendants(g.taskId).includes(target.id)
794
+ const where: 'before' | 'after' | 'inside' = f < 0.3 ? 'before' : f > 0.7 ? 'after' : 'inside'
795
+ rowDrop.value = blocked ? null : { taskId: g.taskId, target: target.id, where }
796
+ }
797
+ function moveRow(id: string, target: string, where: 'before' | 'after' | 'inside') {
798
+ const list = current.value
799
+ const moving = new Set([id, ...descendants(id)])
800
+ const block = list.filter((t) => moving.has(t.id))
801
+ const rest = list.filter((t) => !moving.has(t.id))
802
+ const tIndex = rest.findIndex((t) => t.id === target)
803
+ if (tIndex < 0) return
804
+ const targetTask = rest[tIndex]!
805
+ let at = tIndex
806
+ if (where !== 'before') {
807
+ // After the target's own subtree
808
+ const sub = new Set(descendants(target))
809
+ at = tIndex + 1
810
+ while (at < rest.length && sub.has(rest[at]!.id)) at++
811
+ }
812
+ const parentId = where === 'inside' ? target : targetTask.parentId
813
+ const head = block[0]!
814
+ const moved = { ...head, parentId } as GanttTask
815
+ if (!parentId) delete moved.parentId
816
+ block[0] = moved
817
+ const next = [...rest.slice(0, at), ...block, ...rest.slice(at)]
818
+ if (where === 'inside' && foldedSet.value.has(target)) toggle(target, true)
819
+ commit(next)
820
+ const pos = rows.value.findIndex((r) => r.task.id === id) + 1
821
+ emit('change', { tasks: [moved], kind: 'reorder' })
822
+ nextTick(() => announce(locale.ganttReordered.replace('{name}', moved.name).replace('{pos}', String(rows.value.findIndex((r) => r.task.id === id) + 1 || pos))))
823
+ }
824
+
825
+ function onUp(e: PointerEvent) {
826
+ const g = gesture
827
+ if (!g || g.id !== e.pointerId) return
828
+ gesture = null
829
+ removeWindow()
830
+ stopAutoScroll()
831
+ if (g.kind === 'pan' || g.kind === 'split') return
832
+ if (g.kind === 'row') {
833
+ dragging.value = null
834
+ const drop = rowDrop.value
835
+ rowDrop.value = null
836
+ if (g.active && drop) moveRow(drop.taskId, drop.target, drop.where)
837
+ return
838
+ }
839
+ dragging.value = null
840
+ if (!g.active) {
841
+ const t = byId.value.get(g.taskId)
842
+ if (!t) return
843
+ selectFromClick(t, e)
844
+ emit('task-click', t, e)
845
+ return
846
+ }
847
+ if (g.part === 'link-start' || g.part === 'link-end') {
848
+ const d = linkDraft.value
849
+ linkDraft.value = null
850
+ if (d?.target && d.valid) link(d.from, d.target, d.fromEnd ? (d.targetEnd ? 'FF' : 'FS') : d.targetEnd ? 'SF' : 'SS')
851
+ return
852
+ }
853
+ const next = preview.value
854
+ preview.value = null
855
+ if (!next) return
856
+ const before = new Map(rolled.value.map((t) => [t.id, t]))
857
+ const changed = next.filter((t) => before.get(t.id) && before.get(t.id) !== t && !(sums.value.has(t.id) && childrenOf.value.has(t.id)))
858
+ if (!changed.length) return
859
+ // Keep the order and the objects of what didn't change
860
+ const byNext = new Map(next.map((t) => [t.id, t]))
861
+ commit(current.value.map((t) => (changed.some((c) => c.id === t.id) ? byNext.get(t.id)! : t)))
862
+ const kind = g.part === 'progress' ? 'progress' : g.part === 'body' ? 'move' : 'resize'
863
+ emit('change', { tasks: changed, kind })
864
+ const lead = byNext.get(g.taskId)!
865
+ if (kind === 'progress') announce(locale.ganttProgressSet.replace('{name}', lead.name).replace('{progress}', String(lead.progress ?? 0)))
866
+ else announce(locale.ganttMoved.replace('{name}', lead.name).replace('{start}', formatShort(lead.start)).replace('{end}', formatShort(lead.end ?? lead.start)))
867
+ }
868
+ function onCancel(e: PointerEvent) {
869
+ if (!gesture || gesture.id !== e.pointerId) return
870
+ gesture = null
871
+ removeWindow()
872
+ stopAutoScroll()
873
+ preview.value = null
874
+ dragging.value = null
875
+ linkDraft.value = null
876
+ rowDrop.value = null
877
+ }
878
+
879
+ function selectFromClick(t: GanttTask, e: MouseEvent) {
880
+ selectedLink.value = null
881
+ if (t.selectable === false) return
882
+ if (e.shiftKey || e.metaKey || e.ctrlKey) setSelection(selectedSet.value.has(t.id) ? selected.value.filter((x) => x !== t.id) : [...selected.value, t.id])
883
+ else setSelection([t.id])
884
+ focusedId.value = t.id
885
+ }
886
+
887
+ // Scroll while a drag is held near an edge
888
+ let autoRaf = 0
889
+ function startAutoScroll() {
890
+ if (autoRaf) return
891
+ const step = () => {
892
+ autoRaf = requestAnimationFrame(step)
893
+ const el = scroller.value
894
+ if (!el || !gesture || !('active' in gesture) || !gesture.active) return
895
+ const r = el.getBoundingClientRect()
896
+ const edge = 40
897
+ const left = r.left + listWidth.value
898
+ let dx = 0
899
+ let dy = 0
900
+ if (gesture.kind === 'bar') {
901
+ if (pointer.x < left + edge) dx = -Math.ceil((left + edge - pointer.x) / 4)
902
+ else if (pointer.x > r.right - edge) dx = Math.ceil((pointer.x - r.right + edge) / 4)
903
+ }
904
+ if (pointer.y < r.top + headerHeight + edge) dy = -Math.ceil((r.top + headerHeight + edge - pointer.y) / 4)
905
+ else if (pointer.y > r.bottom - edge) dy = Math.ceil((pointer.y - r.bottom + edge) / 4)
906
+ if (!dx && !dy) return
907
+ el.scrollLeft += dx
908
+ el.scrollTop += dy
909
+ dragTo(pointer.x, pointer.y)
910
+ }
911
+ autoRaf = requestAnimationFrame(step)
912
+ }
913
+ function stopAutoScroll() {
914
+ cancelAnimationFrame(autoRaf)
915
+ autoRaf = 0
916
+ }
917
+
918
+ // A finger's drag mustn't scroll the chart (its touchmoves are cancelled once the drag is on)
919
+ function onTouchMove(e: TouchEvent) {
920
+ if (axis.pinchMove(e)) return
921
+ if (gesture && 'active' in gesture && gesture.active && e.cancelable) e.preventDefault()
922
+ }
923
+ function onScroll() {
924
+ axis.readView()
925
+ hovered.value = null
926
+ }
927
+
928
+ // ── Tooltip ───────────────────────────────────────────────────────────────────────────────────────────────
929
+ const hovered = ref<{ id: string; x: number; y: number } | null>(null)
930
+ let hoverTimer: ReturnType<typeof setTimeout> | undefined
931
+ function onBarEnter(e: PointerEvent, t: GanttTask) {
932
+ if (e.pointerType === 'touch') return
933
+ clearTimeout(hoverTimer)
934
+ const el = e.currentTarget as HTMLElement
935
+ hoverTimer = setTimeout(() => {
936
+ const r = el.getBoundingClientRect()
937
+ hovered.value = { id: t.id, x: r.left + r.width / 2, y: r.top }
938
+ }, 450)
939
+ }
940
+ function onBarLeave() {
941
+ clearTimeout(hoverTimer)
942
+ hovered.value = null
943
+ }
944
+ const tooltipTask = computed(() => {
945
+ const id = dragging.value?.taskId ?? hovered.value?.id
946
+ return id ? byId.value.get(id) : undefined
947
+ })
948
+ const tooltipPos = ref({ x: 0, y: 0 })
949
+ watch(tooltipTask, () => {
950
+ if (dragging.value) {
951
+ const el = barEls.get(dragging.value.taskId)
952
+ const r = el?.getBoundingClientRect()
953
+ if (r) tooltipPos.value = { x: r.left + r.width / 2, y: r.top }
954
+ } else if (hovered.value) tooltipPos.value = { x: hovered.value.x, y: hovered.value.y }
955
+ }, { flush: 'post' })
956
+ watch(preview, () => {
957
+ if (!dragging.value) return
958
+ nextTick(() => {
959
+ const r = barEls.get(dragging.value?.taskId ?? '')?.getBoundingClientRect()
960
+ if (r) tooltipPos.value = { x: Math.min(Math.max(r.left + r.width / 2, 120), window.innerWidth - 120), y: r.top }
961
+ })
962
+ })
963
+
964
+ // ── Text ──────────────────────────────────────────────────────────────────────────────────────────────────
965
+ function formatShort(s: string) {
966
+ const ms = parseDate(s)
967
+ if (Number.isNaN(ms)) return ''
968
+ const o: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'short' }
969
+ if (new Date(ms).getFullYear() !== new Date().getFullYear()) o.year = '2-digit'
970
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(s)) { o.hour = 'numeric'; o.minute = '2-digit' }
971
+ return new Intl.DateTimeFormat(lang.value, o).format(ms)
972
+ }
973
+ function durationText(t: GanttTask) {
974
+ if (isMilestone(t)) return locale.ganttMilestone
975
+ const days = taskDays(t)
976
+ if (taskSpan(t).dateOnly || days >= 1) return locale.ganttDays.replace('{n}', String(Math.round(days * 10) / 10))
977
+ return locale.ganttHours.replace('{n}', String(Math.round(days * 24 * 10) / 10))
978
+ }
979
+ const columnWidths = computed(() => {
980
+ const fixed = columnList.value.reduce((s, c) => s + (c.key === 'name' && !c.width ? 0 : (c.width ?? 100)), 0)
981
+ return columnList.value.map((c) => (c.key === 'name' && !c.width ? Math.max(120, gridW.value - fixed) : (c.width ?? 100)))
982
+ })
983
+ function cellText(t: GanttTask, c: GanttColumn): string {
984
+ if (c.format) return c.format(t)
985
+ switch (c.key) {
986
+ case 'name': return t.name
987
+ case 'start': return formatShort(t.start)
988
+ case 'end': return isMilestone(t) ? '' : formatShort(t.end ?? t.start)
989
+ case 'duration': return durationText(t)
990
+ case 'progress': return isMilestone(t) ? '' : `${Math.round(t.progress ?? 0)}%`
991
+ }
992
+ const v = (t.data as Record<string, unknown> | undefined)?.[c.key] ?? (t as unknown as Record<string, unknown>)[c.key]
993
+ return v === undefined || v === null ? '' : String(v)
994
+ }
995
+ function baselineGeo(t: GanttTask): Geo | null {
996
+ if (!props.baselines || !t.baselineStart) return null
997
+ const s = taskSpan({ start: t.baselineStart, end: t.baselineEnd ?? (t.end ? t.baselineStart : undefined), type: t.type })
998
+ if (!Number.isFinite(s.start)) return null
999
+ return { x: xOf(s.start), w: Math.max(4, xOf(s.end) - xOf(s.start)) }
1000
+ }
1001
+ const showLabelInside = (t: GanttTask) => {
1002
+ const g = geometry.value.get(t.id)
1003
+ return !!g && g.w > t.name.length * 7 + 24
1004
+ }
1005
+
1006
+ const TONES = {
1007
+ primary: { bar: 'bg-primary-container text-on-primary-container', fill: 'bg-primary/30', solid: 'bg-primary text-primary' },
1008
+ secondary: { bar: 'bg-secondary-container text-on-secondary-container', fill: 'bg-secondary/30', solid: 'bg-secondary text-secondary' },
1009
+ tertiary: { bar: 'bg-tertiary-container text-on-tertiary-container', fill: 'bg-tertiary/30', solid: 'bg-tertiary text-tertiary' },
1010
+ error: { bar: 'bg-error-container text-on-error-container', fill: 'bg-error/30', solid: 'bg-error text-error' },
1011
+ success: { bar: 'bg-success-container text-on-success-container', fill: 'bg-success/30', solid: 'bg-success text-success' },
1012
+ neutral: { bar: 'bg-surface-container-highest text-on-surface', fill: 'bg-on-surface/16', solid: 'bg-on-surface-variant text-on-surface-variant' },
1013
+ }
1014
+ function toneOf(t: GanttTask) {
1015
+ if (criticalSet.value.has(t.id) && !(sums.value.has(t.id) && childrenOf.value.has(t.id))) return TONES.error
1016
+ return TONES[t.color ?? (sums.value.has(t.id) ? 'neutral' : 'primary')] ?? TONES.primary
1017
+ }
1018
+
1019
+ // ── Keyboard and announcements ────────────────────────────────────────────────────────────────────────────
1020
+ const focusedId = ref<string | null>(null)
1021
+ const tabStop = computed(() => (focusedId.value && rowIndex.value.has(focusedId.value) ? focusedId.value : rows.value[0]?.task.id))
1022
+ const message = ref('')
1023
+ function announce(text: string) {
1024
+ message.value = ''
1025
+ nextTick(() => { message.value = text })
1026
+ }
1027
+ const editing = ref<string | null>(null)
1028
+ const editValue = ref('')
1029
+ function startRename(id: string) {
1030
+ const t = byId.value.get(id)
1031
+ if (!t || props.readonly) return
1032
+ editing.value = id
1033
+ editValue.value = t.name
1034
+ nextTick(() => {
1035
+ const input = scroller.value?.querySelector<HTMLInputElement>('[data-gantt-rename]')
1036
+ input?.focus()
1037
+ input?.select()
1038
+ })
1039
+ }
1040
+ function finishRename(save: boolean) {
1041
+ const id = editing.value
1042
+ if (!id) return
1043
+ editing.value = null
1044
+ const t = current.value.find((x) => x.id === id)
1045
+ if (save && t && editValue.value.trim() && editValue.value !== t.name) {
1046
+ const renamed = { ...t, name: editValue.value.trim() }
1047
+ commit(current.value.map((x) => (x.id === id ? renamed : x)))
1048
+ emit('change', { tasks: [renamed], kind: 'rename' })
1049
+ }
1050
+ focusRow(id)
1051
+ }
1052
+ function focusRow(id: string) {
1053
+ focusedId.value = id
1054
+ nextTick(() => scroller.value?.querySelector<HTMLElement>(`[data-gantt-row="${CSS.escape(id)}"]`)?.focus({ preventScroll: true }))
1055
+ }
1056
+ function shiftTask(t: GanttTask, steps: number, endOnly: boolean) {
1057
+ const s = taskSpan(t)
1058
+ const step = snapStep(t)
1059
+ const by = (ms: number) => (s.dateOnly ? addDays(ms, steps) : ms + steps * step * 60_000)
1060
+ const ns = endOnly ? s.start : by(s.start)
1061
+ let ne = by(s.end)
1062
+ if (endOnly && ne <= s.start) ne = s.dateOnly ? addDays(s.start, 1) : s.start + step * 60_000
1063
+ const moving = endOnly ? [t.id] : [t.id, ...descendants(t.id)]
1064
+ const patched = current.value.map((x) => {
1065
+ if (!moving.includes(x.id) || (sums.value.has(x.id) && childrenOf.value.has(x.id))) return x
1066
+ if (x.id === t.id) return { ...x, ...spanDates(x, ns, ne) }
1067
+ const xs = taskSpan(x)
1068
+ return { ...x, ...spanDates(x, xs.dateOnly ? addDays(xs.start, steps) : xs.start + steps * step * 60_000, xs.dateOnly ? addDays(xs.end, steps) : xs.end + steps * step * 60_000) }
1069
+ })
1070
+ const next = props.schedule === 'auto' ? scheduleTasks(patched, scheduleOptions()) : patched
1071
+ commit(next)
1072
+ const moved = rollupSummaries(next).find((x) => x.id === t.id)!
1073
+ emit('change', { tasks: [moved], kind: endOnly ? 'resize' : 'move' })
1074
+ announce(locale.ganttMoved.replace('{name}', moved.name).replace('{start}', formatShort(moved.start)).replace('{end}', formatShort(moved.end ?? moved.start)))
1075
+ }
1076
+ function onRowKey(e: KeyboardEvent, t: GanttTask) {
1077
+ if (editing.value) return
1078
+ const i = rowIndex.value.get(t.id) ?? 0
1079
+ const mod = e.ctrlKey || e.metaKey
1080
+ const go = (j: number) => {
1081
+ const r = rows.value[Math.max(0, Math.min(rows.value.length - 1, j))]
1082
+ if (!r) return
1083
+ focusRow(r.task.id)
1084
+ if (!e.shiftKey) setSelection([r.task.id])
1085
+ else setSelection([...new Set([...selected.value, r.task.id])])
1086
+ scrollToTask(r.task.id)
1087
+ }
1088
+ const editable = !props.readonly
1089
+ if (e.altKey && editable && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) {
1090
+ e.preventDefault()
1091
+ if (t.draggable !== false) shiftTask(t, e.key === 'ArrowLeft' ? -1 : 1, e.shiftKey)
1092
+ return
1093
+ }
1094
+ if (e.altKey && editable && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
1095
+ e.preventDefault()
1096
+ const sibs = childrenOf.value.get(t.parentId && byId.value.has(t.parentId) ? t.parentId : undefined) ?? []
1097
+ const k = sibs.findIndex((s) => s.id === t.id)
1098
+ const other = sibs[k + (e.key === 'ArrowUp' ? -1 : 1)]
1099
+ if (other) moveRow(t.id, other.id, e.key === 'ArrowUp' ? 'before' : 'after')
1100
+ focusRow(t.id)
1101
+ return
1102
+ }
1103
+ if (mod && editable && (e.key === ']' || e.key === '[')) {
1104
+ e.preventDefault()
1105
+ if (e.key === ']') {
1106
+ // Into the sibling above, at its end
1107
+ const sibs = childrenOf.value.get(t.parentId && byId.value.has(t.parentId) ? t.parentId : undefined) ?? []
1108
+ const above = sibs[sibs.findIndex((s) => s.id === t.id) - 1]
1109
+ if (above) {
1110
+ const last = (childrenOf.value.get(above.id) ?? []).at(-1)
1111
+ if (last) moveRow(t.id, last.id, 'after')
1112
+ else moveRow(t.id, above.id, 'inside')
1113
+ }
1114
+ } else if (t.parentId && byId.value.has(t.parentId)) moveRow(t.id, t.parentId, 'after')
1115
+ focusRow(t.id)
1116
+ return
1117
+ }
1118
+ if (mod && e.key.toLowerCase() === 'z') { e.preventDefault(); e.shiftKey ? redo() : undo(); return }
1119
+ if (mod && e.key.toLowerCase() === 'y') { e.preventDefault(); redo(); return }
1120
+ if (mod && e.key.toLowerCase() === 'a') { e.preventDefault(); setSelection(rows.value.map((r) => r.task.id)); return }
1121
+ switch (e.key) {
1122
+ case 'ArrowDown': e.preventDefault(); go(i + 1); break
1123
+ case 'ArrowUp': e.preventDefault(); go(i - 1); break
1124
+ case 'Home': e.preventDefault(); go(0); break
1125
+ case 'End': e.preventDefault(); go(rows.value.length - 1); break
1126
+ case 'ArrowRight':
1127
+ e.preventDefault()
1128
+ if (childrenOf.value.has(t.id) && foldedSet.value.has(t.id)) toggle(t.id, true)
1129
+ else if (childrenOf.value.has(t.id)) go(i + 1)
1130
+ break
1131
+ case 'ArrowLeft':
1132
+ e.preventDefault()
1133
+ if (childrenOf.value.has(t.id) && !foldedSet.value.has(t.id)) toggle(t.id, false)
1134
+ else if (t.parentId && rowIndex.value.has(t.parentId)) go(rowIndex.value.get(t.parentId)!)
1135
+ break
1136
+ case ' ':
1137
+ e.preventDefault()
1138
+ setSelection(selectedSet.value.has(t.id) ? selected.value.filter((x) => x !== t.id) : [...selected.value, t.id])
1139
+ break
1140
+ case 'Enter': e.preventDefault(); emit('task-dblclick', t, e); break
1141
+ case 'F2': e.preventDefault(); startRename(t.id); break
1142
+ case 'Delete':
1143
+ case 'Backspace':
1144
+ if (!editable) break
1145
+ e.preventDefault()
1146
+ removeTasks(selectedSet.value.has(t.id) ? selected.value : [t.id])
1147
+ break
1148
+ }
1149
+ }
1150
+ function onRootKey(e: KeyboardEvent) {
1151
+ if (e.key !== 'Delete' && e.key !== 'Backspace') return
1152
+ if (selectedLink.value && !props.readonly) {
1153
+ e.preventDefault()
1154
+ const [from, to] = selectedLink.value.split('>')
1155
+ unlink(from!, to!)
1156
+ }
1157
+ }
1158
+
1159
+ // ── Rows reorder: FLIP ────────────────────────────────────────────────────────────────────────────────────
1160
+ let rowTops = new Map<string, number>()
1161
+ onBeforeUpdate(() => {
1162
+ if (gesture && 'active' in gesture && gesture.active) return
1163
+ rowTops = new Map(rows.value.map((r, i) => [r.task.id, i * props.rowHeight]))
1164
+ })
1165
+ onUpdated(() => {
1166
+ if (!rowTops.size || prefersReducedMotion()) return
1167
+ const now = rowIndex.value
1168
+ for (const el of scroller.value?.querySelectorAll<HTMLElement>('[data-gantt-flip]') ?? []) {
1169
+ const id = el.dataset.ganttFlip!
1170
+ const before = rowTops.get(id)
1171
+ const i = now.get(id)
1172
+ if (before === undefined || i === undefined) continue
1173
+ const dy = before - i * props.rowHeight
1174
+ if (Math.abs(dy) < 1 || Math.abs(dy) > props.rowHeight * 40) continue
1175
+ const samples = sampleSpring(dy, 0, 0, { dampingRatio: 0.9, stiffness: 700 }, 0.5)
1176
+ playSamples(el, samples, (v) => ({ translate: `0 ${v}px` }))
1177
+ }
1178
+ rowTops.clear()
1179
+ })
1180
+
1181
+ // ── Context ───────────────────────────────────────────────────────────────────────────────────────────────
1182
+ const context: GanttContext = {
1183
+ tasks: computed(() => shown.value),
1184
+ selection: computed(() => selected.value),
1185
+ scale: scaleNow,
1186
+ pxPerDay: ppd,
1187
+ readonly: computed(() => props.readonly),
1188
+ canUndo,
1189
+ canRedo,
1190
+ collapsed: computed(() => folded.value),
1191
+ undo,
1192
+ redo,
1193
+ zoomIn,
1194
+ zoomOut,
1195
+ setScale,
1196
+ scrollToDate,
1197
+ scrollToTask,
1198
+ toggle,
1199
+ expandAll: () => setFolded([]),
1200
+ collapseAll: () => setFolded([...childrenOf.value.keys()].filter((k): k is string => !!k)),
1201
+ setSelection,
1202
+ addTasks,
1203
+ updateTask,
1204
+ removeTasks,
1205
+ link,
1206
+ unlink,
1207
+ schedule: runSchedule,
1208
+ criticalPath: criticalPathInfo,
1209
+ dateAt,
1210
+ }
1211
+ provide(GANTT_KEY, context)
1212
+ provide(TIMELINE_CONTROLS_KEY, {
1213
+ ...context,
1214
+ foldable: computed(() => childrenOf.value.size > 1),
1215
+ folded: computed(() => folded.value.length > 0),
1216
+ })
1217
+
1218
+ onMounted(() => {
1219
+ const el = scroller.value!
1220
+ el.addEventListener('touchmove', onTouchMove, { passive: false })
1221
+ // Start at today when it's on the chart, else at the first task
1222
+ nextTick(() => {
1223
+ const now = todayMs.value
1224
+ const at = now !== null && now >= extent.value.min && now <= extent.value.max ? now : extent.value.min
1225
+ el.scrollLeft = Math.max(0, xOf(at) - Math.min(80, timelineView.value / 4))
1226
+ view.value.left = el.scrollLeft
1227
+ })
1228
+ })
1229
+ onBeforeUnmount(() => {
1230
+ scroller.value?.removeEventListener('touchmove', onTouchMove)
1231
+ removeWindow()
1232
+ stopAutoScroll()
1233
+ cancelAnimationFrame(springRaf)
1234
+ clearTimeout(hoverTimer)
1235
+ })
1236
+
1237
+ defineExpose(context)
1238
+ </script>
1239
+
1240
+ <template>
1241
+ <div class="m3-gantt flex flex-col overflow-hidden rounded-md bg-surface text-on-surface" @keydown="onRootKey">
1242
+ <slot :gantt="context" />
1243
+ <div
1244
+ ref="scroller"
1245
+ class="relative min-h-0 flex-1 touch-pan-x touch-pan-y overflow-auto overscroll-contain"
1246
+ @scroll.passive="onScroll"
1247
+ @touchstart.passive="axis.onTouchStart"
1248
+ @touchend.passive="axis.onTouchEnd"
1249
+ @contextmenu="gesture && $event.preventDefault()"
1250
+ >
1251
+ <div class="relative" :style="{ width: `${listWidth + timelineWidth}px`, height: `${headerHeight + bodyHeight}px` }">
1252
+ <!-- Header -->
1253
+ <div class="sticky top-0 z-20 flex" :style="{ height: `${headerHeight}px`, width: `${listWidth + timelineWidth}px` }">
1254
+ <div
1255
+ v-if="showGrid"
1256
+ class="sticky left-0 z-10 flex shrink-0 items-end border-r border-b border-outline-variant bg-surface-container-low text-label-medium text-on-surface-variant"
1257
+ :style="{ width: `${listWidth}px` }"
1258
+ role="row"
1259
+ >
1260
+ <div
1261
+ v-for="(c, ci) in columnList"
1262
+ :key="c.key"
1263
+ role="columnheader"
1264
+ class="truncate px-3 pb-2"
1265
+ :class="c.align === 'end' ? 'text-right' : c.align === 'center' ? 'text-center' : ''"
1266
+ :style="{ width: `${columnWidths[ci]}px` }"
1267
+ >
1268
+ {{ c.label ?? c.key }}
1269
+ </div>
1270
+ </div>
1271
+ <MTimeHeader :width="timelineWidth" :top-cells="topCells" :bottom-cells="bottomCells" :today-x="todayMs === null ? null : xOf(todayMs)" />
1272
+ </div>
1273
+
1274
+ <!-- Body -->
1275
+ <div class="flex" :style="{ height: `${bodyHeight}px` }">
1276
+ <!-- Task list -->
1277
+ <div
1278
+ v-if="showGrid"
1279
+ class="sticky left-0 z-10 shrink-0 border-r border-outline-variant bg-surface"
1280
+ :style="{ width: `${listWidth}px` }"
1281
+ role="treegrid"
1282
+ :aria-label="label ?? locale.ganttChart"
1283
+ :aria-rowcount="rows.length"
1284
+ aria-multiselectable="true"
1285
+ >
1286
+ <div
1287
+ v-for="r in visibleRows"
1288
+ :key="r.task.id"
1289
+ :data-gantt-row="r.task.id"
1290
+ :data-gantt-flip="r.task.id"
1291
+ role="row"
1292
+ :aria-level="r.depth + 1"
1293
+ :aria-rowindex="r.index + 1"
1294
+ :aria-expanded="r.parent ? !foldedSet.has(r.task.id) : undefined"
1295
+ :aria-selected="selectedSet.has(r.task.id)"
1296
+ :tabindex="tabStop === r.task.id ? 0 : -1"
1297
+ class="m3-gantt-row absolute inset-x-0 flex items-center text-body-medium outline-none select-none focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-secondary focus-visible:ring-inset"
1298
+ :class="[
1299
+ selectedSet.has(r.task.id) ? 'bg-secondary-container text-on-secondary-container' : 'hover:bg-on-surface/8',
1300
+ dragging?.taskId === r.task.id && !dragging?.part.startsWith('link') && rowDrop ? 'opacity-50' : '',
1301
+ ]"
1302
+ :style="{ top: `${r.index * rowHeight}px`, height: `${rowHeight}px` }"
1303
+ @pointerdown="onRowDown($event, r.task)"
1304
+ @click="selectFromClick(r.task, $event)"
1305
+ @dblclick="emit('task-dblclick', r.task, $event)"
1306
+ @contextmenu="emit('task-contextmenu', r.task, $event)"
1307
+ @keydown="onRowKey($event, r.task)"
1308
+ @focus="focusedId = r.task.id"
1309
+ >
1310
+ <div
1311
+ v-for="(c, ci) in columnList"
1312
+ :key="c.key"
1313
+ role="gridcell"
1314
+ class="flex h-full min-w-0 items-center px-3"
1315
+ :class="[c.align === 'end' ? 'justify-end' : c.align === 'center' ? 'justify-center' : '', c.key === 'name' ? 'gap-1' : 'text-on-surface-variant']"
1316
+ :style="{ width: `${columnWidths[ci]}px`, paddingLeft: c.key === 'name' ? `${8 + r.depth * 20}px` : undefined }"
1317
+ >
1318
+ <template v-if="c.key === 'name'">
1319
+ <button
1320
+ v-if="r.parent"
1321
+ type="button"
1322
+ tabindex="-1"
1323
+ data-gantt-action
1324
+ class="flex size-6 shrink-0 items-center justify-center rounded-full text-on-surface-variant hover:bg-on-surface/8"
1325
+ :aria-label="foldedSet.has(r.task.id) ? locale.ganttExpand : locale.ganttCollapse"
1326
+ @click.stop="toggle(r.task.id)"
1327
+ >
1328
+ <span class="material-symbols-outlined text-[20px] transition-transform duration-200" :class="foldedSet.has(r.task.id) ? '-rotate-90' : ''">expand_more</span>
1329
+ </button>
1330
+ <span v-else class="w-6 shrink-0" />
1331
+ <span v-if="isMilestone(r.task)" class="mr-1 size-2 shrink-0 rotate-45 rounded-[1px] bg-tertiary" />
1332
+ <input
1333
+ v-if="editing === r.task.id"
1334
+ v-model="editValue"
1335
+ data-gantt-rename
1336
+ class="h-8 min-w-0 flex-1 rounded-xs border border-primary bg-surface px-2 text-body-medium text-on-surface outline-none"
1337
+ @keydown.stop.enter.prevent="finishRename(true)"
1338
+ @keydown.stop.esc.prevent="finishRename(false)"
1339
+ @blur="finishRename(true)"
1340
+ @click.stop
1341
+ @dblclick.stop
1342
+ >
1343
+ <slot v-else :name="`cell-${c.key}`" :task="r.task" :value="cellText(r.task, c)">
1344
+ <span class="truncate" :class="r.parent ? 'font-medium' : ''" @dblclick.stop="readonly ? emit('task-dblclick', r.task, $event) : startRename(r.task.id)">{{ cellText(r.task, c) }}</span>
1345
+ </slot>
1346
+ </template>
1347
+ <slot v-else :name="`cell-${c.key}`" :task="r.task" :value="cellText(r.task, c)">
1348
+ <span class="truncate">{{ cellText(r.task, c) }}</span>
1349
+ </slot>
1350
+ </div>
1351
+ </div>
1352
+ <!-- Where a dragged row would land -->
1353
+ <div
1354
+ v-if="rowDrop"
1355
+ class="pointer-events-none absolute right-2 z-20"
1356
+ :class="rowDrop.where === 'inside' ? 'rounded-sm border-2 border-primary' : 'h-0.5 rounded-full bg-primary'"
1357
+ :style="rowDrop.where === 'inside'
1358
+ ? { top: `${(rowIndex.get(rowDrop.target) ?? 0) * rowHeight + 2}px`, height: `${rowHeight - 4}px`, left: '8px' }
1359
+ : { top: `${((rowIndex.get(rowDrop.target) ?? 0) + (rowDrop.where === 'after' ? 1 : 0)) * rowHeight - 1}px`, left: `${8 + ((rows[rowIndex.get(rowDrop.target) ?? 0]?.depth ?? 0)) * 20}px` }"
1360
+ />
1361
+ <div
1362
+ role="separator"
1363
+ aria-orientation="vertical"
1364
+ :aria-label="locale.ganttResize"
1365
+ :aria-valuenow="listWidth"
1366
+ tabindex="0"
1367
+ class="absolute inset-y-0 -right-1 z-30 w-2 cursor-col-resize touch-none outline-none hover:bg-primary/20 focus-visible:bg-primary/30"
1368
+ @pointerdown="onSplitDown"
1369
+ @keydown.left.prevent="gridW = Math.max(120, gridW - 16); emit('update:gridWidth', gridW)"
1370
+ @keydown.right.prevent="gridW = gridW + 16; emit('update:gridWidth', gridW)"
1371
+ />
1372
+ </div>
1373
+
1374
+ <!-- Timeline -->
1375
+ <div class="relative shrink-0" :style="{ width: `${timelineWidth}px` }" aria-hidden="true" @pointerdown="onPaneDown">
1376
+ <MTimeBackground :off-times="offTimes" :cells="bottomCells" :today-x="todayMs === null ? null : xOf(todayMs)" />
1377
+ <div
1378
+ v-for="r in visibleRows"
1379
+ :key="`r${r.task.id}`"
1380
+ class="absolute inset-x-0"
1381
+ :class="selectedSet.has(r.task.id) ? 'bg-secondary-container/40' : ''"
1382
+ :style="{ top: `${r.index * rowHeight}px`, height: `${rowHeight}px` }"
1383
+ />
1384
+
1385
+ <!-- Dependencies -->
1386
+ <svg class="pointer-events-none absolute inset-0 overflow-visible" :width="timelineWidth" :height="bodyHeight">
1387
+ <g
1388
+ v-for="l in visibleLinks"
1389
+ :key="l.key"
1390
+ :ref="(el) => bindLink(l.key, el)"
1391
+ class="m3-gantt-link"
1392
+ :class="criticalLinks.has(l.key) ? 'text-error' : selectedLink === l.key ? 'text-primary' : 'text-outline'"
1393
+ >
1394
+ <!-- What a click or a tap selects it by: wider than the line, much wider for a finger -->
1395
+ <path
1396
+ fill="none"
1397
+ stroke="transparent"
1398
+ class="pointer-events-auto cursor-pointer [stroke-width:12px] pointer-coarse:[stroke-width:28px]"
1399
+ @pointerdown.stop
1400
+ @click.stop="selectedLink = l.key; setSelection([])"
1401
+ />
1402
+ <path fill="none" stroke="currentColor" :stroke-width="selectedLink === l.key || criticalLinks.has(l.key) ? 2.5 : 1.5" stroke-linejoin="round" />
1403
+ <path fill="currentColor" stroke="currentColor" stroke-width="1" stroke-linejoin="round" />
1404
+ </g>
1405
+ <path
1406
+ v-if="linkDraft"
1407
+ fill="none"
1408
+ stroke-width="2"
1409
+ stroke-dasharray="6 4"
1410
+ :class="linkDraft.valid ? 'stroke-primary' : 'stroke-outline'"
1411
+ :d="`M${linkDraft.fromEnd ? (liveGeo(linkDraft.from)!.x + liveGeo(linkDraft.from)!.w) : liveGeo(linkDraft.from)!.x},${(rowIndex.get(linkDraft.from) ?? 0) * rowHeight + rowHeight / 2} L${linkDraft.x},${linkDraft.y}`"
1412
+ />
1413
+ </svg>
1414
+ <button
1415
+ v-if="selectedLink && selectedLinkMid && !readonly"
1416
+ type="button"
1417
+ data-gantt-action
1418
+ class="absolute z-10 flex size-6 -translate-1/2 items-center justify-center rounded-full bg-error text-on-error shadow-elevation-2 pointer-coarse:size-10"
1419
+ :style="{ left: `${selectedLinkMid.x}px`, top: `${selectedLinkMid.y}px` }"
1420
+ :aria-label="locale.ganttUnlink"
1421
+ @pointerdown.stop
1422
+ @click.stop="unlink(selectedLink.split('>')[0]!, selectedLink.split('>')[1]!)"
1423
+ >
1424
+ <span class="material-symbols-outlined text-[16px]">close</span>
1425
+ </button>
1426
+
1427
+ <!-- Bars -->
1428
+ <template v-for="r in visibleRows" :key="`g${r.task.id}`">
1429
+ <div
1430
+ v-if="baselineGeo(r.task)"
1431
+ class="pointer-events-none absolute h-1 rounded-full bg-outline"
1432
+ :style="{ top: `${r.index * rowHeight + rowHeight / 2 + barH / 2 + 2}px`, left: `${baselineGeo(r.task)!.x}px`, width: `${baselineGeo(r.task)!.w}px` }"
1433
+ />
1434
+ </template>
1435
+ <div
1436
+ v-for="r in visibleRows"
1437
+ :key="`b${r.task.id}`"
1438
+ :ref="(el) => bindBar(r.task.id, el)"
1439
+ :data-gantt-flip="r.task.id"
1440
+ class="m3-gantt-bar group absolute left-0"
1441
+ :class="[r.task.class, dragging?.taskId === r.task.id ? 'z-10' : '']"
1442
+ :style="{ top: `${r.index * rowHeight + (rowHeight - barH) / 2}px`, height: `${barH}px` }"
1443
+ >
1444
+ <!-- Milestone: a finger gets a wider target than the diamond -->
1445
+ <div
1446
+ v-if="isMilestone(r.task)"
1447
+ class="absolute top-1/2 left-0 hidden size-11 -translate-1/2 pointer-coarse:block"
1448
+ @pointerdown="onBarDown($event, r.task, 'body')"
1449
+ />
1450
+ <div
1451
+ v-if="isMilestone(r.task)"
1452
+ :data-gantt-task="r.task.id"
1453
+ class="absolute top-1/2 left-0 -translate-1/2 rotate-45 rounded-[3px] shadow-elevation-1"
1454
+ :class="[criticalSet.has(r.task.id) ? 'bg-error' : TONES[r.task.color ?? 'tertiary'].solid, selectedSet.has(r.task.id) ? 'ring-2 ring-on-surface ring-offset-2 ring-offset-surface' : '', readonly ? '' : 'cursor-grab']"
1455
+ :style="{ width: `${barH * 0.8}px`, height: `${barH * 0.8}px` }"
1456
+ @pointerdown="onBarDown($event, r.task, 'body')"
1457
+ @pointerenter="onBarEnter($event, r.task)"
1458
+ @pointerleave="onBarLeave"
1459
+ @dblclick="emit('task-dblclick', r.task, $event)"
1460
+ @contextmenu="emit('task-contextmenu', r.task, $event)"
1461
+ />
1462
+ <!-- Summary: a bracket over its tasks -->
1463
+ <div
1464
+ v-else-if="sums.has(r.task.id) && childrenOf.has(r.task.id)"
1465
+ :data-gantt-task="r.task.id"
1466
+ class="m3-gantt-summary absolute inset-x-0 top-1/2 h-2.5 -translate-y-1/2 rounded-t-xs"
1467
+ :class="[toneOf(r.task).solid, selectedSet.has(r.task.id) ? 'ring-2 ring-on-surface ring-offset-1 ring-offset-surface' : '', readonly ? '' : 'cursor-grab']"
1468
+ @pointerdown="onBarDown($event, r.task, 'body')"
1469
+ @pointerenter="onBarEnter($event, r.task)"
1470
+ @pointerleave="onBarLeave"
1471
+ @dblclick="emit('task-dblclick', r.task, $event)"
1472
+ @contextmenu="emit('task-contextmenu', r.task, $event)"
1473
+ />
1474
+ <!-- Task -->
1475
+ <div
1476
+ v-else
1477
+ :data-gantt-task="r.task.id"
1478
+ class="absolute inset-0 overflow-hidden rounded-sm transition-shadow duration-200"
1479
+ :class="[
1480
+ toneOf(r.task).bar,
1481
+ selectedSet.has(r.task.id) ? 'ring-2 ring-on-surface ring-offset-1 ring-offset-surface' : '',
1482
+ dragging?.taskId === r.task.id ? 'shadow-elevation-3' : 'hover:shadow-elevation-1',
1483
+ readonly || r.task.draggable === false ? '' : 'cursor-grab active:cursor-grabbing',
1484
+ ]"
1485
+ @pointerdown="onBarDown($event, r.task, 'body')"
1486
+ @pointerenter="onBarEnter($event, r.task)"
1487
+ @pointerleave="onBarLeave"
1488
+ @dblclick="emit('task-dblclick', r.task, $event)"
1489
+ @contextmenu="emit('task-contextmenu', r.task, $event)"
1490
+ >
1491
+ <div class="pointer-events-none absolute inset-y-0 left-0" :class="toneOf(r.task).fill" :style="{ width: `${r.task.progress ?? 0}%` }" />
1492
+ <div class="pointer-events-none relative flex h-full items-center px-2 text-label-medium whitespace-nowrap">
1493
+ <slot name="bar" :task="r.task" :selected="selectedSet.has(r.task.id)" :critical="criticalSet.has(r.task.id)">
1494
+ <span v-if="showLabelInside(r.task)" class="truncate">{{ r.task.name }}</span>
1495
+ </slot>
1496
+ </div>
1497
+ </div>
1498
+ <!-- Resize handles, outside the bar's clipping: wider for a finger, with a grip while selected -->
1499
+ <template v-if="!readonly && r.task.resizable !== false && !isMilestone(r.task) && !(sums.has(r.task.id) && childrenOf.has(r.task.id))">
1500
+ <div
1501
+ v-for="side in (['start', 'end'] as const)"
1502
+ :key="`rs${side}`"
1503
+ :data-gantt-resize="side"
1504
+ class="absolute inset-y-0 z-[1] flex w-3 cursor-ew-resize items-center justify-center pointer-coarse:w-7"
1505
+ :class="side === 'start' ? '-left-1 pointer-coarse:-left-3.5' : '-right-1 pointer-coarse:-right-3.5'"
1506
+ @pointerdown="onBarDown($event, r.task, side)"
1507
+ >
1508
+ <span class="hidden h-3/5 w-1 rounded-full bg-on-surface pointer-coarse:block" :class="selectedSet.has(r.task.id) ? 'opacity-100' : 'opacity-0'" />
1509
+ </div>
1510
+ </template>
1511
+ <!-- Outside the bar: its label when it doesn't fit, the progress handle, the link dots -->
1512
+ <span
1513
+ v-if="!isMilestone(r.task) && !slots.bar && !(sums.has(r.task.id) && childrenOf.has(r.task.id)) && !showLabelInside(r.task)"
1514
+ class="pointer-events-none absolute top-1/2 left-full ml-2 -translate-y-1/2 text-label-medium whitespace-nowrap text-on-surface-variant"
1515
+ >{{ r.task.name }}</span>
1516
+ <span
1517
+ v-else-if="isMilestone(r.task) || (sums.has(r.task.id) && childrenOf.has(r.task.id))"
1518
+ class="pointer-events-none absolute top-1/2 left-full -translate-y-1/2 text-label-medium whitespace-nowrap"
1519
+ :class="[isMilestone(r.task) ? 'ml-4' : 'ml-2', sums.has(r.task.id) ? 'font-medium text-on-surface' : 'text-on-surface-variant']"
1520
+ >{{ r.task.name }}</span>
1521
+ <template v-if="!readonly && !(sums.has(r.task.id) && childrenOf.has(r.task.id))">
1522
+ <div
1523
+ v-if="!isMilestone(r.task)"
1524
+ class="absolute -bottom-2 size-0 -translate-x-1/2 cursor-ew-resize border-x-[6px] border-b-[7px] border-x-transparent border-b-on-surface-variant opacity-0 transition-opacity group-hover:opacity-100"
1525
+ :class="selectedSet.has(r.task.id) || dragging?.taskId === r.task.id ? 'opacity-100' : ''"
1526
+ :style="{ left: `${r.task.progress ?? 0}%` }"
1527
+ @pointerdown="onBarDown($event, r.task, 'progress')"
1528
+ />
1529
+ <template v-if="r.task.linkable !== false">
1530
+ <div
1531
+ v-for="side in (['start', 'end'] as const)"
1532
+ :key="side"
1533
+ class="absolute top-1/2 flex size-5 -translate-y-1/2 cursor-crosshair items-center justify-center transition-opacity pointer-coarse:size-8"
1534
+ :class="[
1535
+ // Clear of the diamond (and of its wider touch area) for a milestone
1536
+ side === 'start'
1537
+ ? (isMilestone(r.task) ? '-left-9 pointer-coarse:-left-14' : '-left-5 pointer-coarse:-left-9')
1538
+ : (isMilestone(r.task) ? 'left-4 pointer-coarse:left-6' : '-right-5 pointer-coarse:-right-9'),
1539
+ // Only there to grab while shown, or they'd take clicks meant for the arrows that end there
1540
+ selectedSet.has(r.task.id) || linkDraft ? 'opacity-100' : 'pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100',
1541
+ ]"
1542
+ @pointerdown="onBarDown($event, r.task, side === 'start' ? 'link-start' : 'link-end')"
1543
+ >
1544
+ <span class="size-2.5 rounded-full border-2 border-primary bg-surface" />
1545
+ </div>
1546
+ </template>
1547
+ </template>
1548
+ <!-- Where a dependency drawn now would arrive -->
1549
+ <div
1550
+ v-if="linkDraft?.target === r.task.id"
1551
+ class="pointer-events-none absolute -inset-1 rounded-md border-2"
1552
+ :class="linkDraft.valid ? 'border-primary' : 'border-error'"
1553
+ />
1554
+ </div>
1555
+
1556
+ <div v-if="!rows.length" class="absolute inset-0 flex items-center justify-center p-6" :style="{ left: `${view.left}px`, width: `${timelineView}px` }">
1557
+ <slot name="empty">
1558
+ <span class="text-body-medium text-on-surface-variant">{{ locale.ganttEmpty }}</span>
1559
+ </slot>
1560
+ </div>
1561
+ </div>
1562
+ </div>
1563
+ </div>
1564
+ </div>
1565
+
1566
+ <Teleport to="body">
1567
+ <div
1568
+ v-if="tooltipTask && !linkDraft && !rowDrop"
1569
+ class="pointer-events-none fixed z-[300] -translate-x-1/2 -translate-y-full rounded-md bg-surface-container px-3 py-2 text-on-surface shadow-elevation-2"
1570
+ :style="{ left: `${tooltipPos.x}px`, top: `${tooltipPos.y - 8}px` }"
1571
+ role="tooltip"
1572
+ >
1573
+ <slot name="tooltip" :task="tooltipTask" :slack="criticalPathInfo.slack[tooltipTask.id]">
1574
+ <div class="text-title-small">{{ tooltipTask.name }}</div>
1575
+ <div class="text-body-small text-on-surface-variant">
1576
+ {{ formatShort(tooltipTask.start) }}<template v-if="!isMilestone(tooltipTask)"> – {{ formatShort(tooltipTask.end ?? tooltipTask.start) }} · {{ durationText(tooltipTask) }}</template>
1577
+ <template v-if="!isMilestone(tooltipTask) && tooltipTask.progress !== undefined"> · {{ Math.round(tooltipTask.progress) }}%</template>
1578
+ </div>
1579
+ <div v-if="criticalPath && criticalPathInfo.slack[tooltipTask.id] !== undefined" class="text-body-small" :class="criticalSet.has(tooltipTask.id) ? 'text-error' : 'text-on-surface-variant'">
1580
+ {{ criticalSet.has(tooltipTask.id) ? locale.ganttCritical : locale.ganttSlack.replace('{n}', String(Math.round(criticalPathInfo.slack[tooltipTask.id]! * 10) / 10)) }}
1581
+ </div>
1582
+ </slot>
1583
+ </div>
1584
+ </Teleport>
1585
+ <div class="sr-only" aria-live="polite">{{ message }}</div>
1586
+ </div>
1587
+ </template>
1588
+
1589
+ <style>
1590
+ /* The summary bracket's ends point down at its first and last tasks */
1591
+ .m3-gantt-summary::before,
1592
+ .m3-gantt-summary::after {
1593
+ content: '';
1594
+ position: absolute;
1595
+ top: 100%;
1596
+ border-top: 6px solid currentColor;
1597
+ border-left: 5px solid transparent;
1598
+ border-right: 5px solid transparent;
1599
+ color: inherit;
1600
+ }
1601
+ .m3-gantt-summary::before {
1602
+ left: 0;
1603
+ border-left: 0;
1604
+ }
1605
+ .m3-gantt-summary::after {
1606
+ right: 0;
1607
+ border-right: 0;
1608
+ }
1609
+ </style>