@justanarthur/modo-ui 0.6.0-canary.9 → 1.0.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 (619) hide show
  1. package/README.md +197 -643
  2. package/blocks/sidebar-app/examples.mdx +2 -2
  3. package/blocks/sidebar-app/index.tsx +20 -7
  4. package/blocks/sidebar-app/inset-topbar.tsx +3 -8
  5. package/blocks/sidebar-app/menu-grid.ts +8 -18
  6. package/blocks/sidebar-app/nav-data.ts +1 -1
  7. package/blocks/sidebar-app/search-field.tsx +8 -15
  8. package/blocks/sidebar-app/thread-page.tsx +58 -0
  9. package/blocks/sidebar-app/user-footer.tsx +8 -15
  10. package/blocks/sidebar-app/workspace-header.tsx +9 -28
  11. package/components/AI/input-message/examples.mdx +37 -33
  12. package/components/AI/input-message/file-preview-tile.tsx +59 -0
  13. package/components/AI/input-message/file-thumbnail.tsx +26 -53
  14. package/components/AI/input-message/index.tsx +362 -1122
  15. package/components/AI/input-message/input-message.css +25 -0
  16. package/components/AI/input-message/queued-row.tsx +102 -0
  17. package/components/AI/input-message/shared.ts +38 -0
  18. package/components/AI/input-message/suggestion-row.tsx +64 -0
  19. package/components/AI/input-message/use-composer-files.ts +142 -0
  20. package/components/AI/input-message/use-history-nav.ts +60 -0
  21. package/components/AI/input-message/use-message-queue.ts +108 -0
  22. package/components/AI/input-message/use-region-height.ts +34 -0
  23. package/components/AI/thinking-indicator/index.tsx +9 -31
  24. package/components/accordion/accordion-content.tsx +217 -0
  25. package/components/accordion/accordion-context.tsx +118 -0
  26. package/components/accordion/accordion-group.tsx +215 -0
  27. package/components/accordion/examples.mdx +64 -132
  28. package/components/accordion/index.tsx +127 -891
  29. package/components/avatar/examples.mdx +2 -2
  30. package/components/avatar/index.tsx +40 -34
  31. package/components/badge/change-demo.tsx +2 -0
  32. package/components/badge/examples.mdx +16 -34
  33. package/components/badge/index.tsx +31 -69
  34. package/components/badge/variants.ts +5 -30
  35. package/components/button/examples.mdx +79 -94
  36. package/components/button/index.tsx +97 -188
  37. package/components/button/loading-demo.tsx +2 -0
  38. package/components/button/variants.ts +12 -117
  39. package/components/card/card-group.tsx +184 -0
  40. package/components/card/card-media.tsx +207 -0
  41. package/components/card/card-parts.tsx +179 -0
  42. package/components/card/examples.mdx +91 -143
  43. package/components/card/index.tsx +190 -881
  44. package/components/copy/examples.mdx +29 -67
  45. package/components/copy/index.tsx +58 -285
  46. package/components/inputs/checkbox/examples.mdx +22 -39
  47. package/components/inputs/checkbox/index.tsx +103 -255
  48. package/components/inputs/checkbox/select-all-demo.tsx +8 -6
  49. package/components/inputs/color-picker/channel-sliders.tsx +70 -0
  50. package/components/inputs/color-picker/color-input.tsx +387 -0
  51. package/components/inputs/color-picker/{variants.ts → color-math.ts} +22 -57
  52. package/components/inputs/color-picker/context.ts +11 -0
  53. package/components/inputs/color-picker/examples.mdx +20 -59
  54. package/components/inputs/color-picker/format-menu.tsx +212 -0
  55. package/components/inputs/color-picker/index.tsx +190 -1776
  56. package/components/inputs/color-picker/inputs-row.tsx +196 -0
  57. package/components/inputs/color-picker/popover.tsx +161 -0
  58. package/components/inputs/color-picker/saturation-square.tsx +167 -0
  59. package/components/inputs/color-picker/swatches.tsx +178 -0
  60. package/components/inputs/combobox/context.ts +90 -0
  61. package/components/inputs/combobox/examples.mdx +103 -206
  62. package/components/inputs/combobox/fields.tsx +328 -0
  63. package/components/inputs/combobox/index.tsx +155 -1310
  64. package/components/inputs/combobox/list.tsx +415 -0
  65. package/components/inputs/combobox/remote-demo.tsx +70 -74
  66. package/components/inputs/date-time/calendar/examples.mdx +0 -11
  67. package/components/inputs/date-time/calendar/index.tsx +32 -59
  68. package/components/inputs/date-time/calendar/use-month-window.ts +35 -32
  69. package/components/inputs/date-time/date-picker/examples.mdx +59 -155
  70. package/components/inputs/date-time/date-picker/index.tsx +186 -370
  71. package/components/inputs/date-time/date-picker/masked-date-input.tsx +105 -247
  72. package/components/inputs/date-time/date-range-picker/examples.mdx +6 -62
  73. package/components/inputs/date-time/date-range-picker/index.tsx +105 -404
  74. package/components/inputs/date-time/date-value.ts +37 -0
  75. package/components/inputs/date-time/day-rules.ts +22 -0
  76. package/components/inputs/date-time/duration-picker/examples.mdx +0 -24
  77. package/components/inputs/date-time/duration-picker/index.tsx +50 -140
  78. package/components/inputs/date-time/month-picker/examples.mdx +0 -29
  79. package/components/inputs/date-time/month-picker/index.tsx +48 -132
  80. package/components/inputs/date-time/picker-shell.tsx +226 -347
  81. package/components/inputs/date-time/time-columns.tsx +11 -15
  82. package/components/inputs/date-time/time-picker/examples.mdx +0 -31
  83. package/components/inputs/date-time/time-picker/index.tsx +37 -118
  84. package/components/inputs/field/examples.mdx +81 -39
  85. package/components/inputs/field/index.tsx +113 -103
  86. package/components/inputs/file-dropzone/examples.mdx +23 -24
  87. package/components/inputs/file-dropzone/file-row.tsx +20 -21
  88. package/components/inputs/file-dropzone/index.tsx +130 -129
  89. package/components/inputs/file-dropzone/upload-demo.tsx +22 -18
  90. package/components/inputs/file-dropzone/variants.ts +3 -1
  91. package/components/inputs/input/examples.mdx +19 -74
  92. package/components/inputs/input/index.tsx +86 -149
  93. package/components/inputs/input/password-demo.tsx +5 -5
  94. package/components/inputs/label/examples.mdx +19 -26
  95. package/components/inputs/label/index.tsx +21 -34
  96. package/components/inputs/number-input/examples.mdx +63 -36
  97. package/components/inputs/number-input/index.tsx +62 -57
  98. package/components/inputs/radio/examples.mdx +24 -39
  99. package/components/inputs/radio/index.tsx +125 -328
  100. package/components/inputs/search/examples.mdx +3 -3
  101. package/components/inputs/search/index.tsx +46 -39
  102. package/components/inputs/select/examples.mdx +76 -167
  103. package/components/inputs/select/index.tsx +252 -776
  104. package/components/inputs/slider/comfortable.tsx +524 -0
  105. package/components/inputs/slider/compact.tsx +690 -0
  106. package/components/inputs/slider/examples.mdx +9 -35
  107. package/components/inputs/slider/geometry.ts +88 -0
  108. package/components/inputs/slider/index.tsx +65 -1796
  109. package/components/inputs/slider/value-display.tsx +184 -0
  110. package/components/inputs/switch/examples.mdx +31 -33
  111. package/components/inputs/switch/index.tsx +55 -107
  112. package/components/inputs/textarea/examples.mdx +23 -61
  113. package/components/inputs/textarea/index.tsx +21 -99
  114. package/components/navigation/navigation-menu/content.tsx +76 -0
  115. package/components/navigation/navigation-menu/context.ts +34 -0
  116. package/components/navigation/navigation-menu/examples.mdx +21 -84
  117. package/components/navigation/navigation-menu/index.tsx +139 -639
  118. package/components/navigation/navigation-menu/item.tsx +47 -0
  119. package/components/navigation/navigation-menu/link.tsx +104 -0
  120. package/components/navigation/navigation-menu/list.tsx +86 -0
  121. package/components/navigation/navigation-menu/trigger.tsx +78 -0
  122. package/components/navigation/navigation-menu/use-dom-rows.ts +56 -0
  123. package/components/navigation/pagination/examples.mdx +25 -34
  124. package/components/navigation/pagination/index.tsx +75 -153
  125. package/components/navigation/sidebar/examples.mdx +17 -23
  126. package/components/navigation/sidebar/index.tsx +59 -119
  127. package/components/navigation/sidebar/menu-scope.tsx +439 -0
  128. package/components/navigation/sidebar/row-label.tsx +61 -0
  129. package/components/navigation/sidebar/sidebar-context.tsx +71 -0
  130. package/components/navigation/sidebar/sidebar-group.tsx +299 -0
  131. package/components/navigation/sidebar/sidebar-menu-actions.tsx +209 -0
  132. package/components/navigation/sidebar/sidebar-menu-button.tsx +214 -0
  133. package/components/navigation/sidebar/sidebar-menu-item.tsx +207 -0
  134. package/components/navigation/sidebar/sidebar-menu-sub.tsx +180 -0
  135. package/components/navigation/sidebar/sidebar-parts.tsx +94 -0
  136. package/components/navigation/sidebar/sidebar-provider.tsx +248 -0
  137. package/components/navigation/sidebar/sidebar-rail.tsx +206 -0
  138. package/components/navigation/sidebar/sidebar-shell.tsx +180 -0
  139. package/components/navigation/sidebar/sidebar-shortcut.tsx +101 -0
  140. package/components/navigation/sidebar/sidebar.css +7 -11
  141. package/components/navigation/sidebar/use-measured-collapse.ts +62 -0
  142. package/components/navigation/tabs/context.ts +45 -0
  143. package/components/navigation/tabs/examples.mdx +63 -17
  144. package/components/navigation/tabs/index.tsx +82 -434
  145. package/components/navigation/tabs/item.tsx +161 -0
  146. package/components/navigation/tabs/list.tsx +143 -0
  147. package/components/overlays/alert-dialog/examples.mdx +2 -36
  148. package/components/overlays/alert-dialog/index.tsx +76 -90
  149. package/components/overlays/alert-dialog/pending-demo.tsx +3 -1
  150. package/components/overlays/command/index.tsx +28 -59
  151. package/components/overlays/context-menu/examples.mdx +58 -4
  152. package/components/overlays/context-menu/index.tsx +77 -221
  153. package/components/overlays/dialog/examples.mdx +8 -31
  154. package/components/overlays/dialog/index.tsx +81 -261
  155. package/components/overlays/dropdown/dropdown-search.tsx +33 -98
  156. package/components/overlays/dropdown/examples.mdx +77 -363
  157. package/components/overlays/dropdown/index.tsx +114 -1010
  158. package/components/overlays/dropdown/menu-item.tsx +98 -382
  159. package/components/overlays/dropdown/menu-popup.tsx +294 -0
  160. package/components/overlays/dropdown/panel-state.ts +176 -0
  161. package/components/overlays/dropdown/submenu.tsx +170 -0
  162. package/components/overlays/popover/anchored-demo.tsx +22 -13
  163. package/components/overlays/popover/examples.mdx +16 -65
  164. package/components/overlays/popover/index.tsx +93 -137
  165. package/components/overlays/preview-card/examples.mdx +4 -4
  166. package/components/overlays/preview-card/index.tsx +48 -103
  167. package/components/overlays/sheet/examples.mdx +0 -12
  168. package/components/overlays/sheet/index.tsx +44 -129
  169. package/components/overlays/toast/examples.mdx +33 -25
  170. package/components/overlays/toast/index.tsx +56 -203
  171. package/components/overlays/toast/manager.ts +63 -119
  172. package/components/overlays/tooltip/examples.mdx +6 -12
  173. package/components/overlays/tooltip/index.tsx +124 -264
  174. package/components/progress/index.tsx +24 -30
  175. package/components/progress/progress.css +6 -28
  176. package/components/progress/step-demo.tsx +2 -0
  177. package/components/table/context.ts +49 -0
  178. package/components/table/examples.mdx +40 -72
  179. package/components/table/head.tsx +105 -0
  180. package/components/table/index.tsx +73 -458
  181. package/components/table/parts.tsx +188 -0
  182. package/components/table/sort-demo.tsx +21 -30
  183. package/dist/base.css +141 -122
  184. package/dist/blocks/sidebar-app/index.d.ts +10 -2
  185. package/dist/blocks/sidebar-app/index.js +49 -40
  186. package/dist/components/AI/input-message/index.d.ts +22 -19
  187. package/dist/components/AI/input-message/index.js +30 -23
  188. package/dist/components/AI/thinking-indicator/index.d.ts +2 -0
  189. package/dist/components/AI/thinking-indicator/index.js +10 -9
  190. package/dist/components/accordion/index.d.ts +52 -85
  191. package/dist/components/accordion/index.js +25 -19
  192. package/dist/components/avatar/index.d.ts +10 -10
  193. package/dist/components/avatar/index.js +9 -8
  194. package/dist/components/badge/index.d.ts +11 -18
  195. package/dist/components/badge/index.js +9 -9
  196. package/dist/components/badge/variants.d.ts +2 -9
  197. package/dist/components/badge/variants.js +3 -5
  198. package/dist/components/button/index.d.ts +36 -60
  199. package/dist/components/button/index.js +12 -9
  200. package/dist/components/button/variants.d.ts +3 -34
  201. package/dist/components/button/variants.js +2 -4
  202. package/dist/components/card/index.d.ts +163 -108
  203. package/dist/components/card/index.js +30 -21
  204. package/dist/components/copy/index.d.ts +10 -41
  205. package/dist/components/copy/index.js +18 -15
  206. package/dist/components/inputs/checkbox/index.d.ts +25 -25
  207. package/dist/components/inputs/checkbox/index.js +22 -18
  208. package/dist/components/inputs/color-picker/index.d.ts +65 -53
  209. package/dist/components/inputs/color-picker/index.js +35 -29
  210. package/dist/components/inputs/combobox/index.d.ts +147 -152
  211. package/dist/components/inputs/combobox/index.js +31 -29
  212. package/dist/components/inputs/date-time/calendar/index.d.ts +18 -24
  213. package/dist/components/inputs/date-time/calendar/index.js +17 -15
  214. package/dist/components/inputs/date-time/date-picker/index.d.ts +52 -96
  215. package/dist/components/inputs/date-time/date-picker/index.js +42 -35
  216. package/dist/components/inputs/date-time/date-range-picker/index.d.ts +48 -108
  217. package/dist/components/inputs/date-time/date-range-picker/index.js +40 -35
  218. package/dist/components/inputs/date-time/duration-picker/index.d.ts +21 -67
  219. package/dist/components/inputs/date-time/duration-picker/index.js +39 -33
  220. package/dist/components/inputs/date-time/month-picker/index.d.ts +18 -61
  221. package/dist/components/inputs/date-time/month-picker/index.js +38 -32
  222. package/dist/components/inputs/date-time/time-picker/index.d.ts +18 -59
  223. package/dist/components/inputs/date-time/time-picker/index.js +39 -33
  224. package/dist/components/inputs/field/index.d.ts +37 -41
  225. package/dist/components/inputs/field/index.js +13 -14
  226. package/dist/components/inputs/file-dropzone/index.d.ts +32 -25
  227. package/dist/components/inputs/file-dropzone/index.js +18 -15
  228. package/dist/components/inputs/file-dropzone/variants.js +1 -1
  229. package/dist/components/inputs/input/index.d.ts +48 -50
  230. package/dist/components/inputs/input/index.js +14 -12
  231. package/dist/components/inputs/label/index.d.ts +12 -10
  232. package/dist/components/inputs/label/index.js +5 -4
  233. package/dist/components/inputs/number-input/index.d.ts +31 -23
  234. package/dist/components/inputs/number-input/index.js +16 -14
  235. package/dist/components/inputs/radio/index.d.ts +20 -16
  236. package/dist/components/inputs/radio/index.js +20 -16
  237. package/dist/components/inputs/search/index.d.ts +12 -5
  238. package/dist/components/inputs/search/index.js +33 -26
  239. package/dist/components/inputs/select/index.d.ts +88 -99
  240. package/dist/components/inputs/select/index.js +32 -29
  241. package/dist/components/inputs/slider/index.d.ts +26 -48
  242. package/dist/components/inputs/slider/index.js +9 -10
  243. package/dist/components/inputs/switch/index.d.ts +12 -6
  244. package/dist/components/inputs/switch/index.js +17 -15
  245. package/dist/components/inputs/textarea/index.d.ts +12 -22
  246. package/dist/components/inputs/textarea/index.js +12 -9
  247. package/dist/components/navigation/navigation-menu/index.d.ts +112 -83
  248. package/dist/components/navigation/navigation-menu/index.js +31 -27
  249. package/dist/components/navigation/pagination/index.d.ts +25 -38
  250. package/dist/components/navigation/pagination/index.js +27 -34
  251. package/dist/components/navigation/sidebar/index.d.ts +236 -230
  252. package/dist/components/navigation/sidebar/index.js +59 -55
  253. package/dist/components/navigation/tabs/index.d.ts +62 -45
  254. package/dist/components/navigation/tabs/index.js +23 -17
  255. package/dist/components/overlays/alert-dialog/index.d.ts +71 -106
  256. package/dist/components/overlays/alert-dialog/index.js +24 -19
  257. package/dist/components/overlays/command/index.d.ts +40 -31
  258. package/dist/components/overlays/command/index.js +31 -25
  259. package/dist/components/overlays/context-menu/index.d.ts +70 -84
  260. package/dist/components/overlays/context-menu/index.js +35 -31
  261. package/dist/components/overlays/dialog/index.d.ts +82 -98
  262. package/dist/components/overlays/dialog/index.js +23 -20
  263. package/dist/components/overlays/dropdown/index.d.ts +191 -357
  264. package/dist/components/overlays/dropdown/index.js +35 -41
  265. package/dist/components/overlays/popover/index.d.ts +81 -52
  266. package/dist/components/overlays/popover/index.js +17 -13
  267. package/dist/components/overlays/preview-card/index.d.ts +52 -26
  268. package/dist/components/overlays/preview-card/index.js +16 -12
  269. package/dist/components/overlays/sheet/index.d.ts +41 -45
  270. package/dist/components/overlays/sheet/index.js +24 -19
  271. package/dist/components/overlays/toast/index.d.ts +73 -183
  272. package/dist/components/overlays/toast/index.js +20 -21
  273. package/dist/components/overlays/tooltip/index.d.ts +80 -118
  274. package/dist/components/overlays/tooltip/index.js +14 -12
  275. package/dist/components/progress/index.d.ts +10 -11
  276. package/dist/components/progress/index.js +7 -6
  277. package/dist/components/table/index.d.ts +72 -71
  278. package/dist/components/table/index.js +18 -16
  279. package/dist/index.d.ts +2575 -3149
  280. package/dist/index.js +186 -202
  281. package/dist/lib/date-locale.d.ts +6 -13
  282. package/dist/lib/date-locale.js +5 -11
  283. package/dist/lib/date-mask.d.ts +41 -0
  284. package/dist/lib/date-mask.js +20 -0
  285. package/dist/lib/field-box.d.ts +114 -0
  286. package/dist/lib/field-box.js +18 -0
  287. package/dist/lib/field-classes.d.ts +15 -119
  288. package/dist/lib/field-classes.js +4 -21
  289. package/dist/lib/fluid-hover-highlight.d.ts +3 -25
  290. package/dist/lib/fluid-hover-highlight.js +8 -13
  291. package/dist/lib/focus-ring.d.ts +16 -10
  292. package/dist/lib/focus-ring.js +6 -6
  293. package/dist/lib/goo-indicator.js +6 -5
  294. package/dist/lib/icon-context.d.ts +2 -8
  295. package/dist/lib/icon-context.js +2 -6
  296. package/dist/lib/merge-refs.d.ts +10 -0
  297. package/dist/lib/merge-refs.js +8 -0
  298. package/dist/lib/morph-layers.d.ts +12 -6
  299. package/dist/lib/morph-layers.js +7 -6
  300. package/dist/lib/morph-part.js +3 -3
  301. package/dist/lib/overlay.d.ts +113 -0
  302. package/dist/lib/overlay.js +21 -0
  303. package/dist/lib/popup-rows.d.ts +101 -0
  304. package/dist/lib/popup-rows.js +25 -0
  305. package/dist/lib/popup-surface.d.ts +92 -0
  306. package/dist/lib/popup-surface.js +17 -0
  307. package/dist/lib/popup.d.ts +17 -1
  308. package/dist/lib/popup.js +4 -1
  309. package/dist/lib/rect.d.ts +16 -0
  310. package/dist/lib/rect.js +12 -0
  311. package/dist/lib/reduced-motion.js +1 -1
  312. package/dist/lib/row-group.d.ts +100 -0
  313. package/dist/lib/row-group.js +12 -0
  314. package/dist/lib/row-index.d.ts +12 -7
  315. package/dist/lib/row-index.js +4 -2
  316. package/dist/lib/scroll-column.d.ts +1 -5
  317. package/dist/lib/scroll-column.js +13 -12
  318. package/dist/lib/shape-classes.d.ts +16 -0
  319. package/dist/lib/shape-classes.js +6 -0
  320. package/dist/lib/shape-context.d.ts +2 -9
  321. package/dist/lib/shape-context.js +3 -7
  322. package/dist/lib/size-context.d.ts +1 -2
  323. package/dist/lib/size-context.js +2 -7
  324. package/dist/lib/size-scale.js +1 -1
  325. package/dist/lib/slot.d.ts +31 -26
  326. package/dist/lib/slot.js +9 -9
  327. package/dist/lib/spinner-glyph.d.ts +7 -0
  328. package/dist/lib/spinner-glyph.js +7 -0
  329. package/dist/lib/springs.d.ts +5 -1
  330. package/dist/lib/springs.js +4 -2
  331. package/dist/lib/surface-classes.js +1 -1
  332. package/dist/lib/surface-context.d.ts +3 -1
  333. package/dist/lib/surface-context.js +3 -1
  334. package/dist/lib/use-autosize-textarea.d.ts +16 -0
  335. package/dist/lib/use-autosize-textarea.js +7 -0
  336. package/dist/lib/use-controllable-state.d.ts +15 -1
  337. package/dist/lib/use-controllable-state.js +1 -1
  338. package/dist/lib/use-fluid-hover.d.ts +1 -49
  339. package/dist/lib/use-fluid-hover.js +1 -7
  340. package/dist/lib/use-is-mobile.js +1 -1
  341. package/dist/lib/use-iso-layout-effect.d.ts +7 -0
  342. package/dist/lib/use-iso-layout-effect.js +6 -0
  343. package/dist/lib/use-keyboard-nav-gate.js +3 -2
  344. package/dist/lib/use-merge-split.js +7 -6
  345. package/dist/lib/use-morph.d.ts +13 -7
  346. package/dist/lib/use-morph.js +4 -3
  347. package/dist/lib/use-touch-primary.js +1 -1
  348. package/dist/lib/utils.js +1 -1
  349. package/dist/lib/weight-label.d.ts +26 -0
  350. package/dist/lib/weight-label.js +7 -0
  351. package/dist/preset.d.ts +4 -8
  352. package/dist/preset.js +8 -8
  353. package/dist/primitives/code/index.js +8 -8
  354. package/dist/primitives/craft/index.d.ts +1 -1
  355. package/dist/primitives/craft/index.js +13 -12
  356. package/dist/primitives/fluid-hover/index.d.ts +13 -14
  357. package/dist/primitives/fluid-hover/index.js +13 -10
  358. package/dist/primitives/morph/index.d.ts +1 -1
  359. package/dist/primitives/morph/index.js +20 -16
  360. package/dist/primitives/motion/index.d.ts +2 -0
  361. package/dist/primitives/motion/index.js +14 -11
  362. package/dist/primitives/scroll-area/index.d.ts +5 -4
  363. package/dist/primitives/scroll-area/index.js +5 -5
  364. package/dist/primitives/separator/index.d.ts +12 -11
  365. package/dist/primitives/separator/index.js +2 -2
  366. package/dist/primitives/sizes/index.d.ts +17 -4
  367. package/dist/primitives/sizes/index.js +7 -4
  368. package/dist/primitives/skeleton/index.d.ts +8 -8
  369. package/dist/primitives/skeleton/index.js +7 -6
  370. package/dist/primitives/surface/index.d.ts +12 -25
  371. package/dist/primitives/surface/index.js +8 -6
  372. package/dist/shared/{components-yxmxn2jp.js → components-07g2gbjy.js} +30 -75
  373. package/dist/shared/components-099sdasz.js +552 -0
  374. package/dist/shared/{components-bsqynhaj.js → components-0h3f5jae.js} +49 -51
  375. package/dist/shared/{components-wbbckbw8.js → components-0mrhj88d.js} +13 -12
  376. package/dist/shared/{components-0h78g3b5.js → components-0p2na0cp.js} +19 -47
  377. package/dist/shared/components-1a7cr7vh.js +40 -0
  378. package/dist/shared/components-1axxc3tk.js +334 -0
  379. package/dist/shared/components-1hc3xv0y.js +381 -0
  380. package/dist/shared/{components-gyt7my41.js → components-1jxw899c.js} +94 -84
  381. package/dist/shared/{components-jqpefjsn.js → components-1nv9q3s8.js} +24 -44
  382. package/dist/shared/components-1p3k62x2.js +137 -0
  383. package/dist/shared/{components-kz5q11pp.js → components-2xmke84n.js} +12 -4
  384. package/dist/shared/{components-c7rwx0ap.js → components-346ged8v.js} +24 -3
  385. package/dist/shared/{components-4j3t39dd.js → components-34brwmgp.js} +12 -11
  386. package/dist/shared/components-38wa9nx5.js +19 -0
  387. package/dist/shared/components-3hgk57s0.js +27 -0
  388. package/dist/shared/{components-px2zm7dc.js → components-3js2vgds.js} +13 -6
  389. package/dist/shared/{components-ctqmge8t.js → components-3m4rqrqm.js} +10 -3
  390. package/dist/shared/{components-3ey0hzpb.js → components-45r18egt.js} +11 -1
  391. package/dist/shared/components-50rh4ggz.js +54 -0
  392. package/dist/shared/components-5atrr490.js +99 -0
  393. package/dist/shared/components-5f3tq4qb.js +70 -0
  394. package/dist/shared/{components-dc5q749x.js → components-5vyaexsj.js} +16 -17
  395. package/dist/shared/{components-pwayrkw9.js → components-5ynncdpn.js} +5 -4
  396. package/dist/shared/{components-1e64t8aj.js → components-62mg6pab.js} +232 -93
  397. package/dist/shared/{components-drxrtnp2.js → components-6f5pyzb2.js} +8 -0
  398. package/dist/shared/{components-868v7scv.js → components-6xfhc5qm.js} +104 -169
  399. package/dist/shared/{components-yhgq0qxx.js → components-7c4a0egq.js} +20 -12
  400. package/dist/shared/components-7fqnqbh0.js +79 -0
  401. package/dist/shared/components-7fsy0jxg.js +443 -0
  402. package/dist/shared/{components-p0fm0bab.js → components-7t3pz7v7.js} +496 -526
  403. package/dist/shared/components-85epgxwf.js +620 -0
  404. package/dist/shared/{components-wknae3m4.js → components-86vvx0c8.js} +75 -121
  405. package/dist/shared/{components-wgtjt2af.js → components-88ktjdg0.js} +30 -27
  406. package/dist/shared/{components-ft3zdc79.js → components-88r046aa.js} +6 -6
  407. package/dist/shared/{components-xd3emmy4.js → components-8hfrd2fk.js} +1462 -1464
  408. package/dist/shared/components-8sazy704.js +146 -0
  409. package/dist/shared/{components-rrbpmfx4.js → components-8wp8d8q1.js} +8 -0
  410. package/dist/shared/{components-rtadhd9j.js → components-9ybenn5v.js} +16 -16
  411. package/dist/shared/components-amsc86fb.js +293 -0
  412. package/dist/shared/{components-9as3rf68.js → components-az04rmng.js} +12 -6
  413. package/dist/shared/components-bdkm2jzy.js +34 -0
  414. package/dist/shared/{components-xjkdvnbg.js → components-be3wggg1.js} +54 -48
  415. package/dist/shared/components-bkwjvvkh.js +18 -0
  416. package/dist/shared/{components-vf45j12c.js → components-ceyn28cf.js} +7 -0
  417. package/dist/shared/{components-3h92d94m.js → components-cy5z8zxy.js} +1 -2
  418. package/dist/shared/components-dm86y7b3.js +105 -0
  419. package/dist/shared/{components-c9yr4ed1.js → components-ejn6tvbw.js} +8 -6
  420. package/dist/shared/{components-34txk9rj.js → components-ew4wq7mj.js} +7 -0
  421. package/dist/shared/{components-svkt577j.js → components-f75y4gn8.js} +53 -70
  422. package/dist/shared/components-f9adtfq8.js +34 -0
  423. package/dist/shared/{components-2a7hcand.js → components-gbsdhmrv.js} +48 -83
  424. package/dist/shared/{components-9sttq78t.js → components-gc5zky2w.js} +54 -59
  425. package/dist/shared/{components-bae8sbjx.js → components-gkdx1787.js} +12 -6
  426. package/dist/shared/{components-124epb7f.js → components-grxgqa75.js} +3 -7
  427. package/dist/shared/components-gw0wd7gd.js +986 -0
  428. package/dist/shared/components-j4z3rtw2.js +179 -0
  429. package/dist/shared/{components-t5pk5nmc.js → components-j8tcbm8y.js} +927 -953
  430. package/dist/shared/components-jm91mjm1.js +297 -0
  431. package/dist/shared/{components-b94t6qtj.js → components-jtfptckj.js} +44 -39
  432. package/dist/shared/components-jx9qb4z8.js +63 -0
  433. package/dist/shared/components-k785rge6.js +336 -0
  434. package/dist/shared/{components-r8eqs7gz.js → components-k81x1aea.js} +10 -6
  435. package/dist/shared/{components-qx27excf.js → components-kn5c7652.js} +11 -13
  436. package/dist/shared/components-mse06t0x.js +31 -0
  437. package/dist/shared/{components-cet3jpa0.js → components-n7e31ct4.js} +71 -49
  438. package/dist/shared/components-nskr4hwg.js +1008 -0
  439. package/dist/shared/components-nv5m3gcv.js +37 -0
  440. package/dist/shared/components-nwa2a9tq.js +27 -0
  441. package/dist/shared/{components-f7h57m6t.js → components-p0x8ren6.js} +3 -1
  442. package/dist/shared/{components-2krsc300.js → components-p0z99d5b.js} +67 -92
  443. package/dist/shared/{components-b1e239g3.js → components-pa43g2r2.js} +15 -4
  444. package/dist/shared/{components-m06yq8wk.js → components-pedbt2dc.js} +35 -49
  445. package/dist/shared/components-pva1wj1r.js +27 -0
  446. package/dist/shared/components-q4wyd06h.js +382 -0
  447. package/dist/shared/{components-71nbt03m.js → components-qrpdtvxa.js} +12 -45
  448. package/dist/shared/components-r33dxr5j.js +91 -0
  449. package/dist/shared/{components-005jt2nz.js → components-re8p99fj.js} +53 -179
  450. package/dist/shared/components-s217vq1n.js +35 -0
  451. package/dist/shared/{components-vc864c51.js → components-sesrjvcc.js} +7 -6
  452. package/dist/shared/{components-qh1cvj6p.js → components-skn189mp.js} +29 -36
  453. package/dist/shared/{components-tz4gaf1v.js → components-tcyz2tdn.js} +9 -1
  454. package/dist/shared/components-tjxy84s9.js +53 -0
  455. package/dist/shared/components-tnj6mkhg.js +89 -0
  456. package/dist/shared/{components-de99ykt7.js → components-tz0axc0f.js} +1 -0
  457. package/dist/shared/components-v2j3jx89.js +7 -0
  458. package/dist/shared/components-vcte8p75.js +71 -0
  459. package/dist/shared/{components-c74gf16d.js → components-vgzerqt0.js} +34 -47
  460. package/dist/shared/components-vp6vzsee.js +30 -0
  461. package/dist/shared/components-vpkh6j83.js +42 -0
  462. package/dist/shared/{components-4nck8acq.js → components-wgd1nebp.js} +21 -14
  463. package/dist/shared/{components-pt5ftm4p.js → components-wrbw67f6.js} +10 -3
  464. package/dist/shared/{components-tz1fv35x.js → components-wwd093xg.js} +1 -0
  465. package/dist/shared/components-wyfmhtw9.js +61 -0
  466. package/dist/shared/{components-d3shbwqq.js → components-xpw8dzb0.js} +16 -23
  467. package/dist/shared/{components-mattt5jp.js → components-xzcgr3gy.js} +62 -60
  468. package/dist/shared/{components-jcnjay5g.js → components-ycx2kxeq.js} +9 -1
  469. package/dist/shared/components-zbzx62pg.js +1771 -0
  470. package/dist/shared/{components-dtca4s6b.js → components-zf0nnvvg.js} +67 -147
  471. package/dist/shared/{components-h83az0bz.js → components-znspksk0.js} +9 -1
  472. package/dist/shared/components-zpatc9x3.js +78 -0
  473. package/dist/styles.css +218 -235
  474. package/dist/tailwind.css +20 -8
  475. package/dist/tokens.css +53 -68
  476. package/index.ts +16 -2
  477. package/lib/date-locale.ts +12 -149
  478. package/lib/date-mask.ts +146 -0
  479. package/lib/field-box.ts +117 -0
  480. package/lib/field-classes.ts +85 -100
  481. package/lib/fluid-hover-highlight.tsx +12 -57
  482. package/lib/focus-ring.tsx +25 -22
  483. package/lib/goo-indicator.tsx +2 -0
  484. package/lib/icon-context.tsx +23 -75
  485. package/lib/merge-refs.ts +29 -0
  486. package/lib/morph-layers.tsx +3 -1
  487. package/lib/morph-part.tsx +5 -3
  488. package/lib/overlay.tsx +118 -0
  489. package/lib/popup-rows.tsx +149 -0
  490. package/lib/popup-surface.tsx +52 -0
  491. package/lib/popup.ts +10 -9
  492. package/lib/rect.ts +48 -0
  493. package/lib/reduced-motion.ts +2 -0
  494. package/lib/row-group.tsx +113 -0
  495. package/lib/row-index.tsx +27 -10
  496. package/lib/scroll-column.tsx +26 -53
  497. package/lib/shape-classes.ts +56 -0
  498. package/lib/shape-context.tsx +10 -79
  499. package/lib/size-context.tsx +8 -21
  500. package/lib/size-scale.ts +3 -9
  501. package/lib/slot.tsx +124 -0
  502. package/lib/spinner-glyph.tsx +27 -0
  503. package/lib/springs.ts +8 -9
  504. package/lib/surface-classes.ts +3 -8
  505. package/lib/surface-context.tsx +10 -5
  506. package/lib/use-autosize-textarea.ts +64 -0
  507. package/lib/use-controllable-state.ts +30 -15
  508. package/lib/use-fluid-hover.ts +9 -11
  509. package/lib/use-is-mobile.ts +5 -5
  510. package/lib/use-iso-layout-effect.ts +14 -0
  511. package/lib/use-keyboard-nav-gate.ts +5 -6
  512. package/lib/use-merge-split.tsx +5 -15
  513. package/lib/use-morph.ts +34 -76
  514. package/lib/use-touch-primary.tsx +5 -5
  515. package/lib/utils.ts +4 -11
  516. package/lib/weight-label.tsx +69 -0
  517. package/package.json +57 -194
  518. package/primitives/code/index.tsx +4 -2
  519. package/primitives/craft/demos.tsx +4 -2
  520. package/primitives/craft/examples.mdx +32 -34
  521. package/primitives/craft/index.tsx +3 -0
  522. package/primitives/fluid-hover/examples.mdx +1 -1
  523. package/primitives/fluid-hover/index.tsx +33 -68
  524. package/primitives/morph/examples.mdx +16 -19
  525. package/primitives/morph/index.tsx +5 -3
  526. package/primitives/motion/examples.mdx +3 -3
  527. package/primitives/motion/index.tsx +6 -22
  528. package/primitives/scroll-area/examples.mdx +4 -4
  529. package/primitives/scroll-area/index.tsx +16 -41
  530. package/primitives/separator/examples.mdx +2 -2
  531. package/primitives/separator/index.tsx +15 -14
  532. package/primitives/sizes/examples.mdx +1 -1
  533. package/primitives/sizes/index.tsx +28 -42
  534. package/primitives/skeleton/examples.mdx +6 -6
  535. package/primitives/skeleton/index.tsx +24 -10
  536. package/primitives/skeleton/skeleton.css +8 -3
  537. package/primitives/surface/examples.mdx +11 -11
  538. package/primitives/surface/index.tsx +15 -40
  539. package/primitives/surface/surface.css +1 -1
  540. package/DESIGN.md +0 -623
  541. package/components/inputs/select/variants.ts +0 -32
  542. package/components/navigation/sidebar/sidebar-core.tsx +0 -1408
  543. package/components/navigation/sidebar/sidebar-menu.tsx +0 -1495
  544. package/components/navigation/sidebar/variants.ts +0 -55
  545. package/components/navigation/tabs-subtle/examples.mdx +0 -49
  546. package/components/navigation/tabs-subtle/index.tsx +0 -512
  547. package/components/overlays/dropdown/menu-parts.tsx +0 -725
  548. package/components/overlays/toast/global-demo.tsx +0 -72
  549. package/dist/components/inputs/color-picker/variants.d.ts +0 -61
  550. package/dist/components/inputs/color-picker/variants.js +0 -28
  551. package/dist/components/inputs/select/variants.d.ts +0 -5
  552. package/dist/components/inputs/select/variants.js +0 -6
  553. package/dist/components/navigation/sidebar/variants.d.ts +0 -25
  554. package/dist/components/navigation/sidebar/variants.js +0 -28
  555. package/dist/components/navigation/tabs-subtle/index.d.ts +0 -73
  556. package/dist/components/navigation/tabs-subtle/index.js +0 -24
  557. package/dist/docs/index.d.ts +0 -83
  558. package/dist/docs/index.js +0 -288
  559. package/dist/docs/vite.d.ts +0 -31
  560. package/dist/docs/vite.js +0 -45
  561. package/dist/lib/field-variants.d.ts +0 -47
  562. package/dist/lib/field-variants.js +0 -26
  563. package/dist/lib/inert.d.ts +0 -9
  564. package/dist/lib/inert.js +0 -8
  565. package/dist/lib/row-order.d.ts +0 -28
  566. package/dist/lib/row-order.js +0 -10
  567. package/dist/lib/shape-radius.d.ts +0 -19
  568. package/dist/lib/shape-radius.js +0 -6
  569. package/dist/shared/components-01w9qcfa.js +0 -277
  570. package/dist/shared/components-26snnbs9.js +0 -322
  571. package/dist/shared/components-2qbqqpgq.js +0 -1545
  572. package/dist/shared/components-303jf96s.js +0 -1478
  573. package/dist/shared/components-4vfm04wq.js +0 -82
  574. package/dist/shared/components-54nq988h.js +0 -123
  575. package/dist/shared/components-7qx17na9.js +0 -300
  576. package/dist/shared/components-7s7pykk5.js +0 -281
  577. package/dist/shared/components-8jrk5eye.js +0 -448
  578. package/dist/shared/components-91zw3d9f.js +0 -136
  579. package/dist/shared/components-9jmjnkqd.js +0 -503
  580. package/dist/shared/components-adkarj8n.js +0 -35
  581. package/dist/shared/components-c5w5zk0s.js +0 -218
  582. package/dist/shared/components-cnead5qm.js +0 -185
  583. package/dist/shared/components-czdvj1a8.js +0 -266
  584. package/dist/shared/components-dcc02hs2.js +0 -31
  585. package/dist/shared/components-dhgk6mbt.js +0 -16
  586. package/dist/shared/components-g3eafs70.js +0 -337
  587. package/dist/shared/components-gx4h5rbb.js +0 -40
  588. package/dist/shared/components-h6p86be3.js +0 -19
  589. package/dist/shared/components-hdzrqqpx.js +0 -55
  590. package/dist/shared/components-hgv6tygd.js +0 -986
  591. package/dist/shared/components-krtx3m5b.js +0 -84
  592. package/dist/shared/components-kswxnm3h.js +0 -24
  593. package/dist/shared/components-mhza2wdn.js +0 -482
  594. package/dist/shared/components-mrbaxt8q.js +0 -62
  595. package/dist/shared/components-pv1dyrtn.js +0 -678
  596. package/dist/shared/components-s8yqk2dc.js +0 -124
  597. package/dist/shared/components-syynwm1r.js +0 -114
  598. package/dist/shared/components-tv7b8tet.js +0 -271
  599. package/dist/shared/components-w2jqa6hx.js +0 -404
  600. package/dist/shared/components-xdqmt6ed.js +0 -20
  601. package/dist/shared/components-y0kfy2g4.js +0 -578
  602. package/dist/shared/components-z3v0n0de.js +0 -11
  603. package/dist/shared/components-z8fedth5.js +0 -305
  604. package/dist/shared/components-zkk3fmw8.js +0 -150
  605. package/dist/tokens/colors.css +0 -230
  606. package/dist/tokens/motion.css +0 -40
  607. package/dist/tokens/radius.css +0 -10
  608. package/dist/tokens/spacing.css +0 -9
  609. package/dist/tokens/typography.css +0 -119
  610. package/docs/chrome.css +0 -120
  611. package/docs/chrome.tsx +0 -283
  612. package/docs/index.ts +0 -9
  613. package/docs/vite.ts +0 -85
  614. package/lib/field-variants.ts +0 -117
  615. package/lib/inert.ts +0 -22
  616. package/lib/row-order.tsx +0 -126
  617. package/lib/shape-radius.ts +0 -67
  618. package/lib/slot.ts +0 -115
  619. package/preset.ts +0 -199
