(
{
editorTheme = DEFAULT_EDITOR_THEME,
keyMap = DEFAULT_KEY_MAP,
onClickReference,
onEdit,
readOnly = false,
}: UseVariableEditorArgs = {},
caller?: Function,
)
| 46 | const _useVariableEditor = useVariableEditor; |
| 47 | |
| 48 | export 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 |
no test coverage detected