@middag-io/react 0.44.1 → 0.45.2

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 (362) hide show
  1. package/README.md +7 -0
  2. package/dist-lib/{FormField-Bj43PjHH.js → FormField-Csx8hGAW.js} +1956 -1936
  3. package/dist-lib/{FormPanelBlock-C6eDfGoI.js → FormPanelBlock-Bmd0DpiX.js} +337 -337
  4. package/dist-lib/base/blocks/DenseTableBlock.d.ts.map +1 -1
  5. package/dist-lib/base/blocks/LinkListBlock.d.ts +2 -1
  6. package/dist-lib/base/blocks/LinkListBlock.d.ts.map +1 -1
  7. package/dist-lib/base/form/FormField.d.ts.map +1 -1
  8. package/dist-lib/base/layout/DashboardLayout.d.ts.map +1 -1
  9. package/dist-lib/base/partials/ConfirmationDialog/index.d.ts.map +1 -1
  10. package/dist-lib/base/partials/DataTable/cell-renderers.d.ts +1 -1
  11. package/dist-lib/base/partials/DataTable/cell-renderers.d.ts.map +1 -1
  12. package/dist-lib/base/partials/DataTable/index.d.ts +1 -1
  13. package/dist-lib/base/partials/DataTable/index.d.ts.map +1 -1
  14. package/dist-lib/base/partials/DataTable/sanitize-html.d.ts +17 -0
  15. package/dist-lib/base/partials/DataTable/sanitize-html.d.ts.map +1 -0
  16. package/dist-lib/base/partials/DataTable/types.d.ts +15 -0
  17. package/dist-lib/base/partials/DataTable/types.d.ts.map +1 -1
  18. package/dist-lib/base/partials/FilterBar/index.d.ts.map +1 -1
  19. package/dist-lib/base/shell/BasicShell.js +1 -1
  20. package/dist-lib/base/shell/partials/InlineEditablePanel.js +38 -24
  21. package/dist-lib/base/shell/partials/PageActionButton.d.ts.map +1 -1
  22. package/dist-lib/base/shell/partials/PageActionButton.js +1 -1
  23. package/dist-lib/chunks/subpath-Bh1MAmBT.js +165 -0
  24. package/dist-lib/chunks/{subpath-AeMdleNB.js → subpath-fEhy6n_U.js} +10 -6
  25. package/dist-lib/contracts/block-data/data-display.d.ts +51 -2
  26. package/dist-lib/contracts/block-data/data-display.d.ts.map +1 -1
  27. package/dist-lib/contracts/generated/contract-schema.d.ts +1 -1
  28. package/dist-lib/contracts/generated/contract-types.d.ts +4 -2
  29. package/dist-lib/contracts/generated/contract-types.d.ts.map +1 -1
  30. package/dist-lib/contracts/generated/index.d.ts +1 -1
  31. package/dist-lib/i18n/I18nProvider.js +1 -1
  32. package/dist-lib/i18n/instance.js +1 -1
  33. package/dist-lib/i18n/locales/en/ui.json +5 -3
  34. package/dist-lib/i18n/locales/pt-BR/ui.json +5 -3
  35. package/dist-lib/i18n/register-strings.js +1 -1
  36. package/dist-lib/index.d.ts +1 -1
  37. package/dist-lib/index.d.ts.map +1 -1
  38. package/dist-lib/middag-react.css +1 -1
  39. package/dist-lib/middag-react.js +18641 -13317
  40. package/dist-lib/primitives/reui/chart.d.ts.map +1 -1
  41. package/dist-lib/primitives/reui/chart.js +35 -31
  42. package/docs/public/schemas/ai-contract-manifest.json +1820 -0
  43. package/docs/public/schemas/blocks.json +445 -0
  44. package/docs/public/schemas/components.json +166 -0
  45. package/docs/public/schemas/connectors.json +97 -0
  46. package/docs/public/schemas/fragment.json +2329 -0
  47. package/docs/public/schemas/manifest.json +119 -0
  48. package/docs/public/schemas/navigation.json +72 -0
  49. package/docs/public/schemas/page-contract.json +2329 -0
  50. package/docs/public/schemas/shared-props.json +118 -0
  51. package/docs/public/schemas/theme-defaults.json +253 -0
  52. package/docs/public/schemas/theme.json +401 -0
  53. package/package.json +109 -3
  54. package/src/assets/lottie/calendar/schedule-1.json +1 -0
  55. package/src/assets/lottie/calendar/schedule-2.json +1 -0
  56. package/src/assets/lottie/celebration/confetti-1.json +1 -0
  57. package/src/assets/lottie/celebration/confetti-2.json +1 -0
  58. package/src/assets/lottie/celebration/confetti-3.json +1 -0
  59. package/src/assets/lottie/cloud/cloud-1.json +1 -0
  60. package/src/assets/lottie/cloud/cloud-2.json +1 -0
  61. package/src/assets/lottie/connection/network-1.json +1 -0
  62. package/src/assets/lottie/connection/network-2.json +1 -0
  63. package/src/assets/lottie/connection/network-3.json +1 -0
  64. package/src/assets/lottie/dashboard/analytics-1.json +1 -0
  65. package/src/assets/lottie/dashboard/analytics-2.json +1 -0
  66. package/src/assets/lottie/dashboard/analytics-3.json +1 -0
  67. package/src/assets/lottie/email/mail-1.json +1 -0
  68. package/src/assets/lottie/email/mail-2.json +1 -0
  69. package/src/assets/lottie/email/mail-3.json +1 -0
  70. package/src/assets/lottie/empty-state/empty-1.json +1 -0
  71. package/src/assets/lottie/empty-state/empty-2.json +1 -0
  72. package/src/assets/lottie/empty-state/empty-3.json +1 -0
  73. package/src/assets/lottie/error/warning-1.json +1 -0
  74. package/src/assets/lottie/error/warning-2.json +1 -0
  75. package/src/assets/lottie/error/warning-3.json +1 -0
  76. package/src/assets/lottie/index.ts +49 -0
  77. package/src/assets/lottie/loading/spinner-1.json +1 -0
  78. package/src/assets/lottie/loading/spinner-2.json +1 -0
  79. package/src/assets/lottie/loading/spinner-3.json +1 -0
  80. package/src/assets/lottie/maintenance/construction-1.json +1 -0
  81. package/src/assets/lottie/maintenance/construction-2.json +1 -0
  82. package/src/assets/lottie/maintenance/construction-3.json +1 -0
  83. package/src/assets/lottie/not-found/404-1.json +1 -0
  84. package/src/assets/lottie/not-found/404-2.json +1 -0
  85. package/src/assets/lottie/not-found/404-3.json +1 -0
  86. package/src/assets/lottie/notification/bell-1.json +1 -0
  87. package/src/assets/lottie/notification/bell-2.json +1 -0
  88. package/src/assets/lottie/notification/bell-3.json +1 -0
  89. package/src/assets/lottie/onboarding/welcome-1.json +1 -0
  90. package/src/assets/lottie/onboarding/welcome-2.json +1 -0
  91. package/src/assets/lottie/onboarding/welcome-3.json +1 -0
  92. package/src/assets/lottie/payment/wallet-1.json +1 -0
  93. package/src/assets/lottie/payment/wallet-2.json +1 -0
  94. package/src/assets/lottie/payment/wallet-3.json +1 -0
  95. package/src/assets/lottie/search/search-1.json +1 -0
  96. package/src/assets/lottie/search/search-2.json +1 -0
  97. package/src/assets/lottie/search/search-3.json +1 -0
  98. package/src/assets/lottie/security/lock-1.json +1 -0
  99. package/src/assets/lottie/security/lock-2.json +1 -0
  100. package/src/assets/lottie/security/lock-3.json +1 -0
  101. package/src/assets/lottie/settings/gear-1.json +1 -0
  102. package/src/assets/lottie/settings/gear-2.json +1 -0
  103. package/src/assets/lottie/settings/gear-3.json +1 -0
  104. package/src/assets/lottie/success/check-1.json +1 -0
  105. package/src/assets/lottie/success/check-2.json +1 -0
  106. package/src/assets/lottie/success/check-3.json +1 -0
  107. package/src/assets/lottie/upload/upload-1.json +1 -0
  108. package/src/assets/lottie/upload/upload-2.json +1 -0
  109. package/src/assets/lottie/upload/upload-3.json +1 -0
  110. package/src/assets/lottie/user/profile-1.json +1 -0
  111. package/src/assets/lottie/user/profile-2.json +1 -0
  112. package/src/assets/lottie/user/profile-3.json +1 -0
  113. package/src/base/blocks/ActionGridBlock.tsx +151 -0
  114. package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
  115. package/src/base/blocks/CardGridBlock.tsx +384 -0
  116. package/src/base/blocks/ChartBlock.tsx +81 -0
  117. package/src/base/blocks/DenseTableBlock.tsx +403 -0
  118. package/src/base/blocks/DetailPanelBlock.tsx +189 -0
  119. package/src/base/blocks/EmptyStateBlock.tsx +46 -0
  120. package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
  121. package/src/base/blocks/FormPanelBlock.tsx +480 -0
  122. package/src/base/blocks/LinkListBlock.tsx +94 -0
  123. package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
  124. package/src/base/blocks/MetricCardBlock.tsx +128 -0
  125. package/src/base/blocks/StatusStripBlock.tsx +43 -0
  126. package/src/base/blocks/TabsBlock.tsx +94 -0
  127. package/src/base/form/FormField.tsx +607 -0
  128. package/src/base/form/fields/CheckboxField.tsx +56 -0
  129. package/src/base/form/fields/ColorField.tsx +76 -0
  130. package/src/base/form/fields/CurrencyField.tsx +126 -0
  131. package/src/base/form/fields/DateField.tsx +168 -0
  132. package/src/base/form/fields/DateRangeField.tsx +66 -0
  133. package/src/base/form/fields/DocumentField.tsx +222 -0
  134. package/src/base/form/fields/EntityPickerField.tsx +244 -0
  135. package/src/base/form/fields/FileUploadField.tsx +253 -0
  136. package/src/base/form/fields/MultiSelectField.tsx +286 -0
  137. package/src/base/form/fields/NativeSelectField.tsx +67 -0
  138. package/src/base/form/fields/NumberField.tsx +67 -0
  139. package/src/base/form/fields/OtpField.tsx +88 -0
  140. package/src/base/form/fields/PasswordField.tsx +69 -0
  141. package/src/base/form/fields/PhoneField.tsx +64 -0
  142. package/src/base/form/fields/RadioField.tsx +66 -0
  143. package/src/base/form/fields/RatingField.tsx +52 -0
  144. package/src/base/form/fields/SelectField.tsx +76 -0
  145. package/src/base/form/fields/SliderField.tsx +77 -0
  146. package/src/base/form/fields/SlugField.tsx +114 -0
  147. package/src/base/form/fields/StaticField.tsx +25 -0
  148. package/src/base/form/fields/SwitchField.tsx +56 -0
  149. package/src/base/form/fields/TagsField.tsx +128 -0
  150. package/src/base/form/fields/TextField.tsx +55 -0
  151. package/src/base/form/fields/TextareaField.tsx +55 -0
  152. package/src/base/form/fields/document-validation.ts +126 -0
  153. package/src/base/form/fields/field-registry.ts +53 -0
  154. package/src/base/form/fields/register-default-fields.ts +86 -0
  155. package/src/base/form/form-schema-builder.ts +192 -0
  156. package/src/base/form/form-utils.ts +71 -0
  157. package/src/base/hooks/useIsDark.ts +50 -0
  158. package/src/base/hooks/useLazyTabs.ts +98 -0
  159. package/src/base/hooks/usePolling.ts +43 -0
  160. package/src/base/hooks/useRemember.ts +58 -0
  161. package/src/base/hooks/useToast.ts +27 -0
  162. package/src/base/layout/BlockRegion.tsx +39 -0
  163. package/src/base/layout/DashboardLayout.tsx +110 -0
  164. package/src/base/layout/SidebarLayout.tsx +38 -0
  165. package/src/base/layout/StackLayout.tsx +32 -0
  166. package/src/base/layout/WizardLayout.tsx +49 -0
  167. package/src/base/partials/ActionBar/index.tsx +115 -0
  168. package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
  169. package/src/base/partials/DataTable/cell-registry.ts +50 -0
  170. package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
  171. package/src/base/partials/DataTable/index.tsx +1282 -0
  172. package/src/base/partials/DataTable/register-default-cells.ts +37 -0
  173. package/src/base/partials/DataTable/sanitize-html.ts +45 -0
  174. package/src/base/partials/DataTable/types.ts +229 -0
  175. package/src/base/partials/DetailSection/index.tsx +316 -0
  176. package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
  177. package/src/base/partials/EntityItem/index.tsx +154 -0
  178. package/src/base/partials/FilterBar/index.tsx +256 -0
  179. package/src/base/partials/FormSection/index.tsx +87 -0
  180. package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
  181. package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
  182. package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
  183. package/src/base/partials/LogViewer/index.tsx +110 -0
  184. package/src/base/partials/LogViewer/types.ts +28 -0
  185. package/src/base/partials/MarkdownContent/index.tsx +307 -0
  186. package/src/base/partials/MenuBar/index.tsx +80 -0
  187. package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
  188. package/src/base/partials/ResizableSidebar/index.tsx +70 -0
  189. package/src/base/partials/StatRow/index.tsx +28 -0
  190. package/src/base/partials/StatusBar/index.tsx +126 -0
  191. package/src/base/partials/StatusIndicator/index.tsx +61 -0
  192. package/src/base/partials/StepIndicator/index.tsx +63 -0
  193. package/src/base/partials/TableOfContents/index.tsx +78 -0
  194. package/src/base/partials/TimelineList/index.tsx +273 -0
  195. package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
  196. package/src/base/partials/TreeView/index.tsx +75 -0
  197. package/src/base/partials/index.ts +23 -0
  198. package/src/base/shell/AuthShell.tsx +54 -0
  199. package/src/base/shell/BasicShell.tsx +286 -0
  200. package/src/base/shell/ImmersiveShell.tsx +85 -0
  201. package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
  202. package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
  203. package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
  204. package/src/base/shell/partials/InspectorContext.tsx +173 -0
  205. package/src/base/shell/partials/InspectorPanel.tsx +65 -0
  206. package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
  207. package/src/base/shell/partials/OverlayScreen.tsx +67 -0
  208. package/src/base/shell/partials/PageActionButton.tsx +203 -0
  209. package/src/base/theme/appearance.ts +133 -0
  210. package/src/base/theme/host-layout-detector.ts +119 -0
  211. package/src/base/theme/host-theme-detector.ts +146 -0
  212. package/src/base/theme/sidebar-safelist.txt +20 -0
  213. package/src/base/theme/tailwind-theme.css +136 -0
  214. package/src/base/theme/theme-bridge.css +164 -0
  215. package/src/base/theme/theme-context.tsx +142 -0
  216. package/src/base/theme/themes/classic.css +174 -0
  217. package/src/base/theme/tokens.css +290 -0
  218. package/src/base/theme/useHostTheme.ts +95 -0
  219. package/src/base/utils/clipboard.ts +39 -0
  220. package/src/base/utils/conditions.ts +27 -0
  221. package/src/base/utils/icon-registry.ts +78 -0
  222. package/src/base/utils/icons.ts +31 -0
  223. package/src/base/utils/interpolate.ts +9 -0
  224. package/src/base/utils/register-default-icons.ts +163 -0
  225. package/src/base/utils/storage.ts +65 -0
  226. package/src/base/utils/time.ts +139 -0
  227. package/src/contracts/block-data/actions.ts +73 -0
  228. package/src/contracts/block-data/data-display.ts +343 -0
  229. package/src/contracts/block-data/form.ts +164 -0
  230. package/src/contracts/block-data/index.ts +15 -0
  231. package/src/contracts/block-data/interactive.ts +34 -0
  232. package/src/contracts/block-data/shared.ts +44 -0
  233. package/src/contracts/connectors.ts +60 -0
  234. package/src/contracts/generated/contract-schema.ts +1237 -0
  235. package/src/contracts/generated/contract-types.ts +675 -0
  236. package/src/contracts/generated/index.ts +15 -0
  237. package/src/contracts/navigation.ts +59 -0
  238. package/src/contracts/page-contract-schema.ts +40 -0
  239. package/src/contracts/page-contract.ts +79 -0
  240. package/src/contracts/shared-props.ts +92 -0
  241. package/src/engine/ContractPage.tsx +178 -0
  242. package/src/engine/EntityRoutes.tsx +72 -0
  243. package/src/engine/HostSlot.tsx +126 -0
  244. package/src/engine/LazyBlock.tsx +92 -0
  245. package/src/engine/bootstrap.tsx +20 -0
  246. package/src/engine/providers/auth.tsx +87 -0
  247. package/src/engine/providers/error-reporter.tsx +89 -0
  248. package/src/engine/providers/flash.tsx +44 -0
  249. package/src/engine/providers/index.ts +18 -0
  250. package/src/engine/providers/inertia-error-reporter.tsx +61 -0
  251. package/src/engine/providers/progress.tsx +56 -0
  252. package/src/engine/providers/scope.tsx +51 -0
  253. package/src/engine/register-defaults.ts +88 -0
  254. package/src/engine/registries.ts +96 -0
  255. package/src/i18n/I18nProvider.tsx +53 -0
  256. package/src/i18n/MANIFEST.md +101 -0
  257. package/src/i18n/host-resolver.ts +18 -0
  258. package/src/i18n/instance.ts +69 -0
  259. package/src/i18n/locales/en/ui.json +277 -0
  260. package/src/i18n/locales/en/validators.json +13 -0
  261. package/src/i18n/locales/pt-BR/ui.json +277 -0
  262. package/src/i18n/locales/pt-BR/validators.json +13 -0
  263. package/src/i18n/register-strings.ts +10 -0
  264. package/src/i18n/render-label.ts +33 -0
  265. package/src/i18n/resolve-field-error.ts +29 -0
  266. package/src/i18n/useHostString.ts +50 -0
  267. package/src/i18n/useTranslation.ts +83 -0
  268. package/src/lib/actions/resolve-action-target.ts +151 -0
  269. package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
  270. package/src/lib/hooks/use-file-upload.ts +406 -0
  271. package/src/lib/hooks/use-mobile.ts +21 -0
  272. package/src/lib/host-pending.ts +76 -0
  273. package/src/lib/portal-container.ts +16 -0
  274. package/src/lib/test-ids.ts +40 -0
  275. package/src/lib/utils.ts +6 -0
  276. package/src/primitives/reui/MANIFEST.md +97 -0
  277. package/src/primitives/reui/accordion.tsx +64 -0
  278. package/src/primitives/reui/alert-dialog.tsx +196 -0
  279. package/src/primitives/reui/alert.tsx +92 -0
  280. package/src/primitives/reui/aspect-ratio.tsx +9 -0
  281. package/src/primitives/reui/autocomplete.tsx +343 -0
  282. package/src/primitives/reui/avatar.tsx +109 -0
  283. package/src/primitives/reui/badge.tsx +94 -0
  284. package/src/primitives/reui/breadcrumb.tsx +109 -0
  285. package/src/primitives/reui/button-group.tsx +83 -0
  286. package/src/primitives/reui/button.tsx +64 -0
  287. package/src/primitives/reui/calendar.tsx +220 -0
  288. package/src/primitives/reui/card.tsx +92 -0
  289. package/src/primitives/reui/carousel.tsx +239 -0
  290. package/src/primitives/reui/chart.tsx +388 -0
  291. package/src/primitives/reui/checkbox.tsx +30 -0
  292. package/src/primitives/reui/collapsible.tsx +31 -0
  293. package/src/primitives/reui/combobox.tsx +308 -0
  294. package/src/primitives/reui/command.tsx +182 -0
  295. package/src/primitives/reui/context-menu.tsx +250 -0
  296. package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
  297. package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
  298. package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
  299. package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
  300. package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
  301. package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
  302. package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
  303. package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
  304. package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
  305. package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
  306. package/src/primitives/reui/data-grid-pagination.tsx +235 -0
  307. package/src/primitives/reui/date-selector.tsx +1353 -0
  308. package/src/primitives/reui/dialog.tsx +158 -0
  309. package/src/primitives/reui/drawer.tsx +133 -0
  310. package/src/primitives/reui/dropdown-menu.tsx +257 -0
  311. package/src/primitives/reui/empty.tsx +104 -0
  312. package/src/primitives/reui/field.tsx +246 -0
  313. package/src/primitives/reui/filters.tsx +1891 -0
  314. package/src/primitives/reui/frame.tsx +170 -0
  315. package/src/primitives/reui/hover-card.tsx +42 -0
  316. package/src/primitives/reui/icon-placeholder.tsx +39 -0
  317. package/src/primitives/reui/index.ts +98 -0
  318. package/src/primitives/reui/input-group.tsx +170 -0
  319. package/src/primitives/reui/input-otp.tsx +75 -0
  320. package/src/primitives/reui/input.tsx +21 -0
  321. package/src/primitives/reui/item.tsx +193 -0
  322. package/src/primitives/reui/kanban.tsx +743 -0
  323. package/src/primitives/reui/kbd.tsx +28 -0
  324. package/src/primitives/reui/label.tsx +22 -0
  325. package/src/primitives/reui/menubar.tsx +274 -0
  326. package/src/primitives/reui/native-select.tsx +62 -0
  327. package/src/primitives/reui/navigation-menu.tsx +168 -0
  328. package/src/primitives/reui/number-field.tsx +250 -0
  329. package/src/primitives/reui/pagination.tsx +127 -0
  330. package/src/primitives/reui/phone-input.tsx +231 -0
  331. package/src/primitives/reui/popover.tsx +87 -0
  332. package/src/primitives/reui/progress.tsx +31 -0
  333. package/src/primitives/reui/radio-group.tsx +43 -0
  334. package/src/primitives/reui/rating.tsx +177 -0
  335. package/src/primitives/reui/resizable.tsx +51 -0
  336. package/src/primitives/reui/scroll-area.tsx +58 -0
  337. package/src/primitives/reui/scrollspy.tsx +240 -0
  338. package/src/primitives/reui/select.tsx +188 -0
  339. package/src/primitives/reui/separator.tsx +28 -0
  340. package/src/primitives/reui/sheet.tsx +141 -0
  341. package/src/primitives/reui/sidebar.tsx +732 -0
  342. package/src/primitives/reui/skeleton.tsx +13 -0
  343. package/src/primitives/reui/slider.tsx +61 -0
  344. package/src/primitives/reui/sonner.tsx +47 -0
  345. package/src/primitives/reui/sortable.tsx +414 -0
  346. package/src/primitives/reui/spinner.tsx +16 -0
  347. package/src/primitives/reui/stepper.tsx +484 -0
  348. package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
  349. package/src/primitives/reui/svgs/gemini.tsx +171 -0
  350. package/src/primitives/reui/svgs/openai.tsx +9 -0
  351. package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
  352. package/src/primitives/reui/switch.tsx +33 -0
  353. package/src/primitives/reui/table.tsx +114 -0
  354. package/src/primitives/reui/tabs.tsx +91 -0
  355. package/src/primitives/reui/textarea.tsx +18 -0
  356. package/src/primitives/reui/timeline.tsx +219 -0
  357. package/src/primitives/reui/toggle-group.tsx +83 -0
  358. package/src/primitives/reui/toggle.tsx +45 -0
  359. package/src/primitives/reui/tooltip.tsx +55 -0
  360. package/src/primitives/reui/tree.tsx +247 -0
  361. package/src/theme.css +71 -0
  362. package/dist-lib/chunks/subpath-q4Q2zg_p.js +0 -153
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Document validation — country-aware tax/identity document validation.
3
+ *
4
+ * Uses validator.js isTaxID for checksum validation across 30+ countries.
5
+ * Supports scope restriction: "person" (individual), "company" (business), or "any" (both).
6
+ *
7
+ * Example: locale "pt-BR" with scope "person" validates CPF only (rejects CNPJ).
8
+ */
9
+
10
+ import isTaxID from "validator/lib/isTaxID";
11
+
12
+ /**
13
+ * Document type: a validator.js locale string ("pt-BR", "en-US", etc.),
14
+ * "generic" (accepts anything), or a custom key matching a documentMasks entry.
15
+ */
16
+ export type DocumentType = string;
17
+
18
+ export type DocumentScope = "person" | "company" | "any";
19
+
20
+ /**
21
+ * All locales supported by validator.js isTaxID.
22
+ */
23
+ export const SUPPORTED_LOCALES = [
24
+ "bg-BG",
25
+ "cs-CZ",
26
+ "de-AT",
27
+ "de-DE",
28
+ "dk-DK",
29
+ "el-CY",
30
+ "el-GR",
31
+ "en-CA",
32
+ "en-GB",
33
+ "en-IE",
34
+ "en-US",
35
+ "es-AR",
36
+ "es-ES",
37
+ "et-EE",
38
+ "fi-FI",
39
+ "fr-BE",
40
+ "fr-CA",
41
+ "fr-FR",
42
+ "fr-LU",
43
+ "hr-HR",
44
+ "hu-HU",
45
+ "it-IT",
46
+ "lb-LU",
47
+ "lt-LT",
48
+ "lv-LV",
49
+ "mt-MT",
50
+ "nl-BE",
51
+ "nl-NL",
52
+ "pl-PL",
53
+ "pt-BR",
54
+ "pt-PT",
55
+ "ro-RO",
56
+ "sk-SK",
57
+ "sl-SI",
58
+ "sv-SE",
59
+ "uk-UA",
60
+ ] as const;
61
+
62
+ export type TaxIDLocale = (typeof SUPPORTED_LOCALES)[number];
63
+
64
+ /** Strip non-alphanumeric characters from a value. */
65
+ function stripFormatting(value: string): string {
66
+ return value.replace(/[^a-zA-Z0-9]/g, "");
67
+ }
68
+
69
+ /**
70
+ * Digit-length rules for scope enforcement.
71
+ * When a locale has distinct person/company document lengths,
72
+ * we check the stripped length to enforce scope.
73
+ */
74
+ const SCOPE_LENGTH_RULES: Record<string, { person?: number[]; company?: number[] }> = {
75
+ "pt-BR": { person: [11], company: [14] }, // CPF=11, CNPJ=14
76
+ "en-US": { person: [9], company: [9] }, // SSN=9, EIN=9 (same length, different format)
77
+ "it-IT": { person: [16], company: [11] }, // CF=16 alphanum, P.IVA=11
78
+ "fr-FR": { person: [13], company: [9, 14] }, // SPI=13, SIREN=9, SIRET=14
79
+ "pl-PL": { person: [11], company: [10] }, // PESEL=11, NIP=10
80
+ "nl-NL": { person: [9], company: [8] }, // BSN=9, KVK=8
81
+ "ro-RO": { person: [13], company: [2, 3, 4, 5, 6, 7, 8, 9, 10] }, // CNP=13, CUI=2-10
82
+ "fi-FI": { person: [11], company: [9] }, // HETU=11 with dash, Y-tunnus=9
83
+ };
84
+
85
+ /**
86
+ * Validate a document/tax ID value with optional scope restriction.
87
+ *
88
+ * @param value - The document value (can be formatted with masks).
89
+ * @param type - A validator.js locale ("pt-BR", "en-US", etc.),
90
+ * "generic" (accepts anything), or a custom key.
91
+ * @param scope - Restrict to "person", "company", or "any" (default).
92
+ */
93
+ export function isValidDocument(
94
+ value: string,
95
+ type: DocumentType,
96
+ scope: DocumentScope = "any",
97
+ ): boolean {
98
+ if (!value || type === "generic") return true;
99
+
100
+ const stripped = stripFormatting(value);
101
+ if (stripped.length === 0) return true;
102
+
103
+ // If it matches a validator.js locale pattern (xx-XX), use isTaxID
104
+ if (/^[a-z]{2}-[A-Z]{2}$/.test(type)) {
105
+ // First validate with isTaxID (checksum)
106
+ if (!isTaxID(stripped, type as Parameters<typeof isTaxID>[1])) {
107
+ return false;
108
+ }
109
+
110
+ // Then enforce scope if rules exist for this locale
111
+ if (scope !== "any") {
112
+ const rules = SCOPE_LENGTH_RULES[type];
113
+ if (rules) {
114
+ const allowedLengths = scope === "person" ? rules.person : rules.company;
115
+ if (allowedLengths && !allowedLengths.includes(stripped.length)) {
116
+ return false;
117
+ }
118
+ }
119
+ }
120
+
121
+ return true;
122
+ }
123
+
124
+ // Custom type — no built-in validation, accept anything non-empty
125
+ return stripped.length > 0;
126
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Field component registry — maps FormFieldType keys to React components.
3
+ *
4
+ * Analogous to blockRegistry for blocks. Consumers can register custom field
5
+ * components without modifying FormField.tsx (Open/Closed principle).
6
+ *
7
+ * Default field components are registered by registerDefaultFields().
8
+ */
9
+
10
+ import type { ComponentType } from "react";
11
+
12
+ /**
13
+ * Props that every registered field component receives.
14
+ *
15
+ * Field-specific props (documentType, currency, etc.) are passed via the
16
+ * `fieldProps` bag — each component extracts what it needs.
17
+ */
18
+ export interface FieldComponentProps {
19
+ id: string;
20
+ value: unknown;
21
+ onChange: (value: unknown) => void;
22
+ error?: string;
23
+ helpTextId: string;
24
+ errorId: string;
25
+ disabled?: boolean;
26
+ required?: boolean;
27
+ /** Full field props bag — field components extract type-specific props. */
28
+ fieldProps: Record<string, unknown>;
29
+ }
30
+
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- registry stores heterogeneous field components
32
+ const fieldRegistry = new Map<string, ComponentType<any>>();
33
+
34
+ /**
35
+ * Register a field component for a given field type key.
36
+ *
37
+ * The component receives the same props as built-in field components
38
+ * (id, value, onChange, error, etc.). Use `FieldComponentProps` as a
39
+ * baseline, but specific fields may have additional typed props.
40
+ */
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- field components have heterogeneous props
42
+ export function registerFieldComponent(type: string, component: ComponentType<any>): void {
43
+ fieldRegistry.set(type, component);
44
+ }
45
+
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- field components have heterogeneous props
47
+ export function resolveFieldComponent(type: string): ComponentType<any> | undefined {
48
+ return fieldRegistry.get(type);
49
+ }
50
+
51
+ export function getRegisteredFieldTypes(): string[] {
52
+ return [...fieldRegistry.keys()];
53
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Registers all built-in field components in the field registry.
3
+ *
4
+ * Called by registerDefaults(). The field registry enables consumers to
5
+ * register custom field types (e.g. registerFieldComponent("rating", RatingField))
6
+ * without modifying FormField.tsx.
7
+ *
8
+ * Built-in fields are registered eagerly here because they are already
9
+ * imported by FormField.tsx — the registry simply makes them discoverable
10
+ * for custom form renderers and type lookups.
11
+ */
12
+
13
+ // Import all built-in field components
14
+ import { CheckboxField } from "./CheckboxField";
15
+ import { ColorField } from "./ColorField";
16
+ import { CurrencyField } from "./CurrencyField";
17
+ // DateField and DocumentField are NOT registered here — they're lazy-loaded
18
+ // in FormField.tsx to avoid bundling date-fns+react-day-picker (~115KB) and
19
+ // validator.js (~28KB) in the main chunk. Same pattern as PhoneField.
20
+ import { EntityPickerField } from "./EntityPickerField";
21
+ import { registerFieldComponent } from "./field-registry";
22
+ import { FileUploadField } from "./FileUploadField";
23
+ import { MultiSelectField } from "./MultiSelectField";
24
+ import { NativeSelectField } from "./NativeSelectField";
25
+ import { NumberFieldComponent } from "./NumberField";
26
+ import { OtpField } from "./OtpField";
27
+ import { PasswordField } from "./PasswordField";
28
+ import { RadioField } from "./RadioField";
29
+ import { RatingField } from "./RatingField";
30
+ import { SelectField } from "./SelectField";
31
+ import { SliderField } from "./SliderField";
32
+ import { SlugField } from "./SlugField";
33
+ import { StaticField } from "./StaticField";
34
+ import { SwitchField } from "./SwitchField";
35
+ import { TagsField } from "./TagsField";
36
+ import { TextareaField } from "./TextareaField";
37
+ import { TextField } from "./TextField";
38
+
39
+ let registered = false;
40
+
41
+ export function registerDefaultFields(): void {
42
+ if (registered) return;
43
+ registered = true;
44
+
45
+ // Text-based
46
+ registerFieldComponent("text", TextField);
47
+ registerFieldComponent("email", TextField);
48
+ registerFieldComponent("url", TextField);
49
+ registerFieldComponent("password", PasswordField);
50
+ registerFieldComponent("otp", OtpField);
51
+ registerFieldComponent("textarea", TextareaField);
52
+
53
+ // Numeric
54
+ registerFieldComponent("int", NumberFieldComponent);
55
+ registerFieldComponent("float", NumberFieldComponent);
56
+ registerFieldComponent("slider", SliderField);
57
+
58
+ // Selection
59
+ registerFieldComponent("select", SelectField);
60
+ registerFieldComponent("native_select", NativeSelectField);
61
+ registerFieldComponent("multiselect", MultiSelectField);
62
+ registerFieldComponent("radio", RadioField);
63
+
64
+ // Boolean
65
+ registerFieldComponent("checkbox", CheckboxField);
66
+ registerFieldComponent("switch", SwitchField);
67
+
68
+ // Note: "date" and "datetime" are NOT registered here — they're lazy-loaded
69
+ // in FormField.tsx to avoid bundling date-fns+react-day-picker (~115KB).
70
+
71
+ // Specialized
72
+ // Note: "document" is NOT registered here — it's lazy-loaded in FormField.tsx
73
+ // to avoid bundling validator.js (~28KB) in the main chunk.
74
+ registerFieldComponent("currency", CurrencyField);
75
+ registerFieldComponent("entity_picker", EntityPickerField);
76
+ registerFieldComponent("slug", SlugField);
77
+ registerFieldComponent("tags", TagsField);
78
+ registerFieldComponent("file", FileUploadField);
79
+ registerFieldComponent("rating", RatingField);
80
+ registerFieldComponent("color", ColorField);
81
+ registerFieldComponent("static", StaticField);
82
+
83
+ // Note: "phone" is NOT registered here — it's lazy-loaded in FormField.tsx
84
+ // to avoid bundling libphonenumber-js (~40KB) in the main chunk.
85
+ // Custom renderers that need phone support should lazy-import PhoneField.
86
+ }
@@ -0,0 +1,192 @@
1
+ /**
2
+ * form-schema-builder — generates a Zod validation schema from a FormSchemaNode tree.
3
+ *
4
+ * Walks the server-sent schema, extracts visible fields, and builds Zod validators
5
+ * from field type + validation props. Used by FormPanelBlock with zodResolver for
6
+ * react-hook-form client-side validation.
7
+ *
8
+ * The same form is always re-validated server-side via Inertia — this is an additive
9
+ * UX improvement, not a replacement for server validation.
10
+ */
11
+
12
+ import type { TFunction } from "i18next";
13
+ import { z, type ZodTypeAny } from "zod";
14
+
15
+ import type { DocumentScope, DocumentType } from "@/base/form/fields/document-validation";
16
+ import { extractFields, isFieldRequired, isFieldVisible } from "@/base/form/form-utils";
17
+ import type { FormFieldNode, FormSchemaNode } from "@/contracts/block-data";
18
+
19
+ type TranslateFn = TFunction;
20
+
21
+ /**
22
+ * Build a Zod validator for a single form field based on its type and props.
23
+ *
24
+ * `required` is the effective required state already resolved by the caller
25
+ * (static `required` prop OR a matching `required_when` condition), not the raw
26
+ * `props.required`.
27
+ */
28
+ function buildFieldSchema(
29
+ field: Exclude<FormFieldNode, import("@/contracts/block-data").HeaderFormField>,
30
+ t: TranslateFn,
31
+ required: boolean,
32
+ ): ZodTypeAny {
33
+ const { component, props } = field;
34
+ const v = props.validation;
35
+ const req = required;
36
+
37
+ switch (component) {
38
+ case "text":
39
+ case "textarea":
40
+ case "password":
41
+ case "slug":
42
+ case "color": {
43
+ let s = z.string();
44
+ if (req) s = s.min(1, t("middag.ui.validation.required"));
45
+ if (v?.minLength)
46
+ s = s.min(v.minLength, t("middag.ui.validation.min_length", { min: v.minLength }));
47
+ if (v?.maxLength)
48
+ s = s.max(v.maxLength, t("middag.ui.validation.max_length", { max: v.maxLength }));
49
+ if (v?.pattern)
50
+ s = s.regex(new RegExp(v.pattern), v.patternMessage ?? t("middag.ui.validation.pattern"));
51
+ return req ? s : s.or(z.literal(""));
52
+ }
53
+
54
+ case "email": {
55
+ let s = z.string();
56
+ if (req) {
57
+ s = s.min(1, t("middag.ui.validation.required")).email(t("middag.ui.validation.email"));
58
+ } else {
59
+ return s.email(t("middag.ui.validation.email")).or(z.literal(""));
60
+ }
61
+ return s;
62
+ }
63
+
64
+ case "url": {
65
+ let s = z.string();
66
+ if (req) {
67
+ s = s.min(1, t("middag.ui.validation.required")).url(t("middag.ui.validation.url"));
68
+ } else {
69
+ return s.url(t("middag.ui.validation.url")).or(z.literal(""));
70
+ }
71
+ return s;
72
+ }
73
+
74
+ case "int": {
75
+ let n = z
76
+ .number({ message: t("middag.ui.validation.integer") })
77
+ .int(t("middag.ui.validation.integer"));
78
+ if (props.min != null)
79
+ n = n.min(props.min, t("middag.ui.validation.min_value", { min: props.min }));
80
+ if (props.max != null)
81
+ n = n.max(props.max, t("middag.ui.validation.max_value", { max: props.max }));
82
+ return req ? n : n.nullable();
83
+ }
84
+
85
+ case "float": {
86
+ let n = z.number();
87
+ if (props.min != null)
88
+ n = n.min(props.min, t("middag.ui.validation.min_value", { min: props.min }));
89
+ if (props.max != null)
90
+ n = n.max(props.max, t("middag.ui.validation.max_value", { max: props.max }));
91
+ return req ? n : n.nullable();
92
+ }
93
+
94
+ case "currency": {
95
+ const n = z.number();
96
+ return req ? n : n.nullable();
97
+ }
98
+
99
+ case "select":
100
+ case "radio":
101
+ case "entity_picker": {
102
+ const s = z.string();
103
+ return req ? s.min(1, t("middag.ui.validation.required")) : s;
104
+ }
105
+
106
+ case "multiselect":
107
+ case "tags": {
108
+ const a = z.array(z.string());
109
+ return req ? a.min(1, t("middag.ui.validation.required")) : a;
110
+ }
111
+
112
+ case "checkbox":
113
+ case "switch":
114
+ return z.boolean();
115
+
116
+ case "date":
117
+ case "datetime": {
118
+ const s = z.string();
119
+ return req ? s.min(1, t("middag.ui.validation.required")) : s;
120
+ }
121
+
122
+ case "phone": {
123
+ const s = z.string();
124
+ if (req) return s.min(1, t("middag.ui.validation.required"));
125
+ return s;
126
+ }
127
+
128
+ case "document": {
129
+ const docType = (props.documentType ?? "generic") as DocumentType;
130
+ const docScope = (props.documentScope ?? "any") as DocumentScope;
131
+ const s = z.string();
132
+ // Validate lazily: the validator.js-backed checksum module (~28 KB) is
133
+ // dynamically imported only when a document field is actually validated,
134
+ // so it never enters the FormPanelBlock chunk for document-less forms.
135
+ // The async refine is fine — zodResolver runs in async mode by default.
136
+ const isValid = async (val: string) => {
137
+ const { isValidDocument } = await import("@/base/form/fields/document-validation");
138
+ return isValidDocument(val, docType, docScope);
139
+ };
140
+ if (req) {
141
+ return s
142
+ .min(1, t("middag.ui.validation.required"))
143
+ .refine(isValid, t("middag.ui.validation.document_invalid"));
144
+ }
145
+ return s.refine(
146
+ async (val) => val === "" || (await isValid(val)),
147
+ t("middag.ui.validation.document_invalid"),
148
+ );
149
+ }
150
+
151
+ // file, hidden, static, header, duration — no client validation
152
+ default:
153
+ return z.any();
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Build a complete Zod schema from a FormSchemaNode tree.
159
+ *
160
+ * Only visible fields are included in the schema — hidden fields are not validated.
161
+ * Call this function whenever form values change to rebuild the schema with updated
162
+ * visibility conditions.
163
+ *
164
+ * @param schema - The server-sent form schema tree
165
+ * @param values - Current form values (used for conditional visibility evaluation)
166
+ * @param t - Translation function for error messages
167
+ */
168
+ export function buildFormSchema(
169
+ schema: FormSchemaNode[],
170
+ values: Record<string, unknown>,
171
+ t: TranslateFn,
172
+ ): z.ZodObject<Record<string, ZodTypeAny>> {
173
+ const allFields = extractFields(schema);
174
+ const shape: Record<string, ZodTypeAny> = {};
175
+
176
+ for (const field of allFields) {
177
+ // Skip non-interactive and hidden fields
178
+ if (
179
+ field.component === "header" ||
180
+ field.component === "hidden" ||
181
+ field.component === "static"
182
+ ) {
183
+ continue;
184
+ }
185
+ if (!isFieldVisible(field, values)) {
186
+ continue;
187
+ }
188
+ shape[field.key] = buildFieldSchema(field, t, isFieldRequired(field, values));
189
+ }
190
+
191
+ return z.object(shape);
192
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Form utility functions shared between FormPanelBlock and form-schema-builder.
3
+ */
4
+
5
+ import { evaluateCondition } from "@/base/utils/conditions";
6
+ import type { FormFieldNode, FormSchemaNode } from "@/contracts/block-data";
7
+
8
+ /**
9
+ * Extract all field nodes from a recursive schema tree.
10
+ */
11
+ export function extractFields(nodes: FormSchemaNode[]): FormFieldNode[] {
12
+ const fields: FormFieldNode[] = [];
13
+ for (const node of nodes) {
14
+ if (node.kind === "field") {
15
+ fields.push(node);
16
+ } else if (node.kind === "section" || node.kind === "group") {
17
+ fields.push(...extractFields(node.children));
18
+ }
19
+ }
20
+ return fields;
21
+ }
22
+
23
+ /**
24
+ * Check if a field is visible given current form values.
25
+ * Headers are always visible (they have no conditional props).
26
+ */
27
+ export function isFieldVisible(field: FormFieldNode, values: Record<string, unknown>): boolean {
28
+ if (field.component === "header") return true;
29
+ const { props } = field;
30
+ if (props.hidden_when && evaluateCondition(props.hidden_when, values)) {
31
+ return false;
32
+ }
33
+ if (props.visible_when && !evaluateCondition(props.visible_when, values)) {
34
+ return false;
35
+ }
36
+ return true;
37
+ }
38
+
39
+ /**
40
+ * Check if a field is disabled given current form values.
41
+ * Combines the static `disabled` prop with the conditional `disabled_when` rule.
42
+ * Headers are never disabled (they have no conditional props).
43
+ */
44
+ export function isFieldDisabled(field: FormFieldNode, values: Record<string, unknown>): boolean {
45
+ if (field.component === "header") return false;
46
+ const { props } = field;
47
+ if (props.disabled) return true;
48
+ if (props.disabled_when && evaluateCondition(props.disabled_when, values)) {
49
+ return true;
50
+ }
51
+ return false;
52
+ }
53
+
54
+ /**
55
+ * Check if a field is required given current form values.
56
+ * Combines the static `required` prop with the conditional `required_when` rule.
57
+ *
58
+ * A disabled field is never treated as required: the user cannot fill it, so
59
+ * enforcing required would make the form impossible to submit (UX deadlock).
60
+ * Headers are never required.
61
+ */
62
+ export function isFieldRequired(field: FormFieldNode, values: Record<string, unknown>): boolean {
63
+ if (field.component === "header") return false;
64
+ if (isFieldDisabled(field, values)) return false;
65
+ const { props } = field;
66
+ if (props.required) return true;
67
+ if (props.required_when && evaluateCondition(props.required_when, values)) {
68
+ return true;
69
+ }
70
+ return false;
71
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * useIsDark — reactive dark mode detection via MutationObserver.
3
+ *
4
+ * Watches `document.documentElement` for class changes and returns
5
+ * whether the `dark` class is currently present. Shared source of
6
+ * truth for all components that need to react to theme changes
7
+ * (mock headers, shells, etc.).
8
+ *
9
+ * Does NOT control the theme — use cycleAppearance() for that.
10
+ */
11
+
12
+ import { useSyncExternalStore } from "react";
13
+
14
+ function getSnapshot(): boolean {
15
+ return document.documentElement.classList.contains("dark");
16
+ }
17
+
18
+ function getServerSnapshot(): boolean {
19
+ return false;
20
+ }
21
+
22
+ let listeners: Array<() => void> = [];
23
+
24
+ let observing = false;
25
+
26
+ function startObserver(): void {
27
+ if (observing) return;
28
+ observing = true;
29
+
30
+ const observer = new MutationObserver(() => {
31
+ listeners.forEach((l) => l());
32
+ });
33
+
34
+ observer.observe(document.documentElement, {
35
+ attributes: true,
36
+ attributeFilter: ["class"],
37
+ });
38
+ }
39
+
40
+ function subscribe(listener: () => void): () => void {
41
+ listeners = [...listeners, listener];
42
+ startObserver();
43
+ return () => {
44
+ listeners = listeners.filter((l) => l !== listener);
45
+ };
46
+ }
47
+
48
+ export function useIsDark(): boolean {
49
+ return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
50
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * useLazyTabs — lazy-loads Inertia partial data when a tab is activated.
3
+ *
4
+ * Tracks which tabs have been loaded, which are in-flight, and which
5
+ * failed. Consumers call `handleTabChange` on every tab switch;
6
+ * the hook triggers `router.reload({ only: [tab] })` for tabs that
7
+ * haven't been fetched yet.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const { handleTabChange, isLoading, hasError, retryTab } = useLazyTabs("overview");
12
+ *
13
+ * <SomeTabsComponent onTabChange={handleTabChange}>
14
+ * <Tab key="overview">...</Tab>
15
+ * <Tab key="invoices">
16
+ * {isLoading("invoices") ? <Spinner /> : <InvoiceTable />}
17
+ * {hasError("invoices") && <RetryButton onClick={() => retryTab("invoices")} />}
18
+ * </Tab>
19
+ * </SomeTabsComponent>
20
+ * ```
21
+ *
22
+ * Imperative escape hatch: for simple per-tab loading without retry/error
23
+ * tracking, prefer the declarative `<WhenVisible data={tab}>` (loads when the
24
+ * tab panel scrolls into view) or `<Deferred data={tab}>` from
25
+ * `@inertiajs/react`. This hook stays for cases that need explicit
26
+ * loading/error state and a `retryTab` affordance the primitives don't expose.
27
+ */
28
+
29
+ import { useCallback, useState } from "react";
30
+ import { router } from "@inertiajs/react";
31
+
32
+ export interface UseLazyTabsReturn {
33
+ /** Call on every tab switch — triggers partial reload for unloaded tabs. */
34
+ handleTabChange: (tab: string) => void;
35
+ /** True while a tab's data is being fetched. */
36
+ isLoading: (tab: string) => boolean;
37
+ /** True if a tab's fetch failed. */
38
+ hasError: (tab: string) => boolean;
39
+ /** Re-fetch a previously failed tab. */
40
+ retryTab: (tab: string) => void;
41
+ }
42
+
43
+ export function useLazyTabs(defaultTab: string): UseLazyTabsReturn {
44
+ const [loadedTabs, setLoadedTabs] = useState<Set<string>>(new Set([defaultTab]));
45
+ const [loadingTabs, setLoadingTabs] = useState<Set<string>>(new Set());
46
+ const [errorTabs, setErrorTabs] = useState<Set<string>>(new Set());
47
+
48
+ const triggerLoad = useCallback((tab: string) => {
49
+ setLoadingTabs((prev) => new Set([...prev, tab]));
50
+ setErrorTabs((prev) => {
51
+ const next = new Set(prev);
52
+ next.delete(tab);
53
+ return next;
54
+ });
55
+
56
+ router.reload({
57
+ only: [tab],
58
+ onSuccess: () => {
59
+ setLoadedTabs((prev) => new Set([...prev, tab]));
60
+ setLoadingTabs((prev) => {
61
+ const next = new Set(prev);
62
+ next.delete(tab);
63
+ return next;
64
+ });
65
+ },
66
+ onError: () => {
67
+ setErrorTabs((prev) => new Set([...prev, tab]));
68
+ setLoadingTabs((prev) => {
69
+ const next = new Set(prev);
70
+ next.delete(tab);
71
+ return next;
72
+ });
73
+ },
74
+ });
75
+ }, []);
76
+
77
+ const handleTabChange = useCallback(
78
+ (tab: string) => {
79
+ if (tab !== defaultTab && !loadedTabs.has(tab) && !loadingTabs.has(tab)) {
80
+ triggerLoad(tab);
81
+ }
82
+ },
83
+ [defaultTab, loadedTabs, loadingTabs, triggerLoad],
84
+ );
85
+
86
+ const isLoading = useCallback((tab: string) => loadingTabs.has(tab), [loadingTabs]);
87
+
88
+ const hasError = useCallback((tab: string) => errorTabs.has(tab), [errorTabs]);
89
+
90
+ const retryTab = useCallback(
91
+ (tab: string) => {
92
+ triggerLoad(tab);
93
+ },
94
+ [triggerLoad],
95
+ );
96
+
97
+ return { handleTabChange, isLoading, hasError, retryTab };
98
+ }