@rapidmx/web-client 0.9.0 → 0.11.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.
- package/README.md +373 -88
- package/apps/admin/_layout.tsx +8 -2
- package/apps/admin/index.tsx +7 -1
- package/apps/admin/ingest-queue/index.tsx +2 -1
- package/apps/admin/mailboxes/[uid].tsx +23 -10
- package/apps/admin/quarantine/index.tsx +2 -1
- package/apps/admin/signing-certificates/index.tsx +343 -0
- package/apps/escrow/_layout.tsx +8 -2
- package/apps/shared/appearance/AppearanceForm.tsx +392 -0
- package/apps/shared/appearance/AppearanceHead.tsx +49 -0
- package/apps/shared/appearance/AppearanceProvider.tsx +470 -0
- package/apps/shared/appearance/ColorField.tsx +107 -0
- package/apps/shared/appearance/appearanceCache.ts +106 -0
- package/apps/shared/appearance/appearanceContext.ts +77 -0
- package/apps/shared/appearance/bootScript.ts +35 -0
- package/apps/shared/appearance/color.ts +169 -0
- package/apps/shared/appearance/photo.ts +88 -0
- package/apps/shared/appearance/resolvedTheme.ts +67 -0
- package/apps/shared/appearance/theme.ts +355 -0
- package/apps/shared/auth/accountUrl.ts +9 -0
- package/apps/shared/auth/adminAccess.ts +99 -0
- package/apps/shared/components/admin/layout/AdminShell.tsx +22 -10
- package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +107 -60
- package/apps/shared/components/admin/settings/BrandingForm.tsx +24 -0
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +2 -1
- package/apps/shared/components/admin/settings/PluginsManager.tsx +228 -25
- package/apps/shared/components/admin/setup/SetupWizard.tsx +2 -1
- package/apps/shared/components/calendar/CalendarListSidebar.tsx +4 -5
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +8 -2
- package/apps/shared/components/contacts/ContactForm.tsx +11 -5
- package/apps/shared/components/contacts/ContactsSidebar.tsx +5 -3
- package/apps/shared/components/contacts/ContactsToolbar.tsx +98 -115
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +25 -8
- package/apps/shared/components/escrow/layout/EscrowShell.tsx +13 -6
- package/apps/shared/components/layout/AppShell.tsx +477 -288
- package/apps/shared/components/layout/BrandingChrome.tsx +200 -13
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -389
- package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -164
- package/apps/shared/components/layout/RailIcon.tsx +100 -0
- package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -0
- package/apps/shared/components/layout/ThemeSwitch.tsx +84 -0
- package/apps/shared/components/layout/UserMenu.tsx +372 -185
- package/apps/shared/components/mail/ConversationList.tsx +271 -262
- package/apps/shared/components/mail/ConversationThreadPane.tsx +147 -94
- package/apps/shared/components/mail/LazyReadingPane.tsx +113 -0
- package/apps/shared/components/mail/MailSelectionBar.tsx +227 -222
- package/apps/shared/components/mail/MessageDetailPane.tsx +1537 -1387
- package/apps/shared/components/mail/OutboxBadge.tsx +44 -0
- package/apps/shared/components/mail/OutboxRowStatus.tsx +31 -0
- package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -160
- package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -418
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1644 -1736
- package/apps/shared/components/mail/compose/ComposeWindowPlaceholder.tsx +111 -0
- package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -118
- package/apps/shared/components/mail/compose/composePerf.ts +46 -0
- package/apps/shared/components/mail/compose/encryptionRequirement.ts +86 -0
- package/apps/shared/components/mail/compose/quotedBody.ts +161 -100
- package/apps/shared/components/mail/layout/MailShell.tsx +490 -472
- package/apps/shared/components/mail/reading/EncryptedBody.tsx +65 -0
- package/apps/shared/components/mail/reading/EncryptedPreview.tsx +35 -0
- package/apps/shared/components/mail/reading/MessageBody.tsx +240 -0
- package/apps/shared/components/mail/reading/MessageCard.tsx +174 -0
- package/apps/shared/components/mail/reading/bodyContent.ts +100 -0
- package/apps/shared/components/mail/reading/bodyHtml.ts +298 -0
- package/apps/shared/components/mail/reading/color.ts +245 -0
- package/apps/shared/components/mail/reading/frameControl.ts +142 -0
- package/apps/shared/components/mail/reading/frameDocument.ts +123 -0
- package/apps/shared/components/mail/reading/safeDocument.ts +24 -0
- package/apps/shared/components/mail/reading/themeAdaptation.ts +221 -0
- package/apps/shared/components/mail/reading/themeSurface.ts +90 -0
- package/apps/shared/components/mail/reading/viewOriginal.ts +38 -0
- package/apps/shared/components/mail/unreadStyle.tsx +75 -0
- package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -0
- package/apps/shared/components/settings/layout/SettingsShell.tsx +253 -240
- package/apps/shared/components/sharing/PrincipalPicker.tsx +145 -0
- package/apps/shared/components/tasks/TasksSidebar.tsx +5 -3
- package/apps/shared/components/tasks/layout/TasksShell.tsx +24 -8
- package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -0
- package/apps/shared/keyboard/ShortcutProvider.tsx +62 -0
- package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -0
- package/apps/shared/keyboard/dispatch.ts +124 -0
- package/apps/shared/keyboard/format.ts +89 -0
- package/apps/shared/keyboard/keymap.ts +114 -0
- package/apps/shared/keyboard/match.ts +44 -0
- package/apps/shared/keyboard/parse.ts +136 -0
- package/apps/shared/keyboard/platform.ts +34 -0
- package/apps/shared/keyboard/registry.ts +65 -0
- package/apps/shared/keyboard/targets.ts +79 -0
- package/apps/shared/keyboard/useShortcut.ts +50 -0
- package/apps/shared/keyboard/useShortcutProps.ts +17 -0
- package/apps/shared/mail/folderCounts.ts +308 -0
- package/apps/shared/mail/folderTree.ts +143 -0
- package/apps/shared/mail/listSnapshots.ts +87 -0
- package/apps/shared/mail/messageReadState.ts +85 -0
- package/apps/shared/mail/newMailNotifications.ts +183 -0
- package/apps/shared/mail/outbox/UnlockBridge.tsx +23 -0
- package/apps/shared/mail/outbox/composeBridge.ts +69 -0
- package/apps/shared/mail/outbox/outboxState.ts +88 -0
- package/apps/shared/mail/outbox/pendingSends.ts +146 -0
- package/apps/shared/mail/outbox/sendDecision.ts +157 -0
- package/apps/shared/mail/outbox/sendJob.ts +427 -0
- package/apps/shared/mail/outbox/sendOutcomes.ts +146 -0
- package/apps/shared/mail/outbox/sendState.ts +35 -0
- package/apps/shared/mail/outbox/useOutboxStatus.ts +61 -0
- package/apps/shared/mail/useMailConnection.ts +203 -0
- package/apps/shared/mail/useMailLiveUpdates.ts +277 -224
- package/apps/shared/mail/useMarkMessageRead.ts +47 -0
- package/apps/shared/mail/useNewMailNotifications.ts +178 -0
- package/apps/shared/mail/useUnreadTitle.ts +42 -0
- package/apps/shared/navigation/AppRouter.tsx +300 -0
- package/apps/shared/navigation/appHrefs.ts +23 -0
- package/apps/shared/navigation/frameContext.tsx +35 -0
- package/apps/shared/navigation/idle.ts +45 -0
- package/apps/shared/navigation/routerContext.tsx +83 -0
- package/apps/shared/navigation/routes.ts +72 -0
- package/apps/shared/notifications/NotificationCenter.tsx +215 -0
- package/apps/shared/notifications/NotificationHistoryDialog.tsx +90 -0
- package/apps/shared/notifications/apiErrors.ts +98 -0
- package/apps/shared/notifications/headerOffset.ts +35 -0
- package/apps/shared/notifications/pushStatus.ts +56 -0
- package/apps/shared/notifications/store.ts +549 -0
- package/apps/shared/notifications/systemErrors.ts +63 -0
- package/apps/shared/notifications/useNotifications.ts +41 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +114 -98
- package/apps/shared/signing/enrollmentStorage.ts +33 -0
- package/apps/shared/signing/enrollmentTracker.ts +385 -0
- package/apps/shared/signing/enrollmentView.ts +251 -0
- package/apps/shared/signing/signingInfo.ts +58 -0
- package/apps/shared/signing/useNow.ts +19 -0
- package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -0
- package/apps/shared/styles/app.css +108 -10
- package/apps/www/_layout.tsx +8 -2
- package/apps/www/_routedPage.tsx +24 -0
- package/apps/www/_routes.ts +36 -0
- package/apps/www/calendar/index.tsx +64 -33
- package/apps/www/contacts/[uid].tsx +109 -107
- package/apps/www/contacts/index.tsx +62 -42
- package/apps/www/index.tsx +2291 -1917
- package/apps/www/messages/[uid].tsx +108 -101
- package/apps/www/settings/appearance/index.tsx +21 -0
- package/apps/www/settings/auto-reply/index.tsx +7 -8
- package/apps/www/settings/encryption/index.tsx +1287 -1249
- package/apps/www/settings/filters/[uid].tsx +7 -2
- package/apps/www/settings/filters/index.tsx +102 -99
- package/apps/www/settings/filters/new/index.tsx +140 -133
- package/apps/www/settings/labels/index.tsx +204 -201
- package/apps/www/settings/privacy/index.tsx +7 -9
- package/apps/www/settings/read-receipts/index.tsx +7 -8
- package/apps/www/settings/sharing/index.tsx +256 -274
- package/apps/www/settings/signatures/[uid].tsx +172 -167
- package/apps/www/settings/signatures/index.tsx +88 -85
- package/apps/www/settings/signatures/new/index.tsx +135 -129
- package/apps/www/tasks/index.tsx +29 -18
- package/dist/apps/admin/_layout.d.ts +5 -1
- package/dist/apps/admin/_layout.js +3 -2
- package/dist/apps/admin/index.js +3 -2
- package/dist/apps/admin/ingest-queue/index.js +2 -1
- package/dist/apps/admin/mailboxes/[uid].js +9 -6
- package/dist/apps/admin/quarantine/index.js +2 -1
- package/dist/apps/admin/signing-certificates/index.d.ts +3 -0
- package/dist/apps/admin/signing-certificates/index.js +161 -0
- package/dist/apps/escrow/_layout.d.ts +5 -1
- package/dist/apps/escrow/_layout.js +3 -2
- package/dist/apps/shared/appearance/AppearanceForm.d.ts +7 -0
- package/dist/apps/shared/appearance/AppearanceForm.js +131 -0
- package/dist/apps/shared/appearance/AppearanceHead.d.ts +15 -0
- package/dist/apps/shared/appearance/AppearanceHead.js +31 -0
- package/dist/apps/shared/appearance/AppearanceProvider.d.ts +32 -0
- package/dist/apps/shared/appearance/AppearanceProvider.js +390 -0
- package/dist/apps/shared/appearance/ColorField.d.ts +22 -0
- package/dist/apps/shared/appearance/ColorField.js +40 -0
- package/dist/apps/shared/appearance/appearanceCache.d.ts +45 -0
- package/dist/apps/shared/appearance/appearanceCache.js +80 -0
- package/dist/apps/shared/appearance/appearanceContext.d.ts +45 -0
- package/dist/apps/shared/appearance/appearanceContext.js +29 -0
- package/dist/apps/shared/appearance/bootScript.d.ts +16 -0
- package/dist/apps/shared/appearance/bootScript.js +33 -0
- package/dist/apps/shared/appearance/color.d.ts +65 -0
- package/dist/apps/shared/appearance/color.js +132 -0
- package/dist/apps/shared/appearance/photo.d.ts +17 -0
- package/dist/apps/shared/appearance/photo.js +79 -0
- package/dist/apps/shared/appearance/resolvedTheme.d.ts +21 -0
- package/dist/apps/shared/appearance/resolvedTheme.js +55 -0
- package/dist/apps/shared/appearance/theme.d.ts +111 -0
- package/dist/apps/shared/appearance/theme.js +251 -0
- package/dist/apps/shared/auth/accountUrl.d.ts +2 -0
- package/dist/apps/shared/auth/accountUrl.js +8 -0
- package/dist/apps/shared/auth/adminAccess.d.ts +30 -0
- package/dist/apps/shared/auth/adminAccess.js +89 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
- package/dist/apps/shared/components/admin/layout/AdminShell.js +16 -6
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +10 -5
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +49 -34
- package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +2 -0
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +7 -1
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +1 -1
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +106 -20
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +2 -1
- package/dist/apps/shared/components/calendar/CalendarListSidebar.js +8 -8
- package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +1 -1
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +8 -4
- package/dist/apps/shared/components/contacts/ContactForm.js +1 -1
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +4 -2
- package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +6 -2
- package/dist/apps/shared/components/contacts/ContactsToolbar.js +28 -10
- package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +1 -1
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +19 -6
- package/dist/apps/shared/components/escrow/layout/EscrowShell.js +7 -4
- package/dist/apps/shared/components/layout/AppShell.d.ts +34 -4
- package/dist/apps/shared/components/layout/AppShell.js +122 -17
- package/dist/apps/shared/components/layout/BrandingChrome.d.ts +69 -10
- package/dist/apps/shared/components/layout/BrandingChrome.js +140 -12
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +10 -9
- package/dist/apps/shared/components/layout/MailboxProvisioning.js +3 -1
- package/dist/apps/shared/components/layout/RailIcon.d.ts +21 -0
- package/dist/apps/shared/components/layout/RailIcon.js +85 -0
- package/dist/apps/shared/components/layout/ResponsiveToolbar.d.ts +55 -0
- package/dist/apps/shared/components/layout/ResponsiveToolbar.js +199 -0
- package/dist/apps/shared/components/layout/ThemeSwitch.d.ts +9 -0
- package/dist/apps/shared/components/layout/ThemeSwitch.js +54 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +25 -3
- package/dist/apps/shared/components/layout/UserMenu.js +88 -7
- package/dist/apps/shared/components/mail/ConversationList.js +5 -11
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +6 -2
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +87 -40
- package/dist/apps/shared/components/mail/LazyReadingPane.d.ts +9 -0
- package/dist/apps/shared/components/mail/LazyReadingPane.js +83 -0
- package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +6 -4
- package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -4
- package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +25 -8
- package/dist/apps/shared/components/mail/MessageDetailPane.js +167 -73
- package/dist/apps/shared/components/mail/OutboxBadge.d.ts +17 -0
- package/dist/apps/shared/components/mail/OutboxBadge.js +18 -0
- package/dist/apps/shared/components/mail/OutboxRowStatus.d.ts +10 -0
- package/dist/apps/shared/components/mail/OutboxRowStatus.js +19 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +38 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +97 -6
- package/dist/apps/shared/components/mail/compose/ComposeToolbar.js +4 -3
- package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +3 -2
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +316 -339
- package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.d.ts +19 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.js +33 -0
- package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +9 -1
- package/dist/apps/shared/components/mail/compose/RichTextEditor.js +20 -2
- package/dist/apps/shared/components/mail/compose/composePerf.d.ts +16 -0
- package/dist/apps/shared/components/mail/compose/composePerf.js +41 -0
- package/dist/apps/shared/components/mail/compose/encryptionRequirement.d.ts +49 -0
- package/dist/apps/shared/components/mail/compose/encryptionRequirement.js +35 -0
- package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +13 -0
- package/dist/apps/shared/components/mail/compose/quotedBody.js +67 -11
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +14 -4
- package/dist/apps/shared/components/mail/layout/MailShell.js +90 -104
- package/dist/apps/shared/components/mail/reading/EncryptedBody.d.ts +21 -0
- package/dist/apps/shared/components/mail/reading/EncryptedBody.js +22 -0
- package/dist/apps/shared/components/mail/reading/EncryptedPreview.d.ts +18 -0
- package/dist/apps/shared/components/mail/reading/EncryptedPreview.js +22 -0
- package/dist/apps/shared/components/mail/reading/MessageBody.d.ts +32 -0
- package/dist/apps/shared/components/mail/reading/MessageBody.js +136 -0
- package/dist/apps/shared/components/mail/reading/MessageCard.d.ts +62 -0
- package/dist/apps/shared/components/mail/reading/MessageCard.js +58 -0
- package/dist/apps/shared/components/mail/reading/bodyContent.d.ts +38 -0
- package/dist/apps/shared/components/mail/reading/bodyContent.js +84 -0
- package/dist/apps/shared/components/mail/reading/bodyHtml.d.ts +47 -0
- package/dist/apps/shared/components/mail/reading/bodyHtml.js +267 -0
- package/dist/apps/shared/components/mail/reading/color.d.ts +63 -0
- package/dist/apps/shared/components/mail/reading/color.js +201 -0
- package/dist/apps/shared/components/mail/reading/frameControl.d.ts +33 -0
- package/dist/apps/shared/components/mail/reading/frameControl.js +120 -0
- package/dist/apps/shared/components/mail/reading/frameDocument.d.ts +52 -0
- package/dist/apps/shared/components/mail/reading/frameDocument.js +98 -0
- package/dist/apps/shared/components/mail/reading/safeDocument.d.ts +3 -0
- package/dist/apps/shared/components/mail/reading/safeDocument.js +12 -0
- package/dist/apps/shared/components/mail/reading/themeAdaptation.d.ts +56 -0
- package/dist/apps/shared/components/mail/reading/themeAdaptation.js +144 -0
- package/dist/apps/shared/components/mail/reading/themeSurface.d.ts +17 -0
- package/dist/apps/shared/components/mail/reading/themeSurface.js +83 -0
- package/dist/apps/shared/components/mail/reading/viewOriginal.d.ts +9 -0
- package/dist/apps/shared/components/mail/reading/viewOriginal.js +32 -0
- package/dist/apps/shared/components/mail/unreadStyle.d.ts +45 -0
- package/dist/apps/shared/components/mail/unreadStyle.js +61 -0
- package/dist/apps/shared/components/settings/SigningCertificateCard.d.ts +32 -0
- package/dist/apps/shared/components/settings/SigningCertificateCard.js +98 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +1 -1
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +16 -5
- package/dist/apps/shared/components/sharing/PrincipalPicker.d.ts +26 -0
- package/dist/apps/shared/components/sharing/PrincipalPicker.js +77 -0
- package/dist/apps/shared/components/tasks/TasksSidebar.js +4 -2
- package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +1 -1
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +18 -6
- package/dist/apps/shared/keyboard/GlobalShortcuts.d.ts +14 -0
- package/dist/apps/shared/keyboard/GlobalShortcuts.js +37 -0
- package/dist/apps/shared/keyboard/ShortcutProvider.d.ts +20 -0
- package/dist/apps/shared/keyboard/ShortcutProvider.js +52 -0
- package/dist/apps/shared/keyboard/ShortcutsDialog.d.ts +14 -0
- package/dist/apps/shared/keyboard/ShortcutsDialog.js +42 -0
- package/dist/apps/shared/keyboard/dispatch.d.ts +16 -0
- package/dist/apps/shared/keyboard/dispatch.js +109 -0
- package/dist/apps/shared/keyboard/format.d.ts +12 -0
- package/dist/apps/shared/keyboard/format.js +74 -0
- package/dist/apps/shared/keyboard/keymap.d.ts +294 -0
- package/dist/apps/shared/keyboard/keymap.js +84 -0
- package/dist/apps/shared/keyboard/match.d.ts +20 -0
- package/dist/apps/shared/keyboard/match.js +31 -0
- package/dist/apps/shared/keyboard/parse.d.ts +31 -0
- package/dist/apps/shared/keyboard/parse.js +107 -0
- package/dist/apps/shared/keyboard/platform.d.ts +15 -0
- package/dist/apps/shared/keyboard/platform.js +22 -0
- package/dist/apps/shared/keyboard/registry.d.ts +39 -0
- package/dist/apps/shared/keyboard/registry.js +33 -0
- package/dist/apps/shared/keyboard/targets.d.ts +14 -0
- package/dist/apps/shared/keyboard/targets.js +67 -0
- package/dist/apps/shared/keyboard/useShortcut.d.ts +19 -0
- package/dist/apps/shared/keyboard/useShortcut.js +35 -0
- package/dist/apps/shared/keyboard/useShortcutProps.d.ts +10 -0
- package/dist/apps/shared/keyboard/useShortcutProps.js +15 -0
- package/dist/apps/shared/mail/folderCounts.d.ts +78 -0
- package/dist/apps/shared/mail/folderCounts.js +218 -0
- package/dist/apps/shared/mail/folderTree.d.ts +55 -0
- package/dist/apps/shared/mail/folderTree.js +116 -0
- package/dist/apps/shared/mail/listSnapshots.d.ts +46 -0
- package/dist/apps/shared/mail/listSnapshots.js +43 -0
- package/dist/apps/shared/mail/messageReadState.d.ts +32 -0
- package/dist/apps/shared/mail/messageReadState.js +63 -0
- package/dist/apps/shared/mail/newMailNotifications.d.ts +62 -0
- package/dist/apps/shared/mail/newMailNotifications.js +138 -0
- package/dist/apps/shared/mail/outbox/UnlockBridge.d.ts +5 -0
- package/dist/apps/shared/mail/outbox/UnlockBridge.js +18 -0
- package/dist/apps/shared/mail/outbox/composeBridge.d.ts +34 -0
- package/dist/apps/shared/mail/outbox/composeBridge.js +32 -0
- package/dist/apps/shared/mail/outbox/outboxState.d.ts +41 -0
- package/dist/apps/shared/mail/outbox/outboxState.js +42 -0
- package/dist/apps/shared/mail/outbox/pendingSends.d.ts +39 -0
- package/dist/apps/shared/mail/outbox/pendingSends.js +109 -0
- package/dist/apps/shared/mail/outbox/sendDecision.d.ts +80 -0
- package/dist/apps/shared/mail/outbox/sendDecision.js +94 -0
- package/dist/apps/shared/mail/outbox/sendJob.d.ts +68 -0
- package/dist/apps/shared/mail/outbox/sendJob.js +319 -0
- package/dist/apps/shared/mail/outbox/sendOutcomes.d.ts +3 -0
- package/dist/apps/shared/mail/outbox/sendOutcomes.js +141 -0
- package/dist/apps/shared/mail/outbox/sendState.d.ts +25 -0
- package/dist/apps/shared/mail/outbox/sendState.js +8 -0
- package/dist/apps/shared/mail/outbox/useOutboxStatus.d.ts +11 -0
- package/dist/apps/shared/mail/outbox/useOutboxStatus.js +49 -0
- package/dist/apps/shared/mail/useMailConnection.d.ts +56 -0
- package/dist/apps/shared/mail/useMailConnection.js +138 -0
- package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +29 -9
- package/dist/apps/shared/mail/useMailLiveUpdates.js +60 -32
- package/dist/apps/shared/mail/useMarkMessageRead.d.ts +12 -0
- package/dist/apps/shared/mail/useMarkMessageRead.js +44 -0
- package/dist/apps/shared/mail/useNewMailNotifications.d.ts +35 -0
- package/dist/apps/shared/mail/useNewMailNotifications.js +130 -0
- package/dist/apps/shared/mail/useUnreadTitle.d.ts +18 -0
- package/dist/apps/shared/mail/useUnreadTitle.js +31 -0
- package/dist/apps/shared/navigation/AppRouter.d.ts +52 -0
- package/dist/apps/shared/navigation/AppRouter.js +242 -0
- package/dist/apps/shared/navigation/appHrefs.d.ts +14 -0
- package/dist/apps/shared/navigation/appHrefs.js +20 -0
- package/dist/apps/shared/navigation/frameContext.d.ts +19 -0
- package/dist/apps/shared/navigation/frameContext.js +24 -0
- package/dist/apps/shared/navigation/idle.d.ts +14 -0
- package/dist/apps/shared/navigation/idle.js +43 -0
- package/dist/apps/shared/navigation/routerContext.d.ts +37 -0
- package/dist/apps/shared/navigation/routerContext.js +56 -0
- package/dist/apps/shared/navigation/routes.d.ts +32 -0
- package/dist/apps/shared/navigation/routes.js +37 -0
- package/dist/apps/shared/notifications/NotificationCenter.d.ts +19 -0
- package/dist/apps/shared/notifications/NotificationCenter.js +90 -0
- package/dist/apps/shared/notifications/NotificationHistoryDialog.d.ts +10 -0
- package/dist/apps/shared/notifications/NotificationHistoryDialog.js +36 -0
- package/dist/apps/shared/notifications/apiErrors.d.ts +19 -0
- package/dist/apps/shared/notifications/apiErrors.js +86 -0
- package/dist/apps/shared/notifications/headerOffset.d.ts +8 -0
- package/dist/apps/shared/notifications/headerOffset.js +33 -0
- package/dist/apps/shared/notifications/pushStatus.d.ts +9 -0
- package/dist/apps/shared/notifications/pushStatus.js +54 -0
- package/dist/apps/shared/notifications/store.d.ts +136 -0
- package/dist/apps/shared/notifications/store.js +416 -0
- package/dist/apps/shared/notifications/systemErrors.d.ts +9 -0
- package/dist/apps/shared/notifications/systemErrors.js +58 -0
- package/dist/apps/shared/notifications/useNotifications.d.ts +17 -0
- package/dist/apps/shared/notifications/useNotifications.js +18 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +17 -3
- package/dist/apps/shared/signing/enrollmentStorage.d.ts +10 -0
- package/dist/apps/shared/signing/enrollmentStorage.js +33 -0
- package/dist/apps/shared/signing/enrollmentTracker.d.ts +73 -0
- package/dist/apps/shared/signing/enrollmentTracker.js +307 -0
- package/dist/apps/shared/signing/enrollmentView.d.ts +57 -0
- package/dist/apps/shared/signing/enrollmentView.js +214 -0
- package/dist/apps/shared/signing/signingInfo.d.ts +11 -0
- package/dist/apps/shared/signing/signingInfo.js +48 -0
- package/dist/apps/shared/signing/useNow.d.ts +2 -0
- package/dist/apps/shared/signing/useNow.js +18 -0
- package/dist/apps/shared/signing/useSigningEnrollmentWatcher.d.ts +16 -0
- package/dist/apps/shared/signing/useSigningEnrollmentWatcher.js +87 -0
- package/dist/apps/shared/styles/app.css +108 -10
- package/dist/apps/www/_layout.d.ts +5 -1
- package/dist/apps/www/_layout.js +3 -2
- package/dist/apps/www/_routedPage.d.ts +12 -0
- package/dist/apps/www/_routedPage.js +19 -0
- package/dist/apps/www/_routes.d.ts +11 -0
- package/dist/apps/www/_routes.js +30 -0
- package/dist/apps/www/calendar/index.d.ts +2 -2
- package/dist/apps/www/calendar/index.js +41 -11
- package/dist/apps/www/contacts/[uid].d.ts +3 -9
- package/dist/apps/www/contacts/[uid].js +11 -9
- package/dist/apps/www/contacts/index.d.ts +2 -2
- package/dist/apps/www/contacts/index.js +30 -24
- package/dist/apps/www/index.d.ts +2 -2
- package/dist/apps/www/index.js +332 -48
- package/dist/apps/www/messages/[uid].d.ts +3 -7
- package/dist/apps/www/messages/[uid].js +10 -5
- package/dist/apps/www/settings/appearance/index.d.ts +4 -0
- package/dist/apps/www/settings/appearance/index.js +13 -0
- package/dist/apps/www/settings/auto-reply/index.d.ts +2 -2
- package/dist/apps/www/settings/auto-reply/index.js +6 -7
- package/dist/apps/www/settings/encryption/index.d.ts +2 -2
- package/dist/apps/www/settings/encryption/index.js +106 -96
- package/dist/apps/www/settings/filters/[uid].d.ts +2 -2
- package/dist/apps/www/settings/filters/[uid].js +6 -2
- package/dist/apps/www/settings/filters/index.d.ts +2 -2
- package/dist/apps/www/settings/filters/index.js +3 -1
- package/dist/apps/www/settings/filters/new/index.d.ts +2 -2
- package/dist/apps/www/settings/filters/new/index.js +9 -3
- package/dist/apps/www/settings/labels/index.d.ts +2 -2
- package/dist/apps/www/settings/labels/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.d.ts +2 -2
- package/dist/apps/www/settings/privacy/index.js +8 -9
- package/dist/apps/www/settings/read-receipts/index.d.ts +2 -2
- package/dist/apps/www/settings/read-receipts/index.js +6 -7
- package/dist/apps/www/settings/sharing/index.d.ts +2 -2
- package/dist/apps/www/settings/sharing/index.js +22 -34
- package/dist/apps/www/settings/signatures/[uid].d.ts +2 -2
- package/dist/apps/www/settings/signatures/[uid].js +6 -2
- package/dist/apps/www/settings/signatures/index.d.ts +2 -2
- package/dist/apps/www/settings/signatures/index.js +3 -1
- package/dist/apps/www/settings/signatures/new/index.d.ts +2 -2
- package/dist/apps/www/settings/signatures/new/index.js +9 -4
- package/dist/apps/www/tasks/index.d.ts +2 -2
- package/dist/apps/www/tasks/index.js +22 -16
- package/package.json +2 -2
- package/apps/shared/components/mail/compose/SendFailureAlert.tsx +0 -48
- package/dist/apps/shared/components/mail/compose/SendFailureAlert.d.ts +0 -14
- package/dist/apps/shared/components/mail/compose/SendFailureAlert.js +0 -11
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import type { KeyEnvironment } from "./platform.js";
|
|
6
|
+
|
|
7
|
+
/** A shortcut such as `ctrl+shift+a`, `alt+n`, `Delete` or `?`, broken into what a key event is compared with. */
|
|
8
|
+
export interface ParsedSpec {
|
|
9
|
+
/** The spec as written. */
|
|
10
|
+
spec: string;
|
|
11
|
+
/** The key, lower-case: a letter or digit, a symbol (`?`, `/`, `.`, `,`), or a named key (`enter`, `delete`, `arrowup`, ...). */
|
|
12
|
+
key: string;
|
|
13
|
+
ctrl: boolean;
|
|
14
|
+
shift: boolean;
|
|
15
|
+
alt: boolean;
|
|
16
|
+
meta: boolean;
|
|
17
|
+
/** Ctrl on Windows and Linux, Cmd on macOS - resolved against the environment by `resolveModifiers()`. */
|
|
18
|
+
mod: boolean;
|
|
19
|
+
/** The `KeyboardEvent.code` of the key on a QWERTY keyboard, for layouts where `event.key` is not the letter (see `match.ts`). */
|
|
20
|
+
code?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const MODIFIERS: Record<string, "ctrl" | "shift" | "alt" | "meta" | "mod"> = {
|
|
24
|
+
ctrl: "ctrl",
|
|
25
|
+
control: "ctrl",
|
|
26
|
+
shift: "shift",
|
|
27
|
+
alt: "alt",
|
|
28
|
+
option: "alt",
|
|
29
|
+
opt: "alt",
|
|
30
|
+
meta: "meta",
|
|
31
|
+
cmd: "meta",
|
|
32
|
+
command: "meta",
|
|
33
|
+
mod: "mod",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Spec spellings of keys whose `event.key` is something else. */
|
|
37
|
+
const KEY_ALIASES: Record<string, string> = {
|
|
38
|
+
esc: "escape",
|
|
39
|
+
del: "delete",
|
|
40
|
+
ins: "insert",
|
|
41
|
+
return: "enter",
|
|
42
|
+
up: "arrowup",
|
|
43
|
+
down: "arrowdown",
|
|
44
|
+
left: "arrowleft",
|
|
45
|
+
right: "arrowright",
|
|
46
|
+
space: " ",
|
|
47
|
+
spacebar: " ",
|
|
48
|
+
plus: "+",
|
|
49
|
+
pgup: "pageup",
|
|
50
|
+
pgdn: "pagedown",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** The named keys a spec may use besides a single character and `F1`-`F12`. */
|
|
54
|
+
const NAMED_KEYS = new Set([
|
|
55
|
+
"escape",
|
|
56
|
+
"enter",
|
|
57
|
+
"tab",
|
|
58
|
+
"backspace",
|
|
59
|
+
"delete",
|
|
60
|
+
"insert",
|
|
61
|
+
"home",
|
|
62
|
+
"end",
|
|
63
|
+
"pageup",
|
|
64
|
+
"pagedown",
|
|
65
|
+
"arrowup",
|
|
66
|
+
"arrowdown",
|
|
67
|
+
"arrowleft",
|
|
68
|
+
"arrowright",
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
const SYMBOL_CODES: Record<string, string> = { "/": "Slash", ".": "Period", ",": "Comma" };
|
|
72
|
+
|
|
73
|
+
/** The `code` a key has on a QWERTY keyboard, for the keys where one is worth falling back to. */
|
|
74
|
+
function codeFor(key: string): string | undefined {
|
|
75
|
+
if (/^[a-z]$/.test(key)) {
|
|
76
|
+
return `Key${key.toUpperCase()}`;
|
|
77
|
+
}
|
|
78
|
+
if (/^[0-9]$/.test(key)) {
|
|
79
|
+
return `Digit${key}`;
|
|
80
|
+
}
|
|
81
|
+
return SYMBOL_CODES[key];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Parses a shortcut spec: modifiers and one key joined by `+`, in any order and any case - `ctrl+shift+a`, `Alt+N`, `mod+enter`,
|
|
86
|
+
* `Delete`, `?`, `ctrl+/`, `ctrl++`. `mod` is Ctrl on Windows/Linux and Cmd on macOS. Throws on a spec that cannot be understood, so a
|
|
87
|
+
* typo in a key map fails at once rather than silently never matching.
|
|
88
|
+
*/
|
|
89
|
+
export function parseSpec(spec: string): ParsedSpec {
|
|
90
|
+
// A trailing `+` is the plus key itself (`ctrl++`), which a plain split would lose.
|
|
91
|
+
const plusKey = spec.length > 1 && spec.endsWith("++");
|
|
92
|
+
const tokens = (plusKey ? spec.slice(0, -2) : spec).split("+").map((token) => token.trim());
|
|
93
|
+
if (plusKey) {
|
|
94
|
+
tokens.push("+");
|
|
95
|
+
}
|
|
96
|
+
const parsed: ParsedSpec = { spec, key: "", ctrl: false, shift: false, alt: false, meta: false, mod: false };
|
|
97
|
+
for (const token of tokens) {
|
|
98
|
+
if (token === "") {
|
|
99
|
+
throw new Error(`Invalid shortcut "${spec}": empty part.`);
|
|
100
|
+
}
|
|
101
|
+
const lower = token.toLowerCase();
|
|
102
|
+
const modifier = MODIFIERS[lower];
|
|
103
|
+
if (modifier) {
|
|
104
|
+
parsed[modifier] = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (parsed.key !== "") {
|
|
108
|
+
throw new Error(`Invalid shortcut "${spec}": more than one key.`);
|
|
109
|
+
}
|
|
110
|
+
const key = KEY_ALIASES[lower] ?? lower;
|
|
111
|
+
if ([...key].length > 1 && !NAMED_KEYS.has(key) && !/^f([1-9]|1[0-2])$/.test(key)) {
|
|
112
|
+
throw new Error(`Invalid shortcut "${spec}": unknown key "${token}".`);
|
|
113
|
+
}
|
|
114
|
+
parsed.key = key;
|
|
115
|
+
parsed.code = codeFor(key);
|
|
116
|
+
}
|
|
117
|
+
if (parsed.key === "") {
|
|
118
|
+
throw new Error(`Invalid shortcut "${spec}": no key.`);
|
|
119
|
+
}
|
|
120
|
+
return parsed;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The modifiers a spec needs on a given platform, with `mod` turned into Cmd (macOS) or Ctrl. */
|
|
124
|
+
export function resolveModifiers(parsed: ParsedSpec, env: KeyEnvironment): { ctrl: boolean; shift: boolean; alt: boolean; meta: boolean } {
|
|
125
|
+
return {
|
|
126
|
+
ctrl: parsed.ctrl || (parsed.mod && !env.mac),
|
|
127
|
+
shift: parsed.shift,
|
|
128
|
+
alt: parsed.alt,
|
|
129
|
+
meta: parsed.meta || (parsed.mod && env.mac),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Whether the key is a printable symbol whose shifted-ness depends on the layout (`?` is Shift+/ on a US keyboard, not on others). */
|
|
134
|
+
export function isSymbolKey(key: string): boolean {
|
|
135
|
+
return [...key].length === 1 && !/[a-z0-9]/.test(key);
|
|
136
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
|
|
6
|
+
/** What the keyboard layer needs to know about where it runs. */
|
|
7
|
+
export interface KeyEnvironment {
|
|
8
|
+
/** macOS (and iOS/iPadOS): `mod` is Cmd there, and Option is a text-entry modifier. */
|
|
9
|
+
mac: boolean;
|
|
10
|
+
/** The desktop client (`electron-client`), which exposes `window.rapidmx` from its preload script. */
|
|
11
|
+
electron: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** What the server render and the first client render use, so the two agree; the real environment is read after mount. */
|
|
15
|
+
export const SERVER_ENVIRONMENT: KeyEnvironment = { mac: false, electron: false };
|
|
16
|
+
|
|
17
|
+
/** Whether this is an Apple platform. Prefers `navigator.userAgentData` (Chromium), then the older `navigator.platform`. */
|
|
18
|
+
export function isMacPlatform(): boolean {
|
|
19
|
+
if (typeof navigator === "undefined") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const uaData = (navigator as { userAgentData?: { platform?: string } }).userAgentData;
|
|
23
|
+
return /mac|iphone|ipad|ipod/i.test(uaData?.platform || navigator.platform || "");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Whether the page is running inside the desktop client, which is what `window.rapidmx` (its preload's `contextBridge`) tells. */
|
|
27
|
+
export function isElectronClient(): boolean {
|
|
28
|
+
return typeof window !== "undefined" && (window as { rapidmx?: unknown }).rapidmx !== undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The environment as it is right now. Only meaningful in a browser: on the server it is `SERVER_ENVIRONMENT`. */
|
|
32
|
+
export function currentEnvironment(): KeyEnvironment {
|
|
33
|
+
return { mac: isMacPlatform(), electron: isElectronClient() };
|
|
34
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import type { RefObject } from "react";
|
|
6
|
+
import type { ShortcutDef, ShortcutScope } from "./keymap.js";
|
|
7
|
+
import { ParsedSpec } from "./parse.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What a handler does with its key. Returning `false` says it did not handle it (nothing selected, a button that is disabled right now)
|
|
11
|
+
* - the key is then left alone, and a handler of a lower scope may take it. Anything else means it did, and the key is consumed.
|
|
12
|
+
*/
|
|
13
|
+
export type ShortcutHandler = (event: KeyboardEvent) => boolean | void;
|
|
14
|
+
|
|
15
|
+
/** One mounted view's claim on a shortcut. */
|
|
16
|
+
export interface Registration {
|
|
17
|
+
/** Unique per registration. */
|
|
18
|
+
id: number;
|
|
19
|
+
shortcut: ShortcutDef;
|
|
20
|
+
scope: ShortcutScope;
|
|
21
|
+
/** Called at event time; reads whatever the component holds now. */
|
|
22
|
+
run: ShortcutHandler;
|
|
23
|
+
/** Applies only to events whose target is inside this element (a compose window). */
|
|
24
|
+
container?: RefObject<Element | null>;
|
|
25
|
+
keys: ParsedSpec[];
|
|
26
|
+
electronKeys: ParsedSpec[];
|
|
27
|
+
/** Later registrations win over earlier ones in the same scope. */
|
|
28
|
+
order: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The shortcuts that are mounted right now. Components add and remove their claims as they mount and unmount, so a page switch changes
|
|
33
|
+
* what a key does with nothing to re-wire; the dispatcher (`dispatchKeyEvent()`) looks handlers up here at the time of the key press,
|
|
34
|
+
* and the help dialog lists what is here.
|
|
35
|
+
*/
|
|
36
|
+
export class ShortcutRegistry {
|
|
37
|
+
private registrations: readonly Registration[] = [];
|
|
38
|
+
private counter = 0;
|
|
39
|
+
private listeners = new Set<() => void>();
|
|
40
|
+
|
|
41
|
+
/** Adds a claim; returns what removes it. */
|
|
42
|
+
add(claim: Omit<Registration, "id" | "order">): () => void {
|
|
43
|
+
const registration: Registration = { ...claim, id: ++this.counter, order: this.counter };
|
|
44
|
+
this.registrations = [...this.registrations, registration];
|
|
45
|
+
this.publish();
|
|
46
|
+
return () => {
|
|
47
|
+
this.registrations = this.registrations.filter((existing) => existing.id !== registration.id);
|
|
48
|
+
this.publish();
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The current claims, oldest first. A new array whenever they change (so it can be a `useSyncExternalStore()` snapshot). */
|
|
53
|
+
getSnapshot = (): readonly Registration[] => this.registrations;
|
|
54
|
+
|
|
55
|
+
subscribe = (listener: () => void): (() => void) => {
|
|
56
|
+
this.listeners.add(listener);
|
|
57
|
+
return () => {
|
|
58
|
+
this.listeners.delete(listener);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
private publish(): void {
|
|
63
|
+
this.listeners.forEach((listener) => listener());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
|
|
6
|
+
/** `<input>` types that take no typed text, so a letter pressed on one is a shortcut, not input. (Radios and ranges use the arrows.) */
|
|
7
|
+
const NON_TEXT_INPUT_TYPES = new Set(["button", "checkbox", "submit", "reset", "image", "file", "color"]);
|
|
8
|
+
|
|
9
|
+
/** Roles whose members have keys of their own (arrows, Enter, Escape, type-ahead): a bare key pressed inside one belongs to the widget. */
|
|
10
|
+
const WIDGET_SELECTOR = [
|
|
11
|
+
"menu",
|
|
12
|
+
"menubar",
|
|
13
|
+
"listbox",
|
|
14
|
+
"tablist",
|
|
15
|
+
"tree",
|
|
16
|
+
"grid",
|
|
17
|
+
"radiogroup",
|
|
18
|
+
"slider",
|
|
19
|
+
"spinbutton",
|
|
20
|
+
"combobox",
|
|
21
|
+
]
|
|
22
|
+
.map((role) => `[role="${role}"]`)
|
|
23
|
+
.join(",");
|
|
24
|
+
|
|
25
|
+
/** Elements Enter (and Space) already does something on. */
|
|
26
|
+
const ACTIVATABLE_SELECTOR = 'a[href], button, summary, [role="button"], [role="link"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"], [role="tab"], [role="option"]';
|
|
27
|
+
|
|
28
|
+
/** An open popup's trigger: Escape closes the popup, so it is not a shortcut then. */
|
|
29
|
+
const OPEN_POPUP_TRIGGER = '[aria-haspopup][aria-expanded="true"], [role="combobox"][aria-expanded="true"]';
|
|
30
|
+
|
|
31
|
+
function elementOf(target: EventTarget | null): Element | null {
|
|
32
|
+
return target instanceof Element ? target : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether the event target takes typed text: a text field, a select, a textarea, or anything contenteditable (the rich-text editor). */
|
|
36
|
+
export function isTextEntry(target: EventTarget | null): boolean {
|
|
37
|
+
const element = elementOf(target);
|
|
38
|
+
if (!element) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const tag = element.tagName;
|
|
42
|
+
if (tag === "TEXTAREA" || tag === "SELECT") {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (tag === "INPUT") {
|
|
46
|
+
return !NON_TEXT_INPUT_TYPES.has((element as HTMLInputElement).type);
|
|
47
|
+
}
|
|
48
|
+
return !!element.closest('[contenteditable]:not([contenteditable="false"]), [role="textbox"], [role="searchbox"]');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Whether the target is inside a widget that reads bare keys itself (an open menu, a listbox, a tab list, ...). */
|
|
52
|
+
export function isInWidget(target: EventTarget | null): boolean {
|
|
53
|
+
return !!elementOf(target)?.closest(WIDGET_SELECTOR);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Whether Enter/Space on the target already activates it (a button, a link, a menu item). */
|
|
57
|
+
export function isActivatable(target: EventTarget | null): boolean {
|
|
58
|
+
return !!elementOf(target)?.closest(ACTIVATABLE_SELECTOR);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Whether the target is the trigger of a popup that is open right now (or the combobox that owns an open list). */
|
|
62
|
+
export function isPopupOpenAt(target: EventTarget | null): boolean {
|
|
63
|
+
return !!elementOf(target)?.closest(OPEN_POPUP_TRIGGER);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Whether a modal dialog (`aria-modal="true"`: react-shared's `Modal` and `Drawer`, the unlock prompts, ...) is on screen. */
|
|
67
|
+
export function isModalOpen(doc: Document): boolean {
|
|
68
|
+
return doc.querySelector('[aria-modal="true"]') !== null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Whether the target is inside a popover that is a dialog of its own (the emoji and GIF pickers, the send-later picker): Escape is theirs, not a view's. A region that declares a shortcut scope (a compose window) is not one. */
|
|
72
|
+
export function isInPopoverDialog(target: EventTarget | null): boolean {
|
|
73
|
+
return !!elementOf(target)?.closest('[role="dialog"]:not([data-shortcut-scope])');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The `data-shortcut-scope` of the region the target is in (a compose window), if any. */
|
|
77
|
+
export function regionScopeOf(target: EventTarget | null): string | undefined {
|
|
78
|
+
return elementOf(target)?.closest("[data-shortcut-scope]")?.getAttribute("data-shortcut-scope") ?? undefined;
|
|
79
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { RefObject, useEffect, useMemo, useRef } from "react";
|
|
6
|
+
import type { ShortcutDef, ShortcutScope } from "./keymap.js";
|
|
7
|
+
import { parseSpec } from "./parse.js";
|
|
8
|
+
import type { ShortcutHandler } from "./registry.js";
|
|
9
|
+
import { useShortcutRegistry } from "./ShortcutProvider.js";
|
|
10
|
+
|
|
11
|
+
export interface UseShortcutOptions {
|
|
12
|
+
/** Overrides the scope the shortcut is defined with - required for a bare spec string, which has none. Default `global`. */
|
|
13
|
+
scope?: ShortcutScope;
|
|
14
|
+
/** Registers only while true: a view offers a shortcut only when it can really do the thing. Default true. */
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/** Restricts it to events whose target is inside this element (a compose window). */
|
|
17
|
+
container?: RefObject<Element | null>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Claims a shortcut for as long as the calling component is mounted (and `enabled`). `shortcut` is an entry of `SHORTCUTS` - which is what
|
|
22
|
+
* the help dialog and tooltips describe - or a bare spec such as `"alt+n"` for a one-off. The handler is read at the time of the key press,
|
|
23
|
+
* so it always sees the component's current state without the registration being redone; return `false` from it to decline the key.
|
|
24
|
+
*
|
|
25
|
+
* Does nothing outside a `ShortcutProvider`.
|
|
26
|
+
*/
|
|
27
|
+
export function useShortcut(shortcut: ShortcutDef | string, handler: ShortcutHandler, options: UseShortcutOptions = {}): void {
|
|
28
|
+
const { scope, enabled = true, container } = options;
|
|
29
|
+
const registry = useShortcutRegistry();
|
|
30
|
+
const handlerRef = useRef(handler);
|
|
31
|
+
handlerRef.current = handler;
|
|
32
|
+
const def = useMemo<ShortcutDef>(
|
|
33
|
+
() => (typeof shortcut === "string" ? { id: `custom:${shortcut}`, keys: [shortcut], label: shortcut, scope: "global" } : shortcut),
|
|
34
|
+
[shortcut],
|
|
35
|
+
);
|
|
36
|
+
const resolvedScope = scope ?? def.scope;
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!registry || !enabled) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return registry.add({
|
|
42
|
+
shortcut: def,
|
|
43
|
+
scope: resolvedScope,
|
|
44
|
+
run: (event) => handlerRef.current(event),
|
|
45
|
+
container,
|
|
46
|
+
keys: def.keys.map(parseSpec),
|
|
47
|
+
electronKeys: (def.electronKeys ?? []).map(parseSpec),
|
|
48
|
+
});
|
|
49
|
+
}, [registry, enabled, def, resolvedScope, container]);
|
|
50
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { ariaKeyShortcuts, withHint } from "./format.js";
|
|
6
|
+
import type { ShortcutDef } from "./keymap.js";
|
|
7
|
+
import { useKeyEnvironment } from "./ShortcutProvider.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What a control that a keyboard shortcut also triggers gets: a tooltip naming the key - `Reply (Ctrl+R)`, in this platform's own key names -
|
|
11
|
+
* and `aria-keyshortcuts` for assistive technology. The accessible name is left alone (the control keeps its own label), so a tooltip suffix never
|
|
12
|
+
* changes what a screen reader or a test finds it by. With `active` false - the shortcut isn't registered right now - it is just the plain label.
|
|
13
|
+
*/
|
|
14
|
+
export function useShortcutProps(label: string, shortcut: ShortcutDef, active = true): { title: string; "aria-keyshortcuts"?: string } {
|
|
15
|
+
const env = useKeyEnvironment();
|
|
16
|
+
return active ? { title: withHint(label, shortcut, env), "aria-keyshortcuts": ariaKeyShortcuts(shortcut, env) } : { title: label };
|
|
17
|
+
}
|