@rapidmx/web-client 0.8.0 → 0.10.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 (247) hide show
  1. package/README.md +192 -88
  2. package/apps/shared/auth/accountUrl.ts +9 -0
  3. package/apps/shared/auth/adminAccess.ts +99 -0
  4. package/apps/shared/components/admin/elevation.ts +61 -0
  5. package/apps/shared/components/admin/layout/AdminShell.tsx +73 -7
  6. package/apps/shared/components/admin/settings/BrandingForm.tsx +2 -1
  7. package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +87 -24
  8. package/apps/shared/components/calendar/layout/CalendarShell.tsx +8 -2
  9. package/apps/shared/components/contacts/ContactsToolbar.tsx +125 -115
  10. package/apps/shared/components/contacts/layout/ContactsShell.tsx +15 -3
  11. package/apps/shared/components/layout/AppShell.tsx +411 -288
  12. package/apps/shared/components/layout/BrandingChrome.tsx +3 -2
  13. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -389
  14. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -126
  15. package/apps/shared/components/layout/UserMenu.tsx +303 -150
  16. package/apps/shared/components/mail/ConversationList.tsx +269 -253
  17. package/apps/shared/components/mail/ConversationThreadPane.tsx +475 -434
  18. package/apps/shared/components/mail/LazyReadingPane.tsx +115 -0
  19. package/apps/shared/components/mail/MailAddress.tsx +88 -0
  20. package/apps/shared/components/mail/MailSelectionBar.tsx +235 -222
  21. package/apps/shared/components/mail/MessageDetailPane.tsx +1458 -1383
  22. package/apps/shared/components/mail/NewMailToasts.tsx +141 -0
  23. package/apps/shared/components/mail/compose/ComposeContext.tsx +279 -160
  24. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -418
  25. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1842 -1700
  26. package/apps/shared/components/mail/compose/ComposeWindowPlaceholder.tsx +111 -0
  27. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -118
  28. package/apps/shared/components/mail/compose/SendFailureAlert.tsx +48 -0
  29. package/apps/shared/components/mail/compose/composePerf.ts +46 -0
  30. package/apps/shared/components/mail/compose/quotedBody.ts +161 -100
  31. package/apps/shared/components/mail/layout/MailShell.tsx +476 -445
  32. package/apps/shared/components/mail/unreadStyle.tsx +75 -0
  33. package/apps/shared/components/settings/layout/SettingsShell.tsx +252 -240
  34. package/apps/shared/components/tasks/layout/TasksShell.tsx +15 -3
  35. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -0
  36. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -0
  37. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -0
  38. package/apps/shared/keyboard/dispatch.ts +124 -0
  39. package/apps/shared/keyboard/format.ts +89 -0
  40. package/apps/shared/keyboard/keymap.ts +114 -0
  41. package/apps/shared/keyboard/match.ts +44 -0
  42. package/apps/shared/keyboard/parse.ts +136 -0
  43. package/apps/shared/keyboard/platform.ts +34 -0
  44. package/apps/shared/keyboard/registry.ts +65 -0
  45. package/apps/shared/keyboard/targets.ts +79 -0
  46. package/apps/shared/keyboard/useShortcut.ts +50 -0
  47. package/apps/shared/keyboard/useShortcutProps.ts +17 -0
  48. package/apps/shared/mail/folderCounts.ts +302 -0
  49. package/apps/shared/mail/listSnapshots.ts +87 -0
  50. package/apps/shared/mail/mergeFirstPage.ts +47 -0
  51. package/apps/shared/mail/messageReadState.ts +85 -0
  52. package/apps/shared/mail/newMailNotifications.ts +183 -0
  53. package/apps/shared/mail/useMailConnection.ts +150 -0
  54. package/apps/shared/mail/useMailLiveUpdates.ts +232 -0
  55. package/apps/shared/mail/useMarkMessageRead.ts +47 -0
  56. package/apps/shared/mail/useNewMailNotifications.ts +163 -0
  57. package/apps/shared/mail/useUnreadTitle.ts +42 -0
  58. package/apps/shared/navigation/AppRouter.tsx +300 -0
  59. package/apps/shared/navigation/appHrefs.ts +23 -0
  60. package/apps/shared/navigation/frameContext.tsx +35 -0
  61. package/apps/shared/navigation/idle.ts +45 -0
  62. package/apps/shared/navigation/routerContext.tsx +83 -0
  63. package/apps/shared/navigation/routes.ts +72 -0
  64. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -98
  65. package/apps/shared/styles/app.css +28 -10
  66. package/apps/www/_routedPage.tsx +24 -0
  67. package/apps/www/_routes.ts +35 -0
  68. package/apps/www/calendar/index.tsx +55 -19
  69. package/apps/www/contacts/[uid].tsx +112 -107
  70. package/apps/www/contacts/index.tsx +584 -567
  71. package/apps/www/index.tsx +2280 -1854
  72. package/apps/www/messages/[uid].tsx +106 -101
  73. package/apps/www/settings/auto-reply/index.tsx +4 -1
  74. package/apps/www/settings/encryption/index.tsx +1252 -1249
  75. package/apps/www/settings/filters/[uid].tsx +4 -1
  76. package/apps/www/settings/filters/index.tsx +102 -99
  77. package/apps/www/settings/filters/new/index.tsx +138 -133
  78. package/apps/www/settings/labels/index.tsx +204 -201
  79. package/apps/www/settings/privacy/index.tsx +4 -1
  80. package/apps/www/settings/read-receipts/index.tsx +4 -1
  81. package/apps/www/settings/sharing/index.tsx +277 -274
  82. package/apps/www/settings/signatures/[uid].tsx +170 -167
  83. package/apps/www/settings/signatures/index.tsx +88 -85
  84. package/apps/www/settings/signatures/new/index.tsx +134 -129
  85. package/apps/www/tasks/index.tsx +18 -2
  86. package/dist/apps/shared/auth/accountUrl.d.ts +2 -0
  87. package/dist/apps/shared/auth/accountUrl.js +8 -0
  88. package/dist/apps/shared/auth/adminAccess.d.ts +30 -0
  89. package/dist/apps/shared/auth/adminAccess.js +89 -0
  90. package/dist/apps/shared/components/admin/elevation.d.ts +24 -0
  91. package/dist/apps/shared/components/admin/elevation.js +56 -0
  92. package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +12 -4
  93. package/dist/apps/shared/components/admin/layout/AdminShell.js +49 -6
  94. package/dist/apps/shared/components/admin/settings/BrandingForm.js +1 -1
  95. package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +31 -13
  96. package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +1 -1
  97. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +8 -4
  98. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
  99. package/dist/apps/shared/components/contacts/ContactsToolbar.js +7 -4
  100. package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +1 -1
  101. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +15 -5
  102. package/dist/apps/shared/components/layout/AppShell.d.ts +29 -4
  103. package/dist/apps/shared/components/layout/AppShell.js +73 -14
  104. package/dist/apps/shared/components/layout/BrandingChrome.d.ts +3 -2
  105. package/dist/apps/shared/components/layout/BrandingChrome.js +3 -2
  106. package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +10 -9
  107. package/dist/apps/shared/components/layout/MailboxProvisioning.d.ts +5 -2
  108. package/dist/apps/shared/components/layout/MailboxProvisioning.js +45 -8
  109. package/dist/apps/shared/components/layout/UserMenu.d.ts +28 -9
  110. package/dist/apps/shared/components/layout/UserMenu.js +87 -14
  111. package/dist/apps/shared/components/mail/ConversationList.js +9 -13
  112. package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +4 -1
  113. package/dist/apps/shared/components/mail/ConversationThreadPane.js +53 -28
  114. package/dist/apps/shared/components/mail/LazyReadingPane.d.ts +9 -0
  115. package/dist/apps/shared/components/mail/LazyReadingPane.js +82 -0
  116. package/dist/apps/shared/components/mail/MailAddress.d.ts +27 -0
  117. package/dist/apps/shared/components/mail/MailAddress.js +39 -0
  118. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +4 -1
  119. package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -3
  120. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +7 -1
  121. package/dist/apps/shared/components/mail/MessageDetailPane.js +87 -36
  122. package/dist/apps/shared/components/mail/NewMailToasts.d.ts +19 -0
  123. package/dist/apps/shared/components/mail/NewMailToasts.js +55 -0
  124. package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +30 -0
  125. package/dist/apps/shared/components/mail/compose/ComposeContext.js +71 -5
  126. package/dist/apps/shared/components/mail/compose/ComposeToolbar.js +4 -3
  127. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +1 -1
  128. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +122 -27
  129. package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.d.ts +19 -0
  130. package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.js +33 -0
  131. package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +9 -1
  132. package/dist/apps/shared/components/mail/compose/RichTextEditor.js +20 -2
  133. package/dist/apps/shared/components/mail/compose/SendFailureAlert.d.ts +14 -0
  134. package/dist/apps/shared/components/mail/compose/SendFailureAlert.js +11 -0
  135. package/dist/apps/shared/components/mail/compose/composePerf.d.ts +16 -0
  136. package/dist/apps/shared/components/mail/compose/composePerf.js +41 -0
  137. package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +13 -0
  138. package/dist/apps/shared/components/mail/compose/quotedBody.js +67 -11
  139. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +19 -4
  140. package/dist/apps/shared/components/mail/layout/MailShell.js +85 -85
  141. package/dist/apps/shared/components/mail/unreadStyle.d.ts +45 -0
  142. package/dist/apps/shared/components/mail/unreadStyle.js +61 -0
  143. package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +1 -1
  144. package/dist/apps/shared/components/settings/layout/SettingsShell.js +15 -5
  145. package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +1 -1
  146. package/dist/apps/shared/components/tasks/layout/TasksShell.js +15 -5
  147. package/dist/apps/shared/keyboard/GlobalShortcuts.d.ts +14 -0
  148. package/dist/apps/shared/keyboard/GlobalShortcuts.js +37 -0
  149. package/dist/apps/shared/keyboard/ShortcutProvider.d.ts +20 -0
  150. package/dist/apps/shared/keyboard/ShortcutProvider.js +52 -0
  151. package/dist/apps/shared/keyboard/ShortcutsDialog.d.ts +14 -0
  152. package/dist/apps/shared/keyboard/ShortcutsDialog.js +42 -0
  153. package/dist/apps/shared/keyboard/dispatch.d.ts +16 -0
  154. package/dist/apps/shared/keyboard/dispatch.js +109 -0
  155. package/dist/apps/shared/keyboard/format.d.ts +12 -0
  156. package/dist/apps/shared/keyboard/format.js +74 -0
  157. package/dist/apps/shared/keyboard/keymap.d.ts +294 -0
  158. package/dist/apps/shared/keyboard/keymap.js +84 -0
  159. package/dist/apps/shared/keyboard/match.d.ts +20 -0
  160. package/dist/apps/shared/keyboard/match.js +31 -0
  161. package/dist/apps/shared/keyboard/parse.d.ts +31 -0
  162. package/dist/apps/shared/keyboard/parse.js +107 -0
  163. package/dist/apps/shared/keyboard/platform.d.ts +15 -0
  164. package/dist/apps/shared/keyboard/platform.js +22 -0
  165. package/dist/apps/shared/keyboard/registry.d.ts +39 -0
  166. package/dist/apps/shared/keyboard/registry.js +33 -0
  167. package/dist/apps/shared/keyboard/targets.d.ts +14 -0
  168. package/dist/apps/shared/keyboard/targets.js +67 -0
  169. package/dist/apps/shared/keyboard/useShortcut.d.ts +19 -0
  170. package/dist/apps/shared/keyboard/useShortcut.js +35 -0
  171. package/dist/apps/shared/keyboard/useShortcutProps.d.ts +10 -0
  172. package/dist/apps/shared/keyboard/useShortcutProps.js +15 -0
  173. package/dist/apps/shared/mail/folderCounts.d.ts +78 -0
  174. package/dist/apps/shared/mail/folderCounts.js +212 -0
  175. package/dist/apps/shared/mail/listSnapshots.d.ts +46 -0
  176. package/dist/apps/shared/mail/listSnapshots.js +43 -0
  177. package/dist/apps/shared/mail/mergeFirstPage.d.ts +23 -0
  178. package/dist/apps/shared/mail/mergeFirstPage.js +30 -0
  179. package/dist/apps/shared/mail/messageReadState.d.ts +32 -0
  180. package/dist/apps/shared/mail/messageReadState.js +63 -0
  181. package/dist/apps/shared/mail/newMailNotifications.d.ts +62 -0
  182. package/dist/apps/shared/mail/newMailNotifications.js +138 -0
  183. package/dist/apps/shared/mail/useMailConnection.d.ts +55 -0
  184. package/dist/apps/shared/mail/useMailConnection.js +96 -0
  185. package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +55 -0
  186. package/dist/apps/shared/mail/useMailLiveUpdates.js +182 -0
  187. package/dist/apps/shared/mail/useMarkMessageRead.d.ts +12 -0
  188. package/dist/apps/shared/mail/useMarkMessageRead.js +44 -0
  189. package/dist/apps/shared/mail/useNewMailNotifications.d.ts +41 -0
  190. package/dist/apps/shared/mail/useNewMailNotifications.js +110 -0
  191. package/dist/apps/shared/mail/useUnreadTitle.d.ts +18 -0
  192. package/dist/apps/shared/mail/useUnreadTitle.js +31 -0
  193. package/dist/apps/shared/navigation/AppRouter.d.ts +52 -0
  194. package/dist/apps/shared/navigation/AppRouter.js +242 -0
  195. package/dist/apps/shared/navigation/appHrefs.d.ts +14 -0
  196. package/dist/apps/shared/navigation/appHrefs.js +20 -0
  197. package/dist/apps/shared/navigation/frameContext.d.ts +19 -0
  198. package/dist/apps/shared/navigation/frameContext.js +24 -0
  199. package/dist/apps/shared/navigation/idle.d.ts +14 -0
  200. package/dist/apps/shared/navigation/idle.js +43 -0
  201. package/dist/apps/shared/navigation/routerContext.d.ts +37 -0
  202. package/dist/apps/shared/navigation/routerContext.js +56 -0
  203. package/dist/apps/shared/navigation/routes.d.ts +32 -0
  204. package/dist/apps/shared/navigation/routes.js +37 -0
  205. package/dist/apps/shared/search/LocalIndexLifecycle.js +17 -3
  206. package/dist/apps/shared/styles/app.css +28 -10
  207. package/dist/apps/www/_routedPage.d.ts +12 -0
  208. package/dist/apps/www/_routedPage.js +19 -0
  209. package/dist/apps/www/_routes.d.ts +11 -0
  210. package/dist/apps/www/_routes.js +29 -0
  211. package/dist/apps/www/calendar/index.d.ts +2 -2
  212. package/dist/apps/www/calendar/index.js +39 -8
  213. package/dist/apps/www/contacts/[uid].d.ts +3 -9
  214. package/dist/apps/www/contacts/[uid].js +6 -2
  215. package/dist/apps/www/contacts/index.d.ts +2 -2
  216. package/dist/apps/www/contacts/index.js +17 -4
  217. package/dist/apps/www/index.d.ts +2 -2
  218. package/dist/apps/www/index.js +361 -34
  219. package/dist/apps/www/messages/[uid].d.ts +3 -7
  220. package/dist/apps/www/messages/[uid].js +7 -4
  221. package/dist/apps/www/settings/auto-reply/index.d.ts +2 -2
  222. package/dist/apps/www/settings/auto-reply/index.js +3 -1
  223. package/dist/apps/www/settings/encryption/index.d.ts +2 -2
  224. package/dist/apps/www/settings/encryption/index.js +3 -1
  225. package/dist/apps/www/settings/filters/[uid].d.ts +2 -2
  226. package/dist/apps/www/settings/filters/[uid].js +3 -1
  227. package/dist/apps/www/settings/filters/index.d.ts +2 -2
  228. package/dist/apps/www/settings/filters/index.js +3 -1
  229. package/dist/apps/www/settings/filters/new/index.d.ts +2 -2
  230. package/dist/apps/www/settings/filters/new/index.js +6 -2
  231. package/dist/apps/www/settings/labels/index.d.ts +2 -2
  232. package/dist/apps/www/settings/labels/index.js +3 -1
  233. package/dist/apps/www/settings/privacy/index.d.ts +2 -2
  234. package/dist/apps/www/settings/privacy/index.js +3 -1
  235. package/dist/apps/www/settings/read-receipts/index.d.ts +2 -2
  236. package/dist/apps/www/settings/read-receipts/index.js +3 -1
  237. package/dist/apps/www/settings/sharing/index.d.ts +2 -2
  238. package/dist/apps/www/settings/sharing/index.js +3 -1
  239. package/dist/apps/www/settings/signatures/[uid].d.ts +2 -2
  240. package/dist/apps/www/settings/signatures/[uid].js +3 -1
  241. package/dist/apps/www/settings/signatures/index.d.ts +2 -2
  242. package/dist/apps/www/settings/signatures/index.js +3 -1
  243. package/dist/apps/www/settings/signatures/new/index.d.ts +2 -2
  244. package/dist/apps/www/settings/signatures/new/index.js +6 -2
  245. package/dist/apps/www/tasks/index.d.ts +2 -2
  246. package/dist/apps/www/tasks/index.js +15 -3
  247. package/package.json +2 -2
