@middag-io/react 0.45.0 → 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 (320) hide show
  1. package/docs/public/schemas/ai-contract-manifest.json +1820 -0
  2. package/docs/public/schemas/blocks.json +445 -0
  3. package/docs/public/schemas/components.json +166 -0
  4. package/docs/public/schemas/connectors.json +97 -0
  5. package/docs/public/schemas/fragment.json +2329 -0
  6. package/docs/public/schemas/manifest.json +119 -0
  7. package/docs/public/schemas/navigation.json +72 -0
  8. package/docs/public/schemas/page-contract.json +2329 -0
  9. package/docs/public/schemas/shared-props.json +118 -0
  10. package/docs/public/schemas/theme-defaults.json +253 -0
  11. package/docs/public/schemas/theme.json +401 -0
  12. package/package.json +109 -3
  13. package/src/assets/lottie/calendar/schedule-1.json +1 -0
  14. package/src/assets/lottie/calendar/schedule-2.json +1 -0
  15. package/src/assets/lottie/celebration/confetti-1.json +1 -0
  16. package/src/assets/lottie/celebration/confetti-2.json +1 -0
  17. package/src/assets/lottie/celebration/confetti-3.json +1 -0
  18. package/src/assets/lottie/cloud/cloud-1.json +1 -0
  19. package/src/assets/lottie/cloud/cloud-2.json +1 -0
  20. package/src/assets/lottie/connection/network-1.json +1 -0
  21. package/src/assets/lottie/connection/network-2.json +1 -0
  22. package/src/assets/lottie/connection/network-3.json +1 -0
  23. package/src/assets/lottie/dashboard/analytics-1.json +1 -0
  24. package/src/assets/lottie/dashboard/analytics-2.json +1 -0
  25. package/src/assets/lottie/dashboard/analytics-3.json +1 -0
  26. package/src/assets/lottie/email/mail-1.json +1 -0
  27. package/src/assets/lottie/email/mail-2.json +1 -0
  28. package/src/assets/lottie/email/mail-3.json +1 -0
  29. package/src/assets/lottie/empty-state/empty-1.json +1 -0
  30. package/src/assets/lottie/empty-state/empty-2.json +1 -0
  31. package/src/assets/lottie/empty-state/empty-3.json +1 -0
  32. package/src/assets/lottie/error/warning-1.json +1 -0
  33. package/src/assets/lottie/error/warning-2.json +1 -0
  34. package/src/assets/lottie/error/warning-3.json +1 -0
  35. package/src/assets/lottie/index.ts +49 -0
  36. package/src/assets/lottie/loading/spinner-1.json +1 -0
  37. package/src/assets/lottie/loading/spinner-2.json +1 -0
  38. package/src/assets/lottie/loading/spinner-3.json +1 -0
  39. package/src/assets/lottie/maintenance/construction-1.json +1 -0
  40. package/src/assets/lottie/maintenance/construction-2.json +1 -0
  41. package/src/assets/lottie/maintenance/construction-3.json +1 -0
  42. package/src/assets/lottie/not-found/404-1.json +1 -0
  43. package/src/assets/lottie/not-found/404-2.json +1 -0
  44. package/src/assets/lottie/not-found/404-3.json +1 -0
  45. package/src/assets/lottie/notification/bell-1.json +1 -0
  46. package/src/assets/lottie/notification/bell-2.json +1 -0
  47. package/src/assets/lottie/notification/bell-3.json +1 -0
  48. package/src/assets/lottie/onboarding/welcome-1.json +1 -0
  49. package/src/assets/lottie/onboarding/welcome-2.json +1 -0
  50. package/src/assets/lottie/onboarding/welcome-3.json +1 -0
  51. package/src/assets/lottie/payment/wallet-1.json +1 -0
  52. package/src/assets/lottie/payment/wallet-2.json +1 -0
  53. package/src/assets/lottie/payment/wallet-3.json +1 -0
  54. package/src/assets/lottie/search/search-1.json +1 -0
  55. package/src/assets/lottie/search/search-2.json +1 -0
  56. package/src/assets/lottie/search/search-3.json +1 -0
  57. package/src/assets/lottie/security/lock-1.json +1 -0
  58. package/src/assets/lottie/security/lock-2.json +1 -0
  59. package/src/assets/lottie/security/lock-3.json +1 -0
  60. package/src/assets/lottie/settings/gear-1.json +1 -0
  61. package/src/assets/lottie/settings/gear-2.json +1 -0
  62. package/src/assets/lottie/settings/gear-3.json +1 -0
  63. package/src/assets/lottie/success/check-1.json +1 -0
  64. package/src/assets/lottie/success/check-2.json +1 -0
  65. package/src/assets/lottie/success/check-3.json +1 -0
  66. package/src/assets/lottie/upload/upload-1.json +1 -0
  67. package/src/assets/lottie/upload/upload-2.json +1 -0
  68. package/src/assets/lottie/upload/upload-3.json +1 -0
  69. package/src/assets/lottie/user/profile-1.json +1 -0
  70. package/src/assets/lottie/user/profile-2.json +1 -0
  71. package/src/assets/lottie/user/profile-3.json +1 -0
  72. package/src/base/blocks/ActionGridBlock.tsx +151 -0
  73. package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
  74. package/src/base/blocks/CardGridBlock.tsx +384 -0
  75. package/src/base/blocks/ChartBlock.tsx +81 -0
  76. package/src/base/blocks/DenseTableBlock.tsx +403 -0
  77. package/src/base/blocks/DetailPanelBlock.tsx +189 -0
  78. package/src/base/blocks/EmptyStateBlock.tsx +46 -0
  79. package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
  80. package/src/base/blocks/FormPanelBlock.tsx +480 -0
  81. package/src/base/blocks/LinkListBlock.tsx +94 -0
  82. package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
  83. package/src/base/blocks/MetricCardBlock.tsx +128 -0
  84. package/src/base/blocks/StatusStripBlock.tsx +43 -0
  85. package/src/base/blocks/TabsBlock.tsx +94 -0
  86. package/src/base/form/FormField.tsx +607 -0
  87. package/src/base/form/fields/CheckboxField.tsx +56 -0
  88. package/src/base/form/fields/ColorField.tsx +76 -0
  89. package/src/base/form/fields/CurrencyField.tsx +126 -0
  90. package/src/base/form/fields/DateField.tsx +168 -0
  91. package/src/base/form/fields/DateRangeField.tsx +66 -0
  92. package/src/base/form/fields/DocumentField.tsx +222 -0
  93. package/src/base/form/fields/EntityPickerField.tsx +244 -0
  94. package/src/base/form/fields/FileUploadField.tsx +253 -0
  95. package/src/base/form/fields/MultiSelectField.tsx +286 -0
  96. package/src/base/form/fields/NativeSelectField.tsx +67 -0
  97. package/src/base/form/fields/NumberField.tsx +67 -0
  98. package/src/base/form/fields/OtpField.tsx +88 -0
  99. package/src/base/form/fields/PasswordField.tsx +69 -0
  100. package/src/base/form/fields/PhoneField.tsx +64 -0
  101. package/src/base/form/fields/RadioField.tsx +66 -0
  102. package/src/base/form/fields/RatingField.tsx +52 -0
  103. package/src/base/form/fields/SelectField.tsx +76 -0
  104. package/src/base/form/fields/SliderField.tsx +77 -0
  105. package/src/base/form/fields/SlugField.tsx +114 -0
  106. package/src/base/form/fields/StaticField.tsx +25 -0
  107. package/src/base/form/fields/SwitchField.tsx +56 -0
  108. package/src/base/form/fields/TagsField.tsx +128 -0
  109. package/src/base/form/fields/TextField.tsx +55 -0
  110. package/src/base/form/fields/TextareaField.tsx +55 -0
  111. package/src/base/form/fields/document-validation.ts +126 -0
  112. package/src/base/form/fields/field-registry.ts +53 -0
  113. package/src/base/form/fields/register-default-fields.ts +86 -0
  114. package/src/base/form/form-schema-builder.ts +192 -0
  115. package/src/base/form/form-utils.ts +71 -0
  116. package/src/base/hooks/useIsDark.ts +50 -0
  117. package/src/base/hooks/useLazyTabs.ts +98 -0
  118. package/src/base/hooks/usePolling.ts +43 -0
  119. package/src/base/hooks/useRemember.ts +58 -0
  120. package/src/base/hooks/useToast.ts +27 -0
  121. package/src/base/layout/BlockRegion.tsx +39 -0
  122. package/src/base/layout/DashboardLayout.tsx +110 -0
  123. package/src/base/layout/SidebarLayout.tsx +38 -0
  124. package/src/base/layout/StackLayout.tsx +32 -0
  125. package/src/base/layout/WizardLayout.tsx +49 -0
  126. package/src/base/partials/ActionBar/index.tsx +115 -0
  127. package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
  128. package/src/base/partials/DataTable/cell-registry.ts +50 -0
  129. package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
  130. package/src/base/partials/DataTable/index.tsx +1282 -0
  131. package/src/base/partials/DataTable/register-default-cells.ts +37 -0
  132. package/src/base/partials/DataTable/sanitize-html.ts +45 -0
  133. package/src/base/partials/DataTable/types.ts +229 -0
  134. package/src/base/partials/DetailSection/index.tsx +316 -0
  135. package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
  136. package/src/base/partials/EntityItem/index.tsx +154 -0
  137. package/src/base/partials/FilterBar/index.tsx +256 -0
  138. package/src/base/partials/FormSection/index.tsx +87 -0
  139. package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
  140. package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
  141. package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
  142. package/src/base/partials/LogViewer/index.tsx +110 -0
  143. package/src/base/partials/LogViewer/types.ts +28 -0
  144. package/src/base/partials/MarkdownContent/index.tsx +307 -0
  145. package/src/base/partials/MenuBar/index.tsx +80 -0
  146. package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
  147. package/src/base/partials/ResizableSidebar/index.tsx +70 -0
  148. package/src/base/partials/StatRow/index.tsx +28 -0
  149. package/src/base/partials/StatusBar/index.tsx +126 -0
  150. package/src/base/partials/StatusIndicator/index.tsx +61 -0
  151. package/src/base/partials/StepIndicator/index.tsx +63 -0
  152. package/src/base/partials/TableOfContents/index.tsx +78 -0
  153. package/src/base/partials/TimelineList/index.tsx +273 -0
  154. package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
  155. package/src/base/partials/TreeView/index.tsx +75 -0
  156. package/src/base/partials/index.ts +23 -0
  157. package/src/base/shell/AuthShell.tsx +54 -0
  158. package/src/base/shell/BasicShell.tsx +286 -0
  159. package/src/base/shell/ImmersiveShell.tsx +85 -0
  160. package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
  161. package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
  162. package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
  163. package/src/base/shell/partials/InspectorContext.tsx +173 -0
  164. package/src/base/shell/partials/InspectorPanel.tsx +65 -0
  165. package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
  166. package/src/base/shell/partials/OverlayScreen.tsx +67 -0
  167. package/src/base/shell/partials/PageActionButton.tsx +203 -0
  168. package/src/base/theme/appearance.ts +133 -0
  169. package/src/base/theme/host-layout-detector.ts +119 -0
  170. package/src/base/theme/host-theme-detector.ts +146 -0
  171. package/src/base/theme/sidebar-safelist.txt +20 -0
  172. package/src/base/theme/tailwind-theme.css +136 -0
  173. package/src/base/theme/theme-bridge.css +164 -0
  174. package/src/base/theme/theme-context.tsx +142 -0
  175. package/src/base/theme/themes/classic.css +174 -0
  176. package/src/base/theme/tokens.css +290 -0
  177. package/src/base/theme/useHostTheme.ts +95 -0
  178. package/src/base/utils/clipboard.ts +39 -0
  179. package/src/base/utils/conditions.ts +27 -0
  180. package/src/base/utils/icon-registry.ts +78 -0
  181. package/src/base/utils/icons.ts +31 -0
  182. package/src/base/utils/interpolate.ts +9 -0
  183. package/src/base/utils/register-default-icons.ts +163 -0
  184. package/src/base/utils/storage.ts +65 -0
  185. package/src/base/utils/time.ts +139 -0
  186. package/src/contracts/block-data/actions.ts +73 -0
  187. package/src/contracts/block-data/data-display.ts +343 -0
  188. package/src/contracts/block-data/form.ts +164 -0
  189. package/src/contracts/block-data/index.ts +15 -0
  190. package/src/contracts/block-data/interactive.ts +34 -0
  191. package/src/contracts/block-data/shared.ts +44 -0
  192. package/src/contracts/connectors.ts +60 -0
  193. package/src/contracts/generated/contract-schema.ts +1237 -0
  194. package/src/contracts/generated/contract-types.ts +675 -0
  195. package/src/contracts/generated/index.ts +15 -0
  196. package/src/contracts/navigation.ts +59 -0
  197. package/src/contracts/page-contract-schema.ts +40 -0
  198. package/src/contracts/page-contract.ts +79 -0
  199. package/src/contracts/shared-props.ts +92 -0
  200. package/src/engine/ContractPage.tsx +178 -0
  201. package/src/engine/EntityRoutes.tsx +72 -0
  202. package/src/engine/HostSlot.tsx +126 -0
  203. package/src/engine/LazyBlock.tsx +92 -0
  204. package/src/engine/bootstrap.tsx +20 -0
  205. package/src/engine/providers/auth.tsx +87 -0
  206. package/src/engine/providers/error-reporter.tsx +89 -0
  207. package/src/engine/providers/flash.tsx +44 -0
  208. package/src/engine/providers/index.ts +18 -0
  209. package/src/engine/providers/inertia-error-reporter.tsx +61 -0
  210. package/src/engine/providers/progress.tsx +56 -0
  211. package/src/engine/providers/scope.tsx +51 -0
  212. package/src/engine/register-defaults.ts +88 -0
  213. package/src/engine/registries.ts +96 -0
  214. package/src/i18n/I18nProvider.tsx +53 -0
  215. package/src/i18n/MANIFEST.md +101 -0
  216. package/src/i18n/host-resolver.ts +18 -0
  217. package/src/i18n/instance.ts +69 -0
  218. package/src/i18n/locales/en/ui.json +277 -0
  219. package/src/i18n/locales/en/validators.json +13 -0
  220. package/src/i18n/locales/pt-BR/ui.json +277 -0
  221. package/src/i18n/locales/pt-BR/validators.json +13 -0
  222. package/src/i18n/register-strings.ts +10 -0
  223. package/src/i18n/render-label.ts +33 -0
  224. package/src/i18n/resolve-field-error.ts +29 -0
  225. package/src/i18n/useHostString.ts +50 -0
  226. package/src/i18n/useTranslation.ts +83 -0
  227. package/src/lib/actions/resolve-action-target.ts +151 -0
  228. package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
  229. package/src/lib/hooks/use-file-upload.ts +406 -0
  230. package/src/lib/hooks/use-mobile.ts +21 -0
  231. package/src/lib/host-pending.ts +76 -0
  232. package/src/lib/portal-container.ts +16 -0
  233. package/src/lib/test-ids.ts +40 -0
  234. package/src/lib/utils.ts +6 -0
  235. package/src/primitives/reui/MANIFEST.md +97 -0
  236. package/src/primitives/reui/accordion.tsx +64 -0
  237. package/src/primitives/reui/alert-dialog.tsx +196 -0
  238. package/src/primitives/reui/alert.tsx +92 -0
  239. package/src/primitives/reui/aspect-ratio.tsx +9 -0
  240. package/src/primitives/reui/autocomplete.tsx +343 -0
  241. package/src/primitives/reui/avatar.tsx +109 -0
  242. package/src/primitives/reui/badge.tsx +94 -0
  243. package/src/primitives/reui/breadcrumb.tsx +109 -0
  244. package/src/primitives/reui/button-group.tsx +83 -0
  245. package/src/primitives/reui/button.tsx +64 -0
  246. package/src/primitives/reui/calendar.tsx +220 -0
  247. package/src/primitives/reui/card.tsx +92 -0
  248. package/src/primitives/reui/carousel.tsx +239 -0
  249. package/src/primitives/reui/chart.tsx +388 -0
  250. package/src/primitives/reui/checkbox.tsx +30 -0
  251. package/src/primitives/reui/collapsible.tsx +31 -0
  252. package/src/primitives/reui/combobox.tsx +308 -0
  253. package/src/primitives/reui/command.tsx +182 -0
  254. package/src/primitives/reui/context-menu.tsx +250 -0
  255. package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
  256. package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
  257. package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
  258. package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
  259. package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
  260. package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
  261. package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
  262. package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
  263. package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
  264. package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
  265. package/src/primitives/reui/data-grid-pagination.tsx +235 -0
  266. package/src/primitives/reui/date-selector.tsx +1353 -0
  267. package/src/primitives/reui/dialog.tsx +158 -0
  268. package/src/primitives/reui/drawer.tsx +133 -0
  269. package/src/primitives/reui/dropdown-menu.tsx +257 -0
  270. package/src/primitives/reui/empty.tsx +104 -0
  271. package/src/primitives/reui/field.tsx +246 -0
  272. package/src/primitives/reui/filters.tsx +1891 -0
  273. package/src/primitives/reui/frame.tsx +170 -0
  274. package/src/primitives/reui/hover-card.tsx +42 -0
  275. package/src/primitives/reui/icon-placeholder.tsx +39 -0
  276. package/src/primitives/reui/index.ts +98 -0
  277. package/src/primitives/reui/input-group.tsx +170 -0
  278. package/src/primitives/reui/input-otp.tsx +75 -0
  279. package/src/primitives/reui/input.tsx +21 -0
  280. package/src/primitives/reui/item.tsx +193 -0
  281. package/src/primitives/reui/kanban.tsx +743 -0
  282. package/src/primitives/reui/kbd.tsx +28 -0
  283. package/src/primitives/reui/label.tsx +22 -0
  284. package/src/primitives/reui/menubar.tsx +274 -0
  285. package/src/primitives/reui/native-select.tsx +62 -0
  286. package/src/primitives/reui/navigation-menu.tsx +168 -0
  287. package/src/primitives/reui/number-field.tsx +250 -0
  288. package/src/primitives/reui/pagination.tsx +127 -0
  289. package/src/primitives/reui/phone-input.tsx +231 -0
  290. package/src/primitives/reui/popover.tsx +87 -0
  291. package/src/primitives/reui/progress.tsx +31 -0
  292. package/src/primitives/reui/radio-group.tsx +43 -0
  293. package/src/primitives/reui/rating.tsx +177 -0
  294. package/src/primitives/reui/resizable.tsx +51 -0
  295. package/src/primitives/reui/scroll-area.tsx +58 -0
  296. package/src/primitives/reui/scrollspy.tsx +240 -0
  297. package/src/primitives/reui/select.tsx +188 -0
  298. package/src/primitives/reui/separator.tsx +28 -0
  299. package/src/primitives/reui/sheet.tsx +141 -0
  300. package/src/primitives/reui/sidebar.tsx +732 -0
  301. package/src/primitives/reui/skeleton.tsx +13 -0
  302. package/src/primitives/reui/slider.tsx +61 -0
  303. package/src/primitives/reui/sonner.tsx +47 -0
  304. package/src/primitives/reui/sortable.tsx +414 -0
  305. package/src/primitives/reui/spinner.tsx +16 -0
  306. package/src/primitives/reui/stepper.tsx +484 -0
  307. package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
  308. package/src/primitives/reui/svgs/gemini.tsx +171 -0
  309. package/src/primitives/reui/svgs/openai.tsx +9 -0
  310. package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
  311. package/src/primitives/reui/switch.tsx +33 -0
  312. package/src/primitives/reui/table.tsx +114 -0
  313. package/src/primitives/reui/tabs.tsx +91 -0
  314. package/src/primitives/reui/textarea.tsx +18 -0
  315. package/src/primitives/reui/timeline.tsx +219 -0
  316. package/src/primitives/reui/toggle-group.tsx +83 -0
  317. package/src/primitives/reui/toggle.tsx +45 -0
  318. package/src/primitives/reui/tooltip.tsx +55 -0
  319. package/src/primitives/reui/tree.tsx +247 -0
  320. package/src/theme.css +71 -0
