@middag-io/react 0.45.0 → 0.45.3

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 (321) hide show
  1. package/README.md +4 -3
  2. package/docs/public/schemas/ai-contract-manifest.json +1820 -0
  3. package/docs/public/schemas/blocks.json +445 -0
  4. package/docs/public/schemas/components.json +166 -0
  5. package/docs/public/schemas/connectors.json +97 -0
  6. package/docs/public/schemas/fragment.json +2329 -0
  7. package/docs/public/schemas/manifest.json +119 -0
  8. package/docs/public/schemas/navigation.json +72 -0
  9. package/docs/public/schemas/page-contract.json +2329 -0
  10. package/docs/public/schemas/shared-props.json +118 -0
  11. package/docs/public/schemas/theme-defaults.json +253 -0
  12. package/docs/public/schemas/theme.json +401 -0
  13. package/package.json +109 -3
  14. package/src/assets/lottie/calendar/schedule-1.json +1 -0
  15. package/src/assets/lottie/calendar/schedule-2.json +1 -0
  16. package/src/assets/lottie/celebration/confetti-1.json +1 -0
  17. package/src/assets/lottie/celebration/confetti-2.json +1 -0
  18. package/src/assets/lottie/celebration/confetti-3.json +1 -0
  19. package/src/assets/lottie/cloud/cloud-1.json +1 -0
  20. package/src/assets/lottie/cloud/cloud-2.json +1 -0
  21. package/src/assets/lottie/connection/network-1.json +1 -0
  22. package/src/assets/lottie/connection/network-2.json +1 -0
  23. package/src/assets/lottie/connection/network-3.json +1 -0
  24. package/src/assets/lottie/dashboard/analytics-1.json +1 -0
  25. package/src/assets/lottie/dashboard/analytics-2.json +1 -0
  26. package/src/assets/lottie/dashboard/analytics-3.json +1 -0
  27. package/src/assets/lottie/email/mail-1.json +1 -0
  28. package/src/assets/lottie/email/mail-2.json +1 -0
  29. package/src/assets/lottie/email/mail-3.json +1 -0
  30. package/src/assets/lottie/empty-state/empty-1.json +1 -0
  31. package/src/assets/lottie/empty-state/empty-2.json +1 -0
  32. package/src/assets/lottie/empty-state/empty-3.json +1 -0
  33. package/src/assets/lottie/error/warning-1.json +1 -0
  34. package/src/assets/lottie/error/warning-2.json +1 -0
  35. package/src/assets/lottie/error/warning-3.json +1 -0
  36. package/src/assets/lottie/index.ts +49 -0
  37. package/src/assets/lottie/loading/spinner-1.json +1 -0
  38. package/src/assets/lottie/loading/spinner-2.json +1 -0
  39. package/src/assets/lottie/loading/spinner-3.json +1 -0
  40. package/src/assets/lottie/maintenance/construction-1.json +1 -0
  41. package/src/assets/lottie/maintenance/construction-2.json +1 -0
  42. package/src/assets/lottie/maintenance/construction-3.json +1 -0
  43. package/src/assets/lottie/not-found/404-1.json +1 -0
  44. package/src/assets/lottie/not-found/404-2.json +1 -0
  45. package/src/assets/lottie/not-found/404-3.json +1 -0
  46. package/src/assets/lottie/notification/bell-1.json +1 -0
  47. package/src/assets/lottie/notification/bell-2.json +1 -0
  48. package/src/assets/lottie/notification/bell-3.json +1 -0
  49. package/src/assets/lottie/onboarding/welcome-1.json +1 -0
  50. package/src/assets/lottie/onboarding/welcome-2.json +1 -0
  51. package/src/assets/lottie/onboarding/welcome-3.json +1 -0
  52. package/src/assets/lottie/payment/wallet-1.json +1 -0
  53. package/src/assets/lottie/payment/wallet-2.json +1 -0
  54. package/src/assets/lottie/payment/wallet-3.json +1 -0
  55. package/src/assets/lottie/search/search-1.json +1 -0
  56. package/src/assets/lottie/search/search-2.json +1 -0
  57. package/src/assets/lottie/search/search-3.json +1 -0
  58. package/src/assets/lottie/security/lock-1.json +1 -0
  59. package/src/assets/lottie/security/lock-2.json +1 -0
  60. package/src/assets/lottie/security/lock-3.json +1 -0
  61. package/src/assets/lottie/settings/gear-1.json +1 -0
  62. package/src/assets/lottie/settings/gear-2.json +1 -0
  63. package/src/assets/lottie/settings/gear-3.json +1 -0
  64. package/src/assets/lottie/success/check-1.json +1 -0
  65. package/src/assets/lottie/success/check-2.json +1 -0
  66. package/src/assets/lottie/success/check-3.json +1 -0
  67. package/src/assets/lottie/upload/upload-1.json +1 -0
  68. package/src/assets/lottie/upload/upload-2.json +1 -0
  69. package/src/assets/lottie/upload/upload-3.json +1 -0
  70. package/src/assets/lottie/user/profile-1.json +1 -0
  71. package/src/assets/lottie/user/profile-2.json +1 -0
  72. package/src/assets/lottie/user/profile-3.json +1 -0
  73. package/src/base/blocks/ActionGridBlock.tsx +151 -0
  74. package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
  75. package/src/base/blocks/CardGridBlock.tsx +384 -0
  76. package/src/base/blocks/ChartBlock.tsx +81 -0
  77. package/src/base/blocks/DenseTableBlock.tsx +403 -0
  78. package/src/base/blocks/DetailPanelBlock.tsx +189 -0
  79. package/src/base/blocks/EmptyStateBlock.tsx +46 -0
  80. package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
  81. package/src/base/blocks/FormPanelBlock.tsx +480 -0
  82. package/src/base/blocks/LinkListBlock.tsx +94 -0
  83. package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
  84. package/src/base/blocks/MetricCardBlock.tsx +128 -0
  85. package/src/base/blocks/StatusStripBlock.tsx +43 -0
  86. package/src/base/blocks/TabsBlock.tsx +94 -0
  87. package/src/base/form/FormField.tsx +607 -0
  88. package/src/base/form/fields/CheckboxField.tsx +56 -0
  89. package/src/base/form/fields/ColorField.tsx +76 -0
  90. package/src/base/form/fields/CurrencyField.tsx +126 -0
  91. package/src/base/form/fields/DateField.tsx +168 -0
  92. package/src/base/form/fields/DateRangeField.tsx +66 -0
  93. package/src/base/form/fields/DocumentField.tsx +222 -0
  94. package/src/base/form/fields/EntityPickerField.tsx +244 -0
  95. package/src/base/form/fields/FileUploadField.tsx +253 -0
  96. package/src/base/form/fields/MultiSelectField.tsx +286 -0
  97. package/src/base/form/fields/NativeSelectField.tsx +67 -0
  98. package/src/base/form/fields/NumberField.tsx +67 -0
  99. package/src/base/form/fields/OtpField.tsx +88 -0
  100. package/src/base/form/fields/PasswordField.tsx +69 -0
  101. package/src/base/form/fields/PhoneField.tsx +64 -0
  102. package/src/base/form/fields/RadioField.tsx +66 -0
  103. package/src/base/form/fields/RatingField.tsx +52 -0
  104. package/src/base/form/fields/SelectField.tsx +76 -0
  105. package/src/base/form/fields/SliderField.tsx +77 -0
  106. package/src/base/form/fields/SlugField.tsx +114 -0
  107. package/src/base/form/fields/StaticField.tsx +25 -0
  108. package/src/base/form/fields/SwitchField.tsx +56 -0
  109. package/src/base/form/fields/TagsField.tsx +128 -0
  110. package/src/base/form/fields/TextField.tsx +55 -0
  111. package/src/base/form/fields/TextareaField.tsx +55 -0
  112. package/src/base/form/fields/document-validation.ts +126 -0
  113. package/src/base/form/fields/field-registry.ts +53 -0
  114. package/src/base/form/fields/register-default-fields.ts +86 -0
  115. package/src/base/form/form-schema-builder.ts +192 -0
  116. package/src/base/form/form-utils.ts +71 -0
  117. package/src/base/hooks/useIsDark.ts +50 -0
  118. package/src/base/hooks/useLazyTabs.ts +98 -0
  119. package/src/base/hooks/usePolling.ts +43 -0
  120. package/src/base/hooks/useRemember.ts +58 -0
  121. package/src/base/hooks/useToast.ts +27 -0
  122. package/src/base/layout/BlockRegion.tsx +39 -0
  123. package/src/base/layout/DashboardLayout.tsx +110 -0
  124. package/src/base/layout/SidebarLayout.tsx +38 -0
  125. package/src/base/layout/StackLayout.tsx +32 -0
  126. package/src/base/layout/WizardLayout.tsx +49 -0
  127. package/src/base/partials/ActionBar/index.tsx +115 -0
  128. package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
  129. package/src/base/partials/DataTable/cell-registry.ts +50 -0
  130. package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
  131. package/src/base/partials/DataTable/index.tsx +1282 -0
  132. package/src/base/partials/DataTable/register-default-cells.ts +37 -0
  133. package/src/base/partials/DataTable/sanitize-html.ts +45 -0
  134. package/src/base/partials/DataTable/types.ts +229 -0
  135. package/src/base/partials/DetailSection/index.tsx +316 -0
  136. package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
  137. package/src/base/partials/EntityItem/index.tsx +154 -0
  138. package/src/base/partials/FilterBar/index.tsx +256 -0
  139. package/src/base/partials/FormSection/index.tsx +87 -0
  140. package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
  141. package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
  142. package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
  143. package/src/base/partials/LogViewer/index.tsx +110 -0
  144. package/src/base/partials/LogViewer/types.ts +28 -0
  145. package/src/base/partials/MarkdownContent/index.tsx +307 -0
  146. package/src/base/partials/MenuBar/index.tsx +80 -0
  147. package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
  148. package/src/base/partials/ResizableSidebar/index.tsx +70 -0
  149. package/src/base/partials/StatRow/index.tsx +28 -0
  150. package/src/base/partials/StatusBar/index.tsx +126 -0
  151. package/src/base/partials/StatusIndicator/index.tsx +61 -0
  152. package/src/base/partials/StepIndicator/index.tsx +63 -0
  153. package/src/base/partials/TableOfContents/index.tsx +78 -0
  154. package/src/base/partials/TimelineList/index.tsx +273 -0
  155. package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
  156. package/src/base/partials/TreeView/index.tsx +75 -0
  157. package/src/base/partials/index.ts +23 -0
  158. package/src/base/shell/AuthShell.tsx +54 -0
  159. package/src/base/shell/BasicShell.tsx +286 -0
  160. package/src/base/shell/ImmersiveShell.tsx +85 -0
  161. package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
  162. package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
  163. package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
  164. package/src/base/shell/partials/InspectorContext.tsx +173 -0
  165. package/src/base/shell/partials/InspectorPanel.tsx +65 -0
  166. package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
  167. package/src/base/shell/partials/OverlayScreen.tsx +67 -0
  168. package/src/base/shell/partials/PageActionButton.tsx +203 -0
  169. package/src/base/theme/appearance.ts +133 -0
  170. package/src/base/theme/host-layout-detector.ts +119 -0
  171. package/src/base/theme/host-theme-detector.ts +146 -0
  172. package/src/base/theme/sidebar-safelist.txt +20 -0
  173. package/src/base/theme/tailwind-theme.css +136 -0
  174. package/src/base/theme/theme-bridge.css +164 -0
  175. package/src/base/theme/theme-context.tsx +142 -0
  176. package/src/base/theme/themes/classic.css +174 -0
  177. package/src/base/theme/tokens.css +290 -0
  178. package/src/base/theme/useHostTheme.ts +95 -0
  179. package/src/base/utils/clipboard.ts +39 -0
  180. package/src/base/utils/conditions.ts +27 -0
  181. package/src/base/utils/icon-registry.ts +78 -0
  182. package/src/base/utils/icons.ts +31 -0
  183. package/src/base/utils/interpolate.ts +9 -0
  184. package/src/base/utils/register-default-icons.ts +163 -0
  185. package/src/base/utils/storage.ts +65 -0
  186. package/src/base/utils/time.ts +139 -0
  187. package/src/contracts/block-data/actions.ts +73 -0
  188. package/src/contracts/block-data/data-display.ts +343 -0
  189. package/src/contracts/block-data/form.ts +164 -0
  190. package/src/contracts/block-data/index.ts +15 -0
  191. package/src/contracts/block-data/interactive.ts +34 -0
  192. package/src/contracts/block-data/shared.ts +44 -0
  193. package/src/contracts/connectors.ts +60 -0
  194. package/src/contracts/generated/contract-schema.ts +1237 -0
  195. package/src/contracts/generated/contract-types.ts +675 -0
  196. package/src/contracts/generated/index.ts +15 -0
  197. package/src/contracts/navigation.ts +59 -0
  198. package/src/contracts/page-contract-schema.ts +40 -0
  199. package/src/contracts/page-contract.ts +79 -0
  200. package/src/contracts/shared-props.ts +92 -0
  201. package/src/engine/ContractPage.tsx +178 -0
  202. package/src/engine/EntityRoutes.tsx +72 -0
  203. package/src/engine/HostSlot.tsx +126 -0
  204. package/src/engine/LazyBlock.tsx +92 -0
  205. package/src/engine/bootstrap.tsx +20 -0
  206. package/src/engine/providers/auth.tsx +87 -0
  207. package/src/engine/providers/error-reporter.tsx +89 -0
  208. package/src/engine/providers/flash.tsx +44 -0
  209. package/src/engine/providers/index.ts +18 -0
  210. package/src/engine/providers/inertia-error-reporter.tsx +61 -0
  211. package/src/engine/providers/progress.tsx +56 -0
  212. package/src/engine/providers/scope.tsx +51 -0
  213. package/src/engine/register-defaults.ts +88 -0
  214. package/src/engine/registries.ts +96 -0
  215. package/src/i18n/I18nProvider.tsx +53 -0
  216. package/src/i18n/MANIFEST.md +101 -0
  217. package/src/i18n/host-resolver.ts +18 -0
  218. package/src/i18n/instance.ts +69 -0
  219. package/src/i18n/locales/en/ui.json +277 -0
  220. package/src/i18n/locales/en/validators.json +13 -0
  221. package/src/i18n/locales/pt-BR/ui.json +277 -0
  222. package/src/i18n/locales/pt-BR/validators.json +13 -0
  223. package/src/i18n/register-strings.ts +10 -0
  224. package/src/i18n/render-label.ts +33 -0
  225. package/src/i18n/resolve-field-error.ts +29 -0
  226. package/src/i18n/useHostString.ts +50 -0
  227. package/src/i18n/useTranslation.ts +83 -0
  228. package/src/lib/actions/resolve-action-target.ts +151 -0
  229. package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
  230. package/src/lib/hooks/use-file-upload.ts +406 -0
  231. package/src/lib/hooks/use-mobile.ts +21 -0
  232. package/src/lib/host-pending.ts +76 -0
  233. package/src/lib/portal-container.ts +16 -0
  234. package/src/lib/test-ids.ts +40 -0
  235. package/src/lib/utils.ts +6 -0
  236. package/src/primitives/reui/MANIFEST.md +97 -0
  237. package/src/primitives/reui/accordion.tsx +64 -0
  238. package/src/primitives/reui/alert-dialog.tsx +196 -0
  239. package/src/primitives/reui/alert.tsx +92 -0
  240. package/src/primitives/reui/aspect-ratio.tsx +9 -0
  241. package/src/primitives/reui/autocomplete.tsx +343 -0
  242. package/src/primitives/reui/avatar.tsx +109 -0
  243. package/src/primitives/reui/badge.tsx +94 -0
  244. package/src/primitives/reui/breadcrumb.tsx +109 -0
  245. package/src/primitives/reui/button-group.tsx +83 -0
  246. package/src/primitives/reui/button.tsx +64 -0
  247. package/src/primitives/reui/calendar.tsx +220 -0
  248. package/src/primitives/reui/card.tsx +92 -0
  249. package/src/primitives/reui/carousel.tsx +239 -0
  250. package/src/primitives/reui/chart.tsx +388 -0
  251. package/src/primitives/reui/checkbox.tsx +30 -0
  252. package/src/primitives/reui/collapsible.tsx +31 -0
  253. package/src/primitives/reui/combobox.tsx +308 -0
  254. package/src/primitives/reui/command.tsx +182 -0
  255. package/src/primitives/reui/context-menu.tsx +250 -0
  256. package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
  257. package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
  258. package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
  259. package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
  260. package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
  261. package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
  262. package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
  263. package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
  264. package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
  265. package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
  266. package/src/primitives/reui/data-grid-pagination.tsx +235 -0
  267. package/src/primitives/reui/date-selector.tsx +1353 -0
  268. package/src/primitives/reui/dialog.tsx +158 -0
  269. package/src/primitives/reui/drawer.tsx +133 -0
  270. package/src/primitives/reui/dropdown-menu.tsx +257 -0
  271. package/src/primitives/reui/empty.tsx +104 -0
  272. package/src/primitives/reui/field.tsx +246 -0
  273. package/src/primitives/reui/filters.tsx +1891 -0
  274. package/src/primitives/reui/frame.tsx +170 -0
  275. package/src/primitives/reui/hover-card.tsx +42 -0
  276. package/src/primitives/reui/icon-placeholder.tsx +39 -0
  277. package/src/primitives/reui/index.ts +98 -0
  278. package/src/primitives/reui/input-group.tsx +170 -0
  279. package/src/primitives/reui/input-otp.tsx +75 -0
  280. package/src/primitives/reui/input.tsx +21 -0
  281. package/src/primitives/reui/item.tsx +193 -0
  282. package/src/primitives/reui/kanban.tsx +743 -0
  283. package/src/primitives/reui/kbd.tsx +28 -0
  284. package/src/primitives/reui/label.tsx +22 -0
  285. package/src/primitives/reui/menubar.tsx +274 -0
  286. package/src/primitives/reui/native-select.tsx +62 -0
  287. package/src/primitives/reui/navigation-menu.tsx +168 -0
  288. package/src/primitives/reui/number-field.tsx +250 -0
  289. package/src/primitives/reui/pagination.tsx +127 -0
  290. package/src/primitives/reui/phone-input.tsx +231 -0
  291. package/src/primitives/reui/popover.tsx +87 -0
  292. package/src/primitives/reui/progress.tsx +31 -0
  293. package/src/primitives/reui/radio-group.tsx +43 -0
  294. package/src/primitives/reui/rating.tsx +177 -0
  295. package/src/primitives/reui/resizable.tsx +51 -0
  296. package/src/primitives/reui/scroll-area.tsx +58 -0
  297. package/src/primitives/reui/scrollspy.tsx +240 -0
  298. package/src/primitives/reui/select.tsx +188 -0
  299. package/src/primitives/reui/separator.tsx +28 -0
  300. package/src/primitives/reui/sheet.tsx +141 -0
  301. package/src/primitives/reui/sidebar.tsx +732 -0
  302. package/src/primitives/reui/skeleton.tsx +13 -0
  303. package/src/primitives/reui/slider.tsx +61 -0
  304. package/src/primitives/reui/sonner.tsx +47 -0
  305. package/src/primitives/reui/sortable.tsx +414 -0
  306. package/src/primitives/reui/spinner.tsx +16 -0
  307. package/src/primitives/reui/stepper.tsx +484 -0
  308. package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
  309. package/src/primitives/reui/svgs/gemini.tsx +171 -0
  310. package/src/primitives/reui/svgs/openai.tsx +9 -0
  311. package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
  312. package/src/primitives/reui/switch.tsx +33 -0
  313. package/src/primitives/reui/table.tsx +114 -0
  314. package/src/primitives/reui/tabs.tsx +91 -0
  315. package/src/primitives/reui/textarea.tsx +18 -0
  316. package/src/primitives/reui/timeline.tsx +219 -0
  317. package/src/primitives/reui/toggle-group.tsx +83 -0
  318. package/src/primitives/reui/toggle.tsx +45 -0
  319. package/src/primitives/reui/tooltip.tsx +55 -0
  320. package/src/primitives/reui/tree.tsx +247 -0
  321. package/src/theme.css +71 -0
