@middag-io/react 0.44.1 → 0.45.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/README.md +7 -0
  2. package/dist-lib/{FormField-Bj43PjHH.js → FormField-Csx8hGAW.js} +1956 -1936
  3. package/dist-lib/{FormPanelBlock-C6eDfGoI.js → FormPanelBlock-Bmd0DpiX.js} +337 -337
  4. package/dist-lib/base/blocks/DenseTableBlock.d.ts.map +1 -1
  5. package/dist-lib/base/blocks/LinkListBlock.d.ts +2 -1
  6. package/dist-lib/base/blocks/LinkListBlock.d.ts.map +1 -1
  7. package/dist-lib/base/form/FormField.d.ts.map +1 -1
  8. package/dist-lib/base/layout/DashboardLayout.d.ts.map +1 -1
  9. package/dist-lib/base/partials/ConfirmationDialog/index.d.ts.map +1 -1
  10. package/dist-lib/base/partials/DataTable/cell-renderers.d.ts +1 -1
  11. package/dist-lib/base/partials/DataTable/cell-renderers.d.ts.map +1 -1
  12. package/dist-lib/base/partials/DataTable/index.d.ts +1 -1
  13. package/dist-lib/base/partials/DataTable/index.d.ts.map +1 -1
  14. package/dist-lib/base/partials/DataTable/sanitize-html.d.ts +17 -0
  15. package/dist-lib/base/partials/DataTable/sanitize-html.d.ts.map +1 -0
  16. package/dist-lib/base/partials/DataTable/types.d.ts +15 -0
  17. package/dist-lib/base/partials/DataTable/types.d.ts.map +1 -1
  18. package/dist-lib/base/partials/FilterBar/index.d.ts.map +1 -1
  19. package/dist-lib/base/shell/BasicShell.js +1 -1
  20. package/dist-lib/base/shell/partials/InlineEditablePanel.js +38 -24
  21. package/dist-lib/base/shell/partials/PageActionButton.d.ts.map +1 -1
  22. package/dist-lib/base/shell/partials/PageActionButton.js +1 -1
  23. package/dist-lib/chunks/subpath-Bh1MAmBT.js +165 -0
  24. package/dist-lib/chunks/{subpath-AeMdleNB.js → subpath-fEhy6n_U.js} +10 -6
  25. package/dist-lib/contracts/block-data/data-display.d.ts +51 -2
  26. package/dist-lib/contracts/block-data/data-display.d.ts.map +1 -1
  27. package/dist-lib/contracts/generated/contract-schema.d.ts +1 -1
  28. package/dist-lib/contracts/generated/contract-types.d.ts +4 -2
  29. package/dist-lib/contracts/generated/contract-types.d.ts.map +1 -1
  30. package/dist-lib/contracts/generated/index.d.ts +1 -1
  31. package/dist-lib/i18n/I18nProvider.js +1 -1
  32. package/dist-lib/i18n/instance.js +1 -1
  33. package/dist-lib/i18n/locales/en/ui.json +5 -3
  34. package/dist-lib/i18n/locales/pt-BR/ui.json +5 -3
  35. package/dist-lib/i18n/register-strings.js +1 -1
  36. package/dist-lib/index.d.ts +1 -1
  37. package/dist-lib/index.d.ts.map +1 -1
  38. package/dist-lib/middag-react.css +1 -1
  39. package/dist-lib/middag-react.js +18641 -13317
  40. package/dist-lib/primitives/reui/chart.d.ts.map +1 -1
  41. package/dist-lib/primitives/reui/chart.js +35 -31
  42. package/docs/public/schemas/ai-contract-manifest.json +1820 -0
  43. package/docs/public/schemas/blocks.json +445 -0
  44. package/docs/public/schemas/components.json +166 -0
  45. package/docs/public/schemas/connectors.json +97 -0
  46. package/docs/public/schemas/fragment.json +2329 -0
  47. package/docs/public/schemas/manifest.json +119 -0
  48. package/docs/public/schemas/navigation.json +72 -0
  49. package/docs/public/schemas/page-contract.json +2329 -0
  50. package/docs/public/schemas/shared-props.json +118 -0
  51. package/docs/public/schemas/theme-defaults.json +253 -0
  52. package/docs/public/schemas/theme.json +401 -0
  53. package/package.json +109 -3
  54. package/src/assets/lottie/calendar/schedule-1.json +1 -0
  55. package/src/assets/lottie/calendar/schedule-2.json +1 -0
  56. package/src/assets/lottie/celebration/confetti-1.json +1 -0
  57. package/src/assets/lottie/celebration/confetti-2.json +1 -0
  58. package/src/assets/lottie/celebration/confetti-3.json +1 -0
  59. package/src/assets/lottie/cloud/cloud-1.json +1 -0
  60. package/src/assets/lottie/cloud/cloud-2.json +1 -0
  61. package/src/assets/lottie/connection/network-1.json +1 -0
  62. package/src/assets/lottie/connection/network-2.json +1 -0
  63. package/src/assets/lottie/connection/network-3.json +1 -0
  64. package/src/assets/lottie/dashboard/analytics-1.json +1 -0
  65. package/src/assets/lottie/dashboard/analytics-2.json +1 -0
  66. package/src/assets/lottie/dashboard/analytics-3.json +1 -0
  67. package/src/assets/lottie/email/mail-1.json +1 -0
  68. package/src/assets/lottie/email/mail-2.json +1 -0
  69. package/src/assets/lottie/email/mail-3.json +1 -0
  70. package/src/assets/lottie/empty-state/empty-1.json +1 -0
  71. package/src/assets/lottie/empty-state/empty-2.json +1 -0
  72. package/src/assets/lottie/empty-state/empty-3.json +1 -0
  73. package/src/assets/lottie/error/warning-1.json +1 -0
  74. package/src/assets/lottie/error/warning-2.json +1 -0
  75. package/src/assets/lottie/error/warning-3.json +1 -0
  76. package/src/assets/lottie/index.ts +49 -0
  77. package/src/assets/lottie/loading/spinner-1.json +1 -0
  78. package/src/assets/lottie/loading/spinner-2.json +1 -0
  79. package/src/assets/lottie/loading/spinner-3.json +1 -0
  80. package/src/assets/lottie/maintenance/construction-1.json +1 -0
  81. package/src/assets/lottie/maintenance/construction-2.json +1 -0
  82. package/src/assets/lottie/maintenance/construction-3.json +1 -0
  83. package/src/assets/lottie/not-found/404-1.json +1 -0
  84. package/src/assets/lottie/not-found/404-2.json +1 -0
  85. package/src/assets/lottie/not-found/404-3.json +1 -0
  86. package/src/assets/lottie/notification/bell-1.json +1 -0
  87. package/src/assets/lottie/notification/bell-2.json +1 -0
  88. package/src/assets/lottie/notification/bell-3.json +1 -0
  89. package/src/assets/lottie/onboarding/welcome-1.json +1 -0
  90. package/src/assets/lottie/onboarding/welcome-2.json +1 -0
  91. package/src/assets/lottie/onboarding/welcome-3.json +1 -0
  92. package/src/assets/lottie/payment/wallet-1.json +1 -0
  93. package/src/assets/lottie/payment/wallet-2.json +1 -0
  94. package/src/assets/lottie/payment/wallet-3.json +1 -0
  95. package/src/assets/lottie/search/search-1.json +1 -0
  96. package/src/assets/lottie/search/search-2.json +1 -0
  97. package/src/assets/lottie/search/search-3.json +1 -0
  98. package/src/assets/lottie/security/lock-1.json +1 -0
  99. package/src/assets/lottie/security/lock-2.json +1 -0
  100. package/src/assets/lottie/security/lock-3.json +1 -0
  101. package/src/assets/lottie/settings/gear-1.json +1 -0
  102. package/src/assets/lottie/settings/gear-2.json +1 -0
  103. package/src/assets/lottie/settings/gear-3.json +1 -0
  104. package/src/assets/lottie/success/check-1.json +1 -0
  105. package/src/assets/lottie/success/check-2.json +1 -0
  106. package/src/assets/lottie/success/check-3.json +1 -0
  107. package/src/assets/lottie/upload/upload-1.json +1 -0
  108. package/src/assets/lottie/upload/upload-2.json +1 -0
  109. package/src/assets/lottie/upload/upload-3.json +1 -0
  110. package/src/assets/lottie/user/profile-1.json +1 -0
  111. package/src/assets/lottie/user/profile-2.json +1 -0
  112. package/src/assets/lottie/user/profile-3.json +1 -0
  113. package/src/base/blocks/ActionGridBlock.tsx +151 -0
  114. package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
  115. package/src/base/blocks/CardGridBlock.tsx +384 -0
  116. package/src/base/blocks/ChartBlock.tsx +81 -0
  117. package/src/base/blocks/DenseTableBlock.tsx +403 -0
  118. package/src/base/blocks/DetailPanelBlock.tsx +189 -0
  119. package/src/base/blocks/EmptyStateBlock.tsx +46 -0
  120. package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
  121. package/src/base/blocks/FormPanelBlock.tsx +480 -0
  122. package/src/base/blocks/LinkListBlock.tsx +94 -0
  123. package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
  124. package/src/base/blocks/MetricCardBlock.tsx +128 -0
  125. package/src/base/blocks/StatusStripBlock.tsx +43 -0
  126. package/src/base/blocks/TabsBlock.tsx +94 -0
  127. package/src/base/form/FormField.tsx +607 -0
  128. package/src/base/form/fields/CheckboxField.tsx +56 -0
  129. package/src/base/form/fields/ColorField.tsx +76 -0
  130. package/src/base/form/fields/CurrencyField.tsx +126 -0
  131. package/src/base/form/fields/DateField.tsx +168 -0
  132. package/src/base/form/fields/DateRangeField.tsx +66 -0
  133. package/src/base/form/fields/DocumentField.tsx +222 -0
  134. package/src/base/form/fields/EntityPickerField.tsx +244 -0
  135. package/src/base/form/fields/FileUploadField.tsx +253 -0
  136. package/src/base/form/fields/MultiSelectField.tsx +286 -0
  137. package/src/base/form/fields/NativeSelectField.tsx +67 -0
  138. package/src/base/form/fields/NumberField.tsx +67 -0
  139. package/src/base/form/fields/OtpField.tsx +88 -0
  140. package/src/base/form/fields/PasswordField.tsx +69 -0
  141. package/src/base/form/fields/PhoneField.tsx +64 -0
  142. package/src/base/form/fields/RadioField.tsx +66 -0
  143. package/src/base/form/fields/RatingField.tsx +52 -0
  144. package/src/base/form/fields/SelectField.tsx +76 -0
  145. package/src/base/form/fields/SliderField.tsx +77 -0
  146. package/src/base/form/fields/SlugField.tsx +114 -0
  147. package/src/base/form/fields/StaticField.tsx +25 -0
  148. package/src/base/form/fields/SwitchField.tsx +56 -0
  149. package/src/base/form/fields/TagsField.tsx +128 -0
  150. package/src/base/form/fields/TextField.tsx +55 -0
  151. package/src/base/form/fields/TextareaField.tsx +55 -0
  152. package/src/base/form/fields/document-validation.ts +126 -0
  153. package/src/base/form/fields/field-registry.ts +53 -0
  154. package/src/base/form/fields/register-default-fields.ts +86 -0
  155. package/src/base/form/form-schema-builder.ts +192 -0
  156. package/src/base/form/form-utils.ts +71 -0
  157. package/src/base/hooks/useIsDark.ts +50 -0
  158. package/src/base/hooks/useLazyTabs.ts +98 -0
  159. package/src/base/hooks/usePolling.ts +43 -0
  160. package/src/base/hooks/useRemember.ts +58 -0
  161. package/src/base/hooks/useToast.ts +27 -0
  162. package/src/base/layout/BlockRegion.tsx +39 -0
  163. package/src/base/layout/DashboardLayout.tsx +110 -0
  164. package/src/base/layout/SidebarLayout.tsx +38 -0
  165. package/src/base/layout/StackLayout.tsx +32 -0
  166. package/src/base/layout/WizardLayout.tsx +49 -0
  167. package/src/base/partials/ActionBar/index.tsx +115 -0
  168. package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
  169. package/src/base/partials/DataTable/cell-registry.ts +50 -0
  170. package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
  171. package/src/base/partials/DataTable/index.tsx +1282 -0
  172. package/src/base/partials/DataTable/register-default-cells.ts +37 -0
  173. package/src/base/partials/DataTable/sanitize-html.ts +45 -0
  174. package/src/base/partials/DataTable/types.ts +229 -0
  175. package/src/base/partials/DetailSection/index.tsx +316 -0
  176. package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
  177. package/src/base/partials/EntityItem/index.tsx +154 -0
  178. package/src/base/partials/FilterBar/index.tsx +256 -0
  179. package/src/base/partials/FormSection/index.tsx +87 -0
  180. package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
  181. package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
  182. package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
  183. package/src/base/partials/LogViewer/index.tsx +110 -0
  184. package/src/base/partials/LogViewer/types.ts +28 -0
  185. package/src/base/partials/MarkdownContent/index.tsx +307 -0
  186. package/src/base/partials/MenuBar/index.tsx +80 -0
  187. package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
  188. package/src/base/partials/ResizableSidebar/index.tsx +70 -0
  189. package/src/base/partials/StatRow/index.tsx +28 -0
  190. package/src/base/partials/StatusBar/index.tsx +126 -0
  191. package/src/base/partials/StatusIndicator/index.tsx +61 -0
  192. package/src/base/partials/StepIndicator/index.tsx +63 -0
  193. package/src/base/partials/TableOfContents/index.tsx +78 -0
  194. package/src/base/partials/TimelineList/index.tsx +273 -0
  195. package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
  196. package/src/base/partials/TreeView/index.tsx +75 -0
  197. package/src/base/partials/index.ts +23 -0
  198. package/src/base/shell/AuthShell.tsx +54 -0
  199. package/src/base/shell/BasicShell.tsx +286 -0
  200. package/src/base/shell/ImmersiveShell.tsx +85 -0
  201. package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
  202. package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
  203. package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
  204. package/src/base/shell/partials/InspectorContext.tsx +173 -0
  205. package/src/base/shell/partials/InspectorPanel.tsx +65 -0
  206. package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
  207. package/src/base/shell/partials/OverlayScreen.tsx +67 -0
  208. package/src/base/shell/partials/PageActionButton.tsx +203 -0
  209. package/src/base/theme/appearance.ts +133 -0
  210. package/src/base/theme/host-layout-detector.ts +119 -0
  211. package/src/base/theme/host-theme-detector.ts +146 -0
  212. package/src/base/theme/sidebar-safelist.txt +20 -0
  213. package/src/base/theme/tailwind-theme.css +136 -0
  214. package/src/base/theme/theme-bridge.css +164 -0
  215. package/src/base/theme/theme-context.tsx +142 -0
  216. package/src/base/theme/themes/classic.css +174 -0
  217. package/src/base/theme/tokens.css +290 -0
  218. package/src/base/theme/useHostTheme.ts +95 -0
  219. package/src/base/utils/clipboard.ts +39 -0
  220. package/src/base/utils/conditions.ts +27 -0
  221. package/src/base/utils/icon-registry.ts +78 -0
  222. package/src/base/utils/icons.ts +31 -0
  223. package/src/base/utils/interpolate.ts +9 -0
  224. package/src/base/utils/register-default-icons.ts +163 -0
  225. package/src/base/utils/storage.ts +65 -0
  226. package/src/base/utils/time.ts +139 -0
  227. package/src/contracts/block-data/actions.ts +73 -0
  228. package/src/contracts/block-data/data-display.ts +343 -0
  229. package/src/contracts/block-data/form.ts +164 -0
  230. package/src/contracts/block-data/index.ts +15 -0
  231. package/src/contracts/block-data/interactive.ts +34 -0
  232. package/src/contracts/block-data/shared.ts +44 -0
  233. package/src/contracts/connectors.ts +60 -0
  234. package/src/contracts/generated/contract-schema.ts +1237 -0
  235. package/src/contracts/generated/contract-types.ts +675 -0
  236. package/src/contracts/generated/index.ts +15 -0
  237. package/src/contracts/navigation.ts +59 -0
  238. package/src/contracts/page-contract-schema.ts +40 -0
  239. package/src/contracts/page-contract.ts +79 -0
  240. package/src/contracts/shared-props.ts +92 -0
  241. package/src/engine/ContractPage.tsx +178 -0
  242. package/src/engine/EntityRoutes.tsx +72 -0
  243. package/src/engine/HostSlot.tsx +126 -0
  244. package/src/engine/LazyBlock.tsx +92 -0
  245. package/src/engine/bootstrap.tsx +20 -0
  246. package/src/engine/providers/auth.tsx +87 -0
  247. package/src/engine/providers/error-reporter.tsx +89 -0
  248. package/src/engine/providers/flash.tsx +44 -0
  249. package/src/engine/providers/index.ts +18 -0
  250. package/src/engine/providers/inertia-error-reporter.tsx +61 -0
  251. package/src/engine/providers/progress.tsx +56 -0
  252. package/src/engine/providers/scope.tsx +51 -0
  253. package/src/engine/register-defaults.ts +88 -0
  254. package/src/engine/registries.ts +96 -0
  255. package/src/i18n/I18nProvider.tsx +53 -0
  256. package/src/i18n/MANIFEST.md +101 -0
  257. package/src/i18n/host-resolver.ts +18 -0
  258. package/src/i18n/instance.ts +69 -0
  259. package/src/i18n/locales/en/ui.json +277 -0
  260. package/src/i18n/locales/en/validators.json +13 -0
  261. package/src/i18n/locales/pt-BR/ui.json +277 -0
  262. package/src/i18n/locales/pt-BR/validators.json +13 -0
  263. package/src/i18n/register-strings.ts +10 -0
  264. package/src/i18n/render-label.ts +33 -0
  265. package/src/i18n/resolve-field-error.ts +29 -0
  266. package/src/i18n/useHostString.ts +50 -0
  267. package/src/i18n/useTranslation.ts +83 -0
  268. package/src/lib/actions/resolve-action-target.ts +151 -0
  269. package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
  270. package/src/lib/hooks/use-file-upload.ts +406 -0
  271. package/src/lib/hooks/use-mobile.ts +21 -0
  272. package/src/lib/host-pending.ts +76 -0
  273. package/src/lib/portal-container.ts +16 -0
  274. package/src/lib/test-ids.ts +40 -0
  275. package/src/lib/utils.ts +6 -0
  276. package/src/primitives/reui/MANIFEST.md +97 -0
  277. package/src/primitives/reui/accordion.tsx +64 -0
  278. package/src/primitives/reui/alert-dialog.tsx +196 -0
  279. package/src/primitives/reui/alert.tsx +92 -0
  280. package/src/primitives/reui/aspect-ratio.tsx +9 -0
  281. package/src/primitives/reui/autocomplete.tsx +343 -0
  282. package/src/primitives/reui/avatar.tsx +109 -0
  283. package/src/primitives/reui/badge.tsx +94 -0
  284. package/src/primitives/reui/breadcrumb.tsx +109 -0
  285. package/src/primitives/reui/button-group.tsx +83 -0
  286. package/src/primitives/reui/button.tsx +64 -0
  287. package/src/primitives/reui/calendar.tsx +220 -0
  288. package/src/primitives/reui/card.tsx +92 -0
  289. package/src/primitives/reui/carousel.tsx +239 -0
  290. package/src/primitives/reui/chart.tsx +388 -0
  291. package/src/primitives/reui/checkbox.tsx +30 -0
  292. package/src/primitives/reui/collapsible.tsx +31 -0
  293. package/src/primitives/reui/combobox.tsx +308 -0
  294. package/src/primitives/reui/command.tsx +182 -0
  295. package/src/primitives/reui/context-menu.tsx +250 -0
  296. package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
  297. package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
  298. package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
  299. package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
  300. package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
  301. package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
  302. package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
  303. package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
  304. package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
  305. package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
  306. package/src/primitives/reui/data-grid-pagination.tsx +235 -0
  307. package/src/primitives/reui/date-selector.tsx +1353 -0
  308. package/src/primitives/reui/dialog.tsx +158 -0
  309. package/src/primitives/reui/drawer.tsx +133 -0
  310. package/src/primitives/reui/dropdown-menu.tsx +257 -0
  311. package/src/primitives/reui/empty.tsx +104 -0
  312. package/src/primitives/reui/field.tsx +246 -0
  313. package/src/primitives/reui/filters.tsx +1891 -0
  314. package/src/primitives/reui/frame.tsx +170 -0
  315. package/src/primitives/reui/hover-card.tsx +42 -0
  316. package/src/primitives/reui/icon-placeholder.tsx +39 -0
  317. package/src/primitives/reui/index.ts +98 -0
  318. package/src/primitives/reui/input-group.tsx +170 -0
  319. package/src/primitives/reui/input-otp.tsx +75 -0
  320. package/src/primitives/reui/input.tsx +21 -0
  321. package/src/primitives/reui/item.tsx +193 -0
  322. package/src/primitives/reui/kanban.tsx +743 -0
  323. package/src/primitives/reui/kbd.tsx +28 -0
  324. package/src/primitives/reui/label.tsx +22 -0
  325. package/src/primitives/reui/menubar.tsx +274 -0
  326. package/src/primitives/reui/native-select.tsx +62 -0
  327. package/src/primitives/reui/navigation-menu.tsx +168 -0
  328. package/src/primitives/reui/number-field.tsx +250 -0
  329. package/src/primitives/reui/pagination.tsx +127 -0
  330. package/src/primitives/reui/phone-input.tsx +231 -0
  331. package/src/primitives/reui/popover.tsx +87 -0
  332. package/src/primitives/reui/progress.tsx +31 -0
  333. package/src/primitives/reui/radio-group.tsx +43 -0
  334. package/src/primitives/reui/rating.tsx +177 -0
  335. package/src/primitives/reui/resizable.tsx +51 -0
  336. package/src/primitives/reui/scroll-area.tsx +58 -0
  337. package/src/primitives/reui/scrollspy.tsx +240 -0
  338. package/src/primitives/reui/select.tsx +188 -0
  339. package/src/primitives/reui/separator.tsx +28 -0
  340. package/src/primitives/reui/sheet.tsx +141 -0
  341. package/src/primitives/reui/sidebar.tsx +732 -0
  342. package/src/primitives/reui/skeleton.tsx +13 -0
  343. package/src/primitives/reui/slider.tsx +61 -0
  344. package/src/primitives/reui/sonner.tsx +47 -0
  345. package/src/primitives/reui/sortable.tsx +414 -0
  346. package/src/primitives/reui/spinner.tsx +16 -0
  347. package/src/primitives/reui/stepper.tsx +484 -0
  348. package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
  349. package/src/primitives/reui/svgs/gemini.tsx +171 -0
  350. package/src/primitives/reui/svgs/openai.tsx +9 -0
  351. package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
  352. package/src/primitives/reui/switch.tsx +33 -0
  353. package/src/primitives/reui/table.tsx +114 -0
  354. package/src/primitives/reui/tabs.tsx +91 -0
  355. package/src/primitives/reui/textarea.tsx +18 -0
  356. package/src/primitives/reui/timeline.tsx +219 -0
  357. package/src/primitives/reui/toggle-group.tsx +83 -0
  358. package/src/primitives/reui/toggle.tsx +45 -0
  359. package/src/primitives/reui/tooltip.tsx +55 -0
  360. package/src/primitives/reui/tree.tsx +247 -0
  361. package/src/theme.css +71 -0
  362. package/dist-lib/chunks/subpath-q4Q2zg_p.js +0 -153
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Navigation contract — typed shape for the `navigation` Inertia shared prop.
3
+ *
4
+ * Unified tree model (NV-05 — ADR-807 expanded).
5
+ * PHP serializes this from navigation_registry during boot().
6
+ * Frontend reads it from usePage().props.navigation.
7
+ *
8
+ * @see ADR-807 ref/shell-and-navigation §4
9
+ * @see NV-05-ux-shell-sidebar.md §1.3
10
+ */
11
+
12
+ /** Entity types for automatic icon resolution when no explicit icon is set. */
13
+ export type NavigationEntityType =
14
+ | "connector"
15
+ | "workflow"
16
+ | "segment"
17
+ | "instancegroup"
18
+ | "condition"
19
+ | "compliance"
20
+ | "offering"
21
+ | "order"
22
+ | "course"
23
+ | "category"
24
+ | "form"
25
+ | "certificate";
26
+
27
+ export interface NavigationNode {
28
+ key: string;
29
+ label: string;
30
+ icon?: string;
31
+ /** Entity type for automatic icon resolution (CC-based). Overrides depth fallback. */
32
+ entityType?: NavigationEntityType;
33
+ href?: string;
34
+ badge?: string | number;
35
+ /** Badge display variant: 'count' (muted text, default) or 'alert' (red pill like WooCommerce). */
36
+ badgeVariant?: "count" | "alert";
37
+ active?: boolean;
38
+ /** When true, clicking replaces sidebar with this node's children + back. */
39
+ drilldown?: boolean;
40
+ /** When true, group renders with a toggle to expand/collapse its content. */
41
+ collapsible?: boolean;
42
+ /** Whether a collapsible group starts expanded (default: false). */
43
+ defaultOpen?: boolean;
44
+ /** CSS color for status dot shown next to drilldown title (e.g. 'var(--success)'). */
45
+ statusColor?: string;
46
+ /** Link target attribute (e.g. '_blank'). External URLs (http/https) auto-detect. */
47
+ target?: string;
48
+ children?: NavigationNode[];
49
+ }
50
+
51
+ /** Navigation payload using the unified tree model */
52
+ export interface NavigationTreePayload {
53
+ tree: NavigationNode[];
54
+ activeKey: string;
55
+ /** Stack of drilled-down node keys (for ← back navigation). */
56
+ drilldownStack?: string[];
57
+ /** Persistent footer items (Settings, Help). */
58
+ footer: NavigationNode[];
59
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Zod schema for PageContract runtime validation.
3
+ *
4
+ * Used by ContractPage to validate contracts received from the backend before
5
+ * rendering. The schema is the canonical wire shape generated from
6
+ * `middag-php-ui` (single source of truth) — see `@/contracts/generated`.
7
+ *
8
+ * DA-03: the host-extensible parts are validated loosely. The generated core is
9
+ * already lenient on unknown keys (Pro overlay + forward-compat fields are
10
+ * stripped, not rejected); on top of that, `resources` is relaxed to a
11
+ * permissive record because hosts patch it (preferences/capabilities/branding)
12
+ * and the React Pro overlay (auth/locale) rides alongside.
13
+ */
14
+
15
+ import { z } from "zod";
16
+
17
+ import { pageContractSchemaCore } from "@/contracts/generated";
18
+
19
+ export const pageContractSchema = pageContractSchemaCore.extend({
20
+ resources: z.record(z.string(), z.unknown()).optional(),
21
+ });
22
+
23
+ export type PageContractValidationError = {
24
+ field: string;
25
+ message: string;
26
+ };
27
+
28
+ /**
29
+ * Validate a PageContract shape. Returns null if valid, or an array of
30
+ * validation errors if invalid.
31
+ */
32
+ export function validatePageContract(contract: unknown): PageContractValidationError[] | null {
33
+ const result = pageContractSchema.safeParse(contract);
34
+ if (result.success) return null;
35
+
36
+ return result.error.issues.map((issue) => ({
37
+ field: issue.path.join("."),
38
+ message: issue.message,
39
+ }));
40
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Page Contract — composed wire types.
3
+ *
4
+ * The wire shape comes from `middag-php-ui` value objects, generated into
5
+ * `@/contracts/generated`. This file refines those canonical types into the
6
+ * public contract the runtime renders (i18n-aware actions, typed block data).
7
+ *
8
+ * Pro overlays — page chrome (badge, meta, filter tabs), contextual help,
9
+ * inspector, the action `display` channel, and the `Pro*` page contract — live in
10
+ * `@middag-io/react-pro`, composed OVER these base types. The Community engine ships
11
+ * the lean wire shape only. Dependency direction is one-way: react-pro → react.
12
+ */
13
+
14
+ import type { Action } from "@/contracts/block-data";
15
+ import type {
16
+ BlockDescriptor as WireBlockDescriptor,
17
+ Breadcrumb as WireBreadcrumb,
18
+ LayoutDescriptor as WireLayoutDescriptor,
19
+ PageContract as WirePageContract,
20
+ PageMeta as WirePageMeta,
21
+ PageResources as WirePageResources,
22
+ } from "@/contracts/generated";
23
+
24
+ // ── Composed wire types ──────────────────────────────────────────────────────
25
+
26
+ /** Breadcrumb — canonical (i18n-aware label, external flag). */
27
+ export type Breadcrumb = WireBreadcrumb;
28
+
29
+ /** Page-level action button — the canonical Action (DA-05). */
30
+ export type PageAction = Action;
31
+
32
+ export type PageMeta = Omit<WirePageMeta, "actions"> & {
33
+ actions?: PageAction[];
34
+ };
35
+
36
+ export type BlockDescriptor<TData = Record<string, unknown>> = Omit<
37
+ WireBlockDescriptor,
38
+ "data" | "actions"
39
+ > & {
40
+ data: TData;
41
+ actions?: PageAction[];
42
+ };
43
+
44
+ export type LayoutDescriptor = Omit<WireLayoutDescriptor, "regions"> & {
45
+ regions: Record<string, BlockDescriptor[]>;
46
+ };
47
+
48
+ /** Page resources — canonical php-ui shape. */
49
+ export type PageResources = WirePageResources;
50
+
51
+ export type PageContract = Omit<WirePageContract, "page" | "layout" | "resources"> & {
52
+ page: PageMeta;
53
+ layout: LayoutDescriptor;
54
+ resources?: PageResources;
55
+ // `entities` (entity type → route pattern) now rides on the generated
56
+ // WirePageContract — sourced from the middag-php-ui PageContract VO.
57
+ };
58
+
59
+ // ── Extended Inertia props (sent alongside the contract, not inside it) ──────
60
+
61
+ /**
62
+ * Inertia props shape for ContractPage. `overlay` toggles a full-screen overlay.
63
+ * Pro props (help, inspector) are added by @middag-io/react-pro.
64
+ */
65
+ export interface ContractPageProps {
66
+ contract: PageContract;
67
+ /** When true, page renders in a full-screen overlay with X close. */
68
+ overlay?: boolean;
69
+ /**
70
+ * Shell rendering mode:
71
+ * - `"full"` (default): resolve and mount the contract's shell around the
72
+ * layout — the standalone/self-contained rendering used by Inertia pages.
73
+ * - `"content-only"`: render only `EntityRoutesProvider + Layout`, WITHOUT
74
+ * the shell. For hosts that mount a persistent shell once (e.g. a React
75
+ * Router layout route) and swap page content beneath it, avoiding the shell
76
+ * remount that flashes the sidebar on every navigation.
77
+ */
78
+ shellMode?: "full" | "content-only";
79
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * SharedProps — typed Inertia shared props sent on every request.
3
+ *
4
+ * PHP side: inertia_manager::share() in http_kernel boot.
5
+ * Frontend: usePage<SharedProps>().props
6
+ *
7
+ * @see NV-05-ux-shell-sidebar.md §1.3
8
+ */
9
+
10
+ import type { NavigationTreePayload } from "@/contracts/navigation";
11
+
12
+ export interface SharedPropsAuth {
13
+ /** Moodle user ID */
14
+ id: number;
15
+ /** Full display name */
16
+ name: string;
17
+ /** Email address */
18
+ email: string;
19
+ /** URL to user avatar (Moodle profile picture) */
20
+ avatarUrl?: string;
21
+ /** Array of Moodle capability strings the user holds in current context */
22
+ capabilities: string[];
23
+ /** Logout URL (Moodle sesskey-signed). Present when the host injects it. */
24
+ logoutUrl?: string;
25
+ }
26
+
27
+ export interface SharedPropsTheme {
28
+ /** Pre-loaded i18n strings for the current page (key → translated string) */
29
+ strings?: Record<string, string>;
30
+ /**
31
+ * Current appearance preference: 'system' | 'light' | 'dark'.
32
+ * Sent from server to sync cross-device. Client reads localStorage first.
33
+ */
34
+ appearance?: "system" | "light" | "dark";
35
+ /**
36
+ * Moodle brand color (hex, e.g. "#1177d1").
37
+ * Present when local_middag/inherit_theme_colors = ON.
38
+ * PHP injects :root { --middag-brand: <value> } in page head.
39
+ */
40
+ brandColor?: string;
41
+ /** Whether Moodle theme color inheritance is active */
42
+ inherit?: boolean;
43
+ }
44
+
45
+ export interface SharedPropsFlash {
46
+ /** Success message to show as toast */
47
+ success?: string;
48
+ /** Error message to show as toast */
49
+ error?: string;
50
+ /** Info message to show as toast */
51
+ info?: string;
52
+ /** Warning message to show as toast */
53
+ warning?: string;
54
+ toast?: {
55
+ severity: "success" | "error" | "warning" | "info";
56
+ message: string;
57
+ duration?: number;
58
+ };
59
+ }
60
+
61
+ export interface AdminTabItem {
62
+ key: string;
63
+ label: string;
64
+ href: string;
65
+ }
66
+
67
+ export interface AdminTabsProps {
68
+ active: string;
69
+ items: AdminTabItem[];
70
+ }
71
+
72
+ export interface SharedProps {
73
+ navigation: NavigationTreePayload;
74
+ /**
75
+ * Authenticated user. Optional/null on guest-facing pages (e.g. login) where
76
+ * no user is established yet. AuthProvider tolerates its absence: `user` is
77
+ * null, `isAuthenticated` false, and every capability check returns false.
78
+ */
79
+ auth?: SharedPropsAuth | null;
80
+ theme: SharedPropsTheme;
81
+ flash?: SharedPropsFlash;
82
+ /** Effective locale string, e.g. "pt-BR", "en" */
83
+ locale: string;
84
+ /** MIDDAG version string, e.g. "5.0.0" */
85
+ version: string;
86
+ /** Global scope data from global_scope_manager (extensions add their keys) */
87
+ scope?: Record<string, unknown>;
88
+ /** CSRF/session token (Moodle sesskey) for state-changing requests. */
89
+ csrf_token?: string;
90
+ /** Index signature required by Inertia's PageProps constraint (usePage<SharedProps>()). */
91
+ [key: string]: unknown;
92
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * ContractPage — entry point for any page driven by PageContract.
3
+ *
4
+ * Resolves shell → layout → blocks through registries (ADR-807).
5
+ * Feature pages compose their contract in the backend; the runtime
6
+ * handles rendering deterministically.
7
+ *
8
+ * Validation (D4): Zod validates the contract shape on entry. Invalid
9
+ * contracts render a diagnostic panel in dev, preventing white screens.
10
+ *
11
+ * Fallbacks (D5): Unknown layout falls back to "stack" with console.warn.
12
+ */
13
+
14
+ import { Suspense, useCallback, useMemo, type ReactElement } from "react";
15
+
16
+ import { NavErrorBoundary } from "@/base/shell/partials/NavErrorBoundary";
17
+ import { OverlayScreen } from "@/base/shell/partials/OverlayScreen";
18
+ import type { BlockDescriptor, ContractPageProps } from "@/contracts/page-contract";
19
+ import { validatePageContract } from "@/contracts/page-contract-schema";
20
+ import { EntityRoutesProvider } from "@/engine/EntityRoutes";
21
+ import { isLazyBlock, LazyBlock } from "@/engine/LazyBlock";
22
+ import { resolveBlock, resolveLayout, resolveShell } from "@/engine/registries";
23
+ import { useTranslation } from "@/i18n/useTranslation";
24
+
25
+ // Registry-based dynamic component resolution (ADR-807 §6). Shell and Layout are
26
+ // stable singleton references retrieved from the registry — not new components.
27
+ /* eslint-disable react-hooks/static-components */
28
+ export function ContractPage({
29
+ contract,
30
+ overlay,
31
+ shellMode = "full",
32
+ }: ContractPageProps): ReactElement {
33
+ // All hooks called unconditionally before any early returns.
34
+ const { t } = useTranslation();
35
+ const validationErrors = useMemo(() => validatePageContract(contract), [contract]);
36
+
37
+ const Shell = useMemo(
38
+ () => resolveShell(contract?.shell) ?? resolveShell("immersive"),
39
+ [contract?.shell],
40
+ );
41
+
42
+ // D5: unknown layout falls back to "stack" instead of rendering error
43
+ const Layout = useMemo(() => {
44
+ const resolved = resolveLayout(contract?.layout?.template);
45
+ if (!resolved) {
46
+ return resolveLayout("stack");
47
+ }
48
+ return resolved;
49
+ }, [contract?.layout?.template]);
50
+
51
+ // D15: stable reference — prevents Layout re-renders if it's memoized
52
+ const renderBlock = useCallback(
53
+ (block: BlockDescriptor): ReactElement | null => {
54
+ const Block = resolveBlock(block.type);
55
+
56
+ if (!Block) {
57
+ // role="alert" surfaces the diagnostic to assistive tech; the specific
58
+ // block type is a dev-only detail (verbose só DEV) — prod shows only the
59
+ // translated category so internal keys never leak to end users.
60
+ return (
61
+ <div
62
+ key={block.key}
63
+ role="alert"
64
+ className="border-muted-foreground/30 text-muted-foreground rounded border border-dashed p-2 text-xs"
65
+ >
66
+ {t("middag.ui.block.unknown_type")}
67
+ {import.meta.env.DEV ? (
68
+ <>
69
+ {" "}
70
+ <code>{block.type}</code>
71
+ </>
72
+ ) : null}
73
+ </div>
74
+ );
75
+ }
76
+
77
+ // Lazy blocks fetch data via Inertia partial reload on mount
78
+ if (isLazyBlock(block)) {
79
+ return (
80
+ <NavErrorBoundary key={block.key}>
81
+ <LazyBlock block={block} Component={Block} />
82
+ </NavErrorBoundary>
83
+ );
84
+ }
85
+
86
+ return (
87
+ <NavErrorBoundary key={block.key}>
88
+ <Suspense fallback={<div className="bg-muted animate-pulse rounded p-4" />}>
89
+ <Block block={block} />
90
+ </Suspense>
91
+ </NavErrorBoundary>
92
+ );
93
+ },
94
+ [t],
95
+ );
96
+
97
+ // ── Early returns after all hooks ───────────────────────────────────────
98
+
99
+ if (validationErrors) {
100
+ // The per-field validation list is a dev diagnostic (verbose só DEV); prod
101
+ // renders only the translated headline inside the alert.
102
+ return (
103
+ <div
104
+ role="alert"
105
+ className="border-destructive/20 bg-destructive/10 text-destructive m-4 rounded-md border p-4 text-sm"
106
+ >
107
+ <p className="font-semibold">{t("middag.ui.contract.invalid")}</p>
108
+ {import.meta.env.DEV ? (
109
+ <ul className="mt-2 list-inside list-disc space-y-1">
110
+ {validationErrors.map((err, i) => (
111
+ <li key={i}>
112
+ <code className="text-xs">{err.field || "root"}</code>: {err.message}
113
+ </li>
114
+ ))}
115
+ </ul>
116
+ ) : null}
117
+ </div>
118
+ );
119
+ }
120
+
121
+ if (!Layout) {
122
+ return (
123
+ <div
124
+ role="alert"
125
+ className="border-destructive/20 bg-destructive/10 text-destructive m-4 rounded-md border p-4 text-sm"
126
+ >
127
+ {t("middag.ui.layout.unknown_type")}
128
+ {import.meta.env.DEV ? (
129
+ <>
130
+ {" "}
131
+ <code>{contract.layout.template}</code>
132
+ </>
133
+ ) : null}
134
+ </div>
135
+ );
136
+ }
137
+
138
+ const layoutEl = <Layout layout={contract.layout} renderBlock={renderBlock} />;
139
+
140
+ // Content-only: render EntityRoutesProvider + Layout WITHOUT the shell, so a
141
+ // host that mounts the shell once (persistent layout route) can swap page
142
+ // content beneath it without remounting — and re-triggering — the sidebar.
143
+ if (shellMode === "content-only") {
144
+ const contentOnly = (
145
+ <EntityRoutesProvider entities={contract.entities ?? {}}>{layoutEl}</EntityRoutesProvider>
146
+ );
147
+ return overlay ? <OverlayScreen>{contentOnly}</OverlayScreen> : contentOnly;
148
+ }
149
+
150
+ if (!Shell) {
151
+ return (
152
+ <div
153
+ role="alert"
154
+ className="border-destructive/20 bg-destructive/10 text-destructive m-4 rounded-md border p-4 text-sm"
155
+ >
156
+ {t("middag.ui.shell.unknown_type")}
157
+ {import.meta.env.DEV ? (
158
+ <>
159
+ {" "}
160
+ <code>{contract.shell}</code>
161
+ </>
162
+ ) : null}
163
+ </div>
164
+ );
165
+ }
166
+
167
+ const shellContent = (
168
+ <EntityRoutesProvider entities={contract.entities ?? {}}>
169
+ <Shell>{layoutEl}</Shell>
170
+ </EntityRoutesProvider>
171
+ );
172
+
173
+ if (overlay) {
174
+ return <OverlayScreen>{shellContent}</OverlayScreen>;
175
+ }
176
+
177
+ return shellContent;
178
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * EntityRoutes — contract-level entity-to-route resolution.
3
+ *
4
+ * ContractPage provides the entities map via context.
5
+ * Any block can use useEntityRoute() to resolve entity links.
6
+ */
7
+
8
+ import { createContext, useContext, type ReactElement, type ReactNode } from "react";
9
+ import { router } from "@inertiajs/core";
10
+
11
+ type EntityRoutes = Record<string, string>;
12
+
13
+ const EntityRoutesContext = createContext<EntityRoutes>({});
14
+
15
+ export function EntityRoutesProvider({
16
+ entities,
17
+ children,
18
+ }: {
19
+ entities: EntityRoutes;
20
+ children: ReactNode;
21
+ }): ReactElement {
22
+ const parent = useContext(EntityRoutesContext);
23
+ const merged = { ...parent, ...entities };
24
+ return <EntityRoutesContext.Provider value={merged}>{children}</EntityRoutesContext.Provider>;
25
+ }
26
+
27
+ /**
28
+ * Resolve an entity type + ID to a URL.
29
+ * Returns null if the entity type is not in the contract's entities map.
30
+ */
31
+ // eslint-disable-next-line react-refresh/only-export-components
32
+ export function useEntityRoute(): (type: string, id: string | number) => string | null {
33
+ const entities = useContext(EntityRoutesContext);
34
+ return (type: string, id: string | number) => {
35
+ const pattern = entities[type];
36
+ if (!pattern) return null;
37
+ return pattern.replace("{id}", String(id));
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Render a value as a navigable entity link.
43
+ * Falls back to plain text if entity type is not in the contract map.
44
+ */
45
+ export function EntityLink({
46
+ type,
47
+ id,
48
+ children,
49
+ }: {
50
+ type: string;
51
+ id: string | number;
52
+ children: ReactNode;
53
+ }): ReactElement {
54
+ const resolve = useEntityRoute();
55
+ const href = resolve(type, id);
56
+
57
+ if (!href) return <>{children}</>;
58
+
59
+ return (
60
+ <a
61
+ href={href}
62
+ onClick={(e) => {
63
+ e.preventDefault();
64
+ e.stopPropagation();
65
+ router.visit(href);
66
+ }}
67
+ className="text-primary hover:underline"
68
+ >
69
+ {children}
70
+ </a>
71
+ );
72
+ }
@@ -0,0 +1,126 @@
1
+ /**
2
+ * HostSlot — portal React components into host-rendered DOM slots.
3
+ *
4
+ * Pattern: the host (Moodle PHP / WordPress) renders empty containers
5
+ * with a known `id` or `data-middag-slot` attribute inside its own
6
+ * chrome (e.g. the Boost navbar). React portals MIDDAG widgets into
7
+ * those containers at runtime, achieving seamless visual integration
8
+ * without the host needing to know about React.
9
+ *
10
+ * ## Host side (PHP — Moodle Boost renderer example)
11
+ *
12
+ * ```php
13
+ * // In theme_boost/layout/columns2.php or local_middag output hook:
14
+ * echo '<div id="middag-global-search" data-middag-slot="search" class="middag-slot"></div>';
15
+ * echo '<div id="middag-org-selector" data-middag-slot="org" class="middag-slot"></div>';
16
+ * echo '<div id="middag-quick-menu" data-middag-slot="menu" class="middag-slot"></div>';
17
+ * ```
18
+ *
19
+ * ## React side (app bootstrap)
20
+ *
21
+ * ```tsx
22
+ * import { HostSlot } from '@middag-io/react';
23
+ * import { BoostSearchBar } from '@middag-io/react';
24
+ *
25
+ * // Inside your provider tree (after I18nProvider):
26
+ * <HostSlot selector="#middag-global-search">
27
+ * <BoostSearchBar onActivate={() => openCommandPalette()} />
28
+ * </HostSlot>
29
+ *
30
+ * <HostSlot selector="#middag-org-selector">
31
+ * <OrgSelector orgs={scopeData.orgs} current={scopeData.current} />
32
+ * </HostSlot>
33
+ * ```
34
+ *
35
+ * ## How it works
36
+ *
37
+ * 1. On mount, `HostSlot` queries the DOM for the target element.
38
+ * 2. If found, it uses `createPortal` to render children into it.
39
+ * 3. If not found (e.g. mock environment, WP without slots), renders nothing.
40
+ * 4. A MutationObserver watches for late-arriving slots (Moodle may render
41
+ * the navbar asynchronously via Mustache templates).
42
+ *
43
+ * ## Reserved slot IDs
44
+ *
45
+ * | Slot ID | Purpose | Injected by |
46
+ * |--------------------------|------------------------------|-----------------|
47
+ * | `middag-global-search` | Central search bar (⌘K) | local_middag |
48
+ * | `middag-org-selector` | Organization/scope switcher | local_middag |
49
+ * | `middag-quick-menu` | MIDDAG quick-access grid | local_middag |
50
+ *
51
+ * @see ADR-807 ref/host-integration
52
+ */
53
+
54
+ "use client";
55
+
56
+ import { useMemo, useSyncExternalStore, type ReactElement, type ReactNode } from "react";
57
+ import { createPortal } from "react-dom";
58
+
59
+ interface HostSlotProps {
60
+ /** CSS selector for the host-rendered container (e.g. "#middag-global-search"). */
61
+ selector: string;
62
+ /** Content to portal into the slot. */
63
+ children: ReactNode;
64
+ /** If true, render children inline as fallback when the slot is not found. */
65
+ fallback?: boolean;
66
+ }
67
+
68
+ /**
69
+ * External store that watches for a DOM element matching a selector.
70
+ * Uses MutationObserver to detect late-arriving elements.
71
+ */
72
+ function createSlotStore(selector: string) {
73
+ let current: Element | null = document.querySelector(selector);
74
+ const listeners = new Set<() => void>();
75
+
76
+ const subscribe = (cb: () => void) => {
77
+ listeners.add(cb);
78
+
79
+ // If element already found, no observer needed
80
+ if (current) return () => listeners.delete(cb);
81
+
82
+ // Watch for late-arriving slots
83
+ const observer = new MutationObserver(() => {
84
+ const found = document.querySelector(selector);
85
+ if (found && found !== current) {
86
+ current = found;
87
+ listeners.forEach((fn) => fn());
88
+ observer.disconnect();
89
+ }
90
+ });
91
+ observer.observe(document.body, { childList: true, subtree: true });
92
+
93
+ return () => {
94
+ listeners.delete(cb);
95
+ observer.disconnect();
96
+ };
97
+ };
98
+
99
+ const getSnapshot = () => current;
100
+
101
+ return { subscribe, getSnapshot };
102
+ }
103
+
104
+ /**
105
+ * Portal children into a host-rendered DOM element identified by CSS selector.
106
+ * If the element doesn't exist, renders nothing (or children inline if fallback=true).
107
+ */
108
+ export function HostSlot({
109
+ selector,
110
+ children,
111
+ fallback = false,
112
+ }: HostSlotProps): ReactElement | null {
113
+ const store = useMemo(() => createSlotStore(selector), [selector]);
114
+
115
+ const target = useSyncExternalStore(store.subscribe, store.getSnapshot);
116
+
117
+ if (target) {
118
+ return createPortal(children, target);
119
+ }
120
+
121
+ if (fallback) {
122
+ return <>{children}</>;
123
+ }
124
+
125
+ return null;
126
+ }