Skip to content

Commit 8c0ce50

Browse files
committed
feat: change to new editor
1 parent bfc28ad commit 8c0ce50

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@fontsource/dm-mono": "^5.2.5",
1515
"@hono/valibot-validator": "^0.5.2",
1616
"@microlink/react-json-view": "^1.26.2",
17+
"@monaco-editor/react": "^4.7.0",
1718
"@radix-ui/react-checkbox": "^1.3.2",
1819
"@radix-ui/react-dialog": "^1.1.14",
1920
"@radix-ui/react-dropdown-menu": "^2.1.15",
@@ -35,6 +36,7 @@
3536
"hono": "^4.7.11",
3637
"lodash": "^4.17.21",
3738
"lucide-react": "^0.511.0",
39+
"monaco-editor": "^0.52.2",
3840
"motion": "^12.15.0",
3941
"nanoid": "^5.1.5",
4042
"prismjs": "^1.30.0",

pnpm-lock.yaml

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/Editor.tsx

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,16 @@ import {
2727
ZapIcon,
2828
} from "lucide-react";
2929
import { type FC, useCallback, useEffect, useRef, useState } from "react";
30-
import CodeEditor from "react-simple-code-editor";
30+
import { Editor as MonacoEditor } from "@monaco-editor/react";
3131

32-
// The following imports can't be re-ordered otherwise things break
33-
// @ts-expect-error TODO: create types for this
34-
import { highlight, languages } from "prismjs/components/prism-core";
35-
import "prismjs/components/prism-hcl";
36-
import "prismjs/themes/prism.css";
3732
import { cn } from "@/utils/cn";
3833
import type { ParameterFormType } from "@/gen/types";
3934
import { multiSelect, radio, switchInput, textInput } from "@/client/snippets";
40-
41-
// Adds line numbers to the highlight.
42-
const hightlightWithLineNumbers = (input: string, language: unknown) =>
43-
highlight(input, language)
44-
.split("\n")
45-
.map(
46-
(line: string, i: number) =>
47-
`<span class='editorLineNumber'>${i + 1}</span>${line}`,
48-
)
49-
.join("\n");
35+
import { useTheme } from "@/client/contexts/theme";
5036

5137
export const Editor: FC = () => {
38+
const { appliedTheme } = useTheme();
39+
5240
const $code = useStore((state) => state.code);
5341
const $setCode = useStore((state) => state.setCode);
5442

@@ -160,7 +148,7 @@ export const Editor: FC = () => {
160148
)}
161149
>
162150
<Button
163-
className="pointer-events-auto z-10"
151+
className="pointer-events-auto z-10 hidden"
164152
variant="subtle"
165153
size="sm"
166154
onClick={onCopy}
@@ -170,15 +158,30 @@ export const Editor: FC = () => {
170158
</div>
171159

172160
<Tabs.Content value="code" asChild={true}>
173-
<div className="h-full w-full overflow-y-scroll bg-surface-secondary font-mono">
174-
<CodeEditor
161+
<div className="h-full w-full bg-surface-secondary font-mono">
162+
<MonacoEditor
175163
value={$code}
176-
onValueChange={(code) => $setCode(code)}
177-
highlight={(code) =>
178-
hightlightWithLineNumbers(code, languages.hcl)
179-
}
180-
textareaId="codeArea"
181-
className="editor pt-3"
164+
onChange={(code) => {
165+
if (code !== undefined) {
166+
$setCode(code);
167+
}
168+
}}
169+
theme={appliedTheme === "dark" ? "vs-dark" : "vs-light"}
170+
className=""
171+
defaultLanguage="hcl"
172+
options={{
173+
minimap: {
174+
enabled: false,
175+
},
176+
automaticLayout: true,
177+
fontFamily: "DM Mono",
178+
fontSize: 14,
179+
wordWrap: "on",
180+
padding: {
181+
top: 16,
182+
bottom: 16,
183+
},
184+
}}
182185
/>
183186
</div>
184187
</Tabs.Content>

0 commit comments

Comments
 (0)