@@ -1,161 +1,57 @@
1
- // biome-ignore-all lint: vendored upstream code keeps its own patterns (see the header)
2
- /*
1
+ /*!
3
2
  * Ported from Fluid Functionalism — github.com/mickadesign/fluid-functionalism
4
3
  * `registry/default/input-message.tsx` @ b3587bdbd83fc66c2a6aae3817ffb856cb09260b
5
- * MIT License © 2026 Micka Touillaud — fluidfunctionalism.com (notice: LICENSE.fluid-functionalism)
6
- * Local modifications:
7
- * - `"use client"` directive dropped (no RSC here).
8
- * - `framer-motion` → `motion/react`; `@/lib/*` and `@/hooks/*` rewritten to
9
- * `../../../lib/*` (`SizeProvider` → `../../../primitives/sizes`); `@/components/ui/fluid-hover-highlight` →
10
- * `../../../lib/fluid-hover-highlight`; `@/registry/radix/{button,tooltip}` →
11
- * `../../button` / `../../overlays/tooltip`; `@/registry/default/file-thumbnail` → `./file-thumbnail`
12
- * (vendored beside this file).
13
- * - Uncontrolled twins (Base UI shape, via `lib/use-controllable-state`), so the
14
- * composer works with no state in the caller. The controlled API is unchanged — every
15
- * `value` / `files` / `queue` / `status` prop still wins and still reports through its
16
- * callback:
17
- * · `value` / `onValueChange` are now optional and gain `defaultValue`;
18
- * · `defaultFiles` seeds an internal file list — attachments are enabled by
19
- * `onFilesChange` OR `defaultFiles` (upstream: `onFilesChange` alone);
20
- * · `defaultQueue` seeds an internal queue — the queue is enabled by
21
- * `onQueueChange` OR `defaultQueue`, still only alongside a status;
22
- * · `defaultStatus` seeds an internal status (plus an optional `onStatusChange`);
23
- * with the status uncontrolled the Stop control is offered even without
24
- * `onStop` and flips the status to `"idle"` itself, which is the edge that
25
- * auto-dispatches the head of the queue;
26
- * · an uncontrolled draft / file list clears itself after `onSend`, which a
27
- * controlled consumer does by hand.
28
- * - React 18 / `noUncheckedIndexedAccess`: `useRef<HTMLDivElement | null>` where the ref is
29
- * assigned, guards on `queue[0]`, `history[i]`, `suggestions[i]` and the swap in
30
- * `moveQueued`, and `FilePreviewTile` turned into a `forwardRef` — it renders inside
31
- * `<AnimatePresence mode="popLayout">`, which measures the exiting child through a ref
32
- * (React 19 passes `ref` as a plain prop; React 18 warns and drops it).
33
- * - modo item: TSDoc from the FF "InputMessage" docs page (its Playground section is
34
- * skipped, and the transcript around the Attachments / Send Handler demos is dropped —
35
- * `ChatMessage` is not part of this port).
36
- * - Styling reads DS tokens (AGENTS.md styling): `text-[Npx]` →
37
- * `text-<role>[-compact]`; `leading-[18px]` → `leading-4.5`; inline
38
- * `fontVariationSettings` → `weight-*`; the hex focus-ring fallback →
39
- * `ring-focus-ring` / `border-focus-ring`; literal colors → color tokens;
40
- * `rounded-[Npx]` → radius tokens; `duration-80|120|160` and tier-length JS
41
- * durations → `duration-<tier>` / `spring.*`.
4
+ * MIT License © 2026 Micka Touillaud (notice: LICENSE.fluid-functionalism). Local changes: see PORTING.md.
42
5
  */
