@rapidmx/web-client 0.15.1 → 0.17.0

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 (318) hide show
  1. package/README.md +381 -373
  2. package/apps/admin/branding/index.tsx +39 -39
  3. package/apps/admin/data-requests/index.tsx +482 -480
  4. package/apps/admin/distribution-lists/new/index.tsx +3 -1
  5. package/apps/admin/domains/[uid].tsx +166 -164
  6. package/apps/admin/domains/new/index.tsx +3 -1
  7. package/apps/admin/escrow-scopes/[uid].tsx +350 -348
  8. package/apps/admin/escrow-scopes/new/index.tsx +3 -1
  9. package/apps/admin/index.tsx +129 -124
  10. package/apps/admin/mailboxes/[uid].tsx +271 -224
  11. package/apps/admin/mailboxes/new/index.tsx +30 -28
  12. package/apps/admin/plugins/index.tsx +15 -15
  13. package/apps/admin/retention-policy/index.tsx +39 -39
  14. package/apps/admin/signing-certificates/index.tsx +343 -343
  15. package/apps/admin/transport-rules/new/index.tsx +3 -1
  16. package/apps/escrow/audit-log/index.tsx +196 -196
  17. package/apps/escrow/matters/[uid].tsx +621 -621
  18. package/apps/escrow/matters/new/index.tsx +3 -1
  19. package/apps/shared/auth/adminAccess.ts +99 -99
  20. package/apps/shared/components/admin/layout/AdminShell.tsx +381 -378
  21. package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -0
  22. package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
  23. package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -0
  24. package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
  25. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
  26. package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +50 -3
  27. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
  28. package/apps/shared/components/admin/settings/PluginsManager.tsx +1545 -1545
  29. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
  30. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
  31. package/apps/shared/components/admin/setup/SetupWizard.tsx +446 -444
  32. package/apps/shared/components/admin/usePagedList.tsx +129 -129
  33. package/apps/shared/components/calendar/EventEditor.tsx +5 -10
  34. package/apps/shared/components/calendar/EventFormParts.tsx +16 -47
  35. package/apps/shared/components/calendar/EventModal.tsx +206 -206
  36. package/apps/shared/components/calendar/GuestInput.tsx +100 -0
  37. package/apps/shared/components/calendar/MonthView.tsx +185 -185
  38. package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
  39. package/apps/shared/components/calendar/RequestChangeForm.tsx +23 -54
  40. package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
  41. package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
  42. package/apps/shared/components/calendar/allDay.ts +124 -124
  43. package/apps/shared/components/calendar/eventForm.ts +2 -2
  44. package/apps/shared/components/calendar/eventFormat.ts +49 -22
  45. package/apps/shared/components/calendar/layout/CalendarShell.tsx +201 -200
  46. package/apps/shared/components/contacts/ContactForm.tsx +383 -383
  47. package/apps/shared/components/contacts/ContactsSidebar.tsx +1 -1
  48. package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -98
  49. package/apps/shared/components/contacts/layout/ContactsShell.tsx +218 -216
  50. package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
  51. package/apps/shared/components/layout/AppShell.tsx +461 -480
  52. package/apps/shared/components/layout/FloatingActionButton.tsx +31 -0
  53. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
  54. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
  55. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
  56. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
  57. package/apps/shared/components/layout/UserMenu.tsx +439 -424
  58. package/apps/shared/components/mail/ConversationList.tsx +323 -323
  59. package/apps/shared/components/mail/ConversationThreadPane.tsx +613 -491
  60. package/apps/shared/components/mail/EmptyFolderBar.tsx +41 -0
  61. package/apps/shared/components/mail/MailSelectionBar.tsx +240 -227
  62. package/apps/shared/components/mail/MenuButton.tsx +31 -11
  63. package/apps/shared/components/mail/MessageDetailPane.tsx +1757 -1559
  64. package/apps/shared/components/mail/PermanentDeleteDialog.tsx +47 -0
  65. package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
  66. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
  67. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1681 -1677
  68. package/apps/shared/components/mail/compose/RecipientInput.tsx +54 -11
  69. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
  70. package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
  71. package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
  72. package/apps/shared/components/mail/layout/FolderBadgeChip.tsx +21 -0
  73. package/apps/shared/components/mail/layout/MailShell.tsx +161 -134
  74. package/apps/shared/components/mail/layout/SidebarSection.tsx +66 -0
  75. package/apps/shared/components/mail/reading/MessageMoreMenu.tsx +258 -0
  76. package/apps/shared/components/mail/reading/MessageSourceDialog.tsx +79 -0
  77. package/apps/shared/components/mail/reading/PendingMessageCard.tsx +68 -0
  78. package/apps/shared/components/mail/reading/messageExport.ts +59 -0
  79. package/apps/shared/components/mail/reading/printMessage.ts +99 -0
  80. package/apps/shared/components/mail/reading/useMessageActions.ts +443 -0
  81. package/apps/shared/components/mail/verificationSeals.ts +125 -125
  82. package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
  83. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
  84. package/apps/shared/components/settings/layout/SettingsShell.tsx +257 -254
  85. package/apps/shared/components/tasks/TasksSidebar.tsx +1 -1
  86. package/apps/shared/components/tasks/layout/TasksShell.tsx +219 -217
  87. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
  88. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
  89. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
  90. package/apps/shared/keyboard/dispatch.ts +124 -124
  91. package/apps/shared/keyboard/format.ts +89 -89
  92. package/apps/shared/keyboard/keymap.ts +114 -114
  93. package/apps/shared/keyboard/registry.ts +65 -65
  94. package/apps/shared/keyboard/targets.ts +79 -79
  95. package/apps/shared/mail/folderCounts.ts +17 -0
  96. package/apps/shared/mail/folderOfType.ts +49 -0
  97. package/apps/shared/mail/folderTree.ts +143 -143
  98. package/apps/shared/mail/listAllPages.ts +39 -39
  99. package/apps/shared/mail/newMailNotifications.ts +171 -171
  100. package/apps/shared/mail/outbox/outgoingReplies.ts +192 -0
  101. package/apps/shared/mail/outbox/sendJob.ts +19 -1
  102. package/apps/shared/mail/outbox/sendOutcomes.ts +13 -4
  103. package/apps/shared/mail/permanentDelete.ts +160 -0
  104. package/apps/shared/mail/primaryMailbox.ts +71 -0
  105. package/apps/shared/mail/reportNotices.ts +66 -0
  106. package/apps/shared/mail/senderBlocking.ts +141 -0
  107. package/apps/shared/mail/useCollapsedSections.ts +146 -0
  108. package/apps/shared/mail/useMailConnection.ts +205 -203
  109. package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
  110. package/apps/shared/mail/useMailboxUpdateAccess.ts +60 -0
  111. package/apps/shared/mail/useMarkMessageRead.ts +47 -47
  112. package/apps/shared/mail/useNewMailNotifications.ts +178 -178
  113. package/apps/shared/mail/usePermanentDelete.tsx +160 -0
  114. package/apps/shared/navigation/frameContext.tsx +1 -1
  115. package/apps/shared/navigation/index.ts +43 -0
  116. package/apps/shared/navigation/pageTitle.ts +19 -0
  117. package/apps/shared/notifications/store.ts +560 -560
  118. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
  119. package/apps/shared/search/crossMailboxSearch.ts +169 -0
  120. package/apps/shared/search/localIndexBuilder.ts +481 -481
  121. package/apps/shared/signing/enrollmentStorage.ts +33 -33
  122. package/apps/shared/signing/enrollmentTracker.ts +385 -385
  123. package/apps/shared/signing/enrollmentView.ts +251 -251
  124. package/apps/shared/signing/useNow.ts +19 -19
  125. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
  126. package/apps/shared/styles/app.css +396 -386
  127. package/apps/www/_shell.tsx +82 -0
  128. package/apps/www/calendar/index.tsx +581 -571
  129. package/apps/www/contacts/[uid].tsx +112 -109
  130. package/apps/www/contacts/index.tsx +14 -3
  131. package/apps/www/index.tsx +2962 -2479
  132. package/apps/www/messages/[uid].tsx +139 -135
  133. package/apps/www/settings/appearance/index.tsx +5 -2
  134. package/apps/www/settings/auto-reply/index.tsx +136 -133
  135. package/apps/www/settings/blocked-senders/index.tsx +303 -0
  136. package/apps/www/settings/encryption/index.tsx +1290 -1287
  137. package/apps/www/settings/filters/[uid].tsx +179 -176
  138. package/apps/www/settings/filters/index.tsx +105 -102
  139. package/apps/www/settings/filters/new/index.tsx +165 -140
  140. package/apps/www/settings/labels/index.tsx +207 -204
  141. package/apps/www/settings/privacy/index.tsx +495 -492
  142. package/apps/www/settings/profile/index.tsx +251 -248
  143. package/apps/www/settings/read-receipts/index.tsx +150 -147
  144. package/apps/www/settings/sharing/index.tsx +259 -256
  145. package/apps/www/settings/signatures/[uid].tsx +175 -172
  146. package/apps/www/settings/signatures/index.tsx +91 -88
  147. package/apps/www/settings/signatures/new/index.tsx +138 -135
  148. package/apps/www/tasks/index.tsx +654 -649
  149. package/dist/apps/admin/data-requests/index.js +1 -1
  150. package/dist/apps/admin/distribution-lists/new/index.js +3 -1
  151. package/dist/apps/admin/domains/[uid].js +3 -1
  152. package/dist/apps/admin/domains/new/index.js +3 -1
  153. package/dist/apps/admin/escrow-scopes/[uid].js +3 -1
  154. package/dist/apps/admin/escrow-scopes/new/index.js +3 -1
  155. package/dist/apps/admin/index.js +5 -2
  156. package/dist/apps/admin/mailboxes/[uid].js +15 -3
  157. package/dist/apps/admin/mailboxes/new/index.js +3 -1
  158. package/dist/apps/admin/transport-rules/new/index.js +3 -1
  159. package/dist/apps/escrow/matters/new/index.js +3 -1
  160. package/dist/apps/shared/components/admin/layout/AdminShell.js +6 -3
  161. package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.d.ts +35 -0
  162. package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.js +115 -0
  163. package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.d.ts +16 -0
  164. package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.js +92 -0
  165. package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
  166. package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +25 -3
  167. package/dist/apps/shared/components/admin/setup/SetupWizard.js +3 -1
  168. package/dist/apps/shared/components/calendar/EventEditor.js +5 -10
  169. package/dist/apps/shared/components/calendar/EventFormParts.d.ts +3 -2
  170. package/dist/apps/shared/components/calendar/EventFormParts.js +5 -16
  171. package/dist/apps/shared/components/calendar/GuestInput.d.ts +45 -0
  172. package/dist/apps/shared/components/calendar/GuestInput.js +30 -0
  173. package/dist/apps/shared/components/calendar/RequestChangeForm.js +11 -22
  174. package/dist/apps/shared/components/calendar/eventForm.d.ts +2 -2
  175. package/dist/apps/shared/components/calendar/eventFormat.d.ts +21 -8
  176. package/dist/apps/shared/components/calendar/eventFormat.js +50 -23
  177. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +5 -4
  178. package/dist/apps/shared/components/contacts/ContactsSidebar.js +1 -1
  179. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
  180. package/dist/apps/shared/components/contacts/ContactsToolbar.js +4 -2
  181. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +7 -5
  182. package/dist/apps/shared/components/layout/AppShell.d.ts +8 -11
  183. package/dist/apps/shared/components/layout/AppShell.js +24 -33
  184. package/dist/apps/shared/components/layout/FloatingActionButton.d.ts +13 -0
  185. package/dist/apps/shared/components/layout/FloatingActionButton.js +9 -0
  186. package/dist/apps/shared/components/layout/UserMenu.d.ts +4 -1
  187. package/dist/apps/shared/components/layout/UserMenu.js +6 -5
  188. package/dist/apps/shared/components/mail/ConversationThreadPane.js +127 -22
  189. package/dist/apps/shared/components/mail/EmptyFolderBar.d.ts +18 -0
  190. package/dist/apps/shared/components/mail/EmptyFolderBar.js +10 -0
  191. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +14 -4
  192. package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -13
  193. package/dist/apps/shared/components/mail/MenuButton.d.ts +9 -2
  194. package/dist/apps/shared/components/mail/MenuButton.js +15 -11
  195. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +5 -0
  196. package/dist/apps/shared/components/mail/MessageDetailPane.js +147 -7
  197. package/dist/apps/shared/components/mail/PermanentDeleteDialog.d.ts +19 -0
  198. package/dist/apps/shared/components/mail/PermanentDeleteDialog.js +11 -0
  199. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +8 -4
  200. package/dist/apps/shared/components/mail/compose/RecipientInput.d.ts +21 -1
  201. package/dist/apps/shared/components/mail/compose/RecipientInput.js +18 -10
  202. package/dist/apps/shared/components/mail/layout/FolderBadgeChip.d.ts +6 -0
  203. package/dist/apps/shared/components/mail/layout/FolderBadgeChip.js +9 -0
  204. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +16 -7
  205. package/dist/apps/shared/components/mail/layout/MailShell.js +78 -65
  206. package/dist/apps/shared/components/mail/layout/SidebarSection.d.ts +23 -0
  207. package/dist/apps/shared/components/mail/layout/SidebarSection.js +16 -0
  208. package/dist/apps/shared/components/mail/reading/MessageMoreMenu.d.ts +56 -0
  209. package/dist/apps/shared/components/mail/reading/MessageMoreMenu.js +153 -0
  210. package/dist/apps/shared/components/mail/reading/MessageSourceDialog.d.ts +27 -0
  211. package/dist/apps/shared/components/mail/reading/MessageSourceDialog.js +27 -0
  212. package/dist/apps/shared/components/mail/reading/PendingMessageCard.d.ts +14 -0
  213. package/dist/apps/shared/components/mail/reading/PendingMessageCard.js +16 -0
  214. package/dist/apps/shared/components/mail/reading/messageExport.d.ts +19 -0
  215. package/dist/apps/shared/components/mail/reading/messageExport.js +51 -0
  216. package/dist/apps/shared/components/mail/reading/printMessage.d.ts +30 -0
  217. package/dist/apps/shared/components/mail/reading/printMessage.js +70 -0
  218. package/dist/apps/shared/components/mail/reading/useMessageActions.d.ts +57 -0
  219. package/dist/apps/shared/components/mail/reading/useMessageActions.js +366 -0
  220. package/dist/apps/shared/components/settings/layout/SettingsShell.js +10 -7
  221. package/dist/apps/shared/components/tasks/TasksSidebar.js +1 -1
  222. package/dist/apps/shared/components/tasks/layout/TasksShell.js +7 -5
  223. package/dist/apps/shared/keyboard/GlobalShortcuts.js +1 -1
  224. package/dist/apps/shared/mail/folderCounts.d.ts +10 -0
  225. package/dist/apps/shared/mail/folderCounts.js +12 -0
  226. package/dist/apps/shared/mail/folderOfType.d.ts +13 -0
  227. package/dist/apps/shared/mail/folderOfType.js +40 -0
  228. package/dist/apps/shared/mail/outbox/outgoingReplies.d.ts +80 -0
  229. package/dist/apps/shared/mail/outbox/outgoingReplies.js +131 -0
  230. package/dist/apps/shared/mail/outbox/sendJob.d.ts +5 -1
  231. package/dist/apps/shared/mail/outbox/sendJob.js +14 -1
  232. package/dist/apps/shared/mail/outbox/sendOutcomes.js +13 -4
  233. package/dist/apps/shared/mail/permanentDelete.d.ts +62 -0
  234. package/dist/apps/shared/mail/permanentDelete.js +127 -0
  235. package/dist/apps/shared/mail/primaryMailbox.d.ts +29 -0
  236. package/dist/apps/shared/mail/primaryMailbox.js +61 -0
  237. package/dist/apps/shared/mail/reportNotices.d.ts +21 -0
  238. package/dist/apps/shared/mail/reportNotices.js +47 -0
  239. package/dist/apps/shared/mail/senderBlocking.d.ts +26 -0
  240. package/dist/apps/shared/mail/senderBlocking.js +92 -0
  241. package/dist/apps/shared/mail/useCollapsedSections.d.ts +32 -0
  242. package/dist/apps/shared/mail/useCollapsedSections.js +110 -0
  243. package/dist/apps/shared/mail/useMailConnection.js +3 -1
  244. package/dist/apps/shared/mail/useMailboxUpdateAccess.d.ts +11 -0
  245. package/dist/apps/shared/mail/useMailboxUpdateAccess.js +52 -0
  246. package/dist/apps/shared/mail/usePermanentDelete.d.ts +35 -0
  247. package/dist/apps/shared/mail/usePermanentDelete.js +96 -0
  248. package/dist/apps/shared/navigation/frameContext.d.ts +1 -1
  249. package/dist/apps/shared/navigation/index.d.ts +16 -0
  250. package/dist/apps/shared/navigation/index.js +34 -0
  251. package/dist/apps/shared/navigation/pageTitle.d.ts +11 -0
  252. package/dist/apps/shared/navigation/pageTitle.js +12 -0
  253. package/dist/apps/shared/search/crossMailboxSearch.d.ts +72 -0
  254. package/dist/apps/shared/search/crossMailboxSearch.js +136 -0
  255. package/dist/apps/shared/styles/app.css +396 -386
  256. package/dist/apps/www/_shell.d.ts +26 -0
  257. package/dist/apps/www/_shell.js +31 -0
  258. package/dist/apps/www/calendar/index.d.ts +7 -2
  259. package/dist/apps/www/calendar/index.js +7 -4
  260. package/dist/apps/www/contacts/[uid].d.ts +14 -3
  261. package/dist/apps/www/contacts/[uid].js +5 -3
  262. package/dist/apps/www/contacts/index.d.ts +7 -2
  263. package/dist/apps/www/contacts/index.js +8 -4
  264. package/dist/apps/www/index.d.ts +7 -2
  265. package/dist/apps/www/index.js +542 -207
  266. package/dist/apps/www/messages/[uid].d.ts +14 -3
  267. package/dist/apps/www/messages/[uid].js +7 -5
  268. package/dist/apps/www/settings/appearance/index.d.ts +8 -2
  269. package/dist/apps/www/settings/appearance/index.js +4 -2
  270. package/dist/apps/www/settings/auto-reply/index.d.ts +7 -2
  271. package/dist/apps/www/settings/auto-reply/index.js +4 -2
  272. package/dist/apps/www/settings/blocked-senders/index.d.ts +9 -0
  273. package/dist/apps/www/settings/blocked-senders/index.js +134 -0
  274. package/dist/apps/www/settings/encryption/index.d.ts +7 -2
  275. package/dist/apps/www/settings/encryption/index.js +4 -2
  276. package/dist/apps/www/settings/filters/[uid].d.ts +7 -2
  277. package/dist/apps/www/settings/filters/[uid].js +4 -2
  278. package/dist/apps/www/settings/filters/index.d.ts +7 -2
  279. package/dist/apps/www/settings/filters/index.js +4 -2
  280. package/dist/apps/www/settings/filters/new/index.d.ts +7 -2
  281. package/dist/apps/www/settings/filters/new/index.js +28 -5
  282. package/dist/apps/www/settings/labels/index.d.ts +7 -2
  283. package/dist/apps/www/settings/labels/index.js +4 -2
  284. package/dist/apps/www/settings/privacy/index.d.ts +7 -2
  285. package/dist/apps/www/settings/privacy/index.js +4 -2
  286. package/dist/apps/www/settings/profile/index.d.ts +7 -2
  287. package/dist/apps/www/settings/profile/index.js +4 -2
  288. package/dist/apps/www/settings/read-receipts/index.d.ts +7 -2
  289. package/dist/apps/www/settings/read-receipts/index.js +4 -2
  290. package/dist/apps/www/settings/sharing/index.d.ts +7 -2
  291. package/dist/apps/www/settings/sharing/index.js +4 -2
  292. package/dist/apps/www/settings/signatures/[uid].d.ts +7 -2
  293. package/dist/apps/www/settings/signatures/[uid].js +4 -2
  294. package/dist/apps/www/settings/signatures/index.d.ts +7 -2
  295. package/dist/apps/www/settings/signatures/index.js +4 -2
  296. package/dist/apps/www/settings/signatures/new/index.d.ts +7 -2
  297. package/dist/apps/www/settings/signatures/new/index.js +5 -3
  298. package/dist/apps/www/tasks/index.d.ts +7 -2
  299. package/dist/apps/www/tasks/index.js +5 -3
  300. package/package.json +4 -2
  301. package/apps/shared/navigation/AppRouter.tsx +0 -300
  302. package/apps/shared/navigation/idle.ts +0 -45
  303. package/apps/shared/navigation/routerContext.tsx +0 -83
  304. package/apps/shared/navigation/routes.ts +0 -72
  305. package/apps/www/_routedPage.tsx +0 -24
  306. package/apps/www/_routes.ts +0 -37
  307. package/dist/apps/shared/navigation/AppRouter.d.ts +0 -52
  308. package/dist/apps/shared/navigation/AppRouter.js +0 -242
  309. package/dist/apps/shared/navigation/idle.d.ts +0 -14
  310. package/dist/apps/shared/navigation/idle.js +0 -43
  311. package/dist/apps/shared/navigation/routerContext.d.ts +0 -37
  312. package/dist/apps/shared/navigation/routerContext.js +0 -56
  313. package/dist/apps/shared/navigation/routes.d.ts +0 -32
  314. package/dist/apps/shared/navigation/routes.js +0 -37
  315. package/dist/apps/www/_routedPage.d.ts +0 -12
  316. package/dist/apps/www/_routedPage.js +0 -19
  317. package/dist/apps/www/_routes.d.ts +0 -11
  318. package/dist/apps/www/_routes.js +0 -31
