Skip to content

Commit 5bbe23d

Browse files
committed
feat: 新增 hotkeys 子包,统一维护全局快捷键
1 parent ee62670 commit 5bbe23d

118 files changed

Lines changed: 1508 additions & 3769 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/core-ant-design-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"@fantastic-admin/components": "workspace:*",
1717
"@fantastic-admin/composables": "workspace:*",
18+
"@fantastic-admin/hotkeys": "workspace:*",
1819
"@fantastic-admin/settings": "workspace:*",
1920
"@fantastic-admin/types": "workspace:*",
2021
"@vee-validate/zod": "catalog:",
@@ -28,7 +29,6 @@
2829
"dayjs": "catalog:",
2930
"eruda": "catalog:",
3031
"es-toolkit": "catalog:",
31-
"hotkeys-js": "catalog:",
3232
"mitt": "catalog:",
3333
"nprogress": "catalog:",
3434
"path-browserify": "catalog:",

apps/core-ant-design-vue/src/hotkeys/README.md

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { HotkeyBinding } from '@fantastic-admin/hotkeys'
2+
3+
/**
4+
* 业务扩展快捷键 id
5+
*
6+
* 使用方式:
7+
*
8+
* export const EXT_HOTKEY_ID = {
9+
* demoOpen: 'demo.open',
10+
* } as const
11+
*/
12+
export const EXT_HOTKEY_ID = {} as const
13+
14+
type ExtendHotkeyId = typeof EXT_HOTKEY_ID[keyof typeof EXT_HOTKEY_ID]
15+
16+
/**
17+
* 业务扩展全局快捷键
18+
*
19+
* 示例:
20+
*
21+
* export const extendGlobalHotkeyBindings = [
22+
* {
23+
* id: EXT_HOTKEY_ID.demoOpen,
24+
* keys: ['command+j', 'ctrl+j'],
25+
* enabled: ctx => ctx.settings.toolbar.menuSearch.enable,
26+
* help: {
27+
* group: 'global',
28+
* titleKey: 'global.demoOpen',
29+
* order: 90,
30+
* visible: ctx => ctx.settings.toolbar.menuSearch.enable,
31+
* displayKeys: {
32+
* default: ['Ctrl', 'J'],
33+
* mac: ['⌘', 'J'],
34+
* },
35+
* },
36+
* },
37+
* ] satisfies HotkeyBinding<ExtendHotkeyId>[]
38+
*/
39+
export const extendGlobalHotkeyBindings = [] satisfies HotkeyBinding<ExtendHotkeyId>[]
40+
41+
/**
42+
* 业务扩展局部快捷键
43+
*
44+
* 示例:
45+
*
46+
* export const extendScopedHotkeyBindings = [
47+
* {
48+
* id: EXT_HOTKEY_ID.demoConfirm,
49+
* keys: ['enter'],
50+
* },
51+
* {
52+
* id: EXT_HOTKEY_ID.demoClose,
53+
* keys: ['esc'],
54+
* },
55+
* ] satisfies HotkeyBinding<ExtendHotkeyId>[]
56+
*/
57+
export const extendScopedHotkeyBindings = [] satisfies HotkeyBinding<ExtendHotkeyId>[]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type {
2+
HotkeyBinding,
3+
HotkeyContextBase,
4+
HotkeyDisplayKeys,
5+
HotkeyHandler,
6+
HotkeyHandlerArgs,
7+
HotkeyHandlersMap,
8+
HotkeyHelpGroup,
9+
HotkeyHelpMeta,
10+
} from '@fantastic-admin/hotkeys'
11+
import { createHotkeys } from '@fantastic-admin/hotkeys'
12+
import { EXT_HOTKEY_ID, extendGlobalHotkeyBindings, extendScopedHotkeyBindings } from './extend'
13+
14+
const appHotkeys = createHotkeys({
15+
extendIds: EXT_HOTKEY_ID,
16+
extendGlobalHotkeyBindings,
17+
extendScopedHotkeyBindings,
18+
getContext: () => ({
19+
settings: useAppSettingsStore().settings,
20+
}),
21+
})
22+
23+
export const HOTKEY_ID = appHotkeys.HOTKEY_ID
24+
export const hotkeyIds = appHotkeys.hotkeyIds
25+
export const globalHotkeyBindings = appHotkeys.globalHotkeyBindings
26+
export const menuSearchHotkeyBindings = appHotkeys.menuSearchHotkeyBindings
27+
export const hotkeyBindings = appHotkeys.hotkeyBindings
28+
export const useHotkey = appHotkeys.useHotkey
29+
export const useHotkeyBindings = appHotkeys.useHotkeyBindings
30+
31+
export type HotkeyId = typeof HOTKEY_ID[keyof typeof HOTKEY_ID]
32+
export type {
33+
HotkeyBinding,
34+
HotkeyContextBase,
35+
HotkeyDisplayKeys,
36+
HotkeyHandler,
37+
HotkeyHandlerArgs,
38+
HotkeyHandlersMap,
39+
HotkeyHelpGroup,
40+
HotkeyHelpMeta,
41+
}

apps/core-ant-design-vue/src/hotkeys/registry.extend.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)