tempest-react-sdk 0.39.0 → 0.40.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 (475) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  2. package/dist/access/access-control-context.cjs.map +1 -1
  3. package/dist/access/use-can.cjs.map +1 -1
  4. package/dist/app/AppProviders.cjs.map +1 -1
  5. package/dist/app/AppProviders.js.map +1 -1
  6. package/dist/audio/use-audio-recorder.cjs.map +1 -1
  7. package/dist/audio/use-audio.cjs.map +1 -1
  8. package/dist/audio/use-microphone.cjs.map +1 -1
  9. package/dist/auth/create-auth-store.cjs.map +1 -1
  10. package/dist/auth/lazy-with-retry.cjs.map +1 -1
  11. package/dist/auth/passkey.cjs.map +1 -1
  12. package/dist/auth/passkey.js.map +1 -1
  13. package/dist/auth/use-passkey.cjs.map +1 -1
  14. package/dist/br/BrazilMap.cjs +1 -1
  15. package/dist/br/BrazilMap.cjs.map +1 -1
  16. package/dist/br/BrazilMap.js +2 -2
  17. package/dist/br/BrazilMap.js.map +1 -1
  18. package/dist/br/BrazilStateCitySelect.cjs.map +1 -1
  19. package/dist/br/BrazilStateCitySelect.js.map +1 -1
  20. package/dist/br/BrazilStateMap.cjs +1 -1
  21. package/dist/br/BrazilStateMap.cjs.map +1 -1
  22. package/dist/br/BrazilStateMap.js +2 -2
  23. package/dist/br/BrazilStateMap.js.map +1 -1
  24. package/dist/br/MapLegend.cjs.map +1 -1
  25. package/dist/br/MapLegend.js.map +1 -1
  26. package/dist/br/MapMarkers.cjs.map +1 -1
  27. package/dist/br/MapMarkers.js.map +1 -1
  28. package/dist/br/MunicipalitySearch.cjs.map +1 -1
  29. package/dist/br/MunicipalitySearch.js.map +1 -1
  30. package/dist/br/PixQRCode.cjs.map +1 -1
  31. package/dist/br/PixQRCode.js.map +1 -1
  32. package/dist/br/use-map-hover.cjs.map +1 -1
  33. package/dist/br/use-map-zoom.cjs.map +1 -1
  34. package/dist/capture/media-recorder.cjs +1 -1
  35. package/dist/capture/media-recorder.js +2 -2
  36. package/dist/capture/use-barcode-scanner.cjs +1 -1
  37. package/dist/capture/use-barcode-scanner.cjs.map +1 -1
  38. package/dist/capture/use-barcode-scanner.js +2 -2
  39. package/dist/capture/use-barcode-scanner.js.map +1 -1
  40. package/dist/capture/use-screen-capture.cjs.map +1 -1
  41. package/dist/capture/use-speech-recognition.cjs.map +1 -1
  42. package/dist/capture/use-torch.cjs.map +1 -1
  43. package/dist/capture/use-video-recorder.cjs.map +1 -1
  44. package/dist/charts/AreaChart.cjs.map +1 -1
  45. package/dist/charts/AreaChart.js.map +1 -1
  46. package/dist/charts/BarChart.cjs.map +1 -1
  47. package/dist/charts/BarChart.js.map +1 -1
  48. package/dist/charts/LineChart.cjs.map +1 -1
  49. package/dist/charts/LineChart.js.map +1 -1
  50. package/dist/charts/PieChart.cjs.map +1 -1
  51. package/dist/charts/PieChart.js.map +1 -1
  52. package/dist/charts/RadarChart.cjs.map +1 -1
  53. package/dist/charts/RadarChart.js.map +1 -1
  54. package/dist/charts/use-chart-colors.cjs.map +1 -1
  55. package/dist/components/AIChat/AIChat.cjs.map +1 -1
  56. package/dist/components/AIChat/AIChat.js.map +1 -1
  57. package/dist/components/AIChat/AIChatComposer.cjs.map +1 -1
  58. package/dist/components/AIChat/AIChatComposer.js.map +1 -1
  59. package/dist/components/AIChat/AIChatTurn.cjs.map +1 -1
  60. package/dist/components/AIChat/AIChatTurn.js.map +1 -1
  61. package/dist/components/Accordion/Accordion.cjs.map +1 -1
  62. package/dist/components/Accordion/Accordion.js.map +1 -1
  63. package/dist/components/Alert/Alert.cjs.map +1 -1
  64. package/dist/components/Alert/Alert.js.map +1 -1
  65. package/dist/components/AppBar/AppBar.cjs.map +1 -1
  66. package/dist/components/AppBar/AppBar.js.map +1 -1
  67. package/dist/components/AppShell/AppShell.cjs.map +1 -1
  68. package/dist/components/AppShell/AppShell.js.map +1 -1
  69. package/dist/components/AudioPlayer/AudioPlayer.cjs.map +1 -1
  70. package/dist/components/AudioPlayer/AudioPlayer.js.map +1 -1
  71. package/dist/components/AudioRecorder/AudioRecorder.cjs.map +1 -1
  72. package/dist/components/AudioRecorder/AudioRecorder.js.map +1 -1
  73. package/dist/components/Avatar/Avatar.cjs.map +1 -1
  74. package/dist/components/Avatar/Avatar.js.map +1 -1
  75. package/dist/components/AvatarGroup/AvatarGroup.cjs.map +1 -1
  76. package/dist/components/AvatarGroup/AvatarGroup.js.map +1 -1
  77. package/dist/components/Badge/Badge.cjs.map +1 -1
  78. package/dist/components/Badge/Badge.js.map +1 -1
  79. package/dist/components/Banner/Banner.cjs.map +1 -1
  80. package/dist/components/Banner/Banner.js.map +1 -1
  81. package/dist/components/BarcodeScanner/BarcodeScanner.cjs.map +1 -1
  82. package/dist/components/BarcodeScanner/BarcodeScanner.js.map +1 -1
  83. package/dist/components/BottomNavigation/BottomNavigation.cjs.map +1 -1
  84. package/dist/components/BottomNavigation/BottomNavigation.js.map +1 -1
  85. package/dist/components/BottomSheet/BottomSheet.cjs.map +1 -1
  86. package/dist/components/BottomSheet/BottomSheet.js.map +1 -1
  87. package/dist/components/Breadcrumbs/Breadcrumbs.cjs.map +1 -1
  88. package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -1
  89. package/dist/components/Button/Button.cjs.map +1 -1
  90. package/dist/components/Button/Button.js.map +1 -1
  91. package/dist/components/Calendar/Calendar.cjs +1 -1
  92. package/dist/components/Calendar/Calendar.cjs.map +1 -1
  93. package/dist/components/Calendar/Calendar.js +38 -41
  94. package/dist/components/Calendar/Calendar.js.map +1 -1
  95. package/dist/components/Card/Card.cjs.map +1 -1
  96. package/dist/components/Card/Card.js.map +1 -1
  97. package/dist/components/Carousel/Carousel.cjs.map +1 -1
  98. package/dist/components/Carousel/Carousel.js.map +1 -1
  99. package/dist/components/Chat/Chat.cjs.map +1 -1
  100. package/dist/components/Chat/Chat.js.map +1 -1
  101. package/dist/components/Chat/ChatComposer.cjs.map +1 -1
  102. package/dist/components/Chat/ChatComposer.js.map +1 -1
  103. package/dist/components/Chat/chat-groups.cjs +1 -1
  104. package/dist/components/Chat/chat-groups.cjs.map +1 -1
  105. package/dist/components/Chat/chat-groups.js +2 -2
  106. package/dist/components/Chat/chat-groups.js.map +1 -1
  107. package/dist/components/Checkbox/Checkbox.cjs.map +1 -1
  108. package/dist/components/Checkbox/Checkbox.js.map +1 -1
  109. package/dist/components/ChipInput/ChipInput.cjs.map +1 -1
  110. package/dist/components/ChipInput/ChipInput.js.map +1 -1
  111. package/dist/components/ClickOutside/ClickOutside.cjs.map +1 -1
  112. package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -1
  113. package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
  114. package/dist/components/Collapsible/Collapsible.cjs.map +1 -1
  115. package/dist/components/Collapsible/Collapsible.js.map +1 -1
  116. package/dist/components/Combobox/Combobox.cjs.map +1 -1
  117. package/dist/components/Combobox/Combobox.js.map +1 -1
  118. package/dist/components/Command/Command.cjs.map +1 -1
  119. package/dist/components/Command/Command.js.map +1 -1
  120. package/dist/components/ConfirmDialog/ConfirmDialog.cjs.map +1 -1
  121. package/dist/components/ConfirmDialog/ConfirmDialog.js.map +1 -1
  122. package/dist/components/ContextMenu/ContextMenu.cjs.map +1 -1
  123. package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
  124. package/dist/components/CopyButton/CopyButton.cjs.map +1 -1
  125. package/dist/components/CopyButton/CopyButton.js.map +1 -1
  126. package/dist/components/DataList/DataList.cjs.map +1 -1
  127. package/dist/components/DataList/DataList.js.map +1 -1
  128. package/dist/components/DataTable/DataTable.cjs +1 -1
  129. package/dist/components/DataTable/DataTable.cjs.map +1 -1
  130. package/dist/components/DataTable/DataTable.js +2 -2
  131. package/dist/components/DataTable/DataTable.js.map +1 -1
  132. package/dist/components/DataTable/EditableCell.cjs.map +1 -1
  133. package/dist/components/DataTable/EditableCell.js.map +1 -1
  134. package/dist/components/DatePicker/DatePicker.cjs.map +1 -1
  135. package/dist/components/DateRangePicker/DateRangePicker.cjs.map +1 -1
  136. package/dist/components/DateRangePicker/DateRangePicker.js.map +1 -1
  137. package/dist/components/DescriptionList/DescriptionList.cjs.map +1 -1
  138. package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
  139. package/dist/components/Divider/Divider.cjs.map +1 -1
  140. package/dist/components/Divider/Divider.js.map +1 -1
  141. package/dist/components/Drawer/Drawer.cjs.map +1 -1
  142. package/dist/components/Drawer/Drawer.js.map +1 -1
  143. package/dist/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
  144. package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
  145. package/dist/components/Dropzone/Dropzone.cjs.map +1 -1
  146. package/dist/components/Dropzone/Dropzone.js.map +1 -1
  147. package/dist/components/EmptyState/EmptyState.cjs.map +1 -1
  148. package/dist/components/EmptyState/EmptyState.js.map +1 -1
  149. package/dist/components/ErrorState/ErrorState.cjs.map +1 -1
  150. package/dist/components/ErrorState/ErrorState.js.map +1 -1
  151. package/dist/components/FileUpload/FileUpload.cjs +1 -1
  152. package/dist/components/FileUpload/FileUpload.cjs.map +1 -1
  153. package/dist/components/FileUpload/FileUpload.js +1 -1
  154. package/dist/components/FileUpload/FileUpload.js.map +1 -1
  155. package/dist/components/FilterBar/FilterBar.cjs.map +1 -1
  156. package/dist/components/FilterBar/FilterBar.js.map +1 -1
  157. package/dist/components/FloatingActionButton/FloatingActionButton.cjs.map +1 -1
  158. package/dist/components/FloatingActionButton/FloatingActionButton.js.map +1 -1
  159. package/dist/components/Form/Form.cjs.map +1 -1
  160. package/dist/components/Form/Form.js.map +1 -1
  161. package/dist/components/HoverCard/HoverCard.cjs.map +1 -1
  162. package/dist/components/HoverCard/HoverCard.js.map +1 -1
  163. package/dist/components/Image/Image.cjs.map +1 -1
  164. package/dist/components/ImageCropper/ImageCropper.cjs +1 -1
  165. package/dist/components/ImageCropper/ImageCropper.cjs.map +1 -1
  166. package/dist/components/ImageCropper/ImageCropper.js +1 -1
  167. package/dist/components/ImageCropper/ImageCropper.js.map +1 -1
  168. package/dist/components/Input/Input.cjs.map +1 -1
  169. package/dist/components/Input/Input.js.map +1 -1
  170. package/dist/components/InstallBanner/InstallBanner.cjs.map +1 -1
  171. package/dist/components/InstallBanner/InstallBanner.js.map +1 -1
  172. package/dist/components/InstallButton/InstallButton.cjs.map +1 -1
  173. package/dist/components/InstallButton/InstallButton.js.map +1 -1
  174. package/dist/components/Kanban/Kanban.cjs.map +1 -1
  175. package/dist/components/Kanban/Kanban.js.map +1 -1
  176. package/dist/components/Label/Label.cjs.map +1 -1
  177. package/dist/components/Label/Label.js.map +1 -1
  178. package/dist/components/Lightbox/Lightbox.cjs.map +1 -1
  179. package/dist/components/Lightbox/Lightbox.js.map +1 -1
  180. package/dist/components/ListTile/ListTile.cjs.map +1 -1
  181. package/dist/components/ListTile/ListTile.js.map +1 -1
  182. package/dist/components/Markdown/Markdown.cjs +1 -1
  183. package/dist/components/Markdown/Markdown.cjs.map +1 -1
  184. package/dist/components/Markdown/Markdown.js +2 -2
  185. package/dist/components/Markdown/Markdown.js.map +1 -1
  186. package/dist/components/Masonry/Masonry.cjs.map +1 -1
  187. package/dist/components/Masonry/Masonry.js.map +1 -1
  188. package/dist/components/Menubar/Menubar.cjs.map +1 -1
  189. package/dist/components/Menubar/Menubar.js.map +1 -1
  190. package/dist/components/Modal/Modal.cjs.map +1 -1
  191. package/dist/components/Modal/Modal.js.map +1 -1
  192. package/dist/components/ModalsManager/ModalsManager.cjs.map +1 -1
  193. package/dist/components/ModalsManager/ModalsManager.js.map +1 -1
  194. package/dist/components/Money/Money.cjs.map +1 -1
  195. package/dist/components/Money/Money.js.map +1 -1
  196. package/dist/components/MultiSelect/MultiSelect.cjs.map +1 -1
  197. package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
  198. package/dist/components/NProgress/NProgress.cjs.map +1 -1
  199. package/dist/components/Navbar/Navbar.cjs.map +1 -1
  200. package/dist/components/Navbar/Navbar.js.map +1 -1
  201. package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
  202. package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
  203. package/dist/components/NavigationRail/NavigationRail.cjs.map +1 -1
  204. package/dist/components/NavigationRail/NavigationRail.js.map +1 -1
  205. package/dist/components/NotificationCenter/NotificationCenter.cjs.map +1 -1
  206. package/dist/components/NotificationCenter/NotificationCenter.js.map +1 -1
  207. package/dist/components/NotificationCenter/use-notification-inbox.cjs.map +1 -1
  208. package/dist/components/OfflineIndicator/OfflineIndicator.cjs.map +1 -1
  209. package/dist/components/OfflineIndicator/OfflineIndicator.js.map +1 -1
  210. package/dist/components/Page/Page.cjs.map +1 -1
  211. package/dist/components/Page/Page.js.map +1 -1
  212. package/dist/components/Pagination/Pagination.cjs.map +1 -1
  213. package/dist/components/Pagination/Pagination.js.map +1 -1
  214. package/dist/components/PasswordInput/PasswordInput.cjs.map +1 -1
  215. package/dist/components/PasswordInput/PasswordInput.js.map +1 -1
  216. package/dist/components/PinInput/PinInput.cjs.map +1 -1
  217. package/dist/components/PinInput/PinInput.js.map +1 -1
  218. package/dist/components/Popover/Popover.cjs.map +1 -1
  219. package/dist/components/Popover/Popover.js.map +1 -1
  220. package/dist/components/Portal/Portal.cjs.map +1 -1
  221. package/dist/components/Progress/Progress.cjs.map +1 -1
  222. package/dist/components/Progress/Progress.js.map +1 -1
  223. package/dist/components/QRCode/QRCode.cjs.map +1 -1
  224. package/dist/components/QRCode/QRCode.js.map +1 -1
  225. package/dist/components/Radio/Radio.cjs.map +1 -1
  226. package/dist/components/Radio/Radio.js.map +1 -1
  227. package/dist/components/RangeSlider/RangeSlider.cjs.map +1 -1
  228. package/dist/components/RangeSlider/RangeSlider.js.map +1 -1
  229. package/dist/components/RatingStars/RatingStars.cjs.map +1 -1
  230. package/dist/components/RatingStars/RatingStars.js.map +1 -1
  231. package/dist/components/RefreshIndicator/RefreshIndicator.cjs.map +1 -1
  232. package/dist/components/RefreshIndicator/RefreshIndicator.js.map +1 -1
  233. package/dist/components/RelativeTime/RelativeTime.cjs.map +1 -1
  234. package/dist/components/RelativeTime/RelativeTime.js.map +1 -1
  235. package/dist/components/Resizable/Resizable.cjs.map +1 -1
  236. package/dist/components/Resizable/Resizable.js.map +1 -1
  237. package/dist/components/Scheduler/Scheduler.cjs.map +1 -1
  238. package/dist/components/Scheduler/Scheduler.js.map +1 -1
  239. package/dist/components/ScrollArea/ScrollArea.cjs.map +1 -1
  240. package/dist/components/SearchBar/SearchBar.cjs.map +1 -1
  241. package/dist/components/SearchBar/SearchBar.js.map +1 -1
  242. package/dist/components/SegmentedControl/SegmentedControl.cjs.map +1 -1
  243. package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
  244. package/dist/components/Select/Select.cjs.map +1 -1
  245. package/dist/components/Select/Select.js.map +1 -1
  246. package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
  247. package/dist/components/Sidebar/Sidebar.js.map +1 -1
  248. package/dist/components/SignaturePad/SignaturePad.cjs.map +1 -1
  249. package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
  250. package/dist/components/Slider/Slider.cjs.map +1 -1
  251. package/dist/components/Slider/Slider.js.map +1 -1
  252. package/dist/components/Sparkline/Sparkline.cjs.map +1 -1
  253. package/dist/components/Sparkline/Sparkline.js.map +1 -1
  254. package/dist/components/Spinner/Spinner.cjs.map +1 -1
  255. package/dist/components/Spinner/Spinner.js.map +1 -1
  256. package/dist/components/Stat/Stat.cjs.map +1 -1
  257. package/dist/components/Stat/Stat.js.map +1 -1
  258. package/dist/components/Stepper/Stepper.cjs.map +1 -1
  259. package/dist/components/Stepper/Stepper.js.map +1 -1
  260. package/dist/components/StepperInput/StepperInput.cjs.map +1 -1
  261. package/dist/components/StepperInput/StepperInput.js.map +1 -1
  262. package/dist/components/Switch/Switch.cjs.map +1 -1
  263. package/dist/components/Switch/Switch.js.map +1 -1
  264. package/dist/components/SyncStatusBadge/SyncStatusBadge.cjs.map +1 -1
  265. package/dist/components/SyncStatusBadge/SyncStatusBadge.js.map +1 -1
  266. package/dist/components/Table/Table.cjs.map +1 -1
  267. package/dist/components/Table/Table.js.map +1 -1
  268. package/dist/components/Tabs/Tabs.cjs.map +1 -1
  269. package/dist/components/Tabs/Tabs.js.map +1 -1
  270. package/dist/components/Tag/Tag.cjs.map +1 -1
  271. package/dist/components/Tag/Tag.js.map +1 -1
  272. package/dist/components/Textarea/Textarea.cjs.map +1 -1
  273. package/dist/components/Textarea/Textarea.js.map +1 -1
  274. package/dist/components/TimePicker/TimePicker.cjs.map +1 -1
  275. package/dist/components/TimePicker/TimePicker.js.map +1 -1
  276. package/dist/components/Timeline/Timeline.cjs.map +1 -1
  277. package/dist/components/Timeline/Timeline.js.map +1 -1
  278. package/dist/components/Toast/ToastProvider.cjs.map +1 -1
  279. package/dist/components/Toast/ToastProvider.js.map +1 -1
  280. package/dist/components/Toggle/Toggle.cjs.map +1 -1
  281. package/dist/components/ToggleGroup/ToggleGroup.cjs.map +1 -1
  282. package/dist/components/ToggleGroup/ToggleGroup.js.map +1 -1
  283. package/dist/components/Tooltip/Tooltip.cjs.map +1 -1
  284. package/dist/components/Tooltip/Tooltip.js.map +1 -1
  285. package/dist/components/Tour/Tour.cjs.map +1 -1
  286. package/dist/components/Tour/Tour.js.map +1 -1
  287. package/dist/components/Transfer/Transfer.cjs.map +1 -1
  288. package/dist/components/Transfer/Transfer.js.map +1 -1
  289. package/dist/components/TreeView/TreeView.cjs +1 -1
  290. package/dist/components/TreeView/TreeView.cjs.map +1 -1
  291. package/dist/components/TreeView/TreeView.js +1 -4
  292. package/dist/components/TreeView/TreeView.js.map +1 -1
  293. package/dist/components/UpdatePrompt/UpdatePrompt.cjs.map +1 -1
  294. package/dist/components/UpdatePrompt/UpdatePrompt.js.map +1 -1
  295. package/dist/components/VirtualList/VirtualList.cjs.map +1 -1
  296. package/dist/components/VirtualList/VirtualList.js.map +1 -1
  297. package/dist/components/VirtualTable/VirtualTable.cjs.map +1 -1
  298. package/dist/components/VirtualTable/VirtualTable.js.map +1 -1
  299. package/dist/components/VisuallyHidden/VisuallyHidden.cjs.map +1 -1
  300. package/dist/components/Wizard/Wizard.cjs.map +1 -1
  301. package/dist/components/Wizard/Wizard.js.map +1 -1
  302. package/dist/data/data-provider-context.cjs.map +1 -1
  303. package/dist/data/use-resource.cjs.map +1 -1
  304. package/dist/editor/RichTextEditor.cjs.map +1 -1
  305. package/dist/editor/RichTextEditor.js.map +1 -1
  306. package/dist/error-boundary/use-error-handler.cjs.map +1 -1
  307. package/dist/feature-flags/FeatureFlagsProvider.cjs.map +1 -1
  308. package/dist/forms/FormField.cjs.map +1 -1
  309. package/dist/forms/masked-inputs.cjs +1 -1
  310. package/dist/forms/masked-inputs.cjs.map +1 -1
  311. package/dist/forms/masked-inputs.js +1 -1
  312. package/dist/forms/masked-inputs.js.map +1 -1
  313. package/dist/forms/use-viacep.cjs.map +1 -1
  314. package/dist/forms/use-zod-form.cjs.map +1 -1
  315. package/dist/forms/zod-resolver.cjs.map +1 -1
  316. package/dist/forms/zod-resolver.js.map +1 -1
  317. package/dist/geo/TrajectoryMap.cjs.map +1 -1
  318. package/dist/geo/TrajectoryMap.js.map +1 -1
  319. package/dist/geo/leaflet-map.cjs.map +1 -1
  320. package/dist/geo/leaflet-map.js.map +1 -1
  321. package/dist/geo/use-position-tracker.cjs.map +1 -1
  322. package/dist/hooks/use-announce.cjs.map +1 -1
  323. package/dist/hooks/use-async.cjs.map +1 -1
  324. package/dist/hooks/use-before-install-prompt.cjs.map +1 -1
  325. package/dist/hooks/use-breakpoint.cjs.map +1 -1
  326. package/dist/hooks/use-click-outside.cjs.map +1 -1
  327. package/dist/hooks/use-client-filter.cjs.map +1 -1
  328. package/dist/hooks/use-clipboard.cjs.map +1 -1
  329. package/dist/hooks/use-counter.cjs.map +1 -1
  330. package/dist/hooks/use-debounce.cjs.map +1 -1
  331. package/dist/hooks/use-deep-memo.cjs.map +1 -1
  332. package/dist/hooks/use-disclosure.cjs.map +1 -1
  333. package/dist/hooks/use-document-visibility.cjs.map +1 -1
  334. package/dist/hooks/use-event-listener.cjs.map +1 -1
  335. package/dist/hooks/use-geolocation.cjs.map +1 -1
  336. package/dist/hooks/use-hover.cjs.map +1 -1
  337. package/dist/hooks/use-idle.cjs.map +1 -1
  338. package/dist/hooks/use-install-prompt.cjs +1 -1
  339. package/dist/hooks/use-install-prompt.cjs.map +1 -1
  340. package/dist/hooks/use-install-prompt.js +1 -1
  341. package/dist/hooks/use-install-prompt.js.map +1 -1
  342. package/dist/hooks/use-intersection-observer.cjs.map +1 -1
  343. package/dist/hooks/use-interval.cjs.map +1 -1
  344. package/dist/hooks/use-is-first-render.cjs.map +1 -1
  345. package/dist/hooks/use-keyboard-shortcut.cjs +1 -1
  346. package/dist/hooks/use-keyboard-shortcut.cjs.map +1 -1
  347. package/dist/hooks/use-keyboard-shortcut.js +1 -1
  348. package/dist/hooks/use-keyboard-shortcut.js.map +1 -1
  349. package/dist/hooks/use-list-state.cjs.map +1 -1
  350. package/dist/hooks/use-local-storage.cjs.map +1 -1
  351. package/dist/hooks/use-long-press-handlers.cjs.map +1 -1
  352. package/dist/hooks/use-long-press.cjs.map +1 -1
  353. package/dist/hooks/use-map.cjs.map +1 -1
  354. package/dist/hooks/use-media-devices.cjs.map +1 -1
  355. package/dist/hooks/use-media-permission.cjs.map +1 -1
  356. package/dist/hooks/use-media-query.cjs.map +1 -1
  357. package/dist/hooks/use-object-url.cjs.map +1 -1
  358. package/dist/hooks/use-online.cjs.map +1 -1
  359. package/dist/hooks/use-pagination.cjs.map +1 -1
  360. package/dist/hooks/use-previous.cjs.map +1 -1
  361. package/dist/hooks/use-queue.cjs.map +1 -1
  362. package/dist/hooks/use-resize-observer.cjs.map +1 -1
  363. package/dist/hooks/use-scroll-overflow.cjs.map +1 -1
  364. package/dist/hooks/use-service-worker-update.cjs.map +1 -1
  365. package/dist/hooks/use-set.cjs.map +1 -1
  366. package/dist/hooks/use-sortable.cjs +1 -1
  367. package/dist/hooks/use-sortable.cjs.map +1 -1
  368. package/dist/hooks/use-sortable.js +0 -2
  369. package/dist/hooks/use-sortable.js.map +1 -1
  370. package/dist/hooks/use-stable-callback.cjs.map +1 -1
  371. package/dist/hooks/use-storage-estimate.cjs.map +1 -1
  372. package/dist/hooks/use-throttle.cjs.map +1 -1
  373. package/dist/hooks/use-timeout.cjs.map +1 -1
  374. package/dist/hooks/use-toggle.cjs.map +1 -1
  375. package/dist/hooks/use-window-size.cjs.map +1 -1
  376. package/dist/http/api-client.cjs +1 -1
  377. package/dist/http/api-client.cjs.map +1 -1
  378. package/dist/http/api-client.js +7 -5
  379. package/dist/http/api-client.js.map +1 -1
  380. package/dist/http/resumable-upload.cjs +1 -1
  381. package/dist/http/resumable-upload.cjs.map +1 -1
  382. package/dist/http/resumable-upload.js +1 -1
  383. package/dist/http/resumable-upload.js.map +1 -1
  384. package/dist/http/use-poll.cjs.map +1 -1
  385. package/dist/i18n/I18nProvider.cjs.map +1 -1
  386. package/dist/icons/Icon.cjs.map +1 -1
  387. package/dist/icons/IconProvider.cjs.map +1 -1
  388. package/dist/icons/icon-context.cjs.map +1 -1
  389. package/dist/icons/use-icon.cjs.map +1 -1
  390. package/dist/imaging/use-image-processing.cjs.map +1 -1
  391. package/dist/oauth/GoogleSignIn.cjs.map +1 -1
  392. package/dist/oauth/GoogleSignIn.js.map +1 -1
  393. package/dist/oauth/use-oauth-callback.cjs.map +1 -1
  394. package/dist/offline/use-offline-sync.cjs.map +1 -1
  395. package/dist/push/use-push-subscription.cjs.map +1 -1
  396. package/dist/query/QueryProvider.cjs.map +1 -1
  397. package/dist/query/constants.cjs +1 -1
  398. package/dist/query/constants.cjs.map +1 -1
  399. package/dist/query/constants.js +10 -10
  400. package/dist/query/constants.js.map +1 -1
  401. package/dist/query/create-query-keys.cjs +1 -1
  402. package/dist/query/create-query-keys.cjs.map +1 -1
  403. package/dist/query/create-query-keys.js +1 -1
  404. package/dist/query/create-query-keys.js.map +1 -1
  405. package/dist/query/offline-persistence.cjs.map +1 -1
  406. package/dist/query/use-cursor-query.cjs.map +1 -1
  407. package/dist/query/use-offline-mutation.cjs.map +1 -1
  408. package/dist/query/use-paginated-query.cjs.map +1 -1
  409. package/dist/router/AppRouter.cjs +1 -1
  410. package/dist/router/AppRouter.cjs.map +1 -1
  411. package/dist/router/AppRouter.js +7 -2
  412. package/dist/router/AppRouter.js.map +1 -1
  413. package/dist/sse/use-event-stream.cjs.map +1 -1
  414. package/dist/store/create-store.cjs.map +1 -1
  415. package/dist/tabular/use-tabular-predictor.cjs.map +1 -1
  416. package/dist/telemetry/TelemetryProvider.cjs.map +1 -1
  417. package/dist/tempest-react-sdk.d.ts +25 -26
  418. package/dist/theme/ThemeProvider.cjs.map +1 -1
  419. package/dist/theme/color.cjs +1 -1
  420. package/dist/theme/color.cjs.map +1 -1
  421. package/dist/theme/color.js +1 -1
  422. package/dist/theme/color.js.map +1 -1
  423. package/dist/utils/cn.cjs +1 -1
  424. package/dist/utils/cn.cjs.map +1 -1
  425. package/dist/utils/cn.js +1 -1
  426. package/dist/utils/cn.js.map +1 -1
  427. package/dist/utils/objects.cjs +1 -1
  428. package/dist/utils/objects.cjs.map +1 -1
  429. package/dist/utils/objects.js +1 -1
  430. package/dist/utils/objects.js.map +1 -1
  431. package/dist/utils/xlsx.cjs +1 -1
  432. package/dist/utils/xlsx.cjs.map +1 -1
  433. package/dist/utils/xlsx.js +3 -3
  434. package/dist/utils/xlsx.js.map +1 -1
  435. package/dist/vision/core/exceptions.cjs.map +1 -1
  436. package/dist/vision/core/exceptions.js.map +1 -1
  437. package/dist/vision/core/metadata.cjs +1 -1
  438. package/dist/vision/core/metadata.cjs.map +1 -1
  439. package/dist/vision/core/metadata.js +1 -1
  440. package/dist/vision/core/metadata.js.map +1 -1
  441. package/dist/vision/io/image.cjs +1 -1
  442. package/dist/vision/io/image.cjs.map +1 -1
  443. package/dist/vision/io/image.js +4 -2
  444. package/dist/vision/io/image.js.map +1 -1
  445. package/dist/vision/preprocess/image.cjs +1 -1
  446. package/dist/vision/preprocess/image.cjs.map +1 -1
  447. package/dist/vision/preprocess/image.js +4 -2
  448. package/dist/vision/preprocess/image.js.map +1 -1
  449. package/dist/vision/tasks/base.cjs +1 -1
  450. package/dist/vision/tasks/base.cjs.map +1 -1
  451. package/dist/vision/tasks/base.js +3 -1
  452. package/dist/vision/tasks/base.js.map +1 -1
  453. package/dist/vision/tasks/classifier.cjs +1 -1
  454. package/dist/vision/tasks/classifier.cjs.map +1 -1
  455. package/dist/vision/tasks/classifier.js +2 -2
  456. package/dist/vision/tasks/classifier.js.map +1 -1
  457. package/dist/vision/tasks/detectClassify.cjs +1 -1
  458. package/dist/vision/tasks/detectClassify.cjs.map +1 -1
  459. package/dist/vision/tasks/detectClassify.js +16 -15
  460. package/dist/vision/tasks/detectClassify.js.map +1 -1
  461. package/dist/vision/use-camera-stream.cjs.map +1 -1
  462. package/dist/vision/use-live-luminance.cjs.map +1 -1
  463. package/dist/vite/create-vite-config.cjs +1 -1
  464. package/dist/vite/create-vite-config.cjs.map +1 -1
  465. package/dist/vite/create-vite-config.js +3 -3
  466. package/dist/vite/create-vite-config.js.map +1 -1
  467. package/dist/vite/tempest-icons.cjs.map +1 -1
  468. package/dist/vite/tempest-pwa-dev-sw.cjs.map +1 -1
  469. package/dist/vite/tempest-pwa-icons.cjs.map +1 -1
  470. package/dist/ws/use-web-socket.cjs +1 -1
  471. package/dist/ws/use-web-socket.cjs.map +1 -1
  472. package/dist/ws/use-web-socket.js +5 -3
  473. package/dist/ws/use-web-socket.js.map +1 -1
  474. package/package.json +2 -2
  475. package/template/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"TreeView.js","names":[],"sources":["../../../src/components/TreeView/TreeView.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — expansion and selection\n * are two independent controlled states, each with its uncontrolled twin\n * (expandedIds/defaultExpandedIds/onExpandedChange, selectedId/\n * defaultSelectedId/onSelect), plus toggleOnSelect for the case where they should\n * move together. The body is the flattened visible list and the roving focus over\n * it.\n */\nimport { ChevronRight } from \"lucide-react\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./TreeView.module.css\";\n\n/** One node of the tree. Children make it a branch; no children makes it a leaf. */\nexport interface TreeNode {\n /** Stable identifier, unique across the whole tree. */\n id: string;\n /** Rendered label. */\n label: ReactNode;\n /** Child nodes. An empty array still renders as a branch (an empty folder). */\n children?: TreeNode[];\n /** Icon rendered before the label. */\n icon?: ReactNode;\n /** Blocks selection and expansion, and skips the node in keyboard navigation. */\n disabled?: boolean;\n}\n\nexport interface TreeViewProps {\n /** Root nodes. */\n nodes: TreeNode[];\n /** Controlled expanded ids. */\n expandedIds?: string[];\n /** Uncontrolled initial expanded ids. */\n defaultExpandedIds?: string[];\n onExpandedChange?: (expandedIds: string[]) => void;\n /** Controlled selected id. `null` means nothing selected. */\n selectedId?: string | null;\n /** Uncontrolled initial selection. */\n defaultSelectedId?: string | null;\n onSelect?: (node: TreeNode) => void;\n /**\n * Selecting a branch also toggles it. Default `true` — matches how a file\n * explorer behaves; set `false` when a branch is itself a meaningful choice\n * (a category that owns items, for instance).\n */\n toggleOnSelect?: boolean;\n /** Accessible name for the tree. */\n label?: string;\n className?: string;\n}\n\ninterface FlatNode {\n node: TreeNode;\n depth: number;\n parentId: string | null;\n hasChildren: boolean;\n expanded: boolean;\n}\n\n/**\n * Walk the tree into the list of *currently visible* rows.\n *\n * Keyboard navigation works on this flattened view, which is what makes\n * ArrowDown from the last child of a collapsed-sibling branch land on the right\n * row: rows that are not rendered simply are not in the list.\n */\nfunction flatten(\n nodes: TreeNode[],\n expandedIds: Set<string>,\n depth = 0,\n parentId: string | null = null,\n out: FlatNode[] = [],\n): FlatNode[] {\n for (const node of nodes) {\n const hasChildren = Array.isArray(node.children);\n const expanded = hasChildren && expandedIds.has(node.id);\n out.push({ node, depth, parentId, hasChildren, expanded });\n if (expanded && node.children) {\n flatten(node.children, expandedIds, depth + 1, node.id, out);\n }\n }\n return out;\n}\n\n/**\n * Accessible tree for hierarchical data — categories, permissions, folders, an\n * org chart.\n *\n * Implements the `tree` role with **roving tabindex**: exactly one row is\n * tabbable, and the arrow keys move focus within the widget. That is what keeps a\n * 500-node tree from adding 500 stops to the page's tab order.\n *\n * Keyboard map: `↓`/`↑` move, `→` expands (or descends), `←` collapses (or goes to\n * the parent), `Home`/`End` jump to the first/last visible row, `Enter`/`Space`\n * select.\n *\n * The chevron is decoration (`aria-hidden`), not a button: the row itself carries\n * `aria-expanded`, so a second focusable control there would only add noise for a\n * screen reader while duplicating an action the keyboard map already has. It still\n * accepts a click, with the event stopped so it toggles without also selecting.\n *\n * @example\n * ```tsx\n * const nodes: TreeNode[] = [\n * {\n * id: \"vendas\",\n * label: \"Vendas\",\n * children: [\n * { id: \"vendas.ler\", label: \"Ler\" },\n * { id: \"vendas.editar\", label: \"Editar\" },\n * ],\n * },\n * { id: \"config\", label: \"Configurações\", children: [] },\n * ];\n *\n * <TreeView nodes={nodes} defaultExpandedIds={[\"vendas\"]} onSelect={(node) => console.log(node.id)} />\n * ```\n */\nexport function TreeView({\n nodes,\n expandedIds,\n defaultExpandedIds = [],\n onExpandedChange,\n selectedId,\n defaultSelectedId = null,\n onSelect,\n toggleOnSelect = true,\n label,\n className,\n}: TreeViewProps) {\n const expandedControlled = expandedIds !== undefined;\n const [internalExpanded, setInternalExpanded] = useState<string[]>(defaultExpandedIds);\n const expanded = expandedControlled ? expandedIds : internalExpanded;\n\n const selectionControlled = selectedId !== undefined;\n const [internalSelected, setInternalSelected] = useState<string | null>(defaultSelectedId);\n const selected = selectionControlled ? selectedId : internalSelected;\n\n const expandedSet = useMemo(() => new Set(expanded), [expanded]);\n const rows = useMemo(() => flatten(nodes, expandedSet), [nodes, expandedSet]);\n\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const containerRef = useRef<HTMLUListElement>(null);\n\n const activeId =\n focusedId ?? selected ?? rows.find((row) => !row.node.disabled)?.node.id ?? null;\n\n const setExpanded = useCallback(\n (next: string[]): void => {\n if (!expandedControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [expandedControlled, onExpandedChange],\n );\n\n const toggle = useCallback(\n (id: string): void => {\n setExpanded(\n expanded.includes(id) ? expanded.filter((x) => x !== id) : [...expanded, id],\n );\n },\n [expanded, setExpanded],\n );\n\n const select = useCallback(\n (row: FlatNode): void => {\n if (row.node.disabled) return;\n if (!selectionControlled) setInternalSelected(row.node.id);\n setFocusedId(row.node.id);\n onSelect?.(row.node);\n if (row.hasChildren && toggleOnSelect) toggle(row.node.id);\n },\n [onSelect, selectionControlled, toggle, toggleOnSelect],\n );\n\n /** Move DOM focus to a row by id, so the roving tabindex actually roves. */\n const focusRow = useCallback((id: string): void => {\n setFocusedId(id);\n const element = containerRef.current?.querySelector<HTMLElement>(`[data-tree-id=\"${id}\"]`);\n element?.focus();\n }, []);\n\n const moveFocus = useCallback(\n (from: number, delta: number): void => {\n for (let index = from + delta; index >= 0 && index < rows.length; index += delta) {\n if (!rows[index].node.disabled) {\n focusRow(rows[index].node.id);\n return;\n }\n }\n },\n [rows, focusRow],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>, row: FlatNode, index: number): void => {\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n moveFocus(index, 1);\n break;\n case \"ArrowUp\":\n event.preventDefault();\n moveFocus(index, -1);\n break;\n case \"ArrowRight\":\n event.preventDefault();\n if (row.hasChildren && !row.expanded) toggle(row.node.id);\n else if (row.expanded) moveFocus(index, 1);\n break;\n case \"ArrowLeft\":\n event.preventDefault();\n if (row.expanded) {\n toggle(row.node.id);\n } else if (row.parentId) {\n focusRow(row.parentId);\n }\n break;\n case \"Home\":\n event.preventDefault();\n moveFocus(-1, 1);\n break;\n case \"End\":\n event.preventDefault();\n moveFocus(rows.length, -1);\n break;\n case \"Enter\":\n case \" \":\n event.preventDefault();\n select(row);\n break;\n default:\n break;\n }\n },\n [moveFocus, rows.length, select, toggle, focusRow],\n );\n\n return (\n <ul\n ref={containerRef}\n role=\"tree\"\n aria-label={label}\n className={cn(styles.tree, className)}\n >\n {rows.map((row, index) => {\n const isSelected = selected === row.node.id;\n return (\n <li\n key={row.node.id}\n role=\"treeitem\"\n aria-expanded={row.hasChildren ? row.expanded : undefined}\n aria-selected={isSelected}\n aria-level={row.depth + 1}\n aria-disabled={row.node.disabled || undefined}\n className={styles.item}\n >\n <div\n data-tree-id={row.node.id}\n className={cn(\n styles.row,\n isSelected && styles.selected,\n row.node.disabled && styles.disabled,\n )}\n style={{\n paddingInlineStart: `calc(${row.depth} * var(--tempest-space-5))`,\n }}\n tabIndex={activeId === row.node.id && !row.node.disabled ? 0 : -1}\n onClick={() => select(row)}\n onFocus={() => setFocusedId(row.node.id)}\n onKeyDown={(event) => handleKeyDown(event, row, index)}\n >\n {row.hasChildren ? (\n <span\n className={cn(\n styles.chevron,\n row.expanded && styles.chevronOpen,\n )}\n aria-hidden=\"true\"\n onClick={(event) => {\n event.stopPropagation();\n if (!row.node.disabled) toggle(row.node.id);\n }}\n >\n <ChevronRight size={14} />\n </span>\n ) : (\n <span className={styles.chevronPlaceholder} aria-hidden=\"true\" />\n )}\n {row.node.icon ? (\n <span className={styles.icon} aria-hidden=\"true\">\n {row.node.icon}\n </span>\n ) : null}\n <span className={styles.label}>{row.node.label}</span>\n </div>\n </li>\n );\n })}\n </ul>\n );\n}\n"],"mappings":";;;;;;AAmEA,SAAS,EACL,GACA,GACA,IAAQ,GACR,IAA0B,MAC1B,IAAkB,CAAC,GACT;CACV,KAAK,IAAM,KAAQ,GAAO;EACtB,IAAM,IAAc,MAAM,QAAQ,EAAK,QAAQ,GACzC,IAAW,KAAe,EAAY,IAAI,EAAK,EAAE;EAEvD,AADA,EAAI,KAAK;GAAE;GAAM;GAAO;GAAU;GAAa;EAAS,CAAC,GACrD,K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I,KAAK;GACzC,OACI,kBAAC,MAAD;IAEI,MAAK;IACL,iBAAe,EAAI,cAAc,EAAI,WAAW,KAAA;IAChD,iBAAe;IACf,cAAY,EAAI,QAAQ;IACxB,iBAAe,EAAI,KAAK,YAAY,KAAA;IACpC,WAAW,EAAO;cAElB,kBAAC,OAAD;KACI,gBAAc,EAAI,KAAK;KACvB,WAAW,EACP,EAAO,KACP,KAAc,EAAO,UACrB,EAAI,KAAK,YAAY,EAAO,QAChC;KACA,OAAO,EACH,oBAAoB,QAAQ,EAAI,MAAM,4BAC1C;KACA,UAAU,MAAa,EAAI,KAAK,MAAM,CAAC,EAAI,KAAK,WAAW,IAAI;KAC/D,eAAe,EAAO,CAAG;KACzB,eAAe,EAAa,EAAI,KAAK,EAAE;KACvC,YAAY,MAAU,EAAc,GAAO,GAAK,CAAK;eAbzD;MAeK,EAAI,cACD,kBAAC,QAAD;OACI,WAAW,EACP,EAAO,SACP,EAAI,YAAY,EAAO,WAC3B;OACA,eAAY;OACZ,UAAU,MAAU;QAEhB,AADA,EAAM,gBAAgB,GACjB,EAAI,KAAK,YAAU,EAAO,EAAI,KAAK,EAAE;OAC9C;iBAEA,kBAAC,GAAD,EAAc,MAAM,GAAK,CAAA;MACvB,CAAA,IAEN,kBAAC,QAAD;OAAM,WAAW,EAAO;OAAoB,eAAY;MAAQ,CAAA;MAEnE,EAAI,KAAK,OACN,kBAAC,QAAD;OAAM,WAAW,EAAO;OAAM,eAAY;iBACrC,EAAI,KAAK;MACR,CAAA,IACN;MACJ,kBAAC,QAAD;OAAM,WAAW,EAAO;iBAAQ,EAAI,KAAK;MAAY,CAAA;KACpD;;GACL,GA/CK,EAAI,KAAK,EA+Cd;EAEZ,CAAC;CACD,CAAA;AAEZ"}