43
6
 
44
- import { AnimatePresence, motion, Reorder, useReducedMotion } from 'motion/react'
7
+ 'use client'
8
+
9
+ import { AnimatePresence, motion, Reorder } from 'motion/react'
45
10
  import {
46
- type ChangeEvent,
47
11
  forwardRef,
48
12
  type HTMLAttributes,
49
- type DragEvent as ReactDragEvent,
50
13
  type KeyboardEvent as ReactKeyboardEvent,
51
14
  type MouseEvent as ReactMouseEvent,
52
- type ReactNode,
53
15
  type TextareaHTMLAttributes,
54
16
  useCallback,
55
17
  useEffect,
56
18
  useId,
57
- useLayoutEffect,
58
19
  useMemo,
59
20
  useRef,
60
- useState,
61
21
  } from 'react'
62
22
  import { FluidHoverHighlight } from '../../../lib/fluid-hover-highlight'
63
23
  import { useIcon } from '../../../lib/icon-context'
24
+ import { useReduceMotion } from '../../../lib/reduced-motion'
64
25
  import { useShape } from '../../../lib/shape-context'
65
26
  import { type SizeVariant, useSize } from '../../../lib/size-context'
66
27
  import { spring } from '../../../lib/springs'
67
28
  import { surfaceClasses } from '../../../lib/surface-classes'
