@@ -29,6 +29,9 @@ const styles = theme => ({
29
29
}
30
30
} ) ;
31
31
32
+ const defaultElevation = 2 ;
33
+ const focusedElevation = 8 ;
34
+
32
35
class Index extends React . Component {
33
36
34
37
constructor ( props ) {
@@ -69,6 +72,14 @@ class Index extends React.Component {
69
72
} ;
70
73
}
71
74
75
+ componentDidMount ( ) {
76
+ document . onblur = ( ) => {
77
+ // Needed when the user clicks outside the document,
78
+ // e.g. the browser address bar
79
+ this . setFocus ( null ) ;
80
+ }
81
+ }
82
+
72
83
setPersistentState = ( updater ) => {
73
84
this . setState ( updater , function ( updater ) {
74
85
if ( typeof updater === 'function' ) {
@@ -129,13 +140,15 @@ class Index extends React.Component {
129
140
} ) ;
130
141
}
131
142
132
- handleInsertClick = ( ) => {
143
+ handleInsertButtonClick = ( ) => {
144
+ this . setFocusIf ( 'insertPanelsAreOpen' , null , 'InsertPanels' )
133
145
this . setPersistentState ( {
134
146
insertPanelsAreOpen : ! this . state . insertPanelsAreOpen ,
135
147
} ) ;
136
148
}
137
149
138
- handleNodeFormatClick = ( ) => {
150
+ handleNodeFormatButtonClick = ( ) => {
151
+ this . setFocusIf ( 'nodeFormatDrawerIsOpen' , null , 'NodeFormatDrawer' )
139
152
this . setPersistentState ( {
140
153
nodeFormatDrawerIsOpen : ! this . state . nodeFormatDrawerIsOpen ,
141
154
edgeFormatDrawerIsOpen : false ,
@@ -146,9 +159,11 @@ class Index extends React.Component {
146
159
this . setPersistentState ( {
147
160
nodeFormatDrawerIsOpen : false ,
148
161
} ) ;
162
+ this . setFocus ( null ) ;
149
163
}
150
164
151
- handleEdgeFormatClick = ( ) => {
165
+ handleEdgeFormatButtonClick = ( ) => {
166
+ this . setFocusIf ( 'edgeFormatDrawerIsOpen' , null , 'EdgeFormatDrawer' )
152
167
this . setPersistentState ( {
153
168
edgeFormatDrawerIsOpen : ! this . state . edgeFormatDrawerIsOpen ,
154
169
nodeFormatDrawerIsOpen : false ,
@@ -159,6 +174,7 @@ class Index extends React.Component {
159
174
this . setPersistentState ( {
160
175
edgeFormatDrawerIsOpen : false ,
161
176
} ) ;
177
+ this . setFocus ( null ) ;
162
178
}
163
179
164
180
handleSettingsClick = ( ) => {
@@ -381,9 +397,65 @@ class Index extends React.Component {
381
397
this . redo = redo ;
382
398
}
383
399
400
+ handleTextEditorFocus = ( ) => {
401
+ this . setFocus ( 'TextEditor' ) ;
402
+ }
403
+
404
+ handleTextEditorBlur = ( ) => {
405
+ // Needed when the user clicks outside of a pane,
406
+ // e.g. the app bar or the background
407
+ this . setFocusIfFocusIs ( 'TextEditor' , null ) ;
408
+ }
409
+
410
+ handleGraphFocus = ( ) => {
411
+ this . setFocus ( 'Graph' ) ;
412
+ }
413
+
414
+ handleInsertPanelsClick = ( ) => {
415
+ this . setFocus ( 'InsertPanels' ) ;
416
+ }
417
+
418
+ handleNodeFormatDrawerClick = ( ) => {
419
+ this . setFocusIf ( 'nodeFormatDrawerIsOpen' , 'NodeFormatDrawer' , null )
420
+ }
421
+
422
+ handleEdgeFormatDrawerClick = ( ) => {
423
+ this . setFocus ( 'EdgeFormatDrawer' ) ;
424
+ this . setFocusIf ( 'edgeFormatDrawerIsOpen' , 'EdgeFormatDrawer' , null )
425
+ }
426
+
427
+ setFocus = ( focusedPane ) => {
428
+ this . setState ( ( state ) => ( state . focusedPane !== focusedPane && {
429
+ focusedPane : focusedPane ,
430
+ } ) || null ) ;
431
+ }
432
+
433
+ setFocusIfFocusIs = ( currentlyFocusedPane , newFocusedPane ) => {
434
+ this . setState ( ( state ) => ( state . focusedPane === currentlyFocusedPane && {
435
+ focusedPane : newFocusedPane ,
436
+ } ) || null ) ;
437
+ }
438
+
439
+ setFocusIf = ( stateProperty , focusedPaneIf , focusedPaneElse ) => {
440
+ this . setState ( ( state ) => {
441
+ const focusedPane = state [ stateProperty ] ? focusedPaneIf : focusedPaneElse ;
442
+ return ( state . focusedPane !== focusedPane && {
443
+ focusedPane : focusedPane ,
444
+ } ) || null ;
445
+ } ) ;
446
+ }
447
+
384
448
render ( ) {
385
449
const { classes } = this . props ;
386
450
const editorIsOpen = ! this . state . nodeFormatDrawerIsOpen && ! this . state . edgeFormatDrawerIsOpen ;
451
+ const textEditorHasFocus = this . state . focusedPane === 'TextEditor' ;
452
+ const nodeFormatDrawerHasFocus = this . state . focusedPane === 'NodeFormatDrawer' ;
453
+ const edgeFormatDrawerHasFocus = this . state . focusedPane === 'EdgeFormatDrawer' ;
454
+ const insertPanelsHaveFocus = this . state . focusedPane === 'InsertPanels' ;
455
+ const graphHasFocus = this . state . focusedPane === 'Graph' ;
456
+ const leftPaneElevation = textEditorHasFocus || nodeFormatDrawerHasFocus || edgeFormatDrawerHasFocus ? focusedElevation : defaultElevation ;
457
+ const rightPaneElevation = graphHasFocus ? focusedElevation : defaultElevation ;
458
+ const midPaneElevation = insertPanelsHaveFocus ? focusedElevation : defaultElevation ;
387
459
388
460
var columns ;
389
461
if ( this . state . insertPanelsAreOpen && this . state . graphInitialized ) {
@@ -407,9 +479,9 @@ class Index extends React.Component {
407
479
onMenuButtonClick = { this . handleMainMenuButtonClick }
408
480
onUndoButtonClick = { this . handleUndoButtonClick }
409
481
onRedoButtonClick = { this . handleRedoButtonClick }
410
- onInsertClick = { this . handleInsertClick }
411
- onNodeFormatClick = { this . handleNodeFormatClick }
412
- onEdgeFormatClick = { this . handleEdgeFormatClick }
482
+ onInsertClick = { this . handleInsertButtonClick }
483
+ onNodeFormatClick = { this . handleNodeFormatButtonClick }
484
+ onEdgeFormatClick = { this . handleEdgeFormatButtonClick }
413
485
onZoomInButtonClick = { this . handleZoomInButtonClick }
414
486
onZoomOutButtonClick = { this . handleZoomOutButtonClick }
415
487
onZoomOutMapButtonClick = { this . handleZoomOutMapButtonClick }
@@ -454,11 +526,12 @@ class Index extends React.Component {
454
526
} }
455
527
>
456
528
< Grid item xs = { columns . textEditor } >
457
- < Paper className = { classes . paper } >
529
+ < Paper elevation = { leftPaneElevation } className = { classes . paper } >
458
530
< FormatDrawer
459
531
type = 'node'
460
532
open = { this . state . nodeFormatDrawerIsOpen }
461
533
defaultAttributes = { this . state . defaultNodeAttributes }
534
+ onClick = { this . handleNodeFormatDrawerClick }
462
535
onFormatDrawerClose = { this . handleNodeFormatDrawerClose }
463
536
onStyleChange = { this . handleNodeStyleChange }
464
537
onColorChange = { this . handleNodeColorChange }
@@ -468,6 +541,7 @@ class Index extends React.Component {
468
541
type = 'edge'
469
542
open = { this . state . edgeFormatDrawerIsOpen }
470
543
defaultAttributes = { this . state . defaultEdgeAttributes }
544
+ onClick = { this . handleEdgeFormatDrawerClick }
471
545
onFormatDrawerClose = { this . handleEdgeFormatDrawerClose }
472
546
onStyleChange = { this . handleEdgeStyleChange }
473
547
onColorChange = { this . handleEdgeColorChange }
@@ -494,8 +568,9 @@ class Index extends React.Component {
494
568
</ Grid >
495
569
{ this . state . insertPanelsAreOpen && this . state . graphInitialized && (
496
570
< Grid item xs = { columns . insertPanels } >
497
- < Paper className = { classes . paper } >
571
+ < Paper elevation = { midPaneElevation } className = { classes . paper } >
498
572
< InsertPanels
573
+ onClick = { this . handleInsertPanelsClick }
499
574
onNodeShapeClick = { this . handleNodeShapeClick }
500
575
onNodeShapeDragStart = { this . handleNodeShapeDragStart }
501
576
onNodeShapeDragEnd = { this . handleNodeShapeDragEnd }
@@ -504,8 +579,9 @@ class Index extends React.Component {
504
579
</ Grid >
505
580
) }
506
581
< Grid item xs = { columns . graph } >
507
- < Paper className = { classes . paper } >
582
+ < Paper elevation = { rightPaneElevation } className = { classes . paper } >
508
583
< Graph
584
+ hasFocus = { graphHasFocus }
509
585
dotSrc = { this . state . dotSrc }
510
586
engine = { this . state . engine }
511
587
fit = { this . state . fitGraph }
@@ -515,6 +591,7 @@ class Index extends React.Component {
515
591
tweenPrecision = { this . state . tweenPrecision }
516
592
defaultNodeAttributes = { this . state . defaultNodeAttributes }
517
593
defaultEdgeAttributes = { this . state . defaultEdgeAttributes }
594
+ onFocus = { this . handleGraphFocus }
518
595
onTextChange = { this . handleTextChange }
519
596
onHelp = { this . handleKeyboardShortcutsClick }
520
597
onSelect = { this . handleGraphComponentSelect }
0 commit comments