1
+ {"version":3,"file":"TreeView.js","names":[],"sources":["../../../src/components/TreeView/TreeView.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — expansion and selection\n * are two independent controlled states, each with its uncontrolled twin\n * (expandedIds/defaultExpandedIds/onExpandedChange, selectedId/\n * defaultSelectedId/onSelect), plus toggleOnSelect for the case where they should\n * move together. The body is the flattened visible list and the roving focus over\n * it.\n */\nimport { ChevronRight } from \"lucide-react\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./TreeView.module.css\";\n\n/** One node of the tree. Children make it a branch; no children makes it a leaf. */\nexport interface TreeNode {\n /** Stable identifier, unique across the whole tree. */\n id: string;\n /** Rendered label. */\n label: ReactNode;\n /** Child nodes. An empty array still renders as a branch (an empty folder). */\n children?: TreeNode[];\n /** Icon rendered before the label. */\n icon?: ReactNode;\n /** Blocks selection and expansion, and skips the node in keyboard navigation. */\n disabled?: boolean;\n}\n\nexport interface TreeViewProps {\n /** Root nodes. */\n nodes: TreeNode[];\n /** Controlled expanded ids. */\n expandedIds?: string[];\n /** Uncontrolled initial expanded ids. */\n defaultExpandedIds?: string[];\n onExpandedChange?: (expandedIds: string[]) => void;\n /** Controlled selected id. `null` means nothing selected. */\n selectedId?: string | null;\n /** Uncontrolled initial selection. */\n defaultSelectedId?: string | null;\n onSelect?: (node: TreeNode) => void;\n /**\n * Selecting a branch also toggles it. Default `true` — matches how a file\n * explorer behaves; set `false` when a branch is itself a meaningful choice\n * (a category that owns items, for instance).\n */\n toggleOnSelect?: boolean;\n /** Accessible name for the tree. */\n label?: string;\n className?: string;\n}\n\ninterface FlatNode {\n node: TreeNode;\n depth: number;\n parentId: string | null;\n hasChildren: boolean;\n expanded: boolean;\n}\n\n/**\n * Walk the tree into the list of *currently visible* rows.\n *\n * Keyboard navigation works on this flattened view, which is what makes\n * ArrowDown from the last child of a collapsed-sibling branch land on the right\n * row: rows that are not rendered simply are not in the list.\n */\nfunction flatten(\n nodes: TreeNode[],\n expandedIds: Set<string>,\n depth = 0,\n parentId: string | null = null,\n out: FlatNode[] = [],\n): FlatNode[] {\n for (const node of nodes) {\n const hasChildren = Array.isArray(node.children);\n const expanded = hasChildren && expandedIds.has(node.id);\n out.push({ node, depth, parentId, hasChildren, expanded });\n if (expanded && node.children) {\n flatten(node.children, expandedIds, depth + 1, node.id, out);\n }\n }\n return out;\n}\n\n/**\n * Accessible tree for hierarchical data — categories, permissions, folders, an\n * org chart.\n *\n * Implements the `tree` role with **roving tabindex**: exactly one row is\n * tabbable, and the arrow keys move focus within the widget. That is what keeps a\n * 500-node tree from adding 500 stops to the page's tab order.\n *\n * Keyboard map: `↓`/`↑` move, `→` expands (or descends), `←` collapses (or goes to\n * the parent), `Home`/`End` jump to the first/last visible row, `Enter`/`Space`\n * select.\n *\n * The chevron is decoration (`aria-hidden`), not a button: the row itself carries\n * `aria-expanded`, so a second focusable control there would only add noise for a\n * screen reader while duplicating an action the keyboard map already has. It still\n * accepts a click, with the event stopped so it toggles without also selecting.\n *\n * @example\n * ```tsx\n * const nodes: TreeNode[] = [\n * {\n * id: \"vendas\",\n * label: \"Vendas\",\n * children: [\n * { id: \"vendas.ler\", label: \"Ler\" },\n * { id: \"vendas.editar\", label: \"Editar\" },\n * ],\n * },\n * { id: \"config\", label: \"Configurações\", children: [] },\n * ];\n *\n * <TreeView nodes={nodes} defaultExpandedIds={[\"vendas\"]} onSelect={(node) => console.log(node.id)} />\n * ```\n */\nexport function TreeView({\n nodes,\n expandedIds,\n defaultExpandedIds = [],\n onExpandedChange,\n selectedId,\n defaultSelectedId = null,\n onSelect,\n toggleOnSelect = true,\n label,\n className,\n}: TreeViewProps) {\n const expandedControlled = expandedIds !== undefined;\n const [internalExpanded, setInternalExpanded] = useState<string[]>(defaultExpandedIds);\n const expanded = expandedControlled ? expandedIds : internalExpanded;\n\n const selectionControlled = selectedId !== undefined;\n const [internalSelected, setInternalSelected] = useState<string | null>(defaultSelectedId);\n const selected = selectionControlled ? selectedId : internalSelected;\n\n const expandedSet = useMemo(() => new Set(expanded), [expanded]);\n const rows = useMemo(() => flatten(nodes, expandedSet), [nodes, expandedSet]);\n\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const containerRef = useRef<HTMLUListElement>(null);\n\n const activeId =\n focusedId ?? selected ?? rows.find((row) => !row.node.disabled)?.node.id ?? null;\n\n const setExpanded = useCallback(\n (next: string[]): void => {\n if (!expandedControlled) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [expandedControlled, onExpandedChange],\n );\n\n const toggle = useCallback(\n (id: string): void => {\n setExpanded(\n expanded.includes(id) ? expanded.filter((x) => x !== id) : [...expanded, id],\n );\n },\n [expanded, setExpanded],\n );\n\n const select = useCallback(\n (row: FlatNode): void => {\n if (row.node.disabled) return;\n if (!selectionControlled) setInternalSelected(row.node.id);\n setFocusedId(row.node.id);\n onSelect?.(row.node);\n if (row.hasChildren && toggleOnSelect) toggle(row.node.id);\n },\n [onSelect, selectionControlled, toggle, toggleOnSelect],\n );\n\n /** Move DOM focus to a row by id, so the roving tabindex actually roves. */\n const focusRow = useCallback((id: string): void => {\n setFocusedId(id);\n const element = containerRef.current?.querySelector<HTMLElement>(`[data-tree-id=\"${id}\"]`);\n element?.focus();\n }, []);\n\n const moveFocus = useCallback(\n (from: number, delta: number): void => {\n for (let index = from + delta; index >= 0 && index < rows.length; index += delta) {\n if (!rows[index].node.disabled) {\n focusRow(rows[index].node.id);\n return;\n }\n }\n },\n [rows, focusRow],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>, row: FlatNode, index: number): void => {\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n moveFocus(index, 1);\n break;\n case \"ArrowUp\":\n event.preventDefault();\n moveFocus(index, -1);\n break;\n case \"ArrowRight\":\n event.preventDefault();\n if (row.hasChildren && !row.expanded) toggle(row.node.id);\n else if (row.expanded) moveFocus(index, 1);\n break;\n case \"ArrowLeft\":\n event.preventDefault();\n if (row.expanded) {\n toggle(row.node.id);\n } else if (row.parentId) {\n focusRow(row.parentId);\n }\n break;\n case \"Home\":\n event.preventDefault();\n moveFocus(-1, 1);\n break;\n case \"End\":\n event.preventDefault();\n moveFocus(rows.length, -1);\n break;\n case \"Enter\":\n case \" \":\n event.preventDefault();\n select(row);\n break;\n default:\n break;\n }\n },\n [moveFocus, rows.length, select, toggle, focusRow],\n );\n\n return (\n <ul\n ref={containerRef}\n role=\"tree\"\n aria-label={label}\n className={cn(styles.tree, className)}\n >\n {rows.map((row, index) => {\n const isSelected = selected === row.node.id;\n return (\n <li\n key={row.node.id}\n role=\"treeitem\"\n aria-expanded={row.hasChildren ? row.expanded : undefined}\n aria-selected={isSelected}\n aria-level={row.depth + 1}\n aria-disabled={row.node.disabled || undefined}\n className={styles.item}\n >\n <div\n data-tree-id={row.node.id}\n className={cn(\n styles.row,\n isSelected && styles.selected,\n row.node.disabled && styles.disabled,\n )}\n style={{\n paddingInlineStart: `calc(${row.depth} * var(--tempest-space-5))`,\n }}\n tabIndex={activeId === row.node.id && !row.node.disabled ? 0 : -1}\n onClick={() => select(row)}\n onFocus={() => setFocusedId(row.node.id)}\n onKeyDown={(event) => handleKeyDown(event, row, index)}\n >\n {row.hasChildren ? (\n <span\n className={cn(\n styles.chevron,\n row.expanded && styles.chevronOpen,\n )}\n aria-hidden=\"true\"\n onClick={(event) => {\n event.stopPropagation();\n if (!row.node.disabled) toggle(row.node.id);\n }}\n >\n <ChevronRight size={14} />\n </span>\n ) : (\n <span className={styles.chevronPlaceholder} aria-hidden=\"true\" />\n )}\n {row.node.icon ? (\n <span className={styles.icon} aria-hidden=\"true\">\n {row.node.icon}\n </span>\n ) : null}\n <span className={styles.label}>{row.node.label}</span>\n </div>\n </li>\n );\n })}\n </ul>\n );\n}\n"],"mappings":";;;;;;AAmEA,SAAS,EACL,GACA,GACA,IAAQ,GACR,IAA0B,MAC1B,IAAkB,CAAC,GACT;CACV,KAAK,IAAM,KAAQ,GAAO;EACtB,IAAM,IAAc,MAAM,QAAQ,EAAK,QAAQ,GACzC,IAAW,KAAe,EAAY,IAAI,EAAK,EAAE;EAEvD,AADA,EAAI,KAA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pdatePrompt.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactNode } from \"react\";\nimport { RefreshCw, X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./UpdatePrompt.module.css\";\n\nexport type UpdatePromptPosition = \"top\" | \"bottom\";\n\nexport interface UpdatePromptProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Whether the prompt is visible. Feed from `useServiceWorkerUpdate().updateAvailable`. */\n open: boolean;\n /** Called when the user confirms the update. Wire to `applyUpdate`. */\n onUpdate: () => void;\n /** Called when the user dismisses the prompt. Omit to hide the dismiss button. */\n onDismiss?: () => void;\n /** Body message. */\n message?: ReactNode;\n /** Confirm button label. Default `\"Atualizar\"`. */\n actionLabel?: string;\n /** Where to pin the fixed toast. Default `\"bottom\"`. */\n position?: UpdatePromptPosition;\n}\n\n/**\n * Fixed toast prompting the user to activate a freshly installed service\n * worker. Presentational — pair with {@link useServiceWorkerUpdate}, feeding\n * `updateAvailable` to `open` and `applyUpdate` to `onUpdate`.\n *\n * Renders nothing while `open` is `false`.\n *\n * @example\n * const { updateAvailable, applyUpdate } = useServiceWorkerUpdate({ url: \"/sw.js\" });\n * <UpdatePrompt open={updateAvailable} onUpdate={applyUpdate} />\n */\nexport function UpdatePrompt({\n open,\n onUpdate,\n onDismiss,\n message = \"Uma nova versão está disponível.\",\n actionLabel = \"Atualizar\",\n position = \"bottom\",\n className,\n ...props\n}: UpdatePromptProps) {\n if (!open) return null;\n return (\n <div\n className={cn(styles.prompt, styles[position], className)}\n role=\"alert\"\n aria-live=\"assertive\"\n {...props}\n >\n <RefreshCw className={styles.icon} size={18} aria-hidden=\"true\" />\n <span className={styles.message}>{message}</span>\n <button type=\"button\" className={styles.action} onClick={onUpdate}>\n {actionLabel}\n </button>\n {onDismiss && (\n <button\n type=\"button\"\n className={styles.dismiss}\n aria-label=\"Dispensar\"\n onClick={onDismiss}\n >\n <X size={16} aria-hidden=\"true\" />\n </button>\n )}\n </div>\n );\n}\n"],"mappings":"0IAiCA,SAAgB,EAAa,CACzB,OACA,WACA,YACA,UAAU,mCACV,cAAc,YACd,WAAW,SACX,YACA,GAAG,GACe,CAElB,OADK,GAED,EAAA,EAAA,KAAA,CAAC,MAAD,CACI,UAAW,EAAA,GAAG,EAAA,QAAO,OAAQ,EAAA,QAAO,GAAW,CAAS,EACxD,KAAK,QACL,YAAU,YACV,GAAI,WAJR,EAMI,EAAA,EAAA,IAAA,CAAC,EAAA,UAAD,CAAW,UAAW,EAAA,QAAO,KAAM,KAAM,GAAI,cAAY,MAAQ,CAAA,GACjE,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,iBAAU,CAAc,CAAA,GAChD,EAAA,EAAA,IAAA,CAAC,SAAD,CAAQ,KAAK,SAAS,UAAW,EAAA,QAAO,OAAQ,QAAS,WACpD,CACG,CAAA,EACP,IACG,EAAA,EAAA,IAAA,CAAC,SAAD,CACI,KAAK,SACL,UAAW,EAAA,QAAO,QAClB,aAAW,YACX,QAAS,YAET,EAAA,EAAA,IAAA,CAAC,EAAA,EAAD,CAAG,KAAM,GAAI,cAAY,MAAQ,CAAA,CAC7B,CAAA,CAEX,IAvBS,IAyBtB"}
1
+ {"version":3,"file":"UpdatePrompt.cjs","names":[],"sources":["../../../src/components/UpdatePrompt/UpdatePrompt.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactNode } from \"react\";\nimport { RefreshCw, X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./UpdatePrompt.module.css\";\n\nexport type UpdatePromptPosition = \"top\" | \"bottom\";\n\nexport interface UpdatePromptProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Whether the prompt is visible. Feed from `useServiceWorkerUpdate().updateAvailable`. */\n open: boolean;\n /** Called when the user confirms the update. Wire to `applyUpdate`. */\n onUpdate: () => void;\n /** Called when the user dismisses the prompt. Omit to hide the dismiss button. */\n onDismiss?: () => void;\n /** Body message. */\n message?: ReactNode;\n /** Confirm button label. Default `\"Atualizar\"`. */\n actionLabel?: string;\n /** Where to pin the fixed toast. Default `\"bottom\"`. */\n position?: UpdatePromptPosition;\n}\n\n/**\n * Fixed toast prompting the user to activate a freshly installed service\n * worker. Presentational — pair with {@link useServiceWorkerUpdate}, feeding\n * `updateAvailable` to `open` and `applyUpdate` to `onUpdate`.\n *\n * Renders nothing while `open` is `false`.\n *\n * @example\n * const { updateAvailable, applyUpdate } = useServiceWorkerUpdate({ url: \"/sw.js\" });\n * <UpdatePrompt open={updateAvailable} onUpdate={applyUpdate} />\n */\nexport function UpdatePrompt({\n open,\n onUpdate,\n onDismiss,\n message = \"Uma nova versão está disponível.\",\n actionLabel = \"Atualizar\",\n position = \"bottom\",\n className,\n ...props\n}: UpdatePromptProps) {\n if (!open) return null;\n return (\n <div\n className={cn(styles.prompt, styles[position], className)}\n role=\"alert\"\n aria-live=\"assertive\"\n {...props}\n >\n <RefreshCw className={styles.icon} size={18} aria-hidden=\"true\" />\n <span className={styles.message}>{message}</span>\n <button type=\"button\" className={styles.action} onClick={onUpdate}>\n {actionLabel}\n </button>\n {onDismiss && (\n <button\n type=\"button\"\n className={styles.dismiss}\n aria-label=\"Dispensar\"\n onClick={onDismiss}\n >\n <X size={16} aria-hidden=\"true\" />\n </button>\n )}\n </div>\n );\n}\n"],"mappings":"0IAiCA,SAAgB,EAAa,CACzB,OACA,WACA,YACA,UAAU,mCACV,cAAc,YACd,WAAW,SACX,YACA,GAAG,GACe,CAElB,OADK,GAED,EAAA,EAAA,KAAA,CAAC,MAAD,CACI,UAAW,EAAA,GAAG,EAAA,QAAO,OAAQ,EAAA,QAAO,GAAW,CAAS,EACxD,KAAK,QACL,YAAU,YACV,GAAI,EAJR,SAAA,EAMI,EAAA,EAAA,IAAA,CAAC,EAAA,UAAD,CAAW,UAAW,EAAA,QAAO,KAAM,KAAM,GAAI,cAAY,MAAQ,CAAA,GACjE,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,QAAU,SAAA,CAAc,CAAA,GAChD,EAAA,EAAA,IAAA,CAAC,SAAD,CAAQ,KAAK,SAAS,UAAW,EAAA,QAAO,OAAQ,QAAS,EACpD,SAAA,CACG,CAAA,EACP,IACG,EAAA,EAAA,IAAA,CAAC,SAAD,CACI,KAAK,SACL,UAAW,EAAA,QAAO,QAClB,aAAW,YACX,QAAS,EAET,UAAA,EAAA,EAAA,IAAA,CAAC,EAAA,EAAD,CAAG,KAAM,GAAI,cAAY,MAAQ,CAAA,CAC7B,CAAA,CAEX,IAvBS,IAyBtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"UpdatePrompt.js","names":[],"sources":["../../../src/components/UpdatePrompt/UpdatePrompt.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactNode } from \"react\";\nimport { RefreshCw, X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./UpdatePrompt.module.css\";\n\nexport type UpdatePromptPosition = \"top\" | \"bottom\";\n\nexport interface UpdatePromptProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Whether the prompt is visible. Feed from `useServiceWorkerUpdate().updateAvailable`. */\n open: boolean;\n /** Called when the user confirms the update. Wire to `applyUpdate`. */\n onUpdate: () => void;\n /** Called when the user dismisses the prompt. Omit to hide the dismiss button. */\n onDismiss?: () => void;\n /** Body message. */\n message?: ReactNode;\n /** Confirm button label. Default `\"Atualizar\"`. */\n actionLabel?: string;\n /** Where to pin the fixed toast. Default `\"bottom\"`. */\n position?: UpdatePromptPosition;\n}\n\n/**\n * Fixed toast prompting the user to activate a freshly installed service\n * worker. Presentational — pair with {@link useServiceWorkerUpdate}, feeding\n * `updateAvailable` to `open` and `applyUpdate` to `onUpdate`.\n *\n * Renders nothing while `open` is `false`.\n *\n * @example\n * const { updateAvailable, applyUpdate } = useServiceWorkerUpdate({ url: \"/sw.js\" });\n * <UpdatePrompt open={updateAvailable} onUpdate={applyUpdate} />\n */\nexport function UpdatePrompt({\n open,\n onUpdate,\n onDismiss,\n message = \"Uma nova versão está disponível.\",\n actionLabel = \"Atualizar\",\n position = \"bottom\",\n className,\n ...props\n}: UpdatePromptProps) {\n if (!open) return null;\n return (\n <div\n className={cn(styles.prompt, styles[position], className)}\n role=\"alert\"\n aria-live=\"assertive\"\n {...props}\n >\n <RefreshCw className={styles.icon} size={18} aria-hidden=\"true\" />\n <span className={styles.message}>{message}</span>\n <button type=\"button\" className={styles.action} onClick={onUpdate}>\n {actionLabel}\n </button>\n {onDismiss && (\n <button\n type=\"button\"\n className={styles.dismiss}\n aria-label=\"Dispensar\"\n onClick={onDismiss}\n >\n <X size={16} aria-hidden=\"true\" />\n </button>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;AAiCA,SAAgB,EAAa,EACzB,SACA,aACA,cACA,aAAU,oCACV,iBAAc,aACd,cAAW,UACX,cACA,GAAG,KACe;CAElB,OADK,IAED,kBAAC,OAAD;EACI,WAAW,EAAG,EAAO,QAAQ,EAAO,IAAW,CAAS;EACxD,MAAK;EACL,aAAU;EACV,GAAI;YAJR;GAMI,kBAAC,GAAD;IAAW,WAAW,EAAO;IAAM,MAAM;IAAI,eAAY;GAAQ,CAAA;GACjE,kBAAC,QAAD;IAAM,WAAW,EAAO;cAAU;GAAc,CAAA;GAChD,kBAAC,UAAD;IAAQ,MAAK;IAAS,WAAW,EAAO;IAAQ,SAAS;cACpD;GACG,CAAA;GACP,KACG,kBAAC,UAAD;IACI,MAAK;IACL,WAAW,EAAO;IAClB,cAAW;IACX,SAAS;cAET,kBAAC,GAAD;KAAG,MAAM;KAAI,eAAY;IAAQ,CAAA;GAC7B,CAAA;EAEX;MAvBS;AAyBtB"}
1
+ {"version":3,"file":"UpdatePrompt.js","names":[],"sources":["../../../src/components/UpdatePrompt/UpdatePrompt.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactNode } from \"react\";\nimport { RefreshCw, X } from \"lucide-react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./UpdatePrompt.module.css\";\n\nexport type UpdatePromptPosition = \"top\" | \"bottom\";\n\nexport interface UpdatePromptProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Whether the prompt is visible. Feed from `useServiceWorkerUpdate().updateAvailable`. */\n open: boolean;\n /** Called when the user confirms the update. Wire to `applyUpdate`. */\n onUpdate: () => void;\n /** Called when the user dismisses the prompt. Omit to hide the dismiss button. */\n onDismiss?: () => void;\n /** Body message. */\n message?: ReactNode;\n /** Confirm button label. Default `\"Atualizar\"`. */\n actionLabel?: string;\n /** Where to pin the fixed toast. Default `\"bottom\"`. */\n position?: UpdatePromptPosition;\n}\n\n/**\n * Fixed toast prompting the user to activate a freshly installed service\n * worker. Presentational — pair with {@link useServiceWorkerUpdate}, feeding\n * `updateAvailable` to `open` and `applyUpdate` to `onUpdate`.\n *\n * Renders nothing while `open` is `false`.\n *\n * @example\n * const { updateAvailable, applyUpdate } = useServiceWorkerUpdate({ url: \"/sw.js\" });\n * <UpdatePrompt open={updateAvailable} onUpdate={applyUpdate} />\n */\nexport function UpdatePrompt({\n open,\n onUpdate,\n onDismiss,\n message = \"Uma nova versão está disponível.\",\n actionLabel = \"Atualizar\",\n position = \"bottom\",\n className,\n ...props\n}: UpdatePromptProps) {\n if (!open) return null;\n return (\n <div\n className={cn(styles.prompt, styles[position], className)}\n role=\"alert\"\n aria-live=\"assertive\"\n {...props}\n >\n <RefreshCw className={styles.icon} size={18} aria-hidden=\"true\" />\n <span className={styles.message}>{message}</span>\n <button type=\"button\" className={styles.action} onClick={onUpdate}>\n {actionLabel}\n </button>\n {onDismiss && (\n <button\n type=\"button\"\n className={styles.dismiss}\n aria-label=\"Dispensar\"\n onClick={onDismiss}\n >\n <X size={16} aria-hidden=\"true\" />\n </button>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;AAiCA,SAAgB,EAAa,EACzB,SACA,aACA,cACA,aAAU,oCACV,iBAAc,aACd,cAAW,UACX,cACA,GAAG,KACe;CAElB,OADK,IAED,kBAAC,OAAD;EACI,WAAW,EAAG,EAAO,QAAQ,EAAO,IAAW,CAAS;EACxD,MAAK;EACL,aAAU;EACV,GAAI;EAJR,UAAA;GAMI,kBAAC,GAAD;IAAW,WAAW,EAAO;IAAM,MAAM;IAAI,eAAY;GAAQ,CAAA;GACjE,kBAAC,QAAD;IAAM,WAAW,EAAO;IAAU,UAAA;GAAc,CAAA;GAChD,kBAAC,UAAD;IAAQ,MAAK;IAAS,WAAW,EAAO;IAAQ,SAAS;IACpD,UAAA;GACG,CAAA;GACP,KACG,kBAAC,UAAD;IACI,MAAK;IACL,WAAW,EAAO;IAClB,cAAW;IACX,SAAS;IAET,UAAA,kBAAC,GAAD;KAAG,MAAM;KAAI,eAAY;IAAQ,CAAA;GAC7B,CAAA;EAEX;MAvBS;AAyBtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualList.cjs","names":[],"sources":["../../../src/components/VirtualList/VirtualList.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — items, itemHeight, height and overscan are the\n * window maths; renderItem and getKey the row contract; label the accessible name of\n * a scroll region. Nine props is what windowing costs — the alternative is the app\n * doing the maths.\n */\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./VirtualList.module.css\";\n\nexport interface VirtualListProps<T> {\n items: T[];\n /** Fixed pixel height for each row. */\n itemHeight: number;\n /** Render a single row. */\n renderItem: (item: T, index: number) => ReactNode;\n /** Container height (px) or any CSS length. */\n height: number | string;\n /** Number of items rendered above/below the viewport. Default: 4. */\n overscan?: number;\n /** Stable key derivation; defaults to the index. */\n getKey?: (item: T, index: number) => string | number;\n className?: string;\n style?: CSSProperties;\n /**\n * Accessible name for the list. Worth setting when the list scrolls: it\n * then carries a tab stop of its own, and a focus stop that announces\n * nothing is worse than no focus stop.\n */\n label?: string;\n}\n\n/**\n * Fixed-height virtual list. Renders only the visible window plus a small\n * overscan buffer. Suitable for lists of thousands of identical rows.\n *\n * For variable heights, use `react-window`/`@tanstack/react-virtual` — those\n * solve a more general problem at the cost of extra setup.\n */\nexport function VirtualList<T>({\n items,\n itemHeight,\n renderItem,\n height,\n overscan = 4,\n getKey,\n className,\n style,\n label,\n}: VirtualListProps<T>) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n\n useEffect(() => {\n const element = containerRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n const totalHeight = items.length * itemHeight;\n /*\n * Rows are absolutely positioned inside the spacer, so nothing in a\n * virtual list is focusable by default: a keyboard user can see the\n * scrollbar and has no way to move it. The tab stop only appears while\n * there is something past the fold — measured from the numbers already at\n * hand rather than from the DOM.\n */\n const scrollable = viewport > 0 && totalHeight - viewport > 1;\n const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);\n const visibleCount = Math.ceil(viewport / itemHeight) + overscan * 2;\n const end = Math.min(items.length, start + visibleCount);\n\n return (\n <div\n ref={containerRef}\n className={cn(styles.scroll, className)}\n style={{ height, ...style }}\n onScroll={(event) => setScrollTop((event.target as HTMLDivElement).scrollTop)}\n role=\"list\"\n aria-label={label}\n tabIndex={scrollable ? 0 : undefined}\n >\n <div className={styles.spacer} style={{ height: totalHeight }}>\n {items.slice(start, end).map((item, offset) => {\n const index = start + offset;\n const key = getKey ? getKey(item, index) : index;\n return (\n <div\n key={key}\n role=\"listitem\"\n className={styles.row}\n style={{ top: index * itemHeight, height: itemHeight }}\n >\n {renderItem(item, index)}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n"],"mappings":"kIAwCA,SAAgB,EAAe,CAC3B,QACA,aACA,aACA,SACA,WAAW,EACX,SACA,YACA,QACA,SACoB,CACpB,IAAM,GAAA,EAAA,EAAA,OAAA,C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CACtB,EANI,CAMJ,CAEb,CAAC,CACA,CAAA,CACJ,CAAA,CAEb"}
1
+ {"version":3,"file":"VirtualList.cjs","names":[],"sources":["../../../src/components/VirtualList/VirtualList.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — items, itemHeight, height and overscan are the\n * window maths; renderItem and getKey the row contract; label the accessible name of\n * a scroll region. Nine props is what windowing costs — the alternative is the app\n * doing the maths.\n */\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./VirtualList.module.css\";\n\nexport interface VirtualListProps<T> {\n items: T[];\n /** Fixed pixel height for each row. */\n itemHeight: number;\n /** Render a single row. */\n renderItem: (item: T, index: number) => ReactNode;\n /** Container height (px) or any CSS length. */\n height: number | string;\n /** Number of items rendered above/below the viewport. Default: 4. */\n overscan?: number;\n /** Stable key derivation; defaults to the index. */\n getKey?: (item: T, index: number) => string | number;\n className?: string;\n style?: CSSProperties;\n /**\n * Accessible name for the list. Worth setting when the list scrolls: it\n * then carries a tab stop of its own, and a focus stop that announces\n * nothing is worse than no focus stop.\n */\n label?: string;\n}\n\n/**\n * Fixed-height virtual list. Renders only the visible window plus a small\n * overscan buffer. Suitable for lists of thousands of identical rows.\n *\n * For variable heights, use `react-window`/`@tanstack/react-virtual` — those\n * solve a more general problem at the cost of extra setup.\n */\nexport function VirtualList<T>({\n items,\n itemHeight,\n renderItem,\n height,\n overscan = 4,\n getKey,\n className,\n style,\n label,\n}: VirtualListProps<T>) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n\n useEffect(() => {\n const element = containerRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n const totalHeight = items.length * itemHeight;\n /*\n * Rows are absolutely positioned inside the spacer, so nothing in a\n * virtual list is focusable by default: a keyboard user can see the\n * scrollbar and has no way to move it. The tab stop only appears while\n * there is something past the fold — measured from the numbers already at\n * hand rather than from the DOM.\n */\n const scrollable = viewport > 0 && totalHeight - viewport > 1;\n const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);\n const visibleCount = Math.ceil(viewport / itemHeight) + overscan * 2;\n const end = Math.min(items.length, start + visibleCount);\n\n return (\n <div\n ref={containerRef}\n className={cn(styles.scroll, className)}\n style={{ height, ...style }}\n onScroll={(event) => setScrollTop((event.target as HTMLDivElement).scrollTop)}\n role=\"list\"\n aria-label={label}\n tabIndex={scrollable ? 0 : undefined}\n >\n <div className={styles.spacer} style={{ height: totalHeight }}>\n {items.slice(start, end).map((item, offset) => {\n const index = start + offset;\n const key = getKey ? getKey(item, index) : index;\n return (\n <div\n key={key}\n role=\"listitem\"\n className={styles.row}\n style={{ top: index * itemHeight, height: itemHeight }}\n >\n {renderItem(item, index)}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n"],"mappings":"kIAwCA,SAAgB,EAAe,CAC3B,QACA,aACA,aACA,SACA,WAAW,EACX,SACA,YACA,QACA,SACoB,CACpB,IAAM,GAAA,EAAe,EAAA,OAAA,CAAuB,IAAI,EAC1C,CAAC,EAAW,IAAA,EAAgB,EAAA,SAAA,CAAiB,CAAC,EAC9C,CAAC,EAAU,IAAA,EAAe,EAAA,SAAA,CAAiB,CAAC,GAElD,EAAA,EAAA,UAAA,KAAgB,CACZ,IAAM,EAAU,EAAa,QAG7B,GAFI,CAAC,IACL,EAAY,EAAQ,YAAY,EAC5B,OAAO,eAAmB,KAAa,OAC3C,IAAM,EAAW,IAAI,mBAAqB,EAAY,EAAQ,YAAY,CAAC,EAE3E,OADA,EAAS,QAAQ,CAAO,MACX,EAAS,WAAW,CACrC,EAAG,CAAC,CAAC,EAEL,IAAM,EAAc,EAAM,OAAS,EAQ7B,EAAa,EAAW,GAAK,EAAc,EAAW,EACtD,EAAQ,KAAK,IAAI,EAAG,KAAK,MAAM,EAAY,CAAU,EAAI,CAAQ,EACjE,EAAe,KAAK,KAAK,EAAW,CAAU,EAAI,EAAW,EAC7D,EAAM,KAAK,IAAI,EAAM,OAAQ,EAAQ,CAAY,EAEvD,OACI,EAAA,EAAA,IAAA,CAAC,MAAD,CACI,IAAK,EACL,UAAW,EAAA,GAAG,EAAA,QAAO,OAAQ,CAAS,EACtC,MAAO,CAAE,SAAQ,GAAG,CAAM,EAC1B,SAAW,GAAU,EAAc,EAAM,OAA0B,SAAS,EAC5E,KAAK,OACL,aAAY,EACZ,SAAU,EAAa,EAAI,IAAA,GAE3B,UAAA,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,OAAQ,MAAO,CAAE,OAAQ,CAAY,EACvD,SAAA,EAAM,MAAM,EAAO,CAAG,CAAC,CAAC,KAAK,EAAM,IAAW,CAC3C,IAAM,EAAQ,EAAQ,EAChB,EAAM,EAAS,EAAO,EAAM,CAAK,EAAI,EAC3C,OACI,EAAA,EAAA,IAAA,CAAC,MAAD,CAEI,KAAK,WACL,UAAW,EAAA,QAAO,IAClB,MAAO,CAAE,IAAK,EAAQ,EAAY,OAAQ,CAAW,EAEpD,SAAA,EAAW,EAAM,CAAK,CACtB,EANI,CAMJ,CAEb,CAAC,CACA,CAAA,CACJ,CAAA,CAEb"}
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualList.js","names":[],"sources":["../../../src/components/VirtualList/VirtualList.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — items, itemHeight, height and overscan are the\n * window maths; renderItem and getKey the row contract; label the accessible name of\n * a scroll region. Nine props is what windowing costs — the alternative is the app\n * doing the maths.\n */\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./VirtualList.module.css\";\n\nexport interface VirtualListProps<T> {\n items: T[];\n /** Fixed pixel height for each row. */\n itemHeight: number;\n /** Render a single row. */\n renderItem: (item: T, index: number) => ReactNode;\n /** Container height (px) or any CSS length. */\n height: number | string;\n /** Number of items rendered above/below the viewport. Default: 4. */\n overscan?: number;\n /** Stable key derivation; defaults to the index. */\n getKey?: (item: T, index: number) => string | number;\n className?: string;\n style?: CSSProperties;\n /**\n * Accessible name for the list. Worth setting when the list scrolls: it\n * then carries a tab stop of its own, and a focus stop that announces\n * nothing is worse than no focus stop.\n */\n label?: string;\n}\n\n/**\n * Fixed-height virtual list. Renders only the visible window plus a small\n * overscan buffer. Suitable for lists of thousands of identical rows.\n *\n * For variable heights, use `react-window`/`@tanstack/react-virtual` — those\n * solve a more general problem at the cost of extra setup.\n */\nexport function VirtualList<T>({\n items,\n itemHeight,\n renderItem,\n height,\n overscan = 4,\n getKey,\n className,\n style,\n label,\n}: VirtualListProps<T>) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n\n useEffect(() => {\n const element = containerRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n const totalHeight = items.length * itemHeight;\n /*\n * Rows are absolutely positioned inside the spacer, so nothing in a\n * virtual list is focusable by default: a keyboard user can see the\n * scrollbar and has no way to move it. The tab stop only appears while\n * there is something past the fold — measured from the numbers already at\n * hand rather than from the DOM.\n */\n const scrollable = viewport > 0 && totalHeight - viewport > 1;\n const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);\n const visibleCount = Math.ceil(viewport / itemHeight) + overscan * 2;\n const end = Math.min(items.length, start + visibleCount);\n\n return (\n <div\n ref={containerRef}\n className={cn(styles.scroll, className)}\n style={{ height, ...style }}\n onScroll={(event) => setScrollTop((event.target as HTMLDivElement).scrollTop)}\n role=\"list\"\n aria-label={label}\n tabIndex={scrollable ? 0 : undefined}\n >\n <div className={styles.spacer} style={{ height: totalHeight }}>\n {items.slice(start, end).map((item, offset) => {\n const index = start + offset;\n const key = getKey ? getKey(item, index) : index;\n return (\n <div\n key={key}\n role=\"listitem\"\n className={styles.row}\n style={{ top: index * itemHeight, height: itemHeight }}\n >\n {renderItem(item, index)}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;AAwCA,SAAgB,EAAe,EAC3B,UACA,eACA,eACA,WACA,cAAW,GACX,WACA,cACA,UACA,YACoB;CACpB,IAAM,IAAe,EAAuB,IAAI,GAC1C,CAAC,GAAW,KAAgB,EAAiB,CAAC,GAC9C,CAAC,GAAU,KAAe,EAAiB,CAAC;CAElD,QAAgB;EACZ,IAAM,IAAU,EAAa;EAG7B,IAFI,CAAC,MACL,EAAY,EAAQ,YAAY,GAC5B,OAAO,iBAAmB,MAAa;EAC3C,IAAM,IAAW,IAAI,qBAAqB,EAAY,EAAQ,YAAY,CAAC;EAE3E,OADA,EAAS,QAAQ,CAAO,SACX,EAAS,WAAW;CACrC,GAAG,CAAC,CAAC;CAEL,IAAM,IAAc,EAAM,SAAS,GAQ7B,IAAa,IAAW,KAAK,IAAc,IAAW,GACtD,IAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,IAAY,CAAU,IAAI,CAAQ,GACjE,IAAe,KAAK,KAAK,IAAW,CAAU,IAAI,IAAW,GAC7D,IAAM,KAAK,IAAI,EAAM,QAAQ,IAAQ,CAAY;CAEvD,OACI,kBAAC,OAAD;EACI,KAAK;EACL,WAAW,EAAG,EAAO,QAAQ,CAAS;EACtC,OAAO;GAAE;GAAQ,GAAG;EAAM;EAC1B,WAAW,MAAU,EAAc,EAAM,OAA0B,SAAS;EAC5E,MAAK;EACL,cAAY;EACZ,UAAU,IAAa,IAAI,KAAA;YAE3B,kBAAC,OAAD;GAAK,WAAW,EAAO;GAAQ,OAAO,EAAE,QAAQ,EAAY;aACvD,EAAM,MAAM,GAAO,CAAG,CAAC,CAAC,KAAK,GAAM,MAAW;IAC3C,IAAM,IAAQ,IAAQ,GAChB,IAAM,IAAS,EAAO,GAAM,CAAK,IAAI;IAC3C,OACI,kBAAC,OAAD;KAEI,MAAK;KACL,WAAW,EAAO;KAClB,OAAO;MAAE,KAAK,IAAQ;MAAY,QAAQ;KAAW;eAEpD,EAAW,GAAM,CAAK;IACtB,GANI,CAMJ;GAEb,CAAC;EACA,CAAA;CACJ,CAAA;AAEb"}
1
+ {"version":3,"file":"VirtualList.js","names":[],"sources":["../../../src/components/VirtualList/VirtualList.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — items, itemHeight, height and overscan are the\n * window maths; renderItem and getKey the row contract; label the accessible name of\n * a scroll region. Nine props is what windowing costs — the alternative is the app\n * doing the maths.\n */\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./VirtualList.module.css\";\n\nexport interface VirtualListProps<T> {\n items: T[];\n /** Fixed pixel height for each row. */\n itemHeight: number;\n /** Render a single row. */\n renderItem: (item: T, index: number) => ReactNode;\n /** Container height (px) or any CSS length. */\n height: number | string;\n /** Number of items rendered above/below the viewport. Default: 4. */\n overscan?: number;\n /** Stable key derivation; defaults to the index. */\n getKey?: (item: T, index: number) => string | number;\n className?: string;\n style?: CSSProperties;\n /**\n * Accessible name for the list. Worth setting when the list scrolls: it\n * then carries a tab stop of its own, and a focus stop that announces\n * nothing is worse than no focus stop.\n */\n label?: string;\n}\n\n/**\n * Fixed-height virtual list. Renders only the visible window plus a small\n * overscan buffer. Suitable for lists of thousands of identical rows.\n *\n * For variable heights, use `react-window`/`@tanstack/react-virtual` — those\n * solve a more general problem at the cost of extra setup.\n */\nexport function VirtualList<T>({\n items,\n itemHeight,\n renderItem,\n height,\n overscan = 4,\n getKey,\n className,\n style,\n label,\n}: VirtualListProps<T>) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n\n useEffect(() => {\n const element = containerRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n const totalHeight = items.length * itemHeight;\n /*\n * Rows are absolutely positioned inside the spacer, so nothing in a\n * virtual list is focusable by default: a keyboard user can see the\n * scrollbar and has no way to move it. The tab stop only appears while\n * there is something past the fold — measured from the numbers already at\n * hand rather than from the DOM.\n */\n const scrollable = viewport > 0 && totalHeight - viewport > 1;\n const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);\n const visibleCount = Math.ceil(viewport / itemHeight) + overscan * 2;\n const end = Math.min(items.length, start + visibleCount);\n\n return (\n <div\n ref={containerRef}\n className={cn(styles.scroll, className)}\n style={{ height, ...style }}\n onScroll={(event) => setScrollTop((event.target as HTMLDivElement).scrollTop)}\n role=\"list\"\n aria-label={label}\n tabIndex={scrollable ? 0 : undefined}\n >\n <div className={styles.spacer} style={{ height: totalHeight }}>\n {items.slice(start, end).map((item, offset) => {\n const index = start + offset;\n const key = getKey ? getKey(item, index) : index;\n return (\n <div\n key={key}\n role=\"listitem\"\n className={styles.row}\n style={{ top: index * itemHeight, height: itemHeight }}\n >\n {renderItem(item, index)}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;AAwCA,SAAgB,EAAe,EAC3B,UACA,eACA,eACA,WACA,cAAW,GACX,WACA,cACA,UACA,YACoB;CACpB,IAAM,IAAe,EAAuB,IAAI,GAC1C,CAAC,GAAW,KAAgB,EAAiB,CAAC,GAC9C,CAAC,GAAU,KAAe,EAAiB,CAAC;CAElD,QAAgB;EACZ,IAAM,IAAU,EAAa;EAG7B,IAFI,CAAC,MACL,EAAY,EAAQ,YAAY,GAC5B,OAAO,iBAAmB,MAAa;EAC3C,IAAM,IAAW,IAAI,qBAAqB,EAAY,EAAQ,YAAY,CAAC;EAE3E,OADA,EAAS,QAAQ,CAAO,SACX,EAAS,WAAW;CACrC,GAAG,CAAC,CAAC;CAEL,IAAM,IAAc,EAAM,SAAS,GAQ7B,IAAa,IAAW,KAAK,IAAc,IAAW,GACtD,IAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,IAAY,CAAU,IAAI,CAAQ,GACjE,IAAe,KAAK,KAAK,IAAW,CAAU,IAAI,IAAW,GAC7D,IAAM,KAAK,IAAI,EAAM,QAAQ,IAAQ,CAAY;CAEvD,OACI,kBAAC,OAAD;EACI,KAAK;EACL,WAAW,EAAG,EAAO,QAAQ,CAAS;EACtC,OAAO;GAAE;GAAQ,GAAG;EAAM;EAC1B,WAAW,MAAU,EAAc,EAAM,OAA0B,SAAS;EAC5E,MAAK;EACL,cAAY;EACZ,UAAU,IAAa,IAAI,KAAA;EAE3B,UAAA,kBAAC,OAAD;GAAK,WAAW,EAAO;GAAQ,OAAO,EAAE,QAAQ,EAAY;GACvD,UAAA,EAAM,MAAM,GAAO,CAAG,CAAC,CAAC,KAAK,GAAM,MAAW;IAC3C,IAAM,IAAQ,IAAQ,GAChB,IAAM,IAAS,EAAO,GAAM,CAAK,IAAI;IAC3C,OACI,kBAAC,OAAD;KAEI,MAAK;KACL,WAAW,EAAO;KAClB,OAAO;MAAE,KAAK,IAAQ;MAAY,QAAQ;KAAW;KAEpD,UAAA,EAAW,GAAM,CAAK;IACtB,GANI,CAMJ;GAEb,CAAC;EACA,CAAA;CACJ,CAAA;AAEb"}
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualTable.cjs","names":[],"sources":["../../../src/components/VirtualTable/VirtualTable.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count — windowing needs its own measurements\n * (rowHeight, height, overscan, scrollToIndex) on top of everything a table already\n * takes (data, columns, rowKey, initialSort, onRowClick, emptyMessage, caption). The\n * caption is not optional chrome — a virtualised grid without one is unreadable to a\n * screen reader.\n */\nimport {\n type HTMLAttributes,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { cn } from \"@/utils/cn\";\nimport { compareValues } from \"@/utils/compare-values\";\n\nimport type { TableAlign } from \"../Table\";\nimport styles from \"./VirtualTable.module.css\";\n\nexport type VirtualTableSortDirection = \"asc\" | \"desc\";\n\nexport interface VirtualTableSort<T> {\n key: keyof T;\n direction: VirtualTableSortDirection;\n}\n\nexport interface VirtualTableColumn<T> {\n /** Property of the row this column reads from. Doubles as the cell key. */\n key: keyof T;\n /** Column heading. */\n header: ReactNode;\n /** Custom cell renderer. Defaults to `row[key]`. */\n render?: (row: T, index: number) => ReactNode;\n /** Enable click-to-sort on this column's header. */\n sortable?: boolean;\n /** Text alignment. */\n align?: TableAlign;\n /**\n * Column width. Recommended for every column: virtualized rows enter and\n * leave the DOM as you scroll, so letting the browser auto-size columns from\n * whatever is currently rendered makes them jump mid-scroll.\n */\n width?: string | number;\n}\n\nexport interface VirtualTableProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Full dataset. Every row is accounted for; only the visible ones render. */\n data: T[];\n /** Column definitions. */\n columns: VirtualTableColumn<T>[];\n /**\n * Row height in px. Must be uniform and must match what the CSS produces,\n * because it is what maps scroll offset to row index.\n */\n rowHeight: number;\n /** Height of the scroll viewport — a number of px or any CSS length. */\n height: number | string;\n /** Rows rendered above and below the viewport. Default `4`. */\n overscan?: number;\n /** Stable key extractor. Defaults to the row's index in `data`. */\n rowKey?: (row: T, index: number) => string | number;\n /** Sort applied before any header interaction. */\n initialSort?: VirtualTableSort<T>;\n /** Called when a row is activated by click, `Enter` or `Space`. */\n onRowClick?: (row: T, index: number) => void;\n /** Content shown when `data` is empty. */\n emptyMessage?: ReactNode;\n /** Accessible name for the table. Rendered as a visually hidden `<caption>`. */\n caption?: ReactNode;\n /** Scroll this row into view whenever it changes. */\n scrollToIndex?: number;\n}\n\n/** Resolve a column's alignment to its CSS module class. */\nfunction alignClass(align: TableAlign | undefined): string | undefined {\n if (align === \"right\") return styles.alignRight;\n if (align === \"center\") return styles.alignCenter;\n return undefined;\n}\n\n/**\n * A table that stays responsive at 10k+ rows by rendering only the visible window.\n *\n * `Table` renders every row it is given and `DataTable` paginates to keep that\n * count small; neither has an answer for \"show me all 40 000 rows in one\n * scrollable grid\". This does, at the cost of one constraint: **`rowHeight` must\n * be uniform**, since mapping a scroll offset to a row index is what makes the\n * window computable without measuring anything.\n *\n * It stays a real `<table>`. The window is produced by two spacer rows — one\n * above the visible slice, one below — instead of absolutely positioning rows.\n * That is deliberate: `position: absolute` on `<tr>` collapses table layout, so\n * every column width would have to be computed by hand, and the element would\n * stop being a table for assistive technology. With spacer rows the browser keeps\n * doing column layout and screen readers keep announcing a grid.\n *\n * Because only a slice is in the DOM, `aria-rowcount` on the table and\n * `aria-rowindex` on each row carry the real numbers — without them a screen\n * reader announces \"row 3 of 20\" while the user is on row 5003 of 40 000.\n *\n * @example\n * <VirtualTable\n * data={rows}\n * columns={[\n * { key: \"id\", header: \"#\", width: 80, sortable: true },\n * { key: \"name\", header: \"Nome\", width: 240, sortable: true },\n * { key: \"total\", header: \"Total\", align: \"right\", width: 120, sortable: true },\n * ]}\n * rowHeight={40}\n * height={480}\n * rowKey={(row) => row.id}\n * />\n */\nexport function VirtualTable<T>({\n data,\n columns,\n rowHeight,\n height,\n overscan = 4,\n rowKey,\n initialSort,\n onRowClick,\n emptyMessage = \"Nenhum registro encontrado.\",\n caption,\n scrollToIndex,\n className,\n ...rest\n}: VirtualTableProps<T>) {\n const scrollRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n const [sort, setSort] = useState<VirtualTableSort<T> | null>(initialSort ?? null);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element || scrollToIndex == null) return;\n element.scrollTop = Math.max(0, Math.min(scrollToIndex, data.length - 1)) * rowHeight;\n }, [scrollToIndex, rowHeight, data.length]);\n\n const sorted = useMemo<T[]>(() => {\n if (!sort) return data;\n const factor = sort.direction === \"asc\" ? 1 : -1;\n return [...data].sort((a, b) => compareValues(a[sort.key], b[sort.key]) * factor);\n }, [data, sort]);\n\n const start = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan);\n const windowSize = Math.ceil(viewport / rowHeight) + overscan * 2;\n const end = Math.min(sorted.length, start + windowSize);\n const slice = sorted.slice(start, end);\n\n /**\n * Advance a column through asc → desc → unsorted, and jump back to the top.\n *\n * The scroll reset happens here rather than in an effect keyed on the sort\n * state for two reasons: this is the actual event that invalidates the offset\n * (keeping it would leave the user at the same pixel of a different dataset,\n * which reads as the table having jumped somewhere random), and an effect would\n * also fire on mount — clobbering an initial `scrollToIndex`.\n */\n const toggleSort = useCallback((key: keyof T): void => {\n setSort((current) => {\n if (!current || current.key !== key) return { key, direction: \"asc\" };\n if (current.direction === \"asc\") return { key, direction: \"desc\" };\n return null;\n });\n const element = scrollRef.current;\n if (element) element.scrollTop = 0;\n setScrollTop(0);\n }, []);\n\n return (\n <div\n ref={scrollRef}\n className={cn(styles.scroll, className)}\n style={{ height }}\n onScroll={(event) => setScrollTop(event.currentTarget.scrollTop)}\n {...rest}\n >\n <table className={styles.table} aria-rowcount={sorted.length}>\n {caption ? <caption className={styles.caption}>{caption}</caption> : null}\n <thead className={styles.head}>\n <tr>\n {columns.map((column) => {\n const isSorted = sort?.key === column.key;\n return (\n <th\n key={String(column.key)}\n scope=\"col\"\n className={cn(styles.th, alignClass(column.align))}\n style={{ width: column.width }}\n aria-sort={\n isSorted\n ? sort?.direction === \"asc\"\n ? \"ascending\"\n : \"descending\"\n : column.sortable\n ? \"none\"\n : undefined\n }\n >\n {column.sortable ? (\n <button\n type=\"button\"\n className={styles.sortButton}\n onClick={() => toggleSort(column.key)}\n >\n {column.header}\n <span className={styles.sortIndicator} aria-hidden>\n {isSorted\n ? sort?.direction === \"asc\"\n ? \"▲\"\n : \"▼\"\n : \"↕\"}\n </span>\n </button>\n ) : (\n column.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {sorted.length === 0 ? (\n <tr>\n <td className={styles.emptyRow} colSpan={columns.length}>\n {emptyMessage}\n </td>\n </tr>\n ) : (\n <>\n {start > 0 && <tr aria-hidden style={{ height: start * rowHeight }} />}\n {slice.map((row, offset) => {\n const index = start + offset;\n return (\n <tr\n key={rowKey ? rowKey(row, index) : index}\n aria-rowindex={index + 1}\n className={cn(styles.tr, onRowClick && styles.clickable)}\n style={{ height: rowHeight }}\n tabIndex={onRowClick ? 0 : undefined}\n onClick={\n onRowClick ? () => onRowClick(row, index) : undefined\n }\n onKeyDown={\n onRowClick\n ? (event) => {\n if (\n event.key === \"Enter\" ||\n event.key === \" \"\n ) {\n event.preventDefault();\n onRowClick(row, index);\n }\n }\n : undefined\n }\n >\n {columns.map((column) => (\n <td\n key={String(column.key)}\n className={cn(styles.td, alignClass(column.align))}\n style={{ width: column.width }}\n >\n {column.render\n ? column.render(row, index)\n : ((row[column.key] as ReactNode) ?? null)}\n </td>\n ))}\n </tr>\n );\n })}\n {end < sorted.length && (\n <tr\n aria-hidden\n style={{ height: (sorted.length - end) * rowHeight }}\n />\n )}\n </>\n )}\n </tbody>\n </table>\n </div>\n );\n}\n"],"mappings":"+KA8EA,SAAS,EAAW,EAAmD,CACnE,GAAI,IAAU,QAAS,OAAO,EAAA,QAAO,WACrC,GAAI,IAAU,SAAU,OAAO,EAAA,QAAO,WAE1C,CAmCA,SAAgB,EAAgB,CAC5B,OACA,UACA,YACA,SACA,WAAW,EACX,SACA,cACA,aACA,eAAe,8BACf,UACA,gBACA,YACA,GAAG,GACkB,CACrB,IAAM,GAAA,EAAA,EAAA,OAAA,CAAmC,IAAI,EACvC,CAAC,EAAW,IAAA,E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,CAAA,CAEP,CAAA,CAAA,CAEH,CAAA,CACJ,GACN,CAAA,CAEb"}
1
+ {"version":3,"file":"VirtualTable.cjs","names":[],"sources":["../../../src/components/VirtualTable/VirtualTable.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count — windowing needs its own measurements\n * (rowHeight, height, overscan, scrollToIndex) on top of everything a table already\n * takes (data, columns, rowKey, initialSort, onRowClick, emptyMessage, caption). The\n * caption is not optional chrome — a virtualised grid without one is unreadable to a\n * screen reader.\n */\nimport {\n type HTMLAttributes,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { cn } from \"@/utils/cn\";\nimport { compareValues } from \"@/utils/compare-values\";\n\nimport type { TableAlign } from \"../Table\";\nimport styles from \"./VirtualTable.module.css\";\n\nexport type VirtualTableSortDirection = \"asc\" | \"desc\";\n\nexport interface VirtualTableSort<T> {\n key: keyof T;\n direction: VirtualTableSortDirection;\n}\n\nexport interface VirtualTableColumn<T> {\n /** Property of the row this column reads from. Doubles as the cell key. */\n key: keyof T;\n /** Column heading. */\n header: ReactNode;\n /** Custom cell renderer. Defaults to `row[key]`. */\n render?: (row: T, index: number) => ReactNode;\n /** Enable click-to-sort on this column's header. */\n sortable?: boolean;\n /** Text alignment. */\n align?: TableAlign;\n /**\n * Column width. Recommended for every column: virtualized rows enter and\n * leave the DOM as you scroll, so letting the browser auto-size columns from\n * whatever is currently rendered makes them jump mid-scroll.\n */\n width?: string | number;\n}\n\nexport interface VirtualTableProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Full dataset. Every row is accounted for; only the visible ones render. */\n data: T[];\n /** Column definitions. */\n columns: VirtualTableColumn<T>[];\n /**\n * Row height in px. Must be uniform and must match what the CSS produces,\n * because it is what maps scroll offset to row index.\n */\n rowHeight: number;\n /** Height of the scroll viewport — a number of px or any CSS length. */\n height: number | string;\n /** Rows rendered above and below the viewport. Default `4`. */\n overscan?: number;\n /** Stable key extractor. Defaults to the row's index in `data`. */\n rowKey?: (row: T, index: number) => string | number;\n /** Sort applied before any header interaction. */\n initialSort?: VirtualTableSort<T>;\n /** Called when a row is activated by click, `Enter` or `Space`. */\n onRowClick?: (row: T, index: number) => void;\n /** Content shown when `data` is empty. */\n emptyMessage?: ReactNode;\n /** Accessible name for the table. Rendered as a visually hidden `<caption>`. */\n caption?: ReactNode;\n /** Scroll this row into view whenever it changes. */\n scrollToIndex?: number;\n}\n\n/** Resolve a column's alignment to its CSS module class. */\nfunction alignClass(align: TableAlign | undefined): string | undefined {\n if (align === \"right\") return styles.alignRight;\n if (align === \"center\") return styles.alignCenter;\n return undefined;\n}\n\n/**\n * A table that stays responsive at 10k+ rows by rendering only the visible window.\n *\n * `Table` renders every row it is given and `DataTable` paginates to keep that\n * count small; neither has an answer for \"show me all 40 000 rows in one\n * scrollable grid\". This does, at the cost of one constraint: **`rowHeight` must\n * be uniform**, since mapping a scroll offset to a row index is what makes the\n * window computable without measuring anything.\n *\n * It stays a real `<table>`. The window is produced by two spacer rows — one\n * above the visible slice, one below — instead of absolutely positioning rows.\n * That is deliberate: `position: absolute` on `<tr>` collapses table layout, so\n * every column width would have to be computed by hand, and the element would\n * stop being a table for assistive technology. With spacer rows the browser keeps\n * doing column layout and screen readers keep announcing a grid.\n *\n * Because only a slice is in the DOM, `aria-rowcount` on the table and\n * `aria-rowindex` on each row carry the real numbers — without them a screen\n * reader announces \"row 3 of 20\" while the user is on row 5003 of 40 000.\n *\n * @example\n * <VirtualTable\n * data={rows}\n * columns={[\n * { key: \"id\", header: \"#\", width: 80, sortable: true },\n * { key: \"name\", header: \"Nome\", width: 240, sortable: true },\n * { key: \"total\", header: \"Total\", align: \"right\", width: 120, sortable: true },\n * ]}\n * rowHeight={40}\n * height={480}\n * rowKey={(row) => row.id}\n * />\n */\nexport function VirtualTable<T>({\n data,\n columns,\n rowHeight,\n height,\n overscan = 4,\n rowKey,\n initialSort,\n onRowClick,\n emptyMessage = \"Nenhum registro encontrado.\",\n caption,\n scrollToIndex,\n className,\n ...rest\n}: VirtualTableProps<T>) {\n const scrollRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n const [sort, setSort] = useState<VirtualTableSort<T> | null>(initialSort ?? null);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element || scrollToIndex == null) return;\n element.scrollTop = Math.max(0, Math.min(scrollToIndex, data.length - 1)) * rowHeight;\n }, [scrollToIndex, rowHeight, data.length]);\n\n const sorted = useMemo<T[]>(() => {\n if (!sort) return data;\n const factor = sort.direction === \"asc\" ? 1 : -1;\n return [...data].sort((a, b) => compareValues(a[sort.key], b[sort.key]) * factor);\n }, [data, sort]);\n\n const start = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan);\n const windowSize = Math.ceil(viewport / rowHeight) + overscan * 2;\n const end = Math.min(sorted.length, start + windowSize);\n const slice = sorted.slice(start, end);\n\n /**\n * Advance a column through asc → desc → unsorted, and jump back to the top.\n *\n * The scroll reset happens here rather than in an effect keyed on the sort\n * state for two reasons: this is the actual event that invalidates the offset\n * (keeping it would leave the user at the same pixel of a different dataset,\n * which reads as the table having jumped somewhere random), and an effect would\n * also fire on mount — clobbering an initial `scrollToIndex`.\n */\n const toggleSort = useCallback((key: keyof T): void => {\n setSort((current) => {\n if (!current || current.key !== key) return { key, direction: \"asc\" };\n if (current.direction === \"asc\") return { key, direction: \"desc\" };\n return null;\n });\n const element = scrollRef.current;\n if (element) element.scrollTop = 0;\n setScrollTop(0);\n }, []);\n\n return (\n <div\n ref={scrollRef}\n className={cn(styles.scroll, className)}\n style={{ height }}\n onScroll={(event) => setScrollTop(event.currentTarget.scrollTop)}\n {...rest}\n >\n <table className={styles.table} aria-rowcount={sorted.length}>\n {caption ? <caption className={styles.caption}>{caption}</caption> : null}\n <thead className={styles.head}>\n <tr>\n {columns.map((column) => {\n const isSorted = sort?.key === column.key;\n return (\n <th\n key={String(column.key)}\n scope=\"col\"\n className={cn(styles.th, alignClass(column.align))}\n style={{ width: column.width }}\n aria-sort={\n isSorted\n ? sort?.direction === \"asc\"\n ? \"ascending\"\n : \"descending\"\n : column.sortable\n ? \"none\"\n : undefined\n }\n >\n {column.sortable ? (\n <button\n type=\"button\"\n className={styles.sortButton}\n onClick={() => toggleSort(column.key)}\n >\n {column.header}\n <span className={styles.sortIndicator} aria-hidden>\n {isSorted\n ? sort?.direction === \"asc\"\n ? \"▲\"\n : \"▼\"\n : \"↕\"}\n </span>\n </button>\n ) : (\n column.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {sorted.length === 0 ? (\n <tr>\n <td className={styles.emptyRow} colSpan={columns.length}>\n {emptyMessage}\n </td>\n </tr>\n ) : (\n <>\n {start > 0 && <tr aria-hidden style={{ height: start * rowHeight }} />}\n {slice.map((row, offset) => {\n const index = start + offset;\n return (\n <tr\n key={rowKey ? rowKey(row, index) : index}\n aria-rowindex={index + 1}\n className={cn(styles.tr, onRowClick && styles.clickable)}\n style={{ height: rowHeight }}\n tabIndex={onRowClick ? 0 : undefined}\n onClick={\n onRowClick ? () => onRowClick(row, index) : undefined\n }\n onKeyDown={\n onRowClick\n ? (event) => {\n if (\n event.key === \"Enter\" ||\n event.key === \" \"\n ) {\n event.preventDefault();\n onRowClick(row, index);\n }\n }\n : undefined\n }\n >\n {columns.map((column) => (\n <td\n key={String(column.key)}\n className={cn(styles.td, alignClass(column.align))}\n style={{ width: column.width }}\n >\n {column.render\n ? column.render(row, index)\n : ((row[column.key] as ReactNode) ?? null)}\n </td>\n ))}\n </tr>\n );\n })}\n {end < sorted.length && (\n <tr\n aria-hidden\n style={{ height: (sorted.length - end) * rowHeight }}\n />\n )}\n </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,EAAA,IAAA,CAAC,KAAD,CAEI,UAAW,EAAA,GAAG,EAAA,QAAO,GAAI,EAAW,EAAO,KAAK,CAAC,EACjD,MAAO,CAAE,MAAO,EAAO,KAAM,EAE5B,SAAA,EAAO,OACF,EAAO,OAAO,EAAK,CAAK,EACtB,EAAI,EAAO,MAAsB,IACzC,EAPK,OAAO,EAAO,GAAG,CAOtB,CACP,CACD,EAjCK,EAAS,EAAO,EAAK,CAAK,EAAI,CAiCnC,CAEZ,CAAC,EACA,EAAM,EAAO,SACV,EAAA,EAAA,IAAA,CAAC,KAAD,CACI,cAAA,GACA,MAAO,CAAE,QAAS,EAAO,OAAS,GAAO,CAAU,CACtD,CAAA,CAEP,CAAA,CAAA,CAEH,CAAA,CACJ,GACN,CAAA,CAEb"}
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualTable.js","names":[],"sources":["../../../src/components/VirtualTable/VirtualTable.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count — windowing needs its own measurements\n * (rowHeight, height, overscan, scrollToIndex) on top of everything a table already\n * takes (data, columns, rowKey, initialSort, onRowClick, emptyMessage, caption). The\n * caption is not optional chrome — a virtualised grid without one is unreadable to a\n * screen reader.\n */\nimport {\n type HTMLAttributes,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { cn } from \"@/utils/cn\";\nimport { compareValues } from \"@/utils/compare-values\";\n\nimport type { TableAlign } from \"../Table\";\nimport styles from \"./VirtualTable.module.css\";\n\nexport type VirtualTableSortDirection = \"asc\" | \"desc\";\n\nexport interface VirtualTableSort<T> {\n key: keyof T;\n direction: VirtualTableSortDirection;\n}\n\nexport interface VirtualTableColumn<T> {\n /** Property of the row this column reads from. Doubles as the cell key. */\n key: keyof T;\n /** Column heading. */\n header: ReactNode;\n /** Custom cell renderer. Defaults to `row[key]`. */\n render?: (row: T, index: number) => ReactNode;\n /** Enable click-to-sort on this column's header. */\n sortable?: boolean;\n /** Text alignment. */\n align?: TableAlign;\n /**\n * Column width. Recommended for every column: virtualized rows enter and\n * leave the DOM as you scroll, so letting the browser auto-size columns from\n * whatever is currently rendered makes them jump mid-scroll.\n */\n width?: string | number;\n}\n\nexport interface VirtualTableProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Full dataset. Every row is accounted for; only the visible ones render. */\n data: T[];\n /** Column definitions. */\n columns: VirtualTableColumn<T>[];\n /**\n * Row height in px. Must be uniform and must match what the CSS produces,\n * because it is what maps scroll offset to row index.\n */\n rowHeight: number;\n /** Height of the scroll viewport — a number of px or any CSS length. */\n height: number | string;\n /** Rows rendered above and below the viewport. Default `4`. */\n overscan?: number;\n /** Stable key extractor. Defaults to the row's index in `data`. */\n rowKey?: (row: T, index: number) => string | number;\n /** Sort applied before any header interaction. */\n initialSort?: VirtualTableSort<T>;\n /** Called when a row is activated by click, `Enter` or `Space`. */\n onRowClick?: (row: T, index: number) => void;\n /** Content shown when `data` is empty. */\n emptyMessage?: ReactNode;\n /** Accessible name for the table. Rendered as a visually hidden `<caption>`. */\n caption?: ReactNode;\n /** Scroll this row into view whenever it changes. */\n scrollToIndex?: number;\n}\n\n/** Resolve a column's alignment to its CSS module class. */\nfunction alignClass(align: TableAlign | undefined): string | undefined {\n if (align === \"right\") return styles.alignRight;\n if (align === \"center\") return styles.alignCenter;\n return undefined;\n}\n\n/**\n * A table that stays responsive at 10k+ rows by rendering only the visible window.\n *\n * `Table` renders every row it is given and `DataTable` paginates to keep that\n * count small; neither has an answer for \"show me all 40 000 rows in one\n * scrollable grid\". This does, at the cost of one constraint: **`rowHeight` must\n * be uniform**, since mapping a scroll offset to a row index is what makes the\n * window computable without measuring anything.\n *\n * It stays a real `<table>`. The window is produced by two spacer rows — one\n * above the visible slice, one below — instead of absolutely positioning rows.\n * That is deliberate: `position: absolute` on `<tr>` collapses table layout, so\n * every column width would have to be computed by hand, and the element would\n * stop being a table for assistive technology. With spacer rows the browser keeps\n * doing column layout and screen readers keep announcing a grid.\n *\n * Because only a slice is in the DOM, `aria-rowcount` on the table and\n * `aria-rowindex` on each row carry the real numbers — without them a screen\n * reader announces \"row 3 of 20\" while the user is on row 5003 of 40 000.\n *\n * @example\n * <VirtualTable\n * data={rows}\n * columns={[\n * { key: \"id\", header: \"#\", width: 80, sortable: true },\n * { key: \"name\", header: \"Nome\", width: 240, sortable: true },\n * { key: \"total\", header: \"Total\", align: \"right\", width: 120, sortable: true },\n * ]}\n * rowHeight={40}\n * height={480}\n * rowKey={(row) => row.id}\n * />\n */\nexport function VirtualTable<T>({\n data,\n columns,\n rowHeight,\n height,\n overscan = 4,\n rowKey,\n initialSort,\n onRowClick,\n emptyMessage = \"Nenhum registro encontrado.\",\n caption,\n scrollToIndex,\n className,\n ...rest\n}: VirtualTableProps<T>) {\n const scrollRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n const [sort, setSort] = useState<VirtualTableSort<T> | null>(initialSort ?? null);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element || scrollToIndex == null) return;\n element.scrollTop = Math.max(0, Math.min(scrollToIndex, data.length - 1)) * rowHeight;\n }, [scrollToIndex, rowHeight, data.length]);\n\n const sorted = useMemo<T[]>(() => {\n if (!sort) return data;\n const factor = sort.direction === \"asc\" ? 1 : -1;\n return [...data].sort((a, b) => compareValues(a[sort.key], b[sort.key]) * factor);\n }, [data, sort]);\n\n const start = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan);\n const windowSize = Math.ceil(viewport / rowHeight) + overscan * 2;\n const end = Math.min(sorted.length, start + windowSize);\n const slice = sorted.slice(start, end);\n\n /**\n * Advance a column through asc → desc → unsorted, and jump back to the top.\n *\n * The scroll reset happens here rather than in an effect keyed on the sort\n * state for two reasons: this is the actual event that invalidates the offset\n * (keeping it would leave the user at the same pixel of a different dataset,\n * which reads as the table having jumped somewhere random), and an effect would\n * also fire on mount — clobbering an initial `scrollToIndex`.\n */\n const toggleSort = useCallback((key: keyof T): void => {\n setSort((current) => {\n if (!current || current.key !== key) return { key, direction: \"asc\" };\n if (current.direction === \"asc\") return { key, direction: \"desc\" };\n return null;\n });\n const element = scrollRef.current;\n if (element) element.scrollTop = 0;\n setScrollTop(0);\n }, []);\n\n return (\n <div\n ref={scrollRef}\n className={cn(styles.scroll, className)}\n style={{ height }}\n onScroll={(event) => setScrollTop(event.currentTarget.scrollTop)}\n {...rest}\n >\n <table className={styles.table} aria-rowcount={sorted.length}>\n {caption ? <caption className={styles.caption}>{caption}</caption> : null}\n <thead className={styles.head}>\n <tr>\n {columns.map((column) => {\n const isSorted = sort?.key === column.key;\n return (\n <th\n key={String(column.key)}\n scope=\"col\"\n className={cn(styles.th, alignClass(column.align))}\n style={{ width: column.width }}\n aria-sort={\n isSorted\n ? sort?.direction === \"asc\"\n ? \"ascending\"\n : \"descending\"\n : column.sortable\n ? \"none\"\n : undefined\n }\n >\n {column.sortable ? (\n <button\n type=\"button\"\n className={styles.sortButton}\n onClick={() => toggleSort(column.key)}\n >\n {column.header}\n <span className={styles.sortIndicator} aria-hidden>\n {isSorted\n ? sort?.direction === \"asc\"\n ? \"▲\"\n : \"▼\"\n : \"↕\"}\n </span>\n </button>\n ) : (\n column.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {sorted.length === 0 ? (\n <tr>\n <td className={styles.emptyRow} colSpan={columns.length}>\n {emptyMessage}\n </td>\n </tr>\n ) : (\n <>\n {start > 0 && <tr aria-hidden style={{ height: start * rowHeight }} />}\n {slice.map((row, offset) => {\n const index = start + offset;\n return (\n <tr\n key={rowKey ? rowKey(row, index) : index}\n aria-rowindex={index + 1}\n className={cn(styles.tr, onRowClick && styles.clickable)}\n style={{ height: rowHeight }}\n tabIndex={onRowClick ? 0 : undefined}\n onClick={\n onRowClick ? () => onRowClick(row, index) : undefined\n }\n onKeyDown={\n onRowClick\n ? (event) => {\n if (\n event.key === \"Enter\" ||\n event.key === \" \"\n ) {\n event.preventDefault();\n onRowClick(row, index);\n }\n }\n : undefined\n }\n >\n {columns.map((column) => (\n <td\n key={String(column.key)}\n className={cn(styles.td, alignClass(column.align))}\n style={{ width: column.width }}\n >\n {column.render\n ? column.render(row, index)\n : ((row[column.key] as ReactNode) ?? null)}\n </td>\n ))}\n </tr>\n );\n })}\n {end < sorted.length && (\n <tr\n aria-hidden\n style={{ height: (sorted.length - end) * rowHeight }}\n />\n )}\n </>\n )}\n </tbody>\n </table>\n </div>\n );\n}\n"],"mappings":";;;;;;AA8EA,SAAS,EAAW,GAAmD;CACnE,IAAI,MAAU,SAAS,OAAO,EAAO;CACrC,IAAI,MAAU,UAAU,OAAO,EAAO;AAE1C;AAmCA,SAAgB,EAAgB,EAC5B,SACA,YACA,cACA,WACA,cAAW,GACX,WACA,gBACA,eACA,kBAAe,+BACf,YACA,kBACA,cACA,GAAG,KACkB;CACrB,IAAM,IAAY,EAAuB,IAAI,GACvC,CAAC,GAAW,KAAgB,EAAiB,CAAC,GAC9C,CAAC,GAAU,KAAe,EAAiB,CAAC,GAC5C,CAAC,GAAM,KAAW,EAAqC,KAAe,IAAI;CAYhF,AAVA,QAAgB;EACZ,IAAM,IAAU,EAAU;EAG1B,IAFI,CAAC,MACL,EAAY,EAAQ,YAAY,GAC5B,OAAO,iBAAmB,MAAa;EAC3C,IAAM,IAAW,IAAI,qBAAqB,EAAY,EAAQ,YAAY,CAAC;EAE3E,OADA,EAAS,QAAQ,CAAO,SACX,EAAS,WAAW;CACrC,GAAG,CAAC,CAAC,GAEL,QAAgB;EACZ,IAAM,IAAU,EAAU;EACtB,CAAC,KAAW,KAAiB,SACjC,EAAQ,YAAY,KAAK,IAAI,GAAG,KAAK,IAAI,GAAe,EAAK,SAA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AAO,MAAM;kBAE5B,EAAO,SACF,EAAO,OAAO,GAAK,CAAK,IACtB,EAAI,EAAO,QAAsB;OACzC,GAPK,OAAO,EAAO,GAAG,CAOtB,CACP;MACD,GAjCK,IAAS,EAAO,GAAK,CAAK,IAAI,CAiCnC;KAEZ,CAAC;KACA,IAAM,EAAO,UACV,kBAAC,MAAD;MACI,eAAA;MACA,OAAO,EAAE,SAAS,EAAO,SAAS,KAAO,EAAU;KACtD,CAAA;IAEP,EAAA,CAAA,EAEH,CAAA;GACJ;;CACN,CAAA;AAEb"}
1
+ {"version":3,"file":"VirtualTable.js","names":[],"sources":["../../../src/components/VirtualTable/VirtualTable.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count — windowing needs its own measurements\n * (rowHeight, height, overscan, scrollToIndex) on top of everything a table already\n * takes (data, columns, rowKey, initialSort, onRowClick, emptyMessage, caption). The\n * caption is not optional chrome — a virtualised grid without one is unreadable to a\n * screen reader.\n */\nimport {\n type HTMLAttributes,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { cn } from \"@/utils/cn\";\nimport { compareValues } from \"@/utils/compare-values\";\n\nimport type { TableAlign } from \"../Table\";\nimport styles from \"./VirtualTable.module.css\";\n\nexport type VirtualTableSortDirection = \"asc\" | \"desc\";\n\nexport interface VirtualTableSort<T> {\n key: keyof T;\n direction: VirtualTableSortDirection;\n}\n\nexport interface VirtualTableColumn<T> {\n /** Property of the row this column reads from. Doubles as the cell key. */\n key: keyof T;\n /** Column heading. */\n header: ReactNode;\n /** Custom cell renderer. Defaults to `row[key]`. */\n render?: (row: T, index: number) => ReactNode;\n /** Enable click-to-sort on this column's header. */\n sortable?: boolean;\n /** Text alignment. */\n align?: TableAlign;\n /**\n * Column width. Recommended for every column: virtualized rows enter and\n * leave the DOM as you scroll, so letting the browser auto-size columns from\n * whatever is currently rendered makes them jump mid-scroll.\n */\n width?: string | number;\n}\n\nexport interface VirtualTableProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** Full dataset. Every row is accounted for; only the visible ones render. */\n data: T[];\n /** Column definitions. */\n columns: VirtualTableColumn<T>[];\n /**\n * Row height in px. Must be uniform and must match what the CSS produces,\n * because it is what maps scroll offset to row index.\n */\n rowHeight: number;\n /** Height of the scroll viewport — a number of px or any CSS length. */\n height: number | string;\n /** Rows rendered above and below the viewport. Default `4`. */\n overscan?: number;\n /** Stable key extractor. Defaults to the row's index in `data`. */\n rowKey?: (row: T, index: number) => string | number;\n /** Sort applied before any header interaction. */\n initialSort?: VirtualTableSort<T>;\n /** Called when a row is activated by click, `Enter` or `Space`. */\n onRowClick?: (row: T, index: number) => void;\n /** Content shown when `data` is empty. */\n emptyMessage?: ReactNode;\n /** Accessible name for the table. Rendered as a visually hidden `<caption>`. */\n caption?: ReactNode;\n /** Scroll this row into view whenever it changes. */\n scrollToIndex?: number;\n}\n\n/** Resolve a column's alignment to its CSS module class. */\nfunction alignClass(align: TableAlign | undefined): string | undefined {\n if (align === \"right\") return styles.alignRight;\n if (align === \"center\") return styles.alignCenter;\n return undefined;\n}\n\n/**\n * A table that stays responsive at 10k+ rows by rendering only the visible window.\n *\n * `Table` renders every row it is given and `DataTable` paginates to keep that\n * count small; neither has an answer for \"show me all 40 000 rows in one\n * scrollable grid\". This does, at the cost of one constraint: **`rowHeight` must\n * be uniform**, since mapping a scroll offset to a row index is what makes the\n * window computable without measuring anything.\n *\n * It stays a real `<table>`. The window is produced by two spacer rows — one\n * above the visible slice, one below — instead of absolutely positioning rows.\n * That is deliberate: `position: absolute` on `<tr>` collapses table layout, so\n * every column width would have to be computed by hand, and the element would\n * stop being a table for assistive technology. With spacer rows the browser keeps\n * doing column layout and screen readers keep announcing a grid.\n *\n * Because only a slice is in the DOM, `aria-rowcount` on the table and\n * `aria-rowindex` on each row carry the real numbers — without them a screen\n * reader announces \"row 3 of 20\" while the user is on row 5003 of 40 000.\n *\n * @example\n * <VirtualTable\n * data={rows}\n * columns={[\n * { key: \"id\", header: \"#\", width: 80, sortable: true },\n * { key: \"name\", header: \"Nome\", width: 240, sortable: true },\n * { key: \"total\", header: \"Total\", align: \"right\", width: 120, sortable: true },\n * ]}\n * rowHeight={40}\n * height={480}\n * rowKey={(row) => row.id}\n * />\n */\nexport function VirtualTable<T>({\n data,\n columns,\n rowHeight,\n height,\n overscan = 4,\n rowKey,\n initialSort,\n onRowClick,\n emptyMessage = \"Nenhum registro encontrado.\",\n caption,\n scrollToIndex,\n className,\n ...rest\n}: VirtualTableProps<T>) {\n const scrollRef = useRef<HTMLDivElement>(null);\n const [scrollTop, setScrollTop] = useState<number>(0);\n const [viewport, setViewport] = useState<number>(0);\n const [sort, setSort] = useState<VirtualTableSort<T> | null>(initialSort ?? null);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element) return;\n setViewport(element.clientHeight);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => setViewport(element.clientHeight));\n observer.observe(element);\n return () => observer.disconnect();\n }, []);\n\n useEffect(() => {\n const element = scrollRef.current;\n if (!element || scrollToIndex == null) return;\n element.scrollTop = Math.max(0, Math.min(scrollToIndex, data.length - 1)) * rowHeight;\n }, [scrollToIndex, rowHeight, data.length]);\n\n const sorted = useMemo<T[]>(() => {\n if (!sort) return data;\n const factor = sort.direction === \"asc\" ? 1 : -1;\n return [...data].sort((a, b) => compareValues(a[sort.key], b[sort.key]) * factor);\n }, [data, sort]);\n\n const start = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan);\n const windowSize = Math.ceil(viewport / rowHeight) + overscan * 2;\n const end = Math.min(sorted.length, start + windowSize);\n const slice = sorted.slice(start, end);\n\n /**\n * Advance a column through asc → desc → unsorted, and jump back to the top.\n *\n * The scroll reset happens here rather than in an effect keyed on the sort\n * state for two reasons: this is the actual event that invalidates the offset\n * (keeping it would leave the user at the same pixel of a different dataset,\n * which reads as the table having jumped somewhere random), and an effect would\n * also fire on mount — clobbering an initial `scrollToIndex`.\n */\n const toggleSort = useCallback((key: keyof T): void => {\n setSort((current) => {\n if (!current || current.key !== key) return { key, direction: \"asc\" };\n if (current.direction === \"asc\") return { key, direction: \"desc\" };\n return null;\n });\n const element = scrollRef.current;\n if (element) element.scrollTop = 0;\n setScrollTop(0);\n }, []);\n\n return (\n <div\n ref={scrollRef}\n className={cn(styles.scroll, className)}\n style={{ height }}\n onScroll={(event) => setScrollTop(event.currentTarget.scrollTop)}\n {...rest}\n >\n <table className={styles.table} aria-rowcount={sorted.length}>\n {caption ? <caption className={styles.caption}>{caption}</caption> : null}\n <thead className={styles.head}>\n <tr>\n {columns.map((column) => {\n const isSorted = sort?.key === column.key;\n return (\n <th\n key={String(column.key)}\n scope=\"col\"\n className={cn(styles.th, alignClass(column.align))}\n style={{ width: column.width }}\n aria-sort={\n isSorted\n ? sort?.direction === \"asc\"\n ? \"ascending\"\n : \"descending\"\n : column.sortable\n ? \"none\"\n : undefined\n }\n >\n {column.sortable ? (\n <button\n type=\"button\"\n className={styles.sortButton}\n onClick={() => toggleSort(column.key)}\n >\n {column.header}\n <span className={styles.sortIndicator} aria-hidden>\n {isSorted\n ? sort?.direction === \"asc\"\n ? \"▲\"\n : \"▼\"\n : \"↕\"}\n </span>\n </button>\n ) : (\n column.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody>\n {sorted.length === 0 ? (\n <tr>\n <td className={styles.emptyRow} colSpan={columns.length}>\n {emptyMessage}\n </td>\n </tr>\n ) : (\n <>\n {start > 0 && <tr aria-hidden style={{ height: start * rowHeight }} />}\n {slice.map((row, offset) => {\n const index = start + offset;\n return (\n <tr\n key={rowKey ? rowKey(row, index) : index}\n aria-rowindex={index + 1}\n className={cn(styles.tr, onRowClick && styles.clickable)}\n style={{ height: rowHeight }}\n tabIndex={onRowClick ? 0 : undefined}\n onClick={\n onRowClick ? () => onRowClick(row, index) : undefined\n }\n onKeyDown={\n onRowClick\n ? (event) => {\n if (\n event.key === \"Enter\" ||\n event.key === \" \"\n ) {\n event.preventDefault();\n onRowClick(row, index);\n }\n }\n : undefined\n }\n >\n {columns.map((column) => (\n <td\n key={String(column.key)}\n className={cn(styles.td, alignClass(column.align))}\n style={{ width: column.width }}\n >\n {column.render\n ? column.render(row, index)\n : ((row[column.key] as ReactNode) ?? null)}\n </td>\n ))}\n </tr>\n );\n })}\n {end < sorted.length && (\n <tr\n aria-hidden\n style={{ height: (sorted.length - end) * rowHeight }}\n />\n )}\n </>\n )}\n </tbody>\n </table>\n </div>\n );\n}\n"],"mappings":";;;;;;AA8EA,SAAS,EAAW,GAAmD;CACnE,IAAI,MAAU,SAAS,OAAO,EAAO;CACrC,IAAI,MAAU,UAAU,OAAO,EAAO;AAE1C;AAmCA,SAAgB,EAAgB,EAC5B,SACA,YACA,cACA,WACA,cAAW,GACX,WACA,gBACA,eACA,kBAAe,+BACf,YACA,kBACA,cACA,GAAG,KACkB;CACrB,IAAM,IAAY,EAAuB,IAAI,GACvC,CAAC,GAAW,KAAgB,EAAiB,CAAC,GAC9C,CAAC,GAAU,KAAe,EAAiB,CAAC,GAC5C,CAAC,GAAM,KAAW,EAAqC,KAAe,IAAI;CAYhF,AAVA,QAAgB;EACZ,IAAM,IAAU,EAAU;EAG1B,IAFI,CAAC,MACL,EAAY,EAAQ,YAAY,GAC5B,OAAO,iBAAmB,MAAa;EAC3C,IAAM,IAAW,IAAI,qBAAqB,EAAY,EAAQ,YAAY,CAAC;EAE3E,OADA,EAAS,QAAQ,CAAO,SACX,EAAS,WAAW;CACrC,GAAG,CAAC,CAAC,GAEL,QAAgB;EACZ,IAAM,IAAU,EAAU;EACtB,CAAC,KAAW,KAAiB,SACjC,EAAQ,YAAY,KAAK,IAAI,GAAG,KAAK,IAAI,GAAe,EAAK,SAAS,CAAC,CAAC,IAAI;CAChF,GAAG;EAAC;EAAe;EAAW,EAAK;CAAM,CAAC;CAE1C,IAAM,IAAS,QAAmB;EAC9B,IAAI,CAAC,GAAM,OAAO;EAClB,IAAM,IAAS,EAAK,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,GAPK,OAAO,EAAO,GAAG,CAOtB,CACP;MACD,GAjCK,IAAS,EAAO,GAAK,CAAK,IAAI,CAiCnC;KAEZ,CAAC;KACA,IAAM,EAAO,UACV,kBAAC,MAAD;MACI,eAAA;MACA,OAAO,EAAE,SAAS,EAAO,SAAS,KAAO,EAAU;KACtD,CAAA;IAEP,EAAA,CAAA,EAEH,CAAA;GACJ;;CACN,CAAA;AAEb"}
@@ -1 +1 @@
1
- {"version":3,"file":"VisuallyHidden.cjs","names":[],"sources":["../../../src/components/VisuallyHidden/VisuallyHidden.tsx"],"sourcesContent":["import type { HTMLAttributes, JSX } from \"react\";\nimport { createElement } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./VisuallyHidden.module.css\";\n\nexport interface VisuallyHiddenProps extends HTMLAttributes<HTMLElement> {\n /** Intrinsic element to render. Defaults to \"span\". */\n as?: keyof JSX.IntrinsicElements;\n}\n\n/**\n * Render content that is hidden visually but remains available to screen\n * readers — the standard \"sr-only\" pattern. Useful for accessible labels on\n * icon-only controls.\n *\n * @example\n * <button><Icon /><VisuallyHidden>Close</VisuallyHidden></button>\n */\nexport function VisuallyHidden({\n as = \"span\",\n className,\n children,\n ...props\n}: VisuallyHiddenProps) {\n return createElement(as, { className: cn(styles.hidden, className), ...props }, children);\n}\n"],"mappings":"sGAkBA,SAAgB,EAAe,CAC3B,KAAK,OACL,YACA,WACA,GAAG,GACiB,CACpB,OAAA,EAAA,EAAA,cAAA,CAAqB,EAAI,CAAE,UAAW,EAAA,GAAG,EAAA,QAAO,OAAQ,CAAS,EAAG,GAAG,CAAM,EAAG,CAAQ,CAC5F"}
1
+ {"version":3,"file":"VisuallyHidden.cjs","names":[],"sources":["../../../src/components/VisuallyHidden/VisuallyHidden.tsx"],"sourcesContent":["import type { HTMLAttributes, JSX } from \"react\";\nimport { createElement } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./VisuallyHidden.module.css\";\n\nexport interface VisuallyHiddenProps extends HTMLAttributes<HTMLElement> {\n /** Intrinsic element to render. Defaults to \"span\". */\n as?: keyof JSX.IntrinsicElements;\n}\n\n/**\n * Render content that is hidden visually but remains available to screen\n * readers — the standard \"sr-only\" pattern. Useful for accessible labels on\n * icon-only controls.\n *\n * @example\n * <button><Icon /><VisuallyHidden>Close</VisuallyHidden></button>\n */\nexport function VisuallyHidden({\n as = \"span\",\n className,\n children,\n ...props\n}: VisuallyHiddenProps) {\n return createElement(as, { className: cn(styles.hidden, className), ...props }, children);\n}\n"],"mappings":"sGAkBA,SAAgB,EAAe,CAC3B,KAAK,OACL,YACA,WACA,GAAG,GACiB,CACpB,OAAA,EAAO,EAAA,cAAA,CAAc,EAAI,CAAE,UAAW,EAAA,GAAG,EAAA,QAAO,OAAQ,CAAS,EAAG,GAAG,CAAM,EAAG,CAAQ,CAC5F"}
@@ -1 +1 @@
1
- {"version":3,"file":"Wizard.cjs","names":[],"sources":["../../../src/components/Wizard/Wizard.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — steps plus the\n * controlled-or-not pair (activeIndex, defaultActiveIndex, onStepChange,\n * onComplete), the four strings it renders (nextLabel, backLabel, finishLabel,\n * optionalLabel) and the two behaviours (clickableSteps, renderActions). The labels\n * are props because a wizard's buttons are the most translated text in an app.\n */\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"../Button\";\nimport { Stepper } from \"../Stepper\";\nimport styles from \"./Wizard.module.css\";\n\n/** One step of the flow. */\nexport interface WizardStep {\n /** Stable identifier. */\n id: string;\n /** Step label shown in the indicator. */\n label: string;\n /** Optional description under the label. */\n description?: string;\n /** Step body. A function receives the flow controls, for a \"skip\" link inside the form. */\n content: ReactNode | ((controls: WizardControls) => ReactNode);\n /**\n * Gate for leaving this step forward. Return `false` (or a rejected/`false`\n * promise) to keep the user here — typically `() => form.trigger()`.\n * Async is supported: the Next button shows a pending state while it runs.\n */\n validate?: () => boolean | Promise<boolean>;\n /** Marks the step as optional, so `onComplete` can ignore it. */\n optional?: boolean;\n}\n\n/** Flow controls handed to a step body and to `renderActions`. */\nexport interface WizardControls {\n /** Zero-based index of the current step. */\n activeIndex: number;\n /** The current step. */\n step: WizardStep;\n /** `true` while a `validate` promise is pending. */\n validating: boolean;\n isFirst: boolean;\n isLast: boolean;\n /** Run the current step's `validate` and advance when it passes. */\n next: () => Promise<void>;\n /** Go back one step. No validation — going back never blocks. */\n back: () => void;\n /** Jump to an index. Forward jumps validate every step in between. */\n goTo: (index: number) => Promise<void>;\n}\n\nexport interface WizardProps {\n steps: WizardStep[];\n /** Controlled active index. */\n activeIndex?: number;\n /** Uncontrolled initial index. Default `0`. */\n defaultActiveIndex?: number;\n onStepChange?: (index: number, step: WizardStep) => void;\n /** Called when the last step passes validation. */\n onComplete?: () => void | Promise<void>;\n /** Label of the advance button. Default `\"Next\"`. */\n nextLabel?: string;\n /** Label of the back button. Default `\"Back\"`. */\n backLabel?: string;\n /** Label of the button on the last step. Default `\"Finish\"`. */\n finishLabel?: string;\n /**\n * Suffix appended to an optional step's description in the indicator.\n * Default `\"(optional)\"` — override it to localize, since the SDK ships no\n * translation for component-internal copy.\n */\n optionalLabel?: string;\n /**\n * Allow clicking the indicator to jump. Default `false` — a wizard exists\n * because order matters, and a free jump skips the gates.\n */\n clickableSteps?: boolean;\n /** Replace the default button row. */\n renderActions?: (controls: WizardControls) => ReactNode;\n className?: string;\n}\n\n/**\n * Multi-step flow: step indicator, one body at a time, and navigation that\n * respects per-step validation.\n *\n * `Stepper` draws the indicator; this owns the part every app was rewriting — the\n * active index, the async gate before advancing, the disabled/pending buttons and\n * the completion call.\n *\n * Only the active step's body is mounted. Uncommitted input in a step you leave is\n * therefore lost unless the state lives outside (react-hook-form's `FormProvider`,\n * a store, a parent `useState`) — which is the right place for it anyway, since\n * the last step usually needs to submit everything at once.\n *\n * @example\n * ```tsx\n * const form = useZodForm(schema);\n *\n * <FormProvider {...form}>\n * <Wizard\n * steps={[\n * {\n * id: \"dados\",\n * label: \"Dados\",\n * validate: () => form.trigger([\"nome\", \"email\"]),\n * content: (\n * <>\n * <FormField name=\"nome\" label=\"Nome\"><Input /></FormField>\n * <FormField name=\"email\" label=\"E-mail\"><Input type=\"email\" /></FormField>\n * </>\n * ),\n * },\n * { id: \"revisao\", label: \"Revisão\", content: <Review /> },\n * ]}\n * onComplete={form.handleSubmit(onSubmit)}\n * />\n * </FormProvider>\n * ```\n */\nexport function Wizard({\n steps,\n activeIndex,\n defaultActiveIndex = 0,\n onStepChange,\n onComplete,\n nextLabel = \"Next\",\n backLabel = \"Back\",\n finishLabel = \"Finish\",\n optionalLabel = \"(optional)\",\n clickableSteps = false,\n renderActions,\n className,\n}: WizardProps) {\n const isControlled = activeIndex !== undefined;\n const [internalIndex, setInternalIndex] = useState(defaultActiveIndex);\n const [validating, setValidating] = useState(false);\n\n const current = Math.min(isControlled ? activeIndex : internalIndex, steps.length - 1);\n const step = steps[current];\n\n const moveTo = useCallback(\n (index: number): void => {\n if (!isControlled) setInternalIndex(index);\n onStepChange?.(index, steps[index]);\n },\n [isControlled, onStepChange, steps],\n );\n\n /**\n * Run a step's gate. A gate that throws counts as \"not allowed\": a `validate`\n * wired to a network check should not strand the user on a half-advanced flow\n * when the request fails.\n */\n const runValidate = useCallback(async (candidate: WizardStep): Promise<boolean> => {\n if (!candidate.validate) return true;\n setValidating(true);\n try {\n return await candidate.validate();\n } catch {\n return false;\n } finally {\n setValidating(false);\n }\n }, []);\n\n const next = useCallback(async (): Promise<void> => {\n if (!(await runValidate(step))) return;\n if (current === steps.length - 1) {\n await onComplete?.();\n return;\n }\n moveTo(current + 1);\n }, [current, moveTo, onComplete, runValidate, step, steps.length]);\n\n const back = useCallback((): void => {\n if (current > 0) moveTo(current - 1);\n }, [current, moveTo]);\n\n const goTo = useCallback(\n async (index: number): Promise<void> => {\n const target = Math.max(0, Math.min(index, steps.length - 1));\n if (target === current) return;\n if (target < current) {\n moveTo(target);\n return;\n }\n for (let i = current; i < target; i += 1) {\n if (!(await runValidate(steps[i]))) return;\n }\n moveTo(target);\n },\n [current, moveTo, runValidate, steps],\n );\n\n const controls = useMemo<WizardControls>(\n () => ({\n activeIndex: current,\n step,\n validating,\n isFirst: current === 0,\n isLast: current === steps.length - 1,\n next,\n back,\n goTo,\n }),\n [back, current, goTo, next, step, steps.length, validating],\n );\n\n const indicatorSteps = useMemo(\n () =>\n steps.map((item) => ({\n label: item.label,\n description: item.optional\n ? `${item.description ?? \"\"} ${optionalLabel}`.trim()\n : item.description,\n })),\n [optionalLabel, steps],\n );\n\n return (\n <div className={cn(styles.wizard, className)}>\n <Stepper\n steps={indicatorSteps}\n current={current}\n onStepClick={clickableSteps ? (index) => void goTo(index) : undefined}\n />\n\n <div className={styles.body} role=\"group\" aria-label={step.label}>\n {typeof step.content === \"function\" ? step.content(controls) : step.content}\n </div>\n\n {renderActions ? (\n renderActions(controls)\n ) : (\n <div className={styles.actions}>\n <Button\n variant=\"secondary\"\n onClick={back}\n disabled={controls.isFirst || validating}\n >\n {backLabel}\n </Button>\n <Button onClick={() => void next()} loading={validating}>\n {controls.isLast ? finishLabel : nextLabel}\n </Button>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":"mMAyHA,SAAgB,EAAO,CACnB,QACA,cACA,qBAAqB,EACrB,eACA,aACA,YAAY,OACZ,YAAY,OACZ,cAAc,SACd,gBAAgB,aAChB,iBAAiB,GACjB,gBACA,aACY,CACZ,IAAM,EAAe,IAAgB,IAAA,GAC/B,CAAC,EAAe,IAAA,EAAA,EAAA,SAAA,CAA6B,CAAkB,EAC/D,CAAC,EAAY,IAAA,EAAA,EAAA,SAAA,CAA0B,EAAK,EAE5C,EAAU,KAAK,IAAI,EAAe,EAAc,EAAe,EAAM,OAAS,CAAC,EAC/E,EAAO,EAAM,GAEb,GAAA,EAAA,EAAA,YAAA,CACD,GAAwB,CAChB,GAAc,EAAiB,CAAK,EACzC,IAAe,EAAO,EAAM,EAA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,MAAO,EAAK,MACZ,YAAa,EAAK,SACZ,GAAG,EAAK,aAAe,GAAG,GAAG,IAAgB,KAAK,EAClD,EAAK,WACf,EAAE,EACN,CAAC,EAAe,CAAK,CACzB,EAEA,OACI,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,GAAG,EAAA,QAAO,OAAQ,CAAS,WAA3C,EACI,EAAA,EAAA,IAAA,CAAC,EAAA,QAAD,CACI,MAAO,EACE,UACT,YAAa,EAAkB,GAAU,KAAK,EAAK,CAAK,EAAI,IAAA,EAC/D,CAAA,GAED,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,KAAM,KAAK,QAAQ,aAAY,EAAK,eACtD,OAAO,EAAK,SAAY,WAAa,EAAK,QAAQ,CAAQ,EAAI,EAAK,OACnE,CAAA,EAEJ,EACG,EAAc,CAAQ,GAEtB,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,iBAAvB,EACI,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CACI,QAAQ,YACR,QAAS,EACT,SAAU,EAAS,SAAW,WAE7B,CACG,CAAA,GACR,EAAA,EAAA,IAAA,CAAC,EAAA,OAAD,CAAQ,YAAe,KAAK,EAAK,EAAG,QAAS,WACxC,EAAS,OAAS,EAAc,CAC7B,CAAA,CACP,GAER,GAEb"}
1
+ {"version":3,"file":"Wizard.cjs","names":[],"sources":["../../../src/components/Wizard/Wizard.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — steps plus the\n * controlled-or-not pair (activeIndex, defaultActiveIndex, onStepChange,\n * onComplete), the four strings it renders (nextLabel, backLabel, finishLabel,\n * optionalLabel) and the two behaviours (clickableSteps, renderActions). The labels\n * are props because a wizard's buttons are the most translated text in an app.\n */\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"../Button\";\nimport { Stepper } from \"../Stepper\";\nimport styles from \"./Wizard.module.css\";\n\n/** One step of the flow. */\nexport interface WizardStep {\n /** Stable identifier. */\n id: string;\n /** Step label shown in the indicator. */\n label: string;\n /** Optional description under the label. */\n description?: string;\n /** Step body. A function receives the flow controls, for a \"skip\" link inside the form. */\n content: ReactNode | ((controls: WizardControls) => ReactNode);\n /**\n * Gate for leaving this step forward. Return `false` (or a rejected/`false`\n * promise) to keep the user here — typically `() => form.trigger()`.\n * Async is supported: the Next button shows a pending state while it runs.\n */\n validate?: () => boolean | Promise<boolean>;\n /** Marks the step as optional, so `onComplete` can ignore it. */\n optional?: boolean;\n}\n\n/** Flow controls handed to a step body and to `renderActions`. */\nexport interface WizardControls {\n /** Zero-based index of the current step. */\n activeIndex: number;\n /** The current step. */\n step: WizardStep;\n /** `true` while a `validate` promise is pending. */\n validating: boolean;\n isFirst: boolean;\n isLast: boolean;\n /** Run the current step's `validate` and advance when it passes. */\n next: () => Promise<void>;\n /** Go back one step. No validation — going back never blocks. */\n back: () => void;\n /** Jump to an index. Forward jumps validate every step in between. */\n goTo: (index: number) => Promise<void>;\n}\n\nexport interface WizardProps {\n steps: WizardStep[];\n /** Controlled active index. */\n activeIndex?: number;\n /** Uncontrolled initial index. Default `0`. */\n defaultActiveIndex?: number;\n onStepChange?: (index: number, step: WizardStep) => void;\n /** Called when the last step passes validation. */\n onComplete?: () => void | Promise<void>;\n /** Label of the advance button. Default `\"Next\"`. */\n nextLabel?: string;\n /** Label of the back button. Default `\"Back\"`. */\n backLabel?: string;\n /** Label of the button on the last step. Default `\"Finish\"`. */\n finishLabel?: string;\n /**\n * Suffix appended to an optional step's description in the indicator.\n * Default `\"(optional)\"` — override it to localize, since the SDK ships no\n * translation for component-internal copy.\n */\n optionalLabel?: string;\n /**\n * Allow clicking the indicator to jump. Default `false` — a wizard exists\n * because order matters, and a free jump skips the gates.\n */\n clickableSteps?: boolean;\n /** Replace the default button row. */\n renderActions?: (controls: WizardControls) => ReactNode;\n className?: string;\n}\n\n/**\n * Multi-step flow: step indicator, one body at a time, and navigation that\n * respects per-step validation.\n *\n * `Stepper` draws the indicator; this owns the part every app was rewriting — the\n * active index, the async gate before advancing, the disabled/pending buttons and\n * the completion call.\n *\n * Only the active step's body is mounted. Uncommitted input in a step you leave is\n * therefore lost unless the state lives outside (react-hook-form's `FormProvider`,\n * a store, a parent `useState`) — which is the right place for it anyway, since\n * the last step usually needs to submit everything at once.\n *\n * @example\n * ```tsx\n * const form = useZodForm(schema);\n *\n * <FormProvider {...form}>\n * <Wizard\n * steps={[\n * {\n * id: \"dados\",\n * label: \"Dados\",\n * validate: () => form.trigger([\"nome\", \"email\"]),\n * content: (\n * <>\n * <FormField name=\"nome\" label=\"Nome\"><Input /></FormField>\n * <FormField name=\"email\" label=\"E-mail\"><Input type=\"email\" /></FormField>\n * </>\n * ),\n * },\n * { id: \"revisao\", label: \"Revisão\", content: <Review /> },\n * ]}\n * onComplete={form.handleSubmit(onSubmit)}\n * />\n * </FormProvider>\n * ```\n */\nexport function Wizard({\n steps,\n activeIndex,\n defaultActiveIndex = 0,\n onStepChange,\n onComplete,\n nextLabel = \"Next\",\n backLabel = \"Back\",\n finishLabel = \"Finish\",\n optionalLabel = \"(optional)\",\n clickableSteps = false,\n renderActions,\n className,\n}: WizardProps) {\n const isControlled = activeIndex !== undefined;\n const [internalIndex, setInternalIndex] = useState(defaultActiveIndex);\n const [validating, setValidating] = useState(false);\n\n const current = Math.min(isControlled ? activeIndex : internalIndex, steps.length - 1);\n const step = steps[current];\n\n const moveTo = useCallback(\n (index: number): void => {\n if (!isControlled) setInternalIndex(index);\n onStepChange?.(index, steps[index]);\n },\n [isControlled, onStepChange, steps],\n );\n\n /**\n * Run a step's gate. A gate that throws counts as \"not allowed\": a `validate`\n * wired to a network check should not strand the user on a half-advanced flow\n * when the request fails.\n */\n const runValidate = useCallback(async (candidate: WizardStep): Promise<boolean> => {\n if (!candidate.validate) return true;\n setValidating(true);\n try {\n return await candidate.validate();\n } catch {\n return false;\n } finally {\n setValidating(false);\n }\n }, []);\n\n const next = useCallback(async (): Promise<void> => {\n if (!(await runValidate(step))) return;\n if (current === steps.length - 1) {\n await onComplete?.();\n return;\n }\n moveTo(current + 1);\n }, [current, moveTo, onComplete, runValidate, step, steps.length]);\n\n const back = useCallback((): void => {\n if (current > 0) moveTo(current - 1);\n }, [current, moveTo]);\n\n const goTo = useCallback(\n async (index: number): Promise<void> => {\n const target = Math.max(0, Math.min(index, steps.length - 1));\n if (target === current) return;\n if (target < current) {\n moveTo(target);\n return;\n }\n for (let i = current; i < target; i += 1) {\n if (!(await runValidate(steps[i]))) return;\n }\n moveTo(target);\n },\n [current, moveTo, runValidate, steps],\n );\n\n const controls = useMemo<WizardControls>(\n () => ({\n activeIndex: current,\n step,\n validating,\n isFirst: current === 0,\n isLast: current === steps.length - 1,\n next,\n back,\n goTo,\n }),\n [back, current, goTo, next, step, steps.length, validating],\n );\n\n const indicatorSteps = useMemo(\n () =>\n steps.map((item) => ({\n label: item.label,\n description: item.optional\n ? `${item.description ?? \"\"} ${optionalLabel}`.trim()\n : item.description,\n })),\n [optionalLabel, steps],\n );\n\n return (\n <div className={cn(styles.wizard, className)}>\n <Stepper\n steps={indicatorSteps}\n current={current}\n onStepClick={clickableSteps ? (index) => void goTo(index) : undefined}\n />\n\n <div className={styles.body} role=\"group\" aria-label={step.label}>\n {typeof step.content === \"function\" ? step.content(controls) : step.content}\n </div>\n\n {renderActions ? (\n renderActions(controls)\n ) : (\n <div className={styles.actions}>\n <Button\n variant=\"secondary\"\n onClick={back}\n disabled={controls.isFirst || validating}\n >\n {backLabel}\n </Button>\n <Button onClick={() => void next()} loading={validating}>\n {controls.isLast ? finishLabel : nextLabel}\n </Button>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":"mMAyHA,SAAgB,EAAO,CACnB,QACA,cACA,qBAAqB,EACrB,eACA,aACA,YAAY,OACZ,YAAY,OACZ,cAAc,SACd,gBAAgB,aAChB,iBAAiB,GACjB,gBACA,aACY,CAC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ard.js","names":[],"sources":["../../../src/components/Wizard/Wizard.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — steps plus the\n * controlled-or-not pair (activeIndex, defaultActiveIndex, onStepChange,\n * onComplete), the four strings it renders (nextLabel, backLabel, finishLabel,\n * optionalLabel) and the two behaviours (clickableSteps, renderActions). The labels\n * are props because a wizard's buttons are the most translated text in an app.\n */\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"../Button\";\nimport { Stepper } from \"../Stepper\";\nimport styles from \"./Wizard.module.css\";\n\n/** One step of the flow. */\nexport interface WizardStep {\n /** Stable identifier. */\n id: string;\n /** Step label shown in the indicator. */\n label: string;\n /** Optional description under the label. */\n description?: string;\n /** Step body. A function receives the flow controls, for a \"skip\" link inside the form. */\n content: ReactNode | ((controls: WizardControls) => ReactNode);\n /**\n * Gate for leaving this step forward. Return `false` (or a rejected/`false`\n * promise) to keep the user here — typically `() => form.trigger()`.\n * Async is supported: the Next button shows a pending state while it runs.\n */\n validate?: () => boolean | Promise<boolean>;\n /** Marks the step as optional, so `onComplete` can ignore it. */\n optional?: boolean;\n}\n\n/** Flow controls handed to a step body and to `renderActions`. */\nexport interface WizardControls {\n /** Zero-based index of the current step. */\n activeIndex: number;\n /** The current step. */\n step: WizardStep;\n /** `true` while a `validate` promise is pending. */\n validating: boolean;\n isFirst: boolean;\n isLast: boolean;\n /** Run the current step's `validate` and advance when it passes. */\n next: () => Promise<void>;\n /** Go back one step. No validation — going back never blocks. */\n back: () => void;\n /** Jump to an index. Forward jumps validate every step in between. */\n goTo: (index: number) => Promise<void>;\n}\n\nexport interface WizardProps {\n steps: WizardStep[];\n /** Controlled active index. */\n activeIndex?: number;\n /** Uncontrolled initial index. Default `0`. */\n defaultActiveIndex?: number;\n onStepChange?: (index: number, step: WizardStep) => void;\n /** Called when the last step passes validation. */\n onComplete?: () => void | Promise<void>;\n /** Label of the advance button. Default `\"Next\"`. */\n nextLabel?: string;\n /** Label of the back button. Default `\"Back\"`. */\n backLabel?: string;\n /** Label of the button on the last step. Default `\"Finish\"`. */\n finishLabel?: string;\n /**\n * Suffix appended to an optional step's description in the indicator.\n * Default `\"(optional)\"` — override it to localize, since the SDK ships no\n * translation for component-internal copy.\n */\n optionalLabel?: string;\n /**\n * Allow clicking the indicator to jump. Default `false` — a wizard exists\n * because order matters, and a free jump skips the gates.\n */\n clickableSteps?: boolean;\n /** Replace the default button row. */\n renderActions?: (controls: WizardControls) => ReactNode;\n className?: string;\n}\n\n/**\n * Multi-step flow: step indicator, one body at a time, and navigation that\n * respects per-step validation.\n *\n * `Stepper` draws the indicator; this owns the part every app was rewriting — the\n * active index, the async gate before advancing, the disabled/pending buttons and\n * the completion call.\n *\n * Only the active step's body is mounted. Uncommitted input in a step you leave is\n * therefore lost unless the state lives outside (react-hook-form's `FormProvider`,\n * a store, a parent `useState`) — which is the right place for it anyway, since\n * the last step usually needs to submit everything at once.\n *\n * @example\n * ```tsx\n * const form = useZodForm(schema);\n *\n * <FormProvider {...form}>\n * <Wizard\n * steps={[\n * {\n * id: \"dados\",\n * label: \"Dados\",\n * validate: () => form.trigger([\"nome\", \"email\"]),\n * content: (\n * <>\n * <FormField name=\"nome\" label=\"Nome\"><Input /></FormField>\n * <FormField name=\"email\" label=\"E-mail\"><Input type=\"email\" /></FormField>\n * </>\n * ),\n * },\n * { id: \"revisao\", label: \"Revisão\", content: <Review /> },\n * ]}\n * onComplete={form.handleSubmit(onSubmit)}\n * />\n * </FormProvider>\n * ```\n */\nexport function Wizard({\n steps,\n activeIndex,\n defaultActiveIndex = 0,\n onStepChange,\n onComplete,\n nextLabel = \"Next\",\n backLabel = \"Back\",\n finishLabel = \"Finish\",\n optionalLabel = \"(optional)\",\n clickableSteps = false,\n renderActions,\n className,\n}: WizardProps) {\n const isControlled = activeIndex !== undefined;\n const [internalIndex, setInternalIndex] = useState(defaultActiveIndex);\n const [validating, setValidating] = useState(false);\n\n const current = Math.min(isControlled ? activeIndex : internalIndex, steps.length - 1);\n const step = steps[current];\n\n const moveTo = useCallback(\n (index: number): void => {\n if (!isControlled) setInternalIndex(index);\n onStepChange?.(index, steps[index]);\n },\n [isControlled, onStepChange, steps],\n );\n\n /**\n * Run a step's gate. A gate that throws counts as \"not allowed\": a `validate`\n * wired to a network check should not strand the user on a half-advanced flow\n * when the request fails.\n */\n const runValidate = useCallback(async (candidate: WizardStep): Promise<boolean> => {\n if (!candidate.validate) return true;\n setValidating(true);\n try {\n return await candidate.validate();\n } catch {\n return false;\n } finally {\n setValidating(false);\n }\n }, []);\n\n const next = useCallback(async (): Promise<void> => {\n if (!(await runValidate(step))) return;\n if (current === steps.length - 1) {\n await onComplete?.();\n return;\n }\n moveTo(current + 1);\n }, [current, moveTo, onComplete, runValidate, step, steps.length]);\n\n const back = useCallback((): void => {\n if (current > 0) moveTo(current - 1);\n }, [current, moveTo]);\n\n const goTo = useCallback(\n async (index: number): Promise<void> => {\n const target = Math.max(0, Math.min(index, steps.length - 1));\n if (target === current) return;\n if (target < current) {\n moveTo(target);\n return;\n }\n for (let i = current; i < target; i += 1) {\n if (!(await runValidate(steps[i]))) return;\n }\n moveTo(target);\n },\n [current, moveTo, runValidate, steps],\n );\n\n const controls = useMemo<WizardControls>(\n () => ({\n activeIndex: current,\n step,\n validating,\n isFirst: current === 0,\n isLast: current === steps.length - 1,\n next,\n back,\n goTo,\n }),\n [back, current, goTo, next, step, steps.length, validating],\n );\n\n const indicatorSteps = useMemo(\n () =>\n steps.map((item) => ({\n label: item.label,\n description: item.optional\n ? `${item.description ?? \"\"} ${optionalLabel}`.trim()\n : item.description,\n })),\n [optionalLabel, steps],\n );\n\n return (\n <div className={cn(styles.wizard, className)}>\n <Stepper\n steps={indicatorSteps}\n current={current}\n onStepClick={clickableSteps ? (index) => void goTo(index) : undefined}\n />\n\n <div className={styles.body} role=\"group\" aria-label={step.label}>\n {typeof step.content === \"function\" ? step.content(controls) : step.content}\n </div>\n\n {renderActions ? (\n renderActions(controls)\n ) : (\n <div className={styles.actions}>\n <Button\n variant=\"secondary\"\n onClick={back}\n disabled={controls.isFirst || validating}\n >\n {backLabel}\n </Button>\n <Button onClick={() => void next()} loading={validating}>\n {controls.isLast ? finishLabel : nextLabel}\n </Button>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAyHA,SAAgB,EAAO,EACnB,UACA,gBACA,wBAAqB,GACrB,iBACA,eACA,eAAY,QACZ,eAAY,QACZ,iBAAc,UACd,mBAAgB,cAChB,oBAAiB,IACjB,kBACA,gBACY;CACZ,IAAM,IAAe,MAAgB,KAAA,GAC/B,CAAC,GAAe,KAAoB,EAAS,CAAkB,GAC/D,CAAC,GAAY,KAAiB,EAAS,EAAK,GAE5C,IAAU,KAAK,IAAI,IAAe,IAAc,GAAe,EAAM,SAAS,CAAC,GAC/E,IAAO,EAAM,IAEb,IAAS,GACV,MAAwB;EAErB,AADK,KAAc,EAAiB,CAAK,GACzC,IAAe,GAAO,EAAM,EAAM;CACtC,GACA;EAAC;EAAc;EAAc;CAAK,CACtC,GAOM,IAAc,EAAY,OAAO,MAA4C;EAC/E,IAAI,CAAC,EAAU,UAAU,OAAO;EAChC,EAAc,EAAI;EAClB,IAAI;GACA,OAAO,MAAM,EAAU,SAAS;EACpC,QAAQ;GACJ,OAAO;EACX,UAAU;GACN,EAAc,EAAK;EACvB;CACJ,GAAG,CAAC,CAAC,GAEC,IAAO,EAAY,YAA2B;EAC1C,UAAM,EAAY,CAAI,GAC5B;OAAI,MAAY,EAAM,SAAS,GAAG;IAC9B,MAAM,IAAa;IACnB;GACJ;GACA,EAAO,IAAU,CAAC;EADlB;CAEJ,GAAG;EAAC;EAAS;EAAQ;EAAY;EAAa;EAAM,EAAM;CAAM,CAAC,GAE3D,IAAO,QAAwB;EACjC,AAAI,IAAU,KAAG,EAAO,IAAU,CAAC;CACvC,GAAG,CAAC,GAAS,CAAM,CAAC,GAEd,IAAO,EACT,OAAO,MA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;;AAEb"}
1
+ {"version":3,"file":"Wizard.js","names":[],"sources":["../../../src/components/Wizard/Wizard.tsx"],"sourcesContent":["/**\n * @tempest-limits file-lines, props-count, function-lines — steps plus the\n * controlled-or-not pair (activeIndex, defaultActiveIndex, onStepChange,\n * onComplete), the four strings it renders (nextLabel, backLabel, finishLabel,\n * optionalLabel) and the two behaviours (clickableSteps, renderActions). The labels\n * are props because a wizard's buttons are the most translated text in an app.\n */\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport { Button } from \"../Button\";\nimport { Stepper } from \"../Stepper\";\nimport styles from \"./Wizard.module.css\";\n\n/** One step of the flow. */\nexport interface WizardStep {\n /** Stable identifier. */\n id: string;\n /** Step label shown in the indicator. */\n label: string;\n /** Optional description under the label. */\n description?: string;\n /** Step body. A function receives the flow controls, for a \"skip\" link inside the form. */\n content: ReactNode | ((controls: WizardControls) => ReactNode);\n /**\n * Gate for leaving this step forward. Return `false` (or a rejected/`false`\n * promise) to keep the user here — typically `() => form.trigger()`.\n * Async is supported: the Next button shows a pending state while it runs.\n */\n validate?: () => boolean | Promise<boolean>;\n /** Marks the step as optional, so `onComplete` can ignore it. */\n optional?: boolean;\n}\n\n/** Flow controls handed to a step body and to `renderActions`. */\nexport interface WizardControls {\n /** Zero-based index of the current step. */\n activeIndex: number;\n /** The current step. */\n step: WizardStep;\n /** `true` while a `validate` promise is pending. */\n validating: boolean;\n isFirst: boolean;\n isLast: boolean;\n /** Run the current step's `validate` and advance when it passes. */\n next: () => Promise<void>;\n /** Go back one step. No validation — going back never blocks. */\n back: () => void;\n /** Jump to an index. Forward jumps validate every step in between. */\n goTo: (index: number) => Promise<void>;\n}\n\nexport interface WizardProps {\n steps: WizardStep[];\n /** Controlled active index. */\n activeIndex?: number;\n /** Uncontrolled initial index. Default `0`. */\n defaultActiveIndex?: number;\n onStepChange?: (index: number, step: WizardStep) => void;\n /** Called when the last step passes validation. */\n onComplete?: () => void | Promise<void>;\n /** Label of the advance button. Default `\"Next\"`. */\n nextLabel?: string;\n /** Label of the back button. Default `\"Back\"`. */\n backLabel?: string;\n /** Label of the button on the last step. Default `\"Finish\"`. */\n finishLabel?: string;\n /**\n * Suffix appended to an optional step's description in the indicator.\n * Default `\"(optional)\"` — override it to localize, since the SDK ships no\n * translation for component-internal copy.\n */\n optionalLabel?: string;\n /**\n * Allow clicking the indicator to jump. Default `false` — a wizard exists\n * because order matters, and a free jump skips the gates.\n */\n clickableSteps?: boolean;\n /** Replace the default button row. */\n renderActions?: (controls: WizardControls) => ReactNode;\n className?: string;\n}\n\n/**\n * Multi-step flow: step indicator, one body at a time, and navigation that\n * respects per-step validation.\n *\n * `Stepper` draws the indicator; this owns the part every app was rewriting — the\n * active index, the async gate before advancing, the disabled/pending buttons and\n * the completion call.\n *\n * Only the active step's body is mounted. Uncommitted input in a step you leave is\n * therefore lost unless the state lives outside (react-hook-form's `FormProvider`,\n * a store, a parent `useState`) — which is the right place for it anyway, since\n * the last step usually needs to submit everything at once.\n *\n * @example\n * ```tsx\n * const form = useZodForm(schema);\n *\n * <FormProvider {...form}>\n * <Wizard\n * steps={[\n * {\n * id: \"dados\",\n * label: \"Dados\",\n * validate: () => form.trigger([\"nome\", \"email\"]),\n * content: (\n * <>\n * <FormField name=\"nome\" label=\"Nome\"><Input /></FormField>\n * <FormField name=\"email\" label=\"E-mail\"><Input type=\"email\" /></FormField>\n * </>\n * ),\n * },\n * { id: \"revisao\", label: \"Revisão\", content: <Review /> },\n * ]}\n * onComplete={form.handleSubmit(onSubmit)}\n * />\n * </FormProvider>\n * ```\n */\nexport function Wizard({\n steps,\n activeIndex,\n defaultActiveIndex = 0,\n onStepChange,\n onComplete,\n nextLabel = \"Next\",\n backLabel = \"Back\",\n finishLabel = \"Finish\",\n optionalLabel = \"(optional)\",\n clickableSteps = false,\n renderActions,\n className,\n}: WizardProps) {\n const isControlled = activeIndex !== undefined;\n const [internalIndex, setInternalIndex] = useState(defaultActiveIndex);\n const [validating, setValidating] = useState(false);\n\n const current = Math.min(isControlled ? activeIndex : internalIndex, steps.length - 1);\n const step = steps[current];\n\n const moveTo = useCallback(\n (index: number): void => {\n if (!isControlled) setInternalIndex(index);\n onStepChange?.(index, steps[index]);\n },\n [isControlled, onStepChange, steps],\n );\n\n /**\n * Run a step's gate. A gate that throws counts as \"not allowed\": a `validate`\n * wired to a network check should not strand the user on a half-advanced flow\n * when the request fails.\n */\n const runValidate = useCallback(async (candidate: WizardStep): Promise<boolean> => {\n if (!candidate.validate) return true;\n setValidating(true);\n try {\n return await candidate.validate();\n } catch {\n return false;\n } finally {\n setValidating(false);\n }\n }, []);\n\n const next = useCallback(async (): Promise<void> => {\n if (!(await runValidate(step))) return;\n if (current === steps.length - 1) {\n await onComplete?.();\n return;\n }\n moveTo(current + 1);\n }, [current, moveTo, onComplete, runValidate, step, steps.length]);\n\n const back = useCallback((): void => {\n if (current > 0) moveTo(current - 1);\n }, [current, moveTo]);\n\n const goTo = useCallback(\n async (index: number): Promise<void> => {\n const target = Math.max(0, Math.min(index, steps.length - 1));\n if (target === current) return;\n if (target < current) {\n moveTo(target);\n return;\n }\n for (let i = current; i < target; i += 1) {\n if (!(await runValidate(steps[i]))) return;\n }\n moveTo(target);\n },\n [current, moveTo, runValidate, steps],\n );\n\n const controls = useMemo<WizardControls>(\n () => ({\n activeIndex: current,\n step,\n validating,\n isFirst: current === 0,\n isLast: current === steps.length - 1,\n next,\n back,\n goTo,\n }),\n [back, current, goTo, next, step, steps.length, validating],\n );\n\n const indicatorSteps = useMemo(\n () =>\n steps.map((item) => ({\n label: item.label,\n description: item.optional\n ? `${item.description ?? \"\"} ${optionalLabel}`.trim()\n : item.description,\n })),\n [optionalLabel, steps],\n );\n\n return (\n <div className={cn(styles.wizard, className)}>\n <Stepper\n steps={indicatorSteps}\n current={current}\n onStepClick={clickableSteps ? (index) => void goTo(index) : undefined}\n />\n\n <div className={styles.body} role=\"group\" aria-label={step.label}>\n {typeof step.content === \"function\" ? step.content(controls) : step.content}\n </div>\n\n {renderActions ? (\n renderActions(controls)\n ) : (\n <div className={styles.actions}>\n <Button\n variant=\"secondary\"\n onClick={back}\n disabled={controls.isFirst || validating}\n >\n {backLabel}\n </Button>\n <Button onClick={() => void next()} loading={validating}>\n {controls.isLast ? finishLabel : nextLabel}\n </Button>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAyHA,SAAgB,EAAO,EACnB,UACA,gBACA,wBAAqB,GACrB,iBACA,eACA,eAAY,QACZ,eAAY,QACZ,iBAAc,UACd,mBAAgB,cAChB,oBAAiB,IACjB,kBACA,gBACY;CACZ,IAAM,IAAe,MAAgB,KAAA,GAC/B,CAAC,GAAe,KAAoB,EAAS,CAAkB,GAC/D,CAAC,GAAY,KAAiB,EAAS,EAAK,GAE5C,IAAU,KAAK,IAAI,IAAe,IAAc,GAAe,EAAM,SAAS,CAAC,GAC/E,IAAO,EAAM,IAEb,IAAS,GACV,MAAwB;EAErB,AADK,KAAc,EAAiB,CAAK,GACzC,IAAe,GAAO,EAAM,EAAM;CACtC,GACA;EAAC;EAAc;EAAc;CAAK,CACtC,GAOM,IAAc,EAAY,OAAO,MAA4C;EAC/E,IAAI,CAAC,EAAU,UAAU,OAAO;EAChC,EAAc,EAAI;EAClB,IAAI;GACA,OAAO,MAAM,EAAU,SAAS;EACpC,QAAQ;GACJ,OAAO;EACX,UAAU;GACN,EAAc,EAAK;EACvB;CACJ,GAAG,CAAC,CAAC,GAEC,IAAO,EAAY,YAA2B;EAC1C,UAAM,EAAY,CAAI,GAC5B;OAAI,MAAY,EAAM,SAAS,GAAG;IAC9B,MAAM,IAAa;IACnB;GACJ;GACA,EAAO,IAAU,CAAC;EADlB;CAEJ,GAAG;EAAC;EAAS;EAAQ;EAAY;EAAa;EAAM,EAAM;CAAM,CAAC,GAE3D,IAAO,QAAwB;EACjC,AAAI,IAAU,KAAG,EAAO,IAAU,CAAC;CACvC,GAAG,CAAC,GAAS,CAAM,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G,SAAS;KACxC,UAAA,EAAS,SAAS,IAAc;IAC7B,CAAA,CACP;;EAER;;AAEb"}
@@ -1 +1 @@
1
- {"version":3,"file":"data-provider-context.cjs","names":[],"sources":["../../src/data/data-provider-context.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport type { DataProvider } from \"./create-data-provider\";\n\nconst DataProviderContext = createContext<DataProvider | null>(null);\n\n/** Props for {@link TempestDataProvider}. */\nexport interface TempestDataProviderProps {\n /** The data provider to expose to descendant resource hooks. */\n provider: DataProvider;\n /** The subtree that consumes the provider. */\n children: ReactNode;\n}\n\n/**\n * Inject a {@link DataProvider} into the React tree so the resource hooks\n * (`useList`, `useOne`, `useCreate`, …) can resolve it via {@link useDataProvider}.\n *\n * @example\n * const dataProvider = createDataProvider(apiClient);\n * <TempestDataProvider provider={dataProvider}>\n * <App />\n * </TempestDataProvider>\n */\nexport function TempestDataProvider({ provider, children }: TempestDataProviderProps) {\n return <DataProviderContext.Provider value={provider}>{children}</DataProviderContext.Provider>;\n}\n\n/**\n * Read the {@link DataProvider} from context.\n *\n * @returns The data provider supplied to the nearest {@link TempestDataProvider}.\n * @throws {Error} When used outside a {@link TempestDataProvider}.\n */\nexport function useDataProvider(): DataProvider {\n const provider = useContext(DataProviderContext);\n if (!provider) {\n throw new Error(\"useDataProvider must be used within a <TempestDataProvider>\");\n }\n return provider;\n}\n"],"mappings":"sDAKA,IAAM,GAAA,EAAA,EAAA,cAAA,CAAyD,IAAI,EAoBnE,SAAgB,EAAoB,CAAE,WAAU,YAAsC,CAClF,OAAO,EAAA,EAAA,IAAA,CAAC,EAAoB,SAArB,CAA8B,MAAO,EAAW,UAAuC,CAAA,CAClG,CAQA,SAAgB,GAAgC,CAC5C,IAAM,GAAA,EAAA,EAAA,WAAA,CAAsB,CAAmB,EAC/C,GAAI,CAAC,EACD,MAAU,MAAM,6DAA6D,EAEjF,OAAO,CACX"}
1
+ {"version":3,"file":"data-provider-context.cjs","names":[],"sources":["../../src/data/data-provider-context.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport type { DataProvider } from \"./create-data-provider\";\n\nconst DataProviderContext = createContext<DataProvider | null>(null);\n\n/** Props for {@link TempestDataProvider}. */\nexport interface TempestDataProviderProps {\n /** The data provider to expose to descendant resource hooks. */\n provider: DataProvider;\n /** The subtree that consumes the provider. */\n children: ReactNode;\n}\n\n/**\n * Inject a {@link DataProvider} into the React tree so the resource hooks\n * (`useList`, `useOne`, `useCreate`, …) can resolve it via {@link useDataProvider}.\n *\n * @example\n * const dataProvider = createDataProvider(apiClient);\n * <TempestDataProvider provider={dataProvider}>\n * <App />\n * </TempestDataProvider>\n */\nexport function TempestDataProvider({ provider, children }: TempestDataProviderProps) {\n return <DataProviderContext.Provider value={provider}>{children}</DataProviderContext.Provider>;\n}\n\n/**\n * Read the {@link DataProvider} from context.\n *\n * @returns The data provider supplied to the nearest {@link TempestDataProvider}.\n * @throws {Error} When used outside a {@link TempestDataProvider}.\n */\nexport function useDataProvider(): DataProvider {\n const provider = useContext(DataProviderContext);\n if (!provider) {\n throw new Error(\"useDataProvider must be used within a <TempestDataProvider>\");\n }\n return provider;\n}\n"],"mappings":"sDAKA,IAAM,GAAA,EAAsB,EAAA,cAAA,CAAmC,IAAI,EAoBnE,SAAgB,EAAoB,CAAE,WAAU,YAAsC,CAClF,OAAO,EAAA,EAAA,IAAA,CAAC,EAAoB,SAArB,CAA8B,MAAO,EAAW,UAAuC,CAAA,CAClG,CAQA,SAAgB,GAAgC,CAC5C,IAAM,GAAA,EAAW,EAAA,WAAA,CAAW,CAAmB,EAC/C,GAAI,CAAC,EACD,MAAU,MAAM,6DAA6D,EAEjF,OAAO,CACX"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-resource.cjs","names":[],"sources":["../../src/data/use-resource.ts"],"sourcesContent":["import { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type {\n UseMutationOptions,\n UseMutationResult,\n UseQueryOptions,\n UseQueryResult,\n} from \"@tanstack/react-query\";\n\nimport type { OffsetPage } from \"@/query/pagination\";\n\nimport type { GetListParams } from \"./create-data-provider\";\nimport { useDataProvider } from \"./data-provider-context\";\n\n/** Extra TanStack Query options for {@link useList} (key + fn are provided). */\nexport type UseListOptions<T> = Omit<\n UseQueryOptions<OffsetPage<T>, Error, OffsetPage<T>>,\n \"queryKey\" | \"queryFn\"\n>;\n\n/** Extra TanStack Query options for {@link useOne} (key + fn + enabled are provided). */\nexport type UseOneOptions<T> = Omit<\n UseQueryOptions<T, Error, T>,\n \"queryKey\" | \"queryFn\" | \"enabled\"\n> & { enabled?: boolean };\n\n/**\n * Build the cache key for a resource list query.\n *\n * @param resource - The resource name.\n * @param params - The list params (page/sort/filters).\n * @returns A stable TanStack Query key.\n */\nexport function listQueryKey(resource: string, params?: GetListParams): unknown[] {\n return [\"data\", resource, \"list\", params];\n}\n\n/**\n * Build the cache key for a single-record query.\n *\n * @param resource - The resource name.\n * @param id - The record id.\n * @returns A stable TanStack Query key.\n */\nexport function oneQueryKey(resource: string, id: string | number | null | undefined): unknown[] {\n return [\"data\", resource, \"one\", id];\n}\n\n/**\n * Query a paginated list of a resource through the active {@link useDataProvider}.\n *\n * @param resource - The resource name.\n * @param params - Pagination, sort and filter parameters.\n * @param options - Extra TanStack Query options.\n * @returns The TanStack Query result for the offset page.\n */\nexport function useList<T>(\n resource: string,\n params?: GetListParams,\n options?: UseListOptions<T>,\n): UseQueryResult<OffsetPage<T>, Error> {\n const provider = useDataProvider();\n return useQuery<OffsetPage<T>, Error>({\n queryKey: listQueryKey(resource, params),\n queryFn: () => provider.getList<T>(resource, params),\n ...options,\n });\n}\n\n/**\n * Query a single record by id through the active {@link useDataProvider}.\n *\n * The query is disabled while `id` is `null`/`undefined`.\n *\n * @param resource - The resource name.\n * @param id - The record id.\n * @param options - Extra TanStack Query options.\n * @returns The TanStack Query result for the record.\n */\nexport function useOne<T>(\n resource: string,\n id: string | number | null | undefined,\n options?: UseOneOptions<T>,\n): UseQueryResult<T, Error> {\n const provider = useDataProvider();\n const { enabled, ...rest } = options ?? {};\n return useQuery<T, Error>({\n queryKey: oneQueryKey(resource, id),\n queryFn: () => provider.getOne<T>(resource, id as string | number),\n enabled: id != null && (enabled ?? true),\n ...rest,\n });\n}\n\n/** Options for the create mutation (mutationFn + onSuccess are provided). */\nexport type UseCreateOptions<T> = Omit<UseMutationOptions<T, Error, unknown>, \"mutationFn\">;\n\n/**\n * Create a record and invalidate the resource list cache on success.\n *\n * @param resource - The resource name.\n * @param options - Extra TanStack Mutation options.\n * @returns The mutation; `mutate(data)` creates the record.\n */\nexport function useCreate<T>(\n resource: string,\n options?: UseCreateOptions<T>,\n): UseMutationResult<T, Error, unknown> {\n const provider = useDataProvider();\n const queryClient = useQueryClient();\n return useMutation<T, Error, unknown>({\n mutationFn: (data: unknown) => provider.create<T>(resource, data),\n onSuccess: (...args) => {\n void queryClient.invalidateQueries({ queryKey: [\"data\", resource, \"list\"] });\n options?.onSuccess?.(...args);\n },\n ...options,\n });\n}\n\n/** Variables accepted by the update mutation. */\nexport interface UpdateVariables {\n /** The record id to update. */\n id: string | number;\n /** The update payload. */\n data: unknown;\n}\n\n/** Options for the update mutation (mutationFn + onSuccess are provided). */\nexport type UseUpdateOptions<T> = Omit<UseMutationOptions<T, Error, UpdateVariables>, \"mutationFn\">;\n\n/**\n * Update a record and invalidate both the list and the single-record caches.\n *\n * @param resource - The resource name.\n * @param options - Extra TanStack Mutation options.\n * @returns The mutation; `mutate({ id, data })` updates the record.\n */\nexport function useUpdate<T>(\n resource: string,\n options?: UseUpdateOptions<T>,\n): UseMutationResult<T, Error, UpdateVariables> {\n const provider = useDataProvider();\n const queryClient = useQueryClient();\n return useMutation<T, Error, UpdateVariables>({\n mutationFn: ({ id, data }: UpdateVariables) => provider.update<T>(resource, id, data),\n onSuccess: (...args) => {\n const [, variables] = args;\n void queryClient.invalidateQueries({ queryKey: [\"data\", resource, \"list\"] });\n void queryClient.invalidateQueries({ queryKey: oneQueryKey(resource, variables.id) });\n options?.onSuccess?.(...args);\n },\n ...options,\n });\n}\n\n/** Options for the delete mutation (mutationFn + onSuccess are provided). */\nexport type UseDeleteOptions<T> = Omit<UseMutationOptions<T, Error, string | number>, \"mutationFn\">;\n\n/**\n * Delete a record by id and invalidate the resource list cache on success.\n *\n * @param resource - The resource name.\n * @param options - Extra TanStack Mutation options.\n * @returns The mutation; `mutate(id)` deletes the record.\n */\nexport function useDelete<T>(\n resource: string,\n options?: UseDeleteOptions<T>,\n): UseMutationResult<T, Error, string | number> {\n const provider = useDataProvider();\n const queryClient = useQueryClient();\n return useMutation<T, Error, string | number>({\n mutationFn: (id: string | number) => provider.deleteOne<T>(resource, id),\n onSuccess: (...args) => {\n void queryClient.invalidateQueries({ queryKey: [\"data\", resource, \"list\"] });\n options?.onSuccess?.(...args);\n },\n ...options,\n });\n}\n"],"mappings":"sFAgCA,SAAgB,EAAa,EAAkB,EAAmC,CAC9E,MAAO,CAAC,OAAQ,EAAU,OAAQ,CAAM,CAC5C,CASA,SAAgB,EAAY,EAAkB,EAAmD,CAC7F,MAAO,CAAC,OAAQ,EAAU,MAAO,CAAE,CACvC,CAUA,SAAgB,EACZ,EACA,EACA,EACoC,CACpC,IAAM,EAAW,EAAA,gBAAgB,EACjC,OAAA,EAAA,EAAA,SAAA,CAAsC,CAClC,SAAU,EAAa,EAAU,CAAM,EACvC,YAAe,EAAS,QAAW,EAAU,CAAM,EACnD,GAAG,CACP,CAAC,CACL,CAYA,SAAgB,EACZ,EACA,EACA,EACwB,CACxB,IAAM,EAAW,EAAA,gBAAgB,EAC3B,CAAE,UAAS,GAAG,GAAS,GAAW,CAAC,EACzC,OAAA,EAAA,EAAA,SAAA,CAA0B,CACtB,SAAU,EAAY,EAAU,CAAE,EAClC,YAAe,EAAS,OAAU,EAAU,CAAqB,EACjE,QAAS,GAAM,OAAS,GAAW,IACnC,GAAG,CACP,CAAC,CACL,CAYA,SAAgB,EACZ,EACA,EACoC,CACpC,IAAM,EAAW,EAAA,gBAAgB,EAC3B,GAAA,EAAA,EAAA,eAAA,CAA6B,EACnC,OAAA,EAAA,EAAA,YAAA,CAAsC,CAClC,WAAa,GAAkB,EAAS,OAAU,EAAU,CAAI,EAChE,WAAY,GAAG,IAAS,CACpB,EAAiB,kBAAkB,CAAE,SAAU,CAAC,OAAQ,EAAU,MAAM,CAAE,CAAC,EAC3E,GAAS,YAAY,GAAG,CAAI,CAChC,EACA,GAAG,CACP,CAAC,CACL,CAoBA,SAAgB,EACZ,EACA,EAC4C,CAC5C,IAAM,EAAW,EAAA,gBAAgB,EAC3B,GAAA,EAAA,EAAA,eAAA,CAA6B,EACnC,OAAA,EAAA,EAAA,YAAA,CAA8C,CAC1C,YAAa,CAAE,KAAI,UAA4B,EAAS,OAAU,EAAU,EAAI,CAAI,EACpF,WAAY,GAAG,IAAS,CACpB,GAAM,EAAG,GAAa,EACtB,EAAiB,kBAAkB,CAAE,SAAU,CAAC,OAAQ,EAAU,MAAM,CAAE,CAAC,EAC3E,EAAiB,kBAAkB,CAAE,SAAU,EAAY,EAAU,EAAU,EAAE,CAAE,CAAC,EACpF,GAAS,YAAY,GAAG,CAAI,CAChC,EACA,GAAG,CACP,CAAC,CACL,CAYA,SAAgB,EACZ,EACA,EAC4C,CAC5C,IAAM,EAAW,EAAA,gBAAgB,EAC3B,GAAA,EAAA,EAAA,eAAA,CAA6B,EACnC,OAAA,EAAA,EAAA,YAAA,CAA8C,CAC1C,WAAa,GAAwB,EAAS,UAAa,EAAU,CAAE,EACvE,WAAY,GAAG,IAAS,CACpB,EAAiB,kBAAkB,CAAE,SAAU,CAAC,OAAQ,EAAU,MAAM,CAAE,CAAC,EAC3E,GAAS,YAAY,GAAG,CAAI,CAChC,EACA,GAAG,CACP,CAAC,CACL"}
1
+ {"version":3,"file":"use-resource.cjs","names":[],"sources":["../../src/data/use-resource.ts"],"sourcesContent":["import { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type {\n UseMutationOptions,\n UseMutationResult,\n UseQueryOptions,\n UseQueryResult,\n} from \"@tanstack/react-query\";\n\nimport type { OffsetPage } from \"@/query/pagination\";\n\nimport type { GetListParams } from \"./create-data-provider\";\nimport { useDataProvider } from \"./data-provider-context\";\n\n/** Extra TanStack Query options for {@link useList} (key + fn are provided). */\nexport type UseListOptions<T> = Omit<\n UseQueryOptions<OffsetPage<T>, Error, OffsetPage<T>>,\n \"queryKey\" | \"queryFn\"\n>;\n\n/** Extra TanStack Query options for {@link useOne} (key + fn + enabled are provided). */\nexport type UseOneOptions<T> = Omit<\n UseQueryOptions<T, Error, T>,\n \"queryKey\" | \"queryFn\" | \"enabled\"\n> & { enabled?: boolean };\n\n/**\n * Build the cache key for a resource list query.\n *\n * @param resource - The resource name.\n * @param params - The list params (page/sort/filters).\n * @returns A stable TanStack Query key.\n */\nexport function listQueryKey(resource: string, params?: GetListParams): unknown[] {\n return [\"data\", resource, \"list\", params];\n}\n\n/**\n * Build the cache key for a single-record query.\n *\n * @param resource - The resource name.\n * @param id - The record id.\n * @returns A stable TanStack Query key.\n */\nexport function oneQueryKey(resource: string, id: string | number | null | undefined): unknown[] {\n return [\"data\", resource, \"one\", id];\n}\n\n/**\n * Query a paginated list of a resource through the active {@link useDataProvider}.\n *\n * @param resource - The resource name.\n * @param params - Pagination, sort and filter parameters.\n * @param options - Extra TanStack Query options.\n * @returns The TanStack Query result for the offset page.\n */\nexport function useList<T>(\n resource: string,\n params?: GetListParams,\n options?: UseListOptions<T>,\n): UseQueryResult<OffsetPage<T>, Error> {\n const provider = useDataProvider();\n return useQuery<OffsetPage<T>, Error>({\n queryKey: listQueryKey(resource, params),\n queryFn: () => provider.getList<T>(resource, params),\n ...options,\n });\n}\n\n/**\n * Query a single record by id through the active {@link useDataProvider}.\n *\n * The query is disabled while `id` is `null`/`undefined`.\n *\n * @param resource - The resource name.\n * @param id - The record id.\n * @param options - Extra TanStack Query options.\n * @returns The TanStack Query result for the record.\n */\nexport function useOne<T>(\n resource: string,\n id: string | number | null | undefined,\n options?: UseOneOptions<T>,\n): UseQueryResult<T, Error> {\n const provider = useDataProvider();\n const { enabled, ...rest } = options ?? {};\n return useQuery<T, Error>({\n queryKey: oneQueryKey(resource, id),\n queryFn: () => provider.getOne<T>(resource, id as string | number),\n enabled: id != null && (enabled ?? true),\n ...rest,\n });\n}\n\n/** Options for the create mutation (mutationFn + onSuccess are provided). */\nexport type UseCreateOptions<T> = Omit<UseMutationOptions<T, Error, unknown>, \"mutationFn\">;\n\n/**\n * Create a record and invalidate the resource list cache on success.\n *\n * @param resource - The resource name.\n * @param options - Extra TanStack Mutation options.\n * @returns The mutation; `mutate(data)` creates the record.\n */\nexport function useCreate<T>(\n resource: string,\n options?: UseCreateOptions<T>,\n): UseMutationResult<T, Error, unknown> {\n const provider = useDataProvider();\n const queryClient = useQueryClient();\n return useMutation<T, Error, unknown>({\n mutationFn: (data: unknown) => provider.create<T>(resource, data),\n onSuccess: (...args) => {\n void queryClient.invalidateQueries({ queryKey: [\"data\", resource, \"list\"] });\n options?.onSuccess?.(...args);\n },\n ...options,\n });\n}\n\n/** Variables accepted by the update mutation. */\nexport interface UpdateVariables {\n /** The record id to update. */\n id: string | number;\n /** The update payload. */\n data: unknown;\n}\n\n/** Options for the update mutation (mutationFn + onSuccess are provided). */\nexport type UseUpdateOptions<T> = Omit<UseMutationOptions<T, Error, UpdateVariables>, \"mutationFn\">;\n\n/**\n * Update a record and invalidate both the list and the single-record caches.\n *\n * @param resource - The resource name.\n * @param options - Extra TanStack Mutation options.\n * @returns The mutation; `mutate({ id, data })` updates the record.\n */\nexport function useUpdate<T>(\n resource: string,\n options?: UseUpdateOptions<T>,\n): UseMutationResult<T, Error, UpdateVariables> {\n const provider = useDataProvider();\n const queryClient = useQueryClient();\n return useMutation<T, Error, UpdateVariables>({\n mutationFn: ({ id, data }: UpdateVariables) => provider.update<T>(resource, id, data),\n onSuccess: (...args) => {\n const [, variables] = args;\n void queryClient.invalidateQueries({ queryKey: [\"data\", resource, \"list\"] });\n void queryClient.invalidateQueries({ queryKey: oneQueryKey(resource, variables.id) });\n options?.onSuccess?.(...args);\n },\n ...options,\n });\n}\n\n/** Options for the delete mutation (mutationFn + onSuccess are provided). */\nexport type UseDeleteOptions<T> = Omit<UseMutationOptions<T, Error, string | number>, \"mutationFn\">;\n\n/**\n * Delete a record by id and invalidate the resource list cache on success.\n *\n * @param resource - The resource name.\n * @param options - Extra TanStack Mutation options.\n * @returns The mutation; `mutate(id)` deletes the record.\n */\nexport function useDelete<T>(\n resource: string,\n options?: UseDeleteOptions<T>,\n): UseMutationResult<T, Error, string | number> {\n const provider = useDataProvider();\n const queryClient = useQueryClient();\n return useMutation<T, Error, string | number>({\n mutationFn: (id: string | number) => provider.deleteOne<T>(resource, id),\n onSuccess: (...args) => {\n void queryClient.invalidateQueries({ queryKey: [\"data\", resource, \"list\"] });\n options?.onSuccess?.(...args);\n },\n ...options,\n });\n}\n"],"mappings":"sFAgCA,SAAgB,EAAa,EAAkB,EAAmC,CAC9E,MAAO,CAAC,OAAQ,EAAU,OAAQ,CAAM,CAC5C,CASA,SAAgB,EAAY,EAAkB,EAAmD,CAC7F,MAAO,CAAC,OAAQ,EAAU,MAAO,CAAE,CACvC,CAUA,SAAgB,EACZ,EACA,EACA,EACoC,CACpC,IAAM,EAAW,EAAA,gBAAgB,EACjC,OAAA,EAAO,EAAA,SAAA,CAA+B,CAClC,SAAU,EAAa,EAAU,CAAM,EACvC,YAAe,EAAS,QAAW,EAAU,CAAM,EACnD,GAAG,CACP,CAAC,CACL,CAYA,SAAgB,EACZ,EACA,EACA,EACwB,CACxB,IAAM,EAAW,EAAA,gBAAgB,EAC3B,CAAE,UAAS,GAAG,GAAS,GAAW,CAAC,EACzC,OAAA,EAAO,EAAA,SAAA,CAAmB,CACtB,SAAU,EAAY,EAAU,CAAE,EAClC,YAAe,EAAS,OAAU,EAAU,CAAqB,EACjE,QAAS,GAAM,OAAS,G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