68
29
  import { SurfaceProvider } from '../../../lib/surface-context'
30
+ import { useAutosizeTextarea } from '../../../lib/use-autosize-textarea'
69
31
  import { useControllableState } from '../../../lib/use-controllable-state'
70
- import { useFluidHover, useRegisterFluidHoverItem } from '../../../lib/use-fluid-hover'
32
+ import { useFluidHover } from '../../../lib/use-fluid-hover'
33
+ import { useTouchPrimary } from '../../../lib/use-touch-primary'
71
34
  import { cn } from '../../../lib/utils'
72
- import { SizeProvider } from '../../../primitives/sizes'
35
+ import { SizeScope } from '../../../primitives/sizes'
73
36
  import { Button } from '../../button'
74
- import { Tooltip } from '../../overlays/tooltip'
75
- import { FileThumbnail } from './file-thumbnail'
76
-
77
- const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
78
-
79
- /**
80
- * Measured layout height for one of the composer's collapsible regions
81
- * (attachments, queue, suggestions).
82
- *
83
- * These animate to a self-measured PIXEL height rather than `height: "auto"`:
84
- * motion resolves an "auto" target from the element's *visual* (transformed)
85
- * size, so under a scaled ancestor the region springs out to scale× its real
86
- * height and snaps back when "auto" lands, which reads as the region
87
- * ballooning and then correcting. Same treatment as Accordion's content
88
- * height.
89
- *
90
- * Returns a ref for the region's CONTENT element. The height it reports is the
91
- * clipping parent's scrollHeight, so inner margins count (the parent's
92
- * overflow-hidden makes it a block formatting context, so they don't collapse
93
- * out) and the value stays correct while the animated height is mid-flight.
94
- * Observing the child rather than the parent keeps the ResizeObserver out of a
95
- * feedback loop with that animation.
96
- */
97
- function useRegionHeight() {
98
- const roRef = useRef<ResizeObserver | null>(null)
99
- const [height, setHeight] = useState<number | null>(null)
100
- const ref = useCallback((el: HTMLElement | null) => {
101
- roRef.current?.disconnect()
102
- roRef.current = null
103
- if (!el) return
104
- const sync = () => {
105
- const next = el.parentElement?.scrollHeight ?? el.offsetHeight
106
- if (next > 0) setHeight(next)
107
- }
108
- sync()
109
- const ro = new ResizeObserver(sync)
110
- ro.observe(el)
111
- roRef.current = ro
112
- }, [])
113
- return [ref, height] as const
114
- }
115
-
116
- // Touch devices have no hover, so hover-revealed affordances (like a queued
117
- // row's × button) would never appear. `(hover: none)` flags those so they can
118
- // be shown persistently instead. SSR-safe: starts false, resolves on mount.
119
- function useIsTouch() {
120
- const [isTouch, setIsTouch] = useState(false)
121
- useEffect(() => {
122
- const mq = window.matchMedia('(hover: none)')
123
- const update = () => setIsTouch(mq.matches)
124
- update()
125
- mq.addEventListener('change', update)
126
- return () => mq.removeEventListener('change', update)
127
- }, [])
128
- return isTouch
129
- }
37
+ import { FilePreviewTile } from './file-preview-tile'
38
+ import { QueuedRow } from './queued-row'
39
+ import {
40
+ caretToEnd,
41
+ type InputMessageSlot,
42
+ type InputMessageSlotContext,
43
+ type InputMessageStatus,
44
+ type QueuedMessage,
45
+ } from './shared'
46
+ import { SuggestionRow } from './suggestion-row'
47
+ import { useComposerFiles } from './use-composer-files'
48
+ import { useHistoryNav } from './use-history-nav'
49
+ import { useMessageQueue } from './use-message-queue'
50
+ import { useRegionHeight } from './use-region-height'
130
51
 
131
52
  const DEFAULT_ACCEPT = 'image/png,image/jpeg,application/pdf'
132
-
133
- // Stable empty seeds: `useControllableState` reads its default once, but a
134
- // fresh literal on every render would still churn the identity it stores.
135
- const NO_FILES: File[] = []
136
- const NO_QUEUE: QueuedMessage[] = []
137
-
138
- type InputMessageStatus = 'idle' | 'streaming'
139
-
140
- interface InputMessageSlotContext {
141
- /** Opens the native file picker via the hidden `<input type="file">`.
142
- * Pass `acceptOverride` (e.g. `"image/*"`) to scope the picker to a
143
- * subset of the component's accept types just for this invocation. */
144
- openFilePicker: (acceptOverride?: string) => void
145
- /** Currently-attached files. */
146
- files: File[]
147
- }
148
-
149
- type InputMessageSlot = ReactNode | ((ctx: InputMessageSlotContext) => ReactNode)
150
-
151
- /** A message held in the queue while the assistant is responding. Carries the
152
- * trimmed text plus a snapshot of the files attached when it was queued, so
153
- * double-click-to-edit can restore both. `id` is a stable key minted on enqueue. */
154
- interface QueuedMessage {
155
- id: string
156
- text: string
157
- files: File[]
158
- }
53
+ const NO_STRINGS: string[] = []
54
+ const REGION_SPRING = { ...spring.moderate, bounce: 0 }
159
55
 
160
56
  interface InputMessageProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
161
57
  /** Step on the size ladder (see Sizes). Wins over the surrounding SizeProvider and propagates to the composer's rows, buttons and queued messages. */
@@ -194,7 +90,7 @@ interface InputMessageProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChan
194
90
  accept?: string
195
91
  /** Maximum number of attached files. Extra files beyond this limit are dropped. */
196
92
  maxFiles?: number
197
- /** Side length (in pixels) of each preview tile. Images use object-cover; PDFs render the first page via pdfjs; other types fall back to a centered icon. Defaults to 80. */
93
+ /** Side length (in pixels) of each preview tile. Images use object-cover; PDFs render the first page via pdfjs (an optional peer: without `pdfjs-dist` they show the file icon); other types fall back to a centered icon. Defaults to 80. */
198
94
  filePreviewSize?: number
199
95
  /** Extra props forwarded to the underlying textarea (value, onChange, onKeyDown, disabled and placeholder are controlled by the component). */
200
96
  textareaProps?: Omit<
@@ -227,220 +123,7 @@ interface InputMessageProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChan
227
123
  className?: string
228
124
  }
229
125
 
230
- // ─── File preview tile ────────────────────────────────────────────────────
231
- // Composer-row tile: a FileThumbnail wrapped with enter/exit motion and a
232
- // hover-revealed remove (×) button.
233
- interface FilePreviewTileProps {
234
- file: File
235
- onRemove: () => void
236
- size: number
237
- }
238
-
239
- // React 18: the tile is rendered inside `<AnimatePresence mode="popLayout">`,
240
- // which measures the exiting child through a ref. Upstream can be a plain
241
- // function component (React 19 passes `ref` as a prop); here it has to be a
242
- // forwardRef, or React logs "Function components cannot be given refs" and the
243
- // pop-out measurement never lands.
244
- const FilePreviewTile = forwardRef<HTMLDivElement, FilePreviewTileProps>(function FilePreviewTile(
245
- { file, onRemove, size },
246
- ref,
247
- ) {
248
- const XIcon = useIcon('x')
249
-
250
- return (
251
- <motion.div
252
- ref={ref}
253
- // `layout` animates sibling tiles into the gap when one is removed.
254
- // Enter: spring.fast (0.08s) — the small-state-flip tier.
255
- // Exit: 0.06s linear — exits should be slightly faster than enter.
256
- layout
257
- initial={{ opacity: 0, scale: 0.9 }}
258
- animate={{ opacity: 1, scale: 1 }}
259
- exit={{ opacity: 0, scale: 0.9, transition: spring.fast.exit }}
260
- transition={spring.fast}
261
- // `cursor-default` opts out of the parent's `cursor-text` so hovering
262
- // a preview tile doesn't look like it'll land in the textarea.
263
- className="relative shrink-0 cursor-default group/tile"
264
- >
265
- <FileThumbnail file={file} size={size} />
266
- <Tooltip content="Remove" side="top">
267
- <button
268
- type="button"
269
- onClick={e => {
270
- e.stopPropagation()
271
- onRemove()
272
- }}
273
- aria-label={`Remove ${file.name}`}
274
- // Pinned to the light scheme (`light` class: dark circle + light X)
275
- // regardless of theme — the close badge needs to read as a "delete
276
- // affordance" over arbitrary image/PDF content, so it sits at a fixed
277
- // contrast instead of flipping with the surrounding surface.
278
- className="light absolute top-1 right-1 w-5 h-5 rounded-full bg-foreground text-background opacity-0 group-hover/tile:opacity-100 transition-opacity duration-fast flex items-center justify-center cursor-pointer outline-none focus-visible:opacity-100 focus-visible:ring-1 focus-visible:ring-focus-ring"
279
- >
280
- <XIcon size={12} strokeWidth={2.5} />
281
- </button>
282
- </Tooltip>
283
- </motion.div>
284
- )
285
- })
286
-
287
- // ─── Queued message row ───────────────────────────────────────────────────
288
- // A pending message in the queue: a recessed, draggable row that reads as
289
- // "staged, not live". Double-click (or Enter/F2) edits it back into the
290
- // composer; the hover-revealed × (or Delete) removes it; drag — or Alt+↑/↓ —
291
- // reorders. Top of the list is next to dispatch.
292
- interface QueuedRowProps {
293
- item: QueuedMessage
294
- index: number
295
- total: number
296
- reduceMotion: boolean
297
- isTouch: boolean
298
- onEdit: (item: QueuedMessage) => void
299
- onRemove: (item: QueuedMessage) => void
300
- onMove: (item: QueuedMessage, dir: -1 | 1) => void
301
- }
302
-
303
- function QueuedRow({ item, index, total, reduceMotion, isTouch, onEdit, onRemove, onMove }: QueuedRowProps) {
304
- const XIcon = useIcon('x')
305
- const ImageIcon = useIcon('image')
306
- const compactStep = useSize().variant === 'compact'
307
- const fileCount = item.files.length
308
- const label = item.text || `${fileCount} attachment${fileCount === 1 ? '' : 's'}`
309
-
310
- return (
311
- <Reorder.Item
312
- value={item}
313
- layout
314
- // Enter: spring-fast chip category. Exit slightly faster (0.06s linear).
315
- // Reduced-motion drops the scale.
316
- initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.97 }}
317
- animate={{ opacity: 1, scale: 1 }}
318
- exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.97, transition: spring.fast.exit }}
319
- transition={spring.fast}
320
- aria-label={`Queued message ${index + 1} of ${total}: ${label}`}
321
- tabIndex={0}
322
- onDoubleClick={() => onEdit(item)}
323
- onKeyDown={e => {
324
- if (e.key === 'Enter' || e.key === 'F2') {
325
- e.preventDefault()
326
- onEdit(item)
327
- } else if (e.key === 'Delete' || e.key === 'Backspace') {
328
- e.preventDefault()
329
- onRemove(item)
330
- } else if (e.altKey && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
331
- e.preventDefault()
332
- onMove(item, e.key === 'ArrowUp' ? -1 : 1)
333
- }
334
- }}
335
- className={cn(
336
- // Fixed height (was py-1.5 around a 19.5px line box ≈ 31.5px) so the
337
- // text-box trim on the label doesn't shrink the row.
338
- 'group/qrow flex items-center gap-2 rounded-lg bg-muted',
339
- compactStep ? 'h-7 px-2 text-body-compact' : 'h-8 px-2.5 text-body',
340
- 'text-foreground/85 select-none outline-none',
341
- 'cursor-grab active:cursor-grabbing',
342
- 'focus-visible:ring-1 focus-visible:ring-focus-ring',
343
- 'weight-normal',
344
- )}
345
- >
346
- {fileCount > 0 && (
347
- <span className="flex shrink-0 items-center gap-0.5 text-muted-foreground">
348
- <ImageIcon size={13} />
349
- {item.text && <span className="tabular-nums">{fileCount}</span>}
350
- </span>
351
- )}
352
- {/* py-1/-my-1 keeps truncate's overflow-hidden from clipping
353
- ascenders and descenders outside the trimmed box. */}
354
- <span className="min-w-0 flex-1 truncate [text-box:trim-both_cap_alphabetic] py-1 -my-1">{label}</span>
355
- <Tooltip content="Remove" side="top">
356
- <button
357
- type="button"
358
- // Stop the pointer-down from starting a Reorder drag, and the click
359
- // from bubbling to the row's double-click/edit handler.
360
- onPointerDown={e => e.stopPropagation()}
361
- onClick={e => {
362
- e.stopPropagation()
363
- onRemove(item)
364
- }}
365
- aria-label={`Remove queued message: ${label}`}
366
- className={cn(
367
- 'shrink-0 flex h-5 w-5 items-center justify-center rounded-full',
368
- 'text-muted-foreground hover:text-foreground hover:bg-hover',
369
- // Hover devices reveal × on row-hover; touch has no hover, so keep
370
- // it persistently visible there.
371
- isTouch ? 'opacity-100' : 'opacity-0 group-hover/qrow:opacity-100 focus-visible:opacity-100',
372
- 'transition-opacity duration-fast cursor-pointer outline-none',
373
- 'focus-visible:ring-1 focus-visible:ring-focus-ring',
374
- )}
375
- >
376
- <XIcon size={13} strokeWidth={2.5} />
377
- </button>
378
- </Tooltip>
379
- </Reorder.Item>
380
- )
381
- }
382
-
383
- // ─── Suggestion row ───────────────────────────────────────────────────────
384
- // A suggested prompt in the listbox under the action bar. Registers itself
385
- // with the fluid-hover system in an effect (MenuItem's pattern — an
386
- // inline ref callback would re-register every render and keep the hook's
387
- // measurement pass from ever settling). The highlight itself is the parent's
388
- // sliding overlay, so the row only recolors its text when active.
389
- interface SuggestionRowProps {
390
- text: string
391
- index: number
392
- active: boolean
393
- /** Show a ↓ keycap hint in the icon slot — the first row displays it while
394
- * no row is highlighted, signposting that ArrowDown enters the list. */
395
- keyHint: boolean
396
- optionId: string
397
- registerItem: (index: number, element: HTMLElement | null) => void
398
- onSelect: () => void
399
- }
400
-
401
- function SuggestionRow({ text, index, active, keyHint, optionId, registerItem, onSelect }: SuggestionRowProps) {
402
- const EnterIcon = useIcon('corner-down-left')
403
- const ArrowDownIcon = useIcon('arrow-down')
404
- const compactStep = useSize().variant === 'compact'
405
- const ref = useRef<HTMLDivElement>(null)
406
-
407
- useRegisterFluidHoverItem(registerItem, index, ref)
408
-
409
- return (
410
- <div
411
- ref={ref}
412
- id={optionId}
413
- role="option"
414
- aria-selected={active}
415
- onClick={onSelect}
416
- className={cn(
417
- 'relative flex cursor-pointer items-center gap-2',
418
- // Text size mirrors the composer's textarea/placeholder (the rows
419
- // read as prompt candidates, not metadata); heights follow the
420
- // QueuedRow step ladder.
421
- compactStep ? 'h-7 px-2 text-subtitle-compact' : 'h-8 px-2.5 text-subtitle',
422
- 'text-muted-foreground transition-colors duration-fast',
423
- active && 'text-foreground',
424
- 'weight-normal',
425
- )}
426
- >
427
- <span className="min-w-0 flex-1 truncate [text-box:trim-both_cap_alphabetic] py-1 -my-1">{text}</span>
428
- {/* One icon slot: ↵ on the highlighted row; on the first row a muted ↓
429
- takes the same slot while nothing is highlighted, signposting the
430
- keyboard path into the list. */}
431
- {!active && keyHint ? (
432
- <ArrowDownIcon size={13} className="shrink-0 text-muted-foreground/70 transition-opacity duration-fast" />
433
- ) : (
434
- <EnterIcon
435
- size={13}
436
- className={cn('shrink-0 transition-opacity duration-fast', active ? 'opacity-100' : 'opacity-0')}
437
- />
438
- )}
439
- </div>
440
- )
441
- }
442
-
443
- // ─── InputMessage ─────────────────────────────────────────────────────────
126
+ const isPlain = (e: ReactKeyboardEvent) => !e.shiftKey && !e.altKey && !e.metaKey && !e.ctrlKey
444
127
 
