@graphiql/react
Advanced tools
Comparing version 0.20.2-canary-bc65d4e0.0 to 0.20.2
{ | ||
"name": "@graphiql/react", | ||
"version": "0.20.2-canary-bc65d4e0.0", | ||
"version": "0.20.2", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -14,3 +14,3 @@ import { fillLeafs, GetDefaultFieldNamesFn, mergeAst } from '@graphiql/toolkit'; | ||
import { onHasCompletion } from './completion'; | ||
import { DEFAULT_QUERY, useEditorContext } from './context'; | ||
import { useEditorContext } from './context'; | ||
import { CodeMirrorEditor } from './types'; | ||
@@ -341,19 +341,12 @@ | ||
export const useEditorState = ( | ||
editor: 'query' | 'variable' | 'header', | ||
initialState?: InitialState, | ||
) => { | ||
export const useEditorState = (editor: 'query' | 'variable' | 'header') => { | ||
const context = useEditorContext({ | ||
nonNull: true, | ||
}); | ||
const initialValue = | ||
typeof initialState === 'function' ? initialState() : initialState; | ||
const editorInstance = context[`${editor}Editor` as const]; | ||
let valueString = ''; | ||
const editorValue = editorInstance?.getValue(); | ||
if (editorValue && editorValue.length > 0 && editorValue !== DEFAULT_QUERY) { | ||
const editorValue = editorInstance?.getValue() ?? false; | ||
if (editorValue && editorValue.length > 0) { | ||
valueString = editorValue; | ||
} else { | ||
valueString = initialValue || ''; | ||
editorInstance?.setValue(valueString); | ||
} | ||
@@ -374,7 +367,8 @@ | ||
*/ | ||
export function useOperationsEditorState( | ||
initialState?: InitialState, | ||
): [operations: string, setOperations: (content: string) => void] { | ||
return useEditorState('query', initialState); | ||
} | ||
export const useOperationsEditorState = (): [ | ||
operations: string, | ||
setOperations: (content: string) => void, | ||
] => { | ||
return useEditorState('query'); | ||
}; | ||
@@ -384,7 +378,8 @@ /** | ||
*/ | ||
export function useVariablesEditorState( | ||
initialState?: InitialState, | ||
): [variables: string, setVariables: (content: string) => void] { | ||
return useEditorState('variable', initialState); | ||
} | ||
export const useVariablesEditorState = (): [ | ||
variables: string, | ||
setVariables: (content: string) => void, | ||
] => { | ||
return useEditorState('variable'); | ||
}; | ||
@@ -394,6 +389,7 @@ /** | ||
*/ | ||
export function useHeadersEditorState( | ||
initialState?: InitialState, | ||
): [headers: string, setHeaders: (content: string) => void] { | ||
return useEditorState('header', initialState); | ||
} | ||
export const useHeadersEditorState = (): [ | ||
headers: string, | ||
setHeaders: (content: string) => void, | ||
] => { | ||
return useEditorState('header'); | ||
}; |
@@ -52,15 +52,15 @@ import { GetDefaultFieldNamesFn } from '@graphiql/toolkit'; | ||
export declare type InitialState = string | (() => string); | ||
export declare const useEditorState: (editor: 'query' | 'variable' | 'header', initialState?: InitialState | undefined) => [string, (val: string) => void]; | ||
export declare const useEditorState: (editor: 'query' | 'variable' | 'header') => [string, (val: string) => void]; | ||
/** | ||
* useState-like hook for current tab operations editor state | ||
*/ | ||
export declare function useOperationsEditorState(initialState?: InitialState): [operations: string, setOperations: (content: string) => void]; | ||
export declare const useOperationsEditorState: () => [operations: string, setOperations: (content: string) => void]; | ||
/** | ||
* useState-like hook for current tab variables editor state | ||
*/ | ||
export declare function useVariablesEditorState(initialState?: InitialState): [variables: string, setVariables: (content: string) => void]; | ||
export declare const useVariablesEditorState: () => [variables: string, setVariables: (content: string) => void]; | ||
/** | ||
* useState-like hook for current tab variables editor state | ||
*/ | ||
export declare function useHeadersEditorState(initialState?: InitialState): [headers: string, setHeaders: (content: string) => void]; | ||
export declare const useHeadersEditorState: () => [headers: string, setHeaders: (content: string) => void]; | ||
export {}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4610630
28342