@@ -96,10 +96,6 @@ if (majorVersion < 16) {
96
96
) ;
97
97
}
98
98
99
- declare namespace window {
100
- export let g : GraphiQL ;
101
- }
102
-
103
99
export type GraphiQLToolbarConfig = {
104
100
additionalContent ?: React . ReactNode ;
105
101
} ;
@@ -318,12 +314,6 @@ export class GraphiQL extends React.Component<GraphiQLProps> {
318
314
super ( props ) ;
319
315
}
320
316
321
- componentDidMount ( ) {
322
- if ( typeof window !== 'undefined' ) {
323
- window . g = this ;
324
- }
325
- }
326
-
327
317
render ( ) {
328
318
return (
329
319
< GraphiQLProviders
@@ -623,6 +613,7 @@ type GraphiQLWithContextConsumerProps = Omit<
623
613
624
614
export type GraphiQLState = {
625
615
activeSecondaryEditor : 'variable' | 'header' ;
616
+ showShortKeys : boolean ;
626
617
showSettings : boolean ;
627
618
clearStorageStatus : 'success' | 'error' | null ;
628
619
} ;
@@ -637,6 +628,7 @@ class GraphiQLWithContext extends React.Component<
637
628
// Initialize state
638
629
this . state = {
639
630
activeSecondaryEditor : 'variable' ,
631
+ showShortKeys : false ,
640
632
showSettings : false ,
641
633
clearStorageStatus : null ,
642
634
} ;
@@ -695,6 +687,13 @@ class GraphiQLWithContext extends React.Component<
695
687
}
696
688
} ;
697
689
690
+ const modifier =
691
+ window . navigator . platform . toLowerCase ( ) . indexOf ( 'mac' ) === 0 ? (
692
+ < code className = "graphiql-key" > Cmd</ code >
693
+ ) : (
694
+ < code className = "graphiql-key" > Ctrl</ code >
695
+ ) ;
696
+
698
697
return (
699
698
< div data-testid = "graphiql-container" className = "graphiql-container" >
700
699
< div className = "graphiql-sidebar" >
@@ -758,7 +757,10 @@ class GraphiQLWithContext extends React.Component<
758
757
}
759
758
/>
760
759
</ UnStyledButton >
761
- < UnStyledButton >
760
+ < UnStyledButton
761
+ onClick = { ( ) => {
762
+ this . setState ( { showShortKeys : true } ) ;
763
+ } } >
762
764
< KeyboardShortcutIcon />
763
765
</ UnStyledButton >
764
766
< UnStyledButton
@@ -1007,6 +1009,111 @@ class GraphiQLWithContext extends React.Component<
1007
1009
</ div >
1008
1010
</ div >
1009
1011
</ div >
1012
+ < Dialog
1013
+ isOpen = { this . state . showShortKeys }
1014
+ onDismiss = { ( ) => {
1015
+ this . setState ( { showShortKeys : false } ) ;
1016
+ } } >
1017
+ < div className = "graphiql-dialog-header" >
1018
+ < div className = "graphiql-dialog-title" > Short Keys</ div >
1019
+ < Dialog . Close
1020
+ onClick = { ( ) => {
1021
+ this . setState ( { showShortKeys : false } ) ;
1022
+ } }
1023
+ />
1024
+ </ div >
1025
+ < div className = "graphiql-dialog-section" >
1026
+ < div >
1027
+ < table className = "graphiql-table" >
1028
+ < thead >
1029
+ < tr >
1030
+ < th > Short key</ th >
1031
+ < th > Function</ th >
1032
+ </ tr >
1033
+ </ thead >
1034
+ < tbody >
1035
+ < tr >
1036
+ < td >
1037
+ { modifier }
1038
+ { ' + ' }
1039
+ < code className = "graphiql-key" > F</ code >
1040
+ </ td >
1041
+ < td > Search in editor</ td >
1042
+ </ tr >
1043
+ < tr >
1044
+ < td >
1045
+ { modifier }
1046
+ { ' + ' }
1047
+ < code className = "graphiql-key" > K</ code >
1048
+ </ td >
1049
+ < td > Search in documentation</ td >
1050
+ </ tr >
1051
+ < tr >
1052
+ < td >
1053
+ { modifier }
1054
+ { ' + ' }
1055
+ < code className = "graphiql-key" > Enter</ code >
1056
+ </ td >
1057
+ < td > Execute query</ td >
1058
+ </ tr >
1059
+ < tr >
1060
+ < td >
1061
+ < code className = "graphiql-key" > Ctrl</ code >
1062
+ { ' + ' }
1063
+ < code className = "graphiql-key" > Shift</ code >
1064
+ { ' + ' }
1065
+ < code className = "graphiql-key" > P</ code >
1066
+ </ td >
1067
+ < td > Prettify editors</ td >
1068
+ </ tr >
1069
+ < tr >
1070
+ < td >
1071
+ < code className = "graphiql-key" > Ctrl</ code >
1072
+ { ' + ' }
1073
+ < code className = "graphiql-key" > Shift</ code >
1074
+ { ' + ' }
1075
+ < code className = "graphiql-key" > M</ code >
1076
+ </ td >
1077
+ < td >
1078
+ Merge fragments definitions into operation definition
1079
+ </ td >
1080
+ </ tr >
1081
+ < tr >
1082
+ < td >
1083
+ < code className = "graphiql-key" > Ctrl</ code >
1084
+ { ' + ' }
1085
+ < code className = "graphiql-key" > Shift</ code >
1086
+ { ' + ' }
1087
+ < code className = "graphiql-key" > C</ code >
1088
+ </ td >
1089
+ < td > Copy query</ td >
1090
+ </ tr >
1091
+ < tr >
1092
+ < td >
1093
+ < code className = "graphiql-key" > Ctrl</ code >
1094
+ { ' + ' }
1095
+ < code className = "graphiql-key" > Shift</ code >
1096
+ { ' + ' }
1097
+ < code className = "graphiql-key" > R</ code >
1098
+ </ td >
1099
+ < td > Re-fetch schema using introspection</ td >
1100
+ </ tr >
1101
+ </ tbody >
1102
+ </ table >
1103
+ < p >
1104
+ The editors use{ ' ' }
1105
+ < a
1106
+ href = "https://codemirror.net/5/doc/manual.html#keymaps"
1107
+ target = "_blank"
1108
+ rel = "noopener noreferrer" >
1109
+ CodeMirror Key Maps
1110
+ </ a > { ' ' }
1111
+ that add more short keys. This instance of Graph< em > i</ em > QL
1112
+ uses < code > { this . props . keyMap || 'sublime' } </ code > .
1113
+ </ p >
1114
+ </ div >
1115
+ </ div >
1116
+ </ Dialog >
1010
1117
< Dialog
1011
1118
isOpen = { this . state . showSettings }
1012
1119
onDismiss = { ( ) => {
0 commit comments