@zonsh/ui 0.4.1 → 0.6.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 (562) hide show
  1. package/CHANGELOG.md +639 -0
  2. package/README.md +49 -21
  3. package/dist/brand.d.ts +3 -0
  4. package/dist/brand.js +7 -0
  5. package/dist/components/_breadcrumb-more.d.ts +6 -0
  6. package/dist/components/_breadcrumb-more.js +5 -0
  7. package/dist/components/_drawing-svg.d.ts +11 -0
  8. package/dist/components/_drawing-svg.js +30 -0
  9. package/dist/components/_media.d.ts +159 -0
  10. package/dist/components/_media.js +266 -0
  11. package/dist/components/_overlay.d.ts +8 -5
  12. package/dist/components/_overlay.js +11 -6
  13. package/dist/components/_scheduler-calendar.d.ts +71 -0
  14. package/dist/components/_scheduler-calendar.js +940 -0
  15. package/dist/components/_scheduler-editor.d.ts +29 -0
  16. package/dist/components/_scheduler-editor.js +111 -0
  17. package/dist/components/_scheduler-menu.d.ts +16 -0
  18. package/dist/components/_scheduler-menu.js +18 -0
  19. package/dist/components/_scheduler-parts.d.ts +164 -0
  20. package/dist/components/_scheduler-parts.js +327 -0
  21. package/dist/components/_suggest-list.d.ts +142 -0
  22. package/dist/components/_suggest-list.js +159 -0
  23. package/dist/components/_toolbar-more.d.ts +24 -0
  24. package/dist/components/_toolbar-more.js +25 -0
  25. package/dist/components/accordion.d.ts +1 -1
  26. package/dist/components/accordion.js +7 -7
  27. package/dist/components/action-sheet.d.ts +88 -0
  28. package/dist/components/action-sheet.js +124 -0
  29. package/dist/components/alert-dialog.js +3 -1
  30. package/dist/components/alert.d.ts +11 -18
  31. package/dist/components/alert.js +9 -6
  32. package/dist/components/app-bar.d.ts +93 -0
  33. package/dist/components/app-bar.js +175 -0
  34. package/dist/components/ascii-field.js +2 -1
  35. package/dist/components/audio-player.d.ts +134 -0
  36. package/dist/components/audio-player.js +618 -0
  37. package/dist/components/avatar.d.ts +6 -6
  38. package/dist/components/avatar.js +13 -11
  39. package/dist/components/badge.d.ts +12 -12
  40. package/dist/components/badge.js +7 -5
  41. package/dist/components/bottom-nav.d.ts +53 -11
  42. package/dist/components/bottom-nav.js +389 -24
  43. package/dist/components/breadcrumb.d.ts +11 -2
  44. package/dist/components/breadcrumb.js +60 -6
  45. package/dist/components/button-group.js +5 -1
  46. package/dist/components/button.d.ts +23 -6
  47. package/dist/components/button.js +64 -8
  48. package/dist/components/calendar.js +8 -6
  49. package/dist/components/card.d.ts +10 -8
  50. package/dist/components/card.js +15 -14
  51. package/dist/components/carousel.d.ts +2 -2
  52. package/dist/components/carousel.js +21 -8
  53. package/dist/components/chart.d.ts +38 -1
  54. package/dist/components/chart.js +27 -5
  55. package/dist/components/checkbox.js +2 -2
  56. package/dist/components/code-block.d.ts +9 -2
  57. package/dist/components/code-block.js +26 -7
  58. package/dist/components/collapsible.js +4 -4
  59. package/dist/components/color-picker.d.ts +2 -2
  60. package/dist/components/color-picker.js +5 -5
  61. package/dist/components/combobox.d.ts +26 -7
  62. package/dist/components/combobox.js +32 -13
  63. package/dist/components/command.d.ts +29 -5
  64. package/dist/components/command.js +37 -12
  65. package/dist/components/context-menu.d.ts +5 -2
  66. package/dist/components/context-menu.js +24 -3
  67. package/dist/components/conversation.d.ts +1 -1
  68. package/dist/components/conversation.js +77 -16
  69. package/dist/components/copy-button.d.ts +1 -1
  70. package/dist/components/copy-button.js +8 -6
  71. package/dist/components/data-table.d.ts +6 -6
  72. package/dist/components/data-table.js +41 -15
  73. package/dist/components/date-picker.d.ts +31 -9
  74. package/dist/components/date-picker.js +100 -18
  75. package/dist/components/dialog.d.ts +17 -10
  76. package/dist/components/dialog.js +20 -13
  77. package/dist/components/drawer.d.ts +26 -8
  78. package/dist/components/drawer.js +75 -16
  79. package/dist/components/drawing.d.ts +25 -0
  80. package/dist/components/drawing.js +32 -0
  81. package/dist/components/empty.js +2 -2
  82. package/dist/components/feature-list.d.ts +65 -13
  83. package/dist/components/feature-list.js +116 -15
  84. package/dist/components/field.js +2 -2
  85. package/dist/components/file-drop.d.ts +9 -7
  86. package/dist/components/file-drop.js +8 -43
  87. package/dist/components/filter-bar.d.ts +10 -9
  88. package/dist/components/filter-bar.js +42 -25
  89. package/dist/components/graph.d.ts +19 -3
  90. package/dist/components/graph.js +190 -28
  91. package/dist/components/illustration.js +53 -31
  92. package/dist/components/input-group.d.ts +6 -11
  93. package/dist/components/input-group.js +21 -19
  94. package/dist/components/input.d.ts +2 -2
  95. package/dist/components/input.js +3 -3
  96. package/dist/components/item.d.ts +9 -6
  97. package/dist/components/item.js +13 -8
  98. package/dist/components/kbd.d.ts +1 -1
  99. package/dist/components/kbd.js +1 -1
  100. package/dist/components/layout.d.ts +2 -1
  101. package/dist/components/layout.js +55 -11
  102. package/dist/components/lightbox.d.ts +76 -9
  103. package/dist/components/lightbox.js +354 -48
  104. package/dist/components/locale.d.ts +6 -6
  105. package/dist/components/logo.d.ts +21 -1
  106. package/dist/components/logo.js +32 -2
  107. package/dist/components/markdown-editor.d.ts +275 -0
  108. package/dist/components/markdown-editor.js +831 -0
  109. package/dist/components/mentions.d.ts +153 -0
  110. package/dist/components/mentions.js +507 -0
  111. package/dist/components/menu.d.ts +2 -1
  112. package/dist/components/menu.js +5 -4
  113. package/dist/components/menubar.d.ts +23 -5
  114. package/dist/components/menubar.js +153 -31
  115. package/dist/components/message.d.ts +62 -11
  116. package/dist/components/message.js +51 -14
  117. package/dist/components/meter.js +1 -1
  118. package/dist/components/money-input.d.ts +1 -1
  119. package/dist/components/money-input.js +1 -1
  120. package/dist/components/native-select.d.ts +2 -2
  121. package/dist/components/native-select.js +4 -4
  122. package/dist/components/navigation-menu.d.ts +3 -1
  123. package/dist/components/navigation-menu.js +23 -10
  124. package/dist/components/number-field.d.ts +2 -9
  125. package/dist/components/number-field.js +90 -26
  126. package/dist/components/number-roll.d.ts +26 -0
  127. package/dist/components/number-roll.js +81 -0
  128. package/dist/components/otp-field.d.ts +1 -1
  129. package/dist/components/otp-field.js +24 -3
  130. package/dist/components/pagination.d.ts +11 -3
  131. package/dist/components/pagination.js +59 -13
  132. package/dist/components/pdf-viewer.d.ts +1 -1
  133. package/dist/components/pdf-viewer.js +8 -8
  134. package/dist/components/phone-input.d.ts +1 -1
  135. package/dist/components/phone-input.js +2 -2
  136. package/dist/components/popover.js +5 -3
  137. package/dist/components/preview-card.d.ts +37 -2
  138. package/dist/components/preview-card.js +226 -2
  139. package/dist/components/progress.js +1 -1
  140. package/dist/components/prompt-input.d.ts +1 -1
  141. package/dist/components/prompt-input.js +35 -17
  142. package/dist/components/pull-to-refresh.d.ts +50 -0
  143. package/dist/components/pull-to-refresh.js +189 -0
  144. package/dist/components/quote.d.ts +6 -1
  145. package/dist/components/quote.js +3 -2
  146. package/dist/components/radio-group.js +8 -3
  147. package/dist/components/rating.d.ts +4 -1
  148. package/dist/components/rating.js +131 -10
  149. package/dist/components/reasoning.d.ts +1 -1
  150. package/dist/components/reasoning.js +7 -3
  151. package/dist/components/resizable.d.ts +1 -1
  152. package/dist/components/resizable.js +2 -2
  153. package/dist/components/response.d.ts +4 -3
  154. package/dist/components/response.js +39 -15
  155. package/dist/components/scheduler.d.ts +352 -0
  156. package/dist/components/scheduler.js +1717 -0
  157. package/dist/components/scroll-area.js +1 -1
  158. package/dist/components/select.d.ts +17 -4
  159. package/dist/components/select.js +140 -9
  160. package/dist/components/separator.d.ts +1 -1
  161. package/dist/components/separator.js +3 -3
  162. package/dist/components/sidebar.d.ts +44 -3
  163. package/dist/components/sidebar.js +90 -31
  164. package/dist/components/site-header.d.ts +18 -13
  165. package/dist/components/site-header.js +26 -9
  166. package/dist/components/skeleton.d.ts +18 -8
  167. package/dist/components/skeleton.js +23 -8
  168. package/dist/components/slider.js +2 -2
  169. package/dist/components/sortable.d.ts +55 -4
  170. package/dist/components/sortable.js +187 -94
  171. package/dist/components/sources.d.ts +1 -1
  172. package/dist/components/sources.js +2 -2
  173. package/dist/components/spinner.d.ts +4 -4
  174. package/dist/components/spinner.js +4 -4
  175. package/dist/components/stat.d.ts +21 -4
  176. package/dist/components/stat.js +17 -8
  177. package/dist/components/stepper.d.ts +1 -1
  178. package/dist/components/stepper.js +8 -7
  179. package/dist/components/suggestions.d.ts +11 -3
  180. package/dist/components/suggestions.js +10 -4
  181. package/dist/components/swipe-actions.d.ts +66 -0
  182. package/dist/components/swipe-actions.js +292 -0
  183. package/dist/components/switch.js +1 -1
  184. package/dist/components/table.d.ts +13 -7
  185. package/dist/components/table.js +124 -23
  186. package/dist/components/tabs.js +15 -8
  187. package/dist/components/tag.d.ts +19 -20
  188. package/dist/components/tag.js +9 -5
  189. package/dist/components/tags-input.d.ts +2 -7
  190. package/dist/components/tags-input.js +11 -8
  191. package/dist/components/textarea.d.ts +3 -2
  192. package/dist/components/textarea.js +4 -3
  193. package/dist/components/theme.d.ts +50 -7
  194. package/dist/components/theme.js +168 -12
  195. package/dist/components/time-field.d.ts +6 -10
  196. package/dist/components/time-field.js +19 -9
  197. package/dist/components/timeline.d.ts +19 -3
  198. package/dist/components/timeline.js +21 -9
  199. package/dist/components/tippy.d.ts +17 -1
  200. package/dist/components/tippy.js +95 -15
  201. package/dist/components/toast.d.ts +2 -7
  202. package/dist/components/toast.js +12 -8
  203. package/dist/components/toggle-group.d.ts +7 -1
  204. package/dist/components/toggle-group.js +17 -5
  205. package/dist/components/toggle.d.ts +2 -2
  206. package/dist/components/toggle.js +3 -2
  207. package/dist/components/tool-call.d.ts +1 -1
  208. package/dist/components/tool-call.js +8 -3
  209. package/dist/components/toolbar.d.ts +57 -4
  210. package/dist/components/toolbar.js +219 -16
  211. package/dist/components/tooltip.d.ts +5 -3
  212. package/dist/components/tooltip.js +14 -6
  213. package/dist/components/tour.d.ts +1 -1
  214. package/dist/components/tour.js +70 -24
  215. package/dist/components/tree.js +33 -10
  216. package/dist/components/typography.d.ts +31 -8
  217. package/dist/components/typography.js +21 -10
  218. package/dist/components/video-player.d.ts +7 -2
  219. package/dist/components/video-player.js +182 -225
  220. package/dist/index.d.ts +99 -92
  221. package/dist/index.js +99 -92
  222. package/dist/lib/calendar.d.ts +153 -0
  223. package/dist/lib/calendar.js +312 -0
  224. package/dist/lib/cn.d.ts +3 -1
  225. package/dist/lib/cn.js +5 -0
  226. package/dist/lib/code-highlight.d.ts +14 -0
  227. package/dist/lib/code-highlight.js +81 -18
  228. package/dist/lib/drag.d.ts +39 -0
  229. package/dist/lib/drag.js +96 -0
  230. package/dist/lib/editorial-assets.js +16 -8
  231. package/dist/lib/figure/figures/automation.js +25 -6
  232. package/dist/lib/figure/figures/bar-chart.js +6 -1
  233. package/dist/lib/figure/figures/brackets-classic.js +4 -1
  234. package/dist/lib/figure/figures/city.js +12 -2
  235. package/dist/lib/figure/figures/conveyor.js +17 -4
  236. package/dist/lib/figure/figures/database.js +5 -2
  237. package/dist/lib/figure/figures/documents.js +11 -3
  238. package/dist/lib/figure/figures/inbox.js +5 -2
  239. package/dist/lib/figure/figures/laptop.js +3 -1
  240. package/dist/lib/figure/figures/pipeline.js +45 -10
  241. package/dist/lib/figure/figures/platform.js +62 -7
  242. package/dist/lib/figure/figures/server.js +21 -5
  243. package/dist/lib/figure/figures/spreadsheet.js +29 -5
  244. package/dist/lib/figure/kernel.d.ts +4 -2
  245. package/dist/lib/figure/kernel.js +10 -5
  246. package/dist/lib/figure/parts.js +6 -2
  247. package/dist/lib/files.d.ts +31 -0
  248. package/dist/lib/files.js +60 -0
  249. package/dist/lib/gesture.d.ts +70 -0
  250. package/dist/lib/gesture.js +141 -0
  251. package/dist/lib/glide.d.ts +10 -4
  252. package/dist/lib/glide.js +14 -5
  253. package/dist/lib/icons.d.ts +1 -0
  254. package/dist/lib/icons.js +6 -0
  255. package/dist/lib/illustration-library.js +1 -6
  256. package/dist/lib/markdown-edit.d.ts +112 -0
  257. package/dist/lib/markdown-edit.js +557 -0
  258. package/dist/lib/markdown-rich-editor.d.ts +188 -0
  259. package/dist/lib/markdown-rich-editor.js +1153 -0
  260. package/dist/lib/markdown-rich.d.ts +63 -0
  261. package/dist/lib/markdown-rich.js +534 -0
  262. package/dist/lib/mentions.d.ts +100 -0
  263. package/dist/lib/mentions.js +246 -0
  264. package/dist/lib/motion.d.ts +18 -0
  265. package/dist/lib/motion.js +43 -5
  266. package/dist/lib/number-roll.d.ts +89 -0
  267. package/dist/lib/number-roll.js +391 -0
  268. package/dist/lib/platform.d.ts +6 -0
  269. package/dist/lib/platform.js +14 -0
  270. package/dist/lib/portal-container.d.ts +9 -0
  271. package/dist/lib/portal-container.js +10 -0
  272. package/dist/lib/press.d.ts +5 -0
  273. package/dist/lib/press.js +186 -0
  274. package/dist/lib/scheduler.d.ts +128 -0
  275. package/dist/lib/scheduler.js +272 -0
  276. package/dist/lib/scroll-edges.d.ts +9 -0
  277. package/dist/lib/scroll-edges.js +50 -0
  278. package/dist/lib/table-fit.d.ts +4 -3
  279. package/dist/lib/table-fit.js +92 -25
  280. package/dist/lib/theme-preset.d.ts +267 -0
  281. package/dist/lib/theme-preset.js +1046 -0
  282. package/dist/lib/theme-script.d.ts +23 -3
  283. package/dist/lib/theme-script.js +17 -5
  284. package/dist/lib/tippy/sprite.d.ts +36 -4
  285. package/dist/lib/tippy/sprite.js +188 -15
  286. package/dist/lib/tone.d.ts +4 -0
  287. package/dist/lib/tone.js +1 -0
  288. package/dist/messages/de.d.ts +3 -3
  289. package/dist/messages/de.js +274 -3
  290. package/dist/skills/zon-ui/SKILL.md +279 -0
  291. package/dist/skills/zon-ui/references/authoring.md +265 -0
  292. package/dist/skills/zon-ui/references/brand.md +416 -0
  293. package/dist/skills/zon-ui/references/components/accordion.md +199 -0
  294. package/dist/skills/zon-ui/references/components/action-sheet.md +268 -0
  295. package/dist/skills/zon-ui/references/components/alert-dialog.md +276 -0
  296. package/dist/skills/zon-ui/references/components/alert.md +167 -0
  297. package/dist/skills/zon-ui/references/components/app-bar.md +307 -0
  298. package/dist/skills/zon-ui/references/components/ascii-field.md +121 -0
  299. package/dist/skills/zon-ui/references/components/aspect-ratio.md +112 -0
  300. package/dist/skills/zon-ui/references/components/audio-player.md +231 -0
  301. package/dist/skills/zon-ui/references/components/avatar.md +98 -0
  302. package/dist/skills/zon-ui/references/components/badge.md +227 -0
  303. package/dist/skills/zon-ui/references/components/bottom-nav.md +709 -0
  304. package/dist/skills/zon-ui/references/components/breadcrumb.md +143 -0
  305. package/dist/skills/zon-ui/references/components/button-group.md +216 -0
  306. package/dist/skills/zon-ui/references/components/button.md +309 -0
  307. package/dist/skills/zon-ui/references/components/calendar.md +296 -0
  308. package/dist/skills/zon-ui/references/components/card.md +158 -0
  309. package/dist/skills/zon-ui/references/components/carousel.md +297 -0
  310. package/dist/skills/zon-ui/references/components/chart.md +739 -0
  311. package/dist/skills/zon-ui/references/components/chat.md +417 -0
  312. package/dist/skills/zon-ui/references/components/checkbox.md +219 -0
  313. package/dist/skills/zon-ui/references/components/code-block.md +143 -0
  314. package/dist/skills/zon-ui/references/components/code-highlight.md +118 -0
  315. package/dist/skills/zon-ui/references/components/collapsible.md +146 -0
  316. package/dist/skills/zon-ui/references/components/color-picker.md +200 -0
  317. package/dist/skills/zon-ui/references/components/combobox.md +455 -0
  318. package/dist/skills/zon-ui/references/components/command.md +326 -0
  319. package/dist/skills/zon-ui/references/components/contact-form.md +562 -0
  320. package/dist/skills/zon-ui/references/components/context-menu.md +159 -0
  321. package/dist/skills/zon-ui/references/components/conversation.md +146 -0
  322. package/dist/skills/zon-ui/references/components/copy-button.md +162 -0
  323. package/dist/skills/zon-ui/references/components/crm.md +1022 -0
  324. package/dist/skills/zon-ui/references/components/dashboard.md +612 -0
  325. package/dist/skills/zon-ui/references/components/data-table.md +776 -0
  326. package/dist/skills/zon-ui/references/components/date-picker.md +444 -0
  327. package/dist/skills/zon-ui/references/components/dialog.md +335 -0
  328. package/dist/skills/zon-ui/references/components/direction.md +165 -0
  329. package/dist/skills/zon-ui/references/components/drawer.md +276 -0
  330. package/dist/skills/zon-ui/references/components/drawing.md +94 -0
  331. package/dist/skills/zon-ui/references/components/empty.md +225 -0
  332. package/dist/skills/zon-ui/references/components/feature-list.md +412 -0
  333. package/dist/skills/zon-ui/references/components/field.md +209 -0
  334. package/dist/skills/zon-ui/references/components/file-drop.md +234 -0
  335. package/dist/skills/zon-ui/references/components/filter-bar.md +485 -0
  336. package/dist/skills/zon-ui/references/components/form.md +970 -0
  337. package/dist/skills/zon-ui/references/components/graph.md +339 -0
  338. package/dist/skills/zon-ui/references/components/illustration.md +497 -0
  339. package/dist/skills/zon-ui/references/components/inbox.md +263 -0
  340. package/dist/skills/zon-ui/references/components/input-group.md +339 -0
  341. package/dist/skills/zon-ui/references/components/input.md +189 -0
  342. package/dist/skills/zon-ui/references/components/item.md +277 -0
  343. package/dist/skills/zon-ui/references/components/kanban.md +626 -0
  344. package/dist/skills/zon-ui/references/components/kbd.md +116 -0
  345. package/dist/skills/zon-ui/references/components/label.md +104 -0
  346. package/dist/skills/zon-ui/references/components/layout.md +291 -0
  347. package/dist/skills/zon-ui/references/components/lightbox.md +235 -0
  348. package/dist/skills/zon-ui/references/components/locale.md +279 -0
  349. package/dist/skills/zon-ui/references/components/logo.md +257 -0
  350. package/dist/skills/zon-ui/references/components/markdown-editor.md +558 -0
  351. package/dist/skills/zon-ui/references/components/mentions.md +512 -0
  352. package/dist/skills/zon-ui/references/components/menu.md +218 -0
  353. package/dist/skills/zon-ui/references/components/menubar.md +292 -0
  354. package/dist/skills/zon-ui/references/components/message.md +243 -0
  355. package/dist/skills/zon-ui/references/components/meter.md +105 -0
  356. package/dist/skills/zon-ui/references/components/money-input.md +333 -0
  357. package/dist/skills/zon-ui/references/components/native-select.md +197 -0
  358. package/dist/skills/zon-ui/references/components/navigation-menu.md +253 -0
  359. package/dist/skills/zon-ui/references/components/number-field.md +210 -0
  360. package/dist/skills/zon-ui/references/components/number-roll.md +175 -0
  361. package/dist/skills/zon-ui/references/components/onboarding.md +896 -0
  362. package/dist/skills/zon-ui/references/components/otp-field.md +166 -0
  363. package/dist/skills/zon-ui/references/components/pagination.md +109 -0
  364. package/dist/skills/zon-ui/references/components/pdf-viewer.md +177 -0
  365. package/dist/skills/zon-ui/references/components/phone-input.md +252 -0
  366. package/dist/skills/zon-ui/references/components/popover.md +176 -0
  367. package/dist/skills/zon-ui/references/components/preview-card.md +193 -0
  368. package/dist/skills/zon-ui/references/components/pricing.md +724 -0
  369. package/dist/skills/zon-ui/references/components/progress.md +92 -0
  370. package/dist/skills/zon-ui/references/components/prompt-input.md +307 -0
  371. package/dist/skills/zon-ui/references/components/pull-to-refresh.md +188 -0
  372. package/dist/skills/zon-ui/references/components/quote.md +115 -0
  373. package/dist/skills/zon-ui/references/components/radio-group.md +215 -0
  374. package/dist/skills/zon-ui/references/components/rating.md +260 -0
  375. package/dist/skills/zon-ui/references/components/reasoning.md +102 -0
  376. package/dist/skills/zon-ui/references/components/resizable.md +213 -0
  377. package/dist/skills/zon-ui/references/components/response.md +170 -0
  378. package/dist/skills/zon-ui/references/components/scheduler.md +732 -0
  379. package/dist/skills/zon-ui/references/components/scroll-area.md +122 -0
  380. package/dist/skills/zon-ui/references/components/select.md +351 -0
  381. package/dist/skills/zon-ui/references/components/separator.md +103 -0
  382. package/dist/skills/zon-ui/references/components/settings.md +793 -0
  383. package/dist/skills/zon-ui/references/components/shop.md +1715 -0
  384. package/dist/skills/zon-ui/references/components/sidebar.md +813 -0
  385. package/dist/skills/zon-ui/references/components/sign-in.md +1639 -0
  386. package/dist/skills/zon-ui/references/components/site-header.md +303 -0
  387. package/dist/skills/zon-ui/references/components/skeleton.md +256 -0
  388. package/dist/skills/zon-ui/references/components/slider.md +172 -0
  389. package/dist/skills/zon-ui/references/components/sortable.md +405 -0
  390. package/dist/skills/zon-ui/references/components/sources.md +106 -0
  391. package/dist/skills/zon-ui/references/components/spinner.md +222 -0
  392. package/dist/skills/zon-ui/references/components/stat.md +267 -0
  393. package/dist/skills/zon-ui/references/components/stepper.md +285 -0
  394. package/dist/skills/zon-ui/references/components/suggestions.md +146 -0
  395. package/dist/skills/zon-ui/references/components/swipe-actions.md +344 -0
  396. package/dist/skills/zon-ui/references/components/switch.md +160 -0
  397. package/dist/skills/zon-ui/references/components/table.md +999 -0
  398. package/dist/skills/zon-ui/references/components/tabs.md +258 -0
  399. package/dist/skills/zon-ui/references/components/tag.md +115 -0
  400. package/dist/skills/zon-ui/references/components/tags-input.md +216 -0
  401. package/dist/skills/zon-ui/references/components/textarea.md +95 -0
  402. package/dist/skills/zon-ui/references/components/theme-editor.md +3940 -0
  403. package/dist/skills/zon-ui/references/components/theme.md +362 -0
  404. package/dist/skills/zon-ui/references/components/time-field.md +222 -0
  405. package/dist/skills/zon-ui/references/components/timeline.md +285 -0
  406. package/dist/skills/zon-ui/references/components/tippy.md +243 -0
  407. package/dist/skills/zon-ui/references/components/toast.md +220 -0
  408. package/dist/skills/zon-ui/references/components/toggle-group.md +261 -0
  409. package/dist/skills/zon-ui/references/components/toggle.md +167 -0
  410. package/dist/skills/zon-ui/references/components/tool-call.md +146 -0
  411. package/dist/skills/zon-ui/references/components/toolbar.md +260 -0
  412. package/dist/skills/zon-ui/references/components/tooltip.md +172 -0
  413. package/dist/skills/zon-ui/references/components/tour.md +423 -0
  414. package/dist/skills/zon-ui/references/components/tree.md +481 -0
  415. package/dist/skills/zon-ui/references/components/typography.md +347 -0
  416. package/dist/skills/zon-ui/references/components/video-player.md +386 -0
  417. package/dist/skills/zon-ui/references/marketing.md +467 -0
  418. package/dist/skills/zon-ui/references/motion.md +455 -0
  419. package/dist/skills/zon-ui/references/recipes.md +1232 -0
  420. package/dist/skills/zon-ui/references/tokens.md +866 -0
  421. package/dist/sources/accordion.css +4 -0
  422. package/dist/sources/action-sheet.css +11 -0
  423. package/dist/sources/alert-dialog.css +6 -0
  424. package/dist/sources/alert.css +3 -0
  425. package/dist/sources/app-bar.css +14 -0
  426. package/dist/sources/ascii-field.css +3 -0
  427. package/dist/sources/aspect-ratio.css +3 -0
  428. package/dist/sources/audio-player.css +20 -0
  429. package/dist/sources/avatar.css +3 -0
  430. package/dist/sources/badge.css +3 -0
  431. package/dist/sources/bottom-nav.css +9 -0
  432. package/dist/sources/breadcrumb.css +14 -0
  433. package/dist/sources/button-group.css +3 -0
  434. package/dist/sources/button.css +9 -0
  435. package/dist/sources/calendar.css +13 -0
  436. package/dist/sources/card.css +3 -0
  437. package/dist/sources/carousel.css +11 -0
  438. package/dist/sources/chart.css +5 -0
  439. package/dist/sources/checkbox.css +6 -0
  440. package/dist/sources/code-block.css +13 -0
  441. package/dist/sources/collapsible.css +4 -0
  442. package/dist/sources/color-picker.css +13 -0
  443. package/dist/sources/combobox.css +13 -0
  444. package/dist/sources/command.css +13 -0
  445. package/dist/sources/context-menu.css +12 -0
  446. package/dist/sources/conversation.css +10 -0
  447. package/dist/sources/copy-button.css +10 -0
  448. package/dist/sources/data-table.css +27 -0
  449. package/dist/sources/date-picker.css +20 -0
  450. package/dist/sources/dialog.css +9 -0
  451. package/dist/sources/direction.css +2 -0
  452. package/dist/sources/drawer.css +9 -0
  453. package/dist/sources/drawing.css +5 -0
  454. package/dist/sources/empty.css +3 -0
  455. package/dist/sources/feature-list.css +4 -0
  456. package/dist/sources/field.css +4 -0
  457. package/dist/sources/file-drop.css +15 -0
  458. package/dist/sources/filter-bar.css +30 -0
  459. package/dist/sources/form.css +4 -0
  460. package/dist/sources/graph.css +19 -0
  461. package/dist/sources/illustration.css +28 -0
  462. package/dist/sources/input-group.css +7 -0
  463. package/dist/sources/input.css +3 -0
  464. package/dist/sources/item.css +4 -0
  465. package/dist/sources/kbd.css +5 -0
  466. package/dist/sources/label.css +3 -0
  467. package/dist/sources/layout.css +3 -0
  468. package/dist/sources/lightbox.css +33 -0
  469. package/dist/sources/locale.css +2 -0
  470. package/dist/sources/logo.css +4 -0
  471. package/dist/sources/markdown-editor.css +41 -0
  472. package/dist/sources/mentions.css +13 -0
  473. package/dist/sources/menu.css +11 -0
  474. package/dist/sources/menubar.css +14 -0
  475. package/dist/sources/message.css +16 -0
  476. package/dist/sources/meter.css +4 -0
  477. package/dist/sources/money-input.css +10 -0
  478. package/dist/sources/native-select.css +4 -0
  479. package/dist/sources/navigation-menu.css +8 -0
  480. package/dist/sources/number-field.css +8 -0
  481. package/dist/sources/number-roll.css +6 -0
  482. package/dist/sources/otp-field.css +5 -0
  483. package/dist/sources/pagination.css +11 -0
  484. package/dist/sources/pdf-viewer.css +30 -0
  485. package/dist/sources/phone-input.css +20 -0
  486. package/dist/sources/popover.css +7 -0
  487. package/dist/sources/preview-card.css +7 -0
  488. package/dist/sources/progress.css +4 -0
  489. package/dist/sources/prompt-input.css +15 -0
  490. package/dist/sources/pull-to-refresh.css +14 -0
  491. package/dist/sources/quote.css +3 -0
  492. package/dist/sources/radio-group.css +5 -0
  493. package/dist/sources/rating.css +6 -0
  494. package/dist/sources/reasoning.css +6 -0
  495. package/dist/sources/resizable.css +4 -0
  496. package/dist/sources/response.css +16 -0
  497. package/dist/sources/scheduler.css +44 -0
  498. package/dist/sources/scroll-area.css +3 -0
  499. package/dist/sources/select.css +12 -0
  500. package/dist/sources/separator.css +3 -0
  501. package/dist/sources/sidebar.css +19 -0
  502. package/dist/sources/site-header.css +15 -0
  503. package/dist/sources/skeleton.css +3 -0
  504. package/dist/sources/slider.css +6 -0
  505. package/dist/sources/sortable.css +12 -0
  506. package/dist/sources/sources.css +6 -0
  507. package/dist/sources/spinner.css +6 -0
  508. package/dist/sources/stat.css +9 -0
  509. package/dist/sources/stepper.css +6 -0
  510. package/dist/sources/suggestions.css +10 -0
  511. package/dist/sources/swipe-actions.css +20 -0
  512. package/dist/sources/switch.css +5 -0
  513. package/dist/sources/table.css +7 -0
  514. package/dist/sources/tabs.css +5 -0
  515. package/dist/sources/tag.css +3 -0
  516. package/dist/sources/tags-input.css +6 -0
  517. package/dist/sources/textarea.css +3 -0
  518. package/dist/sources/theme.css +13 -0
  519. package/dist/sources/time-field.css +7 -0
  520. package/dist/sources/timeline.css +7 -0
  521. package/dist/sources/tippy.css +6 -0
  522. package/dist/sources/toast.css +6 -0
  523. package/dist/sources/toggle-group.css +5 -0
  524. package/dist/sources/toggle.css +3 -0
  525. package/dist/sources/tool-call.css +16 -0
  526. package/dist/sources/toolbar.css +14 -0
  527. package/dist/sources/tooltip.css +6 -0
  528. package/dist/sources/tour.css +14 -0
  529. package/dist/sources/tree.css +6 -0
  530. package/dist/sources/typography.css +4 -0
  531. package/dist/sources/video-player.css +21 -0
  532. package/dist/styles/ai.css +3 -0
  533. package/dist/styles/brand.css +98 -0
  534. package/dist/styles/core.css +266 -0
  535. package/dist/styles/editor.css +3 -0
  536. package/dist/styles/expressive.css +75 -77
  537. package/dist/styles/fonts.css +61 -117
  538. package/dist/styles/graph.css +4 -0
  539. package/dist/styles/illustration.css +4 -0
  540. package/dist/styles/index.css +11 -193
  541. package/dist/styles/material.css +177 -31
  542. package/dist/styles/parts/ai.css +20 -14
  543. package/dist/styles/parts/brand.css +2 -2
  544. package/dist/styles/parts/controls.css +51 -38
  545. package/dist/styles/parts/data.css +43 -11
  546. package/dist/styles/parts/editor.css +372 -0
  547. package/dist/styles/parts/feedback.css +75 -15
  548. package/dist/styles/parts/foundations.css +12 -7
  549. package/dist/styles/parts/graph.css +25 -9
  550. package/dist/styles/parts/inputs.css +172 -9
  551. package/dist/styles/parts/isometric.css +6 -5
  552. package/dist/styles/parts/navigation.css +237 -25
  553. package/dist/styles/parts/overlays.css +110 -8
  554. package/dist/styles/parts/pdf.css +15 -9
  555. package/dist/styles/pdf.css +3 -0
  556. package/dist/styles/prose.css +3 -0
  557. package/dist/styles/tokens.css +105 -15
  558. package/dist/theme.d.ts +1 -0
  559. package/dist/theme.js +5 -0
  560. package/dist/vite.d.ts +48 -59
  561. package/dist/vite.js +54 -21
  562. package/package.json +69 -2
