@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,37 @@
1
+ /**
2
+ * Registers all built-in cell renderers in the cell registry.
3
+ *
4
+ * Called by registerDefaults(). Consumers can register custom cell types
5
+ * (e.g. registerCellRenderer("sparkline", SparklineCell)) without modifying
6
+ * DataTable/index.tsx.
7
+ */
8
+
9
+ import { registerCellRenderer } from "./cell-registry";
10
+ import {
11
+ AnnotatedCell,
12
+ BooleanCell,
13
+ HtmlCell,
14
+ LinkCell,
15
+ LinkGroupCell,
16
+ ProgressCell,
17
+ RichStatusCell,
18
+ StatusCell,
19
+ TimestampCell,
20
+ } from "./cell-renderers";
21
+
22
+ let registered = false;
23
+
24
+ export function registerDefaultCells(): void {
25
+ if (registered) return;
26
+ registered = true;
27
+
28
+ registerCellRenderer("status", StatusCell);
29
+ registerCellRenderer("boolean", BooleanCell);
30
+ registerCellRenderer("timestamp", TimestampCell);
31
+ registerCellRenderer("link", LinkCell);
32
+ registerCellRenderer("rich_status", RichStatusCell);
33
+ registerCellRenderer("html", HtmlCell);
34
+ registerCellRenderer("link_group", LinkGroupCell);
35
+ registerCellRenderer("annotated", AnnotatedCell);
36
+ registerCellRenderer("progress", ProgressCell);
37
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Turns an untrusted HTML string into React elements through an allowlist.
3
+ *
4
+ * `html` columns carry markup that comes from row data, so it is never handed
5
+ * to the DOM as a raw string. The string is parsed into a syntax tree,
6
+ * filtered by the GitHub-style default schema of `hast-util-sanitize`
7
+ * (no `<script>`, `<style>`, event handlers, inline styles or `javascript:`
8
+ * URLs), and rendered as ordinary React elements. Parsing does not need a DOM,
9
+ * so the same path works during server rendering.
10
+ *
11
+ * `className` is allowed on every element on top of the default schema: host
12
+ * markup commonly styles badges and labels with classes, and a class cannot
13
+ * run code.
14
+ */
15
+
16
+ import type { ReactNode } from "react";
17
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
18
+ import { fromHtml } from "hast-util-from-html";
19
+ import { defaultSchema, sanitize, type Schema } from "hast-util-sanitize";
20
+ import { toJsxRuntime } from "hast-util-to-jsx-runtime";
21
+
22
+ type AttributeList = NonNullable<Schema["attributes"]>[string];
23
+
24
+ // The default schema pins `className` to fixed values on a few elements (for
25
+ // example `a` only accepts `data-footnote-backref`), and a per-element rule
26
+ // wins over `*`. Those value pins are dropped so the `*` rule applies.
27
+ function withoutClassNamePins(list: AttributeList): AttributeList {
28
+ return list.filter((entry) => !(Array.isArray(entry) && entry[0] === "className"));
29
+ }
30
+
31
+ const CELL_HTML_SCHEMA: Schema = {
32
+ ...defaultSchema,
33
+ attributes: Object.fromEntries([
34
+ ...Object.entries(defaultSchema.attributes ?? {})
35
+ .filter(([tag]) => tag !== "*")
36
+ .map(([tag, list]) => [tag, withoutClassNamePins(list)]),
37
+ ["*", [...(defaultSchema.attributes?.["*"] ?? []), "className"]],
38
+ ]),
39
+ };
40
+
41
+ export function sanitizeHtmlToReact(html: string): ReactNode {
42
+ const tree = fromHtml(html, { fragment: true });
43
+ const clean = sanitize(tree, CELL_HTML_SCHEMA);
44
+ return toJsxRuntime(clean, { Fragment, jsx, jsxs });
45
+ }
@@ -0,0 +1,229 @@
1
+ /**
2
+ * DataTable types — column definitions, pagination, sorting, filtering, and actions.
3
+ *
4
+ * @see NV-05-ux-blocks.md
5
+ */
6
+
7
+ import type { ReactNode } from "react";
8
+
9
+ import type { EmptyPlaceholderCTA } from "@/base/partials/EmptyPlaceholder";
10
+ import type { AppliedFilters, FilterDef } from "@/base/partials/FilterBar";
11
+ import type { ExecutableAction, TimestampFormat } from "@/contracts/block-data";
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Column
15
+ // ---------------------------------------------------------------------------
16
+
17
+ export type DataTableCellType =
18
+ | "text"
19
+ | "status"
20
+ | "boolean"
21
+ | "timestamp"
22
+ | "link"
23
+ | "custom"
24
+ | "rich_status"
25
+ | "html"
26
+ | "link_group"
27
+ | "annotated"
28
+ | "progress";
29
+
30
+ export interface DataTableColumn<TData> {
31
+ /** Unique column key, must match a property of TData (or use `render` for computed). */
32
+ key: string;
33
+ /** Header label text. */
34
+ label: string;
35
+ /** Cell type — controls default rendering. Defaults to "text". */
36
+ type?: DataTableCellType;
37
+ /** Display format for type="timestamp" columns. Defaults to "relative". */
38
+ timestampFormat?: TimestampFormat;
39
+ /** Whether the column is sortable. Defaults to false. */
40
+ sortable?: boolean;
41
+ /** Whether the column can be hidden via column visibility. Defaults to true. */
42
+ hideable?: boolean;
43
+ /** Whether the column is visible by default. Defaults to true. */
44
+ visible?: boolean;
45
+ /** Fixed width in pixels. When omitted, column auto-sizes. */
46
+ width?: number;
47
+ /** Min width in pixels. */
48
+ minWidth?: number;
49
+ /** Max width in pixels. Longer content clips to one line with an ellipsis. */
50
+ maxWidth?: number;
51
+ /** URL pattern for link cells. Interpolated per row (e.g. "/organizations/{organizationId}"). */
52
+ href?: string;
53
+ /** Entity type for link resolution (from PageContract.entities map). */
54
+ entityType?: string;
55
+ /** Field name in row data containing the entity ID. */
56
+ entityIdField?: string;
57
+ /** Custom cell renderer. Overrides type-based rendering. */
58
+ render?: (value: unknown, row: TData) => ReactNode;
59
+ /** Status-to-semantic mapping for type="status" columns. Maps status string to a semantic intent. */
60
+ statusMap?: Record<
61
+ string,
62
+ "success" | "warning" | "destructive" | "secondary" | "info" | "default"
63
+ >;
64
+ }
65
+
66
+ // ---------------------------------------------------------------------------
67
+ // Pagination
68
+ // ---------------------------------------------------------------------------
69
+
70
+ export interface DataTablePagination {
71
+ /** Current page index (0-based). */
72
+ page: number;
73
+ /** Rows per page. */
74
+ perPage: number;
75
+ /** Total number of rows across all pages. */
76
+ total: number;
77
+ /** Available page size options. Defaults to [10, 25, 50, 100]. */
78
+ pageSizes?: number[];
79
+ }
80
+
81
+ // ---------------------------------------------------------------------------
82
+ // Sorting
83
+ // ---------------------------------------------------------------------------
84
+
85
+ export interface DataTableSort {
86
+ /** Column key being sorted. */
87
+ key: string;
88
+ /** Sort direction. */
89
+ direction: "asc" | "desc";
90
+ }
91
+
92
+ // ---------------------------------------------------------------------------
93
+ // Filters (re-exports + DataTable-scoped aliases)
94
+ // ---------------------------------------------------------------------------
95
+
96
+ export type DataTableFilterOption = { value: string; label: string };
97
+
98
+ export type DataTableFilterDef = FilterDef;
99
+
100
+ export type DataTableAppliedFilters = AppliedFilters;
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // Row actions
104
+ // ---------------------------------------------------------------------------
105
+
106
+ export interface DataTableRowAction<TData> {
107
+ /** Unique action id. */
108
+ id: string;
109
+ /** Visible label. */
110
+ label: string;
111
+ /** Icon name (kebab-case, resolved via getIcon). */
112
+ icon?: string;
113
+ /** Visual intent for dangerous actions. */
114
+ intent?: "default" | "danger";
115
+ /** Display variant: 'icon' (default) or 'button' (text label visible). */
116
+ variant?: "icon" | "button";
117
+ /** Called when the action is triggered. */
118
+ onAction: (row: TData) => void;
119
+ /** Conditionally hide the action per row. */
120
+ hidden?: (row: TData) => boolean;
121
+ /** Conditionally disable the action per row. */
122
+ disabled?: (row: TData) => boolean;
123
+ /** Show loading spinner instead of icon per row. */
124
+ loading?: (row: TData) => boolean;
125
+ /** Return disabled reason text for tooltip per row. */
126
+ disabledReason?: (row: TData) => string | undefined;
127
+ }
128
+
129
+ // ---------------------------------------------------------------------------
130
+ // Bulk actions (re-export alias)
131
+ // ---------------------------------------------------------------------------
132
+
133
+ export type DataTableBulkAction = ExecutableAction;
134
+
135
+ // ---------------------------------------------------------------------------
136
+ // Param change callback
137
+ // ---------------------------------------------------------------------------
138
+
139
+ export interface DataTableParamChange {
140
+ /**
141
+ * 0-based page index, matching TanStack's `pageIndex` — not the 1-based `page`
142
+ * of the block contract. Consumers that bridge to that contract must add 1.
143
+ */
144
+ page?: number;
145
+ perPage?: number;
146
+ sort?: DataTableSort | null;
147
+ search?: string;
148
+ filters?: DataTableAppliedFilters;
149
+ }
150
+
151
+ // ---------------------------------------------------------------------------
152
+ // DataTableProps
153
+ // ---------------------------------------------------------------------------
154
+
155
+ export interface DataTableProps<TData> {
156
+ /** Column definitions. */
157
+ columns: DataTableColumn<TData>[];
158
+ /** Row data. */
159
+ rows: TData[];
160
+ /** Unique key extractor for each row. String property name or function. */
161
+ rowKey: keyof TData | ((row: TData) => string);
162
+
163
+ /** Server-driven pagination state. */
164
+ pagination?: DataTablePagination;
165
+ /** Current sort state. */
166
+ sort?: DataTableSort;
167
+
168
+ /** Available filter definitions. */
169
+ filters?: DataTableFilterDef[];
170
+ /** Currently applied filters. */
171
+ appliedFilters?: DataTableAppliedFilters;
172
+
173
+ /** Row-level actions (shown on hover by default). */
174
+ rowActions?: DataTableRowAction<TData>[];
175
+ /** When true, row actions are always visible instead of hover-only. */
176
+ actionsAlwaysVisible?: boolean;
177
+ /** Bulk actions for selected rows. */
178
+ bulkActions?: DataTableBulkAction[];
179
+
180
+ /** Whether data is currently loading. */
181
+ isLoading?: boolean;
182
+
183
+ /** Placeholder for the search input. */
184
+ searchPlaceholder?: string;
185
+ /** Initial search value (controlled externally). */
186
+ searchValue?: string;
187
+
188
+ /** Empty state: icon name (kebab-case). */
189
+ emptyStateIcon?: string;
190
+ /** Empty state: title text. */
191
+ emptyStateTitle?: string;
192
+ /** Empty state: description text. */
193
+ emptyStateDescription?: string;
194
+ /** Empty state: CTA button. */
195
+ emptyStateCTA?: EmptyPlaceholderCTA;
196
+
197
+ /** Callback when any table parameter changes (page, sort, search, filters). */
198
+ onParamChange?: (params: DataTableParamChange) => void;
199
+ /** Callback when a bulk action is triggered. Receives action id + selected row keys. */
200
+ onBulkAction?: (actionId: string, selectedKeys: string[]) => void;
201
+
202
+ /**
203
+ * Callback for the "save as view" control. The control only renders when this
204
+ * is supplied — a toolbar button that does nothing is worse than no button.
205
+ */
206
+ onSaveView?: () => void;
207
+ /** Renders the "save as view" control in its active state. */
208
+ savedView?: boolean;
209
+ /**
210
+ * Overrides the control's tooltip and accessible name. The consumer decides
211
+ * what saving means here, so it also gets to say so — the built-in "Save as
212
+ * view" would describe the wrong gesture on a page that toggles a favourite.
213
+ */
214
+ saveViewLabel?: string;
215
+
216
+ /** Callback when a row is clicked (e.g. to open inspector). */
217
+ onRowClick?: (row: TData) => void;
218
+ /** Key of the currently selected row (for visual highlight). */
219
+ selectedRowKey?: string;
220
+
221
+ /**
222
+ * Persist client-only view state (column visibility, density) across Inertia
223
+ * history navigation. Driven by `BlockDescriptor.remember` from the backend.
224
+ * When false (default), state is plain `useState` (lost on back/forward).
225
+ */
226
+ remember?: boolean;
227
+ /** Stable, unique key scoping the remembered state (use `block.key`). */
228
+ rememberKey?: string;
229
+ }
@@ -0,0 +1,316 @@
1
+ /**
2
+ * DetailSection — section-based detail view with key-value fields.
3
+ *
4
+ * Renders structured data as label/value pairs in a responsive grid.
5
+ * Desktop uses CSS grid (1fr/2fr), mobile stacks with overline labels.
6
+ * Supports multiple field kinds: text, status, timestamp, boolean, link, code, email.
7
+ *
8
+ * @see NV-05-ux-blocks.md §4 (detail section anatomy)
9
+ */
10
+
11
+ import { useCallback, useState, type ReactElement } from "react";
12
+ import {
13
+ ArrowDown01Icon,
14
+ ArrowRight01Icon,
15
+ Cancel01Icon,
16
+ CheckmarkCircle01Icon,
17
+ CheckmarkSquare01Icon,
18
+ Copy01Icon,
19
+ Globe02Icon,
20
+ } from "@hugeicons/core-free-icons";
21
+ import { HugeiconsIcon } from "@hugeicons/react";
22
+
23
+ import { copyToClipboard } from "@/base/utils/clipboard";
24
+ import { formatISO, formatRelativeTime } from "@/base/utils/time";
25
+ import { useTranslation } from "@/i18n/useTranslation";
26
+ import { cn } from "@/lib/utils";
27
+ import { Badge } from "@/primitives/reui/badge";
28
+ import { Button } from "@/primitives/reui/button";
29
+ import { Frame, FrameHeader, FramePanel, FrameTitle } from "@/primitives/reui/frame";
30
+ import { Skeleton } from "@/primitives/reui/skeleton";
31
+
32
+ /* ------------------------------------------------------------------ */
33
+ /* Types */
34
+ /* ------------------------------------------------------------------ */
35
+
36
+ export type FieldKind = "text" | "status" | "timestamp" | "boolean" | "link" | "code" | "email";
37
+
38
+ export interface DetailField {
39
+ key: string;
40
+ label: string;
41
+ value: string | number | boolean | null;
42
+ kind?: FieldKind;
43
+ copyable?: boolean;
44
+ href?: string;
45
+ }
46
+
47
+ export interface SectionAction {
48
+ id: string;
49
+ label: string;
50
+ onClick: () => void;
51
+ }
52
+
53
+ export interface DetailSectionSection {
54
+ id: string;
55
+ title: string;
56
+ fields: DetailField[];
57
+ defaultCollapsed?: boolean;
58
+ actions?: SectionAction[];
59
+ }
60
+
61
+ export interface DetailSectionProps {
62
+ sections: DetailSectionSection[];
63
+ isLoading?: boolean;
64
+ }
65
+
66
+ /* ------------------------------------------------------------------ */
67
+ /* Status badge mapping */
68
+ /* ------------------------------------------------------------------ */
69
+
70
+ const STATUS_BADGE_VARIANT: Record<string, string> = {
71
+ active: "success-light",
72
+ connected: "success-light",
73
+ healthy: "success-light",
74
+ success: "success-light",
75
+ warning: "warning-light",
76
+ degraded: "warning-light",
77
+ pending: "warning-light",
78
+ error: "destructive-light",
79
+ failed: "destructive-light",
80
+ disconnected: "destructive-light",
81
+ inactive: "outline",
82
+ unknown: "outline",
83
+ };
84
+
85
+ function resolveBadgeVariant(status: string): string {
86
+ return STATUS_BADGE_VARIANT[status.toLowerCase()] ?? "outline";
87
+ }
88
+
89
+ /* ------------------------------------------------------------------ */
90
+ /* CopyButton */
91
+ /* ------------------------------------------------------------------ */
92
+
93
+ function CopyButton({ text }: { text: string }): ReactElement {
94
+ const { t } = useTranslation();
95
+ const [copied, setCopied] = useState(false);
96
+
97
+ const handleCopy = useCallback(async () => {
98
+ const success = await copyToClipboard(text);
99
+ if (success) {
100
+ setCopied(true);
101
+ setTimeout(() => setCopied(false), 2000);
102
+ }
103
+ }, [text]);
104
+
105
+ return (
106
+ <button
107
+ type="button"
108
+ onClick={handleCopy}
109
+ className="ml-2 inline-flex shrink-0 opacity-0 transition-opacity group-hover/field:opacity-100 focus:opacity-100"
110
+ aria-label={t("middag.ui.detail_section.copy_value")}
111
+ >
112
+ <HugeiconsIcon
113
+ icon={copied ? CheckmarkSquare01Icon : Copy01Icon}
114
+ size={14}
115
+ className={cn(
116
+ "transition-colors",
117
+ copied ? "text-success" : "text-muted-foreground hover:text-foreground",
118
+ )}
119
+ />
120
+ </button>
121
+ );
122
+ }
123
+
124
+ /* ------------------------------------------------------------------ */
125
+ /* FieldValue */
126
+ /* ------------------------------------------------------------------ */
127
+
128
+ function FieldValue({ field }: { field: DetailField }): ReactElement {
129
+ const { t, locale } = useTranslation();
130
+ const { value, kind = "text", href } = field;
131
+
132
+ // Null / undefined
133
+ if (value === null || value === undefined) {
134
+ return <span className="text-muted-foreground">&mdash;</span>;
135
+ }
136
+
137
+ switch (kind) {
138
+ case "status": {
139
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Badge variant resolved dynamically
140
+ const variant = resolveBadgeVariant(String(value)) as any;
141
+ return (
142
+ <Badge variant={variant} size="sm">
143
+ {String(value)}
144
+ </Badge>
145
+ );
146
+ }
147
+
148
+ case "timestamp": {
149
+ const ts = typeof value === "number" ? value : Number(value);
150
+ return (
151
+ <time dateTime={formatISO(ts)} title={formatISO(ts)} className="text-sm">
152
+ {formatRelativeTime(ts, locale)}
153
+ </time>
154
+ );
155
+ }
156
+
157
+ case "boolean":
158
+ return (
159
+ <HugeiconsIcon
160
+ icon={value ? CheckmarkCircle01Icon : Cancel01Icon}
161
+ size={16}
162
+ className={value ? "text-success" : "text-muted-foreground"}
163
+ aria-label={value ? t("middag.ui.common.yes") : t("middag.ui.common.no")}
164
+ />
165
+ );
166
+
167
+ case "link":
168
+ return (
169
+ <a
170
+ href={href ?? String(value)}
171
+ target="_blank"
172
+ rel="noopener noreferrer"
173
+ className="text-primary inline-flex items-center gap-1 text-sm hover:underline"
174
+ >
175
+ {String(value)}
176
+ <HugeiconsIcon icon={Globe02Icon} size={12} aria-hidden="true" />
177
+ </a>
178
+ );
179
+
180
+ case "code":
181
+ return (
182
+ <code className="bg-muted rounded px-1.5 py-0.5 font-mono text-xs">{String(value)}</code>
183
+ );
184
+
185
+ case "email":
186
+ return (
187
+ <a href={`mailto:${String(value)}`} className="text-primary text-sm hover:underline">
188
+ {String(value)}
189
+ </a>
190
+ );
191
+
192
+ default:
193
+ return <span className="text-sm">{String(value)}</span>;
194
+ }
195
+ }
196
+
197
+ /* ------------------------------------------------------------------ */
198
+ /* Section (collapsible) */
199
+ /* ------------------------------------------------------------------ */
200
+
201
+ function Section({ section }: { section: DetailSectionSection }): ReactElement {
202
+ const [collapsed, setCollapsed] = useState(section.defaultCollapsed ?? false);
203
+ const expanded = !collapsed;
204
+ const contentId = `detail-section-${section.id}-content`;
205
+
206
+ return (
207
+ <Frame variant="default" spacing="sm">
208
+ <FrameHeader>
209
+ <div className="flex items-center justify-between">
210
+ <Button
211
+ variant="ghost"
212
+ size="sm"
213
+ onClick={() => setCollapsed(!collapsed)}
214
+ aria-expanded={expanded}
215
+ aria-controls={contentId}
216
+ className="-ml-2 flex items-center gap-2 px-2"
217
+ >
218
+ <HugeiconsIcon
219
+ icon={expanded ? ArrowDown01Icon : ArrowRight01Icon}
220
+ size={14}
221
+ aria-hidden="true"
222
+ />
223
+ <FrameTitle className="text-base">{section.title}</FrameTitle>
224
+ </Button>
225
+
226
+ {section.actions && section.actions.length > 0 && (
227
+ <div className="flex items-center gap-2">
228
+ {section.actions.map((action) => (
229
+ <Button key={action.id} variant="outline" size="xs" onClick={action.onClick}>
230
+ {action.label}
231
+ </Button>
232
+ ))}
233
+ </div>
234
+ )}
235
+ </div>
236
+ </FrameHeader>
237
+
238
+ <FramePanel
239
+ className={cn(
240
+ "transition-[opacity,height] duration-200 ease-[var(--ease-default)]",
241
+ expanded ? "opacity-100" : "hidden opacity-0",
242
+ )}
243
+ >
244
+ <div id={contentId}>
245
+ <dl className="space-y-0">
246
+ {section.fields.map((field) => (
247
+ <div
248
+ key={field.key}
249
+ className="group/field border-border/50 grid grid-cols-1 gap-1 border-b py-3 last:border-b-0 md:grid-cols-[1fr_2fr] md:items-center md:gap-4"
250
+ >
251
+ {/* Label */}
252
+ <dt className="text-muted-foreground text-xs font-medium tracking-wide uppercase md:text-sm md:tracking-normal md:normal-case">
253
+ {field.label}
254
+ </dt>
255
+
256
+ {/* Value */}
257
+ <dd className="flex items-center">
258
+ <FieldValue field={field} />
259
+ {field.copyable && field.value !== null && field.value !== undefined && (
260
+ <CopyButton text={String(field.value)} />
261
+ )}
262
+ </dd>
263
+ </div>
264
+ ))}
265
+ </dl>
266
+ </div>
267
+ </FramePanel>
268
+ </Frame>
269
+ );
270
+ }
271
+
272
+ /* ------------------------------------------------------------------ */
273
+ /* Skeleton */
274
+ /* ------------------------------------------------------------------ */
275
+
276
+ function DetailSectionSkeleton(): ReactElement {
277
+ return (
278
+ <div className="space-y-6">
279
+ {[1, 2].map((s) => (
280
+ <Frame key={s} variant="default" spacing="sm">
281
+ <FrameHeader>
282
+ <Skeleton className="h-5 w-36" />
283
+ </FrameHeader>
284
+ <FramePanel>
285
+ <div className="space-y-4">
286
+ {[1, 2, 3].map((f) => (
287
+ <div key={f} className="grid grid-cols-1 gap-2 md:grid-cols-[1fr_2fr]">
288
+ <Skeleton className="h-4 w-24" />
289
+ <Skeleton className="h-4 w-48" />
290
+ </div>
291
+ ))}
292
+ </div>
293
+ </FramePanel>
294
+ </Frame>
295
+ ))}
296
+ </div>
297
+ );
298
+ }
299
+
300
+ /* ------------------------------------------------------------------ */
301
+ /* Main component */
302
+ /* ------------------------------------------------------------------ */
303
+
304
+ export function DetailSection({ sections, isLoading }: DetailSectionProps): ReactElement {
305
+ if (isLoading) {
306
+ return <DetailSectionSkeleton />;
307
+ }
308
+
309
+ return (
310
+ <div className="space-y-6">
311
+ {sections.map((section) => (
312
+ <Section key={section.id} section={section} />
313
+ ))}
314
+ </div>
315
+ );
316
+ }