feat: implement platform-specific keyboard shortcuts and refactor shortcut data management

This commit is contained in:
Firman Ramdhani
2026-07-13 10:17:07 +07:00
parent ad5be7056a
commit 164ec284ae
7 changed files with 58 additions and 28 deletions
+1
View File
@@ -0,0 +1 @@
export * from './shortcut.data';
@@ -0,0 +1,29 @@
export const shortcutsData = [
{
key: 'create_data',
label: 'information:shortcuts.create.label',
desc: 'information:shortcuts.create.desc',
macKeys: ['Cmd', 'Shift', 'N'],
macKeyIcons: ['⌘', '⇧', 'N'],
winKeys: ['Ctrl', 'Shift', 'N'],
winKeyIcons: ['Ctrl', '⇧', 'N'],
},
{
key: 'search_menu',
label: 'information:shortcuts.searchMenu.label',
desc: 'information:shortcuts.searchMenu.desc',
macKeys: ['Cmd', 'Shift', 'M'],
macKeyIcons: ['⌘', '⇧', 'M'],
winKeys: ['Ctrl', 'Shift', 'M'],
winKeyIcons: ['Ctrl', '⇧', 'M'],
},
{
key: 'collapse_sidebar',
label: 'information:shortcuts.toggleSidebar.label',
desc: 'information:shortcuts.toggleSidebar.desc',
macKeys: ['Cmd', 'Shift', 'B'],
macKeyIcons: ['⌘', '⇧', 'B'],
winKeys: ['Ctrl', 'Shift', 'B'],
winKeyIcons: ['Ctrl', '⇧', 'B'],
},
];
@@ -10,6 +10,7 @@ import {
useEnterpriseModuleNavigationContext,
useEnterpriseModuleTranslationContext,
} from '../hooks/use-module.context';
import { shortcutsData } from '../../../constants';
// ---------------------------------------------------------------------------
// Helpers
@@ -18,9 +19,6 @@ import {
/** Detect macOS / iOS for displaying platform-specific shortcut labels. */
const IS_MAC = typeof navigator !== 'undefined' && /Mac|iPod|iPhone|iPad/.test(navigator.userAgent);
/** Platform-aware shortcut label for the Create action. */
const CREATE_SHORTCUT_LABEL = IS_MAC ? '⇧⌘N' : 'Ctrl+Shift+N';
// ---------------------------------------------------------------------------
// Component
// ---------------------------------------------------------------------------
@@ -48,6 +46,13 @@ export function EnterpriseIndexPageProvider<E extends BaseEntity = BaseEntity>(p
// -------------------------------------------------------------------------
// Global keyboard shortcut: Ctrl+Shift+N / ⌘+Shift+N → Create
// -------------------------------------------------------------------------
/** Platform-aware shortcut label for the Create action. */
const CREATE_SHORTCUT_LABEL = useMemo(() => {
const shortcutData = shortcutsData.find((s) => s.key === 'collapse_sidebar');
return IS_MAC ? shortcutData?.macKeyIcons.join(' ') : shortcutData?.winKeyIcons.join(' ');
}, [IS_MAC]);
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
const isShortcut = (e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === 'n';