velvetkit 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (458) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +80 -0
  3. data/README.md +30 -8
  4. data/lib/generators/velvetkit/add/add_generator.rb +77 -0
  5. data/lib/generators/velvetkit/helpers.rb +29 -2
  6. data/lib/generators/velvetkit/icons/icons_generator.rb +71 -0
  7. data/lib/generators/velvetkit/install/install_generator.rb +9 -12
  8. data/lib/velvetkit/icons.rb +148 -0
  9. data/lib/velvetkit/registry.rb +5 -2
  10. data/lib/velvetkit/version.rb +4 -1
  11. data/lib/velvetkit.rb +8 -0
  12. data/registry/app/assets/tailwind/velvetkit.css +90 -155
  13. data/registry/app/components/ui/alert.rb +1 -1
  14. data/registry/app/components/ui/chart.html.erb +47 -0
  15. data/registry/app/components/ui/chart.rb +177 -0
  16. data/registry/app/components/ui/command/group.rb +27 -0
  17. data/registry/app/components/ui/command/item.rb +64 -0
  18. data/registry/app/components/ui/command.html.erb +41 -0
  19. data/registry/app/components/ui/command.rb +122 -0
  20. data/registry/app/components/ui/confirm_dialog.html.erb +13 -0
  21. data/registry/app/components/ui/confirm_dialog.rb +55 -0
  22. data/registry/app/components/ui/date_picker.html.erb +58 -64
  23. data/registry/app/components/ui/date_picker.rb +199 -75
  24. data/registry/app/components/ui/empty_state.html.erb +20 -0
  25. data/registry/app/components/ui/empty_state.rb +46 -0
  26. data/registry/app/components/ui/file_field.html.erb +14 -4
  27. data/registry/app/components/ui/file_field.rb +179 -28
  28. data/registry/app/components/ui/gallery/image.rb +20 -0
  29. data/registry/app/components/ui/gallery.html.erb +52 -0
  30. data/registry/app/components/ui/gallery.rb +164 -0
  31. data/registry/app/components/ui/icon.html.erb +1 -1
  32. data/registry/app/components/ui/icon.rb +80 -8
  33. data/registry/app/components/ui/kbd.html.erb +27 -0
  34. data/registry/app/components/ui/kbd.rb +134 -0
  35. data/registry/app/components/ui/number_input.html.erb +11 -0
  36. data/registry/app/components/ui/number_input.rb +103 -0
  37. data/registry/app/components/ui/password_input.html.erb +1 -1
  38. data/registry/app/components/ui/progress/segment.rb +25 -0
  39. data/registry/app/components/ui/progress.html.erb +25 -0
  40. data/registry/app/components/ui/progress.rb +182 -0
  41. data/registry/app/components/ui/select.html.erb +24 -5
  42. data/registry/app/components/ui/select.rb +44 -5
  43. data/registry/app/components/ui/stepper/step.html.erb +27 -0
  44. data/registry/app/components/ui/stepper/step.rb +213 -0
  45. data/registry/app/components/ui/stepper.html.erb +19 -0
  46. data/registry/app/components/ui/stepper.rb +145 -0
  47. data/registry/app/components/ui/theme_toggle.rb +2 -4
  48. data/registry/app/components/ui/timeline/item.html.erb +21 -0
  49. data/registry/app/components/ui/timeline/item.rb +145 -0
  50. data/registry/app/components/ui/timeline.html.erb +1 -0
  51. data/registry/app/components/ui/timeline.rb +42 -0
  52. data/registry/app/components/ui/toast.rb +6 -6
  53. data/registry/app/components/ui/toggle_group/item.html.erb +1 -0
  54. data/registry/app/components/ui/toggle_group/item.rb +85 -0
  55. data/registry/app/components/ui/toggle_group.html.erb +1 -0
  56. data/registry/app/components/ui/toggle_group.rb +79 -0
  57. data/registry/app/javascript/chart_js.ts +37 -0
  58. data/registry/app/javascript/controllers/ui/_internal/date_format.ts +74 -0
  59. data/registry/app/javascript/controllers/ui/_internal/shortcut.ts +80 -0
  60. data/registry/app/javascript/controllers/ui/chart_controller.ts +585 -0
  61. data/registry/app/javascript/controllers/ui/command_controller.ts +454 -0
  62. data/registry/app/javascript/controllers/ui/confirm_dialog_controller.ts +110 -0
  63. data/registry/app/javascript/controllers/ui/date_picker_controller.ts +247 -82
  64. data/registry/app/javascript/controllers/ui/file_field_controller.ts +288 -16
  65. data/registry/app/javascript/controllers/ui/gallery_controller.ts +568 -0
  66. data/registry/app/javascript/controllers/ui/kbd_controller.ts +60 -0
  67. data/registry/app/javascript/controllers/ui/number_input_controller.ts +111 -0
  68. data/registry/app/javascript/controllers/ui/progress_controller.ts +87 -0
  69. data/registry/app/javascript/controllers/ui/select_controller.ts +198 -8
  70. data/registry/app/javascript/controllers/ui/stepper_controller.ts +187 -0
  71. data/registry/app/javascript/vanilla_calendar.ts +15 -0
  72. data/registry/components.yml +28 -5
  73. data/registry/config/locales/velvetkit.en.yml +84 -0
  74. data/registry/docs/agents.md +7 -4
  75. data/registry/icons/lucide/LICENSE +39 -0
  76. data/registry/icons/lucide/align-center.svg +17 -0
  77. data/registry/icons/lucide/align-left.svg +17 -0
  78. data/registry/icons/lucide/align-right.svg +17 -0
  79. data/registry/icons/lucide/arrow-left.svg +16 -0
  80. data/registry/icons/lucide/arrow-right.svg +16 -0
  81. data/registry/icons/lucide/badge-check.svg +16 -0
  82. data/registry/icons/lucide/bar-chart-3.svg +18 -0
  83. data/registry/icons/lucide/bell.svg +16 -0
  84. data/registry/icons/lucide/bold.svg +15 -0
  85. data/registry/icons/lucide/book-open.svg +16 -0
  86. data/registry/icons/lucide/calendar.svg +18 -0
  87. data/registry/icons/lucide/chart-column.svg +18 -0
  88. data/registry/icons/lucide/check.svg +15 -0
  89. data/registry/icons/lucide/chevron-down.svg +15 -0
  90. data/registry/icons/lucide/chevron-left.svg +15 -0
  91. data/registry/icons/lucide/chevron-right.svg +15 -0
  92. data/registry/icons/lucide/chevrons-up-down.svg +16 -0
  93. data/registry/icons/lucide/circle-alert.svg +17 -0
  94. data/registry/icons/lucide/circle-check.svg +16 -0
  95. data/registry/icons/lucide/cloud.svg +15 -0
  96. data/registry/icons/lucide/credit-card.svg +16 -0
  97. data/registry/icons/lucide/download.svg +17 -0
  98. data/registry/icons/lucide/ellipsis-vertical.svg +17 -0
  99. data/registry/icons/lucide/ellipsis.svg +17 -0
  100. data/registry/icons/lucide/eye-off.svg +18 -0
  101. data/registry/icons/lucide/eye.svg +16 -0
  102. data/registry/icons/lucide/file-plus.svg +18 -0
  103. data/registry/icons/lucide/file-text.svg +19 -0
  104. data/registry/icons/lucide/file.svg +16 -0
  105. data/registry/icons/lucide/folder-kanban.svg +18 -0
  106. data/registry/icons/lucide/folder.svg +15 -0
  107. data/registry/icons/lucide/git-branch.svg +18 -0
  108. data/registry/icons/lucide/globe.svg +17 -0
  109. data/registry/icons/lucide/graduation-cap.svg +17 -0
  110. data/registry/icons/lucide/grip-vertical.svg +20 -0
  111. data/registry/icons/lucide/home.svg +16 -0
  112. data/registry/icons/lucide/inbox.svg +16 -0
  113. data/registry/icons/lucide/info.svg +17 -0
  114. data/registry/icons/lucide/italic.svg +17 -0
  115. data/registry/icons/lucide/keyboard.svg +23 -0
  116. data/registry/icons/lucide/layout-dashboard.svg +18 -0
  117. data/registry/icons/lucide/layout-grid.svg +18 -0
  118. data/registry/icons/lucide/life-buoy.svg +20 -0
  119. data/registry/icons/lucide/list.svg +20 -0
  120. data/registry/icons/lucide/loader.svg +22 -0
  121. data/registry/icons/lucide/lock.svg +16 -0
  122. data/registry/icons/lucide/log-out.svg +17 -0
  123. data/registry/icons/lucide/mail.svg +16 -0
  124. data/registry/icons/lucide/menu.svg +17 -0
  125. data/registry/icons/lucide/message-circle.svg +15 -0
  126. data/registry/icons/lucide/minus.svg +15 -0
  127. data/registry/icons/lucide/monitor.svg +17 -0
  128. data/registry/icons/lucide/moon.svg +15 -0
  129. data/registry/icons/lucide/newspaper.svg +18 -0
  130. data/registry/icons/lucide/package.svg +18 -0
  131. data/registry/icons/lucide/panel-left.svg +16 -0
  132. data/registry/icons/lucide/pause.svg +16 -0
  133. data/registry/icons/lucide/percent.svg +17 -0
  134. data/registry/icons/lucide/plus.svg +16 -0
  135. data/registry/icons/lucide/printer.svg +17 -0
  136. data/registry/icons/lucide/qr-code.svg +26 -0
  137. data/registry/icons/lucide/receipt.svg +17 -0
  138. data/registry/icons/lucide/rocket.svg +18 -0
  139. data/registry/icons/lucide/rotate-cw.svg +16 -0
  140. data/registry/icons/lucide/search.svg +16 -0
  141. data/registry/icons/lucide/settings.svg +16 -0
  142. data/registry/icons/lucide/shield-check.svg +16 -0
  143. data/registry/icons/lucide/shield.svg +15 -0
  144. data/registry/icons/lucide/store.svg +17 -0
  145. data/registry/icons/lucide/sun-moon.svg +19 -0
  146. data/registry/icons/lucide/sun.svg +23 -0
  147. data/registry/icons/lucide/trash-2.svg +19 -0
  148. data/registry/icons/lucide/truck.svg +19 -0
  149. data/registry/icons/lucide/underline.svg +16 -0
  150. data/registry/icons/lucide/upload.svg +17 -0
  151. data/registry/icons/lucide/user-plus.svg +18 -0
  152. data/registry/icons/lucide/user.svg +16 -0
  153. data/registry/icons/lucide/users.svg +18 -0
  154. data/registry/icons/lucide/workflow.svg +17 -0
  155. data/registry/icons/lucide/x.svg +16 -0
  156. data/registry/icons/lucide/zoom-in.svg +18 -0
  157. data/registry/icons/lucide/zoom-out.svg +17 -0
  158. data/registry/icons/phosphor/LICENSE +21 -0
  159. data/registry/icons/phosphor/arrow-clockwise.svg +2 -0
  160. data/registry/icons/phosphor/arrow-left.svg +2 -0
  161. data/registry/icons/phosphor/arrow-right.svg +2 -0
  162. data/registry/icons/phosphor/bell.svg +2 -0
  163. data/registry/icons/phosphor/book-open.svg +2 -0
  164. data/registry/icons/phosphor/calendar-blank.svg +2 -0
  165. data/registry/icons/phosphor/caret-down.svg +2 -0
  166. data/registry/icons/phosphor/caret-left.svg +2 -0
  167. data/registry/icons/phosphor/caret-right.svg +2 -0
  168. data/registry/icons/phosphor/caret-up-down.svg +2 -0
  169. data/registry/icons/phosphor/chart-bar.svg +2 -0
  170. data/registry/icons/phosphor/chat-circle.svg +2 -0
  171. data/registry/icons/phosphor/check-circle.svg +2 -0
  172. data/registry/icons/phosphor/check.svg +2 -0
  173. data/registry/icons/phosphor/circle-half.svg +2 -0
  174. data/registry/icons/phosphor/cloud.svg +2 -0
  175. data/registry/icons/phosphor/credit-card.svg +2 -0
  176. data/registry/icons/phosphor/desktop.svg +2 -0
  177. data/registry/icons/phosphor/dots-six-vertical.svg +2 -0
  178. data/registry/icons/phosphor/dots-three-vertical.svg +2 -0
  179. data/registry/icons/phosphor/dots-three.svg +2 -0
  180. data/registry/icons/phosphor/download-simple.svg +2 -0
  181. data/registry/icons/phosphor/envelope.svg +2 -0
  182. data/registry/icons/phosphor/eye-slash.svg +2 -0
  183. data/registry/icons/phosphor/eye.svg +2 -0
  184. data/registry/icons/phosphor/file-plus.svg +2 -0
  185. data/registry/icons/phosphor/file-text.svg +2 -0
  186. data/registry/icons/phosphor/file.svg +2 -0
  187. data/registry/icons/phosphor/flow-arrow.svg +2 -0
  188. data/registry/icons/phosphor/folder.svg +2 -0
  189. data/registry/icons/phosphor/gear.svg +2 -0
  190. data/registry/icons/phosphor/git-branch.svg +2 -0
  191. data/registry/icons/phosphor/globe.svg +2 -0
  192. data/registry/icons/phosphor/graduation-cap.svg +2 -0
  193. data/registry/icons/phosphor/grid-four.svg +2 -0
  194. data/registry/icons/phosphor/house.svg +2 -0
  195. data/registry/icons/phosphor/info.svg +2 -0
  196. data/registry/icons/phosphor/kanban.svg +2 -0
  197. data/registry/icons/phosphor/keyboard.svg +2 -0
  198. data/registry/icons/phosphor/lifebuoy.svg +2 -0
  199. data/registry/icons/phosphor/list.svg +2 -0
  200. data/registry/icons/phosphor/lock.svg +2 -0
  201. data/registry/icons/phosphor/magnifying-glass-minus.svg +2 -0
  202. data/registry/icons/phosphor/magnifying-glass-plus.svg +2 -0
  203. data/registry/icons/phosphor/magnifying-glass.svg +2 -0
  204. data/registry/icons/phosphor/minus.svg +2 -0
  205. data/registry/icons/phosphor/moon.svg +2 -0
  206. data/registry/icons/phosphor/newspaper.svg +2 -0
  207. data/registry/icons/phosphor/package.svg +2 -0
  208. data/registry/icons/phosphor/pause.svg +2 -0
  209. data/registry/icons/phosphor/percent.svg +2 -0
  210. data/registry/icons/phosphor/plus.svg +2 -0
  211. data/registry/icons/phosphor/printer.svg +2 -0
  212. data/registry/icons/phosphor/qr-code.svg +2 -0
  213. data/registry/icons/phosphor/receipt.svg +2 -0
  214. data/registry/icons/phosphor/rocket.svg +2 -0
  215. data/registry/icons/phosphor/seal-check.svg +2 -0
  216. data/registry/icons/phosphor/shield-check.svg +2 -0
  217. data/registry/icons/phosphor/shield.svg +2 -0
  218. data/registry/icons/phosphor/sidebar.svg +2 -0
  219. data/registry/icons/phosphor/sign-out.svg +2 -0
  220. data/registry/icons/phosphor/spinner.svg +2 -0
  221. data/registry/icons/phosphor/squares-four.svg +2 -0
  222. data/registry/icons/phosphor/storefront.svg +2 -0
  223. data/registry/icons/phosphor/sun.svg +2 -0
  224. data/registry/icons/phosphor/text-align-center.svg +2 -0
  225. data/registry/icons/phosphor/text-align-left.svg +2 -0
  226. data/registry/icons/phosphor/text-align-right.svg +2 -0
  227. data/registry/icons/phosphor/text-b.svg +2 -0
  228. data/registry/icons/phosphor/text-italic.svg +2 -0
  229. data/registry/icons/phosphor/text-underline.svg +2 -0
  230. data/registry/icons/phosphor/trash.svg +2 -0
  231. data/registry/icons/phosphor/tray.svg +2 -0
  232. data/registry/icons/phosphor/truck.svg +2 -0
  233. data/registry/icons/phosphor/upload-simple.svg +2 -0
  234. data/registry/icons/phosphor/user-plus.svg +2 -0
  235. data/registry/icons/phosphor/user.svg +2 -0
  236. data/registry/icons/phosphor/users.svg +2 -0
  237. data/registry/icons/phosphor/warning-circle.svg +2 -0
  238. data/registry/icons/phosphor/x.svg +2 -0
  239. data/registry/icons/tabler/LICENSE +21 -0
  240. data/registry/icons/tabler/alert-circle.svg +18 -0
  241. data/registry/icons/tabler/align-center.svg +18 -0
  242. data/registry/icons/tabler/align-left.svg +18 -0
  243. data/registry/icons/tabler/align-right.svg +18 -0
  244. data/registry/icons/tabler/arrow-left.svg +18 -0
  245. data/registry/icons/tabler/arrow-right.svg +18 -0
  246. data/registry/icons/tabler/bell.svg +17 -0
  247. data/registry/icons/tabler/bold.svg +17 -0
  248. data/registry/icons/tabler/book.svg +20 -0
  249. data/registry/icons/tabler/building-store.svg +20 -0
  250. data/registry/icons/tabler/calendar.svg +21 -0
  251. data/registry/icons/tabler/chart-bar.svg +19 -0
  252. data/registry/icons/tabler/check.svg +16 -0
  253. data/registry/icons/tabler/chevron-down.svg +16 -0
  254. data/registry/icons/tabler/chevron-left.svg +16 -0
  255. data/registry/icons/tabler/chevron-right.svg +16 -0
  256. data/registry/icons/tabler/circle-check.svg +17 -0
  257. data/registry/icons/tabler/cloud.svg +16 -0
  258. data/registry/icons/tabler/credit-card.svg +19 -0
  259. data/registry/icons/tabler/device-desktop.svg +19 -0
  260. data/registry/icons/tabler/dots-vertical.svg +18 -0
  261. data/registry/icons/tabler/dots.svg +18 -0
  262. data/registry/icons/tabler/download.svg +18 -0
  263. data/registry/icons/tabler/eye-off.svg +18 -0
  264. data/registry/icons/tabler/eye.svg +17 -0
  265. data/registry/icons/tabler/file-plus.svg +19 -0
  266. data/registry/icons/tabler/file-text.svg +20 -0
  267. data/registry/icons/tabler/file.svg +17 -0
  268. data/registry/icons/tabler/folder.svg +16 -0
  269. data/registry/icons/tabler/git-branch.svg +21 -0
  270. data/registry/icons/tabler/grip-vertical.svg +21 -0
  271. data/registry/icons/tabler/home.svg +18 -0
  272. data/registry/icons/tabler/inbox.svg +17 -0
  273. data/registry/icons/tabler/info-circle.svg +18 -0
  274. data/registry/icons/tabler/italic.svg +18 -0
  275. data/registry/icons/tabler/keyboard.svg +23 -0
  276. data/registry/icons/tabler/layout-dashboard.svg +19 -0
  277. data/registry/icons/tabler/layout-grid.svg +19 -0
  278. data/registry/icons/tabler/layout-kanban.svg +19 -0
  279. data/registry/icons/tabler/layout-sidebar.svg +17 -0
  280. data/registry/icons/tabler/lifebuoy.svg +21 -0
  281. data/registry/icons/tabler/list.svg +21 -0
  282. data/registry/icons/tabler/loader.svg +23 -0
  283. data/registry/icons/tabler/lock.svg +18 -0
  284. data/registry/icons/tabler/logout.svg +18 -0
  285. data/registry/icons/tabler/mail.svg +17 -0
  286. data/registry/icons/tabler/menu-2.svg +18 -0
  287. data/registry/icons/tabler/message-circle.svg +16 -0
  288. data/registry/icons/tabler/minus.svg +16 -0
  289. data/registry/icons/tabler/moon.svg +16 -0
  290. data/registry/icons/tabler/news.svg +19 -0
  291. data/registry/icons/tabler/package.svg +20 -0
  292. data/registry/icons/tabler/percentage.svg +18 -0
  293. data/registry/icons/tabler/player-pause.svg +17 -0
  294. data/registry/icons/tabler/plus.svg +17 -0
  295. data/registry/icons/tabler/printer.svg +18 -0
  296. data/registry/icons/tabler/qrcode.svg +27 -0
  297. data/registry/icons/tabler/receipt.svg +16 -0
  298. data/registry/icons/tabler/rocket.svg +18 -0
  299. data/registry/icons/tabler/rosette-discount-check.svg +17 -0
  300. data/registry/icons/tabler/rotate-clockwise.svg +16 -0
  301. data/registry/icons/tabler/school.svg +17 -0
  302. data/registry/icons/tabler/search.svg +17 -0
  303. data/registry/icons/tabler/selector.svg +17 -0
  304. data/registry/icons/tabler/settings.svg +17 -0
  305. data/registry/icons/tabler/shield-check.svg +17 -0
  306. data/registry/icons/tabler/shield.svg +16 -0
  307. data/registry/icons/tabler/sitemap.svg +20 -0
  308. data/registry/icons/tabler/sun-moon.svg +21 -0
  309. data/registry/icons/tabler/sun.svg +17 -0
  310. data/registry/icons/tabler/trash.svg +20 -0
  311. data/registry/icons/tabler/truck.svg +18 -0
  312. data/registry/icons/tabler/underline.svg +17 -0
  313. data/registry/icons/tabler/upload.svg +18 -0
  314. data/registry/icons/tabler/user-plus.svg +19 -0
  315. data/registry/icons/tabler/user.svg +17 -0
  316. data/registry/icons/tabler/users.svg +19 -0
  317. data/registry/icons/tabler/world.svg +20 -0
  318. data/registry/icons/tabler/x.svg +17 -0
  319. data/registry/icons/tabler/zoom-in.svg +19 -0
  320. data/registry/icons/tabler/zoom-out.svg +18 -0
  321. data/registry/icons.yml +90 -0
  322. data/registry/test/components/previews/ui/chart_preview/cash_flow.html.erb +6 -0
  323. data/registry/test/components/previews/ui/chart_preview/donut.html.erb +6 -0
  324. data/registry/test/components/previews/ui/chart_preview/margin.html.erb +6 -0
  325. data/registry/test/components/previews/ui/chart_preview/pie.html.erb +6 -0
  326. data/registry/test/components/previews/ui/chart_preview/sales.html.erb +6 -0
  327. data/registry/test/components/previews/ui/chart_preview/stock.html.erb +6 -0
  328. data/registry/test/components/previews/ui/chart_preview/takings.html.erb +8 -0
  329. data/registry/test/components/previews/ui/chart_preview.rb +46 -0
  330. data/registry/test/components/previews/ui/command_preview/_picked.html.erb +14 -0
  331. data/registry/test/components/previews/ui/command_preview/dialog.html.erb +24 -0
  332. data/registry/test/components/previews/ui/command_preview/inline.html.erb +16 -0
  333. data/registry/test/components/previews/ui/command_preview/playground.html.erb +15 -0
  334. data/registry/test/components/previews/ui/command_preview/server_search.html.erb +24 -0
  335. data/registry/test/components/previews/ui/command_preview/shortcuts.html.erb +12 -0
  336. data/registry/test/components/previews/ui/command_preview/till.html.erb +17 -0
  337. data/registry/test/components/previews/ui/command_preview.rb +25 -0
  338. data/registry/test/components/previews/ui/confirm_dialog_preview/destructive.html.erb +7 -0
  339. data/registry/test/components/previews/ui/confirm_dialog_preview/in_form.html.erb +6 -0
  340. data/registry/test/components/previews/ui/confirm_dialog_preview/on_link.html.erb +5 -0
  341. data/registry/test/components/previews/ui/confirm_dialog_preview/plain.html.erb +3 -0
  342. data/registry/test/components/previews/ui/confirm_dialog_preview/with_description.html.erb +4 -0
  343. data/registry/test/components/previews/ui/confirm_dialog_preview.rb +20 -0
  344. data/registry/test/components/previews/ui/date_picker_preview/custom_presets.html.erb +6 -0
  345. data/registry/test/components/previews/ui/date_picker_preview/in_form.html.erb +11 -0
  346. data/registry/test/components/previews/ui/date_picker_preview/range.html.erb +5 -0
  347. data/registry/test/components/previews/ui/date_picker_preview/states.html.erb +4 -3
  348. data/registry/test/components/previews/ui/date_picker_preview.rb +26 -6
  349. data/registry/test/components/previews/ui/empty_state_preview/in_card.html.erb +7 -0
  350. data/registry/test/components/previews/ui/empty_state_preview/no_results.html.erb +3 -0
  351. data/registry/test/components/previews/ui/empty_state_preview/outline.html.erb +3 -0
  352. data/registry/test/components/previews/ui/empty_state_preview/with_actions.html.erb +4 -0
  353. data/registry/test/components/previews/ui/empty_state_preview/with_media.html.erb +8 -0
  354. data/registry/test/components/previews/ui/empty_state_preview.rb +26 -0
  355. data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +1 -1
  356. data/registry/test/components/previews/ui/file_field_preview/product_photos.html.erb +12 -0
  357. data/registry/test/components/previews/ui/file_field_preview/single_image.html.erb +4 -0
  358. data/registry/test/components/previews/ui/file_field_preview.rb +32 -5
  359. data/registry/test/components/previews/ui/gallery_preview/hover_zoom.html.erb +13 -0
  360. data/registry/test/components/previews/ui/gallery_preview/landscape.html.erb +5 -0
  361. data/registry/test/components/previews/ui/gallery_preview/product_page.html.erb +13 -0
  362. data/registry/test/components/previews/ui/gallery_preview/single.html.erb +3 -0
  363. data/registry/test/components/previews/ui/gallery_preview.rb +45 -0
  364. data/registry/test/components/previews/ui/icon_preview/common.html.erb +19 -3
  365. data/registry/test/components/previews/ui/icon_preview/labelled.html.erb +4 -0
  366. data/registry/test/components/previews/ui/icon_preview/missing.html.erb +3 -0
  367. data/registry/test/components/previews/ui/icon_preview.rb +18 -3
  368. data/registry/test/components/previews/ui/input_group_preview/playground.html.erb +2 -2
  369. data/registry/test/components/previews/ui/input_group_preview.rb +3 -3
  370. data/registry/test/components/previews/ui/kbd_preview/bound.html.erb +20 -0
  371. data/registry/test/components/previews/ui/kbd_preview/keys.html.erb +13 -0
  372. data/registry/test/components/previews/ui/kbd_preview/menu.html.erb +13 -0
  373. data/registry/test/components/previews/ui/kbd_preview/search_field.html.erb +8 -0
  374. data/registry/test/components/previews/ui/kbd_preview/shortcuts_list.html.erb +17 -0
  375. data/registry/test/components/previews/ui/kbd_preview/till.html.erb +23 -0
  376. data/registry/test/components/previews/ui/kbd_preview/tooltip_and_buttons.html.erb +14 -0
  377. data/registry/test/components/previews/ui/kbd_preview.rb +32 -0
  378. data/registry/test/components/previews/ui/number_input_preview/cart.html.erb +11 -0
  379. data/registry/test/components/previews/ui/number_input_preview/decimals.html.erb +4 -0
  380. data/registry/test/components/previews/ui/number_input_preview/sizes.html.erb +5 -0
  381. data/registry/test/components/previews/ui/number_input_preview/states.html.erb +7 -0
  382. data/registry/test/components/previews/ui/number_input_preview/stock_adjustment.html.erb +3 -0
  383. data/registry/test/components/previews/ui/number_input_preview.rb +36 -0
  384. data/registry/test/components/previews/ui/progress_preview/file_upload.html.erb +36 -0
  385. data/registry/test/components/previews/ui/progress_preview/free_shipping.html.erb +4 -0
  386. data/registry/test/components/previews/ui/progress_preview/indeterminate.html.erb +4 -0
  387. data/registry/test/components/previews/ui/progress_preview/sizes_and_tones.html.erb +8 -0
  388. data/registry/test/components/previews/ui/progress_preview/steps.html.erb +9 -0
  389. data/registry/test/components/previews/ui/progress_preview/storage.html.erb +8 -0
  390. data/registry/test/components/previews/ui/progress_preview/storage_by_category.html.erb +7 -0
  391. data/registry/test/components/previews/ui/progress_preview/tasks_by_status.html.erb +14 -0
  392. data/registry/test/components/previews/ui/progress_preview/traffic_by_source.html.erb +15 -0
  393. data/registry/test/components/previews/ui/progress_preview.rb +46 -0
  394. data/registry/test/components/previews/ui/select_preview/server_search.html.erb +22 -0
  395. data/registry/test/components/previews/ui/select_preview.rb +5 -0
  396. data/registry/test/components/previews/ui/stepper_preview/approvals.html.erb +9 -0
  397. data/registry/test/components/previews/ui/stepper_preview/checklist.html.erb +12 -0
  398. data/registry/test/components/previews/ui/stepper_preview/dot_wizard.html.erb +41 -0
  399. data/registry/test/components/previews/ui/stepper_preview/failed_deploy.html.erb +13 -0
  400. data/registry/test/components/previews/ui/stepper_preview/inline.html.erb +31 -0
  401. data/registry/test/components/previews/ui/stepper_preview/onboarding.html.erb +12 -0
  402. data/registry/test/components/previews/ui/stepper_preview/order_tracking.html.erb +10 -0
  403. data/registry/test/components/previews/ui/stepper_preview/price_calculator.html.erb +14 -0
  404. data/registry/test/components/previews/ui/stepper_preview/server_driven.html.erb +20 -0
  405. data/registry/test/components/previews/ui/stepper_preview/sidebar.html.erb +43 -0
  406. data/registry/test/components/previews/ui/stepper_preview/wizard.html.erb +55 -0
  407. data/registry/test/components/previews/ui/stepper_preview.rb +57 -0
  408. data/registry/test/components/previews/ui/timeline_preview/activity_log.html.erb +7 -0
  409. data/registry/test/components/previews/ui/timeline_preview/colored.html.erb +7 -0
  410. data/registry/test/components/previews/ui/timeline_preview/colored_by_meaning.html.erb +7 -0
  411. data/registry/test/components/previews/ui/timeline_preview/failed_delivery.html.erb +6 -0
  412. data/registry/test/components/previews/ui/timeline_preview/order_status.html.erb +9 -0
  413. data/registry/test/components/previews/ui/timeline_preview/real_dates.html.erb +5 -0
  414. data/registry/test/components/previews/ui/timeline_preview/stock_history.html.erb +6 -0
  415. data/registry/test/components/previews/ui/timeline_preview.rb +40 -0
  416. data/registry/test/components/previews/ui/toggle_group_preview/icon_only.html.erb +5 -0
  417. data/registry/test/components/previews/ui/toggle_group_preview/in_form.html.erb +11 -0
  418. data/registry/test/components/previews/ui/toggle_group_preview/multiple.html.erb +5 -0
  419. data/registry/test/components/previews/ui/toggle_group_preview/outline.html.erb +5 -0
  420. data/registry/test/components/previews/ui/toggle_group_preview/sizes.html.erb +9 -0
  421. data/registry/test/components/previews/ui/toggle_group_preview/with_icons.html.erb +5 -0
  422. data/registry/test/components/previews/ui/toggle_group_preview.rb +36 -0
  423. data/registry/test/components/ui/accordion/trigger_test.rb +1 -1
  424. data/registry/test/components/ui/alert_test.rb +10 -10
  425. data/registry/test/components/ui/badge_test.rb +3 -3
  426. data/registry/test/components/ui/banner_test.rb +3 -3
  427. data/registry/test/components/ui/breadcrumb/ellipsis_test.rb +2 -2
  428. data/registry/test/components/ui/button_test.rb +17 -14
  429. data/registry/test/components/ui/button_to_test.rb +2 -2
  430. data/registry/test/components/ui/chart_test.rb +187 -0
  431. data/registry/test/components/ui/checkbox_test.rb +2 -2
  432. data/registry/test/components/ui/command/group_test.rb +19 -0
  433. data/registry/test/components/ui/command/item_test.rb +47 -0
  434. data/registry/test/components/ui/command_test.rb +110 -0
  435. data/registry/test/components/ui/confirm_dialog_test.rb +68 -0
  436. data/registry/test/components/ui/date_picker_test.rb +129 -111
  437. data/registry/test/components/ui/empty_state_test.rb +87 -0
  438. data/registry/test/components/ui/file_field_test.rb +105 -9
  439. data/registry/test/components/ui/gallery_test.rb +192 -0
  440. data/registry/test/components/ui/icon_test.rb +60 -20
  441. data/registry/test/components/ui/input_group_test.rb +1 -1
  442. data/registry/test/components/ui/kbd_test.rb +150 -0
  443. data/registry/test/components/ui/link_test.rb +3 -3
  444. data/registry/test/components/ui/navigation_menu_test.rb +2 -2
  445. data/registry/test/components/ui/number_input_test.rb +155 -0
  446. data/registry/test/components/ui/progress_test.rb +188 -0
  447. data/registry/test/components/ui/select_test.rb +62 -0
  448. data/registry/test/components/ui/session_tabs_test.rb +3 -3
  449. data/registry/test/components/ui/spinner_test.rb +9 -9
  450. data/registry/test/components/ui/stepper_test.rb +239 -0
  451. data/registry/test/components/ui/tabs/trigger_test.rb +2 -2
  452. data/registry/test/components/ui/theme_toggle_test.rb +6 -8
  453. data/registry/test/components/ui/timeline_test.rb +175 -0
  454. data/registry/test/components/ui/toast_test.rb +11 -10
  455. data/registry/test/components/ui/toggle_group_test.rb +162 -0
  456. metadata +399 -3
  457. data/registry/app/javascript/cally.ts +0 -8
  458. data/registry/app/javascript/velvetkit_icons.ts +0 -78