@@ -10,6 +10,7 @@ import { Folder, Mailbox, listFolders, listMailboxes } from "@rapidmx/react-shar
10
10
  import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
11
11
  import Skeleton, { SkeletonList } from "@rapidmx/react-shared/components/feedback/Skeleton.js";
12
12
  import AppShell, { AppShellProps } from "../../layout/AppShell.js";
13
+ import { useLocationSearch, useNavigate } from "../../../navigation/AppRouter.js";
13
14
  import MailboxProvisioning from "../../layout/MailboxProvisioning.js";
14
15
 
15
16
  export type TasksShellProps = Omit<AppShellProps, "active">;
@@ -47,6 +48,7 @@ export default function TasksShell({
47
48
  impersonating,
48
49
  impersonationBaseUrl,
49
50
  trusted,
51
+ trustedRoles,
50
52
  pluginNav,
51
53
  children,
52
54
  }: PropsWithChildren<TasksShellProps>) {
@@ -58,9 +60,18 @@ export default function TasksShell({
58
60
  const [requestedMailboxUid, setRequestedMailboxUid] = useState<string | null>(null);
59
61
  const [drawerOpen, setDrawerOpen] = useState(false);
60
62
 
63
+ // Read from the router's location, so a mailbox change (a link, or `navigate()`) takes effect without a page load - and in an
64
+ // effect, not during render, so the server render and the hydrating render agree.
65
+ const search = useLocationSearch();
66
+ const navigate = useNavigate();
61
67
  useEffect(() => {
62
- setRequestedMailboxUid(new URLSearchParams(window.location.search).get("mailboxUid"));
63
- }, []);
68
+ setRequestedMailboxUid(new URLSearchParams(search).get("mailboxUid"));
69
+ }, [search]);
70
+ // Choosing a folder (or mailbox) changes the URL without a page load now, so the drawer that held the choice - which used to go
71
+ // with the page - is closed here.
72
+ useEffect(() => {
73
+ setDrawerOpen(false);
74
+ }, [search]);
64
75
 
65
76
  useEffect(() => {
66
77
  if (!userUid) {
@@ -144,7 +155,7 @@ export default function TasksShell({
144
155
  className="w-full text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
145
156
  value={mailboxUid}
146
157
  onChange={(e) => {
147
- window.location.href = `/tasks?mailboxUid=${encodeURIComponent(e.target.value)}`;
158
+ navigate(`/tasks?mailboxUid=${encodeURIComponent(e.target.value)}`);
148
159
  }}
149
160
  >
150
161
  {mailboxes.map((mb) => (
@@ -193,6 +204,7 @@ export default function TasksShell({
193
204
  impersonating={impersonating}
194
205
  impersonationBaseUrl={impersonationBaseUrl}
195
206
  trusted={trusted}
207
+ trustedRoles={trustedRoles}
196
208
  pluginNav={pluginNav}
197
209
  >
198
210
  {inner}
@@ -0,0 +1,51 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { accountUrlOf } from "../auth/accountUrl.js";
6
+ import { APP_HREFS, SETTINGS_HREF, isSettingsPath } from "../navigation/appHrefs.js";
7
+ import { useNavigate } from "../navigation/routerContext.js";
8
+ import { SHORTCUTS } from "./keymap.js";
9
+ import { useShortcut } from "./useShortcut.js";
10
+
11
+ export interface GlobalShortcutsProps {
12
+ /** auth-server's base URL - "Go to Account" is offered only when it is set. */
13
+ authServerUrl?: string;
14
+ /** Opens the keyboard shortcuts dialog, or closes it if it is open. */
15
+ onToggleHelp: () => void;
16
+ }
17
+
18
+ /**
19
+ * The shortcuts that work in every view: the "Go to ..." navigation set and the keyboard help. Mounted once by `AppChrome`, next to the
20
+ * `ShortcutProvider`, so it works from Settings and every app alike. Renders nothing.
21
+ *
22
+ * In-app places go through the client-side router (`useNavigate()`); Account is another origin, so it is a plain navigation. Asking for the
23
+ * page you are already on does nothing - but the key is still taken, so the browser doesn't act on it either.
24
+ */
25
+ export function GlobalShortcuts({ authServerUrl, onToggleHelp }: GlobalShortcutsProps) {
26
+ const navigate = useNavigate();
27
+ const accountUrl = accountUrlOf(authServerUrl);
28
+
29
+ /** A handler that goes to `href` unless the address bar's path says it is already there. */
30
+ const goTo = (href: string, isHere: (pathname: string) => boolean) => () => {
31
+ if (!isHere(window.location.pathname)) {
32
+ navigate(href);
33
+ }
34
+ };
35
+ const isPath = (path: string) => (pathname: string) => pathname === path;
36
+
37
+ useShortcut(SHORTCUTS.global.mail, goTo(APP_HREFS.mail, isPath(APP_HREFS.mail)));
38
+ useShortcut(SHORTCUTS.global.calendar, goTo(APP_HREFS.calendar, isPath(APP_HREFS.calendar)));
39
+ useShortcut(SHORTCUTS.global.contacts, goTo(APP_HREFS.contacts, isPath(APP_HREFS.contacts)));
40
+ useShortcut(SHORTCUTS.global.tasks, goTo(APP_HREFS.tasks, isPath(APP_HREFS.tasks)));
41
+ useShortcut(SHORTCUTS.global.settings, goTo(SETTINGS_HREF, isSettingsPath));
42
+ useShortcut(
43
+ SHORTCUTS.global.account,
44
+ () => {
45
+ window.location.href = accountUrl!;
46
+ },
47
+ { enabled: !!accountUrl },
48
+ );
49
+ useShortcut(SHORTCUTS.global.help, onToggleHelp);
50
+ return null;
51
+ }
@@ -0,0 +1,62 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { PropsWithChildren, createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore } from "react";
6
+ import { dispatchKeyEvent } from "./dispatch.js";
7
+ import { KeyEnvironment, SERVER_ENVIRONMENT, currentEnvironment } from "./platform.js";
8
+ import { Registration, ShortcutRegistry } from "./registry.js";
9
+
10
+ interface ShortcutContextValue {
11
+ registry: ShortcutRegistry;
12
+ env: KeyEnvironment;
13
+ }
14
+
15
+ const ShortcutContext = createContext<ShortcutContextValue | null>(null);
16
+
17
+ /**
18
+ * The web client's one keyboard layer. Mounted once, by `AppChrome` (the frame that stays mounted as the router swaps pages), so shortcuts
19
+ * work in every view - mail, calendar, contacts, tasks, settings - and a page change only changes which handlers are registered.
20
+ *
21
+ * One `keydown` listener on `document` (bubbling, so what a widget handles itself and `preventDefault()`s is left alone) hands each key to
22
+ * `dispatchKeyEvent()`. Views claim keys with `useShortcut()`. Outside a provider - an admin page, a component rendered on its own - that
23
+ * hook does nothing.
24
+ *
25
+ * The platform (macOS, the desktop client) is read after mount, never during render, so the server render and hydration agree.
26
+ */
27
+ export function ShortcutProvider({ children }: PropsWithChildren) {
28
+ const registry = useMemo(() => new ShortcutRegistry(), []);
29
+ const [env, setEnv] = useState<KeyEnvironment>(SERVER_ENVIRONMENT);
30
+ useEffect(() => {
31
+ setEnv(currentEnvironment());
32
+ }, []);
33
+ useEffect(() => {
34
+ function handleKeyDown(event: KeyboardEvent) {
35
+ dispatchKeyEvent(registry, event, currentEnvironment(), document);
36
+ }
37
+ document.addEventListener("keydown", handleKeyDown);
38
+ return () => document.removeEventListener("keydown", handleKeyDown);
39
+ }, [registry]);
40
+ const value = useMemo(() => ({ registry, env }), [registry, env]);
41
+ return <ShortcutContext.Provider value={value}>{children}</ShortcutContext.Provider>;
42
+ }
43
+
44
+ /** The registry, or `null` outside a `ShortcutProvider`. */
45
+ export function useShortcutRegistry(): ShortcutRegistry | null {
46
+ return useContext(ShortcutContext)?.registry ?? null;
47
+ }
48
+
49
+ /** The platform as the keyboard layer sees it - `SERVER_ENVIRONMENT` until the client has mounted, and outside a provider. */
50
+ export function useKeyEnvironment(): KeyEnvironment {
51
+ return useContext(ShortcutContext)?.env ?? SERVER_ENVIRONMENT;
52
+ }
53
+
54
+ const NO_REGISTRATIONS: readonly Registration[] = [];
55
+ const getNoRegistrations = () => NO_REGISTRATIONS;
56
+ const NEVER = () => () => undefined;
57
+
58
+ /** Everything registered right now, updating as views mount and unmount - what the help dialog lists. Empty outside a provider. */
59
+ export function useRegisteredShortcuts(): readonly Registration[] {
60
+ const registry = useShortcutRegistry();
61
+ return useSyncExternalStore(registry?.subscribe ?? NEVER, registry?.getSnapshot ?? getNoRegistrations, getNoRegistrations);
62
+ }
@@ -0,0 +1,84 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React from "react";
6
+ import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
7
+ import { formatSpec, specsFor } from "./format.js";
8
+ import { HELP_SCOPES, SCOPE_LABELS, SHORTCUTS, ShortcutDef, shortcutRank } from "./keymap.js";
9
+ import { useKeyEnvironment, useRegisteredShortcuts } from "./ShortcutProvider.js";
10
+ import { useShortcut } from "./useShortcut.js";
11
+
12
+ export interface ShortcutsDialogProps {
13
+ open: boolean;
14
+ onClose: () => void;
15
+ }
16
+
17
+ function Keys({ shortcut }: { shortcut: ShortcutDef }) {
18
+ const env = useKeyEnvironment();
19
+ return (
20
+ <span className="flex flex-wrap justify-end gap-x-1.5 gap-y-1 shrink-0">
21
+ {specsFor(shortcut, env).map((spec, index) => (
22
+ <React.Fragment key={spec}>
23
+ {index > 0 && <span className="text-xs text-text-muted self-center">or</span>}
24
+ <kbd className="px-1.5 py-0.5 rounded-sm border border-border bg-surface-alt text-xs font-sans font-semibold whitespace-nowrap">
25
+ {formatSpec(spec, env)}
26
+ </kbd>
27
+ </React.Fragment>
28
+ ))}
29
+ </span>
30
+ );
31
+ }
32
+
33
+ /**
34
+ * The keyboard shortcuts help dialog: what can be done from the keyboard *here*. It lists what is registered right now (see
35
+ * `useRegisteredShortcuts()`), so it shows the global shortcuts and those of the view that is on screen - and the compose window's while one
36
+ * is open - in groups, with the platform's own key names (Ctrl or Cmd, Alt or Option), and in the desktop client also the keys only it has.
37
+ * A shortcut a view cannot do at the moment (no message selected) is not registered, and so not listed.
38
+ *
39
+ * Built on `Modal`: focus moves into the dialog and stays there, Escape closes it, and it has an accessible name. `?` and Ctrl+/ close it too.
40
+ */
41
+ export default function ShortcutsDialog({ open, onClose }: ShortcutsDialogProps) {
42
+ // Mounted only while open: the body subscribes to the registry, which every view's shortcuts change as it mounts - not something the
43
+ // whole app should re-render for while the dialog is closed.
44
+ return open ? <ShortcutsDialogBody onClose={onClose} /> : null;
45
+ }
46
+
47
+ function ShortcutsDialogBody({ onClose }: { onClose: () => void }) {
48
+ const registrations = useRegisteredShortcuts();
49
+ useShortcut(SHORTCUTS.global.help, onClose, { scope: "dialog" });
50
+ const groups = HELP_SCOPES.map((scope) => {
51
+ const listed = new Map<string, ShortcutDef>();
52
+ for (const registration of registrations) {
53
+ if (registration.scope === scope) {
54
+ listed.set(registration.shortcut.id, registration.shortcut);
55
+ }
56
+ }
57
+ return { scope, shortcuts: [...listed.values()].sort((a, b) => shortcutRank(a) - shortcutRank(b)) };
58
+ }).filter((group) => group.shortcuts.length > 0);
59
+
60
+ return (
61
+ <Modal open onClose={onClose} title="Keyboard shortcuts">
62
+ <div className="flex flex-col gap-5">
63
+ {groups.map(({ scope, shortcuts }) => (
64
+ <section key={scope} aria-labelledby={`shortcuts-${scope}`}>
65
+ <h3 id={`shortcuts-${scope}`} className="text-xs font-bold uppercase tracking-wide text-text-muted mb-2">
66
+ {SCOPE_LABELS[scope]}
67
+ </h3>
68
+ <ul className="flex flex-col gap-1.5">
69
+ {shortcuts.map((shortcut) => (
70
+ <li key={shortcut.id} className="flex items-start justify-between gap-4 text-sm">
71
+ <span>{shortcut.label}</span>
72
+ <Keys shortcut={shortcut} />
73
+ </li>
74
+ ))}
75
+ </ul>
76
+ </section>
77
+ ))}
78
+ <p className="text-xs text-text-muted border-t border-border pt-3">
79
+ Some browsers keep a few keys for themselves, so a shortcut may not work everywhere.
80
+ </p>
81
+ </div>
82
+ </Modal>
83
+ );
84
+ }
@@ -0,0 +1,124 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import type { ShortcutScope } from "./keymap.js";
6
+ import { matchesEvent } from "./match.js";
7
+ import { ParsedSpec, resolveModifiers } from "./parse.js";
8
+ import type { KeyEnvironment } from "./platform.js";
9
+ import type { Registration, ShortcutRegistry } from "./registry.js";
10
+ import { isActivatable, isInPopoverDialog, isInWidget, isModalOpen, isPopupOpenAt, isTextEntry, regionScopeOf } from "./targets.js";
11
+
12
+ /** The keys of the four view scopes: only the mounted view has registrations, so precedence among them is moot. */
13
+ const VIEW_SCOPES: readonly ShortcutScope[] = ["mail", "calendar", "contacts", "tasks"];
14
+
15
+ /** Keys that move the caret or delete text, which a text field owns even with Ctrl or Alt held (word jumps, delete-word). */
16
+ const EDITING_KEYS = new Set(["arrowup", "arrowdown", "arrowleft", "arrowright", "home", "end", "pageup", "pagedown", "backspace", "delete"]);
17
+
18
+ /** The Copy / Cut / Paste / Select all / Undo / Redo / Find chords: never a shortcut, anywhere - they act on the page's selection, not on a view. */
19
+ function isReservedChord(parsed: ParsedSpec, env: KeyEnvironment): boolean {
20
+ const modifiers = resolveModifiers(parsed, env);
21
+ return (modifiers.ctrl || modifiers.meta) && !modifiers.alt && !modifiers.shift && ["a", "c", "v", "x", "z", "y", "f"].includes(parsed.key);
22
+ }
23
+
24
+ /** Paste as plain text (Ctrl+Shift+V) and Redo (Ctrl+Shift+Z): text-editing chords in a field, free everywhere else (Ctrl+Shift+V is Move to). */
25
+ function isShiftedEditingChord(parsed: ParsedSpec, env: KeyEnvironment): boolean {
26
+ const modifiers = resolveModifiers(parsed, env);
27
+ return (modifiers.ctrl || modifiers.meta) && !modifiers.alt && modifiers.shift && ["z", "v"].includes(parsed.key);
28
+ }
29
+
30
+ /**
31
+ * Whether `parsed` may fire with the event on this target.
32
+ *
33
+ * A text field (input, textarea, select, contenteditable - the rich-text editor) keeps everything that types or edits: bare keys
34
+ * (`j`, `?`, Delete), the caret keys with any modifier, and paste-as-plain-text and redo. A chord with Ctrl/Cmd/Alt works from one (that is how Ctrl+Enter sends from
35
+ * the body), except that Option on a Mac and Ctrl+Alt (AltGr) elsewhere type characters, so those don't. Escape works from a field unless a
36
+ * popup it owns is open (or it is in a popover dialog of its own). Outside a field, a bare key still isn't taken from a widget that reads keys itself (an open menu, a list box), and
37
+ * Enter/Space are left to the button or link that has the focus - unless the shortcut asked for them.
38
+ */
39
+ function allowedOnTarget(registration: Registration, parsed: ParsedSpec, target: EventTarget | null, env: KeyEnvironment): boolean {
40
+ const modifiers = resolveModifiers(parsed, env);
41
+ const command = modifiers.ctrl || modifiers.meta || modifiers.alt;
42
+ if (parsed.key === "escape" && (isPopupOpenAt(target) || isInPopoverDialog(target))) {
43
+ return false;
44
+ }
45
+ if (isTextEntry(target)) {
46
+ if (parsed.key === "escape") {
47
+ return true;
48
+ }
49
+ if (!command || EDITING_KEYS.has(parsed.key) || isShiftedEditingChord(parsed, env)) {
50
+ return false;
51
+ }
52
+ return !(modifiers.alt && !modifiers.meta && (env.mac || modifiers.ctrl));
53
+ }
54
+ if (!command) {
55
+ if (isInWidget(target)) {
56
+ return false;
57
+ }
58
+ if ((parsed.key === "enter" || parsed.key === " ") && !registration.shortcut.allowOnActivatable && isActivatable(target)) {
59
+ return false;
60
+ }
61
+ }
62
+ return true;
63
+ }
64
+
65
+ /** The scopes that may act on this event, highest precedence first. */
66
+ function activeScopes(event: KeyboardEvent, doc: Document): readonly ShortcutScope[] {
67
+ if (isModalOpen(doc)) {
68
+ return ["dialog"];
69
+ }
70
+ if (regionScopeOf(event.target) === "compose") {
71
+ return ["compose", "global"];
72
+ }
73
+ return [...VIEW_SCOPES, "global"];
74
+ }
75
+
76
+ /** Whether the registration applies to where the event happened (a compose window's shortcuts only inside it). */
77
+ function inContainer(registration: Registration, event: KeyboardEvent): boolean {
78
+ if (!registration.container) {
79
+ return true;
80
+ }
81
+ return !!registration.container.current?.contains(event.target as Node | null);
82
+ }
83
+
84
+ /**
85
+ * Handles one `keydown`: finds the registered shortcut it is, and runs its handler. Returns whether a handler ran - and only then is the
86
+ * event's default prevented and its propagation stopped, so a key nobody claims (or a handler that declines) behaves exactly as if this layer
87
+ * did not exist.
88
+ *
89
+ * Skipped outright: an event some other handler already `defaultPrevented` (a menu, the rich-text editor's own bindings), one from an IME
90
+ * composition, a bare modifier key, and the Copy/Cut/Paste/Select all/Undo/Redo/Find chords. A held key repeats: an action that is not
91
+ * marked `repeat` runs on the first press only, and the repeats are swallowed (so a browser doesn't reload on a held Ctrl+R) without running it.
92
+ *
93
+ * Which registration wins: the dialog scope alone while a modal is open; else, inside a compose window, `compose` then `global`; else
94
+ * whichever view is mounted, then `global`. Within a scope the most recently mounted registration goes first, and one that returns
95
+ * `false` passes the key on to the next.
96
+ */
97
+ export function dispatchKeyEvent(registry: ShortcutRegistry, event: KeyboardEvent, env: KeyEnvironment, doc: Document): boolean {
98
+ if (event.defaultPrevented || event.isComposing || event.key === "Process" || ["Control", "Shift", "Alt", "Meta"].includes(event.key)) {
99
+ return false;
100
+ }
101
+ const scopes = activeScopes(event, doc);
102
+ const candidates = registry
103
+ .getSnapshot()
104
+ .filter((registration) => scopes.includes(registration.scope) && inContainer(registration, event))
105
+ .sort((a, b) => scopes.indexOf(a.scope) - scopes.indexOf(b.scope) || b.order - a.order);
106
+ for (const registration of candidates) {
107
+ const specs = env.electron ? [...registration.keys, ...registration.electronKeys] : registration.keys;
108
+ const parsed = specs.find((spec) => matchesEvent(spec, event, env));
109
+ if (!parsed || isReservedChord(parsed, env) || !allowedOnTarget(registration, parsed, event.target, env)) {
110
+ continue;
111
+ }
112
+ if (event.repeat && !registration.shortcut.repeat) {
113
+ event.preventDefault();
114
+ event.stopPropagation();
115
+ return true;
116
+ }
117
+ if (registration.run(event) !== false) {
118
+ event.preventDefault();
119
+ event.stopPropagation();
120
+ return true;
121
+ }
122
+ }
123
+ return false;
124
+ }
@@ -0,0 +1,89 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import type { ShortcutDef } from "./keymap.js";
6
+ import { parseSpec, resolveModifiers } from "./parse.js";
7
+ import type { KeyEnvironment } from "./platform.js";
8
+
9
+ const KEY_NAMES: Record<string, string> = {
10
+ escape: "Esc",
11
+ enter: "Enter",
12
+ tab: "Tab",
13
+ backspace: "Backspace",
14
+ delete: "Delete",
15
+ insert: "Insert",
16
+ home: "Home",
17
+ end: "End",
18
+ pageup: "Page Up",
19
+ pagedown: "Page Down",
20
+ arrowup: "↑",
21
+ arrowdown: "↓",
22
+ arrowleft: "←",
23
+ arrowright: "→",
24
+ " ": "Space",
25
+ };
26
+
27
+ const MAC_KEY_NAMES: Record<string, string> = { ...KEY_NAMES, enter: "↩", backspace: "⌫", delete: "⌦" };
28
+
29
+ /** The key as it is printed on a key cap: `R`, `F5`, `Enter`, an arrow. */
30
+ function keyLabel(key: string, mac: boolean): string {
31
+ return (mac ? MAC_KEY_NAMES : KEY_NAMES)[key] ?? key.toUpperCase();
32
+ }
33
+
34
+ /** A spec as a person reads it: `Ctrl+Shift+R`, or `⌃⇧R`-style glyphs on a Mac (`⌘` for Cmd, `⌥` for Option). */
35
+ export function formatSpec(spec: string, env: KeyEnvironment): string {
36
+ const parsed = parseSpec(spec);
37
+ const modifiers = resolveModifiers(parsed, env);
38
+ if (env.mac) {
39
+ return [modifiers.ctrl && "⌃", modifiers.alt && "⌥", modifiers.shift && "⇧", modifiers.meta && "⌘", keyLabel(parsed.key, true)]
40
+ .filter(Boolean)
41
+ .join("");
42
+ }
43
+ return [modifiers.ctrl && "Ctrl", modifiers.shift && "Shift", modifiers.alt && "Alt", modifiers.meta && "Meta", keyLabel(parsed.key, false)]
44
+ .filter(Boolean)
45
+ .join("+");
46
+ }
47
+
48
+ const ARIA_NAMED_KEYS: Record<string, string> = {
49
+ escape: "Escape",
50
+ enter: "Enter",
51
+ tab: "Tab",
52
+ backspace: "Backspace",
53
+ delete: "Delete",
54
+ insert: "Insert",
55
+ home: "Home",
56
+ end: "End",
57
+ pageup: "PageUp",
58
+ pagedown: "PageDown",
59
+ arrowup: "ArrowUp",
60
+ arrowdown: "ArrowDown",
61
+ arrowleft: "ArrowLeft",
62
+ arrowright: "ArrowRight",
63
+ " ": "Space",
64
+ };
65
+
66
+ /** A spec in `aria-keyshortcuts` syntax: `Control+Shift+R`, `Meta+R`. */
67
+ export function ariaSpec(spec: string, env: KeyEnvironment): string {
68
+ const parsed = parseSpec(spec);
69
+ const modifiers = resolveModifiers(parsed, env);
70
+ const key = ARIA_NAMED_KEYS[parsed.key] ?? parsed.key.toUpperCase();
71
+ return [modifiers.ctrl && "Control", modifiers.alt && "Alt", modifiers.shift && "Shift", modifiers.meta && "Meta", key].filter(Boolean).join("+");
72
+ }
73
+
74
+ /** Every spec that triggers a shortcut here: its keys, and in the desktop client also its desktop-only ones. */
75
+ export function specsFor(shortcut: ShortcutDef, env: KeyEnvironment): string[] {
76
+ return env.electron && shortcut.electronKeys ? [...shortcut.keys, ...shortcut.electronKeys] : [...shortcut.keys];
77
+ }
78
+
79
+ /** The `aria-keyshortcuts` value for a control that runs a shortcut: every alternative, space separated. */
80
+ export function ariaKeyShortcuts(shortcut: ShortcutDef, env: KeyEnvironment): string {
81
+ return specsFor(shortcut, env)
82
+ .map((spec) => ariaSpec(spec, env))
83
+ .join(" ");
84
+ }
85
+
86
+ /** A tooltip/name suffix such as `Reply (Ctrl+R)`: the label with the shortcut's first key. */
87
+ export function withHint(label: string, shortcut: ShortcutDef, env: KeyEnvironment): string {
88
+ return `${label} (${formatSpec(shortcut.keys[0], env)})`;
89
+ }
@@ -0,0 +1,114 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+
6
+ /**
7
+ * Where a shortcut applies. `global` works in every view; a view scope (`mail`, `calendar`, `contacts`, `tasks`) exists only while that
8
+ * view is mounted; `compose` applies while focus is inside a compose window; `dialog` is for what a modal dialog binds itself - a
9
+ * dialog on screen silences every other scope.
10
+ */
11
+ export type ShortcutScope = "global" | "mail" | "compose" | "calendar" | "contacts" | "tasks" | "dialog";
12
+
13
+ /** The scopes the help dialog lists, in the order it lists them. */
14
+ export const HELP_SCOPES: readonly ShortcutScope[] = ["global", "mail", "compose", "calendar", "contacts", "tasks"];
15
+
16
+ export const SCOPE_LABELS: Record<ShortcutScope, string> = {
17
+ global: "Global",
18
+ mail: "Mail",
19
+ compose: "Compose",
20
+ calendar: "Calendar",
21
+ contacts: "Contacts",
22
+ tasks: "Tasks",
23
+ dialog: "Dialog",
24
+ };
25
+
26
+ /** One action the keyboard can trigger, and the keys that trigger it. Views register handlers for these; nothing else defines a key. */
27
+ export interface ShortcutDef {
28
+ /** Stable name, unique across the map - what the help dialog de-duplicates on. */
29
+ id: string;
30
+ /** Specs (see `parseSpec()`) that trigger it, the first being the one shown first. `mod` is Ctrl, or Cmd on macOS. */
31
+ keys: readonly string[];
32
+ /** Extra specs that apply only in the desktop client, where the browser's own reserved keys (Ctrl+N, Ctrl+T) are the app's. */
33
+ electronKeys?: readonly string[];
34
+ /** What the help dialog and a button's tooltip call it. */
35
+ label: string;
36
+ scope: ShortcutScope;
37
+ /** Fires from a focused button or link too (Enter on a message row); by default Enter/Space are left to what has the focus. */
38
+ allowOnActivatable?: boolean;
39
+ /** Keeps firing while the key is held (arrows); by default a held key runs a one-shot action once. */
40
+ repeat?: boolean;
41
+ }
42
+
43
+ function def<T extends ShortcutDef>(shortcut: T): T {
44
+ return shortcut;
45
+ }
46
+
47
+ /**
48
+ * The whole key map, in the order the help dialog lists it. The navigation set is literally Ctrl+Shift+<letter> on every platform (Cmd+Shift
49
+ * on macOS collides with the browsers' own - Cmd+Shift+A/B/C/L/M/S are tab search, the bookmarks bar, Inspect, the sidebar, the profile
50
+ * switcher and Save As - so it is not offered); the mail actions use `mod`, so Reply is Ctrl+R on Windows and Linux and Cmd+R on a Mac.
51
+ * Ctrl+Q (mark read) stays Ctrl on a Mac because Cmd+Q is the system's Quit.
52
+ */
53
+ export const SHORTCUTS = {
54
+ global: {
55
+ account: def({ id: "go.account", keys: ["ctrl+shift+a"], label: "Go to Account", scope: "global" }),
56
+ settings: def({ id: "go.settings", keys: ["ctrl+shift+s"], label: "Go to Settings", scope: "global" }),
57
+ contacts: def({ id: "go.contacts", keys: ["ctrl+shift+b"], label: "Go to Contacts", scope: "global" }),
58
+ mail: def({ id: "go.mail", keys: ["ctrl+shift+m"], label: "Go to Mail", scope: "global" }),
59
+ calendar: def({ id: "go.calendar", keys: ["ctrl+shift+c"], label: "Go to Calendar", scope: "global" }),
60
+ tasks: def({ id: "go.tasks", keys: ["ctrl+shift+l"], electronKeys: ["ctrl+shift+t"], label: "Go to Tasks", scope: "global" }),
61
+ help: def({ id: "help", keys: ["?", "ctrl+/"], label: "Keyboard shortcuts", scope: "global" }),
62
+ },
63
+ mail: {
64
+ create: def({ id: "mail.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New message", scope: "mail" }),
65
+ reply: def({ id: "mail.reply", keys: ["mod+r"], label: "Reply", scope: "mail" }),
66
+ replyAll: def({ id: "mail.replyAll", keys: ["mod+shift+r"], label: "Reply all", scope: "mail" }),
67
+ forward: def({ id: "mail.forward", keys: ["mod+shift+f"], label: "Forward", scope: "mail" }),
68
+ delete: def({ id: "mail.delete", keys: ["mod+d", "delete"], label: "Delete", scope: "mail" }),
69
+ archive: def({ id: "mail.archive", keys: ["e", "backspace"], label: "Archive", scope: "mail" }),
70
+ move: def({ id: "mail.move", keys: ["mod+shift+v"], label: "Move to folder", scope: "mail" }),
71
+ markRead: def({ id: "mail.markRead", keys: ["ctrl+q"], label: "Mark as read", scope: "mail" }),
72
+ markUnread: def({ id: "mail.markUnread", keys: ["mod+u"], label: "Mark as unread", scope: "mail" }),
73
+ flag: def({ id: "mail.flag", keys: ["insert"], label: "Flag or unflag", scope: "mail" }),
74
+ next: def({ id: "mail.next", keys: ["arrowdown", "j"], label: "Next message", scope: "mail", repeat: true }),
75
+ previous: def({ id: "mail.previous", keys: ["arrowup", "k"], label: "Previous message", scope: "mail", repeat: true }),
76
+ nextUnread: def({ id: "mail.nextUnread", keys: ["ctrl+."], label: "Next unread message", scope: "mail" }),
77
+ previousUnread: def({ id: "mail.previousUnread", keys: ["ctrl+,"], label: "Previous unread message", scope: "mail" }),
78
+ open: def({ id: "mail.open", keys: ["enter"], label: "Open the message on its own page", scope: "mail", allowOnActivatable: true }),
79
+ close: def({ id: "mail.close", keys: ["escape"], label: "Clear the selection", scope: "mail" }),
80
+ search: def({ id: "mail.search", keys: ["/", "mod+e"], label: "Search mail", scope: "mail" }),
81
+ },
82
+ compose: {
83
+ create: def({ id: "compose.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New message", scope: "compose" }),
84
+ send: def({ id: "compose.send", keys: ["mod+enter"], label: "Send", scope: "compose" }),
85
+ saveDraft: def({ id: "compose.saveDraft", keys: ["mod+s"], label: "Save draft", scope: "compose" }),
86
+ close: def({ id: "compose.close", keys: ["escape"], label: "Close (keeps the draft)", scope: "compose" }),
87
+ },
88
+ calendar: {
89
+ create: def({ id: "calendar.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New event", scope: "calendar" }),
90
+ today: def({ id: "calendar.today", keys: ["t"], label: "Go to today", scope: "calendar" }),
91
+ previous: def({ id: "calendar.previous", keys: ["arrowleft", "mod+arrowleft"], label: "Previous period", scope: "calendar", repeat: true }),
92
+ next: def({ id: "calendar.next", keys: ["arrowright", "mod+arrowright"], label: "Next period", scope: "calendar", repeat: true }),
93
+ day: def({ id: "calendar.day", keys: ["ctrl+alt+1"], label: "Day view", scope: "calendar" }),
94
+ workWeek: def({ id: "calendar.workWeek", keys: ["ctrl+alt+2"], label: "Work week view", scope: "calendar" }),
95
+ week: def({ id: "calendar.week", keys: ["ctrl+alt+3"], label: "Week view", scope: "calendar" }),
96
+ month: def({ id: "calendar.month", keys: ["ctrl+alt+4"], label: "Month view", scope: "calendar" }),
97
+ },
98
+ contacts: {
99
+ create: def({ id: "contacts.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New contact", scope: "contacts" }),
100
+ search: def({ id: "contacts.search", keys: ["/", "mod+e"], label: "Search contacts", scope: "contacts" }),
101
+ },
102
+ tasks: {
103
+ create: def({ id: "tasks.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New task", scope: "tasks" }),
104
+ },
105
+ } as const;
106
+
107
+ /** Every shortcut of the map flattened, in listing order. */
108
+ export const ALL_SHORTCUTS: readonly ShortcutDef[] = Object.values(SHORTCUTS).flatMap((group) => Object.values(group) as ShortcutDef[]);
109
+
110
+ /** Where a shortcut sits in the listing, for ordering registrations that arrive in whatever order components mount. */
111
+ export function shortcutRank(shortcut: ShortcutDef): number {
112
+ const index = ALL_SHORTCUTS.findIndex((candidate) => candidate.id === shortcut.id);
113
+ return index === -1 ? ALL_SHORTCUTS.length : index;
114
+ }
@@ -0,0 +1,44 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { ParsedSpec, isSymbolKey, resolveModifiers } from "./parse.js";
6
+ import type { KeyEnvironment } from "./platform.js";
7
+
8
+ /** The part of a `KeyboardEvent` matching reads. */
9
+ export interface KeyEventLike {
10
+ key: string;
11
+ code?: string;
12
+ ctrlKey: boolean;
13
+ shiftKey: boolean;
14
+ altKey: boolean;
15
+ metaKey: boolean;
16
+ }
17
+
18
+ /** Whether `key` is what a Latin layout produces for a printable key: then `event.key` says which key it is, whatever `event.code` is. */
19
+ function isAsciiKey(key: string): boolean {
20
+ return /^[\x21-\x7e]$/.test(key);
21
+ }
22
+
23
+ /**
24
+ * Whether a key event is the shortcut `parsed`, on `env`.
25
+ *
26
+ * The key is matched on `event.key` (case-insensitively), so a shortcut means the letter on the key cap on any layout that has it -
27
+ * Dvorak, AZERTY - and falls back to `event.code` only when `event.key` is not a Latin character at all: macOS Option+N produces a
28
+ * dead key or `~`-like symbol, and a Cyrillic or Greek layout produces `ф`/`α` for the key that is A on a QWERTY board. Modifiers must
29
+ * match exactly (Ctrl+Shift+R is not Ctrl+R), except Shift for a printable symbol, which some layouts need to type it (`?`).
30
+ */
31
+ export function matchesEvent(parsed: ParsedSpec, event: KeyEventLike, env: KeyEnvironment): boolean {
32
+ const modifiers = resolveModifiers(parsed, env);
33
+ if (event.ctrlKey !== modifiers.ctrl || event.altKey !== modifiers.alt || event.metaKey !== modifiers.meta) {
34
+ return false;
35
+ }
36
+ if (event.shiftKey !== modifiers.shift && !(isSymbolKey(parsed.key) && !parsed.shift)) {
37
+ return false;
38
+ }
39
+ const key = (event.key ?? "").toLowerCase();
40
+ if (key === parsed.key) {
41
+ return true;
42
+ }
43
+ return !!parsed.code && event.code === parsed.code && !isAsciiKey(key);
44
+ }