-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit graphiql remove unused and add editor theme add monaco-editor-webpack-plugin remove
- Loading branch information
1 parent
67bf93a
commit 2e06209
Showing
35 changed files
with
1,042 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { editor as MONACO_EDITOR } from 'monaco-editor'; | ||
import { | ||
OPERATIONS_MODEL, | ||
VARIABLES_MODEL, | ||
HEADERS_MODEL, | ||
RESULTS_MODEL, | ||
editorThemeDark, | ||
editorThemeLight, | ||
} from './constants'; | ||
|
||
// this should be called somewhere else, but fine here for now | ||
MONACO_EDITOR.defineTheme('graphiql-DARK', editorThemeDark); | ||
MONACO_EDITOR.defineTheme('graphiql-LIGHT', editorThemeLight); | ||
|
||
export function createEditor( | ||
type: 'operations' | 'variables' | 'headers' | 'results', | ||
domElement: HTMLDivElement, | ||
) { | ||
return MONACO_EDITOR.create(domElement, { | ||
language: type === 'operations' ? 'graphql' : 'json', | ||
// the default theme | ||
theme: 'graphiql-DARK', | ||
automaticLayout: true, | ||
// folding: false, // disable folding | ||
fontFamily: "'Fira Code', monospace", // TODO: set the font (this is problematic because the font has to be installed locally) | ||
fontSize: 13, // default is 12 | ||
// lineDecorationsWidth: 100, | ||
lineNumbersMinChars: 2, | ||
minimap: { | ||
enabled: false, // disable the minimap | ||
}, | ||
overviewRulerLanes: 0, // remove unnecessary cruft on right side of editors | ||
scrollbar: { | ||
// hide the scrollbars | ||
horizontal: 'hidden', | ||
// vertical: 'hidden', | ||
verticalScrollbarSize: 4, | ||
}, | ||
// scrollPredominantAxis: false, | ||
scrollBeyondLastLine: false, // cleans up unnecessary "padding" on the bottom of each editor | ||
tabSize: 2, | ||
wordWrap: 'on', | ||
// wrappingIndent: 'none', | ||
wrappingStrategy: 'advanced', | ||
fixedOverflowWidgets: true, | ||
...(type === 'results' && { | ||
readOnly: true, | ||
lineNumbers: 'off', | ||
}), | ||
model: { | ||
operations: OPERATIONS_MODEL, | ||
variables: VARIABLES_MODEL, | ||
headers: HEADERS_MODEL, | ||
results: RESULTS_MODEL, | ||
}[type], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/graphiql-react/src/editor/components/header-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/graphiql-react/src/editor/components/headers-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { clsx } from 'clsx'; | ||
import { useEditorContext } from '../context'; | ||
import { UseHeaderEditorArgs } from '../header-editor'; | ||
import '../style/editor.css'; | ||
import { createEditor } from '@/create-editor'; | ||
import { HEADERS_MODEL } from '@/constants'; | ||
import debounce from '@/utility/debounce'; | ||
import { useStorageContext } from '@/storage'; | ||
|
||
type HeaderEditorProps = UseHeaderEditorArgs & { | ||
/** | ||
* Visually hide the header editor. | ||
* @default false | ||
*/ | ||
isHidden?: boolean; | ||
}; | ||
|
||
export function HeadersEditor({ isHidden, ...hookArgs }: HeaderEditorProps) { | ||
const { setHeaderEditor, updateActiveTabValues, shouldPersistHeaders } = | ||
useEditorContext({ | ||
nonNull: true, | ||
caller: HeadersEditor, | ||
}); | ||
const ref = useRef<HTMLDivElement>(null); | ||
const storage = useStorageContext(); | ||
|
||
useEffect(() => { | ||
setHeaderEditor(createEditor('headers', ref.current!)); | ||
if (!shouldPersistHeaders) { | ||
return; | ||
} | ||
HEADERS_MODEL.onDidChangeContent( | ||
debounce(500, () => { | ||
const value = HEADERS_MODEL.getValue(); | ||
storage?.set(STORAGE_KEY, value); | ||
updateActiveTabValues({ headers: value }); | ||
}), | ||
); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps -- only on mount | ||
}, []); | ||
|
||
return ( | ||
<div className={clsx('graphiql-editor', isHidden && 'hidden')} ref={ref} /> | ||
); | ||
} | ||
|
||
export const STORAGE_KEY = 'headers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/graphiql-react/src/editor/components/operations-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { useQueryEditor, UseQueryEditorArgs } from '../operations-editor'; | ||
|
||
export function OperationsEditor(props: UseQueryEditorArgs) { | ||
const ref = useQueryEditor(props, OperationsEditor); | ||
|
||
return <div className="graphiql-editor" ref={ref} />; | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/graphiql-react/src/editor/components/results-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { UseResponseEditorArgs } from '../response-editor'; | ||
import { useEffect, useRef } from 'react'; | ||
import { createEditor } from '@/create-editor'; | ||
import { useEditorContext } from '@/editor'; | ||
import '../style/editor.css'; | ||
|
||
export function ResultsEditor(props: UseResponseEditorArgs) { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
const { setResponseEditor } = useEditorContext({ | ||
nonNull: true, | ||
caller: ResultsEditor, | ||
}); | ||
|
||
useEffect(() => { | ||
setResponseEditor(createEditor('results', ref.current!)); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps -- only on mount | ||
}, []); | ||
|
||
return ( | ||
<section | ||
className="result-window" | ||
aria-label="Result Window" | ||
aria-live="polite" | ||
aria-atomic="true" | ||
ref={ref} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/graphiql-react/src/editor/components/variables-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { clsx } from 'clsx'; | ||
import { UseVariableEditorArgs } from '../variable-editor'; | ||
import { createEditor } from '@/create-editor'; | ||
import { VARIABLES_MODEL } from '@/constants'; | ||
import { useStorageContext } from '@/storage'; | ||
import { useEditorContext } from '@/editor'; | ||
import debounce from '@/utility/debounce'; | ||
|
||
type VariableEditorProps = UseVariableEditorArgs & { | ||
/** | ||
* Visually hide the header editor. | ||
* @default false | ||
*/ | ||
isHidden?: boolean; | ||
}; | ||
|
||
export function VariablesEditor({ | ||
isHidden, | ||
...hookArgs | ||
}: VariableEditorProps) { | ||
const ref = useRef<HTMLDivElement>(null); | ||
const storage = useStorageContext(); | ||
|
||
const { updateActiveTabValues, setVariableEditor } = useEditorContext({ | ||
nonNull: true, | ||
caller: VariablesEditor, | ||
}); | ||
|
||
useEffect(() => { | ||
setVariableEditor(createEditor('variables', ref.current!)); | ||
VARIABLES_MODEL.onDidChangeContent( | ||
debounce(500, () => { | ||
const value = VARIABLES_MODEL.getValue(); | ||
storage?.set(STORAGE_KEY, value); | ||
updateActiveTabValues({ variables: value }); | ||
}), | ||
); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps -- only on mount | ||
}, []); | ||
|
||
return ( | ||
<div className={clsx('graphiql-editor', isHidden && 'hidden')} ref={ref} /> | ||
); | ||
} | ||
|
||
const STORAGE_KEY = 'variables'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.