@@ -1,480 +1,461 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import "../../styles/app.css";
6
- import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
7
- import type { IconType } from "react-icons";
8
- import {
9
- HiOutlineCalendarDays,
10
- HiOutlineClipboardDocumentList,
11
- HiOutlineEnvelope,
12
- HiOutlinePuzzlePiece,
13
- HiOutlineUsers,
14
- } from "react-icons/hi2";
15
- import { useRedirectIfUnauthenticated } from "@rapidmx/react-shared/auth/session.js";
16
- import { getSetupStatus } from "@rapidmx/react-shared/admin/setupApi.js";
17
- import { stopImpersonating } from "@rapidmx/react-shared/mail/mailApi.js";
18
- import useBranding from "@rapidmx/react-shared/branding/useBranding.js";
19
- import { useIdleKeyTimeout } from "@rapidmx/react-shared/crypto/useIdleKeyTimeout.js";
20
- import ComposeProvider from "../mail/compose/ComposeContext.js";
21
- import { flushComposeDrafts, markSigningOut } from "../mail/compose/composeFlushRegistry.js";
22
- import BottomTabBar, { NavItem } from "@rapidmx/react-shared/components/navigation/BottomTabBar.js";
23
- import { FrameBrandingFooter, FrameBrandingHeader, useBrandingHtml } from "./BrandingChrome.js";
24
- import RailIcon from "./RailIcon.js";
25
- import AppearanceProvider from "../../appearance/AppearanceProvider.js";
26
- import { clearAppearanceCache } from "../../appearance/appearanceCache.js";
27
- import type { Branding } from "@rapidmx/react-shared/branding/brandingApi.js";
28
- import UserMenu from "./UserMenu.js";
29
- import { UnlockPromptProvider } from "./UnlockPromptProvider.js";
30
- import { SIGN_OUT_CHANNEL, destroyAllLocalIndexes } from "../../search/localIndexRpcClient.js";
31
- import { authApiFetch, setApiUnauthorizedObserver } from "@rapidmx/react-shared/util/api.js";
32
- import { destroyUnlockedKeys } from "@rapidmx/react-shared/crypto/keySession.js";
33
- import { clearPinnedSignerCache } from "../mail/pinnedSigners.js";
34
- import { mergePluginNavItems, PluginNav, PluginNavProps } from "../../plugins/pluginNav.js";
35
- import { useInAppFrame } from "../../navigation/frameContext.js";
36
- import { APP_HREFS } from "../../navigation/appHrefs.js";
37
- import { useNavigate } from "../../navigation/routerContext.js";
38
- import { GlobalShortcuts } from "../../keyboard/GlobalShortcuts.js";
39
- import { ShortcutProvider } from "../../keyboard/ShortcutProvider.js";
40
- import ShortcutsDialog from "../../keyboard/ShortcutsDialog.js";
41
- import { inboxUnreadTotal } from "../../mail/folderCounts.js";
42
- import { MailConnectionContext, useMailConnection } from "../../mail/useMailConnection.js";
43
- import { useUnreadTitle } from "../../mail/useUnreadTitle.js";
44
- import UnlockBridge from "../../mail/outbox/UnlockBridge.js";
45
- import NotificationCenter from "../../notifications/NotificationCenter.js";
46
- import { useHeaderHeightRef } from "../../notifications/headerOffset.js";
47
- import NotificationHistoryDialog from "../../notifications/NotificationHistoryDialog.js";
48
- import { notifySessionExpired, setSignInUrl } from "../../notifications/apiErrors.js";
49
- import { useUnseenErrorCount } from "../../notifications/useNotifications.js";
50
- import { useSigningEnrollmentWatcher } from "../../signing/useSigningEnrollmentWatcher.js";
51
- import { useCalendarReminders } from "../../calendar/useCalendarReminders.js";
52
-
53
- /** How long sign-out waits for auth-server's logout before navigating anyway. */
54
- export const LOGOUT_TIMEOUT_MS = 3_000;
55
-
56
- /**
57
- * Calls auth-server's logout (`POST /api/auth/logout`, cross-origin with credentials), which clears the auth
58
- * cookie and invalidates the session's refresh token. Bounded by `LOGOUT_TIMEOUT_MS` and never rejects - a
59
- * failure (unreachable server, CORS) must not keep the user from leaving.
60
- */
61
- async function logOutOfAuthServer(authServerUrl: string | undefined): Promise<void> {
62
- if (!authServerUrl) {
63
- return;
64
- }
65
- const controller = new AbortController();
66
- const timer = setTimeout(() => controller.abort(), LOGOUT_TIMEOUT_MS);
67
- try {
68
- await authApiFetch(authServerUrl, "/auth/logout", { method: "POST", signal: controller.signal });
69
- } catch {
70
- // Navigate anyway - see this function's doc comment.
71
- } finally {
72
- clearTimeout(timer);
73
- }
74
- }
75
-
76
- export type AppShellApp = "mail" | "calendar" | "contacts" | "tasks";
77
-
78
- /** `"settings"` is a valid `active` value but deliberately has no entry in `APPS` below — Settings is
79
- * reached via a `UserMenu` item, not a 5th rail icon (see `SettingsShell.tsx`), so it highlights no
80
- * rail/tab icon at all; only the header title needs to account for it. Any other string is a plugin's
81
- * `appRail` item id (see `PluginNav`). */
82
- export type AppShellActive = AppShellApp | "settings" | (string & {});
83
-
84
- export interface AppShellProps extends PluginNavProps {
85
- /** Which icon in the rail is highlighted as the current app — `"settings"` highlights none, and a plugin
86
- * app page passes its own `appRail` item id. */
87
- active: AppShellActive;
88
- /** Populated automatically by the framework from an authenticated request (e.g. a valid `jwt` cookie). */
89
- userUid?: string;
90
- /** auth-server's base URL, injected via the route's `fetchProps`. */
91
- authServerUrl?: string;
92
- /**
93
- * `true` when this session is an admin "log in as user" impersonation (a `jwt_impersonator` cookie is
94
- * present) — see `MailShell`'s original doc comment, unchanged now that this lives here. Drives the
95
- * "you are viewing as this user — stop impersonating" banner below.
96
- */
97
- impersonating?: boolean;
98
- /** Where `mailApi.ts`'s `stopImpersonating()` should call — see `MailShell`'s original doc comment. */
99
- impersonationBaseUrl?: string;
100
- /** `true` when the caller's JWT carries a trusted role — shows an "Admin Console" item in the user menu below. A token
101
- * only carries one once elevated, so a real administrator with an ordinary session is `false` here; the user menu
102
- * asks auth-server about them separately (see `UserMenu`'s `detectAdmin`). */
103
- trusted?: boolean;
104
- /** The role names the server treats as trusted (its `trusted_roles` config, injected via the route's `fetchProps`) -
105
- * what that lookup looks for. Absent means the server's own default, `["admin"]`. */
106
- trustedRoles?: string[];
107
- /** The deployment's branding as the server rendered the page (its `branding` prop). Used until the frame's own fetch answers, so a custom header is there from the first paint - and the frame knows to drop its own title bar - instead of appearing (and moving everything) once the request returns. */
108
- branding?: Branding;
109
- /** The signed-in user's stored appearance preferences as the server rendered the page (its `appearance` prop), so the first paint already wears the theme and background - see `AppearanceProvider`. */
110
- appearance?: unknown;
111
- }
112
-
113
- export interface AppDef {
114
- id: AppShellApp;
115
- href: string;
116
- label: string;
117
- icon: IconType;
118
- }
119
-
120
- export const APPS: AppDef[] = [
121
- { id: "mail", href: APP_HREFS.mail, label: "Mail", icon: HiOutlineEnvelope },
122
- { id: "calendar", href: APP_HREFS.calendar, label: "Calendar", icon: HiOutlineCalendarDays },
123
- { id: "contacts", href: APP_HREFS.contacts, label: "Contacts", icon: HiOutlineUsers },
124
- { id: "tasks", href: APP_HREFS.tasks, label: "Tasks", icon: HiOutlineClipboardDocumentList },
125
- ];
126
-
127
- /** Ids plugin `appRail` items can't take besides `APPS`' own - `"settings"` has no rail icon but is still a
128
- * core `active` value. */
129
- const RESERVED_APP_IDS = ["settings"];
130
-
131
- /** `APPS` followed by the plugins' `appRail` items (generic icon), core ids winning - see `mergePluginNavItems`. */
132
- export function appRailItems(pluginNav?: PluginNav): NavItem[] {
133
- return mergePluginNavItems<NavItem>(
134
- APPS,
135
- pluginNav?.appRail,
136
- ({ id, href, label }) => ({ id, href, label, icon: HiOutlinePuzzlePiece }),
137
- RESERVED_APP_IDS,
138
- );
139
- }
140
-
141
- /** What only the persistent frame (`AppRouter`) passes to the chrome it keeps mounted. */
142
- export interface AppChromeProps extends AppShellProps {
143
- /** Changes whenever the router shows a different page: the chrome then moves focus to the content, scrolls to its top,
144
- * sets the document title and announces the page. Absent outside the router, when nothing does. */
145
- routeKey?: string;
146
- /** The router is loading the next page's code - the content is `aria-busy`. */
147
- busy?: boolean;
148
- /** A screen that takes over the window (`FrameTakeover`) is showing: the rail, header, banner and footer are hidden - not
149
- * unmounted, so what is inside them (and the page in the content region) keeps its state. */
150
- hideChrome?: boolean;
151
- }
152
-
153
- /**
154
- * The persistent chrome shared by every webmail app (Mail, Calendar, Contacts, Tasks): a left icon rail for
155
- * switching apps, a header with the current app's name and `UserMenu`, and the impersonation banner.
156
- * Each app's own shell (e.g. `MailShell`) renders its own contextual sidebar + content as `children`, inside
157
- * the area to the right of the icon rail and below the header.
158
- *
159
- * Rendered by `AppRouter`, once, for the life of the page, so that moving between apps replaces only `children` - see
160
- * `AppShell` below for what a page's own shell renders instead.
161
- */
162
- export function AppChrome({
163
- active,
164
- userUid,
165
- authServerUrl,
166
- impersonating,
167
- impersonationBaseUrl,
168
- trusted,
169
- trustedRoles,
170
- branding: initialBranding,
171
- appearance,
172
- pluginNav,
173
- routeKey,
174
- busy,
175
- hideChrome,
176
- children,
177
- }: PropsWithChildren<AppChromeProps>) {
178
- const [stoppingImpersonation, setStoppingImpersonation] = useState(false);
179
- // The keyboard shortcuts dialog: opened by `?`/Ctrl+/ (`GlobalShortcuts`) and by the account menu's item.
180
- const [shortcutsOpen, setShortcutsOpen] = useState(false);
181
- // The pop-up history ("Recent notifications" in the account menu). The pop-ups themselves are drawn by `NotificationCenter`, below.
182
- const [historyOpen, setHistoryOpen] = useState(false);
183
- // Only the count is read, so the whole frame does not render again for every pop-up that comes and goes.
184
- const unseenErrors = useUnseenErrorCount();
185
- // The title bar's height for the pop-up stack, which sticks just below the header (a branding header publishes its own - `FrameBrandingHeader`).
186
- const headerRef = useHeaderHeightRef();
187
- const signingOutRef = useRef(false);
188
- const { branding: fetchedBranding, iconSrc: fetchedIconSrc } = useBranding();
189
- // The server's copy until the fetch answers, so the frame's shape (a custom header replaces the title bar) never changes after the first paint.
190
- const branding = fetchedBranding ?? initialBranding ?? null;
191
- const iconSrc = fetchedBranding ? fetchedIconSrc : initialBranding?.iconUrl || initialBranding?.logoUrl || fetchedIconSrc;
192
- // The custom header and footer, sanitized and with their `{USER_MENU}` / `{APP_TITLE}` placeholders (`undefined` until parsed, `null` when there is none).
193
- const header = useBrandingHtml(branding?.headerHtml);
194
- const footer = useBrandingHtml(branding?.footerHtml);
195
- // The mailboxes, their folders and the one push connection live here, in the frame that stays mounted as the router swaps pages - so
196
- // new-mail pop-ups, the folder counters and the tab title's unread count work in Calendar, Contacts, Tasks and Settings too, and moving
197
- // between apps never opens a second socket (the server allows ten per user). `MailShell` reads them from `MailConnectionContext`. Outside
198
- // the router (`AppShell` rendered as a page's own chrome: tests, plugin pages) it stays off, and a Mail shell owns its connection itself.
199
- const inFrame = useInAppFrame();
200
- const navigate = useNavigate();
201
- const mail = useMailConnection({ userUid, enabled: inFrame, open: navigate });
202
- // A signing certificate the user asked for is announced when it is issued (or fails), on whichever page they are - see the hook.
203
- useSigningEnrollmentWatcher({ userUid, mailboxes: mail.mailboxes, enabled: inFrame });
204
- // A meeting reminder pops up on whichever page they are - see the hook.
205
- useCalendarReminders({ userUid, enabled: inFrame });
206
-
207
- useRedirectIfUnauthenticated(userUid, authServerUrl);
208
- // Any request this app makes that the server answers with a 401 - the session ended - raises one "Your session expired" pop-up with a
209
- // Sign in action (see `notifySessionExpired()`), whichever request noticed first, a background refresh included.
210
- useEffect(() => {
211
- setSignInUrl(authServerUrl);
212
- if (!userUid) {
213
- return;
214
- }
215
- setApiUnauthorizedObserver(() => void notifySessionExpired());
216
- return () => setApiUnauthorizedObserver(undefined);
217
- }, [userUid, authServerUrl]);
218
- // Mounted here, not scoped to Mail/Settings (the only shells that actually read unlocked keys),
219
- // specifically so activity in *any* app resets the idle clock - see that hook's own doc comment.
220
- useIdleKeyTimeout();
221
-
222
- // An administrator on a server that hasn't finished first-run setup is sent to the setup wizard. The status
223
- // check is admin-only, so it's only made for a trusted caller - everyone else would just get a 403 on every
224
- // page load. Any failure is ignored.
225
- useEffect(() => {
226
- if (!userUid || impersonating || !trusted) {
227
- return;
228
- }
229
- getSetupStatus()
230
- .then((status) => {
231
- if (status.required) {
232
- window.location.href = "/admin/setup";
233
- }
234
- })
235
- .catch(() => undefined);
236
- }, [userUid, impersonating, trusted]);
237
-
238
- // Another tab signing out (this app's `handleSignOut`, or the admin/escrow consoles' `signOutOfConsole()`)
239
- // ended this session too - its auth cookie is gone - so this tab destroys its own unlocked keys and every
240
- // local search index on the device, then leaves as well. The consoles have no local-index client of their
241
- // own, so this is what actually removes the indexes after a console sign-out (the console also records a
242
- // pending deletion, retried on the next mail load, in case no mail tab is open). `destroyAllLocalIndexes()`
243
- // announces the sign-out on this same channel, which this tab then hears itself, so the ref is set first:
244
- // each tab reacts once, and the tab that started the sign-out ignores its own announcement.
245
- useEffect(() => {
246
- if (!userUid || typeof BroadcastChannel === "undefined") {
247
- return;
248
- }
249
- const channel = new BroadcastChannel(SIGN_OUT_CHANNEL);
250
- channel.addEventListener("message", (event: MessageEvent<{ type?: string }>) => {
251
- if (event.data?.type !== "sign-out" || signingOutRef.current) {
252
- return;
253
- }
254
- signingOutRef.current = true;
255
- // Compose windows must not ask "Leave site?" - that would let this forced navigation be cancelled.
256
- markSigningOut();
257
- destroyUnlockedKeys();
258
- clearPinnedSignerCache();
259
- clearAppearanceCache();
260
- // Bounded by its own timeout and never rejects - awaited so navigating doesn't kill the Worker mid-delete.
261
- void destroyAllLocalIndexes().then(() => {
262
- window.location.href = authServerUrl ?? "/";
263
- });
264
- });
265
- return () => channel.close();
266
- }, [userUid, authServerUrl]);
267
-
268
- async function handleSignOut() {
269
- signingOutRef.current = true;
270
- // Before flushing and navigating: compose windows then skip their "Leave site?" prompt, which could
271
- // otherwise cancel the sign-out's own navigation.
272
- markSigningOut();
273
- // Unlocked private keys never outlive an explicit sign-out.
274
- destroyUnlockedKeys();
275
- // Trusted signer pins read from contacts don't outlive the session either.
276
- clearPinnedSignerCache();
277
- clearAppearanceCache();
278
- // Open compose windows save edits still waiting on their autosave debounce while the session is still
279
- // valid - logout invalidates it. Bounded the same way as logout itself, and never rejects.
280
- await flushComposeDrafts(LOGOUT_TIMEOUT_MS);
281
- // The Tier 2 local index MUST be destroyed on explicit logout, the same as unlocked keys themselves
282
- // (spec §11). Destroys every index on this device (not only mailboxes opened this page load) and is
283
- // awaited before navigating - a navigation tears down the Worker mid-delete otherwise.
284
- // destroyAllLocalIndexes() is bounded by its own timeout and never rejects, so sign-out can't hang.
285
- // In parallel, auth-server's logout clears the auth cookie and invalidates the session's refresh
286
- // token - without it, "Sign Out" would only navigate away from a still-valid session.
287
- await Promise.all([destroyAllLocalIndexes(), logOutOfAuthServer(authServerUrl)]);
288
- window.location.href = authServerUrl ?? "/";
289
- }
290
-
291
- async function handleStopImpersonating() {
292
- setStoppingImpersonation(true);
293
- try {
294
- await stopImpersonating(impersonationBaseUrl ?? "");
295
- } catch {
296
- // Navigate either way: a failed call leaves the impersonator cookie (and this banner) exactly as
297
- // they were, so there's nothing else useful to show — matching this app's other network-error
298
- // handling, which surfaces via a full reload rather than an inline retry affordance.
299
- } finally {
300
- window.location.href = "/admin";
301
- }
302
- }
303
-
304
- // What the persistent frame (`AppRouter`) needs on top of a page that never changes: the document title follows the page, and
305
- // after the router replaces the page the keyboard focus, the scroll position and a screen reader are told about it - a
306
- // page load did all of that by itself. Nothing here runs for a page shown outside the router (`routeKey` is undefined).
307
- const contentRef = useRef<HTMLDivElement>(null);
308
- const [announcement, setAnnouncement] = useState("");
309
- const firstRouteKeyRef = useRef(routeKey);
310
- const pageLabel = active === "settings" ? "Settings" : appRailItems(pluginNav).find((app) => app.id === active)?.label;
311
- useEffect(() => {
312
- if (routeKey !== undefined) {
313
- const brand = branding?.title || branding?.companyName || "RapidMX";
314
- document.title = pageLabel ? `${brand}: ${pageLabel}` : brand;
315
- }
316
- }, [routeKey, pageLabel, branding]);
317
- // After the title effect above, so a page change (which rewrites the title) is followed by the unread count going back in front of it.
318
- useUnreadTitle(inboxUnreadTotal(mail.mailboxFolders, mail.folderCounts.counts), {
319
- enabled: inFrame,
320
- resetKey: `${routeKey}|${pageLabel}|${branding?.title}|${branding?.companyName}`,
321
- });
322
- useEffect(() => {
323
- if (routeKey === undefined || routeKey === firstRouteKeyRef.current) {
324
- return;
325
- }
326
- setAnnouncement(pageLabel ?? "");
327
- contentRef.current?.focus({ preventScroll: true });
328
- window.scrollTo(0, 0);
329
- }, [routeKey]);
330
-
331
- if (!userUid) {
332
- return <div className="min-h-screen" />;
333
- }
334
-
335
- const apps = appRailItems(pluginNav);
336
- // The header title: "settings" has no rail item, everything else is labelled by its own rail item.
337
- const activeLabel = active === "settings" ? "Settings" : apps.find((app) => app.id === active)?.label;
338
- // A custom header (`Branding.headerHtml`) replaces the app's own title bar and the icon at the top of the rail: it is the top of the app, and the
339
- // account menu moves into it. While it is still being parsed it already counts, so the frame's shape doesn't change under the user.
340
- const customHeader = header !== null;
341
- // Where the one account menu lives: the header's `{USER_MENU}`, else the footer's, else a small cell at the header's right end - never lost.
342
- const menuInHeader = !!header?.hasUserMenu;
343
- const menuInFooter = customHeader && !!header && !menuInHeader && !!footer?.hasUserMenu;
344
- const renderUserMenu = (placement: "down" | "up") => (
345
- <UserMenu
346
- userUid={userUid}
347
- authServerUrl={authServerUrl}
348
- onSignOut={handleSignOut}
349
- // An impersonating administrator acts as the impersonated user, so the console link is hidden then.
350
- showAdminLink={!!trusted && !impersonating}
351
- detectAdmin={!trusted && !impersonating}
352
- trustedRoles={trustedRoles}
353
- showSettingsLink
354
- showNotificationSettings
355
- onShowShortcuts={() => setShortcutsOpen(true)}
356
- onShowNotifications={() => setHistoryOpen(true)}
357
- unseenErrors={unseenErrors}
358
- placement={placement}
359
- />
360
- );
361
-
362
- return (
363
- // Mounted here, not scoped to Mail/Settings, for the same reason as useIdleKeyTimeout() above -
364
- // ComposeWindow's sign/encrypt toggles and MessageDetailPane's encrypted-message view (both Mail)
365
- // are today's only useUnlockPrompt() callers, but this needs to be available to any app shell.
366
- // Asks the server for the user's appearance only in the persistent frame (every core page); a page that renders its own chrome (a plugin's) uses the
367
- // `appearance` it was given and what this browser cached.
368
- <AppearanceProvider userUid={userUid} initial={appearance} lookUp={inFrame}>
369
- <ShortcutProvider>
370
- <MailConnectionContext.Provider value={inFrame ? mail : null}>
371
- <GlobalShortcuts authServerUrl={authServerUrl} onToggleHelp={() => setShortcutsOpen((open) => !open)} />
372
- <ShortcutsDialog open={shortcutsOpen} onClose={() => setShortcutsOpen(false)} />
373
- <UnlockPromptProvider>
374
- <UnlockBridge />
375
- {/* An impersonating admin acts with the impersonated user's access, so their own trusted role
376
- mustn't skip the per-mailbox checks. */}
377
- <ComposeProvider userUid={userUid} trusted={!!trusted && !impersonating}>
378
- <div className="rr-frame-bg min-h-screen flex flex-col">
379
- {!hideChrome && customHeader && (
380
- <FrameBrandingHeader
381
- parsed={header}
382
- userMenu={menuInHeader ? renderUserMenu("down") : undefined}
383
- fallbackMenu={header && !menuInHeader && !menuInFooter ? renderUserMenu("down") : undefined}
384
- appTitle={activeLabel}
385
- />
386
- )}
387
- {impersonating && !hideChrome && (
388
- <div className="h-10 shrink-0 bg-warning text-warning-contrast flex items-center justify-center gap-3 text-sm font-medium px-4">
389
- <span>
390
- You are viewing as <strong>{userUid}</strong>.
391
- </span>
392
- <button
393
- type="button"
394
- onClick={handleStopImpersonating}
395
- disabled={stoppingImpersonation}
396
- className="underline hover:no-underline disabled:opacity-60"
397
- >
398
- {stoppingImpersonation ? "Returning to admin…" : "Return to admin"}
399
- </button>
400
- </div>
401
- )}
402
- <div className="flex-1 flex min-h-0">
403
- {!hideChrome && (
404
- <nav
405
- aria-label="Apps"
406
- className={[
407
- "hidden md:flex w-16 shrink-0 bg-surface border-r border-border flex-col items-center gap-1",
408
- // Under a custom header the rail starts with the app icons; without one its own icon is flush with the top of the window.
409
- customHeader ? "py-3" : "pb-3",
410
- ].join(" ")}
411
- >
412
- {!customHeader && (
413
- <RailIcon src={iconSrc} />
414
- )}
415
- {apps.map(({ id, href, label, icon: Icon }) => (
416
- <a
417
- key={id}
418
- href={href}
419
- aria-label={label}
420
- aria-current={id === active ? "page" : undefined}
421
- title={label}
422
- className={[
423
- "w-10 h-10 flex items-center justify-center rounded-sm",
424
- id === active
425
- ? "bg-primary/10 text-primary-dark"
426
- : "text-text-muted hover:bg-surface-alt hover:text-text",
427
- ].join(" ")}
428
- >
429
- <Icon size={20} aria-hidden="true" />
430
- </a>
431
- ))}
432
- </nav>
433
- )}
434
- {!hideChrome && <BottomTabBar apps={apps} active={active} />}
435
- <div className="flex-1 flex flex-col min-w-0">
436
- {!hideChrome && !customHeader && (
437
- <header ref={headerRef} className="rr-solid sticky top-0 z-30 h-16 shrink-0 bg-surface border-b border-border flex items-center justify-between gap-4 px-6">
438
- <span className="font-display font-bold text-lg uppercase tracking-wide">{activeLabel}</span>
439
- {renderUserMenu("down")}
440
- </header>
441
- )}
442
- {/* The one pop-up stack for the whole app: right under the header row, so it never covers the account menu. */}
443
- <NotificationCenter />
444
- <div
445
- ref={contentRef}
446
- id="app-content"
447
- tabIndex={-1}
448
- aria-busy={busy || undefined}
449
- className={["flex-1 flex min-h-0 outline-none", hideChrome ? "" : "pb-14 md:pb-0"].join(" ")}
450
- >
451
- {children}
452
- </div>
453
- </div>
454
- </div>
455
- {routeKey !== undefined && (
456
- <div role="status" aria-live="polite" className="sr-only">
457
- {announcement}
458
- </div>
459
- )}
460
- {!hideChrome && <FrameBrandingFooter parsed={footer} userMenu={menuInFooter ? renderUserMenu("up") : undefined} appTitle={activeLabel} />}
461
- </div>
462
- </ComposeProvider>
463
- </UnlockPromptProvider>
464
- <NotificationHistoryDialog open={historyOpen} onClose={() => setHistoryOpen(false)} />
465
- </MailConnectionContext.Provider>
466
- </ShortcutProvider>
467
- </AppearanceProvider>
468
- );
469
- }
470
-
471
- /**
472
- * What a page's own shell (`MailShell`, `CalendarShell`, ...) renders around its content. Outside the client-side router it
473
- * is the whole `AppChrome`, as it always was. Inside it (`AppRouter`) the chrome is already mounted above the page - and stays
474
- * mounted as the page is replaced - so this is only its children; everything it would have been given comes from the router
475
- * frame instead (the props are the same for every page, and `active` is the route's).
476
- */
477
- export default function AppShell(props: PropsWithChildren<AppShellProps>) {
478
- const inFrame = useInAppFrame();
479
- return inFrame ? <>{props.children}</> : <AppChrome {...props} />;
480
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import "../../styles/app.css";
6
+ import React, { PropsWithChildren, useEffect, useLayoutEffect, useRef, useState } from "react";
7
+ import type { IconType } from "react-icons";
8
+ import {
9
+ HiOutlineCalendarDays,
10
+ HiOutlineClipboardDocumentList,
11
+ HiOutlineEnvelope,
12
+ HiOutlinePuzzlePiece,
13
+ HiOutlineUsers,
14
+ } from "react-icons/hi2";
15
+ import { useRouter } from "@rapidrest/react/client";
16
+ import { useRedirectIfUnauthenticated } from "@rapidmx/react-shared/auth/session.js";
17
+ import { getSetupStatus } from "@rapidmx/react-shared/admin/setupApi.js";
18
+ import { stopImpersonating } from "@rapidmx/react-shared/mail/mailApi.js";
19
+ import useBranding from "@rapidmx/react-shared/branding/useBranding.js";
20
+ import { useIdleKeyTimeout } from "@rapidmx/react-shared/crypto/useIdleKeyTimeout.js";
21
+ import ComposeProvider from "../mail/compose/ComposeContext.js";
22
+ import { flushComposeDrafts, markSigningOut } from "../mail/compose/composeFlushRegistry.js";
23
+ import BottomTabBar, { NavItem } from "@rapidmx/react-shared/components/navigation/BottomTabBar.js";
24
+ import { FrameBrandingFooter, FrameBrandingHeader, useBrandingHtml } from "./BrandingChrome.js";
25
+ import RailIcon from "./RailIcon.js";
26
+ import AppearanceProvider from "../../appearance/AppearanceProvider.js";
27
+ import { clearAppearanceCache } from "../../appearance/appearanceCache.js";
28
+ import type { Branding } from "@rapidmx/react-shared/branding/brandingApi.js";
29
+ import UserMenu from "./UserMenu.js";
30
+ import { UnlockPromptProvider } from "./UnlockPromptProvider.js";
31
+ import { SIGN_OUT_CHANNEL, destroyAllLocalIndexes } from "../../search/localIndexRpcClient.js";
32
+ import { authApiFetch, setApiUnauthorizedObserver } from "@rapidmx/react-shared/util/api.js";
33
+ import { destroyUnlockedKeys } from "@rapidmx/react-shared/crypto/keySession.js";
34
+ import { clearPinnedSignerCache } from "../mail/pinnedSigners.js";
35
+ import { mergePluginNavItems, PluginNav, PluginNavProps } from "../../plugins/pluginNav.js";
36
+ import { useInAppFrame } from "../../navigation/frameContext.js";
37
+ import { APP_HREFS } from "../../navigation/appHrefs.js";
38
+ import { useNavigate } from "../../navigation/index.js";
39
+ import { GlobalShortcuts } from "../../keyboard/GlobalShortcuts.js";
40
+ import { ShortcutProvider } from "../../keyboard/ShortcutProvider.js";
41
+ import ShortcutsDialog from "../../keyboard/ShortcutsDialog.js";
42
+ import { inboxUnreadTotal } from "../../mail/folderCounts.js";
43
+ import { MailConnectionContext, useMailConnection } from "../../mail/useMailConnection.js";
44
+ import { useUnreadTitle } from "../../mail/useUnreadTitle.js";
45
+ import UnlockBridge from "../../mail/outbox/UnlockBridge.js";
46
+ import NotificationCenter from "../../notifications/NotificationCenter.js";
47
+ import { useHeaderHeightRef } from "../../notifications/headerOffset.js";
48
+ import NotificationHistoryDialog from "../../notifications/NotificationHistoryDialog.js";
49
+ import { notifySessionExpired, setSignInUrl } from "../../notifications/apiErrors.js";
50
+ import { useUnseenErrorCount } from "../../notifications/useNotifications.js";
51
+ import { useSigningEnrollmentWatcher } from "../../signing/useSigningEnrollmentWatcher.js";
52
+ import { useCalendarReminders } from "../../calendar/useCalendarReminders.js";
53
+
54
+ /** How long sign-out waits for auth-server's logout before navigating anyway. */
55
+ export const LOGOUT_TIMEOUT_MS = 3_000;
56
+
57
+ /**
58
+ * Calls auth-server's logout (`POST /api/auth/logout`, cross-origin with credentials), which clears the auth
59
+ * cookie and invalidates the session's refresh token. Bounded by `LOGOUT_TIMEOUT_MS` and never rejects - a
60
+ * failure (unreachable server, CORS) must not keep the user from leaving.
61
+ */
62
+ async function logOutOfAuthServer(authServerUrl: string | undefined): Promise<void> {
63
+ if (!authServerUrl) {
64
+ return;
65
+ }
66
+ const controller = new AbortController();
67
+ const timer = setTimeout(() => controller.abort(), LOGOUT_TIMEOUT_MS);
68
+ try {
69
+ await authApiFetch(authServerUrl, "/auth/logout", { method: "POST", signal: controller.signal });
70
+ } catch {
71
+ // Navigate anyway - see this function's doc comment.
72
+ } finally {
73
+ clearTimeout(timer);
74
+ }
75
+ }
76
+
77
+ export type AppShellApp = "mail" | "calendar" | "contacts" | "tasks";
78
+
79
+ /** `"settings"` is a valid `active` value but deliberately has no entry in `APPS` below — Settings is
80
+ * reached via a `UserMenu` item, not a 5th rail icon (see `SettingsShell.tsx`), so it highlights no
81
+ * rail/tab icon at all; only the header title needs to account for it. Any other string is a plugin's
82
+ * `appRail` item id (see `PluginNav`). */
83
+ export type AppShellActive = AppShellApp | "settings" | (string & {});
84
+
85
+ export interface AppShellProps extends PluginNavProps {
86
+ /** Which icon in the rail is highlighted as the current app — `"settings"` highlights none, and a plugin
87
+ * app page passes its own `appRail` item id. */
88
+ active: AppShellActive;
89
+ /** Populated automatically by the framework from an authenticated request (e.g. a valid `jwt` cookie). */
90
+ userUid?: string;
91
+ /** auth-server's base URL, injected via the route's `fetchProps`. */
92
+ authServerUrl?: string;
93
+ /**
94
+ * `true` when this session is an admin "log in as user" impersonation (a `jwt_impersonator` cookie is
95
+ * present) — see `MailShell`'s original doc comment, unchanged now that this lives here. Drives the
96
+ * "you are viewing as this user — stop impersonating" banner below.
97
+ */
98
+ impersonating?: boolean;
99
+ /** Where `mailApi.ts`'s `stopImpersonating()` should call — see `MailShell`'s original doc comment. */
100
+ impersonationBaseUrl?: string;
101
+ /** `true` when the caller's JWT carries a trusted role — shows an "Admin Console" item in the user menu below. A token
102
+ * only carries one once elevated, so a real administrator with an ordinary session is `false` here; the user menu
103
+ * asks auth-server about them separately (see `UserMenu`'s `detectAdmin`). */
104
+ trusted?: boolean;
105
+ /** The role names the server treats as trusted (its `trusted_roles` config, injected via the route's `fetchProps`) -
106
+ * what that lookup looks for. Absent means the server's own default, `["admin"]`. */
107
+ trustedRoles?: string[];
108
+ /** The deployment's branding as the server rendered the page (its `branding` prop). Used until the frame's own fetch answers, so a custom header is there from the first paint - and the frame knows to drop its own title bar - instead of appearing (and moving everything) once the request returns. */
109
+ branding?: Branding;
110
+ /** The signed-in user's stored appearance preferences as the server rendered the page (its `appearance` prop), so the first paint already wears the theme and background - see `AppearanceProvider`. */
111
+ appearance?: unknown;
112
+ }
113
+
114
+ export interface AppDef {
115
+ id: AppShellApp;
116
+ href: string;
117
+ label: string;
118
+ icon: IconType;
119
+ }
120
+
121
+ export const APPS: AppDef[] = [
122
+ { id: "mail", href: APP_HREFS.mail, label: "Mail", icon: HiOutlineEnvelope },
123
+ { id: "calendar", href: APP_HREFS.calendar, label: "Calendar", icon: HiOutlineCalendarDays },
124
+ { id: "contacts", href: APP_HREFS.contacts, label: "Contacts", icon: HiOutlineUsers },
125
+ { id: "tasks", href: APP_HREFS.tasks, label: "Tasks", icon: HiOutlineClipboardDocumentList },
126
+ ];
127
+
128
+ /** Ids plugin `appRail` items can't take besides `APPS`' own - `"settings"` has no rail icon but is still a
129
+ * core `active` value. */
130
+ const RESERVED_APP_IDS = ["settings"];
131
+
132
+ /** `APPS` followed by the plugins' `appRail` items (generic icon), core ids winning - see `mergePluginNavItems`. */
133
+ export function appRailItems(pluginNav?: PluginNav): NavItem[] {
134
+ return mergePluginNavItems<NavItem>(
135
+ APPS,
136
+ pluginNav?.appRail,
137
+ ({ id, href, label }) => ({ id, href, label, icon: HiOutlinePuzzlePiece }),
138
+ RESERVED_APP_IDS,
139
+ );
140
+ }
141
+
142
+ /** What only the persistent frame (`apps/www/_shell.tsx`) passes to the chrome it keeps mounted. */
143
+ export interface AppChromeProps extends AppShellProps {
144
+ /** The router is loading the next page - the content is `aria-busy`. */
145
+ busy?: boolean;
146
+ /** A screen that takes over the window (`FrameTakeover`) is showing: the rail, header, banner and footer are hidden - not
147
+ * unmounted, so what is inside them (and the page in the content region) keeps its state. */
148
+ hideChrome?: boolean;
149
+ }
150
+
151
+ /**
152
+ * The persistent chrome shared by every webmail app (Mail, Calendar, Contacts, Tasks): a left icon rail for
153
+ * switching apps, a header with the current app's name and `UserMenu`, and the impersonation banner.
154
+ * Each app's own shell (e.g. `MailShell`) renders its own contextual sidebar + content as `children`, inside
155
+ * the area to the right of the icon rail and below the header.
156
+ *
157
+ * Rendered by the webmail's app shell (`apps/www/_shell.tsx`, the router's persistent client layout), once, for the life of the
158
+ * page, so that moving between apps replaces only `children` - see `AppShell` below for what a page's own shell renders instead.
159
+ */
160
+ export function AppChrome({
161
+ active,
162
+ userUid,
163
+ authServerUrl,
164
+ impersonating,
165
+ impersonationBaseUrl,
166
+ trusted,
167
+ trustedRoles,
168
+ branding: initialBranding,
169
+ appearance,
170
+ pluginNav,
171
+ busy,
172
+ hideChrome,
173
+ children,
174
+ }: PropsWithChildren<AppChromeProps>) {
175
+ const [stoppingImpersonation, setStoppingImpersonation] = useState(false);
176
+ // The keyboard shortcuts dialog: opened by `?`/Ctrl+/ (`GlobalShortcuts`) and by the account menu's item.
177
+ const [shortcutsOpen, setShortcutsOpen] = useState(false);
178
+ // The pop-up history ("Recent notifications" in the account menu). The pop-ups themselves are drawn by `NotificationCenter`, below.
179
+ const [historyOpen, setHistoryOpen] = useState(false);
180
+ // Only the count is read, so the whole frame does not render again for every pop-up that comes and goes.
181
+ const unseenErrors = useUnseenErrorCount();
182
+ // The title bar's height for the pop-up stack, which sticks just below the header (a branding header publishes its own - `FrameBrandingHeader`).
183
+ const headerRef = useHeaderHeightRef();
184
+ const signingOutRef = useRef(false);
185
+ const { branding: fetchedBranding, iconSrc: fetchedIconSrc } = useBranding();
186
+ // The server's copy until the fetch answers, so the frame's shape (a custom header replaces the title bar) never changes after the first paint.
187
+ const branding = fetchedBranding ?? initialBranding ?? null;
188
+ const iconSrc = fetchedBranding ? fetchedIconSrc : initialBranding?.iconUrl || initialBranding?.logoUrl || fetchedIconSrc;
189
+ // The custom header and footer, sanitized and with their `{USER_MENU}` / `{APP_TITLE}` placeholders (`undefined` until parsed, `null` when there is none).
190
+ const header = useBrandingHtml(branding?.headerHtml);
191
+ const footer = useBrandingHtml(branding?.footerHtml);
192
+ // The mailboxes, their folders and the one push connection live here, in the frame that stays mounted as the router swaps pages - so
193
+ // new-mail pop-ups, the folder counters and the tab title's unread count work in Calendar, Contacts, Tasks and Settings too, and moving
194
+ // between apps never opens a second socket (the server allows ten per user). `MailShell` reads them from `MailConnectionContext`. Outside
195
+ // the router (`AppShell` rendered as a page's own chrome: tests, plugin pages) it stays off, and a Mail shell owns its connection itself.
196
+ const inFrame = useInAppFrame();
197
+ const navigate = useNavigate();
198
+ const { pathname } = useRouter();
199
+ const mail = useMailConnection({ userUid, enabled: inFrame, open: navigate });
200
+ // A signing certificate the user asked for is announced when it is issued (or fails), on whichever page they are - see the hook.
201
+ useSigningEnrollmentWatcher({ userUid, mailboxes: mail.mailboxes, enabled: inFrame });
202
+ // A meeting reminder pops up on whichever page they are - see the hook.
203
+ useCalendarReminders({ userUid, enabled: inFrame });
204
+
205
+ useRedirectIfUnauthenticated(userUid, authServerUrl);
206
+ // Any request this app makes that the server answers with a 401 - the session ended - raises one "Your session expired" pop-up with a
207
+ // Sign in action (see `notifySessionExpired()`), whichever request noticed first, a background refresh included.
208
+ useEffect(() => {
209
+ setSignInUrl(authServerUrl);
210
+ if (!userUid) {
211
+ return;
212
+ }
213
+ setApiUnauthorizedObserver(() => void notifySessionExpired());
214
+ return () => setApiUnauthorizedObserver(undefined);
215
+ }, [userUid, authServerUrl]);
216
+ // Mounted here, not scoped to Mail/Settings (the only shells that actually read unlocked keys),
217
+ // specifically so activity in *any* app resets the idle clock - see that hook's own doc comment.
218
+ useIdleKeyTimeout();
219
+
220
+ // An administrator on a server that hasn't finished first-run setup is sent to the setup wizard. The status
221
+ // check is admin-only, so it's only made for a trusted caller - everyone else would just get a 403 on every
222
+ // page load. Any failure is ignored.
223
+ useEffect(() => {
224
+ if (!userUid || impersonating || !trusted) {
225
+ return;
226
+ }
227
+ getSetupStatus()
228
+ .then((status) => {
229
+ if (status.required) {
230
+ window.location.href = "/admin/setup";
231
+ }
232
+ })
233
+ .catch(() => undefined);
234
+ }, [userUid, impersonating, trusted]);
235
+
236
+ // Another tab signing out (this app's `handleSignOut`, or the admin/escrow consoles' `signOutOfConsole()`)
237
+ // ended this session too - its auth cookie is gone - so this tab destroys its own unlocked keys and every
238
+ // local search index on the device, then leaves as well. The consoles have no local-index client of their
239
+ // own, so this is what actually removes the indexes after a console sign-out (the console also records a
240
+ // pending deletion, retried on the next mail load, in case no mail tab is open). `destroyAllLocalIndexes()`
241
+ // announces the sign-out on this same channel, which this tab then hears itself, so the ref is set first:
242
+ // each tab reacts once, and the tab that started the sign-out ignores its own announcement.
243
+ useEffect(() => {
244
+ if (!userUid || typeof BroadcastChannel === "undefined") {
245
+ return;
246
+ }
247
+ const channel = new BroadcastChannel(SIGN_OUT_CHANNEL);
248
+ channel.addEventListener("message", (event: MessageEvent<{ type?: string }>) => {
249
+ if (event.data?.type !== "sign-out" || signingOutRef.current) {
250
+ return;
251
+ }
252
+ signingOutRef.current = true;
253
+ // Compose windows must not ask "Leave site?" - that would let this forced navigation be cancelled.
254
+ markSigningOut();
255
+ destroyUnlockedKeys();
256
+ clearPinnedSignerCache();
257
+ clearAppearanceCache();
258
+ // Bounded by its own timeout and never rejects - awaited so navigating doesn't kill the Worker mid-delete.
259
+ void destroyAllLocalIndexes().then(() => {
260
+ window.location.href = authServerUrl ?? "/";
261
+ });
262
+ });
263
+ return () => channel.close();
264
+ }, [userUid, authServerUrl]);
265
+
266
+ async function handleSignOut() {
267
+ signingOutRef.current = true;
268
+ // Before flushing and navigating: compose windows then skip their "Leave site?" prompt, which could
269
+ // otherwise cancel the sign-out's own navigation.
270
+ markSigningOut();
271
+ // Unlocked private keys never outlive an explicit sign-out.
272
+ destroyUnlockedKeys();
273
+ // Trusted signer pins read from contacts don't outlive the session either.
274
+ clearPinnedSignerCache();
275
+ clearAppearanceCache();
276
+ // Open compose windows save edits still waiting on their autosave debounce while the session is still
277
+ // valid - logout invalidates it. Bounded the same way as logout itself, and never rejects.
278
+ await flushComposeDrafts(LOGOUT_TIMEOUT_MS);
279
+ // The Tier 2 local index MUST be destroyed on explicit logout, the same as unlocked keys themselves
280
+ // (spec §11). Destroys every index on this device (not only mailboxes opened this page load) and is
281
+ // awaited before navigating - a navigation tears down the Worker mid-delete otherwise.
282
+ // destroyAllLocalIndexes() is bounded by its own timeout and never rejects, so sign-out can't hang.
283
+ // In parallel, auth-server's logout clears the auth cookie and invalidates the session's refresh
284
+ // token - without it, "Sign Out" would only navigate away from a still-valid session.
285
+ await Promise.all([destroyAllLocalIndexes(), logOutOfAuthServer(authServerUrl)]);
286
+ window.location.href = authServerUrl ?? "/";
287
+ }
288
+
289
+ async function handleStopImpersonating() {
290
+ setStoppingImpersonation(true);
291
+ try {
292
+ await stopImpersonating(impersonationBaseUrl ?? "");
293
+ } catch {
294
+ // Navigate either way: a failed call leaves the impersonator cookie (and this banner) exactly as
295
+ // they were, so there's nothing else useful to show — matching this app's other network-error
296
+ // handling, which surfaces via a full reload rather than an inline retry affordance.
297
+ } finally {
298
+ window.location.href = "/admin";
299
+ }
300
+ }
301
+
302
+ // The tab's title in the frame is each page's own (its `title` export: rendered by the server, set again by the router on every navigation),
303
+ // but `useBranding()` above sets it to the branding's title once its fetch answers - a title for a page that has none. The page's is put back:
304
+ // the layout effect reads it before that hook's effect runs, this one (declared after it) writes it back.
305
+ const pageTitleRef = useRef("");
306
+ useLayoutEffect(() => {
307
+ pageTitleRef.current = document.title;
308
+ }, [fetchedBranding?.title]);
309
+ useEffect(() => {
310
+ if (inFrame) {
311
+ document.title = pageTitleRef.current;
312
+ }
313
+ }, [fetchedBranding?.title, inFrame]);
314
+ // The router sets the document's title to the page's own whenever the page changes, which drops the unread count this puts in front
315
+ // of it, so a new pathname is what puts the count back. (A folder change is shallow and keeps the title.)
316
+ useUnreadTitle(inboxUnreadTotal(mail.mailboxFolders, mail.folderCounts.counts), { enabled: inFrame, resetKey: pathname });
317
+
318
+ if (!userUid) {
319
+ return <div className="min-h-screen" />;
320
+ }
321
+
322
+ const apps = appRailItems(pluginNav);
323
+ // The header title: "settings" has no rail item, everything else is labelled by its own rail item.
324
+ const activeLabel = active === "settings" ? "Settings" : apps.find((app) => app.id === active)?.label;
325
+ // A custom header (`Branding.headerHtml`) replaces the app's own title bar and the icon at the top of the rail: it is the top of the app, and the
326
+ // account menu moves into it. While it is still being parsed it already counts, so the frame's shape doesn't change under the user.
327
+ const customHeader = header !== null;
328
+ // Where the one account menu lives: the header's `{USER_MENU}`, else the footer's, else a small cell at the header's right end - never lost.
329
+ const menuInHeader = !!header?.hasUserMenu;
330
+ const menuInFooter = customHeader && !!header && !menuInHeader && !!footer?.hasUserMenu;
331
+ const renderUserMenu = (placement: "down" | "up") => (
332
+ <UserMenu
333
+ userUid={userUid}
334
+ authServerUrl={authServerUrl}
335
+ onSignOut={handleSignOut}
336
+ // An impersonating administrator acts as the impersonated user, so the console link is hidden then.
337
+ showAdminLink={!!trusted && !impersonating}
338
+ detectAdmin={!trusted && !impersonating}
339
+ trustedRoles={trustedRoles}
340
+ showSettingsLink
341
+ showNotificationSettings
342
+ onShowShortcuts={() => setShortcutsOpen(true)}
343
+ onShowNotifications={() => setHistoryOpen(true)}
344
+ unseenErrors={unseenErrors}
345
+ placement={placement}
346
+ />
347
+ );
348
+
349
+ return (
350
+ // Mounted here, not scoped to Mail/Settings, for the same reason as useIdleKeyTimeout() above -
351
+ // ComposeWindow's sign/encrypt toggles and MessageDetailPane's encrypted-message view (both Mail)
352
+ // are today's only useUnlockPrompt() callers, but this needs to be available to any app shell.
353
+ // Asks the server for the user's appearance only in the persistent frame (every core page); a page that renders its own chrome (a plugin's) uses the
354
+ // `appearance` it was given and what this browser cached.
355
+ <AppearanceProvider userUid={userUid} initial={appearance} lookUp={inFrame}>
356
+ <ShortcutProvider>
357
+ <MailConnectionContext.Provider value={inFrame ? mail : null}>
358
+ <GlobalShortcuts authServerUrl={authServerUrl} onToggleHelp={() => setShortcutsOpen((open) => !open)} />
359
+ <ShortcutsDialog open={shortcutsOpen} onClose={() => setShortcutsOpen(false)} />
360
+ <UnlockPromptProvider>
361
+ <UnlockBridge />
362
+ {/* An impersonating admin acts with the impersonated user's access, so their own trusted role
363
+ mustn't skip the per-mailbox checks. */}
364
+ <ComposeProvider userUid={userUid} trusted={!!trusted && !impersonating}>
365
+ <div className="rr-frame-bg min-h-screen flex flex-col">
366
+ {!hideChrome && customHeader && (
367
+ <FrameBrandingHeader
368
+ parsed={header}
369
+ userMenu={menuInHeader ? renderUserMenu("down") : undefined}
370
+ fallbackMenu={header && !menuInHeader && !menuInFooter ? renderUserMenu("down") : undefined}
371
+ appTitle={activeLabel}
372
+ />
373
+ )}
374
+ {impersonating && !hideChrome && (
375
+ <div className="h-10 shrink-0 bg-warning text-warning-contrast flex items-center justify-center gap-3 text-sm font-medium px-4">
376
+ <span>
377
+ You are viewing as <strong>{userUid}</strong>.
378
+ </span>
379
+ <button
380
+ type="button"
381
+ onClick={handleStopImpersonating}
382
+ disabled={stoppingImpersonation}
383
+ className="underline hover:no-underline disabled:opacity-60"
384
+ >
385
+ {stoppingImpersonation ? "Returning to admin…" : "Return to admin"}
386
+ </button>
387
+ </div>
388
+ )}
389
+ <div className="flex-1 flex min-h-0">
390
+ {!hideChrome && (
391
+ <nav
392
+ aria-label="Apps"
393
+ className={[
394
+ "hidden md:flex w-16 shrink-0 bg-surface border-r border-border flex-col items-center gap-1",
395
+ // Under a custom header the rail starts with the app icons; without one its own icon is flush with the top of the window.
396
+ customHeader ? "py-3" : "pb-3",
397
+ ].join(" ")}
398
+ >
399
+ {!customHeader && (
400
+ <RailIcon src={iconSrc} />
401
+ )}
402
+ {apps.map(({ id, href, label, icon: Icon }) => (
403
+ <a
404
+ key={id}
405
+ href={href}
406
+ aria-label={label}
407
+ aria-current={id === active ? "page" : undefined}
408
+ title={label}
409
+ className={[
410
+ "w-10 h-10 flex items-center justify-center rounded-sm",
411
+ id === active
412
+ ? "bg-primary/10 text-primary-dark"
413
+ : "text-text-muted hover:bg-surface-alt hover:text-text",
414
+ ].join(" ")}
415
+ >
416
+ <Icon size={20} aria-hidden="true" />
417
+ </a>
418
+ ))}
419
+ </nav>
420
+ )}
421
+ {!hideChrome && <BottomTabBar apps={apps} active={active} />}
422
+ <div className="flex-1 flex flex-col min-w-0">
423
+ {!hideChrome && !customHeader && (
424
+ <header ref={headerRef} className="rr-solid sticky top-0 z-30 h-16 shrink-0 bg-surface border-b border-border flex items-center justify-between gap-4 px-6">
425
+ <span className="font-display font-bold text-lg uppercase tracking-wide">{activeLabel}</span>
426
+ {renderUserMenu("down")}
427
+ </header>
428
+ )}
429
+ {/* The one pop-up stack for the whole app: right under the header row, so it never covers the account menu. */}
430
+ <NotificationCenter />
431
+ <div
432
+ id="app-content"
433
+ tabIndex={-1}
434
+ aria-busy={busy || undefined}
435
+ className={["flex-1 flex min-h-0 outline-none", hideChrome ? "" : "pb-14 md:pb-0"].join(" ")}
436
+ >
437
+ {children}
438
+ </div>
439
+ </div>
440
+ </div>
441
+ {!hideChrome && <FrameBrandingFooter parsed={footer} userMenu={menuInFooter ? renderUserMenu("up") : undefined} appTitle={activeLabel} />}
442
+ </div>
443
+ </ComposeProvider>
444
+ </UnlockPromptProvider>
445
+ <NotificationHistoryDialog open={historyOpen} onClose={() => setHistoryOpen(false)} />
446
+ </MailConnectionContext.Provider>
447
+ </ShortcutProvider>
448
+ </AppearanceProvider>
449
+ );
450
+ }
451
+
452
+ /**
453
+ * What a page's own shell (`MailShell`, `CalendarShell`, ...) renders around its content. Outside the client-side router it
454
+ * is the whole `AppChrome`, as it always was. Inside it (the router's app shell, `apps/www/_shell.tsx`) the chrome is already mounted above the
455
+ * page - and stays mounted as the page is replaced - so this is only its children; everything it would have been given comes from
456
+ * the shell instead (the props are the same for every page, and `active` is the route's).
457
+ */
458
+ export default function AppShell(props: PropsWithChildren<AppShellProps>) {
459
+ const inFrame = useInAppFrame();
460
+ return inFrame ? <>{props.children}</> : <AppChrome {...props} />;
461
+ }