@@ -0,0 +1,203 @@
1
+ /**
2
+ * PageActionButton — handles navigation, API calls, loading, and confirmation.
3
+ *
4
+ * Replaces inline ActionButton in PageHeader with full v2 support:
5
+ * - GET → Link navigation (existing)
6
+ * - POST/PUT/PATCH/DELETE → Inertia in-place with preserveState
7
+ * - confirmation → ConfirmationDialog before executing
8
+ * - loading state while request in-flight
9
+ *
10
+ * Navigation/request is resolved through `resolveActionTarget` (Phase-0 adapter seam)
11
+ * so the later flip from flat `href`/`method` to the canonical `target` is a no-op
12
+ * here; labels render through `renderLabel` for the same reason.
13
+ *
14
+ * @see Page Builder v2 spec §Gap 6
15
+ */
16
+
17
+ import { useCallback, useState, type ReactElement } from "react";
18
+ import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react";
19
+ import { router } from "@inertiajs/core";
20
+ import { Link } from "@inertiajs/react";
21
+
22
+ import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
23
+ import { getIcon, hasIcon } from "@/base/utils/icons";
24
+ import type { PageAction } from "@/contracts/page-contract";
25
+ import { renderLabel } from "@/i18n/render-label";
26
+ import { useTranslation } from "@/i18n/useTranslation";
27
+ import { resolveActionTarget } from "@/lib/actions/resolve-action-target";
28
+ import { actionTestId } from "@/lib/test-ids";
29
+ import { Button } from "@/primitives/reui/button";
30
+
31
+ type ButtonVariant = "default" | "outline" | "destructive" | "ghost" | "secondary" | "link";
32
+
33
+ const VARIANT_MAP: Record<string, ButtonVariant> = {
34
+ primary: "default",
35
+ secondary: "outline",
36
+ danger: "destructive",
37
+ ghost: "ghost",
38
+ };
39
+
40
+ export function PageActionButton({ action }: { action: PageAction }): ReactElement {
41
+ const { t } = useTranslation();
42
+ const [isLoading, setIsLoading] = useState(false);
43
+ const [showConfirm, setShowConfirm] = useState(false);
44
+ const [isWaiting, setIsWaiting] = useState(false);
45
+
46
+ const target = resolveActionTarget(action);
47
+ const variant: ButtonVariant = VARIANT_MAP[action.intent] ?? "outline";
48
+ const isNavigation = target.kind === "link";
49
+ // External loading (server-driven via action.loading) merges with local in-flight state
50
+ const effectiveLoading = isLoading || action.loading === true;
51
+
52
+ const executeAction = useCallback(() => {
53
+ if (!target.url) return;
54
+
55
+ if (isNavigation) {
56
+ router.visit(target.url);
57
+ return;
58
+ }
59
+
60
+ setIsLoading(true);
61
+
62
+ const options = {
63
+ preserveState: true,
64
+ preserveScroll: true,
65
+ onFinish: () => {
66
+ if (!action.confirmation?.waitForPolling) {
67
+ setIsLoading(false);
68
+ }
69
+ },
70
+ };
71
+ if (target.method === "delete") {
72
+ // router.delete signature is (url, options) — no data arg.
73
+ router.delete(target.url, options);
74
+ } else {
75
+ const method = target.method as "post" | "put" | "patch";
76
+ router[method](target.url, {} as never, options);
77
+ }
78
+
79
+ if (action.confirmation?.waitForPolling) {
80
+ setIsWaiting(true);
81
+ }
82
+ }, [action, target, isNavigation]);
83
+
84
+ const confirmation = action.confirmation;
85
+
86
+ const handleClick = useCallback(() => {
87
+ if (confirmation) {
88
+ setShowConfirm(true);
89
+ } else {
90
+ executeAction();
91
+ }
92
+ }, [confirmation, executeAction]);
93
+
94
+ const handleConfirm = useCallback(() => {
95
+ // Execute FIRST, then close — avoids onOpenChange race condition
96
+ executeAction();
97
+ if (!action.confirmation?.waitForPolling) {
98
+ setShowConfirm(false);
99
+ }
100
+ }, [action, executeAction]);
101
+
102
+ const handleCloseConfirm = useCallback(() => {
103
+ setShowConfirm(false);
104
+ setIsWaiting(false);
105
+ // Only reset loading if no request is in-flight
106
+ if (!isLoading) {
107
+ setIsLoading(false);
108
+ }
109
+ }, [isLoading]);
110
+
111
+ const label = renderLabel(action.label, t);
112
+
113
+ /**
114
+ * The action's icon, when it names one the registry knows.
115
+ *
116
+ * `Action.icon` has always been part of the contract and this button ignored
117
+ * it, so every page action and every tab-strip action rendered label-only
118
+ * while the contract said otherwise. `hasIcon` gates the lookup because
119
+ * `getIcon` answers an unregistered name with a generic inbox glyph — drawing
120
+ * the wrong picture confidently is worse than drawing none.
121
+ */
122
+ const icon =
123
+ action.icon && hasIcon(action.icon) ? (
124
+ <HugeiconsIcon
125
+ icon={getIcon(action.icon) as unknown as IconSvgElement}
126
+ className="size-3.5"
127
+ />
128
+ ) : null;
129
+
130
+ // Simple navigation link (GET, no confirmation). A disabled action never renders
131
+ // as an anchor: an <a> keeps its href and ignores `disabled`, so it would stay
132
+ // navigable and look enabled. It falls through to the locked <button> below.
133
+ if (isNavigation && target.url && !confirmation && !action.loading && !action.disabled) {
134
+ return (
135
+ <Button data-testid={actionTestId(action.id)} variant={variant} size="sm" asChild>
136
+ <Link href={target.url}>
137
+ {icon}
138
+ {label}
139
+ </Link>
140
+ </Button>
141
+ );
142
+ }
143
+
144
+ return (
145
+ <>
146
+ <Button
147
+ data-testid={actionTestId(action.id)}
148
+ variant={variant}
149
+ size="sm"
150
+ onClick={handleClick}
151
+ data-locked={action.disabled ? "true" : undefined}
152
+ disabled={action.disabled || effectiveLoading}
153
+ aria-disabled={action.disabled || effectiveLoading}
154
+ >
155
+ {!effectiveLoading && icon}
156
+ {effectiveLoading && (
157
+ <svg
158
+ className="mr-2 size-3.5 animate-spin"
159
+ xmlns="http://www.w3.org/2000/svg"
160
+ fill="none"
161
+ viewBox="0 0 24 24"
162
+ >
163
+ <circle
164
+ className="opacity-25"
165
+ cx="12"
166
+ cy="12"
167
+ r="10"
168
+ stroke="currentColor"
169
+ strokeWidth="4"
170
+ />
171
+ <path
172
+ className="opacity-75"
173
+ fill="currentColor"
174
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
175
+ />
176
+ </svg>
177
+ )}
178
+ {label}
179
+ </Button>
180
+
181
+ {confirmation && (
182
+ <ConfirmationDialog
183
+ open={showConfirm}
184
+ onClose={handleCloseConfirm}
185
+ onConfirm={handleConfirm}
186
+ title={renderLabel(confirmation.title, t)}
187
+ message={renderLabel(confirmation.message, t)}
188
+ intent={confirmation.intent}
189
+ confirmLabel={
190
+ confirmation.confirmLabel ? renderLabel(confirmation.confirmLabel, t) : undefined
191
+ }
192
+ cancelLabel={
193
+ confirmation.cancelLabel ? renderLabel(confirmation.cancelLabel, t) : undefined
194
+ }
195
+ waiting={isWaiting}
196
+ waitingMessage={
197
+ confirmation.waitingMessage ? renderLabel(confirmation.waitingMessage, t) : undefined
198
+ }
199
+ />
200
+ )}
201
+ </>
202
+ );
203
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * appearance — dark mode system with host detection + manual override.
3
+ *
4
+ * Three-tier resolution:
5
+ * 1. Manual override (user clicked toggle) → 'light' or 'dark'
6
+ * 2. 'system' → detectHostTheme() (Moodle/WP classes, attrs, localStorage)
7
+ * 3. 'system' + no host signal → OS prefers-color-scheme
8
+ *
9
+ * Applies theme via:
10
+ * - `data-theme="dark|light"` on all `.middag-root` elements
11
+ * - `class="dark"` on `<html>` (for Tailwind dark: prefix compatibility)
12
+ *
13
+ * Never modifies host page's own classes/attributes (except <html>.dark which
14
+ * is MIDDAG's own — the host doesn't use Tailwind dark: prefix).
15
+ *
16
+ * @see host-theme-detector.ts — read-only host detection
17
+ * @see useHostTheme.ts — React hook with live observation
18
+ */
19
+
20
+ import { detectHostTheme, type DetectedTheme } from "@/base/theme/host-theme-detector";
21
+ import { getStorageItem, setStorageItem } from "@/base/utils/storage";
22
+
23
+ export type Appearance = "system" | "light" | "dark";
24
+
25
+ export type EffectiveTheme = "light" | "dark";
26
+
27
+ /**
28
+ * Resolve the effective theme from a preference.
29
+ * 'system' consults host page first, then OS.
30
+ */
31
+ export function getEffectiveTheme(preference: Appearance): EffectiveTheme {
32
+ if (preference !== "system") return preference;
33
+
34
+ const hostTheme: DetectedTheme = detectHostTheme();
35
+ if (hostTheme === "dark") return "dark";
36
+ if (hostTheme === "light") return "light";
37
+
38
+ // Host returned 'auto' — fall back to OS
39
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
40
+ }
41
+
42
+ /**
43
+ * Read stored preference from localStorage.
44
+ */
45
+ export function getStoredAppearance(): Appearance {
46
+ const stored = getStorageItem("appearance");
47
+ if (stored === "light" || stored === "dark" || stored === "system") {
48
+ return stored;
49
+ }
50
+ return "system";
51
+ }
52
+
53
+ /**
54
+ * Apply resolved theme to DOM.
55
+ * Sets data-theme on all .middag-root elements + class dark on <html> for Tailwind.
56
+ *
57
+ * Also syncs `color-scheme` on <html> so native form controls (text inputs,
58
+ * textareas, native selects, date/number pickers, autofill, scrollbars) render
59
+ * in the matching UA scheme. Without this, switching to dark leaves native
60
+ * widgets in the OS/UA light scheme — light foreground text on a light native
61
+ * background reads as invisible inside forms.
62
+ */
63
+ export function applyTheme(theme: EffectiveTheme): void {
64
+ document.documentElement.classList.toggle("dark", theme === "dark");
65
+ document.documentElement.style.colorScheme = theme;
66
+
67
+ const roots = document.querySelectorAll(".middag-root");
68
+ roots.forEach((el) => {
69
+ el.setAttribute("data-theme", theme);
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Apply appearance: persist preference, toggle dark class, set data-theme on MIDDAG roots.
75
+ */
76
+ export function setAppearance(preference: Appearance): void {
77
+ setStorageItem("appearance", preference);
78
+ const theme = getEffectiveTheme(preference);
79
+ applyTheme(theme);
80
+ }
81
+
82
+ /**
83
+ * Cycle through modes: System → Light → Dark → System.
84
+ */
85
+ export function cycleAppearance(): Appearance {
86
+ const current = getStoredAppearance();
87
+ const next: Appearance = current === "system" ? "light" : current === "light" ? "dark" : "system";
88
+ setAppearance(next);
89
+ return next;
90
+ }
91
+
92
+ /**
93
+ * Toggle document direction between LTR and RTL.
94
+ * Persists choice in localStorage.
95
+ */
96
+ export function toggleDir(): "ltr" | "rtl" {
97
+ const root = document.documentElement;
98
+ const current = root.dir || "ltr";
99
+ const next = current === "ltr" ? "rtl" : "ltr";
100
+ root.dir = next;
101
+ setStorageItem("dir", next);
102
+ return next;
103
+ }
104
+
105
+ /**
106
+ * Restore persisted direction on load.
107
+ */
108
+ export function initDir(): void {
109
+ const stored = getStorageItem("dir");
110
+ if (stored === "rtl") {
111
+ document.documentElement.dir = "rtl";
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Listen for OS theme changes.
117
+ * Only reacts when preference is 'system'.
118
+ * Returns a cleanup function.
119
+ */
120
+ export function onSystemThemeChange(callback?: () => void): () => void {
121
+ const mql = window.matchMedia("(prefers-color-scheme: dark)");
122
+
123
+ const handler = (): void => {
124
+ if (getStoredAppearance() === "system") {
125
+ const theme = getEffectiveTheme("system");
126
+ applyTheme(theme);
127
+ callback?.();
128
+ }
129
+ };
130
+
131
+ mql.addEventListener("change", handler);
132
+ return () => mql.removeEventListener("change", handler);
133
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Host layout detector -- measures the host platform's header height
3
+ * and sets --host-header-height on :root.
4
+ *
5
+ * The sidebar primitive reads var(--host-header-height, 0px) for
6
+ * top offset and height. Without this, the sidebar starts at viewport top.
7
+ *
8
+ * Detection is read-only -- never modifies the host's DOM.
9
+ * Re-measures on window resize and DOM mutations (admin notices, etc.).
10
+ *
11
+ * Known host headers:
12
+ * - Moodle Boost: nav.navbar, [data-region="navbar"]
13
+ * - WordPress: #wpadminbar
14
+ * - Generic: [data-host-header], header:first-child
15
+ */
16
+
17
+ const HOST_HEADER_SELECTORS = [
18
+ // WordPress admin bar
19
+ "#wpadminbar",
20
+ // Moodle Boost navbar
21
+ "nav.navbar",
22
+ '[data-region="navbar"]',
23
+ // Explicit opt-in from any host
24
+ "[data-host-header]",
25
+ ] as const;
26
+
27
+ let _observer: MutationObserver | null = null;
28
+ let _resizeHandler: (() => void) | null = null;
29
+
30
+ /**
31
+ * Measure the host header height by finding the first matching element.
32
+ * Returns the offsetHeight or 0 if no host header is found.
33
+ */
34
+ function measureHostHeaderHeight(): number {
35
+ if (typeof document === "undefined") return 0;
36
+
37
+ for (const selector of HOST_HEADER_SELECTORS) {
38
+ const el = document.querySelector<HTMLElement>(selector);
39
+ if (el) {
40
+ // getBoundingClientRect is more accurate for fixed/sticky elements
41
+ const rect = el.getBoundingClientRect();
42
+ return Math.round(rect.height);
43
+ }
44
+ }
45
+
46
+ return 0;
47
+ }
48
+
49
+ /**
50
+ * Apply --host-header-height to :root.
51
+ * Only writes if the value changed (avoids layout thrashing).
52
+ */
53
+ function applyHostHeaderHeight(): void {
54
+ const height = measureHostHeaderHeight();
55
+ const current = document.documentElement.style.getPropertyValue("--host-header-height");
56
+ const next = `${height}px`;
57
+
58
+ if (current !== next) {
59
+ document.documentElement.style.setProperty("--host-header-height", next);
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Initialize host header height detection.
65
+ *
66
+ * Call once from your production entry point (or from ProductShell mount).
67
+ * Sets --host-header-height immediately, then observes resize + DOM mutations.
68
+ *
69
+ * Safe to call in dev/mock (returns 0 if no host header is found).
70
+ * Idempotent (calling multiple times does not stack observers).
71
+ */
72
+ export function initHostHeaderHeight(): void {
73
+ if (typeof document === "undefined") return;
74
+
75
+ // Initial measurement
76
+ applyHostHeaderHeight();
77
+
78
+ // Observe resize (responsive breakpoints change header height)
79
+ if (!_resizeHandler) {
80
+ _resizeHandler = () => applyHostHeaderHeight();
81
+ window.addEventListener("resize", _resizeHandler, { passive: true });
82
+ }
83
+
84
+ // Observe DOM mutations on <body> (admin notices, dynamic banners)
85
+ if (!_observer) {
86
+ _observer = new MutationObserver(() => {
87
+ // Debounce with requestAnimationFrame
88
+ requestAnimationFrame(() => applyHostHeaderHeight());
89
+ });
90
+ _observer.observe(document.body, {
91
+ childList: true,
92
+ subtree: false,
93
+ attributes: false,
94
+ });
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Set --host-header-height to a fixed value (for mock/dev).
100
+ * Bypasses auto-detection. Call initHostHeaderHeight() to resume auto mode.
101
+ */
102
+ export function setHostHeaderHeight(px: number): void {
103
+ if (typeof document === "undefined") return;
104
+ document.documentElement.style.setProperty("--host-header-height", `${px}px`);
105
+ }
106
+
107
+ /**
108
+ * Clean up observers (for testing or unmount).
109
+ */
110
+ export function destroyHostHeaderHeight(): void {
111
+ if (_resizeHandler) {
112
+ window.removeEventListener("resize", _resizeHandler);
113
+ _resizeHandler = null;
114
+ }
115
+ if (_observer) {
116
+ _observer.disconnect();
117
+ _observer = null;
118
+ }
119
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Host theme detector — detects dark/light mode from the host page (Moodle, WordPress, etc.)
3
+ *
4
+ * Designed to be defensive: each host CMS/theme may implement dark mode differently.
5
+ * Detection is read-only — never modifies the host's DOM, classes, or localStorage.
6
+ *
7
+ * Priority order:
8
+ * 1. Class/attribute on <html> and <body>
9
+ * 2. Known localStorage keys (scan, not assume)
10
+ * 3. prefers-color-scheme media query (OS fallback)
11
+ *
12
+ * @see ADR-807 — CSS isolation via .middag-root
13
+ */
14
+
15
+ export type DetectedTheme = "dark" | "light" | "auto";
16
+
17
+ // ── Class/attribute patterns ────────────────────────────────────────────────
18
+
19
+ /** CSS classes that indicate dark mode on <html> or <body> */
20
+ const DARK_CLASS_PATTERNS = [
21
+ "dark",
22
+ "theme-dark",
23
+ "dark-mode",
24
+ "darkmode",
25
+ "is-dark",
26
+ "night",
27
+ "bp-dark", // Boost Plus
28
+ ] as const;
29
+
30
+ /** data-* attributes checked on <html> and <body> */
31
+ const DARK_ATTRIBUTE_CHECKS: { attr: string; value: string }[] = [
32
+ { attr: "data-theme", value: "dark" },
33
+ { attr: "data-bs-theme", value: "dark" }, // Bootstrap 5.3+
34
+ { attr: "data-color-scheme", value: "dark" },
35
+ { attr: "data-color-mode", value: "dark" }, // GitHub-style
36
+ { attr: "data-moodle-theme-mode", value: "dark" },
37
+ { attr: "data-wp-dark", value: "true" }, // WP dark mode plugins
38
+ ];
39
+
40
+ /** Scan element for dark mode indicators */
41
+ function elementHasDarkIndicator(el: Element): boolean {
42
+ const classes = el.classList;
43
+ for (const pattern of DARK_CLASS_PATTERNS) {
44
+ if (classes.contains(pattern)) return true;
45
+ }
46
+
47
+ for (const { attr, value } of DARK_ATTRIBUTE_CHECKS) {
48
+ if (el.getAttribute(attr) === value) return true;
49
+ }
50
+
51
+ const style = (el as HTMLElement).style;
52
+ if (style.colorScheme === "dark") return true;
53
+
54
+ return false;
55
+ }
56
+
57
+ // ── localStorage patterns ───────────────────────────────────────────────────
58
+
59
+ /**
60
+ * Known localStorage keys that CMS/theme plugins use for dark mode.
61
+ * Scanned defensively — no single key is assumed to exist.
62
+ */
63
+ const LOCALSTORAGE_DARK_INDICATORS: { key: string; darkValues: string[] }[] = [
64
+ // Moodle themes
65
+ { key: "theme-dark-mode", darkValues: ["true", "1", "dark"] },
66
+ { key: "darkmode", darkValues: ["true", "1", "dark", "enabled"] },
67
+ { key: "dark-mode", darkValues: ["true", "1", "dark"] },
68
+ { key: "moodle-theme-mode", darkValues: ["dark"] },
69
+ { key: "boost-dark-mode", darkValues: ["true", "1"] },
70
+ { key: "moove-dark-mode", darkValues: ["true", "1"] },
71
+ // WordPress
72
+ { key: "wp-dark-mode", darkValues: ["true", "1", "dark"] },
73
+ { key: "flavor", darkValues: ["dark"] },
74
+ // Generic
75
+ { key: "theme", darkValues: ["dark"] },
76
+ { key: "color-scheme", darkValues: ["dark"] },
77
+ { key: "color-mode", darkValues: ["dark"] },
78
+ ];
79
+
80
+ function localStorageIndicatesDark(): boolean | null {
81
+ try {
82
+ for (const { key, darkValues } of LOCALSTORAGE_DARK_INDICATORS) {
83
+ const stored = localStorage.getItem(key);
84
+ if (stored !== null && darkValues.includes(stored.toLowerCase())) {
85
+ return true;
86
+ }
87
+ }
88
+ } catch {
89
+ // localStorage not available
90
+ }
91
+ return null;
92
+ }
93
+
94
+ // ── OS media query ──────────────────────────────────────────────────────────
95
+
96
+ function osPrefersColorScheme(): DetectedTheme {
97
+ if (typeof window === "undefined") return "auto";
98
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) return "dark";
99
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) return "light";
100
+ return "auto";
101
+ }
102
+
103
+ // ── Main detector ───────────────────────────────────────────────────────────
104
+
105
+ /**
106
+ * Detect the host page's theme. Read-only — never modifies host DOM.
107
+ *
108
+ * Returns 'dark', 'light', or 'auto' (couldn't determine).
109
+ */
110
+ export function detectHostTheme(): DetectedTheme {
111
+ if (typeof document === "undefined") return "auto";
112
+
113
+ // 1. Check <html> and <body> for class/attribute indicators
114
+ if (elementHasDarkIndicator(document.documentElement) || elementHasDarkIndicator(document.body)) {
115
+ return "dark";
116
+ }
117
+
118
+ // Check for explicit light indicators
119
+ if (
120
+ document.documentElement.getAttribute("data-theme") === "light" ||
121
+ document.documentElement.getAttribute("data-bs-theme") === "light" ||
122
+ document.body.getAttribute("data-theme") === "light"
123
+ ) {
124
+ return "light";
125
+ }
126
+
127
+ // 2. Check localStorage patterns
128
+ const lsResult = localStorageIndicatesDark();
129
+ if (lsResult === true) return "dark";
130
+
131
+ // 3. Fall back to OS preference
132
+ return osPrefersColorScheme();
133
+ }
134
+
135
+ // ── Attributes to observe for MutationObserver ──────────────────────────────
136
+
137
+ export const OBSERVED_ATTRIBUTES = [
138
+ "class",
139
+ "data-theme",
140
+ "data-bs-theme",
141
+ "data-color-scheme",
142
+ "data-color-mode",
143
+ "data-moodle-theme-mode",
144
+ "data-wp-dark",
145
+ "style",
146
+ ];
@@ -0,0 +1,20 @@
1
+ w-(--sidebar-width)
2
+ w-(--sidebar-width-icon)
3
+ w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]
4
+ w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]
5
+ group-data-[collapsible=icon]:w-(--sidebar-width-icon)
6
+ group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]
7
+ group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]
8
+ group-data-[collapsible=icon]:hidden
9
+ group-data-[collapsible=icon]:overflow-hidden
10
+ group-data-[collapsible=icon]:p-0!
11
+ group-data-[collapsible=icon]:size-8!
12
+ group-data-[collapsible=icon]:p-2!
13
+ group-data-[collapsible=icon]:-mt-8
14
+ group-data-[collapsible=icon]:opacity-0
15
+ group-data-[collapsible=offcanvas]:w-0
16
+ group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]
17
+ group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]
18
+ group-data-[collapsible=offcanvas]:bg-sidebar
19
+ group-data-[collapsible=offcanvas]:translate-x-0
20
+ group-data-[collapsible=offcanvas]:after:left-full