@rapidmx/web-client 0.9.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.
- package/README.md +192 -88
- package/apps/shared/auth/accountUrl.ts +9 -0
- package/apps/shared/auth/adminAccess.ts +99 -0
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +2 -1
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +8 -2
- package/apps/shared/components/contacts/ContactsToolbar.tsx +125 -115
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +15 -3
- package/apps/shared/components/layout/AppShell.tsx +411 -288
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -389
- package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -164
- package/apps/shared/components/layout/UserMenu.tsx +303 -185
- package/apps/shared/components/mail/ConversationList.tsx +269 -262
- package/apps/shared/components/mail/ConversationThreadPane.tsx +475 -434
- package/apps/shared/components/mail/LazyReadingPane.tsx +115 -0
- package/apps/shared/components/mail/MailSelectionBar.tsx +235 -222
- package/apps/shared/components/mail/MessageDetailPane.tsx +1458 -1387
- package/apps/shared/components/mail/NewMailToasts.tsx +141 -0
- package/apps/shared/components/mail/compose/ComposeContext.tsx +279 -160
- package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -418
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1842 -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/quotedBody.ts +161 -100
- package/apps/shared/components/mail/layout/MailShell.tsx +476 -472
- package/apps/shared/components/mail/unreadStyle.tsx +75 -0
- package/apps/shared/components/settings/layout/SettingsShell.tsx +252 -240
- package/apps/shared/components/tasks/layout/TasksShell.tsx +15 -3
- 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 +302 -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/useMailConnection.ts +150 -0
- package/apps/shared/mail/useMailLiveUpdates.ts +232 -224
- package/apps/shared/mail/useMarkMessageRead.ts +47 -0
- package/apps/shared/mail/useNewMailNotifications.ts +163 -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/search/LocalIndexLifecycle.tsx +114 -98
- package/apps/shared/styles/app.css +28 -10
- package/apps/www/_routedPage.tsx +24 -0
- package/apps/www/_routes.ts +35 -0
- package/apps/www/calendar/index.tsx +55 -19
- package/apps/www/contacts/[uid].tsx +112 -107
- package/apps/www/contacts/index.tsx +584 -567
- package/apps/www/index.tsx +2280 -1917
- package/apps/www/messages/[uid].tsx +106 -101
- package/apps/www/settings/auto-reply/index.tsx +4 -1
- package/apps/www/settings/encryption/index.tsx +1252 -1249
- package/apps/www/settings/filters/[uid].tsx +4 -1
- package/apps/www/settings/filters/index.tsx +102 -99
- package/apps/www/settings/filters/new/index.tsx +138 -133
- package/apps/www/settings/labels/index.tsx +204 -201
- package/apps/www/settings/privacy/index.tsx +4 -1
- package/apps/www/settings/read-receipts/index.tsx +4 -1
- package/apps/www/settings/sharing/index.tsx +277 -274
- package/apps/www/settings/signatures/[uid].tsx +170 -167
- package/apps/www/settings/signatures/index.tsx +88 -85
- package/apps/www/settings/signatures/new/index.tsx +134 -129
- package/apps/www/tasks/index.tsx +18 -2
- 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/settings/DomainDnsSetup.js +1 -1
- 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/ContactsToolbar.d.ts +3 -1
- package/dist/apps/shared/components/contacts/ContactsToolbar.js +7 -4
- package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +1 -1
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +15 -5
- package/dist/apps/shared/components/layout/AppShell.d.ts +29 -4
- package/dist/apps/shared/components/layout/AppShell.js +73 -14
- 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/UserMenu.d.ts +19 -3
- package/dist/apps/shared/components/layout/UserMenu.js +52 -5
- package/dist/apps/shared/components/mail/ConversationList.js +4 -11
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +4 -1
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +52 -27
- package/dist/apps/shared/components/mail/LazyReadingPane.d.ts +9 -0
- package/dist/apps/shared/components/mail/LazyReadingPane.js +82 -0
- package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +4 -1
- package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -3
- package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +7 -1
- package/dist/apps/shared/components/mail/MessageDetailPane.js +83 -34
- package/dist/apps/shared/components/mail/NewMailToasts.d.ts +19 -0
- package/dist/apps/shared/components/mail/NewMailToasts.js +55 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +30 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +71 -5
- package/dist/apps/shared/components/mail/compose/ComposeToolbar.js +4 -3
- package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +1 -1
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +98 -22
- 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/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 +12 -4
- package/dist/apps/shared/components/mail/layout/MailShell.js +76 -96
- 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/layout/SettingsShell.d.ts +1 -1
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +15 -5
- package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +1 -1
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +15 -5
- 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 +212 -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/useMailConnection.d.ts +55 -0
- package/dist/apps/shared/mail/useMailConnection.js +96 -0
- package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +13 -6
- package/dist/apps/shared/mail/useMailLiveUpdates.js +28 -26
- 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 +41 -0
- package/dist/apps/shared/mail/useNewMailNotifications.js +110 -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/search/LocalIndexLifecycle.js +17 -3
- package/dist/apps/shared/styles/app.css +28 -10
- 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 +29 -0
- package/dist/apps/www/calendar/index.d.ts +2 -2
- package/dist/apps/www/calendar/index.js +39 -8
- package/dist/apps/www/contacts/[uid].d.ts +3 -9
- package/dist/apps/www/contacts/[uid].js +6 -2
- package/dist/apps/www/contacts/index.d.ts +2 -2
- package/dist/apps/www/contacts/index.js +17 -4
- package/dist/apps/www/index.d.ts +2 -2
- package/dist/apps/www/index.js +301 -35
- package/dist/apps/www/messages/[uid].d.ts +3 -7
- package/dist/apps/www/messages/[uid].js +7 -4
- package/dist/apps/www/settings/auto-reply/index.d.ts +2 -2
- package/dist/apps/www/settings/auto-reply/index.js +3 -1
- package/dist/apps/www/settings/encryption/index.d.ts +2 -2
- package/dist/apps/www/settings/encryption/index.js +3 -1
- package/dist/apps/www/settings/filters/[uid].d.ts +2 -2
- package/dist/apps/www/settings/filters/[uid].js +3 -1
- 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 +6 -2
- 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 +3 -1
- package/dist/apps/www/settings/read-receipts/index.d.ts +2 -2
- package/dist/apps/www/settings/read-receipts/index.js +3 -1
- package/dist/apps/www/settings/sharing/index.d.ts +2 -2
- package/dist/apps/www/settings/sharing/index.js +3 -1
- package/dist/apps/www/settings/signatures/[uid].d.ts +2 -2
- package/dist/apps/www/settings/signatures/[uid].js +3 -1
- 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 +6 -2
- package/dist/apps/www/tasks/index.d.ts +2 -2
- package/dist/apps/www/tasks/index.js +15 -3
- package/package.json +2 -2
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
/** The scopes the help dialog lists, in the order it lists them. */
|
|
6
|
+
export const HELP_SCOPES = ["global", "mail", "compose", "calendar", "contacts", "tasks"];
|
|
7
|
+
export const SCOPE_LABELS = {
|
|
8
|
+
global: "Global",
|
|
9
|
+
mail: "Mail",
|
|
10
|
+
compose: "Compose",
|
|
11
|
+
calendar: "Calendar",
|
|
12
|
+
contacts: "Contacts",
|
|
13
|
+
tasks: "Tasks",
|
|
14
|
+
dialog: "Dialog",
|
|
15
|
+
};
|
|
16
|
+
function def(shortcut) {
|
|
17
|
+
return shortcut;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 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
|
|
21
|
+
* 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
|
|
22
|
+
* 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.
|
|
23
|
+
* Ctrl+Q (mark read) stays Ctrl on a Mac because Cmd+Q is the system's Quit.
|
|
24
|
+
*/
|
|
25
|
+
export const SHORTCUTS = {
|
|
26
|
+
global: {
|
|
27
|
+
account: def({ id: "go.account", keys: ["ctrl+shift+a"], label: "Go to Account", scope: "global" }),
|
|
28
|
+
settings: def({ id: "go.settings", keys: ["ctrl+shift+s"], label: "Go to Settings", scope: "global" }),
|
|
29
|
+
contacts: def({ id: "go.contacts", keys: ["ctrl+shift+b"], label: "Go to Contacts", scope: "global" }),
|
|
30
|
+
mail: def({ id: "go.mail", keys: ["ctrl+shift+m"], label: "Go to Mail", scope: "global" }),
|
|
31
|
+
calendar: def({ id: "go.calendar", keys: ["ctrl+shift+c"], label: "Go to Calendar", scope: "global" }),
|
|
32
|
+
tasks: def({ id: "go.tasks", keys: ["ctrl+shift+l"], electronKeys: ["ctrl+shift+t"], label: "Go to Tasks", scope: "global" }),
|
|
33
|
+
help: def({ id: "help", keys: ["?", "ctrl+/"], label: "Keyboard shortcuts", scope: "global" }),
|
|
34
|
+
},
|
|
35
|
+
mail: {
|
|
36
|
+
create: def({ id: "mail.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New message", scope: "mail" }),
|
|
37
|
+
reply: def({ id: "mail.reply", keys: ["mod+r"], label: "Reply", scope: "mail" }),
|
|
38
|
+
replyAll: def({ id: "mail.replyAll", keys: ["mod+shift+r"], label: "Reply all", scope: "mail" }),
|
|
39
|
+
forward: def({ id: "mail.forward", keys: ["mod+shift+f"], label: "Forward", scope: "mail" }),
|
|
40
|
+
delete: def({ id: "mail.delete", keys: ["mod+d", "delete"], label: "Delete", scope: "mail" }),
|
|
41
|
+
archive: def({ id: "mail.archive", keys: ["e", "backspace"], label: "Archive", scope: "mail" }),
|
|
42
|
+
move: def({ id: "mail.move", keys: ["mod+shift+v"], label: "Move to folder", scope: "mail" }),
|
|
43
|
+
markRead: def({ id: "mail.markRead", keys: ["ctrl+q"], label: "Mark as read", scope: "mail" }),
|
|
44
|
+
markUnread: def({ id: "mail.markUnread", keys: ["mod+u"], label: "Mark as unread", scope: "mail" }),
|
|
45
|
+
flag: def({ id: "mail.flag", keys: ["insert"], label: "Flag or unflag", scope: "mail" }),
|
|
46
|
+
next: def({ id: "mail.next", keys: ["arrowdown", "j"], label: "Next message", scope: "mail", repeat: true }),
|
|
47
|
+
previous: def({ id: "mail.previous", keys: ["arrowup", "k"], label: "Previous message", scope: "mail", repeat: true }),
|
|
48
|
+
nextUnread: def({ id: "mail.nextUnread", keys: ["ctrl+."], label: "Next unread message", scope: "mail" }),
|
|
49
|
+
previousUnread: def({ id: "mail.previousUnread", keys: ["ctrl+,"], label: "Previous unread message", scope: "mail" }),
|
|
50
|
+
open: def({ id: "mail.open", keys: ["enter"], label: "Open the message on its own page", scope: "mail", allowOnActivatable: true }),
|
|
51
|
+
close: def({ id: "mail.close", keys: ["escape"], label: "Clear the selection", scope: "mail" }),
|
|
52
|
+
search: def({ id: "mail.search", keys: ["/", "mod+e"], label: "Search mail", scope: "mail" }),
|
|
53
|
+
},
|
|
54
|
+
compose: {
|
|
55
|
+
create: def({ id: "compose.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New message", scope: "compose" }),
|
|
56
|
+
send: def({ id: "compose.send", keys: ["mod+enter"], label: "Send", scope: "compose" }),
|
|
57
|
+
saveDraft: def({ id: "compose.saveDraft", keys: ["mod+s"], label: "Save draft", scope: "compose" }),
|
|
58
|
+
close: def({ id: "compose.close", keys: ["escape"], label: "Close (keeps the draft)", scope: "compose" }),
|
|
59
|
+
},
|
|
60
|
+
calendar: {
|
|
61
|
+
create: def({ id: "calendar.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New event", scope: "calendar" }),
|
|
62
|
+
today: def({ id: "calendar.today", keys: ["t"], label: "Go to today", scope: "calendar" }),
|
|
63
|
+
previous: def({ id: "calendar.previous", keys: ["arrowleft", "mod+arrowleft"], label: "Previous period", scope: "calendar", repeat: true }),
|
|
64
|
+
next: def({ id: "calendar.next", keys: ["arrowright", "mod+arrowright"], label: "Next period", scope: "calendar", repeat: true }),
|
|
65
|
+
day: def({ id: "calendar.day", keys: ["ctrl+alt+1"], label: "Day view", scope: "calendar" }),
|
|
66
|
+
workWeek: def({ id: "calendar.workWeek", keys: ["ctrl+alt+2"], label: "Work week view", scope: "calendar" }),
|
|
67
|
+
week: def({ id: "calendar.week", keys: ["ctrl+alt+3"], label: "Week view", scope: "calendar" }),
|
|
68
|
+
month: def({ id: "calendar.month", keys: ["ctrl+alt+4"], label: "Month view", scope: "calendar" }),
|
|
69
|
+
},
|
|
70
|
+
contacts: {
|
|
71
|
+
create: def({ id: "contacts.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New contact", scope: "contacts" }),
|
|
72
|
+
search: def({ id: "contacts.search", keys: ["/", "mod+e"], label: "Search contacts", scope: "contacts" }),
|
|
73
|
+
},
|
|
74
|
+
tasks: {
|
|
75
|
+
create: def({ id: "tasks.new", keys: ["alt+n"], electronKeys: ["mod+n"], label: "New task", scope: "tasks" }),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
/** Every shortcut of the map flattened, in listing order. */
|
|
79
|
+
export const ALL_SHORTCUTS = Object.values(SHORTCUTS).flatMap((group) => Object.values(group));
|
|
80
|
+
/** Where a shortcut sits in the listing, for ordering registrations that arrive in whatever order components mount. */
|
|
81
|
+
export function shortcutRank(shortcut) {
|
|
82
|
+
const index = ALL_SHORTCUTS.findIndex((candidate) => candidate.id === shortcut.id);
|
|
83
|
+
return index === -1 ? ALL_SHORTCUTS.length : index;
|
|
84
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ParsedSpec } from "./parse.js";
|
|
2
|
+
import type { KeyEnvironment } from "./platform.js";
|
|
3
|
+
/** The part of a `KeyboardEvent` matching reads. */
|
|
4
|
+
export interface KeyEventLike {
|
|
5
|
+
key: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
ctrlKey: boolean;
|
|
8
|
+
shiftKey: boolean;
|
|
9
|
+
altKey: boolean;
|
|
10
|
+
metaKey: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Whether a key event is the shortcut `parsed`, on `env`.
|
|
14
|
+
*
|
|
15
|
+
* 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 -
|
|
16
|
+
* Dvorak, AZERTY - and falls back to `event.code` only when `event.key` is not a Latin character at all: macOS Option+N produces a
|
|
17
|
+
* dead key or `~`-like symbol, and a Cyrillic or Greek layout produces `ф`/`α` for the key that is A on a QWERTY board. Modifiers must
|
|
18
|
+
* match exactly (Ctrl+Shift+R is not Ctrl+R), except Shift for a printable symbol, which some layouts need to type it (`?`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function matchesEvent(parsed: ParsedSpec, event: KeyEventLike, env: KeyEnvironment): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { isSymbolKey, resolveModifiers } from "./parse.js";
|
|
6
|
+
/** Whether `key` is what a Latin layout produces for a printable key: then `event.key` says which key it is, whatever `event.code` is. */
|
|
7
|
+
function isAsciiKey(key) {
|
|
8
|
+
return /^[\x21-\x7e]$/.test(key);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether a key event is the shortcut `parsed`, on `env`.
|
|
12
|
+
*
|
|
13
|
+
* 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 -
|
|
14
|
+
* Dvorak, AZERTY - and falls back to `event.code` only when `event.key` is not a Latin character at all: macOS Option+N produces a
|
|
15
|
+
* dead key or `~`-like symbol, and a Cyrillic or Greek layout produces `ф`/`α` for the key that is A on a QWERTY board. Modifiers must
|
|
16
|
+
* match exactly (Ctrl+Shift+R is not Ctrl+R), except Shift for a printable symbol, which some layouts need to type it (`?`).
|
|
17
|
+
*/
|
|
18
|
+
export function matchesEvent(parsed, event, env) {
|
|
19
|
+
const modifiers = resolveModifiers(parsed, env);
|
|
20
|
+
if (event.ctrlKey !== modifiers.ctrl || event.altKey !== modifiers.alt || event.metaKey !== modifiers.meta) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (event.shiftKey !== modifiers.shift && !(isSymbolKey(parsed.key) && !parsed.shift)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const key = (event.key ?? "").toLowerCase();
|
|
27
|
+
if (key === parsed.key) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return !!parsed.code && event.code === parsed.code && !isAsciiKey(key);
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { KeyEnvironment } from "./platform.js";
|
|
2
|
+
/** A shortcut such as `ctrl+shift+a`, `alt+n`, `Delete` or `?`, broken into what a key event is compared with. */
|
|
3
|
+
export interface ParsedSpec {
|
|
4
|
+
/** The spec as written. */
|
|
5
|
+
spec: string;
|
|
6
|
+
/** The key, lower-case: a letter or digit, a symbol (`?`, `/`, `.`, `,`), or a named key (`enter`, `delete`, `arrowup`, ...). */
|
|
7
|
+
key: string;
|
|
8
|
+
ctrl: boolean;
|
|
9
|
+
shift: boolean;
|
|
10
|
+
alt: boolean;
|
|
11
|
+
meta: boolean;
|
|
12
|
+
/** Ctrl on Windows and Linux, Cmd on macOS - resolved against the environment by `resolveModifiers()`. */
|
|
13
|
+
mod: boolean;
|
|
14
|
+
/** The `KeyboardEvent.code` of the key on a QWERTY keyboard, for layouts where `event.key` is not the letter (see `match.ts`). */
|
|
15
|
+
code?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parses a shortcut spec: modifiers and one key joined by `+`, in any order and any case - `ctrl+shift+a`, `Alt+N`, `mod+enter`,
|
|
19
|
+
* `Delete`, `?`, `ctrl+/`, `ctrl++`. `mod` is Ctrl on Windows/Linux and Cmd on macOS. Throws on a spec that cannot be understood, so a
|
|
20
|
+
* typo in a key map fails at once rather than silently never matching.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseSpec(spec: string): ParsedSpec;
|
|
23
|
+
/** The modifiers a spec needs on a given platform, with `mod` turned into Cmd (macOS) or Ctrl. */
|
|
24
|
+
export declare function resolveModifiers(parsed: ParsedSpec, env: KeyEnvironment): {
|
|
25
|
+
ctrl: boolean;
|
|
26
|
+
shift: boolean;
|
|
27
|
+
alt: boolean;
|
|
28
|
+
meta: boolean;
|
|
29
|
+
};
|
|
30
|
+
/** Whether the key is a printable symbol whose shifted-ness depends on the layout (`?` is Shift+/ on a US keyboard, not on others). */
|
|
31
|
+
export declare function isSymbolKey(key: string): boolean;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const MODIFIERS = {
|
|
2
|
+
ctrl: "ctrl",
|
|
3
|
+
control: "ctrl",
|
|
4
|
+
shift: "shift",
|
|
5
|
+
alt: "alt",
|
|
6
|
+
option: "alt",
|
|
7
|
+
opt: "alt",
|
|
8
|
+
meta: "meta",
|
|
9
|
+
cmd: "meta",
|
|
10
|
+
command: "meta",
|
|
11
|
+
mod: "mod",
|
|
12
|
+
};
|
|
13
|
+
/** Spec spellings of keys whose `event.key` is something else. */
|
|
14
|
+
const KEY_ALIASES = {
|
|
15
|
+
esc: "escape",
|
|
16
|
+
del: "delete",
|
|
17
|
+
ins: "insert",
|
|
18
|
+
return: "enter",
|
|
19
|
+
up: "arrowup",
|
|
20
|
+
down: "arrowdown",
|
|
21
|
+
left: "arrowleft",
|
|
22
|
+
right: "arrowright",
|
|
23
|
+
space: " ",
|
|
24
|
+
spacebar: " ",
|
|
25
|
+
plus: "+",
|
|
26
|
+
pgup: "pageup",
|
|
27
|
+
pgdn: "pagedown",
|
|
28
|
+
};
|
|
29
|
+
/** The named keys a spec may use besides a single character and `F1`-`F12`. */
|
|
30
|
+
const NAMED_KEYS = new Set([
|
|
31
|
+
"escape",
|
|
32
|
+
"enter",
|
|
33
|
+
"tab",
|
|
34
|
+
"backspace",
|
|
35
|
+
"delete",
|
|
36
|
+
"insert",
|
|
37
|
+
"home",
|
|
38
|
+
"end",
|
|
39
|
+
"pageup",
|
|
40
|
+
"pagedown",
|
|
41
|
+
"arrowup",
|
|
42
|
+
"arrowdown",
|
|
43
|
+
"arrowleft",
|
|
44
|
+
"arrowright",
|
|
45
|
+
]);
|
|
46
|
+
const SYMBOL_CODES = { "/": "Slash", ".": "Period", ",": "Comma" };
|
|
47
|
+
/** The `code` a key has on a QWERTY keyboard, for the keys where one is worth falling back to. */
|
|
48
|
+
function codeFor(key) {
|
|
49
|
+
if (/^[a-z]$/.test(key)) {
|
|
50
|
+
return `Key${key.toUpperCase()}`;
|
|
51
|
+
}
|
|
52
|
+
if (/^[0-9]$/.test(key)) {
|
|
53
|
+
return `Digit${key}`;
|
|
54
|
+
}
|
|
55
|
+
return SYMBOL_CODES[key];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parses a shortcut spec: modifiers and one key joined by `+`, in any order and any case - `ctrl+shift+a`, `Alt+N`, `mod+enter`,
|
|
59
|
+
* `Delete`, `?`, `ctrl+/`, `ctrl++`. `mod` is Ctrl on Windows/Linux and Cmd on macOS. Throws on a spec that cannot be understood, so a
|
|
60
|
+
* typo in a key map fails at once rather than silently never matching.
|
|
61
|
+
*/
|
|
62
|
+
export function parseSpec(spec) {
|
|
63
|
+
// A trailing `+` is the plus key itself (`ctrl++`), which a plain split would lose.
|
|
64
|
+
const plusKey = spec.length > 1 && spec.endsWith("++");
|
|
65
|
+
const tokens = (plusKey ? spec.slice(0, -2) : spec).split("+").map((token) => token.trim());
|
|
66
|
+
if (plusKey) {
|
|
67
|
+
tokens.push("+");
|
|
68
|
+
}
|
|
69
|
+
const parsed = { spec, key: "", ctrl: false, shift: false, alt: false, meta: false, mod: false };
|
|
70
|
+
for (const token of tokens) {
|
|
71
|
+
if (token === "") {
|
|
72
|
+
throw new Error(`Invalid shortcut "${spec}": empty part.`);
|
|
73
|
+
}
|
|
74
|
+
const lower = token.toLowerCase();
|
|
75
|
+
const modifier = MODIFIERS[lower];
|
|
76
|
+
if (modifier) {
|
|
77
|
+
parsed[modifier] = true;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (parsed.key !== "") {
|
|
81
|
+
throw new Error(`Invalid shortcut "${spec}": more than one key.`);
|
|
82
|
+
}
|
|
83
|
+
const key = KEY_ALIASES[lower] ?? lower;
|
|
84
|
+
if ([...key].length > 1 && !NAMED_KEYS.has(key) && !/^f([1-9]|1[0-2])$/.test(key)) {
|
|
85
|
+
throw new Error(`Invalid shortcut "${spec}": unknown key "${token}".`);
|
|
86
|
+
}
|
|
87
|
+
parsed.key = key;
|
|
88
|
+
parsed.code = codeFor(key);
|
|
89
|
+
}
|
|
90
|
+
if (parsed.key === "") {
|
|
91
|
+
throw new Error(`Invalid shortcut "${spec}": no key.`);
|
|
92
|
+
}
|
|
93
|
+
return parsed;
|
|
94
|
+
}
|
|
95
|
+
/** The modifiers a spec needs on a given platform, with `mod` turned into Cmd (macOS) or Ctrl. */
|
|
96
|
+
export function resolveModifiers(parsed, env) {
|
|
97
|
+
return {
|
|
98
|
+
ctrl: parsed.ctrl || (parsed.mod && !env.mac),
|
|
99
|
+
shift: parsed.shift,
|
|
100
|
+
alt: parsed.alt,
|
|
101
|
+
meta: parsed.meta || (parsed.mod && env.mac),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Whether the key is a printable symbol whose shifted-ness depends on the layout (`?` is Shift+/ on a US keyboard, not on others). */
|
|
105
|
+
export function isSymbolKey(key) {
|
|
106
|
+
return [...key].length === 1 && !/[a-z0-9]/.test(key);
|
|
107
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** What the keyboard layer needs to know about where it runs. */
|
|
2
|
+
export interface KeyEnvironment {
|
|
3
|
+
/** macOS (and iOS/iPadOS): `mod` is Cmd there, and Option is a text-entry modifier. */
|
|
4
|
+
mac: boolean;
|
|
5
|
+
/** The desktop client (`electron-client`), which exposes `window.rapidmx` from its preload script. */
|
|
6
|
+
electron: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** What the server render and the first client render use, so the two agree; the real environment is read after mount. */
|
|
9
|
+
export declare const SERVER_ENVIRONMENT: KeyEnvironment;
|
|
10
|
+
/** Whether this is an Apple platform. Prefers `navigator.userAgentData` (Chromium), then the older `navigator.platform`. */
|
|
11
|
+
export declare function isMacPlatform(): boolean;
|
|
12
|
+
/** Whether the page is running inside the desktop client, which is what `window.rapidmx` (its preload's `contextBridge`) tells. */
|
|
13
|
+
export declare function isElectronClient(): boolean;
|
|
14
|
+
/** The environment as it is right now. Only meaningful in a browser: on the server it is `SERVER_ENVIRONMENT`. */
|
|
15
|
+
export declare function currentEnvironment(): KeyEnvironment;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
/** What the server render and the first client render use, so the two agree; the real environment is read after mount. */
|
|
6
|
+
export const SERVER_ENVIRONMENT = { mac: false, electron: false };
|
|
7
|
+
/** Whether this is an Apple platform. Prefers `navigator.userAgentData` (Chromium), then the older `navigator.platform`. */
|
|
8
|
+
export function isMacPlatform() {
|
|
9
|
+
if (typeof navigator === "undefined") {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const uaData = navigator.userAgentData;
|
|
13
|
+
return /mac|iphone|ipad|ipod/i.test(uaData?.platform || navigator.platform || "");
|
|
14
|
+
}
|
|
15
|
+
/** Whether the page is running inside the desktop client, which is what `window.rapidmx` (its preload's `contextBridge`) tells. */
|
|
16
|
+
export function isElectronClient() {
|
|
17
|
+
return typeof window !== "undefined" && window.rapidmx !== undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The environment as it is right now. Only meaningful in a browser: on the server it is `SERVER_ENVIRONMENT`. */
|
|
20
|
+
export function currentEnvironment() {
|
|
21
|
+
return { mac: isMacPlatform(), electron: isElectronClient() };
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { ShortcutDef, ShortcutScope } from "./keymap.js";
|
|
3
|
+
import { ParsedSpec } from "./parse.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a handler does with its key. Returning `false` says it did not handle it (nothing selected, a button that is disabled right now)
|
|
6
|
+
* - 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.
|
|
7
|
+
*/
|
|
8
|
+
export type ShortcutHandler = (event: KeyboardEvent) => boolean | void;
|
|
9
|
+
/** One mounted view's claim on a shortcut. */
|
|
10
|
+
export interface Registration {
|
|
11
|
+
/** Unique per registration. */
|
|
12
|
+
id: number;
|
|
13
|
+
shortcut: ShortcutDef;
|
|
14
|
+
scope: ShortcutScope;
|
|
15
|
+
/** Called at event time; reads whatever the component holds now. */
|
|
16
|
+
run: ShortcutHandler;
|
|
17
|
+
/** Applies only to events whose target is inside this element (a compose window). */
|
|
18
|
+
container?: RefObject<Element | null>;
|
|
19
|
+
keys: ParsedSpec[];
|
|
20
|
+
electronKeys: ParsedSpec[];
|
|
21
|
+
/** Later registrations win over earlier ones in the same scope. */
|
|
22
|
+
order: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The shortcuts that are mounted right now. Components add and remove their claims as they mount and unmount, so a page switch changes
|
|
26
|
+
* what a key does with nothing to re-wire; the dispatcher (`dispatchKeyEvent()`) looks handlers up here at the time of the key press,
|
|
27
|
+
* and the help dialog lists what is here.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ShortcutRegistry {
|
|
30
|
+
private registrations;
|
|
31
|
+
private counter;
|
|
32
|
+
private listeners;
|
|
33
|
+
/** Adds a claim; returns what removes it. */
|
|
34
|
+
add(claim: Omit<Registration, "id" | "order">): () => void;
|
|
35
|
+
/** The current claims, oldest first. A new array whenever they change (so it can be a `useSyncExternalStore()` snapshot). */
|
|
36
|
+
getSnapshot: () => readonly Registration[];
|
|
37
|
+
subscribe: (listener: () => void) => (() => void);
|
|
38
|
+
private publish;
|
|
39
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shortcuts that are mounted right now. Components add and remove their claims as they mount and unmount, so a page switch changes
|
|
3
|
+
* what a key does with nothing to re-wire; the dispatcher (`dispatchKeyEvent()`) looks handlers up here at the time of the key press,
|
|
4
|
+
* and the help dialog lists what is here.
|
|
5
|
+
*/
|
|
6
|
+
export class ShortcutRegistry {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.registrations = [];
|
|
9
|
+
this.counter = 0;
|
|
10
|
+
this.listeners = new Set();
|
|
11
|
+
/** The current claims, oldest first. A new array whenever they change (so it can be a `useSyncExternalStore()` snapshot). */
|
|
12
|
+
this.getSnapshot = () => this.registrations;
|
|
13
|
+
this.subscribe = (listener) => {
|
|
14
|
+
this.listeners.add(listener);
|
|
15
|
+
return () => {
|
|
16
|
+
this.listeners.delete(listener);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Adds a claim; returns what removes it. */
|
|
21
|
+
add(claim) {
|
|
22
|
+
const registration = { ...claim, id: ++this.counter, order: this.counter };
|
|
23
|
+
this.registrations = [...this.registrations, registration];
|
|
24
|
+
this.publish();
|
|
25
|
+
return () => {
|
|
26
|
+
this.registrations = this.registrations.filter((existing) => existing.id !== registration.id);
|
|
27
|
+
this.publish();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
publish() {
|
|
31
|
+
this.listeners.forEach((listener) => listener());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Whether the event target takes typed text: a text field, a select, a textarea, or anything contenteditable (the rich-text editor). */
|
|
2
|
+
export declare function isTextEntry(target: EventTarget | null): boolean;
|
|
3
|
+
/** Whether the target is inside a widget that reads bare keys itself (an open menu, a listbox, a tab list, ...). */
|
|
4
|
+
export declare function isInWidget(target: EventTarget | null): boolean;
|
|
5
|
+
/** Whether Enter/Space on the target already activates it (a button, a link, a menu item). */
|
|
6
|
+
export declare function isActivatable(target: EventTarget | null): boolean;
|
|
7
|
+
/** Whether the target is the trigger of a popup that is open right now (or the combobox that owns an open list). */
|
|
8
|
+
export declare function isPopupOpenAt(target: EventTarget | null): boolean;
|
|
9
|
+
/** Whether a modal dialog (`aria-modal="true"`: react-shared's `Modal` and `Drawer`, the unlock prompts, ...) is on screen. */
|
|
10
|
+
export declare function isModalOpen(doc: Document): boolean;
|
|
11
|
+
/** 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. */
|
|
12
|
+
export declare function isInPopoverDialog(target: EventTarget | null): boolean;
|
|
13
|
+
/** The `data-shortcut-scope` of the region the target is in (a compose window), if any. */
|
|
14
|
+
export declare function regionScopeOf(target: EventTarget | null): string | undefined;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
/** `<input>` types that take no typed text, so a letter pressed on one is a shortcut, not input. (Radios and ranges use the arrows.) */
|
|
6
|
+
const NON_TEXT_INPUT_TYPES = new Set(["button", "checkbox", "submit", "reset", "image", "file", "color"]);
|
|
7
|
+
/** Roles whose members have keys of their own (arrows, Enter, Escape, type-ahead): a bare key pressed inside one belongs to the widget. */
|
|
8
|
+
const WIDGET_SELECTOR = [
|
|
9
|
+
"menu",
|
|
10
|
+
"menubar",
|
|
11
|
+
"listbox",
|
|
12
|
+
"tablist",
|
|
13
|
+
"tree",
|
|
14
|
+
"grid",
|
|
15
|
+
"radiogroup",
|
|
16
|
+
"slider",
|
|
17
|
+
"spinbutton",
|
|
18
|
+
"combobox",
|
|
19
|
+
]
|
|
20
|
+
.map((role) => `[role="${role}"]`)
|
|
21
|
+
.join(",");
|
|
22
|
+
/** Elements Enter (and Space) already does something on. */
|
|
23
|
+
const ACTIVATABLE_SELECTOR = 'a[href], button, summary, [role="button"], [role="link"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"], [role="tab"], [role="option"]';
|
|
24
|
+
/** An open popup's trigger: Escape closes the popup, so it is not a shortcut then. */
|
|
25
|
+
const OPEN_POPUP_TRIGGER = '[aria-haspopup][aria-expanded="true"], [role="combobox"][aria-expanded="true"]';
|
|
26
|
+
function elementOf(target) {
|
|
27
|
+
return target instanceof Element ? target : null;
|
|
28
|
+
}
|
|
29
|
+
/** Whether the event target takes typed text: a text field, a select, a textarea, or anything contenteditable (the rich-text editor). */
|
|
30
|
+
export function isTextEntry(target) {
|
|
31
|
+
const element = elementOf(target);
|
|
32
|
+
if (!element) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const tag = element.tagName;
|
|
36
|
+
if (tag === "TEXTAREA" || tag === "SELECT") {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (tag === "INPUT") {
|
|
40
|
+
return !NON_TEXT_INPUT_TYPES.has(element.type);
|
|
41
|
+
}
|
|
42
|
+
return !!element.closest('[contenteditable]:not([contenteditable="false"]), [role="textbox"], [role="searchbox"]');
|
|
43
|
+
}
|
|
44
|
+
/** Whether the target is inside a widget that reads bare keys itself (an open menu, a listbox, a tab list, ...). */
|
|
45
|
+
export function isInWidget(target) {
|
|
46
|
+
return !!elementOf(target)?.closest(WIDGET_SELECTOR);
|
|
47
|
+
}
|
|
48
|
+
/** Whether Enter/Space on the target already activates it (a button, a link, a menu item). */
|
|
49
|
+
export function isActivatable(target) {
|
|
50
|
+
return !!elementOf(target)?.closest(ACTIVATABLE_SELECTOR);
|
|
51
|
+
}
|
|
52
|
+
/** Whether the target is the trigger of a popup that is open right now (or the combobox that owns an open list). */
|
|
53
|
+
export function isPopupOpenAt(target) {
|
|
54
|
+
return !!elementOf(target)?.closest(OPEN_POPUP_TRIGGER);
|
|
55
|
+
}
|
|
56
|
+
/** Whether a modal dialog (`aria-modal="true"`: react-shared's `Modal` and `Drawer`, the unlock prompts, ...) is on screen. */
|
|
57
|
+
export function isModalOpen(doc) {
|
|
58
|
+
return doc.querySelector('[aria-modal="true"]') !== null;
|
|
59
|
+
}
|
|
60
|
+
/** 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. */
|
|
61
|
+
export function isInPopoverDialog(target) {
|
|
62
|
+
return !!elementOf(target)?.closest('[role="dialog"]:not([data-shortcut-scope])');
|
|
63
|
+
}
|
|
64
|
+
/** The `data-shortcut-scope` of the region the target is in (a compose window), if any. */
|
|
65
|
+
export function regionScopeOf(target) {
|
|
66
|
+
return elementOf(target)?.closest("[data-shortcut-scope]")?.getAttribute("data-shortcut-scope") ?? undefined;
|
|
67
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { ShortcutDef, ShortcutScope } from "./keymap.js";
|
|
3
|
+
import type { ShortcutHandler } from "./registry.js";
|
|
4
|
+
export interface UseShortcutOptions {
|
|
5
|
+
/** Overrides the scope the shortcut is defined with - required for a bare spec string, which has none. Default `global`. */
|
|
6
|
+
scope?: ShortcutScope;
|
|
7
|
+
/** Registers only while true: a view offers a shortcut only when it can really do the thing. Default true. */
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/** Restricts it to events whose target is inside this element (a compose window). */
|
|
10
|
+
container?: RefObject<Element | null>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Claims a shortcut for as long as the calling component is mounted (and `enabled`). `shortcut` is an entry of `SHORTCUTS` - which is what
|
|
14
|
+
* 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,
|
|
15
|
+
* so it always sees the component's current state without the registration being redone; return `false` from it to decline the key.
|
|
16
|
+
*
|
|
17
|
+
* Does nothing outside a `ShortcutProvider`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useShortcut(shortcut: ShortcutDef | string, handler: ShortcutHandler, options?: UseShortcutOptions): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
6
|
+
import { parseSpec } from "./parse.js";
|
|
7
|
+
import { useShortcutRegistry } from "./ShortcutProvider.js";
|
|
8
|
+
/**
|
|
9
|
+
* Claims a shortcut for as long as the calling component is mounted (and `enabled`). `shortcut` is an entry of `SHORTCUTS` - which is what
|
|
10
|
+
* 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,
|
|
11
|
+
* so it always sees the component's current state without the registration being redone; return `false` from it to decline the key.
|
|
12
|
+
*
|
|
13
|
+
* Does nothing outside a `ShortcutProvider`.
|
|
14
|
+
*/
|
|
15
|
+
export function useShortcut(shortcut, handler, options = {}) {
|
|
16
|
+
const { scope, enabled = true, container } = options;
|
|
17
|
+
const registry = useShortcutRegistry();
|
|
18
|
+
const handlerRef = useRef(handler);
|
|
19
|
+
handlerRef.current = handler;
|
|
20
|
+
const def = useMemo(() => (typeof shortcut === "string" ? { id: `custom:${shortcut}`, keys: [shortcut], label: shortcut, scope: "global" } : shortcut), [shortcut]);
|
|
21
|
+
const resolvedScope = scope ?? def.scope;
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!registry || !enabled) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return registry.add({
|
|
27
|
+
shortcut: def,
|
|
28
|
+
scope: resolvedScope,
|
|
29
|
+
run: (event) => handlerRef.current(event),
|
|
30
|
+
container,
|
|
31
|
+
keys: def.keys.map(parseSpec),
|
|
32
|
+
electronKeys: (def.electronKeys ?? []).map(parseSpec),
|
|
33
|
+
});
|
|
34
|
+
}, [registry, enabled, def, resolvedScope, container]);
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ShortcutDef } from "./keymap.js";
|
|
2
|
+
/**
|
|
3
|
+
* 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 -
|
|
4
|
+
* and `aria-keyshortcuts` for assistive technology. The accessible name is left alone (the control keeps its own label), so a tooltip suffix never
|
|
5
|
+
* 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.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useShortcutProps(label: string, shortcut: ShortcutDef, active?: boolean): {
|
|
8
|
+
title: string;
|
|
9
|
+
"aria-keyshortcuts"?: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { useKeyEnvironment } from "./ShortcutProvider.js";
|
|
7
|
+
/**
|
|
8
|
+
* 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 -
|
|
9
|
+
* and `aria-keyshortcuts` for assistive technology. The accessible name is left alone (the control keeps its own label), so a tooltip suffix never
|
|
10
|
+
* 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.
|
|
11
|
+
*/
|
|
12
|
+
export function useShortcutProps(label, shortcut, active = true) {
|
|
13
|
+
const env = useKeyEnvironment();
|
|
14
|
+
return active ? { title: withHint(label, shortcut, env), "aria-keyshortcuts": ariaKeyShortcuts(shortcut, env) } : { title: label };
|
|
15
|
+
}
|