-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: monaco editor for console (#2040)
* feat: monaco editor * feat: handle json error in request console; change theme * chore: fix build * chore: refactor * chore: rm vite config stuff * chore: add back default editor worker
- Loading branch information
1 parent
1a495e1
commit 0266072
Showing
9 changed files
with
171 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.ContextEditor { | ||
width: 100vw; | ||
height: 50vh; | ||
} |
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,53 @@ | ||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; | ||
import tmrw from 'monaco-themes/themes/Tomorrow-Night-Bright.json'; | ||
import { useEffect, useRef } from 'react'; | ||
import styles from './ContextEditor.module.css'; | ||
import './worker'; | ||
|
||
type ContextEditorProps = { | ||
id: string; | ||
setValue(value: string): void; | ||
}; | ||
|
||
export const ContextEditor: React.FC<ContextEditorProps> = ( | ||
props: ContextEditorProps | ||
) => { | ||
const { id, setValue } = props; | ||
|
||
const editor = useRef<undefined | monaco.editor.IStandaloneCodeEditor>(); | ||
const monacoEl = useRef(null); | ||
const subscription = useRef<monaco.IDisposable | null>(null); | ||
|
||
monaco.editor.defineTheme('tmrw', tmrw as monaco.editor.IStandaloneThemeData); | ||
|
||
useEffect(() => { | ||
if (monacoEl.current) { | ||
editor.current = monaco.editor.create(monacoEl.current!, { | ||
value: '{}', | ||
language: 'json', | ||
fontSize: 14, | ||
lineNumbers: 'off', | ||
renderLineHighlight: 'none', | ||
minimap: { | ||
enabled: false | ||
}, | ||
folding: false, | ||
autoDetectHighContrast: false, | ||
autoClosingBrackets: 'always', | ||
scrollBeyondLastLine: false, | ||
theme: 'tmrw' | ||
}); | ||
|
||
// After initializing monaco editor | ||
if (editor?.current) { | ||
subscription.current = editor.current.onDidChangeModelContent(() => { | ||
if (editor?.current) setValue(editor.current.getValue()); | ||
}); | ||
} | ||
|
||
return () => editor.current && editor.current.dispose(); | ||
} | ||
}, []); | ||
|
||
return <div id={id} className={styles.ContextEditor} ref={monacoEl}></div>; | ||
}; |
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,21 @@ | ||
// @ts-ignore | ||
self.MonacoEnvironment = { | ||
getWorker(_, label) { | ||
switch (label) { | ||
case 'json': | ||
return new Worker( | ||
new URL( | ||
'monaco-editor/esm/vs/language/json/json.worker.js', | ||
import.meta.url | ||
) | ||
); | ||
default: | ||
return new Worker( | ||
new URL( | ||
'monaco-editor/esm/vs/editor/editor.worker.js', | ||
import.meta.url | ||
) | ||
); | ||
} | ||
} | ||
}; |
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
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