445
128
  /**
446
129
  * Chat-style message composer with an auto-resizing textarea, flexible
@@ -464,7 +147,12 @@ function SuggestionRow({ text, index, active, keyHint, optionId, registerItem, o
464
147
  * `defaultFiles`, `defaultQueue`, `defaultStatus` — so a composer can hold
465
148
  * its own draft, attachments and queue with no state in the caller.
466
149
  *
150
+ * Also exported from this item: `FileThumbnail`, the square preview the
151
+ * attachment tiles use, for showing sent attachments in a transcript.
152
+ *
467
153
  * @example {@include ./examples.mdx}
154
+ * @source https://github.com/mickadesign/fluid-functionalism/blob/b3587bdbd83fc66c2a6aae3817ffb856cb09260b/registry/default/input-message.tsx Fluid Functionalism
155
+ * @license MIT © 2026 Micka Touillaud
468
156
  */
469
157
  const InputMessage = forwardRef<HTMLDivElement, InputMessageProps>(
470
158
  (
@@ -482,26 +170,25 @@ const InputMessage = forwardRef<HTMLDivElement, InputMessageProps>(
482
170
  maxRows = 8,
483
171
  clickToFocus = true,
484
172
  sendLabel = 'Send',
485
- files: filesProp,
173
+ files,
486
174
  defaultFiles,
487
175
  onFilesChange,
488
176
  accept = DEFAULT_ACCEPT,
489
177
  maxFiles,
490
178
  filePreviewSize = 80,
491
179
  textareaProps,
492
- status: statusProp,
180
+ status,
493
181
  defaultStatus,
494
182
  onStatusChange,
495
183
  onStop,
496
- queue: queueProp,
184
+ queue,
497
185
  defaultQueue,
498
186
  onQueueChange,
499
187
  showQueue = true,
500
- history = [],
188
+ history = NO_STRINGS,
501
189
  placeholderSuggestion,
502
190
  suggestions,
503
191
  className,
504
- style,
505
192
  ...props
506
193
  },
507
194
  ref,
@@ -509,78 +196,37 @@ const InputMessage = forwardRef<HTMLDivElement, InputMessageProps>(
509
196
  const shape = useShape()
510
197
  const compactStep = useSize(size).variant === 'compact'
511
198
  const ArrowUpIcon = useIcon('arrow-up')
512
- const reduceMotion = useReducedMotion() ?? false
513
- const isTouch = useIsTouch()
514
-
199
+ const reduceMotion = useReduceMotion()
200
+ const isTouch = useTouchPrimary()
515
201
  const textareaRef = useRef<HTMLTextAreaElement>(null)
516
- const fileInputRef = useRef<HTMLInputElement>(null)
517
- const [focusVisible, setFocusVisible] = useState(false)
518
- const [dragOver, setDragOver] = useState(false)
519
- const [hovered, setHovered] = useState(false)
520
-
521
- // Split out onFocus/onBlur so the rest-spread onto the textarea can't
522
- // clobber the composed handlers below.
523
202
  const {
524
- onFocus: _textareaOnFocus,
525
- onBlur: _textareaOnBlur,
203
+ onBlur: textareaOnBlur,
526
204
  'aria-describedby': textareaDescribedBy,
527
205
  ...restTextareaProps
528
206
  } = textareaProps ?? {}
529
207
 
530
- // ── Controlled / uncontrolled state ───────────────────────────────
531
- // Each pair keeps upstream's controlled contract (the prop wins, the
532
- // callback still fires) and gains an internal fallback, so the composer
533
- // runs with no state in the caller.
534
208
  const valueControlled = valueProp !== undefined
535
209
  const [value, setValue] = useControllableState<string>(valueProp, defaultValue ?? '', onValueChange)
536
-
537
- const filesControlled = filesProp !== undefined
538
- const supportsFiles = onFilesChange !== undefined || defaultFiles !== undefined
539
- const [filesArr, setFiles] = useControllableState<File[]>(filesProp, defaultFiles ?? NO_FILES, onFilesChange)
540
-
541
- // Queue is active only when a status exists (controlled or seeded) and a
542
- // queue is wired — same opt-in shape as `supportsFiles`.
543
- const statusEnabled = statusProp !== undefined || defaultStatus !== undefined
544
- const [statusValue, setStatus] = useControllableState<InputMessageStatus>(
545
- statusProp,
546
- defaultStatus ?? 'idle',
210
+ const attachments = useComposerFiles({ files, defaultFiles, onFilesChange, accept, maxFiles, disabled })
211
+ const messages = useMessageQueue({
212
+ status,
213
+ defaultStatus,
547
214
  onStatusChange,
548
- )
549
- const status = statusEnabled ? statusValue : undefined
550
- const streaming = status === 'streaming'
551
-
552
- const [queueArr, setQueue] = useControllableState<QueuedMessage[]>(
553
- queueProp,
554
- defaultQueue ?? NO_QUEUE,
215
+ onStop,
216
+ queue,
217
+ defaultQueue,
555
218
  onQueueChange,
556
- )
557
- // Always-current view of the queue, so enqueue/edit/remove/move read the
558
- // latest value even if a handler closure is stale (e.g. two submits land
559
- // before the controlled `queue` prop round-trips back).
560
- const queueRef = useRef(queueArr)
561
- queueRef.current = queueArr
562
- const supportsQueue = statusEnabled && (onQueueChange !== undefined || defaultQueue !== undefined)
563
- const [liveMsg, setLiveMsg] = useState('')
219
+ onSend,
220
+ })
221
+ const recall = useHistoryNav(history, value, setValue, textareaRef)
564
222
 
565
- // Sent-message history navigation (readline-style). `historyIndex` is null
566
- // when not browsing; `draftBeforeHistory` stashes the in-progress text so
567
- // ArrowDown past the newest entry restores it.
568
- const [historyIndex, setHistoryIndex] = useState<number | null>(null)
569
- const draftBeforeHistory = useRef('')
223
+ useAutosizeTextarea(textareaRef, { minRows, maxRows }, [value, compactStep])
570
224
 
571
- // Suggested prompts. The list only shows while the draft is empty, and
572
- // `activeSuggestion` is the highlighted row — focus never leaves the
573
- // textarea (aria-activedescendant points at the highlighted option).
574
- // Highlight state lives in the fluid-hover system so pointer and
575
- // keyboard drive the same sliding bg-hover overlay (Dropdown's pattern):
576
- // mouse movement resolves the nearest row, ↓/↑ set the index directly.
577
- const suggestionsArr = useMemo(() => suggestions ?? [], [suggestions])
578
- const suggestionsOpen = suggestionsArr.length > 0 && value === ''
225
+ // The list shows while the draft is empty; focus stays in the textarea
226
+ // (aria-activedescendant), and pointer and keyboard drive one fluid-hover highlight.
227
+ const suggestionList = suggestions ?? NO_STRINGS
228
+ const suggestionsOpen = suggestionList.length > 0 && value === ''
579
229
  const suggestionListRef = useRef<HTMLDivElement | null>(null)
580
- // Pixel heights for the three collapsible regions (see useRegionHeight).
581
- const [filesRegionRef, filesRegionHeight] = useRegionHeight()
582
- const [queueRegionRef, queueRegionHeight] = useRegionHeight()
583
- const [suggestionsRegionRef, suggestionsRegionHeight] = useRegionHeight()
584
230
  const suggestionHover = useFluidHover(suggestionListRef)
585
231
  const {
586
232
  activeIndex: activeSuggestion,
@@ -589,791 +235,385 @@ const InputMessage = forwardRef<HTMLDivElement, InputMessageProps>(
589
235
  registerItem: registerSuggestion,
590
236
  remeasure,
591
237
  } = suggestionHover
592
-
593
- // Rows stay registered while the list is closed, so their rects are from
594
- // a hidden layout: re-measure on open. The highlight waits for it.
595
- useEffect(() => {
596
- if (suggestionsOpen) remeasure()
597
- }, [suggestionsOpen, remeasure])
598
238
  const suggestionListId = useId()
599
239
  const ghostHintId = useId()
600
- const showGhost = !!placeholderSuggestion && value === '' && !(dragOver && supportsFiles)
240
+ const showGhost = !!placeholderSuggestion && value === '' && !attachments.dragging
601
241
 
242
+ const [filesRegionRef, filesRegionHeight] = useRegionHeight()
243
+ const [queueRegionRef, queueRegionHeight] = useRegionHeight()
244
+ const [suggestionsRegionRef, suggestionsRegionHeight] = useRegionHeight()
245
+
246
+ // Closed rows keep their registration with stale rects: remeasure on open.
602
247
  useEffect(() => {
603
- if (!suggestionsOpen) setActiveSuggestion(null)
604
- }, [suggestionsOpen, setActiveSuggestion])
248
+ if (suggestionsOpen) remeasure()
249
+ else setActiveSuggestion(null)
250
+ }, [suggestionsOpen, remeasure, setActiveSuggestion])
605
251
 
606
- // Fill a suggested prompt into the composer (Tab / Enter / click). Fills
607
- // only — the user still reviews and sends.
608
252
  const acceptSuggestion = useCallback(
609
253
  (text: string) => {
610
254
  setActiveSuggestion(null)
611
- setHistoryIndex(null)
255
+ recall.exit()
612
256
  setValue(text)
613
- requestAnimationFrame(() => {
614
- const el = textareaRef.current
615
- if (!el) return
616
- el.focus()
617
- el.setSelectionRange(el.value.length, el.value.length)
618
- })
257
+ caretToEnd(textareaRef)
619
258
  },
620
- [setValue, setActiveSuggestion],
259
+ [setValue, setActiveSuggestion, recall.exit],
621
260
  )
622
261
 
623
- // Parsed line-height, cached per textarea element — getComputedStyle on
624
- // every keystroke is needless work when the value only changes with font
625
- // or zoom changes.
626
- const lineHeightCache = useRef<{ el: HTMLTextAreaElement; value: number } | null>(null)
627
-
628
- const resizeTextarea = useCallback(() => {
629
- const el = textareaRef.current
630
- if (!el) return
631
- el.style.height = 'auto'
632
- let cache = lineHeightCache.current
633
- if (!cache || cache.el !== el) {
634
- const lineHeight = parseFloat(getComputedStyle(el).lineHeight)
635
- cache = { el, value: Number.isNaN(lineHeight) ? 20 : lineHeight }
636
- lineHeightCache.current = cache
637
- }
638
- const min = cache.value * minRows
639
- const max = cache.value * maxRows
640
- const next = Math.min(Math.max(el.scrollHeight, min), max)
641
- el.style.height = `${next}px`
642
- el.style.overflowY = el.scrollHeight > max ? 'auto' : 'hidden'
643
- }, [minRows, maxRows])
644
-
645
- useIsoLayoutEffect(() => {
646
- resizeTextarea()
647
- }, [value, resizeTextarea])
648
-
649
- // Re-measure when the textarea's width changes. The mount-time pass can
650
- // run while an ancestor is still laid out at (near-)zero width — the
651
- // wrapped placeholder then reads as many lines and pins the height at
652
- // maxRows until the next value change. Width-gated so the observer
653
- // doesn't loop on its own height writes.
654
- useEffect(() => {
655
- const el = textareaRef.current
656
- if (!el || typeof ResizeObserver === 'undefined') return
657
- let lastWidth = el.offsetWidth
658
- const ro = new ResizeObserver(() => {
659
- const width = el.offsetWidth
660
- if (width === lastWidth) return
661
- lastWidth = width
662
- resizeTextarea()
663
- })
664
- ro.observe(el)
665
- return () => ro.disconnect()
666
- }, [resizeTextarea])
667
-
668
262
  const trimmed = value.trim()
669
- const canSend = !disabled && (trimmed.length > 0 || filesArr.length > 0)
670
-
671
- // Edge = the box-shadow's 1px ring, recoloured in place per state so the
672
- // stroke gains contrast without ever appearing to thicken (no second
673
- // border band layered beside it). The drop (`0 1px 1px`) is kept so the
674
- // composer holds its lift across states. Applied inline (not via a
675
- // `shadow-*` utility, which mangles multi-layer arbitrary values) with the
676
- // precedence drag > focus > hover; when none are active, the className's
677
- // `shadow-surface-2` supplies the resting edge.
678
- const EDGE_DROP = '0 1px 1px -0.5px var(--shadow-color)'
679
- const edgeShadow = dragOver
680
- ? `0 0 0 1px var(--brand), ${EDGE_DROP}`
681
- : focusVisible
682
- ? `0 0 0 1px color-mix(in oklab, var(--foreground) 20%, transparent), ${EDGE_DROP}`
683
- : hovered && clickToFocus && !disabled
684
- ? `0 0 0 1px var(--border), ${EDGE_DROP}`
685
- : undefined
263
+ const canSend = !disabled && (trimmed.length > 0 || attachments.files.length > 0)
686
264
 
687
- const handleSend = useCallback(() => {
265
+ const handleSend = () => {
688
266
  if (!canSend) return
689
- setHistoryIndex(null)
690
- // While the assistant is streaming, a submit enqueues instead of sending:
691
- // snapshot the draft (text + currently-attached files) into a queue item,
692
- // then clear the composer and keep focus.
693
- if (streaming && supportsQueue) {
694
- const item: QueuedMessage = {
695
- id: crypto.randomUUID(),
696
- text: trimmed,
697
- files: filesArr,
698
- }
699
- setQueue([...queueRef.current, item])
267
+ recall.exit()
268
+ if (messages.streaming && messages.supported) {
269
+ messages.enqueue(trimmed, attachments.files)
700
270
  setValue('')
701
- if (supportsFiles) setFiles([])
702
- requestAnimationFrame(() => textareaRef.current?.focus())
271
+ attachments.replace([])
272
+ caretToEnd(textareaRef)
703
273
  return
704
274
  }
705
- onSend?.(trimmed, filesArr)
706
- // Local addition: an uncontrolled draft / file list clears itself, the
707
- // way a controlled consumer clears its own state inside `onSend`.
275
+ onSend?.(trimmed, attachments.files)
708
276
  if (!valueControlled) setValue('')
709
- if (supportsFiles && !filesControlled) setFiles([])
710
- }, [
711
- canSend,
712
- streaming,
713
- supportsQueue,
714
- onSend,
715
- trimmed,
716
- filesArr,
717
- setQueue,
718
- setValue,
719
- supportsFiles,
720
- setFiles,
721
- valueControlled,
722
- filesControlled,
723
- ])
724
-
725
- // Stop halts the response. With the status uncontrolled the component owns
726
- // that flag, so it flips itself to "idle" — the edge the auto-dispatch
727
- // below watches for.
728
- const statusControlled = statusProp !== undefined
729
- const handleStop = useCallback(() => {
730
- onStop?.()
731
- if (!statusControlled) setStatus('idle')
732
- }, [onStop, statusControlled, setStatus])
733
-
734
- // Auto-dispatch: on the streaming → idle edge (whether the response
735
- // finished on its own or the user pressed Stop), fire the head of the
736
- // queue and drop it. The consumer is expected to set status back to
737
- // "streaming" inside onSend, which re-arms this for the next item.
738
- const prevStatusRef = useRef(status)
739
- useEffect(() => {
740
- const prev = prevStatusRef.current
741
- prevStatusRef.current = status
742
- if (!supportsQueue) return
743
- if (prev === 'streaming' && status === 'idle' && queueArr.length > 0) {
744
- const [next, ...rest] = queueArr
745
- if (!next) return
746
- setQueue(rest)
747
- onSend?.(next.text, next.files, { queuedId: next.id })
748
- setLiveMsg(`Message sent.${rest.length ? ` ${rest.length} still queued.` : ''}`)
749
- }
750
- }, [status, supportsQueue, queueArr, setQueue, onSend])
751
-
752
- // ── Queue item actions ────────────────────────────────────────────
753
- const editQueued = useCallback(
754
- (item: QueuedMessage) => {
755
- if (!supportsQueue) return
756
- // Silent replace: pull the item out of the queue into the composer,
757
- // overwriting any current draft. Re-sending re-queues it to the end.
758
- setHistoryIndex(null)
759
- setValue(item.text)
760
- if (supportsFiles) {
761
- setFiles(maxFiles != null ? item.files.slice(0, maxFiles) : item.files)
762
- }
763
- setQueue(queueRef.current.filter(q => q.id !== item.id))
764
- requestAnimationFrame(() => {
765
- const el = textareaRef.current
766
- if (!el) return
767
- el.focus()
768
- el.setSelectionRange(el.value.length, el.value.length)
769
- })
770
- },
771
- [supportsQueue, supportsFiles, setValue, setFiles, maxFiles, setQueue],
772
- )
773
-
774
- const removeQueued = useCallback(
775
- (item: QueuedMessage) => setQueue(queueRef.current.filter(q => q.id !== item.id)),
776
- [setQueue],
777
- )
277
+ if (!attachments.controlled) attachments.replace([])
278
+ }
778
279
 
779
- const moveQueued = useCallback(
780
- (item: QueuedMessage, dir: -1 | 1) => {
781
- const cur = queueRef.current
782
- const i = cur.findIndex(q => q.id === item.id)
783
- const j = i + dir
784
- if (i < 0 || j < 0 || j >= cur.length) return
785
- const next = [...cur]
786
- const a = next[i]
787
- const b = next[j]
788
- if (!a || !b) return
789
- next[i] = b
790
- next[j] = a
791
- setQueue(next)
792
- },
793
- [setQueue],
794
- )
280
+ const editQueued = (item: QueuedMessage) => {
281
+ recall.exit()
282
+ setValue(item.text)
283
+ attachments.replace(item.files)
284
+ messages.remove(item)
285
+ caretToEnd(textareaRef)
286
+ }
795
287
 
796
- // Send button morph: Stop (streaming + empty draft) → Queue (streaming +
797
- // draft) → Send (idle). Send and Queue share the arrow-up glyph; only the
798
- // Stop⇄arrow swap animates. An uncontrolled status can always stop.
799
- const canStop = onStop !== undefined || !statusControlled
800
- const buttonMode: 'send' | 'queue' | 'stop' = !streaming
288
+ const buttonMode: 'send' | 'queue' | 'stop' = !messages.streaming
801
289
  ? 'send'
802
- : canSend && supportsQueue
290
+ : canSend && messages.supported
803
291
  ? 'queue'
804
- : canStop
292
+ : messages.canStop
805
293
  ? 'stop'
806
294
  : 'send'
807
295
  const buttonLabel = buttonMode === 'stop' ? 'Stop' : buttonMode === 'queue' ? 'Queue message' : sendLabel
808
296
 
809
- const setCaretEnd = useCallback(() => {
810
- requestAnimationFrame(() => {
811
- const el = textareaRef.current
812
- if (el) el.setSelectionRange(el.value.length, el.value.length)
813
- })
814
- }, [])
815
-
816
- const handleKeyDown = useCallback(
817
- (e: ReactKeyboardEvent<HTMLTextAreaElement>) => {
818
- if (e.nativeEvent.isComposing) return
819
-
820
- // Suggested prompts: plain ArrowDown moves the highlight into / down
821
- // the list, ArrowUp walks it back up (then out, returning to plain
822
- // textarea behavior), Enter fills the highlighted prompt, Escape
823
- // drops the highlight. With no highlight, ArrowUp still falls through
824
- // to history recall below.
825
- if (suggestionsOpen && !e.shiftKey && !e.altKey && !e.metaKey && !e.ctrlKey) {
826
- if (e.key === 'ArrowDown') {
827
- e.preventDefault()
828
- setActiveSuggestion(prev => (prev == null ? 0 : Math.min(prev + 1, suggestionsArr.length - 1)))
829
- return
830
- }
831
- if (activeSuggestion != null) {
832
- if (e.key === 'ArrowUp') {
833
- e.preventDefault()
834
- setActiveSuggestion(activeSuggestion === 0 ? null : activeSuggestion - 1)
835
- return
836
- }
837
- if (e.key === 'Enter') {
838
- e.preventDefault()
839
- const picked = suggestionsArr[activeSuggestion]
840
- if (picked !== undefined) acceptSuggestion(picked)
841
- return
842
- }
843
- if (e.key === 'Escape') {
844
- e.preventDefault()
845
- setActiveSuggestion(null)
846
- return
847
- }
848
- }
849
- }
297
+ const handleKeyDown = (e: ReactKeyboardEvent<HTMLTextAreaElement>) => {
298
+ if (e.nativeEvent.isComposing) return
850
299
 
851
- // Tab fills the suggested placeholder prompt into the empty composer
852
- // (Shift+Tab still moves focus backward, and once the draft is
853
- // non-empty Tab resumes normal focus traversal).
854
- if (e.key === 'Tab' && !e.shiftKey && placeholderSuggestion && value === '') {
300
+ if (suggestionsOpen && isPlain(e)) {
301
+ if (e.key === 'ArrowDown') {
855
302
  e.preventDefault()
856
- acceptSuggestion(placeholderSuggestion)
303
+ setActiveSuggestion(prev => (prev == null ? 0 : Math.min(prev + 1, suggestionList.length - 1)))
857
304
  return
858
305
  }
859
-
860
- // Readline-style history. Only plain ArrowUp/ArrowDown navigate (no
861
- // modifiers), and only when the caret is on the first/last line so
862
- // multi-line editing still works normally.
863
- if (
864
- history.length > 0 &&
865
- (e.key === 'ArrowUp' || e.key === 'ArrowDown') &&
866
- !e.shiftKey &&
867
- !e.altKey &&
868
- !e.metaKey &&
869
- !e.ctrlKey
870
- ) {
871
- const el = e.currentTarget
872
- const caret = el.selectionStart ?? 0
873
- const end = el.selectionEnd ?? caret
874
- if (e.key === 'ArrowUp' && !value.slice(0, caret).includes('\n')) {
875
- const start = historyIndex == null ? history.length : historyIndex
876
- if (start > 0) {
877
- e.preventDefault()
878
- if (historyIndex == null) draftBeforeHistory.current = value
879
- const ni = start - 1
880
- setHistoryIndex(ni)
881
- setValue(history[ni] ?? '')
882
- setCaretEnd()
883
- }
306
+ if (activeSuggestion != null) {
307
+ if (e.key === 'ArrowUp') {
308
+ e.preventDefault()
309
+ setActiveSuggestion(activeSuggestion === 0 ? null : activeSuggestion - 1)
884
310
  return
885
311
  }
886
- if (e.key === 'ArrowDown' && historyIndex != null && !value.slice(end).includes('\n')) {
312
+ if (e.key === 'Enter') {
887
313
  e.preventDefault()
888
- const ni = historyIndex + 1
889
- if (ni >= history.length) {
890
- setHistoryIndex(null)
891
- setValue(draftBeforeHistory.current)
892
- } else {
893
- setHistoryIndex(ni)
894
- setValue(history[ni] ?? '')
895
- }
896
- setCaretEnd()
314
+ const picked = suggestionList[activeSuggestion]
315
+ if (picked !== undefined) acceptSuggestion(picked)
316
+ return
317
+ }
318
+ if (e.key === 'Escape') {
319
+ e.preventDefault()
320
+ setActiveSuggestion(null)
897
321
  return
898
322
  }
899
323
  }
324
+ }
900
325
 
901
- if (e.key === 'Enter' && !e.shiftKey) {
902
- e.preventDefault()
903
- handleSend()
904
- }
905
- },
906
- [
907
- history,
908
- value,
909
- historyIndex,
910
- setValue,
911
- setCaretEnd,
912
- handleSend,
913
- suggestionsOpen,
914
- suggestionsArr,
915
- activeSuggestion,
916
- setActiveSuggestion,
917
- acceptSuggestion,
918
- placeholderSuggestion,
919
- ],
920
- )
921
-
922
- const handleContainerMouseDown = useCallback(
923
- (e: ReactMouseEvent<HTMLDivElement>) => {
924
- if (!clickToFocus || disabled) return
925
- const target = e.target as HTMLElement
926
- if (target === textareaRef.current) return
927
- // A press in a popup portalled out of the box reaches it through the React tree only.
928
- if (!e.currentTarget.contains(target)) return
929
- if (target.closest('button, a, input, select, textarea, [contenteditable], [role="button"], [data-im-queue]')) {
930
- return
931
- }
326
+ // Shift+Tab, and Tab once there is a draft, still move focus.
327
+ if (e.key === 'Tab' && !e.shiftKey && placeholderSuggestion && value === '') {
932
328
  e.preventDefault()
933
- textareaRef.current?.focus()
934
- },
935
- [clickToFocus, disabled],
936
- )
937
-
938
- // ── File helpers ──────────────────────────────────────────────────
939
- const acceptTokens = useMemo(
940
- () =>
941
- accept
942
- .split(',')
943
- .map(s => s.trim())
944
- .filter(Boolean),
945
- [accept],
946
- )
947
-
948
- const matchesAccept = useCallback(
949
- (file: File) =>
950
- acceptTokens.some(token => {
951
- if (token.endsWith('/*')) return file.type.startsWith(token.slice(0, -1))
952
- if (token.startsWith('.')) return file.name.toLowerCase().endsWith(token.toLowerCase())
953
- return file.type === token
954
- }),
955
- [acceptTokens],
956
- )
329
+ acceptSuggestion(placeholderSuggestion)
330
+ return
331
+ }
957
332
 
958
- const addFiles = useCallback(
959
- (incoming: File[]) => {
960
- if (!supportsFiles) return
961
- // Identity key for dedup: name + size + lastModified is unique enough
962
- // to catch "user dropped the same file twice" without false positives
963
- // on legitimately distinct files (different bytes ⇒ different size).
964
- const fingerprint = (f: File) => `${f.name}-${f.size}-${f.lastModified}`
965
- const existing = new Set(filesArr.map(fingerprint))
966
- const accepted: File[] = []
967
- for (const f of incoming) {
968
- if (!matchesAccept(f)) continue
969
- const fp = fingerprint(f)
970
- if (existing.has(fp)) continue
971
- existing.add(fp)
972
- accepted.push(f)
973
- }
974
- if (!accepted.length) return
975
- const next = [...filesArr, ...accepted]
976
- setFiles(maxFiles != null ? next.slice(0, maxFiles) : next)
977
- },
978
- [supportsFiles, setFiles, filesArr, matchesAccept, maxFiles],
979
- )
333
+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
334
+ recall.onKeyDown(e)
335
+ return
336
+ }
980
337
 
981
- const removeFile = useCallback(
982
- (idx: number) => {
983
- if (!supportsFiles) return
984
- setFiles(filesArr.filter((_, i) => i !== idx))
985
- },
986
- [supportsFiles, setFiles, filesArr],
987
- )
338
+ if (e.key === 'Enter' && !e.shiftKey) {
339
+ e.preventDefault()
340
+ handleSend()
341
+ }
342
+ }
988
343
 
989
- const openFilePicker = useCallback(
990
- (overrideAccept?: string) => {
991
- const el = fileInputRef.current
992
- if (!el) return
993
- // Temporarily narrow `accept` for this invocation (e.g. "image/*").
994
- // Reset after the click so subsequent native invocations still honor
995
- // the component-level accept.
996
- if (overrideAccept) {
997
- el.accept = overrideAccept
998
- el.click()
999
- // Restore on next tick — the picker dialog reads `accept` synchronously.
1000
- queueMicrotask(() => {
1001
- if (fileInputRef.current) fileInputRef.current.accept = accept
1002
- })
1003
- return
1004
- }
1005
- el.click()
1006
- },
1007
- [accept],
1008
- )
344
+ const handleContainerMouseDown = (e: ReactMouseEvent<HTMLDivElement>) => {
345
+ if (!clickToFocus || disabled) return
346
+ const target = e.target as HTMLElement
347
+ if (target === textareaRef.current) return
348
+ if (target.closest('button, a, input, select, textarea, [contenteditable], [role="button"], [data-im-queue]'))
349
+ return
350
+ e.preventDefault()
351
+ textareaRef.current?.focus()
352
+ }
1009
353
 
1010
- // ── Slot rendering ────────────────────────────────────────────────
1011
354
  const slotCtx = useMemo<InputMessageSlotContext>(
1012
- () => ({ openFilePicker, files: filesArr }),
1013
- [openFilePicker, filesArr],
355
+ () => ({ openFilePicker: attachments.openPicker, files: attachments.files }),
356
+ [attachments.openPicker, attachments.files],
1014
357
  )
1015
358
  const leftContent = typeof leftSlot === 'function' ? leftSlot(slotCtx) : leftSlot
1016
359
  const rightContent = typeof rightSlot === 'function' ? rightSlot(slotCtx) : rightSlot
1017
-
1018
- // ── Drag-and-drop ────────────────────────────────────────────────
1019
- const handleDragOver = useCallback(
1020
- (e: ReactDragEvent<HTMLDivElement>) => {
1021
- if (!supportsFiles || disabled) return
1022
- // Only treat as a file drag — text/HTML drags shouldn't trigger.
1023
- if (!Array.from(e.dataTransfer.types).includes('Files')) return
1024
- e.preventDefault()
1025
- e.dataTransfer.dropEffect = 'copy'
1026
- setDragOver(true)
1027
- },
1028
- [supportsFiles, disabled],
1029
- )
1030
-
1031
- const handleDragLeave = useCallback((e: ReactDragEvent<HTMLDivElement>) => {
1032
- const wrapper = e.currentTarget
1033
- const next = e.relatedTarget as Node | null
1034
- if (next && wrapper.contains(next)) return
1035
- setDragOver(false)
1036
- }, [])
1037
-
1038
- const handleDrop = useCallback(
1039
- (e: ReactDragEvent<HTMLDivElement>) => {
1040
- e.preventDefault()
1041
- setDragOver(false)
1042
- if (!supportsFiles || disabled) return
1043
- addFiles(Array.from(e.dataTransfer.files))
1044
- },
1045
- [supportsFiles, disabled, addFiles],
1046
- )
1047
-
1048
- const handleFileInputChange = useCallback(
1049
- (e: ChangeEvent<HTMLInputElement>) => {
1050
- if (!e.target.files) return
1051
- addFiles(Array.from(e.target.files))
1052
- e.target.value = '' // Allow re-selecting the same file.
1053
- },
1054
- [addFiles],
1055
- )
1056
-
1057
- const composer = (
1058
- <div
1059
- ref={ref}
1060
- onMouseDown={handleContainerMouseDown}
1061
- onDragOver={handleDragOver}
1062
- onDragLeave={handleDragLeave}
1063
- onDrop={handleDrop}
1064
- className={cn(
1065
- // The edge is the box-shadow's hairline ring (from surface-2), not a
1066
- // border. State changes recolor that same 1px ring in place rather
1067
- // than layering a second colored border beside it — so hover / focus
1068
- // bump *contrast* without ever appearing to thicken the stroke.
1069
- 'flex flex-col gap-1 p-2 transition-[box-shadow,color] duration-fast',
1070
- surfaceClasses(2, 2),
1071
- shape.container,
1072
- clickToFocus && !disabled && 'cursor-text',
1073
- disabled && 'opacity-50 pointer-events-none',
1074
- className,
1075
- )}
1076
- style={edgeShadow ? { boxShadow: edgeShadow, ...style } : style}
1077
- onMouseEnter={() => setHovered(true)}
1078
- onMouseLeave={() => setHovered(false)}
1079
- {...props}
1080
- >
1081
- <SurfaceProvider value={2}>
1082
- {supportsFiles && (
1083
- <input
1084
- ref={fileInputRef}
1085
- type="file"
1086
- accept={accept}
1087
- multiple={maxFiles == null || maxFiles > 1}
1088
- className="hidden"
1089
- onChange={handleFileInputChange}
1090
- aria-hidden="true"
1091
- tabIndex={-1}
1092
- />
360
+ const textStep = compactStep
361
+ ? 'text-subtitle-compact leading-4.5 px-1.5 py-1.5'
362
+ : 'text-subtitle leading-5 px-2 py-2'
363
+
364
+ return (
365
+ <SizeScope size={size}>
366
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: the textarea is the control; the panel forwards pointer focus and takes drops. */}
367
+ <div
368
+ ref={ref}
369
+ data-input-message=""
370
+ data-click-to-focus={clickToFocus && !disabled ? '' : undefined}
371
+ data-drag-over={attachments.dragging ? '' : undefined}
372
+ onMouseDown={handleContainerMouseDown}
373
+ {...attachments.dropHandlers}
374
+ className={cn(
375
+ 'flex flex-col gap-1 p-2 transition-[box-shadow,color] duration-fast',
376
+ surfaceClasses(2, 2),
377
+ shape.container,
378
+ clickToFocus && !disabled && 'cursor-text',
379
+ disabled && 'opacity-50 pointer-events-none',
380
+ className,
1093
381
  )}
1094
-
1095
- {/* Attached files preview row — sits above the textarea.
1096
- The outer motion.div animates the row's height (collapsing the
1097
- whole component height) when files appear / disappear.
1098
- The inner `mode="popLayout"` AnimatePresence pulls a removing
1099
- tile out of layout flow so siblings can slide into the gap
1100
- without fighting its exit anim. Keys are purely file-identity
1101
- (no index) so removing the first file doesn't re-key — and
1102
- remount — every surviving sibling. */}
1103
- <AnimatePresence initial={false}>
1104
- {filesArr.length > 0 && (
1105
- <motion.div
1106
- key="preview-row"
1107
- initial={{ height: 0, opacity: 0 }}
1108
- animate={{ height: filesRegionHeight ?? 0, opacity: 1 }}
1109
- exit={{ height: 0, opacity: 0 }}
1110
- transition={{ ...spring.moderate, bounce: 0 }}
1111
- className="overflow-hidden"
1112
- >
1113
- <div ref={filesRegionRef} className="flex flex-wrap gap-2 pb-1">
1114
- <AnimatePresence initial={false} mode="popLayout">
1115
- {filesArr.map((file, i) => (
1116
- <FilePreviewTile
1117
- key={`${file.name}-${file.size}-${file.lastModified}`}
1118
- file={file}
1119
- onRemove={() => removeFile(i)}
1120
- size={filePreviewSize}
1121
- />
1122
- ))}
1123
- </AnimatePresence>
1124
- </div>
1125
- </motion.div>
382
+ {...props}
383
+ >
384
+ <SurfaceProvider value={2}>
385
+ {attachments.supported && (
386
+ <input {...attachments.inputProps} className="hidden" aria-hidden="true" tabIndex={-1} />
1126
387
  )}
1127
- </AnimatePresence>
1128
388
 
1129
- {/* Queued messages — reorderable rows above the textarea. The outer
1130
- motion.div collapses the region height when the queue empties;
1131
- the Reorder.Group handles drag-reorder (top = next to dispatch)
1132
- and AnimatePresence handles per-row enter/exit. */}
1133
- {supportsQueue && showQueue && (
389
+ {/* popLayout pulls a leaving tile out of flow so its siblings slide in;
390
+ keys are file identity, so removing one never remounts the rest. */}
1134
391
  <AnimatePresence initial={false}>
1135
- {queueArr.length > 0 && (
392
+ {attachments.files.length > 0 && (
1136
393
  <motion.div
1137
- key="queue-row"
394
+ key="preview-row"
1138
395
  initial={{ height: 0, opacity: 0 }}
1139
- animate={{ height: queueRegionHeight ?? 0, opacity: 1 }}
396
+ animate={{ height: filesRegionHeight ?? 0, opacity: 1 }}
1140
397
  exit={{ height: 0, opacity: 0 }}
1141
- transition={{ ...spring.moderate, bounce: 0 }}
398
+ transition={REGION_SPRING}
1142
399
  className="overflow-hidden"
1143
400
  >
1144
- <Reorder.Group
1145
- ref={queueRegionRef}
1146
- axis="y"
1147
- values={queueArr}
1148
- onReorder={(next: QueuedMessage[]) => setQueue(next)}
1149
- data-im-queue
1150
- className="flex flex-col gap-1 pb-1"
1151
- >
1152
- <AnimatePresence initial={false}>
1153
- {queueArr.map((item, i) => (
1154
- <QueuedRow
1155
- key={item.id}
1156
- item={item}
1157
- index={i}
1158
- total={queueArr.length}
1159
- reduceMotion={reduceMotion}
1160
- isTouch={isTouch}
1161
- onEdit={editQueued}
1162
- onRemove={removeQueued}
1163
- onMove={moveQueued}
401
+ <div ref={filesRegionRef} className="flex flex-wrap gap-2 pb-1">
402
+ <AnimatePresence initial={false} mode="popLayout">
403
+ {attachments.files.map((file, i) => (
404
+ <FilePreviewTile
405
+ key={`${file.name}-${file.size}-${file.lastModified}`}
406
+ file={file}
407
+ onRemove={() => attachments.remove(i)}
408
+ size={filePreviewSize}
1164
409
  />
1165
410
  ))}
1166
411
  </AnimatePresence>
1167
- </Reorder.Group>
412
+ </div>
1168
413
  </motion.div>
1169
414
  )}
1170
415
  </AnimatePresence>
1171
- )}
1172
416
 
1173
- <div className="relative">
1174
- <textarea
1175
- ref={textareaRef}
1176
- value={value}
1177
- onChange={e => {
1178
- // Real typing exits history mode (recall sets the value
1179
- // programmatically, which doesn't fire onChange) and drops
1180
- // any suggestion highlight.
1181
- setHistoryIndex(null)
1182
- setActiveSuggestion(null)
1183
- setValue(e.target.value)
1184
- }}
1185
- onKeyDown={handleKeyDown}
1186
- // Compose the consumer's textareaProps handlers with the internal
1187
- // focus-visible tracking (the spread below would otherwise
1188
- // overwrite these).
1189
- onFocus={e => {
1190
- if (e.target.matches(':focus-visible')) setFocusVisible(true)
1191
- textareaProps?.onFocus?.(e)
1192
- }}
1193
- onBlur={e => {
1194
- setFocusVisible(false)
1195
- setActiveSuggestion(null)
1196
- textareaProps?.onBlur?.(e)
1197
- }}
1198
- placeholder={
1199
- dragOver && supportsFiles
1200
- ? 'Drop files here to add to chat'
1201
- : placeholderSuggestion
1202
- ? undefined // the ghost overlay below renders it
1203
- : placeholder
1204
- }
1205
- disabled={disabled}
1206
- rows={minRows}
1207
- aria-label={textareaProps?.['aria-label'] ?? 'Message'}
1208
- aria-describedby={
1209
- [showGhost ? ghostHintId : null, textareaDescribedBy].filter(Boolean).join(' ') || undefined
1210
- }
1211
- aria-activedescendant={activeSuggestion != null ? `${suggestionListId}-${activeSuggestion}` : undefined}
1212
- className={cn(
1213
- 'w-full resize-none rounded-none bg-transparent outline-none',
1214
- 'text-foreground placeholder:text-muted-foreground',
1215
- compactStep ? 'text-subtitle-compact leading-4.5 px-1.5 py-1.5' : 'text-subtitle leading-5 px-2 py-2',
1216
- 'weight-normal',
1217
- )}
1218
- {...restTextareaProps}
1219
- />
1220
- {/* Ghost placeholder: the suggested prompt with a Tab keycap. A
1221
- real overlay (not the native placeholder) so the keycap can
1222
- render inline after the text; typography mirrors the textarea
1223
- exactly so it sits where typed text will. */}
1224
- {showGhost && (
1225
- <div
1226
- aria-hidden="true"
417
+ {messages.supported && showQueue && (
418
+ <AnimatePresence initial={false}>
419
+ {messages.queue.length > 0 && (
420
+ <motion.div
421
+ key="queue-row"
422
+ initial={{ height: 0, opacity: 0 }}
423
+ animate={{ height: queueRegionHeight ?? 0, opacity: 1 }}
424
+ exit={{ height: 0, opacity: 0 }}
425
+ transition={REGION_SPRING}
426
+ className="overflow-hidden"
427
+ >
428
+ <Reorder.Group
429
+ ref={queueRegionRef}
430
+ axis="y"
431
+ values={messages.queue}
432
+ onReorder={messages.setQueue}
433
+ data-im-queue
434
+ className="flex flex-col gap-1 pb-1"
435
+ >
436
+ <AnimatePresence initial={false}>
437
+ {messages.queue.map((item, i) => (
438
+ <QueuedRow
439
+ key={item.id}
440
+ item={item}
441
+ index={i}
442
+ total={messages.queue.length}
443
+ reduceMotion={reduceMotion}
444
+ isTouch={isTouch}
445
+ onEdit={editQueued}
446
+ onRemove={messages.remove}
447
+ onMove={messages.move}
448
+ />
449
+ ))}
450
+ </AnimatePresence>
451
+ </Reorder.Group>
452
+ </motion.div>
453
+ )}
454
+ </AnimatePresence>
455
+ )}
456
+
457
+ <div className="relative">
458
+ <textarea
459
+ ref={textareaRef}
460
+ value={value}
461
+ onChange={e => {
462
+ recall.exit()
463
+ setActiveSuggestion(null)
464
+ setValue(e.target.value)
465
+ }}
466
+ onKeyDown={handleKeyDown}
467
+ onBlur={e => {
468
+ setActiveSuggestion(null)
469
+ textareaOnBlur?.(e)
470
+ }}
471
+ placeholder={
472
+ attachments.dragging
473
+ ? 'Drop files here to add to chat'
474
+ : placeholderSuggestion
475
+ ? undefined // the ghost below renders it
476
+ : placeholder
477
+ }
478
+ disabled={disabled}
479
+ rows={minRows}
480
+ aria-label={textareaProps?.['aria-label'] ?? 'Message'}
481
+ aria-describedby={
482
+ [showGhost ? ghostHintId : null, textareaDescribedBy].filter(Boolean).join(' ') || undefined
483
+ }
484
+ aria-activedescendant={activeSuggestion != null ? `${suggestionListId}-${activeSuggestion}` : undefined}
1227
485
  className={cn(
1228
- 'pointer-events-none absolute inset-0 overflow-hidden text-muted-foreground',
1229
- // Mirror the textarea's step typography exactly so the ghost
1230
- // sits where typed text will.
1231
- compactStep ? 'text-subtitle-compact leading-4.5 px-1.5 py-1.5' : 'text-subtitle leading-5 px-2 py-2',
486
+ 'w-full resize-none rounded-none bg-transparent outline-none',
487
+ 'text-foreground placeholder:text-muted-foreground',
488
+ textStep,
1232
489
  'weight-normal',
1233
490
  )}
1234
- >
1235
- {/* One flex line: a suggestion longer than the field truncates
1236
- with an ellipsis instead of wrapping into the clip (the
1237
- overlay is inset-0 over a possibly single-row textarea),
1238
- and the Tab chip never gets cut. */}
1239
- <span className="flex max-w-full items-center gap-1.5">
1240
- <span className="min-w-0 truncate">{placeholderSuggestion}</span>
1241
- <kbd
1242
- className={cn(
1243
- 'inline-flex shrink-0 -translate-y-px items-center rounded-box border border-border bg-background px-1 font-sans text-muted-foreground',
1244
- compactStep ? 'h-4 text-micro-compact' : 'h-[18px] text-micro',
1245
- )}
1246
- >
1247
- Tab
1248
- </kbd>
491
+ {...restTextareaProps}
492
+ />
493
+ {/* An overlay rather than the native placeholder, so the Tab keycap can sit inline. */}
494
+ {showGhost && (
495
+ <div
496
+ aria-hidden="true"
497
+ className={cn(
498
+ 'pointer-events-none absolute inset-0 overflow-hidden text-muted-foreground',
499
+ textStep,
500
+ 'weight-normal',
501
+ )}
502
+ >
503
+ <span className="flex max-w-full items-center gap-1.5">
504
+ <span className="min-w-0 truncate">{placeholderSuggestion}</span>
505
+ <kbd
506
+ className={cn(
507
+ 'inline-flex shrink-0 -translate-y-px items-center rounded-box border border-border bg-background px-1 font-sans text-muted-foreground',
508
+ compactStep ? 'h-4 text-micro-compact' : 'h-[18px] text-micro',
509
+ )}
510
+ >
511
+ Tab
512
+ </kbd>
513
+ </span>
514
+ </div>
515
+ )}
516
+ {showGhost && (
517
+ <span id={ghostHintId} className="sr-only">
518
+ Suggested prompt: {placeholderSuggestion}. Press Tab to fill the composer with it.
1249
519
  </span>
520
+ )}
521
+ </div>
522
+ <div
523
+ className={cn(
524
+ 'flex items-center justify-between',
525
+ // Slot buttons are the consumer's: the compact step scales every one, send included.
526
+ compactStep ? 'gap-1.5 [&_button]:h-6 [&_button.w-7]:w-6 [&_button]:text-caption-compact' : 'gap-2',
527
+ )}
528
+ >
529
+ <div className="flex items-center gap-1.5 min-w-0">{leftContent}</div>
530
+ <div className="flex items-center gap-1.5 shrink-0">
531
+ {rightContent}
532
+ <Button
533
+ type="button"
534
+ variant="primary"
535
+ size="icon-compact"
536
+ onClick={buttonMode === 'stop' ? messages.stop : handleSend}
537
+ disabled={buttonMode === 'stop' ? disabled : !canSend}
538
+ aria-label={buttonLabel}
539
+ >
540
+ <AnimatePresence mode="wait" initial={false}>
541
+ <motion.span
542
+ key={buttonMode === 'stop' ? 'stop' : 'arrow'}
543
+ initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6 }}
544
+ animate={{ opacity: 1, scale: 1 }}
545
+ exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, transition: spring.fast.exit }}
546
+ transition={spring.fast}
547
+ className="flex items-center justify-center leading-none"
548
+ >
549
+ {buttonMode === 'stop' ? (
550
+ <span className="h-3 w-3 rounded-glyph bg-current" />
551
+ ) : (
552
+ // A touch larger than icon-compact's 14px svg.
553
+ <ArrowUpIcon
554
+ size={compactStep ? 15 : 19}
555
+ className={cn('block', compactStep ? '!h-[15px] !w-[15px]' : '!h-[19px] !w-[19px]')}
556
+ />
557
+ )}
558
+ </motion.span>
559
+ </AnimatePresence>
560
+ </Button>
1250
561
  </div>
1251
- )}
1252
- {showGhost && (
1253
- <span id={ghostHintId} className="sr-only">
1254
- Suggested prompt: {placeholderSuggestion}. Press Tab to fill the composer with it.
1255
- </span>
1256
- )}
1257
- </div>
1258
- <div
1259
- className={cn(
1260
- 'flex items-center justify-between',
1261
- // The footer's controls sit one notch below the composer's step:
1262
- // slot content is consumer-authored (usually sm/icon-sm pinned
1263
- // Buttons), so the compact step scales any button in the row —
1264
- // send button included — down to 24px via a scoped override.
1265
- compactStep ? 'gap-1.5 [&_button]:h-6 [&_button.w-7]:w-6 [&_button]:text-caption-compact' : 'gap-2',
1266
- )}
1267
- >
1268
- <div className="flex items-center gap-1.5 min-w-0">{leftContent}</div>
1269
- <div className="flex items-center gap-1.5 shrink-0">
1270
- {rightContent}
1271
- <Button
1272
- type="button"
1273
- variant="primary"
1274
- size="icon-sm"
1275
- onClick={buttonMode === 'stop' ? handleStop : handleSend}
1276
- disabled={buttonMode === 'stop' ? disabled : !canSend}
1277
- aria-label={buttonLabel}
1278
- >
1279
- <AnimatePresence mode="wait" initial={false}>
1280
- <motion.span
1281
- key={buttonMode === 'stop' ? 'stop' : 'arrow'}
1282
- initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6 }}
1283
- animate={{ opacity: 1, scale: 1 }}
1284
- exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, transition: spring.fast.exit }}
1285
- transition={spring.fast}
1286
- className="flex items-center justify-center leading-none"
1287
- >
1288
- {buttonMode === 'stop' ? (
1289
- <span className="h-3 w-3 rounded-glyph bg-current" />
1290
- ) : (
1291
- // Override icon-sm's small 14px svg — the send glyph reads
1292
- // better a touch larger. `size` matches the attribute to
1293
- // the CSS so the svg box stays centered.
1294
- <ArrowUpIcon
1295
- size={compactStep ? 15 : 19}
1296
- className={cn('block', compactStep ? '!h-[15px] !w-[15px]' : '!h-[19px] !w-[19px]')}
1297
- />
1298
- )}
1299
- </motion.span>
1300
- </AnimatePresence>
1301
- </Button>
1302
562
  </div>
1303
- </div>
1304
563
 
1305
- {/* Suggested prompts — a listbox under the action bar, shown while
1306
- the draft is empty. ↓/↑ move the highlight without moving focus
1307
- (the textarea's aria-activedescendant tracks it); Enter or click
1308
- fills the composer. The outer motion.div collapses the region's
1309
- height once typing hides the list; -mx-2 cancels the container
1310
- padding so the divider runs the composer's full width. Pointer
1311
- and keyboard share one bg-hover overlay that springs between
1312
- row rects (fluid-hover, same as Dropdown). */}
1313
- {suggestionsArr.length > 0 && (
1314
- <AnimatePresence initial={false}>
1315
- {suggestionsOpen && (
1316
- <motion.div
1317
- key="suggestions"
1318
- initial={{ height: 0, opacity: 0 }}
1319
- animate={{ height: suggestionsRegionHeight ?? 0, opacity: 1 }}
1320
- // Height-only exit: the region clips shut bottom-up under
1321
- // overflow-hidden, so the divider holds its place until the
1322
- // space actually closes (a simultaneous opacity fade made it
1323
- // vanish mid-collapse, which read as a height glitch).
1324
- exit={{ height: 0 }}
1325
- transition={{ ...spring.moderate, bounce: 0 }}
1326
- // -mt-1 cancels the container's gap-1 above this region and
1327
- // the listbox's mt-2 restores it INSIDE the collapsible
1328
- // area — otherwise that 4px gap sits outside the height
1329
- // animation and snaps away only at unmount.
1330
- className="-mx-2 -mt-1 overflow-hidden"
1331
- >
1332
- <div
1333
- ref={el => {
1334
- suggestionListRef.current = el
1335
- suggestionsRegionRef(el)
1336
- }}
1337
- role="listbox"
1338
- id={suggestionListId}
1339
- aria-label="Suggested prompts"
1340
- onMouseEnter={suggestionHandlers.onMouseEnter}
1341
- onMouseMove={suggestionHandlers.onMouseMove}
1342
- onMouseLeave={suggestionHandlers.onMouseLeave}
1343
- onClick={suggestionHandlers.onClick}
1344
- className="relative mt-2 flex flex-col border-t border-border/60 px-1.5 pt-1.5"
564
+ {suggestionList.length > 0 && (
565
+ <AnimatePresence initial={false}>
566
+ {suggestionsOpen && (
567
+ <motion.div
568
+ key="suggestions"
569
+ initial={{ height: 0, opacity: 0 }}
570
+ animate={{ height: suggestionsRegionHeight ?? 0, opacity: 1 }}
571
+ // Height only: a fade would drop the divider before the space closes.
572
+ exit={{ height: 0 }}
573
+ transition={REGION_SPRING}
574
+ // -mt-1 / mt-2 move the gap inside the collapsing region; -mx-2 runs the divider full width.
575
+ className="-mx-2 -mt-1 overflow-hidden"
1345
576
  >
1346
- {/* Hover / keyboard highlight: one overlay sliding
1347
- between rows instead of per-row backgrounds. */}
1348
- <FluidHoverHighlight hover={suggestionHover} className={shape.bg} />
1349
- {suggestionsArr.map((s, i) => (
1350
- <SuggestionRow
1351
- key={`${s}-${i}`}
1352
- text={s}
1353
- index={i}
1354
- active={i === activeSuggestion}
1355
- keyHint={i === 0 && activeSuggestion == null}
1356
- optionId={`${suggestionListId}-${i}`}
1357
- registerItem={registerSuggestion}
1358
- onSelect={() => acceptSuggestion(s)}
1359
- />
1360
- ))}
1361
- </div>
1362
- </motion.div>
1363
- )}
1364
- </AnimatePresence>
1365
- )}
1366
- {/* Politely announces auto-dispatch of queued messages. */}
1367
- <span className="sr-only" role="status" aria-live="polite">
1368
- {liveMsg}
1369
- </span>
1370
- </SurfaceProvider>
1371
- </div>
577
+ {/* biome-ignore lint/a11y/useKeyWithClickEvents: the textarea drives the list by keyboard (aria-activedescendant). */}
578
+ <div
579
+ ref={el => {
580
+ suggestionListRef.current = el
581
+ suggestionsRegionRef(el)
582
+ }}
583
+ role="listbox"
584
+ id={suggestionListId}
585
+ aria-label="Suggested prompts"
586
+ onMouseEnter={suggestionHandlers.onMouseEnter}
587
+ onMouseMove={suggestionHandlers.onMouseMove}
588
+ onMouseLeave={suggestionHandlers.onMouseLeave}
589
+ onClick={suggestionHandlers.onClick}
590
+ className="relative mt-2 flex flex-col border-t border-border/60 px-1.5 pt-1.5"
591
+ >
592
+ <FluidHoverHighlight hover={suggestionHover} className={shape.bg} />
593
+ {suggestionList.map((s, i) => (
594
+ <SuggestionRow
595
+ key={`${s}-${i}`}
596
+ text={s}
597
+ index={i}
598
+ active={i === activeSuggestion}
599
+ keyHint={i === 0 && activeSuggestion == null}
600
+ optionId={`${suggestionListId}-${i}`}
601
+ registerItem={registerSuggestion}
602
+ onSelect={() => acceptSuggestion(s)}
603
+ />
604
+ ))}
605
+ </div>
606
+ </motion.div>
607
+ )}
608
+ </AnimatePresence>
609
+ )}
610
+ <span className="sr-only" role="status" aria-live="polite">
611
+ {messages.announcement}
612
+ </span>
613
+ </SurfaceProvider>
614
+ </div>
615
+ </SizeScope>
1372
616
  )
1373
-
1374
- // A size prop pins the whole composer — inner buttons, rows and queued
1375
- // messages included — to one ladder step (matches InputGroup).
1376
- return size ? <SizeProvider size={size}>{composer}</SizeProvider> : composer
1377
617
  },
1378
618
  )
1379
619