Skip to content

Commit 5b76624

Browse files
authored
Change hotkeys package (#110)
1 parent 58797eb commit 5b76624

File tree

4 files changed

+34
-37
lines changed

4 files changed

+34
-37
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"react-dnd": "^10.0.2",
3232
"react-dnd-html5-backend": "^10.0.2",
3333
"react-dom": "^16.12.0",
34-
"react-hotkeys": "^2.0.0",
34+
"react-hotkeys-hook": "^2.4.0",
3535
"react-icons": "^3.9.0",
3636
"react-redux": "^7.1.3",
3737
"react-scripts": "3.3.0",

src/hooks/useShortcuts.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ import useDispatch from './useDispatch'
22
import { useSelector } from 'react-redux'
33
import { ActionCreators as UndoActionCreators } from 'redux-undo'
44
import { getSelectedComponent } from '~core/selectors/components'
5+
import { useHotkeys } from 'react-hotkeys-hook'
56

6-
export const keyMap = {
7-
DELETE_NODE: ['backspace', 'del'],
7+
const keyMap = {
8+
DELETE_NODE: 'Backspace, del',
89
TOGGLE_BUILDER_MODE: 'b',
910
TOGGLE_CODE_PANEL: 'c',
10-
UNDO: ['ctrl+z', 'cmd+z'],
11-
REDO: ['ctrl+y', 'cmd+y'],
12-
UNSELECT: ['Escape'],
11+
UNDO: 'ctrl+z, command+z',
12+
REDO: 'ctrl+y, cmd+y',
13+
UNSELECT: 'esc',
1314
PARENT: 'p',
14-
DUPLICATE: ['ctrl+d', 'cmd+d'],
15-
KONAMI_CODE: [
16-
'up up down down left right left right b a',
17-
'up up down down left right left right B A',
18-
],
15+
DUPLICATE: 'ctrl+d, command+d',
16+
KONAMI_CODE:
17+
'up up down down left right left right b a, up up down down left right left right B A',
1918
}
2019

2120
const hasNoSpecialKeyPressed = (event: KeyboardEvent | undefined) =>
@@ -85,19 +84,15 @@ const useShortcuts = () => {
8584
dispatch.components.loadDemo('secretchakra')
8685
}
8786

88-
const handlers = {
89-
DELETE_NODE: deleteNode,
90-
TOGGLE_BUILDER_MODE: toggleBuilderMode,
91-
TOGGLE_CODE_PANEL: toggleCodePanel,
92-
UNDO: undo,
93-
REDO: redo,
94-
UNSELECT: onUnselect,
95-
PARENT: onSelectParent,
96-
DUPLICATE: onDuplicate,
97-
KONAMI_CODE: onKonamiCode,
98-
}
99-
100-
return { handlers }
87+
useHotkeys(keyMap.DELETE_NODE, deleteNode, {}, [selected.id])
88+
useHotkeys(keyMap.TOGGLE_BUILDER_MODE, toggleBuilderMode)
89+
useHotkeys(keyMap.TOGGLE_CODE_PANEL, toggleCodePanel)
90+
useHotkeys(keyMap.UNDO, undo)
91+
useHotkeys(keyMap.REDO, redo)
92+
useHotkeys(keyMap.UNSELECT, onUnselect)
93+
useHotkeys(keyMap.PARENT, onSelectParent)
94+
useHotkeys(keyMap.DUPLICATE, onDuplicate)
95+
useHotkeys(keyMap.KONAMI_CODE, onKonamiCode)
10196
}
10297

10398
export default useShortcuts

src/pages/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { Flex, Box } from '@chakra-ui/react'
33
import { DndProvider } from 'react-dnd'
44
import Backend from 'react-dnd-html5-backend'
55
import { Global } from '@emotion/react'
6-
import { HotKeys } from 'react-hotkeys'
76
import Metadata from '~components/Metadata'
8-
import useShortcuts, { keyMap } from '~hooks/useShortcuts'
7+
import useShortcuts from '~hooks/useShortcuts'
98
import Header from '~components/Header'
109
import Sidebar from '~components/sidebar/Sidebar'
1110
import EditorErrorBoundary from '~components/errorBoundaries/EditorErrorBoundary'
@@ -14,18 +13,16 @@ import { InspectorProvider } from '~contexts/inspector-context'
1413
import Inspector from '~components/inspector/Inspector'
1514

1615
const App = () => {
17-
const { handlers } = useShortcuts()
16+
useShortcuts()
1817

1918
return (
20-
<HotKeys allowChanges handlers={handlers} keyMap={keyMap}>
19+
<>
2120
<Global
2221
styles={() => ({
2322
html: { minWidth: '860px', backgroundColor: '#1a202c' },
2423
})}
2524
/>
26-
2725
<Metadata />
28-
2926
<Header />
3027
<DndProvider backend={Backend}>
3128
<Flex h="calc(100vh - 3rem)">
@@ -50,7 +47,7 @@ const App = () => {
5047
</Box>
5148
</Flex>
5249
</DndProvider>
53-
</HotKeys>
50+
</>
5451
)
5552
}
5653

yarn.lock

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8189,6 +8189,11 @@ hosted-git-info@^2.1.4, hosted-git-info@^2.4.2:
81898189
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.5.tgz#759cfcf2c4d156ade59b0b2dfabddc42a6b9c70c"
81908190
integrity sha512-kssjab8CvdXfcXMXVcvsXum4Hwdq9XGtRD3TteMEvEbq0LXyiNQr6AprqKqfeaDXze7SxWvRxdpwE6ku7ikLkg==
81918191

8192+
hotkeys-js@3.8.1:
8193+
version "3.8.1"
8194+
resolved "https://registry.yarnpkg.com/hotkeys-js/-/hotkeys-js-3.8.1.tgz#fa7051f73bf1dc92a8b8d580a40b247f91966376"
8195+
integrity sha512-YlhVQtyG9f1b7GhtzdhR0Pl+cImD1ZrKI6zYUa7QLd0zuThiL7RzZ+ANJyy7z+kmcCpNYBf5PjBa3CjiQ5PFpw==
8196+
81928197
hpack.js@^2.1.6:
81938198
version "2.1.6"
81948199
resolved "https://registry.yarnpkg.com/hpack.js/-/hpack.js-2.1.6.tgz#87774c0949e513f42e84575b3c45681fade2a0b2"
@@ -12567,7 +12572,7 @@ prompts@^2.0.1:
1256712572
kleur "^3.0.3"
1256812573
sisteransi "^1.0.3"
1256912574

12570-
prop-types@15.7.2, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
12575+
prop-types@15.7.2, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.6.2, prop-types@^15.7.2:
1257112576
version "15.7.2"
1257212577
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
1257312578
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -12891,12 +12896,12 @@ react-focus-lock@2.4.1:
1289112896
use-callback-ref "^1.2.1"
1289212897
use-sidecar "^1.0.1"
1289312898

12894-
react-hotkeys@^2.0.0:
12895-
version "2.0.0"
12896-
resolved "https://registry.yarnpkg.com/react-hotkeys/-/react-hotkeys-2.0.0.tgz#a7719c7340cbba888b0e9184f806a9ec0ac2c53f"
12897-
integrity sha512-3n3OU8vLX/pfcJrR3xJ1zlww6KS1kEJt0Whxc4FiGV+MJrQ1mYSYI3qS/11d2MJDFm8IhOXMTFQirfu6AVOF6Q==
12899+
react-hotkeys-hook@^2.4.0:
12900+
version "2.4.0"
12901+
resolved "https://registry.yarnpkg.com/react-hotkeys-hook/-/react-hotkeys-hook-2.4.0.tgz#becf941641bab04c8095917b5876ad8ed53b0dc6"
12902+
integrity sha512-Veh9FUe+iXab+lZ5shPoyGDnFBu5codQ15omOXiOvCC/Q5QfTY1lefLVx/Zi2NnYBSXfkfQbhnpE+Rnhi2+wBw==
1289812903
dependencies:
12899-
prop-types "^15.6.1"
12904+
hotkeys-js "3.8.1"
1290012905

1290112906
react-icons@^3.9.0:
1290212907
version "3.9.0"

0 commit comments

Comments
 (0)