@@ -0,0 +1,111 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ // Connects to data-controller="ui--number-input"
4
+ //
5
+ // The stepping itself is the browser's: stepUp() and stepDown() already respect
6
+ // min, max and step, and don't drift on decimals. This adds holding a button to
7
+ // keep counting, and turns a button off at its limit.
8
+ const HOLD_DELAY = 400;
9
+ const REPEAT_EVERY = 100;
10
+
11
+ type Direction = 'up' | 'down';
12
+ type StepEvent<E extends Event> = E & { params: { direction: Direction } };
13
+
14
+ export default class extends Controller<HTMLElement> {
15
+ static targets = ['input', 'decrement', 'increment'];
16
+
17
+ declare readonly inputTarget: HTMLInputElement;
18
+ declare readonly decrementTarget: HTMLButtonElement;
19
+ declare readonly incrementTarget: HTMLButtonElement;
20
+
21
+ private holdTimer?: number;
22
+ private repeatTimer?: number;
23
+ private changed = false;
24
+
25
+ connect() {
26
+ this.sync();
27
+ }
28
+
29
+ disconnect() {
30
+ this.release();
31
+ }
32
+
33
+ // One step at once, then repeating until the button is let go. Listens on the
34
+ // window: a button that reaches its limit is disabled, and a disabled button
35
+ // doesn't hear the pointer come up.
36
+ press(event: StepEvent<PointerEvent>) {
37
+ if (event.button !== 0) return;
38
+
39
+ this.release();
40
+ const { direction } = event.params;
41
+ if (!this.step(direction)) return;
42
+
43
+ window.addEventListener('pointerup', this.release);
44
+ window.addEventListener('pointercancel', this.release);
45
+ window.addEventListener('blur', this.release);
46
+ this.holdTimer = window.setTimeout(() => {
47
+ this.repeatTimer = window.setInterval(() => {
48
+ if (!this.step(direction)) this.stopRepeating();
49
+ }, REPEAT_EVERY);
50
+ }, HOLD_DELAY);
51
+ }
52
+
53
+ // A pointer has already stepped in press(). A click with no pointer behind it
54
+ // (detail 0) is the keyboard or a screen reader.
55
+ click(event: StepEvent<MouseEvent>) {
56
+ if (event.detail !== 0) return;
57
+
58
+ if (this.step(event.params.direction)) this.release();
59
+ }
60
+
61
+ sync() {
62
+ const input = this.inputTarget;
63
+ const locked = input.disabled || input.readOnly;
64
+ const value = input.valueAsNumber;
65
+ this.decrementTarget.disabled = locked || value <= parseFloat(input.min);
66
+ this.incrementTarget.disabled = locked || value >= parseFloat(input.max);
67
+ }
68
+
69
+ private release = () => {
70
+ this.stopRepeating();
71
+ window.removeEventListener('pointerup', this.release);
72
+ window.removeEventListener('pointercancel', this.release);
73
+ window.removeEventListener('blur', this.release);
74
+ if (!this.changed) return;
75
+
76
+ this.changed = false;
77
+ this.inputTarget.dispatchEvent(new Event('change', { bubbles: true }));
78
+ };
79
+
80
+ private stopRepeating() {
81
+ window.clearTimeout(this.holdTimer);
82
+ window.clearInterval(this.repeatTimer);
83
+ }
84
+
85
+ private step(direction: Direction): boolean {
86
+ const input = this.inputTarget;
87
+ const before = input.value;
88
+
89
+ if (input.step === 'any') {
90
+ this.stepByOne(direction);
91
+ } else if (direction === 'up') {
92
+ input.stepUp();
93
+ } else {
94
+ input.stepDown();
95
+ }
96
+ if (input.value === before) return false;
97
+
98
+ this.changed = true;
99
+ input.dispatchEvent(new Event('input', { bubbles: true }));
100
+ return true;
101
+ }
102
+
103
+ // stepUp() throws on step="any", and limits are then up to us.
104
+ private stepByOne(direction: Direction) {
105
+ const input = this.inputTarget;
106
+ const next = (input.valueAsNumber || 0) + (direction === 'up' ? 1 : -1);
107
+ const min = parseFloat(input.min);
108
+ const max = parseFloat(input.max);
109
+ input.value = String(Math.min(Number.isNaN(max) ? next : max, Math.max(Number.isNaN(min) ? next : min, next)));
110
+ }
111
+ }
@@ -0,0 +1,87 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ // Connects to data-controller="ui--progress"
4
+ //
5
+ // Moves the bar when its value changes. Set the value from anywhere, an
6
+ // upload's progress event for one:
7
+ //
8
+ // bar.setAttribute('data-ui--progress-value-value', String(loaded / total * 100))
9
+ //
10
+ // Removing the attribute puts it back to "working on it", with no amount.
11
+ // The bar is drawn by the server first, so with no JavaScript it still shows
12
+ // where things stood; this only keeps it moving.
13
+ export default class extends Controller<HTMLElement> {
14
+ static targets = ['bar', 'indicator', 'text'];
15
+ static values = { value: Number, max: { type: Number, default: 100 }, format: { type: String, default: '%{percent}%' } };
16
+ static classes = ['determinate', 'indeterminate'];
17
+
18
+ declare readonly barTarget: HTMLElement;
19
+ declare readonly indicatorTarget: HTMLElement;
20
+ declare readonly textTarget: HTMLElement;
21
+ declare readonly hasTextTarget: boolean;
22
+ declare valueValue: number;
23
+ declare readonly hasValueValue: boolean;
24
+ declare readonly maxValue: number;
25
+ declare readonly formatValue: string;
26
+ declare readonly determinateClasses: string[];
27
+ declare readonly indeterminateClasses: string[];
28
+
29
+ private wasComplete = false;
30
+
31
+ connect() {
32
+ this.wasComplete = this.barTarget.dataset.state === 'complete';
33
+ }
34
+
35
+ valueValueChanged() {
36
+ if (!this.hasBarTarget) return;
37
+ this.hasValueValue ? this.showAmount() : this.showWorking();
38
+ }
39
+
40
+ maxValueChanged() {
41
+ this.valueValueChanged();
42
+ }
43
+
44
+ private showAmount() {
45
+ const max = this.maxValue > 0 ? this.maxValue : 100;
46
+ const value = Math.min(Math.max(this.valueValue, 0), max);
47
+ // Rounded down, so it never says 100% before it's done.
48
+ const percent = Math.floor((value / max) * 100);
49
+ const text = this.formatValue
50
+ .replaceAll('%{value}', this.number(value))
51
+ .replaceAll('%{max}', this.number(max))
52
+ .replaceAll('%{percent}', String(percent));
53
+ const complete = value >= max;
54
+
55
+ this.indicatorTarget.classList.remove(...this.indeterminateClasses);
56
+ this.indicatorTarget.classList.add(...this.determinateClasses);
57
+ this.indicatorTarget.style.width = `${percent}%`;
58
+ this.barTarget.dataset.state = complete ? 'complete' : 'loading';
59
+ this.barTarget.setAttribute('aria-valuenow', this.number(value));
60
+ this.barTarget.setAttribute('aria-valuemax', this.number(max));
61
+ this.barTarget.setAttribute('aria-valuetext', text);
62
+ this.barTarget.toggleAttribute('aria-busy', !complete);
63
+ if (this.hasTextTarget) this.textTarget.textContent = text;
64
+
65
+ if (complete && !this.wasComplete) this.dispatch('complete', { detail: { value, max } });
66
+ this.wasComplete = complete;
67
+ }
68
+
69
+ private showWorking() {
70
+ this.indicatorTarget.classList.remove(...this.determinateClasses);
71
+ this.indicatorTarget.classList.add(...this.indeterminateClasses);
72
+ this.indicatorTarget.style.removeProperty('width');
73
+ this.barTarget.dataset.state = 'indeterminate';
74
+ this.barTarget.removeAttribute('aria-valuenow');
75
+ this.barTarget.removeAttribute('aria-valuetext');
76
+ this.barTarget.setAttribute('aria-busy', 'true');
77
+ if (this.hasTextTarget) this.textTarget.textContent = '';
78
+ this.wasComplete = false;
79
+ }
80
+
81
+ // 3, not 3.0; 2.5 stays 2.5.
82
+ private number(n: number) {
83
+ return Number.isInteger(n) ? String(n) : String(Math.round(n * 100) / 100);
84
+ }
85
+
86
+ declare readonly hasBarTarget: boolean;
87
+ }
@@ -11,9 +11,28 @@ import { useDismiss } from './_internal/use_dismiss.js';
11
11
  // The hidden native <select> holds the value. Every pick is written to it and