@@ -0,0 +1,1717 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { cn } from "../lib/cn.js";
5
+ import { autoScroll, DRAG_THRESHOLD, LONG_PRESS, scrollersOf, TOUCH_SLOP, useAnnouncer, } from "../lib/drag.js";
6
+ import { CalendarIcon, EllipsisIcon, PlusIcon } from "../lib/icons.js";
7
+ import { axisRange, changeSpan, DAY, fromWall, HOUR, isoWeek, startOf, startOfDay, startOfMonth, keyAction, packLanes, pxPerMs, rowAt, roundedPath, rowOffsets, snapDelta, ticks as axisTicks, toWall, visibleRows, weekendRuns, withStep, ZOOMS, } from "../lib/scheduler.js";
8
+ import { SchedulerCalendar } from "./_scheduler-calendar.js";
9
+ import { categoriesOf, categoryOf, clamp, defaultMessages, describeSpan, editedItem, newId, preloadEditor, SchedulerEditorHost, SchedulerMenuHost, doneTones, formatRange, formats, markTones, toneClasses, SchedulerDetails, weekInfo, } from "./_scheduler-parts.js";
10
+ import { Button } from "./button.js";
11
+ import { Empty, EmptyDescription, EmptyMedia } from "./empty.js";
12
+ import { Input } from "./input.js";
13
+ import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from "./popover.js";
14
+ import { useLocale, useMessages } from "./locale.js";
15
+ import { NativeSelect, NativeSelectOption } from "./native-select.js";
16
+ import { ScrollArea } from "./scroll-area.js";
17
+ import { Skeleton } from "./skeleton.js";
18
+ import { ToggleGroup, ToggleGroupItem } from "./toggle-group.js";
19
+ const FALLBACK = { default: { row: 38, lane: 30, bar: 24 }, sm: { row: 30, lane: 30, bar: 24 } };
20
+ const MIN_GRID = 120;
21
+ const MAX_GRID = 560;
22
+ /** Below this many px wide, details open in a drawer and the list keeps only its first column. */
23
+ const NARROW = 640;
24
+ /** The whole days a span touches, at least one. */
25
+ const daysOf = (span) => {
26
+ const start = startOfDay(span.start);
27
+ return { start, end: Math.max(Math.ceil(span.end / DAY) * DAY, start + DAY) };
28
+ };
29
+ function buildModel(layout, items, rows, metrics,
30
+ /** Draw bookings as the days they touch: an hour is a sliver at a day's width of 48px. */
31
+ wholeDays,
32
+ /** End the list with a row that adds to it. */
33
+ adding,
34
+ /** A row's items as a cell a day, with how many (a resource timeline's Month), not as bars. */
35
+ asCells = false) {
36
+ const rowList = rows ??
37
+ (layout === "gantt"
38
+ ? items.map((item) => ({ id: item.id, title: item.title, group: item.group }))
39
+ : [...new Set(items.map((i) => i.row ?? ""))].map((id) => ({ id, title: id })));
40
+ // Rows keep their order, gathered under their groups in the order the groups first appear.
41
+ const groups = new Map();
42
+ const loose = [];
43
+ for (const row of rowList) {
44
+ if (row.group === undefined)
45
+ loose.push(row);
46
+ else {
47
+ const list = groups.get(row.group);
48
+ if (list)
49
+ list.push(row);
50
+ else
51
+ groups.set(row.group, [row]);
52
+ }
53
+ }
54
+ const display = [];
55
+ let position = 0;
56
+ for (const row of loose)
57
+ display.push({ kind: "row", row, position: ++position });
58
+ for (const [group, members] of groups) {
59
+ display.push({ kind: "group", id: `group:${group}`, title: group });
60
+ for (const row of members)
61
+ display.push({ kind: "row", row, position: ++position });
62
+ }
63
+ if (adding)
64
+ display.push({ kind: "add", id: "add" });
65
+ const rowIndex = new Map();
66
+ display.forEach((d, i) => d.kind === "row" && rowIndex.set(d.row.id, i));
67
+ const byRow = display.map(() => []);
68
+ const entries = new Map();
69
+ for (const item of items) {
70
+ const rowId = item.row ?? (layout === "gantt" ? item.id : "");
71
+ const row = rowIndex.get(rowId);
72
+ if (row === undefined)
73
+ continue;
74
+ const start = toWall(item.start);
75
+ const milestone = !!item.milestone;
76
+ const end = milestone ? start : Math.max(toWall(item.end), start);
77
+ const span = { start, end };
78
+ const shown = wholeDays && !milestone ? daysOf(span) : span;
79
+ entries.set(item.id, { item, span, shown, milestone, row, lane: 0 });
80
+ byRow[row].push(item.id);
81
+ }
82
+ const cells = new Map();
83
+ const heights = display.map((d, i) => {
84
+ if (d.kind === "group")
85
+ return metrics.lane;
86
+ if (d.kind === "add")
87
+ return metrics.row;
88
+ const ids = byRow[i];
89
+ // By day, then by start: a day's bookings stack in the order they happen.
90
+ const { lane, lanes } = packLanes([...ids]
91
+ .sort((a, b) => entries.get(a).shown.start - entries.get(b).shown.start ||
92
+ entries.get(a).span.start - entries.get(b).span.start)
93
+ .map((id) => ({ id, ...entries.get(id).shown })));
94
+ for (const id of ids)
95
+ entries.get(id).lane = lane.get(id) ?? 0;
96
+ ids.sort((a, b) => entries.get(a).span.start - entries.get(b).span.start);
97
+ if (!asCells)
98
+ return metrics.row + (lanes - 1) * metrics.lane;
99
+ const days = new Map();
100
+ for (const id of ids) {
101
+ const e = entries.get(id);
102
+ for (let day = e.shown.start; day < e.shown.end; day += DAY)
103
+ days.set(day, [...(days.get(day) ?? []), id]);
104
+ }
105
+ cells.set(i, days);
106
+ byRow[i] = [];
107
+ return metrics.row;
108
+ });
109
+ const groupSpans = new Map();
110
+ let group = -1;
111
+ display.forEach((d, i) => {
112
+ if (d.kind === "group")
113
+ return void (group = i);
114
+ if (group < 0)
115
+ return;
116
+ for (const id of byRow[i]) {
117
+ const { shown: span } = entries.get(id);
118
+ const now = groupSpans.get(group);
119
+ groupSpans.set(group, now ? { start: Math.min(now.start, span.start), end: Math.max(now.end, span.end) } : { ...span });
120
+ }
121
+ });
122
+ const links = [];
123
+ for (const entry of entries.values())
124
+ for (const from of entry.item.dependsOn ?? [])
125
+ if (entries.has(from))
126
+ links.push({ from, to: entry.item.id });
127
+ return {
128
+ display,
129
+ offsets: rowOffsets(heights),
130
+ entries,
131
+ byRow,
132
+ order: byRow.flat(),
133
+ groupSpans,
134
+ rowCount: position,
135
+ links,
136
+ cells,
137
+ };
138
+ }
139
+ /* ── Helpers ───────────────────────────────────────────────────────────────── */
140
+ /** The scroll offset from the inline start, the same in both directions. */
141
+ const getInline = (el, rtl) => (rtl ? -el.scrollLeft : el.scrollLeft);
142
+ const setInline = (el, rtl, value) => {
143
+ el.scrollLeft = rtl ? -value : value;
144
+ };
145
+ /** The views a calendar offers when `views` is not given. */
146
+ const DEFAULT_VIEWS = ["day", "week", "month"];
147
+ /** The timeline zoom for a calendar's items after a view: hours after the time grid, days after the month. */
148
+ const zoomOfView = (view) => (view === "month" ? "week" : "day");
149
+ /**
150
+ * Scheduler — tasks, bookings and events in time: a Gantt chart of a project, a resource timeline
151
+ * of people or rooms, or a calendar of days and hours.
152
+ *
153
+ * The timelines (`layout="gantt"`, `"resource"`) list rows on the left beside a time axis with Day,
154
+ * Week and Month zoom. The calendar (`layout="calendar"`) puts days across and hours down — a day,
155
+ * a few days, a week or the working week — or a month of weeks; overlapping events sit side by
156
+ * side. Everything moves with a drag and resizes from its end, snapping as it goes; on touch, a long
157
+ * press picks it up. From the keyboard, the arrow keys move a focused item and Shift with them its
158
+ * end. Every change is said out loud.
159
+ *
160
+ * The rule people break: colouring every item. Items stay in the material; a tone marks a kind of
161
+ * work or a state, and the same words sit beside it in a column or a legend.
162
+ */
163
+ export function Scheduler({ layout = "gantt", items: itemsProp, defaultItems, onItemsChange, view: viewProp, defaultView = "week", onViewChange, views = DEFAULT_VIEWS, date: dateProp, onDateChange, defaultDate, labels, ...props }) {
164
+ const text = useMessages("scheduler", defaultMessages, labels);
165
+ const [uncontrolled, setUncontrolled] = React.useState(defaultItems ?? []);
166
+ const items = itemsProp ?? uncontrolled;
167
+ const controlled = itemsProp !== undefined;
168
+ const changeRef = React.useRef(onItemsChange);
169
+ changeRef.current = onItemsChange;
170
+ // The items live here, so a calendar switching between its views keeps what was changed in any.
171
+ const change = React.useCallback((next, details) => {
172
+ if (!controlled)
173
+ setUncontrolled(next);
174
+ changeRef.current?.(next, details);
175
+ }, [controlled]);
176
+ const [viewState, setViewState] = React.useState(defaultView);
177
+ const view = viewProp ?? viewState;
178
+ /** The calendar view before the timeline was picked: the timeline's zoom follows it. */
179
+ const [lastView, setLastView] = React.useState(view === "timeline" ? "week" : view);
180
+ const setView = (next) => {
181
+ if (next === view)
182
+ return;
183
+ if (view !== "timeline")
184
+ setLastView(view);
185
+ if (viewProp === undefined)
186
+ setViewState(next);
187
+ onViewChange?.(next);
188
+ };
189
+ const [dateState, setDateState] = React.useState(defaultDate);
190
+ const date = dateProp ?? dateState;
191
+ const setDate = (next) => {
192
+ if (dateProp === undefined)
193
+ setDateState(next);
194
+ onDateChange?.(next);
195
+ };
196
+ if (layout !== "calendar")
197
+ return (_jsx(SchedulerTimeline, { ...props, layout: layout, items: items, onItemsChange: change, defaultDate: defaultDate, labels: labels }));
198
+ const viewName = (v) => v === "work-week"
199
+ ? text.workWeek
200
+ : v === "days"
201
+ ? text.days(props.days ?? 3)
202
+ : v === "timeline"
203
+ ? text.timeline
204
+ : text[v];
205
+ // More than three views do not fit a phone's width as segments: there they are a select.
206
+ const many = views.length > 3;
207
+ const viewSwitch = props.controls !== false && views.length > 1 ? (_jsxs(_Fragment, { children: [_jsx(ToggleGroup, { "data-slot": "scheduler-view", "aria-label": text.view, value: [view], onValueChange: (value) => value[0] && setView(value[0]), className: many ? "@max-[40rem]/scheduler:hidden" : undefined, children: views.map((v) => (_jsx(ToggleGroupItem, { value: v, children: viewName(v) }, v))) }), many && (_jsx(NativeSelect, { "data-slot": "scheduler-view-select", "aria-label": text.view, value: view, onChange: (event) => setView(event.target.value), wrapperClassName: "hidden @max-[40rem]/scheduler:inline-flex", children: views.map((v) => (_jsx(NativeSelectOption, { value: v, children: viewName(v) }, v))) }))] })) : null;
208
+ // The timeline's own props stay off the calendar's frame.
209
+ const { rows, columns: _columns, zoom: _zoom, defaultZoom: _defaultZoom, onZoomChange: _onZoomChange, zooms: _zooms, range: _range, defaultListWidth: _defaultListWidth, empty: _empty, onRowsChange: _onRowsChange, ...calendarProps } = props;
210
+ if (view === "timeline") {
211
+ const zoom = zoomOfView(lastView);
212
+ // The calendar's date, at the start of the working day in the Day zoom.
213
+ let from = date ?? defaultDate;
214
+ if (from && zoom === "day") {
215
+ from = new Date(from);
216
+ from.setHours(props.workHours?.start ?? 8, 0, 0, 0);
217
+ }
218
+ return (_jsx(SchedulerTimeline, { ...props, layout: rows ? "resource" : "gantt", items: items, onItemsChange: change, zoom: zoom, zooms: [zoom], defaultDate: from, labels: labels, viewSwitch: viewSwitch, "data-view": "timeline" }));
219
+ }
220
+ return (_jsx(SchedulerCalendar, { ...calendarProps, rows: rows, view: view, items: items, onItemsChange: change, date: date, onDate: setDate, onShowDay: views.includes("day")
221
+ ? (day) => {
222
+ setDate(day);
223
+ setView("day");
224
+ }
225
+ : undefined, labels: labels, viewSwitch: viewSwitch }));
226
+ }
227
+ /** The timelines: a Gantt chart or a resource timeline. */
228
+ function SchedulerTimeline({ layout, items: itemsProp, defaultItems, onItemsChange, rows, columns = [], zoom: zoomProp, defaultZoom = "week", onZoomChange, zooms = ["day", "week", "month"], range: rangeProp, today: todayProp, defaultDate, weekStartsOn: weekStartsOnProp, readOnly = false, loading = false, empty, toolbar, controls = true, renderDetails, onItemOpen, size = "default", variant = "region", defaultListWidth, labels, viewSwitch, step, hour12, className, style,
229
+ // Calendar-only props, not for the frame.
230
+ days: _days, workHours: _workHours, onItemCreate, editor = false, categories: categoriesProp, onRowsChange, createId = newId, ...props }) {
231
+ const text = useMessages("scheduler", defaultMessages, labels);
232
+ const locale = useLocale();
233
+ const fmt = React.useMemo(() => formats(locale, hour12), [locale, hour12]);
234
+ const week = React.useMemo(() => weekInfo(locale), [locale]);
235
+ const weekStartsOn = weekStartsOnProp ?? week.firstDay;
236
+ const [uncontrolled, setUncontrolled] = React.useState(defaultItems ?? []);
237
+ const items = itemsProp ?? uncontrolled;
238
+ const [zoomState, setZoomState] = React.useState(defaultZoom);
239
+ const zoom = zoomProp ?? zoomState;
240
+ // A `step` changes what the Day zoom snaps to; a day stays a day in the others.
241
+ const baseScale = React.useMemo(() => withStep(ZOOMS[zoom], zoom === "day" ? step : undefined), [zoom, step]);
242
+ /** A resource timeline's Week and Month zoom draw a booking as the days it touches. */
243
+ const wholeDays = layout === "resource" && zoom !== "day";
244
+ /** The list ends in a row that adds a task (a Gantt chart of items) or a row (with `onRowsChange`). */
245
+ const adding = !readOnly && !loading && (layout === "gantt" ? editor && !rows : !!onRowsChange && !!rows);
246
+ const categories = React.useMemo(() => categoriesOf(categoriesProp, text), [categoriesProp, text]);
247
+ const rootRef = React.useRef(null);
248
+ const viewportRef = React.useRef(null);
249
+ const canvasRef = React.useRef(null);
250
+ const listRef = React.useRef(null);
251
+ const highlightRef = React.useRef(null);
252
+ const readoutRef = React.useRef(null);
253
+ const linkRefs = React.useRef(new Map());
254
+ const probeRef = React.useRef(null);
255
+ const instructionsId = React.useId();
256
+ const markerId = `scheduler-arrow-${React.useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
257
+ const [message, announce] = useAnnouncer();
258
+ const [rtl, setRtl] = React.useState(false);
259
+ /** The same, for scroll code that runs in the commit that first reads it. */
260
+ const rtlRef = React.useRef(false);
261
+ const [narrow, setNarrow] = React.useState(false);
262
+ const [metrics, setMetrics] = React.useState(FALLBACK[size]);
263
+ const [listWidth, setListWidth] = React.useState(defaultListWidth ?? 240 + columns.reduce((sum, c) => sum + (c.width ?? 96), 0));
264
+ /** The bar in the tab order, and the one keyboard focus follows. */
265
+ const [activeId, setActiveId] = React.useState(null);
266
+ const [openId, setOpenId] = React.useState(null);
267
+ const [draggingId, setDraggingId] = React.useState(null);
268
+ const [view, setView] = React.useState({ top: 0, height: 600, left: 0, width: 1200 });
269
+ /** Whether there is more of the timeline to scroll to before and after the view: a fade says so. */
270
+ const [edges, setEdges] = React.useState({ start: false, end: false });
271
+ // The theme's sizes, and which way the page runs.
272
+ React.useLayoutEffect(() => {
273
+ const root = rootRef.current;
274
+ if (!root)
275
+ return;
276
+ viewportRef.current = root.querySelector("[data-slot=scroll-area-viewport]");
277
+ rtlRef.current = getComputedStyle(root).direction === "rtl";
278
+ setRtl(rtlRef.current);
279
+ const probe = probeRef.current;
280
+ if (!probe)
281
+ return;
282
+ const measure = () => {
283
+ const [row, lane, bar] = [...probe.children].map((c) => c.offsetHeight);
284
+ if (row && lane && bar)
285
+ setMetrics((m) => (m.row === row && m.lane === lane && m.bar === bar ? m : { row, lane, bar }));
286
+ else
287
+ setMetrics(FALLBACK[size]);
288
+ };
289
+ measure();
290
+ // A theme that changes while the chart is open (a density switch, the theme editor) resizes the
291
+ // probe's parts: measure again, so the rows and bars follow it.
292
+ if (typeof ResizeObserver === "undefined")
293
+ return;
294
+ const observer = new ResizeObserver(measure);
295
+ for (const child of probe.children)
296
+ observer.observe(child);
297
+ return () => observer.disconnect();
298
+ }, [size]);
299
+ React.useEffect(() => {
300
+ const root = rootRef.current;
301
+ if (!root || typeof ResizeObserver === "undefined")
302
+ return;
303
+ const observer = new ResizeObserver(() => setNarrow(root.offsetWidth > 0 && root.offsetWidth < NARROW));
304
+ observer.observe(root);
305
+ return () => observer.disconnect();
306
+ }, []);
307
+ // The width the timeline has beside the list, for a short range to fill.
308
+ React.useLayoutEffect(() => {
309
+ const vp = viewportRef.current;
310
+ if (!vp)
311
+ return;
312
+ const measure = () => {
313
+ const width = Math.floor(vp.clientWidth - (listRef.current?.offsetWidth ?? 0));
314
+ setAvailable((w) => (w === width ? w : width));
315
+ };
316
+ measure();
317
+ if (typeof ResizeObserver === "undefined")
318
+ return;
319
+ const observer = new ResizeObserver(measure);
320
+ observer.observe(vp);
321
+ if (listRef.current)
322
+ observer.observe(listRef.current);
323
+ return () => observer.disconnect();
324
+ }, []);
325
+ const model = React.useMemo(() => buildModel(layout, items, rows, metrics, wholeDays, adding, wholeDays && zoom === "month"), [layout, items, rows, metrics, wholeDays, adding, zoom]);
326
+ const totalHeight = model.offsets[model.offsets.length - 1] ?? 0;
327
+ const todayWall = React.useMemo(() => toWall(todayProp ?? new Date()), [todayProp]);
328
+ const range = React.useMemo(() => {
329
+ if (rangeProp)
330
+ return { start: toWall(rangeProp.start), end: toWall(rangeProp.end) };
331
+ // A resource timeline's Month: the months that are booked (and today's), each across the frame.
332
+ if (wholeDays && zoom === "month") {
333
+ let low = todayWall;
334
+ let high = todayWall;
335
+ for (const e of model.entries.values()) {
336
+ low = Math.min(low, e.span.start);
337
+ high = Math.max(high, e.span.end - 1);
338
+ }
339
+ return { start: startOfMonth(low), end: startOf("month", startOfMonth(high) + 32 * DAY, weekStartsOn) };
340
+ }
341
+ return axisRange([...model.entries.values()].map((e) => e.span), todayWall, zoom, weekStartsOn);
342
+ }, [rangeProp, model, todayWall, zoom, weekStartsOn, wholeDays]);
343
+ // A range shorter than the frame is wide stretches its columns to fill it: no dead space after it.
344
+ const [available, setAvailable] = React.useState(0);
345
+ // A resource timeline's Week is one week across the frame (a day at least 120px), its Month one
346
+ // month: its bookings sit in their days as chips with room for a name.
347
+ const periodScale = React.useMemo(() => {
348
+ if (!wholeDays || available <= 0)
349
+ return baseScale;
350
+ if (zoom === "week")
351
+ return { ...baseScale, unitWidth: Math.max(120, available / 7) };
352
+ // The days share the width, 28px at least.
353
+ const month = startOfMonth(defaultDate ? toWall(defaultDate) : todayWall);
354
+ const days = Math.round((startOf("month", month + 32 * DAY, weekStartsOn) - month) / DAY);
355
+ return { ...baseScale, minor: "day", unitWidth: Math.max(28, available / days) };
356
+ }, [baseScale, wholeDays, available, zoom, defaultDate, todayWall, weekStartsOn]);
357
+ const baseWidth = (range.end - range.start) * pxPerMs(periodScale);
358
+ const stretch = baseWidth > 0 && available > baseWidth + 1 ? available / baseWidth : 1;
359
+ const scale = stretch === 1 ? periodScale : { ...periodScale, unitWidth: periodScale.unitWidth * stretch };
360
+ const ppm = pxPerMs(scale);
361
+ const exactWidth = (range.end - range.start) * ppm;
362
+ // Within a pixel of the frame is the frame: no scrollbar for a rounding.
363
+ const timelineWidth = stretch !== 1 || Math.abs(exactWidth - available) < 1 ? available : Math.ceil(exactWidth);
364
+ const xOf = React.useCallback((wall) => (wall - range.start) * ppm, [range.start, ppm]);
365
+ const geometry = React.useCallback((entry, span = entry.shown, row = entry.row, lane = entry.lane) => {
366
+ const top = (model.offsets[row] ?? 0) + (metrics.row - metrics.lane) / 2 + lane * metrics.lane;
367
+ const y = top + (metrics.lane - metrics.bar) / 2;
368
+ if (entry.milestone)
369
+ return { x: xOf(span.start) - metrics.bar / 2, y, w: metrics.bar };
370
+ const x = xOf(span.start);
371
+ // A chip in its days, clear of the day lines either side.
372
+ if (wholeDays)
373
+ return { x: x + 2, y, w: Math.max((span.end - span.start) * ppm - 4, 6) };
374
+ return { x, y, w: Math.max((span.end - span.start) * ppm, 6) };
375
+ }, [model, metrics, xOf, wholeDays]);
376
+ // Scroll: which rows and which stretch of the axis are drawn.
377
+ const listW = () => listRef.current?.offsetWidth ?? listWidth;
378
+ const readView = React.useCallback(() => {
379
+ const vp = viewportRef.current;
380
+ if (!vp)
381
+ return;
382
+ const head = 2 * metrics.lane;
383
+ const next = {
384
+ top: Math.max(0, vp.scrollTop - head),
385
+ height: vp.clientHeight,
386
+ // In whole steps, so a scroll redraws the axis now and then, not on every frame.
387
+ left: Math.floor(getInline(vp, rtlRef.current) / 400) * 400,
388
+ width: Math.ceil((vp.clientWidth - listW()) / 400) * 400 + 400,
389
+ };
390
+ const scrolled = getInline(vp, rtlRef.current);
391
+ const more = { start: scrolled > 1, end: scrolled < vp.scrollWidth - vp.clientWidth - 1 };
392
+ setEdges((e) => (e.start === more.start && e.end === more.end ? e : more));
393
+ setView((v) => visibleRows(model.offsets, v.top, v.height).join() ===
394
+ visibleRows(model.offsets, next.top, next.height).join() &&
395
+ v.left === next.left &&
396
+ v.width === next.width
397
+ ? v
398
+ : next);
399
+ // eslint-disable-next-line react-hooks/exhaustive-deps
400
+ }, [model, metrics, rtl]);
401
+ React.useEffect(() => {
402
+ const vp = viewportRef.current;
403
+ if (!vp)
404
+ return;
405
+ let frame = 0;
406
+ const onScroll = () => {
407
+ cancelAnimationFrame(frame);
408
+ frame = requestAnimationFrame(readView);
409
+ };
410
+ readView();
411
+ vp.addEventListener("scroll", onScroll, { passive: true });
412
+ window.addEventListener("resize", onScroll);
413
+ return () => {
414
+ cancelAnimationFrame(frame);
415
+ vp.removeEventListener("scroll", onScroll);
416
+ window.removeEventListener("resize", onScroll);
417
+ };
418
+ }, [readView]);
419
+ // Scroll a moment into view, a little in from the list's edge.
420
+ const scrollToTime = React.useCallback((wall, where = "start") => {
421
+ const vp = viewportRef.current;
422
+ if (!vp)
423
+ return;
424
+ const visible = vp.clientWidth - listW();
425
+ const x = xOf(wall);
426
+ setInline(vp, rtlRef.current, Math.max(0, where === "center" ? x - visible / 2 : where === "edge" ? x : x - Math.min(visible * 0.08, 96)));
427
+ },
428
+ // eslint-disable-next-line react-hooks/exhaustive-deps
429
+ [xOf, rtl]);
430
+ // First paint: the date in view.
431
+ const placed = React.useRef(false);
432
+ React.useLayoutEffect(() => {
433
+ if (placed.current || loading || !viewportRef.current)
434
+ return;
435
+ placed.current = true;
436
+ const earliest = Math.min(...[...model.entries.values()].map((e) => e.span.start));
437
+ const wall = defaultDate ? toWall(defaultDate) : Number.isFinite(earliest) ? earliest : todayWall;
438
+ if (wholeDays)
439
+ scrollToTime(periodOf(wall), "edge");
440
+ else
441
+ scrollToTime(wall);
442
+ }, [loading, model, defaultDate, todayWall, scrollToTime]);
443
+ // A new zoom keeps the moment in the middle of the view where it was; a range that grows at its
444
+ // start keeps everything where it stands.
445
+ const anchor = React.useRef(null);
446
+ React.useLayoutEffect(() => {
447
+ const vp = viewportRef.current;
448
+ const before = anchor.current;
449
+ anchor.current = { zoom, start: range.start, ppm };
450
+ if (!vp || !before)
451
+ return;
452
+ if (before.zoom !== zoom) {
453
+ const visible = vp.clientWidth - listW();
454
+ const middle = before.start + (getInline(vp, rtlRef.current) + visible / 2) / before.ppm;
455
+ // A resource timeline's Week and Month open on the week or month in the middle, whole.
456
+ if (wholeDays)
457
+ scrollToTime(periodOf(middle), "edge");
458
+ else
459
+ scrollToTime(middle, "center");
460
+ }
461
+ else if (before.ppm !== ppm) {
462
+ // Wider or narrower days (the frame resized): the moment at the start stays there.
463
+ const left = before.start + getInline(vp, rtlRef.current) / before.ppm;
464
+ scrollToTime(wholeDays ? periodOf(left + DAY / 2) : left, "edge");
465
+ }
466
+ else if (before.start !== range.start) {
467
+ const dir = rtlRef.current;
468
+ setInline(vp, dir, getInline(vp, dir) + (before.start - range.start) * ppm);
469
+ }
470
+ readView();
471
+ // eslint-disable-next-line react-hooks/exhaustive-deps
472
+ }, [zoom, range.start, ppm]);
473
+ /** The week or month that holds a moment, as the axis draws them. */
474
+ function periodOf(wall) {
475
+ // A week wider than the frame (a phone): its day, not its start, comes first.
476
+ if (zoom === "week" && available > 0 && available < 7 * scale.unitWidth - 1)
477
+ return startOfDay(wall);
478
+ return startOf(ZOOMS[zoom].major === "week" ? "week" : "month", wall, weekStartsOn);
479
+ }
480
+ const setZoom = (next) => {
481
+ if (zoomProp === undefined)
482
+ setZoomState(next);
483
+ onZoomChange?.(next);
484
+ };
485
+ /* ── Changing items ─────────────────────────────────────────────────────── */
486
+ const itemsRef = React.useRef(items);
487
+ itemsRef.current = items;
488
+ const modelRef = React.useRef(model);
489
+ modelRef.current = model;
490
+ const callbacks = React.useRef({ onItemsChange, onItemOpen, onItemCreate });
491
+ callbacks.current = { onItemsChange, onItemOpen, onItemCreate };
492
+ const rowTitle = (displayRow) => {
493
+ const d = modelRef.current.display[displayRow];
494
+ return d?.kind === "row" ? d.row.title : "";
495
+ };
496
+ const describe = (entry, span) => describeSpan(fmt, span, entry.milestone);
497
+ /** Commit a new span (and row) for an item; returns whether anything changed. */
498
+ const commit = (entry, span, rowIndex, change, source) => {
499
+ const target = modelRef.current.display[rowIndex];
500
+ const rowId = target?.kind === "row" ? target.row.id : undefined;
501
+ const rowChanged = rowIndex !== entry.row && rowId !== undefined;
502
+ if (span.start === entry.span.start && span.end === entry.span.end && !rowChanged)
503
+ return false;
504
+ const previous = entry.item;
505
+ const item = {
506
+ ...previous,
507
+ start: fromWall(span.start),
508
+ end: fromWall(entry.milestone ? span.start : span.end),
509
+ ...(rowChanged ? { row: rowId } : null),
510
+ };
511
+ const next = itemsRef.current.map((i) => (i.id === item.id ? item : i));
512
+ if (itemsProp === undefined)
513
+ setUncontrolled(next);
514
+ callbacks.current.onItemsChange?.(next, { item, previous, change: rowChanged ? "row" : change, source });
515
+ return true;
516
+ };
517
+ /* ── Editing ──────────────────────────────────────────────────────────────── */
518
+ /** The editor, open on an item or on a new booking drawn (`pending`, dashed until it is saved). */
519
+ const [editing, setEditing] = React.useState(null);
520
+ const [pending, setPending] = React.useState(null);
521
+ const [menu, setMenu] = React.useState(null);
522
+ /** The day whose "+2" list is open: `row:day`. */
523
+ const [moreKey, setMoreKey] = React.useState(null);
524
+ /** A booking being drawn over empty space. */
525
+ const [drawing, setDrawing] = React.useState(null);
526
+ const linkDraftRef = React.useRef(null);
527
+ /** The row whose name is being typed: a task's id, or a row's. */
528
+ const [renaming, setRenaming] = React.useState(null);
529
+ /** A dependency picked with a click (`from>to`), for Delete to remove. */
530
+ const [selectedLink, setSelectedLink] = React.useState(null);
531
+ /** New bookings drawn in a row of a resource timeline. */
532
+ const canCreate = layout === "resource" && !readOnly && (editor || !!onItemCreate);
533
+ /** Dependencies drawn from a bar's end. */
534
+ const linking = layout === "gantt" && editor && !readOnly;
535
+ React.useEffect(() => {
536
+ if ((editor || onRowsChange) && !readOnly)
537
+ preloadEditor();
538
+ }, [editor, onRowsChange, readOnly]);
539
+ // A dependency picked with a click: Delete removes it, Escape lets it go.
540
+ React.useEffect(() => {
541
+ if (!selectedLink)
542
+ return;
543
+ const onKey = (e) => {
544
+ if (e.key === "Escape")
545
+ return setSelectedLink(null);
546
+ if (e.key !== "Delete" && e.key !== "Backspace")
547
+ return;
548
+ const target = e.target;
549
+ if (target?.closest("input, textarea, [contenteditable=true]"))
550
+ return;
551
+ e.preventDefault();
552
+ const [from, to] = selectedLink.split(">");
553
+ if (from && to)
554
+ setDependency(from, to, false, "keyboard");
555
+ };
556
+ window.addEventListener("keydown", onKey);
557
+ return () => window.removeEventListener("keydown", onKey);
558
+ });
559
+ /** Hand a new list of items to the app (and keep it, uncontrolled). */
560
+ const emit = (next, details) => {
561
+ if (itemsProp === undefined)
562
+ setUncontrolled(next);
563
+ callbacks.current.onItemsChange?.(next, details);
564
+ };
565
+ const editable = (entry) => editor && !readOnly && !entry.item.disabled;
566
+ const rowIdOf = (index) => {
567
+ const d = modelRef.current.display[index];
568
+ return d?.kind === "row" ? d.row.id : undefined;
569
+ };
570
+ const open = (id) => {
571
+ const entry = modelRef.current.entries.get(id);
572
+ if (!entry)
573
+ return;
574
+ callbacks.current.onItemOpen?.(entry.item);
575
+ setSelectedLink(null);
576
+ // With the editor, an item that can change opens in it; a locked one shows its details.
577
+ if (editable(entry)) {
578
+ const whole = entry.span.start === startOfDay(entry.span.start) && entry.span.end === startOfDay(entry.span.end);
579
+ return setEditing({
580
+ kind: layout === "gantt" ? "task" : "booking",
581
+ id,
582
+ milestone: entry.milestone,
583
+ value: {
584
+ title: entry.item.title,
585
+ start: entry.item.start,
586
+ end: entry.item.end,
587
+ allDay: layout === "gantt" || (whole && entry.span.end > entry.span.start),
588
+ row: layout === "resource" ? rowIdOf(entry.row) : undefined,
589
+ category: categoryOf(entry.item, categories),
590
+ },
591
+ });
592
+ }
593
+ if (renderDetails)
594
+ setOpenId(id);
595
+ };
596
+ /** A new booking over `span` in a row: to the editor, or to the app. */
597
+ const create = (row, span) => {
598
+ const draft = {
599
+ start: fromWall(span.start),
600
+ end: fromWall(span.end),
601
+ allDay: wholeDays,
602
+ row: rowIdOf(row),
603
+ };
604
+ if (editor) {
605
+ setPending({ row, span });
606
+ setEditing({ kind: "booking", value: { title: "", ...draft, category: undefined } });
607
+ return;
608
+ }
609
+ callbacks.current.onItemCreate?.(draft);
610
+ announce(text.creating(`${rowTitle(row)}, ${describeSpan(fmt, span, false)}`));
611
+ };
612
+ const closeEditor = () => {
613
+ setEditing(null);
614
+ setPending(null);
615
+ };
616
+ const whenOf = (item) => {
617
+ const start = toWall(item.start);
618
+ return describeSpan(fmt, { start, end: item.milestone ? start : Math.max(toWall(item.end), start) }, !!item.milestone);
619
+ };
620
+ const saveEditor = (value) => {
621
+ const state = editing;
622
+ if (!state)
623
+ return;
624
+ const base = state.id ? modelRef.current.entries.get(state.id)?.item : undefined;
625
+ const id = base?.id ?? createId();
626
+ const item = editedItem(base, id, state, value, categories, !!categoriesProp);
627
+ if (layout === "gantt")
628
+ delete item.row;
629
+ const next = base ? itemsRef.current.map((i) => (i.id === id ? item : i)) : [...itemsRef.current, item];
630
+ emit(next, { item, previous: base ?? item, change: base ? "edit" : "create", source: "editor" });
631
+ announce((base ? text.saved : text.created)(item.title, whenOf(item)));
632
+ closeEditor();
633
+ setActiveId(id);
634
+ reveal.current = id;
635
+ };
636
+ const deleteItem = (id, source) => {
637
+ const entry = modelRef.current.entries.get(id);
638
+ if (!entry || !editable(entry))
639
+ return;
640
+ const order = modelRef.current.order;
641
+ const at = order.indexOf(id);
642
+ const neighbour = order[at + 1] ?? order[at - 1];
643
+ // Whatever waited for it waits no more.
644
+ const next = itemsRef.current
645
+ .filter((i) => i.id !== id)
646
+ .map((i) => (i.dependsOn?.includes(id) ? { ...i, dependsOn: i.dependsOn.filter((d) => d !== id) } : i));
647
+ emit(next, { item: entry.item, previous: entry.item, change: "delete", source });
648
+ announce(text.deleted(entry.item.title));
649
+ closeEditor();
650
+ if (neighbour) {
651
+ setActiveId(neighbour);
652
+ if (source !== "pointer")
653
+ reveal.current = neighbour;
654
+ }
655
+ };
656
+ /** Whether `to` waits, through any chain, for `from`'s own waits: a link from→to would loop. */
657
+ const loops = (from, to) => {
658
+ const seen = new Set();
659
+ const walk = (id) => {
660
+ if (id === to)
661
+ return true;
662
+ if (seen.has(id))
663
+ return false;
664
+ seen.add(id);
665
+ return (modelRef.current.entries.get(id)?.item.dependsOn ?? []).some(walk);
666
+ };
667
+ return walk(from);
668
+ };
669
+ /** `to` waits for `from` (`on`), or no longer does. */
670
+ const setDependency = (from, to, on, source) => {
671
+ const a = modelRef.current.entries.get(from);
672
+ const b = modelRef.current.entries.get(to);
673
+ if (!a || !b || from === to)
674
+ return;
675
+ const had = b.item.dependsOn?.includes(from) ?? false;
676
+ if (had === on || (on && loops(from, to)))
677
+ return;
678
+ const previous = b.item;
679
+ const dependsOn = on
680
+ ? [...(previous.dependsOn ?? []), from]
681
+ : (previous.dependsOn ?? []).filter((d) => d !== from);
682
+ const item = { ...previous, dependsOn };
683
+ emit(itemsRef.current.map((i) => (i.id === to ? item : i)), { item, previous, change: "dependency", source });
684
+ announce((on ? text.linked : text.unlinked)(a.item.title, b.item.title));
685
+ setSelectedLink(null);
686
+ };
687
+ /** A bar's menu: edit it, the tasks it waits for, delete it. */
688
+ const itemMenu = (id, anchor, returnFocus, first = []) => {
689
+ const entry = modelRef.current.entries.get(id);
690
+ if (!entry || !editable(entry))
691
+ return false;
692
+ const entries = [...first, { label: text.edit, onSelect: () => open(id) }];
693
+ if (linking) {
694
+ const waits = new Set(entry.item.dependsOn ?? []);
695
+ entries.push({
696
+ label: text.dependsOn,
697
+ options: modelRef.current.order
698
+ .filter((other) => other !== id && (waits.has(other) || !loops(other, id)))
699
+ .map((other) => ({
700
+ label: modelRef.current.entries.get(other).item.title,
701
+ checked: waits.has(other),
702
+ onToggle: () => setDependency(other, id, !waits.has(other), "keyboard"),
703
+ })),
704
+ });
705
+ }
706
+ entries.push("separator", {
707
+ label: text.delete,
708
+ destructive: true,
709
+ onSelect: () => deleteItem(id, "keyboard"),
710
+ });
711
+ setMenu({ anchor, label: text.itemMenu(entry.item.title), entries, returnFocus });
712
+ return true;
713
+ };
714
+ /* ── Rows ───────────────────────────────────────────────────────────────── */
715
+ /** A new task (in `group`, or the last phase) from today for three days, named next. */
716
+ const addTask = (group) => {
717
+ const groups = modelRef.current.display.filter((d) => d.kind === "group");
718
+ const phase = group ?? (groups.length ? groups[groups.length - 1].title : undefined);
719
+ const vp = viewportRef.current;
720
+ const middle = vp
721
+ ? range.start + (getInline(vp, rtlRef.current) + (vp.clientWidth - listW()) / 3) / ppm
722
+ : todayWall;
723
+ const from = startOfDay(todayWall >= range.start && todayWall < range.end ? todayWall : middle);
724
+ const id = createId();
725
+ const item = {
726
+ id,
727
+ title: text.newTask,
728
+ start: fromWall(from),
729
+ end: fromWall(from + 3 * DAY),
730
+ ...(phase !== undefined ? { group: phase } : null),
731
+ };
732
+ // After the phase's last task, so it is listed there.
733
+ const list = [...itemsRef.current];
734
+ let at = list.length;
735
+ if (phase !== undefined)
736
+ for (let i = list.length - 1; i >= 0; i--)
737
+ if (list[i].group === phase) {
738
+ at = i + 1;
739
+ break;
740
+ }
741
+ list.splice(at, 0, item);
742
+ emit(list, { item, previous: item, change: "create", source: "pointer" });
743
+ announce(text.created(item.title, whenOf(item)));
744
+ setActiveId(id);
745
+ setRenaming(id);
746
+ };
747
+ const addRow = () => {
748
+ if (!rows || !onRowsChange)
749
+ return;
750
+ const row = { id: createId(), title: text.newRow };
751
+ onRowsChange([...rows, row], { row, change: "create" });
752
+ announce(text.rowAdded(row.title));
753
+ setRenaming(row.id);
754
+ };
755
+ /** A row's (or a task's) new name. */
756
+ const rename = (id, title, refocus) => {
757
+ setRenaming(null);
758
+ // Done from the keyboard, focus goes on: to the task's bar, or back to the list's add button.
759
+ if (refocus && layout === "gantt")
760
+ reveal.current = id;
761
+ else if (refocus)
762
+ requestAnimationFrame(() => rootRef.current
763
+ ?.querySelector("[data-slot=scheduler-add]")
764
+ ?.focus({ preventScroll: true }));
765
+ if (title === null)
766
+ return;
767
+ const name = title.trim();
768
+ if (layout === "gantt") {
769
+ const entry = modelRef.current.entries.get(id);
770
+ if (!entry || !name || name === entry.item.title)
771
+ return;
772
+ const item = { ...entry.item, title: name };
773
+ emit(itemsRef.current.map((i) => (i.id === id ? item : i)), { item, previous: entry.item, change: "edit", source: "keyboard" });
774
+ return;
775
+ }
776
+ const row = rows?.find((r) => r.id === id);
777
+ if (!row || !rows || !onRowsChange || !name || name === row.title)
778
+ return;
779
+ const next = { ...row, title: name };
780
+ onRowsChange(rows.map((r) => (r.id === id ? next : r)), { row: next, change: "edit" });
781
+ };
782
+ /** A resource's row goes, and the bookings in it. */
783
+ const deleteRow = (id) => {
784
+ const row = rows?.find((r) => r.id === id);
785
+ if (!row || !rows || !onRowsChange)
786
+ return;
787
+ onRowsChange(rows.filter((r) => r.id !== id), { row, change: "delete" });
788
+ let left = itemsRef.current;
789
+ for (const item of itemsRef.current.filter((i) => i.row === id)) {
790
+ left = left.filter((i) => i.id !== item.id);
791
+ emit(left, { item, previous: item, change: "delete", source: "pointer" });
792
+ }
793
+ announce(text.rowDeleted(row.title));
794
+ };
795
+ /** A row's menu, from its button in the list. */
796
+ const rowMenu = (id, button) => {
797
+ const rename = { label: text.rename, onSelect: () => setRenaming(id) };
798
+ // A task's row has its bar's menu too: edit it, the tasks it waits for, delete it.
799
+ if (layout === "gantt")
800
+ return void itemMenu(id, button, button, [rename]);
801
+ const title = rows?.find((r) => r.id === id)?.title ?? "";
802
+ setMenu({
803
+ anchor: button,
804
+ label: text.rowActions(title),
805
+ returnFocus: button,
806
+ entries: [
807
+ rename,
808
+ "separator",
809
+ { label: text.delete, destructive: true, onSelect: () => deleteRow(id) },
810
+ ],
811
+ });
812
+ };
813
+ /** After a keyboard step, bring the active bar into view and keep focus on it. */
814
+ const reveal = React.useRef(null);
815
+ React.useLayoutEffect(() => {
816
+ const id = reveal.current;
817
+ if (!id)
818
+ return;
819
+ reveal.current = null;
820
+ const el = barEl(id);
821
+ if (!el)
822
+ return;
823
+ if (document.activeElement !== el)
824
+ el.focus({ preventScroll: true });
825
+ el.scrollIntoView?.({ block: "nearest", inline: "nearest" });
826
+ });
827
+ const barEl = (id) => canvasRef.current?.querySelector(`[data-slot=scheduler-item][data-id="${CSS.escape(id)}"]`) ?? null;
828
+ const onKeyDown = (event) => {
829
+ const el = event.target.closest("[data-slot=scheduler-item]");
830
+ const id = el?.dataset.id;
831
+ const entry = id ? model.entries.get(id) : undefined;
832
+ if (!entry || !id || draggingId)
833
+ return;
834
+ if (editable(entry) && (event.key === "Delete" || event.key === "Backspace")) {
835
+ event.preventDefault();
836
+ return deleteItem(id, "keyboard");
837
+ }
838
+ const locked = readOnly || !!entry.item.disabled;
839
+ const action = keyAction(event, { rtl, rows: layout === "resource", locked, milestone: entry.milestone });
840
+ if (!action)
841
+ return;
842
+ event.preventDefault();
843
+ const name = entry.item.title;
844
+ if (action.type === "open")
845
+ return open(id);
846
+ if (action.type === "focus") {
847
+ const order = model.order;
848
+ const at = order.indexOf(id);
849
+ const next = action.by === "first"
850
+ ? order[0]
851
+ : action.by === "last"
852
+ ? order[order.length - 1]
853
+ : order[clamp(at + action.by, 0, order.length - 1)];
854
+ if (next && next !== id) {
855
+ setActiveId(next);
856
+ reveal.current = next;
857
+ }
858
+ return;
859
+ }
860
+ if (action.type === "row") {
861
+ let row = entry.row;
862
+ do
863
+ row += action.by;
864
+ while (model.display[row] && model.display[row].kind !== "row");
865
+ if (!model.display[row])
866
+ return;
867
+ commit(entry, entry.span, row, "row", "keyboard");
868
+ announce(text.movedRow(name, rowTitle(row), describe(entry, entry.span)));
869
+ reveal.current = id;
870
+ return;
871
+ }
872
+ const delta = action.units * scale.unit;
873
+ const change = action.type === "move" ? "move" : action.edge;
874
+ const span = changeSpan(entry.span, change, delta, scale.unit);
875
+ if (!commit(entry, span, entry.row, change, "keyboard"))
876
+ return announce(text.unchanged(name, describe(entry, entry.span)));
877
+ announce((change === "move" ? text.moved : text.resized)(name, describe(entry, span)));
878
+ reveal.current = id;
879
+ };
880
+ /* ── Dragging ────────────────────────────────────────────────────────────── */
881
+ const dragCleanup = React.useRef(null);
882
+ React.useEffect(() => () => dragCleanup.current?.(), []);
883
+ const linkPath = (a, b) => {
884
+ const bar = metrics.bar;
885
+ const down = b.y >= a.y;
886
+ // Out of the bar just inside its end, straight down (or up) to the waiting bar's middle, and
887
+ // into its start: clear of a name written after the bar. Around it when it starts earlier.
888
+ const x1 = a.x + a.w - Math.min(10, a.w / 2);
889
+ const y1 = down ? a.y + bar : a.y;
890
+ const x2 = b.x;
891
+ const y2 = b.y + bar / 2;
892
+ if (x2 - 8 >= x1)
893
+ return roundedPath([
894
+ [x1, y1],
895
+ [x1, y2],
896
+ [x2 - 1, y2],
897
+ ]);
898
+ const between = down ? b.y - 5 : b.y + bar + 5;
899
+ return roundedPath([
900
+ [x1, y1],
901
+ [x1, between],
902
+ [x2 - 10, between],
903
+ [x2 - 10, y2],
904
+ [x2 - 1, y2],
905
+ ]);
906
+ };
907
+ /** A point of the window on the timeline, from its inline start. */
908
+ const timelinePoint = (x, y) => {
909
+ const rect = canvasRef.current.getBoundingClientRect();
910
+ return { x: rtl ? rect.right - x : x - rect.left, y: y - rect.top };
911
+ };
912
+ /** The unit of the zoom that holds `t`. */
913
+ const floorUnit = (t) => Math.floor(t / scale.unit) * scale.unit;
914
+ /** Over empty space in a resource row: draw a new booking, snapping to the zoom's unit. */
915
+ const startDraw = (event) => {
916
+ if (!canvasRef.current || dragCleanup.current)
917
+ return;
918
+ const p0 = timelinePoint(event.clientX, event.clientY);
919
+ if (p0.y < 0 || p0.y >= totalHeight)
920
+ return;
921
+ const row = rowAt(model.offsets, p0.y);
922
+ if (model.display[row]?.kind !== "row")
923
+ return;
924
+ const touch = event.pointerType === "touch";
925
+ if (!touch)
926
+ event.preventDefault();
927
+ const t0 = range.start + p0.x / ppm;
928
+ const startX = event.clientX;
929
+ const startY = event.clientY;
930
+ let pointer = { x: startX, y: startY };
931
+ let travelled = 0;
932
+ let active = false;
933
+ let timer = 0;
934
+ let span = { start: floorUnit(t0), end: floorUnit(t0) + scale.unit };
935
+ const compute = () => {
936
+ const t = range.start + timelinePoint(pointer.x, pointer.y).x / ppm;
937
+ return { start: floorUnit(Math.min(t, t0)), end: floorUnit(Math.max(t, t0)) + scale.unit };
938
+ };
939
+ const begin = () => {
940
+ active = true;
941
+ document.body.style.userSelect = "none";
942
+ document.body.style.cursor = "ew-resize";
943
+ span = compute();
944
+ setDrawing({ row, span });
945
+ if (touch)
946
+ navigator.vibrate?.(10);
947
+ };
948
+ const detach = () => {
949
+ clearTimeout(timer);
950
+ window.removeEventListener("pointermove", onMove);
951
+ window.removeEventListener("pointerup", onUp);
952
+ window.removeEventListener("pointercancel", onCancel);
953
+ window.removeEventListener("touchmove", onTouchMove);
954
+ window.removeEventListener("keydown", onKey, true);
955
+ window.removeEventListener("contextmenu", onContextMenu, true);
956
+ document.body.style.userSelect = "";
957
+ document.body.style.cursor = "";
958
+ dragCleanup.current = null;
959
+ };
960
+ const end = (drop) => {
961
+ const was = active;
962
+ detach();
963
+ setDrawing(null);
964
+ if (!was || !drop)
965
+ return;
966
+ // A long press let go where it began is a touch's right click: the slot's menu.
967
+ if (touch && travelled < TOUCH_SLOP)
968
+ return slotMenu(row, t0, pointer);
969
+ create(row, span);
970
+ };
971
+ const onMove = (e) => {
972
+ if (e.pointerId !== event.pointerId)
973
+ return;
974
+ if (e.pointerType === "mouse" && e.buttons === 0)
975
+ return end(false);
976
+ pointer = { x: e.clientX, y: e.clientY };
977
+ const moved = Math.hypot(pointer.x - startX, pointer.y - startY);
978
+ travelled = Math.max(travelled, moved);
979
+ if (active) {
980
+ const next = compute();
981
+ if (next.start !== span.start || next.end !== span.end) {
982
+ span = next;
983
+ setDrawing({ row, span });
984
+ }
985
+ return;
986
+ }
987
+ if (touch) {
988
+ if (moved > TOUCH_SLOP)
989
+ detach(); // a scroll, not a drag
990
+ return;
991
+ }
992
+ if (moved >= DRAG_THRESHOLD)
993
+ begin();
994
+ };
995
+ // A click on empty space does nothing: a booking is drawn, or made from the slot's menu.
996
+ const onUp = (e) => {
997
+ if (e.pointerId === event.pointerId)
998
+ end(true);
999
+ };
1000
+ const onCancel = (e) => {
1001
+ if (e.pointerId === event.pointerId)
1002
+ end(false);
1003
+ };
1004
+ const onTouchMove = (e) => {
1005
+ if (active && e.cancelable)
1006
+ e.preventDefault();
1007
+ };
1008
+ const onContextMenu = (e) => {
1009
+ if (touch)
1010
+ e.preventDefault();
1011
+ };
1012
+ const onKey = (e) => {
1013
+ if (e.key !== "Escape" || !active)
1014
+ return;
1015
+ e.preventDefault();
1016
+ e.stopPropagation();
1017
+ end(false);
1018
+ };
1019
+ window.addEventListener("pointermove", onMove);
1020
+ window.addEventListener("pointerup", onUp);
1021
+ window.addEventListener("pointercancel", onCancel);
1022
+ window.addEventListener("touchmove", onTouchMove, { passive: false });
1023
+ window.addEventListener("keydown", onKey, true);
1024
+ window.addEventListener("contextmenu", onContextMenu, true);
1025
+ dragCleanup.current = () => end(false);
1026
+ if (touch)
1027
+ timer = window.setTimeout(begin, LONG_PRESS);
1028
+ };
1029
+ /** The menu of an empty slot in a resource row: a new booking there. */
1030
+ const slotMenu = (row, t, at) => {
1031
+ const start = floorUnit(t);
1032
+ setMenu({
1033
+ anchor: at,
1034
+ label: text.slotMenu,
1035
+ entries: [
1036
+ { label: text.newBookingHere, onSelect: () => create(row, { start, end: start + scale.unit }) },
1037
+ ],
1038
+ });
1039
+ };
1040
+ /**
1041
+ * From a bar's connector to another bar: the other waits for this one. A dashed line follows the
1042
+ * pointer, every bar it may be drawn to is marked (a loop may not), the one under the pointer
1043
+ * takes the focus ring, and held near an edge the timeline scrolls.
1044
+ */
1045
+ const startLink = (event, from) => {
1046
+ const a = model.entries.get(from);
1047
+ const path = linkDraftRef.current;
1048
+ const canvas = canvasRef.current;
1049
+ if (!a || !path || !canvas || dragCleanup.current)
1050
+ return;
1051
+ event.preventDefault();
1052
+ event.stopPropagation();
1053
+ const ga = geometry(a);
1054
+ const x1 = ga.x + ga.w;
1055
+ const y1 = ga.y + metrics.bar / 2;
1056
+ const source = event.target.closest("[data-slot=scheduler-item]");
1057
+ source?.setAttribute("data-linking", "");
1058
+ let target = null;
1059
+ let pointer = { x: event.clientX, y: event.clientY };
1060
+ let frame = 0;
1061
+ let last = 0;
1062
+ const scrollers = scrollersOf(canvas);
1063
+ const valid = (id) => !!id && id !== from && !loops(from, id);
1064
+ const bars = () => canvas.querySelectorAll("[data-slot=scheduler-item]");
1065
+ // Bars scrolled into view mid-drag are marked as they come.
1066
+ const markCandidates = () => {
1067
+ for (const bar of bars())
1068
+ if (bar !== target && valid(bar.dataset.id))
1069
+ bar.setAttribute("data-link-candidate", "");
1070
+ };
1071
+ const mark = (el) => {
1072
+ if (el === target)
1073
+ return;
1074
+ if (target) {
1075
+ target.removeAttribute("data-link-target");
1076
+ target.setAttribute("data-link-candidate", "");
1077
+ }
1078
+ target = el;
1079
+ target?.removeAttribute("data-link-candidate");
1080
+ target?.setAttribute("data-link-target", "");
1081
+ };
1082
+ const draw = () => {
1083
+ const p = timelinePoint(pointer.x, pointer.y);
1084
+ path.style.display = "";
1085
+ path.setAttribute("d", `M${x1} ${y1}L${p.x} ${p.y}`);
1086
+ const over = document
1087
+ .elementFromPoint(pointer.x, pointer.y)
1088
+ ?.closest("[data-slot=scheduler-item]");
1089
+ mark(over && valid(over.dataset.id) ? over : null);
1090
+ };
1091
+ const tick = (time) => {
1092
+ const dt = last ? Math.min(time - last, 32) : 16;
1093
+ last = time;
1094
+ autoScroll(scrollers, pointer.x, pointer.y, dt, { top: 2 * metrics.lane, start: listW() });
1095
+ markCandidates();
1096
+ draw();
1097
+ frame = requestAnimationFrame(tick);
1098
+ };
1099
+ const onMove = (e) => {
1100
+ if (e.pointerId !== event.pointerId)
1101
+ return;
1102
+ pointer = { x: e.clientX, y: e.clientY };
1103
+ draw();
1104
+ };
1105
+ const detach = () => {
1106
+ cancelAnimationFrame(frame);
1107
+ window.removeEventListener("pointermove", onMove);
1108
+ window.removeEventListener("pointerup", onUp);
1109
+ window.removeEventListener("pointercancel", onCancel);
1110
+ window.removeEventListener("keydown", onKey, true);
1111
+ document.body.style.userSelect = "";
1112
+ document.body.style.cursor = "";
1113
+ path.style.display = "none";
1114
+ source?.removeAttribute("data-linking");
1115
+ for (const bar of bars())
1116
+ bar.removeAttribute("data-link-candidate");
1117
+ dragCleanup.current = null;
1118
+ };
1119
+ const end = (drop) => {
1120
+ const to = target?.dataset.id;
1121
+ mark(null);
1122
+ detach();
1123
+ if (drop && to)
1124
+ setDependency(from, to, true, "pointer");
1125
+ };
1126
+ const onUp = (e) => {
1127
+ if (e.pointerId === event.pointerId)
1128
+ end(true);
1129
+ };
1130
+ const onCancel = (e) => {
1131
+ if (e.pointerId === event.pointerId)
1132
+ end(false);
1133
+ };
1134
+ const onKey = (e) => {
1135
+ if (e.key !== "Escape")
1136
+ return;
1137
+ e.preventDefault();
1138
+ e.stopPropagation();
1139
+ end(false);
1140
+ };
1141
+ document.body.style.userSelect = "none";
1142
+ document.body.style.cursor = "crosshair";
1143
+ window.addEventListener("pointermove", onMove);
1144
+ window.addEventListener("pointerup", onUp);
1145
+ window.addEventListener("pointercancel", onCancel);
1146
+ window.addEventListener("keydown", onKey, true);
1147
+ dragCleanup.current = () => end(false);
1148
+ markCandidates();
1149
+ frame = requestAnimationFrame(tick);
1150
+ };
1151
+ /** A right click (or the menu key): a bar's menu, or an empty slot's. */
1152
+ const onContextMenu = (event) => {
1153
+ if (dragCleanup.current || loading)
1154
+ return;
1155
+ const native = event.nativeEvent;
1156
+ if (native.pointerType === "touch")
1157
+ return;
1158
+ const target = event.target;
1159
+ if (target.closest("button"))
1160
+ return;
1161
+ const point = { x: event.clientX, y: event.clientY };
1162
+ const el = target.closest("[data-slot=scheduler-item]");
1163
+ if (el) {
1164
+ const r = el.getBoundingClientRect();
1165
+ // From the keyboard the point is wherever the browser puts it: open beside the bar.
1166
+ const inside = point.x >= r.left - 1 && point.x <= r.right + 1 && point.y >= r.top - 1 && point.y <= r.bottom + 1;
1167
+ if (el.dataset.id && itemMenu(el.dataset.id, inside ? point : el, el))
1168
+ event.preventDefault();
1169
+ return;
1170
+ }
1171
+ if (!canCreate)
1172
+ return;
1173
+ const p = timelinePoint(point.x, point.y);
1174
+ if (p.y < 0 || p.y >= totalHeight)
1175
+ return;
1176
+ const row = rowAt(model.offsets, p.y);
1177
+ if (model.display[row]?.kind !== "row")
1178
+ return;
1179
+ event.preventDefault();
1180
+ slotMenu(row, range.start + p.x / ppm, point);
1181
+ };
1182
+ const onPointerDown = (event) => {
1183
+ if (event.pointerType === "mouse" && event.button !== 0)
1184
+ return;
1185
+ const target = event.target;
1186
+ // A day's "+2" opens its own list.
1187
+ if (target.closest("button"))
1188
+ return;
1189
+ if (selectedLink)
1190
+ setSelectedLink(null);
1191
+ const connector = target.closest("[data-slot=scheduler-item-connector]");
1192
+ if (connector && linking) {
1193
+ const from = connector.closest("[data-slot=scheduler-item]")?.dataset.id;
1194
+ if (from)
1195
+ return startLink(event, from);
1196
+ }
1197
+ const el = target.closest("[data-slot=scheduler-item]");
1198
+ if (!el && canCreate)
1199
+ return startDraw(event);
1200
+ const id = el?.dataset.id;
1201
+ const entry = id ? model.entries.get(id) : undefined;
1202
+ const canvas = canvasRef.current;
1203
+ const vp = viewportRef.current;
1204
+ if (!el || !id || !entry || !canvas || !vp || dragCleanup.current)
1205
+ return;
1206
+ if (activeId !== id)
1207
+ setActiveId(id);
1208
+ const touch = event.pointerType === "touch";
1209
+ if (!touch) {
1210
+ // No text selection, and focus without a scroll jump.
1211
+ event.preventDefault();
1212
+ el.focus({ preventScroll: true });
1213
+ }
1214
+ const editable = !readOnly && !entry.item.disabled;
1215
+ const edge = target.closest("[data-slot=scheduler-item-handle]")?.dataset.edge;
1216
+ const change = edge === "start" ? "start" : edge === "end" ? "end" : "move";
1217
+ const vertical = layout === "resource" && change === "move";
1218
+ const origin = geometry(entry);
1219
+ const canvasPoint = (x, y) => {
1220
+ const rect = canvas.getBoundingClientRect();
1221
+ return { x: rtl ? rect.right - x : x - rect.left, y: y - rect.top };
1222
+ };
1223
+ const start = canvasPoint(event.clientX, event.clientY);
1224
+ const startX = event.clientX;
1225
+ const startY = event.clientY;
1226
+ let pointer = { x: startX, y: startY };
1227
+ let active = false;
1228
+ let span = entry.span;
1229
+ let row = entry.row;
1230
+ let frame = 0;
1231
+ let last = 0;
1232
+ let timer = 0;
1233
+ let scrollers = [];
1234
+ const links = model.links.filter((l) => l.from === id || l.to === id);
1235
+ const draw = () => {
1236
+ const now = canvasPoint(pointer.x, pointer.y);
1237
+ span = changeSpan(entry.span, change, snapDelta(now.x - start.x, scale), scale.unit);
1238
+ const shownSpan = wholeDays && !entry.milestone ? daysOf(span) : span;
1239
+ if (vertical) {
1240
+ const offsets = modelRef.current.offsets;
1241
+ let at = rowAt(offsets, clamp(now.y, 0, (offsets[offsets.length - 1] ?? 1) - 1));
1242
+ if (model.display[at]?.kind !== "row")
1243
+ at = row;
1244
+ row = at;
1245
+ }
1246
+ const g = geometry(entry, shownSpan);
1247
+ const y = vertical
1248
+ ? clamp(now.y - (start.y - origin.y), 0, Math.max(totalHeight - metrics.bar, 0))
1249
+ : g.y;
1250
+ el.style.transform = `translate(${rtl ? -g.x : g.x}px, ${y}px)`;
1251
+ el.style.width = `${g.w}px`;
1252
+ const highlight = highlightRef.current;
1253
+ if (highlight && vertical) {
1254
+ highlight.hidden = false;
1255
+ highlight.style.transform = `translateY(${model.offsets[row] ?? 0}px)`;
1256
+ highlight.style.height = `${(model.offsets[row + 1] ?? 0) - (model.offsets[row] ?? 0)}px`;
1257
+ }
1258
+ const readout = readoutRef.current;
1259
+ if (readout) {
1260
+ readout.hidden = false;
1261
+ readout.textContent = describe(entry, span);
1262
+ // Above the bar, or under it in the first row.
1263
+ const above = y - metrics.lane >= 0 ? y - metrics.lane : y + metrics.bar + 4;
1264
+ readout.style.transform = `translate(${rtl ? -g.x : g.x}px, ${above}px)`;
1265
+ }
1266
+ for (const link of links) {
1267
+ const path = linkRefs.current.get(`${link.from}>${link.to}`);
1268
+ const a = model.entries.get(link.from);
1269
+ const b = model.entries.get(link.to);
1270
+ if (!path || !a || !b)
1271
+ continue;
1272
+ const ga = link.from === id ? { ...g, y } : geometry(a);
1273
+ const gb = link.to === id ? { ...g, y } : geometry(b);
1274
+ path.setAttribute("d", linkPath(ga, gb));
1275
+ }
1276
+ };
1277
+ const tick = (time) => {
1278
+ const dt = last ? Math.min(time - last, 32) : 16;
1279
+ last = time;
1280
+ autoScroll(scrollers, pointer.x, pointer.y, dt, { top: 2 * metrics.lane, start: listW() });
1281
+ draw();
1282
+ frame = requestAnimationFrame(tick);
1283
+ };
1284
+ const restore = () => {
1285
+ const g = geometry(entry);
1286
+ el.style.transform = `translate(${rtl ? -g.x : g.x}px, ${g.y}px)`;
1287
+ el.style.width = `${g.w}px`;
1288
+ if (highlightRef.current)
1289
+ highlightRef.current.hidden = true;
1290
+ if (readoutRef.current)
1291
+ readoutRef.current.hidden = true;
1292
+ for (const link of links) {
1293
+ const path = linkRefs.current.get(`${link.from}>${link.to}`);
1294
+ const a = model.entries.get(link.from);
1295
+ const b = model.entries.get(link.to);
1296
+ if (path && a && b)
1297
+ path.setAttribute("d", linkPath(geometry(a), geometry(b)));
1298
+ }
1299
+ };
1300
+ const begin = () => {
1301
+ active = true;
1302
+ scrollers = scrollersOf(canvas);
1303
+ document.body.style.userSelect = "none";
1304
+ document.body.style.cursor = change === "move" ? "grabbing" : "ew-resize";
1305
+ setDraggingId(id);
1306
+ announce(text.pickedUp(entry.item.title, describe(entry, entry.span)));
1307
+ if (touch)
1308
+ navigator.vibrate?.(10);
1309
+ frame = requestAnimationFrame(tick);
1310
+ };
1311
+ const detach = () => {
1312
+ clearTimeout(timer);
1313
+ cancelAnimationFrame(frame);
1314
+ window.removeEventListener("pointermove", onMove);
1315
+ window.removeEventListener("pointerup", onUp);
1316
+ window.removeEventListener("pointercancel", onCancel);
1317
+ window.removeEventListener("touchmove", onTouchMove);
1318
+ window.removeEventListener("keydown", onKey, true);
1319
+ window.removeEventListener("contextmenu", onContextMenu, true);
1320
+ document.body.style.userSelect = "";
1321
+ document.body.style.cursor = "";
1322
+ dragCleanup.current = null;
1323
+ };
1324
+ const end = (drop) => {
1325
+ const was = active;
1326
+ detach();
1327
+ if (!was)
1328
+ return;
1329
+ setDraggingId(null);
1330
+ draw();
1331
+ restore();
1332
+ const name = entry.item.title;
1333
+ if (!drop)
1334
+ return announce(text.cancelled(name, describe(entry, entry.span)));
1335
+ const rowChanged = row !== entry.row;
1336
+ if (!commit(entry, span, row, change, "pointer"))
1337
+ return announce(text.unchanged(name, describe(entry, entry.span)));
1338
+ if (rowChanged)
1339
+ announce(text.movedRow(name, rowTitle(row), describe(entry, span)));
1340
+ else
1341
+ announce((change === "move" ? text.moved : text.resized)(name, describe(entry, span)));
1342
+ };
1343
+ const onMove = (e) => {
1344
+ if (e.pointerId !== event.pointerId)
1345
+ return;
1346
+ if (e.pointerType === "mouse" && e.buttons === 0)
1347
+ return end(false);
1348
+ pointer = { x: e.clientX, y: e.clientY };
1349
+ if (active)
1350
+ return;
1351
+ const moved = Math.hypot(pointer.x - startX, pointer.y - startY);
1352
+ if (touch) {
1353
+ if (moved > TOUCH_SLOP)
1354
+ detach(); // a scroll, not a drag
1355
+ return;
1356
+ }
1357
+ if (moved >= DRAG_THRESHOLD) {
1358
+ if (editable)
1359
+ begin();
1360
+ else
1361
+ detach();
1362
+ }
1363
+ };
1364
+ const onUp = (e) => {
1365
+ if (e.pointerId !== event.pointerId)
1366
+ return;
1367
+ pointer = { x: e.clientX, y: e.clientY };
1368
+ if (!active) {
1369
+ detach();
1370
+ // A click or a tap that never became a drag opens the item.
1371
+ if (Math.hypot(pointer.x - startX, pointer.y - startY) < (touch ? TOUCH_SLOP : DRAG_THRESHOLD))
1372
+ open(id);
1373
+ return;
1374
+ }
1375
+ end(true);
1376
+ };
1377
+ const onCancel = (e) => {
1378
+ if (e.pointerId === event.pointerId)
1379
+ end(false);
1380
+ };
1381
+ // Once a touch drag has started, the finger moves the bar and not the page.
1382
+ const onTouchMove = (e) => {
1383
+ if (active && e.cancelable)
1384
+ e.preventDefault();
1385
+ };
1386
+ const onContextMenu = (e) => {
1387
+ if (touch)
1388
+ e.preventDefault();
1389
+ };
1390
+ const onKey = (e) => {
1391
+ if (e.key !== "Escape" || !active)
1392
+ return;
1393
+ e.preventDefault();
1394
+ e.stopPropagation();
1395
+ end(false);
1396
+ };
1397
+ window.addEventListener("pointermove", onMove);
1398
+ window.addEventListener("pointerup", onUp);
1399
+ window.addEventListener("pointercancel", onCancel);
1400
+ window.addEventListener("touchmove", onTouchMove, { passive: false });
1401
+ window.addEventListener("keydown", onKey, true);
1402
+ window.addEventListener("contextmenu", onContextMenu, true);
1403
+ dragCleanup.current = () => end(false);
1404
+ if (touch && editable)
1405
+ timer = window.setTimeout(begin, LONG_PRESS);
1406
+ };
1407
+ /* ── The list's width ───────────────────────────────────────────────────── */
1408
+ const onHandlePointerDown = (event) => {
1409
+ if (event.pointerType === "mouse" && event.button !== 0)
1410
+ return;
1411
+ event.preventDefault();
1412
+ const handle = event.currentTarget;
1413
+ handle.setPointerCapture?.(event.pointerId);
1414
+ const from = listW();
1415
+ const x0 = event.clientX;
1416
+ const move = (e) => setListWidth(clamp(from + (rtl ? x0 - e.clientX : e.clientX - x0), MIN_GRID, MAX_GRID));
1417
+ const up = () => {
1418
+ handle.removeEventListener("pointermove", move);
1419
+ handle.removeEventListener("pointerup", up);
1420
+ handle.removeEventListener("pointercancel", up);
1421
+ handle.removeAttribute("data-dragging");
1422
+ };
1423
+ handle.setAttribute("data-dragging", "");
1424
+ handle.addEventListener("pointermove", move);
1425
+ handle.addEventListener("pointerup", up);
1426
+ handle.addEventListener("pointercancel", up);
1427
+ };
1428
+ const onHandleKeyDown = (event) => {
1429
+ const step = event.shiftKey ? 64 : 16;
1430
+ const forward = event.key === (rtl ? "ArrowLeft" : "ArrowRight");
1431
+ const back = event.key === (rtl ? "ArrowRight" : "ArrowLeft");
1432
+ let next = null;
1433
+ if (forward)
1434
+ next = listW() + step;
1435
+ else if (back)
1436
+ next = listW() - step;
1437
+ else if (event.key === "Home")
1438
+ next = MIN_GRID;
1439
+ else if (event.key === "End")
1440
+ next = MAX_GRID;
1441
+ if (next === null)
1442
+ return;
1443
+ event.preventDefault();
1444
+ setListWidth(clamp(next, MIN_GRID, MAX_GRID));
1445
+ };
1446
+ /* ── What is drawn ───────────────────────────────────────────────────────── */
1447
+ const [first, last] = visibleRows(model.offsets, view.top, view.height);
1448
+ const shown = new Set();
1449
+ for (let i = first; i <= last; i++)
1450
+ shown.add(i);
1451
+ const activeOrFirst = activeId && model.entries.has(activeId) ? activeId : model.order[0];
1452
+ // The bar in the tab order, the open one and the dragged one stay drawn wherever the view is.
1453
+ for (const id of [activeOrFirst, openId, draggingId])
1454
+ if (id && model.entries.has(id))
1455
+ shown.add(model.entries.get(id).row);
1456
+ const shownRows = [...shown].sort((a, b) => a - b);
1457
+ const fromX = view.left - 400;
1458
+ const toX = view.left + view.width + 400;
1459
+ const windowSpan = { start: range.start + fromX / ppm, end: range.start + toX / ppm };
1460
+ const majorTicks = axisTicks(scale.major, range, weekStartsOn, windowSpan.start, windowSpan.end);
1461
+ const minorTicks = axisTicks(scale.minor, range, weekStartsOn, windowSpan.start, windowSpan.end);
1462
+ const weekends = weekendRuns(range, week.weekend).filter((r) => r.end > windowSpan.start && r.start < windowSpan.end);
1463
+ const majorLabel = (t) => {
1464
+ if (scale.major === "day")
1465
+ return fmt.dayLong.format(t.start);
1466
+ if (scale.major === "week")
1467
+ return `${text.weekNumber(isoWeek(t.start))} · ${formatRange(fmt.dayShort, t.start, t.end - DAY)}`;
1468
+ return fmt.month.format(t.start);
1469
+ };
1470
+ const minorLabel = (t) => {
1471
+ if (scale.minor === "hour")
1472
+ return fmt.hour.format(t.start);
1473
+ // One month across: only the day's number fits.
1474
+ if (scale.minor === "day" && zoom === "month")
1475
+ return fmt.dayNumber.format(t.start);
1476
+ if (scale.minor === "day")
1477
+ return `${fmt.weekday.format(t.start)} ${fmt.dayNumber.format(t.start)}`;
1478
+ return fmt.dayShort.format(t.start);
1479
+ };
1480
+ const isToday = (t) => todayWall >= t.start && todayWall < t.end;
1481
+ const openEntry = openId ? model.entries.get(openId) : undefined;
1482
+ const isEmpty = !loading && model.rowCount === 0;
1483
+ const head = 2 * metrics.lane;
1484
+ const role = layout === "gantt" ? text.taskRole : text.bookingRole;
1485
+ const instructions = readOnly
1486
+ ? text.instructionsReadOnly
1487
+ : layout === "resource"
1488
+ ? text.instructionsRows
1489
+ : text.instructions;
1490
+ const columnHeader = layout === "gantt" ? text.taskColumn : text.resourceColumn;
1491
+ const extraColumns = narrow ? [] : columns;
1492
+ const placeholderRows = 6;
1493
+ const activeRow = activeId ? model.entries.get(activeId)?.row : undefined;
1494
+ const todayIn = todayWall >= range.start && todayWall < range.end;
1495
+ // The grid's lines and shading reach the bottom of the frame, even with few rows.
1496
+ const bodyHeight = Math.max(totalHeight, view.height - head, 0);
1497
+ return (_jsxs("div", { ref: rootRef, "data-slot": "scheduler", "data-layout": layout, "data-zoom": zoom, "data-size": size, "data-variant": variant, "data-readonly": readOnly ? "" : undefined, "data-dragging": draggingId ? "" : undefined, "data-narrow": narrow ? "" : undefined, "data-empty": isEmpty ? "" : undefined, role: "group", "aria-busy": loading || undefined, className: cn("@container/scheduler relative flex h-[min(36rem,80svh)] w-full min-w-0 flex-col overflow-hidden font-body", variant === "card" ? "surface-card [--card-padding:0]" : "surface-container", className), style: {
1498
+ "--scheduler-list": `${listWidth}px`,
1499
+ // The list's width on screen: never more than 40% of the frame (a phone keeps the timeline).
1500
+ "--scheduler-list-w": "min(var(--scheduler-list), 40cqw)",
1501
+ ...style,
1502
+ }, ...props, children: [_jsxs("div", { ref: probeRef, "aria-hidden": true, className: "pointer-events-none invisible absolute -z-10 flex", children: [_jsx("span", { className: size === "sm" ? "h-(--control-h-sm)" : "h-(--control-h)" }), _jsx("span", { className: "h-(--control-h-sm)" }), _jsx("span", { className: "h-(--control-inset-sm)" })] }), (toolbar || controls) && (_jsxs("div", { "data-slot": "scheduler-toolbar", className: "flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-border/(--hairline-opacity) px-3 py-2", children: [toolbar && (_jsx("div", { className: "flex min-w-0 flex-1 items-center gap-2 @max-[40rem]/scheduler:basis-full", children: toolbar })), controls && (_jsxs("div", { className: "ms-auto flex items-center gap-2", children: [_jsx(Button, { "data-slot": "scheduler-today", variant: "secondary", onClick: () => wholeDays ? scrollToTime(periodOf(todayWall), "edge") : scrollToTime(todayWall, "center"), children: text.today }), viewSwitch ??
1503
+ (zooms.length > 1 && (_jsx(ToggleGroup, { "data-slot": "scheduler-zoom", "aria-label": text.zoom, value: [zoom], onValueChange: (value) => value[0] && setZoom(value[0]), children: zooms.map((z) => (_jsx(ToggleGroupItem, { value: z, children: text[z] }, z))) })))] }))] })), _jsxs("div", { className: "relative min-h-0 flex-1", children: [_jsx(ScrollArea, { orientation: "both", fade: false, className: "size-full",
1504
+ // Keyboard focus scrolls a bar into view clear of the pinned axis and list.
1505
+ viewportClassName: "[scroll-padding-top:calc(var(--control-h-sm)*2)] [scroll-padding-inline-start:var(--scheduler-list-w)]", children: _jsxs("div", { "data-slot": "scheduler-body", className: "grid", style: {
1506
+ gridTemplateColumns: `var(--scheduler-list-w) ${timelineWidth}px`,
1507
+ gridTemplateRows: `${head}px ${bodyHeight}px`,
1508
+ }, children: [_jsx("div", { "data-slot": "scheduler-list-header", className: "sticky start-0 top-0 z-30 flex items-end border-e border-b border-border/(--hairline-opacity) bg-field-surface", children: _jsxs("div", { className: "flex w-full items-center", style: { height: metrics.lane }, children: [_jsx("span", { className: "min-w-0 flex-1 truncate px-3 eyebrow", children: columnHeader }), extraColumns.map((c) => (_jsx("span", { className: "shrink-0 truncate px-2 eyebrow", style: { width: c.width ?? 96 }, children: c.header }, c.id)))] }) }), _jsxs("div", { "data-slot": "scheduler-axis", "aria-hidden": true,
1509
+ // Clipped, not hidden: `overflow: hidden` would hold the sticky labels in place.
1510
+ className: "sticky top-0 z-20 overflow-clip border-b border-border/(--hairline-opacity) bg-field-surface font-mono text-11 tabular-nums", children: [_jsx("div", { className: "relative", style: { height: metrics.lane }, children: majorTicks.map((t) => (_jsx("div", { "data-slot": "scheduler-axis-period", className: "absolute top-0 flex h-full items-center border-s border-border/(--hairline-opacity) whitespace-nowrap text-foreground", style: { insetInlineStart: xOf(t.start), width: (t.end - t.start) * ppm }, children: _jsx("span", { className: "sticky start-(--scheduler-list-w) max-w-full truncate px-2 [unicode-bidi:plaintext]", children: majorLabel(t) }) }, t.start))) }), _jsxs("div", { className: "relative border-t border-border/(--hairline-opacity)", style: { height: metrics.lane }, children: [minorTicks.map((t) => (_jsx("div", { "data-today": isToday(t) ? "" : undefined, className: "absolute top-0 flex h-full items-center justify-center overflow-clip border-s border-border/(--hairline-opacity) whitespace-nowrap text-muted-foreground data-today:font-medium data-today:text-foreground", style: { insetInlineStart: xOf(t.start), width: (t.end - t.start) * ppm }, children: _jsx("span", { className: cn("min-w-0 truncate px-0.5 [unicode-bidi:plaintext]", isToday(t) &&
1511
+ scale.minor === "day" &&
1512
+ "rounded-full bg-foreground px-1.5 leading-[18px] text-background forced-colors:border forced-colors:border-[CanvasText]"), children: minorLabel(t) }) }, t.start))), todayIn && (_jsx("span", { "data-slot": "scheduler-today-mark", className: "absolute -bottom-1 size-[7px] -translate-x-1/2 rounded-full bg-foreground ring-2 ring-field-surface rtl:translate-x-1/2 forced-colors:bg-[CanvasText]", style: { insetInlineStart: xOf(todayWall) + 0.5 } }))] })] }), _jsx("div", { ref: listRef, "data-slot": "scheduler-list", role: loading ? undefined : "list", "aria-label": loading ? undefined : columnHeader, className: cn("sticky start-0 z-10 border-e border-border/(--hairline-opacity) bg-field-surface",
1513
+ // The viewport keeps the list's width clear for bars that take focus. The list's own
1514
+ // buttons and fields are in that width: focus on them must not scroll the timeline.
1515
+ "[&_button,&_input]:scroll-ms-[calc(var(--scheduler-list-w)*-1)]"), children: loading
1516
+ ? Array.from({ length: placeholderRows }, (_, i) => (_jsx("div", { className: "flex items-center border-b border-border/(--hairline-opacity) px-3", style: { height: metrics.row }, children: _jsx(Skeleton, { className: "text-13", style: { width: `${[62, 48, 70, 40, 56, 66][i]}%` } }) }, i)))
1517
+ : shownRows.map((i) => {
1518
+ const d = model.display[i];
1519
+ const top = model.offsets[i];
1520
+ const height = model.offsets[i + 1] - top;
1521
+ if (d.kind === "group")
1522
+ return (_jsxs("div", { role: "listitem", "data-slot": "scheduler-group", className: "group/row absolute inset-x-0 top-0 flex items-end gap-2 ps-3 pe-1.5 pb-1", style: { transform: `translateY(${top}px)`, height }, children: [_jsx("span", { className: "min-w-0 flex-1 truncate pb-0.5 eyebrow", children: d.title }), adding && layout === "gantt" && (_jsx(Button, { "data-slot": "scheduler-add-to-group", variant: "bare", size: "icon-sm", "aria-label": text.addTaskTo(d.title), onClick: () => addTask(d.title), className: "size-6 opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100", children: _jsx(PlusIcon, {}) }))] }, d.id));
1523
+ if (d.kind === "add")
1524
+ return (_jsx("div", { role: "listitem", className: "absolute inset-x-0 top-0 flex items-center px-1.5", style: { transform: `translateY(${top}px)`, height }, children: _jsxs(Button, { "data-slot": "scheduler-add", variant: "ghost", size: "sm", onClick: () => (layout === "gantt" ? addTask() : addRow()), className: "text-muted-foreground", children: [_jsx(PlusIcon, {}), layout === "gantt" ? text.addTask : text.addRow] }) }, d.id));
1525
+ const rowEntry = layout === "gantt" ? model.entries.get(d.row.id) : undefined;
1526
+ const actions = adding && (layout === "resource" || (!!rowEntry && editable(rowEntry)));
1527
+ const typing = renaming === d.row.id;
1528
+ return (_jsxs("div", { role: "listitem", "aria-setsize": model.rowCount, "aria-posinset": d.position, "data-slot": "scheduler-row", "data-row": d.row.id, "data-active": i === activeRow ? "" : undefined, className: "group/row absolute inset-x-0 top-0 flex items-start border-b border-border/(--hairline-opacity) transition-colors duration-(--duration-fade) ease-(--ease) data-active:bg-control-hover/60", style: { transform: `translateY(${top}px)`, height }, children: [_jsxs("div", { className: cn("flex min-w-0 flex-1 items-center gap-2 ps-3", actions ? "pe-1" : "pe-3"), style: { height: metrics.row }, children: [d.row.icon && _jsx("span", { className: "flex shrink-0 items-center", children: d.row.icon }), typing ? (_jsx(RowName, { defaultValue: layout === "gantt" ? (rowEntry?.item.title ?? d.row.title) : d.row.title, label: text.rowName, onDone: (name, key) => rename(d.row.id, name, key) })) : (_jsxs("span", { className: "min-w-0 flex-1 truncate text-13 text-foreground", children: [d.row.title, d.row.description && (_jsx("span", { className: "ms-2 font-mono text-11 text-muted-foreground tabular-nums", children: d.row.description }))] })), actions && !typing && (_jsx(Button, { "data-slot": "scheduler-row-actions", variant: "bare", size: "icon-sm", "aria-label": text.rowActions(d.row.title), "aria-haspopup": "menu", onClick: (e) => rowMenu(d.row.id, e.currentTarget), className: "size-6 shrink-0 opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100 data-active:opacity-100 pointer-coarse:opacity-100", children: _jsx(EllipsisIcon, {}) }))] }), extraColumns.map((c) => (_jsx("div", { className: "flex shrink-0 items-center truncate px-2 text-13 text-foreground-soft", style: { width: c.width ?? 96, height: metrics.row }, children: c.cell(d.row, model.byRow[i].map((id) => model.entries.get(id).item)) }, c.id)))] }, d.row.id));
1529
+ }) }), _jsxs("div", { ref: canvasRef, "data-slot": "scheduler-timeline",
1530
+ // Isolated, so a lifted bar stays under the pinned axis and list.
1531
+ className: "relative isolate overflow-hidden bg-field-surface", onPointerDown: onPointerDown, onKeyDown: onKeyDown, onContextMenu: onContextMenu, children: [_jsxs("div", { "aria-hidden": true, className: "pointer-events-none absolute inset-0", children: [weekends.map((w) => (_jsx("div", { "data-slot": "scheduler-weekend", className: "absolute inset-y-0 bg-control-surface", style: { insetInlineStart: xOf(w.start), width: (w.end - w.start) * ppm } }, w.start))), activeRow !== undefined && !loading && (_jsx("div", { "data-slot": "scheduler-active-row", className: "absolute inset-x-0 top-0 bg-control-hover/45", style: {
1532
+ transform: `translateY(${model.offsets[activeRow]}px)`,
1533
+ height: model.offsets[activeRow + 1] - model.offsets[activeRow],
1534
+ } })), minorTicks.map((t) => (_jsx("div", { className: "absolute inset-y-0 w-px bg-border/(--hairline-opacity)", style: { insetInlineStart: xOf(t.start) } }, t.start))), shownRows.map((i) => (_jsx("div", { className: cn("absolute inset-x-0 top-0", model.display[i]?.kind === "row" && "border-b border-border/(--hairline-opacity)"), style: {
1535
+ transform: `translateY(${model.offsets[i]}px)`,
1536
+ height: model.offsets[i + 1] - model.offsets[i],
1537
+ } }, i))), todayIn && !wholeDays && (_jsx("div", { "data-slot": "scheduler-today-line", className: "absolute inset-y-0 w-px bg-foreground/45 forced-colors:bg-[CanvasText]", style: { insetInlineStart: xOf(todayWall) } })), _jsx("div", { ref: highlightRef, hidden: true, "data-slot": "scheduler-drop-row", className: "absolute inset-x-0 top-0 bg-control-hover/70" })] }), !loading &&
1538
+ shownRows.map((i) => {
1539
+ const span = model.groupSpans.get(i);
1540
+ if (!span)
1541
+ return null;
1542
+ const top = model.offsets[i + 1] - 8;
1543
+ return (_jsx("div", { "aria-hidden": true, "data-slot": "scheduler-group-span",
1544
+ // A hairline bracket over the phase's bars, its ends turned down.
1545
+ className: cn("absolute start-0 top-0 h-px bg-foreground/40 forced-colors:bg-[CanvasText]", "before:absolute before:start-0 before:top-0 before:h-1.5 before:w-px before:bg-inherit before:content-['']", "after:absolute after:end-0 after:top-0 after:h-1.5 after:w-px after:bg-inherit after:content-['']"), style: {
1546
+ transform: `translate(${rtl ? -xOf(span.start) : xOf(span.start)}px, ${top}px)`,
1547
+ width: Math.max((span.end - span.start) * ppm, 6),
1548
+ } }, `g${i}`));
1549
+ }), !loading && (model.links.length > 0 || linking) && (_jsxs("svg", { "aria-hidden": true, "data-slot": "scheduler-links", className: "pointer-events-none absolute start-0 top-0 overflow-visible text-muted-foreground rtl:-scale-x-100", width: timelineWidth, height: totalHeight, children: [_jsx("defs", { children: _jsx("marker", { id: markerId, viewBox: "0 0 8 8", refX: "7", refY: "4", markerWidth: "5", markerHeight: "5", orient: "auto", children: _jsx("path", { d: "M0 0L8 4L0 8z", fill: "currentColor" }) }) }), model.links.map((link) => {
1550
+ const a = model.entries.get(link.from);
1551
+ const b = model.entries.get(link.to);
1552
+ const key = `${link.from}>${link.to}`;
1553
+ const touches = activeId === link.from || activeId === link.to;
1554
+ const d = linkPath(geometry(a), geometry(b));
1555
+ return (_jsxs(React.Fragment, { children: [_jsx("path", { ref: (el) => {
1556
+ if (el)
1557
+ linkRefs.current.set(key, el);
1558
+ else
1559
+ linkRefs.current.delete(key);
1560
+ }, "data-slot": "scheduler-link", "data-link": key, "data-active": touches ? "" : undefined, "data-selected": selectedLink === key ? "" : undefined, d: d, fill: "none", stroke: "currentColor", strokeWidth: selectedLink === key ? 2 : 1,
1561
+ // The lines of the bar in hand come forward in the ink.
1562
+ className: "transition-colors duration-(--duration-fade) ease-(--ease) data-active:text-foreground data-selected:text-foreground", markerEnd: `url(#${markerId})` }), linking && (_jsx("path", { "data-slot": "scheduler-link-hit", "data-link": key, d: d, fill: "none", stroke: "transparent", strokeWidth: 10, className: "[pointer-events:stroke] cursor-pointer", onPointerDown: (e) => {
1563
+ e.stopPropagation();
1564
+ e.preventDefault();
1565
+ setSelectedLink(key);
1566
+ } }))] }, key));
1567
+ }), linking && (_jsx("path", { ref: linkDraftRef, "data-slot": "scheduler-link-draft", style: { display: "none" }, fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeDasharray: "4 3", className: "text-foreground" }))] })), loading
1568
+ ? Array.from({ length: placeholderRows }, (_, i) => (_jsx(Skeleton, { shape: "item", className: "absolute start-0 top-0", style: {
1569
+ transform: `translate(${(rtl ? -1 : 1) * (view.left + 48 + ((i * 97) % 240))}px, ${i * metrics.row + (metrics.row - metrics.bar) / 2}px)`,
1570
+ width: 120 + ((i * 53) % 160),
1571
+ height: metrics.bar,
1572
+ } }, i)))
1573
+ : shownRows.flatMap((i) => (model.byRow[i] ?? []).map((id) => {
1574
+ const entry = model.entries.get(id);
1575
+ const g = geometry(entry);
1576
+ // The free stretch after it in its lane, for a name that does not fit inside.
1577
+ let next = range.end;
1578
+ for (const other of model.byRow[i]) {
1579
+ const o = model.entries.get(other);
1580
+ if (o !== entry && o.lane === entry.lane && o.shown.start >= entry.shown.end)
1581
+ next = Math.min(next, o.shown.start);
1582
+ }
1583
+ return (_jsx(SchedulerBar, { entry: entry, x: rtl ? -g.x : g.x, y: g.y, width: g.w, height: metrics.bar, tabbable: id === activeOrFirst, role: role, when: describe(entry, entry.span), rowTitle: layout === "resource" ? rowTitle(entry.row) : undefined,
1584
+ // In a Gantt chart a row is the bar's own: a name that does not fit sits after
1585
+ // it. A booking's does where its lane is free that far.
1586
+ labelOutside: layout === "gantt",
1587
+ // In its days, a booking keeps its name inside: never after it.
1588
+ room: wholeDays ? 0 : (next - entry.shown.end) * ppm,
1589
+ // A booking says when it starts beside its name, where it fits: in hours,
1590
+ // and in a chip of its day (unless it is the whole day).
1591
+ time: !entry.milestone &&
1592
+ (scale.minor === "hour" ||
1593
+ (wholeDays && entry.span.start !== startOfDay(entry.span.start)))
1594
+ ? (entry.span.start % HOUR === 0 ? fmt.hour : fmt.time).format(entry.span.start)
1595
+ : undefined, readOnly: readOnly, dragging: id === draggingId, lifted: editing?.id === id, connector: linking && !entry.item.disabled, instructionsId: instructionsId, text: text, onFocus: () => id !== activeId && setActiveId(id) }, id));
1596
+ })), !loading &&
1597
+ shownRows.flatMap((i) => [...(model.cells.get(i) ?? [])].map(([day, ids]) => {
1598
+ const key = `${i}:${day}`;
1599
+ const x = xOf(day) + 2;
1600
+ const top = (model.offsets[i] ?? 0) + 3;
1601
+ const all = ids
1602
+ .map((id) => model.entries.get(id))
1603
+ .sort((a, b) => a.span.start - b.span.start);
1604
+ // How much of an eight-hour day it is booked: a whole day counts in full.
1605
+ const booked = all.reduce((sum, e) => sum + Math.min(e.span.end, day + DAY) - Math.max(e.span.start, day), 0);
1606
+ const load = booked >= 4 * HOUR ? "heavy" : "light";
1607
+ const tones = [...new Set(all.flatMap((e) => (e.item.tone ? [e.item.tone] : [])))].slice(0, 3);
1608
+ const name = `${rowTitle(i)}, ${fmt.dayShort.format(day)}: ${text.bookingCount(all.length)}`;
1609
+ return (_jsxs(Popover, { open: moreKey === key, onOpenChange: (o) => setMoreKey(o ? key : null), children: [_jsxs(PopoverTrigger, { "data-slot": "scheduler-day-cell", "data-load": load, "aria-label": name, title: name, className: cn("absolute start-0 top-0 flex flex-col items-center justify-center gap-0.5 rounded-item font-mono text-12 text-foreground tabular-nums", "transition-[background-color] duration-(--duration-fade) ease-(--ease) hover:bg-control-hover", "data-[load=light]:bg-control-hover/50", "data-[load=heavy]:bg-[color-mix(in_oklab,var(--control-hover),var(--foreground)_12%)]", "data-popup-open:shadow-raised-current forced-colors:border forced-colors:border-[CanvasText]"), style: {
1610
+ transform: `translate(${rtl ? -x : x}px, ${top}px)`,
1611
+ width: Math.max(DAY * ppm - 4, 6),
1612
+ height: metrics.row - 6,
1613
+ }, children: [_jsx("span", { className: "leading-none", children: all.length }), tones.length > 0 && (_jsx("span", { "aria-hidden": true, className: "flex gap-0.5", children: tones.map((tone) => (_jsx("span", { className: cn("size-1 rounded-full forced-colors:bg-[CanvasText]", markTones[tone]) }, tone))) }))] }), _jsxs(PopoverContent, { side: "bottom", align: "start", className: "w-64", children: [_jsxs(PopoverTitle, { className: "mb-2 font-mono text-12 font-normal tracking-[0.12em] text-muted-foreground uppercase", children: [rowTitle(i), " \u00B7 ", fmt.dayShort.format(day)] }), _jsx("ul", { className: "flex flex-col gap-0.5", children: all.map((e) => (_jsx("li", { children: _jsxs("button", { type: "button", "data-slot": "scheduler-more-item", onClick: () => {
1614
+ setMoreKey(null);
1615
+ open(e.item.id);
1616
+ }, className: "flex min-h-(--control-h-sm) w-full items-center gap-2 rounded-item px-2 text-start text-13 transition-colors duration-(--duration-fade) ease-(--ease) hover:bg-control-hover", children: [_jsx("span", { "aria-hidden": true, className: cn("size-1.5 shrink-0 rounded-full", e.item.tone ? markTones[e.item.tone] : "bg-foreground/60") }), _jsx("span", { className: "shrink-0 font-mono text-11 text-muted-foreground tabular-nums", children: e.span.start === startOfDay(e.span.start)
1617
+ ? fmt.dayShort.format(e.span.start)
1618
+ : fmt.time.format(e.span.start) }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: e.item.title })] }) }, e.item.id))) })] })] }, key));
1619
+ })), (drawing ?? pending) &&
1620
+ (() => {
1621
+ const draft = (drawing ?? pending);
1622
+ const top = (model.offsets[draft.row] ?? 0) + (metrics.row - metrics.bar) / 2;
1623
+ const x = xOf(draft.span.start);
1624
+ return (_jsxs("div", { "aria-hidden": true, "data-slot": "scheduler-draft", className: "absolute start-0 top-0 z-20 flex items-center gap-1.5 overflow-hidden rounded-item border border-dashed border-control-focus bg-control-hover px-2 text-12 whitespace-nowrap text-foreground", style: {
1625
+ transform: `translate(${rtl ? -x : x}px, ${top}px)`,
1626
+ width: Math.max((draft.span.end - draft.span.start) * ppm, 6),
1627
+ height: metrics.bar,
1628
+ }, children: [_jsx("span", { className: "font-medium", children: text.newBooking }), _jsx("span", { className: "font-mono text-11 text-muted-foreground tabular-nums", children: describeSpan(fmt, draft.span, false) })] }));
1629
+ })(), _jsx("div", { ref: readoutRef, hidden: true, "aria-hidden": true, "data-slot": "scheduler-readout", className: "pointer-events-none absolute start-0 top-0 z-20 rounded-item material-menu px-2 py-1 font-mono text-11 whitespace-nowrap tabular-nums" })] })] }) }), !isEmpty && edges.start && (_jsx("div", { "aria-hidden": true, "data-slot": "scheduler-edge", "data-edge": "start", className: "pointer-events-none absolute bottom-0 z-20 w-8 bg-linear-to-r from-field-surface to-transparent rtl:bg-linear-to-l", style: { top: head, insetInlineStart: "var(--scheduler-list-w)" } })), !isEmpty && edges.end && (_jsx("div", { "aria-hidden": true, "data-slot": "scheduler-edge", "data-edge": "end", className: "pointer-events-none absolute end-0 bottom-0 z-20 w-12 bg-linear-to-l from-field-surface to-transparent rtl:bg-linear-to-r", style: { top: head } })), !isEmpty && (_jsx("div", { role: "separator", "aria-orientation": "vertical", "aria-label": text.resizeList, "aria-valuemin": MIN_GRID, "aria-valuemax": MAX_GRID, "aria-valuenow": listWidth, tabIndex: 0, "data-slot": "scheduler-resize", onPointerDown: onHandlePointerDown, onKeyDown: onHandleKeyDown, className: cn(
1630
+ // A 24px target centred on the list's edge, drawing a 1px line (2px when focused).
1631
+ "absolute inset-y-0 z-40 w-6 cursor-col-resize touch-none outline-none", "before:absolute before:inset-y-0 before:start-1/2 before:w-px before:bg-transparent before:content-['']", "before:transition-[background-color] before:duration-(--duration-fade) before:ease-(--ease)", "hover:before:bg-control-focus focus-visible:before:w-0.5 focus-visible:before:bg-control-focus data-dragging:before:bg-control-focus"), style: { insetInlineStart: "calc(var(--scheduler-list-w) - 12px)" } })), isEmpty && (_jsx("div", { className: "absolute end-0 bottom-0",
1632
+ // With a row to add from, the list stays in view beside the empty state.
1633
+ style: { top: head, insetInlineStart: adding ? "var(--scheduler-list-w)" : 0 }, children: empty ?? (_jsxs(Empty, { "data-slot": "scheduler-empty", className: "h-full", children: [_jsx(EmptyMedia, { children: _jsx(CalendarIcon, {}) }), _jsx(EmptyDescription, { children: text.empty })] })) }))] }), _jsx("span", { id: instructionsId, "data-slot": "scheduler-instructions", className: "sr-only", children: instructions }), _jsx("span", { "data-slot": "scheduler-announcer", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: loading ? text.loading : message }), renderDetails && openEntry && (_jsx(SchedulerDetails, { narrow: narrow, item: openEntry.item, anchor: () => barEl(openEntry.item.id), onClose: () => setOpenId(null), children: renderDetails(openEntry.item) })), editing && (_jsx(SchedulerEditorHost, { narrow: narrow, state: editing, anchor: () => editing.id
1634
+ ? (barEl(editing.id) ?? canvasRef.current)
1635
+ : (rootRef.current?.querySelector("[data-slot=scheduler-draft]") ?? null), text: text, hour12: fmt.hour12, rows: layout === "resource"
1636
+ ? model.display.flatMap((d) => (d.kind === "row" ? [{ id: d.row.id, title: d.row.title }] : []))
1637
+ : undefined, rowLabel: columnHeader, categories: categories, onSave: saveEditor, onCancel: closeEditor, onDelete: editing.id ? () => deleteItem(editing.id, "editor") : undefined })), menu && (_jsx(SchedulerMenuHost, { anchor: menu.anchor, label: menu.label, entries: menu.entries, returnFocus: menu.returnFocus, onClose: () => setMenu(null) }))] }));
1638
+ }
1639
+ /** About how wide a name is at 12px in Licht Sans, with the bar's padding: enough to choose a side. */
1640
+ const nameWidth = (title) => title.length * 6.6 + 18;
1641
+ function SchedulerBar({ entry, x, y, width, height, tabbable, role, when, rowTitle, labelOutside, room, time, readOnly, dragging, lifted = false, connector = false, instructionsId, text, onFocus, }) {
1642
+ const { item, milestone } = entry;
1643
+ const editable = !readOnly && !item.disabled;
1644
+ const progress = item.progress === undefined ? undefined : clamp(Math.round(item.progress), 0, 100);
1645
+ const label = [
1646
+ item.title,
1647
+ rowTitle,
1648
+ milestone ? `${text.milestone}, ${when}` : when,
1649
+ progress !== undefined ? text.progress(progress) : undefined,
1650
+ item.disabled ? text.locked : undefined,
1651
+ ]
1652
+ .filter(Boolean)
1653
+ .join(", ");
1654
+ // Too short for its name: in a Gantt chart the name sits after the bar. In a resource row the
1655
+ // next booking may follow at once: there it goes after the bar only where the lane is free that
1656
+ // far, and otherwise stays inside, cut short (the whole of it, and when, on hover).
1657
+ const name = nameWidth(item.title);
1658
+ const outside = milestone || (name > width && (labelOutside || name + 8 <= room));
1659
+ return (_jsxs("div", { role: "button", tabIndex: tabbable ? 0 : -1, "aria-roledescription": role, "aria-label": label, "aria-describedby": instructionsId, "aria-disabled": item.disabled || undefined, "data-slot": "scheduler-item", "data-id": item.id, "data-tone": item.tone, "data-milestone": milestone ? "" : undefined, "data-disabled": item.disabled ? "" : undefined, "data-dragging": dragging ? "" : undefined,
1660
+ // The whole name and when on hover, where the bar cuts it short.
1661
+ title: `${item.title} · ${when}`, onFocus: onFocus, className: cn("group/item absolute start-0 top-0 flex touch-manipulation items-center outline-none select-none [-webkit-touch-callout:none]",
1662
+ // `outline-none` at rest sets the style to none: the ring names its own style.
1663
+ "focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-control-focus focus-visible:outline-solid", editable && "cursor-grab active:cursor-grabbing", (dragging || lifted) && "z-20", milestone ? "justify-center" : "rounded-item", !milestone &&
1664
+ (item.tone
1665
+ ? cn("border", toneClasses[item.tone])
1666
+ : // A locked bar sits flat in a dashed edge: it reads as fixed without a colour of its own.
1667
+ item.disabled
1668
+ ? "border border-dashed border-field-edge bg-control-surface forced-colors:text-[GrayText]"
1669
+ : "material-raised"), !milestone && item.disabled && "border-dashed", !milestone && (dragging || lifted) && "shadow-overlay",
1670
+ // While a dependency is drawn: the bars it may go to, dashed, and the one under the pointer.
1671
+ "data-link-candidate:outline-1 data-link-candidate:outline-offset-2 data-link-candidate:outline-control-focus/70 data-link-candidate:outline-dashed", "data-link-target:outline-2 data-link-target:outline-control-focus data-link-target:outline-solid"), style: { transform: `translate(${x}px, ${y}px)`, width, height }, children: [milestone ? (_jsx("span", { "aria-hidden": true, "data-slot": "scheduler-milestone", className: cn("size-3 rotate-45 ring-2 ring-field-surface", item.tone ? markTones[item.tone] : "bg-foreground") })) : (_jsxs(_Fragment, { children: [progress !== undefined && progress > 0 && (_jsx("span", { "aria-hidden": true, "data-slot": "scheduler-item-progress", className: cn("pointer-events-none absolute inset-y-0 start-0 rounded-s-item", progress >= 100 && "rounded-e-item", item.tone ? doneTones[item.tone] : "bg-foreground/12"), style: { width: `${progress}%` } })), !outside && (_jsxs("span", { className: cn("relative flex min-w-0 flex-1 flex-wrap overflow-hidden text-12", width < 64 ? "px-1" : "px-2"), style: { height, lineHeight: `${height}px` }, children: [_jsx("span", { className: cn("max-w-full min-w-0 truncate font-medium", item.disabled ? "text-muted-foreground forced-colors:text-[GrayText]" : "text-foreground"), children: item.title }), time && (_jsx("span", { "aria-hidden": true, "data-time": time, className: "ps-1.5 font-mono text-11 whitespace-nowrap text-muted-foreground tabular-nums [unicode-bidi:plaintext] after:content-[attr(data-time)]" }))] })), editable && (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, "data-slot": "scheduler-item-handle", "data-edge": "start", className: "absolute inset-y-0 -start-1 w-2.5 cursor-ew-resize pointer-coarse:-start-2 pointer-coarse:w-4" }), _jsx("span", { "aria-hidden": true, "data-slot": "scheduler-item-handle", "data-edge": "end", className: "absolute inset-y-0 -end-1 w-2.5 cursor-ew-resize pointer-coarse:-end-2 pointer-coarse:w-4" })] }))] })), connector && (_jsxs("span", { "aria-hidden": true, "data-slot": "scheduler-item-connector",
1672
+ // Its own hint, not the bar's title.
1673
+ title: "", className: cn("group/connector absolute top-1/2 z-10 flex size-5 -translate-y-1/2 cursor-crosshair items-center justify-center", "opacity-0 transition-opacity duration-(--duration-fade) ease-(--ease)", "group-hover/item:opacity-100 group-focus/item:opacity-100 group-data-linking/item:opacity-100", milestone ? "-end-5" : "-end-6"), children: [_jsx("span", { className: cn("size-3 rounded-full border-[1.5px] border-foreground/70 bg-field-surface shadow-raised", "transition-[scale,background-color,border-color] duration-(--duration-fade) ease-(--ease)", "group-hover/connector:scale-125 group-hover/connector:border-foreground group-hover/connector:bg-foreground", "group-data-linking/item:scale-125 group-data-linking/item:border-foreground group-data-linking/item:bg-foreground", "forced-colors:border-[CanvasText] group-hover/connector:forced-colors:bg-[CanvasText]") }), _jsx("span", { "data-slot": "scheduler-item-connector-hint", className: cn("pointer-events-none absolute start-full top-1/2 ms-1 -translate-y-1/2 rounded-item material-menu px-2 py-1 font-mono text-11 whitespace-nowrap text-foreground", "opacity-0 transition-opacity duration-(--duration-fade) ease-(--ease) group-hover/connector:opacity-100 group-data-linking/item:opacity-0"), children: text.linkHint })] })), outside && (_jsxs("span", { "aria-hidden": true, className: cn("pointer-events-none absolute start-full text-12 whitespace-nowrap text-foreground", connector ? "ms-7" : "ms-2"), children: [item.title, time && (_jsx("span", { "data-time": time, className: "ps-1.5 font-mono text-11 text-muted-foreground tabular-nums [unicode-bidi:plaintext] after:content-[attr(data-time)]" }))] }))] }));
1674
+ }
1675
+ /* ── A row's name, typed ───────────────────────────────────────────────────── */
1676
+ /** The field a task's or a row's name is typed in: Enter or leaving it keeps it, Escape does not. */
1677
+ function RowName({ defaultValue, label, onDone, }) {
1678
+ const done = React.useRef(false);
1679
+ const ref = React.useRef(null);
1680
+ // Focused without a scroll: the list is pinned, and the timeline stays where it was. A browser
1681
+ // keeps the caret in view as it is typed, and finds a pinned field "out of view" at the
1682
+ // timeline's start: while the name is typed, the timeline keeps its place across.
1683
+ React.useEffect(() => {
1684
+ const input = ref.current;
1685
+ const vp = input?.closest("[data-slot=scroll-area-viewport]");
1686
+ if (!input)
1687
+ return;
1688
+ input.focus({ preventScroll: true });
1689
+ input.select();
1690
+ if (!vp)
1691
+ return;
1692
+ const left = vp.scrollLeft;
1693
+ const hold = () => {
1694
+ if (vp.scrollLeft !== left)
1695
+ vp.scrollLeft = left;
1696
+ };
1697
+ vp.addEventListener("scroll", hold);
1698
+ return () => vp.removeEventListener("scroll", hold);
1699
+ }, []);
1700
+ const finish = (name, key = false) => {
1701
+ if (done.current)
1702
+ return;
1703
+ done.current = true;
1704
+ onDone(name, key);
1705
+ };
1706
+ return (_jsx(Input, { "data-slot": "scheduler-row-name", size: "sm", ref: ref, "aria-label": label, defaultValue: defaultValue, onBlur: (e) => finish(e.currentTarget.value), onKeyDown: (e) => {
1707
+ e.stopPropagation();
1708
+ if (e.key === "Enter") {
1709
+ e.preventDefault();
1710
+ finish(e.currentTarget.value, true);
1711
+ }
1712
+ else if (e.key === "Escape") {
1713
+ e.preventDefault();
1714
+ finish(null, true);
1715
+ }
1716
+ }, className: "min-w-0 flex-1" }));
1717
+ }