@@ -96,10 +96,6 @@ if (majorVersion < 16) {
9696 ) ;
9797}
9898
99- declare namespace window {
100- export let g : GraphiQL ;
101- }
102-
10399export type GraphiQLToolbarConfig = {
104100 additionalContent ?: React . ReactNode ;
105101} ;
@@ -318,12 +314,6 @@ export class GraphiQL extends React.Component<GraphiQLProps> {
318314 super ( props ) ;
319315 }
320316
321- componentDidMount ( ) {
322- if ( typeof window !== 'undefined' ) {
323- window . g = this ;
324- }
325- }
326-
327317 render ( ) {
328318 return (
329319 < GraphiQLProviders
@@ -645,6 +635,7 @@ type GraphiQLWithContextConsumerProps = Omit<
645635
646636export type GraphiQLState = {
647637 activeSecondaryEditor : 'variable' | 'header' ;
638+ showShortKeys : boolean ;
648639 showSettings : boolean ;
649640 clearStorageStatus : 'success' | 'error' | null ;
650641} ;
@@ -659,6 +650,7 @@ class GraphiQLWithContext extends React.Component<
659650 // Initialize state
660651 this . state = {
661652 activeSecondaryEditor : 'variable' ,
653+ showShortKeys : false ,
662654 showSettings : false ,
663655 clearStorageStatus : null ,
664656 } ;
@@ -720,6 +712,13 @@ class GraphiQLWithContext extends React.Component<
720712 }
721713 } ;
722714
715+ const modifier =
716+ window . navigator . platform . toLowerCase ( ) . indexOf ( 'mac' ) === 0 ? (
717+ < code className = "graphiql-key" > Cmd</ code >
718+ ) : (
719+ < code className = "graphiql-key" > Ctrl</ code >
720+ ) ;
721+
723722 return (
724723 < div data-testid = "graphiql-container" className = "graphiql-container" >
725724 < div className = "graphiql-sidebar" >
@@ -789,7 +788,12 @@ class GraphiQLWithContext extends React.Component<
789788 }
790789 />
791790 </ UnStyledButton >
792- < UnStyledButton type = "button" >
791+ < UnStyledButton
792+ type = "button"
793+ onClick = { ( ) => {
794+ this . setState ( { showShortKeys : true } ) ;
795+ } }
796+ >
793797 < KeyboardShortcutIcon />
794798 </ UnStyledButton >
795799 < UnStyledButton
@@ -1051,6 +1055,113 @@ class GraphiQLWithContext extends React.Component<
10511055 </ div >
10521056 </ div >
10531057 </ div >
1058+ < Dialog
1059+ isOpen = { this . state . showShortKeys }
1060+ onDismiss = { ( ) => {
1061+ this . setState ( { showShortKeys : false } ) ;
1062+ } }
1063+ >
1064+ < div className = "graphiql-dialog-header" >
1065+ < div className = "graphiql-dialog-title" > Short Keys</ div >
1066+ < Dialog . Close
1067+ onClick = { ( ) => {
1068+ this . setState ( { showShortKeys : false } ) ;
1069+ } }
1070+ />
1071+ </ div >
1072+ < div className = "graphiql-dialog-section" >
1073+ < div >
1074+ < table className = "graphiql-table" >
1075+ < thead >
1076+ < tr >
1077+ < th > Short key</ th >
1078+ < th > Function</ th >
1079+ </ tr >
1080+ </ thead >
1081+ < tbody >
1082+ < tr >
1083+ < td >
1084+ { modifier }
1085+ { ' + ' }
1086+ < code className = "graphiql-key" > F</ code >
1087+ </ td >
1088+ < td > Search in editor</ td >
1089+ </ tr >
1090+ < tr >
1091+ < td >
1092+ { modifier }
1093+ { ' + ' }
1094+ < code className = "graphiql-key" > K</ code >
1095+ </ td >
1096+ < td > Search in documentation</ td >
1097+ </ tr >
1098+ < tr >
1099+ < td >
1100+ { modifier }
1101+ { ' + ' }
1102+ < code className = "graphiql-key" > Enter</ code >
1103+ </ td >
1104+ < td > Execute query</ td >
1105+ </ tr >
1106+ < tr >
1107+ < td >
1108+ < code className = "graphiql-key" > Ctrl</ code >
1109+ { ' + ' }
1110+ < code className = "graphiql-key" > Shift</ code >
1111+ { ' + ' }
1112+ < code className = "graphiql-key" > P</ code >
1113+ </ td >
1114+ < td > Prettify editors</ td >
1115+ </ tr >
1116+ < tr >
1117+ < td >
1118+ < code className = "graphiql-key" > Ctrl</ code >
1119+ { ' + ' }
1120+ < code className = "graphiql-key" > Shift</ code >
1121+ { ' + ' }
1122+ < code className = "graphiql-key" > M</ code >
1123+ </ td >
1124+ < td >
1125+ Merge fragments definitions into operation definition
1126+ </ td >
1127+ </ tr >
1128+ < tr >
1129+ < td >
1130+ < code className = "graphiql-key" > Ctrl</ code >
1131+ { ' + ' }
1132+ < code className = "graphiql-key" > Shift</ code >
1133+ { ' + ' }
1134+ < code className = "graphiql-key" > C</ code >
1135+ </ td >
1136+ < td > Copy query</ td >
1137+ </ tr >
1138+ < tr >
1139+ < td >
1140+ < code className = "graphiql-key" > Ctrl</ code >
1141+ { ' + ' }
1142+ < code className = "graphiql-key" > Shift</ code >
1143+ { ' + ' }
1144+ < code className = "graphiql-key" > R</ code >
1145+ </ td >
1146+ < td > Re-fetch schema using introspection</ td >
1147+ </ tr >
1148+ </ tbody >
1149+ </ table >
1150+ < p >
1151+ The editors use{ ' ' }
1152+ < a
1153+ href = "https://codemirror.net/5/doc/manual.html#keymaps"
1154+ target = "_blank"
1155+ rel = "noopener noreferrer"
1156+ >
1157+ CodeMirror Key Maps
1158+ </ a > { ' ' }
1159+ that add more short keys. This instance of Graph< em > i</ em > QL
1160+ uses < code > { this . props . keyMap || 'sublime' } </ code > .
1161+ </ p >
1162+ </ div >
1163+ </ div >
1164+ </ Dialog >
10541165 < Dialog
10551166 isOpen = { this . state . showSettings }
10561167 onDismiss = { ( ) => {
0 commit comments