MCPcopy
hub / github.com/graphql/graphiql / useVariableEditor

Function useVariableEditor

packages/graphiql-react/src/editor/variable-editor.ts:48–155  ·  view source on GitHub ↗
(
  {
    editorTheme = DEFAULT_EDITOR_THEME,
    keyMap = DEFAULT_KEY_MAP,
    onClickReference,
    onEdit,
    readOnly = false,
  }: UseVariableEditorArgs = {},
  caller?: Function,
)

Source from the content-addressed store, hash-verified

46const _useVariableEditor = useVariableEditor;
47
48export function useVariableEditor(
49 {
50 editorTheme = DEFAULT_EDITOR_THEME,
51 keyMap = DEFAULT_KEY_MAP,
52 onClickReference,
53 onEdit,
54 readOnly = false,
55 }: UseVariableEditorArgs = {},
56 caller?: Function,
57) {
58 const { initialVariables, variableEditor, setVariableEditor } =
59 useEditorContext({
60 nonNull: true,
61 caller: caller || _useVariableEditor,
62 });
63 const executionContext = useExecutionContext();
64 const merge = useMergeQuery({ caller: caller || _useVariableEditor });
65 const prettify = usePrettifyEditors({ caller: caller || _useVariableEditor });
66 const ref = useRef<HTMLDivElement>(null);
67 useEffect(() => {
68 let isActive = true;
69
70 void importCodeMirrorImports().then(CodeMirror => {
71 // Don't continue if the effect has already been cleaned up
72 if (!isActive) {
73 return;
74 }
75 const container = ref.current;
76 if (!container) {
77 return;
78 }
79
80 const newEditor = CodeMirror(container, {
81 value: initialVariables,
82 lineNumbers: true,
83 tabSize: 2,
84 mode: 'graphql-variables',
85 theme: editorTheme,
86 autoCloseBrackets: true,
87 matchBrackets: true,
88 showCursorWhenSelecting: true,
89 readOnly: readOnly ? 'nocursor' : false,
90 foldGutter: true,
91 lint: {
92 // @ts-expect-error
93 variableToType: undefined,
94 },
95 hintOptions: {
96 closeOnUnfocus: false,
97 completeSingle: false,
98 container,
99 // @ts-expect-error
100 variableToType: undefined,
101 },
102 gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
103 extraKeys: commonKeys,
104 });
105

Callers 1

VariableEditorFunction · 0.90

Calls 10

useMergeQueryFunction · 0.90
usePrettifyEditorsFunction · 0.90
useSynchronizeOptionFunction · 0.90
useChangeHandlerFunction · 0.90
useCompletionFunction · 0.90
useKeyMapFunction · 0.90
useEditorContextFunction · 0.85
useExecutionContextFunction · 0.85
CodeMirrorFunction · 0.85
importCodeMirrorImportsFunction · 0.70

Tested by

no test coverage detected