12
12
  // announced with `input` and `change`, so forms and listeners see an ordinary
13
13
  // select. A multiple select stays open while you tick options.
14
+ //
15
+ // With a `url`, the search box asks the server instead of filtering what's on
16
+ // the page. A picked option is added to the native select if it isn't there
17
+ // yet, so it submits, and stays chosen when it drops out of later results.
18
+ const SEARCH_DELAY = 250;
19
+ const SLOW_SEARCH = 200;
20
+ // How long a search's results are reused instead of asked for again.
21
+ const REMEMBER_FOR = 60_000;
22
+
23
+ type Result = { value: string; label: string };
24
+
25
+ // Results by URL, shared by every select on the page that asks the same
26
+ // server the same thing, so reopening a list or retyping a search is instant.
27
+ const remembered = new Map<string, { at: number; results: Result[] }>();
28
+ // Searches on their way, by URL, so the same one is never asked for twice.
29
+ const pending = new Map<string, Promise<Result[]>>();
14
30
  export default class extends Controller<HTMLElement> {
15
- static targets = ['trigger', 'value', 'panel', 'listbox', 'option', 'native', 'search', 'empty'];
16
- static values = { multiple: Boolean, summary: String, placeholder: String };
31
+ static targets = ['trigger', 'value', 'panel', 'listbox', 'option', 'native', 'search', 'empty', 'status', 'template', 'searchIcon', 'spinner'];
32
+ static values = {
33
+ multiple: Boolean, summary: String, placeholder: String,
34
+ url: String, param: { type: String, default: 'q' }, searching: String, failed: String,
35
+ };
17
36
 
18
37
  declare readonly triggerTarget: HTMLButtonElement;
19
38
  declare readonly valueTarget: HTMLElement;
@@ -27,6 +46,18 @@ export default class extends Controller<HTMLElement> {
27
46
  declare readonly multipleValue: boolean;
28
47
  declare readonly summaryValue: string;
29
48
  declare readonly placeholderValue: string;
49
+ declare readonly listboxTarget: HTMLElement;
50
+ declare readonly hasStatusTarget: boolean;
51
+ declare readonly statusTarget: HTMLElement;
52
+ declare readonly templateTarget: HTMLTemplateElement;
53
+ declare readonly hasSpinnerTarget: boolean;
54
+ declare readonly spinnerTarget: HTMLElement;
55
+ declare readonly searchIconTarget: HTMLElement;
56
+ declare readonly hasUrlValue: boolean;
57
+ declare readonly urlValue: string;
58
+ declare readonly paramValue: string;
59
+ declare readonly searchingValue: string;
60
+ declare readonly failedValue: string;
30
61
 
31
62
  private isOpen = false;
32
63
  private active: HTMLElement | null = null;
@@ -34,6 +65,12 @@ export default class extends Controller<HTMLElement> {
34
65
  private typedAt = 0;
35
66
  private floatingCleanup: (() => void) | null = null;
36
67
  private dismissCleanup: (() => void) | null = null;
68
+ // The search whose results the list is waiting for. An older one still on
69
+ // its way finishes and is remembered, but doesn't fill the list.
70
+ private latestKey = '';
71
+ private searchTimer?: number;
72
+ private slowTimer?: number;
73
+ private resultCount = 0;
37
74
  private onReset = () => requestAnimationFrame(() => this.sync());
38
75
  private onInvalid = () => this.triggerTarget.setAttribute('aria-invalid', 'true');
39
76
 
@@ -46,6 +83,7 @@ export default class extends Controller<HTMLElement> {
46
83
  disconnect() {
47
84
  this.nativeTarget.form?.removeEventListener('reset', this.onReset);
48
85
  this.nativeTarget.removeEventListener('invalid', this.onInvalid);
86
+ this.stopSearch();
49
87
  this.teardown();
50
88
  }
51
89
 
@@ -63,6 +101,12 @@ export default class extends Controller<HTMLElement> {
63
101
  if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {
64
102
  event.preventDefault();
65
103
  this.open(event.key === 'ArrowUp' ? 'last' : 'first');
104
+ } else if (this.isPrintable(event) && this.remote) {
105
+ // Typing on a closed server-searched select starts a search with it.
106
+ event.preventDefault();
107
+ this.open();
108
+ this.searchTarget.value = event.key;
109
+ this.filter();
66
110
  } else if (this.isPrintable(event) && !this.multipleValue) {
67
111
  this.typeahead(event.key, true);
68
112
  }
@@ -108,6 +152,11 @@ export default class extends Controller<HTMLElement> {
108
152
 
109
153
  filter() {
110
154
  if (!this.hasSearchTarget) return;
155
+ if (this.remote) {
156
+ window.clearTimeout(this.searchTimer);
157
+ this.searchTimer = window.setTimeout(() => this.fetchResults(this.searchTarget.value.trim()), SEARCH_DELAY);
158
+ return;
159
+ }
111
160
 
112
161
  const query = this.searchTarget.value.trim().toLowerCase();
113
162
  this.optionTargets.forEach((option) => {
@@ -154,7 +203,9 @@ export default class extends Controller<HTMLElement> {
154
203
 
155
204
  if (this.hasSearchTarget) {
156
205
  this.searchTarget.value = '';
157
- this.filter();
206
+ // A server-searched list starts with what the server offers for nothing typed.
207
+ if (this.remote) this.fetchResults('');
208
+ else this.filter();
158
209
  this.searchTarget.focus();
159
210
  }
160
211
 
@@ -167,6 +218,7 @@ export default class extends Controller<HTMLElement> {
167
218
  if (!this.isOpen) return;
168
219
 
169
220
  this.teardown();
221
+ this.stopSearch();
170
222
  this.panelTarget.hidden = true;
171
223
  this.panelTarget.dataset.state = 'closed';
172
224
  this.triggerTarget.setAttribute('aria-expanded', 'false');
@@ -181,9 +233,15 @@ export default class extends Controller<HTMLElement> {
181
233
  const native = this.nativeTarget;
182
234
  const before = Array.from(native.selectedOptions).map((o) => o.value).join('\n');
183
235
 
236
+ // A fetched option the native select hasn't seen yet joins it, so it submits.
237
+ let item = Array.from(native.options).find((o) => o.value === value);
238
+ if (!item) {
239
+ item = new Option(this.label(option), value);
240
+ native.add(item);
241
+ }
242
+
184
243
  if (this.multipleValue) {
185
- const item = Array.from(native.options).find((o) => o.value === value);
186
- if (item) item.selected = !item.selected;
244
+ item.selected = !item.selected;
187
245
  } else {
188
246
  native.value = value;
189
247
  }
@@ -207,9 +265,10 @@ export default class extends Controller<HTMLElement> {
207
265
  if (check) check.hidden = !on;
208
266
  });
209
267
 
210
- const labels = this.optionTargets
211
- .filter((o) => o.dataset.value !== '' && chosen.has(o.dataset.value ?? ''))
212
- .map((o) => this.label(o));
268
+ // Named from the native select, which also holds choices no longer in the list.
269
+ const labels = Array.from(this.nativeTarget.selectedOptions)
270
+ .filter((o) => o.value !== '')
271
+ .map((o) => o.text.trim());
213
272
  const text = labels.length > 2 ? this.summaryValue.replace('%{count}', String(labels.length)) : labels.join(', ');
214
273
  this.valueTarget.textContent = text || this.placeholderValue;
215
274
  this.valueTarget.classList.toggle('text-muted-foreground', !text);
@@ -248,6 +307,137 @@ export default class extends Controller<HTMLElement> {
248
307
  else this.highlight(match);
249
308
  }
250
309
 
310
+ // ── Searching the server ─────────────────────────────────────────────────
311
+
312
+ private get remote(): boolean {
313
+ return this.hasUrlValue && this.urlValue !== '' && this.hasSearchTarget;
314
+ }
315
+
316
+ // Asks for the options matching `query`: from the last minute's results if
317
+ // it can, joining the same search if it's already on its way, otherwise
318
+ // from the server. Nothing is cancelled, since the server has the request
319
+ // either way; an outdated answer is kept for later but only the newest
320
+ // search fills the list.
321
+ private async fetchResults(query: string) {
322
+ const url = new URL(this.urlValue, window.location.href);
323
+ url.searchParams.set(this.paramValue, query);
324
+ const key = url.toString();
325
+ this.latestKey = key;
326
+ window.clearTimeout(this.slowTimer);
327
+
328
+ const known = remembered.get(key);
329
+ if (known && Date.now() - known.at < REMEMBER_FOR) {
330
+ this.showResults(known.results);
331
+ this.showStatus(null);
332
+ return;
333
+ }
334
+
335
+ this.listboxTarget.setAttribute('aria-busy', 'true');
336
+ this.slowTimer = window.setTimeout(() => this.showStatus(this.searchingValue, true), SLOW_SEARCH);
337
+ try {
338
+ const results = await this.ask(url, key);
339
+ if (this.latestKey !== key || !this.isOpen) return;
340
+
341
+ this.showResults(results);
342
+ this.showStatus(null);
343
+ } catch {
344
+ if (this.latestKey !== key || !this.isOpen) return;
345
+
346
+ this.showResults([]);
347
+ if (this.hasEmptyTarget) this.emptyTarget.hidden = true;
348
+ this.showStatus(this.failedValue);
349
+ } finally {
350
+ if (this.latestKey === key) this.listboxTarget.removeAttribute('aria-busy');
351
+ }
352
+ }
353
+
354
+ private ask(url: URL, key: string): Promise<Result[]> {
355
+ let request = pending.get(key);
356
+ if (!request) {
357
+ request = fetch(url, { headers: { Accept: 'application/json' } })
358
+ .then((response) => {
359
+ if (!response.ok) throw new Error(`${response.status}`);
360
+ return response.json();
361
+ })
362
+ .then((data) => {
363
+ const results = this.normalise(data);
364
+ remembered.set(key, { at: Date.now(), results });
365
+ return results;
366
+ })
367
+ .finally(() => pending.delete(key));
368
+ pending.set(key, request);
369
+ }
370
+ return request;
371
+ }
372
+
373
+ // Accepts [{ value, label }] or [[label, value]], as the server prefers.
374
+ private normalise(data: unknown): Result[] {
375
+ if (!Array.isArray(data)) return [];
376
+
377
+ return data.flatMap((item) => {
378
+ if (Array.isArray(item)) return [{ label: String(item[0] ?? ''), value: String(item[1] ?? '') }];
379
+ if (item && typeof item === 'object') {
380
+ const { value, label } = item as { value?: unknown; label?: unknown };
381
+ return [{ value: String(value ?? ''), label: String(label ?? value ?? '') }];
382
+ }
383
+ return [];
384
+ });
385
+ }
386
+
387
+ // Swaps the listed options for the new results. The empty "prompt" option,
388
+ // if there is one, stays first.
389
+ private showResults(results: Result[]) {
390
+ this.optionTargets.filter((o) => o.dataset.value !== '').forEach((o) => o.remove());
391
+ const base = this.listboxTarget.id;
392
+ results.forEach((result) => {
393
+ const option = this.templateTarget.content.firstElementChild!.cloneNode(true) as HTMLElement;
394
+ option.id = `${base}-result-${this.resultCount++}`;
395
+ option.dataset.value = result.value;
396
+ option.querySelector('.truncate')!.textContent = result.label;
397
+ this.listboxTarget.append(option);
398
+ });
399
+
400
+ this.sync();
401
+ if (this.hasEmptyTarget) this.emptyTarget.hidden = results.length > 0;
402
+ const visible = this.visible();
403
+ const chosen = visible.find((o) => o.getAttribute('aria-selected') === 'true' && o.dataset.value !== '');
404
+ this.highlight(chosen ?? visible.find((o) => o.dataset.value !== '') ?? visible[0] ?? null);
405
+ }
406
+
407
+ // A slow search shows as a spinner in the search box, where people are
408
+ // looking, and is said to screen readers; a failure is written out for all.
409
+ private showStatus(text: string | null, busy = false) {
410
+ if (!this.hasStatusTarget) return;
411
+
412
+ window.clearTimeout(this.slowTimer);
413
+ this.statusTarget.textContent = text ?? '';
414
+ this.statusTarget.hidden = !text;
415
+ this.statusTarget.classList.toggle('sr-only', busy);
416
+ this.setSpinning(busy);
417
+ if (busy && this.hasEmptyTarget) this.emptyTarget.hidden = true;
418
+ }
419
+
420
+ private setSpinning(on: boolean) {
421
+ if (!this.hasSpinnerTarget) return;
422
+
423
+ this.spinnerTarget.classList.toggle('hidden', !on);
424
+ this.spinnerTarget.classList.toggle('flex', on);
425
+ this.searchIconTarget.classList.toggle('hidden', on);
426
+ this.searchIconTarget.classList.toggle('flex', !on);
427
+ }
428
+
429
+ // Closing, or leaving the page, stops the search waiting to be asked and
430
+ // the spinner. One already on its way still finishes and is remembered, so
431
+ // its results are there on reopening; it just doesn't fill a closed list.
432
+ private stopSearch() {
433
+ window.clearTimeout(this.searchTimer);
434
+ window.clearTimeout(this.slowTimer);
435
+ this.latestKey = '';
436
+ this.setSpinning(false);
437
+ this.listboxTarget.removeAttribute('aria-busy');
438
+ if (this.hasStatusTarget) this.statusTarget.hidden = true;
439
+ }
440
+
251
441
  private visible() {
252
442
  return this.optionTargets.filter((o) => !o.hidden);
253
443
  }
@@ -0,0 +1,187 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ type Status = 'complete' | 'current' | 'upcoming' | 'error' | 'loading';
4
+
5
+ // Moves a UI::Stepper between its steps in the browser. Every step's look hangs
6
+ // off its data-status, so this sets that, aria-current, and which panel shows.
7
+ // Moving on checks the current panel's fields first; an invalid one keeps
8
+ // someone on the step and marks it as an error until it's fixed. Going back
9
+ // keeps the steps after it done, so a click on one returns there, checking
10
+ // each panel on the way.
11
+ export default class extends Controller<HTMLElement> {
12
+ static targets = ['step', 'panel', 'completion', 'previous', 'next', 'submit', 'summary'];
13
+ static values = { current: { type: Number, default: 1 }, summary: String };
14
+
15
+ declare readonly stepTargets: HTMLElement[];
16
+ declare readonly panelTargets: HTMLElement[];
17
+ declare readonly completionTargets: HTMLElement[];
18
+ declare readonly previousTargets: HTMLButtonElement[];
19
+ declare readonly nextTargets: HTMLElement[];
20
+ declare readonly submitTargets: HTMLElement[];
21
+ declare readonly summaryTargets: HTMLElement[];
22
+ declare currentValue: number;
23
+ declare summaryValue: string;
24
+
25
+ // The furthest step reached; the ones before it stay done while someone
26
+ // goes back to change an answer.
27
+ private furthest = 1;
28
+
29
+ connect() {
30
+ // The server drew the steps as they are; only the buttons need setting.
31
+ this.furthest = this.currentValue;
32
+ this.syncButtons();
33
+ }
34
+
35
+ next() {
36
+ if (this.currentValue > this.total) return;
37
+ if (!this.validate()) return;
38
+ this.go(this.currentValue + 1);
39
+ }
40
+
41
+ previous() {
42
+ if (this.currentValue > 1) this.go(this.currentValue - 1);
43
+ }
44
+
45
+ reset() {
46
+ this.furthest = 1;
47
+ this.go(1);
48
+ }
49
+
50
+ // A done step's title (or indicator) was clicked: go to it.
51
+ select(event: Event) {
52
+ const step = (event.currentTarget as HTMLElement).closest<HTMLElement>('[data-ui--stepper-target~="step"]');
53
+ const index = step ? this.stepTargets.indexOf(step) : -1;
54
+ if (index >= 0 && step?.dataset.status === 'complete') this.travel(index + 1);
55
+ }
56
+
57
+ // data-action="ui--stepper#goTo" data-ui--stepper-step-param="2".
58
+ goTo(event: Event & { params: { step?: number | string } }) {
59
+ const step = Number(event.params.step);
60
+ if (step >= 1 && step <= this.total + 1) this.travel(step);
61
+ }
62
+
63
+ // Enter in a field moves on, rather than submitting the form underneath from
64
+ // the first step. On the last step it submits as usual.
65
+ keydown(event: KeyboardEvent) {
66
+ const field = event.target as HTMLElement;
67
+ if (event.key !== 'Enter' || !(field instanceof HTMLInputElement)) return;
68
+ if (!this.panelTargets.length || this.currentValue >= this.total) return;
69
+ if (!this.currentPanel?.contains(field)) return;
70
+ event.preventDefault();
71
+ this.next();
72
+ }
73
+
74
+ // Back to plain "current" once an invalid panel's fields are all valid.
75
+ revalidate() {
76
+ const step = this.currentStep;
77
+ if (step?.dataset.status !== 'error' || !this.currentPanel) return;
78
+ if (this.fields(this.currentPanel).every((field) => field.checkValidity())) this.setStatus(step, 'current');
79
+ }
80
+
81
+ // A form inside the stepper being checked on the server: a spinner on the
82
+ // step until the answer comes back and replaces the stepper, or fails.
83
+ submitting() {
84
+ const step = this.currentStep;
85
+ if (step) this.setStatus(step, 'loading');
86
+ }
87
+
88
+ submitted(event: CustomEvent<{ success: boolean }>) {
89
+ const step = this.currentStep;
90
+ if (step?.dataset.status === 'loading') this.setStatus(step, event.detail.success ? 'current' : 'error');
91
+ }
92
+
93
+ private get total() {
94
+ return this.stepTargets.length;
95
+ }
96
+
97
+ private get currentStep(): HTMLElement | undefined {
98
+ return this.stepTargets[this.currentValue - 1];
99
+ }
100
+
101
+ private get currentPanel(): HTMLElement | undefined {
102
+ return this.panelTargets.find((panel) => Number(panel.dataset.step) === this.currentValue);
103
+ }
104
+
105
+ private fields(panel: HTMLElement) {
106
+ return Array.from(panel.querySelectorAll<HTMLInputElement>('input, select, textarea')).filter(
107
+ (field) => !field.disabled && field.willValidate,
108
+ );
109
+ }
110
+
111
+ // Straight back; forward a step at a time, stopping at a panel that's wrong.
112
+ private travel(step: number) {
113
+ if (step < this.currentValue) return this.go(step);
114
+ while (this.currentValue < step) {
115
+ if (!this.validate()) return;
116
+ this.go(this.currentValue + 1);
117
+ }
118
+ }
119
+
120
+ private validate() {
121
+ const panel = this.currentPanel;
122
+ const step = this.currentStep;
123
+ if (!panel || !step) return true;
124
+ const invalid = this.fields(panel).find((field) => !field.checkValidity());
125
+ if (!invalid) return true;
126
+ this.setStatus(step, 'error');
127
+ invalid.reportValidity();
128
+ invalid.focus();
129
+ return false;
130
+ }
131
+
132
+ private go(step: number) {
133
+ const back = step < this.currentValue;
134
+ // Turns on the enter animations, which a page load shouldn't play.
135
+ this.element.dataset.moved = '';
136
+ this.element.dataset.direction = back ? 'back' : 'forward';
137
+ this.currentValue = step;
138
+ this.furthest = Math.max(this.furthest, step);
139
+ this.sync();
140
+ }
141
+
142
+ private setStatus(step: HTMLElement, status: Status) {
143
+ step.dataset.status = status;
144
+ step.querySelectorAll<HTMLButtonElement>('button[data-action~="ui--stepper#select"]').forEach((button) => {
145
+ button.disabled = status !== 'complete';
146
+ });
147
+ if (status === 'current' || status === 'loading') step.setAttribute('aria-current', 'step');
148
+ else step.removeAttribute('aria-current');
149
+ }
150
+
151
+ private sync() {
152
+ const current = this.currentValue;
153
+ const finished = current > this.total;
154
+
155
+ this.stepTargets.forEach((step, index) => {
156
+ const number = index + 1;
157
+ this.setStatus(step, number === current ? 'current' : number < this.furthest ? 'complete' : 'upcoming');
158
+ });
159
+ this.panelTargets.forEach((panel) => (panel.hidden = Number(panel.dataset.step) !== current));
160
+ this.completionTargets.forEach((el) => (el.hidden = !finished));
161
+ this.syncButtons();
162
+
163
+ const title = this.currentStep?.querySelector('[id$="-step-' + current + '"]')?.textContent ?? '';
164
+ this.summaryTargets.forEach((el) => {
165
+ if (finished) el.hidden = true;
166
+ else {
167
+ el.hidden = false;
168
+ el.textContent = `${this.summaryValue.replace('%{current}', String(current)).replace('%{total}', String(this.total))}: ${title}`;
169
+ }
170
+ });
171
+
172
+ const shown = finished ? this.completionTargets[0] : this.currentPanel;
173
+ shown?.focus({ preventScroll: true });
174
+ this.dispatch('change', { detail: { current, total: this.total } });
175
+ }
176
+
177
+ private syncButtons() {
178
+ const current = this.currentValue;
179
+ const finished = current > this.total;
180
+ const last = current === this.total;
181
+ this.previousTargets.forEach((button) => {
182
+ button.hidden = finished || current <= 1;
183
+ });
184
+ this.nextTargets.forEach((el) => (el.hidden = finished || (last && this.submitTargets.length > 0)));
185
+ this.submitTargets.forEach((el) => (el.hidden = !last));
186
+ }
187
+ }
@@ -0,0 +1,15 @@
1
+ // Vanilla Calendar Pro, built as its own entry point rather than bundled into
2
+ // application.js, and loaded the first time a date picker opens. Its layout
3
+ // stylesheet and the light theme come out of the same build as
4
+ // vanilla_calendar.css; the kit points the theme's colours at its own tokens
5
+ // (velvetkit.css), so it follows dark mode.
6
+ //
7
+ // Same shape as ag_grid.ts and chart_js.ts: a bun code-split chunk can't be
8
+ // used because Propshaft serves digested filenames, so Ruby hands the
9
+ // controller both URLs.
10
+ import 'vanilla-calendar-pro/styles/layout.css';
11
+ import 'vanilla-calendar-pro/styles/layout/months.css';
12
+ import 'vanilla-calendar-pro/styles/themes/light.css';
13
+
14
+ // `months` is the extension that shows more than one month at once, for a range.
15
+ export { Calendar, months } from 'vanilla-calendar-pro';