1
- import React from 'react' ;
1
+ import React , { useEffect } from 'react' ;
2
2
import './App.css' ;
3
- import { DesignCanvas } from "./DesignCanvas" ;
4
- import { observer } from "mobx-react"
5
- import { EditorAppViewModel } from "../viewmodels/EditorAppViewModel" ;
6
- import { PropertiesPanel } from "./PropertiesPanel" ;
3
+ import { DesignCanvas } from './DesignCanvas' ;
4
+ import { observer } from 'mobx-react' ;
5
+ import { EditorAppViewModel } from '../viewmodels/EditorAppViewModel' ;
6
+ import { PropertiesPanel } from './PropertiesPanel' ;
7
+ import hotkeys from 'hotkeys-js' ;
7
8
8
9
let editorVm = new EditorAppViewModel ( ) ;
9
10
10
11
let EditorApp = observer ( function EditorApp ( ) {
12
+ useEffect ( ( ) => {
13
+ const scopeName = 'app' ;
14
+
15
+ const add = function ( shortcut : string , callback : ( ) => void ) {
16
+ hotkeys ( shortcut , scopeName , ( evt ) => {
17
+ callback ( ) ;
18
+ evt . preventDefault ( ) ;
19
+ } ) ;
20
+ } ;
21
+
22
+ add ( 'ctrl+z' , ( ) => editorVm . undo ( ) ) ;
23
+ add ( 'ctrl+y' , ( ) => editorVm . redo ( ) ) ;
24
+ add ( 'delete' , ( ) => editorVm . removeSelected ( ) ) ;
25
+ add ( 'ctrl+n' , ( ) => editorVm . clearLayout ( ) ) ;
26
+
27
+ hotkeys . setScope ( scopeName ) ;
28
+
29
+ return ( ) => hotkeys . deleteScope ( scopeName ) ;
30
+ } , [ ] ) ;
31
+
11
32
return (
12
33
< div className = "design-app" >
13
34
< header >
14
35
< h1 > Web App Builder</ h1 >
15
36
{ /* Render each control as a button that inserts it */ }
16
- { editorVm . controls . descriptors . map ( d =>
17
- < button key = { d . id } onClick = { ( ) => editorVm . addControl ( d ) } > Add { d . displayName } </ button >
18
- ) }
37
+ { editorVm . controls . descriptors . map ( ( d ) => (
38
+ < button key = { d . id } onClick = { ( ) => editorVm . addControl ( d ) } >
39
+ Add { d . displayName }
40
+ </ button >
41
+ ) ) }
19
42
< button onClick = { ( ) => editorVm . removeSelected ( ) } > Delete</ button >
20
43
< button onClick = { ( ) => editorVm . undo ( ) } > Undo</ button >
21
44
< button onClick = { ( ) => editorVm . redo ( ) } > Redo</ button >
@@ -33,6 +56,6 @@ let EditorApp = observer(function EditorApp() {
33
56
</ aside >
34
57
</ div >
35
58
) ;
36
- } )
59
+ } ) ;
37
60
38
61
export default EditorApp ;
0 commit comments