feat: implement platform-specific keyboard shortcuts and refactor shortcut data management
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
"./hooks": "./src/hooks/index.ts",
|
||||
"./provider": "./src/provider/index.ts",
|
||||
"./validators": "./src/validators/index.ts",
|
||||
"./foundations": "./src/foundations/index.ts"
|
||||
"./foundations": "./src/foundations/index.ts",
|
||||
"./constants": "./src/constants/index.ts"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user