|
|
@@ -1,11 +1,11 @@
|
|
1
|
|
-import Editor, { Monaco } from "@monaco-editor/react"
|
|
2
|
|
-import useTheme from "hooks/useTheme"
|
|
3
|
|
-import prettier from "prettier/standalone"
|
|
4
|
|
-import parserTypeScript from "prettier/parser-typescript"
|
|
5
|
|
-import codeAsString from "./code-as-string"
|
|
6
|
|
-import React, { useCallback, useEffect, useRef } from "react"
|
|
7
|
|
-import styled from "styles"
|
|
8
|
|
-import { IMonaco, IMonacoEditor } from "types"
|
|
|
1
|
+import Editor, { Monaco } from '@monaco-editor/react'
|
|
|
2
|
+import useTheme from 'hooks/useTheme'
|
|
|
3
|
+import prettier from 'prettier/standalone'
|
|
|
4
|
+import parserTypeScript from 'prettier/parser-typescript'
|
|
|
5
|
+import codeAsString from './code-as-string'
|
|
|
6
|
+import React, { useCallback, useEffect, useRef } from 'react'
|
|
|
7
|
+import styled from 'styles'
|
|
|
8
|
+import { IMonaco, IMonacoEditor } from 'types'
|
|
9
|
9
|
|
|
10
|
10
|
interface Props {
|
|
11
|
11
|
value: string
|
|
|
@@ -48,7 +48,7 @@ export default function CodeEditor({
|
|
48
|
48
|
checkJs: false,
|
|
49
|
49
|
strict: false,
|
|
50
|
50
|
noLib: true,
|
|
51
|
|
- lib: ["es6"],
|
|
|
51
|
+ lib: ['es6'],
|
|
52
|
52
|
target: monaco.languages.typescript.ScriptTarget.ES2015,
|
|
53
|
53
|
allowNonTsExtensions: true,
|
|
54
|
54
|
})
|
|
|
@@ -69,13 +69,13 @@ export default function CodeEditor({
|
|
69
|
69
|
|
|
70
|
70
|
monaco.languages.typescript.javascriptDefaults.addExtraLib(codeAsString)
|
|
71
|
71
|
|
|
72
|
|
- monaco.languages.registerDocumentFormattingEditProvider("javascript", {
|
|
|
72
|
+ monaco.languages.registerDocumentFormattingEditProvider('javascript', {
|
|
73
|
73
|
async provideDocumentFormattingEdits(model) {
|
|
74
|
74
|
const text = prettier.format(model.getValue(), {
|
|
75
|
|
- parser: "typescript",
|
|
|
75
|
+ parser: 'typescript',
|
|
76
|
76
|
plugins: [parserTypeScript],
|
|
77
|
77
|
singleQuote: true,
|
|
78
|
|
- trailingComma: "es5",
|
|
|
78
|
+ trailingComma: 'es5',
|
|
79
|
79
|
semi: false,
|
|
80
|
80
|
})
|
|
81
|
81
|
|
|
|
@@ -114,12 +114,12 @@ export default function CodeEditor({
|
|
114
|
114
|
(e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
115
|
115
|
onKey && onKey()
|
|
116
|
116
|
e.stopPropagation()
|
|
117
|
|
- const metaKey = navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey
|
|
118
|
|
- if (e.key === "s" && metaKey) {
|
|
|
117
|
+ const metaKey = navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey
|
|
|
118
|
+ if (e.key === 's' && metaKey) {
|
|
119
|
119
|
const editor = rEditor.current
|
|
120
|
120
|
if (!editor) return
|
|
121
|
121
|
editor
|
|
122
|
|
- .getAction("editor.action.formatDocument")
|
|
|
122
|
+ .getAction('editor.action.formatDocument')
|
|
123
|
123
|
.run()
|
|
124
|
124
|
.then(() =>
|
|
125
|
125
|
onSave(rEditor.current?.getModel().getValue(), rEditor.current)
|
|
|
@@ -127,10 +127,10 @@ export default function CodeEditor({
|
|
127
|
127
|
|
|
128
|
128
|
e.preventDefault()
|
|
129
|
129
|
}
|
|
130
|
|
- if (e.key === "p" && metaKey) {
|
|
|
130
|
+ if (e.key === 'p' && metaKey) {
|
|
131
|
131
|
e.preventDefault()
|
|
132
|
132
|
}
|
|
133
|
|
- if (e.key === "d" && metaKey) {
|
|
|
133
|
+ if (e.key === 'd' && metaKey) {
|
|
134
|
134
|
e.preventDefault()
|
|
135
|
135
|
}
|
|
136
|
136
|
},
|
|
|
@@ -167,7 +167,7 @@ export default function CodeEditor({
|
|
167
|
167
|
),
|
|
168
|
168
|
options: {
|
|
169
|
169
|
isWholeLine: true,
|
|
170
|
|
- className: "editorLineError",
|
|
|
170
|
+ className: 'editorLineError',
|
|
171
|
171
|
},
|
|
172
|
172
|
},
|
|
173
|
173
|
])
|
|
|
@@ -176,7 +176,7 @@ export default function CodeEditor({
|
|
176
|
176
|
useEffect(() => {
|
|
177
|
177
|
const monaco = rMonaco.current
|
|
178
|
178
|
if (!monaco) return
|
|
179
|
|
- monaco.editor.setTheme(theme === "dark" ? "vs-dark" : "light")
|
|
|
179
|
+ monaco.editor.setTheme(theme === 'dark' ? 'vs-dark' : 'light')
|
|
180
|
180
|
}, [theme])
|
|
181
|
181
|
|
|
182
|
182
|
useEffect(() => {
|
|
|
@@ -194,7 +194,7 @@ export default function CodeEditor({
|
|
194
|
194
|
height="100%"
|
|
195
|
195
|
language="javascript"
|
|
196
|
196
|
value={value}
|
|
197
|
|
- theme={theme === "dark" ? "vs-dark" : "light"}
|
|
|
197
|
+ theme={theme === 'dark' ? 'vs-dark' : 'light'}
|
|
198
|
198
|
beforeMount={handleBeforeMount}
|
|
199
|
199
|
onMount={handleMount}
|
|
200
|
200
|
onChange={handleChange}
|
|
|
@@ -203,12 +203,12 @@ export default function CodeEditor({
|
|
203
|
203
|
)
|
|
204
|
204
|
}
|
|
205
|
205
|
|
|
206
|
|
-const EditorContainer = styled("div", {
|
|
207
|
|
- height: "100%",
|
|
208
|
|
- pointerEvents: "all",
|
|
209
|
|
- userSelect: "all",
|
|
|
206
|
+const EditorContainer = styled('div', {
|
|
|
207
|
+ height: '100%',
|
|
|
208
|
+ pointerEvents: 'all',
|
|
|
209
|
+ userSelect: 'all',
|
|
210
|
210
|
|
|
211
|
|
- ".editorLineError": {
|
|
212
|
|
- backgroundColor: "$lineError",
|
|
|
211
|
+ '.editorLineError': {
|
|
|
212
|
+ backgroundColor: '$lineError',
|
|
213
|
213
|
},
|
|
214
|
214
|
})
|