@@ -0,0 +1,607 @@
1
+ /**
2
+ * FormField -- router component that renders the correct input based on field type.
3
+ *
4
+ * Receives a field descriptor and delegates to the matching field component.
5
+ * Wraps each field in a consistent layout: label, help text, input, error message.
6
+ */
7
+
8
+ import { lazy, Suspense, useId, type ReactElement, type ReactNode } from "react";
9
+ import type { TFunction } from "i18next";
10
+
11
+ import { CheckboxField } from "@/base/form/fields/CheckboxField";
12
+ import { ColorField } from "@/base/form/fields/ColorField";
13
+ import { CurrencyField } from "@/base/form/fields/CurrencyField";
14
+ // DateField, DocumentField, PhoneField are lazy-loaded — see below
15
+ import { EntityPickerField } from "@/base/form/fields/EntityPickerField";
16
+ import { FileUploadField } from "@/base/form/fields/FileUploadField";
17
+ import { MultiSelectField } from "@/base/form/fields/MultiSelectField";
18
+ import { NativeSelectField } from "@/base/form/fields/NativeSelectField";
19
+ import { NumberFieldComponent } from "@/base/form/fields/NumberField";
20
+ import { OtpField } from "@/base/form/fields/OtpField";
21
+ import { PasswordField } from "@/base/form/fields/PasswordField";
22
+ import { RadioField } from "@/base/form/fields/RadioField";
23
+ import { RatingField } from "@/base/form/fields/RatingField";
24
+ import { SelectField } from "@/base/form/fields/SelectField";
25
+ import { SliderField } from "@/base/form/fields/SliderField";
26
+ import { SlugField } from "@/base/form/fields/SlugField";
27
+ import { StaticField } from "@/base/form/fields/StaticField";
28
+ import { SwitchField } from "@/base/form/fields/SwitchField";
29
+ import { TagsField } from "@/base/form/fields/TagsField";
30
+ import { TextareaField } from "@/base/form/fields/TextareaField";
31
+ import { TextField } from "@/base/form/fields/TextField";
32
+ import { isFieldDisabled, isFieldRequired } from "@/base/form/form-utils";
33
+ import { useTranslation } from "@/i18n/useTranslation";
34
+ import { fieldTestId } from "@/lib/test-ids";
35
+ import { Label } from "@/primitives/reui/label";
36
+ import { Skeleton } from "@/primitives/reui/skeleton";
37
+
38
+ import { resolveFieldComponent } from "./fields/field-registry";
39
+
40
+ /** Lazy-loaded PhoneField — libphonenumber-js (~40KB) loads only when a phone field renders. */
41
+ const LazyPhoneField = lazy(() =>
42
+ import("@/base/form/fields/PhoneField").then((m) => ({ default: m.PhoneField })),
43
+ );
44
+
45
+ /** Lazy-loaded DateField — date-fns + react-day-picker (~115KB) load only when a date field renders. */
46
+ const LazyDateField = lazy(() =>
47
+ import("@/base/form/fields/DateField").then((m) => ({ default: m.DateField })),
48
+ );
49
+
50
+ /** Lazy-loaded DocumentField — validator.js (~28KB) loads only when a document field renders. */
51
+ const LazyDocumentField = lazy(() =>
52
+ import("@/base/form/fields/DocumentField").then((m) => ({ default: m.DocumentField })),
53
+ );
54
+
55
+ /** Lazy-loaded DateRangeField — date-fns + ReUI DateSelector loads only when a date_range field renders. */
56
+ const LazyDateRangeField = lazy(() =>
57
+ import("@/base/form/fields/DateRangeField").then((m) => ({ default: m.DateRangeField })),
58
+ );
59
+
60
+ function InputSkeleton() {
61
+ return <Skeleton className="h-9 w-full rounded-md" />;
62
+ }
63
+
64
+ export interface FieldOption {
65
+ value: string;
66
+ label: string;
67
+ }
68
+
69
+ /**
70
+ * FieldDescriptor — type alias for the discriminated union FormFieldNode
71
+ * used by FormField component. Narrow by `component` for type-specific props.
72
+ */
73
+ export type FieldDescriptor = import("@/contracts/block-data").FormFieldNode;
74
+
75
+ /**
76
+ * Flattened props union for internal use in renderField().
77
+ * This is the union of ALL possible props across all field variants —
78
+ * used only in the field switch where props are accessed after manual narrowing.
79
+ * Consumer code should use the discriminated union for type-safe narrowing.
80
+ */
81
+ type AnyFieldProps = import("@/contracts/block-data").FieldPropsBase &
82
+ Partial<{
83
+ options: Array<{ value: string; label: string }>;
84
+ min: number;
85
+ max: number;
86
+ step: number;
87
+ rows: number;
88
+ accept: string;
89
+ multiple: boolean;
90
+ maxFiles: number;
91
+ maxSize: number;
92
+ documentType: string;
93
+ documentScope: "person" | "company" | "any";
94
+ documentMasks: Record<string, { pattern: string; maxLength: number; placeholder?: string }>;
95
+ defaultCountry: string;
96
+ fixedCountry: boolean;
97
+ currency: string;
98
+ currencyLocale: string;
99
+ autocompleteHref: string;
100
+ autocompleteMinChars: number;
101
+ initialOption: { value: string; label: string; subtitle?: string; avatarUrl?: string };
102
+ entityDisplayField: string;
103
+ entitySubtitleField: string;
104
+ entityAvatarField: string;
105
+ sourceField: string;
106
+ prefix: string;
107
+ maxTags: number;
108
+ maxRating: number;
109
+ operator: string;
110
+ maxLength: number;
111
+ pattern: "digits" | "alphanumeric";
112
+ groupSize: number;
113
+ }>;
114
+
115
+ export interface FormFieldProps {
116
+ field: FieldDescriptor;
117
+ value: unknown;
118
+ onChange: (value: unknown) => void;
119
+ error?: string;
120
+ sourceValues?: Record<string, unknown>;
121
+ }
122
+
123
+ /**
124
+ * Renders a header separator (non-interactive, no label wrapper).
125
+ */
126
+ function HeaderField({ label }: { label: string }): ReactElement {
127
+ return (
128
+ <div className="pt-4 pb-1">
129
+ <h4 className="text-foreground text-sm font-semibold">{label}</h4>
130
+ </div>
131
+ );
132
+ }
133
+
134
+ /**
135
+ * Renders the input element for the hidden type.
136
+ */
137
+ function HiddenField({ id, value }: { id: string; value: unknown }): ReactElement {
138
+ return <input type="hidden" id={id} value={String(value ?? "")} />;
139
+ }
140
+
141
+ export function FormField({
142
+ field,
143
+ value,
144
+ onChange,
145
+ error,
146
+ sourceValues = {},
147
+ }: FormFieldProps): ReactElement {
148
+ const { t } = useTranslation();
149
+ const generatedId = useId();
150
+ const fieldId = `field-${field.key}-${generatedId}`;
151
+ const helpTextId = `${fieldId}-help`;
152
+ const errorId = `${fieldId}-error`;
153
+
154
+ const { component, props } = field;
155
+
156
+ // Header -- renders just a heading, no label/help/error wrapper.
157
+ if (component === "header") {
158
+ return <HeaderField label={props.label} />;
159
+ }
160
+
161
+ // Hidden -- renders a hidden input, no visible wrapper.
162
+ if (component === "hidden") {
163
+ return <HiddenField id={fieldId} value={value} />;
164
+ }
165
+
166
+ // Resolve conditional state against the current sibling field values.
167
+ // `sourceValues` carries the full form value map, so disabled_when /
168
+ // required_when can be evaluated here.
169
+ const effectiveDisabled = isFieldDisabled(field, sourceValues);
170
+ const effectiveRequired = isFieldRequired(field, sourceValues);
171
+
172
+ // For checkbox and switch, the label is rendered inline by the field itself.
173
+ const isInlineLabel = component === "checkbox" || component === "switch";
174
+
175
+ const fieldContent = renderField(
176
+ component,
177
+ fieldId,
178
+ value,
179
+ onChange,
180
+ props as AnyFieldProps,
181
+ error,
182
+ helpTextId,
183
+ errorId,
184
+ t,
185
+ sourceValues,
186
+ effectiveDisabled,
187
+ effectiveRequired,
188
+ );
189
+
190
+ return (
191
+ <div className="space-y-1.5" data-testid={fieldTestId(field.key)}>
192
+ {/* Label */}
193
+ {!isInlineLabel && (
194
+ <Label htmlFor={fieldId}>
195
+ {props.label}
196
+ {effectiveRequired && <span className="text-destructive ml-0.5">*</span>}
197
+ </Label>
198
+ )}
199
+
200
+ {/* Help text */}
201
+ {props.helpText && (
202
+ <p id={helpTextId} className="text-muted-foreground text-xs">
203
+ {props.helpText}
204
+ </p>
205
+ )}
206
+
207
+ {/* Field component */}
208
+ {fieldContent}
209
+
210
+ {/* Error message */}
211
+ {error && (
212
+ <p id={errorId} className="text-destructive text-xs" aria-live="polite">
213
+ {error}
214
+ </p>
215
+ )}
216
+ </div>
217
+ );
218
+ }
219
+
220
+ /**
221
+ * Switches on component type and renders the correct field component.
222
+ */
223
+ function renderField(
224
+ component: string,
225
+ id: string,
226
+ value: unknown,
227
+ onChange: (value: unknown) => void,
228
+ props: AnyFieldProps,
229
+ error: string | undefined,
230
+ helpTextId: string,
231
+ errorId: string,
232
+ _t: TFunction,
233
+ sourceValues: Record<string, unknown>,
234
+ disabled: boolean,
235
+ required: boolean,
236
+ ): ReactNode {
237
+ const common = {
238
+ id,
239
+ error,
240
+ helpTextId,
241
+ errorId,
242
+ disabled,
243
+ required,
244
+ };
245
+
246
+ switch (component) {
247
+ case "text":
248
+ return (
249
+ <TextField
250
+ {...common}
251
+ type="text"
252
+ value={value as string}
253
+ onChange={onChange as (v: string) => void}
254
+ placeholder={props.placeholder}
255
+ readOnly={props.readOnly}
256
+ />
257
+ );
258
+
259
+ case "email":
260
+ return (
261
+ <TextField
262
+ {...common}
263
+ type="email"
264
+ value={value as string}
265
+ onChange={onChange as (v: string) => void}
266
+ placeholder={props.placeholder}
267
+ readOnly={props.readOnly}
268
+ />
269
+ );
270
+
271
+ case "url":
272
+ return (
273
+ <TextField
274
+ {...common}
275
+ type="url"
276
+ value={value as string}
277
+ onChange={onChange as (v: string) => void}
278
+ placeholder={props.placeholder}
279
+ readOnly={props.readOnly}
280
+ />
281
+ );
282
+
283
+ case "textarea":
284
+ return (
285
+ <TextareaField
286
+ {...common}
287
+ value={value as string}
288
+ onChange={onChange as (v: string) => void}
289
+ placeholder={props.placeholder}
290
+ rows={props.rows}
291
+ readOnly={props.readOnly}
292
+ />
293
+ );
294
+
295
+ case "password":
296
+ return (
297
+ <PasswordField
298
+ {...common}
299
+ value={value as string}
300
+ onChange={onChange as (v: string) => void}
301
+ placeholder={props.placeholder}
302
+ />
303
+ );
304
+
305
+ case "otp":
306
+ return (
307
+ <OtpField
308
+ {...common}
309
+ value={value as string}
310
+ onChange={onChange as (v: string) => void}
311
+ maxLength={props.maxLength}
312
+ pattern={props.pattern}
313
+ groupSize={props.groupSize}
314
+ />
315
+ );
316
+
317
+ case "select":
318
+ return (
319
+ <SelectField
320
+ {...common}
321
+ value={value as string}
322
+ onChange={onChange as (v: string) => void}
323
+ options={props.options ?? []}
324
+ placeholder={props.placeholder}
325
+ />
326
+ );
327
+
328
+ case "native_select":
329
+ return (
330
+ <NativeSelectField
331
+ {...common}
332
+ value={value as string}
333
+ onChange={onChange as (v: string) => void}
334
+ options={props.options ?? []}
335
+ placeholder={props.placeholder}
336
+ />
337
+ );
338
+
339
+ case "multiselect":
340
+ return (
341
+ <MultiSelectField
342
+ {...common}
343
+ value={value as string[]}
344
+ onChange={onChange as (v: string[]) => void}
345
+ options={props.options ?? []}
346
+ placeholder={props.placeholder}
347
+ variant={(props as { variant?: "auto" | "combobox" | "checkbox" }).variant}
348
+ />
349
+ );
350
+
351
+ case "radio":
352
+ return (
353
+ <RadioField
354
+ {...common}
355
+ value={value as string}
356
+ onChange={onChange as (v: string) => void}
357
+ options={props.options ?? []}
358
+ />
359
+ );
360
+
361
+ case "int":
362
+ return (
363
+ <NumberFieldComponent
364
+ {...common}
365
+ value={value as number | null}
366
+ onChange={onChange as (v: number | null) => void}
367
+ min={props.min}
368
+ max={props.max}
369
+ step={1}
370
+ />
371
+ );
372
+
373
+ case "float":
374
+ return (
375
+ <NumberFieldComponent
376
+ {...common}
377
+ value={value as number | null}
378
+ onChange={onChange as (v: number | null) => void}
379
+ min={props.min}
380
+ max={props.max}
381
+ step={props.step ?? 0.1}
382
+ />
383
+ );
384
+
385
+ case "slider":
386
+ return (
387
+ <SliderField
388
+ {...common}
389
+ value={value as number | number[] | null}
390
+ onChange={onChange as (v: number | number[]) => void}
391
+ min={props.min}
392
+ max={props.max}
393
+ step={props.step}
394
+ multiple={props.multiple}
395
+ />
396
+ );
397
+
398
+ case "checkbox":
399
+ return (
400
+ <CheckboxField
401
+ {...common}
402
+ value={value as boolean}
403
+ onChange={onChange as (v: boolean) => void}
404
+ label={props.label}
405
+ />
406
+ );
407
+
408
+ case "switch":
409
+ return (
410
+ <SwitchField
411
+ {...common}
412
+ value={value as boolean}
413
+ onChange={onChange as (v: boolean) => void}
414
+ label={props.label}
415
+ />
416
+ );
417
+
418
+ case "date":
419
+ return (
420
+ <Suspense fallback={<InputSkeleton />}>
421
+ <LazyDateField
422
+ {...common}
423
+ mode="date"
424
+ value={value as string}
425
+ onChange={onChange as (v: string) => void}
426
+ placeholder={props.placeholder}
427
+ />
428
+ </Suspense>
429
+ );
430
+
431
+ case "datetime":
432
+ return (
433
+ <Suspense fallback={<InputSkeleton />}>
434
+ <LazyDateField
435
+ {...common}
436
+ mode="datetime"
437
+ value={value as string}
438
+ onChange={onChange as (v: string) => void}
439
+ placeholder={props.placeholder}
440
+ />
441
+ </Suspense>
442
+ );
443
+
444
+ case "file":
445
+ return (
446
+ <FileUploadField
447
+ {...common}
448
+ value={value}
449
+ onChange={onChange as (v: File[] | File | null) => void}
450
+ accept={props.accept}
451
+ multiple={props.multiple}
452
+ maxFiles={props.maxFiles}
453
+ maxSize={props.maxSize}
454
+ />
455
+ );
456
+
457
+ case "entity_picker":
458
+ return (
459
+ <EntityPickerField
460
+ {...common}
461
+ value={value as string}
462
+ onChange={onChange as (v: string) => void}
463
+ options={
464
+ props.options as
465
+ | Array<{ value: string; label: string; subtitle?: string; avatarUrl?: string }>
466
+ | undefined
467
+ }
468
+ autocompleteHref={props.autocompleteHref}
469
+ autocompleteMinChars={props.autocompleteMinChars}
470
+ initialOption={props.initialOption}
471
+ entityAvatarField={props.entityAvatarField}
472
+ entitySubtitleField={props.entitySubtitleField}
473
+ placeholder={props.placeholder}
474
+ />
475
+ );
476
+
477
+ case "static":
478
+ return <StaticField id={id} value={value} />;
479
+
480
+ case "phone":
481
+ return (
482
+ <Suspense fallback={<InputSkeleton />}>
483
+ <LazyPhoneField
484
+ {...common}
485
+ value={value as string}
486
+ onChange={onChange as (v: string) => void}
487
+ placeholder={props.placeholder}
488
+ defaultCountry={props.defaultCountry}
489
+ fixedCountry={props.fixedCountry}
490
+ />
491
+ </Suspense>
492
+ );
493
+
494
+ case "document":
495
+ return (
496
+ <Suspense fallback={<InputSkeleton />}>
497
+ <LazyDocumentField
498
+ {...common}
499
+ value={value as string}
500
+ onChange={onChange as (v: string) => void}
501
+ documentType={props.documentType}
502
+ documentScope={props.documentScope}
503
+ documentMasks={props.documentMasks}
504
+ placeholder={props.placeholder}
505
+ />
506
+ </Suspense>
507
+ );
508
+
509
+ case "currency":
510
+ return (
511
+ <CurrencyField
512
+ {...common}
513
+ value={value as number | null}
514
+ onChange={onChange as (v: number | null) => void}
515
+ currency={props.currency}
516
+ placeholder={props.placeholder}
517
+ min={props.min}
518
+ max={props.max}
519
+ />
520
+ );
521
+
522
+ case "color":
523
+ return (
524
+ <ColorField
525
+ {...common}
526
+ value={value as string}
527
+ onChange={onChange as (v: string) => void}
528
+ placeholder={props.placeholder}
529
+ />
530
+ );
531
+
532
+ case "slug":
533
+ return (
534
+ <SlugField
535
+ {...common}
536
+ value={value as string}
537
+ onChange={onChange as (v: string) => void}
538
+ sourceValue={
539
+ props.sourceField !== undefined
540
+ ? String(sourceValues[props.sourceField] ?? "")
541
+ : undefined
542
+ }
543
+ prefix={props.prefix}
544
+ placeholder={props.placeholder}
545
+ />
546
+ );
547
+
548
+ case "tags":
549
+ return (
550
+ <TagsField
551
+ {...common}
552
+ value={value as string[]}
553
+ onChange={onChange as (v: string[]) => void}
554
+ placeholder={props.placeholder}
555
+ maxTags={props.maxTags}
556
+ />
557
+ );
558
+
559
+ case "date_range":
560
+ return (
561
+ <Suspense fallback={<InputSkeleton />}>
562
+ <LazyDateRangeField
563
+ {...common}
564
+ value={value}
565
+ onChange={onChange}
566
+ operator={props.operator}
567
+ />
568
+ </Suspense>
569
+ );
570
+
571
+ case "rating":
572
+ return (
573
+ <RatingField
574
+ {...common}
575
+ value={value as number | null}
576
+ onChange={onChange as (v: number) => void}
577
+ maxRating={props.maxRating}
578
+ />
579
+ );
580
+
581
+ default: {
582
+ /**
583
+ * A component this file has never heard of, resolved from the registry.
584
+ *
585
+ * `registerFieldComponent` has been public, and documented as the way to
586
+ * add a field without editing this file, while nothing ever read the
587
+ * registry back — registering one had no effect at all. This is where that
588
+ * promise comes true.
589
+ *
590
+ * The lookup belongs *here* and not before the switch, even though earlier
591
+ * would also let a consumer replace a built-in: `registerDefaultFields`
592
+ * puts every shipped field in the same registry, and those expect their own
593
+ * explicit props, which the cases above supply. Resolving from the registry
594
+ * first would hand `select` a `fieldProps` bag instead of its `options` and
595
+ * break every form in the library.
596
+ *
597
+ * A custom field gets the whole bag, per `FieldComponentProps` — this file
598
+ * cannot know what a field it does not recognise needs.
599
+ */
600
+ const Registered = resolveFieldComponent(component);
601
+ if (Registered) {
602
+ return <Registered {...common} value={value} onChange={onChange} fieldProps={props} />;
603
+ }
604
+ return <p className="text-destructive text-xs">Unknown field component: {component}</p>;
605
+ }
606
+ }
607
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * CheckboxField -- single boolean checkbox with label.
3
+ *
4
+ * Wraps the ReUI Checkbox (Radix) primitive with form-field aria plumbing.
5
+ */
6
+
7
+ import type { ReactElement } from "react";
8
+
9
+ import { Checkbox } from "@/primitives/reui/checkbox";
10
+ import { Label } from "@/primitives/reui/label";
11
+
12
+ export interface CheckboxFieldProps {
13
+ id: string;
14
+ value: boolean;
15
+ onChange: (value: boolean) => void;
16
+ label?: string;
17
+ disabled?: boolean;
18
+ required?: boolean;
19
+ error?: string;
20
+ helpTextId?: string;
21
+ errorId?: string;
22
+ }
23
+
24
+ export function CheckboxField({
25
+ id,
26
+ value,
27
+ onChange,
28
+ label,
29
+ disabled,
30
+ required,
31
+ error,
32
+ helpTextId,
33
+ errorId,
34
+ }: CheckboxFieldProps): ReactElement {
35
+ const describedBy =
36
+ [error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
37
+
38
+ return (
39
+ <div className="flex items-center gap-2">
40
+ <Checkbox
41
+ id={id}
42
+ checked={!!value}
43
+ onCheckedChange={(checked) => onChange(checked === true)}
44
+ disabled={disabled}
45
+ aria-invalid={error ? true : undefined}
46
+ aria-required={required || undefined}
47
+ aria-describedby={describedBy}
48
+ />
49
+ {label && (
50
+ <Label htmlFor={id} className="text-sm font-normal">
51
+ {label}
52
+ </Label>
53
+ )}
54
+ </div>
55
+ );
56
+ }