-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out all the separate codemirror editors
- Loading branch information
Showing
7 changed files
with
128 additions
and
103 deletions.
There are no files selected for viewing
97 changes: 0 additions & 97 deletions
97
studio/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
studio/src/components/CodeMirrorEditor/CodeMirrorJsonEditor.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 "./CodeMirrorEditorCssOverrides.css"; | ||
|
||
import { json } from "@codemirror/lang-json"; | ||
import { duotoneDark } from "@uiw/codemirror-theme-duotone"; | ||
|
||
import CodeMirror, { EditorView } from "@uiw/react-codemirror"; | ||
import { customTheme } from "./themes"; | ||
|
||
type CodeMirrorEditorProps = { | ||
height?: string; | ||
minHeight?: string; | ||
maxHeight?: string; | ||
theme?: string; | ||
readOnly?: boolean; | ||
value?: string; | ||
onChange: (value?: string) => void; | ||
}; | ||
|
||
export function CodeMirrorJsonEditor(props: CodeMirrorEditorProps) { | ||
const { | ||
height, | ||
value, | ||
onChange, | ||
readOnly, | ||
minHeight = "200px", | ||
maxHeight, | ||
} = props; | ||
|
||
return ( | ||
<CodeMirror | ||
value={value} | ||
height={height} | ||
maxHeight={maxHeight} | ||
minHeight={minHeight} | ||
extensions={[EditorView.lineWrapping, json()]} | ||
onChange={onChange} | ||
theme={[duotoneDark, customTheme]} | ||
readOnly={readOnly} | ||
basicSetup={{ | ||
// Turn off searching the input via cmd+g and cmd+f | ||
searchKeymap: false, | ||
// Investigate: Remap the default keymap: https://codemirror.net/docs/ref/#commands.defaultKeymap | ||
// This will allow us to do things like cmd+enter to submit a payload | ||
}} | ||
/> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
studio/src/components/CodeMirrorEditor/CodeMirrorSqlEditor.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,26 @@ | ||
import "./CodeMirrorEditorCssOverrides.css"; | ||
|
||
import { sql } from "@codemirror/lang-sql"; | ||
import { duotoneDark } from "@uiw/codemirror-theme-duotone"; | ||
|
||
import CodeMirror, { EditorView } from "@uiw/react-codemirror"; | ||
import { customTheme } from "./themes"; | ||
import type { CodeMirrorEditorProps } from "./types"; | ||
|
||
type CodeMirrorSqlEditorProps = CodeMirrorEditorProps; | ||
|
||
export function CodeMirrorSqlEditor(props: CodeMirrorSqlEditorProps) { | ||
const { height, value, onChange, minHeight, maxHeight, readOnly } = props; | ||
return ( | ||
<CodeMirror | ||
value={value} | ||
height={height} | ||
minHeight={minHeight} | ||
maxHeight={maxHeight} | ||
readOnly={readOnly} | ||
extensions={[EditorView.lineWrapping, sql()]} | ||
onChange={onChange} | ||
theme={[duotoneDark, customTheme]} | ||
/> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
studio/src/components/CodeMirrorEditor/CodeMirrorTypescriptEditor.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,34 @@ | ||
import "./CodeMirrorEditorCssOverrides.css"; | ||
|
||
import { javascript } from "@codemirror/lang-javascript"; | ||
import { duotoneDark } from "@uiw/codemirror-theme-duotone"; | ||
|
||
import CodeMirror, { EditorView } from "@uiw/react-codemirror"; | ||
import { customTheme } from "./themes"; | ||
import type { CodeMirrorEditorProps } from "./types"; | ||
|
||
type CodeMirrorTypescriptEditorProps = CodeMirrorEditorProps & { | ||
jsx: boolean; | ||
}; | ||
|
||
export function CodeMirrorTypescriptEditor( | ||
props: CodeMirrorTypescriptEditorProps, | ||
) { | ||
const { height, value, onChange, jsx, minHeight, maxHeight, readOnly } = | ||
props; | ||
return ( | ||
<CodeMirror | ||
value={value} | ||
height={height} | ||
minHeight={minHeight} | ||
maxHeight={maxHeight} | ||
readOnly={readOnly} | ||
extensions={[ | ||
EditorView.lineWrapping, | ||
javascript({ jsx, typescript: true }), | ||
]} | ||
onChange={onChange} | ||
theme={[duotoneDark, customTheme]} | ||
/> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
export { | ||
CodeMirrorTypescriptEditor, | ||
CodeMirrorJsonEditor, | ||
CodeMirrorSqlEditor, | ||
} from "./CodeMirrorEditor"; | ||
|
||
export { CodeMirrorSqlEditor } from "./CodeMirrorSqlEditor"; | ||
export { CodeMirrorTypescriptEditor } from "./CodeMirrorTypescriptEditor"; | ||
export { CodeMirrorJsonEditor } from "./CodeMirrorJsonEditor"; | ||
export { CodeMirrorInput } from "./CodeMirrorInput"; |
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,9 @@ | ||
import { EditorView } from "@uiw/react-codemirror"; | ||
|
||
export const customTheme = EditorView.theme({ | ||
"&": { | ||
fontSize: "14px", | ||
// HACK | ||
background: "transparent !important", | ||
}, | ||
}); |
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,9 @@ | ||
export type CodeMirrorEditorProps = { | ||
height?: string; | ||
minHeight?: string; | ||
maxHeight?: string; | ||
theme?: string; | ||
readOnly?: boolean; | ||
value?: string; | ||
onChange: (value?: string) => void; | ||
}; |