(
{
editorTheme = DEFAULT_EDITOR_THEME,
keyMap = DEFAULT_KEY_MAP,
onClickReference,
onCopyQuery,
onEdit,
onPrettifyQuery,
readOnly = false,
}: UseQueryEditorArgs = {},
caller?: Function,
)
| 118 | } |
| 119 | |
| 120 | export function useQueryEditor( |
| 121 | { |
| 122 | editorTheme = DEFAULT_EDITOR_THEME, |
| 123 | keyMap = DEFAULT_KEY_MAP, |
| 124 | onClickReference, |
| 125 | onCopyQuery, |
| 126 | onEdit, |
| 127 | onPrettifyQuery, |
| 128 | readOnly = false, |
| 129 | }: UseQueryEditorArgs = {}, |
| 130 | caller?: Function, |
| 131 | ) { |
| 132 | const { schema, setSchemaReference } = useSchemaContext({ |
| 133 | nonNull: true, |
| 134 | caller: caller || _useQueryEditor, |
| 135 | }); |
| 136 | const { |
| 137 | externalFragments, |
| 138 | initialQuery, |
| 139 | queryEditor, |
| 140 | setOperationName, |
| 141 | setQueryEditor, |
| 142 | validationRules, |
| 143 | variableEditor, |
| 144 | updateActiveTabValues, |
| 145 | } = useEditorContext({ |
| 146 | nonNull: true, |
| 147 | caller: caller || _useQueryEditor, |
| 148 | }); |
| 149 | const executionContext = useExecutionContext(); |
| 150 | const storage = useStorageContext(); |
| 151 | const plugin = usePluginContext(); |
| 152 | const copy = useCopyQuery({ caller: caller || _useQueryEditor, onCopyQuery }); |
| 153 | const merge = useMergeQuery({ caller: caller || _useQueryEditor }); |
| 154 | const prettify = usePrettifyEditors({ |
| 155 | caller: caller || _useQueryEditor, |
| 156 | onPrettifyQuery, |
| 157 | }); |
| 158 | const ref = useRef<HTMLDivElement>(null); |
| 159 | const codeMirrorRef = useRef<CodeMirrorType>(undefined); |
| 160 | |
| 161 | const onClickReferenceRef = useRef< |
| 162 | NonNullable<UseQueryEditorArgs['onClickReference']> |
| 163 | >(() => {}); |
| 164 | |
| 165 | useEffect(() => { |
| 166 | onClickReferenceRef.current = reference => { |
| 167 | const referencePlugin = plugin?.referencePlugin; |
| 168 | if (!referencePlugin) { |
| 169 | return; |
| 170 | } |
| 171 | plugin.setVisiblePlugin(referencePlugin); |
| 172 | setSchemaReference(reference); |
| 173 | onClickReference?.(reference); |
| 174 | }; |
| 175 | }, [onClickReference, plugin, setSchemaReference]); |
| 176 | |
| 177 | useEffect(() => { |
no test coverage detected