@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,239 @@
1
+ "use client";
2
+
3
+ import { useMemo, useState, type ReactElement, type ReactNode } from "react";
4
+
5
+ import { buildFormSchema } from "@/base/form/form-schema-builder";
6
+ import { isFieldVisible } from "@/base/form/form-utils";
7
+ import { FormField } from "@/base/form/FormField";
8
+ import type { FormFieldNode, FormSchemaNode } from "@/contracts/block-data";
9
+ import { useTranslation } from "@/i18n/useTranslation";
10
+ import { cn } from "@/lib/utils";
11
+ import { Button } from "@/primitives/reui/button";
12
+
13
+ import { useEditablePanel } from "./EditablePanelContext";
14
+
15
+ type Values = Record<string, unknown>;
16
+
17
+ function defaultValueFor(node: FormFieldNode): unknown {
18
+ switch (node.component) {
19
+ case "int":
20
+ case "float":
21
+ case "currency":
22
+ case "slider":
23
+ case "rating":
24
+ return null;
25
+ case "checkbox":
26
+ case "switch":
27
+ return false;
28
+ case "multiselect":
29
+ case "tags":
30
+ return [];
31
+ default:
32
+ return "";
33
+ }
34
+ }
35
+
36
+ function valueOf(node: FormFieldNode, values: Values): unknown {
37
+ if (Object.prototype.hasOwnProperty.call(values, node.key)) return values[node.key];
38
+ return defaultValueFor(node);
39
+ }
40
+
41
+ /** Recursively render the schema tree — fields, sections, groups, headers. */
42
+ function renderNodes(
43
+ nodes: FormSchemaNode[],
44
+ values: Values,
45
+ errors: Record<string, string>,
46
+ setValue: (key: string, value: unknown) => void,
47
+ ): ReactNode {
48
+ return nodes.map((node, index) => {
49
+ switch (node.kind) {
50
+ case "field": {
51
+ if (!isFieldVisible(node, values)) return null;
52
+ return (
53
+ <FormField
54
+ key={node.key}
55
+ field={node}
56
+ value={valueOf(node, values)}
57
+ onChange={(val) => setValue(node.key, val)}
58
+ error={errors[node.key]}
59
+ sourceValues={values}
60
+ />
61
+ );
62
+ }
63
+ case "header":
64
+ return (
65
+ <h4 key={`header-${index}`} className="text-foreground pt-2 text-sm font-semibold">
66
+ {node.label}
67
+ </h4>
68
+ );
69
+ case "section":
70
+ return (
71
+ <section key={node.id} className="space-y-3">
72
+ <div className="text-muted-foreground text-[11px] font-medium tracking-[0.04em] uppercase">
73
+ {node.label}
74
+ </div>
75
+ {renderNodes(node.children, values, errors, setValue)}
76
+ </section>
77
+ );
78
+ case "group":
79
+ return (
80
+ <div
81
+ key={node.id}
82
+ className={cn(node.columns === 2 ? "grid grid-cols-2 gap-3" : "space-y-3")}
83
+ >
84
+ {renderNodes(node.children, values, errors, setValue)}
85
+ </div>
86
+ );
87
+ default:
88
+ return null;
89
+ }
90
+ });
91
+ }
92
+
93
+ /**
94
+ * InlineEditablePanel — the free editable-panel primitive's renderer. A resizable
95
+ * right-side drawer that renders an EditablePanelDescriptor's form (reusing the
96
+ * FormField router + Zod schema builder), validates on save, and submits via the
97
+ * provider. Renders nothing when the context is disabled or nothing is selected.
98
+ *
99
+ * Reads everything from useEditablePanel(); the free EditablePanelProvider fills
100
+ * the context. Mount once inside the shell (a fixed overlay, so it does not need
101
+ * to sit in any particular flex slot).
102
+ */
103
+ export function InlineEditablePanel(): ReactElement | null {
104
+ const { t } = useTranslation();
105
+ const { enabled, selectedId, descriptor, loading, saving, submit, close, width } =
106
+ useEditablePanel();
107
+
108
+ const [values, setValues] = useState<Values>(() =>
109
+ descriptor?.values ? { ...descriptor.values } : {},
110
+ );
111
+ const [errors, setErrors] = useState<Record<string, string>>({});
112
+
113
+ // Re-seed the form whenever a new descriptor arrives (new selection). Done as
114
+ // the "adjust state when a prop changes" render-time pattern (guarded by the
115
+ // previous descriptor stored in state) rather than an effect, so no cascading
116
+ // render / set-state-in-effect.
117
+ const [seededFrom, setSeededFrom] = useState(descriptor);
118
+ if (descriptor !== seededFrom) {
119
+ setSeededFrom(descriptor);
120
+ setValues(descriptor?.values ? { ...descriptor.values } : {});
121
+ setErrors({});
122
+ }
123
+
124
+ const [resizeWidth, setResizeWidth] = useState<number | null>(null);
125
+ const effectiveWidth = resizeWidth ?? width;
126
+
127
+ const setValue = useMemo(
128
+ () => (key: string, value: unknown) => {
129
+ setValues((prev) => ({ ...prev, [key]: value }));
130
+ setErrors((prev) => {
131
+ if (!prev[key]) return prev;
132
+ const next = { ...prev };
133
+ delete next[key];
134
+ return next;
135
+ });
136
+ },
137
+ [],
138
+ );
139
+
140
+ if (!enabled || selectedId === null) return null;
141
+
142
+ const onResizeDown = (e: React.PointerEvent) => {
143
+ e.preventDefault();
144
+ const startX = e.clientX;
145
+ const startW = effectiveWidth;
146
+ const move = (ev: PointerEvent) => {
147
+ setResizeWidth(Math.min(720, Math.max(320, startW + (startX - ev.clientX))));
148
+ };
149
+ const up = () => {
150
+ window.removeEventListener("pointermove", move);
151
+ window.removeEventListener("pointerup", up);
152
+ };
153
+ window.addEventListener("pointermove", move);
154
+ window.addEventListener("pointerup", up);
155
+ };
156
+
157
+ const onSave = () => {
158
+ if (!descriptor) return;
159
+ const zschema = buildFormSchema(descriptor.schema, values, t);
160
+ const result = zschema.safeParse(values);
161
+ if (!result.success) {
162
+ const next: Record<string, string> = {};
163
+ for (const issue of result.error.issues) {
164
+ const key = String(issue.path[0] ?? "");
165
+ if (key && !next[key]) next[key] = issue.message;
166
+ }
167
+ setErrors(next);
168
+ return;
169
+ }
170
+ submit(result.data as Values);
171
+ };
172
+
173
+ return (
174
+ <>
175
+ <div className="fixed inset-0 z-40 bg-black/40" onClick={close} aria-hidden />
176
+ <div
177
+ role="dialog"
178
+ aria-modal="true"
179
+ className="bg-background fixed top-0 right-0 bottom-0 z-50 flex flex-col overflow-hidden border-l shadow-2xl"
180
+ style={{ width: effectiveWidth }}
181
+ >
182
+ <div
183
+ onPointerDown={onResizeDown}
184
+ className="hover:bg-primary/30 absolute top-0 bottom-0 left-0 z-10 w-1.5 cursor-col-resize"
185
+ aria-hidden
186
+ />
187
+
188
+ {/* Header */}
189
+ <div className="border-border/60 flex items-start gap-2 border-b px-4 pt-3 pb-2.5">
190
+ <div className="min-w-0 flex-1">
191
+ {descriptor?.subtitle && (
192
+ <div className="text-muted-foreground mb-0.5 font-mono text-[11px] font-semibold tracking-wide uppercase">
193
+ {descriptor.subtitle}
194
+ </div>
195
+ )}
196
+ <h3 className="text-foreground truncate text-base leading-snug font-semibold">
197
+ {descriptor?.title ?? t("middag.ui.loading")}
198
+ </h3>
199
+ </div>
200
+ <button
201
+ type="button"
202
+ onClick={close}
203
+ aria-label={t("middag.ui.editable_panel.close")}
204
+ className="text-muted-foreground hover:text-foreground hover:bg-muted rounded p-1 transition-colors"
205
+ >
206
+ <span aria-hidden className="text-sm leading-none">
207
+ ✕
208
+ </span>
209
+ </button>
210
+ </div>
211
+
212
+ {/* Body */}
213
+ <div className="min-h-0 flex-1 overflow-y-auto p-4">
214
+ {loading || !descriptor ? (
215
+ <div className="flex items-center justify-center p-8">
216
+ <div className="border-primary h-6 w-6 animate-spin rounded-full border-2 border-t-transparent" />
217
+ </div>
218
+ ) : (
219
+ <div className="space-y-3.5">
220
+ {renderNodes(descriptor.schema, values, errors, setValue)}
221
+ </div>
222
+ )}
223
+ </div>
224
+
225
+ {/* Footer */}
226
+ {descriptor && !loading && (
227
+ <div className="flex justify-end gap-2 border-t p-3">
228
+ <Button type="button" variant="outline" size="sm" onClick={close} disabled={saving}>
229
+ {descriptor.cancelLabel ?? t("middag.ui.cancel")}
230
+ </Button>
231
+ <Button type="button" size="sm" onClick={onSave} disabled={saving}>
232
+ {descriptor.submitLabel ?? t("middag.ui.form.save")}
233
+ </Button>
234
+ </div>
235
+ )}
236
+ </div>
237
+ </>
238
+ );
239
+ }
@@ -0,0 +1,173 @@
1
+ "use client";
2
+
3
+ import { createContext, useContext } from "react";
4
+
5
+ // ── Types ────────────────────────────────────────────────────────────────────
6
+
7
+ export interface InspectorAction {
8
+ id: string;
9
+ label: string;
10
+ icon?: string;
11
+ href?: string;
12
+ }
13
+
14
+ export interface InspectorSection {
15
+ id: string;
16
+ title: string;
17
+ fields: InspectorField[];
18
+ actions?: InspectorAction[];
19
+ }
20
+
21
+ export interface InspectorField {
22
+ key: string;
23
+ label: string;
24
+ value: string | number | boolean | null;
25
+ kind?: "text" | "status" | "boolean" | "timestamp" | "link" | "badge" | "code";
26
+ }
27
+
28
+ export interface InspectorHeaderAction {
29
+ id: string;
30
+ label: string;
31
+ icon?: string;
32
+ variant?: "primary" | "ghost";
33
+ }
34
+
35
+ export interface InspectorResponse {
36
+ title: string;
37
+ /** Subtitle shown above title (e.g. "CON-104 · Conector"). */
38
+ subtitle?: string;
39
+ /** Status badge shown in status row below header. */
40
+ badge?: string;
41
+ /** Badge variant: 'success' | 'warning' | 'destructive' | 'info'. */
42
+ badgeVariant?: "success" | "warning" | "destructive" | "info";
43
+ /** Header-level actions (e.g. sync button). */
44
+ headerActions?: InspectorHeaderAction[];
45
+ /** Activity item count (shown on activity tab). */
46
+ activityCount?: number;
47
+ sections: InspectorSection[];
48
+ }
49
+
50
+ export interface InspectorContextValue {
51
+ selectedId: string | number | null;
52
+ select: (id: string | number) => void;
53
+ close: () => void;
54
+ enabled: boolean;
55
+ data: InspectorResponse | null;
56
+ loading: boolean;
57
+ width: number;
58
+ }
59
+
60
+ // ── Context ──────────────────────────────────────────────────────────────────
61
+ //
62
+ // The Community engine owns the inspector CONTEXT (so Community blocks — DenseTable,
63
+ // CardGrid — can call useInspector() and degrade gracefully), but NOT the
64
+ // provider. The Pro @middag-io/react-pro InspectorProvider fills this context
65
+ // with real data fetching; without it, the no-op default keeps the inspector
66
+ // disabled. The Pro InspectorData config type lives in @middag-io/react-pro.
67
+
68
+ // eslint-disable-next-line react-refresh/only-export-components
69
+ export const InspectorContext = createContext<InspectorContextValue>({
70
+ selectedId: null,
71
+ select: () => {},
72
+ close: () => {},
73
+ enabled: false,
74
+ data: null,
75
+ loading: false,
76
+ width: 380,
77
+ });
78
+
79
+ // eslint-disable-next-line react-refresh/only-export-components
80
+ export function useInspector(): InspectorContextValue {
81
+ return useContext(InspectorContext);
82
+ }
83
+
84
+ // ── Generic inspector content renderer (exported for InlineInspector) ───────
85
+
86
+ export function InspectorFieldValue({ field }: { field: InspectorField }) {
87
+ if (field.value === null || field.value === "") {
88
+ return <span className="text-muted-foreground">---</span>;
89
+ }
90
+
91
+ if (field.kind === "boolean") {
92
+ return <span>{field.value ? "✓" : "✗"}</span>;
93
+ }
94
+
95
+ if (field.kind === "status" || field.kind === "badge") {
96
+ const color =
97
+ field.value === "active" || field.value === "granted"
98
+ ? "bg-success-subtle text-success"
99
+ : field.value === "failed" || field.value === "revoked"
100
+ ? "bg-destructive-subtle text-destructive"
101
+ : "bg-muted text-muted-foreground";
102
+ return (
103
+ <span className={`inline-flex rounded-full px-2 py-0.5 text-[10px] font-semibold ${color}`}>
104
+ {String(field.value)}
105
+ </span>
106
+ );
107
+ }
108
+
109
+ if (field.kind === "timestamp" && typeof field.value === "number") {
110
+ return <span>{new Date(field.value * 1000).toLocaleDateString()}</span>;
111
+ }
112
+
113
+ if (field.kind === "code") {
114
+ return (
115
+ <code className="bg-muted rounded-[3px] px-1.5 py-px font-mono text-xs">
116
+ {String(field.value)}
117
+ </code>
118
+ );
119
+ }
120
+
121
+ if (field.kind === "link" && typeof field.value === "string") {
122
+ return (
123
+ <a
124
+ href={field.value}
125
+ target="_blank"
126
+ rel="noopener noreferrer"
127
+ className="text-primary truncate hover:underline"
128
+ >
129
+ {field.value.replace(/^https?:\/\//, "")}
130
+ </a>
131
+ );
132
+ }
133
+
134
+ return <span>{String(field.value)}</span>;
135
+ }
136
+
137
+ export function InspectorSectionContent({ sections }: { sections: InspectorSection[] }) {
138
+ return (
139
+ <div className="divide-y">
140
+ {sections.map((section, index) => (
141
+ // Section ids double as tab-group discriminators ("overview"/"activity"/
142
+ // "config"), so a single tab can legitimately stack several sections
143
+ // sharing an id — the render key must include the index to stay unique.
144
+ <div key={`${section.id}-${index}`} className="px-4 py-3.5">
145
+ <dl className="space-y-3.5">
146
+ {section.fields.map((field) => (
147
+ <div key={field.key}>
148
+ <dt className="text-muted-foreground mb-0.5 text-[11px] font-medium tracking-[0.04em] uppercase">
149
+ {field.label}
150
+ </dt>
151
+ <dd className="text-foreground text-[13px]">
152
+ <InspectorFieldValue field={field} />
153
+ </dd>
154
+ </div>
155
+ ))}
156
+ </dl>
157
+ {section.actions && section.actions.length > 0 && (
158
+ <div className="mt-3.5 flex gap-1.5">
159
+ {section.actions.map((action) => (
160
+ <button
161
+ key={action.id}
162
+ className="border-border text-secondary-foreground hover:bg-muted rounded-md border px-2.5 py-[5px] text-xs font-medium transition-colors"
163
+ >
164
+ {action.label}
165
+ </button>
166
+ ))}
167
+ </div>
168
+ )}
169
+ </div>
170
+ ))}
171
+ </div>
172
+ );
173
+ }
@@ -0,0 +1,65 @@
1
+ "use client";
2
+
3
+ import type { ReactNode } from "react";
4
+
5
+ import {
6
+ Sheet,
7
+ SheetContent,
8
+ SheetDescription,
9
+ SheetHeader,
10
+ SheetTitle,
11
+ } from "@/primitives/reui/sheet";
12
+
13
+ interface InspectorPanelProps {
14
+ /** Whether the panel is open. */
15
+ open: boolean;
16
+ /** Called when the panel should close (overlay click or X button). */
17
+ onClose: () => void;
18
+ /** Panel width in pixels (from inspector descriptor, default 440). */
19
+ width?: number;
20
+ /** Panel title. */
21
+ title?: string;
22
+ /** Optional description below the title. */
23
+ description?: string;
24
+ /** Panel body content (tabs, detail sections, etc.). */
25
+ children: ReactNode;
26
+ }
27
+
28
+ /**
29
+ * InspectorPanel — drawer-style side panel for inspecting selected items.
30
+ *
31
+ * Wraps the ReUI Sheet (Radix Dialog) with:
32
+ * - Lighter overlay (bg-black/20 instead of bg-black/50)
33
+ * - Configurable width (default 440px from inspector_descriptor)
34
+ * - Jira-style 220ms cubic-bezier animation
35
+ *
36
+ * @see inspector_descriptor (PHP) for backend configuration
37
+ * @see HelpPanel for the similar contextual-help slide-out
38
+ */
39
+ export function InspectorPanel({
40
+ open,
41
+ onClose,
42
+ width = 440,
43
+ title,
44
+ description,
45
+ children,
46
+ }: InspectorPanelProps) {
47
+ return (
48
+ <Sheet open={open} onOpenChange={(isOpen) => !isOpen && onClose()}>
49
+ <SheetContent
50
+ side="right"
51
+ className="inspector-panel flex flex-col"
52
+ style={{ "--inspector-width": `${width}px` } as React.CSSProperties}
53
+ showCloseButton
54
+ >
55
+ {title && (
56
+ <SheetHeader>
57
+ <SheetTitle>{title}</SheetTitle>
58
+ {description && <SheetDescription>{description}</SheetDescription>}
59
+ </SheetHeader>
60
+ )}
61
+ <div className="flex-1 overflow-y-auto">{children}</div>
62
+ </SheetContent>
63
+ </Sheet>
64
+ );
65
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * NavErrorBoundary — error boundary for sidebar and page header.
3
+ * Shows a minimal fallback if navigation rendering fails.
4
+ *
5
+ * @see NV-05-ux-shell-sidebar.md §8.3
6
+ */
7
+
8
+ import { Component, type ErrorInfo, type ReactElement, type ReactNode } from "react";
9
+
10
+ import { useErrorReporter, type ErrorReporter } from "@/engine/providers/error-reporter";
11
+
12
+ // ── Default fallback ─────────────────────────────────────────────────────────
13
+ // Hardcoded strings — an error boundary fallback must never depend on providers
14
+ // (I18nProvider, etc.) that may themselves be missing or broken.
15
+
16
+ function NavErrorFallback(): ReactElement {
17
+ return (
18
+ <div className="flex min-h-[200px] flex-col items-center justify-center gap-3 p-6 text-center">
19
+ <span className="text-destructive" aria-hidden="true">
20
+ &#x26A0;
21
+ </span>
22
+ <p className="text-muted-foreground text-sm">Navigation failed to load.</p>
23
+ <button
24
+ onClick={() => window.location.reload()}
25
+ className="text-primary text-sm underline hover:no-underline"
26
+ >
27
+ Reload page
28
+ </button>
29
+ </div>
30
+ );
31
+ }
32
+
33
+ interface Props {
34
+ children: ReactNode;
35
+ fallback?: ReactNode;
36
+ }
37
+
38
+ interface State {
39
+ hasError: boolean;
40
+ error?: Error;
41
+ }
42
+
43
+ class NavErrorBoundaryInner extends Component<Props & { reporter: ErrorReporter | null }, State> {
44
+ constructor(props: Props & { reporter: ErrorReporter | null }) {
45
+ super(props);
46
+ this.state = { hasError: false };
47
+ }
48
+
49
+ static getDerivedStateFromError(error: Error): State {
50
+ return { hasError: true, error };
51
+ }
52
+
53
+ componentDidCatch(error: Error, info: ErrorInfo): void {
54
+ if (this.props.reporter) {
55
+ this.props.reporter.captureError(error, {
56
+ component: "NavErrorBoundary",
57
+ action: "shell_render",
58
+ componentStack: info.componentStack ?? undefined,
59
+ });
60
+ } else {
61
+ console.error("[MIDDAG] Shell rendering error:", error, info.componentStack);
62
+ }
63
+ }
64
+
65
+ render(): ReactNode {
66
+ if (this.state.hasError) {
67
+ return this.props.fallback ?? <NavErrorFallback />;
68
+ }
69
+
70
+ return this.props.children;
71
+ }
72
+ }
73
+
74
+ /** Error boundary that reports to the pluggable ErrorReporter (Sentry, New Relic, etc.) */
75
+ export function NavErrorBoundary({ children, fallback }: Props): ReactElement {
76
+ const reporter = useErrorReporter();
77
+ return (
78
+ <NavErrorBoundaryInner reporter={reporter} fallback={fallback}>
79
+ {children}
80
+ </NavErrorBoundaryInner>
81
+ );
82
+ }
@@ -0,0 +1,67 @@
1
+ "use client";
2
+
3
+ import { useCallback, useEffect, type ReactNode } from "react";
4
+ import { X } from "lucide-react";
5
+
6
+ import { useTranslation } from "@/i18n/useTranslation";
7
+
8
+ interface OverlayScreenProps {
9
+ children: ReactNode;
10
+ onClose?: () => void;
11
+ }
12
+
13
+ /**
14
+ * Full-screen overlay panel with X close button (NV-05 — ADR-807).
15
+ *
16
+ * Not a modal (no backdrop, no centering). Renders a stacked screen
17
+ * on top of the current page. The underlying page stays mounted in the DOM.
18
+ *
19
+ * Close behavior: calls onClose if provided, otherwise window.history.back().
20
+ * Also closes on Escape key.
21
+ */
22
+ export function OverlayScreen({ children, onClose }: OverlayScreenProps) {
23
+ const { t } = useTranslation();
24
+ const handleClose = useCallback(() => {
25
+ if (onClose) {
26
+ onClose();
27
+ } else {
28
+ window.history.back();
29
+ }
30
+ }, [onClose]);
31
+
32
+ useEffect(() => {
33
+ const handler = (e: KeyboardEvent) => {
34
+ if (e.key === "Escape") {
35
+ handleClose();
36
+ }
37
+ };
38
+
39
+ document.addEventListener("keydown", handler);
40
+
41
+ return () => document.removeEventListener("keydown", handler);
42
+ }, [handleClose]);
43
+
44
+ // Trap focus inside overlay.
45
+ useEffect(() => {
46
+ const previouslyFocused = document.activeElement as HTMLElement | null;
47
+
48
+ return () => {
49
+ previouslyFocused?.focus();
50
+ };
51
+ }, []);
52
+
53
+ return (
54
+ <div className="bg-background fixed inset-0 z-50 overflow-auto">
55
+ <button
56
+ onClick={handleClose}
57
+ className="hover:bg-muted fixed top-4 right-4 z-[51] rounded-md p-2 transition-colors"
58
+ aria-label={t("middag.ui.overlay.close")}
59
+ type="button"
60
+ >
61
+ <X className="h-5 w-5" />
62
+ </button>
63
+
64
+ <div className="min-h-screen p-6">{children}</div>
65
+ </div>
66
+ );
67
+ }